mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
Turn virNetServer* into virObject instances
Make all the virNetServer* objects use the virObject APIs for reference counting Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
410a5dac42
commit
958499b0c1
4
cfg.mk
4
cfg.mk
@ -148,13 +148,9 @@ useless_free_options = \
|
||||
--name=virNetClientFree \
|
||||
--name=virNetClientProgramFree \
|
||||
--name=virNetClientStreamFree \
|
||||
--name=virNetServerFree \
|
||||
--name=virNetServerClientFree \
|
||||
--name=virNetServerMDNSFree \
|
||||
--name=virNetServerMDNSEntryFree \
|
||||
--name=virNetServerMDNSGroupFree \
|
||||
--name=virNetServerProgramFree \
|
||||
--name=virNetServerServiceFree \
|
||||
--name=virNWFilterDefFree \
|
||||
--name=virNWFilterEntryFree \
|
||||
--name=virNWFilterHashTableFree \
|
||||
|
@ -568,10 +568,10 @@ static int daemonSetupNetworking(virNetServerPtr srv,
|
||||
return 0;
|
||||
|
||||
error:
|
||||
virNetServerServiceFree(svcTLS);
|
||||
virNetServerServiceFree(svcTCP);
|
||||
virNetServerServiceFree(svc);
|
||||
virNetServerServiceFree(svcRO);
|
||||
virObjectUnref(svcTLS);
|
||||
virObjectUnref(svcTCP);
|
||||
virObjectUnref(svc);
|
||||
virObjectUnref(svcRO);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -759,21 +759,21 @@ static void daemonRunStateInit(void *opaque)
|
||||
VIR_ERROR(_("Driver state initialization failed"));
|
||||
/* Ensure the main event loop quits */
|
||||
kill(getpid(), SIGTERM);
|
||||
virNetServerFree(srv);
|
||||
virObjectUnref(srv);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Only now accept clients from network */
|
||||
virNetServerUpdateServices(srv, true);
|
||||
virNetServerFree(srv);
|
||||
virObjectUnref(srv);
|
||||
}
|
||||
|
||||
static int daemonStateInit(virNetServerPtr srv)
|
||||
{
|
||||
virThread thr;
|
||||
virNetServerRef(srv);
|
||||
virObjectRef(srv);
|
||||
if (virThreadCreate(&thr, false, daemonRunStateInit, srv) < 0) {
|
||||
virNetServerFree(srv);
|
||||
virObjectUnref(srv);
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@ -1325,10 +1325,10 @@ int main(int argc, char **argv) {
|
||||
|
||||
cleanup:
|
||||
virNetlinkEventServiceStop();
|
||||
virNetServerProgramFree(remoteProgram);
|
||||
virNetServerProgramFree(qemuProgram);
|
||||
virObjectUnref(remoteProgram);
|
||||
virObjectUnref(qemuProgram);
|
||||
virNetServerClose(srv);
|
||||
virNetServerFree(srv);
|
||||
virObjectUnref(srv);
|
||||
virNetlinkShutdown();
|
||||
if (statuswrite != -1) {
|
||||
if (ret != 0) {
|
||||
|
@ -104,14 +104,6 @@ daemonStreamMessageFinished(virNetMessagePtr msg ATTRIBUTE_UNUSED,
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
daemonStreamEventFreeFunc(void *opaque)
|
||||
{
|
||||
virNetServerClientPtr client = opaque;
|
||||
|
||||
virNetServerClientFree(client);
|
||||
}
|
||||
|
||||
/*
|
||||
* Callback that gets invoked when a stream becomes writable/readable
|
||||
*/
|
||||
@ -332,14 +324,12 @@ daemonCreateClientStream(virNetServerClientPtr client,
|
||||
|
||||
stream->refs = 1;
|
||||
stream->priv = priv;
|
||||
stream->prog = prog;
|
||||
stream->prog = virObjectRef(prog);
|
||||
stream->procedure = header->proc;
|
||||
stream->serial = header->serial;
|
||||
stream->filterID = -1;
|
||||
stream->st = st;
|
||||
|
||||
virNetServerProgramRef(prog);
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
@ -365,7 +355,7 @@ int daemonFreeClientStream(virNetServerClientPtr client,
|
||||
VIR_DEBUG("client=%p, proc=%d, serial=%d",
|
||||
client, stream->procedure, stream->serial);
|
||||
|
||||
virNetServerProgramFree(stream->prog);
|
||||
virObjectUnref(stream->prog);
|
||||
|
||||
msg = stream->rx;
|
||||
while (msg) {
|
||||
@ -411,10 +401,11 @@ int daemonAddClientStream(virNetServerClientPtr client,
|
||||
|
||||
if (virStreamEventAddCallback(stream->st, 0,
|
||||
daemonStreamEvent, client,
|
||||
daemonStreamEventFreeFunc) < 0)
|
||||
virObjectFreeCallback) < 0)
|
||||
return -1;
|
||||
|
||||
virNetServerClientRef(client);
|
||||
virObjectRef(client);
|
||||
|
||||
if ((stream->filterID = virNetServerClientAddFilter(client,
|
||||
daemonStreamFilter,
|
||||
stream)) < 0) {
|
||||
|
@ -1485,14 +1485,11 @@ virNetServerAddService;
|
||||
virNetServerAddSignalHandler;
|
||||
virNetServerAutoShutdown;
|
||||
virNetServerClose;
|
||||
virNetServerFree;
|
||||
virNetServerIsPrivileged;
|
||||
virNetServerKeepAliveRequired;
|
||||
virNetServerNew;
|
||||
virNetServerQuit;
|
||||
virNetServerRef;
|
||||
virNetServerRun;
|
||||
virNetServerServiceFree;
|
||||
virNetServerServiceNewTCP;
|
||||
virNetServerServiceNewUNIX;
|
||||
virNetServerSetTLSContext;
|
||||
@ -1503,7 +1500,6 @@ virNetServerUpdateServices;
|
||||
virNetServerClientAddFilter;
|
||||
virNetServerClientClose;
|
||||
virNetServerClientDelayedClose;
|
||||
virNetServerClientFree;
|
||||
virNetServerClientGetAuth;
|
||||
virNetServerClientGetFD;
|
||||
virNetServerClientGetIdentity;
|
||||
@ -1520,7 +1516,6 @@ virNetServerClientIsSecure;
|
||||
virNetServerClientLocalAddrString;
|
||||
virNetServerClientNeedAuth;
|
||||
virNetServerClientNew;
|
||||
virNetServerClientRef;
|
||||
virNetServerClientRemoteAddrString;
|
||||
virNetServerClientRemoveFilter;
|
||||
virNetServerClientSendMessage;
|
||||
@ -1547,13 +1542,11 @@ virNetServerMDNSStop;
|
||||
|
||||
# virnetserverprogram.h
|
||||
virNetServerProgramDispatch;
|
||||
virNetServerProgramFree;
|
||||
virNetServerProgramGetID;
|
||||
virNetServerProgramGetPriority;
|
||||
virNetServerProgramGetVersion;
|
||||
virNetServerProgramMatches;
|
||||
virNetServerProgramNew;
|
||||
virNetServerProgramRef;
|
||||
virNetServerProgramSendReplyError;
|
||||
virNetServerProgramSendStreamData;
|
||||
virNetServerProgramSendStreamError;
|
||||
@ -1562,13 +1555,11 @@ virNetServerProgramUnknownError;
|
||||
|
||||
# virnetserverservice.h
|
||||
virNetServerServiceClose;
|
||||
virNetServerServiceFree;
|
||||
virNetServerServiceGetAuth;
|
||||
virNetServerServiceGetPort;
|
||||
virNetServerServiceIsReadonly;
|
||||
virNetServerServiceNewTCP;
|
||||
virNetServerServiceNewUNIX;
|
||||
virNetServerServiceRef;
|
||||
virNetServerServiceSetDispatcher;
|
||||
virNetServerServiceToggle;
|
||||
|
||||
|
@ -32,9 +32,7 @@ provider libvirt {
|
||||
|
||||
# file: src/rpc/virnetserverclient.c
|
||||
# prefix: rpc
|
||||
probe rpc_server_client_new(void *client, int refs, void *sock);
|
||||
probe rpc_server_client_ref(void *client, int refs);
|
||||
probe rpc_server_client_free(void *client, int refs);
|
||||
probe rpc_server_client_new(void *client, void *sock);
|
||||
|
||||
probe rpc_server_client_msg_tx_queue(void *client, int len, int prog, int vers, int proc, int type, int status, int serial);
|
||||
probe rpc_server_client_msg_rx(void *client, int len, int prog, int vers, int proc, int type, int status, int serial);
|
||||
|
@ -264,7 +264,7 @@ static void virLXCControllerFree(virLXCControllerPtr ctrl)
|
||||
if (ctrl->timerShutdown != -1)
|
||||
virEventRemoveTimeout(ctrl->timerShutdown);
|
||||
|
||||
virNetServerFree(ctrl->server);
|
||||
virObjectUnref(ctrl->server);
|
||||
|
||||
VIR_FREE(ctrl);
|
||||
}
|
||||
@ -620,7 +620,7 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
|
||||
|
||||
if (virNetServerAddService(ctrl->server, svc, NULL) < 0)
|
||||
goto error;
|
||||
virNetServerServiceFree(svc);
|
||||
virObjectUnref(svc);
|
||||
svc = NULL;
|
||||
|
||||
if (!(ctrl->prog = virNetServerProgramNew(VIR_LXC_PROTOCOL_PROGRAM,
|
||||
@ -635,9 +635,9 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl)
|
||||
|
||||
error:
|
||||
VIR_FREE(sockpath);
|
||||
virNetServerFree(ctrl->server);
|
||||
virObjectUnref(ctrl->server);
|
||||
ctrl->server = NULL;
|
||||
virNetServerServiceFree(svc);
|
||||
virObjectUnref(svc);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ struct _virNetServerJob {
|
||||
};
|
||||
|
||||
struct _virNetServer {
|
||||
int refs;
|
||||
virObjectPtr object;
|
||||
|
||||
virMutex lock;
|
||||
|
||||
@ -109,6 +109,22 @@ struct _virNetServer {
|
||||
};
|
||||
|
||||
|
||||
static virClassPtr virNetServerClass;
|
||||
static void virNetServerDispose(void *obj);
|
||||
|
||||
static int virNetServerOnceInit(void)
|
||||
{
|
||||
if (!(virNetServerClass = virClassNew("virNetServer",
|
||||
sizeof(virNetServer),
|
||||
virNetServerDispose)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virNetServer)
|
||||
|
||||
|
||||
static void virNetServerLock(virNetServerPtr srv)
|
||||
{
|
||||
virMutexLock(&srv->lock);
|
||||
@ -175,18 +191,18 @@ static void virNetServerHandleJob(void *jobOpaque, void *opaque)
|
||||
goto error;
|
||||
|
||||
virNetServerLock(srv);
|
||||
virNetServerProgramFree(job->prog);
|
||||
virObjectUnref(job->prog);
|
||||
virNetServerUnlock(srv);
|
||||
|
||||
virNetServerClientFree(job->client);
|
||||
virObjectUnref(job->client);
|
||||
VIR_FREE(job);
|
||||
return;
|
||||
|
||||
error:
|
||||
virNetServerProgramFree(job->prog);
|
||||
virObjectUnref(job->prog);
|
||||
virNetMessageFree(job->msg);
|
||||
virNetServerClientClose(job->client);
|
||||
virNetServerClientFree(job->client);
|
||||
virObjectUnref(job->client);
|
||||
VIR_FREE(job);
|
||||
}
|
||||
|
||||
@ -223,7 +239,7 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
|
||||
job->msg = msg;
|
||||
|
||||
if (prog) {
|
||||
virNetServerProgramRef(prog);
|
||||
virObjectRef(prog);
|
||||
job->prog = prog;
|
||||
priority = virNetServerProgramGetPriority(prog, msg->header.proc);
|
||||
}
|
||||
@ -232,7 +248,7 @@ static int virNetServerDispatchNewMessage(virNetServerClientPtr client,
|
||||
|
||||
if (ret < 0) {
|
||||
VIR_FREE(job);
|
||||
virNetServerProgramFree(prog);
|
||||
virObjectUnref(prog);
|
||||
}
|
||||
} else {
|
||||
ret = virNetServerProcessMsg(srv, client, prog, msg);
|
||||
@ -272,7 +288,7 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc ATTRIBUTE_UN
|
||||
goto error;
|
||||
}
|
||||
srv->clients[srv->nclients-1] = client;
|
||||
virNetServerClientRef(client);
|
||||
virObjectRef(client);
|
||||
|
||||
virNetServerClientSetDispatcher(client,
|
||||
virNetServerDispatchNewMessage,
|
||||
@ -332,12 +348,11 @@ virNetServerPtr virNetServerNew(size_t min_workers,
|
||||
virNetServerPtr srv;
|
||||
struct sigaction sig_action;
|
||||
|
||||
if (VIR_ALLOC(srv) < 0) {
|
||||
virReportOOMError();
|
||||
if (virNetServerInitialize() < 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
srv->refs = 1;
|
||||
if (!(srv = virObjectNew(virNetServerClass)))
|
||||
return NULL;
|
||||
|
||||
if (max_workers &&
|
||||
!(srv->workers = virThreadPoolNew(min_workers, max_workers,
|
||||
@ -398,24 +413,14 @@ virNetServerPtr virNetServerNew(size_t min_workers,
|
||||
sigaction(SIGUSR2, &sig_action, NULL);
|
||||
#endif
|
||||
|
||||
VIR_DEBUG("srv=%p refs=%d", srv, srv->refs);
|
||||
return srv;
|
||||
|
||||
error:
|
||||
virNetServerFree(srv);
|
||||
virObjectUnref(srv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void virNetServerRef(virNetServerPtr srv)
|
||||
{
|
||||
virNetServerLock(srv);
|
||||
srv->refs++;
|
||||
VIR_DEBUG("srv=%p refs=%d", srv, srv->refs);
|
||||
virNetServerUnlock(srv);
|
||||
}
|
||||
|
||||
|
||||
bool virNetServerIsPrivileged(virNetServerPtr srv)
|
||||
{
|
||||
bool priv;
|
||||
@ -603,7 +608,7 @@ int virNetServerAddService(virNetServerPtr srv,
|
||||
}
|
||||
|
||||
srv->services[srv->nservices-1] = svc;
|
||||
virNetServerServiceRef(svc);
|
||||
virObjectRef(svc);
|
||||
|
||||
virNetServerServiceSetDispatcher(svc,
|
||||
virNetServerDispatchNewClient,
|
||||
@ -627,8 +632,7 @@ int virNetServerAddProgram(virNetServerPtr srv,
|
||||
if (VIR_EXPAND_N(srv->programs, srv->nprograms, 1) < 0)
|
||||
goto no_memory;
|
||||
|
||||
srv->programs[srv->nprograms-1] = prog;
|
||||
virNetServerProgramRef(prog);
|
||||
srv->programs[srv->nprograms-1] = virObjectRef(prog);
|
||||
|
||||
virNetServerUnlock(srv);
|
||||
return 0;
|
||||
@ -737,7 +741,7 @@ void virNetServerRun(virNetServerPtr srv)
|
||||
if (virNetServerClientWantClose(srv->clients[i]))
|
||||
virNetServerClientClose(srv->clients[i]);
|
||||
if (virNetServerClientIsClosed(srv->clients[i])) {
|
||||
virNetServerClientFree(srv->clients[i]);
|
||||
virObjectUnref(srv->clients[i]);
|
||||
if (srv->nclients > 1) {
|
||||
memmove(srv->clients + i,
|
||||
srv->clients + i + 1,
|
||||
@ -768,20 +772,10 @@ void virNetServerQuit(virNetServerPtr srv)
|
||||
virNetServerUnlock(srv);
|
||||
}
|
||||
|
||||
void virNetServerFree(virNetServerPtr srv)
|
||||
void virNetServerDispose(void *obj)
|
||||
{
|
||||
virNetServerPtr srv = obj;
|
||||
int i;
|
||||
int refs;
|
||||
|
||||
if (!srv)
|
||||
return;
|
||||
|
||||
virNetServerLock(srv);
|
||||
VIR_DEBUG("srv=%p refs=%d", srv, srv->refs);
|
||||
refs = --srv->refs;
|
||||
virNetServerUnlock(srv);
|
||||
if (refs > 0)
|
||||
return;
|
||||
|
||||
for (i = 0 ; i < srv->nservices ; i++)
|
||||
virNetServerServiceToggle(srv->services[i], false);
|
||||
@ -799,16 +793,16 @@ void virNetServerFree(virNetServerPtr srv)
|
||||
virEventRemoveHandle(srv->sigwatch);
|
||||
|
||||
for (i = 0 ; i < srv->nservices ; i++)
|
||||
virNetServerServiceFree(srv->services[i]);
|
||||
virObjectUnref(srv->services[i]);
|
||||
VIR_FREE(srv->services);
|
||||
|
||||
for (i = 0 ; i < srv->nprograms ; i++)
|
||||
virNetServerProgramFree(srv->programs[i]);
|
||||
virObjectUnref(srv->programs[i]);
|
||||
VIR_FREE(srv->programs);
|
||||
|
||||
for (i = 0 ; i < srv->nclients ; i++) {
|
||||
virNetServerClientClose(srv->clients[i]);
|
||||
virNetServerClientFree(srv->clients[i]);
|
||||
virObjectUnref(srv->clients[i]);
|
||||
}
|
||||
VIR_FREE(srv->clients);
|
||||
|
||||
@ -816,7 +810,6 @@ void virNetServerFree(virNetServerPtr srv)
|
||||
virNetServerMDNSFree(srv->mdns);
|
||||
|
||||
virMutexDestroy(&srv->lock);
|
||||
VIR_FREE(srv);
|
||||
}
|
||||
|
||||
void virNetServerClose(virNetServerPtr srv)
|
||||
|
@ -30,6 +30,7 @@
|
||||
# include "virnetserverprogram.h"
|
||||
# include "virnetserverclient.h"
|
||||
# include "virnetserverservice.h"
|
||||
# include "virobject.h"
|
||||
|
||||
typedef int (*virNetServerClientInitHook)(virNetServerPtr srv,
|
||||
virNetServerClientPtr client,
|
||||
@ -48,8 +49,6 @@ virNetServerPtr virNetServerNew(size_t min_workers,
|
||||
|
||||
typedef int (*virNetServerAutoShutdownFunc)(virNetServerPtr srv, void *opaque);
|
||||
|
||||
void virNetServerRef(virNetServerPtr srv);
|
||||
|
||||
bool virNetServerIsPrivileged(virNetServerPtr srv);
|
||||
|
||||
void virNetServerAutoShutdown(virNetServerPtr srv,
|
||||
@ -81,8 +80,6 @@ void virNetServerRun(virNetServerPtr srv);
|
||||
|
||||
void virNetServerQuit(virNetServerPtr srv);
|
||||
|
||||
void virNetServerFree(virNetServerPtr srv);
|
||||
|
||||
void virNetServerClose(virNetServerPtr srv);
|
||||
|
||||
bool virNetServerKeepAliveRequired(virNetServerPtr srv);
|
||||
|
@ -57,7 +57,8 @@ struct _virNetServerClientFilter {
|
||||
|
||||
struct _virNetServerClient
|
||||
{
|
||||
int refs;
|
||||
virObject object;
|
||||
|
||||
bool wantClose;
|
||||
bool delayedClose;
|
||||
virMutex lock;
|
||||
@ -103,6 +104,22 @@ struct _virNetServerClient
|
||||
};
|
||||
|
||||
|
||||
static virClassPtr virNetServerClientClass;
|
||||
static void virNetServerClientDispose(void *obj);
|
||||
|
||||
static int virNetServerClientOnceInit(void)
|
||||
{
|
||||
if (!(virNetServerClientClass = virClassNew("virNetServerClient",
|
||||
sizeof(virNetServerClient),
|
||||
virNetServerClientDispose)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virNetServerClient)
|
||||
|
||||
|
||||
static void virNetServerClientDispatchEvent(virNetSocketPtr sock, int events, void *opaque);
|
||||
static void virNetServerClientUpdateEvent(virNetServerClientPtr client);
|
||||
static void virNetServerClientDispatchRead(virNetServerClientPtr client);
|
||||
@ -167,13 +184,6 @@ virNetServerClientCalculateHandleMode(virNetServerClientPtr client) {
|
||||
return mode;
|
||||
}
|
||||
|
||||
static void virNetServerClientEventFree(void *opaque)
|
||||
{
|
||||
virNetServerClientPtr client = opaque;
|
||||
|
||||
virNetServerClientFree(client);
|
||||
}
|
||||
|
||||
/*
|
||||
* @server: a locked or unlocked server object
|
||||
* @client: a locked client object
|
||||
@ -182,15 +192,17 @@ static int virNetServerClientRegisterEvent(virNetServerClientPtr client)
|
||||
{
|
||||
int mode = virNetServerClientCalculateHandleMode(client);
|
||||
|
||||
client->refs++;
|
||||
if (!client->sock)
|
||||
return -1;
|
||||
|
||||
virObjectRef(client);
|
||||
VIR_DEBUG("Registering client event callback %d", mode);
|
||||
if (!client->sock ||
|
||||
virNetSocketAddIOCallback(client->sock,
|
||||
if (virNetSocketAddIOCallback(client->sock,
|
||||
mode,
|
||||
virNetServerClientDispatchEvent,
|
||||
client,
|
||||
virNetServerClientEventFree) < 0) {
|
||||
client->refs--;
|
||||
virObjectFreeCallback) < 0) {
|
||||
virObjectUnref(client);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -334,15 +346,17 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
|
||||
|
||||
VIR_DEBUG("sock=%p auth=%d tls=%p", sock, auth, tls);
|
||||
|
||||
if (VIR_ALLOC(client) < 0) {
|
||||
virReportOOMError();
|
||||
if (virNetServerClientInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(client = virObjectNew(virNetServerClientClass)))
|
||||
return NULL;
|
||||
|
||||
if (virMutexInit(&client->lock) < 0) {
|
||||
VIR_FREE(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (virMutexInit(&client->lock) < 0)
|
||||
goto error;
|
||||
|
||||
client->refs = 1;
|
||||
client->sock = sock;
|
||||
client->auth = auth;
|
||||
client->readonly = readonly;
|
||||
@ -365,28 +379,18 @@ virNetServerClientPtr virNetServerClientNew(virNetSocketPtr sock,
|
||||
client->nrequests = 1;
|
||||
|
||||
PROBE(RPC_SERVER_CLIENT_NEW,
|
||||
"client=%p refs=%d sock=%p",
|
||||
client, client->refs, client->sock);
|
||||
"client=%p sock=%p",
|
||||
client, client->sock);
|
||||
|
||||
return client;
|
||||
|
||||
error:
|
||||
/* XXX ref counting is better than this */
|
||||
client->sock = NULL; /* Caller owns 'sock' upon failure */
|
||||
virNetServerClientFree(client);
|
||||
virObjectUnref(client);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void virNetServerClientRef(virNetServerClientPtr client)
|
||||
{
|
||||
virNetServerClientLock(client);
|
||||
client->refs++;
|
||||
PROBE(RPC_SERVER_CLIENT_REF,
|
||||
"client=%p refs=%d",
|
||||
client, client->refs);
|
||||
virNetServerClientUnlock(client);
|
||||
}
|
||||
|
||||
|
||||
int virNetServerClientGetAuth(virNetServerClientPtr client)
|
||||
{
|
||||
@ -568,21 +572,9 @@ const char *virNetServerClientRemoteAddrString(virNetServerClientPtr client)
|
||||
}
|
||||
|
||||
|
||||
void virNetServerClientFree(virNetServerClientPtr client)
|
||||
void virNetServerClientDispose(void *obj)
|
||||
{
|
||||
if (!client)
|
||||
return;
|
||||
|
||||
virNetServerClientLock(client);
|
||||
PROBE(RPC_SERVER_CLIENT_FREE,
|
||||
"client=%p refs=%d",
|
||||
client, client->refs);
|
||||
|
||||
client->refs--;
|
||||
if (client->refs > 0) {
|
||||
virNetServerClientUnlock(client);
|
||||
return;
|
||||
}
|
||||
virNetServerClientPtr client = obj;
|
||||
|
||||
if (client->privateData &&
|
||||
client->privateDataFreeFunc)
|
||||
@ -599,7 +591,6 @@ void virNetServerClientFree(virNetServerClientPtr client)
|
||||
virObjectUnref(client->sock);
|
||||
virNetServerClientUnlock(client);
|
||||
virMutexDestroy(&client->lock);
|
||||
VIR_FREE(client);
|
||||
}
|
||||
|
||||
|
||||
@ -617,7 +608,7 @@ void virNetServerClientClose(virNetServerClientPtr client)
|
||||
virKeepAlivePtr ka;
|
||||
|
||||
virNetServerClientLock(client);
|
||||
VIR_DEBUG("client=%p refs=%d", client, client->refs);
|
||||
VIR_DEBUG("client=%p", client);
|
||||
if (!client->sock) {
|
||||
virNetServerClientUnlock(client);
|
||||
return;
|
||||
@ -627,20 +618,20 @@ void virNetServerClientClose(virNetServerClientPtr client)
|
||||
virKeepAliveStop(client->keepalive);
|
||||
ka = client->keepalive;
|
||||
client->keepalive = NULL;
|
||||
client->refs++;
|
||||
virObjectRef(client);
|
||||
virNetServerClientUnlock(client);
|
||||
virObjectUnref(ka);
|
||||
virNetServerClientLock(client);
|
||||
client->refs--;
|
||||
virObjectUnref(client);
|
||||
}
|
||||
|
||||
if (client->privateDataCloseFunc) {
|
||||
cf = client->privateDataCloseFunc;
|
||||
client->refs++;
|
||||
virObjectRef(client);
|
||||
virNetServerClientUnlock(client);
|
||||
(cf)(client);
|
||||
virNetServerClientLock(client);
|
||||
client->refs--;
|
||||
virObjectUnref(client);
|
||||
}
|
||||
|
||||
/* Do now, even though we don't close the socket
|
||||
@ -904,12 +895,12 @@ readmore:
|
||||
|
||||
/* Send off to for normal dispatch to workers */
|
||||
if (msg) {
|
||||
client->refs++;
|
||||
virObjectRef(client);
|
||||
if (!client->dispatchFunc ||
|
||||
client->dispatchFunc(client, msg, client->dispatchOpaque) < 0) {
|
||||
virNetMessageFree(msg);
|
||||
client->wantClose = true;
|
||||
client->refs--;
|
||||
virObjectUnref(client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -1168,11 +1159,6 @@ virNetServerClientKeepAliveSendCB(void *opaque,
|
||||
return virNetServerClientSendMessage(opaque, msg);
|
||||
}
|
||||
|
||||
static void
|
||||
virNetServerClientFreeCB(void *opaque)
|
||||
{
|
||||
virNetServerClientFree(opaque);
|
||||
}
|
||||
|
||||
int
|
||||
virNetServerClientInitKeepAlive(virNetServerClientPtr client,
|
||||
@ -1187,10 +1173,10 @@ virNetServerClientInitKeepAlive(virNetServerClientPtr client,
|
||||
if (!(ka = virKeepAliveNew(interval, count, client,
|
||||
virNetServerClientKeepAliveSendCB,
|
||||
virNetServerClientKeepAliveDeadCB,
|
||||
virNetServerClientFreeCB)))
|
||||
virObjectFreeCallback)))
|
||||
goto cleanup;
|
||||
/* keepalive object has a reference to client */
|
||||
client->refs++;
|
||||
virObjectRef(client);
|
||||
|
||||
client->keepalive = ka;
|
||||
ka = NULL;
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
# include "virnetsocket.h"
|
||||
# include "virnetmessage.h"
|
||||
# include "virobject.h"
|
||||
|
||||
typedef struct _virNetServerClient virNetServerClient;
|
||||
typedef virNetServerClient *virNetServerClientPtr;
|
||||
@ -73,8 +74,6 @@ const char *virNetServerClientGetIdentity(virNetServerClientPtr client);
|
||||
int virNetServerClientGetUNIXIdentity(virNetServerClientPtr client,
|
||||
uid_t *uid, gid_t *gid, pid_t *pid);
|
||||
|
||||
void virNetServerClientRef(virNetServerClientPtr client);
|
||||
|
||||
typedef void (*virNetServerClientFreeFunc)(void *data);
|
||||
|
||||
void virNetServerClientSetPrivateData(virNetServerClientPtr client,
|
||||
@ -114,7 +113,5 @@ int virNetServerClientSendMessage(virNetServerClientPtr client,
|
||||
|
||||
bool virNetServerClientNeedAuth(virNetServerClientPtr client);
|
||||
|
||||
void virNetServerClientFree(virNetServerClientPtr client);
|
||||
|
||||
|
||||
#endif /* __VIR_NET_SERVER_CLIENT_H__ */
|
||||
|
@ -30,11 +30,12 @@
|
||||
#include "virterror_internal.h"
|
||||
#include "logging.h"
|
||||
#include "virfile.h"
|
||||
#include "threads.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_RPC
|
||||
|
||||
struct _virNetServerProgram {
|
||||
int refs;
|
||||
virObject object;
|
||||
|
||||
unsigned program;
|
||||
unsigned version;
|
||||
@ -42,6 +43,23 @@ struct _virNetServerProgram {
|
||||
size_t nprocs;
|
||||
};
|
||||
|
||||
|
||||
static virClassPtr virNetServerProgramClass;
|
||||
static void virNetServerProgramDispose(void *obj);
|
||||
|
||||
static int virNetServerProgramOnceInit(void)
|
||||
{
|
||||
if (!(virNetServerProgramClass = virClassNew("virNetServerProgram",
|
||||
sizeof(virNetServerProgram),
|
||||
virNetServerProgramDispose)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virNetServerProgram)
|
||||
|
||||
|
||||
virNetServerProgramPtr virNetServerProgramNew(unsigned program,
|
||||
unsigned version,
|
||||
virNetServerProgramProcPtr procs,
|
||||
@ -49,18 +67,18 @@ virNetServerProgramPtr virNetServerProgramNew(unsigned program,
|
||||
{
|
||||
virNetServerProgramPtr prog;
|
||||
|
||||
if (VIR_ALLOC(prog) < 0) {
|
||||
virReportOOMError();
|
||||
if (virNetServerProgramInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(prog = virObjectNew(virNetServerProgramClass)))
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prog->refs = 1;
|
||||
prog->program = program;
|
||||
prog->version = version;
|
||||
prog->procs = procs;
|
||||
prog->nprocs = nprocs;
|
||||
|
||||
VIR_DEBUG("prog=%p refs=%d", prog, prog->refs);
|
||||
VIR_DEBUG("prog=%p", prog);
|
||||
|
||||
return prog;
|
||||
}
|
||||
@ -78,13 +96,6 @@ int virNetServerProgramGetVersion(virNetServerProgramPtr prog)
|
||||
}
|
||||
|
||||
|
||||
void virNetServerProgramRef(virNetServerProgramPtr prog)
|
||||
{
|
||||
prog->refs++;
|
||||
VIR_DEBUG("prog=%p refs=%d", prog, prog->refs);
|
||||
}
|
||||
|
||||
|
||||
int virNetServerProgramMatches(virNetServerProgramPtr prog,
|
||||
virNetMessagePtr msg)
|
||||
{
|
||||
@ -516,16 +527,6 @@ int virNetServerProgramSendStreamData(virNetServerProgramPtr prog,
|
||||
}
|
||||
|
||||
|
||||
void virNetServerProgramFree(virNetServerProgramPtr prog)
|
||||
void virNetServerProgramDispose(void *obj ATTRIBUTE_UNUSED)
|
||||
{
|
||||
if (!prog)
|
||||
return;
|
||||
|
||||
VIR_DEBUG("prog=%p refs=%d", prog, prog->refs);
|
||||
|
||||
prog->refs--;
|
||||
if (prog->refs > 0)
|
||||
return;
|
||||
|
||||
VIR_FREE(prog);
|
||||
}
|
||||
|
@ -26,6 +26,7 @@
|
||||
|
||||
# include "virnetmessage.h"
|
||||
# include "virnetserverclient.h"
|
||||
# include "virobject.h"
|
||||
|
||||
typedef struct _virNetServer virNetServer;
|
||||
typedef virNetServer *virNetServerPtr;
|
||||
@ -67,8 +68,6 @@ int virNetServerProgramGetVersion(virNetServerProgramPtr prog);
|
||||
unsigned int virNetServerProgramGetPriority(virNetServerProgramPtr prog,
|
||||
int procedure);
|
||||
|
||||
void virNetServerProgramRef(virNetServerProgramPtr prog);
|
||||
|
||||
int virNetServerProgramMatches(virNetServerProgramPtr prog,
|
||||
virNetMessagePtr msg);
|
||||
|
||||
@ -102,9 +101,4 @@ int virNetServerProgramSendStreamData(virNetServerProgramPtr prog,
|
||||
const char *data,
|
||||
size_t len);
|
||||
|
||||
void virNetServerProgramFree(virNetServerProgramPtr prog);
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __VIR_NET_SERVER_PROGRAM_H__ */
|
||||
|
@ -27,12 +27,12 @@
|
||||
|
||||
#include "memory.h"
|
||||
#include "virterror_internal.h"
|
||||
|
||||
#include "threads.h"
|
||||
|
||||
#define VIR_FROM_THIS VIR_FROM_RPC
|
||||
|
||||
struct _virNetServerService {
|
||||
int refs;
|
||||
virObject object;
|
||||
|
||||
size_t nsocks;
|
||||
virNetSocketPtr *socks;
|
||||
@ -48,6 +48,21 @@ struct _virNetServerService {
|
||||
};
|
||||
|
||||
|
||||
static virClassPtr virNetServerServiceClass;
|
||||
static void virNetServerServiceDispose(void *obj);
|
||||
|
||||
static int virNetServerServiceOnceInit(void)
|
||||
{
|
||||
if (!(virNetServerServiceClass = virClassNew("virNetServerService",
|
||||
sizeof(virNetServerService),
|
||||
virNetServerServiceDispose)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
VIR_ONCE_GLOBAL_INIT(virNetServerService)
|
||||
|
||||
|
||||
static void virNetServerServiceAccept(virNetSocketPtr sock,
|
||||
int events ATTRIBUTE_UNUSED,
|
||||
@ -76,7 +91,7 @@ static void virNetServerServiceAccept(virNetSocketPtr sock,
|
||||
if (svc->dispatchFunc(svc, client, svc->dispatchOpaque) < 0)
|
||||
virNetServerClientClose(client);
|
||||
|
||||
virNetServerClientFree(client);
|
||||
virObjectUnref(client);
|
||||
|
||||
cleanup:
|
||||
return;
|
||||
@ -84,21 +99,13 @@ cleanup:
|
||||
error:
|
||||
if (client) {
|
||||
virNetServerClientClose(client);
|
||||
virNetServerClientFree(client);
|
||||
virObjectUnref(client);
|
||||
} else {
|
||||
virObjectUnref(clientsock);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void virNetServerServiceEventFree(void *opaque)
|
||||
{
|
||||
virNetServerServicePtr svc = opaque;
|
||||
|
||||
virNetServerServiceFree(svc);
|
||||
}
|
||||
|
||||
|
||||
virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
||||
const char *service,
|
||||
int auth,
|
||||
@ -109,10 +116,12 @@ virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
||||
virNetServerServicePtr svc;
|
||||
size_t i;
|
||||
|
||||
if (VIR_ALLOC(svc) < 0)
|
||||
goto no_memory;
|
||||
if (virNetServerServiceInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
||||
return NULL;
|
||||
|
||||
svc->refs = 1;
|
||||
svc->auth = auth;
|
||||
svc->readonly = readonly;
|
||||
svc->nrequests_client_max = nrequests_client_max;
|
||||
@ -130,13 +139,13 @@ virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
||||
|
||||
/* IO callback is initially disabled, until we're ready
|
||||
* to deal with incoming clients */
|
||||
virNetServerServiceRef(svc);
|
||||
virObjectRef(svc);
|
||||
if (virNetSocketAddIOCallback(svc->socks[i],
|
||||
0,
|
||||
virNetServerServiceAccept,
|
||||
svc,
|
||||
virNetServerServiceEventFree) < 0) {
|
||||
virNetServerServiceFree(svc);
|
||||
virObjectFreeCallback) < 0) {
|
||||
virObjectUnref(svc);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -144,10 +153,8 @@ virNetServerServicePtr virNetServerServiceNewTCP(const char *nodename,
|
||||
|
||||
return svc;
|
||||
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
error:
|
||||
virNetServerServiceFree(svc);
|
||||
virObjectUnref(svc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -163,10 +170,12 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
|
||||
virNetServerServicePtr svc;
|
||||
int i;
|
||||
|
||||
if (VIR_ALLOC(svc) < 0)
|
||||
goto no_memory;
|
||||
if (virNetServerServiceInitialize() < 0)
|
||||
return NULL;
|
||||
|
||||
if (!(svc = virObjectNew(virNetServerServiceClass)))
|
||||
return NULL;
|
||||
|
||||
svc->refs = 1;
|
||||
svc->auth = auth;
|
||||
svc->readonly = readonly;
|
||||
svc->nrequests_client_max = nrequests_client_max;
|
||||
@ -189,13 +198,13 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
|
||||
|
||||
/* IO callback is initially disabled, until we're ready
|
||||
* to deal with incoming clients */
|
||||
virNetServerServiceRef(svc);
|
||||
virObjectRef(svc);
|
||||
if (virNetSocketAddIOCallback(svc->socks[i],
|
||||
0,
|
||||
virNetServerServiceAccept,
|
||||
svc,
|
||||
virNetServerServiceEventFree) < 0) {
|
||||
virNetServerServiceFree(svc);
|
||||
virObjectFreeCallback) < 0) {
|
||||
virObjectUnref(svc);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
@ -206,7 +215,7 @@ virNetServerServicePtr virNetServerServiceNewUNIX(const char *path,
|
||||
no_memory:
|
||||
virReportOOMError();
|
||||
error:
|
||||
virNetServerServiceFree(svc);
|
||||
virObjectUnref(svc);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -231,12 +240,6 @@ bool virNetServerServiceIsReadonly(virNetServerServicePtr svc)
|
||||
}
|
||||
|
||||
|
||||
void virNetServerServiceRef(virNetServerServicePtr svc)
|
||||
{
|
||||
svc->refs++;
|
||||
}
|
||||
|
||||
|
||||
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
||||
virNetServerServiceDispatchFunc func,
|
||||
void *opaque)
|
||||
@ -246,24 +249,16 @@ void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
||||
}
|
||||
|
||||
|
||||
void virNetServerServiceFree(virNetServerServicePtr svc)
|
||||
void virNetServerServiceDispose(void *obj)
|
||||
{
|
||||
virNetServerServicePtr svc = obj;
|
||||
int i;
|
||||
|
||||
if (!svc)
|
||||
return;
|
||||
|
||||
svc->refs--;
|
||||
if (svc->refs > 0)
|
||||
return;
|
||||
|
||||
for (i = 0 ; i < svc->nsocks ; i++)
|
||||
virObjectUnref(svc->socks[i]);
|
||||
VIR_FREE(svc->socks);
|
||||
|
||||
virObjectUnref(svc->tls);
|
||||
|
||||
VIR_FREE(svc);
|
||||
}
|
||||
|
||||
void virNetServerServiceToggle(virNetServerServicePtr svc,
|
||||
|
@ -25,6 +25,7 @@
|
||||
# define __VIR_NET_SERVER_SERVICE_H__
|
||||
|
||||
# include "virnetserverprogram.h"
|
||||
# include "virobject.h"
|
||||
|
||||
enum {
|
||||
VIR_NET_SERVER_SERVICE_AUTH_NONE = 0,
|
||||
@ -55,14 +56,10 @@ int virNetServerServiceGetPort(virNetServerServicePtr svc);
|
||||
int virNetServerServiceGetAuth(virNetServerServicePtr svc);
|
||||
bool virNetServerServiceIsReadonly(virNetServerServicePtr svc);
|
||||
|
||||
void virNetServerServiceRef(virNetServerServicePtr svc);
|
||||
|
||||
void virNetServerServiceSetDispatcher(virNetServerServicePtr svc,
|
||||
virNetServerServiceDispatchFunc func,
|
||||
void *opaque);
|
||||
|
||||
void virNetServerServiceFree(virNetServerServicePtr svc);
|
||||
|
||||
void virNetServerServiceToggle(virNetServerServicePtr svc,
|
||||
bool enabled);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user