[libvirt] [PATCH] Refresh /etc/xen if inotify wasn't initialized

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

 



If libvirt was built against inotify, but an API user isn't using domain
events (virsh, virt-manager), the xen xm driver doesn't poll /etc/xen
for new config files. This means that domains created or deleted on
other libvirt connections aren't reflected in the original connection
(but they will show up for all newly opened connections). This causes
newly created VMs to disappear from virt-manager < 0.8.0 once they are
shutdown, since VMs were installed on a separate connection.

The attached patch refreshes /etc/xen in all cases, unless inotify was
successfully initialized (user is using domain events).

Thanks,
Cole
diff --git a/src/xm_internal.c b/src/xm_internal.c
index 9d021eb..c1188fe 100644
--- a/src/xm_internal.c
+++ b/src/xm_internal.c
@@ -122,6 +122,19 @@ struct xenUnifiedDriver xenXMDriver = {
         virReportErrorHelper(conn, VIR_FROM_XENXM, code, __FILE__,         \
                                __FUNCTION__, __LINE__, fmt)
 
+static int xenInotifyActive(virConnectPtr conn)
+{
+    int ret;
+#ifndef WITH_XEN_INOTIFY
+    ret = 0;
+#else
+    xenUnifiedPrivatePtr priv = (xenUnifiedPrivatePtr) conn->privateData;
+    ret = (priv->inotifyWatch > 0);
+#endif
+
+    return ret;
+}
+
 /* Convenience method to grab a int from the config file object */
 static int xenXMConfigGetBool(virConnectPtr conn,
                               virConfPtr conf,
@@ -1737,10 +1750,8 @@ virDomainPtr xenXMDomainLookupByName(virConnectPtr conn, const char *domname) {
     priv = conn->privateData;
     xenUnifiedLock(priv);
 
-#ifndef WITH_XEN_INOTIFY
-    if (xenXMConfigCacheRefresh (conn) < 0)
+    if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh (conn) < 0)
         goto cleanup;
-#endif
 
     if (!(filename = virHashLookup(priv->nameConfigMap, domname)))
         goto cleanup;
@@ -1795,10 +1806,8 @@ virDomainPtr xenXMDomainLookupByUUID(virConnectPtr conn,
     priv = conn->privateData;
     xenUnifiedLock(priv);
 
-#ifndef WITH_XEN_INOTIFY
-    if (xenXMConfigCacheRefresh (conn) < 0)
+    if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh (conn) < 0)
         goto cleanup;
-#endif
 
     if (!(entry = virHashSearch(priv->configCache, xenXMDomainSearchForUUID, (const void *)uuid)))
         goto cleanup;
@@ -2551,12 +2560,10 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml) {
 
     xenUnifiedLock(priv);
 
-#ifndef WITH_XEN_INOTIFY
-    if (xenXMConfigCacheRefresh (conn) < 0) {
+    if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh (conn) < 0) {
         xenUnifiedUnlock(priv);
         return (NULL);
     }
-#endif
 
     if (!(def = virDomainDefParseString(conn, priv->caps, xml,
                                         VIR_DOMAIN_XML_INACTIVE))) {
@@ -2741,10 +2748,8 @@ int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
     priv = conn->privateData;
     xenUnifiedLock(priv);
 
-#ifndef WITH_XEN_INOTIFY
-    if (xenXMConfigCacheRefresh (conn) < 0)
+    if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh (conn) < 0)
         goto cleanup;
-#endif
 
     if (maxnames > virHashSize(priv->configCache))
         maxnames = virHashSize(priv->configCache);
@@ -2757,9 +2762,7 @@ int xenXMListDefinedDomains(virConnectPtr conn, char **const names, int maxnames
     virHashForEach(priv->nameConfigMap, xenXMListIterator, &ctx);
     ret = ctx.count;
 
-#ifndef WITH_XEN_INOTIFY
 cleanup:
-#endif
     xenUnifiedUnlock(priv);
     return ret;
 }
@@ -2780,16 +2783,12 @@ int xenXMNumOfDefinedDomains(virConnectPtr conn) {
     priv = conn->privateData;
     xenUnifiedLock(priv);
 
-#ifndef WITH_XEN_INOTIFY
-    if (xenXMConfigCacheRefresh (conn) < 0)
+    if (!xenInotifyActive(conn) && xenXMConfigCacheRefresh (conn) < 0)
         goto cleanup;
-#endif
 
     ret = virHashSize(priv->nameConfigMap);
 
-#ifndef WITH_XEN_INOTIFY
 cleanup:
-#endif
     xenUnifiedUnlock(priv);
     return ret;
 }
--
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]