introduce function
xenParseXMVif(virConfPtr conf,........);
which parses Vfb config instead
signed-off-by: Kiarie Kahurani <davidkiarie4(a)gmail.com>
Signed-off-by: Kiarie Kahurani <davidkiarie4(a)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