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

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

 



This patch introduce virNetlinkEventServiceStopAll() to stop
all the monitors to receive netlink messages for libvirtd.

Signed-off-by: Tang Chen <tangchen@xxxxxxxxxxxxxx>
---
 src/libvirt_private.syms |    1 +
 src/util/virnetlink.c    |   50 ++++++++++++++++++++++++++++++++++++++++++++++
 src/util/virnetlink.h    |    5 +++++
 3 files changed, 56 insertions(+)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 03f7f3e..5880cc4 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1382,6 +1382,7 @@ virNetlinkEventRemoveClient;
 virNetlinkEventServiceIsRunning;
 virNetlinkEventServiceLocalPid;
 virNetlinkEventServiceStop;
+virNetlinkEventServiceStopAll;
 virNetlinkEventServiceStart;
 virNetlinkShutdown;
 virNetlinkStartup;
diff --git a/src/util/virnetlink.c b/src/util/virnetlink.c
index c1e198d..401a8eb 100644
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -405,6 +405,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;
+    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.
@@ -742,6 +782,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 6b572ff..fbd0df8 100644
--- a/src/util/virnetlink.h
+++ b/src/util/virnetlink.h
@@ -56,6 +56,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);
-- 
1.7.10.2

--
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]