From 1917ed3b418d3820ab811b5132ad98124248fef7 Mon Sep 17 00:00:00 2001
From: Luiz Capitulino <lcapitulino@redhat.com>
Date: Mon, 29 Mar 2010 16:14:44 -0300
Subject: [PATCH 09/23] Monitor: Convert pci_device_hot_add() to cmd_new_ret()

RH-Author: Luiz Capitulino <lcapitulino@redhat.com>
Message-id: <1269879298-30711-10-git-send-email-lcapitulino@redhat.com>
Patchwork-id: 8171
O-Subject: [PATCH 09/23] Monitor: Convert pci_device_hot_add() to cmd_new_ret()
Bugzilla: 563491
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
RH-Acked-by: Juan Quintela <quintela@redhat.com>
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>

Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
---
 hw/pci-hotplug.c |   20 ++++++++++++++------
 qemu-monitor.hx  |    2 +-
 sysemu.h         |    2 +-
 3 files changed, 16 insertions(+), 8 deletions(-)

Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
 hw/pci-hotplug.c |   20 ++++++++++++++------
 qemu-monitor.hx  |    2 +-
 sysemu.h         |    2 +-
 3 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index fb28254..3680357 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -273,7 +273,7 @@ void pci_device_hot_add_print(Monitor *mon, const QObject *data)
  *
  * { "domain": 0, "bus": 0, "slot": 5, "function": 0 }
  */
-void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
+int pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     PCIDevice *dev = NULL;
     const char *pci_addr = qdict_get_str(qdict, "pci_addr");
@@ -292,24 +292,32 @@ void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
     if (!strcmp(pci_addr, "auto"))
         pci_addr = NULL;
 
-    if (strcmp(type, "nic") == 0)
+    if (strcmp(type, "nic") == 0) {
         dev = qemu_pci_hot_add_nic(mon, pci_addr, opts);
-    else if (strcmp(type, "storage") == 0)
+    } else if (strcmp(type, "storage") == 0) {
         dev = qemu_pci_hot_add_storage(mon, pci_addr, opts);
+    }
 #ifdef CONFIG_KVM_DEVICE_ASSIGNMENT
-    else if (strcmp(type, "host") == 0)
+    else if (strcmp(type, "host") == 0) {
         dev = qemu_pci_hot_assign_device(mon, pci_addr, opts);
+    }
 #endif /* CONFIG_KVM_DEVICE_ASSIGNMENT */
-    else
+    else {
         monitor_printf(mon, "invalid type: %s\n", type);
+        return -1;
+    }
 
     if (dev) {
         *ret_data =
         qobject_from_jsonf("{ 'domain': 0, 'bus': %d, 'slot': %d, "
                            "'function': %d }", pci_bus_num(dev->bus),
                            PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
-    } else
+    } else {
         monitor_printf(mon, "failed to add %s\n", opts);
+        return -1;
+    }
+
+    return 0;
 }
 #endif
 
diff --git a/qemu-monitor.hx b/qemu-monitor.hx
index c22fee5..0ddf249 100644
--- a/qemu-monitor.hx
+++ b/qemu-monitor.hx
@@ -813,7 +813,7 @@ ETEXI
         .params     = "auto|[[<domain>:]<bus>:]<slot> nic|storage|host [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]... [host=02:00.0[,name=string][,dma=none]",
         .help       = "hot-add PCI device",
         .user_print = pci_device_hot_add_print,
-        .mhandler.cmd_new = pci_device_hot_add,
+        .cmd_new_ret = pci_device_hot_add,
     },
 #endif
 
diff --git a/sysemu.h b/sysemu.h
index e2ec29a..2593426 100644
--- a/sysemu.h
+++ b/sysemu.h
@@ -220,7 +220,7 @@ DriveInfo *add_init_drive(const char *opts);
 
 /* pci-hotplug */
 void pci_device_hot_add_print(Monitor *mon, const QObject *data);
-void pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
+int pci_device_hot_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
 void drive_hot_add(Monitor *mon, const QDict *qdict);
 void pci_device_hot_remove(Monitor *mon, const char *pci_addr);
 void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict,
-- 
1.7.0.3

