mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 13:35:17 +00:00
Convert all rpc classes over to virObjectLockable
This commit is contained in:
parent
325b02b5a3
commit
bba93d40da
@ -35,9 +35,7 @@
|
|||||||
#define VIR_FROM_THIS VIR_FROM_RPC
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
||||||
|
|
||||||
struct _virKeepAlive {
|
struct _virKeepAlive {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
int interval;
|
int interval;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
@ -58,7 +56,7 @@ static void virKeepAliveDispose(void *obj);
|
|||||||
|
|
||||||
static int virKeepAliveOnceInit(void)
|
static int virKeepAliveOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virKeepAliveClass = virClassNew(virClassForObject(),
|
if (!(virKeepAliveClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virKeepAlive",
|
"virKeepAlive",
|
||||||
sizeof(virKeepAlive),
|
sizeof(virKeepAlive),
|
||||||
virKeepAliveDispose)))
|
virKeepAliveDispose)))
|
||||||
@ -69,19 +67,6 @@ static int virKeepAliveOnceInit(void)
|
|||||||
|
|
||||||
VIR_ONCE_GLOBAL_INIT(virKeepAlive)
|
VIR_ONCE_GLOBAL_INIT(virKeepAlive)
|
||||||
|
|
||||||
static void
|
|
||||||
virKeepAliveLock(virKeepAlivePtr ka)
|
|
||||||
{
|
|
||||||
virMutexLock(&ka->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
virKeepAliveUnlock(virKeepAlivePtr ka)
|
|
||||||
{
|
|
||||||
virMutexUnlock(&ka->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static virNetMessagePtr
|
static virNetMessagePtr
|
||||||
virKeepAliveMessage(virKeepAlivePtr ka, int proc)
|
virKeepAliveMessage(virKeepAlivePtr ka, int proc)
|
||||||
{
|
{
|
||||||
@ -174,7 +159,7 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
|||||||
bool dead;
|
bool dead;
|
||||||
void *client;
|
void *client;
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
|
|
||||||
client = ka->client;
|
client = ka->client;
|
||||||
dead = virKeepAliveTimerInternal(ka, &msg);
|
dead = virKeepAliveTimerInternal(ka, &msg);
|
||||||
@ -183,7 +168,7 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
virObjectRef(ka);
|
virObjectRef(ka);
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
|
|
||||||
if (dead) {
|
if (dead) {
|
||||||
ka->deadCB(client);
|
ka->deadCB(client);
|
||||||
@ -192,11 +177,11 @@ virKeepAliveTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
|||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
virObjectUnref(ka);
|
virObjectUnref(ka);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -215,14 +200,9 @@ virKeepAliveNew(int interval,
|
|||||||
if (virKeepAliveInitialize() < 0)
|
if (virKeepAliveInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ka = virObjectNew(virKeepAliveClass)))
|
if (!(ka = virObjectLockableNew(virKeepAliveClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virMutexInit(&ka->lock) < 0) {
|
|
||||||
VIR_FREE(ka);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ka->interval = interval;
|
ka->interval = interval;
|
||||||
ka->count = count;
|
ka->count = count;
|
||||||
ka->countToDeath = count;
|
ka->countToDeath = count;
|
||||||
@ -245,7 +225,6 @@ virKeepAliveDispose(void *obj)
|
|||||||
{
|
{
|
||||||
virKeepAlivePtr ka = obj;
|
virKeepAlivePtr ka = obj;
|
||||||
|
|
||||||
virMutexDestroy(&ka->lock);
|
|
||||||
ka->freeCB(ka->client);
|
ka->freeCB(ka->client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +239,7 @@ virKeepAliveStart(virKeepAlivePtr ka,
|
|||||||
int timeout;
|
int timeout;
|
||||||
time_t now;
|
time_t now;
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
|
|
||||||
if (ka->timer >= 0) {
|
if (ka->timer >= 0) {
|
||||||
VIR_DEBUG("Keepalive messages already enabled");
|
VIR_DEBUG("Keepalive messages already enabled");
|
||||||
@ -306,7 +285,7 @@ virKeepAliveStart(virKeepAlivePtr ka,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -314,7 +293,7 @@ cleanup:
|
|||||||
void
|
void
|
||||||
virKeepAliveStop(virKeepAlivePtr ka)
|
virKeepAliveStop(virKeepAlivePtr ka)
|
||||||
{
|
{
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
|
|
||||||
PROBE(RPC_KEEPALIVE_STOP,
|
PROBE(RPC_KEEPALIVE_STOP,
|
||||||
"ka=%p client=%p",
|
"ka=%p client=%p",
|
||||||
@ -325,7 +304,7 @@ virKeepAliveStop(virKeepAlivePtr ka)
|
|||||||
ka->timer = -1;
|
ka->timer = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -337,7 +316,7 @@ virKeepAliveTimeout(virKeepAlivePtr ka)
|
|||||||
if (!ka)
|
if (!ka)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
|
|
||||||
if (ka->interval <= 0 || ka->intervalStart == 0) {
|
if (ka->interval <= 0 || ka->intervalStart == 0) {
|
||||||
timeout = -1;
|
timeout = -1;
|
||||||
@ -347,7 +326,7 @@ virKeepAliveTimeout(virKeepAlivePtr ka)
|
|||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
|
|
||||||
if (timeout < 0)
|
if (timeout < 0)
|
||||||
return -1;
|
return -1;
|
||||||
@ -366,9 +345,9 @@ virKeepAliveTrigger(virKeepAlivePtr ka,
|
|||||||
if (!ka)
|
if (!ka)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
dead = virKeepAliveTimerInternal(ka, msg);
|
dead = virKeepAliveTimerInternal(ka, msg);
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
|
|
||||||
return dead;
|
return dead;
|
||||||
}
|
}
|
||||||
@ -388,7 +367,7 @@ virKeepAliveCheckMessage(virKeepAlivePtr ka,
|
|||||||
if (!ka)
|
if (!ka)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
virKeepAliveLock(ka);
|
virObjectLock(ka);
|
||||||
|
|
||||||
ka->countToDeath = ka->count;
|
ka->countToDeath = ka->count;
|
||||||
ka->lastPacketReceived = ka->intervalStart = time(NULL);
|
ka->lastPacketReceived = ka->intervalStart = time(NULL);
|
||||||
@ -420,7 +399,7 @@ virKeepAliveCheckMessage(virKeepAlivePtr ka,
|
|||||||
if (ka->timer >= 0)
|
if (ka->timer >= 0)
|
||||||
virEventUpdateTimeout(ka->timer, ka->interval * 1000);
|
virEventUpdateTimeout(ka->timer, ka->interval * 1000);
|
||||||
|
|
||||||
virKeepAliveUnlock(ka);
|
virObjectUnlock(ka);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -63,9 +63,7 @@ struct _virNetClientCall {
|
|||||||
|
|
||||||
|
|
||||||
struct _virNetClient {
|
struct _virNetClient {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
virNetSocketPtr sock;
|
virNetSocketPtr sock;
|
||||||
bool asyncIO;
|
bool asyncIO;
|
||||||
@ -136,28 +134,16 @@ static void virNetClientCloseInternal(virNetClientPtr client,
|
|||||||
int reason);
|
int reason);
|
||||||
|
|
||||||
|
|
||||||
static void virNetClientLock(virNetClientPtr client)
|
|
||||||
{
|
|
||||||
virMutexLock(&client->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void virNetClientUnlock(virNetClientPtr client)
|
|
||||||
{
|
|
||||||
virMutexUnlock(&client->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void virNetClientSetCloseCallback(virNetClientPtr client,
|
void virNetClientSetCloseCallback(virNetClientPtr client,
|
||||||
virNetClientCloseFunc cb,
|
virNetClientCloseFunc cb,
|
||||||
void *opaque,
|
void *opaque,
|
||||||
virFreeCallback ff)
|
virFreeCallback ff)
|
||||||
{
|
{
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
client->closeCb = cb;
|
client->closeCb = cb;
|
||||||
client->closeOpaque = opaque;
|
client->closeOpaque = opaque;
|
||||||
client->closeFf = ff;
|
client->closeFf = ff;
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -261,9 +247,9 @@ virNetClientKeepAliveIsSupported(virNetClientPtr client)
|
|||||||
{
|
{
|
||||||
bool supported;
|
bool supported;
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
supported = !!client->keepalive;
|
supported = !!client->keepalive;
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
|
|
||||||
return supported;
|
return supported;
|
||||||
}
|
}
|
||||||
@ -275,9 +261,9 @@ virNetClientKeepAliveStart(virNetClientPtr client,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
ret = virKeepAliveStart(client->keepalive, interval, count);
|
ret = virKeepAliveStart(client->keepalive, interval, count);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -285,9 +271,9 @@ virNetClientKeepAliveStart(virNetClientPtr client,
|
|||||||
void
|
void
|
||||||
virNetClientKeepAliveStop(virNetClientPtr client)
|
virNetClientKeepAliveStop(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
virKeepAliveStop(client->keepalive);
|
virKeepAliveStop(client->keepalive);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -323,14 +309,9 @@ static virNetClientPtr virNetClientNew(virNetSocketPtr sock,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(client = virObjectNew(virNetClientClass)))
|
if (!(client = virObjectLockableNew(virNetClientClass)))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (virMutexInit(&client->lock) < 0) {
|
|
||||||
VIR_FREE(client);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
client->sock = sock;
|
client->sock = sock;
|
||||||
client->wakeupReadFD = wakeupFD[0];
|
client->wakeupReadFD = wakeupFD[0];
|
||||||
client->wakeupSendFD = wakeupFD[1];
|
client->wakeupSendFD = wakeupFD[1];
|
||||||
@ -583,9 +564,9 @@ int virNetClientRegisterKeepAlive(virNetClientPtr client)
|
|||||||
int virNetClientGetFD(virNetClientPtr client)
|
int virNetClientGetFD(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
fd = virNetSocketGetFD(client->sock);
|
fd = virNetSocketGetFD(client->sock);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,9 +574,9 @@ int virNetClientGetFD(virNetClientPtr client)
|
|||||||
int virNetClientDupFD(virNetClientPtr client, bool cloexec)
|
int virNetClientDupFD(virNetClientPtr client, bool cloexec)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
fd = virNetSocketDupFD(client->sock, cloexec);
|
fd = virNetSocketDupFD(client->sock, cloexec);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -603,9 +584,9 @@ int virNetClientDupFD(virNetClientPtr client, bool cloexec)
|
|||||||
bool virNetClientHasPassFD(virNetClientPtr client)
|
bool virNetClientHasPassFD(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
bool hasPassFD;
|
bool hasPassFD;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
hasPassFD = virNetSocketHasPassFD(client->sock);
|
hasPassFD = virNetSocketHasPassFD(client->sock);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return hasPassFD;
|
return hasPassFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -639,8 +620,7 @@ void virNetClientDispose(void *obj)
|
|||||||
|
|
||||||
virNetMessageClear(&client->msg);
|
virNetMessageClear(&client->msg);
|
||||||
|
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
virMutexDestroy(&client->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -685,7 +665,7 @@ virNetClientCloseLocked(virNetClientPtr client)
|
|||||||
void *closeOpaque = client->closeOpaque;
|
void *closeOpaque = client->closeOpaque;
|
||||||
int closeReason = client->closeReason;
|
int closeReason = client->closeReason;
|
||||||
virObjectRef(client);
|
virObjectRef(client);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
|
|
||||||
if (ka) {
|
if (ka) {
|
||||||
virKeepAliveStop(ka);
|
virKeepAliveStop(ka);
|
||||||
@ -694,7 +674,7 @@ virNetClientCloseLocked(virNetClientPtr client)
|
|||||||
if (closeCb)
|
if (closeCb)
|
||||||
closeCb(client, closeReason, closeOpaque);
|
closeCb(client, closeReason, closeOpaque);
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
virObjectUnref(client);
|
virObjectUnref(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -711,7 +691,7 @@ static void virNetClientCloseInternal(virNetClientPtr client,
|
|||||||
client->wantClose)
|
client->wantClose)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
virNetClientMarkClose(client, reason);
|
virNetClientMarkClose(client, reason);
|
||||||
|
|
||||||
@ -730,7 +710,7 @@ static void virNetClientCloseInternal(virNetClientPtr client,
|
|||||||
virNetClientIOEventLoopPassTheBuck(client, NULL);
|
virNetClientIOEventLoopPassTheBuck(client, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -744,10 +724,10 @@ void virNetClientClose(virNetClientPtr client)
|
|||||||
void virNetClientSetSASLSession(virNetClientPtr client,
|
void virNetClientSetSASLSession(virNetClientPtr client,
|
||||||
virNetSASLSessionPtr sasl)
|
virNetSASLSessionPtr sasl)
|
||||||
{
|
{
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
client->sasl = virObjectRef(sasl);
|
client->sasl = virObjectRef(sasl);
|
||||||
virNetSocketSetSASLSession(client->sock, client->sasl);
|
virNetSocketSetSASLSession(client->sock, client->sasl);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -771,7 +751,7 @@ int virNetClientSetTLSSession(virNetClientPtr client,
|
|||||||
# endif
|
# endif
|
||||||
sigaddset(&blockedsigs, SIGPIPE);
|
sigaddset(&blockedsigs, SIGPIPE);
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (!(client->tls = virNetTLSSessionNew(tls,
|
if (!(client->tls = virNetTLSSessionNew(tls,
|
||||||
client->hostname)))
|
client->hostname)))
|
||||||
@ -846,13 +826,13 @@ int virNetClientSetTLSSession(virNetClientPtr client,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virObjectUnref(client->tls);
|
virObjectUnref(client->tls);
|
||||||
client->tls = NULL;
|
client->tls = NULL;
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -860,7 +840,7 @@ error:
|
|||||||
bool virNetClientIsEncrypted(virNetClientPtr client)
|
bool virNetClientIsEncrypted(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
#if WITH_GNUTLS
|
#if WITH_GNUTLS
|
||||||
if (client->tls)
|
if (client->tls)
|
||||||
ret = true;
|
ret = true;
|
||||||
@ -869,7 +849,7 @@ bool virNetClientIsEncrypted(virNetClientPtr client)
|
|||||||
if (client->sasl)
|
if (client->sasl)
|
||||||
ret = true;
|
ret = true;
|
||||||
#endif
|
#endif
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -881,9 +861,9 @@ bool virNetClientIsOpen(virNetClientPtr client)
|
|||||||
if (!client)
|
if (!client)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
ret = client->sock && !client->wantClose;
|
ret = client->sock && !client->wantClose;
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -891,19 +871,19 @@ bool virNetClientIsOpen(virNetClientPtr client)
|
|||||||
int virNetClientAddProgram(virNetClientPtr client,
|
int virNetClientAddProgram(virNetClientPtr client,
|
||||||
virNetClientProgramPtr prog)
|
virNetClientProgramPtr prog)
|
||||||
{
|
{
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0)
|
if (VIR_EXPAND_N(client->programs, client->nprograms, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
client->programs[client->nprograms-1] = virObjectRef(prog);
|
client->programs[client->nprograms-1] = virObjectRef(prog);
|
||||||
|
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -911,19 +891,19 @@ no_memory:
|
|||||||
int virNetClientAddStream(virNetClientPtr client,
|
int virNetClientAddStream(virNetClientPtr client,
|
||||||
virNetClientStreamPtr st)
|
virNetClientStreamPtr st)
|
||||||
{
|
{
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0)
|
if (VIR_EXPAND_N(client->streams, client->nstreams, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
client->streams[client->nstreams-1] = virObjectRef(st);
|
client->streams[client->nstreams-1] = virObjectRef(st);
|
||||||
|
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -931,7 +911,7 @@ no_memory:
|
|||||||
void virNetClientRemoveStream(virNetClientPtr client,
|
void virNetClientRemoveStream(virNetClientPtr client,
|
||||||
virNetClientStreamPtr st)
|
virNetClientStreamPtr st)
|
||||||
{
|
{
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
size_t i;
|
size_t i;
|
||||||
for (i = 0 ; i < client->nstreams ; i++) {
|
for (i = 0 ; i < client->nstreams ; i++) {
|
||||||
if (client->streams[i] == st)
|
if (client->streams[i] == st)
|
||||||
@ -953,7 +933,7 @@ void virNetClientRemoveStream(virNetClientPtr client,
|
|||||||
virObjectUnref(st);
|
virObjectUnref(st);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -971,10 +951,10 @@ const char *virNetClientRemoteAddrString(virNetClientPtr client)
|
|||||||
int virNetClientGetTLSKeySize(virNetClientPtr client)
|
int virNetClientGetTLSKeySize(virNetClientPtr client)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
if (client->tls)
|
if (client->tls)
|
||||||
ret = virNetTLSSessionGetKeySize(client->tls);
|
ret = virNetTLSSessionGetKeySize(client->tls);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -1522,7 +1502,7 @@ static int virNetClientIOEventLoop(virNetClientPtr client,
|
|||||||
|
|
||||||
/* Release lock while poll'ing so other threads
|
/* Release lock while poll'ing so other threads
|
||||||
* can stuff themselves on the queue */
|
* can stuff themselves on the queue */
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
|
|
||||||
/* Block SIGWINCH from interrupting poll in curses programs,
|
/* Block SIGWINCH from interrupting poll in curses programs,
|
||||||
* then restore the original signal mask again immediately
|
* 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));
|
ignore_value(pthread_sigmask(SIG_SETMASK, &oldmask, NULL));
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
virReportSystemError(errno,
|
virReportSystemError(errno,
|
||||||
@ -1762,7 +1742,7 @@ static int virNetClientIO(virNetClientPtr client,
|
|||||||
VIR_DEBUG("Going to sleep head=%p call=%p",
|
VIR_DEBUG("Going to sleep head=%p call=%p",
|
||||||
client->waitDispatch, thiscall);
|
client->waitDispatch, thiscall);
|
||||||
/* Go to sleep while other thread is working... */
|
/* 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);
|
virNetClientCallRemove(&client->waitDispatch, thiscall);
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
_("failed to wait on condition"));
|
_("failed to wait on condition"));
|
||||||
@ -1834,7 +1814,7 @@ void virNetClientIncomingEvent(virNetSocketPtr sock,
|
|||||||
{
|
{
|
||||||
virNetClientPtr client = opaque;
|
virNetClientPtr client = opaque;
|
||||||
|
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
VIR_DEBUG("client=%p wantclose=%d", client, client ? client->wantClose : false);
|
VIR_DEBUG("client=%p wantclose=%d", client, client ? client->wantClose : false);
|
||||||
|
|
||||||
@ -1876,7 +1856,7 @@ void virNetClientIncomingEvent(virNetSocketPtr sock,
|
|||||||
done:
|
done:
|
||||||
if (client->wantClose)
|
if (client->wantClose)
|
||||||
virNetClientCloseLocked(client);
|
virNetClientCloseLocked(client);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -2012,9 +1992,9 @@ int virNetClientSendWithReply(virNetClientPtr client,
|
|||||||
virNetMessagePtr msg)
|
virNetMessagePtr msg)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
ret = virNetClientSendInternal(client, msg, true, false);
|
ret = virNetClientSendInternal(client, msg, true, false);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -2035,9 +2015,9 @@ int virNetClientSendNoReply(virNetClientPtr client,
|
|||||||
virNetMessagePtr msg)
|
virNetMessagePtr msg)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
ret = virNetClientSendInternal(client, msg, false, false);
|
ret = virNetClientSendInternal(client, msg, false, false);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -2058,9 +2038,9 @@ int virNetClientSendNonBlock(virNetClientPtr client,
|
|||||||
virNetMessagePtr msg)
|
virNetMessagePtr msg)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
ret = virNetClientSendInternal(client, msg, false, true);
|
ret = virNetClientSendInternal(client, msg, false, true);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2079,18 +2059,18 @@ int virNetClientSendWithReplyStream(virNetClientPtr client,
|
|||||||
virNetClientStreamPtr st)
|
virNetClientStreamPtr st)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
virNetClientLock(client);
|
virObjectLock(client);
|
||||||
/* Other thread might have already received
|
/* Other thread might have already received
|
||||||
* stream EOF so we don't want sent anything.
|
* stream EOF so we don't want sent anything.
|
||||||
* Server won't respond anyway.
|
* Server won't respond anyway.
|
||||||
*/
|
*/
|
||||||
if (virNetClientStreamEOF(st)) {
|
if (virNetClientStreamEOF(st)) {
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virNetClientSendInternal(client, msg, true, false);
|
ret = virNetClientSendInternal(client, msg, true, false);
|
||||||
virNetClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -32,9 +32,7 @@
|
|||||||
#define VIR_FROM_THIS VIR_FROM_RPC
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
||||||
|
|
||||||
struct _virNetClientStream {
|
struct _virNetClientStream {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
virNetClientProgramPtr prog;
|
virNetClientProgramPtr prog;
|
||||||
int proc;
|
int proc;
|
||||||
@ -68,7 +66,7 @@ static void virNetClientStreamDispose(void *obj);
|
|||||||
|
|
||||||
static int virNetClientStreamOnceInit(void)
|
static int virNetClientStreamOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetClientStreamClass = virClassNew(virClassForObject(),
|
if (!(virNetClientStreamClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetClientStream",
|
"virNetClientStream",
|
||||||
sizeof(virNetClientStream),
|
sizeof(virNetClientStream),
|
||||||
virNetClientStreamDispose)))
|
virNetClientStreamDispose)))
|
||||||
@ -106,8 +104,7 @@ virNetClientStreamEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
|||||||
virNetClientStreamPtr st = opaque;
|
virNetClientStreamPtr st = opaque;
|
||||||
int events = 0;
|
int events = 0;
|
||||||
|
|
||||||
|
virObjectLock(st);
|
||||||
virMutexLock(&st->lock);
|
|
||||||
|
|
||||||
if (st->cb &&
|
if (st->cb &&
|
||||||
(st->cbEvents & VIR_STREAM_EVENT_READABLE) &&
|
(st->cbEvents & VIR_STREAM_EVENT_READABLE) &&
|
||||||
@ -124,15 +121,15 @@ virNetClientStreamEventTimer(int timer ATTRIBUTE_UNUSED, void *opaque)
|
|||||||
virFreeCallback cbFree = st->cbFree;
|
virFreeCallback cbFree = st->cbFree;
|
||||||
|
|
||||||
st->cbDispatch = 1;
|
st->cbDispatch = 1;
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
(cb)(st, events, cbOpaque);
|
(cb)(st, events, cbOpaque);
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
st->cbDispatch = 0;
|
st->cbDispatch = 0;
|
||||||
|
|
||||||
if (!st->cb && cbFree)
|
if (!st->cb && cbFree)
|
||||||
(cbFree)(cbOpaque);
|
(cbFree)(cbOpaque);
|
||||||
}
|
}
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -145,20 +142,13 @@ virNetClientStreamPtr virNetClientStreamNew(virNetClientProgramPtr prog,
|
|||||||
if (virNetClientStreamInitialize() < 0)
|
if (virNetClientStreamInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(st = virObjectNew(virNetClientStreamClass)))
|
if (!(st = virObjectLockableNew(virNetClientStreamClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
st->prog = prog;
|
st->prog = prog;
|
||||||
st->proc = proc;
|
st->proc = proc;
|
||||||
st->serial = serial;
|
st->serial = serial;
|
||||||
|
|
||||||
if (virMutexInit(&st->lock) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("cannot initialize mutex"));
|
|
||||||
VIR_FREE(st);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
virObjectRef(prog);
|
virObjectRef(prog);
|
||||||
|
|
||||||
return st;
|
return st;
|
||||||
@ -170,7 +160,6 @@ void virNetClientStreamDispose(void *obj)
|
|||||||
|
|
||||||
virResetError(&st->err);
|
virResetError(&st->err);
|
||||||
VIR_FREE(st->incoming);
|
VIR_FREE(st->incoming);
|
||||||
virMutexDestroy(&st->lock);
|
|
||||||
virObjectUnref(st->prog);
|
virObjectUnref(st->prog);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -178,21 +167,21 @@ bool virNetClientStreamMatches(virNetClientStreamPtr st,
|
|||||||
virNetMessagePtr msg)
|
virNetMessagePtr msg)
|
||||||
{
|
{
|
||||||
bool match = false;
|
bool match = false;
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
if (virNetClientProgramMatches(st->prog, msg) &&
|
if (virNetClientProgramMatches(st->prog, msg) &&
|
||||||
st->proc == msg->header.proc &&
|
st->proc == msg->header.proc &&
|
||||||
st->serial == msg->header.serial)
|
st->serial == msg->header.serial)
|
||||||
match = true;
|
match = true;
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return match;
|
return match;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool virNetClientStreamRaiseError(virNetClientStreamPtr st)
|
bool virNetClientStreamRaiseError(virNetClientStreamPtr st)
|
||||||
{
|
{
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
if (st->err.code == VIR_ERR_OK) {
|
if (st->err.code == VIR_ERR_OK) {
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,7 +195,7 @@ bool virNetClientStreamRaiseError(virNetClientStreamPtr st)
|
|||||||
st->err.int1,
|
st->err.int1,
|
||||||
st->err.int2,
|
st->err.int2,
|
||||||
"%s", st->err.message ? st->err.message : _("Unknown error"));
|
"%s", st->err.message ? st->err.message : _("Unknown error"));
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +206,7 @@ int virNetClientStreamSetError(virNetClientStreamPtr st,
|
|||||||
virNetMessageError err;
|
virNetMessageError err;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
|
|
||||||
if (st->err.code != VIR_ERR_OK)
|
if (st->err.code != VIR_ERR_OK)
|
||||||
VIR_DEBUG("Overwriting existing stream error %s", NULLSTR(st->err.message));
|
VIR_DEBUG("Overwriting existing stream error %s", NULLSTR(st->err.message));
|
||||||
@ -265,7 +254,7 @@ int virNetClientStreamSetError(virNetClientStreamPtr st,
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
xdr_free((xdrproc_t)xdr_virNetMessageError, (void*)&err);
|
xdr_free((xdrproc_t)xdr_virNetMessageError, (void*)&err);
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -276,7 +265,7 @@ int virNetClientStreamQueuePacket(virNetClientStreamPtr st,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
size_t need;
|
size_t need;
|
||||||
|
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
need = msg->bufferLength - msg->bufferOffset;
|
need = msg->bufferLength - msg->bufferOffset;
|
||||||
if (need) {
|
if (need) {
|
||||||
size_t avail = st->incomingLength - st->incomingOffset;
|
size_t avail = st->incomingLength - st->incomingOffset;
|
||||||
@ -306,7 +295,7 @@ int virNetClientStreamQueuePacket(virNetClientStreamPtr st,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -323,7 +312,7 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
|
|||||||
if (!(msg = virNetMessageNew(false)))
|
if (!(msg = virNetMessageNew(false)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
|
|
||||||
msg->header.prog = virNetClientProgramGetProgram(st->prog);
|
msg->header.prog = virNetClientProgramGetProgram(st->prog);
|
||||||
msg->header.vers = virNetClientProgramGetVersion(st->prog);
|
msg->header.vers = virNetClientProgramGetVersion(st->prog);
|
||||||
@ -332,7 +321,7 @@ int virNetClientStreamSendPacket(virNetClientStreamPtr st,
|
|||||||
msg->header.serial = st->serial;
|
msg->header.serial = st->serial;
|
||||||
msg->header.proc = st->proc;
|
msg->header.proc = st->proc;
|
||||||
|
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
|
|
||||||
if (virNetMessageEncodeHeader(msg) < 0)
|
if (virNetMessageEncodeHeader(msg) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -373,7 +362,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
|
|||||||
int rv = -1;
|
int rv = -1;
|
||||||
VIR_DEBUG("st=%p client=%p data=%p nbytes=%zu nonblock=%d",
|
VIR_DEBUG("st=%p client=%p data=%p nbytes=%zu nonblock=%d",
|
||||||
st, client, data, nbytes, nonblock);
|
st, client, data, nbytes, nonblock);
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
if (!st->incomingOffset && !st->incomingEOF) {
|
if (!st->incomingOffset && !st->incomingEOF) {
|
||||||
virNetMessagePtr msg;
|
virNetMessagePtr msg;
|
||||||
int ret;
|
int ret;
|
||||||
@ -397,9 +386,9 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
|
|||||||
msg->header.status = VIR_NET_CONTINUE;
|
msg->header.status = VIR_NET_CONTINUE;
|
||||||
|
|
||||||
VIR_DEBUG("Dummy packet to wait for stream data");
|
VIR_DEBUG("Dummy packet to wait for stream data");
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
ret = virNetClientSendWithReplyStream(client, msg, st);
|
ret = virNetClientSendWithReplyStream(client, msg, st);
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
virNetMessageFree(msg);
|
virNetMessageFree(msg);
|
||||||
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -427,7 +416,7 @@ int virNetClientStreamRecvPacket(virNetClientStreamPtr st,
|
|||||||
virNetClientStreamEventTimerUpdate(st);
|
virNetClientStreamEventTimerUpdate(st);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,7 +429,7 @@ int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
if (st->cb) {
|
if (st->cb) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("multiple stream callbacks not supported"));
|
"%s", _("multiple stream callbacks not supported"));
|
||||||
@ -467,7 +456,7 @@ int virNetClientStreamEventAddCallback(virNetClientStreamPtr st,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -476,7 +465,7 @@ int virNetClientStreamEventUpdateCallback(virNetClientStreamPtr st,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
if (!st->cb) {
|
if (!st->cb) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("no stream callback registered"));
|
"%s", _("no stream callback registered"));
|
||||||
@ -490,7 +479,7 @@ int virNetClientStreamEventUpdateCallback(virNetClientStreamPtr st,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -498,7 +487,7 @@ int virNetClientStreamEventRemoveCallback(virNetClientStreamPtr st)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&st->lock);
|
virObjectLock(st);
|
||||||
if (!st->cb) {
|
if (!st->cb) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
"%s", _("no stream callback registered"));
|
"%s", _("no stream callback registered"));
|
||||||
@ -517,7 +506,7 @@ int virNetClientStreamEventRemoveCallback(virNetClientStreamPtr st)
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&st->lock);
|
virObjectUnlock(st);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,16 +33,14 @@
|
|||||||
#define VIR_FROM_THIS VIR_FROM_RPC
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
||||||
|
|
||||||
struct _virNetSASLContext {
|
struct _virNetSASLContext {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
const char *const*usernameWhitelist;
|
const char *const*usernameWhitelist;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _virNetSASLSession {
|
struct _virNetSASLSession {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
sasl_conn_t *conn;
|
sasl_conn_t *conn;
|
||||||
size_t maxbufsize;
|
size_t maxbufsize;
|
||||||
};
|
};
|
||||||
@ -50,18 +48,17 @@ struct _virNetSASLSession {
|
|||||||
|
|
||||||
static virClassPtr virNetSASLContextClass;
|
static virClassPtr virNetSASLContextClass;
|
||||||
static virClassPtr virNetSASLSessionClass;
|
static virClassPtr virNetSASLSessionClass;
|
||||||
static void virNetSASLContextDispose(void *obj);
|
|
||||||
static void virNetSASLSessionDispose(void *obj);
|
static void virNetSASLSessionDispose(void *obj);
|
||||||
|
|
||||||
static int virNetSASLContextOnceInit(void)
|
static int virNetSASLContextOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetSASLContextClass = virClassNew(virClassForObject(),
|
if (!(virNetSASLContextClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetSASLContext",
|
"virNetSASLContext",
|
||||||
sizeof(virNetSASLContext),
|
sizeof(virNetSASLContext),
|
||||||
virNetSASLContextDispose)))
|
NULL)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(virNetSASLSessionClass = virClassNew(virClassForObject(),
|
if (!(virNetSASLSessionClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetSASLSession",
|
"virNetSASLSession",
|
||||||
sizeof(virNetSASLSession),
|
sizeof(virNetSASLSession),
|
||||||
virNetSASLSessionDispose)))
|
virNetSASLSessionDispose)))
|
||||||
@ -89,16 +86,9 @@ virNetSASLContextPtr virNetSASLContextNewClient(void)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ctxt = virObjectNew(virNetSASLContextClass)))
|
if (!(ctxt = virObjectLockableNew(virNetSASLContextClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virMutexInit(&ctxt->lock) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Failed to initialized mutex"));
|
|
||||||
VIR_FREE(ctxt);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctxt;
|
return ctxt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,16 +108,9 @@ virNetSASLContextPtr virNetSASLContextNewServer(const char *const*usernameWhitel
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(ctxt = virObjectNew(virNetSASLContextClass)))
|
if (!(ctxt = virObjectLockableNew(virNetSASLContextClass)))
|
||||||
return NULL;
|
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;
|
ctxt->usernameWhitelist = usernameWhitelist;
|
||||||
|
|
||||||
return ctxt;
|
return ctxt;
|
||||||
@ -139,7 +122,7 @@ int virNetSASLContextCheckIdentity(virNetSASLContextPtr ctxt,
|
|||||||
const char *const*wildcards;
|
const char *const*wildcards;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&ctxt->lock);
|
virObjectLock(ctxt);
|
||||||
|
|
||||||
/* If the list is not set, allow any DN. */
|
/* If the list is not set, allow any DN. */
|
||||||
wildcards = ctxt->usernameWhitelist;
|
wildcards = ctxt->usernameWhitelist;
|
||||||
@ -173,18 +156,11 @@ int virNetSASLContextCheckIdentity(virNetSASLContextPtr ctxt,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&ctxt->lock);
|
virObjectUnlock(ctxt);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void virNetSASLContextDispose(void *obj)
|
|
||||||
{
|
|
||||||
virNetSASLContextPtr ctxt = obj;
|
|
||||||
|
|
||||||
virMutexDestroy(&ctxt->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt ATTRIBUTE_UNUSED,
|
virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt ATTRIBUTE_UNUSED,
|
||||||
const char *service,
|
const char *service,
|
||||||
const char *hostname,
|
const char *hostname,
|
||||||
@ -195,16 +171,9 @@ virNetSASLSessionPtr virNetSASLSessionNewClient(virNetSASLContextPtr ctxt ATTRIB
|
|||||||
virNetSASLSessionPtr sasl = NULL;
|
virNetSASLSessionPtr sasl = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!(sasl = virObjectNew(virNetSASLSessionClass)))
|
if (!(sasl = virObjectLockableNew(virNetSASLSessionClass)))
|
||||||
return NULL;
|
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 */
|
/* Arbitrary size for amount of data we can encode in a single block */
|
||||||
sasl->maxbufsize = 1 << 16;
|
sasl->maxbufsize = 1 << 16;
|
||||||
|
|
||||||
@ -237,16 +206,9 @@ virNetSASLSessionPtr virNetSASLSessionNewServer(virNetSASLContextPtr ctxt ATTRIB
|
|||||||
virNetSASLSessionPtr sasl = NULL;
|
virNetSASLSessionPtr sasl = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (!(sasl = virObjectNew(virNetSASLSessionClass)))
|
if (!(sasl = virObjectLockableNew(virNetSASLSessionClass)))
|
||||||
return NULL;
|
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 */
|
/* Arbitrary size for amount of data we can encode in a single block */
|
||||||
sasl->maxbufsize = 1 << 16;
|
sasl->maxbufsize = 1 << 16;
|
||||||
|
|
||||||
@ -277,7 +239,7 @@ int virNetSASLSessionExtKeySize(virNetSASLSessionPtr sasl,
|
|||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
|
|
||||||
err = sasl_setprop(sasl->conn, SASL_SSF_EXTERNAL, &ssf);
|
err = sasl_setprop(sasl->conn, SASL_SSF_EXTERNAL, &ssf);
|
||||||
if (err != SASL_OK) {
|
if (err != SASL_OK) {
|
||||||
@ -290,7 +252,7 @@ int virNetSASLSessionExtKeySize(virNetSASLSessionPtr sasl,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,7 +260,7 @@ const char *virNetSASLSessionGetIdentity(virNetSASLSessionPtr sasl)
|
|||||||
{
|
{
|
||||||
const void *val = NULL;
|
const void *val = NULL;
|
||||||
int err;
|
int err;
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
|
|
||||||
err = sasl_getprop(sasl->conn, SASL_USERNAME, &val);
|
err = sasl_getprop(sasl->conn, SASL_USERNAME, &val);
|
||||||
if (err != SASL_OK) {
|
if (err != SASL_OK) {
|
||||||
@ -316,7 +278,7 @@ const char *virNetSASLSessionGetIdentity(virNetSASLSessionPtr sasl)
|
|||||||
VIR_DEBUG("SASL client username %s", (const char *)val);
|
VIR_DEBUG("SASL client username %s", (const char *)val);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return (const char*)val;
|
return (const char*)val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -327,7 +289,7 @@ int virNetSASLSessionGetKeySize(virNetSASLSessionPtr sasl)
|
|||||||
int ssf;
|
int ssf;
|
||||||
const void *val;
|
const void *val;
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
err = sasl_getprop(sasl->conn, SASL_SSF, &val);
|
err = sasl_getprop(sasl->conn, SASL_SSF, &val);
|
||||||
if (err != SASL_OK) {
|
if (err != SASL_OK) {
|
||||||
virReportError(VIR_ERR_AUTH_FAILED,
|
virReportError(VIR_ERR_AUTH_FAILED,
|
||||||
@ -339,7 +301,7 @@ int virNetSASLSessionGetKeySize(virNetSASLSessionPtr sasl)
|
|||||||
ssf = *(const int *)val;
|
ssf = *(const int *)val;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ssf;
|
return ssf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,7 +317,7 @@ int virNetSASLSessionSecProps(virNetSASLSessionPtr sasl,
|
|||||||
VIR_DEBUG("minSSF=%d maxSSF=%d allowAnonymous=%d maxbufsize=%zu",
|
VIR_DEBUG("minSSF=%d maxSSF=%d allowAnonymous=%d maxbufsize=%zu",
|
||||||
minSSF, maxSSF, allowAnonymous, sasl->maxbufsize);
|
minSSF, maxSSF, allowAnonymous, sasl->maxbufsize);
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
memset(&secprops, 0, sizeof(secprops));
|
memset(&secprops, 0, sizeof(secprops));
|
||||||
|
|
||||||
secprops.min_ssf = minSSF;
|
secprops.min_ssf = minSSF;
|
||||||
@ -375,7 +337,7 @@ int virNetSASLSessionSecProps(virNetSASLSessionPtr sasl,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +370,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl)
|
|||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
err = sasl_listmech(sasl->conn,
|
err = sasl_listmech(sasl->conn,
|
||||||
NULL, /* Don't need to set user */
|
NULL, /* Don't need to set user */
|
||||||
"", /* Prefix */
|
"", /* Prefix */
|
||||||
@ -429,7 +391,7 @@ char *virNetSASLSessionListMechanisms(virNetSASLSessionPtr sasl)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
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",
|
VIR_DEBUG("sasl=%p mechlist=%s prompt_need=%p clientout=%p clientoutlen=%p mech=%p",
|
||||||
sasl, mechlist, prompt_need, clientout, clientoutlen, mech);
|
sasl, mechlist, prompt_need, clientout, clientoutlen, mech);
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
err = sasl_client_start(sasl->conn,
|
err = sasl_client_start(sasl->conn,
|
||||||
mechlist,
|
mechlist,
|
||||||
prompt_need,
|
prompt_need,
|
||||||
@ -478,7 +440,7 @@ int virNetSASLSessionClientStart(virNetSASLSessionPtr sasl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
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",
|
VIR_DEBUG("sasl=%p serverin=%s serverinlen=%zu prompt_need=%p clientout=%p clientoutlen=%p",
|
||||||
sasl, serverin, serverinlen, prompt_need, clientout, clientoutlen);
|
sasl, serverin, serverinlen, prompt_need, clientout, clientoutlen);
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
err = sasl_client_step(sasl->conn,
|
err = sasl_client_step(sasl->conn,
|
||||||
serverin,
|
serverin,
|
||||||
inlen,
|
inlen,
|
||||||
@ -527,7 +489,7 @@ int virNetSASLSessionClientStep(virNetSASLSessionPtr sasl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,7 +505,7 @@ int virNetSASLSessionServerStart(virNetSASLSessionPtr sasl,
|
|||||||
int err;
|
int err;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
err = sasl_server_start(sasl->conn,
|
err = sasl_server_start(sasl->conn,
|
||||||
mechname,
|
mechname,
|
||||||
clientin,
|
clientin,
|
||||||
@ -573,7 +535,7 @@ int virNetSASLSessionServerStart(virNetSASLSessionPtr sasl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -589,7 +551,7 @@ int virNetSASLSessionServerStep(virNetSASLSessionPtr sasl,
|
|||||||
int err;
|
int err;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
err = sasl_server_step(sasl->conn,
|
err = sasl_server_step(sasl->conn,
|
||||||
clientin,
|
clientin,
|
||||||
inlen,
|
inlen,
|
||||||
@ -618,16 +580,16 @@ int virNetSASLSessionServerStep(virNetSASLSessionPtr sasl,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t virNetSASLSessionGetMaxBufSize(virNetSASLSessionPtr sasl)
|
size_t virNetSASLSessionGetMaxBufSize(virNetSASLSessionPtr sasl)
|
||||||
{
|
{
|
||||||
size_t ret;
|
size_t ret;
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
ret = sasl->maxbufsize;
|
ret = sasl->maxbufsize;
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -642,7 +604,7 @@ ssize_t virNetSASLSessionEncode(virNetSASLSessionPtr sasl,
|
|||||||
int err;
|
int err;
|
||||||
ssize_t ret = -1;
|
ssize_t ret = -1;
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
if (inputLen > sasl->maxbufsize) {
|
if (inputLen > sasl->maxbufsize) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
_("SASL data length %zu too long, max %zu"),
|
_("SASL data length %zu too long, max %zu"),
|
||||||
@ -666,7 +628,7 @@ ssize_t virNetSASLSessionEncode(virNetSASLSessionPtr sasl,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -681,7 +643,7 @@ ssize_t virNetSASLSessionDecode(virNetSASLSessionPtr sasl,
|
|||||||
int err;
|
int err;
|
||||||
ssize_t ret = -1;
|
ssize_t ret = -1;
|
||||||
|
|
||||||
virMutexLock(&sasl->lock);
|
virObjectLock(sasl);
|
||||||
if (inputLen > sasl->maxbufsize) {
|
if (inputLen > sasl->maxbufsize) {
|
||||||
virReportSystemError(EINVAL,
|
virReportSystemError(EINVAL,
|
||||||
_("SASL data length %zu too long, max %zu"),
|
_("SASL data length %zu too long, max %zu"),
|
||||||
@ -704,7 +666,7 @@ ssize_t virNetSASLSessionDecode(virNetSASLSessionPtr sasl,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sasl->lock);
|
virObjectUnlock(sasl);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -715,5 +677,4 @@ void virNetSASLSessionDispose(void *obj)
|
|||||||
if (sasl->conn)
|
if (sasl->conn)
|
||||||
sasl_dispose(&sasl->conn);
|
sasl_dispose(&sasl->conn);
|
||||||
|
|
||||||
virMutexDestroy(&sasl->lock);
|
|
||||||
}
|
}
|
||||||
|
@ -64,9 +64,7 @@ struct _virNetServerJob {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _virNetServer {
|
struct _virNetServer {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
virThreadPoolPtr workers;
|
virThreadPoolPtr workers;
|
||||||
|
|
||||||
@ -119,7 +117,7 @@ static void virNetServerDispose(void *obj);
|
|||||||
|
|
||||||
static int virNetServerOnceInit(void)
|
static int virNetServerOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetServerClass = virClassNew(virClassForObject(),
|
if (!(virNetServerClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetServer",
|
"virNetServer",
|
||||||
sizeof(virNetServer),
|
sizeof(virNetServer),
|
||||||
virNetServerDispose)))
|
virNetServerDispose)))
|
||||||
@ -131,17 +129,6 @@ static int virNetServerOnceInit(void)
|
|||||||
VIR_ONCE_GLOBAL_INIT(virNetServer)
|
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,
|
static int virNetServerProcessMsg(virNetServerPtr srv,
|
||||||
virNetServerClientPtr client,
|
virNetServerClientPtr client,
|
||||||
virNetServerProgramPtr prog,
|
virNetServerProgramPtr prog,
|
||||||
@ -222,7 +209,7 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
|
|||||||
VIR_DEBUG("server=%p client=%p message=%p",
|
VIR_DEBUG("server=%p client=%p message=%p",
|
||||||
srv, client, msg);
|
srv, client, msg);
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
for (i = 0 ; i < srv->nprograms ; i++) {
|
for (i = 0 ; i < srv->nprograms ; i++) {
|
||||||
if (virNetServerProgramMatches(srv->programs[i], msg)) {
|
if (virNetServerProgramMatches(srv->programs[i], msg)) {
|
||||||
prog = srv->programs[i];
|
prog = srv->programs[i];
|
||||||
@ -258,7 +245,7 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -267,7 +254,7 @@ cleanup:
|
|||||||
static int virNetServerAddClient(virNetServerPtr srv,
|
static int virNetServerAddClient(virNetServerPtr srv,
|
||||||
virNetServerClientPtr client)
|
virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (srv->nclients >= srv->nclients_max) {
|
if (srv->nclients >= srv->nclients_max) {
|
||||||
virReportError(VIR_ERR_RPC,
|
virReportError(VIR_ERR_RPC,
|
||||||
@ -293,11 +280,11 @@ static int virNetServerAddClient(virNetServerPtr srv,
|
|||||||
virNetServerClientInitKeepAlive(client, srv->keepaliveInterval,
|
virNetServerClientInitKeepAlive(client, srv->keepaliveInterval,
|
||||||
srv->keepaliveCount);
|
srv->keepaliveCount);
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -378,7 +365,7 @@ virNetServerPtr virNetServerNew(size_t min_workers,
|
|||||||
if (virNetServerInitialize() < 0)
|
if (virNetServerInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(srv = virObjectNew(virNetServerClass)))
|
if (!(srv = virObjectLockableNew(virNetServerClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (max_workers &&
|
if (max_workers &&
|
||||||
@ -413,12 +400,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virMutexInit(&srv->lock) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("cannot initialize mutex"));
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (virEventRegisterDefaultImpl() < 0)
|
if (virEventRegisterDefaultImpl() < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
@ -607,7 +588,7 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
|
|||||||
virJSONValuePtr services;
|
virJSONValuePtr services;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
virMutexLock(&srv->lock);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (!(object = virJSONValueNewObject()))
|
if (!(object = virJSONValueNewObject()))
|
||||||
goto error;
|
goto error;
|
||||||
@ -692,13 +673,13 @@ virJSONValuePtr virNetServerPreExecRestart(virNetServerPtr srv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&srv->lock);
|
virObjectUnlock(srv);
|
||||||
|
|
||||||
return object;
|
return object;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virJSONValueFree(object);
|
virJSONValueFree(object);
|
||||||
virMutexUnlock(&srv->lock);
|
virObjectUnlock(srv);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -706,9 +687,9 @@ error:
|
|||||||
bool virNetServerIsPrivileged(virNetServerPtr srv)
|
bool virNetServerIsPrivileged(virNetServerPtr srv)
|
||||||
{
|
{
|
||||||
bool priv;
|
bool priv;
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
priv = srv->privileged;
|
priv = srv->privileged;
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return priv;
|
return priv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,11 +697,11 @@ bool virNetServerIsPrivileged(virNetServerPtr srv)
|
|||||||
void virNetServerAutoShutdown(virNetServerPtr srv,
|
void virNetServerAutoShutdown(virNetServerPtr srv,
|
||||||
unsigned int timeout)
|
unsigned int timeout)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
srv->autoShutdownTimeout = timeout;
|
srv->autoShutdownTimeout = timeout;
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -732,7 +713,7 @@ static void virNetServerGotInhibitReply(DBusPendingCall *pending,
|
|||||||
DBusMessage *reply;
|
DBusMessage *reply;
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
srv->autoShutdownCallingInhibit = false;
|
srv->autoShutdownCallingInhibit = false;
|
||||||
|
|
||||||
VIR_DEBUG("srv=%p", srv);
|
VIR_DEBUG("srv=%p", srv);
|
||||||
@ -754,7 +735,7 @@ static void virNetServerGotInhibitReply(DBusPendingCall *pending,
|
|||||||
dbus_message_unref(reply);
|
dbus_message_unref(reply);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -808,7 +789,7 @@ static void virNetServerCallInhibit(virNetServerPtr srv,
|
|||||||
|
|
||||||
void virNetServerAddShutdownInhibition(virNetServerPtr srv)
|
void virNetServerAddShutdownInhibition(virNetServerPtr srv)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
srv->autoShutdownInhibitions++;
|
srv->autoShutdownInhibitions++;
|
||||||
|
|
||||||
VIR_DEBUG("srv=%p inhibitions=%zu", srv, srv->autoShutdownInhibitions);
|
VIR_DEBUG("srv=%p inhibitions=%zu", srv, srv->autoShutdownInhibitions);
|
||||||
@ -822,13 +803,13 @@ void virNetServerAddShutdownInhibition(virNetServerPtr srv)
|
|||||||
"delay");
|
"delay");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void virNetServerRemoveShutdownInhibition(virNetServerPtr srv)
|
void virNetServerRemoveShutdownInhibition(virNetServerPtr srv)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
srv->autoShutdownInhibitions--;
|
srv->autoShutdownInhibitions--;
|
||||||
|
|
||||||
VIR_DEBUG("srv=%p inhibitions=%zu", srv, srv->autoShutdownInhibitions);
|
VIR_DEBUG("srv=%p inhibitions=%zu", srv, srv->autoShutdownInhibitions);
|
||||||
@ -836,7 +817,7 @@ void virNetServerRemoveShutdownInhibition(virNetServerPtr srv)
|
|||||||
if (srv->autoShutdownInhibitions == 0)
|
if (srv->autoShutdownInhibitions == 0)
|
||||||
VIR_FORCE_CLOSE(srv->autoShutdownInhibitFd);
|
VIR_FORCE_CLOSE(srv->autoShutdownInhibitFd);
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -879,7 +860,7 @@ virNetServerSignalEvent(int watch,
|
|||||||
siginfo_t siginfo;
|
siginfo_t siginfo;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (saferead(srv->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
|
if (saferead(srv->sigread, &siginfo, sizeof(siginfo)) != sizeof(siginfo)) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
@ -893,7 +874,7 @@ virNetServerSignalEvent(int watch,
|
|||||||
if (siginfo.si_signo == srv->signals[i]->signum) {
|
if (siginfo.si_signo == srv->signals[i]->signum) {
|
||||||
virNetServerSignalFunc func = srv->signals[i]->func;
|
virNetServerSignalFunc func = srv->signals[i]->func;
|
||||||
void *funcopaque = srv->signals[i]->opaque;
|
void *funcopaque = srv->signals[i]->opaque;
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
func(srv, &siginfo, funcopaque);
|
func(srv, &siginfo, funcopaque);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -903,7 +884,7 @@ virNetServerSignalEvent(int watch,
|
|||||||
_("Unexpected signal received: %d"), siginfo.si_signo);
|
_("Unexpected signal received: %d"), siginfo.si_signo);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int virNetServerSignalSetup(virNetServerPtr srv)
|
static int virNetServerSignalSetup(virNetServerPtr srv)
|
||||||
@ -948,7 +929,7 @@ int virNetServerAddSignalHandler(virNetServerPtr srv,
|
|||||||
virNetServerSignalPtr sigdata;
|
virNetServerSignalPtr sigdata;
|
||||||
struct sigaction sig_action;
|
struct sigaction sig_action;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (virNetServerSignalSetup(srv) < 0)
|
if (virNetServerSignalSetup(srv) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -972,14 +953,14 @@ int virNetServerAddSignalHandler(virNetServerPtr srv,
|
|||||||
|
|
||||||
srv->signals[srv->nsignals-1] = sigdata;
|
srv->signals[srv->nsignals-1] = sigdata;
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
error:
|
error:
|
||||||
VIR_FREE(sigdata);
|
VIR_FREE(sigdata);
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -989,7 +970,7 @@ int virNetServerAddService(virNetServerPtr srv,
|
|||||||
virNetServerServicePtr svc,
|
virNetServerServicePtr svc,
|
||||||
const char *mdnsEntryName)
|
const char *mdnsEntryName)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0)
|
if (VIR_EXPAND_N(srv->services, srv->nservices, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
@ -1010,32 +991,32 @@ int virNetServerAddService(virNetServerPtr srv,
|
|||||||
virNetServerDispatchNewClient,
|
virNetServerDispatchNewClient,
|
||||||
srv);
|
srv);
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
error:
|
error:
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virNetServerAddProgram(virNetServerPtr srv,
|
int virNetServerAddProgram(virNetServerPtr srv,
|
||||||
virNetServerProgramPtr prog)
|
virNetServerProgramPtr prog)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0)
|
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
srv->programs[srv->nprograms-1] = virObjectRef(prog);
|
srv->programs[srv->nprograms-1] = virObjectRef(prog);
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1053,14 +1034,14 @@ static void virNetServerAutoShutdownTimer(int timerid ATTRIBUTE_UNUSED,
|
|||||||
void *opaque) {
|
void *opaque) {
|
||||||
virNetServerPtr srv = opaque;
|
virNetServerPtr srv = opaque;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (!srv->autoShutdownInhibitions) {
|
if (!srv->autoShutdownInhibitions) {
|
||||||
VIR_DEBUG("Automatic shutdown triggered");
|
VIR_DEBUG("Automatic shutdown triggered");
|
||||||
srv->quit = 1;
|
srv->quit = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1069,11 +1050,11 @@ void virNetServerUpdateServices(virNetServerPtr srv,
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
for (i = 0 ; i < srv->nservices ; i++)
|
for (i = 0 ; i < srv->nservices ; i++)
|
||||||
virNetServerServiceToggle(srv->services[i], enabled);
|
virNetServerServiceToggle(srv->services[i], enabled);
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1083,7 +1064,7 @@ void virNetServerRun(virNetServerPtr srv)
|
|||||||
int timerActive = 0;
|
int timerActive = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
if (srv->mdns &&
|
if (srv->mdns &&
|
||||||
virNetServerMDNSStart(srv->mdns) < 0)
|
virNetServerMDNSStart(srv->mdns) < 0)
|
||||||
@ -1123,13 +1104,13 @@ void virNetServerRun(virNetServerPtr srv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
if (virEventRunDefaultImpl() < 0) {
|
if (virEventRunDefaultImpl() < 0) {
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
VIR_DEBUG("Loop iteration error, exiting");
|
VIR_DEBUG("Loop iteration error, exiting");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
reprocess:
|
reprocess:
|
||||||
for (i = 0 ; i < srv->nclients ; i++) {
|
for (i = 0 ; i < srv->nclients ; i++) {
|
||||||
@ -1156,18 +1137,18 @@ void virNetServerRun(virNetServerPtr srv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void virNetServerQuit(virNetServerPtr srv)
|
void virNetServerQuit(virNetServerPtr srv)
|
||||||
{
|
{
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
VIR_DEBUG("Quit requested %p", srv);
|
VIR_DEBUG("Quit requested %p", srv);
|
||||||
srv->quit = 1;
|
srv->quit = 1;
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void virNetServerDispose(void *obj)
|
void virNetServerDispose(void *obj)
|
||||||
@ -1208,8 +1189,6 @@ void virNetServerDispose(void *obj)
|
|||||||
|
|
||||||
VIR_FREE(srv->mdnsGroupName);
|
VIR_FREE(srv->mdnsGroupName);
|
||||||
virNetServerMDNSFree(srv->mdns);
|
virNetServerMDNSFree(srv->mdns);
|
||||||
|
|
||||||
virMutexDestroy(&srv->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void virNetServerClose(virNetServerPtr srv)
|
void virNetServerClose(virNetServerPtr srv)
|
||||||
@ -1219,20 +1198,20 @@ void virNetServerClose(virNetServerPtr srv)
|
|||||||
if (!srv)
|
if (!srv)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
|
|
||||||
for (i = 0; i < srv->nservices; i++) {
|
for (i = 0; i < srv->nservices; i++) {
|
||||||
virNetServerServiceClose(srv->services[i]);
|
virNetServerServiceClose(srv->services[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool virNetServerKeepAliveRequired(virNetServerPtr srv)
|
bool virNetServerKeepAliveRequired(virNetServerPtr srv)
|
||||||
{
|
{
|
||||||
bool required;
|
bool required;
|
||||||
virNetServerLock(srv);
|
virObjectLock(srv);
|
||||||
required = srv->keepaliveRequired;
|
required = srv->keepaliveRequired;
|
||||||
virNetServerUnlock(srv);
|
virObjectUnlock(srv);
|
||||||
return required;
|
return required;
|
||||||
}
|
}
|
||||||
|
@ -57,11 +57,10 @@ struct _virNetServerClientFilter {
|
|||||||
|
|
||||||
struct _virNetServerClient
|
struct _virNetServerClient
|
||||||
{
|
{
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
bool wantClose;
|
bool wantClose;
|
||||||
bool delayedClose;
|
bool delayedClose;
|
||||||
virMutex lock;
|
|
||||||
virNetSocketPtr sock;
|
virNetSocketPtr sock;
|
||||||
int auth;
|
int auth;
|
||||||
bool readonly;
|
bool readonly;
|
||||||
@ -112,7 +111,7 @@ static void virNetServerClientDispose(void *obj);
|
|||||||
|
|
||||||
static int virNetServerClientOnceInit(void)
|
static int virNetServerClientOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetServerClientClass = virClassNew(virClassForObject(),
|
if (!(virNetServerClientClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetServerClient",
|
"virNetServerClient",
|
||||||
sizeof(virNetServerClient),
|
sizeof(virNetServerClient),
|
||||||
virNetServerClientDispose)))
|
virNetServerClientDispose)))
|
||||||
@ -130,17 +129,6 @@ static void virNetServerClientDispatchRead(virNetServerClientPtr client);
|
|||||||
static int virNetServerClientSendMessageLocked(virNetServerClientPtr client,
|
static int virNetServerClientSendMessageLocked(virNetServerClientPtr client,
|
||||||
virNetMessagePtr msg);
|
virNetMessagePtr msg);
|
||||||
|
|
||||||
static void virNetServerClientLock(virNetServerClientPtr client)
|
|
||||||
{
|
|
||||||
virMutexLock(&client->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void virNetServerClientUnlock(virNetServerClientPtr client)
|
|
||||||
{
|
|
||||||
virMutexUnlock(&client->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* @client: a locked client object
|
* @client: a locked client object
|
||||||
*/
|
*/
|
||||||
@ -253,7 +241,7 @@ int virNetServerClientAddFilter(virNetServerClientPtr client,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
filter->id = client->nextFilterID++;
|
filter->id = client->nextFilterID++;
|
||||||
filter->func = func;
|
filter->func = func;
|
||||||
@ -266,7 +254,7 @@ int virNetServerClientAddFilter(virNetServerClientPtr client,
|
|||||||
|
|
||||||
ret = filter->id;
|
ret = filter->id;
|
||||||
|
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -276,7 +264,7 @@ void virNetServerClientRemoveFilter(virNetServerClientPtr client,
|
|||||||
{
|
{
|
||||||
virNetServerClientFilterPtr tmp, prev;
|
virNetServerClientFilterPtr tmp, prev;
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
prev = NULL;
|
prev = NULL;
|
||||||
tmp = client->filters;
|
tmp = client->filters;
|
||||||
@ -294,7 +282,7 @@ void virNetServerClientRemoveFilter(virNetServerClientPtr client,
|
|||||||
tmp = tmp->next;
|
tmp = tmp->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -341,13 +329,13 @@ static void virNetServerClientSockTimerFunc(int timer,
|
|||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virNetServerClientPtr client = opaque;
|
virNetServerClientPtr client = opaque;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
virEventUpdateTimeout(timer, -1);
|
virEventUpdateTimeout(timer, -1);
|
||||||
/* Although client->rx != NULL when this timer is enabled, it might have
|
/* Although client->rx != NULL when this timer is enabled, it might have
|
||||||
* changed since the client was unlocked in the meantime. */
|
* changed since the client was unlocked in the meantime. */
|
||||||
if (client->rx)
|
if (client->rx)
|
||||||
virNetServerClientDispatchRead(client);
|
virNetServerClientDispatchRead(client);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -365,14 +353,9 @@ virNetServerClientNewInternal(virNetSocketPtr sock,
|
|||||||
if (virNetServerClientInitialize() < 0)
|
if (virNetServerClientInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(client = virObjectNew(virNetServerClientClass)))
|
if (!(client = virObjectLockableNew(virNetServerClientClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virMutexInit(&client->lock) < 0) {
|
|
||||||
VIR_FREE(client);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
client->sock = virObjectRef(sock);
|
client->sock = virObjectRef(sock);
|
||||||
client->auth = auth;
|
client->auth = auth;
|
||||||
client->readonly = readonly;
|
client->readonly = readonly;
|
||||||
@ -544,7 +527,7 @@ virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
|
|||||||
if (!object)
|
if (!object)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < 0)
|
if (virJSONValueObjectAppendNumberInt(object, "auth", client->auth) < 0)
|
||||||
goto error;
|
goto error;
|
||||||
@ -574,11 +557,11 @@ virJSONValuePtr virNetServerClientPreExecRestart(virNetServerClientPtr client)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return object;
|
return object;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
virJSONValueFree(object);
|
virJSONValueFree(object);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -587,18 +570,18 @@ error:
|
|||||||
int virNetServerClientGetAuth(virNetServerClientPtr client)
|
int virNetServerClientGetAuth(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
int auth;
|
int auth;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
auth = client->auth;
|
auth = client->auth;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return auth;
|
return auth;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool virNetServerClientGetReadonly(virNetServerClientPtr client)
|
bool virNetServerClientGetReadonly(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
bool readonly;
|
bool readonly;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
readonly = client->readonly;
|
readonly = client->readonly;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return readonly;
|
return readonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,19 +590,19 @@ bool virNetServerClientGetReadonly(virNetServerClientPtr client)
|
|||||||
bool virNetServerClientHasTLSSession(virNetServerClientPtr client)
|
bool virNetServerClientHasTLSSession(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
bool has;
|
bool has;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
has = client->tls ? true : false;
|
has = client->tls ? true : false;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return has;
|
return has;
|
||||||
}
|
}
|
||||||
|
|
||||||
int virNetServerClientGetTLSKeySize(virNetServerClientPtr client)
|
int virNetServerClientGetTLSKeySize(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
int size = 0;
|
int size = 0;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
if (client->tls)
|
if (client->tls)
|
||||||
size = virNetTLSSessionGetKeySize(client->tls);
|
size = virNetTLSSessionGetKeySize(client->tls);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -627,10 +610,10 @@ int virNetServerClientGetTLSKeySize(virNetServerClientPtr client)
|
|||||||
int virNetServerClientGetFD(virNetServerClientPtr client)
|
int virNetServerClientGetFD(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
if (client->sock)
|
if (client->sock)
|
||||||
fd = virNetSocketGetFD(client->sock);
|
fd = virNetSocketGetFD(client->sock);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -638,17 +621,17 @@ int virNetServerClientGetUNIXIdentity(virNetServerClientPtr client,
|
|||||||
uid_t *uid, gid_t *gid, pid_t *pid)
|
uid_t *uid, gid_t *gid, pid_t *pid)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
if (client->sock)
|
if (client->sock)
|
||||||
ret = virNetSocketGetUNIXIdentity(client->sock, uid, gid, pid);
|
ret = virNetSocketGetUNIXIdentity(client->sock, uid, gid, pid);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool virNetServerClientIsSecure(virNetServerClientPtr client)
|
bool virNetServerClientIsSecure(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
bool secure = false;
|
bool secure = false;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
#if WITH_GNUTLS
|
#if WITH_GNUTLS
|
||||||
if (client->tls)
|
if (client->tls)
|
||||||
secure = true;
|
secure = true;
|
||||||
@ -659,7 +642,7 @@ bool virNetServerClientIsSecure(virNetServerClientPtr client)
|
|||||||
#endif
|
#endif
|
||||||
if (client->sock && virNetSocketIsLocal(client->sock))
|
if (client->sock && virNetSocketIsLocal(client->sock))
|
||||||
secure = true;
|
secure = true;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return secure;
|
return secure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,9 +656,9 @@ void virNetServerClientSetSASLSession(virNetServerClientPtr client,
|
|||||||
* in the clear. Only once we complete the next 'tx'
|
* in the clear. Only once we complete the next 'tx'
|
||||||
* operation do we switch to SASL mode
|
* operation do we switch to SASL mode
|
||||||
*/
|
*/
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
client->sasl = virObjectRef(sasl);
|
client->sasl = virObjectRef(sasl);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -684,7 +667,7 @@ int virNetServerClientSetIdentity(virNetServerClientPtr client,
|
|||||||
const char *identity)
|
const char *identity)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
if (!(client->identity = strdup(identity))) {
|
if (!(client->identity = strdup(identity))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
goto error;
|
goto error;
|
||||||
@ -692,16 +675,16 @@ int virNetServerClientSetIdentity(virNetServerClientPtr client,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *virNetServerClientGetIdentity(virNetServerClientPtr client)
|
const char *virNetServerClientGetIdentity(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
const char *identity;
|
const char *identity;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
identity = client->identity;
|
identity = client->identity;
|
||||||
virNetServerClientLock(client);
|
virObjectUnlock(client);
|
||||||
return identity;
|
return identity;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -709,9 +692,9 @@ const char *virNetServerClientGetIdentity(virNetServerClientPtr client)
|
|||||||
void *virNetServerClientGetPrivateData(virNetServerClientPtr client)
|
void *virNetServerClientGetPrivateData(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
void *data;
|
void *data;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
data = client->privateData;
|
data = client->privateData;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,9 +702,9 @@ void *virNetServerClientGetPrivateData(virNetServerClientPtr client)
|
|||||||
void virNetServerClientSetCloseHook(virNetServerClientPtr client,
|
void virNetServerClientSetCloseHook(virNetServerClientPtr client,
|
||||||
virNetServerClientCloseFunc cf)
|
virNetServerClientCloseFunc cf)
|
||||||
{
|
{
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
client->privateDataCloseFunc = cf;
|
client->privateDataCloseFunc = cf;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -729,10 +712,10 @@ void virNetServerClientSetDispatcher(virNetServerClientPtr client,
|
|||||||
virNetServerClientDispatchFunc func,
|
virNetServerClientDispatchFunc func,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
client->dispatchFunc = func;
|
client->dispatchFunc = func;
|
||||||
client->dispatchOpaque = opaque;
|
client->dispatchOpaque = opaque;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -771,8 +754,7 @@ void virNetServerClientDispose(void *obj)
|
|||||||
virObjectUnref(client->tlsCtxt);
|
virObjectUnref(client->tlsCtxt);
|
||||||
#endif
|
#endif
|
||||||
virObjectUnref(client->sock);
|
virObjectUnref(client->sock);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
virMutexDestroy(&client->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -789,10 +771,10 @@ void virNetServerClientClose(virNetServerClientPtr client)
|
|||||||
virNetServerClientCloseFunc cf;
|
virNetServerClientCloseFunc cf;
|
||||||
virKeepAlivePtr ka;
|
virKeepAlivePtr ka;
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
VIR_DEBUG("client=%p", client);
|
VIR_DEBUG("client=%p", client);
|
||||||
if (!client->sock) {
|
if (!client->sock) {
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -801,18 +783,18 @@ void virNetServerClientClose(virNetServerClientPtr client)
|
|||||||
ka = client->keepalive;
|
ka = client->keepalive;
|
||||||
client->keepalive = NULL;
|
client->keepalive = NULL;
|
||||||
virObjectRef(client);
|
virObjectRef(client);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
virObjectUnref(ka);
|
virObjectUnref(ka);
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
virObjectUnref(client);
|
virObjectUnref(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (client->privateDataCloseFunc) {
|
if (client->privateDataCloseFunc) {
|
||||||
cf = client->privateDataCloseFunc;
|
cf = client->privateDataCloseFunc;
|
||||||
virObjectRef(client);
|
virObjectRef(client);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
(cf)(client);
|
(cf)(client);
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
virObjectUnref(client);
|
virObjectUnref(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -846,46 +828,46 @@ void virNetServerClientClose(virNetServerClientPtr client)
|
|||||||
client->sock = NULL;
|
client->sock = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool virNetServerClientIsClosed(virNetServerClientPtr client)
|
bool virNetServerClientIsClosed(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
bool closed;
|
bool closed;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
closed = client->sock == NULL ? true : false;
|
closed = client->sock == NULL ? true : false;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return closed;
|
return closed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void virNetServerClientDelayedClose(virNetServerClientPtr client)
|
void virNetServerClientDelayedClose(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
client->delayedClose = true;
|
client->delayedClose = true;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
void virNetServerClientImmediateClose(virNetServerClientPtr client)
|
void virNetServerClientImmediateClose(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
client->wantClose = true;
|
client->wantClose = true;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool virNetServerClientWantClose(virNetServerClientPtr client)
|
bool virNetServerClientWantClose(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
bool wantClose;
|
bool wantClose;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
wantClose = client->wantClose;
|
wantClose = client->wantClose;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return wantClose;
|
return wantClose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virNetServerClientInit(virNetServerClientPtr client)
|
int virNetServerClientInit(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
#if WITH_GNUTLS
|
#if WITH_GNUTLS
|
||||||
if (!client->tlsCtxt) {
|
if (!client->tlsCtxt) {
|
||||||
@ -924,12 +906,12 @@ int virNetServerClientInit(virNetServerClientPtr client)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
client->wantClose = true;
|
client->wantClose = true;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1255,11 +1237,11 @@ virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque)
|
|||||||
{
|
{
|
||||||
virNetServerClientPtr client = opaque;
|
virNetServerClientPtr client = opaque;
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (client->sock != sock) {
|
if (client->sock != sock) {
|
||||||
virNetSocketRemoveIOCallback(sock);
|
virNetSocketRemoveIOCallback(sock);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1288,7 +1270,7 @@ virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque)
|
|||||||
VIR_EVENT_HANDLE_HANGUP))
|
VIR_EVENT_HANDLE_HANGUP))
|
||||||
client->wantClose = true;
|
client->wantClose = true;
|
||||||
|
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1322,9 +1304,9 @@ int virNetServerClientSendMessage(virNetServerClientPtr client,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
ret = virNetServerClientSendMessageLocked(client, msg);
|
ret = virNetServerClientSendMessageLocked(client, msg);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1333,10 +1315,10 @@ int virNetServerClientSendMessage(virNetServerClientPtr client,
|
|||||||
bool virNetServerClientNeedAuth(virNetServerClientPtr client)
|
bool virNetServerClientNeedAuth(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
bool need = false;
|
bool need = false;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
if (client->auth && !client->identity)
|
if (client->auth && !client->identity)
|
||||||
need = true;
|
need = true;
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return need;
|
return need;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1363,7 +1345,7 @@ virNetServerClientInitKeepAlive(virNetServerClientPtr client,
|
|||||||
virKeepAlivePtr ka;
|
virKeepAlivePtr ka;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
|
|
||||||
if (!(ka = virKeepAliveNew(interval, count, client,
|
if (!(ka = virKeepAliveNew(interval, count, client,
|
||||||
virNetServerClientKeepAliveSendCB,
|
virNetServerClientKeepAliveSendCB,
|
||||||
@ -1377,7 +1359,7 @@ virNetServerClientInitKeepAlive(virNetServerClientPtr client,
|
|||||||
ka = NULL;
|
ka = NULL;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
if (ka)
|
if (ka)
|
||||||
virKeepAliveStop(ka);
|
virKeepAliveStop(ka);
|
||||||
virObjectUnref(ka);
|
virObjectUnref(ka);
|
||||||
@ -1389,8 +1371,8 @@ int
|
|||||||
virNetServerClientStartKeepAlive(virNetServerClientPtr client)
|
virNetServerClientStartKeepAlive(virNetServerClientPtr client)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
virNetServerClientLock(client);
|
virObjectLock(client);
|
||||||
ret = virKeepAliveStart(client->keepalive, 0, 0);
|
ret = virKeepAliveStart(client->keepalive, 0, 0);
|
||||||
virNetServerClientUnlock(client);
|
virObjectUnlock(client);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -59,9 +59,7 @@
|
|||||||
|
|
||||||
|
|
||||||
struct _virNetSocket {
|
struct _virNetSocket {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
int watch;
|
int watch;
|
||||||
@ -104,7 +102,7 @@ static void virNetSocketDispose(void *obj);
|
|||||||
|
|
||||||
static int virNetSocketOnceInit(void)
|
static int virNetSocketOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetSocketClass = virClassNew(virClassForObject(),
|
if (!(virNetSocketClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetSocket",
|
"virNetSocket",
|
||||||
sizeof(virNetSocket),
|
sizeof(virNetSocket),
|
||||||
virNetSocketDispose)))
|
virNetSocketDispose)))
|
||||||
@ -163,16 +161,9 @@ static virNetSocketPtr virNetSocketNew(virSocketAddrPtr localAddr,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(sock = virObjectNew(virNetSocketClass)))
|
if (!(sock = virObjectLockableNew(virNetSocketClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virMutexInit(&sock->lock) < 0) {
|
|
||||||
virReportSystemError(errno, "%s",
|
|
||||||
_("Unable to initialize mutex"));
|
|
||||||
VIR_FREE(sock);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (localAddr)
|
if (localAddr)
|
||||||
sock->localAddr = *localAddr;
|
sock->localAddr = *localAddr;
|
||||||
if (remoteAddr)
|
if (remoteAddr)
|
||||||
@ -944,7 +935,7 @@ virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock)
|
|||||||
{
|
{
|
||||||
virJSONValuePtr object = NULL;
|
virJSONValuePtr object = NULL;
|
||||||
|
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
#if WITH_SASL
|
#if WITH_SASL
|
||||||
if (sock->saslSession) {
|
if (sock->saslSession) {
|
||||||
@ -990,11 +981,11 @@ virJSONValuePtr virNetSocketPreExecRestart(virNetSocketPtr sock)
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return object;
|
return object;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
virJSONValueFree(object);
|
virJSONValueFree(object);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -1039,17 +1030,15 @@ void virNetSocketDispose(void *obj)
|
|||||||
|
|
||||||
VIR_FREE(sock->localAddrStr);
|
VIR_FREE(sock->localAddrStr);
|
||||||
VIR_FREE(sock->remoteAddrStr);
|
VIR_FREE(sock->remoteAddrStr);
|
||||||
|
|
||||||
virMutexDestroy(&sock->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virNetSocketGetFD(virNetSocketPtr sock)
|
int virNetSocketGetFD(virNetSocketPtr sock)
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
fd = sock->fd;
|
fd = sock->fd;
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return fd;
|
return fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1074,10 +1063,10 @@ int virNetSocketDupFD(virNetSocketPtr sock, bool cloexec)
|
|||||||
bool virNetSocketIsLocal(virNetSocketPtr sock)
|
bool virNetSocketIsLocal(virNetSocketPtr sock)
|
||||||
{
|
{
|
||||||
bool isLocal = false;
|
bool isLocal = false;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
if (sock->localAddr.data.sa.sa_family == AF_UNIX)
|
if (sock->localAddr.data.sa.sa_family == AF_UNIX)
|
||||||
isLocal = true;
|
isLocal = true;
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return isLocal;
|
return isLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1085,10 +1074,10 @@ bool virNetSocketIsLocal(virNetSocketPtr sock)
|
|||||||
bool virNetSocketHasPassFD(virNetSocketPtr sock)
|
bool virNetSocketHasPassFD(virNetSocketPtr sock)
|
||||||
{
|
{
|
||||||
bool hasPassFD = false;
|
bool hasPassFD = false;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
if (sock->localAddr.data.sa.sa_family == AF_UNIX)
|
if (sock->localAddr.data.sa.sa_family == AF_UNIX)
|
||||||
hasPassFD = true;
|
hasPassFD = true;
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return hasPassFD;
|
return hasPassFD;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1096,9 +1085,9 @@ bool virNetSocketHasPassFD(virNetSocketPtr sock)
|
|||||||
int virNetSocketGetPort(virNetSocketPtr sock)
|
int virNetSocketGetPort(virNetSocketPtr sock)
|
||||||
{
|
{
|
||||||
int port;
|
int port;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
port = virSocketAddrGetPort(&sock->localAddr);
|
port = virSocketAddrGetPort(&sock->localAddr);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1111,12 +1100,12 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
|
|||||||
{
|
{
|
||||||
struct ucred cr;
|
struct ucred cr;
|
||||||
socklen_t cr_len = sizeof(cr);
|
socklen_t cr_len = sizeof(cr);
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
if (getsockopt(sock->fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) < 0) {
|
if (getsockopt(sock->fd, SOL_SOCKET, SO_PEERCRED, &cr, &cr_len) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Failed to get client socket identity"));
|
_("Failed to get client socket identity"));
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1124,7 +1113,7 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
|
|||||||
*uid = cr.uid;
|
*uid = cr.uid;
|
||||||
*gid = cr.gid;
|
*gid = cr.gid;
|
||||||
|
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#elif defined(LOCAL_PEERCRED)
|
#elif defined(LOCAL_PEERCRED)
|
||||||
@ -1135,12 +1124,12 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
|
|||||||
{
|
{
|
||||||
struct xucred cr;
|
struct xucred cr;
|
||||||
socklen_t cr_len = sizeof(cr);
|
socklen_t cr_len = sizeof(cr);
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr, &cr_len) < 0) {
|
if (getsockopt(sock->fd, SOL_SOCKET, LOCAL_PEERCRED, &cr, &cr_len) < 0) {
|
||||||
virReportSystemError(errno, "%s",
|
virReportSystemError(errno, "%s",
|
||||||
_("Failed to get client socket identity"));
|
_("Failed to get client socket identity"));
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1148,7 +1137,7 @@ int virNetSocketGetUNIXIdentity(virNetSocketPtr sock,
|
|||||||
*uid = cr.cr_uid;
|
*uid = cr.cr_uid;
|
||||||
*gid = cr.cr_gid;
|
*gid = cr.cr_gid;
|
||||||
|
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
@ -1169,9 +1158,9 @@ int virNetSocketSetBlocking(virNetSocketPtr sock,
|
|||||||
bool blocking)
|
bool blocking)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
ret = virSetBlocking(sock->fd, blocking);
|
ret = virSetBlocking(sock->fd, blocking);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1209,14 +1198,14 @@ static ssize_t virNetSocketTLSSessionRead(char *buf,
|
|||||||
void virNetSocketSetTLSSession(virNetSocketPtr sock,
|
void virNetSocketSetTLSSession(virNetSocketPtr sock,
|
||||||
virNetTLSSessionPtr sess)
|
virNetTLSSessionPtr sess)
|
||||||
{
|
{
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
virObjectUnref(sock->tlsSession);
|
virObjectUnref(sock->tlsSession);
|
||||||
sock->tlsSession = virObjectRef(sess);
|
sock->tlsSession = virObjectRef(sess);
|
||||||
virNetTLSSessionSetIOCallbacks(sess,
|
virNetTLSSessionSetIOCallbacks(sess,
|
||||||
virNetSocketTLSSessionWrite,
|
virNetSocketTLSSessionWrite,
|
||||||
virNetSocketTLSSessionRead,
|
virNetSocketTLSSessionRead,
|
||||||
sock);
|
sock);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1224,10 +1213,10 @@ void virNetSocketSetTLSSession(virNetSocketPtr sock,
|
|||||||
void virNetSocketSetSASLSession(virNetSocketPtr sock,
|
void virNetSocketSetSASLSession(virNetSocketPtr sock,
|
||||||
virNetSASLSessionPtr sess)
|
virNetSASLSessionPtr sess)
|
||||||
{
|
{
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
virObjectUnref(sock->saslSession);
|
virObjectUnref(sock->saslSession);
|
||||||
sock->saslSession = virObjectRef(sess);
|
sock->saslSession = virObjectRef(sess);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1235,7 +1224,7 @@ void virNetSocketSetSASLSession(virNetSocketPtr sock,
|
|||||||
bool virNetSocketHasCachedData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
|
bool virNetSocketHasCachedData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
bool hasCached = false;
|
bool hasCached = false;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
#if WITH_SSH2
|
#if WITH_SSH2
|
||||||
if (virNetSSHSessionHasCachedData(sock->sshSession))
|
if (virNetSSHSessionHasCachedData(sock->sshSession))
|
||||||
@ -1246,7 +1235,7 @@ bool virNetSocketHasCachedData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
|
|||||||
if (sock->saslDecoded)
|
if (sock->saslDecoded)
|
||||||
hasCached = true;
|
hasCached = true;
|
||||||
#endif
|
#endif
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return hasCached;
|
return hasCached;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1269,12 +1258,12 @@ static ssize_t virNetSocketLibSSH2Write(virNetSocketPtr sock,
|
|||||||
bool virNetSocketHasPendingData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
|
bool virNetSocketHasPendingData(virNetSocketPtr sock ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
bool hasPending = false;
|
bool hasPending = false;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
#if WITH_SASL
|
#if WITH_SASL
|
||||||
if (sock->saslEncoded)
|
if (sock->saslEncoded)
|
||||||
hasPending = true;
|
hasPending = true;
|
||||||
#endif
|
#endif
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return hasPending;
|
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 virNetSocketRead(virNetSocketPtr sock, char *buf, size_t len)
|
||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
#if WITH_SASL
|
#if WITH_SASL
|
||||||
if (sock->saslSession)
|
if (sock->saslSession)
|
||||||
ret = virNetSocketReadSASL(sock, buf, len);
|
ret = virNetSocketReadSASL(sock, buf, len);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
ret = virNetSocketReadWire(sock, buf, len);
|
ret = virNetSocketReadWire(sock, buf, len);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1498,14 +1487,14 @@ ssize_t virNetSocketWrite(virNetSocketPtr sock, const char *buf, size_t len)
|
|||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
#if WITH_SASL
|
#if WITH_SASL
|
||||||
if (sock->saslSession)
|
if (sock->saslSession)
|
||||||
ret = virNetSocketWriteSASL(sock, buf, len);
|
ret = virNetSocketWriteSASL(sock, buf, len);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
ret = virNetSocketWriteWire(sock, buf, len);
|
ret = virNetSocketWriteWire(sock, buf, len);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1521,7 +1510,7 @@ int virNetSocketSendFD(virNetSocketPtr sock, int fd)
|
|||||||
_("Sending file descriptors is not supported on this socket"));
|
_("Sending file descriptors is not supported on this socket"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
PROBE(RPC_SOCKET_SEND_FD,
|
PROBE(RPC_SOCKET_SEND_FD,
|
||||||
"sock=%p fd=%d", sock, fd);
|
"sock=%p fd=%d", sock, fd);
|
||||||
if (sendfd(sock->fd, fd) < 0) {
|
if (sendfd(sock->fd, fd) < 0) {
|
||||||
@ -1536,7 +1525,7 @@ int virNetSocketSendFD(virNetSocketPtr sock, int fd)
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1555,7 +1544,7 @@ int virNetSocketRecvFD(virNetSocketPtr sock, int *fd)
|
|||||||
_("Receiving file descriptors is not supported on this socket"));
|
_("Receiving file descriptors is not supported on this socket"));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
if ((*fd = recvfd(sock->fd, O_CLOEXEC)) < 0) {
|
if ((*fd = recvfd(sock->fd, O_CLOEXEC)) < 0) {
|
||||||
if (errno == EAGAIN)
|
if (errno == EAGAIN)
|
||||||
@ -1570,20 +1559,20 @@ int virNetSocketRecvFD(virNetSocketPtr sock, int *fd)
|
|||||||
ret = 1;
|
ret = 1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int virNetSocketListen(virNetSocketPtr sock, int backlog)
|
int virNetSocketListen(virNetSocketPtr sock, int backlog)
|
||||||
{
|
{
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
if (listen(sock->fd, backlog > 0 ? backlog : 30) < 0) {
|
if (listen(sock->fd, backlog > 0 ? backlog : 30) < 0) {
|
||||||
virReportSystemError(errno, "%s", _("Unable to listen on socket"));
|
virReportSystemError(errno, "%s", _("Unable to listen on socket"));
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1594,7 +1583,7 @@ int virNetSocketAccept(virNetSocketPtr sock, virNetSocketPtr *clientsock)
|
|||||||
virSocketAddr remoteAddr;
|
virSocketAddr remoteAddr;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
*clientsock = NULL;
|
*clientsock = NULL;
|
||||||
|
|
||||||
@ -1631,7 +1620,7 @@ int virNetSocketAccept(virNetSocketPtr sock, virNetSocketPtr *clientsock)
|
|||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FORCE_CLOSE(fd);
|
VIR_FORCE_CLOSE(fd);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1645,10 +1634,10 @@ static void virNetSocketEventHandle(int watch ATTRIBUTE_UNUSED,
|
|||||||
virNetSocketIOFunc func;
|
virNetSocketIOFunc func;
|
||||||
void *eopaque;
|
void *eopaque;
|
||||||
|
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
func = sock->func;
|
func = sock->func;
|
||||||
eopaque = sock->opaque;
|
eopaque = sock->opaque;
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
|
|
||||||
if (func)
|
if (func)
|
||||||
func(sock, events, eopaque);
|
func(sock, events, eopaque);
|
||||||
@ -1661,13 +1650,13 @@ static void virNetSocketEventFree(void *opaque)
|
|||||||
virFreeCallback ff;
|
virFreeCallback ff;
|
||||||
void *eopaque;
|
void *eopaque;
|
||||||
|
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
ff = sock->ff;
|
ff = sock->ff;
|
||||||
eopaque = sock->opaque;
|
eopaque = sock->opaque;
|
||||||
sock->func = NULL;
|
sock->func = NULL;
|
||||||
sock->ff = NULL;
|
sock->ff = NULL;
|
||||||
sock->opaque = NULL;
|
sock->opaque = NULL;
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
|
|
||||||
if (ff)
|
if (ff)
|
||||||
ff(eopaque);
|
ff(eopaque);
|
||||||
@ -1684,7 +1673,7 @@ int virNetSocketAddIOCallback(virNetSocketPtr sock,
|
|||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virObjectRef(sock);
|
virObjectRef(sock);
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
if (sock->watch > 0) {
|
if (sock->watch > 0) {
|
||||||
VIR_DEBUG("Watch already registered on socket %p", sock);
|
VIR_DEBUG("Watch already registered on socket %p", sock);
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -1705,7 +1694,7 @@ int virNetSocketAddIOCallback(virNetSocketPtr sock,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
virObjectUnref(sock);
|
virObjectUnref(sock);
|
||||||
return ret;
|
return ret;
|
||||||
@ -1714,31 +1703,31 @@ cleanup:
|
|||||||
void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
|
void virNetSocketUpdateIOCallback(virNetSocketPtr sock,
|
||||||
int events)
|
int events)
|
||||||
{
|
{
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
if (sock->watch <= 0) {
|
if (sock->watch <= 0) {
|
||||||
VIR_DEBUG("Watch not registered on socket %p", sock);
|
VIR_DEBUG("Watch not registered on socket %p", sock);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virEventUpdateHandle(sock->watch, events);
|
virEventUpdateHandle(sock->watch, events);
|
||||||
|
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void virNetSocketRemoveIOCallback(virNetSocketPtr sock)
|
void virNetSocketRemoveIOCallback(virNetSocketPtr sock)
|
||||||
{
|
{
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
if (sock->watch <= 0) {
|
if (sock->watch <= 0) {
|
||||||
VIR_DEBUG("Watch not registered on socket %p", sock);
|
VIR_DEBUG("Watch not registered on socket %p", sock);
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
virEventRemoveHandle(sock->watch);
|
virEventRemoveHandle(sock->watch);
|
||||||
|
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void virNetSocketClose(virNetSocketPtr sock)
|
void virNetSocketClose(virNetSocketPtr sock)
|
||||||
@ -1746,7 +1735,7 @@ void virNetSocketClose(virNetSocketPtr sock)
|
|||||||
if (!sock)
|
if (!sock)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
virMutexLock(&sock->lock);
|
virObjectLock(sock);
|
||||||
|
|
||||||
VIR_FORCE_CLOSE(sock->fd);
|
VIR_FORCE_CLOSE(sock->fd);
|
||||||
|
|
||||||
@ -1760,5 +1749,5 @@ void virNetSocketClose(virNetSocketPtr sock)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
virMutexUnlock(&sock->lock);
|
virObjectUnlock(sock);
|
||||||
}
|
}
|
||||||
|
@ -78,9 +78,8 @@ struct _virNetSSHAuthMethod {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _virNetSSHSession {
|
struct _virNetSSHSession {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
virNetSSHSessionState state;
|
virNetSSHSessionState state;
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
/* libssh2 internal stuff */
|
/* libssh2 internal stuff */
|
||||||
LIBSSH2_SESSION *session;
|
LIBSSH2_SESSION *session;
|
||||||
@ -161,7 +160,7 @@ static virClassPtr virNetSSHSessionClass;
|
|||||||
static int
|
static int
|
||||||
virNetSSHSessionOnceInit(void)
|
virNetSSHSessionOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetSSHSessionClass = virClassNew(virClassForObject(),
|
if (!(virNetSSHSessionClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetSSHSession",
|
"virNetSSHSession",
|
||||||
sizeof(virNetSSHSession),
|
sizeof(virNetSSHSession),
|
||||||
virNetSSHSessionDispose)))
|
virNetSSHSessionDispose)))
|
||||||
@ -927,18 +926,18 @@ int
|
|||||||
virNetSSHSessionAuthSetCallback(virNetSSHSessionPtr sess,
|
virNetSSHSessionAuthSetCallback(virNetSSHSessionPtr sess,
|
||||||
virConnectAuthPtr auth)
|
virConnectAuthPtr auth)
|
||||||
{
|
{
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
sess->cred = auth;
|
sess->cred = auth;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
virNetSSHSessionAuthReset(virNetSSHSessionPtr sess)
|
virNetSSHSessionAuthReset(virNetSSHSessionPtr sess)
|
||||||
{
|
{
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
virNetSSHSessionAuthMethodsFree(sess);
|
virNetSSHSessionAuthMethodsFree(sess);
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -957,7 +956,7 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
if (!(user = strdup(username)) ||
|
if (!(user = strdup(username)) ||
|
||||||
!(pass = strdup(password)))
|
!(pass = strdup(password)))
|
||||||
@ -970,14 +969,14 @@ virNetSSHSessionAuthAddPasswordAuth(virNetSSHSessionPtr sess,
|
|||||||
auth->password = pass;
|
auth->password = pass;
|
||||||
auth->method = VIR_NET_SSH_AUTH_PASSWORD;
|
auth->method = VIR_NET_SSH_AUTH_PASSWORD;
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
VIR_FREE(user);
|
VIR_FREE(user);
|
||||||
VIR_FREE(pass);
|
VIR_FREE(pass);
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -995,7 +994,7 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
if (!(user = strdup(username)))
|
if (!(user = strdup(username)))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
@ -1006,13 +1005,13 @@ virNetSSHSessionAuthAddAgentAuth(virNetSSHSessionPtr sess,
|
|||||||
auth->username = user;
|
auth->username = user;
|
||||||
auth->method = VIR_NET_SSH_AUTH_AGENT;
|
auth->method = VIR_NET_SSH_AUTH_AGENT;
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
VIR_FREE(user);
|
VIR_FREE(user);
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1035,7 +1034,7 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
if (!(user = strdup(username)) ||
|
if (!(user = strdup(username)) ||
|
||||||
!(file = strdup(keyfile)))
|
!(file = strdup(keyfile)))
|
||||||
@ -1052,7 +1051,7 @@ virNetSSHSessionAuthAddPrivKeyAuth(virNetSSHSessionPtr sess,
|
|||||||
auth->filename = file;
|
auth->filename = file;
|
||||||
auth->method = VIR_NET_SSH_AUTH_PRIVKEY;
|
auth->method = VIR_NET_SSH_AUTH_PRIVKEY;
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
@ -1060,7 +1059,7 @@ no_memory:
|
|||||||
VIR_FREE(pass);
|
VIR_FREE(pass);
|
||||||
VIR_FREE(file);
|
VIR_FREE(file);
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1079,7 +1078,7 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
if (!(user = strdup(username)))
|
if (!(user = strdup(username)))
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
@ -1091,13 +1090,13 @@ virNetSSHSessionAuthAddKeyboardAuth(virNetSSHSessionPtr sess,
|
|||||||
auth->tries = tries;
|
auth->tries = tries;
|
||||||
auth->method = VIR_NET_SSH_AUTH_KEYBOARD_INTERACTIVE;
|
auth->method = VIR_NET_SSH_AUTH_KEYBOARD_INTERACTIVE;
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
VIR_FREE(user);
|
VIR_FREE(user);
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -1107,7 +1106,7 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess,
|
|||||||
const char *command)
|
const char *command)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
VIR_FREE(sess->channelCommand);
|
VIR_FREE(sess->channelCommand);
|
||||||
|
|
||||||
@ -1116,7 +1115,7 @@ virNetSSHSessionSetChannelCommand(virNetSSHSessionPtr sess,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1130,7 +1129,7 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
|
|||||||
{
|
{
|
||||||
char *errmsg;
|
char *errmsg;
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
sess->port = port;
|
sess->port = port;
|
||||||
sess->hostKeyVerify = opt;
|
sess->hostKeyVerify = opt;
|
||||||
@ -1167,13 +1166,13 @@ virNetSSHSessionSetHostKeyVerification(virNetSSHSessionPtr sess,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
no_memory:
|
no_memory:
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
error:
|
error:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1185,16 +1184,9 @@ virNetSSHSessionPtr virNetSSHSessionNew(void)
|
|||||||
if (virNetSSHSessionInitialize() < 0)
|
if (virNetSSHSessionInitialize() < 0)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (!(sess = virObjectNew(virNetSSHSessionClass)))
|
if (!(sess = virObjectLockableNew(virNetSSHSessionClass)))
|
||||||
goto error;
|
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
|
/* initialize session data, use the internal data for callbacks
|
||||||
* and stick to default memory management functions */
|
* and stick to default memory management functions */
|
||||||
if (!(sess->session = libssh2_session_init_ex(NULL,
|
if (!(sess->session = libssh2_session_init_ex(NULL,
|
||||||
@ -1250,7 +1242,7 @@ virNetSSHSessionConnect(virNetSSHSessionPtr sess,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
/* check if configuration is valid */
|
/* check if configuration is valid */
|
||||||
if ((ret = virNetSSHValidateConfig(sess)) < 0)
|
if ((ret = virNetSSHValidateConfig(sess)) < 0)
|
||||||
@ -1284,12 +1276,12 @@ virNetSSHSessionConnect(virNetSSHSessionPtr sess,
|
|||||||
libssh2_session_set_blocking(sess->session, 0);
|
libssh2_session_set_blocking(sess->session, 0);
|
||||||
sess->state = VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE;
|
sess->state = VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE;
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
sess->state = VIR_NET_SSH_STATE_ERROR;
|
sess->state = VIR_NET_SSH_STATE_ERROR;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1302,7 +1294,7 @@ virNetSSHChannelRead(virNetSSHSessionPtr sess,
|
|||||||
ssize_t ret = -1;
|
ssize_t ret = -1;
|
||||||
ssize_t read_n = 0;
|
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_HANDSHAKE_COMPLETE) {
|
||||||
if (sess->state == VIR_NET_SSH_STATE_ERROR_REMOTE)
|
if (sess->state == VIR_NET_SSH_STATE_ERROR_REMOTE)
|
||||||
@ -1314,7 +1306,7 @@ virNetSSHChannelRead(virNetSSHSessionPtr sess,
|
|||||||
virReportError(VIR_ERR_SSH, "%s",
|
virReportError(VIR_ERR_SSH, "%s",
|
||||||
_("Tried to write socket in error state"));
|
_("Tried to write socket in error state"));
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1387,22 +1379,22 @@ virNetSSHChannelRead(virNetSSHSessionPtr sess,
|
|||||||
libssh2_channel_get_exit_status(sess->channel));
|
libssh2_channel_get_exit_status(sess->channel));
|
||||||
sess->channelCommandReturnValue = libssh2_channel_get_exit_status(sess->channel);
|
sess->channelCommandReturnValue = libssh2_channel_get_exit_status(sess->channel);
|
||||||
sess->state = VIR_NET_SSH_STATE_ERROR_REMOTE;
|
sess->state = VIR_NET_SSH_STATE_ERROR_REMOTE;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
sess->state = VIR_NET_SSH_STATE_CLOSED;
|
sess->state = VIR_NET_SSH_STATE_CLOSED;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
success:
|
success:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return read_n;
|
return read_n;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
sess->state = VIR_NET_SSH_STATE_ERROR;
|
sess->state = VIR_NET_SSH_STATE_ERROR;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1413,7 +1405,7 @@ virNetSSHChannelWrite(virNetSSHSessionPtr sess,
|
|||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
if (sess->state != VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE) {
|
if (sess->state != VIR_NET_SSH_STATE_HANDSHAKE_COMPLETE) {
|
||||||
if (sess->state == VIR_NET_SSH_STATE_ERROR_REMOTE)
|
if (sess->state == VIR_NET_SSH_STATE_ERROR_REMOTE)
|
||||||
@ -1459,7 +1451,7 @@ virNetSSHChannelWrite(virNetSSHSessionPtr sess,
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1471,10 +1463,10 @@ virNetSSHSessionHasCachedData(virNetSSHSessionPtr sess)
|
|||||||
if (!sess)
|
if (!sess)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
|
|
||||||
ret = sess->bufUsed > 0;
|
ret = sess->bufUsed > 0;
|
||||||
|
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -50,9 +50,7 @@
|
|||||||
#define VIR_FROM_THIS VIR_FROM_RPC
|
#define VIR_FROM_THIS VIR_FROM_RPC
|
||||||
|
|
||||||
struct _virNetTLSContext {
|
struct _virNetTLSContext {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
gnutls_certificate_credentials_t x509cred;
|
gnutls_certificate_credentials_t x509cred;
|
||||||
gnutls_dh_params_t dhParams;
|
gnutls_dh_params_t dhParams;
|
||||||
@ -63,9 +61,7 @@ struct _virNetTLSContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct _virNetTLSSession {
|
struct _virNetTLSSession {
|
||||||
virObject object;
|
virObjectLockable parent;
|
||||||
|
|
||||||
virMutex lock;
|
|
||||||
|
|
||||||
bool handshakeComplete;
|
bool handshakeComplete;
|
||||||
|
|
||||||
@ -85,13 +81,13 @@ static void virNetTLSSessionDispose(void *obj);
|
|||||||
|
|
||||||
static int virNetTLSContextOnceInit(void)
|
static int virNetTLSContextOnceInit(void)
|
||||||
{
|
{
|
||||||
if (!(virNetTLSContextClass = virClassNew(virClassForObject(),
|
if (!(virNetTLSContextClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetTLSContext",
|
"virNetTLSContext",
|
||||||
sizeof(virNetTLSContext),
|
sizeof(virNetTLSContext),
|
||||||
virNetTLSContextDispose)))
|
virNetTLSContextDispose)))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (!(virNetTLSSessionClass = virClassNew(virClassForObject(),
|
if (!(virNetTLSSessionClass = virClassNew(virClassForObjectLockable(),
|
||||||
"virNetTLSSession",
|
"virNetTLSSession",
|
||||||
sizeof(virNetTLSSession),
|
sizeof(virNetTLSSession),
|
||||||
virNetTLSSessionDispose)))
|
virNetTLSSessionDispose)))
|
||||||
@ -676,16 +672,9 @@ static virNetTLSContextPtr virNetTLSContextNew(const char *cacert,
|
|||||||
if (virNetTLSContextInitialize() < 0)
|
if (virNetTLSContextInitialize() < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (!(ctxt = virObjectNew(virNetTLSContextClass)))
|
if (!(ctxt = virObjectLockableNew(virNetTLSContextClass)))
|
||||||
return NULL;
|
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) {
|
if ((gnutlsdebug = getenv("LIBVIRT_GNUTLS_DEBUG")) != NULL) {
|
||||||
int val;
|
int val;
|
||||||
if (virStrToLong_i(gnutlsdebug, NULL, 10, &val) < 0)
|
if (virStrToLong_i(gnutlsdebug, NULL, 10, &val) < 0)
|
||||||
@ -1097,8 +1086,8 @@ int virNetTLSContextCheckCertificate(virNetTLSContextPtr ctxt,
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
virMutexLock(&ctxt->lock);
|
virObjectLock(ctxt);
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
if (virNetTLSContextValidCertificate(ctxt, sess) < 0) {
|
if (virNetTLSContextValidCertificate(ctxt, sess) < 0) {
|
||||||
virErrorPtr err = virGetLastError();
|
virErrorPtr err = virGetLastError();
|
||||||
VIR_WARN("Certificate check failed %s", err && err->message ? err->message : "<unknown>");
|
VIR_WARN("Certificate check failed %s", err && err->message ? err->message : "<unknown>");
|
||||||
@ -1114,8 +1103,8 @@ int virNetTLSContextCheckCertificate(virNetTLSContextPtr ctxt,
|
|||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&ctxt->lock);
|
virObjectUnlock(ctxt);
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1126,7 +1115,6 @@ void virNetTLSContextDispose(void *obj)
|
|||||||
|
|
||||||
gnutls_dh_params_deinit(ctxt->dhParams);
|
gnutls_dh_params_deinit(ctxt->dhParams);
|
||||||
gnutls_certificate_free_credentials(ctxt->x509cred);
|
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",
|
VIR_DEBUG("ctxt=%p hostname=%s isServer=%d",
|
||||||
ctxt, NULLSTR(hostname), ctxt->isServer);
|
ctxt, NULLSTR(hostname), ctxt->isServer);
|
||||||
|
|
||||||
if (!(sess = virObjectNew(virNetTLSSessionClass)))
|
if (!(sess = virObjectLockableNew(virNetTLSSessionClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (virMutexInit(&sess->lock) < 0) {
|
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
|
||||||
_("Failed to initialized mutex"));
|
|
||||||
VIR_FREE(sess);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (hostname &&
|
if (hostname &&
|
||||||
!(sess->hostname = strdup(hostname))) {
|
!(sess->hostname = strdup(hostname))) {
|
||||||
virReportOOMError();
|
virReportOOMError();
|
||||||
@ -1243,11 +1224,11 @@ void virNetTLSSessionSetIOCallbacks(virNetTLSSessionPtr sess,
|
|||||||
virNetTLSSessionReadFunc readFunc,
|
virNetTLSSessionReadFunc readFunc,
|
||||||
void *opaque)
|
void *opaque)
|
||||||
{
|
{
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
sess->writeFunc = writeFunc;
|
sess->writeFunc = writeFunc;
|
||||||
sess->readFunc = readFunc;
|
sess->readFunc = readFunc;
|
||||||
sess->opaque = opaque;
|
sess->opaque = opaque;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1256,7 +1237,7 @@ ssize_t virNetTLSSessionWrite(virNetTLSSessionPtr sess,
|
|||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
ret = gnutls_record_send(sess->session, buf, len);
|
ret = gnutls_record_send(sess->session, buf, len);
|
||||||
|
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
@ -1280,7 +1261,7 @@ ssize_t virNetTLSSessionWrite(virNetTLSSessionPtr sess,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1289,7 +1270,7 @@ ssize_t virNetTLSSessionRead(virNetTLSSessionPtr sess,
|
|||||||
{
|
{
|
||||||
ssize_t ret;
|
ssize_t ret;
|
||||||
|
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
ret = gnutls_record_recv(sess->session, buf, len);
|
ret = gnutls_record_recv(sess->session, buf, len);
|
||||||
|
|
||||||
if (ret >= 0)
|
if (ret >= 0)
|
||||||
@ -1310,7 +1291,7 @@ ssize_t virNetTLSSessionRead(virNetTLSSessionPtr sess,
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1318,7 +1299,7 @@ int virNetTLSSessionHandshake(virNetTLSSessionPtr sess)
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
VIR_DEBUG("sess=%p", sess);
|
VIR_DEBUG("sess=%p", sess);
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
ret = gnutls_handshake(sess->session);
|
ret = gnutls_handshake(sess->session);
|
||||||
VIR_DEBUG("Ret=%d", ret);
|
VIR_DEBUG("Ret=%d", ret);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
@ -1342,7 +1323,7 @@ int virNetTLSSessionHandshake(virNetTLSSessionPtr sess)
|
|||||||
ret = -1;
|
ret = -1;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1350,14 +1331,14 @@ virNetTLSSessionHandshakeStatus
|
|||||||
virNetTLSSessionGetHandshakeStatus(virNetTLSSessionPtr sess)
|
virNetTLSSessionGetHandshakeStatus(virNetTLSSessionPtr sess)
|
||||||
{
|
{
|
||||||
virNetTLSSessionHandshakeStatus ret;
|
virNetTLSSessionHandshakeStatus ret;
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
if (sess->handshakeComplete)
|
if (sess->handshakeComplete)
|
||||||
ret = VIR_NET_TLS_HANDSHAKE_COMPLETE;
|
ret = VIR_NET_TLS_HANDSHAKE_COMPLETE;
|
||||||
else if (gnutls_record_get_direction(sess->session) == 0)
|
else if (gnutls_record_get_direction(sess->session) == 0)
|
||||||
ret = VIR_NET_TLS_HANDSHAKE_RECVING;
|
ret = VIR_NET_TLS_HANDSHAKE_RECVING;
|
||||||
else
|
else
|
||||||
ret = VIR_NET_TLS_HANDSHAKE_SENDING;
|
ret = VIR_NET_TLS_HANDSHAKE_SENDING;
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1365,7 +1346,7 @@ int virNetTLSSessionGetKeySize(virNetTLSSessionPtr sess)
|
|||||||
{
|
{
|
||||||
gnutls_cipher_algorithm_t cipher;
|
gnutls_cipher_algorithm_t cipher;
|
||||||
int ssf;
|
int ssf;
|
||||||
virMutexLock(&sess->lock);
|
virObjectLock(sess);
|
||||||
cipher = gnutls_cipher_get(sess->session);
|
cipher = gnutls_cipher_get(sess->session);
|
||||||
if (!(ssf = gnutls_cipher_get_key_size(cipher))) {
|
if (!(ssf = gnutls_cipher_get_key_size(cipher))) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||||
@ -1375,7 +1356,7 @@ int virNetTLSSessionGetKeySize(virNetTLSSessionPtr sess)
|
|||||||
}
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virMutexUnlock(&sess->lock);
|
virObjectUnlock(sess);
|
||||||
return ssf;
|
return ssf;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1386,7 +1367,6 @@ void virNetTLSSessionDispose(void *obj)
|
|||||||
|
|
||||||
VIR_FREE(sess->hostname);
|
VIR_FREE(sess->hostname);
|
||||||
gnutls_deinit(sess->session);
|
gnutls_deinit(sess->session);
|
||||||
virMutexDestroy(&sess->lock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user