mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 05:35:25 +00:00
nodedev: Add VIR_NODE_DEVICE_(CREATE|DEFINE)_XML_VALIDATE flags
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>
This commit is contained in:
parent
0268270b0f
commit
d8791c3c7c
@ -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
|
||||
----------------
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user