[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>

authored by

Hannes Reinecke and committed by
James Bottomley
ca9f0089 2aef6d5c

+94 -69
+94 -69
drivers/scsi/device_handler/scsi_dh_rdac.c
··· 173 173 #define RDAC_STATE_ACTIVE 0 174 174 #define RDAC_STATE_PASSIVE 1 175 175 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; 176 181 unsigned char sense[SCSI_SENSE_BUFFERSIZE]; 177 182 union { 178 183 struct c2_inquiry c2; ··· 185 180 struct c8_inquiry c8; 186 181 struct c9_inquiry c9; 187 182 } inq; 183 + }; 184 + 185 + static const char *lun_state[] = 186 + { 187 + "unowned", 188 + "owned", 189 + "owned (AVT mode)", 188 190 }; 189 191 190 192 static LIST_HEAD(ctlr_list); ··· 209 197 { 210 198 struct request *rq; 211 199 struct request_queue *q = sdev->request_queue; 212 - struct rdac_dh_data *h = get_rdac_data(sdev); 213 200 214 - rq = blk_get_request(q, rw, GFP_KERNEL); 201 + rq = blk_get_request(q, rw, GFP_NOIO); 215 202 216 203 if (!rq) { 217 204 sdev_printk(KERN_INFO, sdev, ··· 218 207 return NULL; 219 208 } 220 209 221 - if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_KERNEL)) { 210 + if (buflen && blk_rq_map_kern(q, rq, buffer, buflen, GFP_NOIO)) { 222 211 blk_put_request(rq); 223 212 sdev_printk(KERN_INFO, sdev, 224 213 "get_rdac_req: blk_rq_map_kern failed.\n"); 225 214 return NULL; 226 215 } 227 216 228 - memset(&rq->cmd, 0, BLK_MAX_CDB); 229 - rq->sense = h->sense; 230 - memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); 231 - rq->sense_len = 0; 217 + memset(rq->cmd, 0, BLK_MAX_CDB); 232 218 233 219 rq->cmd_type = REQ_TYPE_BLOCK_PC; 234 220 rq->cmd_flags |= REQ_FAILFAST | REQ_NOMERGE; ··· 235 227 return rq; 236 228 } 237 229 238 - static struct request *rdac_failover_get(struct scsi_device *sdev) 230 + static struct request *rdac_failover_get(struct scsi_device *sdev, 231 + struct rdac_dh_data *h) 239 232 { 240 233 struct request *rq; 241 234 struct rdac_mode_common *common; 242 235 unsigned data_size; 243 - struct rdac_dh_data *h = get_rdac_data(sdev); 244 236 245 237 if (h->ctlr->use_ms10) { 246 238 struct rdac_pg_expanded *rdac_pg; ··· 284 276 rq->cmd[4] = data_size; 285 277 } 286 278 rq->cmd_len = COMMAND_SIZE(rq->cmd[0]); 279 + 280 + rq->sense = h->sense; 281 + memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); 282 + rq->sense_len = 0; 287 283 288 284 return rq; 289 285 } ··· 333 321 } 334 322 335 323 static int submit_inquiry(struct scsi_device *sdev, int page_code, 336 - unsigned int len) 324 + unsigned int len, struct rdac_dh_data *h) 337 325 { 338 326 struct request *rq; 339 327 struct request_queue *q = sdev->request_queue; 340 - struct rdac_dh_data *h = get_rdac_data(sdev); 341 328 int err = SCSI_DH_RES_TEMP_UNAVAIL; 342 329 343 330 rq = get_rdac_req(sdev, &h->inq, len, READ); ··· 349 338 rq->cmd[2] = page_code; 350 339 rq->cmd[4] = len; 351 340 rq->cmd_len = COMMAND_SIZE(INQUIRY); 341 + 342 + rq->sense = h->sense; 343 + memset(rq->sense, 0, SCSI_SENSE_BUFFERSIZE); 344 + rq->sense_len = 0; 345 + 352 346 err = blk_execute_rq(q, NULL, rq, 1); 353 347 if (err == -EIO) 354 348 err = SCSI_DH_IO; 349 + 350 + blk_put_request(rq); 355 351 done: 356 352 return err; 357 353 } 358 354 359 - static int get_lun(struct scsi_device *sdev) 355 + static int get_lun(struct scsi_device *sdev, struct rdac_dh_data *h) 360 356 { 361 357 int err; 362 358 struct c8_inquiry *inqp; 363 - struct rdac_dh_data *h = get_rdac_data(sdev); 364 359 365 - err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry)); 360 + err = submit_inquiry(sdev, 0xC8, sizeof(struct c8_inquiry), h); 366 361 if (err == SCSI_DH_OK) { 367 362 inqp = &h->inq.c8; 368 - h->lun = inqp->lun[7]; /* currently it uses only one byte */ 363 + if (inqp->page_code != 0xc8) 364 + return SCSI_DH_NOSYS; 365 + if (inqp->page_id[0] != 'e' || inqp->page_id[1] != 'd' || 366 + inqp->page_id[2] != 'i' || inqp->page_id[3] != 'd') 367 + return SCSI_DH_NOSYS; 368 + h->lun = scsilun_to_int((struct scsi_lun *)inqp->lun); 369 369 } 370 370 return err; 371 371 } 372 372 373 - #define RDAC_OWNED 0 374 - #define RDAC_UNOWNED 1 375 - #define RDAC_FAILED 2 376 - static int check_ownership(struct scsi_device *sdev) 373 + static int check_ownership(struct scsi_device *sdev, struct rdac_dh_data *h) 377 374 { 378 375 int err; 379 376 struct c9_inquiry *inqp; 380 - struct rdac_dh_data *h = get_rdac_data(sdev); 381 377 382 - err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry)); 378 + err = submit_inquiry(sdev, 0xC9, sizeof(struct c9_inquiry), h); 383 379 if (err == SCSI_DH_OK) { 384 - err = RDAC_UNOWNED; 385 380 inqp = &h->inq.c9; 386 - /* 387 - * If in AVT mode or if the path already owns the LUN, 388 - * return RDAC_OWNED; 389 - */ 390 - if (((inqp->avte_cvp >> 7) == 0x1) || 391 - ((inqp->avte_cvp & 0x1) != 0)) 392 - err = RDAC_OWNED; 393 - } else 394 - err = RDAC_FAILED; 381 + if ((inqp->avte_cvp >> 7) == 0x1) { 382 + /* LUN in AVT mode */ 383 + sdev_printk(KERN_NOTICE, sdev, 384 + "%s: AVT mode detected\n", 385 + RDAC_NAME); 386 + h->lun_state = RDAC_LUN_AVT; 387 + } else if ((inqp->avte_cvp & 0x1) != 0) { 388 + /* LUN was owned by the controller */ 389 + h->lun_state = RDAC_LUN_OWNED; 390 + } 391 + } 392 + 395 393 return err; 396 394 } 397 395 398 - static int initialize_controller(struct scsi_device *sdev) 396 + static int initialize_controller(struct scsi_device *sdev, 397 + struct rdac_dh_data *h) 399 398 { 400 399 int err; 401 400 struct c4_inquiry *inqp; 402 - struct rdac_dh_data *h = get_rdac_data(sdev); 403 401 404 - err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry)); 402 + err = submit_inquiry(sdev, 0xC4, sizeof(struct c4_inquiry), h); 405 403 if (err == SCSI_DH_OK) { 406 404 inqp = &h->inq.c4; 407 405 h->ctlr = get_controller(inqp->subsys_id, inqp->slot_id); ··· 420 400 return err; 421 401 } 422 402 423 - static int set_mode_select(struct scsi_device *sdev) 403 + static int set_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h) 424 404 { 425 405 int err; 426 406 struct c2_inquiry *inqp; 427 - struct rdac_dh_data *h = get_rdac_data(sdev); 428 407 429 - err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry)); 408 + err = submit_inquiry(sdev, 0xC2, sizeof(struct c2_inquiry), h); 430 409 if (err == SCSI_DH_OK) { 431 410 inqp = &h->inq.c2; 432 411 /* ··· 440 421 return err; 441 422 } 442 423 443 - static int mode_select_handle_sense(struct scsi_device *sdev) 424 + static int mode_select_handle_sense(struct scsi_device *sdev, 425 + unsigned char *sensebuf) 444 426 { 445 427 struct scsi_sense_hdr sense_hdr; 446 - struct rdac_dh_data *h = get_rdac_data(sdev); 447 428 int sense, err = SCSI_DH_IO, ret; 448 429 449 - ret = scsi_normalize_sense(h->sense, SCSI_SENSE_BUFFERSIZE, &sense_hdr); 430 + ret = scsi_normalize_sense(sensebuf, SCSI_SENSE_BUFFERSIZE, &sense_hdr); 450 431 if (!ret) 451 432 goto done; 452 433 ··· 470 451 return err; 471 452 } 472 453 473 - static int send_mode_select(struct scsi_device *sdev) 454 + static int send_mode_select(struct scsi_device *sdev, struct rdac_dh_data *h) 474 455 { 475 456 struct request *rq; 476 457 struct request_queue *q = sdev->request_queue; 477 - struct rdac_dh_data *h = get_rdac_data(sdev); 478 458 int err = SCSI_DH_RES_TEMP_UNAVAIL; 479 459 480 - rq = rdac_failover_get(sdev); 460 + rq = rdac_failover_get(sdev, h); 481 461 if (!rq) 482 462 goto done; 483 463 ··· 484 466 485 467 err = blk_execute_rq(q, NULL, rq, 1); 486 468 if (err != SCSI_DH_OK) 487 - err = mode_select_handle_sense(sdev); 469 + err = mode_select_handle_sense(sdev, h->sense); 488 470 if (err == SCSI_DH_OK) 489 471 h->state = RDAC_STATE_ACTIVE; 472 + 473 + blk_put_request(rq); 490 474 done: 491 475 return err; 492 476 } ··· 498 478 struct rdac_dh_data *h = get_rdac_data(sdev); 499 479 int err = SCSI_DH_OK; 500 480 501 - if (h->lun == UNINITIALIZED_LUN) { 502 - err = get_lun(sdev); 503 - if (err != SCSI_DH_OK) 504 - goto done; 505 - } 506 - 507 - err = check_ownership(sdev); 508 - switch (err) { 509 - case RDAC_UNOWNED: 510 - break; 511 - case RDAC_OWNED: 512 - err = SCSI_DH_OK; 481 + err = check_ownership(sdev, h); 482 + if (err != SCSI_DH_OK) 513 483 goto done; 514 - case RDAC_FAILED: 515 - default: 516 - err = SCSI_DH_IO; 517 - goto done; 518 - } 519 484 520 485 if (!h->ctlr) { 521 - err = initialize_controller(sdev); 486 + err = initialize_controller(sdev, h); 522 487 if (err != SCSI_DH_OK) 523 488 goto done; 524 489 } 525 490 526 491 if (h->ctlr->use_ms10 == -1) { 527 - err = set_mode_select(sdev); 492 + err = set_mode_select(sdev, h); 528 493 if (err != SCSI_DH_OK) 529 494 goto done; 530 495 } 531 - 532 - err = send_mode_select(sdev); 496 + if (h->lun_state == RDAC_LUN_UNOWNED) 497 + err = send_mode_select(sdev, h); 533 498 done: 534 499 return err; 535 500 } ··· 611 606 struct scsi_dh_data *scsi_dh_data; 612 607 struct rdac_dh_data *h; 613 608 unsigned long flags; 609 + int err; 614 610 615 611 scsi_dh_data = kzalloc(sizeof(struct scsi_device_handler *) 616 612 + sizeof(*h) , GFP_KERNEL); 617 613 if (!scsi_dh_data) { 618 - sdev_printk(KERN_ERR, sdev, "Attach failed %s.\n", 614 + sdev_printk(KERN_ERR, sdev, "%s: Attach failed\n", 619 615 RDAC_NAME); 620 616 return 0; 621 617 } ··· 625 619 h = (struct rdac_dh_data *) scsi_dh_data->buf; 626 620 h->lun = UNINITIALIZED_LUN; 627 621 h->state = RDAC_STATE_ACTIVE; 622 + 623 + err = get_lun(sdev, h); 624 + if (err != SCSI_DH_OK) 625 + goto failed; 626 + 627 + err = check_ownership(sdev, h); 628 + if (err != SCSI_DH_OK) 629 + goto failed; 630 + 631 + if (!try_module_get(THIS_MODULE)) 632 + goto failed; 633 + 628 634 spin_lock_irqsave(sdev->request_queue->queue_lock, flags); 629 635 sdev->scsi_dh_data = scsi_dh_data; 630 636 spin_unlock_irqrestore(sdev->request_queue->queue_lock, flags); 631 - try_module_get(THIS_MODULE); 632 637 633 - sdev_printk(KERN_NOTICE, sdev, "Attached %s\n", RDAC_NAME); 638 + sdev_printk(KERN_NOTICE, sdev, 639 + "%s: LUN %d (%s)\n", 640 + RDAC_NAME, h->lun, lun_state[(int)h->lun_state]); 634 641 635 642 return 0; 643 + 644 + failed: 645 + kfree(scsi_dh_data); 646 + sdev_printk(KERN_ERR, sdev, "%s: not attached\n", 647 + RDAC_NAME); 648 + return -EINVAL; 636 649 } 637 650 638 651 static void rdac_bus_detach( struct scsi_device *sdev ) ··· 670 645 kref_put(&h->ctlr->kref, release_controller); 671 646 kfree(scsi_dh_data); 672 647 module_put(THIS_MODULE); 673 - sdev_printk(KERN_NOTICE, sdev, "Detached %s\n", RDAC_NAME); 648 + sdev_printk(KERN_NOTICE, sdev, "%s: Detached\n", RDAC_NAME); 674 649 } 675 650 676 651