From nobody Tue Sep 9 03:13:47 2025 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 1738604570983128.2591238938677; Mon, 3 Feb 2025 09:42:50 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 01CA418E4; Mon, 3 Feb 2025 12:42:49 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 81E2D19C6; Mon, 3 Feb 2025 12:41:29 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 54F3818C6; Mon, 3 Feb 2025 12:41:21 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 D220118B4 for ; Mon, 3 Feb 2025 12:41:20 -0500 (EST) Received: from mx-prod-mc-03.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-265-HFg8jr-0PbqJAZ_sfZFm3A-1; Mon, 03 Feb 2025 12:41:19 -0500 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3346419560B0 for ; Mon, 3 Feb 2025 17:41:18 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.3]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 629C51956095 for ; Mon, 3 Feb 2025 17:41:17 +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.7 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,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=1738604480; 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=vvyBwd8kv2lv2735No26at1mCYTkiW0p4fIStEB2Jv0=; b=YPZffIfWw7nFARwJ5OxBzGO2oq92Yalcez9YxRXfTHavUl+UXQcup0nbFe+VLhdWvYr1cY aJpuckdyDIsAWB1efn6qhj+z3jlXVGOTXL/e6OwXXM5t1foJrJNRUdH2oDBiRvRp/b6eSH JAT3o++iNPwM/hTtvxLuQbtHJUpHXsc= X-MC-Unique: HFg8jr-0PbqJAZ_sfZFm3A-1 X-Mimecast-MFC-AGG-ID: HFg8jr-0PbqJAZ_sfZFm3A From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 3/3] qemu: snapshot: Ensure that NVRAM image exists when taking inactive internal snapshot Date: Mon, 3 Feb 2025 18:41:11 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0ZLTE2GRRFQm6sxF9TFNIR_-EjHg0zrLZG4P-w3-2OY_1738604478 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: FTBTRC2YRZRCUE5PTJXVPK2UP46LUICU X-Message-ID-Hash: FTBTRC2YRZRCUE5PTJXVPK2UP46LUICU 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: 1738604572043019100 Content-Type: text/plain; charset="utf-8" Attempting to take an internal snapshot of a freshly defined VM with qcow2 backed NVRAM results in failure as the NVRAM image doesn't get populated until the VM is started for the first time. Fix this by invoking qemuPrepareNVRAM() when qcow2 nvram is defined. Resolves: https://issues.redhat.com/browse/RHEL-73315 Signed-off-by: Peter Krempa --- src/qemu/qemu_snapshot.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index e5226db942..ed140dd41c 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -269,6 +269,7 @@ qemuSnapshotForEachQcow2One(virStorageSource *src, /** * qemuSnapshotForEachQcow2: * + * @driver: qemu driver configuration * @def: domain definition * @snap: snapshot object * @op: 'qemu-img snapshot' operation flag, one of "-c", "-d", "-a" @@ -282,7 +283,8 @@ qemuSnapshotForEachQcow2One(virStorageSource *src, * permissive modes. */ static int -qemuSnapshotForEachQcow2(virDomainDef *def, +qemuSnapshotForEachQcow2(virQEMUDriver *driver, + virDomainDef *def, virDomainMomentObj *snap, const char *op) { @@ -352,6 +354,16 @@ qemuSnapshotForEachQcow2(virDomainDef *def, if (virStorageSourceIsLocalStorage(nvram) && nvram->format =3D=3D VIR_STORAGE_FILE_QCOW2) { + if (create) { + /* Ensure that the NVRAM image exists; e.g. when snapshott= ing + * a VM directly after defining it */ + if (qemuPrepareNVRAM(driver, def, false) < 0) { + nrollback =3D def->ndisks; + virErrorPreserveLast(&orig_err); + goto rollback; + } + } + if (qemuSnapshotForEachQcow2One(nvram, op, snap->def->name) < = 0) { if (create) { nrollback =3D def->ndisks; @@ -392,7 +404,8 @@ static int qemuSnapshotCreateInactiveInternal(virDomainObj *vm, virDomainMomentObj *snap) { - return qemuSnapshotForEachQcow2(vm->def, snap, "-c"); + return qemuSnapshotForEachQcow2(QEMU_DOMAIN_PRIVATE(vm)->driver, + vm->def, snap, "-c"); } @@ -2697,7 +2710,8 @@ qemuSnapshotInternalRevertInactive(virDomainObj *vm, } /* Try all disks, but report failure if we skipped any. */ - if (qemuSnapshotForEachQcow2(def, snap, "-a") !=3D 0) + if (qemuSnapshotForEachQcow2(QEMU_DOMAIN_PRIVATE(vm)->driver, + def, snap, "-a") !=3D 0) return -1; return 0; @@ -4064,7 +4078,8 @@ qemuSnapshotDiscardImpl(virDomainObj *vm, if (qemuSnapshotDiscardExternal(vm, snap, externalData) < = 0) return -1; } else { - if (qemuSnapshotForEachQcow2(def, snap, "-d") < 0) + if (qemuSnapshotForEachQcow2(QEMU_DOMAIN_PRIVATE(vm)->driv= er, + def, snap, "-d") < 0) return -1; } } else { --=20 2.48.1