1
0

qemu: do not create useless <cpu> element

Avoid creating an empty <cpu> element when the QEMU command-line simply
specifies the default "-cpu qemu32" or "-cpu qemu64".

This requires the previous patch, which lets us represent "-cpu qemu32"
as <os arch='i686'> in the generated XML.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2012-01-27 14:49:50 +01:00 committed by Jiri Denemark
parent d5e88b2c33
commit df8e6918b3

View File

@ -6778,12 +6778,10 @@ static int
qemuParseCommandLineCPU(virDomainDefPtr dom, qemuParseCommandLineCPU(virDomainDefPtr dom,
const char *val) const char *val)
{ {
virCPUDefPtr cpu; virCPUDefPtr cpu = NULL;
const char *p = val; const char *p = val;
const char *next; const char *next;
char *model = NULL;
if (!(cpu = qemuInitGuestCPU(dom)))
goto error;
do { do {
if (*p == '\0' || *p == ',') if (*p == '\0' || *p == ',')
@ -6792,14 +6790,22 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
if ((next = strchr(p, ','))) if ((next = strchr(p, ',')))
next++; next++;
if (!cpu->model) { if (p == val) {
if (next) if (next)
cpu->model = strndup(p, next - p - 1); model = strndup(p, next - p - 1);
else else
cpu->model = strdup(p); model = strdup(p);
if (!cpu->model) if (!model)
goto no_memory; goto no_memory;
if (!STREQ(model, "qemu32") && !STREQ(model, "qemu64")) {
if (!(cpu = qemuInitGuestCPU(dom)))
goto error;
cpu->model = model;
model = NULL;
}
} }
else if (*p == '+' || *p == '-') { else if (*p == '+' || *p == '-') {
char *feature; char *feature;
@ -6823,6 +6829,13 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
if (!feature) if (!feature)
goto no_memory; goto no_memory;
if (!cpu) {
if (!(cpu = qemuInitGuestCPU(dom)))
goto error;
cpu->model = model;
model = NULL;
}
ret = virCPUDefAddFeature(cpu, feature, policy); ret = virCPUDefAddFeature(cpu, feature, policy);
VIR_FREE(feature); VIR_FREE(feature);
if (ret < 0) if (ret < 0)
@ -6832,22 +6845,27 @@ qemuParseCommandLineCPU(virDomainDefPtr dom,
if (STREQ(dom->os.arch, "x86_64")) { if (STREQ(dom->os.arch, "x86_64")) {
bool is_32bit = false; bool is_32bit = false;
union cpuData *cpuData = NULL; if (cpu) {
int ret; union cpuData *cpuData = NULL;
int ret;
ret = cpuEncode("x86_64", cpu, NULL, &cpuData, ret = cpuEncode("x86_64", cpu, NULL, &cpuData,
NULL, NULL, NULL, NULL); NULL, NULL, NULL, NULL);
if (ret < 0) if (ret < 0)
goto error; goto error;
is_32bit = (cpuHasFeature("x86_64", cpuData, "lm") != 1); is_32bit = (cpuHasFeature("x86_64", cpuData, "lm") != 1);
cpuDataFree("x86_64", cpuData); cpuDataFree("x86_64", cpuData);
} else if (model) {
is_32bit = STREQ(model, "qemu32");
}
if (is_32bit) { if (is_32bit) {
VIR_FREE(dom->os.arch); VIR_FREE(dom->os.arch);
dom->os.arch = strdup("i686"); dom->os.arch = strdup("i686");
} }
} }
VIR_FREE(model);
return 0; return 0;
syntax: syntax: