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