qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
	Laurent Vivier <lvivier@redhat.com>,
	Thomas Huth <thuth@redhat.com>,
	qemu-block@nongnu.org, "Michael S. Tsirkin" <mst@redhat.com>,
	Peter Maydell <peter.maydell@linaro.org>,
	Coiby Xu <coiby.xu@gmail.com>, Max Reitz <mreitz@redhat.com>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Raphael Norwitz <raphael.norwitz@nutanix.com>
Subject: [PATCH v3 08/12] block/export: use VIRTIO_BLK_SECTOR_BITS
Date: Tue, 23 Feb 2021 14:46:49 +0000	[thread overview]
Message-ID: <20210223144653.811468-9-stefanha@redhat.com> (raw)
In-Reply-To: <20210223144653.811468-1-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>
---
 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


  parent reply	other threads:[~2021-02-23 14:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-23 14:46 [PATCH v3 00/12] block/export: vhost-user-blk server tests and input validation Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 01/12] vhost-user-blk: fix blkcfg->num_queues endianness Stefan Hajnoczi
2021-02-23 16:13   ` Michael S. Tsirkin
2021-02-24 15:12     ` Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 02/12] libqtest: add qtest_socket_server() Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 03/12] libqtest: add qtest_kill_qemu() Stefan Hajnoczi
2021-03-08  6:38   ` Thomas Huth
2021-02-23 14:46 ` [PATCH v3 04/12] libqtest: add qtest_remove_abrt_handler() Stefan Hajnoczi
2021-03-08  6:44   ` Thomas Huth
2021-02-23 14:46 ` [PATCH v3 05/12] test: new qTest case to test the vhost-user-blk-server Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 06/12] tests/qtest: add multi-queue test case to vhost-user-blk-test Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 07/12] block/export: fix blk_size double byteswap Stefan Hajnoczi
2021-02-23 14:46 ` Stefan Hajnoczi [this message]
2021-02-23 14:46 ` [PATCH v3 09/12] block/export: fix vhost-user-blk export sector number calculation Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 10/12] block/export: port virtio-blk discard/write zeroes input validation Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 11/12] vhost-user-blk-test: test discard/write zeroes invalid inputs Stefan Hajnoczi
2021-02-23 14:46 ` [PATCH v3 12/12] block/export: port virtio-blk read/write range check Stefan Hajnoczi
2021-03-03 12:40 ` [PATCH v3 00/12] block/export: vhost-user-blk server tests and input validation Kevin Wolf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210223144653.811468-9-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=coiby.xu@gmail.com \
    --cc=kwolf@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=raphael.norwitz@nutanix.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).