[PATCH v2 1/3] Add helper APIs to track if libvirtd or loadable modules have changed

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

 



The future QEMU capabilities cache needs to be able to invalidate
itself if the libvirtd binary or any loadable modules are changed
on disk. Record the 'ctime' value for these binaries and provide
helper APIs to query it. This approach assumes that if libvirt.so
is changed, then libvirtd will also change, which should usually
be the case with libtool's wrapper scripts that cause libvirtd to
get re-linked

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 daemon/libvirtd.c        |  2 ++
 src/driver.c             |  2 ++
 src/libvirt_private.syms |  2 ++
 src/util/virutil.c       | 23 +++++++++++++++++++++++
 src/util/virutil.h       |  4 ++++
 5 files changed, 33 insertions(+)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 72f0e81..36adaf0 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1152,6 +1152,8 @@ int main(int argc, char **argv) {
         exit(EXIT_FAILURE);
     }
 
+    virUpdateSelfLastChanged(argv[0]);
+
     if (strstr(argv[0], "lt-libvirtd") ||
         strstr(argv[0], "/daemon/.libs/libvirtd")) {
         char *tmp = strrchr(argv[0], '/');
diff --git a/src/driver.c b/src/driver.c
index ab2a253..721cbeb 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -74,6 +74,8 @@ virDriverLoadModule(const char *name)
         goto cleanup;
     }
 
+    virUpdateSelfLastChanged(modfile);
+
     handle = dlopen(modfile, RTLD_NOW | RTLD_GLOBAL);
     if (!handle) {
         VIR_ERROR(_("failed to load module %s %s"), modfile, dlerror());
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 00e3d9c..f1607cd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1954,6 +1954,7 @@ virGetGroupID;
 virGetGroupList;
 virGetGroupName;
 virGetHostname;
+virGetSelfLastChanged;
 virGetUnprivSGIOSysfsPath;
 virGetUserCacheDirectory;
 virGetUserConfigDirectory;
@@ -1983,6 +1984,7 @@ virSetNonBlock;
 virSetUIDGID;
 virSetUIDGIDWithCaps;
 virStrIsPrint;
+virUpdateSelfLastChanged;
 virValidateWWN;
 
 
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 7a2fbb0..b6106fc 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -2173,3 +2173,26 @@ bool virIsSUID(void)
 {
     return getuid() != geteuid();
 }
+
+
+static time_t selfLastChanged;
+
+time_t virGetSelfLastChanged(void)
+{
+    return selfLastChanged;
+}
+
+
+void virUpdateSelfLastChanged(const char *path)
+{
+    struct stat sb;
+
+    if (stat(path, &sb) < 0)
+        return;
+
+    if (sb.st_ctime > selfLastChanged) {
+        VIR_DEBUG("Setting self last changed to %lld for '%s'",
+                  (long long)sb.st_ctime, path);
+        selfLastChanged = sb.st_ctime;
+    }
+}
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 029265c..cffe1ed 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -194,4 +194,8 @@ const char *virGetEnvBlockSUID(const char *name);
 const char *virGetEnvAllowSUID(const char *name);
 bool virIsSUID(void);
 
+
+time_t virGetSelfLastChanged(void);
+void virUpdateSelfLastChanged(const char *path);
+
 #endif /* __VIR_UTIL_H__ */
-- 
1.8.5.3

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