From 4821c32c94f0d01b406e257ec6c17174392cf67f Mon Sep 17 00:00:00 2001 From: Kiarie Kahurani Date: Thu, 7 Aug 2014 21:32:58 +0300 Subject: [PATCH] src/xenxs: Refactor code parsing Vif config introduce function xenParseXMVif(virConfPtr conf,........); which parses Vfb config instead Signed-off-by: Kiarie Kahurani --- src/xenxs/xen_xm.c | 272 ++++++++++++++++++++++++--------------------- 1 file changed, 143 insertions(+), 129 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 06e437515d..1de8673a49 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -946,133 +946,13 @@ xenParseXMCharDev(virConfPtr conf, virDomainDefPtr def) } -/* - * 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 +xenParseXMVif(virConfPtr conf, virDomainDefPtr def) { - const char *str; - int hvm = 0; - virConfValuePtr list; - virDomainDefPtr def = NULL; - virDomainNetDefPtr net = NULL; - size_t i; - const char *defaultMachine; char *script = NULL; + virDomainNetDefPtr net = NULL; + virConfValuePtr list = virConfGetValue(conf, "vif"); - 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; while (list) { @@ -1128,14 +1008,16 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, int len = nextkey ? (nextkey - data) : sizeof(model) - 1; if (virStrncpy(model, data, len, sizeof(model)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Model %s too big for destination"), data); + _("Model %s too big for destination"), + data); goto skipnic; } } else if (STRPREFIX(key, "type=")) { int len = nextkey ? (nextkey - data) : sizeof(type) - 1; if (virStrncpy(type, data, len, sizeof(type)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("Type %s too big for destination"), data); + _("Type %s too big for destination"), + data); goto skipnic; } } else if (STRPREFIX(key, "vifname=")) { @@ -1212,9 +1094,144 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, skipnic: list = list->next; virDomainNetDefFree(net); + VIR_FREE(script); + } + } + + return 0; + + cleanup: + VIR_FREE(script); + return -1; +} + + +/* + * 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; + virDomainDefPtr def = NULL; + size_t i; + const char *defaultMachine; + + 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; + + if (xenParseXMVif(conf, def) < 0) + goto cleanup; + if (xenParseXMPCI(conf, def) < 0) goto cleanup; @@ -1259,13 +1276,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; } - VIR_FREE(script); return def; cleanup: - virDomainNetDefFree(net); virDomainDefFree(def); - VIR_FREE(script); return NULL; } -- 2.39.5