Skip to contentSkip to conversation

block: support drive_del with dataplane

PATCH In review Stefan Hajnoczi 2 participants 4 messages Aug 18, 2014 – Aug 20, 2014

lore
Share & tools
lore
#0 lore raw

cover block: support drive_del with dataplane

This series makes hot unplug work with virtio-blk dataplane devices. It should also work with Fam's virtio-scsi dataplane patches.

Up until now dataplane installed an op blocker that prevented drive_del. Thanks to the op blocker and AioContext acquire/release infrastructure we can now make drive_del safe.

Stefan Hajnoczi (2):
block: acquire AioContext in do_drive_del()
virtio-blk: allow drive_del with dataplane

 blockdev.c                      | 7 +++++++
 hw/block/dataplane/virtio-blk.c | 1 +
 2 files changed, 8 insertions(+)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/2 block: acquire AioContext in do_drive_del()

Make drive_del safe for dataplane where another thread may be running the BlockDriverState's AioContext.

Note the assumption that AioContext's lifetime exceeds DriveInfo and BlockDriverState. We release AioContext after DriveInfo and BlockDriverState are potentially freed.

This is clearly safe with the global AioContext but also with -object iothread and implicit iothreads created by -device virtio-blk-pci,x-data-plane=on (their lifetime is tied to DeviceState, not BlockDriverState).

---
 blockdev.c | 7 +++++++
 1 file changed, 7 insertions(+)
blockdev.c +7 -0
index 48bd9a3..5cabb99 100644
@@ -1757,6 +1757,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
 {
     const char *id = qdict_get_str(qdict, "id");
     BlockDriverState *bs;
+    AioContext *aio_context;
     Error *local_err = NULL;
 
     bs = bdrv_find(id);
@@ -1764,9 +1765,14 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         error_report("Device '%s' not found", id);
         return -1;
     }
+
+    aio_context = bdrv_get_aio_context(bs);
+    aio_context_acquire(aio_context);
+
     if (bdrv_op_is_blocked(bs, BLOCK_OP_TYPE_DRIVE_DEL, &local_err)) {
         error_report("%s", error_get_pretty(local_err));
         error_free(local_err);
+        aio_context_release(aio_context);
         return -1;
     }
 
@@ -1790,6 +1796,7 @@ int do_drive_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
         drive_del(drive_get_by_blockdev(bs));
     }
 
+    aio_context_release(aio_context);
     return 0;
 }
 
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/2 virtio-blk: allow drive_del with dataplane

In reply to Stefan Hajnoczi

Now that drive_del acquires the AioContext we can safely allow deleting the drive. As with non-dataplane mode, all I/Os submitted by the guest after drive_del will return EIO.

This patch makes hot unplug work with virtio-blk dataplane. Previously drive_del reported an error because the device was busy.

---
 hw/block/dataplane/virtio-blk.c | 1 +
 1 file changed, 1 insertion(+)
hw/block/dataplane/virtio-blk.c +1 -0
index d6ba65c..907d5c7 100644
@@ -192,6 +192,7 @@ void virtio_blk_data_plane_create(VirtIODevice *vdev, VirtIOBlkConf *blk,
 
     error_setg(&s->blocker, "block device is in use by data plane");
     bdrv_op_block_all(blk->conf.bs, s->blocker);
+    bdrv_op_unblock(blk->conf.bs, BLOCK_OP_TYPE_DRIVE_DEL, s->blocker);
 
     *dataplane = s;
 }
Signature · 1 line
1.9.3
Reviewed-by on the v1 series
#3 lore raw
In reply to Stefan Hajnoczi
Quoted 7 lines · Stefan Hajnoczi

This series makes hot unplug work with virtio-blk dataplane devices. It should also work with Fam's virtio-scsi dataplane patches.

Up until now dataplane installed an op blocker that prevented drive_del. Thanks to the op blocker and AioContext acquire/release infrastructure we can now make drive_del safe.

Quoted 7 lines

Stefan Hajnoczi (2):
block: acquire AioContext in do_drive_del()
virtio-blk: allow drive_del with dataplane

 blockdev.c                      | 7 +++++++
 hw/block/dataplane/virtio-blk.c | 1 +
 2 files changed, 8 insertions(+)