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>
|
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
|
* 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);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
if ((vm = qemudFindVMByName(server, def->name))) {
|
if ((vm = qemudFindVMByName(server, def->name))) {
|
||||||
if (vm->id == -1) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
qemudFreeVMDef(vm->def);
|
qemudFreeVMDef(vm->def);
|
||||||
vm->def = def;
|
vm->def = def;
|
||||||
} else {
|
} else {
|
||||||
@ -1266,8 +1266,8 @@ struct qemud_vm *qemudLoadConfigXML(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newVM) {
|
if (newVM) {
|
||||||
vm->next = server->inactivevms;
|
vm->next = server->vms;
|
||||||
server->inactivevms = vm;
|
server->vms = vm;
|
||||||
server->ninactivevms++;
|
server->ninactivevms++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1573,7 +1573,7 @@ struct qemud_network *qemudLoadNetworkConfigXML(struct qemud_server *server,
|
|||||||
xmlFreeDoc(xml);
|
xmlFreeDoc(xml);
|
||||||
|
|
||||||
if ((network = qemudFindNetworkByName(server, def->name))) {
|
if ((network = qemudFindNetworkByName(server, def->name))) {
|
||||||
if (!network->active) {
|
if (!qemudIsActiveNetwork(network)) {
|
||||||
qemudFreeNetworkDef(network->def);
|
qemudFreeNetworkDef(network->def);
|
||||||
network->def = def;
|
network->def = def;
|
||||||
} else {
|
} else {
|
||||||
@ -1614,8 +1614,8 @@ struct qemud_network *qemudLoadNetworkConfigXML(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (newNetwork) {
|
if (newNetwork) {
|
||||||
network->next = server->inactivenetworks;
|
network->next = server->networks;
|
||||||
server->inactivenetworks = network;
|
server->networks = network;
|
||||||
server->ninactivenetworks++;
|
server->ninactivenetworks++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1780,7 +1780,7 @@ char *qemudGenerateXML(struct qemud_server *server, struct qemud_vm *vm, int liv
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->id >= 0 && live) {
|
if (qemudIsActiveVM(vm) && live) {
|
||||||
if (qemudBufferPrintf(&buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0)
|
if (qemudBufferPrintf(&buf, "<domain type='%s' id='%d'>\n", type, vm->id) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
} else {
|
} else {
|
||||||
@ -1948,7 +1948,7 @@ char *qemudGenerateXML(struct qemud_server *server, struct qemud_vm *vm, int liv
|
|||||||
|
|
||||||
if (def->vncPort &&
|
if (def->vncPort &&
|
||||||
qemudBufferPrintf(&buf, " port='%d'",
|
qemudBufferPrintf(&buf, " port='%d'",
|
||||||
vm->id >= 0 && live ? def->vncActivePort : def->vncPort) < 0)
|
qemudIsActiveVM(vm) && live ? def->vncActivePort : def->vncPort) < 0)
|
||||||
goto no_memory;
|
goto no_memory;
|
||||||
|
|
||||||
if (qemudBufferAdd(&buf, "/>\n") < 0)
|
if (qemudBufferAdd(&buf, "/>\n") < 0)
|
||||||
|
152
qemud/driver.c
152
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 *qemudFindVMByID(const struct qemud_server *server, int id) {
|
||||||
struct qemud_vm *vm = server->activevms;
|
struct qemud_vm *vm = server->vms;
|
||||||
|
|
||||||
while (vm) {
|
while (vm) {
|
||||||
if (vm->id == id)
|
if (qemudIsActiveVM(vm) && vm->id == id)
|
||||||
return vm;
|
return vm;
|
||||||
vm = vm->next;
|
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,
|
struct qemud_vm *qemudFindVMByUUID(const struct qemud_server *server,
|
||||||
const unsigned char *uuid) {
|
const unsigned char *uuid) {
|
||||||
struct qemud_vm *vm = server->activevms;
|
struct qemud_vm *vm = server->vms;
|
||||||
|
|
||||||
while (vm) {
|
while (vm) {
|
||||||
if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
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 = vm->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm = server->inactivevms;
|
|
||||||
while (vm) {
|
|
||||||
if (!memcmp(vm->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
|
||||||
return vm;
|
|
||||||
vm = vm->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
|
struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
struct qemud_vm *vm = server->activevms;
|
struct qemud_vm *vm = server->vms;
|
||||||
|
|
||||||
while (vm) {
|
while (vm) {
|
||||||
if (!strcmp(vm->def->name, name))
|
if (!strcmp(vm->def->name, name))
|
||||||
@ -263,13 +256,6 @@ struct qemud_vm *qemudFindVMByName(const struct qemud_server *server,
|
|||||||
vm = vm->next;
|
vm = vm->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
vm = server->inactivevms;
|
|
||||||
while (vm) {
|
|
||||||
if (!strcmp(vm->def->name, name))
|
|
||||||
return vm;
|
|
||||||
vm = vm->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,12 +264,14 @@ int qemudGetVersion(struct qemud_server *server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qemudListDomains(struct qemud_server *server, int *ids, int nids) {
|
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;
|
int got = 0;
|
||||||
while (vm && got < nids) {
|
while (vm && got < nids) {
|
||||||
ids[got] = vm->id;
|
if (qemudIsActiveVM(vm)) {
|
||||||
|
ids[got] = vm->id;
|
||||||
|
got++;
|
||||||
|
}
|
||||||
vm = vm->next;
|
vm = vm->next;
|
||||||
got++;
|
|
||||||
}
|
}
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
@ -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);
|
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vm->pid == -1) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||||
return -1;
|
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);
|
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vm->pid == -1) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||||
return -1;
|
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);
|
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vm->pid == -1) {
|
|
||||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (qemudShutdownVMDaemon(server, vm) < 0)
|
if (qemudShutdownVMDaemon(server, vm) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -378,14 +361,14 @@ int qemudDomainGetInfo(struct qemud_server *server, const unsigned char *uuid,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->pid == -1) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
*runstate = QEMUD_STATE_STOPPED;
|
*runstate = QEMUD_STATE_STOPPED;
|
||||||
} else {
|
} else {
|
||||||
/* XXX in future need to add PAUSED */
|
/* XXX in future need to add PAUSED */
|
||||||
*runstate = QEMUD_STATE_RUNNING;
|
*runstate = QEMUD_STATE_RUNNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->pid == -1) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
*cputime = 0;
|
*cputime = 0;
|
||||||
} else {
|
} else {
|
||||||
if (qemudGetProcessInfo(cputime, vm->pid) < 0) {
|
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);
|
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching id %d", id);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (vm->pid == -1) {
|
if (!qemudIsActiveVM(vm)) {
|
||||||
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
qemudReportError(server, VIR_ERR_OPERATION_FAILED, "domain is not running");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -444,13 +427,15 @@ int qemudDomainDumpXML(struct qemud_server *server, const unsigned char *uuid, c
|
|||||||
|
|
||||||
|
|
||||||
int qemudListDefinedDomains(struct qemud_server *server, char *const*names, int nnames) {
|
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;
|
int got = 0;
|
||||||
while (vm && got < nnames) {
|
while (vm && got < nnames) {
|
||||||
strncpy(names[got], vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
if (!qemudIsActiveVM(vm)) {
|
||||||
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
strncpy(names[got], vm->def->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
|
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
got++;
|
||||||
|
}
|
||||||
vm = vm->next;
|
vm = vm->next;
|
||||||
got++;
|
|
||||||
}
|
}
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
@ -462,30 +447,7 @@ int qemudNumDefinedDomains(struct qemud_server *server) {
|
|||||||
|
|
||||||
|
|
||||||
int qemudDomainStart(struct qemud_server *server, struct qemud_vm *vm) {
|
int qemudDomainStart(struct qemud_server *server, struct qemud_vm *vm) {
|
||||||
struct qemud_vm *prev = NULL, *curr = server->inactivevms;
|
return qemudStartVMDaemon(server, vm);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -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) {
|
int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid) {
|
||||||
struct qemud_vm *vm = qemudFindVMByUUID(server, 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) {
|
if (!vm) {
|
||||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
|
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no domain with matching uuid");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vm->pid != -1) {
|
if (qemudIsActiveVM(vm)) {
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "cannot delete active domain");
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR, "cannot delete active domain");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -517,7 +479,7 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid)
|
|||||||
if (prev) {
|
if (prev) {
|
||||||
prev->next = curr->next;
|
prev->next = curr->next;
|
||||||
} else {
|
} else {
|
||||||
server->inactivevms = curr->next;
|
server->vms = curr->next;
|
||||||
}
|
}
|
||||||
server->ninactivevms--;
|
server->ninactivevms--;
|
||||||
break;
|
break;
|
||||||
@ -534,7 +496,7 @@ int qemudDomainUndefine(struct qemud_server *server, const unsigned char *uuid)
|
|||||||
|
|
||||||
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
|
struct qemud_network *qemudFindNetworkByUUID(const struct qemud_server *server,
|
||||||
const unsigned char *uuid) {
|
const unsigned char *uuid) {
|
||||||
struct qemud_network *network = server->activenetworks;
|
struct qemud_network *network = server->networks;
|
||||||
|
|
||||||
while (network) {
|
while (network) {
|
||||||
if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
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 = network->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
network = server->inactivenetworks;
|
|
||||||
while (network) {
|
|
||||||
if (!memcmp(network->def->uuid, uuid, QEMUD_UUID_RAW_LEN))
|
|
||||||
return network;
|
|
||||||
network = network->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
|
struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
|
||||||
const char *name) {
|
const char *name) {
|
||||||
struct qemud_network *network = server->activenetworks;
|
struct qemud_network *network = server->networks;
|
||||||
|
|
||||||
while (network) {
|
while (network) {
|
||||||
if (!strcmp(network->def->name, name))
|
if (!strcmp(network->def->name, name))
|
||||||
@ -562,13 +517,6 @@ struct qemud_network *qemudFindNetworkByName(const struct qemud_server *server,
|
|||||||
network = network->next;
|
network = network->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
network = server->inactivenetworks;
|
|
||||||
while (network) {
|
|
||||||
if (!strcmp(network->def->name, name))
|
|
||||||
return network;
|
|
||||||
network = network->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -577,13 +525,15 @@ int qemudNumNetworks(struct qemud_server *server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qemudListNetworks(struct qemud_server *server, char *const*names, int nnames) {
|
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;
|
int got = 0;
|
||||||
while (network && got < nnames) {
|
while (network && got < nnames) {
|
||||||
strncpy(names[got], network->def->name, QEMUD_MAX_NAME_LEN-1);
|
if (qemudIsActiveNetwork(network)) {
|
||||||
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
strncpy(names[got], network->def->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
|
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
got++;
|
||||||
|
}
|
||||||
network = network->next;
|
network = network->next;
|
||||||
got++;
|
|
||||||
}
|
}
|
||||||
return got;
|
return got;
|
||||||
}
|
}
|
||||||
@ -593,13 +543,15 @@ int qemudNumDefinedNetworks(struct qemud_server *server) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qemudListDefinedNetworks(struct qemud_server *server, char *const*names, int nnames) {
|
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;
|
int got = 0;
|
||||||
while (network && got < nnames) {
|
while (network && got < nnames) {
|
||||||
strncpy(names[got], network->def->name, QEMUD_MAX_NAME_LEN-1);
|
if (!qemudIsActiveNetwork(network)) {
|
||||||
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
strncpy(names[got], network->def->name, QEMUD_MAX_NAME_LEN-1);
|
||||||
|
names[got][QEMUD_MAX_NAME_LEN-1] = '\0';
|
||||||
|
got++;
|
||||||
|
}
|
||||||
network = network->next;
|
network = network->next;
|
||||||
got++;
|
|
||||||
}
|
}
|
||||||
return got;
|
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) {
|
int qemudNetworkUndefine(struct qemud_server *server, const unsigned char *uuid) {
|
||||||
struct qemud_network *network = qemudFindNetworkByUUID(server, 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) {
|
if (!network) {
|
||||||
qemudReportError(server, VIR_ERR_INVALID_DOMAIN, "no network with matching uuid");
|
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) {
|
if (prev) {
|
||||||
prev->next = curr->next;
|
prev->next = curr->next;
|
||||||
} else {
|
} else {
|
||||||
server->inactivenetworks = curr->next;
|
server->networks = curr->next;
|
||||||
}
|
}
|
||||||
server->ninactivenetworks--;
|
server->ninactivenetworks--;
|
||||||
break;
|
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) {
|
int qemudNetworkStart(struct qemud_server *server, struct qemud_network *network) {
|
||||||
struct qemud_network *prev = NULL, *curr = server->inactivenetworks;
|
return qemudStartNetworkDaemon(server, network);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int qemudNetworkDestroy(struct qemud_server *server, const unsigned char *uuid) {
|
int qemudNetworkDestroy(struct qemud_server *server, const unsigned char *uuid) {
|
||||||
|
@ -280,14 +280,12 @@ struct qemud_server {
|
|||||||
int sigread;
|
int sigread;
|
||||||
int nvmfds;
|
int nvmfds;
|
||||||
int nactivevms;
|
int nactivevms;
|
||||||
struct qemud_vm *activevms;
|
|
||||||
int ninactivevms;
|
int ninactivevms;
|
||||||
struct qemud_vm *inactivevms;
|
struct qemud_vm *vms;
|
||||||
int nextvmid;
|
int nextvmid;
|
||||||
int nactivenetworks;
|
int nactivenetworks;
|
||||||
struct qemud_network *activenetworks;
|
|
||||||
int ninactivenetworks;
|
int ninactivenetworks;
|
||||||
struct qemud_network *inactivenetworks;
|
struct qemud_network *networks;
|
||||||
brControl *brctl;
|
brControl *brctl;
|
||||||
iptablesContext *iptables;
|
iptablesContext *iptables;
|
||||||
char configDir[PATH_MAX];
|
char configDir[PATH_MAX];
|
||||||
@ -317,6 +315,18 @@ void qemudLog(int priority, const char *fmt, ...);
|
|||||||
#define qemudDebug(fmt, ...) do { } while(0);
|
#define qemudDebug(fmt, ...) do { } while(0);
|
||||||
#endif
|
#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
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
142
qemud/qemud.c
142
qemud/qemud.c
@ -95,39 +95,43 @@ static int qemudDispatchSignal(struct qemud_server *server)
|
|||||||
qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
|
qemudLog(QEMUD_WARN, "Shutting down on signal %d", sigc);
|
||||||
|
|
||||||
/* shutdown active VMs */
|
/* shutdown active VMs */
|
||||||
vm = server->activevms;
|
vm = server->vms;
|
||||||
while (vm) {
|
while (vm) {
|
||||||
struct qemud_vm *next = vm->next;
|
struct qemud_vm *next = vm->next;
|
||||||
qemudShutdownVMDaemon(server, vm);
|
if (qemudIsActiveVM(vm))
|
||||||
|
qemudShutdownVMDaemon(server, vm);
|
||||||
vm = next;
|
vm = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free inactive VMs */
|
/* free inactive VMs */
|
||||||
vm = server->inactivevms;
|
vm = server->vms;
|
||||||
while (vm) {
|
while (vm) {
|
||||||
struct qemud_vm *next = vm->next;
|
struct qemud_vm *next = vm->next;
|
||||||
qemudFreeVM(vm);
|
qemudFreeVM(vm);
|
||||||
vm = next;
|
vm = next;
|
||||||
}
|
}
|
||||||
server->inactivevms = NULL;
|
server->vms = NULL;
|
||||||
|
server->nactivevms = 0;
|
||||||
server->ninactivevms = 0;
|
server->ninactivevms = 0;
|
||||||
|
|
||||||
/* shutdown active networks */
|
/* shutdown active networks */
|
||||||
network = server->activenetworks;
|
network = server->networks;
|
||||||
while (network) {
|
while (network) {
|
||||||
struct qemud_network *next = network->next;
|
struct qemud_network *next = network->next;
|
||||||
qemudShutdownNetworkDaemon(server, network);
|
if (qemudIsActiveNetwork(network))
|
||||||
|
qemudShutdownNetworkDaemon(server, network);
|
||||||
network = next;
|
network = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free inactive networks */
|
/* free inactive networks */
|
||||||
network = server->inactivenetworks;
|
network = server->networks;
|
||||||
while (network) {
|
while (network) {
|
||||||
struct qemud_network *next = network->next;
|
struct qemud_network *next = network->next;
|
||||||
qemudFreeNetwork(network);
|
qemudFreeNetwork(network);
|
||||||
network = next;
|
network = next;
|
||||||
}
|
}
|
||||||
server->inactivenetworks = NULL;
|
server->networks = NULL;
|
||||||
|
server->nactivenetworks = 0;
|
||||||
server->ninactivenetworks = 0;
|
server->ninactivenetworks = 0;
|
||||||
|
|
||||||
server->shutdown = 1;
|
server->shutdown = 1;
|
||||||
@ -576,6 +580,12 @@ int qemudStartVMDaemon(struct qemud_server *server,
|
|||||||
char **argv = NULL;
|
char **argv = NULL;
|
||||||
int i, ret = -1;
|
int i, ret = -1;
|
||||||
|
|
||||||
|
if (qemudIsActiveVM(vm)) {
|
||||||
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
|
"VM is already active");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (vm->def->vncPort < 0)
|
if (vm->def->vncPort < 0)
|
||||||
vm->def->vncActivePort = 5900 + server->nextvmid;
|
vm->def->vncActivePort = 5900 + server->nextvmid;
|
||||||
else
|
else
|
||||||
@ -586,6 +596,11 @@ int qemudStartVMDaemon(struct qemud_server *server,
|
|||||||
|
|
||||||
if (qemudExec(server, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
|
if (qemudExec(server, argv, &vm->pid, &vm->stdout, &vm->stderr) == 0) {
|
||||||
vm->id = server->nextvmid++;
|
vm->id = server->nextvmid++;
|
||||||
|
|
||||||
|
server->ninactivevms--;
|
||||||
|
server->nactivevms++;
|
||||||
|
server->nvmfds += 2;
|
||||||
|
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -805,50 +820,24 @@ qemudNetworkIfaceDisconnect(struct qemud_server *server,
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
|
int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
|
||||||
struct qemud_vm *prev = NULL, *curr = server->activevms;
|
|
||||||
struct qemud_vm_net_def *net;
|
struct qemud_vm_net_def *net;
|
||||||
|
|
||||||
|
if (!qemudIsActiveVM(vm))
|
||||||
|
return 0;
|
||||||
|
|
||||||
qemudLog(QEMUD_INFO, "Shutting down VM '%s'", vm->def->name);
|
qemudLog(QEMUD_INFO, "Shutting down VM '%s'", vm->def->name);
|
||||||
|
|
||||||
/* Already cleaned-up */
|
|
||||||
if (vm->pid < 0)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
kill(vm->pid, SIGTERM);
|
kill(vm->pid, SIGTERM);
|
||||||
|
|
||||||
/* Move it to inactive vm list */
|
qemudVMData(server, vm, vm->stdout);
|
||||||
while (curr) {
|
qemudVMData(server, vm, vm->stderr);
|
||||||
if (curr == vm) {
|
close(vm->stdout);
|
||||||
if (prev) {
|
close(vm->stderr);
|
||||||
prev->next = curr->next;
|
if (vm->monitor != -1)
|
||||||
} else {
|
close(vm->monitor);
|
||||||
server->activevms = curr->next;
|
vm->stdout = -1;
|
||||||
}
|
vm->stderr = -1;
|
||||||
server->nactivevms--;
|
vm->monitor = -1;
|
||||||
|
|
||||||
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;
|
|
||||||
server->nvmfds -= 2;
|
server->nvmfds -= 2;
|
||||||
|
|
||||||
net = vm->def->nets;
|
net = vm->def->nets;
|
||||||
@ -874,6 +863,9 @@ int qemudShutdownVMDaemon(struct qemud_server *server, struct qemud_vm *vm) {
|
|||||||
vm->newDef = NULL;
|
vm->newDef = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server->nactivevms--;
|
||||||
|
server->ninactivevms++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1121,7 +1113,7 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
|||||||
const char *name;
|
const char *name;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (network->active) {
|
if (qemudIsActiveNetwork(network)) {
|
||||||
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
qemudReportError(server, VIR_ERR_INTERNAL_ERROR,
|
||||||
"network is already active");
|
"network is already active");
|
||||||
return -1;
|
return -1;
|
||||||
@ -1185,6 +1177,9 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
|||||||
|
|
||||||
network->active = 1;
|
network->active = 1;
|
||||||
|
|
||||||
|
server->ninactivenetworks--;
|
||||||
|
server->nactivenetworks++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
err_delbr2:
|
err_delbr2:
|
||||||
@ -1209,12 +1204,11 @@ int qemudStartNetworkDaemon(struct qemud_server *server,
|
|||||||
|
|
||||||
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
||||||
struct qemud_network *network) {
|
struct qemud_network *network) {
|
||||||
struct qemud_network *prev, *curr;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name);
|
qemudLog(QEMUD_INFO, "Shutting down network '%s'", network->def->name);
|
||||||
|
|
||||||
if (!network->active)
|
if (!qemudIsActiveNetwork(network))
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (network->dnsmasqPid > 0)
|
if (network->dnsmasqPid > 0)
|
||||||
@ -1233,27 +1227,6 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
|||||||
network->bridge, strerror(err));
|
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 &&
|
if (network->dnsmasqPid > 0 &&
|
||||||
waitpid(network->dnsmasqPid, NULL, WNOHANG) != network->dnsmasqPid) {
|
waitpid(network->dnsmasqPid, NULL, WNOHANG) != network->dnsmasqPid) {
|
||||||
kill(network->dnsmasqPid, SIGKILL);
|
kill(network->dnsmasqPid, SIGKILL);
|
||||||
@ -1271,6 +1244,9 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
|||||||
network->newDef = NULL;
|
network->newDef = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server->nactivenetworks--;
|
||||||
|
server->ninactivenetworks++;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1278,7 +1254,7 @@ int qemudShutdownNetworkDaemon(struct qemud_server *server,
|
|||||||
static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
||||||
struct qemud_socket *sock = server->sockets;
|
struct qemud_socket *sock = server->sockets;
|
||||||
struct qemud_client *client = server->clients;
|
struct qemud_client *client = server->clients;
|
||||||
struct qemud_vm *vm = server->activevms;
|
struct qemud_vm *vm;
|
||||||
struct qemud_vm *tmp;
|
struct qemud_vm *tmp;
|
||||||
struct qemud_network *network, *prevnet;
|
struct qemud_network *network, *prevnet;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -1314,12 +1290,18 @@ static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
|||||||
fd++;
|
fd++;
|
||||||
client = next;
|
client = next;
|
||||||
}
|
}
|
||||||
|
vm = server->vms;
|
||||||
while (vm) {
|
while (vm) {
|
||||||
struct qemud_vm *next = vm->next;
|
struct qemud_vm *next = vm->next;
|
||||||
int failed = 0,
|
int failed = 0,
|
||||||
stdoutfd = vm->stdout,
|
stdoutfd = vm->stdout,
|
||||||
stderrfd = vm->stderr;
|
stderrfd = vm->stderr;
|
||||||
|
|
||||||
|
if (!qemudIsActiveVM(vm)) {
|
||||||
|
vm = next;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (stdoutfd != -1) {
|
if (stdoutfd != -1) {
|
||||||
if (fds[fd].revents) {
|
if (fds[fd].revents) {
|
||||||
if (fds[fd].revents == POLLIN) {
|
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
|
/* Cleanup any VMs which shutdown & dont have an associated
|
||||||
config file */
|
config file */
|
||||||
vm = server->inactivevms;
|
vm = server->vms;
|
||||||
tmp = NULL;
|
tmp = NULL;
|
||||||
while (vm) {
|
while (vm) {
|
||||||
if (!vm->configFile[0]) {
|
if (!qemudIsActiveVM(vm) && !vm->configFile[0]) {
|
||||||
struct qemud_vm *next = vm->next;
|
struct qemud_vm *next = vm->next;
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
tmp->next = next;
|
tmp->next = next;
|
||||||
} else {
|
} else {
|
||||||
server->inactivevms = next;
|
server->vms = next;
|
||||||
}
|
}
|
||||||
qemudFreeVM(vm);
|
qemudFreeVM(vm);
|
||||||
|
server->ninactivevms--;
|
||||||
vm = next;
|
vm = next;
|
||||||
} else {
|
} else {
|
||||||
tmp = vm;
|
tmp = vm;
|
||||||
@ -1372,17 +1355,18 @@ static int qemudDispatchPoll(struct qemud_server *server, struct pollfd *fds) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Cleanup any networks too */
|
/* Cleanup any networks too */
|
||||||
network = server->inactivenetworks;
|
network = server->networks;
|
||||||
prevnet = NULL;
|
prevnet = NULL;
|
||||||
while (network) {
|
while (network) {
|
||||||
if (!network->configFile[0]) {
|
if (!qemudIsActiveNetwork(network) && !network->configFile[0]) {
|
||||||
struct qemud_network *next = network->next;
|
struct qemud_network *next = network->next;
|
||||||
if (prevnet) {
|
if (prevnet) {
|
||||||
prevnet->next = next;
|
prevnet->next = next;
|
||||||
} else {
|
} else {
|
||||||
server->inactivenetworks = next;
|
server->networks = next;
|
||||||
}
|
}
|
||||||
qemudFreeNetwork(network);
|
qemudFreeNetwork(network);
|
||||||
|
server->ninactivenetworks--;
|
||||||
network = next;
|
network = next;
|
||||||
} else {
|
} else {
|
||||||
prevnet = network;
|
prevnet = network;
|
||||||
@ -1419,7 +1403,9 @@ static void qemudPreparePoll(struct qemud_server *server, struct pollfd *fds) {
|
|||||||
fds[fd].events = POLLIN | POLLERR | POLLHUP;
|
fds[fd].events = POLLIN | POLLERR | POLLHUP;
|
||||||
fd++;
|
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) {
|
if (vm->stdout != -1) {
|
||||||
fds[fd].fd = vm->stdout;
|
fds[fd].fd = vm->stdout;
|
||||||
fds[fd].events = POLLIN | POLLERR | POLLHUP;
|
fds[fd].events = POLLIN | POLLERR | POLLHUP;
|
||||||
|
Loading…
Reference in New Issue
Block a user