From: Miquel van Smoorenburg <miquels@cistron.nl>

This implements the queue congestion callout for DM stacks.  To make
bdi_read/write_congested() return correct information.


---

 25-akpm/drivers/md/dm-table.c |   14 ++++++++++++++
 25-akpm/drivers/md/dm.c       |   14 ++++++++++++++
 25-akpm/drivers/md/dm.h       |    1 +
 3 files changed, 29 insertions(+)

diff -puN drivers/md/dm.c~queue-congestion-dm-implementation drivers/md/dm.c
--- 25/drivers/md/dm.c~queue-congestion-dm-implementation	Thu Feb 26 14:24:11 2004
+++ 25-akpm/drivers/md/dm.c	Thu Feb 26 14:24:11 2004
@@ -489,6 +489,18 @@ static int dm_request(request_queue_t *q
 	return 0;
 }
 
+static int dm_any_congested(void *congested_data, int bdi_bits)
+{
+	int r;
+	struct mapped_device *md = congested_data;
+
+	down_read(&md->lock);
+	r = dm_table_any_congested(md->map, bdi_bits);
+	up_read(&md->lock);
+
+	return r;
+}
+
 /*-----------------------------------------------------------------
  * A bitset is used to keep track of allocated minor numbers.
  *---------------------------------------------------------------*/
@@ -567,6 +579,8 @@ static struct mapped_device *alloc_dev(u
 		goto bad1;
 
 	md->queue->queuedata = md;
+	md->queue->backing_dev_info.congested_fn = dm_any_congested;
+	md->queue->backing_dev_info.congested_data = md;
 	blk_queue_make_request(md->queue, dm_request);
 
 	md->io_pool = mempool_create(MIN_IOS, mempool_alloc_slab,
diff -puN drivers/md/dm.h~queue-congestion-dm-implementation drivers/md/dm.h
--- 25/drivers/md/dm.h~queue-congestion-dm-implementation	Thu Feb 26 14:24:11 2004
+++ 25-akpm/drivers/md/dm.h	Thu Feb 26 14:24:11 2004
@@ -115,6 +115,7 @@ struct list_head *dm_table_get_devices(s
 int dm_table_get_mode(struct dm_table *t);
 void dm_table_suspend_targets(struct dm_table *t);
 void dm_table_resume_targets(struct dm_table *t);
+int dm_table_any_congested(struct dm_table *t, int bdi_bits);
 
 /*-----------------------------------------------------------------
  * A registry of target types.
diff -puN drivers/md/dm-table.c~queue-congestion-dm-implementation drivers/md/dm-table.c
--- 25/drivers/md/dm-table.c~queue-congestion-dm-implementation	Thu Feb 26 14:24:11 2004
+++ 25-akpm/drivers/md/dm-table.c	Thu Feb 26 14:24:11 2004
@@ -862,6 +862,20 @@ void dm_table_resume_targets(struct dm_t
 	}
 }
 
+int dm_table_any_congested(struct dm_table *t, int bdi_bits)
+{
+	struct list_head *d, *devices;
+	int r = 0;
+
+	devices = dm_table_get_devices(t);
+	for (d = devices->next; d != devices; d = d->next) {
+		struct dm_dev *dd = list_entry(d, struct dm_dev, list);
+		request_queue_t *q = bdev_get_queue(dd->bdev);
+		r |= bdi_congested(&q->backing_dev_info, bdi_bits);
+	}
+
+	return r;
+}
 
 EXPORT_SYMBOL(dm_vcalloc);
 EXPORT_SYMBOL(dm_get_device);

_