From nobody Wed Dec 17 00:03:33 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail header.i=povilas@radix.lt; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1540141557957681.2050492154643; Sun, 21 Oct 2018 10:05:57 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2A8DE3DE3D; Sun, 21 Oct 2018 17:05:56 +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 39BC472303; Sun, 21 Oct 2018 17:05:55 +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 E699B18005B1; Sun, 21 Oct 2018 17:05:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w9LGdEo6005907 for ; Sun, 21 Oct 2018 12:39:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3213E6B8D1; Sun, 21 Oct 2018 16:39:14 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2ABB16B8CE for ; Sun, 21 Oct 2018 16:39:14 +0000 (UTC) Received: from sender-op-o11.zoho.com (sender-op-o11.zoho.com [135.84.80.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7096F3D945 for ; Sun, 21 Oct 2018 16:39:12 +0000 (UTC) Received: from localhost.localdomain (94.244.84.107 [94.244.84.107]) by mx.zohomail.com with SMTPS id 1540139946123765.6356760367719; Sun, 21 Oct 2018 09:39:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540139946; cv=none; d=zoho.com; s=zohoarc; b=RvkcZCUwzO087s92nVWcu7Qa2kQTMrRerhDHJiwsFzuNJUccwomsASXwAneH63hbYpvSaAsjQav6cBMK4idDNDncx63h90X18R/7Ept7fzWaprfFFEqrEJ66RWM/bwsHgBOWc5Y7A1k0bIKF7VqnGfwdrADh1/mlsM0vPD1RTIw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1540139946; h=Cc:Date:From:In-Reply-To:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=MWSTjRgBoJCHxmvjKd+uZ4ibdT6I7Yr64EYLtLs1JPo=; b=E1Gkf5Kjisv4BFe/kWkIYQ7/ndviM+5KTrPnwrp+LKMOdhmsIMSzRgUDjjI1j+CVWS150snLV4Hg59aU+YDGkTpXGzrhOKTG/aIDww1Ac8p3cgLb5yj6KX3YhJPs6Gx1pVxDBn8IQIoec21gUqUdj16QgyWnC+NN3Do+vPC/TLs= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=radix.lt; spf=pass smtp.mailfrom=povilas@radix.lt; dmarc=pass header.from= header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1540139946; s=zoho; d=radix.lt; i=povilas@radix.lt; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; l=3265; bh=MWSTjRgBoJCHxmvjKd+uZ4ibdT6I7Yr64EYLtLs1JPo=; b=dfJtxyDQ+SKLxGru5eBSyN3aacSxVnPD5VRMzlBKFpLKl9t35Mmj4SR0TI1Ksw1p ZuyIiKDnOqLQRxZsGPe77TqrWTypyKdpEJAnD+Z6bZXDAEPTZ41DhpXLDVcDpbPhb2y fdlodEeyjTiNJKqPdDOJ2VpsyAnrtVScBk+lzIts= From: Povilas Kanapickas To: libvir-list@redhat.com Date: Sun, 21 Oct 2018 19:38:50 +0300 Message-Id: <20181021163852.15114-4-povilas@radix.lt> In-Reply-To: <20181021163852.15114-1-povilas@radix.lt> References: <20181021163852.15114-1-povilas@radix.lt> X-ZohoMailClient: External X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 21 Oct 2018 16:39:12 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sun, 21 Oct 2018 16:39:12 +0000 (UTC) for IP:'135.84.80.196' DOMAIN:'sender-op-o11.zoho.com' HELO:'sender-op-o11.zoho.com' FROM:'povilas@radix.lt' RCPT:'' X-RedHat-Spam-Score: -0.111 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_NONE, SPF_PASS) 135.84.80.196 sender-op-o11.zoho.com 135.84.80.196 sender-op-o11.zoho.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Cc: Povilas Kanapickas Subject: [libvirt] [PATCH 3/5] snapshot: Support deleting external disk snapshots when deleting 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sun, 21 Oct 2018 17:05:56 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Povilas Kanapickas --- src/qemu/qemu_domain.c | 45 ++++++++++++++++++++++++++++++++++++++---- src/qemu/qemu_driver.c | 7 ++++--- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ba3fff607a..73c41788f8 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8244,6 +8244,38 @@ qemuDomainSnapshotForEachQcow2(virQEMUDriverPtr driv= er, op, try_all, def->ndisks); } =20 +static int +qemuDomainSnapshotDiscardExternal(virDomainSnapshotObjPtr snap) +{ + int i; + virDomainSnapshotDiskDefPtr snap_disk; + + // FIXME: libvirt stores the VM definition and the list of disks that + // snapshot has been taken of since 0.9.5. Before that we must assume = that + // all disks from within the VM definition have been snapshotted and t= hat + // they all were internal disks. Did libvirt support external snapshots + // before 0.9.5? If so, if we ever end up in this code path we may inc= ur + // data loss as we'll delete whole QEMU file thinking it's an external + // snapshot. + if (!snap->def->dom) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("Snapshots created using libvirt 9.5 and containi= ng " + "external disk snapshots cannot be safely " + "discarded.")); + return -1; + } + + for (i =3D 0; i < snap->def->ndisks; ++i) { + snap_disk =3D &(snap->def->disks[i]); + if (snap_disk->snapshot !=3D VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) + continue; + if (unlink(snap_disk->src->path) < 0) + VIR_WARN("Failed to unlink snapshot disk '%s'", + snap_disk->src->path); + } + return 0; +} + /* Discard one snapshot (or its metadata), without reparenting any childre= n. */ int qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, @@ -8260,10 +8292,15 @@ qemuDomainSnapshotDiscard(virQEMUDriverPtr driver, =20 if (!metadata_only) { if (!virDomainObjIsActive(vm)) { - /* Ignore any skipped disks */ - if (qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-d", - true) < 0) - goto cleanup; + if (virDomainSnapshotIsExternal(snap)) { + if (qemuDomainSnapshotDiscardExternal(snap) < 0) + goto cleanup; + } else { + /* Ignore any skipped disks */ + if (qemuDomainSnapshotForEachQcow2(driver, vm, snap, "-d", + true) < 0) + goto cleanup; + } } else { priv =3D vm->privateData; qemuDomainObjEnterMonitor(driver, vm); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index eb104d306b..7cd44d6957 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -16662,7 +16662,7 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snaps= hot, if (!(snap =3D qemuSnapObjFromSnapshot(vm, snapshot))) goto endjob; =20 - if (!metadata_only) { + if (!metadata_only && virDomainObjIsActive(vm)) { if (!(flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN_ONLY) && virDomainSnapshotIsExternal(snap)) external++; @@ -16673,8 +16673,9 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr snaps= hot, &external); if (external) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("deletion of %d external disk snapshots not " - "supported yet"), external); + _("deletion of %d external disk snapshots while= the " + "domain is active is not supported yet"), + external); goto endjob; } } --=20 2.17.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list