From: Marcelo Tosatti <mtosatti@redhat.com>
To: kvm-devel@lists.sourceforge.net
Cc: Marcelo Tosatti <mtosatti@redhat.com>,
Avi Kivity <avi@qumranet.com>, Glauber Costa <gcosta@redhat.com>
Subject: [patch 14/23] QEMU/KVM: device hot-add
Date: Tue, 04 Mar 2008 15:34:33 -0300 [thread overview]
Message-ID: <20080304183903.567712544@localhost.localdomain> (raw)
In-Reply-To: 20080304183419.187172133@localhost.localdomain
[-- Attachment #1: monitor --]
[-- Type: text/plain, Size: 5764 bytes --]
Add monitor command to hot-add PCI devices (nic and drive).
Save QEMUMachine necessary for drive_init.
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Index: kvm-userspace.hotplug/qemu/Makefile.target
===================================================================
--- kvm-userspace.hotplug.orig/qemu/Makefile.target
+++ kvm-userspace.hotplug/qemu/Makefile.target
@@ -576,6 +576,8 @@ OBJS+= hypercall.o
# virtio devices
OBJS += virtio.o virtio-net.o virtio-blk.o
+OBJS += device-hotplug.o
+
ifeq ($(TARGET_BASE_ARCH), i386)
# Hardware support
OBJS+= ide.o pckbd.o ps2.o vga.o $(SOUND_HW) dma.o
Index: kvm-userspace.hotplug/qemu/hw/device-hotplug.c
===================================================================
--- /dev/null
+++ kvm-userspace.hotplug/qemu/hw/device-hotplug.c
@@ -0,0 +1,92 @@
+#include "hw.h"
+#include "boards.h"
+#include "pci.h"
+#include "net.h"
+#include "sysemu.h"
+#include "pc.h"
+#include "console.h"
+
+static PCIDevice *qemu_system_hot_add_nic(const char *opts, int bus_nr)
+{
+ int ret;
+ char buf[4096];
+ PCIBus *pci_bus;
+
+ pci_bus = pci_find_bus (bus_nr);
+ if (!pci_bus) {
+ term_printf ("Can't find pci_bus %d\n", bus_nr);
+ return NULL;
+ }
+
+ memset (buf, 0, sizeof (buf));
+
+ strcpy (buf, "nic,");
+ strncat (buf, opts, sizeof (buf) - strlen (buf) - 1);
+
+ ret = net_client_init (buf);
+ if (ret < 0 || !nd_table[ret].model)
+ return NULL;
+ return pci_nic_init (pci_bus, &nd_table[ret], -1);
+}
+
+static PCIDevice *qemu_system_hot_add_drive(const char *opts, int bus_nr)
+{
+ int drive_opt_idx, drive_idx;
+ int type = 0;
+ int bus = 0;
+ void *opaque = NULL;
+ PCIBus *pci_bus;
+
+ pci_bus = pci_find_bus(bus_nr);
+ if (!pci_bus) {
+ term_printf("Can't find pci_bus %d\n", bus_nr);
+ return NULL;
+ }
+
+ drive_opt_idx = drive_add(NULL, "%s", opts);
+ if (!drive_opt_idx)
+ return NULL;
+
+ drive_idx = drive_init(&drives_opt[drive_opt_idx], 0, current_machine);
+ if (drive_idx == -1) {
+ drive_remove(drive_opt_idx);
+ return NULL;
+ }
+
+ type = drives_table[drive_idx].type;
+ bus = drive_get_max_bus (type);
+
+ switch (type) {
+ case IF_SCSI:
+ /* XXX: additional unit on existing device? */
+ opaque = lsi_scsi_init (pci_bus, -1);
+ lsi_scsi_attach (opaque, drives_table[drive_idx].bdrv,
+ drives_table[drive_idx].unit);
+ break;
+ case IF_VIRTIO:
+ opaque = virtio_blk_init (pci_bus, 0x1AF4, 0x1001,
+ drives_table[drive_idx].bdrv);
+ break;
+ default:
+ term_printf ("type %d not a PCI device!\n", type);
+ }
+
+ return opaque;
+}
+
+void device_hot_add(const char *type, const char *opts)
+{
+ PCIDevice *dev = NULL;
+
+ if (strcmp(type, "nic") == 0)
+ dev = qemu_system_hot_add_nic(opts, 0);
+ else if (strcmp(type, "drive") == 0)
+ dev = qemu_system_hot_add_drive(opts, 0);
+ else
+ term_printf("invalid type: %s\n", type);
+
+ if (dev)
+ qemu_system_device_hot_add(PCI_SLOT(dev->devfn), 1);
+ else
+ term_printf("failed to add %s\n", opts);
+}
Index: kvm-userspace.hotplug/qemu/monitor.c
===================================================================
--- kvm-userspace.hotplug.orig/qemu/monitor.c
+++ kvm-userspace.hotplug/qemu/monitor.c
@@ -1354,6 +1354,7 @@ static term_cmd_t term_cmds[] = {
{ "migrate_set_speed", "s", do_migrate_set_speed,
"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" },
{ NULL, NULL, },
};
Index: kvm-userspace.hotplug/qemu/hw/boards.h
===================================================================
--- kvm-userspace.hotplug.orig/qemu/hw/boards.h
+++ kvm-userspace.hotplug/qemu/hw/boards.h
@@ -19,6 +19,8 @@ typedef struct QEMUMachine {
int qemu_register_machine(QEMUMachine *m);
+extern QEMUMachine *current_machine;
+
/* Axis ETRAX. */
extern QEMUMachine bareetraxfs_machine;
Index: kvm-userspace.hotplug/qemu/sysemu.h
===================================================================
--- kvm-userspace.hotplug.orig/qemu/sysemu.h
+++ kvm-userspace.hotplug/qemu/sysemu.h
@@ -174,6 +174,10 @@ 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);
+
+/* device-hotplug */
+void device_hot_add(const char *type, const char *opts);
/* vmchannel devices */
Index: kvm-userspace.hotplug/qemu/vl.c
===================================================================
--- kvm-userspace.hotplug.orig/qemu/vl.c
+++ kvm-userspace.hotplug/qemu/vl.c
@@ -7573,6 +7573,7 @@ void qemu_bh_delete(QEMUBH *bh)
/* machine registration */
QEMUMachine *first_machine = NULL;
+QEMUMachine *current_machine = NULL;
int qemu_register_machine(QEMUMachine *m)
{
@@ -9703,6 +9704,8 @@ int main(int argc, char **argv)
machine->init(ram_size, vga_ram_size, boot_devices, ds,
kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
+ current_machine = machine;
+
/* init USB devices */
if (usb_enabled) {
for(i = 0; i < usb_devices_index; i++) {
--
-------------------------------------------------------------------------
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/
next prev parent reply other threads:[~2008-03-04 18:34 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-03-04 18:34 [patch 00/23] [RFC] QEMU/KVM ACPI PCI hotplug Marcelo Tosatti
2008-03-04 18:34 ` [patch 01/23] QEMU/KVM: add PCI IRQ routing information up to slot 32 Marcelo Tosatti
2008-03-05 5:40 ` Avi Kivity
2008-03-04 18:34 ` [patch 02/23] QEMU/KVM: add devices to represent PCI slots with _EJ0 method Marcelo Tosatti
2008-03-04 18:34 ` [patch 03/23] QEMU/KVM: add OperationRegion and GPE handler for add/removal notification Marcelo Tosatti
2008-03-04 18:34 ` [patch 04/23] QEMU/KVM: add pci_find_bus Marcelo Tosatti
2008-03-04 18:34 ` [patch 05/23] QEMU/KVM: return PCIDevice on net device init and record devfn Marcelo Tosatti
2008-03-04 18:34 ` [patch 06/23] QEMU/KVM: pci hotplug GPE support Marcelo Tosatti
2008-03-04 18:34 ` [patch 07/23] QEMU/KVM: dynamic drive/drive_opt index allocation Marcelo Tosatti
2008-03-04 18:34 ` [patch 08/23] QEMU/KVM: dynamic nic info " Marcelo Tosatti
2008-03-04 18:34 ` [patch 09/23] QEMU/KVM: drive removal support Marcelo Tosatti
2008-03-04 18:34 ` [patch 10/23] QEMU/KVM: record devfn on block driver instance Marcelo Tosatti
2008-03-04 18:34 ` [patch 11/23] QEMU/KVM: move drives_opt for external use Marcelo Tosatti
2008-03-04 18:34 ` [patch 12/23] QEMU/KVM: net/drive add/remove tweaks Marcelo Tosatti
2008-03-04 18:34 ` [patch 13/23] QEMU/KVM: add net_client_uninit Marcelo Tosatti
2008-03-04 18:34 ` Marcelo Tosatti [this message]
2008-03-04 19:14 ` [patch 14/23] QEMU/KVM: device hot-add Daniel P. Berrange
2008-03-04 19:30 ` Anthony Liguori
2008-03-04 19:53 ` Daniel P. Berrange
2008-03-04 21:44 ` Itamar Heim
2008-03-05 5:50 ` Avi Kivity
2008-03-11 14:18 ` Marcelo Tosatti
2008-03-04 18:34 ` [patch 15/23] QEMU/KVM: add pci_find_device Marcelo Tosatti
2008-03-04 18:34 ` [patch 16/23] QEMU/KVM: add cpu_unregister_io_memory and make io mem table index dynamic Marcelo Tosatti
2008-03-04 18:34 ` [patch 17/23] QEMU/KVM: notify _EJ0 through _SEJ OperationRegion Marcelo Tosatti
2008-03-04 18:34 ` [patch 18/23] QEMU/KVM: handle SEJ notifications Marcelo Tosatti
2008-03-04 18:34 ` [patch 19/23] QEMU/KVM: add qemu_free_irqs Marcelo Tosatti
2008-03-04 18:34 ` [patch 20/23] QEMU/KVM: add pci_unregister_device Marcelo Tosatti
2008-03-04 18:34 ` [patch 21/23] QEMU/KVM: LSI SCSI unregister callback Marcelo Tosatti
2008-03-04 18:34 ` [patch 22/23] QEMU/KVM: zero ioport_opaque on isa_unassign_ioport Marcelo Tosatti
2008-03-04 18:34 ` [patch 23/23] QEMU/KVM: device hot-remove Marcelo Tosatti
2008-03-04 19:18 ` Daniel P. Berrange
2008-03-04 19:32 ` Anthony Liguori
2008-03-04 20:00 ` Marcelo Tosatti
2008-03-04 20:06 ` Daniel P. Berrange
2008-03-05 6:28 ` Avi Kivity
2008-03-05 5:46 ` Avi Kivity
2008-03-05 6:47 ` Avi Kivity
2008-03-05 6:00 ` [patch 00/23] [RFC] QEMU/KVM ACPI PCI hotplug 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=20080304183903.567712544@localhost.localdomain \
--to=mtosatti@redhat.com \
--cc=avi@qumranet.com \
--cc=gcosta@redhat.com \
--cc=kvm-devel@lists.sourceforge.net \
/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