From patchwork Thu Sep 21 17:12:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9964517 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 F3BA96020C for ; Thu, 21 Sep 2017 17:13:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DBF4628A21 for ; Thu, 21 Sep 2017 17:13:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CEE7C29604; Thu, 21 Sep 2017 17:13:09 +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.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C79228A21 for ; Thu, 21 Sep 2017 17:13:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751922AbdIURNH (ORCPT ); Thu, 21 Sep 2017 13:13:07 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:34782 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751838AbdIURNF (ORCPT ); Thu, 21 Sep 2017 13:13:05 -0400 Received: by mail-wr0-f193.google.com with SMTP id k20so3469506wre.1 for ; Thu, 21 Sep 2017 10:13:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=73jHphiN70SXakjHulWmppIb67KFi8Kc7+sYMt5Zl4s=; b=jIInNwp7SIGVkD0Nm7SiMbXWl30UhyyE2NYhNqYQkCNDzniQQF3m+Zzx/9b8CKhW4K ifT9BOpWj8b9Ylx2zuobmGlRVvLdtYQwslwwQCZDLtyDiidUMXsk3nt53FNgpud5cuOy h8rAZJrTwepWXVC+SxHfY4b34CVN2L4ooT5b+y15X7i9dHIuHDAiuY5ze7PCieKK5aD8 TdJ4hqMrMJfu8B3uVbLkRe+toad2rpwY9AJWcFjG9M8+zSlQapSnRPgH4eeCyicHULwM Xq//Y/JXk2FFrkVx1jaU9LL7FjfltH10W3ZYee10SSjhNE8FbM/4TY9ux9XPUSXuc/pD dINw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=73jHphiN70SXakjHulWmppIb67KFi8Kc7+sYMt5Zl4s=; b=s/KTqC+81KvxQPS79Pa0ruM7f1XsOTgBCduvQ7OTqmYWXeXLKhu10xcif2Vne/Txie lt9hzS72ODYp5WS7bJ4v+xfnqkIeZxFUkgDlS9Wh3Znu5EVVBmukIKxn8ocBCx/2DnKV GUsZopPbIWMkOjmxrMp7SWfdA/jL/mQ3nm91PdfiRqPOg/frvvZAc0BUShWFHpIl8iAH Q4qyon2/8h1QKYD2rnaVK4lsrk5AZyAfycBG55vAMEZvTal8aaBNcDGtxp5ydPrW5c2x 5P/6LwNW1AeiyU7heAAIiz6aAh6v0V1/jMlLa8qNglsX/g2N+9RQezUncILSRHNlIipD Djwg== X-Gm-Message-State: AHPjjUhS6MjayDOb0cB4pQtZnJCL8ft8ZffBdh5ji/kvUuvPBQ9DGqCY gZOlNBrejfwftJQyV2Frqpc= X-Google-Smtp-Source: AOwi7QC2BYkTPWkpWX0WMkHhWMXbB/BQWuAg1q1ZTEgObMCRY4XV7sPRrIwAmBGpcXpEERPe74I/8g== X-Received: by 10.223.184.250 with SMTP id c55mr2465513wrg.134.1506013984359; Thu, 21 Sep 2017 10:13:04 -0700 (PDT) Received: from orange.redhat.com ([213.175.37.12]) by smtp.gmail.com with ESMTPSA id i13sm1083021wre.93.2017.09.21.10.13.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Sep 2017 10:13:03 -0700 (PDT) From: Ilya Dryomov To: Christoph Hellwig Cc: "Martin K. Petersen" , Hannes Reinecke , Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH 1/2] block: factor out __blkdev_issue_zero_pages() Date: Thu, 21 Sep 2017 19:12:51 +0200 Message-Id: <1506013972-23049-2-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1506013972-23049-1-git-send-email-idryomov@gmail.com> References: <1506013972-23049-1-git-send-email-idryomov@gmail.com> Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP blkdev_issue_zeroout() will use this in !BLKDEV_ZERO_NOFALLBACK case. Signed-off-by: Ilya Dryomov Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 58 +++++++++++++++++++++++++++++++-------------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 62240f8832ca..6b97feb71065 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -274,6 +274,35 @@ static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects) return min(pages, (sector_t)BIO_MAX_PAGES); } +static void __blkdev_issue_zero_pages(struct block_device *bdev, + sector_t sector, sector_t nr_sects, gfp_t gfp_mask, + struct bio **biop) +{ + struct bio *bio = *biop; + int bi_size = 0; + unsigned int sz; + + while (nr_sects != 0) { + bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), + gfp_mask); + bio->bi_iter.bi_sector = sector; + bio_set_dev(bio, bdev); + bio_set_op_attrs(bio, REQ_OP_WRITE, 0); + + while (nr_sects != 0) { + sz = min((sector_t) PAGE_SIZE, nr_sects << 9); + bi_size = bio_add_page(bio, ZERO_PAGE(0), sz, 0); + nr_sects -= bi_size >> 9; + sector += bi_size >> 9; + if (bi_size < sz) + break; + } + cond_resched(); + } + + *biop = bio; +} + /** * __blkdev_issue_zeroout - generate number of zero filed write bios * @bdev: blockdev to issue @@ -304,9 +333,6 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, unsigned flags) { int ret; - int bi_size = 0; - struct bio *bio = *biop; - unsigned int sz; sector_t bs_mask; bs_mask = (bdev_logical_block_size(bdev) >> 9) - 1; @@ -316,30 +342,10 @@ int __blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, ret = __blkdev_issue_write_zeroes(bdev, sector, nr_sects, gfp_mask, biop, flags); if (ret != -EOPNOTSUPP || (flags & BLKDEV_ZERO_NOFALLBACK)) - goto out; - - ret = 0; - while (nr_sects != 0) { - bio = next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), - gfp_mask); - bio->bi_iter.bi_sector = sector; - bio_set_dev(bio, bdev); - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); - - while (nr_sects != 0) { - sz = min((sector_t) PAGE_SIZE, nr_sects << 9); - bi_size = bio_add_page(bio, ZERO_PAGE(0), sz, 0); - nr_sects -= bi_size >> 9; - sector += bi_size >> 9; - if (bi_size < sz) - break; - } - cond_resched(); - } + return ret; - *biop = bio; -out: - return ret; + __blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp_mask, biop); + return 0; } EXPORT_SYMBOL(__blkdev_issue_zeroout);