[PATCH 09/11] qemu: introduce struct _virQEMUCapsCachePriv

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

 



This will store private data that will be used by following patches
when switching to virFileCache.

Signed-off-by: Pavel Hrdina <phrdina@xxxxxxxxxx>
---
 src/qemu/qemu_capabilities.c | 51 ++++++++++++++++++++++++++------------------
 src/qemu/qemu_capspriv.h     | 12 ++++++++---
 2 files changed, 39 insertions(+), 24 deletions(-)

diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 1f3240b942..e190cfa8b1 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3765,6 +3765,14 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
 }
 
 
+static void
+virQEMUCapsCachePrivFree(virQEMUCapsCachePrivPtr priv)
+{
+    VIR_FREE(priv->libDir);
+    VIR_FREE(priv);
+}
+
+
 /*
  * Parsing a doc that looks like
  *
@@ -4253,8 +4261,7 @@ virQEMUCapsRememberCached(virQEMUCapsPtr qemuCaps, const char *cacheDir)
 
 static bool
 virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
-                   uid_t runUid,
-                   gid_t runGid)
+                   virQEMUCapsCachePrivPtr priv)
 {
     bool kvmUsable;
     struct stat sb;
@@ -4291,7 +4298,7 @@ virQEMUCapsIsValid(virQEMUCapsPtr qemuCaps,
     }
 
     kvmUsable = virFileAccessibleAs("/dev/kvm", R_OK | W_OK,
-                                    runUid, runGid) == 0;
+                                    priv->runUid, priv->runGid) == 0;
 
     if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM) &&
         virQEMUCapsGet(qemuCaps, QEMU_CAPS_ENABLE_KVM) &&
@@ -4319,8 +4326,7 @@ virQEMUCapsInitCached(virCapsPtr caps,
                       virQEMUCapsPtr *qemuCaps,
                       const char *binary,
                       const char *cacheDir,
-                      uid_t runUid,
-                      gid_t runGid)
+                      virQEMUCapsCachePrivPtr priv)
 {
     char *capsdir = NULL;
     char *capsfile = NULL;
@@ -4371,7 +4377,7 @@ virQEMUCapsInitCached(virCapsPtr caps,
         goto discard;
     }
 
-    if (!virQEMUCapsIsValid(qemuCapsNew, runUid, runGid))
+    if (!virQEMUCapsIsValid(qemuCapsNew, priv))
         goto discard;
 
     VIR_DEBUG("Loaded '%s' for '%s' ctime %lld usedQMP=%d",
@@ -5277,22 +5283,21 @@ virQEMUCapsNewForBinaryInternal(virCapsPtr caps,
 static virQEMUCapsPtr
 virQEMUCapsNewForBinary(virCapsPtr caps,
                         const char *binary,
-                        const char *libDir,
                         const char *cacheDir,
-                        uid_t runUid,
-                        gid_t runGid)
+                        virQEMUCapsCachePrivPtr priv)
 {
     int rv;
     virQEMUCapsPtr qemuCaps = NULL;
 
-    if ((rv = virQEMUCapsInitCached(caps, &qemuCaps, binary, cacheDir,
-                                    runUid, runGid)) < 0)
+    if ((rv = virQEMUCapsInitCached(caps, &qemuCaps, binary, cacheDir, priv)) < 0)
         goto error;
 
     if (rv == 0) {
         if (!(qemuCaps = virQEMUCapsNewForBinaryInternal(caps, binary,
-                                                         libDir, runUid,
-                                                         runGid, false))) {
+                                                         priv->libDir,
+                                                         priv->runUid,
+                                                         priv->runGid,
+                                                         false))) {
             goto error;
         }
 
@@ -5366,13 +5371,17 @@ virQEMUCapsCacheNew(const char *libDir,
 
     if (!(cache->binaries = virHashCreate(10, virObjectFreeHashData)))
         goto error;
-    if (VIR_STRDUP(cache->libDir, libDir) < 0)
-        goto error;
     if (VIR_STRDUP(cache->cacheDir, cacheDir) < 0)
         goto error;
 
-    cache->runUid = runUid;
-    cache->runGid = runGid;
+    if (VIR_ALLOC(cache->priv) < 0)
+        goto error;
+
+    if (VIR_STRDUP(cache->priv->libDir, libDir) < 0)
+        goto error;
+
+    cache->priv->runUid = runUid;
+    cache->priv->runGid = runGid;
 
     return cache;
 
@@ -5389,7 +5398,7 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache,
                          virQEMUCapsPtr *qemuCaps)
 {
     if (*qemuCaps &&
-        !virQEMUCapsIsValid(*qemuCaps, cache->runUid, cache->runGid)) {
+        !virQEMUCapsIsValid(*qemuCaps, cache->priv)) {
         VIR_DEBUG("Cached capabilities %p no longer valid for %s",
                   *qemuCaps, binary);
         virHashRemoveEntry(cache->binaries, binary);
@@ -5399,8 +5408,8 @@ virQEMUCapsCacheValidate(virQEMUCapsCachePtr cache,
     if (!*qemuCaps) {
         VIR_DEBUG("Creating capabilities for %s", binary);
         *qemuCaps = virQEMUCapsNewForBinary(caps, binary,
-                                            cache->libDir, cache->cacheDir,
-                                            cache->runUid, cache->runGid);
+                                            cache->cacheDir,
+                                            cache->priv);
         if (*qemuCaps) {
             VIR_DEBUG("Caching capabilities %p for %s", *qemuCaps, binary);
             if (virHashAddEntry(cache->binaries, binary, *qemuCaps) < 0) {
@@ -5519,7 +5528,7 @@ virQEMUCapsCacheFree(virQEMUCapsCachePtr cache)
     if (!cache)
         return;
 
-    VIR_FREE(cache->libDir);
+    virQEMUCapsCachePrivFree(cache->priv);
     VIR_FREE(cache->cacheDir);
     virHashFree(cache->binaries);
     virMutexDestroy(&cache->lock);
diff --git a/src/qemu/qemu_capspriv.h b/src/qemu/qemu_capspriv.h
index 3458fc0700..61e7c34d12 100644
--- a/src/qemu/qemu_capspriv.h
+++ b/src/qemu/qemu_capspriv.h
@@ -28,13 +28,19 @@
 #ifndef __QEMU_CAPSPRIV_H__
 # define __QEMU_CAPSPRIV_H__
 
+struct _virQEMUCapsCachePriv {
+    char *libDir;
+    uid_t runUid;
+    gid_t runGid;
+};
+typedef struct _virQEMUCapsCachePriv virQEMUCapsCachePriv;
+typedef virQEMUCapsCachePriv *virQEMUCapsCachePrivPtr;
+
 struct _virQEMUCapsCache {
     virMutex lock;
     virHashTablePtr binaries;
-    char *libDir;
     char *cacheDir;
-    uid_t runUid;
-    gid_t runGid;
+    virQEMUCapsCachePrivPtr priv;
 };
 
 virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps);
-- 
2.13.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]
  Powered by Linux