From nobody Wed Mar 12 13:56:09 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 1741268409279447.3654565649665; Thu, 6 Mar 2025 05:40:09 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id AAB841880; Thu, 6 Mar 2025 08:40:08 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id AE83118F0; Thu, 6 Mar 2025 08:39:50 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 88AA7188F; Thu, 6 Mar 2025 08:39:47 -0500 (EST) 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 123251879 for ; Thu, 6 Mar 2025 08:39:47 -0500 (EST) Received: from mx-prod-mc-03.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-371-RSaDlLHjNFS40muVtzm6Jw-1; Thu, 06 Mar 2025 08:39:45 -0500 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 99AE51954B3A for ; Thu, 6 Mar 2025 13:39:44 +0000 (UTC) Received: from antique-work.redhat.com (unknown [10.44.33.191]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5195B1944F2E for ; Thu, 6 Mar 2025 13:39:43 +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.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5,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=1741268386; 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=x9+VZdK95HGqU2Xm2nvQsdsXFZxuTNc5wFbcrlU/5Ms=; b=HgvXdUfGPtgEt0FBIM0qjpUcZbLGXVA9b5UukMuWRovp8DtYKu114u4OF16GkBjL5NGb7V 5swN0IL3C9SVMWu+mmt6oKhWdBVMu8Y93W8o+xeT0yLuEbnbAs2E0MbeFF5pXxGYTiGsq6 yCRlqFr1lm8kV3KXvQEQfXSbyqWGsIk= X-MC-Unique: RSaDlLHjNFS40muVtzm6Jw-1 X-Mimecast-MFC-AGG-ID: RSaDlLHjNFS40muVtzm6Jw_1741268384 From: Pavel Hrdina To: devel@lists.libvirt.org Subject: [libvirt PATCH v2] qemu: snapshot: error out early when reverting snapshot for VM with non-file disk Date: Thu, 6 Mar 2025 14:39:41 +0100 Message-ID: <2e4be97a9cab46ac2600b1b09aa51a6c923bc725.1741265850.git.phrdina@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: dzLBjDQ8FxfpmggYzfOJY9hxrcFkq1i-sJu9GmzVUP4_1741268384 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: BDTDAD3JARDQ65TTXYABHQBMYUSN2AMK X-Message-ID-Hash: BDTDAD3JARDQ65TTXYABHQBMYUSN2AMK X-MailFrom: phrdina@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: 1741268409751019000 Content-Type: text/plain; charset="utf-8"; x-default="true" Before this patch the code would start the revert process by destroying the VM and preparing to revert where it would fail with following error: error: unsupported configuration: source for disk 'sdb' is not a regula= r file; refusing to generate external snapshot name and leaving user with offline VM even if it was running. Make the check before we start the revert process to not destroy VMs. Resolves: https://issues.redhat.com/browse/RHEL-30971 Resolves: https://issues.redhat.com/browse/RHEL-79928 Signed-off-by: Pavel Hrdina Reviewed-by: Peter Krempa --- Changes in v2: - add comments - limit the check for external snapshots src/qemu/qemu_snapshot.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/qemu/qemu_snapshot.c b/src/qemu/qemu_snapshot.c index 891e67e98b..dab841ef5b 100644 --- a/src/qemu/qemu_snapshot.c +++ b/src/qemu/qemu_snapshot.c @@ -2203,6 +2203,8 @@ qemuSnapshotRevertValidate(virDomainObj *vm, virDomainSnapshotDef *snapdef, unsigned int flags) { + size_t i; + if (!vm->persistent && snapdef->state !=3D VIR_DOMAIN_SNAPSHOT_RUNNING && snapdef->state !=3D VIR_DOMAIN_SNAPSHOT_PAUSED && @@ -2230,6 +2232,22 @@ qemuSnapshotRevertValidate(virDomainObj *vm, } } =20 + /* Reverting to external snapshot creates overlay files for every disk= and + * it would fail for non-file based disks. + * See qemuSnapshotRevertExternalPrepare for more details. */ + if (virDomainSnapshotIsExternal(snap)) { + for (i =3D 0; i < snap->def->dom->ndisks; i++) { + virDomainDiskDef *disk =3D snap->def->dom->disks[i]; + + if (disk->src->type !=3D VIR_STORAGE_TYPE_FILE) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("source disk for '%1$s' is not a regular = file, reverting to snapshot is not supported"), + disk->dst); + return -1; + } + } + } + return 0; } =20 @@ -2381,6 +2399,9 @@ qemuSnapshotRevertExternalPrepare(virDomainObj *vm, if (virDomainMomentDefPostParse(&tmpsnapdef->parent) < 0) return -1; =20 + /* Force default location to be external in order to create overlay fi= les + * for every disk. In qemuSnapshotRevertValidate we make sure that each + * disk is regular file otherwise this would fail. */ if (virDomainSnapshotAlignDisks(tmpsnapdef, domdef, VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL, false, true) < 0) { --=20 2.48.1