Lines Matching +full:key +full:- +full:release

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * This file contains SPC-3 compliant persistent reservations and
6 * legacy SPC-2 reservations with compatible reservation handling (CRH=1)
8 * (c) Copyright 2009-2013 Datera, Inc.
48 if (!pr_reg->isid_present_at_reg) { in core_pr_dump_initiator_port()
53 snprintf(buf, size, ",i,0x%s", pr_reg->pr_reg_isid); in core_pr_dump_initiator_port()
77 pr_res_type = pr_res_holder->pr_res_type; in is_reservation_holder()
89 struct se_device *dev = cmd->se_dev; in target_scsi2_reservation_check()
90 struct se_session *sess = cmd->se_sess; in target_scsi2_reservation_check()
92 switch (cmd->t_task_cdb[0]) { in target_scsi2_reservation_check()
94 case RELEASE: in target_scsi2_reservation_check()
101 if (!dev->reservation_holder || !sess) in target_scsi2_reservation_check()
104 if (dev->reservation_holder->se_node_acl != sess->se_node_acl) in target_scsi2_reservation_check()
107 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) { in target_scsi2_reservation_check()
108 if (dev->dev_res_bin_isid != sess->sess_bin_isid) in target_scsi2_reservation_check()
121 struct se_session *se_sess = cmd->se_sess; in target_check_scsi2_reservation_conflict()
122 struct se_device *dev = cmd->se_dev; in target_check_scsi2_reservation_conflict()
124 struct t10_reservation *pr_tmpl = &dev->t10_pr; in target_check_scsi2_reservation_conflict()
127 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, in target_check_scsi2_reservation_conflict()
131 * From spc4r17 5.7.3 Exceptions to SPC-2 RESERVE and RELEASE in target_check_scsi2_reservation_conflict()
139 * A RELEASE(6) or RELEASE(10) command shall complete with GOOD in target_check_scsi2_reservation_conflict()
148 * RELEASE(6) command, or RELEASE(10) command shall be processed in target_check_scsi2_reservation_conflict()
149 * as defined in SPC-2. in target_check_scsi2_reservation_conflict()
151 if (pr_reg->pr_res_holder) { in target_check_scsi2_reservation_conflict()
155 if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_REGONLY) || in target_check_scsi2_reservation_conflict()
156 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_REGONLY) || in target_check_scsi2_reservation_conflict()
157 (pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || in target_check_scsi2_reservation_conflict()
158 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) { in target_check_scsi2_reservation_conflict()
170 * EXISTING KEY service action and is still registered by any in target_check_scsi2_reservation_conflict()
171 * initiator, all RESERVE commands and all RELEASE commands in target_check_scsi2_reservation_conflict()
175 spin_lock(&pr_tmpl->registration_lock); in target_check_scsi2_reservation_conflict()
176 conflict = (list_empty(&pr_tmpl->registration_list)) ? 0 : 1; in target_check_scsi2_reservation_conflict()
177 spin_unlock(&pr_tmpl->registration_lock); in target_check_scsi2_reservation_conflict()
181 pr_err("Received legacy SPC-2 RESERVE/RELEASE" in target_check_scsi2_reservation_conflict()
182 " while active SPC-3 registrations exist," in target_check_scsi2_reservation_conflict()
184 return -EBUSY; in target_check_scsi2_reservation_conflict()
192 dev->reservation_holder = NULL; in target_release_reservation()
193 dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS; in target_release_reservation()
194 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS_WITH_ISID) { in target_release_reservation()
195 dev->dev_res_bin_isid = 0; in target_release_reservation()
196 dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS_WITH_ISID; in target_release_reservation()
203 struct se_device *dev = cmd->se_dev; in target_scsi2_reservation_release()
204 struct se_session *sess = cmd->se_sess; in target_scsi2_reservation_release()
208 if (!sess || !sess->se_tpg) in target_scsi2_reservation_release()
216 spin_lock(&dev->dev_reservation_lock); in target_scsi2_reservation_release()
217 if (!dev->reservation_holder || !sess) in target_scsi2_reservation_release()
220 if (dev->reservation_holder->se_node_acl != sess->se_node_acl) in target_scsi2_reservation_release()
223 if (dev->dev_res_bin_isid != sess->sess_bin_isid) in target_scsi2_reservation_release()
227 tpg = sess->se_tpg; in target_scsi2_reservation_release()
228 pr_debug("SCSI-2 Released reservation for %s LUN: %llu ->" in target_scsi2_reservation_release()
230 tpg->se_tpg_tfo->fabric_name, in target_scsi2_reservation_release()
231 cmd->se_lun->unpacked_lun, cmd->orig_fe_lun, in target_scsi2_reservation_release()
232 sess->se_node_acl->initiatorname); in target_scsi2_reservation_release()
235 spin_unlock(&dev->dev_reservation_lock); in target_scsi2_reservation_release()
244 struct se_device *dev = cmd->se_dev; in target_scsi2_reservation_reserve()
245 struct se_session *sess = cmd->se_sess; in target_scsi2_reservation_reserve()
250 if ((cmd->t_task_cdb[1] & 0x01) && in target_scsi2_reservation_reserve()
251 (cmd->t_task_cdb[1] & 0x02)) { in target_scsi2_reservation_reserve()
259 if (!sess || !sess->se_tpg) in target_scsi2_reservation_reserve()
268 tpg = sess->se_tpg; in target_scsi2_reservation_reserve()
269 spin_lock(&dev->dev_reservation_lock); in target_scsi2_reservation_reserve()
270 if (dev->reservation_holder && in target_scsi2_reservation_reserve()
271 dev->reservation_holder->se_node_acl != sess->se_node_acl) { in target_scsi2_reservation_reserve()
272 pr_err("SCSI-2 RESERVATION CONFLICT for %s fabric\n", in target_scsi2_reservation_reserve()
273 tpg->se_tpg_tfo->fabric_name); in target_scsi2_reservation_reserve()
275 cmd->se_lun->unpacked_lun, in target_scsi2_reservation_reserve()
276 dev->reservation_holder->se_node_acl->initiatorname); in target_scsi2_reservation_reserve()
277 pr_err("Current attempt - LUN: %llu -> MAPPED LUN: %llu" in target_scsi2_reservation_reserve()
278 " from %s \n", cmd->se_lun->unpacked_lun, in target_scsi2_reservation_reserve()
279 cmd->orig_fe_lun, in target_scsi2_reservation_reserve()
280 sess->se_node_acl->initiatorname); in target_scsi2_reservation_reserve()
285 dev->reservation_holder = sess; in target_scsi2_reservation_reserve()
286 dev->dev_reservation_flags |= DRF_SPC2_RESERVATIONS; in target_scsi2_reservation_reserve()
287 if (sess->sess_bin_isid != 0) { in target_scsi2_reservation_reserve()
288 dev->dev_res_bin_isid = sess->sess_bin_isid; in target_scsi2_reservation_reserve()
289 dev->dev_reservation_flags |= DRF_SPC2_RESERVATIONS_WITH_ISID; in target_scsi2_reservation_reserve()
291 pr_debug("SCSI-2 Reserved %s LUN: %llu -> MAPPED LUN: %llu" in target_scsi2_reservation_reserve()
292 " for %s\n", tpg->se_tpg_tfo->fabric_name, in target_scsi2_reservation_reserve()
293 cmd->se_lun->unpacked_lun, cmd->orig_fe_lun, in target_scsi2_reservation_reserve()
294 sess->se_node_acl->initiatorname); in target_scsi2_reservation_reserve()
297 spin_unlock(&dev->dev_reservation_lock); in target_scsi2_reservation_reserve()
306 * Begin SPC-3/SPC-4 Persistent Reservations emulation support
314 unsigned char *cdb = cmd->t_task_cdb; in core_scsi3_pr_seq_non_holder()
315 struct se_session *se_sess = cmd->se_sess; in core_scsi3_pr_seq_non_holder()
316 struct se_node_acl *nacl = se_sess->se_node_acl; in core_scsi3_pr_seq_non_holder()
330 se_deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); in core_scsi3_pr_seq_non_holder()
333 &se_deve->deve_flags); in core_scsi3_pr_seq_non_holder()
366 return -EINVAL; in core_scsi3_pr_seq_non_holder()
418 return -EINVAL; in core_scsi3_pr_seq_non_holder()
421 case RELEASE: in core_scsi3_pr_seq_non_holder()
465 return -EINVAL; in core_scsi3_pr_seq_non_holder()
499 if (cmd->data_direction == DMA_TO_DEVICE) { in core_scsi3_pr_seq_non_holder()
506 se_sess->se_node_acl->initiatorname, cdb[0], in core_scsi3_pr_seq_non_holder()
513 * non-registered_nexuxes NOT holding the reservation. in core_scsi3_pr_seq_non_holder()
516 * as we expect registered non-reservation holding in core_scsi3_pr_seq_non_holder()
547 if (cmd->data_direction == DMA_FROM_DEVICE) { in core_scsi3_pr_seq_non_holder()
558 se_sess->se_node_acl->initiatorname, cdb[0], in core_scsi3_pr_seq_non_holder()
567 struct se_device *dev = cmd->se_dev; in target_scsi3_pr_reservation_check()
568 struct se_session *sess = cmd->se_sess; in target_scsi3_pr_reservation_check()
572 if (!dev->dev_pr_res_holder) in target_scsi3_pr_reservation_check()
575 pr_reg_type = dev->dev_pr_res_holder->pr_res_type; in target_scsi3_pr_reservation_check()
576 cmd->pr_res_key = dev->dev_pr_res_holder->pr_res_key; in target_scsi3_pr_reservation_check()
577 if (dev->dev_pr_res_holder->pr_reg_nacl != sess->se_node_acl) in target_scsi3_pr_reservation_check()
580 if (dev->dev_pr_res_holder->isid_present_at_reg) { in target_scsi3_pr_reservation_check()
581 if (dev->dev_pr_res_holder->pr_reg_bin_isid != in target_scsi3_pr_reservation_check()
582 sess->sess_bin_isid) { in target_scsi3_pr_reservation_check()
601 * PRGeneration field shall contain the value of a 32-bit wrapping in core_scsi3_pr_generation()
609 spin_lock(&dev->dev_reservation_lock); in core_scsi3_pr_generation()
610 prg = dev->t10_pr.pr_generation++; in core_scsi3_pr_generation()
611 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pr_generation()
635 INIT_LIST_HEAD(&pr_reg->pr_reg_list); in __core_scsi3_do_alloc_registration()
636 INIT_LIST_HEAD(&pr_reg->pr_reg_abort_list); in __core_scsi3_do_alloc_registration()
637 INIT_LIST_HEAD(&pr_reg->pr_reg_aptpl_list); in __core_scsi3_do_alloc_registration()
638 INIT_LIST_HEAD(&pr_reg->pr_reg_atp_list); in __core_scsi3_do_alloc_registration()
639 INIT_LIST_HEAD(&pr_reg->pr_reg_atp_mem_list); in __core_scsi3_do_alloc_registration()
640 atomic_set(&pr_reg->pr_res_holders, 0); in __core_scsi3_do_alloc_registration()
641 pr_reg->pr_reg_nacl = nacl; in __core_scsi3_do_alloc_registration()
644 * the se_dev_entry->pr_ref will have been already obtained by in __core_scsi3_do_alloc_registration()
651 pr_reg->pr_reg_deve = dest_deve; in __core_scsi3_do_alloc_registration()
654 pr_reg->pr_reg_deve = target_nacl_find_deve(nacl, mapped_lun); in __core_scsi3_do_alloc_registration()
655 if (!pr_reg->pr_reg_deve) { in __core_scsi3_do_alloc_registration()
658 nacl->initiatorname, mapped_lun); in __core_scsi3_do_alloc_registration()
662 kref_get(&pr_reg->pr_reg_deve->pr_kref); in __core_scsi3_do_alloc_registration()
665 pr_reg->pr_res_mapped_lun = mapped_lun; in __core_scsi3_do_alloc_registration()
666 pr_reg->pr_aptpl_target_lun = lun->unpacked_lun; in __core_scsi3_do_alloc_registration()
667 pr_reg->tg_pt_sep_rtpi = lun->lun_tpg->tpg_rtpi; in __core_scsi3_do_alloc_registration()
668 pr_reg->pr_res_key = sa_res_key; in __core_scsi3_do_alloc_registration()
669 pr_reg->pr_reg_all_tg_pt = all_tg_pt; in __core_scsi3_do_alloc_registration()
670 pr_reg->pr_reg_aptpl = aptpl; in __core_scsi3_do_alloc_registration()
676 pr_reg->pr_reg_bin_isid = get_unaligned_be64(isid); in __core_scsi3_do_alloc_registration()
677 snprintf(pr_reg->pr_reg_isid, PR_REG_ISID_LEN, "%s", isid); in __core_scsi3_do_alloc_registration()
678 pr_reg->isid_present_at_reg = 1; in __core_scsi3_do_alloc_registration()
706 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; in __core_scsi3_alloc_registration()
727 spin_lock(&dev->se_port_lock); in __core_scsi3_alloc_registration()
728 list_for_each_entry_safe(lun_tmp, next, &dev->dev_sep_list, lun_dev_link) { in __core_scsi3_alloc_registration()
729 if (!percpu_ref_tryget_live(&lun_tmp->lun_ref)) in __core_scsi3_alloc_registration()
731 spin_unlock(&dev->se_port_lock); in __core_scsi3_alloc_registration()
733 spin_lock(&lun_tmp->lun_deve_lock); in __core_scsi3_alloc_registration()
734 list_for_each_entry(deve_tmp, &lun_tmp->lun_deve_list, lun_link) { in __core_scsi3_alloc_registration()
740 if (!deve_tmp->se_lun_acl) in __core_scsi3_alloc_registration()
743 lacl_tmp = deve_tmp->se_lun_acl; in __core_scsi3_alloc_registration()
744 nacl_tmp = lacl_tmp->se_lun_nacl; in __core_scsi3_alloc_registration()
756 if (tfo != nacl_tmp->se_tpg->se_tpg_tfo) in __core_scsi3_alloc_registration()
761 if (strcmp(nacl->initiatorname, nacl_tmp->initiatorname)) in __core_scsi3_alloc_registration()
764 kref_get(&deve_tmp->pr_kref); in __core_scsi3_alloc_registration()
765 spin_unlock(&lun_tmp->lun_deve_lock); in __core_scsi3_alloc_registration()
776 percpu_ref_put(&lun_tmp->lun_ref); in __core_scsi3_alloc_registration()
777 kref_put(&deve_tmp->pr_kref, target_pr_kref_release); in __core_scsi3_alloc_registration()
783 * pr_reg->pr_reg_atp_list that will be processed once in __core_scsi3_alloc_registration()
787 dest_lun = deve_tmp->se_lun; in __core_scsi3_alloc_registration()
791 deve_tmp->mapped_lun, NULL, in __core_scsi3_alloc_registration()
794 percpu_ref_put(&lun_tmp->lun_ref); in __core_scsi3_alloc_registration()
799 list_add_tail(&pr_reg_atp->pr_reg_atp_mem_list, in __core_scsi3_alloc_registration()
800 &pr_reg->pr_reg_atp_list); in __core_scsi3_alloc_registration()
801 spin_lock(&lun_tmp->lun_deve_lock); in __core_scsi3_alloc_registration()
803 spin_unlock(&lun_tmp->lun_deve_lock); in __core_scsi3_alloc_registration()
805 spin_lock(&dev->se_port_lock); in __core_scsi3_alloc_registration()
806 percpu_ref_put(&lun_tmp->lun_ref); in __core_scsi3_alloc_registration()
808 spin_unlock(&dev->se_port_lock); in __core_scsi3_alloc_registration()
813 &pr_reg->pr_reg_atp_list, pr_reg_atp_mem_list) { in __core_scsi3_alloc_registration()
814 list_del(&pr_reg_tmp->pr_reg_atp_mem_list); in __core_scsi3_alloc_registration()
815 core_scsi3_lunacl_undepend_item(pr_reg_tmp->pr_reg_deve); in __core_scsi3_alloc_registration()
839 return -EINVAL; in core_scsi3_alloc_aptpl_registration()
845 return -ENOMEM; in core_scsi3_alloc_aptpl_registration()
848 INIT_LIST_HEAD(&pr_reg->pr_reg_list); in core_scsi3_alloc_aptpl_registration()
849 INIT_LIST_HEAD(&pr_reg->pr_reg_abort_list); in core_scsi3_alloc_aptpl_registration()
850 INIT_LIST_HEAD(&pr_reg->pr_reg_aptpl_list); in core_scsi3_alloc_aptpl_registration()
851 INIT_LIST_HEAD(&pr_reg->pr_reg_atp_list); in core_scsi3_alloc_aptpl_registration()
852 INIT_LIST_HEAD(&pr_reg->pr_reg_atp_mem_list); in core_scsi3_alloc_aptpl_registration()
853 atomic_set(&pr_reg->pr_res_holders, 0); in core_scsi3_alloc_aptpl_registration()
854 pr_reg->pr_reg_nacl = NULL; in core_scsi3_alloc_aptpl_registration()
855 pr_reg->pr_reg_deve = NULL; in core_scsi3_alloc_aptpl_registration()
856 pr_reg->pr_res_mapped_lun = mapped_lun; in core_scsi3_alloc_aptpl_registration()
857 pr_reg->pr_aptpl_target_lun = target_lun; in core_scsi3_alloc_aptpl_registration()
858 pr_reg->pr_res_key = sa_res_key; in core_scsi3_alloc_aptpl_registration()
859 pr_reg->pr_reg_all_tg_pt = all_tg_pt; in core_scsi3_alloc_aptpl_registration()
860 pr_reg->pr_reg_aptpl = 1; in core_scsi3_alloc_aptpl_registration()
861 pr_reg->pr_res_scope = 0; /* Always LUN_SCOPE */ in core_scsi3_alloc_aptpl_registration()
862 pr_reg->pr_res_type = type; in core_scsi3_alloc_aptpl_registration()
868 pr_reg->pr_reg_bin_isid = get_unaligned_be64(isid); in core_scsi3_alloc_aptpl_registration()
869 snprintf(pr_reg->pr_reg_isid, PR_REG_ISID_LEN, "%s", isid); in core_scsi3_alloc_aptpl_registration()
870 pr_reg->isid_present_at_reg = 1; in core_scsi3_alloc_aptpl_registration()
875 snprintf(pr_reg->pr_iport, PR_APTPL_MAX_IPORT_LEN, "%s", i_port); in core_scsi3_alloc_aptpl_registration()
876 snprintf(pr_reg->pr_tport, PR_APTPL_MAX_TPORT_LEN, "%s", t_port); in core_scsi3_alloc_aptpl_registration()
877 pr_reg->pr_reg_tpgt = tpgt; in core_scsi3_alloc_aptpl_registration()
884 pr_reg->pr_res_holder = res_holder; in core_scsi3_alloc_aptpl_registration()
886 list_add_tail(&pr_reg->pr_reg_aptpl_list, &pr_tmpl->aptpl_reg_list); in core_scsi3_alloc_aptpl_registration()
887 pr_debug("SPC-3 PR APTPL Successfully added registration%s from" in core_scsi3_alloc_aptpl_registration()
902 spin_lock(&dev->dev_reservation_lock); in core_scsi3_aptpl_reserve()
903 dev->dev_pr_res_holder = pr_reg; in core_scsi3_aptpl_reserve()
904 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_aptpl_reserve()
906 pr_debug("SPC-3 PR [%s] Service Action: APTPL RESERVE created" in core_scsi3_aptpl_reserve()
908 tpg->se_tpg_tfo->fabric_name, in core_scsi3_aptpl_reserve()
909 core_scsi3_pr_dump_type(pr_reg->pr_res_type), in core_scsi3_aptpl_reserve()
910 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); in core_scsi3_aptpl_reserve()
911 pr_debug("SPC-3 PR [%s] RESERVE Node: %s%s\n", in core_scsi3_aptpl_reserve()
912 tpg->se_tpg_tfo->fabric_name, node_acl->initiatorname, in core_scsi3_aptpl_reserve()
928 struct t10_reservation *pr_tmpl = &dev->t10_pr; in __core_scsi3_check_aptpl_registration()
936 snprintf(i_port, PR_APTPL_MAX_IPORT_LEN, "%s", nacl->initiatorname); in __core_scsi3_check_aptpl_registration()
938 tpg->se_tpg_tfo->tpg_get_wwn(tpg)); in __core_scsi3_check_aptpl_registration()
939 tpgt = tpg->se_tpg_tfo->tpg_get_tag(tpg); in __core_scsi3_check_aptpl_registration()
946 spin_lock(&pr_tmpl->aptpl_reg_lock); in __core_scsi3_check_aptpl_registration()
947 list_for_each_entry_safe(pr_reg, pr_reg_tmp, &pr_tmpl->aptpl_reg_list, in __core_scsi3_check_aptpl_registration()
950 if (!strcmp(pr_reg->pr_iport, i_port) && in __core_scsi3_check_aptpl_registration()
951 (pr_reg->pr_res_mapped_lun == mapped_lun) && in __core_scsi3_check_aptpl_registration()
952 !(strcmp(pr_reg->pr_tport, t_port)) && in __core_scsi3_check_aptpl_registration()
953 (pr_reg->pr_reg_tpgt == tpgt) && in __core_scsi3_check_aptpl_registration()
954 (pr_reg->pr_aptpl_target_lun == target_lun)) { in __core_scsi3_check_aptpl_registration()
956 * Obtain the ->pr_reg_deve pointer + reference, that in __core_scsi3_check_aptpl_registration()
960 pr_reg->pr_reg_deve = target_nacl_find_deve(nacl, mapped_lun); in __core_scsi3_check_aptpl_registration()
961 if (!pr_reg->pr_reg_deve) { in __core_scsi3_check_aptpl_registration()
963 " %llu\n", nacl->initiatorname, mapped_lun); in __core_scsi3_check_aptpl_registration()
967 kref_get(&pr_reg->pr_reg_deve->pr_kref); in __core_scsi3_check_aptpl_registration()
970 pr_reg->pr_reg_nacl = nacl; in __core_scsi3_check_aptpl_registration()
971 pr_reg->tg_pt_sep_rtpi = lun->lun_tpg->tpg_rtpi; in __core_scsi3_check_aptpl_registration()
972 list_del(&pr_reg->pr_reg_aptpl_list); in __core_scsi3_check_aptpl_registration()
973 spin_unlock(&pr_tmpl->aptpl_reg_lock); in __core_scsi3_check_aptpl_registration()
983 if (pr_reg->pr_res_holder) in __core_scsi3_check_aptpl_registration()
990 spin_lock(&pr_tmpl->aptpl_reg_lock); in __core_scsi3_check_aptpl_registration()
991 pr_tmpl->pr_aptpl_active = 1; in __core_scsi3_check_aptpl_registration()
994 spin_unlock(&pr_tmpl->aptpl_reg_lock); in __core_scsi3_check_aptpl_registration()
1006 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) in core_scsi3_check_aptpl_registration()
1010 lun->unpacked_lun, nacl, in core_scsi3_check_aptpl_registration()
1021 struct se_portal_group *se_tpg = nacl->se_tpg; in __core_scsi3_dump_registration()
1026 pr_debug("SPC-3 PR [%s] Service Action: REGISTER%s Initiator" in __core_scsi3_dump_registration()
1027 " Node: %s%s\n", tfo->fabric_name, (register_type == REGISTER_AND_MOVE) ? in __core_scsi3_dump_registration()
1029 "_AND_IGNORE_EXISTING_KEY" : "", nacl->initiatorname, in __core_scsi3_dump_registration()
1031 pr_debug("SPC-3 PR [%s] registration on Target Port: %s,0x%04x\n", in __core_scsi3_dump_registration()
1032 tfo->fabric_name, tfo->tpg_get_wwn(se_tpg), in __core_scsi3_dump_registration()
1033 tfo->tpg_get_tag(se_tpg)); in __core_scsi3_dump_registration()
1034 pr_debug("SPC-3 PR [%s] for %s TCM Subsystem %s Object Target" in __core_scsi3_dump_registration()
1035 " Port(s)\n", tfo->fabric_name, in __core_scsi3_dump_registration()
1036 (pr_reg->pr_reg_all_tg_pt) ? "ALL" : "SINGLE", in __core_scsi3_dump_registration()
1037 dev->transport->name); in __core_scsi3_dump_registration()
1038 pr_debug("SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:" in __core_scsi3_dump_registration()
1039 " 0x%08x APTPL: %d\n", tfo->fabric_name, in __core_scsi3_dump_registration()
1040 pr_reg->pr_res_key, pr_reg->pr_res_generation, in __core_scsi3_dump_registration()
1041 pr_reg->pr_reg_aptpl); in __core_scsi3_dump_registration()
1051 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; in __core_scsi3_add_registration()
1053 struct t10_reservation *pr_tmpl = &dev->t10_pr; in __core_scsi3_add_registration()
1061 * action, the struct se_device->dev_reservation_lock will already be held, in __core_scsi3_add_registration()
1065 pr_reg->pr_res_generation = (register_move) ? in __core_scsi3_add_registration()
1066 dev->t10_pr.pr_generation++ : in __core_scsi3_add_registration()
1069 spin_lock(&pr_tmpl->registration_lock); in __core_scsi3_add_registration()
1070 list_add_tail(&pr_reg->pr_reg_list, &pr_tmpl->registration_list); in __core_scsi3_add_registration()
1073 spin_unlock(&pr_tmpl->registration_lock); in __core_scsi3_add_registration()
1077 if (!pr_reg->pr_reg_all_tg_pt || register_move) in __core_scsi3_add_registration()
1080 * Walk pr_reg->pr_reg_atp_list and add registrations for ALL_TG_PT=1 in __core_scsi3_add_registration()
1084 &pr_reg->pr_reg_atp_list, pr_reg_atp_mem_list) { in __core_scsi3_add_registration()
1085 struct se_node_acl *nacl_tmp = pr_reg_tmp->pr_reg_nacl; in __core_scsi3_add_registration()
1087 list_del(&pr_reg_tmp->pr_reg_atp_mem_list); in __core_scsi3_add_registration()
1089 pr_reg_tmp->pr_res_generation = core_scsi3_pr_generation(dev); in __core_scsi3_add_registration()
1091 spin_lock(&pr_tmpl->registration_lock); in __core_scsi3_add_registration()
1092 list_add_tail(&pr_reg_tmp->pr_reg_list, in __core_scsi3_add_registration()
1093 &pr_tmpl->registration_list); in __core_scsi3_add_registration()
1097 spin_unlock(&pr_tmpl->registration_lock); in __core_scsi3_add_registration()
1099 * Drop configfs group dependency reference and deve->pr_kref in __core_scsi3_add_registration()
1103 deve = pr_reg_tmp->pr_reg_deve; in __core_scsi3_add_registration()
1105 set_bit(DEF_PR_REG_ACTIVE, &deve->deve_flags); in __core_scsi3_add_registration()
1107 pr_reg_tmp->pr_reg_deve = NULL; in __core_scsi3_add_registration()
1113 * Drop deve->pr_kref obtained in __core_scsi3_do_alloc_registration() in __core_scsi3_add_registration()
1116 deve = pr_reg->pr_reg_deve; in __core_scsi3_add_registration()
1118 set_bit(DEF_PR_REG_ACTIVE, &deve->deve_flags); in __core_scsi3_add_registration()
1119 kref_put(&deve->pr_kref, target_pr_kref_release); in __core_scsi3_add_registration()
1120 pr_reg->pr_reg_deve = NULL; in __core_scsi3_add_registration()
1144 return -EPERM; in core_scsi3_alloc_registration()
1156 struct t10_reservation *pr_tmpl = &dev->t10_pr; in __core_scsi3_locate_pr_reg()
1159 spin_lock(&pr_tmpl->registration_lock); in __core_scsi3_locate_pr_reg()
1161 &pr_tmpl->registration_list, pr_reg_list) { in __core_scsi3_locate_pr_reg()
1165 if (pr_reg->pr_reg_nacl != nacl) in __core_scsi3_locate_pr_reg()
1172 if (!pr_reg->isid_present_at_reg) { in __core_scsi3_locate_pr_reg()
1173 atomic_inc_mb(&pr_reg->pr_res_holders); in __core_scsi3_locate_pr_reg()
1174 spin_unlock(&pr_tmpl->registration_lock); in __core_scsi3_locate_pr_reg()
1178 * If the *pr_reg contains a fabric defined ISID for multi-value in __core_scsi3_locate_pr_reg()
1184 if (strcmp(isid, pr_reg->pr_reg_isid)) in __core_scsi3_locate_pr_reg()
1187 atomic_inc_mb(&pr_reg->pr_res_holders); in __core_scsi3_locate_pr_reg()
1188 spin_unlock(&pr_tmpl->registration_lock); in __core_scsi3_locate_pr_reg()
1191 spin_unlock(&pr_tmpl->registration_lock); in __core_scsi3_locate_pr_reg()
1201 struct se_portal_group *tpg = nacl->se_tpg; in core_scsi3_locate_pr_reg()
1205 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) { in core_scsi3_locate_pr_reg()
1206 tpg->se_tpg_tfo->sess_get_initiator_sid(sess, &buf[0], in core_scsi3_locate_pr_reg()
1216 atomic_dec_mb(&pr_reg->pr_res_holders); in core_scsi3_put_pr_reg()
1223 struct se_node_acl *nacl = pr_reg->pr_reg_nacl; in core_scsi3_check_implicit_release()
1227 spin_lock(&dev->dev_reservation_lock); in core_scsi3_check_implicit_release()
1228 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_check_implicit_release()
1230 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_check_implicit_release()
1235 * Perform an implicit RELEASE if the registration that in core_scsi3_check_implicit_release()
1243 * service action or REGISTER AND IGNORE EXISTING KEY in core_scsi3_check_implicit_release()
1244 * service action with the SERVICE ACTION RESERVATION KEY in core_scsi3_check_implicit_release()
1255 } else if (pr_reg->pr_reg_all_tg_pt && in core_scsi3_check_implicit_release()
1256 (!strcmp(pr_res_holder->pr_reg_nacl->initiatorname, in core_scsi3_check_implicit_release()
1257 pr_reg->pr_reg_nacl->initiatorname)) && in core_scsi3_check_implicit_release()
1258 (pr_res_holder->pr_res_key == pr_reg->pr_res_key)) { in core_scsi3_check_implicit_release()
1259 pr_err("SPC-3 PR: Unable to perform ALL_TG_PT=1" in core_scsi3_check_implicit_release()
1261 " key 0x%016Lx is present from another SCSI Initiator" in core_scsi3_check_implicit_release()
1262 " Port\n", pr_reg->pr_res_key); in core_scsi3_check_implicit_release()
1263 ret = -EPERM; in core_scsi3_check_implicit_release()
1265 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_check_implicit_release()
1275 __releases(&pr_tmpl->registration_lock) in __core_scsi3_free_registration()
1276 __acquires(&pr_tmpl->registration_lock) in __core_scsi3_free_registration()
1279 pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; in __core_scsi3_free_registration()
1280 struct t10_reservation *pr_tmpl = &dev->t10_pr; in __core_scsi3_free_registration()
1281 struct se_node_acl *nacl = pr_reg->pr_reg_nacl; in __core_scsi3_free_registration()
1285 lockdep_assert_held(&pr_tmpl->registration_lock); in __core_scsi3_free_registration()
1289 if (!list_empty(&pr_reg->pr_reg_list)) in __core_scsi3_free_registration()
1290 list_del(&pr_reg->pr_reg_list); in __core_scsi3_free_registration()
1298 spin_unlock(&pr_tmpl->registration_lock); in __core_scsi3_free_registration()
1302 * the last core_scsi3_put_pr_reg(pr_reg) will release this reference in __core_scsi3_free_registration()
1303 * count back to zero, and we release *pr_reg. in __core_scsi3_free_registration()
1305 while (atomic_read(&pr_reg->pr_res_holders) != 0) { in __core_scsi3_free_registration()
1306 pr_debug("SPC-3 PR [%s] waiting for pr_res_holders\n", in __core_scsi3_free_registration()
1307 tfo->fabric_name); in __core_scsi3_free_registration()
1312 deve = target_nacl_find_deve(nacl, pr_reg->pr_res_mapped_lun); in __core_scsi3_free_registration()
1314 clear_bit(DEF_PR_REG_ACTIVE, &deve->deve_flags); in __core_scsi3_free_registration()
1317 spin_lock(&pr_tmpl->registration_lock); in __core_scsi3_free_registration()
1318 pr_debug("SPC-3 PR [%s] Service Action: UNREGISTER Initiator" in __core_scsi3_free_registration()
1319 " Node: %s%s\n", tfo->fabric_name, in __core_scsi3_free_registration()
1320 pr_reg->pr_reg_nacl->initiatorname, in __core_scsi3_free_registration()
1322 pr_debug("SPC-3 PR [%s] for %s TCM Subsystem %s Object Target" in __core_scsi3_free_registration()
1323 " Port(s)\n", tfo->fabric_name, in __core_scsi3_free_registration()
1324 (pr_reg->pr_reg_all_tg_pt) ? "ALL" : "SINGLE", in __core_scsi3_free_registration()
1325 dev->transport->name); in __core_scsi3_free_registration()
1326 pr_debug("SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:" in __core_scsi3_free_registration()
1327 " 0x%08x\n", tfo->fabric_name, pr_reg->pr_res_key, in __core_scsi3_free_registration()
1328 pr_reg->pr_res_generation); in __core_scsi3_free_registration()
1331 pr_reg->pr_reg_deve = NULL; in __core_scsi3_free_registration()
1332 pr_reg->pr_reg_nacl = NULL; in __core_scsi3_free_registration()
1340 list_add_tail(&pr_reg->pr_reg_abort_list, preempt_and_abort_list); in __core_scsi3_free_registration()
1347 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_free_pr_reg_from_nacl()
1352 * release the reservation. in core_scsi3_free_pr_reg_from_nacl()
1354 spin_lock(&dev->dev_reservation_lock); in core_scsi3_free_pr_reg_from_nacl()
1355 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_free_pr_reg_from_nacl()
1357 (pr_res_holder->pr_reg_nacl == nacl)) { in core_scsi3_free_pr_reg_from_nacl()
1361 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_free_pr_reg_from_nacl()
1363 * Release any registration associated with the struct se_node_acl. in core_scsi3_free_pr_reg_from_nacl()
1365 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_free_pr_reg_from_nacl()
1370 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_free_pr_reg_from_nacl()
1372 if (pr_reg->pr_reg_nacl != nacl) in core_scsi3_free_pr_reg_from_nacl()
1377 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_free_pr_reg_from_nacl()
1383 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_free_all_registrations()
1386 spin_lock(&dev->dev_reservation_lock); in core_scsi3_free_all_registrations()
1387 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_free_all_registrations()
1389 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; in core_scsi3_free_all_registrations()
1393 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_free_all_registrations()
1395 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_free_all_registrations()
1397 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_free_all_registrations()
1401 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_free_all_registrations()
1403 spin_lock(&pr_tmpl->aptpl_reg_lock); in core_scsi3_free_all_registrations()
1404 list_for_each_entry_safe(pr_reg, pr_reg_tmp, &pr_tmpl->aptpl_reg_list, in core_scsi3_free_all_registrations()
1406 list_del(&pr_reg->pr_reg_aptpl_list); in core_scsi3_free_all_registrations()
1409 spin_unlock(&pr_tmpl->aptpl_reg_lock); in core_scsi3_free_all_registrations()
1414 return target_depend_item(&tpg->tpg_group.cg_item); in core_scsi3_tpg_depend_item()
1419 target_undepend_item(&tpg->tpg_group.cg_item); in core_scsi3_tpg_undepend_item()
1420 atomic_dec_mb(&tpg->tpg_pr_ref_count); in core_scsi3_tpg_undepend_item()
1425 if (nacl->dynamic_node_acl) in core_scsi3_nodeacl_depend_item()
1427 return target_depend_item(&nacl->acl_group.cg_item); in core_scsi3_nodeacl_depend_item()
1432 if (!nacl->dynamic_node_acl) in core_scsi3_nodeacl_undepend_item()
1433 target_undepend_item(&nacl->acl_group.cg_item); in core_scsi3_nodeacl_undepend_item()
1434 atomic_dec_mb(&nacl->acl_pr_ref_count); in core_scsi3_nodeacl_undepend_item()
1440 * For nacl->dynamic_node_acl=1 in core_scsi3_lunacl_depend_item()
1442 if (!se_deve->se_lun_acl) in core_scsi3_lunacl_depend_item()
1445 return target_depend_item(&se_deve->se_lun_acl->se_lun_group.cg_item); in core_scsi3_lunacl_depend_item()
1451 * For nacl->dynamic_node_acl=1 in core_scsi3_lunacl_undepend_item()
1453 if (!se_deve->se_lun_acl) { in core_scsi3_lunacl_undepend_item()
1454 kref_put(&se_deve->pr_kref, target_pr_kref_release); in core_scsi3_lunacl_undepend_item()
1458 target_undepend_item(&se_deve->se_lun_acl->se_lun_group.cg_item); in core_scsi3_lunacl_undepend_item()
1459 kref_put(&se_deve->pr_kref, target_pr_kref_release); in core_scsi3_lunacl_undepend_item()
1471 struct se_device *dev = cmd->se_dev; in core_scsi3_decode_spec_i_port()
1473 struct se_session *se_sess = cmd->se_sess; in core_scsi3_decode_spec_i_port()
1497 INIT_LIST_HEAD(&tidh_new->dest_list); in core_scsi3_decode_spec_i_port()
1498 tidh_new->dest_tpg = tpg; in core_scsi3_decode_spec_i_port()
1499 tidh_new->dest_node_acl = se_sess->se_node_acl; in core_scsi3_decode_spec_i_port()
1501 local_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev, in core_scsi3_decode_spec_i_port()
1502 se_sess->se_node_acl, cmd->se_lun, in core_scsi3_decode_spec_i_port()
1503 NULL, cmd->orig_fe_lun, l_isid, in core_scsi3_decode_spec_i_port()
1510 if (core_scsi3_lunacl_depend_item(local_pr_reg->pr_reg_deve)) { in core_scsi3_decode_spec_i_port()
1512 kref_put(&local_pr_reg->pr_reg_deve->pr_kref, in core_scsi3_decode_spec_i_port()
1518 tidh_new->dest_pr_reg = local_pr_reg; in core_scsi3_decode_spec_i_port()
1519 list_add_tail(&tidh_new->dest_list, &tid_dest_list); in core_scsi3_decode_spec_i_port()
1521 if (cmd->data_length < 28) { in core_scsi3_decode_spec_i_port()
1522 pr_warn("SPC-PR: Received PR OUT parameter list" in core_scsi3_decode_spec_i_port()
1523 " length too small: %u\n", cmd->data_length); in core_scsi3_decode_spec_i_port()
1541 if ((tpdl + 28) != cmd->data_length) { in core_scsi3_decode_spec_i_port()
1542 pr_err("SPC-3 PR: Illegal tpdl: %u + 28 byte header" in core_scsi3_decode_spec_i_port()
1544 cmd->data_length); in core_scsi3_decode_spec_i_port()
1561 spin_lock(&dev->se_port_lock); in core_scsi3_decode_spec_i_port()
1562 list_for_each_entry(tmp_lun, &dev->dev_sep_list, lun_dev_link) { in core_scsi3_decode_spec_i_port()
1563 tmp_tpg = tmp_lun->lun_tpg; in core_scsi3_decode_spec_i_port()
1569 if (tmp_tpg->proto_id != proto_ident) in core_scsi3_decode_spec_i_port()
1571 dest_rtpi = tmp_lun->lun_tpg->tpg_rtpi; in core_scsi3_decode_spec_i_port()
1583 if (tpg->se_tpg_tfo->sess_get_initiator_sid && in core_scsi3_decode_spec_i_port()
1584 dev->dev_attrib.enforce_pr_isids && in core_scsi3_decode_spec_i_port()
1586 …pr_warn("SPC-PR: enforce_pr_isids is set but a isid has not been sent in the SPEC_I_PT data for %s… in core_scsi3_decode_spec_i_port()
1589 spin_unlock(&dev->se_port_lock); in core_scsi3_decode_spec_i_port()
1593 atomic_inc_mb(&tmp_tpg->tpg_pr_ref_count); in core_scsi3_decode_spec_i_port()
1594 spin_unlock(&dev->se_port_lock); in core_scsi3_decode_spec_i_port()
1599 atomic_dec_mb(&tmp_tpg->tpg_pr_ref_count); in core_scsi3_decode_spec_i_port()
1608 mutex_lock(&tmp_tpg->acl_node_mutex); in core_scsi3_decode_spec_i_port()
1612 atomic_inc_mb(&dest_node_acl->acl_pr_ref_count); in core_scsi3_decode_spec_i_port()
1613 mutex_unlock(&tmp_tpg->acl_node_mutex); in core_scsi3_decode_spec_i_port()
1617 spin_lock(&dev->se_port_lock); in core_scsi3_decode_spec_i_port()
1623 " for dest_node_acl->acl_group\n"); in core_scsi3_decode_spec_i_port()
1624 atomic_dec_mb(&dest_node_acl->acl_pr_ref_count); in core_scsi3_decode_spec_i_port()
1631 pr_debug("SPC-3 PR SPEC_I_PT: Located %s Node: %s Port RTPI: %u\n", in core_scsi3_decode_spec_i_port()
1632 dest_tpg->se_tpg_tfo->fabric_name, in core_scsi3_decode_spec_i_port()
1633 dest_node_acl->initiatorname, dest_rtpi); in core_scsi3_decode_spec_i_port()
1635 spin_lock(&dev->se_port_lock); in core_scsi3_decode_spec_i_port()
1638 spin_unlock(&dev->se_port_lock); in core_scsi3_decode_spec_i_port()
1641 pr_err("SPC-3 PR SPEC_I_PT: Unable to locate" in core_scsi3_decode_spec_i_port()
1647 pr_debug("SPC-3 PR SPEC_I_PT: Got %s data_length: %u tpdl: %u" in core_scsi3_decode_spec_i_port()
1649 dest_tpg->se_tpg_tfo->fabric_name, cmd->data_length, in core_scsi3_decode_spec_i_port()
1653 pr_err("SPC-3 PR SPEC_I_PT: Illegal tid_len:" in core_scsi3_decode_spec_i_port()
1669 dest_tpg->se_tpg_tfo->fabric_name, in core_scsi3_decode_spec_i_port()
1681 kref_put(&dest_se_deve->pr_kref, target_pr_kref_release); in core_scsi3_decode_spec_i_port()
1688 pr_debug("SPC-3 PR SPEC_I_PT: Located %s Node: %s" in core_scsi3_decode_spec_i_port()
1690 dest_tpg->se_tpg_tfo->fabric_name, in core_scsi3_decode_spec_i_port()
1691 dest_node_acl->initiatorname, dest_se_deve->mapped_lun); in core_scsi3_decode_spec_i_port()
1705 tpdl -= tid_len; in core_scsi3_decode_spec_i_port()
1724 INIT_LIST_HEAD(&tidh_new->dest_list); in core_scsi3_decode_spec_i_port()
1725 tidh_new->dest_tpg = dest_tpg; in core_scsi3_decode_spec_i_port()
1726 tidh_new->dest_node_acl = dest_node_acl; in core_scsi3_decode_spec_i_port()
1727 tidh_new->dest_se_deve = dest_se_deve; in core_scsi3_decode_spec_i_port()
1745 dest_lun = dest_se_deve->se_lun; in core_scsi3_decode_spec_i_port()
1747 dest_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev, in core_scsi3_decode_spec_i_port()
1749 dest_se_deve->mapped_lun, iport_ptr, in core_scsi3_decode_spec_i_port()
1759 tidh_new->dest_pr_reg = dest_pr_reg; in core_scsi3_decode_spec_i_port()
1760 list_add_tail(&tidh_new->dest_list, &tid_dest_list); in core_scsi3_decode_spec_i_port()
1763 tpdl -= tid_len; in core_scsi3_decode_spec_i_port()
1775 * The SA Reservation Key from the PROUT is set for the in core_scsi3_decode_spec_i_port()
1784 dest_tpg = tidh->dest_tpg; in core_scsi3_decode_spec_i_port()
1785 dest_node_acl = tidh->dest_node_acl; in core_scsi3_decode_spec_i_port()
1786 dest_se_deve = tidh->dest_se_deve; in core_scsi3_decode_spec_i_port()
1787 dest_pr_reg = tidh->dest_pr_reg; in core_scsi3_decode_spec_i_port()
1789 list_del(&tidh->dest_list); in core_scsi3_decode_spec_i_port()
1795 __core_scsi3_add_registration(cmd->se_dev, dest_node_acl, in core_scsi3_decode_spec_i_port()
1798 pr_debug("SPC-3 PR [%s] SPEC_I_PT: Successfully" in core_scsi3_decode_spec_i_port()
1800 " %llu\n", dest_tpg->se_tpg_tfo->fabric_name, in core_scsi3_decode_spec_i_port()
1801 dest_node_acl->initiatorname, i_buf, (dest_se_deve) ? in core_scsi3_decode_spec_i_port()
1802 dest_se_deve->mapped_lun : 0); in core_scsi3_decode_spec_i_port()
1816 * For the failure case, release everything from tid_dest_list in core_scsi3_decode_spec_i_port()
1822 dest_tpg = tidh->dest_tpg; in core_scsi3_decode_spec_i_port()
1823 dest_node_acl = tidh->dest_node_acl; in core_scsi3_decode_spec_i_port()
1824 dest_se_deve = tidh->dest_se_deve; in core_scsi3_decode_spec_i_port()
1825 dest_pr_reg = tidh->dest_pr_reg; in core_scsi3_decode_spec_i_port()
1830 list_del(&tidh->dest_list); in core_scsi3_decode_spec_i_port()
1833 * Release any extra ALL_TG_PT=1 registrations for in core_scsi3_decode_spec_i_port()
1837 &dest_pr_reg->pr_reg_atp_list, in core_scsi3_decode_spec_i_port()
1839 list_del(&pr_reg_tmp->pr_reg_atp_mem_list); in core_scsi3_decode_spec_i_port()
1840 core_scsi3_lunacl_undepend_item(pr_reg_tmp->pr_reg_deve); in core_scsi3_decode_spec_i_port()
1868 spin_lock(&dev->dev_reservation_lock); in core_scsi3_update_aptpl_buf()
1869 spin_lock(&dev->t10_pr.registration_lock); in core_scsi3_update_aptpl_buf()
1873 list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, in core_scsi3_update_aptpl_buf()
1878 tpg = pr_reg->pr_reg_nacl->se_tpg; in core_scsi3_update_aptpl_buf()
1883 if (pr_reg->isid_present_at_reg) in core_scsi3_update_aptpl_buf()
1885 pr_reg->pr_reg_isid); in core_scsi3_update_aptpl_buf()
1890 if (dev->dev_pr_res_holder == pr_reg) { in core_scsi3_update_aptpl_buf()
1898 tpg->se_tpg_tfo->fabric_name, in core_scsi3_update_aptpl_buf()
1899 pr_reg->pr_reg_nacl->initiatorname, isid_buf, in core_scsi3_update_aptpl_buf()
1900 pr_reg->pr_res_key, pr_reg->pr_res_type, in core_scsi3_update_aptpl_buf()
1901 pr_reg->pr_res_scope, pr_reg->pr_reg_all_tg_pt, in core_scsi3_update_aptpl_buf()
1902 pr_reg->pr_res_mapped_lun); in core_scsi3_update_aptpl_buf()
1908 reg_count, tpg->se_tpg_tfo->fabric_name, in core_scsi3_update_aptpl_buf()
1909 pr_reg->pr_reg_nacl->initiatorname, isid_buf, in core_scsi3_update_aptpl_buf()
1910 pr_reg->pr_res_key, pr_reg->pr_reg_all_tg_pt, in core_scsi3_update_aptpl_buf()
1911 pr_reg->pr_res_mapped_lun); in core_scsi3_update_aptpl_buf()
1917 ret = -EMSGSIZE; in core_scsi3_update_aptpl_buf()
1927 " %d\n", tpg->se_tpg_tfo->fabric_name, in core_scsi3_update_aptpl_buf()
1928 tpg->se_tpg_tfo->tpg_get_wwn(tpg), in core_scsi3_update_aptpl_buf()
1929 tpg->se_tpg_tfo->tpg_get_tag(tpg), in core_scsi3_update_aptpl_buf()
1930 pr_reg->tg_pt_sep_rtpi, pr_reg->pr_aptpl_target_lun, in core_scsi3_update_aptpl_buf()
1936 ret = -EMSGSIZE; in core_scsi3_update_aptpl_buf()
1947 spin_unlock(&dev->t10_pr.registration_lock); in core_scsi3_update_aptpl_buf()
1948 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_update_aptpl_buf()
1957 struct t10_wwn *wwn = &dev->t10_wwn; in __core_scsi3_write_aptpl_to_file()
1966 &wwn->unit_serial[0]); in __core_scsi3_write_aptpl_to_file()
1968 return -ENOMEM; in __core_scsi3_write_aptpl_to_file()
1987 return (ret < 0) ? -EIO : 0; in __core_scsi3_write_aptpl_to_file()
2003 dev->t10_pr.pr_aptpl_active = 0; in core_scsi3_update_and_write_aptpl()
2004 pr_debug("SPC-3 PR: Set APTPL Bit Deactivated\n"); in core_scsi3_update_and_write_aptpl()
2025 pr_err("SPC-3 PR: Could not update APTPL\n"); in core_scsi3_update_and_write_aptpl()
2029 dev->t10_pr.pr_aptpl_active = 1; in core_scsi3_update_and_write_aptpl()
2031 pr_debug("SPC-3 PR: Set APTPL Bit Activated\n"); in core_scsi3_update_and_write_aptpl()
2039 struct se_session *se_sess = cmd->se_sess; in core_scsi3_emulate_pro_register()
2040 struct se_device *dev = cmd->se_dev; in core_scsi3_emulate_pro_register()
2041 struct se_lun *se_lun = cmd->se_lun; in core_scsi3_emulate_pro_register()
2044 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_emulate_pro_register()
2051 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); in core_scsi3_emulate_pro_register()
2054 se_tpg = se_sess->se_tpg; in core_scsi3_emulate_pro_register()
2056 if (se_tpg->se_tpg_tfo->sess_get_initiator_sid) { in core_scsi3_emulate_pro_register()
2057 se_tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, &isid_buf[0], in core_scsi3_emulate_pro_register()
2064 pr_reg = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess); in core_scsi3_emulate_pro_register()
2067 pr_warn("SPC-3 PR: Reservation Key non-zero" in core_scsi3_emulate_pro_register()
2083 if (core_scsi3_alloc_registration(cmd->se_dev, in core_scsi3_emulate_pro_register()
2084 se_sess->se_node_acl, cmd->se_lun, in core_scsi3_emulate_pro_register()
2085 NULL, cmd->orig_fe_lun, isid_ptr, in core_scsi3_emulate_pro_register()
2111 if ((register_type == REGISTER) && (res_key != pr_reg->pr_res_key)) { in core_scsi3_emulate_pro_register()
2112 pr_err("SPC-3 PR REGISTER: Received" in core_scsi3_emulate_pro_register()
2116 pr_reg->pr_res_key); in core_scsi3_emulate_pro_register()
2122 pr_err("SPC-3 PR REGISTER: SPEC_I_PT" in core_scsi3_emulate_pro_register()
2132 if (pr_reg->pr_reg_all_tg_pt && !all_tg_pt) { in core_scsi3_emulate_pro_register()
2133 pr_err("SPC-3 PR REGISTER: ALL_TG_PT=1" in core_scsi3_emulate_pro_register()
2141 * sa_res_key=1 Change Reservation Key for registered I_T Nexus. in core_scsi3_emulate_pro_register()
2149 pr_reg->pr_res_generation = core_scsi3_pr_generation(cmd->se_dev); in core_scsi3_emulate_pro_register()
2150 pr_reg->pr_res_key = sa_res_key; in core_scsi3_emulate_pro_register()
2151 pr_debug("SPC-3 PR [%s] REGISTER%s: Changed Reservation" in core_scsi3_emulate_pro_register()
2152 " Key for %s to: 0x%016Lx PRgeneration:" in core_scsi3_emulate_pro_register()
2153 " 0x%08x\n", cmd->se_tfo->fabric_name, in core_scsi3_emulate_pro_register()
2155 pr_reg->pr_reg_nacl->initiatorname, in core_scsi3_emulate_pro_register()
2156 pr_reg->pr_res_key, pr_reg->pr_res_generation); in core_scsi3_emulate_pro_register()
2160 * sa_res_key=0 Unregister Reservation Key for registered I_T Nexus. in core_scsi3_emulate_pro_register()
2162 type = pr_reg->pr_res_type; in core_scsi3_emulate_pro_register()
2163 pr_holder = core_scsi3_check_implicit_release(cmd->se_dev, in core_scsi3_emulate_pro_register()
2170 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_register()
2172 * Release all ALL_TG_PT=1 for the matching SCSI Initiator Port in core_scsi3_emulate_pro_register()
2175 if (pr_reg->pr_reg_all_tg_pt) { in core_scsi3_emulate_pro_register()
2177 &pr_tmpl->registration_list, in core_scsi3_emulate_pro_register()
2180 if (!pr_reg_p->pr_reg_all_tg_pt) in core_scsi3_emulate_pro_register()
2182 if (pr_reg_p->pr_res_key != res_key) in core_scsi3_emulate_pro_register()
2186 if (strcmp(pr_reg->pr_reg_nacl->initiatorname, in core_scsi3_emulate_pro_register()
2187 pr_reg_p->pr_reg_nacl->initiatorname)) in core_scsi3_emulate_pro_register()
2196 * Release the calling I_T Nexus registration now.. in core_scsi3_emulate_pro_register()
2198 __core_scsi3_free_registration(cmd->se_dev, pr_reg, NULL, 1); in core_scsi3_emulate_pro_register()
2216 &pr_tmpl->registration_list, in core_scsi3_emulate_pro_register()
2220 pr_reg_p->pr_reg_nacl, in core_scsi3_emulate_pro_register()
2221 pr_reg_p->pr_res_mapped_lun, in core_scsi3_emulate_pro_register()
2227 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_register()
2257 return "Unknown SPC-3 PR Type"; in core_scsi3_pr_dump_type()
2263 struct se_device *dev = cmd->se_dev; in core_scsi3_pro_reserve()
2264 struct se_session *se_sess = cmd->se_sess; in core_scsi3_pro_reserve()
2265 struct se_lun *se_lun = cmd->se_lun; in core_scsi3_pro_reserve()
2267 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_pro_reserve()
2272 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); in core_scsi3_pro_reserve()
2278 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, in core_scsi3_pro_reserve()
2281 pr_err("SPC-3 PR: Unable to locate" in core_scsi3_pro_reserve()
2291 * a) RESERVATION KEY set to the value of the reservation key that is in core_scsi3_pro_reserve()
2294 if (res_key != pr_reg->pr_res_key) { in core_scsi3_pro_reserve()
2295 pr_err("SPC-3 PR RESERVE: Received res_key: 0x%016Lx" in core_scsi3_pro_reserve()
2297 " 0x%016Lx\n", res_key, pr_reg->pr_res_key); in core_scsi3_pro_reserve()
2312 pr_err("SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope); in core_scsi3_pro_reserve()
2318 * struct se_device->dev_pr_res_holder in the form struct t10_pr_registration in core_scsi3_pro_reserve()
2321 spin_lock(&dev->dev_reservation_lock); in core_scsi3_pro_reserve()
2322 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_pro_reserve()
2335 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; in core_scsi3_pro_reserve()
2336 pr_err("SPC-3 PR: Attempted RESERVE from" in core_scsi3_pro_reserve()
2339 cmd->se_tfo->fabric_name, in core_scsi3_pro_reserve()
2340 se_sess->se_node_acl->initiatorname, in core_scsi3_pro_reserve()
2341 pr_res_nacl->se_tpg->se_tpg_tfo->fabric_name, in core_scsi3_pro_reserve()
2342 pr_res_holder->pr_reg_nacl->initiatorname); in core_scsi3_pro_reserve()
2344 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_reserve()
2355 if ((pr_res_holder->pr_res_type != type) || in core_scsi3_pro_reserve()
2356 (pr_res_holder->pr_res_scope != scope)) { in core_scsi3_pro_reserve()
2357 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; in core_scsi3_pro_reserve()
2358 pr_err("SPC-3 PR: Attempted RESERVE from" in core_scsi3_pro_reserve()
2362 cmd->se_tfo->fabric_name, in core_scsi3_pro_reserve()
2363 se_sess->se_node_acl->initiatorname, in core_scsi3_pro_reserve()
2364 pr_res_nacl->se_tpg->se_tpg_tfo->fabric_name, in core_scsi3_pro_reserve()
2365 pr_res_holder->pr_reg_nacl->initiatorname); in core_scsi3_pro_reserve()
2367 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_reserve()
2381 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_reserve()
2389 pr_reg->pr_res_scope = scope; in core_scsi3_pro_reserve()
2390 pr_reg->pr_res_type = type; in core_scsi3_pro_reserve()
2391 pr_reg->pr_res_holder = 1; in core_scsi3_pro_reserve()
2392 dev->dev_pr_res_holder = pr_reg; in core_scsi3_pro_reserve()
2395 pr_debug("SPC-3 PR [%s] Service Action: RESERVE created new" in core_scsi3_pro_reserve()
2397 cmd->se_tfo->fabric_name, core_scsi3_pr_dump_type(type), in core_scsi3_pro_reserve()
2398 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); in core_scsi3_pro_reserve()
2399 pr_debug("SPC-3 PR [%s] RESERVE Node: %s%s\n", in core_scsi3_pro_reserve()
2400 cmd->se_tfo->fabric_name, in core_scsi3_pro_reserve()
2401 se_sess->se_node_acl->initiatorname, in core_scsi3_pro_reserve()
2403 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_reserve()
2405 if (pr_tmpl->pr_aptpl_active) in core_scsi3_pro_reserve()
2406 core_scsi3_update_and_write_aptpl(cmd->se_dev, true); in core_scsi3_pro_reserve()
2427 pr_err("SPC-3 PR: Unknown Service Action RESERVE Type:" in core_scsi3_emulate_pro_reserve()
2440 const struct target_core_fabric_ops *tfo = se_nacl->se_tpg->se_tpg_tfo; in __core_scsi3_complete_pro_release()
2444 lockdep_assert_held(&dev->dev_reservation_lock); in __core_scsi3_complete_pro_release()
2448 * Go ahead and release the current PR reservation holder. in __core_scsi3_complete_pro_release()
2453 if (dev->dev_pr_res_holder) { in __core_scsi3_complete_pro_release()
2454 pr_res_type = dev->dev_pr_res_holder->pr_res_type; in __core_scsi3_complete_pro_release()
2455 pr_res_scope = dev->dev_pr_res_holder->pr_res_scope; in __core_scsi3_complete_pro_release()
2456 dev->dev_pr_res_holder->pr_res_type = 0; in __core_scsi3_complete_pro_release()
2457 dev->dev_pr_res_holder->pr_res_scope = 0; in __core_scsi3_complete_pro_release()
2458 dev->dev_pr_res_holder->pr_res_holder = 0; in __core_scsi3_complete_pro_release()
2459 dev->dev_pr_res_holder = NULL; in __core_scsi3_complete_pro_release()
2464 spin_lock(&dev->t10_pr.registration_lock); in __core_scsi3_complete_pro_release()
2465 list_del_init(&pr_reg->pr_reg_list); in __core_scsi3_complete_pro_release()
2469 * registered I_T nexus, then the device server shall also release the in __core_scsi3_complete_pro_release()
2472 if (!list_empty(&dev->t10_pr.registration_list) && in __core_scsi3_complete_pro_release()
2475 dev->dev_pr_res_holder = in __core_scsi3_complete_pro_release()
2476 list_entry(dev->t10_pr.registration_list.next, in __core_scsi3_complete_pro_release()
2478 dev->dev_pr_res_holder->pr_res_type = pr_res_type; in __core_scsi3_complete_pro_release()
2479 dev->dev_pr_res_holder->pr_res_scope = pr_res_scope; in __core_scsi3_complete_pro_release()
2480 dev->dev_pr_res_holder->pr_res_holder = 1; in __core_scsi3_complete_pro_release()
2482 spin_unlock(&dev->t10_pr.registration_lock); in __core_scsi3_complete_pro_release()
2484 if (!dev->dev_pr_res_holder) { in __core_scsi3_complete_pro_release()
2485 pr_debug("SPC-3 PR [%s] Service Action: %s RELEASE cleared" in __core_scsi3_complete_pro_release()
2487 tfo->fabric_name, (explicit) ? "explicit" : in __core_scsi3_complete_pro_release()
2489 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); in __core_scsi3_complete_pro_release()
2491 pr_debug("SPC-3 PR [%s] RELEASE Node: %s%s\n", in __core_scsi3_complete_pro_release()
2492 tfo->fabric_name, se_nacl->initiatorname, in __core_scsi3_complete_pro_release()
2497 pr_reg->pr_res_holder = pr_reg->pr_res_type = pr_reg->pr_res_scope = 0; in __core_scsi3_complete_pro_release()
2504 struct se_device *dev = cmd->se_dev; in core_scsi3_emulate_pro_release()
2505 struct se_session *se_sess = cmd->se_sess; in core_scsi3_emulate_pro_release()
2506 struct se_lun *se_lun = cmd->se_lun; in core_scsi3_emulate_pro_release()
2508 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_emulate_pro_release()
2512 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); in core_scsi3_emulate_pro_release()
2518 pr_reg = core_scsi3_locate_pr_reg(dev, se_sess->se_node_acl, se_sess); in core_scsi3_emulate_pro_release()
2520 pr_err("SPC-3 PR: Unable to locate" in core_scsi3_emulate_pro_release()
2521 " PR_REGISTERED *pr_reg for RELEASE\n"); in core_scsi3_emulate_pro_release()
2528 * reservation release request from a registered I_T nexus that is not a in core_scsi3_emulate_pro_release()
2532 * a) Not release the persistent reservation, if any; in core_scsi3_emulate_pro_release()
2536 spin_lock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_release()
2537 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_emulate_pro_release()
2542 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_release()
2548 * Release request from a registered I_T nexus that is not a in core_scsi3_emulate_pro_release()
2551 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_release()
2559 * release a persistent reservation. in core_scsi3_emulate_pro_release()
2562 * a PERSISTENT RESERVE OUT command with RELEASE service action through in core_scsi3_emulate_pro_release()
2566 * a) RESERVATION KEY field set to the value of the reservation key in core_scsi3_emulate_pro_release()
2569 if (res_key != pr_reg->pr_res_key) { in core_scsi3_emulate_pro_release()
2570 pr_err("SPC-3 PR RELEASE: Received res_key: 0x%016Lx" in core_scsi3_emulate_pro_release()
2572 " 0x%016Lx\n", res_key, pr_reg->pr_res_key); in core_scsi3_emulate_pro_release()
2573 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_release()
2583 if ((pr_res_holder->pr_res_type != type) || in core_scsi3_emulate_pro_release()
2584 (pr_res_holder->pr_res_scope != scope)) { in core_scsi3_emulate_pro_release()
2585 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; in core_scsi3_emulate_pro_release()
2586 pr_err("SPC-3 PR RELEASE: Attempted to release" in core_scsi3_emulate_pro_release()
2590 cmd->se_tfo->fabric_name, in core_scsi3_emulate_pro_release()
2591 se_sess->se_node_acl->initiatorname, in core_scsi3_emulate_pro_release()
2592 pr_res_nacl->se_tpg->se_tpg_tfo->fabric_name, in core_scsi3_emulate_pro_release()
2593 pr_res_holder->pr_reg_nacl->initiatorname); in core_scsi3_emulate_pro_release()
2595 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_release()
2600 * In response to a persistent reservation release request from the in core_scsi3_emulate_pro_release()
2602 * release by doing the following as an uninterrupted series of actions: in core_scsi3_emulate_pro_release()
2603 * a) Release the persistent reservation; in core_scsi3_emulate_pro_release()
2608 * the initiator port associated with every regis- in core_scsi3_emulate_pro_release()
2610 * RESERVE OUT command with RELEASE service action was received, in core_scsi3_emulate_pro_release()
2615 __core_scsi3_complete_pro_release(dev, se_sess->se_node_acl, in core_scsi3_emulate_pro_release()
2618 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_release()
2632 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_release()
2633 list_for_each_entry(pr_reg_p, &pr_tmpl->registration_list, in core_scsi3_emulate_pro_release()
2642 target_ua_allocate_lun(pr_reg_p->pr_reg_nacl, in core_scsi3_emulate_pro_release()
2643 pr_reg_p->pr_res_mapped_lun, in core_scsi3_emulate_pro_release()
2646 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_release()
2649 if (pr_tmpl->pr_aptpl_active) in core_scsi3_emulate_pro_release()
2650 core_scsi3_update_and_write_aptpl(cmd->se_dev, true); in core_scsi3_emulate_pro_release()
2660 struct se_device *dev = cmd->se_dev; in core_scsi3_emulate_pro_clear()
2662 struct se_session *se_sess = cmd->se_sess; in core_scsi3_emulate_pro_clear()
2663 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_emulate_pro_clear()
2670 pr_reg_n = core_scsi3_locate_pr_reg(cmd->se_dev, in core_scsi3_emulate_pro_clear()
2671 se_sess->se_node_acl, se_sess); in core_scsi3_emulate_pro_clear()
2673 pr_err("SPC-3 PR: Unable to locate" in core_scsi3_emulate_pro_clear()
2680 * Any application client may release the persistent reservation and in core_scsi3_emulate_pro_clear()
2685 * a) RESERVATION KEY field set to the value of the reservation key in core_scsi3_emulate_pro_clear()
2688 if (res_key != pr_reg_n->pr_res_key) { in core_scsi3_emulate_pro_clear()
2689 pr_err("SPC-3 PR REGISTER: Received" in core_scsi3_emulate_pro_clear()
2692 " 0x%016Lx\n", res_key, pr_reg_n->pr_res_key); in core_scsi3_emulate_pro_clear()
2697 * a) Release the persistent reservation, if any; in core_scsi3_emulate_pro_clear()
2699 spin_lock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_clear()
2700 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_emulate_pro_clear()
2702 struct se_node_acl *pr_res_nacl = pr_res_holder->pr_reg_nacl; in core_scsi3_emulate_pro_clear()
2706 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_clear()
2710 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_clear()
2712 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_emulate_pro_clear()
2715 pr_reg_nacl = pr_reg->pr_reg_nacl; in core_scsi3_emulate_pro_clear()
2716 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; in core_scsi3_emulate_pro_clear()
2730 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_clear()
2732 pr_debug("SPC-3 PR [%s] Service Action: CLEAR complete\n", in core_scsi3_emulate_pro_clear()
2733 cmd->se_tfo->fabric_name); in core_scsi3_emulate_pro_clear()
2735 core_scsi3_update_and_write_aptpl(cmd->se_dev, false); in core_scsi3_emulate_pro_clear()
2749 struct se_node_acl *nacl = pr_reg->pr_reg_nacl; in __core_scsi3_complete_pro_preempt()
2750 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; in __core_scsi3_complete_pro_preempt()
2753 lockdep_assert_held(&dev->dev_reservation_lock); in __core_scsi3_complete_pro_preempt()
2757 * Do an implicit RELEASE of the existing reservation. in __core_scsi3_complete_pro_preempt()
2759 if (dev->dev_pr_res_holder) in __core_scsi3_complete_pro_preempt()
2761 dev->dev_pr_res_holder, 0, 0); in __core_scsi3_complete_pro_preempt()
2763 dev->dev_pr_res_holder = pr_reg; in __core_scsi3_complete_pro_preempt()
2764 pr_reg->pr_res_holder = 1; in __core_scsi3_complete_pro_preempt()
2765 pr_reg->pr_res_type = type; in __core_scsi3_complete_pro_preempt()
2766 pr_reg->pr_res_scope = scope; in __core_scsi3_complete_pro_preempt()
2768 pr_debug("SPC-3 PR [%s] Service Action: PREEMPT%s created new" in __core_scsi3_complete_pro_preempt()
2770 tfo->fabric_name, (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : "", in __core_scsi3_complete_pro_preempt()
2772 (pr_reg->pr_reg_all_tg_pt) ? 1 : 0); in __core_scsi3_complete_pro_preempt()
2773 pr_debug("SPC-3 PR [%s] PREEMPT%s from Node: %s%s\n", in __core_scsi3_complete_pro_preempt()
2774 tfo->fabric_name, (preempt_type == PREEMPT_AND_ABORT) ? "_AND_ABORT" : "", in __core_scsi3_complete_pro_preempt()
2775 nacl->initiatorname, i_buf); in __core_scsi3_complete_pro_preempt()
2782 list_add_tail(&pr_reg->pr_reg_abort_list, in __core_scsi3_complete_pro_preempt()
2795 list_del(&pr_reg->pr_reg_abort_list); in core_scsi3_release_preempt_and_abort()
2798 if (pr_reg->pr_res_holder) { in core_scsi3_release_preempt_and_abort()
2799 pr_warn("pr_reg->pr_res_holder still set\n"); in core_scsi3_release_preempt_and_abort()
2803 pr_reg->pr_reg_deve = NULL; in core_scsi3_release_preempt_and_abort()
2804 pr_reg->pr_reg_nacl = NULL; in core_scsi3_release_preempt_and_abort()
2813 struct se_device *dev = cmd->se_dev; in core_scsi3_pro_preempt()
2815 struct se_session *se_sess = cmd->se_sess; in core_scsi3_pro_preempt()
2818 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_pro_preempt()
2827 pr_reg_n = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, in core_scsi3_pro_preempt()
2830 pr_err("SPC-3 PR: Unable to locate" in core_scsi3_pro_preempt()
2835 if (pr_reg_n->pr_res_key != res_key) { in core_scsi3_pro_preempt()
2840 pr_err("SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope); in core_scsi3_pro_preempt()
2845 spin_lock(&dev->dev_reservation_lock); in core_scsi3_pro_preempt()
2846 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_pro_preempt()
2848 ((pr_res_holder->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || in core_scsi3_pro_preempt()
2849 (pr_res_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG))) in core_scsi3_pro_preempt()
2853 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_preempt()
2860 * If the SERVICE ACTION RESERVATION KEY field does not identify a in core_scsi3_pro_preempt()
2866 if (!pr_res_holder || (pr_res_holder->pr_res_key != sa_res_key)) { in core_scsi3_pro_preempt()
2868 * No existing or SA Reservation Key matching reservations.. in core_scsi3_pro_preempt()
2871 * allowed to be processed without a matching SA Reservation Key in core_scsi3_pro_preempt()
2873 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_pro_preempt()
2875 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_pro_preempt()
2879 * key. in core_scsi3_pro_preempt()
2882 * specified by the SERVICE ACTION RESERVATION KEY in core_scsi3_pro_preempt()
2894 if (pr_reg->pr_res_key != sa_res_key) in core_scsi3_pro_preempt()
2899 pr_reg_nacl = pr_reg->pr_reg_nacl; in core_scsi3_pro_preempt()
2900 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; in core_scsi3_pro_preempt()
2910 * For a ZERO SA Reservation key, release in core_scsi3_pro_preempt()
2912 * release of active persistent reservation. in core_scsi3_pro_preempt()
2914 * For a non-ZERO SA Reservation key, only in core_scsi3_pro_preempt()
2915 * release the matching reservation key from in core_scsi3_pro_preempt()
2919 (pr_reg->pr_res_key != sa_res_key)) in core_scsi3_pro_preempt()
2927 pr_reg_nacl = pr_reg->pr_reg_nacl; in core_scsi3_pro_preempt()
2928 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; in core_scsi3_pro_preempt()
2938 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_pro_preempt()
2942 * RESERVATION KEY field to a value that does not match any in core_scsi3_pro_preempt()
2943 * registered reservation key, then the device server shall in core_scsi3_pro_preempt()
2947 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_preempt()
2953 * with a zero SA rservation key, preempt the existing in core_scsi3_pro_preempt()
2962 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_preempt()
2965 * SPC-4 5.12.11.2.6 Preempting and aborting in core_scsi3_pro_preempt()
2967 * for all I_T nexuses that are registered with the non-zero in core_scsi3_pro_preempt()
2968 * SERVICE ACTION RESERVATION KEY value, without regard for in core_scsi3_pro_preempt()
2970 * reservation. If the SERVICE ACTION RESERVATION KEY field is in core_scsi3_pro_preempt()
2982 if (pr_tmpl->pr_aptpl_active) in core_scsi3_pro_preempt()
2983 core_scsi3_update_and_write_aptpl(cmd->se_dev, true); in core_scsi3_pro_preempt()
2986 core_scsi3_pr_generation(cmd->se_dev); in core_scsi3_pro_preempt()
2990 * The PREEMPTing SA reservation key matches that of the in core_scsi3_pro_preempt()
3001 * SERVICE ACTION RESERVATION KEY value equal to the in core_scsi3_pro_preempt()
3002 * persistent reservation holder's reservation key that in core_scsi3_pro_preempt()
3008 prh_type = pr_res_holder->pr_res_type; in core_scsi3_pro_preempt()
3009 prh_scope = pr_res_holder->pr_res_scope; in core_scsi3_pro_preempt()
3011 * If the SERVICE ACTION RESERVATION KEY field identifies a in core_scsi3_pro_preempt()
3016 * a) Release the persistent reservation for the holder in core_scsi3_pro_preempt()
3017 * identified by the SERVICE ACTION RESERVATION KEY field; in core_scsi3_pro_preempt()
3021 pr_res_holder->pr_reg_nacl, in core_scsi3_pro_preempt()
3022 dev->dev_pr_res_holder, 0, 0); in core_scsi3_pro_preempt()
3025 * by the SERVICE ACTION RESERVATION KEY field, except the in core_scsi3_pro_preempt()
3028 * is present and the SERVICE ACTION RESERVATION KEY field in core_scsi3_pro_preempt()
3033 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_pro_preempt()
3035 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_pro_preempt()
3041 if (sa_res_key && pr_reg->pr_res_key != sa_res_key) in core_scsi3_pro_preempt()
3044 pr_reg_nacl = pr_reg->pr_reg_nacl; in core_scsi3_pro_preempt()
3045 pr_res_mapped_lun = pr_reg->pr_res_mapped_lun; in core_scsi3_pro_preempt()
3058 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_pro_preempt()
3070 * whose reservation key was not removed, except for the I_T in core_scsi3_pro_preempt()
3080 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_pro_preempt()
3082 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_pro_preempt()
3088 target_ua_allocate_lun(pr_reg->pr_reg_nacl, in core_scsi3_pro_preempt()
3089 pr_reg->pr_res_mapped_lun, 0x2A, in core_scsi3_pro_preempt()
3092 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_pro_preempt()
3094 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pro_preempt()
3101 * release every registration in the list (which have already in core_scsi3_pro_preempt()
3111 if (pr_tmpl->pr_aptpl_active) in core_scsi3_pro_preempt()
3112 core_scsi3_update_and_write_aptpl(cmd->se_dev, true); in core_scsi3_pro_preempt()
3115 core_scsi3_pr_generation(cmd->se_dev); in core_scsi3_pro_preempt()
3133 pr_err("SPC-3 PR: Unknown Service Action PREEMPT%s" in core_scsi3_emulate_pro_preempt()
3144 struct se_session *se_sess = cmd->se_sess; in core_scsi3_emulate_pro_register_and_move()
3145 struct se_device *dev = cmd->se_dev; in core_scsi3_emulate_pro_register_and_move()
3147 struct se_lun *se_lun = cmd->se_lun, *tmp_lun; in core_scsi3_emulate_pro_register_and_move()
3152 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_emulate_pro_register_and_move()
3163 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); in core_scsi3_emulate_pro_register_and_move()
3167 se_tpg = se_sess->se_tpg; in core_scsi3_emulate_pro_register_and_move()
3168 tf_ops = se_tpg->se_tpg_tfo; in core_scsi3_emulate_pro_register_and_move()
3170 * Follow logic from spc4r17 Section 5.7.8, Table 50 -- in core_scsi3_emulate_pro_register_and_move()
3175 pr_reg = core_scsi3_locate_pr_reg(cmd->se_dev, se_sess->se_node_acl, in core_scsi3_emulate_pro_register_and_move()
3178 pr_err("SPC-3 PR: Unable to locate PR_REGISTERED" in core_scsi3_emulate_pro_register_and_move()
3183 * The provided reservation key much match the existing reservation key in core_scsi3_emulate_pro_register_and_move()
3186 if (res_key != pr_reg->pr_res_key) { in core_scsi3_emulate_pro_register_and_move()
3187 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Received" in core_scsi3_emulate_pro_register_and_move()
3189 " res_key: 0x%016Lx\n", res_key, pr_reg->pr_res_key); in core_scsi3_emulate_pro_register_and_move()
3194 * The service active reservation key needs to be non zero in core_scsi3_emulate_pro_register_and_move()
3197 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Received zero" in core_scsi3_emulate_pro_register_and_move()
3219 if ((tid_len + 24) != cmd->data_length) { in core_scsi3_emulate_pro_register_and_move()
3220 pr_err("SPC-3 PR: Illegal tid_len: %u + 24 byte header" in core_scsi3_emulate_pro_register_and_move()
3222 cmd->data_length); in core_scsi3_emulate_pro_register_and_move()
3227 spin_lock(&dev->se_port_lock); in core_scsi3_emulate_pro_register_and_move()
3228 list_for_each_entry(tmp_lun, &dev->dev_sep_list, lun_dev_link) { in core_scsi3_emulate_pro_register_and_move()
3229 if (tmp_lun->lun_tpg->tpg_rtpi != rtpi) in core_scsi3_emulate_pro_register_and_move()
3231 dest_se_tpg = tmp_lun->lun_tpg; in core_scsi3_emulate_pro_register_and_move()
3232 dest_tf_ops = dest_se_tpg->se_tpg_tfo; in core_scsi3_emulate_pro_register_and_move()
3236 atomic_inc_mb(&dest_se_tpg->tpg_pr_ref_count); in core_scsi3_emulate_pro_register_and_move()
3237 spin_unlock(&dev->se_port_lock); in core_scsi3_emulate_pro_register_and_move()
3242 atomic_dec_mb(&dest_se_tpg->tpg_pr_ref_count); in core_scsi3_emulate_pro_register_and_move()
3247 spin_lock(&dev->se_port_lock); in core_scsi3_emulate_pro_register_and_move()
3250 spin_unlock(&dev->se_port_lock); in core_scsi3_emulate_pro_register_and_move()
3253 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate" in core_scsi3_emulate_pro_register_and_move()
3267 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Extracted Protocol Identifier:" in core_scsi3_emulate_pro_register_and_move()
3270 if (proto_ident != dest_se_tpg->proto_id) { in core_scsi3_emulate_pro_register_and_move()
3271 pr_err("SPC-3 PR REGISTER_AND_MOVE: Received" in core_scsi3_emulate_pro_register_and_move()
3274 dest_se_tpg->proto_id, in core_scsi3_emulate_pro_register_and_move()
3275 dest_tf_ops->fabric_name); in core_scsi3_emulate_pro_register_and_move()
3282 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate" in core_scsi3_emulate_pro_register_and_move()
3291 pr_debug("SPC-3 PR [%s] Extracted initiator %s identifier: %s" in core_scsi3_emulate_pro_register_and_move()
3292 " %s\n", dest_tf_ops->fabric_name, (iport_ptr != NULL) ? in core_scsi3_emulate_pro_register_and_move()
3299 * be terminated with CHECK CONDITION status, with the sense key set to in core_scsi3_emulate_pro_register_and_move()
3303 pr_reg_nacl = pr_reg->pr_reg_nacl; in core_scsi3_emulate_pro_register_and_move()
3305 pr_reg_nacl->initiatorname)) ? 1 : 0; in core_scsi3_emulate_pro_register_and_move()
3309 if (!iport_ptr || !pr_reg->isid_present_at_reg) { in core_scsi3_emulate_pro_register_and_move()
3310 pr_err("SPC-3 PR REGISTER_AND_MOVE: TransportID: %s" in core_scsi3_emulate_pro_register_and_move()
3312 pr_reg_nacl->initiatorname); in core_scsi3_emulate_pro_register_and_move()
3316 if (!strcmp(iport_ptr, pr_reg->pr_reg_isid)) { in core_scsi3_emulate_pro_register_and_move()
3317 pr_err("SPC-3 PR REGISTER_AND_MOVE: TransportID: %s %s" in core_scsi3_emulate_pro_register_and_move()
3319 initiator_str, iport_ptr, pr_reg_nacl->initiatorname, in core_scsi3_emulate_pro_register_and_move()
3320 pr_reg->pr_reg_isid); in core_scsi3_emulate_pro_register_and_move()
3328 mutex_lock(&dest_se_tpg->acl_node_mutex); in core_scsi3_emulate_pro_register_and_move()
3332 atomic_inc_mb(&dest_node_acl->acl_pr_ref_count); in core_scsi3_emulate_pro_register_and_move()
3333 mutex_unlock(&dest_se_tpg->acl_node_mutex); in core_scsi3_emulate_pro_register_and_move()
3337 " TransportID%s\n", dest_tf_ops->fabric_name, in core_scsi3_emulate_pro_register_and_move()
3346 atomic_dec_mb(&dest_node_acl->acl_pr_ref_count); in core_scsi3_emulate_pro_register_and_move()
3352 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Found %s dest_node_acl:" in core_scsi3_emulate_pro_register_and_move()
3353 " %s from TransportID\n", dest_tf_ops->fabric_name, in core_scsi3_emulate_pro_register_and_move()
3354 dest_node_acl->initiatorname); in core_scsi3_emulate_pro_register_and_move()
3363 " %hu\n", dest_tf_ops->fabric_name, rtpi); in core_scsi3_emulate_pro_register_and_move()
3370 kref_put(&dest_se_deve->pr_kref, target_pr_kref_release); in core_scsi3_emulate_pro_register_and_move()
3376 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Located %s node %s LUN" in core_scsi3_emulate_pro_register_and_move()
3377 " ACL for dest_se_deve->mapped_lun: %llu\n", in core_scsi3_emulate_pro_register_and_move()
3378 dest_tf_ops->fabric_name, dest_node_acl->initiatorname, in core_scsi3_emulate_pro_register_and_move()
3379 dest_se_deve->mapped_lun); in core_scsi3_emulate_pro_register_and_move()
3385 spin_lock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3386 pr_res_holder = dev->dev_pr_res_holder; in core_scsi3_emulate_pro_register_and_move()
3388 pr_warn("SPC-3 PR REGISTER_AND_MOVE: No reservation" in core_scsi3_emulate_pro_register_and_move()
3390 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3397 * From spc4r17 section 5.7.8 Table 50 -- in core_scsi3_emulate_pro_register_and_move()
3401 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Calling I_T" in core_scsi3_emulate_pro_register_and_move()
3403 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3412 * Write Exclusive - All Registrants type or Exclusive Access - in core_scsi3_emulate_pro_register_and_move()
3416 if ((pr_res_holder->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || in core_scsi3_emulate_pro_register_and_move()
3417 (pr_res_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) { in core_scsi3_emulate_pro_register_and_move()
3418 pr_warn("SPC-3 PR REGISTER_AND_MOVE: Unable to move" in core_scsi3_emulate_pro_register_and_move()
3420 core_scsi3_pr_dump_type(pr_res_holder->pr_res_type)); in core_scsi3_emulate_pro_register_and_move()
3421 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3425 pr_res_nacl = pr_res_holder->pr_reg_nacl; in core_scsi3_emulate_pro_register_and_move()
3429 type = pr_res_holder->pr_res_type; in core_scsi3_emulate_pro_register_and_move()
3430 scope = pr_res_holder->pr_res_type; in core_scsi3_emulate_pro_register_and_move()
3432 * c) Associate the reservation key specified in the SERVICE ACTION in core_scsi3_emulate_pro_register_and_move()
3433 * RESERVATION KEY field with the I_T nexus specified as the in core_scsi3_emulate_pro_register_and_move()
3442 * d) Register the reservation key specified in the SERVICE ACTION in core_scsi3_emulate_pro_register_and_move()
3443 * RESERVATION KEY field; in core_scsi3_emulate_pro_register_and_move()
3447 * reservation key or a different reservation key. in core_scsi3_emulate_pro_register_and_move()
3452 struct se_lun *dest_lun = dest_se_deve->se_lun; in core_scsi3_emulate_pro_register_and_move()
3454 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3455 if (core_scsi3_alloc_registration(cmd->se_dev, dest_node_acl, in core_scsi3_emulate_pro_register_and_move()
3456 dest_lun, dest_se_deve, dest_se_deve->mapped_lun, in core_scsi3_emulate_pro_register_and_move()
3461 spin_lock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3467 * e) Retain the reservation key specified in the SERVICE ACTION in core_scsi3_emulate_pro_register_and_move()
3468 * RESERVATION KEY field and associated information; in core_scsi3_emulate_pro_register_and_move()
3470 dest_pr_reg->pr_res_key = sa_res_key; in core_scsi3_emulate_pro_register_and_move()
3473 * f) Release the persistent reservation for the persistent reservation in core_scsi3_emulate_pro_register_and_move()
3477 dev->dev_pr_res_holder, 0, 0); in core_scsi3_emulate_pro_register_and_move()
3483 dev->dev_pr_res_holder = dest_pr_reg; in core_scsi3_emulate_pro_register_and_move()
3484 dest_pr_reg->pr_res_holder = 1; in core_scsi3_emulate_pro_register_and_move()
3485 dest_pr_reg->pr_res_type = type; in core_scsi3_emulate_pro_register_and_move()
3486 pr_reg->pr_res_scope = scope; in core_scsi3_emulate_pro_register_and_move()
3492 dest_pr_reg->pr_res_generation = pr_tmpl->pr_generation++; in core_scsi3_emulate_pro_register_and_move()
3493 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_emulate_pro_register_and_move()
3495 pr_debug("SPC-3 PR [%s] Service Action: REGISTER_AND_MOVE" in core_scsi3_emulate_pro_register_and_move()
3497 " %hu PRGeneration: 0x%08x\n", dest_tf_ops->fabric_name, in core_scsi3_emulate_pro_register_and_move()
3499 dest_pr_reg->pr_res_generation); in core_scsi3_emulate_pro_register_and_move()
3500 pr_debug("SPC-3 PR Successfully moved reservation from" in core_scsi3_emulate_pro_register_and_move()
3501 " %s Fabric Node: %s%s -> %s Fabric Node: %s %s\n", in core_scsi3_emulate_pro_register_and_move()
3502 tf_ops->fabric_name, pr_reg_nacl->initiatorname, in core_scsi3_emulate_pro_register_and_move()
3503 i_buf, dest_tf_ops->fabric_name, in core_scsi3_emulate_pro_register_and_move()
3504 dest_node_acl->initiatorname, (iport_ptr != NULL) ? in core_scsi3_emulate_pro_register_and_move()
3507 * It is now safe to release configfs group dependencies for destination in core_scsi3_emulate_pro_register_and_move()
3518 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_register_and_move()
3520 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_emulate_pro_register_and_move()
3524 core_scsi3_update_and_write_aptpl(cmd->se_dev, aptpl); in core_scsi3_emulate_pro_register_and_move()
3546 struct exec_cmd_ops *ops = cmd->protocol_data; in target_try_pr_out_pt()
3548 if (!cmd->se_sess || !cmd->se_lun) { in target_try_pr_out_pt()
3549 pr_err("SPC-3 PR: se_sess || struct se_lun is NULL!\n"); in target_try_pr_out_pt()
3553 if (!ops->execute_pr_out) { in target_try_pr_out_pt()
3554 …pr_err("SPC-3 PR: Device has been configured for PR passthrough but it's not supported by the back… in target_try_pr_out_pt()
3561 …pr_err("SPC-3 PR: PRO_REGISTER_AND_MOVE and PRO_REPLACE_LOST_RESERVATION are not supported by PR p… in target_try_pr_out_pt()
3566 pr_err("SPC-3 PR: SPEC_I_PT and ALL_TG_PT are not supported by PR passthrough.\n"); in target_try_pr_out_pt()
3570 return ops->execute_pr_out(cmd, sa, res_key, sa_res_key, type, aptpl); in target_try_pr_out_pt()
3579 struct se_device *dev = cmd->se_dev; in target_scsi3_emulate_pr_out()
3580 unsigned char *cdb = &cmd->t_task_cdb[0]; in target_scsi3_emulate_pr_out()
3596 if (cmd->se_dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) { in target_scsi3_emulate_pr_out()
3598 " SPC-2 reservation is held, returning" in target_scsi3_emulate_pr_out()
3607 if (!cmd->se_sess) in target_scsi3_emulate_pr_out()
3610 if (cmd->data_length < 24) { in target_scsi3_emulate_pr_out()
3611 pr_warn("SPC-PR: Received PR OUT parameter list" in target_scsi3_emulate_pr_out()
3612 " length too small: %u\n", cmd->data_length); in target_scsi3_emulate_pr_out()
3646 * write-out, go ahead and propigate aptpl=1 down now. in target_scsi3_emulate_pr_out()
3648 if (dev->dev_attrib.force_pr_aptpl) in target_scsi3_emulate_pr_out()
3666 * the sense key set to ILLEGAL REQUEST, and the additional sense in target_scsi3_emulate_pr_out()
3670 (cmd->data_length != 24)) { in target_scsi3_emulate_pr_out()
3671 pr_warn("SPC-PR: Received PR OUT illegal parameter" in target_scsi3_emulate_pr_out()
3672 " list length: %u\n", cmd->data_length); in target_scsi3_emulate_pr_out()
3676 if (dev->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) { in target_scsi3_emulate_pr_out()
3737 struct se_device *dev = cmd->se_dev; in core_scsi3_pri_read_keys()
3742 if (cmd->data_length < 8) { in core_scsi3_pri_read_keys()
3744 " too small\n", cmd->data_length); in core_scsi3_pri_read_keys()
3752 put_unaligned_be32(dev->t10_pr.pr_generation, buf); in core_scsi3_pri_read_keys()
3754 spin_lock(&dev->t10_pr.registration_lock); in core_scsi3_pri_read_keys()
3755 list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, in core_scsi3_pri_read_keys()
3759 * next reservation key list descriptor. in core_scsi3_pri_read_keys()
3761 if (off + 8 <= cmd->data_length) { in core_scsi3_pri_read_keys()
3762 put_unaligned_be64(pr_reg->pr_res_key, &buf[off]); in core_scsi3_pri_read_keys()
3768 * the Reservation key list. The contents of the ADDITIONAL in core_scsi3_pri_read_keys()
3773 spin_unlock(&dev->t10_pr.registration_lock); in core_scsi3_pri_read_keys()
3791 struct se_device *dev = cmd->se_dev; in core_scsi3_pri_read_reservation()
3797 if (cmd->data_length < 8) { in core_scsi3_pri_read_reservation()
3799 " too small\n", cmd->data_length); in core_scsi3_pri_read_reservation()
3807 put_unaligned_be32(dev->t10_pr.pr_generation, &buf[0]); in core_scsi3_pri_read_reservation()
3809 spin_lock(&dev->dev_reservation_lock); in core_scsi3_pri_read_reservation()
3810 pr_reg = dev->dev_pr_res_holder; in core_scsi3_pri_read_reservation()
3818 if (cmd->data_length < 22) in core_scsi3_pri_read_reservation()
3822 * Set the Reservation key. in core_scsi3_pri_read_reservation()
3825 * A persistent reservation holder has its reservation key in core_scsi3_pri_read_reservation()
3830 * - All Registrants or Exclusive Access ­ All Regitrants, in core_scsi3_pri_read_reservation()
3831 * the reservation key shall be set to zero; or in core_scsi3_pri_read_reservation()
3833 * reservation key shall be set to the registered in core_scsi3_pri_read_reservation()
3834 * reservation key for the I_T nexus that holds the in core_scsi3_pri_read_reservation()
3837 if ((pr_reg->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG) || in core_scsi3_pri_read_reservation()
3838 (pr_reg->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG)) in core_scsi3_pri_read_reservation()
3841 pr_res_key = pr_reg->pr_res_key; in core_scsi3_pri_read_reservation()
3847 buf[21] = (pr_reg->pr_res_scope & 0xf0) | in core_scsi3_pri_read_reservation()
3848 (pr_reg->pr_res_type & 0x0f); in core_scsi3_pri_read_reservation()
3854 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pri_read_reservation()
3868 struct se_device *dev = cmd->se_dev; in core_scsi3_pri_report_capabilities()
3869 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_pri_report_capabilities()
3873 if (cmd->data_length < 6) { in core_scsi3_pri_report_capabilities()
3875 " %u too small\n", cmd->data_length); in core_scsi3_pri_report_capabilities()
3900 if (pr_tmpl->pr_aptpl_active) in core_scsi3_pri_report_capabilities()
3927 struct se_device *dev = cmd->se_dev; in core_scsi3_pri_read_full_status()
3931 struct t10_reservation *pr_tmpl = &dev->t10_pr; in core_scsi3_pri_read_full_status()
3939 if (cmd->data_length < 8) { in core_scsi3_pri_read_full_status()
3941 " too small\n", cmd->data_length); in core_scsi3_pri_read_full_status()
3949 put_unaligned_be32(dev->t10_pr.pr_generation, &buf[0]); in core_scsi3_pri_read_full_status()
3951 spin_lock(&dev->dev_reservation_lock); in core_scsi3_pri_read_full_status()
3952 if (dev->dev_pr_res_holder) { in core_scsi3_pri_read_full_status()
3953 struct t10_pr_registration *pr_holder = dev->dev_pr_res_holder; in core_scsi3_pri_read_full_status()
3955 if (pr_holder->pr_res_type == PR_TYPE_WRITE_EXCLUSIVE_ALLREG || in core_scsi3_pri_read_full_status()
3956 pr_holder->pr_res_type == PR_TYPE_EXCLUSIVE_ACCESS_ALLREG) { in core_scsi3_pri_read_full_status()
3958 pr_res_type = pr_holder->pr_res_type; in core_scsi3_pri_read_full_status()
3959 pr_res_scope = pr_holder->pr_res_scope; in core_scsi3_pri_read_full_status()
3962 spin_unlock(&dev->dev_reservation_lock); in core_scsi3_pri_read_full_status()
3964 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_pri_read_full_status()
3966 &pr_tmpl->registration_list, pr_reg_list) { in core_scsi3_pri_read_full_status()
3968 se_nacl = pr_reg->pr_reg_nacl; in core_scsi3_pri_read_full_status()
3969 se_tpg = pr_reg->pr_reg_nacl->se_tpg; in core_scsi3_pri_read_full_status()
3972 atomic_inc_mb(&pr_reg->pr_res_holders); in core_scsi3_pri_read_full_status()
3973 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_pri_read_full_status()
3981 exp_desc_len + add_len > cmd->data_length) { in core_scsi3_pri_read_full_status()
3982 pr_warn("SPC-3 PRIN READ_FULL_STATUS ran" in core_scsi3_pri_read_full_status()
3983 " out of buffer: %d\n", cmd->data_length); in core_scsi3_pri_read_full_status()
3984 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_pri_read_full_status()
3985 atomic_dec_mb(&pr_reg->pr_res_holders); in core_scsi3_pri_read_full_status()
3989 * Set RESERVATION KEY in core_scsi3_pri_read_full_status()
3991 put_unaligned_be64(pr_reg->pr_res_key, &buf[off]); in core_scsi3_pri_read_full_status()
3998 if (pr_reg->pr_reg_all_tg_pt) in core_scsi3_pri_read_full_status()
4008 if (pr_reg->pr_res_holder) { in core_scsi3_pri_read_full_status()
4010 buf[off++] = (pr_reg->pr_res_scope & 0xf0) | in core_scsi3_pri_read_full_status()
4011 (pr_reg->pr_res_type & 0x0f); in core_scsi3_pri_read_full_status()
4031 if (!pr_reg->pr_reg_all_tg_pt) { in core_scsi3_pri_read_full_status()
4032 u16 sep_rtpi = pr_reg->tg_pt_sep_rtpi; in core_scsi3_pri_read_full_status()
4039 buf[off+4] = se_tpg->proto_id; in core_scsi3_pri_read_full_status()
4047 spin_lock(&pr_tmpl->registration_lock); in core_scsi3_pri_read_full_status()
4048 atomic_dec_mb(&pr_reg->pr_res_holders); in core_scsi3_pri_read_full_status()
4069 spin_unlock(&pr_tmpl->registration_lock); in core_scsi3_pri_read_full_status()
4083 struct exec_cmd_ops *ops = cmd->protocol_data; in target_try_pr_in_pt()
4087 if (cmd->data_length < 8) { in target_try_pr_in_pt()
4089 cmd->data_length); in target_try_pr_in_pt()
4093 if (!ops->execute_pr_in) { in target_try_pr_in_pt()
4094 …pr_err("SPC-3 PR: Device has been configured for PR passthrough but it's not supported by the back… in target_try_pr_in_pt()
4099 pr_err("SPC-3 PR: PRI_READ_FULL_STATUS is not supported by PR passthrough.\n"); in target_try_pr_in_pt()
4107 ret = ops->execute_pr_in(cmd, sa, buf); in target_try_pr_in_pt()
4116 u8 sa = cmd->t_task_cdb[1] & 0x1f; in target_scsi3_emulate_pr_in()
4128 if (cmd->se_dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) { in target_scsi3_emulate_pr_in()
4130 " SPC-2 reservation is held, returning" in target_scsi3_emulate_pr_in()
4135 if (cmd->se_dev->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) { in target_scsi3_emulate_pr_in()
4155 " action: 0x%02x\n", cmd->t_task_cdb[1] & 0x1f); in target_scsi3_emulate_pr_in()
4168 struct se_device *dev = cmd->se_dev; in target_check_reservation()
4171 if (!cmd->se_sess) in target_check_reservation()
4173 if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE) in target_check_reservation()
4175 if (!dev->dev_attrib.emulate_pr) in target_check_reservation()
4177 if (dev->transport_flags & TRANSPORT_FLAG_PASSTHROUGH_PGR) in target_check_reservation()
4180 spin_lock(&dev->dev_reservation_lock); in target_check_reservation()
4181 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) in target_check_reservation()
4185 spin_unlock(&dev->dev_reservation_lock); in target_check_reservation()