1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2024-12-23 21:34:54 +03:00

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
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;

View File

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