[libvirt] [PATCH V3 2/3] Introduce virNetlinkEventServiceStopAll() to stop all netlink services.

Daniel Veillard veillard at redhat.com
Wed Aug 22 10:29:33 UTC 2012


On Wed, Aug 22, 2012 at 12:10:24PM +0800, Tang Chen wrote:
> This patch introduce virNetlinkEventServiceStopAll() to stop
> all the monitors to receive netlink messages for libvirtd.
> 
> Signed-off-by: Tang Chen <tangchen at cn.fujitsu.com>
> ---
>  daemon/libvirtd.c        |    2 +-
>  src/libvirt_private.syms |    1 +
>  src/util/virnetlink.c    |   50 ++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virnetlink.h    |    5 +++++
>  4 files changed, 57 insertions(+), 1 deletion(-)
> 
> diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
> index e2e4fbd..922c5b5 100644
> --- a/daemon/libvirtd.c
> +++ b/daemon/libvirtd.c
> @@ -1325,7 +1325,7 @@ int main(int argc, char **argv) {
>                  0, "shutdown", NULL, NULL);
>  
>  cleanup:
> -    virNetlinkEventServiceStop(NETLINK_ROUTE);
> +    virNetlinkEventServiceStopAll();
>      virObjectUnref(remoteProgram);
>      virObjectUnref(qemuProgram);
>      virNetServerClose(srv);
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index a55fb73..af1a22a 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1470,6 +1470,7 @@ virNetlinkEventRemoveClient;
>  virNetlinkEventServiceIsRunning;
>  virNetlinkEventServiceLocalPid;
>  virNetlinkEventServiceStop;
> +virNetlinkEventServiceStopAll;
>  virNetlinkEventServiceStart;

  that's not kept in order but not really your fault ;-)

>  virNetlinkShutdown;
>  virNetlinkStartup;
> diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
> index 64bd47d..944ebe1 100644
> --- a/src/util/virnetlink.c
> +++ b/src/util/virnetlink.c
> @@ -404,6 +404,46 @@ virNetlinkEventServiceStop(unsigned int protocol)
>  }
>  
>  /**
> + * virNetlinkEventServiceStopAll:
> + *
> + * Stop all the monitors to receive netlink messages for libvirtd.
> + *
> + * Returns -1 if any monitor cannot be unregistered, 0 upon success
> + */
> +int
> +virNetlinkEventServiceStopAll(void)
> +{
> +    unsigned int i, j;
> +
> +    VIR_INFO("stopping all netlink event services");
> +
> +    virNetlinkEventSrvPrivatePtr srv = NULL;

  aestetic, we usually define variables before code in the function
  block

> +    for (i = 0; i < MAX_LINKS; i++) {
> +        srv = server[i];
> +        if (!srv)
> +            continue;
> +
> +        virNetlinkEventServerLock(srv);
> +        nl_close(srv->netlinknh);
> +        virNetlinkFree(srv->netlinknh);
> +        virEventRemoveHandle(srv->eventwatch);
> +
> +        for (j = 0; j < srv->handlesCount; j++) {
> +            if (srv->handles[j].deleted == VIR_NETLINK_HANDLE_VALID)
> +                virNetlinkEventRemoveClientPrimitive(j, i);
> +        }
> +
> +        server[i] = NULL;
> +        virNetlinkEventServerUnlock(srv);
> +
> +        virMutexDestroy(&srv->lock);
> +        VIR_FREE(srv);
> +    }
> +
> +    return 0;
> +}
> +
> +/**
>   * virNetlinkEventServiceIsRunning:
>   *
>   * Returns if the netlink event service is running.
> @@ -731,6 +771,16 @@ int virNetlinkEventServiceStop(unsigned int protocol ATTRIBUTE_UNUSED)
>  }
>  
>  /**
> + * stopNetlinkEventServerAll: stop all the monitors to receive netlink
> + * messages for libvirtd
> + */
> +int virNetlinkEventServiceStopAll(void)
> +{
> +    VIR_DEBUG("%s", _(unsupported));
> +    return 0;
> +}
> +
> +/**
>   * startNetlinkEventServer: start a monitor to receive netlink
>   * messages for libvirtd
>   */
> diff --git a/src/util/virnetlink.h b/src/util/virnetlink.h
> index 2e18af4..1982dae 100644
> --- a/src/util/virnetlink.h
> +++ b/src/util/virnetlink.h
> @@ -54,6 +54,11 @@ typedef void (*virNetlinkEventRemoveCallback)(int watch, const virMacAddrPtr mac
>  int virNetlinkEventServiceStop(unsigned int protocol);
>  
>  /**
> + * stopNetlinkEventServerAll: stop all the monitors to receive netlink messages for libvirtd
> + */
> +int virNetlinkEventServiceStopAll(void);
> +
> +/**
>   * startNetlinkEventServer: start a monitor to receive netlink messages for libvirtd
>   */
>  int virNetlinkEventServiceStart(unsigned int protocol, unsigned int groups);
> -- 

  Okay, ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel at veillard.com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/




More information about the libvir-list mailing list