Skip to content

Commit a022f7d

Browse files
committed
Merge tag 'block-5.14-2021-07-08' of git://git.kernel.dk/linux-block
Pull more block updates from Jens Axboe: "A combination of changes that ended up depending on both the driver and core branch (and/or the IDE removal), and a few late arriving fixes. In detail: - Fix io ticks wrap-around issue (Chunguang) - nvme-tcp sock locking fix (Maurizio) - s390-dasd fixes (Kees, Christoph) - blk_execute_rq polling support (Keith) - blk-cgroup RCU iteration fix (Yu) - nbd backend ID addition (Prasanna) - Partition deletion fix (Yufen) - Use blk_mq_alloc_disk for mmc, mtip32xx, ubd (Christoph) - Removal of now dead block request types due to IDE removal (Christoph) - Loop probing and control device cleanups (Christoph) - Device uevent fix (Christoph) - Misc cleanups/fixes (Tetsuo, Christoph)" * tag 'block-5.14-2021-07-08' of git://git.kernel.dk/linux-block: (34 commits) blk-cgroup: prevent rcu_sched detected stalls warnings while iterating blkgs block: fix the problem of io_ticks becoming smaller nvme-tcp: can't set sk_user_data without write_lock loop: remove unused variable in loop_set_status() block: remove the bdgrab in blk_drop_partitions block: grab a device refcount in disk_uevent s390/dasd: Avoid field over-reading memcpy() dasd: unexport dasd_set_target_state block: check disk exist before trying to add partition ubd: remove dead code in ubd_setup_common nvme: use return value from blk_execute_rq() block: return errors from blk_execute_rq() nvme: use blk_execute_rq() for passthrough commands block: support polling through blk_execute_rq block: remove REQ_OP_SCSI_{IN,OUT} block: mark blk_mq_init_queue_data static loop: rewrite loop_exit using idr_for_each_entry loop: split loop_lookup loop: don't allow deleting an unspecified loop device loop: move loop_ctl_mutex locking into loop_add ...
2 parents 3de6295 + a731763 commit a022f7d

43 files changed

Lines changed: 346 additions & 520 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arch/um/drivers/ubd_kern.c

Lines changed: 26 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,7 @@ static const struct block_device_operations ubd_blops = {
125125
};
126126

127127
/* Protected by ubd_lock */
128-
static int fake_major = UBD_MAJOR;
129128
static struct gendisk *ubd_gendisk[MAX_DEV];
130-
static struct gendisk *fake_gendisk[MAX_DEV];
131129

132130
#ifdef CONFIG_BLK_DEV_UBD_SYNC
133131
#define OPEN_FLAGS ((struct openflags) { .r = 1, .w = 1, .s = 1, .c = 0, \
@@ -197,54 +195,19 @@ struct ubd {
197195
/* Protected by ubd_lock */
198196
static struct ubd ubd_devs[MAX_DEV] = { [0 ... MAX_DEV - 1] = DEFAULT_UBD };
199197

200-
/* Only changed by fake_ide_setup which is a setup */
201-
static int fake_ide = 0;
202-
static struct proc_dir_entry *proc_ide_root = NULL;
203-
static struct proc_dir_entry *proc_ide = NULL;
204-
205198
static blk_status_t ubd_queue_rq(struct blk_mq_hw_ctx *hctx,
206199
const struct blk_mq_queue_data *bd);
207200

208-
static void make_proc_ide(void)
209-
{
210-
proc_ide_root = proc_mkdir("ide", NULL);
211-
proc_ide = proc_mkdir("ide0", proc_ide_root);
212-
}
213-
214-
static int fake_ide_media_proc_show(struct seq_file *m, void *v)
215-
{
216-
seq_puts(m, "disk\n");
217-
return 0;
218-
}
219-
220-
static void make_ide_entries(const char *dev_name)
221-
{
222-
struct proc_dir_entry *dir, *ent;
223-
char name[64];
224-
225-
if(proc_ide_root == NULL) make_proc_ide();
226-
227-
dir = proc_mkdir(dev_name, proc_ide);
228-
if(!dir) return;
229-
230-
ent = proc_create_single("media", S_IRUGO, dir,
231-
fake_ide_media_proc_show);
232-
if(!ent) return;
233-
snprintf(name, sizeof(name), "ide0/%s", dev_name);
234-
proc_symlink(dev_name, proc_ide_root, name);
235-
}
236-
237201
static int fake_ide_setup(char *str)
238202
{
239-
fake_ide = 1;
203+
pr_warn("The fake_ide option has been removed\n");
240204
return 1;
241205
}
242-
243206
__setup("fake_ide", fake_ide_setup);
244207

245208
__uml_help(fake_ide_setup,
246209
"fake_ide\n"
247-
" Create ide0 entries that map onto ubd devices.\n\n"
210+
" Obsolete stub.\n\n"
248211
);
249212

250213
static int parse_unit(char **ptr)
@@ -280,36 +243,14 @@ static int ubd_setup_common(char *str, int *index_out, char **error_out)
280243
if(index_out) *index_out = -1;
281244
n = *str;
282245
if(n == '='){
283-
char *end;
284-
int major;
285-
286246
str++;
287247
if(!strcmp(str, "sync")){
288248
global_openflags = of_sync(global_openflags);
289249
return err;
290250
}
291251

292-
err = -EINVAL;
293-
major = simple_strtoul(str, &end, 0);
294-
if((*end != '\0') || (end == str)){
295-
*error_out = "Didn't parse major number";
296-
return err;
297-
}
298-
299-
mutex_lock(&ubd_lock);
300-
if (fake_major != UBD_MAJOR) {
301-
*error_out = "Can't assign a fake major twice";
302-
goto out1;
303-
}
304-
305-
fake_major = major;
306-
307-
printk(KERN_INFO "Setting extra ubd major number to %d\n",
308-
major);
309-
err = 0;
310-
out1:
311-
mutex_unlock(&ubd_lock);
312-
return err;
252+
pr_warn("fake major not supported any more\n");
253+
return 0;
313254
}
314255

315256
n = parse_unit(&str);
@@ -874,7 +815,6 @@ static void ubd_device_release(struct device *dev)
874815
{
875816
struct ubd *ubd_dev = dev_get_drvdata(dev);
876817

877-
blk_cleanup_queue(ubd_dev->queue);
878818
blk_mq_free_tag_set(&ubd_dev->tag_set);
879819
*ubd_dev = ((struct ubd) DEFAULT_UBD);
880820
}
@@ -914,41 +854,25 @@ static const struct attribute_group *ubd_attr_groups[] = {
914854
NULL,
915855
};
916856

917-
static int ubd_disk_register(int major, u64 size, int unit,
918-
struct gendisk **disk_out)
857+
static void ubd_disk_register(int major, u64 size, int unit,
858+
struct gendisk *disk)
919859
{
920-
struct device *parent = NULL;
921-
struct gendisk *disk;
922-
923-
disk = alloc_disk(1 << UBD_SHIFT);
924-
if(disk == NULL)
925-
return -ENOMEM;
926-
927860
disk->major = major;
928861
disk->first_minor = unit << UBD_SHIFT;
862+
disk->minors = 1 << UBD_SHIFT;
929863
disk->fops = &ubd_blops;
930864
set_capacity(disk, size / 512);
931-
if (major == UBD_MAJOR)
932-
sprintf(disk->disk_name, "ubd%c", 'a' + unit);
933-
else
934-
sprintf(disk->disk_name, "ubd_fake%d", unit);
935-
936-
/* sysfs register (not for ide fake devices) */
937-
if (major == UBD_MAJOR) {
938-
ubd_devs[unit].pdev.id = unit;
939-
ubd_devs[unit].pdev.name = DRIVER_NAME;
940-
ubd_devs[unit].pdev.dev.release = ubd_device_release;
941-
dev_set_drvdata(&ubd_devs[unit].pdev.dev, &ubd_devs[unit]);
942-
platform_device_register(&ubd_devs[unit].pdev);
943-
parent = &ubd_devs[unit].pdev.dev;
944-
}
865+
sprintf(disk->disk_name, "ubd%c", 'a' + unit);
866+
867+
ubd_devs[unit].pdev.id = unit;
868+
ubd_devs[unit].pdev.name = DRIVER_NAME;
869+
ubd_devs[unit].pdev.dev.release = ubd_device_release;
870+
dev_set_drvdata(&ubd_devs[unit].pdev.dev, &ubd_devs[unit]);
871+
platform_device_register(&ubd_devs[unit].pdev);
945872

946873
disk->private_data = &ubd_devs[unit];
947874
disk->queue = ubd_devs[unit].queue;
948-
device_add_disk(parent, disk, ubd_attr_groups);
949-
950-
*disk_out = disk;
951-
return 0;
875+
device_add_disk(&ubd_devs[unit].pdev.dev, disk, ubd_attr_groups);
952876
}
953877

954878
#define ROUND_BLOCK(n) ((n + (SECTOR_SIZE - 1)) & (-SECTOR_SIZE))
@@ -960,6 +884,7 @@ static const struct blk_mq_ops ubd_mq_ops = {
960884
static int ubd_add(int n, char **error_out)
961885
{
962886
struct ubd *ubd_dev = &ubd_devs[n];
887+
struct gendisk *disk;
963888
int err = 0;
964889

965890
if(ubd_dev->file == NULL)
@@ -984,43 +909,24 @@ static int ubd_add(int n, char **error_out)
984909
if (err)
985910
goto out;
986911

987-
ubd_dev->queue = blk_mq_init_queue(&ubd_dev->tag_set);
988-
if (IS_ERR(ubd_dev->queue)) {
989-
err = PTR_ERR(ubd_dev->queue);
912+
disk = blk_mq_alloc_disk(&ubd_dev->tag_set, ubd_dev);
913+
if (IS_ERR(disk)) {
914+
err = PTR_ERR(disk);
990915
goto out_cleanup_tags;
991916
}
917+
ubd_dev->queue = disk->queue;
992918

993-
ubd_dev->queue->queuedata = ubd_dev;
994919
blk_queue_write_cache(ubd_dev->queue, true, false);
995-
996920
blk_queue_max_segments(ubd_dev->queue, MAX_SG);
997921
blk_queue_segment_boundary(ubd_dev->queue, PAGE_SIZE - 1);
998-
err = ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, &ubd_gendisk[n]);
999-
if(err){
1000-
*error_out = "Failed to register device";
1001-
goto out_cleanup_tags;
1002-
}
1003-
1004-
if (fake_major != UBD_MAJOR)
1005-
ubd_disk_register(fake_major, ubd_dev->size, n,
1006-
&fake_gendisk[n]);
1007-
1008-
/*
1009-
* Perhaps this should also be under the "if (fake_major)" above
1010-
* using the fake_disk->disk_name
1011-
*/
1012-
if (fake_ide)
1013-
make_ide_entries(ubd_gendisk[n]->disk_name);
1014-
1015-
err = 0;
1016-
out:
1017-
return err;
922+
ubd_disk_register(UBD_MAJOR, ubd_dev->size, n, disk);
923+
ubd_gendisk[n] = disk;
924+
return 0;
1018925

1019926
out_cleanup_tags:
1020927
blk_mq_free_tag_set(&ubd_dev->tag_set);
1021-
if (!(IS_ERR(ubd_dev->queue)))
1022-
blk_cleanup_queue(ubd_dev->queue);
1023-
goto out;
928+
out:
929+
return err;
1024930
}
1025931

1026932
static int ubd_config(char *str, char **error_out)
@@ -1123,13 +1029,7 @@ static int ubd_remove(int n, char **error_out)
11231029
ubd_gendisk[n] = NULL;
11241030
if(disk != NULL){
11251031
del_gendisk(disk);
1126-
put_disk(disk);
1127-
}
1128-
1129-
if(fake_gendisk[n] != NULL){
1130-
del_gendisk(fake_gendisk[n]);
1131-
put_disk(fake_gendisk[n]);
1132-
fake_gendisk[n] = NULL;
1032+
blk_cleanup_disk(disk);
11331033
}
11341034

11351035
err = 0;
@@ -1188,14 +1088,6 @@ static int __init ubd_init(void)
11881088
if (register_blkdev(UBD_MAJOR, "ubd"))
11891089
return -1;
11901090

1191-
if (fake_major != UBD_MAJOR) {
1192-
char name[sizeof("ubd_nnn\0")];
1193-
1194-
snprintf(name, sizeof(name), "ubd_%d", fake_major);
1195-
if (register_blkdev(fake_major, "ubd"))
1196-
return -1;
1197-
}
1198-
11991091
irq_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
12001092
sizeof(struct io_thread_req *),
12011093
GFP_KERNEL

block/blk-cgroup.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ static LIST_HEAD(all_blkcgs); /* protected by blkcg_pol_mutex */
5656
bool blkcg_debug_stats = false;
5757
static struct workqueue_struct *blkcg_punt_bio_wq;
5858

59+
#define BLKG_DESTROY_BATCH_SIZE 64
60+
5961
static bool blkcg_policy_enabled(struct request_queue *q,
6062
const struct blkcg_policy *pol)
6163
{
@@ -422,14 +424,27 @@ static void blkg_destroy(struct blkcg_gq *blkg)
422424
static void blkg_destroy_all(struct request_queue *q)
423425
{
424426
struct blkcg_gq *blkg, *n;
427+
int count = BLKG_DESTROY_BATCH_SIZE;
425428

429+
restart:
426430
spin_lock_irq(&q->queue_lock);
427431
list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
428432
struct blkcg *blkcg = blkg->blkcg;
429433

430434
spin_lock(&blkcg->lock);
431435
blkg_destroy(blkg);
432436
spin_unlock(&blkcg->lock);
437+
438+
/*
439+
* in order to avoid holding the spin lock for too long, release
440+
* it when a batch of blkgs are destroyed.
441+
*/
442+
if (!(--count)) {
443+
count = BLKG_DESTROY_BATCH_SIZE;
444+
spin_unlock_irq(&q->queue_lock);
445+
cond_resched();
446+
goto restart;
447+
}
433448
}
434449

435450
q->root_blkg = NULL;

block/blk-core.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ static const char *const blk_op_name[] = {
142142
REQ_OP_NAME(ZONE_APPEND),
143143
REQ_OP_NAME(WRITE_SAME),
144144
REQ_OP_NAME(WRITE_ZEROES),
145-
REQ_OP_NAME(SCSI_IN),
146-
REQ_OP_NAME(SCSI_OUT),
147145
REQ_OP_NAME(DRV_IN),
148146
REQ_OP_NAME(DRV_OUT),
149147
};
@@ -1243,7 +1241,7 @@ static void update_io_ticks(struct block_device *part, unsigned long now,
12431241
unsigned long stamp;
12441242
again:
12451243
stamp = READ_ONCE(part->bd_stamp);
1246-
if (unlikely(stamp != now)) {
1244+
if (unlikely(time_after(now, stamp))) {
12471245
if (likely(cmpxchg(&part->bd_stamp, stamp, now) == stamp))
12481246
__part_stat_add(part, io_ticks, end ? now - stamp : 1);
12491247
}

block/blk-exec.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static void blk_end_sync_rq(struct request *rq, blk_status_t error)
2121
{
2222
struct completion *waiting = rq->end_io_data;
2323

24-
rq->end_io_data = NULL;
24+
rq->end_io_data = (void *)(uintptr_t)error;
2525

2626
/*
2727
* complete last, if this is a stack request the process (and thus
@@ -63,6 +63,19 @@ void blk_execute_rq_nowait(struct gendisk *bd_disk, struct request *rq,
6363
}
6464
EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);
6565

66+
static bool blk_rq_is_poll(struct request *rq)
67+
{
68+
return rq->mq_hctx && rq->mq_hctx->type == HCTX_TYPE_POLL;
69+
}
70+
71+
static void blk_rq_poll_completion(struct request *rq, struct completion *wait)
72+
{
73+
do {
74+
blk_poll(rq->q, request_to_qc_t(rq->mq_hctx, rq), true);
75+
cond_resched();
76+
} while (!completion_done(wait));
77+
}
78+
6679
/**
6780
* blk_execute_rq - insert a request into queue for execution
6881
* @bd_disk: matching gendisk
@@ -72,8 +85,9 @@ EXPORT_SYMBOL_GPL(blk_execute_rq_nowait);
7285
* Description:
7386
* Insert a fully prepared request at the back of the I/O scheduler queue
7487
* for execution and wait for completion.
88+
* Return: The blk_status_t result provided to blk_mq_end_request().
7589
*/
76-
void blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)
90+
blk_status_t blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)
7791
{
7892
DECLARE_COMPLETION_ONSTACK(wait);
7993
unsigned long hang_check;
@@ -83,9 +97,14 @@ void blk_execute_rq(struct gendisk *bd_disk, struct request *rq, int at_head)
8397

8498
/* Prevent hang_check timer from firing at us during very long I/O */
8599
hang_check = sysctl_hung_task_timeout_secs;
86-
if (hang_check)
100+
101+
if (blk_rq_is_poll(rq))
102+
blk_rq_poll_completion(rq, &wait);
103+
else if (hang_check)
87104
while (!wait_for_completion_io_timeout(&wait, hang_check * (HZ/2)));
88105
else
89106
wait_for_completion_io(&wait);
107+
108+
return (blk_status_t)(uintptr_t)rq->end_io_data;
90109
}
91110
EXPORT_SYMBOL(blk_execute_rq);

block/blk-mq.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,7 +3109,7 @@ void blk_mq_release(struct request_queue *q)
31093109
blk_mq_sysfs_deinit(q);
31103110
}
31113111

3112-
struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
3112+
static struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
31133113
void *queuedata)
31143114
{
31153115
struct request_queue *q;
@@ -3126,7 +3126,6 @@ struct request_queue *blk_mq_init_queue_data(struct blk_mq_tag_set *set,
31263126
}
31273127
return q;
31283128
}
3129-
EXPORT_SYMBOL_GPL(blk_mq_init_queue_data);
31303129

31313130
struct request_queue *blk_mq_init_queue(struct blk_mq_tag_set *set)
31323131
{

block/bsg-lib.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ static int bsg_transport_fill_hdr(struct request *rq, struct sg_io_v4 *hdr,
4545
return PTR_ERR(job->request);
4646

4747
if (hdr->dout_xfer_len && hdr->din_xfer_len) {
48-
job->bidi_rq = blk_get_request(rq->q, REQ_OP_SCSI_IN, 0);
48+
job->bidi_rq = blk_get_request(rq->q, REQ_OP_DRV_IN, 0);
4949
if (IS_ERR(job->bidi_rq)) {
5050
ret = PTR_ERR(job->bidi_rq);
5151
goto out;

0 commit comments

Comments
 (0)