2 * Copyright (C) 2005 Mike Christie, All rights reserved.
3 * Copyright (C) 2007 Red Hat, Inc. All rights reserved.
4 * Authors: Mike Christie
7 * This file is released under the GPL.
9 * This module implements the specific path activation code for
10 * HP StorageWorks and FSC FibreCat Asymmetric (Active/Passive)
12 * These storage arrays have controller-based failover, not
13 * LUN-based failover. However, LUN-based failover is the design
14 * of dm-multipath. Thus, this module is written for LUN-based failover.
16 #include <linux/blkdev.h>
17 #include <linux/list.h>
18 #include <linux/types.h>
19 #include <scsi/scsi.h>
20 #include <scsi/scsi_cmnd.h>
23 #include "dm-hw-handler.h"
25 #define DM_MSG_PREFIX "multipath hp-sw"
26 #define DM_HP_HWH_NAME "hp-sw"
27 #define DM_HP_HWH_VER "0.0.3"
29 struct hp_sw_context {
30 unsigned char sense[SCSI_SENSE_BUFFERSIZE];
34 * hp_sw_end_io - Completion handler for HP path activation.
35 * @req: path activation request
36 * @error: scsi-ml error
38 * Check sense data, free request structure, and notify dm that
39 * pg initialization has completed.
41 * Context: scsi-ml softirq
43 * Possible optimizations
44 * 1. Actually check sense data for retryable error (e.g. NOT_READY)
46 static void hp_sw_end_io(struct request *req, int error)
48 struct dm_path *path = req->end_io_data;
49 unsigned err_flags = 0;
52 DMDEBUG("%s path activation command - success",
55 DMWARN("%s path activation command - error=0x%x",
56 path->dev->name, error);
57 err_flags = MP_FAIL_PATH;
60 req->end_io_data = NULL;
61 __blk_put_request(req->q, req);
62 dm_pg_init_complete(path, err_flags);
66 * hp_sw_get_request - Allocate an HP specific path activation request
67 * @path: path on which request will be sent (needed for request queue)
69 * The START command is used for path activation request.
70 * These arrays are controller-based failover, not LUN based.
71 * One START command issued to a single path will fail over all
72 * LUNs for the same controller.
74 * Possible optimizations
75 * 1. Make timeout configurable
76 * 2. Preallocate request
78 static struct request *hp_sw_get_request(struct dm_path *path)
81 struct block_device *bdev = path->dev->bdev;
82 struct request_queue *q = bdev_get_queue(bdev);
83 struct hp_sw_context *h = path->hwhcontext;
85 req = blk_get_request(q, WRITE, GFP_NOIO);
89 req->timeout = 60 * HZ;
92 req->cmd_type = REQ_TYPE_BLOCK_PC;
93 req->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
94 req->end_io_data = path;
95 req->sense = h->sense;
96 memset(req->sense, 0, SCSI_SENSE_BUFFERSIZE);
98 memset(&req->cmd, 0, BLK_MAX_CDB);
99 req->cmd[0] = START_STOP;
101 req->cmd_len = COMMAND_SIZE(req->cmd[0]);
108 * hp_sw_pg_init - HP path activation implementation.
109 * @hwh: hardware handler specific data
110 * @bypassed: unused; is the path group bypassed? (see dm-mpath.c)
111 * @path: path to send initialization command
113 * Send an HP-specific path activation command on 'path'.
114 * Do not try to optimize in any way, just send the activation command.
115 * More than one path activation command may be sent to the same controller.
116 * This seems to work fine for basic failover support.
118 * Possible optimizations
119 * 1. Detect an in-progress activation request and avoid submitting another one
120 * 2. Model the controller and only send a single activation request at a time
121 * 3. Determine the state of a path before sending an activation request
123 * Context: kmpathd (see process_queued_ios() in dm-mpath.c)
125 static void hp_sw_pg_init(struct hw_handler *hwh, unsigned bypassed,
126 struct dm_path *path)
129 struct hp_sw_context *h;
131 path->hwhcontext = hwh->context;
134 req = hp_sw_get_request(path);
136 DMERR("%s path activation command - allocation fail",
141 DMDEBUG("%s path activation command - sent", path->dev->name);
143 blk_execute_rq_nowait(req->q, NULL, req, 1, hp_sw_end_io);
147 dm_pg_init_complete(path, MP_FAIL_PATH);
150 static int hp_sw_create(struct hw_handler *hwh, unsigned argc, char **argv)
152 struct hp_sw_context *h;
154 h = kmalloc(sizeof(*h), GFP_KERNEL);
163 static void hp_sw_destroy(struct hw_handler *hwh)
165 struct hp_sw_context *h = hwh->context;
170 static struct hw_handler_type hp_sw_hwh = {
171 .name = DM_HP_HWH_NAME,
172 .module = THIS_MODULE,
173 .create = hp_sw_create,
174 .destroy = hp_sw_destroy,
175 .pg_init = hp_sw_pg_init,
178 static int __init hp_sw_init(void)
182 r = dm_register_hw_handler(&hp_sw_hwh);
184 DMERR("register failed %d", r);
186 DMINFO("version " DM_HP_HWH_VER " loaded");
191 static void __exit hp_sw_exit(void)
195 r = dm_unregister_hw_handler(&hp_sw_hwh);
197 DMERR("unregister failed %d", r);
200 module_init(hp_sw_init);
201 module_exit(hp_sw_exit);
203 MODULE_DESCRIPTION("DM Multipath HP StorageWorks / FSC FibreCat (A/P) support");
204 MODULE_AUTHOR("Mike Christie, Dave Wysochanski <dm-devel@redhat.com>");
205 MODULE_LICENSE("GPL");
206 MODULE_VERSION(DM_HP_HWH_VER);