[PATCH 06/13] virsh: Add --print-xml flag for 'vol-clone' command

Peter Krempa pkrempa at redhat.com
Fri Dec 2 14:16:50 UTC 2022


Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 docs/manpages/virsh.rst | 5 ++++-
 tools/virsh-volume.c    | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 14ed9cd5a0..c85bc8151d 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -6719,7 +6719,7 @@ vol-clone
 ::

    vol-clone vol-name-or-key-or-path name
-      [--pool pool-or-uuid] [--prealloc-metadata] [--reflink]
+      [--pool pool-or-uuid] [--prealloc-metadata] [--reflink] [--print-xml]

 Clone an existing volume within the parent pool.  Less powerful,
 but easier to type, version of ``vol-create-from``.
@@ -6743,6 +6743,9 @@ When *--reflink* is specified, perform a COW lightweight copy,
 where the data blocks are copied only when modified.
 If this is not possible, the copy fails.

+If *--print-xml* is specified, then the XML used to clone the volume is
+printed instead.
+

 vol-delete
 ----------
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index b7a1ddb9e5..adfea570be 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -559,6 +559,10 @@ static const vshCmdOptDef opts_vol_clone[] = {
      .type = VSH_OT_BOOL,
      .help = N_("use btrfs COW lightweight copy")
     },
+    {.name = "print-xml",
+     .type = VSH_OT_BOOL,
+     .help = N_("print XML document rather than clone the volume")
+    },
     {.name = NULL}
 };

@@ -599,6 +603,11 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd)
         return false;
     }

+    if (vshCommandOptBool(cmd, "print-xml")) {
+        vshPrint(ctl, "%s", newxml);
+        return true;
+    }
+
     if (!(newvol = virStorageVolCreateXMLFrom(origpool, (char *) newxml,
                                               origvol, flags))) {
         vshError(ctl, _("Failed to clone vol from %s"),
-- 
2.38.1



More information about the libvir-list mailing list