提交 4821c32c 编写于 作者: K Kiarie Kahurani 提交者: Jim Fehlig

src/xenxs: Refactor code parsing Vif config

introduce function
  xenParseXMVif(virConfPtr conf,........);
which parses Vfb config instead
Signed-off-by: NKiarie Kahurani <davidkiarie4@gmail.com>
上级 aa964890
...@@ -946,133 +946,13 @@ xenParseXMCharDev(virConfPtr conf, virDomainDefPtr def) ...@@ -946,133 +946,13 @@ xenParseXMCharDev(virConfPtr conf, virDomainDefPtr def)
} }
/* static int
* Turn a config record into a lump of XML describing the xenParseXMVif(virConfPtr conf, virDomainDefPtr def)
* domain, suitable for later feeding for virDomainCreateXML
*/
virDomainDefPtr
xenParseXM(virConfPtr conf, int xendConfigVersion,
virCapsPtr caps)
{ {
const char *str;
int hvm = 0;
virConfValuePtr list;
virDomainDefPtr def = NULL;
virDomainNetDefPtr net = NULL;
size_t i;
const char *defaultMachine;
char *script = NULL; 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) { if (list && list->type == VIR_CONF_LIST) {
list = list->list; list = list->list;
while (list) { while (list) {
...@@ -1128,14 +1008,16 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1128,14 +1008,16 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
int len = nextkey ? (nextkey - data) : sizeof(model) - 1; int len = nextkey ? (nextkey - data) : sizeof(model) - 1;
if (virStrncpy(model, data, len, sizeof(model)) == NULL) { if (virStrncpy(model, data, len, sizeof(model)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Model %s too big for destination"), data); _("Model %s too big for destination"),
data);
goto skipnic; goto skipnic;
} }
} else if (STRPREFIX(key, "type=")) { } else if (STRPREFIX(key, "type=")) {
int len = nextkey ? (nextkey - data) : sizeof(type) - 1; int len = nextkey ? (nextkey - data) : sizeof(type) - 1;
if (virStrncpy(type, data, len, sizeof(type)) == NULL) { if (virStrncpy(type, data, len, sizeof(type)) == NULL) {
virReportError(VIR_ERR_INTERNAL_ERROR, virReportError(VIR_ERR_INTERNAL_ERROR,
_("Type %s too big for destination"), data); _("Type %s too big for destination"),
data);
goto skipnic; goto skipnic;
} }
} else if (STRPREFIX(key, "vifname=")) { } else if (STRPREFIX(key, "vifname=")) {
...@@ -1212,9 +1094,144 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1212,9 +1094,144 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
skipnic: skipnic:
list = list->next; list = list->next;
virDomainNetDefFree(net); virDomainNetDefFree(net);
VIR_FREE(script);
}
}
return 0;
cleanup:
VIR_FREE(script);
return -1;
}
/*
* Turn a config record into a lump of XML describing the
* domain, suitable for later feeding for virDomainCreateXML
*/
virDomainDefPtr
xenParseXM(virConfPtr conf, int xendConfigVersion,
virCapsPtr caps)
{
const char *str;
int hvm = 0;
virDomainDefPtr def = NULL;
size_t i;
const char *defaultMachine;
if (VIR_ALLOC(def) < 0)
return NULL;
def->virtType = VIR_DOMAIN_VIRT_XEN;
def->id = -1;
if (xenXMConfigCopyString(conf, "name", &def->name) < 0)
goto cleanup;
if (xenXMConfigGetUUID(conf, "uuid", def->uuid) < 0)
goto cleanup;
if ((xenXMConfigGetString(conf, "builder", &str, "linux") == 0) &&
STREQ(str, "hvm"))
hvm = 1;
if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
goto cleanup;
def->os.arch =
virCapabilitiesDefaultGuestArch(caps,
def->os.type,
virDomainVirtTypeToString(def->virtType));
if (!def->os.arch) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("no supported architecture for os type '%s'"),
def->os.type);
goto cleanup;
}
defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
def->os.type,
def->os.arch,
virDomainVirtTypeToString(def->virtType));
if (defaultMachine != NULL) {
if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
goto cleanup;
}
if (hvm) {
const char *boot;
if (xenXMConfigCopyString(conf, "kernel", &def->os.loader) < 0)
goto cleanup;
if (xenXMConfigGetString(conf, "boot", &boot, "c") < 0)
goto cleanup;
for (i = 0; i < VIR_DOMAIN_BOOT_LAST && boot[i]; i++) {
switch (*boot) {
case 'a':
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_FLOPPY;
break;
case 'd':
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_CDROM;
break;
case 'n':
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_NET;
break;
case 'c':
default:
def->os.bootDevs[i] = VIR_DOMAIN_BOOT_DISK;
break;
}
def->os.nBootDevs++;
}
} else {
const char *extra, *root;
if (xenXMConfigCopyStringOpt(conf, "bootloader", &def->os.bootloader) < 0)
goto cleanup;
if (xenXMConfigCopyStringOpt(conf, "bootargs", &def->os.bootloaderArgs) < 0)
goto cleanup;
if (xenXMConfigCopyStringOpt(conf, "kernel", &def->os.kernel) < 0)
goto cleanup;
if (xenXMConfigCopyStringOpt(conf, "ramdisk", &def->os.initrd) < 0)
goto cleanup;
if (xenXMConfigGetString(conf, "extra", &extra, NULL) < 0)
goto cleanup;
if (xenXMConfigGetString(conf, "root", &root, NULL) < 0)
goto cleanup;
if (root) {
if (virAsprintf(&def->os.cmdline, "root=%s %s", root, extra) < 0)
goto cleanup;
} else {
if (VIR_STRDUP(def->os.cmdline, extra) < 0)
goto cleanup;
} }
} }
if (xenParseXMMem(conf, def) < 0)
goto cleanup;
if (xenParseXMEventsActions(conf, def) < 0)
goto cleanup;
if (xenParseXMCPUFeatures(conf, def) < 0)
goto cleanup;
if (xenParseXMTimeOffset(conf, def, xendConfigVersion) < 0)
goto cleanup;
if (xenParseXMDisk(conf, def, xendConfigVersion) < 0)
goto cleanup;
if (xenXMConfigCopyStringOpt(conf, "device_model", &def->emulator) < 0)
goto cleanup;
if (xenParseXMVif(conf, def) < 0)
goto cleanup;
if (xenParseXMPCI(conf, def) < 0) if (xenParseXMPCI(conf, def) < 0)
goto cleanup; goto cleanup;
...@@ -1259,13 +1276,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion, ...@@ -1259,13 +1276,10 @@ xenParseXM(virConfPtr conf, int xendConfigVersion,
goto cleanup; goto cleanup;
} }
VIR_FREE(script);
return def; return def;
cleanup: cleanup:
virDomainNetDefFree(net);
virDomainDefFree(def); virDomainDefFree(def);
VIR_FREE(script);
return NULL; return NULL;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册