Skip to content

Commit

Permalink
snapshot: add bdrv_drain_all() to bdrv_snapshot_delete() to avoid con…
Browse files Browse the repository at this point in the history
…currency 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.

Signed-off-by: Zhang Haoyu <[email protected]>
Reviewed-by: Paolo Bonzini <[email protected]>
Message-id: [email protected]
Signed-off-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
Zhang Haoyu authored and stefanhaRH committed Nov 3, 2014
1 parent 573742a commit 3432a19
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions block/snapshot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 3432a19

Please sign in to comment.