Skip to contentSkip to conversation

blk-lib: cleanup bdev_get_queue()

PATCH Superseded Chaitanya Kulkarni 3 participants 7 messages Feb 14, 2022 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover blk-lib: cleanup bdev_get_queue()

Hi,

Based on the comment in the include/linux/blkdev.h:bdev_get_queue() the return value of the function will never be NULL. This patch series removes those checks present in the blk-lib.c, also removes the not needed local variable pointer to request_queue from the write_zeroes helpers.

Below is the test log for discard (__blkdev_issue_disacrd()) and write-zeroes (__blkdev_issue_write_zeroes/__blkdev_issue_zero_pages()).

-ck

Chaitanya Kulkarni (4):
blk-lib: don't check bdev_get_queue() NULL check
blk-lib: don't check bdev_get_queue() NULL check
blk-lib: don't check bdev_get_queue() NULL check
blk-lib: don't check bdev_get_queue() NULL check

 block/blk-lib.c | 14 --------------
 1 file changed, 14 deletions(-)

1. Execute discard (__blkdev_issue_disacrd()) and write-zeroes (__blkdev_issue_write_zeroes, __blkdev_issue_zero_pages())

root@dev linux-block (for-next) # sh test-discard-wz.sh
+ modprobe -r null_blk
+ modprobe null_blk
+ blkdiscard -o 0 -l 40960 /dev/nullb0
+ dmesg -c

[ 1749.411466] null_blk: module loaded

*[ 1749.425918] __blkdev_issue_discard 82 sector 0 nr_sects 80*
+ blkdiscard -z -o 0 -l 40960 /dev/nullb0
+ dmesg -c
*[ 1749.443746] __blkdev_issue_zero_pages 289 sector 0 nr_sects 80*
+ modprobe -r null_blk
+ modprobe null_blk write_zeroes=1
+ blkdiscard -z -o 0 -l 40960 /dev/nullb0
+ dmesg -c

[ 1749.532618] null_blk: module loaded

*[ 1749.542257] __blkdev_issue_write_zeroes 242 sector 0 nr_sects 80*
+ modprobe -r null_blk
+ set +x

2. Debug patch to test disacrd and write-zeroes on the null_blk:
root@dev linux-block (for-next) # git diff

block/blk-lib.c +6 -0
index fc6ea52e7482..a0e7891cae60 100644
@@ -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, 0, op, gfp_mask);
                bio->bi_iter.bi_sector = sector;
                bio->bi_iter.bi_size = req_sects << 9;
@@ -237,6 +239,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, 0, REQ_OP_WRITE_ZEROES, gfp_mask);
                bio->bi_iter.bi_sector = sector;
                if (flags & BLKDEV_ZERO_NOUNMAP)
@@ -282,6 +286,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, __blkdev_sectors_to_bio_pages(nr_sects),
                                   REQ_OP_WRITE, gfp_mask);
                bio->bi_iter.bi_sector = sector;
drivers/block/null_blk/main.c +5 -15
index 13004beb48ca..584ac0519c3e 100644
@@ -84,6 +84,9 @@ 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");
 
+static bool g_write_zeroes = false;
+module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
+
 static int g_no_sched;
 module_param_named(no_sched, g_no_sched, int, 0444);
 MODULE_PARM_DESC(no_sched, "No io scheduler");
@@ -1755,25 +1758,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);
 }
 
 
Signature · 1 line
2.29.0
#1 lore raw

PATCH 1/4 blk-lib: don't check bdev_get_queue() NULL check

Based on the comment present in the bdev_get_queue() bdev->bd_disk->queue can never be NULL. Remove the NULL check for the local variable q that is set from bdev_get_queue() in the function __blkdev_issue_discard().

---
 block/blk-lib.c | 3 ---
 1 file changed, 3 deletions(-)
block/blk-lib.c +0 -3
index 9f09beadcbe3..08ac56eb3a70 100644
@@ -32,9 +32,6 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector,
 	unsigned int op;
 	sector_t bs_mask, part_offset = 0;
 
-	if (!q)
-		return -ENXIO;
-
 	if (bdev_read_only(bdev))
 		return -EPERM;
 
Signature · 1 line
2.29.0
#2 lore raw

PATCH 2/4 blk-lib: don't check bdev_get_queue() NULL check

In reply to Chaitanya Kulkarni

Based on the comment present in the bdev_get_queue() bdev->bd_disk->queue can never be NULL. Remove the NULL check for the local variabel q that is set from bdev_get_queue() in the function __blkdev_issue_write_same().

---
 block/blk-lib.c | 3 ---
 1 file changed, 3 deletions(-)
block/blk-lib.c +0 -3
index 08ac56eb3a70..473888d667a1 100644
@@ -169,9 +169,6 @@ static int __blkdev_issue_write_same(struct block_device *bdev, sector_t sector,
 	struct bio *bio = *biop;
 	sector_t bs_mask;
 
-	if (!q)
-		return -ENXIO;
-
 	if (bdev_read_only(bdev))
 		return -EPERM;
 
Signature · 1 line
2.29.0
#3 lore raw

PATCH 3/4 blk-lib: don't check bdev_get_queue() NULL check

In reply to Chaitanya Kulkarni

Based on the comment present in the bdev_get_queue() bdev->bd_disk->queue can never be NULL. Remove the NULL check for the local variabel q that is set from bdev_get_queue() in the function __blkdev_issue_write_zeroes() and the respective NULL check.

---
 block/blk-lib.c | 4 ----
 1 file changed, 4 deletions(-)
block/blk-lib.c +0 -4
index 473888d667a1..e7a9ed8cc5df 100644
@@ -244,10 +244,6 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev,
 {
 	struct bio *bio = *biop;
 	unsigned int max_write_zeroes_sectors;
-	struct request_queue *q = bdev_get_queue(bdev);
-
-	if (!q)
-		return -ENXIO;
 
 	if (bdev_read_only(bdev))
 		return -EPERM;
Signature · 1 line
2.29.0
#4 lore raw

PATCH 4/4 blk-lib: don't check bdev_get_queue() NULL check

In reply to Chaitanya Kulkarni

The queue variable is only used to check if it is NULL or not in __blkdev_issue_zero_pages(). The return value of the bdev_get_queue() will not be NULL based on the comment in the bdev_get_queue().

Remove the variable and respective NULL check.

---
 block/blk-lib.c | 4 ----
 1 file changed, 4 deletions(-)
block/blk-lib.c +0 -4
index e7a9ed8cc5df..e6e854936ef6 100644
@@ -294,14 +294,10 @@ 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;
-
 	if (bdev_read_only(bdev))
 		return -EPERM;
 
Signature · 1 line
2.29.0
#5 lore raw
In reply to Chaitanya Kulkarni
Quoted 8 lines · Chaitanya Kulkarni

Hi,

Based on the comment in the include/linux/blkdev.h:bdev_get_queue() the return value of the function will never be NULL. This patch series removes those checks present in the blk-lib.c, also removes the not needed local variable pointer to request_queue from the write_zeroes helpers.

Quoted 5 lines

Below is the test log for discard (__blkdev_issue_disacrd()) and write-zeroes (__blkdev_issue_write_zeroes/__blkdev_issue_zero_pages()).

-ck

This clashes with Christoph's write same cleanup. I'll resend this once that is in the linux-block tree, meanwhile any comments on discard, write-zeroes and zero-pages patches are welcome.

-ck

maintainer
#6 lore raw
Quoted 12 lines · Chaitanya Kulkarni
Quoted 11 lines · Chaitanya Kulkarni

Hi,

Based on the comment in the include/linux/blkdev.h:bdev_get_queue() the return value of the function will never be NULL. This patch series removes those checks present in the blk-lib.c, also removes the not needed local variable pointer to request_queue from the write_zeroes helpers.

Below is the test log for discard (__blkdev_issue_disacrd()) and write-zeroes (__blkdev_issue_write_zeroes/__blkdev_issue_zero_pages()).

Quoted 6 lines
Quoted 2 lines

-ck

This clashes with Christoph's write same cleanup. I'll resend this once that is in the linux-block tree, meanwhile any comments on discard, write-zeroes and zero-pages patches are welcome.

Please just collapse those patches into 1. Right now it's 4 patches with identical titles, that's very confusing.

Signature · 1 line
Jens Axboe