From 53fb7844f03241a0e6de2c342c9e1b89df12da4d Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:35 +0100 Subject: block: Add a 'flags' param to bdrv_{pread,pwrite,pwrite_sync}() For consistency with other I/O functions, and in preparation to implement them using generated_co_wrapper. Callers were updated using this Coccinelle script: @@ expression child, offset, buf, bytes; @@ - bdrv_pread(child, offset, buf, bytes) + bdrv_pread(child, offset, buf, bytes, 0) @@ expression child, offset, buf, bytes; @@ - bdrv_pwrite(child, offset, buf, bytes) + bdrv_pwrite(child, offset, buf, bytes, 0) @@ expression child, offset, buf, bytes; @@ - bdrv_pwrite_sync(child, offset, buf, bytes) + bdrv_pwrite_sync(child, offset, buf, bytes, 0) Resulting overly-long lines were then fixed by hand. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20220609152744.3891847-2-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/block/block-io.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/block/block-io.h b/include/block/block-io.h index 053a271..1a02d23 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -42,11 +42,12 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes, BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); -int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes); +int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, + BdrvRequestFlags flags); int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, - int64_t bytes); + int64_t bytes, BdrvRequestFlags flags); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, - const void *buf, int64_t bytes); + const void *buf, int64_t bytes, BdrvRequestFlags flags); /* * Efficiently zero a region of the disk image. Note that this is a regular * I/O request like read or write and should have a reasonable size. This -- cgit v1.1 From 32cc71def9e3885f9527af713e6d8dc7521ddc08 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:36 +0100 Subject: block: Change bdrv_{pread,pwrite,pwrite_sync}() param order Swap 'buf' and 'bytes' around for consistency with bdrv_co_{pread,pwrite}(), and in preparation to implement these functions using generated_co_wrapper. Callers were updated using this Coccinelle script: @@ expression child, offset, buf, bytes, flags; @@ - bdrv_pread(child, offset, buf, bytes, flags) + bdrv_pread(child, offset, bytes, buf, flags) @@ expression child, offset, buf, bytes, flags; @@ - bdrv_pwrite(child, offset, buf, bytes, flags) + bdrv_pwrite(child, offset, bytes, buf, flags) @@ expression child, offset, buf, bytes, flags; @@ - bdrv_pwrite_sync(child, offset, buf, bytes, flags) + bdrv_pwrite_sync(child, offset, bytes, buf, flags) Resulting overly-long lines were then fixed by hand. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Reviewed-by: Vladimir Sementsov-Ogievskiy Message-Id: <20220609152744.3891847-3-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/block/block-io.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/block/block-io.h b/include/block/block-io.h index 1a02d23..ecce56c 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -42,12 +42,12 @@ int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, int64_t bytes, BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); -int bdrv_pread(BdrvChild *child, int64_t offset, void *buf, int64_t bytes, +int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags); -int bdrv_pwrite(BdrvChild *child, int64_t offset, const void *buf, - int64_t bytes, BdrvRequestFlags flags); -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, - const void *buf, int64_t bytes, BdrvRequestFlags flags); +int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, + const void *buf, BdrvRequestFlags flags); +int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, + const void *buf, BdrvRequestFlags flags); /* * Efficiently zero a region of the disk image. Note that this is a regular * I/O request like read or write and should have a reasonable size. This -- cgit v1.1 From 757dda54b43867936012970a1b457f3d16e7398d Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:38 +0100 Subject: crypto: Make block callbacks return 0 on success They currently return the value of their headerlen/buflen parameter on success. Returning 0 instead makes it clear that short reads/writes are not possible. Signed-off-by: Alberto Faria Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Message-Id: <20220609152744.3891847-5-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/crypto/block.h | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'include') diff --git a/include/crypto/block.h b/include/crypto/block.h index 7a65e8e..4f63a37 100644 --- a/include/crypto/block.h +++ b/include/crypto/block.h @@ -29,24 +29,24 @@ typedef struct QCryptoBlock QCryptoBlock; /* See also QCryptoBlockFormat, QCryptoBlockCreateOptions * and QCryptoBlockOpenOptions in qapi/crypto.json */ -typedef ssize_t (*QCryptoBlockReadFunc)(QCryptoBlock *block, - size_t offset, - uint8_t *buf, - size_t buflen, - void *opaque, - Error **errp); +typedef int (*QCryptoBlockReadFunc)(QCryptoBlock *block, + size_t offset, + uint8_t *buf, + size_t buflen, + void *opaque, + Error **errp); -typedef ssize_t (*QCryptoBlockInitFunc)(QCryptoBlock *block, - size_t headerlen, - void *opaque, - Error **errp); +typedef int (*QCryptoBlockInitFunc)(QCryptoBlock *block, + size_t headerlen, + void *opaque, + Error **errp); -typedef ssize_t (*QCryptoBlockWriteFunc)(QCryptoBlock *block, - size_t offset, - const uint8_t *buf, - size_t buflen, - void *opaque, - Error **errp); +typedef int (*QCryptoBlockWriteFunc)(QCryptoBlock *block, + size_t offset, + const uint8_t *buf, + size_t buflen, + void *opaque, + Error **errp); /** * qcrypto_block_has_format: -- cgit v1.1 From ca71a64ee52eb0954541137026288970cc8213f7 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:39 +0100 Subject: block: Make bdrv_co_pwrite() take a const buffer It does not mutate the buffer. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Stefan Hajnoczi Message-Id: <20220609152744.3891847-6-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/block/block_int-io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index ded29e7..5474293 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -65,7 +65,7 @@ static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, } static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, - int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags) + int64_t offset, unsigned int bytes, const void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); -- cgit v1.1 From c1458c66b2a56a86d4e453b52dfd2c06040fe006 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:40 +0100 Subject: block: Make 'bytes' param of bdrv_co_{pread,pwrite,preadv,pwritev}() an int64_t For consistency with other I/O functions, and in preparation to implement bdrv_{pread,pwrite}() using generated_co_wrapper. unsigned int fits in int64_t, so all callers remain correct. bdrv_check_request32() is called further down the stack and causes -EIO to be returned if 'bytes' is negative or greater than BDRV_REQUEST_MAX_BYTES, which in turns never exceeds SIZE_MAX. Signed-off-by: Alberto Faria Message-Id: <20220609152744.3891847-7-afaria@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/block/block_int-io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/block/block_int-io.h b/include/block/block_int-io.h index 5474293..91cdd61 100644 --- a/include/block/block_int-io.h +++ b/include/block/block_int-io.h @@ -56,7 +56,7 @@ int coroutine_fn bdrv_co_pwritev_part(BdrvChild *child, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, - int64_t offset, unsigned int bytes, void *buf, BdrvRequestFlags flags) + int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); @@ -65,7 +65,7 @@ static inline int coroutine_fn bdrv_co_pread(BdrvChild *child, } static inline int coroutine_fn bdrv_co_pwrite(BdrvChild *child, - int64_t offset, unsigned int bytes, const void *buf, BdrvRequestFlags flags) + int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); IO_CODE(); -- cgit v1.1 From 1d39c7098bbfa6862cb96066c4f8f6735ea397c5 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:41 +0100 Subject: block: Implement bdrv_{pread,pwrite,pwrite_zeroes}() using generated_co_wrapper bdrv_{pread,pwrite}() now return -EIO instead of -EINVAL when 'bytes' is negative, making them consistent with bdrv_{preadv,pwritev}() and bdrv_co_{pread,pwrite,preadv,pwritev}(). bdrv_pwrite_zeroes() now also calls trace_bdrv_co_pwrite_zeroes() and clears the BDRV_REQ_MAY_UNMAP flag when appropriate, which it didn't previously. Signed-off-by: Alberto Faria Message-Id: <20220609152744.3891847-8-afaria@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/block/block-io.h | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/block/block-io.h b/include/block/block-io.h index ecce56c..260f669 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -39,13 +39,16 @@ * to catch when they are accidentally called by the wrong API. */ -int bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, - int64_t bytes, BdrvRequestFlags flags); +int generated_co_wrapper bdrv_pwrite_zeroes(BdrvChild *child, int64_t offset, + int64_t bytes, + BdrvRequestFlags flags); int bdrv_make_zero(BdrvChild *child, BdrvRequestFlags flags); -int bdrv_pread(BdrvChild *child, int64_t offset, int64_t bytes, void *buf, - BdrvRequestFlags flags); -int bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, - const void *buf, BdrvRequestFlags flags); +int generated_co_wrapper bdrv_pread(BdrvChild *child, int64_t offset, + int64_t bytes, void *buf, + BdrvRequestFlags flags); +int generated_co_wrapper bdrv_pwrite(BdrvChild *child, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); /* -- cgit v1.1 From e97190a4057d42dce0322a23e6347101225ee39e Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Thu, 9 Jun 2022 16:27:42 +0100 Subject: block: Add bdrv_co_pwrite_sync() Also convert bdrv_pwrite_sync() to being implemented using generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Eric Blake Reviewed-by: Stefan Hajnoczi Message-Id: <20220609152744.3891847-9-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/block/block-io.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/block/block-io.h b/include/block/block-io.h index 260f669..fd25ffa 100644 --- a/include/block/block-io.h +++ b/include/block/block-io.h @@ -49,8 +49,12 @@ int generated_co_wrapper bdrv_pread(BdrvChild *child, int64_t offset, int generated_co_wrapper bdrv_pwrite(BdrvChild *child, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); -int bdrv_pwrite_sync(BdrvChild *child, int64_t offset, int64_t bytes, - const void *buf, BdrvRequestFlags flags); +int generated_co_wrapper bdrv_pwrite_sync(BdrvChild *child, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); +int coroutine_fn bdrv_co_pwrite_sync(BdrvChild *child, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); /* * Efficiently zero a region of the disk image. Note that this is a regular * I/O request like read or write and should have a reasonable size. This -- cgit v1.1 From 3b35d4542c8537a9269f6372df531ced6c960084 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:10 +0100 Subject: block: Add a 'flags' param to blk_pread() For consistency with other I/O functions, and in preparation to implement it using generated_co_wrapper. Callers were updated using this Coccinelle script: @@ expression blk, offset, buf, bytes; @@ - blk_pread(blk, offset, buf, bytes) + blk_pread(blk, offset, buf, bytes, 0) It had no effect on hw/block/nand.c, presumably due to the #if, so that file was updated manually. Overly-long lines were then fixed by hand. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Greg Kurz Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-3-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index ccef514..5c5c108 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -101,7 +101,8 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, * the "I/O or GS" API. */ -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes); +int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, + BdrvRequestFlags flags); int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, BdrvRequestFlags flags); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, -- cgit v1.1 From a9262f551eba44d4d0f9e396d7124c059a93e204 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:11 +0100 Subject: block: Change blk_{pread,pwrite}() param order Swap 'buf' and 'bytes' around for consistency with blk_co_{pread,pwrite}(), and in preparation to implement these functions using generated_co_wrapper. Callers were updated using this Coccinelle script: @@ expression blk, offset, buf, bytes, flags; @@ - blk_pread(blk, offset, buf, bytes, flags) + blk_pread(blk, offset, bytes, buf, flags) @@ expression blk, offset, buf, bytes, flags; @@ - blk_pwrite(blk, offset, buf, bytes, flags) + blk_pwrite(blk, offset, bytes, buf, flags) It had no effect on hw/block/nand.c, presumably due to the #if, so that file was updated manually. Overly-long lines were then fixed by hand. Signed-off-by: Alberto Faria Reviewed-by: Eric Blake Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-4-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 5c5c108..e2e7ab9 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -101,9 +101,9 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, * the "I/O or GS" API. */ -int blk_pread(BlockBackend *blk, int64_t offset, void *buf, int bytes, +int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, BdrvRequestFlags flags); -int blk_pwrite(BlockBackend *blk, int64_t offset, const void *buf, int bytes, +int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf, BdrvRequestFlags flags); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, -- cgit v1.1 From 40fb4861b2d23c78a95a1d6f92591bc5f962c023 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:12 +0100 Subject: block: Make 'bytes' param of blk_{pread,pwrite}() an int64_t For consistency with other I/O functions, and in preparation to implement them using generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-5-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index e2e7ab9..8bf1296 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -101,10 +101,10 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, * the "I/O or GS" API. */ -int blk_pread(BlockBackend *blk, int64_t offset, int bytes, void *buf, +int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags); -int blk_pwrite(BlockBackend *blk, int64_t offset, int bytes, const void *buf, - BdrvRequestFlags flags); +int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, + const void *buf, BdrvRequestFlags flags); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -- cgit v1.1 From 7d252ba5caf094f03b032cad8bbef718a86712ae Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:13 +0100 Subject: block: Make blk_co_pwrite() take a const buffer It does not mutate the buffer. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-6-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 8bf1296..b048476 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -129,7 +129,7 @@ static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, } static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, - int64_t bytes, void *buf, + int64_t bytes, const void *buf, BdrvRequestFlags flags) { QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); -- cgit v1.1 From facbaad946db92900654a3df8678b1dc7d581524 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:14 +0100 Subject: block: Implement blk_{pread,pwrite}() using generated_co_wrapper We need to add include/sysemu/block-backend-io.h to the inputs of the block-gen.c target defined in block/meson.build. Signed-off-by: Alberto Faria Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-7-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index b048476..750089f 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -101,10 +101,12 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, * the "I/O or GS" API. */ -int blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, - BdrvRequestFlags flags); -int blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, - const void *buf, BdrvRequestFlags flags); +int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, + int64_t bytes, void *buf, + BdrvRequestFlags flags); +int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, + int64_t bytes, const void *buf, + BdrvRequestFlags flags); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -- cgit v1.1 From 7c8cd723c7e3c108a62938bd7741c2db95fcfb8a Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:15 +0100 Subject: block: Add blk_{preadv,pwritev}() Implement them using generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-8-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 750089f..cbf4422 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -107,6 +107,9 @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); +int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); @@ -114,6 +117,9 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); +int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -- cgit v1.1 From d1d3fc3d1d3bf4749400df18462f8fef4c4ca1fb Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:16 +0100 Subject: block: Add blk_[co_]preadv_part() Implement blk_preadv_part() using generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-9-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index cbf4422..877274a 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -107,6 +107,13 @@ int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, const void *buf, BdrvRequestFlags flags); +int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + size_t qiov_offset, + BdrvRequestFlags flags); +int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + size_t qiov_offset, BdrvRequestFlags flags); int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); -- cgit v1.1 From 09cca043bf68719f93f0ce1f1efafbec4ca72229 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:17 +0100 Subject: block: Export blk_pwritev_part() in block-backend-io.h Also convert it into a generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-10-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 877274a..93a1507 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -120,6 +120,10 @@ int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); +int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + size_t qiov_offset, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, -- cgit v1.1 From 0cadf2c8a37e15d3f3e1191024005e53dabb81f0 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:18 +0100 Subject: block: Change blk_pwrite_compressed() param order Swap 'buf' and 'bytes' around for consistency with other I/O functions. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-11-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 93a1507..695b793 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -167,8 +167,8 @@ int blk_flush(BlockBackend *blk); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); -int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, const void *buf, - int64_t bytes); +int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, + const void *buf); int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flags); -- cgit v1.1 From 2c9715fa28042ce84215dfd6b3bf35af90624e14 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:19 +0100 Subject: block: Add blk_co_pwrite_compressed() Also convert blk_pwrite_compressed() into a generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-12-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 695b793..8500a63 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -167,8 +167,11 @@ int blk_flush(BlockBackend *blk); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); -int blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, - const void *buf); +int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, + int64_t offset, int64_t bytes, + const void *buf); +int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, + int64_t bytes, const void *buf); int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flags); -- cgit v1.1 From 1c95dc914a0218e58dc8d857b736b966a721d96d Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:20 +0100 Subject: block: Implement blk_pwrite_zeroes() using generated_co_wrapper Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-13-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 8500a63..346ca47 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -173,8 +173,9 @@ int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, const void *buf); int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); -int blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, - int64_t bytes, BdrvRequestFlags flags); +int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, + int64_t bytes, + BdrvRequestFlags flags); int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flags); int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, -- cgit v1.1 From 50db162df068e1951aebf5c28d254ded883e9468 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:21 +0100 Subject: block: Implement blk_pdiscard() using generated_co_wrapper Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-14-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 346ca47..5a12a1f 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -159,6 +159,8 @@ static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, return blk_co_pwritev(blk, offset, bytes, &qiov, flags); } +int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, + int64_t bytes); int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); @@ -172,7 +174,6 @@ int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, const void *buf); int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, const void *buf); -int blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flags); -- cgit v1.1 From 25873f57c6c927999b5a613204acaa2e221d8e14 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:22 +0100 Subject: block: Implement blk_flush() using generated_co_wrapper Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-15-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 5a12a1f..6954c3b 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -164,8 +164,8 @@ int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); +int generated_co_wrapper blk_flush(BlockBackend *blk); int coroutine_fn blk_co_flush(BlockBackend *blk); -int blk_flush(BlockBackend *blk); int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); -- cgit v1.1 From df02da003daabe2666c13db3d539a7bce6f8b24b Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:23 +0100 Subject: block: Add blk_co_ioctl() Also convert blk_ioctl() into a generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-16-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 6954c3b..21f3a1b 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -167,7 +167,10 @@ int coroutine_fn blk_co_pdiscard(BlockBackend *blk, int64_t offset, int generated_co_wrapper blk_flush(BlockBackend *blk); int coroutine_fn blk_co_flush(BlockBackend *blk); -int blk_ioctl(BlockBackend *blk, unsigned long int req, void *buf); +int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req, + void *buf); +int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req, + void *buf); int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, int64_t offset, int64_t bytes, -- cgit v1.1 From 015ed2529a1a1876f2a78de90b768361c6e79345 Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:24 +0100 Subject: block: Add blk_co_truncate() Also convert blk_truncate() into a generated_co_wrapper. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Reviewed-by: Hanna Reitz Message-Id: <20220705161527.1054072-17-afaria@redhat.com> Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index 21f3a1b..a79b7d9 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -182,7 +182,11 @@ int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, BdrvRequestFlags flags); int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, int64_t bytes, BdrvRequestFlags flags); -int blk_truncate(BlockBackend *blk, int64_t offset, bool exact, - PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); +int generated_co_wrapper blk_truncate(BlockBackend *blk, int64_t offset, + bool exact, PreallocMode prealloc, + BdrvRequestFlags flags, Error **errp); +int coroutine_fn blk_co_truncate(BlockBackend *blk, int64_t offset, bool exact, + PreallocMode prealloc, BdrvRequestFlags flags, + Error **errp); #endif /* BLOCK_BACKEND_IO_H */ -- cgit v1.1 From 6f675c9306b732af8afafda91a0a3cd4e4ef97eb Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 5 Jul 2022 17:15:25 +0100 Subject: block: Reorganize some declarations in block-backend-io.h Keep generated_co_wrapper and coroutine_fn pairs together. This should make it clear that each I/O function has these two versions. Also move blk_co_{pread,pwrite}()'s implementations out of the header file for consistency. Signed-off-by: Alberto Faria Reviewed-by: Paolo Bonzini Message-Id: <20220705161527.1054072-18-afaria@redhat.com> Reviewed-by: Hanna Reitz Signed-off-by: Hanna Reitz --- include/sysemu/block-backend-io.h | 77 ++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 45 deletions(-) (limited to 'include') diff --git a/include/sysemu/block-backend-io.h b/include/sysemu/block-backend-io.h index a79b7d9..50f5aa2 100644 --- a/include/sysemu/block-backend-io.h +++ b/include/sysemu/block-backend-io.h @@ -104,9 +104,16 @@ int coroutine_fn blk_co_copy_range(BlockBackend *blk_in, int64_t off_in, int generated_co_wrapper blk_pread(BlockBackend *blk, int64_t offset, int64_t bytes, void *buf, BdrvRequestFlags flags); -int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, - int64_t bytes, const void *buf, +int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, int64_t bytes, + void *buf, BdrvRequestFlags flags); + +int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, BdrvRequestFlags flags); +int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); + int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, @@ -114,12 +121,20 @@ int generated_co_wrapper blk_preadv_part(BlockBackend *blk, int64_t offset, int coroutine_fn blk_co_preadv_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); -int generated_co_wrapper blk_preadv(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, + +int generated_co_wrapper blk_pwrite(BlockBackend *blk, int64_t offset, + int64_t bytes, const void *buf, BdrvRequestFlags flags); -int coroutine_fn blk_co_preadv(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); +int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, int64_t bytes, + const void *buf, BdrvRequestFlags flags); + +int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); +int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, + int64_t bytes, QEMUIOVector *qiov, + BdrvRequestFlags flags); + int generated_co_wrapper blk_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, @@ -128,36 +143,18 @@ int coroutine_fn blk_co_pwritev_part(BlockBackend *blk, int64_t offset, int64_t bytes, QEMUIOVector *qiov, size_t qiov_offset, BdrvRequestFlags flags); -int generated_co_wrapper blk_pwritev(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); -int coroutine_fn blk_co_pwritev(BlockBackend *blk, int64_t offset, - int64_t bytes, QEMUIOVector *qiov, - BdrvRequestFlags flags); - -static inline int coroutine_fn blk_co_pread(BlockBackend *blk, int64_t offset, - int64_t bytes, void *buf, - BdrvRequestFlags flags) -{ - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); - IO_OR_GS_CODE(); - - assert(bytes <= SIZE_MAX); - - return blk_co_preadv(blk, offset, bytes, &qiov, flags); -} - -static inline int coroutine_fn blk_co_pwrite(BlockBackend *blk, int64_t offset, - int64_t bytes, const void *buf, - BdrvRequestFlags flags) -{ - QEMUIOVector qiov = QEMU_IOVEC_INIT_BUF(qiov, buf, bytes); - IO_OR_GS_CODE(); - assert(bytes <= SIZE_MAX); +int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, + int64_t offset, int64_t bytes, + const void *buf); +int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, + int64_t bytes, const void *buf); - return blk_co_pwritev(blk, offset, bytes, &qiov, flags); -} +int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, + int64_t bytes, + BdrvRequestFlags flags); +int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, + int64_t bytes, BdrvRequestFlags flags); int generated_co_wrapper blk_pdiscard(BlockBackend *blk, int64_t offset, int64_t bytes); @@ -172,16 +169,6 @@ int generated_co_wrapper blk_ioctl(BlockBackend *blk, unsigned long int req, int coroutine_fn blk_co_ioctl(BlockBackend *blk, unsigned long int req, void *buf); -int generated_co_wrapper blk_pwrite_compressed(BlockBackend *blk, - int64_t offset, int64_t bytes, - const void *buf); -int coroutine_fn blk_co_pwrite_compressed(BlockBackend *blk, int64_t offset, - int64_t bytes, const void *buf); -int generated_co_wrapper blk_pwrite_zeroes(BlockBackend *blk, int64_t offset, - int64_t bytes, - BdrvRequestFlags flags); -int coroutine_fn blk_co_pwrite_zeroes(BlockBackend *blk, int64_t offset, - int64_t bytes, BdrvRequestFlags flags); int generated_co_wrapper blk_truncate(BlockBackend *blk, int64_t offset, bool exact, PreallocMode prealloc, BdrvRequestFlags flags, Error **errp); -- cgit v1.1