From patchwork Wed Oct 14 13:30:22 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 35963 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 43DD5B7B70 for ; Thu, 15 Oct 2009 00:32:31 +1100 (EST) Received: from localhost ([127.0.0.1]:42845 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My3xr-0000W6-R6 for incoming@patchwork.ozlabs.org; Wed, 14 Oct 2009 09:32:27 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1My3w2-00085e-6N for qemu-devel@nongnu.org; Wed, 14 Oct 2009 09:30:34 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1My3vx-00081k-HO for qemu-devel@nongnu.org; Wed, 14 Oct 2009 09:30:33 -0400 Received: from [199.232.76.173] (port=32889 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1My3vx-00081V-5F for qemu-devel@nongnu.org; Wed, 14 Oct 2009 09:30:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6430) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1My3vw-0000pv-IF for qemu-devel@nongnu.org; Wed, 14 Oct 2009 09:30:28 -0400 Received: from int-mx05.intmail.prod.int.phx2.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.18]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9EDUQKA008495 for ; Wed, 14 Oct 2009 09:30:26 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-6.ams2.redhat.com [10.36.5.6]) by int-mx05.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with SMTP id n9EDUO2U009778; Wed, 14 Oct 2009 09:30:25 -0400 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id 6F575700FC; Wed, 14 Oct 2009 15:30:23 +0200 (CEST) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Wed, 14 Oct 2009 15:30:22 +0200 Message-Id: <1255527022-18944-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.18 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH] hotplug: more fixes for scsi disk hotplug. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Changes: - create common scsi_hot_add function for adding a scsi disk to a adapter. - Add sanity checks. You can't drive_add disks to the VGA any more. - Ignore the unit value calculated by drive_init, add a comment explaining why. Review the patch to find the details ;) Signed-off-by: Gerd Hoffmann --- hw/pci-hotplug.c | 44 ++++++++++++++++++++++++++++++++++---------- 1 files changed, 34 insertions(+), 10 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 2a192d3..146238f 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -61,6 +61,33 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, return pci_nic_init(&nd_table[ret], "rtl8139", devaddr); } +static int scsi_hot_add(DeviceState *adapter, DriveInfo *dinfo, int printinfo) +{ + SCSIBus *scsibus; + SCSIDevice *scsidev; + + scsibus = DO_UPCAST(SCSIBus, qbus, QLIST_FIRST(&adapter->child_bus)); + if (!scsibus || strcmp(scsibus->qbus.info->name, "SCSI") != 0) { + qemu_error("Device is not a SCSI adapter\n"); + return -1; + } + + /* + * drive_init() tries to find a default for dinfo->unit. Doesn't + * work at all for hotplug though as we assign the device to a + * specific bus instead of the first bus with spare scsi ids. + * + * Ditch the calculated value and reload from option string (if + * specified). + */ + dinfo->unit = qemu_opt_get_number(dinfo->opts, "unit", -1); + scsidev = scsi_bus_legacy_add_drive(scsibus, dinfo, dinfo->unit); + + if (printinfo) + qemu_error("OK bus %d, unit %d\n", scsibus->busnr, scsidev->id); + return 0; +} + void drive_hot_add(Monitor *mon, const QDict *qdict) { int dom, pci_bus; @@ -70,7 +97,6 @@ void drive_hot_add(Monitor *mon, const QDict *qdict) DriveInfo *dinfo = NULL; const char *pci_addr = qdict_get_str(qdict, "pci_addr"); const char *opts = qdict_get_str(qdict, "opts"); - BusState *scsibus; dinfo = add_init_drive(opts); if (!dinfo) @@ -92,12 +118,9 @@ void drive_hot_add(Monitor *mon, const QDict *qdict) monitor_printf(mon, "no pci device with address %s\n", pci_addr); goto err; } - scsibus = QLIST_FIRST(&dev->qdev.child_bus); - scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus), - dinfo, dinfo->unit); - monitor_printf(mon, "OK bus %d, unit %d\n", - dinfo->bus, - dinfo->unit); + if (scsi_hot_add(&dev->qdev, dinfo, 1) != 0) { + goto err; + } break; case IF_NONE: monitor_printf(mon, "OK\n"); @@ -167,9 +190,10 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, if (qdev_init(&dev->qdev) < 0) dev = NULL; if (dev) { - BusState *scsibus = QLIST_FIRST(&dev->qdev.child_bus); - scsi_bus_legacy_add_drive(DO_UPCAST(SCSIBus, qbus, scsibus), - dinfo, dinfo->unit); + if (scsi_hot_add(&dev->qdev, dinfo, 0) != 0) { + qdev_unplug(&dev->qdev); + dev = NULL; + } } break; case IF_VIRTIO: