[libvirt] [PATCH 01/24] src/xenxs: Refactor code parsing memory config

introduce function xenParseXMMem(virConfPtr conf,.........); which parses memory config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 83 +++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 4461654..443e6da 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -40,11 +40,9 @@ #include "virstoragefile.h" #include "virstring.h" -/* Convenience method to grab a long int from the config file object */ -static int xenXMConfigGetBool(virConfPtr conf, - const char *name, - int *value, - int def) +/* Convenience method to grab a int from the config file object */ +static int +xenXMConfigGetBool(virConfPtr conf, const char *name, int *value, int def) { virConfValuePtr val; @@ -67,11 +65,10 @@ static int xenXMConfigGetBool(virConfPtr conf, } -/* Convenience method to grab a int from the config file object */ -static int xenXMConfigGetULong(virConfPtr conf, - const char *name, - unsigned long *value, - unsigned long def) +/* Convenience method to grab a long int from the config file object */ +static int +xenXMConfigGetULong(virConfPtr conf, const char *name, unsigned long *value, + unsigned long def) { virConfValuePtr val; @@ -99,10 +96,9 @@ static int xenXMConfigGetULong(virConfPtr conf, /* Convenience method to grab a int from the config file object */ -static int xenXMConfigGetULongLong(virConfPtr conf, - const char *name, - unsigned long long *value, - unsigned long long def) +static int +xenXMConfigGetULongLong(virConfPtr conf, const char *name, + unsigned long long *value, unsigned long long def) { virConfValuePtr val; @@ -130,10 +126,9 @@ static int xenXMConfigGetULongLong(virConfPtr conf, /* Convenience method to grab a string from the config file object */ -static int xenXMConfigGetString(virConfPtr conf, - const char *name, - const char **value, - const char *def) +static int +xenXMConfigGetString(virConfPtr conf, const char *name, const char **value, + const char *def) { virConfValuePtr val; @@ -155,10 +150,10 @@ static int xenXMConfigGetString(virConfPtr conf, return 0; } -static int xenXMConfigCopyStringInternal(virConfPtr conf, - const char *name, - char **value, - int allowMissing) + +static int +xenXMConfigCopyStringInternal(virConfPtr conf, const char *name, char **value, + int allowMissing) { virConfValuePtr val; @@ -188,15 +183,16 @@ static int xenXMConfigCopyStringInternal(virConfPtr conf, } -static int xenXMConfigCopyString(virConfPtr conf, - const char *name, - char **value) { +static int +xenXMConfigCopyString(virConfPtr conf, const char *name, char **value) +{ return xenXMConfigCopyStringInternal(conf, name, value, 0); } -static int xenXMConfigCopyStringOpt(virConfPtr conf, - const char *name, - char **value) { + +static int +xenXMConfigCopyStringOpt(virConfPtr conf, const char *name, char **value) +{ return xenXMConfigCopyStringInternal(conf, name, value, 1); } @@ -244,6 +240,25 @@ xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) return 0; } + +static int +xenParseXMMem(virConfPtr conf, virDomainDefPtr def) +{ + if (xenXMConfigGetULongLong(conf, "memory", &def->mem.cur_balloon, + MIN_XEN_GUEST_SIZE * 2) < 0) + return -1; + + if (xenXMConfigGetULongLong(conf, "maxmem", &def->mem.max_balloon, + def->mem.cur_balloon) < 0) + return -1; + + def->mem.cur_balloon *= 1024; + def->mem.max_balloon *= 1024; + + return 0; +} + + #define MAX_VFB 1024 /* * Turn a config record into a lump of XML describing the @@ -251,7 +266,7 @@ xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) */ virDomainDefPtr xenParseXM(virConfPtr conf, int xendConfigVersion, - virCapsPtr caps) + virCapsPtr caps) { const char *str; int hvm = 0; @@ -360,17 +375,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } } - if (xenXMConfigGetULongLong(conf, "memory", &def->mem.cur_balloon, - MIN_XEN_GUEST_SIZE * 2) < 0) - goto cleanup; - - if (xenXMConfigGetULongLong(conf, "maxmem", &def->mem.max_balloon, - def->mem.cur_balloon) < 0) + if (xenParseXMMem(conf, def) < 0) goto cleanup; - def->mem.cur_balloon *= 1024; - def->mem.max_balloon *= 1024; - if (xenXMConfigGetULong(conf, "vcpus", &count, 1) < 0 || MAX_VIRT_CPUS < count) goto cleanup; -- 1.8.4.5

introduce function xenParseXMTimeOffset(virConfPtr conf,.......); which parses time offset config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 443e6da..0e0cf90 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -259,7 +259,48 @@ xenParseXMMem(virConfPtr conf, virDomainDefPtr def) } +static int +xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + int vmlocaltime; + + if (xenXMConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0) + return -1; + + if (STREQ(def->os.type, "hvm")) { + /* only managed HVM domains since 3.1.0 have persistent rtc_timeoffset */ + if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) { + if (vmlocaltime) + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; + else + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC; + def->clock.data.utc_reset = true; + } else { + unsigned long rtc_timeoffset; + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; + if (xenXMConfigGetULong(conf, "rtc_timeoffset", &rtc_timeoffset, 0) < 0) + return -1; + + def->clock.data.variable.adjustment = (int)rtc_timeoffset; + def->clock.data.variable.basis = vmlocaltime ? + VIR_DOMAIN_CLOCK_BASIS_LOCALTIME : + VIR_DOMAIN_CLOCK_BASIS_UTC; + } + } else { + /* PV domains do not have an emulated RTC and the offset is fixed. */ + def->clock.offset = vmlocaltime ? + VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME : + VIR_DOMAIN_CLOCK_OFFSET_UTC; + def->clock.data.utc_reset = true; + } /* !hvm */ + + return 0; +} + + #define MAX_VFB 1024 + /* * Turn a config record into a lump of XML describing the * domain, suitable for later feeding for virDomainCreateXML @@ -279,7 +320,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainHostdevDefPtr hostdev = NULL; size_t i; const char *defaultMachine; - int vmlocaltime = 0; unsigned long count; char *script = NULL; char *listenAddr = NULL; @@ -456,34 +496,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, def->clock.timers[0] = timer; } } - if (xenXMConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0) - goto cleanup; - if (hvm) { - /* only managed HVM domains since 3.1.0 have persistent rtc_timeoffset */ - if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) { - if (vmlocaltime) - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; - else - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC; - def->clock.data.utc_reset = true; - } else { - unsigned long rtc_timeoffset; - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; - if (xenXMConfigGetULong(conf, "rtc_timeoffset", &rtc_timeoffset, 0) < 0) - goto cleanup; - def->clock.data.variable.adjustment = (int)rtc_timeoffset; - def->clock.data.variable.basis = vmlocaltime ? - VIR_DOMAIN_CLOCK_BASIS_LOCALTIME : - VIR_DOMAIN_CLOCK_BASIS_UTC; - } - } else { - /* PV domains do not have an emulated RTC and the offset is fixed. */ - def->clock.offset = vmlocaltime ? - VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME : - VIR_DOMAIN_CLOCK_OFFSET_UTC; - def->clock.data.utc_reset = true; - } /* !hvm */ + if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0) + goto cleanup; if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) goto cleanup; -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMTimeOffset(virConfPtr conf,.......); which parses time offset config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 71 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 43 insertions(+), 28 deletions(-)
ACK. Will push shortly after removing the first SOB. Regards, Jim
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 443e6da..0e0cf90 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -259,7 +259,48 @@ xenParseXMMem(virConfPtr conf, virDomainDefPtr def) }
+static int +xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + int vmlocaltime; + + if (xenXMConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0) + return -1; + + if (STREQ(def->os.type, "hvm")) { + /* only managed HVM domains since 3.1.0 have persistent rtc_timeoffset */ + if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) { + if (vmlocaltime) + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; + else + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC; + def->clock.data.utc_reset = true; + } else { + unsigned long rtc_timeoffset; + def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; + if (xenXMConfigGetULong(conf, "rtc_timeoffset", &rtc_timeoffset, 0) < 0) + return -1; + + def->clock.data.variable.adjustment = (int)rtc_timeoffset; + def->clock.data.variable.basis = vmlocaltime ? + VIR_DOMAIN_CLOCK_BASIS_LOCALTIME : + VIR_DOMAIN_CLOCK_BASIS_UTC; + } + } else { + /* PV domains do not have an emulated RTC and the offset is fixed. */ + def->clock.offset = vmlocaltime ? + VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME : + VIR_DOMAIN_CLOCK_OFFSET_UTC; + def->clock.data.utc_reset = true; + } /* !hvm */ + + return 0; +} + + #define MAX_VFB 1024 + /* * Turn a config record into a lump of XML describing the * domain, suitable for later feeding for virDomainCreateXML @@ -279,7 +320,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainHostdevDefPtr hostdev = NULL; size_t i; const char *defaultMachine; - int vmlocaltime = 0; unsigned long count; char *script = NULL; char *listenAddr = NULL; @@ -456,34 +496,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, def->clock.timers[0] = timer; } } - if (xenXMConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0) - goto cleanup;
- if (hvm) { - /* only managed HVM domains since 3.1.0 have persistent rtc_timeoffset */ - if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) { - if (vmlocaltime) - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME; - else - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_UTC; - def->clock.data.utc_reset = true; - } else { - unsigned long rtc_timeoffset; - def->clock.offset = VIR_DOMAIN_CLOCK_OFFSET_VARIABLE; - if (xenXMConfigGetULong(conf, "rtc_timeoffset", &rtc_timeoffset, 0) < 0) - goto cleanup; - def->clock.data.variable.adjustment = (int)rtc_timeoffset; - def->clock.data.variable.basis = vmlocaltime ? - VIR_DOMAIN_CLOCK_BASIS_LOCALTIME : - VIR_DOMAIN_CLOCK_BASIS_UTC; - } - } else { - /* PV domains do not have an emulated RTC and the offset is fixed. */ - def->clock.offset = vmlocaltime ? - VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME : - VIR_DOMAIN_CLOCK_OFFSET_UTC; - def->clock.data.utc_reset = true; - } /* !hvm */ + if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0) + goto cleanup;
if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) goto cleanup;

introduce function xenParseXMEventActions(virConfPtr conf,........) which parses events leading to certain actions signed-off-by: Kiarie Kahurani <davidkiarie@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 61 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 0e0cf90..ecc8f52 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -299,6 +299,42 @@ xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr def, } +static int +xenParseXMEventsActions(virConfPtr conf, virDomainDefPtr def) +{ + const char *str = NULL; + + if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0) + return -1; + + if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value %s for on_poweroff"), str); + return -1; + } + + if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0) + return -1; + + if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value %s for on_reboot"), str); + return -1; + } + + if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0) + return -1; + + if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value %s for on_crash"), str); + return -1; + } + + return 0; +} + + #define MAX_VFB 1024 /* @@ -431,31 +467,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0)) goto cleanup; - if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0) + if (xenParseXMEventsActions(conf, def) < 0) goto cleanup; - if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_poweroff"), str); - goto cleanup; - } - - if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0) - goto cleanup; - if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_reboot"), str); - goto cleanup; - } - - if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0) - goto cleanup; - if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_crash"), str); - goto cleanup; - } - - if (hvm) { if (xenXMConfigGetBool(conf, "pae", &val, 0) < 0) -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMEventActions(virConfPtr conf,........) which parses events leading to certain actions
signed-off-by: Kiarie Kahurani <davidkiarie@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 61 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-)
ACK. Will push after removing the first SOB. Regards, Jim
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 0e0cf90..ecc8f52 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -299,6 +299,42 @@ xenParseXMTimeOffset(virConfPtr conf, virDomainDefPtr def, }
+static int +xenParseXMEventsActions(virConfPtr conf, virDomainDefPtr def) +{ + const char *str = NULL; + + if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0) + return -1; + + if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value %s for on_poweroff"), str); + return -1; + } + + if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0) + return -1; + + if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value %s for on_reboot"), str); + return -1; + } + + if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0) + return -1; + + if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected value %s for on_crash"), str); + return -1; + } + + return 0; +} + + #define MAX_VFB 1024
/* @@ -431,31 +467,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0)) goto cleanup;
- if (xenXMConfigGetString(conf, "on_poweroff", &str, "destroy") < 0) + if (xenParseXMEventsActions(conf, def) < 0) goto cleanup; - if ((def->onPoweroff = virDomainLifecycleTypeFromString(str)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_poweroff"), str); - goto cleanup; - } - - if (xenXMConfigGetString(conf, "on_reboot", &str, "restart") < 0) - goto cleanup; - if ((def->onReboot = virDomainLifecycleTypeFromString(str)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_reboot"), str); - goto cleanup; - } - - if (xenXMConfigGetString(conf, "on_crash", &str, "restart") < 0) - goto cleanup; - if ((def->onCrash = virDomainLifecycleCrashTypeFromString(str)) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected value %s for on_crash"), str); - goto cleanup; - } - -
if (hvm) { if (xenXMConfigGetBool(conf, "pae", &val, 0) < 0)

introduce function xenParseXMPCI(virConfPtr conf, ........); which parses PCI config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 185 +++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 90 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index ecc8f52..8cc892b 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -335,6 +335,99 @@ xenParseXMEventsActions(virConfPtr conf, virDomainDefPtr def) } +static int +xenParseXMPCI(virConfPtr conf, virDomainDefPtr def) +{ + virConfValuePtr list = virConfGetValue(conf, "pci"); + virDomainHostdevDefPtr hostdev = NULL; + + if (list && list->type == VIR_CONF_LIST) { + list = list->list; + while (list) { + char domain[5]; + char bus[3]; + char slot[3]; + char func[2]; + char *key, *nextkey; + int domainID; + int busID; + int slotID; + int funcID; + + domain[0] = bus[0] = slot[0] = func[0] = '\0'; + + if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) + goto skippci; + /* pci=['0000:00:1b.0','0000:00:13.0'] */ + if (!(key = list->str)) + goto skippci; + if (!(nextkey = strchr(key, ':'))) + goto skippci; + if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Domain %s too big for destination"), key); + goto skippci; + } + + key = nextkey + 1; + if (!(nextkey = strchr(key, ':'))) + goto skippci; + if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Bus %s too big for destination"), key); + goto skippci; + } + + key = nextkey + 1; + if (!(nextkey = strchr(key, '.'))) + goto skippci; + if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Slot %s too big for destination"), key); + goto skippci; + } + + key = nextkey + 1; + if (strlen(key) != 1) + goto skippci; + if (virStrncpy(func, key, 1, sizeof(func)) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Function %s too big for destination"), key); + goto skippci; + } + + if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) + goto skippci; + if (virStrToLong_i(bus, NULL, 16, &busID) < 0) + goto skippci; + if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) + goto skippci; + if (virStrToLong_i(func, NULL, 16, &funcID) < 0) + goto skippci; + if (!(hostdev = virDomainHostdevDefAlloc())) + return -1; + + hostdev->managed = false; + hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; + hostdev->source.subsys.u.pci.addr.domain = domainID; + hostdev->source.subsys.u.pci.addr.bus = busID; + hostdev->source.subsys.u.pci.addr.slot = slotID; + hostdev->source.subsys.u.pci.addr.function = funcID; + + if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) { + virDomainHostdevDefFree(hostdev); + return -1; + } + + skippci: + list = list->next; + } + } + + return 0; +} + + #define MAX_VFB 1024 /* @@ -353,7 +446,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainDiskDefPtr disk = NULL; virDomainNetDefPtr net = NULL; virDomainGraphicsDefPtr graphics = NULL; - virDomainHostdevDefPtr hostdev = NULL; size_t i; const char *defaultMachine; unsigned long count; @@ -837,95 +929,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } } - list = virConfGetValue(conf, "pci"); - if (list && list->type == VIR_CONF_LIST) { - list = list->list; - while (list) { - char domain[5]; - char bus[3]; - char slot[3]; - char func[2]; - char *key, *nextkey; - int domainID; - int busID; - int slotID; - int funcID; - - domain[0] = bus[0] = slot[0] = func[0] = '\0'; - - if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) - goto skippci; - - /* pci=['0000:00:1b.0','0000:00:13.0'] */ - if (!(key = list->str)) - goto skippci; - if (!(nextkey = strchr(key, ':'))) - goto skippci; - - if (virStrncpy(domain, key, (nextkey - key), sizeof(domain)) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Domain %s too big for destination"), key); - goto skippci; - } - - key = nextkey + 1; - if (!(nextkey = strchr(key, ':'))) - goto skippci; - - if (virStrncpy(bus, key, (nextkey - key), sizeof(bus)) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Bus %s too big for destination"), key); - goto skippci; - } - - key = nextkey + 1; - if (!(nextkey = strchr(key, '.'))) - goto skippci; - - if (virStrncpy(slot, key, (nextkey - key), sizeof(slot)) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Slot %s too big for destination"), key); - goto skippci; - } - - key = nextkey + 1; - if (strlen(key) != 1) - goto skippci; - - if (virStrncpy(func, key, 1, sizeof(func)) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Function %s too big for destination"), key); - goto skippci; - } - - if (virStrToLong_i(domain, NULL, 16, &domainID) < 0) - goto skippci; - if (virStrToLong_i(bus, NULL, 16, &busID) < 0) - goto skippci; - if (virStrToLong_i(slot, NULL, 16, &slotID) < 0) - goto skippci; - if (virStrToLong_i(func, NULL, 16, &funcID) < 0) - goto skippci; - - if (!(hostdev = virDomainHostdevDefAlloc())) - goto cleanup; - - hostdev->managed = false; - hostdev->source.subsys.type = VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI; - hostdev->source.subsys.u.pci.addr.domain = domainID; - hostdev->source.subsys.u.pci.addr.bus = busID; - hostdev->source.subsys.u.pci.addr.slot = slotID; - hostdev->source.subsys.u.pci.addr.function = funcID; - - if (VIR_APPEND_ELEMENT(def->hostdevs, def->nhostdevs, hostdev) < 0) { - virDomainHostdevDefFree(hostdev); - goto cleanup; - } - - skippci: - list = list->next; - } - } + if (xenParseXMPCI(conf, def) < 0) + goto cleanup; if (hvm) { if (xenXMConfigGetString(conf, "usbdevice", &str, NULL) < 0) -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMPCI(virConfPtr conf, ........); which parses PCI config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 185 +++++++++++++++++++++++++++-------------------------- 1 file changed, 95 insertions(+), 90 deletions(-)
Looks good, ACK. Will push after removing the first SOB. Regards, Jim

introduce function xenParseXMCPUFeatures(virConfPtr conf,.........); which parses CPU features instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 127 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 53 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 8cc892b..e75842f 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -428,6 +428,78 @@ xenParseXMPCI(virConfPtr conf, virDomainDefPtr def) } +static int +xenParseXMCPUFeatures(virConfPtr conf, virDomainDefPtr def) +{ + unsigned long count = 0; + const char *str = NULL; + int val = 0; + + if (xenXMConfigGetULong(conf, "vcpus", &count, 1) < 0 || + MAX_VIRT_CPUS < count) + return -1; + + def->maxvcpus = count; + if (xenXMConfigGetULong(conf, "vcpu_avail", &count, -1) < 0) + return -1; + + def->vcpus = MIN(count_one_bits_l(count), def->maxvcpus); + if (xenXMConfigGetString(conf, "cpus", &str, NULL) < 0) + return -1; + + if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0)) + return -1; + + if (STREQ(def->os.type, "hvm")) { + if (xenXMConfigGetBool(conf, "pae", &val, 0) < 0) + return -1; + + else if (val) + def->features[VIR_DOMAIN_FEATURE_PAE] = VIR_TRISTATE_SWITCH_ON; + if (xenXMConfigGetBool(conf, "acpi", &val, 0) < 0) + return -1; + + else if (val) + def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON; + if (xenXMConfigGetBool(conf, "apic", &val, 0) < 0) + return -1; + + else if (val) + def->features[VIR_DOMAIN_FEATURE_APIC] = VIR_TRISTATE_SWITCH_ON; + if (xenXMConfigGetBool(conf, "hap", &val, 0) < 0) + return -1; + + else if (val) + def->features[VIR_DOMAIN_FEATURE_HAP] = VIR_TRISTATE_SWITCH_ON; + if (xenXMConfigGetBool(conf, "viridian", &val, 0) < 0) + return -1; + + else if (val) + def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] = VIR_TRISTATE_SWITCH_ON; + + if (xenXMConfigGetBool(conf, "hpet", &val, -1) < 0) + return -1; + + else if (val != -1) { + virDomainTimerDefPtr timer; + + if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || + VIR_ALLOC(timer) < 0) + return -1; + + timer->name = VIR_DOMAIN_TIMER_NAME_HPET; + timer->present = val; + timer->tickpolicy = -1; + + def->clock.ntimers = 1; + def->clock.timers[0] = timer; + } + } + + return 0; +} + + #define MAX_VFB 1024 /* @@ -448,7 +520,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainGraphicsDefPtr graphics = NULL; size_t i; const char *defaultMachine; - unsigned long count; char *script = NULL; char *listenAddr = NULL; @@ -546,61 +617,11 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (xenParseXMMem(conf, def) < 0) goto cleanup; - if (xenXMConfigGetULong(conf, "vcpus", &count, 1) < 0 || - MAX_VIRT_CPUS < count) - goto cleanup; - def->maxvcpus = count; - if (xenXMConfigGetULong(conf, "vcpu_avail", &count, -1) < 0) - goto cleanup; - def->vcpus = MIN(count_one_bits_l(count), def->maxvcpus); - - if (xenXMConfigGetString(conf, "cpus", &str, NULL) < 0) - goto cleanup; - if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0)) - goto cleanup; - if (xenParseXMEventsActions(conf, def) < 0) goto cleanup; - if (hvm) { - if (xenXMConfigGetBool(conf, "pae", &val, 0) < 0) - goto cleanup; - else if (val) - def->features[VIR_DOMAIN_FEATURE_PAE] = VIR_TRISTATE_SWITCH_ON; - if (xenXMConfigGetBool(conf, "acpi", &val, 0) < 0) - goto cleanup; - else if (val) - def->features[VIR_DOMAIN_FEATURE_ACPI] = VIR_TRISTATE_SWITCH_ON; - if (xenXMConfigGetBool(conf, "apic", &val, 0) < 0) - goto cleanup; - else if (val) - def->features[VIR_DOMAIN_FEATURE_APIC] = VIR_TRISTATE_SWITCH_ON; - if (xenXMConfigGetBool(conf, "hap", &val, 0) < 0) - goto cleanup; - else if (val) - def->features[VIR_DOMAIN_FEATURE_HAP] = VIR_TRISTATE_SWITCH_ON; - if (xenXMConfigGetBool(conf, "viridian", &val, 0) < 0) - goto cleanup; - else if (val) - def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] = VIR_TRISTATE_SWITCH_ON; - - if (xenXMConfigGetBool(conf, "hpet", &val, -1) < 0) - goto cleanup; - else if (val != -1) { - virDomainTimerDefPtr timer; - - if (VIR_ALLOC_N(def->clock.timers, 1) < 0 || - VIR_ALLOC(timer) < 0) - goto cleanup; - - timer->name = VIR_DOMAIN_TIMER_NAME_HPET; - timer->present = val; - timer->tickpolicy = -1; - - def->clock.ntimers = 1; - def->clock.timers[0] = timer; - } - } + if (xenParseXMCPUFeatures(conf, def) < 0) + goto cleanup; if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0) goto cleanup; -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMCPUFeatures(virConfPtr conf,.........); which parses CPU features instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 127 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 74 insertions(+), 53 deletions(-)
ACK. Will push shortly after cleaning up the extra SOB. Regards, Jim

introduce function xenParseXMDisk(virConfPtr conf, ........); which parses xm disk config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 322 ++++++++++++++++++++++++++++------------------------- 1 file changed, 168 insertions(+), 154 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index e75842f..f4bb37d 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -500,136 +500,15 @@ xenParseXMCPUFeatures(virConfPtr conf, virDomainDefPtr def) } -#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; - - 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; + int hvm = STREQ(def->os.type, "hvm"); + virConfValuePtr list = virConfGetValue(conf, "disk"); - 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) { @@ -641,9 +520,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) goto skipdisk; head = list->str; - if (!(disk = virDomainDiskDefNew())) - goto cleanup; + return -1; /* * Disks have 3 components, SOURCE,DEST-DEVICE,MODE @@ -662,32 +540,35 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ignore_value(virDomainDiskSetSource(disk, NULL)); } else { if (VIR_STRNDUP(tmp, head, offset - head) < 0) - goto cleanup; + return -1; + if (virDomainDiskSetSource(disk, tmp) < 0) { VIR_FREE(tmp); - goto cleanup; + return -1; } + 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; + return -1; + 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; + return -1; } - head = offset + 1; + head = offset + 1; /* Extract source driver type */ src = virDomainDiskGetSource(disk); if (src) { @@ -696,29 +577,31 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if ((tmp = strchr(src, ':')) != NULL) { len = tmp - src; if (VIR_STRNDUP(tmp, src, len) < 0) - goto cleanup; + return -1; + if (virDomainDiskSetDriver(disk, tmp) < 0) { VIR_FREE(tmp); - goto cleanup; + return -1; } + VIR_FREE(tmp); /* Strip the prefix we found off the source file name */ if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; + return -1; + src = virDomainDiskGetSource(disk); } /* And the sub-type for tap:XXX: type */ if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap")) { char *driverType; - if (!(tmp = strchr(src, ':'))) goto skipdisk; len = tmp - src; - if (VIR_STRNDUP(driverType, src, len) < 0) - goto cleanup; + return -1; + if (STREQ(driverType, "aio")) virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); else @@ -729,12 +612,12 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown driver type %s"), src); - goto cleanup; + return -1; } /* Strip the prefix we found off the source file name */ if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; + return -1; src = virDomainDiskGetSource(disk); } } @@ -742,15 +625,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, /* No source, or driver name, so fix to phy: */ if (!virDomainDiskGetDriver(disk) && virDomainDiskSetDriver(disk, "phy") < 0) - goto cleanup; - + return -1; /* phy: type indicates a block device */ virDomainDiskSetType(disk, STREQ(virDomainDiskGetDriver(disk), "phy") ? VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE); - /* Check for a :cdrom/:disk postfix */ disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; if ((tmp = strchr(disk->dst, ':')) != NULL) { @@ -773,10 +654,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, else if ((STREQ(head, "w!")) || (STREQ(head, "!"))) disk->src->shared = true; - /* Maintain list in sorted order according to target device name */ if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) - goto cleanup; + return -1; skipdisk: list = list->next; @@ -786,27 +666,161 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) { if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0) - goto cleanup; + return -1; if (str) { if (!(disk = virDomainDiskDefNew())) - goto cleanup; + return -1; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (virDomainDiskSetDriver(disk, "file") < 0) - goto cleanup; + return -1; if (virDomainDiskSetSource(disk, str) < 0) - goto cleanup; + return -1; if (VIR_STRDUP(disk->dst, "hdc") < 0) - goto cleanup; + return -1; disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->src->readonly = true; if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) + return -1; + } + } + + return 0; +} +#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; + 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; + + 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; -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMDisk(virConfPtr conf, ........); which parses xm disk config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 322 ++++++++++++++++++++++++++++------------------------- 1 file changed, 168 insertions(+), 154 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index e75842f..f4bb37d 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -500,136 +500,15 @@ xenParseXMCPUFeatures(virConfPtr conf, virDomainDefPtr def) }
-#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)
Whitespace off a bit.
{ - 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; - - 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; + int hvm = STREQ(def->os.type, "hvm"); + virConfValuePtr list = virConfGetValue(conf, "disk");
- 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) { @@ -641,9 +520,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) goto skipdisk; head = list->str; - if (!(disk = virDomainDiskDefNew())) - goto cleanup; + return -1;
/* * Disks have 3 components, SOURCE,DEST-DEVICE,MODE @@ -662,32 +540,35 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ignore_value(virDomainDiskSetSource(disk, NULL)); } else { if (VIR_STRNDUP(tmp, head, offset - head) < 0) - goto cleanup; + return -1;
'disk' could be leaked here and below where we return error from the function without cleanup. The function should have a cleanup label similar to the vfb parsing code in 7/24.
+ if (virDomainDiskSetSource(disk, tmp) < 0) { VIR_FREE(tmp); - goto cleanup; + return -1; } + 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; + return -1; + 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; + return -1; } - head = offset + 1;
+ head = offset + 1; /* Extract source driver type */ src = virDomainDiskGetSource(disk); if (src) { @@ -696,29 +577,31 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if ((tmp = strchr(src, ':')) != NULL) { len = tmp - src; if (VIR_STRNDUP(tmp, src, len) < 0) - goto cleanup; + return -1; + if (virDomainDiskSetDriver(disk, tmp) < 0) { VIR_FREE(tmp); - goto cleanup; + return -1; } + VIR_FREE(tmp);
/* Strip the prefix we found off the source file name */ if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; + return -1; + src = virDomainDiskGetSource(disk); }
/* And the sub-type for tap:XXX: type */ if (STREQ_NULLABLE(virDomainDiskGetDriver(disk), "tap")) { char *driverType; - if (!(tmp = strchr(src, ':'))) goto skipdisk; len = tmp - src; - if (VIR_STRNDUP(driverType, src, len) < 0) - goto cleanup; + return -1; + if (STREQ(driverType, "aio")) virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); else @@ -729,12 +612,12 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown driver type %s"), src); - goto cleanup; + return -1; }
/* Strip the prefix we found off the source file name */ if (virDomainDiskSetSource(disk, src + len + 1) < 0) - goto cleanup; + return -1; src = virDomainDiskGetSource(disk); } } @@ -742,15 +625,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, /* No source, or driver name, so fix to phy: */ if (!virDomainDiskGetDriver(disk) && virDomainDiskSetDriver(disk, "phy") < 0) - goto cleanup; - + return -1;
/* phy: type indicates a block device */ virDomainDiskSetType(disk, STREQ(virDomainDiskGetDriver(disk), "phy") ? VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE); - /* Check for a :cdrom/:disk postfix */ disk->device = VIR_DOMAIN_DISK_DEVICE_DISK; if ((tmp = strchr(disk->dst, ':')) != NULL) { @@ -773,10 +654,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, else if ((STREQ(head, "w!")) || (STREQ(head, "!"))) disk->src->shared = true; - /* Maintain list in sorted order according to target device name */ if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) - goto cleanup; + return -1;
skipdisk: list = list->next; @@ -786,27 +666,161 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) { if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0) - goto cleanup; + return -1; if (str) { if (!(disk = virDomainDiskDefNew())) - goto cleanup; + return -1;
virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (virDomainDiskSetDriver(disk, "file") < 0) - goto cleanup; + return -1; if (virDomainDiskSetSource(disk, str) < 0) - goto cleanup; + return -1; if (VIR_STRDUP(disk->dst, "hdc") < 0) - goto cleanup; + return -1; disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->src->readonly = true;
if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) + return -1; + } + } + + return 0; +} +#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; + virDomainDiskDefPtr disk = NULL;
'disk' is no longer used in this function and can be removed. ACK with the below squashed in. Regards, Jim diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 88b63ac..855eceb 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -505,8 +505,7 @@ xenParseXMCPUFeatures(virConfPtr conf, virDomainDefPtr def) static int -xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, - int xendConfigVersion) +xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion) { const char *str = NULL; virDomainDiskDefPtr disk = NULL; @@ -544,13 +544,12 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, ignore_value(virDomainDiskSetSource(disk, NULL)); } else { if (VIR_STRNDUP(tmp, head, offset - head) < 0) - return -1; + goto cleanup; if (virDomainDiskSetSource(disk, tmp) < 0) { VIR_FREE(tmp); - return -1; + goto cleanup; } - VIR_FREE(tmp); } @@ -563,13 +562,13 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, goto skipdisk; if (VIR_ALLOC_N(disk->dst, (offset - head) + 1) < 0) - return -1; + 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); - return -1; + goto cleanup; } head = offset + 1; @@ -581,18 +580,17 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, if ((tmp = strchr(src, ':')) != NULL) { len = tmp - src; if (VIR_STRNDUP(tmp, src, len) < 0) - return -1; + goto cleanup; if (virDomainDiskSetDriver(disk, tmp) < 0) { VIR_FREE(tmp); - return -1; + goto cleanup; } - VIR_FREE(tmp); /* Strip the prefix we found off the source file name */ if (virDomainDiskSetSource(disk, src + len + 1) < 0) - return -1; + goto cleanup; src = virDomainDiskGetSource(disk); } @@ -604,7 +602,7 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, goto skipdisk; len = tmp - src; if (VIR_STRNDUP(driverType, src, len) < 0) - return -1; + goto cleanup; if (STREQ(driverType, "aio")) virDomainDiskSetFormat(disk, VIR_STORAGE_FILE_RAW); @@ -616,12 +614,12 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unknown driver type %s"), src); - return -1; + goto cleanup; } /* Strip the prefix we found off the source file name */ if (virDomainDiskSetSource(disk, src + len + 1) < 0) - return -1; + goto cleanup; src = virDomainDiskGetSource(disk); } } @@ -629,7 +627,7 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, /* No source, or driver name, so fix to phy: */ if (!virDomainDiskGetDriver(disk) && virDomainDiskSetDriver(disk, "phy") < 0) - return -1; + goto cleanup; /* phy: type indicates a block device */ virDomainDiskSetType(disk, @@ -660,7 +658,7 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, disk->src->shared = true; /* Maintain list in sorted order according to target device name */ if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) - return -1; + goto cleanup; skipdisk: list = list->next; @@ -670,29 +668,35 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, if (hvm && xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) { if (xenXMConfigGetString(conf, "cdrom", &str, NULL) < 0) - return -1; + goto cleanup; if (str) { if (!(disk = virDomainDiskDefNew())) - return -1; + goto cleanup; virDomainDiskSetType(disk, VIR_STORAGE_TYPE_FILE); disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM; if (virDomainDiskSetDriver(disk, "file") < 0) - return -1; + goto cleanup; if (virDomainDiskSetSource(disk, str) < 0) - return -1; + goto cleanup; if (VIR_STRDUP(disk->dst, "hdc") < 0) - return -1; + goto cleanup; disk->bus = VIR_DOMAIN_DISK_BUS_IDE; disk->src->readonly = true; if (VIR_APPEND_ELEMENT(def->disks, def->ndisks, disk) < 0) - return -1; + goto cleanup; } } return 0; + + cleanup: + virDomainDiskDefFree(disk); + return -1; } + + #define MAX_VFB 1024 /* @@ -708,7 +712,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, int val; virConfValuePtr list; virDomainDefPtr def = NULL; - virDomainDiskDefPtr disk = NULL; virDomainNetDefPtr net = NULL; virDomainGraphicsDefPtr graphics = NULL; size_t i; @@ -1235,7 +1238,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, cleanup: virDomainGraphicsDefFree(graphics); virDomainNetDefFree(net); - virDomainDiskDefFree(disk); virDomainDefFree(def); VIR_FREE(script); VIR_FREE(listenAddr);

introduce function xenParseXMVfb(virConfPtr conf,..........); which parses Vfb config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 301 +++++++++++++++++++++++++++-------------------------- 1 file changed, 155 insertions(+), 146 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index f4bb37d..228e0a2 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -40,6 +40,7 @@ #include "virstoragefile.h" #include "virstring.h" +#define MAX_VFB 1024 /* Convenience method to grab a int from the config file object */ static int xenXMConfigGetBool(virConfPtr conf, const char *name, int *value, int def) @@ -689,7 +690,158 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, return 0; } -#define MAX_VFB 1024 + + +static int +xenParseXMVfb(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + int val; + char *listenAddr = NULL; + int hvm = STREQ(def->os.type, "hvm"); + virConfValuePtr list; + virDomainGraphicsDefPtr graphics = NULL; + + if (hvm || xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { + if (xenXMConfigGetBool(conf, "vnc", &val, 0) < 0) + goto cleanup; + if (val) { + if (VIR_ALLOC(graphics) < 0) + goto cleanup; + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; + if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0) + goto cleanup; + graphics->data.vnc.autoport = val ? 1 : 0; + if (!graphics->data.vnc.autoport) { + unsigned long vncdisplay; + if (xenXMConfigGetULong(conf, "vncdisplay", &vncdisplay, 0) < 0) + goto cleanup; + graphics->data.vnc.port = (int)vncdisplay + 5900; + } + + if (xenXMConfigCopyStringOpt(conf, "vnclisten", &listenAddr) < 0) + goto cleanup; + if (listenAddr && + virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, + -1, true) < 0) { + goto cleanup; + } + + VIR_FREE(listenAddr); + if (xenXMConfigCopyStringOpt(conf, "vncpasswd", &graphics->data.vnc.auth.passwd) < 0) + goto cleanup; + if (xenXMConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0) + goto cleanup; + if (VIR_ALLOC_N(def->graphics, 1) < 0) + goto cleanup; + def->graphics[0] = graphics; + def->ngraphics = 1; + graphics = NULL; + } else { + if (xenXMConfigGetBool(conf, "sdl", &val, 0) < 0) + goto cleanup; + if (val) { + if (VIR_ALLOC(graphics) < 0) + goto cleanup; + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; + if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0) + goto cleanup; + if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0) + goto cleanup; + if (VIR_ALLOC_N(def->graphics, 1) < 0) + goto cleanup; + def->graphics[0] = graphics; + def->ngraphics = 1; + graphics = NULL; + } + } + } + + if (!hvm && def->graphics == NULL) { /* New PV guests use this format */ + list = virConfGetValue(conf, "vfb"); + if (list && list->type == VIR_CONF_LIST && + list->list && list->list->type == VIR_CONF_STRING && + list->list->str) { + char vfb[MAX_VFB]; + char *key = vfb; + + if (virStrcpyStatic(vfb, list->list->str) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("VFB %s too big for destination"), + list->list->str); + goto cleanup; + } + + if (VIR_ALLOC(graphics) < 0) + goto cleanup; + if (strstr(key, "type=sdl")) + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; + else + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; + while (key) { + char *nextkey = strchr(key, ','); + char *end = nextkey; + if (nextkey) { + *end = '\0'; + nextkey++; + } + + if (!strchr(key, '=')) + break; + if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { + if (STRPREFIX(key, "vncunused=")) { + if (STREQ(key + 10, "1")) + graphics->data.vnc.autoport = true; + } else if (STRPREFIX(key, "vnclisten=")) { + if (virDomainGraphicsListenSetAddress(graphics, 0, key+10, + -1, true) < 0) + goto cleanup; + } else if (STRPREFIX(key, "vncpasswd=")) { + if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0) + goto cleanup; + } else if (STRPREFIX(key, "keymap=")) { + if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) + goto cleanup; + } else if (STRPREFIX(key, "vncdisplay=")) { + if (virStrToLong_i(key + 11, NULL, 10, + &graphics->data.vnc.port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid vncdisplay value '%s'"), + key + 11); + goto cleanup; + } + graphics->data.vnc.port += 5900; + } + } else { + if (STRPREFIX(key, "display=")) { + if (VIR_STRDUP(graphics->data.sdl.display, key + 8) < 0) + goto cleanup; + } else if (STRPREFIX(key, "xauthority=")) { + if (VIR_STRDUP(graphics->data.sdl.xauth, key + 11) < 0) + goto cleanup; + } + } + + while (nextkey && (nextkey[0] == ',' || + nextkey[0] == ' ' || + nextkey[0] == '\t')) + nextkey++; + key = nextkey; + } + if (VIR_ALLOC_N(def->graphics, 1) < 0) + goto cleanup; + def->graphics[0] = graphics; + def->ngraphics = 1; + graphics = NULL; + } + } + + return 0; + + cleanup: + virDomainGraphicsDefFree(graphics); + return -1; +} /* * Turn a config record into a lump of XML describing the @@ -701,16 +853,13 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, { const char *str; int hvm = 0; - int val; virConfValuePtr list; virDomainDefPtr def = 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; @@ -993,146 +1142,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } } - /* HVM guests, or old PV guests use this config format */ - if (hvm || xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { - if (xenXMConfigGetBool(conf, "vnc", &val, 0) < 0) - goto cleanup; - - if (val) { - if (VIR_ALLOC(graphics) < 0) - goto cleanup; - graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; - if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0) - goto cleanup; - graphics->data.vnc.autoport = val ? 1 : 0; - - if (!graphics->data.vnc.autoport) { - unsigned long vncdisplay; - if (xenXMConfigGetULong(conf, "vncdisplay", &vncdisplay, 0) < 0) - goto cleanup; - graphics->data.vnc.port = (int)vncdisplay + 5900; - } - - if (xenXMConfigCopyStringOpt(conf, "vnclisten", &listenAddr) < 0) - goto cleanup; - if (listenAddr && - virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, - -1, true) < 0) { - goto cleanup; - } - VIR_FREE(listenAddr); - - if (xenXMConfigCopyStringOpt(conf, "vncpasswd", &graphics->data.vnc.auth.passwd) < 0) - goto cleanup; - if (xenXMConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0) - goto cleanup; - - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; - def->graphics[0] = graphics; - def->ngraphics = 1; - graphics = NULL; - } else { - if (xenXMConfigGetBool(conf, "sdl", &val, 0) < 0) - goto cleanup; - if (val) { - if (VIR_ALLOC(graphics) < 0) - goto cleanup; - graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; - if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0) - goto cleanup; - if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0) - goto cleanup; - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; - def->graphics[0] = graphics; - def->ngraphics = 1; - graphics = NULL; - } - } - } - - if (!hvm && def->graphics == NULL) { /* New PV guests use this format */ - list = virConfGetValue(conf, "vfb"); - if (list && list->type == VIR_CONF_LIST && - list->list && list->list->type == VIR_CONF_STRING && - list->list->str) { - char vfb[MAX_VFB]; - char *key = vfb; - - if (virStrcpyStatic(vfb, list->list->str) == NULL) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("VFB %s too big for destination"), - list->list->str); - goto cleanup; - } - - if (VIR_ALLOC(graphics) < 0) - goto cleanup; - - if (strstr(key, "type=sdl")) - graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; - else - graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; - - while (key) { - char *nextkey = strchr(key, ','); - char *end = nextkey; - if (nextkey) { - *end = '\0'; - nextkey++; - } - - if (!strchr(key, '=')) - break; - - if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { - if (STRPREFIX(key, "vncunused=")) { - if (STREQ(key + 10, "1")) - graphics->data.vnc.autoport = true; - } else if (STRPREFIX(key, "vnclisten=")) { - if (virDomainGraphicsListenSetAddress(graphics, 0, key+10, - -1, true) < 0) - goto cleanup; - } else if (STRPREFIX(key, "vncpasswd=")) { - if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0) - goto cleanup; - } else if (STRPREFIX(key, "keymap=")) { - if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) - goto cleanup; - } else if (STRPREFIX(key, "vncdisplay=")) { - if (virStrToLong_i(key + 11, NULL, 10, - &graphics->data.vnc.port) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("invalid vncdisplay value '%s'"), - key + 11); - goto cleanup; - } - graphics->data.vnc.port += 5900; - } - } else { - if (STRPREFIX(key, "display=")) { - if (VIR_STRDUP(graphics->data.sdl.display, key + 8) < 0) - goto cleanup; - } else if (STRPREFIX(key, "xauthority=")) { - if (VIR_STRDUP(graphics->data.sdl.xauth, key + 11) < 0) - goto cleanup; - } - } - - while (nextkey && (nextkey[0] == ',' || - nextkey[0] == ' ' || - nextkey[0] == '\t')) - nextkey++; - key = nextkey; - } - if (VIR_ALLOC_N(def->graphics, 1) < 0) - goto cleanup; - def->graphics[0] = graphics; - def->ngraphics = 1; - graphics = NULL; - } - } + if (xenParseXMVfb(conf, def, xendConfigVersion) < 0) + goto cleanup; if (hvm) { virDomainChrDefPtr chr = NULL; @@ -1229,12 +1240,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, return def; cleanup: - virDomainGraphicsDefFree(graphics); virDomainNetDefFree(net); virDomainDiskDefFree(disk); virDomainDefFree(def); VIR_FREE(script); - VIR_FREE(listenAddr); return NULL; } -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMVfb(virConfPtr conf,..........); which parses Vfb config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 301 +++++++++++++++++++++++++++-------------------------- 1 file changed, 155 insertions(+), 146 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index f4bb37d..228e0a2 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -40,6 +40,7 @@ #include "virstoragefile.h" #include "virstring.h"
+#define MAX_VFB 1024 /* Convenience method to grab a int from the config file object */ static int xenXMConfigGetBool(virConfPtr conf, const char *name, int *value, int def) @@ -689,7 +690,158 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def,
return 0; } -#define MAX_VFB 1024 + + +static int +xenParseXMVfb(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + int val; + char *listenAddr = NULL; + int hvm = STREQ(def->os.type, "hvm"); + virConfValuePtr list; + virDomainGraphicsDefPtr graphics = NULL; + + if (hvm || xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) { + if (xenXMConfigGetBool(conf, "vnc", &val, 0) < 0) + goto cleanup; + if (val) { + if (VIR_ALLOC(graphics) < 0) + goto cleanup; + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; + if (xenXMConfigGetBool(conf, "vncunused", &val, 1) < 0) + goto cleanup; + graphics->data.vnc.autoport = val ? 1 : 0; + if (!graphics->data.vnc.autoport) { + unsigned long vncdisplay; + if (xenXMConfigGetULong(conf, "vncdisplay", &vncdisplay, 0) < 0) + goto cleanup; + graphics->data.vnc.port = (int)vncdisplay + 5900; + } + + if (xenXMConfigCopyStringOpt(conf, "vnclisten", &listenAddr) < 0) + goto cleanup; + if (listenAddr && + virDomainGraphicsListenSetAddress(graphics, 0, listenAddr, + -1, true) < 0) { + goto cleanup; + } + + VIR_FREE(listenAddr); + if (xenXMConfigCopyStringOpt(conf, "vncpasswd", &graphics->data.vnc.auth.passwd) < 0) + goto cleanup; + if (xenXMConfigCopyStringOpt(conf, "keymap", &graphics->data.vnc.keymap) < 0) + goto cleanup; + if (VIR_ALLOC_N(def->graphics, 1) < 0) + goto cleanup; + def->graphics[0] = graphics; + def->ngraphics = 1; + graphics = NULL; + } else { + if (xenXMConfigGetBool(conf, "sdl", &val, 0) < 0) + goto cleanup; + if (val) { + if (VIR_ALLOC(graphics) < 0) + goto cleanup; + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; + if (xenXMConfigCopyStringOpt(conf, "display", &graphics->data.sdl.display) < 0) + goto cleanup; + if (xenXMConfigCopyStringOpt(conf, "xauthority", &graphics->data.sdl.xauth) < 0) + goto cleanup; + if (VIR_ALLOC_N(def->graphics, 1) < 0) + goto cleanup; + def->graphics[0] = graphics; + def->ngraphics = 1; + graphics = NULL; + } + } + } + + if (!hvm && def->graphics == NULL) { /* New PV guests use this format */ + list = virConfGetValue(conf, "vfb"); + if (list && list->type == VIR_CONF_LIST && + list->list && list->list->type == VIR_CONF_STRING && + list->list->str) { + char vfb[MAX_VFB]; + char *key = vfb; + + if (virStrcpyStatic(vfb, list->list->str) == NULL) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("VFB %s too big for destination"), + list->list->str); + goto cleanup; + } + + if (VIR_ALLOC(graphics) < 0) + goto cleanup; + if (strstr(key, "type=sdl")) + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_SDL; + else + graphics->type = VIR_DOMAIN_GRAPHICS_TYPE_VNC; + while (key) { + char *nextkey = strchr(key, ','); + char *end = nextkey; + if (nextkey) { + *end = '\0'; + nextkey++; + } + + if (!strchr(key, '=')) + break; + if (graphics->type == VIR_DOMAIN_GRAPHICS_TYPE_VNC) { + if (STRPREFIX(key, "vncunused=")) { + if (STREQ(key + 10, "1")) + graphics->data.vnc.autoport = true; + } else if (STRPREFIX(key, "vnclisten=")) { + if (virDomainGraphicsListenSetAddress(graphics, 0, key+10, + -1, true) < 0) + goto cleanup; + } else if (STRPREFIX(key, "vncpasswd=")) { + if (VIR_STRDUP(graphics->data.vnc.auth.passwd, key + 10) < 0) + goto cleanup; + } else if (STRPREFIX(key, "keymap=")) { + if (VIR_STRDUP(graphics->data.vnc.keymap, key + 7) < 0) + goto cleanup; + } else if (STRPREFIX(key, "vncdisplay=")) { + if (virStrToLong_i(key + 11, NULL, 10, + &graphics->data.vnc.port) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("invalid vncdisplay value '%s'"), + key + 11); + goto cleanup; + } + graphics->data.vnc.port += 5900; + } + } else { + if (STRPREFIX(key, "display=")) { + if (VIR_STRDUP(graphics->data.sdl.display, key + 8) < 0) + goto cleanup; + } else if (STRPREFIX(key, "xauthority=")) { + if (VIR_STRDUP(graphics->data.sdl.xauth, key + 11) < 0) + goto cleanup; + } + } + + while (nextkey && (nextkey[0] == ',' || + nextkey[0] == ' ' || + nextkey[0] == '\t')) + nextkey++; + key = nextkey; + } + if (VIR_ALLOC_N(def->graphics, 1) < 0) + goto cleanup; + def->graphics[0] = graphics; + def->ngraphics = 1; + graphics = NULL; + } + } + + return 0; + + cleanup: + virDomainGraphicsDefFree(graphics);
'listenAddr' should be freed on cleanup too. ACK otherwise. I'll fix that up before pushing. Regards, Jim

introduce function xenParseXMCharDev(virConfPtr conf,.........); which parses Char devices config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 174 ++++++++++++++++++++++++++++------------------------- 1 file changed, 93 insertions(+), 81 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 228e0a2..628cef6 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -843,6 +843,97 @@ xenParseXMVfb(virConfPtr conf, virDomainDefPtr def, return -1; } + +static int +xenParseXMCharDev(virConfPtr conf, virDomainDefPtr def) +{ + const char *str; + virConfValuePtr value = NULL; + virDomainChrDefPtr chr = NULL; + + if (STREQ(def->os.type, "hvm")) { + if (xenXMConfigGetString(conf, "parallel", &str, NULL) < 0) + goto cleanup; + if (str && STRNEQ(str, "none") && + !(chr = xenParseSxprChar(str, NULL))) + goto cleanup; + if (chr) { + if (VIR_ALLOC_N(def->parallels, 1) < 0) { + goto cleanup; + } + + chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; + chr->target.port = 0; + def->parallels[0] = chr; + def->nparallels++; + chr = NULL; + } + + /* Try to get the list of values to support multiple serial ports */ + value = virConfGetValue(conf, "serial"); + if (value && value->type == VIR_CONF_LIST) { + int portnum = -1; + + value = value->list; + while (value) { + char *port = NULL; + + if ((value->type != VIR_CONF_STRING) || (value->str == NULL)) + goto cleanup; + port = value->str; + portnum++; + if (STREQ(port, "none")) { + value = value->next; + continue; + } + + if (!(chr = xenParseSxprChar(port, NULL))) + goto cleanup; + chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; + chr->target.port = portnum; + if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) { + goto cleanup; + } + + value = value->next; + } + } else { + /* If domain is not using multiple serial ports we parse data old way */ + if (xenXMConfigGetString(conf, "serial", &str, NULL) < 0) + goto cleanup; + if (str && STRNEQ(str, "none") && + !(chr = xenParseSxprChar(str, NULL))) + goto cleanup; + if (chr) { + if (VIR_ALLOC_N(def->serials, 1) < 0) { + virDomainChrDefFree(chr); + goto cleanup; + } + chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; + chr->target.port = 0; + def->serials[0] = chr; + def->nserials++; + } + } + } else { + if (VIR_ALLOC_N(def->consoles, 1) < 0) + goto cleanup; + def->nconsoles = 1; + if (!(def->consoles[0] = xenParseSxprChar("pty", NULL))) + goto cleanup; + def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; + def->consoles[0]->target.port = 0; + def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; + } + + return 0; + + cleanup: + virDomainChrDefFree(chr); + return -1; +} + + /* * Turn a config record into a lump of XML describing the * domain, suitable for later feeding for virDomainCreateXML @@ -1145,87 +1236,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (xenParseXMVfb(conf, def, xendConfigVersion) < 0) goto cleanup; - if (hvm) { - virDomainChrDefPtr chr = NULL; - - if (xenXMConfigGetString(conf, "parallel", &str, NULL) < 0) - goto cleanup; - if (str && STRNEQ(str, "none") && - !(chr = xenParseSxprChar(str, NULL))) - goto cleanup; - - if (chr) { - if (VIR_ALLOC_N(def->parallels, 1) < 0) { - virDomainChrDefFree(chr); - goto cleanup; - } - chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL; - chr->target.port = 0; - def->parallels[0] = chr; - def->nparallels++; - chr = NULL; - } - - /* Try to get the list of values to support multiple serial ports */ - list = virConfGetValue(conf, "serial"); - if (list && list->type == VIR_CONF_LIST) { - int portnum = -1; - - list = list->list; - while (list) { - char *port = NULL; - - if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) - goto cleanup; - - port = list->str; - portnum++; - if (STREQ(port, "none")) { - list = list->next; - continue; - } - - if (!(chr = xenParseSxprChar(port, NULL))) - goto cleanup; - - chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; - chr->target.port = portnum; - - if (VIR_APPEND_ELEMENT(def->serials, def->nserials, chr) < 0) { - virDomainChrDefFree(chr); - goto cleanup; - } - - list = list->next; - } - } else { - /* If domain is not using multiple serial ports we parse data old way */ - if (xenXMConfigGetString(conf, "serial", &str, NULL) < 0) - goto cleanup; - if (str && STRNEQ(str, "none") && - !(chr = xenParseSxprChar(str, NULL))) - goto cleanup; - if (chr) { - if (VIR_ALLOC_N(def->serials, 1) < 0) { - virDomainChrDefFree(chr); - goto cleanup; - } - chr->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL; - chr->target.port = 0; - def->serials[0] = chr; - def->nserials++; - } - } - } else { - if (VIR_ALLOC_N(def->consoles, 1) < 0) - goto cleanup; - def->nconsoles = 1; - if (!(def->consoles[0] = xenParseSxprChar("pty", NULL))) - goto cleanup; - def->consoles[0]->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE; - def->consoles[0]->target.port = 0; - def->consoles[0]->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN; - } + if (xenParseXMCharDev(conf, def) < 0) + goto cleanup; if (hvm) { if (xenXMConfigGetString(conf, "soundhw", &str, NULL) < 0) -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMCharDev(virConfPtr conf,.........); which parses Char devices config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 174 ++++++++++++++++++++++++++++------------------------- 1 file changed, 93 insertions(+), 81 deletions(-)
ACK. Will push after removing the extra SOB. Regards, Jim

introduce function xenParseXMVif(virConfPtr conf,........); which parses Vfb config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 283 +++++++++++++++++++++++++++-------------------------- 1 file changed, 143 insertions(+), 140 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 628cef6..73efa5f 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -934,134 +934,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; - virDomainDiskDefPtr disk = 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) { @@ -1082,7 +961,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) goto skipnic; - key = list->str; while (key) { char *data; @@ -1091,7 +969,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (!(data = strchr(key, '='))) goto skipnic; data++; - if (STRPREFIX(key, "mac=")) { int len = nextkey ? (nextkey - data) : sizeof(mac) - 1; if (virStrncpy(mac, data, len, sizeof(mac)) == NULL) { @@ -1117,14 +994,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=")) { @@ -1139,7 +1018,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, int len = nextkey ? (nextkey - data) : sizeof(ip) - 1; if (virStrncpy(ip, data, len, sizeof(ip)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("IP %s too big for destination"), data); + _("IP %s too big for destination"), + data); goto skipnic; } } @@ -1153,7 +1033,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (VIR_ALLOC(net) < 0) goto cleanup; - if (mac[0]) { if (virMacAddrParse(mac, &net->mac) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1182,28 +1061,156 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (script && script[0] && VIR_STRDUP(net->script, script) < 0) goto cleanup; - if (model[0] && VIR_STRDUP(net->model, model) < 0) goto cleanup; - if (!model[0] && type[0] && STREQ(type, "netfront") && VIR_STRDUP(net->model, "netfront") < 0) goto cleanup; - if (vifname[0] && VIR_STRDUP(net->ifname, vifname) < 0) goto cleanup; - if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) goto cleanup; - + VIR_FREE(script); skipnic: list = list->next; virDomainNetDefFree(net); } } + 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; @@ -1248,14 +1255,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; } - VIR_FREE(script); return def; cleanup: - virDomainNetDefFree(net); - virDomainDiskDefFree(disk); virDomainDefFree(def); - VIR_FREE(script); return NULL; } -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMVif(virConfPtr conf,........); which parses Vfb config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 283 +++++++++++++++++++++++++++-------------------------- 1 file changed, 143 insertions(+), 140 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 628cef6..73efa5f 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -934,134 +934,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; - virDomainDiskDefPtr disk = 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) { @@ -1082,7 +961,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if ((list->type != VIR_CONF_STRING) || (list->str == NULL)) goto skipnic; - key = list->str; while (key) { char *data; @@ -1091,7 +969,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (!(data = strchr(key, '='))) goto skipnic; data++; - if (STRPREFIX(key, "mac=")) { int len = nextkey ? (nextkey - data) : sizeof(mac) - 1; if (virStrncpy(mac, data, len, sizeof(mac)) == NULL) { @@ -1117,14 +994,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=")) { @@ -1139,7 +1018,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, int len = nextkey ? (nextkey - data) : sizeof(ip) - 1; if (virStrncpy(ip, data, len, sizeof(ip)) == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, - _("IP %s too big for destination"), data); + _("IP %s too big for destination"), + data);
This one actually fit within 80 columns.
goto skipnic; } } @@ -1153,7 +1033,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
if (VIR_ALLOC(net) < 0) goto cleanup; - if (mac[0]) { if (virMacAddrParse(mac, &net->mac) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1182,28 +1061,156 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (script && script[0] && VIR_STRDUP(net->script, script) < 0) goto cleanup; - if (model[0] && VIR_STRDUP(net->model, model) < 0) goto cleanup; - if (!model[0] && type[0] && STREQ(type, "netfront") && VIR_STRDUP(net->model, "netfront") < 0) goto cleanup; - if (vifname[0] && VIR_STRDUP(net->ifname, vifname) < 0) goto cleanup; - if (VIR_APPEND_ELEMENT(def->nets, def->nnets, net) < 0) goto cleanup; - + VIR_FREE(script);
Can go at the end of the 'skipnic' label.
skipnic: list = list->next; virDomainNetDefFree(net); } }
+ 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;
@@ -1248,14 +1255,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, goto cleanup; }
- VIR_FREE(script); return def;
cleanup: - virDomainNetDefFree(net); - virDomainDiskDefFree(disk);
Freeing 'disk' should be in 6/24. I've taken care of that. I'll fix up the other nits and push shortly. Regards, Jim

introduce function xenParseXMEmulatedHardware(virConfPtr conf,.........); which parses emulated devices config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 82 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 34 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 73efa5f..9eabfa4 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1085,6 +1085,52 @@ xenParseXMVif(virConfPtr conf, virDomainDefPtr def) VIR_FREE(script); return -1; } + + +static int +xenParseXMEmulatedDevices(virConfPtr conf, virDomainDefPtr def) +{ + const char *str; + + if (STREQ(def->os.type, "hvm")) { + if (xenXMConfigGetString(conf, "soundhw", &str, NULL) < 0) + return -1; + + if (str && + xenParseSxprSound(def, str) < 0) + return -1; + + if (xenXMConfigGetString(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_ALLOC_N(def->inputs, 1) < 0) { + virDomainInputDefFree(input); + return -1; + + } + def->inputs[0] = input; + def->ninputs = 1; + } + } + + return 0; +} + /* * Turn a config record into a lump of XML describing the * domain, suitable for later feeding for virDomainCreateXML @@ -1214,31 +1260,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (xenParseXMPCI(conf, def) < 0) goto cleanup; - if (hvm) { - if (xenXMConfigGetString(conf, "usbdevice", &str, NULL) < 0) - goto cleanup; - if (str && - (STREQ(str, "tablet") || - STREQ(str, "mouse") || - STREQ(str, "keyboard"))) { - virDomainInputDefPtr input; - if (VIR_ALLOC(input) < 0) - goto cleanup; - 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_ALLOC_N(def->inputs, 1) < 0) { - virDomainInputDefFree(input); - goto cleanup; - } - def->inputs[0] = input; - def->ninputs = 1; - } - } + if (xenParseXMEmulatedDevices(conf, def) < 0) + goto cleanup; if (xenParseXMVfb(conf, def, xendConfigVersion) < 0) goto cleanup; @@ -1246,15 +1269,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, if (xenParseXMCharDev(conf, def) < 0) goto cleanup; - if (hvm) { - if (xenXMConfigGetString(conf, "soundhw", &str, NULL) < 0) - goto cleanup; - - if (str && - xenParseSxprSound(def, str) < 0) - goto cleanup; - } - return def; cleanup: -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMEmulatedHardware(virConfPtr conf,.........); which parses emulated devices config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 82 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 34 deletions(-)
Looks good, ACK. I'll push after removing the extra SOB. Regards, Jim

introduce function xenParseXMGeneralMeta(virConfPtr conf, .......); which parses general metadata instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 58 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 9eabfa4..32c6d8c 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1131,38 +1131,28 @@ xenParseXMEmulatedDevices(virConfPtr conf, virDomainDefPtr def) return 0; } -/* - * 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 +xenParseXMGeneralMeta(virConfPtr conf, virDomainDefPtr def, + virCapsPtr caps) { + + const char *defaultMachine; 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; + return -1; + if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0) + return -1; if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) && STREQ(str, "hvm")) hvm = 1; if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0) - goto cleanup; + return -1; def->os.arch = virCapabilitiesDefaultGuestArch(caps, @@ -1172,7 +1162,7 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virReportError(VIR_ERR_INTERNAL_ERROR, _("no supported architecture for os type '%s'"), def->os.type); - goto cleanup; + return -1; } defaultMachine = virCapabilitiesDefaultGuestMachine(caps, @@ -1181,10 +1171,32 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, virDomainVirtTypeToString(def->virtType)); if (defaultMachine != NULL) { if (VIR_STRDUP(def->os.machine, defaultMachine) < 0) - goto cleanup; + return -1; } - if (hvm) { + return 0; +} +/* + * 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) +{ + virDomainDefPtr def = NULL; + size_t i; + + if (VIR_ALLOC(def) < 0) + return NULL; + + def->virtType = VIR_DOMAIN_VIRT_XEN; + def->id = -1; + + if (xenParseXMGeneralMeta(conf, def, caps) < 0) + goto cleanup; + + if (STREQ(def->os.type, "hvm")) { const char *boot; if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0) goto cleanup; -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMGeneralMeta(virConfPtr conf, .......); which parses general metadata instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 58 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 35 insertions(+), 23 deletions(-)
ACK. Will push shortly. Regards, Jim

introduce function xenParseXMOS(virConfPtr conf,...........); which parses the OS config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 80 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 30 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 32c6d8c..b21d794 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1176,33 +1176,26 @@ xenParseXMGeneralMeta(virConfPtr conf, virDomainDefPtr def, return 0; } -/* - * 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) -{ - virDomainDefPtr def = NULL; - size_t i; - if (VIR_ALLOC(def) < 0) - return NULL; - - def->virtType = VIR_DOMAIN_VIRT_XEN; - def->id = -1; - if (xenParseXMGeneralMeta(conf, def, caps) < 0) - goto cleanup; +static int +xenParseXMOS(virConfPtr conf, virDomainDefPtr def) +{ + size_t i; if (STREQ(def->os.type, "hvm")) { const char *boot; + if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) + return -1; + + if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) + return -1; + if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0) - goto cleanup; + return -1; if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0) - goto cleanup; + return -1; for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) { switch (*boot) { @@ -1226,28 +1219,58 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, const char *extra, *root; if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0) - goto cleanup; + return -1; + if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0) - goto cleanup; + return -1; if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) - goto cleanup; + return -1; + if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) - goto cleanup; + return -1; + if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0) - goto cleanup; + return -1; + if (xenXMConfigGetString(conf, "root", &root, NULL) < 0) - goto cleanup; + return -1; if (root) { if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) - goto cleanup; + return -1; + } else { if (VIR_STRDUP(def->os.cmdline, extra) < 0) - goto cleanup; + return -1; + } } + return 0; +} +/* + * 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) +{ + virDomainDefPtr def = NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + def->virtType = VIR_DOMAIN_VIRT_XEN; + def->id = -1; + + if (xenParseXMGeneralMeta(conf, def, caps) < 0) + goto cleanup; + + if (xenParseXMOS(conf, def) < 0) + goto cleanup; + if (xenParseXMMem(conf, def) < 0) goto cleanup; @@ -1263,9 +1286,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, 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; -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMOS(virConfPtr conf,...........); which parses the OS config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 80 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 30 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 32c6d8c..b21d794 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1176,33 +1176,26 @@ xenParseXMGeneralMeta(virConfPtr conf, virDomainDefPtr def,
return 0; } -/* - * 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) -{ - virDomainDefPtr def = NULL; - size_t i;
- if (VIR_ALLOC(def) < 0) - return NULL; - - def->virtType = VIR_DOMAIN_VIRT_XEN; - def->id = -1;
- if (xenParseXMGeneralMeta(conf, def, caps) < 0) - goto cleanup; +static int +xenParseXMOS(virConfPtr conf, virDomainDefPtr def) +{ + size_t i;
if (STREQ(def->os.type, "hvm")) { const char *boot; + if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) + return -1; + + if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) + return -1;
Opps, copy and paste one time too many. This should also be outside the 'if (hvm)', as it was originally. ACK otherwise. I've fixed this up and pushed 1-12. The rest will have to wait until next week. Thanks! Regards, Jim
+ if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0) - goto cleanup; + return -1;
if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0) - goto cleanup; + return -1;
for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) { switch (*boot) { @@ -1226,28 +1219,58 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, const char *extra, *root;
if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0) - goto cleanup; + return -1; + if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0) - goto cleanup; + return -1;
if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) - goto cleanup; + return -1; + if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) - goto cleanup; + return -1; + if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0) - goto cleanup; + return -1; + if (xenXMConfigGetString(conf, "root", &root, NULL) < 0) - goto cleanup; + return -1;
if (root) { if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) - goto cleanup; + return -1; + } else { if (VIR_STRDUP(def->os.cmdline, extra) < 0) - goto cleanup; + return -1; + } }
+ return 0; +} +/* + * 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) +{ + virDomainDefPtr def = NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + def->virtType = VIR_DOMAIN_VIRT_XEN; + def->id = -1; + + if (xenParseXMGeneralMeta(conf, def, caps) < 0) + goto cleanup; + + if (xenParseXMOS(conf, def) < 0) + goto cleanup; + if (xenParseXMMem(conf, def) < 0) goto cleanup;
@@ -1263,9 +1286,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, 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;

On Fri, Aug 08, 2014 at 03:50:44PM -0600, Jim Fehlig wrote:
Kiarie Kahurani wrote:
introduce function xenParseXMOS(virConfPtr conf,...........); which parses the OS config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 80 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 50 insertions(+), 30 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 32c6d8c..b21d794 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1176,33 +1176,26 @@ xenParseXMGeneralMeta(virConfPtr conf, virDomainDefPtr def,
return 0; } -/* - * 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) -{ - virDomainDefPtr def = NULL; - size_t i;
- if (VIR_ALLOC(def) < 0) - return NULL; - - def->virtType = VIR_DOMAIN_VIRT_XEN; - def->id = -1;
- if (xenParseXMGeneralMeta(conf, def, caps) < 0) - goto cleanup; +static int +xenParseXMOS(virConfPtr conf, virDomainDefPtr def) +{ + size_t i;
if (STREQ(def->os.type, "hvm")) { const char *boot; + if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) + return -1; + + if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0) + return -1;
Opps, copy and paste one time too many. This should also be outside the 'if (hvm)', as it was originally.
ACK otherwise. I've fixed this up and pushed 1-12. The rest will have to wait until next week. Thanks!
Regards, Jim
+ if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0) - goto cleanup; + return -1;
if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0) - goto cleanup; + return -1;
for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) { switch (*boot) { @@ -1226,28 +1219,58 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, const char *extra, *root;
if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0) - goto cleanup; + return -1; + if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0) - goto cleanup; + return -1;
if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0) - goto cleanup; + return -1; + if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0) - goto cleanup; + return -1; + if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0) - goto cleanup; + return -1; + if (xenXMConfigGetString(conf, "root", &root, NULL) < 0) - goto cleanup; + return -1;
if (root) { if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0) - goto cleanup; + return -1; + } else { if (VIR_STRDUP(def->os.cmdline, extra) < 0) - goto cleanup; + return -1; + } }
+ return 0; +} +/* + * 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) +{ + virDomainDefPtr def = NULL; + + if (VIR_ALLOC(def) < 0) + return NULL; + + def->virtType = VIR_DOMAIN_VIRT_XEN; + def->id = -1; + + if (xenParseXMGeneralMeta(conf, def, caps) < 0) + goto cleanup; + + if (xenParseXMOS(conf, def) < 0) + goto cleanup; + if (xenParseXMMem(conf, def) < 0) goto cleanup;
@@ -1263,9 +1286,6 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, 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;
Thanks for fixing *sooo* much crap. What can I say, I thought "git commit" and not "git send-email" signs of the patches and hence would not resign my patches :( and again didn't check the patches after sending David.

wrap code tagged for resuse into one function and export it signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 71 ++++++++++++++++++++++++++++++++---------------------- src/xenxs/xen_xm.h | 2 ++ 2 files changed, 44 insertions(+), 29 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index b21d794..aa943ca 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1249,56 +1249,69 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def) return 0; } -/* - * 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) -{ - virDomainDefPtr def = NULL; - if (VIR_ALLOC(def) < 0) - return NULL; - def->virtType = VIR_DOMAIN_VIRT_XEN; - def->id = -1; +int +xenParseConfigCommon(virConfPtr conf, virDomainDefPtr def, + virCapsPtr caps, int xendConfigVersion) +{ if (xenParseXMGeneralMeta(conf, def, caps) < 0) - goto cleanup; + return -1; if (xenParseXMOS(conf, def) < 0) - goto cleanup; + return -1; if (xenParseXMMem(conf, def) < 0) - goto cleanup; + return -1; + + if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0) + return -1; if (xenParseXMEventsActions(conf, def) < 0) - goto cleanup; + return -1; + + if (xenParseXMPCI(conf, def) < 0) + return -1; if (xenParseXMCPUFeatures(conf, def) < 0) - goto cleanup; + return -1; - if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0) - goto cleanup; + if (xenParseXMEmulatedDevices(conf, def) < 0) + return -1; - if (xenParseXMDisk(conf, def, xendConfigVersion) < 0) - goto cleanup; + if (xenParseXMCharDev(conf, def) < 0) + return -1; + + if (xenParseXMVfb(conf, def, xendConfigVersion) < 0) + return -1; if (xenParseXMVif(conf, def) < 0) - goto cleanup; + return -1; - if (xenParseXMPCI(conf, def) < 0) - goto cleanup; + return 0; +} - if (xenParseXMEmulatedDevices(conf, def) < 0) - goto cleanup; +/* + * 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) +{ + virDomainDefPtr def = NULL; - if (xenParseXMVfb(conf, def, xendConfigVersion) < 0) + if (VIR_ALLOC(def) < 0) + return NULL; + + def->virtType = VIR_DOMAIN_VIRT_XEN; + def->id = -1; + + if (xenParseConfigCommon(conf, def, caps, xendConfigVersion) < 0) goto cleanup; - if (xenParseXMCharDev(conf, def) < 0) + if (xenParseXMDisk(conf, def, xendConfigVersion) < 0) goto cleanup; return def; diff --git a/src/xenxs/xen_xm.h b/src/xenxs/xen_xm.h index 629a4b3..5292396 100644 --- a/src/xenxs/xen_xm.h +++ b/src/xenxs/xen_xm.h @@ -35,5 +35,7 @@ virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def, virDomainDefPtr xenParseXM(virConfPtr conf, int xendConfigVersion, virCapsPtr caps); +int xenParseConfigCommon(virConfPtr conf, virDomainDefPtr def, + virCapsPtr caps, int xendConfigVersion); #endif /* __VIR_XEN_XM_H__ */ -- 1.8.4.5

introduce function xenFormatXMGeneralMeta(virConfPtr conf,......); which parses uuid and name instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index aa943ca..08d26e5 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1322,8 +1322,8 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } -static -int xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l) +static int +xenXMConfigSetInt(virConfPtr conf, const char *setting, long long l) { virConfValuePtr value = NULL; @@ -1445,8 +1445,10 @@ xenFormatXMDisk(virConfValuePtr list, return -1; } -static int xenFormatXMSerial(virConfValuePtr list, - virDomainChrDefPtr serial) + +static int +xenFormatXMSerial(virConfValuePtr list, + virDomainChrDefPtr serial) { virBuffer buf = VIR_BUFFER_INITIALIZER; virConfValuePtr val, tmp; @@ -1482,10 +1484,12 @@ static int xenFormatXMSerial(virConfValuePtr list, return -1; } -static int xenFormatXMNet(virConnectPtr conn, - virConfValuePtr list, - virDomainNetDefPtr net, - int hvm, int xendConfigVersion) + +static int +xenFormatXMNet(virConnectPtr conn, + virConfValuePtr list, + virDomainNetDefPtr net, + int hvm, int xendConfigVersion) { virBuffer buf = VIR_BUFFER_INITIALIZER; virConfValuePtr val, tmp; @@ -1587,10 +1591,8 @@ static int xenFormatXMNet(virConnectPtr conn, } - static int -xenFormatXMPCI(virConfPtr conf, - virDomainDefPtr def) +xenFormatXMPCI(virConfPtr conf, virDomainDefPtr def) { virConfValuePtr pciVal = NULL; @@ -1656,32 +1658,41 @@ xenFormatXMPCI(virConfPtr conf, } +static int +xenFormatXMGeneralMeta(virConfPtr conf, virDomainDefPtr def) +{ + char uuid[VIR_UUID_STRING_BUFLEN]; + + if (xenXMConfigSetString(conf, "name", def->name) < 0) + return -1; + + virUUIDFormat(def->uuid, uuid); + if (xenXMConfigSetString(conf, "uuid", uuid) < 0) + return -1; + + return 0; +} /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); -virConfPtr xenFormatXM(virConnectPtr conn, - virDomainDefPtr def, - int xendConfigVersion) +virConfPtr +xenFormatXM(virConnectPtr conn, + virDomainDefPtr def, + int xendConfigVersion) { virConfPtr conf = NULL; int hvm = 0, vmlocaltime = 0; size_t i; char *cpus = NULL; const char *lifecycle; - char uuid[VIR_UUID_STRING_BUFLEN]; virConfValuePtr diskVal = NULL; virConfValuePtr netVal = NULL; if (!(conf = virConfNew())) goto cleanup; - - if (xenXMConfigSetString(conf, "name", def->name) < 0) - goto cleanup; - - virUUIDFormat(def->uuid, uuid); - if (xenXMConfigSetString(conf, "uuid", uuid) < 0) + if (xenFormatXMGeneralMeta(conf, def) < 0) goto cleanup; if (xenXMConfigSetInt(conf, "maxmem", -- 1.8.4.5

introduce function xenFormatXMMem(virConfPtr conf,...........); which parses memory config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 08d26e5..350aeeb 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1672,6 +1672,23 @@ xenFormatXMGeneralMeta(virConfPtr conf, virDomainDefPtr def) return 0; } + + +static int +xenFormatXMMem(virConfPtr conf, virDomainDefPtr def) +{ + if (xenXMConfigSetInt(conf, "maxmem", + VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0) + return -1; + + if (xenXMConfigSetInt(conf, "memory", + VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0) + return -1; + + return 0; +} + + /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -1695,12 +1712,7 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMGeneralMeta(conf, def) < 0) goto cleanup; - if (xenXMConfigSetInt(conf, "maxmem", - VIR_DIV_UP(def->mem.max_balloon, 1024)) < 0) - goto cleanup; - - if (xenXMConfigSetInt(conf, "memory", - VIR_DIV_UP(def->mem.cur_balloon, 1024)) < 0) + if (xenFormatXMMem(conf, def) < 0) goto cleanup; if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0) -- 1.8.4.5

introduce function xenFormatXMTimeOffset(virConfPtr conf,........); which formats time config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 153 ++++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 71 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 350aeeb..5f092dc 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1689,6 +1689,86 @@ xenFormatXMMem(virConfPtr conf, virDomainDefPtr def) } +static int +xenFormatXMTimeOffset(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + int vmlocaltime; + if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) { + /* <3.1: UTC and LOCALTIME */ + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + vmlocaltime = 0; + break; + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + vmlocaltime = 1; + break; + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported clock offset='%s'"), + virDomainClockOffsetTypeToString(def->clock.offset)); + return -1; + } + + } else { + if (STREQ(def->os.type, "hvm")) { + /* >=3.1 HV: VARIABLE */ + int rtc_timeoffset; + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: + vmlocaltime = (int)def->clock.data.variable.basis; + rtc_timeoffset = def->clock.data.variable.adjustment; + break; + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + if (def->clock.data.utc_reset) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unsupported clock adjustment='reset'")); + return -1; + } + vmlocaltime = 0; + rtc_timeoffset = 0; + break; + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + if (def->clock.data.utc_reset) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unsupported clock adjustment='reset'")); + return -1; + } + vmlocaltime = 1; + rtc_timeoffset = 0; + break; + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported clock offset='%s'"), + virDomainClockOffsetTypeToString(def->clock.offset)); + return -1; + } + if (xenXMConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) < 0) + return -1; + + } else { + /* >=3.1 PV: UTC and LOCALTIME */ + switch (def->clock.offset) { + case VIR_DOMAIN_CLOCK_OFFSET_UTC: + vmlocaltime = 0; + break; + case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: + vmlocaltime = 1; + break; + default: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("unsupported clock offset='%s'"), + virDomainClockOffsetTypeToString(def->clock.offset)); + return -1; + } + } /* !hvm */ + } + + if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0) + return -1; + + return 0; +} /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -1699,7 +1779,7 @@ xenFormatXM(virConnectPtr conn, int xendConfigVersion) { virConfPtr conf = NULL; - int hvm = 0, vmlocaltime = 0; + int hvm = 0; size_t i; char *cpus = NULL; const char *lifecycle; @@ -1838,78 +1918,9 @@ xenFormatXM(virConnectPtr conn, goto cleanup; } /* !hvm */ - - if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) { - /* <3.1: UTC and LOCALTIME */ - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - vmlocaltime = 0; - break; - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - vmlocaltime = 1; - break; - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported clock offset='%s'"), - virDomainClockOffsetTypeToString(def->clock.offset)); - goto cleanup; - } - } else { - if (hvm) { - /* >=3.1 HV: VARIABLE */ - int rtc_timeoffset; - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_VARIABLE: - vmlocaltime = (int)def->clock.data.variable.basis; - rtc_timeoffset = def->clock.data.variable.adjustment; - break; - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - if (def->clock.data.utc_reset) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unsupported clock adjustment='reset'")); - goto cleanup; - } - vmlocaltime = 0; - rtc_timeoffset = 0; - break; - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - if (def->clock.data.utc_reset) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unsupported clock adjustment='reset'")); - goto cleanup; - } - vmlocaltime = 1; - rtc_timeoffset = 0; - break; - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported clock offset='%s'"), - virDomainClockOffsetTypeToString(def->clock.offset)); - goto cleanup; - } - if (xenXMConfigSetInt(conf, "rtc_timeoffset", rtc_timeoffset) < 0) - goto cleanup; - } else { - /* >=3.1 PV: UTC and LOCALTIME */ - switch (def->clock.offset) { - case VIR_DOMAIN_CLOCK_OFFSET_UTC: - vmlocaltime = 0; - break; - case VIR_DOMAIN_CLOCK_OFFSET_LOCALTIME: - vmlocaltime = 1; - break; - default: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("unsupported clock offset='%s'"), - virDomainClockOffsetTypeToString(def->clock.offset)); - goto cleanup; - } - } /* !hvm */ - } - if (xenXMConfigSetInt(conf, "localtime", vmlocaltime) < 0) + if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) goto cleanup; - if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unexpected lifecycle action %d"), def->onPoweroff); -- 1.8.4.5

introduce function xenFormatXMEventActions(virConfPtr conf,.........); which formats event actions instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 63 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 36 insertions(+), 27 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 5f092dc..c3e7cde 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1769,6 +1769,41 @@ xenFormatXMTimeOffset(virConfPtr conf, virDomainDefPtr def, return 0; } + + +static int +xenFormatXMEventActions(virConfPtr conf, virDomainDefPtr def) +{ + const char *lifecycle = NULL; + + if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected lifecycle action %d"), def->onPoweroff); + return -1; + } + if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0) + return -1; + + + if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected lifecycle action %d"), def->onReboot); + return -1; + } + if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0) + return -1; + + + if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("unexpected lifecycle action %d"), def->onCrash); + return -1; + } + if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0) + return -1; + + return 0; +} /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -1782,7 +1817,6 @@ xenFormatXM(virConnectPtr conn, int hvm = 0; size_t i; char *cpus = NULL; - const char *lifecycle; virConfValuePtr diskVal = NULL; virConfValuePtr netVal = NULL; @@ -1921,33 +1955,8 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) goto cleanup; - if (!(lifecycle = virDomainLifecycleTypeToString(def->onPoweroff))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected lifecycle action %d"), def->onPoweroff); - goto cleanup; - } - if (xenXMConfigSetString(conf, "on_poweroff", lifecycle) < 0) - goto cleanup; - - - if (!(lifecycle = virDomainLifecycleTypeToString(def->onReboot))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected lifecycle action %d"), def->onReboot); + if (xenFormatXMEventActions(conf, def) < 0) goto cleanup; - } - if (xenXMConfigSetString(conf, "on_reboot", lifecycle) < 0) - goto cleanup; - - - if (!(lifecycle = virDomainLifecycleCrashTypeToString(def->onCrash))) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("unexpected lifecycle action %d"), def->onCrash); - goto cleanup; - } - if (xenXMConfigSetString(conf, "on_crash", lifecycle) < 0) - goto cleanup; - - if (hvm) { if (def->emulator && -- 1.8.4.5

introduce function xenFormatXMCharDev(virConfPtr conf,........); which formats Char devices config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 163 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 91 insertions(+), 72 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index c3e7cde..6752b27 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1804,6 +1804,94 @@ xenFormatXMEventActions(virConfPtr conf, virDomainDefPtr def) return 0; } + + +static int +xenFormatXMCharDev(virConfPtr conf, virDomainDefPtr def) +{ + size_t i; + + if (STREQ(def->os.type, "hvm")) { + if (def->nparallels) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + char *str; + int ret; + + ret = xenFormatSxprChr(def->parallels[0], &buf); + str = virBufferContentAndReset(&buf); + if (ret == 0) + ret = xenXMConfigSetString(conf, "parallel", str); + VIR_FREE(str); + if (ret < 0) + return -1; + + } else { + if (xenXMConfigSetString(conf, "parallel", "none") < 0) + return -1; + } + + if (def->nserials) { + if ((def->nserials == 1) && (def->serials[0]->target.port == 0)) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + char *str; + int ret; + + ret = xenFormatSxprChr(def->serials[0], &buf); + str = virBufferContentAndReset(&buf); + if (ret == 0) + ret = xenXMConfigSetString(conf, "serial", str); + VIR_FREE(str); + if (ret < 0) + return -1; + + } else { + size_t j = 0; + int maxport = -1, port; + virConfValuePtr serialVal = NULL; + + if (VIR_ALLOC(serialVal) < 0) + return -1; + + serialVal->type = VIR_CONF_LIST; + serialVal->list = NULL; + + for (i = 0; i < def->nserials; i++) + if (def->serials[i]->target.port > maxport) + maxport = def->serials[i]->target.port; + + for (port = 0; port <= maxport; port++) { + virDomainChrDefPtr chr = NULL; + for (j = 0; j < def->nserials; j++) { + if (def->serials[j]->target.port == port) { + chr = def->serials[j]; + break; + } + } + + if (xenFormatXMSerial(serialVal, chr) < 0) { + VIR_FREE(serialVal); + return -1; + } + } + + if (serialVal->list != NULL) { + int ret = virConfSetValue(conf, "serial", serialVal); + serialVal = NULL; + if (ret < 0) + return -1; + } + VIR_FREE(serialVal); + } + } else { + if (xenXMConfigSetString(conf, "serial", "none") < 0) + return -1; + } + } + + return 0; +} + + /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -2134,79 +2222,10 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMPCI(conf, def) < 0) goto cleanup; - if (hvm) { - if (def->nparallels) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - char *str; - int ret; - - ret = xenFormatSxprChr(def->parallels[0], &buf); - str = virBufferContentAndReset(&buf); - if (ret == 0) - ret = xenXMConfigSetString(conf, "parallel", str); - VIR_FREE(str); - if (ret < 0) - goto cleanup; - } else { - if (xenXMConfigSetString(conf, "parallel", "none") < 0) - goto cleanup; - } - - if (def->nserials) { - if ((def->nserials == 1) && (def->serials[0]->target.port == 0)) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - char *str; - int ret; - - ret = xenFormatSxprChr(def->serials[0], &buf); - str = virBufferContentAndReset(&buf); - if (ret == 0) - ret = xenXMConfigSetString(conf, "serial", str); - VIR_FREE(str); - if (ret < 0) - goto cleanup; - } else { - size_t j = 0; - int maxport = -1, port; - virConfValuePtr serialVal = NULL; - - if (VIR_ALLOC(serialVal) < 0) - goto cleanup; - serialVal->type = VIR_CONF_LIST; - serialVal->list = NULL; - - for (i = 0; i < def->nserials; i++) - if (def->serials[i]->target.port > maxport) - maxport = def->serials[i]->target.port; - - for (port = 0; port <= maxport; port++) { - virDomainChrDefPtr chr = NULL; - for (j = 0; j < def->nserials; j++) { - if (def->serials[j]->target.port == port) { - chr = def->serials[j]; - break; - } - } - if (xenFormatXMSerial(serialVal, chr) < 0) { - virConfFreeValue(serialVal); - goto cleanup; - } - } - - if (serialVal->list != NULL) { - int ret = virConfSetValue(conf, "serial", serialVal); - serialVal = NULL; - if (ret < 0) - goto cleanup; - } - VIR_FREE(serialVal); - } - } else { - if (xenXMConfigSetString(conf, "serial", "none") < 0) - goto cleanup; - } - + if (xenFormatXMCharDev(conf, def) < 0) + goto cleanup; + if (hvm) { if (def->sounds) { virBuffer buf = VIR_BUFFER_INITIALIZER; char *str = NULL; -- 1.8.4.5

introduce function xenFormatXMDomainDisks(virConfPtr conf,.........); which formats domain disks config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 72 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 6752b27..5a585ce 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1892,6 +1892,49 @@ xenFormatXMCharDev(virConfPtr conf, virDomainDefPtr def) } +static int +xenFormatXMDomainDisks(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + virConfValuePtr diskVal = NULL; + size_t i = 0; + int hvm = STREQ(def->os.type, "hvm"); + + if (VIR_ALLOC(diskVal) < 0) + goto cleanup; + + diskVal->type = VIR_CONF_LIST; + diskVal->list = NULL; + + for (i = 0; i < def->ndisks; i++) { + if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2 && + def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM && + def->disks[i]->dst && + STREQ(def->disks[i]->dst, "hdc")) { + continue; + } + + if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) + continue; + + if (xenFormatXMDisk(diskVal, def->disks[i], + hvm, xendConfigVersion) < 0) + goto cleanup; + } + + if (diskVal->list != NULL) { + int ret = virConfSetValue(conf, "disk", diskVal); + diskVal = NULL; + if (ret < 0) + goto cleanup; + } + + return 0; + + cleanup: + virConfFreeValue(diskVal); + return -1; +} /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -1905,7 +1948,6 @@ xenFormatXM(virConnectPtr conn, int hvm = 0; size_t i; char *cpus = NULL; - virConfValuePtr diskVal = NULL; virConfValuePtr netVal = NULL; if (!(conf = virConfNew())) @@ -2173,33 +2215,8 @@ xenFormatXM(virConnectPtr conn, } } - /* analyze of the devices */ - if (VIR_ALLOC(diskVal) < 0) + if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0) goto cleanup; - diskVal->type = VIR_CONF_LIST; - diskVal->list = NULL; - - for (i = 0; i < def->ndisks; i++) { - if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2 && - def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM && - def->disks[i]->dst && - STREQ(def->disks[i]->dst, "hdc")) { - continue; - } - if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) - continue; - - if (xenFormatXMDisk(diskVal, def->disks[i], - hvm, xendConfigVersion) < 0) - goto cleanup; - } - if (diskVal->list != NULL) { - int ret = virConfSetValue(conf, "disk", diskVal); - diskVal = NULL; - if (ret < 0) - goto cleanup; - } - VIR_FREE(diskVal); if (VIR_ALLOC(netVal) < 0) goto cleanup; @@ -2243,7 +2260,6 @@ xenFormatXM(virConnectPtr conn, return conf; cleanup: - virConfFreeValue(diskVal); virConfFreeValue(netVal); VIR_FREE(cpus); if (conf) -- 1.8.4.5

introduce function xenFormatXMCPUFeatures(virConfPtr conf, ......); which formats CPU features config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 118 ++++++++++++--------- tests/xmconfigdata/test-escape-paths.cfg | 6 +- tests/xmconfigdata/test-fullvirt-force-hpet.cfg | 6 +- tests/xmconfigdata/test-fullvirt-force-nohpet.cfg | 6 +- tests/xmconfigdata/test-fullvirt-localtime.cfg | 6 +- tests/xmconfigdata/test-fullvirt-net-ioemu.cfg | 6 +- tests/xmconfigdata/test-fullvirt-net-netfront.cfg | 6 +- tests/xmconfigdata/test-fullvirt-new-cdrom.cfg | 6 +- tests/xmconfigdata/test-fullvirt-old-cdrom.cfg | 6 +- tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg | 6 +- .../test-fullvirt-serial-dev-2-ports.cfg | 6 +- .../test-fullvirt-serial-dev-2nd-port.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-file.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-null.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-pipe.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-pty.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-stdio.cfg | 6 +- .../test-fullvirt-serial-tcp-telnet.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-tcp.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-udp.cfg | 6 +- tests/xmconfigdata/test-fullvirt-serial-unix.cfg | 6 +- tests/xmconfigdata/test-fullvirt-sound.cfg | 6 +- tests/xmconfigdata/test-fullvirt-usbmouse.cfg | 6 +- tests/xmconfigdata/test-fullvirt-usbtablet.cfg | 6 +- tests/xmconfigdata/test-fullvirt-utc.cfg | 6 +- tests/xmconfigdata/test-no-source-cdrom.cfg | 6 +- tests/xmconfigdata/test-pci-devs.cfg | 6 +- 27 files changed, 146 insertions(+), 128 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 5a585ce..6bd04ba 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -1935,6 +1935,73 @@ xenFormatXMDomainDisks(virConfPtr conf, virDomainDefPtr def, virConfFreeValue(diskVal); return -1; } + + +static int +xenFormatXMCPUFeatures(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + char *cpus = NULL; + size_t i; + + if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0) + return -1; + /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is + either 32, or 64 on a platform where long is big enough. */ + if (def->vcpus < def->maxvcpus && + xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0) + return -1; + + if ((def->cpumask != NULL) && + ((cpus = virBitmapFormat(def->cpumask)) == NULL)) { + return -1; + } + + if (cpus && + xenXMConfigSetString(conf, "cpus", cpus) < 0) + return -1; + + VIR_FREE(cpus); + if (STREQ(def->os.type, "hvm")) { + if (xenXMConfigSetInt(conf, "pae", + (def->features[VIR_DOMAIN_FEATURE_PAE] == + VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) + return -1; + + if (xenXMConfigSetInt(conf, "acpi", + (def->features[VIR_DOMAIN_FEATURE_ACPI] == + VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) + return -1; + + if (xenXMConfigSetInt(conf, "apic", + (def->features[VIR_DOMAIN_FEATURE_APIC] == + VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) + return -1; + + if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) { + if (xenXMConfigSetInt(conf, "hap", + (def->features[VIR_DOMAIN_FEATURE_HAP] == + VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) + return -1; + + if (xenXMConfigSetInt(conf, "viridian", + (def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] == + VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) + return -1; + } + + for (i = 0; i < def->clock.ntimers; i++) { + if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET && + def->clock.timers[i]->present != -1 && + xenXMConfigSetInt(conf, "hpet", def->clock.timers[i]->present) < 0) + return -1; + } + } + + return 0; +} + + /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -1959,24 +2026,9 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMMem(conf, def) < 0) goto cleanup; - if (xenXMConfigSetInt(conf, "vcpus", def->maxvcpus) < 0) - goto cleanup; - /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ - if (def->vcpus < def->maxvcpus && - xenXMConfigSetInt(conf, "vcpu_avail", (1UL << def->vcpus) - 1) < 0) + if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) goto cleanup; - if ((def->cpumask != NULL) && - ((cpus = virBitmapFormat(def->cpumask)) == NULL)) { - goto cleanup; - } - - if (cpus && - xenXMConfigSetString(conf, "cpus", cpus) < 0) - goto cleanup; - VIR_FREE(cpus); - hvm = STREQ(def->os.type, "hvm") ? 1 : 0; if (hvm) { @@ -2015,40 +2067,6 @@ xenFormatXM(virConnectPtr conn, if (xenXMConfigSetString(conf, "boot", boot) < 0) goto cleanup; - if (xenXMConfigSetInt(conf, "pae", - (def->features[VIR_DOMAIN_FEATURE_PAE] == - VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) - goto cleanup; - - if (xenXMConfigSetInt(conf, "acpi", - (def->features[VIR_DOMAIN_FEATURE_ACPI] == - VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) - goto cleanup; - - if (xenXMConfigSetInt(conf, "apic", - (def->features[VIR_DOMAIN_FEATURE_APIC] == - VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) - goto cleanup; - - if (xendConfigVersion >= XEND_CONFIG_VERSION_3_0_4) { - if (xenXMConfigSetInt(conf, "hap", - (def->features[VIR_DOMAIN_FEATURE_HAP] == - VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) - goto cleanup; - - if (xenXMConfigSetInt(conf, "viridian", - (def->features[VIR_DOMAIN_FEATURE_VIRIDIAN] == - VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0) - goto cleanup; - } - - for (i = 0; i < def->clock.ntimers; i++) { - if (def->clock.timers[i]->name == VIR_DOMAIN_TIMER_NAME_HPET && - def->clock.timers[i]->present != -1 && - xenXMConfigSetInt(conf, "hpet", def->clock.timers[i]->present) < 0) - goto cleanup; - } - if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) { for (i = 0; i < def->ndisks; i++) { if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM && diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg index 13be2a0..4a18cc1 100644 --- a/tests/xmconfigdata/test-escape-paths.cfg +++ b/tests/xmconfigdata/test-escape-paths.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader&test" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader&test" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-force-hpet.cfg b/tests/xmconfigdata/test-fullvirt-force-hpet.cfg index 178aecd..c1afc08 100644 --- a/tests/xmconfigdata/test-fullvirt-force-hpet.cfg +++ b/tests/xmconfigdata/test-fullvirt-force-hpet.cfg @@ -3,13 +3,13 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 hpet = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg b/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg index 44f5ac7..397d8ef 100644 --- a/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg +++ b/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg @@ -3,13 +3,13 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 hpet = 0 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-localtime.cfg b/tests/xmconfigdata/test-fullvirt-localtime.cfg index d4eb4a9..7292e7f 100755 --- a/tests/xmconfigdata/test-fullvirt-localtime.cfg +++ b/tests/xmconfigdata/test-fullvirt-localtime.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 1 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg b/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg index 922450b..ef97329 100644 --- a/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg +++ b/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-net-netfront.cfg b/tests/xmconfigdata/test-fullvirt-net-netfront.cfg index d15f1f5..385f917 100644 --- a/tests/xmconfigdata/test-fullvirt-net-netfront.cfg +++ b/tests/xmconfigdata/test-fullvirt-net-netfront.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg index 922450b..ef97329 100755 --- a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg +++ b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg index 5d2ab81..27407e7 100755 --- a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg +++ b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" cdrom = "/root/boot.iso" localtime = 0 on_poweroff = "destroy" diff --git a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg index 4588f1f..86e0aa0 100755 --- a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg +++ b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg b/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg index 86e7998..8ada1fd 100644 --- a/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg b/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg index 287e08a..61e2af3 100644 --- a/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-file.cfg b/tests/xmconfigdata/test-fullvirt-serial-file.cfg index 08accf6..ad4a874 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-file.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-file.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-null.cfg b/tests/xmconfigdata/test-fullvirt-serial-null.cfg index f16c9c2..a11c42a 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-null.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-null.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg index 1e1fa54..1ee0bc8 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg index ea4d4a5..10465a5 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg index a4e30c5..3733161 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg index 2164738..442309f 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg index 7f17781..f141269 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg index 1af3c7b..3ccc4a7 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg index 309c89e..dd250ac 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-sound.cfg b/tests/xmconfigdata/test-fullvirt-sound.cfg index c4f54fe..d315f93 100644 --- a/tests/xmconfigdata/test-fullvirt-sound.cfg +++ b/tests/xmconfigdata/test-fullvirt-sound.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg index 8a66035..3d30bb1 100755 --- a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg +++ b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg index 24c159e..4463e31 100755 --- a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg +++ b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-fullvirt-utc.cfg b/tests/xmconfigdata/test-fullvirt-utc.cfg index 922450b..ef97329 100755 --- a/tests/xmconfigdata/test-fullvirt-utc.cfg +++ b/tests/xmconfigdata/test-fullvirt-utc.cfg @@ -3,12 +3,12 @@ uuid = "c7a5fdb2-cdaf-9455-926a-d65c16db1809" maxmem = 579 memory = 394 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "d" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "d" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" diff --git a/tests/xmconfigdata/test-no-source-cdrom.cfg b/tests/xmconfigdata/test-no-source-cdrom.cfg index 7b258e5..ee22632 100644 --- a/tests/xmconfigdata/test-no-source-cdrom.cfg +++ b/tests/xmconfigdata/test-no-source-cdrom.cfg @@ -3,12 +3,12 @@ uuid = "cc2315e7-d26a-307a-438c-6d188ec4c09c" maxmem = 382 memory = 350 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "c" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "c" localtime = 0 on_poweroff = "destroy" on_reboot = "destroy" diff --git a/tests/xmconfigdata/test-pci-devs.cfg b/tests/xmconfigdata/test-pci-devs.cfg index 9f9b2f4..6d19f21 100644 --- a/tests/xmconfigdata/test-pci-devs.cfg +++ b/tests/xmconfigdata/test-pci-devs.cfg @@ -3,12 +3,12 @@ uuid = "cc2315e7-d26a-307a-438c-6d188ec4c09c" maxmem = 382 memory = 350 vcpus = 1 -builder = "hvm" -kernel = "/usr/lib/xen/boot/hvmloader" -boot = "c" pae = 1 acpi = 1 apic = 1 +builder = "hvm" +kernel = "/usr/lib/xen/boot/hvmloader" +boot = "c" localtime = 0 on_poweroff = "destroy" on_reboot = "destroy" -- 1.8.4.5

introduce function xenFormatXMOS(virConfPtr conf,........); which formats OS config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 95 ++++++++++++---------- tests/xmconfigdata/test-escape-paths.cfg | 2 +- tests/xmconfigdata/test-fullvirt-force-hpet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-force-nohpet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-localtime.cfg | 2 +- tests/xmconfigdata/test-fullvirt-net-ioemu.cfg | 2 +- tests/xmconfigdata/test-fullvirt-net-netfront.cfg | 2 +- tests/xmconfigdata/test-fullvirt-new-cdrom.cfg | 2 +- tests/xmconfigdata/test-fullvirt-old-cdrom.cfg | 2 +- tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg | 2 +- .../test-fullvirt-serial-dev-2-ports.cfg | 2 +- .../test-fullvirt-serial-dev-2nd-port.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-file.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-null.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-pipe.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-pty.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-stdio.cfg | 2 +- .../test-fullvirt-serial-tcp-telnet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-tcp.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-udp.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-unix.cfg | 2 +- tests/xmconfigdata/test-fullvirt-sound.cfg | 2 +- tests/xmconfigdata/test-fullvirt-usbmouse.cfg | 2 +- tests/xmconfigdata/test-fullvirt-usbtablet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-utc.cfg | 2 +- tests/xmconfigdata/test-no-source-cdrom.cfg | 2 +- tests/xmconfigdata/test-pci-devs.cfg | 2 +- 27 files changed, 80 insertions(+), 67 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 6bd04ba..9db159d 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2002,43 +2002,20 @@ xenFormatXMCPUFeatures(virConfPtr conf, virDomainDefPtr def, } -/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ -verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); - -virConfPtr -xenFormatXM(virConnectPtr conn, - virDomainDefPtr def, - int xendConfigVersion) +static int +xenFormatXMOS(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) { - virConfPtr conf = NULL; - int hvm = 0; size_t i; - char *cpus = NULL; - virConfValuePtr netVal = NULL; - - if (!(conf = virConfNew())) - goto cleanup; - - if (xenFormatXMGeneralMeta(conf, def) < 0) - goto cleanup; - - if (xenFormatXMMem(conf, def) < 0) - goto cleanup; - if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) - goto cleanup; - - hvm = STREQ(def->os.type, "hvm") ? 1 : 0; - - if (hvm) { + if (STREQ(def->os.type, "hvm")) { char boot[VIR_DOMAIN_BOOT_LAST+1]; if (xenXMConfigSetString(conf, "builder", "hvm") < 0) - goto cleanup; + return -1; if (def->os.loader && xenXMConfigSetString(conf, "kernel", def->os.loader) < 0) - goto cleanup; + return -1; for (i = 0; i < def->os.nBootDevs; i++) { switch (def->os.bootDevs[i]) { @@ -2065,7 +2042,7 @@ xenFormatXM(virConnectPtr conn, } if (xenXMConfigSetString(conf, "boot", boot) < 0) - goto cleanup; + return -1; if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) { for (i = 0; i < def->ndisks; i++) { @@ -2075,31 +2052,72 @@ xenFormatXM(virConnectPtr conn, virDomainDiskGetSource(def->disks[i])) { if (xenXMConfigSetString(conf, "cdrom", virDomainDiskGetSource(def->disks[i])) < 0) - goto cleanup; + return -1; + break; } } } + if (def->emulator && + xenXMConfigSetString(conf, "device_model", def->emulator) < 0) + return -1; /* XXX floppy disks */ } else { if (def->os.bootloader && xenXMConfigSetString(conf, "bootloader", def->os.bootloader) < 0) - goto cleanup; + return -1; + if (def->os.bootloaderArgs && xenXMConfigSetString(conf, "bootargs", def->os.bootloaderArgs) < 0) - goto cleanup; + return -1; + if (def->os.kernel && xenXMConfigSetString(conf, "kernel", def->os.kernel) < 0) - goto cleanup; + return -1; + if (def->os.initrd && xenXMConfigSetString(conf, "ramdisk", def->os.initrd) < 0) - goto cleanup; + return -1; + if (def->os.cmdline && xenXMConfigSetString(conf, "extra", def->os.cmdline) < 0) - goto cleanup; + return -1; } /* !hvm */ + return 0; +} +/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is + either 32, or 64 on a platform where long is big enough. */ +verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); + +virConfPtr +xenFormatXM(virConnectPtr conn, + virDomainDefPtr def, + int xendConfigVersion) +{ + virConfPtr conf = NULL; + int hvm = 0; + size_t i; + virConfValuePtr netVal = NULL; + + if (!(conf = virConfNew())) + goto cleanup; + + if (xenFormatXMGeneralMeta(conf, def) < 0) + goto cleanup; + + if (xenFormatXMMem(conf, def) < 0) + goto cleanup; + + if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) + goto cleanup; + + hvm = STREQ(def->os.type, "hvm"); + + if (xenFormatXMOS(conf, def, xendConfigVersion) < 0) + goto cleanup; + if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) goto cleanup; @@ -2107,10 +2125,6 @@ xenFormatXM(virConnectPtr conn, goto cleanup; if (hvm) { - if (def->emulator && - xenXMConfigSetString(conf, "device_model", def->emulator) < 0) - goto cleanup; - for (i = 0; i < def->ninputs; i++) { if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { if (xenXMConfigSetInt(conf, "usb", 1) < 0) @@ -2279,7 +2293,6 @@ xenFormatXM(virConnectPtr conn, cleanup: virConfFreeValue(netVal); - VIR_FREE(cpus); if (conf) virConfFree(conf); return NULL; diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg index 4a18cc1..68984da 100644 --- a/tests/xmconfigdata/test-escape-paths.cfg +++ b/tests/xmconfigdata/test-escape-paths.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader&test" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm&test" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm&test" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-force-hpet.cfg b/tests/xmconfigdata/test-fullvirt-force-hpet.cfg index c1afc08..f2377dc 100644 --- a/tests/xmconfigdata/test-fullvirt-force-hpet.cfg +++ b/tests/xmconfigdata/test-fullvirt-force-hpet.cfg @@ -10,11 +10,11 @@ hpet = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg b/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg index 397d8ef..093c8de 100644 --- a/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg +++ b/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg @@ -10,11 +10,11 @@ hpet = 0 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-localtime.cfg b/tests/xmconfigdata/test-fullvirt-localtime.cfg index 7292e7f..34ea100 100755 --- a/tests/xmconfigdata/test-fullvirt-localtime.cfg +++ b/tests/xmconfigdata/test-fullvirt-localtime.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 1 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg b/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg index ef97329..a4f3aec 100644 --- a/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg +++ b/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-net-netfront.cfg b/tests/xmconfigdata/test-fullvirt-net-netfront.cfg index 385f917..57cff7b 100644 --- a/tests/xmconfigdata/test-fullvirt-net-netfront.cfg +++ b/tests/xmconfigdata/test-fullvirt-net-netfront.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg index ef97329..a4f3aec 100755 --- a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg +++ b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg index 27407e7..9b74db4 100755 --- a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg +++ b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg @@ -10,11 +10,11 @@ builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" cdrom = "/root/boot.iso" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg index 86e0aa0..6a0e1ac 100755 --- a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg +++ b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg b/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg index 8ada1fd..2021ac3 100644 --- a/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg b/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg index 61e2af3..0200194 100644 --- a/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-file.cfg b/tests/xmconfigdata/test-fullvirt-serial-file.cfg index ad4a874..4602516 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-file.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-file.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-null.cfg b/tests/xmconfigdata/test-fullvirt-serial-null.cfg index a11c42a..c8365e8 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-null.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-null.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg index 1ee0bc8..f30a072 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg index 10465a5..bb490b0 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg index 3733161..6583076 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg index 442309f..730b2e8 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg index f141269..3a15c11 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg index 3ccc4a7..5b7804d 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg index dd250ac..6cd7272 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-sound.cfg b/tests/xmconfigdata/test-fullvirt-sound.cfg index d315f93..a12a30c 100644 --- a/tests/xmconfigdata/test-fullvirt-sound.cfg +++ b/tests/xmconfigdata/test-fullvirt-sound.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg index 3d30bb1..be27f08 100755 --- a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg +++ b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" usb = 1 usbdevice = "mouse" sdl = 0 diff --git a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg index 4463e31..5e84e7e 100755 --- a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg +++ b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" usb = 1 usbdevice = "tablet" sdl = 0 diff --git a/tests/xmconfigdata/test-fullvirt-utc.cfg b/tests/xmconfigdata/test-fullvirt-utc.cfg index ef97329..a4f3aec 100755 --- a/tests/xmconfigdata/test-fullvirt-utc.cfg +++ b/tests/xmconfigdata/test-fullvirt-utc.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "d" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-no-source-cdrom.cfg b/tests/xmconfigdata/test-no-source-cdrom.cfg index ee22632..27bec8d 100644 --- a/tests/xmconfigdata/test-no-source-cdrom.cfg +++ b/tests/xmconfigdata/test-no-source-cdrom.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "c" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "destroy" on_crash = "destroy" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 diff --git a/tests/xmconfigdata/test-pci-devs.cfg b/tests/xmconfigdata/test-pci-devs.cfg index 6d19f21..a24a09c 100644 --- a/tests/xmconfigdata/test-pci-devs.cfg +++ b/tests/xmconfigdata/test-pci-devs.cfg @@ -9,11 +9,11 @@ apic = 1 builder = "hvm" kernel = "/usr/lib/xen/boot/hvmloader" boot = "c" +device_model = "/usr/lib/xen/bin/qemu-dm" localtime = 0 on_poweroff = "destroy" on_reboot = "destroy" on_crash = "destroy" -device_model = "/usr/lib/xen/bin/qemu-dm" sdl = 0 vnc = 1 vncunused = 1 -- 1.8.4.5

introduce function xenFormatXMVfb(virConfPtr conf,.........); which formats Vfb config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 171 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 97 insertions(+), 74 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 9db159d..bf5a23a 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2087,108 +2087,65 @@ xenFormatXMOS(virConfPtr conf, virDomainDefPtr def, return 0; } -/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ -verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); - -virConfPtr -xenFormatXM(virConnectPtr conn, - virDomainDefPtr def, - int xendConfigVersion) -{ - virConfPtr conf = NULL; - int hvm = 0; - size_t i; - virConfValuePtr netVal = NULL; - - if (!(conf = virConfNew())) - goto cleanup; - - if (xenFormatXMGeneralMeta(conf, def) < 0) - goto cleanup; - - if (xenFormatXMMem(conf, def) < 0) - goto cleanup; - - if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) - goto cleanup; - - hvm = STREQ(def->os.type, "hvm"); - if (xenFormatXMOS(conf, def, xendConfigVersion) < 0) - goto cleanup; - - if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) - goto cleanup; - if (xenFormatXMEventActions(conf, def) < 0) - goto cleanup; - - if (hvm) { - for (i = 0; i < def->ninputs; i++) { - if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { - if (xenXMConfigSetInt(conf, "usb", 1) < 0) - goto cleanup; - switch (def->inputs[i]->type) { - case VIR_DOMAIN_INPUT_TYPE_MOUSE: - if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) - goto cleanup; - break; - case VIR_DOMAIN_INPUT_TYPE_TABLET: - if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) - goto cleanup; - break; - case VIR_DOMAIN_INPUT_TYPE_KBD: - if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) - goto cleanup; - break; - } - break; - } - } - } +static int +xenFormatXMVfb(virConfPtr conf, virDomainDefPtr def, + int xendConfigVersion) +{ + int hvm = STREQ(def->os.type, "hvm"); if (def->ngraphics == 1) { if (hvm || (xendConfigVersion < XEND_CONFIG_MIN_VERS_PVFB_NEWCONF)) { if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) { if (xenXMConfigSetInt(conf, "sdl", 1) < 0) - goto cleanup; + return -1; + if (xenXMConfigSetInt(conf, "vnc", 0) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.sdl.display && xenXMConfigSetString(conf, "display", def->graphics[0]->data.sdl.display) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.sdl.xauth && xenXMConfigSetString(conf, "xauthority", def->graphics[0]->data.sdl.xauth) < 0) - goto cleanup; + return -1; + } else { const char *listenAddr; if (xenXMConfigSetInt(conf, "sdl", 0) < 0) - goto cleanup; + return -1; + if (xenXMConfigSetInt(conf, "vnc", 1) < 0) - goto cleanup; + return -1; + if (xenXMConfigSetInt(conf, "vncunused", def->graphics[0]->data.vnc.autoport ? 1 : 0) < 0) - goto cleanup; + return -1; + if (!def->graphics[0]->data.vnc.autoport && xenXMConfigSetInt(conf, "vncdisplay", def->graphics[0]->data.vnc.port - 5900) < 0) - goto cleanup; + return -1; + listenAddr = virDomainGraphicsListenGetAddress(def->graphics[0], 0); if (listenAddr && xenXMConfigSetString(conf, "vnclisten", listenAddr) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.vnc.auth.passwd && xenXMConfigSetString(conf, "vncpasswd", def->graphics[0]->data.vnc.auth.passwd) < 0) - goto cleanup; + return -1; + if (def->graphics[0]->data.vnc.keymap && xenXMConfigSetString(conf, "keymap", def->graphics[0]->data.vnc.keymap) < 0) - goto cleanup; + return -1; } } else { virConfValuePtr vfb, disp; @@ -2221,20 +2178,20 @@ xenFormatXM(virConnectPtr conn, virBufferAsprintf(&buf, ",keymap=%s", def->graphics[0]->data.vnc.keymap); } + if (virBufferCheckError(&buf) < 0) - goto cleanup; + return -1; vfbstr = virBufferContentAndReset(&buf); - if (VIR_ALLOC(vfb) < 0) { VIR_FREE(vfbstr); - goto cleanup; + return -1; } if (VIR_ALLOC(disp) < 0) { VIR_FREE(vfb); VIR_FREE(vfbstr); - goto cleanup; + return -1; } vfb->type = VIR_CONF_LIST; @@ -2243,10 +2200,76 @@ xenFormatXM(virConnectPtr conn, disp->str = vfbstr; if (virConfSetValue(conf, "vfb", vfb) < 0) - goto cleanup; + return -1; + } + } + + return 0; +} +/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is + either 32, or 64 on a platform where long is big enough. */ +verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); + +virConfPtr +xenFormatXM(virConnectPtr conn, + virDomainDefPtr def, + int xendConfigVersion) +{ + virConfPtr conf = NULL; + int hvm = 0; + size_t i; + virConfValuePtr netVal = NULL; + + if (!(conf = virConfNew())) + goto cleanup; + + if (xenFormatXMGeneralMeta(conf, def) < 0) + goto cleanup; + + if (xenFormatXMMem(conf, def) < 0) + goto cleanup; + + if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) + goto cleanup; + + hvm = STREQ(def->os.type, "hvm"); + + if (xenFormatXMOS(conf, def, xendConfigVersion) < 0) + goto cleanup; + + if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) + goto cleanup; + + if (xenFormatXMEventActions(conf, def) < 0) + goto cleanup; + + if (hvm) { + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { + if (xenXMConfigSetInt(conf, "usb", 1) < 0) + goto cleanup; + switch (def->inputs[i]->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) + goto cleanup; + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) + goto cleanup; + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) + goto cleanup; + break; + } + break; + } } } + if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0) + goto cleanup; + if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0) goto cleanup; -- 1.8.4.5

introduce function xenFormatXMEmulatedHardware(virConfPtr conf,....); which formats emulated hardware config instead signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 150 +++++++++++++++++------------ tests/xmconfigdata/test-escape-paths.cfg | 2 +- tests/xmconfigdata/test-fullvirt-sound.cfg | 2 +- 3 files changed, 92 insertions(+), 62 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index bf5a23a..071802d 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2206,6 +2206,93 @@ xenFormatXMVfb(virConfPtr conf, virDomainDefPtr def, return 0; } + + +static int +xenFormatXMVif(virConfPtr conf, virConnectPtr conn, + virDomainDefPtr def, int xendConfigVersion) +{ + virConfValuePtr netVal = NULL; + size_t i; + int hvm = STREQ(def->os.type, "hvm"); + + if (VIR_ALLOC(netVal) < 0) + goto cleanup; + netVal->type = VIR_CONF_LIST; + netVal->list = NULL; + + for (i = 0; i < def->nnets; i++) { + if (xenFormatXMNet(conn, netVal, def->nets[i], + hvm, xendConfigVersion) < 0) + goto cleanup; + } + + if (netVal->list != NULL) { + int ret = virConfSetValue(conf, "vif", netVal); + netVal = NULL; + if (ret < 0) + goto cleanup; + } + + VIR_FREE(netVal); + return 0; + + cleanup: + virConfFreeValue(netVal); + return -1; +} + + +static int +xenFormatXMEmulatedHardware(virConfPtr conf, virDomainDefPtr def) +{ + size_t i; + + if (STREQ(def->os.type, "hvm")) { + if (def->sounds) { + virBuffer buf = VIR_BUFFER_INITIALIZER; + char *str = NULL; + int ret = xenFormatSxprSound(def, &buf); + str = virBufferContentAndReset(&buf); + if (ret == 0) + ret = xenXMConfigSetString(conf, "soundhw", str); + + VIR_FREE(str); + if (ret < 0) + return -1; + } + + for (i = 0; i < def->ninputs; i++) { + if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { + if (xenXMConfigSetInt(conf, "usb", 1) < 0) + return -1; + + switch (def->inputs[i]->type) { + case VIR_DOMAIN_INPUT_TYPE_MOUSE: + if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) + return -1; + + break; + case VIR_DOMAIN_INPUT_TYPE_TABLET: + if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) + return -1; + + break; + case VIR_DOMAIN_INPUT_TYPE_KBD: + if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) + return -1; + + break; + } + break; + } + } + } + + return 0; +} + + /* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is either 32, or 64 on a platform where long is big enough. */ verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); @@ -2216,9 +2303,6 @@ xenFormatXM(virConnectPtr conn, int xendConfigVersion) { virConfPtr conf = NULL; - int hvm = 0; - size_t i; - virConfValuePtr netVal = NULL; if (!(conf = virConfNew())) goto cleanup; @@ -2232,8 +2316,6 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) goto cleanup; - hvm = STREQ(def->os.type, "hvm"); - if (xenFormatXMOS(conf, def, xendConfigVersion) < 0) goto cleanup; @@ -2243,29 +2325,8 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMEventActions(conf, def) < 0) goto cleanup; - if (hvm) { - for (i = 0; i < def->ninputs; i++) { - if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) { - if (xenXMConfigSetInt(conf, "usb", 1) < 0) - goto cleanup; - switch (def->inputs[i]->type) { - case VIR_DOMAIN_INPUT_TYPE_MOUSE: - if (xenXMConfigSetString(conf, "usbdevice", "mouse") < 0) - goto cleanup; - break; - case VIR_DOMAIN_INPUT_TYPE_TABLET: - if (xenXMConfigSetString(conf, "usbdevice", "tablet") < 0) - goto cleanup; - break; - case VIR_DOMAIN_INPUT_TYPE_KBD: - if (xenXMConfigSetString(conf, "usbdevice", "keyboard") < 0) - goto cleanup; - break; - } - break; - } - } - } + if (xenFormatXMEmulatedHardware(conf, def) < 0) + goto cleanup; if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0) goto cleanup; @@ -2273,23 +2334,8 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0) goto cleanup; - if (VIR_ALLOC(netVal) < 0) + if (xenFormatXMVif(conf, conn, def, xendConfigVersion) < 0) goto cleanup; - netVal->type = VIR_CONF_LIST; - netVal->list = NULL; - - for (i = 0; i < def->nnets; i++) { - if (xenFormatXMNet(conn, netVal, def->nets[i], - hvm, xendConfigVersion) < 0) - goto cleanup; - } - if (netVal->list != NULL) { - int ret = virConfSetValue(conf, "vif", netVal); - netVal = NULL; - if (ret < 0) - goto cleanup; - } - VIR_FREE(netVal); if (xenFormatXMPCI(conf, def) < 0) goto cleanup; @@ -2297,25 +2343,9 @@ xenFormatXM(virConnectPtr conn, if (xenFormatXMCharDev(conf, def) < 0) goto cleanup; - if (hvm) { - if (def->sounds) { - virBuffer buf = VIR_BUFFER_INITIALIZER; - char *str = NULL; - int ret = xenFormatSxprSound(def, &buf); - str = virBufferContentAndReset(&buf); - if (ret == 0) - ret = xenXMConfigSetString(conf, "soundhw", str); - - VIR_FREE(str); - if (ret < 0) - goto cleanup; - } - } - return conf; cleanup: - virConfFreeValue(netVal); if (conf) virConfFree(conf); return NULL; diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg index 68984da..1336ece 100644 --- a/tests/xmconfigdata/test-escape-paths.cfg +++ b/tests/xmconfigdata/test-escape-paths.cfg @@ -14,6 +14,7 @@ localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" +soundhw = "sb16,es1370" sdl = 0 vnc = 1 vncunused = 1 @@ -23,4 +24,3 @@ disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", """phy:/dev/HostVG/XenGuest'",hdb,w" vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" -soundhw = "sb16,es1370" diff --git a/tests/xmconfigdata/test-fullvirt-sound.cfg b/tests/xmconfigdata/test-fullvirt-sound.cfg index a12a30c..67dd8e0 100644 --- a/tests/xmconfigdata/test-fullvirt-sound.cfg +++ b/tests/xmconfigdata/test-fullvirt-sound.cfg @@ -14,6 +14,7 @@ localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" +soundhw = "sb16,es1370" sdl = 0 vnc = 1 vncunused = 1 @@ -23,4 +24,3 @@ disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" -soundhw = "sb16,es1370" -- 1.8.4.5

export code for reuse and some formating fix signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> --- src/xenxs/xen_xm.c | 59 +++++++++++++--------- src/xenxs/xen_xm.h | 4 +- tests/xmconfigdata/test-escape-paths.cfg | 2 +- tests/xmconfigdata/test-fullvirt-force-hpet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-force-nohpet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-localtime.cfg | 2 +- tests/xmconfigdata/test-fullvirt-net-ioemu.cfg | 2 +- tests/xmconfigdata/test-fullvirt-net-netfront.cfg | 2 +- tests/xmconfigdata/test-fullvirt-new-cdrom.cfg | 2 +- tests/xmconfigdata/test-fullvirt-old-cdrom.cfg | 2 +- tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg | 2 +- .../test-fullvirt-serial-dev-2-ports.cfg | 2 +- .../test-fullvirt-serial-dev-2nd-port.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-file.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-null.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-pipe.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-pty.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-stdio.cfg | 2 +- .../test-fullvirt-serial-tcp-telnet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-tcp.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-udp.cfg | 2 +- tests/xmconfigdata/test-fullvirt-serial-unix.cfg | 2 +- tests/xmconfigdata/test-fullvirt-sound.cfg | 2 +- tests/xmconfigdata/test-fullvirt-usbmouse.cfg | 2 +- tests/xmconfigdata/test-fullvirt-usbtablet.cfg | 2 +- tests/xmconfigdata/test-fullvirt-utc.cfg | 2 +- tests/xmconfigdata/test-no-source-cdrom.cfg | 2 +- tests/xmconfigdata/test-paravirt-net-e1000.cfg | 2 +- tests/xmconfigdata/test-paravirt-net-vifname.cfg | 2 +- .../test-paravirt-new-pvfb-vncdisplay.cfg | 2 +- tests/xmconfigdata/test-paravirt-new-pvfb.cfg | 2 +- .../test-paravirt-old-pvfb-vncdisplay.cfg | 2 +- tests/xmconfigdata/test-paravirt-old-pvfb.cfg | 2 +- tests/xmconfigdata/test-paravirt-vcpu.cfg | 2 +- tests/xmconfigdata/test-pci-devs.cfg | 2 +- 35 files changed, 70 insertions(+), 59 deletions(-) diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 071802d..215dfdc 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -2293,54 +2293,63 @@ xenFormatXMEmulatedHardware(virConfPtr conf, virDomainDefPtr def) } -/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is - either 32, or 64 on a platform where long is big enough. */ -verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); - -virConfPtr -xenFormatXM(virConnectPtr conn, - virDomainDefPtr def, - int xendConfigVersion) +int xenFormatConfigCommon(virConfPtr conf, virDomainDefPtr def, + virConnectPtr conn, int xendConfigVersion) { - virConfPtr conf = NULL; - - if (!(conf = virConfNew())) - goto cleanup; if (xenFormatXMGeneralMeta(conf, def) < 0) - goto cleanup; + return -1; if (xenFormatXMMem(conf, def) < 0) - goto cleanup; + return -1; if (xenFormatXMCPUFeatures(conf, def, xendConfigVersion) < 0) - goto cleanup; + return -1; if (xenFormatXMOS(conf, def, xendConfigVersion) < 0) - goto cleanup; + return -1; if (xenFormatXMTimeOffset(conf, def, xendConfigVersion) < 0) - goto cleanup; + return -1; if (xenFormatXMEventActions(conf, def) < 0) - goto cleanup; + return -1; if (xenFormatXMEmulatedHardware(conf, def) < 0) - goto cleanup; + return -1; if (xenFormatXMVfb(conf, def, xendConfigVersion) < 0) - goto cleanup; - - if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0) - goto cleanup; + return -1; if (xenFormatXMVif(conf, conn, def, xendConfigVersion) < 0) - goto cleanup; + return -1; if (xenFormatXMPCI(conf, def) < 0) - goto cleanup; + return -1; if (xenFormatXMCharDev(conf, def) < 0) + return -1; + + return 0; +} +/* Computing the vcpu_avail bitmask works because MAX_VIRT_CPUS is + either 32, or 64 on a platform where long is big enough. */ +verify(MAX_VIRT_CPUS <= sizeof(1UL) * CHAR_BIT); + +virConfPtr +xenFormatXM(virConnectPtr conn, + virDomainDefPtr def, + int xendConfigVersion) +{ + virConfPtr conf = NULL; + + if (!(conf = virConfNew())) + goto cleanup; + + if (xenFormatConfigCommon(conf, def, conn, xendConfigVersion) < 0) + goto cleanup; + + if (xenFormatXMDomainDisks(conf, def, xendConfigVersion) < 0) goto cleanup; return conf; diff --git a/src/xenxs/xen_xm.h b/src/xenxs/xen_xm.h index 5292396..c48fa41 100644 --- a/src/xenxs/xen_xm.h +++ b/src/xenxs/xen_xm.h @@ -35,7 +35,9 @@ virConfPtr xenFormatXM(virConnectPtr conn, virDomainDefPtr def, virDomainDefPtr xenParseXM(virConfPtr conf, int xendConfigVersion, virCapsPtr caps); -int xenParseConfigCommon(virConfPtr conf, virDomainDefPtr def, +int xenParseConfigCommon(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps, int xendConfigVersion); +int xenFormatConfigCommon(virConfPtr conf, virDomainDefPtr def, + virConnectPtr conn, int xendConfigVersion); #endif /* __VIR_XEN_XM_H__ */ diff --git a/tests/xmconfigdata/test-escape-paths.cfg b/tests/xmconfigdata/test-escape-paths.cfg index 1336ece..2055858 100644 --- a/tests/xmconfigdata/test-escape-paths.cfg +++ b/tests/xmconfigdata/test-escape-paths.cfg @@ -20,7 +20,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", """phy:/dev/HostVG/XenGuest'",hdb,w""", "file:/root/boot.iso&test,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", """phy:/dev/HostVG/XenGuest'",hdb,w""", "file:/root/boot.iso&test,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-force-hpet.cfg b/tests/xmconfigdata/test-fullvirt-force-hpet.cfg index f2377dc..89d8024 100644 --- a/tests/xmconfigdata/test-fullvirt-force-hpet.cfg +++ b/tests/xmconfigdata/test-fullvirt-force-hpet.cfg @@ -20,7 +20,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg b/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg index 093c8de..7219001 100644 --- a/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg +++ b/tests/xmconfigdata/test-fullvirt-force-nohpet.cfg @@ -20,7 +20,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-localtime.cfg b/tests/xmconfigdata/test-fullvirt-localtime.cfg index 34ea100..3a75a0f 100755 --- a/tests/xmconfigdata/test-fullvirt-localtime.cfg +++ b/tests/xmconfigdata/test-fullvirt-localtime.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg b/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg index a4f3aec..10fcd80 100644 --- a/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg +++ b/tests/xmconfigdata/test-fullvirt-net-ioemu.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-net-netfront.cfg b/tests/xmconfigdata/test-fullvirt-net-netfront.cfg index 57cff7b..8f63d2e 100644 --- a/tests/xmconfigdata/test-fullvirt-net-netfront.cfg +++ b/tests/xmconfigdata/test-fullvirt-net-netfront.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,type=netfront" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg index a4f3aec..10fcd80 100755 --- a/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg +++ b/tests/xmconfigdata/test-fullvirt-new-cdrom.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg index 9b74db4..f5db0f0 100755 --- a/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg +++ b/tests/xmconfigdata/test-fullvirt-old-cdrom.cfg @@ -20,7 +20,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,ioemu:hda,w" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr0,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,ioemu:hda,w" ] diff --git a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg index 6a0e1ac..de01a4a 100755 --- a/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg +++ b/tests/xmconfigdata/test-fullvirt-parallel-tcp.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "tcp:127.0.0.1:7777" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg b/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg index 2021ac3..d8028f3 100644 --- a/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-dev-2-ports.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = [ "/dev/ttyS0", "/dev/ttyS1" ] +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg b/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg index 0200194..226aecb 100644 --- a/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-dev-2nd-port.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = [ "none", "/dev/ttyS1" ] +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-file.cfg b/tests/xmconfigdata/test-fullvirt-serial-file.cfg index 4602516..fb1c9ab 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-file.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-file.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "file:/tmp/serial.log" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-null.cfg b/tests/xmconfigdata/test-fullvirt-serial-null.cfg index c8365e8..d91b07f 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-null.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-null.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "null" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg index f30a072..ce27cf2 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-pipe.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "pipe:/tmp/serial.pipe" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg index bb490b0..5c8c962 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-pty.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-pty.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "pty" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg index 6583076..e89b875 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-stdio.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "stdio" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg index 730b2e8..a556b8a 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-tcp-telnet.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "telnet:127.0.0.1:9999,server,nowait" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg index 3a15c11..1690c3b 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-tcp.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "tcp:127.0.0.1:7777" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg index 5b7804d..481bedb 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-udp.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-udp.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "udp:127.0.0.1:9999@0.0.0.0:99998" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg index 6cd7272..a5cb063 100755 --- a/tests/xmconfigdata/test-fullvirt-serial-unix.cfg +++ b/tests/xmconfigdata/test-fullvirt-serial-unix.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "unix:/tmp/serial.sock,server,nowait" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-sound.cfg b/tests/xmconfigdata/test-fullvirt-sound.cfg index 67dd8e0..5f33f0f 100644 --- a/tests/xmconfigdata/test-fullvirt-sound.cfg +++ b/tests/xmconfigdata/test-fullvirt-sound.cfg @@ -20,7 +20,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg index be27f08..438e55d 100755 --- a/tests/xmconfigdata/test-fullvirt-usbmouse.cfg +++ b/tests/xmconfigdata/test-fullvirt-usbmouse.cfg @@ -21,7 +21,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg index 5e84e7e..5637385 100755 --- a/tests/xmconfigdata/test-fullvirt-usbtablet.cfg +++ b/tests/xmconfigdata/test-fullvirt-usbtablet.cfg @@ -21,7 +21,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-fullvirt-utc.cfg b/tests/xmconfigdata/test-fullvirt-utc.cfg index a4f3aec..10fcd80 100755 --- a/tests/xmconfigdata/test-fullvirt-utc.cfg +++ b/tests/xmconfigdata/test-fullvirt-utc.cfg @@ -19,7 +19,7 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] vif = [ "mac=00:16:3e:66:92:9c,bridge=xenbr1,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "none" +disk = [ "phy:/dev/HostVG/XenGuest2,hda,w", "file:/root/boot.iso,hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-no-source-cdrom.cfg b/tests/xmconfigdata/test-no-source-cdrom.cfg index 27bec8d..63537e7 100644 --- a/tests/xmconfigdata/test-no-source-cdrom.cfg +++ b/tests/xmconfigdata/test-no-source-cdrom.cfg @@ -17,7 +17,7 @@ on_crash = "destroy" sdl = 0 vnc = 1 vncunused = 1 -disk = [ "phy:/dev/sda8,hda,w", ",hdc:cdrom,r" ] vif = [ "mac=00:16:3e:0a:7b:39,bridge=xenbr0,script=vif-bridge,model=e1000,type=ioemu" ] parallel = "none" serial = "pty" +disk = [ "phy:/dev/sda8,hda,w", ",hdc:cdrom,r" ] diff --git a/tests/xmconfigdata/test-paravirt-net-e1000.cfg b/tests/xmconfigdata/test-paravirt-net-e1000.cfg index bcc16fb..ac43507 100755 --- a/tests/xmconfigdata/test-paravirt-net-e1000.cfg +++ b/tests/xmconfigdata/test-paravirt-net-e1000.cfg @@ -9,5 +9,5 @@ on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" vfb = [ "type=vnc,vncunused=1,vnclisten=127.0.0.1,vncpasswd=123poi" ] -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge,model=e1000" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-paravirt-net-vifname.cfg b/tests/xmconfigdata/test-paravirt-net-vifname.cfg index 98ce75b..c66721c 100644 --- a/tests/xmconfigdata/test-paravirt-net-vifname.cfg +++ b/tests/xmconfigdata/test-paravirt-net-vifname.cfg @@ -9,5 +9,5 @@ on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" vfb = [ "type=vnc,vncunused=1,vnclisten=127.0.0.1,vncpasswd=123poi" ] -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge,model=e1000,vifname=net0" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-paravirt-new-pvfb-vncdisplay.cfg b/tests/xmconfigdata/test-paravirt-new-pvfb-vncdisplay.cfg index 633552c..de1c912 100644 --- a/tests/xmconfigdata/test-paravirt-new-pvfb-vncdisplay.cfg +++ b/tests/xmconfigdata/test-paravirt-new-pvfb-vncdisplay.cfg @@ -9,5 +9,5 @@ on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" vfb = [ "type=vnc,vncunused=0,vncdisplay=25,vnclisten=127.0.0.1,vncpasswd=123poi" ] -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-paravirt-new-pvfb.cfg b/tests/xmconfigdata/test-paravirt-new-pvfb.cfg index 8b56e19..df91e89 100755 --- a/tests/xmconfigdata/test-paravirt-new-pvfb.cfg +++ b/tests/xmconfigdata/test-paravirt-new-pvfb.cfg @@ -9,5 +9,5 @@ on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" vfb = [ "type=vnc,vncunused=1,vnclisten=127.0.0.1,vncpasswd=123poi" ] -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-paravirt-old-pvfb-vncdisplay.cfg b/tests/xmconfigdata/test-paravirt-old-pvfb-vncdisplay.cfg index eea3365..6f9a1aa 100644 --- a/tests/xmconfigdata/test-paravirt-old-pvfb-vncdisplay.cfg +++ b/tests/xmconfigdata/test-paravirt-old-pvfb-vncdisplay.cfg @@ -14,5 +14,5 @@ vncunused = 0 vncdisplay = 25 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-paravirt-old-pvfb.cfg b/tests/xmconfigdata/test-paravirt-old-pvfb.cfg index ed9c771..7daad8c 100755 --- a/tests/xmconfigdata/test-paravirt-old-pvfb.cfg +++ b/tests/xmconfigdata/test-paravirt-old-pvfb.cfg @@ -13,5 +13,5 @@ vnc = 1 vncunused = 1 vnclisten = "127.0.0.1" vncpasswd = "123poi" -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-paravirt-vcpu.cfg b/tests/xmconfigdata/test-paravirt-vcpu.cfg index 2ac0f79..fb89bf9 100644 --- a/tests/xmconfigdata/test-paravirt-vcpu.cfg +++ b/tests/xmconfigdata/test-paravirt-vcpu.cfg @@ -9,5 +9,5 @@ localtime = 0 on_poweroff = "destroy" on_reboot = "restart" on_crash = "restart" -disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] vif = [ "mac=00:16:3e:66:94:9c,bridge=br0,script=vif-bridge" ] +disk = [ "phy:/dev/HostVG/XenGuest1,xvda,w" ] diff --git a/tests/xmconfigdata/test-pci-devs.cfg b/tests/xmconfigdata/test-pci-devs.cfg index a24a09c..4e3096d 100644 --- a/tests/xmconfigdata/test-pci-devs.cfg +++ b/tests/xmconfigdata/test-pci-devs.cfg @@ -17,8 +17,8 @@ on_crash = "destroy" sdl = 0 vnc = 1 vncunused = 1 -disk = [ "phy:/dev/sda8,hda,w", ",hdc:cdrom,r" ] vif = [ "mac=00:16:3e:0a:7b:39,bridge=xenbr0,script=vif-bridge,model=e1000,type=ioemu" ] pci = [ "0001:0c:1b.2", "0000:01:13.0" ] parallel = "none" serial = "pty" +disk = [ "phy:/dev/sda8,hda,w", ",hdc:cdrom,r" ] -- 1.8.4.5

Kiarie Kahurani wrote:
introduce function xenParseXMMem(virConfPtr conf,.........); which parses memory config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com>
Extra SOB in the patches. I'll remove the first one before pushing any patch.
--- src/xenxs/xen_xm.c | 83 +++++++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 38 deletions(-)
diff --git a/src/xenxs/xen_xm.c b/src/xenxs/xen_xm.c index 4461654..443e6da 100644 --- a/src/xenxs/xen_xm.c +++ b/src/xenxs/xen_xm.c @@ -40,11 +40,9 @@ #include "virstoragefile.h" #include "virstring.h"
-/* Convenience method to grab a long int from the config file object */ -static int xenXMConfigGetBool(virConfPtr conf, - const char *name, - int *value, - int def) +/* Convenience method to grab a int from the config file object */ +static int +xenXMConfigGetBool(virConfPtr conf, const char *name, int *value, int def)
You forgot to remove this and the other whitespace changes that have nothing to do with "Refactor code parsing memory config". ACK to the patch otherwise. I'll remove these unrelated changes before pushing. Regards, Jim
{ virConfValuePtr val;
@@ -67,11 +65,10 @@ static int xenXMConfigGetBool(virConfPtr conf, }
-/* Convenience method to grab a int from the config file object */ -static int xenXMConfigGetULong(virConfPtr conf, - const char *name, - unsigned long *value, - unsigned long def) +/* Convenience method to grab a long int from the config file object */ +static int +xenXMConfigGetULong(virConfPtr conf, const char *name, unsigned long *value, + unsigned long def) { virConfValuePtr val;
@@ -99,10 +96,9 @@ static int xenXMConfigGetULong(virConfPtr conf,
/* Convenience method to grab a int from the config file object */ -static int xenXMConfigGetULongLong(virConfPtr conf, - const char *name, - unsigned long long *value, - unsigned long long def) +static int +xenXMConfigGetULongLong(virConfPtr conf, const char *name, + unsigned long long *value, unsigned long long def) { virConfValuePtr val;
@@ -130,10 +126,9 @@ static int xenXMConfigGetULongLong(virConfPtr conf,
/* Convenience method to grab a string from the config file object */ -static int xenXMConfigGetString(virConfPtr conf, - const char *name, - const char **value, - const char *def) +static int +xenXMConfigGetString(virConfPtr conf, const char *name, const char **value, + const char *def) { virConfValuePtr val;
@@ -155,10 +150,10 @@ static int xenXMConfigGetString(virConfPtr conf, return 0; }
-static int xenXMConfigCopyStringInternal(virConfPtr conf, - const char *name, - char **value, - int allowMissing) + +static int +xenXMConfigCopyStringInternal(virConfPtr conf, const char *name, char **value, + int allowMissing) { virConfValuePtr val;
@@ -188,15 +183,16 @@ static int xenXMConfigCopyStringInternal(virConfPtr conf, }
-static int xenXMConfigCopyString(virConfPtr conf, - const char *name, - char **value) { +static int +xenXMConfigCopyString(virConfPtr conf, const char *name, char **value) +{ return xenXMConfigCopyStringInternal(conf, name, value, 0); }
-static int xenXMConfigCopyStringOpt(virConfPtr conf, - const char *name, - char **value) { + +static int +xenXMConfigCopyStringOpt(virConfPtr conf, const char *name, char **value) +{ return xenXMConfigCopyStringInternal(conf, name, value, 1); }
@@ -244,6 +240,25 @@ xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) return 0; }
+ +static int +xenParseXMMem(virConfPtr conf, virDomainDefPtr def) +{ + if (xenXMConfigGetULongLong(conf, "memory", &def->mem.cur_balloon, + MIN_XEN_GUEST_SIZE * 2) < 0) + return -1; + + if (xenXMConfigGetULongLong(conf, "maxmem", &def->mem.max_balloon, + def->mem.cur_balloon) < 0) + return -1; + + def->mem.cur_balloon *= 1024; + def->mem.max_balloon *= 1024; + + return 0; +} + + #define MAX_VFB 1024 /* * Turn a config record into a lump of XML describing the @@ -251,7 +266,7 @@ xenXMConfigGetUUID(virConfPtr conf, const char *name, unsigned char *uuid) */ virDomainDefPtr xenParseXM(virConfPtr conf, int xendConfigVersion, - virCapsPtr caps) + virCapsPtr caps) { const char *str; int hvm = 0; @@ -360,17 +375,9 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, } }
- if (xenXMConfigGetULongLong(conf, "memory", &def->mem.cur_balloon, - MIN_XEN_GUEST_SIZE * 2) < 0) - goto cleanup; - - if (xenXMConfigGetULongLong(conf, "maxmem", &def->mem.max_balloon, - def->mem.cur_balloon) < 0) + if (xenParseXMMem(conf, def) < 0) goto cleanup;
- def->mem.cur_balloon *= 1024; - def->mem.max_balloon *= 1024; - if (xenXMConfigGetULong(conf, "vcpus", &count, 1) < 0 || MAX_VIRT_CPUS < count) goto cleanup;

On 08/08/2014 02:58 PM, Jim Fehlig wrote:
Kiarie Kahurani wrote:
introduce function xenParseXMMem(virConfPtr conf,.........); which parses memory config instead
signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com> Signed-off-by: Kiarie Kahurani <davidkiarie4@gmail.com>
Extra SOB in the patches. I'll remove the first one before pushing any patch.
Also, you forgot a cover letter this time around. When sending a series, it's helpful to have the 0/24 cover letter. :) -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (4)
-
David Kiarie
-
Eric Blake
-
Jim Fehlig
-
Kiarie Kahurani