mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 02:51:16 +00:00
Switch domain objects to array instead of linked list
This commit is contained in:
parent
1564711a27
commit
4789154063
@ -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>
|
||||
|
||||
* configure.in: option to enable/disable network driver
|
||||
|
@ -145,44 +145,40 @@ VIR_ENUM_IMPL(virDomainHostdevSubsys, VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_LAST,
|
||||
__virReportErrorHelper(conn, VIR_FROM_DOMAIN, code, __FILE__, \
|
||||
__FUNCTION__, __LINE__, fmt)
|
||||
|
||||
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;
|
||||
}
|
||||
@ -404,13 +400,24 @@ void virDomainObjFree(virDomainObjPtr 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 *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;
|
||||
@ -430,33 +437,41 @@ virDomainObjPtr virDomainAssignDef(virConnectPtr conn,
|
||||
|
||||
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
|
||||
@ -3245,7 +3260,7 @@ int virDomainSaveConfig(virConnectPtr conn,
|
||||
|
||||
virDomainObjPtr virDomainLoadConfig(virConnectPtr conn,
|
||||
virCapsPtr caps,
|
||||
virDomainObjPtr *doms,
|
||||
virDomainObjListPtr doms,
|
||||
const char *configDir,
|
||||
const char *autostartDir,
|
||||
const char *name)
|
||||
@ -3284,7 +3299,7 @@ error:
|
||||
|
||||
int virDomainLoadAllConfigs(virConnectPtr conn,
|
||||
virCapsPtr caps,
|
||||
virDomainObjPtr *doms,
|
||||
virDomainObjListPtr doms,
|
||||
const char *configDir,
|
||||
const char *autostartDir)
|
||||
{
|
||||
|
@ -460,10 +460,14 @@ struct _virDomainObj {
|
||||
|
||||
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 @@ virDomainIsActive(virDomainObjPtr dom)
|
||||
}
|
||||
|
||||
|
||||
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 virDomainHostdevDefFree(virDomainHostdevDefPtr def);
|
||||
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 @@ int virDomainSaveConfig(virConnectPtr conn,
|
||||
|
||||
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);
|
||||
|
||||
|
@ -38,7 +38,7 @@ typedef struct __lxc_driver lxc_driver_t;
|
||||
struct __lxc_driver {
|
||||
virCapsPtr caps;
|
||||
|
||||
virDomainObjPtr domains;
|
||||
virDomainObjList domains;
|
||||
char *configDir;
|
||||
char *autostartDir;
|
||||
char *stateDir;
|
||||
|
116
src/lxc_driver.c
116
src/lxc_driver.c
@ -104,7 +104,7 @@ static virDomainPtr lxcDomainLookupByID(virConnectPtr conn,
|
||||
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) {
|
||||
@ -124,7 +124,7 @@ static virDomainPtr lxcDomainLookupByUUID(virConnectPtr conn,
|
||||
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) {
|
||||
@ -144,7 +144,7 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
|
||||
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) {
|
||||
@ -162,44 +162,40 @@ static virDomainPtr lxcDomainLookupByName(virConnectPtr conn,
|
||||
|
||||
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:
|
||||
@ -211,13 +207,12 @@ static int lxcListDefinedDomains(virConnectPtr conn,
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -264,7 +259,7 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
|
||||
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,
|
||||
@ -299,7 +294,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
||||
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,
|
||||
@ -325,7 +320,7 @@ static int lxcDomainGetInfo(virDomainPtr dom,
|
||||
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,
|
||||
@ -340,7 +335,7 @@ static char *lxcDomainDumpXML(virDomainPtr dom,
|
||||
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,
|
||||
@ -593,12 +588,14 @@ static void lxcMonitorEvent(int fd,
|
||||
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);
|
||||
@ -855,7 +852,7 @@ static int lxcDomainStart(virDomainPtr dom)
|
||||
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,
|
||||
@ -935,7 +932,7 @@ return_point:
|
||||
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,
|
||||
@ -958,7 +955,7 @@ static int lxcDomainShutdown(virDomainPtr dom)
|
||||
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,
|
||||
@ -987,7 +984,7 @@ static int lxcCheckNetNsSupport(void)
|
||||
static int lxcStartup(void)
|
||||
{
|
||||
uid_t uid = getuid();
|
||||
virDomainObjPtr vm;
|
||||
unsigned int i;
|
||||
|
||||
/* Check that the user is root */
|
||||
if (0 != uid) {
|
||||
@ -1024,21 +1021,18 @@ static int lxcStartup(void)
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1063,8 +1057,6 @@ static int lxcStartup(void)
|
||||
close(vm->monitor);
|
||||
vm->monitor = -1;
|
||||
}
|
||||
|
||||
vm = vm->next;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1081,15 +1073,10 @@ static void lxcFreeDriver(lxc_driver_t *driver)
|
||||
|
||||
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;
|
||||
|
||||
@ -1105,17 +1092,14 @@ static int lxcShutdown(void)
|
||||
*/
|
||||
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;
|
||||
@ -1166,7 +1150,7 @@ static int lxcSetSchedulerParameters(virDomainPtr _domain,
|
||||
if (virCgroupHaveSupport() != 0)
|
||||
return 0;
|
||||
|
||||
domain = virDomainFindByUUID(lxc_driver->domains, _domain->uuid);
|
||||
domain = virDomainFindByUUID(&lxc_driver->domains, _domain->uuid);
|
||||
if (domain == NULL) {
|
||||
lxcError(NULL, _domain, VIR_ERR_INTERNAL_ERROR,
|
||||
_("No such domain %s"), _domain->uuid);
|
||||
@ -1214,7 +1198,7 @@ static int lxcGetSchedulerParameters(virDomainPtr _domain,
|
||||
return -1;
|
||||
}
|
||||
|
||||
domain = virDomainFindByUUID(lxc_driver->domains, _domain->uuid);
|
||||
domain = virDomainFindByUUID(&lxc_driver->domains, _domain->uuid);
|
||||
if (domain == NULL) {
|
||||
lxcError(NULL, _domain, VIR_ERR_INTERNAL_ERROR,
|
||||
_("No such domain %s"), _domain->uuid);
|
||||
|
@ -273,18 +273,10 @@ error:
|
||||
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);
|
||||
}
|
||||
|
||||
@ -295,7 +287,7 @@ int openvzLoadDomains(struct openvz_driver *driver) {
|
||||
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)
|
||||
@ -363,12 +355,12 @@ int openvzLoadDomains(struct openvz_driver *driver) {
|
||||
|
||||
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);
|
||||
|
@ -52,7 +52,7 @@ enum { OPENVZ_WARN, OPENVZ_ERR };
|
||||
|
||||
struct openvz_driver {
|
||||
virCapsPtr caps;
|
||||
virDomainObjPtr domains;
|
||||
virDomainObjList domains;
|
||||
};
|
||||
|
||||
int openvz_readline(int fd, char *ptr, int maxlen);
|
||||
|
@ -157,7 +157,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
||||
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 virDomainPtr openvzDomainLookupByID(virConnectPtr conn,
|
||||
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 char *openvzGetOSType(virDomainPtr dom)
|
||||
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 openvzDomainLookupByUUID(virConnectPtr conn,
|
||||
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 virDomainPtr openvzDomainLookupByName(virConnectPtr conn,
|
||||
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 int openvzDomainGetInfo(virDomainPtr dom,
|
||||
|
||||
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 char *openvzDomainDumpXML(virDomainPtr dom, int flags) {
|
||||
|
||||
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 openvzDomainShutdown(virDomainPtr dom) {
|
||||
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 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
|
||||
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 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
|
||||
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 @@ static int
|
||||
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 @@ openvzDomainUndefine(virDomainPtr dom)
|
||||
{
|
||||
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 @@ openvzDomainSetAutostart(virDomainPtr dom, int autostart)
|
||||
{
|
||||
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 @@ openvzDomainGetAutostart(virDomainPtr dom, int *autostart)
|
||||
{
|
||||
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 openvzDomainGetMaxVcpus(virDomainPtr dom) {
|
||||
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 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) {
|
||||
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 @@ Version: 2.2
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ struct qemud_driver {
|
||||
unsigned int qemuVersion;
|
||||
int nextvmid;
|
||||
|
||||
virDomainObjPtr domains;
|
||||
virDomainObjList domains;
|
||||
|
||||
brControl *brctl;
|
||||
char *configDir;
|
||||
|
@ -126,23 +126,18 @@ static int qemudMonitorCommand (const struct qemud_driver *driver,
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,6 +233,9 @@ qemudStartup(void) {
|
||||
*/
|
||||
static int
|
||||
qemudReload(void) {
|
||||
if (!qemu_driver)
|
||||
return 0;
|
||||
|
||||
virDomainLoadAllConfigs(NULL,
|
||||
qemu_driver->caps,
|
||||
&qemu_driver->domains,
|
||||
@ -259,13 +257,14 @@ qemudReload(void) {
|
||||
*/
|
||||
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;
|
||||
@ -278,7 +277,7 @@ qemudActive(void) {
|
||||
*/
|
||||
static int
|
||||
qemudShutdown(void) {
|
||||
virDomainObjPtr vm;
|
||||
unsigned int i;
|
||||
|
||||
if (!qemu_driver)
|
||||
return -1;
|
||||
@ -286,25 +285,16 @@ qemudShutdown(void) {
|
||||
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);
|
||||
@ -1019,15 +1009,16 @@ static int qemudDispatchVMFailure(struct qemud_driver *driver, virDomainObjPtr v
|
||||
|
||||
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)
|
||||
@ -1334,7 +1325,7 @@ static int qemudGetProcessInfo(unsigned long long *cpuTime, int pid) {
|
||||
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) {
|
||||
@ -1349,7 +1340,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
|
||||
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) {
|
||||
@ -1364,7 +1355,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
|
||||
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) {
|
||||
@ -1410,26 +1401,22 @@ qemudGetHostname (virConnectPtr conn)
|
||||
|
||||
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,
|
||||
@ -1442,7 +1429,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
||||
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"),
|
||||
@ -1450,7 +1437,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
||||
virDomainDefFree(def);
|
||||
return NULL;
|
||||
}
|
||||
vm = virDomainFindByUUID(driver->domains, def->uuid);
|
||||
vm = virDomainFindByUUID(&driver->domains, def->uuid);
|
||||
if (vm) {
|
||||
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||
|
||||
@ -1484,7 +1471,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
|
||||
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;
|
||||
@ -1512,7 +1499,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
|
||||
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);
|
||||
@ -1539,7 +1526,7 @@ static int qemudDomainResume(virDomainPtr dom) {
|
||||
|
||||
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) {
|
||||
@ -1561,7 +1548,7 @@ static int qemudDomainShutdown(virDomainPtr dom) {
|
||||
|
||||
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,
|
||||
@ -1580,7 +1567,7 @@ static int qemudDomainDestroy(virDomainPtr dom) {
|
||||
|
||||
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) {
|
||||
@ -1600,7 +1587,7 @@ static char *qemudDomainGetOSType(virDomainPtr dom) {
|
||||
/* 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];
|
||||
@ -1616,7 +1603,7 @@ static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) {
|
||||
|
||||
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];
|
||||
@ -1639,7 +1626,7 @@ static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long newmax) {
|
||||
|
||||
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];
|
||||
@ -1669,7 +1656,7 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
|
||||
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"));
|
||||
@ -1790,7 +1777,7 @@ struct qemud_save_header {
|
||||
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;
|
||||
@ -1910,8 +1897,8 @@ static int qemudDomainSave(virDomainPtr dom,
|
||||
|
||||
|
||||
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) {
|
||||
@ -1954,7 +1941,7 @@ qemudDomainPinVcpu(virDomainPtr dom,
|
||||
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;
|
||||
@ -2007,7 +1994,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
|
||||
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;
|
||||
|
||||
@ -2072,7 +2059,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
|
||||
|
||||
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;
|
||||
|
||||
@ -2165,9 +2152,9 @@ static int qemudDomainRestore(virConnectPtr conn,
|
||||
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);
|
||||
@ -2218,7 +2205,7 @@ static int qemudDomainRestore(virConnectPtr conn,
|
||||
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"));
|
||||
@ -2235,19 +2222,18 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
|
||||
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"));
|
||||
goto cleanup;
|
||||
}
|
||||
got++;
|
||||
}
|
||||
vm = vm->next;
|
||||
}
|
||||
|
||||
return got;
|
||||
|
||||
cleanup:
|
||||
@ -2256,23 +2242,21 @@ static int qemudListDefinedDomains(virConnectPtr conn,
|
||||
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,
|
||||
@ -2316,7 +2300,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
|
||||
|
||||
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,
|
||||
@ -2392,7 +2376,7 @@ static int qemudDomainChangeEjectableMedia(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);
|
||||
virDomainDiskDefPtr origdisk, newdisk;
|
||||
char *cmd, *reply, *safe_path;
|
||||
char *devname = NULL;
|
||||
@ -2509,7 +2493,7 @@ static int qemudDomainChangeEjectableMedia(virDomainPtr dom,
|
||||
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;
|
||||
@ -2579,7 +2563,7 @@ static int qemudDomainAttachUsbMassstorageDevice(virDomainPtr dom, virDomainDevi
|
||||
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;
|
||||
|
||||
@ -2634,7 +2618,7 @@ static int qemudDomainAttachHostDevice(virDomainPtr dom, virDomainDeviceDefPtr d
|
||||
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;
|
||||
|
||||
@ -2680,7 +2664,7 @@ static int qemudDomainAttachDevice(virDomainPtr dom,
|
||||
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,
|
||||
@ -2696,7 +2680,7 @@ static int qemudDomainGetAutostart(virDomainPtr dom,
|
||||
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;
|
||||
|
||||
@ -2766,13 +2750,13 @@ qemudDomainBlockStats (virDomainPtr dom,
|
||||
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,
|
||||
@ -2906,7 +2890,7 @@ qemudDomainInterfaceStats (virDomainPtr dom,
|
||||
{
|
||||
#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) {
|
||||
@ -2954,7 +2938,7 @@ qemudDomainBlockPeek (virDomainPtr dom,
|
||||
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;
|
||||
|
||||
@ -3012,7 +2996,7 @@ qemudDomainMemoryPeek (virDomainPtr dom,
|
||||
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;
|
||||
|
75
src/test.c
75
src/test.c
@ -57,7 +57,7 @@ struct _testConn {
|
||||
int nextDomID;
|
||||
virCapsPtr caps;
|
||||
virNodeInfo nodeInfo;
|
||||
virDomainObjPtr domains;
|
||||
virDomainObjList domains;
|
||||
virNetworkObjPtr networks;
|
||||
int numCells;
|
||||
testCell cells[MAX_CELLS];
|
||||
@ -86,7 +86,7 @@ static const virNodeInfo defaultNodeInfo = {
|
||||
\
|
||||
privconn = (testConnPtr)dom->conn->privateData; \
|
||||
do { \
|
||||
if ((privdom = virDomainFindByName(privconn->domains, \
|
||||
if ((privdom = virDomainFindByName(&privconn->domains, \
|
||||
(dom)->name)) == NULL) { \
|
||||
testError((dom)->conn, (dom), NULL, VIR_ERR_INVALID_ARG, \
|
||||
__FUNCTION__); \
|
||||
@ -259,7 +259,7 @@ static int testOpenDefault(virConnectPtr conn) {
|
||||
return VIR_DRV_OPEN_SUCCESS;
|
||||
|
||||
error:
|
||||
virDomainObjFree(privconn->domains);
|
||||
virDomainObjListFree(&privconn->domains);
|
||||
virNetworkObjFree(privconn->networks);
|
||||
virCapabilitiesFree(privconn->caps);
|
||||
VIR_FREE(privconn);
|
||||
@ -494,12 +494,7 @@ static int testOpenFromFile(virConnectPtr conn,
|
||||
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;
|
||||
@ -552,16 +547,10 @@ static int testOpen(virConnectPtr conn,
|
||||
|
||||
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;
|
||||
@ -642,16 +631,13 @@ static char *testGetCapabilities (virConnectPtr conn)
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@ -690,7 +676,7 @@ static virDomainPtr testLookupDomainByID(virConnectPtr conn,
|
||||
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;
|
||||
}
|
||||
@ -709,7 +695,7 @@ static virDomainPtr testLookupDomainByUUID(virConnectPtr conn,
|
||||
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;
|
||||
}
|
||||
@ -728,7 +714,7 @@ static virDomainPtr testLookupDomainByName(virConnectPtr conn,
|
||||
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;
|
||||
}
|
||||
@ -744,16 +730,13 @@ static int testListDomains (virConnectPtr conn,
|
||||
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;
|
||||
}
|
||||
|
||||
@ -1097,34 +1080,28 @@ static char *testDomainDumpXML(virDomainPtr domain, int flags)
|
||||
}
|
||||
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user