From: Marcelo Tosatti <mtosatti@redhat.com>
To: qemu-devel@nongnu.org, kvm-devel@lists.sourceforge.net
Cc: aliguori@us.ibm.com, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [Qemu-devel] [patch 24/24] QEMU/KVM: device hot-remove
Date: Tue, 11 Mar 2008 17:12:15 -0300 [thread overview]
Message-ID: <20080311201419.123995962@localhost.localdomain> (raw)
In-Reply-To: 20080311201151.959635433@localhost.localdomain
[-- Attachment #1: monitor-remove --]
[-- Type: text/plain, Size: 4701 bytes --]
Add monitor command to hot-remove devices.
Remove device data on _EJ0 notification.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm-userspace.hotplug2/qemu/monitor.c
===================================================================
--- kvm-userspace.hotplug2.orig/qemu/monitor.c
+++ kvm-userspace.hotplug2/qemu/monitor.c
@@ -1365,6 +1365,7 @@ static term_cmd_t term_cmds[] = {
"[snapshot=on|off][,cache=on|off]",
"add drive to PCI storage controller" },
{ "pci_add", "iss", device_hot_add, "bus nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
+ { "pci_del", "ii", device_hot_remove, "bus slot-number", "hot remove PCI device" },
{ NULL, NULL, },
};
Index: kvm-userspace.hotplug2/qemu/hw/device-hotplug.c
===================================================================
--- kvm-userspace.hotplug2.orig/qemu/hw/device-hotplug.c
+++ kvm-userspace.hotplug2/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)
{
@@ -148,7 +150,7 @@ void device_hot_add(int pcibus, const ch
term_printf("invalid type: %s\n", type);
if (dev) {
- qemu_system_device_hot_add(PCI_SLOT(dev->devfn), 1);
+ qemu_system_device_hot_add(pcibus, PCI_SLOT(dev->devfn), 1);
term_printf("OK bus %d, slot %d, function %d (devfn %d)\n",
pci_bus_num(dev->bus), PCI_SLOT(dev->devfn),
PCI_FUNC(dev->devfn), dev->devfn);
@@ -156,3 +158,67 @@ void device_hot_add(int pcibus, const ch
term_printf("failed to add %s\n", opts);
}
+void device_hot_remove(int pcibus, int slot)
+{
+ PCIDevice *d = pci_find_device(pcibus, slot);
+
+ if (!d) {
+ term_printf("invalid slot %d\n", slot);
+ return;
+ }
+
+ qemu_system_device_hot_add(pcibus, 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 pcibus, int slot)
+{
+ PCIDevice *d = pci_find_device(pcibus, 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.hotplug2/qemu/sysemu.h
===================================================================
--- kvm-userspace.hotplug2.orig/qemu/sysemu.h
+++ kvm-userspace.hotplug2/qemu/sysemu.h
@@ -176,11 +176,13 @@ extern int drive_init(struct drive_opt *
/* acpi */
void qemu_system_cpu_hot_add(int cpu, int state);
void qemu_system_hot_add_init(char *cpu_model);
-void qemu_system_device_hot_add(int slot, int state);
+void qemu_system_device_hot_add(int pcibus, int slot, int state);
/* device-hotplug */
void device_hot_add(int pcibus, const char *type, const char *opts);
void drive_hot_add(int pcibus, const char *devfn_string, const char *opts);
+void device_hot_remove(int pcibus, int slot);
+void device_hot_remove_success(int pcibus, int slot);
/* vmchannel devices */
Index: kvm-userspace.hotplug2/qemu/hw/acpi.c
===================================================================
--- kvm-userspace.hotplug2.orig/qemu/hw/acpi.c
+++ kvm-userspace.hotplug2/qemu/hw/acpi.c
@@ -673,6 +673,8 @@ static void pciej_write(void *opaque, ui
{
int slot = ffs(val) - 1;
+ device_hot_remove_success(0, slot);
+
#if defined(DEBUG)
printf("pciej write %lx <== %d\n", addr, val);
#endif
@@ -751,7 +753,7 @@ static void disable_device(struct pci_st
p->down |= (1 << slot);
}
-void qemu_system_device_hot_add(int slot, int state)
+void qemu_system_device_hot_add(int pcibus, int slot, int state)
{
qemu_set_irq(pm_state->irq, 1);
pci0_status.up = 0;
--
next prev parent reply other threads:[~2008-03-11 20:17 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-11 20:11 [Qemu-devel] [patch 00/24] QEMU ACPI PCI hotplug support Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 01/24] QEMU/KVM: add devices to represent PCI slots with _EJ0 method Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 02/24] QEMU/KVM: add OperationRegion and GPE handler for add/removal notification Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 03/24] QEMU/KVM: add pci_find_bus Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 04/24] QEMU/KVM: return PCIDevice on net device init and record devfn Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 05/24] QEMU/KVM: pci hotplug GPE support Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 06/24] QEMU/KVM: dynamic drive/drive_opt index allocation Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 07/24] QEMU/KVM: dynamic nic info " Marcelo Tosatti
2008-03-11 20:11 ` [Qemu-devel] [patch 08/24] QEMU/KVM: drive removal support Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 09/24] QEMU/KVM: record devfn on block driver instance Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 10/24] QEMU/KVM: move drives_opt for external use Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 11/24] QEMU/KVM: net/drive add/remove tweaks Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 12/24] QEMU/KVM: add net_client_uninit Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 13/24] QEMU/KVM: export get_param_value/check_params Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 14/24] QEMU/KVM: add pci_find_device Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 15/24] QEMU/KVM: virtio_blk_init return PCIDevice pointer Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 16/24] QEMU/KVM: device and disk hot-add Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 17/24] QEMU/KVM: add cpu_unregister_io_memory and make io mem table index dynamic Marcelo Tosatti
2008-03-18 12:32 ` [Qemu-devel] Re: [kvm-devel] " Amit Shah
2008-03-18 13:54 ` Marcelo Tosatti
2008-03-18 14:13 ` [Qemu-devel] " Amit Shah
2008-03-18 15:22 ` [Qemu-devel] " Avi Kivity
2008-03-11 20:12 ` [Qemu-devel] [patch 18/24] QEMU/KVM: notify _EJ0 through _SEJ OperationRegion Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 19/24] QEMU/KVM: handle SEJ notifications Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 20/24] QEMU/KVM: add qemu_free_irqs Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 21/24] QEMU/KVM: add pci_unregister_device Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 22/24] QEMU/KVM: LSI SCSI and e1000 unregister callbacks Marcelo Tosatti
2008-03-11 20:12 ` [Qemu-devel] [patch 23/24] QEMU/KVM: zero ioport_opaque on isa_unassign_ioport Marcelo Tosatti
2008-03-11 20:12 ` Marcelo Tosatti [this message]
2008-03-16 12:30 ` [Qemu-devel] Re: [kvm-devel] [patch 00/24] QEMU ACPI PCI hotplug support Avi Kivity
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20080311201419.123995962@localhost.localdomain \
--to=mtosatti@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kvm-devel@lists.sourceforge.net \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).