Convert all rpc classes over to virObjectLockable

This commit is contained in:
Daniel P. Berrange 2013-01-09 21:27:28 +00:00
parent 325b02b5a3
commit bba93d40da
9 changed files with 366 additions and 535 deletions

View File

@ -35,9 +35,7 @@
#define VIR_FROM_THIS VIR_FROM_RPC
struct _virKeepAlive {
virObject object;
virMutex lock;
virObjectLockable parent;
int interval;
unsigned int count;
@ -58,7 +56,7 @@ static void virKeepAliveDispose(void *obj);
static int virKeepAliveOnceInit(void)
{
if (!(virKeepAliveClass = virClassNew(virClassForObject(),
if (!(virKeepAliveClass = virClassNew(virClassForObjectLockable(),
"virKeepAlive",
sizeof(virKeepAlive),
virKeepAliveDispose)))
@ -69,19 +67,6 @@ static int virKeepAliveOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virKeepAlive)
static void
virKeepAliveLock(virKeepAlivePtr ka)
{
virMutexLock(&ka->lock);
}
static void
virKeepAliveUnlock(virKeepAlivePtr ka)
{
virMutexUnlock(&ka->lock);
}
static virNetMessagePtr
virKeepAliveMessage(virKeepAlivePtr ka, int proc)
{
@ -174,7 +159,7 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
bool dead;
void *client;
virKeepAliveLock(ka);
virObjectLock(ka);
client = ka->client;
dead = virKeepAliveTimerInternal(ka, &msg);
@ -183,7 +168,7 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
goto cleanup;
virObjectRef(ka);
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
if (dead) {
ka->deadCB(client);
@ -192,11 +177,11 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
virNetMessageFree(msg);
}
virKeepAliveLock(ka);
virObjectLock(ka);
virObjectUnref(ka);
cleanup:
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
}
@ -215,14 +200,9 @@ virKeepAliveNew(int interval,
if (virKeepAliveInitialize() < 0)
return NULL;
if (!(ka = virObjectNew(virKeepAliveClass)))
if (!(ka = virObjectLockableNew(virKeepAliveClass)))
return NULL;
if (virMutexInit(&ka->lock) < 0) {
VIR_FREE(ka);
return NULL;
}
ka->interval = interval;
ka->count = count;
ka->countToDeath = count;
@ -245,7 +225,6 @@ virKeepAliveDispose(void *obj)
{
virKeepAlivePtr ka = obj;
virMutexDestroy(&ka->lock);
ka->freeCB(ka->client);
}
@ -260,7 +239,7 @@ virKeepAliveStart(virKeepAlivePtr ka,
int timeout;
time_t now;
virKeepAliveLock(ka);
virObjectLock(ka);
if (ka->timer >= 0) {
VIR_DEBUG("Keepalive messages already enabled");
@ -306,7 +285,7 @@ virKeepAliveStart(virKeepAlivePtr ka,
ret = 0;
cleanup:
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
return ret;
}
@ -314,7 +293,7 @@ cleanup:
void
virKeepAliveStop(virKeepAlivePtr ka)
{
virKeepAliveLock(ka);
virObjectLock(ka);
PROBE(RPC_KEEPALIVE_STOP,
"ka=%p client=%p",
@ -325,7 +304,7 @@ virKeepAliveStop(virKeepAlivePtr ka)
ka->timer = -1;
}
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
}
@ -337,7 +316,7 @@ virKeepAliveTimeout(virKeepAlivePtr ka)
if (!ka)
return -1;
virKeepAliveLock(ka);
virObjectLock(ka);
if (ka->interval <= 0 || ka->intervalStart == 0) {
timeout = -1;
@ -347,7 +326,7 @@ virKeepAliveTimeout(virKeepAlivePtr ka)
timeout = 0;
}
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
if (timeout < 0)
return -1;
@ -366,9 +345,9 @@ virKeepAliveTrigger(virKeepAlivePtr ka,
if (!ka)
return false;
virKeepAliveLock(ka);
virObjectLock(ka);
dead = virKeepAliveTimerInternal(ka, msg);
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
return dead;
}
@ -388,7 +367,7 @@ virKeepAliveCheckMessage(virKeepAlivePtr ka,
if (!ka)
return false;
virKeepAliveLock(ka);
virObjectLock(ka);
ka->countToDeath = ka->count;
ka->lastPacketReceived = ka->intervalStart = time(NULL);
@ -420,7 +399,7 @@ virKeepAliveCheckMessage(virKeepAlivePtr ka,
if (ka->timer >= 0)
virEventUpdateTimeout(ka->timer, ka->interval * 1000);
virKeepAliveUnlock(ka);
virObjectUnlock(ka);
return ret;
}

View File

@ -63,9 +63,7 @@ struct _virNetClientCall {
struct _virNetClient {
virObject object;
virMutex lock;
virObjectLockable parent;
virNetSocketPtr sock;
bool asyncIO;
@ -136,28 +134,16 @@ static void virNetClientCloseInternal(virNetClientPtr client,
int reason);
static void virNetClientLock(virNetClientPtr client)
{
virMutexLock(&client->lock);
}
static void virNetClientUnlock(virNetClientPtr client)
{
virMutexUnlock(&client->lock);
}
void virNetClientSetCloseCallback(virNetClientPtr client,
virNetClientCloseFunc cb,
void *opaque,
virFreeCallback ff)
{
virNetClientLock(client);
virObjectLock(client);
client->closeCb = cb;
client->closeOpaque = opaque;
client->closeFf = ff;
virNetClientUnlock(client);
virObjectUnlock(client);
}
@ -261,9 +247,9 @@ virNetClientKeepAliveIsSupported(virNetClientPtr client)
{
bool supported;
virNetClientLock(client);
virObjectLock(client);
supported = !!client->keepalive;
virNetClientUnlock(client);
virObjectUnlock(client);
return supported;
}
@ -275,9 +261,9 @@ virNetClientKeepAliveStart(virNetClientPtr client,
{
int ret;
virNetClientLock(client);
virObjectLock(client);
ret = virKeepAliveStart(client->keepalive, interval, count);
virNetClientUnlock(client);
virObjectUnlock(client);
return ret;
}
@ -285,9 +271,9 @@ virNetClientKeepAliveStart(virNetClientPtr client,
void
virNetClientKeepAliveStop(virNetClientPtr client)
{
virNetClientLock(client);
virObjectLock(client);
virKeepAliveStop(client->keepalive);
virNetClientUnlock(client);
virObjectUnlock(client);
}
static void
@ -323,14 +309,9 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
goto error;
}
if (!(client = virObjectNew(virNetClientClass)))
if (!(client = virObjectLockableNew(virNetClientClass)))
goto error;
if (virMutexInit(&client->lock) < 0) {
VIR_FREE(client);
goto error;
}
client->sock = sock;
client->wakeupReadFD = wakeupFD[0];
client->wakeupSendFD = wakeupFD[1];
@ -583,9 +564,9 @@ int virNetClientRegisterKeepAlive(virNetClientPtr client)
int virNetClientGetFD(virNetClientPtr client)
{
int fd;
virNetClientLock(client);
virObjectLock(client);
fd = virNetSocketGetFD(client->sock);
virNetClientUnlock(client);
virObjectUnlock(client);
return fd;
}
@ -593,9 +574,9 @@ int virNetClientGetFD(virNetClientPtr client)
int virNetClientDupFD(virNetClientPtr client, bool cloexec)
{
int fd;
virNetClientLock(client);
virObjectLock(client);
fd = virNetSocketDupFD(client->sock, cloexec);
virNetClientUnlock(client);
virObjectUnlock(client);
return fd;
}
@ -603,9 +584,9 @@ int virNetClientDupFD(virNetClientPtr client, bool cloexec)
bool virNetClientHasPassFD(virNetClientPtr client)
{
bool hasPassFD;
virNetClientLock(client);
virObjectLock(client);
hasPassFD = virNetSocketHasPassFD(client->sock);
virNetClientUnlock(client);
virObjectUnlock(client);
return hasPassFD;
}
@ -639,8 +620,7 @@ void virNetClientDispose(void *obj)
virNetMessageClear(&client->msg);
virNetClientUnlock(client);
virMutexDestroy(&client->lock);
virObjectUnlock(client);
}
@ -685,7 +665,7 @@ virNetClientCloseLocked(virNetClientPtr client)
void *closeOpaque = client->closeOpaque;
int closeReason = client->closeReason;
virObjectRef(client);
virNetClientUnlock(client);
virObjectUnlock(client);
if (ka) {
virKeepAliveStop(ka);
@ -694,7 +674,7 @@ virNetClientCloseLocked(virNetClientPtr client)
if (closeCb)
closeCb(client, closeReason, closeOpaque);
virNetClientLock(client);
virObjectLock(client);
virObjectUnref(client);
}
}
@ -711,7 +691,7 @@ static void virNetClientCloseInternal(virNetClientPtr client,
client->wantClose)
return;
virNetClientLock(client);
virObjectLock(client);
virNetClientMarkClose(client, reason);
@ -730,7 +710,7 @@ static void virNetClientCloseInternal(virNetClientPtr client,
virNetClientIOEventLoopPassTheBuck(client, NULL);
}
virNetClientUnlock(client);
virObjectUnlock(client);
}
@ -744,10 +724,10 @@ void virNetClientClose(virNetClientPtr client)
void virNetClientSetSASLSession(virNetClientPtr client,
virNetSASLSessionPtr sasl)
{
virNetClientLock(client);
virObjectLock(client);
client->sasl = virObjectRef(sasl);
virNetSocketSetSASLSession(client->sock, client->sasl);
virNetClientUnlock(client);
virObjectUnlock(client);
}
#endif
@ -771,7 +751,7 @@ int virNetClientSetTLSSession(virNetClientPtr client,
# endif
sigaddset(&blockedsigs, SIGPIPE);
virNetClientLock(client);
virObjectLock(client);
if (!(client->tls = virNetTLSSessionNew(tls,
client->hostname)))
@ -846,13 +826,13 @@ int virNetClientSetTLSSession(virNetClientPtr client,
goto error;
}
virNetClientUnlock(client);
virObjectUnlock(client);
return 0;
error:
virObjectUnref(client->tls);
client->tls = NULL;
virNetClientUnlock(client);
virObjectUnlock(client);
return -1;
}
#endif
@ -860,7 +840,7 @@ error:
bool virNetClientIsEncrypted(virNetClientPtr client)
{
bool ret = false;
virNetClientLock(client);
virObjectLock(client);
#if WITH_GNUTLS
if (client->tls)
ret = true;
@ -869,7 +849,7 @@ bool virNetClientIsEncrypted(virNetClientPtr client)
if (client->sasl)
ret = true;
#endif
virNetClientUnlock(client);
virObjectUnlock(client);
return ret;
}
@ -881,9 +861,9 @@ bool virNetClientIsOpen(virNetClientPtr client)
if (!client)
return false;
virNetClientLock(client);
virObjectLock(client);
ret = client->sock && !client->wantClose;
virNetClientUnlock(client);
virObjectUnlock(client);
return ret;
}
@ -891,19 +871,19 @@ bool virNetClientIsOpen(virNetClientPtr client)
int virNetClientAddProgram(virNetClientPtr client,
virNetClientProgramPtr prog)
{
virNetClientLock(client);
virObjectLock(client);
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0)
goto no_memory;
client->programs[client->nprograms-1] = virObjectRef(prog);
virNetClientUnlock(client);
virObjectUnlock(client);
return 0;
no_memory:
virReportOOMError();
virNetClientUnlock(client);
virObjectUnlock(client);
return -1;
}
@ -911,19 +891,19 @@ no_memory:
int virNetClientAddStream(virNetClientPtr client,
virNetClientStreamPtr st)
{
virNetClientLock(client);
virObjectLock(client);
if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0)
goto no_memory;
client->streams[client->nstreams-1] = virObjectRef(st);
virNetClientUnlock(client);
virObjectUnlock(client);
return 0;
no_memory:
virReportOOMError();
virNetClientUnlock(client);
virObjectUnlock(client);
return -1;
}
@ -931,7 +911,7 @@ no_memory:
void virNetClientRemoveStream(virNetClientPtr client,
virNetClientStreamPtr st)
{
virNetClientLock(client);
virObjectLock(client);
size_t i;
for (i = 0 ; i < client->nstreams ; i++) {
if (client->streams[i] == st)
@ -953,7 +933,7 @@ void virNetClientRemoveStream(virNetClientPtr client,
virObjectUnref(st);
cleanup:
virNetClientUnlock(client);
virObjectUnlock(client);
}
@ -971,10 +951,10 @@ const char *virNetClientRemoteAddrString(virNetClientPtr client)
int virNetClientGetTLSKeySize(virNetClientPtr client)
{
int ret = 0;
virNetClientLock(client);
virObjectLock(client);
if (client->tls)
ret = virNetTLSSessionGetKeySize(client->tls);
virNetClientUnlock(client);
virObjectUnlock(client);
return ret;
}
#endif
@ -1522,7 +1502,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
/* Release lock while poll'ing so other threads
* can stuff themselves on the queue */
virNetClientUnlock(client);
virObjectUnlock(client);
/* Block SIGWINCH from interrupting poll in curses programs,
* then restore the original signal mask again immediately
@ -1546,7 +1526,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
virNetClientLock(client);
virObjectLock(client);
if (ret < 0) {
virReportSystemError(errno,
@ -1762,7 +1742,7 @@ static int virNetClientIO(virNetClientPtr client,
VIR_DEBUG("Going to sleep head=%p call=%p",
client->waitDispatch, thiscall);
/* Go to sleep while other thread is working... */
if (virCondWait(&thiscall->cond, &client->lock) < 0) {
if (virCondWait(&thiscall->cond, &client->parent.lock) < 0) {
virNetClientCallRemove(&client->waitDispatch, thiscall);
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("failed to wait on condition"));
@ -1834,7 +1814,7 @@ void virNetClientIncomingEvent(virNetSocketPtr sock,
{
virNetClientPtr client = opaque;
virNetClientLock(client);
virObjectLock(client);
VIR_DEBUG("client=%p wantclose=%d", client, client ? client->wantClose : false);
@ -1876,7 +1856,7 @@ void virNetClientIncomingEvent(virNetSocketPtr sock,
done:
if (client->wantClose)
virNetClientCloseLocked(client);
virNetClientUnlock(client);
virObjectUnlock(client);
}
@ -2012,9 +1992,9 @@ int virNetClientSendWithReply(virNetClientPtr client,
virNetMessagePtr msg)
{
int ret;
virNetClientLock(client);
virObjectLock(client);
ret = virNetClientSendInternal(client, msg, true, false);
virNetClientUnlock(client);
virObjectUnlock(client);
if (ret < 0)
return -1;
return 0;
@ -2035,9 +2015,9 @@ int virNetClientSendNoReply(virNetClientPtr client,
virNetMessagePtr msg)
{
int ret;
virNetClientLock(client);
virObjectLock(client);
ret = virNetClientSendInternal(client, msg, false, false);
virNetClientUnlock(client);
virObjectUnlock(client);
if (ret < 0)
return -1;
return 0;
@ -2058,9 +2038,9 @@ int virNetClientSendNonBlock(virNetClientPtr client,
virNetMessagePtr msg)
{
int ret;
virNetClientLock(client);
virObjectLock(client);
ret = virNetClientSendInternal(client, msg, false, true);
virNetClientUnlock(client);
virObjectUnlock(client);
return ret;
}
@ -2079,18 +2059,18 @@ int virNetClientSendWithReplyStream(virNetClientPtr client,
virNetClientStreamPtr st)
{
int ret;
virNetClientLock(client);
virObjectLock(client);
/* Other thread might have already received
* stream EOF so we don't want sent anything.
* Server won't respond anyway.
*/
if (virNetClientStreamEOF(st)) {
virNetClientUnlock(client);
virObjectUnlock(client);
return 0;
}
ret = virNetClientSendInternal(client, msg, true, false);
virNetClientUnlock(client);
virObjectUnlock(client);
if (ret < 0)
return -1;
return 0;

View File

@ -32,9 +32,7 @@
#define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetClientStream {
virObject object;
virMutex lock;
virObjectLockable parent;
virNetClientProgramPtr prog;
int proc;
@ -68,7 +66,7 @@ static void virNetClientStreamDispose(void *obj);
static int virNetClientStreamOnceInit(void)
{
if (!(virNetClientStreamClass = virClassNew(virClassForObject(),
if (!(virNetClientStreamClass = virClassNew(virClassForObjectLockable(),
"virNetClientStream",
sizeof(virNetClientStream),
virNetClientStreamDispose)))
@ -106,8 +104,7 @@ virNetClientStreamEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
virNetClientStreamPtr st = opaque;
int events = 0;
virMutexLock(&st->lock);
virObjectLock(st);
if (st->cb &&
(st->cbEvents & VIR_STREAM_EVENT_READABLE) &&
@ -124,15 +121,15 @@ virNetClientStreamEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
virFreeCallback cbFree = st->cbFree;
st->cbDispatch = 1;
virMutexUnlock(&st->lock);
virObjectUnlock(st);
(cb)(st, events, cbOpaque);
virMutexLock(&st->lock);
virObjectLock(st);
st->cbDispatch = 0;
if (!st->cb && cbFree)
(cbFree)(cbOpaque);
}
virMutexUnlock(&st->lock);
virObjectUnlock(st);
}
@ -145,20 +142,13 @@ virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr prog,
if (virNetClientStreamInitialize() < 0)
return NULL;
if (!(st = virObjectNew(virNetClientStreamClass)))
if (!(st = virObjectLockableNew(virNetClientStreamClass)))
return NULL;
st->prog = prog;
st->proc = proc;
st->serial = serial;
if (virMutexInit(&st->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
VIR_FREE(st);
return NULL;
}
virObjectRef(prog);
return st;
@ -170,7 +160,6 @@ void virNetClientStreamDispose(void *obj)
virResetError(&st->err);
VIR_FREE(st->incoming);
virMutexDestroy(&st->lock);
virObjectUnref(st->prog);
}
@ -178,21 +167,21 @@ bool virNetClientStreamMatches(virNetClientStreamPtr st,
virNetMessagePtr msg)
{
bool match = false;
virMutexLock(&st->lock);
virObjectLock(st);
if (virNetClientProgramMatches(st->prog, msg) &&
st->proc == msg->header.proc &&
st->serial == msg->header.serial)
match = true;
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return match;
}
bool virNetClientStreamRaiseError(virNetClientStreamPtr st)
{
virMutexLock(&st->lock);
virObjectLock(st);
if (st->err.code == VIR_ERR_OK) {
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return false;
}
@ -206,7 +195,7 @@ bool virNetClientStreamRaiseError(virNetClientStreamPtr st)
st->err.int1,
st->err.int2,
"%s", st->err.message ? st->err.message : _("Unknown error"));
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return true;
}
@ -217,7 +206,7 @@ int virNetClientStreamSetError(virNetClientStreamPtr st,
virNetMessageError err;
int ret = -1;
virMutexLock(&st->lock);
virObjectLock(st);
if (st->err.code != VIR_ERR_OK)
VIR_DEBUG("Overwriting existing stream error %s", NULLSTR(st->err.message));
@ -265,7 +254,7 @@ int virNetClientStreamSetError(virNetClientStreamPtr st,
cleanup:
xdr_free((xdrproc_t)xdr_virNetMessageError, (void*)&err);
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return ret;
}
@ -276,7 +265,7 @@ int virNetClientStreamQueuePacket(virNetClientStreamPtr st,
int ret = -1;
size_t need;
virMutexLock(&st->lock);
virObjectLock(st);
need = msg->bufferLength - msg->bufferOffset;
if (need) {
size_t avail = st->incomingLength - st->incomingOffset;
@ -306,7 +295,7 @@ int virNetClientStreamQueuePacket(virNetClientStreamPtr st,
ret = 0;
cleanup:
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return ret;
}
@ -323,7 +312,7 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
if (!(msg = virNetMessageNew(false)))
return -1;
virMutexLock(&st->lock);
virObjectLock(st);
msg->header.prog = virNetClientProgramGetProgram(st->prog);
msg->header.vers = virNetClientProgramGetVersion(st->prog);
@ -332,7 +321,7 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
msg->header.serial = st->serial;
msg->header.proc = st->proc;
virMutexUnlock(&st->lock);
virObjectUnlock(st);
if (virNetMessageEncodeHeader(msg) < 0)
goto error;
@ -373,7 +362,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
int rv = -1;
VIR_DEBUG("st=%p client=%p data=%p nbytes=%zu nonblock=%d",
st, client, data, nbytes, nonblock);
virMutexLock(&st->lock);
virObjectLock(st);
if (!st->incomingOffset && !st->incomingEOF) {
virNetMessagePtr msg;
int ret;
@ -397,9 +386,9 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
msg->header.status = VIR_NET_CONTINUE;
VIR_DEBUG("Dummy packet to wait for stream data");
virMutexUnlock(&st->lock);
virObjectUnlock(st);
ret = virNetClientSendWithReplyStream(client, msg, st);
virMutexLock(&st->lock);
virObjectLock(st);
virNetMessageFree(msg);
if (ret < 0)
@ -427,7 +416,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
virNetClientStreamEventTimerUpdate(st);
cleanup:
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return rv;
}
@ -440,7 +429,7 @@ int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
{
int ret = -1;
virMutexLock(&st->lock);
virObjectLock(st);
if (st->cb) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("multiple stream callbacks not supported"));
@ -467,7 +456,7 @@ int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
ret = 0;
cleanup:
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return ret;
}
@ -476,7 +465,7 @@ int virNetClientStreamEventUpdateCallback(virNetClientStreamPtr st,
{
int ret = -1;
virMutexLock(&st->lock);
virObjectLock(st);
if (!st->cb) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no stream callback registered"));
@ -490,7 +479,7 @@ int virNetClientStreamEventUpdateCallback(virNetClientStreamPtr st,
ret = 0;
cleanup:
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return ret;
}
@ -498,7 +487,7 @@ int virNetClientStreamEventRemoveCallback(virNetClientStreamPtr st)
{
int ret = -1;
virMutexLock(&st->lock);
virObjectLock(st);
if (!st->cb) {
virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("no stream callback registered"));
@ -517,7 +506,7 @@ int virNetClientStreamEventRemoveCallback(virNetClientStreamPtr st)
ret = 0;
cleanup:
virMutexUnlock(&st->lock);
virObjectUnlock(st);
return ret;
}

View File

@ -33,16 +33,14 @@
#define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetSASLContext {
virObject object;
virObjectLockable parent;
virMutex lock;
const char *const*usernameWhitelist;
};
struct _virNetSASLSession {
virObject object;
virObjectLockable parent;
virMutex lock;
sasl_conn_t *conn;
size_t maxbufsize;
};
@ -50,18 +48,17 @@ struct _virNetSASLSession {
static virClassPtr virNetSASLContextClass;
static virClassPtr virNetSASLSessionClass;
static void virNetSASLContextDispose(void *obj);
static void virNetSASLSessionDispose(void *obj);
static int virNetSASLContextOnceInit(void)
{
if (!(virNetSASLContextClass = virClassNew(virClassForObject(),
if (!(virNetSASLContextClass = virClassNew(virClassForObjectLockable(),
"virNetSASLContext",
sizeof(virNetSASLContext),
virNetSASLContextDispose)))
NULL)))
return -1;
if (!(virNetSASLSessionClass = virClassNew(virClassForObject(),
if (!(virNetSASLSessionClass = virClassNew(virClassForObjectLockable(),
"virNetSASLSession",
sizeof(virNetSASLSession),
virNetSASLSessionDispose)))
@ -89,16 +86,9 @@ virNetSASLContextPtr virNetSASLContextNewClient(void)
return NULL;
}
if (!(ctxt = virObjectNew(virNetSASLContextClass)))
if (!(ctxt = virObjectLockableNew(virNetSASLContextClass)))
return NULL;
if (virMutexInit(&ctxt->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to initialized mutex"));
VIR_FREE(ctxt);
return NULL;
}
return ctxt;
}
@ -118,16 +108,9 @@ virNetSASLContextPtr virNetSASLContextNewServer(const char *const*usernameWhitel
return NULL;
}
if (!(ctxt = virObjectNew(virNetSASLContextClass)))
if (!(ctxt = virObjectLockableNew(virNetSASLContextClass)))
return NULL;
if (virMutexInit(&ctxt->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to initialized mutex"));
VIR_FREE(ctxt);
return NULL;
}
ctxt->usernameWhitelist = usernameWhitelist;
return ctxt;
@ -139,7 +122,7 @@ int virNetSASLContextCheckIdentity(virNetSASLContextPtr ctxt,
const char *const*wildcards;
int ret = -1;
virMutexLock(&ctxt->lock);
virObjectLock(ctxt);
/* If the list is not set, allow any DN. */
wildcards = ctxt->usernameWhitelist;
@ -173,18 +156,11 @@ int virNetSASLContextCheckIdentity(virNetSASLContextPtr ctxt,
ret = 0;
cleanup:
virMutexUnlock(&ctxt->lock);
virObjectUnlock(ctxt);
return ret;
}
void virNetSASLContextDispose(void *obj)
{
virNetSASLContextPtr ctxt = obj;
virMutexDestroy(&ctxt->lock);
}
virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt ATTRIBUTE_UNUSED,
const char *service,
const char *hostname,
@ -195,16 +171,9 @@ virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt ATTRIB
virNetSASLSessionPtr sasl = NULL;
int err;
if (!(sasl = virObjectNew(virNetSASLSessionClass)))
if (!(sasl = virObjectLockableNew(virNetSASLSessionClass)))
return NULL;
if (virMutexInit(&sasl->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to initialized mutex"));
VIR_FREE(sasl);
return NULL;
}
/* Arbitrary size for amount of data we can encode in a single block */
sasl->maxbufsize = 1 << 16;
@ -237,16 +206,9 @@ virNetSASLSessionPtr virNetSASLSessionNewServer(virNetSASLContextPtr ctxt ATTRIB
virNetSASLSessionPtr sasl = NULL;
int err;
if (!(sasl = virObjectNew(virNetSASLSessionClass)))
if (!(sasl = virObjectLockableNew(virNetSASLSessionClass)))
return NULL;
if (virMutexInit(&sasl->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to initialized mutex"));
VIR_FREE(sasl);
return NULL;
}
/* Arbitrary size for amount of data we can encode in a single block */
sasl->maxbufsize = 1 << 16;
@ -277,7 +239,7 @@ int virNetSASLSessionExtKeySize(virNetSASLSessionPtr sasl,
{
int err;
int ret = -1;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_setprop(sasl->conn, SASL_SSF_EXTERNAL, &ssf);
if (err != SASL_OK) {
@ -290,7 +252,7 @@ int virNetSASLSessionExtKeySize(virNetSASLSessionPtr sasl,
ret = 0;
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -298,7 +260,7 @@ const char *virNetSASLSessionGetIdentity(virNetSASLSessionPtr sasl)
{
const void *val = NULL;
int err;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_getprop(sasl->conn, SASL_USERNAME, &val);
if (err != SASL_OK) {
@ -316,7 +278,7 @@ const char *virNetSASLSessionGetIdentity(virNetSASLSessionPtr sasl)
VIR_DEBUG("SASL client username %s", (const char *)val);
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return (const char*)val;
}
@ -327,7 +289,7 @@ int virNetSASLSessionGetKeySize(virNetSASLSessionPtr sasl)
int ssf;
const void *val;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_getprop(sasl->conn, SASL_SSF, &val);
if (err != SASL_OK) {
virReportError(VIR_ERR_AUTH_FAILED,
@ -339,7 +301,7 @@ int virNetSASLSessionGetKeySize(virNetSASLSessionPtr sasl)
ssf = *(const int *)val;
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ssf;
}
@ -355,7 +317,7 @@ int virNetSASLSessionSecProps(virNetSASLSessionPtr sasl,
VIR_DEBUG("minSSF=%d maxSSF=%d allowAnonymous=%d maxbufsize=%zu",
minSSF, maxSSF, allowAnonymous, sasl->maxbufsize);
virMutexLock(&sasl->lock);
virObjectLock(sasl);
memset(&secprops, 0, sizeof(secprops));
secprops.min_ssf = minSSF;
@ -375,7 +337,7 @@ int virNetSASLSessionSecProps(virNetSASLSessionPtr sasl,
ret = 0;
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -408,7 +370,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl)
char *ret = NULL;
int err;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_listmech(sasl->conn,
NULL, /* Don't need to set user */
"", /* Prefix */
@ -429,7 +391,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl)
}
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -448,7 +410,7 @@ int virNetSASLSessionClientStart(virNetSASLSessionPtr sasl,
VIR_DEBUG("sasl=%p mechlist=%s prompt_need=%p clientout=%p clientoutlen=%p mech=%p",
sasl, mechlist, prompt_need, clientout, clientoutlen, mech);
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_client_start(sasl->conn,
mechlist,
prompt_need,
@ -478,7 +440,7 @@ int virNetSASLSessionClientStart(virNetSASLSessionPtr sasl,
}
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -498,7 +460,7 @@ int virNetSASLSessionClientStep(virNetSASLSessionPtr sasl,
VIR_DEBUG("sasl=%p serverin=%s serverinlen=%zu prompt_need=%p clientout=%p clientoutlen=%p",
sasl, serverin, serverinlen, prompt_need, clientout, clientoutlen);
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_client_step(sasl->conn,
serverin,
inlen,
@ -527,7 +489,7 @@ int virNetSASLSessionClientStep(virNetSASLSessionPtr sasl,
}
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -543,7 +505,7 @@ int virNetSASLSessionServerStart(virNetSASLSessionPtr sasl,
int err;
int ret = -1;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_server_start(sasl->conn,
mechname,
clientin,
@ -573,7 +535,7 @@ int virNetSASLSessionServerStart(virNetSASLSessionPtr sasl,
}
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -589,7 +551,7 @@ int virNetSASLSessionServerStep(virNetSASLSessionPtr sasl,
int err;
int ret = -1;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
err = sasl_server_step(sasl->conn,
clientin,
inlen,
@ -618,16 +580,16 @@ int virNetSASLSessionServerStep(virNetSASLSessionPtr sasl,
}
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
size_t virNetSASLSessionGetMaxBufSize(virNetSASLSessionPtr sasl)
{
size_t ret;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
ret = sasl->maxbufsize;
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -642,7 +604,7 @@ ssize_t virNetSASLSessionEncode(virNetSASLSessionPtr sasl,
int err;
ssize_t ret = -1;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
if (inputLen > sasl->maxbufsize) {
virReportSystemError(EINVAL,
_("SASL data length %zu too long, max %zu"),
@ -666,7 +628,7 @@ ssize_t virNetSASLSessionEncode(virNetSASLSessionPtr sasl,
ret = 0;
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -681,7 +643,7 @@ ssize_t virNetSASLSessionDecode(virNetSASLSessionPtr sasl,
int err;
ssize_t ret = -1;
virMutexLock(&sasl->lock);
virObjectLock(sasl);
if (inputLen > sasl->maxbufsize) {
virReportSystemError(EINVAL,
_("SASL data length %zu too long, max %zu"),
@ -704,7 +666,7 @@ ssize_t virNetSASLSessionDecode(virNetSASLSessionPtr sasl,
ret = 0;
cleanup:
virMutexUnlock(&sasl->lock);
virObjectUnlock(sasl);
return ret;
}
@ -715,5 +677,4 @@ void virNetSASLSessionDispose(void *obj)
if (sasl->conn)
sasl_dispose(&sasl->conn);
virMutexDestroy(&sasl->lock);
}

View File

@ -64,9 +64,7 @@ struct _virNetServerJob {
};
struct _virNetServer {
virObject object;
virMutex lock;
virObjectLockable parent;
virThreadPoolPtr workers;
@ -119,7 +117,7 @@ static void virNetServerDispose(void *obj);
static int virNetServerOnceInit(void)
{
if (!(virNetServerClass = virClassNew(virClassForObject(),
if (!(virNetServerClass = virClassNew(virClassForObjectLockable(),
"virNetServer",
sizeof(virNetServer),
virNetServerDispose)))
@ -131,17 +129,6 @@ static int virNetServerOnceInit(void)
VIR_ONCE_GLOBAL_INIT(virNetServer)
static void virNetServerLock(virNetServerPtr srv)
{
virMutexLock(&srv->lock);
}
static void virNetServerUnlock(virNetServerPtr srv)
{
virMutexUnlock(&srv->lock);
}
static int virNetServerProcessMsg(virNetServerPtr srv,
virNetServerClientPtr client,
virNetServerProgramPtr prog,
@ -222,7 +209,7 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
VIR_DEBUG("server=%p client=%p message=%p",
srv, client, msg);
virNetServerLock(srv);
virObjectLock(srv);
for (i = 0 ; i < srv->nprograms ; i++) {
if (virNetServerProgramMatches(srv->programs[i], msg)) {
prog = srv->programs[i];
@ -258,7 +245,7 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
}
cleanup:
virNetServerUnlock(srv);
virObjectUnlock(srv);
return ret;
}
@ -267,7 +254,7 @@ cleanup:
static int virNetServerAddClient(virNetServerPtr srv,
virNetServerClientPtr client)
{
virNetServerLock(srv);
virObjectLock(srv);
if (srv->nclients >= srv->nclients_max) {
virReportError(VIR_ERR_RPC,
@ -293,11 +280,11 @@ static int virNetServerAddClient(virNetServerPtr srv,
virNetServerClientInitKeepAlive(client, srv->keepaliveInterval,
srv->keepaliveCount);
virNetServerUnlock(srv);
virObjectUnlock(srv);
return 0;
error:
virNetServerUnlock(srv);
virObjectUnlock(srv);
return -1;
}
@ -378,7 +365,7 @@ virNetServerPtr virNetServerNew(size_t min_workers,
if (virNetServerInitialize() < 0)
return NULL;
if (!(srv = virObjectNew(virNetServerClass)))
if (!(srv = virObjectLockableNew(virNetServerClass)))
return NULL;
if (max_workers &&
@ -413,12 +400,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
goto error;
}
if (virMutexInit(&srv->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("cannot initialize mutex"));
goto error;
}
if (virEventRegisterDefaultImpl() < 0)
goto error;
@ -607,7 +588,7 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
virJSONValuePtr services;
size_t i;
virMutexLock(&srv->lock);
virObjectLock(srv);
if (!(object = virJSONValueNewObject()))
goto error;
@ -692,13 +673,13 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
}
}
virMutexUnlock(&srv->lock);
virObjectUnlock(srv);
return object;
error:
virJSONValueFree(object);
virMutexUnlock(&srv->lock);
virObjectUnlock(srv);
return NULL;
}
@ -706,9 +687,9 @@ error:
bool virNetServerIsPrivileged(virNetServerPtr srv)
{
bool priv;
virNetServerLock(srv);
virObjectLock(srv);
priv = srv->privileged;
virNetServerUnlock(srv);
virObjectUnlock(srv);
return priv;
}
@ -716,11 +697,11 @@ bool virNetServerIsPrivileged(virNetServerPtr srv)
void virNetServerAutoShutdown(virNetServerPtr srv,
unsigned int timeout)
{
virNetServerLock(srv);
virObjectLock(srv);
srv->autoShutdownTimeout = timeout;
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
@ -732,7 +713,7 @@ static void virNetServerGotInhibitReply(DBusPendingCall *pending,
DBusMessage *reply;
int fd;
virNetServerLock(srv);
virObjectLock(srv);
srv->autoShutdownCallingInhibit = false;
VIR_DEBUG("srv=%p", srv);
@ -754,7 +735,7 @@ static void virNetServerGotInhibitReply(DBusPendingCall *pending,
dbus_message_unref(reply);
cleanup:
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
@ -808,7 +789,7 @@ static void virNetServerCallInhibit(virNetServerPtr srv,
void virNetServerAddShutdownInhibition(virNetServerPtr srv)
{
virNetServerLock(srv);
virObjectLock(srv);
srv->autoShutdownInhibitions++;
VIR_DEBUG("srv=%p inhibitions=%zu", srv, srv->autoShutdownInhibitions);
@ -822,13 +803,13 @@ void virNetServerAddShutdownInhibition(virNetServerPtr srv)
"delay");
#endif
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
void virNetServerRemoveShutdownInhibition(virNetServerPtr srv)
{
virNetServerLock(srv);
virObjectLock(srv);
srv->autoShutdownInhibitions--;
VIR_DEBUG("srv=%p inhibitions=%zu", srv, srv->autoShutdownInhibitions);
@ -836,7 +817,7 @@ void virNetServerRemoveShutdownInhibition(virNetServerPtr srv)
if (srv->autoShutdownInhibitions == 0)
VIR_FORCE_CLOSE(srv->autoShutdownInhibitFd);
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
@ -879,7 +860,7 @@ virNetServerSignalEvent(int watch,
siginfo_t siginfo;
int i;
virNetServerLock(srv);
virObjectLock(srv);
if (saferead(srv->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
virReportSystemError(errno, "%s",
@ -893,7 +874,7 @@ virNetServerSignalEvent(int watch,
if (siginfo.si_signo == srv->signals[i]->signum) {
virNetServerSignalFunc func = srv->signals[i]->func;
void *funcopaque = srv->signals[i]->opaque;
virNetServerUnlock(srv);
virObjectUnlock(srv);
func(srv, &siginfo, funcopaque);
return;
}
@ -903,7 +884,7 @@ virNetServerSignalEvent(int watch,
_("Unexpected signal received: %d"), siginfo.si_signo);
cleanup:
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
static int virNetServerSignalSetup(virNetServerPtr srv)
@ -948,7 +929,7 @@ int virNetServerAddSignalHandler(virNetServerPtr srv,
virNetServerSignalPtr sigdata;
struct sigaction sig_action;
virNetServerLock(srv);
virObjectLock(srv);
if (virNetServerSignalSetup(srv) < 0)
goto error;
@ -972,14 +953,14 @@ int virNetServerAddSignalHandler(virNetServerPtr srv,
srv->signals[srv->nsignals-1] = sigdata;
virNetServerUnlock(srv);
virObjectUnlock(srv);
return 0;
no_memory:
virReportOOMError();
error:
VIR_FREE(sigdata);
virNetServerUnlock(srv);
virObjectUnlock(srv);
return -1;
}
@ -989,7 +970,7 @@ int virNetServerAddService(virNetServerPtr srv,
virNetServerServicePtr svc,
const char *mdnsEntryName)
{
virNetServerLock(srv);
virObjectLock(srv);
if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0)
goto no_memory;
@ -1010,32 +991,32 @@ int virNetServerAddService(virNetServerPtr srv,
virNetServerDispatchNewClient,
srv);
virNetServerUnlock(srv);
virObjectUnlock(srv);
return 0;
no_memory:
virReportOOMError();
error:
virNetServerUnlock(srv);
virObjectUnlock(srv);
return -1;
}
int virNetServerAddProgram(virNetServerPtr srv,
virNetServerProgramPtr prog)
{
virNetServerLock(srv);
virObjectLock(srv);
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0)
goto no_memory;
srv->programs[srv->nprograms-1] = virObjectRef(prog);
virNetServerUnlock(srv);
virObjectUnlock(srv);
return 0;
no_memory:
virReportOOMError();
virNetServerUnlock(srv);
virObjectUnlock(srv);
return -1;
}
@ -1053,14 +1034,14 @@ static void virNetServerAutoShutdownTimer(int timerid ATTRIBUTE_UNUSED,
void *opaque) {
virNetServerPtr srv = opaque;
virNetServerLock(srv);
virObjectLock(srv);
if (!srv->autoShutdownInhibitions) {
VIR_DEBUG("Automatic shutdown triggered");
srv->quit = 1;
}
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
@ -1069,11 +1050,11 @@ void virNetServerUpdateServices(virNetServerPtr srv,
{
int i;
virNetServerLock(srv);
virObjectLock(srv);
for (i = 0 ; i < srv->nservices ; i++)
virNetServerServiceToggle(srv->services[i], enabled);
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
@ -1083,7 +1064,7 @@ void virNetServerRun(virNetServerPtr srv)
int timerActive = 0;
int i;
virNetServerLock(srv);
virObjectLock(srv);
if (srv->mdns &&
virNetServerMDNSStart(srv->mdns) < 0)
@ -1123,13 +1104,13 @@ void virNetServerRun(virNetServerPtr srv)
}
}
virNetServerUnlock(srv);
virObjectUnlock(srv);
if (virEventRunDefaultImpl() < 0) {
virNetServerLock(srv);
virObjectLock(srv);
VIR_DEBUG("Loop iteration error, exiting");
break;
}
virNetServerLock(srv);
virObjectLock(srv);
reprocess:
for (i = 0 ; i < srv->nclients ; i++) {
@ -1156,18 +1137,18 @@ void virNetServerRun(virNetServerPtr srv)
}
cleanup:
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
void virNetServerQuit(virNetServerPtr srv)
{
virNetServerLock(srv);
virObjectLock(srv);
VIR_DEBUG("Quit requested %p", srv);
srv->quit = 1;
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
void virNetServerDispose(void *obj)
@ -1208,8 +1189,6 @@ void virNetServerDispose(void *obj)
VIR_FREE(srv->mdnsGroupName);
virNetServerMDNSFree(srv->mdns);
virMutexDestroy(&srv->lock);
}
void virNetServerClose(virNetServerPtr srv)
@ -1219,20 +1198,20 @@ void virNetServerClose(virNetServerPtr srv)
if (!srv)
return;
virNetServerLock(srv);
virObjectLock(srv);
for (i = 0; i < srv->nservices; i++) {
virNetServerServiceClose(srv->services[i]);
}
virNetServerUnlock(srv);
virObjectUnlock(srv);
}
bool virNetServerKeepAliveRequired(virNetServerPtr srv)
{
bool required;
virNetServerLock(srv);
virObjectLock(srv);
required = srv->keepaliveRequired;
virNetServerUnlock(srv);
virObjectUnlock(srv);
return required;
}

View File

@ -57,11 +57,10 @@ struct _virNetServerClientFilter {
struct _virNetServerClient
{
virObject object;
virObjectLockable parent;
bool wantClose;
bool delayedClose;
virMutex lock;
virNetSocketPtr sock;
int auth;
bool readonly;
@ -112,7 +111,7 @@ static void virNetServerClientDispose(void *obj);
static int virNetServerClientOnceInit(void)
{
if (!(virNetServerClientClass = virClassNew(virClassForObject(),
if (!(virNetServerClientClass = virClassNew(virClassForObjectLockable(),
"virNetServerClient",
sizeof(virNetServerClient),
virNetServerClientDispose)))
@ -130,17 +129,6 @@ static void virNetServerClientDispatchRead(virNetServerClientPtr client);
static int virNetServerClientSendMessageLocked(virNetServerClientPtr client,
virNetMessagePtr msg);
static void virNetServerClientLock(virNetServerClientPtr client)
{
virMutexLock(&client->lock);
}
static void virNetServerClientUnlock(virNetServerClientPtr client)
{
virMutexUnlock(&client->lock);
}
/*
* @client: a locked client object
*/
@ -253,7 +241,7 @@ int virNetServerClientAddFilter(virNetServerClientPtr client,
return -1;
}
virNetServerClientLock(client);
virObjectLock(client);
filter->id = client->nextFilterID++;
filter->func = func;
@ -266,7 +254,7 @@ int virNetServerClientAddFilter(virNetServerClientPtr client,
ret = filter->id;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return ret;
}
@ -276,7 +264,7 @@ void virNetServerClientRemoveFilter(virNetServerClientPtr client,
{
virNetServerClientFilterPtr tmp, prev;
virNetServerClientLock(client);
virObjectLock(client);
prev = NULL;
tmp = client->filters;
@ -294,7 +282,7 @@ void virNetServerClientRemoveFilter(virNetServerClientPtr client,
tmp = tmp->next;
}
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
@ -341,13 +329,13 @@ static void virNetServerClientSockTimerFunc(int timer,
void *opaque)
{
virNetServerClientPtr client = opaque;
virNetServerClientLock(client);
virObjectLock(client);
virEventUpdateTimeout(timer, -1);
/* Although client->rx != NULL when this timer is enabled, it might have
* changed since the client was unlocked in the meantime. */
if (client->rx)
virNetServerClientDispatchRead(client);
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
@ -365,14 +353,9 @@ virNetServerClientNewInternal(virNetSocketPtr sock,
if (virNetServerClientInitialize() < 0)
return NULL;
if (!(client = virObjectNew(virNetServerClientClass)))
if (!(client = virObjectLockableNew(virNetServerClientClass)))
return NULL;
if (virMutexInit(&client->lock) < 0) {
VIR_FREE(client);
return NULL;
}
client->sock = virObjectRef(sock);
client->auth = auth;
client->readonly = readonly;
@ -544,7 +527,7 @@ virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
if (!object)
return NULL;
virNetServerClientLock(client);
virObjectLock(client);
if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < 0)
goto error;
@ -574,11 +557,11 @@ virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
goto error;
}
virNetServerClientUnlock(client);
virObjectUnlock(client);
return object;
error:
virNetServerClientUnlock(client);
virObjectUnlock(client);
virJSONValueFree(object);
return NULL;
}
@ -587,18 +570,18 @@ error:
int virNetServerClientGetAuth(virNetServerClientPtr client)
{
int auth;
virNetServerClientLock(client);
virObjectLock(client);
auth = client->auth;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return auth;
}
bool virNetServerClientGetReadonly(virNetServerClientPtr client)
{
bool readonly;
virNetServerClientLock(client);
virObjectLock(client);
readonly = client->readonly;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return readonly;
}
@ -607,19 +590,19 @@ bool virNetServerClientGetReadonly(virNetServerClientPtr client)
bool virNetServerClientHasTLSSession(virNetServerClientPtr client)
{
bool has;
virNetServerClientLock(client);
virObjectLock(client);
has = client->tls ? true : false;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return has;
}
int virNetServerClientGetTLSKeySize(virNetServerClientPtr client)
{
int size = 0;
virNetServerClientLock(client);
virObjectLock(client);
if (client->tls)
size = virNetTLSSessionGetKeySize(client->tls);
virNetServerClientUnlock(client);
virObjectUnlock(client);
return size;
}
#endif
@ -627,10 +610,10 @@ int virNetServerClientGetTLSKeySize(virNetServerClientPtr client)
int virNetServerClientGetFD(virNetServerClientPtr client)
{
int fd = -1;
virNetServerClientLock(client);
virObjectLock(client);
if (client->sock)
fd = virNetSocketGetFD(client->sock);
virNetServerClientUnlock(client);
virObjectUnlock(client);
return fd;
}
@ -638,17 +621,17 @@ int virNetServerClientGetUNIXIdentity(virNetServerClientPtr client,
uid_t *uid, gid_t *gid, pid_t *pid)
{
int ret = -1;
virNetServerClientLock(client);
virObjectLock(client);
if (client->sock)
ret = virNetSocketGetUNIXIdentity(client->sock, uid, gid, pid);
virNetServerClientUnlock(client);
virObjectUnlock(client);
return ret;
}
bool virNetServerClientIsSecure(virNetServerClientPtr client)
{
bool secure = false;
virNetServerClientLock(client);
virObjectLock(client);
#if WITH_GNUTLS
if (client->tls)
secure = true;
@ -659,7 +642,7 @@ bool virNetServerClientIsSecure(virNetServerClientPtr client)
#endif
if (client->sock && virNetSocketIsLocal(client->sock))
secure = true;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return secure;
}
@ -673,9 +656,9 @@ void virNetServerClientSetSASLSession(virNetServerClientPtr client,
* in the clear. Only once we complete the next 'tx'
* operation do we switch to SASL mode
*/
virNetServerClientLock(client);
virObjectLock(client);
client->sasl = virObjectRef(sasl);
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
#endif
@ -684,7 +667,7 @@ int virNetServerClientSetIdentity(virNetServerClientPtr client,
const char *identity)
{
int ret = -1;
virNetServerClientLock(client);
virObjectLock(client);
if (!(client->identity = strdup(identity))) {
virReportOOMError();
goto error;
@ -692,16 +675,16 @@ int virNetServerClientSetIdentity(virNetServerClientPtr client,
ret = 0;
error:
virNetServerClientUnlock(client);
virObjectUnlock(client);
return ret;
}
const char *virNetServerClientGetIdentity(virNetServerClientPtr client)
{
const char *identity;
virNetServerClientLock(client);
virObjectLock(client);
identity = client->identity;
virNetServerClientLock(client);
virObjectUnlock(client);
return identity;
}
@ -709,9 +692,9 @@ const char *virNetServerClientGetIdentity(virNetServerClientPtr client)
void *virNetServerClientGetPrivateData(virNetServerClientPtr client)
{
void *data;
virNetServerClientLock(client);
virObjectLock(client);
data = client->privateData;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return data;
}
@ -719,9 +702,9 @@ void *virNetServerClientGetPrivateData(virNetServerClientPtr client)
void virNetServerClientSetCloseHook(virNetServerClientPtr client,
virNetServerClientCloseFunc cf)
{
virNetServerClientLock(client);
virObjectLock(client);
client->privateDataCloseFunc = cf;
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
@ -729,10 +712,10 @@ void virNetServerClientSetDispatcher(virNetServerClientPtr client,
virNetServerClientDispatchFunc func,
void *opaque)
{
virNetServerClientLock(client);
virObjectLock(client);
client->dispatchFunc = func;
client->dispatchOpaque = opaque;
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
@ -771,8 +754,7 @@ void virNetServerClientDispose(void *obj)
virObjectUnref(client->tlsCtxt);
#endif
virObjectUnref(client->sock);
virNetServerClientUnlock(client);
virMutexDestroy(&client->lock);
virObjectUnlock(client);
}
@ -789,10 +771,10 @@ void virNetServerClientClose(virNetServerClientPtr client)
virNetServerClientCloseFunc cf;
virKeepAlivePtr ka;
virNetServerClientLock(client);
virObjectLock(client);
VIR_DEBUG("client=%p", client);
if (!client->sock) {
virNetServerClientUnlock(client);
virObjectUnlock(client);
return;
}
@ -801,18 +783,18 @@ void virNetServerClientClose(virNetServerClientPtr client)
ka = client->keepalive;
client->keepalive = NULL;
virObjectRef(client);
virNetServerClientUnlock(client);
virObjectUnlock(client);
virObjectUnref(ka);
virNetServerClientLock(client);
virObjectLock(client);
virObjectUnref(client);
}
if (client->privateDataCloseFunc) {
cf = client->privateDataCloseFunc;
virObjectRef(client);
virNetServerClientUnlock(client);
virObjectUnlock(client);
(cf)(client);
virNetServerClientLock(client);
virObjectLock(client);
virObjectUnref(client);
}
@ -846,46 +828,46 @@ void virNetServerClientClose(virNetServerClientPtr client)
client->sock = NULL;
}
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
bool virNetServerClientIsClosed(virNetServerClientPtr client)
{
bool closed;
virNetServerClientLock(client);
virObjectLock(client);
closed = client->sock == NULL ? true : false;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return closed;
}
void virNetServerClientDelayedClose(virNetServerClientPtr client)
{
virNetServerClientLock(client);
virObjectLock(client);
client->delayedClose = true;
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
void virNetServerClientImmediateClose(virNetServerClientPtr client)
{
virNetServerClientLock(client);
virObjectLock(client);
client->wantClose = true;
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
bool virNetServerClientWantClose(virNetServerClientPtr client)
{
bool wantClose;
virNetServerClientLock(client);
virObjectLock(client);
wantClose = client->wantClose;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return wantClose;
}
int virNetServerClientInit(virNetServerClientPtr client)
{
virNetServerClientLock(client);
virObjectLock(client);
#if WITH_GNUTLS
if (!client->tlsCtxt) {
@ -924,12 +906,12 @@ int virNetServerClientInit(virNetServerClientPtr client)
}
#endif
virNetServerClientUnlock(client);
virObjectUnlock(client);
return 0;
error:
client->wantClose = true;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return -1;
}
@ -1255,11 +1237,11 @@ virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque)
{
virNetServerClientPtr client = opaque;
virNetServerClientLock(client);
virObjectLock(client);
if (client->sock != sock) {
virNetSocketRemoveIOCallback(sock);
virNetServerClientUnlock(client);
virObjectUnlock(client);
return;
}
@ -1288,7 +1270,7 @@ virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque)
VIR_EVENT_HANDLE_HANGUP))
client->wantClose = true;
virNetServerClientUnlock(client);
virObjectUnlock(client);
}
@ -1322,9 +1304,9 @@ int virNetServerClientSendMessage(virNetServerClientPtr client,
{
int ret;
virNetServerClientLock(client);
virObjectLock(client);
ret = virNetServerClientSendMessageLocked(client, msg);
virNetServerClientUnlock(client);
virObjectUnlock(client);
return ret;
}
@ -1333,10 +1315,10 @@ int virNetServerClientSendMessage(virNetServerClientPtr client,
bool virNetServerClientNeedAuth(virNetServerClientPtr client)
{
bool need = false;
virNetServerClientLock(client);
virObjectLock(client);
if (client->auth && !client->identity)
need = true;
virNetServerClientUnlock(client);
virObjectUnlock(client);
return need;
}
@ -1363,7 +1345,7 @@ virNetServerClientInitKeepAlive(virNetServerClientPtr client,
virKeepAlivePtr ka;
int ret = -1;
virNetServerClientLock(client);
virObjectLock(client);
if (!(ka = virKeepAliveNew(interval, count, client,
virNetServerClientKeepAliveSendCB,
@ -1377,7 +1359,7 @@ virNetServerClientInitKeepAlive(virNetServerClientPtr client,
ka = NULL;
cleanup:
virNetServerClientUnlock(client);
virObjectUnlock(client);
if (ka)
virKeepAliveStop(ka);
virObjectUnref(ka);
@ -1389,8 +1371,8 @@ int
virNetServerClientStartKeepAlive(virNetServerClientPtr client)
{
int ret;
virNetServerClientLock(client);
virObjectLock(client);
ret = virKeepAliveStart(client->keepalive, 0, 0);
virNetServerClientUnlock(client);
virObjectUnlock(client);
return ret;
}

View File

@ -59,9 +59,7 @@
struct _virNetSocket {
virObject object;
virMutex lock;
virObjectLockable parent;
int fd;
int watch;
@ -104,7 +102,7 @@ static void virNetSocketDispose(void *obj);
static int virNetSocketOnceInit(void)
{
if (!(virNetSocketClass = virClassNew(virClassForObject(),
if (!(virNetSocketClass = virClassNew(virClassForObjectLockable(),
"virNetSocket",
sizeof(virNetSocket),
virNetSocketDispose)))
@ -163,16 +161,9 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
return NULL;
}
if (!(sock = virObjectNew(virNetSocketClass)))
if (!(sock = virObjectLockableNew(virNetSocketClass)))
return NULL;
if (virMutexInit(&sock->lock) < 0) {
virReportSystemError(errno, "%s",
_("Unable to initialize mutex"));
VIR_FREE(sock);
return NULL;
}
if (localAddr)
sock->localAddr = *localAddr;
if (remoteAddr)
@ -944,7 +935,7 @@ virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock)
{
virJSONValuePtr object = NULL;
virMutexLock(&sock->lock);
virObjectLock(sock);
#if WITH_SASL
if (sock->saslSession) {
@ -990,11 +981,11 @@ virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock)
goto error;
}
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return object;
error:
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
virJSONValueFree(object);
return NULL;
}
@ -1039,17 +1030,15 @@ void virNetSocketDispose(void *obj)
VIR_FREE(sock->localAddrStr);
VIR_FREE(sock->remoteAddrStr);
virMutexDestroy(&sock->lock);
}
int virNetSocketGetFD(virNetSocketPtr sock)
{
int fd;
virMutexLock(&sock->lock);
virObjectLock(sock);
fd = sock->fd;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return fd;
}
@ -1074,10 +1063,10 @@ int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
bool virNetSocketIsLocal(virNetSocketPtr sock)
{
bool isLocal = false;
virMutexLock(&sock->lock);
virObjectLock(sock);
if (sock->localAddr.data.sa.sa_family == AF_UNIX)
isLocal = true;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return isLocal;
}
@ -1085,10 +1074,10 @@ bool virNetSocketIsLocal(virNetSocketPtr sock)
bool virNetSocketHasPassFD(virNetSocketPtr sock)
{
bool hasPassFD = false;
virMutexLock(&sock->lock);
virObjectLock(sock);
if (sock->localAddr.data.sa.sa_family == AF_UNIX)
hasPassFD = true;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return hasPassFD;
}
@ -1096,9 +1085,9 @@ bool virNetSocketHasPassFD(virNetSocketPtr sock)
int virNetSocketGetPort(virNetSocketPtr sock)
{
int port;
virMutexLock(&sock->lock);
virObjectLock(sock);
port = virSocketAddrGetPort(&sock->localAddr);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return port;
}
@ -1111,12 +1100,12 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
{
struct ucred cr;
socklen_t cr_len = sizeof(cr);
virMutexLock(&sock->lock);
virObjectLock(sock);
if (getsockopt(sock->fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) < 0) {
virReportSystemError(errno, "%s",
_("Failed to get client socket identity"));
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return -1;
}
@ -1124,7 +1113,7 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
*uid = cr.uid;
*gid = cr.gid;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return 0;
}
#elif defined(LOCAL_PEERCRED)
@ -1135,12 +1124,12 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
{
struct xucred cr;
socklen_t cr_len = sizeof(cr);
virMutexLock(&sock->lock);
virObjectLock(sock);
if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr, &cr_len) < 0) {
virReportSystemError(errno, "%s",
_("Failed to get client socket identity"));
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return -1;
}
@ -1148,7 +1137,7 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
*uid = cr.cr_uid;
*gid = cr.cr_gid;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return 0;
}
#else
@ -1169,9 +1158,9 @@ int virNetSocketSetBlocking(virNetSocketPtr sock,
bool blocking)
{
int ret;
virMutexLock(&sock->lock);
virObjectLock(sock);
ret = virSetBlocking(sock->fd, blocking);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return ret;
}
@ -1209,14 +1198,14 @@ static ssize_t virNetSocketTLSSessionRead(char *buf,
void virNetSocketSetTLSSession(virNetSocketPtr sock,
virNetTLSSessionPtr sess)
{
virMutexLock(&sock->lock);
virObjectLock(sock);
virObjectUnref(sock->tlsSession);
sock->tlsSession = virObjectRef(sess);
virNetTLSSessionSetIOCallbacks(sess,
virNetSocketTLSSessionWrite,
virNetSocketTLSSessionRead,
sock);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
}
#endif
@ -1224,10 +1213,10 @@ void virNetSocketSetTLSSession(virNetSocketPtr sock,
void virNetSocketSetSASLSession(virNetSocketPtr sock,
virNetSASLSessionPtr sess)
{
virMutexLock(&sock->lock);
virObjectLock(sock);
virObjectUnref(sock->saslSession);
sock->saslSession = virObjectRef(sess);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
}
#endif
@ -1235,7 +1224,7 @@ void virNetSocketSetSASLSession(virNetSocketPtr sock,
bool virNetSocketHasCachedData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
{
bool hasCached = false;
virMutexLock(&sock->lock);
virObjectLock(sock);
#if WITH_SSH2
if (virNetSSHSessionHasCachedData(sock->sshSession))
@ -1246,7 +1235,7 @@ bool virNetSocketHasCachedData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
if (sock->saslDecoded)
hasCached = true;
#endif
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return hasCached;
}
@ -1269,12 +1258,12 @@ static ssize_t virNetSocketLibSSH2Write(virNetSocketPtr sock,
bool virNetSocketHasPendingData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
{
bool hasPending = false;
virMutexLock(&sock->lock);
virObjectLock(sock);
#if WITH_SASL
if (sock->saslEncoded)
hasPending = true;
#endif
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return hasPending;
}
@ -1483,14 +1472,14 @@ static ssize_t virNetSocketWriteSASL(virNetSocketPtr sock, const char *buf, size
ssize_t virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len)
{
ssize_t ret;
virMutexLock(&sock->lock);
virObjectLock(sock);
#if WITH_SASL
if (sock->saslSession)
ret = virNetSocketReadSASL(sock, buf, len);
else
#endif
ret = virNetSocketReadWire(sock, buf, len);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return ret;
}
@ -1498,14 +1487,14 @@ ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len)
{
ssize_t ret;
virMutexLock(&sock->lock);
virObjectLock(sock);
#if WITH_SASL
if (sock->saslSession)
ret = virNetSocketWriteSASL(sock, buf, len);
else
#endif
ret = virNetSocketWriteWire(sock, buf, len);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return ret;
}
@ -1521,7 +1510,7 @@ int virNetSocketSendFD(virNetSocketPtr sock, int fd)
_("Sending file descriptors is not supported on this socket"));
return -1;
}
virMutexLock(&sock->lock);
virObjectLock(sock);
PROBE(RPC_SOCKET_SEND_FD,
"sock=%p fd=%d", sock, fd);
if (sendfd(sock->fd, fd) < 0) {
@ -1536,7 +1525,7 @@ int virNetSocketSendFD(virNetSocketPtr sock, int fd)
ret = 1;
cleanup:
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return ret;
}
@ -1555,7 +1544,7 @@ int virNetSocketRecvFD(virNetSocketPtr sock, int *fd)
_("Receiving file descriptors is not supported on this socket"));
return -1;
}
virMutexLock(&sock->lock);
virObjectLock(sock);
if ((*fd = recvfd(sock->fd, O_CLOEXEC)) < 0) {
if (errno == EAGAIN)
@ -1570,20 +1559,20 @@ int virNetSocketRecvFD(virNetSocketPtr sock, int *fd)
ret = 1;
cleanup:
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return ret;
}
int virNetSocketListen(virNetSocketPtr sock, int backlog)
{
virMutexLock(&sock->lock);
virObjectLock(sock);
if (listen(sock->fd, backlog > 0 ? backlog : 30) < 0) {
virReportSystemError(errno, "%s", _("Unable to listen on socket"));
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return -1;
}
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return 0;
}
@ -1594,7 +1583,7 @@ int virNetSocketAccept(virNetSocketPtr sock, virNetSocketPtr *clientsock)
virSocketAddr remoteAddr;
int ret = -1;
virMutexLock(&sock->lock);
virObjectLock(sock);
*clientsock = NULL;
@ -1631,7 +1620,7 @@ int virNetSocketAccept(virNetSocketPtr sock, virNetSocketPtr *clientsock)
cleanup:
VIR_FORCE_CLOSE(fd);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return ret;
}
@ -1645,10 +1634,10 @@ static void virNetSocketEventHandle(int watch ATTRIBUTE_UNUSED,
virNetSocketIOFunc func;
void *eopaque;
virMutexLock(&sock->lock);
virObjectLock(sock);
func = sock->func;
eopaque = sock->opaque;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
if (func)
func(sock, events, eopaque);
@ -1661,13 +1650,13 @@ static void virNetSocketEventFree(void *opaque)
virFreeCallback ff;
void *eopaque;
virMutexLock(&sock->lock);
virObjectLock(sock);
ff = sock->ff;
eopaque = sock->opaque;
sock->func = NULL;
sock->ff = NULL;
sock->opaque = NULL;
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
if (ff)
ff(eopaque);
@ -1684,7 +1673,7 @@ int virNetSocketAddIOCallback(virNetSocketPtr sock,
int ret = -1;
virObjectRef(sock);
virMutexLock(&sock->lock);
virObjectLock(sock);
if (sock->watch > 0) {
VIR_DEBUG("Watch already registered on socket %p", sock);
goto cleanup;
@ -1705,7 +1694,7 @@ int virNetSocketAddIOCallback(virNetSocketPtr sock,
ret = 0;
cleanup:
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
if (ret != 0)
virObjectUnref(sock);
return ret;
@ -1714,31 +1703,31 @@ cleanup:
void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
int events)
{
virMutexLock(&sock->lock);
virObjectLock(sock);
if (sock->watch <= 0) {
VIR_DEBUG("Watch not registered on socket %p", sock);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return;
}
virEventUpdateHandle(sock->watch, events);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
}
void virNetSocketRemoveIOCallback(virNetSocketPtr sock)
{
virMutexLock(&sock->lock);
virObjectLock(sock);
if (sock->watch <= 0) {
VIR_DEBUG("Watch not registered on socket %p", sock);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
return;
}
virEventRemoveHandle(sock->watch);
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
}
void virNetSocketClose(virNetSocketPtr sock)
@ -1746,7 +1735,7 @@ void virNetSocketClose(virNetSocketPtr sock)
if (!sock)
return;
virMutexLock(&sock->lock);
virObjectLock(sock);
VIR_FORCE_CLOSE(sock->fd);
@ -1760,5 +1749,5 @@ void virNetSocketClose(virNetSocketPtr sock)
}
#endif
virMutexUnlock(&sock->lock);
virObjectUnlock(sock);
}

View File

@ -78,9 +78,8 @@ struct _virNetSSHAuthMethod {
};
struct _virNetSSHSession {
virObject object;
virObjectLockable parent;
virNetSSHSessionState state;
virMutex lock;
/* libssh2 internal stuff */
LIBSSH2_SESSION *session;
@ -161,7 +160,7 @@ static virClassPtr virNetSSHSessionClass;
static int
virNetSSHSessionOnceInit(void)
{
if (!(virNetSSHSessionClass = virClassNew(virClassForObject(),
if (!(virNetSSHSessionClass = virClassNew(virClassForObjectLockable(),
"virNetSSHSession",
sizeof(virNetSSHSession),
virNetSSHSessionDispose)))
@ -927,18 +926,18 @@ int
virNetSSHSessionAuthSetCallback(virNetSSHSessionPtr sess,
virConnectAuthPtr auth)
{
virMutexLock(&sess->lock);
virObjectLock(sess);
sess->cred = auth;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return 0;
}
void
virNetSSHSessionAuthReset(virNetSSHSessionPtr sess)
{
virMutexLock(&sess->lock);
virObjectLock(sess);
virNetSSHSessionAuthMethodsFree(sess);
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
}
int
@ -957,7 +956,7 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
return -1;
}
virMutexLock(&sess->lock);
virObjectLock(sess);
if (!(user = strdup(username)) ||
!(pass = strdup(password)))
@ -970,14 +969,14 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
auth->password = pass;
auth->method = VIR_NET_SSH_AUTH_PASSWORD;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return 0;
no_memory:
VIR_FREE(user);
VIR_FREE(pass);
virReportOOMError();
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
@ -995,7 +994,7 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
return -1;
}
virMutexLock(&sess->lock);
virObjectLock(sess);
if (!(user = strdup(username)))
goto no_memory;
@ -1006,13 +1005,13 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
auth->username = user;
auth->method = VIR_NET_SSH_AUTH_AGENT;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return 0;
no_memory:
VIR_FREE(user);
virReportOOMError();
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
@ -1035,7 +1034,7 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
return -1;
}
virMutexLock(&sess->lock);
virObjectLock(sess);
if (!(user = strdup(username)) ||
!(file = strdup(keyfile)))
@ -1052,7 +1051,7 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
auth->filename = file;
auth->method = VIR_NET_SSH_AUTH_PRIVKEY;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return 0;
no_memory:
@ -1060,7 +1059,7 @@ no_memory:
VIR_FREE(pass);
VIR_FREE(file);
virReportOOMError();
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
@ -1079,7 +1078,7 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
return -1;
}
virMutexLock(&sess->lock);
virObjectLock(sess);
if (!(user = strdup(username)))
goto no_memory;
@ -1091,13 +1090,13 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
auth->tries = tries;
auth->method = VIR_NET_SSH_AUTH_KEYBOARD_INTERACTIVE;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return 0;
no_memory:
VIR_FREE(user);
virReportOOMError();
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
@ -1107,7 +1106,7 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess,
const char *command)
{
int ret = 0;
virMutexLock(&sess->lock);
virObjectLock(sess);
VIR_FREE(sess->channelCommand);
@ -1116,7 +1115,7 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess,
ret = -1;
}
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1130,7 +1129,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
{
char *errmsg;
virMutexLock(&sess->lock);
virObjectLock(sess);
sess->port = port;
sess->hostKeyVerify = opt;
@ -1167,13 +1166,13 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
}
}
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return 0;
no_memory:
virReportOOMError();
error:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
@ -1185,16 +1184,9 @@ virNetSSHSessionPtr virNetSSHSessionNew(void)
if (virNetSSHSessionInitialize() < 0)
goto error;
if (!(sess = virObjectNew(virNetSSHSessionClass)))
if (!(sess = virObjectLockableNew(virNetSSHSessionClass)))
goto error;
/* initialize internal structures */
if (virMutexInit(&sess->lock) < 0) {
virReportError(VIR_ERR_SSH, "%s",
_("Failed to initialize mutex"));
goto error;
}
/* initialize session data, use the internal data for callbacks
* and stick to default memory management functions */
if (!(sess->session = libssh2_session_init_ex(NULL,
@ -1250,7 +1242,7 @@ virNetSSHSessionConnect(virNetSSHSessionPtr sess,
return -1;
}
virMutexLock(&sess->lock);
virObjectLock(sess);
/* check if configuration is valid */
if ((ret = virNetSSHValidateConfig(sess)) < 0)
@ -1284,12 +1276,12 @@ virNetSSHSessionConnect(virNetSSHSessionPtr sess,
libssh2_session_set_blocking(sess->session, 0);
sess->state = VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
error:
sess->state = VIR_NET_SSH_STATE_ERROR;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1302,7 +1294,7 @@ virNetSSHChannelRead(virNetSSHSessionPtr sess,
ssize_t ret = -1;
ssize_t read_n = 0;
virMutexLock(&sess->lock);
virObjectLock(sess);
if (sess->state != VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE) {
if (sess->state == VIR_NET_SSH_STATE_ERROR_REMOTE)
@ -1314,7 +1306,7 @@ virNetSSHChannelRead(virNetSSHSessionPtr sess,
virReportError(VIR_ERR_SSH, "%s",
_("Tried to write socket in error state"));
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
@ -1387,22 +1379,22 @@ virNetSSHChannelRead(virNetSSHSessionPtr sess,
libssh2_channel_get_exit_status(sess->channel));
sess->channelCommandReturnValue = libssh2_channel_get_exit_status(sess->channel);
sess->state = VIR_NET_SSH_STATE_ERROR_REMOTE;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
sess->state = VIR_NET_SSH_STATE_CLOSED;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return -1;
}
success:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return read_n;
error:
sess->state = VIR_NET_SSH_STATE_ERROR;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1413,7 +1405,7 @@ virNetSSHChannelWrite(virNetSSHSessionPtr sess,
{
ssize_t ret;
virMutexLock(&sess->lock);
virObjectLock(sess);
if (sess->state != VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE) {
if (sess->state == VIR_NET_SSH_STATE_ERROR_REMOTE)
@ -1459,7 +1451,7 @@ virNetSSHChannelWrite(virNetSSHSessionPtr sess,
}
cleanup:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1471,10 +1463,10 @@ virNetSSHSessionHasCachedData(virNetSSHSessionPtr sess)
if (!sess)
return false;
virMutexLock(&sess->lock);
virObjectLock(sess);
ret = sess->bufUsed > 0;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}

View File

@ -50,9 +50,7 @@
#define VIR_FROM_THIS VIR_FROM_RPC
struct _virNetTLSContext {
virObject object;
virMutex lock;
virObjectLockable parent;
gnutls_certificate_credentials_t x509cred;
gnutls_dh_params_t dhParams;
@ -63,9 +61,7 @@ struct _virNetTLSContext {
};
struct _virNetTLSSession {
virObject object;
virMutex lock;
virObjectLockable parent;
bool handshakeComplete;
@ -85,13 +81,13 @@ static void virNetTLSSessionDispose(void *obj);
static int virNetTLSContextOnceInit(void)
{
if (!(virNetTLSContextClass = virClassNew(virClassForObject(),
if (!(virNetTLSContextClass = virClassNew(virClassForObjectLockable(),
"virNetTLSContext",
sizeof(virNetTLSContext),
virNetTLSContextDispose)))
return -1;
if (!(virNetTLSSessionClass = virClassNew(virClassForObject(),
if (!(virNetTLSSessionClass = virClassNew(virClassForObjectLockable(),
"virNetTLSSession",
sizeof(virNetTLSSession),
virNetTLSSessionDispose)))
@ -676,16 +672,9 @@ static virNetTLSContextPtr virNetTLSContextNew(const char *cacert,
if (virNetTLSContextInitialize() < 0)
return NULL;
if (!(ctxt = virObjectNew(virNetTLSContextClass)))
if (!(ctxt = virObjectLockableNew(virNetTLSContextClass)))
return NULL;
if (virMutexInit(&ctxt->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to initialized mutex"));
VIR_FREE(ctxt);
return NULL;
}
if ((gnutlsdebug = getenv("LIBVIRT_GNUTLS_DEBUG")) != NULL) {
int val;
if (virStrToLong_i(gnutlsdebug, NULL, 10, &val) < 0)
@ -1097,8 +1086,8 @@ int virNetTLSContextCheckCertificate(virNetTLSContextPtr ctxt,
{
int ret = -1;
virMutexLock(&ctxt->lock);
virMutexLock(&sess->lock);
virObjectLock(ctxt);
virObjectLock(sess);
if (virNetTLSContextValidCertificate(ctxt, sess) < 0) {
virErrorPtr err = virGetLastError();
VIR_WARN("Certificate check failed %s", err && err->message ? err->message : "<unknown>");
@ -1114,8 +1103,8 @@ int virNetTLSContextCheckCertificate(virNetTLSContextPtr ctxt,
ret = 0;
cleanup:
virMutexUnlock(&ctxt->lock);
virMutexUnlock(&sess->lock);
virObjectUnlock(ctxt);
virObjectUnlock(sess);
return ret;
}
@ -1126,7 +1115,6 @@ void virNetTLSContextDispose(void *obj)
gnutls_dh_params_deinit(ctxt->dhParams);
gnutls_certificate_free_credentials(ctxt->x509cred);
virMutexDestroy(&ctxt->lock);
}
@ -1167,16 +1155,9 @@ virNetTLSSessionPtr virNetTLSSessionNew(virNetTLSContextPtr ctxt,
VIR_DEBUG("ctxt=%p hostname=%s isServer=%d",
ctxt, NULLSTR(hostname), ctxt->isServer);
if (!(sess = virObjectNew(virNetTLSSessionClass)))
if (!(sess = virObjectLockableNew(virNetTLSSessionClass)))
return NULL;
if (virMutexInit(&sess->lock) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Failed to initialized mutex"));
VIR_FREE(sess);
return NULL;
}
if (hostname &&
!(sess->hostname = strdup(hostname))) {
virReportOOMError();
@ -1243,11 +1224,11 @@ void virNetTLSSessionSetIOCallbacks(virNetTLSSessionPtr sess,
virNetTLSSessionReadFunc readFunc,
void *opaque)
{
virMutexLock(&sess->lock);
virObjectLock(sess);
sess->writeFunc = writeFunc;
sess->readFunc = readFunc;
sess->opaque = opaque;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
}
@ -1256,7 +1237,7 @@ ssize_t virNetTLSSessionWrite(virNetTLSSessionPtr sess,
{
ssize_t ret;
virMutexLock(&sess->lock);
virObjectLock(sess);
ret = gnutls_record_send(sess->session, buf, len);
if (ret >= 0)
@ -1280,7 +1261,7 @@ ssize_t virNetTLSSessionWrite(virNetTLSSessionPtr sess,
ret = -1;
cleanup:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1289,7 +1270,7 @@ ssize_t virNetTLSSessionRead(virNetTLSSessionPtr sess,
{
ssize_t ret;
virMutexLock(&sess->lock);
virObjectLock(sess);
ret = gnutls_record_recv(sess->session, buf, len);
if (ret >= 0)
@ -1310,7 +1291,7 @@ ssize_t virNetTLSSessionRead(virNetTLSSessionPtr sess,
ret = -1;
cleanup:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1318,7 +1299,7 @@ int virNetTLSSessionHandshake(virNetTLSSessionPtr sess)
{
int ret;
VIR_DEBUG("sess=%p", sess);
virMutexLock(&sess->lock);
virObjectLock(sess);
ret = gnutls_handshake(sess->session);
VIR_DEBUG("Ret=%d", ret);
if (ret == 0) {
@ -1342,7 +1323,7 @@ int virNetTLSSessionHandshake(virNetTLSSessionPtr sess)
ret = -1;
cleanup:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1350,14 +1331,14 @@ virNetTLSSessionHandshakeStatus
virNetTLSSessionGetHandshakeStatus(virNetTLSSessionPtr sess)
{
virNetTLSSessionHandshakeStatus ret;
virMutexLock(&sess->lock);
virObjectLock(sess);
if (sess->handshakeComplete)
ret = VIR_NET_TLS_HANDSHAKE_COMPLETE;
else if (gnutls_record_get_direction(sess->session) == 0)
ret = VIR_NET_TLS_HANDSHAKE_RECVING;
else
ret = VIR_NET_TLS_HANDSHAKE_SENDING;
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ret;
}
@ -1365,7 +1346,7 @@ int virNetTLSSessionGetKeySize(virNetTLSSessionPtr sess)
{
gnutls_cipher_algorithm_t cipher;
int ssf;
virMutexLock(&sess->lock);
virObjectLock(sess);
cipher = gnutls_cipher_get(sess->session);
if (!(ssf = gnutls_cipher_get_key_size(cipher))) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@ -1375,7 +1356,7 @@ int virNetTLSSessionGetKeySize(virNetTLSSessionPtr sess)
}
cleanup:
virMutexUnlock(&sess->lock);
virObjectUnlock(sess);
return ssf;
}
@ -1386,7 +1367,6 @@ void virNetTLSSessionDispose(void *obj)
VIR_FREE(sess->hostname);
gnutls_deinit(sess->session);
virMutexDestroy(&sess->lock);
}
/*