This patch removes the linked list in the virDomainObjPtr object, and adds a new virDomainObjList struct to track domains as an array. The QEMU, LXC, OpenVZ and Test drivers get updated to account for this API change. domain_conf.c | 99 ++++++++++++++++------------ domain_conf.h | 23 +++--- lxc_conf.h | 2 lxc_driver.c | 112 +++++++++++++------------------ openvz_conf.c | 24 ++---- openvz_conf.h | 2 openvz_driver.c | 54 +++++++-------- qemu_conf.h | 2 qemu_driver.c | 198 +++++++++++++++++++++++++------------------------------- test.c | 77 +++++++-------------- 10 files changed, 274 insertions(+), 319 deletions(-) Daniel diff -r 2bb12d98c26b src/domain_conf.c --- a/src/domain_conf.c Fri Oct 03 12:45:58 2008 +0100 +++ b/src/domain_conf.c Fri Oct 03 12:58:03 2008 +0100 @@ -166,44 +166,40 @@ } -virDomainObjPtr virDomainFindByID(const virDomainObjPtr doms, +virDomainObjPtr virDomainFindByID(const virDomainObjListPtr doms, int id) { - virDomainObjPtr dom = doms; - while (dom) { - if (virDomainIsActive(dom) && dom->def->id == id) - return dom; - dom = dom->next; - } + unsigned int i; + + for (i = 0 ; i < doms->count ; i++) + if (virDomainIsActive(doms->objs[i]) && + doms->objs[i]->def->id == id) + return doms->objs[i]; return NULL; } -virDomainObjPtr virDomainFindByUUID(const virDomainObjPtr doms, +virDomainObjPtr virDomainFindByUUID(const virDomainObjListPtr doms, const unsigned char *uuid) { - virDomainObjPtr dom = doms; + unsigned int i; - while (dom) { - if (!memcmp(dom->def->uuid, uuid, VIR_UUID_BUFLEN)) - return dom; - dom = dom->next; - } + for (i = 0 ; i < doms->count ; i++) + if (!memcmp(doms->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN)) + return doms->objs[i]; return NULL; } -virDomainObjPtr virDomainFindByName(const virDomainObjPtr doms, +virDomainObjPtr virDomainFindByName(const virDomainObjListPtr doms, const char *name) { - virDomainObjPtr dom = doms; + unsigned int i; - while (dom) { - if (STREQ(dom->def->name, name)) - return dom; - dom = dom->next; - } + for (i = 0 ; i < doms->count ; i++) + if (STREQ(doms->objs[i]->def->name, name)) + return doms->objs[i]; return NULL; } @@ -425,13 +421,24 @@ VIR_FREE(dom); } +void virDomainObjListFree(virDomainObjListPtr vms) +{ + unsigned int i; + + for (i = 0 ; i < vms->count ; i++) + virDomainObjFree(vms->objs[i]); + + VIR_FREE(vms->objs); + vms->count = 0; +} + virDomainObjPtr virDomainAssignDef(virConnectPtr conn, - virDomainObjPtr *doms, + virDomainObjListPtr doms, const virDomainDefPtr def) { virDomainObjPtr domain; - if ((domain = virDomainFindByName(*doms, def->name))) { + if ((domain = virDomainFindByName(doms, def->name))) { if (!virDomainIsActive(domain)) { virDomainDefFree(domain->def); domain->def = def; @@ -451,33 +458,41 @@ domain->state = VIR_DOMAIN_SHUTOFF; domain->def = def; - domain->next = *doms; - *doms = domain; + if (VIR_REALLOC_N(doms->objs, doms->count + 1) < 0) { + virDomainReportError(conn, VIR_ERR_NO_MEMORY, NULL); + VIR_FREE(domain); + return NULL; + } + + doms->objs[doms->count] = domain; + doms->count++; return domain; } -void virDomainRemoveInactive(virDomainObjPtr *doms, +void virDomainRemoveInactive(virDomainObjListPtr doms, virDomainObjPtr dom) { - virDomainObjPtr prev = NULL; - virDomainObjPtr curr = *doms; + unsigned int i; - while (curr && - curr != dom) { - prev = curr; - curr = curr->next; + for (i = 0 ; i < doms->count ; i++) { + if (doms->objs[i] == dom) { + virDomainObjFree(doms->objs[i]); + + if (i < (doms->count - 1)) + memmove(doms->objs + i, doms->objs + i + 1, + sizeof(*(doms->objs)) * (doms->count - (i + 1))); + + if (VIR_REALLOC_N(doms->objs, doms->count - 1) < 0) { + ; /* Failure to reduce memory allocation isn't fatal */ + } + doms->count--; + + break; + } } - if (curr) { - if (prev) - prev->next = curr->next; - else - *doms = curr->next; - } - - virDomainObjFree(dom); } #ifndef PROXY @@ -3266,7 +3281,7 @@ virDomainObjPtr virDomainLoadConfig(virConnectPtr conn, virCapsPtr caps, - virDomainObjPtr *doms, + virDomainObjListPtr doms, const char *configDir, const char *autostartDir, const char *name) @@ -3305,7 +3320,7 @@ int virDomainLoadAllConfigs(virConnectPtr conn, virCapsPtr caps, - virDomainObjPtr *doms, + virDomainObjListPtr doms, const char *configDir, const char *autostartDir) { diff -r 2bb12d98c26b src/domain_conf.h --- a/src/domain_conf.h Fri Oct 03 12:45:58 2008 +0100 +++ b/src/domain_conf.h Fri Oct 03 12:58:03 2008 +0100 @@ -460,10 +460,14 @@ virDomainDefPtr def; /* The current definition */ virDomainDefPtr newDef; /* New definition to activate at shutdown */ - - virDomainObjPtr next; }; +typedef struct _virDomainObjList virDomainObjList; +typedef virDomainObjList *virDomainObjListPtr; +struct _virDomainObjList { + unsigned int count; + virDomainObjPtr *objs; +}; static inline int virDomainIsActive(virDomainObjPtr dom) @@ -472,11 +476,11 @@ } -virDomainObjPtr virDomainFindByID(const virDomainObjPtr doms, +virDomainObjPtr virDomainFindByID(const virDomainObjListPtr doms, int id); -virDomainObjPtr virDomainFindByUUID(const virDomainObjPtr doms, +virDomainObjPtr virDomainFindByUUID(const virDomainObjListPtr doms, const unsigned char *uuid); -virDomainObjPtr virDomainFindByName(const virDomainObjPtr doms, +virDomainObjPtr virDomainFindByName(const virDomainObjListPtr doms, const char *name); @@ -491,11 +495,12 @@ void virDomainDeviceDefFree(virDomainDeviceDefPtr def); void virDomainDefFree(virDomainDefPtr vm); void virDomainObjFree(virDomainObjPtr vm); +void virDomainObjListFree(virDomainObjListPtr vms); virDomainObjPtr virDomainAssignDef(virConnectPtr conn, - virDomainObjPtr *doms, + virDomainObjListPtr doms, const virDomainDefPtr def); -void virDomainRemoveInactive(virDomainObjPtr *doms, +void virDomainRemoveInactive(virDomainObjListPtr doms, virDomainObjPtr dom); #ifndef PROXY @@ -535,14 +540,14 @@ virDomainObjPtr virDomainLoadConfig(virConnectPtr conn, virCapsPtr caps, - virDomainObjPtr *doms, + virDomainObjListPtr doms, const char *configDir, const char *autostartDir, const char *name); int virDomainLoadAllConfigs(virConnectPtr conn, virCapsPtr caps, - virDomainObjPtr *doms, + virDomainObjListPtr doms, const char *configDir, const char *autostartDir); diff -r 2bb12d98c26b src/lxc_conf.h --- a/src/lxc_conf.h Fri Oct 03 12:45:58 2008 +0100 +++ b/src/lxc_conf.h Fri Oct 03 12:58:03 2008 +0100 @@ -38,7 +38,7 @@ struct __lxc_driver { virCapsPtr caps; - virDomainObjPtr domains; + virDomainObjList domains; char *configDir; char *autostartDir; char *stateDir; diff -r 2bb12d98c26b src/lxc_driver.c --- a/src/lxc_driver.c Fri Oct 03 12:45:58 2008 +0100 +++ b/src/lxc_driver.c Fri Oct 03 12:58:03 2008 +0100 @@ -107,7 +107,7 @@ int id) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, id); virDomainPtr dom; if (!vm) { @@ -127,7 +127,7 @@ const unsigned char *uuid) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid); virDomainPtr dom; if (!vm) { @@ -147,7 +147,7 @@ const char *name) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - virDomainObjPtr vm = virDomainFindByName(driver->domains, name); + virDomainObjPtr vm = virDomainFindByName(&driver->domains, name); virDomainPtr dom; if (!vm) { @@ -165,44 +165,40 @@ static int lxcListDomains(virConnectPtr conn, int *ids, int nids) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - virDomainObjPtr vm = driver->domains; - int got = 0; - while (vm && got < nids) { - if (virDomainIsActive(vm)) { - ids[got] = vm->def->id; - got++; - } - vm = vm->next; - } + int got = 0, i; + + for (i = 0 ; i < driver->domains.count && got < nids ; i++) + if (virDomainIsActive(driver->domains.objs[i])) + ids[got++] = driver->domains.objs[i]->def->id; + return got; } static int lxcNumDomains(virConnectPtr conn) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - int n = 0; - virDomainObjPtr dom = driver->domains; - while (dom) { - if (virDomainIsActive(dom)) + int n = 0, i; + + for (i = 0 ; i < driver->domains.count ; i++) + if (virDomainIsActive(driver->domains.objs[i])) n++; - dom = dom->next; - } + return n; } static int lxcListDefinedDomains(virConnectPtr conn, char **const names, int nnames) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - virDomainObjPtr vm = driver->domains; int got = 0, i; - while (vm && got < nnames) { - if (!virDomainIsActive(vm)) { - if (!(names[got] = strdup(vm->def->name))) { - lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL); + + for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { + if (!virDomainIsActive(driver->domains.objs[i])) { + if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { + lxcError(conn, NULL, VIR_ERR_NO_MEMORY, + "%s", _("failed to allocate space for VM name string")); goto cleanup; } - got++; } - vm = vm->next; } + return got; cleanup: @@ -214,13 +210,12 @@ static int lxcNumDefinedDomains(virConnectPtr conn) { lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; - int n = 0; - virDomainObjPtr dom = driver->domains; - while (dom) { - if (!virDomainIsActive(dom)) + int n = 0, i; + + for (i = 0 ; i < driver->domains.count ; i++) + if (!virDomainIsActive(driver->domains.objs[i])) n++; - dom = dom->next; - } + return n; } @@ -267,7 +262,7 @@ static int lxcDomainUndefine(virDomainPtr dom) { lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -302,7 +297,7 @@ virDomainInfoPtr info) { lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -328,7 +323,7 @@ static char *lxcGetOSType(virDomainPtr dom) { lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -343,7 +338,7 @@ int flags) { lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -590,12 +585,14 @@ void *data) { lxc_driver_t *driver = data; - virDomainObjPtr vm = driver->domains; + virDomainObjPtr vm = NULL; + unsigned int i; - while (vm) { - if (vm->monitor == fd) + for (i = 0 ; i < driver->domains.count ; i++) { + if (driver->domains.objs[i]->monitor == fd) { + vm = driver->domains.objs[i]; break; - vm = vm->next; + } } if (!vm) { virEventRemoveHandle(fd); @@ -852,7 +849,7 @@ int rc = -1; virConnectPtr conn = dom->conn; lxc_driver_t *driver = (lxc_driver_t *)(conn->privateData); - virDomainObjPtr vm = virDomainFindByName(driver->domains, dom->name); + virDomainObjPtr vm = virDomainFindByName(&driver->domains, dom->name); if (!vm) { lxcError(conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -932,7 +929,7 @@ static int lxcDomainShutdown(virDomainPtr dom) { lxc_driver_t *driver = (lxc_driver_t*)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); if (!vm) { lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -955,7 +952,7 @@ static int lxcDomainDestroy(virDomainPtr dom) { lxc_driver_t *driver = (lxc_driver_t*)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); if (!vm) { lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, @@ -984,7 +981,7 @@ static int lxcStartup(void) { uid_t uid = getuid(); - virDomainObjPtr vm; + unsigned int i; /* Check that the user is root */ if (0 != uid) { @@ -1021,21 +1018,18 @@ return -1; } - vm = lxc_driver->domains; - while (vm) { + for (i = 0 ; i < lxc_driver->domains.count ; i++) { + virDomainObjPtr vm = lxc_driver->domains.objs[i]; char *config = NULL; virDomainDefPtr tmp; int rc; - if ((vm->monitor = lxcMonitorClient(NULL, lxc_driver, vm)) < 0) { - vm = vm->next; + if ((vm->monitor = lxcMonitorClient(NULL, lxc_driver, vm)) < 0) continue; - } /* Read pid from controller */ if ((rc = virFileReadPid(lxc_driver->stateDir, vm->def->name, &vm->pid)) != 0) { close(vm->monitor); vm->monitor = -1; - vm = vm->next; continue; } @@ -1060,8 +1054,6 @@ close(vm->monitor); vm->monitor = -1; } - - vm = vm->next; } return 0; @@ -1078,15 +1070,10 @@ static int lxcShutdown(void) { - virDomainObjPtr vm; if (lxc_driver == NULL) return(-1); - vm = lxc_driver->domains; - while (vm) { - virDomainObjPtr next = vm->next; - virDomainObjFree(vm); - vm = next; - } + + virDomainObjListFree(&lxc_driver->domains); lxcFreeDriver(lxc_driver); lxc_driver = NULL; @@ -1102,17 +1089,14 @@ */ static int lxcActive(void) { - virDomainObjPtr dom; + unsigned int i; if (lxc_driver == NULL) return(0); - dom = lxc_driver->domains; - while (dom) { - if (virDomainIsActive(dom)) + for (i = 0 ; i < lxc_driver->domains.count ; i++) + if (virDomainIsActive(lxc_driver->domains.objs[i])) return 1; - dom = dom->next; - } /* Otherwise we're happy to deal with a shutdown */ return 0; diff -r 2bb12d98c26b src/openvz_conf.c --- a/src/openvz_conf.c Fri Oct 03 12:45:58 2008 +0100 +++ b/src/openvz_conf.c Fri Oct 03 12:58:03 2008 +0100 @@ -295,18 +295,10 @@ void openvzFreeDriver(struct openvz_driver *driver) { - virDomainObjPtr dom; - if (!driver) return; - dom = driver->domains; - while (dom) { - virDomainObjPtr tmp = dom->next; - virDomainObjFree(dom); - dom = tmp; - } - + virDomainObjListFree(&driver->domains); virCapabilitiesFree(driver->caps); } @@ -317,7 +309,7 @@ int veid, ret; char status[16]; char uuidstr[VIR_UUID_STRING_BUFLEN]; - virDomainObjPtr dom = NULL, prev = NULL; + virDomainObjPtr dom = NULL; char temp[50]; if (openvzAssignUUIDs() < 0) @@ -385,12 +377,12 @@ dom->def->nets = openvzReadNetworkConf(NULL, veid); - if (prev) { - prev->next = dom; - } else { - driver->domains = dom; - } - prev = dom; + if (VIR_REALLOC_N(driver->domains.objs, + driver->domains.count + 1) < 0) + goto no_memory; + + driver->domains.objs[driver->domains.count++] = dom; + dom = NULL; } fclose(fp); diff -r 2bb12d98c26b src/openvz_conf.h --- a/src/openvz_conf.h Fri Oct 03 12:45:58 2008 +0100 +++ b/src/openvz_conf.h Fri Oct 03 12:58:03 2008 +0100 @@ -47,7 +47,7 @@ struct openvz_driver { virCapsPtr caps; - virDomainObjPtr domains; + virDomainObjList domains; }; void openvzError (virConnectPtr conn, virErrorNumber code, const char *fmt, ...) diff -r 2bb12d98c26b src/openvz_driver.c --- a/src/openvz_driver.c Fri Oct 03 12:45:58 2008 +0100 +++ b/src/openvz_driver.c Fri Oct 03 12:58:03 2008 +0100 @@ -157,7 +157,7 @@ virDomainObjPtr vm; virDomainPtr dom; - vm = virDomainFindByID(driver->domains, id); + vm = virDomainFindByID(&driver->domains, id); if (!vm) { openvzError(conn, VIR_ERR_NO_DOMAIN, NULL); @@ -175,7 +175,7 @@ static char *openvzGetOSType(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); char *ret; if (!vm) { @@ -193,7 +193,7 @@ static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { struct openvz_driver *driver = (struct openvz_driver *)conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid); virDomainPtr dom; if (!vm) { @@ -212,7 +212,7 @@ static virDomainPtr openvzDomainLookupByName(virConnectPtr conn, const char *name) { struct openvz_driver *driver = (struct openvz_driver *)conn->privateData; - virDomainObjPtr vm = virDomainFindByName(driver->domains, name); + virDomainObjPtr vm = virDomainFindByName(&driver->domains, name); virDomainPtr dom; if (!vm) { @@ -231,7 +231,7 @@ static int openvzDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) { struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, @@ -260,7 +260,7 @@ static char *openvzDomainDumpXML(virDomainPtr dom, int flags) { struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, @@ -275,7 +275,7 @@ static int openvzDomainShutdown(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); const char *prog[] = {VZCTL, "--quiet", "stop", vm ? vm->def->name : NULL, NULL}; if (!vm) { @@ -302,7 +302,7 @@ static int openvzDomainReboot(virDomainPtr dom, unsigned int flags ATTRIBUTE_UNUSED) { struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); const char *prog[] = {VZCTL, "--quiet", "restart", vm ? vm->def->name : NULL, NULL}; if (!vm) { @@ -434,7 +434,7 @@ return NULL; } - vm = virDomainFindByName(driver->domains, vmdef->name); + vm = virDomainFindByName(&driver->domains, vmdef->name); if (vm) { openvzError(conn, VIR_ERR_OPERATION_FAILED, _("Already an OPENVZ VM active with the id '%s'"), @@ -511,7 +511,7 @@ return NULL; } - vm = virDomainFindByName(driver->domains, vmdef->name); + vm = virDomainFindByName(&driver->domains, vmdef->name); if (vm) { openvzError(conn, VIR_ERR_OPERATION_FAILED, _("Already an OPENVZ VM defined with the id '%s'"), @@ -581,7 +581,7 @@ openvzDomainCreate(virDomainPtr dom) { struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByName(driver->domains, dom->name); + virDomainObjPtr vm = virDomainFindByName(&driver->domains, dom->name); const char *prog[] = {VZCTL, "--quiet", "start", vm ? vm->def->name : NULL, NULL }; if (!vm) { @@ -614,7 +614,7 @@ { virConnectPtr conn= dom->conn; struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); const char *prog[] = { VZCTL, "--quiet", "destroy", vm ? vm->def->name : NULL, NULL }; if (!vm) { @@ -643,7 +643,7 @@ { virConnectPtr conn= dom->conn; struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL, "--onboot", autostart ? "yes" : "no", "--save", NULL }; @@ -666,7 +666,7 @@ { virConnectPtr conn= dom->conn; struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); char value[1024]; if (!vm) { @@ -703,7 +703,7 @@ static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { virConnectPtr conn= dom->conn; struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); char str_vcpus[32]; const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL, "--cpus", str_vcpus, "--save", NULL }; @@ -844,15 +844,14 @@ return got; } -static int openvzNumDomains(virConnectPtr conn ATTRIBUTE_UNUSED) { +static int openvzNumDomains(virConnectPtr conn) { struct openvz_driver *driver = conn->privateData; - int nactive = 0; - virDomainObjPtr vm = driver->domains; - while (vm) { - if (virDomainIsActive(vm)) + int nactive = 0, i; + + for (i = 0 ; i < driver->domains.count ; i++) + if (virDomainIsActive(driver->domains.objs[i])) nactive++; - vm = vm->next; - } + return nactive; } @@ -944,13 +943,12 @@ static int openvzNumDefinedDomains(virConnectPtr conn) { struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; - int ninactive = 0; - virDomainObjPtr vm = driver->domains; - while (vm) { - if (!virDomainIsActive(vm)) + int ninactive = 0, i; + + for (i = 0 ; i < driver->domains.count ; i++) + if (!virDomainIsActive(driver->domains.objs[i])) ninactive++; - vm = vm->next; - } + return ninactive; } diff -r 2bb12d98c26b src/qemu_conf.h --- a/src/qemu_conf.h Fri Oct 03 12:45:58 2008 +0100 +++ b/src/qemu_conf.h Fri Oct 03 12:58:03 2008 +0100 @@ -51,7 +51,7 @@ unsigned int qemuVersion; int nextvmid; - virDomainObjPtr domains; + virDomainObjList domains; brControl *brctl; char *configDir; diff -r 2bb12d98c26b src/qemu_driver.c --- a/src/qemu_driver.c Fri Oct 03 12:45:58 2008 +0100 +++ b/src/qemu_driver.c Fri Oct 03 12:58:03 2008 +0100 @@ -126,23 +126,18 @@ static struct qemud_driver *qemu_driver = NULL; -static -void qemudAutostartConfigs(struct qemud_driver *driver) { - virDomainObjPtr vm; +static void +qemudAutostartConfigs(struct qemud_driver *driver) { + unsigned int i; - vm = driver->domains; - while (vm != NULL) { - virDomainObjPtr next = vm->next; - - if (vm->autostart && - !virDomainIsActive(vm) && - qemudStartVMDaemon(NULL, driver, vm, NULL) < 0) { + for (i = 0 ; i < driver->domains.count ; i++) { + if (driver->domains.objs[i]->autostart && + !virDomainIsActive(driver->domains.objs[i]) && + qemudStartVMDaemon(NULL, driver, driver->domains.objs[i], NULL) < 0) { virErrorPtr err = virGetLastError(); qemudLog(QEMUD_ERR, _("Failed to autostart VM '%s': %s\n"), - vm->def->name, err->message); + driver->domains.objs[i]->def->name, err->message); } - - vm = next; } } @@ -240,6 +235,9 @@ */ static int qemudReload(void) { + if (!qemu_driver) + return 0; + virDomainLoadAllConfigs(NULL, qemu_driver->caps, &qemu_driver->domains, @@ -261,13 +259,14 @@ */ static int qemudActive(void) { - virDomainObjPtr dom = qemu_driver->domains; + unsigned int i; - while (dom) { - if (virDomainIsActive(dom)) + if (!qemu_driver) + return 0; + + for (i = 0 ; i < qemu_driver->domains.count ; i++) + if (virDomainIsActive(qemu_driver->domains.objs[i])) return 1; - dom = dom->next; - } /* Otherwise we're happy to deal with a shutdown */ return 0; @@ -280,7 +279,7 @@ */ static int qemudShutdown(void) { - virDomainObjPtr vm; + unsigned int i; if (!qemu_driver) return -1; @@ -288,25 +287,16 @@ virCapabilitiesFree(qemu_driver->caps); /* shutdown active VMs */ - vm = qemu_driver->domains; - while (vm) { - virDomainObjPtr next = vm->next; - if (virDomainIsActive(vm)) - qemudShutdownVMDaemon(NULL, qemu_driver, vm); - if (!vm->persistent) + for (i = 0 ; i < qemu_driver->domains.count ; i++) { + virDomainObjPtr dom = qemu_driver->domains.objs[i]; + if (virDomainIsActive(dom)) + qemudShutdownVMDaemon(NULL, qemu_driver, dom); + if (!dom->persistent) virDomainRemoveInactive(&qemu_driver->domains, - vm); - vm = next; + dom); } - /* free inactive VMs */ - vm = qemu_driver->domains; - while (vm) { - virDomainObjPtr next = vm->next; - virDomainObjFree(vm); - vm = next; - } - qemu_driver->domains = NULL; + virDomainObjListFree(&qemu_driver->domains); VIR_FREE(qemu_driver->logDir); VIR_FREE(qemu_driver->configDir); @@ -1036,15 +1026,16 @@ static void qemudDispatchVMEvent(int fd, int events, void *opaque) { struct qemud_driver *driver = (struct qemud_driver *)opaque; - virDomainObjPtr vm = driver->domains; + virDomainObjPtr vm = NULL; + unsigned int i; - while (vm) { - if (virDomainIsActive(vm) && - (vm->stdout_fd == fd || - vm->stderr_fd == fd)) + for (i = 0 ; i < driver->domains.count ; i++) { + if (virDomainIsActive(driver->domains.objs[i]) && + (driver->domains.objs[i]->stdout_fd == fd || + driver->domains.objs[i]->stderr_fd == fd)) { + vm = driver->domains.objs[i]; break; - - vm = vm->next; + } } if (!vm) @@ -1351,7 +1342,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn, int id) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, id); virDomainPtr dom; if (!vm) { @@ -1366,7 +1357,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn, const unsigned char *uuid) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid); virDomainPtr dom; if (!vm) { @@ -1381,7 +1372,7 @@ static virDomainPtr qemudDomainLookupByName(virConnectPtr conn, const char *name) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - virDomainObjPtr vm = virDomainFindByName(driver->domains, name); + virDomainObjPtr vm = virDomainFindByName(&driver->domains, name); virDomainPtr dom; if (!vm) { @@ -1427,26 +1418,22 @@ static int qemudListDomains(virConnectPtr conn, int *ids, int nids) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - virDomainObjPtr vm = driver->domains; - int got = 0; - while (vm && got < nids) { - if (virDomainIsActive(vm)) { - ids[got] = vm->def->id; - got++; - } - vm = vm->next; - } + int got = 0, i; + + for (i = 0 ; i < driver->domains.count && got < nids ; i++) + if (virDomainIsActive(driver->domains.objs[i])) + ids[got++] = driver->domains.objs[i]->def->id; + return got; } static int qemudNumDomains(virConnectPtr conn) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - int n = 0; - virDomainObjPtr dom = driver->domains; - while (dom) { - if (virDomainIsActive(dom)) + int n = 0, i; + + for (i = 0 ; i < driver->domains.count ; i++) + if (virDomainIsActive(driver->domains.objs[i])) n++; - dom = dom->next; - } + return n; } static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, @@ -1459,7 +1446,7 @@ if (!(def = virDomainDefParseString(conn, driver->caps, xml))) return NULL; - vm = virDomainFindByName(driver->domains, def->name); + vm = virDomainFindByName(&driver->domains, def->name); if (vm) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("domain '%s' is already defined"), @@ -1467,7 +1454,7 @@ virDomainDefFree(def); return NULL; } - vm = virDomainFindByUUID(driver->domains, def->uuid); + vm = virDomainFindByUUID(&driver->domains, def->uuid); if (vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -1501,7 +1488,7 @@ static int qemudDomainSuspend(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; char *info; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, _("no domain with matching id %d"), dom->id); return -1; @@ -1529,7 +1516,7 @@ static int qemudDomainResume(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; char *info; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, _("no domain with matching id %d"), dom->id); @@ -1556,7 +1543,7 @@ static int qemudDomainShutdown(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); char* info; if (!vm) { @@ -1577,7 +1564,7 @@ static int qemudDomainDestroy(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, @@ -1596,7 +1583,7 @@ static char *qemudDomainGetOSType(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); char *type; if (!vm) { @@ -1616,7 +1603,7 @@ /* Returns max memory in kb, 0 if error */ static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -1632,7 +1619,7 @@ static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -1655,7 +1642,7 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -1685,7 +1672,7 @@ static int qemudDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid")); @@ -1806,7 +1793,7 @@ static int qemudDomainSave(virDomainPtr dom, const char *path) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); char *command, *info; int fd; char *safe_path; @@ -1926,8 +1913,8 @@ static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { - const struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); int max; if (!vm) { @@ -1970,7 +1957,7 @@ unsigned char *cpumap, int maplen) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); cpu_set_t mask; int i, maxcpu; virNodeInfo nodeinfo; @@ -2023,7 +2010,7 @@ unsigned char *cpumaps, int maplen) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); virNodeInfo nodeinfo; int i, v, maxcpu; @@ -2088,7 +2075,7 @@ static int qemudDomainGetMaxVcpus(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); const char *type; int ret; @@ -2181,9 +2168,9 @@ VIR_FREE(xml); /* Ensure the name and UUID don't already exist in an active VM */ - vm = virDomainFindByUUID(driver->domains, def->uuid); + vm = virDomainFindByUUID(&driver->domains, def->uuid); if (!vm) - vm = virDomainFindByName(driver->domains, def->name); + vm = virDomainFindByName(&driver->domains, def->name); if (vm && virDomainIsActive(vm)) { qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, _("domain is already active as '%s'"), vm->def->name); @@ -2234,7 +2221,7 @@ static char *qemudDomainDumpXML(virDomainPtr dom, int flags ATTRIBUTE_UNUSED) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, "%s", _("no domain with matching uuid")); @@ -2251,19 +2238,18 @@ static int qemudListDefinedDomains(virConnectPtr conn, char **const names, int nnames) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - virDomainObjPtr vm = driver->domains; int got = 0, i; - while (vm && got < nnames) { - if (!virDomainIsActive(vm)) { - if (!(names[got] = strdup(vm->def->name))) { + + for (i = 0 ; i < driver->domains.count && got < nnames ; i++) { + if (!virDomainIsActive(driver->domains.objs[i])) { + if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) { qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, - "%s", _("failed to allocate space for VM name string")); + "%s", _("failed to allocate space for VM name string")); goto cleanup; } - got++; } - vm = vm->next; } + return got; cleanup: @@ -2272,23 +2258,21 @@ return -1; } - static int qemudNumDefinedDomains(virConnectPtr conn) { struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; - int n = 0; - virDomainObjPtr dom = driver->domains; - while (dom) { - if (!virDomainIsActive(dom)) + int n = 0, i; + + for (i = 0 ; i < driver->domains.count ; i++) + if (!virDomainIsActive(driver->domains.objs[i])) n++; - dom = dom->next; - } + return n; } static int qemudDomainStart(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, @@ -2332,7 +2316,7 @@ static int qemudDomainUndefine(virDomainPtr dom) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, @@ -2408,7 +2392,7 @@ virDomainDeviceDefPtr dev) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); virDomainDiskDefPtr origdisk, newdisk; char *cmd, *reply, *safe_path; char *devname = NULL; @@ -2525,7 +2509,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDeviceDefPtr dev) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); int ret; char *cmd, *reply; virDomainDiskDefPtr *dest, *prev, ptr; @@ -2595,7 +2579,7 @@ static int qemudDomainAttachHostDevice(virDomainPtr dom, virDomainDeviceDefPtr dev) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); int ret; char *cmd, *reply; @@ -2650,7 +2634,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom, const char *xml) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); virDomainDeviceDefPtr dev; int ret = 0; @@ -2696,7 +2680,7 @@ static int qemudDomainGetAutostart(virDomainPtr dom, int *autostart) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); if (!vm) { qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, @@ -2712,7 +2696,7 @@ static int qemudDomainSetAutostart(virDomainPtr dom, int autostart) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); char *configFile = NULL, *autostartLink = NULL; int ret = -1; @@ -2782,13 +2766,13 @@ const char *path, struct _virDomainBlockStats *stats) { - const struct qemud_driver *driver = + struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; char *dummy, *info; const char *p, *eol; char qemu_dev_name[32]; size_t len; - const virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + const virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); if (!vm) { qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, @@ -2922,7 +2906,7 @@ { #ifdef __linux__ struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); virDomainNetDefPtr net; if (!vm) { @@ -2970,7 +2954,7 @@ unsigned int flags ATTRIBUTE_UNUSED) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByUUID(driver->domains, dom->uuid); + virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, dom->uuid); virDomainDiskDefPtr disk; int fd, ret = -1; @@ -3028,7 +3012,7 @@ unsigned int flags) { struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; - virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); + virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id); char cmd[256], *info; char tmp[] = TEMPDIR "/qemu.mem.XXXXXX"; int fd = -1, ret = -1; diff -r 2bb12d98c26b src/test.c --- a/src/test.c Fri Oct 03 12:45:58 2008 +0100 +++ b/src/test.c Fri Oct 03 12:58:03 2008 +0100 @@ -57,7 +57,7 @@ int nextDomID; virCapsPtr caps; virNodeInfo nodeInfo; - virDomainObjPtr domains; + virDomainObjList domains; virNetworkObjPtr networks; int numCells; testCell cells[MAX_CELLS]; @@ -86,8 +86,8 @@ \ privconn = (testConnPtr)dom->conn->privateData; \ do { \ - if ((privdom = virDomainFindByName(privconn->domains, \ - (dom)->name)) == NULL) { \ + if ((privdom = virDomainFindByName(&privconn->domains, \ + (dom)->name)) == NULL) { \ testError((dom)->conn, (dom), NULL, VIR_ERR_INVALID_ARG, \ __FUNCTION__); \ return (ret); \ @@ -272,7 +272,7 @@ return VIR_DRV_OPEN_SUCCESS; error: - virDomainObjFree(privconn->domains); + virDomainObjListFree(&privconn->domains); virNetworkObjFree(privconn->networks); virCapabilitiesFree(privconn->caps); VIR_FREE(privconn); @@ -507,12 +507,7 @@ VIR_FREE(networks); if (fd != -1) close(fd); - dom = privconn->domains; - while (dom) { - virDomainObjPtr tmp = dom->next; - virDomainObjFree(dom); - dom = tmp; - } + virDomainObjListFree(&privconn->domains); net = privconn->networks; while (net) { virNetworkObjPtr tmp = net->next; @@ -565,16 +560,10 @@ static int testClose(virConnectPtr conn) { - virDomainObjPtr dom; virNetworkObjPtr net; GET_CONNECTION(conn); virCapabilitiesFree(privconn->caps); - dom = privconn->domains; - while (dom) { - virDomainObjPtr tmp = dom->next; - virDomainObjFree(dom); - dom = tmp; - } + virDomainObjListFree(&privconn->domains); net = privconn->networks; while (net) { virNetworkObjPtr tmp = net->next; @@ -652,16 +641,13 @@ static int testNumOfDomains(virConnectPtr conn) { - int numActive = 0; - virDomainObjPtr dom; + unsigned int numActive = 0, i; GET_CONNECTION(conn); - dom = privconn->domains; - while (dom) { - if (virDomainIsActive(dom)) + for (i = 0 ; i < privconn->domains.count ; i++) + if (virDomainIsActive(privconn->domains.objs[i])) numActive++; - dom = dom->next; - } + return numActive; } @@ -700,7 +686,7 @@ virDomainPtr ret; GET_CONNECTION(conn); - if ((dom = virDomainFindByID(privconn->domains, id)) == NULL) { + if ((dom = virDomainFindByID(&privconn->domains, id)) == NULL) { testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -719,7 +705,7 @@ virDomainObjPtr dom = NULL; GET_CONNECTION(conn); - if ((dom = virDomainFindByUUID(privconn->domains, uuid)) == NULL) { + if ((dom = virDomainFindByUUID(&privconn->domains, uuid)) == NULL) { testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -738,7 +724,7 @@ virDomainObjPtr dom = NULL; GET_CONNECTION(conn); - if ((dom = virDomainFindByName(privconn->domains, name)) == NULL) { + if ((dom = virDomainFindByName(&privconn->domains, name)) == NULL) { testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL); return NULL; } @@ -754,16 +740,13 @@ int *ids, int maxids) { - int n = 0; - virDomainObjPtr dom; + unsigned int n = 0, i; GET_CONNECTION(conn); - dom = privconn->domains; - while (dom && n < maxids) { - if (virDomainIsActive(dom)) - ids[n++] = dom->def->id; - dom = dom->next; - } + for (i = 0 ; i < privconn->domains.count && n < maxids ; i++) + if (virDomainIsActive(privconn->domains.objs[i])) + ids[n++] = privconn->domains.objs[i]->def->id; + return n; } @@ -1107,34 +1090,28 @@ } static int testNumOfDefinedDomains(virConnectPtr conn) { - int numInactive = 0; - virDomainObjPtr dom; + unsigned int numInactive = 0, i; GET_CONNECTION(conn); - dom = privconn->domains; - while (dom) { - if (!virDomainIsActive(dom)) + for (i = 0 ; i < privconn->domains.count ; i++) + if (!virDomainIsActive(privconn->domains.objs[i])) numInactive++; - dom = dom->next; - } + return numInactive; } static int testListDefinedDomains(virConnectPtr conn, char **const names, int maxnames) { - int n = 0; - virDomainObjPtr dom; + unsigned int n = 0, i; GET_CONNECTION(conn); - dom = privconn->domains; memset(names, 0, sizeof(*names)*maxnames); - while (dom && n < maxnames) { - if (!virDomainIsActive(dom) && - !(names[n++] = strdup(dom->def->name))) + for (i = 0 ; i < privconn->domains.count && n < maxnames ; i++) + if (!virDomainIsActive(privconn->domains.objs[i]) && + !(names[n++] = strdup(privconn->domains.objs[i]->def->name))) goto no_memory; - dom = dom->next; - } + return n; no_memory: -- |: Red Hat, Engineering, London -o- http://people.redhat.com/berrange/ :| |: http://libvirt.org -o- http://virt-manager.org -o- http://ovirt.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: GnuPG: 7D3B9505 -o- F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :| -- Libvir-list mailing list Libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list