All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: Anthony Liguori <aliguori@us.ibm.com>
Cc: qemu-devel@nongnu.org, Dustin Kirkland <kirkland@canonical.com>
Subject: [Qemu-devel] Re: [PATCH] [STABLE] Fix virtio-blk hot add after remove
Date: Thu, 15 Oct 2009 10:00:01 +0200	[thread overview]
Message-ID: <4AD6D681.3050401@redhat.com> (raw)
In-Reply-To: <1255539554-7956-1-git-send-email-aliguori@us.ibm.com>

[-- Attachment #1: Type: text/plain, Size: 550 bytes --]

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

[-- Attachment #2: 0001-fix-virtio-blk-hotplugging.patch --]
[-- Type: text/plain, Size: 1891 bytes --]

>From 572ff4912ed021c7b4bb2076d8d72e497f0c434b Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Thu, 15 Oct 2009 09:55:11 +0200
Subject: [PATCH] fix virtio blk hotplugging.


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 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


      parent reply	other threads:[~2009-10-15  8:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-14 16:59 [Qemu-devel] [PATCH] [STABLE] Fix virtio-blk hot add after remove Anthony Liguori
2009-10-14 18:22 ` [Qemu-devel] " Dustin Kirkland
2009-10-15  8:00 ` Gerd Hoffmann [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4AD6D681.3050401@redhat.com \
    --to=kraxel@redhat.com \
    --cc=aliguori@us.ibm.com \
    --cc=kirkland@canonical.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.