diff mbox

[1/2] block/block-backend.c: add blk_check_byte_request call to blk_pread/blk_pwrite

Message ID 20170920114310.13080-2-el13635@mail.ntua.gr (mailing list archive)
State New, archived
Headers show

Commit Message

Manos Pitsidianakis Sept. 20, 2017, 11:43 a.m. UTC
blk_check_byte_request() is called from the blk_co_pwritev/blk_co_preadv to
check if the request offset and request bytes parameters are valid for the
given Blockbackend. Let's do that in blk_pread/blk_pwrite too.

Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
---
 block/block-backend.c | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

Comments

Kevin Wolf Sept. 20, 2017, 12:24 p.m. UTC | #1
Am 20.09.2017 um 13:43 hat Manos Pitsidianakis geschrieben:
> blk_check_byte_request() is called from the blk_co_pwritev/blk_co_preadv to
> check if the request offset and request bytes parameters are valid for the
> given Blockbackend. Let's do that in blk_pread/blk_pwrite too.
> 
> Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr>

I don't think this is necessary, blk_pread/pwrite() are only wrappers
around blk_co_preadv/pwritev(), so we're already checking the
parameters.

Kevin
Manos Pitsidianakis Sept. 20, 2017, 2:35 p.m. UTC | #2
On Wed, Sep 20, 2017 at 02:24:21PM +0200, Kevin Wolf wrote:
>Am 20.09.2017 um 13:43 hat Manos Pitsidianakis geschrieben:
>> blk_check_byte_request() is called from the blk_co_pwritev/blk_co_preadv to
>> check if the request offset and request bytes parameters are valid for the
>> given Blockbackend. Let's do that in blk_pread/blk_pwrite too.
>>
>> Signed-off-by: Manos Pitsidianakis <el13635@mail.ntua.gr>
>
>I don't think this is necessary, blk_pread/pwrite() are only wrappers
>around blk_co_preadv/pwritev(), so we're already checking the
>parameters.
>
>Kevin


Alright, this can be dropped then. Thanks!
diff mbox

Patch

diff --git a/block/block-backend.c b/block/block-backend.c
index 45d9101be3..110a52d5b1 100644
--- a/block/block-backend.c
+++ b/block/block-backend.c
@@ -1288,22 +1288,23 @@  BlockAIOCB *blk_aio_pwrite_zeroes(BlockBackend *blk, int64_t offset,
 
 int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int count)
 {
-    int ret = blk_prw(blk, offset, buf, count, blk_read_entry, 0);
+    int ret = blk_check_byte_request(blk, offset, count);
     if (ret < 0) {
         return ret;
     }
-    return count;
+    ret = blk_prw(blk, offset, buf, count, blk_read_entry, 0);
+    return ret < 0 ? ret : count;
 }
 
 int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int count,
                BdrvRequestFlags flags)
 {
-    int ret = blk_prw(blk, offset, (void *) buf, count, blk_write_entry,
-                      flags);
+    int ret = blk_check_byte_request(blk, offset, count);
     if (ret < 0) {
         return ret;
     }
-    return count;
+    ret = blk_prw(blk, offset, (void *) buf, count, blk_write_entry, flags);
+    return ret < 0 ? ret : count;
 }
 
 int64_t blk_getlength(BlockBackend *blk)