[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 30/34] block/io: bdrv_check_byte_request(): drop bdrv_is_inserted(
From: |
Kevin Wolf |
Subject: |
[PULL 30/34] block/io: bdrv_check_byte_request(): drop bdrv_is_inserted() |
Date: |
Fri, 11 Dec 2020 18:08:08 +0100 |
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Move bdrv_is_inserted() calls into callers.
We are going to make bdrv_check_byte_request() a clean thing.
bdrv_is_inserted() is not about checking the request, it's about
checking the bs. So, it should be separate.
With this patch we probably change error path for some failure
scenarios. But depending on the fact that querying too big request on
empty cdrom (or corrupted qcow2 node with no drv) will result in EIO
and not ENOMEDIUM would be very strange. More over, we are going to
move to 64bit requests, so larger requests will be allowed anyway.
More over, keeping in mind that cdrom is the only driver that has
.bdrv_is_inserted() handler it's strange that we should care so much
about it in generic block layer, intuitively we should just do read and
write, and cdrom driver should return correct errors if it is not
inserted. But it's a work for another series.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
Message-Id: <20201203222713.13507-4-vsementsov@virtuozzo.com>
Reviewed-by: Alberto Garcia <berto@igalia.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/io.c | 25 ++++++++++++-------------
1 file changed, 12 insertions(+), 13 deletions(-)
diff --git a/block/io.c b/block/io.c
index 3e91074c9f..ef75a5abb4 100644
--- a/block/io.c
+++ b/block/io.c
@@ -884,17 +884,12 @@ static bool coroutine_fn
bdrv_wait_serialising_requests(BdrvTrackedRequest *self
return waited;
}
-static int bdrv_check_byte_request(BlockDriverState *bs, int64_t offset,
- size_t size)
+static int bdrv_check_byte_request(int64_t offset, size_t size)
{
if (size > BDRV_REQUEST_MAX_BYTES) {
return -EIO;
}
- if (!bdrv_is_inserted(bs)) {
- return -ENOMEDIUM;
- }
-
if (offset < 0) {
return -EIO;
}
@@ -1642,7 +1637,11 @@ int coroutine_fn bdrv_co_preadv_part(BdrvChild *child,
trace_bdrv_co_preadv(bs, offset, bytes, flags);
- ret = bdrv_check_byte_request(bs, offset, bytes);
+ if (!bdrv_is_inserted(bs)) {
+ return -ENOMEDIUM;
+ }
+
+ ret = bdrv_check_byte_request(offset, bytes);
if (ret < 0) {
return ret;
}
@@ -2054,11 +2053,11 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child,
trace_bdrv_co_pwritev(child->bs, offset, bytes, flags);
- if (!bs->drv) {
+ if (!bdrv_is_inserted(bs)) {
return -ENOMEDIUM;
}
- ret = bdrv_check_byte_request(bs, offset, bytes);
+ ret = bdrv_check_byte_request(offset, bytes);
if (ret < 0) {
return ret;
}
@@ -3045,10 +3044,10 @@ static int coroutine_fn bdrv_co_copy_range_internal(
assert(!(read_flags & BDRV_REQ_NO_FALLBACK));
assert(!(write_flags & BDRV_REQ_NO_FALLBACK));
- if (!dst || !dst->bs) {
+ if (!dst || !dst->bs || !bdrv_is_inserted(dst->bs)) {
return -ENOMEDIUM;
}
- ret = bdrv_check_byte_request(dst->bs, dst_offset, bytes);
+ ret = bdrv_check_byte_request(dst_offset, bytes);
if (ret) {
return ret;
}
@@ -3056,10 +3055,10 @@ static int coroutine_fn bdrv_co_copy_range_internal(
return bdrv_co_pwrite_zeroes(dst, dst_offset, bytes, write_flags);
}
- if (!src || !src->bs) {
+ if (!src || !src->bs || !bdrv_is_inserted(src->bs)) {
return -ENOMEDIUM;
}
- ret = bdrv_check_byte_request(src->bs, src_offset, bytes);
+ ret = bdrv_check_byte_request(src_offset, bytes);
if (ret) {
return ret;
}
--
2.29.2
- [PULL 27/34] can-host: Fix crash when 'canbus' property is not set, (continued)
- [PULL 27/34] can-host: Fix crash when 'canbus' property is not set, Kevin Wolf, 2020/12/11
- [PULL 22/34] iotests: Allow testing FUSE exports, Kevin Wolf, 2020/12/11
- [PULL 21/34] iotests: Give access to the qemu-storage-daemon, Kevin Wolf, 2020/12/11
- [PULL 23/34] iotests: Enable fuse for many tests, Kevin Wolf, 2020/12/11
- [PULL 28/34] block/file-posix: fix workaround in raw_do_pwrite_zeroes(), Kevin Wolf, 2020/12/11
- [PULL 29/34] block/io: bdrv_refresh_limits(): use ERRP_GUARD, Kevin Wolf, 2020/12/11
- [PULL 31/34] block: introduce BDRV_MAX_LENGTH, Kevin Wolf, 2020/12/11
- [PULL 34/34] block: Fix deadlock in bdrv_co_yield_to_drain(), Kevin Wolf, 2020/12/11
- [PULL 32/34] block: Simplify qmp_block_resize() error paths, Kevin Wolf, 2020/12/11
- [PULL 33/34] block: Fix locking in qmp_block_resize(), Kevin Wolf, 2020/12/11
- [PULL 30/34] block/io: bdrv_check_byte_request(): drop bdrv_is_inserted(),
Kevin Wolf <=
- Re: [PULL 00/34] Block layer patches, Peter Maydell, 2020/12/12