From nobody Tue Feb 10 05:43:54 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=1770648167; cv=none; d=zohomail.com; s=zohoarc; b=DcE+md8sggwzWCax8R+uZidAsrZd8B5104BCsKqG7WR8nsV28d9Cyei3XbkDl+fG/ldskNunJdL+qUG+Raco80HSTtmPWrrV60c+lihnMwr0IIY2FwhuG0/cmxGg574UrpQ8l/5fWrfbE3HEu7MCqEnaegjr7MA0JE5KJcAUp94= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1770648167; 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=pXMO7muTjnC8ZfkKhDorV8IBAlfIut2QbnRi92excQI=; b=d3IqBtkoj+I2Dym+TcI3dhop6tAVbtfq0iBquLHs1TCyG4nV4/u66DNv5vmDH9SBx4ihTEo5Bbd2L95noZNiONuqR4gWP+EqOO9HuOzz1bn40iG7r/rrZuhVCQK6dIpWnwCizfn0bQn1LYENwVSZ0ubbdAvMZpe4C2QVzVZsJoU= 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 1770648167600573.1017030406985; Mon, 9 Feb 2026 06:42:47 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 993) id 1A0843FD29; Mon, 9 Feb 2026 09:42:47 -0500 (EST) Received: from [172.19.199.6] (lists.libvirt.org [8.43.85.245]) by lists.libvirt.org (Postfix) with ESMTP id 1CD8D44600; Mon, 9 Feb 2026 09:07:07 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 993) id F136243DB2; Mon, 9 Feb 2026 09:02:36 -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 5509541AE0 for ; Mon, 9 Feb 2026 08:47:56 -0500 (EST) Received: from mx-prod-mc-08.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-530-gVlnmUBzPQ6HjZXeJKK4KA-1; Mon, 09 Feb 2026 08:47:54 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 141741800578 for ; Mon, 9 Feb 2026 13:47:54 +0000 (UTC) Received: from harajuku.usersys.redhat.com.homenet.telecomitalia.it (unknown [10.45.226.251]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 52C781956053 for ; Mon, 9 Feb 2026 13:47:53 +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=-5.0 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,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=1770644876; 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=pXMO7muTjnC8ZfkKhDorV8IBAlfIut2QbnRi92excQI=; b=ONUufNyUw1XtFekDMsAlwm6E1GNyBRjCnIGT2fY5Bshw1JcGAv0MGW7lDEEaNwoLABvjiY 770nJqzdE//TaAXbYXw8HLLvsTK0Cd5xs4dlZXpS+PcCMfATBr1+nABKExvhN3Z+BjVMCH OWH5z47OteWtBNK9yDlvKUMtWZp1bqA= X-MC-Unique: gVlnmUBzPQ6HjZXeJKK4KA-1 X-Mimecast-MFC-AGG-ID: gVlnmUBzPQ6HjZXeJKK4KA_1770644874 To: devel@lists.libvirt.org Subject: [PATCH v2 31/38] qemu: Introduce qemuPrepareNVRAMFileCommon() Date: Mon, 9 Feb 2026 14:47:05 +0100 Message-ID: <20260209134712.296670-32-abologna@redhat.com> In-Reply-To: <20260209134712.296670-1-abologna@redhat.com> References: <20260209134712.296670-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: 9WZS51XSzgvewsvkX3Y2D0TIBFC97P-84SAjr3QpTU8_1770644874 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: JN5Y33YVQVDPJ3NNEDL6RRGIXFPLOX5Q X-Message-ID-Hash: JN5Y33YVQVDPJ3NNEDL6RRGIXFPLOX5Q 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: 1770648169086154100 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 --- 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 c5b2a5fda8..997b1d383b 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4919,45 +4919,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, @@ -4969,6 +4964,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