[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/14] block/export: improve vu_blk_sect_range_ok()
From: |
Kevin Wolf |
Subject: |
[PULL 05/14] block/export: improve vu_blk_sect_range_ok() |
Date: |
Fri, 14 May 2021 18:31:15 +0200 |
From: Stefan Hajnoczi <stefanha@redhat.com>
The checks in vu_blk_sect_range_ok() assume VIRTIO_BLK_SECTOR_SIZE is
equal to BDRV_SECTOR_SIZE. This is true, but let's add a
QEMU_BUILD_BUG_ON() to make it explicit.
We might as well check that the request buffer size is a multiple of
VIRTIO_BLK_SECTOR_SIZE while we're at it.
Suggested-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20210331142727.391465-1-stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/export/vhost-user-blk-server.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/block/export/vhost-user-blk-server.c
b/block/export/vhost-user-blk-server.c
index fa06996d37..1862563336 100644
--- a/block/export/vhost-user-blk-server.c
+++ b/block/export/vhost-user-blk-server.c
@@ -70,9 +70,16 @@ static void vu_blk_req_complete(VuBlkReq *req)
static bool vu_blk_sect_range_ok(VuBlkExport *vexp, uint64_t sector,
size_t size)
{
- uint64_t nb_sectors = size >> BDRV_SECTOR_BITS;
+ uint64_t nb_sectors;
uint64_t total_sectors;
+ if (size % VIRTIO_BLK_SECTOR_SIZE) {
+ return false;
+ }
+
+ nb_sectors = size >> VIRTIO_BLK_SECTOR_BITS;
+
+ QEMU_BUILD_BUG_ON(BDRV_SECTOR_SIZE != VIRTIO_BLK_SECTOR_SIZE);
if (nb_sectors > BDRV_REQUEST_MAX_SECTORS) {
return false;
}
--
2.30.2
- [PULL 00/14] Block layer patches, Kevin Wolf, 2021/05/14
- [PULL 01/14] qcow2: set bdi->is_dirty, Kevin Wolf, 2021/05/14
- [PULL 02/14] block: Fix Transaction leak in bdrv_root_attach_child(), Kevin Wolf, 2021/05/14
- [PULL 05/14] block/export: improve vu_blk_sect_range_ok(),
Kevin Wolf <=
- [PULL 03/14] block: Fix Transaction leak in bdrv_reopen_multiple(), Kevin Wolf, 2021/05/14
- [PULL 04/14] qapi: spelling fix (addtional), Kevin Wolf, 2021/05/14
- [PULL 10/14] vhost-user-blk: Don't reconnect during initialisation, Kevin Wolf, 2021/05/14
- [PULL 06/14] test: new qTest case to test the vhost-user-blk-server, Kevin Wolf, 2021/05/14
- [PULL 08/14] vhost-user-blk-test: test discard/write zeroes invalid inputs, Kevin Wolf, 2021/05/14
- [PULL 14/14] vhost-user-blk: Check that num-queues is supported by backend, Kevin Wolf, 2021/05/14
- [PULL 09/14] vhost-user-blk: Make sure to set Error on realize failure, Kevin Wolf, 2021/05/14
- [PULL 12/14] vhost-user-blk: Get more feature flags from vhost device, Kevin Wolf, 2021/05/14
- [PULL 11/14] vhost-user-blk: Improve error reporting in realize, Kevin Wolf, 2021/05/14