]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid concurrency problem
authorZhang Haoyu <zhanghy@sangfor.com>
Tue, 21 Oct 2014 08:38:01 +0000 (16:38 +0800)
committerStefan Hajnoczi <stefanha@redhat.com>
Mon, 3 Nov 2014 09:48:42 +0000 (09:48 +0000)
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.

Signed-off-by: Zhang Haoyu <zhanghy@sangfor.com>
Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
Message-id: 201410211637596311287@sangfor.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/snapshot.c

index 85c52ff4559e9158e36380195152e5eb3a03bf2e..698e1a1d5881cd92ba6c0aae832db687e20d7fd3 100644 (file)
@@ -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);
     }