From nobody Sat Nov 23 12:58:30 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1731660034057662.3023191688153; Fri, 15 Nov 2024 00:40:34 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id E62391A1D; Fri, 15 Nov 2024 03:40:32 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 3506B19CD; Fri, 15 Nov 2024 03:39:43 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 6516F14A8; Fri, 15 Nov 2024 03:39:38 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id C016017AB for ; Fri, 15 Nov 2024 03:39:37 -0500 (EST) Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-260-d1nxipTDOvWVkaMnz2Ykgg-1; Fri, 15 Nov 2024 03:39:35 -0500 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DDB021954128 for ; Fri, 15 Nov 2024 08:39:34 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.6]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id EEA1519560A3 for ; Fri, 15 Nov 2024 08:39:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1731659977; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=phmaP87FOhVGU5MEd0kdbzyOe9KMkBQndpF/BKspUSs=; b=jD2F04fivnY6QOe3yXQUp+llmnXGLFzj+9yRyBgEt+VFFHQ6SIh6utaIGI4yEr0oGJeFeK osd2lE4doalth7fKSlh2/09oEwSuGlXHv+laieR4n+mzS6PYNMHoFqpRm959SrVK03VSCc IdJoqaYLNVPkyZSNQprRFIl+9muXmf0= X-MC-Unique: d1nxipTDOvWVkaMnz2Ykgg-1 X-Mimecast-MFC-AGG-ID: d1nxipTDOvWVkaMnz2Ykgg From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/9] qemu: Don't store path to qemu img Date: Fri, 15 Nov 2024 09:39:22 +0100 Message-ID: <3af7193e8fb6843d742e5ce542a114e6c3c26797.1731659896.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Xoga6LMckhmE6lUUGcNWLFP8BRsg9T8pjjqWD4Z232w_1731659975 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FK35YYYXO3LZEHIGBBDZKGTFBP5OIQGO X-Message-ID-Hash: FK35YYYXO3LZEHIGBBDZKGTFBP5OIQGO X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1731660036250116600 Content-Type: text/plain; charset="utf-8" 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 --- 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 *dr= iver, int ndisks) { virDomainSnapshotDef *snapdef =3D virDomainSnapshotObjGetDef(snap); - const char *qemuimgbin; size_t i; bool skipped =3D false; - qemuimgbin =3D qemuFindQemuImgBinary(driver); - if (qemuimgbin =3D=3D NULL) { - /* qemuFindQemuImgBinary set the error */ - return -1; - } - for (i =3D 0; i < ndisks; i++) { - g_autoptr(virCommand) cmd =3D virCommandNewArgList(qemuimgbin, "sn= apshot", + g_autoptr(virCommand) cmd =3D virCommandNewArgList("qemu-img", "sn= apshot", op, snap->def->na= me, NULL); int format =3D 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 =3D virFindFileInPath("qemu-img"); - if (!(qemu_driver->lockManager =3D 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 =3D VIR_BUFFER_INITIALIZER; virDomainSnapshotDiskDef *snapdisk =3D NULL; virDomainDiskDef *defdisk =3D NULL; - if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) - return -1; - for (i =3D 0; i < snapdef->ndisks; i++) { g_autoptr(virCommand) cmd =3D NULL; snapdisk =3D &(snapdef->disks[i]); @@ -225,7 +219,7 @@ qemuSnapshotCreateQcow2Files(virQEMUDriver *driver, return -1; /* creates cmd line args: qemu-img create -f qcow2 -o */ - if (!(cmd =3D virCommandNewArgList(qemuImgPath, + if (!(cmd =3D virCommandNewArgList("qemu-img", "create", "-f", virStorageFileFormatTypeToString(= snapdisk->src->format), @@ -281,7 +275,7 @@ qemuSnapshotCreateInactiveExternal(virQEMUDriver *drive= r, /* 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, c= reated) < 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 =3D QEMU_DOMAIN_PRIVATE(vm)->driver; g_autoptr(virBitmap) created =3D NULL; int ret =3D -1; created =3D 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 =3D NULL; - const char *qemuImgPath; - virQEMUDriver *driver =3D QEMU_DOMAIN_PRIVATE(vm)->driver; - - if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) - return; for (cur =3D data->disksWithBacking; cur; cur =3D g_slist_next(cur)) { struct _qemuSnapshotDisksWithBackingStoreData *backingData =3D cur= ->data; g_autoptr(virCommand) cmd =3D NULL; /* creates cmd line args: qemu-img create -f qcow2 -o */ - if (!(cmd =3D virCommandNewArgList(qemuImgPath, + if (!(cmd =3D 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, f= alse) < 0) goto error; --=20 2.47.0