static int xenParseCmdline(virConfPtr conf, char **r_cmdline) { char *cmdline = NULL; const char *root, *extra, *buf; if (xenConfigGetString(conf, "cmdline", &buf, NULL) < 0) return -1; if (xenConfigGetString(conf, "root", &root, NULL) < 0) return -1; if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) return -1; if (buf) { if (VIR_STRDUP(cmdline, buf) < 0) return -1; if (root || extra) VIR_WARN("ignoring root= and extra= in favour of cmdline="); } else { if (root && extra) { if (virAsprintf(&cmdline, "root=%s %s", root, extra) < 0) return -1; } else if (root) { if (virAsprintf(&cmdline, "root=%s", root) < 0) return -1; } else if (extra) { if (VIR_STRDUP(cmdline, extra) < 0) return -1; } } *r_cmdline = cmdline; return 0; }
static int xenParseXMInputDevs(virConfPtr conf, virDomainDefPtr def) { const char *str; if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { if (xenConfigGetString(conf, "usbdevice", &str, NULL) < 0) return -1; if (str && (STREQ(str, "tablet") || STREQ(str, "mouse") || STREQ(str, "keyboard"))) { virDomainInputDefPtr input; if (VIR_ALLOC(input) < 0) return -1; input->bus = VIR_DOMAIN_INPUT_BUS_USB; if (STREQ(str, "mouse")) input->type = VIR_DOMAIN_INPUT_TYPE_MOUSE; else if (STREQ(str, "tablet")) input->type = VIR_DOMAIN_INPUT_TYPE_TABLET; else if (STREQ(str, "keyboard")) input->type = VIR_DOMAIN_INPUT_TYPE_KBD; if (VIR_APPEND_ELEMENT(def->inputs, def->ninputs, input) < 0) { virDomainInputDefFree(input); return -1; } } } return 0; }
static int xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) { size_t i; if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { const char *bios; const char *boot; if (xenConfigGetString(conf, "bios", &bios, NULL) < 0) return -1; if (bios && STREQ(bios, "ovmf")) { if (VIR_ALLOC(def->os.loader) < 0) return -1; def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_PFLASH; def->os.loader->readonly = VIR_TRISTATE_BOOL_YES; if (VIR_STRDUP(def->os.loader->path, LIBXL_FIRMWARE_DIR "/ovmf.bin") < 0) return -1; } else { for (i = 0; i < caps->nguests; i++) { if (caps->guests[i]->ostype == VIR_DOMAIN_OSTYPE_HVM && caps->guests[i]->arch.id == def->os.arch) { if (VIR_ALLOC(def->os.loader) < 0 || VIR_STRDUP(def->os.loader->path, caps->guests[i]->arch.defaultInfo.loader) < 0) return -1; } } } #ifdef LIBXL_HAVE_BUILDINFO_KERNEL if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) return -1; if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; if (xenParseCmdline(conf, &def->os.cmdline) < 0) return -1; #endif if (xenConfigGetString(conf, "boot", &boot, "c") < 0) return -1; for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) { switch (boot[i]) { 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 { if (xenConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0) return -1; if (xenConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0) return -1; if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) return -1; if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; if (xenParseCmdline(conf, &def->os.cmdline) < 0) return -1; } return 0; }
static int xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps) { size_t i; const char *extra, *root; if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { const char *boot; for (i = 0; i < caps->nguests; i++) { if (caps->guests[i]->ostype == VIR_DOMAIN_OSTYPE_HVM && caps->guests[i]->arch.id == def->os.arch) { if (VIR_ALLOC(def->os.loader) < 0 || VIR_STRDUP(def->os.loader->path, caps->guests[i]->arch.defaultInfo.loader) < 0) return -1; } } #ifdef LIBXL_HAVE_BUILDINFO_KERNEL if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) return -1; if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) return -1; if (xenConfigGetString(conf, "root", &root, NULL) < 0) return -1; if (root) { if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) return -1; } else { if (VIR_STRDUP(def->os.cmdline, extra) < 0) return -1; } #endif if (xenConfigGetString(conf, "boot", &boot, "c") < 0) return -1; for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) { switch (boot[i]) { 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 { if (xenConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0) return -1; if (xenConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0) return -1; if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) return -1; if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) return -1; if (xenConfigGetString(conf, "root", &root, NULL) < 0) return -1; if (root) { if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) return -1; } else { if (VIR_STRDUP(def->os.cmdline, extra) < 0) return -1; } } return 0; }
static int xenParseXMOS(virConfPtr conf, virDomainDefPtr def) { size_t i; if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) { const char *boot; if (VIR_ALLOC(def->os.loader) < 0 || xenConfigCopyString(conf, "kernel", &def->os.loader->path) < 0) return -1; if (xenConfigGetString(conf, "boot", &boot, "c") < 0) return -1; for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) { switch (boot[i]) { 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 (xenConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0) return -1; if (xenConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0) return -1; if (xenConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) return -1; if (xenConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) return -1; if (xenConfigGetString(conf, "extra", &extra, NULL) < 0) return -1; if (xenConfigGetString(conf, "root", &root, NULL) < 0) return -1; if (root) { if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) return -1; } else { if (VIR_STRDUP(def->os.cmdline, extra) < 0) return -1; } } return 0; }