From: Mandeep Singh Baines <[email-masked]>

Allow QUEUE_FLAG_NONROT to propagate up the device stack if all
underlying devices are non-rotational.  Tools like ureadahead will
schedule IOs differently based on the rotational flag.

With this patch, I see boot time go from 7.75 s to 7.46 s on my device.

Suggested-by: J. Richard Barnette <[email-masked]>
Signed-off-by: Mandeep Singh Baines <[email-masked]>
Signed-off-by: Mike Snitzer <[email-masked]>
Cc: Neil Brown <[email-masked]>
Cc: Jens Axboe <[email-masked]>
Cc: Martin K. Petersen <[email-masked]>
Cc: [email-masked]
Signed-off-by: Alasdair G Kergon <[email-masked]>

---
 drivers/md/dm-table.c |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

Index: linux-3.0/drivers/md/dm-table.c
===================================================================
--- linux-3.0.orig/drivers/md/dm-table.c
+++ linux-3.0/drivers/md/dm-table.c
@@ -1301,6 +1301,31 @@ static void dm_table_set_integrity(struc
 			       blk_get_integrity(template_disk));
 }
 
+static int device_is_nonrot(struct dm_target *ti, struct dm_dev *dev,
+			    sector_t start, sector_t len, void *data)
+{
+	struct request_queue *q = bdev_get_queue(dev->bdev);
+
+	return q && blk_queue_nonrot(q);
+}
+
+static bool dm_table_is_nonrot(struct dm_table *t)
+{
+	struct dm_target *ti;
+	unsigned i = 0;
+
+	/* Ensure that all underlying device are non-rotational. */
+	while (i < dm_table_get_num_targets(t)) {
+		ti = dm_table_get_target(t, i++);
+
+		if (!ti->type->iterate_devices ||
+		    !ti->type->iterate_devices(ti, device_is_nonrot, NULL))
+			return 0;
+	}
+
+	return 1;
+}
+
 void dm_table_set_restrictions(struct dm_table *t, struct request_queue *q,
 			       struct queue_limits *limits)
 {
@@ -1314,6 +1339,11 @@ void dm_table_set_restrictions(struct dm
 	else
 		queue_flag_set_unlocked(QUEUE_FLAG_DISCARD, q);
 
+	if (dm_table_is_nonrot(t))
+		queue_flag_set_unlocked(QUEUE_FLAG_NONROT, q);
+	else
+		queue_flag_clear_unlocked(QUEUE_FLAG_NONROT, q);
+
 	dm_table_set_integrity(t);
 
 	/*