multipath: implement controller framework for hardware handlers
Subsystems (2)
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 | 119 ++++++++++++++++++++++++++++++- drivers/md/dm-hw-handler.h | 29 ++++++++ drivers/md/dm-mpath-rdac.c | 171 ++++++++++++++++++-------------------------- 3 files changed, 216 insertions(+), 103 deletions(-)
drivers/md/dm-hw-handler.c +117 -2
@@ -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,45 @@ int dm_unregister_hw_handler(struct hw_handler_type *hwht)return 0 ; } +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); +} +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); +struct hw_controller *ctlr = hwh->ctlr;if (hwht->workq_fn) hwht->workq_fn (hwh); +if (ctlr && ctlr->submitted) { +/* Resubmit first queued request */ +spin_lock (&ctlr->lock); + + ctlr->submitted =0 ; +if (!list_empty (&ctlr->cmd_list)) { + hwh = list_first_entry(&ctlr->cmd_list, struct hw_handler, entry); +list_del (&hwh->entry); +queue_work (hwhi->workq, &hwh->work); + ctlr->submitted =1 ; + } +spin_unlock (&ctlr->lock); + +/* Drop controller reference */ +kref_put (&ctlr->kref, _release_hw_controller); + } } int dm_create_hw_handler(struct hw_handler *hwh, unsigned int argc,
@@ -200,6 +233,8 @@ int dm_create_hw_handler(struct hw_handler *hwh, unsigned int argc,if (hwht->workq_fn) {INIT_WORK (&hwh->work, dm_service_hw_workq); + hwh->ctlr =NULL ; +dm_select_hw_controller (hwh,NULL , hwht->name); }return 0 ;
@@ -209,6 +244,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,14 +259,89 @@ 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);return ; } +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); + } +} + +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; +} +unsigned dm_scsi_err_handler (struct hw_handler *hwh,struct bio *bio) {#if 0
@@ -294,4 +407,6 @@ 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_scsi_err_handler);
drivers/md/dm-hw-handler.h +29 -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,14 @@ 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); +/* Enqueue an element to the workqueue */ void dm_enqueue_hw_workq (struct hw_handler *hwh);
drivers/md/dm-mpath-rdac.c +70 -101
302 lines not on this page · raw message
Signature · 1 line
1.5.3.2