Simplify repeated code patterns by providing a new constructor taking
the QEMU binary name.
Signed-off-by: Daniel P. Berrangé <berrange(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 23 ++++++++++++++---------
src/qemu/qemu_capabilities.h | 1 +
2 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index cc6d9bbd44..2ab7ead92e 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1649,6 +1649,17 @@ virQEMUCapsNew(void)
}
+virQEMUCapsPtr
+virQEMUCapsNewBinary(const char *binary)
+{
+ virQEMUCapsPtr qemuCaps = virQEMUCapsNew();
+
+ qemuCaps->binary = g_strdup(binary);
+
+ return qemuCaps;
+}
+
+
void
virQEMUCapsSetInvalidation(virQEMUCapsPtr qemuCaps,
bool enabled)
@@ -1750,7 +1761,7 @@ virQEMUCapsAccelCopy(virQEMUCapsAccelPtr dst,
virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
{
- virQEMUCapsPtr ret = virQEMUCapsNew();
+ virQEMUCapsPtr ret = virQEMUCapsNewBinary(qemuCaps->binary);
size_t i;
if (!ret)
@@ -1760,8 +1771,6 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
ret->usedQMP = qemuCaps->usedQMP;
ret->kvmSupportsNesting = qemuCaps->kvmSupportsNesting;
- ret->binary = g_strdup(qemuCaps->binary);
-
ret->ctime = qemuCaps->ctime;
virBitmapCopy(ret->flags, qemuCaps->flags);
@@ -4950,11 +4959,9 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
virQEMUCapsPtr qemuCaps;
struct stat sb;
- if (!(qemuCaps = virQEMUCapsNew()))
+ if (!(qemuCaps = virQEMUCapsNewBinary(binary)))
goto error;
- qemuCaps->binary = g_strdup(binary);
-
/* We would also want to check faccessat if we cared about ACLs,
* but we don't. */
if (stat(binary, &sb) < 0) {
@@ -5021,14 +5028,12 @@ virQEMUCapsLoadFile(const char *filename,
const char *binary,
void *privData)
{
- virQEMUCapsPtr qemuCaps = virQEMUCapsNew();
+ virQEMUCapsPtr qemuCaps = virQEMUCapsNewBinary(binary);
virQEMUCapsCachePrivPtr priv = privData;
if (!qemuCaps)
return NULL;
- qemuCaps->binary = g_strdup(binary);
-
if (virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename) < 0)
goto error;
diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h
index 7488b9ddb8..70225926bf 100644
--- a/src/qemu/qemu_capabilities.h
+++ b/src/qemu/qemu_capabilities.h
@@ -544,6 +544,7 @@ typedef virQEMUCaps *virQEMUCapsPtr;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUCaps, virObjectUnref);
virQEMUCapsPtr virQEMUCapsNew(void);
+virQEMUCapsPtr virQEMUCapsNewBinary(const char *binary);
void virQEMUCapsSetInvalidation(virQEMUCapsPtr qemuCaps,
bool enabled);
--
2.23.0