As previously discussed, Dave Allen's reworking the NPIV patches to
do creation/deleation of vports via the node device APIs. Thus, this
patch adds the 2 new APIs required for this approach.
Daniel
diff -r 2d1278bdf31f include/libvirt/libvirt.h
--- a/include/libvirt/libvirt.h Fri Apr 24 11:01:11 2009 +0100
+++ b/include/libvirt/libvirt.h Fri Apr 24 13:06:12 2009 +0100
@@ -1124,6 +1124,12 @@ int virNodeDeviceDet
int virNodeDeviceReAttach (virNodeDevicePtr dev);
int virNodeDeviceReset (virNodeDevicePtr dev);
+virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags);
+
+int virNodeDeviceDestroy (virNodeDevicePtr dev);
+
/*
* Domain Event Notification
*/
diff -r 2d1278bdf31f include/libvirt/libvirt.h.in
--- a/include/libvirt/libvirt.h.in Fri Apr 24 11:01:11 2009 +0100
+++ b/include/libvirt/libvirt.h.in Fri Apr 24 13:06:12 2009 +0100
@@ -1124,6 +1124,12 @@ int virNodeDeviceDet
int virNodeDeviceReAttach (virNodeDevicePtr dev);
int virNodeDeviceReset (virNodeDevicePtr dev);
+virNodeDevicePtr virNodeDeviceCreateXML (virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags);
+
+int virNodeDeviceDestroy (virNodeDevicePtr dev);
+
/*
* Domain Event Notification
*/
diff -r 2d1278bdf31f qemud/remote.c
--- a/qemud/remote.c Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote.c Fri Apr 24 13:06:12 2009 +0100
@@ -4323,6 +4323,54 @@ remoteDispatchNodeDeviceReset (struct qe
}
+static int
+remoteDispatchNodeDeviceCreateXml(struct qemud_server *server ATTRIBUTE_UNUSED,
+ struct qemud_client *client ATTRIBUTE_UNUSED,
+ virConnectPtr conn,
+ remote_error *rerr,
+ remote_node_device_create_xml_args *args,
+ remote_node_device_create_xml_ret *ret)
+{
+ virNodeDevicePtr dev;
+
+ dev = virNodeDeviceCreateXML (conn, args->xml_desc, args->flags);
+ if (dev == NULL) {
+ remoteDispatchConnError(rerr, conn);
+ return -1;
+ }
+
+ make_nonnull_node_device (&ret->dev, dev);
+ virNodeDeviceFree(dev);
+
+ return 0;
+}
+
+
+static int
+remoteDispatchNodeDeviceDestroy(struct qemud_server *server ATTRIBUTE_UNUSED,
+ struct qemud_client *client ATTRIBUTE_UNUSED,
+ virConnectPtr conn,
+ remote_error *rerr,
+ remote_node_device_destroy_args *args,
+ void *ret ATTRIBUTE_UNUSED)
+{
+ virNodeDevicePtr dev;
+
+ dev = virNodeDeviceLookupByName(conn, args->name);
+ if (dev == NULL) {
+ remoteDispatchFormatError(rerr, "%s", _("node_device not
found"));
+ return -1;
+ }
+
+ if (virNodeDeviceDestroy(dev) == -1) {
+ remoteDispatchConnError(rerr, conn);
+ return -1;
+ }
+
+ return 0;
+}
+
+
/**************************
* Async Events
**************************/
diff -r 2d1278bdf31f qemud/remote_dispatch_args.h
--- a/qemud/remote_dispatch_args.h Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_dispatch_args.h Fri Apr 24 13:06:12 2009 +0100
@@ -103,3 +103,5 @@
remote_node_device_re_attach_args val_remote_node_device_re_attach_args;
remote_node_device_reset_args val_remote_node_device_reset_args;
remote_domain_get_security_label_args val_remote_domain_get_security_label_args;
+ remote_node_device_create_xml_args val_remote_node_device_create_xml_args;
+ remote_node_device_destroy_args val_remote_node_device_destroy_args;
diff -r 2d1278bdf31f qemud/remote_dispatch_prototypes.h
--- a/qemud/remote_dispatch_prototypes.h Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_dispatch_prototypes.h Fri Apr 24 13:06:12 2009 +0100
@@ -527,6 +527,20 @@ static int remoteDispatchNetworkUndefine
remote_error *err,
remote_network_undefine_args *args,
void *ret);
+static int remoteDispatchNodeDeviceCreateXml(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_error *err,
+ remote_node_device_create_xml_args *args,
+ remote_node_device_create_xml_ret *ret);
+static int remoteDispatchNodeDeviceDestroy(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_error *err,
+ remote_node_device_destroy_args *args,
+ void *ret);
static int remoteDispatchNodeDeviceDettach(
struct qemud_server *server,
struct qemud_client *client,
diff -r 2d1278bdf31f qemud/remote_dispatch_ret.h
--- a/qemud/remote_dispatch_ret.h Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_dispatch_ret.h Fri Apr 24 13:06:12 2009 +0100
@@ -88,3 +88,4 @@
remote_node_device_list_caps_ret val_remote_node_device_list_caps_ret;
remote_domain_get_security_label_ret val_remote_domain_get_security_label_ret;
remote_node_get_security_model_ret val_remote_node_get_security_model_ret;
+ remote_node_device_create_xml_ret val_remote_node_device_create_xml_ret;
diff -r 2d1278bdf31f qemud/remote_dispatch_table.h
--- a/qemud/remote_dispatch_table.h Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_dispatch_table.h Fri Apr 24 13:06:12 2009 +0100
@@ -607,13 +607,23 @@
.args_filter = (xdrproc_t) xdr_remote_node_device_reset_args,
.ret_filter = (xdrproc_t) xdr_void,
},
-{ /* DomainGetSecurityLabel => 118 */
+{ /* DomainGetSecurityLabel => 121 */
.fn = (dispatch_fn) remoteDispatchDomainGetSecurityLabel,
.args_filter = (xdrproc_t) xdr_remote_domain_get_security_label_args,
.ret_filter = (xdrproc_t) xdr_remote_domain_get_security_label_ret,
},
-{ /* NodeGetSecurityModel => 119 */
+{ /* NodeGetSecurityModel => 122 */
.fn = (dispatch_fn) remoteDispatchNodeGetSecurityModel,
.args_filter = (xdrproc_t) xdr_void,
.ret_filter = (xdrproc_t) xdr_remote_node_get_security_model_ret,
},
+{ /* NodeDeviceCreateXml => 123 */
+ .fn = (dispatch_fn) remoteDispatchNodeDeviceCreateXml,
+ .args_filter = (xdrproc_t) xdr_remote_node_device_create_xml_args,
+ .ret_filter = (xdrproc_t) xdr_remote_node_device_create_xml_ret,
+},
+{ /* NodeDeviceDestroy => 124 */
+ .fn = (dispatch_fn) remoteDispatchNodeDeviceDestroy,
+ .args_filter = (xdrproc_t) xdr_remote_node_device_destroy_args,
+ .ret_filter = (xdrproc_t) xdr_void,
+},
diff -r 2d1278bdf31f qemud/remote_protocol.c
--- a/qemud/remote_protocol.c Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_protocol.c Fri Apr 24 13:06:12 2009 +0100
@@ -2230,6 +2230,35 @@ xdr_remote_node_device_reset_args (XDR *
}
bool_t
+xdr_remote_node_device_create_xml_args (XDR *xdrs, remote_node_device_create_xml_args
*objp)
+{
+
+ if (!xdr_remote_nonnull_string (xdrs, &objp->xml_desc))
+ return FALSE;
+ if (!xdr_int (xdrs, &objp->flags))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_remote_node_device_create_xml_ret (XDR *xdrs, remote_node_device_create_xml_ret
*objp)
+{
+
+ if (!xdr_remote_nonnull_node_device (xdrs, &objp->dev))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_remote_node_device_destroy_args (XDR *xdrs, remote_node_device_destroy_args *objp)
+{
+
+ if (!xdr_remote_nonnull_string (xdrs, &objp->name))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_remote_domain_events_register_ret (XDR *xdrs, remote_domain_events_register_ret
*objp)
{
diff -r 2d1278bdf31f qemud/remote_protocol.h
--- a/qemud/remote_protocol.h Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_protocol.h Fri Apr 24 13:06:12 2009 +0100
@@ -1255,6 +1255,22 @@ struct remote_node_device_reset_args {
};
typedef struct remote_node_device_reset_args remote_node_device_reset_args;
+struct remote_node_device_create_xml_args {
+ remote_nonnull_string xml_desc;
+ int flags;
+};
+typedef struct remote_node_device_create_xml_args remote_node_device_create_xml_args;
+
+struct remote_node_device_create_xml_ret {
+ remote_nonnull_node_device dev;
+};
+typedef struct remote_node_device_create_xml_ret remote_node_device_create_xml_ret;
+
+struct remote_node_device_destroy_args {
+ remote_nonnull_string name;
+};
+typedef struct remote_node_device_destroy_args remote_node_device_destroy_args;
+
struct remote_domain_events_register_ret {
int cb_registered;
};
@@ -1397,6 +1413,8 @@ enum remote_procedure {
REMOTE_PROC_NODE_DEVICE_RESET = 120,
REMOTE_PROC_DOMAIN_GET_SECURITY_LABEL = 121,
REMOTE_PROC_NODE_GET_SECURITY_MODEL = 122,
+ REMOTE_PROC_NODE_DEVICE_CREATE_XML = 123,
+ REMOTE_PROC_NODE_DEVICE_DESTROY = 124,
};
typedef enum remote_procedure remote_procedure;
@@ -1629,6 +1647,9 @@ extern bool_t xdr_remote_node_device_li
extern bool_t xdr_remote_node_device_dettach_args (XDR *,
remote_node_device_dettach_args*);
extern bool_t xdr_remote_node_device_re_attach_args (XDR *,
remote_node_device_re_attach_args*);
extern bool_t xdr_remote_node_device_reset_args (XDR *,
remote_node_device_reset_args*);
+extern bool_t xdr_remote_node_device_create_xml_args (XDR *,
remote_node_device_create_xml_args*);
+extern bool_t xdr_remote_node_device_create_xml_ret (XDR *,
remote_node_device_create_xml_ret*);
+extern bool_t xdr_remote_node_device_destroy_args (XDR *,
remote_node_device_destroy_args*);
extern bool_t xdr_remote_domain_events_register_ret (XDR *,
remote_domain_events_register_ret*);
extern bool_t xdr_remote_domain_events_deregister_ret (XDR *,
remote_domain_events_deregister_ret*);
extern bool_t xdr_remote_domain_event_ret (XDR *, remote_domain_event_ret*);
@@ -1840,6 +1861,9 @@ extern bool_t xdr_remote_node_device_lis
extern bool_t xdr_remote_node_device_dettach_args ();
extern bool_t xdr_remote_node_device_re_attach_args ();
extern bool_t xdr_remote_node_device_reset_args ();
+extern bool_t xdr_remote_node_device_create_xml_args ();
+extern bool_t xdr_remote_node_device_create_xml_ret ();
+extern bool_t xdr_remote_node_device_destroy_args ();
extern bool_t xdr_remote_domain_events_register_ret ();
extern bool_t xdr_remote_domain_events_deregister_ret ();
extern bool_t xdr_remote_domain_event_ret ();
diff -r 2d1278bdf31f qemud/remote_protocol.x
--- a/qemud/remote_protocol.x Fri Apr 24 11:01:11 2009 +0100
+++ b/qemud/remote_protocol.x Fri Apr 24 13:06:12 2009 +0100
@@ -1109,6 +1109,19 @@ struct remote_node_device_reset_args {
remote_nonnull_string name;
};
+struct remote_node_device_create_xml_args {
+ remote_nonnull_string xml_desc;
+ int flags;
+};
+
+struct remote_node_device_create_xml_ret {
+ remote_nonnull_node_device dev;
+};
+
+struct remote_node_device_destroy_args {
+ remote_nonnull_string name;
+};
+
/**
* Events Register/Deregister:
@@ -1270,7 +1283,10 @@ enum remote_procedure {
REMOTE_PROC_NODE_DEVICE_RESET = 120,
REMOTE_PROC_DOMAIN_GET_SECURITY_LABEL = 121,
- REMOTE_PROC_NODE_GET_SECURITY_MODEL = 122
+ REMOTE_PROC_NODE_GET_SECURITY_MODEL = 122,
+
+ REMOTE_PROC_NODE_DEVICE_CREATE_XML = 123,
+ REMOTE_PROC_NODE_DEVICE_DESTROY = 124
};
/* Custom RPC structure. */
diff -r 2d1278bdf31f src/driver.h
--- a/src/driver.h Fri Apr 24 11:01:11 2009 +0100
+++ b/src/driver.h Fri Apr 24 13:06:12 2009 +0100
@@ -684,6 +684,11 @@ typedef int (*virDevMonDeviceListCaps)(v
char **const names,
int maxnames);
+typedef virNodeDevicePtr (*virDrvNodeDeviceCreateXML)(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags);
+typedef int (*virDrvNodeDeviceDestroy)(virNodeDevicePtr dev);
+
/**
* _virDeviceMonitor:
*
@@ -702,6 +707,8 @@ struct _virDeviceMonitor {
virDevMonDeviceGetParent deviceGetParent;
virDevMonDeviceNumOfCaps deviceNumOfCaps;
virDevMonDeviceListCaps deviceListCaps;
+ virDrvNodeDeviceCreateXML deviceCreateXML;
+ virDrvNodeDeviceDestroy deviceDestroy;
};
/*
diff -r 2d1278bdf31f src/libvirt.c
--- a/src/libvirt.c Fri Apr 24 11:01:11 2009 +0100
+++ b/src/libvirt.c Fri Apr 24 13:06:12 2009 +0100
@@ -7491,6 +7491,103 @@ error:
}
+/**
+ * virNodeDeviceCreateXML:
+ * @conn: pointer to the hypervisor connection
+ * @xmlDesc: string containing an XML description of the device to be created
+ * @flags: callers should always pass 0
+ *
+ * Create a new device on the VM host machine, for example, virtual
+ * HBAs created using vport_create.
+ *
+ * Returns a node device object if successful, NULL in case of failure
+ */
+virNodeDevicePtr
+virNodeDeviceCreateXML(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags)
+{
+ VIR_DEBUG("conn=%p, xmlDesc=%s, flags=%d", conn, xmlDesc, flags);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECT(conn)) {
+ virLibConnError(NULL, VIR_ERR_INVALID_CONN, __FUNCTION__);
+ return NULL;
+ }
+
+ if (conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+
+ if (xmlDesc == NULL) {
+ virLibConnError(conn, VIR_ERR_INVALID_ARG, __FUNCTION__);
+ goto error;
+ }
+
+ if (conn->deviceMonitor->deviceCreateXML) {
+ virNodeDevicePtr dev = conn->deviceMonitor->deviceCreateXML(conn, xmlDesc,
flags);
+ if (dev == NULL)
+ goto error;
+ return dev;
+ }
+
+ virLibConnError (conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(conn);
+ return NULL;
+}
+
+
+/**
+ * virNodeDeviceDestroy:
+ * @dev: a device object
+ *
+ * Destroy 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
+virNodeDeviceDestroy(virNodeDevicePtr dev)
+{
+ int retval = 0;
+
+ DEBUG("dev=%p", dev);
+
+ virResetLastError();
+
+ if (!VIR_IS_CONNECTED_NODE_DEVICE(dev)) {
+ virLibNodeDeviceError(NULL, VIR_ERR_INVALID_NODE_DEVICE, __FUNCTION__);
+ return (-1);
+ }
+
+ if (dev->conn->flags & VIR_CONNECT_RO) {
+ virLibConnError(dev->conn, VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+ goto error;
+ }
+
+ if (dev->conn->deviceMonitor->deviceDestroy) {
+ retval = dev->conn->deviceMonitor->deviceDestroy(dev);
+ if (retval < 0) {
+ goto error;
+ }
+
+ return 0;
+ }
+
+ virLibConnError (dev->conn, VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+ /* Copy to connection error object for back compatability */
+ virSetConnError(dev->conn);
+ return -1;
+}
+
+
/*
* Domain Event Notification
*/
diff -r 2d1278bdf31f src/libvirt_public.syms
--- a/src/libvirt_public.syms Fri Apr 24 11:01:11 2009 +0100
+++ b/src/libvirt_public.syms Fri Apr 24 13:06:12 2009 +0100
@@ -258,4 +258,10 @@ LIBVIRT_0.6.1 {
virNodeGetSecurityModel;
} LIBVIRT_0.6.0;
+LIBVIRT_0.6.3 {
+ global:
+ virNodeDeviceCreateXML;
+ virNodeDeviceDestroy;
+} LIBVIRT_0.6.1;
+
# .... define new API here using predicted next version number ....
diff -r 2d1278bdf31f src/remote_internal.c
--- a/src/remote_internal.c Fri Apr 24 11:01:11 2009 +0100
+++ b/src/remote_internal.c Fri Apr 24 13:06:12 2009 +0100
@@ -4987,6 +4987,59 @@ done:
}
+static virNodeDevicePtr
+remoteNodeDeviceCreateXML(virConnectPtr conn,
+ const char *xmlDesc,
+ unsigned int flags)
+{
+ remote_node_device_create_xml_args args;
+ remote_node_device_create_xml_ret ret;
+ virNodeDevicePtr dev = NULL;
+ struct private_data *priv = conn->privateData;
+
+ remoteDriverLock(priv);
+
+ memset(&ret, 0, sizeof ret);
+ args.xml_desc = (char *)xmlDesc;
+ args.flags = flags;
+
+ if (call(conn, priv, 0, REMOTE_PROC_NODE_DEVICE_CREATE_XML,
+ (xdrproc_t) xdr_remote_node_device_create_xml_args, (char *) &args,
+ (xdrproc_t) xdr_remote_node_device_create_xml_ret, (char *) &ret) ==
-1)
+ goto done;
+
+ dev = get_nonnull_node_device(conn, ret.dev);
+ xdr_free ((xdrproc_t) xdr_remote_node_device_create_xml_ret, (char *) &ret);
+
+done:
+ remoteDriverUnlock(priv);
+ return dev;
+}
+
+static int
+remoteNodeDeviceDestroy(virNodeDevicePtr dev)
+{
+ int rv = -1;
+ remote_node_device_destroy_args args;
+ struct private_data *priv = dev->conn->privateData;
+
+ remoteDriverLock(priv);
+
+ args.name = dev->name;
+
+ if (call(dev->conn, priv, 0, REMOTE_PROC_NODE_DEVICE_RESET,
+ (xdrproc_t) xdr_remote_node_device_destroy_args, (char *) &args,
+ (xdrproc_t) xdr_void, (char *) NULL) == -1)
+ goto done;
+
+ rv = 0;
+
+done:
+ remoteDriverUnlock(priv);
+ return rv;
+}
+
+
/*----------------------------------------------------------------------*/
static int
@@ -6991,6 +7044,8 @@ static virDeviceMonitor dev_monitor = {
.deviceGetParent = remoteNodeDeviceGetParent,
.deviceNumOfCaps = remoteNodeDeviceNumOfCaps,
.deviceListCaps = remoteNodeDeviceListCaps,
+ .deviceCreateXML = remoteNodeDeviceCreateXML,
+ .deviceDestroy = remoteNodeDeviceDestroy
};
--
|: Red Hat, Engineering, London -o-
http://people.redhat.com/berrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org -o-
http://ovirt.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|