From nobody Tue Mar 3 04:54:10 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=1771873289; cv=none; d=zohomail.com; s=zohoarc; b=Nra0zRdWhbq2J+a1CQ+gO4BN78JZt2C0EP4im3TaL1uYUTHRmEcLk8srtvh/dmNsqNbFwk/+ColgMairh9Sh2VfbTGG2GRe01quw3AQIsUSwpT2xOBmjVrmnZoRi4XLMPDhfgy33y4LT8p9UDq7YMu3bXk+17oTboPGYcwtLEQk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771873289; 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=K22trZUg4euBemqjE1DN3UH3tld3+y9/yEt1WAI47sQ=; b=GZLFRuf/hcvOLO6Es5rFFoo+EemQEo90Vc8xLAJMywT+eoE3qKm9soy1+w00g2KYE5zQsDjPy1j4XFz/DX43oGQ1Vh8bqLzrRbAMaSBNhsnvBUfd1ygthe23QCC/SSMlUIx9JrnxyvkABc3BJ0roV8Xv1TxKNYmhYF3rHeusNgI= 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 1771873289790820.1229048341188; Mon, 23 Feb 2026 11:01:29 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 07BA341B83; Mon, 23 Feb 2026 14:01:29 -0500 (EST) Received: from [172.19.199.9] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 86C5B442B9; Mon, 23 Feb 2026 13:36:57 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id 3625B44192; Mon, 23 Feb 2026 13:36:47 -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 D4B2841C6F for ; Mon, 23 Feb 2026 13:32:21 -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-302-aLF-GLPuNfuKktFpy77jvg-1; Mon, 23 Feb 2026 13:32:18 -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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 282C318011CC for ; Mon, 23 Feb 2026 18:32:16 +0000 (UTC) Received: from kinshicho.usersys.redhat.com (unknown [10.44.32.20]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id EF76F1944CC4 for ; Mon, 23 Feb 2026 18:32:14 +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=-2.6 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=1771871541; 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=K22trZUg4euBemqjE1DN3UH3tld3+y9/yEt1WAI47sQ=; b=QFt9JVjU3dmJ5TP9w9CDjBtbYraA8T1Yd2iLE2qlEqjK+Oo9GAlin6GcH0S9sRMysXu2XA Kaayd6bMQrW4VsVMJuGWKyOk76viObgAss2C1G9l7IHDNWQat6EZj82SjTYAvYlJQ2Q4Hk cAy609Lwxi6Rx6sWe3eUFSIY6SXEE0k= X-MC-Unique: aLF-GLPuNfuKktFpy77jvg-1 X-Mimecast-MFC-AGG-ID: aLF-GLPuNfuKktFpy77jvg_1771871538 To: devel@lists.libvirt.org Subject: [PATCH v4 28/36] qemu: Introduce qemuPrepareNVRAMFileCommon() Date: Mon, 23 Feb 2026 19:31:11 +0100 Message-ID: <20260223183119.501349-29-abologna@redhat.com> In-Reply-To: <20260223183119.501349-1-abologna@redhat.com> References: <20260223183119.501349-1-abologna@redhat.com> 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: Vga9zIUiccvnRrkL-wdOretNYyhGmkMDfNyDVXUH2eE_1771871538 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JZW5K62V2SQ54GHPD6IFSXDVHP3UO6CV X-Message-ID-Hash: JZW5K62V2SQ54GHPD6IFSXDVHP3UO6CV 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: 1771873290514158500 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: Michal Privoznik Acked-by: Gerd Hoffmann 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