}
-#define MAX_VFB 1024
-
-/*
- * Turn a config record into a lump of XML describing the
- * domain, suitable for later feeding for virDomainCreateXML
- */
-virDomainDefPtr
-xenParseXM(virConfPtr conf, int xendConfigVersion,
- virCapsPtr caps)
+static int
+xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
{
- const char *str;
- int hvm = 0;
- int val;
- virConfValuePtr list;
- virDomainDefPtr def = NULL;
+ const char *str = NULL;
virDomainDiskDefPtr disk = NULL;
- virDomainNetDefPtr net = NULL;
- virDomainGraphicsDefPtr graphics = NULL;
- size_t i;
- const char *defaultMachine;
- char *script = NULL;
- char *listenAddr = NULL;
-
- if (VIR_ALLOC(def) < 0)
- return NULL;
-
- def->virtType = VIR_DOMAIN_VIRT_XEN;
- def->id = -1;
+ int hvm = STREQ(def->os.type, "hvm");
+ virConfValuePtr list = virConfGetValue(conf, "disk");
- if (xenXMConfigCopyString(conf, "name", &def->name) < 0)
- goto cleanup;
- if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
- goto cleanup;
-
-
- if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
- STREQ(str, "hvm"))
- hvm = 1;
-
- if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
- goto cleanup;
-
- def->os.arch =
- virCapabilitiesDefaultGuestArch(caps,
- def->os.type,
- virDomainVirtTypeToString(def->virtType));
- if (!def->os.arch) {
- virReportError(VIR_ERR_INTERNAL_ERROR,
- _("no supported architecture for os type '%s'"),
- def->os.type);
- goto cleanup;
- }
-
- defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
- def->os.type,
- def->os.arch,
- virDomainVirtTypeToString(def->virtType));
- if (defaultMachine != NULL) {
- if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
- goto cleanup;
- }
-
- if (hvm) {
- const char *boot;
- if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
- goto cleanup;
-
- if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
- goto cleanup;
-
- for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
- switch (*boot) {
- case 'a':
- def->os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
- break;
- case 'd':
- def->os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
- break;
- case 'n':
- def->os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
- break;
- case 'c':
- default:
- def->os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
- break;
- }
- def->os.nBootDevs++;
- }
- } else {
- const char *extra, *root;
-
- if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
- goto cleanup;
- if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
- goto cleanup;
-
- if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
- goto cleanup;
- if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
- goto cleanup;
- if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
- goto cleanup;
- if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
- goto cleanup;
-
- if (root) {
- if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
- goto cleanup;
- } else {
- if (VIR_STRDUP(def->os.cmdline, extra) < 0)
- goto cleanup;
- }
- }
-
- if (xenParseXMMem(conf, def) < 0)
- goto cleanup;
-
- if (xenParseXMEventsActions(conf, def) < 0)
- goto cleanup;
-
- if (xenParseXMCPUFeatures(conf, def) < 0)
- goto cleanup;
-
- if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0)
- goto cleanup;
-
- if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
- goto cleanup;
-
- list = virConfGetValue(conf, "disk");
if (list && list->type == VIR_CONF_LIST) {
list = list->list;
while (list) {
if ((list->type != VIR_CONF_STRING) || (list->str == NULL))
goto skipdisk;
- head = list->str;
+ head = list->str;
if (!(disk = virDomainDiskDefNew()))
- goto cleanup;
+ return -1;
/*
* Disks have 3 components, SOURCE,DEST-DEVICE,MODE
} else {
if (VIR_STRNDUP(tmp, head, offset - head) < 0)
goto cleanup;
+
if (virDomainDiskSetSource(disk, tmp) < 0) {
VIR_FREE(tmp);
goto cleanup;
}
VIR_FREE(tmp);
}
- head = offset + 1;
+ head = offset + 1;
/* Remove legacy ioemu: junk */
if (STRPREFIX(head, "ioemu:"))
head = head + 6;
/* Extract the dest device name */
if (!(offset = strchr(head, ',')))
goto skipdisk;
+
if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0)
goto cleanup;
+
if (virStrncpy(disk->dst, head, offset - head,
(offset - head) + 1) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Dest file %s too big for destination"), head);
goto cleanup;
}
- head = offset + 1;
+ head = offset + 1;
/* Extract source driver type */
src = virDomainDiskGetSource(disk);
if (src) {
len = tmp - src;
if (VIR_STRNDUP(tmp, src, len) < 0)
goto cleanup;
+
if (virDomainDiskSetDriver(disk, tmp) < 0) {
VIR_FREE(tmp);
goto cleanup;
/* Strip the prefix we found off the source file name */
if (virDomainDiskSetSource(disk, src + len + 1) < 0)
goto cleanup;
+
src = virDomainDiskGetSource(disk);
}
if (VIR_STRNDUP(driverType, src, len) < 0)
goto cleanup;
+
if (STREQ(driverType, "aio"))
virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW);
else
virDomainDiskSetDriver(disk, "phy") < 0)
goto cleanup;
-
/* phy: type indicates a block device */
virDomainDiskSetType(disk,
STREQ(virDomainDiskGetDriver(disk), "phy") ?
}
}
+ return 0;
+
+ cleanup:
+ virDomainDiskDefFree(disk);
+ return -1;
+}
+
+
+#define MAX_VFB 1024
+
+/*
+ * Turn a config record into a lump of XML describing the
+ * domain, suitable for later feeding for virDomainCreateXML
+ */
+virDomainDefPtr
+xenParseXM(virConfPtr conf, int xendConfigVersion,
+ virCapsPtr caps)
+{
+ const char *str;
+ int hvm = 0;
+ int val;
+ virConfValuePtr list;
+ virDomainDefPtr def = NULL;
+ virDomainNetDefPtr net = NULL;
+ virDomainGraphicsDefPtr graphics = NULL;
+ size_t i;
+ const char *defaultMachine;
+ char *script = NULL;
+ char *listenAddr = NULL;
+
+ if (VIR_ALLOC(def) < 0)
+ return NULL;
+
+ def->virtType = VIR_DOMAIN_VIRT_XEN;
+ def->id = -1;
+
+ if (xenXMConfigCopyString(conf, "name", &def->name) < 0)
+ goto cleanup;
+ if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
+ goto cleanup;
+
+
+ if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
+ STREQ(str, "hvm"))
+ hvm = 1;
+
+ if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
+ goto cleanup;
+
+ def->os.arch =
+ virCapabilitiesDefaultGuestArch(caps,
+ def->os.type,
+ virDomainVirtTypeToString(def->virtType));
+ if (!def->os.arch) {
+ virReportError(VIR_ERR_INTERNAL_ERROR,
+ _("no supported architecture for os type '%s'"),
+ def->os.type);
+ goto cleanup;
+ }
+
+ defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
+ def->os.type,
+ def->os.arch,
+ virDomainVirtTypeToString(def->virtType));
+ if (defaultMachine != NULL) {
+ if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
+ goto cleanup;
+ }
+
+ if (hvm) {
+ const char *boot;
+ if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
+ goto cleanup;
+
+ if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
+ goto cleanup;
+
+ for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
+ switch (*boot) {
+ case 'a':
+ def->os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
+ break;
+ case 'd':
+ def->os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
+ break;
+ case 'n':
+ def->os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
+ break;
+ case 'c':
+ default:
+ def->os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
+ break;
+ }
+ def->os.nBootDevs++;
+ }
+ } else {
+ const char *extra, *root;
+
+ if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
+ goto cleanup;
+ if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
+ goto cleanup;
+
+ if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
+ goto cleanup;
+ if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
+ goto cleanup;
+ if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
+ goto cleanup;
+ if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
+ goto cleanup;
+
+ if (root) {
+ if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
+ goto cleanup;
+ } else {
+ if (VIR_STRDUP(def->os.cmdline, extra) < 0)
+ goto cleanup;
+ }
+ }
+
+ if (xenParseXMMem(conf, def) < 0)
+ goto cleanup;
+
+ if (xenParseXMEventsActions(conf, def) < 0)
+ goto cleanup;
+
+ if (xenParseXMCPUFeatures(conf, def) < 0)
+ goto cleanup;
+
+ if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0)
+ goto cleanup;
+
+ if (xenParseXMDisk(conf, def, xendConfigVersion) < 0)
+ goto cleanup;
+
+ if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
+ goto cleanup;
+
list = virConfGetValue(conf, "vif");
if (list && list->type == VIR_CONF_LIST) {
list = list->list;
cleanup:
virDomainGraphicsDefFree(graphics);
virDomainNetDefFree(net);
- virDomainDiskDefFree(disk);
virDomainDefFree(def);
VIR_FREE(script);
VIR_FREE(listenAddr);