[PATCH 5/6] storage: Add VIR_STORAGE_VOL_CREATE_VALIDATE flag

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Allow users to request validation of the storage volume XML. Add new
flag and virsh support.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 docs/manpages/virsh.rst           |  9 +++++++--
 include/libvirt/libvirt-storage.h |  1 +
 tools/virsh-volume.c              | 14 ++++++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/docs/manpages/virsh.rst b/docs/manpages/virsh.rst
index 532d4e779c..1e85b6ae78 100644
--- a/docs/manpages/virsh.rst
+++ b/docs/manpages/virsh.rst
@@ -6542,7 +6542,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>.

@@ -6557,6 +6557,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:**

 ::
@@ -6574,7 +6577,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.

@@ -6596,6 +6599,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
 -------------
diff --git a/include/libvirt/libvirt-storage.h b/include/libvirt/libvirt-storage.h
index af1c50b9f1..aaad4a3da1 100644
--- a/include/libvirt/libvirt-storage.h
+++ b/include/libvirt/libvirt-storage.h
@@ -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,
diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c
index 300a0aa8e5..4f23481180 100644
--- a/tools/virsh-volume.c
+++ b/tools/virsh-volume.c
@@ -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;

-- 
2.37.3




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux