From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947796; cv=none; d=zoho.com; s=zohoarc; b=HrSzyFPuCHI3O5AwwlRVgyFuy5jrtwd1TXGyifCcfkYhPm/sQkTv7LfMmaBI/HB8gTpPifucUQ6JhcmomJLOjek0SwNi3dXC4umBp1rIGQBRXdsv4F+UZCIIqdOOXyiBtmOmm1LfihF3t+yctvZf5j/RCKVcI1p9tWVjOMmsTvE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947796; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=m29X5b+VS2Rs8FsJHnE5f2UZIdzjctwdDJGDUEwKaGI=; b=G+Xl38CL5kUmb1ov3OZ+bQFGKVmrH7LrMM5VW5y8zRkqGsisUGsUsjKQyNnl9T1B9Ta24NwLeYikXFB3XwVL+2xg9CLyIEUiZ4T5cOj1N2Bhfr4uRvjIKMtyQUVz+ihyQsONDgkV7K9TaDRkCJAldG+mb8E+L1ZEhK6WnG6rAQQ= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947796384860.3027899499485; Tue, 23 Jul 2019 22:56:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D821A81DF2; Wed, 24 Jul 2019 05:56:34 +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 B5B7717C41; Wed, 24 Jul 2019 05:56:34 +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 7D9B53CB9; Wed, 24 Jul 2019 05:56:34 +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 x6O5uDKj029087 for ; Wed, 24 Jul 2019 01:56:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4A47760C05; Wed, 24 Jul 2019 05:56:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id CE8D660BEC; Wed, 24 Jul 2019 05:56:12 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:51 -0500 Message-Id: <20190724055609.30691-2-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 01/19] snapshot: Don't leak moment obj list metaroot to callers 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 24 Jul 2019 05:56:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" virDomainSnapshotFindByName(list, NULL) should return NULL, rather than the internal-use-only metaroot. Most existing callers pass in a non-NULL name; the few that don't are immediately calling virDomainMomentSetParent (which indeed needs the metaroot if the parent name is NULL); but as the leak is ugly, it is worth instead making virDomainMomentSetParent static and adding a new function for resolving the link of a brand new moment within its list (and where we are either requesting NULL for a new root moment, or requesting the name of the current moment, and therefore the new function does not need to return failure, but merely warn if future code breaks our assumptions). Missed when commit 02c4e24d refactored things to attempt to remove direct metaroot manipulations out of the qemu and test drivers into internal-only details, and made more obvious when commit dc8d3dc6 factored it out into a separate file. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/virdomainmomentobjlist.h | 4 ++-- src/conf/virdomainsnapshotobjlist.h | 2 ++ src/conf/virdomainmomentobjlist.c | 34 +++++++++++++++++++++++++---- src/conf/virdomainsnapshotobjlist.c | 9 ++++++++ src/libvirt_private.syms | 2 +- src/qemu/qemu_driver.c | 5 +---- src/test/test_driver.c | 5 +---- 7 files changed, 46 insertions(+), 15 deletions(-) diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentob= jlist.h index 4067e928f4..897d8d54d1 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -60,8 +60,8 @@ void virDomainMomentDropParent(virDomainMomentObjPtr mome= nt); void virDomainMomentDropChildren(virDomainMomentObjPtr moment); void virDomainMomentMoveChildren(virDomainMomentObjPtr from, virDomainMomentObjPtr to); -void virDomainMomentSetParent(virDomainMomentObjPtr moment, - virDomainMomentObjPtr parent); +void virDomainMomentLinkParent(virDomainMomentObjListPtr moments, + virDomainMomentObjPtr moment); virDomainMomentObjListPtr virDomainMomentObjListNew(void); void virDomainMomentObjListFree(virDomainMomentObjListPtr moments); diff --git a/src/conf/virdomainsnapshotobjlist.h b/src/conf/virdomainsnapsh= otobjlist.h index fed8d22bc8..b8c80b39ed 100644 --- a/src/conf/virdomainsnapshotobjlist.h +++ b/src/conf/virdomainsnapshotobjlist.h @@ -51,6 +51,8 @@ void virDomainSnapshotObjListRemoveAll(virDomainSnapshotO= bjListPtr snapshots); int virDomainSnapshotForEach(virDomainSnapshotObjListPtr snapshots, virHashIterator iter, void *data); +void virDomainSnapshotLinkParent(virDomainSnapshotObjListPtr snapshots, + virDomainMomentObjPtr moment); int virDomainSnapshotUpdateRelations(virDomainSnapshotObjListPtr snapshots= ); int virDomainSnapshotCheckCycles(virDomainSnapshotObjListPtr snapshots, virDomainSnapshotDefPtr def, diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentob= jlist.c index 7cb1745525..5c147bdbbf 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -151,7 +151,7 @@ virDomainMomentDropChildren(virDomainMomentObjPtr momen= t) /* Add @moment to @parent's list of children. */ -void +static void virDomainMomentSetParent(virDomainMomentObjPtr moment, virDomainMomentObjPtr parent) { @@ -162,6 +162,27 @@ virDomainMomentSetParent(virDomainMomentObjPtr moment, } +/* Add @moment to the appropriate parent's list of children. The + * caller must ensure that moment->def->parent_name is either NULL + * (for a new root) or set to an existing moment already in the + * list. */ +void +virDomainMomentLinkParent(virDomainMomentObjListPtr moments, + virDomainMomentObjPtr moment) +{ + virDomainMomentObjPtr parent; + + parent =3D virDomainMomentFindByName(moments, moment->def->parent_name= ); + if (!parent) { + parent =3D &moments->metaroot; + if (moment->def->parent_name) + VIR_WARN("moment %s lacks parent %s", moment->def->name, + moment->def->parent_name); + } + virDomainMomentSetParent(moment, parent); +} + + /* Take all children of @from and convert them into children of @to. */ void virDomainMomentMoveChildren(virDomainMomentObjPtr from, @@ -390,7 +411,9 @@ virDomainMomentObjPtr virDomainMomentFindByName(virDomainMomentObjListPtr moments, const char *name) { - return name ? virHashLookup(moments->objs, name) : &moments->metaroot; + if (name) + return virHashLookup(moments->objs, name); + return NULL; } @@ -484,9 +507,12 @@ virDomainMomentSetRelations(void *payload, parent =3D virDomainMomentFindByName(curr->moments, obj->def->parent_n= ame); if (!parent) { - curr->err =3D -1; parent =3D &curr->moments->metaroot; - VIR_WARN("moment %s lacks parent", obj->def->name); + if (obj->def->parent_name) { + curr->err =3D -1; + VIR_WARN("moment %s lacks parent %s", obj->def->name, + obj->def->parent_name); + } } else { tmp =3D parent; while (tmp && tmp->def) { diff --git a/src/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapsh= otobjlist.c index 99bc4bb0c5..95622f0ba7 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -223,6 +223,15 @@ virDomainSnapshotForEach(virDomainSnapshotObjListPtr s= napshots, } +/* Populate parent link of a given snapshot. */ +void +virDomainSnapshotLinkParent(virDomainSnapshotObjListPtr snapshots, + virDomainMomentObjPtr snap) +{ + return virDomainMomentLinkParent(snapshots->base, snap); +} + + /* Populate parent link and child count of all snapshots, with all * assigned defs having relations starting as 0/NULL. Return 0 on * success, -1 if a parent is missing or if a circular relationship diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index dff97bd82a..ff5a77b0e2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -978,7 +978,6 @@ virDomainMomentDropParent; virDomainMomentForEachChild; virDomainMomentForEachDescendant; virDomainMomentMoveChildren; -virDomainMomentSetParent; # conf/virdomainobjlist.h @@ -1007,6 +1006,7 @@ virDomainSnapshotFindByName; virDomainSnapshotForEach; virDomainSnapshotGetCurrent; virDomainSnapshotGetCurrentName; +virDomainSnapshotLinkParent; virDomainSnapshotObjListFree; virDomainSnapshotObjListGetNames; virDomainSnapshotObjListNew; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 482f915b67..065e0a1bd8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15540,7 +15540,6 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, bool update_current =3D true; bool redefine =3D flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; unsigned int parse_flags =3D VIR_DOMAIN_SNAPSHOT_PARSE_DISKS; - virDomainMomentObjPtr other =3D NULL; int align_location =3D VIR_DOMAIN_SNAPSHOT_LOCATION_INTERNAL; bool align_match =3D true; virQEMUDriverConfigPtr cfg =3D NULL; @@ -15807,9 +15806,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, snap->def->name); virDomainSnapshotObjListRemove(vm->snapshots, snap); } else { - other =3D virDomainSnapshotFindByName(vm->snapshots, - snap->def->parent_name); - virDomainMomentSetParent(snap, other); + virDomainSnapshotLinkParent(vm->snapshots, snap); } } else if (snap) { virDomainSnapshotObjListRemove(vm->snapshots, snap); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2e33a9dd55..d96dd638e7 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7361,12 +7361,9 @@ testDomainSnapshotCreateXML(virDomainPtr domain, cleanup: if (vm) { if (snapshot) { - virDomainMomentObjPtr other; if (update_current) virDomainSnapshotSetCurrent(vm->snapshots, snap); - other =3D virDomainSnapshotFindByName(vm->snapshots, - snap->def->parent_name); - virDomainMomentSetParent(snap, other); + virDomainSnapshotLinkParent(vm->snapshots, snap); } virDomainObjEndAPI(&vm); } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947780; cv=none; d=zoho.com; s=zohoarc; b=cNMMz7w2Onj2cg6rxvuY93zdW7MX1I1hiFWVHeJZXmt7KO87rV8l5+KbGcyuG9LULpODXKoj6E8yrSt9WJGIgW+SU7Zw2rSNuR0EXwq+F1f07t0+qmHxf/z4UkyDE6jZan3LYAknku/wu5Pkjy+z4O4TmKRirnUSDt0BASqyJlc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947780; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=n6ouKwcdRm0fVrb/KZYoc4wrdOuAsSge5ZH3cEXS4sA=; b=Gj/8VKJxtYhGILKYGYHuIZk/rKUcepUGsGXR37MZQUw2CRKhAy+m4i0pk5TU7TrjlKBbsB0OxDKXfN1Msph1ZIdslP5b7Cba78B3HToKTxJ9X5cCHxSGIKC7PxU4LpcM5d8FGkxMKT1/Crc4Lc1gNoaq7mah9KoN9ho9w8y4QjE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947780240374.78717334469457; Tue, 23 Jul 2019 22:56:20 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BFC6E81F1B; Wed, 24 Jul 2019 05:56:18 +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 8F6E76012D; Wed, 24 Jul 2019 05:56:18 +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 E7C621800208; Wed, 24 Jul 2019 05:56:16 +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 x6O5uDM5029093 for ; Wed, 24 Jul 2019 01:56:13 -0400 Received: by smtp.corp.redhat.com (Postfix) id DD47D60BF7; Wed, 24 Jul 2019 05:56:13 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6D37760BEC; Wed, 24 Jul 2019 05:56:13 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:52 -0500 Message-Id: <20190724055609.30691-3-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 02/19] snapshot: Saner error message for duplicate create 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 24 Jul 2019 05:56:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Any message that is easy to trigger (as evidenced by the testsuite update) should not use 'internal error' as its category. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/virdomainmomentobjlist.c | 4 ++-- tests/virsh-snapshot | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentob= jlist.c index 5c147bdbbf..c8dd8f8e01 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -242,8 +242,8 @@ virDomainMomentAssignDef(virDomainMomentObjListPtr mome= nts, virDomainMomentObjPtr moment; if (virHashLookup(moments->objs, def->name) !=3D NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected domain moment %s already exists"), + virReportError(VIR_ERR_OPERATION_FAILED, + _("domain moment %s already exists"), def->name); return NULL; } diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot index 510904f470..c31da52ef9 100755 --- a/tests/virsh-snapshot +++ b/tests/virsh-snapshot @@ -34,6 +34,7 @@ $abs_top_builddir/tools/virsh --connect test:///default >= out 2>err ' # Create a series of snapshots, with names that intentionally sort # differently by topology than by name. Use revert to create fanout. snapshot-create-as test s1 + snapshot-create-as test s1 snapshot-create-as test s3 snapshot-create-as test s2 snapshot-revert test s3 @@ -90,6 +91,7 @@ sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=3D1 cat <<\EOF > exp || fail=3D1 Domain snapshot s1 created + Domain snapshot s3 created Domain snapshot s2 created @@ -171,6 +173,7 @@ EOF compare exp out.cooked || fail=3D1 cat < exp || fail=3D1 +error: operation failed: domain moment s1 already exists error: marker error: domain 'test' has no current snapshot error: marker --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947780; cv=none; d=zoho.com; s=zohoarc; b=eaZjkTCinvXPIWp2Tge3iBEVvoAJAGx5/4Uoi9zs0g/PHdYXPkU8mU6ibBbPI8riBpg4z4czpWvOlnj5rJAazEVI0mQzho0N6OdM/Yc5poUgme19T2dGteQKda7+eWX4CmPeTbzZ7heC88uz5OXknbFIWdlU5Ok9Wwi88sAfdQ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947780; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=Kxzlu7seqb+uyCC73CIg4nDAWGWF+EGFGjbR2FCyOOs=; b=HOAMrwrg+dhBlgEWRW6E7MpC0phuUokfIgeDxWvq3IkLYwgypzukzZxGWmOKuywuoND7YnKKju1Fyn56zLBRqPTlH5k9AvvDzJKV0N0N2GJF0Zs4QzTr87H/Bq/u/EFu21PP5JJvUyTyRlJFg0beH0qCpaxEKmM1RwVgsdrfhPw= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947780248927.92067380769; Tue, 23 Jul 2019 22:56:20 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B27842F8BDB; Wed, 24 Jul 2019 05:56:18 +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 87F6A60603; Wed, 24 Jul 2019 05:56:18 +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 E04E71800207; Wed, 24 Jul 2019 05:56:16 +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 x6O5uE7A029101 for ; Wed, 24 Jul 2019 01:56:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9377960C05; Wed, 24 Jul 2019 05:56:14 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 165B760BEC; Wed, 24 Jul 2019 05:56:13 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:53 -0500 Message-Id: <20190724055609.30691-4-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 03/19] snapshot: Documentation and comment improvements 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Wed, 24 Jul 2019 05:56:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Changes noticed while copying to similar aspects of checkpoints. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/formatsnapshot.html.in | 8 +++----- tests/virsh-snapshot | 2 +- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/docs/formatsnapshot.html.in b/docs/formatsnapshot.html.in index 92cc566467..005800bc00 100644 --- a/docs/formatsnapshot.html.in +++ b/docs/formatsnapshot.html.in @@ -223,11 +223,9 @@ guest.
parent
-
An optional readonly representation of the parent of this - snapshot. If present, this element contains exactly one child - element, name. This specifies the name of the - parent snapshot of this snapshot, and is used to represent - trees of snapshots. +
Readonly, present only if this snapshot has a parent. The + parent name is given by the sub-element name. The + parent relationship allows tracking a tree of related snapshots.
domain
A readonly representation of the domain that this snapshot diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot index c31da52ef9..b23d949f62 100755 --- a/tests/virsh-snapshot +++ b/tests/virsh-snapshot @@ -85,7 +85,7 @@ $abs_top_builddir/tools/virsh --connect test:///default >= out 2>err ' # and snapshot-list produces timestamps sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/; /MarkerA/,/MarkerC/d' < out > out.cooked || fail=3D1 -# Second part holds domain XMLs +# Second part holds domain snapshot XMLs sed -n '/MarkerA/,/MarkerB/p' < out > s3.xml || fail=3D1 sed -n '/MarkerB/,/MarkerC/p' < out > s2.xml || fail=3D1 --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947796; cv=none; d=zoho.com; s=zohoarc; b=mtVpNz5zepZ3pz4A3PuuGjtud7m5U9RREj5YLQbHPymk/5yaJ4g+dqmwbOC5BqwxlGd9NxaKB3GcCuyf8+E7QVF0uwyty9vj1PQadaYCAn7komtc2jlGOx6uDyIk2eMG9lAVzgSAosQ6pwTOhJWC3uxgq1dB7sbqxtIEBqQw4Ko= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947796; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=3krD/q/yKf4dvK0CDVQ47OPlapWeojobpxTKLQ9QPsk=; b=HVph+MfKhtfhStdV41CZaCe6hWdjWFVwA8QrapnPGg+jIpNnFdDDrpSQHhe+sm/gakudty2bS81KNrzyDXALoFfDjLGCq/tcrASITV9U158ncYMYNIH4DlhnP46GcYiZDU5C4lg7e7F9xayyn8DZIkYVr/P21x2ce/jx6EDmK1Q= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947796765738.1120865232573; Tue, 23 Jul 2019 22:56:36 -0700 (PDT) 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 406E288309; Wed, 24 Jul 2019 05:56:35 +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 B86C21001B0F; Wed, 24 Jul 2019 05:56:34 +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 7DE7C180020B; Wed, 24 Jul 2019 05:56:34 +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 x6O5uF3o029111 for ; Wed, 24 Jul 2019 01:56:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id 31DC460BF7; Wed, 24 Jul 2019 05:56:15 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id B65E660BEC; Wed, 24 Jul 2019 05:56:14 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:54 -0500 Message-Id: <20190724055609.30691-5-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 04/19] backup: qemu: Detect node names at domain startup 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.28]); Wed, 24 Jul 2019 05:56:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" If we are using -blockdev, then node names are always available (because we set them). But when not using it, we were scraping node names after reconnecting a new libvirtd to an existing guest (see qemuProcessReconnect), and after any block job that may have changed the set of node names we care about, but forgot to scrape the names when first starting a guest. Do so now in order to allow the checkpoint code to always have access to a node name without having to repeat a node name scrape itself. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- Grepping for use of qemuBlockNodeNamesDetect, I see that qemuDomainSetBlockThreshold is still scraping names, and that hotplug and cdrom disk changes do not appear to scrape names. Either of these situations could interfere with checkpoints; perhaps they should also be addressed here... --- src/qemu/qemu_process.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 75205bc121..53b8ff36f6 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -7060,6 +7060,8 @@ qemuProcessRefreshState(virQEMUDriverPtr driver, virDomainObjPtr vm, qemuDomainAsyncJob asyncJob) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; + VIR_DEBUG("Fetching list of active devices"); if (qemuDomainUpdateDeviceList(driver, vm, asyncJob) < 0) return -1; @@ -7075,6 +7077,9 @@ qemuProcessRefreshState(virQEMUDriverPtr driver, VIR_DEBUG("Updating disk data"); if (qemuProcessRefreshDisks(driver, vm, asyncJob) < 0) return -1; + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BLOCKDEV) && + qemuBlockNodeNamesDetect(driver, vm, asyncJob) < 0) + return -1; return 0; } --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947799; cv=none; d=zoho.com; s=zohoarc; b=E7IiU9tlH9YN2+S/by9CPusIadQg+6uMdjmxdEsaG4QI28Nt2qlhjFBmWZspxXRdgdzn6TZbYUTlcyRPecoRE0q344F7tIb22ByDSt3ZuAcV/jF0ZV/AsjlRrXpWF3TVWdXcTA71h4UMU1Q/MnWXD3BzThLn9YHMtW58YpJxwyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947799; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=rkSTxLaP+C4nl4KQrOb5YlZFbQfmxUYWA1OiiCMBvA4=; b=np3iEVmUaxaK+kRNZOKvz5Ev1MkgWgWs+rURsfQ3KBHZkdQJtBcsPqvTguSUIejw2nZT2uuSLKX1bfBHa0Mw/LuqilvZ/PiYaswdBAkRZCp5lINKRxzDQkvRaRS5WkBpS7XyjpV8W2Ba36QQ9mDMRG7KE/Qd+e6NZNSQiDsASfQ= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947799498434.55554155474067; Tue, 23 Jul 2019 22:56:39 -0700 (PDT) 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 489AE30C75AB; Wed, 24 Jul 2019 05:56:38 +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 1C2AF1024816; Wed, 24 Jul 2019 05:56:38 +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 D33D8180020A; Wed, 24 Jul 2019 05:56:37 +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 x6O5uFTP029118 for ; Wed, 24 Jul 2019 01:56:15 -0400 Received: by smtp.corp.redhat.com (Postfix) id D831460BF7; Wed, 24 Jul 2019 05:56:15 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 54ECF60BEC; Wed, 24 Jul 2019 05:56:15 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:55 -0500 Message-Id: <20190724055609.30691-6-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 05/19] backup: Document new XML for checkpoints 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.46]); Wed, 24 Jul 2019 05:56:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Prepare for new checkpoint APIs by describing the XML that will represent a checkpoint. The checkpoint XML is modeled heavily after virDomainSnapshotPtr. See the docs for more details. Add testsuite coverage for some minimal uses of the XML (bare minimum, the sample from html, and a full dumpxml, and some counter-examples that should fail schema validation). Although use of the REDEFINE flag will require the subelement to be present, it is easier for most of the tests to provide counterpart output produced with the NO_DOMAIN flag (particularly since synthesizing a valid during testing is not trivial). Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/docs.html.in | 3 +- docs/format.html.in | 1 + docs/formatcheckpoint.html.in | 194 ++++++++++++++++++ docs/index.html.in | 3 +- docs/schemas/domaincheckpoint.rng | 94 +++++++++ libvirt.spec.in | 1 + mingw-libvirt.spec.in | 2 + tests/Makefile.am | 2 + .../disk-default.xml | 7 + .../disk-invalid.xml | 8 + tests/qemudomaincheckpointxml2xmlin/empty.xml | 1 + .../name-invalid.xml | 4 + .../qemudomaincheckpointxml2xmlin/sample.xml | 7 + tests/qemudomaincheckpointxml2xmlin/size.xml | 4 + .../disk-default.xml | 11 + .../qemudomaincheckpointxml2xmlout/empty.xml | 7 + .../redefine.xml | 63 ++++++ .../qemudomaincheckpointxml2xmlout/sample.xml | 12 ++ tests/qemudomaincheckpointxml2xmlout/size.xml | 11 + tests/virschematest.c | 2 + 20 files changed, 435 insertions(+), 2 deletions(-) create mode 100644 docs/formatcheckpoint.html.in create mode 100644 docs/schemas/domaincheckpoint.rng create mode 100644 tests/qemudomaincheckpointxml2xmlin/disk-default.xml create mode 100644 tests/qemudomaincheckpointxml2xmlin/disk-invalid.xml create mode 100644 tests/qemudomaincheckpointxml2xmlin/empty.xml create mode 100644 tests/qemudomaincheckpointxml2xmlin/name-invalid.xml create mode 100644 tests/qemudomaincheckpointxml2xmlin/sample.xml create mode 100644 tests/qemudomaincheckpointxml2xmlin/size.xml create mode 100644 tests/qemudomaincheckpointxml2xmlout/disk-default.xml create mode 100644 tests/qemudomaincheckpointxml2xmlout/empty.xml create mode 100644 tests/qemudomaincheckpointxml2xmlout/redefine.xml create mode 100644 tests/qemudomaincheckpointxml2xmlout/sample.xml create mode 100644 tests/qemudomaincheckpointxml2xmlout/size.xml diff --git a/docs/docs.html.in b/docs/docs.html.in index 9e1ef6be41..74af38002e 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -81,7 +81,8 @@ storage pool capabilities, node devices, secrets, - snapshots
+ snapshots, + checkpoints
URI format
The URI formats used for connecting to libvirt
diff --git a/docs/format.html.in b/docs/format.html.in index b488f7b38f..3be2237663 100644 --- a/docs/format.html.in +++ b/docs/format.html.in @@ -26,6 +26,7 @@
  • Node devices
  • Secrets
  • Snapshots
  • +
  • Checkpoints
  • Command line validation

    diff --git a/docs/formatcheckpoint.html.in b/docs/formatcheckpoint.html.in new file mode 100644 index 0000000000..50dd4d284c --- /dev/null +++ b/docs/formatcheckpoint.html.in @@ -0,0 +1,194 @@ + + + + +

    Checkpoint XML format

    + +
      + +

      Checkpoint XML

      + +

      + One method of capturing domain disk backups is via the use of + incremental backups. Right now, incremental backups are only + supported for the QEMU hypervisor when using qcow2 disks at the + active layer; if other disk formats are in use, capturing disk + backups requires different libvirt APIs. +

      +

      + Libvirt is able to facilitate incremental backups by tracking + disk checkpoints, which are points in time against which it is + easy to compute which portion of the disk has changed. Given a + full backup (a backup created from the creation of the disk to a + given point in time), coupled with the creation of a disk + checkpoint at that time, and an incremental backup (a backup + created from just the dirty portion of the disk between the + first checkpoint and the second backup operation), it is + possible to do an offline reconstruction of the state of the + disk at the time of the second backup without having to copy as + much data as a second full backup would require. Future API + additions will make it possible to create checkpoints in + conjunction with a backup + via virDomainBackupBegin() or with an external + snapshot via virDomainSnapshotCreateXML2; but for + now, libvirt exposes enough support to create disk checkpoints + independently from a backup operation + via virDomainCheckpointCreateXML() since + 5.6.0. +

      +

      + Attributes of libvirt checkpoints are stored as child elements + of the domaincheckpoint element. At checkpoint + creation time, normally only + the name, description, + and disks elements are settable. The rest of the + fields are ignored on creation and will be filled in by libvirt + in for informational purposes + by virDomainCheckpointGetXMLDesc(). However, when + redefining a checkpoint, with + the VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE flag + of virDomainCheckpointCreateXML(), all of the XML + fields described here are relevant on input, even the fields + that are normally described as readonly for output. +

      +

      + The top-level domaincheckpoint element may contain + the following elements: +

      +
      +
      name
      +
      The optional name for this checkpoint. If the name is + omitted, libvirt will create a name based on the time of the + creation. +
      +
      description
      +
      An optional human-readable description of the checkpoint. + If the description is omitted when initially creating the + checkpoint, then this field will be empty. +
      +
      disks
      +
      On input, this is an optional listing of specific + instructions for disk checkpoints; it is needed when making a + checkpoint on only a subset of the disks associated with a + domain. In particular, since QEMU checkpoints require qcow2 + disks, this element may be needed on input for excluding guest + disks that are not in qcow2 format. If the entire element was + omitted on input, then all disks participate in the + checkpoint, otherwise, only the disks explicitly listed which + do not also use checkpoint=3D'no' will + participate. On output, this is the checkpoint state of each + of the domain's disks. +
      +
      disk
      +
      This sub-element describes the checkpoint properties of + a specific disk with the following attributes: +
      +
      name
      +
      A mandatory attribute which must match either + the <target dev=3D'name'/> or an + unambiguous <source file=3D'name'/> + of one of + the disk + devices specified for the domain at the time of + the checkpoint.
      +
      checkpoint
      +
      An optional attribute; possible values + are no when the disk does not participate + in this checkpoint; or bitmap if the disk + will track all changes since the creation of this + checkpoint via a bitmap.
      +
      bitmap
      +
      The attribute bitmap is only valid + if checkpoint=3D'bitmap'; it describes the + name of the tracking bitmap (defaulting to the + checkpoint name).
      +
      size
      +
      The attribute size is ignored on input; + on output, it is only present if + the VIR_DOMAIN_CHECKPOINT_XML_SIZE flag + was used to perform a dynamic query of the estimated + size in bytes of the changes made since the checkpoint + was created.
      +
      +
      +
      +
      +
      creationTime
      +
      A readonly representation of the time this checkpoint was + created. The time is specified in seconds since the Epoch, + UTC (i.e. Unix time). +
      +
      parent
      +
      Readonly, present if this checkpoint has a parent. The + parent name is given by the sub-element name. The + parent relationship allows tracking a list of related checkpoints. +
      +
      domain
      +
      A readonly representation of the + inactive domain configuration + at the time the checkpoint was created. This element may be + omitted for output brevity by supplying + the VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN flag, but + the resulting XML is no longer viable for use with + the VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE flag + of virDomainCheckpointCreateXML(). The domain + will have security-sensitive information omitted unless the + flag VIR_DOMAIN_CHECKPOINT_XML_SECURE is provided + on a read-write connection. +
      +
      + +

      Examples

      + +

      Using this XML to create a checkpoint of just vda on a qemu + domain with two disks and a prior checkpoint:

      +
      +<domaincheckpoint>
      +  <description>Completion of updates after OS install</descriptio=
      n>
      +  <disks>
      +    <disk name=3D'vda' checkpoint=3D'bitmap'/>
      +    <disk name=3D'vdb' checkpoint=3D'no'/>
      +  </disks>
      +</domaincheckpoint>
      + +

      will result in XML similar to this from + virDomainCheckpointGetXMLDesc():

      +
      +<domaincheckpoint>
      +  <name>1525889631</name>
      +  <description>Completion of updates after OS install</descriptio=
      n>
      +  <parent>
      +    <name>1525111885</name>
      +  </parent>
      +  <creationTime>1525889631</creationTime>
      +  <disks>
      +    <disk name=3D'vda' checkpoint=3D'bitmap' bitmap=3D'1525889631'/>
      +    <disk name=3D'vdb' checkpoint=3D'no'/>
      +  </disks>
      +  <domain type=3D'qemu'>
      +    <name>fedora</name>
      +    <uuid>93a5c045-6457-2c09-e56c-927cdf34e178</uuid>
      +    <memory>1048576</memory>
      +    ...
      +    <devices>
      +      <disk type=3D'file' device=3D'disk'>
      +        <driver name=3D'qemu' type=3D'qcow2'/>
      +        <source file=3D'/path/to/file1'/>
      +        <target dev=3D'vda' bus=3D'virtio'/>
      +      </disk>
      +      <disk type=3D'file' device=3D'disk' snapshot=3D'external'>
      +        <driver name=3D'qemu' type=3D'raw'/>
      +        <source file=3D'/path/to/file2'/>
      +        <target dev=3D'vdb' bus=3D'virtio'/>
      +      </disk>
      +      ...
      +    </devices>
      +  </domain>
      +</domaincheckpoint>
      + +

      With that checkpoint created, the qcow2 image is now tracking + all changes that occur in the image since the checkpoint via + the persistent bitmap named 1525889631. +

      + + diff --git a/docs/index.html.in b/docs/index.html.in index 2bd647f8dd..7d0ab650e3 100644 --- a/docs/index.html.in +++ b/docs/index.html.in @@ -58,7 +58,8 @@ storage pool capabilities, node devices, secrets, - snapshots + snapshots, + checkpoints
      Wiki
      Read further community contributed content
      diff --git a/docs/schemas/domaincheckpoint.rng b/docs/schemas/domaincheckpo= int.rng new file mode 100644 index 0000000000..4399eca7fc --- /dev/null +++ b/docs/schemas/domaincheckpoint.rng @@ -0,0 +1,94 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + no + + + + + bitmap + + + + + + + + + + + + + + + + + + + + + [a-zA-Z0-9_\-][a-zA-Z0-9_\-.]* + + + + diff --git a/libvirt.spec.in b/libvirt.spec.in index b13b863928..4dee2d8ac2 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1802,6 +1802,7 @@ exit 0 %{_datadir}/libvirt/schemas/cputypes.rng %{_datadir}/libvirt/schemas/domain.rng %{_datadir}/libvirt/schemas/domaincaps.rng +%{_datadir}/libvirt/schemas/domaincheckpoint.rng %{_datadir}/libvirt/schemas/domaincommon.rng %{_datadir}/libvirt/schemas/domainsnapshot.rng %{_datadir}/libvirt/schemas/interface.rng diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index ad6d6e952e..df89d9f8b3 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -232,6 +232,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw32_datadir}/libvirt/schemas/cputypes.rng %{mingw32_datadir}/libvirt/schemas/domain.rng %{mingw32_datadir}/libvirt/schemas/domaincaps.rng +%{mingw32_datadir}/libvirt/schemas/domaincheckpoint.rng %{mingw32_datadir}/libvirt/schemas/domaincommon.rng %{mingw32_datadir}/libvirt/schemas/domainsnapshot.rng %{mingw32_datadir}/libvirt/schemas/interface.rng @@ -321,6 +322,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw64_datadir}/libvirt/schemas/cputypes.rng %{mingw64_datadir}/libvirt/schemas/domain.rng %{mingw64_datadir}/libvirt/schemas/domaincaps.rng +%{mingw64_datadir}/libvirt/schemas/domaincheckpoint.rng %{mingw64_datadir}/libvirt/schemas/domaincommon.rng %{mingw64_datadir}/libvirt/schemas/domainsnapshot.rng %{mingw64_datadir}/libvirt/schemas/interface.rng diff --git a/tests/Makefile.am b/tests/Makefile.am index f480e68e7d..9e2e57459e 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -110,6 +110,8 @@ EXTRA_DIST =3D \ qemublocktestdata \ qemucapabilitiesdata \ qemucaps2xmloutdata \ + qemudomaincheckpointxml2xmlin \ + qemudomaincheckpointxml2xmlout \ qemudomainsnapshotxml2xmlin \ qemudomainsnapshotxml2xmlout \ qemuhotplugtestcpus \ diff --git a/tests/qemudomaincheckpointxml2xmlin/disk-default.xml b/tests/q= emudomaincheckpointxml2xmlin/disk-default.xml new file mode 100644 index 0000000000..706a9a8fd5 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlin/disk-default.xml @@ -0,0 +1,7 @@ + + Completion of updates after OS install + + + + + diff --git a/tests/qemudomaincheckpointxml2xmlin/disk-invalid.xml b/tests/q= emudomaincheckpointxml2xmlin/disk-invalid.xml new file mode 100644 index 0000000000..c57c8f6490 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlin/disk-invalid.xml @@ -0,0 +1,8 @@ + + bogus + + + + + diff --git a/tests/qemudomaincheckpointxml2xmlin/empty.xml b/tests/qemudoma= incheckpointxml2xmlin/empty.xml new file mode 100644 index 0000000000..dc36449142 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlin/empty.xml @@ -0,0 +1 @@ + diff --git a/tests/qemudomaincheckpointxml2xmlin/name-invalid.xml b/tests/q= emudomaincheckpointxml2xmlin/name-invalid.xml new file mode 100644 index 0000000000..b13d7b09e9 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlin/name-invalid.xml @@ -0,0 +1,4 @@ + + + ../escape + diff --git a/tests/qemudomaincheckpointxml2xmlin/sample.xml b/tests/qemudom= aincheckpointxml2xmlin/sample.xml new file mode 100644 index 0000000000..70ed964e1e --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlin/sample.xml @@ -0,0 +1,7 @@ + + Completion of updates after OS install + + + + + diff --git a/tests/qemudomaincheckpointxml2xmlin/size.xml b/tests/qemudomai= ncheckpointxml2xmlin/size.xml new file mode 100644 index 0000000000..99ce84c7a0 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlin/size.xml @@ -0,0 +1,4 @@ + + c2 + something fun + diff --git a/tests/qemudomaincheckpointxml2xmlout/disk-default.xml b/tests/= qemudomaincheckpointxml2xmlout/disk-default.xml new file mode 100644 index 0000000000..ea18252c17 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/disk-default.xml @@ -0,0 +1,11 @@ + + 1525889631 + Completion of updates after OS install + + 1525111885 + + 1525889631 + + + + diff --git a/tests/qemudomaincheckpointxml2xmlout/empty.xml b/tests/qemudom= aincheckpointxml2xmlout/empty.xml new file mode 100644 index 0000000000..6fe6124ce4 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/empty.xml @@ -0,0 +1,7 @@ + + 1525889631 + 1525889631 + + + + diff --git a/tests/qemudomaincheckpointxml2xmlout/redefine.xml b/tests/qemu= domaincheckpointxml2xmlout/redefine.xml new file mode 100644 index 0000000000..823ae1ee2d --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/redefine.xml @@ -0,0 +1,63 @@ + + c1 + 1553647812 + + + + + + + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
      + + + + + + +
      + + + + + +
      + + + + + +
      + + +
      + + +
      + + + + + + + + diff --git a/tests/qemudomaincheckpointxml2xmlout/sample.xml b/tests/qemudo= maincheckpointxml2xmlout/sample.xml new file mode 100644 index 0000000000..91cfac27df --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/sample.xml @@ -0,0 +1,12 @@ + + 1525889631 + Completion of updates after OS install + + 1525111885 + + 1525889631 + + + + + diff --git a/tests/qemudomaincheckpointxml2xmlout/size.xml b/tests/qemudoma= incheckpointxml2xmlout/size.xml new file mode 100644 index 0000000000..4f11cfa680 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/size.xml @@ -0,0 +1,11 @@ + + c2 + something fun + + 1525111885 + + 1553648510 + + + + diff --git a/tests/virschematest.c b/tests/virschematest.c index 56ee6ec77e..d5a56d3f96 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -222,6 +222,8 @@ mymain(void) "genericxml2xmloutdata", "xlconfigdata", "libxlxml2domconf= igdata", "qemuhotplugtestdomains"); DO_TEST_DIR("domaincaps.rng", "domaincapsschemadata"); + DO_TEST_DIR("domaincheckpoint.rng", "qemudomaincheckpointxml2xmlin", + "qemudomaincheckpointxml2xmlout"); DO_TEST_DIR("domainsnapshot.rng", "qemudomainsnapshotxml2xmlin", "qemudomainsnapshotxml2xmlout"); DO_TEST_DIR("interface.rng", "interfaceschemadata"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947800; cv=none; d=zoho.com; s=zohoarc; b=iCTKWOUfPKDzRkmFA0lgW75F0jhY1MH8XUEmqbKLeqAeChGPajN9Hvwct4pF2l8wnvb1ifqKtGISjqkZsxlBBcKCkIf5zokBwUYT3ggKGEpZGskJFo8CqE0xwjBK9zVE76KJky5omv+9889fA/qkCfTit+iXr/4fnsMYyp5V6LA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947800; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=7CszaXkOo3T75yQCohocs+grcR41qRkeMUfApta/tyc=; b=aI/8NLNK0eQcHs/fapV7P8jhXc1OqcDA2EZ8kJWqmI2qnlQZ9zU8mGaIEtqKbYuCFeVb3o9mATa3OKf2ohWb8J2ehgTN8MQV3JauQwBf3JeDOL/F+NgKX+PtYMxeg9XuiiBGOm0dum28Bx1gWKSv14Mtq85+5+qHjJqwV2Zndxo= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15639478000091000.2265416448241; Tue, 23 Jul 2019 22:56:40 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 50B2736899; Wed, 24 Jul 2019 05:56:38 +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 240D739C6; Wed, 24 Jul 2019 05:56:38 +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 DA1423CBD; Wed, 24 Jul 2019 05:56:37 +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 x6O5uIqO029135 for ; Wed, 24 Jul 2019 01:56:18 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7AFA260BFC; Wed, 24 Jul 2019 05:56:18 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC03960BF3; Wed, 24 Jul 2019 05:56:15 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:56 -0500 Message-Id: <20190724055609.30691-7-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 06/19] backup: Introduce virDomainCheckpoint APIs 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Jul 2019 05:56:38 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a bunch of new public APIs related to backup checkpoints. Checkpoints are modeled heavily after virDomainSnapshotPtr (both represent a point in time of the guest), although a snapshot exists with the intent of rolling back to that state, while a checkpoint exists to make it possible to create an incremental backup at a later time. We may have a future hypervisor that can completely manage checkpoints without libvirt metadata, but the first two planned hypervisors (qemu and test) both always use libvirt for tracking metadata relations between checkpoints, so for now, I've deferred the counterpart of virDomainSnapshotHasMetadata for a separate API addition at a later date if there is ever a need for it. Note that until we allow snapshots and checkpoints to exist simultaneously on the same domain (although the actual prevention of this will be in a separate patch for the sake of an easier revert down the road), that it is not possible to branch out to create more than one checkpoint child to a given parent, although it may become possible later when we revert to a snapshot that coincides with a checkpoint. This also means that for now, the decision of which checkpoint becomes the parent of a newly created one is the only checkpoint with no child (so while there are APIs for dealing with a current snapshot, we do not need those for checkpoints). We may end up exposing a notion of a current checkpoint later, but it's easier to add stuff when proven needed than to blindly support it now and wish we hadn't exposed it. The following map shows the API relations to snapshots, with new APIs on the right: Operate on a domain object to create/redefine a child: virDomainSnapshotCreateXML virDomainCheckpointCreateXML Operate on a child object for lifetime management: virDomainSnapshotDelete virDomainCheckpointDelete virDomainSnapshotFree virDomainCheckpointFree virDomainSnapshotRef virDomainCheckpointRef Operate on a child object to learn more about it: virDomainSnapshotGetXMLDesc virDomainCheckpointGetXMLDesc virDomainSnapshotGetConnect virDomainCheckpointGetConnect virDomainSnapshotGetDomain virDomainCheckpointGetDomain virDomainSnapshotGetName virDomainCheckpiontGetName virDomainSnapshotGetParent virDomainCheckpiontGetParent virDomainSnapshotHasMetadata (deferred for later) virDomainSnapshotIsCurrent (no counterpart, see note above) Operate on a domain object to list all children: virDomainSnapshotNum (no counterparts, these are the old virDomainSnapshotListNames racy interfaces) virDomainSnapshotListAllSnapshots virDomainListAllCheckpoints Operate on a child object to list descendents: virDomainSnapshotNumChildren (no counterparts, these are the old virDomainSnapshotListChildrenNames racy interfaces) virDomainSnapshotListAllChildren virDomainCheckpointListAllChildren Operate on a domain to locate a particular child: virDomainSnapshotLookupByName virDomainCheckpointLookupByName virDomainSnapshotCurrent (no counterpart, see note above) virDomainHasCurrentSnapshot (no counterpart, old racy interface) Operate on a snapshot to roll back to earlier state: virDomainSnapshotRevert (no counterpart, instead checkpoints are used in incremental backups via XML to virDomainBackupBegin) Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- include/libvirt/libvirt-domain-checkpoint.h | 137 +++++ include/libvirt/libvirt-domain.h | 6 + include/libvirt/libvirt.h | 5 +- src/conf/virdomainmomentobjlist.h | 5 +- src/driver-hypervisor.h | 38 ++ docs/Makefile.am | 3 + docs/apibuild.py | 2 + docs/docs.html.in | 1 + libvirt.spec.in | 1 + mingw-libvirt.spec.in | 2 + po/POTFILES | 1 + src/Makefile.am | 2 + src/libvirt-domain-checkpoint.c | 567 ++++++++++++++++++++ src/libvirt-domain.c | 19 +- src/libvirt_public.syms | 16 + 15 files changed, 796 insertions(+), 9 deletions(-) create mode 100644 include/libvirt/libvirt-domain-checkpoint.h create mode 100644 src/libvirt-domain-checkpoint.c diff --git a/include/libvirt/libvirt-domain-checkpoint.h b/include/libvirt/= libvirt-domain-checkpoint.h new file mode 100644 index 0000000000..f4bd92e81c --- /dev/null +++ b/include/libvirt/libvirt-domain-checkpoint.h @@ -0,0 +1,137 @@ +/* + * libvirt-domain-checkpoint.h + * Summary: APIs for management of domain checkpoints + * Description: Provides APIs for the management of domain checkpoints + * + * 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 + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#ifndef LIBVIRT_DOMAIN_CHECKPOINT_H +# define LIBVIRT_DOMAIN_CHECKPOINT_H + +# ifndef __VIR_LIBVIRT_H_INCLUDES__ +# error "Don't include this file directly, only use libvirt/libvirt.h" +# endif + +/** + * virDomainCheckpoint: + * + * A virDomainCheckpoint is a private structure representing a checkpoint = of + * a domain. A checkpoint is useful for tracking which portions of the + * domain disks have been altered since a point in time, but by itself does + * not allow reverting back to that point in time. + */ +typedef struct _virDomainCheckpoint virDomainCheckpoint; + +/** + * virDomainCheckpointPtr: + * + * A virDomainCheckpointPtr is pointer to a virDomainCheckpoint + * private structure, and is the type used to reference a domain + * checkpoint in the API. + */ +typedef virDomainCheckpoint *virDomainCheckpointPtr; + +const char *virDomainCheckpointGetName(virDomainCheckpointPtr checkpoint); +virDomainPtr virDomainCheckpointGetDomain(virDomainCheckpointPtr checkpoin= t); +virConnectPtr virDomainCheckpointGetConnect(virDomainCheckpointPtr checkpo= int); + +typedef enum { + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE =3D (1 << 0), /* Restore or a= lter + metadata */ + VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE =3D (1 << 1), /* use guest ag= ent to + quiesce all mo= unted + file systems w= ithin + the domain */ +} virDomainCheckpointCreateFlags; + +/* Create a checkpoint using the current VM state. */ +virDomainCheckpointPtr virDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags); + +typedef enum { + VIR_DOMAIN_CHECKPOINT_XML_SECURE =3D (1 << 0), /* Include sensitive= data */ + VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN =3D (1 << 1), /* Suppress + subelement */ + VIR_DOMAIN_CHECKPOINT_XML_SIZE =3D (1 << 2), /* Include dynamic + per- size */ +} virDomainCheckpointXMLFlags; + +/* Dump the XML of a checkpoint */ +char *virDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +/** + * virDomainCheckpointListFlags: + * + * Flags valid for virDomainListAllCheckpoints() and + * virDomainCheckpointListAllChildren(). Note that the interpretation of + * flag (1<<0) depends on which function it is passed to; but serves + * to toggle the per-call default of whether the listing is shallow or + * recursive. Remaining bits come in groups; if all bits from a group + * are 0, then that group is not used to filter results. */ +typedef enum { + VIR_DOMAIN_CHECKPOINT_LIST_ROOTS =3D (1 << 0), /* Filter by chec= kpoints + with no parents,= when + listing a domain= */ + VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS =3D (1 << 0), /* List all desce= ndants, + not just childre= n, when + listing a checkp= oint */ + VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL =3D (1 << 1), /* Ensure parents= occur + before children = in + the resulting li= st */ + + VIR_DOMAIN_CHECKPOINT_LIST_LEAVES =3D (1 << 2), /* Filter by chec= kpoints + with no children= */ + VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES =3D (1 << 3), /* Filter by chec= kpoints + that have childr= en */ +} virDomainCheckpointListFlags; + +/* Get all checkpoint objects for this domain */ +int virDomainListAllCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **checkpoints, + unsigned int flags); + +/* Get all checkpoint object children for this checkpoint */ +int virDomainCheckpointListAllChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **children, + unsigned int flags); + +/* Get a handle to a named checkpoint */ +virDomainCheckpointPtr virDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags); + +/* Get a handle to the parent checkpoint, if one exists */ +virDomainCheckpointPtr virDomainCheckpointGetParent(virDomainCheckpointPtr= checkpoint, + unsigned int flags); + +/* Delete a checkpoint */ +typedef enum { + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN =3D (1 << 0), /* Also delet= e children */ + VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY =3D (1 << 1), /* Delete jus= t metadata */ + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY =3D (1 << 2), /* Delete jus= t children */ +} virDomainCheckpointDeleteFlags; + +int virDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +int virDomainCheckpointRef(virDomainCheckpointPtr checkpoint); +int virDomainCheckpointFree(virDomainCheckpointPtr checkpoint); + +#endif /* LIBVIRT_DOMAIN_CHECKPOINT_H */ diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index 2dbd74d4f3..f160ee88b5 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1800,6 +1800,9 @@ typedef enum { VIR_DOMAIN_UNDEFINE_NVRAM =3D (1 << 2), /* Also remove any nvram file */ VIR_DOMAIN_UNDEFINE_KEEP_NVRAM =3D (1 << 3), /* Keep nvram fil= e */ + VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA =3D (1 << 4), /* If last use = of domain, + then also remo= ve any + checkpoint met= adata */ /* Future undefine control flags should come here. */ } virDomainUndefineFlagsValues; @@ -1838,6 +1841,9 @@ typedef enum { VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT =3D 1 << 12, VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT =3D 1 << 13, + + VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT =3D 1 << 14, + VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT =3D 1 << 15, } virConnectListAllDomainsFlags; int virConnectListAllDomains (virConnectPtr conn, diff --git a/include/libvirt/libvirt.h b/include/libvirt/libvirt.h index 13de151cb6..f93e3bfa85 100644 --- a/include/libvirt/libvirt.h +++ b/include/libvirt/libvirt.h @@ -34,10 +34,7 @@ extern "C" { # include # include # include -/* FIXME: Temporary hack until later patch creates new - * libvirt-domain-checkpoint.h file */ -typedef struct _virDomainCheckpoint virDomainCheckpoint; -typedef virDomainCheckpoint *virDomainCheckpointPtr; +# include # include # include # include diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentob= jlist.h index 897d8d54d1..5b73175e8d 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -70,8 +70,9 @@ virDomainMomentObjPtr virDomainMomentAssignDef(virDomainM= omentObjListPtr moments virDomainMomentDefPtr def); /* Various enum bits that map to public API filters. Note that the - * values of the internal bits are not necessarily the same as the - * public ones. */ + * values of the internal bits are not the same as the public ones for + * snapshot, however, this list should be kept in sync with the public + * ones for checkpoint. */ typedef enum { VIR_DOMAIN_MOMENT_LIST_ROOTS =3D (1 << 0), VIR_DOMAIN_MOMENT_LIST_DESCENDANTS =3D (1 << 0), diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index b15aaa36bc..c1632ae4c6 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1327,6 +1327,37 @@ typedef int int *nparams, unsigned int flags); +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointCreateXML)(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags); + +typedef char * +(*virDrvDomainCheckpointGetXMLDesc)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainListAllCheckpoints)(virDomainPtr domain, + virDomainCheckpointPtr **checkpoints, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointListAllChildren)(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **children, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointLookupByName)(virDomainPtr domain, + const char *name, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointGetParent)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointDelete)(virDomainCheckpointPtr checkpoint, + unsigned int flags); typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1579,4 +1610,11 @@ struct _virHypervisorDriver { virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; virDrvNodeGetSEVInfo nodeGetSEVInfo; virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo; + virDrvDomainCheckpointCreateXML domainCheckpointCreateXML; + virDrvDomainCheckpointGetXMLDesc domainCheckpointGetXMLDesc; + virDrvDomainListAllCheckpoints domainListAllCheckpoints; + virDrvDomainCheckpointListAllChildren domainCheckpointListAllChildren; + virDrvDomainCheckpointLookupByName domainCheckpointLookupByName; + virDrvDomainCheckpointGetParent domainCheckpointGetParent; + virDrvDomainCheckpointDelete domainCheckpointDelete; }; diff --git a/docs/Makefile.am b/docs/Makefile.am index ae2673ca9b..1cdb584b0b 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -22,6 +22,7 @@ DEVHELP_DIR=3D$(datadir)/gtk-doc/html/libvirt modules =3D \ libvirt-common \ libvirt-domain \ + libvirt-domain-checkpoint \ libvirt-domain-snapshot \ libvirt-event \ libvirt-host \ @@ -313,6 +314,7 @@ $(python_generated_files): $(APIBUILD_STAMP) $(APIBUILD_STAMP): $(srcdir)/apibuild.py \ $(top_srcdir)/include/libvirt/libvirt.h \ $(top_srcdir)/include/libvirt/libvirt-common.h.in \ + $(top_srcdir)/include/libvirt/libvirt-domain-checkpoint.h \ $(top_srcdir)/include/libvirt/libvirt-domain-snapshot.h \ $(top_srcdir)/include/libvirt/libvirt-domain.h \ $(top_srcdir)/include/libvirt/libvirt-event.h \ @@ -329,6 +331,7 @@ $(APIBUILD_STAMP): $(srcdir)/apibuild.py \ $(top_srcdir)/include/libvirt/libvirt-admin.h \ $(top_srcdir)/include/libvirt/virterror.h \ $(top_srcdir)/src/libvirt.c \ + $(top_srcdir)/src/libvirt-domain-checkpoint.c \ $(top_srcdir)/src/libvirt-domain-snapshot.c \ $(top_srcdir)/src/libvirt-domain.c \ $(top_srcdir)/src/libvirt-host.c \ diff --git a/docs/apibuild.py b/docs/apibuild.py index 9e04871220..dbdc1c95af 100755 --- a/docs/apibuild.py +++ b/docs/apibuild.py @@ -26,6 +26,7 @@ debugsym =3D None included_files =3D { "libvirt-common.h": "header with general libvirt API definitions", "libvirt-domain.h": "header with general libvirt API definitions", + "libvirt-domain-checkpoint.h": "header with general libvirt API definiti= ons", "libvirt-domain-snapshot.h": "header with general libvirt API definition= s", "libvirt-event.h": "header with general libvirt API definitions", "libvirt-host.h": "header with general libvirt API definitions", @@ -39,6 +40,7 @@ included_files =3D { "virterror.h": "header with error specific API definitions", "libvirt.c": "Main interfaces for the libvirt library", "libvirt-domain.c": "Domain interfaces for the libvirt library", + "libvirt-domain-checkpoint.c": "Domain checkpoint interfaces for the lib= virt library", "libvirt-domain-snapshot.c": "Domain snapshot interfaces for the libvirt= library", "libvirt-host.c": "Host interfaces for the libvirt library", "libvirt-interface.c": "Interface interfaces for the libvirt library", diff --git a/docs/docs.html.in b/docs/docs.html.in index 74af38002e..ba9514279a 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -94,6 +94,7 @@
      Reference manual for the C public API, split in common, domain, + domain c= heckpoint, domain sna= pshot, error, event, diff --git a/libvirt.spec.in b/libvirt.spec.in index 4dee2d8ac2..045c0fed1a 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1862,6 +1862,7 @@ exit 0 %{_includedir}/libvirt/libvirt-admin.h %{_includedir}/libvirt/libvirt-common.h %{_includedir}/libvirt/libvirt-domain.h +%{_includedir}/libvirt/libvirt-domain-checkpoint.h %{_includedir}/libvirt/libvirt-domain-snapshot.h %{_includedir}/libvirt/libvirt-event.h %{_includedir}/libvirt/libvirt-host.h diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index df89d9f8b3..a20c4b7d74 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -264,6 +264,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw32_includedir}/libvirt/libvirt.h %{mingw32_includedir}/libvirt/libvirt-common.h %{mingw32_includedir}/libvirt/libvirt-domain.h +%{mingw32_includedir}/libvirt/libvirt-domain-checkpoint.h %{mingw32_includedir}/libvirt/libvirt-domain-snapshot.h %{mingw32_includedir}/libvirt/libvirt-event.h %{mingw32_includedir}/libvirt/libvirt-host.h @@ -354,6 +355,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw64_includedir}/libvirt/libvirt.h %{mingw64_includedir}/libvirt/libvirt-common.h %{mingw64_includedir}/libvirt/libvirt-domain.h +%{mingw64_includedir}/libvirt/libvirt-domain-checkpoint.h %{mingw64_includedir}/libvirt/libvirt-domain-snapshot.h %{mingw64_includedir}/libvirt/libvirt-event.h %{mingw64_includedir}/libvirt/libvirt-host.h diff --git a/po/POTFILES b/po/POTFILES index ab582ffbe9..5d0bf43f02 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -69,6 +69,7 @@ src/interface/interface_backend_netcf.c src/interface/interface_backend_udev.c src/internal.h src/libvirt-admin.c +src/libvirt-domain-checkpoint.c src/libvirt-domain-snapshot.c src/libvirt-domain.c src/libvirt-host.c diff --git a/src/Makefile.am b/src/Makefile.am index 0b562dc250..4a8cae11dc 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -167,6 +167,7 @@ DRIVER_SOURCES +=3D \ $(DATATYPES_SOURCES) \ libvirt.c libvirt_internal.h \ libvirt-domain.c \ + libvirt-domain-checkpoint.c \ libvirt-domain-snapshot.c \ libvirt-host.c \ libvirt-interface.c \ @@ -719,6 +720,7 @@ libvirt_setuid_rpc_client_la_SOURCES =3D \ datatypes.c \ libvirt.c \ libvirt-domain.c \ + libvirt-domain-checkpoint.c \ libvirt-domain-snapshot.c \ libvirt-host.c \ libvirt-interface.c \ diff --git a/src/libvirt-domain-checkpoint.c b/src/libvirt-domain-checkpoin= t.c new file mode 100644 index 0000000000..fa391f8a06 --- /dev/null +++ b/src/libvirt-domain-checkpoint.c @@ -0,0 +1,567 @@ +/* + * libvirt-domain-checkpoint.c: entry points for virDomainCheckpointPtr AP= Is + * + * 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 + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "datatypes.h" +#include "virlog.h" + +VIR_LOG_INIT("libvirt.domain-checkpoint"); + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT + +/** + * virDomainCheckpointGetName: + * @checkpoint: a checkpoint object + * + * Get the public name for that checkpoint + * + * Returns a pointer to the name or NULL, the string need not be deallocat= ed + * as its lifetime will be the same as the checkpoint object. + */ +const char * +virDomainCheckpointGetName(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + + return checkpoint->name; +} + + +/** + * virDomainCheckpointGetDomain: + * @checkpoint: a checkpoint object + * + * Provides the domain pointer associated with a checkpoint. The + * reference counter on the domain is not increased by this + * call. + * + * Returns the domain or NULL. + */ +virDomainPtr +virDomainCheckpointGetDomain(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + + return checkpoint->domain; +} + + +/** + * virDomainCheckpointGetConnect: + * @checkpoint: a checkpoint object + * + * Provides the connection pointer associated with a checkpoint. The + * reference counter on the connection is not increased by this + * call. + * + * Returns the connection or NULL. + */ +virConnectPtr +virDomainCheckpointGetConnect(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + + return checkpoint->domain->conn; +} + + +/** + * virDomainCheckpointCreateXML: + * @domain: a domain object + * @xmlDesc: description of the checkpoint to create + * @flags: bitwise-OR of supported virDomainCheckpointCreateFlags + * + * Create a new checkpoint using @xmlDesc, with a top-level + * element, on a running @domain. Note that @xmlDesc + * must validate against the XML schema. + * + * See Checkpoint X= ML + * for more details on @xmlDesc. In particular, some hypervisors may requi= re + * particular disk formats, such as qcow2, in order to support this + * command; where @xmlDesc can be used to limit the checkpoint to a working + * subset of the domain's disks. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, then this + * is a request to reinstate checkpoint metadata that was previously + * captured from virDomainCheckpointGetXMLDesc() before removing that + * metadata, rather than creating a new checkpoint. Note that while + * original creation can omit a number of elements from @xmlDesc (and + * libvirt will supply sane defaults based on the domain state at that + * point in time), a redefinition must supply more elements (as the + * domain may have changed in the meantime, so that libvirt no longer + * has a way to resupply correct defaults). Not all hypervisors support + * this flag. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE, then the + * libvirt will attempt to use guest agent to freeze and thaw all file + * systems in use within domain OS. However, if the guest agent is not + * present, an error is thrown. This flag is incompatible with + * VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE. + * + * Returns an (opaque) new virDomainCheckpointPtr on success or NULL + * on failure. + */ +virDomainCheckpointPtr +virDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "xmlDesc=3D%s, flags=3D0x%x", xmlDesc, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNullArgGoto(xmlDesc, error); + virCheckReadOnlyGoto(conn->flags, error); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, + VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE, + error); + + if (conn->driver->domainCheckpointCreateXML) { + virDomainCheckpointPtr ret; + ret =3D conn->driver->domainCheckpointCreateXML(domain, xmlDesc, f= lags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointGetXMLDesc: + * @checkpoint: a domain checkpoint object + * @flags: bitwise-OR of supported virDomainCheckpointXMLFlags + * + * Provide an XML description of the domain checkpoint. + * + * No security-sensitive data will be included unless @flags contains + * VIR_DOMAIN_CHECKPOINT_XML_SECURE; this flag is rejected on read-only + * connections. + * + * Normally, the XML description includes an element giving a full + * description of the domain at the time the checkpoint was created; to + * reduce parsing time, it will be suppressed when @flags contains + * VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN. + * + * By default, the XML description contains only static information that + * does not change over time. However, when @flags contains + * VIR_DOMAIN_CHECKPOINT_XML_SIZE, each listing adds an additional + * attribute that shows an estimate of the current size in bytes that + * have been dirtied between the time the checkpoint was created and the + * current point in time. + * + * Returns a 0 terminated UTF-8 encoded XML instance or NULL in case + * of error. The caller must free() the returned value. + */ +char * +virDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + conn =3D checkpoint->domain->conn; + + if ((conn->flags & VIR_CONNECT_RO) && + (flags & VIR_DOMAIN_CHECKPOINT_XML_SECURE)) { + virReportError(VIR_ERR_OPERATION_DENIED, "%s", + _("virDomainCheckpointGetXMLDesc with secure flag")= ); + goto error; + } + + if (conn->driver->domainCheckpointGetXMLDesc) { + char *ret; + ret =3D conn->driver->domainCheckpointGetXMLDesc(checkpoint, flags= ); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainListAllCheckpoints: + * @domain: a domain object + * @checkpoints: pointer to variable to store the array containing checkpo= int + * object, or NULL if the list is not required (just returns + * number of checkpoints) + * @flags: bitwise-OR of supported virDomainCheckpoinListFlags + * + * Collect the list of domain checkpoints for the given domain and allocate + * an array to store those objects. + * + * If @flags contains VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL, + * @checkpoints is non-NULL, and no other connection is modifying + * checkpoints, then it is guaranteed that for any checkpoint in the + * resulting list, no checkpoints later in the list can be reached by + * a sequence of virDomainCheckpointGetParent() starting from that + * earlier checkpoint; otherwise, the order of checkpoints in the + * resulting list is unspecified. + * + * By default, this command covers all checkpoints. It is also + * possible to limit things to just checkpoints with no parents, when + * @flags includes VIR_DOMAIN_CHECKPOINT_LIST_ROOTS. Additional + * filters are provided in groups listed below. Within a group, bits + * are mutually exclusive, where all possible checkpoints are + * described by exactly one bit from the group. Some hypervisors might + * reject particular flags where it cannot make a distinction for + * filtering. If the set of filter flags selected forms an impossible + * combination, the hypervisor may return either 0 or an error. + * + * The first group of @flags is VIR_DOMAIN_CHECKPOINT_LIST_LEAVES and + * VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES, to filter based on checkpoints th= at + * have no further children (a leaf checkpoint). + * + * Returns the number of domain checkpoints found or -1 and sets @checkpoi= nts + * to NULL in case of error. On success, the array stored into @checkpoin= ts + * is guaranteed to have an extra allocated element set to NULL but not + * included in the return count, to make iteration easier. The caller is + * responsible for calling virDomainCheckpointFree() on each array element, + * then calling free() on @checkpoints. + */ +int +virDomainListAllCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **checkpoints, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "checkpoints=3D%p, flags=3D0x%x", checkpoints= , flags); + + virResetLastError(); + + if (checkpoints) + *checkpoints =3D NULL; + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + if (conn->driver->domainListAllCheckpoints) { + int ret =3D conn->driver->domainListAllCheckpoints(domain, checkpo= ints, + flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointListAllChildren: + * @checkpoint: a domain checkpoint object + * @children: pointer to variable to store the array containing checkpoint + * objects or NULL if the list is not required (just returns + * number of checkpoints) + * @flags: bitwise-OR of supported virDomainCheckpointListFlags + * + * Collect the list of domain checkpoints that are children of the given + * checkpoint, and allocate an array to store those objects. + * + * If @flags contains VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL, + * @checkpoints is non-NULL, and no other connection is modifying + * checkpoints, then it is guaranteed that for any checkpoint in the + * resulting list, no checkpoints later in the list can be reached by + * a sequence of virDomainCheckpointGetParent() starting from that + * earlier checkpoint; otherwise, the order of checkpoints in the + * resulting list is unspecified. + * + * By default, this command covers only direct children. It is also + * possible to expand things to cover all descendants, when @flags + * includes VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS. Additional + * are provided via the remaining @flags values as documented in + * virDomainListAllCheckpoints(), with the exception that + * VIR_DOMAIN_CHECKPOINT_LIST_ROOTS is not supported (in fact, + * VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS has the same bit value but + * opposite semantics of widening rather than narrowing the listing). + * + * Returns the number of domain checkpoints found or -1 and sets @children= to + * NULL in case of error. On success, the array stored into @children is + * guaranteed to have an extra allocated element set to NULL but not inclu= ded + * in the return count, to make iteration easier. The caller is responsib= le + * for calling virDomainCheckpointFree() on each array element, then calli= ng + * free() on @children. + */ +int +virDomainCheckpointListAllChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **children, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, children=3D%p, flags=3D0x%x", + checkpoint, children, flags); + + virResetLastError(); + + if (children) + *children =3D NULL; + + virCheckDomainCheckpointReturn(checkpoint, -1); + conn =3D checkpoint->domain->conn; + + if (conn->driver->domainCheckpointListAllChildren) { + int ret =3D conn->driver->domainCheckpointListAllChildren(checkpoi= nt, + children, + flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointLookupByName: + * @domain: a domain object + * @name: name for the domain checkpoint + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Try to lookup a domain checkpoint based on its name. + * + * Returns a domain checkpoint object or NULL in case of failure. If the + * domain checkpoint cannot be found, then the VIR_ERR_NO_DOMAIN_CHECKPOINT + * error is raised. + */ +virDomainCheckpointPtr +virDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "name=3D%s, flags=3D0x%x", name, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNullArgGoto(name, error); + + if (conn->driver->domainCheckpointLookupByName) { + virDomainCheckpointPtr checkpoint; + checkpoint =3D conn->driver->domainCheckpointLookupByName(domain, = name, + flags); + if (!checkpoint) + goto error; + return checkpoint; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointGetParent: + * @checkpoint: a checkpoint object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Get the parent checkpoint for @checkpoint, if any. + * + * virDomainCheckpointFree should be used to free the resources after the + * checkpoint object is no longer needed. + * + * Returns a domain checkpoint object or NULL in case of failure. If the + * given checkpoint is a root (no parent), then the VIR_ERR_NO_DOMAIN_CHEC= KPOINT + * error is raised. + */ +virDomainCheckpointPtr +virDomainCheckpointGetParent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, NULL); + conn =3D checkpoint->domain->conn; + + if (conn->driver->domainCheckpointGetParent) { + virDomainCheckpointPtr parent; + parent =3D conn->driver->domainCheckpointGetParent(checkpoint, fla= gs); + if (!parent) + goto error; + return parent; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointDelete: + * @checkpoint: the checkpoint to remove + * @flags: bitwise-OR of supported virDomainCheckpointDeleteFlags + * + * Removes a checkpoint from the domain. + * + * When removing a checkpoint, the record of which portions of the + * disk were dirtied after the checkpoint will be merged into the + * record tracked by the parent checkpoint, if any. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN, then any + * descendant checkpoints are also deleted. If @flags includes + * VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY, then any descendant + * checkepoints are deleted, but this checkpoint remains. These two + * flags are mutually exclusive. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY, then + * any checkpoint metadata tracked by libvirt is removed while keeping + * the checkpoint contents intact; if a hypervisor does not require + * any libvirt metadata to track checkpoints, then this flag is + * silently ignored. + * + * Returns 0 on success, -1 on error. + */ +int +virDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DEBUG("checkpoint=3D%p, flags=3D0x%x", checkpoint, flags); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + conn =3D checkpoint->domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN, + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY, + error); + + if (conn->driver->domainCheckpointDelete) { + int ret =3D conn->driver->domainCheckpointDelete(checkpoint, flags= ); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointRef: + * @checkpoint: the checkpoint to hold a reference on + * + * Increment the reference count on the checkpoint. For each + * additional call to this method, there shall be a corresponding + * call to virDomainCheckpointFree to release the reference count, once + * the caller no longer needs the reference to this object. + * + * This method is typically useful for applications where multiple + * threads are using a connection, and it is required that the + * connection and domain remain open until all threads have finished + * using the checkpoint. ie, each new thread using a checkpoint would + * increment the reference count. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainCheckpointRef(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p, refs=3D%d", checkpoint, + checkpoint ? checkpoint->parent.u.s.refs : 0); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + + virObjectRef(checkpoint); + return 0; +} + + +/** + * virDomainCheckpointFree: + * @checkpoint: a domain checkpoint object + * + * Free the domain checkpoint object. The checkpoint itself is not modifi= ed. + * The data structure is freed and should not be used thereafter. + * + * Returns 0 in case of success and -1 in case of failure. + */ +int +virDomainCheckpointFree(virDomainCheckpointPtr checkpoint) +{ + VIR_DEBUG("checkpoint=3D%p", checkpoint); + + virResetLastError(); + + virCheckDomainCheckpointReturn(checkpoint, -1); + + virObjectUnref(checkpoint); + return 0; +} diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 3d12e7c125..2fe9bb8e91 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6218,8 +6218,9 @@ virDomainDefineXMLFlags(virConnectPtr conn, const cha= r *xml, unsigned int flags) * * If the domain has a managed save image (see * virDomainHasManagedSaveImage()), or if it is inactive and has any - * snapshot metadata (see virDomainSnapshotNum()), then the undefine will - * fail. See virDomainUndefineFlags() for more control. + * snapshot metadata (see virDomainSnapshotNum()) or checkpoint + * metadata (see virDomainListAllCheckpoints()), then the undefine + * will fail. See virDomainUndefineFlags() for more control. * * Returns 0 in case of success, -1 in case of error */ @@ -6276,6 +6277,16 @@ virDomainUndefine(virDomainPtr domain) * support snapshots, but where snapshots do not use libvirt metadata, * this flag has no effect. * + * If the domain is inactive and has any checkpoint metadata (see + * virDomainListAllCheckpoints()), then including + * VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA in @flags will also remove + * that metadata. Omitting the flag will cause the undefine of an + * inactive domain with checkpoints to fail. Active domains will + * retain checkpoint metadata until the (now-transient) domain halts, + * regardless of whether this flag is present. On hypervisors that + * support checkpoints, but where checkpoints do not use libvirt + * metadata, this flag has no effect. + * * If the domain has any nvram specified, the undefine process will fail * unless VIR_DOMAIN_UNDEFINE_KEEP_NVRAM is specified, or if * VIR_DOMAIN_UNDEFINE_NVRAM is specified to remove the nvram file. @@ -6436,7 +6447,9 @@ virConnectListDefinedDomains(virConnectPtr conn, char= **const names, * VIR_CONNECT_LIST_DOMAINS_NO_AUTOSTART, for filtering based on autostart; * VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT and * VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT, for filtering based on whether - * a domain has snapshots. + * a domain has snapshots; VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT and + * VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT, for filtering based on whether + * a domain has checkpoints. * * Example of usage: * diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index 18500ec8b2..54256b6317 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -836,4 +836,20 @@ LIBVIRT_5.5.0 { virNetworkPortSetParameters; } LIBVIRT_5.2.0; +LIBVIRT_5.6.0 { + global: + virDomainCheckpointCreateXML; + virDomainCheckpointDelete; + virDomainCheckpointFree; + virDomainCheckpointGetConnect; + virDomainCheckpointGetDomain; + virDomainCheckpointGetName; + virDomainCheckpointGetParent; + virDomainCheckpointGetXMLDesc; + virDomainCheckpointListAllChildren; + virDomainCheckpointLookupByName; + virDomainCheckpointRef; + virDomainListAllCheckpoints; +} LIBVIRT_5.5.0; + # .... define new API here using predicted next version number .... --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947803; cv=none; d=zoho.com; s=zohoarc; b=YP+24BNTHo4J4UcxFJcEFdd9TozE0LmR3ygSH063IH7/g7fPPDXXN/urHOuJHZtA52DxLy4Cgf6RJji4+v1hrB3pTwOOdjyV5KY3wEc/olU5nhNWVdA+AwiJzDFh7tNa2CZYyS0q2ro0solQibseG4ewbB+nMac+mDhybeIbQ4I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947803; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=S3sNYERYBR/8slBY/e6JC8wDDFYbq0ikg/UAjvFqmZk=; b=cF0ZmCPmSdhw+T8HAkixrJbalRJhbMF/XaiIS/OkI5XxSL13aOeJIuPifJwFcLn8yiVKGhAuMbMhNvgSmL0FzHPQrCXOU+xcU74PVI9nVaz/OLVu2r9r5jRCnTbwG6E/uK9hlp9b3sCxiKDpzm/1mstxdGYyR/94VR3+9kTdETE= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947803077417.3997497680939; Tue, 23 Jul 2019 22:56:43 -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 A147181DF9; Wed, 24 Jul 2019 05:56:41 +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 792F41820D; Wed, 24 Jul 2019 05:56:41 +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 36A471972F; Wed, 24 Jul 2019 05:56:41 +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 x6O5uP2j029160 for ; Wed, 24 Jul 2019 01:56:25 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD08D60C69; Wed, 24 Jul 2019 05:56:25 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 198A360BF7; Wed, 24 Jul 2019 05:56:25 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:57 -0500 Message-Id: <20190724055609.30691-8-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 07/19] backup: Document nuances between different state capture APIs 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-Type: text/plain; charset="utf-8" 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.25]); Wed, 24 Jul 2019 05:56:42 +0000 (UTC) Now that various new API have been added or are coming soon, it is worth a landing page that gives an overview of capturing various pieces of guest state, and which APIs are best suited to which tasks. Signed-off-by: Eric Blake Reviewed-by: John Ferlan Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/formatcheckpoint.html.in | 4 +- docs/formatsnapshot.html.in | 2 + docs/kbase.html.in | 5 + docs/kbase/domainstatecapture.html.in | 303 ++++++++++++++++++++++++++ 4 files changed, 313 insertions(+), 1 deletion(-) create mode 100644 docs/kbase/domainstatecapture.html.in diff --git a/docs/formatcheckpoint.html.in b/docs/formatcheckpoint.html.in index 50dd4d284c..aae0e27463 100644 --- a/docs/formatcheckpoint.html.in +++ b/docs/formatcheckpoint.html.in @@ -13,7 +13,9 @@ incremental backups. Right now, incremental backups are only supported for the QEMU hypervisor when using qcow2 disks at the active layer; if other disk formats are in use, capturing disk - backups requires different libvirt APIs. + backups requires different libvirt APIs + (see domain state capture + for a comparison between APIs).

      Libvirt is able to facilitate incremental backups by tracking diff --git a/docs/formatsnapshot.html.in b/docs/formatsnapshot.html.in index 005800bc00..ced8bbd6db 100644 --- a/docs/formatsnapshot.html.in +++ b/docs/formatsnapshot.html.in @@ -9,6 +9,8 @@

      Snapshot XML

      + Snapshots are one form + of domain state capture. There are several types of snapshots:

      diff --git a/docs/kbase.html.in b/docs/kbase.html.in index 78f2a4e0c5..97d3f4c384 100644 --- a/docs/kbase.html.in +++ b/docs/kbase.html.in @@ -16,6 +16,11 @@
      Launch security=
      Securely launching VMs with AMD SEV
      + +
      Domain state + capture
      +
      Comparison between different methods of capturing domain + state
      diff --git a/docs/kbase/domainstatecapture.html.in b/docs/kbase/domainstate= capture.html.in new file mode 100644 index 0000000000..f8c7394785 --- /dev/null +++ b/docs/kbase/domainstatecapture.html.in @@ -0,0 +1,303 @@ + + + + + +

      Domain state capture using Libvirt

      + +
        + +

        + In order to aid application developers to choose which + operations best suit their needs, this page compares the + different means for capturing state related to a domain managed + by libvirt. +

        + +

        + The information here is primarily geared towards capturing the + state of an active domain. Capturing the state of an inactive + domain essentially amounts to copying the contents of guest + disks, followed by a fresh boot of the same domain configuration + with disks restored back to that saved state. +

        + +

        State capture trade-offs

        + +

        One of the features made possible with virtual machines is live + migration -- transferring all state related to the guest from + one host to another with minimal interruption to the guest's + activity. In this case, state includes domain memory (including + register and device contents), and domain storage (whether the + guest's view of the disks are backed by local storage on the + host, or by the hypervisor accessing shared storage over a + network). A clever observer will then note that if all state is + available for live migration, then there is nothing stopping a + user from saving some or all of that state at a given point of + time in order to be able to later rewind guest execution back to + the state it previously had. The astute reader will also realize + that state capture at any level requires that the data must be + stored and managed by some mechanism. This processing might fit + in a single file, or more likely require a chain of related + files, and may require synchronization with third-party tools + built around managing the amount of data resulting from + capturing the state of multiple guests that each use multiple + disks. +

        + +

        + There are several libvirt APIs associated with capturing the + state of a guest, which can later be used to rewind that guest + to the conditions it was in earlier. The following is a list of + trade-offs and differences between the various facets that + affect capturing domain state for active domains: +

        + +
        +
        Duration
        +
        Capturing state can be a lengthy process, so while the + captured state ideally represents an atomic point in time + corresponding to something the guest was actually executing, + capturing state tends to focus on minimizing guest downtime + while performing the rest of the state capture in parallel + with guest execution. Some interfaces require up-front + preparation (the state captured is not complete until the API + ends, which may be some time after the command was first + started), while other interfaces track the state when the + command was first issued, regardless of the time spent in + capturing the rest of the state. Also, time spent in state + capture may be longer than the time required for live + migration, when state must be duplicated rather than shared. +
        + +
        Amount of state
        +
        For an online guest, there is a choice between capturing the + guest's memory (all that is needed during live migration when + the storage is already shared between source and destination), + the guest's disk state (all that is needed if there are no + pending guest I/O transactions that would be lost without the + corresponding memory state), or both together. Reverting to + partial state may still be viable, but typically, booting from + captured disk state without corresponding memory is comparable + to rebooting a machine that had power cut before I/O could be + flushed. Guests may need to use proper journaling methods to + avoid problems when booting from partial state. +
        + +
        Quiescing of data
        +
        Even if a guest has no pending I/O, capturing disk state may + catch the guest at a time when the contents of the disk are + inconsistent. Cooperating with the guest to perform data + quiescing is an optional step to ensure that captured disk + state is fully consistent without requiring additional memory + state, rather than just crash-consistent. But guest + cooperation may also have time constraints, where the guest + can rightfully panic if there is too much downtime while I/O + is frozen. +
        + +
        Quantity of files
        +
        When capturing state, some approaches store all state within + the same file (internal), while others expand a chain of + related files that must be used together (external), for more + files that a management application must track. +
        + +
        Impact to guest definition
        +
        Capturing state may require temporary changes to the guest + definition, such as associating new files into the domain + definition. While state capture should never impact the + running guest, a change to the domain's active XML may have + impact on other host operations being performed on the domain. +
        + +
        Third-party integration
        +
        When capturing state, there are tradeoffs to how much of the + process must be done directly by the hypervisor, and how much + can be off-loaded to third-party software. Since capturing + state is not instantaneous, it is essential that any + third-party integration see consistent data even if the + running guest continues to modify that data after the point in + time of the capture.
        + +
        Full vs. incremental
        +
        When periodically repeating the action of state capture, it + is useful to minimize the amount of state that must be + captured by exploiting the relation to a previous capture, + such as focusing only on the portions of the disk that the + guest has modified in the meantime. Some approaches are able + to take advantage of checkpoints to provide an incremental + backup, while others are only capable of a full backup even if + that means re-capturing unchanged portions of the disk.
        + +
        Local vs. remote
        +
        Domains that completely use remote storage may only need + some mechanism to keep track of guest memory state while using + external means to manage storage. Still, hypervisor and guest + cooperation to ensure points in time when no I/O is in flight + across the network can be important for properly capturing + disk state.
        + +
        Network latency
        +
        Whether it's domain storage or saving domain state into + remote storage, network latency has an impact on snapshot + data. Having dedicated network capacity, bandwidth, or quality + of service levels may play a role, as well as planning for how + much of the backup process needs to be local.
        +
        + +

        + An example of the various facets in action is migration of a + running guest. In order for the guest to be able to resume on + the destination at the same place it left off at the source, the + hypervisor has to get to a point where execution on the source + is stopped, the last remaining changes occurring since the + migration started are then transferred, and the guest is started + on the target. The management software thus must keep track of + the starting point and any changes since the starting + point. These last changes are often referred to as dirty page + tracking or dirty disk block bitmaps. At some point in time + during the migration, the management software must freeze the + source guest, transfer the dirty data, and then start the guest + on the target. This period of time must be minimal. To minimize + overall migration time, one is advised to use a dedicated + network connection with a high quality of service. Alternatively + saving the current state of the running guest can just be a + point in time type operation which doesn't require updating the + "last vestiges" of state prior to writing out the saved state + file. The state file is the point in time of whatever is current + and may contain incomplete data which if used to restart the + guest could cause confusion or problems because some operation + wasn't completed depending upon where in time the operation was + commenced. +

        + +

        State capture APIs

        +

        With those definitions, the following libvirt APIs related to + state capture have these properties:

        +
        +
        virDomainManagedSave
        +
        This API saves guest memory, with libvirt managing all of + the saved state, then stops the guest. While stopped, the + disks can be copied by a third party. However, since any + subsequent restart of the guest by libvirt API will restore + the memory state (which typically only works if the disk state + is unchanged in the meantime), and since it is not possible to + get at the memory state that libvirt is managing, this is not + viable as a means for rolling back to earlier saved states, + but is rather more suited to situations such as suspending a + guest prior to rebooting the host in order to resume the guest + when the host is back up. This API also has a drawback of + potentially long guest downtime, and therefore does not lend + itself well to live backups.
        + +
        virDomainSave
        +
        This API is similar to virDomainManagedSave(), but moves the + burden on managing the stored memory state to the user. As + such, the user can now couple saved state with copies of the + disks to perform a revert to an arbitrary earlier saved state. + However, changing who manages the memory state does not change + the drawback of potentially long guest downtime when capturing + state.
        + +
        virDomainSnapshotCreateXML
        +
        This API wraps several approaches for capturing guest state, + with a general premise of creating a snapshot (where the + current guest resources are frozen in time and a new wrapper + layer is opened for tracking subsequent guest changes). It + can operate on both offline and running guests, can choose + whether to capture the state of memory, disk, or both when + used on a running guest, and can choose between internal and + external storage for captured state. However, it is geared + towards post-event captures (when capturing both memory and + disk state, the disk state is not captured until all memory + state has been collected first). Using QEMU as the + hypervisor, internal snapshots currently have lengthy downtime + that is incompatible with freezing guest I/O, but external + snapshots are quick when memory contents are not also saved. + Since creating an external snapshot changes which disk image + resource is in use by the guest, this API can be coupled + with virDomainBlockCommit() + to restore things back to the guest using its original disk + image, where a third-party tool can read the backing file + prior to the live commit. See also + the XML details used with + this command.
        + +
        <= code>virDomainFSFreeze, virDomainFSThaw
        +
        This pair of APIs does not directly capture guest state, but + can be used to coordinate with a trusted live guest that state + capture is about to happen, and therefore guest I/O should be + quiesced so that the state capture is fully consistent, rather + than merely crash consistent. Some APIs are able to + automatically perform a freeze and thaw via a flags parameter, + rather than having to make separate calls to these + functions. Also, note that freezing guest I/O is only possible + with trusted guests running a guest agent, and that some + guests place maximum time limits on how long I/O can be + frozen.
        + +
        virDomainCheckpointCreateXML
        +
        This API does not actually capture guest state, rather it + makes it possible to track which portions of guest disks have + changed between a checkpoint and the current live execution of + the guest. However, while it is possible use this API to + create checkpoints in isolation, it is more typical to create + a checkpoint as a side-effect of starting a new incremental + backup with virDomainBackupBegin() or at the + creation of an external snapshot + with virDomainSnapshotCreateXML2(), since a + second incremental backup is most useful when using the + checkpoint created during the first. See also + the XML details used with + this command.
        + +
        virDomainBackupBegin, virDomainBackupEnd
        +
        This API wraps approaches for capturing the state of disks + of a running guest, but does not track accompanying guest + memory state. The capture is consistent to the start of the + operation, where the captured state is stored independently + from the disk image in use with the guest and where it can be + easily integrated with a third-party for capturing the disk + state. Since the backup operation is stored externally from + the guest resources, there is no need to commit data back in + at the completion of the operation. When coupled with + checkpoints, this can be used to capture incremental backups + instead of full.
        +
        + +

        Examples

        +

        The following two sequences both accomplish the task of + capturing the disk state of a running guest, then wrapping + things up so that the guest is still running with the same file + as its disk image as before the sequence of operations began. + The difference between the two sequences boils down to the + impact of an unexpected interruption made at any point in the + middle of the sequence: with such an interruption, the first + example leaves the guest tied to a temporary wrapper file rather + than the original disk, and requires manual clean up of the + domain definition; while the second example has no impact to the + domain definition.

        + +

        1. Backup via temporary snapshot +

        +virDomainFSFreeze()
        +virDomainSnapshotCreateXML(VIR_DOMAIN_SNAPSHOT_CREATE_DISK_ONLY)
        +virDomainFSThaw()
        +third-party copy the backing file to backup storage # most time spent here
        +virDomainBlockCommit(VIR_DOMAIN_BLOCK_COMMIT_ACTIVE) per disk
        +wait for commit ready event per disk
        +virDomainBlockJobAbort() per disk
        +      

        + +

        2. Direct backup +

        +virDomainFSFreeze()
        +virDomainBackupBegin()
        +virDomainFSThaw()
        +wait for push mode event, or pull data over NBD # most time spent here
        +virDomainBackupEnd()
        +    

        + + + --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947796; cv=none; d=zoho.com; s=zohoarc; b=MS1y15/PKtnCXyCcwuM7FcDsNXYPowdiDZUrRtKn3W4H03dp5FOZO9JmphgatEvUhYZU5lxPYztszPjsVMpkjHks6aqeuBAut2EBUHBQTFncRBN3wypRhRAJy6BFMJLSJ+AFRGCpmRgTrzJQKw/3YuYRNg34eTz7VpO9ywOzTBg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947796; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=fsCWKdqwyLjL77tDe9oIQqkjbHwHxhl903OTsQdkUnk=; b=HjhjCC0h9P4fPTGUspAiowTzsvrrUqBmGQ2mPmZgwiegCnEScHvRPcDGsyHVeFGuZiPHQp2/7u3vxsi9oMdUQH1t/rQ8V1NmzgLvrwmrIkorjdDUL68ab3uwlqThMxPq0kHrJxfgs1TVknoL8jp21anGduw+S+Qut8TcWC9T5Q4= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947796990864.9967382323042; Tue, 23 Jul 2019 22:56:36 -0700 (PDT) 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 87DB92EED1C; Wed, 24 Jul 2019 05:56:35 +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 511EA1024816; Wed, 24 Jul 2019 05:56:35 +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 18CB718045CF; Wed, 24 Jul 2019 05:56:35 +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 x6O5uQoE029168 for ; Wed, 24 Jul 2019 01:56:26 -0400 Received: by smtp.corp.redhat.com (Postfix) id 770D160C05; Wed, 24 Jul 2019 05:56:26 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id DE37B60BFC; Wed, 24 Jul 2019 05:56:25 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:58 -0500 Message-Id: <20190724055609.30691-9-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 08/19] backup: Parse and output checkpoint XML 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.29]); Wed, 24 Jul 2019 05:56:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add a new file checkpoint_conf.c that performs the translation to and from new XML describing a checkpoint. The code shares a common base class with snapshots, since a checkpoint similarly represents the domain state at a moment in time. Add some basic testing of round trip XML handling through the new code. Of note - this code intentionally differs from snapshots in that XML schema validation is unconditional, rather than based on a public API flag. Also, the redefine flag requires the sub-element to be present, rather than catering to historical back-compat to older versions. Signed-off-by: Eric Blake --- src/conf/checkpoint_conf.h | 84 +++ src/conf/virconftypes.h | 3 + po/POTFILES | 1 + src/conf/Makefile.inc.am | 2 + src/conf/checkpoint_conf.c | 535 ++++++++++++++++++ src/libvirt_private.syms | 8 + tests/Makefile.am | 9 +- .../internal-active-invalid.xml | 53 ++ .../internal-inactive-invalid.xml | 53 ++ tests/qemudomaincheckpointxml2xmltest.c | 213 +++++++ 10 files changed, 959 insertions(+), 2 deletions(-) create mode 100644 src/conf/checkpoint_conf.h create mode 100644 src/conf/checkpoint_conf.c create mode 100644 tests/qemudomaincheckpointxml2xmlout/internal-active-in= valid.xml create mode 100644 tests/qemudomaincheckpointxml2xmlout/internal-inactive-= invalid.xml create mode 100644 tests/qemudomaincheckpointxml2xmltest.c diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h new file mode 100644 index 0000000000..0fac521efe --- /dev/null +++ b/src/conf/checkpoint_conf.h @@ -0,0 +1,84 @@ +/* + * checkpoint_conf.h: domain checkpoint XML processing + * (based on snapshot_conf.h) + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "internal.h" +#include "domain_conf.h" +#include "moment_conf.h" +#include "virobject.h" + +/* Items related to checkpoint state */ + +typedef enum { + VIR_DOMAIN_CHECKPOINT_TYPE_DEFAULT =3D 0, + VIR_DOMAIN_CHECKPOINT_TYPE_NONE, + VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP, + + VIR_DOMAIN_CHECKPOINT_TYPE_LAST +} virDomainCheckpointType; + +/* Stores disk-checkpoint information */ +typedef struct _virDomainCheckpointDiskDef virDomainCheckpointDiskDef; +typedef virDomainCheckpointDiskDef *virDomainCheckpointDiskDefPtr; +struct _virDomainCheckpointDiskDef { + char *name; /* name matching the dom->disks that matches na= me */ + int type; /* virDomainCheckpointType */ + char *bitmap; /* bitmap name, if type is bitmap */ + unsigned long long size; /* current checkpoint size in bytes */ +}; + +/* Stores the complete checkpoint metadata */ +struct _virDomainCheckpointDef { + virDomainMomentDef parent; + + /* Additional Public XML. */ + size_t ndisks; /* should not exceed dom->ndisks */ + virDomainCheckpointDiskDef *disks; +}; + + +typedef enum { + VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE =3D 1 << 0, +} virDomainCheckpointParseFlags; + +typedef enum { + VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE =3D 1 << 0, + VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN =3D 1 << 1, + VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE =3D 1 << 2, +} virDomainCheckpointFormatFlags; + +unsigned int virDomainCheckpointFormatConvertXMLFlags(unsigned int flags); + +virDomainCheckpointDefPtr virDomainCheckpointDefParseString(const char *xm= lStr, + virCapsPtr cap= s, + virDomainXMLOp= tionPtr xmlopt, + unsigned int f= lags); +virDomainCheckpointDefPtr virDomainCheckpointDefNew(void); +char *virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +int virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr checkpoint); + +VIR_ENUM_DECL(virDomainCheckpoint); diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index b8f553f7fb..fe3f0af14f 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -102,6 +102,9 @@ typedef virDomainBlkiotune *virDomainBlkiotunePtr; typedef struct _virDomainBlockIoTuneInfo virDomainBlockIoTuneInfo; typedef virDomainBlockIoTuneInfo *virDomainBlockIoTuneInfoPtr; +typedef struct _virDomainCheckpointDef virDomainCheckpointDef; +typedef virDomainCheckpointDef *virDomainCheckpointDefPtr; + typedef struct _virDomainChrDef virDomainChrDef; typedef virDomainChrDef *virDomainChrDefPtr; diff --git a/po/POTFILES b/po/POTFILES index 5d0bf43f02..2c27049d55 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -15,6 +15,7 @@ src/bhyve/bhyve_monitor.c src/bhyve/bhyve_parse_command.c src/bhyve/bhyve_process.c src/conf/capabilities.c +src/conf/checkpoint_conf.c src/conf/cpu_conf.c src/conf/device_conf.c src/conf/domain_addr.c diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index 16a21c34f3..f656725e3a 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -14,6 +14,8 @@ NETDEV_CONF_SOURCES =3D \ DOMAIN_CONF_SOURCES =3D \ conf/capabilities.c \ conf/capabilities.h \ + conf/checkpoint_conf.c \ + conf/checkpoint_conf.h \ conf/domain_addr.c \ conf/domain_addr.h \ conf/domain_capabilities.c \ diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c new file mode 100644 index 0000000000..69c9040a43 --- /dev/null +++ b/src/conf/checkpoint_conf.c @@ -0,0 +1,535 @@ +/* + * checkpoint_conf.c: domain checkpoint XML processing + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "configmake.h" +#include "internal.h" +#include "virbitmap.h" +#include "virbuffer.h" +#include "datatypes.h" +#include "domain_conf.h" +#include "virlog.h" +#include "viralloc.h" +#include "checkpoint_conf.h" +#include "virstoragefile.h" +#include "viruuid.h" +#include "virfile.h" +#include "virerror.h" +#include "virxml.h" +#include "virstring.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT + +VIR_LOG_INIT("conf.checkpoint_conf"); + +static virClassPtr virDomainCheckpointDefClass; +static void virDomainCheckpointDefDispose(void *obj); + +static int +virDomainCheckpointOnceInit(void) +{ + if (!VIR_CLASS_NEW(virDomainCheckpointDef, virClassForDomainMomentDef(= ))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virDomainCheckpoint); + +VIR_ENUM_IMPL(virDomainCheckpoint, + VIR_DOMAIN_CHECKPOINT_TYPE_LAST, + "default", "no", "bitmap"); + + +/* Checkpoint Def functions */ +static void +virDomainCheckpointDiskDefClear(virDomainCheckpointDiskDefPtr disk) +{ + VIR_FREE(disk->name); + VIR_FREE(disk->bitmap); +} + +/* Allocate a new virDomainCheckpointDef; free with virObjectUnref() */ +virDomainCheckpointDefPtr +virDomainCheckpointDefNew(void) +{ + virDomainCheckpointDefPtr def; + + if (virDomainCheckpointInitialize() < 0) + return NULL; + + def =3D virObjectNew(virDomainCheckpointDefClass); + return def; +} + +static void +virDomainCheckpointDefDispose(void *obj) +{ + virDomainCheckpointDefPtr def =3D obj; + size_t i; + + for (i =3D 0; i < def->ndisks; i++) + virDomainCheckpointDiskDefClear(&def->disks[i]); + VIR_FREE(def->disks); +} + +static int +virDomainCheckpointDiskDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainCheckpointDiskDefPtr def) +{ + VIR_AUTOFREE(char *) checkpoint =3D NULL; + VIR_XPATH_NODE_AUTORESTORE(ctxt); + + ctxt->node =3D node; + + /* Schema guarantees this is non-NULL: */ + def->name =3D virXMLPropString(node, "name"); + + checkpoint =3D virXMLPropString(node, "checkpoint"); + if (checkpoint) + /* Schema guarantees this is in range: */ + def->type =3D virDomainCheckpointTypeFromString(checkpoint); + else + def->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + + def->bitmap =3D virXMLPropString(node, "bitmap"); + + return 0; +} + +/* flags is bitwise-or of virDomainCheckpointParseFlags. If flags + * does not include VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE, then caps + * is ignored. + */ +static virDomainCheckpointDefPtr +virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainCheckpointDefPtr ret =3D NULL; + size_t i; + int n; + char *tmp; + VIR_AUTOFREE(xmlNodePtr *) nodes =3D NULL; + VIR_AUTOFREE(char *)creation =3D NULL; + VIR_AUTOUNREF(virDomainCheckpointDefPtr) def =3D NULL; + + if (!(def =3D virDomainCheckpointDefNew())) + return NULL; + + def->parent.name =3D virXPathString("string(./name)", ctxt); + + if (def->parent.name =3D=3D NULL) { + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("a redefined checkpoint must have a name")); + return NULL; + } + } + + def->parent.description =3D virXPathString("string(./description)", ct= xt); + + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) { + if (virXPathLongLong("string(./creationTime)", ctxt, + &def->parent.creationTime) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing creationTime from existing checkpoin= t")); + return NULL; + } + + def->parent.parent_name =3D virXPathString("string(./parent/name)"= , ctxt); + + if ((tmp =3D virXPathString("string(./domain/@type)", ctxt))) { + int domainflags =3D VIR_DOMAIN_DEF_PARSE_INACTIVE | + VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE; + xmlNodePtr domainNode =3D virXPathNode("./domain", ctxt); + + VIR_FREE(tmp); + if (!domainNode) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint")); + return NULL; + } + def->parent.dom =3D virDomainDefParseNode(ctxt->node->doc, dom= ainNode, + caps, xmlopt, NULL, + domainflags); + if (!def->parent.dom) + return NULL; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint redefine")); + return NULL; + } + } else if (virDomainXMLOptionRunMomentPostParse(xmlopt, &def->parent) = < 0) { + return NULL; + } + + if ((n =3D virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0) + return NULL; + if (n && VIR_ALLOC_N(def->disks, n) < 0) + return NULL; + def->ndisks =3D n; + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainCheckpointDiskDefParseXML(nodes[i], ctxt, + &def->disks[i]) < 0) + return NULL; + } + + VIR_STEAL_PTR(ret, def); + return ret; +} + +static virDomainCheckpointDefPtr +virDomainCheckpointDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + virDomainCheckpointDefPtr def =3D NULL; + VIR_AUTOFREE(char *) schema =3D NULL; + + if (!virXMLNodeNameEqual(root, "domaincheckpoint")) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("domaincheckpoint")); + goto cleanup; + } + + /* This is a new enough API to make schema validation unconditional */ + schema =3D virFileFindResource("domaincheckpoint.rng", + abs_top_srcdir "/docs/schemas", + PKGDATADIR "/schemas"); + if (!schema) + return NULL; + if (virXMLValidateAgainstSchema(schema, xml) < 0) + return NULL; + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virDomainCheckpointDefParse(ctxt, caps, xmlopt, flags); + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + +virDomainCheckpointDefPtr +virDomainCheckpointDefParseString(const char *xmlStr, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainCheckpointDefPtr ret =3D NULL; + xmlDocPtr xml; + int keepBlanksDefault =3D xmlKeepBlanksDefault(0); + + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_checkpoint)")))) { + xmlKeepBlanksDefault(keepBlanksDefault); + ret =3D virDomainCheckpointDefParseNode(xml, xmlDocGetRootElement(= xml), + caps, xmlopt, flags); + xmlFreeDoc(xml); + } + xmlKeepBlanksDefault(keepBlanksDefault); + + return ret; +} + + +/** + * virDomainCheckpointDefAssignBitmapNames: + * @def: checkpoint def object + * + * Generate default bitmap names for checkpoint targets. Returns 0 on + * success, -1 on error. + */ +static int +virDomainCheckpointDefAssignBitmapNames(virDomainCheckpointDefPtr def) +{ + size_t i; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &def->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP || + disk->bitmap) + continue; + + if (VIR_STRDUP(disk->bitmap, def->parent.name) < 0) + return -1; + } + + return 0; +} + + +static int +virDomainCheckpointCompareDiskIndex(const void *a, const void *b) +{ + const virDomainCheckpointDiskDef *diska =3D a; + const virDomainCheckpointDiskDef *diskb =3D b; + + /* Integer overflow shouldn't be a problem here. */ + return diska->idx - diskb->idx; +} + +/* Align def->disks to def->domain. Sort the list of def->disks, + * filling in any missing disks with appropriate default. Convert + * paths to disk targets for uniformity. Issue an error and return -1 + * if any def->disks[n]->name appears more than once or does not map + * to dom->disks. */ +int +virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr def) +{ + int ret =3D -1; + virBitmapPtr map =3D NULL; + size_t i; + int ndisks; + int checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE; + + if (!def->parent.dom) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint")); + goto cleanup; + } + + if (def->ndisks > def->parent.dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("too many disk checkpoint requests for domain")); + goto cleanup; + } + + /* Unlikely to have a guest without disks but technically possible. */ + if (!def->parent.dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("domain must have at least one disk to perform " + "checkpoints")); + goto cleanup; + } + + /* If omitted, do bitmap on all writeable disks; + * otherwise, do nothing for omitted disks */ + if (!def->ndisks) + checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + + if (!(map =3D virBitmapNew(def->parent.dom->ndisks))) + goto cleanup; + + /* Double check requested disks. */ + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &def->disks[i]; + int idx =3D virDomainDiskIndexByName(def->parent.dom, disk->name, = false); + + if (idx < 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("no disk named '%s'"), disk->name); + goto cleanup; + } + + if (virBitmapIsBitSet(map, idx)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' specified twice"), + disk->name); + goto cleanup; + } + if ((virStorageSourceIsEmpty(def->parent.dom->disks[idx]->src) || + def->parent.dom->disks[idx]->src->readonly) && + disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' is empty or readonly"), + disk->name); + goto cleanup; + } + ignore_value(virBitmapSetBit(map, idx)); + disk->idx =3D idx; + + if (STRNEQ(disk->name, def->parent.dom->disks[idx]->dst)) { + VIR_FREE(disk->name); + if (VIR_STRDUP(disk->name, def->parent.dom->disks[idx]->dst) <= 0) + goto cleanup; + } + } + + /* Provide defaults for all remaining disks. */ + ndisks =3D def->ndisks; + if (VIR_EXPAND_N(def->disks, def->ndisks, + def->parent.dom->ndisks - def->ndisks) < 0) + goto cleanup; + + for (i =3D 0; i < def->parent.dom->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk; + + if (virBitmapIsBitSet(map, i)) + continue; + disk =3D &def->disks[ndisks++]; + if (VIR_STRDUP(disk->name, def->parent.dom->disks[i]->dst) < 0) + goto cleanup; + disk->idx =3D i; + + /* Don't checkpoint empty or readonly drives */ + if (virStorageSourceIsEmpty(def->parent.dom->disks[i]->src) || + def->parent.dom->disks[i]->src->readonly) + disk->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE; + else + disk->type =3D checkpoint_default; + } + + qsort(&def->disks[0], def->ndisks, sizeof(def->disks[0]), + virDomainCheckpointCompareDiskIndex); + + /* Generate default bitmap names for checkpoint */ + if (virDomainCheckpointDefAssignBitmapNames(def) < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + virBitmapFree(map); + return ret; +} + + +/* Converts public VIR_DOMAIN_CHECKPOINT_XML_* into + * VIR_DOMAIN_CHECKPOINT_FORMAT_* flags, and silently ignores any other + * flags. */ +unsigned int virDomainCheckpointFormatConvertXMLFlags(unsigned int flags) +{ + unsigned int formatFlags =3D 0; + + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SECURE) + formatFlags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE; + if (flags & VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN) + formatFlags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN; + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) + formatFlags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE; + + return formatFlags; +} + + +static int +virDomainCheckpointDiskDefFormat(virBufferPtr buf, + virDomainCheckpointDiskDefPtr disk, + unsigned int flags) +{ + if (!disk->name) + return 0; + + virBufferEscapeString(buf, "name); + if (disk->type) + virBufferAsprintf(buf, " checkpoint=3D'%s'", + virDomainCheckpointTypeToString(disk->type)); + if (disk->bitmap) { + virBufferEscapeString(buf, " bitmap=3D'%s'", disk->bitmap); + if (flags & VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE) + virBufferAsprintf(buf, " size=3D'%llu'", disk->size); + } + virBufferAddLit(buf, "/>\n"); + return 0; +} + + +static int +virDomainCheckpointDefFormatInternal(virBufferPtr buf, + virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + size_t i; + unsigned int domainflags =3D VIR_DOMAIN_DEF_FORMAT_INACTIVE; + + if (flags & VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE) + domainflags |=3D VIR_DOMAIN_DEF_FORMAT_SECURE; + + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + + virBufferEscapeString(buf, "%s\n", def->parent.name); + virBufferEscapeString(buf, "%s\n", + def->parent.description); + + if (def->parent.parent_name) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s\n", + def->parent.parent_name); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + if (def->parent.creationTime) + virBufferAsprintf(buf, "%lld\n", + def->parent.creationTime); + + if (def->ndisks) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainCheckpointDiskDefFormat(buf, &def->disks[i], + flags) < 0) + goto error; + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + if (!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN) && + virDomainDefFormatInternal(def->parent.dom, caps, domainflags, buf, + xmlopt) < 0) + goto error; + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + if (virBufferCheckError(buf) < 0) + goto error; + + return 0; + + error: + virBufferFreeAndReset(buf); + return -1; +} + +char * +virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE | + VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN | + VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE, NULL); + if (virDomainCheckpointDefFormatInternal(&buf, def, caps, xmlopt, + flags) < 0) + return NULL; + + return virBufferContentAndReset(&buf); +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index ff5a77b0e2..693c75b45d 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -69,6 +69,14 @@ virCapabilitiesSetHostCPU; virCapabilitiesSetNetPrefix; +# conf/checkpoint_conf.h +virDomainCheckpointDefFormat; +virDomainCheckpointDefNew; +virDomainCheckpointDefParseString; +virDomainCheckpointTypeFromString; +virDomainCheckpointTypeToString; + + # conf/cpu_conf.h virCPUCacheModeTypeFromString; virCPUCacheModeTypeToString; diff --git a/tests/Makefile.am b/tests/Makefile.am index 9e2e57459e..544328bb18 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -276,7 +276,7 @@ endif WITH_LIBXL if WITH_QEMU test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ - qemudomainsnapshotxml2xmltest \ + qemudomaincheckpointxml2xmltest qemudomainsnapshotxml2xmltest \ qemumonitorjsontest qemuhotplugtest \ qemuagenttest qemucapabilitiestest qemucaps2xmltest \ qemumemlocktest \ @@ -647,6 +647,11 @@ qemublocktest_LDADD =3D \ $(qemu_LDADDS) \ $(NULL) +qemudomaincheckpointxml2xmltest_SOURCES =3D \ + qemudomaincheckpointxml2xmltest.c testutilsqemu.c testutilsqemu.h \ + testutils.c testutils.h +qemudomaincheckpointxml2xmltest_LDADD =3D $(qemu_LDADDS) + qemudomainsnapshotxml2xmltest_SOURCES =3D \ qemudomainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h @@ -682,7 +687,7 @@ qemufirmwaretest_LDADD =3D $(qemu_LDADDS) else ! WITH_QEMU EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c \ - qemudomainsnapshotxml2xmltest.c \ + qemudomaincheckpointxml2xmltest.c qemudomainsnapshotxml2xmltest.c \ testutilsqemu.c testutilsqemu.h \ testutilsqemuschema.c testutilsqemuschema.h \ qemumonitorjsontest.c qemuhotplugtest.c \ diff --git a/tests/qemudomaincheckpointxml2xmlout/internal-active-invalid.x= ml b/tests/qemudomaincheckpointxml2xmlout/internal-active-invalid.xml new file mode 100644 index 0000000000..a518c58915 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/internal-active-invalid.xml @@ -0,0 +1,53 @@ + + 1525889631 + Completion of updates after OS install + + 1525111885 + + 1525889631 + + + + + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
        + + + + + +
        + + +
        + + +
        + + + + + + + + 1 + diff --git a/tests/qemudomaincheckpointxml2xmlout/internal-inactive-invalid= .xml b/tests/qemudomaincheckpointxml2xmlout/internal-inactive-invalid.xml new file mode 100644 index 0000000000..df14c97836 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmlout/internal-inactive-invalid.xml @@ -0,0 +1,53 @@ + + 1525889631 + Completion of updates after OS install + + 1525111885 + + 1525889631 + + + + + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + + +
        + + + + + +
        + + +
        + + +
        + + + + + + + + 0 + diff --git a/tests/qemudomaincheckpointxml2xmltest.c b/tests/qemudomainchec= kpointxml2xmltest.c new file mode 100644 index 0000000000..8a7c0922c7 --- /dev/null +++ b/tests/qemudomaincheckpointxml2xmltest.c @@ -0,0 +1,213 @@ +#include + +#include +#include +#include +#include + +#include +#include + +#include "testutils.h" + +#ifdef WITH_QEMU + +# include "internal.h" +# include "qemu/qemu_conf.h" +# include "qemu/qemu_domain.h" +# include "checkpoint_conf.h" +# include "testutilsqemu.h" +# include "virstring.h" + +# define VIR_FROM_THIS VIR_FROM_NONE + +static virQEMUDriver driver; + +enum { + TEST_REDEFINE =3D 1 << 0, /* Test use of REDEFINE parse flag */ + TEST_PARENT =3D 1 << 1, /* hard-code parent after parse */ + TEST_VDA_BITMAP =3D 1 << 2, /* hard-code disk vda after parse */ + TEST_SIZE =3D 1 << 3, /* Test use of SIZE format flag */ + TEST_INVALID =3D 1 << 4, /* Test that input fails parse */ +}; + +static int +testCompareXMLToXMLFiles(const char *inxml, + const char *outxml, + unsigned int flags) +{ + unsigned int parseflags =3D 0; + unsigned int formatflags =3D VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE; + VIR_AUTOFREE(char *) inXmlData =3D NULL; + VIR_AUTOFREE(char *) outXmlData =3D NULL; + VIR_AUTOFREE(char *) actual =3D NULL; + VIR_AUTOUNREF(virDomainCheckpointDefPtr) def =3D NULL; + + if (flags & TEST_REDEFINE) + parseflags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + + if (virTestLoadFile(inxml, &inXmlData) < 0) + return -1; + + if (!(flags & TEST_INVALID) && + virTestLoadFile(outxml, &outXmlData) < 0) + return -1; + + if (!(def =3D virDomainCheckpointDefParseString(inXmlData, driver.caps, + driver.xmlopt, + parseflags))) { + if (flags & TEST_INVALID) + return 0; + return -1; + } + if (flags & TEST_PARENT) { + if (def->parent.parent_name) + return -1; + if (VIR_STRDUP(def->parent.parent_name, "1525111885") < 0) + return -1; + } + if (flags & TEST_VDA_BITMAP) { + virDomainCheckpointDiskDefPtr disk; + + if (VIR_EXPAND_N(def->disks, def->ndisks, 1) < 0) + return -1; + disk =3D &def->disks[0]; + if (disk->bitmap) + return -1; + if (!disk->name) { + disk->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + if (VIR_STRDUP(disk->name, "vda") < 0) + return -1; + } else if (STRNEQ(disk->name, "vda")) { + return -1; + } + if (VIR_STRDUP(disk->bitmap, def->parent.name) < 0) + return -1; + } + if (flags & TEST_SIZE) { + def->disks[0].size =3D 1048576; + formatflags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_SIZE; + } + + /* Parsing XML does not populate the domain definition; work + * around that by not requesting domain on output */ + if (!def->parent.dom) + formatflags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN; + + if (!(actual =3D virDomainCheckpointDefFormat(def, driver.caps, + driver.xmlopt, + formatflags))) + return -1; + + if (STRNEQ(outXmlData, actual)) { + virTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); + return -1; + } + + return 0; +} + +struct testInfo { + const char *inxml; + const char *outxml; + long long creationTime; + unsigned int flags; +}; +static long long mocktime; + +static int +testCheckpointPostParse(virDomainMomentDefPtr def) +{ + if (!mocktime) + return 0; + if (def->creationTime) + return -1; + def->creationTime =3D mocktime; + if (!def->name && + virAsprintf(&def->name, "%lld", def->creationTime) < 0) + return -1; + return 0; +} + +static int +testCompareXMLToXMLHelper(const void *data) +{ + const struct testInfo *info =3D data; + + mocktime =3D info->creationTime; + return testCompareXMLToXMLFiles(info->inxml, info->outxml, info->flags= ); +} + + +static int +mymain(void) +{ + int ret =3D 0; + + if (qemuTestDriverInit(&driver) < 0) + return EXIT_FAILURE; + + virDomainXMLOptionSetMomentPostParse(driver.xmlopt, + testCheckpointPostParse); + +# define DO_TEST(prefix, name, inpath, outpath, time, flags) \ + do { \ + const struct testInfo info =3D {abs_srcdir "/" inpath "/" name ".x= ml", \ + abs_srcdir "/" outpath "/" name ".xm= l", \ + time, flags}; \ + if (virTestRun("CHECKPOINT XML-2-XML " prefix " " name, \ + testCompareXMLToXMLHelper, &info) < 0) \ + ret =3D -1; \ + } while (0) + +# define DO_TEST_INOUT(name, time, flags) \ + DO_TEST("in->out", name, \ + "qemudomaincheckpointxml2xmlin", \ + "qemudomaincheckpointxml2xmlout", \ + time, flags) +# define DO_TEST_OUT(name, flags) \ + DO_TEST("out->out", name, \ + "qemudomaincheckpointxml2xmlout", \ + "qemudomaincheckpointxml2xmlout", \ + 0, flags | TEST_REDEFINE) +# define DO_TEST_INVALID(name) \ + DO_TEST("in->out", name, \ + "qemudomaincheckpointxml2xmlin", \ + "qemudomaincheckpointxml2xmlout", \ + 0, TEST_INVALID) + + /* Unset or set all envvars here that are copied in qemudBuildCommandL= ine + * using ADD_ENV_COPY, otherwise these tests may fail due to unexpected + * values for these envvars */ + setenv("PATH", "/bin", 1); + + /* Test a normal user redefine */ + DO_TEST_OUT("redefine", 0); + + /* Tests of valid user input, and resulting output */ + DO_TEST_INOUT("empty", 1525889631, TEST_VDA_BITMAP); + DO_TEST_INOUT("disk-default", 1525889631, TEST_PARENT | TEST_VDA_BITMA= P); + DO_TEST_INOUT("sample", 1525889631, TEST_PARENT | TEST_VDA_BITMAP); + DO_TEST_INOUT("size", 1553648510, + TEST_PARENT | TEST_VDA_BITMAP | TEST_SIZE); + + /* Tests of invalid user input */ + DO_TEST_INVALID("disk-invalid"); + DO_TEST_INVALID("name-invalid"); + + qemuTestDriverFree(&driver); + + return ret =3D=3D 0 ? EXIT_SUCCESS : EXIT_FAILURE; +} + +VIR_TEST_MAIN(mymain) + +#else + +int +main(void) +{ + return EXIT_AM_SKIP; +} + +#endif /* WITH_QEMU */ --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947803; cv=none; d=zoho.com; s=zohoarc; b=YFuRWx7ewUcbOCLIj49nxuvDoNWO9L/H38AwLZK05P3GsdTpy58jzKet/T3nCUT2Quo0HTQhEw6dUIAHrV5CCYR19W6xDpdRfRoQhun1DlqCmSVZ7lz6h8N1iO2qtHBvwoODe2oG4PyioeQ9oEgOlQdyR3TdtsNIP/17Zlje3H4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947803; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=b2Dk0Mc5y1PdYxeaj/+8o/KWqa+QN57E+cuASvijFOY=; b=n2+2pP9kej7yqPvIHMyUmqUDUVGxBKUYYPXHsoufVtvggRV+f6k31pLJqp93U4SbyuiHmwAmJNhG2NhXK+wS5a6rEOug+fh+lxz9gMZEL4yzHaTzOr3TL/gaR6wkyvxxcKVTtGc64yZ2zU/z8HgePRrOCMhfMCbtaeum2ugvEJo= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 15639478034481012.8395274407826; Tue, 23 Jul 2019 22:56:43 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 328EF7FDF8; Wed, 24 Jul 2019 05:56:42 +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 0C2765D71A; Wed, 24 Jul 2019 05:56:42 +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 C152F18045D2; Wed, 24 Jul 2019 05:56:41 +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 x6O5uRWh029173 for ; Wed, 24 Jul 2019 01:56:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id 20D8F60BFC; Wed, 24 Jul 2019 05:56:27 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9B78060BF3; Wed, 24 Jul 2019 05:56:26 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:55:59 -0500 Message-Id: <20190724055609.30691-10-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 09/19] backup: Allow for lists of checkpoint objects 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 24 Jul 2019 05:56:42 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Create a new file for managing a list of checkpoint objects, borrowing heavily from existing virDomainSnapshotObjList paradigms. Note that while snapshots definitely have a use case for multiple children to a single parent (create a base snapshot, create a child snapshot, revert to the base, then create another child snapshot), it's harder to predict how checkpoints will play out with reverting to prior points in time. Thus, in initial use, given a list of checkpoints, you never have more than one child, and we can treat the most-recent leaf node as the parent of the next node creation, without having to expose a notion of a current node in XML or public API. However, as the snapshot machinery is already generic, it is easier to reuse the generic machinery that tracks relations between domain moments than it is to open-code a new list-management scheme just for checkpoints (hence, we still have internal functions related to a current checkpoint, even though that has no observable effect externally). Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/conf/checkpoint_conf.h | 7 + src/conf/domain_conf.h | 2 + src/conf/virconftypes.h | 6 + src/conf/virdomaincheckpointobjlist.h | 72 ++++++++ src/conf/virdomainmomentobjlist.h | 1 + src/conf/virdomainobjlist.h | 7 +- src/conf/Makefile.inc.am | 2 + src/conf/checkpoint_conf.c | 62 +++++++ src/conf/domain_conf.c | 6 + src/conf/virdomaincheckpointobjlist.c | 243 ++++++++++++++++++++++++++ src/conf/virdomainmomentobjlist.c | 17 +- src/conf/virdomainobjlist.c | 11 ++ src/libvirt_private.syms | 19 ++ 13 files changed, 453 insertions(+), 2 deletions(-) create mode 100644 src/conf/virdomaincheckpointobjlist.h create mode 100644 src/conf/virdomaincheckpointobjlist.c diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h index 0fac521efe..018e9f53b1 100644 --- a/src/conf/checkpoint_conf.h +++ b/src/conf/checkpoint_conf.h @@ -81,4 +81,11 @@ char *virDomainCheckpointDefFormat(virDomainCheckpointDe= fPtr def, unsigned int flags); int virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr checkpoint); +int virDomainCheckpointRedefinePrep(virDomainPtr domain, + virDomainObjPtr vm, + virDomainCheckpointDefPtr *def, + virDomainMomentObjPtr *checkpoint, + virDomainXMLOptionPtr xmlopt, + bool *update_current); + VIR_ENUM_DECL(virDomainCheckpoint); diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 48b0af4b04..b7a553b249 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2562,6 +2562,8 @@ struct _virDomainObj { bool hasManagedSave; + virDomainCheckpointObjListPtr checkpoints; + void *privateData; void (*privateDataFreeFunc)(void *); diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index fe3f0af14f..e8e9b6c314 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -105,6 +105,12 @@ typedef virDomainBlockIoTuneInfo *virDomainBlockIoTune= InfoPtr; typedef struct _virDomainCheckpointDef virDomainCheckpointDef; typedef virDomainCheckpointDef *virDomainCheckpointDefPtr; +typedef struct _virDomainCheckpointObj virDomainCheckpointObj; +typedef virDomainCheckpointObj *virDomainCheckpointObjPtr; + +typedef struct _virDomainCheckpointObjList virDomainCheckpointObjList; +typedef virDomainCheckpointObjList *virDomainCheckpointObjListPtr; + typedef struct _virDomainChrDef virDomainChrDef; typedef virDomainChrDef *virDomainChrDefPtr; diff --git a/src/conf/virdomaincheckpointobjlist.h b/src/conf/virdomainchec= kpointobjlist.h new file mode 100644 index 0000000000..3a51a46e68 --- /dev/null +++ b/src/conf/virdomaincheckpointobjlist.h @@ -0,0 +1,72 @@ +/* + * virdomaincheckpointobjlist.h: handle a tree of checkpoint objects + * (derived from virdomainsnapshotobjlist.h) + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#pragma once + +#include "internal.h" +#include "virdomainmomentobjlist.h" +#include "virbuffer.h" + +virDomainCheckpointObjListPtr virDomainCheckpointObjListNew(void); +void virDomainCheckpointObjListFree(virDomainCheckpointObjListPtr checkpoi= nts); + +virDomainMomentObjPtr virDomainCheckpointAssignDef(virDomainCheckpointObjL= istPtr checkpoints, + virDomainCheckpointDefP= tr def); + +virDomainMomentObjPtr virDomainCheckpointFindByName(virDomainCheckpointObj= ListPtr checkpoints, + const char *name); +virDomainMomentObjPtr virDomainCheckpointGetCurrent(virDomainCheckpointObj= ListPtr checkpoints); +const char *virDomainCheckpointGetCurrentName(virDomainCheckpointObjListPt= r checkpoints); +void virDomainCheckpointSetCurrent(virDomainCheckpointObjListPtr checkpoin= ts, + virDomainMomentObjPtr checkpoint); +bool virDomainCheckpointObjListRemove(virDomainCheckpointObjListPtr checkp= oints, + virDomainMomentObjPtr checkpoint); +void virDomainCheckpointObjListRemoveAll(virDomainCheckpointObjListPtr che= ckpoints); +int virDomainCheckpointForEach(virDomainCheckpointObjListPtr checkpoints, + virHashIterator iter, + void *data); +void virDomainCheckpointLinkParent(virDomainCheckpointObjListPtr checkpoin= ts, + virDomainMomentObjPtr chk); +int virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr check= points, + virDomainMomentObjPtr *leaf); +int virDomainCheckpointCheckCycles(virDomainCheckpointObjListPtr checkpoin= ts, + virDomainCheckpointDefPtr def, + const char *domname); + +#define VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES \ + (VIR_DOMAIN_CHECKPOINT_LIST_LEAVES | \ + VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES) + +#define VIR_DOMAIN_CHECKPOINT_FILTERS_ALL \ + (VIR_DOMAIN_CHECKPOINT_FILTERS_LEAVES) + +int virDomainListCheckpoints(virDomainCheckpointObjListPtr checkpoints, + virDomainMomentObjPtr from, + virDomainPtr dom, + virDomainCheckpointPtr **objs, + unsigned int flags); + +static inline virDomainCheckpointDefPtr +virDomainCheckpointObjGetDef(virDomainMomentObjPtr obj) +{ + return (virDomainCheckpointDefPtr) obj->def; +} diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentob= jlist.h index 5b73175e8d..75198909ba 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -121,3 +121,4 @@ int virDomainMomentUpdateRelations(virDomainMomentObjLi= stPtr moments); int virDomainMomentCheckCycles(virDomainMomentObjListPtr list, virDomainMomentDefPtr def, const char *domname); +virDomainMomentObjPtr virDomainMomentFindLeaf(virDomainMomentObjListPtr li= st); diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index bf3ab396fa..7d71bc54d0 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -120,13 +120,18 @@ int virDomainObjListForEach(virDomainObjListPtr doms, (VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT | \ VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT) +#define VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT \ + (VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT | \ + VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT) + #define VIR_CONNECT_LIST_DOMAINS_FILTERS_ALL \ (VIR_CONNECT_LIST_DOMAINS_FILTERS_ACTIVE | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_PERSISTENT | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_STATE | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_MANAGEDSAVE | \ VIR_CONNECT_LIST_DOMAINS_FILTERS_AUTOSTART | \ - VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT) + VIR_CONNECT_LIST_DOMAINS_FILTERS_SNAPSHOT | \ + VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT) int virDomainObjListCollect(virDomainObjListPtr doms, virConnectPtr conn, diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index f656725e3a..5035b9b524 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -36,6 +36,8 @@ DOMAIN_CONF_SOURCES =3D \ conf/numa_conf.c \ conf/numa_conf.h \ conf/virconftypes.h \ + conf/virdomaincheckpointobjlist.c \ + conf/virdomaincheckpointobjlist.h \ conf/virdomainobjlist.c \ conf/virdomainobjlist.h \ conf/virdomainmomentobjlist.c \ diff --git a/src/conf/checkpoint_conf.c b/src/conf/checkpoint_conf.c index 69c9040a43..30c6d2e717 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -36,6 +36,7 @@ #include "virerror.h" #include "virxml.h" #include "virstring.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT @@ -533,3 +534,64 @@ virDomainCheckpointDefFormat(virDomainCheckpointDefPtr= def, return virBufferContentAndReset(&buf); } + + +int +virDomainCheckpointRedefinePrep(virDomainPtr domain, + virDomainObjPtr vm, + virDomainCheckpointDefPtr *defptr, + virDomainMomentObjPtr *chk, + virDomainXMLOptionPtr xmlopt, + bool *update_current) +{ + virDomainCheckpointDefPtr def =3D *defptr; + char uuidstr[VIR_UUID_STRING_BUFLEN]; + virDomainMomentObjPtr other =3D NULL; + virDomainCheckpointDefPtr otherdef =3D NULL; + + virUUIDFormat(domain->uuid, uuidstr); + + if (virDomainCheckpointCheckCycles(vm->checkpoints, def, vm->def->name= ) < 0) + return -1; + + if (!def->parent.dom || + memcmp(def->parent.dom->uuid, domain->uuid, VIR_UUID_BUFLEN)) { + virReportError(VIR_ERR_INVALID_ARG, + _("definition for checkpoint %s must use uuid %s"), + def->parent.name, uuidstr); + return -1; + } + if (virDomainCheckpointAlignDisks(def) < 0) + return -1; + + if (def->parent.parent_name) + other =3D virDomainCheckpointFindByName(vm->checkpoints, + def->parent.parent_name); + if (other =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints)) { + *update_current =3D true; + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + } + + other =3D virDomainCheckpointFindByName(vm->checkpoints, def->parent.n= ame); + if (other) { + otherdef =3D virDomainCheckpointObjGetDef(other); + if (!virDomainDefCheckABIStability(otherdef->parent.dom, + def->parent.dom, xmlopt)) + return -1; + + if (other =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints)) { + *update_current =3D true; + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + } + + /* Drop and rebuild the parent relationship, but keep all + * child relations by reusing chk. */ + virDomainMomentDropParent(other); + virObjectUnref(otherdef); + other->def =3D &(*defptr)->parent; + *defptr =3D NULL; + *chk =3D other; + } + + return 0; +} diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 0574c69a46..cc3bb4110f 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -29,6 +29,7 @@ #include "configmake.h" #include "internal.h" #include "virerror.h" +#include "checkpoint_conf.h" #include "datatypes.h" #include "domain_addr.h" #include "domain_conf.h" @@ -60,6 +61,7 @@ #include "virhostdev.h" #include "virmdev.h" #include "virdomainsnapshotobjlist.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -3486,6 +3488,7 @@ static void virDomainObjDispose(void *obj) (dom->privateDataFreeFunc)(dom->privateData); virDomainSnapshotObjListFree(dom->snapshots); + virDomainCheckpointObjListFree(dom->checkpoints); } virDomainObjPtr @@ -3515,6 +3518,9 @@ virDomainObjNew(virDomainXMLOptionPtr xmlopt) if (!(domain->snapshots =3D virDomainSnapshotObjListNew())) goto error; + if (!(domain->checkpoints =3D virDomainCheckpointObjListNew())) + goto error; + virObjectLock(domain); virDomainObjSetState(domain, VIR_DOMAIN_SHUTOFF, VIR_DOMAIN_SHUTOFF_UNKNOWN); diff --git a/src/conf/virdomaincheckpointobjlist.c b/src/conf/virdomainchec= kpointobjlist.c new file mode 100644 index 0000000000..03aad9f5ef --- /dev/null +++ b/src/conf/virdomaincheckpointobjlist.c @@ -0,0 +1,243 @@ +/* + * virdomaincheckpointobjlist.c: handle a tree of checkpoint objects + * (derived from virdomainsnapshotobjlist.c) + * + * Copyright (C) 2006-2019 Red Hat, Inc. + * Copyright (C) 2006-2008 Daniel P. Berrange + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + */ + +#include + +#include "internal.h" +#include "virdomaincheckpointobjlist.h" +#include "checkpoint_conf.h" +#include "virlog.h" +#include "virerror.h" +#include "datatypes.h" +#include "virstring.h" +#include "viralloc.h" + +#define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT + +VIR_LOG_INIT("conf.virdomaincheckpointobjlist"); + +struct _virDomainCheckpointObjList { + virDomainMomentObjListPtr base; +}; + +virDomainMomentObjPtr +virDomainCheckpointAssignDef(virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointDefPtr def) +{ + return virDomainMomentAssignDef(checkpoints->base, &def->parent); +} + + +static bool +virDomainCheckpointFilter(virDomainMomentObjPtr obj ATTRIBUTE_UNUSED, + unsigned int flags) +{ + /* For now, we have no further filters than what the common code handl= es. */ + virCheckFlags(0, false); + return true; +} + + +virDomainCheckpointObjListPtr +virDomainCheckpointObjListNew(void) +{ + virDomainCheckpointObjListPtr checkpoints; + + if (VIR_ALLOC(checkpoints) < 0) + return NULL; + checkpoints->base =3D virDomainMomentObjListNew(); + if (!checkpoints->base) { + VIR_FREE(checkpoints); + return NULL; + } + return checkpoints; +} + + +void +virDomainCheckpointObjListFree(virDomainCheckpointObjListPtr checkpoints) +{ + if (!checkpoints) + return; + virDomainMomentObjListFree(checkpoints->base); + VIR_FREE(checkpoints); +} + + +static int +virDomainCheckpointObjListGetNames(virDomainCheckpointObjListPtr checkpoin= ts, + virDomainMomentObjPtr from, + char **const names, + int maxnames, + unsigned int flags) +{ + /* We intentionally chose our public flags to match the common flags */ + verify(VIR_DOMAIN_CHECKPOINT_LIST_ROOTS =3D=3D + (int) VIR_DOMAIN_MOMENT_LIST_ROOTS); + verify(VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL =3D=3D + (int) VIR_DOMAIN_MOMENT_LIST_TOPOLOGICAL); + verify(VIR_DOMAIN_CHECKPOINT_LIST_LEAVES =3D=3D + (int) VIR_DOMAIN_MOMENT_LIST_LEAVES); + verify(VIR_DOMAIN_CHECKPOINT_LIST_NO_LEAVES =3D=3D + (int) VIR_DOMAIN_MOMENT_LIST_NO_LEAVES); + + return virDomainMomentObjListGetNames(checkpoints->base, from, names, + maxnames, flags, + virDomainCheckpointFilter, 0); +} + + +virDomainMomentObjPtr +virDomainCheckpointFindByName(virDomainCheckpointObjListPtr checkpoints, + const char *name) +{ + return virDomainMomentFindByName(checkpoints->base, name); +} + + +/* Return the current checkpoint, or NULL */ +virDomainMomentObjPtr +virDomainCheckpointGetCurrent(virDomainCheckpointObjListPtr checkpoints) +{ + return virDomainMomentGetCurrent(checkpoints->base); +} + + +/* Return the current checkpoint's name, or NULL */ +const char * +virDomainCheckpointGetCurrentName(virDomainCheckpointObjListPtr checkpoint= s) +{ + return virDomainMomentGetCurrentName(checkpoints->base); +} + + +/* Update the current checkpoint, using NULL if no current remains */ +void +virDomainCheckpointSetCurrent(virDomainCheckpointObjListPtr checkpoints, + virDomainMomentObjPtr checkpoint) +{ + virDomainMomentSetCurrent(checkpoints->base, checkpoint); +} + + +/* Remove checkpoint from the list; return true if it was current */ +bool +virDomainCheckpointObjListRemove(virDomainCheckpointObjListPtr checkpoints, + virDomainMomentObjPtr checkpoint) +{ + return virDomainMomentObjListRemove(checkpoints->base, checkpoint); +} + + +/* Remove all checkpoints tracked in the list */ +void +virDomainCheckpointObjListRemoveAll(virDomainCheckpointObjListPtr checkpoi= nts) +{ + return virDomainMomentObjListRemoveAll(checkpoints->base); +} + + +int +virDomainCheckpointForEach(virDomainCheckpointObjListPtr checkpoints, + virHashIterator iter, + void *data) +{ + return virDomainMomentForEach(checkpoints->base, iter, data); +} + + +/* Populate parent link of a given checkpoint. */ +void +virDomainCheckpointLinkParent(virDomainCheckpointObjListPtr checkpoints, + virDomainMomentObjPtr chk) +{ + return virDomainMomentLinkParent(checkpoints->base, chk); +} + + +/* Populate parent link and child count of all checkpoints, with all + * assigned defs having relations starting as 0/NULL. Return 0 on + * success, -1 if a parent is missing or if a circular relationship + * was requested. Set leaf to the end of the chain, if there is + * exactly one such leaf. */ +int +virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr checkpoin= ts, + virDomainMomentObjPtr *leaf) +{ + int ret =3D virDomainMomentUpdateRelations(checkpoints->base); + + if (ret =3D=3D 0) + *leaf =3D virDomainMomentFindLeaf(checkpoints->base); + return ret; +} + + +int +virDomainCheckpointCheckCycles(virDomainCheckpointObjListPtr checkpoints, + virDomainCheckpointDefPtr def, + const char *domname) +{ + return virDomainMomentCheckCycles(checkpoints->base, &def->parent, dom= name); +} + + +int +virDomainListCheckpoints(virDomainCheckpointObjListPtr checkpoints, + virDomainMomentObjPtr from, + virDomainPtr dom, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + int count =3D virDomainCheckpointObjListGetNames(checkpoints, from, NU= LL, + 0, flags); + virDomainCheckpointPtr *list =3D NULL; + char **names; + int ret =3D -1; + size_t i; + + if (!chks || count < 0) + return count; + if (VIR_ALLOC_N(names, count) < 0 || + VIR_ALLOC_N(list, count + 1) < 0) + goto cleanup; + + if (virDomainCheckpointObjListGetNames(checkpoints, from, names, count, + flags) < 0) + goto cleanup; + for (i =3D 0; i < count; i++) + if ((list[i] =3D virGetDomainCheckpoint(dom, names[i])) =3D=3D NUL= L) + goto cleanup; + + ret =3D count; + *chks =3D list; + + cleanup: + for (i =3D 0; i < count; i++) + VIR_FREE(names[i]); + VIR_FREE(names); + if (ret < 0 && list) { + for (i =3D 0; i < count; i++) + virObjectUnref(list[i]); + VIR_FREE(list); + } + return ret; +} diff --git a/src/conf/virdomainmomentobjlist.c b/src/conf/virdomainmomentob= jlist.c index c8dd8f8e01..d02efb420a 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -31,8 +31,8 @@ #include "viralloc.h" /* FIXME: using virObject would allow us to not need this */ -#include "snapshot_conf.h" #include "virdomainsnapshotobjlist.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -589,3 +589,18 @@ virDomainMomentCheckCycles(virDomainMomentObjListPtr l= ist, } return 0; } + +/* If there is exactly one leaf node, return that node. */ +virDomainMomentObjPtr +virDomainMomentFindLeaf(virDomainMomentObjListPtr list) +{ + virDomainMomentObjPtr moment =3D &list->metaroot; + + if (moment->nchildren !=3D 1) + return NULL; + while (moment->nchildren =3D=3D 1) + moment =3D moment->first_child; + if (moment->nchildren =3D=3D 0) + return moment; + return NULL; +} diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index d58d25f847..d640da6205 100644 --- a/src/conf/virdomainobjlist.c +++ b/src/conf/virdomainobjlist.c @@ -25,12 +25,14 @@ #include "internal.h" #include "datatypes.h" #include "virdomainobjlist.h" +#include "checkpoint_conf.h" #include "snapshot_conf.h" #include "viralloc.h" #include "virfile.h" #include "virlog.h" #include "virstring.h" #include "virdomainsnapshotobjlist.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -887,6 +889,15 @@ virDomainObjMatchFilter(virDomainObjPtr vm, return false; } + /* filter by checkpoint existence */ + if (MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT)) { + int nchk =3D virDomainListCheckpoints(vm->checkpoints, NULL, NULL, + NULL, 0); + if (!((MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT) && nchk > 0)= || + (MATCH(VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT) && nchk <=3D = 0))) + return false; + } + return true; } #undef MATCH diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 693c75b45d..3350cb963c 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -70,9 +70,12 @@ virCapabilitiesSetNetPrefix; # conf/checkpoint_conf.h +virDomainCheckpointAlignDisks; virDomainCheckpointDefFormat; virDomainCheckpointDefNew; virDomainCheckpointDefParseString; +virDomainCheckpointFormatConvertXMLFlags; +virDomainCheckpointRedefinePrep; virDomainCheckpointTypeFromString; virDomainCheckpointTypeToString; @@ -980,6 +983,22 @@ virChrdevFree; virChrdevOpen; +# conf/virdomaincheckpointobjlist.h +virDomainCheckpointAssignDef; +virDomainCheckpointFindByName; +virDomainCheckpointForEach; +virDomainCheckpointGetCurrent; +virDomainCheckpointGetCurrentName; +virDomainCheckpointLinkParent; +virDomainCheckpointObjListFree; +virDomainCheckpointObjListNew; +virDomainCheckpointObjListRemove; +virDomainCheckpointObjListRemoveAll; +virDomainCheckpointSetCurrent; +virDomainCheckpointUpdateRelations; +virDomainListCheckpoints; + + # conf/virdomainmomentobjlist.h virDomainMomentDropChildren; virDomainMomentDropParent; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947806; cv=none; d=zoho.com; s=zohoarc; b=Ct2iA3r69UKYf55lR00xPaAe6M7jDegILJl9PstVUwAHbzUuc1fAzupNs/pDj08urAg1ILaKaA0YLln5d181Ics6eXUr4jhLq3HvZqrL7HIJ2PhjMBImttk4KVfRjOPTNkPjYRx9LQ3oR/tEGLIfDfmnYRQYmGyfxe/q9K/XEwo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947806; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=7Sa6JPomAFhTLYoYBV6OcAxpKQ8xPNkRm0jNEABM9ZE=; b=ITY1jSwtg54oKuVfkr0rB/71kSbZrPgcgUZ1fprzF5iIwMxUTtdqPvSYSeAw+V+q/c+mxf875GwGAstml8fGqZZlE7DDNFR7gjouOmpSn+1KGiH4apIbLLX5/0Q8jaWvfRDfNIe9mLoQq2LSRUrX+UnuD6Qgsrc05gj4b3a2HCM= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947806383587.9018307309171; Tue, 23 Jul 2019 22:56:46 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 4973581DFC; Wed, 24 Jul 2019 05:56:45 +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 244FA17D28; Wed, 24 Jul 2019 05:56:45 +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 DE4E819733; Wed, 24 Jul 2019 05:56:44 +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 x6O5uRR5029180 for ; Wed, 24 Jul 2019 01:56:27 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3A4B60C18; Wed, 24 Jul 2019 05:56:27 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4359A60BEC; Wed, 24 Jul 2019 05:56:27 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:00 -0500 Message-Id: <20190724055609.30691-11-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 10/19] backup: Add new domain:checkpoint access control 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-Type: text/plain; charset="utf-8" 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 24 Jul 2019 05:56:45 +0000 (UTC) Creating a checkpoint does not modify guest-visible state, but does modify host resources. Rather than reuse existing domain:write, domain:block_write, or domain:snapshot access controls, it seems better to introduce a new access control specific to tasks related to checkpoints and incremental backups of guest disk state. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/access/viraccessperm.h | 6 ++++++ src/access/viraccessperm.c | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/access/viraccessperm.h b/src/access/viraccessperm.h index d4b9c69c1e..a42512d5e0 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -186,6 +186,12 @@ typedef enum { */ VIR_ACCESS_PERM_DOMAIN_MIGRATE, /* Host migration */ + /** + * @desc: Checkpoint domain + * @message: Checkpointing domain requires authorization + */ + VIR_ACCESS_PERM_DOMAIN_CHECKPOINT, /* Checkpoint disks */ + /** * @desc: Snapshot domain * @message: Snapshotting domain requires authorization diff --git a/src/access/viraccessperm.c b/src/access/viraccessperm.c index 74993e9f29..33db7752b6 100644 --- a/src/access/viraccessperm.c +++ b/src/access/viraccessperm.c @@ -39,7 +39,8 @@ VIR_ENUM_IMPL(virAccessPermDomain, "getattr", "read", "write", "read_secure", "start", "stop", "reset", "save", "delete", - "migrate", "snapshot", "suspend", "hibernate", "core_dump", = "pm_control", + "migrate", "checkpoint", "snapshot", "suspend", "hibernate", + "core_dump", "pm_control", "init_control", "inject_nmi", "send_input", "send_signal", "fs_trim", "fs_freeze", "block_read", "block_write", "mem_read", --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947805; cv=none; d=zoho.com; s=zohoarc; b=dHIRBWyQzmCb7u8Q6gSAysH15JHADsgKgz7HN2nM3Vp5UwsCcsAsa+p4NawLzBhBM7aDR7y4hQm/GBFYVuBD+yNMYa4jkYQ1ddDOn7kgUmpxk3UD6KGtiDdNLATJBecPRie4dXpb/sWj++bFIgf++yGdc2FAb4P4GukqgqX+xbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947805; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=Uapro9i2bqa2Lagdpcxx81BveMVOeCwZqY11GgyVAiA=; b=A5XT3RPFp4HwIk/qFFHEK8XeYRzp5qMhcUgbLUOo8AwyDJO2odtpTP1gpT/nrpbmB+dlSAxA2R0Qkl11q1iCYjjQvlyNItOi/wRNe9fSTl+h8bVCtcxtUfElzCwE5AGvzaJwmtRL2nLO+hXBuvqyH86b321Xs7fQKFxFJDY4+Ac= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947805894172.79522619878333; Tue, 23 Jul 2019 22:56:45 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id D0D9E88313; Wed, 24 Jul 2019 05:56:44 +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 AB39960C05; Wed, 24 Jul 2019 05:56:44 +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 75CF119732; Wed, 24 Jul 2019 05:56:44 +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 x6O5uURQ029198 for ; Wed, 24 Jul 2019 01:56:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id D24A160C18; Wed, 24 Jul 2019 05:56:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id E635360BEC; Wed, 24 Jul 2019 05:56:27 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:01 -0500 Message-Id: <20190724055609.30691-12-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 11/19] backup: Implement checkpoint APIs for remote driver 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-Type: text/plain; charset="utf-8" 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 24 Jul 2019 05:56:45 +0000 (UTC) The remote code generator had to be taught about the new virDomainCheckpointPtr type, at which point the remote driver code for checkpoints can be generated. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon_dispatch.c | 20 +++++ src/remote/remote_driver.c | 24 +++++- src/remote/remote_protocol.x | 123 +++++++++++++++++++++++++++- src/remote_protocol-structs | 69 ++++++++++++++++ src/rpc/gendispatch.pl | 32 ++++---- 5 files changed, 252 insertions(+), 16 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index 856c5e48e7..444c03a644 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -90,6 +90,7 @@ static virStorageVolPtr get_nonnull_storage_vol(virConnec= tPtr conn, remote_nonnu static virSecretPtr get_nonnull_secret(virConnectPtr conn, remote_nonnull_= secret secret); static virNWFilterPtr get_nonnull_nwfilter(virConnectPtr conn, remote_nonn= ull_nwfilter nwfilter); static virNWFilterBindingPtr get_nonnull_nwfilter_binding(virConnectPtr co= nn, remote_nonnull_nwfilter_binding binding); +static virDomainCheckpointPtr get_nonnull_domain_checkpoint(virDomainPtr d= om, remote_nonnull_domain_checkpoint checkpoint); static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr dom, = remote_nonnull_domain_snapshot snapshot); static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote= _nonnull_node_device dev); static int make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainPt= r dom_src) ATTRIBUTE_RETURN_CHECK; @@ -102,6 +103,7 @@ static int make_nonnull_node_device(remote_nonnull_node= _device *dev_dst, virNode static int make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecre= tPtr secret_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_nwfilter(remote_nonnull_nwfilter *net_dst, virNWFi= lterPtr nwfilter_src) ATTRIBUTE_RETURN_CHECK; static int make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding *= binding_dst, virNWFilterBindingPtr binding_src) ATTRIBUTE_RETURN_CHECK; +static int make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint= *checkpoint_dst, virDomainCheckpointPtr checkpoint_src) ATTRIBUTE_RETURN_C= HECK; static int make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *sn= apshot_dst, virDomainSnapshotPtr snapshot_src) ATTRIBUTE_RETURN_CHECK; static int @@ -7301,6 +7303,12 @@ get_nonnull_nwfilter_binding(virConnectPtr conn, rem= ote_nonnull_nwfilter_binding return virGetNWFilterBinding(conn, binding.portdev, binding.filtername= ); } +static virDomainCheckpointPtr +get_nonnull_domain_checkpoint(virDomainPtr dom, remote_nonnull_domain_chec= kpoint checkpoint) +{ + return virGetDomainCheckpoint(dom, checkpoint.name); +} + static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr dom, remote_nonnull_domain_snapsh= ot snapshot) { @@ -7421,6 +7429,18 @@ make_nonnull_nwfilter_binding(remote_nonnull_nwfilte= r_binding *binding_dst, virN return 0; } +static int +make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint *checkpoin= t_dst, virDomainCheckpointPtr checkpoint_src) +{ + if (VIR_STRDUP(checkpoint_dst->name, checkpoint_src->name) < 0) + return -1; + if (make_nonnull_domain(&checkpoint_dst->dom, checkpoint_src->domain) = < 0) { + VIR_FREE(checkpoint_dst->name); + return -1; + } + return 0; +} + static int make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst,= virDomainSnapshotPtr snapshot_src) { diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 925ada1cac..72c2336b7a 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -146,6 +146,7 @@ static virStoragePoolPtr get_nonnull_storage_pool(virCo= nnectPtr conn, remote_non static virStorageVolPtr get_nonnull_storage_vol(virConnectPtr conn, remote= _nonnull_storage_vol vol); static virNodeDevicePtr get_nonnull_node_device(virConnectPtr conn, remote= _nonnull_node_device dev); static virSecretPtr get_nonnull_secret(virConnectPtr conn, remote_nonnull_= secret secret); +static virDomainCheckpointPtr get_nonnull_domain_checkpoint(virDomainPtr d= omain, remote_nonnull_domain_checkpoint checkpoint); static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domai= n, remote_nonnull_domain_snapshot snapshot); static void make_nonnull_domain(remote_nonnull_domain *dom_dst, virDomainP= tr dom_src); static void make_nonnull_network(remote_nonnull_network *net_dst, virNetwo= rkPtr net_src); @@ -158,6 +159,7 @@ make_nonnull_node_device(remote_nonnull_node_device *de= v_dst, virNodeDevicePtr d static void make_nonnull_secret(remote_nonnull_secret *secret_dst, virSecr= etPtr secret_src); static void make_nonnull_nwfilter(remote_nonnull_nwfilter *nwfilter_dst, v= irNWFilterPtr nwfilter_src); static void make_nonnull_nwfilter_binding(remote_nonnull_nwfilter_binding = *binding_dst, virNWFilterBindingPtr binding_src); +static void make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoin= t *checkpoint_dst, virDomainCheckpointPtr checkpoint_src); static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *s= napshot_dst, virDomainSnapshotPtr snapshot_src); /*----------------------------------------------------------------------*/ @@ -8242,6 +8244,12 @@ get_nonnull_nwfilter_binding(virConnectPtr conn, rem= ote_nonnull_nwfilter_binding return virGetNWFilterBinding(conn, binding.portdev, binding.filtername= ); } +static virDomainCheckpointPtr +get_nonnull_domain_checkpoint(virDomainPtr domain, remote_nonnull_domain_c= heckpoint checkpoint) +{ + return virGetDomainCheckpoint(domain, checkpoint.name); +} + static virDomainSnapshotPtr get_nonnull_domain_snapshot(virDomainPtr domain, remote_nonnull_domain_sna= pshot snapshot) { @@ -8324,6 +8332,13 @@ make_nonnull_nwfilter_binding(remote_nonnull_nwfilte= r_binding *binding_dst, virN binding_dst->filtername =3D binding_src->filtername; } +static void +make_nonnull_domain_checkpoint(remote_nonnull_domain_checkpoint *checkpoin= t_dst, virDomainCheckpointPtr checkpoint_src) +{ + checkpoint_dst->name =3D checkpoint_src->name; + make_nonnull_domain(&checkpoint_dst->dom, checkpoint_src->domain); +} + static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapshot_dst,= virDomainSnapshotPtr snapshot_src) { @@ -8573,7 +8588,14 @@ static virHypervisorDriver hypervisor_driver =3D { .connectCompareHypervisorCPU =3D remoteConnectCompareHypervisorCPU, /*= 4.4.0 */ .connectBaselineHypervisorCPU =3D remoteConnectBaselineHypervisorCPU, = /* 4.4.0 */ .nodeGetSEVInfo =3D remoteNodeGetSEVInfo, /* 4.5.0 */ - .domainGetLaunchSecurityInfo =3D remoteDomainGetLaunchSecurityInfo /* = 4.5.0 */ + .domainGetLaunchSecurityInfo =3D remoteDomainGetLaunchSecurityInfo, /*= 4.5.0 */ + .domainCheckpointCreateXML =3D remoteDomainCheckpointCreateXML, /* 5.6= .0 */ + .domainCheckpointGetXMLDesc =3D remoteDomainCheckpointGetXMLDesc, /* 5= .6.0 */ + .domainListAllCheckpoints =3D remoteDomainListAllCheckpoints, /* 5.6.0= */ + .domainCheckpointListAllChildren =3D remoteDomainCheckpointListAllChil= dren, /* 5.6.0 */ + .domainCheckpointLookupByName =3D remoteDomainCheckpointLookupByName, = /* 5.6.0 */ + .domainCheckpointGetParent =3D remoteDomainCheckpointGetParent, /* 5.6= .0 */ + .domainCheckpointDelete =3D remoteDomainCheckpointDelete, /* 5.6.0 */ }; static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 2e45b5cef0..2f91bd1921 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -140,6 +140,9 @@ const REMOTE_AUTH_TYPE_LIST_MAX =3D 20; /* Upper limit on list of memory stats */ const REMOTE_DOMAIN_MEMORY_STATS_MAX =3D 1024; +/* Upper limit on lists of domain checkpoints. */ +const REMOTE_DOMAIN_CHECKPOINT_LIST_MAX =3D 16384; + /* Upper limit on lists of domain snapshots. */ const REMOTE_DOMAIN_SNAPSHOT_LIST_MAX =3D 16384; @@ -336,6 +339,12 @@ struct remote_nonnull_secret { remote_nonnull_string usageID; }; +/* A checkpoint which may not be NULL. */ +struct remote_nonnull_domain_checkpoint { + remote_nonnull_string name; + remote_nonnull_domain dom; +}; + /* A snapshot which may not be NULL. */ struct remote_nonnull_domain_snapshot { remote_nonnull_string name; @@ -3649,6 +3658,70 @@ struct remote_network_port_delete_args { unsigned int flags; }; +struct remote_domain_checkpoint_create_xml_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + unsigned int flags; +}; + +struct remote_domain_checkpoint_create_xml_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; + +struct remote_domain_checkpoint_get_xml_desc_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_get_xml_desc_ret { + remote_nonnull_string xml; +}; + +struct remote_domain_list_all_checkpoints_args { + remote_nonnull_domain dom; + int need_results; + unsigned int flags; +}; + +struct remote_domain_list_all_checkpoints_ret { /* insert@1 */ + remote_nonnull_domain_checkpoint checkpoints; + int ret; +}; + +struct remote_domain_checkpoint_list_all_children_args { + remote_nonnull_domain_checkpoint checkpoint; + int need_results; + unsigned int flags; +}; + +struct remote_domain_checkpoint_list_all_children_ret { /* insert@1 */ + remote_nonnull_domain_checkpoint checkpoints; + int ret; +}; + +struct remote_domain_checkpoint_lookup_by_name_args { + remote_nonnull_domain dom; + remote_nonnull_string name; + unsigned int flags; +}; + +struct remote_domain_checkpoint_lookup_by_name_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; + +struct remote_domain_checkpoint_get_parent_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_get_parent_ret { + remote_nonnull_domain_checkpoint parent; +}; + +struct remote_domain_checkpoint_delete_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; /*----- Protocol. -----*/ @@ -6463,5 +6536,53 @@ enum remote_procedure { * @generate: both * @acl: network_port:delete */ - REMOTE_PROC_NETWORK_PORT_DELETE =3D 410 + REMOTE_PROC_NETWORK_PORT_DELETE =3D 410, + + /** + * @generate: both + * @acl: domain:checkpoint + * @acl: domain:fs_freeze:VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_CREATE_XML =3D 411, + + /** + * @generate: both + * @acl: domain:read + * @acl: domain:read_secure:VIR_DOMAIN_CHECKPOINT_XML_SECURE + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_XML_DESC =3D 412, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_LIST_ALL_CHECKPOINTS =3D 413, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_LIST_ALL_CHILDREN =3D 414, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_LOOKUP_BY_NAME =3D 415, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_PARENT =3D 416, + + /** + * @generate: both + * @acl: domain:checkpoint + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 417 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 2398494520..a42b4a9671 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -50,6 +50,10 @@ struct remote_nonnull_secret { int usageType; remote_nonnull_string usageID; }; +struct remote_nonnull_domain_checkpoint { + remote_nonnull_string name; + remote_nonnull_domain dom; +}; struct remote_nonnull_domain_snapshot { remote_nonnull_string name; remote_nonnull_domain dom; @@ -3043,6 +3047,64 @@ struct remote_network_port_delete_args { remote_nonnull_network_port port; u_int flags; }; +struct remote_domain_checkpoint_create_xml_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + u_int flags; +}; +struct remote_domain_checkpoint_create_xml_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; +struct remote_domain_checkpoint_get_xml_desc_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_get_xml_desc_ret { + remote_nonnull_string xml; +}; +struct remote_domain_list_all_checkpoints_args { + remote_nonnull_domain dom; + int need_results; + u_int flags; +}; +struct remote_domain_list_all_checkpoints_ret { + struct { + u_int checkpoints_len; + remote_nonnull_domain_checkpoint * checkpoints_val; + } checkpoints; + int ret; +}; +struct remote_domain_checkpoint_list_all_children_args { + remote_nonnull_domain_checkpoint checkpoint; + int need_results; + u_int flags; +}; +struct remote_domain_checkpoint_list_all_children_ret { + struct { + u_int checkpoints_len; + remote_nonnull_domain_checkpoint * checkpoints_val; + } checkpoints; + int ret; +}; +struct remote_domain_checkpoint_lookup_by_name_args { + remote_nonnull_domain dom; + remote_nonnull_string name; + u_int flags; +}; +struct remote_domain_checkpoint_lookup_by_name_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; +struct remote_domain_checkpoint_get_parent_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_get_parent_ret { + remote_nonnull_domain_checkpoint parent; +}; +struct remote_domain_checkpoint_delete_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3454,4 +3516,11 @@ enum remote_procedure { REMOTE_PROC_NETWORK_PORT_SET_PARAMETERS =3D 408, REMOTE_PROC_NETWORK_PORT_GET_XML_DESC =3D 409, REMOTE_PROC_NETWORK_PORT_DELETE =3D 410, + REMOTE_PROC_DOMAIN_CHECKPOINT_CREATE_XML =3D 411, + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_XML_DESC =3D 412, + REMOTE_PROC_DOMAIN_LIST_ALL_CHECKPOINTS =3D 413, + REMOTE_PROC_DOMAIN_CHECKPOINT_LIST_ALL_CHILDREN =3D 414, + REMOTE_PROC_DOMAIN_CHECKPOINT_LOOKUP_BY_NAME =3D 415, + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_PARENT =3D 416, + REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 417, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index f683e711ce..4e548e14cd 100755 --- a/src/rpc/gendispatch.pl +++ b/src/rpc/gendispatch.pl @@ -58,6 +58,7 @@ sub fixup_name { $name =3D~ s/Nwfilter/NWFilter/; $name =3D~ s/Xml$/XML/; + $name =3D~ s/Xml2$/XML2/; $name =3D~ s/Uri$/URI/; $name =3D~ s/Uuid$/UUID/; $name =3D~ s/Id$/ID/; @@ -567,18 +568,20 @@ elsif ($mode eq "server") { push(@args_list, "$2"); push(@free_list, " virObjectUnref($2);"); - } elsif ($args_member =3D~ m/^remote_nonnull_domain_snapsh= ot (\S+);$/) { + } elsif ($args_member =3D~ m/^remote_nonnull_domain_(check= point|snapshot) (\S+);$/) { + my $type_name =3D name_to_TypeName($1); + push(@vars_list, "virDomainPtr dom =3D NULL"); - push(@vars_list, "virDomainSnapshotPtr snapshot =3D NU= LL"); + push(@vars_list, "virDomain${type_name}Ptr ${1} =3D NU= LL"); push(@getters_list, - " if (!(dom =3D get_nonnull_domain($conn, args= ->${1}.dom)))\n" . + " if (!(dom =3D get_nonnull_domain($conn, args= ->${2}.dom)))\n" . " goto cleanup;\n" . "\n" . - " if (!(snapshot =3D get_nonnull_domain_snapsh= ot(dom, args->${1})))\n" . + " if (!($1 =3D get_nonnull_domain_${1}(dom, ar= gs->$2)))\n" . " goto cleanup;\n"); - push(@args_list, "snapshot"); + push(@args_list, "$1"); push(@free_list, - " virObjectUnref(snapshot);\n" . + " virObjectUnref($1);\n" . " virObjectUnref(dom);"); } elsif ($args_member =3D~ m/^(?:(?:admin|remote)_string|r= emote_uuid) (\S+)<\S+>;/) { push(@args_list, $conn) if !@args_list; @@ -722,7 +725,7 @@ elsif ($mode eq "server") { if (!$modern_ret_as_list) { push(@ret_list, "ret->$3 =3D tmp.$3;"); } - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port= |storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)= >;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port= |storage_vol|storage_pool|domain_checkpoint|domain_snapshot|domain|server|c= lient) (\S+)<(\S+)>;/) { $modern_ret_struct_name =3D $1; $single_ret_list_error_msg_type =3D $1; $single_ret_list_name =3D $2; @@ -780,7 +783,7 @@ elsif ($mode eq "server") { $single_ret_var =3D $1; $single_ret_by_ref =3D 0; $single_ret_check =3D " =3D=3D NULL"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|interface|node_device|secret|nwfilt= er|nwfilter_binding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|interface|node_device|secret|nwfilt= er|nwfilter_binding|domain_checkpoint|domain_snapshot) (\S+);/) { my $type_name =3D name_to_TypeName($1); if ($call->{ProcName} eq "DomainCreateWithFlags") { @@ -1328,13 +1331,14 @@ elsif ($mode eq "client") { $priv_src =3D "dev->conn"; push(@args_list, "virNodeDevicePtr dev"); push(@setters_list, "args.name =3D dev->name;"); - } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter= _binding|domain_snapshot) (\S+);/) { + } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|network_port|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter= _binding|domain_checkpoint|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); if ($is_first_arg) { - if ($name eq "domain_snapshot") { + if ($name eq "domain_snapshot" || + $name eq "domain_checkpoint") { $priv_src =3D "$arg_name->domain->conn"; } elsif ($name eq "network_port") { $priv_src =3D "$arg_name->net->conn"; @@ -1523,7 +1527,7 @@ elsif ($mode eq "client") { } push(@ret_list, "memcpy(result->$3, ret.$3, sizeof= (result->$3));"); - } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port= |storage_vol|storage_pool|domain_snapshot|domain|server|client) (\S+)<(\S+)= >;/) { + } elsif ($ret_member =3D~ m/(?:admin|remote)_nonnull_(= secret|nwfilter|nwfilter_binding|node_device|interface|network|network_port= |storage_vol|storage_pool|domain_checkpoint|domain_snapshot|domain|server|c= lient) (\S+)<(\S+)>;/) { my $proc_name =3D name_to_TypeName($1); if ($structprefix eq "admin") { @@ -1576,7 +1580,7 @@ elsif ($mode eq "client") { push(@ret_list, "VIR_FREE(ret.$1);"); $single_ret_var =3D "char *rv =3D NULL"; $single_ret_type =3D "char *"; - } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|node_device|interface|secret|nwfilt= er|nwfilter_binding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|network_port|storage_pool|storage_vol|node_device|interface|secret|nwfilt= er|nwfilter_binding|domain_checkpoint|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -1590,7 +1594,7 @@ elsif ($mode eq "client") { $single_ret_var =3D "int rv =3D -1"; $single_ret_type =3D "int"; } else { - if ($name eq "domain_snapshot") { + if ($name =3D~ m/^domain_.*/) { my $dom =3D "$priv_src"; $dom =3D~ s/->conn//; push(@ret_list, "rv =3D get_nonnull_$name($dom= , ret.$arg_name);"); @@ -1934,7 +1938,7 @@ elsif ($mode eq "client") { print " }\n"; print "\n"; } elsif ($modern_ret_as_list) { - if ($modern_ret_struct_name =3D~ m/domain_snapshot|client/) { + if ($modern_ret_struct_name =3D~ m/domain_checkpoint|domain_sn= apshot|client/) { $priv_src =3D~ s/->conn//; } print " if (result) {\n"; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947806; cv=none; d=zoho.com; s=zohoarc; b=Y9Bty3Y5XG5H/9syWp4iXijmbAVd8wetWih1MquegsWHenTMeOvQ4v50fk7rEOicQtvxGQ7dCOrKoYOkSAAnqALSEE8ULQ2wI2SqcxqqnW4S0fa9VOiZdhaZucr1NOVOe1HiKoeWKFlvEKgCiXahO8UD3oRLJzrX3YYa5eHfCaU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947806; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=QjlRAAgyEHQJcKHgcBLan3nEQfiIjCBld4THOQjInn8=; b=VNMvB20lnfO7zIrWV08suEzpu94TdvPTY1LYSPUJYBqPei5E+iabwPha+0m4MH8/eOSHXF0yJPicjqUMAlAVUoWa0fc5G3cINz8bKiQcKzmF5tdSGXujNEyBp3L8n3dfSS0DZfpjN9oyr5BluQa/XVW70rf69DAiPwnUGB20qhI= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947806229279.66354895510653; Tue, 23 Jul 2019 22:56:46 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E45C32EED34; Wed, 24 Jul 2019 05:56:44 +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 BF31B182DB; Wed, 24 Jul 2019 05:56:44 +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 5CBE018045DB; Wed, 24 Jul 2019 05:56:44 +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 x6O5uhqC029383 for ; Wed, 24 Jul 2019 01:56:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id D896460C68; Wed, 24 Jul 2019 05:56:43 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 989AE60BF7; Wed, 24 Jul 2019 05:56:30 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:02 -0500 Message-Id: <20190724055609.30691-13-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 12/19] backup: Implement virsh support for checkpoints 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 24 Jul 2019 05:56:45 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a bunch of new virsh commands for managing checkpoints in isolation. More commands are needed for performing incremental backups, but these commands were easy to implement by modeling heavily after virsh-snapshot.c. There is no need for checkpoint-revert or checkpoint-current since those snapshot APIs have no checkpoint counterpart. Similarly, it is not necessary to change which checkpoint is current when redefining from XML, since checkpoints expose whether they are current in the public XML (rather than the way snapshots did it behind the scenese). checkpoint-list is a bit simpler, in part because we don't have to cater to back-compat to older API. checkpoint-info is a bit trickier, because it requires parsing XML (maybe we'll want virDomainCheckpointIsCurrent() as an API after all). Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- tools/virsh-checkpoint.h | 26 + tools/virsh-completer.h | 4 + tools/virsh-util.h | 3 + tools/virsh.h | 1 + po/POTFILES | 1 + tools/Makefile.am | 1 + tools/virsh-checkpoint.c | 1153 ++++++++++++++++++++++++++++++++++ tools/virsh-completer.c | 51 ++ tools/virsh-domain-monitor.c | 23 + tools/virsh-domain.c | 7 + tools/virsh-util.c | 11 + tools/virsh.c | 2 + tools/virsh.pod | 185 +++++- 13 files changed, 1461 insertions(+), 7 deletions(-) create mode 100644 tools/virsh-checkpoint.h create mode 100644 tools/virsh-checkpoint.c diff --git a/tools/virsh-checkpoint.h b/tools/virsh-checkpoint.h new file mode 100644 index 0000000000..7cc998638f --- /dev/null +++ b/tools/virsh-checkpoint.h @@ -0,0 +1,26 @@ +/* + * virsh-checkpoint.h: Commands to manage domain checkpoints + * + * Copyright (C) 2005-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 + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + */ + +#pragma once + +#include "virsh.h" + +extern const vshCmdDef checkpointCmds[]; diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index cb7aafcc8c..2e54dddc05 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -78,6 +78,10 @@ char ** virshSecretUUIDCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); +char ** virshCheckpointNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags); + char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, unsigned int flags); diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 55520302ff..9005aa9d36 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -42,6 +42,9 @@ virshCommandOptDomain(vshControl *ctl, void virshDomainFree(virDomainPtr dom); +void +virshDomainCheckpointFree(virDomainCheckpointPtr chk); + void virshDomainSnapshotFree(virDomainSnapshotPtr snap); diff --git a/tools/virsh.h b/tools/virsh.h index 847ed25151..b4e610b2a4 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -40,6 +40,7 @@ /* * Command group types */ +#define VIRSH_CMD_GRP_CHECKPOINT "Checkpoint" #define VIRSH_CMD_GRP_DOM_MANAGEMENT "Domain Management" #define VIRSH_CMD_GRP_DOM_MONITORING "Domain Monitoring" #define VIRSH_CMD_GRP_STORAGE_POOL "Storage Pool" diff --git a/po/POTFILES b/po/POTFILES index 2c27049d55..c62bc32bb2 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -296,6 +296,7 @@ src/xenconfig/xen_xl.c src/xenconfig/xen_xm.c tests/virpolkittest.c tools/libvirt-guests.sh.in +tools/virsh-checkpoint.c tools/virsh-console.c tools/virsh-domain-monitor.c tools/virsh-domain.c diff --git a/tools/Makefile.am b/tools/Makefile.am index c6064dee08..2807b9f6fd 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -216,6 +216,7 @@ virt_login_shell_CFLAGS =3D \ virsh_SOURCES =3D \ virsh.c virsh.h \ + virsh-checkpoint.c virsh-checkpoint.h \ virsh-completer.c virsh-completer.h \ virsh-console.c virsh-console.h \ virsh-domain.c virsh-domain.h \ diff --git a/tools/virsh-checkpoint.c b/tools/virsh-checkpoint.c new file mode 100644 index 0000000000..f6401f2cf0 --- /dev/null +++ b/tools/virsh-checkpoint.c @@ -0,0 +1,1153 @@ +/* + * virsh-checkpoint.c: Commands to manage domain checkpoints + * + * Copyright (C) 2005-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 + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see + * . + * + * Daniel Veillard + * Karel Zak + * Daniel P. Berrange + * + */ + +#include +#include "virsh-checkpoint.h" + +#include + +#include +#include +#include +#include + +#include "internal.h" +#include "virbuffer.h" +#include "viralloc.h" +#include "virfile.h" +#include "virsh-util.h" +#include "virstring.h" +#include "virxml.h" +#include "conf/checkpoint_conf.h" +#include "vsh-table.h" + +/* Helper for checkpoint-create and checkpoint-create-as */ +static bool +virshCheckpointCreate(vshControl *ctl, + virDomainPtr dom, + const char *buffer, + unsigned int flags, + const char *from) +{ + bool ret =3D false; + virDomainCheckpointPtr checkpoint; + const char *name =3D NULL; + + checkpoint =3D virDomainCheckpointCreateXML(dom, buffer, flags); + + if (checkpoint =3D=3D NULL) + goto cleanup; + + name =3D virDomainCheckpointGetName(checkpoint); + if (!name) { + vshError(ctl, "%s", _("Could not get checkpoint name")); + goto cleanup; + } + + if (from) + vshPrintExtra(ctl, _("Domain checkpoint %s created from '%s'"), + name, from); + else + vshPrintExtra(ctl, _("Domain checkpoint %s created"), name); + + ret =3D true; + + cleanup: + virshDomainCheckpointFree(checkpoint); + return ret; +} + + +/* + * "checkpoint-create" command + */ +static const vshCmdInfo info_checkpoint_create[] =3D { + {.name =3D "help", + .data =3D N_("Create a checkpoint from XML") + }, + {.name =3D "desc", + .data =3D N_("Create a checkpoint from XML for use in " + "future incremental backups") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_create[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "xmlfile", + .type =3D VSH_OT_STRING, + .help =3D N_("domain checkpoint XML") + }, + {.name =3D "redefine", + .type =3D VSH_OT_BOOL, + .help =3D N_("redefine metadata for existing checkpoint") + }, + {.name =3D "quiesce", + .type =3D VSH_OT_BOOL, + .help =3D N_("quiesce guest's file systems") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointCreate(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *from =3D NULL; + char *buffer =3D NULL; + unsigned int flags =3D 0; + + if (vshCommandOptBool(cmd, "redefine")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &from) < 0) + goto cleanup; + if (!from) { + buffer =3D vshStrdup(ctl, ""); + } else { + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + ret =3D virshCheckpointCreate(ctl, dom, buffer, flags, from); + + cleanup: + VIR_FREE(buffer); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-create-as" command + */ +static int +virshParseCheckpointDiskspec(vshControl *ctl, + virBufferPtr buf, + const char *str) +{ + int ret =3D -1; + const char *name =3D NULL; + const char *checkpoint =3D NULL; + const char *bitmap =3D NULL; + char **array =3D NULL; + int narray; + size_t i; + + narray =3D vshStringToArray(str, &array); + if (narray <=3D 0) + goto cleanup; + + name =3D array[0]; + for (i =3D 1; i < narray; i++) { + if (!checkpoint && STRPREFIX(array[i], "checkpoint=3D")) + checkpoint =3D array[i] + strlen("checkpoint=3D"); + else if (!bitmap && STRPREFIX(array[i], "bitmap=3D")) + bitmap =3D array[i] + strlen("bitmap=3D"); + else + goto cleanup; + } + + virBufferEscapeString(buf, "\n"); + ret =3D 0; + cleanup: + if (ret < 0) + vshError(ctl, _("unable to parse diskspec: %s"), str); + virStringListFree(array); + return ret; +} + +static const vshCmdInfo info_checkpoint_create_as[] =3D { + {.name =3D "help", + .data =3D N_("Create a checkpoint from a set of args") + }, + {.name =3D "desc", + .data =3D N_("Create a checkpoint from arguments for use in " + "future incremental backups") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_create_as[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "name", + .type =3D VSH_OT_STRING, + .help =3D N_("name of checkpoint") + }, + {.name =3D "description", + .type =3D VSH_OT_STRING, + .help =3D N_("description of checkpoint") + }, + {.name =3D "print-xml", + .type =3D VSH_OT_BOOL, + .help =3D N_("print XML document rather than create") + }, + {.name =3D "quiesce", + .type =3D VSH_OT_BOOL, + .help =3D N_("quiesce guest's file systems") + }, + {.name =3D "diskspec", + .type =3D VSH_OT_ARGV, + .help =3D N_("disk attributes: disk[,checkpoint=3Dtype][,bitmap=3Dnam= e]") + }, + {.name =3D NULL} +}; + + +static bool +cmdCheckpointCreateAs(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + char *buffer =3D NULL; + const char *name =3D NULL; + const char *desc =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + unsigned int flags =3D 0; + const vshCmdOpt *opt =3D NULL; + + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "name", &name) < 0 || + vshCommandOptStringReq(ctl, cmd, "description", &desc) < 0) + goto cleanup; + + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + virBufferEscapeString(&buf, "%s\n", name); + virBufferEscapeString(&buf, "%s\n", desc); + + if (vshCommandOptBool(cmd, "diskspec")) { + virBufferAddLit(&buf, "\n"); + virBufferAdjustIndent(&buf, 2); + while ((opt =3D vshCommandOptArgv(ctl, cmd, opt))) { + if (virshParseCheckpointDiskspec(ctl, &buf, opt->data) < 0) + goto cleanup; + } + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + } + virBufferAdjustIndent(&buf, -2); + virBufferAddLit(&buf, "\n"); + + if (virBufferError(&buf)) { + vshError(ctl, "%s", _("Out of memory")); + goto cleanup; + } + + buffer =3D virBufferContentAndReset(&buf); + + if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s\n", buffer); + ret =3D true; + goto cleanup; + } + + ret =3D virshCheckpointCreate(ctl, dom, buffer, flags, NULL); + + cleanup: + virBufferFreeAndReset(&buf); + VIR_FREE(buffer); + virshDomainFree(dom); + + return ret; +} + + +/* Helper for resolving --ARG name into a checkpoint + * belonging to DOM. On success, populate *CHK and *NAME, before + * returning 0. On failure, return -1 after issuing an error + * message. */ +static int +virshLookupCheckpoint(vshControl *ctl, + const vshCmd *cmd, + const char *arg, + virDomainPtr dom, + virDomainCheckpointPtr *chk, + const char **name) +{ + const char *chkname =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, arg, &chkname) < 0) + return -1; + + if (chkname) { + *chk =3D virDomainCheckpointLookupByName(dom, chkname, 0); + } else { + vshError(ctl, _("--%s is required"), arg); + return -1; + } + if (!*chk) { + vshReportError(ctl); + return -1; + } + + *name =3D virDomainCheckpointGetName(*chk); + return 0; +} + + +/* + * "checkpoint-edit" command + */ +static const vshCmdInfo info_checkpoint_edit[] =3D { + {.name =3D "help", + .data =3D N_("edit XML for a checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Edit the domain checkpoint XML for a named checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_edit[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointEdit(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + virDomainCheckpointPtr edited =3D NULL; + const char *name =3D NULL; + const char *edited_name; + bool ret =3D false; + unsigned int getxml_flags =3D VIR_DOMAIN_CHECKPOINT_XML_SECURE; + unsigned int define_flags =3D VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", dom, + &checkpoint, &name) < 0) + goto cleanup; + +#define EDIT_GET_XML \ + virDomainCheckpointGetXMLDesc(checkpoint, getxml_flags) +#define EDIT_NOT_CHANGED \ + do { \ + vshPrintExtra(ctl, \ + _("Checkpoint %s XML configuration not changed.\n"),= \ + name); \ + ret =3D true; \ + goto edit_cleanup; \ + } while (0) +#define EDIT_DEFINE \ + edited =3D virDomainCheckpointCreateXML(dom, doc_edited, define_flags) +#include "virsh-edit.c" + + edited_name =3D virDomainCheckpointGetName(edited); + if (STREQ(name, edited_name)) { + vshPrintExtra(ctl, _("Checkpoint %s edited.\n"), name); + } else { + unsigned int delete_flags =3D VIR_DOMAIN_CHECKPOINT_DELETE_METADAT= A_ONLY; + + if (virDomainCheckpointDelete(edited, delete_flags) < 0) { + vshReportError(ctl); + vshError(ctl, _("Failed to clean up %s"), edited_name); + goto cleanup; + } + vshError(ctl, _("Cannot rename checkpoint %s to %s"), + name, edited_name); + goto cleanup; + } + + ret =3D true; + + cleanup: + if (!ret && name) + vshError(ctl, _("Failed to update %s"), name); + virshDomainCheckpointFree(edited); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + return ret; +} + + +/* Helper function to get the name of a checkpoint's parent. Caller + * must free the result. Returns 0 on success (including when it was + * proven no parent exists), and -1 on failure with error reported + * (such as no checkpoint support or domain deleted in meantime). */ +static int +virshGetCheckpointParent(vshControl *ctl, + virDomainCheckpointPtr checkpoint, + char **parent_name) +{ + virDomainCheckpointPtr parent =3D NULL; + int ret =3D -1; + + *parent_name =3D NULL; + + parent =3D virDomainCheckpointGetParent(checkpoint, 0); + if (parent) { + /* API works, and virDomainCheckpointGetName will succeed */ + *parent_name =3D vshStrdup(ctl, virDomainCheckpointGetName(parent)= ); + ret =3D 0; + } else if (last_error->code =3D=3D VIR_ERR_NO_DOMAIN_CHECKPOINT) { + /* API works, and we found a root with no parent */ + ret =3D 0; + } + + if (ret < 0) { + vshReportError(ctl); + vshError(ctl, "%s", _("unable to determine if checkpoint has paren= t")); + } else { + vshResetLibvirtError(); + } + virshDomainCheckpointFree(parent); + return ret; +} + + +/* + * "checkpoint-info" command + */ +static const vshCmdInfo info_checkpoint_info[] =3D { + {.name =3D "help", + .data =3D N_("checkpoint information") + }, + {.name =3D "desc", + .data =3D N_("Returns basic information about a checkpoint.") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_info[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D NULL} +}; + + +static bool +cmdCheckpointInfo(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom; + virDomainCheckpointPtr checkpoint =3D NULL; + const char *name; + char *parent =3D NULL; + char *xml =3D NULL; + xmlDocPtr xmldoc =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + bool ret =3D false; + int count; + unsigned int flags; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", dom, + &checkpoint, &name) < 0) + goto cleanup; + + vshPrint(ctl, "%-15s %s\n", _("Name:"), name); + vshPrint(ctl, "%-15s %s\n", _("Domain:"), virDomainGetName(dom)); + + if (virshGetCheckpointParent(ctl, checkpoint, &parent) < 0) { + vshError(ctl, "%s", + _("unexpected problem querying checkpoint state")); + goto cleanup; + } + vshPrint(ctl, "%-15s %s\n", _("Parent:"), parent ? parent : "-"); + + /* Children, Descendants. */ + flags =3D 0; + count =3D virDomainCheckpointListAllChildren(checkpoint, NULL, flags); + if (count < 0) { + if (last_error->code =3D=3D VIR_ERR_NO_SUPPORT) { + vshResetLibvirtError(); + ret =3D true; + } + goto cleanup; + } + vshPrint(ctl, "%-15s %d\n", _("Children:"), count); + flags =3D VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS; + count =3D virDomainCheckpointListAllChildren(checkpoint, NULL, flags); + if (count < 0) + goto cleanup; + vshPrint(ctl, "%-15s %d\n", _("Descendants:"), count); + + ret =3D true; + + cleanup: + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xmldoc); + VIR_FREE(xml); + VIR_FREE(parent); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + return ret; +} + + +/* Helpers for collecting a list of checkpoints. */ +struct virshChk { + virDomainCheckpointPtr chk; + char *parent; +}; +struct virshCheckpointList { + struct virshChk *chks; + int nchks; +}; +typedef struct virshCheckpointList *virshCheckpointListPtr; + +static void +virshCheckpointListFree(virshCheckpointListPtr checkpointlist) +{ + size_t i; + + if (!checkpointlist) + return; + if (checkpointlist->chks) { + for (i =3D 0; i < checkpointlist->nchks; i++) { + virshDomainCheckpointFree(checkpointlist->chks[i].chk); + VIR_FREE(checkpointlist->chks[i].parent); + } + VIR_FREE(checkpointlist->chks); + } + VIR_FREE(checkpointlist); +} + + +static int +virshChkSorter(const void *a, + const void *b) +{ + const struct virshChk *sa =3D a; + const struct virshChk *sb =3D b; + + if (sa->chk && !sb->chk) + return -1; + if (!sa->chk) + return sb->chk !=3D NULL; + + return vshStrcasecmp(virDomainCheckpointGetName(sa->chk), + virDomainCheckpointGetName(sb->chk)); +} + + +/* Compute a list of checkpoints from DOM. If FROM is provided, the + * list is limited to descendants of the given checkpoint. If FLAGS is + * given, the list is filtered. If TREE is specified, then all but + * FROM or the roots will also have parent information. */ +static virshCheckpointListPtr +virshCheckpointListCollect(vshControl *ctl, + virDomainPtr dom, + virDomainCheckpointPtr from, + unsigned int orig_flags, + bool tree) +{ + size_t i; + char **names =3D NULL; + int count =3D -1; + virDomainCheckpointPtr *chks; + virshCheckpointListPtr checkpointlist =3D vshMalloc(ctl, + sizeof(*checkpointli= st)); + virshCheckpointListPtr ret =3D NULL; + unsigned int flags =3D orig_flags; + + if (from) + count =3D virDomainCheckpointListAllChildren(from, &chks, flags); + else + count =3D virDomainListAllCheckpoints(dom, &chks, flags); + if (count < 0) { + vshError(ctl, "%s", + _("unexpected problem querying checkpoints")); + goto cleanup; + } + + /* When mixing --from and --tree, we also want a copy of from + * in the list, but with no parent for that one entry. */ + checkpointlist->chks =3D vshCalloc(ctl, count + (tree && from), + sizeof(*checkpointlist->chks)); + checkpointlist->nchks =3D count; + for (i =3D 0; i < count; i++) + checkpointlist->chks[i].chk =3D chks[i]; + VIR_FREE(chks); + if (tree) { + for (i =3D 0; i < count; i++) { + if (virshGetCheckpointParent(ctl, checkpointlist->chks[i].chk, + &checkpointlist->chks[i].parent) = < 0) + goto cleanup; + } + if (from) { + checkpointlist->chks[checkpointlist->nchks++].chk =3D from; + virDomainCheckpointRef(from); + } + } + + if (!(orig_flags & VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL)) + qsort(checkpointlist->chks, checkpointlist->nchks, + sizeof(*checkpointlist->chks), virshChkSorter); + + ret =3D checkpointlist; + checkpointlist =3D NULL; + + cleanup: + virshCheckpointListFree(checkpointlist); + if (names && count > 0) + for (i =3D 0; i < count; i++) + VIR_FREE(names[i]); + VIR_FREE(names); + return ret; +} + + +static const char * +virshCheckpointListLookup(int id, + bool parent, + void *opaque) +{ + virshCheckpointListPtr checkpointlist =3D opaque; + if (parent) + return checkpointlist->chks[id].parent; + return virDomainCheckpointGetName(checkpointlist->chks[id].chk); +} + + +/* + * "checkpoint-list" command + */ +static const vshCmdInfo info_checkpoint_list[] =3D { + {.name =3D "help", + .data =3D N_("List checkpoints for a domain") + }, + {.name =3D "desc", + .data =3D N_("Checkpoint List") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_list[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "parent", + .type =3D VSH_OT_BOOL, + .help =3D N_("add a column showing parent checkpoint") + }, + {.name =3D "roots", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints without parents") + }, + {.name =3D "leaves", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints without children") + }, + {.name =3D "no-leaves", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints that are not leaves (with childre= n)") + }, + {.name =3D "tree", + .type =3D VSH_OT_BOOL, + .help =3D N_("list checkpoints in a tree") + }, + {.name =3D "from", + .type =3D VSH_OT_STRING, + .help =3D N_("limit list to children of given checkpoint"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D "descendants", + .type =3D VSH_OT_BOOL, + .help =3D N_("with --from, list all descendants") + }, + {.name =3D "name", + .type =3D VSH_OT_BOOL, + .help =3D N_("list checkpoint names only") + }, + {.name =3D "topological", + .type =3D VSH_OT_BOOL, + .help =3D N_("sort list topologically rather than by name"), + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointList(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + unsigned int flags =3D 0; + size_t i; + xmlDocPtr xml =3D NULL; + xmlXPathContextPtr ctxt =3D NULL; + char *doc =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + long long creation_longlong; + time_t creation_time_t; + char timestr[100]; + struct tm time_info; + bool tree =3D vshCommandOptBool(cmd, "tree"); + bool name =3D vshCommandOptBool(cmd, "name"); + bool from =3D vshCommandOptBool(cmd, "from"); + bool parent =3D vshCommandOptBool(cmd, "parent"); + bool roots =3D vshCommandOptBool(cmd, "roots"); + const char *from_chk =3D NULL; + char *parent_chk =3D NULL; + virDomainCheckpointPtr start =3D NULL; + virshCheckpointListPtr checkpointlist =3D NULL; + vshTablePtr table =3D NULL; + + VSH_EXCLUSIVE_OPTIONS_VAR(tree, name); + VSH_EXCLUSIVE_OPTIONS_VAR(parent, roots); + VSH_EXCLUSIVE_OPTIONS_VAR(parent, tree); + VSH_EXCLUSIVE_OPTIONS_VAR(roots, tree); + VSH_EXCLUSIVE_OPTIONS_VAR(roots, from); + +#define FILTER(option, flag) \ + do { \ + if (vshCommandOptBool(cmd, option)) { \ + if (tree) { \ + vshError(ctl, \ + _("--%s and --tree are mutually exclusive"), \ + option); \ + return false; \ + } \ + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_ ## flag; \ + } \ + } while (0) + + FILTER("leaves", LEAVES); + FILTER("no-leaves", NO_LEAVES); +#undef FILTER + + if (vshCommandOptBool(cmd, "topological")) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL; + + if (roots) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_ROOTS; + + if (vshCommandOptBool(cmd, "descendants")) { + if (!from) { + vshError(ctl, "%s", + _("--descendants requires --from")); + return false; + } + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS; + } + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (from && + virshLookupCheckpoint(ctl, cmd, "from", dom, &start, &from_chk) < = 0) + goto cleanup; + + if (!(checkpointlist =3D virshCheckpointListCollect(ctl, dom, start, f= lags, + tree))) + goto cleanup; + + if (!tree && !name) { + if (parent) + table =3D vshTableNew(_("Name"), _("Creation Time"), _("Parent= "), + NULL); + else + table =3D vshTableNew(_("Name"), _("Creation Time"), NULL); + if (!table) + goto cleanup; + } + + if (tree) { + for (i =3D 0; i < checkpointlist->nchks; i++) { + if (!checkpointlist->chks[i].parent && + vshTreePrint(ctl, virshCheckpointListLookup, checkpointlis= t, + checkpointlist->nchks, i) < 0) + goto cleanup; + } + ret =3D true; + goto cleanup; + } + + for (i =3D 0; i < checkpointlist->nchks; i++) { + const char *chk_name; + + /* free up memory from previous iterations of the loop */ + VIR_FREE(parent_chk); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(doc); + + checkpoint =3D checkpointlist->chks[i].chk; + chk_name =3D virDomainCheckpointGetName(checkpoint); + assert(chk_name); + + if (name) { + /* just print the checkpoint name */ + vshPrint(ctl, "%s\n", chk_name); + continue; + } + + if (!(doc =3D virDomainCheckpointGetXMLDesc(checkpoint, 0))) + continue; + + if (!(xml =3D virXMLParseStringCtxt(doc, _("(domain_checkpoint)"),= &ctxt))) + continue; + + if (parent) + parent_chk =3D virXPathString("string(/domaincheckpoint/parent= /name)", + ctxt); + + if (virXPathLongLong("string(/domaincheckpoint/creationTime)", ctx= t, + &creation_longlong) < 0) + continue; + creation_time_t =3D creation_longlong; + if (creation_time_t !=3D creation_longlong) { + vshError(ctl, "%s", _("time_t overflow")); + continue; + } + localtime_r(&creation_time_t, &time_info); + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S %z", + &time_info); + + if (parent) { + if (vshTableRowAppend(table, chk_name, timestr, + NULLSTR_EMPTY(parent_chk), NULL) < 0) + goto cleanup; + } else { + if (vshTableRowAppend(table, chk_name, timestr, NULL) < 0) + goto cleanup; + } + } + + if (table) + vshTablePrintToStdout(table, ctl); + + ret =3D true; + + cleanup: + /* this frees up memory from the last iteration of the loop */ + virshCheckpointListFree(checkpointlist); + VIR_FREE(parent_chk); + virshDomainCheckpointFree(start); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(doc); + virshDomainFree(dom); + vshTableFree(table); + + return ret; +} + + +/* + * "checkpoint-dumpxml" command + */ +static const vshCmdInfo info_checkpoint_dumpxml[] =3D { + {.name =3D "help", + .data =3D N_("Dump XML for a domain checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Checkpoint Dump XML") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_dumpxml[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D "security-info", + .type =3D VSH_OT_BOOL, + .help =3D N_("include security sensitive information in XML dump") + }, + {.name =3D "no-domain", + .type =3D VSH_OT_BOOL, + .help =3D N_("exclude from XML") + }, + {.name =3D "size", + .type =3D VSH_OT_BOOL, + .help =3D N_("include backup size estimate in XML dump") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointDumpXML(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + char *xml =3D NULL; + unsigned int flags =3D 0; + + if (vshCommandOptBool(cmd, "security-info")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_SECURE; + if (vshCommandOptBool(cmd, "no-domain")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN; + if (vshCommandOptBool(cmd, "size")) + flags |=3D VIR_DOMAIN_CHECKPOINT_XML_SIZE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", dom, + &checkpoint, &name) < 0) + goto cleanup; + + if (!(xml =3D virDomainCheckpointGetXMLDesc(checkpoint, flags))) + goto cleanup; + + vshPrint(ctl, "%s", xml); + ret =3D true; + + cleanup: + VIR_FREE(xml); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-parent" command + */ +static const vshCmdInfo info_checkpoint_parent[] =3D { + {.name =3D "help", + .data =3D N_("Get the name of the parent of a checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Extract the checkpoint's parent, if any") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_parent[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("find parent of checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointParent(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + char *parent =3D NULL; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + goto cleanup; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", dom, + &checkpoint, &name) < 0) + goto cleanup; + + if (virshGetCheckpointParent(ctl, checkpoint, &parent) < 0) + goto cleanup; + if (!parent) { + vshError(ctl, _("checkpoint '%s' has no parent"), name); + goto cleanup; + } + + vshPrint(ctl, "%s", parent); + + ret =3D true; + + cleanup: + VIR_FREE(parent); + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +/* + * "checkpoint-delete" command + */ +static const vshCmdInfo info_checkpoint_delete[] =3D { + {.name =3D "help", + .data =3D N_("Delete a domain checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Checkpoint Delete") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_delete[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("checkpoint name"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D "children", + .type =3D VSH_OT_BOOL, + .help =3D N_("delete checkpoint and all children") + }, + {.name =3D "children-only", + .type =3D VSH_OT_BOOL, + .help =3D N_("delete children but not checkpoint") + }, + {.name =3D "metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("delete only libvirt metadata, leaving checkpoint conten= ts behind") + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointDelete(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *name =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + unsigned int flags =3D 0; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + goto cleanup; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", dom, + &checkpoint, &name) < 0) + goto cleanup; + + if (vshCommandOptBool(cmd, "children")) + flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN; + if (vshCommandOptBool(cmd, "children-only")) + flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY; + if (vshCommandOptBool(cmd, "metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY; + + if (virDomainCheckpointDelete(checkpoint, flags) =3D=3D 0) { + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) + vshPrintExtra(ctl, _("Domain checkpoint %s children deleted\n"= ), name); + else + vshPrintExtra(ctl, _("Domain checkpoint %s deleted\n"), name); + } else { + vshError(ctl, _("Failed to delete checkpoint %s"), name); + goto cleanup; + } + + ret =3D true; + + cleanup: + virshDomainCheckpointFree(checkpoint); + virshDomainFree(dom); + + return ret; +} + + +const vshCmdDef checkpointCmds[] =3D { + {.name =3D "checkpoint-create", + .handler =3D cmdCheckpointCreate, + .opts =3D opts_checkpoint_create, + .info =3D info_checkpoint_create, + .flags =3D 0 + }, + {.name =3D "checkpoint-create-as", + .handler =3D cmdCheckpointCreateAs, + .opts =3D opts_checkpoint_create_as, + .info =3D info_checkpoint_create_as, + .flags =3D 0 + }, + {.name =3D "checkpoint-delete", + .handler =3D cmdCheckpointDelete, + .opts =3D opts_checkpoint_delete, + .info =3D info_checkpoint_delete, + .flags =3D 0 + }, + {.name =3D "checkpoint-dumpxml", + .handler =3D cmdCheckpointDumpXML, + .opts =3D opts_checkpoint_dumpxml, + .info =3D info_checkpoint_dumpxml, + .flags =3D 0 + }, + {.name =3D "checkpoint-edit", + .handler =3D cmdCheckpointEdit, + .opts =3D opts_checkpoint_edit, + .info =3D info_checkpoint_edit, + .flags =3D 0 + }, + {.name =3D "checkpoint-info", + .handler =3D cmdCheckpointInfo, + .opts =3D opts_checkpoint_info, + .info =3D info_checkpoint_info, + .flags =3D 0 + }, + {.name =3D "checkpoint-list", + .handler =3D cmdCheckpointList, + .opts =3D opts_checkpoint_list, + .info =3D info_checkpoint_list, + .flags =3D 0 + }, + {.name =3D "checkpoint-parent", + .handler =3D cmdCheckpointParent, + .opts =3D opts_checkpoint_parent, + .info =3D info_checkpoint_parent, + .flags =3D 0 + }, + {.name =3D NULL} +}; diff --git a/tools/virsh-completer.c b/tools/virsh-completer.c index 37f946d4b6..4fa6b19225 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -693,6 +693,57 @@ virshSecretUUIDCompleter(vshControl *ctl, } +char ** +virshCheckpointNameCompleter(vshControl *ctl, + const vshCmd *cmd, + unsigned int flags) +{ + virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; + virDomainCheckpointPtr *checkpoints =3D NULL; + int ncheckpoints =3D 0; + size_t i =3D 0; + char **ret =3D NULL; + + virCheckFlags(0, NULL); + + if (!priv->conn || virConnectIsAlive(priv->conn) <=3D 0) + return NULL; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return NULL; + + if ((ncheckpoints =3D virDomainListAllCheckpoints(dom, &checkpoints, + flags)) < 0) + goto error; + + if (VIR_ALLOC_N(ret, ncheckpoints + 1) < 0) + goto error; + + for (i =3D 0; i < ncheckpoints; i++) { + const char *name =3D virDomainCheckpointGetName(checkpoints[i]); + + if (VIR_STRDUP(ret[i], name) < 0) + goto error; + + virshDomainCheckpointFree(checkpoints[i]); + } + VIR_FREE(checkpoints); + virshDomainFree(dom); + + return ret; + + error: + for (; i < ncheckpoints; i++) + virshDomainCheckpointFree(checkpoints[i]); + VIR_FREE(checkpoints); + for (i =3D 0; i < ncheckpoints; i++) + VIR_FREE(ret[i]); + VIR_FREE(ret); + virshDomainFree(dom); + return NULL; +} + char ** virshSnapshotNameCompleter(vshControl *ctl, const vshCmd *cmd, diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index e399195deb..0e2c4191d7 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1621,6 +1621,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int = flags) int autostart; int state; int nsnap; + int nchk; int mansave; virshControlPtr priv =3D ctl->privData; @@ -1788,6 +1789,17 @@ virshDomainListCollect(vshControl *ctl, unsigned int= flags) goto remove_entry; } + /* checkpoint filter */ + if (VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_FILTERS_CHECKPOINT)) { + if ((nchk =3D virDomainListAllCheckpoints(dom, NULL, 0)) < 0) { + vshError(ctl, "%s", _("Failed to get checkpoint count")); + goto cleanup; + } + if (!((VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT) && n= chk > 0) || + (VSH_MATCH(VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT) && nc= hk =3D=3D 0))) + goto remove_entry; + } + /* the domain matched all filters, it may stay */ continue; @@ -1849,6 +1861,14 @@ static const vshCmdOptDef opts_list[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("list domains without a snapshot") }, + {.name =3D "with-checkpoint", + .type =3D VSH_OT_BOOL, + .help =3D N_("list domains with existing checkpoint") + }, + {.name =3D "without-checkpoint", + .type =3D VSH_OT_BOOL, + .help =3D N_("list domains without a checkpoint") + }, {.name =3D "state-running", .type =3D VSH_OT_BOOL, .help =3D N_("list domains in running state") @@ -1948,6 +1968,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd) FILTER("with-snapshot", VIR_CONNECT_LIST_DOMAINS_HAS_SNAPSHOT); FILTER("without-snapshot", VIR_CONNECT_LIST_DOMAINS_NO_SNAPSHOT); + FILTER("with-checkpoint", VIR_CONNECT_LIST_DOMAINS_HAS_CHECKPOINT); + FILTER("without-checkpoint", VIR_CONNECT_LIST_DOMAINS_NO_CHECKPOINT); + FILTER("state-running", VIR_CONNECT_LIST_DOMAINS_RUNNING); FILTER("state-paused", VIR_CONNECT_LIST_DOMAINS_PAUSED); FILTER("state-shutoff", VIR_CONNECT_LIST_DOMAINS_SHUTOFF); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 2ad73959ec..e79dc75342 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3633,6 +3633,10 @@ static const vshCmdOptDef opts_undefine[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("remove all domain snapshot metadata (vm must be inactiv= e)") }, + {.name =3D "checkpoints-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("remove all domain checkpoint metadata (vm must be inact= ive)") + }, {.name =3D "nvram", .type =3D VSH_OT_BOOL, .help =3D N_("remove nvram file, if inactive") @@ -3662,6 +3666,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* User-requested actions. */ bool managed_save =3D vshCommandOptBool(cmd, "managed-save"); bool snapshots_metadata =3D vshCommandOptBool(cmd, "snapshots-metadata= "); + bool checkpoints_metadata =3D vshCommandOptBool(cmd, "checkpoints-meta= data"); bool wipe_storage =3D vshCommandOptBool(cmd, "wipe-storage"); bool remove_all_storage =3D vshCommandOptBool(cmd, "remove-all-storage= "); bool delete_snapshots =3D vshCommandOptBool(cmd, "delete-snapshots"); @@ -3716,6 +3721,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe =3D true; } + if (checkpoints_metadata) + flags |=3D VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA; if (nvram) flags |=3D VIR_DOMAIN_UNDEFINE_NVRAM; if (keep_nvram) diff --git a/tools/virsh-util.c b/tools/virsh-util.c index aa88397d61..933d1c825d 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -228,6 +228,17 @@ virshDomainFree(virDomainPtr dom) } +void +virshDomainCheckpointFree(virDomainCheckpointPtr chk) +{ + if (!chk) + return; + + vshSaveLibvirtHelperError(); + virDomainCheckpointFree(chk); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshDomainSnapshotFree(virDomainSnapshotPtr snap) { diff --git a/tools/virsh.c b/tools/virsh.c index b41304a888..0de41e33b8 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -50,6 +50,7 @@ #include "virstring.h" #include "virgettext.h" +#include "virsh-checkpoint.h" #include "virsh-console.h" #include "virsh-domain.h" #include "virsh-domain-monitor.h" @@ -832,6 +833,7 @@ static const vshCmdGrp cmdGroups[] =3D { {VIRSH_CMD_GRP_DOM_MANAGEMENT, "domain", domManagementCmds}, {VIRSH_CMD_GRP_DOM_MONITORING, "monitor", domMonitoringCmds}, {VIRSH_CMD_GRP_HOST_AND_HV, "host", hostAndHypervisorCmds}, + {VIRSH_CMD_GRP_CHECKPOINT, "checkpoint", checkpointCmds}, {VIRSH_CMD_GRP_IFACE, "interface", ifaceCmds}, {VIRSH_CMD_GRP_NWFILTER, "filter", nwfilterCmds}, {VIRSH_CMD_GRP_NETWORK, "network", networkCmds}, diff --git a/tools/virsh.pod b/tools/virsh.pod index 40c7b638f7..f58578e3b3 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -409,6 +409,7 @@ Inject NMI to the guest. [I<--with-managed-save>] [I<--without-managed-save>] [I<--autostart>] [I<--no-autostart>] [I<--with-snapshot>] [I<--without-snapshot>] + [I<--with-checkpoint>] [I<--without-checkpoint>] [I<--state-running>] [I<--state-paused>] [I<--state-shutoff>] [I<--state-other>] @@ -514,6 +515,11 @@ this feature disabled use I<--no-autostart>. Domains that have snapshot images can be listed using flag I<--with-snapsh= ot>, domains without a snapshot I<--without-snapshot>. +=3Ditem B + +Domains that have checkpoints can be listed using flag I<--with-checkpoint= >, +domains without a checkpoint I<--without-checkpoint>. + =3Dback When talking to older servers, this command is forced to use a series of A= PI @@ -809,7 +815,8 @@ can be restarted later. If I is transient, then the metadata of any snapshots will be lost once the guest stops running, but the snapshot contents still exist, and a new domain with the same name and UUID can restore the -snapshot metadata with B. +snapshot metadata with B. Similarly, the metadata of +any checkpoints will be lost, but can be restored with B. If I<--graceful> is specified, don't resort to extreme measures (e.g. SIGKILL) when the guest doesn't stop after a reasonable timeout; @@ -1574,7 +1581,7 @@ Convert a domain Id (or UUID) to domain name Rename a domain. This command changes current domain name to the new name specified in the second argument. -B: Domain must be inactive and without snapshots. +B: Domain must be inactive and without snapshots or checkpoints. =3Ditem B I [I<--reason>] @@ -2815,10 +2822,11 @@ services must be shutdown in the domain. The exact behavior of a domain when it shuts down is set by the I parameter in the domain's XML definition. -If I is transient, then the metadata of any snapshots will -be lost once the guest stops running, but the snapshot contents still -exist, and a new domain with the same name and UUID can restore the -snapshot metadata with B. +If I is transient, then the metadata of any snapshots and +checkpoints will be lost once the guest stops running, but the underlying +contents still exist, and a new domain with the same name and UUID can +restore the snapshot metadata with B, and the checkpoint +metadata with B. By default the hypervisor will try to pick a suitable shutdown method. To specify an alternative method, the I<--mode> parameter @@ -2895,7 +2903,7 @@ Output the device used for the TTY console of the dom= ain. If the information is not available the processes will provide an exit code of 1. =3Ditem B I [I<--managed-save>] [I<--snapshots-metadata>] -[I<--nvram>] [I<--keep-nvram>] +[I<--checkpoints-metadata>] [I<--nvram>] [I<--keep-nvram>] [ {I<--storage> B | I<--remove-all-storage> [I<--delete-storage-volume-snapshots>]} I<--wipe-storage>] @@ -2913,6 +2921,12 @@ domain. Without the flag, attempts to undefine an i= nactive domain with snapshot metadata will fail. If the domain is active, this flag is ignored. +The I<--checkpoints-metadata> flag guarantees that any checkpoints (see the +B command) are also cleaned up when undefining an inactive +domain. Without the flag, attempts to undefine an inactive domain with +checkpoint metadata will fail. If the domain is active, this flag is +ignored. + I<--nvram> and I<--keep-nvram> specify accordingly to delete or keep nvram (/domain/os/nvram/) file. If the domain has an nvram file and the flags are omitted, the undefine will fail. @@ -4890,6 +4904,163 @@ the data contents from that point in time. =3Dback +=3Dhead1 CHECKPOINT COMMANDS + +The following commands manipulate domain checkpoints. Checkpoints serve as +a point in time to identify which portions of a guest's disks have changed +after that time, making it possible to perform incremental and differential +backups. Checkpoints are identified with a unique name. See +L for documentation of the XML +format used to represent properties of checkpoints. + +=3Dover 4 + +=3Ditem B I [I] { I<--redefine> +| [I<--quiesce>]} + +Create a checkpoint for domain I with the properties specified +in I describing a top-level element. The +format of the input XML file will be validated against an internal RNG +schema (idential to using the L tool). If +I is completely omitted, then libvirt will create a +checkpoint with a name based on the current time. + +If I<--redefine> is specified, then all XML elements produced by +B are valid; this can be used to migrate +checkpoint hierarchy from one machine to another, to recreate +hierarchy for the case of a transient domain that goes away and is +later recreated with the same name and UUID, or to make slight +alterations in the checkpoint metadata (such as host-specific aspects +of the domain XML embedded in the checkpoint). When this flag is +supplied, the I argument is mandatory. + +If I<--quiesce> is specified, libvirt will try to use guest agent +to freeze and unfreeze domain's mounted file systems. However, +if domain has no guest agent, checkpoint creation will fail. + +Existence of checkpoint metadata will prevent attempts to B +a persistent domain. However, for transient domains, checkpoint +metadata is silently lost when the domain quits running (whether +by command such as B or by internal guest action). + +=3Ditem B I [I<--print-xml>] +[I] [I] [I<--quiesce>] [I<--diskspec>] B]... + +Create a checkpoint for domain I with the given and +; if either value is omitted, libvirt will choose a +value. If I<--print-xml> is specified, then XML appropriate for +I is output, rather than actually creating a +checkpoint. + +The I<--diskspec> option can be used to control which guest disks +participate in the checkpoint. This option can occur multiple times, +according to the number of elements in the domain xml. Each + is in the form B. A +literal I<--diskspec> must precede each B unless +all three of I, I, and I are also present. +For example, a diskspec of "vda,checkpoint=3Dbitmap,bitmap=3Dmap1" +results in the following XML: + + +If I<--quiesce> is specified, libvirt will try to use guest agent +to freeze and unfreeze domain's mounted file systems. However, +if domain has no guest agent, checkpoint creation will fail. + +=3Ditem B I I + +Edit the XML configuration file for I of a domain. + +This is equivalent to: + + virsh checkpoint-dumpxml dom name > checkpoint.xml + vi checkpoint.xml (or make changes with your other text editor) + virsh checkpoint-create dom checkpoint.xml --redefine + +except that it does some error checking, including that the edits +should not attempt to change the checkpoint name. + +The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment +variables, and defaults to C. + +=3Ditem B I I + +Output basic information about a named . + +=3Ditem B I [{I<--parent> | I<--roots> | +[{I<--tree> | I<--name>}]}] [I<--topological>] +[[I<--from>] B | [I<--descendants>]] +[I<--leaves>] [I<--no-leaves>] + +List all of the available checkpoints for the given domain, defaulting +to show columns for the checkpoint name and creation time. + +Normally, table form output is sorted by checkpoint 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 checkpoint. If I<--roots> is +specified, the list will be filtered to just checkpoints that have no +parents. If I<--tree> is specified, the output will be in a tree +format, listing just checkpoint names. These three options are +mutually exclusive. If I<--name> is specified only the checkpoint name +is printed. This option is mutually exclusive with I<--tree>. + +If I<--from> is provided, filter the list to checkpoints which are +children of the given B. When used in isolation or with +I<--parent>, the list is limited to direct children unless +I<--descendants> is also present. When used with I<--tree>, the use +of I<--descendants> is implied. This option is not compatible with +I<--roots>. Note that the starting point of I<--from> +is not included in the list unless the I<--tree> option is also +present. + +If I<--leaves> is specified, the list will be filtered to just +checkpoints that have no children. Likewise, if I<--no-leaves> is +specified, the list will be filtered to just checkpoints with +children. (Note that omitting both options does no filtering, while +providing both options will either produce the same list or error out +depending on whether the server recognizes the flags). Filtering +options are not compatible with I<--tree>. + +=3Ditem B I I +[I<--security-info>] [I<--no-domain>] [I<--size>] + +Output the checkpoint XML for the domain's checkpoint named +I. Using +I<--security-info> will also include security sensitive information. +Using I<--size> will add XML indicating the current size in bytes of +guest data that has changed since the checkpoint was created (although +remember that guest activity between a size check and actually +creating a backup can result in the backup needing slightly more +space). Using I<--no-domain> will omit the element from the +output for a more compact view. + +=3Ditem B I I + +Output the name of the parent checkpoint, if any, for the given +I. + +=3Ditem B I I +[I<--metadata>] [{I<--children> | I<--children-only>}] + +Delete the checkpoint for the domain named I. The +record of which portions of +the disk changed since the checkpoint are merged into the parent +checkpoint (if any). If I<--children> is passed, then delete this +checkpoint and any children of this checkpoint. If I<--children-only> +is passed, then delete any children of this checkpoint, but leave this +checkpoint intact. These two flags are mutually exclusive. + +If I<--metadata> is specified, then only delete the checkpoint +metadata maintained by libvirt, while leaving the checkpoint contents +intact for access by external tools; otherwise deleting a checkpoint +also removes the ability to perform an incremental backup from that +point in time. + +=3Dback + =3Dhead1 NWFILTER COMMANDS The following commands manipulate network filters. Network filters allow --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947818; cv=none; d=zoho.com; s=zohoarc; b=CiyEWfmlO0xPYmkjRST+OoAS2Wx7pAbOVU68HTM+ezjBPa6PjUHKi06/XW7/tmG4R01H7pEkkzvPTu2vQBQsFbQGyXWhX0x44QhDNTvomG6DwPEwnLf6OotF4mCWbVkgpRogEo7TotweFciY6ldoxNASe/7DbM6XbfT9J86sMKI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947818; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=aHviB3xE0Hpac7b4iM1V4jU1hXBcG26GXfav4ZIet/w=; b=OU99acyvGzl4Js3xpeFli6gPtKFYG2Gqr4aDpkBmoDrE71Q2mba65kw/MeHx1kA0aRnK6fzMSVZ9Q9kGTODsvHEua5T2+spORFpLXjW/Uc1mgfL3KrT6ldxzEKy6MHrS7+Ao2cu6lLIZpc/YnCPvUPV5wrVEvWIHwLTSxqd0ce0= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947818158561.8548117185254; Tue, 23 Jul 2019 22:56:58 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id E0283356D2; Wed, 24 Jul 2019 05:56:56 +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 B55C86061B; Wed, 24 Jul 2019 05:56:56 +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 66D1919738; Wed, 24 Jul 2019 05:56:56 +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 x6O5usgi029601 for ; Wed, 24 Jul 2019 01:56:54 -0400 Received: by smtp.corp.redhat.com (Postfix) id B3BA260C05; Wed, 24 Jul 2019 05:56:54 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1E9D660BEC; Wed, 24 Jul 2019 05:56:43 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:03 -0500 Message-Id: <20190724055609.30691-14-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 13/19] backup: test: Implement metadata tracking for checkpoint APIs 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 24 Jul 2019 05:56:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" A lot of this work heavily copies from the existing snapshot APIs. The test driver doesn't really have to do anything more than just expose an interface into libvirt metadata, making it possible to test saving and restoring XML, and tracking relations between multiple checkpoints. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/test/test_driver.c | 369 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 369 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d96dd638e7..abe51f252a 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -39,6 +39,7 @@ #include "viralloc.h" #include "virnetworkobj.h" #include "interface_conf.h" +#include "checkpoint_conf.h" #include "domain_conf.h" #include "domain_event.h" #include "network_event.h" @@ -63,6 +64,7 @@ #include "virdomainobjlist.h" #include "virinterfaceobj.h" #include "virhostcpu.h" +#include "virdomaincheckpointobjlist.h" #include "virdomainsnapshotobjlist.h" #include "virkeycode.h" @@ -7692,7 +7694,366 @@ testDomainRevertToSnapshot(virDomainSnapshotPtr sna= pshot, return ret; } +/* + * Checkpoint APIs + */ +static int +testDomainCheckpointDiscardAll(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *data) +{ + virDomainMomentObjPtr chk =3D payload; + testMomentRemoveDataPtr curr =3D data; + + curr->current |=3D virDomainCheckpointObjListRemove(curr->vm->checkpoi= nts, + chk); + return 0; +} + +static virDomainObjPtr +testDomObjFromCheckpoint(virDomainCheckpointPtr checkpoint) +{ + return testDomObjFromDomain(checkpoint->domain); +} + +static virDomainMomentObjPtr +testCheckpointObjFromName(virDomainObjPtr vm, + const char *name) +{ + virDomainMomentObjPtr chk =3D NULL; + + chk =3D virDomainCheckpointFindByName(vm->checkpoints, name); + if (!chk) + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain checkpoint with matching name '%s'"), + name); + + return chk; +} + +static virDomainMomentObjPtr +testCheckpointObjFromCheckpoint(virDomainObjPtr vm, + virDomainCheckpointPtr checkpoint) +{ + return testCheckpointObjFromName(vm, checkpoint->name); +} + +static virDomainCheckpointPtr +testDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + testDriverPtr privconn =3D domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + virDomainMomentObjPtr current =3D NULL; + bool update_current =3D true; + bool redefine =3D flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + unsigned int parse_flags =3D 0; + VIR_AUTOUNREF(virDomainCheckpointDefPtr) def =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE, NULL); + + if (redefine) { + parse_flags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + update_current =3D false; + } + + if (!(vm =3D testDomObjFromDomain(domain))) + goto cleanup; + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create checkpoint for inactive domain")); + goto cleanup; + } + + if (!(def =3D virDomainCheckpointDefParseString(xmlDesc, privconn->cap= s, + privconn->xmlopt, + parse_flags))) + goto cleanup; + + if (redefine) { + if (virDomainCheckpointRedefinePrep(domain, vm, &def, &chk, + privconn->xmlopt, + &update_current) < 0) + goto cleanup; + } else { + if (!(def->parent.dom =3D virDomainDefCopy(vm->def, + privconn->caps, + privconn->xmlopt, + NULL, + true))) + goto cleanup; + + if (virDomainCheckpointAlignDisks(def) < 0) + goto cleanup; + } + + if (!chk) { + if (!(chk =3D virDomainCheckpointAssignDef(vm->checkpoints, def))) + goto cleanup; + + def =3D NULL; + } + + current =3D virDomainCheckpointGetCurrent(vm->checkpoints); + if (current) { + if (!redefine && + VIR_STRDUP(chk->def->parent_name, current->def->name) < 0) + goto cleanup; + if (update_current) + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + } + + /* actually do the checkpoint - except the test driver has nothing + * to actually do here */ + + /* If we fail after this point, there's not a whole lot we can do; + * we've successfully created the checkpoint, so we have to go + * forward the best we can. + */ + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + cleanup: + if (checkpoint) { + if (update_current) + virDomainCheckpointSetCurrent(vm->checkpoints, chk); + virDomainCheckpointLinkParent(vm->checkpoints, chk); + } else if (chk) { + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } + + virDomainObjEndAPI(&vm); + VIR_FREE(xml); + return checkpoint; +} + + +static int +testDomainListAllCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int n =3D -1; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_LIST_ROOTS | + VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL | + VIR_DOMAIN_CHECKPOINT_FILTERS_ALL, -1); + + if (!(vm =3D testDomObjFromDomain(domain))) + return -1; + + n =3D virDomainListCheckpoints(vm->checkpoints, NULL, domain, chks, fl= ags); + + virDomainObjEndAPI(&vm); + return n; +} + + +static int +testDomainCheckpointListAllChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + int n =3D -1; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS | + VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL | + VIR_DOMAIN_CHECKPOINT_FILTERS_ALL, -1); + + if (!(vm =3D testDomObjFromCheckpoint(checkpoint))) + return -1; + + if (!(chk =3D testCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + n =3D virDomainListCheckpoints(vm->checkpoints, chk, checkpoint->domai= n, + chks, flags); + + cleanup: + virDomainObjEndAPI(&vm); + return n; +} + + +static virDomainCheckpointPtr +testDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D testDomObjFromDomain(domain))) + return NULL; + + if (!(chk =3D testCheckpointObjFromName(vm, name))) + goto cleanup; + + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + cleanup: + virDomainObjEndAPI(&vm); + return checkpoint; +} + + +static virDomainCheckpointPtr +testDomainCheckpointGetParent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointPtr parent =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D testDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (!(chk =3D testCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + if (!chk->def->parent_name) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("checkpoint '%s' does not have a parent"), + chk->def->name); + goto cleanup; + } + + parent =3D virGetDomainCheckpoint(checkpoint->domain, chk->def->parent= _name); + + cleanup: + virDomainObjEndAPI(&vm); + return parent; +} + + +static char * +testDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + testDriverPtr privconn =3D checkpoint->domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + size_t i; + virDomainCheckpointDefPtr chkdef; + unsigned int format_flags; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_XML_SECURE | + VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN | + VIR_DOMAIN_CHECKPOINT_XML_SIZE, NULL); + + if (!(vm =3D testDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (!(chk =3D testCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + chkdef =3D virDomainCheckpointObjGetDef(chk); + + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) { + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + for (i =3D 0; i < chkdef->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &chkdef->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + disk->size =3D 1024; /* Any number will do... */ + } + } + + format_flags =3D virDomainCheckpointFormatConvertXMLFlags(flags); + xml =3D virDomainCheckpointDefFormat(chkdef, privconn->caps, + privconn->xmlopt, format_flags); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + + +static int +testDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainMomentObjPtr chk =3D NULL; + virDomainMomentObjPtr parentchk =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN | + VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY | + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY, -1); + + if (!(vm =3D testDomObjFromCheckpoint(checkpoint))) + return -1; + + if (!(chk =3D testCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + if (flags & (VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN | + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY)) { + testMomentRemoveData rem; + + rem.vm =3D vm; + rem.current =3D false; + virDomainMomentForEachDescendant(chk, testDomainCheckpointDiscardA= ll, + &rem); + if (rem.current) + virDomainCheckpointSetCurrent(vm->checkpoints, chk); + } else if (chk->nchildren) { + testMomentReparentData rep; + + rep.parent =3D chk->parent; + rep.vm =3D vm; + rep.err =3D 0; + virDomainMomentForEachChild(chk, testDomainMomentReparentChildren, + &rep); + if (rep.err < 0) + goto cleanup; + virDomainMomentMoveChildren(chk, chk->parent); + } + + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { + virDomainMomentDropChildren(chk); + } else { + virDomainMomentDropParent(chk); + if (chk =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints)) { + if (chk->def->parent_name) { + parentchk =3D virDomainCheckpointFindByName(vm->checkpoint= s, + chk->def->parent= _name); + if (!parentchk) + VIR_WARN("missing parent checkpoint matching name '%s'= ", + chk->def->parent_name); + } + virDomainCheckpointSetCurrent(vm->checkpoints, parentchk); + } + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } + + ret =3D 0; + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + +/* + * Test driver + */ static virHypervisorDriver testHypervisorDriver =3D { .name =3D "Test", .connectOpen =3D testConnectOpen, /* 0.1.1 */ @@ -7817,6 +8178,14 @@ static virHypervisorDriver testHypervisorDriver =3D { .domainSnapshotDelete =3D testDomainSnapshotDelete, /* 1.1.4 */ .connectBaselineCPU =3D testConnectBaselineCPU, /* 1.2.0 */ + .domainCheckpointCreateXML =3D testDomainCheckpointCreateXML, /* 5.6.0= */ + .domainCheckpointGetXMLDesc =3D testDomainCheckpointGetXMLDesc, /* 5.6= .0 */ + + .domainListAllCheckpoints =3D testDomainListAllCheckpoints, /* 5.6.0 */ + .domainCheckpointListAllChildren =3D testDomainCheckpointListAllChildr= en, /* 5.6.0 */ + .domainCheckpointLookupByName =3D testDomainCheckpointLookupByName, /*= 5.6.0 */ + .domainCheckpointGetParent =3D testDomainCheckpointGetParent, /* 5.6.0= */ + .domainCheckpointDelete =3D testDomainCheckpointDelete, /* 5.6.0 */ }; static virNetworkDriver testNetworkDriver =3D { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947823; cv=none; d=zoho.com; s=zohoarc; b=F2U65lzT8RbEyRBVmKP3X33nGHLC0oQ2IvrNgaoJYPddffJgYwbebnLFeVoSwbF3zio5BK2IEaJ/GTR08DW7r7S7KESsDRgNZ0UlFGduGYYSybc1GsABSvMf4pqlLPM7GedaRALn/UJjrQXDuHooalF7QWthuX0z4HFm71da6NU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947823; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=scNWzKHTcOE0+vwld50L4kRUviPVKJtq8DhJcfpGj7c=; b=bJPcQpAE5JFOwxd9Mn59+qUmKpTCBEJsoho47PjjwiLz3+iUPDxKtLzxo8p2Xj17Yut/FTas9c7OhArsJtUY37Apk0EyANuEmhEhqay1dcydAGw/9RdT/kV1/4NJglBPfWuV9U50KSaIEFjcm97F/lDfKDsZW9rgEz2VNgcoM7E= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947823916626.7272564815811; Tue, 23 Jul 2019 22:57:03 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id C72BF30C746B; Wed, 24 Jul 2019 05:57:02 +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 A011760BF3; Wed, 24 Jul 2019 05:57:02 +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 66EAC180020C; Wed, 24 Jul 2019 05:57:02 +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 x6O5v0ni029706 for ; Wed, 24 Jul 2019 01:57:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 969FE60C05; Wed, 24 Jul 2019 05:57:00 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 23CAD60BEC; Wed, 24 Jul 2019 05:56:54 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:04 -0500 Message-Id: <20190724055609.30691-15-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 14/19] backup: Add virsh-checkpoints test 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 24 Jul 2019 05:57:03 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Similar to virsh-snapshots (which also gets a minor tweak, to prove we properly lock out one API from the other until later integration efforts figure out the best way to proceed). Provides decent coverage of the checkpoint API, the test driver implementation, and the virsh access to the API. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- tests/Makefile.am | 1 + tests/virsh-checkpoint | 164 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100755 tests/virsh-checkpoint diff --git a/tests/Makefile.am b/tests/Makefile.am index 544328bb18..1c92e3ca6f 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -413,6 +413,7 @@ libvirtd_test_scripts =3D \ virsh-schedinfo \ virsh-self-test \ virt-admin-self-test \ + virsh-checkpoint \ virsh-snapshot \ virsh-start \ virsh-undefine \ diff --git a/tests/virsh-checkpoint b/tests/virsh-checkpoint new file mode 100755 index 0000000000..6fe5aa4c05 --- /dev/null +++ b/tests/virsh-checkpoint @@ -0,0 +1,164 @@ +#!/bin/sh +# simple testing of checkpoint APIs on test driver + +# Copyright (C) 2019 Red Hat, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see +# . + +. "$(dirname $0)/test-lib.sh" + +if test "$VERBOSE" =3D yes; then + set -x + $abs_top_builddir/tools/virsh --version +fi + +fail=3D0 + +mock_xdg_ || framework_failure + +# The test driver loses states between restarts, so we perform a script +# with some convenient markers for later post-processing of output. +$abs_top_builddir/tools/virsh --connect test:///default >out 2>err ' + # Create a series of checkpoints, with names that intentionally sort + # differently by topology than by name. For now, it is not possible + # to create fanout without hacking through redefines. + checkpoint-create-as test c1 + checkpoint-create-as test c1 + checkpoint-create-as test c3 + checkpoint-create-as test c2 + # Checking tree view (siblings sorted alphabetically) + checkpoint-list test --tree + # Demonstrate list filtering + checkpoint-list test --roots + checkpoint-list test --leaves + checkpoint-list test --parent --no-leaves + checkpoint-list test --from c3 + checkpoint-list test --from c1 --descendants --name + # Now the tree is linear, so we have an unambiguous topological order + checkpoint-list test --name + checkpoint-list test --name --topological + # Capture some XML for later redefine + checkpoint-delete test c1 + echo "" + checkpoint-dumpxml test c3 + echo "" + checkpoint-dumpxml test c2 + echo "" + # Deleting current checkpoint moves current up to remaining parent + checkpoint-delete test --children-only c3 + checkpoint-list test --leaves --name + checkpoint-delete test --children c3 + checkpoint-list test --leaves --name + # All done +' || fail=3D1 + +# First part is expected output, --tree results in trailing spaces, +# and checkpoint-list produces timestamps +sed 's/ *$//; s/[0-9-]\{10\} [0-9:.]* .[0-9]\{4\}/TIMESTAMP/; + /MarkerA/,/MarkerC/d' < out > out.cooked || fail=3D1 +# Second part holds domain checkpoint XMLs +sed -n '/MarkerA/,/MarkerB/p' < out > c3.xml || fail=3D1 +sed -n '/MarkerB/,/MarkerC/p' < out > c2.xml || fail=3D1 + +cat <<\EOF > exp || fail=3D1 +Domain checkpoint c1 created + +Domain checkpoint c3 created +Domain checkpoint c2 created +c1 + | + +- c3 + | + +- c2 + + + Name Creation Time +----------------------------------- + c1 TIMESTAMP + + Name Creation Time +----------------------------------- + c2 TIMESTAMP + + Name Creation Time Parent +-------------------------------------------- + c1 TIMESTAMP + c3 TIMESTAMP c1 + + Name Creation Time +----------------------------------- + c2 TIMESTAMP + +c2 +c3 + +c1 +c2 +c3 + +c1 +c3 +c2 + +Domain checkpoint c1 deleted + +Domain checkpoint c3 children deleted + +c3 + +Domain checkpoint c3 deleted + + +EOF +compare exp out.cooked || fail=3D1 + +cat < exp || fail=3D1 +error: operation failed: domain moment c1 already exists +EOF +compare exp err || fail=3D1 + +# Restore state with redefine +$abs_top_builddir/tools/virsh -c test:///default >out 2>err < exp || fail=3D1 + + +Domain checkpoint s3 created from 's3.xml' +Domain checkpoint s2 created from 's2.xml' +Name: s2 +Domain: test +Current: yes +Parent: s3 +Children: 0 +Descendants: 0 + +EOF + +cat < exp || fail=3D1 +error: invalid argument: parent c3 for moment c2 not found +error: marker +EOF +compare exp err || fail=3D1 + +(exit $fail); exit $fail --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947823; cv=none; d=zoho.com; s=zohoarc; b=ASISYxOVNVruLc2N6iQ+Ct2S0skkDVHTNtKod4e4bd8Kl2UE36U8co/XkbeqBRxP5eW0XS7jabCsEac5DSQ3kF2MsXly4W8z8+V3H+8kPhpaNP+wxqTo137kIKzL4aTPLJ5fkt9SLF09q5fiWND9MDfv/uA6E5btDsd8Nxvq1So= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947823; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=Crv8wUCq7WdmSMogcvxEiaZ5uNi8M0tDWLSeTK4r7g8=; b=TjRtU+qyx2R5f/yrK2P8R/QvXA0qFcEPzGxzz7TY7FII41Gv87dyg1hC+o2wOEs1/7dwDgt0gjqgJAVRFUThz+vmCZUfyEFpJK1yk1jclNIGJm1bT2GGnsJhVd4CR19ar6Lc93+h74Z2QZA5oU43LhqUTVsD4R/xpf8X6sjlAys= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947823262818.5678038369527; Tue, 23 Jul 2019 22:57:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20E623CA32; Wed, 24 Jul 2019 05:57:02 +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 F3F64601B7; Wed, 24 Jul 2019 05:57:01 +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 BFAEE1800209; Wed, 24 Jul 2019 05:57: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 x6O5v1gH029714 for ; Wed, 24 Jul 2019 01:57:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38D7C60BF3; Wed, 24 Jul 2019 05:57:01 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id B99C460BEC; Wed, 24 Jul 2019 05:57:00 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:05 -0500 Message-Id: <20190724055609.30691-16-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 15/19] backup: qemu: Add directory for tracking checkpoints 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 24 Jul 2019 05:57:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This is similar to the existing directory for snapshots; the domain will save one xml file per checkpoint, for reloading on the next libvirtd restart. Fortunately, since checkpoints mandate RNG validation, we are assured that the checkpoint name will be usable as a file name (no abuse of '../escape' as a checkpoint name, for example). Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_conf.h | 2 ++ src/qemu/qemu_conf.c | 5 +++++ src/qemu/qemu_driver.c | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 2229b76e89..962df4f52c 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -28,6 +28,7 @@ #include "capabilities.h" #include "network_conf.h" #include "domain_conf.h" +#include "checkpoint_conf.h" #include "snapshot_conf.h" #include "domain_event.h" #include "virthread.h" @@ -101,6 +102,7 @@ struct _virQEMUDriverConfig { char *cacheDir; char *saveDir; char *snapshotDir; + char *checkpointDir; char *channelTargetDir; char *nvramDir; char *swtpmStorageDir; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index e0195dac29..7a02ea5b07 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -160,6 +160,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) goto error; if (virAsprintf(&cfg->snapshotDir, "%s/snapshot", cfg->libDir) < 0) goto error; + if (virAsprintf(&cfg->checkpointDir, "%s/checkpoint", cfg->libDir)= < 0) + goto error; if (virAsprintf(&cfg->autoDumpPath, "%s/dump", cfg->libDir) < 0) goto error; if (virAsprintf(&cfg->channelTargetDir, @@ -223,6 +225,8 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool priv= ileged) goto error; if (virAsprintf(&cfg->snapshotDir, "%s/qemu/snapshot", cfg->config= BaseDir) < 0) goto error; + if (virAsprintf(&cfg->checkpointDir, "%s/qemu/checkpoint", cfg->co= nfigBaseDir) < 0) + goto error; if (virAsprintf(&cfg->autoDumpPath, "%s/qemu/dump", cfg->configBas= eDir) < 0) goto error; if (virAsprintf(&cfg->channelTargetDir, @@ -335,6 +339,7 @@ static void virQEMUDriverConfigDispose(void *obj) VIR_FREE(cfg->cacheDir); VIR_FREE(cfg->saveDir); VIR_FREE(cfg->snapshotDir); + VIR_FREE(cfg->checkpointDir); VIR_FREE(cfg->channelTargetDir); VIR_FREE(cfg->nvramDir); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 065e0a1bd8..fae2bd3b08 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -655,6 +655,11 @@ qemuStateInitialize(bool privileged, cfg->snapshotDir); goto error; } + if (virFileMakePath(cfg->checkpointDir) < 0) { + virReportSystemError(errno, _("Failed to create checkpoint dir %s"= ), + cfg->checkpointDir); + goto error; + } if (virFileMakePath(cfg->autoDumpPath) < 0) { virReportSystemError(errno, _("Failed to create dump dir %s"), cfg->autoDumpPath); @@ -766,6 +771,13 @@ qemuStateInitialize(bool privileged, (int)cfg->group); goto error; } + if (chown(cfg->checkpointDir, cfg->user, cfg->group) < 0) { + virReportSystemError(errno, + _("unable to set ownership of '%s' to %d:= %d"), + cfg->checkpointDir, (int)cfg->user, + (int)cfg->group); + goto error; + } if (chown(cfg->autoDumpPath, cfg->user, cfg->group) < 0) { virReportSystemError(errno, _("unable to set ownership of '%s' to %d:= %d"), --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947826; cv=none; d=zoho.com; s=zohoarc; b=YP+maRVu6RhQzh/vPTnUnL6TUwpt8q+SSc6YQGMKj+JCQ/p3rwKX2IYQTghhZXCkwTUgNqPWJd9NZPONQ/CNB/JyHHFPKzCDaIdmg+p19MdJSGnD763WA6HAADbpCRo1ulnb/50L218s8Amuv2HBuKM+KNAoP4iBZjd6j0fUReY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947826; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=xQgFju5rHnoHOp31oM8PjcsqPbGfAnI24LUt6HOsihM=; b=W59SvfODQVhy+aP8utfAlns3JZpT/wz6EQxe6yui9XW2/SWz50WJUM76VnnuLEFg9EWpCRFSFjBEiMwHfD740n793G+gchNMfy3nJjACnUEr4EuUgEVP+axDRLx+BpWEND+rEOlWtjqW5XR06jVSL9lPGXAqa0fFbZu1S68UbC4= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947826058193.1326175628974; Tue, 23 Jul 2019 22:57:06 -0700 (PDT) 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 F28DAC09AD1B; Wed, 24 Jul 2019 05:57:04 +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 CCA5619C78; Wed, 24 Jul 2019 05:57:04 +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 916231972F; Wed, 24 Jul 2019 05:57:04 +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 x6O5v1W5029728 for ; Wed, 24 Jul 2019 01:57:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id E448760C05; Wed, 24 Jul 2019 05:57:01 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5EA2560BEC; Wed, 24 Jul 2019 05:57:01 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:06 -0500 Message-Id: <20190724055609.30691-17-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 16/19] backup: qemu: Implement metadata tracking for checkpoint APIs 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]); Wed, 24 Jul 2019 05:57:05 +0000 (UTC) Content-Type: text/plain; charset="utf-8" A lot of this work heavily copies from the existing snapshot APIs. The interaction with qemu during create/delete still needs to be implemented, but this takes care of all the libvirt metadata (saving and restoring XML, and tracking the relations between multiple checkpoints). Signed-off-by: Eric Blake --- src/qemu/qemu_domain.h | 15 + src/qemu/qemu_domain.c | 131 +++++++++ src/qemu/qemu_driver.c | 606 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 752 insertions(+) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index b0c465cb22..eeb07180b7 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -755,6 +755,21 @@ int qemuDomainMomentDiscardAll(void *payload, int qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverPtr driver, virDomainObjPtr vm); +int qemuDomainCheckpointWriteMetadata(virDomainObjPtr vm, + virDomainMomentObjPtr checkpoint, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *checkpointDir); + +int qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainMomentObjPtr chk, + bool update_current, + bool metadata_only); + +int qemuDomainCheckpointDiscardAllMetadata(virQEMUDriverPtr driver, + virDomainObjPtr vm); + void qemuDomainRemoveInactive(virQEMUDriverPtr driver, virDomainObjPtr vm); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e7f28aa2b8..44ac7eb73e 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -56,6 +56,7 @@ #include "logging/log_manager.h" #include "locking/domain_lock.h" #include "virdomainsnapshotobjlist.h" +#include "virdomaincheckpointobjlist.h" #ifdef MAJOR_IN_MKDEV # include @@ -9019,6 +9020,37 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm, return ret; } +int +qemuDomainCheckpointWriteMetadata(virDomainObjPtr vm, + virDomainMomentObjPtr checkpoint, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + const char *checkpointDir) +{ + unsigned int flags =3D VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE; + virDomainCheckpointDefPtr def =3D virDomainCheckpointObjGetDef(checkpo= int); + VIR_AUTOFREE(char *) newxml =3D NULL; + VIR_AUTOFREE(char *) chkDir =3D NULL; + VIR_AUTOFREE(char *) chkFile =3D NULL; + + newxml =3D virDomainCheckpointDefFormat(def, caps, xmlopt, flags); + if (newxml =3D=3D NULL) + return -1; + + if (virAsprintf(&chkDir, "%s/%s", checkpointDir, vm->def->name) < 0) + return -1; + if (virFileMakePath(chkDir) < 0) { + virReportSystemError(errno, _("cannot create checkpoint directory = '%s'"), + chkDir); + return -1; + } + + if (virAsprintf(&chkFile, "%s/%s.xml", chkDir, def->parent.name) < 0) + return -1; + + return virXMLSaveFile(chkFile, NULL, "checkpoint-edit", newxml); +} + /* The domain is expected to be locked and inactive. Return -1 on normal * failure, 1 if we skipped a disk due to try_all. */ static int @@ -9215,12 +9247,100 @@ qemuDomainSnapshotDiscardAllMetadata(virQEMUDriver= Ptr driver, } +/* Discard one checkpoint (or its metadata), without reparenting any child= ren. */ +int +qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, + virDomainObjPtr vm, + virDomainMomentObjPtr chk, + bool update_parent, + bool metadata_only) +{ + char *chkFile =3D NULL; + int ret =3D -1; + virDomainMomentObjPtr parentchk =3D NULL; + virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + + if (!metadata_only) { + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot remove checkpoint from inactive domai= n")); + goto cleanup; + } else { + /* TODO: Implement QMP sequence to merge bitmaps */ + // qemuDomainObjPrivatePtr priv; + // priv =3D vm->privateData; + // qemuDomainObjEnterMonitor(driver, vm); + // /* we continue on even in the face of error */ + // qemuMonitorDeleteCheckpoint(priv->mon, chk->def->name); + // ignore_value(qemuDomainObjExitMonitor(driver, vm)); + } + } + + if (virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir, + vm->def->name, chk->def->name) < 0) + goto cleanup; + + if (chk =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints)) { + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + if (update_parent && chk->def->parent_name) { + parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent_nam= e); + if (!parentchk) { + VIR_WARN("missing parent checkpoint matching name '%s'", + chk->def->parent_name); + } else { + virDomainCheckpointSetCurrent(vm->checkpoints, parentchk); + if (qemuDomainCheckpointWriteMetadata(vm, parentchk, drive= r->caps, + driver->xmlopt, + cfg->checkpointDir) = < 0) { + VIR_WARN("failed to set parent checkpoint '%s' as curr= ent", + chk->def->parent_name); + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + } + } + } + } + + if (unlink(chkFile) < 0) + VIR_WARN("Failed to unlink %s", chkFile); + if (update_parent) + virDomainMomentDropParent(chk); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + + ret =3D 0; + + cleanup: + VIR_FREE(chkFile); + virObjectUnref(cfg); + return ret; +} + +int +qemuDomainCheckpointDiscardAllMetadata(virQEMUDriverPtr driver, + virDomainObjPtr vm) +{ + virQEMUMomentRemove rem =3D { + .driver =3D driver, + .vm =3D vm, + .metadata_only =3D true, + .momentDiscard =3D qemuDomainCheckpointDiscard, + }; + + virDomainCheckpointForEach(vm->checkpoints, qemuDomainMomentDiscardAll, + &rem); + virDomainCheckpointObjListRemoveAll(vm->checkpoints); + + return rem.err; +} + + static void qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driver, virDomainObjPtr vm) { virQEMUDriverConfigPtr cfg; VIR_AUTOFREE(char *) snapDir =3D NULL; + VIR_AUTOFREE(char *) chkDir =3D NULL; cfg =3D virQEMUDriverGetConfig(driver); @@ -9235,6 +9355,17 @@ qemuDomainRemoveInactiveCommon(virQEMUDriverPtr driv= er, } else if (rmdir(snapDir) < 0 && errno !=3D ENOENT) { VIR_WARN("unable to remove snapshot directory %s", snapDir); } + /* Remove any checkpoint metadata prior to removing the domain */ + if (qemuDomainCheckpointDiscardAllMetadata(driver, vm) < 0) { + VIR_WARN("unable to remove all checkpoints for domain %s", + vm->def->name); + } else if (virAsprintf(&chkDir, "%s/%s", cfg->checkpointDir, + vm->def->name) < 0) { + VIR_WARN("unable to remove checkpoint directory %s/%s", + cfg->checkpointDir, vm->def->name); + } else if (rmdir(chkDir) < 0 && errno !=3D ENOENT) { + VIR_WARN("unable to remove checkpoint directory %s", chkDir); + } qemuExtDevicesCleanupHost(driver, vm->def); virObjectUnref(cfg); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index fae2bd3b08..a75a16492b 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -103,6 +103,7 @@ #include "virqemu.h" #include "virdomainsnapshotobjlist.h" #include "virenum.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -222,6 +223,40 @@ qemuSnapObjFromSnapshot(virDomainObjPtr vm, return qemuSnapObjFromName(vm, snapshot->name); } +/* Looks up the domain object from checkpoint and unlocks the + * driver. The returned domain object is locked and ref'd and the + * caller must call virDomainObjEndAPI() on it. */ +static virDomainObjPtr +qemuDomObjFromCheckpoint(virDomainCheckpointPtr checkpoint) +{ + return qemuDomObjFromDomain(checkpoint->domain); +} + + +/* Looks up checkpoint object from VM and name */ +static virDomainMomentObjPtr +qemuCheckpointObjFromName(virDomainObjPtr vm, + const char *name) +{ + virDomainMomentObjPtr chk =3D NULL; + chk =3D virDomainCheckpointFindByName(vm->checkpoints, name); + if (!chk) + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain checkpoint with matching name '%s'"), + name); + + return chk; +} + + +/* Looks up checkpoint object from VM and checkpointPtr */ +static virDomainMomentObjPtr +qemuCheckpointObjFromCheckpoint(virDomainObjPtr vm, + virDomainCheckpointPtr checkpoint) +{ + return qemuCheckpointObjFromName(vm, checkpoint->name); +} + static int qemuAutostartDomain(virDomainObjPtr vm, void *opaque) @@ -525,6 +560,113 @@ qemuDomainSnapshotLoad(virDomainObjPtr vm, } +static int +qemuDomainCheckpointLoad(virDomainObjPtr vm, + void *data) +{ + char *baseDir =3D (char *)data; + char *chkDir =3D NULL; + DIR *dir =3D NULL; + struct dirent *entry; + char *xmlStr; + char *fullpath; + virDomainCheckpointDefPtr def =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + virDomainMomentObjPtr current =3D NULL; + unsigned int flags =3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + int ret =3D -1; + virCapsPtr caps =3D NULL; + int direrr; + + virObjectLock(vm); + if (virAsprintf(&chkDir, "%s/%s", baseDir, vm->def->name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to allocate memory for " + "checkpoint directory for domain %s"), + vm->def->name); + goto cleanup; + } + + if (!(caps =3D virQEMUDriverGetCapabilities(qemu_driver, false))) + goto cleanup; + + VIR_INFO("Scanning for checkpoints for domain %s in %s", vm->def->name, + chkDir); + + if (virDirOpenIfExists(&dir, chkDir) <=3D 0) + goto cleanup; + + while ((direrr =3D virDirRead(dir, &entry, NULL)) > 0) { + /* NB: ignoring errors, so one malformed config doesn't + kill the whole process */ + VIR_INFO("Loading checkpoint file '%s'", entry->d_name); + + if (virAsprintf(&fullpath, "%s/%s", chkDir, entry->d_name) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Failed to allocate memory for path")); + continue; + } + + if (virFileReadAll(fullpath, 1024*1024*1, &xmlStr) < 0) { + /* Nothing we can do here, skip this one */ + virReportSystemError(errno, + _("Failed to read checkpoint file %s"), + fullpath); + VIR_FREE(fullpath); + continue; + } + + def =3D virDomainCheckpointDefParseString(xmlStr, caps, + qemu_driver->xmlopt, + flags); + if (!def || virDomainCheckpointAlignDisks(def) < 0) { + /* Nothing we can do here, skip this one */ + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to parse checkpoint XML from file '%s= '"), + fullpath); + VIR_FREE(fullpath); + VIR_FREE(xmlStr); + virObjectUnref(def); + continue; + } + + chk =3D virDomainCheckpointAssignDef(vm->checkpoints, def); + if (chk =3D=3D NULL) + virObjectUnref(def); + + VIR_FREE(fullpath); + VIR_FREE(xmlStr); + } + if (direrr < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to fully read directory %s"), + chkDir); + + if (virDomainCheckpointUpdateRelations(vm->checkpoints, ¤t) < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Checkpoints have inconsistent relations for doma= in %s"), + vm->def->name); + virDomainCheckpointSetCurrent(vm->checkpoints, current); + + /* Note that it is not practical to automatically construct + * checkpoints based solely on qcow2 bitmaps, since qemu does not + * track parent relations which we find important in our metadata. + * Perhaps we could double-check that our just-loaded checkpoint + * metadata is consistent with existing qcow2 bitmaps, but a user + * that changes things behind our backs deserves what happens. */ + + virResetLastError(); + + ret =3D 0; + cleanup: + VIR_DIR_CLOSE(dir); + VIR_FREE(chkDir); + virObjectUnref(caps); + virObjectUnlock(vm); + return ret; +} + + static int qemuDomainNetsRestart(virDomainObjPtr vm, void *data ATTRIBUTE_UNUSED) @@ -911,6 +1053,10 @@ qemuStateInitialize(bool privileged, qemuDomainSnapshotLoad, cfg->snapshotDir); + virDomainObjListForEach(qemu_driver->domains, + qemuDomainCheckpointLoad, + cfg->checkpointDir); + virDomainObjListForEach(qemu_driver->domains, qemuDomainManagedSaveLoad, qemu_driver); @@ -7711,10 +7857,12 @@ qemuDomainUndefineFlags(virDomainPtr dom, char *name =3D NULL; int ret =3D -1; int nsnapshots; + int ncheckpoints; virQEMUDriverConfigPtr cfg =3D NULL; virCheckFlags(VIR_DOMAIN_UNDEFINE_MANAGED_SAVE | VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA | + VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA | VIR_DOMAIN_UNDEFINE_NVRAM | VIR_DOMAIN_UNDEFINE_KEEP_NVRAM, -1); @@ -7754,6 +7902,19 @@ qemuDomainUndefineFlags(virDomainPtr dom, if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) goto endjob; } + if (!virDomainObjIsActive(vm) && + (ncheckpoints =3D virDomainListCheckpoints(vm->checkpoints, NULL, = dom, + NULL, flags)) > 0) { + if (!(flags & VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA)) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("cannot delete inactive domain with %d " + "checkpoints"), + ncheckpoints); + goto endjob; + } + if (qemuDomainCheckpointDiscardAllMetadata(driver, vm) < 0) + goto endjob; + } name =3D qemuDomainManagedSavePath(driver, vm); if (name =3D=3D NULL) @@ -16786,6 +16947,443 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr sna= pshot, return ret; } + +/* Called inside job lock */ +static int +qemuDomainCheckpointPrepare(virQEMUDriverPtr driver, virCapsPtr caps, + virDomainObjPtr vm, + virDomainCheckpointDefPtr def) +{ + int ret =3D -1; + size_t i; + char *xml =3D NULL; + qemuDomainObjPrivatePtr priv =3D vm->privateData; + + /* Easiest way to clone inactive portion of vm->def is via + * conversion in and back out of xml. */ + if (!(xml =3D qemuDomainDefFormatLive(driver, vm->def, priv->origCPU, + true, true)) || + !(def->parent.dom =3D virDomainDefParseString(xml, caps, driver->x= mlopt, NULL, + VIR_DOMAIN_DEF_PARSE_I= NACTIVE | + VIR_DOMAIN_DEF_PARSE_S= KIP_VALIDATE))) + goto cleanup; + + if (virDomainCheckpointAlignDisks(def) < 0) + goto cleanup; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk =3D &def->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + + if (vm->def->disks[i]->src->format !=3D VIR_STORAGE_FILE_QCOW2) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("checkpoint for disk %s unsupported " + "for storage type %s"), + disk->name, + virStorageFileFormatTypeToString( + vm->def->disks[i]->src->format)); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + VIR_FREE(xml); + return ret; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointCreateXML(virDomainPtr domain, + const char *xmlDesc, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + bool update_current =3D true; + bool redefine =3D flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE; + unsigned int parse_flags =3D 0; + virDomainMomentObjPtr other =3D NULL; + virQEMUDriverConfigPtr cfg =3D NULL; + virCapsPtr caps =3D NULL; + VIR_AUTOUNREF(virDomainCheckpointDefPtr) def =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, NULL); + /* TODO: VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE */ + + if (redefine) { + parse_flags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + update_current =3D false; + } + + if (!(vm =3D qemuDomObjFromDomain(domain))) + goto cleanup; + + if (virDomainSnapshotObjListNum(vm->snapshots, NULL, 0) > 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create checkpoint while snapshot exists")= ); + goto cleanup; + } + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainCheckpointCreateXMLEnsureACL(domain->conn, vm->def, flags= ) < 0) + goto cleanup; + + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) + goto cleanup; + + if (qemuProcessAutoDestroyActive(driver, vm)) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("domain is marked for auto destroy")); + goto cleanup; + } + + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create checkpoint for inactive domain")); + goto cleanup; + } + + if (!(def =3D virDomainCheckpointDefParseString(xmlDesc, caps, driver-= >xmlopt, + parse_flags))) + goto cleanup; + /* Unlike snapshots, the RNG schema already ensured a sane filename. */ + + /* We are going to modify the domain below. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + if (redefine) { + if (virDomainCheckpointRedefinePrep(domain, vm, &def, &chk, + driver->xmlopt, + &update_current) < 0) + goto endjob; + } else if (qemuDomainCheckpointPrepare(driver, caps, vm, def) < 0) { + goto endjob; + } + + if (!chk) { + if (!(chk =3D virDomainCheckpointAssignDef(vm->checkpoints, def))) + goto endjob; + + def =3D NULL; + } + + other =3D virDomainCheckpointGetCurrent(vm->checkpoints); + if (other) { + if (!redefine && + VIR_STRDUP(chk->def->parent_name, other->def->name) < 0) + goto endjob; + if (update_current) { + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + if (qemuDomainCheckpointWriteMetadata(vm, other, + driver->caps, driver->xm= lopt, + cfg->checkpointDir) < 0) + goto endjob; + } + } + + /* actually do the checkpoint */ + if (redefine) { + /* XXX Should we validate that the redefined checkpoint even + * makes sense, such as checking that qemu-img recognizes the + * checkpoint bitmap name in at least one of the domain's disks? = */ + } else { + /* TODO: issue QMP transaction command */ + } + + /* If we fail after this point, there's not a whole lot we can do; + * we've successfully created the checkpoint, so we have to go + * forward the best we can. + */ + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + endjob: + if (checkpoint) { + if (update_current) + virDomainCheckpointSetCurrent(vm->checkpoints, chk); + if (qemuDomainCheckpointWriteMetadata(vm, chk, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) { + /* if writing of metadata fails, error out rather than trying + * to silently carry on without completing the checkpoint */ + virObjectUnref(checkpoint); + checkpoint =3D NULL; + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to save metadata for checkpoint %s"), + chk->def->name); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } else { + virDomainCheckpointLinkParent(vm->checkpoints, chk); + } + } else if (chk) { + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } + + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + VIR_FREE(xml); + virObjectUnref(caps); + virObjectUnref(cfg); + return checkpoint; +} + + +static int +qemuDomainListAllCheckpoints(virDomainPtr domain, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int n =3D -1; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_LIST_ROOTS | + VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL | + VIR_DOMAIN_CHECKPOINT_FILTERS_ALL, -1); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return -1; + + if (virDomainListAllCheckpointsEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + n =3D virDomainListCheckpoints(vm->checkpoints, NULL, domain, chks, fl= ags); + + cleanup: + virDomainObjEndAPI(&vm); + return n; +} + + +static int +qemuDomainCheckpointListAllChildren(virDomainCheckpointPtr checkpoint, + virDomainCheckpointPtr **chks, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + int n =3D -1; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS | + VIR_DOMAIN_CHECKPOINT_LIST_TOPOLOGICAL | + VIR_DOMAIN_CHECKPOINT_FILTERS_ALL, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + if (virDomainCheckpointListAllChildrenEnsureACL(checkpoint->domain->co= nn, + vm->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + n =3D virDomainListCheckpoints(vm->checkpoints, chk, checkpoint->domai= n, + chks, flags); + + cleanup: + virDomainObjEndAPI(&vm); + return n; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointLookupByName(virDomainPtr domain, + const char *name, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointPtr checkpoint =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return NULL; + + if (virDomainCheckpointLookupByNameEnsureACL(domain->conn, vm->def) < = 0) + goto cleanup; + + if (!(chk =3D qemuCheckpointObjFromName(vm, name))) + goto cleanup; + + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + cleanup: + virDomainObjEndAPI(&vm); + return checkpoint; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointGetParent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointPtr parent =3D NULL; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (virDomainCheckpointGetParentEnsureACL(checkpoint->domain->conn, vm= ->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + if (!chk->def->parent_name) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("checkpoint '%s' does not have a parent"), + chk->def->name); + goto cleanup; + } + + parent =3D virGetDomainCheckpoint(checkpoint->domain, chk->def->parent= _name); + + cleanup: + virDomainObjEndAPI(&vm); + return parent; +} + + +static char * +qemuDomainCheckpointGetXMLDesc(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D checkpoint->domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + virDomainCheckpointDefPtr chkdef; + unsigned int format_flags; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_XML_SECURE | + VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN, NULL); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (virDomainCheckpointGetXMLDescEnsureACL(checkpoint->domain->conn, v= m->def, flags) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckpointObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + chkdef =3D virDomainCheckpointObjGetDef(chk); + + format_flags =3D virDomainCheckpointFormatConvertXMLFlags(flags); + xml =3D virDomainCheckpointDefFormat(chkdef, driver->caps, driver->xml= opt, + format_flags); + + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + + +static int +qemuDomainCheckpointDelete(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virQEMUDriverPtr driver =3D checkpoint->domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainMomentObjPtr chk =3D NULL; + virQEMUMomentRemove rem; + virQEMUMomentReparent rep; + bool metadata_only =3D !!(flags & VIR_DOMAIN_CHECKPOINT_DELETE_METADAT= A_ONLY); + virQEMUDriverConfigPtr cfg =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN | + VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY | + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainCheckpointDeleteEnsureACL(checkpoint->domain->conn, vm->d= ef) < 0) + goto cleanup; + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckpointObjFromCheckpoint(vm, checkpoint))) + goto endjob; + + if (flags & (VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN | + VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY)) { + rem.driver =3D driver; + rem.vm =3D vm; + rem.metadata_only =3D metadata_only; + rem.err =3D 0; + rem.current =3D virDomainCheckpointGetCurrent(vm->checkpoints); + rem.found =3D false; + rem.momentDiscard =3D qemuDomainCheckpointDiscard; + virDomainMomentForEachDescendant(chk, qemuDomainMomentDiscardAll, + &rem); + if (rem.err < 0) + goto endjob; + if (rem.found) { + virDomainCheckpointSetCurrent(vm->checkpoints, chk); + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { + if (qemuDomainCheckpointWriteMetadata(vm, chk, driver->cap= s, + driver->xmlopt, + cfg->checkpointDir) = < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("failed to set checkpoint '%s' as cur= rent"), + chk->def->name); + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + goto endjob; + } + } + } + } else if (chk->nchildren) { + rep.dir =3D cfg->checkpointDir; + rep.parent =3D chk->parent; + rep.vm =3D vm; + rep.err =3D 0; + rep.caps =3D driver->caps; + rep.xmlopt =3D driver->xmlopt; + rep.writeMetadata =3D qemuDomainCheckpointWriteMetadata; + virDomainMomentForEachChild(chk, qemuDomainMomentReparentChildren, + &rep); + if (rep.err < 0) + goto endjob; + virDomainMomentMoveChildren(chk, chk->parent); + } + + if (flags & VIR_DOMAIN_CHECKPOINT_DELETE_CHILDREN_ONLY) { + virDomainMomentDropChildren(chk); + ret =3D 0; + } else { + ret =3D qemuDomainCheckpointDiscard(driver, vm, chk, true, metadat= a_only); + } + + endjob: + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + virObjectUnref(cfg); + return ret; +} + static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *c= md, char **result, unsigned int flags) { @@ -22458,6 +23056,14 @@ static virHypervisorDriver qemuHypervisorDriver = =3D { .connectBaselineHypervisorCPU =3D qemuConnectBaselineHypervisorCPU, /*= 4.4.0 */ .nodeGetSEVInfo =3D qemuNodeGetSEVInfo, /* 4.5.0 */ .domainGetLaunchSecurityInfo =3D qemuDomainGetLaunchSecurityInfo, /* 4= .5.0 */ + .domainCheckpointCreateXML =3D qemuDomainCheckpointCreateXML, /* 5.6.0= */ + .domainCheckpointGetXMLDesc =3D qemuDomainCheckpointGetXMLDesc, /* 5.6= .0 */ + + .domainListAllCheckpoints =3D qemuDomainListAllCheckpoints, /* 5.6.0 */ + .domainCheckpointListAllChildren =3D qemuDomainCheckpointListAllChildr= en, /* 5.6.0 */ + .domainCheckpointLookupByName =3D qemuDomainCheckpointLookupByName, /*= 5.6.0 */ + .domainCheckpointGetParent =3D qemuDomainCheckpointGetParent, /* 5.6.0= */ + .domainCheckpointDelete =3D qemuDomainCheckpointDelete, /* 5.6.0 */ }; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947840; cv=none; d=zoho.com; s=zohoarc; b=f/JlA1ujtD0YOX7g9f0JyxgITprBjlJ1NBYP82NaUQJfYhL2Wl2eypnhgl17BG3BhGfA5rf58XwXHdpnMJDmmhtM3gPUvKfFnL5lu1dlRhmYj4qXbSWdfNuXCudFcmCe8WBDzylYcRwdj0VZQzdOZE1aIm/o9RimV/4CpDabelA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947840; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=8bC8hw7xZV/bvi7VVshpOvE8eTgTHMfvOra/uVdBRXU=; b=YsjfBteE1nnPLKe/cVkLCJ/hpTUfKRhUNx2ujry0k6wGf0Ct2RHib9/3TpBXV0uuCtOBR9J1mcrR6WAP/osRh/sY61ktx6J9NIP/21eDC+zG8pG+ieYREhzR9p2K2yFmY42jc2NwR1l6rvisTaiVC6t975AWvdQuthav+b2ppxk= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947840923366.4053763952095; Tue, 23 Jul 2019 22:57:20 -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 CC390300C72E; Wed, 24 Jul 2019 05:57: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 4056F1820E; Wed, 24 Jul 2019 05:57: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 F2E8E19732; Wed, 24 Jul 2019 05:57:18 +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 x6O5vHd8030222 for ; Wed, 24 Jul 2019 01:57:17 -0400 Received: by smtp.corp.redhat.com (Postfix) id D14C160C69; Wed, 24 Jul 2019 05:57:17 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 345A360C05; Wed, 24 Jul 2019 05:57:01 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:07 -0500 Message-Id: <20190724055609.30691-18-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 17/19] backup: qemu: Add helper API for looking up node name 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.45]); Wed, 24 Jul 2019 05:57:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Qemu bitmap operations require knowing the node name associated with the format layer (the qcow2 file); as upcoming patches will be grabbing that information frequently, make a helper function to access it. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/qemu/qemu_domain.h | 3 +++ src/qemu/qemu_domain.c | 15 +++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index eeb07180b7..b76d3cace9 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -804,6 +804,9 @@ int qemuDomainDetermineDiskChain(virQEMUDriverPtr drive= r, bool qemuDomainDiskChangeSupported(virDomainDiskDefPtr disk, virDomainDiskDefPtr orig_disk); +const char *qemuDomainDiskNodeFormatLookup(virDomainObjPtr vm, + const char *disk); + int qemuDomainStorageFileInit(virQEMUDriverPtr driver, virDomainObjPtr vm, virStorageSourcePtr src, diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 44ac7eb73e..d71b7d1984 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -10260,6 +10260,21 @@ qemuDomainDiskChangeSupported(virDomainDiskDefPtr = disk, return true; } + +/* Return the format node name for a given disk of an online guest */ +const char * +qemuDomainDiskNodeFormatLookup(virDomainObjPtr vm, + const char *disk) +{ + size_t i; + + for (i =3D 0; i < vm->def->ndisks; i++) { + if (STREQ(vm->def->disks[i]->dst, disk)) + return vm->def->disks[i]->src->nodeformat; + } + return NULL; +} + bool qemuDomainDiskBlockJobIsActive(virDomainDiskDefPtr disk) { --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947856; cv=none; d=zoho.com; s=zohoarc; b=Pt9AzOIBgUaUkmrm4Jv4YkMducyZeTOgylke1iCHNcX8rp7s4zXKfZfSyQf3i49G50LDuXLJDbHRC3oLllynFHKVivf/LbIoRUR1K3ffMdhi+tKwfNN823EYyRwiam8D9TL7t/1/TDuJmSJddRDC22flpuMPiFekGU0D20yDykk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947856; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=KMdP3TMrVePrLmOCuOikWw4z859tNndTXsXGAJpQKyE=; b=Od/ahQ0N3gqzt8N7WuTDPVSS5gAkrFREiCXGMzJi74CzwXGcJCSFT33XOgVfw8YOC/gc+/C2ZiqexKYmtLAi9sq4KqPa/8hwQu5JZ9RMIz2aKiupg8tMwh36NytvA1kJGOBc8tnMsQMBjS6fzeJax9IocmJcJl5t6C6KC1uL0hc= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947856986642.114514469302; Tue, 23 Jul 2019 22:57:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id AF59A308A9BE; Wed, 24 Jul 2019 05:57:35 +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 84A8460603; Wed, 24 Jul 2019 05:57:35 +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 4550219731; Wed, 24 Jul 2019 05:57:35 +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 x6O5vXpa030310 for ; Wed, 24 Jul 2019 01:57:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id F0B5660C6A; Wed, 24 Jul 2019 05:57:33 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03B6E60C18; Wed, 24 Jul 2019 05:57:17 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:08 -0500 Message-Id: <20190724055609.30691-19-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 18/19] backup: Wire up qemu checkpoint commands over QMP 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 24 Jul 2019 05:57:36 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Time to actually issue the QMP transactions that create and delete persistent checkpoints. For create, we only need one transaction: inside, we visit all disks affected by the checkpoint, and create a new enabled bitmap, as well as disabling the bitmap of the first ancestor checkpoint (if any) that also had a bitmap. For deletion, we need multiple calls: for each disk, if there is an ancestor checkpoint with a bitmap, then the bitmap must be merged (including activating the ancestor bitmap), all before deleting the bitmap from the checkpoint being removed. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.c | 122 ++++++++++++++++++++++++++++------------- src/qemu/qemu_driver.c | 98 ++++++++++++++++++++++++++++++++- 2 files changed, 180 insertions(+), 40 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index d71b7d1984..062a08ed97 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -9255,48 +9255,97 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, bool update_parent, bool metadata_only) { - char *chkFile =3D NULL; - int ret =3D -1; - virDomainMomentObjPtr parentchk =3D NULL; - virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + virDomainMomentObjPtr parent =3D NULL; + virDomainMomentObjPtr moment; + virDomainCheckpointDefPtr parentdef =3D NULL; + size_t i, j; + VIR_AUTOUNREF(virQEMUDriverConfigPtr) cfg =3D virQEMUDriverGetConfig(d= river); + VIR_AUTOFREE(char *) chkFile =3D NULL; - if (!metadata_only) { - if (!virDomainObjIsActive(vm)) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot remove checkpoint from inactive domai= n")); - goto cleanup; - } else { - /* TODO: Implement QMP sequence to merge bitmaps */ - // qemuDomainObjPrivatePtr priv; - // priv =3D vm->privateData; - // qemuDomainObjEnterMonitor(driver, vm); - // /* we continue on even in the face of error */ - // qemuMonitorDeleteCheckpoint(priv->mon, chk->def->name); - // ignore_value(qemuDomainObjExitMonitor(driver, vm)); - } + if (!metadata_only && !virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot remove checkpoint from inactive domain")); + return -1; } if (virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir, vm->def->name, chk->def->name) < 0) - goto cleanup; + return -1; + + if (!metadata_only) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; + bool success =3D true; + bool search_parents; + virDomainCheckpointDefPtr chkdef =3D virDomainCheckpointObjGetDef(= chk); + + qemuDomainObjEnterMonitor(driver, vm); + parent =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent_name); + for (i =3D 0; i < chkdef->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &chkdef->disks[i]; + const char *node; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + + node =3D qemuDomainDiskNodeFormatLookup(vm, disk->name); + /* If any ancestor checkpoint has a bitmap for the same + * disk, then this bitmap must be merged to the + * ancestor. */ + search_parents =3D true; + for (moment =3D parent; + search_parents && moment; + moment =3D virDomainCheckpointFindByName(vm->checkpoints, + parentdef->parent.= parent_name)) { + parentdef =3D virDomainCheckpointObjGetDef(moment); + for (j =3D 0; j < parentdef->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + VIR_AUTOPTR(virJSONValue) arr =3D NULL; + + disk2 =3D &parentdef->disks[j]; + if (STRNEQ(disk->name, disk2->name) || + disk2->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + search_parents =3D false; + + arr =3D virJSONValueNewArray(); + if (!arr || + virJSONValueArrayAppendString(arr, disk->bitmap) <= 0) { + success =3D false; + break; + } + if (chk =3D=3D virDomainCheckpointGetCurrent(vm->check= points) && + qemuMonitorEnableBitmap(priv->mon, node, + disk2->bitmap) < 0) { + success =3D false; + break; + } + if (qemuMonitorMergeBitmaps(priv->mon, node, + disk2->bitmap, &arr) < 0) { + success =3D false; + break; + } + } + } + if (qemuMonitorDeleteBitmap(priv->mon, node, disk->bitmap) < 0= ) { + success =3D false; + break; + } + } + if (qemuDomainObjExitMonitor(driver, vm) < 0 || !success) + return -1; + } if (chk =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints)) { virDomainCheckpointSetCurrent(vm->checkpoints, NULL); - if (update_parent && chk->def->parent_name) { - parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, - chk->def->parent_nam= e); - if (!parentchk) { - VIR_WARN("missing parent checkpoint matching name '%s'", + if (update_parent && parent) { + virDomainCheckpointSetCurrent(vm->checkpoints, parent); + if (qemuDomainCheckpointWriteMetadata(vm, parent, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0)= { + VIR_WARN("failed to set parent checkpoint '%s' as current", chk->def->parent_name); - } else { - virDomainCheckpointSetCurrent(vm->checkpoints, parentchk); - if (qemuDomainCheckpointWriteMetadata(vm, parentchk, drive= r->caps, - driver->xmlopt, - cfg->checkpointDir) = < 0) { - VIR_WARN("failed to set parent checkpoint '%s' as curr= ent", - chk->def->parent_name); - virDomainCheckpointSetCurrent(vm->checkpoints, NULL); - } + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); } } } @@ -9307,12 +9356,7 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, virDomainMomentDropParent(chk); virDomainCheckpointObjListRemove(vm->checkpoints, chk); - ret =3D 0; - - cleanup: - VIR_FREE(chkFile); - virObjectUnref(cfg); - return ret; + return 0; } int diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index a75a16492b..d0377d78a9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -47,6 +47,7 @@ #include "qemu_hostdev.h" #include "qemu_hotplug.h" #include "qemu_monitor.h" +#include "qemu_monitor_json.h" #include "qemu_process.h" #include "qemu_migration.h" #include "qemu_migration_params.h" @@ -16995,6 +16996,65 @@ qemuDomainCheckpointPrepare(virQEMUDriverPtr drive= r, virCapsPtr caps, return ret; } +static int +qemuDomainCheckpointAddActions(virDomainObjPtr vm, + virJSONValuePtr actions, + virDomainMomentObjPtr old_current, + virDomainCheckpointDefPtr def) +{ + size_t i, j; + virDomainCheckpointDefPtr olddef; + virDomainMomentObjPtr parent; + bool search_parents; + + for (i =3D 0; i < def->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &def->disks[i]; + const char *node; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + node =3D qemuDomainDiskNodeFormatLookup(vm, disk->name); + if (qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-add", + "s:node", node, + "s:name", disk->bitmap, + "b:persistent", true, + NULL) < 0) + return -1; + + /* We only want one active bitmap for a disk along the + * checkpoint chain, then later differential backups will + * merge the bitmaps (only one active) between the bounding + * checkpoint and the leaf checkpoint. If the same disks are + * involved in each checkpoint, this search terminates in one + * iteration; but it is also possible to have to search + * further than the immediate parent to find another + * checkpoint with a bitmap on the same disk. */ + search_parents =3D true; + for (parent =3D old_current; search_parents && parent; + parent =3D virDomainCheckpointFindByName(vm->checkpoints, + olddef->parent.parent_= name)) { + olddef =3D virDomainCheckpointObjGetDef(parent); + for (j =3D 0; j < olddef->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + + disk2 =3D &olddef->disks[j]; + if (STRNEQ(disk->name, disk2->name) || + disk2->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + if (qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-disa= ble", + "s:node", node, + "s:name", disk2->bitmap, + NULL) < 0) + return -1; + search_parents =3D false; + break; + } + } + } + return 0; +} static virDomainCheckpointPtr qemuDomainCheckpointCreateXML(virDomainPtr domain, @@ -17012,6 +17072,9 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, virDomainMomentObjPtr other =3D NULL; virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; + qemuDomainObjPrivatePtr priv; + virJSONValuePtr actions =3D NULL; + int ret; VIR_AUTOUNREF(virDomainCheckpointDefPtr) def =3D NULL; virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, NULL); @@ -17031,11 +17094,18 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, goto cleanup; } + priv =3D vm->privateData; cfg =3D virQEMUDriverGetConfig(driver); if (virDomainCheckpointCreateXMLEnsureACL(domain->conn, vm->def, flags= ) < 0) goto cleanup; + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support")); + goto cleanup; + } + if (!(caps =3D virQEMUDriverGetCapabilities(driver, false))) goto cleanup; @@ -17096,7 +17166,15 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, * makes sense, such as checking that qemu-img recognizes the * checkpoint bitmap name in at least one of the domain's disks? = */ } else { - /* TODO: issue QMP transaction command */ + if (!(actions =3D virJSONValueNewArray())) + goto endjob; + if (qemuDomainCheckpointAddActions(vm, actions, other, + virDomainCheckpointObjGetDef(ch= k)) < 0) + goto endjob; + qemuDomainObjEnterMonitor(driver, vm); + ret =3D qemuMonitorTransaction(priv->mon, &actions); + if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) + goto endjob; } /* If we fail after this point, there's not a whole lot we can do; @@ -17130,6 +17208,7 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, qemuDomainObjEndJob(driver, vm); cleanup: + virJSONValueFree(actions); virDomainObjEndAPI(&vm); VIR_FREE(xml); virObjectUnref(caps); @@ -17301,6 +17380,7 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr c= heckpoint, { virQEMUDriverPtr driver =3D checkpoint->domain->conn->privateData; virDomainObjPtr vm =3D NULL; + qemuDomainObjPrivatePtr priv; int ret =3D -1; virDomainMomentObjPtr chk =3D NULL; virQEMUMomentRemove rem; @@ -17323,6 +17403,22 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr = checkpoint, if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; + priv =3D vm->privateData; + if (!metadata_only) { + /* Until qemu-img supports offline bitmap deletion, we are stuck + * with requiring a running guest */ + if (!virDomainObjIsActive(vm)) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot delete checkpoint for inactive domain= ")); + goto endjob; + } + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support= ")); + goto endjob; + } + } + if (!(chk =3D qemuCheckpointObjFromCheckpoint(vm, checkpoint))) goto endjob; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 14:01:34 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 ARC-Seal: i=1; a=rsa-sha256; t=1563947869; cv=none; d=zoho.com; s=zohoarc; b=NmTEZTfaAQCXgrhWzILdKEVFWrhKbdrvvVd0kgXMaSYmPQv2NWLQyT4h65u3uwmvliO4SfycEdb+eD1q5Utuah8RnB7y5AGqrH/w0LxlFrTWEQLPrUvYH44V12jF/1w2raNqZkWTXNU7TVtvAqYZKA+g1Jsj69gqjh2XV0+dMxk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1563947869; h=Content-Type:Content-Transfer-Encoding:Cc: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:ARC-Authentication-Results; bh=z5DB0OLGuJL0Rzs87MpC2mC2VJ2a2nAIaC9nd9H/gLc=; b=ctN+7CsmtqZLVnPqzkPMwsrpreUMnvu6neaIz0L10TrRUPriRRXQ1Q9an22cDrB4FK/qzIa2CFm9YonPdjRU5xZlUEgGzZnpkJW5+R30ckHMwwSbsGoIBr74FyVMkn2E9zIrZu02gbnN5Zn7/hvWABkMQ5RYNwvQICpWKrJkpxo= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1563947869272716.400623265305; Tue, 23 Jul 2019 22:57:49 -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 245CF31628FF; Wed, 24 Jul 2019 05:57:48 +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 F26981820E; Wed, 24 Jul 2019 05:57:47 +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 B9B0919730; Wed, 24 Jul 2019 05:57:47 +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 x6O5vkRc030346 for ; Wed, 24 Jul 2019 01:57:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7267760C69; Wed, 24 Jul 2019 05:57:46 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-93.phx2.redhat.com [10.3.116.93]) by smtp.corp.redhat.com (Postfix) with ESMTP id 956E360C05; Wed, 24 Jul 2019 05:57:34 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 24 Jul 2019 00:56:09 -0500 Message-Id: <20190724055609.30691-20-eblake@redhat.com> In-Reply-To: <20190724055609.30691-1-eblake@redhat.com> References: <20190724055609.30691-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 Cc: nsoffer@redhat.com, eshenitz@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v10 19/19] backup: Prevent snapshots and checkpoints at same time 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.41]); Wed, 24 Jul 2019 05:57:48 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Earlier patches mentioned that the initial implementation will prevent snapshots and checkpoints from being used on the same domain at once. However, the actual restriction is done in this separate patch to make it easier to lift that restriction via a revert, when we are finally ready to tackle that integration in the future. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- docs/formatsnapshot.html.in | 4 +++- src/qemu/qemu_driver.c | 12 ++++++++++++ src/test/test_driver.c | 12 ++++++++++++ tests/virsh-checkpoint | 10 ++++++++++ tests/virsh-snapshot | 10 ++++++++++ tools/virsh.pod | 16 ++++++++++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) diff --git a/docs/formatsnapshot.html.in b/docs/formatsnapshot.html.in index ced8bbd6db..1935e7351a 100644 --- a/docs/formatsnapshot.html.in +++ b/docs/formatsnapshot.html.in @@ -93,7 +93,9 @@ sets that snapshot as current, and the prior current snapshot is the parent of the new snapshot. Branches in the hierarchy can be formed by reverting to a snapshot with a child, then creating - another snapshot. + another snapshot. For now, the creation of external snapshots + when checkpoints exist is forbidden, although future work will + make it possible to integrate these two concepts.

        The top-level domainsnapshot element may contain diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index d0377d78a9..ca707815d9 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -15749,6 +15749,12 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, if (!(vm =3D qemuDomObjFromDomain(domain))) goto cleanup; + if (virDomainListCheckpoints(vm->checkpoints, NULL, domain, NULL, 0) >= 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create snapshot while checkpoint exists")= ); + goto cleanup; + } + cfg =3D virQEMUDriverGetConfig(driver); if (virDomainSnapshotCreateXMLEnsureACL(domain->conn, vm->def, flags) = < 0) @@ -22332,6 +22338,12 @@ static int qemuDomainRename(virDomainPtr dom, goto endjob; } + if (virDomainListCheckpoints(vm->checkpoints, NULL, dom, NULL, flags) = > 0) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("cannot rename domain with checkpoints")); + goto endjob; + } + if (virDomainObjListRename(driver->domains, vm, new_name, flags, qemuDomainRenameCallback, driver) < 0) goto endjob; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index abe51f252a..886d6720db 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7306,6 +7306,12 @@ testDomainSnapshotCreateXML(virDomainPtr domain, if (!(vm =3D testDomObjFromDomain(domain))) goto cleanup; + if (virDomainListCheckpoints(vm->checkpoints, NULL, domain, NULL, 0) >= 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create snapshot while checkpoint exists")= ); + goto cleanup; + } + if (!vm->persistent && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("cannot halt after transient domain snapshot")); @@ -7766,6 +7772,12 @@ testDomainCheckpointCreateXML(virDomainPtr domain, if (!(vm =3D testDomObjFromDomain(domain))) goto cleanup; + if (virDomainSnapshotObjListNum(vm->snapshots, NULL, 0) > 0) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create checkpoint while snapshot exists")= ); + goto cleanup; + } + if (!virDomainObjIsActive(vm)) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", _("cannot create checkpoint for inactive domain")); diff --git a/tests/virsh-checkpoint b/tests/virsh-checkpoint index 6fe5aa4c05..8f964b5822 100755 --- a/tests/virsh-checkpoint +++ b/tests/virsh-checkpoint @@ -38,6 +38,10 @@ $abs_top_builddir/tools/virsh --connect test:///default = >out 2>err ' checkpoint-create-as test c1 checkpoint-create-as test c3 checkpoint-create-as test c2 + # snapshots cannot be created while checkpoints exist + echo --err marker + snapshot-create-as test s1 + echo --err marker # Checking tree view (siblings sorted alphabetically) checkpoint-list test --tree # Demonstrate list filtering @@ -77,6 +81,9 @@ Domain checkpoint c1 created Domain checkpoint c3 created Domain checkpoint c2 created + + + c1 | +- c3 @@ -126,6 +133,9 @@ compare exp out.cooked || fail=3D1 cat < exp || fail=3D1 error: operation failed: domain moment c1 already exists +error: marker +error: Operation not supported: cannot create snapshot while checkpoint ex= ists +error: marker EOF compare exp err || fail=3D1 diff --git a/tests/virsh-snapshot b/tests/virsh-snapshot index b23d949f62..fa321d3354 100755 --- a/tests/virsh-snapshot +++ b/tests/virsh-snapshot @@ -45,6 +45,10 @@ $abs_top_builddir/tools/virsh --connect test:///default = >out 2>err ' snapshot-revert test s1 snapshot-create-as test s7 snapshot-create-as test s8 + # checkpoints cannot be created while snapshots exist + echo --err marker + checkpoint-create-as test c1 + echo --err marker # Checking tree view (siblings sorted alphabetically) snapshot-list test --tree # Current was last one created, but we can change that @@ -102,6 +106,9 @@ Domain snapshot s4 created Domain snapshot s7 created Domain snapshot s8 created + + + s1 | +- s3 @@ -175,6 +182,9 @@ compare exp out.cooked || fail=3D1 cat < exp || fail=3D1 error: operation failed: domain moment s1 already exists error: marker +error: Operation not supported: cannot create checkpoint while snapshot ex= ists +error: marker +error: marker error: domain 'test' has no current snapshot error: marker EOF diff --git a/tools/virsh.pod b/tools/virsh.pod index f58578e3b3..af739bec24 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -4669,6 +4669,10 @@ a persistent domain. However, for transient domains= , snapshot metadata is silently lost when the domain quits running (whether by command such as B or by internal guest action). +For now, it is not possible to create snapshots in a domain that has +checkpoints, although this restriction will be lifted in a future +release. + =3Ditem B I {[I<--print-xml>] [I<--no-metadata>] [I<--halt>] [I<--reuse-external>]} [I] [I] [I<--disk-only> [I<--quiesce>]] [I<--atomic>] @@ -4735,6 +4739,10 @@ If I<--live> is specified, libvirt takes the snapsho= t while the guest is running. This increases the size of the memory image of the external snapshot. This is currently supported only for external full system snapsh= ots. +For now, it is not possible to create snapshots in a domain that has +checkpoints, although this restriction will be lifted in a future +release. + =3Ditem B I {[I<--name>] | [I<--security-info>] | [I]} @@ -4943,6 +4951,10 @@ a persistent domain. However, for transient domains= , checkpoint metadata is silently lost when the domain quits running (whether by command such as B or by internal guest action). +For now, it is not possible to create checkpoints in a domain that has +snapshots, although this restriction will be lifted in a future +release. + =3Ditem B I [I<--print-xml>] [I] [I] [I<--quiesce>] [I<--diskspec>] B]... @@ -4966,6 +4978,10 @@ If I<--quiesce> is specified, libvirt will try to us= e guest agent to freeze and unfreeze domain's mounted file systems. However, if domain has no guest agent, checkpoint creation will fail. +For now, it is not possible to create checkpoints in a domain that has +snapshots, although this restriction will be lifted in a future +release. + =3Ditem B I I Edit the XML configuration file for I of a domain. --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list