]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Check for changes in qemu modules directory
authorJim Fehlig <jfehlig@suse.com>
Thu, 20 Aug 2020 21:52:17 +0000 (15:52 -0600)
committerJim Fehlig <jfehlig@suse.com>
Tue, 1 Sep 2020 20:22:24 +0000 (14:22 -0600)
Add a configuration option for specifying location of the qemu modules
directory, defaulting to /usr/lib64/qemu. Then use this location to
check for changes in the directory, indicating that a qemu module has
changed and capabilities need to be reprobed.

Signed-off-by: Jim Fehlig <jfehlig@suse.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
meson.build
meson_options.txt
src/qemu/qemu_capabilities.c

index cc2a4bf5c715a00d0c2987eaa12e66688aff7c1d..7435b23df91f2a55b5d66211889518aa4f116bb7 100644 (file)
@@ -1761,6 +1761,12 @@ if not get_option('driver_qemu').disabled()
   if use_qemu
     conf.set('WITH_QEMU', 1)
 
+    qemu_moddir = get_option('qemu_moddir')
+    if qemu_moddir == ''
+      qemu_moddir = '/usr' / libdir / 'qemu'
+    endif
+    conf.set_quoted('QEMU_MODDIR', qemu_moddir)
+
     if host_machine.system() in ['freebsd', 'darwin']
       default_qemu_user = 'root'
       default_qemu_group = 'wheel'
index 79554c318611ec724af72eccb7a66ce9a978024a..7838630c1e9187fdf027b6fdf906362b5fb97eb2 100644 (file)
@@ -60,6 +60,7 @@ option('driver_openvz', type: 'feature', value: 'auto', description: 'OpenVZ dri
 option('driver_qemu', type: 'feature', value: 'auto', description: 'QEMU/KVM driver')
 option('qemu_user', type: 'string', value: '', description: 'username to run QEMU system instance as')
 option('qemu_group', type: 'string', value: '', description: 'groupname to run QEMU system instance as')
+option('qemu_moddir', type: 'string', value: '', description: 'set the directory where QEMU modules are located')
 option('driver_remote', type: 'feature', value: 'enabled', description: 'remote driver')
 option('remote_default_mode', type: 'combo', choices: ['legacy', 'direct'], value: 'legacy', description: 'remote driver default mode')
 option('driver_secrets', type: 'feature', value: 'auto', description: 'local secrets management driver')
index dcfd7cdd4eb54716a91addb70b171ad1db3d256a..2cc0c61588f56f26cb29b8149c6d56eb4724ad70 100644 (file)
@@ -677,6 +677,7 @@ struct _virQEMUCaps {
     char *binary;
     time_t ctime;
     time_t libvirtCtime;
+    time_t modDirMtime;
     bool invalidation;
 
     virBitmapPtr flags;
@@ -4194,6 +4195,7 @@ virQEMUCapsParseSEVInfo(virQEMUCapsPtr qemuCaps, xmlXPathContextPtr ctxt)
  * <qemuCaps>
  *   <emulator>/some/path</emulator>
  *   <qemuctime>234235253</qemuctime>
+ *   <qemumoddirmtime>234235253</qemumoddirmtime>
  *   <selfctime>234235253</selfctime>
  *   <selfvers>1002016</selfvers>
  *   <flag name='foo'/>
@@ -4283,6 +4285,9 @@ virQEMUCapsLoadCache(virArch hostArch,
     }
     qemuCaps->ctime = (time_t)l;
 
+    if (virXPathLongLong("string(./qemumoddirmtime)", ctxt, &l) == 0)
+        qemuCaps->modDirMtime = (time_t)l;
+
     if ((n = virXPathNodeSet("./flag", ctxt, &nodes)) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("failed to parse qemu capabilities flags"));
@@ -4615,6 +4620,10 @@ virQEMUCapsFormatCache(virQEMUCapsPtr qemuCaps)
                           qemuCaps->binary);
     virBufferAsprintf(&buf, "<qemuctime>%llu</qemuctime>\n",
                       (long long)qemuCaps->ctime);
+    if (qemuCaps->modDirMtime > 0) {
+        virBufferAsprintf(&buf, "<qemumoddirmtime>%llu</qemumoddirmtime>\n",
+                          (long long)qemuCaps->modDirMtime);
+    }
     virBufferAsprintf(&buf, "<selfctime>%llu</selfctime>\n",
                       (long long)qemuCaps->libvirtCtime);
     virBufferAsprintf(&buf, "<selfvers>%lu</selfvers>\n",
@@ -4881,6 +4890,23 @@ virQEMUCapsIsValid(void *data,
     if (!qemuCaps->binary)
         return true;
 
+    if (virFileExists(QEMU_MODDIR)) {
+        if (stat(QEMU_MODDIR, &sb) < 0) {
+            VIR_DEBUG("Failed to stat QEMU module directory '%s': %s",
+                      QEMU_MODDIR,
+                      g_strerror(errno));
+            return false;
+        }
+
+        if (sb.st_mtime != qemuCaps->modDirMtime) {
+            VIR_DEBUG("Outdated capabilities for '%s': QEMU modules "
+                      "directory '%s' changed (%lld vs %lld)",
+                      qemuCaps->binary, QEMU_MODDIR,
+                      (long long)sb.st_mtime, (long long)qemuCaps->modDirMtime);
+            return false;
+        }
+    }
+
     if (qemuCaps->libvirtCtime != virGetSelfLastChanged() ||
         qemuCaps->libvirtVersion != LIBVIR_VERSION_NUMBER) {
         VIR_DEBUG("Outdated capabilities for '%s': libvirt changed "
@@ -5463,6 +5489,15 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
         goto error;
     }
 
+    if (virFileExists(QEMU_MODDIR)) {
+        if (stat(QEMU_MODDIR, &sb) < 0) {
+            virReportSystemError(errno, _("Cannot check QEMU module directory %s"),
+                                 QEMU_MODDIR);
+            goto error;
+        }
+        qemuCaps->modDirMtime = sb.st_mtime;
+    }
+
     if (virQEMUCapsInitQMP(qemuCaps, libDir, runUid, runGid) < 0)
         goto error;