From nobody Mon Sep 8 21:39:51 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 1738604519655126.60417793439831; Mon, 3 Feb 2025 09:41:59 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A250019D5; Mon, 3 Feb 2025 12:41:58 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5D5BB1A26; Mon, 3 Feb 2025 12:41:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 671AB18B9; Mon, 3 Feb 2025 12:41:18 -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 E5F1018B4 for ; Mon, 3 Feb 2025 12:41:17 -0500 (EST) Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-o9UySYsrOx6PHK-WnK9jxg-1; Mon, 03 Feb 2025 12:41:16 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7B10218009F5 for ; Mon, 3 Feb 2025 17:41:15 +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 A28121956095 for ; Mon, 3 Feb 2025 17:41:14 +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_H2,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=1738604477; 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=P3igdLFvQuAscPlxrX4oqLda71HYoZbFG970HQu8NH0=; b=YjpY0/Il21Gt8HK7f/LJFPWVipezxSFYsY4slqqy4gzlCFKqrBNk6USbyI3wRD/5fBwPrG EiQ3TvrPGEHYL/M1bONshQVihKtNOwriEvLoTL6cfLDuE8vYfEICwFXU11EkVOsGVAKeTW LYUshGzHT2AMQnvyrJlwHyI+7FAXMaU= X-MC-Unique: o9UySYsrOx6PHK-WnK9jxg-1 X-Mimecast-MFC-AGG-ID: o9UySYsrOx6PHK-WnK9jxg From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 1/3] qemuSnapshotForEachQcow2: Don't initialize 'nrollback' Date: Mon, 3 Feb 2025 18:41:09 +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: Qwx0aq2dgNBbWo0u7oSxf_W5rnC6Y7_iKlc3qtQxsLs_1738604475 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: MTURWMJQ4NZ737QQWZKFAFP3ZVJ5D2ST X-Message-ID-Hash: MTURWMJQ4NZ737QQWZKFAFP3ZVJ5D2ST 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: 1738604521844019100 Content-Type: text/plain; charset="utf-8" The variable holds the amount of disks to roll back the snapshot for. The value must be set before the code jumps to the 'rollback:' label so the best situation is to not initialize it and let the compiler catch errors rather than initialize the unsigned variable to -1 and let it crash. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu_snapshot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 7ce018b026..e5226db942 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -290,7 +290,7 @@ qemuSnapshotForEachQcow2(virDomainDef *def, size_t i; bool skipped =3D false; bool create =3D STREQ(op, "-c"); - size_t nrollback =3D -1; + size_t nrollback; virErrorPtr orig_err; /* pre-checks */ --=20 2.48.1 From nobody Mon Sep 8 21:39:51 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 1738604539696212.3271090513358; Mon, 3 Feb 2025 09:42:19 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id A19EF19FC; Mon, 3 Feb 2025 12:42:18 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 26C031977; Mon, 3 Feb 2025 12:41:26 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id C44C118B9; Mon, 3 Feb 2025 12:41:20 -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 3858A182D for ; Mon, 3 Feb 2025 12:41:20 -0500 (EST) Received: from mx-prod-mc-05.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-497-n0QRboVlN2umCQUXTcHvMw-1; Mon, 03 Feb 2025 12:41:17 -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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D7558195609E for ; Mon, 3 Feb 2025 17:41:16 +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 136E51956095 for ; Mon, 3 Feb 2025 17:41:15 +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=1738604479; 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=FfY4lnMyJ9o7xiOXpj7lF5I+dVzyGan7oIgbM0b8VLY=; b=ea6yZzFJ7ePI7Aj39hm48G/rwDXgPVeRWb/WZLnztwOPFO2ff0v1CYwJkVxQuPOSNa0IPv oeIGf/eT8btUdEudMrJQaq0j9iftxyPZ8D01m407EMcTqKsmKe80vJSbgcmWblkkajyBV/ Y2pkZBZGdbGKgnoMk2XZSku1/v+18wc= X-MC-Unique: n0QRboVlN2umCQUXTcHvMw-1 X-Mimecast-MFC-AGG-ID: n0QRboVlN2umCQUXTcHvMw From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 2/3] qemu: process: Export qemuPrepareNVRAM for use in snapshot code Date: Mon, 3 Feb 2025 18:41:10 +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: ovYQL6fPrLduzo0j8xadNw-vyUwSDTkWkcgZcpZo1ZI_1738604476 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: NSYIQ47BLOCGJAZHCM4SY5RMHK35IKZR X-Message-ID-Hash: NSYIQ47BLOCGJAZHCM4SY5RMHK35IKZR 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: 1738604541979019100 Content-Type: text/plain; charset="utf-8" Export qemuPrepareNVRAM so that it doesn't require the VM object. The snapshot code needs in the corner case of creating a snapshot of a freshly defined VM ensure that the nvram image exists in order to snapshot it. Signed-off-by: Peter Krempa Reviewed-by: Pavel Hrdina --- src/qemu/qemu_process.c | 26 ++++++++++++++------------ src/qemu/qemu_process.h | 4 ++++ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 34a755a49a..4948801ca1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4608,10 +4608,9 @@ qemuPrepareNVRAMHelper(int dstFD, static int -qemuPrepareNVRAMBlock(virDomainObj *vm, +qemuPrepareNVRAMBlock(virDomainLoaderDef *loader, bool reset_nvram) { - virDomainLoaderDef *loader =3D vm->def->os.loader; g_autoptr(virCommand) qemuimg =3D NULL; const char *templateFormatStr =3D "raw"; @@ -4672,13 +4671,12 @@ qemuPrepareNVRAMBlock(virDomainObj *vm, static int -qemuPrepareNVRAMFile(virDomainObj *vm, +qemuPrepareNVRAMFile(virQEMUDriver *driver, + virDomainLoaderDef *loader, bool reset_nvram) { - qemuDomainObjPrivate *priv =3D vm->privateData; - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); VIR_AUTOCLOSE srcFD =3D -1; - virDomainLoaderDef *loader =3D vm->def->os.loader; struct qemuPrepareNVRAMHelperData data; if (virFileExists(loader->nvram->path) && !reset_nvram) @@ -4720,21 +4718,24 @@ qemuPrepareNVRAMFile(virDomainObj *vm, } -static int -qemuPrepareNVRAM(virDomainObj *vm, +int +qemuPrepareNVRAM(virQEMUDriver *driver, + virDomainDef *def, bool reset_nvram) { - virDomainLoaderDef *loader =3D vm->def->os.loader; + virDomainLoaderDef *loader =3D def->os.loader; if (!loader || !loader->nvram) return 0; + VIR_DEBUG("nvram=3D'%s'", NULLSTR(loader->nvram->path)); + switch (virStorageSourceGetActualType(loader->nvram)) { case VIR_STORAGE_TYPE_FILE: - return qemuPrepareNVRAMFile(vm, reset_nvram); + return qemuPrepareNVRAMFile(driver, loader, reset_nvram); case VIR_STORAGE_TYPE_BLOCK: - return qemuPrepareNVRAMBlock(vm, reset_nvram); + return qemuPrepareNVRAMBlock(loader, reset_nvram); case VIR_STORAGE_TYPE_DIR: case VIR_STORAGE_TYPE_NETWORK: @@ -7399,7 +7400,8 @@ qemuProcessPrepareHost(virQEMUDriver *driver, qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0) return -1; - if (qemuPrepareNVRAM(vm, !!(flags & VIR_QEMU_PROCESS_START_RESET_NVRAM= )) < 0) + if (qemuPrepareNVRAM(driver, vm->def, + !!(flags & VIR_QEMU_PROCESS_START_RESET_NVRAM)) <= 0) return -1; if (vm->def->vsock) { diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 12781673c5..fee00ce53b 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -258,3 +258,7 @@ int qemuProcessSetupEmulator(virDomainObj *vm); void qemuProcessHandleNbdkitExit(qemuNbdkitProcess *nbdkit, virDomainObj *vm); + +int qemuPrepareNVRAM(virQEMUDriver *driver, + virDomainDef *def, + bool reset_nvram); --=20 2.48.1 From nobody Mon Sep 8 21:39:51 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 Reviewed-by: Pavel Hrdina --- 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