mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 05:25:18 +00:00
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:
parent
fda53ab3a5
commit
8ed7ef5d1a
@ -133,8 +133,7 @@ remoteAdminClientCloseFunc(virNetClient *client G_GNUC_UNUSED,
|
|||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virAdmConnectCloseCallbackData *cbdata = opaque;
|
virAdmConnectCloseCallbackData *cbdata = opaque;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(cbdata);
|
||||||
virObjectLock(cbdata);
|
|
||||||
|
|
||||||
if (cbdata->callback) {
|
if (cbdata->callback) {
|
||||||
VIR_DEBUG("Triggering connection close callback %p reason=%d, opaque=%p",
|
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);
|
cbdata->callback(cbdata->conn, reason, cbdata->opaque);
|
||||||
virAdmConnectCloseCallbackDataReset(cbdata);
|
virAdmConnectCloseCallbackDataReset(cbdata);
|
||||||
}
|
}
|
||||||
virObjectUnlock(cbdata);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
|
remoteAdminConnectOpen(virAdmConnectPtr conn, unsigned int flags)
|
||||||
{
|
{
|
||||||
int rv = -1;
|
|
||||||
remoteAdminPriv *priv = conn->privateData;
|
remoteAdminPriv *priv = conn->privateData;
|
||||||
admin_connect_open_args args;
|
admin_connect_open_args args;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
args.flags = flags & ~VIR_CONNECT_NO_ALIASES;
|
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,
|
if (call(conn, 0, ADMIN_PROC_CONNECT_OPEN,
|
||||||
(xdrproc_t)xdr_admin_connect_open_args, (char *)&args,
|
(xdrproc_t)xdr_admin_connect_open_args, (char *)&args,
|
||||||
(xdrproc_t)xdr_void, (char *)NULL) == -1) {
|
(xdrproc_t)xdr_void, (char *)NULL) == -1)
|
||||||
goto done;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
rv = 0;
|
return 0;
|
||||||
|
|
||||||
done:
|
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
remoteAdminConnectClose(virAdmConnectPtr conn)
|
remoteAdminConnectClose(virAdmConnectPtr conn)
|
||||||
{
|
{
|
||||||
int rv = -1;
|
|
||||||
remoteAdminPriv *priv = conn->privateData;
|
remoteAdminPriv *priv = conn->privateData;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (call(conn, 0, ADMIN_PROC_CONNECT_CLOSE,
|
if (call(conn, 0, ADMIN_PROC_CONNECT_CLOSE,
|
||||||
(xdrproc_t)xdr_void, (char *)NULL,
|
(xdrproc_t)xdr_void, (char *)NULL,
|
||||||
(xdrproc_t)xdr_void, (char *)NULL) == -1) {
|
(xdrproc_t)xdr_void, (char *)NULL) == -1)
|
||||||
goto done;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
virNetClientSetCloseCallback(priv->client, NULL, conn->closeCallback,
|
virNetClientSetCloseCallback(priv->client, NULL, conn->closeCallback,
|
||||||
virObjectUnref);
|
virObjectUnref);
|
||||||
virNetClientClose(priv->client);
|
virNetClientClose(priv->client);
|
||||||
|
|
||||||
rv = 0;
|
return 0;
|
||||||
|
|
||||||
done:
|
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -249,17 +233,17 @@ remoteAdminServerGetThreadPoolParameters(virAdmServerPtr srv,
|
|||||||
remoteAdminPriv *priv = srv->conn->privateData;
|
remoteAdminPriv *priv = srv->conn->privateData;
|
||||||
admin_server_get_threadpool_parameters_args args;
|
admin_server_get_threadpool_parameters_args args;
|
||||||
admin_server_get_threadpool_parameters_ret ret;
|
admin_server_get_threadpool_parameters_ret ret;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
make_nonnull_server(&args.srv, srv);
|
make_nonnull_server(&args.srv, srv);
|
||||||
|
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (call(srv->conn, 0, ADMIN_PROC_SERVER_GET_THREADPOOL_PARAMETERS,
|
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_args, (char *) &args,
|
||||||
(xdrproc_t)xdr_admin_server_get_threadpool_parameters_ret, (char *) &ret) == -1)
|
(xdrproc_t)xdr_admin_server_get_threadpool_parameters_ret, (char *) &ret) == -1)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
|
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
|
||||||
ret.params.params_len,
|
ret.params.params_len,
|
||||||
@ -272,7 +256,6 @@ remoteAdminServerGetThreadPoolParameters(virAdmServerPtr srv,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xdr_free((xdrproc_t)xdr_admin_server_get_threadpool_parameters_ret, (char *) &ret);
|
xdr_free((xdrproc_t)xdr_admin_server_get_threadpool_parameters_ret, (char *) &ret);
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,12 +268,11 @@ remoteAdminServerSetThreadPoolParameters(virAdmServerPtr srv,
|
|||||||
int rv = -1;
|
int rv = -1;
|
||||||
remoteAdminPriv *priv = srv->conn->privateData;
|
remoteAdminPriv *priv = srv->conn->privateData;
|
||||||
admin_server_set_threadpool_parameters_args args;
|
admin_server_set_threadpool_parameters_args args;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
make_nonnull_server(&args.srv, srv);
|
make_nonnull_server(&args.srv, srv);
|
||||||
|
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (virTypedParamsSerialize(params, nparams,
|
if (virTypedParamsSerialize(params, nparams,
|
||||||
ADMIN_SERVER_THREADPOOL_PARAMETERS_MAX,
|
ADMIN_SERVER_THREADPOOL_PARAMETERS_MAX,
|
||||||
(struct _virTypedParameterRemote **) &args.params.params_val,
|
(struct _virTypedParameterRemote **) &args.params.params_val,
|
||||||
@ -308,7 +290,6 @@ remoteAdminServerSetThreadPoolParameters(virAdmServerPtr srv,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virTypedParamsRemoteFree((struct _virTypedParameterRemote *) args.params.params_val,
|
virTypedParamsRemoteFree((struct _virTypedParameterRemote *) args.params.params_val,
|
||||||
args.params.params_len);
|
args.params.params_len);
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -322,17 +303,17 @@ remoteAdminClientGetInfo(virAdmClientPtr client,
|
|||||||
remoteAdminPriv *priv = client->srv->conn->privateData;
|
remoteAdminPriv *priv = client->srv->conn->privateData;
|
||||||
admin_client_get_info_args args;
|
admin_client_get_info_args args;
|
||||||
admin_client_get_info_ret ret;
|
admin_client_get_info_ret ret;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
make_nonnull_client(&args.clnt, client);
|
make_nonnull_client(&args.clnt, client);
|
||||||
|
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (call(client->srv->conn, 0, ADMIN_PROC_CLIENT_GET_INFO,
|
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_args, (char *) &args,
|
||||||
(xdrproc_t)xdr_admin_client_get_info_ret, (char *) &ret) == -1)
|
(xdrproc_t)xdr_admin_client_get_info_ret, (char *) &ret) == -1)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
|
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
|
||||||
ret.params.params_len,
|
ret.params.params_len,
|
||||||
@ -345,7 +326,6 @@ remoteAdminClientGetInfo(virAdmClientPtr client,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xdr_free((xdrproc_t)xdr_admin_client_get_info_ret, (char *) &ret);
|
xdr_free((xdrproc_t)xdr_admin_client_get_info_ret, (char *) &ret);
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,18 +339,19 @@ remoteAdminServerGetClientLimits(virAdmServerPtr srv,
|
|||||||
admin_server_get_client_limits_args args;
|
admin_server_get_client_limits_args args;
|
||||||
admin_server_get_client_limits_ret ret;
|
admin_server_get_client_limits_ret ret;
|
||||||
remoteAdminPriv *priv = srv->conn->privateData;
|
remoteAdminPriv *priv = srv->conn->privateData;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
make_nonnull_server(&args.srv, srv);
|
make_nonnull_server(&args.srv, srv);
|
||||||
|
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (call(srv->conn, 0, ADMIN_PROC_SERVER_GET_CLIENT_LIMITS,
|
if (call(srv->conn, 0, ADMIN_PROC_SERVER_GET_CLIENT_LIMITS,
|
||||||
(xdrproc_t) xdr_admin_server_get_client_limits_args,
|
(xdrproc_t) xdr_admin_server_get_client_limits_args,
|
||||||
(char *) &args,
|
(char *) &args,
|
||||||
(xdrproc_t) xdr_admin_server_get_client_limits_ret,
|
(xdrproc_t) xdr_admin_server_get_client_limits_ret,
|
||||||
(char *) &ret) == -1)
|
(char *) &ret) == -1)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
|
if (virTypedParamsDeserialize((struct _virTypedParameterRemote *) ret.params.params_val,
|
||||||
ret.params.params_len,
|
ret.params.params_len,
|
||||||
@ -384,7 +365,6 @@ remoteAdminServerGetClientLimits(virAdmServerPtr srv,
|
|||||||
cleanup:
|
cleanup:
|
||||||
xdr_free((xdrproc_t) xdr_admin_server_get_client_limits_ret,
|
xdr_free((xdrproc_t) xdr_admin_server_get_client_limits_ret,
|
||||||
(char *) &ret);
|
(char *) &ret);
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -397,12 +377,11 @@ remoteAdminServerSetClientLimits(virAdmServerPtr srv,
|
|||||||
int rv = -1;
|
int rv = -1;
|
||||||
admin_server_set_client_limits_args args;
|
admin_server_set_client_limits_args args;
|
||||||
remoteAdminPriv *priv = srv->conn->privateData;
|
remoteAdminPriv *priv = srv->conn->privateData;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
make_nonnull_server(&args.srv, srv);
|
make_nonnull_server(&args.srv, srv);
|
||||||
|
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (virTypedParamsSerialize(params, nparams,
|
if (virTypedParamsSerialize(params, nparams,
|
||||||
ADMIN_SERVER_CLIENT_LIMITS_MAX,
|
ADMIN_SERVER_CLIENT_LIMITS_MAX,
|
||||||
(struct _virTypedParameterRemote **) &args.params.params_val,
|
(struct _virTypedParameterRemote **) &args.params.params_val,
|
||||||
@ -420,7 +399,6 @@ remoteAdminServerSetClientLimits(virAdmServerPtr srv,
|
|||||||
cleanup:
|
cleanup:
|
||||||
virTypedParamsRemoteFree((struct _virTypedParameterRemote *) args.params.params_val,
|
virTypedParamsRemoteFree((struct _virTypedParameterRemote *) args.params.params_val,
|
||||||
args.params.params_len);
|
args.params.params_len);
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -433,11 +411,11 @@ remoteAdminConnectGetLoggingOutputs(virAdmConnectPtr conn,
|
|||||||
remoteAdminPriv *priv = conn->privateData;
|
remoteAdminPriv *priv = conn->privateData;
|
||||||
admin_connect_get_logging_outputs_args args;
|
admin_connect_get_logging_outputs_args args;
|
||||||
admin_connect_get_logging_outputs_ret ret;
|
admin_connect_get_logging_outputs_ret ret;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
|
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (call(conn,
|
if (call(conn,
|
||||||
0,
|
0,
|
||||||
@ -446,16 +424,13 @@ remoteAdminConnectGetLoggingOutputs(virAdmConnectPtr conn,
|
|||||||
(char *) &args,
|
(char *) &args,
|
||||||
(xdrproc_t) xdr_admin_connect_get_logging_outputs_ret,
|
(xdrproc_t) xdr_admin_connect_get_logging_outputs_ret,
|
||||||
(char *) &ret) == -1)
|
(char *) &ret) == -1)
|
||||||
goto done;
|
return -1;
|
||||||
|
|
||||||
if (outputs)
|
if (outputs)
|
||||||
*outputs = g_steal_pointer(&ret.outputs);
|
*outputs = g_steal_pointer(&ret.outputs);
|
||||||
|
|
||||||
rv = ret.noutputs;
|
rv = ret.noutputs;
|
||||||
xdr_free((xdrproc_t) xdr_admin_connect_get_logging_outputs_ret, (char *) &ret);
|
xdr_free((xdrproc_t) xdr_admin_connect_get_logging_outputs_ret, (char *) &ret);
|
||||||
|
|
||||||
done:
|
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -468,11 +443,11 @@ remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
|
|||||||
remoteAdminPriv *priv = conn->privateData;
|
remoteAdminPriv *priv = conn->privateData;
|
||||||
admin_connect_get_logging_filters_args args;
|
admin_connect_get_logging_filters_args args;
|
||||||
admin_connect_get_logging_filters_ret ret;
|
admin_connect_get_logging_filters_ret ret;
|
||||||
|
VIR_LOCK_GUARD lock = virObjectLockGuard(priv);
|
||||||
|
|
||||||
args.flags = flags;
|
args.flags = flags;
|
||||||
|
|
||||||
memset(&ret, 0, sizeof(ret));
|
memset(&ret, 0, sizeof(ret));
|
||||||
virObjectLock(priv);
|
|
||||||
|
|
||||||
if (call(conn,
|
if (call(conn,
|
||||||
0,
|
0,
|
||||||
@ -481,15 +456,12 @@ remoteAdminConnectGetLoggingFilters(virAdmConnectPtr conn,
|
|||||||
(char *) &args,
|
(char *) &args,
|
||||||
(xdrproc_t) xdr_admin_connect_get_logging_filters_ret,
|
(xdrproc_t) xdr_admin_connect_get_logging_filters_ret,
|
||||||
(char *) &ret) == -1)
|
(char *) &ret) == -1)
|
||||||
goto done;
|
return -1;
|
||||||
|
|
||||||
if (filters)
|
if (filters)
|
||||||
*filters = ret.filters ? *ret.filters : NULL;
|
*filters = ret.filters ? *ret.filters : NULL;
|
||||||
|
|
||||||
rv = ret.nfilters;
|
rv = ret.nfilters;
|
||||||
VIR_FREE(ret.filters);
|
VIR_FREE(ret.filters);
|
||||||
|
|
||||||
done:
|
|
||||||
virObjectUnlock(priv);
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user