From patchwork Tue Dec 14 21:16:51 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonthan Brassow X-Patchwork-Id: 411421 Received: from mx3-phx2.redhat.com (mx3-phx2.redhat.com [209.132.183.24]) by demeter1.kernel.org (8.14.4/8.14.3) with ESMTP id oBELIZcU029126 for ; Tue, 14 Dec 2010 21:18:57 GMT Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx3-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBELGxoR009269; Tue, 14 Dec 2010 16:17:00 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oBELGwkC001057 for ; Tue, 14 Dec 2010 16:16:58 -0500 Received: from hydrogen.msp.redhat.com (hydrogen.msp.redhat.com [10.15.80.1]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id oBELGqMI002094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 14 Dec 2010 16:16:53 -0500 Received: from hydrogen.msp.redhat.com ([127.0.0.1]) by hydrogen.msp.redhat.com (8.14.1/8.14.1) with ESMTP id oBELGqW3015599 for ; Tue, 14 Dec 2010 15:16:52 -0600 Received: (from jbrassow@localhost) by hydrogen.msp.redhat.com (8.14.1/8.14.1/Submit) id oBELGp34015598 for dm-devel@redhat.com; Tue, 14 Dec 2010 15:16:51 -0600 Date: Tue, 14 Dec 2010 15:16:51 -0600 From: Jonathan Brassow Message-Id: <201012142116.oBELGp34015598@hydrogen.msp.redhat.com> To: dm-devel@redhat.com X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-loop: dm-devel@redhat.com Subject: [dm-devel] [PATCH 5 of 8] dm target callbacks and congestion fn X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.3 (demeter1.kernel.org [140.211.167.41]); Tue, 14 Dec 2010 21:18:57 +0000 (UTC) Index: linux-2.6/drivers/md/dm-raid.c =================================================================== --- linux-2.6.orig/drivers/md/dm-raid.c +++ linux-2.6/drivers/md/dm-raid.c @@ -51,6 +51,7 @@ struct raid_set { struct mddev_s md; struct raid_type *raid_type; + struct target_callbacks callbacks; struct raid_dev dev[0]; }; @@ -355,6 +356,13 @@ static void do_table_event(struct work_s dm_table_event(rs->ti->table); } +static int raid_is_congested(void *v, int bits) +{ + struct target_callbacks *cb = v; + struct raid_set *rs = container_of(cb, struct raid_set, + callbacks); + return md_raid5_congested(&rs->md, bits); +} /* * Construct a RAID4/5/6 mapping: * Args: @@ -435,8 +443,13 @@ static int raid_ctr(struct dm_target *ti rs->md.in_sync = 0; /* Assume already marked dirty */ mutex_unlock(&rs->md.reconfig_mutex); - if (!errnum) - return 0; + if (errnum) + goto err; + + rs->callbacks.congested_fn = raid_is_congested; + dm_table_add_callbacks(ti->table, &rs->callbacks); + + return 0; err: if (rs) @@ -449,6 +462,7 @@ static void raid_dtr(struct dm_target *t { struct raid_set *rs = ti->private; + list_del_init(&rs->callbacks.list); md_stop(&rs->md); context_free(rs); } Index: linux-2.6/drivers/md/dm-table.c =================================================================== --- linux-2.6.orig/drivers/md/dm-table.c +++ linux-2.6/drivers/md/dm-table.c @@ -70,6 +70,8 @@ struct dm_table { void (*event_fn)(void *); void *event_context; + struct list_head target_callbacks; + struct dm_md_mempools *mempools; }; @@ -204,6 +206,7 @@ int dm_table_create(struct dm_table **re return -ENOMEM; INIT_LIST_HEAD(&t->devices); + INIT_LIST_HEAD(&t->target_callbacks); atomic_set(&t->holders, 0); t->discards_supported = 1; @@ -1229,10 +1232,18 @@ int dm_table_resume_targets(struct dm_ta return 0; } +void dm_table_add_callbacks(struct dm_table *t, + struct target_callbacks *cb) +{ + list_add(&cb->list, &t->target_callbacks); +} +EXPORT_SYMBOL_GPL(dm_table_add_callbacks); + int dm_table_any_congested(struct dm_table *t, int bdi_bits) { struct dm_dev_internal *dd; struct list_head *devices = dm_table_get_devices(t); + struct target_callbacks *cb; int r = 0; list_for_each_entry(dd, devices, list) { @@ -1247,6 +1258,10 @@ int dm_table_any_congested(struct dm_tab bdevname(dd->dm_dev.bdev, b)); } + list_for_each_entry(cb, &t->target_callbacks, list) + if (cb->congested_fn) + r |= cb->congested_fn(cb, bdi_bits); + return r; } Index: linux-2.6/include/linux/device-mapper.h =================================================================== --- linux-2.6.orig/include/linux/device-mapper.h +++ linux-2.6/include/linux/device-mapper.h @@ -193,6 +193,12 @@ struct dm_target { char *error; }; +/* Each target can link one of these into the table */ +struct target_callbacks { + struct list_head list; + congested_fn *congested_fn; +}; + int dm_register_target(struct target_type *t); void dm_unregister_target(struct target_type *t); @@ -269,6 +275,12 @@ int dm_table_add_target(struct dm_table sector_t start, sector_t len, char *params); /* + * Target_ctr should call this if they need to add any + * callback + */ +void dm_table_add_callbacks(struct dm_table *t, + struct target_callbacks *cb); +/* * Finally call this to make the table ready for use. */ int dm_table_complete(struct dm_table *t);