aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target/target_core_pr.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/target/target_core_pr.c')
-rw-r--r--drivers/target/target_core_pr.c862
1 files changed, 450 insertions, 412 deletions
diff --git a/drivers/target/target_core_pr.c b/drivers/target/target_core_pr.c
index b662db3a320..1c1b849cd4f 100644
--- a/drivers/target/target_core_pr.c
+++ b/drivers/target/target_core_pr.c
@@ -62,7 +62,7 @@ int core_pr_dump_initiator_port(
62 char *buf, 62 char *buf,
63 u32 size) 63 u32 size)
64{ 64{
65 if (!(pr_reg->isid_present_at_reg)) 65 if (!pr_reg->isid_present_at_reg)
66 return 0; 66 return 0;
67 67
68 snprintf(buf, size, ",i,0x%s", &pr_reg->pr_reg_isid[0]); 68 snprintf(buf, size, ",i,0x%s", &pr_reg->pr_reg_isid[0]);
@@ -95,7 +95,7 @@ static int core_scsi2_reservation_check(struct se_cmd *cmd, u32 *pr_reg_type)
95 struct se_session *sess = cmd->se_sess; 95 struct se_session *sess = cmd->se_sess;
96 int ret; 96 int ret;
97 97
98 if (!(sess)) 98 if (!sess)
99 return 0; 99 return 0;
100 100
101 spin_lock(&dev->dev_reservation_lock); 101 spin_lock(&dev->dev_reservation_lock);
@@ -105,13 +105,13 @@ static int core_scsi2_reservation_check(struct se_cmd *cmd, u32 *pr_reg_type)
105 } 105 }
106 if (dev->dev_reserved_node_acl != sess->se_node_acl) { 106 if (dev->dev_reserved_node_acl != sess->se_node_acl) {
107 spin_unlock(&dev->dev_reservation_lock); 107 spin_unlock(&dev->dev_reservation_lock);
108 return -1; 108 return -EINVAL;
109 } 109 }
110 if (!(dev->dev_flags & DF_SPC2_RESERVATIONS_WITH_ISID)) { 110 if (!(dev->dev_flags & DF_SPC2_RESERVATIONS_WITH_ISID)) {
111 spin_unlock(&dev->dev_reservation_lock); 111 spin_unlock(&dev->dev_reservation_lock);
112 return 0; 112 return 0;
113 } 113 }
114 ret = (dev->dev_res_bin_isid == sess->sess_bin_isid) ? 0 : -1; 114 ret = (dev->dev_res_bin_isid == sess->sess_bin_isid) ? 0 : -EINVAL;
115 spin_unlock(&dev->dev_reservation_lock); 115 spin_unlock(&dev->dev_reservation_lock);
116 116
117 return ret; 117 return ret;
@@ -123,7 +123,7 @@ static int core_scsi2_reservation_release(struct se_cmd *cmd)
123 struct se_session *sess = cmd->se_sess; 123 struct se_session *sess = cmd->se_sess;
124 struct se_portal_group *tpg = sess->se_tpg; 124 struct se_portal_group *tpg = sess->se_tpg;
125 125
126 if (!(sess) || !(tpg)) 126 if (!sess || !tpg)
127 return 0; 127 return 0;
128 128
129 spin_lock(&dev->dev_reservation_lock); 129 spin_lock(&dev->dev_reservation_lock);
@@ -142,9 +142,9 @@ static int core_scsi2_reservation_release(struct se_cmd *cmd)
142 dev->dev_res_bin_isid = 0; 142 dev->dev_res_bin_isid = 0;
143 dev->dev_flags &= ~DF_SPC2_RESERVATIONS_WITH_ISID; 143 dev->dev_flags &= ~DF_SPC2_RESERVATIONS_WITH_ISID;
144 } 144 }
145 printk(KERN_INFO "SCSI-2 Released reservation for %s LUN: %u ->" 145 pr_debug("SCSI-2 Released reservation for %s LUN: %u ->"
146 " MAPPED LUN: %u for %s\n", TPG_TFO(tpg)->get_fabric_name(), 146 " MAPPED LUN: %u for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
147 SE_LUN(cmd)->unpacked_lun, cmd->se_deve->mapped_lun, 147 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
148 sess->se_node_acl->initiatorname); 148 sess->se_node_acl->initiatorname);
149 spin_unlock(&dev->dev_reservation_lock); 149 spin_unlock(&dev->dev_reservation_lock);
150 150
@@ -157,9 +157,9 @@ static int core_scsi2_reservation_reserve(struct se_cmd *cmd)
157 struct se_session *sess = cmd->se_sess; 157 struct se_session *sess = cmd->se_sess;
158 struct se_portal_group *tpg = sess->se_tpg; 158 struct se_portal_group *tpg = sess->se_tpg;
159 159
160 if ((T_TASK(cmd)->t_task_cdb[1] & 0x01) && 160 if ((cmd->t_task_cdb[1] & 0x01) &&
161 (T_TASK(cmd)->t_task_cdb[1] & 0x02)) { 161 (cmd->t_task_cdb[1] & 0x02)) {
162 printk(KERN_ERR "LongIO and Obselete Bits set, returning" 162 pr_err("LongIO and Obselete Bits set, returning"
163 " ILLEGAL_REQUEST\n"); 163 " ILLEGAL_REQUEST\n");
164 return PYX_TRANSPORT_ILLEGAL_REQUEST; 164 return PYX_TRANSPORT_ILLEGAL_REQUEST;
165 } 165 }
@@ -167,19 +167,19 @@ static int core_scsi2_reservation_reserve(struct se_cmd *cmd)
167 * This is currently the case for target_core_mod passthrough struct se_cmd 167 * This is currently the case for target_core_mod passthrough struct se_cmd
168 * ops 168 * ops
169 */ 169 */
170 if (!(sess) || !(tpg)) 170 if (!sess || !tpg)
171 return 0; 171 return 0;
172 172
173 spin_lock(&dev->dev_reservation_lock); 173 spin_lock(&dev->dev_reservation_lock);
174 if (dev->dev_reserved_node_acl && 174 if (dev->dev_reserved_node_acl &&
175 (dev->dev_reserved_node_acl != sess->se_node_acl)) { 175 (dev->dev_reserved_node_acl != sess->se_node_acl)) {
176 printk(KERN_ERR "SCSI-2 RESERVATION CONFLIFT for %s fabric\n", 176 pr_err("SCSI-2 RESERVATION CONFLIFT for %s fabric\n",
177 TPG_TFO(tpg)->get_fabric_name()); 177 tpg->se_tpg_tfo->get_fabric_name());
178 printk(KERN_ERR "Original reserver LUN: %u %s\n", 178 pr_err("Original reserver LUN: %u %s\n",
179 SE_LUN(cmd)->unpacked_lun, 179 cmd->se_lun->unpacked_lun,
180 dev->dev_reserved_node_acl->initiatorname); 180 dev->dev_reserved_node_acl->initiatorname);
181 printk(KERN_ERR "Current attempt - LUN: %u -> MAPPED LUN: %u" 181 pr_err("Current attempt - LUN: %u -> MAPPED LUN: %u"
182 " from %s \n", SE_LUN(cmd)->unpacked_lun, 182 " from %s \n", cmd->se_lun->unpacked_lun,
183 cmd->se_deve->mapped_lun, 183 cmd->se_deve->mapped_lun,
184 sess->se_node_acl->initiatorname); 184 sess->se_node_acl->initiatorname);
185 spin_unlock(&dev->dev_reservation_lock); 185 spin_unlock(&dev->dev_reservation_lock);
@@ -192,9 +192,9 @@ static int core_scsi2_reservation_reserve(struct se_cmd *cmd)
192 dev->dev_res_bin_isid = sess->sess_bin_isid; 192 dev->dev_res_bin_isid = sess->sess_bin_isid;
193 dev->dev_flags |= DF_SPC2_RESERVATIONS_WITH_ISID; 193 dev->dev_flags |= DF_SPC2_RESERVATIONS_WITH_ISID;
194 } 194 }
195 printk(KERN_INFO "SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u" 195 pr_debug("SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u"
196 " for %s\n", TPG_TFO(tpg)->get_fabric_name(), 196 " for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
197 SE_LUN(cmd)->unpacked_lun, cmd->se_deve->mapped_lun, 197 cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun,
198 sess->se_node_acl->initiatorname); 198 sess->se_node_acl->initiatorname);
199 spin_unlock(&dev->dev_reservation_lock); 199 spin_unlock(&dev->dev_reservation_lock);
200 200
@@ -215,15 +215,15 @@ int core_scsi2_emulate_crh(struct se_cmd *cmd)
215 struct se_session *se_sess = cmd->se_sess; 215 struct se_session *se_sess = cmd->se_sess;
216 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev; 216 struct se_subsystem_dev *su_dev = cmd->se_dev->se_sub_dev;
217 struct t10_pr_registration *pr_reg; 217 struct t10_pr_registration *pr_reg;
218 struct t10_reservation_template *pr_tmpl = &su_dev->t10_reservation; 218 struct t10_reservation *pr_tmpl = &su_dev->t10_pr;
219 unsigned char *cdb = &T_TASK(cmd)->t_task_cdb[0]; 219 unsigned char *cdb = &cmd->t_task_cdb[0];
220 int crh = (T10_RES(su_dev)->res_type == SPC3_PERSISTENT_RESERVATIONS); 220 int crh = (su_dev->t10_pr.res_type == SPC3_PERSISTENT_RESERVATIONS);
221 int conflict = 0; 221 int conflict = 0;
222 222
223 if (!(se_sess)) 223 if (!se_sess)
224 return 0; 224 return 0;
225 225
226 if (!(crh)) 226 if (!crh)
227 goto after_crh; 227 goto after_crh;
228 228
229 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, 229 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
@@ -280,7 +280,7 @@ int core_scsi2_emulate_crh(struct se_cmd *cmd)
280 } 280 }
281 281
282 if (conflict) { 282 if (conflict) {
283 printk(KERN_ERR "Received legacy SPC-2 RESERVE/RELEASE" 283 pr_err("Received legacy SPC-2 RESERVE/RELEASE"
284 " while active SPC-3 registrations exist," 284 " while active SPC-3 registrations exist,"
285 " returning RESERVATION_CONFLICT\n"); 285 " returning RESERVATION_CONFLICT\n");
286 return PYX_TRANSPORT_RESERVATION_CONFLICT; 286 return PYX_TRANSPORT_RESERVATION_CONFLICT;
@@ -307,7 +307,7 @@ static int core_scsi3_pr_seq_non_holder(
307 u32 pr_reg_type) 307 u32 pr_reg_type)
308{ 308{
309 struct se_dev_entry *se_deve; 309 struct se_dev_entry *se_deve;
310 struct se_session *se_sess = SE_SESS(cmd); 310 struct se_session *se_sess = cmd->se_sess;
311 int other_cdb = 0, ignore_reg; 311 int other_cdb = 0, ignore_reg;
312 int registered_nexus = 0, ret = 1; /* Conflict by default */ 312 int registered_nexus = 0, ret = 1; /* Conflict by default */
313 int all_reg = 0, reg_only = 0; /* ALL_REG, REG_ONLY */ 313 int all_reg = 0, reg_only = 0; /* ALL_REG, REG_ONLY */
@@ -362,7 +362,7 @@ static int core_scsi3_pr_seq_non_holder(
362 registered_nexus = 1; 362 registered_nexus = 1;
363 break; 363 break;
364 default: 364 default:
365 return -1; 365 return -EINVAL;
366 } 366 }
367 /* 367 /*
368 * Referenced from spc4r17 table 45 for *NON* PR holder access 368 * Referenced from spc4r17 table 45 for *NON* PR holder access
@@ -412,9 +412,9 @@ static int core_scsi3_pr_seq_non_holder(
412 ret = (registered_nexus) ? 0 : 1; 412 ret = (registered_nexus) ? 0 : 1;
413 break; 413 break;
414 default: 414 default:
415 printk(KERN_ERR "Unknown PERSISTENT_RESERVE_OUT service" 415 pr_err("Unknown PERSISTENT_RESERVE_OUT service"
416 " action: 0x%02x\n", cdb[1] & 0x1f); 416 " action: 0x%02x\n", cdb[1] & 0x1f);
417 return -1; 417 return -EINVAL;
418 } 418 }
419 break; 419 break;
420 case RELEASE: 420 case RELEASE:
@@ -459,9 +459,9 @@ static int core_scsi3_pr_seq_non_holder(
459 ret = 0; /* Allowed */ 459 ret = 0; /* Allowed */
460 break; 460 break;
461 default: 461 default:
462 printk(KERN_ERR "Unknown MI Service Action: 0x%02x\n", 462 pr_err("Unknown MI Service Action: 0x%02x\n",
463 (cdb[1] & 0x1f)); 463 (cdb[1] & 0x1f));
464 return -1; 464 return -EINVAL;
465 } 465 }
466 break; 466 break;
467 case ACCESS_CONTROL_IN: 467 case ACCESS_CONTROL_IN:
@@ -481,9 +481,9 @@ static int core_scsi3_pr_seq_non_holder(
481 * Case where the CDB is explicitly allowed in the above switch 481 * Case where the CDB is explicitly allowed in the above switch
482 * statement. 482 * statement.
483 */ 483 */
484 if (!(ret) && !(other_cdb)) { 484 if (!ret && !other_cdb) {
485#if 0 485#if 0
486 printk(KERN_INFO "Allowing explict CDB: 0x%02x for %s" 486 pr_debug("Allowing explict CDB: 0x%02x for %s"
487 " reservation holder\n", cdb[0], 487 " reservation holder\n", cdb[0],
488 core_scsi3_pr_dump_type(pr_reg_type)); 488 core_scsi3_pr_dump_type(pr_reg_type));
489#endif 489#endif
@@ -498,7 +498,7 @@ static int core_scsi3_pr_seq_non_holder(
498 /* 498 /*
499 * Conflict for write exclusive 499 * Conflict for write exclusive
500 */ 500 */
501 printk(KERN_INFO "%s Conflict for unregistered nexus" 501 pr_debug("%s Conflict for unregistered nexus"
502 " %s CDB: 0x%02x to %s reservation\n", 502 " %s CDB: 0x%02x to %s reservation\n",
503 transport_dump_cmd_direction(cmd), 503 transport_dump_cmd_direction(cmd),
504 se_sess->se_node_acl->initiatorname, cdb[0], 504 se_sess->se_node_acl->initiatorname, cdb[0],
@@ -515,8 +515,8 @@ static int core_scsi3_pr_seq_non_holder(
515 * nexuses to issue CDBs. 515 * nexuses to issue CDBs.
516 */ 516 */
517#if 0 517#if 0
518 if (!(registered_nexus)) { 518 if (!registered_nexus) {
519 printk(KERN_INFO "Allowing implict CDB: 0x%02x" 519 pr_debug("Allowing implict CDB: 0x%02x"
520 " for %s reservation on unregistered" 520 " for %s reservation on unregistered"
521 " nexus\n", cdb[0], 521 " nexus\n", cdb[0],
522 core_scsi3_pr_dump_type(pr_reg_type)); 522 core_scsi3_pr_dump_type(pr_reg_type));
@@ -531,14 +531,14 @@ static int core_scsi3_pr_seq_non_holder(
531 * allow commands from registered nexuses. 531 * allow commands from registered nexuses.
532 */ 532 */
533#if 0 533#if 0
534 printk(KERN_INFO "Allowing implict CDB: 0x%02x for %s" 534 pr_debug("Allowing implict CDB: 0x%02x for %s"
535 " reservation\n", cdb[0], 535 " reservation\n", cdb[0],
536 core_scsi3_pr_dump_type(pr_reg_type)); 536 core_scsi3_pr_dump_type(pr_reg_type));
537#endif 537#endif
538 return 0; 538 return 0;
539 } 539 }
540 } 540 }
541 printk(KERN_INFO "%s Conflict for %sregistered nexus %s CDB: 0x%2x" 541 pr_debug("%s Conflict for %sregistered nexus %s CDB: 0x%2x"
542 " for %s reservation\n", transport_dump_cmd_direction(cmd), 542 " for %s reservation\n", transport_dump_cmd_direction(cmd),
543 (registered_nexus) ? "" : "un", 543 (registered_nexus) ? "" : "un",
544 se_sess->se_node_acl->initiatorname, cdb[0], 544 se_sess->se_node_acl->initiatorname, cdb[0],
@@ -549,7 +549,7 @@ static int core_scsi3_pr_seq_non_holder(
549 549
550static u32 core_scsi3_pr_generation(struct se_device *dev) 550static u32 core_scsi3_pr_generation(struct se_device *dev)
551{ 551{
552 struct se_subsystem_dev *su_dev = SU_DEV(dev); 552 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
553 u32 prg; 553 u32 prg;
554 /* 554 /*
555 * PRGeneration field shall contain the value of a 32-bit wrapping 555 * PRGeneration field shall contain the value of a 32-bit wrapping
@@ -561,7 +561,7 @@ static u32 core_scsi3_pr_generation(struct se_device *dev)
561 * See spc4r17 section 6.3.12 READ_KEYS service action 561 * See spc4r17 section 6.3.12 READ_KEYS service action
562 */ 562 */
563 spin_lock(&dev->dev_reservation_lock); 563 spin_lock(&dev->dev_reservation_lock);
564 prg = T10_RES(su_dev)->pr_generation++; 564 prg = su_dev->t10_pr.pr_generation++;
565 spin_unlock(&dev->dev_reservation_lock); 565 spin_unlock(&dev->dev_reservation_lock);
566 566
567 return prg; 567 return prg;
@@ -575,7 +575,7 @@ static int core_scsi3_pr_reservation_check(
575 struct se_session *sess = cmd->se_sess; 575 struct se_session *sess = cmd->se_sess;
576 int ret; 576 int ret;
577 577
578 if (!(sess)) 578 if (!sess)
579 return 0; 579 return 0;
580 /* 580 /*
581 * A legacy SPC-2 reservation is being held. 581 * A legacy SPC-2 reservation is being held.
@@ -584,7 +584,7 @@ static int core_scsi3_pr_reservation_check(
584 return core_scsi2_reservation_check(cmd, pr_reg_type); 584 return core_scsi2_reservation_check(cmd, pr_reg_type);
585 585
586 spin_lock(&dev->dev_reservation_lock); 586 spin_lock(&dev->dev_reservation_lock);
587 if (!(dev->dev_pr_res_holder)) { 587 if (!dev->dev_pr_res_holder) {
588 spin_unlock(&dev->dev_reservation_lock); 588 spin_unlock(&dev->dev_reservation_lock);
589 return 0; 589 return 0;
590 } 590 }
@@ -592,14 +592,14 @@ static int core_scsi3_pr_reservation_check(
592 cmd->pr_res_key = dev->dev_pr_res_holder->pr_res_key; 592 cmd->pr_res_key = dev->dev_pr_res_holder->pr_res_key;
593 if (dev->dev_pr_res_holder->pr_reg_nacl != sess->se_node_acl) { 593 if (dev->dev_pr_res_holder->pr_reg_nacl != sess->se_node_acl) {
594 spin_unlock(&dev->dev_reservation_lock); 594 spin_unlock(&dev->dev_reservation_lock);
595 return -1; 595 return -EINVAL;
596 } 596 }
597 if (!(dev->dev_pr_res_holder->isid_present_at_reg)) { 597 if (!dev->dev_pr_res_holder->isid_present_at_reg) {
598 spin_unlock(&dev->dev_reservation_lock); 598 spin_unlock(&dev->dev_reservation_lock);
599 return 0; 599 return 0;
600 } 600 }
601 ret = (dev->dev_pr_res_holder->pr_reg_bin_isid == 601 ret = (dev->dev_pr_res_holder->pr_reg_bin_isid ==
602 sess->sess_bin_isid) ? 0 : -1; 602 sess->sess_bin_isid) ? 0 : -EINVAL;
603 /* 603 /*
604 * Use bit in *pr_reg_type to notify ISID mismatch in 604 * Use bit in *pr_reg_type to notify ISID mismatch in
605 * core_scsi3_pr_seq_non_holder(). 605 * core_scsi3_pr_seq_non_holder().
@@ -620,19 +620,19 @@ static struct t10_pr_registration *__core_scsi3_do_alloc_registration(
620 int all_tg_pt, 620 int all_tg_pt,
621 int aptpl) 621 int aptpl)
622{ 622{
623 struct se_subsystem_dev *su_dev = SU_DEV(dev); 623 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
624 struct t10_pr_registration *pr_reg; 624 struct t10_pr_registration *pr_reg;
625 625
626 pr_reg = kmem_cache_zalloc(t10_pr_reg_cache, GFP_ATOMIC); 626 pr_reg = kmem_cache_zalloc(t10_pr_reg_cache, GFP_ATOMIC);
627 if (!(pr_reg)) { 627 if (!pr_reg) {
628 printk(KERN_ERR "Unable to allocate struct t10_pr_registration\n"); 628 pr_err("Unable to allocate struct t10_pr_registration\n");
629 return NULL; 629 return NULL;
630 } 630 }
631 631
632 pr_reg->pr_aptpl_buf = kzalloc(T10_RES(su_dev)->pr_aptpl_buf_len, 632 pr_reg->pr_aptpl_buf = kzalloc(su_dev->t10_pr.pr_aptpl_buf_len,
633 GFP_ATOMIC); 633 GFP_ATOMIC);
634 if (!(pr_reg->pr_aptpl_buf)) { 634 if (!pr_reg->pr_aptpl_buf) {
635 printk(KERN_ERR "Unable to allocate pr_reg->pr_aptpl_buf\n"); 635 pr_err("Unable to allocate pr_reg->pr_aptpl_buf\n");
636 kmem_cache_free(t10_pr_reg_cache, pr_reg); 636 kmem_cache_free(t10_pr_reg_cache, pr_reg);
637 return NULL; 637 return NULL;
638 } 638 }
@@ -692,12 +692,12 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
692 */ 692 */
693 pr_reg = __core_scsi3_do_alloc_registration(dev, nacl, deve, isid, 693 pr_reg = __core_scsi3_do_alloc_registration(dev, nacl, deve, isid,
694 sa_res_key, all_tg_pt, aptpl); 694 sa_res_key, all_tg_pt, aptpl);
695 if (!(pr_reg)) 695 if (!pr_reg)
696 return NULL; 696 return NULL;
697 /* 697 /*
698 * Return pointer to pr_reg for ALL_TG_PT=0 698 * Return pointer to pr_reg for ALL_TG_PT=0
699 */ 699 */
700 if (!(all_tg_pt)) 700 if (!all_tg_pt)
701 return pr_reg; 701 return pr_reg;
702 /* 702 /*
703 * Create list of matching SCSI Initiator Port registrations 703 * Create list of matching SCSI Initiator Port registrations
@@ -717,7 +717,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
717 * that have not been make explict via a ConfigFS 717 * that have not been make explict via a ConfigFS
718 * MappedLUN group for the SCSI Initiator Node ACL. 718 * MappedLUN group for the SCSI Initiator Node ACL.
719 */ 719 */
720 if (!(deve_tmp->se_lun_acl)) 720 if (!deve_tmp->se_lun_acl)
721 continue; 721 continue;
722 722
723 nacl_tmp = deve_tmp->se_lun_acl->se_lun_nacl; 723 nacl_tmp = deve_tmp->se_lun_acl->se_lun_nacl;
@@ -751,7 +751,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
751 */ 751 */
752 ret = core_scsi3_lunacl_depend_item(deve_tmp); 752 ret = core_scsi3_lunacl_depend_item(deve_tmp);
753 if (ret < 0) { 753 if (ret < 0) {
754 printk(KERN_ERR "core_scsi3_lunacl_depend" 754 pr_err("core_scsi3_lunacl_depend"
755 "_item() failed\n"); 755 "_item() failed\n");
756 atomic_dec(&port->sep_tg_pt_ref_cnt); 756 atomic_dec(&port->sep_tg_pt_ref_cnt);
757 smp_mb__after_atomic_dec(); 757 smp_mb__after_atomic_dec();
@@ -769,7 +769,7 @@ static struct t10_pr_registration *__core_scsi3_alloc_registration(
769 pr_reg_atp = __core_scsi3_do_alloc_registration(dev, 769 pr_reg_atp = __core_scsi3_do_alloc_registration(dev,
770 nacl_tmp, deve_tmp, NULL, 770 nacl_tmp, deve_tmp, NULL,
771 sa_res_key, all_tg_pt, aptpl); 771 sa_res_key, all_tg_pt, aptpl);
772 if (!(pr_reg_atp)) { 772 if (!pr_reg_atp) {
773 atomic_dec(&port->sep_tg_pt_ref_cnt); 773 atomic_dec(&port->sep_tg_pt_ref_cnt);
774 smp_mb__after_atomic_dec(); 774 smp_mb__after_atomic_dec();
775 atomic_dec(&deve_tmp->pr_ref_count); 775 atomic_dec(&deve_tmp->pr_ref_count);
@@ -803,7 +803,7 @@ out:
803} 803}
804 804
805int core_scsi3_alloc_aptpl_registration( 805int core_scsi3_alloc_aptpl_registration(
806 struct t10_reservation_template *pr_tmpl, 806 struct t10_reservation *pr_tmpl,
807 u64 sa_res_key, 807 u64 sa_res_key,
808 unsigned char *i_port, 808 unsigned char *i_port,
809 unsigned char *isid, 809 unsigned char *isid,
@@ -817,15 +817,15 @@ int core_scsi3_alloc_aptpl_registration(
817{ 817{
818 struct t10_pr_registration *pr_reg; 818 struct t10_pr_registration *pr_reg;
819 819
820 if (!(i_port) || !(t_port) || !(sa_res_key)) { 820 if (!i_port || !t_port || !sa_res_key) {
821 printk(KERN_ERR "Illegal parameters for APTPL registration\n"); 821 pr_err("Illegal parameters for APTPL registration\n");
822 return -1; 822 return -EINVAL;
823 } 823 }
824 824
825 pr_reg = kmem_cache_zalloc(t10_pr_reg_cache, GFP_KERNEL); 825 pr_reg = kmem_cache_zalloc(t10_pr_reg_cache, GFP_KERNEL);
826 if (!(pr_reg)) { 826 if (!pr_reg) {
827 printk(KERN_ERR "Unable to allocate struct t10_pr_registration\n"); 827 pr_err("Unable to allocate struct t10_pr_registration\n");
828 return -1; 828 return -ENOMEM;
829 } 829 }
830 pr_reg->pr_aptpl_buf = kzalloc(pr_tmpl->pr_aptpl_buf_len, GFP_KERNEL); 830 pr_reg->pr_aptpl_buf = kzalloc(pr_tmpl->pr_aptpl_buf_len, GFP_KERNEL);
831 831
@@ -869,7 +869,7 @@ int core_scsi3_alloc_aptpl_registration(
869 pr_reg->pr_res_holder = res_holder; 869 pr_reg->pr_res_holder = res_holder;
870 870
871 list_add_tail(&pr_reg->pr_reg_aptpl_list, &pr_tmpl->aptpl_reg_list); 871 list_add_tail(&pr_reg->pr_reg_aptpl_list, &pr_tmpl->aptpl_reg_list);
872 printk(KERN_INFO "SPC-3 PR APTPL Successfully added registration%s from" 872 pr_debug("SPC-3 PR APTPL Successfully added registration%s from"
873 " metadata\n", (res_holder) ? "+reservation" : ""); 873 " metadata\n", (res_holder) ? "+reservation" : "");
874 return 0; 874 return 0;
875} 875}
@@ -891,13 +891,13 @@ static void core_scsi3_aptpl_reserve(
891 dev->dev_pr_res_holder = pr_reg; 891 dev->dev_pr_res_holder = pr_reg;
892 spin_unlock(&dev->dev_reservation_lock); 892 spin_unlock(&dev->dev_reservation_lock);
893 893
894 printk(KERN_INFO "SPC-3 PR [%s] Service Action: APTPL RESERVE created" 894 pr_debug("SPC-3 PR [%s] Service Action: APTPL RESERVE created"
895 " new reservation holder TYPE: %s ALL_TG_PT: %d\n", 895 " new reservation holder TYPE: %s ALL_TG_PT: %d\n",
896 TPG_TFO(tpg)->get_fabric_name(), 896 tpg->se_tpg_tfo->get_fabric_name(),
897 core_scsi3_pr_dump_type(pr_reg->pr_res_type), 897 core_scsi3_pr_dump_type(pr_reg->pr_res_type),
898 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 898 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0);
899 printk(KERN_INFO "SPC-3 PR [%s] RESERVE Node: %s%s\n", 899 pr_debug("SPC-3 PR [%s] RESERVE Node: %s%s\n",
900 TPG_TFO(tpg)->get_fabric_name(), node_acl->initiatorname, 900 tpg->se_tpg_tfo->get_fabric_name(), node_acl->initiatorname,
901 (prf_isid) ? &i_buf[0] : ""); 901 (prf_isid) ? &i_buf[0] : "");
902} 902}
903 903
@@ -913,7 +913,7 @@ static int __core_scsi3_check_aptpl_registration(
913 struct se_dev_entry *deve) 913 struct se_dev_entry *deve)
914{ 914{
915 struct t10_pr_registration *pr_reg, *pr_reg_tmp; 915 struct t10_pr_registration *pr_reg, *pr_reg_tmp;
916 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 916 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
917 unsigned char i_port[PR_APTPL_MAX_IPORT_LEN]; 917 unsigned char i_port[PR_APTPL_MAX_IPORT_LEN];
918 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN]; 918 unsigned char t_port[PR_APTPL_MAX_TPORT_LEN];
919 u16 tpgt; 919 u16 tpgt;
@@ -925,8 +925,8 @@ static int __core_scsi3_check_aptpl_registration(
925 */ 925 */
926 snprintf(i_port, PR_APTPL_MAX_IPORT_LEN, "%s", nacl->initiatorname); 926 snprintf(i_port, PR_APTPL_MAX_IPORT_LEN, "%s", nacl->initiatorname);
927 snprintf(t_port, PR_APTPL_MAX_TPORT_LEN, "%s", 927 snprintf(t_port, PR_APTPL_MAX_TPORT_LEN, "%s",
928 TPG_TFO(tpg)->tpg_get_wwn(tpg)); 928 tpg->se_tpg_tfo->tpg_get_wwn(tpg));
929 tpgt = TPG_TFO(tpg)->tpg_get_tag(tpg); 929 tpgt = tpg->se_tpg_tfo->tpg_get_tag(tpg);
930 /* 930 /*
931 * Look for the matching registrations+reservation from those 931 * Look for the matching registrations+reservation from those
932 * created from APTPL metadata. Note that multiple registrations 932 * created from APTPL metadata. Note that multiple registrations
@@ -936,7 +936,7 @@ static int __core_scsi3_check_aptpl_registration(
936 spin_lock(&pr_tmpl->aptpl_reg_lock); 936 spin_lock(&pr_tmpl->aptpl_reg_lock);
937 list_for_each_entry_safe(pr_reg, pr_reg_tmp, &pr_tmpl->aptpl_reg_list, 937 list_for_each_entry_safe(pr_reg, pr_reg_tmp, &pr_tmpl->aptpl_reg_list,
938 pr_reg_aptpl_list) { 938 pr_reg_aptpl_list) {
939 if (!(strcmp(pr_reg->pr_iport, i_port)) && 939 if (!strcmp(pr_reg->pr_iport, i_port) &&
940 (pr_reg->pr_res_mapped_lun == deve->mapped_lun) && 940 (pr_reg->pr_res_mapped_lun == deve->mapped_lun) &&
941 !(strcmp(pr_reg->pr_tport, t_port)) && 941 !(strcmp(pr_reg->pr_tport, t_port)) &&
942 (pr_reg->pr_reg_tpgt == tpgt) && 942 (pr_reg->pr_reg_tpgt == tpgt) &&
@@ -980,11 +980,11 @@ int core_scsi3_check_aptpl_registration(
980 struct se_lun *lun, 980 struct se_lun *lun,
981 struct se_lun_acl *lun_acl) 981 struct se_lun_acl *lun_acl)
982{ 982{
983 struct se_subsystem_dev *su_dev = SU_DEV(dev); 983 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
984 struct se_node_acl *nacl = lun_acl->se_lun_nacl; 984 struct se_node_acl *nacl = lun_acl->se_lun_nacl;
985 struct se_dev_entry *deve = &nacl->device_list[lun_acl->mapped_lun]; 985 struct se_dev_entry *deve = &nacl->device_list[lun_acl->mapped_lun];
986 986
987 if (T10_RES(su_dev)->res_type != SPC3_PERSISTENT_RESERVATIONS) 987 if (su_dev->t10_pr.res_type != SPC3_PERSISTENT_RESERVATIONS)
988 return 0; 988 return 0;
989 989
990 return __core_scsi3_check_aptpl_registration(dev, tpg, lun, 990 return __core_scsi3_check_aptpl_registration(dev, tpg, lun,
@@ -1006,19 +1006,19 @@ static void __core_scsi3_dump_registration(
1006 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0], 1006 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0],
1007 PR_REG_ISID_ID_LEN); 1007 PR_REG_ISID_ID_LEN);
1008 1008
1009 printk(KERN_INFO "SPC-3 PR [%s] Service Action: REGISTER%s Initiator" 1009 pr_debug("SPC-3 PR [%s] Service Action: REGISTER%s Initiator"
1010 " Node: %s%s\n", tfo->get_fabric_name(), (register_type == 2) ? 1010 " Node: %s%s\n", tfo->get_fabric_name(), (register_type == 2) ?
1011 "_AND_MOVE" : (register_type == 1) ? 1011 "_AND_MOVE" : (register_type == 1) ?
1012 "_AND_IGNORE_EXISTING_KEY" : "", nacl->initiatorname, 1012 "_AND_IGNORE_EXISTING_KEY" : "", nacl->initiatorname,
1013 (prf_isid) ? i_buf : ""); 1013 (prf_isid) ? i_buf : "");
1014 printk(KERN_INFO "SPC-3 PR [%s] registration on Target Port: %s,0x%04x\n", 1014 pr_debug("SPC-3 PR [%s] registration on Target Port: %s,0x%04x\n",
1015 tfo->get_fabric_name(), tfo->tpg_get_wwn(se_tpg), 1015 tfo->get_fabric_name(), tfo->tpg_get_wwn(se_tpg),
1016 tfo->tpg_get_tag(se_tpg)); 1016 tfo->tpg_get_tag(se_tpg));
1017 printk(KERN_INFO "SPC-3 PR [%s] for %s TCM Subsystem %s Object Target" 1017 pr_debug("SPC-3 PR [%s] for %s TCM Subsystem %s Object Target"
1018 " Port(s)\n", tfo->get_fabric_name(), 1018 " Port(s)\n", tfo->get_fabric_name(),
1019 (pr_reg->pr_reg_all_tg_pt) ? "ALL" : "SINGLE", 1019 (pr_reg->pr_reg_all_tg_pt) ? "ALL" : "SINGLE",
1020 TRANSPORT(dev)->name); 1020 dev->transport->name);
1021 printk(KERN_INFO "SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:" 1021 pr_debug("SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:"
1022 " 0x%08x APTPL: %d\n", tfo->get_fabric_name(), 1022 " 0x%08x APTPL: %d\n", tfo->get_fabric_name(),
1023 pr_reg->pr_res_key, pr_reg->pr_res_generation, 1023 pr_reg->pr_res_key, pr_reg->pr_res_generation,
1024 pr_reg->pr_reg_aptpl); 1024 pr_reg->pr_reg_aptpl);
@@ -1035,10 +1035,10 @@ static void __core_scsi3_add_registration(
1035 int register_type, 1035 int register_type,
1036 int register_move) 1036 int register_move)
1037{ 1037{
1038 struct se_subsystem_dev *su_dev = SU_DEV(dev); 1038 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
1039 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; 1039 struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo;
1040 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; 1040 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe;
1041 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 1041 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
1042 1042
1043 /* 1043 /*
1044 * Increment PRgeneration counter for struct se_device upon a successful 1044 * Increment PRgeneration counter for struct se_device upon a successful
@@ -1050,7 +1050,7 @@ static void __core_scsi3_add_registration(
1050 * for the REGISTER. 1050 * for the REGISTER.
1051 */ 1051 */
1052 pr_reg->pr_res_generation = (register_move) ? 1052 pr_reg->pr_res_generation = (register_move) ?
1053 T10_RES(su_dev)->pr_generation++ : 1053 su_dev->t10_pr.pr_generation++ :
1054 core_scsi3_pr_generation(dev); 1054 core_scsi3_pr_generation(dev);
1055 1055
1056 spin_lock(&pr_tmpl->registration_lock); 1056 spin_lock(&pr_tmpl->registration_lock);
@@ -1062,7 +1062,7 @@ static void __core_scsi3_add_registration(
1062 /* 1062 /*
1063 * Skip extra processing for ALL_TG_PT=0 or REGISTER_AND_MOVE. 1063 * Skip extra processing for ALL_TG_PT=0 or REGISTER_AND_MOVE.
1064 */ 1064 */
1065 if (!(pr_reg->pr_reg_all_tg_pt) || (register_move)) 1065 if (!pr_reg->pr_reg_all_tg_pt || register_move)
1066 return; 1066 return;
1067 /* 1067 /*
1068 * Walk pr_reg->pr_reg_atp_list and add registrations for ALL_TG_PT=1 1068 * Walk pr_reg->pr_reg_atp_list and add registrations for ALL_TG_PT=1
@@ -1106,8 +1106,8 @@ static int core_scsi3_alloc_registration(
1106 1106
1107 pr_reg = __core_scsi3_alloc_registration(dev, nacl, deve, isid, 1107 pr_reg = __core_scsi3_alloc_registration(dev, nacl, deve, isid,
1108 sa_res_key, all_tg_pt, aptpl); 1108 sa_res_key, all_tg_pt, aptpl);
1109 if (!(pr_reg)) 1109 if (!pr_reg)
1110 return -1; 1110 return -EPERM;
1111 1111
1112 __core_scsi3_add_registration(dev, nacl, pr_reg, 1112 __core_scsi3_add_registration(dev, nacl, pr_reg,
1113 register_type, register_move); 1113 register_type, register_move);
@@ -1119,7 +1119,7 @@ static struct t10_pr_registration *__core_scsi3_locate_pr_reg(
1119 struct se_node_acl *nacl, 1119 struct se_node_acl *nacl,
1120 unsigned char *isid) 1120 unsigned char *isid)
1121{ 1121{
1122 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 1122 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
1123 struct t10_pr_registration *pr_reg, *pr_reg_tmp; 1123 struct t10_pr_registration *pr_reg, *pr_reg_tmp;
1124 struct se_portal_group *tpg; 1124 struct se_portal_group *tpg;
1125 1125
@@ -1137,14 +1137,14 @@ static struct t10_pr_registration *__core_scsi3_locate_pr_reg(
1137 * If this registration does NOT contain a fabric provided 1137 * If this registration does NOT contain a fabric provided
1138 * ISID, then we have found a match. 1138 * ISID, then we have found a match.
1139 */ 1139 */
1140 if (!(pr_reg->isid_present_at_reg)) { 1140 if (!pr_reg->isid_present_at_reg) {
1141 /* 1141 /*
1142 * Determine if this SCSI device server requires that 1142 * Determine if this SCSI device server requires that
1143 * SCSI Intiatior TransportID w/ ISIDs is enforced 1143 * SCSI Intiatior TransportID w/ ISIDs is enforced
1144 * for fabric modules (iSCSI) requiring them. 1144 * for fabric modules (iSCSI) requiring them.
1145 */ 1145 */
1146 if (TPG_TFO(tpg)->sess_get_initiator_sid != NULL) { 1146 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) {
1147 if (DEV_ATTRIB(dev)->enforce_pr_isids) 1147 if (dev->se_sub_dev->se_dev_attrib.enforce_pr_isids)
1148 continue; 1148 continue;
1149 } 1149 }
1150 atomic_inc(&pr_reg->pr_res_holders); 1150 atomic_inc(&pr_reg->pr_res_holders);
@@ -1157,7 +1157,7 @@ static struct t10_pr_registration *__core_scsi3_locate_pr_reg(
1157 * SCSI Initiator Port TransportIDs, then we expect a valid 1157 * SCSI Initiator Port TransportIDs, then we expect a valid
1158 * matching ISID to be provided by the local SCSI Initiator Port. 1158 * matching ISID to be provided by the local SCSI Initiator Port.
1159 */ 1159 */
1160 if (!(isid)) 1160 if (!isid)
1161 continue; 1161 continue;
1162 if (strcmp(isid, pr_reg->pr_reg_isid)) 1162 if (strcmp(isid, pr_reg->pr_reg_isid))
1163 continue; 1163 continue;
@@ -1180,9 +1180,9 @@ static struct t10_pr_registration *core_scsi3_locate_pr_reg(
1180 struct se_portal_group *tpg = nacl->se_tpg; 1180 struct se_portal_group *tpg = nacl->se_tpg;
1181 unsigned char buf[PR_REG_ISID_LEN], *isid_ptr = NULL; 1181 unsigned char buf[PR_REG_ISID_LEN], *isid_ptr = NULL;
1182 1182
1183 if (TPG_TFO(tpg)->sess_get_initiator_sid != NULL) { 1183 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) {
1184 memset(&buf[0], 0, PR_REG_ISID_LEN); 1184 memset(&buf[0], 0, PR_REG_ISID_LEN);
1185 TPG_TFO(tpg)->sess_get_initiator_sid(sess, &buf[0], 1185 tpg->se_tpg_tfo->sess_get_initiator_sid(sess, &buf[0],
1186 PR_REG_ISID_LEN); 1186 PR_REG_ISID_LEN);
1187 isid_ptr = &buf[0]; 1187 isid_ptr = &buf[0];
1188 } 1188 }
@@ -1206,7 +1206,7 @@ static int core_scsi3_check_implict_release(
1206 1206
1207 spin_lock(&dev->dev_reservation_lock); 1207 spin_lock(&dev->dev_reservation_lock);
1208 pr_res_holder = dev->dev_pr_res_holder; 1208 pr_res_holder = dev->dev_pr_res_holder;
1209 if (!(pr_res_holder)) { 1209 if (!pr_res_holder) {
1210 spin_unlock(&dev->dev_reservation_lock); 1210 spin_unlock(&dev->dev_reservation_lock);
1211 return ret; 1211 return ret;
1212 } 1212 }
@@ -1236,11 +1236,11 @@ static int core_scsi3_check_implict_release(
1236 (!strcmp(pr_res_holder->pr_reg_nacl->initiatorname, 1236 (!strcmp(pr_res_holder->pr_reg_nacl->initiatorname,
1237 pr_reg->pr_reg_nacl->initiatorname)) && 1237 pr_reg->pr_reg_nacl->initiatorname)) &&
1238 (pr_res_holder->pr_res_key == pr_reg->pr_res_key)) { 1238 (pr_res_holder->pr_res_key == pr_reg->pr_res_key)) {
1239 printk(KERN_ERR "SPC-3 PR: Unable to perform ALL_TG_PT=1" 1239 pr_err("SPC-3 PR: Unable to perform ALL_TG_PT=1"
1240 " UNREGISTER while existing reservation with matching" 1240 " UNREGISTER while existing reservation with matching"
1241 " key 0x%016Lx is present from another SCSI Initiator" 1241 " key 0x%016Lx is present from another SCSI Initiator"
1242 " Port\n", pr_reg->pr_res_key); 1242 " Port\n", pr_reg->pr_res_key);
1243 ret = -1; 1243 ret = -EPERM;
1244 } 1244 }
1245 spin_unlock(&dev->dev_reservation_lock); 1245 spin_unlock(&dev->dev_reservation_lock);
1246 1246
@@ -1248,7 +1248,7 @@ static int core_scsi3_check_implict_release(
1248} 1248}
1249 1249
1250/* 1250/*
1251 * Called with struct t10_reservation_template->registration_lock held. 1251 * Called with struct t10_reservation->registration_lock held.
1252 */ 1252 */
1253static void __core_scsi3_free_registration( 1253static void __core_scsi3_free_registration(
1254 struct se_device *dev, 1254 struct se_device *dev,
@@ -1258,7 +1258,7 @@ static void __core_scsi3_free_registration(
1258{ 1258{
1259 struct target_core_fabric_ops *tfo = 1259 struct target_core_fabric_ops *tfo =
1260 pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; 1260 pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo;
1261 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 1261 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
1262 char i_buf[PR_REG_ISID_ID_LEN]; 1262 char i_buf[PR_REG_ISID_ID_LEN];
1263 int prf_isid; 1263 int prf_isid;
1264 1264
@@ -1283,25 +1283,25 @@ static void __core_scsi3_free_registration(
1283 */ 1283 */
1284 while (atomic_read(&pr_reg->pr_res_holders) != 0) { 1284 while (atomic_read(&pr_reg->pr_res_holders) != 0) {
1285 spin_unlock(&pr_tmpl->registration_lock); 1285 spin_unlock(&pr_tmpl->registration_lock);
1286 printk("SPC-3 PR [%s] waiting for pr_res_holders\n", 1286 pr_debug("SPC-3 PR [%s] waiting for pr_res_holders\n",
1287 tfo->get_fabric_name()); 1287 tfo->get_fabric_name());
1288 cpu_relax(); 1288 cpu_relax();
1289 spin_lock(&pr_tmpl->registration_lock); 1289 spin_lock(&pr_tmpl->registration_lock);
1290 } 1290 }
1291 1291
1292 printk(KERN_INFO "SPC-3 PR [%s] Service Action: UNREGISTER Initiator" 1292 pr_debug("SPC-3 PR [%s] Service Action: UNREGISTER Initiator"
1293 " Node: %s%s\n", tfo->get_fabric_name(), 1293 " Node: %s%s\n", tfo->get_fabric_name(),
1294 pr_reg->pr_reg_nacl->initiatorname, 1294 pr_reg->pr_reg_nacl->initiatorname,
1295 (prf_isid) ? &i_buf[0] : ""); 1295 (prf_isid) ? &i_buf[0] : "");
1296 printk(KERN_INFO "SPC-3 PR [%s] for %s TCM Subsystem %s Object Target" 1296 pr_debug("SPC-3 PR [%s] for %s TCM Subsystem %s Object Target"
1297 " Port(s)\n", tfo->get_fabric_name(), 1297 " Port(s)\n", tfo->get_fabric_name(),
1298 (pr_reg->pr_reg_all_tg_pt) ? "ALL" : "SINGLE", 1298 (pr_reg->pr_reg_all_tg_pt) ? "ALL" : "SINGLE",
1299 TRANSPORT(dev)->name); 1299 dev->transport->name);
1300 printk(KERN_INFO "SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:" 1300 pr_debug("SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:"
1301 " 0x%08x\n", tfo->get_fabric_name(), pr_reg->pr_res_key, 1301 " 0x%08x\n", tfo->get_fabric_name(), pr_reg->pr_res_key,
1302 pr_reg->pr_res_generation); 1302 pr_reg->pr_res_generation);
1303 1303
1304 if (!(preempt_and_abort_list)) { 1304 if (!preempt_and_abort_list) {
1305 pr_reg->pr_reg_deve = NULL; 1305 pr_reg->pr_reg_deve = NULL;
1306 pr_reg->pr_reg_nacl = NULL; 1306 pr_reg->pr_reg_nacl = NULL;
1307 kfree(pr_reg->pr_aptpl_buf); 1307 kfree(pr_reg->pr_aptpl_buf);
@@ -1319,7 +1319,7 @@ void core_scsi3_free_pr_reg_from_nacl(
1319 struct se_device *dev, 1319 struct se_device *dev,
1320 struct se_node_acl *nacl) 1320 struct se_node_acl *nacl)
1321{ 1321{
1322 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 1322 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
1323 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_res_holder; 1323 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_res_holder;
1324 /* 1324 /*
1325 * If the passed se_node_acl matches the reservation holder, 1325 * If the passed se_node_acl matches the reservation holder,
@@ -1349,7 +1349,7 @@ void core_scsi3_free_pr_reg_from_nacl(
1349void core_scsi3_free_all_registrations( 1349void core_scsi3_free_all_registrations(
1350 struct se_device *dev) 1350 struct se_device *dev)
1351{ 1351{
1352 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 1352 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
1353 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_res_holder; 1353 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_res_holder;
1354 1354
1355 spin_lock(&dev->dev_reservation_lock); 1355 spin_lock(&dev->dev_reservation_lock);
@@ -1381,13 +1381,13 @@ void core_scsi3_free_all_registrations(
1381 1381
1382static int core_scsi3_tpg_depend_item(struct se_portal_group *tpg) 1382static int core_scsi3_tpg_depend_item(struct se_portal_group *tpg)
1383{ 1383{
1384 return configfs_depend_item(TPG_TFO(tpg)->tf_subsys, 1384 return configfs_depend_item(tpg->se_tpg_tfo->tf_subsys,
1385 &tpg->tpg_group.cg_item); 1385 &tpg->tpg_group.cg_item);
1386} 1386}
1387 1387
1388static void core_scsi3_tpg_undepend_item(struct se_portal_group *tpg) 1388static void core_scsi3_tpg_undepend_item(struct se_portal_group *tpg)
1389{ 1389{
1390 configfs_undepend_item(TPG_TFO(tpg)->tf_subsys, 1390 configfs_undepend_item(tpg->se_tpg_tfo->tf_subsys,
1391 &tpg->tpg_group.cg_item); 1391 &tpg->tpg_group.cg_item);
1392 1392
1393 atomic_dec(&tpg->tpg_pr_ref_count); 1393 atomic_dec(&tpg->tpg_pr_ref_count);
@@ -1401,7 +1401,7 @@ static int core_scsi3_nodeacl_depend_item(struct se_node_acl *nacl)
1401 if (nacl->dynamic_node_acl) 1401 if (nacl->dynamic_node_acl)
1402 return 0; 1402 return 0;
1403 1403
1404 return configfs_depend_item(TPG_TFO(tpg)->tf_subsys, 1404 return configfs_depend_item(tpg->se_tpg_tfo->tf_subsys,
1405 &nacl->acl_group.cg_item); 1405 &nacl->acl_group.cg_item);
1406} 1406}
1407 1407
@@ -1415,7 +1415,7 @@ static void core_scsi3_nodeacl_undepend_item(struct se_node_acl *nacl)
1415 return; 1415 return;
1416 } 1416 }
1417 1417
1418 configfs_undepend_item(TPG_TFO(tpg)->tf_subsys, 1418 configfs_undepend_item(tpg->se_tpg_tfo->tf_subsys,
1419 &nacl->acl_group.cg_item); 1419 &nacl->acl_group.cg_item);
1420 1420
1421 atomic_dec(&nacl->acl_pr_ref_count); 1421 atomic_dec(&nacl->acl_pr_ref_count);
@@ -1430,13 +1430,13 @@ static int core_scsi3_lunacl_depend_item(struct se_dev_entry *se_deve)
1430 /* 1430 /*
1431 * For nacl->dynamic_node_acl=1 1431 * For nacl->dynamic_node_acl=1
1432 */ 1432 */
1433 if (!(lun_acl)) 1433 if (!lun_acl)
1434 return 0; 1434 return 0;
1435 1435
1436 nacl = lun_acl->se_lun_nacl; 1436 nacl = lun_acl->se_lun_nacl;
1437 tpg = nacl->se_tpg; 1437 tpg = nacl->se_tpg;
1438 1438
1439 return configfs_depend_item(TPG_TFO(tpg)->tf_subsys, 1439 return configfs_depend_item(tpg->se_tpg_tfo->tf_subsys,
1440 &lun_acl->se_lun_group.cg_item); 1440 &lun_acl->se_lun_group.cg_item);
1441} 1441}
1442 1442
@@ -1448,7 +1448,7 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
1448 /* 1448 /*
1449 * For nacl->dynamic_node_acl=1 1449 * For nacl->dynamic_node_acl=1
1450 */ 1450 */
1451 if (!(lun_acl)) { 1451 if (!lun_acl) {
1452 atomic_dec(&se_deve->pr_ref_count); 1452 atomic_dec(&se_deve->pr_ref_count);
1453 smp_mb__after_atomic_dec(); 1453 smp_mb__after_atomic_dec();
1454 return; 1454 return;
@@ -1456,7 +1456,7 @@ static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve)
1456 nacl = lun_acl->se_lun_nacl; 1456 nacl = lun_acl->se_lun_nacl;
1457 tpg = nacl->se_tpg; 1457 tpg = nacl->se_tpg;
1458 1458
1459 configfs_undepend_item(TPG_TFO(tpg)->tf_subsys, 1459 configfs_undepend_item(tpg->se_tpg_tfo->tf_subsys,
1460 &lun_acl->se_lun_group.cg_item); 1460 &lun_acl->se_lun_group.cg_item);
1461 1461
1462 atomic_dec(&se_deve->pr_ref_count); 1462 atomic_dec(&se_deve->pr_ref_count);
@@ -1471,10 +1471,10 @@ static int core_scsi3_decode_spec_i_port(
1471 int all_tg_pt, 1471 int all_tg_pt,
1472 int aptpl) 1472 int aptpl)
1473{ 1473{
1474 struct se_device *dev = SE_DEV(cmd); 1474 struct se_device *dev = cmd->se_dev;
1475 struct se_port *tmp_port; 1475 struct se_port *tmp_port;
1476 struct se_portal_group *dest_tpg = NULL, *tmp_tpg; 1476 struct se_portal_group *dest_tpg = NULL, *tmp_tpg;
1477 struct se_session *se_sess = SE_SESS(cmd); 1477 struct se_session *se_sess = cmd->se_sess;
1478 struct se_node_acl *dest_node_acl = NULL; 1478 struct se_node_acl *dest_node_acl = NULL;
1479 struct se_dev_entry *dest_se_deve = NULL, *local_se_deve; 1479 struct se_dev_entry *dest_se_deve = NULL, *local_se_deve;
1480 struct t10_pr_registration *dest_pr_reg, *local_pr_reg, *pr_reg_e; 1480 struct t10_pr_registration *dest_pr_reg, *local_pr_reg, *pr_reg_e;
@@ -1482,7 +1482,7 @@ static int core_scsi3_decode_spec_i_port(
1482 struct list_head tid_dest_list; 1482 struct list_head tid_dest_list;
1483 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp; 1483 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp;
1484 struct target_core_fabric_ops *tmp_tf_ops; 1484 struct target_core_fabric_ops *tmp_tf_ops;
1485 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 1485 unsigned char *buf;
1486 unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident; 1486 unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident;
1487 char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN]; 1487 char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN];
1488 u32 tpdl, tid_len = 0; 1488 u32 tpdl, tid_len = 0;
@@ -1500,8 +1500,8 @@ static int core_scsi3_decode_spec_i_port(
1500 * processing in the loop of tid_dest_list below. 1500 * processing in the loop of tid_dest_list below.
1501 */ 1501 */
1502 tidh_new = kzalloc(sizeof(struct pr_transport_id_holder), GFP_KERNEL); 1502 tidh_new = kzalloc(sizeof(struct pr_transport_id_holder), GFP_KERNEL);
1503 if (!(tidh_new)) { 1503 if (!tidh_new) {
1504 printk(KERN_ERR "Unable to allocate tidh_new\n"); 1504 pr_err("Unable to allocate tidh_new\n");
1505 return PYX_TRANSPORT_LU_COMM_FAILURE; 1505 return PYX_TRANSPORT_LU_COMM_FAILURE;
1506 } 1506 }
1507 INIT_LIST_HEAD(&tidh_new->dest_list); 1507 INIT_LIST_HEAD(&tidh_new->dest_list);
@@ -1509,10 +1509,10 @@ static int core_scsi3_decode_spec_i_port(
1509 tidh_new->dest_node_acl = se_sess->se_node_acl; 1509 tidh_new->dest_node_acl = se_sess->se_node_acl;
1510 tidh_new->dest_se_deve = local_se_deve; 1510 tidh_new->dest_se_deve = local_se_deve;
1511 1511
1512 local_pr_reg = __core_scsi3_alloc_registration(SE_DEV(cmd), 1512 local_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev,
1513 se_sess->se_node_acl, local_se_deve, l_isid, 1513 se_sess->se_node_acl, local_se_deve, l_isid,
1514 sa_res_key, all_tg_pt, aptpl); 1514 sa_res_key, all_tg_pt, aptpl);
1515 if (!(local_pr_reg)) { 1515 if (!local_pr_reg) {
1516 kfree(tidh_new); 1516 kfree(tidh_new);
1517 return PYX_TRANSPORT_LU_COMM_FAILURE; 1517 return PYX_TRANSPORT_LU_COMM_FAILURE;
1518 } 1518 }
@@ -1524,6 +1524,8 @@ static int core_scsi3_decode_spec_i_port(
1524 */ 1524 */
1525 tidh_new->dest_local_nexus = 1; 1525 tidh_new->dest_local_nexus = 1;
1526 list_add_tail(&tidh_new->dest_list, &tid_dest_list); 1526 list_add_tail(&tidh_new->dest_list, &tid_dest_list);
1527
1528 buf = transport_kmap_first_data_page(cmd);
1527 /* 1529 /*
1528 * For a PERSISTENT RESERVE OUT specify initiator ports payload, 1530 * For a PERSISTENT RESERVE OUT specify initiator ports payload,
1529 * first extract TransportID Parameter Data Length, and make sure 1531 * first extract TransportID Parameter Data Length, and make sure
@@ -1535,7 +1537,7 @@ static int core_scsi3_decode_spec_i_port(
1535 tpdl |= buf[27] & 0xff; 1537 tpdl |= buf[27] & 0xff;
1536 1538
1537 if ((tpdl + 28) != cmd->data_length) { 1539 if ((tpdl + 28) != cmd->data_length) {
1538 printk(KERN_ERR "SPC-3 PR: Illegal tpdl: %u + 28 byte header" 1540 pr_err("SPC-3 PR: Illegal tpdl: %u + 28 byte header"
1539 " does not equal CDB data_length: %u\n", tpdl, 1541 " does not equal CDB data_length: %u\n", tpdl,
1540 cmd->data_length); 1542 cmd->data_length);
1541 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST; 1543 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
@@ -1555,13 +1557,13 @@ static int core_scsi3_decode_spec_i_port(
1555 spin_lock(&dev->se_port_lock); 1557 spin_lock(&dev->se_port_lock);
1556 list_for_each_entry(tmp_port, &dev->dev_sep_list, sep_list) { 1558 list_for_each_entry(tmp_port, &dev->dev_sep_list, sep_list) {
1557 tmp_tpg = tmp_port->sep_tpg; 1559 tmp_tpg = tmp_port->sep_tpg;
1558 if (!(tmp_tpg)) 1560 if (!tmp_tpg)
1559 continue; 1561 continue;
1560 tmp_tf_ops = TPG_TFO(tmp_tpg); 1562 tmp_tf_ops = tmp_tpg->se_tpg_tfo;
1561 if (!(tmp_tf_ops)) 1563 if (!tmp_tf_ops)
1562 continue; 1564 continue;
1563 if (!(tmp_tf_ops->get_fabric_proto_ident) || 1565 if (!tmp_tf_ops->get_fabric_proto_ident ||
1564 !(tmp_tf_ops->tpg_parse_pr_out_transport_id)) 1566 !tmp_tf_ops->tpg_parse_pr_out_transport_id)
1565 continue; 1567 continue;
1566 /* 1568 /*
1567 * Look for the matching proto_ident provided by 1569 * Look for the matching proto_ident provided by
@@ -1575,7 +1577,7 @@ static int core_scsi3_decode_spec_i_port(
1575 i_str = tmp_tf_ops->tpg_parse_pr_out_transport_id( 1577 i_str = tmp_tf_ops->tpg_parse_pr_out_transport_id(
1576 tmp_tpg, (const char *)ptr, &tid_len, 1578 tmp_tpg, (const char *)ptr, &tid_len,
1577 &iport_ptr); 1579 &iport_ptr);
1578 if (!(i_str)) 1580 if (!i_str)
1579 continue; 1581 continue;
1580 1582
1581 atomic_inc(&tmp_tpg->tpg_pr_ref_count); 1583 atomic_inc(&tmp_tpg->tpg_pr_ref_count);
@@ -1584,7 +1586,7 @@ static int core_scsi3_decode_spec_i_port(
1584 1586
1585 ret = core_scsi3_tpg_depend_item(tmp_tpg); 1587 ret = core_scsi3_tpg_depend_item(tmp_tpg);
1586 if (ret != 0) { 1588 if (ret != 0) {
1587 printk(KERN_ERR " core_scsi3_tpg_depend_item()" 1589 pr_err(" core_scsi3_tpg_depend_item()"
1588 " for tmp_tpg\n"); 1590 " for tmp_tpg\n");
1589 atomic_dec(&tmp_tpg->tpg_pr_ref_count); 1591 atomic_dec(&tmp_tpg->tpg_pr_ref_count);
1590 smp_mb__after_atomic_dec(); 1592 smp_mb__after_atomic_dec();
@@ -1605,7 +1607,7 @@ static int core_scsi3_decode_spec_i_port(
1605 } 1607 }
1606 spin_unlock_bh(&tmp_tpg->acl_node_lock); 1608 spin_unlock_bh(&tmp_tpg->acl_node_lock);
1607 1609
1608 if (!(dest_node_acl)) { 1610 if (!dest_node_acl) {
1609 core_scsi3_tpg_undepend_item(tmp_tpg); 1611 core_scsi3_tpg_undepend_item(tmp_tpg);
1610 spin_lock(&dev->se_port_lock); 1612 spin_lock(&dev->se_port_lock);
1611 continue; 1613 continue;
@@ -1613,7 +1615,7 @@ static int core_scsi3_decode_spec_i_port(
1613 1615
1614 ret = core_scsi3_nodeacl_depend_item(dest_node_acl); 1616 ret = core_scsi3_nodeacl_depend_item(dest_node_acl);
1615 if (ret != 0) { 1617 if (ret != 0) {
1616 printk(KERN_ERR "configfs_depend_item() failed" 1618 pr_err("configfs_depend_item() failed"
1617 " for dest_node_acl->acl_group\n"); 1619 " for dest_node_acl->acl_group\n");
1618 atomic_dec(&dest_node_acl->acl_pr_ref_count); 1620 atomic_dec(&dest_node_acl->acl_pr_ref_count);
1619 smp_mb__after_atomic_dec(); 1621 smp_mb__after_atomic_dec();
@@ -1623,9 +1625,9 @@ static int core_scsi3_decode_spec_i_port(
1623 } 1625 }
1624 1626
1625 dest_tpg = tmp_tpg; 1627 dest_tpg = tmp_tpg;
1626 printk(KERN_INFO "SPC-3 PR SPEC_I_PT: Located %s Node:" 1628 pr_debug("SPC-3 PR SPEC_I_PT: Located %s Node:"
1627 " %s Port RTPI: %hu\n", 1629 " %s Port RTPI: %hu\n",
1628 TPG_TFO(dest_tpg)->get_fabric_name(), 1630 dest_tpg->se_tpg_tfo->get_fabric_name(),
1629 dest_node_acl->initiatorname, dest_rtpi); 1631 dest_node_acl->initiatorname, dest_rtpi);
1630 1632
1631 spin_lock(&dev->se_port_lock); 1633 spin_lock(&dev->se_port_lock);
@@ -1633,20 +1635,20 @@ static int core_scsi3_decode_spec_i_port(
1633 } 1635 }
1634 spin_unlock(&dev->se_port_lock); 1636 spin_unlock(&dev->se_port_lock);
1635 1637
1636 if (!(dest_tpg)) { 1638 if (!dest_tpg) {
1637 printk(KERN_ERR "SPC-3 PR SPEC_I_PT: Unable to locate" 1639 pr_err("SPC-3 PR SPEC_I_PT: Unable to locate"
1638 " dest_tpg\n"); 1640 " dest_tpg\n");
1639 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST; 1641 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
1640 goto out; 1642 goto out;
1641 } 1643 }
1642#if 0 1644#if 0
1643 printk("SPC-3 PR SPEC_I_PT: Got %s data_length: %u tpdl: %u" 1645 pr_debug("SPC-3 PR SPEC_I_PT: Got %s data_length: %u tpdl: %u"
1644 " tid_len: %d for %s + %s\n", 1646 " tid_len: %d for %s + %s\n",
1645 TPG_TFO(dest_tpg)->get_fabric_name(), cmd->data_length, 1647 dest_tpg->se_tpg_tfo->get_fabric_name(), cmd->data_length,
1646 tpdl, tid_len, i_str, iport_ptr); 1648 tpdl, tid_len, i_str, iport_ptr);
1647#endif 1649#endif
1648 if (tid_len > tpdl) { 1650 if (tid_len > tpdl) {
1649 printk(KERN_ERR "SPC-3 PR SPEC_I_PT: Illegal tid_len:" 1651 pr_err("SPC-3 PR SPEC_I_PT: Illegal tid_len:"
1650 " %u for Transport ID: %s\n", tid_len, ptr); 1652 " %u for Transport ID: %s\n", tid_len, ptr);
1651 core_scsi3_nodeacl_undepend_item(dest_node_acl); 1653 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1652 core_scsi3_tpg_undepend_item(dest_tpg); 1654 core_scsi3_tpg_undepend_item(dest_tpg);
@@ -1660,10 +1662,10 @@ static int core_scsi3_decode_spec_i_port(
1660 */ 1662 */
1661 dest_se_deve = core_get_se_deve_from_rtpi(dest_node_acl, 1663 dest_se_deve = core_get_se_deve_from_rtpi(dest_node_acl,
1662 dest_rtpi); 1664 dest_rtpi);
1663 if (!(dest_se_deve)) { 1665 if (!dest_se_deve) {
1664 printk(KERN_ERR "Unable to locate %s dest_se_deve" 1666 pr_err("Unable to locate %s dest_se_deve"
1665 " from destination RTPI: %hu\n", 1667 " from destination RTPI: %hu\n",
1666 TPG_TFO(dest_tpg)->get_fabric_name(), 1668 dest_tpg->se_tpg_tfo->get_fabric_name(),
1667 dest_rtpi); 1669 dest_rtpi);
1668 1670
1669 core_scsi3_nodeacl_undepend_item(dest_node_acl); 1671 core_scsi3_nodeacl_undepend_item(dest_node_acl);
@@ -1674,7 +1676,7 @@ static int core_scsi3_decode_spec_i_port(
1674 1676
1675 ret = core_scsi3_lunacl_depend_item(dest_se_deve); 1677 ret = core_scsi3_lunacl_depend_item(dest_se_deve);
1676 if (ret < 0) { 1678 if (ret < 0) {
1677 printk(KERN_ERR "core_scsi3_lunacl_depend_item()" 1679 pr_err("core_scsi3_lunacl_depend_item()"
1678 " failed\n"); 1680 " failed\n");
1679 atomic_dec(&dest_se_deve->pr_ref_count); 1681 atomic_dec(&dest_se_deve->pr_ref_count);
1680 smp_mb__after_atomic_dec(); 1682 smp_mb__after_atomic_dec();
@@ -1684,9 +1686,9 @@ static int core_scsi3_decode_spec_i_port(
1684 goto out; 1686 goto out;
1685 } 1687 }
1686#if 0 1688#if 0
1687 printk(KERN_INFO "SPC-3 PR SPEC_I_PT: Located %s Node: %s" 1689 pr_debug("SPC-3 PR SPEC_I_PT: Located %s Node: %s"
1688 " dest_se_deve mapped_lun: %u\n", 1690 " dest_se_deve mapped_lun: %u\n",
1689 TPG_TFO(dest_tpg)->get_fabric_name(), 1691 dest_tpg->se_tpg_tfo->get_fabric_name(),
1690 dest_node_acl->initiatorname, dest_se_deve->mapped_lun); 1692 dest_node_acl->initiatorname, dest_se_deve->mapped_lun);
1691#endif 1693#endif
1692 /* 1694 /*
@@ -1712,8 +1714,8 @@ static int core_scsi3_decode_spec_i_port(
1712 */ 1714 */
1713 tidh_new = kzalloc(sizeof(struct pr_transport_id_holder), 1715 tidh_new = kzalloc(sizeof(struct pr_transport_id_holder),
1714 GFP_KERNEL); 1716 GFP_KERNEL);
1715 if (!(tidh_new)) { 1717 if (!tidh_new) {
1716 printk(KERN_ERR "Unable to allocate tidh_new\n"); 1718 pr_err("Unable to allocate tidh_new\n");
1717 core_scsi3_lunacl_undepend_item(dest_se_deve); 1719 core_scsi3_lunacl_undepend_item(dest_se_deve);
1718 core_scsi3_nodeacl_undepend_item(dest_node_acl); 1720 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1719 core_scsi3_tpg_undepend_item(dest_tpg); 1721 core_scsi3_tpg_undepend_item(dest_tpg);
@@ -1741,10 +1743,10 @@ static int core_scsi3_decode_spec_i_port(
1741 * and then call __core_scsi3_add_registration() in the 1743 * and then call __core_scsi3_add_registration() in the
1742 * 2nd loop which will never fail. 1744 * 2nd loop which will never fail.
1743 */ 1745 */
1744 dest_pr_reg = __core_scsi3_alloc_registration(SE_DEV(cmd), 1746 dest_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev,
1745 dest_node_acl, dest_se_deve, iport_ptr, 1747 dest_node_acl, dest_se_deve, iport_ptr,
1746 sa_res_key, all_tg_pt, aptpl); 1748 sa_res_key, all_tg_pt, aptpl);
1747 if (!(dest_pr_reg)) { 1749 if (!dest_pr_reg) {
1748 core_scsi3_lunacl_undepend_item(dest_se_deve); 1750 core_scsi3_lunacl_undepend_item(dest_se_deve);
1749 core_scsi3_nodeacl_undepend_item(dest_node_acl); 1751 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1750 core_scsi3_tpg_undepend_item(dest_tpg); 1752 core_scsi3_tpg_undepend_item(dest_tpg);
@@ -1760,6 +1762,9 @@ static int core_scsi3_decode_spec_i_port(
1760 tid_len = 0; 1762 tid_len = 0;
1761 1763
1762 } 1764 }
1765
1766 transport_kunmap_first_data_page(cmd);
1767
1763 /* 1768 /*
1764 * Go ahead and create a registrations from tid_dest_list for the 1769 * Go ahead and create a registrations from tid_dest_list for the
1765 * SPEC_I_PT provided TransportID for the *tidh referenced dest_node_acl 1770 * SPEC_I_PT provided TransportID for the *tidh referenced dest_node_acl
@@ -1787,12 +1792,12 @@ static int core_scsi3_decode_spec_i_port(
1787 prf_isid = core_pr_dump_initiator_port(dest_pr_reg, &i_buf[0], 1792 prf_isid = core_pr_dump_initiator_port(dest_pr_reg, &i_buf[0],
1788 PR_REG_ISID_ID_LEN); 1793 PR_REG_ISID_ID_LEN);
1789 1794
1790 __core_scsi3_add_registration(SE_DEV(cmd), dest_node_acl, 1795 __core_scsi3_add_registration(cmd->se_dev, dest_node_acl,
1791 dest_pr_reg, 0, 0); 1796 dest_pr_reg, 0, 0);
1792 1797
1793 printk(KERN_INFO "SPC-3 PR [%s] SPEC_I_PT: Successfully" 1798 pr_debug("SPC-3 PR [%s] SPEC_I_PT: Successfully"
1794 " registered Transport ID for Node: %s%s Mapped LUN:" 1799 " registered Transport ID for Node: %s%s Mapped LUN:"
1795 " %u\n", TPG_TFO(dest_tpg)->get_fabric_name(), 1800 " %u\n", dest_tpg->se_tpg_tfo->get_fabric_name(),
1796 dest_node_acl->initiatorname, (prf_isid) ? 1801 dest_node_acl->initiatorname, (prf_isid) ?
1797 &i_buf[0] : "", dest_se_deve->mapped_lun); 1802 &i_buf[0] : "", dest_se_deve->mapped_lun);
1798 1803
@@ -1806,6 +1811,7 @@ static int core_scsi3_decode_spec_i_port(
1806 1811
1807 return 0; 1812 return 0;
1808out: 1813out:
1814 transport_kunmap_first_data_page(cmd);
1809 /* 1815 /*
1810 * For the failure case, release everything from tid_dest_list 1816 * For the failure case, release everything from tid_dest_list
1811 * including *dest_pr_reg and the configfs dependances.. 1817 * including *dest_pr_reg and the configfs dependances..
@@ -1855,7 +1861,7 @@ static int __core_scsi3_update_aptpl_buf(
1855{ 1861{
1856 struct se_lun *lun; 1862 struct se_lun *lun;
1857 struct se_portal_group *tpg; 1863 struct se_portal_group *tpg;
1858 struct se_subsystem_dev *su_dev = SU_DEV(dev); 1864 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
1859 struct t10_pr_registration *pr_reg; 1865 struct t10_pr_registration *pr_reg;
1860 unsigned char tmp[512], isid_buf[32]; 1866 unsigned char tmp[512], isid_buf[32];
1861 ssize_t len = 0; 1867 ssize_t len = 0;
@@ -1873,8 +1879,8 @@ static int __core_scsi3_update_aptpl_buf(
1873 /* 1879 /*
1874 * Walk the registration list.. 1880 * Walk the registration list..
1875 */ 1881 */
1876 spin_lock(&T10_RES(su_dev)->registration_lock); 1882 spin_lock(&su_dev->t10_pr.registration_lock);
1877 list_for_each_entry(pr_reg, &T10_RES(su_dev)->registration_list, 1883 list_for_each_entry(pr_reg, &su_dev->t10_pr.registration_list,
1878 pr_reg_list) { 1884 pr_reg_list) {
1879 1885
1880 tmp[0] = '\0'; 1886 tmp[0] = '\0';
@@ -1900,7 +1906,7 @@ static int __core_scsi3_update_aptpl_buf(
1900 "res_holder=1\nres_type=%02x\n" 1906 "res_holder=1\nres_type=%02x\n"
1901 "res_scope=%02x\nres_all_tg_pt=%d\n" 1907 "res_scope=%02x\nres_all_tg_pt=%d\n"
1902 "mapped_lun=%u\n", reg_count, 1908 "mapped_lun=%u\n", reg_count,
1903 TPG_TFO(tpg)->get_fabric_name(), 1909 tpg->se_tpg_tfo->get_fabric_name(),
1904 pr_reg->pr_reg_nacl->initiatorname, isid_buf, 1910 pr_reg->pr_reg_nacl->initiatorname, isid_buf,
1905 pr_reg->pr_res_key, pr_reg->pr_res_type, 1911 pr_reg->pr_res_key, pr_reg->pr_res_type,
1906 pr_reg->pr_res_scope, pr_reg->pr_reg_all_tg_pt, 1912 pr_reg->pr_res_scope, pr_reg->pr_reg_all_tg_pt,
@@ -1910,17 +1916,17 @@ static int __core_scsi3_update_aptpl_buf(
1910 "initiator_fabric=%s\ninitiator_node=%s\n%s" 1916 "initiator_fabric=%s\ninitiator_node=%s\n%s"
1911 "sa_res_key=%llu\nres_holder=0\n" 1917 "sa_res_key=%llu\nres_holder=0\n"
1912 "res_all_tg_pt=%d\nmapped_lun=%u\n", 1918 "res_all_tg_pt=%d\nmapped_lun=%u\n",
1913 reg_count, TPG_TFO(tpg)->get_fabric_name(), 1919 reg_count, tpg->se_tpg_tfo->get_fabric_name(),
1914 pr_reg->pr_reg_nacl->initiatorname, isid_buf, 1920 pr_reg->pr_reg_nacl->initiatorname, isid_buf,
1915 pr_reg->pr_res_key, pr_reg->pr_reg_all_tg_pt, 1921 pr_reg->pr_res_key, pr_reg->pr_reg_all_tg_pt,
1916 pr_reg->pr_res_mapped_lun); 1922 pr_reg->pr_res_mapped_lun);
1917 } 1923 }
1918 1924
1919 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { 1925 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) {
1920 printk(KERN_ERR "Unable to update renaming" 1926 pr_err("Unable to update renaming"
1921 " APTPL metadata\n"); 1927 " APTPL metadata\n");
1922 spin_unlock(&T10_RES(su_dev)->registration_lock); 1928 spin_unlock(&su_dev->t10_pr.registration_lock);
1923 return -1; 1929 return -EMSGSIZE;
1924 } 1930 }
1925 len += sprintf(buf+len, "%s", tmp); 1931 len += sprintf(buf+len, "%s", tmp);
1926 1932
@@ -1929,23 +1935,23 @@ static int __core_scsi3_update_aptpl_buf(
1929 */ 1935 */
1930 snprintf(tmp, 512, "target_fabric=%s\ntarget_node=%s\n" 1936 snprintf(tmp, 512, "target_fabric=%s\ntarget_node=%s\n"
1931 "tpgt=%hu\nport_rtpi=%hu\ntarget_lun=%u\nPR_REG_END:" 1937 "tpgt=%hu\nport_rtpi=%hu\ntarget_lun=%u\nPR_REG_END:"
1932 " %d\n", TPG_TFO(tpg)->get_fabric_name(), 1938 " %d\n", tpg->se_tpg_tfo->get_fabric_name(),
1933 TPG_TFO(tpg)->tpg_get_wwn(tpg), 1939 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1934 TPG_TFO(tpg)->tpg_get_tag(tpg), 1940 tpg->se_tpg_tfo->tpg_get_tag(tpg),
1935 lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count); 1941 lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count);
1936 1942
1937 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { 1943 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) {
1938 printk(KERN_ERR "Unable to update renaming" 1944 pr_err("Unable to update renaming"
1939 " APTPL metadata\n"); 1945 " APTPL metadata\n");
1940 spin_unlock(&T10_RES(su_dev)->registration_lock); 1946 spin_unlock(&su_dev->t10_pr.registration_lock);
1941 return -1; 1947 return -EMSGSIZE;
1942 } 1948 }
1943 len += sprintf(buf+len, "%s", tmp); 1949 len += sprintf(buf+len, "%s", tmp);
1944 reg_count++; 1950 reg_count++;
1945 } 1951 }
1946 spin_unlock(&T10_RES(su_dev)->registration_lock); 1952 spin_unlock(&su_dev->t10_pr.registration_lock);
1947 1953
1948 if (!(reg_count)) 1954 if (!reg_count)
1949 len += sprintf(buf+len, "No Registrations or Reservations"); 1955 len += sprintf(buf+len, "No Registrations or Reservations");
1950 1956
1951 return 0; 1957 return 0;
@@ -1975,7 +1981,7 @@ static int __core_scsi3_write_aptpl_to_file(
1975 unsigned char *buf, 1981 unsigned char *buf,
1976 u32 pr_aptpl_buf_len) 1982 u32 pr_aptpl_buf_len)
1977{ 1983{
1978 struct t10_wwn *wwn = &SU_DEV(dev)->t10_wwn; 1984 struct t10_wwn *wwn = &dev->se_sub_dev->t10_wwn;
1979 struct file *file; 1985 struct file *file;
1980 struct iovec iov[1]; 1986 struct iovec iov[1];
1981 mm_segment_t old_fs; 1987 mm_segment_t old_fs;
@@ -1987,21 +1993,21 @@ static int __core_scsi3_write_aptpl_to_file(
1987 memset(path, 0, 512); 1993 memset(path, 0, 512);
1988 1994
1989 if (strlen(&wwn->unit_serial[0]) >= 512) { 1995 if (strlen(&wwn->unit_serial[0]) >= 512) {
1990 printk(KERN_ERR "WWN value for struct se_device does not fit" 1996 pr_err("WWN value for struct se_device does not fit"
1991 " into path buffer\n"); 1997 " into path buffer\n");
1992 return -1; 1998 return -EMSGSIZE;
1993 } 1999 }
1994 2000
1995 snprintf(path, 512, "/var/target/pr/aptpl_%s", &wwn->unit_serial[0]); 2001 snprintf(path, 512, "/var/target/pr/aptpl_%s", &wwn->unit_serial[0]);
1996 file = filp_open(path, flags, 0600); 2002 file = filp_open(path, flags, 0600);
1997 if (IS_ERR(file) || !file || !file->f_dentry) { 2003 if (IS_ERR(file) || !file || !file->f_dentry) {
1998 printk(KERN_ERR "filp_open(%s) for APTPL metadata" 2004 pr_err("filp_open(%s) for APTPL metadata"
1999 " failed\n", path); 2005 " failed\n", path);
2000 return -1; 2006 return (PTR_ERR(file) < 0 ? PTR_ERR(file) : -ENOENT);
2001 } 2007 }
2002 2008
2003 iov[0].iov_base = &buf[0]; 2009 iov[0].iov_base = &buf[0];
2004 if (!(pr_aptpl_buf_len)) 2010 if (!pr_aptpl_buf_len)
2005 iov[0].iov_len = (strlen(&buf[0]) + 1); /* Add extra for NULL */ 2011 iov[0].iov_len = (strlen(&buf[0]) + 1); /* Add extra for NULL */
2006 else 2012 else
2007 iov[0].iov_len = pr_aptpl_buf_len; 2013 iov[0].iov_len = pr_aptpl_buf_len;
@@ -2012,9 +2018,9 @@ static int __core_scsi3_write_aptpl_to_file(
2012 set_fs(old_fs); 2018 set_fs(old_fs);
2013 2019
2014 if (ret < 0) { 2020 if (ret < 0) {
2015 printk("Error writing APTPL metadata file: %s\n", path); 2021 pr_debug("Error writing APTPL metadata file: %s\n", path);
2016 filp_close(file, NULL); 2022 filp_close(file, NULL);
2017 return -1; 2023 return -EIO;
2018 } 2024 }
2019 filp_close(file, NULL); 2025 filp_close(file, NULL);
2020 2026
@@ -2032,7 +2038,7 @@ static int core_scsi3_update_and_write_aptpl(
2032 /* 2038 /*
2033 * Can be called with a NULL pointer from PROUT service action CLEAR 2039 * Can be called with a NULL pointer from PROUT service action CLEAR
2034 */ 2040 */
2035 if (!(in_buf)) { 2041 if (!in_buf) {
2036 memset(null_buf, 0, 64); 2042 memset(null_buf, 0, 64);
2037 buf = &null_buf[0]; 2043 buf = &null_buf[0];
2038 /* 2044 /*
@@ -2049,14 +2055,14 @@ static int core_scsi3_update_and_write_aptpl(
2049 ret = core_scsi3_update_aptpl_buf(dev, buf, pr_aptpl_buf_len, 2055 ret = core_scsi3_update_aptpl_buf(dev, buf, pr_aptpl_buf_len,
2050 clear_aptpl_metadata); 2056 clear_aptpl_metadata);
2051 if (ret != 0) 2057 if (ret != 0)
2052 return -1; 2058 return ret;
2053 /* 2059 /*
2054 * __core_scsi3_write_aptpl_to_file() will call strlen() 2060 * __core_scsi3_write_aptpl_to_file() will call strlen()
2055 * on the passed buf to determine pr_aptpl_buf_len. 2061 * on the passed buf to determine pr_aptpl_buf_len.
2056 */ 2062 */
2057 ret = __core_scsi3_write_aptpl_to_file(dev, buf, 0); 2063 ret = __core_scsi3_write_aptpl_to_file(dev, buf, 0);
2058 if (ret != 0) 2064 if (ret != 0)
2059 return -1; 2065 return ret;
2060 2066
2061 return ret; 2067 return ret;
2062} 2068}
@@ -2070,28 +2076,28 @@ static int core_scsi3_emulate_pro_register(
2070 int spec_i_pt, 2076 int spec_i_pt,
2071 int ignore_key) 2077 int ignore_key)
2072{ 2078{
2073 struct se_session *se_sess = SE_SESS(cmd); 2079 struct se_session *se_sess = cmd->se_sess;
2074 struct se_device *dev = SE_DEV(cmd); 2080 struct se_device *dev = cmd->se_dev;
2075 struct se_dev_entry *se_deve; 2081 struct se_dev_entry *se_deve;
2076 struct se_lun *se_lun = SE_LUN(cmd); 2082 struct se_lun *se_lun = cmd->se_lun;
2077 struct se_portal_group *se_tpg; 2083 struct se_portal_group *se_tpg;
2078 struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_reg_tmp, *pr_reg_e; 2084 struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_reg_tmp, *pr_reg_e;
2079 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 2085 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
2080 /* Used for APTPL metadata w/ UNREGISTER */ 2086 /* Used for APTPL metadata w/ UNREGISTER */
2081 unsigned char *pr_aptpl_buf = NULL; 2087 unsigned char *pr_aptpl_buf = NULL;
2082 unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL; 2088 unsigned char isid_buf[PR_REG_ISID_LEN], *isid_ptr = NULL;
2083 int pr_holder = 0, ret = 0, type; 2089 int pr_holder = 0, ret = 0, type;
2084 2090
2085 if (!(se_sess) || !(se_lun)) { 2091 if (!se_sess || !se_lun) {
2086 printk(KERN_ERR "SPC-3 PR: se_sess || struct se_lun is NULL!\n"); 2092 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n");
2087 return PYX_TRANSPORT_LU_COMM_FAILURE; 2093 return PYX_TRANSPORT_LU_COMM_FAILURE;
2088 } 2094 }
2089 se_tpg = se_sess->se_tpg; 2095 se_tpg = se_sess->se_tpg;
2090 se_deve = &se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 2096 se_deve = &se_sess->se_node_acl->device_list[cmd->orig_fe_lun];
2091 2097
2092 if (TPG_TFO(se_tpg)->sess_get_initiator_sid != NULL) { 2098 if (se_tpg->se_tpg_tfo->sess_get_initiator_sid) {
2093 memset(&isid_buf[0], 0, PR_REG_ISID_LEN); 2099 memset(&isid_buf[0], 0, PR_REG_ISID_LEN);
2094 TPG_TFO(se_tpg)->sess_get_initiator_sid(se_sess, &isid_buf[0], 2100 se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, &isid_buf[0],
2095 PR_REG_ISID_LEN); 2101 PR_REG_ISID_LEN);
2096 isid_ptr = &isid_buf[0]; 2102 isid_ptr = &isid_buf[0];
2097 } 2103 }
@@ -2099,30 +2105,30 @@ static int core_scsi3_emulate_pro_register(
2099 * Follow logic from spc4r17 Section 5.7.7, Register Behaviors Table 47 2105 * Follow logic from spc4r17 Section 5.7.7, Register Behaviors Table 47
2100 */ 2106 */
2101 pr_reg_e = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess); 2107 pr_reg_e = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess);
2102 if (!(pr_reg_e)) { 2108 if (!pr_reg_e) {
2103 if (res_key) { 2109 if (res_key) {
2104 printk(KERN_WARNING "SPC-3 PR: Reservation Key non-zero" 2110 pr_warn("SPC-3 PR: Reservation Key non-zero"
2105 " for SA REGISTER, returning CONFLICT\n"); 2111 " for SA REGISTER, returning CONFLICT\n");
2106 return PYX_TRANSPORT_RESERVATION_CONFLICT; 2112 return PYX_TRANSPORT_RESERVATION_CONFLICT;
2107 } 2113 }
2108 /* 2114 /*
2109 * Do nothing but return GOOD status. 2115 * Do nothing but return GOOD status.
2110 */ 2116 */
2111 if (!(sa_res_key)) 2117 if (!sa_res_key)
2112 return PYX_TRANSPORT_SENT_TO_TRANSPORT; 2118 return PYX_TRANSPORT_SENT_TO_TRANSPORT;
2113 2119
2114 if (!(spec_i_pt)) { 2120 if (!spec_i_pt) {
2115 /* 2121 /*
2116 * Perform the Service Action REGISTER on the Initiator 2122 * Perform the Service Action REGISTER on the Initiator
2117 * Port Endpoint that the PRO was received from on the 2123 * Port Endpoint that the PRO was received from on the
2118 * Logical Unit of the SCSI device server. 2124 * Logical Unit of the SCSI device server.
2119 */ 2125 */
2120 ret = core_scsi3_alloc_registration(SE_DEV(cmd), 2126 ret = core_scsi3_alloc_registration(cmd->se_dev,
2121 se_sess->se_node_acl, se_deve, isid_ptr, 2127 se_sess->se_node_acl, se_deve, isid_ptr,
2122 sa_res_key, all_tg_pt, aptpl, 2128 sa_res_key, all_tg_pt, aptpl,
2123 ignore_key, 0); 2129 ignore_key, 0);
2124 if (ret != 0) { 2130 if (ret != 0) {
2125 printk(KERN_ERR "Unable to allocate" 2131 pr_err("Unable to allocate"
2126 " struct t10_pr_registration\n"); 2132 " struct t10_pr_registration\n");
2127 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 2133 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
2128 } 2134 }
@@ -2143,10 +2149,10 @@ static int core_scsi3_emulate_pro_register(
2143 /* 2149 /*
2144 * Nothing left to do for the APTPL=0 case. 2150 * Nothing left to do for the APTPL=0 case.
2145 */ 2151 */
2146 if (!(aptpl)) { 2152 if (!aptpl) {
2147 pr_tmpl->pr_aptpl_active = 0; 2153 pr_tmpl->pr_aptpl_active = 0;
2148 core_scsi3_update_and_write_aptpl(SE_DEV(cmd), NULL, 0); 2154 core_scsi3_update_and_write_aptpl(cmd->se_dev, NULL, 0);
2149 printk("SPC-3 PR: Set APTPL Bit Deactivated for" 2155 pr_debug("SPC-3 PR: Set APTPL Bit Deactivated for"
2150 " REGISTER\n"); 2156 " REGISTER\n");
2151 return 0; 2157 return 0;
2152 } 2158 }
@@ -2155,15 +2161,15 @@ static int core_scsi3_emulate_pro_register(
2155 * update the APTPL metadata information using its 2161 * update the APTPL metadata information using its
2156 * preallocated *pr_reg->pr_aptpl_buf. 2162 * preallocated *pr_reg->pr_aptpl_buf.
2157 */ 2163 */
2158 pr_reg = core_scsi3_locate_pr_reg(SE_DEV(cmd), 2164 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev,
2159 se_sess->se_node_acl, se_sess); 2165 se_sess->se_node_acl, se_sess);
2160 2166
2161 ret = core_scsi3_update_and_write_aptpl(SE_DEV(cmd), 2167 ret = core_scsi3_update_and_write_aptpl(cmd->se_dev,
2162 &pr_reg->pr_aptpl_buf[0], 2168 &pr_reg->pr_aptpl_buf[0],
2163 pr_tmpl->pr_aptpl_buf_len); 2169 pr_tmpl->pr_aptpl_buf_len);
2164 if (!(ret)) { 2170 if (!ret) {
2165 pr_tmpl->pr_aptpl_active = 1; 2171 pr_tmpl->pr_aptpl_active = 1;
2166 printk("SPC-3 PR: Set APTPL Bit Activated for REGISTER\n"); 2172 pr_debug("SPC-3 PR: Set APTPL Bit Activated for REGISTER\n");
2167 } 2173 }
2168 2174
2169 core_scsi3_put_pr_reg(pr_reg); 2175 core_scsi3_put_pr_reg(pr_reg);
@@ -2175,9 +2181,9 @@ static int core_scsi3_emulate_pro_register(
2175 pr_reg = pr_reg_e; 2181 pr_reg = pr_reg_e;
2176 type = pr_reg->pr_res_type; 2182 type = pr_reg->pr_res_type;
2177 2183
2178 if (!(ignore_key)) { 2184 if (!ignore_key) {
2179 if (res_key != pr_reg->pr_res_key) { 2185 if (res_key != pr_reg->pr_res_key) {
2180 printk(KERN_ERR "SPC-3 PR REGISTER: Received" 2186 pr_err("SPC-3 PR REGISTER: Received"
2181 " res_key: 0x%016Lx does not match" 2187 " res_key: 0x%016Lx does not match"
2182 " existing SA REGISTER res_key:" 2188 " existing SA REGISTER res_key:"
2183 " 0x%016Lx\n", res_key, 2189 " 0x%016Lx\n", res_key,
@@ -2187,7 +2193,7 @@ static int core_scsi3_emulate_pro_register(
2187 } 2193 }
2188 } 2194 }
2189 if (spec_i_pt) { 2195 if (spec_i_pt) {
2190 printk(KERN_ERR "SPC-3 PR UNREGISTER: SPEC_I_PT" 2196 pr_err("SPC-3 PR UNREGISTER: SPEC_I_PT"
2191 " set while sa_res_key=0\n"); 2197 " set while sa_res_key=0\n");
2192 core_scsi3_put_pr_reg(pr_reg); 2198 core_scsi3_put_pr_reg(pr_reg);
2193 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 2199 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
@@ -2197,7 +2203,7 @@ static int core_scsi3_emulate_pro_register(
2197 * must also set ALL_TG_PT=1 in the incoming PROUT. 2203 * must also set ALL_TG_PT=1 in the incoming PROUT.
2198 */ 2204 */
2199 if (pr_reg->pr_reg_all_tg_pt && !(all_tg_pt)) { 2205 if (pr_reg->pr_reg_all_tg_pt && !(all_tg_pt)) {
2200 printk(KERN_ERR "SPC-3 PR UNREGISTER: ALL_TG_PT=1" 2206 pr_err("SPC-3 PR UNREGISTER: ALL_TG_PT=1"
2201 " registration exists, but ALL_TG_PT=1 bit not" 2207 " registration exists, but ALL_TG_PT=1 bit not"
2202 " present in received PROUT\n"); 2208 " present in received PROUT\n");
2203 core_scsi3_put_pr_reg(pr_reg); 2209 core_scsi3_put_pr_reg(pr_reg);
@@ -2209,8 +2215,8 @@ static int core_scsi3_emulate_pro_register(
2209 if (aptpl) { 2215 if (aptpl) {
2210 pr_aptpl_buf = kzalloc(pr_tmpl->pr_aptpl_buf_len, 2216 pr_aptpl_buf = kzalloc(pr_tmpl->pr_aptpl_buf_len,
2211 GFP_KERNEL); 2217 GFP_KERNEL);
2212 if (!(pr_aptpl_buf)) { 2218 if (!pr_aptpl_buf) {
2213 printk(KERN_ERR "Unable to allocate" 2219 pr_err("Unable to allocate"
2214 " pr_aptpl_buf\n"); 2220 " pr_aptpl_buf\n");
2215 core_scsi3_put_pr_reg(pr_reg); 2221 core_scsi3_put_pr_reg(pr_reg);
2216 return PYX_TRANSPORT_LU_COMM_FAILURE; 2222 return PYX_TRANSPORT_LU_COMM_FAILURE;
@@ -2221,9 +2227,9 @@ static int core_scsi3_emulate_pro_register(
2221 * Nexus sa_res_key=1 Change Reservation Key for registered I_T 2227 * Nexus sa_res_key=1 Change Reservation Key for registered I_T
2222 * Nexus. 2228 * Nexus.
2223 */ 2229 */
2224 if (!(sa_res_key)) { 2230 if (!sa_res_key) {
2225 pr_holder = core_scsi3_check_implict_release( 2231 pr_holder = core_scsi3_check_implict_release(
2226 SE_DEV(cmd), pr_reg); 2232 cmd->se_dev, pr_reg);
2227 if (pr_holder < 0) { 2233 if (pr_holder < 0) {
2228 kfree(pr_aptpl_buf); 2234 kfree(pr_aptpl_buf);
2229 core_scsi3_put_pr_reg(pr_reg); 2235 core_scsi3_put_pr_reg(pr_reg);
@@ -2240,7 +2246,7 @@ static int core_scsi3_emulate_pro_register(
2240 &pr_tmpl->registration_list, 2246 &pr_tmpl->registration_list,
2241 pr_reg_list) { 2247 pr_reg_list) {
2242 2248
2243 if (!(pr_reg_p->pr_reg_all_tg_pt)) 2249 if (!pr_reg_p->pr_reg_all_tg_pt)
2244 continue; 2250 continue;
2245 2251
2246 if (pr_reg_p->pr_res_key != res_key) 2252 if (pr_reg_p->pr_res_key != res_key)
@@ -2260,7 +2266,7 @@ static int core_scsi3_emulate_pro_register(
2260 /* 2266 /*
2261 * Release the calling I_T Nexus registration now.. 2267 * Release the calling I_T Nexus registration now..
2262 */ 2268 */
2263 __core_scsi3_free_registration(SE_DEV(cmd), pr_reg, 2269 __core_scsi3_free_registration(cmd->se_dev, pr_reg,
2264 NULL, 1); 2270 NULL, 1);
2265 /* 2271 /*
2266 * From spc4r17, section 5.7.11.3 Unregistering 2272 * From spc4r17, section 5.7.11.3 Unregistering
@@ -2289,10 +2295,10 @@ static int core_scsi3_emulate_pro_register(
2289 } 2295 }
2290 spin_unlock(&pr_tmpl->registration_lock); 2296 spin_unlock(&pr_tmpl->registration_lock);
2291 2297
2292 if (!(aptpl)) { 2298 if (!aptpl) {
2293 pr_tmpl->pr_aptpl_active = 0; 2299 pr_tmpl->pr_aptpl_active = 0;
2294 core_scsi3_update_and_write_aptpl(dev, NULL, 0); 2300 core_scsi3_update_and_write_aptpl(dev, NULL, 0);
2295 printk("SPC-3 PR: Set APTPL Bit Deactivated" 2301 pr_debug("SPC-3 PR: Set APTPL Bit Deactivated"
2296 " for UNREGISTER\n"); 2302 " for UNREGISTER\n");
2297 return 0; 2303 return 0;
2298 } 2304 }
@@ -2300,9 +2306,9 @@ static int core_scsi3_emulate_pro_register(
2300 ret = core_scsi3_update_and_write_aptpl(dev, 2306 ret = core_scsi3_update_and_write_aptpl(dev,
2301 &pr_aptpl_buf[0], 2307 &pr_aptpl_buf[0],
2302 pr_tmpl->pr_aptpl_buf_len); 2308 pr_tmpl->pr_aptpl_buf_len);
2303 if (!(ret)) { 2309 if (!ret) {
2304 pr_tmpl->pr_aptpl_active = 1; 2310 pr_tmpl->pr_aptpl_active = 1;
2305 printk("SPC-3 PR: Set APTPL Bit Activated" 2311 pr_debug("SPC-3 PR: Set APTPL Bit Activated"
2306 " for UNREGISTER\n"); 2312 " for UNREGISTER\n");
2307 } 2313 }
2308 2314
@@ -2315,20 +2321,20 @@ static int core_scsi3_emulate_pro_register(
2315 * READ_KEYS service action. 2321 * READ_KEYS service action.
2316 */ 2322 */
2317 pr_reg->pr_res_generation = core_scsi3_pr_generation( 2323 pr_reg->pr_res_generation = core_scsi3_pr_generation(
2318 SE_DEV(cmd)); 2324 cmd->se_dev);
2319 pr_reg->pr_res_key = sa_res_key; 2325 pr_reg->pr_res_key = sa_res_key;
2320 printk("SPC-3 PR [%s] REGISTER%s: Changed Reservation" 2326 pr_debug("SPC-3 PR [%s] REGISTER%s: Changed Reservation"
2321 " Key for %s to: 0x%016Lx PRgeneration:" 2327 " Key for %s to: 0x%016Lx PRgeneration:"
2322 " 0x%08x\n", CMD_TFO(cmd)->get_fabric_name(), 2328 " 0x%08x\n", cmd->se_tfo->get_fabric_name(),
2323 (ignore_key) ? "_AND_IGNORE_EXISTING_KEY" : "", 2329 (ignore_key) ? "_AND_IGNORE_EXISTING_KEY" : "",
2324 pr_reg->pr_reg_nacl->initiatorname, 2330 pr_reg->pr_reg_nacl->initiatorname,
2325 pr_reg->pr_res_key, pr_reg->pr_res_generation); 2331 pr_reg->pr_res_key, pr_reg->pr_res_generation);
2326 2332
2327 if (!(aptpl)) { 2333 if (!aptpl) {
2328 pr_tmpl->pr_aptpl_active = 0; 2334 pr_tmpl->pr_aptpl_active = 0;
2329 core_scsi3_update_and_write_aptpl(dev, NULL, 0); 2335 core_scsi3_update_and_write_aptpl(dev, NULL, 0);
2330 core_scsi3_put_pr_reg(pr_reg); 2336 core_scsi3_put_pr_reg(pr_reg);
2331 printk("SPC-3 PR: Set APTPL Bit Deactivated" 2337 pr_debug("SPC-3 PR: Set APTPL Bit Deactivated"
2332 " for REGISTER\n"); 2338 " for REGISTER\n");
2333 return 0; 2339 return 0;
2334 } 2340 }
@@ -2336,9 +2342,9 @@ static int core_scsi3_emulate_pro_register(
2336 ret = core_scsi3_update_and_write_aptpl(dev, 2342 ret = core_scsi3_update_and_write_aptpl(dev,
2337 &pr_aptpl_buf[0], 2343 &pr_aptpl_buf[0],
2338 pr_tmpl->pr_aptpl_buf_len); 2344 pr_tmpl->pr_aptpl_buf_len);
2339 if (!(ret)) { 2345 if (!ret) {
2340 pr_tmpl->pr_aptpl_active = 1; 2346 pr_tmpl->pr_aptpl_active = 1;
2341 printk("SPC-3 PR: Set APTPL Bit Activated" 2347 pr_debug("SPC-3 PR: Set APTPL Bit Activated"
2342 " for REGISTER\n"); 2348 " for REGISTER\n");
2343 } 2349 }
2344 2350
@@ -2378,19 +2384,19 @@ static int core_scsi3_pro_reserve(
2378 int scope, 2384 int scope,
2379 u64 res_key) 2385 u64 res_key)
2380{ 2386{
2381 struct se_session *se_sess = SE_SESS(cmd); 2387 struct se_session *se_sess = cmd->se_sess;
2382 struct se_dev_entry *se_deve; 2388 struct se_dev_entry *se_deve;
2383 struct se_lun *se_lun = SE_LUN(cmd); 2389 struct se_lun *se_lun = cmd->se_lun;
2384 struct se_portal_group *se_tpg; 2390 struct se_portal_group *se_tpg;
2385 struct t10_pr_registration *pr_reg, *pr_res_holder; 2391 struct t10_pr_registration *pr_reg, *pr_res_holder;
2386 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 2392 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
2387 char i_buf[PR_REG_ISID_ID_LEN]; 2393 char i_buf[PR_REG_ISID_ID_LEN];
2388 int ret, prf_isid; 2394 int ret, prf_isid;
2389 2395
2390 memset(i_buf, 0, PR_REG_ISID_ID_LEN); 2396 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
2391 2397
2392 if (!(se_sess) || !(se_lun)) { 2398 if (!se_sess || !se_lun) {
2393 printk(KERN_ERR "SPC-3 PR: se_sess || struct se_lun is NULL!\n"); 2399 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n");
2394 return PYX_TRANSPORT_LU_COMM_FAILURE; 2400 return PYX_TRANSPORT_LU_COMM_FAILURE;
2395 } 2401 }
2396 se_tpg = se_sess->se_tpg; 2402 se_tpg = se_sess->se_tpg;
@@ -2398,10 +2404,10 @@ static int core_scsi3_pro_reserve(
2398 /* 2404 /*
2399 * Locate the existing *pr_reg via struct se_node_acl pointers 2405 * Locate the existing *pr_reg via struct se_node_acl pointers
2400 */ 2406 */
2401 pr_reg = core_scsi3_locate_pr_reg(SE_DEV(cmd), se_sess->se_node_acl, 2407 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
2402 se_sess); 2408 se_sess);
2403 if (!(pr_reg)) { 2409 if (!pr_reg) {
2404 printk(KERN_ERR "SPC-3 PR: Unable to locate" 2410 pr_err("SPC-3 PR: Unable to locate"
2405 " PR_REGISTERED *pr_reg for RESERVE\n"); 2411 " PR_REGISTERED *pr_reg for RESERVE\n");
2406 return PYX_TRANSPORT_LU_COMM_FAILURE; 2412 return PYX_TRANSPORT_LU_COMM_FAILURE;
2407 } 2413 }
@@ -2415,7 +2421,7 @@ static int core_scsi3_pro_reserve(
2415 * registered with the logical unit for the I_T nexus; and 2421 * registered with the logical unit for the I_T nexus; and
2416 */ 2422 */
2417 if (res_key != pr_reg->pr_res_key) { 2423 if (res_key != pr_reg->pr_res_key) {
2418 printk(KERN_ERR "SPC-3 PR RESERVE: Received res_key: 0x%016Lx" 2424 pr_err("SPC-3 PR RESERVE: Received res_key: 0x%016Lx"
2419 " does not match existing SA REGISTER res_key:" 2425 " does not match existing SA REGISTER res_key:"
2420 " 0x%016Lx\n", res_key, pr_reg->pr_res_key); 2426 " 0x%016Lx\n", res_key, pr_reg->pr_res_key);
2421 core_scsi3_put_pr_reg(pr_reg); 2427 core_scsi3_put_pr_reg(pr_reg);
@@ -2432,7 +2438,7 @@ static int core_scsi3_pro_reserve(
2432 * and that persistent reservation has a scope of LU_SCOPE. 2438 * and that persistent reservation has a scope of LU_SCOPE.
2433 */ 2439 */
2434 if (scope != PR_SCOPE_LU_SCOPE) { 2440 if (scope != PR_SCOPE_LU_SCOPE) {
2435 printk(KERN_ERR "SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope); 2441 pr_err("SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope);
2436 core_scsi3_put_pr_reg(pr_reg); 2442 core_scsi3_put_pr_reg(pr_reg);
2437 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 2443 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
2438 } 2444 }
@@ -2456,12 +2462,12 @@ static int core_scsi3_pro_reserve(
2456 */ 2462 */
2457 if (pr_res_holder != pr_reg) { 2463 if (pr_res_holder != pr_reg) {
2458 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; 2464 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl;
2459 printk(KERN_ERR "SPC-3 PR: Attempted RESERVE from" 2465 pr_err("SPC-3 PR: Attempted RESERVE from"
2460 " [%s]: %s while reservation already held by" 2466 " [%s]: %s while reservation already held by"
2461 " [%s]: %s, returning RESERVATION_CONFLICT\n", 2467 " [%s]: %s, returning RESERVATION_CONFLICT\n",
2462 CMD_TFO(cmd)->get_fabric_name(), 2468 cmd->se_tfo->get_fabric_name(),
2463 se_sess->se_node_acl->initiatorname, 2469 se_sess->se_node_acl->initiatorname,
2464 TPG_TFO(pr_res_nacl->se_tpg)->get_fabric_name(), 2470 pr_res_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
2465 pr_res_holder->pr_reg_nacl->initiatorname); 2471 pr_res_holder->pr_reg_nacl->initiatorname);
2466 2472
2467 spin_unlock(&dev->dev_reservation_lock); 2473 spin_unlock(&dev->dev_reservation_lock);
@@ -2478,13 +2484,13 @@ static int core_scsi3_pro_reserve(
2478 if ((pr_res_holder->pr_res_type != type) || 2484 if ((pr_res_holder->pr_res_type != type) ||
2479 (pr_res_holder->pr_res_scope != scope)) { 2485 (pr_res_holder->pr_res_scope != scope)) {
2480 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; 2486 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl;
2481 printk(KERN_ERR "SPC-3 PR: Attempted RESERVE from" 2487 pr_err("SPC-3 PR: Attempted RESERVE from"
2482 " [%s]: %s trying to change TYPE and/or SCOPE," 2488 " [%s]: %s trying to change TYPE and/or SCOPE,"
2483 " while reservation already held by [%s]: %s," 2489 " while reservation already held by [%s]: %s,"
2484 " returning RESERVATION_CONFLICT\n", 2490 " returning RESERVATION_CONFLICT\n",
2485 CMD_TFO(cmd)->get_fabric_name(), 2491 cmd->se_tfo->get_fabric_name(),
2486 se_sess->se_node_acl->initiatorname, 2492 se_sess->se_node_acl->initiatorname,
2487 TPG_TFO(pr_res_nacl->se_tpg)->get_fabric_name(), 2493 pr_res_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
2488 pr_res_holder->pr_reg_nacl->initiatorname); 2494 pr_res_holder->pr_reg_nacl->initiatorname);
2489 2495
2490 spin_unlock(&dev->dev_reservation_lock); 2496 spin_unlock(&dev->dev_reservation_lock);
@@ -2516,22 +2522,22 @@ static int core_scsi3_pro_reserve(
2516 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0], 2522 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0],
2517 PR_REG_ISID_ID_LEN); 2523 PR_REG_ISID_ID_LEN);
2518 2524
2519 printk(KERN_INFO "SPC-3 PR [%s] Service Action: RESERVE created new" 2525 pr_debug("SPC-3 PR [%s] Service Action: RESERVE created new"
2520 " reservation holder TYPE: %s ALL_TG_PT: %d\n", 2526 " reservation holder TYPE: %s ALL_TG_PT: %d\n",
2521 CMD_TFO(cmd)->get_fabric_name(), core_scsi3_pr_dump_type(type), 2527 cmd->se_tfo->get_fabric_name(), core_scsi3_pr_dump_type(type),
2522 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 2528 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0);
2523 printk(KERN_INFO "SPC-3 PR [%s] RESERVE Node: %s%s\n", 2529 pr_debug("SPC-3 PR [%s] RESERVE Node: %s%s\n",
2524 CMD_TFO(cmd)->get_fabric_name(), 2530 cmd->se_tfo->get_fabric_name(),
2525 se_sess->se_node_acl->initiatorname, 2531 se_sess->se_node_acl->initiatorname,
2526 (prf_isid) ? &i_buf[0] : ""); 2532 (prf_isid) ? &i_buf[0] : "");
2527 spin_unlock(&dev->dev_reservation_lock); 2533 spin_unlock(&dev->dev_reservation_lock);
2528 2534
2529 if (pr_tmpl->pr_aptpl_active) { 2535 if (pr_tmpl->pr_aptpl_active) {
2530 ret = core_scsi3_update_and_write_aptpl(SE_DEV(cmd), 2536 ret = core_scsi3_update_and_write_aptpl(cmd->se_dev,
2531 &pr_reg->pr_aptpl_buf[0], 2537 &pr_reg->pr_aptpl_buf[0],
2532 pr_tmpl->pr_aptpl_buf_len); 2538 pr_tmpl->pr_aptpl_buf_len);
2533 if (!(ret)) 2539 if (!ret)
2534 printk(KERN_INFO "SPC-3 PR: Updated APTPL metadata" 2540 pr_debug("SPC-3 PR: Updated APTPL metadata"
2535 " for RESERVE\n"); 2541 " for RESERVE\n");
2536 } 2542 }
2537 2543
@@ -2558,7 +2564,7 @@ static int core_scsi3_emulate_pro_reserve(
2558 ret = core_scsi3_pro_reserve(cmd, dev, type, scope, res_key); 2564 ret = core_scsi3_pro_reserve(cmd, dev, type, scope, res_key);
2559 break; 2565 break;
2560 default: 2566 default:
2561 printk(KERN_ERR "SPC-3 PR: Unknown Service Action RESERVE Type:" 2567 pr_err("SPC-3 PR: Unknown Service Action RESERVE Type:"
2562 " 0x%02x\n", type); 2568 " 0x%02x\n", type);
2563 return PYX_TRANSPORT_INVALID_CDB_FIELD; 2569 return PYX_TRANSPORT_INVALID_CDB_FIELD;
2564 } 2570 }
@@ -2587,12 +2593,12 @@ static void __core_scsi3_complete_pro_release(
2587 */ 2593 */
2588 dev->dev_pr_res_holder = NULL; 2594 dev->dev_pr_res_holder = NULL;
2589 2595
2590 printk(KERN_INFO "SPC-3 PR [%s] Service Action: %s RELEASE cleared" 2596 pr_debug("SPC-3 PR [%s] Service Action: %s RELEASE cleared"
2591 " reservation holder TYPE: %s ALL_TG_PT: %d\n", 2597 " reservation holder TYPE: %s ALL_TG_PT: %d\n",
2592 tfo->get_fabric_name(), (explict) ? "explict" : "implict", 2598 tfo->get_fabric_name(), (explict) ? "explict" : "implict",
2593 core_scsi3_pr_dump_type(pr_reg->pr_res_type), 2599 core_scsi3_pr_dump_type(pr_reg->pr_res_type),
2594 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 2600 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0);
2595 printk(KERN_INFO "SPC-3 PR [%s] RELEASE Node: %s%s\n", 2601 pr_debug("SPC-3 PR [%s] RELEASE Node: %s%s\n",
2596 tfo->get_fabric_name(), se_nacl->initiatorname, 2602 tfo->get_fabric_name(), se_nacl->initiatorname,
2597 (prf_isid) ? &i_buf[0] : ""); 2603 (prf_isid) ? &i_buf[0] : "");
2598 /* 2604 /*
@@ -2608,22 +2614,22 @@ static int core_scsi3_emulate_pro_release(
2608 u64 res_key) 2614 u64 res_key)
2609{ 2615{
2610 struct se_device *dev = cmd->se_dev; 2616 struct se_device *dev = cmd->se_dev;
2611 struct se_session *se_sess = SE_SESS(cmd); 2617 struct se_session *se_sess = cmd->se_sess;
2612 struct se_lun *se_lun = SE_LUN(cmd); 2618 struct se_lun *se_lun = cmd->se_lun;
2613 struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_res_holder; 2619 struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_res_holder;
2614 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 2620 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
2615 int ret, all_reg = 0; 2621 int ret, all_reg = 0;
2616 2622
2617 if (!(se_sess) || !(se_lun)) { 2623 if (!se_sess || !se_lun) {
2618 printk(KERN_ERR "SPC-3 PR: se_sess || struct se_lun is NULL!\n"); 2624 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n");
2619 return PYX_TRANSPORT_LU_COMM_FAILURE; 2625 return PYX_TRANSPORT_LU_COMM_FAILURE;
2620 } 2626 }
2621 /* 2627 /*
2622 * Locate the existing *pr_reg via struct se_node_acl pointers 2628 * Locate the existing *pr_reg via struct se_node_acl pointers
2623 */ 2629 */
2624 pr_reg = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess); 2630 pr_reg = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess);
2625 if (!(pr_reg)) { 2631 if (!pr_reg) {
2626 printk(KERN_ERR "SPC-3 PR: Unable to locate" 2632 pr_err("SPC-3 PR: Unable to locate"
2627 " PR_REGISTERED *pr_reg for RELEASE\n"); 2633 " PR_REGISTERED *pr_reg for RELEASE\n");
2628 return PYX_TRANSPORT_LU_COMM_FAILURE; 2634 return PYX_TRANSPORT_LU_COMM_FAILURE;
2629 } 2635 }
@@ -2641,7 +2647,7 @@ static int core_scsi3_emulate_pro_release(
2641 */ 2647 */
2642 spin_lock(&dev->dev_reservation_lock); 2648 spin_lock(&dev->dev_reservation_lock);
2643 pr_res_holder = dev->dev_pr_res_holder; 2649 pr_res_holder = dev->dev_pr_res_holder;
2644 if (!(pr_res_holder)) { 2650 if (!pr_res_holder) {
2645 /* 2651 /*
2646 * No persistent reservation, return GOOD status. 2652 * No persistent reservation, return GOOD status.
2647 */ 2653 */
@@ -2678,7 +2684,7 @@ static int core_scsi3_emulate_pro_release(
2678 * that is registered with the logical unit for the I_T nexus; 2684 * that is registered with the logical unit for the I_T nexus;
2679 */ 2685 */
2680 if (res_key != pr_reg->pr_res_key) { 2686 if (res_key != pr_reg->pr_res_key) {
2681 printk(KERN_ERR "SPC-3 PR RELEASE: Received res_key: 0x%016Lx" 2687 pr_err("SPC-3 PR RELEASE: Received res_key: 0x%016Lx"
2682 " does not match existing SA REGISTER res_key:" 2688 " does not match existing SA REGISTER res_key:"
2683 " 0x%016Lx\n", res_key, pr_reg->pr_res_key); 2689 " 0x%016Lx\n", res_key, pr_reg->pr_res_key);
2684 spin_unlock(&dev->dev_reservation_lock); 2690 spin_unlock(&dev->dev_reservation_lock);
@@ -2694,13 +2700,13 @@ static int core_scsi3_emulate_pro_release(
2694 if ((pr_res_holder->pr_res_type != type) || 2700 if ((pr_res_holder->pr_res_type != type) ||
2695 (pr_res_holder->pr_res_scope != scope)) { 2701 (pr_res_holder->pr_res_scope != scope)) {
2696 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; 2702 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl;
2697 printk(KERN_ERR "SPC-3 PR RELEASE: Attempted to release" 2703 pr_err("SPC-3 PR RELEASE: Attempted to release"
2698 " reservation from [%s]: %s with different TYPE " 2704 " reservation from [%s]: %s with different TYPE "
2699 "and/or SCOPE while reservation already held by" 2705 "and/or SCOPE while reservation already held by"
2700 " [%s]: %s, returning RESERVATION_CONFLICT\n", 2706 " [%s]: %s, returning RESERVATION_CONFLICT\n",
2701 CMD_TFO(cmd)->get_fabric_name(), 2707 cmd->se_tfo->get_fabric_name(),
2702 se_sess->se_node_acl->initiatorname, 2708 se_sess->se_node_acl->initiatorname,
2703 TPG_TFO(pr_res_nacl->se_tpg)->get_fabric_name(), 2709 pr_res_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
2704 pr_res_holder->pr_reg_nacl->initiatorname); 2710 pr_res_holder->pr_reg_nacl->initiatorname);
2705 2711
2706 spin_unlock(&dev->dev_reservation_lock); 2712 spin_unlock(&dev->dev_reservation_lock);
@@ -2758,11 +2764,11 @@ static int core_scsi3_emulate_pro_release(
2758 2764
2759write_aptpl: 2765write_aptpl:
2760 if (pr_tmpl->pr_aptpl_active) { 2766 if (pr_tmpl->pr_aptpl_active) {
2761 ret = core_scsi3_update_and_write_aptpl(SE_DEV(cmd), 2767 ret = core_scsi3_update_and_write_aptpl(cmd->se_dev,
2762 &pr_reg->pr_aptpl_buf[0], 2768 &pr_reg->pr_aptpl_buf[0],
2763 pr_tmpl->pr_aptpl_buf_len); 2769 pr_tmpl->pr_aptpl_buf_len);
2764 if (!(ret)) 2770 if (!ret)
2765 printk("SPC-3 PR: Updated APTPL metadata for RELEASE\n"); 2771 pr_debug("SPC-3 PR: Updated APTPL metadata for RELEASE\n");
2766 } 2772 }
2767 2773
2768 core_scsi3_put_pr_reg(pr_reg); 2774 core_scsi3_put_pr_reg(pr_reg);
@@ -2775,18 +2781,18 @@ static int core_scsi3_emulate_pro_clear(
2775{ 2781{
2776 struct se_device *dev = cmd->se_dev; 2782 struct se_device *dev = cmd->se_dev;
2777 struct se_node_acl *pr_reg_nacl; 2783 struct se_node_acl *pr_reg_nacl;
2778 struct se_session *se_sess = SE_SESS(cmd); 2784 struct se_session *se_sess = cmd->se_sess;
2779 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 2785 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
2780 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder; 2786 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder;
2781 u32 pr_res_mapped_lun = 0; 2787 u32 pr_res_mapped_lun = 0;
2782 int calling_it_nexus = 0; 2788 int calling_it_nexus = 0;
2783 /* 2789 /*
2784 * Locate the existing *pr_reg via struct se_node_acl pointers 2790 * Locate the existing *pr_reg via struct se_node_acl pointers
2785 */ 2791 */
2786 pr_reg_n = core_scsi3_locate_pr_reg(SE_DEV(cmd), 2792 pr_reg_n = core_scsi3_locate_pr_reg(cmd->se_dev,
2787 se_sess->se_node_acl, se_sess); 2793 se_sess->se_node_acl, se_sess);
2788 if (!(pr_reg_n)) { 2794 if (!pr_reg_n) {
2789 printk(KERN_ERR "SPC-3 PR: Unable to locate" 2795 pr_err("SPC-3 PR: Unable to locate"
2790 " PR_REGISTERED *pr_reg for CLEAR\n"); 2796 " PR_REGISTERED *pr_reg for CLEAR\n");
2791 return PYX_TRANSPORT_LU_COMM_FAILURE; 2797 return PYX_TRANSPORT_LU_COMM_FAILURE;
2792 } 2798 }
@@ -2802,7 +2808,7 @@ static int core_scsi3_emulate_pro_clear(
2802 * that is registered with the logical unit for the I_T nexus. 2808 * that is registered with the logical unit for the I_T nexus.
2803 */ 2809 */
2804 if (res_key != pr_reg_n->pr_res_key) { 2810 if (res_key != pr_reg_n->pr_res_key) {
2805 printk(KERN_ERR "SPC-3 PR REGISTER: Received" 2811 pr_err("SPC-3 PR REGISTER: Received"
2806 " res_key: 0x%016Lx does not match" 2812 " res_key: 0x%016Lx does not match"
2807 " existing SA REGISTER res_key:" 2813 " existing SA REGISTER res_key:"
2808 " 0x%016Lx\n", res_key, pr_reg_n->pr_res_key); 2814 " 0x%016Lx\n", res_key, pr_reg_n->pr_res_key);
@@ -2839,18 +2845,18 @@ static int core_scsi3_emulate_pro_clear(
2839 * command with CLEAR service action was received, with the 2845 * command with CLEAR service action was received, with the
2840 * additional sense code set to RESERVATIONS PREEMPTED. 2846 * additional sense code set to RESERVATIONS PREEMPTED.
2841 */ 2847 */
2842 if (!(calling_it_nexus)) 2848 if (!calling_it_nexus)
2843 core_scsi3_ua_allocate(pr_reg_nacl, pr_res_mapped_lun, 2849 core_scsi3_ua_allocate(pr_reg_nacl, pr_res_mapped_lun,
2844 0x2A, ASCQ_2AH_RESERVATIONS_PREEMPTED); 2850 0x2A, ASCQ_2AH_RESERVATIONS_PREEMPTED);
2845 } 2851 }
2846 spin_unlock(&pr_tmpl->registration_lock); 2852 spin_unlock(&pr_tmpl->registration_lock);
2847 2853
2848 printk(KERN_INFO "SPC-3 PR [%s] Service Action: CLEAR complete\n", 2854 pr_debug("SPC-3 PR [%s] Service Action: CLEAR complete\n",
2849 CMD_TFO(cmd)->get_fabric_name()); 2855 cmd->se_tfo->get_fabric_name());
2850 2856
2851 if (pr_tmpl->pr_aptpl_active) { 2857 if (pr_tmpl->pr_aptpl_active) {
2852 core_scsi3_update_and_write_aptpl(SE_DEV(cmd), NULL, 0); 2858 core_scsi3_update_and_write_aptpl(cmd->se_dev, NULL, 0);
2853 printk(KERN_INFO "SPC-3 PR: Updated APTPL metadata" 2859 pr_debug("SPC-3 PR: Updated APTPL metadata"
2854 " for CLEAR\n"); 2860 " for CLEAR\n");
2855 } 2861 }
2856 2862
@@ -2889,12 +2895,12 @@ static void __core_scsi3_complete_pro_preempt(
2889 pr_reg->pr_res_type = type; 2895 pr_reg->pr_res_type = type;
2890 pr_reg->pr_res_scope = scope; 2896 pr_reg->pr_res_scope = scope;
2891 2897
2892 printk(KERN_INFO "SPC-3 PR [%s] Service Action: PREEMPT%s created new" 2898 pr_debug("SPC-3 PR [%s] Service Action: PREEMPT%s created new"
2893 " reservation holder TYPE: %s ALL_TG_PT: %d\n", 2899 " reservation holder TYPE: %s ALL_TG_PT: %d\n",
2894 tfo->get_fabric_name(), (abort) ? "_AND_ABORT" : "", 2900 tfo->get_fabric_name(), (abort) ? "_AND_ABORT" : "",
2895 core_scsi3_pr_dump_type(type), 2901 core_scsi3_pr_dump_type(type),
2896 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); 2902 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0);
2897 printk(KERN_INFO "SPC-3 PR [%s] PREEMPT%s from Node: %s%s\n", 2903 pr_debug("SPC-3 PR [%s] PREEMPT%s from Node: %s%s\n",
2898 tfo->get_fabric_name(), (abort) ? "_AND_ABORT" : "", 2904 tfo->get_fabric_name(), (abort) ? "_AND_ABORT" : "",
2899 nacl->initiatorname, (prf_isid) ? &i_buf[0] : ""); 2905 nacl->initiatorname, (prf_isid) ? &i_buf[0] : "");
2900 /* 2906 /*
@@ -2920,7 +2926,7 @@ static void core_scsi3_release_preempt_and_abort(
2920 if (pr_reg_holder == pr_reg) 2926 if (pr_reg_holder == pr_reg)
2921 continue; 2927 continue;
2922 if (pr_reg->pr_res_holder) { 2928 if (pr_reg->pr_res_holder) {
2923 printk(KERN_WARNING "pr_reg->pr_res_holder still set\n"); 2929 pr_warn("pr_reg->pr_res_holder still set\n");
2924 continue; 2930 continue;
2925 } 2931 }
2926 2932
@@ -2954,25 +2960,25 @@ static int core_scsi3_pro_preempt(
2954 u64 sa_res_key, 2960 u64 sa_res_key,
2955 int abort) 2961 int abort)
2956{ 2962{
2957 struct se_device *dev = SE_DEV(cmd); 2963 struct se_device *dev = cmd->se_dev;
2958 struct se_dev_entry *se_deve; 2964 struct se_dev_entry *se_deve;
2959 struct se_node_acl *pr_reg_nacl; 2965 struct se_node_acl *pr_reg_nacl;
2960 struct se_session *se_sess = SE_SESS(cmd); 2966 struct se_session *se_sess = cmd->se_sess;
2961 struct list_head preempt_and_abort_list; 2967 struct list_head preempt_and_abort_list;
2962 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder; 2968 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder;
2963 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 2969 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
2964 u32 pr_res_mapped_lun = 0; 2970 u32 pr_res_mapped_lun = 0;
2965 int all_reg = 0, calling_it_nexus = 0, released_regs = 0; 2971 int all_reg = 0, calling_it_nexus = 0, released_regs = 0;
2966 int prh_type = 0, prh_scope = 0, ret; 2972 int prh_type = 0, prh_scope = 0, ret;
2967 2973
2968 if (!(se_sess)) 2974 if (!se_sess)
2969 return PYX_TRANSPORT_LU_COMM_FAILURE; 2975 return PYX_TRANSPORT_LU_COMM_FAILURE;
2970 2976
2971 se_deve = &se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 2977 se_deve = &se_sess->se_node_acl->device_list[cmd->orig_fe_lun];
2972 pr_reg_n = core_scsi3_locate_pr_reg(SE_DEV(cmd), se_sess->se_node_acl, 2978 pr_reg_n = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
2973 se_sess); 2979 se_sess);
2974 if (!(pr_reg_n)) { 2980 if (!pr_reg_n) {
2975 printk(KERN_ERR "SPC-3 PR: Unable to locate" 2981 pr_err("SPC-3 PR: Unable to locate"
2976 " PR_REGISTERED *pr_reg for PREEMPT%s\n", 2982 " PR_REGISTERED *pr_reg for PREEMPT%s\n",
2977 (abort) ? "_AND_ABORT" : ""); 2983 (abort) ? "_AND_ABORT" : "");
2978 return PYX_TRANSPORT_RESERVATION_CONFLICT; 2984 return PYX_TRANSPORT_RESERVATION_CONFLICT;
@@ -2982,7 +2988,7 @@ static int core_scsi3_pro_preempt(
2982 return PYX_TRANSPORT_RESERVATION_CONFLICT; 2988 return PYX_TRANSPORT_RESERVATION_CONFLICT;
2983 } 2989 }
2984 if (scope != PR_SCOPE_LU_SCOPE) { 2990 if (scope != PR_SCOPE_LU_SCOPE) {
2985 printk(KERN_ERR "SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope); 2991 pr_err("SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope);
2986 core_scsi3_put_pr_reg(pr_reg_n); 2992 core_scsi3_put_pr_reg(pr_reg_n);
2987 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 2993 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
2988 } 2994 }
@@ -2995,7 +3001,7 @@ static int core_scsi3_pro_preempt(
2995 (pr_res_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG))) 3001 (pr_res_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)))
2996 all_reg = 1; 3002 all_reg = 1;
2997 3003
2998 if (!(all_reg) && !(sa_res_key)) { 3004 if (!all_reg && !sa_res_key) {
2999 spin_unlock(&dev->dev_reservation_lock); 3005 spin_unlock(&dev->dev_reservation_lock);
3000 core_scsi3_put_pr_reg(pr_reg_n); 3006 core_scsi3_put_pr_reg(pr_reg_n);
3001 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3007 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
@@ -3009,7 +3015,7 @@ static int core_scsi3_pro_preempt(
3009 * server shall perform a preempt by doing the following in an 3015 * server shall perform a preempt by doing the following in an
3010 * uninterrupted series of actions. (See below..) 3016 * uninterrupted series of actions. (See below..)
3011 */ 3017 */
3012 if (!(pr_res_holder) || (pr_res_holder->pr_res_key != sa_res_key)) { 3018 if (!pr_res_holder || (pr_res_holder->pr_res_key != sa_res_key)) {
3013 /* 3019 /*
3014 * No existing or SA Reservation Key matching reservations.. 3020 * No existing or SA Reservation Key matching reservations..
3015 * 3021 *
@@ -3036,7 +3042,7 @@ static int core_scsi3_pro_preempt(
3036 * was received, with the additional sense code set 3042 * was received, with the additional sense code set
3037 * to REGISTRATIONS PREEMPTED. 3043 * to REGISTRATIONS PREEMPTED.
3038 */ 3044 */
3039 if (!(all_reg)) { 3045 if (!all_reg) {
3040 if (pr_reg->pr_res_key != sa_res_key) 3046 if (pr_reg->pr_res_key != sa_res_key)
3041 continue; 3047 continue;
3042 3048
@@ -3076,7 +3082,7 @@ static int core_scsi3_pro_preempt(
3076 NULL, 0); 3082 NULL, 0);
3077 released_regs++; 3083 released_regs++;
3078 } 3084 }
3079 if (!(calling_it_nexus)) 3085 if (!calling_it_nexus)
3080 core_scsi3_ua_allocate(pr_reg_nacl, 3086 core_scsi3_ua_allocate(pr_reg_nacl,
3081 pr_res_mapped_lun, 0x2A, 3087 pr_res_mapped_lun, 0x2A,
3082 ASCQ_2AH_RESERVATIONS_PREEMPTED); 3088 ASCQ_2AH_RESERVATIONS_PREEMPTED);
@@ -3089,7 +3095,7 @@ static int core_scsi3_pro_preempt(
3089 * registered reservation key, then the device server shall 3095 * registered reservation key, then the device server shall
3090 * complete the command with RESERVATION CONFLICT status. 3096 * complete the command with RESERVATION CONFLICT status.
3091 */ 3097 */
3092 if (!(released_regs)) { 3098 if (!released_regs) {
3093 spin_unlock(&dev->dev_reservation_lock); 3099 spin_unlock(&dev->dev_reservation_lock);
3094 core_scsi3_put_pr_reg(pr_reg_n); 3100 core_scsi3_put_pr_reg(pr_reg_n);
3095 return PYX_TRANSPORT_RESERVATION_CONFLICT; 3101 return PYX_TRANSPORT_RESERVATION_CONFLICT;
@@ -3111,17 +3117,17 @@ static int core_scsi3_pro_preempt(
3111 spin_unlock(&dev->dev_reservation_lock); 3117 spin_unlock(&dev->dev_reservation_lock);
3112 3118
3113 if (pr_tmpl->pr_aptpl_active) { 3119 if (pr_tmpl->pr_aptpl_active) {
3114 ret = core_scsi3_update_and_write_aptpl(SE_DEV(cmd), 3120 ret = core_scsi3_update_and_write_aptpl(cmd->se_dev,
3115 &pr_reg_n->pr_aptpl_buf[0], 3121 &pr_reg_n->pr_aptpl_buf[0],
3116 pr_tmpl->pr_aptpl_buf_len); 3122 pr_tmpl->pr_aptpl_buf_len);
3117 if (!(ret)) 3123 if (!ret)
3118 printk(KERN_INFO "SPC-3 PR: Updated APTPL" 3124 pr_debug("SPC-3 PR: Updated APTPL"
3119 " metadata for PREEMPT%s\n", (abort) ? 3125 " metadata for PREEMPT%s\n", (abort) ?
3120 "_AND_ABORT" : ""); 3126 "_AND_ABORT" : "");
3121 } 3127 }
3122 3128
3123 core_scsi3_put_pr_reg(pr_reg_n); 3129 core_scsi3_put_pr_reg(pr_reg_n);
3124 core_scsi3_pr_generation(SE_DEV(cmd)); 3130 core_scsi3_pr_generation(cmd->se_dev);
3125 return 0; 3131 return 0;
3126 } 3132 }
3127 /* 3133 /*
@@ -3247,16 +3253,16 @@ static int core_scsi3_pro_preempt(
3247 } 3253 }
3248 3254
3249 if (pr_tmpl->pr_aptpl_active) { 3255 if (pr_tmpl->pr_aptpl_active) {
3250 ret = core_scsi3_update_and_write_aptpl(SE_DEV(cmd), 3256 ret = core_scsi3_update_and_write_aptpl(cmd->se_dev,
3251 &pr_reg_n->pr_aptpl_buf[0], 3257 &pr_reg_n->pr_aptpl_buf[0],
3252 pr_tmpl->pr_aptpl_buf_len); 3258 pr_tmpl->pr_aptpl_buf_len);
3253 if (!(ret)) 3259 if (!ret)
3254 printk("SPC-3 PR: Updated APTPL metadata for PREEMPT" 3260 pr_debug("SPC-3 PR: Updated APTPL metadata for PREEMPT"
3255 "%s\n", (abort) ? "_AND_ABORT" : ""); 3261 "%s\n", (abort) ? "_AND_ABORT" : "");
3256 } 3262 }
3257 3263
3258 core_scsi3_put_pr_reg(pr_reg_n); 3264 core_scsi3_put_pr_reg(pr_reg_n);
3259 core_scsi3_pr_generation(SE_DEV(cmd)); 3265 core_scsi3_pr_generation(cmd->se_dev);
3260 return 0; 3266 return 0;
3261} 3267}
3262 3268
@@ -3281,7 +3287,7 @@ static int core_scsi3_emulate_pro_preempt(
3281 res_key, sa_res_key, abort); 3287 res_key, sa_res_key, abort);
3282 break; 3288 break;
3283 default: 3289 default:
3284 printk(KERN_ERR "SPC-3 PR: Unknown Service Action PREEMPT%s" 3290 pr_err("SPC-3 PR: Unknown Service Action PREEMPT%s"
3285 " Type: 0x%02x\n", (abort) ? "_AND_ABORT" : "", type); 3291 " Type: 0x%02x\n", (abort) ? "_AND_ABORT" : "", type);
3286 return PYX_TRANSPORT_INVALID_CDB_FIELD; 3292 return PYX_TRANSPORT_INVALID_CDB_FIELD;
3287 } 3293 }
@@ -3297,17 +3303,17 @@ static int core_scsi3_emulate_pro_register_and_move(
3297 int aptpl, 3303 int aptpl,
3298 int unreg) 3304 int unreg)
3299{ 3305{
3300 struct se_session *se_sess = SE_SESS(cmd); 3306 struct se_session *se_sess = cmd->se_sess;
3301 struct se_device *dev = SE_DEV(cmd); 3307 struct se_device *dev = cmd->se_dev;
3302 struct se_dev_entry *se_deve, *dest_se_deve = NULL; 3308 struct se_dev_entry *se_deve, *dest_se_deve = NULL;
3303 struct se_lun *se_lun = SE_LUN(cmd); 3309 struct se_lun *se_lun = cmd->se_lun;
3304 struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL; 3310 struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL;
3305 struct se_port *se_port; 3311 struct se_port *se_port;
3306 struct se_portal_group *se_tpg, *dest_se_tpg = NULL; 3312 struct se_portal_group *se_tpg, *dest_se_tpg = NULL;
3307 struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops; 3313 struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops;
3308 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg; 3314 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg;
3309 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 3315 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
3310 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 3316 unsigned char *buf;
3311 unsigned char *initiator_str; 3317 unsigned char *initiator_str;
3312 char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN]; 3318 char *iport_ptr = NULL, dest_iport[64], i_buf[PR_REG_ISID_ID_LEN];
3313 u32 tid_len, tmp_tid_len; 3319 u32 tid_len, tmp_tid_len;
@@ -3315,14 +3321,14 @@ static int core_scsi3_emulate_pro_register_and_move(
3315 unsigned short rtpi; 3321 unsigned short rtpi;
3316 unsigned char proto_ident; 3322 unsigned char proto_ident;
3317 3323
3318 if (!(se_sess) || !(se_lun)) { 3324 if (!se_sess || !se_lun) {
3319 printk(KERN_ERR "SPC-3 PR: se_sess || struct se_lun is NULL!\n"); 3325 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n");
3320 return PYX_TRANSPORT_LU_COMM_FAILURE; 3326 return PYX_TRANSPORT_LU_COMM_FAILURE;
3321 } 3327 }
3322 memset(dest_iport, 0, 64); 3328 memset(dest_iport, 0, 64);
3323 memset(i_buf, 0, PR_REG_ISID_ID_LEN); 3329 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
3324 se_tpg = se_sess->se_tpg; 3330 se_tpg = se_sess->se_tpg;
3325 tf_ops = TPG_TFO(se_tpg); 3331 tf_ops = se_tpg->se_tpg_tfo;
3326 se_deve = &se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 3332 se_deve = &se_sess->se_node_acl->device_list[cmd->orig_fe_lun];
3327 /* 3333 /*
3328 * Follow logic from spc4r17 Section 5.7.8, Table 50 -- 3334 * Follow logic from spc4r17 Section 5.7.8, Table 50 --
@@ -3330,10 +3336,10 @@ static int core_scsi3_emulate_pro_register_and_move(
3330 * 3336 *
3331 * Locate the existing *pr_reg via struct se_node_acl pointers 3337 * Locate the existing *pr_reg via struct se_node_acl pointers
3332 */ 3338 */
3333 pr_reg = core_scsi3_locate_pr_reg(SE_DEV(cmd), se_sess->se_node_acl, 3339 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl,
3334 se_sess); 3340 se_sess);
3335 if (!(pr_reg)) { 3341 if (!pr_reg) {
3336 printk(KERN_ERR "SPC-3 PR: Unable to locate PR_REGISTERED" 3342 pr_err("SPC-3 PR: Unable to locate PR_REGISTERED"
3337 " *pr_reg for REGISTER_AND_MOVE\n"); 3343 " *pr_reg for REGISTER_AND_MOVE\n");
3338 return PYX_TRANSPORT_LU_COMM_FAILURE; 3344 return PYX_TRANSPORT_LU_COMM_FAILURE;
3339 } 3345 }
@@ -3342,7 +3348,7 @@ static int core_scsi3_emulate_pro_register_and_move(
3342 * provided during this initiator's I_T nexus registration. 3348 * provided during this initiator's I_T nexus registration.
3343 */ 3349 */
3344 if (res_key != pr_reg->pr_res_key) { 3350 if (res_key != pr_reg->pr_res_key) {
3345 printk(KERN_WARNING "SPC-3 PR REGISTER_AND_MOVE: Received" 3351 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Received"
3346 " res_key: 0x%016Lx does not match existing SA REGISTER" 3352 " res_key: 0x%016Lx does not match existing SA REGISTER"
3347 " res_key: 0x%016Lx\n", res_key, pr_reg->pr_res_key); 3353 " res_key: 0x%016Lx\n", res_key, pr_reg->pr_res_key);
3348 core_scsi3_put_pr_reg(pr_reg); 3354 core_scsi3_put_pr_reg(pr_reg);
@@ -3351,26 +3357,30 @@ static int core_scsi3_emulate_pro_register_and_move(
3351 /* 3357 /*
3352 * The service active reservation key needs to be non zero 3358 * The service active reservation key needs to be non zero
3353 */ 3359 */
3354 if (!(sa_res_key)) { 3360 if (!sa_res_key) {
3355 printk(KERN_WARNING "SPC-3 PR REGISTER_AND_MOVE: Received zero" 3361 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Received zero"
3356 " sa_res_key\n"); 3362 " sa_res_key\n");
3357 core_scsi3_put_pr_reg(pr_reg); 3363 core_scsi3_put_pr_reg(pr_reg);
3358 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3364 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3359 } 3365 }
3366
3360 /* 3367 /*
3361 * Determine the Relative Target Port Identifier where the reservation 3368 * Determine the Relative Target Port Identifier where the reservation
3362 * will be moved to for the TransportID containing SCSI initiator WWN 3369 * will be moved to for the TransportID containing SCSI initiator WWN
3363 * information. 3370 * information.
3364 */ 3371 */
3372 buf = transport_kmap_first_data_page(cmd);
3365 rtpi = (buf[18] & 0xff) << 8; 3373 rtpi = (buf[18] & 0xff) << 8;
3366 rtpi |= buf[19] & 0xff; 3374 rtpi |= buf[19] & 0xff;
3367 tid_len = (buf[20] & 0xff) << 24; 3375 tid_len = (buf[20] & 0xff) << 24;
3368 tid_len |= (buf[21] & 0xff) << 16; 3376 tid_len |= (buf[21] & 0xff) << 16;
3369 tid_len |= (buf[22] & 0xff) << 8; 3377 tid_len |= (buf[22] & 0xff) << 8;
3370 tid_len |= buf[23] & 0xff; 3378 tid_len |= buf[23] & 0xff;
3379 transport_kunmap_first_data_page(cmd);
3380 buf = NULL;
3371 3381
3372 if ((tid_len + 24) != cmd->data_length) { 3382 if ((tid_len + 24) != cmd->data_length) {
3373 printk(KERN_ERR "SPC-3 PR: Illegal tid_len: %u + 24 byte header" 3383 pr_err("SPC-3 PR: Illegal tid_len: %u + 24 byte header"
3374 " does not equal CDB data_length: %u\n", tid_len, 3384 " does not equal CDB data_length: %u\n", tid_len,
3375 cmd->data_length); 3385 cmd->data_length);
3376 core_scsi3_put_pr_reg(pr_reg); 3386 core_scsi3_put_pr_reg(pr_reg);
@@ -3382,10 +3392,10 @@ static int core_scsi3_emulate_pro_register_and_move(
3382 if (se_port->sep_rtpi != rtpi) 3392 if (se_port->sep_rtpi != rtpi)
3383 continue; 3393 continue;
3384 dest_se_tpg = se_port->sep_tpg; 3394 dest_se_tpg = se_port->sep_tpg;
3385 if (!(dest_se_tpg)) 3395 if (!dest_se_tpg)
3386 continue; 3396 continue;
3387 dest_tf_ops = TPG_TFO(dest_se_tpg); 3397 dest_tf_ops = dest_se_tpg->se_tpg_tfo;
3388 if (!(dest_tf_ops)) 3398 if (!dest_tf_ops)
3389 continue; 3399 continue;
3390 3400
3391 atomic_inc(&dest_se_tpg->tpg_pr_ref_count); 3401 atomic_inc(&dest_se_tpg->tpg_pr_ref_count);
@@ -3394,7 +3404,7 @@ static int core_scsi3_emulate_pro_register_and_move(
3394 3404
3395 ret = core_scsi3_tpg_depend_item(dest_se_tpg); 3405 ret = core_scsi3_tpg_depend_item(dest_se_tpg);
3396 if (ret != 0) { 3406 if (ret != 0) {
3397 printk(KERN_ERR "core_scsi3_tpg_depend_item() failed" 3407 pr_err("core_scsi3_tpg_depend_item() failed"
3398 " for dest_se_tpg\n"); 3408 " for dest_se_tpg\n");
3399 atomic_dec(&dest_se_tpg->tpg_pr_ref_count); 3409 atomic_dec(&dest_se_tpg->tpg_pr_ref_count);
3400 smp_mb__after_atomic_dec(); 3410 smp_mb__after_atomic_dec();
@@ -3407,20 +3417,22 @@ static int core_scsi3_emulate_pro_register_and_move(
3407 } 3417 }
3408 spin_unlock(&dev->se_port_lock); 3418 spin_unlock(&dev->se_port_lock);
3409 3419
3410 if (!(dest_se_tpg) || (!dest_tf_ops)) { 3420 if (!dest_se_tpg || !dest_tf_ops) {
3411 printk(KERN_ERR "SPC-3 PR REGISTER_AND_MOVE: Unable to locate" 3421 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate"
3412 " fabric ops from Relative Target Port Identifier:" 3422 " fabric ops from Relative Target Port Identifier:"
3413 " %hu\n", rtpi); 3423 " %hu\n", rtpi);
3414 core_scsi3_put_pr_reg(pr_reg); 3424 core_scsi3_put_pr_reg(pr_reg);
3415 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3425 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3416 } 3426 }
3427
3428 buf = transport_kmap_first_data_page(cmd);
3417 proto_ident = (buf[24] & 0x0f); 3429 proto_ident = (buf[24] & 0x0f);
3418#if 0 3430#if 0
3419 printk("SPC-3 PR REGISTER_AND_MOVE: Extracted Protocol Identifier:" 3431 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Extracted Protocol Identifier:"
3420 " 0x%02x\n", proto_ident); 3432 " 0x%02x\n", proto_ident);
3421#endif 3433#endif
3422 if (proto_ident != dest_tf_ops->get_fabric_proto_ident(dest_se_tpg)) { 3434 if (proto_ident != dest_tf_ops->get_fabric_proto_ident(dest_se_tpg)) {
3423 printk(KERN_ERR "SPC-3 PR REGISTER_AND_MOVE: Received" 3435 pr_err("SPC-3 PR REGISTER_AND_MOVE: Received"
3424 " proto_ident: 0x%02x does not match ident: 0x%02x" 3436 " proto_ident: 0x%02x does not match ident: 0x%02x"
3425 " from fabric: %s\n", proto_ident, 3437 " from fabric: %s\n", proto_ident,
3426 dest_tf_ops->get_fabric_proto_ident(dest_se_tpg), 3438 dest_tf_ops->get_fabric_proto_ident(dest_se_tpg),
@@ -3429,7 +3441,7 @@ static int core_scsi3_emulate_pro_register_and_move(
3429 goto out; 3441 goto out;
3430 } 3442 }
3431 if (dest_tf_ops->tpg_parse_pr_out_transport_id == NULL) { 3443 if (dest_tf_ops->tpg_parse_pr_out_transport_id == NULL) {
3432 printk(KERN_ERR "SPC-3 PR REGISTER_AND_MOVE: Fabric does not" 3444 pr_err("SPC-3 PR REGISTER_AND_MOVE: Fabric does not"
3433 " containg a valid tpg_parse_pr_out_transport_id" 3445 " containg a valid tpg_parse_pr_out_transport_id"
3434 " function pointer\n"); 3446 " function pointer\n");
3435 ret = PYX_TRANSPORT_LU_COMM_FAILURE; 3447 ret = PYX_TRANSPORT_LU_COMM_FAILURE;
@@ -3437,14 +3449,17 @@ static int core_scsi3_emulate_pro_register_and_move(
3437 } 3449 }
3438 initiator_str = dest_tf_ops->tpg_parse_pr_out_transport_id(dest_se_tpg, 3450 initiator_str = dest_tf_ops->tpg_parse_pr_out_transport_id(dest_se_tpg,
3439 (const char *)&buf[24], &tmp_tid_len, &iport_ptr); 3451 (const char *)&buf[24], &tmp_tid_len, &iport_ptr);
3440 if (!(initiator_str)) { 3452 if (!initiator_str) {
3441 printk(KERN_ERR "SPC-3 PR REGISTER_AND_MOVE: Unable to locate" 3453 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate"
3442 " initiator_str from Transport ID\n"); 3454 " initiator_str from Transport ID\n");
3443 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3455 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3444 goto out; 3456 goto out;
3445 } 3457 }
3446 3458
3447 printk(KERN_INFO "SPC-3 PR [%s] Extracted initiator %s identifier: %s" 3459 transport_kunmap_first_data_page(cmd);
3460 buf = NULL;
3461
3462 pr_debug("SPC-3 PR [%s] Extracted initiator %s identifier: %s"
3448 " %s\n", dest_tf_ops->get_fabric_name(), (iport_ptr != NULL) ? 3463 " %s\n", dest_tf_ops->get_fabric_name(), (iport_ptr != NULL) ?
3449 "port" : "device", initiator_str, (iport_ptr != NULL) ? 3464 "port" : "device", initiator_str, (iport_ptr != NULL) ?
3450 iport_ptr : ""); 3465 iport_ptr : "");
@@ -3459,18 +3474,18 @@ static int core_scsi3_emulate_pro_register_and_move(
3459 pr_reg_nacl = pr_reg->pr_reg_nacl; 3474 pr_reg_nacl = pr_reg->pr_reg_nacl;
3460 matching_iname = (!strcmp(initiator_str, 3475 matching_iname = (!strcmp(initiator_str,
3461 pr_reg_nacl->initiatorname)) ? 1 : 0; 3476 pr_reg_nacl->initiatorname)) ? 1 : 0;
3462 if (!(matching_iname)) 3477 if (!matching_iname)
3463 goto after_iport_check; 3478 goto after_iport_check;
3464 3479
3465 if (!(iport_ptr) || !(pr_reg->isid_present_at_reg)) { 3480 if (!iport_ptr || !pr_reg->isid_present_at_reg) {
3466 printk(KERN_ERR "SPC-3 PR REGISTER_AND_MOVE: TransportID: %s" 3481 pr_err("SPC-3 PR REGISTER_AND_MOVE: TransportID: %s"
3467 " matches: %s on received I_T Nexus\n", initiator_str, 3482 " matches: %s on received I_T Nexus\n", initiator_str,
3468 pr_reg_nacl->initiatorname); 3483 pr_reg_nacl->initiatorname);
3469 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3484 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3470 goto out; 3485 goto out;
3471 } 3486 }
3472 if (!(strcmp(iport_ptr, pr_reg->pr_reg_isid))) { 3487 if (!strcmp(iport_ptr, pr_reg->pr_reg_isid)) {
3473 printk(KERN_ERR "SPC-3 PR REGISTER_AND_MOVE: TransportID: %s %s" 3488 pr_err("SPC-3 PR REGISTER_AND_MOVE: TransportID: %s %s"
3474 " matches: %s %s on received I_T Nexus\n", 3489 " matches: %s %s on received I_T Nexus\n",
3475 initiator_str, iport_ptr, pr_reg_nacl->initiatorname, 3490 initiator_str, iport_ptr, pr_reg_nacl->initiatorname,
3476 pr_reg->pr_reg_isid); 3491 pr_reg->pr_reg_isid);
@@ -3490,8 +3505,8 @@ after_iport_check:
3490 } 3505 }
3491 spin_unlock_bh(&dest_se_tpg->acl_node_lock); 3506 spin_unlock_bh(&dest_se_tpg->acl_node_lock);
3492 3507
3493 if (!(dest_node_acl)) { 3508 if (!dest_node_acl) {
3494 printk(KERN_ERR "Unable to locate %s dest_node_acl for" 3509 pr_err("Unable to locate %s dest_node_acl for"
3495 " TransportID%s\n", dest_tf_ops->get_fabric_name(), 3510 " TransportID%s\n", dest_tf_ops->get_fabric_name(),
3496 initiator_str); 3511 initiator_str);
3497 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3512 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
@@ -3499,7 +3514,7 @@ after_iport_check:
3499 } 3514 }
3500 ret = core_scsi3_nodeacl_depend_item(dest_node_acl); 3515 ret = core_scsi3_nodeacl_depend_item(dest_node_acl);
3501 if (ret != 0) { 3516 if (ret != 0) {
3502 printk(KERN_ERR "core_scsi3_nodeacl_depend_item() for" 3517 pr_err("core_scsi3_nodeacl_depend_item() for"
3503 " dest_node_acl\n"); 3518 " dest_node_acl\n");
3504 atomic_dec(&dest_node_acl->acl_pr_ref_count); 3519 atomic_dec(&dest_node_acl->acl_pr_ref_count);
3505 smp_mb__after_atomic_dec(); 3520 smp_mb__after_atomic_dec();
@@ -3508,7 +3523,7 @@ after_iport_check:
3508 goto out; 3523 goto out;
3509 } 3524 }
3510#if 0 3525#if 0
3511 printk(KERN_INFO "SPC-3 PR REGISTER_AND_MOVE: Found %s dest_node_acl:" 3526 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Found %s dest_node_acl:"
3512 " %s from TransportID\n", dest_tf_ops->get_fabric_name(), 3527 " %s from TransportID\n", dest_tf_ops->get_fabric_name(),
3513 dest_node_acl->initiatorname); 3528 dest_node_acl->initiatorname);
3514#endif 3529#endif
@@ -3517,8 +3532,8 @@ after_iport_check:
3517 * PORT IDENTIFIER. 3532 * PORT IDENTIFIER.
3518 */ 3533 */
3519 dest_se_deve = core_get_se_deve_from_rtpi(dest_node_acl, rtpi); 3534 dest_se_deve = core_get_se_deve_from_rtpi(dest_node_acl, rtpi);
3520 if (!(dest_se_deve)) { 3535 if (!dest_se_deve) {
3521 printk(KERN_ERR "Unable to locate %s dest_se_deve from RTPI:" 3536 pr_err("Unable to locate %s dest_se_deve from RTPI:"
3522 " %hu\n", dest_tf_ops->get_fabric_name(), rtpi); 3537 " %hu\n", dest_tf_ops->get_fabric_name(), rtpi);
3523 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3538 ret = PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3524 goto out; 3539 goto out;
@@ -3526,7 +3541,7 @@ after_iport_check:
3526 3541
3527 ret = core_scsi3_lunacl_depend_item(dest_se_deve); 3542 ret = core_scsi3_lunacl_depend_item(dest_se_deve);
3528 if (ret < 0) { 3543 if (ret < 0) {
3529 printk(KERN_ERR "core_scsi3_lunacl_depend_item() failed\n"); 3544 pr_err("core_scsi3_lunacl_depend_item() failed\n");
3530 atomic_dec(&dest_se_deve->pr_ref_count); 3545 atomic_dec(&dest_se_deve->pr_ref_count);
3531 smp_mb__after_atomic_dec(); 3546 smp_mb__after_atomic_dec();
3532 dest_se_deve = NULL; 3547 dest_se_deve = NULL;
@@ -3534,7 +3549,7 @@ after_iport_check:
3534 goto out; 3549 goto out;
3535 } 3550 }
3536#if 0 3551#if 0
3537 printk(KERN_INFO "SPC-3 PR REGISTER_AND_MOVE: Located %s node %s LUN" 3552 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Located %s node %s LUN"
3538 " ACL for dest_se_deve->mapped_lun: %u\n", 3553 " ACL for dest_se_deve->mapped_lun: %u\n",
3539 dest_tf_ops->get_fabric_name(), dest_node_acl->initiatorname, 3554 dest_tf_ops->get_fabric_name(), dest_node_acl->initiatorname,
3540 dest_se_deve->mapped_lun); 3555 dest_se_deve->mapped_lun);
@@ -3545,8 +3560,8 @@ after_iport_check:
3545 */ 3560 */
3546 spin_lock(&dev->dev_reservation_lock); 3561 spin_lock(&dev->dev_reservation_lock);
3547 pr_res_holder = dev->dev_pr_res_holder; 3562 pr_res_holder = dev->dev_pr_res_holder;
3548 if (!(pr_res_holder)) { 3563 if (!pr_res_holder) {
3549 printk(KERN_WARNING "SPC-3 PR REGISTER_AND_MOVE: No reservation" 3564 pr_warn("SPC-3 PR REGISTER_AND_MOVE: No reservation"
3550 " currently held\n"); 3565 " currently held\n");
3551 spin_unlock(&dev->dev_reservation_lock); 3566 spin_unlock(&dev->dev_reservation_lock);
3552 ret = PYX_TRANSPORT_INVALID_CDB_FIELD; 3567 ret = PYX_TRANSPORT_INVALID_CDB_FIELD;
@@ -3559,7 +3574,7 @@ after_iport_check:
3559 * Register behaviors for a REGISTER AND MOVE service action 3574 * Register behaviors for a REGISTER AND MOVE service action
3560 */ 3575 */
3561 if (pr_res_holder != pr_reg) { 3576 if (pr_res_holder != pr_reg) {
3562 printk(KERN_WARNING "SPC-3 PR REGISTER_AND_MOVE: Calling I_T" 3577 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Calling I_T"
3563 " Nexus is not reservation holder\n"); 3578 " Nexus is not reservation holder\n");
3564 spin_unlock(&dev->dev_reservation_lock); 3579 spin_unlock(&dev->dev_reservation_lock);
3565 ret = PYX_TRANSPORT_RESERVATION_CONFLICT; 3580 ret = PYX_TRANSPORT_RESERVATION_CONFLICT;
@@ -3576,7 +3591,7 @@ after_iport_check:
3576 */ 3591 */
3577 if ((pr_res_holder->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || 3592 if ((pr_res_holder->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) ||
3578 (pr_res_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) { 3593 (pr_res_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) {
3579 printk(KERN_WARNING "SPC-3 PR REGISTER_AND_MOVE: Unable to move" 3594 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Unable to move"
3580 " reservation for type: %s\n", 3595 " reservation for type: %s\n",
3581 core_scsi3_pr_dump_type(pr_res_holder->pr_res_type)); 3596 core_scsi3_pr_dump_type(pr_res_holder->pr_res_type));
3582 spin_unlock(&dev->dev_reservation_lock); 3597 spin_unlock(&dev->dev_reservation_lock);
@@ -3611,8 +3626,8 @@ after_iport_check:
3611 */ 3626 */
3612 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl, 3627 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl,
3613 iport_ptr); 3628 iport_ptr);
3614 if (!(dest_pr_reg)) { 3629 if (!dest_pr_reg) {
3615 ret = core_scsi3_alloc_registration(SE_DEV(cmd), 3630 ret = core_scsi3_alloc_registration(cmd->se_dev,
3616 dest_node_acl, dest_se_deve, iport_ptr, 3631 dest_node_acl, dest_se_deve, iport_ptr,
3617 sa_res_key, 0, aptpl, 2, 1); 3632 sa_res_key, 0, aptpl, 2, 1);
3618 if (ret != 0) { 3633 if (ret != 0) {
@@ -3644,16 +3659,16 @@ after_iport_check:
3644 /* 3659 /*
3645 * Increment PRGeneration for existing registrations.. 3660 * Increment PRGeneration for existing registrations..
3646 */ 3661 */
3647 if (!(new_reg)) 3662 if (!new_reg)
3648 dest_pr_reg->pr_res_generation = pr_tmpl->pr_generation++; 3663 dest_pr_reg->pr_res_generation = pr_tmpl->pr_generation++;
3649 spin_unlock(&dev->dev_reservation_lock); 3664 spin_unlock(&dev->dev_reservation_lock);
3650 3665
3651 printk(KERN_INFO "SPC-3 PR [%s] Service Action: REGISTER_AND_MOVE" 3666 pr_debug("SPC-3 PR [%s] Service Action: REGISTER_AND_MOVE"
3652 " created new reservation holder TYPE: %s on object RTPI:" 3667 " created new reservation holder TYPE: %s on object RTPI:"
3653 " %hu PRGeneration: 0x%08x\n", dest_tf_ops->get_fabric_name(), 3668 " %hu PRGeneration: 0x%08x\n", dest_tf_ops->get_fabric_name(),
3654 core_scsi3_pr_dump_type(type), rtpi, 3669 core_scsi3_pr_dump_type(type), rtpi,
3655 dest_pr_reg->pr_res_generation); 3670 dest_pr_reg->pr_res_generation);
3656 printk(KERN_INFO "SPC-3 PR Successfully moved reservation from" 3671 pr_debug("SPC-3 PR Successfully moved reservation from"
3657 " %s Fabric Node: %s%s -> %s Fabric Node: %s %s\n", 3672 " %s Fabric Node: %s%s -> %s Fabric Node: %s %s\n",
3658 tf_ops->get_fabric_name(), pr_reg_nacl->initiatorname, 3673 tf_ops->get_fabric_name(), pr_reg_nacl->initiatorname,
3659 (prf_isid) ? &i_buf[0] : "", dest_tf_ops->get_fabric_name(), 3674 (prf_isid) ? &i_buf[0] : "", dest_tf_ops->get_fabric_name(),
@@ -3681,24 +3696,28 @@ after_iport_check:
3681 * Clear the APTPL metadata if APTPL has been disabled, otherwise 3696 * Clear the APTPL metadata if APTPL has been disabled, otherwise
3682 * write out the updated metadata to struct file for this SCSI device. 3697 * write out the updated metadata to struct file for this SCSI device.
3683 */ 3698 */
3684 if (!(aptpl)) { 3699 if (!aptpl) {
3685 pr_tmpl->pr_aptpl_active = 0; 3700 pr_tmpl->pr_aptpl_active = 0;
3686 core_scsi3_update_and_write_aptpl(SE_DEV(cmd), NULL, 0); 3701 core_scsi3_update_and_write_aptpl(cmd->se_dev, NULL, 0);
3687 printk("SPC-3 PR: Set APTPL Bit Deactivated for" 3702 pr_debug("SPC-3 PR: Set APTPL Bit Deactivated for"
3688 " REGISTER_AND_MOVE\n"); 3703 " REGISTER_AND_MOVE\n");
3689 } else { 3704 } else {
3690 pr_tmpl->pr_aptpl_active = 1; 3705 pr_tmpl->pr_aptpl_active = 1;
3691 ret = core_scsi3_update_and_write_aptpl(SE_DEV(cmd), 3706 ret = core_scsi3_update_and_write_aptpl(cmd->se_dev,
3692 &dest_pr_reg->pr_aptpl_buf[0], 3707 &dest_pr_reg->pr_aptpl_buf[0],
3693 pr_tmpl->pr_aptpl_buf_len); 3708 pr_tmpl->pr_aptpl_buf_len);
3694 if (!(ret)) 3709 if (!ret)
3695 printk("SPC-3 PR: Set APTPL Bit Activated for" 3710 pr_debug("SPC-3 PR: Set APTPL Bit Activated for"
3696 " REGISTER_AND_MOVE\n"); 3711 " REGISTER_AND_MOVE\n");
3697 } 3712 }
3698 3713
3714 transport_kunmap_first_data_page(cmd);
3715
3699 core_scsi3_put_pr_reg(dest_pr_reg); 3716 core_scsi3_put_pr_reg(dest_pr_reg);
3700 return 0; 3717 return 0;
3701out: 3718out:
3719 if (buf)
3720 transport_kunmap_first_data_page(cmd);
3702 if (dest_se_deve) 3721 if (dest_se_deve)
3703 core_scsi3_lunacl_undepend_item(dest_se_deve); 3722 core_scsi3_lunacl_undepend_item(dest_se_deve);
3704 if (dest_node_acl) 3723 if (dest_node_acl)
@@ -3723,7 +3742,7 @@ static unsigned long long core_scsi3_extract_reservation_key(unsigned char *cdb)
3723 */ 3742 */
3724static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb) 3743static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3725{ 3744{
3726 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 3745 unsigned char *buf;
3727 u64 res_key, sa_res_key; 3746 u64 res_key, sa_res_key;
3728 int sa, scope, type, aptpl; 3747 int sa, scope, type, aptpl;
3729 int spec_i_pt = 0, all_tg_pt = 0, unreg = 0; 3748 int spec_i_pt = 0, all_tg_pt = 0, unreg = 0;
@@ -3731,11 +3750,11 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3731 * FIXME: A NULL struct se_session pointer means an this is not coming from 3750 * FIXME: A NULL struct se_session pointer means an this is not coming from
3732 * a $FABRIC_MOD's nexus, but from internal passthrough ops. 3751 * a $FABRIC_MOD's nexus, but from internal passthrough ops.
3733 */ 3752 */
3734 if (!(SE_SESS(cmd))) 3753 if (!cmd->se_sess)
3735 return PYX_TRANSPORT_LU_COMM_FAILURE; 3754 return PYX_TRANSPORT_LU_COMM_FAILURE;
3736 3755
3737 if (cmd->data_length < 24) { 3756 if (cmd->data_length < 24) {
3738 printk(KERN_WARNING "SPC-PR: Received PR OUT parameter list" 3757 pr_warn("SPC-PR: Received PR OUT parameter list"
3739 " length too small: %u\n", cmd->data_length); 3758 " length too small: %u\n", cmd->data_length);
3740 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3759 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3741 } 3760 }
@@ -3745,6 +3764,8 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3745 sa = (cdb[1] & 0x1f); 3764 sa = (cdb[1] & 0x1f);
3746 scope = (cdb[2] & 0xf0); 3765 scope = (cdb[2] & 0xf0);
3747 type = (cdb[2] & 0x0f); 3766 type = (cdb[2] & 0x0f);
3767
3768 buf = transport_kmap_first_data_page(cmd);
3748 /* 3769 /*
3749 * From PERSISTENT_RESERVE_OUT parameter list (payload) 3770 * From PERSISTENT_RESERVE_OUT parameter list (payload)
3750 */ 3771 */
@@ -3762,6 +3783,9 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3762 aptpl = (buf[17] & 0x01); 3783 aptpl = (buf[17] & 0x01);
3763 unreg = (buf[17] & 0x02); 3784 unreg = (buf[17] & 0x02);
3764 } 3785 }
3786 transport_kunmap_first_data_page(cmd);
3787 buf = NULL;
3788
3765 /* 3789 /*
3766 * SPEC_I_PT=1 is only valid for Service action: REGISTER 3790 * SPEC_I_PT=1 is only valid for Service action: REGISTER
3767 */ 3791 */
@@ -3776,9 +3800,9 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3776 * the sense key set to ILLEGAL REQUEST, and the additional sense 3800 * the sense key set to ILLEGAL REQUEST, and the additional sense
3777 * code set to PARAMETER LIST LENGTH ERROR. 3801 * code set to PARAMETER LIST LENGTH ERROR.
3778 */ 3802 */
3779 if (!(spec_i_pt) && ((cdb[1] & 0x1f) != PRO_REGISTER_AND_MOVE) && 3803 if (!spec_i_pt && ((cdb[1] & 0x1f) != PRO_REGISTER_AND_MOVE) &&
3780 (cmd->data_length != 24)) { 3804 (cmd->data_length != 24)) {
3781 printk(KERN_WARNING "SPC-PR: Received PR OUT illegal parameter" 3805 pr_warn("SPC-PR: Received PR OUT illegal parameter"
3782 " list length: %u\n", cmd->data_length); 3806 " list length: %u\n", cmd->data_length);
3783 return PYX_TRANSPORT_INVALID_PARAMETER_LIST; 3807 return PYX_TRANSPORT_INVALID_PARAMETER_LIST;
3784 } 3808 }
@@ -3812,7 +3836,7 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3812 return core_scsi3_emulate_pro_register_and_move(cmd, res_key, 3836 return core_scsi3_emulate_pro_register_and_move(cmd, res_key,
3813 sa_res_key, aptpl, unreg); 3837 sa_res_key, aptpl, unreg);
3814 default: 3838 default:
3815 printk(KERN_ERR "Unknown PERSISTENT_RESERVE_OUT service" 3839 pr_err("Unknown PERSISTENT_RESERVE_OUT service"
3816 " action: 0x%02x\n", cdb[1] & 0x1f); 3840 " action: 0x%02x\n", cdb[1] & 0x1f);
3817 return PYX_TRANSPORT_INVALID_CDB_FIELD; 3841 return PYX_TRANSPORT_INVALID_CDB_FIELD;
3818 } 3842 }
@@ -3827,25 +3851,26 @@ static int core_scsi3_emulate_pr_out(struct se_cmd *cmd, unsigned char *cdb)
3827 */ 3851 */
3828static int core_scsi3_pri_read_keys(struct se_cmd *cmd) 3852static int core_scsi3_pri_read_keys(struct se_cmd *cmd)
3829{ 3853{
3830 struct se_device *se_dev = SE_DEV(cmd); 3854 struct se_device *se_dev = cmd->se_dev;
3831 struct se_subsystem_dev *su_dev = SU_DEV(se_dev); 3855 struct se_subsystem_dev *su_dev = se_dev->se_sub_dev;
3832 struct t10_pr_registration *pr_reg; 3856 struct t10_pr_registration *pr_reg;
3833 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 3857 unsigned char *buf;
3834 u32 add_len = 0, off = 8; 3858 u32 add_len = 0, off = 8;
3835 3859
3836 if (cmd->data_length < 8) { 3860 if (cmd->data_length < 8) {
3837 printk(KERN_ERR "PRIN SA READ_KEYS SCSI Data Length: %u" 3861 pr_err("PRIN SA READ_KEYS SCSI Data Length: %u"
3838 " too small\n", cmd->data_length); 3862 " too small\n", cmd->data_length);
3839 return PYX_TRANSPORT_INVALID_CDB_FIELD; 3863 return PYX_TRANSPORT_INVALID_CDB_FIELD;
3840 } 3864 }
3841 3865
3842 buf[0] = ((T10_RES(su_dev)->pr_generation >> 24) & 0xff); 3866 buf = transport_kmap_first_data_page(cmd);
3843 buf[1] = ((T10_RES(su_dev)->pr_generation >> 16) & 0xff); 3867 buf[0] = ((su_dev->t10_pr.pr_generation >> 24) & 0xff);
3844 buf[2] = ((T10_RES(su_dev)->pr_generation >> 8) & 0xff); 3868 buf[1] = ((su_dev->t10_pr.pr_generation >> 16) & 0xff);
3845 buf[3] = (T10_RES(su_dev)->pr_generation & 0xff); 3869 buf[2] = ((su_dev->t10_pr.pr_generation >> 8) & 0xff);
3870 buf[3] = (su_dev->t10_pr.pr_generation & 0xff);
3846 3871
3847 spin_lock(&T10_RES(su_dev)->registration_lock); 3872 spin_lock(&su_dev->t10_pr.registration_lock);
3848 list_for_each_entry(pr_reg, &T10_RES(su_dev)->registration_list, 3873 list_for_each_entry(pr_reg, &su_dev->t10_pr.registration_list,
3849 pr_reg_list) { 3874 pr_reg_list) {
3850 /* 3875 /*
3851 * Check for overflow of 8byte PRI READ_KEYS payload and 3876 * Check for overflow of 8byte PRI READ_KEYS payload and
@@ -3865,13 +3890,15 @@ static int core_scsi3_pri_read_keys(struct se_cmd *cmd)
3865 3890
3866 add_len += 8; 3891 add_len += 8;
3867 } 3892 }
3868 spin_unlock(&T10_RES(su_dev)->registration_lock); 3893 spin_unlock(&su_dev->t10_pr.registration_lock);
3869 3894
3870 buf[4] = ((add_len >> 24) & 0xff); 3895 buf[4] = ((add_len >> 24) & 0xff);
3871 buf[5] = ((add_len >> 16) & 0xff); 3896 buf[5] = ((add_len >> 16) & 0xff);
3872 buf[6] = ((add_len >> 8) & 0xff); 3897 buf[6] = ((add_len >> 8) & 0xff);
3873 buf[7] = (add_len & 0xff); 3898 buf[7] = (add_len & 0xff);
3874 3899
3900 transport_kunmap_first_data_page(cmd);
3901
3875 return 0; 3902 return 0;
3876} 3903}
3877 3904
@@ -3882,23 +3909,24 @@ static int core_scsi3_pri_read_keys(struct se_cmd *cmd)
3882 */ 3909 */
3883static int core_scsi3_pri_read_reservation(struct se_cmd *cmd) 3910static int core_scsi3_pri_read_reservation(struct se_cmd *cmd)
3884{ 3911{
3885 struct se_device *se_dev = SE_DEV(cmd); 3912 struct se_device *se_dev = cmd->se_dev;
3886 struct se_subsystem_dev *su_dev = SU_DEV(se_dev); 3913 struct se_subsystem_dev *su_dev = se_dev->se_sub_dev;
3887 struct t10_pr_registration *pr_reg; 3914 struct t10_pr_registration *pr_reg;
3888 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 3915 unsigned char *buf;
3889 u64 pr_res_key; 3916 u64 pr_res_key;
3890 u32 add_len = 16; /* Hardcoded to 16 when a reservation is held. */ 3917 u32 add_len = 16; /* Hardcoded to 16 when a reservation is held. */
3891 3918
3892 if (cmd->data_length < 8) { 3919 if (cmd->data_length < 8) {
3893 printk(KERN_ERR "PRIN SA READ_RESERVATIONS SCSI Data Length: %u" 3920 pr_err("PRIN SA READ_RESERVATIONS SCSI Data Length: %u"
3894 " too small\n", cmd->data_length); 3921 " too small\n", cmd->data_length);
3895 return PYX_TRANSPORT_INVALID_CDB_FIELD; 3922 return PYX_TRANSPORT_INVALID_CDB_FIELD;
3896 } 3923 }
3897 3924
3898 buf[0] = ((T10_RES(su_dev)->pr_generation >> 24) & 0xff); 3925 buf = transport_kmap_first_data_page(cmd);
3899 buf[1] = ((T10_RES(su_dev)->pr_generation >> 16) & 0xff); 3926 buf[0] = ((su_dev->t10_pr.pr_generation >> 24) & 0xff);
3900 buf[2] = ((T10_RES(su_dev)->pr_generation >> 8) & 0xff); 3927 buf[1] = ((su_dev->t10_pr.pr_generation >> 16) & 0xff);
3901 buf[3] = (T10_RES(su_dev)->pr_generation & 0xff); 3928 buf[2] = ((su_dev->t10_pr.pr_generation >> 8) & 0xff);
3929 buf[3] = (su_dev->t10_pr.pr_generation & 0xff);
3902 3930
3903 spin_lock(&se_dev->dev_reservation_lock); 3931 spin_lock(&se_dev->dev_reservation_lock);
3904 pr_reg = se_dev->dev_pr_res_holder; 3932 pr_reg = se_dev->dev_pr_res_holder;
@@ -3911,10 +3939,9 @@ static int core_scsi3_pri_read_reservation(struct se_cmd *cmd)
3911 buf[6] = ((add_len >> 8) & 0xff); 3939 buf[6] = ((add_len >> 8) & 0xff);
3912 buf[7] = (add_len & 0xff); 3940 buf[7] = (add_len & 0xff);
3913 3941
3914 if (cmd->data_length < 22) { 3942 if (cmd->data_length < 22)
3915 spin_unlock(&se_dev->dev_reservation_lock); 3943 goto err;
3916 return 0; 3944
3917 }
3918 /* 3945 /*
3919 * Set the Reservation key. 3946 * Set the Reservation key.
3920 * 3947 *
@@ -3951,7 +3978,10 @@ static int core_scsi3_pri_read_reservation(struct se_cmd *cmd)
3951 buf[21] = (pr_reg->pr_res_scope & 0xf0) | 3978 buf[21] = (pr_reg->pr_res_scope & 0xf0) |
3952 (pr_reg->pr_res_type & 0x0f); 3979 (pr_reg->pr_res_type & 0x0f);
3953 } 3980 }
3981
3982err:
3954 spin_unlock(&se_dev->dev_reservation_lock); 3983 spin_unlock(&se_dev->dev_reservation_lock);
3984 transport_kunmap_first_data_page(cmd);
3955 3985
3956 return 0; 3986 return 0;
3957} 3987}
@@ -3963,17 +3993,19 @@ static int core_scsi3_pri_read_reservation(struct se_cmd *cmd)
3963 */ 3993 */
3964static int core_scsi3_pri_report_capabilities(struct se_cmd *cmd) 3994static int core_scsi3_pri_report_capabilities(struct se_cmd *cmd)
3965{ 3995{
3966 struct se_device *dev = SE_DEV(cmd); 3996 struct se_device *dev = cmd->se_dev;
3967 struct t10_reservation_template *pr_tmpl = &SU_DEV(dev)->t10_reservation; 3997 struct t10_reservation *pr_tmpl = &dev->se_sub_dev->t10_pr;
3968 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 3998 unsigned char *buf;
3969 u16 add_len = 8; /* Hardcoded to 8. */ 3999 u16 add_len = 8; /* Hardcoded to 8. */
3970 4000
3971 if (cmd->data_length < 6) { 4001 if (cmd->data_length < 6) {
3972 printk(KERN_ERR "PRIN SA REPORT_CAPABILITIES SCSI Data Length:" 4002 pr_err("PRIN SA REPORT_CAPABILITIES SCSI Data Length:"
3973 " %u too small\n", cmd->data_length); 4003 " %u too small\n", cmd->data_length);
3974 return PYX_TRANSPORT_INVALID_CDB_FIELD; 4004 return PYX_TRANSPORT_INVALID_CDB_FIELD;
3975 } 4005 }
3976 4006
4007 buf = transport_kmap_first_data_page(cmd);
4008
3977 buf[0] = ((add_len << 8) & 0xff); 4009 buf[0] = ((add_len << 8) & 0xff);
3978 buf[1] = (add_len & 0xff); 4010 buf[1] = (add_len & 0xff);
3979 buf[2] |= 0x10; /* CRH: Compatible Reservation Hanlding bit. */ 4011 buf[2] |= 0x10; /* CRH: Compatible Reservation Hanlding bit. */
@@ -4004,6 +4036,8 @@ static int core_scsi3_pri_report_capabilities(struct se_cmd *cmd)
4004 buf[4] |= 0x02; /* PR_TYPE_WRITE_EXCLUSIVE */ 4036 buf[4] |= 0x02; /* PR_TYPE_WRITE_EXCLUSIVE */
4005 buf[5] |= 0x01; /* PR_TYPE_EXCLUSIVE_ACCESS_ALLREG */ 4037 buf[5] |= 0x01; /* PR_TYPE_EXCLUSIVE_ACCESS_ALLREG */
4006 4038
4039 transport_kunmap_first_data_page(cmd);
4040
4007 return 0; 4041 return 0;
4008} 4042}
4009 4043
@@ -4014,27 +4048,29 @@ static int core_scsi3_pri_report_capabilities(struct se_cmd *cmd)
4014 */ 4048 */
4015static int core_scsi3_pri_read_full_status(struct se_cmd *cmd) 4049static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4016{ 4050{
4017 struct se_device *se_dev = SE_DEV(cmd); 4051 struct se_device *se_dev = cmd->se_dev;
4018 struct se_node_acl *se_nacl; 4052 struct se_node_acl *se_nacl;
4019 struct se_subsystem_dev *su_dev = SU_DEV(se_dev); 4053 struct se_subsystem_dev *su_dev = se_dev->se_sub_dev;
4020 struct se_portal_group *se_tpg; 4054 struct se_portal_group *se_tpg;
4021 struct t10_pr_registration *pr_reg, *pr_reg_tmp; 4055 struct t10_pr_registration *pr_reg, *pr_reg_tmp;
4022 struct t10_reservation_template *pr_tmpl = &SU_DEV(se_dev)->t10_reservation; 4056 struct t10_reservation *pr_tmpl = &se_dev->se_sub_dev->t10_pr;
4023 unsigned char *buf = (unsigned char *)T_TASK(cmd)->t_task_buf; 4057 unsigned char *buf;
4024 u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len; 4058 u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len;
4025 u32 off = 8; /* off into first Full Status descriptor */ 4059 u32 off = 8; /* off into first Full Status descriptor */
4026 int format_code = 0; 4060 int format_code = 0;
4027 4061
4028 if (cmd->data_length < 8) { 4062 if (cmd->data_length < 8) {
4029 printk(KERN_ERR "PRIN SA READ_FULL_STATUS SCSI Data Length: %u" 4063 pr_err("PRIN SA READ_FULL_STATUS SCSI Data Length: %u"
4030 " too small\n", cmd->data_length); 4064 " too small\n", cmd->data_length);
4031 return PYX_TRANSPORT_INVALID_CDB_FIELD; 4065 return PYX_TRANSPORT_INVALID_CDB_FIELD;
4032 } 4066 }
4033 4067
4034 buf[0] = ((T10_RES(su_dev)->pr_generation >> 24) & 0xff); 4068 buf = transport_kmap_first_data_page(cmd);
4035 buf[1] = ((T10_RES(su_dev)->pr_generation >> 16) & 0xff); 4069
4036 buf[2] = ((T10_RES(su_dev)->pr_generation >> 8) & 0xff); 4070 buf[0] = ((su_dev->t10_pr.pr_generation >> 24) & 0xff);
4037 buf[3] = (T10_RES(su_dev)->pr_generation & 0xff); 4071 buf[1] = ((su_dev->t10_pr.pr_generation >> 16) & 0xff);
4072 buf[2] = ((su_dev->t10_pr.pr_generation >> 8) & 0xff);
4073 buf[3] = (su_dev->t10_pr.pr_generation & 0xff);
4038 4074
4039 spin_lock(&pr_tmpl->registration_lock); 4075 spin_lock(&pr_tmpl->registration_lock);
4040 list_for_each_entry_safe(pr_reg, pr_reg_tmp, 4076 list_for_each_entry_safe(pr_reg, pr_reg_tmp,
@@ -4051,11 +4087,11 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4051 * Determine expected length of $FABRIC_MOD specific 4087 * Determine expected length of $FABRIC_MOD specific
4052 * TransportID full status descriptor.. 4088 * TransportID full status descriptor..
4053 */ 4089 */
4054 exp_desc_len = TPG_TFO(se_tpg)->tpg_get_pr_transport_id_len( 4090 exp_desc_len = se_tpg->se_tpg_tfo->tpg_get_pr_transport_id_len(
4055 se_tpg, se_nacl, pr_reg, &format_code); 4091 se_tpg, se_nacl, pr_reg, &format_code);
4056 4092
4057 if ((exp_desc_len + add_len) > cmd->data_length) { 4093 if ((exp_desc_len + add_len) > cmd->data_length) {
4058 printk(KERN_WARNING "SPC-3 PRIN READ_FULL_STATUS ran" 4094 pr_warn("SPC-3 PRIN READ_FULL_STATUS ran"
4059 " out of buffer: %d\n", cmd->data_length); 4095 " out of buffer: %d\n", cmd->data_length);
4060 spin_lock(&pr_tmpl->registration_lock); 4096 spin_lock(&pr_tmpl->registration_lock);
4061 atomic_dec(&pr_reg->pr_res_holders); 4097 atomic_dec(&pr_reg->pr_res_holders);
@@ -4105,7 +4141,7 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4105 * bit is set to one, the contents of the RELATIVE TARGET PORT 4141 * bit is set to one, the contents of the RELATIVE TARGET PORT
4106 * IDENTIFIER field are not defined by this standard. 4142 * IDENTIFIER field are not defined by this standard.
4107 */ 4143 */
4108 if (!(pr_reg->pr_reg_all_tg_pt)) { 4144 if (!pr_reg->pr_reg_all_tg_pt) {
4109 struct se_port *port = pr_reg->pr_reg_tg_pt_lun->lun_sep; 4145 struct se_port *port = pr_reg->pr_reg_tg_pt_lun->lun_sep;
4110 4146
4111 buf[off++] = ((port->sep_rtpi >> 8) & 0xff); 4147 buf[off++] = ((port->sep_rtpi >> 8) & 0xff);
@@ -4116,7 +4152,7 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4116 /* 4152 /*
4117 * Now, have the $FABRIC_MOD fill in the protocol identifier 4153 * Now, have the $FABRIC_MOD fill in the protocol identifier
4118 */ 4154 */
4119 desc_len = TPG_TFO(se_tpg)->tpg_get_pr_transport_id(se_tpg, 4155 desc_len = se_tpg->se_tpg_tfo->tpg_get_pr_transport_id(se_tpg,
4120 se_nacl, pr_reg, &format_code, &buf[off+4]); 4156 se_nacl, pr_reg, &format_code, &buf[off+4]);
4121 4157
4122 spin_lock(&pr_tmpl->registration_lock); 4158 spin_lock(&pr_tmpl->registration_lock);
@@ -4150,6 +4186,8 @@ static int core_scsi3_pri_read_full_status(struct se_cmd *cmd)
4150 buf[6] = ((add_len >> 8) & 0xff); 4186 buf[6] = ((add_len >> 8) & 0xff);
4151 buf[7] = (add_len & 0xff); 4187 buf[7] = (add_len & 0xff);
4152 4188
4189 transport_kunmap_first_data_page(cmd);
4190
4153 return 0; 4191 return 0;
4154} 4192}
4155 4193
@@ -4165,7 +4203,7 @@ static int core_scsi3_emulate_pr_in(struct se_cmd *cmd, unsigned char *cdb)
4165 case PRI_READ_FULL_STATUS: 4203 case PRI_READ_FULL_STATUS:
4166 return core_scsi3_pri_read_full_status(cmd); 4204 return core_scsi3_pri_read_full_status(cmd);
4167 default: 4205 default:
4168 printk(KERN_ERR "Unknown PERSISTENT_RESERVE_IN service" 4206 pr_err("Unknown PERSISTENT_RESERVE_IN service"
4169 " action: 0x%02x\n", cdb[1] & 0x1f); 4207 " action: 0x%02x\n", cdb[1] & 0x1f);
4170 return PYX_TRANSPORT_INVALID_CDB_FIELD; 4208 return PYX_TRANSPORT_INVALID_CDB_FIELD;
4171 } 4209 }
@@ -4174,7 +4212,7 @@ static int core_scsi3_emulate_pr_in(struct se_cmd *cmd, unsigned char *cdb)
4174 4212
4175int core_scsi3_emulate_pr(struct se_cmd *cmd) 4213int core_scsi3_emulate_pr(struct se_cmd *cmd)
4176{ 4214{
4177 unsigned char *cdb = &T_TASK(cmd)->t_task_cdb[0]; 4215 unsigned char *cdb = &cmd->t_task_cdb[0];
4178 struct se_device *dev = cmd->se_dev; 4216 struct se_device *dev = cmd->se_dev;
4179 /* 4217 /*
4180 * Following spc2r20 5.5.1 Reservations overview: 4218 * Following spc2r20 5.5.1 Reservations overview:
@@ -4186,7 +4224,7 @@ int core_scsi3_emulate_pr(struct se_cmd *cmd)
4186 * CONFLICT status. 4224 * CONFLICT status.
4187 */ 4225 */
4188 if (dev->dev_flags & DF_SPC2_RESERVATIONS) { 4226 if (dev->dev_flags & DF_SPC2_RESERVATIONS) {
4189 printk(KERN_ERR "Received PERSISTENT_RESERVE CDB while legacy" 4227 pr_err("Received PERSISTENT_RESERVE CDB while legacy"
4190 " SPC-2 reservation is held, returning" 4228 " SPC-2 reservation is held, returning"
4191 " RESERVATION_CONFLICT\n"); 4229 " RESERVATION_CONFLICT\n");
4192 return PYX_TRANSPORT_RESERVATION_CONFLICT; 4230 return PYX_TRANSPORT_RESERVATION_CONFLICT;
@@ -4213,39 +4251,39 @@ static int core_pt_seq_non_holder(
4213int core_setup_reservations(struct se_device *dev, int force_pt) 4251int core_setup_reservations(struct se_device *dev, int force_pt)
4214{ 4252{
4215 struct se_subsystem_dev *su_dev = dev->se_sub_dev; 4253 struct se_subsystem_dev *su_dev = dev->se_sub_dev;
4216 struct t10_reservation_template *rest = &su_dev->t10_reservation; 4254 struct t10_reservation *rest = &su_dev->t10_pr;
4217 /* 4255 /*
4218 * If this device is from Target_Core_Mod/pSCSI, use the reservations 4256 * If this device is from Target_Core_Mod/pSCSI, use the reservations
4219 * of the Underlying SCSI hardware. In Linux/SCSI terms, this can 4257 * of the Underlying SCSI hardware. In Linux/SCSI terms, this can
4220 * cause a problem because libata and some SATA RAID HBAs appear 4258 * cause a problem because libata and some SATA RAID HBAs appear
4221 * under Linux/SCSI, but to emulate reservations themselves. 4259 * under Linux/SCSI, but to emulate reservations themselves.
4222 */ 4260 */
4223 if (((TRANSPORT(dev)->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) && 4261 if (((dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) &&
4224 !(DEV_ATTRIB(dev)->emulate_reservations)) || force_pt) { 4262 !(dev->se_sub_dev->se_dev_attrib.emulate_reservations)) || force_pt) {
4225 rest->res_type = SPC_PASSTHROUGH; 4263 rest->res_type = SPC_PASSTHROUGH;
4226 rest->pr_ops.t10_reservation_check = &core_pt_reservation_check; 4264 rest->pr_ops.t10_reservation_check = &core_pt_reservation_check;
4227 rest->pr_ops.t10_seq_non_holder = &core_pt_seq_non_holder; 4265 rest->pr_ops.t10_seq_non_holder = &core_pt_seq_non_holder;
4228 printk(KERN_INFO "%s: Using SPC_PASSTHROUGH, no reservation" 4266 pr_debug("%s: Using SPC_PASSTHROUGH, no reservation"
4229 " emulation\n", TRANSPORT(dev)->name); 4267 " emulation\n", dev->transport->name);
4230 return 0; 4268 return 0;
4231 } 4269 }
4232 /* 4270 /*
4233 * If SPC-3 or above is reported by real or emulated struct se_device, 4271 * If SPC-3 or above is reported by real or emulated struct se_device,
4234 * use emulated Persistent Reservations. 4272 * use emulated Persistent Reservations.
4235 */ 4273 */
4236 if (TRANSPORT(dev)->get_device_rev(dev) >= SCSI_3) { 4274 if (dev->transport->get_device_rev(dev) >= SCSI_3) {
4237 rest->res_type = SPC3_PERSISTENT_RESERVATIONS; 4275 rest->res_type = SPC3_PERSISTENT_RESERVATIONS;
4238 rest->pr_ops.t10_reservation_check = &core_scsi3_pr_reservation_check; 4276 rest->pr_ops.t10_reservation_check = &core_scsi3_pr_reservation_check;
4239 rest->pr_ops.t10_seq_non_holder = &core_scsi3_pr_seq_non_holder; 4277 rest->pr_ops.t10_seq_non_holder = &core_scsi3_pr_seq_non_holder;
4240 printk(KERN_INFO "%s: Using SPC3_PERSISTENT_RESERVATIONS" 4278 pr_debug("%s: Using SPC3_PERSISTENT_RESERVATIONS"
4241 " emulation\n", TRANSPORT(dev)->name); 4279 " emulation\n", dev->transport->name);
4242 } else { 4280 } else {
4243 rest->res_type = SPC2_RESERVATIONS; 4281 rest->res_type = SPC2_RESERVATIONS;
4244 rest->pr_ops.t10_reservation_check = &core_scsi2_reservation_check; 4282 rest->pr_ops.t10_reservation_check = &core_scsi2_reservation_check;
4245 rest->pr_ops.t10_seq_non_holder = 4283 rest->pr_ops.t10_seq_non_holder =
4246 &core_scsi2_reservation_seq_non_holder; 4284 &core_scsi2_reservation_seq_non_holder;
4247 printk(KERN_INFO "%s: Using SPC2_RESERVATIONS emulation\n", 4285 pr_debug("%s: Using SPC2_RESERVATIONS emulation\n",
4248 TRANSPORT(dev)->name); 4286 dev->transport->name);
4249 } 4287 }
4250 4288
4251 return 0; 4289 return 0;