Skip to contentSkip to conversation

snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid concurrency problem

PATCH Applied Zhang Haoyu 3 participants 3 messages Oct 21, 2014 – Oct 28, 2014 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid concurrency problem

If there are still pending i/o while deleting snapshot,
because deleting snapshot is done in non-coroutine context, and the pending i/o read/write (bdrv_co_do_rw) is done in coroutine context, so it's possible to cause concurrency problem between above two operations. Add bdrv_drain_all() to bdrv_snapshot_delete() to avoid this problem.

---
 block/snapshot.c | 4 ++++
 1 file changed, 4 insertions(+)
block/snapshot.c +4 -0
index 85c52ff..ebc386a 100644
@@ -236,6 +236,10 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
         error_setg(errp, "snapshot_id and name are both NULL");
         return -EINVAL;
     }
+
+    /* drain all pending i/o before deleting snapshot */
+    bdrv_drain_all();
+
     if (drv->bdrv_snapshot_delete) {
         return drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp);
     }
Signature · 1 line
1.7.12.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 17 lines · Zhang Haoyu

If there are still pending i/o while deleting snapshot,
because deleting snapshot is done in non-coroutine context, and the pending i/o read/write (bdrv_co_do_rw) is done in coroutine context, so it's possible to cause concurrency problem between above two operations. Add bdrv_drain_all() to bdrv_snapshot_delete() to avoid this problem.

---
  block/snapshot.c | 4 ++++
  1 file changed, 4 insertions(+)
block/snapshot.c +0 -0
index 85c52ff..ebc386a 100644

block/snapshot.c int bdrv_snapshot_delete(BlockDriverState *bs, · line 245

Quoted 10 lines
block/snapshot.c +4 -0
@@ -236,6 +236,10 @@ int bdrv_snapshot_delete(BlockDriverState *bs,
          error_setg(errp, "snapshot_id and name are both NULL");
          return -EINVAL;
      }
+
+    /* drain all pending i/o before deleting snapshot */
+    bdrv_drain_all();
+
      if (drv->bdrv_snapshot_delete) {
          return drv->bdrv_snapshot_delete(bs, snapshot_id, name, errp);
      }
#2 lore raw
In reply to Zhang Haoyu
Quoted 10 lines · Zhang Haoyu

If there are still pending i/o while deleting snapshot,
because deleting snapshot is done in non-coroutine context, and the pending i/o read/write (bdrv_co_do_rw) is done in coroutine context, so it's possible to cause concurrency problem between above two operations. Add bdrv_drain_all() to bdrv_snapshot_delete() to avoid this problem.

---
 block/snapshot.c | 4 ++++
 1 file changed, 4 insertions(+)

Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block

Stefan