[RFC,qom-cpu,v2,3/8] qmp: add 'cpu-del' command support

Submitted by chenfan on Sept. 10, 2013, 9:43 a.m.

Details

Message ID c3ca3023ce03e275ccc1242836270bbe0b6edd43.1378796990.git.chen.fan.fnst@cn.fujitsu.com
State New
Headers show

Commit Message

chenfan Sept. 10, 2013, 9:43 a.m.
Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
---
 hw/i386/pc.c         |  5 +++++
 hw/i386/pc_piix.c    |  1 +
 include/hw/boards.h  |  2 ++
 include/hw/i386/pc.h |  1 +
 qapi-schema.json     | 12 ++++++++++++
 qmp-commands.hx      | 23 +++++++++++++++++++++++
 qmp.c                |  9 +++++++++
 7 files changed, 53 insertions(+)

Comments

Eric Blake Sept. 10, 2013, 3:52 p.m.
On 09/10/2013 03:43 AM, Chen Fan wrote:
> Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> ---
>  hw/i386/pc.c         |  5 +++++
>  hw/i386/pc_piix.c    |  1 +
>  include/hw/boards.h  |  2 ++
>  include/hw/i386/pc.h |  1 +
>  qapi-schema.json     | 12 ++++++++++++
>  qmp-commands.hx      | 23 +++++++++++++++++++++++
>  qmp.c                |  9 +++++++++
>  7 files changed, 53 insertions(+)
> 
> diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> index 0c313fe..3de9c51 100644
> --- a/hw/i386/pc.c
> +++ b/hw/i386/pc.c
> @@ -957,6 +957,11 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
>      pc_new_cpu(current_cpu_model, apic_id, icc_bridge, errp);
>  }
>  
> +void pc_hot_del_cpu(const int64_t id, Error **errp)
> +{
> +    /* TODO: hot remove vCPU. */

Even if you implement things later, it's better to at least set errp
here rather than having a command that silently does nothing but
succeeds.  Or squash the two patches together so that you are providing
functionality at the time you expose the QMP.

Otherwise, looks fine from the QMP perspective.
chenfan Sept. 11, 2013, 2:32 a.m.
On Tue, 2013-09-10 at 09:52 -0600, Eric Blake wrote:
> On 09/10/2013 03:43 AM, Chen Fan wrote:
> > Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> > ---
> >  hw/i386/pc.c         |  5 +++++
> >  hw/i386/pc_piix.c    |  1 +
> >  include/hw/boards.h  |  2 ++
> >  include/hw/i386/pc.h |  1 +
> >  qapi-schema.json     | 12 ++++++++++++
> >  qmp-commands.hx      | 23 +++++++++++++++++++++++
> >  qmp.c                |  9 +++++++++
> >  7 files changed, 53 insertions(+)
> > 
> > diff --git a/hw/i386/pc.c b/hw/i386/pc.c
> > index 0c313fe..3de9c51 100644
> > --- a/hw/i386/pc.c
> > +++ b/hw/i386/pc.c
> > @@ -957,6 +957,11 @@ void pc_hot_add_cpu(const int64_t id, Error **errp)
> >      pc_new_cpu(current_cpu_model, apic_id, icc_bridge, errp);
> >  }
> >  
> > +void pc_hot_del_cpu(const int64_t id, Error **errp)
> > +{
> > +    /* TODO: hot remove vCPU. */
> 
> Even if you implement things later, it's better to at least set errp
> here rather than having a command that silently does nothing but
> succeeds.  Or squash the two patches together so that you are providing
> functionality at the time you expose the QMP.
I should temporarily set some errp here in this patch. Thanks for you
comment.

> 
> Otherwise, looks fine from the QMP perspective.
>

Patch hide | download patch | download mbox

diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index 0c313fe..3de9c51 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -957,6 +957,11 @@  void pc_hot_add_cpu(const int64_t id, Error **errp)
     pc_new_cpu(current_cpu_model, apic_id, icc_bridge, errp);
 }
 
+void pc_hot_del_cpu(const int64_t id, Error **errp)
+{
+    /* TODO: hot remove vCPU. */
+}
+
 void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge)
 {
     int i;
diff --git a/hw/i386/pc_piix.c b/hw/i386/pc_piix.c
index 6e1e654..d779b75 100644
--- a/hw/i386/pc_piix.c
+++ b/hw/i386/pc_piix.c
@@ -347,6 +347,7 @@  static QEMUMachine pc_i440fx_machine_v1_6 = {
     .desc = "Standard PC (i440FX + PIIX, 1996)",
     .init = pc_init_pci_1_6,
     .hot_add_cpu = pc_hot_add_cpu,
+    .hot_del_cpu = pc_hot_del_cpu,
     .max_cpus = 255,
     .is_default = 1,
     DEFAULT_MACHINE_OPTIONS,
diff --git a/include/hw/boards.h b/include/hw/boards.h
index fb7c6f1..fea3737 100644
--- a/include/hw/boards.h
+++ b/include/hw/boards.h
@@ -23,6 +23,7 @@  typedef void QEMUMachineInitFunc(QEMUMachineInitArgs *args);
 typedef void QEMUMachineResetFunc(void);
 
 typedef void QEMUMachineHotAddCPUFunc(const int64_t id, Error **errp);
+typedef void QEMUMachineHotDelCPUFunc(const int64_t id, Error **errp);
 
 typedef struct QEMUMachine {
     const char *name;
@@ -31,6 +32,7 @@  typedef struct QEMUMachine {
     QEMUMachineInitFunc *init;
     QEMUMachineResetFunc *reset;
     QEMUMachineHotAddCPUFunc *hot_add_cpu;
+    QEMUMachineHotDelCPUFunc *hot_del_cpu;
     BlockInterfaceType block_default_type;
     int max_cpus;
     unsigned int no_serial:1,
diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h
index f79d478..b7e66f4 100644
--- a/include/hw/i386/pc.h
+++ b/include/hw/i386/pc.h
@@ -96,6 +96,7 @@  void pc_acpi_smi_interrupt(void *opaque, int irq, int level);
 
 void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge);
 void pc_hot_add_cpu(const int64_t id, Error **errp);
+void pc_hot_del_cpu(const int64_t id, Error **errp);
 void pc_acpi_init(const char *default_dsdt);
 
 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size,
diff --git a/qapi-schema.json b/qapi-schema.json
index a51f7d2..6052aa9 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -1432,6 +1432,18 @@ 
 ##
 { 'command': 'cpu-add', 'data': {'id': 'int'} }
 
+# @cpu-del
+
+# Deletes CPU with specified ID
+#
+# @id: ID of CPU to be deleted, valid values [0..max_cpus)
+#
+# Returns: Nothing on success
+#
+# Since 1.7
+##
+{ 'command': 'cpu-del', 'data': {'id': 'int'} }
+
 ##
 # @memsave:
 #
diff --git a/qmp-commands.hx b/qmp-commands.hx
index cf47e3f..16b54fd 100644
--- a/qmp-commands.hx
+++ b/qmp-commands.hx
@@ -411,6 +411,29 @@  Example:
 EQMP
 
     {
+        .name       = "cpu-del",
+        .args_type  = "id:i",
+        .mhandler.cmd_new = qmp_marshal_input_cpu_del,
+    },
+
+SQMP
+cpu-del
+-------
+
+Deletes virtual cpu
+
+Arguments:
+
+- "id": cpu id (json-int)
+
+Example:
+
+-> { "execute": "cpu-del", "arguments": { "id": 2 } }
+<- { "return": {} }
+
+EQMP
+
+    {
         .name       = "memsave",
         .args_type  = "val:l,size:i,filename:s,cpu:i?",
         .mhandler.cmd_new = qmp_marshal_input_memsave,
diff --git a/qmp.c b/qmp.c
index 4c149b3..84dc873 100644
--- a/qmp.c
+++ b/qmp.c
@@ -118,6 +118,15 @@  void qmp_cpu_add(int64_t id, Error **errp)
     }
 }
 
+void qmp_cpu_del(int64_t id, Error **errp)
+{
+    if (current_machine->hot_del_cpu) {
+        current_machine->hot_del_cpu(id, errp);
+    } else {
+        error_setg(errp, "Not supported");
+    }
+}
+
 #ifndef CONFIG_VNC
 /* If VNC support is enabled, the "true" query-vnc command is
    defined in the VNC subsystem */