From nobody Sat Nov 30 10:55:08 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass header.i=@wdc.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1611817938; cv=none; d=zohomail.com; s=zohoarc; b=nfF4OsBkNZ9UnDdcsk81vdZi/L3P7kKH6RkWcocQnCO4Fypa5dGWIFdhsfeeewuQziR9HMV6OXfAmsNcIc2QKsRDwTHD0RhP8pA+7D91x7tQaVQfzDo9o10TKq7BFzW5QKlRYImxJvw3+gn473InFi6gorT7n55aiiKAkL4NdjI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1611817938; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Osa3OeB+wO5I32f1up39QExl1/Rnv3M1puyTJjwYMBY=; b=doMuvAWbsAOURh9KKiDQmiR6UQjAYV8T6lAMpj5BHfpqPhGUuOMd/MmIvjqQKn6z75lSnJ5Ftl4944OejocJgLBz10fZehpN1epNz1F6BnrMnQE+TQU7rz27GG3YitTwh0AUJJng0wgKVFjjk2ehEZFsdXnfE95307Ev99fuPoA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=@wdc.com; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1611817938469251.6140702240449; Wed, 27 Jan 2021 23:12:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.76569.138191 (Exim 4.92) (envelope-from ) id 1l51T5-0003OJ-Pd; Thu, 28 Jan 2021 07:11:51 +0000 Received: by outflank-mailman (output) from mailman id 76569.138191; Thu, 28 Jan 2021 07:11:51 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l51T5-0003OB-MH; Thu, 28 Jan 2021 07:11:51 +0000 Received: by outflank-mailman (input) for mailman id 76569; Thu, 28 Jan 2021 07:11:50 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1l51T4-0003No-KE for xen-devel@lists.xenproject.org; Thu, 28 Jan 2021 07:11:50 +0000 Received: from esa3.hgst.iphmx.com (unknown [216.71.153.141]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id cd66f260-13a4-4693-b98f-d42b9279e01c; Thu, 28 Jan 2021 07:11:48 +0000 (UTC) Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 28 Jan 2021 15:11:47 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Jan 2021 22:56:07 -0800 Received: from vm.labspan.wdc.com (HELO vm.sc.wdc.com) ([10.6.137.102]) by uls-op-cesaip02.wdc.com with ESMTP; 27 Jan 2021 23:11:46 -0800 X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: cd66f260-13a4-4693-b98f-d42b9279e01c DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1611817908; x=1643353908; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=eWet3+GOqUNRw+dCyihtl3LTOeV3gTTJDd7Ea4w+clg=; b=iMqWOGYFcU/z4lo7PoOXYZTsAbxO7VKfU3WDTRM+XIro0cg2PZ+UoR0O zOdKL9nsRm6UChk8kvAImXLNrXJuxtg9dlr6ojpj8kID5TkhQqGaQom60 wg25bVcYzhDP0hWBoVNCOqFXxW6GTSHb0yNNXD5+gv5Wkm+LjrW6aYuGx 08xgPmCTvnNHJwhyhDcKS8dTurEhHbjHm85Thosp/DiIXf16omtWeRAg7 NNXUdRg9wKKx0J20ty0i+us+O+79Fvluj55eIdqfCHHNcmbDTN+WC/O/r Pw/Nru94ujijYu/STDWWO3smL5bQcTvzOlXUigAN7uyuGXjOLbWYdODyP Q==; IronPort-SDR: Cg0YySq52S1BuYvbYJA5tV8RN60kOfaJ8QXPIarU8RJmGG3ZSm/zgGgxYXimAfRAR57BaBhNGr eklxNYueuhkztz/2Y53pIGN8qULIrhRgLGXXMPGlwjENBeiZpicXu9PleRFAF5EDK5xsI6HFFu 8TG9KKCq/uYMXasbYK6QEKHI3/w6UReRb5bl4JJboF1ixvE3MVGP9ojTuASPW1PjQGHXqKIKNq TFF0e9aMJlt2AjHUKWh6Hr/xiC6D1AVKrOgP2fTJxoUyl6aj5HEI46V+2is+atUd3Q0NGhKsAA I08= X-IronPort-AV: E=Sophos;i="5.79,381,1602518400"; d="scan'208";a="162963089" IronPort-SDR: CQ3xngbmWgBCY128PrOjv3YPIhdzR5/rdx7EQv1x+b0HTwFN4ltwdNFQv5FvA1TbS4ULFawWPm kwT2sibF6IG3KiSh+LGFEWCNi2B/00GnBOk4cp/TDLePP49TiHQd8DgSijwnSZiTydgmYgLvYS KcLPasadLharbWJpg07S5Ezzl0RrLkJ3twr/qU043n8xTi/DMptOxbb20eNEECbQEOlfBU4uWd 7NoP/Y4QBbrDoXvqexuZ776uaQPac/TQHhI3PEFF9dMqayERupQaa+CULj8SgwqQ46dfOiCsy0 jENBUexABXv5dcxgCfqU2R3T IronPort-SDR: UO027L+w2LmrSv+r4jHc7V6MfhclxochZ4q/gKoOnHb/alTZT7F9/4KjZrNCZAKJPJHjEl8zjQ btfDHq8ntGB6arYkxikoGObA79gqCi3nJZAFBbpTjKtHzOWqNheZit1SHeKrnOkOlZqda10wHA lKzVa+peWlZiSXNoZnitf2s3YH424/Lf6Od0Q5TvGZLxtIxoLSsxIGie29rcLN/atLab1ULG9S UmjXPLLRWItiporouoLkwAzUh8fELyClcBeyT3S1PWdOuFAmZ6ShYxhRystXSbBeBsPW0LixEL geY= WDCIronportException: Internal From: Chaitanya Kulkarni To: linux-xfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, dm-devel@redhat.com, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, drbd-dev@lists.linbit.com, xen-devel@lists.xenproject.org, linux-nvme@lists.infradead.org, linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-fscrypt@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-nilfs@vger.kernel.org, ocfs2-devel@oss.oracle.com, linux-pm@vger.kernel.org, linux-mm@kvack.org Cc: axboe@kernel.dk, philipp.reisner@linbit.com, lars.ellenberg@linbit.com, konrad.wilk@oracle.com, roger.pau@citrix.com, minchan@kernel.org, ngupta@vflare.org, sergey.senozhatsky.work@gmail.com, agk@redhat.com, snitzer@redhat.com, hch@lst.de, sagi@grimberg.me, chaitanya.kulkarni@wdc.com, martin.petersen@oracle.com, viro@zeniv.linux.org.uk, tytso@mit.edu, jaegeuk@kernel.org, ebiggers@kernel.org, djwong@kernel.org, shaggy@kernel.org, konishi.ryusuke@gmail.com, mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com, damien.lemoal@wdc.com, naohiro.aota@wdc.com, jth@kernel.org, rjw@rjwysocki.net, len.brown@intel.com, pavel@ucw.cz, akpm@linux-foundation.org, hare@suse.de, gustavoars@kernel.org, tiwai@suse.de, alex.shi@linux.alibaba.com, asml.silence@gmail.com, ming.lei@redhat.com, tj@kernel.org, osandov@fb.com, bvanassche@acm.org, jefflexu@linux.alibaba.com Subject: [RFC PATCH 01/34] block: move common code into blk_next_bio() Date: Wed, 27 Jan 2021 23:11:00 -0800 Message-Id: <20210128071133.60335-2-chaitanya.kulkarni@wdc.com> X-Mailer: git-send-email 2.22.1 In-Reply-To: <20210128071133.60335-1-chaitanya.kulkarni@wdc.com> References: <20210128071133.60335-1-chaitanya.kulkarni@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @wdc.com) Content-Type: text/plain; charset="utf-8" blk_next_bio() is the central function which allocates the bios for discard, write-same, write-zeroes and zone-mgmt. The initialization of various bio members is duplicated in disacrd, write-same, write-zeores. In this preparation patch we add bdev, sector, op, and opf arguments to the blk_next_bio() to reduce the duplication.=20 In the next patch we introduce bio_new(), this prepration patch allows us to call it inside blk_next_bio(). Signed-off-by: Chaitanya Kulkarni --- block/blk-lib.c | 36 +++++++++++++++--------------------- block/blk-zoned.c | 4 +--- block/blk.h | 5 +++-- 3 files changed, 19 insertions(+), 26 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 752f9c722062..fb486a0bdb58 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -10,7 +10,9 @@ =20 #include "blk.h" =20 -struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp) +struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev, + sector_t sect, unsigned op, unsigned opf, + unsigned int nr_pages, gfp_t gfp) { struct bio *new =3D bio_alloc(gfp, nr_pages); =20 @@ -19,6 +21,10 @@ struct bio *blk_next_bio(struct bio *bio, unsigned int n= r_pages, gfp_t gfp) submit_bio(bio); } =20 + new->bi_iter.bi_sector =3D sect; + bio_set_dev(new, bdev); + bio_set_op_attrs(new, op, opf); + return new; } =20 @@ -94,11 +100,7 @@ int __blkdev_issue_discard(struct block_device *bdev, s= ector_t sector, =20 WARN_ON_ONCE((req_sects << 9) > UINT_MAX); =20 - bio =3D blk_next_bio(bio, 0, gfp_mask); - bio->bi_iter.bi_sector =3D sector; - bio_set_dev(bio, bdev); - bio_set_op_attrs(bio, op, 0); - + bio =3D blk_next_bio(bio, bdev, sector, op, 0, 0, gfp_mask); bio->bi_iter.bi_size =3D req_sects << 9; sector +=3D req_sects; nr_sects -=3D req_sects; @@ -168,6 +170,7 @@ static int __blkdev_issue_write_same(struct block_devic= e *bdev, sector_t sector, { struct request_queue *q =3D bdev_get_queue(bdev); unsigned int max_write_same_sectors; + unsigned int op =3D REQ_OP_WRITE_SAME; struct bio *bio =3D *biop; sector_t bs_mask; =20 @@ -188,14 +191,11 @@ static int __blkdev_issue_write_same(struct block_dev= ice *bdev, sector_t sector, max_write_same_sectors =3D bio_allowed_max_sectors(q); =20 while (nr_sects) { - bio =3D blk_next_bio(bio, 1, gfp_mask); - bio->bi_iter.bi_sector =3D sector; - bio_set_dev(bio, bdev); + bio =3D blk_next_bio(bio, bdev, sector, op, 0, 1, gfp_mask); bio->bi_vcnt =3D 1; bio->bi_io_vec->bv_page =3D page; bio->bi_io_vec->bv_offset =3D 0; bio->bi_io_vec->bv_len =3D bdev_logical_block_size(bdev); - bio_set_op_attrs(bio, REQ_OP_WRITE_SAME, 0); =20 if (nr_sects > max_write_same_sectors) { bio->bi_iter.bi_size =3D max_write_same_sectors << 9; @@ -249,7 +249,9 @@ static int __blkdev_issue_write_zeroes(struct block_dev= ice *bdev, { struct bio *bio =3D *biop; unsigned int max_write_zeroes_sectors; + unsigned int op =3D REQ_OP_WRITE_ZEROES; struct request_queue *q =3D bdev_get_queue(bdev); + unsigned int opf =3D flags & BLKDEV_ZERO_NOUNMAP ? REQ_NOUNMAP : 0; =20 if (!q) return -ENXIO; @@ -264,13 +266,7 @@ static int __blkdev_issue_write_zeroes(struct block_de= vice *bdev, return -EOPNOTSUPP; =20 while (nr_sects) { - bio =3D blk_next_bio(bio, 0, gfp_mask); - bio->bi_iter.bi_sector =3D sector; - bio_set_dev(bio, bdev); - bio->bi_opf =3D REQ_OP_WRITE_ZEROES; - if (flags & BLKDEV_ZERO_NOUNMAP) - bio->bi_opf |=3D REQ_NOUNMAP; - + bio =3D blk_next_bio(bio, bdev, sector, op, opf, 0, gfp_mask); if (nr_sects > max_write_zeroes_sectors) { bio->bi_iter.bi_size =3D max_write_zeroes_sectors << 9; nr_sects -=3D max_write_zeroes_sectors; @@ -303,6 +299,7 @@ static int __blkdev_issue_zero_pages(struct block_devic= e *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) { + unsigned int nr_pages =3D __blkdev_sectors_to_bio_pages(nr_sects); struct request_queue *q =3D bdev_get_queue(bdev); struct bio *bio =3D *biop; int bi_size =3D 0; @@ -315,11 +312,8 @@ static int __blkdev_issue_zero_pages(struct block_devi= ce *bdev, return -EPERM; =20 while (nr_sects !=3D 0) { - bio =3D blk_next_bio(bio, __blkdev_sectors_to_bio_pages(nr_sects), + bio =3D blk_next_bio(bio, bdev, sector, REQ_OP_WRITE, 0, nr_pages, gfp_mask); - bio->bi_iter.bi_sector =3D sector; - bio_set_dev(bio, bdev); - bio_set_op_attrs(bio, REQ_OP_WRITE, 0); =20 while (nr_sects !=3D 0) { sz =3D min((sector_t) PAGE_SIZE, nr_sects << 9); diff --git a/block/blk-zoned.c b/block/blk-zoned.c index 7a68b6e4300c..68e77628348d 100644 --- a/block/blk-zoned.c +++ b/block/blk-zoned.c @@ -231,8 +231,7 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum re= q_opf op, return -EINVAL; =20 while (sector < end_sector) { - bio =3D blk_next_bio(bio, 0, gfp_mask); - bio_set_dev(bio, bdev); + bio =3D blk_next_bio(bio, bdev, 0 , op, REQ_SYNC, 0, gfp_mask); =20 /* * Special case for the zone reset operation that reset all @@ -244,7 +243,6 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum re= q_opf op, break; } =20 - bio->bi_opf =3D op | REQ_SYNC; bio->bi_iter.bi_sector =3D sector; sector +=3D zone_sectors; =20 diff --git a/block/blk.h b/block/blk.h index 0198335c5838..0a278bae5478 100644 --- a/block/blk.h +++ b/block/blk.h @@ -329,8 +329,9 @@ extern int blk_iolatency_init(struct request_queue *q); static inline int blk_iolatency_init(struct request_queue *q) { return 0; } #endif =20 -struct bio *blk_next_bio(struct bio *bio, unsigned int nr_pages, gfp_t gfp= ); - +struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev, + sector_t sect, unsigned op, unsigned opf, + unsigned int nr_pages, gfp_t gfp); #ifdef CONFIG_BLK_DEV_ZONED void blk_queue_free_zone_bitmaps(struct request_queue *q); #else --=20 2.22.1