mirror of
https://github.com/libvirt/libvirt.git
synced 2026-10-02 12:20:06 -05:00
rpc: refactor virNetServer setup for post-exec restarts
With the current code it is neccessary to call virNetDaemonNewPostExecRestart() and then for each server that needs restarting you are supposed to call virNetDaemonAddSeverPostExecRestart() This is fine if there's only ever one server, but as soon as you have two servers it is impossible to use this design. The code has no idea which servers were recorded in the JSON state doc, nor in which order the hash table serialized its keys. So this patch changes things so that we only call virNetDaemonNewPostExecRestart() passing in a callback, which is invoked once for each server found int he JSON state doc. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
1 parent
e72f3e5933
commit
8aca141081
6 files changed
+177
-112
No files matched your search
@@ -194,12 +194,32 @@ struct testExecRestartData {
|
||||
bool pass;
|
||||
};
|
||||
|
||||
static virNetServerPtr
|
||||
testNewServerPostExecRestart(virNetDaemonPtr dmn ATTRIBUTE_UNUSED,
|
||||
const char *name,
|
||||
virJSONValuePtr object,
|
||||
void *opaque)
|
||||
{
|
||||
struct testExecRestartData *data = opaque;
|
||||
size_t i;
|
||||
for (i = 0; i < data->nservers; i++) {
|
||||
if (STREQ(data->serverNames[i], name)) {
|
||||
return virNetServerNewPostExecRestart(object,
|
||||
name,
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "Unexpected server name '%s'", name);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
@@ -241,15 +261,20 @@ static int testExecRestart(const void *opaque)
|
||||
if (!(injson = virJSONValueFromString(injsonstr)))
|
||||
goto cleanup;
|
||||
|
||||
if (!(dmn = virNetDaemonNewPostExecRestart(injson)))
|
||||
if (!(dmn = virNetDaemonNewPostExecRestart(injson,
|
||||
data->nservers,
|
||||
data->serverNames,
|
||||
testNewServerPostExecRestart,
|
||||
(void *)data)))
|
||||
goto cleanup;
|
||||
|
||||
for (i = 0; i < data->nservers; i++) {
|
||||
if (!(srv = virNetDaemonAddServerPostExec(dmn, data->serverNames[i],
|
||||
NULL, NULL, NULL,
|
||||
NULL, NULL)))
|
||||
if (!virNetDaemonHasServer(dmn, data->serverNames[i])) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
"Server %s was not created",
|
||||
data->serverNames[i]);
|
||||
goto cleanup;
|
||||
srv = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (!(outjson = virNetDaemonPreExecRestart(dmn)))
|
||||
|
||||
Reference in new issue
Block a user