@@ -1198,7 +1198,7 @@ static bool tracked_request_overlaps(BdrvTrackedRequest *req,
}
static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs,
- int64_t sector_num, int nb_sectors)
+ int64_t sector_num, int nb_sectors, bool writes_only)
{
BdrvTrackedRequest *req;
int64_t cluster_sector_num;
@@ -1214,9 +1214,16 @@ static void coroutine_fn wait_for_overlapping_requests(BlockDriverState *bs,
round_to_clusters(bs, sector_num, nb_sectors,
&cluster_sector_num, &cluster_nb_sectors);
+ if (writes_only && !(bs->open_flags & BDRV_O_RDWR)) {
+ return;
+ }
+
do {
retry = false;
QLIST_FOREACH(req, &bs->tracked_requests, list) {
+ if (writes_only && !req->is_write) {
+ continue;
+ }
if (tracked_request_overlaps(req, cluster_sector_num,
cluster_nb_sectors)) {
/* Hitting this means there was a reentrant request, for
@@ -1591,7 +1598,7 @@ static int coroutine_fn bdrv_co_do_readv(BlockDriverState *bs,
}
if (bs->copy_on_read_in_flight) {
- wait_for_overlapping_requests(bs, sector_num, nb_sectors);
+ wait_for_overlapping_requests(bs, sector_num, nb_sectors, false);
}
tracked_request_begin(&req, bs, sector_num, nb_sectors, false);
@@ -1665,7 +1672,7 @@ static int coroutine_fn bdrv_co_do_writev(BlockDriverState *bs,
}
if (bs->copy_on_read_in_flight) {
- wait_for_overlapping_requests(bs, sector_num, nb_sectors);
+ wait_for_overlapping_requests(bs, sector_num, nb_sectors, false);
}
tracked_request_begin(&req, bs, sector_num, nb_sectors, true);
To implement mismatching block size, we will reuse the request tracking mechanism that is used for copy-on-read. However, waiting for overlapping reads is not needed to protect against "torn reads", so add a flag to wait_for_overlapping_requests. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- block.c | 13 ++++++++++--- 1 files changed, 10 insertions(+), 3 deletions(-)