From 17fd00888a4c3f60c547589cd6f1e44159028c37 Mon Sep 17 00:00:00 2001 From: Osier Yang Date: Tue, 4 Sep 2012 23:16:26 +0800 Subject: [PATCH] list: Implement the RPC calls for virConnectListAllStoragePools The RPC generator doesn't support returning list of object, this patch does the work manually. * daemon/remote.c: Implement the server side handler remoteDispatchConnectListAllStoragePools * src/remote/remote_driver.c: Add remote driver handler remoteConnectListAllStoragePools. * src/remote/remote_protocol.x: New RPC procedure REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS and structs to represent the args and ret for it. * src/remote_protocol-structs: Likewise. --- daemon/remote.c | 54 ++++++++++++++++++++++++++++++ src/remote/remote_driver.c | 64 ++++++++++++++++++++++++++++++++++++ src/remote/remote_protocol.x | 13 +++++++- src/remote_protocol-structs | 12 +++++++ 4 files changed, 142 insertions(+), 1 deletion(-) diff --git a/daemon/remote.c b/daemon/remote.c index 24928f49a2..90564399a5 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -4099,6 +4099,60 @@ cleanup: return rv; } +static int +remoteDispatchConnectListAllStoragePools(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr, + remote_connect_list_all_storage_pools_args *args, + remote_connect_list_all_storage_pools_ret *ret) +{ + virStoragePoolPtr *pools = NULL; + int npools = 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 ((npools = virConnectListAllStoragePools(priv->conn, + args->need_results ? &pools : NULL, + args->flags)) < 0) + goto cleanup; + + if (pools && npools) { + if (VIR_ALLOC_N(ret->pools.pools_val, npools) < 0) { + virReportOOMError(); + goto cleanup; + } + + ret->pools.pools_len = npools; + + for (i = 0; i < npools; i++) + make_nonnull_storage_pool(ret->pools.pools_val + i, pools[i]); + } else { + ret->pools.pools_len = 0; + ret->pools.pools_val = NULL; + } + + ret->ret = npools; + + rv = 0; + +cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + if (pools) { + for (i = 0; i < npools; i++) + virStoragePoolFree(pools[i]); + VIR_FREE(pools); + } + return rv; +} + /*----- Helpers. -----*/ /* get_nonnull_domain and get_nonnull_network turn an on-wire diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index cf1f079be4..b11840e961 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2857,6 +2857,69 @@ done: return rv; } +static int +remoteConnectListAllStoragePools (virConnectPtr conn, + virStoragePoolPtr **pools, + unsigned int flags) +{ + int rv = -1; + int i; + virStoragePoolPtr *tmp_pools = NULL; + remote_connect_list_all_storage_pools_args args; + remote_connect_list_all_storage_pools_ret ret; + + struct private_data *priv = conn->privateData; + + remoteDriverLock(priv); + + args.need_results = !!pools; + args.flags = flags; + + memset(&ret, 0, sizeof(ret)); + if (call(conn, + priv, + 0, + REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS, + (xdrproc_t) xdr_remote_connect_list_all_storage_pools_args, + (char *) &args, + (xdrproc_t) xdr_remote_connect_list_all_storage_pools_ret, + (char *) &ret) == -1) + goto done; + + if (pools) { + if (VIR_ALLOC_N(tmp_pools, ret.pools.pools_len + 1) < 0) { + virReportOOMError(); + goto cleanup; + } + + for (i = 0; i < ret.pools.pools_len; i++) { + tmp_pools[i] = get_nonnull_storage_pool(conn, ret.pools.pools_val[i]); + if (!tmp_pools[i]) { + virReportOOMError(); + goto cleanup; + } + } + *pools = tmp_pools; + tmp_pools = NULL; + } + + rv = ret.ret; + +cleanup: + if (tmp_pools) { + for (i = 0; i < ret.pools.pools_len; i++) + if (tmp_pools[i]) + virStoragePoolFree(tmp_pools[i]); + VIR_FREE(tmp_pools); + } + + xdr_free((xdrproc_t) xdr_remote_connect_list_all_storage_pools_ret, (char *) &ret); + +done: + remoteDriverUnlock(priv); + return rv; +} + /*----------------------------------------------------------------------*/ static virDrvOpenStatus ATTRIBUTE_NONNULL (1) @@ -5612,6 +5675,7 @@ static virStorageDriver storage_driver = { .listPools = remoteListStoragePools, /* 0.4.1 */ .numOfDefinedPools = remoteNumOfDefinedStoragePools, /* 0.4.1 */ .listDefinedPools = remoteListDefinedStoragePools, /* 0.4.1 */ + .listAllPools = remoteConnectListAllStoragePools, /* 0.10.2 */ .findPoolSources = remoteFindStoragePoolSources, /* 0.4.5 */ .poolLookupByName = remoteStoragePoolLookupByName, /* 0.4.1 */ .poolLookupByUUID = remoteStoragePoolLookupByUUID, /* 0.4.1 */ diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x index 085d5d944e..9de3404dcf 100644 --- a/src/remote/remote_protocol.x +++ b/src/remote/remote_protocol.x @@ -2558,6 +2558,15 @@ struct remote_connect_list_all_domains_ret { unsigned int ret; }; +struct remote_connect_list_all_storage_pools_args { + int need_results; + unsigned int flags; +}; + +struct remote_connect_list_all_storage_pools_ret { + remote_nonnull_storage_pool pools<>; + unsigned int ret; +}; /*----- Protocol. -----*/ @@ -2888,7 +2897,9 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_HOSTNAME = 277, /* autogen autogen */ REMOTE_PROC_DOMAIN_GET_SECURITY_LABEL_LIST = 278, /* skipgen skipgen priority:high */ REMOTE_PROC_DOMAIN_PIN_EMULATOR = 279, /* skipgen skipgen */ - REMOTE_PROC_DOMAIN_GET_EMULATOR_PIN_INFO = 280 /* skipgen skipgen */ + REMOTE_PROC_DOMAIN_GET_EMULATOR_PIN_INFO = 280, /* skipgen skipgen */ + + REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 281 /* skipgen skipgen priority:high */ /* * Notice how the entries are grouped in sets of 10 ? diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs index ed40ccb69f..617c202e4b 100644 --- a/src/remote_protocol-structs +++ b/src/remote_protocol-structs @@ -2011,6 +2011,17 @@ struct remote_connect_list_all_domains_ret { } domains; u_int ret; }; +struct remote_connect_list_all_storage_pools_args { + int need_results; + u_int flags; +}; +struct remote_connect_list_all_storage_pools_ret { + struct { + u_int pools_len; + remote_nonnull_storage_pool * pools_val; + } pools; + u_int ret; +}; enum remote_procedure { REMOTE_PROC_OPEN = 1, REMOTE_PROC_CLOSE = 2, @@ -2292,4 +2303,5 @@ enum remote_procedure { REMOTE_PROC_DOMAIN_GET_SECURITY_LABEL_LIST = 278, REMOTE_PROC_DOMAIN_PIN_EMULATOR = 279, REMOTE_PROC_DOMAIN_GET_EMULATOR_PIN_INFO = 280, + REMOTE_PROC_CONNECT_LIST_ALL_STORAGE_POOLS = 281, }; -- GitLab