]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
nodedev: Add VIR_NODE_DEVICE_(CREATE|DEFINE)_XML_VALIDATE flags
authorPeter Krempa <pkrempa@redhat.com>
Tue, 18 Oct 2022 11:19:05 +0000 (13:19 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Nov 2022 12:07:20 +0000 (13:07 +0100)
The node device APIs which get XML from the user don't yet support XML
validation flags. Introduce virNodeDeviceCreateXMLFlags and
virNodeDeviceDefineXMLFlags with the appropriate flags and add virsh
support for the new flags.

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

index 6ea87d2e7622be9dd6ce28d5f809c0ad12a04854..b33e6a3a86fd7c9d9d351596614a66a43a5ed16d 100644 (file)
@@ -5235,7 +5235,7 @@ nodedev-create
 
 ::
 
-   nodedev-create FILE
+   nodedev-create FILE [--validate]
 
 Create a device on the host node that can then be assigned to virtual
 machines. Normally, libvirt is able to automatically determine which
@@ -5243,6 +5243,9 @@ host nodes are available for use, but this allows registration of
 host hardware that libvirt did not automatically detect.  *file*
 contains xml for a top-level <device> description of a node device.
 
+If *--validate* is specified, validates the format of the XML document against
+an internal RNG schema.
+
 
 nodedev-destroy
 ---------------
@@ -5266,11 +5269,14 @@ nodedev-define
 
 ::
 
-   nodedev-define FILE
+   nodedev-define FILE [--validate]
 
 Define an inactive persistent device or modify an existing persistent one from
 the XML *FILE*.
 
+If *--validate* is specified, validates the format of the XML document against
+an internal RNG schema.
+
 
 nodedev-undefine
 ----------------
index 4fccd3f6148ecc955788793d2961b57e0dddb6bb..428b0d722fdb6b91119de6173cf880d96776e94f 100644 (file)
@@ -130,12 +130,31 @@ int                     virNodeDeviceDetachFlags(virNodeDevicePtr dev,
 int                     virNodeDeviceReAttach   (virNodeDevicePtr dev);
 int                     virNodeDeviceReset      (virNodeDevicePtr dev);
 
+/**
+ * virNodeDeviceCreateXMLFlags:
+ *
+ * Since: 8.10.0
+ */
+typedef enum {
+    VIR_NODE_DEVICE_CREATE_XML_VALIDATE = 1 << 0, /* Validate the XML document against schema (Since: 8.10.0) */
+} virNodeDeviceCreateXMLFlags;
+
 virNodeDevicePtr        virNodeDeviceCreateXML  (virConnectPtr conn,
                                                  const char *xmlDesc,
                                                  unsigned int flags);
 
 int                     virNodeDeviceDestroy    (virNodeDevicePtr dev);
 
+
+/**
+ * virNodeDeviceDefineXMLFlags:
+ *
+ * Since: 8.10.0
+ */
+typedef enum {
+    VIR_NODE_DEVICE_DEFINE_XML_VALIDATE = 1 << 0, /* Validate the XML document against schema (Since: 8.10.0) */
+} virNodeDeviceDefineXMLFlags;
+
 virNodeDevicePtr virNodeDeviceDefineXML(virConnectPtr conn,
                                         const char *xmlDesc,
                                         unsigned int flags);
index d5a24ea2ef35337bae3458c678ad97adf4dc9655..1b7dee113ee7cf4d1d636180dcd297f0bebb1a88 100644 (file)
@@ -694,7 +694,7 @@ virNodeDeviceReset(virNodeDevicePtr dev)
  * virNodeDeviceCreateXML:
  * @conn: pointer to the hypervisor connection
  * @xmlDesc: string containing an XML description of the device to be created
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of supported virNodeDeviceCreateXMLFlags
  *
  * Create a new device on the VM host machine, for example, virtual
  * HBAs created using vport_create.
@@ -778,7 +778,7 @@ virNodeDeviceDestroy(virNodeDevicePtr dev)
  * virNodeDeviceDefineXML:
  * @conn: pointer to the hypervisor connection
  * @xmlDesc: string containing an XML description of the device to be defined
- * @flags: extra flags; not used yet, so callers should always pass 0
+ * @flags: bitwise-OR of supported virNodeDeviceDefineXMLFlags
  *
  * Define a new device on the VM host machine, for example, a mediated device
  *
index 2adcad9c1079402e67a29c12bb79b79754ffc239..5dbec65367d341ca3afcf47b02d108482e58c3c1 100644 (file)
@@ -50,6 +50,10 @@ static const vshCmdInfo info_node_device_create[] = {
 static const vshCmdOptDef opts_node_device_create[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML description "
                              "of the device")),
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -60,6 +64,7 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     g_autofree char *buffer = NULL;
     virshControl *priv = ctl->privData;
+    unsigned int flags = 0;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         return false;
@@ -67,7 +72,10 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd)
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    if (!(dev = virNodeDeviceCreateXML(priv->conn, buffer, 0))) {
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_NODE_DEVICE_CREATE_XML_VALIDATE;
+
+    if (!(dev = virNodeDeviceCreateXML(priv->conn, buffer, flags))) {
         vshError(ctl, _("Failed to create node device from %s"), from);
         return false;
     }
@@ -1058,6 +1066,10 @@ static const vshCmdInfo info_node_device_define[] = {
 static const vshCmdOptDef opts_node_device_define[] = {
     VIRSH_COMMON_OPT_FILE(N_("file containing an XML description "
                              "of the device")),
+    {.name = "validate",
+     .type = VSH_OT_BOOL,
+     .help = N_("validate the XML against the schema")
+    },
     {.name = NULL}
 };
 
@@ -1068,6 +1080,7 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
     const char *from = NULL;
     g_autofree char *buffer = NULL;
     virshControl *priv = ctl->privData;
+    unsigned int flags = 0;
 
     if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0)
         return false;
@@ -1075,7 +1088,10 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
     if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0)
         return false;
 
-    if (!(dev = virNodeDeviceDefineXML(priv->conn, buffer, 0))) {
+    if (vshCommandOptBool(cmd, "validate"))
+        flags |= VIR_NODE_DEVICE_DEFINE_XML_VALIDATE;
+
+    if (!(dev = virNodeDeviceDefineXML(priv->conn, buffer, flags))) {
         vshError(ctl, _("Failed to define node device from '%s'"), from);
         return false;
     }