qemu: Don't store path to qemu img

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>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2024-11-11 16:42:10 +01:00
parent 25fdb57d8e
commit 20ffcb912f
5 changed files with 10 additions and 51 deletions

View File

@ -271,9 +271,6 @@ struct _virQEMUDriver {
/* Immutable pointer, self-locking APIs */ /* Immutable pointer, self-locking APIs */
virDomainObjList *domains; virDomainObjList *domains;
/* Immutable pointer */
char *qemuImgBinary;
/* Immutable pointer, lockless APIs. Pointless abstraction */ /* Immutable pointer, lockless APIs. Pointless abstraction */
ebtablesContext *ebtables; ebtablesContext *ebtables;

View File

@ -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 int
qemuDomainSnapshotWriteMetadata(virDomainObj *vm, qemuDomainSnapshotWriteMetadata(virDomainObj *vm,
virDomainMomentObj *snapshot, virDomainMomentObj *snapshot,
@ -5727,18 +5716,11 @@ qemuDomainSnapshotForEachQcow2Raw(virQEMUDriver *driver,
int ndisks) int ndisks)
{ {
virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap); virDomainSnapshotDef *snapdef = virDomainSnapshotObjGetDef(snap);
const char *qemuimgbin;
size_t i; size_t i;
bool skipped = false; bool skipped = false;
qemuimgbin = qemuFindQemuImgBinary(driver);
if (qemuimgbin == NULL) {
/* qemuFindQemuImgBinary set the error */
return -1;
}
for (i = 0; i < ndisks; i++) { 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); op, snap->def->name, NULL);
int format = virDomainDiskGetFormat(def->disks[i]); int format = virDomainDiskGetFormat(def->disks[i]);

View File

@ -665,8 +665,6 @@ int qemuDomainLogAppendMessage(virQEMUDriver *driver,
const char *fmt, const char *fmt,
...) G_GNUC_PRINTF(3, 4); ...) G_GNUC_PRINTF(3, 4);
const char *qemuFindQemuImgBinary(virQEMUDriver *driver);
int qemuDomainSnapshotWriteMetadata(virDomainObj *vm, int qemuDomainSnapshotWriteMetadata(virDomainObj *vm,
virDomainMomentObj *snapshot, virDomainMomentObj *snapshot,
virDomainXMLOption *xmlopt, virDomainXMLOption *xmlopt,

View File

@ -679,8 +679,6 @@ qemuStateInitialize(bool privileged,
virPidFileAcquire(cfg->stateDir, "driver", getpid())) < 0) virPidFileAcquire(cfg->stateDir, "driver", getpid())) < 0)
goto error; goto error;
qemu_driver->qemuImgBinary = virFindFileInPath("qemu-img");
if (!(qemu_driver->lockManager = if (!(qemu_driver->lockManager =
virLockManagerPluginNew(cfg->lockManagerName ? virLockManagerPluginNew(cfg->lockManagerName ?
cfg->lockManagerName : "nop", cfg->lockManagerName : "nop",
@ -1065,7 +1063,6 @@ qemuStateCleanup(void)
virCPUDefFree(qemu_driver->hostcpu); virCPUDefFree(qemu_driver->hostcpu);
virObjectUnref(qemu_driver->caps); virObjectUnref(qemu_driver->caps);
ebtablesContextFree(qemu_driver->ebtables); ebtablesContextFree(qemu_driver->ebtables);
VIR_FREE(qemu_driver->qemuImgBinary);
virObjectUnref(qemu_driver->domains); virObjectUnref(qemu_driver->domains);
virObjectUnref(qemu_driver->nbdkitCapsCache); virObjectUnref(qemu_driver->nbdkitCapsCache);

View File

@ -185,7 +185,6 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef,
/** /**
* qemuSnapshotCreateQcow2Files: * qemuSnapshotCreateQcow2Files:
* @driver: QEMU driver
* @def: domain definition * @def: domain definition
* @snapdef: snapshot definition * @snapdef: snapshot definition
* @created: bitmap to store which disks were created * @created: bitmap to store which disks were created
@ -196,20 +195,15 @@ qemuSnapshotDomainDefUpdateDisk(virDomainDef *domdef,
* Returns 0 on success, -1 on error. * Returns 0 on success, -1 on error.
*/ */
static int static int
qemuSnapshotCreateQcow2Files(virQEMUDriver *driver, qemuSnapshotCreateQcow2Files(virDomainDef *def,
virDomainDef *def,
virDomainSnapshotDef *snapdef, virDomainSnapshotDef *snapdef,
virBitmap *created) virBitmap *created)
{ {
size_t i; size_t i;
const char *qemuImgPath;
g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER; g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
virDomainSnapshotDiskDef *snapdisk = NULL; virDomainSnapshotDiskDef *snapdisk = NULL;
virDomainDiskDef *defdisk = NULL; virDomainDiskDef *defdisk = NULL;
if (!(qemuImgPath = qemuFindQemuImgBinary(driver)))
return -1;
for (i = 0; i < snapdef->ndisks; i++) { for (i = 0; i < snapdef->ndisks; i++) {
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
snapdisk = &(snapdef->disks[i]); snapdisk = &(snapdef->disks[i]);
@ -225,7 +219,7 @@ qemuSnapshotCreateQcow2Files(virQEMUDriver *driver,
return -1; return -1;
/* creates cmd line args: qemu-img create -f qcow2 -o */ /* creates cmd line args: qemu-img create -f qcow2 -o */
if (!(cmd = virCommandNewArgList(qemuImgPath, if (!(cmd = virCommandNewArgList("qemu-img",
"create", "create",
"-f", "-f",
virStorageFileFormatTypeToString(snapdisk->src->format), virStorageFileFormatTypeToString(snapdisk->src->format),
@ -281,7 +275,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *driver,
/* If reuse is true, then qemuSnapshotPrepare already /* If reuse is true, then qemuSnapshotPrepare already
* ensured that the new files exist, and it was up to the user to * ensured that the new files exist, and it was up to the user to
* create them correctly. */ * create them correctly. */
if (!reuse && qemuSnapshotCreateQcow2Files(driver, vm->def, snapdef, created) < 0) if (!reuse && qemuSnapshotCreateQcow2Files(vm->def, snapdef, created) < 0)
goto cleanup; goto cleanup;
/* update disk definitions */ /* update disk definitions */
@ -2300,7 +2294,6 @@ qemuSnapshotRevertExternalActive(virDomainObj *vm,
/** /**
* qemuSnapshotRevertExternalInactive: * qemuSnapshotRevertExternalInactive:
* @vm: domain object
* @tmpsnapdef: temporary snapshot definition * @tmpsnapdef: temporary snapshot definition
* @domdef: offline domain definition * @domdef: offline domain definition
* *
@ -2310,17 +2303,15 @@ qemuSnapshotRevertExternalActive(virDomainObj *vm,
* Returns 0 on success, -1 on error. * Returns 0 on success, -1 on error.
*/ */
static int static int
qemuSnapshotRevertExternalInactive(virDomainObj *vm, qemuSnapshotRevertExternalInactive(virDomainSnapshotDef *tmpsnapdef,
virDomainSnapshotDef *tmpsnapdef,
virDomainDef *domdef) virDomainDef *domdef)
{ {
virQEMUDriver *driver = QEMU_DOMAIN_PRIVATE(vm)->driver;
g_autoptr(virBitmap) created = NULL; g_autoptr(virBitmap) created = NULL;
int ret = -1; int ret = -1;
created = virBitmapNew(tmpsnapdef->ndisks); created = virBitmapNew(tmpsnapdef->ndisks);
if (qemuSnapshotCreateQcow2Files(driver, domdef, tmpsnapdef, created) < 0) if (qemuSnapshotCreateQcow2Files(domdef, tmpsnapdef, created) < 0)
goto cleanup; goto cleanup;
if (qemuSnapshotDomainDefUpdateDisk(domdef, tmpsnapdef, false) < 0) if (qemuSnapshotDomainDefUpdateDisk(domdef, tmpsnapdef, false) < 0)
@ -2613,7 +2604,7 @@ qemuSnapshotRevertInactive(virDomainObj *vm,
return -1; return -1;
} }
if (qemuSnapshotRevertExternalInactive(vm, tmpsnapdef, if (qemuSnapshotRevertExternalInactive(tmpsnapdef,
*inactiveConfig) < 0) { *inactiveConfig) < 0) {
return -1; return -1;
} }
@ -3443,22 +3434,16 @@ qemuSnapshotSetInvalid(virDomainObj *vm,
static void static void
qemuSnapshotUpdateBackingStore(virDomainObj *vm, qemuSnapshotUpdateBackingStore(qemuSnapshotDeleteExternalData *data)
qemuSnapshotDeleteExternalData *data)
{ {
GSList *cur = NULL; 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)) { for (cur = data->disksWithBacking; cur; cur = g_slist_next(cur)) {
struct _qemuSnapshotDisksWithBackingStoreData *backingData = cur->data; struct _qemuSnapshotDisksWithBackingStoreData *backingData = cur->data;
g_autoptr(virCommand) cmd = NULL; g_autoptr(virCommand) cmd = NULL;
/* creates cmd line args: qemu-img create -f qcow2 -o */ /* creates cmd line args: qemu-img create -f qcow2 -o */
if (!(cmd = virCommandNewArgList(qemuImgPath, if (!(cmd = virCommandNewArgList("qemu-img",
"rebase", "rebase",
"-u", "-u",
"-F", "-F",
@ -3565,7 +3550,7 @@ qemuSnapshotDiscardExternal(virDomainObj *vm,
qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_SNAPSHOT); qemuBlockJobSyncEnd(vm, data->job, VIR_ASYNC_JOB_SNAPSHOT);
qemuSnapshotUpdateBackingStore(vm, data); qemuSnapshotUpdateBackingStore(data);
if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, false) < 0) if (qemuSnapshotSetInvalid(vm, data->parentSnap, data->snapDisk, false) < 0)
goto error; goto error;