storage: Add VIR_STORAGE_VOL_CREATE_VALIDATE flag

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>
This commit is contained in:
Peter Krempa 2022-10-18 13:59:29 +02:00
parent 563ef19f9b
commit db5f05dd22
3 changed files with 22 additions and 2 deletions

View 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>. 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 resulting in higher performance compared to images with no preallocation and
only slightly higher initial disk space usage. only slightly higher initial disk space usage.
If *--validate* is specified, validates the format of the XML document against
an internal RNG schema.
**Example:** **Example:**
:: ::
@ -6606,7 +6609,7 @@ vol-create-from
:: ::
vol-create-from pool-or-uuid FILE vol-name-or-key-or-path 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. 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. where the data blocks are copied only when modified.
If this is not possible, the copy fails. 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 vol-create-as
------------- -------------

View File

@ -437,6 +437,7 @@ const char* virStorageVolGetKey (virStorageVolPtr vol);
typedef enum { typedef enum {
VIR_STORAGE_VOL_CREATE_PREALLOC_METADATA = 1 << 0, /* (Since: 1.0.1) */ 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_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; } virStorageVolCreateFlags;
virStorageVolPtr virStorageVolCreateXML (virStoragePoolPtr pool, virStorageVolPtr virStorageVolCreateXML (virStoragePoolPtr pool,

View File

@ -380,6 +380,10 @@ static const vshCmdOptDef opts_vol_create[] = {
.type = VSH_OT_BOOL, .type = VSH_OT_BOOL,
.help = N_("preallocate metadata (for qcow2 instead of full allocation)") .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} {.name = NULL}
}; };
@ -395,6 +399,9 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "prealloc-metadata")) if (vshCommandOptBool(cmd, "prealloc-metadata"))
flags |= VIR_STORAGE_VOL_CREATE_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))) if (!(pool = virshCommandOptPool(ctl, cmd, "pool", NULL)))
return false; return false;
@ -446,6 +453,10 @@ static const vshCmdOptDef opts_vol_create_from[] = {
.type = VSH_OT_BOOL, .type = VSH_OT_BOOL,
.help = N_("use btrfs COW lightweight copy") .help = N_("use btrfs COW lightweight copy")
}, },
{.name = "validate",
.type = VSH_OT_BOOL,
.help = N_("validate the XML against the schema")
},
{.name = NULL} {.name = NULL}
}; };
@ -468,6 +479,9 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptBool(cmd, "reflink")) if (vshCommandOptBool(cmd, "reflink"))
flags |= VIR_STORAGE_VOL_CREATE_REFLINK; flags |= VIR_STORAGE_VOL_CREATE_REFLINK;
if (vshCommandOptBool(cmd, "validate"))
flags |= VIR_STORAGE_VOL_CREATE_VALIDATE;
if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
return false; return false;