Since the daemon can manage and add (at fresh start) multiple servers,
we also should be able to add them from a JSON state file in case of a
daemon restart. This patch introduces virNetDaemonAddServersPostExec
method which harvests the data about servers from a JSON file supporting
both old format with a single server and a new one storing an array of
servers. The method makes use of the original virNetDaemonAddServerPostExec,
declaring the latter as static.
Patch also updates virnetdaemontest accordingly.
---
daemon/libvirtd.c | 8 +-
src/libvirt_remote.syms | 3 +-
src/locking/lock_daemon.c | 16 +--
src/rpc/virnetdaemon.c | 96 +++++++++++-----
src/rpc/virnetdaemon.h | 28 ++++-
src/rpc/virnetserver.c | 4 +
src/rpc/virnetserver.h | 1 +
.../input-data-admin-nomdns-names.json | 128 +++++++++++++++++++++
.../output-data-admin-nomdns-names.json | 128 +++++++++++++++++++++
.../output-data-admin-nomdns-nonames.json | 2 +
.../virnetdaemondata/output-data-anon-clients.json | 1 +
.../output-data-initial-nomdns.json | 1 +
tests/virnetdaemondata/output-data-initial.json | 1 +
tests/virnetdaemontest.c | 52 +++------
14 files changed, 390 insertions(+), 79 deletions(-)
create mode 100644 tests/virnetdaemondata/input-data-admin-nomdns-names.json
create mode 100644 tests/virnetdaemondata/output-data-admin-nomdns-names.json
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index de4953d..5920a96 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1159,6 +1159,8 @@ int main(int argc, char **argv) {
bool implicit_conf = false;
char *run_dir = NULL;
mode_t old_umask;
+ const char *server_names[] = { "libvirtd", "admin" };
+ virNetDaemonFallbackData fbData = { .fb_server_names = server_names };
struct option opts[] = {
{ "verbose", no_argument, &verbose, 'v'},
@@ -1390,7 +1392,7 @@ int main(int argc, char **argv) {
config->keepalive_interval,
config->keepalive_count,
config->mdns_adv ? config->mdns_name : NULL,
- "libvirtd",
+ server_names[0],
remoteClientInitHook,
NULL,
remoteClientFreeFunc,
@@ -1399,12 +1401,14 @@ int main(int argc, char **argv) {
goto cleanup;
}
+ virNetDaemonRegisterFallbackData(&fbData);
if (!(dmn = virNetDaemonNew()) ||
virNetDaemonAddServer(dmn, srv) < 0) {
ret = VIR_DAEMON_ERR_INIT;
goto cleanup;
}
+
/* Beyond this point, nothing should rely on using
* getuid/geteuid() == 0, for privilege level checks.
*/
@@ -1465,7 +1469,7 @@ int main(int argc, char **argv) {
config->admin_keepalive_interval,
config->admin_keepalive_count,
NULL,
- "admin",
+ server_names[1],
remoteAdmClientInitHook,
NULL,
remoteAdmClientFreeFunc,
diff --git a/src/libvirt_remote.syms b/src/libvirt_remote.syms
index 90a453c..4d31b69 100644
--- a/src/libvirt_remote.syms
+++ b/src/libvirt_remote.syms
@@ -59,7 +59,7 @@ virNetClientStreamSetError;
# rpc/virnetdaemon.h
virNetDaemonAddServer;
-virNetDaemonAddServerPostExec;
+virNetDaemonAddServersPostExec;
virNetDaemonAddShutdownInhibition;
virNetDaemonAddSignalHandler;
virNetDaemonAutoShutdown;
@@ -71,6 +71,7 @@ virNetDaemonNew;
virNetDaemonNewPostExecRestart;
virNetDaemonPreExecRestart;
virNetDaemonQuit;
+virNetDaemonRegisterFallbackData;
virNetDaemonRemoveShutdownInhibition;
virNetDaemonRun;
virNetDaemonUpdateServices;
diff --git a/src/locking/lock_daemon.c b/src/locking/lock_daemon.c
index 8c07fd6..94f9b11 100644
--- a/src/locking/lock_daemon.c
+++ b/src/locking/lock_daemon.c
@@ -182,7 +182,6 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool
privileged)
virLockDaemonPtr lockd;
virJSONValuePtr child;
virJSONValuePtr lockspaces;
- virNetServerPtr srv;
size_t i;
int n;
@@ -254,12 +253,12 @@ virLockDaemonNewPostExecRestart(virJSONValuePtr object, bool
privileged)
if (!(lockd->dmn = virNetDaemonNewPostExecRestart(child)))
goto error;
- if (!(srv = virNetDaemonAddServerPostExec(lockd->dmn,
- virLockDaemonClientNew,
- virLockDaemonClientNewPostExecRestart,
- virLockDaemonClientPreExecRestart,
- virLockDaemonClientFree,
- (void*)(intptr_t)(privileged ? 0x1 :
0x0))))
+ if (virNetDaemonAddServersPostExec(lockd->dmn,
+ virLockDaemonClientNew,
+ virLockDaemonClientNewPostExecRestart,
+ virLockDaemonClientPreExecRestart,
+ virLockDaemonClientFree,
+ (void*)(intptr_t)(privileged ? 0x1 : 0x0)) <
0)
goto error;
return lockd;
@@ -1148,6 +1147,8 @@ int main(int argc, char **argv) {
bool privileged = false;
virLockDaemonConfigPtr config = NULL;
int rv;
+ const char *server_names[] = { "virtlockd" };
+ virNetDaemonFallbackData fbData = { .fb_server_names = server_names };
struct option opts[] = {
{ "verbose", no_argument, &verbose, 'v'},
@@ -1314,6 +1315,7 @@ int main(int argc, char **argv) {
}
umask(old_umask);
+ virNetDaemonRegisterFallbackData(&fbData);
if ((rv = virLockDaemonPostExecRestart(state_file,
pid_file,
&pid_file_fd,
diff --git a/src/rpc/virnetdaemon.c b/src/rpc/virnetdaemon.c
index bdfcfb7..a3dde4e 100644
--- a/src/rpc/virnetdaemon.c
+++ b/src/rpc/virnetdaemon.c
@@ -82,8 +82,8 @@ struct _virNetDaemon {
int autoShutdownInhibitFd;
};
-
static virClassPtr virNetDaemonClass;
+static virNetDaemonFallbackDataPtr fbData;
static void
virNetDaemonDispose(void *obj)
@@ -205,38 +205,20 @@ virNetDaemonGetServer(virNetDaemonPtr dmn,
return srv;
}
-virNetServerPtr
+static int
virNetDaemonAddServerPostExec(virNetDaemonPtr dmn,
+ virJSONValuePtr object,
+ const char *fallbackName,
virNetServerClientPrivNew clientPrivNew,
virNetServerClientPrivNewPostExecRestart
clientPrivNewPostExecRestart,
virNetServerClientPrivPreExecRestart
clientPrivPreExecRestart,
virFreeCallback clientPrivFree,
void *clientPrivOpaque)
{
- virJSONValuePtr object = NULL;
virNetServerPtr srv = NULL;
- virObjectLock(dmn);
-
- if (!dmn->srvObject) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
- _("Cannot add more servers post-exec than "
- "there were pre-exec"));
- goto error;
- }
-
- if (virJSONValueIsArray(dmn->srvObject)) {
- object = virJSONValueArraySteal(dmn->srvObject, 0);
- if (virJSONValueArraySize(dmn->srvObject) == 0) {
- virJSONValueFree(dmn->srvObject);
- dmn->srvObject = NULL;
- }
- } else {
- object = dmn->srvObject;
- dmn->srvObject = NULL;
- }
-
srv = virNetServerNewPostExecRestart(object,
+ fallbackName,
clientPrivNew,
clientPrivNewPostExecRestart,
clientPrivPreExecRestart,
@@ -246,17 +228,67 @@ virNetDaemonAddServerPostExec(virNetDaemonPtr dmn,
if (!srv || VIR_APPEND_ELEMENT_COPY(dmn->servers, dmn->nservers, srv) < 0)
goto error;
- virJSONValueFree(object);
- virObjectUnlock(dmn);
- return srv;
+ return 0;
error:
- virObjectUnlock(dmn);
virObjectUnref(srv);
- virJSONValueFree(object);
- return NULL;
+ return -1;
}
+int
+virNetDaemonAddServersPostExec(virNetDaemonPtr dmn,
+ virNetServerClientPrivNew clientPrivNew,
+ virNetServerClientPrivNewPostExecRestart
clientPrivNewPostExecRestart,
+ virNetServerClientPrivPreExecRestart
clientPrivPreExecRestart,
+ virFreeCallback clientPrivFree,
+ void *clientPrivOpaque)
+{
+ int nservers;
+ int ret = -1;
+ size_t i;
+ bool new_version;
+
+ virObjectLock(dmn);
+
+ if (!dmn->srvObject) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("Cannot add more servers post-exec than "
+ "there were pre-exec"));
+ goto cleanup;
+ }
+
+ if (virJSONValueIsArray(dmn->srvObject)) {
+ nservers = virJSONValueArraySize(dmn->srvObject);
+ new_version = true;
+ } else {
+ nservers = 1;
+ new_version = false;
+ }
+
+ for (i = 0; i < nservers; i++) {
+ virJSONValuePtr object;
+ if (new_version)
+ object = virJSONValueArrayGet(dmn->srvObject, i);
+ else
+ object = dmn->srvObject;
+ if (virNetDaemonAddServerPostExec(dmn,
+ object,
+ fbData->fb_server_names[i],
+ clientPrivNew,
+ clientPrivNewPostExecRestart,
+ clientPrivPreExecRestart,
+ clientPrivFree,
+ clientPrivOpaque) < 0)
+ goto cleanup;
+ }
+
+ ret = 0;
+ cleanup:
+ virJSONValueFree(dmn->srvObject);
+ dmn->srvObject = NULL;
+ virObjectUnlock(dmn);
+ return ret;
+}
virNetDaemonPtr
virNetDaemonNewPostExecRestart(virJSONValuePtr object)
@@ -755,3 +787,9 @@ virNetDaemonHasClients(virNetDaemonPtr dmn)
return false;
}
+
+void
+virNetDaemonRegisterFallbackData(virNetDaemonFallbackDataPtr data)
+{
+ fbData = data;
+}
diff --git a/src/rpc/virnetdaemon.h b/src/rpc/virnetdaemon.h
index bb32053..8ad799a 100644
--- a/src/rpc/virnetdaemon.h
+++ b/src/rpc/virnetdaemon.h
@@ -35,16 +35,30 @@
# include "virnetserverservice.h"
# include "virnetserver.h"
+typedef struct _virNetDaemonFallbackData virNetDaemonFallbackData;
+typedef virNetDaemonFallbackData *virNetDaemonFallbackDataPtr;
+
+/* NOTE: Fallback data are necessary for virtlockd which reinitializes its state
+ * from a JSON after being restarted. New admin API requires a server to have
+ * a name which previously wasn't required and virtlockd had formatted its state
+ * without this information, so after an upgrade we need to give the daemon
+ * a hint about what the server names might be according to their formatted order
+ * in a JSON file.
+ */
+struct _virNetDaemonFallbackData {
+ const char **fb_server_names;
+};
+
virNetDaemonPtr virNetDaemonNew(void);
int virNetDaemonAddServer(virNetDaemonPtr dmn, virNetServerPtr);
-virNetServerPtr virNetDaemonAddServerPostExec(virNetDaemonPtr dmn,
- virNetServerClientPrivNew clientPrivNew,
- virNetServerClientPrivNewPostExecRestart
clientPrivNewPostExecRestart,
- virNetServerClientPrivPreExecRestart
clientPrivPreExecRestart,
- virFreeCallback clientPrivFree,
- void *clientPrivOpaque);
+int virNetDaemonAddServersPostExec(virNetDaemonPtr dmn,
+ virNetServerClientPrivNew clientPrivNew,
+ virNetServerClientPrivNewPostExecRestart
clientPrivNewPostExecRestart,
+ virNetServerClientPrivPreExecRestart
clientPrivPreExecRestart,
+ virFreeCallback clientPrivFree,
+ void *clientPrivOpaque);
virNetDaemonPtr virNetDaemonNewPostExecRestart(virJSONValuePtr object);
@@ -81,4 +95,6 @@ bool virNetDaemonHasClients(virNetDaemonPtr dmn);
virNetServerPtr virNetDaemonGetServer(virNetDaemonPtr dmn,
int subServerID);
+void virNetDaemonRegisterFallbackData(virNetDaemonFallbackDataPtr data);
+
#endif /* __VIR_NET_DAEMON_H__ */
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index ffc1b0d..c0a205f 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -367,6 +367,7 @@ virNetServerPtr virNetServerNew(size_t min_workers,
virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
+ const char *fallbackName,
virNetServerClientPrivNew clientPrivNew,
virNetServerClientPrivNewPostExecRestart
clientPrivNewPostExecRestart,
virNetServerClientPrivPreExecRestart
clientPrivPreExecRestart,
@@ -388,6 +389,9 @@ virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr
object,
const char *mdnsGroupName = NULL;
const char *serverName = NULL;
+ if (!(serverName = virJSONValueObjectGetString(object, "name")))
+ serverName = fallbackName;
+
if (virJSONValueObjectGetNumberUint(object, "min_workers",
&min_workers) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("Missing min_workers data in JSON document"));
diff --git a/src/rpc/virnetserver.h b/src/rpc/virnetserver.h
index fb04aa3..96137cc 100644
--- a/src/rpc/virnetserver.h
+++ b/src/rpc/virnetserver.h
@@ -49,6 +49,7 @@ virNetServerPtr virNetServerNew(size_t min_workers,
void *clientPrivOpaque);
virNetServerPtr virNetServerNewPostExecRestart(virJSONValuePtr object,
+ const char *fallbackName,
virNetServerClientPrivNew clientPrivNew,
virNetServerClientPrivNewPostExecRestart
clientPrivNewPostExecRestart,
virNetServerClientPrivPreExecRestart
clientPrivPreExecRestart,
diff --git a/tests/virnetdaemondata/input-data-admin-nomdns-names.json
b/tests/virnetdaemondata/input-data-admin-nomdns-names.json
new file mode 100644
index 0000000..c9d22e1
--- /dev/null
+++ b/tests/virnetdaemondata/input-data-admin-nomdns-names.json
@@ -0,0 +1,128 @@
+{
+ "servers": [
+ {
+ "name": "adminTestServer0",
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ },
+ {
+ "name": "adminTestServer1",
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "keepaliveRequired": true,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetdaemondata/output-data-admin-nomdns-names.json
b/tests/virnetdaemondata/output-data-admin-nomdns-names.json
new file mode 100644
index 0000000..40c66a7
--- /dev/null
+++ b/tests/virnetdaemondata/output-data-admin-nomdns-names.json
@@ -0,0 +1,128 @@
+{
+ "servers": [
+ {
+ "name": "adminTestServer0",
+ "min_workers": 10,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ },
+ {
+ "name": "adminTestServer1",
+ "min_workers": 2,
+ "max_workers": 50,
+ "priority_workers": 5,
+ "max_clients": 100,
+ "max_anonymous_clients": 100,
+ "keepaliveInterval": 120,
+ "keepaliveCount": 5,
+ "services": [
+ {
+ "auth": 0,
+ "readonly": true,
+ "nrequests_client_max": 2,
+ "socks": [
+ {
+ "fd": 100,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ },
+ {
+ "auth": 2,
+ "readonly": false,
+ "nrequests_client_max": 5,
+ "socks": [
+ {
+ "fd": 101,
+ "errfd": -1,
+ "pid": 0,
+ "isClient": false
+ }
+ ]
+ }
+ ],
+ "clients": [
+ {
+ "auth": 1,
+ "readonly": true,
+ "nrequests_max": 15,
+ "sock": {
+ "fd": 102,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ },
+ {
+ "auth": 2,
+ "readonly": true,
+ "nrequests_max": 66,
+ "sock": {
+ "fd": 103,
+ "errfd": -1,
+ "pid": -1,
+ "isClient": true
+ }
+ }
+ ]
+ }
+ ]
+}
diff --git a/tests/virnetdaemondata/output-data-admin-nomdns-nonames.json
b/tests/virnetdaemondata/output-data-admin-nomdns-nonames.json
index a814aeb..4b09311 100644
--- a/tests/virnetdaemondata/output-data-admin-nomdns-nonames.json
+++ b/tests/virnetdaemondata/output-data-admin-nomdns-nonames.json
@@ -1,6 +1,7 @@
{
"servers": [
{
+ "name": "testServer0",
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
@@ -62,6 +63,7 @@
]
},
{
+ "name": "testServer1",
"min_workers": 2,
"max_workers": 50,
"priority_workers": 5,
diff --git a/tests/virnetdaemondata/output-data-anon-clients.json
b/tests/virnetdaemondata/output-data-anon-clients.json
index 05fc0ae..043f072 100644
--- a/tests/virnetdaemondata/output-data-anon-clients.json
+++ b/tests/virnetdaemondata/output-data-anon-clients.json
@@ -1,6 +1,7 @@
{
"servers": [
{
+ "name": "testServer0",
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
diff --git a/tests/virnetdaemondata/output-data-initial-nomdns.json
b/tests/virnetdaemondata/output-data-initial-nomdns.json
index 400e47b..00bebc3 100644
--- a/tests/virnetdaemondata/output-data-initial-nomdns.json
+++ b/tests/virnetdaemondata/output-data-initial-nomdns.json
@@ -1,6 +1,7 @@
{
"servers": [
{
+ "name": "testServer0",
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
diff --git a/tests/virnetdaemondata/output-data-initial.json
b/tests/virnetdaemondata/output-data-initial.json
index e875cff..63a4872 100644
--- a/tests/virnetdaemondata/output-data-initial.json
+++ b/tests/virnetdaemondata/output-data-initial.json
@@ -1,6 +1,7 @@
{
"servers": [
{
+ "name": "testServer0",
"min_workers": 10,
"max_workers": 50,
"priority_workers": 5,
diff --git a/tests/virnetdaemontest.c b/tests/virnetdaemontest.c
index 89d3ca1..3569253 100644
--- a/tests/virnetdaemontest.c
+++ b/tests/virnetdaemontest.c
@@ -28,7 +28,7 @@
#ifdef HAVE_SOCKETPAIR
static virNetServerPtr
-testCreateServer(const char *host, int family)
+testCreateServer(const char *host, int family, const char *name)
{
virNetServerPtr srv = NULL;
virNetServerServicePtr svc1 = NULL, svc2 = NULL;
@@ -51,7 +51,7 @@ testCreateServer(const char *host, int family)
if (!(srv = virNetServerNew(10, 50, 5, 100, 10,
120, 5,
- mdns_group, "test-server",
+ mdns_group, name,
NULL,
NULL,
NULL,
@@ -133,7 +133,7 @@ testCreateServer(const char *host, int family)
goto cleanup;
}
-static char *testGenerateJSON(void)
+static char *testGenerateJSON(const char *server_name)
{
virNetDaemonPtr dmn = NULL;
virNetServerPtr srv = NULL;
@@ -155,7 +155,7 @@ static char *testGenerateJSON(void)
if (!(srv = testCreateServer(
has_ipv4 ? "127.0.0.1" : "::1",
- has_ipv4 ? AF_INET : AF_INET6)))
+ has_ipv4 ? AF_INET : AF_INET6, server_name)))
goto cleanup;
if (!(dmn = virNetDaemonNew()))
@@ -184,16 +184,13 @@ static char *testGenerateJSON(void)
struct testExecRestartData {
const char *jsonfile;
- int nservers;
- bool pass;
+ virNetDaemonFallbackDataPtr fbData;
};
static int testExecRestart(const void *opaque)
{
- size_t i;
int ret = -1;
virNetDaemonPtr dmn = NULL;
- virNetServerPtr srv = NULL;
const struct testExecRestartData *data = opaque;
char *infile = NULL, *outfile = NULL;
char *injsonstr = NULL, *outjsonstr = NULL;
@@ -238,13 +235,9 @@ static int testExecRestart(const void *opaque)
if (!(dmn = virNetDaemonNewPostExecRestart(injson)))
goto cleanup;
- for (i = 0; i < data->nservers; i++) {
- if (!(srv = virNetDaemonAddServerPostExec(dmn,
- NULL, NULL, NULL,
- NULL, NULL)))
- goto cleanup;
- srv = NULL;
- }
+ virNetDaemonRegisterFallbackData(data->fbData);
+ if (virNetDaemonAddServersPostExec(dmn, NULL, NULL, NULL, NULL, NULL) < 0)
+ goto cleanup;
if (!(outjson = virNetDaemonPreExecRestart(dmn)))
goto cleanup;
@@ -255,19 +248,11 @@ static int testExecRestart(const void *opaque)
if (virtTestCompareToFile(outjsonstr, outfile) < 0)
goto cleanup;
- if (!data->pass) {
- virReportError(VIR_ERR_INTERNAL_ERROR, "%s", "Test should've
failed");
- goto cleanup;
- }
-
ret = 0;
cleanup:
- if (ret < 0) {
- if (!data->pass)
- ret = 0;
- else
- virDispatchError(NULL);
- }
+ if (ret < 0)
+ virDispatchError(NULL);
+
VIR_FREE(infile);
VIR_FREE(outfile);
VIR_FREE(injsonstr);
@@ -287,6 +272,8 @@ static int
mymain(void)
{
int ret = 0;
+ const char *server_names[] = { "testServer0", "testServer1" };
+ virNetDaemonFallbackData fbData = { .fb_server_names = server_names };
if (virInitialize() < 0 ||
virEventRegisterDefaultImpl() < 0) {
@@ -300,7 +287,7 @@ mymain(void)
* numbers with 100, 101, 102, 103.
*/
if (getenv("VIR_GENERATE_JSON")) {
- char *json = testGenerateJSON();
+ char *json = testGenerateJSON(server_names[0]);
if (!json)
return EXIT_FAILURE;
@@ -309,26 +296,23 @@ mymain(void)
return ret;
}
-# define EXEC_RESTART_TEST_FULL(file, servers, pass) \
+# define EXEC_RESTART_TEST(file) \
do { \
struct testExecRestartData data = { \
- file, servers, pass \
+ file, &fbData \
}; \
if (virtTestRun("ExecRestart " file, \
testExecRestart, &data) < 0) \
ret = -1; \
} while (0)
-# define EXEC_RESTART_TEST(file) EXEC_RESTART_TEST_FULL(file, 1, true)
-
# ifdef WITH_AVAHI
EXEC_RESTART_TEST("initial");
# endif
EXEC_RESTART_TEST("initial-nomdns");
EXEC_RESTART_TEST("anon-clients");
-
- EXEC_RESTART_TEST_FULL("anon-clients", 2, false);
- EXEC_RESTART_TEST_FULL("admin-nomdns-nonames", 2, true);
+ EXEC_RESTART_TEST("admin-nomdns-nonames");
+ EXEC_RESTART_TEST("admin-nomdns-names");
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
--
2.4.3