diff --git a/ChangeLog b/ChangeLog index 1eca5e683f..93dd8d8fef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Mon Sep 3 18:29:05 CEST 2007 Daniel Veillard + + * src/openvz_conf.c src/openvz_conf.h src/openvz_driver.c: a bit + of cleanup on top of previous patches. + Mon Sep 3 17:35:15 CEST 2007 Daniel Veillard * src/openvz_conf.c src/openvz_conf.h src/openvz_driver.c diff --git a/src/openvz_conf.c b/src/openvz_conf.c index 141139a0e6..ed577608a3 100644 --- a/src/openvz_conf.c +++ b/src/openvz_conf.c @@ -59,9 +59,6 @@ static void error (virConnectPtr conn, virErrorNumber code, const char *info); static struct openvz_vm_def *openvzParseXML(virConnectPtr conn, xmlDocPtr xml); static int openvzGetVPSUUID(int vpsid, char *uuidstr); static int openvzSetUUID(int vpsid); -static struct openvz_vm *openvzLoadConfig(struct openvz_driver *driver, - const char *path, - const char *xmlStr); /* For errors internal to this library. */ static void @@ -117,7 +114,7 @@ struct openvz_vm } int -strtoI(char *str) +strtoI(const char *str) { int base = 10; char *endptr; @@ -340,7 +337,7 @@ static struct openvz_vm_def } /* rejecting VPS ID <= OPENVZ_RSRV_VM_LIMIT for they are reserved */ - if (strtoI(BAD_CAST obj->stringval) <= OPENVZ_RSRV_VM_LIMIT) { + if (strtoI((const char *) obj->stringval) <= OPENVZ_RSRV_VM_LIMIT) { error(conn, VIR_ERR_INTERNAL_ERROR, "VPS ID Error (must be an integer greater than 100"); goto bail_out; @@ -531,13 +528,18 @@ openvzGetVPSInfo(virConnectPtr conn) { *pnext = calloc(1, sizeof(struct openvz_vm)); if(!*pnext) { error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed"); - return NULL; + goto error; } if(!vm) vm = *pnext; - fscanf(fp, "%d %s\n", &veid, status); + if (fscanf(fp, "%d %s\n", &veid, status) != 2) { + error(conn, VIR_ERR_INTERNAL_ERROR, + "Failed to parse vzlist output"); + free(*pnext); + goto error; + } if(strcmp(status, "stopped")) { (*pnext)->status = VIR_DOMAIN_RUNNING; driver->num_active ++; @@ -546,14 +548,18 @@ openvzGetVPSInfo(virConnectPtr conn) { else { (*pnext)->status = VIR_DOMAIN_SHUTOFF; driver->num_inactive ++; - (*pnext)->vpsid = -1; /* inactive domains don't have their ID set in libvirt, - thought this doesn't make sense for OpenVZ */ + /* + * inactive domains don't have their ID set in libvirt, + * thought this doesn't make sense for OpenVZ + */ + (*pnext)->vpsid = -1; } vmdef = calloc(1, sizeof(struct openvz_vm_def)); if(!vmdef) { error(conn, VIR_ERR_INTERNAL_ERROR, "calloc failed"); - return NULL; + free(*pnext); + goto error; } snprintf(vmdef->name, OPENVZ_NAME_MAX, "%i", veid); @@ -561,14 +567,27 @@ openvzGetVPSInfo(virConnectPtr conn) { ret = virUUIDParse(uuidstr, vmdef->uuid); if(ret == -1) { - error(conn, VIR_ERR_INTERNAL_ERROR, "UUID in config file malformed"); - return NULL; + error(conn, VIR_ERR_INTERNAL_ERROR, + "UUID in config file malformed"); + free(*pnext); + free(vmdef); + goto error; } (*pnext)->vmdef = vmdef; pnext = &(*pnext)->next; } return vm; +error: + while (vm != NULL) { + struct openvz_vm *next; + + next = vm->next; + free(vm->vmdef); + free(vm); + vm = next; + } + return NULL; } static char @@ -579,7 +598,7 @@ static char while(conf_dir_list[i]) { if(!access(conf_dir_list[i], F_OK)) - return strdup(conf_dir_list[i]); + return strdup(conf_dir_list[i]); i ++; } @@ -660,7 +679,7 @@ openvzSetUUID(int vpsid) char uuidstr[VIR_UUID_STRING_BUFLEN]; unsigned char uuid[VIR_UUID_BUFLEN]; char *conf_dir; - int fd, ret, i; + int fd, ret; conf_dir = openvzLocateConfDir(); sprintf(conf_file, "%s/%d.conf", conf_dir, vpsid); diff --git a/src/openvz_conf.h b/src/openvz_conf.h index e1ccc72451..eec4d38914 100644 --- a/src/openvz_conf.h +++ b/src/openvz_conf.h @@ -129,5 +129,5 @@ void openvzRemoveInactiveVM(struct openvz_driver *driver, struct openvz_vm *vm); void openvzFreeDriver(struct openvz_driver *driver); void openvzFreeVM(struct openvz_driver *driver, struct openvz_vm *vm, int checkCallee); void openvzFreeVMDef(struct openvz_vm_def *def); -int strtoI(char *str); +int strtoI(const char *str); #endif /* OPENVZ_CONF_H */ diff --git a/src/openvz_driver.c b/src/openvz_driver.c index aad775c12d..84c9e86f41 100644 --- a/src/openvz_driver.c +++ b/src/openvz_driver.c @@ -164,7 +164,7 @@ static virDomainPtr openvzDomainLookupByID(virConnectPtr conn, return dom; } -static char *openvzGetOSType(virDomainPtr dom) +static char *openvzGetOSType(virDomainPtr dom ATTRIBUTE_UNUSED) { /* OpenVZ runs on Linux and runs only Linux */ return strdup("linux"); @@ -275,7 +275,8 @@ bail_out: return ret; } -static int openvzDomainReboot(virDomainPtr dom, unsigned int flags) { +static int openvzDomainReboot(virDomainPtr dom, + unsigned int flags ATTRIBUTE_UNUSED) { char cmdbuf[CMDBUF_LEN]; int ret; char *cmdExec[OPENVZ_MAX_ARG]; @@ -631,7 +632,7 @@ static int openvzListDomains(virConnectPtr conn, int *ids, int nids) { return got; } -static int openvzNumDomains(virConnectPtr conn) { +static int openvzNumDomains(virConnectPtr conn ATTRIBUTE_UNUSED) { return ovz_driver.num_active; } @@ -662,7 +663,7 @@ static int openvzListDefinedDomains(virConnectPtr conn, return got; } -static int openvzNumDefinedDomains(virConnectPtr conn) { +static int openvzNumDefinedDomains(virConnectPtr conn ATTRIBUTE_UNUSED) { return ovz_driver.num_inactive; } @@ -687,11 +688,11 @@ static int openvzActive(void) { return 1; } -static int openvzCloseNetwork(virConnectPtr conn) { +static int openvzCloseNetwork(virConnectPtr conn ATTRIBUTE_UNUSED) { return 0; } -static virDrvOpenStatus openvzOpenNetwork(virConnectPtr conn, +static virDrvOpenStatus openvzOpenNetwork(virConnectPtr conn ATTRIBUTE_UNUSED, const char *name ATTRIBUTE_UNUSED, int flags ATTRIBUTE_UNUSED) { return VIR_DRV_OPEN_SUCCESS; @@ -747,6 +748,11 @@ static virDriver openvzDriver = { NULL, /* domainGetSchedulerType */ NULL, /* domainGetSchedulerParameters */ NULL, /* domainSetSchedulerParameters */ + NULL, /* domainMigratePrepare */ + NULL, /* domainMigratePerform */ + NULL, /* domainMigrateFinish */ + NULL, /* domainBlockStats */ + NULL, /* domainInterfaceStats */ }; static virNetworkDriver openvzNetworkDriver = {