multipath: implement controller framework for hardware handlers
PATCH 3/3 multipath: implement controller framework for hardware handlers
Some hardware handler have a need to identify the controller handling the paths, as the controller might only be able to process one path-switching command in a row.
This patch implements a framework for selecting controllers and allows for throttling (single-threading) commands to this controller.
The RDAC hardware handler is converted to use this new framework.
Signed-off-by Hannes Reinecke <[email protected]>
--- drivers/md/dm-hw-handler.c | 182 +++++++++++++++++++++++++++++++++++++++++++- drivers/md/dm-hw-handler.h | 32 ++++++++ drivers/md/dm-mpath-rdac.c | 172 +++++++++++++++++------------------------ 3 files changed, 281 insertions(+), 105 deletions(-)
drivers/md/dm-hw-handler.c +178 -4
@@ -27,6 +27,9 @@ struct hwh_internal {static LIST_HEAD (_hw_handlers);static DECLARE_RWSEM (_hwh_lock); +static LIST_HEAD (_ctlr_list); +static DEFINE_SPINLOCK (_ctlr_lock); +static struct hwh_internal *__find_hw_handler_type (const char *name) {struct hwh_internal *hwhi;
@@ -177,15 +180,165 @@ int dm_unregister_hw_handler(struct hw_handler_type *hwht)return 0 ; } +/* +* Controller framework for hardware handler +* +* Each hardware handler may define a controller. +* A controller is defined to be the entity on the +* storage server handling the accessed path +* (target port). +* Several paths may use the same controller. +* Command submission to a controller might be +* throttled so that only one request at a time is +* submitted to the controller; this will circumvent +* command contention when switch-over commands +* are being issued simultaneously via different +* paths. +*/ + +static void _release_hw_controller (struct kref *kref) +{ + struct hw_controller *ctlr = container_of(kref, struct hw_controller, kref); + +spin_lock (&_ctlr_lock); +list_del (&ctlr->node); +spin_unlock (&_ctlr_lock); +if (ctlr->type && ctlr->type->destroy) + ctlr->type->destroy (ctlr); + +kfree (ctlr); +} + +/* +* dm_select_hw_controller +* +* Select a controller entity by type and ID. +* A new controller entity is created if no +* matching entity is found. The reference +* to the old controller is dropped. +*/ +int dm_select_hw_controller (struct hw_handler *hwh, +struct hw_controller_type *ctlr_type, +const char *ctlr_id) +{ +int retval =0 , ctlr_id_len =strlen (ctlr_id); +struct hw_controller *ctlr =NULL , *old_ctlr =NULL ; + +spin_lock (&_ctlr_lock); + +list_for_each_entry (ctlr, &_ctlr_list, node) { +if ((ctlr_type && ctlr->type == ctlr_type) && + !strcmp (ctlr->ctlr_id, ctlr_id)) { +kref_get (&ctlr->kref); + goto done; + } + } + ctlr =kzalloc (sizeof (*ctlr),GFP_NOIO ); +if (!ctlr) { + ctlr = hwh->ctlr; + retval = -ENOMEM ; + goto done; + } + +if (ctlr_type && ctlr_type->create) { + retval = ctlr_type->create (ctlr); +if (retval) { + ctlr = hwh->ctlr; + goto done; + } + } + +/* Save old controller instance */ + old_ctlr = hwh->ctlr; + +strncpy (ctlr->ctlr_id, ctlr_id, ctlr_id_len); + ctlr->ctlr_id[ctlr_id_len] ='\0' ; +kref_init (&ctlr->kref); +spin_lock_init (&ctlr->lock); + ctlr->submitted =0 ; + ctlr->type = ctlr_type; +INIT_LIST_HEAD (&ctlr->cmd_list); +list_add (&ctlr->node, &_ctlr_list); + + done: + hwh->ctlr = ctlr; +spin_unlock (&_ctlr_lock); + +/* Release old controller; might take _ctlr_lock */ +if (old_ctlr) +kref_put (&old_ctlr->kref, _release_hw_controller); + +return retval; +} + +/* +* dm_throttle_hw_controller +* +* Throttle command submission to the controller so +* that only once command is active at a time. +*/ +void dm_throttle_hw_controller (struct hw_handler *hwh) +{ +if (hwh->ctlr) { +spin_lock (&hwh->ctlr->lock); + hwh->ctlr->submitted =1 ; +spin_unlock (&hwh->ctlr->lock); + } +} + +/* +* dm_flush_hw_controller +* +* Unset throttling for the controller and +* flush all queued commands. +*/ +void dm_flush_hw_controller (struct hw_handler *hwh) +{ +struct hw_handler_type *hwht = hwh->type; + struct hwh_internal *hwhi = container_of(hwht, struct hwh_internal, hwht); +struct hw_handler *tmp_hwh; +struct hw_controller *ctlr = hwh->ctlr; + +if (ctlr && ctlr->submitted) { +spin_lock (&ctlr->lock); + +/* Stop throttling */ + ctlr->submitted =0 ; + +/* Get additional reference to prevent the controller +* from vanishing underneath us */ +kref_get (&hwh->ctlr->kref); + +list_for_each_entry_safe (hwh, tmp_hwh, &ctlr->cmd_list, entry) { +/* Resubmit all queued requests */ +list_del_init (&hwh->entry); +queue_work (hwhi->workq, &hwh->work); +/* Drop controller reference */ +kref_put (&ctlr->kref, _release_hw_controller); + } +spin_unlock (&ctlr->lock); + +/* Drop additional reference */ +kref_put (&ctlr->kref, _release_hw_controller); + } +} + +/* +* Workqueue handling +* +* Each hardware handler has its own workqueue, which +* is used to submit control commands to the target. +* When throttling is enabled on a controller, all +* requests are being queued internally and issued +* one-by-one to the controller. +*/ static void dm_service_hw_workq (struct work_struct *work) { struct hw_handler *hwh = container_of(work, struct hw_handler, work);struct hw_handler_type *hwht = hwh->type; - struct hwh_internal *hwhi = container_of(hwht, struct hwh_internal, hwht);if (hwht->workq_fn) hwht->workq_fn (hwh); - } int dm_create_hw_handler(struct hw_handler *hwh, unsigned int argc,
@@ -200,6 +353,9 @@ int dm_create_hw_handler(struct hw_handler *hwh, unsigned int argc,if (hwht->workq_fn) {INIT_WORK (&hwh->work, dm_service_hw_workq); +/* Create dummy controller */ + hwh->ctlr =NULL ; +dm_select_hw_controller (hwh,NULL , hwht->name); }return 0 ;
@@ -209,6 +365,9 @@ void dm_destroy_hw_handler(struct hw_handler *hwh) {struct hw_handler_type *hwht = hwh->type; +if (hwh->ctlr) +kref_put (&hwh->ctlr->kref, _release_hw_controller); + hwht->destroy (hwh); }
@@ -221,8 +380,20 @@ void dm_enqueue_hw_workq(struct hw_handler *hwh)if (!hwhi->workq) goto out; -DMWARN ("submit %s request" , hwh->type->name); -queue_work (hwhi->workq, &hwh->work); +if (!hwh->ctlr) { +DMWARN ("%s: no controller link" , hwh->type->name); +queue_work (hwhi->workq, &hwh->work); + goto out; + } + +spin_lock (&hwh->ctlr->lock); +kref_get (&hwh->ctlr->kref); +if (hwh->ctlr->submitted) +list_add (&hwh->entry, &hwh->ctlr->cmd_list); +else +queue_work (hwhi->workq, &hwh->work); + +spin_unlock (&hwh->ctlr->lock); out:up_read (&_hwh_lock);
@@ -294,4 +465,7 @@ unsigned dm_scsi_err_handler(struct hw_handler *hwh, struct bio *bio)EXPORT_SYMBOL_GPL (dm_register_hw_handler);EXPORT_SYMBOL_GPL (dm_unregister_hw_handler);EXPORT_SYMBOL_GPL (dm_enqueue_hw_workq); +EXPORT_SYMBOL_GPL (dm_select_hw_controller); +EXPORT_SYMBOL_GPL (dm_throttle_hw_controller); +EXPORT_SYMBOL_GPL (dm_flush_hw_controller);EXPORT_SYMBOL_GPL (dm_scsi_err_handler);
drivers/md/dm-hw-handler.h +32 -0
@@ -15,10 +15,31 @@struct hw_handler_type ; +#define CTLR_ID_LEN 256 + +struct hw_controller { +struct list_head node; +struct hw_controller_type *type; +unsigned char ctlr_id[CTLR_ID_LEN ]; +struct kref kref; +spinlock_t lock; +struct list_head cmd_list; +int submitted; +void *context; +}; + +struct hw_controller_type { +char *name; + +int (*create) (struct hw_controller *ctlr); +void (*destroy) (struct hw_controller *ctlr); +}; +struct hw_handler {struct list_head entry;struct hw_handler_type *type;struct mapped_device *md; +struct hw_controller *ctlr;struct work_struct work;void *context; };
@@ -62,6 +83,17 @@ int dm_create_hw_handler(struct hw_handler *handler, unsigned int argc,/* Destroys a hardware handler */ void dm_destroy_hw_handler (struct hw_handler *handler); +/* Selects a controller instance */ +int dm_select_hw_controller (struct hw_handler *hwh, +struct hw_controller_type *ctlr_type, +const char *ctrl_id); + +/* Throttle command submission to the controller */ +void dm_throttle_hw_controller (struct hw_handler *hwh); + +/* Flush queued commands to the controller */ +void dm_flush_hw_controller (struct hw_handler *hwh); +/* Enqueue an element to the workqueue */ void dm_enqueue_hw_workq (struct hw_handler *hwh);
drivers/md/dm-mpath-rdac.c +71 -101
303 lines not on this page · raw message
Signature · 4 lines
1.5.3.2 --------------050809070408080500030906--