Skip to content

Commit e692cb6

Browse files
martinkpetersenJens Axboe
authored andcommitted
block: Deprecate QUEUE_FLAG_CLUSTER and use queue_limits instead
When stacking devices, a request_queue is not always available. This forced us to have a no_cluster flag in the queue_limits that could be used as a carrier until the request_queue had been set up for a metadevice. There were several problems with that approach. First of all it was up to the stacking device to remember to set queue flag after stacking had completed. Also, the queue flag and the queue limits had to be kept in sync at all times. We got that wrong, which could lead to us issuing commands that went beyond the max scatterlist limit set by the driver. The proper fix is to avoid having two flags for tracking the same thing. We deprecate QUEUE_FLAG_CLUSTER and use the queue limit directly in the block layer merging functions. The queue_limit 'no_cluster' is turned into 'cluster' to avoid double negatives and to ease stacking. Clustering defaults to being enabled as before. The queue flag logic is removed from the stacking function, and explicitly setting the cluster flag is no longer necessary in DM and MD. Reported-by: Ed Lin <ed.lin@promise.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Acked-by: Mike Snitzer <snitzer@redhat.com> Cc: stable@kernel.org Signed-off-by: Jens Axboe <jaxboe@fusionio.com>
1 parent 04a6b51 commit e692cb6

7 files changed

Lines changed: 13 additions & 40 deletions

File tree

‎block/blk-merge.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ static unsigned int __blk_recalc_rq_segments(struct request_queue *q,
2121
return 0;
2222

2323
fbio = bio;
24-
cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
24+
cluster = blk_queue_cluster(q);
2525
seg_size = 0;
2626
nr_phys_segs = 0;
2727
for_each_bio(bio) {
@@ -87,7 +87,7 @@ EXPORT_SYMBOL(blk_recount_segments);
8787
static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
8888
struct bio *nxt)
8989
{
90-
if (!test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
90+
if (!blk_queue_cluster(q))
9191
return 0;
9292

9393
if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
@@ -123,7 +123,7 @@ int blk_rq_map_sg(struct request_queue *q, struct request *rq,
123123
int nsegs, cluster;
124124

125125
nsegs = 0;
126-
cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
126+
cluster = blk_queue_cluster(q);
127127

128128
/*
129129
* for each bio in rq

‎block/blk-settings.c‎

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void blk_set_default_limits(struct queue_limits *lim)
126126
lim->alignment_offset = 0;
127127
lim->io_opt = 0;
128128
lim->misaligned = 0;
129-
lim->no_cluster = 0;
129+
lim->cluster = 1;
130130
}
131131
EXPORT_SYMBOL(blk_set_default_limits);
132132

@@ -464,15 +464,6 @@ EXPORT_SYMBOL(blk_queue_io_opt);
464464
void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
465465
{
466466
blk_stack_limits(&t->limits, &b->limits, 0);
467-
468-
if (!t->queue_lock)
469-
WARN_ON_ONCE(1);
470-
else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
471-
unsigned long flags;
472-
spin_lock_irqsave(t->queue_lock, flags);
473-
queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
474-
spin_unlock_irqrestore(t->queue_lock, flags);
475-
}
476467
}
477468
EXPORT_SYMBOL(blk_queue_stack_limits);
478469

@@ -545,7 +536,7 @@ int blk_stack_limits(struct queue_limits *t, struct queue_limits *b,
545536
t->io_min = max(t->io_min, b->io_min);
546537
t->io_opt = lcm(t->io_opt, b->io_opt);
547538

548-
t->no_cluster |= b->no_cluster;
539+
t->cluster &= b->cluster;
549540
t->discard_zeroes_data &= b->discard_zeroes_data;
550541

551542
/* Physical block size a multiple of the logical block size? */
@@ -641,7 +632,6 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
641632
sector_t offset)
642633
{
643634
struct request_queue *t = disk->queue;
644-
struct request_queue *b = bdev_get_queue(bdev);
645635

646636
if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
647637
char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
@@ -652,17 +642,6 @@ void disk_stack_limits(struct gendisk *disk, struct block_device *bdev,
652642
printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
653643
top, bottom);
654644
}
655-
656-
if (!t->queue_lock)
657-
WARN_ON_ONCE(1);
658-
else if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags)) {
659-
unsigned long flags;
660-
661-
spin_lock_irqsave(t->queue_lock, flags);
662-
if (!test_bit(QUEUE_FLAG_CLUSTER, &b->queue_flags))
663-
queue_flag_clear(QUEUE_FLAG_CLUSTER, t);
664-
spin_unlock_irqrestore(t->queue_lock, flags);
665-
}
666645
}
667646
EXPORT_SYMBOL(disk_stack_limits);
668647

‎block/blk-sysfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static ssize_t queue_max_integrity_segments_show(struct request_queue *q, char *
119119

120120
static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page)
121121
{
122-
if (test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
122+
if (blk_queue_cluster(q))
123123
return queue_var_show(queue_max_segment_size(q), (page));
124124

125125
return queue_var_show(PAGE_CACHE_SIZE, (page));

‎drivers/md/dm-table.c‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,11 +1131,6 @@ void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
11311131
*/
11321132
q->limits = *limits;
11331133

1134-
if (limits->no_cluster)
1135-
queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q);
1136-
else
1137-
queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, q);
1138-
11391134
if (!dm_table_supports_discards(t))
11401135
queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
11411136
else

‎drivers/md/md.c‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,9 +4296,6 @@ static int md_alloc(dev_t dev, char *name)
42964296
goto abort;
42974297
mddev->queue->queuedata = mddev;
42984298

4299-
/* Can be unlocked because the queue is new: no concurrency */
4300-
queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue);
4301-
43024299
blk_queue_make_request(mddev->queue, md_make_request);
43034300

43044301
disk = alloc_disk(1 << shift);

‎drivers/scsi/scsi_lib.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1642,9 +1642,8 @@ struct request_queue *__scsi_alloc_queue(struct Scsi_Host *shost,
16421642

16431643
blk_queue_max_segment_size(q, dma_get_max_seg_size(dev));
16441644

1645-
/* New queue, no concurrency on queue_flags */
16461645
if (!shost->use_clustering)
1647-
queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q);
1646+
q->limits.cluster = 0;
16481647

16491648
/*
16501649
* set a reasonable default alignment on word boundaries: the

‎include/linux/blkdev.h‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ struct queue_limits {
250250

251251
unsigned char misaligned;
252252
unsigned char discard_misaligned;
253-
unsigned char no_cluster;
253+
unsigned char cluster;
254254
signed char discard_zeroes_data;
255255
};
256256

@@ -380,7 +380,6 @@ struct request_queue
380380
#endif
381381
};
382382

383-
#define QUEUE_FLAG_CLUSTER 0 /* cluster several segments into 1 */
384383
#define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
385384
#define QUEUE_FLAG_STOPPED 2 /* queue is stopped */
386385
#define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */
@@ -403,7 +402,6 @@ struct request_queue
403402
#define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */
404403

405404
#define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
406-
(1 << QUEUE_FLAG_CLUSTER) | \
407405
(1 << QUEUE_FLAG_STACKABLE) | \
408406
(1 << QUEUE_FLAG_SAME_COMP) | \
409407
(1 << QUEUE_FLAG_ADD_RANDOM))
@@ -510,6 +508,11 @@ static inline void queue_flag_clear(unsigned int flag, struct request_queue *q)
510508

511509
#define rq_data_dir(rq) ((rq)->cmd_flags & 1)
512510

511+
static inline unsigned int blk_queue_cluster(struct request_queue *q)
512+
{
513+
return q->limits.cluster;
514+
}
515+
513516
/*
514517
* We regard a request as sync, if either a read or a sync write
515518
*/

0 commit comments

Comments
 (0)