Re: [PATCH 15/16] hyperv: network list functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 08/09/2016 08:39 AM, Jason Miesionczek wrote:
> ---
>  src/hyperv/hyperv_network_driver.c | 156 +++++++++++++++++++++++++++++++++++++
>  1 file changed, 156 insertions(+)
> 
> diff --git a/src/hyperv/hyperv_network_driver.c b/src/hyperv/hyperv_network_driver.c
> index 00037ae..68f03e5 100644
> --- a/src/hyperv/hyperv_network_driver.c
> +++ b/src/hyperv/hyperv_network_driver.c
> @@ -115,10 +115,166 @@ hypervNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags)
>      return xml;
>  }
>  
> +static int
> +hypervConnectNumOfNetworks(virConnectPtr conn)
> +{
> +    int result = -1, count = 0;
> +    hypervPrivate *priv = conn->privateData;
> +    virBuffer query = VIR_BUFFER_INITIALIZER;
> +    Msvm_VirtualSwitch *virtualSwitchList = NULL;
> +    Msvm_VirtualSwitch *virtualSwitch = NULL;
> +
> +    virBufferAddLit(&query, MSVM_VIRTUALSWITCH_WQL_SELECT);
> +    virBufferAsprintf(&query, "where HealthState = %d", 5);

5 is a magic number

> +    if (hypervGetMsvmVirtualSwitchList(priv, &query, &virtualSwitchList) < 0) {
> +        goto cleanup;
> +    }
> +
> +    for (virtualSwitch = virtualSwitchList; virtualSwitch != NULL;
> +         virtualSwitch = virtualSwitch->next) {
> +        count++;
> +    }
> +
> +    result = count;
> +
> + cleanup:
> +    hypervFreeObject(priv, (hypervObject *) virtualSwitchList);
> +    virBufferFreeAndReset(&query);
> +
> +    return result;
> +}
> +
> +
> +
> +static int
> +hypervConnectListNetworks(virConnectPtr conn, char **const names, int maxnames)
> +{
> +    int i, count = 0;
> +    bool success = false;
> +    hypervPrivate *priv = conn->privateData;
> +    virBuffer query = VIR_BUFFER_INITIALIZER;
> +    Msvm_VirtualSwitch *virtualSwitchList = NULL;
> +    Msvm_VirtualSwitch *virtualSwitch = NULL;
> +
> +    if (maxnames <= 0)
> +        return 0;
> +
> +    virBufferAddLit(&query, MSVM_VIRTUALSWITCH_WQL_SELECT);
> +    virBufferAsprintf(&query, "where HealthState = %d", 5);
> +    if (hypervGetMsvmVirtualSwitchList(priv, &query, &virtualSwitchList) < 0) {
> +        goto cleanup;
> +    }

Hmmm this looks familiar - consider a helper instead of cut-copy-paste

> +
> +    for (virtualSwitch = virtualSwitchList; virtualSwitch != NULL;
> +         virtualSwitch = virtualSwitch->next) {
> +        if (VIR_STRDUP(names[count], virtualSwitch->data->ElementName) < 0) {
> +            goto cleanup;
> +        }
> +        count++;
> +        if (count >= maxnames) {

Well I hope count is never > maxnames!

> +            break;
> +        }
> +    }
> +
> +    success = true;
> +
> + cleanup:
> +    if (!success) {
> +        for (i = 0; i < count; ++i) {
> +            VIR_FREE(names[i]);
> +        }
> +        count = -1;
> +    }
> +
> +    hypervFreeObject(priv, (hypervObject *) virtualSwitchList);
> +    virBufferFreeAndReset(&query);
> +
> +    return count;
> +}
>  

The hunks above and below could be separate patches, although I do see
some sense in combining them.

> +static int
> +hypervConnectNumOfDefinedNetworks(virConnectPtr conn)
> +{
> +    int result = -1, count = 0;
> +    hypervPrivate *priv = conn->privateData;
> +    virBuffer query = VIR_BUFFER_INITIALIZER;
> +    Msvm_VirtualSwitch *virtualSwitchList = NULL;
> +    Msvm_VirtualSwitch *virtualSwitch = NULL;
> +
> +    virBufferAddLit(&query, MSVM_VIRTUALSWITCH_WQL_SELECT);
> +    virBufferAsprintf(&query, "where HealthState <> %d", 5);

So defined networks don't include ones with the magic #5

I would think a "defined"
> +    if (hypervGetMsvmVirtualSwitchList(priv, &query, &virtualSwitchList) < 0) {
> +        goto cleanup;
> +    }
> +
> +    for (virtualSwitch = virtualSwitchList; virtualSwitch != NULL;
> +         virtualSwitch = virtualSwitch->next) {
> +        count++;
> +    }
> +
> +    result = count;
> +
> + cleanup:
> +    hypervFreeObject(priv, (hypervObject *) virtualSwitchList);
> +    virBufferFreeAndReset(&query);
> +
> +    return result;
> +}
> +
> +
> +
> +static int
> +hypervConnectListDefinedNetworks(virConnectPtr conn, char **const names, int maxnames)
> +{
> +    int i, count = 0;
> +    bool success = false;
> +    hypervPrivate *priv = conn->privateData;
> +    virBuffer query = VIR_BUFFER_INITIALIZER;
> +    Msvm_VirtualSwitch *virtualSwitchList = NULL;
> +    Msvm_VirtualSwitch *virtualSwitch = NULL;
> +
> +    if (maxnames <= 0)
> +        return 0;
> +
> +    virBufferAddLit(&query, MSVM_VIRTUALSWITCH_WQL_SELECT);
> +    virBufferAsprintf(&query, "where HealthState <> %d", 5);
> +    if (hypervGetMsvmVirtualSwitchList(priv, &query, &virtualSwitchList) < 0) {
> +        goto cleanup;
> +    }

Common code.

> +
> +    for (virtualSwitch = virtualSwitchList; virtualSwitch != NULL;
> +         virtualSwitch = virtualSwitch->next) {
> +        if (VIR_STRDUP(names[count], virtualSwitch->data->ElementName) < 0) {
> +            goto cleanup;
> +        }
> +        count++;
> +        if (count >= maxnames) {
> +            break;
> +        }
> +    }
> +
> +    success = true;
> +
> + cleanup:
> +    if (!success) {
> +        for (i = 0; i < count; ++i) {
> +            VIR_FREE(names[i]);
> +        }
> +        count = -1;
> +    }
> +
> +    hypervFreeObject(priv, (hypervObject *) virtualSwitchList);
> +    virBufferFreeAndReset(&query);
> +
> +    return count;
> +}
>  
>  virNetworkDriver hypervNetworkDriver = {
>      .name = "Hyper-V",
>      .networkLookupByName = hypervNetworkLookupByName, /* 1.2.10 */
>      .networkGetXMLDesc = hypervNetworkGetXMLDesc, /* 1.2.10 */
> +    .connectNumOfNetworks = hypervConnectNumOfNetworks, /* 1.2.10 */
> +    .connectListNetworks = hypervConnectListNetworks, /* 1.2.10 */
> +    .connectNumOfDefinedNetworks = hypervConnectNumOfDefinedNetworks, /* 1.2.10 */
> +    .connectListDefinedNetworks = hypervConnectListDefinedNetworks, /* 1.2.10 */

2.3.0 at the earliest

John

>  };
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]