list: Implement RPC calls for virConnectListAllNodeDevices

The RPC generator doesn't support returning list of object yet, this patch
does the work manually.

  * daemon/remote.c:
    Implemente the server side handler remoteDispatchConnectListAllNodeDevices.

  * src/remote/remote_driver.c:
    Add remote driver handler remoteConnectListAllNodeDevices.

  * src/remote/remote_protocol.x:
    New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES and
This commit is contained in:
Osier Yang 2012-09-05 13:34:08 +08:00
parent c6a3be5dff
commit 4230b6c102
4 changed files with 141 additions and 1 deletions

View File

@ -4321,6 +4321,59 @@ cleanup:
return rv;
}
static int
remoteDispatchConnectListAllNodeDevices(virNetServerPtr server ATTRIBUTE_UNUSED,
virNetServerClientPtr client,
virNetMessagePtr msg ATTRIBUTE_UNUSED,
virNetMessageErrorPtr rerr,
remote_connect_list_all_node_devices_args *args,
remote_connect_list_all_node_devices_ret *ret)
{
virNodeDevicePtr *devices = NULL;
int ndevices = 0;
int i;
int rv = -1;
struct daemonClientPrivate *priv = virNetServerClientGetPrivateData(client);
if (!priv->conn) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open"));
goto cleanup;
}
if ((ndevices = virConnectListAllNodeDevices(priv->conn,
args->need_results ? &devices : NULL,
args->flags)) < 0)
goto cleanup;
if (devices && ndevices) {
if (VIR_ALLOC_N(ret->devices.devices_val, ndevices) < 0) {
virReportOOMError();
goto cleanup;
}
ret->devices.devices_len = ndevices;
for (i = 0; i < ndevices; i++)
make_nonnull_node_device(ret->devices.devices_val + i, devices[i]);
} else {
ret->devices.devices_len = 0;
ret->devices.devices_val = NULL;
}
ret->ret = ndevices;
rv = 0;
cleanup:
if (rv < 0)
virNetMessageSaveError(rerr);
if (devices) {
for (i = 0; i < ndevices; i++)
virNodeDeviceFree(devices[i]);
VIR_FREE(devices);
}
return rv;
}
/*----- Helpers. -----*/

View File

@ -2844,6 +2844,69 @@ done:
return rv;
}
static int
remoteConnectListAllNodeDevices(virConnectPtr conn,
virNodeDevicePtr **devices,
unsigned int flags)
{
int rv = -1;
int i;
virNodeDevicePtr *tmp_devices = NULL;
remote_connect_list_all_node_devices_args args;
remote_connect_list_all_node_devices_ret ret;
struct private_data *priv = conn->privateData;
remoteDriverLock(priv);
args.need_results = !!devices;
args.flags = flags;
memset(&ret, 0, sizeof(ret));
if (call(conn,
priv,
0,
REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES,
(xdrproc_t) xdr_remote_connect_list_all_node_devices_args,
(char *) &args,
(xdrproc_t) xdr_remote_connect_list_all_node_devices_ret,
(char *) &ret) == -1)
goto done;
if (devices) {
if (VIR_ALLOC_N(tmp_devices, ret.devices.devices_len + 1) < 0) {
virReportOOMError();
goto cleanup;
}
for (i = 0; i < ret.devices.devices_len; i++) {
tmp_devices[i] = get_nonnull_node_device(conn, ret.devices.devices_val[i]);
if (!tmp_devices[i]) {
virReportOOMError();
goto cleanup;
}
}
*devices = tmp_devices;
tmp_devices = NULL;
}
rv = ret.ret;
cleanup:
if (tmp_devices) {
for (i = 0; i < ret.devices.devices_len; i++)
if (tmp_devices[i])
virNodeDeviceFree(tmp_devices[i]);
VIR_FREE(tmp_devices);
}
xdr_free((xdrproc_t) xdr_remote_connect_list_all_node_devices_ret, (char *) &ret);
done:
remoteDriverUnlock(priv);
return rv;
}
/*----------------------------------------------------------------------*/
@ -5937,6 +6000,7 @@ static virDeviceMonitor dev_monitor = {
.close = remoteDevMonClose, /* 0.5.0 */
.numOfDevices = remoteNodeNumOfDevices, /* 0.5.0 */
.listDevices = remoteNodeListDevices, /* 0.5.0 */
.listAllNodeDevices = remoteConnectListAllNodeDevices, /* 0.10.2 */
.deviceLookupByName = remoteNodeDeviceLookupByName, /* 0.5.0 */
.deviceGetXMLDesc = remoteNodeDeviceGetXMLDesc, /* 0.5.0 */
.deviceGetParent = remoteNodeDeviceGetParent, /* 0.5.0 */

View File

@ -2599,6 +2599,16 @@ struct remote_connect_list_all_interfaces_ret {
unsigned int ret;
};
struct remote_connect_list_all_node_devices_args {
int need_results;
unsigned int flags;
};
struct remote_connect_list_all_node_devices_ret {
remote_nonnull_node_device devices<>;
unsigned int ret;
};
/*----- Protocol. -----*/
/* Define the program number, protocol version and procedure numbers here. */
@ -2933,7 +2943,8 @@ enum remote_procedure {
REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 281, /* skipgen skipgen priority:high */
REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 282, /* skipgen skipgen priority:high */
REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 283, /* skipgen skipgen priority:high */
REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284 /* skipgen skipgen priority:high */
REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284, /* skipgen skipgen priority:high */
REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 285 /* skipgen skipgen priority:high */
/*
* Notice how the entries are grouped in sets of 10 ?

View File

@ -2056,6 +2056,17 @@ struct remote_connect_list_all_interfaces_ret {
} ifaces;
u_int ret;
};
struct remote_connect_list_all_node_devices_args {
int need_results;
u_int flags;
};
struct remote_connect_list_all_node_devices_ret {
struct {
u_int devices_len;
remote_nonnull_node_device * devices_val;
} devices;
u_int ret;
};
enum remote_procedure {
REMOTE_PROC_OPEN = 1,
REMOTE_PROC_CLOSE = 2,
@ -2341,4 +2352,5 @@ enum remote_procedure {
REMOTE_PROC_STORAGE_POOL_LIST_ALL_VOLUMES = 282,
REMOTE_PROC_CONNECT_LIST_ALL_NETWORKS = 283,
REMOTE_PROC_CONNECT_LIST_ALL_INTERFACES = 284,
REMOTE_PROC_CONNECT_LIST_ALL_NODE_DEVICES = 285,
};