提交 74e27d1c 编写于 作者: C Cole Robinson

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)
上级 8a24579f
...@@ -6140,48 +6140,32 @@ qemuBuildClockArgStr(virDomainClockDefPtr def) ...@@ -6140,48 +6140,32 @@ qemuBuildClockArgStr(virDomainClockDefPtr def)
return NULL; return NULL;
} }
static int static int
qemuBuildCpuArgStr(virQEMUDriverPtr driver, qemuBuildCpuModelArgStr(virQEMUDriverPtr driver,
const virDomainDef *def, const virDomainDef *def,
const char *emulator, virBufferPtr buf,
virQEMUCapsPtr qemuCaps, virQEMUCapsPtr qemuCaps,
virArch hostarch,
char **opt,
bool *hasHwVirt, bool *hasHwVirt,
bool migrating) bool migrating)
{ {
int ret = -1;
size_t i;
virCPUDefPtr host = NULL; virCPUDefPtr host = NULL;
virCPUDefPtr guest = NULL; virCPUDefPtr guest = NULL;
virCPUDefPtr cpu = NULL; virCPUDefPtr cpu = NULL;
size_t ncpus = 0; size_t ncpus = 0;
char **cpus = NULL; char **cpus = NULL;
const char *default_model;
virCPUDataPtr data = NULL; virCPUDataPtr data = NULL;
bool have_cpu = false;
char *compare_msg = NULL; char *compare_msg = NULL;
int ret = -1; virCPUCompareResult cmp;
virBuffer buf = VIR_BUFFER_INITIALIZER; const char *preferred;
size_t i;
virCapsPtr caps = NULL; virCapsPtr caps = NULL;
*hasHwVirt = false;
if (!(caps = virQEMUDriverGetCapabilities(driver, false))) if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup; goto cleanup;
host = caps->host.cpu; 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 || if (!host ||
!host->model || !host->model ||
(ncpus = virQEMUCapsGetCPUDefinitions(qemuCaps, &cpus)) == 0) { (ncpus = virQEMUCapsGetCPUDefinitions(qemuCaps, &cpus)) == 0) {
...@@ -6242,7 +6226,7 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver, ...@@ -6242,7 +6226,7 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
mode); mode);
goto cleanup; goto cleanup;
} }
virBufferAddLit(&buf, "host"); virBufferAddLit(buf, "host");
} else { } else {
if (VIR_ALLOC(guest) < 0) if (VIR_ALLOC(guest) < 0)
goto cleanup; goto cleanup;
...@@ -6260,9 +6244,9 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver, ...@@ -6260,9 +6244,9 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
if (cpuDecode(guest, data, (const char **)cpus, ncpus, preferred) < 0) if (cpuDecode(guest, data, (const char **)cpus, ncpus, preferred) < 0)
goto cleanup; goto cleanup;
virBufferAdd(&buf, guest->model, -1); virBufferAdd(buf, guest->model, -1);
if (guest->vendor_id) 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++) { for (i = 0; i < guest->nfeatures; i++) {
char sign; char sign;
if (guest->features[i].policy == VIR_CPU_FEATURE_DISABLE) if (guest->features[i].policy == VIR_CPU_FEATURE_DISABLE)
...@@ -6270,9 +6254,48 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver, ...@@ -6270,9 +6254,48 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
else else
sign = '+'; 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; have_cpu = true;
} else { } else {
/* /*
...@@ -6398,11 +6421,6 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver, ...@@ -6398,11 +6421,6 @@ qemuBuildCpuArgStr(virQEMUDriverPtr driver,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(compare_msg);
cpuDataFree(data);
virCPUDefFree(guest);
virCPUDefFree(cpu);
virObjectUnref(caps);
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册