qemu_command: Split qemuBuildCpuArgStr

Move the CPU mode/model handling to its own function. This is just
code movement and re-indentation.

(cherry picked from commit e1d872dc77c80d43036f928f83f560f2e9286148)
This commit is contained in:
Cole Robinson 2014-09-23 11:35:57 -04:00
parent 8a24579f3e
commit 74e27d1c0e

View File

@ -6140,48 +6140,32 @@ qemuBuildClockArgStr(virDomainClockDefPtr def)
return NULL;
}
static int
qemuBuildCpuArgStr(virQEMUDriverPtr driver,
qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
const virDomainDef *def,
const char *emulator,
virBufferPtr buf,
virQEMUCapsPtr qemuCaps,
virArch hostarch,
char **opt,
bool *hasHwVirt,
bool migrating)
{
int ret = -1;
size_t i;
virCPUDefPtr host = NULL;
virCPUDefPtr guest = NULL;
virCPUDefPtr cpu = NULL;
size_t ncpus = 0;
char **cpus = NULL;
const char *default_model;
virCPUDataPtr data = NULL;
bool have_cpu = false;
char *compare_msg = NULL;
int ret = -1;
virBuffer buf = VIR_BUFFER_INITIALIZER;
size_t i;
virCPUCompareResult cmp;
const char *preferred;
virCapsPtr caps = NULL;
*hasHwVirt = false;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
host = caps->host.cpu;
if (def->os.arch == VIR_ARCH_I686)
default_model = "qemu32";
else
default_model = "qemu64";
if (def->cpu &&
(def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
virCPUCompareResult cmp;
const char *preferred;
if (!host ||
!host->model ||
(ncpus = virQEMUCapsGetCPUDefinitions(qemuCaps, &cpus)) == 0) {
@ -6242,7 +6226,7 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
mode);
goto cleanup;
}
virBufferAddLit(&buf, "host");
virBufferAddLit(buf, "host");
} else {
if (VIR_ALLOC(guest) < 0)
goto cleanup;
@ -6260,9 +6244,9 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
if (cpuDecode(guest, data, (const char **)cpus, ncpus, preferred) < 0)
goto cleanup;
virBufferAdd(&buf, guest->model, -1);
virBufferAdd(buf, guest->model, -1);
if (guest->vendor_id)
virBufferAsprintf(&buf, ",vendor=%s", guest->vendor_id);
virBufferAsprintf(buf, ",vendor=%s", guest->vendor_id);
for (i = 0; i < guest->nfeatures; i++) {
char sign;
if (guest->features[i].policy == VIR_CPU_FEATURE_DISABLE)
@ -6270,9 +6254,48 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
else
sign = '+';
virBufferAsprintf(&buf, ",%c%s", sign, guest->features[i].name);
virBufferAsprintf(buf, ",%c%s", sign, guest->features[i].name);
}
}
ret = 0;
cleanup:
virObjectUnref(caps);
VIR_FREE(compare_msg);
cpuDataFree(data);
virCPUDefFree(guest);
virCPUDefFree(cpu);
return ret;
}
static int
qemuBuildCpuArgStr(virQEMUDriverPtr driver,
const virDomainDef *def,
const char *emulator,
virQEMUCapsPtr qemuCaps,
virArch hostarch,
char **opt,
bool *hasHwVirt,
bool migrating)
{
const char *default_model;
bool have_cpu = false;
int ret = -1;
virBuffer buf = VIR_BUFFER_INITIALIZER;
size_t i;
*hasHwVirt = false;
if (def->os.arch == VIR_ARCH_I686)
default_model = "qemu32";
else
default_model = "qemu64";
if (def->cpu &&
(def->cpu->mode != VIR_CPU_MODE_CUSTOM || def->cpu->model)) {
if (qemuBuildCpuModelArgStr(driver, def, &buf, qemuCaps,
hasHwVirt, migrating) < 0)
goto cleanup;
have_cpu = true;
} else {
/*
@ -6398,11 +6421,6 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
ret = 0;
cleanup:
VIR_FREE(compare_msg);
cpuDataFree(data);
virCPUDefFree(guest);
virCPUDefFree(cpu);
virObjectUnref(caps);
return ret;
}