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

Re: [libvirt] [PATCHv2 5/5] network: add connections counter to networks



Looks good to me.

Acked-by: Kyle Mestery <kmestery cisco com>

On Aug 14, 2012, at 2:10 AM, Laine Stump wrote:

> Just as each physical device used by a network has a connections
> counter, now each network has a connections counter which is
> incremented once for each guest interface that connects using this
> network.
> 
> The count is output in the live network XML, like this:
> 
>   <network connections='20'>
>   ...
>   </network>
> 
> It is read-only, and for informational purposes only - it isn't used
> internally anywhere by libvirt.
> ---
> src/conf/network_conf.c     |  6 +++++-
> src/conf/network_conf.h     |  1 +
> src/network/bridge_driver.c | 10 ++++++++++
> 3 files changed, 16 insertions(+), 1 deletion(-)
> 
> diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
> index ca5b759..45f8e69 100644
> --- a/src/conf/network_conf.c
> +++ b/src/conf/network_conf.c
> @@ -1463,7 +1463,11 @@ char *virNetworkDefFormat(const virNetworkDefPtr def, unsigned int flags)
>     char uuidstr[VIR_UUID_STRING_BUFLEN];
>     int ii;
> 
> -    virBufferAddLit(&buf, "<network>\n");
> +    virBufferAddLit(&buf, "<network");
> +    if (!(flags & VIR_NETWORK_XML_INACTIVE) && (def->connections > 0)) {
> +        virBufferAsprintf(&buf, " connections='%d'", def->connections);
> +    }
> +    virBufferAddLit(&buf, ">\n");
>     virBufferEscapeString(&buf, "  <name>%s</name>\n", def->name);
> 
>     uuid = def->uuid;
> diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
> index 23f1632..32fc765 100644
> --- a/src/conf/network_conf.h
> +++ b/src/conf/network_conf.h
> @@ -156,6 +156,7 @@ struct _virNetworkDef {
>     unsigned char uuid[VIR_UUID_BUFLEN];
>     bool uuid_specified;
>     char *name;
> +    int   connections; /* # of guest interfaces connected to this network */
> 
>     char *bridge;       /* Name of bridge device */
>     char *domain;
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 680b3f3..b784eb4 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -3005,6 +3005,10 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
>         VIR_DEBUG("Using physical device %s, %d connections",
>                   dev->dev, dev->connections);
>     }
> +
> +    netdef->connections++;
> +    VIR_DEBUG("Using network %s, %d connections",
> +              netdef->name, netdef->connections);
>     ret = 0;
> error:
>     for (ii = 0; ii < num_virt_fns; ii++)
> @@ -3114,6 +3118,9 @@ networkNotifyActualDevice(virDomainNetDefPtr iface)
>     }
> 
> cleanup:
> +    netdef->connections++;
> +    VIR_DEBUG("Using network %s, %d connections",
> +              netdef->name, netdef->connections);
>     ret = 0;
> error:
>     if (network)
> @@ -3199,6 +3206,9 @@ networkReleaseActualDevice(virDomainNetDefPtr iface)
>     }
> 
> cleanup:
> +    netdef->connections--;
> +    VIR_DEBUG("Releasing network %s, %d connections",
> +              netdef->name, netdef->connections);
>     ret = 0;
> error:
>     if (network)
> -- 
> 1.7.11.2
> 
> --
> libvir-list mailing list
> libvir-list redhat com
> https://www.redhat.com/mailman/listinfo/libvir-list



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