From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MyLGB-0008Ev-F1 for qemu-devel@nongnu.org; Thu, 15 Oct 2009 04:00:31 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MyLG5-0008CH-TA for qemu-devel@nongnu.org; Thu, 15 Oct 2009 04:00:30 -0400 Received: from [199.232.76.173] (port=58432 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MyLG5-0008CE-Dc for qemu-devel@nongnu.org; Thu, 15 Oct 2009 04:00:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48973) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MyLG4-0005wJ-QY for qemu-devel@nongnu.org; Thu, 15 Oct 2009 04:00:25 -0400 Message-ID: <4AD6D681.3050401@redhat.com> Date: Thu, 15 Oct 2009 10:00:01 +0200 From: Gerd Hoffmann MIME-Version: 1.0 References: <1255539554-7956-1-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1255539554-7956-1-git-send-email-aliguori@us.ibm.com> Content-Type: multipart/mixed; boundary="------------010408040307060600020702" Subject: [Qemu-devel] Re: [PATCH] [STABLE] Fix virtio-blk hot add after remove List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Anthony Liguori Cc: qemu-devel@nongnu.org, Dustin Kirkland This is a multi-part message in MIME format. --------------010408040307060600020702 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit On 10/14/09 18:59, Anthony Liguori wrote: > qdev_init_bdrv() expects that each drive added is the next logical unit for > the given interface type. However, when dealing with hotplug, there may > be holes in the units. drive_init reclaims holes in units but qdev_init_bdrv() > is not smart enough to do this. Oh, right. > Suggestions for a less ugly solution are appreciated. See attached patch. Isn't exactly pretty. But at least it is less invasive and IMHO the logic is easier to understand as well. Warning: *untested*. cheers, Gerd --------------010408040307060600020702 Content-Type: text/plain; name="0001-fix-virtio-blk-hotplugging.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-fix-virtio-blk-hotplugging.patch" >>From 572ff4912ed021c7b4bb2076d8d72e497f0c434b Mon Sep 17 00:00:00 2001 From: Gerd Hoffmann Date: Thu, 15 Oct 2009 09:55:11 +0200 Subject: [PATCH] fix virtio blk hotplugging. Signed-off-by: Gerd Hoffmann --- hw/pci-hotplug.c | 2 ++ hw/qdev.c | 8 ++++++++ sysemu.h | 1 + 3 files changed, 11 insertions(+), 0 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index 8bedea2..658564e 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -147,7 +147,9 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, drives_table[drive_idx].unit); break; case IF_VIRTIO: + drives_table[drive_idx].qdev_pick_this_one_please = 1; dev = pci_create("virtio-blk-pci", devaddr); + drives_table[drive_idx].qdev_pick_this_one_please = 0; break; default: dev = NULL; diff --git a/hw/qdev.c b/hw/qdev.c index faecc76..9dd896b 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -191,6 +191,14 @@ BlockDriverState *qdev_init_bdrv(DeviceState *dev, BlockInterfaceType type) int unit = next_block_unit[type]++; int index; + for (index = 0; index < MAX_DRIVES; index++) { + if (!drives_table[index].used) + continue; + if (!drives_table[index].qdev_pick_this_one_please) + continue; + return drives_table[index].bdrv; + } + index = drive_get_index(type, 0, unit); if (index == -1) { return NULL; diff --git a/sysemu.h b/sysemu.h index ce25109..6dc2b4f 100644 --- a/sysemu.h +++ b/sysemu.h @@ -173,6 +173,7 @@ typedef struct DriveInfo { int bus; int unit; int used; + int qdev_pick_this_one_please; /* band-aid for virtio-blk hotplug */ int drive_opt_idx; BlockInterfaceErrorAction onerror; char serial[BLOCK_SERIAL_STRLEN + 1]; -- 1.6.2.5 --------------010408040307060600020702--