qemu: add qemu caps constructor which takes binary name

Simplify repeated code patterns by providing a new constructor taking
the QEMU binary name.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-12-20 12:28:57 +00:00
parent 25db737471
commit 0fcc78d51b
2 changed files with 15 additions and 9 deletions

View File

@ -1649,6 +1649,17 @@ virQEMUCapsNew(void)
} }
virQEMUCapsPtr
virQEMUCapsNewBinary(const char *binary)
{
virQEMUCapsPtr qemuCaps = virQEMUCapsNew();
qemuCaps->binary = g_strdup(binary);
return qemuCaps;
}
void void
virQEMUCapsSetInvalidation(virQEMUCapsPtr qemuCaps, virQEMUCapsSetInvalidation(virQEMUCapsPtr qemuCaps,
bool enabled) bool enabled)
@ -1750,7 +1761,7 @@ virQEMUCapsAccelCopy(virQEMUCapsAccelPtr dst,
virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
{ {
virQEMUCapsPtr ret = virQEMUCapsNew(); virQEMUCapsPtr ret = virQEMUCapsNewBinary(qemuCaps->binary);
size_t i; size_t i;
if (!ret) if (!ret)
@ -1760,8 +1771,6 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps)
ret->usedQMP = qemuCaps->usedQMP; ret->usedQMP = qemuCaps->usedQMP;
ret->kvmSupportsNesting = qemuCaps->kvmSupportsNesting; ret->kvmSupportsNesting = qemuCaps->kvmSupportsNesting;
ret->binary = g_strdup(qemuCaps->binary);
ret->ctime = qemuCaps->ctime; ret->ctime = qemuCaps->ctime;
virBitmapCopy(ret->flags, qemuCaps->flags); virBitmapCopy(ret->flags, qemuCaps->flags);
@ -4950,11 +4959,9 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch,
virQEMUCapsPtr qemuCaps; virQEMUCapsPtr qemuCaps;
struct stat sb; struct stat sb;
if (!(qemuCaps = virQEMUCapsNew())) if (!(qemuCaps = virQEMUCapsNewBinary(binary)))
goto error; goto error;
qemuCaps->binary = g_strdup(binary);
/* We would also want to check faccessat if we cared about ACLs, /* We would also want to check faccessat if we cared about ACLs,
* but we don't. */ * but we don't. */
if (stat(binary, &sb) < 0) { if (stat(binary, &sb) < 0) {
@ -5021,14 +5028,12 @@ virQEMUCapsLoadFile(const char *filename,
const char *binary, const char *binary,
void *privData) void *privData)
{ {
virQEMUCapsPtr qemuCaps = virQEMUCapsNew(); virQEMUCapsPtr qemuCaps = virQEMUCapsNewBinary(binary);
virQEMUCapsCachePrivPtr priv = privData; virQEMUCapsCachePrivPtr priv = privData;
if (!qemuCaps) if (!qemuCaps)
return NULL; return NULL;
qemuCaps->binary = g_strdup(binary);
if (virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename) < 0) if (virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename) < 0)
goto error; goto error;

View File

@ -544,6 +544,7 @@ typedef virQEMUCaps *virQEMUCapsPtr;
G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUCaps, virObjectUnref); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virQEMUCaps, virObjectUnref);
virQEMUCapsPtr virQEMUCapsNew(void); virQEMUCapsPtr virQEMUCapsNew(void);
virQEMUCapsPtr virQEMUCapsNewBinary(const char *binary);
void virQEMUCapsSet(virQEMUCapsPtr qemuCaps, void virQEMUCapsSet(virQEMUCapsPtr qemuCaps,
virQEMUCapsFlags flag) ATTRIBUTE_NONNULL(1); virQEMUCapsFlags flag) ATTRIBUTE_NONNULL(1);