Skip to content

Commit ca9f008

Browse files
hreineckejejb
authored andcommitted
[SCSI] scsi_dh: Update RDAC device handler
This patch updates the RDAC device handler to refuse to attach to devices not supporting the RDAC vpd pages. Signed-off-by: Hannes Reinecke <hare@suse.de> Signed-off-by: Chandra Seetharaman <sekharan@us.ibm.com> Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
1 parent 2aef6d5 commit ca9f008

1 file changed

Lines changed: 94 additions & 69 deletions

File tree

‎drivers/scsi/device_handler/scsi_dh_rdac.c‎

Lines changed: 94 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ struct rdac_dh_data {
173173
#define RDAC_STATE_ACTIVE 0
174174
#define RDAC_STATE_PASSIVE 1
175175
unsigned char state;
176+
177+
#define RDAC_LUN_UNOWNED 0
178+
#define RDAC_LUN_OWNED 1
179+
#define RDAC_LUN_AVT 2
180+
char lun_state;
176181
unsigned char sense[SCSI_SENSE_BUFFERSIZE];
177182
union {
178183
struct c2_inquiry c2;
@@ -182,6 +187,13 @@ struct rdac_dh_data {
182187
} inq;
183188
};
184189

190+
static const char *lun_state[] =
191+
{
192+
"unowned",
193+
"owned",
194+
"owned (AVT mode)",
195+
};
196+
185197
static LIST_HEAD(ctlr_list);
186198
static DEFINE_SPINLOCK(list_lock);
187199

@@ -197,27 +209,23 @@ static struct request *get_rdac_req(struct scsi_device *sdev,
197209
{
198210
struct request *rq;
199211
struct request_queue *q = sdev->request_queue;
200-
struct rdac_dh_data *h = get_rdac_data(sdev);
201212

202-
rq = blk_get_request(q, rw, GFP_KERNEL);
213+
rq = blk_get_request(q, rw, GFP_NOIO);
203214

204215
if (!rq) {
205216
sdev_printk(KERN_INFO, sdev,
206217
"get_rdac_req: blk_get_request failed.\n");
207218
return NULL;
208219
}
209220

210-
if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_KERNEL)) {
221+
if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) {
211222
blk_put_request(rq);
212223
sdev_printk(KERN_INFO, sdev,
213224
"get_rdac_req: blk_rq_map_kern failed.\n");
214225
return NULL;
215226
}
216227

217-
memset(&rq->cmd, 0, BLK_MAX_CDB);
218-
rq->sense = h->sense;
219-
memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
220-
rq->sense_len = 0;
228+
memset(rq->cmd, 0, BLK_MAX_CDB);
221229

222230
rq->cmd_type = REQ_TYPE_BLOCK_PC;
223231
rq->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE;
@@ -227,12 +235,12 @@ static struct request *get_rdac_req(struct scsi_device *sdev,
227235
return rq;
228236
}
229237

230-
static struct request *rdac_failover_get(struct scsi_device *sdev)
238+
static struct request *rdac_failover_get(struct scsi_device *sdev,
239+
struct rdac_dh_data *h)
231240
{
232241
struct request *rq;
233242
struct rdac_mode_common *common;
234243
unsigned data_size;
235-
struct rdac_dh_data *h = get_rdac_data(sdev);
236244

237245
if (h->ctlr->use_ms10) {
238246
struct rdac_pg_expanded *rdac_pg;
@@ -277,6 +285,10 @@ static struct request *rdac_failover_get(struct scsi_device *sdev)
277285
}
278286
rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
279287

288+
rq->sense = h->sense;
289+
memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
290+
rq->sense_len = 0;
291+
280292
return rq;
281293
}
282294

@@ -321,11 +333,10 @@ static struct rdac_controller *get_controller(u8 *subsys_id, u8 *slot_id)
321333
}
322334

323335
static int submit_inquiry(struct scsi_device *sdev, int page_code,
324-
unsigned int len)
336+
unsigned int len, struct rdac_dh_data *h)
325337
{
326338
struct request *rq;
327339
struct request_queue *q = sdev->request_queue;
328-
struct rdac_dh_data *h = get_rdac_data(sdev);
329340
int err = SCSI_DH_RES_TEMP_UNAVAIL;
330341

331342
rq = get_rdac_req(sdev, &h->inq, len, READ);
@@ -338,59 +349,68 @@ static int submit_inquiry(struct scsi_device *sdev, int page_code,
338349
rq->cmd[2] = page_code;
339350
rq->cmd[4] = len;
340351
rq->cmd_len = COMMAND_SIZE(INQUIRY);
352+
353+
rq->sense = h->sense;
354+
memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE);
355+
rq->sense_len = 0;
356+
341357
err = blk_execute_rq(q, NULL, rq, 1);
342358
if (err == -EIO)
343359
err = SCSI_DH_IO;
360+
361+
blk_put_request(rq);
344362
done:
345363
return err;
346364
}
347365

348-
static int get_lun(struct scsi_device *sdev)
366+
static int get_lun(struct scsi_device *sdev, struct rdac_dh_data *h)
349367
{
350368
int err;
351369
struct c8_inquiry *inqp;
352-
struct rdac_dh_data *h = get_rdac_data(sdev);
353370

354-
err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry));
371+
err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h);
355372
if (err == SCSI_DH_OK) {
356373
inqp = &h->inq.c8;
357-
h->lun = inqp->lun[7]; /* currently it uses only one byte */
374+
if (inqp->page_code != 0xc8)
375+
return SCSI_DH_NOSYS;
376+
if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' ||
377+
inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd')
378+
return SCSI_DH_NOSYS;
379+
h->lun = scsilun_to_int((struct scsi_lun *)inqp->lun);
358380
}
359381
return err;
360382
}
361383

362-
#define RDAC_OWNED 0
363-
#define RDAC_UNOWNED 1
364-
#define RDAC_FAILED 2
365-
static int check_ownership(struct scsi_device *sdev)
384+
static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h)
366385
{
367386
int err;
368387
struct c9_inquiry *inqp;
369-
struct rdac_dh_data *h = get_rdac_data(sdev);
370388

371-
err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry));
389+
err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h);
372390
if (err == SCSI_DH_OK) {
373-
err = RDAC_UNOWNED;
374391
inqp = &h->inq.c9;
375-
/*
376-
* If in AVT mode or if the path already owns the LUN,
377-
* return RDAC_OWNED;
378-
*/
379-
if (((inqp->avte_cvp >> 7) == 0x1) ||
380-
((inqp->avte_cvp & 0x1) != 0))
381-
err = RDAC_OWNED;
382-
} else
383-
err = RDAC_FAILED;
392+
if ((inqp->avte_cvp >> 7) == 0x1) {
393+
/* LUN in AVT mode */
394+
sdev_printk(KERN_NOTICE, sdev,
395+
"%s: AVT mode detected\n",
396+
RDAC_NAME);
397+
h->lun_state = RDAC_LUN_AVT;
398+
} else if ((inqp->avte_cvp & 0x1) != 0) {
399+
/* LUN was owned by the controller */
400+
h->lun_state = RDAC_LUN_OWNED;
401+
}
402+
}
403+
384404
return err;
385405
}
386406

387-
static int initialize_controller(struct scsi_device *sdev)
407+
static int initialize_controller(struct scsi_device *sdev,
408+
struct rdac_dh_data *h)
388409
{
389410
int err;
390411
struct c4_inquiry *inqp;
391-
struct rdac_dh_data *h = get_rdac_data(sdev);
392412

393-
err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry));
413+
err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h);
394414
if (err == SCSI_DH_OK) {
395415
inqp = &h->inq.c4;
396416
h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id);
@@ -400,13 +420,12 @@ static int initialize_controller(struct scsi_device *sdev)
400420
return err;
401421
}
402422

403-
static int set_mode_select(struct scsi_device *sdev)
423+
static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
404424
{
405425
int err;
406426
struct c2_inquiry *inqp;
407-
struct rdac_dh_data *h = get_rdac_data(sdev);
408427

409-
err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry));
428+
err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h);
410429
if (err == SCSI_DH_OK) {
411430
inqp = &h->inq.c2;
412431
/*
@@ -421,13 +440,13 @@ static int set_mode_select(struct scsi_device *sdev)
421440
return err;
422441
}
423442

424-
static int mode_select_handle_sense(struct scsi_device *sdev)
443+
static int mode_select_handle_sense(struct scsi_device *sdev,
444+
unsigned char *sensebuf)
425445
{
426446
struct scsi_sense_hdr sense_hdr;
427-
struct rdac_dh_data *h = get_rdac_data(sdev);
428447
int sense, err = SCSI_DH_IO, ret;
429448

430-
ret = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
449+
ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr);
431450
if (!ret)
432451
goto done;
433452

@@ -451,24 +470,25 @@ static int mode_select_handle_sense(struct scsi_device *sdev)
451470
return err;
452471
}
453472

454-
static int send_mode_select(struct scsi_device *sdev)
473+
static int send_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h)
455474
{
456475
struct request *rq;
457476
struct request_queue *q = sdev->request_queue;
458-
struct rdac_dh_data *h = get_rdac_data(sdev);
459477
int err = SCSI_DH_RES_TEMP_UNAVAIL;
460478

461-
rq = rdac_failover_get(sdev);
479+
rq = rdac_failover_get(sdev, h);
462480
if (!rq)
463481
goto done;
464482

465483
sdev_printk(KERN_INFO, sdev, "queueing MODE_SELECT command.\n");
466484

467485
err = blk_execute_rq(q, NULL, rq, 1);
468486
if (err != SCSI_DH_OK)
469-
err = mode_select_handle_sense(sdev);
487+
err = mode_select_handle_sense(sdev, h->sense);
470488
if (err == SCSI_DH_OK)
471489
h->state = RDAC_STATE_ACTIVE;
490+
491+
blk_put_request(rq);
472492
done:
473493
return err;
474494
}
@@ -478,38 +498,23 @@ static int rdac_activate(struct scsi_device *sdev)
478498
struct rdac_dh_data *h = get_rdac_data(sdev);
479499
int err = SCSI_DH_OK;
480500

481-
if (h->lun == UNINITIALIZED_LUN) {
482-
err = get_lun(sdev);
483-
if (err != SCSI_DH_OK)
484-
goto done;
485-
}
486-
487-
err = check_ownership(sdev);
488-
switch (err) {
489-
case RDAC_UNOWNED:
490-
break;
491-
case RDAC_OWNED:
492-
err = SCSI_DH_OK;
493-
goto done;
494-
case RDAC_FAILED:
495-
default:
496-
err = SCSI_DH_IO;
501+
err = check_ownership(sdev, h);
502+
if (err != SCSI_DH_OK)
497503
goto done;
498-
}
499504

500505
if (!h->ctlr) {
501-
err = initialize_controller(sdev);
506+
err = initialize_controller(sdev, h);
502507
if (err != SCSI_DH_OK)
503508
goto done;
504509
}
505510

506511
if (h->ctlr->use_ms10 == -1) {
507-
err = set_mode_select(sdev);
512+
err = set_mode_select(sdev, h);
508513
if (err != SCSI_DH_OK)
509514
goto done;
510515
}
511-
512-
err = send_mode_select(sdev);
516+
if (h->lun_state == RDAC_LUN_UNOWNED)
517+
err = send_mode_select(sdev, h);
513518
done:
514519
return err;
515520
}
@@ -606,11 +611,12 @@ static int rdac_bus_attach(struct scsi_device *sdev)
606611
struct scsi_dh_data *scsi_dh_data;
607612
struct rdac_dh_data *h;
608613
unsigned long flags;
614+
int err;
609615

610616
scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *)
611617
+ sizeof(*h) , GFP_KERNEL);
612618
if (!scsi_dh_data) {
613-
sdev_printk(KERN_ERR, sdev, "Attach failed %s.\n",
619+
sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n",
614620
RDAC_NAME);
615621
return 0;
616622
}
@@ -619,14 +625,33 @@ static int rdac_bus_attach(struct scsi_device *sdev)
619625
h = (struct rdac_dh_data *) scsi_dh_data->buf;
620626
h->lun = UNINITIALIZED_LUN;
621627
h->state = RDAC_STATE_ACTIVE;
628+
629+
err = get_lun(sdev, h);
630+
if (err != SCSI_DH_OK)
631+
goto failed;
632+
633+
err = check_ownership(sdev, h);
634+
if (err != SCSI_DH_OK)
635+
goto failed;
636+
637+
if (!try_module_get(THIS_MODULE))
638+
goto failed;
639+
622640
spin_lock_irqsave(sdev->request_queue->queue_lock, flags);
623641
sdev->scsi_dh_data = scsi_dh_data;
624642
spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags);
625-
try_module_get(THIS_MODULE);
626643

627-
sdev_printk(KERN_NOTICE, sdev, "Attached %s\n", RDAC_NAME);
644+
sdev_printk(KERN_NOTICE, sdev,
645+
"%s: LUN %d (%s)\n",
646+
RDAC_NAME, h->lun, lun_state[(int)h->lun_state]);
628647

629648
return 0;
649+
650+
failed:
651+
kfree(scsi_dh_data);
652+
sdev_printk(KERN_ERR, sdev, "%s: not attached\n",
653+
RDAC_NAME);
654+
return -EINVAL;
630655
}
631656

632657
static void rdac_bus_detach( struct scsi_device *sdev )
@@ -645,7 +670,7 @@ static void rdac_bus_detach( struct scsi_device *sdev )
645670
kref_put(&h->ctlr->kref, release_controller);
646671
kfree(scsi_dh_data);
647672
module_put(THIS_MODULE);
648-
sdev_printk(KERN_NOTICE, sdev, "Detached %s\n", RDAC_NAME);
673+
sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME);
649674
}
650675

651676

0 commit comments

Comments
 (0)