From nobody Sat Apr 27 19:55:39 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=1555510205; cv=none; d=zoho.com; s=zohoarc; b=KLYPqznAFRyxcIGoBNnn/23K11VVib38qG470PQHsswcmmiNDP9qTsaXHRzZIqhbEA+vJZw4b4mMfHvLLqx0yQsmLi1UY8lKr9XaosC010sb39Ah8aeXHbX3ti0x2jk77G47TQ+qi1u3pSCBEP5kbQbzdJ4jhQO+8adRWDAz7Pw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510205; 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=EG8Liuk/7PrfB2/qm8bb/5fZGoc5pzm/kCUTjl8uCa0=; b=WORaerc/sYo2eLZ3qPLSWoolr2/+Am+h+4rArxmLN1HGos1IYjuFiGaEBZw+fCVGtXCOSSFLwuRrRHkh2L3ZMsr1+NqU806cYDdKL9QeU6Rbi+MsOSjjskyCrQ4CdaiTey/+giwpK2GNNddaGM5hYt3FX1SenrvFJF5RYvHye5A= 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 1555510205737199.23207896195174; Wed, 17 Apr 2019 07:10:05 -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 AAFFF3001A73; Wed, 17 Apr 2019 14:10:03 +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 6896460148; Wed, 17 Apr 2019 14:10:03 +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 E76B6181AC92; Wed, 17 Apr 2019 14:10:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9Stb023675 for ; Wed, 17 Apr 2019 10:09:28 -0400 Received: by smtp.corp.redhat.com (Postfix) id 958D16014E; Wed, 17 Apr 2019 14:09:28 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id C468960148; Wed, 17 Apr 2019 14:09:27 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:01 -0500 Message-Id: <20190417140921.11964-2-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 01/21] 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-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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 17 Apr 2019 14:10:04 +0000 (UTC) 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). 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 | 202 ++++++++++++++++++ docs/index.html.in | 3 +- docs/schemas/domaincheckpoint.rng | 87 ++++++++ libvirt.spec.in | 1 + mingw-libvirt.spec.in | 2 + tests/Makefile.am | 2 + tests/domaincheckpointxml2xmlin/empty.xml | 1 + tests/domaincheckpointxml2xmlin/sample.xml | 7 + tests/domaincheckpointxml2xmlin/size.xml | 4 + tests/domaincheckpointxml2xmlout/empty.xml | 7 + tests/domaincheckpointxml2xmlout/redefine.xml | 63 ++++++ tests/domaincheckpointxml2xmlout/sample.xml | 12 ++ tests/domaincheckpointxml2xmlout/size.xml | 11 + tests/virschematest.c | 2 + 16 files changed, 406 insertions(+), 2 deletions(-) create mode 100644 docs/formatcheckpoint.html.in create mode 100644 docs/schemas/domaincheckpoint.rng create mode 100644 tests/domaincheckpointxml2xmlin/empty.xml create mode 100644 tests/domaincheckpointxml2xmlin/sample.xml create mode 100644 tests/domaincheckpointxml2xmlin/size.xml create mode 100644 tests/domaincheckpointxml2xmlout/empty.xml create mode 100644 tests/domaincheckpointxml2xmlout/redefine.xml create mode 100644 tests/domaincheckpointxml2xmlout/sample.xml create mode 100644 tests/domaincheckpointxml2xmlout/size.xml diff --git a/docs/docs.html.in b/docs/docs.html.in index d0ff844d0c..f6e599b77b 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -80,7 +80,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 640a9957ee..20f9ef3348 100644 --- a/docs/format.html.in +++ b/docs/format.html.in @@ -25,6 +25,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..e2e9b1173d --- /dev/null +++ b/docs/formatcheckpoint.html.in @@ -0,0 +1,202 @@ + + + + +

    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. Most disk + checkpoints are created in conjunction with a backup + via virDomainBackupBegin() or with a snapshot + via virDomainSnapshotCreateXML2; however, libvirt + also exposes enough support to create disk checkpoints + independently from a backup operation + via virDomainCheckpointCreateXML(). +

      +

      + 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. +

      +

      + Checkpoints are maintained in a hierarchy. A domain can have a + current checkpoint, which is the most recent checkpoint compared + to the current state of the domain (although a domain might have + checkpoints without a current checkpoint, if checkpoints have + been deleted in the meantime). Creating a checkpoint sets that + checkpoint as current and the prior current checkpoint is the + parent of the new checkpoint. In the future, reverting to a + domain snapshot may also affect the current checkpoint. +

      +

      + 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
      +
      An optional readonly representation of the parent of this + checkpoint. If present, this element contains exactly one + child element, name. +
      +
      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_SNAPSHOT_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 f593445d06..0315915402 100644 --- a/docs/index.html.in +++ b/docs/index.html.in @@ -69,7 +69,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..46d3ec1259 --- /dev/null +++ b/docs/schemas/domaincheckpoint.rng @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + no + + + + + bitmap + + + + + + + + + + + + + + + + + + diff --git a/libvirt.spec.in b/libvirt.spec.in index 18f0a0e217..6c2fc3fa06 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 8a96ea914c..d11f96fa6f 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -233,6 +233,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 46d94d2236..2648d0d75d 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -83,6 +83,8 @@ EXTRA_DIST =3D \ commanddata \ cputestdata \ domaincapsschemadata \ + domaincheckpointxml2xmlin \ + domaincheckpointxml2xmlout \ domainconfdata \ domainschemadata \ domainsnapshotxml2xmlin \ diff --git a/tests/domaincheckpointxml2xmlin/empty.xml b/tests/domaincheckp= ointxml2xmlin/empty.xml new file mode 100644 index 0000000000..dc36449142 --- /dev/null +++ b/tests/domaincheckpointxml2xmlin/empty.xml @@ -0,0 +1 @@ + diff --git a/tests/domaincheckpointxml2xmlin/sample.xml b/tests/domaincheck= pointxml2xmlin/sample.xml new file mode 100644 index 0000000000..70ed964e1e --- /dev/null +++ b/tests/domaincheckpointxml2xmlin/sample.xml @@ -0,0 +1,7 @@ + + Completion of updates after OS install + + + + + diff --git a/tests/domaincheckpointxml2xmlin/size.xml b/tests/domaincheckpo= intxml2xmlin/size.xml new file mode 100644 index 0000000000..99ce84c7a0 --- /dev/null +++ b/tests/domaincheckpointxml2xmlin/size.xml @@ -0,0 +1,4 @@ + + c2 + something fun + diff --git a/tests/domaincheckpointxml2xmlout/empty.xml b/tests/domaincheck= pointxml2xmlout/empty.xml new file mode 100644 index 0000000000..6fe6124ce4 --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/empty.xml @@ -0,0 +1,7 @@ + + 1525889631 + 1525889631 + + + + diff --git a/tests/domaincheckpointxml2xmlout/redefine.xml b/tests/domainch= eckpointxml2xmlout/redefine.xml new file mode 100644 index 0000000000..823ae1ee2d --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/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/domaincheckpointxml2xmlout/sample.xml b/tests/domainchec= kpointxml2xmlout/sample.xml new file mode 100644 index 0000000000..91cfac27df --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/sample.xml @@ -0,0 +1,12 @@ + + 1525889631 + Completion of updates after OS install + + 1525111885 + + 1525889631 + + + + + diff --git a/tests/domaincheckpointxml2xmlout/size.xml b/tests/domaincheckp= ointxml2xmlout/size.xml new file mode 100644 index 0000000000..4f11cfa680 --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/size.xml @@ -0,0 +1,11 @@ + + c2 + something fun + + 1525111885 + + 1553648510 + + + + diff --git a/tests/virschematest.c b/tests/virschematest.c index 56bdcb2f88..fa99e67a57 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", "domaincheckpointxml2xmlin", + "domaincheckpointxml2xmlout"); DO_TEST_DIR("domainsnapshot.rng", "domainsnapshotxml2xmlin", "domainsnapshotxml2xmlout"); 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 Sat Apr 27 19:55:39 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=1555510184; cv=none; d=zoho.com; s=zohoarc; b=TDh/oEpnPRqiFknMYB4qIQAi4z7n3mKqRU1fzJRFpZN4muwD+s9ROxXZjiwRAfORuB97DUROgoPOoSjVis/RAg54VI60x3pIzOv5VqX7ynVqEME00HVQimV7+LDUc6u/ZB6NcOncOsigkA4FD5v6S6RHEM1eRdjqTAPhBgx3If4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510184; 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=Viapi0pes6lC5oQUNOPkvwQOiRTKJOdtn/vwSRb5KX0=; b=MxePhkMwwsNhuU2voqQoGNwJdMn5R7LvVyBQ51yNGFpFh8wuvA/WAce8OPYjYvv/ufmoqnf9MSHzG37LvZQYiPXPXlYixjOLML/lJhVOqS13atAnjF9jhUyKMTSjCHO9MoQ+RKmhOmuEht6U4CGr+eYa8CylDfmZtQmf9Q39Uno= 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 1555510184368646.4953405890092; Wed, 17 Apr 2019 07:09:44 -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 1F917306C9E0; Wed, 17 Apr 2019 14:09:41 +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 E68DB5C226; Wed, 17 Apr 2019 14:09:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D723A181AC8F; Wed, 17 Apr 2019 14:09:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9TB6023685 for ; Wed, 17 Apr 2019 10:09:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E1DF6015A; Wed, 17 Apr 2019 14:09:29 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id BED5560148; Wed, 17 Apr 2019 14:09:28 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:02 -0500 Message-Id: <20190417140921.11964-3-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 02/21] backup: Document new XML for backups 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.43]); Wed, 17 Apr 2019 14:09:41 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Prepare for new backup APIs by describing the XML that will represent a backup. The XML resembles snapshots and checkpoints in being able to select actions for a set of disks, but has other differences. It can support both push model (the hypervisor does the backup directly into the destination file) and pull model (the hypervisor exposes an access port for a third party to grab what is necessary). Add testsuite coverage for some minimal uses of the XML. The element within tries to model the same elements as a under , but sharing the RNG grammar proved to be hairy. That is in part because while use to describe a host resource in use by the guest, a backup job is using a host resource that is not visible to the guest: a push backup action is instead describing a (which ultimately could be a remote network resource, but for simplicity the RNG just validates a local file for now), and a pull backup action is instead describing a temporary local file (which probably should not be a remote resource). A future refactoring may thus introduce some way to parameterize RNG to accept ... so that the name of the subelement can be for domain, or or as needed for backups. Future patches may improve this area of code. Signed-off-by: Eric Blake --- docs/docs.html.in | 3 +- docs/format.html.in | 1 + docs/formatbackup.html.in | 182 +++++++++++++++ docs/index.html.in | 3 +- docs/schemas/domainbackup.rng | 219 +++++++++++++++++++ libvirt.spec.in | 1 + mingw-libvirt.spec.in | 2 + tests/Makefile.am | 2 + tests/domainbackupxml2xmlin/backup-pull.xml | 9 + tests/domainbackupxml2xmlin/backup-push.xml | 9 + tests/domainbackupxml2xmlin/empty.xml | 1 + tests/domainbackupxml2xmlout/backup-pull.xml | 9 + tests/domainbackupxml2xmlout/backup-push.xml | 9 + tests/domainbackupxml2xmlout/empty.xml | 7 + tests/virschematest.c | 2 + 15 files changed, 457 insertions(+), 2 deletions(-) create mode 100644 docs/formatbackup.html.in create mode 100644 docs/schemas/domainbackup.rng create mode 100644 tests/domainbackupxml2xmlin/backup-pull.xml create mode 100644 tests/domainbackupxml2xmlin/backup-push.xml create mode 100644 tests/domainbackupxml2xmlin/empty.xml create mode 100644 tests/domainbackupxml2xmlout/backup-pull.xml create mode 100644 tests/domainbackupxml2xmlout/backup-push.xml create mode 100644 tests/domainbackupxml2xmlout/empty.xml diff --git a/docs/docs.html.in b/docs/docs.html.in index f6e599b77b..b6b03313fa 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -81,7 +81,8 @@ node devices, secrets, snapshots, - checkpoints + checkpoints, + backup jobs
      URI format
      The URI formats used for connecting to libvirt
      diff --git a/docs/format.html.in b/docs/format.html.in index 20f9ef3348..e287b430bc 100644 --- a/docs/format.html.in +++ b/docs/format.html.in @@ -26,6 +26,7 @@
    • Secrets
    • Snapshots
    • Checkpoints
    • +
    • Backup jobs
    • Command line validation

      diff --git a/docs/formatbackup.html.in b/docs/formatbackup.html.in new file mode 100644 index 0000000000..8dccfa921f --- /dev/null +++ b/docs/formatbackup.html.in @@ -0,0 +1,182 @@ + + + + +

      Backup XML format

      + +
        + +

        Backup XML

        + +

        + Creating a backup, whether full or incremental, is done + via virDomainBackupBegin(), which takes an XML + description of the actions to perform, as well as an optional + second XML document describing a + checkpoint to create at the same point in time. +

        +

        + There are two general modes for backups: a push mode (where the + hypervisor writes out the data to the destination file, which + may be local or remote), and a pull mode (where the hypervisor + creates an NBD server that a third-party client can then read as + needed, and which requires the use of temporary storage, + typically local, until the backup is complete). +

        +

        + The instructions for beginning a backup job are provided as + attributes and elements of the + top-level domainbackup element. This element + includes an optional attribute mode which can be + either "push" or "pull" (default + push). virDomainBackupGetXMLDesc() can be used to + see the actual values selected for elements omitted during + creation (for example, learning which port the NBD server is + using in the pull model or what file names libvirt generated + when none were supplied). The following child elements are + supported: +

        +
        +
        id
        +
        Ignored on input, this element is the job id of the backup + operation returned on success + from virDomainBackupBegin(), and is used for + selecting which backup operation to target + during virDomainBackupGetXMLDesc() + and virDomainBackupEnd(). (Note that until + additional APIs are added for supporting parallel jobs, it is + also possible to ignore this element and use the job + id 0 to refer to the one and only current backup + job.)
        +
        incremental
        +
        An optional element giving the name of an existing + checkpoint of the domain, which will be used to make this + backup an incremental one. In the push model, only changes + since the named checkpoint are written to the destination. In + the pull model, the NBD server uses the + NBD_OPT_SET_META_CONTEXT extension to advertise to the client + which portions of the export contain changes since the named + checkpoint. If omitted, a full backup is performed. +
        +
        server
        +
        Present only for a pull mode backup. Contains the same + attributes as + the protocol + element of a disk attached via NBD in the domain (such as + transport, socket, name, port, or tls), necessary to set up an + NBD server that exposes the content of each disk at the time + the backup is started. +
        +
        disks
        +
        An optional listing of instructions for disks participating + in the backup (if omitted, all disks participate and libvirt + attempts to generate filenames by appending the current + timestamp as a suffix). If the entire element was omitted on + input, then all disks participate in the backup, otherwise, + only the disks explicitly listed which do not also + use backup=3D'no' will participate. On output, this + is the state of each of the domain's disk in relation to the + backup operation. +
        +
        disk
        +
        This sub-element describes the backup properties of a + specific disk, with the following attributes and child + elements: +
        +
        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.
        +
        backup
        +
        An optional attribute to describe the state of the + backup for the given disk. On input, the + value no skips a backup of the disk, and + any other value is ignored; on output, other values + such as begin, inprogress, + or ready track the backup progress that + libvirt has observed for that disk.
        +
        type
        +
        An optional attribute to describe the type of the + disk, except when backup=3D'no' is + used. Valid values include file + or block for both push and pull model + backups; in the future, network may be + added for push model backups. Similar to a disk + declaration for a domain, the choice of type controls + what additional sub-elements are needed to describe + the destination (such as protocol for a + network destination).
        +
        target
        +
        Valid only for push mode backups, this is the + primary sub-element that describes the file name of + the backup destination, similar to + the source sub-element of a domain + disk. An optional sub-element driver can + also be used, with an attribute type to + specify a destination format different from + qcow2. Additionally, if a push backup is not + incremental, target may contain an + optional attribute shallow=3D"on" so that + the destination file copies only the top-most source + file in a backing chain, rather than collapsing the + entire chain into the copy.
        +
        scratch
        +
        Valid only for pull mode backups, this is the + primary sub-element that describes the file name of + the local scratch file to be used in facilitating the + backup, and is similar to the source + sub-element of a domain disk.
        +
        +
        +
        +
        +
        + +

        Examples

        + +

        Use virDomainBackupBegin() to perform a full + backup using push mode. The example lets libvirt pick the + destination and format for 'vda', fully specifies that we want a + raw backup of 'vdb', and omits 'vdc' from the operation. +

        +
        +<domainbackup>
        +  <disks/>
        +    <disk name=3D'vda'/>
        +    <disk name=3D'vdb' type=3D'file'>
        +      <target file=3D'/path/to/vdb.backup'/>
        +      <driver type=3D'raw'/>
        +    </disk>
        +    <disk name=3D'vdc' backup=3D'no'/>
        +  </disks/>
        +</domainbackup>
        +    
        + +

        If the previous full backup also passed a parameter describing + checkpoint XML that resulted + in a checkpoint named 1525889631, we can make + another call to virDomainBackupBegin() to perform + an incremental backup of just the data changed since that + checkpoint, this time using the following XML to start a pull + model export of the 'vda' and 'vdb' disks, where a third-party + NBD client connecting to '/path/to/server' completes the backup + (omitting 'vdc' from the explicit list has the same effect as + the backup=3D'no' from the previous example): +

        +
        +<domainbackup mode=3D"pull">
        +  <incremental>1525889631</incremental>
        +  <server transport=3D"unix" socket=3D"/path/to/server"/>
        +  <disks/>
        +    <disk name=3D'vda' type=3D'file'>
        +      <scratch file=3D'/path/to/file1.scratch'/>
        +    </disk>
        +  </disks/>
        +</domainbackup>
        +    
        + + diff --git a/docs/index.html.in b/docs/index.html.in index 0315915402..167a58da58 100644 --- a/docs/index.html.in +++ b/docs/index.html.in @@ -70,7 +70,8 @@ node devices, secrets, snapshots, - checkpoints + checkpoints, + backup jobs
        Wiki
        Read further community contributed content
        diff --git a/docs/schemas/domainbackup.rng b/docs/schemas/domainbackup.rng new file mode 100644 index 0000000000..92327e7077 --- /dev/null +++ b/docs/schemas/domainbackup.rng @@ -0,0 +1,219 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + push + + + + + + + pull + + + + + + + + tcp + + + + + + + + + + + + + + + + + + unix + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + begin + inprogress + ready + + + + + + + + + + + + + + + + + + + on + + + + + + no + + + + + + + + file + + + + + + + + + + + + + + + + + block + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + file + + + + + + + + + + + + + block + + + + + + + + + + + + + + + + + diff --git a/libvirt.spec.in b/libvirt.spec.in index 6c2fc3fa06..76f6d13673 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -1801,6 +1801,7 @@ exit 0 %{_datadir}/libvirt/schemas/capability.rng %{_datadir}/libvirt/schemas/cputypes.rng %{_datadir}/libvirt/schemas/domain.rng +%{_datadir}/libvirt/schemas/domainbackup.rng %{_datadir}/libvirt/schemas/domaincaps.rng %{_datadir}/libvirt/schemas/domaincheckpoint.rng %{_datadir}/libvirt/schemas/domaincommon.rng diff --git a/mingw-libvirt.spec.in b/mingw-libvirt.spec.in index d11f96fa6f..562fd1a1e9 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/capability.rng %{mingw32_datadir}/libvirt/schemas/cputypes.rng %{mingw32_datadir}/libvirt/schemas/domain.rng +%{mingw32_datadir}/libvirt/schemas/domainbackup.rng %{mingw32_datadir}/libvirt/schemas/domaincaps.rng %{mingw32_datadir}/libvirt/schemas/domaincheckpoint.rng %{mingw32_datadir}/libvirt/schemas/domaincommon.rng @@ -321,6 +322,7 @@ rm -rf $RPM_BUILD_ROOT%{mingw64_libexecdir}/libvirt-gue= sts.sh %{mingw64_datadir}/libvirt/schemas/capability.rng %{mingw64_datadir}/libvirt/schemas/cputypes.rng %{mingw64_datadir}/libvirt/schemas/domain.rng +%{mingw64_datadir}/libvirt/schemas/domainbackup.rng %{mingw64_datadir}/libvirt/schemas/domaincaps.rng %{mingw64_datadir}/libvirt/schemas/domaincheckpoint.rng %{mingw64_datadir}/libvirt/schemas/domaincommon.rng diff --git a/tests/Makefile.am b/tests/Makefile.am index 2648d0d75d..576e9d6fc6 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -82,6 +82,8 @@ EXTRA_DIST =3D \ capabilityschemadata \ commanddata \ cputestdata \ + domainbackupxml2xmlin \ + domainbackupxml2xmlout \ domaincapsschemadata \ domaincheckpointxml2xmlin \ domaincheckpointxml2xmlout \ diff --git a/tests/domainbackupxml2xmlin/backup-pull.xml b/tests/domainback= upxml2xmlin/backup-pull.xml new file mode 100644 index 0000000000..2ce5cd6711 --- /dev/null +++ b/tests/domainbackupxml2xmlin/backup-pull.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlin/backup-push.xml b/tests/domainback= upxml2xmlin/backup-push.xml new file mode 100644 index 0000000000..1b7d3061fd --- /dev/null +++ b/tests/domainbackupxml2xmlin/backup-push.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlin/empty.xml b/tests/domainbackupxml2= xmlin/empty.xml new file mode 100644 index 0000000000..7ed511f97b --- /dev/null +++ b/tests/domainbackupxml2xmlin/empty.xml @@ -0,0 +1 @@ + diff --git a/tests/domainbackupxml2xmlout/backup-pull.xml b/tests/domainbac= kupxml2xmlout/backup-pull.xml new file mode 100644 index 0000000000..2ce5cd6711 --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-pull.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlout/backup-push.xml b/tests/domainbac= kupxml2xmlout/backup-push.xml new file mode 100644 index 0000000000..1b7d3061fd --- /dev/null +++ b/tests/domainbackupxml2xmlout/backup-push.xml @@ -0,0 +1,9 @@ + + 1525889631 + + + + + + + diff --git a/tests/domainbackupxml2xmlout/empty.xml b/tests/domainbackupxml= 2xmlout/empty.xml new file mode 100644 index 0000000000..13600fbb1c --- /dev/null +++ b/tests/domainbackupxml2xmlout/empty.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/tests/virschematest.c b/tests/virschematest.c index fa99e67a57..82690db8ab 100644 --- a/tests/virschematest.c +++ b/tests/virschematest.c @@ -221,6 +221,8 @@ mymain(void) "lxcxml2xmloutdata", "bhyvexml2argvdata", "genericxml2xmli= ndata", "genericxml2xmloutdata", "xlconfigdata", "libxlxml2domconf= igdata", "qemuhotplugtestdomains"); + DO_TEST_DIR("domainbackup.rng", "domainbackupxml2xmlin", + "domainbackupxml2xmlout"); DO_TEST_DIR("domaincaps.rng", "domaincapsschemadata"); DO_TEST_DIR("domaincheckpoint.rng", "domaincheckpointxml2xmlin", "domaincheckpointxml2xmlout"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510209; cv=none; d=zoho.com; s=zohoarc; b=orcldqYWY74ehjfCvXJjEpqJhkVgaCv3SWAAR1CejqKYPBlM8jt6cEUjguYfI6K+xD4YW8ONOYiBglqX/pTPkrfCJXqKgdpUhspxdvxQI37pcZQoRx57B8zsQir18+GbRyu0Es9KPXTeG13mFTYPA7VqGOyr/XnUCf5aWcrWSjQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510209; 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=3rbxoD3XhnzeLtSBz9sQe5SXm1ZPadxGj2n+wHKAX5E=; b=Z13psEyZVH1DKVNUyY//lSglccKcQ74vxJiBqlIQAfGMAKD64HLCqz4fPKMbl6jQAg8kWW2kQhqCwzJXs20HoJi/pgwq0bchta7ZqfhLJ6f7I1NKVfQRfzreWPNaU7tVvfb9lR/8AAqBVQU5vvwBBDuzCxtq6tpsQMk8dJQ6wPM= 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 155551020954331.560123344388558; Wed, 17 Apr 2019 07:10:09 -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 2AEBA80467; Wed, 17 Apr 2019 14:10: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 DA4D01001E9C; Wed, 17 Apr 2019 14:10: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 739A0181AC48; Wed, 17 Apr 2019 14:10:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9U13023695 for ; Wed, 17 Apr 2019 10:09:30 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8FB7C60159; Wed, 17 Apr 2019 14:09:30 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id B31E160148; Wed, 17 Apr 2019 14:09:29 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:03 -0500 Message-Id: <20190417140921.11964-4-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 03/21] 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-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.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, 17 Apr 2019 14:10:03 +0000 (UTC) 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. 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 virDomainCheckpointHasMetadata virDomainSnapshotIsCurrent virDomainCheckpointIsCurrent Operate on a domain object to list all children: virDomainSnapshotNum (no counterpart, this is the old virDomainSnapshotListNames racy interface) virDomainSnapshotListAllSnapshots virDomainListAllCheckpoints Operate on a child object to list descendents: virDomainSnapshotNumChildren (no counterpart, this is the old virDomainSnapshotListChildrenNames racy interface) virDomainSnapshotListAllChildren virDomainCheckpointListAllChildren Operate on a domain to locate a particular child: virDomainSnapshotLookupByName virDomainCheckpointLookupByName virDomainHasCurrentSnapshot virDomainHasCurrentCheckpoint virDomainSnapshotCurrent virDomainCheckpointCurrent 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 | 161 +++++ include/libvirt/libvirt-domain.h | 6 + include/libvirt/libvirt.h | 5 +- src/conf/virdomainmomentobjlist.h | 5 +- src/driver-hypervisor.h | 58 ++ 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 | 750 ++++++++++++++++++++ src/libvirt-domain.c | 18 +- src/libvirt_public.syms | 20 + 15 files changed, 1026 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..9d37a4e29c --- /dev/null +++ b/include/libvirt/libvirt-domain-checkpoint.h @@ -0,0 +1,161 @@ +/* + * 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_CURRENT =3D (1 << 1), /* With redefin= e, make + checkpoint cur= rent */ + VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA =3D (1 << 2), /* Make checkpo= int without + remembering it= */ + VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE =3D (1 << 3), /* 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 */ + + VIR_DOMAIN_CHECKPOINT_LIST_METADATA =3D (1 << 4), /* Filter by chec= kpoints + which have metad= ata */ + VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA =3D (1 << 5), /* Filter by chec= kpoints + with no metadata= */ +} 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); + +/* Check whether a domain has a checkpoint which is currently used */ +int virDomainHasCurrentCheckpoint(virDomainPtr domain, unsigned int flags); + +/* Get a handle to the current checkpoint */ +virDomainCheckpointPtr virDomainCheckpointCurrent(virDomainPtr domain, + unsigned int flags); + +/* Get a handle to the parent checkpoint, if one exists */ +virDomainCheckpointPtr virDomainCheckpointGetParent(virDomainCheckpointPtr= checkpoint, + unsigned int flags); + +/* Determine if a checkpoint is the current checkpoint of its domain. */ +int virDomainCheckpointIsCurrent(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +/* Determine if checkpoint has metadata that would prevent domain deletion= . */ +int virDomainCheckpointHasMetadata(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 7d36820b5a..fe9ff011fe 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -1788,6 +1788,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; @@ -1826,6 +1829,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 6481c771de..04808e1ac7 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -71,8 +71,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 5315e33dde..49b676dbbb 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -1328,6 +1328,53 @@ 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 int +(*virDrvDomainHasCurrentCheckpoint)(virDomainPtr domain, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointGetParent)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef virDomainCheckpointPtr +(*virDrvDomainCheckpointCurrent)(virDomainPtr domain, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointIsCurrent)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointHasMetadata)(virDomainCheckpointPtr checkpoint, + unsigned int flags); + +typedef int +(*virDrvDomainCheckpointDelete)(virDomainCheckpointPtr checkpoint, + unsigned int flags); typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1580,6 +1627,17 @@ struct _virHypervisorDriver { virDrvConnectBaselineHypervisorCPU connectBaselineHypervisorCPU; virDrvNodeGetSEVInfo nodeGetSEVInfo; virDrvDomainGetLaunchSecurityInfo domainGetLaunchSecurityInfo; + virDrvDomainCheckpointCreateXML domainCheckpointCreateXML; + virDrvDomainCheckpointGetXMLDesc domainCheckpointGetXMLDesc; + virDrvDomainListAllCheckpoints domainListAllCheckpoints; + virDrvDomainCheckpointListAllChildren domainCheckpointListAllChildren; + virDrvDomainCheckpointLookupByName domainCheckpointLookupByName; + virDrvDomainHasCurrentCheckpoint domainHasCurrentCheckpoint; + virDrvDomainCheckpointGetParent domainCheckpointGetParent; + virDrvDomainCheckpointCurrent domainCheckpointCurrent; + virDrvDomainCheckpointIsCurrent domainCheckpointIsCurrent; + virDrvDomainCheckpointHasMetadata domainCheckpointHasMetadata; + virDrvDomainCheckpointDelete domainCheckpointDelete; }; diff --git a/docs/Makefile.am b/docs/Makefile.am index 29b0761a2b..f608b7994a 100644 --- a/docs/Makefile.am +++ b/docs/Makefile.am @@ -25,6 +25,7 @@ apihtml =3D \ apihtml_generated =3D \ html/libvirt-libvirt-common.html \ html/libvirt-libvirt-domain.html \ + html/libvirt-libvirt-domain-checkpoint.html \ html/libvirt-libvirt-domain-snapshot.html \ html/libvirt-libvirt-event.html \ html/libvirt-libvirt-host.html \ @@ -305,6 +306,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 \ @@ -321,6 +323,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 b6b03313fa..400b149791 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -99,6 +99,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 76f6d13673..3513e080f3 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 562fd1a1e9..d1889adade 100644 --- a/mingw-libvirt.spec.in +++ b/mingw-libvirt.spec.in @@ -265,6 +265,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 @@ -355,6 +356,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 9dd4ee7d99..88af551664 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 7d452a9490..38df84d0c1 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..8bab4011a3 --- /dev/null +++ b/src/libvirt-domain-checkpoint.c @@ -0,0 +1,750 @@ +/* + * 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. Typically, it is + * more common to create a new checkpoint as part of kicking off a + * backup job with virDomainBackupBegin() or when creating a snapshot + * with virDomainSnapshotCreateXML2(); however, it is also possible to + * start a checkpoint without a backup. + * + * See Checkpoint XM= L + * 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). When redefining + * checkpoint metadata, the domain's current checkpoint will not be + * altered unless the VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT flag is + * also present. It is an error to request the + * VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT flag without + * VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE. Not all hypervisors support + * these flags. + * + * If @flags includes VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA, then + * the domain's disk images are modified according to @xmlDesc, but + * libvirt does not track any metadata (similar to immediately calling + * virDomainCheckpointDelete() with + * VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY). This flag is + * incompatible with VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE. + * + * 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_REQUIRE_FLAG_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT, + VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, + error); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE, + VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA, + 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 snapshot 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). + * + * The next group of @flags is VIR_DOMAIN_CHECKPOINT_LIST_METADATA and + * VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA, for filtering checkpoints based= on + * whether they have metadata that would prevent the removal of the last + * reference to a domain. + * + * 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 dom; + dom =3D conn->driver->domainCheckpointLookupByName(domain, name, f= lags); + if (!dom) + goto error; + return dom; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainHasCurrentCheckpoint: + * @domain: pointer to the domain object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the domain has a current checkpoint. + * + * Returns 1 if such checkpoint exists, 0 if it doesn't, -1 on error. + */ +int +virDomainHasCurrentCheckpoint(virDomainPtr domain, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "flags=3D0x%x", flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + if (conn->driver->domainHasCurrentCheckpoint) { + int ret =3D conn->driver->domainHasCurrentCheckpoint(domain, flags= ); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointCurrent: + * @domain: a domain object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Get the current checkpoint for a domain, 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 + * current domain checkpoint cannot be found, then the + * VIR_ERR_NO_DOMAIN_CHECKPOINT error is raised. + */ +virDomainCheckpointPtr +virDomainCheckpointCurrent(virDomainPtr domain, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "flags=3D0x%x", flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + if (conn->driver->domainCheckpointCurrent) { + virDomainCheckpointPtr snap; + snap =3D conn->driver->domainCheckpointCurrent(domain, flags); + if (!snap) + goto error; + return snap; + } + + 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 snap; + snap =3D conn->driver->domainCheckpointGetParent(checkpoint, flags= ); + if (!snap) + goto error; + return snap; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainCheckpointIsCurrent: + * @checkpoint: a checkpoint object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the given checkpoint is the domain's current checkpoint. = See + * also virDomainHasCurrentCheckpoint(). + * + * Returns 1 if current, 0 if not current, or -1 on error. + */ +int +virDomainCheckpointIsCurrent(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; + + if (conn->driver->domainCheckpointIsCurrent) { + int ret; + ret =3D conn->driver->domainCheckpointIsCurrent(checkpoint, flags); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainCheckpointHasMetadata: + * @checkpoint: a checkpoint object + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * Determine if the given checkpoint is associated with libvirt metadata + * that would prevent the deletion of the domain. + * + * Returns 1 if the checkpoint has metadata, 0 if the checkpoint exists wi= thout + * help from libvirt, or -1 on error. + */ +int +virDomainCheckpointHasMetadata(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; + + if (conn->driver->domainCheckpointHasMetadata) { + int ret; + ret =3D conn->driver->domainCheckpointHasMetadata(checkpoint, flag= s); + if (ret < 0) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * 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. Likewise, if the + * checkpoint being deleted was the current checkpoint, the parent + * checkpoint becomes the new current checkpoint. + * + * 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 baf21824fe..44438c3be8 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -6227,8 +6227,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 */ @@ -6284,6 +6285,15 @@ virDomainUndefine(virDomainPtr domain) * whether this flag is present. On hypervisors 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_SNAPSHOTS_METADATA in @flags will also remove + * that metadata. Omitting the flag will cause the undefine of an + * inactive domain to fail. Active checkpoints will retain checkpoint + * metadata until the (now-transient) domain halts, regardless of + * whether this flag is present. On hypervisors 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. @@ -6444,7 +6454,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 dbce3336d5..a54804682e 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -819,4 +819,24 @@ LIBVIRT_5.2.0 { virConnectGetStoragePoolCapabilities; } LIBVIRT_4.10.0; +LIBVIRT_5.3.0 { + global: + virDomainCheckpointCreateXML; + virDomainCheckpointCurrent; + virDomainCheckpointDelete; + virDomainCheckpointFree; + virDomainCheckpointGetConnect; + virDomainCheckpointGetDomain; + virDomainCheckpointGetName; + virDomainCheckpointGetParent; + virDomainCheckpointGetXMLDesc; + virDomainCheckpointHasMetadata; + virDomainCheckpointIsCurrent; + virDomainCheckpointListAllChildren; + virDomainCheckpointLookupByName; + virDomainCheckpointRef; + virDomainHasCurrentCheckpoint; + virDomainListAllCheckpoints; +} LIBVIRT_5.2.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 Sat Apr 27 19:55:39 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=1555510222; cv=none; d=zoho.com; s=zohoarc; b=ndzncLe5M7tHJw59B3HbVDFxX5AhpfmqiLUN/PeL0jPR4YXKKzZy+tdcf1B43Si1xGCv/Gnba1WYEQ3dmQTb/uKo9cZUnKJP9/+wBGMv1jBnV1ZywMMu/aec9kkX+RA9MxssTlJSWdfRhol3iZ0qhuz0gGVhHxEaP0ZXOffovxc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510222; 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=AeXtv9zayv/VGYD5ey37VTrrniNutWiGmDFFJXMX080=; b=WXOpdqHNJwt3rN6B4l2CRCZQu1Z5qGamcaLp+DQYiVoYHwHAojFgyG2lPPXsk/HMx6iCtGuEqGpFDGmSk6qPKzbVc/krn5WOGVAMspAQJVC7xEwe4taLZr2rE2FAijs0urbYfZRchZoJ2Sydx97oInftGIqG34UeBkDEdgdKhe4= 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 1555510222531815.5176461722897; Wed, 17 Apr 2019 07:10:22 -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 8817BC067C3B; Wed, 17 Apr 2019 14:10:15 +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 5585719C58; Wed, 17 Apr 2019 14:10:15 +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 0B74C3FB16; Wed, 17 Apr 2019 14:10:15 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9VWL023703 for ; Wed, 17 Apr 2019 10:09:31 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7910F60150; Wed, 17 Apr 2019 14:09:31 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id CA7CC60148; Wed, 17 Apr 2019 14:09:30 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:04 -0500 Message-Id: <20190417140921.11964-5-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 04/21] backup: Introduce virDomainBackup 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.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, 17 Apr 2019 14:10:16 +0000 (UTC) Introduce a few new public APIs related to incremental backups. This builds on the previous notion of a checkpoint (without an existing checkpoint, the new API is a full backup, differing from virDomainBlockCopy in the point of time chosen and in operation on multiple disks at once); and also allows creation of a new checkpoint at the same time as starting the backup (after all, an incremental backup is only useful if it covers the state since the previous backup). Snapshot creation is also a point in time at which creating a checkpoint atomically can be useful; as checkpoints are independent objects, it is not worth embedding inside , and therefore we need a more powerful version of virDomainSnapshotCreateXML(), where we borrow from the naming pattern of virDomainMigrate2() and friends. A backup job also affects filtering a listing of domains, as well as adding event reporting for signaling when a push model backup completes (where the hypervisor creates the backup); note that the pull model does not have an event (starting the backup lets a third party access the data, and only the third party knows when it is finished). Since multiple backup jobs can be run in parallel in the future (well, qemu doesn't support it yet, but we don't want to preclude the idea), virDomainBackupBegin() returns a positive job id, and the id is also visible in the backup XML. But until a future libvirt release adds a bunch of APIs related to parallel job management where job ids will actually matter, the documentation is also clear that job id 0 means the 'currently running backup job' (provided one exists), for use in virDomainBackupGetXMLDesc() and virDomainBackupEnd(). The full list of new APIs: virDomainBackupBegin; virDomainBackupEnd; virDomainBackupGetXMLDesc; virDomainSnapshotCreateXML2; Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- include/libvirt/libvirt-domain-snapshot.h | 8 +- include/libvirt/libvirt-domain.h | 41 +++- src/driver-hypervisor.h | 21 +++ src/qemu/qemu_blockjob.h | 1 + examples/object-events/event-test.c | 3 + src/conf/domain_conf.c | 2 +- src/libvirt-domain-snapshot.c | 89 +++++++++ src/libvirt-domain.c | 219 ++++++++++++++++++++++ src/libvirt_public.syms | 4 + tools/virsh-domain.c | 8 +- 10 files changed, 390 insertions(+), 6 deletions(-) diff --git a/include/libvirt/libvirt-domain-snapshot.h b/include/libvirt/li= bvirt-domain-snapshot.h index 602e5def59..406ac5846c 100644 --- a/include/libvirt/libvirt-domain-snapshot.h +++ b/include/libvirt/libvirt-domain-snapshot.h @@ -3,7 +3,7 @@ * Summary: APIs for management of domain snapshots * Description: Provides APIs for the management of domain snapshots * - * Copyright (C) 2006-2014 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -78,6 +78,12 @@ virDomainSnapshotPtr virDomainSnapshotCreateXML(virDomai= nPtr domain, const char *xmlDesc, unsigned int flags); +/* Take a snapshot of the current VM state, possibly creating a checkpoint= */ +virDomainSnapshotPtr virDomainSnapshotCreateXML2(virDomainPtr domain, + const char *xmlDesc, + const char *checkpointXml, + unsigned int flags); + typedef enum { VIR_DOMAIN_SNAPSHOT_XML_SECURE =3D VIR_DOMAIN_XML_SECURE, /* d= ump security sensitive information too */ } virDomainSnapshotXMLFlags; diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-dom= ain.h index fe9ff011fe..260148ff91 100644 --- a/include/libvirt/libvirt-domain.h +++ b/include/libvirt/libvirt-domain.h @@ -3,7 +3,7 @@ * Summary: APIs for management of domains * Description: Provides APIs for the management of domains * - * Copyright (C) 2006-2015 Red Hat, Inc. + * Copyright (C) 2006-2019 Red Hat, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -2434,6 +2434,9 @@ typedef enum { * exists as long as sync is active */ VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT =3D 4, + /* Backup (virDomainBackupBegin), job exists until virDomainBackupEnd = */ + VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP =3D 5, + # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_BLOCK_JOB_TYPE_LAST # endif @@ -3255,6 +3258,7 @@ typedef enum { VIR_DOMAIN_JOB_OPERATION_SNAPSHOT =3D 6, VIR_DOMAIN_JOB_OPERATION_SNAPSHOT_REVERT =3D 7, VIR_DOMAIN_JOB_OPERATION_DUMP =3D 8, + VIR_DOMAIN_JOB_OPERATION_BACKUP =3D 9, # ifdef VIR_ENUM_SENTINELS VIR_DOMAIN_JOB_OPERATION_LAST @@ -3270,6 +3274,14 @@ typedef enum { */ # define VIR_DOMAIN_JOB_OPERATION "operation" +/** + * VIR_DOMAIN_JOB_ID: + * + * virDomainGetJobStats field: the id of the job (so far, only for jobs + * started by virDomainBackupBegin()), as VIR_TYPED_PARAM_INT. + */ +# define VIR_DOMAIN_JOB_ID "id" + /** * VIR_DOMAIN_JOB_TIME_ELAPSED: * @@ -4094,7 +4106,8 @@ typedef void (*virConnectDomainEventMigrationIteratio= nCallback)(virConnectPtr co * @nparams: size of the params array * @opaque: application specific data * - * This callback occurs when a job (such as migration) running on the doma= in + * This callback occurs when a job (such as migration or push-model + * virDomainBackupBegin()) running on the domain * is completed. The params array will contain statistics of the just comp= leted * job as virDomainGetJobStats would return. The callback must not free @p= arams * (the array will be freed once the callback finishes). @@ -4890,4 +4903,28 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr doma= in, int *nparams, unsigned int flags); +typedef enum { + VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA =3D (1 << 0), /* Make checkpoint w= ithout + remembering it */ + VIR_DOMAIN_BACKUP_BEGIN_QUIESCE =3D (1 << 1), /* use guest agent to + quiesce all mounted + file systems within + the domain */ +} virDomainBackupBeginFlags; + +/* Begin an incremental backup job, possibly creating a checkpoint. */ +int virDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags); + +/* Learn about an ongoing backup job. */ +char *virDomainBackupGetXMLDesc(virDomainPtr domain, int id, + unsigned int flags); + +typedef enum { + VIR_DOMAIN_BACKUP_END_ABORT =3D (1 << 0), /* Abandon a push model back= up */ +} virDomainBackupEndFlags; + +/* Complete (or abort) an incremental backup job. */ +int virDomainBackupEnd(virDomainPtr domain, int id, unsigned int flags); + #endif /* LIBVIRT_DOMAIN_H */ diff --git a/src/driver-hypervisor.h b/src/driver-hypervisor.h index 49b676dbbb..6a0cc709d6 100644 --- a/src/driver-hypervisor.h +++ b/src/driver-hypervisor.h @@ -797,6 +797,12 @@ typedef virDomainSnapshotPtr const char *xmlDesc, unsigned int flags); +typedef virDomainSnapshotPtr +(*virDrvDomainSnapshotCreateXML2)(virDomainPtr domain, + const char *xmlDesc, + const char *checkpointXml, + unsigned int flags); + typedef char * (*virDrvDomainSnapshotGetXMLDesc)(virDomainSnapshotPtr snapshot, unsigned int flags); @@ -1376,6 +1382,17 @@ typedef int (*virDrvDomainCheckpointDelete)(virDomainCheckpointPtr checkpoint, unsigned int flags); +typedef int +(*virDrvDomainBackupBegin)(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags); + +typedef char * +(*virDrvDomainBackupGetXMLDesc)(virDomainPtr domain, int id, + unsigned int flags); + +typedef int +(*virDrvDomainBackupEnd)(virDomainPtr domain, int id, unsigned int flags); + typedef struct _virHypervisorDriver virHypervisorDriver; typedef virHypervisorDriver *virHypervisorDriverPtr; @@ -1541,6 +1558,7 @@ struct _virHypervisorDriver { virDrvDomainManagedSaveGetXMLDesc domainManagedSaveGetXMLDesc; virDrvDomainManagedSaveDefineXML domainManagedSaveDefineXML; virDrvDomainSnapshotCreateXML domainSnapshotCreateXML; + virDrvDomainSnapshotCreateXML2 domainSnapshotCreateXML2; virDrvDomainSnapshotGetXMLDesc domainSnapshotGetXMLDesc; virDrvDomainSnapshotNum domainSnapshotNum; virDrvDomainSnapshotListNames domainSnapshotListNames; @@ -1638,6 +1656,9 @@ struct _virHypervisorDriver { virDrvDomainCheckpointIsCurrent domainCheckpointIsCurrent; virDrvDomainCheckpointHasMetadata domainCheckpointHasMetadata; virDrvDomainCheckpointDelete domainCheckpointDelete; + virDrvDomainBackupBegin domainBackupBegin; + virDrvDomainBackupGetXMLDesc domainBackupGetXMLDesc; + virDrvDomainBackupEnd domainBackupEnd; }; diff --git a/src/qemu/qemu_blockjob.h b/src/qemu/qemu_blockjob.h index c7325c6daf..95f53dde16 100644 --- a/src/qemu/qemu_blockjob.h +++ b/src/qemu/qemu_blockjob.h @@ -55,6 +55,7 @@ typedef enum { QEMU_BLOCKJOB_TYPE_COPY =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY, QEMU_BLOCKJOB_TYPE_COMMIT =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT, QEMU_BLOCKJOB_TYPE_ACTIVE_COMMIT =3D VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_= COMMIT, + QEMU_BLOCKJOB_TYPE_BACKUP =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP, /* Additional enum values local to qemu */ QEMU_BLOCKJOB_TYPE_INTERNAL, QEMU_BLOCKJOB_TYPE_LAST diff --git a/examples/object-events/event-test.c b/examples/object-events/e= vent-test.c index fcf4492470..98337ad185 100644 --- a/examples/object-events/event-test.c +++ b/examples/object-events/event-test.c @@ -891,6 +891,9 @@ blockJobTypeToStr(int type) case VIR_DOMAIN_BLOCK_JOB_TYPE_ACTIVE_COMMIT: return "active layer block commit"; + + case VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP: + return "backup"; } return "unknown"; diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 51aa48f421..3c5d369586 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -1211,7 +1211,7 @@ VIR_ENUM_IMPL(virDomainOsDefFirmware, VIR_ENUM_DECL(virDomainBlockJob); VIR_ENUM_IMPL(virDomainBlockJob, VIR_DOMAIN_BLOCK_JOB_TYPE_LAST, - "", "", "copy", "", "active-commit", + "", "", "copy", "", "active-commit", "", ); VIR_ENUM_IMPL(virDomainMemoryModel, diff --git a/src/libvirt-domain-snapshot.c b/src/libvirt-domain-snapshot.c index 0c8023d9f6..2a50a84417 100644 --- a/src/libvirt-domain-snapshot.c +++ b/src/libvirt-domain-snapshot.c @@ -202,6 +202,10 @@ virDomainSnapshotGetConnect(virDomainSnapshotPtr snaps= hot) * block copy operation; in that case, use virDomainBlockJobAbort() * to stop the block copy first. * + * To create a checkpoint object that coincides with the snapshot, in + * order to facilitate later incremental backups from the time of the + * snapshot, use virDomainSnapshotCreateXML2(). + * * virDomainSnapshotFree should be used to free the resources after the * snapshot object is no longer needed. * @@ -251,6 +255,91 @@ virDomainSnapshotCreateXML(virDomainPtr domain, } +/** + * virDomainSnapshotCreateXML2: + * @domain: a domain object + * @xmlDesc: string containing an XML description of the domain snapshot + * @checkpointXml: description of a checkpoint to create or NULL + * @flags: bitwise-OR of virDomainSnapshotCreateFlags + * + * Creates a new snapshot of a domain based on the snapshot xml + * contained in xmlDesc, with a top-level element . + * + * The @checkpointXml parameter is optional; if non-NULL, then libvirt + * behaves as if virDomainCheckpointCreateXML() were called to create + * a checkpoint atomically covering the same point in time as the + * snapshot, using @checkpointXml and forwarding flags + * VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE and + * VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA. The creation of a new + * checkpoint allows for future incremental backups from the time of + * the snapshot. Note that some hypervisors may require a particular + * disk format, such as qcow2, in order to take advantage of + * checkpoints, while allowing arbitrary formats if checkpoints are + * not involved. This parameter is incompatible with the flag + * VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE. + * + * See virDomainSnapshotCreateXML() for the description of individual + * flags and general behavior. + * + * virDomainSnapshotFree() should be used to free the resources after + * the snapshot object is no longer needed. + * + * Returns an (opaque) new virDomainSnapshotPtr on success or NULL on + * failure. + */ +virDomainSnapshotPtr +virDomainSnapshotCreateXML2(virDomainPtr domain, + const char *xmlDesc, + const char *checkpointXml, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "xmlDesc=3D%s, checkpointXml=3D%s, flags=3D0x= %x", + xmlDesc, checkpointXml, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNullArgGoto(xmlDesc, error); + virCheckReadOnlyGoto(conn->flags, error); + + VIR_REQUIRE_FLAG_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_CURRENT, + VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE, + error); + + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE, + VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA, + error); + VIR_EXCLUSIVE_FLAGS_GOTO(VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE, + VIR_DOMAIN_SNAPSHOT_CREATE_HALT, + error); + + if (checkpointXml && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE)) { + virReportInvalidArg(checkpointXml, "%s", + _("Cannot create checkpoint when redefining " + "snapshot")); + goto error; + } + + if (conn->driver->domainSnapshotCreateXML2) { + virDomainSnapshotPtr ret; + ret =3D conn->driver->domainSnapshotCreateXML2(domain, xmlDesc, + checkpointXml, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + /** * virDomainSnapshotGetXMLDesc: * @snapshot: a domain snapshot object diff --git a/src/libvirt-domain.c b/src/libvirt-domain.c index 44438c3be8..67ae2a9ecd 100644 --- a/src/libvirt-domain.c +++ b/src/libvirt-domain.c @@ -10351,6 +10351,12 @@ virDomainBlockRebase(virDomainPtr dom, const char = *disk, * over the destination format, the ability to copy to a destination that * is not a local file, and the possibility of additional tuning parameter= s. * + * The copy created by this API is not finalized until the job ends, + * and does not lend itself to incremental backups (beyond what + * VIR_DOMAIN_BLOCK_COPY_SHALLOW provides) nor to third-party control + * over the data being copied. For those features, use + * virDomainBackupBegin(). + * * Returns 0 if the operation has started, -1 on failure. */ int @@ -12373,3 +12379,216 @@ int virDomainGetLaunchSecurityInfo(virDomainPtr d= omain, virDispatchError(domain->conn); return -1; } + + +/** + * virDomainBackupBegin: + * @domain: a domain object + * @diskXml: description of storage to utilize and expose during + * the backup, or NULL + * @checkpointXml: description of a checkpoint to create or NULL + * @flags: bitwise-OR of supported virDomainBackupBeginFlags + * + * Start a point-in-time backup job for the specified disks of a + * running domain. + * + * A backup job is mutually exclusive with domain migration + * (particularly when the job sets up an NBD export, since it is not + * possible to tell any NBD clients about a server migrating between + * hosts). For now, backup jobs are also mutually exclusive with any + * other block job on the same device, although this restriction may + * be lifted in a future release. Progress of the backup job can be + * tracked via virDomainGetJobStats(). The job remains active until a + * subsequent call to virDomainBackupEnd(), even if it no longer has + * anything to copy. + * + * This API differs from virDomainBlockCopy() because it can grab the + * state of more than one disk in parallel, and because the state is + * captured as of the start of the job, rather than the end. + * + * There are two fundamental backup approaches. The first, called a + * push model, instructs the hypervisor to copy the state of the guest + * disk to the designated storage destination (which may be on the + * local file system or a network device). In this mode, the + * hypervisor writes the content of the guest disk to the destination, + * then emits VIR_DOMAIN_EVENT_ID_JOB_COMPLETED when the backup is + * either complete or failed (the backup image is invalid if the job + * fails or virDomainBackupEnd() is used prior to the event being + * emitted). + * + * The second, called a pull model, instructs the hypervisor to expose + * the state of the guest disk over an NBD export. A third-party + * client can then connect to this export and read whichever portions + * of the disk it desires. In this mode, there is no event; libvirt + * has to be informed via virDomainBackupEnd() when the third-party + * NBD client is done and the backup resources can be released. + * + * The @diskXml parameter is optional but usually provided and + * contains details about the backup in the top-level element + * , including which backup mode to use, whether the + * backup is incremental from a previous checkpoint, which disks + * participate in the backup, the destination for a push model backup, + * and the temporary storage and NBD server details for a pull model + * backup. If omitted, the backup attempts to default to a push mode + * full backup of all disks, where libvirt generates a filename for + * each disk by appending a suffix of a timestamp in seconds since the + * Epoch. virDomainBackupGetXMLDesc() can be called to learn actual + * values selected. For more information, see + * formatcheckpoint.html#BackupAttributes. + * + * The @checkpointXml parameter is optional; if non-NULL, then libvirt + * behaves as if virDomainCheckpointCreateXML() were called to create + * a checkpoint atomically covering the same point in time as the + * backup, using @checkpointXml and forwarding flags + * VIR_DOMAIN_BACKUP_BEGIN_QUIESCE and + * VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA. The creation of a new + * checkpoint allows for future incremental backups. Note that some + * hypervisors may require a particular disk format, such as qcow2, in + * order to take advantage of checkpoints, while allowing arbitrary + * formats if checkpoints are not involved. + * + * Returns a non-negative job id on success or negative on failure. + * This id is then passed to virDomainBackupGetXMLDesc() and + * virDomainBackupEnd(); it can also be obtained from + * virDomainListJobIds(). This operation returns quickly, such that a + * user can choose to start a backup job between virDomainFSFreeze() + * and virDomainFSThaw() in order to create the backup while guest I/O + * is quiesced. + */ +int +virDomainBackupBegin(virDomainPtr domain, + const char *diskXml, + const char *checkpointXml, + unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "diskXml=3D%s, checkpointXml=3D%s, flags=3D0x= %x", + NULLSTR(diskXml), NULLSTR(checkpointXml), flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + if (flags & VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA) + virCheckNonNullArgGoto(checkpointXml, error); + + if (conn->driver->domainBackupBegin) { + int ret; + ret =3D conn->driver->domainBackupBegin(domain, diskXml, checkpoin= tXml, + flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} + + +/** + * virDomainBackupGetXMLDesc: + * @domain: a domain object + * @id: the id of an active backup job + * @flags: extra flags; not used yet, so callers should always pass 0 + * + * In some cases, a user can start a backup job without supplying all + * details and rely on libvirt to fill in the rest (for example, + * selecting the port used for an NBD export). This API can then be + * used to learn what default values were chosen. At present, none of + * the information provided is security sensitive. + * + * @id can either be the return value of a previous + * virDomainBackupBegin() or the value 0 to select the current backup + * job (the latter usage is an error if the hypervisor supports + * parallel jobs and has more than one running). + * + * Returns a NUL-terminated UTF-8 encoded XML instance or NULL in + * case of error. The caller must free() the returned value. + */ +char * +virDomainBackupGetXMLDesc(virDomainPtr domain, int id, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "id=3D%d, flags=3D0x%x", id, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, NULL); + conn =3D domain->conn; + + virCheckNonNegativeArgGoto(id, error); + + if (conn->driver->domainBackupGetXMLDesc) { + char *ret; + ret =3D conn->driver->domainBackupGetXMLDesc(domain, id, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return NULL; +} + + +/** + * virDomainBackupEnd: + * @domain: a domain object + * @id: the id of an active backup job + * @flags: bitwise-OR of supported virDomainBackupEndFlags + * + * Conclude a point-in-time backup job of the given domain. + * + * @id can either be the return value of a previous + * virDomainBackupBegin() or the value 0 to select the current backup + * job (the latter usage is an error if the hypervisor supports + * parallel jobs and has more than one running). + * + * If the backup job uses the push model, but the event marking that + * all data has been copied has not yet been emitted, then the command + * fails unless @flags includes VIR_DOMAIN_BACKUP_END_ABORT. If the + * event has been issued, or if the backup uses the pull model, the + * flag has no effect. + * + * Returns 1 if the backup job completed successfully (the backup + * destination file in a push model is consistent), 0 if the job was + * aborted successfully (only when VIR_DOMAIN_BACKUP_END_ABORT is + * passed; the destination file is unusable), and -1 on failure. + */ +int +virDomainBackupEnd(virDomainPtr domain, int id, unsigned int flags) +{ + virConnectPtr conn; + + VIR_DOMAIN_DEBUG(domain, "id=3D%d, flags=3D0x%x", id, flags); + + virResetLastError(); + + virCheckDomainReturn(domain, -1); + conn =3D domain->conn; + + virCheckReadOnlyGoto(conn->flags, error); + virCheckNonNegativeArgGoto(id, error); + + if (conn->driver->domainBackupEnd) { + int ret; + ret =3D conn->driver->domainBackupEnd(domain, id, flags); + if (!ret) + goto error; + return ret; + } + + virReportUnsupportedError(); + error: + virDispatchError(conn); + return -1; +} diff --git a/src/libvirt_public.syms b/src/libvirt_public.syms index a54804682e..46668dcb0f 100644 --- a/src/libvirt_public.syms +++ b/src/libvirt_public.syms @@ -821,6 +821,9 @@ LIBVIRT_5.2.0 { LIBVIRT_5.3.0 { global: + virDomainBackupBegin; + virDomainBackupEnd; + virDomainBackupGetXMLDesc; virDomainCheckpointCreateXML; virDomainCheckpointCurrent; virDomainCheckpointDelete; @@ -837,6 +840,7 @@ LIBVIRT_5.3.0 { virDomainCheckpointRef; virDomainHasCurrentCheckpoint; virDomainListAllCheckpoints; + virDomainSnapshotCreateXML2; } LIBVIRT_5.2.0; # .... define new API here using predicted next version number .... diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index da57d96d1a..3ac470fe59 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -2562,7 +2562,9 @@ VIR_ENUM_IMPL(virshDomainBlockJob, N_("Block Pull"), N_("Block Copy"), N_("Block Commit"), - N_("Active Block Commit")); + N_("Active Block Commit"), + N_("Backup"), +); static const char * virshDomainBlockJobToString(int type) @@ -6069,7 +6071,9 @@ VIR_ENUM_IMPL(virshDomainJobOperation, N_("Outgoing migration"), N_("Snapshot"), N_("Snapshot revert"), - N_("Dump")); + N_("Dump"), + N_("Backup"), +); static const char * virshDomainJobOperationToString(int op) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510218; cv=none; d=zoho.com; s=zohoarc; b=X7ZYxthUBS40MRDp3/l1qZTW1CNpr8fH+e0hHrkijKvNCwn0sXURf/8Bntf5hHFWrk3wTl7XBxgbpAhXBKVRzeZ0sPkxIV8h8SVkcXYUe/GDdB7BM2kNPAW1jO3TVsHHtSsunZAd7Rviblrq60obXFSZSkNJUndsjyAqQBhlvyU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510218; 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=r7f+04oakdgYyhYbmI6nK8C55bdtzV3Pn6cEfqWKm8M=; b=A92XAb82sdT/MKhlBOWG3+PCU9pWdCD4zX+NTNF8XKSzwQI2y5X+NuSlzp1sm4vlBKo0CP9tnYop6XXXFJ6M6rypiTTHJ8Vw4BzmSUqIn2NXNvqU8Ol2KIrX18flhRJ0TuLs5lr1nGZ2GDjrG9MoB7fy4MCyCE0Q7I4kW0+9w5M= 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 1555510218708895.4252599257568; Wed, 17 Apr 2019 07:10:18 -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 DB56A3084212; Wed, 17 Apr 2019 14:10:16 +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 AAFAF5D71A; Wed, 17 Apr 2019 14:10:16 +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 62AA33FAF5; Wed, 17 Apr 2019 14:10:16 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9WDj023708 for ; Wed, 17 Apr 2019 10:09:32 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5F97160156; Wed, 17 Apr 2019 14:09:32 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id A0D0E60148; Wed, 17 Apr 2019 14:09:31 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:05 -0500 Message-Id: <20190417140921.11964-6-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 05/21] 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 17 Apr 2019 14:10:17 +0000 (UTC) Now that various new API have been added, 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/docs.html.in | 5 + docs/domainstatecapture.html.in | 315 ++++++++++++++++++++++++++++++++ docs/formatbackup.html.in | 4 +- docs/formatcheckpoint.html.in | 4 +- docs/formatsnapshot.html.in | 2 + 5 files changed, 328 insertions(+), 2 deletions(-) create mode 100644 docs/domainstatecapture.html.in diff --git a/docs/docs.html.in b/docs/docs.html.in index 400b149791..8c08ace402 100644 --- a/docs/docs.html.in +++ b/docs/docs.html.in @@ -124,6 +124,11 @@
        Secure usage
        Secure usage of the libvirt APIs
        + +
        Domain state + capture
        +
        Comparison between different methods of capturing domain + state
        diff --git a/docs/domainstatecapture.html.in b/docs/domainstatecapture.html= .in new file mode 100644 index 0000000000..1d29d70e76 --- /dev/null +++ b/docs/domainstatecapture.html.in @@ -0,0 +1,315 @@ + + + + + +

        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 with disks restored to that + 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. 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.
          + +
          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.
          + +
          <= code>virDomainBlockCopy
          +
          This API wraps approaches for capturing the disk state (but + not memory) of a running guest, but does not track + accompanying guest memory state, and can only operate on one + block device per job. To get a consistent copy of multiple + disks, multiple jobs must be run in parallel, then the domain + must be paused before ending all of the jobs. The capture is + consistent only at the end of the operation with a choice for + future guest changes to either pivot to the new file or to + resume to just using the original file. The resulting backup + file is thus the other file no longer in use by the + guest.
          + +
          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()
          +    

          + + + diff --git a/docs/formatbackup.html.in b/docs/formatbackup.html.in index 8dccfa921f..4f76013d84 100644 --- a/docs/formatbackup.html.in +++ b/docs/formatbackup.html.in @@ -13,7 +13,9 @@ via virDomainBackupBegin(), which takes an XML description of the actions to perform, as well as an optional second XML document describing a - checkpoint to create at the same point in time. + checkpoint to create at the same point in time. See + also a comparison between + the various state capture APIs.

          There are two general modes for backups: a push mode (where the diff --git a/docs/formatcheckpoint.html.in b/docs/formatcheckpoint.html.in index e2e9b1173d..3fc7b2e5d6 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 1bbbf06205..d98b1a5f62 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:

          --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510224; cv=none; d=zoho.com; s=zohoarc; b=NQxCvYJbku0i/l5zb1lqf1z2MX4ndq3CD9y6BZ0++vC17VfwfJArNH9oB3LbfZRzViLRd4wyu0wCloEAwIhzZyK6GvNT+Zf8o1OKz59X623hfZp+7dOsYqDwfdzGrraCDa3icL/Kw0qcG6xkV4Sot5fltVLHfkDNDX8nDz4V8ck= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510224; 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=8GPCtMd0PX/M3ILVslD8BtmSHXiVcKHRQ1DgjapaE/4=; b=R4gTY4CVSqMnBJGGpB26Lt6+zGmKhCC1+yvyi1LCGOkFzE+PATZUR0JrPAiGOMo0wwKo028A+lAV1b+lgyv9j/uu+qNdFVSHflG55/w3W/h+g6gxtb0Ln9ZUFmRHeJ5cFvpszpCLzOHXNmepJCkVHAZcniMDDn0BQbEiVnHU5Ik= 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 1555510224610722.8375031194543; Wed, 17 Apr 2019 07:10:24 -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 7B4AA307CB38; Wed, 17 Apr 2019 14:10:22 +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 445536046C; Wed, 17 Apr 2019 14:10:22 +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 08815181AC90; Wed, 17 Apr 2019 14:10:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9XLJ023719 for ; Wed, 17 Apr 2019 10:09:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 43B7E6015E; Wed, 17 Apr 2019 14:09:33 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 834186014E; Wed, 17 Apr 2019 14:09:32 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:06 -0500 Message-Id: <20190417140921.11964-7-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 06/21] 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.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.42]); Wed, 17 Apr 2019 14:10:23 +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. Signed-off-by: Eric Blake --- src/conf/checkpoint_conf.h | 96 +++ src/conf/virconftypes.h | 3 + po/POTFILES | 1 + src/conf/Makefile.inc.am | 2 + src/conf/checkpoint_conf.c | 550 ++++++++++++++++++ src/libvirt_private.syms | 8 + tests/Makefile.am | 9 +- .../internal-active-invalid.xml | 53 ++ .../internal-inactive-invalid.xml | 53 ++ tests/domaincheckpointxml2xmltest.c | 223 +++++++ 10 files changed, 996 insertions(+), 2 deletions(-) create mode 100644 src/conf/checkpoint_conf.h create mode 100644 src/conf/checkpoint_conf.c create mode 100644 tests/domaincheckpointxml2xmlout/internal-active-invali= d.xml create mode 100644 tests/domaincheckpointxml2xmlout/internal-inactive-inva= lid.xml create mode 100644 tests/domaincheckpointxml2xmltest.c diff --git a/src/conf/checkpoint_conf.h b/src/conf/checkpoint_conf.h new file mode 100644 index 0000000000..6647d0cd7c --- /dev/null +++ b/src/conf/checkpoint_conf.h @@ -0,0 +1,96 @@ +/* + * 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 + * . + */ + +#ifndef LIBVIRT_CHECKPOINT_CONF_H +# define LIBVIRT_CHECKPOINT_CONF_H + +# include "internal.h" +# include "domain_conf.h" +# include "moment_conf.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 common; + + /* Additional Public XML. */ + size_t ndisks; /* should not exceed dom->ndisks */ + virDomainCheckpointDiskDef *disks; +}; + + +typedef enum { + VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE =3D 1 << 0, + VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL =3D 1 << 1, +} 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, + VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL =3D 1 << 3, + VIR_DOMAIN_CHECKPOINT_FORMAT_CURRENT =3D 1 << 4, +} virDomainCheckpointFormatFlags; + +unsigned int virDomainCheckpointFormatConvertXMLFlags(unsigned int flags); + +virDomainCheckpointDefPtr virDomainCheckpointDefParseString(const char *xm= lStr, + virCapsPtr cap= s, + virDomainXMLOp= tionPtr xmlopt, + bool *current, + unsigned int f= lags); +virDomainCheckpointDefPtr virDomainCheckpointDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOpti= onPtr xmlopt, + bool *current, + unsigned int fla= gs); +void virDomainCheckpointDefFree(virDomainCheckpointDefPtr def); +char *virDomainCheckpointDefFormat(virDomainCheckpointDefPtr def, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + unsigned int flags); +int virDomainCheckpointAlignDisks(virDomainCheckpointDefPtr checkpoint); + +VIR_ENUM_DECL(virDomainCheckpoint); + +#endif /* LIBVIRT_CHECKPOINT_CONF_H */ diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index 6a8267c422..f01721c6d5 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -103,6 +103,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 88af551664..57c55fb35f 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 3e9fdd1aea..65bb761c6d 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -12,6 +12,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..87f76e6518 --- /dev/null +++ b/src/conf/checkpoint_conf.c @@ -0,0 +1,550 @@ +/* + * 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 "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"); + +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); +} + +void virDomainCheckpointDefFree(virDomainCheckpointDefPtr def) +{ + size_t i; + + if (!def) + return; + + virDomainMomentDefClear(&def->common); + for (i =3D 0; i < def->ndisks; i++) + virDomainCheckpointDiskDefClear(&def->disks[i]); + VIR_FREE(def->disks); + VIR_FREE(def); +} + +static int +virDomainCheckpointDiskDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainCheckpointDiskDefPtr def) +{ + int ret =3D -1; + char *checkpoint =3D NULL; + char *bitmap =3D NULL; + xmlNodePtr saved =3D ctxt->node; + + ctxt->node =3D node; + + def->name =3D virXMLPropString(node, "name"); + if (!def->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing name from disk checkpoint element")); + goto cleanup; + } + + checkpoint =3D virXMLPropString(node, "checkpoint"); + if (checkpoint) { + def->type =3D virDomainCheckpointTypeFromString(checkpoint); + if (def->type <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk checkpoint setting '%s'"), + checkpoint); + goto cleanup; + } + } else { + def->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + } + + bitmap =3D virXMLPropString(node, "bitmap"); + if (bitmap) { + if (def->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk checkpoint bitmap '%s' requires " + "type=3D'bitmap'"), + bitmap); + goto cleanup; + } + VIR_STEAL_PTR(def->bitmap, bitmap); + } + + ret =3D 0; + cleanup: + ctxt->node =3D saved; + + VIR_FREE(checkpoint); + VIR_FREE(bitmap); + if (ret < 0) + virDomainCheckpointDiskDefClear(def); + return ret; +} + +/* flags is bitwise-or of virDomainCheckpointParseFlags. If flags + * does not include VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE, then caps + * are ignored. If flags does not include + * VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL, then current is ignored. + */ +static virDomainCheckpointDefPtr +virDomainCheckpointDefParse(xmlXPathContextPtr ctxt, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + bool *current, + unsigned int flags) +{ + virDomainCheckpointDefPtr def =3D NULL; + virDomainCheckpointDefPtr ret =3D NULL; + xmlNodePtr *nodes =3D NULL; + size_t i; + int n; + char *creation =3D NULL; + int active; + char *tmp; + + if (VIR_ALLOC(def) < 0) + goto cleanup; + + def->common.name =3D virXPathString("string(./name)", ctxt); + if (def->common.name =3D=3D NULL) { + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) { + virReportError(VIR_ERR_XML_ERROR, "%s", + _("a redefined checkpoint must have a name")); + goto cleanup; + } + } + + def->common.description =3D virXPathString("string(./description)", ct= xt); + + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE) { + if (virXPathLongLong("string(./creationTime)", ctxt, + &def->common.creationTime) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing creationTime from existing checkpoin= t")); + goto cleanup; + } + + def->common.parent =3D virXPathString("string(./parent/name)", ctx= t); + + 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")); + goto cleanup; + } + def->common.dom =3D virDomainDefParseNode(ctxt->node->doc, dom= ainNode, + caps, xmlopt, NULL, + domainflags); + if (!def->common.dom) + goto cleanup; + } else { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint redefine")); + goto cleanup; + } + } else if (virDomainXMLOptionRunMomentPostParse(xmlopt, &def->common) = < 0) { + goto cleanup; + } + + if ((n =3D virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->disks, n) < 0) + goto cleanup; + def->ndisks =3D n; + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainCheckpointDiskDefParseXML(nodes[i], ctxt, + &def->disks[i]) < 0) + goto cleanup; + } + + if (flags & VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL) { + if (!current) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("internal parse requested with NULL current")= ); + goto cleanup; + } + if (virXPathInt("string(./active)", ctxt, &active) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("Could not find 'active' element")); + goto cleanup; + } + *current =3D active !=3D 0; + } + + VIR_STEAL_PTR(ret, def); + + cleanup: + VIR_FREE(creation); + VIR_FREE(nodes); + virDomainCheckpointDefFree(def); + + return ret; +} + +virDomainCheckpointDefPtr +virDomainCheckpointDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + bool *current, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + virDomainCheckpointDefPtr def =3D NULL; + + if (!virXMLNodeNameEqual(root, "domaincheckpoint")) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("domaincheckpoint")); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virDomainCheckpointDefParse(ctxt, caps, xmlopt, current, flags= ); + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + +virDomainCheckpointDefPtr +virDomainCheckpointDefParseString(const char *xmlStr, + virCapsPtr caps, + virDomainXMLOptionPtr xmlopt, + bool *current, + 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, current, 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->common.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->common.dom) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing domain in checkpoint")); + goto cleanup; + } + + if (def->ndisks > def->common.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->common.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 disks; otherwise, do nothing + * for omitted disks */ + if (!def->ndisks) + checkpoint_default =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + + if (!(map =3D virBitmapNew(def->common.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->common.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; + } + ignore_value(virBitmapSetBit(map, idx)); + disk->idx =3D idx; + + if (STRNEQ(disk->name, def->common.dom->disks[idx]->dst)) { + VIR_FREE(disk->name); + if (VIR_STRDUP(disk->name, def->common.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->common.dom->ndisks - def->ndisks) < 0) + goto cleanup; + + for (i =3D 0; i < def->common.dom->ndisks; i++) { + virDomainCheckpointDiskDefPtr disk; + + if (virBitmapIsBitSet(map, i)) + continue; + disk =3D &def->disks[ndisks++]; + if (VIR_STRDUP(disk->name, def->common.dom->disks[i]->dst) < 0) + goto cleanup; + disk->idx =3D i; + + /* Don't checkpoint empty drives */ + if (virStorageSourceIsEmpty(def->common.dom->disks[i]->src)) + 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->common.name); + virBufferEscapeString(buf, "%s\n", + def->common.description); + + if (def->common.parent) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + virBufferEscapeString(buf, "%s\n", def->common.parent= ); + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + if (def->common.creationTime) + virBufferAsprintf(buf, "%lld\n", + def->common.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->common.dom, caps, domainflags, buf, + xmlopt) < 0) + goto error; + + if (flags & VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL) + virBufferAsprintf(buf, "%d\n", + !!(flags & VIR_DOMAIN_CHECKPOINT_FORMAT_CURRENT)= ); + + 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 | + VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL | + VIR_DOMAIN_CHECKPOINT_FORMAT_CURRENT, 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 aa123978fa..d41d24d8d5 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -69,6 +69,14 @@ virCapabilitiesSetHostCPU; virCapabilitiesSetNetPrefix; +# conf/checkpoint_conf.h +virDomainCheckpointDefFormat; +virDomainCheckpointDefFree; +virDomainCheckpointDefParseString; +virDomainCheckpointTypeFromString; +virDomainCheckpointTypeToString; + + # conf/cpu_conf.h virCPUCacheModeTypeFromString; virCPUCacheModeTypeToString; diff --git a/tests/Makefile.am b/tests/Makefile.am index 576e9d6fc6..bd0d496837 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -279,7 +279,7 @@ endif WITH_LIBXL if WITH_QEMU test_programs +=3D qemuxml2argvtest qemuxml2xmltest \ - qemuargv2xmltest domainsnapshotxml2xmltest \ + qemuargv2xmltest domaincheckpointxml2xmltest domainsnapshotxml2xmltest \ qemumonitorjsontest qemuhotplugtest \ qemuagenttest qemucapabilitiestest qemucaps2xmltest \ qemumemlocktest \ @@ -664,6 +664,11 @@ qemublocktest_LDADD =3D \ $(LDADDS) \ $(NULL) +domaincheckpointxml2xmltest_SOURCES =3D \ + domaincheckpointxml2xmltest.c testutilsqemu.c testutilsqemu.h \ + testutils.c testutils.h +domaincheckpointxml2xmltest_LDADD =3D $(qemu_LDADDS) $(LDADDS) + domainsnapshotxml2xmltest_SOURCES =3D \ domainsnapshotxml2xmltest.c testutilsqemu.c testutilsqemu.h \ testutils.c testutils.h @@ -699,7 +704,7 @@ qemufirmwaretest_LDADD =3D $(qemu_LDADDS) $(LDADDS) else ! WITH_QEMU EXTRA_DIST +=3D qemuxml2argvtest.c qemuxml2xmltest.c qemuargv2xmltest.c \ - domainsnapshotxml2xmltest.c \ + domaincheckpointxml2xmltest.c domainsnapshotxml2xmltest.c \ testutilsqemu.c testutilsqemu.h \ testutilsqemuschema.c testutilsqemuschema.h \ qemumonitorjsontest.c qemuhotplugtest.c \ diff --git a/tests/domaincheckpointxml2xmlout/internal-active-invalid.xml b= /tests/domaincheckpointxml2xmlout/internal-active-invalid.xml new file mode 100644 index 0000000000..a518c58915 --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/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/domaincheckpointxml2xmlout/internal-inactive-invalid.xml= b/tests/domaincheckpointxml2xmlout/internal-inactive-invalid.xml new file mode 100644 index 0000000000..df14c97836 --- /dev/null +++ b/tests/domaincheckpointxml2xmlout/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/domaincheckpointxml2xmltest.c b/tests/domaincheckpointxm= l2xmltest.c new file mode 100644 index 0000000000..11ec61658b --- /dev/null +++ b/tests/domaincheckpointxml2xmltest.c @@ -0,0 +1,223 @@ +#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_INTERNAL =3D 1 << 0, /* Test use of INTERNAL parse/format flag */ + TEST_REDEFINE =3D 1 << 1, /* Test use of REDEFINE parse flag */ + TEST_PARENT =3D 1 << 2, /* hard-code parent after parse */ + TEST_VDA_BITMAP =3D 1 << 3, /* hard-code disk vda after parse */ + TEST_SIZE =3D 1 << 4, /* Test use of SIZE format flag */ +}; + +static int +testCompareXMLToXMLFiles(const char *inxml, + const char *outxml, + unsigned int flags) +{ + char *inXmlData =3D NULL; + char *outXmlData =3D NULL; + char *actual =3D NULL; + int ret =3D -1; + virDomainCheckpointDefPtr def =3D NULL; + unsigned int parseflags =3D 0; + unsigned int formatflags =3D VIR_DOMAIN_CHECKPOINT_FORMAT_SECURE; + bool cur =3D false; + + if (flags & TEST_INTERNAL) { + parseflags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL; + formatflags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL; + } + + if (flags & TEST_REDEFINE) + parseflags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + + if (virTestLoadFile(inxml, &inXmlData) < 0) + goto cleanup; + + if (virTestLoadFile(outxml, &outXmlData) < 0) + goto cleanup; + + if (!(def =3D virDomainCheckpointDefParseString(inXmlData, driver.caps, + driver.xmlopt, &cur, + parseflags))) + goto cleanup; + if (cur) { + if (!(flags & TEST_REDEFINE)) + goto cleanup; + formatflags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_CURRENT; + } + if (flags & TEST_PARENT) { + if (def->common.parent) + goto cleanup; + if (VIR_STRDUP(def->common.parent, "1525111885") < 0) + goto cleanup; + } + if (flags & TEST_VDA_BITMAP) { + virDomainCheckpointDiskDefPtr disk; + + if (VIR_EXPAND_N(def->disks, def->ndisks, 1) < 0) + goto cleanup; + disk =3D &def->disks[0]; + if (disk->bitmap) + goto cleanup; + if (!disk->name) { + disk->type =3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP; + if (VIR_STRDUP(disk->name, "vda") < 0) + goto cleanup; + } else if (STRNEQ(disk->name, "vda")) { + goto cleanup; + } + if (VIR_STRDUP(disk->bitmap, def->common.name) < 0) + goto cleanup; + } + 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->common.dom) + formatflags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_NO_DOMAIN; + + if (!(actual =3D virDomainCheckpointDefFormat(def, driver.caps, + driver.xmlopt, + formatflags))) + goto cleanup; + + if (STRNEQ(outXmlData, actual)) { + virTestDifferenceFull(stderr, outXmlData, outxml, actual, inxml); + goto cleanup; + } + + ret =3D 0; + + cleanup: + VIR_FREE(inXmlData); + VIR_FREE(outXmlData); + VIR_FREE(actual); + virDomainCheckpointDefFree(def); + return ret; +} + +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, \ + "domaincheckpointxml2xmlin", \ + "domaincheckpointxml2xmlout", \ + time, flags) +# define DO_TEST_OUT(name, flags) \ + DO_TEST("out->out", name, \ + "domaincheckpointxml2xmlout", \ + "domaincheckpointxml2xmlout", \ + 0, flags | TEST_REDEFINE) + + /* 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); + + /* Tests of internal state saving - the element is not + * permitted or exposed to user XML, so the files are named to + * skip schema validation */ + DO_TEST_OUT("internal-active-invalid", TEST_INTERNAL); + DO_TEST_OUT("internal-inactive-invalid", TEST_INTERNAL); + /* 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("sample", 1525889631, TEST_PARENT | TEST_VDA_BITMAP); + DO_TEST_INOUT("size", 1553648510, + TEST_PARENT | TEST_VDA_BITMAP | TEST_SIZE); + + 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 Sat Apr 27 19:55:39 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=1555510224; cv=none; d=zoho.com; s=zohoarc; b=l10UwzOyryMNyib228EQ/e9DGcaaQuIdmnLRFhtvXox/ksgFKXcrvyKPOBTMZJOtd3/XQX1jeprIikHHMxq9+s42bS7F/V5yI5agV0b8UrkQHRtU3d6rr0Bb0ds7XknrexRz6e4nFd6Hzr64WXfXhKwNehtGVJBlctwHxNbuUy8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510224; 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=Vg5fkI/2/uZdTULuBbygtZVNZWpem4+5IVvCbDgxmvs=; b=QVAvZb+08LqcePFg8OPxD3fBafYS+4biCGbVzKIe+tlthXElDo8hIO9PdR6n4WthVSLa1auzgmhoAbXhu5DAbRRYT9GsJ5MjL3WrlKtZg2z3KriBzv/PPC3sn0qdZfWzb0NQo7xXIbNq18qNB+qnq2of4cn/8MaLTJcR+tHuIzY= 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 1555510224184382.55108181680157; Wed, 17 Apr 2019 07:10:24 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AB883076C6B; Wed, 17 Apr 2019 14:10:22 +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 38E035DA38; Wed, 17 Apr 2019 14:10:22 +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 EEE0B3FA48; Wed, 17 Apr 2019 14:10:21 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9Ygp023729 for ; Wed, 17 Apr 2019 10:09:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 20DFA60156; Wed, 17 Apr 2019 14:09:34 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6EC766014E; Wed, 17 Apr 2019 14:09:33 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:07 -0500 Message-Id: <20190417140921.11964-8-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 07/21] 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 17 Apr 2019 14:10:22 +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 checkpoints 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, we may find that in a list of checkpoints, you never have more than one child. 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. The virDomainMomentObjList code is not quite polymorphic enough until we patch virDomainMomentDef to be a proper virObject, but doing that is a bigger audit. So for now, I had to duplicate the cleanup calls based on a bool flag for which type needs cleaning. Oh well. Signed-off-by: Eric Blake --- src/conf/checkpoint_conf.h | 7 + src/conf/domain_conf.h | 2 + src/conf/virconftypes.h | 6 + src/conf/virdomaincheckpointobjlist.h | 74 +++++++++ src/conf/virdomainmomentobjlist.h | 2 +- src/conf/virdomainobjlist.h | 7 +- src/conf/Makefile.inc.am | 2 + src/conf/checkpoint_conf.c | 86 ++++++++++ src/conf/domain_conf.c | 6 + src/conf/virdomaincheckpointobjlist.c | 223 ++++++++++++++++++++++++++ src/conf/virdomainmomentobjlist.c | 40 ++++- src/conf/virdomainobjlist.c | 11 ++ src/conf/virdomainsnapshotobjlist.c | 2 +- src/libvirt_private.syms | 18 +++ 14 files changed, 477 insertions(+), 9 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 6647d0cd7c..1432c884e9 100644 --- a/src/conf/checkpoint_conf.h +++ b/src/conf/checkpoint_conf.h @@ -91,6 +91,13 @@ 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); #endif /* LIBVIRT_CHECKPOINT_CONF_H */ diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 5910ed0beb..1ef72f79d8 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2556,6 +2556,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 f01721c6d5..d3cc199c43 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -349,4 +349,10 @@ typedef virDomainXMLPrivateDataCallbacks *virDomainXML= PrivateDataCallbacksPtr; typedef struct _virDomainXenbusControllerOpts virDomainXenbusControllerOpt= s; typedef virDomainXenbusControllerOpts *virDomainXenbusControllerOptsPtr; +typedef struct _virDomainCheckpointObj virDomainCheckpointObj; +typedef virDomainCheckpointObj *virDomainCheckpointObjPtr; + +typedef struct _virDomainCheckpointObjList virDomainCheckpointObjList; +typedef virDomainCheckpointObjList *virDomainCheckpointObjListPtr; + #endif /* LIBVIRT_VIRCONFTYPES_H */ diff --git a/src/conf/virdomaincheckpointobjlist.h b/src/conf/virdomainchec= kpointobjlist.h new file mode 100644 index 0000000000..fc1e4f12a1 --- /dev/null +++ b/src/conf/virdomaincheckpointobjlist.h @@ -0,0 +1,74 @@ +/* + * 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 + * . + */ + +#ifndef LIBVIRT_VIRDOMAINCHECKPOINTOBJLIST_H +# define LIBVIRT_VIRDOMAINCHECKPOINTOBJLIST_H + +# 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); +int virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr check= points); + +# define VIR_DOMAIN_CHECKPOINT_FILTERS_METADATA \ + (VIR_DOMAIN_CHECKPOINT_LIST_METADATA | \ + VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA) + +# 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_METADATA | \ + 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; +} + +#endif /* LIBVIRT_VIRDOMAINCHECKPOINTOBJLIST_H */ diff --git a/src/conf/virdomainmomentobjlist.h b/src/conf/virdomainmomentob= jlist.h index 04808e1ac7..a7bdcd73c4 100644 --- a/src/conf/virdomainmomentobjlist.h +++ b/src/conf/virdomainmomentobjlist.h @@ -64,7 +64,7 @@ void virDomainMomentMoveChildren(virDomainMomentObjPtr fr= om, void virDomainMomentSetParent(virDomainMomentObjPtr moment, virDomainMomentObjPtr parent); -virDomainMomentObjListPtr virDomainMomentObjListNew(void); +virDomainMomentObjListPtr virDomainMomentObjListNew(bool snapshot); void virDomainMomentObjListFree(virDomainMomentObjListPtr moments); virDomainMomentObjPtr virDomainMomentAssignDef(virDomainMomentObjListPtr m= oments, diff --git a/src/conf/virdomainobjlist.h b/src/conf/virdomainobjlist.h index c1ffee76ad..3372bf2a29 100644 --- a/src/conf/virdomainobjlist.h +++ b/src/conf/virdomainobjlist.h @@ -121,13 +121,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 65bb761c6d..1d5ade52b3 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -33,6 +33,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 87f76e6518..cb0d71936f 100644 --- a/src/conf/checkpoint_conf.c +++ b/src/conf/checkpoint_conf.c @@ -35,6 +35,7 @@ #include "virerror.h" #include "virxml.h" #include "virstring.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN_CHECKPOINT @@ -548,3 +549,88 @@ 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; + virDomainCheckpointDefPtr otherdef; + + virUUIDFormat(domain->uuid, uuidstr); + + /* TODO: Move this and snapshot version into virDomainMoment */ + /* Prevent circular chains */ + if (def->common.parent) { + if (STREQ(def->common.name, def->common.parent)) { + virReportError(VIR_ERR_INVALID_ARG, + _("cannot set checkpoint %s as its own parent"), + def->common.name); + return -1; + } + other =3D virDomainCheckpointFindByName(vm->checkpoints, def->comm= on.parent); + if (!other) { + virReportError(VIR_ERR_INVALID_ARG, + _("parent %s for checkpoint %s not found"), + def->common.parent, def->common.name); + return -1; + } + otherdef =3D virDomainCheckpointObjGetDef(other); + while (otherdef->common.parent) { + if (STREQ(otherdef->common.parent, def->common.name)) { + virReportError(VIR_ERR_INVALID_ARG, + _("parent %s would create cycle to %s"), + otherdef->common.name, def->common.name); + return -1; + } + other =3D virDomainCheckpointFindByName(vm->checkpoints, + otherdef->common.parent); + if (!other) { + VIR_WARN("checkpoints are inconsistent for %s", + vm->def->name); + break; + } + otherdef =3D virDomainCheckpointObjGetDef(other); + } + } + + if (!def->common.dom || + memcmp(def->common.dom->uuid, domain->uuid, VIR_UUID_BUFLEN)) { + virReportError(VIR_ERR_INVALID_ARG, + _("definition for checkpoint %s must use uuid %s"), + def->common.name, uuidstr); + return -1; + } + if (virDomainCheckpointAlignDisks(def) < 0) + return -1; + + other =3D virDomainCheckpointFindByName(vm->checkpoints, def->common.n= ame); + otherdef =3D other ? virDomainCheckpointObjGetDef(other) : NULL; + if (other) { + if (!virDomainDefCheckABIStability(otherdef->common.dom, + def->common.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); + virDomainCheckpointDefFree(otherdef); + other->def =3D &(*defptr)->common; + *defptr =3D NULL; + *chk =3D other; + } + + return 0; +} diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 3c5d369586..1dc552b7f2 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" @@ -58,6 +59,7 @@ #include "virhostdev.h" #include "virmdev.h" #include "virdomainsnapshotobjlist.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -3484,6 +3486,7 @@ static void virDomainObjDispose(void *obj) (dom->privateDataFreeFunc)(dom->privateData); virDomainSnapshotObjListFree(dom->snapshots); + virDomainCheckpointObjListFree(dom->checkpoints); } virDomainObjPtr @@ -3513,6 +3516,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..dbc1c25c5e --- /dev/null +++ b/src/conf/virdomaincheckpointobjlist.c @@ -0,0 +1,223 @@ +/* + * 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->common); +} + + +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(false); + 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); + verify(VIR_DOMAIN_CHECKPOINT_LIST_METADATA =3D=3D + (int) VIR_DOMAIN_MOMENT_LIST_METADATA); + verify(VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA =3D=3D + (int) VIR_DOMAIN_MOMENT_LIST_NO_METADATA); + + 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 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. */ +int +virDomainCheckpointUpdateRelations(virDomainCheckpointObjListPtr checkpoin= ts) +{ + return virDomainMomentUpdateRelations(checkpoints->base); +} + + +int +virDomainListCheckpoints(virDomainCheckpointObjListPtr checkpoints, + virDomainMomentObjPtr from, + virDomainPtr dom, + virDomainCheckpointPtr **snaps, + 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 (!snaps || 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; + *snaps =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 7f90632a53..3dd6da7acb 100644 --- a/src/conf/virdomainmomentobjlist.c +++ b/src/conf/virdomainmomentobjlist.c @@ -33,6 +33,8 @@ /* FIXME: using virObject would allow us to not need this */ #include "snapshot_conf.h" #include "virdomainsnapshotobjlist.h" +#include "checkpoint_conf.h" +#include "virdomaincheckpointobjlist.h" #define VIR_FROM_THIS VIR_FROM_DOMAIN @@ -201,7 +203,21 @@ virDomainMomentObjNew(void) static void -virDomainMomentObjFree(virDomainMomentObjPtr moment) +virDomainCheckpointObjFree(virDomainMomentObjPtr moment) +{ + if (!moment) + return; + + VIR_DEBUG("obj=3D%p", moment); + + /* FIXME: Make this polymorphic by inheriting from virObject */ + virDomainCheckpointDefFree(virDomainCheckpointObjGetDef(moment)); + VIR_FREE(moment); +} + + +static void +virDomainSnapshotObjFree(virDomainMomentObjPtr moment) { if (!moment) return; @@ -242,23 +258,35 @@ virDomainMomentAssignDef(virDomainMomentObjListPtr mo= ments, static void -virDomainMomentObjListDataFree(void *payload, - const void *name ATTRIBUTE_UNUSED) +virDomainCheckpointObjListDataFree(void *payload, + const void *name ATTRIBUTE_UNUSED) { virDomainMomentObjPtr obj =3D payload; - virDomainMomentObjFree(obj); + virDomainCheckpointObjFree(obj); +} + + +static void +virDomainSnapshotObjListDataFree(void *payload, + const void *name ATTRIBUTE_UNUSED) +{ + virDomainMomentObjPtr obj =3D payload; + + virDomainSnapshotObjFree(obj); } virDomainMomentObjListPtr -virDomainMomentObjListNew(void) +virDomainMomentObjListNew(bool snapshot) { virDomainMomentObjListPtr moments; if (VIR_ALLOC(moments) < 0) return NULL; - moments->objs =3D virHashCreate(50, virDomainMomentObjListDataFree); + moments->objs =3D virHashCreate(50, + snapshot ? virDomainSnapshotObjListDataF= ree : + virDomainCheckpointObjListDataFree); if (!moments->objs) { VIR_FREE(moments); return NULL; diff --git a/src/conf/virdomainobjlist.c b/src/conf/virdomainobjlist.c index f5a7ecc4a4..21b82ee688 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/conf/virdomainsnapshotobjlist.c b/src/conf/virdomainsnapsh= otobjlist.c index 46b7d8b0e7..99afe1ad1d 100644 --- a/src/conf/virdomainsnapshotobjlist.c +++ b/src/conf/virdomainsnapshotobjlist.c @@ -87,7 +87,7 @@ virDomainSnapshotObjListNew(void) if (VIR_ALLOC(snapshots) < 0) return NULL; - snapshots->base =3D virDomainMomentObjListNew(); + snapshots->base =3D virDomainMomentObjListNew(true); if (!snapshots->base) { VIR_FREE(snapshots); return NULL; diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d41d24d8d5..5ae0e49927 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -70,9 +70,12 @@ virCapabilitiesSetNetPrefix; # conf/checkpoint_conf.h +virDomainCheckpointAlignDisks; virDomainCheckpointDefFormat; virDomainCheckpointDefFree; virDomainCheckpointDefParseString; +virDomainCheckpointFormatConvertXMLFlags; +virDomainCheckpointRedefinePrep; virDomainCheckpointTypeFromString; virDomainCheckpointTypeToString; @@ -974,6 +977,21 @@ virChrdevFree; virChrdevOpen; +# conf/virdomaincheckpointobjlist.h +virDomainCheckpointAssignDef; +virDomainCheckpointFindByName; +virDomainCheckpointForEach; +virDomainCheckpointGetCurrent; +virDomainCheckpointGetCurrentName; +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 Sat Apr 27 19:55:39 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=1555510184; cv=none; d=zoho.com; s=zohoarc; b=VgMOiEJSCbboklnWUibj6ykk/FGahZIg90PKCnRCq3Uoy1Gf46AMuF3DzmeXEII09Q7yPXScdejbffKR8patTWR87qYavGrHDEqCyh5XIIiMgcUPBvrZGwkgU7q2TJZm3Etpq/YlHJbc7f/a7BoPy5rbSqdfCZS+fkFoisb+g5s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510184; 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=9Kdlxub6ycgCTQS9EWPs44CsBHfBKG84A8CmaNvo7lU=; b=ZJwWBOZ90WYJjOVhsw6TaJTICViSruefTXjqCLyKPDgAup01FwgulOs593Xnerduhsoui6sneA/rexXpmfO1XE9mierU+1xTwSWykx53vmQHgpfRQqT/j5qSFb/QmHCu1YK7Ui4TT3OlRBVJ5tp1gaNzdXaO4ZulJV8Jl8IA8EQ= 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 1555510184432779.6423019227391; Wed, 17 Apr 2019 07:09:44 -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 83438308A101; Wed, 17 Apr 2019 14:09: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 418F81001E7C; Wed, 17 Apr 2019 14:09:37 +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 BCD45181AC45; Wed, 17 Apr 2019 14:09:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9YuS023739 for ; Wed, 17 Apr 2019 10:09:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id D43D36014E; Wed, 17 Apr 2019 14:09:34 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4708560161; Wed, 17 Apr 2019 14:09:34 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:08 -0500 Message-Id: <20190417140921.11964-9-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 08/21] 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.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.44]); Wed, 17 Apr 2019 14:09:42 +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 ed1f7168ca..bf152d1dc3 100644 --- a/src/access/viraccessperm.h +++ b/src/access/viraccessperm.h @@ -187,6 +187,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 67f751ef9c..b74b28f55b 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 Sat Apr 27 19:55:39 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=1555510210; cv=none; d=zoho.com; s=zohoarc; b=hOsPElraXaX8utvC6R1Vi38ZvUOqt80zSasV6AZlBORwWJ7VXZYlEZ5OaU0XdFzY9PuPZjlpHd66z7PJ2YCTvOidhOg6KQ0vqEW29Px8xYeJtm9Y7MdYNRjhbBkmm4WJU5dGPOkZj9Oi0T9ljNerLzxIR+WtCJ/wF9AX1ghTsbI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510210; 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=JSMxWCwkUCv9JERKcHQvnQ5xh2Fm7DVHvJo+bO4JuPw=; b=DTK0GdjWTTaJ8HcDf1yWy/zoDLmuM39KbvuIAVaGedn/noI2QxzS3cTuWHi7KdF9M6ho3w1EQiCyhIAp7y1/kHeCMrmSBezjlmLviwsvaQ+o0kK1/R7kB4iJ4COh6/vfS4jRI8r1Nh7eCaglYhAlsrciSUKUr1ssC9tzOQjik00= 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 1555510210449517.296849286468; Wed, 17 Apr 2019 07:10:10 -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 7171E89C39; Wed, 17 Apr 2019 14:10:03 +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 3B5F11001E7C; Wed, 17 Apr 2019 14:10:03 +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 C517B3D85; Wed, 17 Apr 2019 14:10:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9Zps023746 for ; Wed, 17 Apr 2019 10:09:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id A9A2D60161; Wed, 17 Apr 2019 14:09:35 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 047886014E; Wed, 17 Apr 2019 14:09:34 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:09 -0500 Message-Id: <20190417140921.11964-10-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 09/21] backup: Implement backup 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.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.27]); Wed, 17 Apr 2019 14:10:04 +0000 (UTC) The remote code generator had to be taught about the new virDomainCheckpointPtr type, and about the capitalization of virDomainSnapshotCreateXML2(), at which point the remote driver code for backups can be generated. Note that virDomainSnapshotCreateXML2 has an unconditional ACL check on domain:checkpoint privileges, even though those privileges are only needed when the checkpointXml argument is non-NULL. If this turns out to be a problem in practice, we will have to either enhance the access code generator to allow conditionals on whether a parameter is non-NULL, or else create a witness flag (similar to VIR_TYPED_PARAM_STRING_OKAY) that gets automatically set by libvirt-domain-snapshot.c when checkpointXml is non-NULL (so that we can then reuse the existing syntax for making checks conditional on particular bits in flags). But until someone complains, being theoretically too strict is good enough. Signed-off-by: Eric Blake Reviewed-by: Daniel P. Berrang=C3=A9 --- src/remote/remote_daemon_dispatch.c | 20 +++ src/remote/remote_driver.c | 32 +++- src/remote/remote_protocol.x | 258 +++++++++++++++++++++++++++- src/remote_protocol-structs | 139 +++++++++++++++ src/rpc/gendispatch.pl | 32 ++-- 5 files changed, 465 insertions(+), 16 deletions(-) diff --git a/src/remote/remote_daemon_dispatch.c b/src/remote/remote_daemon= _dispatch.c index df28259042..7d2a3b846b 100644 --- a/src/remote/remote_daemon_dispatch.c +++ b/src/remote/remote_daemon_dispatch.c @@ -89,6 +89,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; @@ -100,6 +101,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 @@ -7238,6 +7240,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) { @@ -7348,6 +7356,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_QUIET(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 5c4dd41227..5fc42e2623 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -145,6 +145,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); @@ -156,6 +157,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); /*----------------------------------------------------------------------*/ @@ -8193,6 +8195,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) { @@ -8267,6 +8275,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) { @@ -8516,7 +8531,22 @@ 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.3= .0 */ + .domainCheckpointGetXMLDesc =3D remoteDomainCheckpointGetXMLDesc, /* 5= .3.0 */ + .domainListAllCheckpoints =3D remoteDomainListAllCheckpoints, /* 5.3.0= */ + .domainCheckpointListAllChildren =3D remoteDomainCheckpointListAllChil= dren, /* 5.3.0 */ + .domainCheckpointLookupByName =3D remoteDomainCheckpointLookupByName, = /* 5.3.0 */ + .domainHasCurrentCheckpoint =3D remoteDomainHasCurrentCheckpoint, /* 5= .3.0 */ + .domainCheckpointGetParent =3D remoteDomainCheckpointGetParent, /* 5.3= .0 */ + .domainCheckpointCurrent =3D remoteDomainCheckpointCurrent, /* 5.3.0 */ + .domainCheckpointIsCurrent =3D remoteDomainCheckpointIsCurrent, /* 5.3= .0 */ + .domainCheckpointHasMetadata =3D remoteDomainCheckpointHasMetadata, /*= 5.3.0 */ + .domainCheckpointDelete =3D remoteDomainCheckpointDelete, /* 5.3.0 */ + .domainBackupBegin =3D remoteDomainBackupBegin, /* 5.3.0 */ + .domainBackupGetXMLDesc =3D remoteDomainBackupGetXMLDesc, /* 5.3.0 */ + .domainBackupEnd =3D remoteDomainBackupEnd, /* 5.3.0 */ + .domainSnapshotCreateXML2 =3D remoteDomainSnapshotCreateXML2, /* 5.3.0= */ }; static virNetworkDriver network_driver =3D { diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 11f44ee267..f8f76d1b41 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -137,6 +137,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; @@ -322,6 +325,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; @@ -3573,6 +3582,148 @@ struct remote_connect_get_storage_pool_capabilities= _ret { remote_nonnull_string capabilities; }; +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_has_current_checkpoint_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + +struct remote_domain_has_current_checkpoint_ret { + int result; +}; + +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_current_args { + remote_nonnull_domain dom; + unsigned int flags; +}; + +struct remote_domain_checkpoint_current_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; + +struct remote_domain_checkpoint_is_current_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_is_current_ret { + int current; +}; + +struct remote_domain_checkpoint_has_metadata_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_checkpoint_has_metadata_ret { + int metadata; +}; + +struct remote_domain_checkpoint_delete_args { + remote_nonnull_domain_checkpoint checkpoint; + unsigned int flags; +}; + +struct remote_domain_backup_begin_args { + remote_nonnull_domain dom; + remote_string disk_xml; + remote_string checkpoint_xml; + unsigned int flags; +}; + +struct remote_domain_backup_begin_ret { + int id; +}; + +struct remote_domain_backup_get_xml_desc_args { + remote_nonnull_domain dom; + int id; + unsigned int flags; +}; + +struct remote_domain_backup_get_xml_desc_ret { + remote_nonnull_string xml; +}; + +struct remote_domain_backup_end_args { + remote_nonnull_domain dom; + int id; + unsigned int flags; +}; + +struct remote_domain_backup_end_ret { + int retcode; +}; +struct remote_domain_snapshot_create_xml2_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + remote_string checkpoint_xml; + unsigned int flags; +}; + +struct remote_domain_snapshot_create_xml2_ret { + remote_nonnull_domain_snapshot snap; +}; + /*----- Protocol. -----*/ /* Define the program number, protocol version and procedure numbers here.= */ @@ -6342,5 +6493,110 @@ enum remote_procedure { * @generate: both * @acl: connect:read */ - REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403 + REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + + /** + * @generate: both + * @acl: domain:checkpoint + * @acl: domain:fs_freeze:VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_CREATE_XML =3D 404, + + /** + * @generate: both + * @acl: domain:read + * @acl: domain:read_secure:VIR_DOMAIN_CHECKPOINT_XML_SECURE + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_XML_DESC =3D 405, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_LIST_ALL_CHECKPOINTS =3D 406, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_LIST_ALL_CHILDREN =3D 407, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_LOOKUP_BY_NAME =3D 408, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_HAS_CURRENT_CHECKPOINT =3D 409, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_CURRENT =3D 410, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_PARENT =3D 411, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_IS_CURRENT =3D 412, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_HAS_METADATA =3D 413, + + /** + * @generate: both + * @acl: domain:checkpoint + */ + REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 414, + + /** + * @generate: both + * @acl: domain:checkpoint + * @acl: domain:block_write + * @acl: domain:fs_freeze:VIR_DOMAIN_BACKUP_BEGIN_QUIESCE + */ + REMOTE_PROC_DOMAIN_BACKUP_BEGIN =3D 415, + + /** + * @generate: both + * @priority: high + * @acl: domain:read + */ + REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 416, + + /** + * @generate: both + * @acl: domain:checkpoint + */ + REMOTE_PROC_DOMAIN_BACKUP_END =3D 417, + + /** + * @generate: both + * @acl: domain:snapshot + * @acl: domain:checkpoint + * @acl: domain:fs_freeze:VIR_DOMAIN_SNAPSHOT_CREATE_QUIESCE + */ + REMOTE_PROC_DOMAIN_SNAPSHOT_CREATE_XML2 =3D 418 }; diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index 768189c573..5fb694bba6 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -46,6 +46,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; @@ -2981,6 +2985,126 @@ struct remote_connect_get_storage_pool_capabilities= _args { struct remote_connect_get_storage_pool_capabilities_ret { remote_nonnull_string capabilities; }; +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_has_current_checkpoint_args { + remote_nonnull_domain dom; + u_int flags; +}; +struct remote_domain_has_current_checkpoint_ret { + int result; +}; +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_current_args { + remote_nonnull_domain dom; + u_int flags; +}; +struct remote_domain_checkpoint_current_ret { + remote_nonnull_domain_checkpoint checkpoint; +}; +struct remote_domain_checkpoint_is_current_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_is_current_ret { + int current; +}; +struct remote_domain_checkpoint_has_metadata_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_checkpoint_has_metadata_ret { + int metadata; +}; +struct remote_domain_checkpoint_delete_args { + remote_nonnull_domain_checkpoint checkpoint; + u_int flags; +}; +struct remote_domain_backup_begin_args { + remote_nonnull_domain dom; + remote_string disk_xml; + remote_string checkpoint_xml; + u_int flags; +}; +struct remote_domain_backup_begin_ret { + int id; +}; +struct remote_domain_backup_get_xml_desc_args { + remote_nonnull_domain dom; + int id; + u_int flags; +}; +struct remote_domain_backup_get_xml_desc_ret { + remote_nonnull_string xml; +}; +struct remote_domain_backup_end_args { + remote_nonnull_domain dom; + int id; + u_int flags; +}; +struct remote_domain_backup_end_ret { + int retcode; +}; +struct remote_domain_snapshot_create_xml2_args { + remote_nonnull_domain dom; + remote_nonnull_string xml_desc; + remote_string checkpoint_xml; + u_int flags; +}; +struct remote_domain_snapshot_create_xml2_ret { + remote_nonnull_domain_snapshot snap; +}; enum remote_procedure { REMOTE_PROC_CONNECT_OPEN =3D 1, REMOTE_PROC_CONNECT_CLOSE =3D 2, @@ -3385,4 +3509,19 @@ enum remote_procedure { REMOTE_PROC_CONNECT_LIST_ALL_NWFILTER_BINDINGS =3D 401, REMOTE_PROC_DOMAIN_SET_IOTHREAD_PARAMS =3D 402, REMOTE_PROC_CONNECT_GET_STORAGE_POOL_CAPABILITIES =3D 403, + REMOTE_PROC_DOMAIN_CHECKPOINT_CREATE_XML =3D 404, + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_XML_DESC =3D 405, + REMOTE_PROC_DOMAIN_LIST_ALL_CHECKPOINTS =3D 406, + REMOTE_PROC_DOMAIN_CHECKPOINT_LIST_ALL_CHILDREN =3D 407, + REMOTE_PROC_DOMAIN_CHECKPOINT_LOOKUP_BY_NAME =3D 408, + REMOTE_PROC_DOMAIN_HAS_CURRENT_CHECKPOINT =3D 409, + REMOTE_PROC_DOMAIN_CHECKPOINT_CURRENT =3D 410, + REMOTE_PROC_DOMAIN_CHECKPOINT_GET_PARENT =3D 411, + REMOTE_PROC_DOMAIN_CHECKPOINT_IS_CURRENT =3D 412, + REMOTE_PROC_DOMAIN_CHECKPOINT_HAS_METADATA =3D 413, + REMOTE_PROC_DOMAIN_CHECKPOINT_DELETE =3D 414, + REMOTE_PROC_DOMAIN_BACKUP_BEGIN =3D 415, + REMOTE_PROC_DOMAIN_BACKUP_GET_XML_DESC =3D 416, + REMOTE_PROC_DOMAIN_BACKUP_END =3D 417, + REMOTE_PROC_DOMAIN_SNAPSHOT_CREATE_XML2 =3D 418, }; diff --git a/src/rpc/gendispatch.pl b/src/rpc/gendispatch.pl index ae3a42c4c1..857e340692 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|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|storage_vol|= storage_pool|domain_checkpoint|domain_snapshot|domain|server|client) (\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|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_b= inding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|interface|node_device|secret|nwfilter|nwfilter_b= inding|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|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|doma= in_snapshot) (\S+);/) { + } elsif ($args_member =3D~ m/^remote_nonnull_(domain|netwo= rk|storage_pool|storage_vol|interface|secret|nwfilter|nwfilter_binding|doma= in_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"; } else { $priv_src =3D "$arg_name->conn"; @@ -1521,7 +1525,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|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|storage_vol|= storage_pool|domain_checkpoint|domain_snapshot|domain|server|client) (\S+)<= (\S+)>;/) { my $proc_name =3D name_to_TypeName($1); if ($structprefix eq "admin") { @@ -1574,7 +1578,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|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_b= inding|domain_snapshot) (\S+);/) { + } elsif ($ret_member =3D~ m/^remote_nonnull_(domain|networ= k|storage_pool|storage_vol|node_device|interface|secret|nwfilter|nwfilter_b= inding|domain_checkpoint|domain_snapshot) (\S+);/) { my $name =3D $1; my $arg_name =3D $2; my $type_name =3D name_to_TypeName($name); @@ -1588,7 +1592,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);"); @@ -1932,7 +1936,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 Sat Apr 27 19:55:39 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=1555510230; cv=none; d=zoho.com; s=zohoarc; b=KA4sx+VpvWPk46aqwdIN65wTSugNnJjOKqKPxu0OZh1gqGhDYpCmiNEANyJNpL95b3RzPOMlS13+wsXMkeXJGT4WcEWknAbmXzpPsxzs7oqhPTR23u0LOXS30HrwPMo2z7MDHOtBW8HDVxm5zL0LsjzUe6Kd4Ptfofxyk/MO2Eg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510230; 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=HxqV21K9dDt5kZ3vfEeem8zm/q1rTR93O9iAmqCSH0g=; b=k75cVJfNG0C60gDpuQf2AZIa99ivMI9NJ/wj6ChEBO4jx88rX7P8zSbvISTtdLBLOvSGkO0VEa+GgBX+BAY4Ph1jEV2MDMcYVuAucphVhkOUTBq1QIxrfGcthgqck1Y9MKgpbMinxEeLucBWUEVuVVsoBZo/fN3mbrr3XOsVIs8= 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 1555510230691429.22564693330867; Wed, 17 Apr 2019 07:10:30 -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 8EBD6307B964; Wed, 17 Apr 2019 14:10:28 +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 DD634608C6; Wed, 17 Apr 2019 14:10:27 +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 9BFE93FA4D; Wed, 17 Apr 2019 14:10:27 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9a3Z023754 for ; Wed, 17 Apr 2019 10:09:36 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A7AA6015A; Wed, 17 Apr 2019 14:09:36 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id D11DA60161; Wed, 17 Apr 2019 14:09:35 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:10 -0500 Message-Id: <20190417140921.11964-11-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 10/21] conf: Add parameter to virDomainDiskSourceFormat 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.47]); Wed, 17 Apr 2019 14:10:29 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Commits 4bc42986 and 218c81ea removed virDomainStorageSourceFormat on the grounds that there were no external callers; however, the upcoming backup code wants to output a (push mode) or (pull mode) element that is in all other respects identical to a domain's element, where the previous virDomainStorageSourceFormat fit the bill nicely. But rather than reverting the commits, it's easier to just add an additional parameter for the element name to use, and update all callers. Signed-off-by: Eric Blake --- src/conf/domain_conf.h | 1 + src/conf/domain_conf.c | 14 +++++++++----- src/conf/snapshot_conf.c | 3 ++- src/qemu/qemu_domain.c | 2 +- tests/qemublocktest.c | 3 ++- tests/virstoragetest.c | 2 +- 6 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 1ef72f79d8..456da9ec7e 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -3059,6 +3059,7 @@ int virDomainDefFormatInternal(virDomainDefPtr def, int virDomainDiskSourceFormat(virBufferPtr buf, virStorageSourcePtr src, + const char *element, int policy, bool attrIndex, unsigned int flags, diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 1dc552b7f2..36f60fd54a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -23934,6 +23934,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr b= uf, * virDomainDiskSourceFormat: * @buf: output buffer * @src: storage source definition to format + * @element: name to use for the top-level element (often "source") * @policy: startup policy attribute value, if necessary * @attrIndex: the 'index' attribute of is formatted if true * @flags: XML formatter flags @@ -23945,6 +23946,7 @@ virDomainDiskSourceFormatPrivateData(virBufferPtr b= uf, int virDomainDiskSourceFormat(virBufferPtr buf, virStorageSourcePtr src, + const char *element, int policy, bool attrIndex, unsigned int flags, @@ -24025,7 +24027,7 @@ virDomainDiskSourceFormat(virBufferPtr buf, if (virDomainDiskSourceFormatPrivateData(&childBuf, src, flags, xmlopt= ) < 0) return -1; - if (virXMLFormatElement(buf, "source", &attrBuf, &childBuf) < 0) + if (virXMLFormatElement(buf, element, &attrBuf, &childBuf) < 0) return -1; return 0; @@ -24071,7 +24073,8 @@ virDomainDiskBackingStoreFormat(virBufferPtr buf, virBufferAsprintf(&childBuf, "\n", virStorageFileFormatTypeToString(backingStore->forma= t)); - if (virDomainDiskSourceFormat(&childBuf, backingStore, 0, false, flags= , xmlopt) < 0) + if (virDomainDiskSourceFormat(&childBuf, backingStore, "source", 0, fa= lse, + flags, xmlopt) < 0) return -1; if (virDomainDiskBackingStoreFormat(&childBuf, backingStore, xmlopt, f= lags) < 0) @@ -24234,7 +24237,8 @@ virDomainDiskDefFormatMirror(virBufferPtr buf, virDomainDiskMirrorStateTypeToString(disk->m= irrorState)); virBufferEscapeString(&childBuf, "\n", formatStr); - if (virDomainDiskSourceFormat(&childBuf, disk->mirror, 0, true, flags,= xmlopt) < 0) + if (virDomainDiskSourceFormat(&childBuf, disk->mirror, "source", 0, tr= ue, + flags, xmlopt) < 0) return -1; if (virDomainDiskBackingStoreFormat(&childBuf, disk->mirror, xmlopt, f= lags) < 0) @@ -24334,8 +24338,8 @@ virDomainDiskDefFormat(virBufferPtr buf, if (def->src->auth && !def->src->authInherited) virStorageAuthDefFormat(buf, def->src->auth); - if (virDomainDiskSourceFormat(buf, def->src, def->startupPolicy, true, - flags, xmlopt) < 0) + if (virDomainDiskSourceFormat(buf, def->src, "source", def->startupPol= icy, + true, flags, xmlopt) < 0) return -1; /* Don't format backingStore to inactive XMLs until the code for diff --git a/src/conf/snapshot_conf.c b/src/conf/snapshot_conf.c index 36c328f692..eaa9b3c5e6 100644 --- a/src/conf/snapshot_conf.c +++ b/src/conf/snapshot_conf.c @@ -772,7 +772,8 @@ virDomainSnapshotDiskDefFormat(virBufferPtr buf, if (disk->src->format > 0) virBufferEscapeString(buf, "\n", virStorageFileFormatTypeToString(disk->src->= format)); - if (virDomainDiskSourceFormat(buf, disk->src, 0, false, 0, xmlopt) < 0) + if (virDomainDiskSourceFormat(buf, disk->src, "source", 0, false, 0, + xmlopt) < 0) return -1; virBufferAdjustIndent(buf, -2); diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 960aaff3c7..db67fe2193 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2360,7 +2360,7 @@ qemuDomainObjPrivateXMLFormatNBDMigrationSource(virBu= fferPtr buf, virStorageTypeToString(src->type), virStorageFileFormatTypeToString(src->format)); - if (virDomainDiskSourceFormat(&childBuf, src, 0, false, + if (virDomainDiskSourceFormat(&childBuf, src, "source", 0, false, VIR_DOMAIN_DEF_FORMAT_STATUS, xmlopt) < = 0) goto cleanup; diff --git a/tests/qemublocktest.c b/tests/qemublocktest.c index c221b8af30..21db3e4881 100644 --- a/tests/qemublocktest.c +++ b/tests/qemublocktest.c @@ -86,7 +86,8 @@ testBackingXMLjsonXML(const void *args) return -1; } - if (virDomainDiskSourceFormat(&buf, jsonsrc, 0, false, 0, NULL) < 0 || + if (virDomainDiskSourceFormat(&buf, jsonsrc, "source", 0, false, 0, + NULL) < 0 || !(actualxml =3D virBufferContentAndReset(&buf))) { fprintf(stderr, "failed to format disk source xml\n"); return -1; diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c index 4f23511240..ef16b3c6e0 100644 --- a/tests/virstoragetest.c +++ b/tests/virstoragetest.c @@ -627,7 +627,7 @@ testBackingParse(const void *args) goto cleanup; } - if (virDomainDiskSourceFormat(&buf, src, 0, false, 0, NULL) < 0 || + if (virDomainDiskSourceFormat(&buf, src, "source", 0, false, 0, NULL) = < 0 || !(xml =3D virBufferContentAndReset(&buf))) { fprintf(stderr, "failed to format disk source xml\n"); goto cleanup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510235; cv=none; d=zoho.com; s=zohoarc; b=Er6fJsmYlm9m8Twk+kcetSKL+IVtwTi4qkQZPJxXTu+xtunvojzPWdy+w60M4GTXttcb4V+x67vDh9wzml6SqMWhrzk/fgfk5lr1tft//rT50VQV3Ae0sRMgryToNbzebk0pW9t1B3X7VzIdqz7UeuVt97xK+w7hmKPXy4W6PkM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510235; 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=5atXLTiZu2EBfXKvJe+GF2NEJVywPa/Jcu3EVTaDCFo=; b=mvVCkfFvP5HOeX8oiwDX915r6eavtggD/dsl98fJrznq1/cv4/V51WsmH9vMcWabrj4CqS6S0w+fdWk45XzM/i6qCBpSbjYMmmre0DtMm0ef3ujph972nsVF6ZxkNnXbTH1DWT/JFISeWTAkKl2iNqmPBmVx8P0PQH0Bp01nLyM= 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 1555510235519643.4712757518669; Wed, 17 Apr 2019 07:10:35 -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 BA57F30018FE; Wed, 17 Apr 2019 14:10:33 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 8EB8119C78; Wed, 17 Apr 2019 14:10:33 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 33A5C181BA05; Wed, 17 Apr 2019 14:10:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9bLh023764 for ; Wed, 17 Apr 2019 10:09:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id 355426015E; Wed, 17 Apr 2019 14:09:37 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8D1F66014E; Wed, 17 Apr 2019 14:09:36 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:11 -0500 Message-Id: <20190417140921.11964-12-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 11/21] backup: Parse and output backup 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.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 17 Apr 2019 14:10:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Accept XML describing a generic block job, and output it again as needed. This may still need a few tweaks to match the documented XML and RNG schema. Signed-off-by: Eric Blake --- src/conf/backup_conf.h | 97 +++++++ src/conf/virconftypes.h | 3 + src/conf/Makefile.inc.am | 2 + src/conf/backup_conf.c | 538 +++++++++++++++++++++++++++++++++++++++ src/libvirt_private.syms | 8 +- 5 files changed, 647 insertions(+), 1 deletion(-) create mode 100644 src/conf/backup_conf.h create mode 100644 src/conf/backup_conf.c diff --git a/src/conf/backup_conf.h b/src/conf/backup_conf.h new file mode 100644 index 0000000000..74edb601f8 --- /dev/null +++ b/src/conf/backup_conf.h @@ -0,0 +1,97 @@ +/* + * backup_conf.h: domain backup XML processing + * (based on domain_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 + * . + */ + +#ifndef LIBVIRT_BACKUP_CONF_H +# define LIBVIRT_BACKUP_CONF_H + +# include "internal.h" +# include "domain_conf.h" +# include "moment_conf.h" +# include "virenum.h" + +/* Items related to incremental backup state */ + +typedef enum { + VIR_DOMAIN_BACKUP_TYPE_DEFAULT =3D 0, + VIR_DOMAIN_BACKUP_TYPE_PUSH, + VIR_DOMAIN_BACKUP_TYPE_PULL, + + VIR_DOMAIN_BACKUP_TYPE_LAST +} virDomainBackupType; + +typedef enum { + VIR_DOMAIN_BACKUP_DISK_STATE_DEFAULT =3D 0, /* Initial */ + VIR_DOMAIN_BACKUP_DISK_STATE_CREATED, /* File created */ + VIR_DOMAIN_BACKUP_DISK_STATE_LABEL, /* Security labels applied */ + VIR_DOMAIN_BACKUP_DISK_STATE_READY, /* Handed to guest */ + VIR_DOMAIN_BACKUP_DISK_STATE_BITMAP, /* Associated temp bitmap created= */ + VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT, /* NBD export created */ + VIR_DOMAIN_BACKUP_DISK_STATE_COMPLETE, /* Push job finished */ +} virDomainBackupDiskState; + +/* Stores disk-backup information */ +typedef struct _virDomainBackupDiskDef virDomainBackupDiskDef; +typedef virDomainBackupDiskDef *virDomainBackupDiskDefPtr; +struct _virDomainBackupDiskDef { + char *name; /* name matching the dom->disks that matches na= me */ + + /* details of target for push-mode, or of the scratch file for pull-mo= de */ + virStorageSourcePtr store; + int state; /* virDomainBackupDiskState, not stored in XML */ +}; + +/* Stores the complete backup metadata */ +typedef struct _virDomainBackupDef virDomainBackupDef; +typedef virDomainBackupDef *virDomainBackupDefPtr; +struct _virDomainBackupDef { + /* Public XML. */ + int type; /* virDomainBackupType */ + int id; + char *incremental; + virStorageNetHostDefPtr server; /* only when type =3D=3D PULL */ + + size_t ndisks; /* should not exceed dom->ndisks */ + virDomainBackupDiskDef *disks; +}; + +VIR_ENUM_DECL(virDomainBackup); + +typedef enum { + VIR_DOMAIN_BACKUP_PARSE_INTERNAL =3D 1 << 0, +} virDomainBackupParseFlags; + +virDomainBackupDefPtr virDomainBackupDefParseString(const char *xmlStr, + virDomainXMLOptionPtr = xmlopt, + unsigned int flags); +virDomainBackupDefPtr virDomainBackupDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virDomainXMLOptionPtr xm= lopt, + unsigned int flags); +void virDomainBackupDefFree(virDomainBackupDefPtr def); +int virDomainBackupDefFormat(virBufferPtr buf, + virDomainBackupDefPtr def, + bool internal); +int virDomainBackupAlignDisks(virDomainBackupDefPtr backup, + virDomainDefPtr dom, const char *suffix); + +#endif /* LIBVIRT_BACKUP_CONF_H */ diff --git a/src/conf/virconftypes.h b/src/conf/virconftypes.h index d3cc199c43..57022a5288 100644 --- a/src/conf/virconftypes.h +++ b/src/conf/virconftypes.h @@ -355,4 +355,7 @@ typedef virDomainCheckpointObj *virDomainCheckpointObjP= tr; typedef struct _virDomainCheckpointObjList virDomainCheckpointObjList; typedef virDomainCheckpointObjList *virDomainCheckpointObjListPtr; +typedef struct _virDomainBackupDef virDomainBackupDef; +typedef virDomainBackupDef *virDomainBackupDefPtr; + #endif /* LIBVIRT_VIRCONFTYPES_H */ diff --git a/src/conf/Makefile.inc.am b/src/conf/Makefile.inc.am index 1d5ade52b3..d373703e46 100644 --- a/src/conf/Makefile.inc.am +++ b/src/conf/Makefile.inc.am @@ -10,6 +10,8 @@ NETDEV_CONF_SOURCES =3D \ $(NULL) DOMAIN_CONF_SOURCES =3D \ + conf/backup_conf.c \ + conf/backup_conf.h \ conf/capabilities.c \ conf/capabilities.h \ conf/checkpoint_conf.c \ diff --git a/src/conf/backup_conf.c b/src/conf/backup_conf.c new file mode 100644 index 0000000000..723d6bad4b --- /dev/null +++ b/src/conf/backup_conf.c @@ -0,0 +1,538 @@ +/* + * backup_conf.c: domain backup 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 "internal.h" +#include "virbitmap.h" +#include "virbuffer.h" +#include "datatypes.h" +#include "domain_conf.h" +#include "virlog.h" +#include "viralloc.h" +#include "backup_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 + +VIR_LOG_INIT("conf.backup_conf"); + +VIR_ENUM_IMPL(virDomainBackup, + VIR_DOMAIN_BACKUP_TYPE_LAST, + "default", "push", "pull"); + +static void +virDomainBackupDiskDefClear(virDomainBackupDiskDefPtr disk) +{ + VIR_FREE(disk->name); + virStorageSourceClear(disk->store); + disk->store =3D NULL; +} + +void +virDomainBackupDefFree(virDomainBackupDefPtr def) +{ + size_t i; + + if (!def) + return; + + VIR_FREE(def->incremental); + virStorageNetHostDefFree(1, def->server); + for (i =3D 0; i < def->ndisks; i++) + virDomainBackupDiskDefClear(&def->disks[i]); + VIR_FREE(def->disks); + VIR_FREE(def); +} + +static int +virDomainBackupDiskDefParseXML(xmlNodePtr node, + xmlXPathContextPtr ctxt, + virDomainBackupDiskDefPtr def, + bool push, bool internal, + virDomainXMLOptionPtr xmlopt) +{ + int ret =3D -1; + // char *backup =3D NULL; /* backup=3D"yes|no"? */ + char *type =3D NULL; + char *driver =3D NULL; + xmlNodePtr cur; + xmlNodePtr saved =3D ctxt->node; + + ctxt->node =3D node; + + if (VIR_ALLOC(def->store) < 0) + goto cleanup; + + def->name =3D virXMLPropString(node, "name"); + if (!def->name) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("missing name from disk backup element")); + goto cleanup; + } + + /* Needed? A way for users to list a disk and explicitly mark it + * as not participating, and then output shows all disks rather + * than just active disks */ +#if 0 + backup =3D virXMLPropString(node, "backup"); + if (backup) { + def->type =3D virDomainCheckpointTypeFromString(checkpoint); + if (def->type <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk checkpoint setting '%s'"), + checkpoint); + goto cleanup; + } + } +#endif + + if ((type =3D virXMLPropString(node, "type"))) { + if ((def->store->type =3D virStorageTypeFromString(type)) <=3D 0 || + def->store->type =3D=3D VIR_STORAGE_TYPE_VOLUME || + def->store->type =3D=3D VIR_STORAGE_TYPE_DIR) { + virReportError(VIR_ERR_XML_ERROR, + _("unknown disk backup type '%s'"), type); + goto cleanup; + } + } else { + def->store->type =3D VIR_STORAGE_TYPE_FILE; + } + + if ((cur =3D virXPathNode(push ? "./target" : "./scratch", ctxt)) && + virDomainStorageSourceParse(cur, ctxt, def->store, 0, xmlopt) < 0) + goto cleanup; + + if (internal) { + int detected; + if (virXPathInt("string(./node/@detected)", ctxt, &detected) < 0) + goto cleanup; + def->store->detected =3D detected; + def->store->nodeformat =3D virXPathString("string(./node)", ctxt); + } + + if ((driver =3D virXPathString("string(./driver/@type)", ctxt))) { + def->store->format =3D virStorageFileFormatTypeFromString(driver); + if (def->store->format <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown disk backup driver '%s'"), driver); + goto cleanup; + } else if (!push && def->store->format !=3D VIR_STORAGE_FILE_QCOW2= ) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("pull mode requires qcow2 driver, not '%s'"), + driver); + goto cleanup; + } + } + + /* validate that the passed path is absolute */ + if (virStorageSourceIsRelative(def->store)) { + virReportError(VIR_ERR_XML_ERROR, + _("disk backup image path '%s' must be absolute"), + def->store->path); + goto cleanup; + } + + ret =3D 0; + cleanup: + ctxt->node =3D saved; + + VIR_FREE(driver); +// VIR_FREE(backup); + VIR_FREE(type); + if (ret < 0) + virDomainBackupDiskDefClear(def); + return ret; +} + +static virDomainBackupDefPtr +virDomainBackupDefParse(xmlXPathContextPtr ctxt, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainBackupDefPtr def =3D NULL; + virDomainBackupDefPtr ret =3D NULL; + xmlNodePtr *nodes =3D NULL; + xmlNodePtr node =3D NULL; + char *mode =3D NULL; + bool push; + size_t i; + int n; + + if (VIR_ALLOC(def) < 0) + goto cleanup; + + mode =3D virXMLPropString(ctxt->node, "mode"); + if (mode) { + def->type =3D virDomainBackupTypeFromString(mode); + if (def->type <=3D 0) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unknown backup mode '%s'"), mode); + goto cleanup; + } + } else { + def->type =3D VIR_DOMAIN_BACKUP_TYPE_PUSH; + } + push =3D def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PUSH; + + if (flags & VIR_DOMAIN_BACKUP_PARSE_INTERNAL) { + char *tmp =3D virXMLPropString(ctxt->node, "id"); + if (tmp && virStrToLong_i(tmp, NULL, 10, &def->id) < 0) { + virReportError(VIR_ERR_XML_ERROR, + _("invalid 'id' value '%s'"), tmp); + VIR_FREE(tmp); + goto cleanup; + } + VIR_FREE(tmp); + } + + def->incremental =3D virXPathString("string(./incremental)", ctxt); + + node =3D virXPathNode("./server", ctxt); + if (node) { + if (def->type !=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("use of requires pull mode backup")); + goto cleanup; + } + if (VIR_ALLOC(def->server) < 0) + goto cleanup; + if (virDomainStorageNetworkParseHost(node, def->server) < 0) + goto cleanup; + if (def->server->transport =3D=3D VIR_STORAGE_NET_HOST_TRANS_RDMA)= { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("transport rdma is not supported for = ")); + goto cleanup; + } + } + + if ((n =3D virXPathNodeSet("./disks/*", ctxt, &nodes)) < 0) + goto cleanup; + if (n && VIR_ALLOC_N(def->disks, n) < 0) + goto cleanup; + def->ndisks =3D n; + for (i =3D 0; i < def->ndisks; i++) { + if (virDomainBackupDiskDefParseXML(nodes[i], ctxt, + &def->disks[i], push, + flags & VIR_DOMAIN_BACKUP_PARSE= _INTERNAL, + xmlopt) < 0) + goto cleanup; + } + VIR_FREE(nodes); + + VIR_STEAL_PTR(ret, def); + + cleanup: + VIR_FREE(mode); + VIR_FREE(nodes); + virDomainBackupDefFree(def); + + return ret; +} + +virDomainBackupDefPtr +virDomainBackupDefParseString(const char *xmlStr, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + virDomainBackupDefPtr ret =3D NULL; + xmlDocPtr xml; + int keepBlanksDefault =3D xmlKeepBlanksDefault(0); + + if ((xml =3D virXMLParse(NULL, xmlStr, _("(domain_backup)")))) { + xmlKeepBlanksDefault(keepBlanksDefault); + ret =3D virDomainBackupDefParseNode(xml, xmlDocGetRootElement(xml), + xmlopt, flags); + xmlFreeDoc(xml); + } + xmlKeepBlanksDefault(keepBlanksDefault); + + return ret; +} + +virDomainBackupDefPtr +virDomainBackupDefParseNode(xmlDocPtr xml, + xmlNodePtr root, + virDomainXMLOptionPtr xmlopt, + unsigned int flags) +{ + xmlXPathContextPtr ctxt =3D NULL; + virDomainBackupDefPtr def =3D NULL; + + if (!virXMLNodeNameEqual(root, "domainbackup")) { + virReportError(VIR_ERR_XML_ERROR, "%s", _("domainbackup")); + goto cleanup; + } + + ctxt =3D xmlXPathNewContext(xml); + if (ctxt =3D=3D NULL) { + virReportOOMError(); + goto cleanup; + } + + ctxt->node =3D root; + def =3D virDomainBackupDefParse(ctxt, xmlopt, flags); + cleanup: + xmlXPathFreeContext(ctxt); + return def; +} + +static int +virDomainBackupDiskDefFormat(virBufferPtr buf, + virDomainBackupDiskDefPtr disk, + bool push, bool internal) +{ + int type =3D disk->store->type; + virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; + virBuffer childBuf =3D VIR_BUFFER_INITIALIZER; + int ret =3D -1; + + if (!disk->name) + return 0; + + virBufferEscapeString(buf, "name); + /* TODO: per-disk backup=3Doff? */ + + virBufferAsprintf(buf, " type=3D'%s'>\n", virStorageTypeToString(type)= ); + virBufferAdjustIndent(buf, 2); + + if (disk->store->format > 0) + virBufferEscapeString(buf, "\n", + virStorageFileFormatTypeToString(disk->store= ->format)); + /* TODO: should node names be part of storage file xml, rather + * than a one-off hack for qemu? */ + if (internal) { + virBufferEscapeString(buf, "store->detected ? "1" : "0"); + virBufferEscapeString(buf, ">%s\n", disk->store->nodeformat= ); + } + + if (virDomainDiskSourceFormat(buf, disk->store, push ? "target" : "scr= atch", + 0, false, 0, NULL) < 0) + goto cleanup; + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + ret =3D 0; + + cleanup: + virBufferFreeAndReset(&attrBuf); + virBufferFreeAndReset(&childBuf); + return ret; +} + +int +virDomainBackupDefFormat(virBufferPtr buf, virDomainBackupDefPtr def, + bool internal) +{ + size_t i; + + virBufferAsprintf(buf, "type)); + if (def->id) + virBufferAsprintf(buf, " id=3D'%d'", def->id); + virBufferAddLit(buf, ">\n"); + virBufferAdjustIndent(buf, 2); + + virBufferEscapeString(buf, "%s\n", + def->incremental); + if (def->server) { + virBufferAsprintf(buf, "serv= er->transport)); + virBufferEscapeString(buf, " name=3D'%s'", def->server->name); + if (def->server->port) + virBufferAsprintf(buf, " port=3D'%u'", def->server->port); + virBufferEscapeString(buf, " socket=3D'%s'", def->server->socket); + virBufferAddLit(buf, "/>\n"); + } + + if (def->ndisks) { + virBufferAddLit(buf, "\n"); + virBufferAdjustIndent(buf, 2); + for (i =3D 0; i < def->ndisks; i++) { + if (!def->disks[i].store) + continue; + if (virDomainBackupDiskDefFormat(buf, &def->disks[i], + def->type =3D=3D VIR_DOMAIN_B= ACKUP_TYPE_PUSH, + internal) < 0) + return -1; + } + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + } + + virBufferAdjustIndent(buf, -2); + virBufferAddLit(buf, "\n"); + + return virBufferCheckError(buf); +} + + +static int +virDomainBackupCompareDiskIndex(const void *a, const void *b) +{ + const virDomainBackupDiskDef *diska =3D a; + const virDomainBackupDiskDef *diskb =3D b; + + /* Integer overflow shouldn't be a problem here. */ + return diska->idx - diskb->idx; +} + +static int +virDomainBackupDefAssignStore(virDomainBackupDiskDefPtr disk, + virStorageSourcePtr src, + const char *suffix) +{ + int ret =3D -1; + + if (virStorageSourceIsEmpty(src)) { + if (disk->store) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk '%s' has no media"), disk->name); + goto cleanup; + } + } else if (src->readonly && disk->store) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("backup of readonly disk '%s' makes no sense"), + disk->name); + goto cleanup; + } else if (!disk->store) { + if (virStorageSourceGetActualType(src) =3D=3D VIR_STORAGE_TYPE_FIL= E) { + if (VIR_ALLOC(disk->store) < 0) + goto cleanup; + disk->store->type =3D VIR_STORAGE_TYPE_FILE; + if (virAsprintf(&disk->store->path, "%s.%s", src->path, + suffix) < 0) + goto cleanup; + disk->store->detected =3D true; + } else { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("refusing to generate file name for disk '%s'= "), + disk->name); + goto cleanup; + } + } + ret =3D 0; + cleanup: + return ret; +} + +/* Align def->disks to domain. Sort the list of def->disks, + * generating storage names using suffix as needed. 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 +virDomainBackupAlignDisks(virDomainBackupDefPtr def, virDomainDefPtr dom, + const char *suffix) +{ + int ret =3D -1; + virBitmapPtr map =3D NULL; + size_t i; + int ndisks; + bool alloc_all =3D false; + + if (def->ndisks > dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("too many disk backup requests for domain")); + goto cleanup; + } + + /* Unlikely to have a guest without disks but technically possible. */ + if (!dom->ndisks) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("domain must have at least one disk to perform " + "backups")); + goto cleanup; + } + + if (!(map =3D virBitmapNew(dom->ndisks))) + goto cleanup; + + /* Double check requested disks. */ + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDefPtr disk =3D &def->disks[i]; + int idx =3D virDomainDiskIndexByName(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; + } + ignore_value(virBitmapSetBit(map, idx)); + disk->idx =3D idx; + + if (STRNEQ(disk->name, dom->disks[idx]->dst)) { + VIR_FREE(disk->name); + if (VIR_STRDUP(disk->name, dom->disks[idx]->dst) < 0) + goto cleanup; + } + if (disk->store && !disk->store->path) { + virStorageSourceClear(disk->store); + disk->store =3D NULL; + } + if (virDomainBackupDefAssignStore(disk, dom->disks[i]->src, suffix= ) < 0) + goto cleanup; + } + + /* Provide fillers for all remaining disks, for easier iteration. */ + if (!def->ndisks) + alloc_all =3D true; + ndisks =3D def->ndisks; + if (VIR_EXPAND_N(def->disks, def->ndisks, + dom->ndisks - def->ndisks) < 0) + goto cleanup; + + for (i =3D 0; i < dom->ndisks; i++) { + virDomainBackupDiskDefPtr disk; + + if (virBitmapIsBitSet(map, i)) + continue; + disk =3D &def->disks[ndisks++]; + if (VIR_STRDUP(disk->name, dom->disks[i]->dst) < 0) + goto cleanup; + disk->idx =3D i; + if (alloc_all && + virDomainBackupDefAssignStore(disk, dom->disks[i]->src, suffix= ) < 0) + goto cleanup; + } + + qsort(&def->disks[0], def->ndisks, sizeof(def->disks[0]), + virDomainBackupCompareDiskIndex); + + ret =3D 0; + + cleanup: + virBitmapFree(map); + return ret; +} diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 5ae0e49927..afe2ef403b 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -70,6 +70,13 @@ virCapabilitiesSetNetPrefix; # conf/checkpoint_conf.h +virDomainBackupAlignDisks; +virDomainBackupDefFormat; +virDomainBackupDefFree; +virDomainBackupDefParseNode; +virDomainBackupDefParseString; +virDomainBackupTypeFromString; +virDomainBackupTypeToString; virDomainCheckpointAlignDisks; virDomainCheckpointDefFormat; virDomainCheckpointDefFree; @@ -79,7 +86,6 @@ virDomainCheckpointRedefinePrep; virDomainCheckpointTypeFromString; virDomainCheckpointTypeToString; - # conf/cpu_conf.h virCPUCacheModeTypeFromString; virCPUCacheModeTypeToString; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510236; cv=none; d=zoho.com; s=zohoarc; b=oS0cgJc+07DOIg0NiG9oZd4676FW2hhnAM6xfjHM/ENugr54yCujfYx2pOsuzbVdzP4DiMopdc8TLzJt5iKudjVQ2gRiC1Xs8QkFOVJk/cwh+kDYVJkac+XqJYgHAC2c4ArdJwx7cbNnSxZuLDBfzWktEzth4kCYNoxCHPH/nS8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510236; 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=FxOUrutdSqdEfSIKq+xPARg1FRLDdIWe2ozj6AyN+mA=; b=l2Q15BcQxHDfBzeNAJ239Szrkfh02ewDKnui9hfKDw6g2pEWYuGSKP5MYxRaB/kvkufYXN+JiJLU7ZdnoV9TkdIhmV74+p3BtTCfaWWQonVWlyF2a/572ZVonLKmy9kx8U44tTDgEijXXr+3LTEZ3Dqggm9pZNDTZymmuuiSaQw= 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 1555510236647500.983253158896; Wed, 17 Apr 2019 07:10: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 A1486C067C2B; Wed, 17 Apr 2019 14:10:29 +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 7C74B608C6; Wed, 17 Apr 2019 14:10:29 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3308A181B9F5; Wed, 17 Apr 2019 14:10:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9cAQ023774 for ; Wed, 17 Apr 2019 10:09:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D82560166; Wed, 17 Apr 2019 14:09:38 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5BF406015E; Wed, 17 Apr 2019 14:09:37 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:12 -0500 Message-Id: <20190417140921.11964-13-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 12/21] 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Wed, 17 Apr 2019 14:10:30 +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 (no need for checkpoint-revert, and checkpoint-list was a lot easier since we don't have to cater to older libvirt API). Signed-off-by: Eric Blake --- tools/virsh-checkpoint.h | 29 + 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 | 1370 ++++++++++++++++++++++++++++++++++ tools/virsh-completer.c | 51 ++ tools/virsh-domain-monitor.c | 23 + tools/virsh-domain.c | 15 + tools/virsh-util.c | 11 + tools/virsh.c | 2 + tools/virsh.pod | 238 +++++- 13 files changed, 1742 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..707defa1c5 --- /dev/null +++ b/tools/virsh-checkpoint.h @@ -0,0 +1,29 @@ +/* + * virsh-checkpoint.h: Commands to manage domain checkpoints + * + * Copyright (C) 2005-2018 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_VIRSH_CHECKPOINT_H +# define LIBVIRT_VIRSH_CHECKPOINT_H + +# include "virsh.h" + +extern const vshCmdDef checkpointCmds[]; + +#endif /* LIBVIRT_VIRSH_CHECKPOINT_H */ diff --git a/tools/virsh-completer.h b/tools/virsh-completer.h index ed37a26cc9..9e94e85d32 100644 --- a/tools/virsh-completer.h +++ b/tools/virsh-completer.h @@ -75,6 +75,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 fb2ed277af..f814558144 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -43,6 +43,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 254ce3289e..da157d6caa 100644 --- a/tools/virsh.h +++ b/tools/virsh.h @@ -41,6 +41,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 57c55fb35f..70417cd01b 100644 --- a/po/POTFILES +++ b/po/POTFILES @@ -300,6 +300,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..3089383dc5 --- /dev/null +++ b/tools/virsh-checkpoint.c @@ -0,0 +1,1370 @@ +/* + * 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" + +/* 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 snapshot 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") + }, + VIRSH_COMMON_OPT_CURRENT(N_("with redefine, set current checkpoint")), + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("create checkpoint but create no metadata") + }, + {.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, "current")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT; + if (vshCommandOptBool(cmd, "no-metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA; + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_SNAPSHOT_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 "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("take checkpoint but create no metadata") + }, + {.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, "no-metadata")) { + if (vshCommandOptBool(cmd, "print-xml")) { + vshError(ctl, "%s", + _("--print-xml is incompatible with --no-metadata")); + return false; + } + flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_NO_METADATA; + } + 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 {--current | --ARG name} into a checkpoint + * belonging to DOM. If EXCLUSIVE, fail if both --current and arg are + * present. 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, + bool exclusive, + virDomainPtr dom, + virDomainCheckpointPtr *chk, + const char **name) +{ + bool current =3D vshCommandOptBool(cmd, "current"); + const char *chkname =3D NULL; + + if (vshCommandOptStringReq(ctl, cmd, arg, &chkname) < 0) + return -1; + + if (exclusive && current && chkname) { + vshError(ctl, _("--%s and --current are mutually exclusive"), arg); + return -1; + } + + if (chkname) { + *chk =3D virDomainCheckpointLookupByName(dom, chkname, 0); + } else if (current) { + *chk =3D virDomainCheckpointCurrent(dom, 0); + } else { + vshError(ctl, _("--%s or --current 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, + }, + VIRSH_COMMON_OPT_CURRENT(N_("also set edited checkpoint as current")), + {.name =3D "rename", + .type =3D VSH_OT_BOOL, + .help =3D N_("allow renaming an existing checkpoint") + }, + {.name =3D "clone", + .type =3D VSH_OT_BOOL, + .help =3D N_("allow cloning to new name") + }, + {.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; + bool rename_okay =3D vshCommandOptBool(cmd, "rename"); + bool clone_okay =3D vshCommandOptBool(cmd, "clone"); + + VSH_EXCLUSIVE_OPTIONS_EXPR("rename", rename_okay, "clone", clone_okay) + + if (vshCommandOptBool(cmd, "current") && + vshCommandOptBool(cmd, "checkpointname")) + define_flags |=3D VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", false, dom, + &checkpoint, &name) < 0) + goto cleanup; + +#define EDIT_GET_XML \ + virDomainCheckpointGetXMLDesc(checkpoint, getxml_flags) +#define EDIT_NOT_CHANGED \ + do { \ + /* Depending on flags, we re-edit even if XML is unchanged. */ \ + if (!(define_flags & VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT)) { \ + 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 if (clone_okay) { + vshPrintExtra(ctl, _("Checkpoint %s cloned to %s.\n"), name, + edited_name); + } else { + unsigned int delete_flags; + + delete_flags =3D VIR_DOMAIN_CHECKPOINT_DELETE_METADATA_ONLY; + if (virDomainCheckpointDelete(rename_okay ? checkpoint : edited, + delete_flags) < 0) { + vshReportError(ctl); + vshError(ctl, _("Failed to clean up %s"), + rename_okay ? name : edited_name); + goto cleanup; + } + if (!rename_okay) { + vshError(ctl, _("Must use --rename or --clone to change %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; +} + + +/* + * "checkpoint-current" command + */ +static const vshCmdInfo info_checkpoint_current[] =3D { + {.name =3D "help", + .data =3D N_("Get or set the current checkpoint") + }, + {.name =3D "desc", + .data =3D N_("Get or set the current checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_checkpoint_current[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "name", + .type =3D VSH_OT_BOOL, + .help =3D N_("list the name, rather than the full xml") + }, + {.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 "checkpointname", + .type =3D VSH_OT_STRING, + .help =3D N_("name of existing checkpoint to make current"), + .completer =3D virshCheckpointNameCompleter, + }, + {.name =3D NULL} +}; + +static bool +cmdCheckpointCurrent(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + int current; + virDomainCheckpointPtr checkpoint =3D NULL; + char *xml =3D NULL; + const char *checkpointname =3D NULL; + unsigned int flags =3D 0; + const char *domname; + + 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; + + VSH_EXCLUSIVE_OPTIONS("name", "checkpointname"); + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, &domname))) + return false; + + if (vshCommandOptStringReq(ctl, cmd, "checkpointname", &checkpointname= ) < 0) + goto cleanup; + + if (checkpointname) { + virDomainCheckpointPtr checkpoint2 =3D NULL; + flags =3D (VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT); + + if (!(checkpoint =3D virDomainCheckpointLookupByName(dom, + checkpointname,= 0))) + goto cleanup; + + xml =3D virDomainCheckpointGetXMLDesc(checkpoint, + VIR_DOMAIN_CHECKPOINT_XML_SECU= RE); + if (!xml) + goto cleanup; + + if (!(checkpoint2 =3D virDomainCheckpointCreateXML(dom, xml, flags= ))) + goto cleanup; + + virshDomainCheckpointFree(checkpoint2); + vshPrintExtra(ctl, _("Checkpoint %s set as current"), checkpointna= me); + ret =3D true; + goto cleanup; + } + + if ((current =3D virDomainHasCurrentCheckpoint(dom, 0)) < 0) + goto cleanup; + + if (!current) { + vshError(ctl, _("domain '%s' has no current checkpoint"), domname); + goto cleanup; + } else { + if (!(checkpoint =3D virDomainCheckpointCurrent(dom, 0))) + goto cleanup; + + if (vshCommandOptBool(cmd, "name")) { + const char *name; + if (!(name =3D virDomainCheckpointGetName(checkpoint))) + goto cleanup; + + vshPrint(ctl, "%s", name); + } else { + if (!(xml =3D virDomainCheckpointGetXMLDesc(checkpoint, flags)= )) + goto cleanup; + + vshPrint(ctl, "%s", xml); + } + } + + ret =3D true; + + cleanup: + if (!ret) + vshReportError(ctl); + VIR_FREE(xml); + 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, + }, + VIRSH_COMMON_OPT_CURRENT(N_("info on current checkpoint")), + {.name =3D NULL} +}; + + +static bool +cmdCheckpointInfo(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom; + virDomainCheckpointPtr checkpoint =3D NULL; + const char *name; + char *parent =3D NULL; + bool ret =3D false; + int count; + unsigned int flags; + int current; + int metadata; + + dom =3D virshCommandOptDomain(ctl, cmd, NULL); + if (dom =3D=3D NULL) + return false; + + if (virshLookupCheckpoint(ctl, cmd, "checkpointname", true, dom, + &checkpoint, &name) < 0) + goto cleanup; + + vshPrint(ctl, "%-15s %s\n", _("Name:"), name); + vshPrint(ctl, "%-15s %s\n", _("Domain:"), virDomainGetName(dom)); + + /* Determine if checkpoint is current. */ + current =3D virDomainCheckpointIsCurrent(checkpoint, 0); + if (current < 0) { + vshError(ctl, "%s", + _("unexpected problem querying checkpoint state")); + goto cleanup; + } + vshPrint(ctl, "%-15s %s\n", _("Current:"), + current > 0 ? _("yes") : _("no")); + + 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); + + /* Metadata. */ + metadata =3D virDomainCheckpointHasMetadata(checkpoint, 0); + if (metadata >=3D 0) + vshPrint(ctl, "%-15s %s\n", _("Metadata:"), + metadata ? _("yes") : _("no")); + + ret =3D true; + + cleanup: + 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 chklist) +{ + size_t i; + + if (!chklist) + return; + if (chklist->chks) { + for (i =3D 0; i < chklist->nchks; i++) { + virshDomainCheckpointFree(chklist->chks[i].chk); + VIR_FREE(chklist->chks[i].parent); + } + VIR_FREE(chklist->chks); + } + VIR_FREE(chklist); +} + + +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 chklist =3D vshMalloc(ctl, sizeof(*chklist)); + 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. */ + chklist->chks =3D vshCalloc(ctl, count + (tree && from), + sizeof(*chklist->chks)); + chklist->nchks =3D count; + for (i =3D 0; i < count; i++) + chklist->chks[i].chk =3D chks[i]; + VIR_FREE(chks); + if (tree) { + for (i =3D 0; i < count; i++) { + if (virshGetCheckpointParent(ctl, chklist->chks[i].chk, + &chklist->chks[i].parent) < 0) + goto cleanup; + } + if (from) { + chklist->chks[chklist->nchks++].chk =3D from; + virDomainCheckpointRef(from); + } + } + + qsort(chklist->chks, chklist->nchks, sizeof(*chklist->chks), + virshChkSorter); + + ret =3D chklist; + chklist =3D NULL; + + cleanup: + virshCheckpointListFree(chklist); + 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 chklist =3D opaque; + if (parent) + return chklist->chks[id].parent; + return virDomainCheckpointGetName(chklist->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 "metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints that have metadata that would pre= vent undefine") + }, + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("list only checkpoints that have no metadata managed by = libvirt") + }, + {.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, + }, + VIRSH_COMMON_OPT_CURRENT(N_("limit list to children of current checkpo= int")), + {.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"); + bool current =3D vshCommandOptBool(cmd, "current"); + const char *from_chk =3D NULL; + char *parent_chk =3D NULL; + virDomainCheckpointPtr start =3D NULL; + virshCheckpointListPtr chklist =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); + VSH_EXCLUSIVE_OPTIONS_VAR(roots, current); + +#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, "metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_METADATA; + + if (vshCommandOptBool(cmd, "no-metadata")) + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_NO_METADATA; + + if (vshCommandOptBool(cmd, "descendants")) { + if (!from && !current) { + vshError(ctl, "%s", + _("--descendants requires either --from or --current"= )); + return false; + } + flags |=3D VIR_DOMAIN_CHECKPOINT_LIST_DESCENDANTS; + } + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if ((from || current) && + virshLookupCheckpoint(ctl, cmd, "from", true, dom, &start, &from_c= hk) < 0) + goto cleanup; + + if (!(chklist =3D virshCheckpointListCollect(ctl, dom, start, flags, t= ree))) + goto cleanup; + + if (!tree && !name) { + if (parent) + vshPrintExtra(ctl, " %-20s %-25s %s", + _("Name"), _("Creation Time"), _("Parent")); + else + vshPrintExtra(ctl, " %-20s %-25s", + _("Name"), _("Creation Time")); + vshPrintExtra(ctl, "\n" + "------------------------------" + "--------------\n"); + } + + if (tree) { + for (i =3D 0; i < chklist->nchks; i++) { + if (!chklist->chks[i].parent && + vshTreePrint(ctl, virshCheckpointListLookup, chklist, + chklist->nchks, i) < 0) + goto cleanup; + } + ret =3D true; + goto cleanup; + } + + for (i =3D 0; i < chklist->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 chklist->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) + vshPrint(ctl, " %-20s %-25s %s\n", + chk_name, timestr, parent_chk ?: "-"); + else + vshPrint(ctl, " %-20s %-25s\n", chk_name, timestr); + } + + ret =3D true; + + cleanup: + /* this frees up memory from the last iteration of the loop */ + virshCheckpointListFree(chklist); + VIR_FREE(parent_chk); + virshDomainCheckpointFree(start); + xmlXPathFreeContext(ctxt); + xmlFreeDoc(xml); + VIR_FREE(doc); + virshDomainFree(dom); + + 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_DATA, + .flags =3D VSH_OFLAG_REQ, + .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 (vshCommandOptStringReq(ctl, cmd, "checkpointname", &name) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (!(checkpoint =3D virDomainCheckpointLookupByName(dom, 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, + }, + VIRSH_COMMON_OPT_CURRENT(N_("find parent of current checkpoint")), + {.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", true, 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, + }, + VIRSH_COMMON_OPT_CURRENT(N_("delete current checkpoint")), + {.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", true, 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-current", + .handler =3D cmdCheckpointCurrent, + .opts =3D opts_checkpoint_current, + .info =3D info_checkpoint_current, + .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 918e409890..c0689d54b7 100644 --- a/tools/virsh-completer.c +++ b/tools/virsh-completer.c @@ -569,6 +569,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 d87475f6f6..59f3d7e6d9 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1615,6 +1615,7 @@ virshDomainListCollect(vshControl *ctl, unsigned int = flags) int autostart; int state; int nsnap; + int nchk; int mansave; virshControlPtr priv =3D ctl->privData; @@ -1782,6 +1783,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; @@ -1843,6 +1855,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") @@ -1942,6 +1962,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 3ac470fe59..73fecc6e0f 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3631,6 +3631,10 @@ static const vshCmdOptDef opts_undefine[] =3D { .type =3D VSH_OT_BOOL, .help =3D N_("remove all domain snapshot metadata, if inactive") }, + {.name =3D "checkpoints-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("remove all domain checkpoint metadata, if inactive") + }, {.name =3D "nvram", .type =3D VSH_OT_BOOL, .help =3D N_("remove nvram file, if inactive") @@ -3660,6 +3664,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"); @@ -3668,6 +3673,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) /* Positive if these items exist. */ int has_managed_save =3D 0; int has_snapshots_metadata =3D 0; + int has_checkpoints_metadata =3D 0; int has_snapshots =3D 0; /* True if undefine will not strand data, even on older servers. */ bool managed_save_safe =3D false; @@ -3714,6 +3720,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) @@ -3762,7 +3770,12 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) managed_save_safe =3D snapshots_safe =3D true; } } + has_checkpoints_metadata + =3D virDomainListAllCheckpoints(dom, NULL, + VIR_DOMAIN_CHECKPOINT_LIST_METAD= ATA); } + /* Clear flags which older servers might reject, if they would + * otherwise have no effect. */ if (!has_managed_save) { flags &=3D ~VIR_DOMAIN_UNDEFINE_MANAGED_SAVE; managed_save_safe =3D true; @@ -3773,6 +3786,8 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) flags &=3D ~VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA; snapshots_safe =3D true; } + if (has_checkpoints_metadata =3D=3D 0) + flags &=3D ~VIR_DOMAIN_UNDEFINE_CHECKPOINTS_METADATA; /* Stash domain description for later use */ if (vol_string || remove_all_storage) { 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 afc1684db0..064a0a2fa3 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; @@ -1570,7 +1577,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>] @@ -2811,10 +2818,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 @@ -2891,7 +2899,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-snapshots= >]} I<--wipe-storage>] @@ -2909,6 +2917,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. @@ -4876,6 +4890,216 @@ 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<--current>] | [I<--redefine-list>]}] | [I<--no-metadata>] [I<--quiesce= >]} + +Create a checkpoint for domain I with the properties specified +in I describing a top-level element. If +I is completely omitted, then libvirt will create a +checkpoint with a name based on the current time. The new checkpoint +will become current, as listed by B. + +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, and the domain's +current snapshot will not be altered unless the I<--current> flag is +also given. If I<--redefine-list> is specified, I<--redefine> is +implied, I<--current> is rejected, and the XML changes from being a +single to instead being a element +describing a list of checkpoints. List form only works if the domain +has no currently-defined checkpoint metadata, and can be obtained as a +subset of I output. + +If I<--no-metadata> is specified, then the checkpoint data is created, +but any metadata is immediately discarded (that is, libvirt does not +treat the checkpoint as current, and cannot use the checkpoint for an +incremental backup unless I<--redefine> is later used to teach libvirt +about the metadata again). + +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<--no-metadata>]} [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 particip= ate 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. + +If I<--no-metadata> is specified, then the checkpoint data is created, +but any metadata is immediately discarded (that is, libvirt does not +treat the checkpoint as current, and cannot use the checkpoint for an +incremental backup unless I<--redefine> is later used to teach libvirt +about the metadata again). + +=3Ditem B I {[I<--name>] | [I<--security-info>] +[I<--no-domain>] [I<--size>] | [I]} + +Without I, this will output the checkpoint XML for the +domain's current checkpoint (if any). If I<--name> is specified, +output just the current checkpoint name instead of the full xml. +Otherwise, using I<--security-info> will also include security +sensitive information in the XML, using I<--size> will add XML +indicating roughly how much guest data has changed since the +checkpoint was created, and using I<--no-domain> will omit the + element from the output for a more compact view. + +With I, this is a request to make the existing named +checkpoint become the current checkpoint. + +=3Ditem B I [I] [I<--current>] +{[I<--rename>] | [I<--clone>]} + +Edit the XML configuration file for I of a domain. If +both I and I<--current> are specified, also force the +edited checkpoint to become the current snapshot. If +I is omitted, then I<--current> must be supplied, to +edit the current checkpoint. + +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 [--current] + +except that it does some error checking. + +The editor used can be supplied by the C<$VISUAL> or C<$EDITOR> environment +variables, and defaults to C. + +If I<--rename> is specified, then the edits can change the checkpoint +name. If I<--clone> is specified, then changing the snapshot name +will create a clone of the checkpoint metadata. If neither is +specified, then the edits must not change the checkpoint name. Note +that changing a checkpoint name must be done with care, since some +drivers may require the original checkpoint name for actually +accessing changes since a point in time. + +=3Ditem B I {I | I<--current>} + +Output basic information about a named , or the current +checkpoint with I<--current>. + +=3Ditem B I [I<--metadata>] [I<--no-metadata>] +[{I<--parent> | I<--roots> | [{I<--tree> | I<--name>}]}] [I<--topological>] +[{[I<--from>] B | I<--current>} [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; or if I<--current> is provided, +start at the current checkpoint. 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> or I<--current> +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>. + +If I<--metadata> is specified, the list will be filtered to just +checkpoints that involve libvirt metadata, and thus would prevent +B of a persistent domain, or be lost on B of a +transient domain. Likewise, if I<--no-metadata> is specified, the +list will be filtered to just checkpoints that exist without the need +for libvirt metadata. + +=3Ditem B I I [I<--security-info>] +[I<--no-domain>] [I<--size>] + +Output the snapshot 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 roughly +how much guest data has changed since the checkpoint was created, and +using I<--no-domain> will omit the element from the output +for a more compact view. Use B to easily access +the XML of the current snapshot. To grab the XML for all checkpoints +at once, use B. + +=3Ditem B I {I | I<--current>} + +Output the name of the parent checkpoint, if any, for the given +I, or for the current checkpoint with I<--current>. + +=3Ditem B I {I | I<--current>} +[I<--metadata>] [{I<--children> | I<--children-only>}] + +Delete the checkpoint for the domain named I, or the +current checkpoint with I<--current>. 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 Sat Apr 27 19:55:39 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=1555510241; cv=none; d=zoho.com; s=zohoarc; b=lqp+0S1FQpT+w8i29t28FDWZWo6xB/6DX1f2IVHexMYFXMsGBuqzkY6HEDm8Nm6D6nl7HbLhS/WEMysGbKQiKuTboPH5x8aop5H0aUzbwX42OFxyJpspqhLsrMNtix0uZknanREJQ5iRvSaF2yxjDXfJkUnQym/sKjXCmaU6BAw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510241; 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=IDoQMuiyxUL4k8XMCUuwg9z0OhoAuTx7e80k+hvtZOM=; b=I56xMVAGfVKXJcmiGoSB0OP+Fh7O9WuT6PYTaBFTDqf1gArscyoeKuNalAdD7FR9ss25BaRSXr8L0aXagUTIUyxNIF1yOS+2wMz+ykkiEwLjjU4dagev4HWfR8NnQfHZBxiAgoRUR6dB5xp8kswWxBLWpYfnC1l0FlsgJfZQE38= 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 1555510241634455.57720942118056; Wed, 17 Apr 2019 07:10:41 -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 AD7B5C0AC908; Wed, 17 Apr 2019 14:10:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6420E60150; Wed, 17 Apr 2019 14:10:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 08957181AC8F; Wed, 17 Apr 2019 14:10:39 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9dvQ023784 for ; Wed, 17 Apr 2019 10:09:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id 158E76014E; Wed, 17 Apr 2019 14:09:39 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7EE8860166; Wed, 17 Apr 2019 14:09:38 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:13 -0500 Message-Id: <20190417140921.11964-14-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 13/21] backup: Implement virsh support for backup 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.31]); Wed, 17 Apr 2019 14:10:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Introduce a few more new virsh commands for performing backup jobs, as well as creating a checkpoint atomically with a snapshot. At this time, I did not opt for a convenience command 'backup-begin-as' that cobbles together appropriate XML from the user's command line arguments, but that may be a viable future extension. Similarly, since backup is a potentially long-running operation, it might be nice to add some sugar that automatically handles waiting for the job to end, rather than making the user have to poll or figure out virsh event to do the same. Signed-off-by: Eric Blake --- tools/virsh-domain.c | 245 +++++++++++++++++++++++++++++++++++++++++ tools/virsh-snapshot.c | 37 ++++++- tools/virsh.pod | 64 ++++++++++- 3 files changed, 336 insertions(+), 10 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 73fecc6e0f..85006dd98b 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -14045,6 +14045,233 @@ cmdDomFSInfo(vshControl *ctl, const vshCmd *cmd) return ret; } + +/* + * "backup-begin" command + */ +static const vshCmdInfo info_backup_begin[] =3D { + {.name =3D "help", + .data =3D N_("Start a disk backup of a live domain") + }, + {.name =3D "desc", + .data =3D N_("Use XML to start a full or incremental disk backup of a= live " + "domain, optionally creating a checkpoint") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_begin[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "xmlfile", + .type =3D VSH_OT_STRING, + .help =3D N_("domain backup XML"), + }, + {.name =3D "checkpointxml", + .type =3D VSH_OT_STRING, + .help =3D N_("domain checkpoint XML"), + }, + {.name =3D "no-metadata", + .type =3D VSH_OT_BOOL, + .help =3D N_("create checkpoint but don't track metadata"), + }, + {.name =3D "quiesce", + .type =3D VSH_OT_BOOL, + .help =3D N_("quiesce guest's file systems"), + }, + /* TODO: --wait/--verbose/--timeout flags for push model backups? */ + {.name =3D NULL} +}; + +static bool +cmdBackupBegin(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + const char *backup_from =3D NULL; + char *backup_buffer =3D NULL; + const char *check_from =3D NULL; + char *check_buffer =3D NULL; + unsigned int flags =3D 0; + int id; + + if (vshCommandOptBool(cmd, "no-metadata")) + flags |=3D VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA; + if (vshCommandOptBool(cmd, "quiesce")) + flags |=3D VIR_DOMAIN_BACKUP_BEGIN_QUIESCE; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + if (vshCommandOptStringReq(ctl, cmd, "xmlfile", &backup_from) < 0) + goto cleanup; + if (!backup_from) { + backup_buffer =3D vshStrdup(ctl, ""); + } else { + if (virFileReadAll(backup_from, VSH_MAX_XML_FILE, &backup_buffer) = < 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + if (vshCommandOptStringReq(ctl, cmd, "checkpointxml", &check_from) < 0) + goto cleanup; + if (check_from) { + if (virFileReadAll(check_from, VSH_MAX_XML_FILE, &check_buffer) < = 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + id =3D virDomainBackupBegin(dom, backup_buffer, check_buffer, flags); + + if (id < 0) + goto cleanup; + + vshPrint(ctl, _("Backup id %d started\n"), id); + if (backup_from) + vshPrintExtra(ctl, _("backup used description from '%s'\n"), + backup_from); + if (check_buffer) + vshPrintExtra(ctl, _("checkpoint created from '%s'\n"), check_from= ); + + ret =3D true; + + cleanup: + VIR_FREE(backup_buffer); + VIR_FREE(check_buffer); + virshDomainFree(dom); + + return ret; +} + +/* TODO: backup-begin-as? */ + +/* + * "backup-dumpxml" command + */ +static const vshCmdInfo info_backup_dumpxml[] =3D { + {.name =3D "help", + .data =3D N_("Dump XML for an ongoing domain block backup job") + }, + {.name =3D "desc", + .data =3D N_("Backup Dump XML") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_dumpxml[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "id", + .type =3D VSH_OT_INT, + .help =3D N_("backup job id"), + /* TODO: Add API for listing active jobs, then adding a completer? */ + }, + /* TODO - worth adding this flag? + {.name =3D "checkpoint", + .type =3D VSH_OT_BOOL, + .help =3D N_("if the backup created a checkpoint, also dump that XML") + }, + */ + {.name =3D NULL} +}; + +static bool +cmdBackupDumpXML(vshControl *ctl, + const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + char *xml =3D NULL; + unsigned int flags =3D 0; + int id =3D 0; + + if (vshCommandOptBool(cmd, "security-info")) + flags |=3D VIR_DOMAIN_XML_SECURE; + + if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + return false; + + if (!(xml =3D virDomainBackupGetXMLDesc(dom, id, flags))) + goto cleanup; + + vshPrint(ctl, "%s", xml); + ret =3D true; + + cleanup: + VIR_FREE(xml); + virshDomainFree(dom); + + return ret; +} + + +/* + * "backup-end" command + */ +static const vshCmdInfo info_backup_end[] =3D { + {.name =3D "help", + .data =3D N_("Conclude a disk backup of a live domain") + }, + {.name =3D "desc", + .data =3D N_("End a domain block backup job") + }, + {.name =3D NULL} +}; + +static const vshCmdOptDef opts_backup_end[] =3D { + VIRSH_COMMON_OPT_DOMAIN_FULL(0), + {.name =3D "id", + .type =3D VSH_OT_INT, + .help =3D N_("backup job id"), + /* TODO: Add API for listing active jobs, then adding a completer? */ + }, + {.name =3D "abort", + .type =3D VSH_OT_BOOL, + .help =3D N_("abandon a push model backup that has not yet completed") + }, + {.name =3D NULL} +}; + +static bool +cmdBackupEnd(vshControl *ctl, const vshCmd *cmd) +{ + virDomainPtr dom =3D NULL; + bool ret =3D false; + unsigned int flags =3D 0; + int id =3D 0; + int rc; + + if (vshCommandOptBool(cmd, "abort")) + flags |=3D VIR_DOMAIN_BACKUP_END_ABORT; + + if (vshCommandOptInt(ctl, cmd, "id", &id) < 0) + return false; + + if (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL))) + goto cleanup; + + rc =3D virDomainBackupEnd(dom, id, flags); + + if (rc < 0) + goto cleanup; + if (rc =3D=3D 0) + vshPrint(ctl, _("Backup id %d aborted"), id); + else + vshPrint(ctl, _("Backup id %d completed"), id); + + ret =3D true; + + cleanup: + virshDomainFree(dom); + + return ret; +} + + const vshCmdDef domManagementCmds[] =3D { {.name =3D "attach-device", .handler =3D cmdAttachDevice, @@ -14070,6 +14297,24 @@ const vshCmdDef domManagementCmds[] =3D { .info =3D info_autostart, .flags =3D 0 }, + {.name =3D "backup-begin", + .handler =3D cmdBackupBegin, + .opts =3D opts_backup_begin, + .info =3D info_backup_begin, + .flags =3D 0 + }, + {.name =3D "backup-dumpxml", + .handler =3D cmdBackupDumpXML, + .opts =3D opts_backup_dumpxml, + .info =3D info_backup_dumpxml, + .flags =3D 0 + }, + {.name =3D "backup-end", + .handler =3D cmdBackupEnd, + .opts =3D opts_backup_end, + .info =3D info_backup_end, + .flags =3D 0 + }, {.name =3D "blkdeviotune", .handler =3D cmdBlkdeviotune, .opts =3D opts_blkdeviotune, diff --git a/tools/virsh-snapshot.c b/tools/virsh-snapshot.c index f6bb38bc96..57ab80251b 100644 --- a/tools/virsh-snapshot.c +++ b/tools/virsh-snapshot.c @@ -40,18 +40,26 @@ /* Helper for snapshot-create and snapshot-create-as */ static bool -virshSnapshotCreate(vshControl *ctl, virDomainPtr dom, const char *buffer, - unsigned int flags, const char *from) +virshSnapshotCreate(vshControl *ctl, + virDomainPtr dom, + const char *buffer, + const char *check_buffer, + unsigned int flags, + const char *from) { bool ret =3D false; virDomainSnapshotPtr snapshot; bool halt =3D false; const char *name =3D NULL; - snapshot =3D virDomainSnapshotCreateXML(dom, buffer, flags); + if (check_buffer) + snapshot =3D virDomainSnapshotCreateXML2(dom, buffer, check_buffer, + flags); + else + snapshot =3D virDomainSnapshotCreateXML(dom, buffer, flags); /* Emulate --halt on older servers. */ - if (!snapshot && last_error->code =3D=3D VIR_ERR_INVALID_ARG && + if (!check_buffer && !snapshot && last_error->code =3D=3D VIR_ERR_INVA= LID_ARG && (flags & VIR_DOMAIN_SNAPSHOT_CREATE_HALT)) { int persistent; @@ -117,6 +125,10 @@ static const vshCmdOptDef opts_snapshot_create[] =3D { .type =3D VSH_OT_STRING, .help =3D N_("domain snapshot XML") }, + {.name =3D "checkpointxml", + .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 snapshot") @@ -157,7 +169,9 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) bool ret =3D false; const char *from =3D NULL; char *buffer =3D NULL; + const char *check_from =3D NULL; unsigned int flags =3D 0; + VIR_AUTOFREE(char *check_buffer) =3D NULL; if (vshCommandOptBool(cmd, "redefine")) flags |=3D VIR_DOMAIN_SNAPSHOT_CREATE_REDEFINE; @@ -192,7 +206,18 @@ cmdSnapshotCreate(vshControl *ctl, const vshCmd *cmd) } } - ret =3D virshSnapshotCreate(ctl, dom, buffer, flags, from); + if (vshCommandOptStringReq(ctl, cmd, "checkpointxml", &check_from) < 0) + goto cleanup; + if (check_from) { + if (virFileReadAll(check_from, VSH_MAX_XML_FILE, &check_buffer) < = 0) { + vshSaveLibvirtError(); + goto cleanup; + } + } + + ret =3D virshSnapshotCreate(ctl, dom, buffer, check_buffer, flags, fro= m); + if (ret && check_buffer) + vshPrintExtra(ctl, _("checkpoint created from '%s'\n"), check_from= ); cleanup: VIR_FREE(buffer); @@ -434,7 +459,7 @@ cmdSnapshotCreateAs(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - ret =3D virshSnapshotCreate(ctl, dom, buffer, flags, NULL); + ret =3D virshSnapshotCreate(ctl, dom, buffer, NULL, flags, NULL); cleanup: virBufferFreeAndReset(&buf); diff --git a/tools/virsh.pod b/tools/virsh.pod index 064a0a2fa3..af806615bf 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1348,6 +1348,55 @@ I specifies copying bandwidth limit in Mi= B/s. For further information on the I argument see the corresponding section for the B command. +=3Ditem B I [I] +[I [I<--no-metadata>]] [I<--quiesce>] + +Begin a new backup job, and output the resulting job id on success. If +I is omitted, this defaults to a full backup using a push +model to filenames generated by libvirt; supplying XML allows +fine-tuning such as requesting an incremental backup relative to an +earlier checkpoint, controlling which disks participate or which +filenames are involved, or requesting the use of a pull model backup. +The B command shows any resulting values assigned by +libvirt. For more information on backup XML, see: +L. + +If I is specified, a second file with a top-level +element of is used to create a simultaneous +checkpoint, for doing a later incremental backup relative to the time +the snapshot was created. If I<--no-metadata> is specified, then the +checkpoint is created, but any metadata is immediately discarded. See +B for more details on checkpoints. + +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, the backup job will fail. + +This command returns as soon as possible, and the backup job runs in +the background; the progress of a push model backup can be checked +with B or by waiting for an event with B (the +progress of a pull model backup is under the control of whatever third +party connects to the NBD export). The job is ended with B. + +=3Ditem B I [I] + +Output XML describing the backup job I. The default for I is +0, which works as long as there are no parallel jobs; it is also +possible to use the positive id printed by B on success. + +=3Ditem B I [I] [I<--abort>] + +End the currentbackup job I. The default for I is 0, which +works as long as there are no parallel jobs; it is also possible to +use the positive id printed by B on success. + +If the backup job is a push job, but the hypervisor is not yet +complete, this command will fail unless I<--abort> is given; if +aborted, the backup file is incomplete. If the backup job is a pull +job, I<--abort> has no effect, because libvirt assumes the third-party +client is done performing the backup. + + =3Ditem B I I [[I<--config>] [I<--live>] | [I<--current>]] [[I] | [I] [I]] @@ -4593,17 +4642,24 @@ used to represent properties of snapshots. =3Dover 4 =3Ditem B I [I] {[I<--redefine> [I<--cur= rent>]] -| [I<--no-metadata>] [I<--halt>] [I<--disk-only>] [I<--reuse-external>] -[I<--quiesce>] [I<--atomic>] [I<--live>]} +| [I] [I<--no-metadata>] [I<--halt>] [I<--disk-only>] +[I<--reuse-external>] [I<--quiesce>] [I<--atomic>] [I<--live>]} Create a snapshot for domain I with the properties specified in -I. Normally, the only properties settable for a domain snapshot +I, using a top-level element of . Normally, +the only properties settable for a domain snapshot are the and elements, as well as if I<--disk-only> is given; the rest of the fields are ignored, and automatically filled in by libvirt. If I is completely omitted, then libvirt will choose a value for all fields. The new snapshot will become current, as listed by B. +If I is specified, a second file with a top-level +element of is used to create a simultaneous +checkpoint, for doing a later incremental backup relative to the time +the snapshot was created. See B for more details on +checkpoints. + If I<--halt> is specified, the domain will be left in an inactive state after the snapshot is created. @@ -4629,7 +4685,7 @@ If I<--no-metadata> is specified, then the snapshot d= ata is created, but any metadata is immediately discarded (that is, libvirt does not treat the snapshot as current, and cannot revert to the snapshot unless I<--redefine> is later used to teach libvirt about the -metadata again). +metadata again). This flag also affects I. If I<--reuse-external> is specified, and the snapshot XML requests an external snapshot with a destination of an existing file, then the --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510214; cv=none; d=zoho.com; s=zohoarc; b=VEQpUTywGJUFIVucCvE/AGMr7y5hhSXNoVvMGnyD17uQw7EgOgEG/otgXYbP8jD5HdJeBLoz7jFD8A+ucoJq2cDRjgaqiC/8ya5wE3H0qQjPTFcX3rIDv/w4Pw/eygGHbAR+hn9pOelmY1c54H6UoOIIqip7PQn+7D5qu3FBGZ0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510214; 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=Ryc3C2nOi9UNUUiLXV9dwv2b1B6EquUr/KJq07NMock=; b=U5BjykdcS+QBuEIvtZG+KumNx7fipeCK/Dw4mBasDi1+gWM1o7xLCyZKo+e4hC3mbnHJJibnycUGgwkg07unRwYKR7FthktK+vAEIF0Zj4ufeLf9UptwnZ9hiWqAbrJ85/Lr/JgWTngpUroyTg5HQi9sG8TYBAjb2Redb+wJYi0= 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 1555510214434119.22721214463297; Wed, 17 Apr 2019 07:10:14 -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 5E98F356EA; Wed, 17 Apr 2019 14:10:10 +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 23FE260150; Wed, 17 Apr 2019 14:10:10 +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 BCF5F3FB14; Wed, 17 Apr 2019 14:10:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9dio023791 for ; Wed, 17 Apr 2019 10:09:39 -0400 Received: by smtp.corp.redhat.com (Postfix) id C3CFB60150; Wed, 17 Apr 2019 14:09:39 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3AF3C60148; Wed, 17 Apr 2019 14:09:39 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:14 -0500 Message-Id: <20190417140921.11964-15-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 14/21] backup: Prepare for Unix sockets in QMP nbd-server-start 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.30]); Wed, 17 Apr 2019 14:10:11 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Migration always uses a TCP socket for NBD servers, because we don't support same-host migration. But upcoming pull-mode incremental backup needs to also support a Unix socket, for retrieving the backup from the same host. Support this by plumbing virStorageNetHostDef through the monitor calls, since that is the same struct that backup_conf.c chose for tracking both TCP and Unix sockets. Signed-off-by: Eric Blake --- src/qemu/qemu_monitor.h | 6 +++--- src/qemu/qemu_monitor_json.h | 3 +-- src/qemu/qemu_migration.c | 7 ++++++- src/qemu/qemu_monitor.c | 7 +++---- src/qemu/qemu_monitor_json.c | 23 +++++++++++++++++------ tests/qemumonitorjsontest.c | 30 +++++++++++++++++++++++++++++- 6 files changed, 59 insertions(+), 17 deletions(-) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index caf62af5e2..1237c14a84 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -1093,9 +1093,9 @@ int qemuMonitorGetObjectProps(qemuMonitorPtr mon, char *qemuMonitorGetTargetArch(qemuMonitorPtr mon); int qemuMonitorNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, - const char *tls_alias); + const virStorageNetHostDef *server, + const char *tls_alias) + ATTRIBUTE_NONNULL(2); int qemuMonitorNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, bool writable); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index c10513da15..e8472948b5 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -458,8 +458,7 @@ int qemuMonitorJSONGetObjectProps(qemuMonitorPtr mon, char *qemuMonitorJSONGetTargetArch(qemuMonitorPtr mon); int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, + const virStorageNetHostDef *server, const char *tls_alias); int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index e3ad4e52a7..09bd6fbb63 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -380,6 +380,10 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver, unsigned short port =3D 0; char *diskAlias =3D NULL; size_t i; + virStorageNetHostDef server =3D { + .name =3D (char *)listenAddr, /* cast away const */ + .transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP, + }; if (nbdPort < 0 || nbdPort > USHRT_MAX) { virReportError(VIR_ERR_INVALID_ARG, "%s", @@ -415,7 +419,8 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver, else if (virPortAllocatorAcquire(driver->migrationPorts, &port= ) < 0) goto exit_monitor; - if (qemuMonitorNBDServerStart(priv->mon, listenAddr, port, tls= _alias) < 0) + server.port =3D port; + if (qemuMonitorNBDServerStart(priv->mon, &server, tls_alias) <= 0) goto exit_monitor; } diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index babcbde878..694ed90622 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -3924,15 +3924,14 @@ qemuMonitorGetSEVCapabilities(qemuMonitorPtr mon, int qemuMonitorNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, + const virStorageNetHostDef *server, const char *tls_alias) { - VIR_DEBUG("host=3D%s port=3D%u tls_alias=3D%s", host, port, NULLSTR(tl= s_alias)); + VIR_DEBUG("server=3D%p tls_alias=3D%s", server, NULLSTR(tls_alias)); QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONNBDServerStart(mon, host, port, tls_alias); + return qemuMonitorJSONNBDServerStart(mon, server, tls_alias); } diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e7d063a5a8..fc2d193ae2 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -6694,8 +6694,7 @@ qemuMonitorJSONBuildUnixSocketAddress(const char *pat= h) int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, - const char *host, - unsigned int port, + const virStorageNetHostDef *server, const char *tls_alias) { int ret =3D -1; @@ -6704,10 +6703,22 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, virJSONValuePtr addr =3D NULL; char *port_str =3D NULL; - if (virAsprintf(&port_str, "%u", port) < 0) - return ret; - - if (!(addr =3D qemuMonitorJSONBuildInetSocketAddress(host, port_str))) + switch ((virStorageNetHostTransport)server->transport) { + case VIR_STORAGE_NET_HOST_TRANS_TCP: + if (virAsprintf(&port_str, "%u", server->port) < 0) + return ret; + addr =3D qemuMonitorJSONBuildInetSocketAddress(server->name, port_= str); + break; + case VIR_STORAGE_NET_HOST_TRANS_UNIX: + addr =3D qemuMonitorJSONBuildUnixSocketAddress(server->socket); + break; + case VIR_STORAGE_NET_HOST_TRANS_RDMA: + case VIR_STORAGE_NET_HOST_TRANS_LAST: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid server address")); + goto cleanup; + } + if (!addr) goto cleanup; if (!(cmd =3D qemuMonitorJSONMakeCommand("nbd-server-start", diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index f5ad3f6a73..dd3259494a 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1350,7 +1350,6 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "/fo= o/bar1", "/foo/bar2", "back GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb") GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar") GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false) -GEN_TEST_FUNC(qemuMonitorJSONNBDServerStart, "localhost", 12345, "test-ali= as") GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true) GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1") GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true) @@ -1358,6 +1357,35 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose, "foo= dev") GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumRemove, "foodev") GEN_TEST_FUNC(qemuMonitorJSONBlockdevMediumInsert, "foodev", "newnode") +static int +testQemuMonitorJSONqemuMonitorJSONNBDServerStart(const void *data) +{ + virDomainXMLOptionPtr xmlopt =3D (virDomainXMLOptionPtr)data; + qemuMonitorTestPtr test =3D qemuMonitorTestNewSimple(true, xmlopt); + int ret =3D -1; + virStorageNetHostDef server =3D { + .name =3D (char *)"localhost", + .port =3D 12345, + .transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP, + }; + + if (!test) + return -1; + + if (qemuMonitorTestAddItem(test, "nbd-server-start", "{\"return\":{}}"= ) < 0) + goto cleanup; + + if (qemuMonitorJSONNBDServerStart(qemuMonitorTestGetMonitor(test), + &server, "test-alias") < 0) + goto cleanup; + + ret =3D 0; + + cleanup: + qemuMonitorTestFree(test); + return ret; +} + static bool testQemuMonitorJSONqemuMonitorJSONQueryCPUsEqual(struct qemuMonitorQueryCp= usEntry *a, struct qemuMonitorQueryCp= usEntry *b) --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510221; cv=none; d=zoho.com; s=zohoarc; b=mWyEx+0lH29w88f0np7V2vH1ffPHaOntwloTjiKjturPtMbeuaAAUL1lYL642Sn/wZj7EdrzmEGKdKEhD+Nz3VD6EBHKFwJTl5pCV1NQntwWAyPM030QsKog7DpFrYbi/S7EUp4+GlWJ5F676AOPFFoU1hmaXbpYMSNxy7TjRHA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510221; 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=AZiDBocHWJ6+deBFp9jFGn1veebMLn1W1FhuGNZUbbY=; b=fIM9wDuXX0vxblWaWrjrlsU0ari7RipA4TIkMeGIKq8yNGAsdxuLrJxkpf8thyRAYNTWRlvHt8aAmw2XRityN2DmaAdcwJzM5Bm6HB3GfAqUR13LHyEXa2aZCFxF3/RaR4FBhmhMuemCy300lCIHvYwUAbrXuT++X34lU6SKZrA= 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 1555510221539702.1165293324742; Wed, 17 Apr 2019 07:10:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E7F4C306C9E5; Wed, 17 Apr 2019 14:10:19 +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 BCBE95DA38; Wed, 17 Apr 2019 14:10: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 72289181AC8F; Wed, 17 Apr 2019 14:10:19 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9epb023796 for ; Wed, 17 Apr 2019 10:09:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8C8D960159; Wed, 17 Apr 2019 14:09:40 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id E679260148; Wed, 17 Apr 2019 14:09:39 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:15 -0500 Message-Id: <20190417140921.11964-16-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 15/21] backup: Add new qemu monitor interactions X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 17 Apr 2019 14:10:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Add some monitor commands to be used during backup/checkpoint operations: - another facet to query-block for learning bitmap size - new export and bitmap parameters to nbd-server-add - new block-dirty-bitmap-{add,enable,disable,merge} functions Also add two capabilities for testing that they are supported; using block-dirty-bitmap-merge as the generic witness of checkpoint support (since all of the functionalities were added in the same qemu 4.0 release), and the bitmap parameter to nbd-server-add for pull-mode backup support. Even though both capabilities are likely to be present or absent together (that is, it is unlikely to encounter a qemu that backports only one of the two), it still makes sense to keep two capabilities as the two uses are orthogonal (full backups don't require checkpoints, push mode backups don't require NBD bitmap support, and checkpoints can be used for more than just incremental backups). Signed-off-by: Eric Blake --- src/qemu/qemu_capabilities.h | 2 + src/qemu/qemu_monitor.h | 21 +- src/qemu/qemu_monitor_json.h | 19 +- src/qemu/qemu_capabilities.c | 4 + src/qemu/qemu_migration.c | 2 +- src/qemu/qemu_monitor.c | 65 +++++- src/qemu/qemu_monitor_json.c | 199 +++++++++++++++++- .../caps_4.0.0.riscv32.xml | 2 + .../caps_4.0.0.riscv64.xml | 2 + .../caps_4.0.0.x86_64.xml | 2 + tests/qemumonitorjsontest.c | 2 +- 11 files changed, 312 insertions(+), 8 deletions(-) diff --git a/src/qemu/qemu_capabilities.h b/src/qemu/qemu_capabilities.h index 23ecef8c63..fe0675b5cc 100644 --- a/src/qemu/qemu_capabilities.h +++ b/src/qemu/qemu_capabilities.h @@ -506,6 +506,8 @@ typedef enum { /* virQEMUCapsFlags grouping marker for = syntax-check */ QEMU_CAPS_SCSI_DISK_DEVICE_ID, /* 'device_id' property of scsi disk */ QEMU_CAPS_VIRTIO_PCI_TRANSITIONAL, /* virtio *-pci-{non-}transitional = devices */ QEMU_CAPS_OVERCOMMIT, /* -overcommit */ + QEMU_CAPS_BITMAP_MERGE, /* block-dirty-bitmap-merge */ + QEMU_CAPS_NBD_BITMAP, /* nbd-server-add supports bitmap */ QEMU_CAPS_LAST /* this must always be the last item */ } virQEMUCapsFlags; diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index 1237c14a84..aaf8f1df26 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -25,6 +25,7 @@ # include "internal.h" # include "domain_conf.h" +# include "checkpoint_conf.h" # include "virbitmap.h" # include "virhash.h" # include "virjson.h" @@ -630,6 +631,9 @@ int qemuMonitorBlockStatsUpdateCapacity(qemuMonitorPtr = mon, int qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMonitorPtr mon, virHashTablePtr stats) ATTRIBUTE_NONNULL(2); +int qemuMonitorUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk) + ATTRIBUTE_NONNULL(2); int qemuMonitorBlockResize(qemuMonitorPtr mon, const char *device, @@ -646,6 +650,19 @@ int qemuMonitorSetBalloon(qemuMonitorPtr mon, unsigned long long newmem); int qemuMonitorSetCPU(qemuMonitorPtr mon, int cpu, bool online); +int qemuMonitorAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +int qemuMonitorEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); +int qemuMonitorMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3) ATTRIBUTE_NONNULL(4); +int qemuMonitorDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) + ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(3); + /* XXX should we pass the virDomainDiskDefPtr instead * and hide dev_name details inside monitor. Reconsider @@ -1098,7 +1115,9 @@ int qemuMonitorNBDServerStart(qemuMonitorPtr mon, ATTRIBUTE_NONNULL(2); int qemuMonitorNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable); + const char *export, + bool writable, + const char *bitmap); int qemuMonitorNBDServerStop(qemuMonitorPtr); int qemuMonitorGetTPMModels(qemuMonitorPtr mon, char ***tpmmodels); diff --git a/src/qemu/qemu_monitor_json.h b/src/qemu/qemu_monitor_json.h index e8472948b5..f093f1ab3a 100644 --- a/src/qemu/qemu_monitor_json.h +++ b/src/qemu/qemu_monitor_json.h @@ -98,6 +98,9 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon, const char *nodename, unsigned long long size); +int qemuMonitorJSONUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk); + int qemuMonitorJSONSetPassword(qemuMonitorPtr mon, const char *protocol, const char *password, @@ -462,7 +465,9 @@ int qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, const char *tls_alias); int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable); + const char *export, + bool writable, + const char *bitmap); int qemuMonitorJSONNBDServerStop(qemuMonitorPtr mon); int qemuMonitorJSONGetTPMModels(qemuMonitorPtr mon, char ***tpmmodels) @@ -575,4 +580,16 @@ int qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon, virHashTablePtr info) ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2); +int qemuMonitorJSONAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent); + +int qemuMonitorJSONEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap); + +int qemuMonitorJSONMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src); + +int qemuMonitorJSONDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap); + #endif /* LIBVIRT_QEMU_MONITOR_JSON_H */ diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index f8ea66b577..105d6c4320 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -524,6 +524,8 @@ VIR_ENUM_IMPL(virQEMUCaps, "scsi-disk.device_id", "virtio-pci-non-transitional", "overcommit", + "bitmap-merge", + "nbd-bitmap", ); @@ -969,6 +971,7 @@ struct virQEMUCapsStringFlags virQEMUCapsCommands[] =3D= { { "query-cpus-fast", QEMU_CAPS_QUERY_CPUS_FAST }, { "qom-list-properties", QEMU_CAPS_QOM_LIST_PROPERTIES }, { "blockdev-del", QEMU_CAPS_BLOCKDEV_DEL }, + { "block-dirty-bitmap-merge", QEMU_CAPS_BITMAP_MERGE }, }; struct virQEMUCapsStringFlags virQEMUCapsMigration[] =3D { @@ -1263,6 +1266,7 @@ static struct virQEMUCapsStringFlags virQEMUCapsQMPSc= hemaQueries[] =3D { { "block-commit/arg-type/*top", QEMU_CAPS_ACTIVE_COMMIT }, { "query-iothreads/ret-type/poll-max-ns", QEMU_CAPS_IOTHREAD_POLLING }, { "query-display-options/ret-type/+egl-headless/rendernode", QEMU_CAPS= _EGL_HEADLESS_RENDERNODE }, + { "nbd-server-add/arg-type/bitmap", QEMU_CAPS_NBD_BITMAP }, }; typedef struct _virQEMUCapsObjectTypeProps virQEMUCapsObjectTypeProps; diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index 09bd6fbb63..63118523e6 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -424,7 +424,7 @@ qemuMigrationDstStartNBDServer(virQEMUDriverPtr driver, goto exit_monitor; } - if (qemuMonitorNBDServerAdd(priv->mon, diskAlias, true) < 0) + if (qemuMonitorNBDServerAdd(priv->mon, diskAlias, NULL, true, NULL= ) < 0) goto exit_monitor; if (qemuDomainObjExitMonitor(driver, vm) < 0) goto cleanup; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 694ed90622..9b4a5c01ab 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2342,6 +2342,17 @@ qemuMonitorBlockStatsUpdateCapacityBlockdev(qemuMoni= torPtr mon, return qemuMonitorJSONBlockStatsUpdateCapacityBlockdev(mon, stats); } +/* Updates "chk" to fill in size of the associated bitmap */ +int qemuMonitorUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk) +{ + VIR_DEBUG("chk=3D%p", chk); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONUpdateCheckpointSize(mon, chk); +} + int qemuMonitorBlockResize(qemuMonitorPtr mon, const char *device, @@ -3938,13 +3949,17 @@ qemuMonitorNBDServerStart(qemuMonitorPtr mon, int qemuMonitorNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable) + const char *export, + bool writable, + const char *bitmap) { - VIR_DEBUG("deviceID=3D%s", deviceID); + VIR_DEBUG("deviceID=3D%s, export=3D%s, bitmap=3D%s", deviceID, NULLSTR= (export), + NULLSTR(bitmap)); QEMU_CHECK_MONITOR(mon); - return qemuMonitorJSONNBDServerAdd(mon, deviceID, writable); + return qemuMonitorJSONNBDServerAdd(mon, deviceID, export, writable, + bitmap); } @@ -4471,3 +4486,47 @@ qemuMonitorGetPRManagerInfo(qemuMonitorPtr mon, virHashFree(info); return ret; } + +int +qemuMonitorAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent) +{ + VIR_DEBUG("node=3D%s bitmap=3D%s persistent=3D%d", node, bitmap, persi= stent); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONAddBitmap(mon, node, bitmap, persistent); +} + +int +qemuMonitorEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + VIR_DEBUG("node=3D%s bitmap=3D%s", node, bitmap); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONEnableBitmap(mon, node, bitmap); +} + +int +qemuMonitorMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src) +{ + VIR_DEBUG("node=3D%s dst=3D%s src=3D%p", node, dst, *src); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONMergeBitmaps(mon, node, dst, src); +} + +int +qemuMonitorDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + VIR_DEBUG("node=3D%s bitmap=3D%s", node, bitmap); + + QEMU_CHECK_MONITOR(mon); + + return qemuMonitorJSONDeleteBitmap(mon, node, bitmap); +} diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index fc2d193ae2..801433826f 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -1011,6 +1011,8 @@ qemuMonitorJSONHandleBlockJobImpl(qemuMonitorPtr mon, type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT; else if (STREQ(type_str, "mirror")) type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; + else if (STREQ(type_str, "backup")) + type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP; switch ((virConnectDomainEventBlockJobStatus) event) { case VIR_DOMAIN_BLOCK_JOB_COMPLETED: @@ -2755,6 +2757,82 @@ int qemuMonitorJSONBlockResize(qemuMonitorPtr mon, return ret; } +int qemuMonitorJSONUpdateCheckpointSize(qemuMonitorPtr mon, + virDomainCheckpointDefPtr chk) +{ + int ret =3D -1; + size_t i, j; + virJSONValuePtr devices; + + if (!(devices =3D qemuMonitorJSONQueryBlock(mon))) + return -1; + + for (i =3D 0; i < virJSONValueArraySize(devices); i++) { + virJSONValuePtr dev =3D virJSONValueArrayGet(devices, i); + virJSONValuePtr inserted; + virJSONValuePtr bitmaps =3D NULL; + const char *node; + virDomainCheckpointDiskDefPtr disk; + + if (!(dev =3D qemuMonitorJSONGetBlockDev(devices, i))) + goto cleanup; + + if (!(inserted =3D virJSONValueObjectGetObject(dev, "inserted"))) + continue; + if (!(node =3D virJSONValueObjectGetString(inserted, "node-name"))= ) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("query-block device entry was not in expected= format")); + goto cleanup; + } + + for (j =3D 0; j < chk->ndisks; j++) { + disk =3D &chk->disks[j]; + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + if (STREQ(chk->common.dom->disks[disk->idx]->src->nodeformat, = node)) + break; + } + if (j =3D=3D chk->ndisks) { + VIR_DEBUG("query-block did not find node %s", node); + continue; + } + if (!(bitmaps =3D virJSONValueObjectGetArray(dev, "dirty-bitmaps")= )) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("disk %s dirty bitmaps missing"), disk->name); + goto cleanup; + } + for (j =3D 0; j < virJSONValueArraySize(bitmaps); j++) { + virJSONValuePtr map =3D virJSONValueArrayGet(bitmaps, j); + const char *name; + + if (!(name =3D virJSONValueObjectGetString(map, "name"))) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("dirty bitmaps entry was not in expected form= at")); + goto cleanup; + } + if (STRNEQ(name, disk->bitmap)) + continue; + if (virJSONValueObjectGetNumberUlong(map, "count", &disk->size= ) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("invalid bitmap count")); + goto cleanup; + } + break; + } + if (j =3D=3D virJSONValueArraySize(bitmaps)) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("disk %s dirty bitmap info missing"), disk->n= ame); + goto cleanup; + } + } + + ret =3D 0; + + cleanup: + virJSONValueFree(devices); + return ret; +} + int qemuMonitorJSONSetPassword(qemuMonitorPtr mon, const char *protocol, @@ -4706,6 +4784,8 @@ qemuMonitorJSONParseBlockJobInfo(virHashTablePtr bloc= kJobs, info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COMMIT; else if (STREQ(type, "mirror")) info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_COPY; + else if (STREQ(type, "backup")) + info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP; else info->type =3D VIR_DOMAIN_BLOCK_JOB_TYPE_UNKNOWN; @@ -6746,15 +6826,20 @@ qemuMonitorJSONNBDServerStart(qemuMonitorPtr mon, int qemuMonitorJSONNBDServerAdd(qemuMonitorPtr mon, const char *deviceID, - bool writable) + const char *export, + bool writable, + const char *bitmap) { int ret =3D -1; virJSONValuePtr cmd; virJSONValuePtr reply =3D NULL; + /* Note: bitmap must be NULL if QEMU_CAPS_NBD_BITMAP is lacking */ if (!(cmd =3D qemuMonitorJSONMakeCommand("nbd-server-add", "s:device", deviceID, + "S:name", export, "b:writable", writable, + "S:bitmap", bitmap, NULL))) return ret; @@ -8470,3 +8555,115 @@ qemuMonitorJSONGetPRManagerInfo(qemuMonitorPtr mon, return ret; } + +int +qemuMonitorJSONAddBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap, bool persistent) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-add", + "s:node", node, + "s:name", bitmap, + "b:persistent", persistent, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONEnableBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-enable", + "s:node", node, + "s:name", bitmap, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONMergeBitmaps(qemuMonitorPtr mon, const char *node, + const char *dst, virJSONValuePtr *src) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-merge", + "s:node", node, + "s:target", dst, + "a:bitmaps", src, + NULL))) + goto cleanup; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(*src); + *src =3D NULL; + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} + +int +qemuMonitorJSONDeleteBitmap(qemuMonitorPtr mon, const char *node, + const char *bitmap) +{ + int ret =3D -1; + virJSONValuePtr cmd; + virJSONValuePtr reply =3D NULL; + + if (!(cmd =3D qemuMonitorJSONMakeCommand("block-dirty-bitmap-remove", + "s:node", node, + "s:name", bitmap, + NULL))) + return -1; + + if (qemuMonitorJSONCommand(mon, cmd, &reply) < 0) + goto cleanup; + + if (qemuMonitorJSONCheckError(cmd, reply) < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virJSONValueFree(cmd); + virJSONValueFree(reply); + return ret; +} diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv32.xml index d6fc996528..58bfd739b7 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv32.xml @@ -163,6 +163,8 @@ + + 3001091 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml b/tests/qemu= capabilitiesdata/caps_4.0.0.riscv64.xml index fcc34b0ae6..0abf507447 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.riscv64.xml @@ -163,6 +163,8 @@ + + 3001091 0 0 diff --git a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml b/tests/qemuc= apabilitiesdata/caps_4.0.0.x86_64.xml index bc8e35e226..b3f2b5919e 100644 --- a/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml +++ b/tests/qemucapabilitiesdata/caps_4.0.0.x86_64.xml @@ -201,6 +201,8 @@ + + 3001050 0 43100758 diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c index dd3259494a..23f4292d97 100644 --- a/tests/qemumonitorjsontest.c +++ b/tests/qemumonitorjsontest.c @@ -1350,7 +1350,7 @@ GEN_TEST_FUNC(qemuMonitorJSONBlockCommit, "vdb", "/fo= o/bar1", "/foo/bar2", "back GEN_TEST_FUNC(qemuMonitorJSONDrivePivot, "vdb") GEN_TEST_FUNC(qemuMonitorJSONScreendump, "devicename", 1, "/foo/bar") GEN_TEST_FUNC(qemuMonitorJSONOpenGraphics, "spice", "spicefd", false) -GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", true) +GEN_TEST_FUNC(qemuMonitorJSONNBDServerAdd, "vda", NULL, true, NULL) GEN_TEST_FUNC(qemuMonitorJSONDetachCharDev, "serial1") GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayOpen, "foodev", true) GEN_TEST_FUNC(qemuMonitorJSONBlockdevTrayClose, "foodev") --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510228; cv=none; d=zoho.com; s=zohoarc; b=HuJI372aa2+pbILAUbxfsVnT6prOaKYoSJ1dbVUQFcYZvT/i9jSosSsVgsDERbupNqAf+oW3SSsnrqkwdsO9vxnqB23JtvWEm9aDk25yhAbfPBvtX0amMbBoqQkJzLLBl2gS2z+pBF+m8cfBKGYqGeTcRTCzLOMrbvjSNHp7hag= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510228; 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=02wkvmJ7vKkuAf/XKc5gE4HBNVPkIFQgazkb0gIBBx4=; b=YUtCTqfLFHTZfKKw8vafhmFjm3mWhSx2ZY8fhX6x/6LZ2ys5R2tf/dAyfUZc+OQbKiT9TOrtbfIPoMS7H4c92WPLWSL24+I2Ee4sj3HxhhLQzPlThwj2WV45aok8FU9rjYpNUUmyEDP6T+vYPkwG07r68PHuhX6nWGSaapaf0Q4= 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 1555510228679148.46931967603018; Wed, 17 Apr 2019 07:10:28 -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 140D8308620A; Wed, 17 Apr 2019 14:10:27 +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 E12C4608C6; Wed, 17 Apr 2019 14:10:26 +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 9EF7C181B9EE; Wed, 17 Apr 2019 14:10:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9hd0023820 for ; Wed, 17 Apr 2019 10:09:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 95DE660156; Wed, 17 Apr 2019 14:09:43 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id C88F260143; Wed, 17 Apr 2019 14:09:40 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:16 -0500 Message-Id: <20190417140921.11964-17-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 16/21] 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.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.42]); Wed, 17 Apr 2019 14:10:27 +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_block.h | 3 + src/qemu/qemu_conf.h | 2 + src/qemu/qemu_domain.h | 15 + src/qemu/qemu_block.c | 12 + src/qemu/qemu_conf.c | 5 + src/qemu/qemu_domain.c | 133 +++++++ src/qemu/qemu_driver.c | 843 +++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1013 insertions(+) diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h index eab8da8e2c..b280c5d369 100644 --- a/src/qemu/qemu_block.h +++ b/src/qemu/qemu_block.h @@ -128,4 +128,7 @@ qemuBlockSnapshotAddLegacy(virJSONValuePtr actions, virStorageSourcePtr newsrc, bool reuse); +const char * +qemuBlockNodeLookup(virDomainObjPtr vm, const char *disk); + #endif /* LIBVIRT_QEMU_BLOCK_H */ diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h index 983e74a3cf..1029a042f5 100644 --- a/src/qemu/qemu_conf.h +++ b/src/qemu/qemu_conf.h @@ -29,6 +29,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" @@ -110,6 +111,7 @@ struct _virQEMUDriverConfig { char *cacheDir; char *saveDir; char *snapshotDir; + char *checkpointDir; char *channelTargetDir; char *nvramDir; char *swtpmStorageDir; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index 06640a9510..ac7ca1badc 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -724,6 +724,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_block.c b/src/qemu/qemu_block.c index 7d9f7ec3ab..b496b08afa 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -1647,3 +1647,15 @@ qemuBlockStorageGetCopyOnReadProps(virDomainDiskDefP= tr disk) return ret; } + +const char * +qemuBlockNodeLookup(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; +} diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index daea11dacb..1312e753db 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -179,6 +179,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, @@ -242,6 +244,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, @@ -354,6 +358,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_domain.c b/src/qemu/qemu_domain.c index db67fe2193..739074e17d 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 @@ -8479,6 +8480,40 @@ 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 | + VIR_DOMAIN_CHECKPOINT_FORMAT_INTERNAL; + virDomainCheckpointDefPtr def =3D virDomainCheckpointObjGetDef(checkpo= int); + VIR_AUTOFREE(char *) newxml =3D NULL; + VIR_AUTOFREE(char *) chkDir =3D NULL; + VIR_AUTOFREE(char *) chkFile =3D NULL; + + if (virDomainCheckpointGetCurrent(vm->checkpoints) =3D=3D checkpoint) + flags |=3D VIR_DOMAIN_CHECKPOINT_FORMAT_CURRENT; + 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->common.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 @@ -8674,12 +8709,99 @@ qemuDomainSnapshotDiscardAllMetadata(virQEMUDriverP= tr 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) { + parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + if (!parentchk) { + VIR_WARN("missing parent checkpoint matching name '%s'", + chk->def->parent); + } 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); + 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; + + rem.driver =3D driver; + rem.vm =3D vm; + rem.metadata_only =3D true; + rem.err =3D 0; + 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); @@ -8694,6 +8816,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->snapshotDir, 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 c443c881d5..144cb51d89 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 +qemuCheckObjFromName(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 +qemuCheckObjFromCheckpoint(virDomainObjPtr vm, + virDomainCheckpointPtr checkpoint) +{ + return qemuCheckObjFromName(vm, checkpoint->name); +} + static int qemuAutostartDomain(virDomainObjPtr vm, void *opaque) @@ -525,6 +560,124 @@ 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; + bool cur; + unsigned int flags =3D (VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_PARSE_INTERNAL); + 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, &cur, + 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); + continue; + } + + chk =3D virDomainCheckpointAssignDef(vm->checkpoints, def); + if (chk =3D=3D NULL) { + virDomainCheckpointDefFree(def); + } else if (cur) { + if (current) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Too many snapshots claiming to be curren= t for domain %s"), + vm->def->name); + current =3D chk; + } + + VIR_FREE(fullpath); + VIR_FREE(xmlStr); + } + if (direrr < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Failed to fully read directory %s"), + chkDir); + + virDomainCheckpointSetCurrent(vm->checkpoints, current); + + if (virDomainCheckpointUpdateRelations(vm->checkpoints) < 0) + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Checkpoints have inconsistent relations for doma= in %s"), + vm->def->name); + + /* FIXME: qemu keeps internal track of bitmaps, which form the + * basis for checkpoints; it would be nice if we could update our + * internal state to reflect that information automatically. But + * qemu 3.0 did not have access to this via qemu-img for offline + * images (you have to use QMP commands on a running guest), and + * it also does not track relations which we find + * important in our metadata. + */ + + 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) @@ -653,6 +806,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); @@ -760,6 +918,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"), @@ -893,6 +1058,10 @@ qemuStateInitialize(bool privileged, qemuDomainSnapshotLoad, cfg->snapshotDir); + virDomainObjListForEach(qemu_driver->domains, + qemuDomainCheckpointLoad, + cfg->checkpointDir); + virDomainObjListForEach(qemu_driver->domains, qemuDomainManagedSaveLoad, qemu_driver); @@ -7760,6 +7929,7 @@ qemuDomainUndefineFlags(virDomainPtr dom, if (qemuDomainSnapshotDiscardAllMetadata(driver, vm) < 0) goto endjob; } + /* TODO: Restrict deletion if checkpoints exist? */ name =3D qemuDomainManagedSavePath(driver, vm); if (name =3D=3D NULL) @@ -16793,6 +16963,651 @@ qemuDomainSnapshotDelete(virDomainSnapshotPtr sna= pshot, return ret; } + +/* Called prior to job lock */ +static virDomainCheckpointDefPtr +qemuDomainCheckpointDefParseString(virQEMUDriverPtr driver, virCapsPtr cap= s, + const char *xmlDesc, unsigned int flags) +{ + virDomainCheckpointDefPtr def =3D NULL; + virDomainCheckpointDefPtr ret =3D NULL; + unsigned int parse_flags =3D 0; + + if (flags & VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE) + parse_flags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + if (!(def =3D virDomainCheckpointDefParseString(xmlDesc, caps, driver-= >xmlopt, + NULL, parse_flags))) + goto cleanup; + + /* reject checkpoint names containing slashes or starting with dot as + * checkpoint definitions are saved in files named by the checkpoint n= ame */ + if (!(flags & VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA)) { + if (strchr(def->common.name, '/')) { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid checkpoint name '%s': " + "name can't contain '/'"), + def->common.name); + goto cleanup; + } + + if (def->common.name[0] =3D=3D '.') { + virReportError(VIR_ERR_XML_DETAIL, + _("invalid checkpoint name '%s': " + "name can't start with '.'"), + def->common.name); + goto cleanup; + } + } + + VIR_STEAL_PTR(ret, def); + + cleanup: + virDomainCheckpointDefFree(def); + 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->common.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 || + qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 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 > 0 && + 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; + virDomainCheckpointDefPtr def =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; + virDomainMomentObjPtr other =3D NULL; + virQEMUDriverConfigPtr cfg =3D NULL; + virCapsPtr caps =3D NULL; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | + VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT | + VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA, NULL); + /* TODO: VIR_DOMAIN_CHECKPOINT_CREATE_QUIESCE */ + + if (redefine) + parse_flags |=3D VIR_DOMAIN_CHECKPOINT_PARSE_REDEFINE; + if ((redefine && !(flags & VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT)) || + (flags & VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA)) + update_current =3D false; + + if (!(vm =3D qemuDomObjFromDomain(domain))) + 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 qemuDomainCheckpointDefParseString(driver, caps, xmlDesc, + parse_flags))) + goto cleanup; + + /* 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; + } + + current =3D virDomainCheckpointGetCurrent(vm->checkpoints); + if (current) { + if (!redefine && + VIR_STRDUP(chk->def->parent, current->def->name) < 0) + goto endjob; + if (update_current) { + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); + if (qemuDomainCheckpointWriteMetadata(vm, current, + 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 && !(flags & VIR_DOMAIN_CHECKPOINT_CREATE_NO_METADATA))= { + 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 { + other =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + virDomainMomentSetParent(chk, other); + } + } else if (chk) { + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + } + + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + virDomainCheckpointDefFree(def); + 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 qemuCheckObjFromCheckpoint(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 qemuCheckObjFromName(vm, name))) + goto cleanup; + + checkpoint =3D virGetDomainCheckpoint(domain, chk->def->name); + + cleanup: + virDomainObjEndAPI(&vm); + return checkpoint; +} + + +static int +qemuDomainHasCurrentCheckpoint(virDomainPtr domain, + unsigned int flags) +{ + virDomainObjPtr vm; + int ret =3D -1; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return -1; + + if (virDomainHasCurrentCheckpointEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + ret =3D (virDomainCheckpointGetCurrent(vm->checkpoints) !=3D NULL); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +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 qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + if (!chk->def->parent) { + 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= ); + + cleanup: + virDomainObjEndAPI(&vm); + return parent; +} + + +static virDomainCheckpointPtr +qemuDomainCheckpointCurrent(virDomainPtr domain, + unsigned int flags) +{ + virDomainObjPtr vm; + virDomainCheckpointPtr checkpoint =3D NULL; + const char *name; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return NULL; + + if (virDomainCheckpointCurrentEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + name =3D virDomainCheckpointGetCurrentName(vm->checkpoints); + if (!name) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, "%s", + _("the domain does not have a current checkpoint")); + goto cleanup; + } + + checkpoint =3D virGetDomainCheckpoint(domain, name); + + cleanup: + virDomainObjEndAPI(&vm); + return checkpoint; +} + + +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; + qemuDomainObjPrivatePtr priv; + int rc; + size_t i; + virDomainCheckpointDefPtr chkdef; + + virCheckFlags(VIR_DOMAIN_CHECKPOINT_XML_SECURE | + VIR_DOMAIN_CHECKPOINT_XML_NO_DOMAIN | + VIR_DOMAIN_CHECKPOINT_XML_SIZE, NULL); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return NULL; + + if (virDomainCheckpointGetXMLDescEnsureACL(checkpoint->domain->conn, v= m->def, flags) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + chkdef =3D virDomainCheckpointObjGetDef(chk); + + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) { + /* TODO: for non-current checkpoint, this requires a QMP sequence = per + disk, since the stat of one bitmap in isolation is too low, + and merely adding bitmap sizes may be too high: + block-dirty-bitmap-create tmp + for each bitmap from checkpoint to current: + add bitmap to src_list + block-dirty-bitmap-merge dst=3Dtmp src_list + query-block and read tmp size + block-dirty-bitmap-remove tmp + So for now, go with simpler query-blocks only for current. + */ + if (virDomainCheckpointGetCurrent(vm->checkpoints) !=3D chk) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("cannot compute size for non-current checkpoi= nt '%s'"), + checkpoint->name); + goto cleanup; + } + + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto endjob; + + if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto endjob; + + /* TODO: Shouldn't need to recompute node names. */ + for (i =3D 0; i < chkdef->ndisks; i++) { + virDomainCheckpointDiskDef *disk =3D &chkdef->disks[i]; + + if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) + continue; + VIR_FREE(chk->def->dom->disks[disk->idx]->src->nodeformat); + if (VIR_STRDUP(chk->def->dom->disks[disk->idx]->src->nodeforma= t, + qemuBlockNodeLookup(vm, disk->name)) < 0) + goto endjob; + } + + priv =3D vm->privateData; + qemuDomainObjEnterMonitor(driver, vm); + rc =3D qemuMonitorUpdateCheckpointSize(priv->mon, chkdef); + if (qemuDomainObjExitMonitor(driver, vm) < 0) + goto endjob; + if (rc < 0) + goto endjob; + } + + xml =3D virDomainCheckpointDefFormat(chkdef, driver->caps, driver->xml= opt, + flags); + + endjob: + if (flags & VIR_DOMAIN_CHECKPOINT_XML_SIZE) + qemuDomainObjEndJob(driver, vm); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + + +static int +qemuDomainCheckpointIsCurrent(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainMomentObjPtr chk =3D NULL; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + if (virDomainCheckpointIsCurrentEnsureACL(checkpoint->domain->conn, vm= ->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + ret =3D chk =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints); + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +static int +qemuDomainCheckpointHasMetadata(virDomainCheckpointPtr checkpoint, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainMomentObjPtr chk =3D NULL; + + virCheckFlags(0, -1); + + if (!(vm =3D qemuDomObjFromCheckpoint(checkpoint))) + return -1; + + if (virDomainCheckpointHasMetadataEnsureACL(checkpoint->domain->conn, = vm->def) < 0) + goto cleanup; + + if (!(chk =3D qemuCheckObjFromCheckpoint(vm, checkpoint))) + goto cleanup; + + /* XXX Someday, we should recognize internal bitmaps in qcow2 + * images that are not tied to a libvirt checkpoint; if we ever do + * that, then we would have a reason to return 0 here. */ + ret =3D 1; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + + +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 qemuCheckObjFromCheckpoint(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) { @@ -16903,6 +17718,16 @@ static virDomainPtr qemuDomainQemuAttach(virConnec= tPtr conn, goto cleanup; } + if (qemuProcessAttach(conn, driver, vm, pid, + pidfile, monConfig, monJSON) < 0) { + monConfig =3D NULL; + qemuDomainRemoveInactive(driver, vm); + qemuDomainObjEndJob(driver, vm); + goto cleanup; + } + + monConfig =3D NULL; + if (qemuProcessAttach(conn, driver, vm, pid, pidfile, monConfig, monJSON) < 0) { qemuDomainRemoveInactive(driver, vm); @@ -21685,6 +22510,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; @@ -22505,6 +23336,18 @@ 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.3.0= */ + .domainCheckpointGetXMLDesc =3D qemuDomainCheckpointGetXMLDesc, /* 5.3= .0 */ + + .domainListAllCheckpoints =3D qemuDomainListAllCheckpoints, /* 5.3.0 */ + .domainCheckpointListAllChildren =3D qemuDomainCheckpointListAllChildr= en, /* 5.3.0 */ + .domainCheckpointLookupByName =3D qemuDomainCheckpointLookupByName, /*= 5.3.0 */ + .domainHasCurrentCheckpoint =3D qemuDomainHasCurrentCheckpoint, /* 5.3= .0 */ + .domainCheckpointGetParent =3D qemuDomainCheckpointGetParent, /* 5.3.0= */ + .domainCheckpointCurrent =3D qemuDomainCheckpointCurrent, /* 5.3.0 */ + .domainCheckpointIsCurrent =3D qemuDomainCheckpointIsCurrent, /* 5.3.0= */ + .domainCheckpointHasMetadata =3D qemuDomainCheckpointHasMetadata, /* 5= .3.0 */ + .domainCheckpointDelete =3D qemuDomainCheckpointDelete, /* 5.3.0 */ }; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510248; cv=none; d=zoho.com; s=zohoarc; b=L2VGaTHycHvas2Ioh29m153YNeSMNdtY826mUxpLlGn2aHDZBSAPI9kZIA+ml1ttxSNskYB4qnVHP3iEQ4oRDjeezm+iqd3Twp9qFpKyrC6g0KD3hr4hzG5irLjcDdgUJmgwQZRVQ12k5JBp90OiihWAhOYE7trked9Pvf2xfH0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510248; 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=gH2HleuOQQU+zwEtZdaNP2qbUyAM+c6N6voPIEK+w7k=; b=TROf+B230SRqfxEZB5Xi9pUkGf1dIwL+WqTfPk3BxbFtFyqSVpd/IqunXawhGulWUoT9jX0fCL8lVraDpJ7A+p2Osz8jVgK+m6SllznVDj25QuVrq87XJdK7EqkXk8+9s/Z106rjTA1u6slVkRxBP8/qHbdtReOedbDOmtNhbVM= 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 1555510248131107.10953760669656; Wed, 17 Apr 2019 07:10:48 -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 84FBC37E85; Wed, 17 Apr 2019 14:10:46 +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 545B81001E7C; Wed, 17 Apr 2019 14:10:46 +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 14099181B9E2; Wed, 17 Apr 2019 14:10:46 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9ioW023830 for ; Wed, 17 Apr 2019 10:09:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id 534B360156; Wed, 17 Apr 2019 14:09:44 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id B8C0460148; Wed, 17 Apr 2019 14:09:43 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:17 -0500 Message-Id: <20190417140921.11964-18-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 17/21] 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.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, 17 Apr 2019 14:10:47 +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 parent checkpoint (if any). For deletion, we need multiple calls: if the checkpoint to be deleted is active, we must enable the parent; then we must merge the existing checkpoint into the parent, and finally we can delete the checkpoint. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.c | 105 ++++++++++++++++++++++++++++++----------- src/qemu/qemu_driver.c | 92 ++++++++++++++++++++++++++++++++++-- 2 files changed, 165 insertions(+), 32 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 739074e17d..16dec68302 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8720,45 +8720,93 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, char *chkFile =3D NULL; int ret =3D -1; virDomainMomentObjPtr parentchk =3D NULL; + virDomainCheckpointDefPtr parentdef =3D NULL; virQEMUDriverConfigPtr cfg =3D virQEMUDriverGetConfig(driver); + size_t i, j; + virJSONValuePtr arr =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")); + goto cleanup; } if (virAsprintf(&chkFile, "%s/%s/%s.xml", cfg->checkpointDir, vm->def->name, chk->def->name) < 0) goto cleanup; + if (chk->def->parent) { + parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + if (!parentchk) { + VIR_WARN("missing parent checkpoint matching name '%s'", + chk->def->parent); + } + parentdef =3D virDomainCheckpointObjGetDef(parentchk); + } + + if (!metadata_only) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; + bool success =3D true; + virDomainCheckpointDefPtr chkdef =3D virDomainCheckpointObjGetDef(= chk); + + if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + qemuDomainObjEnterMonitor(driver, vm); + 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 qemuBlockNodeLookup(vm, disk->name); + if (parentchk) { + arr =3D virJSONValueNewArray(); + if (!arr || + virJSONValueArrayAppendString(arr, disk->bitmap) < 0) { + success =3D false; + break; + } + + for (j =3D 0; j < parentdef->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + + disk2 =3D &parentdef->disks[j]; + if (STRNEQ(disk->name, disk2->name)) + continue; + 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) + goto cleanup; + } + if (chk =3D=3D virDomainCheckpointGetCurrent(vm->checkpoints)) { virDomainCheckpointSetCurrent(vm->checkpoints, NULL); - if (update_parent && chk->def->parent) { - parentchk =3D virDomainCheckpointFindByName(vm->checkpoints, - chk->def->parent); - if (!parentchk) { - VIR_WARN("missing parent checkpoint matching name '%s'", + if (update_parent && parentchk) { + virDomainCheckpointSetCurrent(vm->checkpoints, parentchk); + if (qemuDomainCheckpointWriteMetadata(vm, parentchk, driver->c= aps, + driver->xmlopt, + cfg->checkpointDir) < 0)= { + VIR_WARN("failed to set parent checkpoint '%s' as current", chk->def->parent); - } 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); - virDomainCheckpointSetCurrent(vm->checkpoints, NULL); - } + virDomainCheckpointSetCurrent(vm->checkpoints, NULL); } } } @@ -8774,6 +8822,7 @@ qemuDomainCheckpointDiscard(virQEMUDriverPtr driver, cleanup: VIR_FREE(chkFile); virObjectUnref(cfg); + virJSONValueFree(arr); return ret; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 144cb51d89..86310b6e92 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -48,6 +48,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" @@ -17056,6 +17057,53 @@ qemuDomainCheckpointPrepare(virQEMUDriverPtr drive= r, virCapsPtr caps, return ret; } +static int +qemuDomainCheckpointAddActions(virDomainObjPtr vm, + virJSONValuePtr actions, + virDomainMomentObjPtr old_current, + virDomainCheckpointDefPtr def) +{ + size_t i, j; + int ret =3D -1; + virDomainCheckpointDefPtr olddef; + + olddef =3D virDomainCheckpointObjGetDef(old_current); + 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 qemuBlockNodeLookup(vm, disk->name); + if (qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-add", + "s:node", node, + "s:name", disk->bitmap, + "b:persistent", true, + NULL) < 0) + goto cleanup; + if (old_current) { + for (j =3D 0; j < olddef->ndisks; j++) { + virDomainCheckpointDiskDef *disk2; + + disk2 =3D &olddef->disks[j]; + if (STRNEQ(disk->name, disk2->name)) + continue; + if (disk2->type =3D=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP && + qemuMonitorJSONTransactionAdd(actions, + "block-dirty-bitmap-disa= ble", + "s:node", node, + "s:name", disk2->bitmap, + NULL) < 0) + goto cleanup; + } + } + } + ret =3D 0; + + cleanup: + return ret; +} static virDomainCheckpointPtr qemuDomainCheckpointCreateXML(virDomainPtr domain, @@ -17075,6 +17123,9 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, virDomainMomentObjPtr other =3D NULL; virQEMUDriverConfigPtr cfg =3D NULL; virCapsPtr caps =3D NULL; + qemuDomainObjPrivatePtr priv; + virJSONValuePtr actions =3D NULL; + int ret; virCheckFlags(VIR_DOMAIN_CHECKPOINT_CREATE_REDEFINE | VIR_DOMAIN_CHECKPOINT_CREATE_CURRENT | @@ -17090,11 +17141,18 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, if (!(vm =3D qemuDomObjFromDomain(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; @@ -17134,10 +17192,10 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, def =3D NULL; } - current =3D virDomainCheckpointGetCurrent(vm->checkpoints); - if (current) { + other =3D virDomainCheckpointGetCurrent(vm->checkpoints); + if (other) { if (!redefine && - VIR_STRDUP(chk->def->parent, current->def->name) < 0) + VIR_STRDUP(chk->def->parent, other->def->name) < 0) goto endjob; if (update_current) { virDomainCheckpointSetCurrent(vm->checkpoints, NULL); @@ -17154,7 +17212,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; @@ -17190,6 +17256,7 @@ qemuDomainCheckpointCreateXML(virDomainPtr domain, qemuDomainObjEndJob(driver, vm); cleanup: + virJSONValueFree(actions); virDomainObjEndAPI(&vm); virDomainCheckpointDefFree(def); VIR_FREE(xml); @@ -17525,6 +17592,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; @@ -17547,6 +17615,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 qemuCheckObjFromCheckpoint(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 Sat Apr 27 19:55:39 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=1555510241; cv=none; d=zoho.com; s=zohoarc; b=hTcXbfTYwHw1UWc9It3/PLz/gQ4EVXoJ8YbaDCtsyg8imj5RlUyoB+v3rOBfXUshMtibUlmgLkZSLsQmn2B2D4VKT2n9QFyWySO2xVwZrh6cB3S5iMBvT3knIvUP7QmN+28qpAICt4l3AgcAuAt4kCXnVHY2oFo1aXUCxiSd7qE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510241; 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=LKnOKTgXcVbgFT0FzBin2t1DhUepxnbwl+TX/2F1Pvw=; b=D5mhXX2rr4dA+zhifeUXC19lyWK1N1YCq96k2uGIZMphsuELo6Rt2DmuVqhWGkJMa6/j8QVcppMzjen6Cq/LBdaGQFoJbDJmJ6EZ9QCE9cfBH0YsiK5pB33ofU7eT2/4unHJvuhBrSxsHSR38PGTbVaPY26u5GdEQMZDlP4/KM4= 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 1555510241577793.3070070015443; Wed, 17 Apr 2019 07:10:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0440E307CB41; Wed, 17 Apr 2019 14:10: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 CE8CA5DA2D; Wed, 17 Apr 2019 14:10: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 8955A3F5CC; Wed, 17 Apr 2019 14:10:34 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9j8c023840 for ; Wed, 17 Apr 2019 10:09:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EC3660150; Wed, 17 Apr 2019 14:09:45 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 75A9860143; Wed, 17 Apr 2019 14:09:44 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:18 -0500 Message-Id: <20190417140921.11964-19-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 18/21] backup: qemu: Implement framework for backup job 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 17 Apr 2019 14:10:35 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Still needs to actually kick off the right QMP commands, but at least allows validation of backup XML, including the fact that a backup job can survive a libvirtd restart. Atomically creating a checkpoint alongside the backup still needs implementing. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.h | 4 + src/qemu/qemu_domain.c | 29 ++++++- src/qemu/qemu_driver.c | 185 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 214 insertions(+), 4 deletions(-) diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index ac7ca1badc..5315939952 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -381,6 +381,10 @@ struct _qemuDomainObjPrivate { /* true if global -mem-prealloc appears on cmd line */ bool memPrealloc; + + /* Any currently running backup job. + * FIXME: allow jobs in parallel. For now, at most one job, always id = 1. */ + virDomainBackupDefPtr backup; }; # define QEMU_DOMAIN_PRIVATE(vm) \ diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 16dec68302..f4be948bae 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -57,6 +57,7 @@ #include "locking/domain_lock.h" #include "virdomainsnapshotobjlist.h" #include "virdomaincheckpointobjlist.h" +#include "backup_conf.h" #ifdef MAJOR_IN_MKDEV # include @@ -2317,13 +2318,25 @@ static int qemuDomainObjPrivateXMLFormatBlockjobs(virBufferPtr buf, virDomainObjPtr vm) { + qemuDomainObjPrivatePtr priv =3D vm->privateData; virBuffer attrBuf =3D VIR_BUFFER_INITIALIZER; bool bj =3D qemuDomainHasBlockjob(vm, false); + int ret =3D -1; virBufferAsprintf(&attrBuf, " active=3D'%s'", virTristateBoolTypeToString(virTristateBoolFromBool(= bj))); - return virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL); + if (virXMLFormatElement(buf, "blockjobs", &attrBuf, NULL) < 0) + goto cleanup; + + /* TODO: merge other blockjobs and backups into uniform space? */ + if (priv->backup && virDomainBackupDefFormat(buf, priv->backup, true) = < 0) + goto cleanup; + + ret =3D 0; + cleanup: + virBufferFreeAndReset(&attrBuf); + return ret; } @@ -2665,16 +2678,24 @@ qemuDomainObjPrivateXMLParseAutomaticPlacement(xmlX= PathContextPtr ctxt, static int -qemuDomainObjPrivateXMLParseBlockjobs(qemuDomainObjPrivatePtr priv, +qemuDomainObjPrivateXMLParseBlockjobs(virQEMUDriverPtr driver, + qemuDomainObjPrivatePtr priv, xmlXPathContextPtr ctxt) { - VIR_AUTOFREE(char *) active =3D NULL; + xmlNodePtr node; int tmp; + VIR_AUTOFREE(char *) active =3D NULL; if ((active =3D virXPathString("string(./blockjobs/@active)", ctxt)) && (tmp =3D virTristateBoolTypeFromString(active)) > 0) priv->reconnectBlockjobs =3D tmp; + if ((node =3D virXPathNode("./domainbackup", ctxt)) && + !(priv->backup =3D virDomainBackupDefParseNode(ctxt->doc, node, + driver->xmlopt, + VIR_DOMAIN_BACKUP_PAR= SE_INTERNAL))) + return -1; + return 0; } @@ -3035,7 +3056,7 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt, qemuDomainObjPrivateXMLParsePR(ctxt, &priv->prDaemonRunning); - if (qemuDomainObjPrivateXMLParseBlockjobs(priv, ctxt) < 0) + if (qemuDomainObjPrivateXMLParseBlockjobs(driver, priv, ctxt) < 0) goto error; qemuDomainStorageIdReset(priv); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 86310b6e92..cca0b550b8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -105,6 +105,7 @@ #include "virdomainsnapshotobjlist.h" #include "virenum.h" #include "virdomaincheckpointobjlist.h" +#include "backup_conf.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -17692,6 +17693,187 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr= checkpoint, return ret; } +static int qemuDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int f= lags) +{ + virQEMUDriverPtr driver =3D domain->conn->privateData; + virDomainObjPtr vm =3D NULL; + virDomainBackupDefPtr def =3D NULL; + virQEMUDriverConfigPtr cfg =3D NULL; + virCapsPtr caps =3D NULL; + qemuDomainObjPrivatePtr priv; + int ret =3D -1; + struct timeval tv; + char *suffix =3D NULL; + + virCheckFlags(VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA, -1); + /* TODO: VIR_DOMAIN_BACKUP_BEGIN_QUIESCE */ + + // FIXME: Support non-null checkpointXML for incremental - what + // code can be shared with CheckpointCreateXML, then add to transaction + // to create new checkpoint at same time as starting blockdev-backup + if (checkpointXml) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create incremental backups yet")); + return -1; + } + // if (chk) VIR_STRDUP(suffix, chk->name); + gettimeofday(&tv, NULL); + if (virAsprintf(&suffix, "%lld", (long long)tv.tv_sec) < 0) + goto cleanup; + + if (!(vm =3D qemuDomObjFromDomain(domain))) + goto cleanup; + + cfg =3D virQEMUDriverGetConfig(driver); + + if (virDomainBackupBeginEnsureACL(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 perform disk backup for inactive domain")= ); + goto cleanup; + } + if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) + goto cleanup; + + /* We are going to modify the domain below. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + priv =3D vm->privateData; + if (priv->backup) { + virReportError(VIR_ERR_OPERATION_INVALID, + "%s", _("another backup job is already running")); + goto endjob; + } + + if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0) + goto endjob; + + /* actually start the checkpoint. 2x2 array of push/pull, full/incr, + plus additional tweak if checkpoint requested */ + /* TODO: issue QMP commands: + - pull: nbd-server-start with from user (or autogenerate s= erver) + - push/pull: blockdev-add per + - incr: bitmap-add of tmp, bitmap-merge per + - transaction, containing: + - push+full: blockdev-backup sync:full + - push+incr: blockdev-backup sync:incremental bitmap:tmp + - pull+full: blockdev-backup sync:none + - pull+incr: blockdev-backup sync:none, bitmap-disable of tmp + - if checkpoint: bitmap-disable of old, bitmap-add of new + - pull: nbd-server-add per , including bitmap for incr + */ + + VIR_STEAL_PTR(priv->backup, def); + ret =3D priv->backup->id =3D 1; /* Hard-coded job id for now */ + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, + driver->caps) < 0) + VIR_WARN("Unable to save status on vm %s after backup job", + vm->def->name); + + endjob: + qemuDomainObjEndJob(driver, vm); + + cleanup: + VIR_FREE(suffix); + virDomainObjEndAPI(&vm); + virDomainBackupDefFree(def); + virObjectUnref(caps); + virObjectUnref(cfg); + return ret; +} + +static char *qemuDomainBackupGetXMLDesc(virDomainPtr domain, int id, + unsigned int flags) +{ + virDomainObjPtr vm =3D NULL; + char *xml =3D NULL; + qemuDomainObjPrivatePtr priv; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + virCheckFlags(0, NULL); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return NULL; + + if (virDomainBackupGetXMLDescEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + /* TODO: Allow more than one hard-coded job id */ + priv =3D vm->privateData; + if ((id !=3D 0 && id !=3D 1) || !priv->backup) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain backup job with id '%d'"), id); + goto cleanup; + } + + if (virDomainBackupDefFormat(&buf, priv->backup, false) < 0) + goto cleanup; + xml =3D virBufferContentAndReset(&buf); + + cleanup: + virDomainObjEndAPI(&vm); + return xml; +} + +static int qemuDomainBackupEnd(virDomainPtr domain, int id, unsigned int f= lags) +{ + virQEMUDriverPtr driver =3D domain->conn->privateData; + virQEMUDriverConfigPtr cfg =3D NULL; + virDomainObjPtr vm =3D NULL; + int ret =3D -1; + virDomainBackupDefPtr backup =3D NULL; + qemuDomainObjPrivatePtr priv; + bool want_abort =3D flags & VIR_DOMAIN_BACKUP_END_ABORT; + + virCheckFlags(VIR_DOMAIN_BACKUP_END_ABORT, -1); + + if (!(vm =3D qemuDomObjFromDomain(domain))) + return -1; + + cfg =3D virQEMUDriverGetConfig(driver); + if (virDomainBackupEndEnsureACL(domain->conn, vm->def) < 0) + goto cleanup; + + /* TODO: Allow more than one hard-coded job id */ + priv =3D vm->privateData; + if ((id !=3D 0 && id !=3D 1) || !priv->backup) { + virReportError(VIR_ERR_NO_DOMAIN_CHECKPOINT, + _("no domain backup job with id '%d'"), id); + goto cleanup; + } + + if (priv->backup->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) + want_abort =3D false; + + /* TODO: QMP commands to actually cancel the pending job, and on + * pull, also tear down the NBD server */ + VIR_STEAL_PTR(backup, priv->backup); + if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, + driver->caps) < 0) + VIR_WARN("Unable to save status on vm %s after backup job", + vm->def->name); + + ret =3D want_abort ? 0 : 1; + + cleanup: + virDomainBackupDefFree(backup); + virDomainObjEndAPI(&vm); + return ret; +} + static int qemuDomainQemuMonitorCommand(virDomainPtr domain, const char *c= md, char **result, unsigned int flags) { @@ -23432,6 +23614,9 @@ static virHypervisorDriver qemuHypervisorDriver =3D= { .domainCheckpointIsCurrent =3D qemuDomainCheckpointIsCurrent, /* 5.3.0= */ .domainCheckpointHasMetadata =3D qemuDomainCheckpointHasMetadata, /* 5= .3.0 */ .domainCheckpointDelete =3D qemuDomainCheckpointDelete, /* 5.3.0 */ + .domainBackupBegin =3D qemuDomainBackupBegin, /* 5.3.0 */ + .domainBackupGetXMLDesc =3D qemuDomainBackupGetXMLDesc, /* 5.3.0 */ + .domainBackupEnd =3D qemuDomainBackupEnd, /* 5.3.0 */ }; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510238; cv=none; d=zoho.com; s=zohoarc; b=K/aiiJ9wYVLgU4Ccc1nmLjNYiJbggy2op5RmgQqWaOz3lzYBxUBOxc6QD+vALXxOfV3x0/IqcM2oJ83bA6LwH/YYV+6fX0NxAdfaJdS2mlZ/9YzjiKHn4MT8ypnHQ3muUNjeXLf7LzDzO6Fr+d6Ya12tBavTs0lY1D+6KLDvlDg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510238; 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=v9TcI9A6spljebx2QDGK6yrQbFQBX1hYlpBWQ6xUPDI=; b=nGn4J/CBYOev/A2Be5JimypCRRymC5mCM1gMwcer0O3TwfCv2pzsfrApBdqJ4ePOCVBs4/SmFeD3QmYqkIgpu7u+UXW59m3XiagPmQDbNMIDddAZOC7g1onZypexBFMHAZeTsCnzJt0e5XXnIypVFbYftnRVvdyUSa0EcSAh81o= 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 1555510238327167.59086060702487; Wed, 17 Apr 2019 07:10:38 -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 A7493307E051; Wed, 17 Apr 2019 14:10:31 +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 7C36560C67; Wed, 17 Apr 2019 14:10:31 +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 3E52B3FA50; Wed, 17 Apr 2019 14:10:31 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9jgX023850 for ; Wed, 17 Apr 2019 10:09:45 -0400 Received: by smtp.corp.redhat.com (Postfix) id C4F7960150; Wed, 17 Apr 2019 14:09:45 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id 305D060143; Wed, 17 Apr 2019 14:09:45 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:19 -0500 Message-Id: <20190417140921.11964-20-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 19/21] backup: Wire up qemu full pull backup 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.42]); Wed, 17 Apr 2019 14:10:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Time to actually issue the QMP transactions that start and stop backup commands (for now, just pull mode, not push). Starting a job has to kick off several pre-req steps, then a transaction, and additionally spawn an NBD server for pull mode; ending a job as well as failing partway through beginning a job has to unwind the earlier steps. Implementing push mode, as well as incremental pull and checkpoint creation, is deferred to later patches. Signed-off-by: Eric Blake --- src/qemu/qemu_domain.c | 18 ++- src/qemu/qemu_driver.c | 310 ++++++++++++++++++++++++++++++++++++++-- src/qemu/qemu_process.c | 9 ++ 3 files changed, 323 insertions(+), 14 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f4be948bae..db00c473d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -2684,17 +2684,25 @@ qemuDomainObjPrivateXMLParseBlockjobs(virQEMUDriver= Ptr driver, { xmlNodePtr node; int tmp; + size_t i; VIR_AUTOFREE(char *) active =3D NULL; if ((active =3D virXPathString("string(./blockjobs/@active)", ctxt)) && (tmp =3D virTristateBoolTypeFromString(active)) > 0) priv->reconnectBlockjobs =3D tmp; - if ((node =3D virXPathNode("./domainbackup", ctxt)) && - !(priv->backup =3D virDomainBackupDefParseNode(ctxt->doc, node, - driver->xmlopt, - VIR_DOMAIN_BACKUP_PAR= SE_INTERNAL))) - return -1; + if ((node =3D virXPathNode("./domainbackup", ctxt))) { + if (!(priv->backup =3D virDomainBackupDefParseNode(ctxt->doc, node, + driver->xmlopt, + VIR_DOMAIN_BACKUP= _PARSE_INTERNAL))) + return -1; + /* The backup job is only stored in XML if backupBegin + * succeeded at exporting the disk, so no need to store disk + * state when we can just force-reset it to a known-good + * value. */ + for (i =3D 0; i < priv->backup->ndisks; i++) + priv->backup->disks[i].state =3D VIR_DOMAIN_BACKUP_DISK_STATE_= EXPORT; + } return 0; } diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index cca0b550b8..044b26196e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17693,8 +17693,80 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr = checkpoint, return ret; } -static int qemuDomainBackupBegin(virDomainPtr domain, const char *diskXml, - const char *checkpointXml, unsigned int f= lags) +static int +qemuDomainBackupPrepare(virQEMUDriverPtr driver, virDomainObjPtr vm, + virDomainBackupDefPtr def) +{ + int ret =3D -1; + size_t i; + + if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) + goto cleanup; + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + + if (!disk->store) + continue; + if (virAsprintf(&disk->store->nodeformat, "tmp-%s", disk->name) < = 0) + goto cleanup; + if (!disk->store->format) + disk->store->format =3D VIR_STORAGE_FILE_QCOW2; + if (def->incremental) { + if (src->format !=3D VIR_STORAGE_FILE_QCOW2) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("incremental backup of %s requires qcow2"= ), + disk->name); + goto cleanup; + } + } + } + ret =3D 0; + cleanup: + return ret; +} + +/* Called while monitor lock is held. Best-effort cleanup. */ +static int +qemuDomainBackupDiskCleanup(virQEMUDriverPtr driver, virDomainObjPtr vm, + virDomainBackupDiskDef *disk, bool incremental) +{ + qemuDomainObjPrivatePtr priv =3D vm->privateData; + const char *node =3D vm->def->disks[disk->idx]->src->nodeformat; + int ret =3D 0; + + if (!disk->store) + return 0; + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT) { + /* No real need to use nbd-server-remove, since we will + * shortly be calling nbd-server-stop. */ + } + if (incremental && disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_BITMA= P && + qemuMonitorDeleteBitmap(priv->mon, node, disk->store->nodeformat) = < 0) { + VIR_WARN("Unable to remove temp bitmap for disk %s after backup", + disk->name); + ret =3D -1; + } + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_READY && + qemuMonitorBlockdevDel(priv->mon, disk->store->nodeformat) < 0) { + VIR_WARN("Unable to remove temp disk %s after backup", + disk->name); + ret =3D -1; + } + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_LABEL) + qemuDomainDiskChainElementRevoke(driver, vm, disk->store); + if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED && + disk->store->detected && unlink(disk->store->path) < 0) { + VIR_WARN("Unable to unlink temp disk %s after backup", + disk->store->path); + ret =3D -1; + } + return ret; +} + +static int +qemuDomainBackupBegin(virDomainPtr domain, const char *diskXml, + const char *checkpointXml, unsigned int flags) { virQEMUDriverPtr driver =3D domain->conn->privateData; virDomainObjPtr vm =3D NULL; @@ -17703,8 +17775,14 @@ static int qemuDomainBackupBegin(virDomainPtr doma= in, const char *diskXml, virCapsPtr caps =3D NULL; qemuDomainObjPrivatePtr priv; int ret =3D -1; + virJSONValuePtr json =3D NULL; + bool job_started =3D false; + bool nbd_running =3D false; + size_t i; struct timeval tv; char *suffix =3D NULL; + virCommandPtr cmd =3D NULL; + const char *qemuImgPath; virCheckFlags(VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA, -1); /* TODO: VIR_DOMAIN_BACKUP_BEGIN_QUIESCE */ @@ -17725,6 +17803,7 @@ static int qemuDomainBackupBegin(virDomainPtr domai= n, const char *diskXml, if (!(vm =3D qemuDomObjFromDomain(domain))) goto cleanup; + priv =3D vm->privateData; cfg =3D virQEMUDriverGetConfig(driver); if (virDomainBackupBeginEnsureACL(domain->conn, vm->def, flags) < 0) @@ -17747,25 +17826,145 @@ static int qemuDomainBackupBegin(virDomainPtr do= main, const char *diskXml, if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) goto cleanup; + if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_BITMAP)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks pull-mode backup support")= ); + goto cleanup; + } + if (!def->server) { + if (VIR_ALLOC(def->server) < 0) + goto cleanup; + def->server->transport =3D VIR_STORAGE_NET_HOST_TRANS_TCP; + if (VIR_STRDUP(def->server->name, "localhost") < 0) + goto cleanup; + } + switch ((virStorageNetHostTransport)def->server->transport) { + case VIR_STORAGE_NET_HOST_TRANS_TCP: + /* TODO: Update qemu.conf to provide a port range, + * probably starting at 10809, for obtaining automatic + * port via virPortAllocatorAcquire, as well as store + * somewhere if we need to call virPortAllocatorRelease + * during BackupEnd. Until then, user must provide port */ + if (!def->server->port) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _(" must specify TCP port for= now")); + goto cleanup; + } + break; + case VIR_STORAGE_NET_HOST_TRANS_UNIX: + /* TODO: Do we need to mess with selinux? */ + break; + case VIR_STORAGE_NET_HOST_TRANS_RDMA: + case VIR_STORAGE_NET_HOST_TRANS_LAST: + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("unexpected transport in ")); + goto cleanup; + } + } else { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("push mode backups not supported yet")); + goto cleanup; + } + if (def->incremental) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support= ")); + goto cleanup; + } + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", + _("cannot create incremental backups yet")); + goto cleanup; + } + + if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) + goto cleanup; + /* We are going to modify the domain below. */ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; - priv =3D vm->privateData; if (priv->backup) { virReportError(VIR_ERR_OPERATION_INVALID, "%s", _("another backup job is already running")); goto endjob; } - if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0) + if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0 || + qemuDomainBackupPrepare(driver, vm, def) < 0) goto endjob; /* actually start the checkpoint. 2x2 array of push/pull, full/incr, plus additional tweak if checkpoint requested */ - /* TODO: issue QMP commands: - - pull: nbd-server-start with from user (or autogenerate s= erver) - - push/pull: blockdev-add per + qemuDomainObjEnterMonitor(driver, vm); + /* - push/pull: blockdev-add per */ + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + virJSONValuePtr file; + virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + const char *node =3D src->nodeformat; + + if (!disk->store) + continue; + if (qemuDomainStorageFileInit(driver, vm, disk->store, src) < 0) + goto endmon; + if (disk->store->detected) { + if (virStorageFileCreate(disk->store) < 0) { + virReportSystemError(errno, + _("failed to create image file '%s'"), + NULLSTR(disk->store->path)); + goto endmon; + } + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED; + } + if (qemuDomainDiskChainElementPrepare(driver, vm, disk->store, fal= se, + true) < 0) + goto endmon; + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_LABEL; + if (disk->store->detected) { + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + /* Force initialization of scratch/target file to new qcow2 */ + if (!(cmd =3D virCommandNewArgList(qemuImgPath, + "create", + "-f", + virStorageFileFormatTypeToStr= ing(disk->store->format), + "-o", + NULL))) + goto endmon; + virBufferAsprintf(&buf, "backing_fmt=3D%s,backing_file=3D", + virStorageFileFormatTypeToString(src->format= )); + virQEMUBuildBufferEscapeComma(&buf, src->path); + virCommandAddArgBuffer(cmd, &buf); + + virQEMUBuildBufferEscapeComma(&buf, disk->store->path); + virCommandAddArgBuffer(cmd, &buf); + if (virCommandRun(cmd, NULL) < 0) + goto endmon; + virCommandFree(cmd); + cmd =3D NULL; + } + + if (virJSONValueObjectCreate(&file, + "s:driver", "file", + "s:filename", disk->store->path, + NULL) < 0) + goto endmon; + if (virJSONValueObjectCreate(&json, + "s:driver", virStorageFileFormatTypeT= oString(disk->store->format), + "s:node-name", disk->store->nodeforma= t, + "a:file", &file, + "s:backing", node, NULL) < 0) { + virJSONValueFree(file); + goto endmon; + } + if (qemuMonitorBlockdevAdd(priv->mon, json) < 0) + goto endmon; + json =3D NULL; + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_READY; + } + + /* TODO: - incr: bitmap-add of tmp, bitmap-merge per - transaction, containing: - push+full: blockdev-backup sync:full @@ -17773,8 +17972,76 @@ static int qemuDomainBackupBegin(virDomainPtr doma= in, const char *diskXml, - pull+full: blockdev-backup sync:none - pull+incr: blockdev-backup sync:none, bitmap-disable of tmp - if checkpoint: bitmap-disable of old, bitmap-add of new + */ + if (!(json =3D virJSONValueNewArray())) + goto endmon; + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + + if (!disk->store) + continue; + if (qemuMonitorJSONTransactionAdd(json, + "blockdev-backup", + "s:device", src->nodeformat, + "s:target", disk->store->nodefor= mat, + "s:sync", "none", + "s:job-id", disk->name, + NULL) < 0) + goto endmon; + } + if (qemuMonitorTransaction(priv->mon, &json) < 0) + goto endmon; + job_started =3D true; + + /* + - pull: nbd-server-start with from user (or autogenerate s= erver) - pull: nbd-server-add per , including bitmap for incr */ + if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + if (qemuMonitorNBDServerStart(priv->mon, def->server, NULL) < 0) + goto endmon; + nbd_running =3D true; + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (!disk->store) + continue; + if (qemuMonitorNBDServerAdd(priv->mon, disk->store->nodeformat, + disk->name, false, + def->incremental ? disk->name : + NULL) < 0) + goto endmon; + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT; + } + } + + ret =3D 0; + endmon: + /* Best effort cleanup if we fail partway through */ + if (ret < 0) { + virErrorPtr save_err =3D virSaveLastError(); + + if (nbd_running && + qemuMonitorNBDServerStop(priv->mon) < 0) + VIR_WARN("Unable to stop NBD server on vm %s after backup job", + vm->def->name); + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (job_started && + qemuMonitorBlockJobCancel(priv->mon, disk->name) < 0) + VIR_WARN("Unable to stop backup job %s on vm %s after fail= ure", + disk->store->nodeformat, vm->def->name); + qemuDomainBackupDiskCleanup(driver, vm, disk, !!def->increment= al); + } + virSetError(save_err); + virFreeError(save_err); + } + if (qemuDomainObjExitMonitor(driver, vm) < 0) + ret =3D -1; + if (ret < 0) + goto endjob; VIR_STEAL_PTR(priv->backup, def); ret =3D priv->backup->id =3D 1; /* Hard-coded job id for now */ @@ -17787,7 +18054,9 @@ static int qemuDomainBackupBegin(virDomainPtr domai= n, const char *diskXml, qemuDomainObjEndJob(driver, vm); cleanup: + virCommandFree(cmd); VIR_FREE(suffix); + virJSONValueFree(json); virDomainObjEndAPI(&vm); virDomainBackupDefFree(def); virObjectUnref(caps); @@ -17837,6 +18106,8 @@ static int qemuDomainBackupEnd(virDomainPtr domain,= int id, unsigned int flags) virDomainBackupDefPtr backup =3D NULL; qemuDomainObjPrivatePtr priv; bool want_abort =3D flags & VIR_DOMAIN_BACKUP_END_ABORT; + virDomainBackupDefPtr def; + size_t i; virCheckFlags(VIR_DOMAIN_BACKUP_END_ABORT, -1); @@ -17857,9 +18128,27 @@ static int qemuDomainBackupEnd(virDomainPtr domain= , int id, unsigned int flags) if (priv->backup->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) want_abort =3D false; + def =3D priv->backup; + + /* We are going to modify the domain below. */ + if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) + goto cleanup; + + qemuDomainObjEnterMonitor(driver, vm); + if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) + ret =3D qemuMonitorNBDServerStop(priv->mon); + for (i =3D 0; i < def->ndisks; i++) { + if (qemuMonitorBlockJobCancel(priv->mon, + def->disks[i].name) < 0 || + qemuDomainBackupDiskCleanup(driver, vm, &def->disks[i], + !!def->incremental) < 0) + ret =3D -1; + } + if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) { + ret =3D -1; + goto endjob; + } - /* TODO: QMP commands to actually cancel the pending job, and on - * pull, also tear down the NBD server */ VIR_STEAL_PTR(backup, priv->backup); if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm, driver->caps) < 0) @@ -17868,6 +18157,9 @@ static int qemuDomainBackupEnd(virDomainPtr domain,= int id, unsigned int flags) ret =3D want_abort ? 0 : 1; + endjob: + qemuDomainObjEndJob(driver, vm); + cleanup: virDomainBackupDefFree(backup); virDomainObjEndAPI(&vm); diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 71d4b39302..68755d58ff 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -88,6 +88,7 @@ #include "virresctrl.h" #include "virvsock.h" #include "viridentity.h" +#include "backup_conf.h" #define VIR_FROM_THIS VIR_FROM_QEMU @@ -932,6 +933,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE_= UNUSED, void *opaque) { virQEMUDriverPtr driver =3D opaque; + qemuDomainObjPrivatePtr priv; struct qemuProcessEvent *processEvent =3D NULL; virDomainDiskDefPtr disk; qemuBlockJobDataPtr job =3D NULL; @@ -942,6 +944,13 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon ATTRIBUTE= _UNUSED, VIR_DEBUG("Block job for device %s (domain: %p,%s) type %d status %d", diskAlias, vm, vm->def->name, type, status); + priv =3D vm->privateData; + if (type =3D=3D VIR_DOMAIN_BLOCK_JOB_TYPE_BACKUP && + (!priv->backup || priv->backup->type =3D=3D VIR_DOMAIN_BACKUP_TYPE= _PULL)) { + /* Event for canceling a pull-mode backup is side-effect that + * should not be forwarded on to user */ + goto cleanup; + } if (!(disk =3D qemuProcessFindDomainDiskByAliasOrQOM(vm, diskAlias, NU= LL))) goto cleanup; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510242; cv=none; d=zoho.com; s=zohoarc; b=V0CcuQS3jPDOpVH+C6nhlrPx8d0M4qnIM+w/ttbLp/DvigEfdvL9Dl07F3Ap0yQZTfrhMVGmv+nXTg3HdtzIN9swSaItZevM1VvdAYSLXnckd6Dc5Dif70Nl6s5ee5fiwx/0nX5cc4/HrRPkgS9ikdJ6bEIceGpwDRbVxhQqHJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510242; 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=W3FGvrrwGIQb8K2J4AYoobzOxLFSfi+YKZZHyAVqoCU=; b=alz4Ncz0jCqv0Zh2EUf3J49DddiuQujMhVqaY6GFv3Oov3AbhsBFbMYMNC8QpX2xikMdG+cJCpBy26Yah0rS+N2ySIwGi1MXAMnV4xNBatiUna8Y6MR8KLXgH7wGfzvGHzexXNtAgc8Ktbsqr5l4S1vP/pyLWrVLxbUxoIPU2lI= 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 1555510242189946.7177316111474; Wed, 17 Apr 2019 07:10:42 -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 8218719D382; Wed, 17 Apr 2019 14:10:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4F1795C22B; Wed, 17 Apr 2019 14:10:39 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E5DDD181BA02; Wed, 17 Apr 2019 14:10:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9kEq023865 for ; Wed, 17 Apr 2019 10:09:46 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7EC6E60156; Wed, 17 Apr 2019 14:09:46 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id E636F60143; Wed, 17 Apr 2019 14:09:45 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:20 -0500 Message-Id: <20190417140921.11964-21-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 20/21] backup: qemu: Wire up qemu full push backup 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Wed, 17 Apr 2019 14:10:40 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Update the code to support push backups; for now, the destination file still has to be local, although the XML could be extended into supporting remote destinations (where we will have to use the full power of blockdev-add). This also touches up the event handling to inform the user when the job is complete. (However, there are probably bugs lurking in the event code; pull mode is more tested than push mode at the time I write this). Signed-off-by: Eric Blake --- src/qemu/qemu_driver.c | 81 +++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 25 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 044b26196e..637cee4a54 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17729,14 +17729,13 @@ qemuDomainBackupPrepare(virQEMUDriverPtr driver, = virDomainObjPtr vm, /* Called while monitor lock is held. Best-effort cleanup. */ static int qemuDomainBackupDiskCleanup(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainBackupDiskDef *disk, bool incremental) + virDomainBackupDiskDef *disk, bool push, + bool incremental, bool completed) { qemuDomainObjPrivatePtr priv =3D vm->privateData; const char *node =3D vm->def->disks[disk->idx]->src->nodeformat; int ret =3D 0; - if (!disk->store) - return 0; if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_EXPORT) { /* No real need to use nbd-server-remove, since we will * shortly be calling nbd-server-stop. */ @@ -17749,16 +17748,17 @@ qemuDomainBackupDiskCleanup(virQEMUDriverPtr driv= er, virDomainObjPtr vm, } if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_READY && qemuMonitorBlockdevDel(priv->mon, disk->store->nodeformat) < 0) { - VIR_WARN("Unable to remove temp disk %s after backup", - disk->name); + VIR_WARN("Unable to remove %s disk %s after backup", + push ? "target" : "scratch", disk->name); ret =3D -1; } if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_LABEL) qemuDomainDiskChainElementRevoke(driver, vm, disk->store); - if (disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED && + if ((!push || !completed) && + disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_CREATED && disk->store->detected && unlink(disk->store->path) < 0) { - VIR_WARN("Unable to unlink temp disk %s after backup", - disk->store->path); + VIR_WARN("Unable to unlink %s disk %s after backup", + push ? "failed target" : "scratch", disk->store->path); ret =3D -1; } return ret; @@ -17778,6 +17778,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, virJSONValuePtr json =3D NULL; bool job_started =3D false; bool nbd_running =3D false; + bool push; size_t i; struct timeval tv; char *suffix =3D NULL; @@ -17826,7 +17827,8 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) goto cleanup; - if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + push =3D def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PUSH; + if (!push) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_BITMAP)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("qemu binary lacks pull-mode backup support")= ); @@ -17861,10 +17863,6 @@ qemuDomainBackupBegin(virDomainPtr domain, const c= har *diskXml, _("unexpected transport in ")); goto cleanup; } - } else { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("push mode backups not supported yet")); - goto cleanup; } if (def->incremental) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { @@ -17945,6 +17943,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, cmd =3D NULL; } + /* FIXME: allow non-local files for push destinations */ if (virJSONValueObjectCreate(&file, "s:driver", "file", "s:filename", disk->store->path, @@ -17985,7 +17984,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, "blockdev-backup", "s:device", src->nodeformat, "s:target", disk->store->nodefor= mat, - "s:sync", "none", + "s:sync", push ? "full" : "none", "s:job-id", disk->name, NULL) < 0) goto endmon; @@ -17998,7 +17997,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, - pull: nbd-server-start with from user (or autogenerate s= erver) - pull: nbd-server-add per , including bitmap for incr */ - if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) { + if (!push) { if (qemuMonitorNBDServerStart(priv->mon, def->server, NULL) < 0) goto endmon; nbd_running =3D true; @@ -18029,11 +18028,14 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; + if (!disk->store) + continue; if (job_started && qemuMonitorBlockJobCancel(priv->mon, disk->name) < 0) VIR_WARN("Unable to stop backup job %s on vm %s after fail= ure", disk->store->nodeformat, vm->def->name); - qemuDomainBackupDiskCleanup(driver, vm, disk, !!def->increment= al); + qemuDomainBackupDiskCleanup(driver, vm, disk, push, + !!def->incremental, false); } virSetError(save_err); virFreeError(save_err); @@ -18108,6 +18110,8 @@ static int qemuDomainBackupEnd(virDomainPtr domain,= int id, unsigned int flags) bool want_abort =3D flags & VIR_DOMAIN_BACKUP_END_ABORT; virDomainBackupDefPtr def; size_t i; + bool push =3D true; + bool completed =3D true; virCheckFlags(VIR_DOMAIN_BACKUP_END_ABORT, -1); @@ -18126,23 +18130,50 @@ static int qemuDomainBackupEnd(virDomainPtr domai= n, int id, unsigned int flags) goto cleanup; } - if (priv->backup->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) - want_abort =3D false; def =3D priv->backup; + if (def->type !=3D VIR_DOMAIN_BACKUP_TYPE_PUSH) { + want_abort =3D false; + push =3D false; + } /* We are going to modify the domain below. */ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_MODIFY) < 0) goto cleanup; qemuDomainObjEnterMonitor(driver, vm); - if (def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PULL) + if (push) { + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (!disk->store) + continue; + if (disk->state !=3D VIR_DOMAIN_BACKUP_DISK_STATE_COMPLETE) + completed =3D false; + } + } else { ret =3D qemuMonitorNBDServerStop(priv->mon); - for (i =3D 0; i < def->ndisks; i++) { - if (qemuMonitorBlockJobCancel(priv->mon, - def->disks[i].name) < 0 || - qemuDomainBackupDiskCleanup(driver, vm, &def->disks[i], - !!def->incremental) < 0) - ret =3D -1; + } + if (!completed && !want_abort) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("backup job id '%d' not complete yet"), id); + } else { + for (i =3D 0; i < def->ndisks; i++) { + virDomainBackupDiskDef *disk =3D &def->disks[i]; + + if (!disk->store) + continue; + if (!push || disk->state < VIR_DOMAIN_BACKUP_DISK_STATE_COMPLE= TE) { + if (qemuMonitorBlockJobCancel(priv->mon, + disk->name) < 0 && + !want_abort) { + ret =3D -1; + continue; + } + } + if (qemuDomainBackupDiskCleanup(driver, vm, disk, push, + !!def->incremental, completed)= < 0) + ret =3D -1; + } } if (qemuDomainObjExitMonitor(driver, vm) < 0 || ret < 0) { ret =3D -1; --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sat Apr 27 19:55:39 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=1555510247; cv=none; d=zoho.com; s=zohoarc; b=mg8M5vlS3wNRCtDAB6/wJbllVI+x6dAq8i/g7yZeQ4lytdmLUhnSNiqRaRX4HcwSHTK+xTCNs6r51GrxrbURFsBduuVymj+5r7SKsv0pPQyv0cyR9G6mEvqM+JyT1vJB3woc4mqHBpBhg42v7dfd6ZS+pRMpkEoOoTz7TTlRqHo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1555510247; 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=pjreBPmZKndTDtQ+vF3vdJLU3RcmFIKgdHYSKCwUeHw=; b=hyun5lYFECUiuGDdtKC1EmzdZfH3J7YWo9BdHd4N/HuQpiFwJbBo9TX3rV20ULNaJZIUSDnc9Cxu8uv0DM6fi7alHtz9aWqgf8HnigFKtlq4lOB7JfD7KW0rf/cgjzz/eYNpUQvpP5LW9cUDKsNfVBZQJjb+Dzu5TB4eDl3JUt4= 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 1555510247123364.57399905629984; Wed, 17 Apr 2019 07:10:47 -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 7CA22307D866; Wed, 17 Apr 2019 14:10: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 4244F1001E7C; Wed, 17 Apr 2019 14:10: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 638393F5A0; Wed, 17 Apr 2019 14:10:44 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x3HE9lSX023873 for ; Wed, 17 Apr 2019 10:09:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3BCDA6014E; Wed, 17 Apr 2019 14:09:47 +0000 (UTC) Received: from blue.redhat.com (ovpn-116-103.phx2.redhat.com [10.3.116.103]) by smtp.corp.redhat.com (Postfix) with ESMTP id A20D060143; Wed, 17 Apr 2019 14:09:46 +0000 (UTC) From: Eric Blake To: libvir-list@redhat.com Date: Wed, 17 Apr 2019 09:09:21 -0500 Message-Id: <20190417140921.11964-22-eblake@redhat.com> In-Reply-To: <20190417140921.11964-1-eblake@redhat.com> References: <20190417140921.11964-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: nsoffer@redhat.com, jtomko@redhat.com, pkrempa@redhat.com Subject: [libvirt] [PATCH v8 21/21] backup: implement qemu incremental pull backup 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.48]); Wed, 17 Apr 2019 14:10:46 +0000 (UTC) Content-Type: text/plain; charset="utf-8" Complete wiring up incremental backup, by adding in support for creating a checkpoint at the same time as a backup (make the transaction have a few more steps) as well as exposing the dirty bitmap for a prior backup over NBD (requires creating a temporary bitmap, merging all appropriate bitmaps in, then exposing that bitmap over NBD). Signed-off-by: Eric Blake --- src/qemu/qemu_driver.c | 198 +++++++++++++++++++++++++++++++++++------ 1 file changed, 170 insertions(+), 28 deletions(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 637cee4a54..ba4c1ec228 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -17039,6 +17039,24 @@ qemuDomainCheckpointPrepare(virQEMUDriverPtr drive= r, virCapsPtr caps, if (disk->type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) continue; + /* We want to name temporary bitmap after disk name during + * incremental backup, which is not possible if that is a + * persistent bitmap name. We can also make life easier by + * enforcing bitmap names match checkpoint name, although this + * is not technically necessary. */ + if (STREQ(disk->name, disk->bitmap)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("checkpoint for disk %s must have distinct bi= tmap name"), + disk->name); + goto cleanup; + } + if (STRNEQ(disk->bitmap, def->common.name)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("disk %s bitmap should match checkpoint name = %s"), + disk->name, def->common.name); + goto cleanup; + } + if (vm->def->disks[i]->src->format > 0 && vm->def->disks[i]->src->format !=3D VIR_STORAGE_FILE_QCOW2) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, @@ -17695,19 +17713,44 @@ qemuDomainCheckpointDelete(virDomainCheckpointPtr= checkpoint, static int qemuDomainBackupPrepare(virQEMUDriverPtr driver, virDomainObjPtr vm, - virDomainBackupDefPtr def) + virDomainBackupDefPtr def, + virDomainMomentObjPtr chk) { int ret =3D -1; size_t i; + virDomainCheckpointDefPtr chkdef; + chkdef =3D chk ? virDomainCheckpointObjGetDef(chk) : NULL; + if (chk && def->ndisks !=3D chkdef->ndisks) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("inconsistency between backup and checkpoint disk= s")); + goto cleanup; + } if (qemuBlockNodeNamesDetect(driver, vm, QEMU_ASYNC_JOB_NONE) < 0) goto cleanup; for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; - if (!disk->store) + /* For now, insist that atomic checkpoint affect same disks as + * those being backed up. */ + if (!disk->store) { + if (chk && + chkdef->disks[i].type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_NONE= ) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("disk %s requested checkpoint without bac= kup"), + disk->name); + goto cleanup; + } continue; + } + if (chk && + chkdef->disks[i].type !=3D VIR_DOMAIN_CHECKPOINT_TYPE_BITMAP) { + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("disk %s requested backup without checkpoint"= ), + disk->name); + goto cleanup; + } if (virAsprintf(&disk->store->nodeformat, "tmp-%s", disk->name) < = 0) goto cleanup; if (!disk->store->format) @@ -17741,7 +17784,7 @@ qemuDomainBackupDiskCleanup(virQEMUDriverPtr driver= , virDomainObjPtr vm, * shortly be calling nbd-server-stop. */ } if (incremental && disk->state >=3D VIR_DOMAIN_BACKUP_DISK_STATE_BITMA= P && - qemuMonitorDeleteBitmap(priv->mon, node, disk->store->nodeformat) = < 0) { + qemuMonitorDeleteBitmap(priv->mon, node, disk->name) < 0) { VIR_WARN("Unable to remove temp bitmap for disk %s after backup", disk->name); ret =3D -1; @@ -17779,28 +17822,22 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, bool job_started =3D false; bool nbd_running =3D false; bool push; + const char *mode; size_t i; struct timeval tv; char *suffix =3D NULL; virCommandPtr cmd =3D NULL; const char *qemuImgPath; + virDomainCheckpointDefPtr chkdef =3D NULL; + virDomainMomentObjPtr chk =3D NULL; + virDomainMomentObjPtr other =3D NULL; + virDomainMomentObjPtr parent =3D NULL; + virDomainMomentObjPtr current; + virJSONValuePtr arr =3D NULL; virCheckFlags(VIR_DOMAIN_BACKUP_BEGIN_NO_METADATA, -1); /* TODO: VIR_DOMAIN_BACKUP_BEGIN_QUIESCE */ - // FIXME: Support non-null checkpointXML for incremental - what - // code can be shared with CheckpointCreateXML, then add to transaction - // to create new checkpoint at same time as starting blockdev-backup - if (checkpointXml) { - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot create incremental backups yet")); - return -1; - } - // if (chk) VIR_STRDUP(suffix, chk->name); - gettimeofday(&tv, NULL); - if (virAsprintf(&suffix, "%lld", (long long)tv.tv_sec) < 0) - goto cleanup; - if (!(vm =3D qemuDomObjFromDomain(domain))) goto cleanup; @@ -17827,6 +17864,17 @@ qemuDomainBackupBegin(virDomainPtr domain, const c= har *diskXml, if (!(def =3D virDomainBackupDefParseString(diskXml, driver->xmlopt, 0= ))) goto cleanup; + if (checkpointXml) { + if (!(chkdef =3D qemuDomainCheckpointDefParseString(driver, caps, + checkpointXml, 0= )) || + VIR_STRDUP(suffix, chkdef->common.name) < 0) + goto cleanup; + } else { + gettimeofday(&tv, NULL); + if (virAsprintf(&suffix, "%lld", (long long)tv.tv_sec) < 0) + goto cleanup; + } + push =3D def->type =3D=3D VIR_DOMAIN_BACKUP_TYPE_PUSH; if (!push) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_NBD_BITMAP)) { @@ -17864,15 +17912,25 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, goto cleanup; } } + current =3D virDomainCheckpointGetCurrent(vm->checkpoints); if (def->incremental) { if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("qemu binary lacks persistent bitmaps support= ")); goto cleanup; } - virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s", - _("cannot create incremental backups yet")); - goto cleanup; + for (other =3D current; other; + other =3D other->def->parent ? + virDomainCheckpointFindByName(vm->checkpoints, + other->def->parent) : NULL) + if (STREQ(other->def->name, def->incremental)) + break; + if (!other) { + virReportError(VIR_ERR_OPERATION_INVALID, + _("could not locate checkpoint '%s' for increme= ntal backup"), + def->incremental); + goto cleanup; + } } if (!(qemuImgPath =3D qemuFindQemuImgBinary(driver))) @@ -17888,14 +17946,38 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, goto endjob; } + if (chkdef) { + if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_BITMAP_MERGE)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("qemu binary lacks persistent bitmaps support= ")); + goto endjob; + } + + if (qemuDomainCheckpointPrepare(driver, caps, vm, chkdef) < 0) + goto endjob; + if (!(chk =3D virDomainCheckpointAssignDef(vm->checkpoints, chkdef= ))) + goto endjob; + chkdef =3D NULL; + if (current) { + parent =3D current; + if (VIR_STRDUP(chk->def->parent, parent->def->name) < 0) + goto endjob; + if (qemuDomainCheckpointWriteMetadata(vm, parent, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) + goto endjob; + } + } + if (virDomainBackupAlignDisks(def, vm->def, suffix) < 0 || - qemuDomainBackupPrepare(driver, vm, def) < 0) + qemuDomainBackupPrepare(driver, vm, def, chk) < 0) goto endjob; /* actually start the checkpoint. 2x2 array of push/pull, full/incr, plus additional tweak if checkpoint requested */ qemuDomainObjEnterMonitor(driver, vm); - /* - push/pull: blockdev-add per */ + /* - push/pull: blockdev-add per + - incr: bitmap-add of tmp, bitmap-merge per */ for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; virJSONValuePtr file; @@ -17961,11 +18043,32 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, goto endmon; json =3D NULL; disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_READY; + + if (def->incremental) { + if (!(arr =3D virJSONValueNewArray())) + goto endmon; + if (qemuMonitorAddBitmap(priv->mon, node, disk->name, false) <= 0) { + virJSONValueFree(arr); + goto endmon; + } + disk->state =3D VIR_DOMAIN_BACKUP_DISK_STATE_BITMAP; + for (other =3D parent ? parent : current; other; + other =3D other->def->parent ? + virDomainCheckpointFindByName(vm->checkpoints, + other->def->parent) : N= ULL) { + if (virJSONValueArrayAppendString(arr, other->def->name) <= 0) { + virJSONValueFree(arr); + goto endmon; + } + if (STREQ(other->def->name, def->incremental)) + break; + } + if (qemuMonitorMergeBitmaps(priv->mon, node, disk->name, &arr)= < 0) + goto endmon; + } } - /* TODO: - - incr: bitmap-add of tmp, bitmap-merge per - - transaction, containing: + /* - transaction, containing: - push+full: blockdev-backup sync:full - push+incr: blockdev-backup sync:incremental bitmap:tmp - pull+full: blockdev-backup sync:none @@ -17974,24 +18077,61 @@ qemuDomainBackupBegin(virDomainPtr domain, const = char *diskXml, */ if (!(json =3D virJSONValueNewArray())) goto endmon; + if (push) + mode =3D def->incremental ? "incremental" : "full"; + else + mode =3D "none"; for (i =3D 0; i < def->ndisks; i++) { virDomainBackupDiskDef *disk =3D &def->disks[i]; - virStorageSourcePtr src =3D vm->def->disks[disk->idx]->src; + const char *node; + const char *push_bitmap =3D NULL; if (!disk->store) continue; + node =3D qemuBlockNodeLookup(vm, disk->name); + if (push && def->incremental) + push_bitmap =3D disk->name; if (qemuMonitorJSONTransactionAdd(json, "blockdev-backup", - "s:device", src->nodeformat, + "s:device", node, "s:target", disk->store->nodefor= mat, - "s:sync", push ? "full" : "none", + "s:sync", mode, + "S:bitmap", push_bitmap, "s:job-id", disk->name, NULL) < 0) goto endmon; + if (def->incremental && !push && + qemuMonitorJSONTransactionAdd(json, + "block-dirty-bitmap-disable", + "s:node", node, + "s:name", disk->name, + NULL) < 0) + goto endmon; } + if (chk && qemuDomainCheckpointAddActions(vm, json, parent, + virDomainCheckpointObjGetDef= (chk)) < 0) + goto endmon; if (qemuMonitorTransaction(priv->mon, &json) < 0) goto endmon; job_started =3D true; + if (chk) { + if (qemuDomainCheckpointWriteMetadata(vm, chk, driver->caps, + driver->xmlopt, + cfg->checkpointDir) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unable to save metadata for checkpoint %s"), + chk->def->name); + virDomainCheckpointObjListRemove(vm->checkpoints, chk); + goto endmon; + } + virDomainCheckpointSetCurrent(vm->checkpoints, chk); + other =3D virDomainCheckpointFindByName(vm->checkpoints, + chk->def->parent); + chk->parent =3D other; + other->nchildren++; + chk->sibling =3D other->first_child; + other->first_child =3D chk; + } /* - pull: nbd-server-start with from user (or autogenerate s= erver) @@ -18033,7 +18173,7 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, if (job_started && qemuMonitorBlockJobCancel(priv->mon, disk->name) < 0) VIR_WARN("Unable to stop backup job %s on vm %s after fail= ure", - disk->store->nodeformat, vm->def->name); + disk->name, vm->def->name); qemuDomainBackupDiskCleanup(driver, vm, disk, push, !!def->incremental, false); } @@ -18056,6 +18196,8 @@ qemuDomainBackupBegin(virDomainPtr domain, const ch= ar *diskXml, qemuDomainObjEndJob(driver, vm); cleanup: + virJSONValueFree(arr); + virDomainCheckpointDefFree(chkdef); virCommandFree(cmd); VIR_FREE(suffix); virJSONValueFree(json); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list