From nobody Sat Nov 23 12:46:24 2024 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 1730793888013531.480412932304; Tue, 5 Nov 2024 00:04:48 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 0530213A0; Tue, 5 Nov 2024 03:04:46 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 2D0581383; Tue, 5 Nov 2024 02:59:07 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 2303E11ED; Tue, 5 Nov 2024 02:58:58 -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 B56FE130D for ; Tue, 5 Nov 2024 02:58:32 -0500 (EST) Received: from mx-prod-mc-01.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-320-oMFDDm2TMPGSXUmQucqoHA-1; Tue, 05 Nov 2024 02:58:31 -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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 3EAFF195421A for ; Tue, 5 Nov 2024 07:58:30 +0000 (UTC) Received: from speedmetal.lan (unknown [10.45.242.2]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 76AEB300018D for ; Tue, 5 Nov 2024 07:58:29 +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.5 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3,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=1730793512; 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=axhKBk7UxxnTDv1MhMBkKOzWRHmJ+caObRGA7OeUEJ8=; b=WFurL4GHdae2ZONvFHDx0GUOEzMYHGWNsgFYL7ztxvZhgqI2ZeC/61pAZvFzmBm9RC0WAj bnrRGWTN7Mvx9hWqxj2aqKFKRI42ele4DSvTMbRW51TQh8uXd0TJNkcxER18YP0uLENQh/ sFlC9stHfVy9F5jdSWJHMJ6ZnKu+K2E= X-MC-Unique: oMFDDm2TMPGSXUmQucqoHA-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 12/13] qemu: process: Extract setup of file-backed nvram from template Date: Tue, 5 Nov 2024 08:58:10 +0100 Message-ID: <7cf06195a093c92c60b9312c5d82ff0e5eaa2914.1730793407.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: ZZQ6CSZQGHD2VRWF6QMRW2JTZC5X3R5R X-Message-ID-Hash: ZZQ6CSZQGHD2VRWF6QMRW2JTZC5X3R5R 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: 1730793889996116600 Content-Type: text/plain; charset="utf-8" The setup of nvram will later be extended to also support block-device backed nvram, so extract the file-backed nvram setup steps from 'qemuPrepareNVRAM' into 'qemuPrepareNVRAMFile'. Signed-off-by: Peter Krempa --- src/qemu/qemu_process.c | 77 +++++++++++++++++++++++++++-------------- 1 file changed, 51 insertions(+), 26 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d134de532c..7fbf18ec10 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4584,39 +4584,18 @@ qemuPrepareNVRAMHelper(int dstFD, static int -qemuPrepareNVRAM(virQEMUDriver *driver, - virDomainObj *vm, - bool reset_nvram) +qemuPrepareNVRAMFile(virDomainObj *vm, + bool reset_nvram) { - g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); + qemuDomainObjPrivate *priv =3D vm->privateData; + g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(priv->dr= iver); VIR_AUTOCLOSE srcFD =3D -1; virDomainLoaderDef *loader =3D vm->def->os.loader; struct qemuPrepareNVRAMHelperData data; - if (!loader || !loader->nvram) - return 0; - - if (!virStorageSourceIsLocalStorage(loader->nvram)) { - if (!reset_nvram) { - return 0; - } else { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("resetting of nvram is not supported with network ba= cked nvram")); - return -1; - } - } - if (virFileExists(loader->nvram->path) && !reset_nvram) return 0; - /* virFileRewrite() would overwrite the device node-file/symlink rathe= r than - * just write the data to it, thus block-device nvram is not yet suppo= rted */ - if (virStorageSourceIsBlockLocal(loader->nvram)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("creation or formatting of nvram type=3D'block' i= s not supported")); - return -1; - } - if (!loader->nvramTemplate) { virReportError(VIR_ERR_OPERATION_FAILED, _("unable to find any master var store for loader: = %1$s"), @@ -4653,6 +4632,52 @@ qemuPrepareNVRAM(virQEMUDriver *driver, } +static int +qemuPrepareNVRAM(virDomainObj *vm, + bool reset_nvram) +{ + virDomainLoaderDef *loader =3D vm->def->os.loader; + + if (!loader || !loader->nvram) + return 0; + + switch (virStorageSourceGetActualType(loader->nvram)) { + case VIR_STORAGE_TYPE_FILE: + return qemuPrepareNVRAMFile(vm, reset_nvram); + + case VIR_STORAGE_TYPE_BLOCK: + /* virFileRewrite() would overwrite the device node-file/symlink r= ather than + * just write the data to it, thus block-device nvram is not yet s= upported */ + if (virFileExists(loader->nvram->path) && !reset_nvram) + return 0; + + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("creation or formatting of nvram type=3D'block' i= s not supported")); + return -1; + + case VIR_STORAGE_TYPE_DIR: + case VIR_STORAGE_TYPE_NETWORK: + case VIR_STORAGE_TYPE_VOLUME: + case VIR_STORAGE_TYPE_NVME: + case VIR_STORAGE_TYPE_VHOST_USER: + case VIR_STORAGE_TYPE_VHOST_VDPA: + case VIR_STORAGE_TYPE_LAST: + case VIR_STORAGE_TYPE_NONE: + if (reset_nvram) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("resetting of nvram is not supported with nvram devi= ce backed by '%1$s'"), + virStorageTypeToString(virStorageSourceGetActualType(l= oader->nvram))); + return -1; + } + + /* otherwise we just assume that the user did set up stuff correct= ly */ + break; + } + + return 0; +} + + static void qemuLogOperation(virDomainObj *vm, const char *msg, @@ -7283,7 +7308,7 @@ qemuProcessPrepareHost(virQEMUDriver *driver, qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0) return -1; - if (qemuPrepareNVRAM(driver, vm, !!(flags & VIR_QEMU_PROCESS_START_RES= ET_NVRAM)) < 0) + if (qemuPrepareNVRAM(vm, !!(flags & VIR_QEMU_PROCESS_START_RESET_NVRAM= )) < 0) return -1; if (vm->def->vsock) { --=20 2.47.0