Skip to content

Commit bd976e5

Browse files
damien-lemoalaxboe
authored andcommitted
block: Kill gfp_t argument of blkdev_report_zones()
Only GFP_KERNEL and GFP_NOIO are used with blkdev_report_zones(). In preparation of using vmalloc() for large report buffer and zone array allocations used by this function, remove its "gfp_t gfp_mask" argument and rely on the caller context to use memalloc_noio_save/restore() where necessary (block layer zone revalidation and dm-zoned I/O error path). Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b4c5875 commit bd976e5

File tree

12 files changed

+46
-44
lines changed

12 files changed

+46
-44
lines changed

block/blk-zoned.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <linux/rbtree.h>
1515
#include <linux/blkdev.h>
1616
#include <linux/blk-mq.h>
17+
#include <linux/sched/mm.h>
1718

1819
#include "blk.h"
1920

@@ -117,8 +118,7 @@ static bool blkdev_report_zone(struct block_device *bdev, struct blk_zone *rep)
117118
}
118119

119120
static int blk_report_zones(struct gendisk *disk, sector_t sector,
120-
struct blk_zone *zones, unsigned int *nr_zones,
121-
gfp_t gfp_mask)
121+
struct blk_zone *zones, unsigned int *nr_zones)
122122
{
123123
struct request_queue *q = disk->queue;
124124
unsigned int z = 0, n, nrz = *nr_zones;
@@ -127,8 +127,7 @@ static int blk_report_zones(struct gendisk *disk, sector_t sector,
127127

128128
while (z < nrz && sector < capacity) {
129129
n = nrz - z;
130-
ret = disk->fops->report_zones(disk, sector, &zones[z], &n,
131-
gfp_mask);
130+
ret = disk->fops->report_zones(disk, sector, &zones[z], &n);
132131
if (ret)
133132
return ret;
134133
if (!n)
@@ -149,17 +148,18 @@ static int blk_report_zones(struct gendisk *disk, sector_t sector,
149148
* @sector: Sector from which to report zones
150149
* @zones: Array of zone structures where to return the zones information
151150
* @nr_zones: Number of zone structures in the zone array
152-
* @gfp_mask: Memory allocation flags (for bio_alloc)
153151
*
154152
* Description:
155153
* Get zone information starting from the zone containing @sector.
156154
* The number of zone information reported may be less than the number
157155
* requested by @nr_zones. The number of zones actually reported is
158156
* returned in @nr_zones.
157+
* The caller must use memalloc_noXX_save/restore() calls to control
158+
* memory allocations done within this function (zone array and command
159+
* buffer allocation by the device driver).
159160
*/
160161
int blkdev_report_zones(struct block_device *bdev, sector_t sector,
161-
struct blk_zone *zones, unsigned int *nr_zones,
162-
gfp_t gfp_mask)
162+
struct blk_zone *zones, unsigned int *nr_zones)
163163
{
164164
struct request_queue *q = bdev_get_queue(bdev);
165165
unsigned int i, nrz;
@@ -184,7 +184,7 @@ int blkdev_report_zones(struct block_device *bdev, sector_t sector,
184184
nrz = min(*nr_zones,
185185
__blkdev_nr_zones(q, bdev->bd_part->nr_sects - sector));
186186
ret = blk_report_zones(bdev->bd_disk, get_start_sect(bdev) + sector,
187-
zones, &nrz, gfp_mask);
187+
zones, &nrz);
188188
if (ret)
189189
return ret;
190190

@@ -305,9 +305,7 @@ int blkdev_report_zones_ioctl(struct block_device *bdev, fmode_t mode,
305305
if (!zones)
306306
return -ENOMEM;
307307

308-
ret = blkdev_report_zones(bdev, rep.sector,
309-
zones, &rep.nr_zones,
310-
GFP_KERNEL);
308+
ret = blkdev_report_zones(bdev, rep.sector, zones, &rep.nr_zones);
311309
if (ret)
312310
goto out;
313311

@@ -415,6 +413,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
415413
unsigned long *seq_zones_wlock = NULL, *seq_zones_bitmap = NULL;
416414
unsigned int i, rep_nr_zones = 0, z = 0, nrz;
417415
struct blk_zone *zones = NULL;
416+
unsigned int noio_flag;
418417
sector_t sector = 0;
419418
int ret = 0;
420419

@@ -427,6 +426,12 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
427426
return 0;
428427
}
429428

429+
/*
430+
* Ensure that all memory allocations in this context are done as
431+
* if GFP_NOIO was specified.
432+
*/
433+
noio_flag = memalloc_noio_save();
434+
430435
if (!blk_queue_is_zoned(q) || !nr_zones) {
431436
nr_zones = 0;
432437
goto update;
@@ -449,7 +454,7 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
449454

450455
while (z < nr_zones) {
451456
nrz = min(nr_zones - z, rep_nr_zones);
452-
ret = blk_report_zones(disk, sector, zones, &nrz, GFP_NOIO);
457+
ret = blk_report_zones(disk, sector, zones, &nrz);
453458
if (ret)
454459
goto out;
455460
if (!nrz)
@@ -480,6 +485,8 @@ int blk_revalidate_disk_zones(struct gendisk *disk)
480485
blk_mq_unfreeze_queue(q);
481486

482487
out:
488+
memalloc_noio_restore(noio_flag);
489+
483490
free_pages((unsigned long)zones,
484491
get_order(rep_nr_zones * sizeof(struct blk_zone)));
485492
kfree(seq_zones_wlock);

drivers/block/null_blk.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,7 @@ struct nullb {
8989
int null_zone_init(struct nullb_device *dev);
9090
void null_zone_exit(struct nullb_device *dev);
9191
int null_zone_report(struct gendisk *disk, sector_t sector,
92-
struct blk_zone *zones, unsigned int *nr_zones,
93-
gfp_t gfp_mask);
92+
struct blk_zone *zones, unsigned int *nr_zones);
9493
void null_zone_write(struct nullb_cmd *cmd, sector_t sector,
9594
unsigned int nr_sectors);
9695
void null_zone_reset(struct nullb_cmd *cmd, sector_t sector);

drivers/block/null_blk_zoned.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ void null_zone_exit(struct nullb_device *dev)
6767
}
6868

6969
int null_zone_report(struct gendisk *disk, sector_t sector,
70-
struct blk_zone *zones, unsigned int *nr_zones,
71-
gfp_t gfp_mask)
70+
struct blk_zone *zones, unsigned int *nr_zones)
7271
{
7372
struct nullb *nullb = disk->private_data;
7473
struct nullb_device *dev = nullb->dev;

drivers/md/dm-flakey.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,15 +461,14 @@ static int flakey_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
461461

462462
#ifdef CONFIG_BLK_DEV_ZONED
463463
static int flakey_report_zones(struct dm_target *ti, sector_t sector,
464-
struct blk_zone *zones, unsigned int *nr_zones,
465-
gfp_t gfp_mask)
464+
struct blk_zone *zones, unsigned int *nr_zones)
466465
{
467466
struct flakey_c *fc = ti->private;
468467
int ret;
469468

470469
/* Do report and remap it */
471470
ret = blkdev_report_zones(fc->dev->bdev, flakey_map_sector(ti, sector),
472-
zones, nr_zones, gfp_mask);
471+
zones, nr_zones);
473472
if (ret != 0)
474473
return ret;
475474

drivers/md/dm-linear.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,14 @@ static int linear_prepare_ioctl(struct dm_target *ti, struct block_device **bdev
137137

138138
#ifdef CONFIG_BLK_DEV_ZONED
139139
static int linear_report_zones(struct dm_target *ti, sector_t sector,
140-
struct blk_zone *zones, unsigned int *nr_zones,
141-
gfp_t gfp_mask)
140+
struct blk_zone *zones, unsigned int *nr_zones)
142141
{
143142
struct linear_c *lc = (struct linear_c *) ti->private;
144143
int ret;
145144

146145
/* Do report and remap it */
147146
ret = blkdev_report_zones(lc->dev->bdev, linear_map_sector(ti, sector),
148-
zones, nr_zones, gfp_mask);
147+
zones, nr_zones);
149148
if (ret != 0)
150149
return ret;
151150

drivers/md/dm-zoned-metadata.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <linux/module.h>
1010
#include <linux/crc32.h>
11+
#include <linux/sched/mm.h>
1112

1213
#define DM_MSG_PREFIX "zoned metadata"
1314

@@ -1162,8 +1163,7 @@ static int dmz_init_zones(struct dmz_metadata *zmd)
11621163
while (sector < dev->capacity) {
11631164
/* Get zone information */
11641165
nr_blkz = DMZ_REPORT_NR_ZONES;
1165-
ret = blkdev_report_zones(dev->bdev, sector, blkz,
1166-
&nr_blkz, GFP_KERNEL);
1166+
ret = blkdev_report_zones(dev->bdev, sector, blkz, &nr_blkz);
11671167
if (ret) {
11681168
dmz_dev_err(dev, "Report zones failed %d", ret);
11691169
goto out;
@@ -1201,12 +1201,20 @@ static int dmz_init_zones(struct dmz_metadata *zmd)
12011201
static int dmz_update_zone(struct dmz_metadata *zmd, struct dm_zone *zone)
12021202
{
12031203
unsigned int nr_blkz = 1;
1204+
unsigned int noio_flag;
12041205
struct blk_zone blkz;
12051206
int ret;
12061207

1207-
/* Get zone information from disk */
1208+
/*
1209+
* Get zone information from disk. Since blkdev_report_zones() uses
1210+
* GFP_KERNEL by default for memory allocations, set the per-task
1211+
* PF_MEMALLOC_NOIO flag so that all allocations are done as if
1212+
* GFP_NOIO was specified.
1213+
*/
1214+
noio_flag = memalloc_noio_save();
12081215
ret = blkdev_report_zones(zmd->dev->bdev, dmz_start_sect(zmd, zone),
1209-
&blkz, &nr_blkz, GFP_NOIO);
1216+
&blkz, &nr_blkz);
1217+
memalloc_noio_restore(noio_flag);
12101218
if (!nr_blkz)
12111219
ret = -EIO;
12121220
if (ret) {

drivers/md/dm.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,7 @@ static int dm_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
441441
}
442442

443443
static int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
444-
struct blk_zone *zones, unsigned int *nr_zones,
445-
gfp_t gfp_mask)
444+
struct blk_zone *zones, unsigned int *nr_zones)
446445
{
447446
#ifdef CONFIG_BLK_DEV_ZONED
448447
struct mapped_device *md = disk->private_data;
@@ -480,8 +479,7 @@ static int dm_blk_report_zones(struct gendisk *disk, sector_t sector,
480479
* So there is no need to loop here trying to fill the entire array
481480
* of zones.
482481
*/
483-
ret = tgt->type->report_zones(tgt, sector, zones,
484-
nr_zones, gfp_mask);
482+
ret = tgt->type->report_zones(tgt, sector, zones, nr_zones);
485483

486484
out:
487485
dm_put_live_table(md, srcu_idx);

drivers/scsi/sd.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,7 @@ extern blk_status_t sd_zbc_setup_reset_cmnd(struct scsi_cmnd *cmd);
213213
extern void sd_zbc_complete(struct scsi_cmnd *cmd, unsigned int good_bytes,
214214
struct scsi_sense_hdr *sshdr);
215215
extern int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
216-
struct blk_zone *zones, unsigned int *nr_zones,
217-
gfp_t gfp_mask);
216+
struct blk_zone *zones, unsigned int *nr_zones);
218217

219218
#else /* CONFIG_BLK_DEV_ZONED */
220219

drivers/scsi/sd_zbc.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ static int sd_zbc_do_report_zones(struct scsi_disk *sdkp, unsigned char *buf,
109109
* @sector: Start 512B sector of the report
110110
* @zones: Array of zone descriptors
111111
* @nr_zones: Number of descriptors in the array
112-
* @gfp_mask: Memory allocation mask
113112
*
114113
* Execute a report zones command on the target disk.
115114
*/
116115
int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
117-
struct blk_zone *zones, unsigned int *nr_zones,
118-
gfp_t gfp_mask)
116+
struct blk_zone *zones, unsigned int *nr_zones)
119117
{
120118
struct scsi_disk *sdkp = scsi_disk(disk);
121119
unsigned int i, buflen, nrz = *nr_zones;
@@ -134,7 +132,7 @@ int sd_zbc_report_zones(struct gendisk *disk, sector_t sector,
134132
*/
135133
buflen = min(queue_max_hw_sectors(disk->queue) << 9,
136134
roundup((nrz + 1) * 64, 512));
137-
buf = kmalloc(buflen, gfp_mask);
135+
buf = kmalloc(buflen, GFP_KERNEL);
138136
if (!buf)
139137
return -ENOMEM;
140138

fs/f2fs/super.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2841,9 +2841,7 @@ static int init_blkz_info(struct f2fs_sb_info *sbi, int devi)
28412841
while (zones && sector < nr_sectors) {
28422842

28432843
nr_zones = F2FS_REPORT_NR_ZONES;
2844-
err = blkdev_report_zones(bdev, sector,
2845-
zones, &nr_zones,
2846-
GFP_KERNEL);
2844+
err = blkdev_report_zones(bdev, sector, zones, &nr_zones);
28472845
if (err)
28482846
break;
28492847
if (!nr_zones) {

include/linux/blkdev.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ struct queue_limits {
347347
extern unsigned int blkdev_nr_zones(struct block_device *bdev);
348348
extern int blkdev_report_zones(struct block_device *bdev,
349349
sector_t sector, struct blk_zone *zones,
350-
unsigned int *nr_zones, gfp_t gfp_mask);
350+
unsigned int *nr_zones);
351351
extern int blkdev_reset_zones(struct block_device *bdev, sector_t sectors,
352352
sector_t nr_sectors, gfp_t gfp_mask);
353353
extern int blk_revalidate_disk_zones(struct gendisk *disk);
@@ -1673,8 +1673,7 @@ struct block_device_operations {
16731673
/* this callback is with swap_lock and sometimes page table lock held */
16741674
void (*swap_slot_free_notify) (struct block_device *, unsigned long);
16751675
int (*report_zones)(struct gendisk *, sector_t sector,
1676-
struct blk_zone *zones, unsigned int *nr_zones,
1677-
gfp_t gfp_mask);
1676+
struct blk_zone *zones, unsigned int *nr_zones);
16781677
struct module *owner;
16791678
const struct pr_ops *pr_ops;
16801679
};

include/linux/device-mapper.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,7 @@ typedef int (*dm_prepare_ioctl_fn) (struct dm_target *ti, struct block_device **
9595

9696
typedef int (*dm_report_zones_fn) (struct dm_target *ti, sector_t sector,
9797
struct blk_zone *zones,
98-
unsigned int *nr_zones,
99-
gfp_t gfp_mask);
98+
unsigned int *nr_zones);
10099

101100
/*
102101
* These iteration functions are typically used to check (and combine)

0 commit comments

Comments
 (0)