]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Add VIR_STORAGE_VOL_CREATE_VALIDATE flag
authorPeter Krempa <pkrempa@redhat.com>
Tue, 18 Oct 2022 11:59:29 +0000 (13:59 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Nov 2022 12:07:20 +0000 (13:07 +0100)
Allow users to request validation of the storage volume XML. Add new
flag and virsh support.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Jonathon Jongsma <jjongsma@redhat.com>
docs/manpages/virsh.rst
include/libvirt/libvirt-storage.h
tools/virsh-volume.c

index b33e6a3a86fd7c9d9d351596614a66a43a5ed16d..5f5f48f83e42f1438cc9ef9c87ac837dfd500240 100644 (file)
@@ -6574,7 +6574,7 @@ vol-create
 
 ::
 
-   vol-create pool-or-uuid FILE [--prealloc-metadata]
+   vol-create pool-or-uuid FILE [--prealloc-metadata] [--validate]
 
 Create a volume from an XML <file>.
 
@@ -6589,6 +6589,9 @@ support full allocation). This option creates a sparse image file with metadata,
 resulting in higher performance compared to images with no preallocation and
 only slightly higher initial disk space usage.
 
+If *--validate* is specified, validates the format of the XML document against
+an internal RNG schema.
+
 **Example:**
 
 ::
@@ -6606,7 +6609,7 @@ vol-create-from
 ::
 
    vol-create-from pool-or-uuid FILE vol-name-or-key-or-path
-      [--inputpool pool-or-uuid]  [--prealloc-metadata] [--reflink]
+      [--inputpool pool-or-uuid]  [--prealloc-metadata] [--reflink] [--validate]
 
 Create a volume, using another volume as input.
 
@@ -6628,6 +6631,8 @@ 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 *--validate* is specified, validates the format of the XML document against
+an internal RNG schema.
 
 vol-create-as
 -------------
index af1c50b9f1a556d942a703b40dd31ec613308fbd..aaad4a3da18380b2f1dfb03a741addb125a5efd3 100644 (file)
@@ -437,6 +437,7 @@ const char*             virStorageVolGetKey             (virStorageVolPtr vol);
 typedef enum {
     VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA = 1 << 0, /* (Since: 1.0.1) */
     VIR_STORAGE_VOL_CREATE_REFLINK = 1 << 1, /* perform a btrfs lightweight copy (Since: 1.2.13) */
+    VIR_STORAGE_VOL_CREATE_VALIDATE = 1 << 2, /* Validate the XML document against schema (Since: 8.10.0) */
 } virStorageVolCreateFlags;
 
 virStorageVolPtr        virStorageVolCreateXML          (virStoragePoolPtr pool,
index 300a0aa8e56b5a968abb9734f3947be58a72307b..4f23481180f0a0a92e732050fbc8fbd3cb51d79f 100644 (file)
@@ -380,6 +380,10 @@ static const vshCmdOptDef opts_vol_create[] = {
      .type = VSH_OT_BOOL,
      .help = N_("preallocate metadata (for qcow2 instead of full allocation)")
     },
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -395,6 +399,9 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool(cmd, "prealloc-metadata"))
         flags |= VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA;
 
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_STORAGE_VOL_CREATE_VALIDATE;
+
     if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
         return false;
 
@@ -446,6 +453,10 @@ static const vshCmdOptDef opts_vol_create_from[] = {
      .type = VSH_OT_BOOL,
      .help = N_("use btrfs COW lightweight copy")
     },
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -468,6 +479,9 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptBool(cmd, "reflink"))
         flags |= VIR_STORAGE_VOL_CREATE_REFLINK;
 
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_STORAGE_VOL_CREATE_VALIDATE;
+
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         return false;