From patchwork Wed Jan 4 02:13:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexander Graf X-Patchwork-Id: 134182 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 227C1B6F9D for ; Wed, 4 Jan 2012 13:16:35 +1100 (EST) Received: from localhost ([::1]:54509 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiG8i-0000Kk-HS for incoming@patchwork.ozlabs.org; Tue, 03 Jan 2012 20:59:40 -0500 Received: from eggs.gnu.org ([140.186.70.92]:52994) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiG7t-0006QA-B2 for qemu-devel@nongnu.org; Tue, 03 Jan 2012 20:58:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RiG7r-0004Kh-Hp for qemu-devel@nongnu.org; Tue, 03 Jan 2012 20:58:49 -0500 Received: from cantor2.suse.de ([195.135.220.15]:46355 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RiG7r-0004KX-7u for qemu-devel@nongnu.org; Tue, 03 Jan 2012 20:58:47 -0500 Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.221.2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mx2.suse.de (Postfix) with ESMTP id 5C4BE8D167; Wed, 4 Jan 2012 02:58:45 +0100 (CET) From: Alexander Graf To: "qemu-devel@nongnu.org Developers" Date: Wed, 4 Jan 2012 03:13:09 +0100 Message-Id: <1325643192-15941-4-git-send-email-agraf@suse.de> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1325643192-15941-1-git-send-email-agraf@suse.de> References: <1325643192-15941-1-git-send-email-agraf@suse.de> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 195.135.220.15 Cc: Blue Swirl , Aurelien Jarno Subject: [Qemu-devel] [PATCH 3/6] Add generic drive hotplugging X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The monitor command for hotplugging is in i386 specific code. This is just plain wrong, as S390 just learned how to do hotplugging too and needs to get drives for that. So let's add a generic copy to generic code that handles drive_add in a way that doesn't have pci dependencies. All pci specific code can then be handled in a pci specific function. Signed-off-by: Alexander Graf --- v1 -> v2: - align generic drive_add to pci specific one - rework to split between generic and pci code v2 -> v3: - remove comment --- hw/device-hotplug.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ hw/pci-hotplug.c | 24 ++++-------------------- sysemu.h | 6 +++++- 3 files changed, 56 insertions(+), 21 deletions(-) diff --git a/hw/device-hotplug.c b/hw/device-hotplug.c index 8b2ed7a..2bdc615 100644 --- a/hw/device-hotplug.c +++ b/hw/device-hotplug.c @@ -26,6 +26,9 @@ #include "boards.h" #include "net.h" #include "blockdev.h" +#include "qemu-config.h" +#include "sysemu.h" +#include "monitor.h" DriveInfo *add_init_drive(const char *optstr) { @@ -44,3 +47,47 @@ DriveInfo *add_init_drive(const char *optstr) return dinfo; } + +#if !defined(TARGET_I386) +int pci_drive_hot_add(Monitor *mon, const QDict *qdict, + DriveInfo *dinfo, int type) +{ + /* On non-x86 we don't do PCI hotplug */ + monitor_printf(mon, "Can't hot-add drive to type %d\n", type); + return -1; +} +#endif + +void drive_hot_add(Monitor *mon, const QDict *qdict) +{ + int type; + DriveInfo *dinfo = NULL; + const char *opts = qdict_get_str(qdict, "opts"); + + dinfo = add_init_drive(opts); + if (!dinfo) { + goto err; + } + if (dinfo->devaddr) { + monitor_printf(mon, "Parameter addr not supported\n"); + goto err; + } + type = dinfo->type; + + switch (type) { + case IF_NONE: + monitor_printf(mon, "OK\n"); + break; + default: + if (pci_drive_hot_add(mon, qdict, dinfo, type)) { + goto err; + } + } + return; + +err: + if (dinfo) { + drive_put_ref(dinfo); + } + return; +} diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 12f61fe..5c6307f 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -104,24 +104,13 @@ static int scsi_hot_add(Monitor *mon, DeviceState *adapter, return 0; } -void drive_hot_add(Monitor *mon, const QDict *qdict) +int pci_drive_hot_add(Monitor *mon, const QDict *qdict, + DriveInfo *dinfo, int type) { int dom, pci_bus; unsigned slot; - int type; PCIDevice *dev; - DriveInfo *dinfo = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); - const char *opts = qdict_get_str(qdict, "opts"); - - dinfo = add_init_drive(opts); - if (!dinfo) - goto err; - if (dinfo->devaddr) { - monitor_printf(mon, "Parameter addr not supported\n"); - goto err; - } - type = dinfo->type; switch (type) { case IF_SCSI: @@ -138,19 +127,14 @@ void drive_hot_add(Monitor *mon, const QDict *qdict) goto err; } break; - case IF_NONE: - monitor_printf(mon, "OK\n"); - break; default: monitor_printf(mon, "Can't hot-add drive to type %d\n", type); goto err; } - return; + return 0; err: - if (dinfo) - drive_put_ref(dinfo); - return; + return -1; } static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, diff --git a/sysemu.h b/sysemu.h index 3806901..ddef2bb 100644 --- a/sysemu.h +++ b/sysemu.h @@ -143,9 +143,13 @@ extern unsigned int nb_prom_envs; /* pci-hotplug */ void pci_device_hot_add(Monitor *mon, const QDict *qdict); -void drive_hot_add(Monitor *mon, const QDict *qdict); +int pci_drive_hot_add(Monitor *mon, const QDict *qdict, + DriveInfo *dinfo, int type); void do_pci_device_hot_remove(Monitor *mon, const QDict *qdict); +/* generic hotplug */ +void drive_hot_add(Monitor *mon, const QDict *qdict); + /* pcie aer error injection */ void pcie_aer_inject_error_print(Monitor *mon, const QObject *data); int do_pcie_aer_inject_error(Monitor *mon,