From nobody Tue May 7 19:08:10 2024 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552025289532951.4498578640059; Thu, 7 Mar 2019 22:08:09 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D1C4C3B7F; Fri, 8 Mar 2019 06:08:06 +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 4355B19C70; Fri, 8 Mar 2019 06:08:05 +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 8FC19181A12C; Fri, 8 Mar 2019 06:08:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2865F7b017301 for ; Fri, 8 Mar 2019 01:05:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id 8018160C5F; Fri, 8 Mar 2019 06:05:15 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2B50E60BE5 for ; Fri, 8 Mar 2019 06:05:15 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 8 Mar 2019 00:05:08 -0600 Message-Id: <20190308060512.17733-2-eblake@redhat.com> In-Reply-To: <20190308060512.17733-1-eblake@redhat.com> References: <20190308060512.17733-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 1/5] snapshots: Add flag to guarantee topological sort 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 08 Mar 2019 06:08:08 +0000 (UTC) Content-Type: text/plain; charset="utf-8" When doing REDEFINE on multiple snapshot metadata XML descriptions, we require that a child cannot be redefined before its parent. Since libvirt already tracks a DAG, it is more convenient if we can ensure that virDomainListAllSnapshots() and friends have a way to return data in an order that we can directly reuse, rather than having to post-process the data ourselves to reconstruct the DAG. Add VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL as our new guarantee (well, a guarantee at the time of the API call conclusion; there's always a possible TOCTTOU race where someone redefining snapshots in between the API results and the client actually using the list might render the list out-of-date). Four listing APIs are directly benefitted by the new flag; additionally, since we document that the older racy ListNames interfaces should be sized by using the same flags on their Num counterparts, the Num interfaces must document when they accept (and ignore) the flag. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- include/libvirt/libvirt-domain-snapshot.h | 4 +++ src/libvirt-domain-snapshot.c | 42 ++++++++++++++++++++++- 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/include/libvirt/libvirt-domain-snapshot.h b/include/libvirt/li= bvirt-domain-snapshot.h index d9b689abbd..602e5def59 100644 --- a/include/libvirt/libvirt-domain-snapshot.h +++ b/include/libvirt/libvirt-domain-snapshot.h @@ -135,6 +135,10 @@ typedef enum { VIR_DOMAIN_SNAPSHOT_LIST_EXTERNAL =3D (1 << 9), /* Filter by snapsh= ots that use files ext= ernal to disk images */ + + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL =3D (1 << 10), /* Ensure parents = occur + before children in + the resulting lis= t */ } virDomainSnapshotListFlags; /* Return the number of snapshots for this domain */ diff --git a/src/libvirt-domain-snapshot.c b/src/libvirt-domain-snapshot.c index 11d84289f8..d133c84933 100644 --- a/src/libvirt-domain-snapshot.c +++ b/src/libvirt-domain-snapshot.c @@ -1,7 +1,7 @@ /* * libvirt-domain-snapshot.c: entry points for virDomainSnapshotPtr APIs * - * Copyright (C) 2006-2014 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -298,6 +298,10 @@ virDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snaps= hot, * * Provides the number of domain snapshots for this domain. * + * This function will accept VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL in + * @flags only if virDomainSnapshotListNames() can honor it, although + * the flag has no other effect here. + * * By default, this command covers all snapshots; it is also possible to * limit things to just snapshots with no parents, when @flags includes * VIR_DOMAIN_SNAPSHOT_LIST_ROOTS. Additional filters are provided in @@ -369,6 +373,14 @@ virDomainSnapshotNum(virDomainPtr domain, unsigned int= flags) * their names in @names. The value to use for @nameslen can be determined * by virDomainSnapshotNum() with the same @flags. * + * If @flags contains VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL, and no + * other connection is modifying snapshots, then it is guaranteed that + * for any snapshot in the resulting list, then no snapshots later in + * the list can be reached by a sequence of + * virDomainSnapshotGetParent() starting from that snapshot; + * otherwise, the order of snapshots in the resulting list is + * unspecified. + * * By default, this command covers all snapshots; it is also possible to * limit things to just snapshots with no parents, when @flags includes * VIR_DOMAIN_SNAPSHOT_LIST_ROOTS. Additional filters are provided in @@ -457,6 +469,14 @@ virDomainSnapshotListNames(virDomainPtr domain, char *= *names, int nameslen, * an array to store those objects. This API solves the race inherent in * virDomainSnapshotListNames(). * + * If @flags contains VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL and @snaps + * is non-NULL, and no other connection is modifying snapshots, then + * it is guaranteed that for any snapshot in the resulting list, no + * snapshots later in the list can be reached by a sequence of + * virDomainSnapshotGetParent() starting from that snapshot; + * otherwise, the order of snapshots in the resulting list is + * unspecified. + * * By default, this command covers all snapshots; it is also possible to * limit things to just snapshots with no parents, when @flags includes * VIR_DOMAIN_SNAPSHOT_LIST_ROOTS. Additional filters are provided in @@ -533,6 +553,10 @@ virDomainListAllSnapshots(virDomainPtr domain, virDoma= inSnapshotPtr **snaps, * * Provides the number of child snapshots for this domain snapshot. * + * This function will accept VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL in + * @flags only if virDomainSnapshotListChildrenNames() can honor it, + * although the flag has no other effect here. + * * By default, this command covers only direct children; it is also possib= le * to expand things to cover all descendants, when @flags includes * VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS. Also, some filters are provided = in @@ -605,6 +629,14 @@ virDomainSnapshotNumChildren(virDomainSnapshotPtr snap= shot, unsigned int flags) * @nameslen can be determined by virDomainSnapshotNumChildren() with * the same @flags. * + * If @flags lacks VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS or contains + * VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL, and no other connection is + * modifying snapshots, then it is guaranteed that for any snapshot in + * the resulting list, no snapshots later in the list can be reached + * by a sequence of virDomainSnapshotGetParent() starting from that + * snapshot; otherwise, the order of snapshots in the resulting list + * is unspecified. + * * By default, this command covers only direct children; it is also possib= le * to expand things to cover all descendants, when @flags includes * VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS. Also, some filters are provided = in @@ -697,6 +729,14 @@ virDomainSnapshotListChildrenNames(virDomainSnapshotPt= r snapshot, * snapshot, and allocate an array to store those objects. This API solves * the race inherent in virDomainSnapshotListChildrenNames(). * + * If @flags lacks VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS or contains + * VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL, @snaps is non-NULL, and no + * other connection is modifying snapshots, then it is guaranteed that + * for any snapshot in the resulting list, no snapshots later in the + * list can be reached by a sequence of virDomainSnapshotGetParent() + * starting from that snapshot; otherwise, the order of snapshots in + * the resulting list is unspecified. + * * By default, this command covers only direct children; it is also possib= le * to expand things to cover all descendants, when @flags includes * VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS. Also, some filters are provided = in --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 19:08:10 2024 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15520253210621005.0047165824402; Thu, 7 Mar 2019 22:08:41 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 57A7BC0587DD; Fri, 8 Mar 2019 06:08:39 +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 2781119C70; Fri, 8 Mar 2019 06:08:39 +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 DBD60181A137; Fri, 8 Mar 2019 06:08:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2865Fvq017306 for ; Fri, 8 Mar 2019 01:05:15 -0500 Received: by smtp.corp.redhat.com (Postfix) id E4C4860C5F; Fri, 8 Mar 2019 06:05:15 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id A653660BE5 for ; Fri, 8 Mar 2019 06:05:15 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 8 Mar 2019 00:05:09 -0600 Message-Id: <20190308060512.17733-3-eblake@redhat.com> In-Reply-To: <20190308060512.17733-1-eblake@redhat.com> References: <20190308060512.17733-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 2/5] snapshots: Support topological visits 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Fri, 08 Mar 2019 06:08:39 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Wire up support for VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL in the domain-agnostic support code. Clients of snapshot_conf were previously getting a depth-first search on anything that used virDomainSnapshotForEachDescendant(); but a switch to a breadth-first search will give a topological search. With that change, we now always have a topological sort for virDomainSnapshotListAllChildren(); then with one more tweak, we can get a topological rather than a faster random hash visit for virDomainListAllSnapshots(). Note that virDomainSnapshotForEach() still uses a random hash visit; we could change that signature to take a tri-state for random, depth-first, or breadth-first visit if we ever had clients that cared about the distinctions, but for now, none of the drivers seem to care. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/conf/snapshot_conf.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 224f3e6ca1..e2c91a5072 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -1213,9 +1213,10 @@ virDomainSnapshotObjListGetNames(virDomainSnapshotOb= jListPtr snapshots, from =3D &snapshots->metaroot; } - /* We handle LIST_ROOT/LIST_DESCENDANTS directly, mask that bit - * out to determine when we must use the filter callback. */ - data.flags &=3D ~VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS; + /* We handle LIST_ROOT/LIST_DESCENDANTS and LIST_TOPOLOGICAL directly, + * mask those bits out to determine when we must use the filter callba= ck. */ + data.flags &=3D ~(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL); /* If this common code is being used, we assume that all snapshots * have metadata, and thus can handle METADATA up front as an @@ -1240,7 +1241,11 @@ virDomainSnapshotObjListGetNames(virDomainSnapshotOb= jListPtr snapshots, data.flags &=3D ~VIR_DOMAIN_SNAPSHOT_FILTERS_LOCATION; if (flags & VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS) { - if (from->def) + /* We could just always do a topological visit; but it is + * possible to optimize for less stack usage and time when a + * simpler full hashtable visit or counter will do. */ + if (from->def || (names && + (flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL))) virDomainSnapshotForEachDescendant(from, virDomainSnapshotObjListCop= yNames, &data); @@ -1327,10 +1332,10 @@ virDomainSnapshotActOnDescendant(void *payload, virDomainSnapshotObjPtr obj =3D payload; struct snapshot_act_on_descendant *curr =3D data; + (curr->iter)(payload, name, curr->data); curr->number +=3D 1 + virDomainSnapshotForEachDescendant(obj, curr->iter, curr->data); - (curr->iter)(payload, name, curr->data); return 0; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 19:08:10 2024 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552025301938184.46228608079286; Thu, 7 Mar 2019 22:08:21 -0800 (PST) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F140130917A8; Fri, 8 Mar 2019 06:08:19 +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 B780F10018F9; Fri, 8 Mar 2019 06:08:19 +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 45F7B41F3D; Fri, 8 Mar 2019 06:08:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2865ITs017321 for ; Fri, 8 Mar 2019 01:05:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 3201860BE5; Fri, 8 Mar 2019 06:05:18 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id E68A160C5F for ; Fri, 8 Mar 2019 06:05:16 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 8 Mar 2019 00:05:10 -0600 Message-Id: <20190308060512.17733-4-eblake@redhat.com> In-Reply-To: <20190308060512.17733-1-eblake@redhat.com> References: <20190308060512.17733-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 3/5] test: Support topological visits 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: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Fri, 08 Mar 2019 06:08:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" snapshot_conf does all the hard work, the test driver just has to accept the new flag. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/test/test_driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ef754658f3..02cd4f4d07 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5960,6 +5960,7 @@ testDomainSnapshotNum(virDomainPtr domain, unsigned i= nt flags) int n; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D testDomObjFromDomain(domain))) @@ -5981,6 +5982,7 @@ testDomainSnapshotListNames(virDomainPtr domain, int n; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D testDomObjFromDomain(domain))) @@ -6002,6 +6004,7 @@ testDomainListAllSnapshots(virDomainPtr domain, int n; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D testDomObjFromDomain(domain))) @@ -6024,6 +6027,7 @@ testDomainSnapshotListChildrenNames(virDomainSnapshot= Ptr snapshot, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D testDomObjFromSnapshot(snapshot))) @@ -6049,6 +6053,7 @@ testDomainSnapshotNumChildren(virDomainSnapshotPtr sn= apshot, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D testDomObjFromSnapshot(snapshot))) @@ -6074,6 +6079,7 @@ testDomainSnapshotListAllChildren(virDomainSnapshotPt= r snapshot, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D testDomObjFromSnapshot(snapshot))) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 19:08:10 2024 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1552025311807324.65637692120856; Thu, 7 Mar 2019 22:08:31 -0800 (PST) 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 mx1.redhat.com (Postfix) with ESMTPS id A9C4930832CB; Fri, 8 Mar 2019 06:08:29 +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 83FF4179E4; Fri, 8 Mar 2019 06:08:29 +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 46F80EEE2; Fri, 8 Mar 2019 06:08:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2865Is6017326 for ; Fri, 8 Mar 2019 01:05:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 97ECE60C5F; Fri, 8 Mar 2019 06:05:18 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 57A6B60BE5 for ; Fri, 8 Mar 2019 06:05:18 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 8 Mar 2019 00:05:11 -0600 Message-Id: <20190308060512.17733-5-eblake@redhat.com> In-Reply-To: <20190308060512.17733-1-eblake@redhat.com> References: <20190308060512.17733-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 4/5] qemu: Support topological visits 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Fri, 08 Mar 2019 06:08:30 +0000 (UTC) Content-Type: text/plain; charset="utf-8" snapshot_conf does all the hard work, the qemu driver just has to accept the new flag. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_driver.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 205e544d92..e461fb51b0 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15972,6 +15972,7 @@ qemuDomainSnapshotListNames(virDomainPtr domain, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D qemuDomObjFromDomain(domain))) @@ -15997,6 +15998,7 @@ qemuDomainSnapshotNum(virDomainPtr domain, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D qemuDomObjFromDomain(domain))) @@ -16022,6 +16024,7 @@ qemuDomainListAllSnapshots(virDomainPtr domain, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_ROOTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D qemuDomObjFromDomain(domain))) @@ -16049,6 +16052,7 @@ qemuDomainSnapshotListChildrenNames(virDomainSnapsh= otPtr snapshot, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D qemuDomObjFromSnapshot(snapshot))) @@ -16078,6 +16082,7 @@ qemuDomainSnapshotNumChildren(virDomainSnapshotPtr = snapshot, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D qemuDomObjFromSnapshot(snapshot))) @@ -16107,6 +16112,7 @@ qemuDomainSnapshotListAllChildren(virDomainSnapshot= Ptr snapshot, int n =3D -1; virCheckFlags(VIR_DOMAIN_SNAPSHOT_LIST_DESCENDANTS | + VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL | VIR_DOMAIN_SNAPSHOT_FILTERS_ALL, -1); if (!(vm =3D qemuDomObjFromSnapshot(snapshot))) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Tue May 7 19:08:10 2024 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; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 155202531495613.263357987337145; Thu, 7 Mar 2019 22:08:34 -0800 (PST) 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 36CB4307EA90; Fri, 8 Mar 2019 06:08:33 +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 0B0A65C5FD; Fri, 8 Mar 2019 06:08:33 +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 B3A85181A135; Fri, 8 Mar 2019 06:08:32 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x2865JQX017331 for ; Fri, 8 Mar 2019 01:05:19 -0500 Received: by smtp.corp.redhat.com (Postfix) id 084E760C5F; Fri, 8 Mar 2019 06:05:19 +0000 (UTC) Received: from blue.redhat.com (ovpn-118-35.phx2.redhat.com [10.3.118.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE41E60BE5 for ; Fri, 8 Mar 2019 06:05:18 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Fri, 8 Mar 2019 00:05:12 -0600 Message-Id: <20190308060512.17733-6-eblake@redhat.com> In-Reply-To: <20190308060512.17733-1-eblake@redhat.com> References: <20190308060512.17733-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH 5/5] virsh: Add snapshot-list --topological 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: , 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.44]); Fri, 08 Mar 2019 06:08:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" To some extent, virsh already has a (shockingly naive [1]) client-side topological sorter with the --tree option. But as a series of REDEFINE calls must be presented in topological order, it's worth letting the server do the work for us. [1] The XXX comment about O(n^3) in virshSnapshotListCollect() is telling; https://en.wikipedia.org/wiki/Topological_sorting is an interesting resource for anyone motivated to use a more elegant algorithm than brute force. For now, I am purposefully NOT implementing virsh fallback code to provide a topological sort when the flag was rejected as unsupported; we can worry about that down the road if users actually demonstrate that they use new virsh but old libvirt to even need the fallback. The test driver makes it easy to test: $ virsh -c test:///default ' snapshot-create-as test a snapshot-create-as test c snapshot-create-as test b snapshot-list test snapshot-list test --topological snapshot-list test --descendants a snapshot-list test --descendants a --topological snapshot-list test --tree snapshot-list test --tree --topological ' Without --topological, virsh does client-side sorting alphabetically, and lists 'b' before 'c' (even though 'c' is the parent of 'b'); with the flag, virsh skips sorting, and you can now see that the server handed back data in a correct ordering. As shown here with a simple linear chain, there isn't any other possible ordering, and --tree mode doesn't seem to care whether --topological is used. But it is possible to compose more complicated DAGs with multiple children to a parent (representing reverting back to a snapshot then creating more snapshots along those divergent execution timelines), where it may become possible to observe non-deterministic behavior when --topological is in use, but even so, the result will still be topologically correct. Signed-off-by: Eric Blake Reviewed-by: J=C3=A1n Tomko --- tools/virsh-snapshot.c | 16 +++++++++++++--- tools/virsh.pod | 7 ++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index 025321c58e..31153f5b10 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -1272,7 +1272,9 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, * still in list. We mark known descendants by clearing * snaps[i].parents. Sorry, this is O(n^3) - hope your * hierarchy isn't huge. XXX Is it worth making O(n^2 log n) - * by using qsort and bsearch? */ + * by using qsort and bsearch? Or even a linear topological + * sort such as Kahn's algorithm? Should we emulate + * --topological for older libvirt that lacked the flag? */ if (start_index < 0) { vshError(ctl, _("snapshot %s disappeared from list"), fromname= ); goto cleanup; @@ -1351,8 +1353,9 @@ virshSnapshotListCollect(vshControl *ctl, virDomainPt= r dom, } } } - qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps), - virshSnapSorter); + if (!(orig_flags & VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL)) + qsort(snaplist->snaps, snaplist->nsnaps, sizeof(*snaplist->snaps), + virshSnapSorter); snaplist->nsnaps -=3D deleted; VIR_STEAL_PTR(ret, snaplist); @@ -1451,6 +1454,10 @@ static const vshCmdOptDef opts_snapshot_list[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("list snapshot names only") }, + {.name =3D "topological", + .type =3D VSH_OT_BOOL, + .help =3D N_("sort list topologically rather than by name"), + }, {.name =3D NULL} }; @@ -1512,6 +1519,9 @@ cmdSnapshotList(vshControl *ctl, const vshCmd *cmd) FILTER("external", EXTERNAL); #undef FILTER + if (vshCommandOptBool(cmd, "topological")) + flags |=3D VIR_DOMAIN_SNAPSHOT_LIST_TOPOLOGICAL; + if (roots) flags |=3D VIR_DOMAIN_SNAPSHOT_LIST_ROOTS; diff --git a/tools/virsh.pod b/tools/virsh.pod index 5759a396d4..66e2bf24ec 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -4726,7 +4726,7 @@ Output basic information about a named , or= the current snapshot with I<--current>. =3Ditem B I [I<--metadata>] [I<--no-metadata>] -[{I<--parent> | I<--roots> | [{I<--tree> | I<--name>}]}] +[{I<--parent> | I<--roots> | [{I<--tree> | I<--name>}]}] [I<--topological>] [{[I<--from>] B | I<--current>} [I<--descendants>]] [I<--leaves>] [I<--no-leaves>] [I<--inactive>] [I<--active>] [I<--disk-only>] [I<--internal>] [I<--external>] @@ -4734,6 +4734,11 @@ with I<--current>. List all of the available snapshots for the given domain, defaulting to show columns for the snapshot name, creation time, and domain state. +Normally, table form output is sorted by snapshot name; using +I<--topological> instead sorts so that no child is listed before its +ancestors (although there may be more than one possible ordering with +this property). + If I<--parent> is specified, add a column to the output table giving the name of the parent of each snapshot. If I<--roots> is specified, the list will be filtered to just snapshots that have no parents. --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list