diff mbox

[RFC,42/42] DO NOT APPLY: simulate CPU unplug when executin cpu-add on a present CPU

Message ID 1462192431-146342-43-git-send-email-imammedo@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Igor Mammedov May 2, 2016, 12:33 p.m. UTC
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
 hw/i386/pc.c      | 8 ++++++++
 include/qom/cpu.h | 2 +-
 qom/cpu.c         | 6 +++---
 3 files changed, 12 insertions(+), 4 deletions(-)
diff mbox

Patch

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 2d29b5e..7072fb5 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -1063,6 +1063,9 @@  out:
     return cpu;
 }
 
+static void pc_machine_device_unplug_request_cb(HotplugHandler *hotplug_dev,
+                                                DeviceState *dev, Error **errp);
+
 void pc_hot_add_cpu(const int64_t id, Error **errp)
 {
     X86CPU *cpu;
@@ -1076,6 +1079,11 @@  void pc_hot_add_cpu(const int64_t id, Error **errp)
     }
 
     if (cpu_exists(apic_id)) {
+        DeviceState *dev = DEVICE(cpu_exists(apic_id));
+        pc_machine_device_unplug_request_cb(
+            qdev_get_hotplug_handler(dev),
+            dev,
+            &local_err);
         error_setg(errp, "Unable to add CPU: %" PRIi64
                    ", it already exists", id);
         return;
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index b7a10f7..da55899 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -629,7 +629,7 @@  CPUState *qemu_get_cpu(int index);
  *
  * Returns: %true - CPU is found, %false - CPU isn't found.
  */
-bool cpu_exists(int64_t id);
+CPUState *cpu_exists(int64_t id);
 
 /**
  * cpu_throttle_set:
diff --git a/qom/cpu.c b/qom/cpu.c
index c9007d3..f3210a2 100644
--- a/qom/cpu.c
+++ b/qom/cpu.c
@@ -29,7 +29,7 @@ 
 #include "qemu/error-report.h"
 #include "sysemu/sysemu.h"
 
-bool cpu_exists(int64_t id)
+CPUState *cpu_exists(int64_t id)
 {
     CPUState *cpu;
 
@@ -37,10 +37,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)