* [PATCH 0/1] block: move sector bio member into blk_next_bio()
@ 2022-03-01 2:23 Chaitanya Kulkarni
2022-03-01 2:23 ` [PATCH 1/1] " Chaitanya Kulkarni
0 siblings, 1 reply; 4+ messages in thread
From: Chaitanya Kulkarni @ 2022-03-01 2:23 UTC (permalink / raw)
To: linux-block, linux-nvme
Cc: damien.lemoal, axboe, hch, sagi, Chaitanya Kulkarni
Hi,
blk_next_bio() is the central function which allocates bios for
discard, write-same, write-zeroes and zone-mgmt. The initialization of
sector bio member is duplicated in disacrd, write-same, write-zeores
etc. Move sector member to the blk_next_bio() just like we have moved
other members to blk_next_bio().
-ck
Chaitanya Kulkarni (1):
block: move sector bio member into blk_next_bio()
block/bio.c | 5 ++++-
block/blk-lib.c | 20 +++++++++-----------
block/blk-zoned.c | 9 ++++-----
drivers/nvme/target/zns.c | 3 +--
include/linux/bio.h | 3 ++-
5 files changed, 20 insertions(+), 20 deletions(-)
dev linux-block-broken (for-next) # sh test-discard-wz.sh
+ git diff block drivers/block/null_blk
diff --git a/block/blk-lib.c b/block/blk-lib.c
index 3407b1afc079..afb2d471bbe7 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -79,6 +79,8 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
WARN_ON_ONCE((req_sects << 9) > UINT_MAX);
+ pr_info("%s %d sector %llu nr_sects %llu\n",
+ __func__, __LINE__, sector, nr_sects);
bio = blk_next_bio(bio, bdev, sector, 0, op, gfp_mask);
bio->bi_iter.bi_size = req_sects << 9;
sector += req_sects;
@@ -166,6 +168,8 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
max_write_same_sectors = bio_allowed_max_sectors(q);
while (nr_sects) {
+ pr_info("%s %d sector %llu nr_sects %llu\n",
+ __func__, __LINE__, sector, nr_sects);
bio = blk_next_bio(bio, bdev, sector, 1, REQ_OP_WRITE_SAME,
gfp_mask);
bio->bi_vcnt = 1;
@@ -238,6 +242,8 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
return -EOPNOTSUPP;
while (nr_sects) {
+ pr_info("%s %d sector %llu nr_sects %llu\n",
+ __func__, __LINE__, sector, nr_sects);
bio = blk_next_bio(bio, bdev, sector, 0, op | opf, gfp_mask);
if (nr_sects > max_write_zeroes_sectors) {
@@ -281,6 +287,8 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
return -EPERM;
while (nr_sects != 0) {
+ pr_info("%s %d sector %llu nr_sects %llu\n",
+ __func__, __LINE__, sector, nr_sects);
bio = blk_next_bio(bio, bdev, sector, nr_pages, REQ_OP_WRITE,
gfp_mask);
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 0a8680df3f1c..78fca69b7b28 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -215,6 +215,8 @@ static int blkdev_zone_reset_all_emulated(struct block_device *bdev,
continue;
}
+ pr_info("%s %d sector %llu nr_sects 0\n",
+ __func__, __LINE__, sector);
bio = blk_next_bio(bio, bdev, sector, 0,
REQ_OP_ZONE_RESET | REQ_SYNC, gfp_mask);
sector += zone_sectors;
@@ -301,6 +303,8 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
}
while (sector < end_sector) {
+ pr_info("%s %d sector %llu nr_sects 0\n",
+ __func__, __LINE__, sector);
bio = blk_next_bio(bio, bdev, sector, 0, op | REQ_SYNC,
gfp_mask);
sector += zone_sectors;
diff --git a/drivers/block/null_blk/main.c b/drivers/block/null_blk/main.c
index 05b1120e6623..9f7be46c6549 100644
--- a/drivers/block/null_blk/main.c
+++ b/drivers/block/null_blk/main.c
@@ -80,6 +80,12 @@ enum {
NULL_Q_MQ = 2,
};
+static bool g_write_zeroes = false;
+module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
+
+static bool g_reset_all = false;
+module_param_named(reset_all, g_reset_all, bool, 0444);
+
static bool g_virt_boundary = false;
module_param_named(virt_boundary, g_virt_boundary, bool, 0444);
MODULE_PARM_DESC(virt_boundary, "Require a virtual boundary for the device. Default: False");
@@ -656,6 +662,7 @@ static struct nullb_device *null_alloc_dev(void)
dev->zone_nr_conv = g_zone_nr_conv;
dev->zone_max_open = g_zone_max_open;
dev->zone_max_active = g_zone_max_active;
+ dev->reset_all = g_reset_all;
dev->virt_boundary = g_virt_boundary;
return dev;
}
@@ -1749,25 +1756,12 @@ static void null_del_dev(struct nullb *nullb)
static void null_config_discard(struct nullb *nullb)
{
- if (nullb->dev->discard == false)
- return;
-
- if (!nullb->dev->memory_backed) {
- nullb->dev->discard = false;
- pr_info("discard option is ignored without memory backing\n");
- return;
- }
-
- if (nullb->dev->zoned) {
- nullb->dev->discard = false;
- pr_info("discard option is ignored in zoned mode\n");
- return;
- }
-
nullb->q->limits.discard_granularity = nullb->dev->blocksize;
nullb->q->limits.discard_alignment = nullb->dev->blocksize;
blk_queue_max_discard_sectors(nullb->q, UINT_MAX >> 9);
blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
+ if (g_write_zeroes)
+ blk_queue_max_write_zeroes_sectors(nullb->q, UINT_MAX >> 9);
}
static const struct block_device_operations null_bio_ops = {
diff --git a/drivers/block/null_blk/null_blk.h b/drivers/block/null_blk/null_blk.h
index 78eb56b0ca55..619433f2d599 100644
--- a/drivers/block/null_blk/null_blk.h
+++ b/drivers/block/null_blk/null_blk.h
@@ -102,6 +102,7 @@ struct nullb_device {
bool power; /* power on/off the device */
bool memory_backed; /* if data is stored in memory */
bool discard; /* if support discard */
+ bool reset_all; /* if support reset_all */
bool zoned; /* if device is zoned */
bool virt_boundary; /* virtual boundary on/off for the device */
};
diff --git a/drivers/block/null_blk/zoned.c b/drivers/block/null_blk/zoned.c
index dae54dd1aeac..7ed032e43131 100644
--- a/drivers/block/null_blk/zoned.c
+++ b/drivers/block/null_blk/zoned.c
@@ -157,7 +157,8 @@ int null_register_zoned_dev(struct nullb *nullb)
struct request_queue *q = nullb->q;
blk_queue_set_zoned(nullb->disk, BLK_ZONED_HM);
- blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
+ if (dev->reset_all)
+ blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE);
if (queue_is_mq(q)) {
+ modprobe -r null_blk
+ modprobe null_blk
+ blkdiscard -o 0 -l 40960 /dev/nullb0
+ blkdiscard -o 1024 -l 10240 /dev/nullb0
+ dmesg -c
[21846.094314] null_blk: module loaded
[21846.097714] __blkdev_issue_discard 82 sector 0 nr_sects 80
[21846.100089] __blkdev_issue_discard 82 sector 2 nr_sects 20
+ blkdiscard -z -o 0 -l 40960 /dev/nullb0
+ blkdiscard -z -o 1024 -l 10240 /dev/nullb0
+ dmesg -c
[21846.104408] __blkdev_issue_zero_pages 290 sector 0 nr_sects 80
[21846.106771] __blkdev_issue_zero_pages 290 sector 2 nr_sects 20
+ modprobe -r null_blk
+ modprobe null_blk write_zeroes=1
+ blkdiscard -z -o 0 -l 40960 /dev/nullb0
+ blkdiscard -z -o 1024 -l 10240 /dev/nullb0
+ dmesg -c
[21846.144751] null_blk: module loaded
[21846.147315] __blkdev_issue_write_zeroes 245 sector 0 nr_sects 80
[21846.149549] __blkdev_issue_write_zeroes 245 sector 2 nr_sects 20
+ modprobe -r null_blk
+ modprobe null_blk zoned=1 gb=1 zone_size=128
+ dd if=/dev/zero of=/dev/nullb0 bs=4k oflag=direct
dd: error writing '/dev/nullb0': No space left on device
262145+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 5.17173 s, 208 MB/s
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000180000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0001c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*7)/512'
++ bc
+ offset=1835008
+ blkzone reset -o 1835008 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000180000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*6)/512'
++ bc
+ offset=1572864
+ blkzone reset -o 1572864 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*5)/512'
++ bc
+ offset=1310720
+ blkzone reset -o 1310720 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*4)/512'
++ bc
+ offset=1048576
+ blkzone reset -o 1048576 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*3)/512'
++ bc
+ offset=786432
+ blkzone reset -o 786432 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*2)/512'
++ bc
+ offset=524288
+ blkzone reset -o 524288 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*1)/512'
++ bc
+ offset=262144
+ blkzone reset -o 262144 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ for i in 7 6 5 4 3 2 1 0
++ echo '(134217728*0)/512'
++ bc
+ offset=0
+ blkzone reset -o 0 -l 262144 /dev/nullb0
+ echo -----------------------------------------
-----------------------------------------
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000040000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ dmesg -c
[21846.186170] null_blk: module loaded
[21851.363766] blkdev_zone_mgmt 306 sector 1835008 nr_sects 0
[21851.368268] blkdev_zone_mgmt 306 sector 1572864 nr_sects 0
[21851.372565] blkdev_zone_mgmt 306 sector 1310720 nr_sects 0
[21851.377126] blkdev_zone_mgmt 306 sector 1048576 nr_sects 0
[21851.381438] blkdev_zone_mgmt 306 sector 786432 nr_sects 0
[21851.385542] blkdev_zone_mgmt 306 sector 524288 nr_sects 0
[21851.389727] blkdev_zone_mgmt 306 sector 262144 nr_sects 0
[21851.394340] blkdev_zone_mgmt 306 sector 0 nr_sects 0
+ echo ---------------------------------------------------
---------------------------------------------------
+ modprobe -r null_blk
+ modprobe null_blk zoned=1 gb=1 zone_size=128 reset_all=0
+ dd if=/dev/zero of=/dev/nullb0 bs=4k oflag=direct
dd: error writing '/dev/nullb0': No space left on device
262145+0 records in
262144+0 records out
1073741824 bytes (1.1 GB, 1.0 GiB) copied, 5.12941 s, 209 MB/s
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000040000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000080000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0000c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000100000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000140000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x000180000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
start: 0x0001c0000, len 0x040000, wptr 0x040000 reset:0 non-seq:0, zcond:14(fu)
+ blkzone reset /dev/nullb0
+ blkzone report /dev/nullb0
start: 0x000000000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000040000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000080000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0000c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000100000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000140000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x000180000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
start: 0x0001c0000, len 0x040000, wptr 0x000000 reset:0 non-seq:0, zcond: 1(em)
+ modprobe -r null_blk
+ rm -fr /dev/nullb0
+ dmesg -c
[21851.434632] null_blk: module loaded
[21856.567436] blkdev_zone_reset_all_emulated 218 sector 0 nr_sects 0
[21856.567441] blkdev_zone_reset_all_emulated 218 sector 262144 nr_sects 0
[21856.567449] blkdev_zone_reset_all_emulated 218 sector 524288 nr_sects 0
[21856.567451] blkdev_zone_reset_all_emulated 218 sector 786432 nr_sects 0
[21856.567452] blkdev_zone_reset_all_emulated 218 sector 1048576 nr_sects 0
[21856.567454] blkdev_zone_reset_all_emulated 218 sector 1310720 nr_sects 0
[21856.567455] blkdev_zone_reset_all_emulated 218 sector 1572864 nr_sects 0
[21856.567459] blkdev_zone_reset_all_emulated 218 sector 1835008 nr_sects 0
+ set +x
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 1/1] block: move sector bio member into blk_next_bio()
2022-03-01 2:23 [PATCH 0/1] block: move sector bio member into blk_next_bio() Chaitanya Kulkarni
@ 2022-03-01 2:23 ` Chaitanya Kulkarni
2022-03-01 11:25 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Chaitanya Kulkarni @ 2022-03-01 2:23 UTC (permalink / raw)
To: linux-block, linux-nvme
Cc: damien.lemoal, axboe, hch, sagi, Chaitanya Kulkarni
blk_next_bio() is the central function which allocates bios for
e.g. discard, write-same, write-zeroes, zone-mgmt and initializes
common members of bios to avoid code duplication. The initialization of
sector bio member is duplicated in disacrd, write-same, write-zeores,
and NVMeOF Target zns backend etc.
The callers of the blk_next_bio() __blkdev_issue_discard(),
__blkdev_issue_write_same(), __blkdev_issue_write_zeroes(),
__blkdev_issue_zero_pages(), blkdev_zone_reset_all_emulated(),
blkdev_zone_mgmt() and nvmet_bdev_zone_mgmt_emulated_all() initialize
bio->bi_iter.bi_sector after the call to blk_next_bio(), so we can
safely move newly returned bio's sector initialization into the
blk_next_bio().
Move sector member to the blk_next_bio() just like we have moved other
members to blk_next_bio().
Signed-off-by: Chaitanya Kulkarni <kch@nvidia.com>
---
block/bio.c | 5 ++++-
block/blk-lib.c | 20 +++++++++-----------
block/blk-zoned.c | 9 ++++-----
drivers/nvme/target/zns.c | 3 +--
include/linux/bio.h | 3 ++-
5 files changed, 20 insertions(+), 20 deletions(-)
diff --git a/block/bio.c b/block/bio.c
index b15f5466ce08..0a68091685ee 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -353,7 +353,8 @@ void bio_chain(struct bio *bio, struct bio *parent)
EXPORT_SYMBOL(bio_chain);
struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
- unsigned int nr_pages, unsigned int opf, gfp_t gfp)
+ sector_t sect, unsigned int nr_pages,
+ unsigned int opf, gfp_t gfp)
{
struct bio *new = bio_alloc(bdev, nr_pages, opf, gfp);
@@ -362,6 +363,8 @@ struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
submit_bio(bio);
}
+ new->bi_iter.bi_sector = sect;
+
return new;
}
EXPORT_SYMBOL_GPL(blk_next_bio);
diff --git a/block/blk-lib.c b/block/blk-lib.c
index fc6ea52e7482..3407b1afc079 100644
--- a/block/blk-lib.c
+++ b/block/blk-lib.c
@@ -79,8 +79,7 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
WARN_ON_ONCE((req_sects << 9) > UINT_MAX);
- bio = blk_next_bio(bio, bdev, 0, op, gfp_mask);
- bio->bi_iter.bi_sector = sector;
+ bio = blk_next_bio(bio, bdev, sector, 0, op, gfp_mask);
bio->bi_iter.bi_size = req_sects << 9;
sector += req_sects;
nr_sects -= req_sects;
@@ -167,8 +166,8 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
max_write_same_sectors = bio_allowed_max_sectors(q);
while (nr_sects) {
- bio = blk_next_bio(bio, bdev, 1, REQ_OP_WRITE_SAME, gfp_mask);
- bio->bi_iter.bi_sector = sector;
+ bio = blk_next_bio(bio, bdev, sector, 1, REQ_OP_WRITE_SAME,
+ gfp_mask);
bio->bi_vcnt = 1;
bio->bi_io_vec->bv_page = page;
bio->bi_io_vec->bv_offset = 0;
@@ -224,6 +223,8 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
struct bio **biop, unsigned flags)
{
+ unsigned int opf = flags & BLKDEV_ZERO_NOUNMAP ? REQ_NOUNMAP : 0;
+ unsigned int op = REQ_OP_WRITE_ZEROES;
struct bio *bio = *biop;
unsigned int max_write_zeroes_sectors;
@@ -237,10 +238,7 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
return -EOPNOTSUPP;
while (nr_sects) {
- bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask);
- bio->bi_iter.bi_sector = sector;
- if (flags & BLKDEV_ZERO_NOUNMAP)
- bio->bi_opf |= REQ_NOUNMAP;
+ bio = blk_next_bio(bio, bdev, sector, 0, op | opf, gfp_mask);
if (nr_sects > max_write_zeroes_sectors) {
bio->bi_iter.bi_size = max_write_zeroes_sectors << 9;
@@ -274,6 +272,7 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
sector_t sector, sector_t nr_sects, gfp_t gfp_mask,
struct bio **biop)
{
+ unsigned int nr_pages = __blkdev_sectors_to_bio_pages(nr_sects);
struct bio *bio = *biop;
int bi_size = 0;
unsigned int sz;
@@ -282,9 +281,8 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev,
return -EPERM;
while (nr_sects != 0) {
- bio = blk_next_bio(bio, bdev, __blkdev_sectors_to_bio_pages(nr_sects),
- REQ_OP_WRITE, gfp_mask);
- bio->bi_iter.bi_sector = sector;
+ bio = blk_next_bio(bio, bdev, sector, nr_pages, REQ_OP_WRITE,
+ gfp_mask);
while (nr_sects != 0) {
sz = min((sector_t) PAGE_SIZE, nr_sects << 9);
diff --git a/block/blk-zoned.c b/block/blk-zoned.c
index 602bef54c813..0a8680df3f1c 100644
--- a/block/blk-zoned.c
+++ b/block/blk-zoned.c
@@ -215,9 +215,8 @@ static int blkdev_zone_reset_all_emulated(struct block_device *bdev,
continue;
}
- bio = blk_next_bio(bio, bdev, 0, REQ_OP_ZONE_RESET | REQ_SYNC,
- gfp_mask);
- bio->bi_iter.bi_sector = sector;
+ bio = blk_next_bio(bio, bdev, sector, 0,
+ REQ_OP_ZONE_RESET | REQ_SYNC, gfp_mask);
sector += zone_sectors;
/* This may take a while, so be nice to others */
@@ -302,8 +301,8 @@ int blkdev_zone_mgmt(struct block_device *bdev, enum req_opf op,
}
while (sector < end_sector) {
- bio = blk_next_bio(bio, bdev, 0, op | REQ_SYNC, gfp_mask);
- bio->bi_iter.bi_sector = sector;
+ bio = blk_next_bio(bio, bdev, sector, 0, op | REQ_SYNC,
+ gfp_mask);
sector += zone_sectors;
/* This may take a while, so be nice to others */
diff --git a/drivers/nvme/target/zns.c b/drivers/nvme/target/zns.c
index 3e421217a7ad..cb4ba3f3a95e 100644
--- a/drivers/nvme/target/zns.c
+++ b/drivers/nvme/target/zns.c
@@ -412,10 +412,9 @@ static u16 nvmet_bdev_zone_mgmt_emulate_all(struct nvmet_req *req)
while (sector < get_capacity(bdev->bd_disk)) {
if (test_bit(blk_queue_zone_no(q, sector), d.zbitmap)) {
- bio = blk_next_bio(bio, bdev, 0,
+ bio = blk_next_bio(bio, bdev, sector, 0,
zsa_req_op(req->cmd->zms.zsa) | REQ_SYNC,
GFP_KERNEL);
- bio->bi_iter.bi_sector = sector;
/* This may take a while, so be nice to others */
cond_resched();
}
diff --git a/include/linux/bio.h b/include/linux/bio.h
index 7523aba4ddf7..c34fd40c8867 100644
--- a/include/linux/bio.h
+++ b/include/linux/bio.h
@@ -788,6 +788,7 @@ static inline void bio_set_polled(struct bio *bio, struct kiocb *kiocb)
}
struct bio *blk_next_bio(struct bio *bio, struct block_device *bdev,
- unsigned int nr_pages, unsigned int opf, gfp_t gfp);
+ sector_t sect, unsigned int nr_pages,
+ unsigned int opf, gfp_t gfp);
#endif /* __LINUX_BIO_H */
--
2.29.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] block: move sector bio member into blk_next_bio()
2022-03-01 2:23 ` [PATCH 1/1] " Chaitanya Kulkarni
@ 2022-03-01 11:25 ` Christoph Hellwig
2022-03-08 23:19 ` Chaitanya Kulkarni
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2022-03-01 11:25 UTC (permalink / raw)
To: Chaitanya Kulkarni
Cc: linux-block, linux-nvme, damien.lemoal, axboe, hch, sagi
It would be nice to just calculate the sector from the previous
bio using bio_end_sector, but that doesn't really work with the
current blk_next_bio pattern. It might make sense to just take the
initial allocation case out of blk_next_bio and do that manually now
that the bio_alloc interface makes a lot more sense.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/1] block: move sector bio member into blk_next_bio()
2022-03-01 11:25 ` Christoph Hellwig
@ 2022-03-08 23:19 ` Chaitanya Kulkarni
0 siblings, 0 replies; 4+ messages in thread
From: Chaitanya Kulkarni @ 2022-03-08 23:19 UTC (permalink / raw)
To: Christoph Hellwig
Cc: linux-block, linux-nvme, damien.lemoal, axboe, sagi, Chaitanya Kulkarni
On 3/1/22 03:25, Christoph Hellwig wrote:
> It would be nice to just calculate the sector from the previous
> bio using bio_end_sector, but that doesn't really work with the
> current blk_next_bio pattern. It might make sense to just take the
> initial allocation case out of blk_next_bio and do that manually now
> that the bio_alloc interface makes a lot more sense.
>
I found existing pattern easier to read with blk_next_bio(),
as removal of blk_next_bio() will result in the duplication of code for
allocation which blk_next_bio() avoids, unless I didn't understand your
comment.
-ck
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-08 23:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-01 2:23 [PATCH 0/1] block: move sector bio member into blk_next_bio() Chaitanya Kulkarni
2022-03-01 2:23 ` [PATCH 1/1] " Chaitanya Kulkarni
2022-03-01 11:25 ` Christoph Hellwig
2022-03-08 23:19 ` Chaitanya Kulkarni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).