From nobody Sun May 19 12:00:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644346442; cv=none; d=zohomail.com; s=zohoarc; b=LDwij54GzLUK/EqZ/PbmKwguIdRx1lrIbMHpt6dUzRjvQ8AeWWgNfYL073djMVIx1x8eZAz8wUUO4RMAC3Q4B6myiU+ra3lcwY6RRhfq9MW9+EQoOUho/lVuiXn43Tzm2F7G/D3iAxJHN7eMAksRw3MA9Meiil8SShqPMD+T4+g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644346442; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6UjRN5CbX0Jzk109v0g5Gqut254op9AK4Pm9vDmmZ+w=; b=l1uP595WMwEZDlwvcBZXucj1nhITmp1+XcVZ5srH0TvXnrP2PueN5OYh2Hmd2IwphAbjVp23FLmnqMt95BGoYuqEk95MCJh6oNiubG1gnAMT1HDnjNcSlurHqXUugadt42WtAzkB8RYNz3AgLk5SUZ6XVdZQYIw2OV4YhVOa8hs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644346442474914.2442473487985; Tue, 8 Feb 2022 10:54:02 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-550-0IiKZ9aCMFGnzWA4k5bc2Q-1; Tue, 08 Feb 2022 13:53:21 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BCE9A8144E4; Tue, 8 Feb 2022 18:53:14 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9DC7A85EED; Tue, 8 Feb 2022 18:53:14 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 6D0131826D1C; Tue, 8 Feb 2022 18:53:14 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 217CbE5K003348 for ; Mon, 7 Feb 2022 07:37:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 769826FB87; Mon, 7 Feb 2022 12:37:14 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id B1AE96FB8C; Mon, 7 Feb 2022 12:37:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644346442; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=6UjRN5CbX0Jzk109v0g5Gqut254op9AK4Pm9vDmmZ+w=; b=fiGuQoXUuQ2zLzyCG4b/49IgrfoYnvVbo4FjEUxFfgdZuKcR7ZDABw9PA0DRZBHeT6CXq4 A2003rfcR24Z1P2sFrGpry2YePl7bskzacYcBa+sJT7Fbqg5Ka8MaHyyKrt1RkLucyGpHZ +Y3lSPknsNm1j1e9j2wFXVYSb3zSwsk= X-MC-Unique: 0IiKZ9aCMFGnzWA4k5bc2Q-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/4] qemu: do crash safe creation of NVRAM file Date: Mon, 7 Feb 2022 12:37:07 +0000 Message-Id: <20220207123711.1042287-2-berrange@redhat.com> In-Reply-To: <20220207123711.1042287-1-berrange@redhat.com> References: <20220207123711.1042287-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644346444739100001 If we crash part way through writing the NVRAM file we end up with an unusable NVRAM on file. To avoid this we need to write to a temporary file and fsync(2) at the end, then rename to the real NVRAM file path. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_process.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index c13280c8f3..bc7c2a4dbc 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4421,6 +4421,7 @@ qemuPrepareNVRAM(virQEMUDriver *driver, bool created =3D false; const char *master_nvram_path; ssize_t r; + g_autofree char *tmp_dst_path =3D NULL; =20 if (!loader || !loader->nvram || virFileExists(loader->nvram)) return 0; @@ -4451,14 +4452,15 @@ qemuPrepareNVRAM(virQEMUDriver *driver, goto cleanup; } =20 - if ((dstFD =3D virFileOpenAs(loader->nvram, + tmp_dst_path =3D g_strdup_printf("%s.tmp", loader->nvram); + if ((dstFD =3D virFileOpenAs(tmp_dst_path, O_WRONLY | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, cfg->user, cfg->group, VIR_FILE_OPEN_FORCE_OWNER)) < 0) { virReportSystemError(-dstFD, _("Failed to create file '%s'"), - loader->nvram); + tmp_dst_path); goto cleanup; } =20 @@ -4477,7 +4479,7 @@ qemuPrepareNVRAM(virQEMUDriver *driver, if (safewrite(dstFD, buf, r) < 0) { virReportSystemError(errno, _("Unable to write to file '%s'"), - loader->nvram); + tmp_dst_path); goto cleanup; } } while (r); @@ -4488,9 +4490,23 @@ qemuPrepareNVRAM(virQEMUDriver *driver, master_nvram_path); goto cleanup; } + + if (g_fsync(dstFD) < 0) { + virReportSystemError(errno, _("cannot sync file '%s'"), + tmp_dst_path); + goto cleanup; + } + if (VIR_CLOSE(dstFD) < 0) { virReportSystemError(errno, _("Unable to close file '%s'"), + tmp_dst_path); + goto cleanup; + } + + if (rename(tmp_dst_path, loader->nvram) < 0) { + virReportSystemError(errno, + _("Unable to replace '%s'"), loader->nvram); goto cleanup; } @@ -4501,7 +4517,7 @@ qemuPrepareNVRAM(virQEMUDriver *driver, * copy the file content. Roll back. */ if (ret < 0) { if (created) - unlink(loader->nvram); + unlink(tmp_dst_path); } =20 VIR_FORCE_CLOSE(srcFD); --=20 2.34.1 From nobody Sun May 19 12:00:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644346509; cv=none; d=zohomail.com; s=zohoarc; b=i3+DZdcjNaIdX79QIgjqhuFew80TN8h2FD6tSUm7eY/yk4BD4sLO4Y3lgVtFCJfUUPiTv29WQYC9pX2WL5ShkxiQcpmZ7sq9l/RNB7K8XxCc8dl6Y1KuE9zUjSYP9kKkUJFAypZ68VLURYWqIJkw5QCrIe9544c91yVbSd56d/w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644346509; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=+ye7AY3Z3kpbOoCai3QhjqOQkgbQ/AABmlA0y+NQOiQ=; b=dvwFlgX5R9u4nCOGKeB6F2BCr43j7F0wLs0dYo9o2E2vUtwa8wmgxXPiFwr7jqtBxMFc+I3h9Eq2Cosi+GGGhaqnbRIykd//O6GD4vxmZBD30gXfx4jjtcAw4MgmdmTUPVvXPErz8BA46Is8hkvfTerb0Pu/7/CtDoVmaDwofYg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1644346509038903.7968047152843; Tue, 8 Feb 2022 10:55:09 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-257-73Iq2VqvO5aSf4i-uPgYSw-1; Tue, 08 Feb 2022 13:53:25 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E377651089; Tue, 8 Feb 2022 18:53:17 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C23D47D498; Tue, 8 Feb 2022 18:53:17 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 907724A708; Tue, 8 Feb 2022 18:53:17 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 217CbFCm003354 for ; Mon, 7 Feb 2022 07:37:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 7AA926FB87; Mon, 7 Feb 2022 12:37:15 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id C89106F95B; Mon, 7 Feb 2022 12:37:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644346507; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+ye7AY3Z3kpbOoCai3QhjqOQkgbQ/AABmlA0y+NQOiQ=; b=Fr62W/E6eDgXDhx77DJ2UwAlWEc+MxIEGCvIckp4OSgmU3PHgqM/cO/hqWf1PJlH4ekmCH OnsbBCA6rdlw/JHlIGKNuVgs7Sy4KxX+lgr78dEKhUS1r+es7izmAokybmSWPhjPihPlpP PT2EvT4hxHu8vUZqlgX5xT/pyxDEUFU= X-MC-Unique: 73Iq2VqvO5aSf4i-uPgYSw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 2/4] include: define constants for resetting NVRAM state Date: Mon, 7 Feb 2022 12:37:08 +0000 Message-Id: <20220207123711.1042287-3-berrange@redhat.com> In-Reply-To: <20220207123711.1042287-1-berrange@redhat.com> References: <20220207123711.1042287-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644346510322100001 When starting a guest with pflash based firmware, we will initialize NVRAM from a template if it does not already exist. In theory if the firmware code file is updated, the existing NVRAM variables should continue to work correctly. It is inevitable that this could break accidentally one day. Or a bug in the firmware might corrupt the NVRAM storage. Or user might make bad changes to the settings that prevent booting. Or the user might have re-configured the XML to point to a different firmware file incompatible with the current variables. In all these cases it would be useful to delete the existing NVRAM and initialize it from the pristine template. To support this introduce a VIR_DOMAIN_START_RESET_NVRAM constant for use with virDomainCreate / virDomainCreateXML, along with a VIR_DOMAIN_SAVE_RESET_NVRAM constant for use with virDomainRestore. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- include/libvirt/libvirt-domain-snapshot.h | 1 + include/libvirt/libvirt-domain.h | 2 ++ src/libvirt-domain.c | 16 ++++++++++++++++ 3 files changed, 19 insertions(+) diff --git a/include/libvirt/libvirt-domain-snapshot.h b/include/libvirt/li= bvirt-domain-snapshot.h index 90673ed0fb..d729d1a532 100644 --- a/include/libvirt/libvirt-domain-snapshot.h +++ b/include/libvirt/libvirt-domain-snapshot.h @@ -198,6 +198,7 @@ typedef enum { VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING =3D 1 << 0, /* Run after revert */ VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED =3D 1 << 1, /* Pause after revert */ VIR_DOMAIN_SNAPSHOT_REVERT_FORCE =3D 1 << 2, /* Allow risky reverts = */ + VIR_DOMAIN_SNAPSHOT_REVERT_RESET_NVRAM =3D 1 << 3, /* Re-initialize NV= RAM from template */ } virDomainSnapshotRevertFlags; =20 /* Revert the domain to a point-in-time snapshot. The diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 374859fdff..8c16598817 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -302,6 +302,7 @@ typedef enum { VIR_DOMAIN_START_BYPASS_CACHE =3D 1 << 2, /* Avoid file system cache p= ollution */ VIR_DOMAIN_START_FORCE_BOOT =3D 1 << 3, /* Boot, discarding any mana= ged save */ VIR_DOMAIN_START_VALIDATE =3D 1 << 4, /* Validate the XML document= against schema */ + VIR_DOMAIN_START_RESET_NVRAM =3D 1 << 5, /* Re-initialize NVRAM from = template */ } virDomainCreateFlags; =20 =20 @@ -1268,6 +1269,7 @@ typedef enum { VIR_DOMAIN_SAVE_BYPASS_CACHE =3D 1 << 0, /* Avoid file system cache po= llution */ VIR_DOMAIN_SAVE_RUNNING =3D 1 << 1, /* Favor running over paused = */ VIR_DOMAIN_SAVE_PAUSED =3D 1 << 2, /* Favor paused over running = */ + VIR_DOMAIN_SAVE_RESET_NVRAM =3D 1 << 3, /* Re-initialize NVRAM from t= emplate */ } virDomainSaveRestoreFlags; =20 int virDomainSave (virDomainPtr domain, diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 5912551a49..75796affc7 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -154,6 +154,10 @@ virDomainGetConnect(virDomainPtr dom) * block attempts at migration. Hypervisors may also block save-to-file, * or snapshots. * + * If @flags includes VIR_DOMAIN_START_RESET_NVRAM, then libvirt will + * discard any existing NVRAM file and re-initialize NVRAM from the + * pristine template. + * * virDomainFree should be used to free the resources after the * domain object is no longer needed. * @@ -1015,6 +1019,10 @@ virDomainRestore(virConnectPtr conn, const char *fro= m) * @flags will override the default read from the file. These two * flags are mutually exclusive. * + * If @flags includes VIR_DOMAIN_SAVE_RESET_NVRAM, then libvirt will + * discard any existing NVRAM file and re-initialize NVRAM from the + * pristine template. + * * Returns 0 in case of success and -1 in case of failure. */ int @@ -6764,6 +6772,10 @@ virDomainCreate(virDomainPtr domain) * If the VIR_DOMAIN_START_FORCE_BOOT flag is set, then any managed save * file for this domain is discarded, and the domain boots from scratch. * + * If @flags includes VIR_DOMAIN_START_RESET_NVRAM, then libvirt will + * discard any existing NVRAM file and re-initialize NVRAM from the + * pristine template. + * * Returns 0 in case of success, -1 in case of error */ int @@ -6836,6 +6848,10 @@ virDomainCreateWithFlags(virDomainPtr domain, unsign= ed int flags) * If the VIR_DOMAIN_START_FORCE_BOOT flag is set, then any managed save * file for this domain is discarded, and the domain boots from scratch. * + * If @flags includes VIR_DOMAIN_START_RESET_NVRAM, then libvirt will + * discard any existing NVRAM file and re-initialize NVRAM from the + * pristine template. + * * Returns 0 in case of success, -1 in case of error */ int --=20 2.34.1 From nobody Sun May 19 12:00:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644346124; cv=none; d=zohomail.com; s=zohoarc; b=TmUMr9OCXty3kIQDPBmdtcnvCnkBuMxyURxtKyAozvhRbKgjw3NhMcg2A4IaTIKJKiPCaKr/1eZh1S0Qfa+zm0odQT4TpUz7jOErFLSGkq4Fz0OCSNb7n5FURY2NiKO5xaJkSkKfdE+xKXoM1BZ7dtlw+Asxrn96aT4xgF9qysM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644346124; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=5oZicreDdS16nOxUoevqGBF1w2RnWR/7/N8AbuAcYgw=; b=bfQjgXlTkxW+jVSEaxJ1kW05Y30B3W0mO6g1BBz62yFBlcIDUMIxpknr+C2CIln5zHgHZGwLWx2sZnCWdB10RxdYSOW4bJ4DLdTPoTBJF3TmY3Wa8ZmRVAhxrbnQRTnC8gqIUGUapnpNIdhpzrDCk+0sP32ywGJU2XLLqOFi+8U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644346124913384.29917122107724; Tue, 8 Feb 2022 10:48:44 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-176-iRQBxoiTNZeT5KGXrHq3hw-1; Tue, 08 Feb 2022 13:48:41 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 222CE51081; Tue, 8 Feb 2022 18:48:36 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0504174EA0; Tue, 8 Feb 2022 18:48:36 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id CC87F181844A; Tue, 8 Feb 2022 18:48:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 217CbGZC003363 for ; Mon, 7 Feb 2022 07:37:16 -0500 Received: by smtp.corp.redhat.com (Postfix) id 907CB6F95B; Mon, 7 Feb 2022 12:37:16 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id CFE396FB8C; Mon, 7 Feb 2022 12:37:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644346123; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=5oZicreDdS16nOxUoevqGBF1w2RnWR/7/N8AbuAcYgw=; b=ikC5ehvMxzMULkN2ogh3s+hix1BOt2Xm/TRM7LKEdr6zU3q+lGktVBJV5Ikh7sR9D9Y7Rv ZoBO/oTQ8pRZZtH+nSaYGYxIsLh6lq5YRWw/KS42tcJJO3/sIpMPVta4zINYuisV999lbu kT9EM0RTK/DTt0hoWvfVyGb7BFq4GYA= X-MC-Unique: iRQBxoiTNZeT5KGXrHq3hw-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 3/4] qemu: wire up support for resetting NVRAM Date: Mon, 7 Feb 2022 12:37:09 +0000 Message-Id: <20220207123711.1042287-4-berrange@redhat.com> In-Reply-To: <20220207123711.1042287-1-berrange@redhat.com> References: <20220207123711.1042287-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644346125916100003 We can now replace the existing NVRAM file on startup when the API requests this. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 24 ++++++++++++++++++------ src/qemu/qemu_process.c | 8 +++++--- src/qemu/qemu_process.h | 1 + src/qemu/qemu_saveimage.c | 9 +++++++-- src/qemu/qemu_saveimage.h | 1 + src/qemu/qemu_snapshot.c | 6 +++++- 6 files changed, 37 insertions(+), 12 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 698f57f00e..4831a81a78 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1589,7 +1589,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr= conn, =20 virCheckFlags(VIR_DOMAIN_START_PAUSED | VIR_DOMAIN_START_AUTODESTROY | - VIR_DOMAIN_START_VALIDATE, NULL); + VIR_DOMAIN_START_VALIDATE | + VIR_DOMAIN_START_RESET_NVRAM, NULL); =20 if (flags & VIR_DOMAIN_START_VALIDATE) parse_flags |=3D VIR_DOMAIN_DEF_PARSE_VALIDATE_SCHEMA; @@ -1597,6 +1598,8 @@ static virDomainPtr qemuDomainCreateXML(virConnectPtr= conn, start_flags |=3D VIR_QEMU_PROCESS_START_PAUSED; if (flags & VIR_DOMAIN_START_AUTODESTROY) start_flags |=3D VIR_QEMU_PROCESS_START_AUTODESTROY; + if (flags & VIR_DOMAIN_START_RESET_NVRAM) + start_flags |=3D VIR_QEMU_PROCESS_START_RESET_NVRAM; =20 virNWFilterReadLockFilterUpdates(); =20 @@ -5754,11 +5757,15 @@ qemuDomainRestoreFlags(virConnectPtr conn, virQEMUSaveData *data =3D NULL; virFileWrapperFd *wrapperFd =3D NULL; bool hook_taint =3D false; + bool reset_nvram =3D false; =20 virCheckFlags(VIR_DOMAIN_SAVE_BYPASS_CACHE | VIR_DOMAIN_SAVE_RUNNING | - VIR_DOMAIN_SAVE_PAUSED, -1); + VIR_DOMAIN_SAVE_PAUSED | + VIR_DOMAIN_SAVE_RESET_NVRAM, -1); =20 + if (flags & VIR_DOMAIN_SAVE_RESET_NVRAM) + reset_nvram =3D true; =20 virNWFilterReadLockFilterUpdates(); =20 @@ -5820,7 +5827,7 @@ qemuDomainRestoreFlags(virConnectPtr conn, goto cleanup; =20 ret =3D qemuSaveImageStartVM(conn, driver, vm, &fd, data, path, - false, QEMU_ASYNC_JOB_START); + false, reset_nvram, QEMU_ASYNC_JOB_START); =20 qemuProcessEndJob(driver, vm); =20 @@ -6029,6 +6036,7 @@ qemuDomainObjRestore(virConnectPtr conn, const char *path, bool start_paused, bool bypass_cache, + bool reset_nvram, qemuDomainAsyncJob asyncJob) { g_autoptr(virDomainDef) def =3D NULL; @@ -6087,7 +6095,7 @@ qemuDomainObjRestore(virConnectPtr conn, virDomainObjAssignDef(vm, &def, true, NULL); =20 ret =3D qemuSaveImageStartVM(conn, driver, vm, &fd, data, path, - start_paused, asyncJob); + start_paused, reset_nvram, asyncJob); =20 cleanup: virQEMUSaveDataFree(data); @@ -6299,11 +6307,13 @@ qemuDomainObjStart(virConnectPtr conn, bool autodestroy =3D (flags & VIR_DOMAIN_START_AUTODESTROY) !=3D 0; bool bypass_cache =3D (flags & VIR_DOMAIN_START_BYPASS_CACHE) !=3D 0; bool force_boot =3D (flags & VIR_DOMAIN_START_FORCE_BOOT) !=3D 0; + bool reset_nvram =3D (flags & VIR_DOMAIN_START_RESET_NVRAM) !=3D 0; unsigned int start_flags =3D VIR_QEMU_PROCESS_START_COLD; qemuDomainObjPrivate *priv =3D vm->privateData; =20 start_flags |=3D start_paused ? VIR_QEMU_PROCESS_START_PAUSED : 0; start_flags |=3D autodestroy ? VIR_QEMU_PROCESS_START_AUTODESTROY : 0; + start_flags |=3D reset_nvram ? VIR_QEMU_PROCESS_START_RESET_NVRAM : 0; =20 /* * If there is a managed saved state restore it instead of starting @@ -6328,7 +6338,8 @@ qemuDomainObjStart(virConnectPtr conn, priv->job.current->operation =3D VIR_DOMAIN_JOB_OPERATION_REST= ORE; =20 ret =3D qemuDomainObjRestore(conn, driver, vm, managed_save, - start_paused, bypass_cache, asyncJo= b); + start_paused, bypass_cache, + reset_nvram, asyncJob); =20 if (ret =3D=3D 0) { if (unlink(managed_save) < 0) @@ -6380,7 +6391,8 @@ qemuDomainCreateWithFlags(virDomainPtr dom, unsigned = int flags) virCheckFlags(VIR_DOMAIN_START_PAUSED | VIR_DOMAIN_START_AUTODESTROY | VIR_DOMAIN_START_BYPASS_CACHE | - VIR_DOMAIN_START_FORCE_BOOT, -1); + VIR_DOMAIN_START_FORCE_BOOT | + VIR_DOMAIN_START_RESET_NVRAM, -1); =20 virNWFilterReadLockFilterUpdates(); =20 diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index bc7c2a4dbc..659fba8672 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -4411,7 +4411,8 @@ qemuProcessUpdateCPU(virQEMUDriver *driver, =20 static int qemuPrepareNVRAM(virQEMUDriver *driver, - virDomainObj *vm) + virDomainObj *vm, + bool reset_nvram) { g_autoptr(virQEMUDriverConfig) cfg =3D virQEMUDriverGetConfig(driver); int ret =3D -1; @@ -4423,7 +4424,8 @@ qemuPrepareNVRAM(virQEMUDriver *driver, ssize_t r; g_autofree char *tmp_dst_path =3D NULL; =20 - if (!loader || !loader->nvram || virFileExists(loader->nvram)) + if (!loader || !loader->nvram || + (virFileExists(loader->nvram) && !reset_nvram)) return 0; =20 master_nvram_path =3D loader->templt; @@ -6973,7 +6975,7 @@ qemuProcessPrepareHost(virQEMUDriver *driver, qemuProcessMakeDir(driver, vm, priv->channelTargetDir) < 0) return -1; =20 - if (qemuPrepareNVRAM(driver, vm) < 0) + if (qemuPrepareNVRAM(driver, vm, flags & VIR_QEMU_PROCESS_START_RESET_= NVRAM) < 0) return -1; =20 if (vm->def->vsock) { diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h index 1b1cc489f0..f6c0d63d11 100644 --- a/src/qemu/qemu_process.h +++ b/src/qemu/qemu_process.h @@ -79,6 +79,7 @@ typedef enum { VIR_QEMU_PROCESS_START_PRETEND =3D 1 << 3, VIR_QEMU_PROCESS_START_NEW =3D 1 << 4, /* internal, new VM is= starting */ VIR_QEMU_PROCESS_START_GEN_VMID =3D 1 << 5, /* Generate a new VMID= */ + VIR_QEMU_PROCESS_START_RESET_NVRAM =3D 1 << 5, /* Re-initialize NVRAM= from template */ } qemuProcessStartFlags; =20 int qemuProcessStart(virConnectPtr conn, diff --git a/src/qemu/qemu_saveimage.c b/src/qemu/qemu_saveimage.c index 557ee2cd21..c0139041eb 100644 --- a/src/qemu/qemu_saveimage.c +++ b/src/qemu/qemu_saveimage.c @@ -577,6 +577,7 @@ qemuSaveImageStartVM(virConnectPtr conn, virQEMUSaveData *data, const char *path, bool start_paused, + bool reset_nvram, qemuDomainAsyncJob asyncJob) { qemuDomainObjPrivate *priv =3D vm->privateData; @@ -590,6 +591,11 @@ qemuSaveImageStartVM(virConnectPtr conn, virQEMUSaveHeader *header =3D &data->header; g_autoptr(qemuDomainSaveCookie) cookie =3D NULL; int rc =3D 0; + unsigned int start_flags =3D VIR_QEMU_PROCESS_START_PAUSED | + VIR_QEMU_PROCESS_START_GEN_VMID; + + if (reset_nvram) + start_flags |=3D VIR_QEMU_PROCESS_START_RESET_NVRAM; =20 if (virSaveCookieParseString(data->cookie, (virObject **)&cookie, virDomainXMLOptionGetSaveCookie(driver->x= mlopt)) < 0) @@ -628,8 +634,7 @@ qemuSaveImageStartVM(virConnectPtr conn, if (qemuProcessStart(conn, driver, vm, cookie ? cookie->cpu : NULL, asyncJob, "stdio", *fd, path, NULL, VIR_NETDEV_VPORT_PROFILE_OP_RESTORE, - VIR_QEMU_PROCESS_START_PAUSED | - VIR_QEMU_PROCESS_START_GEN_VMID) =3D=3D 0) + start_flags) =3D=3D 0) started =3D true; =20 if (intermediatefd !=3D -1) { diff --git a/src/qemu/qemu_saveimage.h b/src/qemu/qemu_saveimage.h index 45c5f35e11..a0daa4ad2b 100644 --- a/src/qemu/qemu_saveimage.h +++ b/src/qemu/qemu_saveimage.h @@ -67,6 +67,7 @@ qemuSaveImageStartVM(virConnectPtr conn, virQEMUSaveData *data, const char *path, bool start_paused, + bool reset_nvram, qemuDomainAsyncJob asyncJob) ATTRIBUTE_NONNULL(4) ATTRIBUTE_NONNULL(5) ATTRIBUTE_NONNULL(6); =20 diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 1887c70708..a99f1246e0 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2243,7 +2243,11 @@ qemuSnapshotRevert(virDomainObj *vm, =20 virCheckFlags(VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING | VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED | - VIR_DOMAIN_SNAPSHOT_REVERT_FORCE, -1); + VIR_DOMAIN_SNAPSHOT_REVERT_FORCE | + VIR_DOMAIN_SNAPSHOT_REVERT_RESET_NVRAM, -1); + + if (flags & VIR_DOMAIN_SNAPSHOT_REVERT_RESET_NVRAM) + start_flags |=3D VIR_QEMU_PROCESS_START_RESET_NVRAM; =20 /* We have the following transitions, which create the following event= s: * 1. inactive -> inactive: none --=20 2.34.1 From nobody Sun May 19 12:00:54 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1644346507; cv=none; d=zohomail.com; s=zohoarc; b=bOKiaRiauaEtk8eF/3PIBGsvX1ZqnIiTRXxF/xVUIhSrPOepjpz4UOb4jJ1Y43naaonodmHqN6e1N1A7NZrZ5RF02vR1pqHJutWCQjqrLXrNtNTxojL8reABsMcfn4vqyaIwYapObSxJNc31lb7jiOap4c2h41WNzLZsYfXeHQs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644346507; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=tGOXgrn3Z9BdlAoG66dmR0gSuFEEnmt949hCXFcPXUk=; b=Yle9Lllnr/5DEPOyE6YEyjHwO7s204iqAWeSLvEX8VUJIbTbVGOrimC5QmvFZrzG+a9QAJmjsKZQULZ3H3Jzgq0VsSP2ALIiYgBoKttmFqsNlYzhdqGwK+TwMxVhHPdJzMWtrADw9MNM0VaOR5Fy+UrRthsIxWVdw7e1YeP7Dwg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1644346507560305.2384173738709; Tue, 8 Feb 2022 10:55:07 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-531-006RwDXJMTmXXrpxOI6HNQ-1; Tue, 08 Feb 2022 13:53:30 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 01EF88519E5; Tue, 8 Feb 2022 18:53:25 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D77387A48F; Tue, 8 Feb 2022 18:53:24 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 8F0011826D2C; Tue, 8 Feb 2022 18:53:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 217CbHGU003378 for ; Mon, 7 Feb 2022 07:37:17 -0500 Received: by smtp.corp.redhat.com (Postfix) id 96BCB6FB8B; Mon, 7 Feb 2022 12:37:17 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.33.36.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id E46CD6F95B; Mon, 7 Feb 2022 12:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644346506; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=tGOXgrn3Z9BdlAoG66dmR0gSuFEEnmt949hCXFcPXUk=; b=cxbfsQzMvdFqZAUWxTXhBiPiqn2f6bJ+8ss6Uzw9L2jAopgSBfuuzupNDtWgTO8co2G2P/ BfCkUQ4Gy+pv2Tyz9zXXLRW1WIcDUaIe++GSbb647W3BrWn77UIeeQhzQmf2rnCiWSaV1b YgTsy1x5CCX5ZQZ36EWwuRbBWd46guE= X-MC-Unique: 006RwDXJMTmXXrpxOI6HNQ-1 From: =?UTF-8?q?Daniel=20P=2E=20Berrang=C3=A9?= To: libvir-list@redhat.com Subject: [libvirt PATCH 4/4] tools: add --reset-nvram arg to several virsh commands Date: Mon, 7 Feb 2022 12:37:10 +0000 Message-Id: <20220207123711.1042287-5-berrange@redhat.com> In-Reply-To: <20220207123711.1042287-1-berrange@redhat.com> References: <20220207123711.1042287-1-berrange@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1644346508127100001 This wires up support for resetting NVRAM for all APIs that allow this feature. Signed-off-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- docs/manpages/virsh.rst | 21 +++++++++++++++++---- tools/virsh-domain.c | 18 ++++++++++++++++++ tools/virsh-snapshot.c | 6 ++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst index e28927ed6c..429879d2dd 100644 --- a/docs/manpages/virsh.rst +++ b/docs/manpages/virsh.rst @@ -1455,7 +1455,7 @@ create :: =20 create FILE [--console] [--paused] [--autodestroy] - [--pass-fds N,M,...] [--validate] + [--pass-fds N,M,...] [--validate] [--reset-nvram] =20 Create a domain from an XML . Optionally, *--validate* option can be passed to validate the format of the input XML file against an internal RNG @@ -1478,6 +1478,9 @@ of open file descriptors which should be pass on into= the guest. The file descriptors will be re-numbered in the guest, starting from 3. This is only supported with container based virtualization. =20 +If *--reset-nvram* is specified, any existing NVRAM file will be deleted +and re-initialized from its pristine template. + **Example:** =20 #. prepare a template from an existing domain (skip directly to 3a if writ= ing @@ -3736,7 +3739,7 @@ restore :: =20 restore state-file [--bypass-cache] [--xml file] - [{--running | --paused}] + [{--running | --paused}] [--reset-nvram] =20 Restores a domain from a ``virsh save`` state file. See *save* for more in= fo. =20 @@ -3754,6 +3757,9 @@ save image to decide between running or paused; passi= ng either the *--running* or *--paused* flag will allow overriding which state the domain should be started in. =20 +If *--reset-nvram* is specified, any existing NVRAM file will be deleted +and re-initialized from its pristine template. + ``Note``: To avoid corrupting file system contents within the domain, you should not reuse the saved state file for a second ``restore`` unless you have also reverted all storage volumes back to the same contents as when @@ -4350,7 +4356,7 @@ start =20 start domain-name-or-uuid [--console] [--paused] [--autodestroy] [--bypass-cache] [--force-boot] - [--pass-fds N,M,...] + [--pass-fds N,M,...] [--reset-nvram] =20 Start a (previously defined) inactive domain, either from the last ``managedsave`` state, or via a fresh boot if no managedsave state is @@ -4369,6 +4375,9 @@ of open file descriptors which should be pass on into= the guest. The file descriptors will be re-numbered in the guest, starting from 3. This is only supported with container based virtualization. =20 +If *--reset-nvram* is specified, any existing NVRAM file will be deleted +and re-initialized from its pristine template. + =20 suspend ------- @@ -7352,7 +7361,8 @@ snapshot-revert =20 :: =20 - snapshot-revert domain {snapshot | --current} [{--running | --paused}] = [--force] + snapshot-revert domain {snapshot | --current} [{--running | --paused}] + [--force] [--reset-nvram] =20 Revert the given domain to the snapshot specified by *snapshot*, or to the current snapshot with *--current*. Be aware @@ -7398,6 +7408,9 @@ requires the use of *--force* to proceed: likely cause extensive filesystem corruption or crashes due to swap co= ntent mismatches when run. =20 +If *--reset-nvram* is specified, any existing NVRAM file will be deleted +and re-initialized from its pristine template. + =20 snapshot-delete --------------- diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 43d310f2af..97986788d7 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -4010,6 +4010,10 @@ static const vshCmdOptDef opts_start[] =3D { .completer =3D virshCompleteEmpty, .help =3D N_("pass file descriptors N,M,... to the guest") }, + {.name =3D "reset-nvram", + .type =3D VSH_OT_BOOL, + .help =3D N_("re-initialize NVRAM from its pristine template") + }, {.name =3D NULL} }; =20 @@ -4087,6 +4091,8 @@ cmdStart(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_START_BYPASS_CACHE; if (vshCommandOptBool(cmd, "force-boot")) flags |=3D VIR_DOMAIN_START_FORCE_BOOT; + if (vshCommandOptBool(cmd, "reset-nvram")) + flags |=3D VIR_DOMAIN_START_RESET_NVRAM; =20 /* We can emulate force boot, even for older servers that reject it. = */ if (flags & VIR_DOMAIN_START_FORCE_BOOT) { @@ -5268,6 +5274,10 @@ static const vshCmdOptDef opts_restore[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("restore domain into paused state") }, + {.name =3D "reset-nvram", + .type =3D VSH_OT_BOOL, + .help =3D N_("re-initialize NVRAM from its pristine template") + }, {.name =3D NULL} }; =20 @@ -5289,6 +5299,8 @@ cmdRestore(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_SAVE_RUNNING; if (vshCommandOptBool(cmd, "paused")) flags |=3D VIR_DOMAIN_SAVE_PAUSED; + if (vshCommandOptBool(cmd, "reset-nvram")) + flags |=3D VIR_DOMAIN_SAVE_RESET_NVRAM; =20 if (vshCommandOptStringReq(ctl, cmd, "xml", &xmlfile) < 0) return false; @@ -8093,6 +8105,10 @@ static const vshCmdOptDef opts_create[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("validate the XML against the schema") }, + {.name =3D "reset-nvram", + .type =3D VSH_OT_BOOL, + .help =3D N_("re-initialize NVRAM from its pristine template") + }, {.name =3D NULL} }; =20 @@ -8125,6 +8141,8 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_START_AUTODESTROY; if (vshCommandOptBool(cmd, "validate")) flags |=3D VIR_DOMAIN_START_VALIDATE; + if (vshCommandOptBool(cmd, "reset-nvram")) + flags |=3D VIR_DOMAIN_START_RESET_NVRAM; =20 if (nfds) dom =3D virDomainCreateXMLWithFiles(priv->conn, buffer, nfds, fds,= flags); diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 154e82b48b..b86fa73ac2 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1725,6 +1725,10 @@ static const vshCmdOptDef opts_snapshot_revert[] =3D= { .type =3D VSH_OT_BOOL, .help =3D N_("try harder on risky reverts") }, + {.name =3D "reset-nvram", + .type =3D VSH_OT_BOOL, + .help =3D N_("re-initialize NVRAM from its pristine template") + }, {.name =3D NULL} }; =20 @@ -1742,6 +1746,8 @@ cmdDomainSnapshotRevert(vshControl *ctl, const vshCmd= *cmd) flags |=3D VIR_DOMAIN_SNAPSHOT_REVERT_RUNNING; if (vshCommandOptBool(cmd, "paused")) flags |=3D VIR_DOMAIN_SNAPSHOT_REVERT_PAUSED; + if (vshCommandOptBool(cmd, "reset-nvram")) + flags |=3D VIR_DOMAIN_SNAPSHOT_REVERT_RESET_NVRAM; /* We want virsh snapshot-revert --force to work even when talking * to older servers that did the unsafe revert by default but * reject the flag, so we probe without the flag, and only use it --=20 2.34.1