All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 18/43] block: Switch discard length bounds to byte-based
Date: Tue,  5 Jul 2016 17:50:27 +0200	[thread overview]
Message-ID: <1467733852-27097-19-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1467733852-27097-1-git-send-email-kwolf@redhat.com>

From: Eric Blake <eblake@redhat.com>

Sector-based limits are awkward to think about; in our on-going
quest to move to byte-based interfaces, convert max_discard and
discard_alignment.  Rename them, using 'pdiscard' as an aid to
track which remaining discard interfaces need conversion, and so
that the compiler will help us catch the change in semantics
across any rebased code.  The BlockLimits type is now completely
byte-based; and in iscsi.c, sector_limits_lun2qemu() is no
longer needed.

pdiscard_alignment is made unsigned (we use power-of-2 alignments
as bitmasks, where unsigned is easier to think about) while
leaving max_pdiscard signed (since we still have an 'int'
interface); this is comparable to what commit cf081fc did for
write zeroes limits.  We may later want to make everything an
unsigned 64-bit limit - but that requires a bigger code audit.

Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/io.c                | 16 +++++++++-------
 block/iscsi.c             | 19 ++++++-------------
 block/nbd.c               |  2 +-
 include/block/block_int.h | 16 +++++++++++-----
 qemu-img.c                |  3 ++-
 5 files changed, 29 insertions(+), 27 deletions(-)

diff --git a/block/io.c b/block/io.c
index 8ca9d43..0f15d05 100644
--- a/block/io.c
+++ b/block/io.c
@@ -2368,19 +2368,21 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
         goto out;
     }
 
-    max_discard = MIN_NON_ZERO(bs->bl.max_discard, BDRV_REQUEST_MAX_SECTORS);
+    max_discard = MIN_NON_ZERO(bs->bl.max_pdiscard >> BDRV_SECTOR_BITS,
+                               BDRV_REQUEST_MAX_SECTORS);
     while (nb_sectors > 0) {
         int ret;
         int num = nb_sectors;
+        int discard_alignment = bs->bl.pdiscard_alignment >> BDRV_SECTOR_BITS;
 
         /* align request */
-        if (bs->bl.discard_alignment &&
-            num >= bs->bl.discard_alignment &&
-            sector_num % bs->bl.discard_alignment) {
-            if (num > bs->bl.discard_alignment) {
-                num = bs->bl.discard_alignment;
+        if (discard_alignment &&
+            num >= discard_alignment &&
+            sector_num % discard_alignment) {
+            if (num > discard_alignment) {
+                num = discard_alignment;
             }
-            num -= sector_num % bs->bl.discard_alignment;
+            num -= sector_num % discard_alignment;
         }
 
         /* limit request size */
diff --git a/block/iscsi.c b/block/iscsi.c
index bde4a04..342f6b8 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1697,13 +1697,6 @@ static void iscsi_close(BlockDriverState *bs)
     memset(iscsilun, 0, sizeof(IscsiLun));
 }
 
-static int sector_limits_lun2qemu(int64_t sector, IscsiLun *iscsilun)
-{
-    int limit = MIN(sector_lun2qemu(sector, iscsilun), INT_MAX / 2 + 1);
-
-    return limit < BDRV_REQUEST_MAX_SECTORS ? limit : 0;
-}
-
 static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
 {
     /* We don't actually refresh here, but just return data queried in
@@ -1723,14 +1716,14 @@ static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp)
     }
 
     if (iscsilun->lbp.lbpu) {
-        if (iscsilun->bl.max_unmap < 0xffffffff) {
-            bs->bl.max_discard =
-                sector_limits_lun2qemu(iscsilun->bl.max_unmap, iscsilun);
+        if (iscsilun->bl.max_unmap < 0xffffffff / iscsilun->block_size) {
+            bs->bl.max_pdiscard =
+                iscsilun->bl.max_unmap * iscsilun->block_size;
         }
-        bs->bl.discard_alignment =
-            sector_limits_lun2qemu(iscsilun->bl.opt_unmap_gran, iscsilun);
+        bs->bl.pdiscard_alignment =
+            iscsilun->bl.opt_unmap_gran * iscsilun->block_size;
     } else {
-        bs->bl.discard_alignment = iscsilun->block_size >> BDRV_SECTOR_BITS;
+        bs->bl.pdiscard_alignment = iscsilun->block_size;
     }
 
     if (iscsilun->bl.max_ws_len < 0xffffffff / iscsilun->block_size) {
diff --git a/block/nbd.c b/block/nbd.c
index f5511ea..08e5b67 100644
--- a/block/nbd.c
+++ b/block/nbd.c
@@ -362,7 +362,7 @@ static int nbd_co_flush(BlockDriverState *bs)
 
 static void nbd_refresh_limits(BlockDriverState *bs, Error **errp)
 {
-    bs->bl.max_discard = NBD_MAX_SECTORS;
+    bs->bl.max_pdiscard = NBD_MAX_BUFFER_SIZE;
     bs->bl.max_transfer = NBD_MAX_BUFFER_SIZE;
 }
 
diff --git a/include/block/block_int.h b/include/block/block_int.h
index 7a4a00f..a3e69fd 100644
--- a/include/block/block_int.h
+++ b/include/block/block_int.h
@@ -324,11 +324,17 @@ struct BlockDriver {
 };
 
 typedef struct BlockLimits {
-    /* maximum number of sectors that can be discarded at once */
-    int max_discard;
-
-    /* optimal alignment for discard requests in sectors */
-    int64_t discard_alignment;
+    /* maximum number of bytes that can be discarded at once (since it
+     * is signed, it must be < 2G, if set), should be multiple of
+     * pdiscard_alignment, but need not be power of 2. May be 0 if no
+     * inherent 32-bit limit */
+    int32_t max_pdiscard;
+
+    /* optimal alignment for discard requests in bytes, must be power
+     * of 2, less than max_pdiscard if that is set, and multiple of
+     * bs->request_alignment. May be 0 if bs->request_alignment is
+     * good enough */
+    uint32_t pdiscard_alignment;
 
     /* maximum number of bytes that can zeroized at once (since it is
      * signed, it must be < 2G, if set), should be multiple of
diff --git a/qemu-img.c b/qemu-img.c
index 046b267..3a7c162 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -2091,7 +2091,8 @@ static int img_convert(int argc, char **argv)
     bufsectors = MIN(32768,
                      MAX(bufsectors,
                          MAX(out_bs->bl.opt_transfer >> BDRV_SECTOR_BITS,
-                             out_bs->bl.discard_alignment)));
+                             out_bs->bl.pdiscard_alignment >>
+                             BDRV_SECTOR_BITS)));
 
     if (skip_create) {
         int64_t output_sectors = blk_nb_sectors(out_blk);
-- 
1.8.3.1

  parent reply	other threads:[~2016-07-05 15:51 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-05 15:50 [Qemu-devel] [PULL 00/43] Block layer patches Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 01/43] qemu-img: fix failed autotests Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 02/43] block: Tighter assertions on bdrv_aligned_pwritev() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 03/43] block: Document supported flags during bdrv_aligned_preadv() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 04/43] block: Fix harmless off-by-one in bdrv_aligned_preadv() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 05/43] nbd: Allow larger requests Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 06/43] nbd: Advertise realistic limits to block layer Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 07/43] iscsi: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 08/43] scsi: Advertise limits by blocksize, not 512 Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 09/43] block: Give nonzero result to blk_get_max_transfer_length() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 10/43] blkdebug: Set request_alignment during .bdrv_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 11/43] iscsi: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 12/43] qcow2: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 13/43] raw-win32: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 14/43] block: " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 15/43] block: Set default request_alignment during bdrv_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 16/43] block: Switch transfer length bounds to byte-based Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 17/43] block: Wording tweaks to write zeroes limits Kevin Wolf
2016-07-05 15:50 ` Kevin Wolf [this message]
2016-07-06  2:14   ` [Qemu-devel] [PULL 18/43] block: Switch discard length bounds to byte-based Eric Blake
2016-07-06  8:27     ` Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 19/43] block: Drop raw_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 20/43] block: Split bdrv_merge_limits() from bdrv_refresh_limits() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 21/43] block: Move request_alignment into BlockLimit Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 22/43] block: Fix error message style Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 23/43] block: Use bool as appropriate for BDS members Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 24/43] block: fix return code for partial write for Linux AIO Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 25/43] block/qdev: Fix NULL access when using BB twice Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 26/43] vvfat: Use BdrvChild for s->qcow Kevin Wolf
2016-07-11 14:02   ` Paolo Bonzini
2016-07-05 15:50 ` [Qemu-devel] [PULL 27/43] blkreplay: Convert to byte-based I/O Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 28/43] vhdx: Some more BlockBackend use in vhdx_create() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 29/43] block: Convert bdrv_co_readv() to BdrvChild Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 30/43] block: Convert bdrv_co_writev() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 31/43] block: Convert bdrv_aio_readv() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 32/43] block: Convert bdrv_aio_writev() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 33/43] block: Convert bdrv_co_do_readv/writev " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 34/43] block: Move bdrv_commit() to block/commit.c Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 35/43] block: Use BlockBackend for I/O in bdrv_commit() Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 36/43] block: Convert bdrv_read() to BdrvChild Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 37/43] block: Convert bdrv_write() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 38/43] block: Convert bdrv_pread(v) " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 39/43] block: Convert bdrv_pwrite(v/_sync) " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 40/43] block: Convert bdrv_pwrite_zeroes() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 41/43] block: Convert bdrv_prwv_co() " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 42/43] block: Convert bdrv_co_preadv/pwritev " Kevin Wolf
2016-07-05 15:50 ` [Qemu-devel] [PULL 43/43] block/qcow2: Don't use cpu_to_*w() Kevin Wolf
2016-07-06  9:23 ` [Qemu-devel] [PULL 00/43] Block layer patches Peter Maydell

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=1467733852-27097-19-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.