From dad3b07814898c7eceaac65c6d5c31968b9236bb Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Tue, 1 Mar 2016 15:34:15 +0100 Subject: [PATCH] server: Store server name in server object At first I did not want to do this, but after trying to implement some newer feaures in the admin API I realized we need that to make our lives easier. On the other hand they are not saved redundantly and the virNetServer objects are still kept in a hash table. Signed-off-by: Martin Kletzander --- daemon/libvirtd.c | 6 ++++-- src/locking/lock_daemon.c | 3 ++- src/logging/log_daemon.c | 3 ++- src/lxc/lxc_controller.c | 3 ++- src/rpc/virnetdaemon.c | 1 + src/rpc/virnetserver.c | 20 ++++++++++++++++++-- src/rpc/virnetserver.h | 6 +++++- tests/virnetdaemontest.c | 8 +++++--- 8 files changed, 39 insertions(+), 11 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index d1b98c9c3d..beddec1bb8 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1382,7 +1382,8 @@ int main(int argc, char **argv) { goto cleanup; } - if (!(srv = virNetServerNew(config->min_workers, + if (!(srv = virNetServerNew("libvirtd", + config->min_workers, config->max_workers, config->prio_workers, config->max_clients, @@ -1456,7 +1457,8 @@ int main(int argc, char **argv) { goto cleanup; } - if (!(srvAdm = virNetServerNew(config->admin_min_workers, + if (!(srvAdm = virNetServerNew("admin", + config->admin_min_workers, config->admin_max_workers, 0, config->admin_max_clients, diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c index cd70aa94d7..c89b842f0f 100644 --- a/src/locking/lock_daemon.c +++ b/src/locking/lock_daemon.c @@ -160,7 +160,8 @@ virLockDaemonNew(virLockDaemonConfigPtr config, bool privileged) return NULL; } - if (!(srv = virNetServerNew(1, 1, 0, config->max_clients, + if (!(srv = virNetServerNew("virtlockd", + 1, 1, 0, config->max_clients, config->max_clients, -1, 0, NULL, virLockDaemonClientNew, diff --git a/src/logging/log_daemon.c b/src/logging/log_daemon.c index 07a03c2419..866e8a85f4 100644 --- a/src/logging/log_daemon.c +++ b/src/logging/log_daemon.c @@ -150,7 +150,8 @@ virLogDaemonNew(virLogDaemonConfigPtr config, bool privileged) return NULL; } - if (!(logd->srv = virNetServerNew(1, 1, 0, config->max_clients, + if (!(logd->srv = virNetServerNew("virtlogd", + 1, 1, 0, config->max_clients, config->max_clients, -1, 0, NULL, virLogDaemonClientNew, diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c index 76bef82e70..21cf71fa08 100644 --- a/src/lxc/lxc_controller.c +++ b/src/lxc/lxc_controller.c @@ -928,7 +928,8 @@ static int virLXCControllerSetupServer(virLXCControllerPtr ctrl) LXC_STATE_DIR, ctrl->name) < 0) return -1; - if (!(srv = virNetServerNew(0, 0, 0, 1, + if (!(srv = virNetServerNew("LXC", + 0, 0, 0, 1, 0, -1, 0, NULL, virLXCControllerClientPrivateNew, diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c index 298fbf4ab0..7ae06dd380 100644 --- a/src/rpc/virnetdaemon.c +++ b/src/rpc/virnetdaemon.c @@ -276,6 +276,7 @@ virNetDaemonAddServerPostExec(virNetDaemonPtr dmn, } srv = virNetServerNewPostExecRestart(object, + serverName, clientPrivNew, clientPrivNewPostExecRestart, clientPrivPreExecRestart, diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c index 547e52e409..cf48e50603 100644 --- a/src/rpc/virnetserver.c +++ b/src/rpc/virnetserver.c @@ -49,6 +49,8 @@ struct _virNetServerJob { struct _virNetServer { virObjectLockable parent; + char *name; + virThreadPoolPtr workers; char *mdnsGroupName; @@ -304,7 +306,8 @@ static int virNetServerDispatchNewClient(virNetServerServicePtr svc, } -virNetServerPtr virNetServerNew(size_t min_workers, +virNetServerPtr virNetServerNew(const char *name, + size_t min_workers, size_t max_workers, size_t priority_workers, size_t max_clients, @@ -332,6 +335,9 @@ virNetServerPtr virNetServerNew(size_t min_workers, srv))) goto error; + if (VIR_STRDUP(srv->name, name) < 0) + goto error; + srv->nclients_max = max_clients; srv->nclients_unauth_max = max_anonymous_clients; srv->keepaliveInterval = keepaliveInterval; @@ -359,6 +365,7 @@ virNetServerPtr virNetServerNew(size_t min_workers, virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, + const char *name, virNetServerClientPrivNew clientPrivNew, virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart, virNetServerClientPrivPreExecRestart clientPrivPreExecRestart, @@ -427,7 +434,8 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, goto error; } - if (!(srv = virNetServerNew(min_workers, max_workers, + if (!(srv = virNetServerNew(name, + min_workers, max_workers, priority_workers, max_clients, max_anonymous_clients, keepaliveInterval, keepaliveCount, @@ -734,6 +742,8 @@ void virNetServerDispose(void *obj) virNetServerPtr srv = obj; size_t i; + VIR_FREE(srv->name); + for (i = 0; i < srv->nservices; i++) virNetServerServiceToggle(srv->services[i], false); @@ -861,3 +871,9 @@ virNetServerStart(virNetServerPtr srv) return virNetServerMDNSStart(srv->mdns); } + +const char * +virNetServerGetName(virNetServerPtr srv) +{ + return srv->name; +} diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h index 89d8db9b9e..aa244401a2 100644 --- a/src/rpc/virnetserver.h +++ b/src/rpc/virnetserver.h @@ -34,7 +34,8 @@ # include "virjson.h" -virNetServerPtr virNetServerNew(size_t min_workers, +virNetServerPtr virNetServerNew(const char *name, + size_t min_workers, size_t max_workers, size_t priority_workers, size_t max_clients, @@ -48,6 +49,7 @@ virNetServerPtr virNetServerNew(size_t min_workers, void *clientPrivOpaque); virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object, + const char *name, virNetServerClientPrivNew clientPrivNew, virNetServerClientPrivNewPostExecRestart clientPrivNewPostExecRestart, virNetServerClientPrivPreExecRestart clientPrivPreExecRestart, @@ -85,4 +87,6 @@ void virNetServerUpdateServices(virNetServerPtr srv, bool enabled); int virNetServerStart(virNetServerPtr srv); +const char *virNetServerGetName(virNetServerPtr srv); + #endif /* __VIR_NET_SERVER_H__ */ diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c index 2f855fdde2..443a406b77 100644 --- a/tests/virnetdaemontest.c +++ b/tests/virnetdaemontest.c @@ -28,7 +28,7 @@ #if defined(HAVE_SOCKETPAIR) && defined(WITH_YAJL) static virNetServerPtr -testCreateServer(const char *host, int family) +testCreateServer(const char *server_name, const char *host, int family) { virNetServerPtr srv = NULL; virNetServerServicePtr svc1 = NULL, svc2 = NULL; @@ -49,7 +49,8 @@ testCreateServer(const char *host, int family) goto cleanup; } - if (!(srv = virNetServerNew(10, 50, 5, 100, 10, + if (!(srv = virNetServerNew(server_name, + 10, 50, 5, 100, 10, 120, 5, mdns_group, NULL, @@ -155,7 +156,8 @@ static char *testGenerateJSON(const char *server_name) if (!has_ipv4 && !has_ipv6) return NULL; - if (!(srv = testCreateServer(has_ipv4 ? "127.0.0.1" : "::1", + if (!(srv = testCreateServer(server_name, + has_ipv4 ? "127.0.0.1" : "::1", has_ipv4 ? AF_INET : AF_INET6))) goto cleanup; -- GitLab