Add monitor command to hot-remove devices.
Remove device data on _EJ0 notification.
Signed-off-by: Marcelo Tosatti <[EMAIL PROTECTED]>
Index: kvm-userspace.hotplug/qemu/monitor.c
===================================================================
--- kvm-userspace.hotplug.orig/qemu/monitor.c
+++ kvm-userspace.hotplug/qemu/monitor.c
@@ -1355,6 +1355,7 @@ static term_cmd_t term_cmds[] = {
"value", "set maximum speed (in bytes) for migrations" },
{ "cpu_set", "is", do_cpu_set_nr, "cpu [online|offline]", "change cpu
state" },
{ "pci_add", "ss", device_hot_add, "nic|drive
[vlan=n][,macaddr=addr][,model=type]
[[file=file][,if=type][,bus=n][,unit=m][,media=d][index=i]]", "hotadd PCI
device" },
+ { "pci_remove", "i", device_hot_remove, "slot number", "hot remove PCI
device" },
{ NULL, NULL, },
};
Index: kvm-userspace.hotplug/qemu/hw/device-hotplug.c
===================================================================
--- kvm-userspace.hotplug.orig/qemu/hw/device-hotplug.c
+++ kvm-userspace.hotplug/qemu/hw/device-hotplug.c
@@ -5,6 +5,8 @@
#include "sysemu.h"
#include "pc.h"
#include "console.h"
+#include "block_int.h"
+#include <linux/pci_ids.h>
static PCIDevice *qemu_system_hot_add_nic(const char *opts, int bus_nr)
{
@@ -90,3 +92,67 @@ void device_hot_add(const char *type, co
else
term_printf("failed to add %s\n", opts);
}
+
+void device_hot_remove(int slot)
+{
+ PCIDevice *d = pci_find_device(0, slot);
+
+ if (!d) {
+ term_printf("invalid slot %d\n", slot);
+ return;
+ }
+
+ qemu_system_device_hot_add(slot, 0);
+}
+
+static void destroy_nic(int slot)
+{
+ int i;
+
+ for (i = 0; i < MAX_NICS; i++)
+ if (nd_table[i].used &&
+ PCI_SLOT(nd_table[i].devfn) == slot)
+ net_client_uninit(&nd_table[i]);
+}
+
+static void destroy_bdrvs(int slot)
+{
+ int i;
+ struct BlockDriverState *bs;
+
+ for (i = 0; i <= MAX_DRIVES; i++) {
+ bs = drives_table[i].bdrv;
+ if (bs && (PCI_SLOT(bs->devfn) == slot)) {
+ drive_uninit(bs);
+ bdrv_delete(bs);
+ }
+ }
+}
+
+/*
+ * OS has executed _EJ0 method, we now can remove the device
+ */
+void device_hot_remove_success(int slot)
+{
+ PCIDevice *d = pci_find_device(0, slot);
+ int class_code;
+
+ if (!d) {
+ term_printf("invalid slot %d\n", slot);
+ return;
+ }
+
+ class_code = d->config_read(d, PCI_CLASS_DEVICE+1, 1);
+
+ pci_unregister_device(d);
+
+ switch(class_code) {
+ case PCI_BASE_CLASS_STORAGE:
+ destroy_bdrvs(slot);
+ break;
+ case PCI_BASE_CLASS_NETWORK:
+ destroy_nic(slot);
+ break;
+ }
+
+}
Index: kvm-userspace.hotplug/qemu/sysemu.h
===================================================================
--- kvm-userspace.hotplug.orig/qemu/sysemu.h
+++ kvm-userspace.hotplug/qemu/sysemu.h
@@ -178,6 +178,8 @@ void qemu_system_device_hot_add(int slot
/* device-hotplug */
void device_hot_add(const char *type, const char *opts);
+void device_hot_remove(int slot);
+void device_hot_remove_success(int slot);
/* vmchannel devices */
Index: kvm-userspace.hotplug/qemu/hw/acpi.c
===================================================================
--- kvm-userspace.hotplug.orig/qemu/hw/acpi.c
+++ kvm-userspace.hotplug/qemu/hw/acpi.c
@@ -673,6 +673,8 @@ static void pciej_write(void *opaque, ui
{
int slot = ffs(val) - 1;
+ device_hot_remove_success(slot);
+
#if defined(DEBUG)
printf("pciej write %lx <== %d\n", addr, val);
#endif
--
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
kvm-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/kvm-devel