2005-04-16 15:20:36 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2004 SUSE LINUX Products GmbH. All rights reserved.
|
|
|
|
* Copyright (C) 2004 Red Hat, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* This file is released under the GPL.
|
|
|
|
*
|
|
|
|
* Multipath support for EMC CLARiiON AX/CX-series hardware.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dm.h"
|
|
|
|
#include "dm-hw-handler.h"
|
|
|
|
#include <scsi/scsi.h>
|
|
|
|
#include <scsi/scsi_cmnd.h>
|
|
|
|
|
2006-06-26 00:27:35 -07:00
|
|
|
#define DM_MSG_PREFIX "multipath emc"
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
struct emc_handler {
|
|
|
|
spinlock_t lock;
|
|
|
|
|
|
|
|
/* Whether we should send the short trespass command (FC-series)
|
|
|
|
* or the long version (default for AX/CX CLARiiON arrays). */
|
|
|
|
unsigned short_trespass;
|
|
|
|
/* Whether or not to honor SCSI reservations when initiating a
|
|
|
|
* switch-over. Default: Don't. */
|
|
|
|
unsigned hr;
|
|
|
|
|
|
|
|
unsigned char sense[SCSI_SENSE_BUFFERSIZE];
|
|
|
|
};
|
|
|
|
|
|
|
|
#define TRESPASS_PAGE 0x22
|
|
|
|
#define EMC_FAILOVER_TIMEOUT (60 * HZ)
|
|
|
|
|
|
|
|
/* Code borrowed from dm-lsi-rdac by Mike Christie */
|
|
|
|
|
|
|
|
static inline void free_bio(struct bio *bio)
|
|
|
|
{
|
|
|
|
__free_page(bio->bi_io_vec[0].bv_page);
|
|
|
|
bio_put(bio);
|
|
|
|
}
|
|
|
|
|
2007-09-27 03:47:43 -07:00
|
|
|
static void emc_endio(struct bio *bio, int error)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-12-08 03:36:33 -07:00
|
|
|
struct dm_path *path = bio->bi_private;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
/* We also need to look at the sense keys here whether or not to
|
|
|
|
* switch to the next PG etc.
|
|
|
|
*
|
|
|
|
* For now simple logic: either it works or it doesn't.
|
|
|
|
*/
|
|
|
|
if (error)
|
|
|
|
dm_pg_init_complete(path, MP_FAIL_PATH);
|
|
|
|
else
|
|
|
|
dm_pg_init_complete(path, 0);
|
|
|
|
|
|
|
|
/* request is freed in block layer */
|
|
|
|
free_bio(bio);
|
|
|
|
}
|
|
|
|
|
2006-12-08 03:36:33 -07:00
|
|
|
static struct bio *get_failover_bio(struct dm_path *path, unsigned data_size)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
struct page *page;
|
|
|
|
|
|
|
|
bio = bio_alloc(GFP_ATOMIC, 1);
|
|
|
|
if (!bio) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("get_failover_bio: bio_alloc() failed.");
|
2005-04-16 15:20:36 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bio->bi_rw |= (1 << BIO_RW);
|
|
|
|
bio->bi_bdev = path->dev->bdev;
|
|
|
|
bio->bi_sector = 0;
|
|
|
|
bio->bi_private = path;
|
|
|
|
bio->bi_end_io = emc_endio;
|
|
|
|
|
|
|
|
page = alloc_page(GFP_ATOMIC);
|
|
|
|
if (!page) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("get_failover_bio: alloc_page() failed.");
|
2005-04-16 15:20:36 -07:00
|
|
|
bio_put(bio);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bio_add_page(bio, page, data_size, 0) != data_size) {
|
2007-10-19 14:38:56 -07:00
|
|
|
DMERR("get_failover_bio: bio_add_page() failed.");
|
2005-04-16 15:20:36 -07:00
|
|
|
__free_page(page);
|
|
|
|
bio_put(bio);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bio;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct request *get_failover_req(struct emc_handler *h,
|
2006-12-08 03:36:33 -07:00
|
|
|
struct bio *bio, struct dm_path *path)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct request *rq;
|
|
|
|
struct block_device *bdev = bio->bi_bdev;
|
|
|
|
struct request_queue *q = bdev_get_queue(bdev);
|
|
|
|
|
|
|
|
/* FIXME: Figure out why it fails with GFP_ATOMIC. */
|
|
|
|
rq = blk_get_request(q, WRITE, __GFP_WAIT);
|
|
|
|
if (!rq) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("get_failover_req: blk_get_request failed");
|
2005-04-16 15:20:36 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2007-08-16 04:31:28 -07:00
|
|
|
blk_rq_append_bio(q, rq, bio);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
rq->sense = h->sense;
|
|
|
|
memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
|
|
|
|
rq->sense_len = 0;
|
|
|
|
|
|
|
|
memset(&rq->cmd, 0, BLK_MAX_CDB);
|
|
|
|
|
|
|
|
rq->timeout = EMC_FAILOVER_TIMEOUT;
|
2006-08-09 23:44:47 -07:00
|
|
|
rq->cmd_type = REQ_TYPE_BLOCK_PC;
|
|
|
|
rq->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return rq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct request *emc_trespass_get(struct emc_handler *h,
|
2006-12-08 03:36:33 -07:00
|
|
|
struct dm_path *path)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct bio *bio;
|
|
|
|
struct request *rq;
|
|
|
|
unsigned char *page22;
|
|
|
|
unsigned char long_trespass_pg[] = {
|
|
|
|
0, 0, 0, 0,
|
|
|
|
TRESPASS_PAGE, /* Page code */
|
|
|
|
0x09, /* Page length - 2 */
|
|
|
|
h->hr ? 0x01 : 0x81, /* Trespass code + Honor reservation bit */
|
|
|
|
0xff, 0xff, /* Trespass target */
|
|
|
|
0, 0, 0, 0, 0, 0 /* Reserved bytes / unknown */
|
|
|
|
};
|
|
|
|
unsigned char short_trespass_pg[] = {
|
|
|
|
0, 0, 0, 0,
|
|
|
|
TRESPASS_PAGE, /* Page code */
|
|
|
|
0x02, /* Page length - 2 */
|
|
|
|
h->hr ? 0x01 : 0x81, /* Trespass code + Honor reservation bit */
|
|
|
|
0xff, /* Trespass target */
|
|
|
|
};
|
|
|
|
unsigned data_size = h->short_trespass ? sizeof(short_trespass_pg) :
|
|
|
|
sizeof(long_trespass_pg);
|
|
|
|
|
|
|
|
/* get bio backing */
|
|
|
|
if (data_size > PAGE_SIZE)
|
|
|
|
/* this should never happen */
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
bio = get_failover_bio(path, data_size);
|
|
|
|
if (!bio) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("emc_trespass_get: no bio");
|
2005-04-16 15:20:36 -07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
page22 = (unsigned char *)bio_data(bio);
|
|
|
|
memset(page22, 0, data_size);
|
|
|
|
|
|
|
|
memcpy(page22, h->short_trespass ?
|
|
|
|
short_trespass_pg : long_trespass_pg, data_size);
|
|
|
|
|
|
|
|
/* get request for block layer packet command */
|
|
|
|
rq = get_failover_req(h, bio, path);
|
|
|
|
if (!rq) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("emc_trespass_get: no rq");
|
2005-04-16 15:20:36 -07:00
|
|
|
free_bio(bio);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Prepare the command. */
|
|
|
|
rq->cmd[0] = MODE_SELECT;
|
|
|
|
rq->cmd[1] = 0x10;
|
|
|
|
rq->cmd[4] = data_size;
|
|
|
|
rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
|
|
|
|
|
|
|
|
return rq;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void emc_pg_init(struct hw_handler *hwh, unsigned bypassed,
|
2006-12-08 03:36:33 -07:00
|
|
|
struct dm_path *path)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
|
|
|
struct request *rq;
|
|
|
|
struct request_queue *q = bdev_get_queue(path->dev->bdev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We can either blindly init the pg (then look at the sense),
|
|
|
|
* or we can send some commands to get the state here (then
|
|
|
|
* possibly send the fo cmnd), or we can also have the
|
|
|
|
* initial state passed into us and then get an update here.
|
|
|
|
*/
|
|
|
|
if (!q) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMINFO("emc_pg_init: no queue");
|
2005-04-16 15:20:36 -07:00
|
|
|
goto fail_path;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* FIXME: The request should be pre-allocated. */
|
|
|
|
rq = emc_trespass_get(hwh->context, path);
|
|
|
|
if (!rq) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("emc_pg_init: no rq");
|
2005-04-16 15:20:36 -07:00
|
|
|
goto fail_path;
|
|
|
|
}
|
|
|
|
|
2006-06-26 00:27:35 -07:00
|
|
|
DMINFO("emc_pg_init: sending switch-over command");
|
2005-04-16 15:20:36 -07:00
|
|
|
elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
|
|
|
|
return;
|
|
|
|
|
|
|
|
fail_path:
|
|
|
|
dm_pg_init_complete(path, MP_FAIL_PATH);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct emc_handler *alloc_emc_handler(void)
|
|
|
|
{
|
2007-10-19 14:38:51 -07:00
|
|
|
struct emc_handler *h = kzalloc(sizeof(*h), GFP_KERNEL);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2007-10-19 14:38:51 -07:00
|
|
|
if (h)
|
2005-04-16 15:20:36 -07:00
|
|
|
spin_lock_init(&h->lock);
|
|
|
|
|
|
|
|
return h;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int emc_create(struct hw_handler *hwh, unsigned argc, char **argv)
|
|
|
|
{
|
|
|
|
struct emc_handler *h;
|
|
|
|
unsigned hr, short_trespass;
|
|
|
|
|
|
|
|
if (argc == 0) {
|
|
|
|
/* No arguments: use defaults */
|
|
|
|
hr = 0;
|
|
|
|
short_trespass = 0;
|
|
|
|
} else if (argc != 2) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("incorrect number of arguments");
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EINVAL;
|
|
|
|
} else {
|
|
|
|
if ((sscanf(argv[0], "%u", &short_trespass) != 1)
|
|
|
|
|| (short_trespass > 1)) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("invalid trespass mode selected");
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((sscanf(argv[1], "%u", &hr) != 1)
|
|
|
|
|| (hr > 1)) {
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("invalid honor reservation flag selected");
|
2005-04-16 15:20:36 -07:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
h = alloc_emc_handler();
|
|
|
|
if (!h)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
hwh->context = h;
|
|
|
|
|
|
|
|
if ((h->short_trespass = short_trespass))
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("short trespass command will be send");
|
2005-04-16 15:20:36 -07:00
|
|
|
else
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("long trespass command will be send");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
if ((h->hr = hr))
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("honor reservation bit will be set");
|
2005-04-16 15:20:36 -07:00
|
|
|
else
|
2006-06-26 00:27:35 -07:00
|
|
|
DMWARN("honor reservation bit will not be set (default)");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void emc_destroy(struct hw_handler *hwh)
|
|
|
|
{
|
|
|
|
struct emc_handler *h = (struct emc_handler *) hwh->context;
|
|
|
|
|
|
|
|
kfree(h);
|
|
|
|
hwh->context = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned emc_error(struct hw_handler *hwh, struct bio *bio)
|
|
|
|
{
|
|
|
|
/* FIXME: Patch from axboe still missing */
|
|
|
|
#if 0
|
|
|
|
int sense;
|
|
|
|
|
|
|
|
if (bio->bi_error & BIO_SENSE) {
|
|
|
|
sense = bio->bi_error & 0xffffff; /* sense key / asc / ascq */
|
|
|
|
|
|
|
|
if (sense == 0x020403) {
|
|
|
|
/* LUN Not Ready - Manual Intervention Required
|
|
|
|
* indicates this is a passive path.
|
|
|
|
*
|
|
|
|
* FIXME: However, if this is seen and EVPD C0
|
|
|
|
* indicates that this is due to a NDU in
|
|
|
|
* progress, we should set FAIL_PATH too.
|
|
|
|
* This indicates we might have to do a SCSI
|
|
|
|
* inquiry in the end_io path. Ugh. */
|
|
|
|
return MP_BYPASS_PG | MP_RETRY_IO;
|
|
|
|
} else if (sense == 0x052501) {
|
|
|
|
/* An array based copy is in progress. Do not
|
|
|
|
* fail the path, do not bypass to another PG,
|
|
|
|
* do not retry. Fail the IO immediately.
|
|
|
|
* (Actually this is the same conclusion as in
|
|
|
|
* the default handler, but lets make sure.) */
|
|
|
|
return 0;
|
|
|
|
} else if (sense == 0x062900) {
|
|
|
|
/* Unit Attention Code. This is the first IO
|
|
|
|
* to the new path, so just retry. */
|
|
|
|
return MP_RETRY_IO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Try default handler */
|
|
|
|
return dm_scsi_err_handler(hwh, bio);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hw_handler_type emc_hwh = {
|
|
|
|
.name = "emc",
|
|
|
|
.module = THIS_MODULE,
|
|
|
|
.create = emc_create,
|
|
|
|
.destroy = emc_destroy,
|
|
|
|
.pg_init = emc_pg_init,
|
|
|
|
.error = emc_error,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init dm_emc_init(void)
|
|
|
|
{
|
|
|
|
int r = dm_register_hw_handler(&emc_hwh);
|
|
|
|
|
|
|
|
if (r < 0)
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("register failed %d", r);
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-06-26 00:27:35 -07:00
|
|
|
DMINFO("version 0.0.3 loaded");
|
2005-04-16 15:20:36 -07:00
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit dm_emc_exit(void)
|
|
|
|
{
|
|
|
|
int r = dm_unregister_hw_handler(&emc_hwh);
|
|
|
|
|
|
|
|
if (r < 0)
|
2006-06-26 00:27:35 -07:00
|
|
|
DMERR("unregister failed %d", r);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
module_init(dm_emc_init);
|
|
|
|
module_exit(dm_emc_exit);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION(DM_NAME " EMC CX/AX/FC-family multipath");
|
|
|
|
MODULE_AUTHOR("Lars Marowsky-Bree <lmb@suse.de>");
|
|
|
|
MODULE_LICENSE("GPL");
|