From patchwork Thu Oct 15 08:00:01 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 36082 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 02345B7063 for ; Thu, 15 Oct 2009 19:01:08 +1100 (EST) Received: from localhost ([127.0.0.1]:53855 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MyLGj-0008Fy-0T for incoming@patchwork.ozlabs.org; Thu, 15 Oct 2009 04:01:05 -0400 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 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9F808hl017340; Thu, 15 Oct 2009 04:00:08 -0400 Received: from zweiblum.home.kraxel.org (vpn1-5-34.ams2.redhat.com [10.36.5.34]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9F802lT008439; Thu, 15 Oct 2009 04:00:06 -0400 Message-ID: <4AD6D681.3050401@redhat.com> Date: Thu, 15 Oct 2009 10:00:01 +0200 From: Gerd Hoffmann User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4pre) Gecko/20090922 Fedora/3.0-2.7.b4.fc11 Lightning/1.0pre Thunderbird/3.0b4 MIME-Version: 1.0 To: Anthony Liguori References: <1255539554-7956-1-git-send-email-aliguori@us.ibm.com> In-Reply-To: <1255539554-7956-1-git-send-email-aliguori@us.ibm.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: qemu-devel@nongnu.org, Dustin Kirkland Subject: [Qemu-devel] Re: [PATCH] [STABLE] Fix virtio-blk hot add after remove 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 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 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];