提交 d2ab0381 编写于 作者: M Michal Privoznik

Adapt to VIR_ALLOC and virAsprintf in src/xenxs/*

上级 2f5560d3
...@@ -89,10 +89,10 @@ xenParseSxprOS(const struct sexpr *node, ...@@ -89,10 +89,10 @@ xenParseSxprOS(const struct sexpr *node,
{ {
if (hvm) { if (hvm) {
if (sexpr_node_copy(node, "domain/image/hvm/loader", &def->os.loader) < 0) if (sexpr_node_copy(node, "domain/image/hvm/loader", &def->os.loader) < 0)
goto no_memory; goto error;
if (def->os.loader == NULL) { if (def->os.loader == NULL) {
if (sexpr_node_copy(node, "domain/image/hvm/kernel", &def->os.loader) < 0) if (sexpr_node_copy(node, "domain/image/hvm/kernel", &def->os.loader) < 0)
goto no_memory; goto error;
if (def->os.loader == NULL) { if (def->os.loader == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -101,23 +101,23 @@ xenParseSxprOS(const struct sexpr *node, ...@@ -101,23 +101,23 @@ xenParseSxprOS(const struct sexpr *node,
} }
} else { } else {
if (sexpr_node_copy(node, "domain/image/hvm/kernel", &def->os.kernel) < 0) if (sexpr_node_copy(node, "domain/image/hvm/kernel", &def->os.kernel) < 0)
goto no_memory; goto error;
if (sexpr_node_copy(node, "domain/image/hvm/ramdisk", &def->os.initrd) < 0) if (sexpr_node_copy(node, "domain/image/hvm/ramdisk", &def->os.initrd) < 0)
goto no_memory; goto error;
if (sexpr_node_copy(node, "domain/image/hvm/args", &def->os.cmdline) < 0) if (sexpr_node_copy(node, "domain/image/hvm/args", &def->os.cmdline) < 0)
goto no_memory; goto error;
if (sexpr_node_copy(node, "domain/image/hvm/root", &def->os.root) < 0) if (sexpr_node_copy(node, "domain/image/hvm/root", &def->os.root) < 0)
goto no_memory; goto error;
} }
} else { } else {
if (sexpr_node_copy(node, "domain/image/linux/kernel", &def->os.kernel) < 0) if (sexpr_node_copy(node, "domain/image/linux/kernel", &def->os.kernel) < 0)
goto no_memory; goto error;
if (sexpr_node_copy(node, "domain/image/linux/ramdisk", &def->os.initrd) < 0) if (sexpr_node_copy(node, "domain/image/linux/ramdisk", &def->os.initrd) < 0)
goto no_memory; goto error;
if (sexpr_node_copy(node, "domain/image/linux/args", &def->os.cmdline) < 0) if (sexpr_node_copy(node, "domain/image/linux/args", &def->os.cmdline) < 0)
goto no_memory; goto error;
if (sexpr_node_copy(node, "domain/image/linux/root", &def->os.root) < 0) if (sexpr_node_copy(node, "domain/image/linux/root", &def->os.root) < 0)
goto no_memory; goto error;
} }
/* If HVM kenrel == loader, then old xend, so kill off kernel */ /* If HVM kenrel == loader, then old xend, so kill off kernel */
...@@ -162,8 +162,7 @@ xenParseSxprOS(const struct sexpr *node, ...@@ -162,8 +162,7 @@ xenParseSxprOS(const struct sexpr *node,
return 0; return 0;
no_memory: error:
virReportOOMError();
return -1; return -1;
} }
...@@ -367,7 +366,7 @@ xenParseSxprDisks(virDomainDefPtr def, ...@@ -367,7 +366,7 @@ xenParseSxprDisks(virDomainDefPtr def,
} }
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto error;
if (dst == NULL) { if (dst == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -401,7 +400,7 @@ xenParseSxprDisks(virDomainDefPtr def, ...@@ -401,7 +400,7 @@ xenParseSxprDisks(virDomainDefPtr def,
goto error; goto error;
} else { } else {
if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0) if (VIR_ALLOC_N(disk->driverName, (offset-src)+1) < 0)
goto no_memory; goto error;
if (virStrncpy(disk->driverName, src, offset-src, if (virStrncpy(disk->driverName, src, offset-src,
(offset-src)+1) == NULL) { (offset-src)+1) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -498,7 +497,7 @@ xenParseSxprDisks(virDomainDefPtr def, ...@@ -498,7 +497,7 @@ xenParseSxprDisks(virDomainDefPtr def,
disk->shared = true; disk->shared = true;
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
goto no_memory; goto error;
/* re-order disks if there is a bootable device */ /* re-order disks if there is a bootable device */
if (STREQ_NULLABLE(bootable, "1")) { if (STREQ_NULLABLE(bootable, "1")) {
...@@ -513,9 +512,6 @@ xenParseSxprDisks(virDomainDefPtr def, ...@@ -513,9 +512,6 @@ xenParseSxprDisks(virDomainDefPtr def,
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
return -1; return -1;
...@@ -550,7 +546,7 @@ xenParseSxprNets(virDomainDefPtr def, ...@@ -550,7 +546,7 @@ xenParseSxprNets(virDomainDefPtr def,
type = sexpr_node(node, "device/vif/type"); type = sexpr_node(node, "device/vif/type");
if (VIR_ALLOC(net) < 0) if (VIR_ALLOC(net) < 0)
goto no_memory; goto cleanup;
if (tmp != NULL || if (tmp != NULL ||
(tmp2 != NULL && STREQ(tmp2, DEFAULT_VIF_SCRIPT))) { (tmp2 != NULL && STREQ(tmp2, DEFAULT_VIF_SCRIPT))) {
...@@ -583,7 +579,7 @@ xenParseSxprNets(virDomainDefPtr def, ...@@ -583,7 +579,7 @@ xenParseSxprNets(virDomainDefPtr def,
goto cleanup; goto cleanup;
} else if (def->id != -1) { } else if (def->id != -1) {
if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0) if (virAsprintf(&net->ifname, "vif%d.%d", def->id, vif_index) < 0)
goto no_memory; goto cleanup;
} }
tmp = sexpr_node(node, "device/vif/mac"); tmp = sexpr_node(node, "device/vif/mac");
...@@ -603,7 +599,7 @@ xenParseSxprNets(virDomainDefPtr def, ...@@ -603,7 +599,7 @@ xenParseSxprNets(virDomainDefPtr def,
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0) if (VIR_REALLOC_N(def->nets, def->nnets + 1) < 0)
goto no_memory; goto cleanup;
def->nets[def->nnets++] = net; def->nets[def->nnets++] = net;
vif_index++; vif_index++;
...@@ -612,8 +608,6 @@ xenParseSxprNets(virDomainDefPtr def, ...@@ -612,8 +608,6 @@ xenParseSxprNets(virDomainDefPtr def,
return 0; return 0;
no_memory:
virReportOOMError();
cleanup: cleanup:
virDomainNetDefFree(net); virDomainNetDefFree(net);
return -1; return -1;
...@@ -651,13 +645,13 @@ xenParseSxprSound(virDomainDefPtr def, ...@@ -651,13 +645,13 @@ xenParseSxprSound(virDomainDefPtr def,
if (VIR_ALLOC_N(def->sounds, if (VIR_ALLOC_N(def->sounds,
VIR_DOMAIN_SOUND_MODEL_ES1370 + 1) < 0) VIR_DOMAIN_SOUND_MODEL_ES1370 + 1) < 0)
goto no_memory; goto error;
for (i = 0; i < (VIR_DOMAIN_SOUND_MODEL_ES1370 + 1); i++) { for (i = 0; i < (VIR_DOMAIN_SOUND_MODEL_ES1370 + 1); i++) {
virDomainSoundDefPtr sound; virDomainSoundDefPtr sound;
if (VIR_ALLOC(sound) < 0) if (VIR_ALLOC(sound) < 0)
goto no_memory; goto error;
sound->model = i; sound->model = i;
def->sounds[def->nsounds++] = sound; def->sounds[def->nsounds++] = sound;
} }
...@@ -681,7 +675,7 @@ xenParseSxprSound(virDomainDefPtr def, ...@@ -681,7 +675,7 @@ xenParseSxprSound(virDomainDefPtr def,
} }
if (VIR_ALLOC(sound) < 0) if (VIR_ALLOC(sound) < 0)
goto no_memory; goto error;
if ((sound->model = virDomainSoundModelTypeFromString(model)) < 0) { if ((sound->model = virDomainSoundModelTypeFromString(model)) < 0) {
VIR_FREE(sound); VIR_FREE(sound);
...@@ -690,7 +684,7 @@ xenParseSxprSound(virDomainDefPtr def, ...@@ -690,7 +684,7 @@ xenParseSxprSound(virDomainDefPtr def,
if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) { if (VIR_REALLOC_N(def->sounds, def->nsounds+1) < 0) {
virDomainSoundDefFree(sound); virDomainSoundDefFree(sound);
goto no_memory; goto error;
} }
def->sounds[def->nsounds++] = sound; def->sounds[def->nsounds++] = sound;
...@@ -700,8 +694,6 @@ xenParseSxprSound(virDomainDefPtr def, ...@@ -700,8 +694,6 @@ xenParseSxprSound(virDomainDefPtr def,
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
return -1; return -1;
} }
...@@ -732,7 +724,7 @@ xenParseSxprUSB(virDomainDefPtr def, ...@@ -732,7 +724,7 @@ xenParseSxprUSB(virDomainDefPtr def,
STREQ(tmp, "mouse")) { STREQ(tmp, "mouse")) {
virDomainInputDefPtr input; virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0) if (VIR_ALLOC(input) < 0)
goto no_memory; goto error;
input->bus = VIR_DOMAIN_INPUT_BUS_USB; input->bus = VIR_DOMAIN_INPUT_BUS_USB;
if (STREQ(tmp, "tablet")) if (STREQ(tmp, "tablet"))
input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; input->type = VIR_DOMAIN_INPUT_TYPE_TABLET;
...@@ -741,7 +733,7 @@ xenParseSxprUSB(virDomainDefPtr def, ...@@ -741,7 +733,7 @@ xenParseSxprUSB(virDomainDefPtr def,
if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) { if (VIR_REALLOC_N(def->inputs, def->ninputs+1) < 0) {
VIR_FREE(input); VIR_FREE(input);
goto no_memory; goto error;
} }
def->inputs[def->ninputs++] = input; def->inputs[def->ninputs++] = input;
} else { } else {
...@@ -752,8 +744,7 @@ xenParseSxprUSB(virDomainDefPtr def, ...@@ -752,8 +744,7 @@ xenParseSxprUSB(virDomainDefPtr def,
} }
return 0; return 0;
no_memory: error:
virReportOOMError();
return -1; return -1;
} }
...@@ -791,7 +782,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, ...@@ -791,7 +782,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
port = vncport; port = vncport;
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto no_memory; goto error;
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
/* For Xen >= 3.0.3, don't generate a fixed port mapping /* For Xen >= 3.0.3, don't generate a fixed port mapping
...@@ -818,7 +809,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, ...@@ -818,7 +809,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
goto error; goto error;
if (VIR_ALLOC_N(def->graphics, 1) < 0) if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory; goto error;
def->graphics[0] = graphics; def->graphics[0] = graphics;
def->ngraphics = 1; def->ngraphics = 1;
graphics = NULL; graphics = NULL;
...@@ -829,7 +820,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, ...@@ -829,7 +820,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
const char *xauth = sexpr_fmt_node(root, "domain/image/%s/xauthority", hvm ? "hvm" : "linux"); const char *xauth = sexpr_fmt_node(root, "domain/image/%s/xauthority", hvm ? "hvm" : "linux");
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto no_memory; goto error;
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
if (VIR_STRDUP(graphics->data.sdl.display, display) < 0) if (VIR_STRDUP(graphics->data.sdl.display, display) < 0)
...@@ -838,7 +829,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, ...@@ -838,7 +829,7 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
goto error; goto error;
if (VIR_ALLOC_N(def->graphics, 1) < 0) if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory; goto error;
def->graphics[0] = graphics; def->graphics[0] = graphics;
def->ngraphics = 1; def->ngraphics = 1;
graphics = NULL; graphics = NULL;
...@@ -846,8 +837,6 @@ xenParseSxprGraphicsOld(virDomainDefPtr def, ...@@ -846,8 +837,6 @@ xenParseSxprGraphicsOld(virDomainDefPtr def,
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virDomainGraphicsDefFree(graphics); virDomainGraphicsDefFree(graphics);
return -1; return -1;
...@@ -889,7 +878,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, ...@@ -889,7 +878,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
} }
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto no_memory; goto error;
if ((graphics->type = virDomainGraphicsTypeFromString(tmp)) < 0) { if ((graphics->type = virDomainGraphicsTypeFromString(tmp)) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -940,7 +929,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, ...@@ -940,7 +929,7 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
} }
if (VIR_ALLOC_N(def->graphics, 1) < 0) if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory; goto error;
def->graphics[0] = graphics; def->graphics[0] = graphics;
def->ngraphics = 1; def->ngraphics = 1;
graphics = NULL; graphics = NULL;
...@@ -950,8 +939,6 @@ xenParseSxprGraphicsNew(virDomainDefPtr def, ...@@ -950,8 +939,6 @@ xenParseSxprGraphicsNew(virDomainDefPtr def,
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virDomainGraphicsDefFree(graphics); virDomainGraphicsDefFree(graphics);
return -1; return -1;
...@@ -1067,7 +1054,7 @@ xenParseSxprPCI(virDomainDefPtr def, ...@@ -1067,7 +1054,7 @@ xenParseSxprPCI(virDomainDefPtr def,
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) { if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
virDomainHostdevDefFree(dev); virDomainHostdevDefFree(dev);
goto no_memory; goto error;
} }
def->hostdevs[def->nhostdevs++] = dev; def->hostdevs[def->nhostdevs++] = dev;
...@@ -1075,9 +1062,6 @@ xenParseSxprPCI(virDomainDefPtr def, ...@@ -1075,9 +1062,6 @@ xenParseSxprPCI(virDomainDefPtr def,
return 0; return 0;
no_memory:
virReportOOMError();
error: error:
virDomainHostdevDefFree(dev); virDomainHostdevDefFree(dev);
return -1; return -1;
...@@ -1108,7 +1092,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1108,7 +1092,7 @@ xenParseSxpr(const struct sexpr *root,
int hvm = 0, vmlocaltime; int hvm = 0, vmlocaltime;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
goto no_memory; goto error;
tmp = sexpr_node(root, "domain/domid"); tmp = sexpr_node(root, "domain/domid");
if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */ if (tmp == NULL && xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { /* domid was mandatory */
...@@ -1123,7 +1107,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1123,7 +1107,7 @@ xenParseSxpr(const struct sexpr *root,
def->id = -1; def->id = -1;
if (sexpr_node_copy(root, "domain/name", &def->name) < 0) if (sexpr_node_copy(root, "domain/name", &def->name) < 0)
goto no_memory; goto error;
if (def->name == NULL) { if (def->name == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
"%s", _("domain information incomplete, missing name")); "%s", _("domain information incomplete, missing name"));
...@@ -1140,13 +1124,13 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1140,13 +1124,13 @@ xenParseSxpr(const struct sexpr *root,
goto error; goto error;
if (sexpr_node_copy(root, "domain/description", &def->description) < 0) if (sexpr_node_copy(root, "domain/description", &def->description) < 0)
goto no_memory; goto error;
hvm = sexpr_lookup(root, "domain/image/hvm") ? 1 : 0; hvm = sexpr_lookup(root, "domain/image/hvm") ? 1 : 0;
if (!hvm) { if (!hvm) {
if (sexpr_node_copy(root, "domain/bootloader", if (sexpr_node_copy(root, "domain/bootloader",
&def->os.bootloader) < 0) &def->os.bootloader) < 0)
goto no_memory; goto error;
if (!def->os.bootloader && if (!def->os.bootloader &&
sexpr_has(root, "domain/bootloader") && sexpr_has(root, "domain/bootloader") &&
...@@ -1156,7 +1140,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1156,7 +1140,7 @@ xenParseSxpr(const struct sexpr *root,
if (def->os.bootloader && if (def->os.bootloader &&
sexpr_node_copy(root, "domain/bootloader_args", sexpr_node_copy(root, "domain/bootloader_args",
&def->os.bootloaderArgs) < 0) &def->os.bootloaderArgs) < 0)
goto no_memory; goto error;
} }
if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0) if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0)
...@@ -1263,10 +1247,8 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1263,10 +1247,8 @@ xenParseSxpr(const struct sexpr *root,
virDomainTimerDefPtr timer; virDomainTimerDefPtr timer;
if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || if (VIR_ALLOC_N(def->clock.timers, 1) < 0 ||
VIR_ALLOC(timer) < 0) { VIR_ALLOC(timer) < 0)
virReportOOMError();
goto error; goto error;
}
timer->name = VIR_DOMAIN_TIMER_NAME_HPET; timer->name = VIR_DOMAIN_TIMER_NAME_HPET;
timer->present = sexpr_int(root, "domain/image/hvm/hpet"); timer->present = sexpr_int(root, "domain/image/hvm/hpet");
...@@ -1296,7 +1278,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1296,7 +1278,7 @@ xenParseSxpr(const struct sexpr *root,
"domain/image/hvm/device_model" : "domain/image/hvm/device_model" :
"domain/image/linux/device_model", "domain/image/linux/device_model",
&def->emulator) < 0) &def->emulator) < 0)
goto no_memory; goto error;
/* append block devices */ /* append block devices */
if (xenParseSxprDisks(def, root, hvm, xendConfigVersion) < 0) if (xenParseSxprDisks(def, root, hvm, xendConfigVersion) < 0)
...@@ -1326,7 +1308,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1326,7 +1308,7 @@ xenParseSxpr(const struct sexpr *root,
if ((tmp != NULL) && (tmp[0] != 0)) { if ((tmp != NULL) && (tmp[0] != 0)) {
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto error;
if (VIR_STRDUP(disk->src, tmp) < 0) { if (VIR_STRDUP(disk->src, tmp) < 0) {
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
goto error; goto error;
...@@ -1346,7 +1328,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1346,7 +1328,7 @@ xenParseSxpr(const struct sexpr *root,
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
goto no_memory; goto error;
} }
def->disks[def->ndisks++] = disk; def->disks[def->ndisks++] = disk;
} }
...@@ -1362,7 +1344,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1362,7 +1344,7 @@ xenParseSxpr(const struct sexpr *root,
if ((tmp != NULL) && (tmp[0] != 0)) { if ((tmp != NULL) && (tmp[0] != 0)) {
virDomainDiskDefPtr disk; virDomainDiskDefPtr disk;
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto error;
if (VIR_STRDUP(disk->src, tmp) < 0) { if (VIR_STRDUP(disk->src, tmp) < 0) {
VIR_FREE(disk); VIR_FREE(disk);
goto error; goto error;
...@@ -1381,7 +1363,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1381,7 +1363,7 @@ xenParseSxpr(const struct sexpr *root,
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) { if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) {
virDomainDiskDefFree(disk); virDomainDiskDefFree(disk);
goto no_memory; goto error;
} }
def->disks[def->ndisks++] = disk; def->disks[def->ndisks++] = disk;
} }
...@@ -1415,7 +1397,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1415,7 +1397,7 @@ xenParseSxpr(const struct sexpr *root,
goto error; goto error;
if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) { if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) {
virDomainChrDefFree(chr); virDomainChrDefFree(chr);
goto no_memory; goto error;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
chr->target.port = def->nserials + ports_skipped; chr->target.port = def->nserials + ports_skipped;
...@@ -1437,7 +1419,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1437,7 +1419,7 @@ xenParseSxpr(const struct sexpr *root,
goto error; goto error;
if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) { if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) {
virDomainChrDefFree(chr); virDomainChrDefFree(chr);
goto no_memory; goto error;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
chr->target.port = 0; chr->target.port = 0;
...@@ -1453,7 +1435,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1453,7 +1435,7 @@ xenParseSxpr(const struct sexpr *root,
goto error; goto error;
if (VIR_REALLOC_N(def->parallels, def->nparallels+1) < 0) { if (VIR_REALLOC_N(def->parallels, def->nparallels+1) < 0) {
virDomainChrDefFree(chr); virDomainChrDefFree(chr);
goto no_memory; goto error;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
chr->target.port = 0; chr->target.port = 0;
...@@ -1462,7 +1444,7 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1462,7 +1444,7 @@ xenParseSxpr(const struct sexpr *root,
} else if (def->id != 0) { } else if (def->id != 0) {
def->nconsoles = 1; def->nconsoles = 1;
if (VIR_ALLOC_N(def->consoles, 1) < 0) if (VIR_ALLOC_N(def->consoles, 1) < 0)
goto no_memory; goto error;
/* Fake a paravirt console, since that's not in the sexpr */ /* Fake a paravirt console, since that's not in the sexpr */
if (!(def->consoles[0] = xenParseSxprChar("pty", tty))) if (!(def->consoles[0] = xenParseSxprChar("pty", tty)))
goto error; goto error;
...@@ -1483,8 +1465,6 @@ xenParseSxpr(const struct sexpr *root, ...@@ -1483,8 +1465,6 @@ xenParseSxpr(const struct sexpr *root,
return def; return def;
no_memory:
virReportOOMError();
error: error:
VIR_FREE(tty); VIR_FREE(tty);
virDomainDefFree(def); virDomainDefFree(def);
......
...@@ -265,10 +265,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -265,10 +265,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
char *script = NULL; char *script = NULL;
char *listenAddr = NULL; char *listenAddr = NULL;
if (VIR_ALLOC(def) < 0) { if (VIR_ALLOC(def) < 0)
virReportOOMError();
return NULL; return NULL;
}
def->virtType = VIR_DOMAIN_VIRT_XEN; def->virtType = VIR_DOMAIN_VIRT_XEN;
def->id = -1; def->id = -1;
...@@ -424,10 +422,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -424,10 +422,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
virDomainTimerDefPtr timer; virDomainTimerDefPtr timer;
if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || if (VIR_ALLOC_N(def->clock.timers, 1) < 0 ||
VIR_ALLOC(timer) < 0) { VIR_ALLOC(timer) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
timer->name = VIR_DOMAIN_TIMER_NAME_HPET; timer->name = VIR_DOMAIN_TIMER_NAME_HPET;
timer->present = val; timer->present = val;
...@@ -482,7 +478,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -482,7 +478,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
head = list->str; head = list->str;
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto cleanup;
/* /*
* Disks have 3 components, SOURCE,DEST-DEVICE,MODE * Disks have 3 components, SOURCE,DEST-DEVICE,MODE
...@@ -500,7 +496,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -500,7 +496,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
disk->src = NULL; /* No source file given, eg CDROM with no media */ disk->src = NULL; /* No source file given, eg CDROM with no media */
} else { } else {
if (VIR_ALLOC_N(disk->src, (offset - head) + 1) < 0) if (VIR_ALLOC_N(disk->src, (offset - head) + 1) < 0)
goto no_memory; goto cleanup;
if (virStrncpy(disk->src, head, offset - head, if (virStrncpy(disk->src, head, offset - head,
(offset - head) + 1) == NULL) { (offset - head) + 1) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -519,7 +515,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -519,7 +515,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (!(offset = strchr(head, ','))) if (!(offset = strchr(head, ',')))
goto skipdisk; goto skipdisk;
if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0)
goto no_memory; goto cleanup;
if (virStrncpy(disk->dst, head, offset - head, if (virStrncpy(disk->dst, head, offset - head,
(offset - head) + 1) == NULL) { (offset - head) + 1) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
...@@ -534,7 +530,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -534,7 +530,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
/* The main type phy:, file:, tap: ... */ /* The main type phy:, file:, tap: ... */
if ((tmp = strchr(disk->src, ':')) != NULL) { if ((tmp = strchr(disk->src, ':')) != NULL) {
if (VIR_ALLOC_N(disk->driverName, (tmp - disk->src) + 1) < 0) if (VIR_ALLOC_N(disk->driverName, (tmp - disk->src) + 1) < 0)
goto no_memory; goto cleanup;
if (virStrncpy(disk->driverName, disk->src, if (virStrncpy(disk->driverName, disk->src,
(tmp - disk->src), (tmp - disk->src),
(tmp - disk->src) + 1) == NULL) { (tmp - disk->src) + 1) == NULL) {
...@@ -613,7 +609,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -613,7 +609,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
/* Maintain list in sorted order according to target device name */ /* Maintain list in sorted order according to target device name */
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
goto no_memory; goto cleanup;
def->disks[def->ndisks++] = disk; def->disks[def->ndisks++] = disk;
disk = NULL; disk = NULL;
...@@ -628,7 +624,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -628,7 +624,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup; goto cleanup;
if (str) { if (str) {
if (VIR_ALLOC(disk) < 0) if (VIR_ALLOC(disk) < 0)
goto no_memory; goto cleanup;
disk->type = VIR_DOMAIN_DISK_TYPE_FILE; disk->type = VIR_DOMAIN_DISK_TYPE_FILE;
disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
...@@ -642,7 +638,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -642,7 +638,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
disk->readonly = true; disk->readonly = true;
if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0) if (VIR_REALLOC_N(def->disks, def->ndisks+1) < 0)
goto no_memory; goto cleanup;
def->disks[def->ndisks++] = disk; def->disks[def->ndisks++] = disk;
disk = NULL; disk = NULL;
} }
...@@ -739,7 +735,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -739,7 +735,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
} }
if (VIR_ALLOC(net) < 0) if (VIR_ALLOC(net) < 0)
goto no_memory; goto cleanup;
if (mac[0]) { if (mac[0]) {
if (virMacAddrParse(mac, &net->mac) < 0) { if (virMacAddrParse(mac, &net->mac) < 0) {
...@@ -772,7 +768,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -772,7 +768,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (model[0] && if (model[0] &&
VIR_STRDUP(net->model, model) < 0) VIR_STRDUP(net->model, model) < 0)
goto no_memory; goto cleanup;
if (!model[0] && type[0] && STREQ(type, "netfront") && if (!model[0] && type[0] && STREQ(type, "netfront") &&
VIR_STRDUP(net->model, "netfront") < 0) VIR_STRDUP(net->model, "netfront") < 0)
...@@ -783,7 +779,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -783,7 +779,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0) if (VIR_REALLOC_N(def->nets, def->nnets+1) < 0)
goto no_memory; goto cleanup;
def->nets[def->nnets++] = net; def->nets[def->nnets++] = net;
net = NULL; net = NULL;
...@@ -875,7 +871,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -875,7 +871,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) { if (VIR_REALLOC_N(def->hostdevs, def->nhostdevs+1) < 0) {
virDomainHostdevDefFree(hostdev); virDomainHostdevDefFree(hostdev);
goto no_memory; goto cleanup;
} }
def->hostdevs[def->nhostdevs++] = hostdev; def->hostdevs[def->nhostdevs++] = hostdev;
hostdev = NULL; hostdev = NULL;
...@@ -893,14 +889,14 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -893,14 +889,14 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
STREQ(str, "mouse"))) { STREQ(str, "mouse"))) {
virDomainInputDefPtr input; virDomainInputDefPtr input;
if (VIR_ALLOC(input) < 0) if (VIR_ALLOC(input) < 0)
goto no_memory; goto cleanup;
input->bus = VIR_DOMAIN_INPUT_BUS_USB; input->bus = VIR_DOMAIN_INPUT_BUS_USB;
input->type = STREQ(str, "tablet") ? input->type = STREQ(str, "tablet") ?
VIR_DOMAIN_INPUT_TYPE_TABLET : VIR_DOMAIN_INPUT_TYPE_TABLET :
VIR_DOMAIN_INPUT_TYPE_MOUSE; VIR_DOMAIN_INPUT_TYPE_MOUSE;
if (VIR_ALLOC_N(def->inputs, 1) < 0) { if (VIR_ALLOC_N(def->inputs, 1) < 0) {
virDomainInputDefFree(input); virDomainInputDefFree(input);
goto no_memory; goto cleanup;
} }
def->inputs[0] = input; def->inputs[0] = input;
def->ninputs = 1; def->ninputs = 1;
...@@ -914,7 +910,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -914,7 +910,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (val) { if (val) {
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto no_memory; goto cleanup;
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC;
if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0) if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0)
goto cleanup; goto cleanup;
...@@ -942,7 +938,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -942,7 +938,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(def->graphics, 1) < 0) if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory; goto cleanup;
def->graphics[0] = graphics; def->graphics[0] = graphics;
def->ngraphics = 1; def->ngraphics = 1;
graphics = NULL; graphics = NULL;
...@@ -951,14 +947,14 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -951,14 +947,14 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup; goto cleanup;
if (val) { if (val) {
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto no_memory; goto cleanup;
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0) if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0)
goto cleanup; goto cleanup;
if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0) if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0)
goto cleanup; goto cleanup;
if (VIR_ALLOC_N(def->graphics, 1) < 0) if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory; goto cleanup;
def->graphics[0] = graphics; def->graphics[0] = graphics;
def->ngraphics = 1; def->ngraphics = 1;
graphics = NULL; graphics = NULL;
...@@ -982,7 +978,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -982,7 +978,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
} }
if (VIR_ALLOC(graphics) < 0) if (VIR_ALLOC(graphics) < 0)
goto no_memory; goto cleanup;
if (strstr(key, "type=sdl")) if (strstr(key, "type=sdl"))
graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL;
...@@ -1034,7 +1030,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1034,7 +1030,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
key = nextkey; key = nextkey;
} }
if (VIR_ALLOC_N(def->graphics, 1) < 0) if (VIR_ALLOC_N(def->graphics, 1) < 0)
goto no_memory; goto cleanup;
def->graphics[0] = graphics; def->graphics[0] = graphics;
def->ngraphics = 1; def->ngraphics = 1;
graphics = NULL; graphics = NULL;
...@@ -1053,7 +1049,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1053,7 +1049,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (chr) { if (chr) {
if (VIR_ALLOC_N(def->parallels, 1) < 0) { if (VIR_ALLOC_N(def->parallels, 1) < 0) {
virDomainChrDefFree(chr); virDomainChrDefFree(chr);
goto no_memory; goto cleanup;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL;
chr->target.port = 0; chr->target.port = 0;
...@@ -1085,7 +1081,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1085,7 +1081,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup; goto cleanup;
if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0) if (VIR_REALLOC_N(def->serials, def->nserials+1) < 0)
goto no_memory; goto cleanup;
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
chr->target.port = portnum; chr->target.port = portnum;
...@@ -1105,7 +1101,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1105,7 +1101,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (chr) { if (chr) {
if (VIR_ALLOC_N(def->serials, 1) < 0) { if (VIR_ALLOC_N(def->serials, 1) < 0) {
virDomainChrDefFree(chr); virDomainChrDefFree(chr);
goto no_memory; goto cleanup;
} }
chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL;
chr->target.port = 0; chr->target.port = 0;
...@@ -1116,7 +1112,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1116,7 +1112,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
} else { } else {
def->nconsoles = 1; def->nconsoles = 1;
if (VIR_ALLOC_N(def->consoles, 1) < 0) if (VIR_ALLOC_N(def->consoles, 1) < 0)
goto no_memory; goto cleanup;
if (!(def->consoles[0] = xenParseSxprChar("pty", NULL))) if (!(def->consoles[0] = xenParseSxprChar("pty", NULL)))
goto cleanup; goto cleanup;
def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE;
...@@ -1136,9 +1132,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1136,9 +1132,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
VIR_FREE(script); VIR_FREE(script);
return def; return def;
no_memory:
virReportOOMError();
/* fallthrough */
cleanup: cleanup:
virDomainGraphicsDefFree(graphics); virDomainGraphicsDefFree(graphics);
virDomainNetDefFree(net); virDomainNetDefFree(net);
...@@ -1159,10 +1152,8 @@ int xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l) { ...@@ -1159,10 +1152,8 @@ int xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l) {
l, setting); l, setting);
return -1; return -1;
} }
if (VIR_ALLOC(value) < 0) { if (VIR_ALLOC(value) < 0)
virReportOOMError();
return -1; return -1;
}
value->type = VIR_CONF_LONG; value->type = VIR_CONF_LONG;
value->next = NULL; value->next = NULL;
...@@ -1176,10 +1167,8 @@ static ...@@ -1176,10 +1167,8 @@ static
int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) { int xenXMConfigSetString(virConfPtr conf, const char *setting, const char *str) {
virConfValuePtr value = NULL; virConfValuePtr value = NULL;
if (VIR_ALLOC(value) < 0) { if (VIR_ALLOC(value) < 0)
virReportOOMError();
return -1; return -1;
}
value->type = VIR_CONF_STRING; value->type = VIR_CONF_STRING;
value->next = NULL; value->next = NULL;
...@@ -1253,10 +1242,8 @@ static int xenFormatXMDisk(virConfValuePtr list, ...@@ -1253,10 +1242,8 @@ static int xenFormatXMDisk(virConfValuePtr list,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC(val) < 0) { if (VIR_ALLOC(val) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
val->type = VIR_CONF_STRING; val->type = VIR_CONF_STRING;
val->str = virBufferContentAndReset(&buf); val->str = virBufferContentAndReset(&buf);
...@@ -1284,10 +1271,8 @@ static int xenFormatXMSerial(virConfValuePtr list, ...@@ -1284,10 +1271,8 @@ static int xenFormatXMSerial(virConfValuePtr list,
if (serial) { if (serial) {
ret = xenFormatSxprChr(serial, &buf); ret = xenFormatSxprChr(serial, &buf);
if (ret < 0) { if (ret < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
} else { } else {
virBufferAddLit(&buf, "none"); virBufferAddLit(&buf, "none");
} }
...@@ -1296,10 +1281,8 @@ static int xenFormatXMSerial(virConfValuePtr list, ...@@ -1296,10 +1281,8 @@ static int xenFormatXMSerial(virConfValuePtr list,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC(val) < 0) { if (VIR_ALLOC(val) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
val->type = VIR_CONF_STRING; val->type = VIR_CONF_STRING;
val->str = virBufferContentAndReset(&buf); val->str = virBufferContentAndReset(&buf);
...@@ -1404,10 +1387,8 @@ static int xenFormatXMNet(virConnectPtr conn, ...@@ -1404,10 +1387,8 @@ static int xenFormatXMNet(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (VIR_ALLOC(val) < 0) { if (VIR_ALLOC(val) < 0)
virReportOOMError();
goto cleanup; goto cleanup;
}
val->type = VIR_CONF_STRING; val->type = VIR_CONF_STRING;
val->str = virBufferContentAndReset(&buf); val->str = virBufferContentAndReset(&buf);
...@@ -1445,10 +1426,8 @@ xenFormatXMPCI(virConfPtr conf, ...@@ -1445,10 +1426,8 @@ xenFormatXMPCI(virConfPtr conf,
if (!hasPCI) if (!hasPCI)
return 0; return 0;
if (VIR_ALLOC(pciVal) < 0) { if (VIR_ALLOC(pciVal) < 0)
virReportOOMError();
return -1; return -1;
}
pciVal->type = VIR_CONF_LIST; pciVal->type = VIR_CONF_LIST;
pciVal->list = NULL; pciVal->list = NULL;
...@@ -1463,14 +1442,11 @@ xenFormatXMPCI(virConfPtr conf, ...@@ -1463,14 +1442,11 @@ xenFormatXMPCI(virConfPtr conf,
def->hostdevs[i]->source.subsys.u.pci.addr.domain, def->hostdevs[i]->source.subsys.u.pci.addr.domain,
def->hostdevs[i]->source.subsys.u.pci.addr.bus, def->hostdevs[i]->source.subsys.u.pci.addr.bus,
def->hostdevs[i]->source.subsys.u.pci.addr.slot, def->hostdevs[i]->source.subsys.u.pci.addr.slot,
def->hostdevs[i]->source.subsys.u.pci.addr.function) < 0) { def->hostdevs[i]->source.subsys.u.pci.addr.function) < 0)
virReportOOMError();
goto error; goto error;
}
if (VIR_ALLOC(val) < 0) { if (VIR_ALLOC(val) < 0) {
VIR_FREE(buf); VIR_FREE(buf);
virReportOOMError();
goto error; goto error;
} }
val->type = VIR_CONF_STRING; val->type = VIR_CONF_STRING;
...@@ -1521,27 +1497,27 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1521,27 +1497,27 @@ virConfPtr xenFormatXM(virConnectPtr conn,
if (xenXMConfigSetString(conf, "name", def->name) < 0) if (xenXMConfigSetString(conf, "name", def->name) < 0)
goto no_memory; goto cleanup;
virUUIDFormat(def->uuid, uuid); virUUIDFormat(def->uuid, uuid);
if (xenXMConfigSetString(conf, "uuid", uuid) < 0) if (xenXMConfigSetString(conf, "uuid", uuid) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "maxmem", if (xenXMConfigSetInt(conf, "maxmem",
VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0) VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "memory", if (xenXMConfigSetInt(conf, "memory",
VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0) VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0) if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0)
goto no_memory; goto cleanup;
/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is
either 32, or 64 on a platform where long is big enough. */ either 32, or 64 on a platform where long is big enough. */
if (def->vcpus < def->maxvcpus && if (def->vcpus < def->maxvcpus &&
xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0) xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0)
goto no_memory; goto cleanup;
if ((def->cpumask != NULL) && if ((def->cpumask != NULL) &&
((cpus = virBitmapFormat(def->cpumask)) == NULL)) { ((cpus = virBitmapFormat(def->cpumask)) == NULL)) {
...@@ -1550,7 +1526,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1550,7 +1526,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
if (cpus && if (cpus &&
xenXMConfigSetString(conf, "cpus", cpus) < 0) xenXMConfigSetString(conf, "cpus", cpus) < 0)
goto no_memory; goto cleanup;
VIR_FREE(cpus); VIR_FREE(cpus);
hvm = STREQ(def->os.type, "hvm") ? 1 : 0; hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
...@@ -1558,11 +1534,11 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1558,11 +1534,11 @@ virConfPtr xenFormatXM(virConnectPtr conn,
if (hvm) { if (hvm) {
char boot[VIR_DOMAIN_BOOT_LAST+1]; char boot[VIR_DOMAIN_BOOT_LAST+1];
if (xenXMConfigSetString(conf, "builder", "hvm") < 0) if (xenXMConfigSetString(conf, "builder", "hvm") < 0)
goto no_memory; goto cleanup;
if (def->os.loader && if (def->os.loader &&
xenXMConfigSetString(conf, "kernel", def->os.loader) < 0) xenXMConfigSetString(conf, "kernel", def->os.loader) < 0)
goto no_memory; goto cleanup;
for (i = 0; i < def->os.nBootDevs; i++) { for (i = 0; i < def->os.nBootDevs; i++) {
switch (def->os.bootDevs[i]) { switch (def->os.bootDevs[i]) {
...@@ -1589,33 +1565,33 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1589,33 +1565,33 @@ virConfPtr xenFormatXM(virConnectPtr conn,
} }
if (xenXMConfigSetString(conf, "boot", boot) < 0) if (xenXMConfigSetString(conf, "boot", boot) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "pae", if (xenXMConfigSetInt(conf, "pae",
(def->features & (def->features &
(1 << VIR_DOMAIN_FEATURE_PAE)) ? 1 : 0) < 0) (1 << VIR_DOMAIN_FEATURE_PAE)) ? 1 : 0) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "acpi", if (xenXMConfigSetInt(conf, "acpi",
(def->features & (def->features &
(1 << VIR_DOMAIN_FEATURE_ACPI)) ? 1 : 0) < 0) (1 << VIR_DOMAIN_FEATURE_ACPI)) ? 1 : 0) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "apic", if (xenXMConfigSetInt(conf, "apic",
(def->features & (def->features &
(1 << VIR_DOMAIN_FEATURE_APIC)) ? 1 : 0) < 0) (1 << VIR_DOMAIN_FEATURE_APIC)) ? 1 : 0) < 0)
goto no_memory; goto cleanup;
if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) { if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) {
if (xenXMConfigSetInt(conf, "hap", if (xenXMConfigSetInt(conf, "hap",
(def->features & (def->features &
(1 << VIR_DOMAIN_FEATURE_HAP)) ? 1 : 0) < 0) (1 << VIR_DOMAIN_FEATURE_HAP)) ? 1 : 0) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "viridian", if (xenXMConfigSetInt(conf, "viridian",
(def->features & (def->features &
(1 << VIR_DOMAIN_FEATURE_VIRIDIAN)) ? 1 : 0) < 0) (1 << VIR_DOMAIN_FEATURE_VIRIDIAN)) ? 1 : 0) < 0)
goto no_memory; goto cleanup;
} }
for (i = 0; i < def->clock.ntimers; i++) { for (i = 0; i < def->clock.ntimers; i++) {
...@@ -1633,7 +1609,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1633,7 +1609,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
def->disks[i]->src) { def->disks[i]->src) {
if (xenXMConfigSetString(conf, "cdrom", if (xenXMConfigSetString(conf, "cdrom",
def->disks[i]->src) < 0) def->disks[i]->src) < 0)
goto no_memory; goto cleanup;
break; break;
} }
} }
...@@ -1643,19 +1619,19 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1643,19 +1619,19 @@ virConfPtr xenFormatXM(virConnectPtr conn,
} else { } else {
if (def->os.bootloader && if (def->os.bootloader &&
xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0) xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0)
goto no_memory; goto cleanup;
if (def->os.bootloaderArgs && if (def->os.bootloaderArgs &&
xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0) xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0)
goto no_memory; goto cleanup;
if (def->os.kernel && if (def->os.kernel &&
xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0) xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0)
goto no_memory; goto cleanup;
if (def->os.initrd && if (def->os.initrd &&
xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0) xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0)
goto no_memory; goto cleanup;
if (def->os.cmdline && if (def->os.cmdline &&
xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0) xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0)
goto no_memory; goto cleanup;
} /* !hvm */ } /* !hvm */
...@@ -1708,7 +1684,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1708,7 +1684,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (xenXMConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) < 0) if (xenXMConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) < 0)
goto no_memory; goto cleanup;
} else { } else {
/* >=3.1 PV: UTC and LOCALTIME */ /* >=3.1 PV: UTC and LOCALTIME */
switch (def->clock.offset) { switch (def->clock.offset) {
...@@ -1727,7 +1703,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1727,7 +1703,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
} /* !hvm */ } /* !hvm */
} }
if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0) if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0)
goto no_memory; goto cleanup;
if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) { if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) {
...@@ -1736,7 +1712,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1736,7 +1712,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0) if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0)
goto no_memory; goto cleanup;
if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) { if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) {
...@@ -1745,7 +1721,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1745,7 +1721,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0) if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0)
goto no_memory; goto cleanup;
if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) { if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) {
...@@ -1754,23 +1730,23 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1754,23 +1730,23 @@ virConfPtr xenFormatXM(virConnectPtr conn,
goto cleanup; goto cleanup;
} }
if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0) if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0)
goto no_memory; goto cleanup;
if (hvm) { if (hvm) {
if (def->emulator && if (def->emulator &&
xenXMConfigSetString(conf, "device_model", def->emulator) < 0) xenXMConfigSetString(conf, "device_model", def->emulator) < 0)
goto no_memory; goto cleanup;
for (i = 0; i < def->ninputs; i++) { for (i = 0; i < def->ninputs; i++) {
if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
if (xenXMConfigSetInt(conf, "usb", 1) < 0) if (xenXMConfigSetInt(conf, "usb", 1) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetString(conf, "usbdevice", if (xenXMConfigSetString(conf, "usbdevice",
def->inputs[i]->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ? def->inputs[i]->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ?
"mouse" : "tablet") < 0) "mouse" : "tablet") < 0)
goto no_memory; goto cleanup;
break; break;
} }
} }
...@@ -1780,43 +1756,43 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1780,43 +1756,43 @@ virConfPtr xenFormatXM(virConnectPtr conn,
if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) { if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) {
if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) {
if (xenXMConfigSetInt(conf, "sdl", 1) < 0) if (xenXMConfigSetInt(conf, "sdl", 1) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "vnc", 0) < 0) if (xenXMConfigSetInt(conf, "vnc", 0) < 0)
goto no_memory; goto cleanup;
if (def->graphics[0]->data.sdl.display && if (def->graphics[0]->data.sdl.display &&
xenXMConfigSetString(conf, "display", xenXMConfigSetString(conf, "display",
def->graphics[0]->data.sdl.display) < 0) def->graphics[0]->data.sdl.display) < 0)
goto no_memory; goto cleanup;
if (def->graphics[0]->data.sdl.xauth && if (def->graphics[0]->data.sdl.xauth &&
xenXMConfigSetString(conf, "xauthority", xenXMConfigSetString(conf, "xauthority",
def->graphics[0]->data.sdl.xauth) < 0) def->graphics[0]->data.sdl.xauth) < 0)
goto no_memory; goto cleanup;
} else { } else {
const char *listenAddr; const char *listenAddr;
if (xenXMConfigSetInt(conf, "sdl", 0) < 0) if (xenXMConfigSetInt(conf, "sdl", 0) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "vnc", 1) < 0) if (xenXMConfigSetInt(conf, "vnc", 1) < 0)
goto no_memory; goto cleanup;
if (xenXMConfigSetInt(conf, "vncunused", if (xenXMConfigSetInt(conf, "vncunused",
def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0) def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0)
goto no_memory; goto cleanup;
if (!def->graphics[0]->data.vnc.autoport && if (!def->graphics[0]->data.vnc.autoport &&
xenXMConfigSetInt(conf, "vncdisplay", xenXMConfigSetInt(conf, "vncdisplay",
def->graphics[0]->data.vnc.port - 5900) < 0) def->graphics[0]->data.vnc.port - 5900) < 0)
goto no_memory; goto cleanup;
listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0); listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0);
if (listenAddr && if (listenAddr &&
xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0) xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0)
goto no_memory; goto cleanup;
if (def->graphics[0]->data.vnc.auth.passwd && if (def->graphics[0]->data.vnc.auth.passwd &&
xenXMConfigSetString(conf, "vncpasswd", xenXMConfigSetString(conf, "vncpasswd",
def->graphics[0]->data.vnc.auth.passwd) < 0) def->graphics[0]->data.vnc.auth.passwd) < 0)
goto no_memory; goto cleanup;
if (def->graphics[0]->data.vnc.keymap && if (def->graphics[0]->data.vnc.keymap &&
xenXMConfigSetString(conf, "keymap", xenXMConfigSetString(conf, "keymap",
def->graphics[0]->data.vnc.keymap) < 0) def->graphics[0]->data.vnc.keymap) < 0)
goto no_memory; goto cleanup;
} }
} else { } else {
virConfValuePtr vfb, disp; virConfValuePtr vfb, disp;
...@@ -1851,20 +1827,21 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1851,20 +1827,21 @@ virConfPtr xenFormatXM(virConnectPtr conn,
} }
if (virBufferError(&buf)) { if (virBufferError(&buf)) {
virBufferFreeAndReset(&buf); virBufferFreeAndReset(&buf);
goto no_memory; virReportOOMError();
goto cleanup;
} }
vfbstr = virBufferContentAndReset(&buf); vfbstr = virBufferContentAndReset(&buf);
if (VIR_ALLOC(vfb) < 0) { if (VIR_ALLOC(vfb) < 0) {
VIR_FREE(vfbstr); VIR_FREE(vfbstr);
goto no_memory; goto cleanup;
} }
if (VIR_ALLOC(disp) < 0) { if (VIR_ALLOC(disp) < 0) {
VIR_FREE(vfb); VIR_FREE(vfb);
VIR_FREE(vfbstr); VIR_FREE(vfbstr);
goto no_memory; goto cleanup;
} }
vfb->type = VIR_CONF_LIST; vfb->type = VIR_CONF_LIST;
...@@ -1873,13 +1850,13 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1873,13 +1850,13 @@ virConfPtr xenFormatXM(virConnectPtr conn,
disp->str = vfbstr; disp->str = vfbstr;
if (virConfSetValue(conf, "vfb", vfb) < 0) if (virConfSetValue(conf, "vfb", vfb) < 0)
goto no_memory; goto cleanup;
} }
} }
/* analyze of the devices */ /* analyze of the devices */
if (VIR_ALLOC(diskVal) < 0) if (VIR_ALLOC(diskVal) < 0)
goto no_memory; goto cleanup;
diskVal->type = VIR_CONF_LIST; diskVal->type = VIR_CONF_LIST;
diskVal->list = NULL; diskVal->list = NULL;
...@@ -1901,12 +1878,12 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1901,12 +1878,12 @@ virConfPtr xenFormatXM(virConnectPtr conn,
int ret = virConfSetValue(conf, "disk", diskVal); int ret = virConfSetValue(conf, "disk", diskVal);
diskVal = NULL; diskVal = NULL;
if (ret < 0) if (ret < 0)
goto no_memory; goto cleanup;
} }
VIR_FREE(diskVal); VIR_FREE(diskVal);
if (VIR_ALLOC(netVal) < 0) if (VIR_ALLOC(netVal) < 0)
goto no_memory; goto cleanup;
netVal->type = VIR_CONF_LIST; netVal->type = VIR_CONF_LIST;
netVal->list = NULL; netVal->list = NULL;
...@@ -1919,7 +1896,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1919,7 +1896,7 @@ virConfPtr xenFormatXM(virConnectPtr conn,
int ret = virConfSetValue(conf, "vif", netVal); int ret = virConfSetValue(conf, "vif", netVal);
netVal = NULL; netVal = NULL;
if (ret < 0) if (ret < 0)
goto no_memory; goto cleanup;
} }
VIR_FREE(netVal); VIR_FREE(netVal);
...@@ -1938,10 +1915,10 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1938,10 +1915,10 @@ virConfPtr xenFormatXM(virConnectPtr conn,
ret = xenXMConfigSetString(conf, "parallel", str); ret = xenXMConfigSetString(conf, "parallel", str);
VIR_FREE(str); VIR_FREE(str);
if (ret < 0) if (ret < 0)
goto no_memory; goto cleanup;
} else { } else {
if (xenXMConfigSetString(conf, "parallel", "none") < 0) if (xenXMConfigSetString(conf, "parallel", "none") < 0)
goto no_memory; goto cleanup;
} }
if (def->nserials) { if (def->nserials) {
...@@ -1956,14 +1933,14 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1956,14 +1933,14 @@ virConfPtr xenFormatXM(virConnectPtr conn,
ret = xenXMConfigSetString(conf, "serial", str); ret = xenXMConfigSetString(conf, "serial", str);
VIR_FREE(str); VIR_FREE(str);
if (ret < 0) if (ret < 0)
goto no_memory; goto cleanup;
} else { } else {
int j = 0; int j = 0;
int maxport = -1; int maxport = -1;
virConfValuePtr serialVal = NULL; virConfValuePtr serialVal = NULL;
if (VIR_ALLOC(serialVal) < 0) if (VIR_ALLOC(serialVal) < 0)
goto no_memory; goto cleanup;
serialVal->type = VIR_CONF_LIST; serialVal->type = VIR_CONF_LIST;
serialVal->list = NULL; serialVal->list = NULL;
...@@ -1987,13 +1964,13 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -1987,13 +1964,13 @@ virConfPtr xenFormatXM(virConnectPtr conn,
int ret = virConfSetValue(conf, "serial", serialVal); int ret = virConfSetValue(conf, "serial", serialVal);
serialVal = NULL; serialVal = NULL;
if (ret < 0) if (ret < 0)
goto no_memory; goto cleanup;
} }
VIR_FREE(serialVal); VIR_FREE(serialVal);
} }
} else { } else {
if (xenXMConfigSetString(conf, "serial", "none") < 0) if (xenXMConfigSetString(conf, "serial", "none") < 0)
goto no_memory; goto cleanup;
} }
...@@ -2007,15 +1984,12 @@ virConfPtr xenFormatXM(virConnectPtr conn, ...@@ -2007,15 +1984,12 @@ virConfPtr xenFormatXM(virConnectPtr conn,
VIR_FREE(str); VIR_FREE(str);
if (ret < 0) if (ret < 0)
goto no_memory; goto cleanup;
} }
} }
return conf; return conf;
no_memory:
virReportOOMError();
cleanup: cleanup:
virConfFreeValue(diskVal); virConfFreeValue(diskVal);
virConfFreeValue(netVal); virConfFreeValue(netVal);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册