Commit 7f8635cc9e66a26d7280ba680b044fa2f65104af

Authored by Linus Torvalds

Merge branch 'for-linus' of git://git.kernel.dk/linux-2.6-block

* 'for-linus' of git://git.kernel.dk/linux-2.6-block:
  cciss: fix cciss_revalidate panic
  block: max hardware sectors limit wrapper
  block: Deprecate QUEUE_FLAG_CLUSTER and use queue_limits instead
  blk-throttle: Correct the placement of smp_rmb()
  blk-throttle: Trim/adjust slice_end once a bio has been dispatched
  block: check for proper length of iov entries earlier in blk_rq_map_user_iov()
  drbd: fix for spin_lock_irqsave in endio callback
  drbd: don't recvmsg with zero length

Showing 13 changed files Side-by-side Diff

... ... @@ -201,12 +201,13 @@
201 201 for (i = 0; i < iov_count; i++) {
202 202 unsigned long uaddr = (unsigned long)iov[i].iov_base;
203 203  
  204 + if (!iov[i].iov_len)
  205 + return -EINVAL;
  206 +
204 207 if (uaddr & queue_dma_alignment(q)) {
205 208 unaligned = 1;
206 209 break;
207 210 }
208   - if (!iov[i].iov_len)
209   - return -EINVAL;
210 211 }
211 212  
212 213 if (unaligned || (q->dma_pad_mask & len) || map_data)
... ... @@ -21,7 +21,7 @@
21 21 return 0;
22 22  
23 23 fbio = bio;
24   - cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
  24 + cluster = blk_queue_cluster(q);
25 25 seg_size = 0;
26 26 nr_phys_segs = 0;
27 27 for_each_bio(bio) {
... ... @@ -87,7 +87,7 @@
87 87 static int blk_phys_contig_segment(struct request_queue *q, struct bio *bio,
88 88 struct bio *nxt)
89 89 {
90   - if (!test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
  90 + if (!blk_queue_cluster(q))
91 91 return 0;
92 92  
93 93 if (bio->bi_seg_back_size + nxt->bi_seg_front_size >
... ... @@ -123,7 +123,7 @@
123 123 int nsegs, cluster;
124 124  
125 125 nsegs = 0;
126   - cluster = test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags);
  126 + cluster = blk_queue_cluster(q);
127 127  
128 128 /*
129 129 * for each bio in rq
block/blk-settings.c
... ... @@ -126,7 +126,7 @@
126 126 lim->alignment_offset = 0;
127 127 lim->io_opt = 0;
128 128 lim->misaligned = 0;
129   - lim->no_cluster = 0;
  129 + lim->cluster = 1;
130 130 }
131 131 EXPORT_SYMBOL(blk_set_default_limits);
132 132  
... ... @@ -229,8 +229,8 @@
229 229 EXPORT_SYMBOL(blk_queue_bounce_limit);
230 230  
231 231 /**
232   - * blk_queue_max_hw_sectors - set max sectors for a request for this queue
233   - * @q: the request queue for the device
  232 + * blk_limits_max_hw_sectors - set hard and soft limit of max sectors for request
  233 + * @limits: the queue limits
234 234 * @max_hw_sectors: max hardware sectors in the usual 512b unit
235 235 *
236 236 * Description:
... ... @@ -244,7 +244,7 @@
244 244 * per-device basis in /sys/block/<device>/queue/max_sectors_kb.
245 245 * The soft limit can not exceed max_hw_sectors.
246 246 **/
247   -void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
  247 +void blk_limits_max_hw_sectors(struct queue_limits *limits, unsigned int max_hw_sectors)
248 248 {
249 249 if ((max_hw_sectors << 9) < PAGE_CACHE_SIZE) {
250 250 max_hw_sectors = 1 << (PAGE_CACHE_SHIFT - 9);
251 251  
... ... @@ -252,10 +252,24 @@
252 252 __func__, max_hw_sectors);
253 253 }
254 254  
255   - q->limits.max_hw_sectors = max_hw_sectors;
256   - q->limits.max_sectors = min_t(unsigned int, max_hw_sectors,
257   - BLK_DEF_MAX_SECTORS);
  255 + limits->max_hw_sectors = max_hw_sectors;
  256 + limits->max_sectors = min_t(unsigned int, max_hw_sectors,
  257 + BLK_DEF_MAX_SECTORS);
258 258 }
  259 +EXPORT_SYMBOL(blk_limits_max_hw_sectors);
  260 +
  261 +/**
  262 + * blk_queue_max_hw_sectors - set max sectors for a request for this queue
  263 + * @q: the request queue for the device
  264 + * @max_hw_sectors: max hardware sectors in the usual 512b unit
  265 + *
  266 + * Description:
  267 + * See description for blk_limits_max_hw_sectors().
  268 + **/
  269 +void blk_queue_max_hw_sectors(struct request_queue *q, unsigned int max_hw_sectors)
  270 +{
  271 + blk_limits_max_hw_sectors(&q->limits, max_hw_sectors);
  272 +}
259 273 EXPORT_SYMBOL(blk_queue_max_hw_sectors);
260 274  
261 275 /**
... ... @@ -464,15 +478,6 @@
464 478 void blk_queue_stack_limits(struct request_queue *t, struct request_queue *b)
465 479 {
466 480 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   - }
476 481 }
477 482 EXPORT_SYMBOL(blk_queue_stack_limits);
478 483  
... ... @@ -545,7 +550,7 @@
545 550 t->io_min = max(t->io_min, b->io_min);
546 551 t->io_opt = lcm(t->io_opt, b->io_opt);
547 552  
548   - t->no_cluster |= b->no_cluster;
  553 + t->cluster &= b->cluster;
549 554 t->discard_zeroes_data &= b->discard_zeroes_data;
550 555  
551 556 /* Physical block size a multiple of the logical block size? */
... ... @@ -641,7 +646,6 @@
641 646 sector_t offset)
642 647 {
643 648 struct request_queue *t = disk->queue;
644   - struct request_queue *b = bdev_get_queue(bdev);
645 649  
646 650 if (bdev_stack_limits(&t->limits, bdev, offset >> 9) < 0) {
647 651 char top[BDEVNAME_SIZE], bottom[BDEVNAME_SIZE];
... ... @@ -651,17 +655,6 @@
651 655  
652 656 printk(KERN_NOTICE "%s: Warning: Device %s is misaligned\n",
653 657 top, bottom);
654   - }
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 658 }
666 659 }
667 660 EXPORT_SYMBOL(disk_stack_limits);
... ... @@ -119,7 +119,7 @@
119 119  
120 120 static ssize_t queue_max_segment_size_show(struct request_queue *q, char *page)
121 121 {
122   - if (test_bit(QUEUE_FLAG_CLUSTER, &q->queue_flags))
  122 + if (blk_queue_cluster(q))
123 123 return queue_var_show(queue_max_segment_size(q), (page));
124 124  
125 125 return queue_var_show(PAGE_CACHE_SIZE, (page));
block/blk-throttle.c
... ... @@ -355,6 +355,12 @@
355 355 tg->slice_end[rw], jiffies);
356 356 }
357 357  
  358 +static inline void throtl_set_slice_end(struct throtl_data *td,
  359 + struct throtl_grp *tg, bool rw, unsigned long jiffy_end)
  360 +{
  361 + tg->slice_end[rw] = roundup(jiffy_end, throtl_slice);
  362 +}
  363 +
358 364 static inline void throtl_extend_slice(struct throtl_data *td,
359 365 struct throtl_grp *tg, bool rw, unsigned long jiffy_end)
360 366 {
... ... @@ -391,6 +397,16 @@
391 397 if (throtl_slice_used(td, tg, rw))
392 398 return;
393 399  
  400 + /*
  401 + * A bio has been dispatched. Also adjust slice_end. It might happen
  402 + * that initially cgroup limit was very low resulting in high
  403 + * slice_end, but later limit was bumped up and bio was dispached
  404 + * sooner, then we need to reduce slice_end. A high bogus slice_end
  405 + * is bad because it does not allow new slice to start.
  406 + */
  407 +
  408 + throtl_set_slice_end(td, tg, rw, jiffies + throtl_slice);
  409 +
394 410 time_elapsed = jiffies - tg->slice_start[rw];
395 411  
396 412 nr_slices = time_elapsed / throtl_slice;
397 413  
398 414  
... ... @@ -709,26 +725,21 @@
709 725 struct throtl_grp *tg;
710 726 struct hlist_node *pos, *n;
711 727  
712   - /*
713   - * Make sure atomic_inc() effects from
714   - * throtl_update_blkio_group_read_bps(), group of functions are
715   - * visible.
716   - * Is this required or smp_mb__after_atomic_inc() was suffcient
717   - * after the atomic_inc().
718   - */
719   - smp_rmb();
720 728 if (!atomic_read(&td->limits_changed))
721 729 return;
722 730  
723 731 throtl_log(td, "limit changed =%d", atomic_read(&td->limits_changed));
724 732  
725   - hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
726   - /*
727   - * Do I need an smp_rmb() here to make sure tg->limits_changed
728   - * update is visible. I am relying on smp_rmb() at the
729   - * beginning of function and not putting a new one here.
730   - */
  733 + /*
  734 + * Make sure updates from throtl_update_blkio_group_read_bps() group
  735 + * of functions to tg->limits_changed are visible. We do not
  736 + * want update td->limits_changed to be visible but update to
  737 + * tg->limits_changed not being visible yet on this cpu. Hence
  738 + * the read barrier.
  739 + */
  740 + smp_rmb();
731 741  
  742 + hlist_for_each_entry_safe(tg, pos, n, &td->tg_list, tg_node) {
732 743 if (throtl_tg_on_rr(tg) && tg->limits_changed) {
733 744 throtl_log_tg(td, tg, "limit change rbps=%llu wbps=%llu"
734 745 " riops=%u wiops=%u", tg->bps[READ],
drivers/block/cciss.c
... ... @@ -2834,6 +2834,8 @@
2834 2834 InquiryData_struct *inq_buff = NULL;
2835 2835  
2836 2836 for (logvol = 0; logvol < CISS_MAX_LUN; logvol++) {
  2837 + if (!h->drv[logvol])
  2838 + continue
2837 2839 if (memcmp(h->drv[logvol]->LunID, drv->LunID,
2838 2840 sizeof(drv->LunID)) == 0) {
2839 2841 FOUND = 1;
drivers/block/drbd/drbd_receiver.c
... ... @@ -3627,15 +3627,17 @@
3627 3627 }
3628 3628  
3629 3629 shs = drbd_cmd_handler[cmd].pkt_size - sizeof(union p_header);
3630   - rv = drbd_recv(mdev, &header->h80.payload, shs);
3631   - if (unlikely(rv != shs)) {
3632   - dev_err(DEV, "short read while reading sub header: rv=%d\n", rv);
3633   - goto err_out;
3634   - }
3635   -
3636 3630 if (packet_size - shs > 0 && !drbd_cmd_handler[cmd].expect_payload) {
3637 3631 dev_err(DEV, "No payload expected %s l:%d\n", cmdname(cmd), packet_size);
3638 3632 goto err_out;
  3633 + }
  3634 +
  3635 + if (shs) {
  3636 + rv = drbd_recv(mdev, &header->h80.payload, shs);
  3637 + if (unlikely(rv != shs)) {
  3638 + dev_err(DEV, "short read while reading sub header: rv=%d\n", rv);
  3639 + goto err_out;
  3640 + }
3639 3641 }
3640 3642  
3641 3643 rv = drbd_cmd_handler[cmd].function(mdev, cmd, packet_size - shs);
drivers/block/drbd/drbd_req.h
... ... @@ -339,7 +339,8 @@
339 339 }
340 340  
341 341 /* completion of master bio is outside of spinlock.
342   - * If you need it irqsave, do it your self! */
  342 + * If you need it irqsave, do it your self!
  343 + * Which means: don't use from bio endio callback. */
343 344 static inline int req_mod(struct drbd_request *req,
344 345 enum drbd_req_event what)
345 346 {
drivers/block/drbd/drbd_worker.c
... ... @@ -193,8 +193,10 @@
193 193 */
194 194 void drbd_endio_pri(struct bio *bio, int error)
195 195 {
  196 + unsigned long flags;
196 197 struct drbd_request *req = bio->bi_private;
197 198 struct drbd_conf *mdev = req->mdev;
  199 + struct bio_and_error m;
198 200 enum drbd_req_event what;
199 201 int uptodate = bio_flagged(bio, BIO_UPTODATE);
200 202  
... ... @@ -220,7 +222,13 @@
220 222 bio_put(req->private_bio);
221 223 req->private_bio = ERR_PTR(error);
222 224  
223   - req_mod(req, what);
  225 + /* not req_mod(), we need irqsave here! */
  226 + spin_lock_irqsave(&mdev->req_lock, flags);
  227 + __req_mod(req, what, &m);
  228 + spin_unlock_irqrestore(&mdev->req_lock, flags);
  229 +
  230 + if (m.bio)
  231 + complete_master_bio(mdev, &m);
224 232 }
225 233  
226 234 int w_read_retry_remote(struct drbd_conf *mdev, struct drbd_work *w, int cancel)
drivers/md/dm-table.c
... ... @@ -517,9 +517,8 @@
517 517 */
518 518  
519 519 if (q->merge_bvec_fn && !ti->type->merge)
520   - limits->max_sectors =
521   - min_not_zero(limits->max_sectors,
522   - (unsigned int) (PAGE_SIZE >> 9));
  520 + blk_limits_max_hw_sectors(limits,
  521 + (unsigned int) (PAGE_SIZE >> 9));
523 522 return 0;
524 523 }
525 524 EXPORT_SYMBOL_GPL(dm_set_device_limits);
... ... @@ -1130,11 +1129,6 @@
1130 1129 * Copy table's limits to the DM device's request_queue
1131 1130 */
1132 1131 q->limits = *limits;
1133   -
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 1132  
1139 1133 if (!dm_table_supports_discards(t))
1140 1134 queue_flag_clear_unlocked(QUEUE_FLAG_DISCARD, q);
... ... @@ -4295,9 +4295,6 @@
4295 4295 goto abort;
4296 4296 mddev->queue->queuedata = mddev;
4297 4297  
4298   - /* Can be unlocked because the queue is new: no concurrency */
4299   - queue_flag_set_unlocked(QUEUE_FLAG_CLUSTER, mddev->queue);
4300   -
4301 4298 blk_queue_make_request(mddev->queue, md_make_request);
4302 4299  
4303 4300 disk = alloc_disk(1 << shift);
drivers/scsi/scsi_lib.c
... ... @@ -1637,9 +1637,8 @@
1637 1637  
1638 1638 blk_queue_max_segment_size(q, dma_get_max_seg_size(dev));
1639 1639  
1640   - /* New queue, no concurrency on queue_flags */
1641 1640 if (!shost->use_clustering)
1642   - queue_flag_clear_unlocked(QUEUE_FLAG_CLUSTER, q);
  1641 + q->limits.cluster = 0;
1643 1642  
1644 1643 /*
1645 1644 * set a reasonable default alignment on word boundaries: the
include/linux/blkdev.h
... ... @@ -250,7 +250,7 @@
250 250  
251 251 unsigned char misaligned;
252 252 unsigned char discard_misaligned;
253   - unsigned char no_cluster;
  253 + unsigned char cluster;
254 254 signed char discard_zeroes_data;
255 255 };
256 256  
... ... @@ -380,7 +380,6 @@
380 380 #endif
381 381 };
382 382  
383   -#define QUEUE_FLAG_CLUSTER 0 /* cluster several segments into 1 */
384 383 #define QUEUE_FLAG_QUEUED 1 /* uses generic tag queueing */
385 384 #define QUEUE_FLAG_STOPPED 2 /* queue is stopped */
386 385 #define QUEUE_FLAG_SYNCFULL 3 /* read queue has been filled */
... ... @@ -403,7 +402,6 @@
403 402 #define QUEUE_FLAG_SECDISCARD 19 /* supports SECDISCARD */
404 403  
405 404 #define QUEUE_FLAG_DEFAULT ((1 << QUEUE_FLAG_IO_STAT) | \
406   - (1 << QUEUE_FLAG_CLUSTER) | \
407 405 (1 << QUEUE_FLAG_STACKABLE) | \
408 406 (1 << QUEUE_FLAG_SAME_COMP) | \
409 407 (1 << QUEUE_FLAG_ADD_RANDOM))
... ... @@ -510,6 +508,11 @@
510 508  
511 509 #define rq_data_dir(rq) ((rq)->cmd_flags & 1)
512 510  
  511 +static inline unsigned int blk_queue_cluster(struct request_queue *q)
  512 +{
  513 + return q->limits.cluster;
  514 +}
  515 +
513 516 /*
514 517 * We regard a request as sync, if either a read or a sync write
515 518 */
... ... @@ -805,6 +808,7 @@
805 808 extern void blk_cleanup_queue(struct request_queue *);
806 809 extern void blk_queue_make_request(struct request_queue *, make_request_fn *);
807 810 extern void blk_queue_bounce_limit(struct request_queue *, u64);
  811 +extern void blk_limits_max_hw_sectors(struct queue_limits *, unsigned int);
808 812 extern void blk_queue_max_hw_sectors(struct request_queue *, unsigned int);
809 813 extern void blk_queue_max_segments(struct request_queue *, unsigned short);
810 814 extern void blk_queue_max_segment_size(struct request_queue *, unsigned int);