From nobody Tue Mar 3 04:54:09 2026 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=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1771418322; cv=none; d=zohomail.com; s=zohoarc; b=jv5WbGrk3bT4/o4WYqAqUybBn0ZH27Ot1XGkNytP+88MeqL96GMeY6ClQgMd/70LYN4zmcsv9KZKYLHjFgj/yaaclSWxtVrUf55e+zkCjRUnSdmBFKIoJI68eZMetn39DOfzSYuxPU1Pz5FgfmpmXi6UGPJ7VHoJ65igenRwyYM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771418322; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Owner:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=YiDpi0AYmpG3fHShcCQ24+wp+rRMd5RY8HDPZ5erzXc=; b=C01wVWueurQJhPT+4zbc9aXoX2fQ4RepMI3IHamvXclY+zer1yqNOC2Ehzbz7W1cJ1frwt/0Jua+r3meqLyE0XvyPCvn/TN+F8heIvujT/ut22OQSk2UKuUIfxlfgeXj0TwZv54PKSIKG6KD/86gdzslJj7ZUo/lzQb8DZKRLj0= ARC-Authentication-Results: i=1; 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=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1771418322614697.9227087284817; Wed, 18 Feb 2026 04:38:42 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 8A0C043E3E; Wed, 18 Feb 2026 07:38:41 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 67C8B4427E; Wed, 18 Feb 2026 07:11:05 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 974F34419B; Wed, 18 Feb 2026 07:10:56 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (3072 bits) server-digest SHA256) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 6E8C141B73 for ; Wed, 18 Feb 2026 07:06:59 -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-462-P7hlMhE2Ofiy4wOahyafmA-1; Wed, 18 Feb 2026 07:06:58 -0500 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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 3E6BD1955D8C for ; Wed, 18 Feb 2026 12:06:57 +0000 (UTC) Received: from kinshicho.usersys.redhat.com (unknown [10.45.226.171]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3B8A830001BF for ; Wed, 18 Feb 2026 12:06:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HELO_MISC_IP,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_PASS autolearn=unavailable autolearn_force=no version=4.0.1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771416419; 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=YiDpi0AYmpG3fHShcCQ24+wp+rRMd5RY8HDPZ5erzXc=; b=Xdw8tm5PdIE02f1Oy4tj3u6gyWe3hh3HdRuNEdMVJblnHuTS7wJOjoo3BJD2dlsgxpb+9Z b/ydr8xghutWO3PjokCoz7TPguts10IRYmdHwOXaaKIZM8mvabk/IKG8+zQVTgn5sdrj+k MlbF1QJo++nkv6dRYM1rViueCfz1Tac= X-MC-Unique: P7hlMhE2Ofiy4wOahyafmA-1 X-Mimecast-MFC-AGG-ID: P7hlMhE2Ofiy4wOahyafmA_1771416417 To: devel@lists.libvirt.org Subject: [PATCH v3 31/38] qemu: Introduce qemuPrepareNVRAMFileCommon() Date: Wed, 18 Feb 2026 13:05:54 +0100 Message-ID: <20260218120601.230343-32-abologna@redhat.com> In-Reply-To: <20260218120601.230343-1-abologna@redhat.com> References: <20260218120601.230343-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: hUkv9z8Nn9GuRLJDlvjD9H2la-bAr9aQ9hqI97EyGxU_1771416417 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: AGG5PWTADQWGDM5IDJUCYXBL2OFQKD3Z X-Message-ID-Hash: AGG5PWTADQWGDM5IDJUCYXBL2OFQKD3Z X-MailFrom: abologna@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; header-match-devel.lists.libvirt.org-0; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Andrea Bolognani via Devel Reply-To: Andrea Bolognani X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1771418323944158500 Content-Type: text/plain; charset="utf-8"; x-default="true" Most of the code in the qemuPrepareNVRAMFile() function can be reused to create a varstore file from template. Move the common parts to a generic helper, leaving only the parts that are NVRAM-specific in the original function. Signed-off-by: Andrea Bolognani Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_process.c | 56 +++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 371b64faac..db43b035c1 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4918,45 +4918,40 @@ qemuPrepareNVRAMBlock(virDomainLoaderDef *loader, =20 =20 static int -qemuPrepareNVRAMFile(virQEMUDriver *driver, - virDomainLoaderDef *loader, - bool reset_nvram) +qemuPrepareNVRAMFileCommon(virQEMUDriver *driver, + const char *path, + const char *template, + bool reset_nvram) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); VIR_AUTOCLOSE srcFD =3D -1; struct qemuPrepareNVRAMHelperData data; =20 - if (virFileExists(loader->nvram->path) && !reset_nvram) + if (!path) return 0; =20 - if (!loader->nvramTemplate) { + if (virFileExists(path) && !reset_nvram) + return 0; + + if (!template) { virReportError(VIR_ERR_OPERATION_FAILED, _("unable to find any master var store for loader: = %1$s"), - loader->path); + path); return -1; } =20 - /* If 'nvramTemplateFormat' is empty it means that it's a user-provided - * template which we couldn't verify. Assume the user knows what they'= re doing */ - if (loader->nvramTemplateFormat !=3D VIR_STORAGE_FILE_NONE && - loader->nvram->format !=3D loader->nvramTemplateFormat) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("conversion of the nvram template to another targ= et format is not supported")); - return -1; - } - - if ((srcFD =3D virFileOpenAs(loader->nvramTemplate, O_RDONLY, + if ((srcFD =3D virFileOpenAs(template, O_RDONLY, 0, -1, -1, 0)) < 0) { virReportSystemError(-srcFD, _("Failed to open file '%1$s'"), - loader->nvramTemplate); + template); return -1; } =20 data.srcFD =3D srcFD; - data.srcPath =3D loader->nvramTemplate; + data.srcPath =3D template; =20 - if (virFileRewrite(loader->nvram->path, + if (virFileRewrite(path, S_IRUSR | S_IWUSR, cfg->user, cfg->group, qemuPrepareNVRAMHelper, @@ -4968,6 +4963,29 @@ qemuPrepareNVRAMFile(virQEMUDriver *driver, } =20 =20 +static int +qemuPrepareNVRAMFile(virQEMUDriver *driver, + virDomainLoaderDef *loader, + bool reset_nvram) +{ + /* If 'nvramTemplateFormat' is empty it means that it's a user-provided + * template which we couldn't verify. Assume the user knows what they'= re doing */ + if (loader && loader->nvram && + loader->nvramTemplateFormat !=3D VIR_STORAGE_FILE_NONE && + loader->nvram->format !=3D loader->nvramTemplateFormat) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("conversion of the nvram template to another targ= et format is not supported")); + return -1; + } + + if (qemuPrepareNVRAMFileCommon(driver, loader->nvram->path, + loader->nvramTemplate, reset_nvram) < 0) + return -1; + + return 0; +} + + int qemuPrepareNVRAM(virQEMUDriver *driver, virDomainDef *def, --=20 2.53.0