Switch domain objects to array instead of linked list

This commit is contained in:
Daniel P. Berrange 2008-10-10 14:20:37 +00:00
parent 1564711a27
commit 4789154063
11 changed files with 285 additions and 321 deletions

View File

@ -1,3 +1,12 @@
Fri Oct 10 15:19:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* src/domain_conf.c, src/domain_conf.h: Switch to using
array instead of linked list for domain objects
* src/lxc_conf.h, src/lxc_driver.c, src/openvz_conf.c,
src/openvz_conf.h, src/openvz_driver.c, src/qemu_conf.h,
src/qemu_driver.c test.c: Update to manage domain objects
in array instead of linked list
Fri Oct 10 14:56:00 BST 2008 Daniel P. Berrange <berrange@redhat.com> Fri Oct 10 14:56:00 BST 2008 Daniel P. Berrange <berrange@redhat.com>
* configure.in: option to enable/disable network driver * configure.in: option to enable/disable network driver

View File

@ -145,44 +145,40 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
__virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__, \ __virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__, \
__FUNCTION__, __LINE__, fmt) __FUNCTION__, __LINE__, fmt)
virDomainObjPtr virDomainFindByID(const virDomainObjPtr doms, virDomainObjPtr virDomainFindByID(const virDomainObjListPtr doms,
int id) int id)
{ {
virDomainObjPtr dom = doms; unsigned int i;
while (dom) {
if (virDomainIsActive(dom) && dom->def->id == id) for (i = 0 ; i < doms->count ; i++)
return dom; if (virDomainIsActive(doms->objs[i]) &&
dom = dom->next; doms->objs[i]->def->id == id)
} return doms->objs[i];
return NULL; return NULL;
} }
virDomainObjPtr virDomainFindByUUID(const virDomainObjPtr doms, virDomainObjPtr virDomainFindByUUID(const virDomainObjListPtr doms,
const unsigned char *uuid) const unsigned char *uuid)
{ {
virDomainObjPtr dom = doms; unsigned int i;
while (dom) { for (i = 0 ; i < doms->count ; i++)
if (!memcmp(dom->def->uuid, uuid, VIR_UUID_BUFLEN)) if (!memcmp(doms->objs[i]->def->uuid, uuid, VIR_UUID_BUFLEN))
return dom; return doms->objs[i];
dom = dom->next;
}
return NULL; return NULL;
} }
virDomainObjPtr virDomainFindByName(const virDomainObjPtr doms, virDomainObjPtr virDomainFindByName(const virDomainObjListPtr doms,
const char *name) const char *name)
{ {
virDomainObjPtr dom = doms; unsigned int i;
while (dom) { for (i = 0 ; i < doms->count ; i++)
if (STREQ(dom->def->name, name)) if (STREQ(doms->objs[i]->def->name, name))
return dom; return doms->objs[i];
dom = dom->next;
}
return NULL; return NULL;
} }
@ -404,13 +400,24 @@ void virDomainObjFree(virDomainObjPtr dom)
VIR_FREE(dom); 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 virDomainAssignDef(virConnectPtr conn,
virDomainObjPtr *doms, virDomainObjListPtr doms,
const virDomainDefPtr def) const virDomainDefPtr def)
{ {
virDomainObjPtr domain; virDomainObjPtr domain;
if ((domain = virDomainFindByName(*doms, def->name))) { if ((domain = virDomainFindByName(doms, def->name))) {
if (!virDomainIsActive(domain)) { if (!virDomainIsActive(domain)) {
virDomainDefFree(domain->def); virDomainDefFree(domain->def);
domain->def = def; domain->def = def;
@ -430,33 +437,41 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
domain->state = VIR_DOMAIN_SHUTOFF; domain->state = VIR_DOMAIN_SHUTOFF;
domain->def = def; 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; return domain;
} }
void virDomainRemoveInactive(virDomainObjPtr *doms, void virDomainRemoveInactive(virDomainObjListPtr doms,
virDomainObjPtr dom) virDomainObjPtr dom)
{ {
virDomainObjPtr prev = NULL; unsigned int i;
virDomainObjPtr curr = *doms;
while (curr && for (i = 0 ; i < doms->count ; i++) {
curr != dom) { if (doms->objs[i] == dom) {
prev = curr; virDomainObjFree(doms->objs[i]);
curr = curr->next;
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 #ifndef PROXY
@ -3245,7 +3260,7 @@ int virDomainSaveConfig(virConnectPtr conn,
virDomainObjPtr virDomainLoadConfig(virConnectPtr conn, virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjPtr *doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir, const char *autostartDir,
const char *name) const char *name)
@ -3284,7 +3299,7 @@ error:
int virDomainLoadAllConfigs(virConnectPtr conn, int virDomainLoadAllConfigs(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjPtr *doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir) const char *autostartDir)
{ {

View File

@ -460,10 +460,14 @@ struct _virDomainObj {
virDomainDefPtr def; /* The current definition */ virDomainDefPtr def; /* The current definition */
virDomainDefPtr newDef; /* New definition to activate at shutdown */ 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 static inline int
virDomainIsActive(virDomainObjPtr dom) virDomainIsActive(virDomainObjPtr dom)
@ -472,11 +476,11 @@ virDomainIsActive(virDomainObjPtr dom)
} }
virDomainObjPtr virDomainFindByID(const virDomainObjPtr doms, virDomainObjPtr virDomainFindByID(const virDomainObjListPtr doms,
int id); int id);
virDomainObjPtr virDomainFindByUUID(const virDomainObjPtr doms, virDomainObjPtr virDomainFindByUUID(const virDomainObjListPtr doms,
const unsigned char *uuid); const unsigned char *uuid);
virDomainObjPtr virDomainFindByName(const virDomainObjPtr doms, virDomainObjPtr virDomainFindByName(const virDomainObjListPtr doms,
const char *name); const char *name);
@ -491,11 +495,12 @@ void virDomainHostdevDefFree(virDomainHostdevDefPtr def);
void virDomainDeviceDefFree(virDomainDeviceDefPtr def); void virDomainDeviceDefFree(virDomainDeviceDefPtr def);
void virDomainDefFree(virDomainDefPtr vm); void virDomainDefFree(virDomainDefPtr vm);
void virDomainObjFree(virDomainObjPtr vm); void virDomainObjFree(virDomainObjPtr vm);
void virDomainObjListFree(virDomainObjListPtr vms);
virDomainObjPtr virDomainAssignDef(virConnectPtr conn, virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
virDomainObjPtr *doms, virDomainObjListPtr doms,
const virDomainDefPtr def); const virDomainDefPtr def);
void virDomainRemoveInactive(virDomainObjPtr *doms, void virDomainRemoveInactive(virDomainObjListPtr doms,
virDomainObjPtr dom); virDomainObjPtr dom);
#ifndef PROXY #ifndef PROXY
@ -535,14 +540,14 @@ int virDomainSaveConfig(virConnectPtr conn,
virDomainObjPtr virDomainLoadConfig(virConnectPtr conn, virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjPtr *doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir, const char *autostartDir,
const char *name); const char *name);
int virDomainLoadAllConfigs(virConnectPtr conn, int virDomainLoadAllConfigs(virConnectPtr conn,
virCapsPtr caps, virCapsPtr caps,
virDomainObjPtr *doms, virDomainObjListPtr doms,
const char *configDir, const char *configDir,
const char *autostartDir); const char *autostartDir);

View File

@ -38,7 +38,7 @@ typedef struct __lxc_driver lxc_driver_t;
struct __lxc_driver { struct __lxc_driver {
virCapsPtr caps; virCapsPtr caps;
virDomainObjPtr domains; virDomainObjList domains;
char *configDir; char *configDir;
char *autostartDir; char *autostartDir;
char *stateDir; char *stateDir;

View File

@ -104,7 +104,7 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
int id) int id)
{ {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
virDomainObjPtr vm = virDomainFindByID(driver->domains, id); virDomainObjPtr vm = virDomainFindByID(&driver->domains, id);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -124,7 +124,7 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn,
const unsigned char *uuid) const unsigned char *uuid)
{ {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
virDomainObjPtr vm = virDomainFindByUUID(driver->domains, uuid); virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -144,7 +144,7 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
const char *name) const char *name)
{ {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
virDomainObjPtr vm = virDomainFindByName(driver->domains, name); virDomainObjPtr vm = virDomainFindByName(&driver->domains, name);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -162,44 +162,40 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
static int lxcListDomains(virConnectPtr conn, int *ids, int nids) { static int lxcListDomains(virConnectPtr conn, int *ids, int nids) {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
virDomainObjPtr vm = driver->domains; int got = 0, i;
int got = 0;
while (vm && got < nids) { for (i = 0 ; i < driver->domains.count && got < nids ; i++)
if (virDomainIsActive(vm)) { if (virDomainIsActive(driver->domains.objs[i]))
ids[got] = vm->def->id; ids[got++] = driver->domains.objs[i]->def->id;
got++;
}
vm = vm->next;
}
return got; return got;
} }
static int lxcNumDomains(virConnectPtr conn) { static int lxcNumDomains(virConnectPtr conn) {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
int n = 0; int n = 0, i;
virDomainObjPtr dom = driver->domains;
while (dom) { for (i = 0 ; i < driver->domains.count ; i++)
if (virDomainIsActive(dom)) if (virDomainIsActive(driver->domains.objs[i]))
n++; n++;
dom = dom->next;
}
return n; return n;
} }
static int lxcListDefinedDomains(virConnectPtr conn, static int lxcListDefinedDomains(virConnectPtr conn,
char **const names, int nnames) { char **const names, int nnames) {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
virDomainObjPtr vm = driver->domains;
int got = 0, i; int got = 0, i;
while (vm && got < nnames) {
if (!virDomainIsActive(vm)) { for (i = 0 ; i < driver->domains.count && got < nnames ; i++) {
if (!(names[got] = strdup(vm->def->name))) { if (!virDomainIsActive(driver->domains.objs[i])) {
lxcError(conn, NULL, VIR_ERR_NO_MEMORY, NULL); 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; goto cleanup;
} }
got++;
} }
vm = vm->next;
} }
return got; return got;
cleanup: cleanup:
@ -211,13 +207,12 @@ static int lxcListDefinedDomains(virConnectPtr conn,
static int lxcNumDefinedDomains(virConnectPtr conn) { static int lxcNumDefinedDomains(virConnectPtr conn) {
lxc_driver_t *driver = (lxc_driver_t *)conn->privateData; lxc_driver_t *driver = (lxc_driver_t *)conn->privateData;
int n = 0; int n = 0, i;
virDomainObjPtr dom = driver->domains;
while (dom) { for (i = 0 ; i < driver->domains.count ; i++)
if (!virDomainIsActive(dom)) if (!virDomainIsActive(driver->domains.objs[i]))
n++; n++;
dom = dom->next;
}
return n; return n;
} }
@ -264,7 +259,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
static int lxcDomainUndefine(virDomainPtr dom) static int lxcDomainUndefine(virDomainPtr dom)
{ {
lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; 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) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -299,7 +294,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
virDomainInfoPtr info) virDomainInfoPtr info)
{ {
lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; 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) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -325,7 +320,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
static char *lxcGetOSType(virDomainPtr dom) static char *lxcGetOSType(virDomainPtr dom)
{ {
lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; 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) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -340,7 +335,7 @@ static char *lxcDomainDumpXML(virDomainPtr dom,
int flags) int flags)
{ {
lxc_driver_t *driver = (lxc_driver_t *)dom->conn->privateData; 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) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -593,12 +588,14 @@ static void lxcMonitorEvent(int fd,
void *data) void *data)
{ {
lxc_driver_t *driver = data; lxc_driver_t *driver = data;
virDomainObjPtr vm = driver->domains; virDomainObjPtr vm = NULL;
unsigned int i;
while (vm) { for (i = 0 ; i < driver->domains.count ; i++) {
if (vm->monitor == fd) if (driver->domains.objs[i]->monitor == fd) {
vm = driver->domains.objs[i];
break; break;
vm = vm->next; }
} }
if (!vm) { if (!vm) {
virEventRemoveHandle(fd); virEventRemoveHandle(fd);
@ -855,7 +852,7 @@ static int lxcDomainStart(virDomainPtr dom)
int rc = -1; int rc = -1;
virConnectPtr conn = dom->conn; virConnectPtr conn = dom->conn;
lxc_driver_t *driver = (lxc_driver_t *)(conn->privateData); 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) { if (!vm) {
lxcError(conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -935,7 +932,7 @@ return_point:
static int lxcDomainShutdown(virDomainPtr dom) static int lxcDomainShutdown(virDomainPtr dom)
{ {
lxc_driver_t *driver = (lxc_driver_t*)dom->conn->privateData; 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) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -958,7 +955,7 @@ static int lxcDomainShutdown(virDomainPtr dom)
static int lxcDomainDestroy(virDomainPtr dom) static int lxcDomainDestroy(virDomainPtr dom)
{ {
lxc_driver_t *driver = (lxc_driver_t*)dom->conn->privateData; 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) { if (!vm) {
lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN, lxcError(dom->conn, dom, VIR_ERR_INVALID_DOMAIN,
@ -987,7 +984,7 @@ static int lxcCheckNetNsSupport(void)
static int lxcStartup(void) static int lxcStartup(void)
{ {
uid_t uid = getuid(); uid_t uid = getuid();
virDomainObjPtr vm; unsigned int i;
/* Check that the user is root */ /* Check that the user is root */
if (0 != uid) { if (0 != uid) {
@ -1024,21 +1021,18 @@ static int lxcStartup(void)
return -1; return -1;
} }
vm = lxc_driver->domains; for (i = 0 ; i < lxc_driver->domains.count ; i++) {
while (vm) { virDomainObjPtr vm = lxc_driver->domains.objs[i];
char *config = NULL; char *config = NULL;
virDomainDefPtr tmp; virDomainDefPtr tmp;
int rc; int rc;
if ((vm->monitor = lxcMonitorClient(NULL, lxc_driver, vm)) < 0) { if ((vm->monitor = lxcMonitorClient(NULL, lxc_driver, vm)) < 0)
vm = vm->next;
continue; continue;
}
/* Read pid from controller */ /* Read pid from controller */
if ((rc = virFileReadPid(lxc_driver->stateDir, vm->def->name, &vm->pid)) != 0) { if ((rc = virFileReadPid(lxc_driver->stateDir, vm->def->name, &vm->pid)) != 0) {
close(vm->monitor); close(vm->monitor);
vm->monitor = -1; vm->monitor = -1;
vm = vm->next;
continue; continue;
} }
@ -1063,8 +1057,6 @@ static int lxcStartup(void)
close(vm->monitor); close(vm->monitor);
vm->monitor = -1; vm->monitor = -1;
} }
vm = vm->next;
} }
return 0; return 0;
@ -1081,15 +1073,10 @@ static void lxcFreeDriver(lxc_driver_t *driver)
static int lxcShutdown(void) static int lxcShutdown(void)
{ {
virDomainObjPtr vm;
if (lxc_driver == NULL) if (lxc_driver == NULL)
return(-1); return(-1);
vm = lxc_driver->domains;
while (vm) { virDomainObjListFree(&lxc_driver->domains);
virDomainObjPtr next = vm->next;
virDomainObjFree(vm);
vm = next;
}
lxcFreeDriver(lxc_driver); lxcFreeDriver(lxc_driver);
lxc_driver = NULL; lxc_driver = NULL;
@ -1105,17 +1092,14 @@ static int lxcShutdown(void)
*/ */
static int static int
lxcActive(void) { lxcActive(void) {
virDomainObjPtr dom; unsigned int i;
if (lxc_driver == NULL) if (lxc_driver == NULL)
return(0); return(0);
dom = lxc_driver->domains; for (i = 0 ; i < lxc_driver->domains.count ; i++)
while (dom) { if (virDomainIsActive(lxc_driver->domains.objs[i]))
if (virDomainIsActive(dom))
return 1; return 1;
dom = dom->next;
}
/* Otherwise we're happy to deal with a shutdown */ /* Otherwise we're happy to deal with a shutdown */
return 0; return 0;
@ -1166,7 +1150,7 @@ static int lxcSetSchedulerParameters(virDomainPtr _domain,
if (virCgroupHaveSupport() != 0) if (virCgroupHaveSupport() != 0)
return 0; return 0;
domain = virDomainFindByUUID(lxc_driver->domains, _domain->uuid); domain = virDomainFindByUUID(&lxc_driver->domains, _domain->uuid);
if (domain == NULL) { if (domain == NULL) {
lxcError(NULL, _domain, VIR_ERR_INTERNAL_ERROR, lxcError(NULL, _domain, VIR_ERR_INTERNAL_ERROR,
_("No such domain %s"), _domain->uuid); _("No such domain %s"), _domain->uuid);
@ -1214,7 +1198,7 @@ static int lxcGetSchedulerParameters(virDomainPtr _domain,
return -1; return -1;
} }
domain = virDomainFindByUUID(lxc_driver->domains, _domain->uuid); domain = virDomainFindByUUID(&lxc_driver->domains, _domain->uuid);
if (domain == NULL) { if (domain == NULL) {
lxcError(NULL, _domain, VIR_ERR_INTERNAL_ERROR, lxcError(NULL, _domain, VIR_ERR_INTERNAL_ERROR,
_("No such domain %s"), _domain->uuid); _("No such domain %s"), _domain->uuid);

View File

@ -273,18 +273,10 @@ error:
void void
openvzFreeDriver(struct openvz_driver *driver) openvzFreeDriver(struct openvz_driver *driver)
{ {
virDomainObjPtr dom;
if (!driver) if (!driver)
return; return;
dom = driver->domains; virDomainObjListFree(&driver->domains);
while (dom) {
virDomainObjPtr tmp = dom->next;
virDomainObjFree(dom);
dom = tmp;
}
virCapabilitiesFree(driver->caps); virCapabilitiesFree(driver->caps);
} }
@ -295,7 +287,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
int veid, ret; int veid, ret;
char status[16]; char status[16];
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
virDomainObjPtr dom = NULL, prev = NULL; virDomainObjPtr dom = NULL;
char temp[50]; char temp[50];
if (openvzAssignUUIDs() < 0) if (openvzAssignUUIDs() < 0)
@ -363,12 +355,12 @@ int openvzLoadDomains(struct openvz_driver *driver) {
dom->def->nets = openvzReadNetworkConf(NULL, veid); dom->def->nets = openvzReadNetworkConf(NULL, veid);
if (prev) { if (VIR_REALLOC_N(driver->domains.objs,
prev->next = dom; driver->domains.count + 1) < 0)
} else { goto no_memory;
driver->domains = dom;
} driver->domains.objs[driver->domains.count++] = dom;
prev = dom; dom = NULL;
} }
fclose(fp); fclose(fp);

View File

@ -52,7 +52,7 @@ enum { OPENVZ_WARN, OPENVZ_ERR };
struct openvz_driver { struct openvz_driver {
virCapsPtr caps; virCapsPtr caps;
virDomainObjPtr domains; virDomainObjList domains;
}; };
int openvz_readline(int fd, char *ptr, int maxlen); int openvz_readline(int fd, char *ptr, int maxlen);

View File

@ -157,7 +157,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
virDomainObjPtr vm; virDomainObjPtr vm;
virDomainPtr dom; virDomainPtr dom;
vm = virDomainFindByID(driver->domains, id); vm = virDomainFindByID(&driver->domains, id);
if (!vm) { if (!vm) {
openvzError(conn, VIR_ERR_NO_DOMAIN, NULL); openvzError(conn, VIR_ERR_NO_DOMAIN, NULL);
@ -175,7 +175,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
static char *openvzGetOSType(virDomainPtr dom) static char *openvzGetOSType(virDomainPtr dom)
{ {
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; 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; char *ret;
if (!vm) { if (!vm) {
@ -193,7 +193,7 @@ static char *openvzGetOSType(virDomainPtr dom)
static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn, static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
const unsigned char *uuid) { const unsigned char *uuid) {
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData; struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
virDomainObjPtr vm = virDomainFindByUUID(driver->domains, uuid); virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -212,7 +212,7 @@ static virDomainPtr openvzDomainLookupByUUID(virConnectPtr conn,
static virDomainPtr openvzDomainLookupByName(virConnectPtr conn, static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
const char *name) { const char *name) {
struct openvz_driver *driver = (struct openvz_driver *)conn->privateData; struct openvz_driver *driver = (struct openvz_driver *)conn->privateData;
virDomainObjPtr vm = virDomainFindByName(driver->domains, name); virDomainObjPtr vm = virDomainFindByName(&driver->domains, name);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -231,7 +231,7 @@ static virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
static int openvzDomainGetInfo(virDomainPtr dom, static int openvzDomainGetInfo(virDomainPtr dom,
virDomainInfoPtr info) { virDomainInfoPtr info) {
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; 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) { if (!vm) {
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
@ -260,7 +260,7 @@ static int openvzDomainGetInfo(virDomainPtr dom,
static char *openvzDomainDumpXML(virDomainPtr dom, int flags) { static char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; 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) { if (!vm) {
openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN, openvzError(dom->conn, VIR_ERR_INVALID_DOMAIN,
@ -275,7 +275,7 @@ static char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
static int openvzDomainShutdown(virDomainPtr dom) { static int openvzDomainShutdown(virDomainPtr dom) {
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; 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}; const char *prog[] = {VZCTL, "--quiet", "stop", vm ? vm->def->name : NULL, NULL};
if (!vm) { if (!vm) {
@ -302,7 +302,7 @@ static int openvzDomainShutdown(virDomainPtr dom) {
static int openvzDomainReboot(virDomainPtr dom, static int openvzDomainReboot(virDomainPtr dom,
unsigned int flags ATTRIBUTE_UNUSED) { unsigned int flags ATTRIBUTE_UNUSED) {
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; 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}; const char *prog[] = {VZCTL, "--quiet", "restart", vm ? vm->def->name : NULL, NULL};
if (!vm) { if (!vm) {
@ -434,7 +434,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
return NULL; return NULL;
} }
vm = virDomainFindByName(driver->domains, vmdef->name); vm = virDomainFindByName(&driver->domains, vmdef->name);
if (vm) { if (vm) {
openvzError(conn, VIR_ERR_OPERATION_FAILED, openvzError(conn, VIR_ERR_OPERATION_FAILED,
_("Already an OPENVZ VM active with the id '%s'"), _("Already an OPENVZ VM active with the id '%s'"),
@ -511,7 +511,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
return NULL; return NULL;
} }
vm = virDomainFindByName(driver->domains, vmdef->name); vm = virDomainFindByName(&driver->domains, vmdef->name);
if (vm) { if (vm) {
openvzError(conn, VIR_ERR_OPERATION_FAILED, openvzError(conn, VIR_ERR_OPERATION_FAILED,
_("Already an OPENVZ VM defined with the id '%s'"), _("Already an OPENVZ VM defined with the id '%s'"),
@ -581,7 +581,7 @@ static int
openvzDomainCreate(virDomainPtr dom) openvzDomainCreate(virDomainPtr dom)
{ {
struct openvz_driver *driver = (struct openvz_driver *)dom->conn->privateData; 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 }; const char *prog[] = {VZCTL, "--quiet", "start", vm ? vm->def->name : NULL, NULL };
if (!vm) { if (!vm) {
@ -614,7 +614,7 @@ openvzDomainUndefine(virDomainPtr dom)
{ {
virConnectPtr conn= dom->conn; virConnectPtr conn= dom->conn;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; 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 }; const char *prog[] = { VZCTL, "--quiet", "destroy", vm ? vm->def->name : NULL, NULL };
if (!vm) { if (!vm) {
@ -643,7 +643,7 @@ openvzDomainSetAutostart(virDomainPtr dom, int autostart)
{ {
virConnectPtr conn= dom->conn; virConnectPtr conn= dom->conn;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; 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, const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL,
"--onboot", autostart ? "yes" : "no", "--onboot", autostart ? "yes" : "no",
"--save", NULL }; "--save", NULL };
@ -666,7 +666,7 @@ openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
{ {
virConnectPtr conn= dom->conn; virConnectPtr conn= dom->conn;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; 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]; char value[1024];
if (!vm) { if (!vm) {
@ -703,7 +703,7 @@ static int openvzDomainGetMaxVcpus(virDomainPtr dom) {
static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { static int openvzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
virConnectPtr conn= dom->conn; virConnectPtr conn= dom->conn;
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; 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]; char str_vcpus[32];
const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL, const char *prog[] = { VZCTL, "--quiet", "set", vm ? vm->def->name : NULL,
"--cpus", str_vcpus, "--save", NULL }; "--cpus", str_vcpus, "--save", NULL };
@ -844,15 +844,14 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
return got; return got;
} }
static int openvzNumDomains(virConnectPtr conn ATTRIBUTE_UNUSED) { static int openvzNumDomains(virConnectPtr conn) {
struct openvz_driver *driver = conn->privateData; struct openvz_driver *driver = conn->privateData;
int nactive = 0; int nactive = 0, i;
virDomainObjPtr vm = driver->domains;
while (vm) { for (i = 0 ; i < driver->domains.count ; i++)
if (virDomainIsActive(vm)) if (virDomainIsActive(driver->domains.objs[i]))
nactive++; nactive++;
vm = vm->next;
}
return nactive; return nactive;
} }
@ -944,13 +943,12 @@ Version: 2.2
static int openvzNumDefinedDomains(virConnectPtr conn) { static int openvzNumDefinedDomains(virConnectPtr conn) {
struct openvz_driver *driver = (struct openvz_driver *) conn->privateData; struct openvz_driver *driver = (struct openvz_driver *) conn->privateData;
int ninactive = 0; int ninactive = 0, i;
virDomainObjPtr vm = driver->domains;
while (vm) { for (i = 0 ; i < driver->domains.count ; i++)
if (!virDomainIsActive(vm)) if (!virDomainIsActive(driver->domains.objs[i]))
ninactive++; ninactive++;
vm = vm->next;
}
return ninactive; return ninactive;
} }

View File

@ -51,7 +51,7 @@ struct qemud_driver {
unsigned int qemuVersion; unsigned int qemuVersion;
int nextvmid; int nextvmid;
virDomainObjPtr domains; virDomainObjList domains;
brControl *brctl; brControl *brctl;
char *configDir; char *configDir;

View File

@ -126,23 +126,18 @@ static int qemudMonitorCommand (const struct qemud_driver *driver,
static struct qemud_driver *qemu_driver = NULL; static struct qemud_driver *qemu_driver = NULL;
static static void
void qemudAutostartConfigs(struct qemud_driver *driver) { qemudAutostartConfigs(struct qemud_driver *driver) {
virDomainObjPtr vm; unsigned int i;
vm = driver->domains; for (i = 0 ; i < driver->domains.count ; i++) {
while (vm != NULL) { if (driver->domains.objs[i]->autostart &&
virDomainObjPtr next = vm->next; !virDomainIsActive(driver->domains.objs[i]) &&
qemudStartVMDaemon(NULL, driver, driver->domains.objs[i], NULL) < 0) {
if (vm->autostart &&
!virDomainIsActive(vm) &&
qemudStartVMDaemon(NULL, driver, vm, NULL) < 0) {
virErrorPtr err = virGetLastError(); virErrorPtr err = virGetLastError();
qemudLog(QEMUD_ERR, _("Failed to autostart VM '%s': %s\n"), 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;
} }
} }
@ -238,6 +233,9 @@ qemudStartup(void) {
*/ */
static int static int
qemudReload(void) { qemudReload(void) {
if (!qemu_driver)
return 0;
virDomainLoadAllConfigs(NULL, virDomainLoadAllConfigs(NULL,
qemu_driver->caps, qemu_driver->caps,
&qemu_driver->domains, &qemu_driver->domains,
@ -259,13 +257,14 @@ qemudReload(void) {
*/ */
static int static int
qemudActive(void) { qemudActive(void) {
virDomainObjPtr dom = qemu_driver->domains; unsigned int i;
while (dom) { if (!qemu_driver)
if (virDomainIsActive(dom)) return 0;
for (i = 0 ; i < qemu_driver->domains.count ; i++)
if (virDomainIsActive(qemu_driver->domains.objs[i]))
return 1; return 1;
dom = dom->next;
}
/* Otherwise we're happy to deal with a shutdown */ /* Otherwise we're happy to deal with a shutdown */
return 0; return 0;
@ -278,7 +277,7 @@ qemudActive(void) {
*/ */
static int static int
qemudShutdown(void) { qemudShutdown(void) {
virDomainObjPtr vm; unsigned int i;
if (!qemu_driver) if (!qemu_driver)
return -1; return -1;
@ -286,25 +285,16 @@ qemudShutdown(void) {
virCapabilitiesFree(qemu_driver->caps); virCapabilitiesFree(qemu_driver->caps);
/* shutdown active VMs */ /* shutdown active VMs */
vm = qemu_driver->domains; for (i = 0 ; i < qemu_driver->domains.count ; i++) {
while (vm) { virDomainObjPtr dom = qemu_driver->domains.objs[i];
virDomainObjPtr next = vm->next; if (virDomainIsActive(dom))
if (virDomainIsActive(vm)) qemudShutdownVMDaemon(NULL, qemu_driver, dom);
qemudShutdownVMDaemon(NULL, qemu_driver, vm); if (!dom->persistent)
if (!vm->persistent)
virDomainRemoveInactive(&qemu_driver->domains, virDomainRemoveInactive(&qemu_driver->domains,
vm); dom);
vm = next;
} }
/* free inactive VMs */ virDomainObjListFree(&qemu_driver->domains);
vm = qemu_driver->domains;
while (vm) {
virDomainObjPtr next = vm->next;
virDomainObjFree(vm);
vm = next;
}
qemu_driver->domains = NULL;
VIR_FREE(qemu_driver->logDir); VIR_FREE(qemu_driver->logDir);
VIR_FREE(qemu_driver->configDir); VIR_FREE(qemu_driver->configDir);
@ -1019,15 +1009,16 @@ static int qemudDispatchVMFailure(struct qemud_driver *driver, virDomainObjPtr v
static void qemudDispatchVMEvent(int fd, int events, void *opaque) { static void qemudDispatchVMEvent(int fd, int events, void *opaque) {
struct qemud_driver *driver = (struct qemud_driver *)opaque; struct qemud_driver *driver = (struct qemud_driver *)opaque;
virDomainObjPtr vm = driver->domains; virDomainObjPtr vm = NULL;
unsigned int i;
while (vm) { for (i = 0 ; i < driver->domains.count ; i++) {
if (virDomainIsActive(vm) && if (virDomainIsActive(driver->domains.objs[i]) &&
(vm->stdout_fd == fd || (driver->domains.objs[i]->stdout_fd == fd ||
vm->stderr_fd == fd)) driver->domains.objs[i]->stderr_fd == fd)) {
vm = driver->domains.objs[i];
break; break;
}
vm = vm->next;
} }
if (!vm) if (!vm)
@ -1334,7 +1325,7 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) {
static virDomainPtr qemudDomainLookupByID(virConnectPtr conn, static virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
int id) { int id) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
virDomainObjPtr vm = virDomainFindByID(driver->domains, id); virDomainObjPtr vm = virDomainFindByID(&driver->domains, id);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -1349,7 +1340,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn, static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
const unsigned char *uuid) { const unsigned char *uuid) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
virDomainObjPtr vm = virDomainFindByUUID(driver->domains, uuid); virDomainObjPtr vm = virDomainFindByUUID(&driver->domains, uuid);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -1364,7 +1355,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
static virDomainPtr qemudDomainLookupByName(virConnectPtr conn, static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
const char *name) { const char *name) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
virDomainObjPtr vm = virDomainFindByName(driver->domains, name); virDomainObjPtr vm = virDomainFindByName(&driver->domains, name);
virDomainPtr dom; virDomainPtr dom;
if (!vm) { if (!vm) {
@ -1410,26 +1401,22 @@ qemudGetHostname (virConnectPtr conn)
static int qemudListDomains(virConnectPtr conn, int *ids, int nids) { static int qemudListDomains(virConnectPtr conn, int *ids, int nids) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
virDomainObjPtr vm = driver->domains; int got = 0, i;
int got = 0;
while (vm && got < nids) { for (i = 0 ; i < driver->domains.count && got < nids ; i++)
if (virDomainIsActive(vm)) { if (virDomainIsActive(driver->domains.objs[i]))
ids[got] = vm->def->id; ids[got++] = driver->domains.objs[i]->def->id;
got++;
}
vm = vm->next;
}
return got; return got;
} }
static int qemudNumDomains(virConnectPtr conn) { static int qemudNumDomains(virConnectPtr conn) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
int n = 0; int n = 0, i;
virDomainObjPtr dom = driver->domains;
while (dom) { for (i = 0 ; i < driver->domains.count ; i++)
if (virDomainIsActive(dom)) if (virDomainIsActive(driver->domains.objs[i]))
n++; n++;
dom = dom->next;
}
return n; return n;
} }
static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml, static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
@ -1442,7 +1429,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
if (!(def = virDomainDefParseString(conn, driver->caps, xml))) if (!(def = virDomainDefParseString(conn, driver->caps, xml)))
return NULL; return NULL;
vm = virDomainFindByName(driver->domains, def->name); vm = virDomainFindByName(&driver->domains, def->name);
if (vm) { if (vm) {
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
_("domain '%s' is already defined"), _("domain '%s' is already defined"),
@ -1450,7 +1437,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
virDomainDefFree(def); virDomainDefFree(def);
return NULL; return NULL;
} }
vm = virDomainFindByUUID(driver->domains, def->uuid); vm = virDomainFindByUUID(&driver->domains, def->uuid);
if (vm) { if (vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -1484,7 +1471,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
static int qemudDomainSuspend(virDomainPtr dom) { static int qemudDomainSuspend(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
char *info; char *info;
virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id);
if (!vm) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, _("no domain with matching id %d"), dom->id); qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, _("no domain with matching id %d"), dom->id);
return -1; return -1;
@ -1512,7 +1499,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
static int qemudDomainResume(virDomainPtr dom) { static int qemudDomainResume(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData;
char *info; char *info;
virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id);
if (!vm) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
_("no domain with matching id %d"), dom->id); _("no domain with matching id %d"), dom->id);
@ -1539,7 +1526,7 @@ static int qemudDomainResume(virDomainPtr dom) {
static int qemudDomainShutdown(virDomainPtr dom) { static int qemudDomainShutdown(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; char* info;
if (!vm) { if (!vm) {
@ -1561,7 +1548,7 @@ static int qemudDomainShutdown(virDomainPtr dom) {
static int qemudDomainDestroy(virDomainPtr dom) { static int qemudDomainDestroy(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@ -1580,7 +1567,7 @@ static int qemudDomainDestroy(virDomainPtr dom) {
static char *qemudDomainGetOSType(virDomainPtr dom) { static char *qemudDomainGetOSType(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; char *type;
if (!vm) { if (!vm) {
@ -1600,7 +1587,7 @@ static char *qemudDomainGetOSType(virDomainPtr dom) {
/* Returns max memory in kb, 0 if error */ /* Returns max memory in kb, 0 if error */
static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) { static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -1616,7 +1603,7 @@ static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) {
static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) { static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -1639,7 +1626,7 @@ static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) {
static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) { static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN]; char uuidstr[VIR_UUID_STRING_BUFLEN];
@ -1669,7 +1656,7 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
static int qemudDomainGetInfo(virDomainPtr dom, static int qemudDomainGetInfo(virDomainPtr dom,
virDomainInfoPtr info) { virDomainInfoPtr info) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
"%s", _("no domain with matching uuid")); "%s", _("no domain with matching uuid"));
@ -1790,7 +1777,7 @@ struct qemud_save_header {
static int qemudDomainSave(virDomainPtr dom, static int qemudDomainSave(virDomainPtr dom,
const char *path) { const char *path) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; char *command, *info;
int fd; int fd;
char *safe_path; char *safe_path;
@ -1910,8 +1897,8 @@ static int qemudDomainSave(virDomainPtr dom,
static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) { static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus) {
const struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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 max; int max;
if (!vm) { if (!vm) {
@ -1954,7 +1941,7 @@ qemudDomainPinVcpu(virDomainPtr dom,
unsigned char *cpumap, unsigned char *cpumap,
int maplen) { int maplen) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; cpu_set_t mask;
int i, maxcpu; int i, maxcpu;
virNodeInfo nodeinfo; virNodeInfo nodeinfo;
@ -2007,7 +1994,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
unsigned char *cpumaps, unsigned char *cpumaps,
int maplen) { int maplen) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; virNodeInfo nodeinfo;
int i, v, maxcpu; int i, v, maxcpu;
@ -2072,7 +2059,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
static int qemudDomainGetMaxVcpus(virDomainPtr dom) { static int qemudDomainGetMaxVcpus(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; const char *type;
int ret; int ret;
@ -2165,9 +2152,9 @@ static int qemudDomainRestore(virConnectPtr conn,
VIR_FREE(xml); VIR_FREE(xml);
/* Ensure the name and UUID don't already exist in an active VM */ /* 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) if (!vm)
vm = virDomainFindByName(driver->domains, def->name); vm = virDomainFindByName(&driver->domains, def->name);
if (vm && virDomainIsActive(vm)) { if (vm && virDomainIsActive(vm)) {
qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED, qemudReportError(conn, NULL, NULL, VIR_ERR_OPERATION_FAILED,
_("domain is already active as '%s'"), vm->def->name); _("domain is already active as '%s'"), vm->def->name);
@ -2218,7 +2205,7 @@ static int qemudDomainRestore(virConnectPtr conn,
static char *qemudDomainDumpXML(virDomainPtr dom, static char *qemudDomainDumpXML(virDomainPtr dom,
int flags ATTRIBUTE_UNUSED) { int flags ATTRIBUTE_UNUSED) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
"%s", _("no domain with matching uuid")); "%s", _("no domain with matching uuid"));
@ -2235,19 +2222,18 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
static int qemudListDefinedDomains(virConnectPtr conn, static int qemudListDefinedDomains(virConnectPtr conn,
char **const names, int nnames) { char **const names, int nnames) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
virDomainObjPtr vm = driver->domains;
int got = 0, i; int got = 0, i;
while (vm && got < nnames) {
if (!virDomainIsActive(vm)) { for (i = 0 ; i < driver->domains.count && got < nnames ; i++) {
if (!(names[got] = strdup(vm->def->name))) { if (!virDomainIsActive(driver->domains.objs[i])) {
if (!(names[got++] = strdup(driver->domains.objs[i]->def->name))) {
qemudReportError(conn, NULL, NULL, VIR_ERR_NO_MEMORY, 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; goto cleanup;
} }
got++;
} }
vm = vm->next;
} }
return got; return got;
cleanup: cleanup:
@ -2256,23 +2242,21 @@ static int qemudListDefinedDomains(virConnectPtr conn,
return -1; return -1;
} }
static int qemudNumDefinedDomains(virConnectPtr conn) { static int qemudNumDefinedDomains(virConnectPtr conn) {
struct qemud_driver *driver = (struct qemud_driver *)conn->privateData; struct qemud_driver *driver = (struct qemud_driver *)conn->privateData;
int n = 0; int n = 0, i;
virDomainObjPtr dom = driver->domains;
while (dom) { for (i = 0 ; i < driver->domains.count ; i++)
if (!virDomainIsActive(dom)) if (!virDomainIsActive(driver->domains.objs[i]))
n++; n++;
dom = dom->next;
}
return n; return n;
} }
static int qemudDomainStart(virDomainPtr dom) { static int qemudDomainStart(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@ -2316,7 +2300,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
static int qemudDomainUndefine(virDomainPtr dom) { static int qemudDomainUndefine(virDomainPtr dom) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@ -2392,7 +2376,7 @@ static int qemudDomainChangeEjectableMedia(virDomainPtr dom,
virDomainDeviceDefPtr dev) virDomainDeviceDefPtr dev)
{ {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; virDomainDiskDefPtr origdisk, newdisk;
char *cmd, *reply, *safe_path; char *cmd, *reply, *safe_path;
char *devname = NULL; char *devname = NULL;
@ -2509,7 +2493,7 @@ static int qemudDomainChangeEjectableMedia(virDomainPtr dom,
static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDeviceDefPtr dev) static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDeviceDefPtr dev)
{ {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; int ret;
char *cmd, *reply; char *cmd, *reply;
virDomainDiskDefPtr *dest, *prev, ptr; virDomainDiskDefPtr *dest, *prev, ptr;
@ -2579,7 +2563,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
static int qemudDomainAttachHostDevice(virDomainPtr dom, virDomainDeviceDefPtr dev) static int qemudDomainAttachHostDevice(virDomainPtr dom, virDomainDeviceDefPtr dev)
{ {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; int ret;
char *cmd, *reply; char *cmd, *reply;
@ -2634,7 +2618,7 @@ static int qemudDomainAttachHostDevice(virDomainPtr dom, virDomainDeviceDefPtr d
static int qemudDomainAttachDevice(virDomainPtr dom, static int qemudDomainAttachDevice(virDomainPtr dom,
const char *xml) { const char *xml) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; virDomainDeviceDefPtr dev;
int ret = 0; int ret = 0;
@ -2680,7 +2664,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
static int qemudDomainGetAutostart(virDomainPtr dom, static int qemudDomainGetAutostart(virDomainPtr dom,
int *autostart) { int *autostart) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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) { if (!vm) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError(dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@ -2696,7 +2680,7 @@ static int qemudDomainGetAutostart(virDomainPtr dom,
static int qemudDomainSetAutostart(virDomainPtr dom, static int qemudDomainSetAutostart(virDomainPtr dom,
int autostart) { int autostart) {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; char *configFile = NULL, *autostartLink = NULL;
int ret = -1; int ret = -1;
@ -2766,13 +2750,13 @@ qemudDomainBlockStats (virDomainPtr dom,
const char *path, const char *path,
struct _virDomainBlockStats *stats) struct _virDomainBlockStats *stats)
{ {
const struct qemud_driver *driver = struct qemud_driver *driver =
(struct qemud_driver *)dom->conn->privateData; (struct qemud_driver *)dom->conn->privateData;
char *dummy, *info; char *dummy, *info;
const char *p, *eol; const char *p, *eol;
char qemu_dev_name[32]; char qemu_dev_name[32];
size_t len; size_t len;
const virDomainObjPtr vm = virDomainFindByID(driver->domains, dom->id); const virDomainObjPtr vm = virDomainFindByID(&driver->domains, dom->id);
if (!vm) { if (!vm) {
qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN, qemudReportError (dom->conn, dom, NULL, VIR_ERR_INVALID_DOMAIN,
@ -2906,7 +2890,7 @@ qemudDomainInterfaceStats (virDomainPtr dom,
{ {
#ifdef __linux__ #ifdef __linux__
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; virDomainNetDefPtr net;
if (!vm) { if (!vm) {
@ -2954,7 +2938,7 @@ qemudDomainBlockPeek (virDomainPtr dom,
unsigned int flags ATTRIBUTE_UNUSED) unsigned int flags ATTRIBUTE_UNUSED)
{ {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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; virDomainDiskDefPtr disk;
int fd, ret = -1; int fd, ret = -1;
@ -3012,7 +2996,7 @@ qemudDomainMemoryPeek (virDomainPtr dom,
unsigned int flags) unsigned int flags)
{ {
struct qemud_driver *driver = (struct qemud_driver *)dom->conn->privateData; 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 cmd[256], *info;
char tmp[] = TEMPDIR "/qemu.mem.XXXXXX"; char tmp[] = TEMPDIR "/qemu.mem.XXXXXX";
int fd = -1, ret = -1; int fd = -1, ret = -1;

View File

@ -57,7 +57,7 @@ struct _testConn {
int nextDomID; int nextDomID;
virCapsPtr caps; virCapsPtr caps;
virNodeInfo nodeInfo; virNodeInfo nodeInfo;
virDomainObjPtr domains; virDomainObjList domains;
virNetworkObjPtr networks; virNetworkObjPtr networks;
int numCells; int numCells;
testCell cells[MAX_CELLS]; testCell cells[MAX_CELLS];
@ -86,7 +86,7 @@ static const virNodeInfo defaultNodeInfo = {
\ \
privconn = (testConnPtr)dom->conn->privateData; \ privconn = (testConnPtr)dom->conn->privateData; \
do { \ do { \
if ((privdom = virDomainFindByName(privconn->domains, \ if ((privdom = virDomainFindByName(&privconn->domains, \
(dom)->name)) == NULL) { \ (dom)->name)) == NULL) { \
testError((dom)->conn, (dom), NULL, VIR_ERR_INVALID_ARG, \ testError((dom)->conn, (dom), NULL, VIR_ERR_INVALID_ARG, \
__FUNCTION__); \ __FUNCTION__); \
@ -259,7 +259,7 @@ static int testOpenDefault(virConnectPtr conn) {
return VIR_DRV_OPEN_SUCCESS; return VIR_DRV_OPEN_SUCCESS;
error: error:
virDomainObjFree(privconn->domains); virDomainObjListFree(&privconn->domains);
virNetworkObjFree(privconn->networks); virNetworkObjFree(privconn->networks);
virCapabilitiesFree(privconn->caps); virCapabilitiesFree(privconn->caps);
VIR_FREE(privconn); VIR_FREE(privconn);
@ -494,12 +494,7 @@ static int testOpenFromFile(virConnectPtr conn,
VIR_FREE(networks); VIR_FREE(networks);
if (fd != -1) if (fd != -1)
close(fd); close(fd);
dom = privconn->domains; virDomainObjListFree(&privconn->domains);
while (dom) {
virDomainObjPtr tmp = dom->next;
virDomainObjFree(dom);
dom = tmp;
}
net = privconn->networks; net = privconn->networks;
while (net) { while (net) {
virNetworkObjPtr tmp = net->next; virNetworkObjPtr tmp = net->next;
@ -552,16 +547,10 @@ static int testOpen(virConnectPtr conn,
static int testClose(virConnectPtr conn) static int testClose(virConnectPtr conn)
{ {
virDomainObjPtr dom;
virNetworkObjPtr net; virNetworkObjPtr net;
GET_CONNECTION(conn); GET_CONNECTION(conn);
virCapabilitiesFree(privconn->caps); virCapabilitiesFree(privconn->caps);
dom = privconn->domains; virDomainObjListFree(&privconn->domains);
while (dom) {
virDomainObjPtr tmp = dom->next;
virDomainObjFree(dom);
dom = tmp;
}
net = privconn->networks; net = privconn->networks;
while (net) { while (net) {
virNetworkObjPtr tmp = net->next; virNetworkObjPtr tmp = net->next;
@ -642,16 +631,13 @@ static char *testGetCapabilities (virConnectPtr conn)
static int testNumOfDomains(virConnectPtr conn) static int testNumOfDomains(virConnectPtr conn)
{ {
int numActive = 0; unsigned int numActive = 0, i;
virDomainObjPtr dom;
GET_CONNECTION(conn); GET_CONNECTION(conn);
dom = privconn->domains; for (i = 0 ; i < privconn->domains.count ; i++)
while (dom) { if (virDomainIsActive(privconn->domains.objs[i]))
if (virDomainIsActive(dom))
numActive++; numActive++;
dom = dom->next;
}
return numActive; return numActive;
} }
@ -690,7 +676,7 @@ static virDomainPtr testLookupDomainByID(virConnectPtr conn,
virDomainPtr ret; virDomainPtr ret;
GET_CONNECTION(conn); 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); testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
return NULL; return NULL;
} }
@ -709,7 +695,7 @@ static virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
GET_CONNECTION(conn); 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); testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
return NULL; return NULL;
} }
@ -728,7 +714,7 @@ static virDomainPtr testLookupDomainByName(virConnectPtr conn,
virDomainObjPtr dom = NULL; virDomainObjPtr dom = NULL;
GET_CONNECTION(conn); 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); testError (conn, NULL, NULL, VIR_ERR_NO_DOMAIN, NULL);
return NULL; return NULL;
} }
@ -744,16 +730,13 @@ static int testListDomains (virConnectPtr conn,
int *ids, int *ids,
int maxids) int maxids)
{ {
int n = 0; unsigned int n = 0, i;
virDomainObjPtr dom;
GET_CONNECTION(conn); GET_CONNECTION(conn);
dom = privconn->domains; for (i = 0 ; i < privconn->domains.count && n < maxids ; i++)
while (dom && n < maxids) { if (virDomainIsActive(privconn->domains.objs[i]))
if (virDomainIsActive(dom)) ids[n++] = privconn->domains.objs[i]->def->id;
ids[n++] = dom->def->id;
dom = dom->next;
}
return n; return n;
} }
@ -1097,34 +1080,28 @@ static char *testDomainDumpXML(virDomainPtr domain, int flags)
} }
static int testNumOfDefinedDomains(virConnectPtr conn) { static int testNumOfDefinedDomains(virConnectPtr conn) {
int numInactive = 0; unsigned int numInactive = 0, i;
virDomainObjPtr dom;
GET_CONNECTION(conn); GET_CONNECTION(conn);
dom = privconn->domains; for (i = 0 ; i < privconn->domains.count ; i++)
while (dom) { if (!virDomainIsActive(privconn->domains.objs[i]))
if (!virDomainIsActive(dom))
numInactive++; numInactive++;
dom = dom->next;
}
return numInactive; return numInactive;
} }
static int testListDefinedDomains(virConnectPtr conn, static int testListDefinedDomains(virConnectPtr conn,
char **const names, char **const names,
int maxnames) { int maxnames) {
int n = 0; unsigned int n = 0, i;
virDomainObjPtr dom;
GET_CONNECTION(conn); GET_CONNECTION(conn);
dom = privconn->domains;
memset(names, 0, sizeof(*names)*maxnames); memset(names, 0, sizeof(*names)*maxnames);
while (dom && n < maxnames) { for (i = 0 ; i < privconn->domains.count && n < maxnames ; i++)
if (!virDomainIsActive(dom) && if (!virDomainIsActive(privconn->domains.objs[i]) &&
!(names[n++] = strdup(dom->def->name))) !(names[n++] = strdup(privconn->domains.objs[i]->def->name)))
goto no_memory; goto no_memory;
dom = dom->next;
}
return n; return n;
no_memory: no_memory: