[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 19/31] block/export: use VIRTIO_BLK_SECTOR_BITS
From: |
Kevin Wolf |
Subject: |
[PULL 19/31] block/export: use VIRTIO_BLK_SECTOR_BITS |
Date: |
Fri, 5 Mar 2021 17:54:42 +0100 |
From: Stefan Hajnoczi <stefanha@redhat.com>
Use VIRTIO_BLK_SECTOR_BITS and VIRTIO_BLK_SECTOR_SIZE when dealing with
virtio-blk sector numbers. Although the values happen to be the same as
BDRV_SECTOR_BITS and BDRV_SECTOR_SIZE, they are conceptually different.
This makes it clearer when we are dealing with virtio-blk sector units.
Use VIRTIO_BLK_SECTOR_BITS in vu_blk_initialize_config(). Later patches
will use it the new constants the virtqueue request processing code
path.
Suggested-by: Max Reitz <mreitz@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-Id: <20210223144653.811468-9-stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/export/vhost-user-blk-server.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)
diff --git a/block/export/vhost-user-blk-server.c
b/block/export/vhost-user-blk-server.c
index 7aea132f69..2614a63791 100644
--- a/block/export/vhost-user-blk-server.c
+++ b/block/export/vhost-user-blk-server.c
@@ -20,6 +20,13 @@
#include "sysemu/block-backend.h"
#include "util/block-helpers.h"
+/*
+ * Sector units are 512 bytes regardless of the
+ * virtio_blk_config->blk_size value.
+ */
+#define VIRTIO_BLK_SECTOR_BITS 9
+#define VIRTIO_BLK_SECTOR_SIZE (1ull << VIRTIO_BLK_SECTOR_BITS)
+
enum {
VHOST_USER_BLK_NUM_QUEUES_DEFAULT = 1,
};
@@ -347,7 +354,8 @@ vu_blk_initialize_config(BlockDriverState *bs,
uint32_t blk_size,
uint16_t num_queues)
{
- config->capacity = cpu_to_le64(bdrv_getlength(bs) >> BDRV_SECTOR_BITS);
+ config->capacity =
+ cpu_to_le64(bdrv_getlength(bs) >> VIRTIO_BLK_SECTOR_BITS);
config->blk_size = cpu_to_le32(blk_size);
config->size_max = cpu_to_le32(0);
config->seg_max = cpu_to_le32(128 - 2);
@@ -356,7 +364,8 @@ vu_blk_initialize_config(BlockDriverState *bs,
config->num_queues = cpu_to_le16(num_queues);
config->max_discard_sectors = cpu_to_le32(32768);
config->max_discard_seg = cpu_to_le32(1);
- config->discard_sector_alignment = cpu_to_le32(blk_size >> 9);
+ config->discard_sector_alignment =
+ cpu_to_le32(blk_size >> VIRTIO_BLK_SECTOR_BITS);
config->max_write_zeroes_sectors = cpu_to_le32(32768);
config->max_write_zeroes_seg = cpu_to_le32(1);
}
@@ -383,7 +392,7 @@ static int vu_blk_exp_create(BlockExport *exp,
BlockExportOptions *opts,
if (vu_opts->has_logical_block_size) {
logical_block_size = vu_opts->logical_block_size;
} else {
- logical_block_size = BDRV_SECTOR_SIZE;
+ logical_block_size = VIRTIO_BLK_SECTOR_SIZE;
}
check_block_size(exp->id, "logical-block-size", logical_block_size,
&local_err);
--
2.29.2
- [PULL 06/31] blockjob: report a better error message, (continued)
- [PULL 06/31] blockjob: report a better error message, Kevin Wolf, 2021/03/05
- [PULL 01/31] iotests: Drop deprecated 'props' from object-add, Kevin Wolf, 2021/03/05
- [PULL 15/31] libqtest: add qtest_remove_abrt_handler(), Kevin Wolf, 2021/03/05
- [PULL 13/31] libqtest: add qtest_socket_server(), Kevin Wolf, 2021/03/05
- [PULL 08/31] storage-daemon: include current command line option in the errors, Kevin Wolf, 2021/03/05
- [PULL 05/31] iotests: Fix up python style in 300, Kevin Wolf, 2021/03/05
- [PULL 09/31] qemu-storage-daemon: add --pidfile option, Kevin Wolf, 2021/03/05
- [PULL 02/31] backup: Remove nodes from job in .clean(), Kevin Wolf, 2021/03/05
- [PULL 26/31] block/parallels: BDRVParallelsState: add cluster_size field, Kevin Wolf, 2021/03/05
- [PULL 11/31] docs: replace insecure /tmp examples in qsd docs, Kevin Wolf, 2021/03/05
- [PULL 19/31] block/export: use VIRTIO_BLK_SECTOR_BITS,
Kevin Wolf <=
- [PULL 25/31] parallels.txt: fix bitmap L1 table description, Kevin Wolf, 2021/03/05
- [PULL 10/31] docs: show how to spawn qemu-storage-daemon with fd passing, Kevin Wolf, 2021/03/05
- [PULL 20/31] block/export: fix vhost-user-blk export sector number calculation, Kevin Wolf, 2021/03/05
- [PULL 17/31] tests/qtest: add multi-queue test case to vhost-user-blk-test, Kevin Wolf, 2021/03/05
- [PULL 21/31] block/export: port virtio-blk discard/write zeroes input validation, Kevin Wolf, 2021/03/05
- [PULL 23/31] block/export: port virtio-blk read/write range check, Kevin Wolf, 2021/03/05
- [PULL 03/31] backup-top: Refuse I/O in inactive state, Kevin Wolf, 2021/03/05
- [PULL 30/31] MAINTAINERS: update parallels block driver, Kevin Wolf, 2021/03/05
- [PULL 31/31] docs: qsd: Explain --export nbd,name=... default, Kevin Wolf, 2021/03/05
- [PULL 28/31] iotests.py: add unarchive_sample_image() helper, Kevin Wolf, 2021/03/05