Signed-off-by: Daniel P. Berrangé <berrange@xxxxxxxxxx> --- src/admin/admin_server.c | 204 ++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 119 deletions(-) diff --git a/src/admin/admin_server.c b/src/admin/admin_server.c index 0d6091937d..ba87f701c3 100644 --- a/src/admin/admin_server.c +++ b/src/admin/admin_server.c @@ -75,15 +75,13 @@ adminServerGetThreadPoolParameters(virNetServerPtr srv, int *nparams, unsigned int flags) { - int ret = -1; - int maxparams = 0; size_t minWorkers; size_t maxWorkers; size_t nWorkers; size_t freeWorkers; size_t nPrioWorkers; size_t jobQueueDepth; - virTypedParameterPtr tmpparams = NULL; + g_autoptr(virTypedParamList) paramlist = g_new0(virTypedParamList, 1); virCheckFlags(0, -1); @@ -93,46 +91,36 @@ adminServerGetThreadPoolParameters(virNetServerPtr srv, &jobQueueDepth) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Unable to retrieve threadpool parameters")); - goto cleanup; + return -1; } - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_MIN, - minWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, minWorkers, + "%s", VIR_THREADPOOL_WORKERS_MIN) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_MAX, - maxWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, maxWorkers, + "%s", VIR_THREADPOOL_WORKERS_MAX) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_CURRENT, - nWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, nWorkers, + "%s", VIR_THREADPOOL_WORKERS_CURRENT) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_FREE, - freeWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, freeWorkers, + "%s", VIR_THREADPOOL_WORKERS_FREE) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_WORKERS_PRIORITY, - nPrioWorkers) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, nPrioWorkers, + "%s", VIR_THREADPOOL_WORKERS_PRIORITY) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, - &maxparams, VIR_THREADPOOL_JOB_QUEUE_DEPTH, - jobQueueDepth) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, jobQueueDepth, + "%s", VIR_THREADPOOL_JOB_QUEUE_DEPTH) < 0) + return -1; - *params = tmpparams; - tmpparams = NULL; - ret = 0; + *nparams = virTypedParamListStealParams(paramlist, params); - cleanup: - virTypedParamsFree(tmpparams, *nparams); - return ret; + return 0; } int @@ -215,106 +203,90 @@ adminClientGetInfo(virNetServerClientPtr client, int *nparams, unsigned int flags) { - int ret = -1; - int maxparams = 0; bool readonly; - char *sock_addr = NULL; + g_autofree char *sock_addr = NULL; const char *attr = NULL; - virTypedParameterPtr tmpparams = NULL; - virIdentityPtr identity = NULL; + g_autoptr(virTypedParamList) paramlist = g_new0(virTypedParamList, 1); + g_autoptr(virIdentity) identity = NULL; int rc; virCheckFlags(0, -1); if (virNetServerClientGetInfo(client, &readonly, &sock_addr, &identity) < 0) - goto cleanup; + return -1; - if (virTypedParamsAddBoolean(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_READONLY, - readonly) < 0) - goto cleanup; + if (virTypedParamListAddBoolean(paramlist, readonly, + "%s", VIR_CLIENT_INFO_READONLY) < 0) + return -1; if ((rc = virIdentityGetSASLUserName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_SASL_USER_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_SASL_USER_NAME) < 0) + return -1; if (!virNetServerClientIsLocal(client)) { - if (virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_SOCKET_ADDR, - sock_addr) < 0) - goto cleanup; + if (virTypedParamListAddString(paramlist, sock_addr, + "%s", VIR_CLIENT_INFO_SOCKET_ADDR) < 0) + return -1; if ((rc = virIdentityGetX509DName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_X509_DISTINGUISHED_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_X509_DISTINGUISHED_NAME) < 0) + return -1; } else { pid_t pid; uid_t uid; gid_t gid; if ((rc = virIdentityGetUNIXUserID(identity, &uid)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddInt(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_USER_ID, uid) < 0) - goto cleanup; + virTypedParamListAddInt(paramlist, uid, + "%s", VIR_CLIENT_INFO_UNIX_USER_ID) < 0) + return -1; if ((rc = virIdentityGetUserName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_USER_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_UNIX_USER_NAME) < 0) + return -1; if ((rc = virIdentityGetUNIXGroupID(identity, &gid)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddInt(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_GROUP_ID, gid) < 0) - goto cleanup; + virTypedParamListAddInt(paramlist, gid, + "%s", VIR_CLIENT_INFO_UNIX_GROUP_ID) < 0) + return -1; if ((rc = virIdentityGetGroupName(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_GROUP_NAME, - attr) < 0) - goto cleanup; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_UNIX_GROUP_NAME) < 0) + return -1; if ((rc = virIdentityGetProcessID(identity, &pid)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddInt(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_UNIX_PROCESS_ID, pid) < 0) - goto cleanup; + virTypedParamListAddInt(paramlist, pid, + "%s", VIR_CLIENT_INFO_UNIX_PROCESS_ID) < 0) + return -1; } if ((rc = virIdentityGetSELinuxContext(identity, &attr)) < 0) - goto cleanup; + return -1; if (rc == 1 && - virTypedParamsAddString(&tmpparams, nparams, &maxparams, - VIR_CLIENT_INFO_SELINUX_CONTEXT, attr) < 0) - goto cleanup; - - *params = tmpparams; - tmpparams = NULL; - ret = 0; + virTypedParamListAddString(paramlist, attr, + "%s", VIR_CLIENT_INFO_SELINUX_CONTEXT) < 0) + return -1; - cleanup: - if (tmpparams) - virTypedParamsFree(tmpparams, *nparams); - virObjectUnref(identity); - VIR_FREE(sock_addr); - return ret; + *nparams = virTypedParamListStealParams(paramlist, params); + return 0; } int adminClientClose(virNetServerClientPtr client, @@ -332,39 +304,33 @@ adminServerGetClientLimits(virNetServerPtr srv, int *nparams, unsigned int flags) { - int ret = -1; - int maxparams = 0; - virTypedParameterPtr tmpparams = NULL; + g_autoptr(virTypedParamList) paramlist = g_new0(virTypedParamList, 1); virCheckFlags(0, -1); - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_MAX, - virNetServerGetMaxClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetMaxClients(srv), + "%s", VIR_SERVER_CLIENTS_MAX) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_CURRENT, - virNetServerGetCurrentClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetCurrentClients(srv), + "%s", VIR_SERVER_CLIENTS_CURRENT) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_UNAUTH_MAX, - virNetServerGetMaxUnauthClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetMaxUnauthClients(srv), + "%s", VIR_SERVER_CLIENTS_UNAUTH_MAX) < 0) + return -1; - if (virTypedParamsAddUInt(&tmpparams, nparams, &maxparams, - VIR_SERVER_CLIENTS_UNAUTH_CURRENT, - virNetServerGetCurrentUnauthClients(srv)) < 0) - goto cleanup; + if (virTypedParamListAddUInt(paramlist, + virNetServerGetCurrentUnauthClients(srv), + "%s", VIR_SERVER_CLIENTS_UNAUTH_CURRENT) < 0) + return -1; - *params = tmpparams; - tmpparams = NULL; - ret = 0; + *nparams = virTypedParamListStealParams(paramlist, params); - cleanup: - virTypedParamsFree(tmpparams, *nparams); - return ret; + return 0; } int -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list