From patchwork Wed Oct 4 15:03:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilya Dryomov X-Patchwork-Id: 9984873 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 F0EC160291 for ; Wed, 4 Oct 2017 15:03:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1DDA28B13 for ; Wed, 4 Oct 2017 15:03:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D6AEF28B18; Wed, 4 Oct 2017 15:03:30 +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 78D8928B13 for ; Wed, 4 Oct 2017 15:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752451AbdJDPD3 (ORCPT ); Wed, 4 Oct 2017 11:03:29 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:50767 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752203AbdJDPD3 (ORCPT ); Wed, 4 Oct 2017 11:03:29 -0400 Received: by mail-wm0-f68.google.com with SMTP id u138so23387289wmu.5 for ; Wed, 04 Oct 2017 08:03:28 -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=V0InMzPymh42HDXc8Tx1qo5171Vb3LU6Xq/NOmA+fmQ=; b=NIDSOMAk1Ad98hDyWkDh90KOAnoRLDqFyBePM8B5zv51fMdkG9DQ3gTOwEfAgo8hfp stu73PMFGwylDonmOZAWwpL70JrqcMmIY4AGmqnsYsl9h0eM3UfNpQfl57DBKAoFx/Q6 Ih3uHfQeUuSgDfi8DEM0PLhUk+bkPprvyCDvxaumubpc2ys1FeSjGsXGIOOXKkEZSyo2 fmMk3kZW2VEzTfcCr75w2wWElHr+GdOQapv9yDFEtYCsodSx6/jLFsKT6cg5NAPcEWZB RSzlGgK4TrGRq8vEQBmAH3h4vCizb1CHT+qpcpER5gykWDfL5IU4bAGVHYShIJ1rVdI9 eAWQ== 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=V0InMzPymh42HDXc8Tx1qo5171Vb3LU6Xq/NOmA+fmQ=; b=Ic2rGgaqCs9wNJwnaNZ+XnHCb0kbkqutFp0erNpWkR7Nl93VOHvnU43W8TfMhU98VN KNw5+wJjl5ev/Huv9/DW/qccZQ2tZDsbi2gU4bHLnQKE3Ibs3MAvFMEid2V/5As//In/ FF4lnPVg9FxFSxDIzL9gJYA6GT9cre76LqFWOKHfSYqy7bqp43M1ErJyK+8boJNgNIZE /YiwsxZFeeLxiAaUxvuvCeI/EpRdC0n/A6SjeOSJeNyTdh3iQJWbKyQH8TdTBbsW7HgY EvhiFlyHdluzIwTk1APrSWEB22gL9W7YzUMy6Td65bq8p1Rembf215PAw9F/OhDzsx+D txDQ== X-Gm-Message-State: AMCzsaUFrBpbKL1i+llaq0ErCrh18C/1osfLUI8KkZwnynlaqtlCEd1x eUWJUgDCVQ8lUThFKGP3vEo= X-Google-Smtp-Source: AOwi7QBP/pMOD6dSQKiMxakieyPUj5t6YiNYRBzjsKqVHcWp77TGQeY9ritt2hzsN8jkLgKGn5HE4A== X-Received: by 10.28.145.72 with SMTP id t69mr16652867wmd.113.1507129408130; Wed, 04 Oct 2017 08:03:28 -0700 (PDT) Received: from orange.brq.redhat.com. (nat-pool-brq-t.redhat.com. [213.175.37.10]) by smtp.gmail.com with ESMTPSA id r1sm9620808wrr.56.2017.10.04.08.03.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 04 Oct 2017 08:03:27 -0700 (PDT) From: Ilya Dryomov To: Christoph Hellwig Cc: "Martin K. Petersen" , Hannes Reinecke , Jens Axboe , linux-block@vger.kernel.org Subject: [PATCH v2 1/2] block: factor out __blkdev_issue_zero_pages() Date: Wed, 4 Oct 2017 17:03:15 +0200 Message-Id: <1507129396-20458-2-git-send-email-idryomov@gmail.com> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1507129396-20458-1-git-send-email-idryomov@gmail.com> References: <1507129396-20458-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 | 63 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 62240f8832ca..9d2ab8bba52a 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -274,6 +274,40 @@ static unsigned int __blkdev_sectors_to_bio_pages(sector_t nr_sects) return min(pages, (sector_t)BIO_MAX_PAGES); } +static int __blkdev_issue_zero_pages(struct block_device *bdev, + sector_t sector, sector_t nr_sects, gfp_t gfp_mask, + struct bio **biop) +{ + struct request_queue *q = bdev_get_queue(bdev); + struct bio *bio = *biop; + int bi_size = 0; + unsigned int sz; + + if (!q) + return -ENXIO; + + 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; + return 0; +} + /** * __blkdev_issue_zeroout - generate number of zero filed write bios * @bdev: blockdev to issue @@ -304,9 +338,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 +347,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; + return __blkdev_issue_zero_pages(bdev, sector, nr_sects, gfp_mask, + biop); } EXPORT_SYMBOL(__blkdev_issue_zeroout);