[libvirt] [PATCH v2 3/6] qemu: move virQEMUCapsIsValid before its usage and make it static

Pavel Hrdina phrdina at redhat.com
Wed Jul 19 15:09:48 UTC 2017


Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
Reviewed-by: Jiri Denemark <jdenemar at redhat.com>
---
 src/qemu/qemu_capabilities.c | 112 +++++++++++++++++++++----------------------
 src/qemu/qemu_capabilities.h |   5 --
 2 files changed, 56 insertions(+), 61 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 61dc5f4a82..1eaba204e3 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -4281,6 +4281,62 @@ virQEMUCapsReset(virQEMUCapsPtr qemuCaps)
 }
 
 
+static bool
+virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
+                   time_t qemuctime,
+                   uid_t runUid,
+                   gid_t runGid)
+{
+    bool kvmUsable;
+
+    if (!qemuCaps->binary)
+        return true;
+
+    if (!qemuctime) {
+        struct stat sb;
+
+        if (stat(qemuCaps->binary, &sb) < 0) {
+            char ebuf[1024];
+            VIR_DEBUG("Failed to stat QEMU binary '%s': %s",
+                      qemuCaps->binary,
+                      virStrerror(errno, ebuf, sizeof(ebuf)));
+            return false;
+        }
+        qemuctime = sb.st_ctime;
+    }
+
+    if (qemuctime != qemuCaps->ctime) {
+        VIR_DEBUG("Outdated capabilities for '%s': QEMU binary changed "
+                  "(%lld vs %lld)",
+                  qemuCaps->binary,
+                  (long long) qemuctime, (long long) qemuCaps->ctime);
+        return false;
+    }
+
+    kvmUsable = virFileAccessibleAs("/dev/kvm", R_OK | W_OK,
+                                    runUid, runGid) == 0;
+
+    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
+        virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) &&
+        kvmUsable) {
+        VIR_DEBUG("KVM was not enabled when probing '%s', "
+                  "but it should be usable now",
+                  qemuCaps->binary);
+        return false;
+    }
+
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
+        !kvmUsable) {
+        VIR_DEBUG("KVM was enabled when probing '%s', "
+                  "but it is not available now",
+                  qemuCaps->binary);
+        return false;
+    }
+
+    return true;
+}
+
+
 static int
 virQEMUCapsInitCached(virCapsPtr caps,
                       virQEMUCapsPtr qemuCaps,
@@ -5275,62 +5331,6 @@ virQEMUCapsNewForBinary(virCapsPtr caps,
 }
 
 
-bool
-virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
-                   time_t qemuctime,
-                   uid_t runUid,
-                   gid_t runGid)
-{
-    bool kvmUsable;
-
-    if (!qemuCaps->binary)
-        return true;
-
-    if (!qemuctime) {
-        struct stat sb;
-
-        if (stat(qemuCaps->binary, &sb) < 0) {
-            char ebuf[1024];
-            VIR_DEBUG("Failed to stat QEMU binary '%s': %s",
-                      qemuCaps->binary,
-                      virStrerror(errno, ebuf, sizeof(ebuf)));
-            return false;
-        }
-        qemuctime = sb.st_ctime;
-    }
-
-    if (qemuctime != qemuCaps->ctime) {
-        VIR_DEBUG("Outdated capabilities for '%s': QEMU binary changed "
-                  "(%lld vs %lld)",
-                  qemuCaps->binary,
-                  (long long) qemuctime, (long long) qemuCaps->ctime);
-        return false;
-    }
-
-    kvmUsable = virFileAccessibleAs("/dev/kvm", R_OK | W_OK,
-                                    runUid, runGid) == 0;
-
-    if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
-        virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) &&
-        kvmUsable) {
-        VIR_DEBUG("KVM was not enabled when probing '%s', "
-                  "but it should be usable now",
-                  qemuCaps->binary);
-        return false;
-    }
-
-    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
-        !kvmUsable) {
-        VIR_DEBUG("KVM was enabled when probing '%s', "
-                  "but it is not available now",
-                  qemuCaps->binary);
-        return false;
-    }
-
-    return true;
-}
-
-
 struct virQEMUCapsMachineTypeFilter {
     const char *machineType;
     virQEMUCapsFlags *flags;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 8250b57b46..bd44b90002 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -495,11 +495,6 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps,
                                    size_t *nmachines,
                                    virCapsGuestMachinePtr **machines);
 
-bool virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
-                        time_t ctime,
-                        uid_t runUid,
-                        gid_t runGid);
-
 void virQEMUCapsFilterByMachineType(virQEMUCapsPtr qemuCaps,
                                     const char *machineType);
 
-- 
2.13.3




More information about the libvir-list mailing list