From nobody Fri Jan 3 08:08:24 2025 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 1729177437294266.0923022398514; Thu, 17 Oct 2024 08:03:57 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 456A4123C; Thu, 17 Oct 2024 11:03:56 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 6E88411E2; Thu, 17 Oct 2024 11:02:12 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 7451A1183; Thu, 17 Oct 2024 11:02:09 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 9C5DB1182 for ; Thu, 17 Oct 2024 11:02:05 -0400 (EDT) Received: from mx-prod-mc-04.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-443-i9jCIsPDOgaotW7ioukOLw-1; Thu, 17 Oct 2024 11:02:03 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (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-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 34E151955F37 for ; Thu, 17 Oct 2024 15:02:03 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.45.242.4]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 57D1E195607C for ; Thu, 17 Oct 2024 15:02:02 +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=3.0 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_SBL_CSS, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED, SPF_HELO_NONE autolearn=no autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1729177325; 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; bh=H9bTM7hjd6dKEMasw8Td6WNgXVQ4BauyEJ6mhrs8M4U=; b=Sc1uDjrvm8LTL8acrlbfSlXsbgMgmgu5JUr7/VQHwIqOaXxcIpGUuOFNFvfdjWuU8Ad70k HTzmC0FZ2vnuqHva0WEdFaPKsJ70TVE1T6MiAcKRiAj6rKNxJIhBIzocjWgD+/1Lb03cIq /kT18XsZx9JdjHK7ukI9xFsa7G1lTN4= X-MC-Unique: i9jCIsPDOgaotW7ioukOLw-1 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH] qemu: Give the users possibility to overwrite temp files for disk Date: Thu, 17 Oct 2024 17:02:00 +0200 Message-ID: <127e826b629c8fb75e2da132da0c606019428385.1729177319.git.pkrempa@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: QBFCNUWZ4HZKDOFMCCHG53ZSKJ7WIULM X-Message-ID-Hash: QBFCNUWZ4HZKDOFMCCHG53ZSKJ7WIULM 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: 1729177438167116600 Content-Type: text/plain; charset="utf-8" Normally when starting up a VM with a transient disk, if the file libvirt would use as the temp overlay for the original disk image exists libvirt will not touch it and fail startup. This is done in order to avoid any potential removal of user files if they manage to create a colliding filename. In case when the user doesn't want the above behaviour this patch' introduces a 'overwriteTemp' attribute for the '' element which allows users to opt into simply removing the file before the next start. Closes: https://gitlab.com/libvirt/libvirt/-/issues/684 Signed-off-by: Peter Krempa --- docs/formatdomain.rst | 7 +++++++ src/conf/domain_conf.c | 7 +++++++ src/conf/domain_conf.h | 1 + src/conf/schemas/domaincommon.rng | 5 +++++ src/qemu/qemu_snapshot.c | 17 +++++++++++++---- .../disk-transient.x86_64-latest.xml | 2 +- tests/qemuxmlconfdata/disk-transient.xml | 2 +- 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index e6f09a728f..ab2fccdd97 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -3479,6 +3479,13 @@ paravirtualized driver is specified via the ``disk``= element. ``shareBacking`` attribute should be set to ``yes``. Note that hypervis= or drivers may need to hotplug such disk and thus it works only with configurations supporting hotplug. :since:`Since 7.4.0` + + Hypervisors may need to store a temporary file containing the data writ= ten + by the domain while running, which may be stored in the same location + as the original source of the disk. Note that in some cases the tempora= ry + file can't be cleaned up (e.g. when the domain is not shutdown before = the host). + An optional attribute ``overwriteTemp`` set to ``yes`` (:since:`Since 1= 0.10`) + indicates that the hypervisor may overwrite the file rather than fail s= tartup. ``serial`` If present, this specify serial number of virtual hard drive. For examp= le, it may look like ``WD-WMAP9A966149``. Not supported for diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 6d7dee7956..359591d8f7 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -8240,6 +8240,11 @@ virDomainDiskDefParseXML(virDomainXMLOption *xmlopt, VIR_XML_PROP_NONE, &def->transientShareBacking) < 0) return NULL; + + if (virXMLPropTristateBool(transientNode, "overwriteTemp", + VIR_XML_PROP_NONE, + &def->transientOverwriteTemp) < 0) + return NULL; } if (virDomainDiskDefIotuneParse(def, ctxt) < 0) @@ -23233,6 +23238,8 @@ virDomainDiskDefFormat(virBuffer *buf, virBufferAddLit(&childBuf, "transientShareBacking =3D=3D VIR_TRISTATE_BOOL_YES) virBufferAddLit(&childBuf, " shareBacking=3D'yes'"); + if (def->transientOverwriteTemp =3D=3D VIR_TRISTATE_BOOL_YES) + virBufferAddLit(&childBuf, " overwriteTemp=3D'yes'"); virBufferAddLit(&childBuf, "/>\n"); } virBufferEscapeString(&childBuf, "%s\n", def->serial); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index a15af4fae3..169c626584 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -569,6 +569,7 @@ struct _virDomainDiskDef { virDomainStartupPolicy startupPolicy; bool transient; virTristateBool transientShareBacking; + virTristateBool transientOverwriteTemp; virDomainDeviceInfo info; virTristateBool rawio; virDomainDeviceSGIO sgio; diff --git a/src/conf/schemas/domaincommon.rng b/src/conf/schemas/domaincom= mon.rng index efb5f00d77..cd87e83410 100644 --- a/src/conf/schemas/domaincommon.rng +++ b/src/conf/schemas/domaincommon.rng @@ -1618,6 +1618,11 @@ + + + + + diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 1187ebf276..b8ca045900 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -1287,10 +1287,19 @@ qemuSnapshotGetTransientDiskDef(virDomainDiskDef *d= omdisk, domdisk->src->path, suffix); if (virFileExists(snapdisk->src->path)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, - _("Overlay file '%1$s' for transient disk '%2$s' al= ready exists"), - snapdisk->src->path, domdisk->dst); - return NULL; + if (domdisk->transientOverwriteTemp =3D=3D VIR_TRISTATE_BOOL_YES) { + if (unlink(snapdisk->src->path) !=3D 0) { + virReportSystemError(errno, + _("Failed to delete overlay file '%1$= s' for transient disk '%2$s'"), + snapdisk->src->path, domdisk->dst); + return NULL; + } + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("Overlay file '%1$s' for transient disk '%2$s= ' already exists"), + snapdisk->src->path, domdisk->dst); + return NULL; + } } return g_steal_pointer(&snapdisk); diff --git a/tests/qemuxmlconfdata/disk-transient.x86_64-latest.xml b/tests= /qemuxmlconfdata/disk-transient.x86_64-latest.xml index aab5894447..5f8f15f714 100644 --- a/tests/qemuxmlconfdata/disk-transient.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/disk-transient.x86_64-latest.xml @@ -21,7 +21,7 @@ - +
diff --git a/tests/qemuxmlconfdata/disk-transient.xml b/tests/qemuxmlconfda= ta/disk-transient.xml index edd65a0da0..722f1f9a92 100644 --- a/tests/qemuxmlconfdata/disk-transient.xml +++ b/tests/qemuxmlconfdata/disk-transient.xml @@ -18,7 +18,7 @@ - + --=20 2.47.0