From patchwork Tue Apr 28 02:52:48 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chandra Seetharaman X-Patchwork-Id: 20313 Received: from hormel.redhat.com (hormel1.redhat.com [209.132.177.33]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n3S2qEVq023949 for ; Tue, 28 Apr 2009 02:52:14 GMT Received: from listman.util.phx.redhat.com (listman.util.phx.redhat.com [10.8.4.110]) by hormel.redhat.com (Postfix) with ESMTP id CDD0461A026; Mon, 27 Apr 2009 22:52:13 -0400 (EDT) Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by listman.util.phx.redhat.com (8.13.1/8.13.1) with ESMTP id n3S2qBwB008942 for ; Mon, 27 Apr 2009 22:52:11 -0400 Received: from mx1.redhat.com (mx1.redhat.com [172.16.48.31]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n3S2qB1R024365 for ; Mon, 27 Apr 2009 22:52:11 -0400 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n3S2ptTG012904 for ; Mon, 27 Apr 2009 22:51:55 -0400 Received: from d03relay04.boulder.ibm.com (d03relay04.boulder.ibm.com [9.17.195.106]) by e35.co.us.ibm.com (8.13.1/8.13.1) with ESMTP id n3S2kJ1F007547 for ; Mon, 27 Apr 2009 20:46:19 -0600 Received: from d03av02.boulder.ibm.com (d03av02.boulder.ibm.com [9.17.195.168]) by d03relay04.boulder.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n3S2ptfn087622 for ; Mon, 27 Apr 2009 20:51:55 -0600 Received: from d03av02.boulder.ibm.com (loopback [127.0.0.1]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n3S2ptDJ003426 for ; Mon, 27 Apr 2009 20:51:55 -0600 Received: from [127.0.1.1] (chandra-ubuntu.beaverton.ibm.com [9.47.17.98]) by d03av02.boulder.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n3S2pspI003415; Mon, 27 Apr 2009 20:51:54 -0600 From: Chandra Seetharaman To: linux-scsi@vger.kernel.org Date: Mon, 27 Apr 2009 19:52:48 -0700 Message-Id: <20090428025248.11108.38596.sendpatchset@chandra-ubuntu> In-Reply-To: <20090428025230.11108.88559.sendpatchset@chandra-ubuntu> References: <20090428025230.11108.88559.sendpatchset@chandra-ubuntu> X-RedHat-Spam-Score: -3.536 X-Scanned-By: MIMEDefang 2.58 on 172.16.52.254 X-Scanned-By: MIMEDefang 2.63 on 172.16.48.31 X-loop: dm-devel@redhat.com Cc: dm-devel@redhat.com, michaelc@cs.wisc.edu Subject: [dm-devel] [PATCH 3/3] scsi_dh: rdac handler: Batch up MODE SELECTs and send few of them X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.5 Precedence: junk Reply-To: device-mapper development List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com Batch up MODE_SELECT in rdac device handler. LSI RDAC storage has the capability of handling mode selects for multiple luns in a same command. Make use of that ability to send as few MODE SELECTs as possible to the storage controller as possible. This patch creates a work queue and queues up activate requests when a MODE SELECT is sent down the wire. When that MODE SELECT completes, it compiles queued up activate requests for multiple luns into a single MODE SELECT. This reduces the time to do failover/failback of large number of LUNS. Signed-off-by: Babu Moger Signed-off-by: Chandra Seetharaman --- drivers/scsi/device_handler/scsi_dh_rdac.c | 117 ++++++++++++++++++++++++++--- 1 file changed, 104 insertions(+), 13 deletions(-) -- dm-devel mailing list dm-devel@redhat.com https://www.redhat.com/mailman/listinfo/dm-devel Index: linux-2.6.29/drivers/scsi/device_handler/scsi_dh_rdac.c =================================================================== --- linux-2.6.29.orig/drivers/scsi/device_handler/scsi_dh_rdac.c +++ linux-2.6.29/drivers/scsi/device_handler/scsi_dh_rdac.c @@ -22,6 +22,7 @@ #include #include #include +#include #define RDAC_NAME "rdac" #define RDAC_RETRY_COUNT 5 @@ -135,6 +136,11 @@ struct rdac_controller { struct rdac_pg_legacy legacy; struct rdac_pg_expanded expanded; } mode_select; + spinlock_t ms_lock; + int ms_queued; + struct work_struct ms_work; + struct scsi_device *ms_sdev; + struct list_head ms_head; }; struct c8_inquiry { u8 peripheral_info; @@ -195,8 +201,17 @@ static const char *lun_state[] = "owned (AVT mode)", }; +struct rdac_queue_data { + struct list_head entry; + struct rdac_dh_data *h; + activate_complete callback_fn; + void *callback_data; +}; + static LIST_HEAD(ctlr_list); static DEFINE_SPINLOCK(list_lock); +static struct workqueue_struct *kmpath_rdacd; +static void send_mode_select(struct work_struct *work); static inline struct rdac_dh_data *get_rdac_data(struct scsi_device *sdev) { @@ -253,7 +268,6 @@ static struct request *rdac_failover_get rdac_pg->subpage_code = 0x1; rdac_pg->page_len[0] = 0x01; rdac_pg->page_len[1] = 0x28; - rdac_pg->lun_table[h->lun] = 0x81; } else { struct rdac_pg_legacy *rdac_pg; @@ -263,7 +277,6 @@ static struct request *rdac_failover_get common = &rdac_pg->common; rdac_pg->page_code = RDAC_PAGE_CODE_REDUNDANT_CONTROLLER; rdac_pg->page_len = 0x68; - rdac_pg->lun_table[h->lun] = 0x81; } common->rdac_mode[1] = RDAC_MODE_TRANSFER_SPECIFIED_LUNS; common->quiescence_timeout = RDAC_QUIESCENCE_TIME; @@ -297,6 +310,7 @@ static void release_controller(struct kr struct rdac_controller *ctlr; ctlr = container_of(kref, struct rdac_controller, kref); + flush_workqueue(kmpath_rdacd); spin_lock(&list_lock); list_del(&ctlr->node); spin_unlock(&list_lock); @@ -326,6 +340,11 @@ static struct rdac_controller *get_contr memcpy(ctlr->slot_id, slot_id, SLOT_ID_LEN); kref_init(&ctlr->kref); ctlr->use_ms10 = -1; + ctlr->ms_queued = 0; + ctlr->ms_sdev = NULL; + spin_lock_init(&ctlr->ms_lock); + INIT_WORK(&ctlr->ms_work, send_mode_select); + INIT_LIST_HEAD(&ctlr->ms_head); list_add(&ctlr->node, &ctlr_list); done: spin_unlock(&list_lock); @@ -445,8 +464,7 @@ static int set_mode_select(struct scsi_d return err; } -static int mode_select_handle_sense(struct scsi_device *sdev, - unsigned char *sensebuf) +static int mode_select_handle_sense(unsigned char *sensebuf) { struct scsi_sense_hdr sense_hdr; int err = SCSI_DH_IO, ret; @@ -478,7 +496,7 @@ static int mode_select_handle_sense(stru err = SCSI_DH_RETRY; break; default: - sdev_printk(KERN_INFO, sdev, + printk(KERN_INFO "MODE_SELECT failed with sense %02x/%02x/%02x.\n", sense_hdr.sense_key, sense_hdr.asc, sense_hdr.ascq); } @@ -487,11 +505,29 @@ done: return err; } -static int send_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h) +static void send_mode_select(struct work_struct *work) { + struct rdac_controller *ctlr = + container_of(work, struct rdac_controller, ms_work); struct request *rq; + struct scsi_device *sdev = ctlr->ms_sdev; + struct rdac_dh_data *h = get_rdac_data(sdev); struct request_queue *q = sdev->request_queue; int err, retry_cnt = RDAC_RETRY_COUNT; + struct rdac_queue_data *tmp, *qdata; + LIST_HEAD(list); + u8 *lun_table; + + spin_lock(&ctlr->ms_lock); + list_splice_init(&ctlr->ms_head, &list); + ctlr->ms_queued = 0; + ctlr->ms_sdev = NULL; + spin_unlock(&ctlr->ms_lock); + + if (ctlr->use_ms10) + lun_table = ctlr->mode_select.expanded.lun_table; + else + lun_table = ctlr->mode_select.legacy.lun_table; retry: err = SCSI_DH_RES_TEMP_UNAVAIL; @@ -499,13 +535,17 @@ retry: if (!rq) goto done; - sdev_printk(KERN_INFO, sdev, "%s MODE_SELECT command.\n", + list_for_each_entry(qdata, &list, entry) { + lun_table[qdata->h->lun] = 0x81; + } + + printk(KERN_INFO "%s MODE_SELECT command.\n", (retry_cnt == RDAC_RETRY_COUNT) ? "queueing" : "retrying"); err = blk_execute_rq(q, NULL, rq, 1); blk_put_request(rq); if (err != SCSI_DH_OK) { - err = mode_select_handle_sense(sdev, h->sense); + err = mode_select_handle_sense(h->sense); if (err == SCSI_DH_RETRY && retry_cnt--) goto retry; } @@ -513,10 +553,45 @@ retry: h->state = RDAC_STATE_ACTIVE; done: - return err; + list_for_each_entry_safe(qdata, tmp, &list, entry) { + list_del(&qdata->entry); + if (err == SCSI_DH_OK) + qdata->h->state = RDAC_STATE_ACTIVE; + if (qdata->callback_fn) + qdata->callback_fn(qdata->callback_data, err); + kfree(qdata); + } + return; } -static int rdac_activate(struct scsi_device *sdev, activate_complete fn, void *data) +static int queue_mode_select(struct scsi_device *sdev, + activate_complete fn, void *data) +{ + struct rdac_queue_data *qdata; + struct rdac_controller *ctlr; + + qdata = kzalloc(sizeof(*qdata), GFP_KERNEL); + if (!qdata) + return SCSI_DH_RETRY; + + qdata->h = get_rdac_data(sdev); + qdata->callback_fn = fn; + qdata->callback_data = data; + + ctlr = qdata->h->ctlr; + spin_lock(&ctlr->ms_lock); + list_add_tail(&qdata->entry, &ctlr->ms_head); + if (!ctlr->ms_queued) { + ctlr->ms_queued = 1; + ctlr->ms_sdev = sdev; + queue_work(kmpath_rdacd, &ctlr->ms_work); + } + spin_unlock(&ctlr->ms_lock); + return SCSI_DH_OK; +} + +static int rdac_activate(struct scsi_device *sdev, + activate_complete fn, void *data) { struct rdac_dh_data *h = get_rdac_data(sdev); int err = SCSI_DH_OK; @@ -536,8 +611,11 @@ static int rdac_activate(struct scsi_dev if (err != SCSI_DH_OK) goto done; } - if (h->lun_state == RDAC_LUN_UNOWNED) - err = send_mode_select(sdev, h); + if (h->lun_state == RDAC_LUN_UNOWNED) { + err = queue_mode_select(sdev, fn, data); + if (err == SCSI_DH_OK) + return 0; + } done: if (fn) fn(data, err); @@ -720,13 +798,26 @@ static int __init rdac_init(void) int r; r = scsi_register_device_handler(&rdac_dh); - if (r != 0) + if (r != 0) { printk(KERN_ERR "Failed to register scsi device handler."); + goto done; + } + + /* + * Create workqueue to handle mode selects for rdac + */ + kmpath_rdacd = create_singlethread_workqueue("kmpath_rdacd"); + if (!kmpath_rdacd) { + scsi_unregister_device_handler(&rdac_dh); + printk(KERN_ERR "kmpath_rdacd creation failed.\n"); + } +done: return r; } static void __exit rdac_exit(void) { + destroy_workqueue(kmpath_rdacd); scsi_unregister_device_handler(&rdac_dh); }