const char *xmlDesc,
unsigned int flags);
+int virNodeDeviceUndefine(virNodeDevicePtr dev);
+
/**
* VIR_NODE_DEVICE_EVENT_CALLBACK:
*
VIR_ACCESS_PERM_NODE_DEVICE_LAST,
"getattr", "read", "write",
"start", "stop",
- "detach",
+ "detach", "delete",
);
VIR_ENUM_IMPL(virAccessPermNWFilter,
*/
VIR_ACCESS_PERM_NODE_DEVICE_DETACH,
+ /**
+ * @desc: Delete node device
+ * @message: Deleting node device driver requires authorization
+ */
+ VIR_ACCESS_PERM_NODE_DEVICE_DELETE,
+
VIR_ACCESS_PERM_NODE_DEVICE_LAST
} virAccessPermNodeDevice;
const char *xmlDesc,
unsigned int flags);
+typedef int
+(*virDrvNodeDeviceUndefine)(virNodeDevicePtr dev);
+
typedef int
(*virDrvConnectNodeDeviceEventRegisterAny)(virConnectPtr conn,
virNodeDevicePtr dev,
virDrvNodeDeviceCreateXML nodeDeviceCreateXML;
virDrvNodeDeviceDestroy nodeDeviceDestroy;
virDrvNodeDeviceDefineXML nodeDeviceDefineXML;
+ virDrvNodeDeviceUndefine nodeDeviceUndefine;
};
}
+/**
+ * virNodeDeviceUndefine:
+ * @dev: a device object
+ *
+ * Undefine the device object. The virtual device is removed from the host
+ * operating system. This function may require privileged access.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virNodeDeviceUndefine(virNodeDevicePtr dev)
+{
+ VIR_DEBUG("dev=%p", dev);
+
+ virResetLastError();
+
+ virCheckNodeDeviceReturn(dev, -1);
+ virCheckReadOnlyGoto(dev->conn->flags, error);
+
+ if (dev->conn->nodeDeviceDriver &&
+ dev->conn->nodeDeviceDriver->nodeDeviceUndefine) {
+ int retval = dev->conn->nodeDeviceDriver->nodeDeviceUndefine(dev);
+ if (retval < 0)
+ goto error;
+
+ return 0;
+ }
+
+ virReportUnsupportedError();
+
+ error:
+ virDispatchError(dev->conn);
+ return -1;
+}
+
+
/**
* virConnectNodeDeviceEventRegisterAny:
* @conn: pointer to the connection
LIBVIRT_7.3.0 {
global:
virNodeDeviceDefineXML;
+ virNodeDeviceUndefine;
} LIBVIRT_7.2.0;
# .... define new API here using predicted next version number ....
}
+virCommand *
+nodeDeviceGetMdevctlUndefineCommand(const char *uuid, char **errmsg)
+{
+ virCommand *cmd = virCommandNewArgList(MDEVCTL,
+ "undefine",
+ "-u",
+ uuid,
+ NULL);
+ virCommandSetErrorBuffer(cmd, errmsg);
+ return cmd;
+}
+
static int
virMdevctlStop(virNodeDeviceDefPtr def, char **errmsg)
{
}
+static int
+virMdevctlUndefine(virNodeDeviceDef *def, char **errmsg)
+{
+ int status;
+ g_autoptr(virCommand) cmd = NULL;
+
+ cmd = nodeDeviceGetMdevctlUndefineCommand(def->caps->data.mdev.uuid,
+ errmsg);
+
+ if (virCommandRun(cmd, &status) < 0 || status != 0)
+ return -1;
+
+ return 0;
+}
+
+
virCommand*
nodeDeviceGetMdevctlListCommand(bool defined,
char **output,
}
+int
+nodeDeviceUndefine(virNodeDevice *device)
+{
+ int ret = -1;
+ virNodeDeviceObj *obj = NULL;
+ virNodeDeviceDef *def;
+
+ if (nodeDeviceWaitInit() < 0)
+ return -1;
+
+ if (!(obj = nodeDeviceObjFindByName(device->name)))
+ return -1;
+
+ def = virNodeDeviceObjGetDef(obj);
+
+ if (virNodeDeviceUndefineEnsureACL(device->conn, def) < 0)
+ goto cleanup;
+
+ if (!virNodeDeviceObjIsPersistent(obj)) {
+ virReportError(VIR_ERR_OPERATION_INVALID,
+ _("Node device '%s' is not defined"),
+ def->name);
+ goto cleanup;
+ }
+
+ if (nodeDeviceHasCapability(def, VIR_NODE_DEV_CAP_MDEV)) {
+ g_autofree char *errmsg = NULL;
+
+ if (virMdevctlUndefine(def, &errmsg) < 0) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("Unable to undefine mediated device: %s"),
+ errmsg && errmsg[0] ? errmsg : "Unknown Error");
+ goto cleanup;
+ }
+ ret = 0;
+ } else {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("Unsupported device type"));
+ }
+
+ cleanup:
+ virNodeDeviceObjEndAPI(&obj);
+ return ret;
+}
+
int
nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
const char *xmlDesc,
unsigned int flags);
+int
+nodeDeviceUndefine(virNodeDevice *dev);
+
int
nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn,
virNodeDevicePtr dev,
nodeDeviceGetMdevctlStopCommand(const char *uuid,
char **errmsg);
+virCommand *
+nodeDeviceGetMdevctlUndefineCommand(const char *uuid,
+ char **errmsg);
+
virCommandPtr
nodeDeviceGetMdevctlListCommand(bool defined,
char **output,
.nodeDeviceCreateXML = nodeDeviceCreateXML, /* 0.7.3 */
.nodeDeviceDestroy = nodeDeviceDestroy, /* 0.7.3 */
.nodeDeviceDefineXML = nodeDeviceDefineXML, /* 7.2.0 */
+ .nodeDeviceUndefine = nodeDeviceUndefine, /* 7.2.0 */
};
.nodeDeviceListCaps = remoteNodeDeviceListCaps, /* 0.5.0 */
.nodeDeviceCreateXML = remoteNodeDeviceCreateXML, /* 0.6.3 */
.nodeDeviceDefineXML = remoteNodeDeviceDefineXML, /* 7.2.0 */
+ .nodeDeviceUndefine = remoteNodeDeviceUndefine, /* 7.2.0 */
.nodeDeviceDestroy = remoteNodeDeviceDestroy /* 0.6.3 */
};
remote_nonnull_node_device dev;
};
+struct remote_node_device_undefine_args {
+ remote_nonnull_string name;
+};
+
/*
* Events Register/Deregister:
* @generate: both
* @acl: node_device:write
*/
- REMOTE_PROC_NODE_DEVICE_DEFINE_XML = 428
+ REMOTE_PROC_NODE_DEVICE_DEFINE_XML = 428,
+
+ /**
+ * @generate: both
+ * @priority: high
+ * @acl: node_device:delete
+ */
+ REMOTE_PROC_NODE_DEVICE_UNDEFINE = 429
+
};
struct remote_node_device_define_xml_ret {
remote_nonnull_node_device dev;
};
+struct remote_node_device_undefine_args {
+ remote_nonnull_string name;
+};
struct remote_connect_domain_event_register_ret {
int cb_registered;
};
REMOTE_PROC_DOMAIN_GET_MESSAGES = 426,
REMOTE_PROC_DOMAIN_START_DIRTY_RATE_CALC = 427,
REMOTE_PROC_NODE_DEVICE_DEFINE_XML = 428,
+ REMOTE_PROC_NODE_DEVICE_UNDEFINE = 429,
};
--- /dev/null
+$MDEVCTL_BINARY$ undefine -u d76a6b78-45ed-4149-a325-005f9abc5281
if (info->command == MDEVCTL_CMD_STOP) {
cmd = "stop";
func = nodeDeviceGetMdevctlStopCommand;
+ } else if (info->command == MDEVCTL_CMD_UNDEFINE) {
+ cmd = "undefine";
+ func = nodeDeviceGetMdevctlUndefineCommand;
} else {
return -1;
}
#define DO_TEST_STOP(uuid) \
DO_TEST_UUID_COMMAND_FULL("mdevctl stop " uuid, uuid, MDEVCTL_CMD_STOP)
+#define DO_TEST_UNDEFINE(uuid) \
+ DO_TEST_UUID_COMMAND_FULL("mdevctl undefine " uuid, uuid, MDEVCTL_CMD_UNDEFINE)
+
#define DO_TEST_LIST_DEFINED() \
DO_TEST_FULL("mdevctl list --defined", testMdevctlListDefined, NULL)
DO_TEST_DEFINE("mdev_fedc4916_1ca8_49ac_b176_871d16c13076");
DO_TEST_DEFINE("mdev_d2441d39_495e_4243_ad9f_beb3f14c23d9");
+ DO_TEST_UNDEFINE("d76a6b78-45ed-4149-a325-005f9abc5281");
+
done:
nodedevTestDriverFree(driver);