@@ -1088,7 +1088,7 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
return;
}
- if (cpu_exists(apic_id)) {
+ if (qemu_get_cpu_by_arch_id(apic_id)) {
error_setg(errp, "Unable to add CPU: %" PRIi64
", it already exists", id);
return;
@@ -622,14 +622,14 @@ void async_run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
CPUState *qemu_get_cpu(int index);
/**
- * cpu_exists:
- * @id: Guest-exposed CPU ID to lookup.
+ * qemu_get_cpu_by_arch_id:
+ * @id: Guest-exposed CPU ID to lookup returned by CPUState@get_arch_id()
*
- * Search for CPU with specified ID.
+ * Gets a CPU matching @id.
*
- * Returns: %true - CPU is found, %false - CPU isn't found.
+ * Returns: The CPU or %NULL if there is no matching CPU.
*/
-bool cpu_exists(int64_t id);
+CPUState *qemu_get_cpu_by_arch_id(int id);
/**
* cpu_throttle_set:
@@ -27,7 +27,7 @@
#include "qemu/error-report.h"
#include "sysemu/sysemu.h"
-bool cpu_exists(int64_t id)
+CPUState *qemu_get_cpu_by_arch_id(int id)
{
CPUState *cpu;
@@ -35,10 +35,10 @@ bool cpu_exists(int64_t id)
CPUClass *cc = CPU_GET_CLASS(cpu);
if (cc->get_arch_id(cpu) == id) {
- return true;
+ return cpu;
}
}
- return false;
+ return NULL;
}
CPUState *cpu_generic_init(const char *typename, const char *cpu_model)
@@ -1789,7 +1789,7 @@ static void x86_cpuid_set_apic_id(Object *obj, Visitor *v, void *opaque,
return;
}
- if ((value != cpu->apic_id) && cpu_exists(value)) {
+ if ((value != cpu->apic_id) && qemu_get_cpu_by_arch_id(value)) {
error_setg(errp, "CPU with APIC ID %" PRIi64 " exists", value);
return;
}