From patchwork Fri Jun 3 17:03:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Blake X-Patchwork-Id: 9153755 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BAE4F60221 for ; Fri, 3 Jun 2016 17:03:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4DBF26E82 for ; Fri, 3 Jun 2016 17:03:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 987EB28304; Fri, 3 Jun 2016 17:03:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D6A0526E82 for ; Fri, 3 Jun 2016 17:03:56 +0000 (UTC) Received: from localhost ([::1]:56754 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVn-0007Gb-JV for patchwork-qemu-devel@patchwork.kernel.org; Fri, 03 Jun 2016 13:03:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36858) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVE-0007G6-JL for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b8sVD-0003Wf-7K for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:20 -0400 Received: from resqmta-po-01v.sys.comcast.net ([2001:558:fe16:19:96:114:154:160]:38532) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b8sVD-0003WG-14 for qemu-devel@nongnu.org; Fri, 03 Jun 2016 13:03:19 -0400 Received: from resomta-po-13v.sys.comcast.net ([96.114.154.237]) by resqmta-po-01v.sys.comcast.net with SMTP id 8sTPbfH0lkzyl8sVCb7cJe; Fri, 03 Jun 2016 17:03:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=q20140121; t=1464973398; bh=6OT1TGKJxwLMff4ppNFbrpfkxUo718CcdnGNUoydAlU=; h=Received:Received:From:To:Subject:Date:Message-Id; b=cZ7rue2DitgUBdoawsjctIUcpzrEHiZ4BZPvuYRJFsPNR2T6mFSutsxJNuJj7v2ST pWmtyojTXh6gN+smk4rpNf987WP4BF6LAjmJyC71rzJlRwcR7QZKPKp39f40pmP+P8 luxsipy5AVBjVheYGlCW2FibrBBDvDcA45L6NXvYX0DZEr2p41Yb5OUGliGKn2Ty2b IXTqoHUqnVtSApQ07/6G+5pc67nPW5Sk+R1PAVeyI4GVSRHXoub2u5lEMz2beOQvse vjwWJ7uTzxkCP+/bCXF7eRYOsqYzRr8It1tl7TM0qkvT10bHslhtGBvu89F9l3T4Or s+sqlREKjCyQA== Received: from red.redhat.com ([24.10.254.122]) by resomta-po-13v.sys.comcast.net with comcast id 2H381t00U2fD5rL01H3J6W; Fri, 03 Jun 2016 17:03:18 +0000 From: Eric Blake To: qemu-devel@nongnu.org Date: Fri, 3 Jun 2016 11:03:07 -0600 Message-Id: <1464973388-15821-5-git-send-email-eblake@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1464973388-15821-1-git-send-email-eblake@redhat.com> References: <1464973388-15821-1-git-send-email-eblake@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:558:fe16:19:96:114:154:160 Subject: [Qemu-devel] [PATCH 4/5] block: Switch discard length bounds to byte-based X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, Fam Zheng , Stefan Hajnoczi , qemu-block@nongnu.org, Peter Lieven , mreitz@redhat.com, Ronnie Sahlberg , Paolo Bonzini Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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. In iscsi.c, sector_limits_lun2qemu() is no longer needed; and the BlockLimits type is now completely byte-based. Signed-off-by: Eric Blake --- include/block/block_int.h | 21 +++++++++++++++------ block/io.c | 16 +++++++++------- block/iscsi.c | 17 ++++++----------- block/nbd.c | 2 +- qemu-img.c | 3 ++- 5 files changed, 33 insertions(+), 26 deletions(-) diff --git a/include/block/block_int.h b/include/block/block_int.h index 96e8476..9dc7af4 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -322,18 +322,27 @@ struct BlockDriver { }; typedef struct BlockLimits { - /* maximum number of sectors that can be discarded at once */ - int max_discard; + /* 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 sectors */ - int64_t discard_alignment; + /* optimal alignment for discard requests in bytes, must be power + * of 2, less than max_discard 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) */ + * signed, it must be < 2G, if set), should be multiple of + * pwrite_zeroes_alignment. May be 0 if no inherent 32-bit limit */ int32_t max_pwrite_zeroes; /* optimal alignment for write zeroes requests in bytes, must be - * power of 2, and less than max_pwrite_zeroes if that is set */ + * power of 2, less than max_pwrite_zeroes if that is set, and + * multiple of bs->request_alignment. May be 0 if + * bs->request_alignment is good enough */ uint32_t pwrite_zeroes_alignment; /* optimal transfer length in bytes (must be power of 2, and diff --git a/block/io.c b/block/io.c index a2bc254..e845ef9 100644 --- a/block/io.c +++ b/block/io.c @@ -2255,19 +2255,21 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num, BDRV_TRACKED_DISCARD); bdrv_set_dirty(bs, sector_num, nb_sectors); - 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 c5855be..1486443 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -1697,11 +1697,6 @@ static void iscsi_close(BlockDriverState *bs) memset(iscsilun, 0, sizeof(IscsiLun)); } -static int sector_limits_lun2qemu(int64_t sector, IscsiLun *iscsilun) -{ - return MIN(sector_lun2qemu(sector, iscsilun), INT_MAX / 2 + 1); -} - static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp) { /* We don't actually refresh here, but just return data queried in @@ -1718,14 +1713,14 @@ static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp) max_xfer_len * iscsilun->block_size); 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 2ce7b4d..a3de9bc 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 = UINT32_MAX >> BDRV_SECTOR_BITS; + bs->bl.max_pdiscard = INT32_MAX; bs->bl.max_transfer = NBD_MAX_BUFFER_SIZE; } diff --git a/qemu-img.c b/qemu-img.c index 577df0d..26500dc 100644 --- a/qemu-img.c +++ b/qemu-img.c @@ -2080,7 +2080,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);