28 #include <linux/slab.h>
30 #include <linux/list.h>
31 #include <scsi/scsi.h>
33 #include <asm/unaligned.h>
71 static int core_scsi2_reservation_seq_non_holder(
88 static int core_scsi2_reservation_check(
struct se_cmd *cmd,
u32 *pr_reg_type)
120 static int target_check_scsi2_reservation_conflict(
struct se_cmd *cmd)
157 core_scsi3_put_pr_reg(pr_reg);
164 core_scsi3_put_pr_reg(pr_reg);
167 core_scsi3_put_pr_reg(pr_reg);
186 pr_err(
"Received legacy SPC-2 RESERVE/RELEASE"
187 " while active SPC-3 registrations exist,"
188 " returning RESERVATION_CONFLICT\n");
203 if (!sess || !sess->
se_tpg)
205 rc = target_check_scsi2_reservation_conflict(cmd);
232 pr_debug(
"SCSI-2 Released reservation for %s LUN: %u ->"
233 " MAPPED LUN: %u for %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
254 pr_err(
"LongIO and Obselete Bits set, returning"
255 " ILLEGAL_REQUEST\n");
264 if (!sess || !sess->
se_tpg)
266 rc = target_check_scsi2_reservation_conflict(cmd);
280 pr_err(
"SCSI-2 RESERVATION CONFLIFT for %s fabric\n",
282 pr_err(
"Original reserver LUN: %u %s\n",
283 cmd->
se_lun->unpacked_lun,
285 pr_err(
"Current attempt - LUN: %u -> MAPPED LUN: %u"
286 " from %s \n", cmd->
se_lun->unpacked_lun,
300 pr_debug(
"SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u"
301 " for %s\n", tpg->
se_tpg_tfo->get_fabric_name(),
320 static int core_scsi3_pr_seq_non_holder(
327 int other_cdb = 0, ignore_reg;
328 int registered_nexus = 0, ret = 1;
337 return core_scsi2_reservation_seq_non_holder(cmd,
345 ignore_reg = (pr_reg_type & 0x80000000);
347 pr_reg_type &= ~0x80000000;
349 switch (pr_reg_type) {
358 registered_nexus = 1;
368 registered_nexus = 1;
378 registered_nexus = 1;
388 if (registered_nexus)
401 if (registered_nexus) {
413 switch (cdb[1] & 0x1f) {
417 ret = (registered_nexus) ? 0 : 1;
428 ret = (registered_nexus) ? 0 : 1;
431 pr_err(
"Unknown PERSISTENT_RESERVE_OUT service"
432 " action: 0x%02x\n", cdb[1] & 0x1f);
447 ret = (legacy) ? 1 : 0;
450 switch (cdb[1] & 0x1f) {
452 if (registered_nexus) {
464 if (registered_nexus) {
478 pr_err(
"Unknown MI Service Action: 0x%02x\n",
501 if (!ret && !other_cdb) {
502 pr_debug(
"Allowing explict CDB: 0x%02x for %s"
503 " reservation holder\n", cdb[0],
512 if (we && !registered_nexus) {
517 pr_debug(
"%s Conflict for unregistered nexus"
518 " %s CDB: 0x%02x to %s reservation\n",
534 if (!registered_nexus) {
535 pr_debug(
"Allowing implict CDB: 0x%02x"
536 " for %s reservation on unregistered"
543 }
else if ((reg_only) || (all_reg)) {
544 if (registered_nexus) {
550 pr_debug(
"Allowing implict CDB: 0x%02x for %s"
551 " reservation\n", cdb[0],
557 pr_debug(
"%s Conflict for %sregistered nexus %s CDB: 0x%2x"
559 (registered_nexus) ?
"" :
"un",
566 static u32 core_scsi3_pr_generation(
struct se_device *dev)
580 prg = su_dev->
t10_pr.pr_generation++;
586 static int core_scsi3_pr_reservation_check(
600 return core_scsi2_reservation_check(cmd, pr_reg_type);
624 *pr_reg_type |= 0x80000000;
644 pr_err(
"Unable to allocate struct t10_pr_registration\n");
651 pr_err(
"Unable to allocate pr_reg->pr_aptpl_buf\n");
683 static int core_scsi3_lunacl_depend_item(
struct se_dev_entry *);
684 static void core_scsi3_lunacl_undepend_item(
struct se_dev_entry *);
709 pr_reg = __core_scsi3_do_alloc_registration(dev, nacl, deve, isid,
710 sa_res_key, all_tg_pt, aptpl);
744 if (nacl == nacl_tmp)
751 if (tfo != nacl_tmp->
se_tpg->se_tpg_tfo)
768 ret = core_scsi3_lunacl_depend_item(deve_tmp);
770 pr_err(
"core_scsi3_lunacl_depend"
785 pr_reg_atp = __core_scsi3_do_alloc_registration(dev,
786 nacl_tmp, deve_tmp,
NULL,
787 sa_res_key, all_tg_pt, aptpl);
793 core_scsi3_lunacl_undepend_item(deve_tmp);
814 core_scsi3_lunacl_undepend_item(pr_reg_tmp->
pr_reg_deve);
824 unsigned char *i_port,
827 unsigned char *t_port,
836 if (!i_port || !t_port || !sa_res_key) {
837 pr_err(
"Illegal parameters for APTPL registration\n");
843 pr_err(
"Unable to allocate struct t10_pr_registration\n");
888 pr_debug(
"SPC-3 PR APTPL Successfully added registration%s from"
889 " metadata\n", (res_holder) ?
"+reservation" :
"");
893 static void core_scsi3_aptpl_reserve(
910 pr_debug(
"SPC-3 PR [%s] Service Action: APTPL RESERVE created"
911 " new reservation holder TYPE: %s ALL_TG_PT: %d\n",
915 pr_debug(
"SPC-3 PR [%s] RESERVE Node: %s%s\n",
917 (prf_isid) ? &i_buf[0] :
"");
923 static int __core_scsi3_check_aptpl_registration(
972 __core_scsi3_add_registration(dev, nacl, pr_reg, 0, 0);
978 core_scsi3_aptpl_reserve(dev, tpg,
1006 return __core_scsi3_check_aptpl_registration(dev, tpg, lun,
1010 static void __core_scsi3_dump_registration(
1025 pr_debug(
"SPC-3 PR [%s] Service Action: REGISTER%s Initiator"
1027 "_AND_MOVE" : (register_type == 1) ?
1029 (prf_isid) ? i_buf :
"");
1030 pr_debug(
"SPC-3 PR [%s] registration on Target Port: %s,0x%04x\n",
1033 pr_debug(
"SPC-3 PR [%s] for %s TCM Subsystem %s Object Target"
1037 pr_debug(
"SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:"
1047 static void __core_scsi3_add_registration(
1069 su_dev->
t10_pr.pr_generation++ :
1070 core_scsi3_pr_generation(dev);
1076 __core_scsi3_dump_registration(tfo, dev, nacl, pr_reg, register_type);
1098 __core_scsi3_dump_registration(tfo, dev,
1106 core_scsi3_lunacl_undepend_item(pr_reg_tmp->
pr_reg_deve);
1110 static int core_scsi3_alloc_registration(
1114 unsigned char *isid,
1123 pr_reg = __core_scsi3_alloc_registration(dev, nacl, deve, isid,
1124 sa_res_key, all_tg_pt, aptpl);
1128 __core_scsi3_add_registration(dev, nacl, pr_reg,
1129 register_type, register_move);
1136 unsigned char *isid)
1163 if (dev->
se_sub_dev->se_dev_attrib.enforce_pr_isids)
1201 tpg->
se_tpg_tfo->sess_get_initiator_sid(sess, &buf[0],
1206 return __core_scsi3_locate_pr_reg(dev, nacl, isid_ptr);
1215 static int core_scsi3_check_implict_release(
1225 if (!pr_res_holder) {
1229 if (pr_res_holder == pr_reg) {
1243 __core_scsi3_complete_pro_release(dev, nacl, pr_reg, 0);
1255 pr_err(
"SPC-3 PR: Unable to perform ALL_TG_PT=1"
1256 " UNREGISTER while existing reservation with matching"
1257 " key 0x%016Lx is present from another SCSI Initiator"
1269 static void __core_scsi3_free_registration(
1272 struct list_head *preempt_and_abort_list,
1293 core_scsi3_put_pr_reg(pr_reg);
1302 pr_debug(
"SPC-3 PR [%s] waiting for pr_res_holders\n",
1308 pr_debug(
"SPC-3 PR [%s] Service Action: UNREGISTER Initiator"
1311 (prf_isid) ? &i_buf[0] :
"");
1312 pr_debug(
"SPC-3 PR [%s] for %s TCM Subsystem %s Object Target"
1316 pr_debug(
"SPC-3 PR [%s] SA Res Key: 0x%016Lx PRgeneration:"
1320 if (!preempt_and_abort_list) {
1346 if ((pr_res_holder !=
NULL) &&
1348 __core_scsi3_complete_pro_release(dev, nacl, pr_res_holder, 0);
1360 __core_scsi3_free_registration(dev, pr_reg,
NULL, 0);
1373 if (pr_res_holder !=
NULL) {
1375 __core_scsi3_complete_pro_release(dev, pr_res_nacl,
1384 __core_scsi3_free_registration(dev, pr_reg,
NULL, 0);
1390 pr_reg_aptpl_list) {
1413 static int core_scsi3_nodeacl_depend_item(
struct se_node_acl *nacl)
1424 static void core_scsi3_nodeacl_undepend_item(
struct se_node_acl *nacl)
1441 static int core_scsi3_lunacl_depend_item(
struct se_dev_entry *se_deve)
1459 static void core_scsi3_lunacl_undepend_item(
struct se_dev_entry *se_deve)
1482 static int core_scsi3_decode_spec_i_port(
1485 unsigned char *l_isid,
1502 unsigned char *
ptr, *i_str =
NULL, proto_ident, tmp_proto_ident;
1504 u32 tpdl, tid_len = 0;
1505 int ret, dest_local_nexus, prf_isid;
1508 memset(dest_iport, 0, 64);
1519 pr_err(
"Unable to allocate tidh_new\n");
1528 local_pr_reg = __core_scsi3_alloc_registration(cmd->
se_dev,
1530 sa_res_key, all_tg_pt, aptpl);
1531 if (!local_pr_reg) {
1546 pr_warn(
"SPC-PR: Received PR OUT parameter list"
1559 tpdl = (buf[24] & 0xff) << 24;
1560 tpdl |= (buf[25] & 0xff) << 16;
1561 tpdl |= (buf[26] & 0xff) << 8;
1562 tpdl |= buf[27] & 0xff;
1565 pr_err(
"SPC-3 PR: Illegal tpdl: %u + 28 byte header"
1566 " does not equal CDB data_length: %u\n", tpdl,
1580 proto_ident = (ptr[0] & 0x0f);
1588 tmp_tf_ops = tmp_tpg->se_tpg_tfo;
1599 if (tmp_proto_ident != proto_ident)
1604 tmp_tpg, (
const char *)ptr, &tid_len,
1613 ret = core_scsi3_tpg_depend_item(tmp_tpg);
1615 pr_err(
" core_scsi3_tpg_depend_item()"
1629 spin_lock_irq(&tmp_tpg->acl_node_lock);
1632 if (dest_node_acl) {
1636 spin_unlock_irq(&tmp_tpg->acl_node_lock);
1638 if (!dest_node_acl) {
1639 core_scsi3_tpg_undepend_item(tmp_tpg);
1644 ret = core_scsi3_nodeacl_depend_item(dest_node_acl);
1646 pr_err(
"configfs_depend_item() failed"
1647 " for dest_node_acl->acl_group\n");
1650 core_scsi3_tpg_undepend_item(tmp_tpg);
1658 pr_debug(
"SPC-3 PR SPEC_I_PT: Located %s Node:"
1659 " %s Port RTPI: %hu\n",
1669 pr_err(
"SPC-3 PR SPEC_I_PT: Unable to locate"
1676 pr_debug(
"SPC-3 PR SPEC_I_PT: Got %s data_length: %u tpdl: %u"
1677 " tid_len: %d for %s + %s\n",
1679 tpdl, tid_len, i_str, iport_ptr);
1681 if (tid_len > tpdl) {
1682 pr_err(
"SPC-3 PR SPEC_I_PT: Illegal tid_len:"
1683 " %u for Transport ID: %s\n", tid_len, ptr);
1684 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1685 core_scsi3_tpg_undepend_item(dest_tpg);
1697 if (!dest_se_deve) {
1698 pr_err(
"Unable to locate %s dest_se_deve"
1699 " from destination RTPI: %hu\n",
1703 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1704 core_scsi3_tpg_undepend_item(dest_tpg);
1710 ret = core_scsi3_lunacl_depend_item(dest_se_deve);
1712 pr_err(
"core_scsi3_lunacl_depend_item()"
1716 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1717 core_scsi3_tpg_undepend_item(dest_tpg);
1724 pr_debug(
"SPC-3 PR SPEC_I_PT: Located %s Node: %s"
1725 " dest_se_deve mapped_lun: %u\n",
1733 pr_reg_e = __core_scsi3_locate_pr_reg(dev, dest_node_acl,
1736 core_scsi3_put_pr_reg(pr_reg_e);
1737 core_scsi3_lunacl_undepend_item(dest_se_deve);
1738 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1739 core_scsi3_tpg_undepend_item(dest_tpg);
1753 pr_err(
"Unable to allocate tidh_new\n");
1754 core_scsi3_lunacl_undepend_item(dest_se_deve);
1755 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1756 core_scsi3_tpg_undepend_item(dest_tpg);
1783 dest_pr_reg = __core_scsi3_alloc_registration(cmd->
se_dev,
1784 dest_node_acl, dest_se_deve, iport_ptr,
1785 sa_res_key, all_tg_pt, aptpl);
1787 core_scsi3_lunacl_undepend_item(dest_se_deve);
1788 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1789 core_scsi3_tpg_undepend_item(dest_tpg);
1833 __core_scsi3_add_registration(cmd->
se_dev, dest_node_acl,
1836 pr_debug(
"SPC-3 PR [%s] SPEC_I_PT: Successfully"
1837 " registered Transport ID for Node: %s%s Mapped LUN:"
1838 " %u\n", dest_tpg->
se_tpg_tfo->get_fabric_name(),
1842 if (dest_local_nexus)
1845 core_scsi3_lunacl_undepend_item(dest_se_deve);
1846 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1847 core_scsi3_tpg_undepend_item(dest_tpg);
1872 pr_reg_atp_mem_list) {
1874 core_scsi3_lunacl_undepend_item(pr_reg_tmp->
pr_reg_deve);
1881 if (dest_local_nexus)
1884 core_scsi3_lunacl_undepend_item(dest_se_deve);
1885 core_scsi3_nodeacl_undepend_item(dest_node_acl);
1886 core_scsi3_tpg_undepend_item(dest_tpg);
1894 static int __core_scsi3_update_aptpl_buf(
1897 u32 pr_aptpl_buf_len,
1898 int clear_aptpl_metadata)
1904 unsigned char tmp[512], isid_buf[32];
1908 memset(buf, 0, pr_aptpl_buf_len);
1912 if (clear_aptpl_metadata) {
1914 "No Registrations or Reservations\n");
1920 spin_lock(&su_dev->
t10_pr.registration_lock);
1933 snprintf(isid_buf, 32,
"initiator_sid=%s\n",
1940 snprintf(tmp, 512,
"PR_REG_START: %d"
1941 "\ninitiator_fabric=%s\n"
1942 "initiator_node=%s\n%s"
1944 "res_holder=1\nres_type=%02x\n"
1945 "res_scope=%02x\nres_all_tg_pt=%d\n"
1946 "mapped_lun=%u\n", reg_count,
1953 snprintf(tmp, 512,
"PR_REG_START: %d\n"
1954 "initiator_fabric=%s\ninitiator_node=%s\n%s"
1955 "sa_res_key=%llu\nres_holder=0\n"
1956 "res_all_tg_pt=%d\nmapped_lun=%u\n",
1957 reg_count, tpg->
se_tpg_tfo->get_fabric_name(),
1963 if ((len +
strlen(tmp) >= pr_aptpl_buf_len)) {
1964 pr_err(
"Unable to update renaming"
1965 " APTPL metadata\n");
1966 spin_unlock(&su_dev->
t10_pr.registration_lock);
1969 len +=
sprintf(buf+len,
"%s", tmp);
1974 snprintf(tmp, 512,
"target_fabric=%s\ntarget_node=%s\n"
1975 "tpgt=%hu\nport_rtpi=%hu\ntarget_lun=%u\nPR_REG_END:"
1981 if ((len +
strlen(tmp) >= pr_aptpl_buf_len)) {
1982 pr_err(
"Unable to update renaming"
1983 " APTPL metadata\n");
1984 spin_unlock(&su_dev->
t10_pr.registration_lock);
1987 len +=
sprintf(buf+len,
"%s", tmp);
1990 spin_unlock(&su_dev->
t10_pr.registration_lock);
1993 len +=
sprintf(buf+len,
"No Registrations or Reservations");
1998 static int core_scsi3_update_aptpl_buf(
2001 u32 pr_aptpl_buf_len,
2002 int clear_aptpl_metadata)
2007 ret = __core_scsi3_update_aptpl_buf(dev, buf, pr_aptpl_buf_len,
2008 clear_aptpl_metadata);
2017 static int __core_scsi3_write_aptpl_to_file(
2020 u32 pr_aptpl_buf_len)
2024 struct iovec iov[1];
2034 pr_err(
"WWN value for struct se_device does not fit"
2035 " into path buffer\n");
2041 if (IS_ERR(file) || !file || !file->f_dentry) {
2042 pr_err(
"filp_open(%s) for APTPL metadata"
2044 return IS_ERR(file) ? PTR_ERR(file) : -
ENOENT;
2047 iov[0].iov_base = &buf[0];
2048 if (!pr_aptpl_buf_len)
2049 iov[0].iov_len = (
strlen(&buf[0]) + 1);
2051 iov[0].iov_len = pr_aptpl_buf_len;
2059 pr_debug(
"Error writing APTPL metadata file: %s\n", path);
2068 static int core_scsi3_update_and_write_aptpl(
2070 unsigned char *in_buf,
2071 u32 in_pr_aptpl_buf_len)
2073 unsigned char null_buf[64], *
buf;
2074 u32 pr_aptpl_buf_len;
2075 int ret, clear_aptpl_metadata = 0;
2086 pr_aptpl_buf_len = 64;
2087 clear_aptpl_metadata = 1;
2090 pr_aptpl_buf_len = in_pr_aptpl_buf_len;
2093 ret = core_scsi3_update_aptpl_buf(dev, buf, pr_aptpl_buf_len,
2094 clear_aptpl_metadata);
2101 ret = __core_scsi3_write_aptpl_to_file(dev, buf, 0);
2108 static int core_scsi3_emulate_pro_register(
2125 unsigned char *pr_aptpl_buf =
NULL;
2127 int pr_holder = 0, ret = 0,
type;
2129 if (!se_sess || !se_lun) {
2130 pr_err(
"SPC-3 PR: se_sess || struct se_lun is NULL!\n");
2134 se_tpg = se_sess->
se_tpg;
2137 if (se_tpg->
se_tpg_tfo->sess_get_initiator_sid) {
2139 se_tpg->
se_tpg_tfo->sess_get_initiator_sid(se_sess, &isid_buf[0],
2141 isid_ptr = &isid_buf[0];
2146 pr_reg_e = core_scsi3_locate_pr_reg(dev, se_sess->
se_node_acl, se_sess);
2149 pr_warn(
"SPC-3 PR: Reservation Key non-zero"
2150 " for SA REGISTER, returning CONFLICT\n");
2166 ret = core_scsi3_alloc_registration(cmd->
se_dev,
2168 sa_res_key, all_tg_pt, aptpl,
2171 pr_err(
"Unable to allocate"
2172 " struct t10_pr_registration\n");
2185 ret = core_scsi3_decode_spec_i_port(cmd, se_tpg,
2186 isid_ptr, sa_res_key, all_tg_pt, aptpl);
2195 core_scsi3_update_and_write_aptpl(cmd->
se_dev,
NULL, 0);
2196 pr_debug(
"SPC-3 PR: Set APTPL Bit Deactivated for"
2205 pr_reg = core_scsi3_locate_pr_reg(cmd->
se_dev,
2208 ret = core_scsi3_update_and_write_aptpl(cmd->
se_dev,
2213 pr_debug(
"SPC-3 PR: Set APTPL Bit Activated for REGISTER\n");
2216 core_scsi3_put_pr_reg(pr_reg);
2227 pr_err(
"SPC-3 PR REGISTER: Received"
2228 " res_key: 0x%016Lx does not match"
2229 " existing SA REGISTER res_key:"
2230 " 0x%016Lx\n", res_key,
2232 core_scsi3_put_pr_reg(pr_reg);
2238 pr_err(
"SPC-3 PR UNREGISTER: SPEC_I_PT"
2239 " set while sa_res_key=0\n");
2240 core_scsi3_put_pr_reg(pr_reg);
2249 pr_err(
"SPC-3 PR UNREGISTER: ALL_TG_PT=1"
2250 " registration exists, but ALL_TG_PT=1 bit not"
2251 " present in received PROUT\n");
2252 core_scsi3_put_pr_reg(pr_reg);
2262 if (!pr_aptpl_buf) {
2263 pr_err(
"Unable to allocate"
2265 core_scsi3_put_pr_reg(pr_reg);
2277 pr_holder = core_scsi3_check_implict_release(
2279 if (pr_holder < 0) {
2280 kfree(pr_aptpl_buf);
2281 core_scsi3_put_pr_reg(pr_reg);
2302 if (pr_reg == pr_reg_p)
2309 __core_scsi3_free_registration(dev,
2316 __core_scsi3_free_registration(cmd->
se_dev, pr_reg,
2347 core_scsi3_update_and_write_aptpl(dev,
NULL, 0);
2348 pr_debug(
"SPC-3 PR: Set APTPL Bit Deactivated"
2349 " for UNREGISTER\n");
2353 ret = core_scsi3_update_and_write_aptpl(dev,
2358 pr_debug(
"SPC-3 PR: Set APTPL Bit Activated"
2359 " for UNREGISTER\n");
2362 kfree(pr_aptpl_buf);
2373 pr_debug(
"SPC-3 PR [%s] REGISTER%s: Changed Reservation"
2374 " Key for %s to: 0x%016Lx PRgeneration:"
2375 " 0x%08x\n", cmd->
se_tfo->get_fabric_name(),
2376 (ignore_key) ?
"_AND_IGNORE_EXISTING_KEY" :
"",
2382 core_scsi3_update_and_write_aptpl(dev,
NULL, 0);
2383 core_scsi3_put_pr_reg(pr_reg);
2384 pr_debug(
"SPC-3 PR: Set APTPL Bit Deactivated"
2389 ret = core_scsi3_update_and_write_aptpl(dev,
2394 pr_debug(
"SPC-3 PR: Set APTPL Bit Activated"
2398 kfree(pr_aptpl_buf);
2399 core_scsi3_put_pr_reg(pr_reg);
2409 return "Write Exclusive Access";
2411 return "Exclusive Access";
2413 return "Write Exclusive Access, Registrants Only";
2415 return "Exclusive Access, Registrants Only";
2417 return "Write Exclusive Access, All Registrants";
2419 return "Exclusive Access, All Registrants";
2424 return "Unknown SPC-3 PR Type";
2427 static int core_scsi3_pro_reserve(
2435 struct se_lun *se_lun = cmd->
se_lun;
2443 if (!se_sess || !se_lun) {
2444 pr_err(
"SPC-3 PR: se_sess || struct se_lun is NULL!\n");
2454 pr_err(
"SPC-3 PR: Unable to locate"
2455 " PR_REGISTERED *pr_reg for RESERVE\n");
2469 pr_err(
"SPC-3 PR RESERVE: Received res_key: 0x%016Lx"
2470 " does not match existing SA REGISTER res_key:"
2472 core_scsi3_put_pr_reg(pr_reg);
2487 pr_err(
"SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope);
2488 core_scsi3_put_pr_reg(pr_reg);
2499 if (pr_res_holder) {
2510 if (pr_res_holder != pr_reg) {
2512 pr_err(
"SPC-3 PR: Attempted RESERVE from"
2513 " [%s]: %s while reservation already held by"
2514 " [%s]: %s, returning RESERVATION_CONFLICT\n",
2515 cmd->
se_tfo->get_fabric_name(),
2517 pr_res_nacl->
se_tpg->se_tpg_tfo->get_fabric_name(),
2521 core_scsi3_put_pr_reg(pr_reg);
2535 pr_err(
"SPC-3 PR: Attempted RESERVE from"
2536 " [%s]: %s trying to change TYPE and/or SCOPE,"
2537 " while reservation already held by [%s]: %s,"
2538 " returning RESERVATION_CONFLICT\n",
2539 cmd->
se_tfo->get_fabric_name(),
2541 pr_res_nacl->
se_tpg->se_tpg_tfo->get_fabric_name(),
2545 core_scsi3_put_pr_reg(pr_reg);
2560 core_scsi3_put_pr_reg(pr_reg);
2574 pr_debug(
"SPC-3 PR [%s] Service Action: RESERVE created new"
2575 " reservation holder TYPE: %s ALL_TG_PT: %d\n",
2578 pr_debug(
"SPC-3 PR [%s] RESERVE Node: %s%s\n",
2579 cmd->
se_tfo->get_fabric_name(),
2581 (prf_isid) ? &i_buf[0] :
"");
2585 ret = core_scsi3_update_and_write_aptpl(cmd->
se_dev,
2589 pr_debug(
"SPC-3 PR: Updated APTPL metadata"
2593 core_scsi3_put_pr_reg(pr_reg);
2597 static int core_scsi3_emulate_pro_reserve(
2613 ret = core_scsi3_pro_reserve(cmd, dev, type, scope, res_key);
2616 pr_err(
"SPC-3 PR: Unknown Service Action RESERVE Type:"
2628 static void __core_scsi3_complete_pro_release(
2646 pr_debug(
"SPC-3 PR [%s] Service Action: %s RELEASE cleared"
2647 " reservation holder TYPE: %s ALL_TG_PT: %d\n",
2651 pr_debug(
"SPC-3 PR [%s] RELEASE Node: %s%s\n",
2653 (prf_isid) ? &i_buf[0] :
"");
2660 static int core_scsi3_emulate_pro_release(
2668 struct se_lun *se_lun = cmd->
se_lun;
2671 int ret, all_reg = 0;
2673 if (!se_sess || !se_lun) {
2674 pr_err(
"SPC-3 PR: se_sess || struct se_lun is NULL!\n");
2681 pr_reg = core_scsi3_locate_pr_reg(dev, se_sess->
se_node_acl, se_sess);
2683 pr_err(
"SPC-3 PR: Unable to locate"
2684 " PR_REGISTERED *pr_reg for RELEASE\n");
2702 if (!pr_res_holder) {
2707 core_scsi3_put_pr_reg(pr_reg);
2714 if ((all_reg == 0) && (pr_res_holder != pr_reg)) {
2721 core_scsi3_put_pr_reg(pr_reg);
2739 pr_err(
"SPC-3 PR RELEASE: Received res_key: 0x%016Lx"
2740 " does not match existing SA REGISTER res_key:"
2743 core_scsi3_put_pr_reg(pr_reg);
2756 pr_err(
"SPC-3 PR RELEASE: Attempted to release"
2757 " reservation from [%s]: %s with different TYPE "
2758 "and/or SCOPE while reservation already held by"
2759 " [%s]: %s, returning RESERVATION_CONFLICT\n",
2760 cmd->
se_tfo->get_fabric_name(),
2762 pr_res_nacl->
se_tpg->se_tpg_tfo->get_fabric_name(),
2766 core_scsi3_put_pr_reg(pr_reg);
2786 __core_scsi3_complete_pro_release(dev, se_sess->
se_node_acl,
2810 if (pr_reg_p == pr_reg)
2821 ret = core_scsi3_update_and_write_aptpl(cmd->
se_dev,
2825 pr_debug(
"SPC-3 PR: Updated APTPL metadata for RELEASE\n");
2828 core_scsi3_put_pr_reg(pr_reg);
2832 static int core_scsi3_emulate_pro_clear(
2842 int calling_it_nexus = 0;
2846 pr_reg_n = core_scsi3_locate_pr_reg(cmd->
se_dev,
2849 pr_err(
"SPC-3 PR: Unable to locate"
2850 " PR_REGISTERED *pr_reg for CLEAR\n");
2866 pr_err(
"SPC-3 PR REGISTER: Received"
2867 " res_key: 0x%016Lx does not match"
2868 " existing SA REGISTER res_key:"
2869 " 0x%016Lx\n", res_key, pr_reg_n->
pr_res_key);
2870 core_scsi3_put_pr_reg(pr_reg_n);
2879 if (pr_res_holder) {
2881 __core_scsi3_complete_pro_release(dev, pr_res_nacl,
2892 calling_it_nexus = (pr_reg_n ==
pr_reg) ? 1 : 0;
2895 __core_scsi3_free_registration(dev, pr_reg,
NULL,
2904 if (!calling_it_nexus)
2910 pr_debug(
"SPC-3 PR [%s] Service Action: CLEAR complete\n",
2911 cmd->
se_tfo->get_fabric_name());
2914 core_scsi3_update_and_write_aptpl(cmd->
se_dev,
NULL, 0);
2915 pr_debug(
"SPC-3 PR: Updated APTPL metadata"
2919 core_scsi3_pr_generation(dev);
2926 static void __core_scsi3_complete_pro_preempt(
2929 struct list_head *preempt_and_abort_list,
2946 __core_scsi3_complete_pro_release(dev, nacl,
2954 pr_debug(
"SPC-3 PR [%s] Service Action: PREEMPT%s created new"
2955 " reservation holder TYPE: %s ALL_TG_PT: %d\n",
2959 pr_debug(
"SPC-3 PR [%s] PREEMPT%s from Node: %s%s\n",
2967 if (preempt_and_abort_list)
2969 preempt_and_abort_list);
2972 static void core_scsi3_release_preempt_and_abort(
2973 struct list_head *preempt_and_abort_list,
2982 if (pr_reg_holder == pr_reg)
2985 pr_warn(
"pr_reg->pr_res_holder still set\n");
2996 static int core_scsi3_pro_preempt(
3010 u32 pr_res_mapped_lun = 0;
3011 int all_reg = 0, calling_it_nexus = 0, released_regs = 0;
3012 int prh_type = 0, prh_scope = 0,
ret;
3022 pr_err(
"SPC-3 PR: Unable to locate"
3023 " PR_REGISTERED *pr_reg for PREEMPT%s\n",
3024 (abort) ?
"_AND_ABORT" :
"");
3029 core_scsi3_put_pr_reg(pr_reg_n);
3034 pr_err(
"SPC-3 PR: Illegal SCOPE: 0x%02x\n", scope);
3035 core_scsi3_put_pr_reg(pr_reg_n);
3042 if (pr_res_holder &&
3047 if (!all_reg && !sa_res_key) {
3049 core_scsi3_put_pr_reg(pr_reg_n);
3062 if (!pr_res_holder || (pr_res_holder->
pr_res_key != sa_res_key)) {
3093 calling_it_nexus = (pr_reg_n ==
pr_reg) ? 1 : 0;
3096 __core_scsi3_free_registration(dev, pr_reg,
3097 (abort) ? &preempt_and_abort_list :
3098 NULL, calling_it_nexus);
3118 calling_it_nexus = (pr_reg_n ==
pr_reg) ? 1 : 0;
3119 if (calling_it_nexus)
3124 __core_scsi3_free_registration(dev, pr_reg,
3125 (abort) ? &preempt_and_abort_list :
3129 if (!calling_it_nexus)
3131 pr_res_mapped_lun, 0x2A,
3142 if (!released_regs) {
3144 core_scsi3_put_pr_reg(pr_reg_n);
3153 if (pr_res_holder && all_reg && !(sa_res_key)) {
3154 __core_scsi3_complete_pro_preempt(dev, pr_reg_n,
3155 (abort) ? &preempt_and_abort_list :
NULL,
3156 type, scope, abort);
3159 core_scsi3_release_preempt_and_abort(
3160 &preempt_and_abort_list, pr_reg_n);
3165 ret = core_scsi3_update_and_write_aptpl(cmd->
se_dev,
3170 " metadata for PREEMPT%s\n", (abort) ?
3174 core_scsi3_put_pr_reg(pr_reg_n);
3175 core_scsi3_pr_generation(cmd->
se_dev);
3208 if (pr_reg_n != pr_res_holder)
3209 __core_scsi3_complete_pro_release(dev,
3226 calling_it_nexus = (pr_reg_n ==
pr_reg) ? 1 : 0;
3227 if (calling_it_nexus)
3235 __core_scsi3_free_registration(dev, pr_reg,
3236 (abort) ? &preempt_and_abort_list :
NULL,
3252 __core_scsi3_complete_pro_preempt(dev, pr_reg_n,
3253 (abort) ? &preempt_and_abort_list :
NULL,
3254 type, scope, abort);
3268 if ((prh_type != type) || (prh_scope != scope)) {
3273 calling_it_nexus = (pr_reg_n ==
pr_reg) ? 1 : 0;
3274 if (calling_it_nexus)
3296 core_scsi3_release_preempt_and_abort(&preempt_and_abort_list,
3301 ret = core_scsi3_update_and_write_aptpl(cmd->
se_dev,
3305 pr_debug(
"SPC-3 PR: Updated APTPL metadata for PREEMPT"
3306 "%s\n", (abort) ?
"_AND_ABORT" :
"");
3309 core_scsi3_put_pr_reg(pr_reg_n);
3310 core_scsi3_pr_generation(cmd->
se_dev);
3314 static int core_scsi3_emulate_pro_preempt(
3331 ret = core_scsi3_pro_preempt(cmd, type, scope,
3332 res_key, sa_res_key, abort);
3335 pr_err(
"SPC-3 PR: Unknown Service Action PREEMPT%s"
3336 " Type: 0x%02x\n", (abort) ?
"_AND_ABORT" :
"", type);
3345 static int core_scsi3_emulate_pro_register_and_move(
3355 struct se_lun *se_lun = cmd->
se_lun;
3363 unsigned char *initiator_str;
3365 u32 tid_len, tmp_tid_len;
3366 int new_reg = 0,
type,
scope,
ret, matching_iname, prf_isid;
3367 unsigned short rtpi;
3368 unsigned char proto_ident;
3370 if (!se_sess || !se_lun) {
3371 pr_err(
"SPC-3 PR: se_sess || struct se_lun is NULL!\n");
3375 memset(dest_iport, 0, 64);
3377 se_tpg = se_sess->
se_tpg;
3388 pr_err(
"SPC-3 PR: Unable to locate PR_REGISTERED"
3389 " *pr_reg for REGISTER_AND_MOVE\n");
3398 pr_warn(
"SPC-3 PR REGISTER_AND_MOVE: Received"
3399 " res_key: 0x%016Lx does not match existing SA REGISTER"
3400 " res_key: 0x%016Lx\n", res_key, pr_reg->
pr_res_key);
3401 core_scsi3_put_pr_reg(pr_reg);
3409 pr_warn(
"SPC-3 PR REGISTER_AND_MOVE: Received zero"
3411 core_scsi3_put_pr_reg(pr_reg);
3422 rtpi = (buf[18] & 0xff) << 8;
3423 rtpi |= buf[19] & 0xff;
3424 tid_len = (buf[20] & 0xff) << 24;
3425 tid_len |= (buf[21] & 0xff) << 16;
3426 tid_len |= (buf[22] & 0xff) << 8;
3427 tid_len |= buf[23] & 0xff;
3432 pr_err(
"SPC-3 PR: Illegal tid_len: %u + 24 byte header"
3433 " does not equal CDB data_length: %u\n", tid_len,
3435 core_scsi3_put_pr_reg(pr_reg);
3444 dest_se_tpg = se_port->
sep_tpg;
3455 ret = core_scsi3_tpg_depend_item(dest_se_tpg);
3457 pr_err(
"core_scsi3_tpg_depend_item() failed"
3458 " for dest_se_tpg\n");
3461 core_scsi3_put_pr_reg(pr_reg);
3471 if (!dest_se_tpg || !dest_tf_ops) {
3472 pr_err(
"SPC-3 PR REGISTER_AND_MOVE: Unable to locate"
3473 " fabric ops from Relative Target Port Identifier:"
3475 core_scsi3_put_pr_reg(pr_reg);
3481 proto_ident = (buf[24] & 0x0f);
3483 pr_debug(
"SPC-3 PR REGISTER_AND_MOVE: Extracted Protocol Identifier:"
3484 " 0x%02x\n", proto_ident);
3487 pr_err(
"SPC-3 PR REGISTER_AND_MOVE: Received"
3488 " proto_ident: 0x%02x does not match ident: 0x%02x"
3489 " from fabric: %s\n", proto_ident,
3497 pr_err(
"SPC-3 PR REGISTER_AND_MOVE: Fabric does not"
3498 " containg a valid tpg_parse_pr_out_transport_id"
3499 " function pointer\n");
3505 (
const char *)&buf[24], &tmp_tid_len, &iport_ptr);
3506 if (!initiator_str) {
3507 pr_err(
"SPC-3 PR REGISTER_AND_MOVE: Unable to locate"
3508 " initiator_str from Transport ID\n");
3517 pr_debug(
"SPC-3 PR [%s] Extracted initiator %s identifier: %s"
3519 "port" :
"device", initiator_str, (iport_ptr !=
NULL) ?
3530 matching_iname = (!
strcmp(initiator_str,
3531 pr_reg_nacl->initiatorname)) ? 1 : 0;
3532 if (!matching_iname)
3533 goto after_iport_check;
3536 pr_err(
"SPC-3 PR REGISTER_AND_MOVE: TransportID: %s"
3537 " matches: %s on received I_T Nexus\n", initiator_str,
3538 pr_reg_nacl->initiatorname);
3544 pr_err(
"SPC-3 PR REGISTER_AND_MOVE: TransportID: %s %s"
3545 " matches: %s %s on received I_T Nexus\n",
3546 initiator_str, iport_ptr, pr_reg_nacl->initiatorname,
3559 if (dest_node_acl) {
3565 if (!dest_node_acl) {
3566 pr_err(
"Unable to locate %s dest_node_acl for"
3573 ret = core_scsi3_nodeacl_depend_item(dest_node_acl);
3575 pr_err(
"core_scsi3_nodeacl_depend_item() for"
3576 " dest_node_acl\n");
3579 dest_node_acl =
NULL;
3585 pr_debug(
"SPC-3 PR REGISTER_AND_MOVE: Found %s dest_node_acl:"
3594 if (!dest_se_deve) {
3595 pr_err(
"Unable to locate %s dest_se_deve from RTPI:"
3602 ret = core_scsi3_lunacl_depend_item(dest_se_deve);
3604 pr_err(
"core_scsi3_lunacl_depend_item() failed\n");
3607 dest_se_deve =
NULL;
3613 pr_debug(
"SPC-3 PR REGISTER_AND_MOVE: Located %s node %s LUN"
3614 " ACL for dest_se_deve->mapped_lun: %u\n",
3616 dest_se_deve->mapped_lun);
3624 if (!pr_res_holder) {
3625 pr_warn(
"SPC-3 PR REGISTER_AND_MOVE: No reservation"
3626 " currently held\n");
3638 if (pr_res_holder != pr_reg) {
3639 pr_warn(
"SPC-3 PR REGISTER_AND_MOVE: Calling I_T"
3640 " Nexus is not reservation holder\n");
3657 pr_warn(
"SPC-3 PR REGISTER_AND_MOVE: Unable to move"
3658 " reservation for type: %s\n",
3691 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl,
3694 ret = core_scsi3_alloc_registration(cmd->
se_dev,
3695 dest_node_acl, dest_se_deve, iport_ptr,
3696 sa_res_key, 0, aptpl, 2, 1);
3703 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl,
3711 __core_scsi3_complete_pro_release(dev, pr_res_nacl,
3731 pr_debug(
"SPC-3 PR [%s] Service Action: REGISTER_AND_MOVE"
3732 " created new reservation holder TYPE: %s on object RTPI:"
3736 pr_debug(
"SPC-3 PR Successfully moved reservation from"
3737 " %s Fabric Node: %s%s -> %s Fabric Node: %s %s\n",
3738 tf_ops->get_fabric_name(), pr_reg_nacl->initiatorname,
3746 core_scsi3_lunacl_undepend_item(dest_se_deve);
3747 core_scsi3_nodeacl_undepend_item(dest_node_acl);
3748 core_scsi3_tpg_undepend_item(dest_se_tpg);
3755 __core_scsi3_free_registration(dev, pr_reg,
NULL, 1);
3758 core_scsi3_put_pr_reg(pr_reg);
3766 core_scsi3_update_and_write_aptpl(cmd->
se_dev,
NULL, 0);
3767 pr_debug(
"SPC-3 PR: Set APTPL Bit Deactivated for"
3768 " REGISTER_AND_MOVE\n");
3771 ret = core_scsi3_update_and_write_aptpl(cmd->
se_dev,
3775 pr_debug(
"SPC-3 PR: Set APTPL Bit Activated for"
3776 " REGISTER_AND_MOVE\n");
3781 core_scsi3_put_pr_reg(dest_pr_reg);
3787 core_scsi3_lunacl_undepend_item(dest_se_deve);
3789 core_scsi3_nodeacl_undepend_item(dest_node_acl);
3790 core_scsi3_tpg_undepend_item(dest_se_tpg);
3791 core_scsi3_put_pr_reg(pr_reg);
3795 static unsigned long long core_scsi3_extract_reservation_key(
unsigned char *cdb)
3797 unsigned int __v1, __v2;
3799 __v1 = (cdb[0] << 24) | (cdb[1] << 16) | (cdb[2] << 8) | cdb[3];
3800 __v2 = (cdb[4] << 24) | (cdb[5] << 16) | (cdb[6] << 8) | cdb[7];
3802 return ((
unsigned long long)__v2) | (
unsigned long long)__v1 << 32;
3812 u64 res_key, sa_res_key;
3814 int spec_i_pt = 0, all_tg_pt = 0, unreg = 0;
3827 pr_err(
"Received PERSISTENT_RESERVE CDB while legacy"
3828 " SPC-2 reservation is held, returning"
3829 " RESERVATION_CONFLICT\n");
3846 pr_warn(
"SPC-PR: Received PR OUT parameter list"
3855 sa = (cdb[1] & 0x1f);
3856 scope = (cdb[2] & 0xf0);
3857 type = (cdb[2] & 0x0f);
3863 res_key = core_scsi3_extract_reservation_key(&buf[0]);
3864 sa_res_key = core_scsi3_extract_reservation_key(&buf[8]);
3870 spec_i_pt = (buf[20] & 0x08);
3871 all_tg_pt = (buf[20] & 0x04);
3872 aptpl = (buf[20] & 0x01);
3874 aptpl = (buf[17] & 0x01);
3875 unreg = (buf[17] & 0x02);
3900 pr_warn(
"SPC-PR: Received PR OUT illegal parameter"
3913 ret = core_scsi3_emulate_pro_register(cmd,
3914 res_key, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 0);
3917 ret = core_scsi3_emulate_pro_reserve(cmd, type, scope, res_key);
3920 ret = core_scsi3_emulate_pro_release(cmd, type, scope, res_key);
3923 ret = core_scsi3_emulate_pro_clear(cmd, res_key);
3926 ret = core_scsi3_emulate_pro_preempt(cmd, type, scope,
3927 res_key, sa_res_key, 0);
3930 ret = core_scsi3_emulate_pro_preempt(cmd, type, scope,
3931 res_key, sa_res_key, 1);
3934 ret = core_scsi3_emulate_pro_register(cmd,
3935 0, sa_res_key, aptpl, all_tg_pt, spec_i_pt, 1);
3938 ret = core_scsi3_emulate_pro_register_and_move(cmd, res_key,
3939 sa_res_key, aptpl, unreg);
3942 pr_err(
"Unknown PERSISTENT_RESERVE_OUT service"
3943 " action: 0x%02x\n", cdb[1] & 0x1f);
3960 static int core_scsi3_pri_read_keys(
struct se_cmd *cmd)
3966 u32 add_len = 0, off = 8;
3969 pr_err(
"PRIN SA READ_KEYS SCSI Data Length: %u"
3976 buf[0] = ((su_dev->
t10_pr.pr_generation >> 24) & 0xff);
3977 buf[1] = ((su_dev->
t10_pr.pr_generation >> 16) & 0xff);
3978 buf[2] = ((su_dev->
t10_pr.pr_generation >> 8) & 0xff);
3979 buf[3] = (su_dev->
t10_pr.pr_generation & 0xff);
3981 spin_lock(&su_dev->
t10_pr.registration_lock);
3991 buf[off++] = ((pr_reg->
pr_res_key >> 56) & 0xff);
3992 buf[off++] = ((pr_reg->
pr_res_key >> 48) & 0xff);
3993 buf[off++] = ((pr_reg->
pr_res_key >> 40) & 0xff);
3994 buf[off++] = ((pr_reg->
pr_res_key >> 32) & 0xff);
3995 buf[off++] = ((pr_reg->
pr_res_key >> 24) & 0xff);
3996 buf[off++] = ((pr_reg->
pr_res_key >> 16) & 0xff);
3997 buf[off++] = ((pr_reg->
pr_res_key >> 8) & 0xff);
4002 spin_unlock(&su_dev->
t10_pr.registration_lock);
4004 buf[4] = ((add_len >> 24) & 0xff);
4005 buf[5] = ((add_len >> 16) & 0xff);
4006 buf[6] = ((add_len >> 8) & 0xff);
4007 buf[7] = (add_len & 0xff);
4019 static int core_scsi3_pri_read_reservation(
struct se_cmd *cmd)
4029 pr_err(
"PRIN SA READ_RESERVATIONS SCSI Data Length: %u"
4036 buf[0] = ((su_dev->
t10_pr.pr_generation >> 24) & 0xff);
4037 buf[1] = ((su_dev->
t10_pr.pr_generation >> 16) & 0xff);
4038 buf[2] = ((su_dev->
t10_pr.pr_generation >> 8) & 0xff);
4039 buf[3] = (su_dev->
t10_pr.pr_generation & 0xff);
4047 buf[4] = ((add_len >> 24) & 0xff);
4048 buf[5] = ((add_len >> 16) & 0xff);
4049 buf[6] = ((add_len >> 8) & 0xff);
4050 buf[7] = (add_len & 0xff);
4077 buf[8] = ((pr_res_key >> 56) & 0xff);
4078 buf[9] = ((pr_res_key >> 48) & 0xff);
4079 buf[10] = ((pr_res_key >> 40) & 0xff);
4080 buf[11] = ((pr_res_key >> 32) & 0xff);
4081 buf[12] = ((pr_res_key >> 24) & 0xff);
4082 buf[13] = ((pr_res_key >> 16) & 0xff);
4083 buf[14] = ((pr_res_key >> 8) & 0xff);
4084 buf[15] = (pr_res_key & 0xff);
4104 static int core_scsi3_pri_report_capabilities(
struct se_cmd *cmd)
4112 pr_err(
"PRIN SA REPORT_CAPABILITIES SCSI Data Length:"
4120 buf[0] = ((add_len << 8) & 0xff);
4121 buf[1] = (add_len & 0xff);
4160 static int core_scsi3_pri_read_full_status(
struct se_cmd *cmd)
4169 u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len;
4171 int format_code = 0;
4174 pr_err(
"PRIN SA READ_FULL_STATUS SCSI Data Length: %u"
4182 buf[0] = ((su_dev->
t10_pr.pr_generation >> 24) & 0xff);
4183 buf[1] = ((su_dev->
t10_pr.pr_generation >> 16) & 0xff);
4184 buf[2] = ((su_dev->
t10_pr.pr_generation >> 8) & 0xff);
4185 buf[3] = (su_dev->
t10_pr.pr_generation & 0xff);
4202 exp_desc_len = se_tpg->
se_tpg_tfo->tpg_get_pr_transport_id_len(
4203 se_tpg, se_nacl, pr_reg, &format_code);
4205 if ((exp_desc_len + add_len) > cmd->
data_length) {
4206 pr_warn(
"SPC-3 PRIN READ_FULL_STATUS ran"
4216 buf[off++] = ((pr_reg->
pr_res_key >> 56) & 0xff);
4217 buf[off++] = ((pr_reg->
pr_res_key >> 48) & 0xff);
4218 buf[off++] = ((pr_reg->
pr_res_key >> 40) & 0xff);
4219 buf[off++] = ((pr_reg->
pr_res_key >> 32) & 0xff);
4220 buf[off++] = ((pr_reg->
pr_res_key >> 24) & 0xff);
4221 buf[off++] = ((pr_reg->
pr_res_key >> 16) & 0xff);
4222 buf[off++] = ((pr_reg->
pr_res_key >> 8) & 0xff);
4259 buf[off++] = ((port->
sep_rtpi >> 8) & 0xff);
4260 buf[off++] = (port->
sep_rtpi & 0xff);
4267 desc_len = se_tpg->
se_tpg_tfo->tpg_get_pr_transport_id(se_tpg,
4268 se_nacl, pr_reg, &format_code, &buf[off+4]);
4276 buf[off++] = ((desc_len >> 24) & 0xff);
4277 buf[off++] = ((desc_len >> 16) & 0xff);
4278 buf[off++] = ((desc_len >> 8) & 0xff);
4279 buf[off++] = (desc_len & 0xff);
4287 add_desc_len = (24 + desc_len);
4290 add_len += add_desc_len;
4296 buf[4] = ((add_len >> 24) & 0xff);
4297 buf[5] = ((add_len >> 16) & 0xff);
4298 buf[6] = ((add_len >> 8) & 0xff);
4299 buf[7] = (add_len & 0xff);
4320 pr_err(
"Received PERSISTENT_RESERVE CDB while legacy"
4321 " SPC-2 reservation is held, returning"
4322 " RESERVATION_CONFLICT\n");
4329 ret = core_scsi3_pri_read_keys(cmd);
4332 ret = core_scsi3_pri_read_reservation(cmd);
4335 ret = core_scsi3_pri_report_capabilities(cmd);
4338 ret = core_scsi3_pri_read_full_status(cmd);
4341 pr_err(
"Unknown PERSISTENT_RESERVE_IN service"
4342 " action: 0x%02x\n", cmd->
t_task_cdb[1] & 0x1f);
4353 static int core_pt_reservation_check(
struct se_cmd *cmd,
u32 *pr_res_type)
4358 static int core_pt_seq_non_holder(
4377 !(dev->
se_sub_dev->se_dev_attrib.emulate_reservations)) || force_pt) {
4379 rest->
pr_ops.t10_reservation_check = &core_pt_reservation_check;
4380 rest->
pr_ops.t10_seq_non_holder = &core_pt_seq_non_holder;
4381 pr_debug(
"%s: Using SPC_PASSTHROUGH, no reservation"
4391 rest->
pr_ops.t10_reservation_check = &core_scsi3_pr_reservation_check;
4392 rest->
pr_ops.t10_seq_non_holder = &core_scsi3_pr_seq_non_holder;
4393 pr_debug(
"%s: Using SPC3_PERSISTENT_RESERVATIONS"
4397 rest->
pr_ops.t10_reservation_check = &core_scsi2_reservation_check;
4398 rest->
pr_ops.t10_seq_non_holder =
4399 &core_scsi2_reservation_seq_non_holder;
4400 pr_debug(
"%s: Using SPC2_RESERVATIONS emulation\n",