This will store private data that will be used by following patches
when switching to virFileCache.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
Reviewed-by: Jiri Denemark <jdenemar(a)redhat.com>
---
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 b7351322bc..c310e97f61 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -3764,6 +3764,14 @@ virQEMUCapsLoadCPUModels(virQEMUCapsPtr qemuCaps,
}
+static void
+virQEMUCapsCachePrivFree(virQEMUCapsCachePrivPtr priv)
+{
+ VIR_FREE(priv->libDir);
+ VIR_FREE(priv);
+}
+
+
/*
* Parsing a doc that looks like
*
@@ -4252,8 +4260,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;
@@ -4290,7 +4297,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) &&
@@ -4318,8 +4325,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;
@@ -4370,7 +4376,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",
@@ -5275,22 +5281,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;
}
@@ -5364,13 +5369,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;
@@ -5387,7 +5396,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);
@@ -5397,8 +5406,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) {
@@ -5517,7 +5526,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.3