* [PATCH 3/8] kvm: qemu: fix hot assign device
@ 2009-02-18 7:12 Han, Weidong
2009-02-18 17:16 ` Marcelo Tosatti
0 siblings, 1 reply; 2+ messages in thread
From: Han, Weidong @ 2009-02-18 7:12 UTC (permalink / raw)
To: 'Avi Kivity'
Cc: 'kvm@vger.kernel.org', 'Mark McLoughlin',
'Marcelo Tosatti'
[-- Attachment #1: Type: text/plain, Size: 5164 bytes --]
Last qemu merge broke device assignment hotplug. Call
qemu_pci_hot_assign_device in pci_device_hot_add for
hot assign device, and add the command for it.
for example hot assign 01:00.0, can use following command:
pci_add pci_addr=auto host host=01:00.0
Signed-off-by: Weidong Han <weidong.han@intel.com>
---
qemu/hw/device-hotplug.c | 37 -------------------------------------
qemu/hw/pci-hotplug.c | 35 +++++++++++++++++++++++++++++++++++
qemu/monitor.c | 2 +-
3 files changed, 36 insertions(+), 38 deletions(-)
diff --git a/qemu/hw/device-hotplug.c b/qemu/hw/device-hotplug.c
index ae72a00..782b6b4 100644
--- a/qemu/hw/device-hotplug.c
+++ b/qemu/hw/device-hotplug.c
@@ -30,49 +30,12 @@
#include "pci.h"
#include "pc.h"
#include "console.h"
-#include "device-assignment.h"
#include "config.h"
#include "virtio-blk.h"
#define PCI_BASE_CLASS_STORAGE 0x01
#define PCI_BASE_CLASS_NETWORK 0x02
-#ifdef USE_KVM_DEVICE_ASSIGNMENT
-static PCIDevice *qemu_system_hot_assign_device(const char *opts, int bus_nr)
-{
- PCIBus *pci_bus;
- AssignedDevInfo *adev;
- PCIDevice *ret;
-
- pci_bus = pci_find_bus(bus_nr);
- if (!pci_bus) {
- term_printf ("Can't find pci_bus %d\n", bus_nr);
- return NULL;
- }
- adev = add_assigned_device(opts);
- if (adev == NULL) {
- term_printf ("Error adding device; check syntax\n");
- return NULL;
- }
-
- ret = init_assigned_device(adev, pci_bus);
- if (ret == NULL) {
- term_printf("Failed to assign device\n");
- free_assigned_device(adev);
- return NULL;
- }
-
- term_printf("Registered host PCI device %02x:%02x.%1x "
- "(\"%s\") as guest device %02x:%02x.%1x\n",
- adev->bus, adev->dev, adev->func, adev->name,
- pci_bus_num(pci_bus), (ret->devfn >> 3) & 0x1f,
- adev->func);
-
- return ret;
-}
-
-#endif /* USE_KVM_DEVICE_ASSIGNMENT */
-
int add_init_drive(const char *opts)
{
int drive_opt_idx, drive_idx;
diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c
index 6286764..8c76453 100644
--- a/qemu/hw/pci-hotplug.c
+++ b/qemu/hw/pci-hotplug.c
@@ -31,6 +31,7 @@
#include "console.h"
#include "block_int.h"
#include "virtio-blk.h"
+#include "device-assignment.h"
#if defined(TARGET_I386) || defined(TARGET_X86_64)
static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts)
@@ -127,6 +128,36 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
return opaque;
}
+#ifdef USE_KVM_DEVICE_ASSIGNMENT
+static PCIDevice *qemu_pci_hot_assign_device(PCIBus *pci_bus, const char *opts)
+{
+ AssignedDevInfo *adev;
+ PCIDevice *ret;
+
+ adev = add_assigned_device(opts);
+ if (adev == NULL) {
+ term_printf ("Error adding device; check syntax\n");
+ return NULL;
+ }
+
+ ret = init_assigned_device(adev, pci_bus);
+ if (ret == NULL) {
+ term_printf("Failed to assign device\n");
+ free_assigned_device(adev);
+ return NULL;
+ }
+
+ term_printf("Registered host PCI device %02x:%02x.%1x "
+ "(\"%s\") as guest device %02x:%02x.%1x\n",
+ adev->bus, adev->dev, adev->func, adev->name,
+ pci_bus_num(pci_bus), (ret->devfn >> 3) & 0x1f,
+ adev->func);
+
+ return ret;
+}
+
+#endif /* USE_KVM_DEVICE_ASSIGNMENT */
+
void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts)
{
PCIDevice *dev = NULL;
@@ -149,6 +180,10 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts
dev = qemu_pci_hot_add_nic(pci_bus, opts);
else if (strcmp(type, "storage") == 0)
dev = qemu_pci_hot_add_storage(pci_bus, opts);
+#ifdef USE_KVM_DEVICE_ASSIGNMENT
+ else if (strcmp(type, "host") == 0)
+ dev = qemu_pci_hot_assign_device(pci_bus, opts);
+#endif /* USE_KVM_DEVICE_ASSIGNMENT */
else
term_printf("invalid type: %s\n", type);
diff --git a/qemu/monitor.c b/qemu/monitor.c
index 2699b6f..a4a6eb4 100644
--- a/qemu/monitor.c
+++ b/qemu/monitor.c
@@ -1545,7 +1545,7 @@ static const term_cmd_t term_cmds[] = {
"[,cyls=c,heads=h,secs=s[,trans=t]]\n"
"[snapshot=on|off][,cache=on|off]",
"add drive to PCI storage controller" },
- { "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
+ { "pci_add", "sss", pci_device_hot_add, "pci_addr=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]", "hot-add PCI device" },
{ "pci_del", "s", pci_device_hot_remove, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
{ "host_net_add", "ss", net_host_device_add,
"[tap,user,socket,vde] options", "add host VLAN client" },
--
1.6.0.4
[-- Attachment #2: 0003-kvm-qemu-fix-hot-assign-device.patch --]
[-- Type: application/octet-stream, Size: 5225 bytes --]
From b112720472935817ccd6db33927c7d4e99a5f2e3 Mon Sep 17 00:00:00 2001
From: Weidong Han <weidong.han@intel.com>
Date: Wed, 18 Feb 2009 14:02:35 +0800
Subject: [PATCH] kvm: qemu: fix hot assign device
Last qemu merge broke device assignment hotplug. Call
qemu_pci_hot_assign_device in pci_device_hot_add for
hot assign device, and add the command for it.
for example hot assign 01:00.0, can use following command:
pci_add pci_addr=auto host host=01:00.0
Signed-off-by: Weidong Han <weidong.han@intel.com>
---
qemu/hw/device-hotplug.c | 37 -------------------------------------
qemu/hw/pci-hotplug.c | 35 +++++++++++++++++++++++++++++++++++
qemu/monitor.c | 2 +-
3 files changed, 36 insertions(+), 38 deletions(-)
diff --git a/qemu/hw/device-hotplug.c b/qemu/hw/device-hotplug.c
index ae72a00..782b6b4 100644
--- a/qemu/hw/device-hotplug.c
+++ b/qemu/hw/device-hotplug.c
@@ -30,49 +30,12 @@
#include "pci.h"
#include "pc.h"
#include "console.h"
-#include "device-assignment.h"
#include "config.h"
#include "virtio-blk.h"
#define PCI_BASE_CLASS_STORAGE 0x01
#define PCI_BASE_CLASS_NETWORK 0x02
-#ifdef USE_KVM_DEVICE_ASSIGNMENT
-static PCIDevice *qemu_system_hot_assign_device(const char *opts, int bus_nr)
-{
- PCIBus *pci_bus;
- AssignedDevInfo *adev;
- PCIDevice *ret;
-
- pci_bus = pci_find_bus(bus_nr);
- if (!pci_bus) {
- term_printf ("Can't find pci_bus %d\n", bus_nr);
- return NULL;
- }
- adev = add_assigned_device(opts);
- if (adev == NULL) {
- term_printf ("Error adding device; check syntax\n");
- return NULL;
- }
-
- ret = init_assigned_device(adev, pci_bus);
- if (ret == NULL) {
- term_printf("Failed to assign device\n");
- free_assigned_device(adev);
- return NULL;
- }
-
- term_printf("Registered host PCI device %02x:%02x.%1x "
- "(\"%s\") as guest device %02x:%02x.%1x\n",
- adev->bus, adev->dev, adev->func, adev->name,
- pci_bus_num(pci_bus), (ret->devfn >> 3) & 0x1f,
- adev->func);
-
- return ret;
-}
-
-#endif /* USE_KVM_DEVICE_ASSIGNMENT */
-
int add_init_drive(const char *opts)
{
int drive_opt_idx, drive_idx;
diff --git a/qemu/hw/pci-hotplug.c b/qemu/hw/pci-hotplug.c
index 6286764..8c76453 100644
--- a/qemu/hw/pci-hotplug.c
+++ b/qemu/hw/pci-hotplug.c
@@ -31,6 +31,7 @@
#include "console.h"
#include "block_int.h"
#include "virtio-blk.h"
+#include "device-assignment.h"
#if defined(TARGET_I386) || defined(TARGET_X86_64)
static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts)
@@ -127,6 +128,36 @@ static PCIDevice *qemu_pci_hot_add_storage(PCIBus *pci_bus, const char *opts)
return opaque;
}
+#ifdef USE_KVM_DEVICE_ASSIGNMENT
+static PCIDevice *qemu_pci_hot_assign_device(PCIBus *pci_bus, const char *opts)
+{
+ AssignedDevInfo *adev;
+ PCIDevice *ret;
+
+ adev = add_assigned_device(opts);
+ if (adev == NULL) {
+ term_printf ("Error adding device; check syntax\n");
+ return NULL;
+ }
+
+ ret = init_assigned_device(adev, pci_bus);
+ if (ret == NULL) {
+ term_printf("Failed to assign device\n");
+ free_assigned_device(adev);
+ return NULL;
+ }
+
+ term_printf("Registered host PCI device %02x:%02x.%1x "
+ "(\"%s\") as guest device %02x:%02x.%1x\n",
+ adev->bus, adev->dev, adev->func, adev->name,
+ pci_bus_num(pci_bus), (ret->devfn >> 3) & 0x1f,
+ adev->func);
+
+ return ret;
+}
+
+#endif /* USE_KVM_DEVICE_ASSIGNMENT */
+
void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts)
{
PCIDevice *dev = NULL;
@@ -149,6 +180,10 @@ void pci_device_hot_add(const char *pci_addr, const char *type, const char *opts
dev = qemu_pci_hot_add_nic(pci_bus, opts);
else if (strcmp(type, "storage") == 0)
dev = qemu_pci_hot_add_storage(pci_bus, opts);
+#ifdef USE_KVM_DEVICE_ASSIGNMENT
+ else if (strcmp(type, "host") == 0)
+ dev = qemu_pci_hot_assign_device(pci_bus, opts);
+#endif /* USE_KVM_DEVICE_ASSIGNMENT */
else
term_printf("invalid type: %s\n", type);
diff --git a/qemu/monitor.c b/qemu/monitor.c
index 2699b6f..a4a6eb4 100644
--- a/qemu/monitor.c
+++ b/qemu/monitor.c
@@ -1545,7 +1545,7 @@ static const term_cmd_t term_cmds[] = {
"[,cyls=c,heads=h,secs=s[,trans=t]]\n"
"[snapshot=on|off][,cache=on|off]",
"add drive to PCI storage controller" },
- { "pci_add", "sss", pci_device_hot_add, "pci_addr=auto|[[<domain>:]<bus>:]<slot> nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" },
+ { "pci_add", "sss", pci_device_hot_add, "pci_addr=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]", "hot-add PCI device" },
{ "pci_del", "s", pci_device_hot_remove, "pci_addr=[[<domain>:]<bus>:]<slot>", "hot remove PCI device" },
{ "host_net_add", "ss", net_host_device_add,
"[tap,user,socket,vde] options", "add host VLAN client" },
--
1.6.0.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH 3/8] kvm: qemu: fix hot assign device
2009-02-18 7:12 [PATCH 3/8] kvm: qemu: fix hot assign device Han, Weidong
@ 2009-02-18 17:16 ` Marcelo Tosatti
0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2009-02-18 17:16 UTC (permalink / raw)
To: Han, Weidong
Cc: 'Avi Kivity', 'kvm@vger.kernel.org',
'Mark McLoughlin'
Acked-by: Marcelo Tosatti <mtosatti@redhat.com>
On Wed, Feb 18, 2009 at 03:12:31PM +0800, Han, Weidong wrote:
> Last qemu merge broke device assignment hotplug. Call
> qemu_pci_hot_assign_device in pci_device_hot_add for
> hot assign device, and add the command for it.
> for example hot assign 01:00.0, can use following command:
> pci_add pci_addr=auto host host=01:00.0
>
> Signed-off-by: Weidong Han <weidong.han@intel.com>
> ---
> qemu/hw/device-hotplug.c | 37 -------------------------------------
> qemu/hw/pci-hotplug.c | 35 +++++++++++++++++++++++++++++++++++
> qemu/monitor.c | 2 +-
> 3 files changed, 36 insertions(+), 38 deletions(-)
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-02-18 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-18 7:12 [PATCH 3/8] kvm: qemu: fix hot assign device Han, Weidong
2009-02-18 17:16 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox