Skip to content

Commit 3d29cb1

Browse files
committed
Merge tag 'block-5.7-2020-04-24' of git://git.kernel.dk/linux-block
Pull block fixes from Jens Axboe: "A few fixes/changes that should go into this release: - null_blk zoned fixes (Damien) - blkdev_close() sync improvement (Douglas) - Fix regression in blk-iocost that impacted (at least) systemtap (Waiman) - Comment fix, header removal (Zhiqiang, Jianpeng)" * tag 'block-5.7-2020-04-24' of git://git.kernel.dk/linux-block: null_blk: Cleanup zoned device initialization null_blk: Fix zoned command handling block: remove unused header blk-iocost: Fix error on iocost_ioc_vrate_adj bdev: Reduce time holding bd_mutex in sync in blkdev_close() buffer: remove useless comment and WB_REASON_FREE_MORE_MEM, reason.
2 parents da5de55 + d205bde commit 3d29cb1

File tree

9 files changed

+99
-62
lines changed

9 files changed

+99
-62
lines changed

block/blk-iocost.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,7 @@ static void ioc_timer_fn(struct timer_list *timer)
15911591
vrate_min, vrate_max);
15921592
}
15931593

1594-
trace_iocost_ioc_vrate_adj(ioc, vrate, &missed_ppm, rq_wait_pct,
1594+
trace_iocost_ioc_vrate_adj(ioc, vrate, missed_ppm, rq_wait_pct,
15951595
nr_lagging, nr_shortages,
15961596
nr_surpluses);
15971597

@@ -1600,7 +1600,7 @@ static void ioc_timer_fn(struct timer_list *timer)
16001600
ioc->period_us * vrate * INUSE_MARGIN_PCT, 100);
16011601
} else if (ioc->busy_level != prev_busy_level || nr_lagging) {
16021602
trace_iocost_ioc_vrate_adj(ioc, atomic64_read(&ioc->vtime_rate),
1603-
&missed_ppm, rq_wait_pct, nr_lagging,
1603+
missed_ppm, rq_wait_pct, nr_lagging,
16041604
nr_shortages, nr_surpluses);
16051605
}
16061606

drivers/block/null_blk.h

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,26 +85,35 @@ struct nullb {
8585
char disk_name[DISK_NAME_LEN];
8686
};
8787

88+
blk_status_t null_process_cmd(struct nullb_cmd *cmd,
89+
enum req_opf op, sector_t sector,
90+
unsigned int nr_sectors);
91+
8892
#ifdef CONFIG_BLK_DEV_ZONED
89-
int null_zone_init(struct nullb_device *dev);
90-
void null_zone_exit(struct nullb_device *dev);
93+
int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q);
94+
int null_register_zoned_dev(struct nullb *nullb);
95+
void null_free_zoned_dev(struct nullb_device *dev);
9196
int null_report_zones(struct gendisk *disk, sector_t sector,
9297
unsigned int nr_zones, report_zones_cb cb, void *data);
93-
blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
94-
enum req_opf op, sector_t sector,
95-
sector_t nr_sectors);
98+
blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
99+
enum req_opf op, sector_t sector,
100+
sector_t nr_sectors);
96101
size_t null_zone_valid_read_len(struct nullb *nullb,
97102
sector_t sector, unsigned int len);
98103
#else
99-
static inline int null_zone_init(struct nullb_device *dev)
104+
static inline int null_init_zoned_dev(struct nullb_device *dev,
105+
struct request_queue *q)
100106
{
101107
pr_err("CONFIG_BLK_DEV_ZONED not enabled\n");
102108
return -EINVAL;
103109
}
104-
static inline void null_zone_exit(struct nullb_device *dev) {}
105-
static inline blk_status_t null_handle_zoned(struct nullb_cmd *cmd,
106-
enum req_opf op, sector_t sector,
107-
sector_t nr_sectors)
110+
static inline int null_register_zoned_dev(struct nullb *nullb)
111+
{
112+
return -ENODEV;
113+
}
114+
static inline void null_free_zoned_dev(struct nullb_device *dev) {}
115+
static inline blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd,
116+
enum req_opf op, sector_t sector, sector_t nr_sectors)
108117
{
109118
return BLK_STS_NOTSUPP;
110119
}

drivers/block/null_blk_main.c

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ static void null_free_dev(struct nullb_device *dev)
580580
if (!dev)
581581
return;
582582

583-
null_zone_exit(dev);
583+
null_free_zoned_dev(dev);
584584
badblocks_exit(&dev->badblocks);
585585
kfree(dev);
586586
}
@@ -1276,6 +1276,25 @@ static inline void nullb_complete_cmd(struct nullb_cmd *cmd)
12761276
}
12771277
}
12781278

1279+
blk_status_t null_process_cmd(struct nullb_cmd *cmd,
1280+
enum req_opf op, sector_t sector,
1281+
unsigned int nr_sectors)
1282+
{
1283+
struct nullb_device *dev = cmd->nq->dev;
1284+
blk_status_t ret;
1285+
1286+
if (dev->badblocks.shift != -1) {
1287+
ret = null_handle_badblocks(cmd, sector, nr_sectors);
1288+
if (ret != BLK_STS_OK)
1289+
return ret;
1290+
}
1291+
1292+
if (dev->memory_backed)
1293+
return null_handle_memory_backed(cmd, op);
1294+
1295+
return BLK_STS_OK;
1296+
}
1297+
12791298
static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
12801299
sector_t nr_sectors, enum req_opf op)
12811300
{
@@ -1294,17 +1313,11 @@ static blk_status_t null_handle_cmd(struct nullb_cmd *cmd, sector_t sector,
12941313
goto out;
12951314
}
12961315

1297-
if (nullb->dev->badblocks.shift != -1) {
1298-
cmd->error = null_handle_badblocks(cmd, sector, nr_sectors);
1299-
if (cmd->error != BLK_STS_OK)
1300-
goto out;
1301-
}
1302-
1303-
if (dev->memory_backed)
1304-
cmd->error = null_handle_memory_backed(cmd, op);
1305-
1306-
if (!cmd->error && dev->zoned)
1307-
cmd->error = null_handle_zoned(cmd, op, sector, nr_sectors);
1316+
if (dev->zoned)
1317+
cmd->error = null_process_zoned_cmd(cmd, op,
1318+
sector, nr_sectors);
1319+
else
1320+
cmd->error = null_process_cmd(cmd, op, sector, nr_sectors);
13081321

13091322
out:
13101323
nullb_complete_cmd(cmd);
@@ -1605,19 +1618,12 @@ static int null_gendisk_register(struct nullb *nullb)
16051618
disk->queue = nullb->q;
16061619
strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
16071620

1608-
#ifdef CONFIG_BLK_DEV_ZONED
16091621
if (nullb->dev->zoned) {
1610-
if (queue_is_mq(nullb->q)) {
1611-
int ret = blk_revalidate_disk_zones(disk);
1612-
if (ret)
1613-
return ret;
1614-
} else {
1615-
blk_queue_chunk_sectors(nullb->q,
1616-
nullb->dev->zone_size_sects);
1617-
nullb->q->nr_zones = blkdev_nr_zones(disk);
1618-
}
1622+
int ret = null_register_zoned_dev(nullb);
1623+
1624+
if (ret)
1625+
return ret;
16191626
}
1620-
#endif
16211627

16221628
add_disk(disk);
16231629
return 0;
@@ -1773,14 +1779,9 @@ static int null_add_dev(struct nullb_device *dev)
17731779
}
17741780

17751781
if (dev->zoned) {
1776-
rv = null_zone_init(dev);
1782+
rv = null_init_zoned_dev(dev, nullb->q);
17771783
if (rv)
17781784
goto out_cleanup_blk_queue;
1779-
1780-
nullb->q->limits.zoned = BLK_ZONED_HM;
1781-
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, nullb->q);
1782-
blk_queue_required_elevator_features(nullb->q,
1783-
ELEVATOR_F_ZBD_SEQ_WRITE);
17841785
}
17851786

17861787
nullb->q->queuedata = nullb;
@@ -1809,8 +1810,7 @@ static int null_add_dev(struct nullb_device *dev)
18091810

18101811
return 0;
18111812
out_cleanup_zone:
1812-
if (dev->zoned)
1813-
null_zone_exit(dev);
1813+
null_free_zoned_dev(dev);
18141814
out_cleanup_blk_queue:
18151815
blk_cleanup_queue(nullb->q);
18161816
out_cleanup_tags:

drivers/block/null_blk_zoned.c

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static inline unsigned int null_zone_no(struct nullb_device *dev, sector_t sect)
1313
return sect >> ilog2(dev->zone_size_sects);
1414
}
1515

16-
int null_zone_init(struct nullb_device *dev)
16+
int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
1717
{
1818
sector_t dev_size = (sector_t)dev->size * 1024 * 1024;
1919
sector_t sector = 0;
@@ -61,10 +61,27 @@ int null_zone_init(struct nullb_device *dev)
6161
sector += dev->zone_size_sects;
6262
}
6363

64+
q->limits.zoned = BLK_ZONED_HM;
65+
blk_queue_flag_set(QUEUE_FLAG_ZONE_RESETALL, q);
66+
blk_queue_required_elevator_features(q, ELEVATOR_F_ZBD_SEQ_WRITE);
67+
68+
return 0;
69+
}
70+
71+
int null_register_zoned_dev(struct nullb *nullb)
72+
{
73+
struct request_queue *q = nullb->q;
74+
75+
if (queue_is_mq(q))
76+
return blk_revalidate_disk_zones(nullb->disk);
77+
78+
blk_queue_chunk_sectors(q, nullb->dev->zone_size_sects);
79+
q->nr_zones = blkdev_nr_zones(nullb->disk);
80+
6481
return 0;
6582
}
6683

67-
void null_zone_exit(struct nullb_device *dev)
84+
void null_free_zoned_dev(struct nullb_device *dev)
6885
{
6986
kvfree(dev->zones);
7087
}
@@ -126,11 +143,16 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
126143
struct nullb_device *dev = cmd->nq->dev;
127144
unsigned int zno = null_zone_no(dev, sector);
128145
struct blk_zone *zone = &dev->zones[zno];
146+
blk_status_t ret;
147+
148+
trace_nullb_zone_op(cmd, zno, zone->cond);
149+
150+
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL)
151+
return null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors);
129152

130153
switch (zone->cond) {
131154
case BLK_ZONE_COND_FULL:
132155
/* Cannot write to a full zone */
133-
cmd->error = BLK_STS_IOERR;
134156
return BLK_STS_IOERR;
135157
case BLK_ZONE_COND_EMPTY:
136158
case BLK_ZONE_COND_IMP_OPEN:
@@ -143,19 +165,18 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
143165
if (zone->cond != BLK_ZONE_COND_EXP_OPEN)
144166
zone->cond = BLK_ZONE_COND_IMP_OPEN;
145167

168+
ret = null_process_cmd(cmd, REQ_OP_WRITE, sector, nr_sectors);
169+
if (ret != BLK_STS_OK)
170+
return ret;
171+
146172
zone->wp += nr_sectors;
147173
if (zone->wp == zone->start + zone->len)
148174
zone->cond = BLK_ZONE_COND_FULL;
149-
break;
150-
case BLK_ZONE_COND_NOT_WP:
151-
break;
175+
return BLK_STS_OK;
152176
default:
153177
/* Invalid zone condition */
154178
return BLK_STS_IOERR;
155179
}
156-
157-
trace_nullb_zone_op(cmd, zno, zone->cond);
158-
return BLK_STS_OK;
159180
}
160181

161182
static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
@@ -216,8 +237,8 @@ static blk_status_t null_zone_mgmt(struct nullb_cmd *cmd, enum req_opf op,
216237
return BLK_STS_OK;
217238
}
218239

219-
blk_status_t null_handle_zoned(struct nullb_cmd *cmd, enum req_opf op,
220-
sector_t sector, sector_t nr_sectors)
240+
blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_opf op,
241+
sector_t sector, sector_t nr_sectors)
221242
{
222243
switch (op) {
223244
case REQ_OP_WRITE:
@@ -229,6 +250,6 @@ blk_status_t null_handle_zoned(struct nullb_cmd *cmd, enum req_opf op,
229250
case REQ_OP_ZONE_FINISH:
230251
return null_zone_mgmt(cmd, op, sector);
231252
default:
232-
return BLK_STS_OK;
253+
return null_process_cmd(cmd, op, sector, nr_sectors);
233254
}
234255
}

fs/block_dev.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include <linux/module.h>
2020
#include <linux/blkpg.h>
2121
#include <linux/magic.h>
22-
#include <linux/dax.h>
2322
#include <linux/buffer_head.h>
2423
#include <linux/swap.h>
2524
#include <linux/pagevec.h>
@@ -1893,6 +1892,16 @@ static void __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part)
18931892
struct gendisk *disk = bdev->bd_disk;
18941893
struct block_device *victim = NULL;
18951894

1895+
/*
1896+
* Sync early if it looks like we're the last one. If someone else
1897+
* opens the block device between now and the decrement of bd_openers
1898+
* then we did a sync that we didn't need to, but that's not the end
1899+
* of the world and we want to avoid long (could be several minute)
1900+
* syncs while holding the mutex.
1901+
*/
1902+
if (bdev->bd_openers == 1)
1903+
sync_blockdev(bdev);
1904+
18961905
mutex_lock_nested(&bdev->bd_mutex, for_part);
18971906
if (for_part)
18981907
bdev->bd_part_count--;

fs/buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
967967
struct page *page;
968968
struct buffer_head *bh;
969969
sector_t end_block;
970-
int ret = 0; /* Will call free_more_memory() */
970+
int ret = 0;
971971
gfp_t gfp_mask;
972972

973973
gfp_mask = mapping_gfp_constraint(inode->i_mapping, ~__GFP_FS) | gfp;

include/linux/backing-dev-defs.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ enum wb_reason {
5454
WB_REASON_SYNC,
5555
WB_REASON_PERIODIC,
5656
WB_REASON_LAPTOP_TIMER,
57-
WB_REASON_FREE_MORE_MEM,
5857
WB_REASON_FS_FREE_SPACE,
5958
/*
6059
* There is no bdi forker thread any more and works are done

include/trace/events/iocost.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ DEFINE_EVENT(iocg_inuse_update, iocost_inuse_reset,
130130

131131
TRACE_EVENT(iocost_ioc_vrate_adj,
132132

133-
TP_PROTO(struct ioc *ioc, u64 new_vrate, u32 (*missed_ppm)[2],
133+
TP_PROTO(struct ioc *ioc, u64 new_vrate, u32 *missed_ppm,
134134
u32 rq_wait_pct, int nr_lagging, int nr_shortages,
135135
int nr_surpluses),
136136

@@ -155,8 +155,8 @@ TRACE_EVENT(iocost_ioc_vrate_adj,
155155
__entry->old_vrate = atomic64_read(&ioc->vtime_rate);;
156156
__entry->new_vrate = new_vrate;
157157
__entry->busy_level = ioc->busy_level;
158-
__entry->read_missed_ppm = (*missed_ppm)[READ];
159-
__entry->write_missed_ppm = (*missed_ppm)[WRITE];
158+
__entry->read_missed_ppm = missed_ppm[READ];
159+
__entry->write_missed_ppm = missed_ppm[WRITE];
160160
__entry->rq_wait_pct = rq_wait_pct;
161161
__entry->nr_lagging = nr_lagging;
162162
__entry->nr_shortages = nr_shortages;

include/trace/events/writeback.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
EM( WB_REASON_SYNC, "sync") \
3737
EM( WB_REASON_PERIODIC, "periodic") \
3838
EM( WB_REASON_LAPTOP_TIMER, "laptop_timer") \
39-
EM( WB_REASON_FREE_MORE_MEM, "free_more_memory") \
4039
EM( WB_REASON_FS_FREE_SPACE, "fs_free_space") \
4140
EMe(WB_REASON_FORKER_THREAD, "forker_thread")
4241

0 commit comments

Comments
 (0)