The 'virCommand' helpers already look up the full path to the binary in
PATH if it's not specified. This means that the qemu driver doesn't have
to lookup and store the path to 'qemu-img' in the conf object but rather
can be cleaned up to use this new infrastructure.
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
src/qemu/qemu_conf.h | 3 ---
src/qemu/qemu_domain.c | 20 +-------------------
src/qemu/qemu_domain.h | 2 --
src/qemu/qemu_driver.c | 3 ---
src/qemu/qemu_snapshot.c | 33 +++++++++------------------------
5 files changed, 10 insertions(+), 51 deletions(-)
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index 157aba9e18..23a900193e 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -271,9 +271,6 @@ struct _virQEMUDriver {
/* Immutable pointer, self-locking APIs */
virDomainObjList *domains;
- /* Immutable pointer */
- char *qemuImgBinary;
-
/* Immutable pointer, lockless APIs. Pointless abstraction */
ebtablesContext *ebtables;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c798ef37fd..e8e72e5091 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -5671,17 +5671,6 @@ qemuDomainLogAppendMessage(virQEMUDriver *driver,
}
-/* Locate an appropriate 'qemu-img' binary. */
-const char *
-qemuFindQemuImgBinary(virQEMUDriver *driver)
-{
- if (!driver->qemuImgBinary)
- virReportError(VIR_ERR_INTERNAL_ERROR,
- "%s", _("unable to find qemu-img"));
-
- return driver->qemuImgBinary;
-}
-
int
qemuDomainSnapshotWriteMetadata(virDomainObj *vm,
virDomainMomentObj *snapshot,
@@ -5727,18 +5716,11 @@ qemuDomainSnapshotForEachQcow2Raw(virQEMUDriver *driver,
int ndisks)
{
virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
- const char *qemuimgbin;
size_t i;
bool skipped = false;
- qemuimgbin = qemuFindQemuImgBinary(driver);
- if (qemuimgbin == NULL) {
- /* qemuFindQemuImgBinary set the error */
- return -1;
- }
-
for (i = 0; i < ndisks; i++) {
- g_autoptr(virCommand) cmd = virCommandNewArgList(qemuimgbin, "snapshot",
+ g_autoptr(virCommand) cmd = virCommandNewArgList("qemu-img", "snapshot",
op, snap->def->name, NULL);
int format = virDomainDiskGetFormat(def->disks[i]);
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 1ae421e5f2..091b27823b 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -665,8 +665,6 @@ int qemuDomainLogAppendMessage(virQEMUDriver *driver,
const char *fmt,
...) G_GNUC_PRINTF(3, 4);
-const char *qemuFindQemuImgBinary(virQEMUDriver *driver);
-
int qemuDomainSnapshotWriteMetadata(virDomainObj *vm,
virDomainMomentObj *snapshot,
virDomainXMLOption *xmlopt,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 72a9542c0b..90d55e53ec 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -679,8 +679,6 @@ qemuStateInitialize(bool privileged,
virPidFileAcquire(cfg->stateDir, "driver", getpid())) < 0)
goto error;
- qemu_driver->qemuImgBinary = virFindFileInPath("qemu-img");
-
if (!(qemu_driver->lockManager =
virLockManagerPluginNew(cfg->lockManagerName ?
cfg->lockManagerName : "nop",
@@ -1065,7 +1063,6 @@ qemuStateCleanup(void)
virCPUDefFree(qemu_driver->hostcpu);
virObjectUnref(qemu_driver->caps);
ebtablesContextFree(qemu_driver->ebtables);
- VIR_FREE(qemu_driver->qemuImgBinary);
virObjectUnref(qemu_driver->domains);
virObjectUnref(qemu_driver->nbdkitCapsCache);
diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c
index 795522da21..35c8d67d20 100644
--- a/src/qemu/qemu_snapshot.c
+++ b/src/qemu/qemu_snapshot.c
@@ -185,7 +185,6 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef,
/**
* qemuSnapshotCreateQcow2Files:
- * @driver: QEMU driver
* @def: domain definition
* @snapdef: snapshot definition
* @created: bitmap to store which disks were created
@@ -196,20 +195,15 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef,
* Returns 0 on success, -1 on error.
*/
static int
-qemuSnapshotCreateQcow2Files(virQEMUDriver *driver,
- virDomainDef *def,
+qemuSnapshotCreateQcow2Files(virDomainDef *def,
virDomainSnapshotDef *snapdef,
virBitmap *created)
{
size_t i;
- const char *qemuImgPath;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virDomainSnapshotDiskDef *snapdisk = NULL;
virDomainDiskDef *defdisk = NULL;
- if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
- return -1;
-
for (i = 0; i < snapdef->ndisks; i++) {
g_autoptr(virCommand) cmd = NULL;
snapdisk = &(snapdef->disks[i]);
@@ -225,7 +219,7 @@ qemuSnapshotCreateQcow2Files(virQEMUDriver *driver,
return -1;
/* creates cmd line args: qemu-img create -f qcow2 -o */
- if (!(cmd = virCommandNewArgList(qemuImgPath,
+ if (!(cmd = virCommandNewArgList("qemu-img",
"create",
"-f",
virStorageFileFormatTypeToString(snapdisk->src->format),
@@ -281,7 +275,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
/* If reuse is true, then qemuSnapshotPrepare already
* ensured that the new files exist, and it was up to the user to
* create them correctly. */
- if (!reuse && qemuSnapshotCreateQcow2Files(driver, vm->def, snapdef, created) < 0)
+ if (!reuse && qemuSnapshotCreateQcow2Files(vm->def, snapdef, created) < 0)
goto cleanup;
/* update disk definitions */
@@ -2300,7 +2294,6 @@ qemuSnapshotRevertExternalActive(virDomainObj *vm,
/**
* qemuSnapshotRevertExternalInactive:
- * @vm: domain object
* @tmpsnapdef: temporary snapshot definition
* @domdef: offline domain definition
*
@@ -2310,17 +2303,15 @@ qemuSnapshotRevertExternalActive(virDomainObj *vm,
* Returns 0 on success, -1 on error.
*/
static int
-qemuSnapshotRevertExternalInactive(virDomainObj *vm,
- virDomainSnapshotDef *tmpsnapdef,
+qemuSnapshotRevertExternalInactive(virDomainSnapshotDef *tmpsnapdef,
virDomainDef *domdef)
{
- virQEMUDriver *driver = QEMU_DOMAIN_PRIVATE(vm)->driver;
g_autoptr(virBitmap) created = NULL;
int ret = -1;
created = virBitmapNew(tmpsnapdef->ndisks);
- if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) < 0)
+ if (qemuSnapshotCreateQcow2Files(domdef, tmpsnapdef, created) < 0)
goto cleanup;
if (qemuSnapshotDomainDefUpdateDisk(domdef, tmpsnapdef, false) < 0)
@@ -2613,7 +2604,7 @@ qemuSnapshotRevertInactive(virDomainObj *vm,
return -1;
}
- if (qemuSnapshotRevertExternalInactive(vm, tmpsnapdef,
+ if (qemuSnapshotRevertExternalInactive(tmpsnapdef,
*inactiveConfig) < 0) {
return -1;
}
@@ -3443,22 +3434,16 @@ qemuSnapshotSetInvalid(virDomainObj *vm,
static void
-qemuSnapshotUpdateBackingStore(virDomainObj *vm,
- qemuSnapshotDeleteExternalData *data)
+qemuSnapshotUpdateBackingStore(qemuSnapshotDeleteExternalData *data)
{
GSList *cur = NULL;
- const char *qemuImgPath;
- virQEMUDriver *driver = QEMU_DOMAIN_PRIVATE(vm)->driver;
-
- if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
- return;
for (cur = data->disksWithBacking; cur; cur = g_slist_next(cur)) {
struct _qemuSnapshotDisksWithBackingStoreData *backingData = cur->data;
g_autoptr(virCommand) cmd = NULL;
/* creates cmd line args: qemu-img create -f qcow2 -o */
- if (!(cmd = virCommandNewArgList(qemuImgPath,
+ if (!(cmd = virCommandNewArgList("qemu-img",
"rebase",
"-u",
"-F",
@@ -3565,7 +3550,7 @@ qemuSnapshotDiscardExternal(virDomainObj *vm,
qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_SNAPSHOT);
- qemuSnapshotUpdateBackingStore(vm, data);
+ qemuSnapshotUpdateBackingStore(data);
if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, false) < 0)
goto error;
--
2.47.0
© 2016 - 2024 Red Hat, Inc.