admin: use VIR_LOCK_GUARD in client code

Using VIR_LOCK_GUARD enables the 'done' goto label to be
eliminated.

Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2022-12-22 10:29:32 -05:00
parent fda53ab3a5
commit 8ed7ef5d1a
1 changed files with 22 additions and 50 deletions

View File

@ -133,8 +133,7 @@ remoteAdminClientCloseFunc(virNetClient *client G_GNUC_UNUSED,
void *opaque)
{
virAdmConnectCloseCallbackData *cbdata = opaque;
virObjectLock(cbdata);
VIR_LOCK_GUARD lock = virObjectLockGuard(cbdata);
if (cbdata->callback) {
VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
@ -142,17 +141,14 @@ remoteAdminClientCloseFunc(virNetClient *client G_GNUC_UNUSED,
cbdata->callback(cbdata->conn, reason, cbdata->opaque);
virAdmConnectCloseCallbackDataReset(cbdata);
}
virObjectUnlock(cbdata);
}
static int
remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
{
int rv = -1;
remoteAdminPriv *priv = conn->privateData;
admin_connect_open_args args;
virObjectLock(priv);
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags & ~VIR_CONNECT_NO_ALIASES;
@ -169,40 +165,28 @@ remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
if (call(conn, 0, ADMIN_PROC_CONNECT_OPEN,
(xdrproc_t)xdr_admin_connect_open_args, (char *)&args,
(xdrproc_t)xdr_void, (char *)NULL) == -1) {
goto done;
}
(xdrproc_t)xdr_void, (char *)NULL) == -1)
return -1;
rv = 0;
done:
virObjectUnlock(priv);
return rv;
return 0;
}
static int
remoteAdminConnectClose(virAdmConnectPtr conn)
{
int rv = -1;
remoteAdminPriv *priv = conn->privateData;
virObjectLock(priv);
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
if (call(conn, 0, ADMIN_PROC_CONNECT_CLOSE,
(xdrproc_t)xdr_void, (char *)NULL,
(xdrproc_t)xdr_void, (char *)NULL) == -1) {
goto done;
}
(xdrproc_t)xdr_void, (char *)NULL) == -1)
return -1;
virNetClientSetCloseCallback(priv->client, NULL, conn->closeCallback,
virObjectUnref);
virNetClientClose(priv->client);
rv = 0;
done:
virObjectUnlock(priv);
return rv;
return 0;
}
static void
@ -249,17 +233,17 @@ remoteAdminServerGetThreadPoolParameters(virAdmServerPtr srv,
remoteAdminPriv *priv = srv->conn->privateData;
admin_server_get_threadpool_parameters_args args;
admin_server_get_threadpool_parameters_ret ret;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
make_nonnull_server(&args.srv, srv);
memset(&ret, 0, sizeof(ret));
virObjectLock(priv);
if (call(srv->conn, 0, ADMIN_PROC_SERVER_GET_THREADPOOL_PARAMETERS,
(xdrproc_t)xdr_admin_server_get_threadpool_parameters_args, (char *) &args,
(xdrproc_t)xdr_admin_server_get_threadpool_parameters_ret, (char *) &ret) == -1)
goto cleanup;
return -1;
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
ret.params.params_len,
@ -272,7 +256,6 @@ remoteAdminServerGetThreadPoolParameters(virAdmServerPtr srv,
cleanup:
xdr_free((xdrproc_t)xdr_admin_server_get_threadpool_parameters_ret, (char *) &ret);
virObjectUnlock(priv);
return rv;
}
@ -285,12 +268,11 @@ remoteAdminServerSetThreadPoolParameters(virAdmServerPtr srv,
int rv = -1;
remoteAdminPriv *priv = srv->conn->privateData;
admin_server_set_threadpool_parameters_args args;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
make_nonnull_server(&args.srv, srv);
virObjectLock(priv);
if (virTypedParamsSerialize(params, nparams,
ADMIN_SERVER_THREADPOOL_PARAMETERS_MAX,
(struct _virTypedParameterRemote **) &args.params.params_val,
@ -308,7 +290,6 @@ remoteAdminServerSetThreadPoolParameters(virAdmServerPtr srv,
cleanup:
virTypedParamsRemoteFree((struct _virTypedParameterRemote *) args.params.params_val,
args.params.params_len);
virObjectUnlock(priv);
return rv;
}
@ -322,17 +303,17 @@ remoteAdminClientGetInfo(virAdmClientPtr client,
remoteAdminPriv *priv = client->srv->conn->privateData;
admin_client_get_info_args args;
admin_client_get_info_ret ret;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
make_nonnull_client(&args.clnt, client);
memset(&ret, 0, sizeof(ret));
virObjectLock(priv);
if (call(client->srv->conn, 0, ADMIN_PROC_CLIENT_GET_INFO,
(xdrproc_t)xdr_admin_client_get_info_args, (char *) &args,
(xdrproc_t)xdr_admin_client_get_info_ret, (char *) &ret) == -1)
goto cleanup;
return -1;
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
ret.params.params_len,
@ -345,7 +326,6 @@ remoteAdminClientGetInfo(virAdmClientPtr client,
cleanup:
xdr_free((xdrproc_t)xdr_admin_client_get_info_ret, (char *) &ret);
virObjectUnlock(priv);
return rv;
}
@ -359,18 +339,19 @@ remoteAdminServerGetClientLimits(virAdmServerPtr srv,
admin_server_get_client_limits_args args;
admin_server_get_client_limits_ret ret;
remoteAdminPriv *priv = srv->conn->privateData;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
make_nonnull_server(&args.srv, srv);
memset(&ret, 0, sizeof(ret));
virObjectLock(priv);
if (call(srv->conn, 0, ADMIN_PROC_SERVER_GET_CLIENT_LIMITS,
(xdrproc_t) xdr_admin_server_get_client_limits_args,
(char *) &args,
(xdrproc_t) xdr_admin_server_get_client_limits_ret,
(char *) &ret) == -1)
goto cleanup;
return -1;
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
ret.params.params_len,
@ -384,7 +365,6 @@ remoteAdminServerGetClientLimits(virAdmServerPtr srv,
cleanup:
xdr_free((xdrproc_t) xdr_admin_server_get_client_limits_ret,
(char *) &ret);
virObjectUnlock(priv);
return rv;
}
@ -397,12 +377,11 @@ remoteAdminServerSetClientLimits(virAdmServerPtr srv,
int rv = -1;
admin_server_set_client_limits_args args;
remoteAdminPriv *priv = srv->conn->privateData;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
make_nonnull_server(&args.srv, srv);
virObjectLock(priv);
if (virTypedParamsSerialize(params, nparams,
ADMIN_SERVER_CLIENT_LIMITS_MAX,
(struct _virTypedParameterRemote **) &args.params.params_val,
@ -420,7 +399,6 @@ remoteAdminServerSetClientLimits(virAdmServerPtr srv,
cleanup:
virTypedParamsRemoteFree((struct _virTypedParameterRemote *) args.params.params_val,
args.params.params_len);
virObjectUnlock(priv);
return rv;
}
@ -433,11 +411,11 @@ remoteAdminConnectGetLoggingOutputs(virAdmConnectPtr conn,
remoteAdminPriv *priv = conn->privateData;
admin_connect_get_logging_outputs_args args;
admin_connect_get_logging_outputs_ret ret;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
memset(&ret, 0, sizeof(ret));
virObjectLock(priv);
if (call(conn,
0,
@ -446,16 +424,13 @@ remoteAdminConnectGetLoggingOutputs(virAdmConnectPtr conn,
(char *) &args,
(xdrproc_t) xdr_admin_connect_get_logging_outputs_ret,
(char *) &ret) == -1)
goto done;
return -1;
if (outputs)
*outputs = g_steal_pointer(&ret.outputs);
rv = ret.noutputs;
xdr_free((xdrproc_t) xdr_admin_connect_get_logging_outputs_ret, (char *) &ret);
done:
virObjectUnlock(priv);
return rv;
}
@ -468,11 +443,11 @@ remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
remoteAdminPriv *priv = conn->privateData;
admin_connect_get_logging_filters_args args;
admin_connect_get_logging_filters_ret ret;
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
args.flags = flags;
memset(&ret, 0, sizeof(ret));
virObjectLock(priv);
if (call(conn,
0,
@ -481,15 +456,12 @@ remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
(char *) &args,
(xdrproc_t) xdr_admin_connect_get_logging_filters_ret,
(char *) &ret) == -1)
goto done;
return -1;
if (filters)
*filters = ret.filters ? *ret.filters : NULL;
rv = ret.nfilters;
VIR_FREE(ret.filters);
done:
virObjectUnlock(priv);
return rv;
}