mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-26 18:41:17 +00:00
Fri Feb 22 08:37:23 IST 2007 Mark McLoughlin <markmc@redhat.com>
* qemud/conf.c, qemud/driver.c, qemud/internal.h, qemud/qemud.c: Merge the ->activevms and ->inactivevms into a single ->vms list in order to make things easier to manage. Likewise for networks. Also add qemudIsActiveVM() and qemudIsActiveNetwork() inline functions.
This commit is contained in:
parent
6d6261f4e8
commit
6ecd4045aa
@ -1,3 +1,12 @@
|
||||
Fri Feb 22 08:37:23 IST 2007 Mark McLoughlin <markmc@redhat.com>
|
||||
|
||||
* qemud/conf.c, qemud/driver.c, qemud/internal.h,
|
||||
qemud/qemud.c: Merge the ->activevms and ->inactivevms
|
||||
into a single ->vms list in order to make things
|
||||
easier to manage. Likewise for networks. Also add
|
||||
qemudIsActiveVM() and qemudIsActiveNetwork() inline
|
||||
functions.
|
||||
|
||||
Thu Feb 22 14:06:24 EST 2007 Daniel P. Berrange <berrange@redhat.com>
|
||||
|
||||
* src/xm_internal.c, src/xend_internal.c: Re-arrange VM creation
|
||||
|
16
qemud/conf.c
16
qemud/conf.c
@ -1218,7 +1218,7 @@ struct qemud_vm *qemudLoadConfigXML(struct qemud_server *server,
|
||||
xmlFreeDoc(xml);
|
||||
|
||||
if ((vm = qemudFindVMByName(server, def->name))) {
|
||||
if (vm->id == -1) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
qemudFreeVMDef(vm->def);
|
||||
vm->def = def;
|
||||
} else {
|
||||
@ -1266,8 +1266,8 @@ struct qemud_vm *qemudLoadConfigXML(struct qemud_server *server,
|
||||
}
|
||||
|
||||
if (newVM) {
|
||||
vm->next = server->inactivevms;
|
||||
server->inactivevms = vm;
|
||||
vm->next = server->vms;
|
||||
server->vms = vm;
|
||||
server->ninactivevms++;
|
||||
}
|
||||
|
||||
@ -1573,7 +1573,7 @@ struct qemud_network *qemudLoadNetworkConfigXML(struct qemud_server *server,
|
||||
xmlFreeDoc(xml);
|
||||
|
||||
if ((network = qemudFindNetworkByName(server, def->name))) {
|
||||
if (!network->active) {
|
||||
if (!qemudIsActiveNetwork(network)) {
|
||||
qemudFreeNetworkDef(network->def);
|
||||
network->def = def;
|
||||
} else {
|
||||
@ -1614,8 +1614,8 @@ struct qemud_network *qemudLoadNetworkConfigXML(struct qemud_server *server,
|
||||
}
|
||||
|
||||
if (newNetwork) {
|
||||
network->next = server->inactivenetworks;
|
||||
server->inactivenetworks = network;
|
||||
network->next = server->networks;
|
||||
server->networks = network;
|
||||
server->ninactivenetworks++;
|
||||
}
|
||||
|
||||
@ -1780,7 +1780,7 @@ char *qemudGenerateXML(struct qemud_server *server, struct qemud_vm *vm, int liv
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (vm->id >= 0 && live) {
|
||||
if (qemudIsActiveVM(vm) && live) {
|
||||
if (qemudBufferPrintf(&buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0)
|
||||
goto no_memory;
|
||||
} else {
|
||||
@ -1948,7 +1948,7 @@ char *qemudGenerateXML(struct qemud_server *server, struct qemud_vm *vm, int liv
|
||||
|
||||
if (def->vncPort &&
|
||||
qemudBufferPrintf(&buf, " port='%d'",
|
||||
vm->id >= 0 && live ? def->vncActivePort : def->vncPort) < 0)
|
||||
qemudIsActiveVM(vm) && live ? def->vncActivePort : def->vncPort) < 0)
|
||||
goto no_memory;
|
||||
|
||||
if (qemudBufferAdd(&buf, "/>\n") < 0)
|
||||
|
138
qemud/driver.c
138
qemud/driver.c
@ -222,10 +222,10 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) {
|
||||
}
|
||||
|
||||
struct qemud_vm *qemudFindVMByID(const struct qemud_server *server, int id) {
|
||||
struct qemud_vm *vm = server->activevms;
|
||||
struct qemud_vm *vm = server->vms;
|
||||
|
||||
while (vm) {
|
||||
if (vm->id == id)
|
||||
if (qemudIsActiveVM(vm) && vm->id == id)
|
||||
return vm;
|
||||
vm = vm->next;
|
||||
}
|
||||
@ -235,7 +235,7 @@ struct qemud_vm *qemudFindVMByID(const struct qemud_server *server, int id) {
|
||||
|
||||
struct qemud_vm *qemudFindVMByUUID(const struct qemud_server *server,
|
||||
const unsigned char *uuid) {
|
||||
struct qemud_vm *vm = server->activevms;
|
||||
struct qemud_vm *vm = server->vms;
|
||||
|
||||
while (vm) {
|
||||
if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
||||
@ -243,19 +243,12 @@ struct qemud_vm *qemudFindVMByUUID(const struct qemud_server *server,
|
||||
vm = vm->next;
|
||||
}
|
||||
|
||||
vm = server->inactivevms;
|
||||
while (vm) {
|
||||
if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
||||
return vm;
|
||||
vm = vm->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
|
||||
const char *name) {
|
||||
struct qemud_vm *vm = server->activevms;
|
||||
struct qemud_vm *vm = server->vms;
|
||||
|
||||
while (vm) {
|
||||
if (!strcmp(vm->def->name, name))
|
||||
@ -263,13 +256,6 @@ struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
|
||||
vm = vm->next;
|
||||
}
|
||||
|
||||
vm = server->inactivevms;
|
||||
while (vm) {
|
||||
if (!strcmp(vm->def->name, name))
|
||||
return vm;
|
||||
vm = vm->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -278,13 +264,15 @@ int qemudGetVersion(struct qemud_server *server) {
|
||||
}
|
||||
|
||||
int qemudListDomains(struct qemud_server *server, int *ids, int nids) {
|
||||
struct qemud_vm *vm = server->activevms;
|
||||
struct qemud_vm *vm = server->vms;
|
||||
int got = 0;
|
||||
while (vm && got < nids) {
|
||||
if (qemudIsActiveVM(vm)) {
|
||||
ids[got] = vm->id;
|
||||
vm = vm->next;
|
||||
got++;
|
||||
}
|
||||
vm = vm->next;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
int qemudNumDomains(struct qemud_server *server) {
|
||||
@ -313,7 +301,7 @@ int qemudDomainSuspend(struct qemud_server *server, int id) {
|
||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||
return -1;
|
||||
}
|
||||
if (vm->pid == -1) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||
return -1;
|
||||
}
|
||||
@ -335,7 +323,7 @@ int qemudDomainResume(struct qemud_server *server, int id) {
|
||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||
return -1;
|
||||
}
|
||||
if (vm->pid == -1) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||
return -1;
|
||||
}
|
||||
@ -355,11 +343,6 @@ int qemudDomainDestroy(struct qemud_server *server, int id) {
|
||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||
return -1;
|
||||
}
|
||||
if (vm->pid == -1) {
|
||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (qemudShutdownVMDaemon(server, vm) < 0)
|
||||
return -1;
|
||||
return 0;
|
||||
@ -378,14 +361,14 @@ int qemudDomainGetInfo(struct qemud_server *server, const unsigned char *uuid,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm->pid == -1) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
*runstate = QEMUD_STATE_STOPPED;
|
||||
} else {
|
||||
/* XXX in future need to add PAUSED */
|
||||
*runstate = QEMUD_STATE_RUNNING;
|
||||
}
|
||||
|
||||
if (vm->pid == -1) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
*cputime = 0;
|
||||
} else {
|
||||
if (qemudGetProcessInfo(cputime, vm->pid) < 0) {
|
||||
@ -408,7 +391,7 @@ int qemudDomainSave(struct qemud_server *server, int id,
|
||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||
return -1;
|
||||
}
|
||||
if (vm->pid == -1) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||
return -1;
|
||||
}
|
||||
@ -444,14 +427,16 @@ int qemudDomainDumpXML(struct qemud_server *server, const unsigned char *uuid, c
|
||||
|
||||
|
||||
int qemudListDefinedDomains(struct qemud_server *server, char *const*names, int nnames) {
|
||||
struct qemud_vm *vm = server->inactivevms;
|
||||
struct qemud_vm *vm = server->vms;
|
||||
int got = 0;
|
||||
while (vm && got < nnames) {
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
strncpy(names[got], vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
||||
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||
vm = vm->next;
|
||||
got++;
|
||||
}
|
||||
vm = vm->next;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
@ -462,30 +447,7 @@ int qemudNumDefinedDomains(struct qemud_server *server) {
|
||||
|
||||
|
||||
int qemudDomainStart(struct qemud_server *server, struct qemud_vm *vm) {
|
||||
struct qemud_vm *prev = NULL, *curr = server->inactivevms;
|
||||
if (qemudStartVMDaemon(server, vm) < 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (curr) {
|
||||
if (curr == vm) {
|
||||
if (prev)
|
||||
prev->next = curr->next;
|
||||
else
|
||||
server->inactivevms = curr->next;
|
||||
server->ninactivevms--;
|
||||
break;
|
||||
}
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
vm->next = server->activevms;
|
||||
server->activevms = vm;
|
||||
server->nactivevms++;
|
||||
server->nvmfds += 2;
|
||||
|
||||
return 0;
|
||||
return qemudStartVMDaemon(server, vm);
|
||||
}
|
||||
|
||||
|
||||
@ -495,14 +457,14 @@ struct qemud_vm *qemudDomainDefine(struct qemud_server *server, const char *xml)
|
||||
|
||||
int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid) {
|
||||
struct qemud_vm *vm = qemudFindVMByUUID(server, uuid);
|
||||
struct qemud_vm *prev = NULL, *curr = server->inactivevms;
|
||||
struct qemud_vm *prev = NULL, *curr = server->vms;
|
||||
|
||||
if (!vm) {
|
||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm->pid != -1) {
|
||||
if (qemudIsActiveVM(vm)) {
|
||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "cannot delete active domain");
|
||||
return -1;
|
||||
}
|
||||
@ -517,7 +479,7 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid)
|
||||
if (prev) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
server->inactivevms = curr->next;
|
||||
server->vms = curr->next;
|
||||
}
|
||||
server->ninactivevms--;
|
||||
break;
|
||||
@ -534,7 +496,7 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid)
|
||||
|
||||
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
|
||||
const unsigned char *uuid) {
|
||||
struct qemud_network *network = server->activenetworks;
|
||||
struct qemud_network *network = server->networks;
|
||||
|
||||
while (network) {
|
||||
if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
||||
@ -542,19 +504,12 @@ struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
|
||||
network = network->next;
|
||||
}
|
||||
|
||||
network = server->inactivenetworks;
|
||||
while (network) {
|
||||
if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
||||
return network;
|
||||
network = network->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
|
||||
const char *name) {
|
||||
struct qemud_network *network = server->activenetworks;
|
||||
struct qemud_network *network = server->networks;
|
||||
|
||||
while (network) {
|
||||
if (!strcmp(network->def->name, name))
|
||||
@ -562,13 +517,6 @@ struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
|
||||
network = network->next;
|
||||
}
|
||||
|
||||
network = server->inactivenetworks;
|
||||
while (network) {
|
||||
if (!strcmp(network->def->name, name))
|
||||
return network;
|
||||
network = network->next;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@ -577,14 +525,16 @@ int qemudNumNetworks(struct qemud_server *server) {
|
||||
}
|
||||
|
||||
int qemudListNetworks(struct qemud_server *server, char *const*names, int nnames) {
|
||||
struct qemud_network *network = server->activenetworks;
|
||||
struct qemud_network *network = server->networks;
|
||||
int got = 0;
|
||||
while (network && got < nnames) {
|
||||
if (qemudIsActiveNetwork(network)) {
|
||||
strncpy(names[got], network->def->name, QEMUD_MAX_NAME_LEN-1);
|
||||
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||
network = network->next;
|
||||
got++;
|
||||
}
|
||||
network = network->next;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
@ -593,14 +543,16 @@ int qemudNumDefinedNetworks(struct qemud_server *server) {
|
||||
}
|
||||
|
||||
int qemudListDefinedNetworks(struct qemud_server *server, char *const*names, int nnames) {
|
||||
struct qemud_network *network = server->inactivenetworks;
|
||||
struct qemud_network *network = server->networks;
|
||||
int got = 0;
|
||||
while (network && got < nnames) {
|
||||
if (!qemudIsActiveNetwork(network)) {
|
||||
strncpy(names[got], network->def->name, QEMUD_MAX_NAME_LEN-1);
|
||||
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||
network = network->next;
|
||||
got++;
|
||||
}
|
||||
network = network->next;
|
||||
}
|
||||
return got;
|
||||
}
|
||||
|
||||
@ -625,7 +577,7 @@ struct qemud_network *qemudNetworkDefine(struct qemud_server *server, const char
|
||||
|
||||
int qemudNetworkUndefine(struct qemud_server *server, const unsigned char *uuid) {
|
||||
struct qemud_network *network = qemudFindNetworkByUUID(server, uuid);
|
||||
struct qemud_network *prev = NULL, *curr = server->inactivenetworks;
|
||||
struct qemud_network *prev = NULL, *curr = server->networks;
|
||||
|
||||
if (!network) {
|
||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no network with matching uuid");
|
||||
@ -642,7 +594,7 @@ int qemudNetworkUndefine(struct qemud_server *server, const unsigned char *uuid)
|
||||
if (prev) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
server->inactivenetworks = curr->next;
|
||||
server->networks = curr->next;
|
||||
}
|
||||
server->ninactivenetworks--;
|
||||
break;
|
||||
@ -658,29 +610,7 @@ int qemudNetworkUndefine(struct qemud_server *server, const unsigned char *uuid)
|
||||
}
|
||||
|
||||
int qemudNetworkStart(struct qemud_server *server, struct qemud_network *network) {
|
||||
struct qemud_network *prev = NULL, *curr = server->inactivenetworks;
|
||||
if (qemudStartNetworkDaemon(server, network) < 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (curr) {
|
||||
if (curr == network) {
|
||||
if (prev)
|
||||
prev->next = curr->next;
|
||||
else
|
||||
server->inactivenetworks = curr->next;
|
||||
server->ninactivenetworks--;
|
||||
break;
|
||||
}
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
network->next = server->activenetworks;
|
||||
server->activenetworks = network;
|
||||
server->nactivenetworks++;
|
||||
|
||||
return 0;
|
||||
return qemudStartNetworkDaemon(server, network);
|
||||
}
|
||||
|
||||
int qemudNetworkDestroy(struct qemud_server *server, const unsigned char *uuid) {
|
||||
|
@ -280,14 +280,12 @@ struct qemud_server {
|
||||
int sigread;
|
||||
int nvmfds;
|
||||
int nactivevms;
|
||||
struct qemud_vm *activevms;
|
||||
int ninactivevms;
|
||||
struct qemud_vm *inactivevms;
|
||||
struct qemud_vm *vms;
|
||||
int nextvmid;
|
||||
int nactivenetworks;
|
||||
struct qemud_network *activenetworks;
|
||||
int ninactivenetworks;
|
||||
struct qemud_network *inactivenetworks;
|
||||
struct qemud_network *networks;
|
||||
brControl *brctl;
|
||||
iptablesContext *iptables;
|
||||
char configDir[PATH_MAX];
|
||||
@ -317,6 +315,18 @@ void qemudLog(int priority, const char *fmt, ...);
|
||||
#define qemudDebug(fmt, ...) do { } while(0);
|
||||
#endif
|
||||
|
||||
static inline int
|
||||
qemudIsActiveVM(struct qemud_vm *vm)
|
||||
{
|
||||
return vm->id != -1;
|
||||
}
|
||||
|
||||
static inline int
|
||||
qemudIsActiveNetwork(struct qemud_network *network)
|
||||
{
|
||||
return network->active;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/*
|
||||
|
138
qemud/qemud.c
138
qemud/qemud.c
@ -95,39 +95,43 @@ static int qemudDispatchSignal(struct qemud_server *server)
|
||||
qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
|
||||
|
||||
/* shutdown active VMs */
|
||||
vm = server->activevms;
|
||||
vm = server->vms;
|
||||
while (vm) {
|
||||
struct qemud_vm *next = vm->next;
|
||||
if (qemudIsActiveVM(vm))
|
||||
qemudShutdownVMDaemon(server, vm);
|
||||
vm = next;
|
||||
}
|
||||
|
||||
/* free inactive VMs */
|
||||
vm = server->inactivevms;
|
||||
vm = server->vms;
|
||||
while (vm) {
|
||||
struct qemud_vm *next = vm->next;
|
||||
qemudFreeVM(vm);
|
||||
vm = next;
|
||||
}
|
||||
server->inactivevms = NULL;
|
||||
server->vms = NULL;
|
||||
server->nactivevms = 0;
|
||||
server->ninactivevms = 0;
|
||||
|
||||
/* shutdown active networks */
|
||||
network = server->activenetworks;
|
||||
network = server->networks;
|
||||
while (network) {
|
||||
struct qemud_network *next = network->next;
|
||||
if (qemudIsActiveNetwork(network))
|
||||
qemudShutdownNetworkDaemon(server, network);
|
||||
network = next;
|
||||
}
|
||||
|
||||
/* free inactive networks */
|
||||
network = server->inactivenetworks;
|
||||
network = server->networks;
|
||||
while (network) {
|
||||
struct qemud_network *next = network->next;
|
||||
qemudFreeNetwork(network);
|
||||
network = next;
|
||||
}
|
||||
server->inactivenetworks = NULL;
|
||||
server->networks = NULL;
|
||||
server->nactivenetworks = 0;
|
||||
server->ninactivenetworks = 0;
|
||||
|
||||
server->shutdown = 1;
|
||||
@ -576,6 +580,12 @@ int qemudStartVMDaemon(struct qemud_server *server,
|
||||
char **argv = NULL;
|
||||
int i, ret = -1;
|
||||
|
||||
if (qemudIsActiveVM(vm)) {
|
||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||
"VM is already active");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (vm->def->vncPort < 0)
|
||||
vm->def->vncActivePort = 5900 + server->nextvmid;
|
||||
else
|
||||
@ -586,6 +596,11 @@ int qemudStartVMDaemon(struct qemud_server *server,
|
||||
|
||||
if (qemudExec(server, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
|
||||
vm->id = server->nextvmid++;
|
||||
|
||||
server->ninactivevms--;
|
||||
server->nactivevms++;
|
||||
server->nvmfds += 2;
|
||||
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
@ -805,50 +820,24 @@ qemudNetworkIfaceDisconnect(struct qemud_server *server,
|
||||
}
|
||||
|
||||
int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
|
||||
struct qemud_vm *prev = NULL, *curr = server->activevms;
|
||||
struct qemud_vm_net_def *net;
|
||||
|
||||
if (!qemudIsActiveVM(vm))
|
||||
return 0;
|
||||
|
||||
qemudLog(QEMUD_INFO, "Shutting down VM '%s'", vm->def->name);
|
||||
|
||||
/* Already cleaned-up */
|
||||
if (vm->pid < 0)
|
||||
return 0;
|
||||
|
||||
kill(vm->pid, SIGTERM);
|
||||
|
||||
/* Move it to inactive vm list */
|
||||
while (curr) {
|
||||
if (curr == vm) {
|
||||
if (prev) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
server->activevms = curr->next;
|
||||
}
|
||||
server->nactivevms--;
|
||||
|
||||
curr->next = server->inactivevms;
|
||||
server->inactivevms = curr;
|
||||
server->ninactivevms++;
|
||||
break;
|
||||
}
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
if (!curr) {
|
||||
qemudDebug("Could not find VM to shutdown");
|
||||
return 0;
|
||||
}
|
||||
|
||||
qemudVMData(server, vm, curr->stdout);
|
||||
qemudVMData(server, vm, curr->stderr);
|
||||
close(curr->stdout);
|
||||
close(curr->stderr);
|
||||
if (curr->monitor != -1)
|
||||
close(curr->monitor);
|
||||
curr->stdout = -1;
|
||||
curr->stderr = -1;
|
||||
curr->monitor = -1;
|
||||
qemudVMData(server, vm, vm->stdout);
|
||||
qemudVMData(server, vm, vm->stderr);
|
||||
close(vm->stdout);
|
||||
close(vm->stderr);
|
||||
if (vm->monitor != -1)
|
||||
close(vm->monitor);
|
||||
vm->stdout = -1;
|
||||
vm->stderr = -1;
|
||||
vm->monitor = -1;
|
||||
server->nvmfds -= 2;
|
||||
|
||||
net = vm->def->nets;
|
||||
@ -874,6 +863,9 @@ int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
|
||||
vm->newDef = NULL;
|
||||
}
|
||||
|
||||
server->nactivevms--;
|
||||
server->ninactivevms++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1121,7 +1113,7 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
||||
const char *name;
|
||||
int err;
|
||||
|
||||
if (network->active) {
|
||||
if (qemudIsActiveNetwork(network)) {
|
||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||
"network is already active");
|
||||
return -1;
|
||||
@ -1185,6 +1177,9 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
||||
|
||||
network->active = 1;
|
||||
|
||||
server->ninactivenetworks--;
|
||||
server->nactivenetworks++;
|
||||
|
||||
return 0;
|
||||
|
||||
err_delbr2:
|
||||
@ -1209,12 +1204,11 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
||||
|
||||
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
||||
struct qemud_network *network) {
|
||||
struct qemud_network *prev, *curr;
|
||||
int err;
|
||||
|
||||
qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name);
|
||||
|
||||
if (!network->active)
|
||||
if (!qemudIsActiveNetwork(network))
|
||||
return 0;
|
||||
|
||||
if (network->dnsmasqPid > 0)
|
||||
@ -1233,27 +1227,6 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
||||
network->bridge, strerror(err));
|
||||
}
|
||||
|
||||
/* Move it to inactive networks list */
|
||||
prev = NULL;
|
||||
curr = server->activenetworks;
|
||||
while (curr) {
|
||||
if (curr == network) {
|
||||
if (prev) {
|
||||
prev->next = curr->next;
|
||||
} else {
|
||||
server->activenetworks = curr->next;
|
||||
}
|
||||
server->nactivenetworks--;
|
||||
|
||||
curr->next = server->inactivenetworks;
|
||||
server->inactivenetworks = curr;
|
||||
server->ninactivenetworks++;
|
||||
break;
|
||||
}
|
||||
prev = curr;
|
||||
curr = curr->next;
|
||||
}
|
||||
|
||||
if (network->dnsmasqPid > 0 &&
|
||||
waitpid(network->dnsmasqPid, NULL, WNOHANG) != network->dnsmasqPid) {
|
||||
kill(network->dnsmasqPid, SIGKILL);
|
||||
@ -1271,6 +1244,9 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
||||
network->newDef = NULL;
|
||||
}
|
||||
|
||||
server->nactivenetworks--;
|
||||
server->ninactivenetworks++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1278,7 +1254,7 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
||||
static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
||||
struct qemud_socket *sock = server->sockets;
|
||||
struct qemud_client *client = server->clients;
|
||||
struct qemud_vm *vm = server->activevms;
|
||||
struct qemud_vm *vm;
|
||||
struct qemud_vm *tmp;
|
||||
struct qemud_network *network, *prevnet;
|
||||
int ret = 0;
|
||||
@ -1314,12 +1290,18 @@ static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
||||
fd++;
|
||||
client = next;
|
||||
}
|
||||
vm = server->vms;
|
||||
while (vm) {
|
||||
struct qemud_vm *next = vm->next;
|
||||
int failed = 0,
|
||||
stdoutfd = vm->stdout,
|
||||
stderrfd = vm->stderr;
|
||||
|
||||
if (!qemudIsActiveVM(vm)) {
|
||||
vm = next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stdoutfd != -1) {
|
||||
if (fds[fd].revents) {
|
||||
if (fds[fd].revents == POLLIN) {
|
||||
@ -1353,17 +1335,18 @@ static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
||||
|
||||
/* Cleanup any VMs which shutdown & dont have an associated
|
||||
config file */
|
||||
vm = server->inactivevms;
|
||||
vm = server->vms;
|
||||
tmp = NULL;
|
||||
while (vm) {
|
||||
if (!vm->configFile[0]) {
|
||||
if (!qemudIsActiveVM(vm) && !vm->configFile[0]) {
|
||||
struct qemud_vm *next = vm->next;
|
||||
if (tmp) {
|
||||
tmp->next = next;
|
||||
} else {
|
||||
server->inactivevms = next;
|
||||
server->vms = next;
|
||||
}
|
||||
qemudFreeVM(vm);
|
||||
server->ninactivevms--;
|
||||
vm = next;
|
||||
} else {
|
||||
tmp = vm;
|
||||
@ -1372,17 +1355,18 @@ static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
||||
}
|
||||
|
||||
/* Cleanup any networks too */
|
||||
network = server->inactivenetworks;
|
||||
network = server->networks;
|
||||
prevnet = NULL;
|
||||
while (network) {
|
||||
if (!network->configFile[0]) {
|
||||
if (!qemudIsActiveNetwork(network) && !network->configFile[0]) {
|
||||
struct qemud_network *next = network->next;
|
||||
if (prevnet) {
|
||||
prevnet->next = next;
|
||||
} else {
|
||||
server->inactivenetworks = next;
|
||||
server->networks = next;
|
||||
}
|
||||
qemudFreeNetwork(network);
|
||||
server->ninactivenetworks--;
|
||||
network = next;
|
||||
} else {
|
||||
prevnet = network;
|
||||
@ -1419,7 +1403,9 @@ static void qemudPreparePoll(struct qemud_server *server, struct pollfd *fds) {
|
||||
fds[fd].events = POLLIN | POLLERR | POLLHUP;
|
||||
fd++;
|
||||
}
|
||||
for (vm = server->activevms ; vm ; vm = vm->next) {
|
||||
for (vm = server->vms ; vm ; vm = vm->next) {
|
||||
if (!qemudIsActiveVM(vm))
|
||||
continue;
|
||||
if (vm->stdout != -1) {
|
||||
fds[fd].fd = vm->stdout;
|
||||
fds[fd].events = POLLIN | POLLERR | POLLHUP;
|
||||
|
Loading…
Reference in New Issue
Block a user