From patchwork Thu Dec 17 11:39:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bart Van Assche X-Patchwork-Id: 7872131 Return-Path: X-Original-To: patchwork-linux-block@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 19C4EBEEE5 for ; Thu, 17 Dec 2015 11:40:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DFB0B203ED for ; Thu, 17 Dec 2015 11:39:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4BC0F203F1 for ; Thu, 17 Dec 2015 11:39:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965899AbbLQLju (ORCPT ); Thu, 17 Dec 2015 06:39:50 -0500 Received: from mail-bn1on0083.outbound.protection.outlook.com ([157.56.110.83]:52684 "EHLO na01-bn1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965885AbbLQLjr (ORCPT ); Thu, 17 Dec 2015 06:39:47 -0500 X-Greylist: delayed 158281 seconds by postgrey-1.27 at vger.kernel.org; Thu, 17 Dec 2015 06:39:47 EST Received: from CY1PR0201CA0020.namprd02.prod.outlook.com (10.163.30.158) by BL2PR02MB289.namprd02.prod.outlook.com (10.141.90.143) with Microsoft SMTP Server (TLS) id 15.1.337.19; Thu, 17 Dec 2015 11:39:45 +0000 Received: from BN1AFFO11FD053.protection.gbl (2a01:111:f400:7c10::160) by CY1PR0201CA0020.outlook.office365.com (2a01:111:e400:58b9::30) with Microsoft SMTP Server (TLS) id 15.1.361.13 via Frontend Transport; Thu, 17 Dec 2015 11:39:44 +0000 Authentication-Results: spf=pass (sender IP is 63.163.107.173) smtp.mailfrom=sandisk.com; redhat.com; dkim=none (message not signed) header.d=none;redhat.com; dmarc=bestguesspass action=none header.from=sandisk.com; Received-SPF: Pass (protection.outlook.com: domain of sandisk.com designates 63.163.107.173 as permitted sender) receiver=protection.outlook.com; client-ip=63.163.107.173; helo=milsmgep12.sandisk.com; Received: from milsmgep12.sandisk.com (63.163.107.173) by BN1AFFO11FD053.mail.protection.outlook.com (10.58.53.68) with Microsoft SMTP Server id 15.1.355.15 via Frontend Transport; Thu, 17 Dec 2015 11:39:43 +0000 Received: from MILHUBIP03.sdcorp.global.sandisk.com ( [172.22.12.162]) by milsmgep12.sandisk.com (Symantec Messaging Gateway) with SMTP id BA.59.32178.FFE92765; Thu, 17 Dec 2015 03:39:43 -0800 (PST) Received: from milsmgip12.sandisk.com (10.177.8.100) by MILHUBIP03.sdcorp.global.sandisk.com (10.177.9.96) with Microsoft SMTP Server id 14.3.248.2; Thu, 17 Dec 2015 03:39:43 -0800 X-AuditID: ac160a69-f79f76d000007db2-fa-56729eff1174 Received: from [10.50.231.72] ( [10.177.8.100]) by milsmgip12.sandisk.com (Symantec Messaging Gateway) with SMTP id 53.E0.17166.DFE92765; Thu, 17 Dec 2015 03:39:43 -0800 (PST) Subject: [PATCH 1/6] block: Introduce blk_round_sect_down() To: Jens Axboe References: <56729ECF.50906@sandisk.com> CC: Jan Kara , Christoph Hellwig , Mike Snitzer , "Martin K. Petersen" , Dmitry Monakhov , "linux-block@vger.kernel.org" , device-mapper development From: Bart Van Assche Message-ID: <56729EFC.1030400@sandisk.com> Date: Thu, 17 Dec 2015 12:39:40 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 MIME-Version: 1.0 In-Reply-To: <56729ECF.50906@sandisk.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprGIsWRmVeSWpSXmKPExsWyRoxnke7/eUVhBluvi1v833OMzWLvu9ms FidmelqsXH2UyWL29GYmi723tC2WH//HZNG28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fyQJSwyugJXFhexpImEVAVeLRjC9gYVGBCIlFOzJBwrwC ghInZz4Bu4BTQFPiV/8zJhCbWUBd4s+8S8wQtrzE9rdzmCcw8s9C0jILSdksJGULGJlXMYrl ZuYU56ZnFhga6RUn5qVkFmfrJefnbmIEhzhn1A7G6xPNDzEycXBKNTBaKR3blhKpurA3eYHG LO5oH6a3hVIv7jA9knvSofn1yUYbFs+Xjs01W8IT/7L1Pl0ktqNINTNqQvT8um2hZ5lW2x6o 9J1s0vL9VcXiRbc3lr96f+/6PLYH/yeLnZCd8Xn+UX6fA1mBnulND9YbbmFhXri5J7aIcYJ0 h0flw2eRgodOZenVLBJSYinOSDTUYi4qTgQAWg/cNiECAAA= X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD053; 1:wA9tsDL20W2McmIDI7lFuKwykqReo43l0uWPtx7t26lh/Xry9inpIXnaKm9iN6njyoPbXko+kj7M4izPCWFferkFGta8uVq4jB/NVS0+tCTZ/dooY99AT4W5WWQoaxeQyrVz5VGpYiLhvGuB7xQ4zTnAfMdK031axQjMDBoKC7gVNZW805ASZ0cfMlWLC523hfzjKp0c0vpdEZCT6B/NqR/UZi7t0zHk7BMseXIGIAkYfveqS9l/U7/FtMU2Sp3Sx5DLiq6gBuff7WAhHOWG2kZE2oxPPD+2NV5App3jUdiRnRjAEQwocyHwm9PCBcX0WFw2f8BaQ0itMSWb+8DabRRlUBQTl+0ETNsrurh7RjdisrgS56e9K/DpkKTp7tJH X-Forefront-Antispam-Report: CIP:63.163.107.173; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(2980300002)(438002)(189002)(199003)(83506001)(81156007)(19580405001)(19580395003)(11100500001)(230700001)(33656002)(586003)(1096002)(106466001)(80316001)(77096005)(50466002)(229853001)(99136001)(97736004)(65806001)(50986999)(189998001)(1220700001)(59896002)(86362001)(2950100001)(4001350100001)(36756003)(87266999)(5001960100002)(69596002)(54356999)(5008740100001)(92566002)(87936001)(110136002)(47776003)(23676002)(65816999)(65956001)(64126003)(76176999); DIR:OUT; SFP:1101; SCL:1; SRVR:BL2PR02MB289; H:milsmgep12.sandisk.com; FPR:; SPF:Pass; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB289; 2:BukLc8DRV+tILDl5CehCnxcK4CvNDH8oxD7zIhdR6kay6adbEA+EbslBeTJe5ZHOLoFJWzM1+d8YCWCCHJ2d2SPMwxoe0Fw4Q2Og10vfEazSshsPD6QI7YEKFt0V/7Grw1mQ9caDHh55/PqoV5JtNQ==; 3:4mEjqi7ApqAP7bPnDFx0UWJT2eTTQP3ELU9l5fgJ+N7iI4tTUGUJU5h6ZUPsdHde28YUSeQUoXs85OWyLYiMgCHYrDQwfNhkqHd64g4MtzdE+8TAQP1hZbP7DJ7yA3enLsS+yOYUirRxxglo8UsJkllddAchAF1XQ44R3PmAr2oTLy5cDmbKJs1gxZHwij9n4nCunSrtB3F9BrCzD/Oo5XVnSU0K3YZxiEmdxoEGgI+3sDrh/SjRtZEnq/zPRxp9nUP2W4VOFtRNRIUP3FQXfQ==; 25:XxSCK9LAW2hJnkMEnkxIPTc3fwH1GlM8IjAyJXv7lybQKPHW4GidqdmQ6YFkXMl0ZD1Q/XnfkKiMRNGP+YFGl81xYASpenPb2d0EVblYU2rNGw9n2ob2WMPz4alNMhJbhnW8PzDhfrL3qH7WwnKiRI20NoSZ9C96YiFxl1qCWia0K8Bto3YBx8Jhc+okDomY7H2tUf8IK11VTe7G6VYoqTrHkTjftn3CG0RuDWYaLa+xCUbklvyxnSXLPPtU33j9 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(8251501001); SRVR:BL2PR02MB289; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB289; 20:BlqykInlfM715apUEoTUFumfFGVK16yrZ/HA/OgqeXlQml63hQQALFbBPfMD1qdeiAMpWow4rRbefsfoBfq+aK7MUd8v6uK/TLBVaUn6jdX11IvZl0jaFvgR0pE2ZBS6AbGDD7R8DVxgDgSrgM+nsHlXcPLTJqrlOeftKTSu7dSbeB44HTiM52aam6/0VZKNSffdriYytedQYq3lG7jTJvex7Wg3gl9wV1A6b+SQUUJ/VUFDZp1hP5MhJZzeVVytFCr691ElDGawL4VUX7svjX6I0qmZcgspJt5vo2kAB+Q20Ty42GQN7Pw2dw5M5Iu6oewsursBmkYXXsVYUovHrBB/BEE/XVUUdPaie4pn4xeF+kUHJMQVVfPvpltbQMh1ll31I0LYirgOMs3/MLbZntFFG5K+YSwOBrf+lRCghKHdFE9ZtXkRBs/VKFqJUTL8iCTmRlXrRzIxls50UaDDiuociG9FmnYUBLiaQ5SYLwbbOshSoJMNeBzONzgCocgC X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(146099531331640)(42932892334569); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(2401047)(5005006)(520078)(8121501046)(10201501046)(3002001); SRVR:BL2PR02MB289; BCL:0; PCL:0; RULEID:; SRVR:BL2PR02MB289; X-Microsoft-Exchange-Diagnostics: 1; BL2PR02MB289; 4:WzJERsLCGT2Jh7PxjIugI4+sogagW0pA/2NmeBaSYnCOON893Se/z8VJcLhi/iImMzo/rviKEhxtLcNExjvDhF1WyGsGzoWE3sFlDQzQkGgrcxTgb/I0/YYSUaO9BXD82LP9Jcxn8My/cYAafDtMjDX0sqe+9PJ9iR7ebXiGo+nCMvZuSGQdZVr+jDk0fcbz3acgTF/G3DTI0TcWvqgUorRhlTi2AURRDWawtkW/TNWREPPQ5G75eNZ8v+irySd6MaDYUdz0NLIKFllBS00YqYROfqN1cOfQ4n2VIqZQgwzoMKRUuQtU8G4HI+Rub+/DGsYnh5kZ4hRa+cKr0Ysecvw9UkbLtLDu86FoqvPYptAsmFZV70w6BhKR0AogUwsJIgSfSv5XOJPtmai5ULx2OICzAfFudiXMV0gGEE98lT6ZrGYuYCVwwvpv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LrZVY642EL38zTb/3ExaCO7XG//gfflo2/TFsBSdBmk/uthGKnAp2HY8ixL0hlXmGrT3WZV8=; 20:GwG7jdAYJs5F/YTMaCdiL2Zpu7B6EpGQHE0+PJlDvmV2wn1i1vad8APvYyW5ihc4pKGYdA04FoNsauTmeX2I63z9rYKnVNgouWbSgJsvrko5BT+qkWWjjUs9xQb15sIbe9FyrNdM1T3R/rO/tGtSN/S4ZC3Xs5NgYrVVfu4EgmP1vgY6jr11HuPmw/JNdUujFO/FNXUxEiaMTLZui3QBPq6mV9MBLF0wISlkM4PhwVk20PmTywnIAXl7n60VKkC8 SpamDiagnosticOutput: 1:23 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: sandisk.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Dec 2015 11:39:43.4469 (UTC) X-MS-Exchange-CrossTenant-Id: fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=fcd9ea9c-ae8c-460c-ab3c-3db42d7ac64d; Ip=[63.163.107.173]; Helo=[milsmgep12.sandisk.com] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR02MB289 Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Move the code for rounding down a sector into a new function. Signed-off-by: Bart Van Assche Cc: Jan Kara Cc: Christoph Hellwig Cc: Mike Snitzer Cc: Martin K. Petersen Cc: Dmitry Monakhov Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 9ebf653..2f4c6b2 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -26,6 +26,26 @@ static void bio_batch_end_io(struct bio *bio) bio_put(bio); } +/* + * Return the largest number that is less than or equal to @s and for which + * the remainder of the division by @granularity is @alignment. + */ +static sector_t blk_round_sect_down(sector_t s, u32 granularity, u32 alignment) +{ + sector_t tmp = s, res = s; + u32 remainder; + + WARN_ON_ONCE(alignment >= granularity); + + remainder = sector_div(tmp, granularity); + if (remainder == alignment) + return res; + res -= remainder - alignment; + if (remainder < alignment) + res -= granularity; + return min(res, s); +} + /** * blkdev_issue_discard - queue a discard * @bdev: blockdev to issue discard for @@ -73,7 +93,7 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, blk_start_plug(&plug); while (nr_sects) { unsigned int req_sects; - sector_t end_sect, tmp; + sector_t end_sect; bio = bio_alloc(gfp_mask, 1); if (!bio) { @@ -89,12 +109,10 @@ int blkdev_issue_discard(struct block_device *bdev, sector_t sector, * misaligned, stop the discard at the previous aligned sector. */ end_sect = sector + req_sects; - tmp = end_sect; - if (req_sects < nr_sects && - sector_div(tmp, granularity) != alignment) { - end_sect = end_sect - alignment; - sector_div(end_sect, granularity); - end_sect = end_sect * granularity + alignment; + if (req_sects < nr_sects) { + end_sect = blk_round_sect_down(end_sect, granularity, + alignment); + WARN_ON_ONCE(end_sect < sector); req_sects = end_sect - sector; }