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