Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending

Pull SCSI target updates from Nicholas Bellinger:
"It's been a busy development cycle for target-core in a number of
different areas.

The fabric API usage for se_node_acl allocation is now within
target-core code, dropping the external API callers for all fabric
drivers tree-wide.

There is a new conversion to RCU hlists for se_node_acl and
se_portal_group LUN mappings, that turns fast-past LUN lookup into a
completely lockless code-path. It also removes the original
hard-coded limitation of 256 LUNs per fabric endpoint.

The configfs attributes for backends can now be shared between core
and driver code, allowing existing drivers to use common code while
still allowing flexibility for new backend provided attributes.

The highlights include:

- Merge sbc_verify_dif_* into common code (sagi)
- Remove iscsi-target support for obsolete IFMarker/OFMarker
(Christophe Vu-Brugier)
- Add bidi support in target/user backend (ilias + vangelis + agover)
- Move se_node_acl allocation into target-core code (hch)
- Add crc_t10dif_update common helper (akinobu + mkp)
- Handle target-core odd SGL mapping for data transfer memory
(akinobu)
- Move transport ID handling into target-core (hch)
- Move task tag into struct se_cmd + support 64-bit tags (bart)
- Convert se_node_acl->device_list[] to RCU hlist (nab + hch +
paulmck)
- Convert se_portal_group->tpg_lun_list[] to RCU hlist (nab + hch +
paulmck)
- Simplify target backend driver registration (hch)
- Consolidate + simplify target backend attribute implementations
(hch + nab)
- Subsume se_port + t10_alua_tg_pt_gp_member into se_lun (hch)
- Drop lun_sep_lock for se_lun->lun_se_dev RCU usage (hch + nab)
- Drop unnecessary core_tpg_register TFO parameter (nab)
- Use 64-bit LUNs tree-wide (hannes)
- Drop left-over TARGET_MAX_LUNS_PER_TRANSPORT limit (hannes)"

* 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (76 commits)
target: Bump core version to v5.0
target: remove target_core_configfs.h
target: remove unused TARGET_CORE_CONFIG_ROOT define
target: consolidate version defines
target: implement WRITE_SAME with UNMAP bit using ->execute_unmap
target: simplify UNMAP handling
target: replace se_cmd->execute_rw with a protocol_data field
target/user: Fix inconsistent kmap_atomic/kunmap_atomic
target: Send UA when changing LUN inventory
target: Send UA upon LUN RESET tmr completion
target: Send UA on ALUA target port group change
target: Convert se_lun->lun_deve_lock to normal spinlock
target: use 'se_dev_entry' when allocating UAs
target: Remove 'ua_nacl' pointer from se_ua structure
target_core_alua: Correct UA handling when switching states
xen-scsiback: Fix compile warning for 64-bit LUN
target: Remove TARGET_MAX_LUNS_PER_TRANSPORT
target: use 64-bit LUNs
target: Drop duplicate + unused se_dev_check_wce
target: Drop unnecessary core_tpg_register TFO parameter
...

+3152 -6301
+1 -276
Documentation/target/tcm_mod_builder.py
··· 50 50 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" 51 51 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" 52 52 buf += "\n" 53 - buf += "struct " + fabric_mod_name + "_nacl {\n" 54 - buf += " /* Binary World Wide unique Port Name for FC Initiator Nport */\n" 55 - buf += " u64 nport_wwpn;\n" 56 - buf += " /* ASCII formatted WWPN for FC Initiator Nport */\n" 57 - buf += " char nport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 58 - buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n" 59 - buf += " struct se_node_acl se_node_acl;\n" 60 - buf += "};\n" 61 - buf += "\n" 62 53 buf += "struct " + fabric_mod_name + "_tpg {\n" 63 54 buf += " /* FC lport target portal group tag for TCM */\n" 64 55 buf += " u16 lport_tpgt;\n" ··· 60 69 buf += "};\n" 61 70 buf += "\n" 62 71 buf += "struct " + fabric_mod_name + "_lport {\n" 63 - buf += " /* SCSI protocol the lport is providing */\n" 64 - buf += " u8 lport_proto_id;\n" 65 72 buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" 66 73 buf += " u64 lport_wwpn;\n" 67 74 buf += " /* ASCII formatted WWPN for FC Target Lport */\n" ··· 94 105 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" 95 106 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" 96 107 buf += "\n" 97 - buf += "struct " + fabric_mod_name + "_nacl {\n" 98 - buf += " /* Binary World Wide unique Port Name for SAS Initiator port */\n" 99 - buf += " u64 iport_wwpn;\n" 100 - buf += " /* ASCII formatted WWPN for Sas Initiator port */\n" 101 - buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 102 - buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n" 103 - buf += " struct se_node_acl se_node_acl;\n" 104 - buf += "};\n\n" 105 108 buf += "struct " + fabric_mod_name + "_tpg {\n" 106 109 buf += " /* SAS port target portal group tag for TCM */\n" 107 110 buf += " u16 tport_tpgt;\n" ··· 103 122 buf += " struct se_portal_group se_tpg;\n" 104 123 buf += "};\n\n" 105 124 buf += "struct " + fabric_mod_name + "_tport {\n" 106 - buf += " /* SCSI protocol the tport is providing */\n" 107 - buf += " u8 tport_proto_id;\n" 108 125 buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" 109 126 buf += " u64 tport_wwpn;\n" 110 127 buf += " /* ASCII formatted WWPN for SAS Target port */\n" ··· 137 158 buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" 138 159 buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" 139 160 buf += "\n" 140 - buf += "struct " + fabric_mod_name + "_nacl {\n" 141 - buf += " /* ASCII formatted InitiatorName */\n" 142 - buf += " char iport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 143 - buf += " /* Returned by " + fabric_mod_name + "_make_nodeacl() */\n" 144 - buf += " struct se_node_acl se_node_acl;\n" 145 - buf += "};\n\n" 146 161 buf += "struct " + fabric_mod_name + "_tpg {\n" 147 162 buf += " /* iSCSI target portal group tag for TCM */\n" 148 163 buf += " u16 tport_tpgt;\n" ··· 146 173 buf += " struct se_portal_group se_tpg;\n" 147 174 buf += "};\n\n" 148 175 buf += "struct " + fabric_mod_name + "_tport {\n" 149 - buf += " /* SCSI protocol the tport is providing */\n" 150 - buf += " u8 tport_proto_id;\n" 151 176 buf += " /* ASCII formatted TargetName for IQN */\n" 152 177 buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" 153 178 buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" ··· 203 232 buf += "#include <target/target_core_base.h>\n" 204 233 buf += "#include <target/target_core_fabric.h>\n" 205 234 buf += "#include <target/target_core_fabric_configfs.h>\n" 206 - buf += "#include <target/target_core_configfs.h>\n" 207 235 buf += "#include <target/configfs_macros.h>\n\n" 208 236 buf += "#include \"" + fabric_mod_name + "_base.h\"\n" 209 237 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" 210 238 211 239 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops;\n\n" 212 - 213 - buf += "static struct se_node_acl *" + fabric_mod_name + "_make_nodeacl(\n" 214 - buf += " struct se_portal_group *se_tpg,\n" 215 - buf += " struct config_group *group,\n" 216 - buf += " const char *name)\n" 217 - buf += "{\n" 218 - buf += " struct se_node_acl *se_nacl, *se_nacl_new;\n" 219 - buf += " struct " + fabric_mod_name + "_nacl *nacl;\n" 220 - 221 - if proto_ident == "FC" or proto_ident == "SAS": 222 - buf += " u64 wwpn = 0;\n" 223 - 224 - buf += " u32 nexus_depth;\n\n" 225 - buf += " /* " + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n" 226 - buf += " return ERR_PTR(-EINVAL); */\n" 227 - buf += " se_nacl_new = " + fabric_mod_name + "_alloc_fabric_acl(se_tpg);\n" 228 - buf += " if (!se_nacl_new)\n" 229 - buf += " return ERR_PTR(-ENOMEM);\n" 230 - buf += "//#warning FIXME: Hardcoded nexus depth in " + fabric_mod_name + "_make_nodeacl()\n" 231 - buf += " nexus_depth = 1;\n" 232 - buf += " /*\n" 233 - buf += " * se_nacl_new may be released by core_tpg_add_initiator_node_acl()\n" 234 - buf += " * when converting a NodeACL from demo mode -> explict\n" 235 - buf += " */\n" 236 - buf += " se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new,\n" 237 - buf += " name, nexus_depth);\n" 238 - buf += " if (IS_ERR(se_nacl)) {\n" 239 - buf += " " + fabric_mod_name + "_release_fabric_acl(se_tpg, se_nacl_new);\n" 240 - buf += " return se_nacl;\n" 241 - buf += " }\n" 242 - buf += " /*\n" 243 - buf += " * Locate our struct " + fabric_mod_name + "_nacl and set the FC Nport WWPN\n" 244 - buf += " */\n" 245 - buf += " nacl = container_of(se_nacl, struct " + fabric_mod_name + "_nacl, se_node_acl);\n" 246 - 247 - if proto_ident == "FC" or proto_ident == "SAS": 248 - buf += " nacl->" + fabric_mod_init_port + "_wwpn = wwpn;\n" 249 - 250 - buf += " /* " + fabric_mod_name + "_format_wwn(&nacl->" + fabric_mod_init_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n" 251 - buf += " return se_nacl;\n" 252 - buf += "}\n\n" 253 - buf += "static void " + fabric_mod_name + "_drop_nodeacl(struct se_node_acl *se_acl)\n" 254 - buf += "{\n" 255 - buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_acl,\n" 256 - buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n" 257 - buf += " core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1);\n" 258 - buf += " kfree(nacl);\n" 259 - buf += "}\n\n" 260 240 261 241 buf += "static struct se_portal_group *" + fabric_mod_name + "_make_tpg(\n" 262 242 buf += " struct se_wwn *wwn,\n" ··· 231 309 buf += " tpg->" + fabric_mod_port + " = " + fabric_mod_port + ";\n" 232 310 buf += " tpg->" + fabric_mod_port + "_tpgt = tpgt;\n\n" 233 311 buf += " ret = core_tpg_register(&" + fabric_mod_name + "_ops, wwn,\n" 234 - buf += " &tpg->se_tpg, tpg,\n" 235 - buf += " TRANSPORT_TPG_TYPE_NORMAL);\n" 312 + buf += " &tpg->se_tpg, SCSI_PROTOCOL_SAS);\n" 236 313 buf += " if (ret < 0) {\n" 237 314 buf += " kfree(tpg);\n" 238 315 buf += " return NULL;\n" ··· 293 372 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n" 294 373 buf += " .module = THIS_MODULE,\n" 295 374 buf += " .name = " + fabric_mod_name + ",\n" 296 - buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n" 297 375 buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" 298 - buf += " .get_fabric_proto_ident = " + fabric_mod_name + "_get_fabric_proto_ident,\n" 299 376 buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" 300 377 buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n" 301 - buf += " .tpg_get_default_depth = " + fabric_mod_name + "_get_default_depth,\n" 302 - buf += " .tpg_get_pr_transport_id = " + fabric_mod_name + "_get_pr_transport_id,\n" 303 - buf += " .tpg_get_pr_transport_id_len = " + fabric_mod_name + "_get_pr_transport_id_len,\n" 304 - buf += " .tpg_parse_pr_out_transport_id = " + fabric_mod_name + "_parse_pr_out_transport_id,\n" 305 378 buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n" 306 379 buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n" 307 380 buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n" 308 381 buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n" 309 - buf += " .tpg_alloc_fabric_acl = " + fabric_mod_name + "_alloc_fabric_acl,\n" 310 - buf += " .tpg_release_fabric_acl = " + fabric_mod_name + "_release_fabric_acl,\n" 311 382 buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n" 312 383 buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n" 313 384 buf += " .shutdown_session = " + fabric_mod_name + "_shutdown_session,\n" ··· 309 396 buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n" 310 397 buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n" 311 398 buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n" 312 - buf += " .get_task_tag = " + fabric_mod_name + "_get_task_tag,\n" 313 399 buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n" 314 400 buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n" 315 401 buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n" ··· 321 409 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" 322 410 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" 323 411 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" 324 - buf += " .fabric_post_link = NULL,\n" 325 - buf += " .fabric_pre_unlink = NULL,\n" 326 - buf += " .fabric_make_np = NULL,\n" 327 - buf += " .fabric_drop_np = NULL,\n" 328 - buf += " .fabric_make_nodeacl = " + fabric_mod_name + "_make_nodeacl,\n" 329 - buf += " .fabric_drop_nodeacl = " + fabric_mod_name + "_drop_nodeacl,\n" 330 412 buf += "\n" 331 413 buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs;\n" 332 414 buf += "};\n\n" ··· 413 507 buf += "#include <scsi/scsi_proto.h>\n" 414 508 buf += "#include <target/target_core_base.h>\n" 415 509 buf += "#include <target/target_core_fabric.h>\n" 416 - buf += "#include <target/target_core_configfs.h>\n\n" 417 510 buf += "#include \"" + fabric_mod_name + "_base.h\"\n" 418 511 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" 419 512 ··· 444 539 bufi += "char *" + fabric_mod_name + "_get_fabric_name(void);\n" 445 540 continue 446 541 447 - if re.search('get_fabric_proto_ident', fo): 448 - buf += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *se_tpg)\n" 449 - buf += "{\n" 450 - buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 451 - buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" 452 - buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n" 453 - buf += " u8 proto_id;\n\n" 454 - buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n" 455 - if proto_ident == "FC": 456 - buf += " case SCSI_PROTOCOL_FCP:\n" 457 - buf += " default:\n" 458 - buf += " proto_id = fc_get_fabric_proto_ident(se_tpg);\n" 459 - buf += " break;\n" 460 - elif proto_ident == "SAS": 461 - buf += " case SCSI_PROTOCOL_SAS:\n" 462 - buf += " default:\n" 463 - buf += " proto_id = sas_get_fabric_proto_ident(se_tpg);\n" 464 - buf += " break;\n" 465 - elif proto_ident == "iSCSI": 466 - buf += " case SCSI_PROTOCOL_ISCSI:\n" 467 - buf += " default:\n" 468 - buf += " proto_id = iscsi_get_fabric_proto_ident(se_tpg);\n" 469 - buf += " break;\n" 470 - 471 - buf += " }\n\n" 472 - buf += " return proto_id;\n" 473 - buf += "}\n\n" 474 - bufi += "u8 " + fabric_mod_name + "_get_fabric_proto_ident(struct se_portal_group *);\n" 475 - 476 542 if re.search('get_wwn', fo): 477 543 buf += "char *" + fabric_mod_name + "_get_fabric_wwn(struct se_portal_group *se_tpg)\n" 478 544 buf += "{\n" ··· 462 586 buf += " return tpg->" + fabric_mod_port + "_tpgt;\n" 463 587 buf += "}\n\n" 464 588 bufi += "u16 " + fabric_mod_name + "_get_tag(struct se_portal_group *);\n" 465 - 466 - if re.search('get_default_depth', fo): 467 - buf += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *se_tpg)\n" 468 - buf += "{\n" 469 - buf += " return 1;\n" 470 - buf += "}\n\n" 471 - bufi += "u32 " + fabric_mod_name + "_get_default_depth(struct se_portal_group *);\n" 472 - 473 - if re.search('get_pr_transport_id\)\(', fo): 474 - buf += "u32 " + fabric_mod_name + "_get_pr_transport_id(\n" 475 - buf += " struct se_portal_group *se_tpg,\n" 476 - buf += " struct se_node_acl *se_nacl,\n" 477 - buf += " struct t10_pr_registration *pr_reg,\n" 478 - buf += " int *format_code,\n" 479 - buf += " unsigned char *buf)\n" 480 - buf += "{\n" 481 - buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 482 - buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" 483 - buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n" 484 - buf += " int ret = 0;\n\n" 485 - buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n" 486 - if proto_ident == "FC": 487 - buf += " case SCSI_PROTOCOL_FCP:\n" 488 - buf += " default:\n" 489 - buf += " ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n" 490 - buf += " format_code, buf);\n" 491 - buf += " break;\n" 492 - elif proto_ident == "SAS": 493 - buf += " case SCSI_PROTOCOL_SAS:\n" 494 - buf += " default:\n" 495 - buf += " ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n" 496 - buf += " format_code, buf);\n" 497 - buf += " break;\n" 498 - elif proto_ident == "iSCSI": 499 - buf += " case SCSI_PROTOCOL_ISCSI:\n" 500 - buf += " default:\n" 501 - buf += " ret = iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg,\n" 502 - buf += " format_code, buf);\n" 503 - buf += " break;\n" 504 - 505 - buf += " }\n\n" 506 - buf += " return ret;\n" 507 - buf += "}\n\n" 508 - bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id(struct se_portal_group *,\n" 509 - bufi += " struct se_node_acl *, struct t10_pr_registration *,\n" 510 - bufi += " int *, unsigned char *);\n" 511 - 512 - if re.search('get_pr_transport_id_len\)\(', fo): 513 - buf += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(\n" 514 - buf += " struct se_portal_group *se_tpg,\n" 515 - buf += " struct se_node_acl *se_nacl,\n" 516 - buf += " struct t10_pr_registration *pr_reg,\n" 517 - buf += " int *format_code)\n" 518 - buf += "{\n" 519 - buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 520 - buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" 521 - buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n" 522 - buf += " int ret = 0;\n\n" 523 - buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n" 524 - if proto_ident == "FC": 525 - buf += " case SCSI_PROTOCOL_FCP:\n" 526 - buf += " default:\n" 527 - buf += " ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n" 528 - buf += " format_code);\n" 529 - buf += " break;\n" 530 - elif proto_ident == "SAS": 531 - buf += " case SCSI_PROTOCOL_SAS:\n" 532 - buf += " default:\n" 533 - buf += " ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n" 534 - buf += " format_code);\n" 535 - buf += " break;\n" 536 - elif proto_ident == "iSCSI": 537 - buf += " case SCSI_PROTOCOL_ISCSI:\n" 538 - buf += " default:\n" 539 - buf += " ret = iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg,\n" 540 - buf += " format_code);\n" 541 - buf += " break;\n" 542 - 543 - 544 - buf += " }\n\n" 545 - buf += " return ret;\n" 546 - buf += "}\n\n" 547 - bufi += "u32 " + fabric_mod_name + "_get_pr_transport_id_len(struct se_portal_group *,\n" 548 - bufi += " struct se_node_acl *, struct t10_pr_registration *,\n" 549 - bufi += " int *);\n" 550 - 551 - if re.search('parse_pr_out_transport_id\)\(', fo): 552 - buf += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(\n" 553 - buf += " struct se_portal_group *se_tpg,\n" 554 - buf += " const char *buf,\n" 555 - buf += " u32 *out_tid_len,\n" 556 - buf += " char **port_nexus_ptr)\n" 557 - buf += "{\n" 558 - buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" 559 - buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n" 560 - buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = tpg->" + fabric_mod_port + ";\n" 561 - buf += " char *tid = NULL;\n\n" 562 - buf += " switch (" + fabric_mod_port + "->" + fabric_mod_port + "_proto_id) {\n" 563 - if proto_ident == "FC": 564 - buf += " case SCSI_PROTOCOL_FCP:\n" 565 - buf += " default:\n" 566 - buf += " tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n" 567 - buf += " port_nexus_ptr);\n" 568 - elif proto_ident == "SAS": 569 - buf += " case SCSI_PROTOCOL_SAS:\n" 570 - buf += " default:\n" 571 - buf += " tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n" 572 - buf += " port_nexus_ptr);\n" 573 - elif proto_ident == "iSCSI": 574 - buf += " case SCSI_PROTOCOL_ISCSI:\n" 575 - buf += " default:\n" 576 - buf += " tid = iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len,\n" 577 - buf += " port_nexus_ptr);\n" 578 - 579 - buf += " }\n\n" 580 - buf += " return tid;\n" 581 - buf += "}\n\n" 582 - bufi += "char *" + fabric_mod_name + "_parse_pr_out_transport_id(struct se_portal_group *,\n" 583 - bufi += " const char *, u32 *, char **);\n" 584 - 585 - if re.search('alloc_fabric_acl\)\(', fo): 586 - buf += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *se_tpg)\n" 587 - buf += "{\n" 588 - buf += " struct " + fabric_mod_name + "_nacl *nacl;\n\n" 589 - buf += " nacl = kzalloc(sizeof(struct " + fabric_mod_name + "_nacl), GFP_KERNEL);\n" 590 - buf += " if (!nacl) {\n" 591 - buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_nacl\\n\");\n" 592 - buf += " return NULL;\n" 593 - buf += " }\n\n" 594 - buf += " return &nacl->se_node_acl;\n" 595 - buf += "}\n\n" 596 - bufi += "struct se_node_acl *" + fabric_mod_name + "_alloc_fabric_acl(struct se_portal_group *);\n" 597 - 598 - if re.search('release_fabric_acl\)\(', fo): 599 - buf += "void " + fabric_mod_name + "_release_fabric_acl(\n" 600 - buf += " struct se_portal_group *se_tpg,\n" 601 - buf += " struct se_node_acl *se_nacl)\n" 602 - buf += "{\n" 603 - buf += " struct " + fabric_mod_name + "_nacl *nacl = container_of(se_nacl,\n" 604 - buf += " struct " + fabric_mod_name + "_nacl, se_node_acl);\n" 605 - buf += " kfree(nacl);\n" 606 - buf += "}\n\n" 607 - bufi += "void " + fabric_mod_name + "_release_fabric_acl(struct se_portal_group *,\n" 608 - bufi += " struct se_node_acl *);\n" 609 589 610 590 if re.search('tpg_get_inst_index\)\(', fo): 611 591 buf += "u32 " + fabric_mod_name + "_tpg_get_inst_index(struct se_portal_group *se_tpg)\n" ··· 518 786 buf += " return;\n" 519 787 buf += "}\n\n" 520 788 bufi += "void " + fabric_mod_name + "_set_default_node_attrs(struct se_node_acl *);\n" 521 - 522 - if re.search('get_task_tag\)\(', fo): 523 - buf += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *se_cmd)\n" 524 - buf += "{\n" 525 - buf += " return 0;\n" 526 - buf += "}\n\n" 527 - bufi += "u32 " + fabric_mod_name + "_get_task_tag(struct se_cmd *);\n" 528 789 529 790 if re.search('get_cmd_state\)\(', fo): 530 791 buf += "int " + fabric_mod_name + "_get_cmd_state(struct se_cmd *se_cmd)\n"
+2 -2
Documentation/target/tcm_mod_builder.txt
··· 13 13 This script will create a new drivers/target/$TCM_NEW_MOD/, and will do the following 14 14 15 15 *) Generate new API callers for drivers/target/target_core_fabric_configs.c logic 16 - ->make_nodeacl(), ->drop_nodeacl(), ->make_tpg(), ->drop_tpg() 17 - ->make_wwn(), ->drop_wwn(). These are created into $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c 16 + ->make_tpg(), ->drop_tpg(), ->make_wwn(), ->drop_wwn(). These are created 17 + into $TCM_NEW_MOD/$TCM_NEW_MOD_configfs.c 18 18 *) Generate basic infrastructure for loading/unloading LKMs and TCM/ConfigFS fabric module 19 19 using a skeleton struct target_core_fabric_ops API template. 20 20 *) Based on user defined T10 Proto_Ident for the new fabric module being built,
+1 -1
Documentation/target/tcmu-design.txt
··· 152 152 are accessible via tht req.iov[] array. iov_cnt contains the number of 153 153 entries in iov[] needed to describe either the Data-In or Data-Out 154 154 buffers. For bidirectional commands, iov_cnt specifies how many iovec 155 - entries cover the Data-Out area, and iov_bidi_count specifies how many 155 + entries cover the Data-Out area, and iov_bidi_cnt specifies how many 156 156 iovec entries immediately after that in iov[] cover the Data-In 157 157 area. Just like other fields, iov.iov_base is an offset from the start 158 158 of the region.
+3 -3
drivers/infiniband/ulp/isert/ib_isert.c
··· 1356 1356 if (!rc && dump_payload == false && unsol_data) 1357 1357 iscsit_set_unsoliticed_dataout(cmd); 1358 1358 else if (dump_payload && imm_data) 1359 - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); 1359 + target_put_sess_cmd(&cmd->se_cmd); 1360 1360 1361 1361 return 0; 1362 1362 } ··· 1781 1781 cmd->se_cmd.t_state == TRANSPORT_WRITE_PENDING) { 1782 1782 struct se_cmd *se_cmd = &cmd->se_cmd; 1783 1783 1784 - target_put_sess_cmd(se_cmd->se_sess, se_cmd); 1784 + target_put_sess_cmd(se_cmd); 1785 1785 } 1786 1786 } 1787 1787 ··· 1954 1954 spin_unlock_bh(&cmd->istate_lock); 1955 1955 1956 1956 if (ret) { 1957 - target_put_sess_cmd(se_cmd->se_sess, se_cmd); 1957 + target_put_sess_cmd(se_cmd); 1958 1958 transport_send_check_condition_and_sense(se_cmd, 1959 1959 se_cmd->pi_err, 0); 1960 1960 } else {
+29 -154
drivers/infiniband/ulp/srpt/ib_srpt.c
··· 47 47 #include <target/target_core_base.h> 48 48 #include <target/target_core_fabric_configfs.h> 49 49 #include <target/target_core_fabric.h> 50 - #include <target/target_core_configfs.h> 51 50 #include "ib_srpt.h" 52 51 53 52 /* Name of this kernel module. */ ··· 93 94 " instead of using the node_guid of the first HCA."); 94 95 95 96 static struct ib_client srpt_client; 96 - static const struct target_core_fabric_ops srpt_template; 97 97 static void srpt_release_channel(struct srpt_rdma_ch *ch); 98 98 static int srpt_queue_status(struct se_cmd *cmd); 99 99 ··· 1334 1336 1335 1337 BUG_ON(ch->sess == NULL); 1336 1338 1337 - target_put_sess_cmd(ch->sess, &ioctx->cmd); 1339 + target_put_sess_cmd(&ioctx->cmd); 1338 1340 goto out; 1339 1341 } 1340 1342 1341 1343 pr_debug("Aborting cmd with state %d and tag %lld\n", state, 1342 - ioctx->tag); 1344 + ioctx->cmd.tag); 1343 1345 1344 1346 switch (state) { 1345 1347 case SRPT_STATE_NEW: ··· 1365 1367 * not been received in time. 1366 1368 */ 1367 1369 srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx); 1368 - target_put_sess_cmd(ioctx->ch->sess, &ioctx->cmd); 1370 + target_put_sess_cmd(&ioctx->cmd); 1369 1371 break; 1370 1372 case SRPT_STATE_MGMT_RSP_SENT: 1371 1373 srpt_set_cmd_state(ioctx, SRPT_STATE_DONE); 1372 - target_put_sess_cmd(ioctx->ch->sess, &ioctx->cmd); 1374 + target_put_sess_cmd(&ioctx->cmd); 1373 1375 break; 1374 1376 default: 1375 1377 WARN(1, "Unexpected command state (%d)", state); ··· 1387 1389 { 1388 1390 struct srpt_send_ioctx *ioctx; 1389 1391 enum srpt_command_state state; 1390 - struct se_cmd *cmd; 1391 1392 u32 index; 1392 1393 1393 1394 atomic_inc(&ch->sq_wr_avail); ··· 1394 1397 index = idx_from_wr_id(wr_id); 1395 1398 ioctx = ch->ioctx_ring[index]; 1396 1399 state = srpt_get_cmd_state(ioctx); 1397 - cmd = &ioctx->cmd; 1398 1400 1399 1401 WARN_ON(state != SRPT_STATE_CMD_RSP_SENT 1400 1402 && state != SRPT_STATE_MGMT_RSP_SENT ··· 1470 1474 struct srpt_send_ioctx *ioctx, 1471 1475 enum srpt_opcode opcode) 1472 1476 { 1473 - struct se_cmd *cmd; 1474 1477 enum srpt_command_state state; 1475 1478 1476 - cmd = &ioctx->cmd; 1477 1479 state = srpt_get_cmd_state(ioctx); 1478 1480 switch (opcode) { 1479 1481 case SRPT_RDMA_READ_LAST: ··· 1675 1681 struct srpt_send_ioctx *ioctx = container_of(cmd, 1676 1682 struct srpt_send_ioctx, cmd); 1677 1683 1678 - return target_put_sess_cmd(ioctx->ch->sess, &ioctx->cmd); 1684 + return target_put_sess_cmd(&ioctx->cmd); 1679 1685 } 1680 1686 1681 1687 /** ··· 1697 1703 1698 1704 srp_cmd = recv_ioctx->ioctx.buf; 1699 1705 cmd = &send_ioctx->cmd; 1700 - send_ioctx->tag = srp_cmd->tag; 1706 + cmd->tag = srp_cmd->tag; 1701 1707 1702 1708 switch (srp_cmd->task_attr) { 1703 1709 case SRP_CMD_SIMPLE_Q: ··· 1768 1774 for (i = 0; i < ch->rq_size; ++i) { 1769 1775 target = ch->ioctx_ring[i]; 1770 1776 if (target->cmd.se_lun == ioctx->cmd.se_lun && 1771 - target->tag == tag && 1777 + target->cmd.tag == tag && 1772 1778 srpt_get_cmd_state(target) != SRPT_STATE_DONE) { 1773 1779 ret = 0; 1774 1780 /* now let the target core abort &target->cmd; */ ··· 1827 1833 srp_tsk->task_tag, srp_tsk->tag, ch->cm_id, ch->sess); 1828 1834 1829 1835 srpt_set_cmd_state(send_ioctx, SRPT_STATE_MGMT); 1830 - send_ioctx->tag = srp_tsk->tag; 1836 + send_ioctx->cmd.tag = srp_tsk->tag; 1831 1837 tcm_tmr = srp_tmr_to_tcm(srp_tsk->tsk_mgmt_func); 1832 1838 if (tcm_tmr < 0) { 1833 1839 send_ioctx->cmd.se_tmr_req->response = ··· 2174 2180 */ 2175 2181 static void __srpt_close_ch(struct srpt_rdma_ch *ch) 2176 2182 { 2177 - struct srpt_device *sdev; 2178 2183 enum rdma_ch_state prev_state; 2179 2184 unsigned long flags; 2180 - 2181 - sdev = ch->sport->sdev; 2182 2185 2183 2186 spin_lock_irqsave(&ch->spinlock, flags); 2184 2187 prev_state = ch->state; ··· 2974 2983 case CH_DRAINING: 2975 2984 case CH_RELEASING: 2976 2985 pr_debug("cmd with tag %lld: channel disconnecting\n", 2977 - ioctx->tag); 2986 + ioctx->cmd.tag); 2978 2987 srpt_set_cmd_state(ioctx, SRPT_STATE_DATA_IN); 2979 2988 ret = -EINVAL; 2980 2989 goto out; ··· 3049 3058 ret = srpt_xfer_data(ch, ioctx); 3050 3059 if (ret) { 3051 3060 pr_err("xfer_data failed for tag %llu\n", 3052 - ioctx->tag); 3061 + ioctx->cmd.tag); 3053 3062 return; 3054 3063 } 3055 3064 } 3056 3065 3057 3066 if (state != SRPT_STATE_MGMT) 3058 - resp_len = srpt_build_cmd_rsp(ch, ioctx, ioctx->tag, 3067 + resp_len = srpt_build_cmd_rsp(ch, ioctx, ioctx->cmd.tag, 3059 3068 cmd->scsi_status); 3060 3069 else { 3061 3070 srp_tm_status 3062 3071 = tcm_to_srp_tsk_mgmt_status(cmd->se_tmr_req->response); 3063 3072 resp_len = srpt_build_tskmgmt_rsp(ch, ioctx, srp_tm_status, 3064 - ioctx->tag); 3073 + ioctx->cmd.tag); 3065 3074 } 3066 3075 ret = srpt_post_send(ch, ioctx, resp_len); 3067 3076 if (ret) { 3068 3077 pr_err("sending cmd response failed for tag %llu\n", 3069 - ioctx->tag); 3078 + ioctx->cmd.tag); 3070 3079 srpt_unmap_sg_to_ib_sge(ch, ioctx); 3071 3080 srpt_set_cmd_state(ioctx, SRPT_STATE_DONE); 3072 - target_put_sess_cmd(ioctx->ch->sess, &ioctx->cmd); 3081 + target_put_sess_cmd(&ioctx->cmd); 3073 3082 } 3074 3083 } 3075 3084 ··· 3389 3398 return "srpt"; 3390 3399 } 3391 3400 3392 - static u8 srpt_get_fabric_proto_ident(struct se_portal_group *se_tpg) 3393 - { 3394 - return SCSI_TRANSPORTID_PROTOCOLID_SRP; 3395 - } 3396 - 3397 3401 static char *srpt_get_fabric_wwn(struct se_portal_group *tpg) 3398 3402 { 3399 3403 struct srpt_port *sport = container_of(tpg, struct srpt_port, port_tpg_1); ··· 3399 3413 static u16 srpt_get_tag(struct se_portal_group *tpg) 3400 3414 { 3401 3415 return 1; 3402 - } 3403 - 3404 - static u32 srpt_get_default_depth(struct se_portal_group *se_tpg) 3405 - { 3406 - return 1; 3407 - } 3408 - 3409 - static u32 srpt_get_pr_transport_id(struct se_portal_group *se_tpg, 3410 - struct se_node_acl *se_nacl, 3411 - struct t10_pr_registration *pr_reg, 3412 - int *format_code, unsigned char *buf) 3413 - { 3414 - struct srpt_node_acl *nacl; 3415 - struct spc_rdma_transport_id *tr_id; 3416 - 3417 - nacl = container_of(se_nacl, struct srpt_node_acl, nacl); 3418 - tr_id = (void *)buf; 3419 - tr_id->protocol_identifier = SCSI_TRANSPORTID_PROTOCOLID_SRP; 3420 - memcpy(tr_id->i_port_id, nacl->i_port_id, sizeof(tr_id->i_port_id)); 3421 - return sizeof(*tr_id); 3422 - } 3423 - 3424 - static u32 srpt_get_pr_transport_id_len(struct se_portal_group *se_tpg, 3425 - struct se_node_acl *se_nacl, 3426 - struct t10_pr_registration *pr_reg, 3427 - int *format_code) 3428 - { 3429 - *format_code = 0; 3430 - return sizeof(struct spc_rdma_transport_id); 3431 - } 3432 - 3433 - static char *srpt_parse_pr_out_transport_id(struct se_portal_group *se_tpg, 3434 - const char *buf, u32 *out_tid_len, 3435 - char **port_nexus_ptr) 3436 - { 3437 - struct spc_rdma_transport_id *tr_id; 3438 - 3439 - *port_nexus_ptr = NULL; 3440 - *out_tid_len = sizeof(struct spc_rdma_transport_id); 3441 - tr_id = (void *)buf; 3442 - return (char *)tr_id->i_port_id; 3443 - } 3444 - 3445 - static struct se_node_acl *srpt_alloc_fabric_acl(struct se_portal_group *se_tpg) 3446 - { 3447 - struct srpt_node_acl *nacl; 3448 - 3449 - nacl = kzalloc(sizeof(struct srpt_node_acl), GFP_KERNEL); 3450 - if (!nacl) { 3451 - pr_err("Unable to allocate struct srpt_node_acl\n"); 3452 - return NULL; 3453 - } 3454 - 3455 - return &nacl->nacl; 3456 - } 3457 - 3458 - static void srpt_release_fabric_acl(struct se_portal_group *se_tpg, 3459 - struct se_node_acl *se_nacl) 3460 - { 3461 - struct srpt_node_acl *nacl; 3462 - 3463 - nacl = container_of(se_nacl, struct srpt_node_acl, nacl); 3464 - kfree(nacl); 3465 3416 } 3466 3417 3467 3418 static u32 srpt_tpg_get_inst_index(struct se_portal_group *se_tpg) ··· 3474 3551 { 3475 3552 } 3476 3553 3477 - static u32 srpt_get_task_tag(struct se_cmd *se_cmd) 3478 - { 3479 - struct srpt_send_ioctx *ioctx; 3480 - 3481 - ioctx = container_of(se_cmd, struct srpt_send_ioctx, cmd); 3482 - return ioctx->tag; 3483 - } 3484 - 3485 3554 /* Note: only used from inside debug printk's by the TCM core. */ 3486 3555 static int srpt_get_tcm_cmd_state(struct se_cmd *se_cmd) 3487 3556 { ··· 3516 3601 * configfs callback function invoked for 3517 3602 * mkdir /sys/kernel/config/target/$driver/$port/$tpg/acls/$i_port_id 3518 3603 */ 3519 - static struct se_node_acl *srpt_make_nodeacl(struct se_portal_group *tpg, 3520 - struct config_group *group, 3521 - const char *name) 3604 + static int srpt_init_nodeacl(struct se_node_acl *se_nacl, const char *name) 3522 3605 { 3523 - struct srpt_port *sport = container_of(tpg, struct srpt_port, port_tpg_1); 3524 - struct se_node_acl *se_nacl, *se_nacl_new; 3525 - struct srpt_node_acl *nacl; 3526 - int ret = 0; 3527 - u32 nexus_depth = 1; 3606 + struct srpt_port *sport = 3607 + container_of(se_nacl->se_tpg, struct srpt_port, port_tpg_1); 3608 + struct srpt_node_acl *nacl = 3609 + container_of(se_nacl, struct srpt_node_acl, nacl); 3528 3610 u8 i_port_id[16]; 3529 3611 3530 3612 if (srpt_parse_i_port_id(i_port_id, name) < 0) { 3531 3613 pr_err("invalid initiator port ID %s\n", name); 3532 - ret = -EINVAL; 3533 - goto err; 3614 + return -EINVAL; 3534 3615 } 3535 3616 3536 - se_nacl_new = srpt_alloc_fabric_acl(tpg); 3537 - if (!se_nacl_new) { 3538 - ret = -ENOMEM; 3539 - goto err; 3540 - } 3541 - /* 3542 - * nacl_new may be released by core_tpg_add_initiator_node_acl() 3543 - * when converting a node ACL from demo mode to explict 3544 - */ 3545 - se_nacl = core_tpg_add_initiator_node_acl(tpg, se_nacl_new, name, 3546 - nexus_depth); 3547 - if (IS_ERR(se_nacl)) { 3548 - ret = PTR_ERR(se_nacl); 3549 - goto err; 3550 - } 3551 - /* Locate our struct srpt_node_acl and set sdev and i_port_id. */ 3552 - nacl = container_of(se_nacl, struct srpt_node_acl, nacl); 3553 3617 memcpy(&nacl->i_port_id[0], &i_port_id[0], 16); 3554 3618 nacl->sport = sport; 3555 3619 ··· 3536 3642 list_add_tail(&nacl->list, &sport->port_acl_list); 3537 3643 spin_unlock_irq(&sport->port_acl_lock); 3538 3644 3539 - return se_nacl; 3540 - err: 3541 - return ERR_PTR(ret); 3645 + return 0; 3542 3646 } 3543 3647 3544 3648 /* 3545 3649 * configfs callback function invoked for 3546 3650 * rmdir /sys/kernel/config/target/$driver/$port/$tpg/acls/$i_port_id 3547 3651 */ 3548 - static void srpt_drop_nodeacl(struct se_node_acl *se_nacl) 3652 + static void srpt_cleanup_nodeacl(struct se_node_acl *se_nacl) 3549 3653 { 3550 - struct srpt_node_acl *nacl; 3551 - struct srpt_device *sdev; 3552 - struct srpt_port *sport; 3654 + struct srpt_node_acl *nacl = 3655 + container_of(se_nacl, struct srpt_node_acl, nacl); 3656 + struct srpt_port *sport = nacl->sport; 3553 3657 3554 - nacl = container_of(se_nacl, struct srpt_node_acl, nacl); 3555 - sport = nacl->sport; 3556 - sdev = sport->sdev; 3557 3658 spin_lock_irq(&sport->port_acl_lock); 3558 3659 list_del(&nacl->list); 3559 3660 spin_unlock_irq(&sport->port_acl_lock); 3560 - core_tpg_del_initiator_node_acl(&sport->port_tpg_1, se_nacl, 1); 3561 - srpt_release_fabric_acl(NULL, se_nacl); 3562 3661 } 3563 3662 3564 3663 static ssize_t srpt_tpg_attrib_show_srp_max_rdma_size( ··· 3736 3849 int res; 3737 3850 3738 3851 /* Initialize sport->port_wwn and sport->port_tpg_1 */ 3739 - res = core_tpg_register(&srpt_template, &sport->port_wwn, 3740 - &sport->port_tpg_1, sport, TRANSPORT_TPG_TYPE_NORMAL); 3852 + res = core_tpg_register(&sport->port_wwn, &sport->port_tpg_1, SCSI_PROTOCOL_SRP); 3741 3853 if (res) 3742 3854 return ERR_PTR(res); 3743 3855 ··· 3806 3920 static const struct target_core_fabric_ops srpt_template = { 3807 3921 .module = THIS_MODULE, 3808 3922 .name = "srpt", 3923 + .node_acl_size = sizeof(struct srpt_node_acl), 3809 3924 .get_fabric_name = srpt_get_fabric_name, 3810 - .get_fabric_proto_ident = srpt_get_fabric_proto_ident, 3811 3925 .tpg_get_wwn = srpt_get_fabric_wwn, 3812 3926 .tpg_get_tag = srpt_get_tag, 3813 - .tpg_get_default_depth = srpt_get_default_depth, 3814 - .tpg_get_pr_transport_id = srpt_get_pr_transport_id, 3815 - .tpg_get_pr_transport_id_len = srpt_get_pr_transport_id_len, 3816 - .tpg_parse_pr_out_transport_id = srpt_parse_pr_out_transport_id, 3817 3927 .tpg_check_demo_mode = srpt_check_false, 3818 3928 .tpg_check_demo_mode_cache = srpt_check_true, 3819 3929 .tpg_check_demo_mode_write_protect = srpt_check_true, 3820 3930 .tpg_check_prod_mode_write_protect = srpt_check_false, 3821 - .tpg_alloc_fabric_acl = srpt_alloc_fabric_acl, 3822 - .tpg_release_fabric_acl = srpt_release_fabric_acl, 3823 3931 .tpg_get_inst_index = srpt_tpg_get_inst_index, 3824 3932 .release_cmd = srpt_release_cmd, 3825 3933 .check_stop_free = srpt_check_stop_free, ··· 3824 3944 .write_pending = srpt_write_pending, 3825 3945 .write_pending_status = srpt_write_pending_status, 3826 3946 .set_default_node_attributes = srpt_set_default_node_attrs, 3827 - .get_task_tag = srpt_get_task_tag, 3828 3947 .get_cmd_state = srpt_get_tcm_cmd_state, 3829 3948 .queue_data_in = srpt_queue_data_in, 3830 3949 .queue_status = srpt_queue_status, ··· 3837 3958 .fabric_drop_wwn = srpt_drop_tport, 3838 3959 .fabric_make_tpg = srpt_make_tpg, 3839 3960 .fabric_drop_tpg = srpt_drop_tpg, 3840 - .fabric_post_link = NULL, 3841 - .fabric_pre_unlink = NULL, 3842 - .fabric_make_np = NULL, 3843 - .fabric_drop_np = NULL, 3844 - .fabric_make_nodeacl = srpt_make_nodeacl, 3845 - .fabric_drop_nodeacl = srpt_drop_nodeacl, 3961 + .fabric_init_nodeacl = srpt_init_nodeacl, 3962 + .fabric_cleanup_nodeacl = srpt_cleanup_nodeacl, 3846 3963 3847 3964 .tfc_wwn_attrs = srpt_wwn_attrs, 3848 3965 .tfc_tpg_base_attrs = srpt_tpg_attrs,
+2 -21
drivers/infiniband/ulp/srpt/ib_srpt.h
··· 238 238 bool rdma_aborted; 239 239 struct se_cmd cmd; 240 240 struct completion tx_done; 241 - u64 tag; 242 241 int sg_cnt; 243 242 int mapped_sg_count; 244 243 u16 n_rdma_ius; ··· 409 410 410 411 /** 411 412 * struct srpt_node_acl - Per-initiator ACL data (managed via configfs). 413 + * @nacl: Target core node ACL information. 412 414 * @i_port_id: 128-bit SRP initiator port ID. 413 415 * @sport: port information. 414 - * @nacl: Target core node ACL information. 415 416 * @list: Element of the per-HCA ACL list. 416 417 */ 417 418 struct srpt_node_acl { 419 + struct se_node_acl nacl; 418 420 u8 i_port_id[16]; 419 421 struct srpt_port *sport; 420 - struct se_node_acl nacl; 421 422 struct list_head list; 422 - }; 423 - 424 - /* 425 - * SRP-releated SCSI persistent reservation definitions. 426 - * 427 - * See also SPC4r28, section 7.6.1 (Protocol specific parameters introduction). 428 - * See also SPC4r28, section 7.6.4.5 (TransportID for initiator ports using 429 - * SCSI over an RDMA interface). 430 - */ 431 - 432 - enum { 433 - SCSI_TRANSPORTID_PROTOCOLID_SRP = 4, 434 - }; 435 - 436 - struct spc_rdma_transport_id { 437 - uint8_t protocol_identifier; 438 - uint8_t reserved[7]; 439 - uint8_t i_port_id[16]; 440 423 }; 441 424 442 425 #endif /* IB_SRPT_H */
+23 -29
drivers/scsi/qla2xxx/qla_target.c
··· 1191 1191 list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { 1192 1192 struct qla_tgt_cmd *cmd = 1193 1193 container_of(se_cmd, struct qla_tgt_cmd, se_cmd); 1194 - if (cmd->tag == abts->exchange_addr_to_abort) { 1194 + if (se_cmd->tag == abts->exchange_addr_to_abort) { 1195 1195 lun = cmd->unpacked_lun; 1196 1196 found_lun = true; 1197 1197 break; ··· 1728 1728 1729 1729 if (unlikely(cmd->aborted)) { 1730 1730 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf014, 1731 - "qla_target(%d): terminating exchange " 1732 - "for aborted cmd=%p (se_cmd=%p, tag=%d)", vha->vp_idx, cmd, 1733 - se_cmd, cmd->tag); 1731 + "qla_target(%d): terminating exchange for aborted cmd=%p (se_cmd=%p, tag=%lld)", 1732 + vha->vp_idx, cmd, se_cmd, se_cmd->tag); 1734 1733 1735 1734 cmd->state = QLA_TGT_STATE_ABORTED; 1736 1735 cmd->cmd_flags |= BIT_6; ··· 1764 1765 if (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { 1765 1766 prm->residual = se_cmd->residual_count; 1766 1767 ql_dbg(ql_dbg_io + ql_dbg_verbose, vha, 0x305c, 1767 - "Residual underflow: %d (tag %d, " 1768 - "op %x, bufflen %d, rq_result %x)\n", prm->residual, 1769 - cmd->tag, se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, 1770 - cmd->bufflen, prm->rq_result); 1768 + "Residual underflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", 1769 + prm->residual, se_cmd->tag, 1770 + se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, 1771 + cmd->bufflen, prm->rq_result); 1771 1772 prm->rq_result |= SS_RESIDUAL_UNDER; 1772 1773 } else if (se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { 1773 1774 prm->residual = se_cmd->residual_count; 1774 1775 ql_dbg(ql_dbg_io, vha, 0x305d, 1775 - "Residual overflow: %d (tag %d, " 1776 - "op %x, bufflen %d, rq_result %x)\n", prm->residual, 1777 - cmd->tag, se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, 1778 - cmd->bufflen, prm->rq_result); 1776 + "Residual overflow: %d (tag %lld, op %x, bufflen %d, rq_result %x)\n", 1777 + prm->residual, se_cmd->tag, se_cmd->t_task_cdb ? 1778 + se_cmd->t_task_cdb[0] : 0, cmd->bufflen, prm->rq_result); 1779 1779 prm->rq_result |= SS_RESIDUAL_OVER; 1780 1780 } 1781 1781 ··· 1847 1849 == 50) { 1848 1850 *xmit_type &= ~QLA_TGT_XMIT_STATUS; 1849 1851 ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf015, 1850 - "Dropping cmd %p (tag %d) status", cmd, cmd->tag); 1852 + "Dropping cmd %p (tag %d) status", cmd, se_cmd->tag); 1851 1853 } 1852 1854 #endif 1853 1855 /* ··· 1871 1873 ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf016, 1872 1874 "Cutting cmd %p (tag %d) buffer" 1873 1875 " tail to len %d, sg_cnt %d (cmd->bufflen %d," 1874 - " cmd->sg_cnt %d)", cmd, cmd->tag, tot_len, leave, 1876 + " cmd->sg_cnt %d)", cmd, se_cmd->tag, tot_len, leave, 1875 1877 cmd->bufflen, cmd->sg_cnt); 1876 1878 1877 1879 cmd->bufflen = tot_len; ··· 1883 1885 1884 1886 ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf017, 1885 1887 "Cutting cmd %p (tag %d) buffer head " 1886 - "to offset %d (cmd->bufflen %d)", cmd, cmd->tag, offset, 1888 + "to offset %d (cmd->bufflen %d)", cmd, se_cmd->tag, offset, 1887 1889 cmd->bufflen); 1888 1890 if (offset == 0) 1889 1891 *xmit_type &= ~QLA_TGT_XMIT_DATA; 1890 1892 else if (qlt_set_data_offset(cmd, offset)) { 1891 1893 ql_dbg(ql_dbg_tgt_mgt, cmd->vha, 0xf018, 1892 - "qlt_set_data_offset() failed (tag %d)", cmd->tag); 1894 + "qlt_set_data_offset() failed (tag %d)", se_cmd->tag); 1893 1895 } 1894 1896 } 1895 1897 } ··· 3192 3194 return; 3193 3195 } else if (cmd->state == QLA_TGT_STATE_ABORTED) { 3194 3196 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf01e, 3195 - "Aborted command %p (tag %d) finished\n", cmd, cmd->tag); 3197 + "Aborted command %p (tag %lld) finished\n", cmd, se_cmd->tag); 3196 3198 } else { 3197 3199 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf05c, 3198 3200 "qla_target(%d): A command in state (%d) should " ··· 3264 3266 goto out_term; 3265 3267 3266 3268 cdb = &atio->u.isp24.fcp_cmnd.cdb[0]; 3267 - cmd->tag = atio->u.isp24.exchange_addr; 3269 + cmd->se_cmd.tag = atio->u.isp24.exchange_addr; 3268 3270 cmd->unpacked_lun = scsilun_to_int( 3269 3271 (struct scsi_lun *)&atio->u.isp24.fcp_cmnd.lun); 3270 3272 ··· 3891 3893 resp = 1; 3892 3894 } else { 3893 3895 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf064, 3894 - "qla_target(%d): SRR for in data for cmd " 3895 - "without them (tag %d, SCSI status %d), " 3896 - "reject", vha->vp_idx, cmd->tag, 3896 + "qla_target(%d): SRR for in data for cmd without them (tag %lld, SCSI status %d), reject", 3897 + vha->vp_idx, se_cmd->tag, 3897 3898 cmd->se_cmd.scsi_status); 3898 3899 goto out_reject; 3899 3900 } ··· 3926 3929 } 3927 3930 } else { 3928 3931 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf066, 3929 - "qla_target(%d): SRR for out data for cmd " 3930 - "without them (tag %d, SCSI status %d), " 3931 - "reject", vha->vp_idx, cmd->tag, 3932 - cmd->se_cmd.scsi_status); 3932 + "qla_target(%d): SRR for out data for cmd without them (tag %lld, SCSI status %d), reject", 3933 + vha->vp_idx, se_cmd->tag, cmd->se_cmd.scsi_status); 3933 3934 goto out_reject; 3934 3935 } 3935 3936 break; ··· 4048 4053 cmd->sg = se_cmd->t_data_sg; 4049 4054 4050 4055 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf02c, 4051 - "SRR cmd %p (se_cmd %p, tag %d, op %x), " 4052 - "sg_cnt=%d, offset=%d", cmd, &cmd->se_cmd, cmd->tag, 4053 - se_cmd->t_task_cdb ? se_cmd->t_task_cdb[0] : 0, 4054 - cmd->sg_cnt, cmd->offset); 4056 + "SRR cmd %p (se_cmd %p, tag %lld, op %x), sg_cnt=%d, offset=%d", 4057 + cmd, &cmd->se_cmd, se_cmd->tag, se_cmd->t_task_cdb ? 4058 + se_cmd->t_task_cdb[0] : 0, cmd->sg_cnt, cmd->offset); 4055 4059 4056 4060 qlt_handle_srr(vha, sctio, imm); 4057 4061
-1
drivers/scsi/qla2xxx/qla_target.h
··· 924 924 int sg_cnt; /* SG segments count */ 925 925 int bufflen; /* cmd buffer length */ 926 926 int offset; 927 - uint32_t tag; 928 927 uint32_t unpacked_lun; 929 928 enum dma_data_direction dma_data_direction; 930 929 uint32_t reset_count;
+13 -214
drivers/scsi/qla2xxx/tcm_qla2xxx.c
··· 44 44 #include <target/target_core_base.h> 45 45 #include <target/target_core_fabric.h> 46 46 #include <target/target_core_fabric_configfs.h> 47 - #include <target/target_core_configfs.h> 48 47 #include <target/configfs_macros.h> 49 48 50 49 #include "qla_def.h" ··· 52 53 53 54 static struct workqueue_struct *tcm_qla2xxx_free_wq; 54 55 static struct workqueue_struct *tcm_qla2xxx_cmd_wq; 55 - 56 - static const struct target_core_fabric_ops tcm_qla2xxx_ops; 57 - static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops; 58 56 59 57 /* 60 58 * Parse WWN. ··· 187 191 return "qla2xxx_npiv"; 188 192 } 189 193 190 - static u8 tcm_qla2xxx_get_fabric_proto_ident(struct se_portal_group *se_tpg) 191 - { 192 - struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 193 - struct tcm_qla2xxx_tpg, se_tpg); 194 - struct tcm_qla2xxx_lport *lport = tpg->lport; 195 - u8 proto_id; 196 - 197 - switch (lport->lport_proto_id) { 198 - case SCSI_PROTOCOL_FCP: 199 - default: 200 - proto_id = fc_get_fabric_proto_ident(se_tpg); 201 - break; 202 - } 203 - 204 - return proto_id; 205 - } 206 - 207 194 static char *tcm_qla2xxx_get_fabric_wwn(struct se_portal_group *se_tpg) 208 195 { 209 196 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, ··· 201 222 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 202 223 struct tcm_qla2xxx_tpg, se_tpg); 203 224 return tpg->lport_tpgt; 204 - } 205 - 206 - static u32 tcm_qla2xxx_get_default_depth(struct se_portal_group *se_tpg) 207 - { 208 - return 1; 209 - } 210 - 211 - static u32 tcm_qla2xxx_get_pr_transport_id( 212 - struct se_portal_group *se_tpg, 213 - struct se_node_acl *se_nacl, 214 - struct t10_pr_registration *pr_reg, 215 - int *format_code, 216 - unsigned char *buf) 217 - { 218 - struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 219 - struct tcm_qla2xxx_tpg, se_tpg); 220 - struct tcm_qla2xxx_lport *lport = tpg->lport; 221 - int ret = 0; 222 - 223 - switch (lport->lport_proto_id) { 224 - case SCSI_PROTOCOL_FCP: 225 - default: 226 - ret = fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 227 - format_code, buf); 228 - break; 229 - } 230 - 231 - return ret; 232 - } 233 - 234 - static u32 tcm_qla2xxx_get_pr_transport_id_len( 235 - struct se_portal_group *se_tpg, 236 - struct se_node_acl *se_nacl, 237 - struct t10_pr_registration *pr_reg, 238 - int *format_code) 239 - { 240 - struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 241 - struct tcm_qla2xxx_tpg, se_tpg); 242 - struct tcm_qla2xxx_lport *lport = tpg->lport; 243 - int ret = 0; 244 - 245 - switch (lport->lport_proto_id) { 246 - case SCSI_PROTOCOL_FCP: 247 - default: 248 - ret = fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 249 - format_code); 250 - break; 251 - } 252 - 253 - return ret; 254 - } 255 - 256 - static char *tcm_qla2xxx_parse_pr_out_transport_id( 257 - struct se_portal_group *se_tpg, 258 - const char *buf, 259 - u32 *out_tid_len, 260 - char **port_nexus_ptr) 261 - { 262 - struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 263 - struct tcm_qla2xxx_tpg, se_tpg); 264 - struct tcm_qla2xxx_lport *lport = tpg->lport; 265 - char *tid = NULL; 266 - 267 - switch (lport->lport_proto_id) { 268 - case SCSI_PROTOCOL_FCP: 269 - default: 270 - tid = fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 271 - port_nexus_ptr); 272 - break; 273 - } 274 - 275 - return tid; 276 225 } 277 226 278 227 static int tcm_qla2xxx_check_demo_mode(struct se_portal_group *se_tpg) ··· 249 342 struct tcm_qla2xxx_tpg, se_tpg); 250 343 251 344 return tpg->tpg_attrib.fabric_prot_type; 252 - } 253 - 254 - static struct se_node_acl *tcm_qla2xxx_alloc_fabric_acl( 255 - struct se_portal_group *se_tpg) 256 - { 257 - struct tcm_qla2xxx_nacl *nacl; 258 - 259 - nacl = kzalloc(sizeof(struct tcm_qla2xxx_nacl), GFP_KERNEL); 260 - if (!nacl) { 261 - pr_err("Unable to allocate struct tcm_qla2xxx_nacl\n"); 262 - return NULL; 263 - } 264 - 265 - return &nacl->se_node_acl; 266 - } 267 - 268 - static void tcm_qla2xxx_release_fabric_acl( 269 - struct se_portal_group *se_tpg, 270 - struct se_node_acl *se_nacl) 271 - { 272 - struct tcm_qla2xxx_nacl *nacl = container_of(se_nacl, 273 - struct tcm_qla2xxx_nacl, se_node_acl); 274 - kfree(nacl); 275 345 } 276 346 277 347 static u32 tcm_qla2xxx_tpg_get_inst_index(struct se_portal_group *se_tpg) ··· 314 430 cmd->cmd_flags |= BIT_14; 315 431 } 316 432 317 - return target_put_sess_cmd(se_cmd->se_sess, se_cmd); 433 + return target_put_sess_cmd(se_cmd); 318 434 } 319 435 320 436 /* tcm_qla2xxx_release_cmd - Callback from TCM Core to release underlying ··· 416 532 static void tcm_qla2xxx_set_default_node_attrs(struct se_node_acl *nacl) 417 533 { 418 534 return; 419 - } 420 - 421 - static u32 tcm_qla2xxx_get_task_tag(struct se_cmd *se_cmd) 422 - { 423 - struct qla_tgt_cmd *cmd; 424 - 425 - /* check for task mgmt cmd */ 426 - if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) 427 - return 0xffffffff; 428 - 429 - cmd = container_of(se_cmd, struct qla_tgt_cmd, se_cmd); 430 - 431 - return cmd->tag; 432 535 } 433 536 434 537 static int tcm_qla2xxx_get_cmd_state(struct se_cmd *se_cmd) ··· 698 827 qlt_unreg_sess(se_sess->fabric_sess_ptr); 699 828 } 700 829 701 - static void tcm_qla2xxx_put_session(struct se_session *se_sess) 702 - { 703 - struct qla_tgt_sess *sess = se_sess->fabric_sess_ptr; 704 - struct qla_hw_data *ha = sess->vha->hw; 705 - unsigned long flags; 706 - 707 - spin_lock_irqsave(&ha->hardware_lock, flags); 708 - kref_put(&se_sess->sess_kref, tcm_qla2xxx_release_session); 709 - spin_unlock_irqrestore(&ha->hardware_lock, flags); 710 - } 711 - 712 830 static void tcm_qla2xxx_put_sess(struct qla_tgt_sess *sess) 713 831 { 714 832 if (!sess) ··· 713 853 target_sess_cmd_list_set_waiting(sess->se_sess); 714 854 } 715 855 716 - static struct se_node_acl *tcm_qla2xxx_make_nodeacl( 717 - struct se_portal_group *se_tpg, 718 - struct config_group *group, 719 - const char *name) 856 + static int tcm_qla2xxx_init_nodeacl(struct se_node_acl *se_nacl, 857 + const char *name) 720 858 { 721 - struct se_node_acl *se_nacl, *se_nacl_new; 722 - struct tcm_qla2xxx_nacl *nacl; 859 + struct tcm_qla2xxx_nacl *nacl = 860 + container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl); 723 861 u64 wwnn; 724 - u32 qla2xxx_nexus_depth; 725 862 726 863 if (tcm_qla2xxx_parse_wwn(name, &wwnn, 1) < 0) 727 - return ERR_PTR(-EINVAL); 864 + return -EINVAL; 728 865 729 - se_nacl_new = tcm_qla2xxx_alloc_fabric_acl(se_tpg); 730 - if (!se_nacl_new) 731 - return ERR_PTR(-ENOMEM); 732 - /* #warning FIXME: Hardcoded qla2xxx_nexus depth in tcm_qla2xxx_make_nodeacl */ 733 - qla2xxx_nexus_depth = 1; 734 - 735 - /* 736 - * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 737 - * when converting a NodeACL from demo mode -> explict 738 - */ 739 - se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 740 - name, qla2xxx_nexus_depth); 741 - if (IS_ERR(se_nacl)) { 742 - tcm_qla2xxx_release_fabric_acl(se_tpg, se_nacl_new); 743 - return se_nacl; 744 - } 745 - /* 746 - * Locate our struct tcm_qla2xxx_nacl and set the FC Nport WWPN 747 - */ 748 - nacl = container_of(se_nacl, struct tcm_qla2xxx_nacl, se_node_acl); 749 866 nacl->nport_wwnn = wwnn; 750 867 tcm_qla2xxx_format_wwn(&nacl->nport_name[0], TCM_QLA2XXX_NAMELEN, wwnn); 751 868 752 - return se_nacl; 753 - } 754 - 755 - static void tcm_qla2xxx_drop_nodeacl(struct se_node_acl *se_acl) 756 - { 757 - struct se_portal_group *se_tpg = se_acl->se_tpg; 758 - struct tcm_qla2xxx_nacl *nacl = container_of(se_acl, 759 - struct tcm_qla2xxx_nacl, se_node_acl); 760 - 761 - core_tpg_del_initiator_node_acl(se_tpg, se_acl, 1); 762 - kfree(nacl); 869 + return 0; 763 870 } 764 871 765 872 /* Start items for tcm_qla2xxx_tpg_attrib_cit */ ··· 1002 1175 tpg->tpg_attrib.cache_dynamic_acls = 1; 1003 1176 tpg->tpg_attrib.demo_mode_login_only = 1; 1004 1177 1005 - ret = core_tpg_register(&tcm_qla2xxx_ops, wwn, 1006 - &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1178 + ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP); 1007 1179 if (ret < 0) { 1008 1180 kfree(tpg); 1009 1181 return NULL; ··· 1121 1295 tpg->tpg_attrib.cache_dynamic_acls = 1; 1122 1296 tpg->tpg_attrib.demo_mode_login_only = 1; 1123 1297 1124 - ret = core_tpg_register(&tcm_qla2xxx_npiv_ops, wwn, 1125 - &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1298 + ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP); 1126 1299 if (ret < 0) { 1127 1300 kfree(tpg); 1128 1301 return NULL; ··· 1813 1988 static const struct target_core_fabric_ops tcm_qla2xxx_ops = { 1814 1989 .module = THIS_MODULE, 1815 1990 .name = "qla2xxx", 1991 + .node_acl_size = sizeof(struct tcm_qla2xxx_nacl), 1816 1992 .get_fabric_name = tcm_qla2xxx_get_fabric_name, 1817 - .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 1818 1993 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn, 1819 1994 .tpg_get_tag = tcm_qla2xxx_get_tag, 1820 - .tpg_get_default_depth = tcm_qla2xxx_get_default_depth, 1821 - .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id, 1822 - .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len, 1823 - .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id, 1824 1995 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode, 1825 1996 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache, 1826 1997 .tpg_check_demo_mode_write_protect = ··· 1825 2004 tcm_qla2xxx_check_prod_write_protect, 1826 2005 .tpg_check_prot_fabric_only = tcm_qla2xxx_check_prot_fabric_only, 1827 2006 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only, 1828 - .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl, 1829 - .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl, 1830 2007 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index, 1831 2008 .check_stop_free = tcm_qla2xxx_check_stop_free, 1832 2009 .release_cmd = tcm_qla2xxx_release_cmd, 1833 - .put_session = tcm_qla2xxx_put_session, 1834 2010 .shutdown_session = tcm_qla2xxx_shutdown_session, 1835 2011 .close_session = tcm_qla2xxx_close_session, 1836 2012 .sess_get_index = tcm_qla2xxx_sess_get_index, ··· 1835 2017 .write_pending = tcm_qla2xxx_write_pending, 1836 2018 .write_pending_status = tcm_qla2xxx_write_pending_status, 1837 2019 .set_default_node_attributes = tcm_qla2xxx_set_default_node_attrs, 1838 - .get_task_tag = tcm_qla2xxx_get_task_tag, 1839 2020 .get_cmd_state = tcm_qla2xxx_get_cmd_state, 1840 2021 .queue_data_in = tcm_qla2xxx_queue_data_in, 1841 2022 .queue_status = tcm_qla2xxx_queue_status, ··· 1848 2031 .fabric_drop_wwn = tcm_qla2xxx_drop_lport, 1849 2032 .fabric_make_tpg = tcm_qla2xxx_make_tpg, 1850 2033 .fabric_drop_tpg = tcm_qla2xxx_drop_tpg, 1851 - .fabric_post_link = NULL, 1852 - .fabric_pre_unlink = NULL, 1853 - .fabric_make_np = NULL, 1854 - .fabric_drop_np = NULL, 1855 - .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl, 1856 - .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl, 2034 + .fabric_init_nodeacl = tcm_qla2xxx_init_nodeacl, 1857 2035 1858 2036 .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs, 1859 2037 .tfc_tpg_base_attrs = tcm_qla2xxx_tpg_attrs, ··· 1858 2046 static const struct target_core_fabric_ops tcm_qla2xxx_npiv_ops = { 1859 2047 .module = THIS_MODULE, 1860 2048 .name = "qla2xxx_npiv", 2049 + .node_acl_size = sizeof(struct tcm_qla2xxx_nacl), 1861 2050 .get_fabric_name = tcm_qla2xxx_npiv_get_fabric_name, 1862 - .get_fabric_proto_ident = tcm_qla2xxx_get_fabric_proto_ident, 1863 2051 .tpg_get_wwn = tcm_qla2xxx_get_fabric_wwn, 1864 2052 .tpg_get_tag = tcm_qla2xxx_get_tag, 1865 - .tpg_get_default_depth = tcm_qla2xxx_get_default_depth, 1866 - .tpg_get_pr_transport_id = tcm_qla2xxx_get_pr_transport_id, 1867 - .tpg_get_pr_transport_id_len = tcm_qla2xxx_get_pr_transport_id_len, 1868 - .tpg_parse_pr_out_transport_id = tcm_qla2xxx_parse_pr_out_transport_id, 1869 2053 .tpg_check_demo_mode = tcm_qla2xxx_check_demo_mode, 1870 2054 .tpg_check_demo_mode_cache = tcm_qla2xxx_check_demo_mode_cache, 1871 2055 .tpg_check_demo_mode_write_protect = tcm_qla2xxx_check_demo_mode, 1872 2056 .tpg_check_prod_mode_write_protect = 1873 2057 tcm_qla2xxx_check_prod_write_protect, 1874 2058 .tpg_check_demo_mode_login_only = tcm_qla2xxx_check_demo_mode_login_only, 1875 - .tpg_alloc_fabric_acl = tcm_qla2xxx_alloc_fabric_acl, 1876 - .tpg_release_fabric_acl = tcm_qla2xxx_release_fabric_acl, 1877 2059 .tpg_get_inst_index = tcm_qla2xxx_tpg_get_inst_index, 1878 2060 .check_stop_free = tcm_qla2xxx_check_stop_free, 1879 2061 .release_cmd = tcm_qla2xxx_release_cmd, 1880 - .put_session = tcm_qla2xxx_put_session, 1881 2062 .shutdown_session = tcm_qla2xxx_shutdown_session, 1882 2063 .close_session = tcm_qla2xxx_close_session, 1883 2064 .sess_get_index = tcm_qla2xxx_sess_get_index, ··· 1878 2073 .write_pending = tcm_qla2xxx_write_pending, 1879 2074 .write_pending_status = tcm_qla2xxx_write_pending_status, 1880 2075 .set_default_node_attributes = tcm_qla2xxx_set_default_node_attrs, 1881 - .get_task_tag = tcm_qla2xxx_get_task_tag, 1882 2076 .get_cmd_state = tcm_qla2xxx_get_cmd_state, 1883 2077 .queue_data_in = tcm_qla2xxx_queue_data_in, 1884 2078 .queue_status = tcm_qla2xxx_queue_status, ··· 1891 2087 .fabric_drop_wwn = tcm_qla2xxx_npiv_drop_lport, 1892 2088 .fabric_make_tpg = tcm_qla2xxx_npiv_make_tpg, 1893 2089 .fabric_drop_tpg = tcm_qla2xxx_drop_tpg, 1894 - .fabric_post_link = NULL, 1895 - .fabric_pre_unlink = NULL, 1896 - .fabric_make_np = NULL, 1897 - .fabric_drop_np = NULL, 1898 - .fabric_make_nodeacl = tcm_qla2xxx_make_nodeacl, 1899 - .fabric_drop_nodeacl = tcm_qla2xxx_drop_nodeacl, 2090 + .fabric_init_nodeacl = tcm_qla2xxx_init_nodeacl, 1900 2091 1901 2092 .tfc_wwn_attrs = tcm_qla2xxx_wwn_attrs, 1902 2093 .tfc_tpg_base_attrs = tcm_qla2xxx_npiv_tpg_attrs,
+2 -4
drivers/scsi/qla2xxx/tcm_qla2xxx.h
··· 13 13 #include "qla_target.h" 14 14 15 15 struct tcm_qla2xxx_nacl { 16 + struct se_node_acl se_node_acl; 17 + 16 18 /* From libfc struct fc_rport->port_id */ 17 19 u32 nport_id; 18 20 /* Binary World Wide unique Node Name for remote FC Initiator Nport */ ··· 25 23 struct qla_tgt_sess *qla_tgt_sess; 26 24 /* Pointer to TCM FC nexus */ 27 25 struct se_session *nport_nexus; 28 - /* Returned by tcm_qla2xxx_make_nodeacl() */ 29 - struct se_node_acl se_node_acl; 30 26 }; 31 27 32 28 struct tcm_qla2xxx_tpg_attrib { ··· 57 57 }; 58 58 59 59 struct tcm_qla2xxx_lport { 60 - /* SCSI protocol the lport is providing */ 61 - u8 lport_proto_id; 62 60 /* Binary World Wide unique Port Name for FC Target Lport */ 63 61 u64 lport_wwpn; 64 62 /* Binary World Wide unique Port Name for FC NPIV Target Lport */
+13 -25
drivers/target/iscsi/iscsi_target.c
··· 29 29 #include <scsi/scsi_tcq.h> 30 30 #include <target/target_core_base.h> 31 31 #include <target/target_core_fabric.h> 32 - #include <target/target_core_configfs.h> 33 32 34 33 #include <target/iscsi/iscsi_target_core.h> 35 34 #include "iscsi_target_parameters.h" ··· 715 716 */ 716 717 if (cmd->se_cmd.se_tfo != NULL) { 717 718 pr_debug("iscsi reject: calling target_put_sess_cmd >>>>>>\n"); 718 - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); 719 + target_put_sess_cmd(&cmd->se_cmd); 719 720 } 720 721 return -1; 721 722 } ··· 1001 1002 hdr->cmdsn, be32_to_cpu(hdr->data_length), payload_length, 1002 1003 conn->cid); 1003 1004 1004 - target_get_sess_cmd(conn->sess->se_sess, &cmd->se_cmd, true); 1005 + target_get_sess_cmd(&cmd->se_cmd, true); 1005 1006 1006 1007 cmd->sense_reason = transport_lookup_cmd_lun(&cmd->se_cmd, 1007 1008 scsilun_to_int(&hdr->lun)); 1008 1009 if (cmd->sense_reason) 1009 1010 goto attach_cmd; 1010 1011 1012 + /* only used for printks or comparing with ->ref_task_tag */ 1013 + cmd->se_cmd.tag = (__force u32)cmd->init_task_tag; 1011 1014 cmd->sense_reason = target_setup_cmd_from_cdb(&cmd->se_cmd, hdr->cdb); 1012 1015 if (cmd->sense_reason) { 1013 1016 if (cmd->sense_reason == TCM_OUT_OF_RESOURCES) { ··· 1069 1068 if (cmdsn_ret == CMDSN_ERROR_CANNOT_RECOVER) 1070 1069 return -1; 1071 1070 else if (cmdsn_ret == CMDSN_LOWER_THAN_EXP) { 1072 - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); 1071 + target_put_sess_cmd(&cmd->se_cmd); 1073 1072 return 0; 1074 1073 } 1075 1074 } ··· 1085 1084 if (!cmd->sense_reason) 1086 1085 return 0; 1087 1086 1088 - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); 1087 + target_put_sess_cmd(&cmd->se_cmd); 1089 1088 return 0; 1090 1089 } 1091 1090 ··· 1116 1115 iscsit_get_immediate_data(struct iscsi_cmd *cmd, struct iscsi_scsi_req *hdr, 1117 1116 bool dump_payload) 1118 1117 { 1119 - struct iscsi_conn *conn = cmd->conn; 1120 1118 int cmdsn_ret = 0, immed_ret = IMMEDIATE_DATA_NORMAL_OPERATION; 1121 1119 /* 1122 1120 * Special case for Unsupported SAM WRITE Opcodes and ImmediateData=Yes. ··· 1142 1142 1143 1143 rc = iscsit_dump_data_payload(cmd->conn, 1144 1144 cmd->first_burst_len, 1); 1145 - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); 1145 + target_put_sess_cmd(&cmd->se_cmd); 1146 1146 return rc; 1147 1147 } else if (cmd->unsolicited_data) 1148 1148 iscsit_set_unsoliticed_dataout(cmd); ··· 1811 1811 conn->sess->se_sess, 0, DMA_NONE, 1812 1812 TCM_SIMPLE_TAG, cmd->sense_buffer + 2); 1813 1813 1814 - target_get_sess_cmd(conn->sess->se_sess, &cmd->se_cmd, true); 1814 + target_get_sess_cmd(&cmd->se_cmd, true); 1815 1815 sess_ref = true; 1816 1816 1817 1817 switch (function) { ··· 1953 1953 */ 1954 1954 if (sess_ref) { 1955 1955 pr_debug("Handle TMR, using sess_ref=true check\n"); 1956 - target_put_sess_cmd(conn->sess->se_sess, &cmd->se_cmd); 1956 + target_put_sess_cmd(&cmd->se_cmd); 1957 1957 } 1958 1958 1959 1959 iscsit_add_cmd_to_response_queue(cmd, conn, cmd->i_state); ··· 2737 2737 cmd->iov_data_count = iov_count; 2738 2738 cmd->tx_size = tx_size; 2739 2739 2740 - /* sendpage is preferred but can't insert markers */ 2741 - if (!conn->conn_ops->IFMarker) 2742 - ret = iscsit_fe_sendpage_sg(cmd, conn); 2743 - else 2744 - ret = iscsit_send_tx_data(cmd, conn, 0); 2740 + ret = iscsit_fe_sendpage_sg(cmd, conn); 2745 2741 2746 2742 iscsit_unmap_iovec(cmd); 2747 2743 ··· 4069 4073 " opcode while ERL=0, closing iSCSI connection.\n"); 4070 4074 return -1; 4071 4075 } 4072 - if (!conn->conn_ops->OFMarker) { 4073 - pr_err("Unable to recover from unknown" 4074 - " opcode while OFMarker=No, closing iSCSI" 4075 - " connection.\n"); 4076 - return -1; 4077 - } 4078 - if (iscsit_recover_from_unknown_opcode(conn) < 0) { 4079 - pr_err("Unable to recover from unknown" 4080 - " opcode, closing iSCSI connection.\n"); 4081 - return -1; 4082 - } 4076 + pr_err("Unable to recover from unknown opcode while OFMarker=No," 4077 + " closing iSCSI connection.\n"); 4078 + ret = -1; 4083 4079 break; 4084 4080 } 4085 4081
+28 -109
drivers/target/iscsi/iscsi_target_configfs.c
··· 24 24 #include <target/target_core_base.h> 25 25 #include <target/target_core_fabric.h> 26 26 #include <target/target_core_fabric_configfs.h> 27 - #include <target/target_core_configfs.h> 28 27 #include <target/configfs_macros.h> 29 28 #include <target/iscsi/iscsi_transport.h> 30 29 ··· 859 860 NULL, 860 861 }; 861 862 862 - static struct se_node_acl *lio_tpg_alloc_fabric_acl( 863 - struct se_portal_group *se_tpg) 863 + static int lio_target_init_nodeacl(struct se_node_acl *se_nacl, 864 + const char *name) 864 865 { 865 - struct iscsi_node_acl *acl; 866 - 867 - acl = kzalloc(sizeof(struct iscsi_node_acl), GFP_KERNEL); 868 - if (!acl) { 869 - pr_err("Unable to allocate memory for struct iscsi_node_acl\n"); 870 - return NULL; 871 - } 872 - 873 - return &acl->se_node_acl; 874 - } 875 - 876 - static struct se_node_acl *lio_target_make_nodeacl( 877 - struct se_portal_group *se_tpg, 878 - struct config_group *group, 879 - const char *name) 880 - { 881 - struct config_group *stats_cg; 882 - struct iscsi_node_acl *acl; 883 - struct se_node_acl *se_nacl_new, *se_nacl; 884 - struct iscsi_portal_group *tpg = container_of(se_tpg, 885 - struct iscsi_portal_group, tpg_se_tpg); 886 - u32 cmdsn_depth; 887 - 888 - se_nacl_new = lio_tpg_alloc_fabric_acl(se_tpg); 889 - if (!se_nacl_new) 890 - return ERR_PTR(-ENOMEM); 891 - 892 - cmdsn_depth = tpg->tpg_attrib.default_cmdsn_depth; 893 - /* 894 - * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 895 - * when converting a NdoeACL from demo mode -> explict 896 - */ 897 - se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 898 - name, cmdsn_depth); 899 - if (IS_ERR(se_nacl)) 900 - return se_nacl; 901 - 902 - acl = container_of(se_nacl, struct iscsi_node_acl, se_node_acl); 903 - stats_cg = &se_nacl->acl_fabric_stat_group; 866 + struct iscsi_node_acl *acl = 867 + container_of(se_nacl, struct iscsi_node_acl, se_node_acl); 868 + struct config_group *stats_cg = &se_nacl->acl_fabric_stat_group; 904 869 905 870 stats_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 906 871 GFP_KERNEL); 907 872 if (!stats_cg->default_groups) { 908 873 pr_err("Unable to allocate memory for" 909 874 " stats_cg->default_groups\n"); 910 - core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); 911 - kfree(acl); 912 - return ERR_PTR(-ENOMEM); 875 + return -ENOMEM; 913 876 } 914 877 915 878 stats_cg->default_groups[0] = &acl->node_stat_grps.iscsi_sess_stats_group; ··· 879 918 config_group_init_type_name(&acl->node_stat_grps.iscsi_sess_stats_group, 880 919 "iscsi_sess_stats", &iscsi_stat_sess_cit); 881 920 882 - return se_nacl; 921 + return 0; 883 922 } 884 923 885 - static void lio_target_drop_nodeacl( 886 - struct se_node_acl *se_nacl) 924 + static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl) 887 925 { 888 - struct se_portal_group *se_tpg = se_nacl->se_tpg; 889 926 struct iscsi_node_acl *acl = container_of(se_nacl, 890 927 struct iscsi_node_acl, se_node_acl); 891 928 struct config_item *df_item; ··· 897 938 config_item_put(df_item); 898 939 } 899 940 kfree(stats_cg->default_groups); 900 - 901 - core_tpg_del_initiator_node_acl(se_tpg, se_nacl, 1); 902 - kfree(acl); 903 941 } 904 942 905 943 /* End items for lio_target_acl_cit */ ··· 1419 1463 if (!tpg) 1420 1464 return NULL; 1421 1465 1422 - ret = core_tpg_register(&iscsi_ops, wwn, &tpg->tpg_se_tpg, 1423 - tpg, TRANSPORT_TPG_TYPE_NORMAL); 1466 + ret = core_tpg_register(wwn, &tpg->tpg_se_tpg, SCSI_PROTOCOL_ISCSI); 1424 1467 if (ret < 0) 1425 1468 return NULL; 1426 1469 ··· 1690 1735 return "iSCSI"; 1691 1736 } 1692 1737 1693 - static u32 iscsi_get_task_tag(struct se_cmd *se_cmd) 1694 - { 1695 - struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); 1696 - 1697 - /* only used for printks or comparism with ->ref_task_tag */ 1698 - return (__force u32)cmd->init_task_tag; 1699 - } 1700 - 1701 1738 static int iscsi_get_cmd_state(struct se_cmd *se_cmd) 1702 1739 { 1703 1740 struct iscsi_cmd *cmd = container_of(se_cmd, struct iscsi_cmd, se_cmd); ··· 1779 1832 cmd->conn->conn_transport->iscsit_aborted_task(cmd->conn, cmd); 1780 1833 } 1781 1834 1835 + static inline struct iscsi_portal_group *iscsi_tpg(struct se_portal_group *se_tpg) 1836 + { 1837 + return container_of(se_tpg, struct iscsi_portal_group, tpg_se_tpg); 1838 + } 1839 + 1782 1840 static char *lio_tpg_get_endpoint_wwn(struct se_portal_group *se_tpg) 1783 1841 { 1784 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1785 - 1786 - return &tpg->tpg_tiqn->tiqn[0]; 1842 + return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn; 1787 1843 } 1788 1844 1789 1845 static u16 lio_tpg_get_tag(struct se_portal_group *se_tpg) 1790 1846 { 1791 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1792 - 1793 - return tpg->tpgt; 1847 + return iscsi_tpg(se_tpg)->tpgt; 1794 1848 } 1795 1849 1796 1850 static u32 lio_tpg_get_default_depth(struct se_portal_group *se_tpg) 1797 1851 { 1798 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1799 - 1800 - return tpg->tpg_attrib.default_cmdsn_depth; 1852 + return iscsi_tpg(se_tpg)->tpg_attrib.default_cmdsn_depth; 1801 1853 } 1802 1854 1803 1855 static int lio_tpg_check_demo_mode(struct se_portal_group *se_tpg) 1804 1856 { 1805 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1806 - 1807 - return tpg->tpg_attrib.generate_node_acls; 1857 + return iscsi_tpg(se_tpg)->tpg_attrib.generate_node_acls; 1808 1858 } 1809 1859 1810 1860 static int lio_tpg_check_demo_mode_cache(struct se_portal_group *se_tpg) 1811 1861 { 1812 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1813 - 1814 - return tpg->tpg_attrib.cache_dynamic_acls; 1862 + return iscsi_tpg(se_tpg)->tpg_attrib.cache_dynamic_acls; 1815 1863 } 1816 1864 1817 1865 static int lio_tpg_check_demo_mode_write_protect( 1818 1866 struct se_portal_group *se_tpg) 1819 1867 { 1820 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1821 - 1822 - return tpg->tpg_attrib.demo_mode_write_protect; 1868 + return iscsi_tpg(se_tpg)->tpg_attrib.demo_mode_write_protect; 1823 1869 } 1824 1870 1825 1871 static int lio_tpg_check_prod_mode_write_protect( 1826 1872 struct se_portal_group *se_tpg) 1827 1873 { 1828 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1829 - 1830 - return tpg->tpg_attrib.prod_mode_write_protect; 1874 + return iscsi_tpg(se_tpg)->tpg_attrib.prod_mode_write_protect; 1831 1875 } 1832 1876 1833 1877 static int lio_tpg_check_prot_fabric_only( 1834 1878 struct se_portal_group *se_tpg) 1835 1879 { 1836 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1837 1880 /* 1838 1881 * Only report fabric_prot_type if t10_pi has also been enabled 1839 1882 * for incoming ib_isert sessions. 1840 1883 */ 1841 - if (!tpg->tpg_attrib.t10_pi) 1884 + if (!iscsi_tpg(se_tpg)->tpg_attrib.t10_pi) 1842 1885 return 0; 1843 - 1844 - return tpg->tpg_attrib.fabric_prot_type; 1845 - } 1846 - 1847 - static void lio_tpg_release_fabric_acl( 1848 - struct se_portal_group *se_tpg, 1849 - struct se_node_acl *se_acl) 1850 - { 1851 - struct iscsi_node_acl *acl = container_of(se_acl, 1852 - struct iscsi_node_acl, se_node_acl); 1853 - kfree(acl); 1886 + return iscsi_tpg(se_tpg)->tpg_attrib.fabric_prot_type; 1854 1887 } 1855 1888 1856 1889 /* ··· 1875 1948 1876 1949 static u32 lio_tpg_get_inst_index(struct se_portal_group *se_tpg) 1877 1950 { 1878 - struct iscsi_portal_group *tpg = se_tpg->se_tpg_fabric_ptr; 1879 - 1880 - return tpg->tpg_tiqn->tiqn_index; 1951 + return iscsi_tpg(se_tpg)->tpg_tiqn->tiqn_index; 1881 1952 } 1882 1953 1883 1954 static void lio_set_default_node_attributes(struct se_node_acl *se_acl) ··· 1892 1967 1893 1968 static int lio_check_stop_free(struct se_cmd *se_cmd) 1894 1969 { 1895 - return target_put_sess_cmd(se_cmd->se_sess, se_cmd); 1970 + return target_put_sess_cmd(se_cmd); 1896 1971 } 1897 1972 1898 1973 static void lio_release_cmd(struct se_cmd *se_cmd) ··· 1906 1981 const struct target_core_fabric_ops iscsi_ops = { 1907 1982 .module = THIS_MODULE, 1908 1983 .name = "iscsi", 1984 + .node_acl_size = sizeof(struct iscsi_node_acl), 1909 1985 .get_fabric_name = iscsi_get_fabric_name, 1910 - .get_fabric_proto_ident = iscsi_get_fabric_proto_ident, 1911 1986 .tpg_get_wwn = lio_tpg_get_endpoint_wwn, 1912 1987 .tpg_get_tag = lio_tpg_get_tag, 1913 1988 .tpg_get_default_depth = lio_tpg_get_default_depth, 1914 - .tpg_get_pr_transport_id = iscsi_get_pr_transport_id, 1915 - .tpg_get_pr_transport_id_len = iscsi_get_pr_transport_id_len, 1916 - .tpg_parse_pr_out_transport_id = iscsi_parse_pr_out_transport_id, 1917 1989 .tpg_check_demo_mode = lio_tpg_check_demo_mode, 1918 1990 .tpg_check_demo_mode_cache = lio_tpg_check_demo_mode_cache, 1919 1991 .tpg_check_demo_mode_write_protect = ··· 1918 1996 .tpg_check_prod_mode_write_protect = 1919 1997 lio_tpg_check_prod_mode_write_protect, 1920 1998 .tpg_check_prot_fabric_only = &lio_tpg_check_prot_fabric_only, 1921 - .tpg_alloc_fabric_acl = lio_tpg_alloc_fabric_acl, 1922 - .tpg_release_fabric_acl = lio_tpg_release_fabric_acl, 1923 1999 .tpg_get_inst_index = lio_tpg_get_inst_index, 1924 2000 .check_stop_free = lio_check_stop_free, 1925 2001 .release_cmd = lio_release_cmd, ··· 1928 2008 .write_pending = lio_write_pending, 1929 2009 .write_pending_status = lio_write_pending_status, 1930 2010 .set_default_node_attributes = lio_set_default_node_attributes, 1931 - .get_task_tag = iscsi_get_task_tag, 1932 2011 .get_cmd_state = iscsi_get_cmd_state, 1933 2012 .queue_data_in = lio_queue_data_in, 1934 2013 .queue_status = lio_queue_status, ··· 1939 2020 .fabric_drop_tpg = lio_target_tiqn_deltpg, 1940 2021 .fabric_make_np = lio_target_call_addnptotpg, 1941 2022 .fabric_drop_np = lio_target_call_delnpfromtpg, 1942 - .fabric_make_nodeacl = lio_target_make_nodeacl, 1943 - .fabric_drop_nodeacl = lio_target_drop_nodeacl, 2023 + .fabric_init_nodeacl = lio_target_init_nodeacl, 2024 + .fabric_cleanup_nodeacl = lio_target_cleanup_nodeacl, 1944 2025 1945 2026 .tfc_discovery_attrs = lio_target_discovery_auth_attrs, 1946 2027 .tfc_wwn_attrs = lio_target_wwn_attrs,
-53
drivers/target/iscsi/iscsi_target_erl0.c
··· 956 956 957 957 iscsit_handle_connection_cleanup(conn); 958 958 } 959 - 960 - /* 961 - * This is the simple function that makes the magic of 962 - * sync and steering happen in the follow paradoxical order: 963 - * 964 - * 0) Receive conn->of_marker (bytes left until next OFMarker) 965 - * bytes into an offload buffer. When we pass the exact number 966 - * of bytes in conn->of_marker, iscsit_dump_data_payload() and hence 967 - * rx_data() will automatically receive the identical u32 marker 968 - * values and store it in conn->of_marker_offset; 969 - * 1) Now conn->of_marker_offset will contain the offset to the start 970 - * of the next iSCSI PDU. Dump these remaining bytes into another 971 - * offload buffer. 972 - * 2) We are done! 973 - * Next byte in the TCP stream will contain the next iSCSI PDU! 974 - * Cool Huh?! 975 - */ 976 - int iscsit_recover_from_unknown_opcode(struct iscsi_conn *conn) 977 - { 978 - /* 979 - * Make sure the remaining bytes to next maker is a sane value. 980 - */ 981 - if (conn->of_marker > (conn->conn_ops->OFMarkInt * 4)) { 982 - pr_err("Remaining bytes to OFMarker: %u exceeds" 983 - " OFMarkInt bytes: %u.\n", conn->of_marker, 984 - conn->conn_ops->OFMarkInt * 4); 985 - return -1; 986 - } 987 - 988 - pr_debug("Advancing %u bytes in TCP stream to get to the" 989 - " next OFMarker.\n", conn->of_marker); 990 - 991 - if (iscsit_dump_data_payload(conn, conn->of_marker, 0) < 0) 992 - return -1; 993 - 994 - /* 995 - * Make sure the offset marker we retrived is a valid value. 996 - */ 997 - if (conn->of_marker_offset > (ISCSI_HDR_LEN + (ISCSI_CRC_LEN * 2) + 998 - conn->conn_ops->MaxRecvDataSegmentLength)) { 999 - pr_err("OfMarker offset value: %u exceeds limit.\n", 1000 - conn->of_marker_offset); 1001 - return -1; 1002 - } 1003 - 1004 - pr_debug("Discarding %u bytes of TCP stream to get to the" 1005 - " next iSCSI Opcode.\n", conn->of_marker_offset); 1006 - 1007 - if (iscsit_dump_data_payload(conn, conn->of_marker_offset, 0) < 0) 1008 - return -1; 1009 - 1010 - return 0; 1011 - }
-1
drivers/target/iscsi/iscsi_target_erl0.h
··· 10 10 extern void iscsit_cause_connection_reinstatement(struct iscsi_conn *, int); 11 11 extern void iscsit_fall_back_to_erl0(struct iscsi_session *); 12 12 extern void iscsit_take_action_for_connection_exit(struct iscsi_conn *); 13 - extern int iscsit_recover_from_unknown_opcode(struct iscsi_conn *); 14 13 15 14 #endif /*** ISCSI_TARGET_ERL0_H ***/
+1 -57
drivers/target/iscsi/iscsi_target_login.c
··· 410 410 if (iscsi_change_param_sprintf(conn, "ErrorRecoveryLevel=%d", na->default_erl)) 411 411 return -1; 412 412 413 - if (iscsi_login_disable_FIM_keys(conn->param_list, conn) < 0) 414 - return -1; 415 413 /* 416 414 * Set RDMAExtensions=Yes by default for iSER enabled network portals 417 415 */ ··· 471 473 " T10-PI enabled ISER session\n"); 472 474 } 473 475 } 474 - 475 - return 0; 476 - } 477 - 478 - /* 479 - * Remove PSTATE_NEGOTIATE for the four FIM related keys. 480 - * The Initiator node will be able to enable FIM by proposing them itself. 481 - */ 482 - int iscsi_login_disable_FIM_keys( 483 - struct iscsi_param_list *param_list, 484 - struct iscsi_conn *conn) 485 - { 486 - struct iscsi_param *param; 487 - 488 - param = iscsi_find_param_from_key("OFMarker", param_list); 489 - if (!param) { 490 - pr_err("iscsi_find_param_from_key() for" 491 - " OFMarker failed\n"); 492 - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 493 - ISCSI_LOGIN_STATUS_NO_RESOURCES); 494 - return -1; 495 - } 496 - param->state &= ~PSTATE_NEGOTIATE; 497 - 498 - param = iscsi_find_param_from_key("OFMarkInt", param_list); 499 - if (!param) { 500 - pr_err("iscsi_find_param_from_key() for" 501 - " IFMarker failed\n"); 502 - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 503 - ISCSI_LOGIN_STATUS_NO_RESOURCES); 504 - return -1; 505 - } 506 - param->state &= ~PSTATE_NEGOTIATE; 507 - 508 - param = iscsi_find_param_from_key("IFMarker", param_list); 509 - if (!param) { 510 - pr_err("iscsi_find_param_from_key() for" 511 - " IFMarker failed\n"); 512 - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 513 - ISCSI_LOGIN_STATUS_NO_RESOURCES); 514 - return -1; 515 - } 516 - param->state &= ~PSTATE_NEGOTIATE; 517 - 518 - param = iscsi_find_param_from_key("IFMarkInt", param_list); 519 - if (!param) { 520 - pr_err("iscsi_find_param_from_key() for" 521 - " IFMarker failed\n"); 522 - iscsit_tx_login_rsp(conn, ISCSI_STATUS_CLS_TARGET_ERR, 523 - ISCSI_LOGIN_STATUS_NO_RESOURCES); 524 - return -1; 525 - } 526 - param->state &= ~PSTATE_NEGOTIATE; 527 476 528 477 return 0; 529 478 } ··· 561 616 if (iscsi_change_param_sprintf(conn, "TargetPortalGroupTag=%hu", sess->tpg->tpgt)) 562 617 return -1; 563 618 564 - return iscsi_login_disable_FIM_keys(conn->param_list, conn); 619 + return 0; 565 620 } 566 621 567 622 int iscsi_login_post_auth_non_zero_tsih( ··· 710 765 conn->conn_state = TARG_CONN_STATE_LOGGED_IN; 711 766 712 767 iscsi_set_connection_parameters(conn->conn_ops, conn->param_list); 713 - iscsit_set_sync_and_steering_values(conn); 714 768 /* 715 769 * SCSI Initiator -> SCSI Target Port Mapping 716 770 */
-1
drivers/target/iscsi/iscsi_target_login.h
··· 16 16 extern void iscsi_target_login_sess_out(struct iscsi_conn *, struct iscsi_np *, 17 17 bool, bool); 18 18 extern int iscsi_target_login_thread(void *); 19 - extern int iscsi_login_disable_FIM_keys(struct iscsi_param_list *, struct iscsi_conn *); 20 19 21 20 #endif /*** ISCSI_TARGET_LOGIN_H ***/
+10 -265
drivers/target/iscsi/iscsi_target_parameters.c
··· 34 34 iov.iov_len = length; 35 35 iov.iov_base = buf; 36 36 37 - /* 38 - * Initial Marker-less Interval. 39 - * Add the values regardless of IFMarker/OFMarker, considering 40 - * it may not be negoitated yet. 41 - */ 42 - conn->of_marker += length; 43 - 44 37 rx_got = rx_data(conn, &iov, 1, length); 45 38 if (rx_got != length) { 46 39 pr_err("rx_data returned %d, expecting %d.\n", ··· 65 72 iov_cnt++; 66 73 } 67 74 68 - /* 69 - * Initial Marker-less Interval. 70 - * Add the values regardless of IFMarker/OFMarker, considering 71 - * it may not be negoitated yet. 72 - */ 73 - conn->if_marker += length; 74 - 75 75 tx_sent = tx_data(conn, &iov[0], iov_cnt, length); 76 76 if (tx_sent != length) { 77 77 pr_err("tx_data returned %d, expecting %d.\n", ··· 83 97 "CRC32C" : "None"); 84 98 pr_debug("MaxRecvDataSegmentLength: %u\n", 85 99 conn_ops->MaxRecvDataSegmentLength); 86 - pr_debug("OFMarker: %s\n", (conn_ops->OFMarker) ? "Yes" : "No"); 87 - pr_debug("IFMarker: %s\n", (conn_ops->IFMarker) ? "Yes" : "No"); 88 - if (conn_ops->OFMarker) 89 - pr_debug("OFMarkInt: %u\n", conn_ops->OFMarkInt); 90 - if (conn_ops->IFMarker) 91 - pr_debug("IFMarkInt: %u\n", conn_ops->IFMarkInt); 92 100 } 93 101 94 102 void iscsi_dump_sess_ops(struct iscsi_sess_ops *sess_ops) ··· 173 193 case TYPERANGE_AUTH: 174 194 case TYPERANGE_DIGEST: 175 195 param->type = TYPE_VALUE_LIST | TYPE_STRING; 176 - break; 177 - case TYPERANGE_MARKINT: 178 - param->type = TYPE_NUMBER_RANGE; 179 - param->type_range |= TYPERANGE_1_TO_65535; 180 196 break; 181 197 case TYPERANGE_ISCSINAME: 182 198 case TYPERANGE_SESSIONTYPE: ··· 398 422 399 423 param = iscsi_set_default_param(pl, IFMARKINT, INITIAL_IFMARKINT, 400 424 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH, 401 - TYPERANGE_MARKINT, USE_INITIAL_ONLY); 425 + TYPERANGE_UTF8, USE_INITIAL_ONLY); 402 426 if (!param) 403 427 goto out; 404 428 405 429 param = iscsi_set_default_param(pl, OFMARKINT, INITIAL_OFMARKINT, 406 430 PHASE_OPERATIONAL, SCOPE_CONNECTION_ONLY, SENDER_BOTH, 407 - TYPERANGE_MARKINT, USE_INITIAL_ONLY); 431 + TYPERANGE_UTF8, USE_INITIAL_ONLY); 408 432 if (!param) 409 433 goto out; 410 434 /* ··· 500 524 } else if (!strcmp(param->name, OFMARKER)) { 501 525 SET_PSTATE_NEGOTIATE(param); 502 526 } else if (!strcmp(param->name, IFMARKINT)) { 503 - SET_PSTATE_NEGOTIATE(param); 527 + SET_PSTATE_REJECT(param); 504 528 } else if (!strcmp(param->name, OFMARKINT)) { 505 - SET_PSTATE_NEGOTIATE(param); 529 + SET_PSTATE_REJECT(param); 506 530 } else if (!strcmp(param->name, RDMAEXTENSIONS)) { 507 531 if (iser) 508 532 SET_PSTATE_NEGOTIATE(param); ··· 882 906 return 0; 883 907 } 884 908 885 - static int iscsi_check_numerical_range_value(struct iscsi_param *param, char *value) 886 - { 887 - char *left_val_ptr = NULL, *right_val_ptr = NULL; 888 - char *tilde_ptr = NULL; 889 - u32 left_val, right_val, local_left_val; 890 - 891 - if (strcmp(param->name, IFMARKINT) && 892 - strcmp(param->name, OFMARKINT)) { 893 - pr_err("Only parameters \"%s\" or \"%s\" may contain a" 894 - " numerical range value.\n", IFMARKINT, OFMARKINT); 895 - return -1; 896 - } 897 - 898 - if (IS_PSTATE_PROPOSER(param)) 899 - return 0; 900 - 901 - tilde_ptr = strchr(value, '~'); 902 - if (!tilde_ptr) { 903 - pr_err("Unable to locate numerical range indicator" 904 - " \"~\" for \"%s\".\n", param->name); 905 - return -1; 906 - } 907 - *tilde_ptr = '\0'; 908 - 909 - left_val_ptr = value; 910 - right_val_ptr = value + strlen(left_val_ptr) + 1; 911 - 912 - if (iscsi_check_numerical_value(param, left_val_ptr) < 0) 913 - return -1; 914 - if (iscsi_check_numerical_value(param, right_val_ptr) < 0) 915 - return -1; 916 - 917 - left_val = simple_strtoul(left_val_ptr, NULL, 0); 918 - right_val = simple_strtoul(right_val_ptr, NULL, 0); 919 - *tilde_ptr = '~'; 920 - 921 - if (right_val < left_val) { 922 - pr_err("Numerical range for parameter \"%s\" contains" 923 - " a right value which is less than the left.\n", 924 - param->name); 925 - return -1; 926 - } 927 - 928 - /* 929 - * For now, enforce reasonable defaults for [I,O]FMarkInt. 930 - */ 931 - tilde_ptr = strchr(param->value, '~'); 932 - if (!tilde_ptr) { 933 - pr_err("Unable to locate numerical range indicator" 934 - " \"~\" for \"%s\".\n", param->name); 935 - return -1; 936 - } 937 - *tilde_ptr = '\0'; 938 - 939 - left_val_ptr = param->value; 940 - right_val_ptr = param->value + strlen(left_val_ptr) + 1; 941 - 942 - local_left_val = simple_strtoul(left_val_ptr, NULL, 0); 943 - *tilde_ptr = '~'; 944 - 945 - if (param->set_param) { 946 - if ((left_val < local_left_val) || 947 - (right_val < local_left_val)) { 948 - pr_err("Passed value range \"%u~%u\" is below" 949 - " minimum left value \"%u\" for key \"%s\"," 950 - " rejecting.\n", left_val, right_val, 951 - local_left_val, param->name); 952 - return -1; 953 - } 954 - } else { 955 - if ((left_val < local_left_val) && 956 - (right_val < local_left_val)) { 957 - pr_err("Received value range \"%u~%u\" is" 958 - " below minimum left value \"%u\" for key" 959 - " \"%s\", rejecting.\n", left_val, right_val, 960 - local_left_val, param->name); 961 - SET_PSTATE_REJECT(param); 962 - if (iscsi_update_param_value(param, REJECT) < 0) 963 - return -1; 964 - } 965 - } 966 - 967 - return 0; 968 - } 969 - 970 909 static int iscsi_check_string_or_list_value(struct iscsi_param *param, char *value) 971 910 { 972 911 if (IS_PSTATE_PROPOSER(param)) ··· 916 1025 } 917 1026 918 1027 return 0; 919 - } 920 - 921 - /* 922 - * This function is used to pick a value range number, currently just 923 - * returns the lesser of both right values. 924 - */ 925 - static char *iscsi_get_value_from_number_range( 926 - struct iscsi_param *param, 927 - char *value) 928 - { 929 - char *end_ptr, *tilde_ptr1 = NULL, *tilde_ptr2 = NULL; 930 - u32 acceptor_right_value, proposer_right_value; 931 - 932 - tilde_ptr1 = strchr(value, '~'); 933 - if (!tilde_ptr1) 934 - return NULL; 935 - *tilde_ptr1++ = '\0'; 936 - proposer_right_value = simple_strtoul(tilde_ptr1, &end_ptr, 0); 937 - 938 - tilde_ptr2 = strchr(param->value, '~'); 939 - if (!tilde_ptr2) 940 - return NULL; 941 - *tilde_ptr2++ = '\0'; 942 - acceptor_right_value = simple_strtoul(tilde_ptr2, &end_ptr, 0); 943 - 944 - return (acceptor_right_value >= proposer_right_value) ? 945 - tilde_ptr1 : tilde_ptr2; 946 1028 } 947 1029 948 1030 static char *iscsi_check_valuelist_for_support( ··· 967 1103 struct iscsi_conn *conn) 968 1104 { 969 1105 u8 acceptor_boolean_value = 0, proposer_boolean_value = 0; 970 - char *negoitated_value = NULL; 1106 + char *negotiated_value = NULL; 971 1107 972 1108 if (IS_PSTATE_ACCEPTOR(param)) { 973 1109 pr_err("Received key \"%s\" twice, protocol error.\n", ··· 1067 1203 pr_debug("Updated %s to target MXDSL value: %s\n", 1068 1204 param->name, param->value); 1069 1205 } 1070 - 1071 - } else if (IS_TYPE_NUMBER_RANGE(param)) { 1072 - negoitated_value = iscsi_get_value_from_number_range( 1073 - param, value); 1074 - if (!negoitated_value) 1075 - return -1; 1076 - if (iscsi_update_param_value(param, negoitated_value) < 0) 1077 - return -1; 1078 1206 } else if (IS_TYPE_VALUE_LIST(param)) { 1079 - negoitated_value = iscsi_check_valuelist_for_support( 1207 + negotiated_value = iscsi_check_valuelist_for_support( 1080 1208 param, value); 1081 - if (!negoitated_value) { 1209 + if (!negotiated_value) { 1082 1210 pr_err("Proposer's value list \"%s\" contains" 1083 1211 " no valid values from Acceptor's value list" 1084 1212 " \"%s\".\n", value, param->value); 1085 1213 return -1; 1086 1214 } 1087 - if (iscsi_update_param_value(param, negoitated_value) < 0) 1215 + if (iscsi_update_param_value(param, negotiated_value) < 0) 1088 1216 return -1; 1089 1217 } else if (IS_PHASE_DECLARATIVE(param)) { 1090 1218 if (iscsi_update_param_value(param, value) < 0) ··· 1095 1239 return -1; 1096 1240 } 1097 1241 1098 - if (IS_TYPE_NUMBER_RANGE(param)) { 1099 - u32 left_val = 0, right_val = 0, recieved_value = 0; 1100 - char *left_val_ptr = NULL, *right_val_ptr = NULL; 1101 - char *tilde_ptr = NULL; 1102 - 1103 - if (!strcmp(value, IRRELEVANT) || !strcmp(value, REJECT)) { 1104 - if (iscsi_update_param_value(param, value) < 0) 1105 - return -1; 1106 - return 0; 1107 - } 1108 - 1109 - tilde_ptr = strchr(value, '~'); 1110 - if (tilde_ptr) { 1111 - pr_err("Illegal \"~\" in response for \"%s\".\n", 1112 - param->name); 1113 - return -1; 1114 - } 1115 - tilde_ptr = strchr(param->value, '~'); 1116 - if (!tilde_ptr) { 1117 - pr_err("Unable to locate numerical range" 1118 - " indicator \"~\" for \"%s\".\n", param->name); 1119 - return -1; 1120 - } 1121 - *tilde_ptr = '\0'; 1122 - 1123 - left_val_ptr = param->value; 1124 - right_val_ptr = param->value + strlen(left_val_ptr) + 1; 1125 - left_val = simple_strtoul(left_val_ptr, NULL, 0); 1126 - right_val = simple_strtoul(right_val_ptr, NULL, 0); 1127 - recieved_value = simple_strtoul(value, NULL, 0); 1128 - 1129 - *tilde_ptr = '~'; 1130 - 1131 - if ((recieved_value < left_val) || 1132 - (recieved_value > right_val)) { 1133 - pr_err("Illegal response \"%s=%u\", value must" 1134 - " be between %u and %u.\n", param->name, 1135 - recieved_value, left_val, right_val); 1136 - return -1; 1137 - } 1138 - } else if (IS_TYPE_VALUE_LIST(param)) { 1242 + if (IS_TYPE_VALUE_LIST(param)) { 1139 1243 char *comma_ptr = NULL, *tmp_ptr = NULL; 1140 1244 1141 1245 comma_ptr = strchr(value, ','); ··· 1176 1360 return -1; 1177 1361 } else if (IS_TYPE_NUMBER(param)) { 1178 1362 if (iscsi_check_numerical_value(param, value) < 0) 1179 - return -1; 1180 - } else if (IS_TYPE_NUMBER_RANGE(param)) { 1181 - if (iscsi_check_numerical_range_value(param, value) < 0) 1182 1363 return -1; 1183 1364 } else if (IS_TYPE_STRING(param) || IS_TYPE_VALUE_LIST(param)) { 1184 1365 if (iscsi_check_string_or_list_value(param, value) < 0) ··· 1296 1483 char *tmpptr; 1297 1484 u8 DataSequenceInOrder = 0; 1298 1485 u8 ErrorRecoveryLevel = 0, SessionType = 0; 1299 - u8 IFMarker = 0, OFMarker = 0; 1300 - u8 IFMarkInt_Reject = 1, OFMarkInt_Reject = 1; 1301 1486 u32 FirstBurstLength = 0, MaxBurstLength = 0; 1302 1487 struct iscsi_param *param = NULL; 1303 1488 ··· 1314 1503 if (!strcmp(param->name, MAXBURSTLENGTH)) 1315 1504 MaxBurstLength = simple_strtoul(param->value, 1316 1505 &tmpptr, 0); 1317 - if (!strcmp(param->name, IFMARKER)) 1318 - if (!strcmp(param->value, YES)) 1319 - IFMarker = 1; 1320 - if (!strcmp(param->name, OFMARKER)) 1321 - if (!strcmp(param->value, YES)) 1322 - OFMarker = 1; 1323 - if (!strcmp(param->name, IFMARKINT)) 1324 - if (!strcmp(param->value, REJECT)) 1325 - IFMarkInt_Reject = 1; 1326 - if (!strcmp(param->name, OFMARKINT)) 1327 - if (!strcmp(param->value, REJECT)) 1328 - OFMarkInt_Reject = 1; 1329 1506 } 1330 1507 1331 1508 list_for_each_entry(param, &param_list->param_list, p_list) { 1332 1509 if (!(param->phase & phase)) 1333 1510 continue; 1334 - if (!SessionType && (!IS_PSTATE_ACCEPTOR(param) && 1335 - (strcmp(param->name, IFMARKER) && 1336 - strcmp(param->name, OFMARKER) && 1337 - strcmp(param->name, IFMARKINT) && 1338 - strcmp(param->name, OFMARKINT)))) 1511 + if (!SessionType && !IS_PSTATE_ACCEPTOR(param)) 1339 1512 continue; 1340 1513 if (!strcmp(param->name, MAXOUTSTANDINGR2T) && 1341 1514 DataSequenceInOrder && (ErrorRecoveryLevel > 0)) { ··· 1350 1555 pr_debug("Reset \"%s\" to \"%s\".\n", 1351 1556 param->name, param->value); 1352 1557 } 1353 - } 1354 - if (!strcmp(param->name, IFMARKER) && IFMarkInt_Reject) { 1355 - if (iscsi_update_param_value(param, NO) < 0) 1356 - return -1; 1357 - IFMarker = 0; 1358 - pr_debug("Reset \"%s\" to \"%s\".\n", 1359 - param->name, param->value); 1360 - } 1361 - if (!strcmp(param->name, OFMARKER) && OFMarkInt_Reject) { 1362 - if (iscsi_update_param_value(param, NO) < 0) 1363 - return -1; 1364 - OFMarker = 0; 1365 - pr_debug("Reset \"%s\" to \"%s\".\n", 1366 - param->name, param->value); 1367 - } 1368 - if (!strcmp(param->name, IFMARKINT) && !IFMarker) { 1369 - if (!strcmp(param->value, REJECT)) 1370 - continue; 1371 - param->state &= ~PSTATE_NEGOTIATE; 1372 - if (iscsi_update_param_value(param, IRRELEVANT) < 0) 1373 - return -1; 1374 - pr_debug("Reset \"%s\" to \"%s\".\n", 1375 - param->name, param->value); 1376 - } 1377 - if (!strcmp(param->name, OFMARKINT) && !OFMarker) { 1378 - if (!strcmp(param->value, REJECT)) 1379 - continue; 1380 - param->state &= ~PSTATE_NEGOTIATE; 1381 - if (iscsi_update_param_value(param, IRRELEVANT) < 0) 1382 - return -1; 1383 - pr_debug("Reset \"%s\" to \"%s\".\n", 1384 - param->name, param->value); 1385 1558 } 1386 1559 } 1387 1560 ··· 1587 1824 */ 1588 1825 pr_debug("MaxRecvDataSegmentLength: %u\n", 1589 1826 ops->MaxRecvDataSegmentLength); 1590 - } else if (!strcmp(param->name, OFMARKER)) { 1591 - ops->OFMarker = !strcmp(param->value, YES); 1592 - pr_debug("OFMarker: %s\n", 1593 - param->value); 1594 - } else if (!strcmp(param->name, IFMARKER)) { 1595 - ops->IFMarker = !strcmp(param->value, YES); 1596 - pr_debug("IFMarker: %s\n", 1597 - param->value); 1598 - } else if (!strcmp(param->name, OFMARKINT)) { 1599 - ops->OFMarkInt = 1600 - simple_strtoul(param->value, &tmpptr, 0); 1601 - pr_debug("OFMarkInt: %s\n", 1602 - param->value); 1603 - } else if (!strcmp(param->name, IFMARKINT)) { 1604 - ops->IFMarkInt = 1605 - simple_strtoul(param->value, &tmpptr, 0); 1606 - pr_debug("IFMarkInt: %s\n", 1607 - param->value); 1608 1827 } else if (!strcmp(param->name, INITIATORRECVDATASEGMENTLENGTH)) { 1609 1828 ops->InitiatorRecvDataSegmentLength = 1610 1829 simple_strtoul(param->value, &tmpptr, 0);
+5 -6
drivers/target/iscsi/iscsi_target_parameters.h
··· 138 138 #define INITIAL_SESSIONTYPE NORMAL 139 139 #define INITIAL_IFMARKER NO 140 140 #define INITIAL_OFMARKER NO 141 - #define INITIAL_IFMARKINT "2048~65535" 142 - #define INITIAL_OFMARKINT "2048~65535" 141 + #define INITIAL_IFMARKINT REJECT 142 + #define INITIAL_OFMARKINT REJECT 143 143 144 144 /* 145 145 * Initial values for iSER parameters following RFC-5046 Section 6 ··· 239 239 #define TYPERANGE_AUTH 0x0200 240 240 #define TYPERANGE_DIGEST 0x0400 241 241 #define TYPERANGE_ISCSINAME 0x0800 242 - #define TYPERANGE_MARKINT 0x1000 243 - #define TYPERANGE_SESSIONTYPE 0x2000 244 - #define TYPERANGE_TARGETADDRESS 0x4000 245 - #define TYPERANGE_UTF8 0x8000 242 + #define TYPERANGE_SESSIONTYPE 0x1000 243 + #define TYPERANGE_TARGETADDRESS 0x2000 244 + #define TYPERANGE_UTF8 0x4000 246 245 247 246 #define IS_TYPERANGE_0_TO_2(p) ((p)->type_range & TYPERANGE_0_TO_2) 248 247 #define IS_TYPERANGE_0_TO_3600(p) ((p)->type_range & TYPERANGE_0_TO_3600)
+2 -2
drivers/target/iscsi/iscsi_target_tmr.c
··· 120 120 struct iscsi_tmr_req *tmr_req = cmd->tmr_req; 121 121 struct se_tmr_req *se_tmr = cmd->se_cmd.se_tmr_req; 122 122 struct iscsi_tm *hdr = (struct iscsi_tm *) buf; 123 - int ret, ref_lun; 123 + u64 ret, ref_lun; 124 124 125 125 pr_debug("Got TASK_REASSIGN TMR ITT: 0x%08x," 126 126 " RefTaskTag: 0x%08x, ExpDataSN: 0x%08x, CID: %hu\n", ··· 164 164 ref_lun = scsilun_to_int(&hdr->lun); 165 165 if (ref_lun != ref_cmd->se_cmd.orig_fe_lun) { 166 166 pr_err("Unable to perform connection recovery for" 167 - " differing ref_lun: %d ref_cmd orig_fe_lun: %u\n", 167 + " differing ref_lun: %llu ref_cmd orig_fe_lun: %llu\n", 168 168 ref_lun, ref_cmd->se_cmd.orig_fe_lun); 169 169 return ISCSI_TMF_RSP_REJECTED; 170 170 }
+6 -6
drivers/target/iscsi/iscsi_target_tpg.c
··· 18 18 19 19 #include <target/target_core_base.h> 20 20 #include <target/target_core_fabric.h> 21 - #include <target/target_core_configfs.h> 22 21 23 22 #include <target/iscsi/iscsi_target_core.h> 24 23 #include "iscsi_target_erl0.h" ··· 66 67 pr_err("Unable to allocate struct iscsi_portal_group\n"); 67 68 return -1; 68 69 } 69 - 70 - ret = core_tpg_register(&iscsi_ops, NULL, &tpg->tpg_se_tpg, 71 - tpg, TRANSPORT_TPG_TYPE_DISCOVERY); 70 + /* 71 + * Save iscsi_ops pointer for special case discovery TPG that 72 + * doesn't exist as se_wwn->wwn_group within configfs. 73 + */ 74 + tpg->tpg_se_tpg.se_tpg_tfo = &iscsi_ops; 75 + ret = core_tpg_register(NULL, &tpg->tpg_se_tpg, -1); 72 76 if (ret < 0) { 73 77 kfree(tpg); 74 78 return -1; ··· 281 279 tpg->tpg_state = old_state; 282 280 return -EPERM; 283 281 } 284 - 285 - core_tpg_clear_object_luns(&tpg->tpg_se_tpg); 286 282 287 283 if (tpg->param_list) { 288 284 iscsi_release_param_list(tpg->param_list);
+2 -51
drivers/target/iscsi/iscsi_target_util.c
··· 22 22 #include <scsi/iscsi_proto.h> 23 23 #include <target/target_core_base.h> 24 24 #include <target/target_core_fabric.h> 25 - #include <target/target_core_configfs.h> 26 25 #include <target/iscsi/iscsi_transport.h> 27 26 28 27 #include <target/iscsi/iscsi_target_core.h> ··· 745 746 rc = transport_generic_free_cmd(&cmd->se_cmd, shutdown); 746 747 if (!rc && shutdown && se_cmd && se_cmd->se_sess) { 747 748 __iscsit_free_cmd(cmd, true, shutdown); 748 - target_put_sess_cmd(se_cmd->se_sess, se_cmd); 749 + target_put_sess_cmd(se_cmd); 749 750 } 750 751 break; 751 752 case ISCSI_OP_REJECT: ··· 761 762 rc = transport_generic_free_cmd(&cmd->se_cmd, shutdown); 762 763 if (!rc && shutdown && se_cmd->se_sess) { 763 764 __iscsit_free_cmd(cmd, true, shutdown); 764 - target_put_sess_cmd(se_cmd->se_sess, se_cmd); 765 + target_put_sess_cmd(se_cmd); 765 766 } 766 767 break; 767 768 } ··· 806 807 spin_lock_bh(&sess->session_usage_lock); 807 808 sess->session_usage_count++; 808 809 spin_unlock_bh(&sess->session_usage_lock); 809 - } 810 - 811 - /* 812 - * Setup conn->if_marker and conn->of_marker values based upon 813 - * the initial marker-less interval. (see iSCSI v19 A.2) 814 - */ 815 - int iscsit_set_sync_and_steering_values(struct iscsi_conn *conn) 816 - { 817 - int login_ifmarker_count = 0, login_ofmarker_count = 0, next_marker = 0; 818 - /* 819 - * IFMarkInt and OFMarkInt are negotiated as 32-bit words. 820 - */ 821 - u32 IFMarkInt = (conn->conn_ops->IFMarkInt * 4); 822 - u32 OFMarkInt = (conn->conn_ops->OFMarkInt * 4); 823 - 824 - if (conn->conn_ops->OFMarker) { 825 - /* 826 - * Account for the first Login Command received not 827 - * via iscsi_recv_msg(). 828 - */ 829 - conn->of_marker += ISCSI_HDR_LEN; 830 - if (conn->of_marker <= OFMarkInt) { 831 - conn->of_marker = (OFMarkInt - conn->of_marker); 832 - } else { 833 - login_ofmarker_count = (conn->of_marker / OFMarkInt); 834 - next_marker = (OFMarkInt * (login_ofmarker_count + 1)) + 835 - (login_ofmarker_count * MARKER_SIZE); 836 - conn->of_marker = (next_marker - conn->of_marker); 837 - } 838 - conn->of_marker_offset = 0; 839 - pr_debug("Setting OFMarker value to %u based on Initial" 840 - " Markerless Interval.\n", conn->of_marker); 841 - } 842 - 843 - if (conn->conn_ops->IFMarker) { 844 - if (conn->if_marker <= IFMarkInt) { 845 - conn->if_marker = (IFMarkInt - conn->if_marker); 846 - } else { 847 - login_ifmarker_count = (conn->if_marker / IFMarkInt); 848 - next_marker = (IFMarkInt * (login_ifmarker_count + 1)) + 849 - (login_ifmarker_count * MARKER_SIZE); 850 - conn->if_marker = (next_marker - conn->if_marker); 851 - } 852 - pr_debug("Setting IFMarker value to %u based on Initial" 853 - " Markerless Interval.\n", conn->if_marker); 854 - } 855 - 856 - return 0; 857 810 } 858 811 859 812 struct iscsi_conn *iscsit_get_conn_from_cid(struct iscsi_session *sess, u16 cid)
-1
drivers/target/iscsi/iscsi_target_util.h
··· 34 34 extern int iscsit_check_session_usage_count(struct iscsi_session *); 35 35 extern void iscsit_dec_session_usage_count(struct iscsi_session *); 36 36 extern void iscsit_inc_session_usage_count(struct iscsi_session *); 37 - extern int iscsit_set_sync_and_steering_values(struct iscsi_conn *); 38 37 extern struct iscsi_conn *iscsit_get_conn_from_cid(struct iscsi_session *, u16); 39 38 extern struct iscsi_conn *iscsit_get_conn_from_cid_rcfr(struct iscsi_session *, u16); 40 39 extern void iscsit_check_conn_usage_count(struct iscsi_conn *);
+9 -173
drivers/target/loopback/tcm_loop.c
··· 35 35 #include <target/target_core_base.h> 36 36 #include <target/target_core_fabric.h> 37 37 #include <target/target_core_fabric_configfs.h> 38 - #include <target/target_core_configfs.h> 39 38 40 39 #include "tcm_loop.h" 41 40 42 41 #define to_tcm_loop_hba(hba) container_of(hba, struct tcm_loop_hba, dev) 43 - 44 - static const struct target_core_fabric_ops loop_ops; 45 42 46 43 static struct workqueue_struct *tcm_loop_workqueue; 47 44 static struct kmem_cache *tcm_loop_cmd_cache; ··· 162 165 transfer_length = scsi_bufflen(sc); 163 166 } 164 167 168 + se_cmd->tag = tl_cmd->sc_cmd_tag; 165 169 rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd, 166 170 &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun, 167 171 transfer_length, TCM_SIMPLE_TAG, ··· 215 217 * to struct scsi_device 216 218 */ 217 219 static int tcm_loop_issue_tmr(struct tcm_loop_tpg *tl_tpg, 218 - int lun, int task, enum tcm_tmreq_table tmr) 220 + u64 lun, int task, enum tcm_tmreq_table tmr) 219 221 { 220 222 struct se_cmd *se_cmd = NULL; 221 223 struct se_session *se_sess; ··· 407 409 sh->max_id = 2; 408 410 sh->max_lun = 0; 409 411 sh->max_channel = 0; 410 - sh->max_cmd_len = TL_SCSI_MAX_CMD_LEN; 412 + sh->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE; 411 413 412 414 host_prot = SHOST_DIF_TYPE1_PROTECTION | SHOST_DIF_TYPE2_PROTECTION | 413 415 SHOST_DIF_TYPE3_PROTECTION | SHOST_DIX_TYPE1_PROTECTION | ··· 518 520 return "loopback"; 519 521 } 520 522 521 - static u8 tcm_loop_get_fabric_proto_ident(struct se_portal_group *se_tpg) 523 + static inline struct tcm_loop_tpg *tl_tpg(struct se_portal_group *se_tpg) 522 524 { 523 - struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr; 524 - struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; 525 - /* 526 - * tl_proto_id is set at tcm_loop_configfs.c:tcm_loop_make_scsi_hba() 527 - * time based on the protocol dependent prefix of the passed configfs group. 528 - * 529 - * Based upon tl_proto_id, TCM_Loop emulates the requested fabric 530 - * ProtocolID using target_core_fabric_lib.c symbols. 531 - */ 532 - switch (tl_hba->tl_proto_id) { 533 - case SCSI_PROTOCOL_SAS: 534 - return sas_get_fabric_proto_ident(se_tpg); 535 - case SCSI_PROTOCOL_FCP: 536 - return fc_get_fabric_proto_ident(se_tpg); 537 - case SCSI_PROTOCOL_ISCSI: 538 - return iscsi_get_fabric_proto_ident(se_tpg); 539 - default: 540 - pr_err("Unknown tl_proto_id: 0x%02x, using" 541 - " SAS emulation\n", tl_hba->tl_proto_id); 542 - break; 543 - } 544 - 545 - return sas_get_fabric_proto_ident(se_tpg); 525 + return container_of(se_tpg, struct tcm_loop_tpg, tl_se_tpg); 546 526 } 547 527 548 528 static char *tcm_loop_get_endpoint_wwn(struct se_portal_group *se_tpg) 549 529 { 550 - struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr; 551 530 /* 552 531 * Return the passed NAA identifier for the SAS Target Port 553 532 */ 554 - return &tl_tpg->tl_hba->tl_wwn_address[0]; 533 + return &tl_tpg(se_tpg)->tl_hba->tl_wwn_address[0]; 555 534 } 556 535 557 536 static u16 tcm_loop_get_tag(struct se_portal_group *se_tpg) 558 537 { 559 - struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr; 560 538 /* 561 539 * This Tag is used when forming SCSI Name identifier in EVPD=1 0x83 562 540 * to represent the SCSI Target Port. 563 541 */ 564 - return tl_tpg->tl_tpgt; 565 - } 566 - 567 - static u32 tcm_loop_get_default_depth(struct se_portal_group *se_tpg) 568 - { 569 - return 1; 570 - } 571 - 572 - static u32 tcm_loop_get_pr_transport_id( 573 - struct se_portal_group *se_tpg, 574 - struct se_node_acl *se_nacl, 575 - struct t10_pr_registration *pr_reg, 576 - int *format_code, 577 - unsigned char *buf) 578 - { 579 - struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr; 580 - struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; 581 - 582 - switch (tl_hba->tl_proto_id) { 583 - case SCSI_PROTOCOL_SAS: 584 - return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 585 - format_code, buf); 586 - case SCSI_PROTOCOL_FCP: 587 - return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 588 - format_code, buf); 589 - case SCSI_PROTOCOL_ISCSI: 590 - return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 591 - format_code, buf); 592 - default: 593 - pr_err("Unknown tl_proto_id: 0x%02x, using" 594 - " SAS emulation\n", tl_hba->tl_proto_id); 595 - break; 596 - } 597 - 598 - return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 599 - format_code, buf); 600 - } 601 - 602 - static u32 tcm_loop_get_pr_transport_id_len( 603 - struct se_portal_group *se_tpg, 604 - struct se_node_acl *se_nacl, 605 - struct t10_pr_registration *pr_reg, 606 - int *format_code) 607 - { 608 - struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr; 609 - struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; 610 - 611 - switch (tl_hba->tl_proto_id) { 612 - case SCSI_PROTOCOL_SAS: 613 - return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 614 - format_code); 615 - case SCSI_PROTOCOL_FCP: 616 - return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 617 - format_code); 618 - case SCSI_PROTOCOL_ISCSI: 619 - return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 620 - format_code); 621 - default: 622 - pr_err("Unknown tl_proto_id: 0x%02x, using" 623 - " SAS emulation\n", tl_hba->tl_proto_id); 624 - break; 625 - } 626 - 627 - return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 628 - format_code); 629 - } 630 - 631 - /* 632 - * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above 633 - * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations. 634 - */ 635 - static char *tcm_loop_parse_pr_out_transport_id( 636 - struct se_portal_group *se_tpg, 637 - const char *buf, 638 - u32 *out_tid_len, 639 - char **port_nexus_ptr) 640 - { 641 - struct tcm_loop_tpg *tl_tpg = se_tpg->se_tpg_fabric_ptr; 642 - struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; 643 - 644 - switch (tl_hba->tl_proto_id) { 645 - case SCSI_PROTOCOL_SAS: 646 - return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 647 - port_nexus_ptr); 648 - case SCSI_PROTOCOL_FCP: 649 - return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 650 - port_nexus_ptr); 651 - case SCSI_PROTOCOL_ISCSI: 652 - return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 653 - port_nexus_ptr); 654 - default: 655 - pr_err("Unknown tl_proto_id: 0x%02x, using" 656 - " SAS emulation\n", tl_hba->tl_proto_id); 657 - break; 658 - } 659 - 660 - return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 661 - port_nexus_ptr); 542 + return tl_tpg(se_tpg)->tl_tpgt; 662 543 } 663 544 664 545 /* ··· 580 703 return tl_tpg->tl_fabric_prot_type; 581 704 } 582 705 583 - static struct se_node_acl *tcm_loop_tpg_alloc_fabric_acl( 584 - struct se_portal_group *se_tpg) 585 - { 586 - struct tcm_loop_nacl *tl_nacl; 587 - 588 - tl_nacl = kzalloc(sizeof(struct tcm_loop_nacl), GFP_KERNEL); 589 - if (!tl_nacl) { 590 - pr_err("Unable to allocate struct tcm_loop_nacl\n"); 591 - return NULL; 592 - } 593 - 594 - return &tl_nacl->se_node_acl; 595 - } 596 - 597 - static void tcm_loop_tpg_release_fabric_acl( 598 - struct se_portal_group *se_tpg, 599 - struct se_node_acl *se_nacl) 600 - { 601 - struct tcm_loop_nacl *tl_nacl = container_of(se_nacl, 602 - struct tcm_loop_nacl, se_node_acl); 603 - 604 - kfree(tl_nacl); 605 - } 606 - 607 706 static u32 tcm_loop_get_inst_index(struct se_portal_group *se_tpg) 608 707 { 609 708 return 1; ··· 593 740 static void tcm_loop_set_default_node_attributes(struct se_node_acl *se_acl) 594 741 { 595 742 return; 596 - } 597 - 598 - static u32 tcm_loop_get_task_tag(struct se_cmd *se_cmd) 599 - { 600 - struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, 601 - struct tcm_loop_cmd, tl_se_cmd); 602 - 603 - return tl_cmd->sc_cmd_tag; 604 743 } 605 744 606 745 static int tcm_loop_get_cmd_state(struct se_cmd *se_cmd) ··· 747 902 se_lun->unpacked_lun); 748 903 if (!sd) { 749 904 pr_err("Unable to locate struct scsi_device for %d:%d:" 750 - "%d\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun); 905 + "%llu\n", 0, tl_tpg->tl_tpgt, se_lun->unpacked_lun); 751 906 return; 752 907 } 753 908 /* ··· 1079 1234 /* 1080 1235 * Register the tl_tpg as a emulated SAS TCM Target Endpoint 1081 1236 */ 1082 - ret = core_tpg_register(&loop_ops, wwn, &tl_tpg->tl_se_tpg, tl_tpg, 1083 - TRANSPORT_TPG_TYPE_NORMAL); 1237 + ret = core_tpg_register(wwn, &tl_tpg->tl_se_tpg, tl_hba->tl_proto_id); 1084 1238 if (ret < 0) 1085 1239 return ERR_PTR(-ENOMEM); 1086 1240 ··· 1230 1386 .module = THIS_MODULE, 1231 1387 .name = "loopback", 1232 1388 .get_fabric_name = tcm_loop_get_fabric_name, 1233 - .get_fabric_proto_ident = tcm_loop_get_fabric_proto_ident, 1234 1389 .tpg_get_wwn = tcm_loop_get_endpoint_wwn, 1235 1390 .tpg_get_tag = tcm_loop_get_tag, 1236 - .tpg_get_default_depth = tcm_loop_get_default_depth, 1237 - .tpg_get_pr_transport_id = tcm_loop_get_pr_transport_id, 1238 - .tpg_get_pr_transport_id_len = tcm_loop_get_pr_transport_id_len, 1239 - .tpg_parse_pr_out_transport_id = tcm_loop_parse_pr_out_transport_id, 1240 1391 .tpg_check_demo_mode = tcm_loop_check_demo_mode, 1241 1392 .tpg_check_demo_mode_cache = tcm_loop_check_demo_mode_cache, 1242 1393 .tpg_check_demo_mode_write_protect = ··· 1239 1400 .tpg_check_prod_mode_write_protect = 1240 1401 tcm_loop_check_prod_mode_write_protect, 1241 1402 .tpg_check_prot_fabric_only = tcm_loop_check_prot_fabric_only, 1242 - .tpg_alloc_fabric_acl = tcm_loop_tpg_alloc_fabric_acl, 1243 - .tpg_release_fabric_acl = tcm_loop_tpg_release_fabric_acl, 1244 1403 .tpg_get_inst_index = tcm_loop_get_inst_index, 1245 1404 .check_stop_free = tcm_loop_check_stop_free, 1246 1405 .release_cmd = tcm_loop_release_cmd, ··· 1248 1411 .write_pending = tcm_loop_write_pending, 1249 1412 .write_pending_status = tcm_loop_write_pending_status, 1250 1413 .set_default_node_attributes = tcm_loop_set_default_node_attributes, 1251 - .get_task_tag = tcm_loop_get_task_tag, 1252 1414 .get_cmd_state = tcm_loop_get_cmd_state, 1253 1415 .queue_data_in = tcm_loop_queue_data_in, 1254 1416 .queue_status = tcm_loop_queue_status,
-9
drivers/target/loopback/tcm_loop.h
··· 2 2 #define TL_WWN_ADDR_LEN 256 3 3 #define TL_TPGS_PER_HBA 32 4 4 5 - /* 6 - * Used in tcm_loop_driver_probe() for struct Scsi_Host->max_cmd_len 7 - */ 8 - #define TL_SCSI_MAX_CMD_LEN 32 9 - 10 5 struct tcm_loop_cmd { 11 6 /* State of Linux/SCSI CDB+Data descriptor */ 12 7 u32 sc_cmd_state; ··· 26 31 * Pointer to TCM session for I_T Nexus 27 32 */ 28 33 struct se_session *se_sess; 29 - }; 30 - 31 - struct tcm_loop_nacl { 32 - struct se_node_acl se_node_acl; 33 34 }; 34 35 35 36 #define TCM_TRANSPORT_ONLINE 0
+53 -222
drivers/target/sbp/sbp_target.c
··· 36 36 #include <target/target_core_backend.h> 37 37 #include <target/target_core_fabric.h> 38 38 #include <target/target_core_fabric_configfs.h> 39 - #include <target/target_core_configfs.h> 40 39 #include <target/configfs_macros.h> 41 40 #include <asm/unaligned.h> 42 41 ··· 108 109 } 109 110 110 111 static struct sbp_login_descriptor *sbp_login_find_by_lun( 111 - struct sbp_session *session, struct se_lun *lun) 112 + struct sbp_session *session, u32 unpacked_lun) 112 113 { 113 114 struct sbp_login_descriptor *login, *found = NULL; 114 115 115 116 spin_lock_bh(&session->lock); 116 117 list_for_each_entry(login, &session->login_list, link) { 117 - if (login->lun == lun) 118 + if (login->login_lun == unpacked_lun) 118 119 found = login; 119 120 } 120 121 spin_unlock_bh(&session->lock); ··· 124 125 125 126 static int sbp_login_count_all_by_lun( 126 127 struct sbp_tpg *tpg, 127 - struct se_lun *lun, 128 + u32 unpacked_lun, 128 129 int exclusive) 129 130 { 130 131 struct se_session *se_sess; ··· 138 139 139 140 spin_lock_bh(&sess->lock); 140 141 list_for_each_entry(login, &sess->login_list, link) { 141 - if (login->lun != lun) 142 + if (login->login_lun != unpacked_lun) 142 143 continue; 143 144 144 145 if (!exclusive || login->exclusive) ··· 174 175 return found; 175 176 } 176 177 177 - static struct se_lun *sbp_get_lun_from_tpg(struct sbp_tpg *tpg, int lun) 178 + static u32 sbp_get_lun_from_tpg(struct sbp_tpg *tpg, u32 login_lun, int *err) 178 179 { 179 180 struct se_portal_group *se_tpg = &tpg->se_tpg; 180 181 struct se_lun *se_lun; 181 182 182 - if (lun >= TRANSPORT_MAX_LUNS_PER_TPG) 183 - return ERR_PTR(-EINVAL); 183 + rcu_read_lock(); 184 + hlist_for_each_entry_rcu(se_lun, &se_tpg->tpg_lun_hlist, link) { 185 + if (se_lun->unpacked_lun == login_lun) { 186 + rcu_read_unlock(); 187 + *err = 0; 188 + return login_lun; 189 + } 190 + } 191 + rcu_read_unlock(); 184 192 185 - spin_lock(&se_tpg->tpg_lun_lock); 186 - se_lun = se_tpg->tpg_lun_list[lun]; 187 - 188 - if (se_lun->lun_status != TRANSPORT_LUN_STATUS_ACTIVE) 189 - se_lun = ERR_PTR(-ENODEV); 190 - 191 - spin_unlock(&se_tpg->tpg_lun_lock); 192 - 193 - return se_lun; 193 + *err = -ENODEV; 194 + return login_lun; 194 195 } 195 196 196 197 static struct sbp_session *sbp_session_create( ··· 294 295 { 295 296 struct sbp_tport *tport = agent->tport; 296 297 struct sbp_tpg *tpg = tport->tpg; 297 - struct se_lun *se_lun; 298 - int ret; 299 - u64 guid; 300 298 struct sbp_session *sess; 301 299 struct sbp_login_descriptor *login; 302 300 struct sbp_login_response_block *response; 303 - int login_response_len; 301 + u64 guid; 302 + u32 unpacked_lun; 303 + int login_response_len, ret; 304 304 305 - se_lun = sbp_get_lun_from_tpg(tpg, 306 - LOGIN_ORB_LUN(be32_to_cpu(req->orb.misc))); 307 - if (IS_ERR(se_lun)) { 305 + unpacked_lun = sbp_get_lun_from_tpg(tpg, 306 + LOGIN_ORB_LUN(be32_to_cpu(req->orb.misc)), &ret); 307 + if (ret) { 308 308 pr_notice("login to unknown LUN: %d\n", 309 309 LOGIN_ORB_LUN(be32_to_cpu(req->orb.misc))); 310 310 ··· 324 326 } 325 327 326 328 pr_notice("mgt_agent LOGIN to LUN %d from %016llx\n", 327 - se_lun->unpacked_lun, guid); 329 + unpacked_lun, guid); 328 330 329 331 sess = sbp_session_find_by_guid(tpg, guid); 330 332 if (sess) { 331 - login = sbp_login_find_by_lun(sess, se_lun); 333 + login = sbp_login_find_by_lun(sess, unpacked_lun); 332 334 if (login) { 333 335 pr_notice("initiator already logged-in\n"); 334 336 ··· 356 358 * reject with access_denied if any logins present 357 359 */ 358 360 if (LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc)) && 359 - sbp_login_count_all_by_lun(tpg, se_lun, 0)) { 361 + sbp_login_count_all_by_lun(tpg, unpacked_lun, 0)) { 360 362 pr_warn("refusing exclusive login with other active logins\n"); 361 363 362 364 req->status.status = cpu_to_be32( ··· 369 371 * check exclusive bit in any existing login descriptor 370 372 * reject with access_denied if any exclusive logins present 371 373 */ 372 - if (sbp_login_count_all_by_lun(tpg, se_lun, 1)) { 374 + if (sbp_login_count_all_by_lun(tpg, unpacked_lun, 1)) { 373 375 pr_warn("refusing login while another exclusive login present\n"); 374 376 375 377 req->status.status = cpu_to_be32( ··· 382 384 * check we haven't exceeded the number of allowed logins 383 385 * reject with resources_unavailable if we have 384 386 */ 385 - if (sbp_login_count_all_by_lun(tpg, se_lun, 0) >= 387 + if (sbp_login_count_all_by_lun(tpg, unpacked_lun, 0) >= 386 388 tport->max_logins_per_lun) { 387 389 pr_warn("max number of logins reached\n"); 388 390 ··· 438 440 } 439 441 440 442 login->sess = sess; 441 - login->lun = se_lun; 443 + login->login_lun = unpacked_lun; 442 444 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo); 443 445 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc)); 444 446 login->login_id = atomic_inc_return(&login_id); ··· 600 602 } 601 603 602 604 pr_info("mgt_agent LOGOUT from LUN %d session %d\n", 603 - login->lun->unpacked_lun, login->login_id); 605 + login->login_lun, login->login_id); 604 606 605 607 if (req->node_addr != login->sess->node_id) { 606 608 pr_warn("logout from different node ID\n"); ··· 1226 1228 goto err; 1227 1229 } 1228 1230 1229 - unpacked_lun = req->login->lun->unpacked_lun; 1231 + unpacked_lun = req->login->login_lun; 1230 1232 sbp_calc_data_length_direction(req, &data_length, &data_dir); 1231 1233 1232 1234 pr_debug("sbp_handle_command ORB:0x%llx unpacked_lun:%d data_len:%d data_dir:%d\n", 1233 1235 req->orb_pointer, unpacked_lun, data_length, data_dir); 1234 1236 1237 + /* only used for printk until we do TMRs */ 1238 + req->se_cmd.tag = req->orb_pointer; 1235 1239 if (target_submit_cmd(&req->se_cmd, sess->se_sess, req->cmd_buf, 1236 1240 req->sense_buf, unpacked_lun, data_length, 1237 1241 TCM_SIMPLE_TAG, data_dir, 0)) ··· 1707 1707 return tpg->tport_tpgt; 1708 1708 } 1709 1709 1710 - static u32 sbp_get_default_depth(struct se_portal_group *se_tpg) 1711 - { 1712 - return 1; 1713 - } 1714 - 1715 - static struct se_node_acl *sbp_alloc_fabric_acl(struct se_portal_group *se_tpg) 1716 - { 1717 - struct sbp_nacl *nacl; 1718 - 1719 - nacl = kzalloc(sizeof(struct sbp_nacl), GFP_KERNEL); 1720 - if (!nacl) { 1721 - pr_err("Unable to allocate struct sbp_nacl\n"); 1722 - return NULL; 1723 - } 1724 - 1725 - return &nacl->se_node_acl; 1726 - } 1727 - 1728 - static void sbp_release_fabric_acl( 1729 - struct se_portal_group *se_tpg, 1730 - struct se_node_acl *se_nacl) 1731 - { 1732 - struct sbp_nacl *nacl = 1733 - container_of(se_nacl, struct sbp_nacl, se_node_acl); 1734 - kfree(nacl); 1735 - } 1736 - 1737 1710 static u32 sbp_tpg_get_inst_index(struct se_portal_group *se_tpg) 1738 1711 { 1739 1712 return 1; ··· 1768 1795 return; 1769 1796 } 1770 1797 1771 - static u32 sbp_get_task_tag(struct se_cmd *se_cmd) 1772 - { 1773 - struct sbp_target_request *req = container_of(se_cmd, 1774 - struct sbp_target_request, se_cmd); 1775 - 1776 - /* only used for printk until we do TMRs */ 1777 - return (u32)req->orb_pointer; 1778 - } 1779 - 1780 1798 static int sbp_get_cmd_state(struct se_cmd *se_cmd) 1781 1799 { 1782 1800 return 0; ··· 1823 1859 return 1; 1824 1860 } 1825 1861 1826 - /* 1827 - * Handlers for Serial Bus Protocol 2/3 (SBP-2 / SBP-3) 1828 - */ 1829 - static u8 sbp_get_fabric_proto_ident(struct se_portal_group *se_tpg) 1830 - { 1831 - /* 1832 - * Return a IEEE 1394 SCSI Protocol identifier for loopback operations 1833 - * This is defined in section 7.5.1 Table 362 in spc4r17 1834 - */ 1835 - return SCSI_PROTOCOL_SBP; 1836 - } 1837 - 1838 - static u32 sbp_get_pr_transport_id( 1839 - struct se_portal_group *se_tpg, 1840 - struct se_node_acl *se_nacl, 1841 - struct t10_pr_registration *pr_reg, 1842 - int *format_code, 1843 - unsigned char *buf) 1844 - { 1845 - int ret; 1846 - 1847 - /* 1848 - * Set PROTOCOL IDENTIFIER to 3h for SBP 1849 - */ 1850 - buf[0] = SCSI_PROTOCOL_SBP; 1851 - /* 1852 - * From spc4r17, 7.5.4.4 TransportID for initiator ports using SCSI 1853 - * over IEEE 1394 1854 - */ 1855 - ret = hex2bin(&buf[8], se_nacl->initiatorname, 8); 1856 - if (ret < 0) 1857 - pr_debug("sbp transport_id: invalid hex string\n"); 1858 - 1859 - /* 1860 - * The IEEE 1394 Transport ID is a hardcoded 24-byte length 1861 - */ 1862 - return 24; 1863 - } 1864 - 1865 - static u32 sbp_get_pr_transport_id_len( 1866 - struct se_portal_group *se_tpg, 1867 - struct se_node_acl *se_nacl, 1868 - struct t10_pr_registration *pr_reg, 1869 - int *format_code) 1870 - { 1871 - *format_code = 0; 1872 - /* 1873 - * From spc4r17, 7.5.4.4 TransportID for initiator ports using SCSI 1874 - * over IEEE 1394 1875 - * 1876 - * The SBP Transport ID is a hardcoded 24-byte length 1877 - */ 1878 - return 24; 1879 - } 1880 - 1881 - /* 1882 - * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above 1883 - * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations. 1884 - */ 1885 - static char *sbp_parse_pr_out_transport_id( 1886 - struct se_portal_group *se_tpg, 1887 - const char *buf, 1888 - u32 *out_tid_len, 1889 - char **port_nexus_ptr) 1890 - { 1891 - /* 1892 - * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.4 TransportID 1893 - * for initiator ports using SCSI over SBP Serial SCSI Protocol 1894 - * 1895 - * The TransportID for a IEEE 1394 Initiator Port is of fixed size of 1896 - * 24 bytes, and IEEE 1394 does not contain a I_T nexus identifier, 1897 - * so we return the **port_nexus_ptr set to NULL. 1898 - */ 1899 - *port_nexus_ptr = NULL; 1900 - *out_tid_len = 24; 1901 - 1902 - return (char *)&buf[8]; 1903 - } 1904 - 1905 1862 static int sbp_count_se_tpg_luns(struct se_portal_group *tpg) 1906 1863 { 1907 - int i, count = 0; 1864 + struct se_lun *lun; 1865 + int count = 0; 1908 1866 1909 - spin_lock(&tpg->tpg_lun_lock); 1910 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 1911 - struct se_lun *se_lun = tpg->tpg_lun_list[i]; 1912 - 1913 - if (se_lun->lun_status == TRANSPORT_LUN_STATUS_FREE) 1914 - continue; 1915 - 1867 + rcu_read_lock(); 1868 + hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link) 1916 1869 count++; 1917 - } 1918 - spin_unlock(&tpg->tpg_lun_lock); 1870 + rcu_read_unlock(); 1919 1871 1920 1872 return count; 1921 1873 } 1922 1874 1923 1875 static int sbp_update_unit_directory(struct sbp_tport *tport) 1924 1876 { 1925 - int num_luns, num_entries, idx = 0, mgt_agt_addr, ret, i; 1877 + struct se_lun *lun; 1878 + int num_luns, num_entries, idx = 0, mgt_agt_addr, ret; 1926 1879 u32 *data; 1927 1880 1928 1881 if (tport->unit_directory.data) { ··· 1901 2020 /* unit unique ID (leaf is just after LUNs) */ 1902 2021 data[idx++] = 0x8d000000 | (num_luns + 1); 1903 2022 1904 - spin_lock(&tport->tpg->se_tpg.tpg_lun_lock); 1905 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 1906 - struct se_lun *se_lun = tport->tpg->se_tpg.tpg_lun_list[i]; 2023 + rcu_read_lock(); 2024 + hlist_for_each_entry_rcu(lun, &tport->tpg->se_tpg.tpg_lun_hlist, link) { 1907 2025 struct se_device *dev; 1908 2026 int type; 1909 - 1910 - if (se_lun->lun_status == TRANSPORT_LUN_STATUS_FREE) 1911 - continue; 1912 - 1913 - spin_unlock(&tport->tpg->se_tpg.tpg_lun_lock); 1914 - 1915 - dev = se_lun->lun_se_dev; 2027 + /* 2028 + * rcu_dereference_raw protected by se_lun->lun_group symlink 2029 + * reference to se_device->dev_group. 2030 + */ 2031 + dev = rcu_dereference_raw(lun->lun_se_dev); 1916 2032 type = dev->transport->get_device_type(dev); 1917 2033 1918 2034 /* logical_unit_number */ 1919 2035 data[idx++] = 0x14000000 | 1920 2036 ((type << 16) & 0x1f0000) | 1921 - (se_lun->unpacked_lun & 0xffff); 1922 - 1923 - spin_lock(&tport->tpg->se_tpg.tpg_lun_lock); 2037 + (lun->unpacked_lun & 0xffff); 1924 2038 } 1925 - spin_unlock(&tport->tpg->se_tpg.tpg_lun_lock); 2039 + rcu_read_unlock(); 1926 2040 1927 2041 /* unit unique ID leaf */ 1928 2042 data[idx++] = 2 << 16; ··· 1976 2100 return snprintf(buf, len, "%016llx", wwn); 1977 2101 } 1978 2102 1979 - static struct se_node_acl *sbp_make_nodeacl( 1980 - struct se_portal_group *se_tpg, 1981 - struct config_group *group, 1982 - const char *name) 2103 + static int sbp_init_nodeacl(struct se_node_acl *se_nacl, const char *name) 1983 2104 { 1984 - struct se_node_acl *se_nacl, *se_nacl_new; 1985 - struct sbp_nacl *nacl; 1986 2105 u64 guid = 0; 1987 - u32 nexus_depth = 1; 1988 2106 1989 2107 if (sbp_parse_wwn(name, &guid) < 0) 1990 - return ERR_PTR(-EINVAL); 1991 - 1992 - se_nacl_new = sbp_alloc_fabric_acl(se_tpg); 1993 - if (!se_nacl_new) 1994 - return ERR_PTR(-ENOMEM); 1995 - 1996 - /* 1997 - * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 1998 - * when converting a NodeACL from demo mode -> explict 1999 - */ 2000 - se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 2001 - name, nexus_depth); 2002 - if (IS_ERR(se_nacl)) { 2003 - sbp_release_fabric_acl(se_tpg, se_nacl_new); 2004 - return se_nacl; 2005 - } 2006 - 2007 - nacl = container_of(se_nacl, struct sbp_nacl, se_node_acl); 2008 - nacl->guid = guid; 2009 - sbp_format_wwn(nacl->iport_name, SBP_NAMELEN, guid); 2010 - 2011 - return se_nacl; 2012 - } 2013 - 2014 - static void sbp_drop_nodeacl(struct se_node_acl *se_acl) 2015 - { 2016 - struct sbp_nacl *nacl = 2017 - container_of(se_acl, struct sbp_nacl, se_node_acl); 2018 - 2019 - core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1); 2020 - kfree(nacl); 2108 + return -EINVAL; 2109 + return 0; 2021 2110 } 2022 2111 2023 2112 static int sbp_post_link_lun( ··· 2055 2214 goto out_free_tpg; 2056 2215 } 2057 2216 2058 - ret = core_tpg_register(&sbp_ops, wwn, &tpg->se_tpg, tpg, 2059 - TRANSPORT_TPG_TYPE_NORMAL); 2217 + ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SBP); 2060 2218 if (ret < 0) 2061 2219 goto out_unreg_mgt_agt; 2062 2220 ··· 2345 2505 .module = THIS_MODULE, 2346 2506 .name = "sbp", 2347 2507 .get_fabric_name = sbp_get_fabric_name, 2348 - .get_fabric_proto_ident = sbp_get_fabric_proto_ident, 2349 2508 .tpg_get_wwn = sbp_get_fabric_wwn, 2350 2509 .tpg_get_tag = sbp_get_tag, 2351 - .tpg_get_default_depth = sbp_get_default_depth, 2352 - .tpg_get_pr_transport_id = sbp_get_pr_transport_id, 2353 - .tpg_get_pr_transport_id_len = sbp_get_pr_transport_id_len, 2354 - .tpg_parse_pr_out_transport_id = sbp_parse_pr_out_transport_id, 2355 2510 .tpg_check_demo_mode = sbp_check_true, 2356 2511 .tpg_check_demo_mode_cache = sbp_check_true, 2357 2512 .tpg_check_demo_mode_write_protect = sbp_check_false, 2358 2513 .tpg_check_prod_mode_write_protect = sbp_check_false, 2359 - .tpg_alloc_fabric_acl = sbp_alloc_fabric_acl, 2360 - .tpg_release_fabric_acl = sbp_release_fabric_acl, 2361 2514 .tpg_get_inst_index = sbp_tpg_get_inst_index, 2362 2515 .release_cmd = sbp_release_cmd, 2363 2516 .shutdown_session = sbp_shutdown_session, ··· 2359 2526 .write_pending = sbp_write_pending, 2360 2527 .write_pending_status = sbp_write_pending_status, 2361 2528 .set_default_node_attributes = sbp_set_default_node_attrs, 2362 - .get_task_tag = sbp_get_task_tag, 2363 2529 .get_cmd_state = sbp_get_cmd_state, 2364 2530 .queue_data_in = sbp_queue_data_in, 2365 2531 .queue_status = sbp_queue_status, ··· 2374 2542 .fabric_pre_unlink = sbp_pre_unlink_lun, 2375 2543 .fabric_make_np = NULL, 2376 2544 .fabric_drop_np = NULL, 2377 - .fabric_make_nodeacl = sbp_make_nodeacl, 2378 - .fabric_drop_nodeacl = sbp_drop_nodeacl, 2545 + .fabric_init_nodeacl = sbp_init_nodeacl, 2379 2546 2380 2547 .tfc_wwn_attrs = sbp_wwn_attrs, 2381 2548 .tfc_tpg_base_attrs = sbp_tpg_base_attrs,
+1 -10
drivers/target/sbp/sbp_target.h
··· 125 125 struct sbp_session *sess; 126 126 struct list_head link; 127 127 128 - struct se_lun *lun; 128 + u32 login_lun; 129 129 130 130 u64 status_fifo_addr; 131 131 int exclusive; ··· 149 149 150 150 int reconnect_hold; 151 151 u64 reconnect_expires; 152 - }; 153 - 154 - struct sbp_nacl { 155 - /* Initiator EUI-64 */ 156 - u64 guid; 157 - /* ASCII formatted GUID for SBP Initiator port */ 158 - char iport_name[SBP_NAMELEN]; 159 - /* Returned by sbp_make_nodeacl() */ 160 - struct se_node_acl se_node_acl; 161 152 }; 162 153 163 154 struct sbp_tpg {
+200 -263
drivers/target/target_core_alua.c
··· 34 34 #include <target/target_core_base.h> 35 35 #include <target/target_core_backend.h> 36 36 #include <target/target_core_fabric.h> 37 - #include <target/target_core_configfs.h> 38 37 39 38 #include "target_core_internal.h" 40 39 #include "target_core_alua.h" ··· 42 43 static sense_reason_t core_alua_check_transition(int state, int valid, 43 44 int *primary); 44 45 static int core_alua_set_tg_pt_secondary_state( 45 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, 46 - struct se_port *port, int explicit, int offline); 46 + struct se_lun *lun, int explicit, int offline); 47 47 48 48 static char *core_alua_dump_state(int state); 49 + 50 + static void __target_attach_tg_pt_gp(struct se_lun *lun, 51 + struct t10_alua_tg_pt_gp *tg_pt_gp); 49 52 50 53 static u16 alua_lu_gps_counter; 51 54 static u32 alua_lu_gps_count; ··· 146 145 target_emulate_report_target_port_groups(struct se_cmd *cmd) 147 146 { 148 147 struct se_device *dev = cmd->se_dev; 149 - struct se_port *port; 150 148 struct t10_alua_tg_pt_gp *tg_pt_gp; 151 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 149 + struct se_lun *lun; 152 150 unsigned char *buf; 153 151 u32 rd_len = 0, off; 154 152 int ext_hdr = (cmd->t_task_cdb[1] & 0x20); ··· 222 222 rd_len += 8; 223 223 224 224 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 225 - list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list, 226 - tg_pt_gp_mem_list) { 227 - port = tg_pt_gp_mem->tg_pt; 225 + list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list, 226 + lun_tg_pt_gp_link) { 228 227 /* 229 228 * Start Target Port descriptor format 230 229 * ··· 233 234 /* 234 235 * Set RELATIVE TARGET PORT IDENTIFIER 235 236 */ 236 - buf[off++] = ((port->sep_rtpi >> 8) & 0xff); 237 - buf[off++] = (port->sep_rtpi & 0xff); 237 + buf[off++] = ((lun->lun_rtpi >> 8) & 0xff); 238 + buf[off++] = (lun->lun_rtpi & 0xff); 238 239 rd_len += 4; 239 240 } 240 241 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); ··· 258 259 * this CDB was received upon to determine this value individually 259 260 * for ALUA target port group. 260 261 */ 261 - port = cmd->se_lun->lun_sep; 262 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 263 - if (tg_pt_gp_mem) { 264 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 265 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 266 - if (tg_pt_gp) 267 - buf[5] = tg_pt_gp->tg_pt_gp_implicit_trans_secs; 268 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 269 - } 262 + spin_lock(&cmd->se_lun->lun_tg_pt_gp_lock); 263 + tg_pt_gp = cmd->se_lun->lun_tg_pt_gp; 264 + if (tg_pt_gp) 265 + buf[5] = tg_pt_gp->tg_pt_gp_implicit_trans_secs; 266 + spin_unlock(&cmd->se_lun->lun_tg_pt_gp_lock); 270 267 } 271 268 transport_kunmap_data_sg(cmd); 272 269 ··· 279 284 target_emulate_set_target_port_groups(struct se_cmd *cmd) 280 285 { 281 286 struct se_device *dev = cmd->se_dev; 282 - struct se_port *port, *l_port = cmd->se_lun->lun_sep; 287 + struct se_lun *l_lun = cmd->se_lun; 283 288 struct se_node_acl *nacl = cmd->se_sess->se_node_acl; 284 289 struct t10_alua_tg_pt_gp *tg_pt_gp = NULL, *l_tg_pt_gp; 285 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, *l_tg_pt_gp_mem; 286 290 unsigned char *buf; 287 291 unsigned char *ptr; 288 292 sense_reason_t rc = TCM_NO_SENSE; 289 293 u32 len = 4; /* Skip over RESERVED area in header */ 290 294 int alua_access_state, primary = 0, valid_states; 291 295 u16 tg_pt_id, rtpi; 292 - 293 - if (!l_port) 294 - return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 295 296 296 297 if (cmd->data_length < 4) { 297 298 pr_warn("SET TARGET PORT GROUPS parameter list length %u too" ··· 303 312 * Determine if explicit ALUA via SET_TARGET_PORT_GROUPS is allowed 304 313 * for the local tg_pt_gp. 305 314 */ 306 - l_tg_pt_gp_mem = l_port->sep_alua_tg_pt_gp_mem; 307 - if (!l_tg_pt_gp_mem) { 308 - pr_err("Unable to access l_port->sep_alua_tg_pt_gp_mem\n"); 309 - rc = TCM_UNSUPPORTED_SCSI_OPCODE; 310 - goto out; 311 - } 312 - spin_lock(&l_tg_pt_gp_mem->tg_pt_gp_mem_lock); 313 - l_tg_pt_gp = l_tg_pt_gp_mem->tg_pt_gp; 315 + spin_lock(&l_lun->lun_tg_pt_gp_lock); 316 + l_tg_pt_gp = l_lun->lun_tg_pt_gp; 314 317 if (!l_tg_pt_gp) { 315 - spin_unlock(&l_tg_pt_gp_mem->tg_pt_gp_mem_lock); 316 - pr_err("Unable to access *l_tg_pt_gp_mem->tg_pt_gp\n"); 318 + spin_unlock(&l_lun->lun_tg_pt_gp_lock); 319 + pr_err("Unable to access l_lun->tg_pt_gp\n"); 317 320 rc = TCM_UNSUPPORTED_SCSI_OPCODE; 318 321 goto out; 319 322 } 320 - spin_unlock(&l_tg_pt_gp_mem->tg_pt_gp_mem_lock); 321 323 322 324 if (!(l_tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA)) { 325 + spin_unlock(&l_lun->lun_tg_pt_gp_lock); 323 326 pr_debug("Unable to process SET_TARGET_PORT_GROUPS" 324 327 " while TPGS_EXPLICIT_ALUA is disabled\n"); 325 328 rc = TCM_UNSUPPORTED_SCSI_OPCODE; 326 329 goto out; 327 330 } 328 331 valid_states = l_tg_pt_gp->tg_pt_gp_alua_supported_states; 332 + spin_unlock(&l_lun->lun_tg_pt_gp_lock); 329 333 330 334 ptr = &buf[4]; /* Skip over RESERVED area in header */ 331 335 ··· 382 396 spin_unlock(&dev->t10_alua.tg_pt_gps_lock); 383 397 384 398 if (!core_alua_do_port_transition(tg_pt_gp, 385 - dev, l_port, nacl, 399 + dev, l_lun, nacl, 386 400 alua_access_state, 1)) 387 401 found = true; 388 402 ··· 392 406 } 393 407 spin_unlock(&dev->t10_alua.tg_pt_gps_lock); 394 408 } else { 409 + struct se_lun *lun; 410 + 395 411 /* 396 412 * Extract the RELATIVE TARGET PORT IDENTIFIER to identify 397 413 * the Target Port in question for the the incoming ··· 405 417 * for the struct se_device storage object. 406 418 */ 407 419 spin_lock(&dev->se_port_lock); 408 - list_for_each_entry(port, &dev->dev_sep_list, 409 - sep_list) { 410 - if (port->sep_rtpi != rtpi) 420 + list_for_each_entry(lun, &dev->dev_sep_list, 421 + lun_dev_link) { 422 + if (lun->lun_rtpi != rtpi) 411 423 continue; 412 424 413 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 414 - 425 + // XXX: racy unlock 415 426 spin_unlock(&dev->se_port_lock); 416 427 417 428 if (!core_alua_set_tg_pt_secondary_state( 418 - tg_pt_gp_mem, port, 1, 1)) 429 + lun, 1, 1)) 419 430 found = true; 420 431 421 432 spin_lock(&dev->se_port_lock); ··· 683 696 struct se_device *dev = cmd->se_dev; 684 697 unsigned char *cdb = cmd->t_task_cdb; 685 698 struct se_lun *lun = cmd->se_lun; 686 - struct se_port *port = lun->lun_sep; 687 699 struct t10_alua_tg_pt_gp *tg_pt_gp; 688 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 689 700 int out_alua_state, nonop_delay_msecs; 690 701 691 702 if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE) ··· 691 706 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) 692 707 return 0; 693 708 694 - if (!port) 695 - return 0; 696 709 /* 697 710 * First, check for a struct se_port specific secondary ALUA target port 698 711 * access state: OFFLINE 699 712 */ 700 - if (atomic_read(&port->sep_tg_pt_secondary_offline)) { 713 + if (atomic_read(&lun->lun_tg_pt_secondary_offline)) { 701 714 pr_debug("ALUA: Got secondary offline status for local" 702 715 " target port\n"); 703 716 set_ascq(cmd, ASCQ_04H_ALUA_OFFLINE); 704 717 return TCM_CHECK_CONDITION_NOT_READY; 705 718 } 706 - /* 707 - * Second, obtain the struct t10_alua_tg_pt_gp_member pointer to the 708 - * ALUA target port group, to obtain current ALUA access state. 709 - * Otherwise look for the underlying struct se_device association with 710 - * a ALUA logical unit group. 711 - */ 712 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 713 - if (!tg_pt_gp_mem) 719 + 720 + if (!lun->lun_tg_pt_gp) 714 721 return 0; 715 722 716 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 717 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 723 + spin_lock(&lun->lun_tg_pt_gp_lock); 724 + tg_pt_gp = lun->lun_tg_pt_gp; 718 725 out_alua_state = atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state); 719 726 nonop_delay_msecs = tg_pt_gp->tg_pt_gp_nonop_delay_msecs; 720 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 727 + 728 + // XXX: keeps using tg_pt_gp witout reference after unlock 729 + spin_unlock(&lun->lun_tg_pt_gp_lock); 721 730 /* 722 731 * Process ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED in a separate conditional 723 732 * statement so the compiler knows explicitly to check this case first. ··· 743 764 break; 744 765 /* 745 766 * OFFLINE is a secondary ALUA target port group access state, that is 746 - * handled above with struct se_port->sep_tg_pt_secondary_offline=1 767 + * handled above with struct se_lun->lun_tg_pt_secondary_offline=1 747 768 */ 748 769 case ALUA_ACCESS_STATE_OFFLINE: 749 770 default: ··· 885 906 } 886 907 EXPORT_SYMBOL(core_alua_check_nonop_delay); 887 908 888 - /* 889 - * Called with tg_pt_gp->tg_pt_gp_md_mutex or tg_pt_gp_mem->sep_tg_pt_md_mutex 890 - * 891 - */ 892 909 static int core_alua_write_tpg_metadata( 893 910 const char *path, 894 911 unsigned char *md_buf, ··· 940 965 return rc; 941 966 } 942 967 943 - static void core_alua_do_transition_tg_pt_work(struct work_struct *work) 968 + static void core_alua_queue_state_change_ua(struct t10_alua_tg_pt_gp *tg_pt_gp) 944 969 { 945 - struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(work, 946 - struct t10_alua_tg_pt_gp, tg_pt_gp_transition_work.work); 947 - struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; 948 970 struct se_dev_entry *se_deve; 971 + struct se_lun *lun; 949 972 struct se_lun_acl *lacl; 950 - struct se_port *port; 951 - struct t10_alua_tg_pt_gp_member *mem; 952 - bool explicit = (tg_pt_gp->tg_pt_gp_alua_access_status == 953 - ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG); 954 973 955 974 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 956 - list_for_each_entry(mem, &tg_pt_gp->tg_pt_gp_mem_list, 957 - tg_pt_gp_mem_list) { 958 - port = mem->tg_pt; 975 + list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list, 976 + lun_tg_pt_gp_link) { 959 977 /* 960 978 * After an implicit target port asymmetric access state 961 979 * change, a device server shall establish a unit attention ··· 963 995 * every I_T nexus other than the I_T nexus on which the SET 964 996 * TARGET PORT GROUPS command 965 997 */ 966 - atomic_inc_mb(&mem->tg_pt_gp_mem_ref_cnt); 998 + if (!percpu_ref_tryget_live(&lun->lun_ref)) 999 + continue; 967 1000 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 968 1001 969 - spin_lock_bh(&port->sep_alua_lock); 970 - list_for_each_entry(se_deve, &port->sep_alua_list, 971 - alua_port_list) { 972 - lacl = se_deve->se_lun_acl; 1002 + spin_lock(&lun->lun_deve_lock); 1003 + list_for_each_entry(se_deve, &lun->lun_deve_list, lun_link) { 1004 + lacl = rcu_dereference_check(se_deve->se_lun_acl, 1005 + lockdep_is_held(&lun->lun_deve_lock)); 1006 + 1007 + /* 1008 + * spc4r37 p.242: 1009 + * After an explicit target port asymmetric access 1010 + * state change, a device server shall establish a 1011 + * unit attention condition with the additional sense 1012 + * code set to ASYMMETRIC ACCESS STATE CHANGED for 1013 + * the initiator port associated with every I_T nexus 1014 + * other than the I_T nexus on which the SET TARGET 1015 + * PORT GROUPS command was received. 1016 + */ 1017 + if ((tg_pt_gp->tg_pt_gp_alua_access_status == 1018 + ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && 1019 + (tg_pt_gp->tg_pt_gp_alua_lun != NULL) && 1020 + (tg_pt_gp->tg_pt_gp_alua_lun == lun)) 1021 + continue; 1022 + 973 1023 /* 974 1024 * se_deve->se_lun_acl pointer may be NULL for a 975 1025 * entry created without explicit Node+MappedLUN ACLs 976 1026 */ 977 - if (!lacl) 1027 + if (lacl && (tg_pt_gp->tg_pt_gp_alua_nacl != NULL) && 1028 + (tg_pt_gp->tg_pt_gp_alua_nacl == lacl->se_lun_nacl)) 978 1029 continue; 979 1030 980 - if ((tg_pt_gp->tg_pt_gp_alua_access_status == 981 - ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && 982 - (tg_pt_gp->tg_pt_gp_alua_nacl != NULL) && 983 - (tg_pt_gp->tg_pt_gp_alua_nacl == lacl->se_lun_nacl) && 984 - (tg_pt_gp->tg_pt_gp_alua_port != NULL) && 985 - (tg_pt_gp->tg_pt_gp_alua_port == port)) 986 - continue; 987 - 988 - core_scsi3_ua_allocate(lacl->se_lun_nacl, 989 - se_deve->mapped_lun, 0x2A, 1031 + core_scsi3_ua_allocate(se_deve, 0x2A, 990 1032 ASCQ_2AH_ASYMMETRIC_ACCESS_STATE_CHANGED); 991 1033 } 992 - spin_unlock_bh(&port->sep_alua_lock); 1034 + spin_unlock(&lun->lun_deve_lock); 993 1035 994 1036 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 995 - atomic_dec_mb(&mem->tg_pt_gp_mem_ref_cnt); 1037 + percpu_ref_put(&lun->lun_ref); 996 1038 } 997 1039 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 1040 + } 1041 + 1042 + static void core_alua_do_transition_tg_pt_work(struct work_struct *work) 1043 + { 1044 + struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(work, 1045 + struct t10_alua_tg_pt_gp, tg_pt_gp_transition_work.work); 1046 + struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; 1047 + bool explicit = (tg_pt_gp->tg_pt_gp_alua_access_status == 1048 + ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG); 1049 + 998 1050 /* 999 1051 * Update the ALUA metadata buf that has been allocated in 1000 1052 * core_alua_do_port_transition(), this metadata will be written ··· 1044 1056 tg_pt_gp->tg_pt_gp_id, 1045 1057 core_alua_dump_state(tg_pt_gp->tg_pt_gp_alua_previous_state), 1046 1058 core_alua_dump_state(tg_pt_gp->tg_pt_gp_alua_pending_state)); 1059 + 1060 + core_alua_queue_state_change_ua(tg_pt_gp); 1061 + 1047 1062 spin_lock(&dev->t10_alua.tg_pt_gps_lock); 1048 1063 atomic_dec(&tg_pt_gp->tg_pt_gp_ref_cnt); 1049 1064 spin_unlock(&dev->t10_alua.tg_pt_gps_lock); ··· 1099 1108 ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG : 1100 1109 ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA; 1101 1110 1111 + core_alua_queue_state_change_ua(tg_pt_gp); 1112 + 1102 1113 /* 1103 1114 * Check for the optional ALUA primary state transition delay 1104 1115 */ ··· 1135 1142 int core_alua_do_port_transition( 1136 1143 struct t10_alua_tg_pt_gp *l_tg_pt_gp, 1137 1144 struct se_device *l_dev, 1138 - struct se_port *l_port, 1145 + struct se_lun *l_lun, 1139 1146 struct se_node_acl *l_nacl, 1140 1147 int new_state, 1141 1148 int explicit) ··· 1165 1172 * core_alua_do_transition_tg_pt() will always return 1166 1173 * success. 1167 1174 */ 1168 - l_tg_pt_gp->tg_pt_gp_alua_port = l_port; 1175 + l_tg_pt_gp->tg_pt_gp_alua_lun = l_lun; 1169 1176 l_tg_pt_gp->tg_pt_gp_alua_nacl = l_nacl; 1170 1177 rc = core_alua_do_transition_tg_pt(l_tg_pt_gp, 1171 1178 new_state, explicit); ··· 1204 1211 continue; 1205 1212 1206 1213 if (l_tg_pt_gp == tg_pt_gp) { 1207 - tg_pt_gp->tg_pt_gp_alua_port = l_port; 1214 + tg_pt_gp->tg_pt_gp_alua_lun = l_lun; 1208 1215 tg_pt_gp->tg_pt_gp_alua_nacl = l_nacl; 1209 1216 } else { 1210 - tg_pt_gp->tg_pt_gp_alua_port = NULL; 1217 + tg_pt_gp->tg_pt_gp_alua_lun = NULL; 1211 1218 tg_pt_gp->tg_pt_gp_alua_nacl = NULL; 1212 1219 } 1213 1220 atomic_inc_mb(&tg_pt_gp->tg_pt_gp_ref_cnt); ··· 1244 1251 return rc; 1245 1252 } 1246 1253 1247 - /* 1248 - * Called with tg_pt_gp_mem->sep_tg_pt_md_mutex held 1249 - */ 1250 - static int core_alua_update_tpg_secondary_metadata( 1251 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, 1252 - struct se_port *port) 1254 + static int core_alua_update_tpg_secondary_metadata(struct se_lun *lun) 1253 1255 { 1256 + struct se_portal_group *se_tpg = lun->lun_tpg; 1254 1257 unsigned char *md_buf; 1255 - struct se_portal_group *se_tpg = port->sep_tpg; 1256 1258 char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN]; 1257 1259 int len, rc; 1260 + 1261 + mutex_lock(&lun->lun_tg_pt_md_mutex); 1258 1262 1259 1263 md_buf = kzalloc(ALUA_MD_BUF_LEN, GFP_KERNEL); 1260 1264 if (!md_buf) { 1261 1265 pr_err("Unable to allocate buf for ALUA metadata\n"); 1262 - return -ENOMEM; 1266 + rc = -ENOMEM; 1267 + goto out_unlock; 1263 1268 } 1264 1269 1265 1270 memset(path, 0, ALUA_METADATA_PATH_LEN); ··· 1272 1281 1273 1282 len = snprintf(md_buf, ALUA_MD_BUF_LEN, "alua_tg_pt_offline=%d\n" 1274 1283 "alua_tg_pt_status=0x%02x\n", 1275 - atomic_read(&port->sep_tg_pt_secondary_offline), 1276 - port->sep_tg_pt_secondary_stat); 1284 + atomic_read(&lun->lun_tg_pt_secondary_offline), 1285 + lun->lun_tg_pt_secondary_stat); 1277 1286 1278 - snprintf(path, ALUA_METADATA_PATH_LEN, "/var/target/alua/%s/%s/lun_%u", 1287 + snprintf(path, ALUA_METADATA_PATH_LEN, "/var/target/alua/%s/%s/lun_%llu", 1279 1288 se_tpg->se_tpg_tfo->get_fabric_name(), wwn, 1280 - port->sep_lun->unpacked_lun); 1289 + lun->unpacked_lun); 1281 1290 1282 1291 rc = core_alua_write_tpg_metadata(path, md_buf, len); 1283 1292 kfree(md_buf); 1284 1293 1294 + out_unlock: 1295 + mutex_unlock(&lun->lun_tg_pt_md_mutex); 1285 1296 return rc; 1286 1297 } 1287 1298 1288 1299 static int core_alua_set_tg_pt_secondary_state( 1289 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, 1290 - struct se_port *port, 1300 + struct se_lun *lun, 1291 1301 int explicit, 1292 1302 int offline) 1293 1303 { 1294 1304 struct t10_alua_tg_pt_gp *tg_pt_gp; 1295 1305 int trans_delay_msecs; 1296 1306 1297 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1298 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 1307 + spin_lock(&lun->lun_tg_pt_gp_lock); 1308 + tg_pt_gp = lun->lun_tg_pt_gp; 1299 1309 if (!tg_pt_gp) { 1300 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1310 + spin_unlock(&lun->lun_tg_pt_gp_lock); 1301 1311 pr_err("Unable to complete secondary state" 1302 1312 " transition\n"); 1303 1313 return -EINVAL; ··· 1306 1314 trans_delay_msecs = tg_pt_gp->tg_pt_gp_trans_delay_msecs; 1307 1315 /* 1308 1316 * Set the secondary ALUA target port access state to OFFLINE 1309 - * or release the previously secondary state for struct se_port 1317 + * or release the previously secondary state for struct se_lun 1310 1318 */ 1311 1319 if (offline) 1312 - atomic_set(&port->sep_tg_pt_secondary_offline, 1); 1320 + atomic_set(&lun->lun_tg_pt_secondary_offline, 1); 1313 1321 else 1314 - atomic_set(&port->sep_tg_pt_secondary_offline, 0); 1322 + atomic_set(&lun->lun_tg_pt_secondary_offline, 0); 1315 1323 1316 - port->sep_tg_pt_secondary_stat = (explicit) ? 1324 + lun->lun_tg_pt_secondary_stat = (explicit) ? 1317 1325 ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG : 1318 1326 ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA; 1319 1327 ··· 1322 1330 "implicit", config_item_name(&tg_pt_gp->tg_pt_gp_group.cg_item), 1323 1331 tg_pt_gp->tg_pt_gp_id, (offline) ? "OFFLINE" : "ONLINE"); 1324 1332 1325 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1333 + spin_unlock(&lun->lun_tg_pt_gp_lock); 1326 1334 /* 1327 1335 * Do the optional transition delay after we set the secondary 1328 1336 * ALUA access state. ··· 1333 1341 * See if we need to update the ALUA fabric port metadata for 1334 1342 * secondary state and status 1335 1343 */ 1336 - if (port->sep_tg_pt_secondary_write_md) { 1337 - mutex_lock(&port->sep_tg_pt_md_mutex); 1338 - core_alua_update_tpg_secondary_metadata(tg_pt_gp_mem, port); 1339 - mutex_unlock(&port->sep_tg_pt_md_mutex); 1340 - } 1344 + if (lun->lun_tg_pt_secondary_write_md) 1345 + core_alua_update_tpg_secondary_metadata(lun); 1341 1346 1342 1347 return 0; 1343 1348 } ··· 1688 1699 return NULL; 1689 1700 } 1690 1701 INIT_LIST_HEAD(&tg_pt_gp->tg_pt_gp_list); 1691 - INIT_LIST_HEAD(&tg_pt_gp->tg_pt_gp_mem_list); 1702 + INIT_LIST_HEAD(&tg_pt_gp->tg_pt_gp_lun_list); 1692 1703 mutex_init(&tg_pt_gp->tg_pt_gp_md_mutex); 1693 1704 spin_lock_init(&tg_pt_gp->tg_pt_gp_lock); 1694 1705 atomic_set(&tg_pt_gp->tg_pt_gp_ref_cnt, 0); ··· 1782 1793 return 0; 1783 1794 } 1784 1795 1785 - struct t10_alua_tg_pt_gp_member *core_alua_allocate_tg_pt_gp_mem( 1786 - struct se_port *port) 1787 - { 1788 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 1789 - 1790 - tg_pt_gp_mem = kmem_cache_zalloc(t10_alua_tg_pt_gp_mem_cache, 1791 - GFP_KERNEL); 1792 - if (!tg_pt_gp_mem) { 1793 - pr_err("Unable to allocate struct t10_alua_tg_pt_gp_member\n"); 1794 - return ERR_PTR(-ENOMEM); 1795 - } 1796 - INIT_LIST_HEAD(&tg_pt_gp_mem->tg_pt_gp_mem_list); 1797 - spin_lock_init(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1798 - atomic_set(&tg_pt_gp_mem->tg_pt_gp_mem_ref_cnt, 0); 1799 - 1800 - tg_pt_gp_mem->tg_pt = port; 1801 - port->sep_alua_tg_pt_gp_mem = tg_pt_gp_mem; 1802 - 1803 - return tg_pt_gp_mem; 1804 - } 1805 - 1806 1796 void core_alua_free_tg_pt_gp( 1807 1797 struct t10_alua_tg_pt_gp *tg_pt_gp) 1808 1798 { 1809 1799 struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; 1810 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, *tg_pt_gp_mem_tmp; 1800 + struct se_lun *lun, *next; 1811 1801 1812 1802 /* 1813 1803 * Once we have reached this point, config_item_put() has already ··· 1817 1849 * struct se_port. 1818 1850 */ 1819 1851 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 1820 - list_for_each_entry_safe(tg_pt_gp_mem, tg_pt_gp_mem_tmp, 1821 - &tg_pt_gp->tg_pt_gp_mem_list, tg_pt_gp_mem_list) { 1822 - if (tg_pt_gp_mem->tg_pt_gp_assoc) { 1823 - list_del(&tg_pt_gp_mem->tg_pt_gp_mem_list); 1824 - tg_pt_gp->tg_pt_gp_members--; 1825 - tg_pt_gp_mem->tg_pt_gp_assoc = 0; 1826 - } 1852 + list_for_each_entry_safe(lun, next, 1853 + &tg_pt_gp->tg_pt_gp_lun_list, lun_tg_pt_gp_link) { 1854 + list_del_init(&lun->lun_tg_pt_gp_link); 1855 + tg_pt_gp->tg_pt_gp_members--; 1856 + 1827 1857 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 1828 1858 /* 1829 - * tg_pt_gp_mem is associated with a single 1830 - * se_port->sep_alua_tg_pt_gp_mem, and is released via 1831 - * core_alua_free_tg_pt_gp_mem(). 1832 - * 1833 1859 * If the passed tg_pt_gp does NOT match the default_tg_pt_gp, 1834 1860 * assume we want to re-associate a given tg_pt_gp_mem with 1835 1861 * default_tg_pt_gp. 1836 1862 */ 1837 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1863 + spin_lock(&lun->lun_tg_pt_gp_lock); 1838 1864 if (tg_pt_gp != dev->t10_alua.default_tg_pt_gp) { 1839 - __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, 1865 + __target_attach_tg_pt_gp(lun, 1840 1866 dev->t10_alua.default_tg_pt_gp); 1841 1867 } else 1842 - tg_pt_gp_mem->tg_pt_gp = NULL; 1843 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1868 + lun->lun_tg_pt_gp = NULL; 1869 + spin_unlock(&lun->lun_tg_pt_gp_lock); 1844 1870 1845 1871 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 1846 1872 } 1847 1873 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 1848 1874 1849 1875 kmem_cache_free(t10_alua_tg_pt_gp_cache, tg_pt_gp); 1850 - } 1851 - 1852 - void core_alua_free_tg_pt_gp_mem(struct se_port *port) 1853 - { 1854 - struct t10_alua_tg_pt_gp *tg_pt_gp; 1855 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 1856 - 1857 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 1858 - if (!tg_pt_gp_mem) 1859 - return; 1860 - 1861 - while (atomic_read(&tg_pt_gp_mem->tg_pt_gp_mem_ref_cnt)) 1862 - cpu_relax(); 1863 - 1864 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1865 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 1866 - if (tg_pt_gp) { 1867 - spin_lock(&tg_pt_gp->tg_pt_gp_lock); 1868 - if (tg_pt_gp_mem->tg_pt_gp_assoc) { 1869 - list_del(&tg_pt_gp_mem->tg_pt_gp_mem_list); 1870 - tg_pt_gp->tg_pt_gp_members--; 1871 - tg_pt_gp_mem->tg_pt_gp_assoc = 0; 1872 - } 1873 - spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 1874 - tg_pt_gp_mem->tg_pt_gp = NULL; 1875 - } 1876 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1877 - 1878 - kmem_cache_free(t10_alua_tg_pt_gp_mem_cache, tg_pt_gp_mem); 1879 1876 } 1880 1877 1881 1878 static struct t10_alua_tg_pt_gp *core_alua_get_tg_pt_gp_by_name( ··· 1876 1943 spin_unlock(&dev->t10_alua.tg_pt_gps_lock); 1877 1944 } 1878 1945 1879 - /* 1880 - * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held 1881 - */ 1882 - void __core_alua_attach_tg_pt_gp_mem( 1883 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, 1884 - struct t10_alua_tg_pt_gp *tg_pt_gp) 1946 + static void __target_attach_tg_pt_gp(struct se_lun *lun, 1947 + struct t10_alua_tg_pt_gp *tg_pt_gp) 1885 1948 { 1949 + struct se_dev_entry *se_deve; 1950 + 1951 + assert_spin_locked(&lun->lun_tg_pt_gp_lock); 1952 + 1886 1953 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 1887 - tg_pt_gp_mem->tg_pt_gp = tg_pt_gp; 1888 - tg_pt_gp_mem->tg_pt_gp_assoc = 1; 1889 - list_add_tail(&tg_pt_gp_mem->tg_pt_gp_mem_list, 1890 - &tg_pt_gp->tg_pt_gp_mem_list); 1954 + lun->lun_tg_pt_gp = tg_pt_gp; 1955 + list_add_tail(&lun->lun_tg_pt_gp_link, &tg_pt_gp->tg_pt_gp_lun_list); 1891 1956 tg_pt_gp->tg_pt_gp_members++; 1957 + spin_lock(&lun->lun_deve_lock); 1958 + list_for_each_entry(se_deve, &lun->lun_deve_list, lun_link) 1959 + core_scsi3_ua_allocate(se_deve, 0x3f, 1960 + ASCQ_3FH_INQUIRY_DATA_HAS_CHANGED); 1961 + spin_unlock(&lun->lun_deve_lock); 1892 1962 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 1893 1963 } 1894 1964 1895 - /* 1896 - * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held 1897 - */ 1898 - static void __core_alua_drop_tg_pt_gp_mem( 1899 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, 1900 - struct t10_alua_tg_pt_gp *tg_pt_gp) 1965 + void target_attach_tg_pt_gp(struct se_lun *lun, 1966 + struct t10_alua_tg_pt_gp *tg_pt_gp) 1901 1967 { 1968 + spin_lock(&lun->lun_tg_pt_gp_lock); 1969 + __target_attach_tg_pt_gp(lun, tg_pt_gp); 1970 + spin_unlock(&lun->lun_tg_pt_gp_lock); 1971 + } 1972 + 1973 + static void __target_detach_tg_pt_gp(struct se_lun *lun, 1974 + struct t10_alua_tg_pt_gp *tg_pt_gp) 1975 + { 1976 + assert_spin_locked(&lun->lun_tg_pt_gp_lock); 1977 + 1902 1978 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 1903 - list_del(&tg_pt_gp_mem->tg_pt_gp_mem_list); 1904 - tg_pt_gp_mem->tg_pt_gp = NULL; 1905 - tg_pt_gp_mem->tg_pt_gp_assoc = 0; 1979 + list_del_init(&lun->lun_tg_pt_gp_link); 1906 1980 tg_pt_gp->tg_pt_gp_members--; 1907 1981 spin_unlock(&tg_pt_gp->tg_pt_gp_lock); 1982 + 1983 + lun->lun_tg_pt_gp = NULL; 1908 1984 } 1909 1985 1910 - ssize_t core_alua_show_tg_pt_gp_info(struct se_port *port, char *page) 1986 + void target_detach_tg_pt_gp(struct se_lun *lun) 1987 + { 1988 + struct t10_alua_tg_pt_gp *tg_pt_gp; 1989 + 1990 + spin_lock(&lun->lun_tg_pt_gp_lock); 1991 + tg_pt_gp = lun->lun_tg_pt_gp; 1992 + if (tg_pt_gp) 1993 + __target_detach_tg_pt_gp(lun, tg_pt_gp); 1994 + spin_unlock(&lun->lun_tg_pt_gp_lock); 1995 + } 1996 + 1997 + ssize_t core_alua_show_tg_pt_gp_info(struct se_lun *lun, char *page) 1911 1998 { 1912 1999 struct config_item *tg_pt_ci; 1913 2000 struct t10_alua_tg_pt_gp *tg_pt_gp; 1914 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 1915 2001 ssize_t len = 0; 1916 2002 1917 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 1918 - if (!tg_pt_gp_mem) 1919 - return len; 1920 - 1921 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 1922 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 2003 + spin_lock(&lun->lun_tg_pt_gp_lock); 2004 + tg_pt_gp = lun->lun_tg_pt_gp; 1923 2005 if (tg_pt_gp) { 1924 2006 tg_pt_ci = &tg_pt_gp->tg_pt_gp_group.cg_item; 1925 2007 len += sprintf(page, "TG Port Alias: %s\nTG Port Group ID:" ··· 1946 1998 &tg_pt_gp->tg_pt_gp_alua_access_state)), 1947 1999 core_alua_dump_status( 1948 2000 tg_pt_gp->tg_pt_gp_alua_access_status), 1949 - (atomic_read(&port->sep_tg_pt_secondary_offline)) ? 2001 + atomic_read(&lun->lun_tg_pt_secondary_offline) ? 1950 2002 "Offline" : "None", 1951 - core_alua_dump_status(port->sep_tg_pt_secondary_stat)); 2003 + core_alua_dump_status(lun->lun_tg_pt_secondary_stat)); 1952 2004 } 1953 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 2005 + spin_unlock(&lun->lun_tg_pt_gp_lock); 1954 2006 1955 2007 return len; 1956 2008 } 1957 2009 1958 2010 ssize_t core_alua_store_tg_pt_gp_info( 1959 - struct se_port *port, 2011 + struct se_lun *lun, 1960 2012 const char *page, 1961 2013 size_t count) 1962 2014 { 1963 - struct se_portal_group *tpg; 1964 - struct se_lun *lun; 1965 - struct se_device *dev = port->sep_lun->lun_se_dev; 2015 + struct se_portal_group *tpg = lun->lun_tpg; 2016 + /* 2017 + * rcu_dereference_raw protected by se_lun->lun_group symlink 2018 + * reference to se_device->dev_group. 2019 + */ 2020 + struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); 1966 2021 struct t10_alua_tg_pt_gp *tg_pt_gp = NULL, *tg_pt_gp_new = NULL; 1967 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 1968 2022 unsigned char buf[TG_PT_GROUP_NAME_BUF]; 1969 2023 int move = 0; 1970 2024 1971 - tpg = port->sep_tpg; 1972 - lun = port->sep_lun; 1973 - 1974 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 1975 - if (!tg_pt_gp_mem) 1976 - return 0; 2025 + if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH || 2026 + (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) 2027 + return -ENODEV; 1977 2028 1978 2029 if (count > TG_PT_GROUP_NAME_BUF) { 1979 2030 pr_err("ALUA Target Port Group alias too large!\n"); ··· 1996 2049 return -ENODEV; 1997 2050 } 1998 2051 1999 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 2000 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 2052 + spin_lock(&lun->lun_tg_pt_gp_lock); 2053 + tg_pt_gp = lun->lun_tg_pt_gp; 2001 2054 if (tg_pt_gp) { 2002 2055 /* 2003 2056 * Clearing an existing tg_pt_gp association, and replacing ··· 2015 2068 &tg_pt_gp->tg_pt_gp_group.cg_item), 2016 2069 tg_pt_gp->tg_pt_gp_id); 2017 2070 2018 - __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem, tg_pt_gp); 2019 - __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, 2071 + __target_detach_tg_pt_gp(lun, tg_pt_gp); 2072 + __target_attach_tg_pt_gp(lun, 2020 2073 dev->t10_alua.default_tg_pt_gp); 2021 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 2074 + spin_unlock(&lun->lun_tg_pt_gp_lock); 2022 2075 2023 2076 return count; 2024 2077 } 2025 - /* 2026 - * Removing existing association of tg_pt_gp_mem with tg_pt_gp 2027 - */ 2028 - __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem, tg_pt_gp); 2078 + __target_detach_tg_pt_gp(lun, tg_pt_gp); 2029 2079 move = 1; 2030 2080 } 2031 - /* 2032 - * Associate tg_pt_gp_mem with tg_pt_gp_new. 2033 - */ 2034 - __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, tg_pt_gp_new); 2035 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 2081 + 2082 + __target_attach_tg_pt_gp(lun, tg_pt_gp_new); 2083 + spin_unlock(&lun->lun_tg_pt_gp_lock); 2036 2084 pr_debug("Target_Core_ConfigFS: %s %s/tpgt_%hu/%s to ALUA" 2037 2085 " Target Port Group: alua/%s, ID: %hu\n", (move) ? 2038 2086 "Moving" : "Adding", tpg->se_tpg_tfo->tpg_get_wwn(tpg), ··· 2210 2268 2211 2269 ssize_t core_alua_show_offline_bit(struct se_lun *lun, char *page) 2212 2270 { 2213 - if (!lun->lun_sep) 2214 - return -ENODEV; 2215 - 2216 2271 return sprintf(page, "%d\n", 2217 - atomic_read(&lun->lun_sep->sep_tg_pt_secondary_offline)); 2272 + atomic_read(&lun->lun_tg_pt_secondary_offline)); 2218 2273 } 2219 2274 2220 2275 ssize_t core_alua_store_offline_bit( ··· 2219 2280 const char *page, 2220 2281 size_t count) 2221 2282 { 2222 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 2283 + /* 2284 + * rcu_dereference_raw protected by se_lun->lun_group symlink 2285 + * reference to se_device->dev_group. 2286 + */ 2287 + struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); 2223 2288 unsigned long tmp; 2224 2289 int ret; 2225 2290 2226 - if (!lun->lun_sep) 2291 + if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH || 2292 + (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) 2227 2293 return -ENODEV; 2228 2294 2229 2295 ret = kstrtoul(page, 0, &tmp); ··· 2241 2297 tmp); 2242 2298 return -EINVAL; 2243 2299 } 2244 - tg_pt_gp_mem = lun->lun_sep->sep_alua_tg_pt_gp_mem; 2245 - if (!tg_pt_gp_mem) { 2246 - pr_err("Unable to locate *tg_pt_gp_mem\n"); 2247 - return -EINVAL; 2248 - } 2249 2300 2250 - ret = core_alua_set_tg_pt_secondary_state(tg_pt_gp_mem, 2251 - lun->lun_sep, 0, (int)tmp); 2301 + ret = core_alua_set_tg_pt_secondary_state(lun, 0, (int)tmp); 2252 2302 if (ret < 0) 2253 2303 return -EINVAL; 2254 2304 ··· 2253 2315 struct se_lun *lun, 2254 2316 char *page) 2255 2317 { 2256 - return sprintf(page, "%d\n", lun->lun_sep->sep_tg_pt_secondary_stat); 2318 + return sprintf(page, "%d\n", lun->lun_tg_pt_secondary_stat); 2257 2319 } 2258 2320 2259 2321 ssize_t core_alua_store_secondary_status( ··· 2276 2338 tmp); 2277 2339 return -EINVAL; 2278 2340 } 2279 - lun->lun_sep->sep_tg_pt_secondary_stat = (int)tmp; 2341 + lun->lun_tg_pt_secondary_stat = (int)tmp; 2280 2342 2281 2343 return count; 2282 2344 } ··· 2285 2347 struct se_lun *lun, 2286 2348 char *page) 2287 2349 { 2288 - return sprintf(page, "%d\n", 2289 - lun->lun_sep->sep_tg_pt_secondary_write_md); 2350 + return sprintf(page, "%d\n", lun->lun_tg_pt_secondary_write_md); 2290 2351 } 2291 2352 2292 2353 ssize_t core_alua_store_secondary_write_metadata( ··· 2306 2369 " %lu\n", tmp); 2307 2370 return -EINVAL; 2308 2371 } 2309 - lun->lun_sep->sep_tg_pt_secondary_write_md = (int)tmp; 2372 + lun->lun_tg_pt_secondary_write_md = (int)tmp; 2310 2373 2311 2374 return count; 2312 2375 }
+5 -9
drivers/target/target_core_alua.h
··· 85 85 extern struct kmem_cache *t10_alua_lu_gp_cache; 86 86 extern struct kmem_cache *t10_alua_lu_gp_mem_cache; 87 87 extern struct kmem_cache *t10_alua_tg_pt_gp_cache; 88 - extern struct kmem_cache *t10_alua_tg_pt_gp_mem_cache; 89 88 extern struct kmem_cache *t10_alua_lba_map_cache; 90 89 extern struct kmem_cache *t10_alua_lba_map_mem_cache; 91 90 ··· 93 94 extern sense_reason_t target_emulate_report_referrals(struct se_cmd *); 94 95 extern int core_alua_check_nonop_delay(struct se_cmd *); 95 96 extern int core_alua_do_port_transition(struct t10_alua_tg_pt_gp *, 96 - struct se_device *, struct se_port *, 97 + struct se_device *, struct se_lun *, 97 98 struct se_node_acl *, int, int); 98 99 extern char *core_alua_dump_status(int); 99 100 extern struct t10_alua_lba_map *core_alua_allocate_lba_map( ··· 116 117 extern struct t10_alua_tg_pt_gp *core_alua_allocate_tg_pt_gp( 117 118 struct se_device *, const char *, int); 118 119 extern int core_alua_set_tg_pt_gp_id(struct t10_alua_tg_pt_gp *, u16); 119 - extern struct t10_alua_tg_pt_gp_member *core_alua_allocate_tg_pt_gp_mem( 120 - struct se_port *); 121 120 extern void core_alua_free_tg_pt_gp(struct t10_alua_tg_pt_gp *); 122 - extern void core_alua_free_tg_pt_gp_mem(struct se_port *); 123 - extern void __core_alua_attach_tg_pt_gp_mem(struct t10_alua_tg_pt_gp_member *, 124 - struct t10_alua_tg_pt_gp *); 125 - extern ssize_t core_alua_show_tg_pt_gp_info(struct se_port *, char *); 126 - extern ssize_t core_alua_store_tg_pt_gp_info(struct se_port *, const char *, 121 + extern void target_detach_tg_pt_gp(struct se_lun *); 122 + extern void target_attach_tg_pt_gp(struct se_lun *, struct t10_alua_tg_pt_gp *); 123 + extern ssize_t core_alua_show_tg_pt_gp_info(struct se_lun *, char *); 124 + extern ssize_t core_alua_store_tg_pt_gp_info(struct se_lun *, const char *, 127 125 size_t); 128 126 extern ssize_t core_alua_show_access_type(struct t10_alua_tg_pt_gp *, char *); 129 127 extern ssize_t core_alua_store_access_type(struct t10_alua_tg_pt_gp *,
+648 -110
drivers/target/target_core_configfs.c
··· 41 41 #include <target/target_core_backend.h> 42 42 #include <target/target_core_fabric.h> 43 43 #include <target/target_core_fabric_configfs.h> 44 - #include <target/target_core_configfs.h> 45 44 #include <target/configfs_macros.h> 46 45 47 46 #include "target_core_internal.h" ··· 50 51 #include "target_core_xcopy.h" 51 52 52 53 #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ 53 - static void target_core_setup_##_name##_cit(struct se_subsystem_api *sa) \ 54 + static void target_core_setup_##_name##_cit(struct target_backend *tb) \ 54 55 { \ 55 - struct target_backend_cits *tbc = &sa->tb_cits; \ 56 - struct config_item_type *cit = &tbc->tb_##_name##_cit; \ 56 + struct config_item_type *cit = &tb->tb_##_name##_cit; \ 57 57 \ 58 58 cit->ct_item_ops = _item_ops; \ 59 59 cit->ct_group_ops = _group_ops; \ 60 60 cit->ct_attrs = _attrs; \ 61 - cit->ct_owner = sa->owner; \ 61 + cit->ct_owner = tb->ops->owner; \ 62 + pr_debug("Setup generic %s\n", __stringify(_name)); \ 63 + } 64 + 65 + #define TB_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ 66 + static void target_core_setup_##_name##_cit(struct target_backend *tb) \ 67 + { \ 68 + struct config_item_type *cit = &tb->tb_##_name##_cit; \ 69 + \ 70 + cit->ct_item_ops = _item_ops; \ 71 + cit->ct_group_ops = _group_ops; \ 72 + cit->ct_attrs = tb->ops->tb_##_name##_attrs; \ 73 + cit->ct_owner = tb->ops->owner; \ 62 74 pr_debug("Setup generic %s\n", __stringify(_name)); \ 63 75 } 64 76 ··· 102 92 char *page) 103 93 { 104 94 return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s" 105 - " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_CONFIGFS_VERSION, 95 + " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_VERSION, 106 96 utsname()->sysname, utsname()->machine); 107 97 } 108 98 ··· 126 116 127 117 mutex_lock(&g_tf_lock); 128 118 list_for_each_entry(tf, &g_tf_list, tf_list) { 129 - if (!strcmp(tf->tf_name, name)) { 119 + if (!strcmp(tf->tf_ops->name, name)) { 130 120 atomic_inc(&tf->tf_access_cnt); 131 121 mutex_unlock(&g_tf_lock); 132 122 return tf; ··· 203 193 return ERR_PTR(-EINVAL); 204 194 } 205 195 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:" 206 - " %s\n", tf->tf_name); 196 + " %s\n", tf->tf_ops->name); 207 197 /* 208 198 * On a successful target_core_get_fabric() look, the returned 209 199 * struct target_fabric_configfs *tf will contain a usage reference. 210 200 */ 211 201 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n", 212 - &tf->tf_cit_tmpl.tfc_wwn_cit); 202 + &tf->tf_wwn_cit); 213 203 214 204 tf->tf_group.default_groups = tf->tf_default_groups; 215 205 tf->tf_group.default_groups[0] = &tf->tf_disc_group; 216 206 tf->tf_group.default_groups[1] = NULL; 217 207 218 - config_group_init_type_name(&tf->tf_group, name, 219 - &tf->tf_cit_tmpl.tfc_wwn_cit); 208 + config_group_init_type_name(&tf->tf_group, name, &tf->tf_wwn_cit); 220 209 config_group_init_type_name(&tf->tf_disc_group, "discovery_auth", 221 - &tf->tf_cit_tmpl.tfc_discovery_cit); 210 + &tf->tf_discovery_cit); 222 211 223 212 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" 224 213 " %s\n", tf->tf_group.cg_item.ci_name); 225 - tf->tf_fabric = &tf->tf_group.cg_item; 226 - pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric" 227 - " for %s\n", name); 228 - 229 214 return &tf->tf_group; 230 215 } 231 216 ··· 241 236 " tf list\n", config_item_name(item)); 242 237 243 238 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:" 244 - " %s\n", tf->tf_name); 239 + " %s\n", tf->tf_ops->name); 245 240 atomic_dec(&tf->tf_access_cnt); 246 - 247 - pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing" 248 - " tf->tf_fabric for %s\n", tf->tf_name); 249 - tf->tf_fabric = NULL; 250 241 251 242 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci" 252 243 " %s\n", config_item_name(item)); ··· 319 318 pr_err("Missing tfo->get_fabric_name()\n"); 320 319 return -EINVAL; 321 320 } 322 - if (!tfo->get_fabric_proto_ident) { 323 - pr_err("Missing tfo->get_fabric_proto_ident()\n"); 324 - return -EINVAL; 325 - } 326 321 if (!tfo->tpg_get_wwn) { 327 322 pr_err("Missing tfo->tpg_get_wwn()\n"); 328 323 return -EINVAL; 329 324 } 330 325 if (!tfo->tpg_get_tag) { 331 326 pr_err("Missing tfo->tpg_get_tag()\n"); 332 - return -EINVAL; 333 - } 334 - if (!tfo->tpg_get_default_depth) { 335 - pr_err("Missing tfo->tpg_get_default_depth()\n"); 336 - return -EINVAL; 337 - } 338 - if (!tfo->tpg_get_pr_transport_id) { 339 - pr_err("Missing tfo->tpg_get_pr_transport_id()\n"); 340 - return -EINVAL; 341 - } 342 - if (!tfo->tpg_get_pr_transport_id_len) { 343 - pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n"); 344 327 return -EINVAL; 345 328 } 346 329 if (!tfo->tpg_check_demo_mode) { ··· 341 356 } 342 357 if (!tfo->tpg_check_prod_mode_write_protect) { 343 358 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n"); 344 - return -EINVAL; 345 - } 346 - if (!tfo->tpg_alloc_fabric_acl) { 347 - pr_err("Missing tfo->tpg_alloc_fabric_acl()\n"); 348 - return -EINVAL; 349 - } 350 - if (!tfo->tpg_release_fabric_acl) { 351 - pr_err("Missing tfo->tpg_release_fabric_acl()\n"); 352 359 return -EINVAL; 353 360 } 354 361 if (!tfo->tpg_get_inst_index) { ··· 373 396 } 374 397 if (!tfo->set_default_node_attributes) { 375 398 pr_err("Missing tfo->set_default_node_attributes()\n"); 376 - return -EINVAL; 377 - } 378 - if (!tfo->get_task_tag) { 379 - pr_err("Missing tfo->get_task_tag()\n"); 380 399 return -EINVAL; 381 400 } 382 401 if (!tfo->get_cmd_state) { ··· 437 464 438 465 INIT_LIST_HEAD(&tf->tf_list); 439 466 atomic_set(&tf->tf_access_cnt, 0); 440 - 441 - /* 442 - * Setup the default generic struct config_item_type's (cits) in 443 - * struct target_fabric_configfs->tf_cit_tmpl 444 - */ 445 - tf->tf_module = fo->module; 446 - snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", fo->name); 447 - 448 - tf->tf_ops = *fo; 467 + tf->tf_ops = fo; 449 468 target_fabric_setup_cits(tf); 450 469 451 470 mutex_lock(&g_tf_lock); ··· 454 489 455 490 mutex_lock(&g_tf_lock); 456 491 list_for_each_entry(t, &g_tf_list, tf_list) { 457 - if (!strcmp(t->tf_name, fo->name)) { 492 + if (!strcmp(t->tf_ops->name, fo->name)) { 458 493 BUG_ON(atomic_read(&t->tf_access_cnt)); 459 494 list_del(&t->tf_list); 460 495 kfree(t); ··· 470 505 //############################################################################*/ 471 506 472 507 /* Start functions for struct config_item_type tb_dev_attrib_cit */ 508 + #define DEF_TB_DEV_ATTRIB_SHOW(_name) \ 509 + static ssize_t show_##_name(struct se_dev_attrib *da, char *page) \ 510 + { \ 511 + return snprintf(page, PAGE_SIZE, "%u\n", da->_name); \ 512 + } 513 + 514 + DEF_TB_DEV_ATTRIB_SHOW(emulate_model_alias); 515 + DEF_TB_DEV_ATTRIB_SHOW(emulate_dpo); 516 + DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_write); 517 + DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_read); 518 + DEF_TB_DEV_ATTRIB_SHOW(emulate_write_cache); 519 + DEF_TB_DEV_ATTRIB_SHOW(emulate_ua_intlck_ctrl); 520 + DEF_TB_DEV_ATTRIB_SHOW(emulate_tas); 521 + DEF_TB_DEV_ATTRIB_SHOW(emulate_tpu); 522 + DEF_TB_DEV_ATTRIB_SHOW(emulate_tpws); 523 + DEF_TB_DEV_ATTRIB_SHOW(emulate_caw); 524 + DEF_TB_DEV_ATTRIB_SHOW(emulate_3pc); 525 + DEF_TB_DEV_ATTRIB_SHOW(pi_prot_type); 526 + DEF_TB_DEV_ATTRIB_SHOW(hw_pi_prot_type); 527 + DEF_TB_DEV_ATTRIB_SHOW(pi_prot_format); 528 + DEF_TB_DEV_ATTRIB_SHOW(enforce_pr_isids); 529 + DEF_TB_DEV_ATTRIB_SHOW(is_nonrot); 530 + DEF_TB_DEV_ATTRIB_SHOW(emulate_rest_reord); 531 + DEF_TB_DEV_ATTRIB_SHOW(force_pr_aptpl); 532 + DEF_TB_DEV_ATTRIB_SHOW(hw_block_size); 533 + DEF_TB_DEV_ATTRIB_SHOW(block_size); 534 + DEF_TB_DEV_ATTRIB_SHOW(hw_max_sectors); 535 + DEF_TB_DEV_ATTRIB_SHOW(optimal_sectors); 536 + DEF_TB_DEV_ATTRIB_SHOW(hw_queue_depth); 537 + DEF_TB_DEV_ATTRIB_SHOW(queue_depth); 538 + DEF_TB_DEV_ATTRIB_SHOW(max_unmap_lba_count); 539 + DEF_TB_DEV_ATTRIB_SHOW(max_unmap_block_desc_count); 540 + DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity); 541 + DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity_alignment); 542 + DEF_TB_DEV_ATTRIB_SHOW(max_write_same_len); 543 + 544 + #define DEF_TB_DEV_ATTRIB_STORE_U32(_name) \ 545 + static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ 546 + size_t count) \ 547 + { \ 548 + u32 val; \ 549 + int ret; \ 550 + \ 551 + ret = kstrtou32(page, 0, &val); \ 552 + if (ret < 0) \ 553 + return ret; \ 554 + da->_name = val; \ 555 + return count; \ 556 + } 557 + 558 + DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_lba_count); 559 + DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_block_desc_count); 560 + DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity); 561 + DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity_alignment); 562 + DEF_TB_DEV_ATTRIB_STORE_U32(max_write_same_len); 563 + 564 + #define DEF_TB_DEV_ATTRIB_STORE_BOOL(_name) \ 565 + static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ 566 + size_t count) \ 567 + { \ 568 + bool flag; \ 569 + int ret; \ 570 + \ 571 + ret = strtobool(page, &flag); \ 572 + if (ret < 0) \ 573 + return ret; \ 574 + da->_name = flag; \ 575 + return count; \ 576 + } 577 + 578 + DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_fua_write); 579 + DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_caw); 580 + DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_3pc); 581 + DEF_TB_DEV_ATTRIB_STORE_BOOL(enforce_pr_isids); 582 + DEF_TB_DEV_ATTRIB_STORE_BOOL(is_nonrot); 583 + 584 + #define DEF_TB_DEV_ATTRIB_STORE_STUB(_name) \ 585 + static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ 586 + size_t count) \ 587 + { \ 588 + printk_once(KERN_WARNING \ 589 + "ignoring deprecated ##_name## attribute\n"); \ 590 + return count; \ 591 + } 592 + 593 + DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_dpo); 594 + DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_fua_read); 595 + 596 + static void dev_set_t10_wwn_model_alias(struct se_device *dev) 597 + { 598 + const char *configname; 599 + 600 + configname = config_item_name(&dev->dev_group.cg_item); 601 + if (strlen(configname) >= 16) { 602 + pr_warn("dev[%p]: Backstore name '%s' is too long for " 603 + "INQUIRY_MODEL, truncating to 16 bytes\n", dev, 604 + configname); 605 + } 606 + snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); 607 + } 608 + 609 + static ssize_t store_emulate_model_alias(struct se_dev_attrib *da, 610 + const char *page, size_t count) 611 + { 612 + struct se_device *dev = da->da_dev; 613 + bool flag; 614 + int ret; 615 + 616 + if (dev->export_count) { 617 + pr_err("dev[%p]: Unable to change model alias" 618 + " while export_count is %d\n", 619 + dev, dev->export_count); 620 + return -EINVAL; 621 + } 622 + 623 + ret = strtobool(page, &flag); 624 + if (ret < 0) 625 + return ret; 626 + 627 + if (flag) { 628 + dev_set_t10_wwn_model_alias(dev); 629 + } else { 630 + strncpy(&dev->t10_wwn.model[0], 631 + dev->transport->inquiry_prod, 16); 632 + } 633 + da->emulate_model_alias = flag; 634 + return count; 635 + } 636 + 637 + static ssize_t store_emulate_write_cache(struct se_dev_attrib *da, 638 + const char *page, size_t count) 639 + { 640 + bool flag; 641 + int ret; 642 + 643 + ret = strtobool(page, &flag); 644 + if (ret < 0) 645 + return ret; 646 + 647 + if (flag && da->da_dev->transport->get_write_cache) { 648 + pr_err("emulate_write_cache not supported for this device\n"); 649 + return -EINVAL; 650 + } 651 + 652 + da->emulate_write_cache = flag; 653 + pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n", 654 + da->da_dev, flag); 655 + return count; 656 + } 657 + 658 + static ssize_t store_emulate_ua_intlck_ctrl(struct se_dev_attrib *da, 659 + const char *page, size_t count) 660 + { 661 + u32 val; 662 + int ret; 663 + 664 + ret = kstrtou32(page, 0, &val); 665 + if (ret < 0) 666 + return ret; 667 + 668 + if (val != 0 && val != 1 && val != 2) { 669 + pr_err("Illegal value %d\n", val); 670 + return -EINVAL; 671 + } 672 + 673 + if (da->da_dev->export_count) { 674 + pr_err("dev[%p]: Unable to change SE Device" 675 + " UA_INTRLCK_CTRL while export_count is %d\n", 676 + da->da_dev, da->da_dev->export_count); 677 + return -EINVAL; 678 + } 679 + da->emulate_ua_intlck_ctrl = val; 680 + pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n", 681 + da->da_dev, val); 682 + return count; 683 + } 684 + 685 + static ssize_t store_emulate_tas(struct se_dev_attrib *da, 686 + const char *page, size_t count) 687 + { 688 + bool flag; 689 + int ret; 690 + 691 + ret = strtobool(page, &flag); 692 + if (ret < 0) 693 + return ret; 694 + 695 + if (da->da_dev->export_count) { 696 + pr_err("dev[%p]: Unable to change SE Device TAS while" 697 + " export_count is %d\n", 698 + da->da_dev, da->da_dev->export_count); 699 + return -EINVAL; 700 + } 701 + da->emulate_tas = flag; 702 + pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n", 703 + da->da_dev, flag ? "Enabled" : "Disabled"); 704 + 705 + return count; 706 + } 707 + 708 + static ssize_t store_emulate_tpu(struct se_dev_attrib *da, 709 + const char *page, size_t count) 710 + { 711 + bool flag; 712 + int ret; 713 + 714 + ret = strtobool(page, &flag); 715 + if (ret < 0) 716 + return ret; 717 + 718 + /* 719 + * We expect this value to be non-zero when generic Block Layer 720 + * Discard supported is detected iblock_create_virtdevice(). 721 + */ 722 + if (flag && !da->max_unmap_block_desc_count) { 723 + pr_err("Generic Block Discard not supported\n"); 724 + return -ENOSYS; 725 + } 726 + 727 + da->emulate_tpu = flag; 728 + pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n", 729 + da->da_dev, flag); 730 + return count; 731 + } 732 + 733 + static ssize_t store_emulate_tpws(struct se_dev_attrib *da, 734 + const char *page, size_t count) 735 + { 736 + bool flag; 737 + int ret; 738 + 739 + ret = strtobool(page, &flag); 740 + if (ret < 0) 741 + return ret; 742 + 743 + /* 744 + * We expect this value to be non-zero when generic Block Layer 745 + * Discard supported is detected iblock_create_virtdevice(). 746 + */ 747 + if (flag && !da->max_unmap_block_desc_count) { 748 + pr_err("Generic Block Discard not supported\n"); 749 + return -ENOSYS; 750 + } 751 + 752 + da->emulate_tpws = flag; 753 + pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n", 754 + da->da_dev, flag); 755 + return count; 756 + } 757 + 758 + static ssize_t store_pi_prot_type(struct se_dev_attrib *da, 759 + const char *page, size_t count) 760 + { 761 + int old_prot = da->pi_prot_type, ret; 762 + struct se_device *dev = da->da_dev; 763 + u32 flag; 764 + 765 + ret = kstrtou32(page, 0, &flag); 766 + if (ret < 0) 767 + return ret; 768 + 769 + if (flag != 0 && flag != 1 && flag != 2 && flag != 3) { 770 + pr_err("Illegal value %d for pi_prot_type\n", flag); 771 + return -EINVAL; 772 + } 773 + if (flag == 2) { 774 + pr_err("DIF TYPE2 protection currently not supported\n"); 775 + return -ENOSYS; 776 + } 777 + if (da->hw_pi_prot_type) { 778 + pr_warn("DIF protection enabled on underlying hardware," 779 + " ignoring\n"); 780 + return count; 781 + } 782 + if (!dev->transport->init_prot || !dev->transport->free_prot) { 783 + /* 0 is only allowed value for non-supporting backends */ 784 + if (flag == 0) 785 + return 0; 786 + 787 + pr_err("DIF protection not supported by backend: %s\n", 788 + dev->transport->name); 789 + return -ENOSYS; 790 + } 791 + if (!(dev->dev_flags & DF_CONFIGURED)) { 792 + pr_err("DIF protection requires device to be configured\n"); 793 + return -ENODEV; 794 + } 795 + if (dev->export_count) { 796 + pr_err("dev[%p]: Unable to change SE Device PROT type while" 797 + " export_count is %d\n", dev, dev->export_count); 798 + return -EINVAL; 799 + } 800 + 801 + da->pi_prot_type = flag; 802 + 803 + if (flag && !old_prot) { 804 + ret = dev->transport->init_prot(dev); 805 + if (ret) { 806 + da->pi_prot_type = old_prot; 807 + return ret; 808 + } 809 + 810 + } else if (!flag && old_prot) { 811 + dev->transport->free_prot(dev); 812 + } 813 + 814 + pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev, flag); 815 + return count; 816 + } 817 + 818 + static ssize_t store_pi_prot_format(struct se_dev_attrib *da, 819 + const char *page, size_t count) 820 + { 821 + struct se_device *dev = da->da_dev; 822 + bool flag; 823 + int ret; 824 + 825 + ret = strtobool(page, &flag); 826 + if (ret < 0) 827 + return ret; 828 + 829 + if (!flag) 830 + return count; 831 + 832 + if (!dev->transport->format_prot) { 833 + pr_err("DIF protection format not supported by backend %s\n", 834 + dev->transport->name); 835 + return -ENOSYS; 836 + } 837 + if (!(dev->dev_flags & DF_CONFIGURED)) { 838 + pr_err("DIF protection format requires device to be configured\n"); 839 + return -ENODEV; 840 + } 841 + if (dev->export_count) { 842 + pr_err("dev[%p]: Unable to format SE Device PROT type while" 843 + " export_count is %d\n", dev, dev->export_count); 844 + return -EINVAL; 845 + } 846 + 847 + ret = dev->transport->format_prot(dev); 848 + if (ret) 849 + return ret; 850 + 851 + pr_debug("dev[%p]: SE Device Protection Format complete\n", dev); 852 + return count; 853 + } 854 + 855 + static ssize_t store_force_pr_aptpl(struct se_dev_attrib *da, 856 + const char *page, size_t count) 857 + { 858 + bool flag; 859 + int ret; 860 + 861 + ret = strtobool(page, &flag); 862 + if (ret < 0) 863 + return ret; 864 + if (da->da_dev->export_count) { 865 + pr_err("dev[%p]: Unable to set force_pr_aptpl while" 866 + " export_count is %d\n", 867 + da->da_dev, da->da_dev->export_count); 868 + return -EINVAL; 869 + } 870 + 871 + da->force_pr_aptpl = flag; 872 + pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da->da_dev, flag); 873 + return count; 874 + } 875 + 876 + static ssize_t store_emulate_rest_reord(struct se_dev_attrib *da, 877 + const char *page, size_t count) 878 + { 879 + bool flag; 880 + int ret; 881 + 882 + ret = strtobool(page, &flag); 883 + if (ret < 0) 884 + return ret; 885 + 886 + if (flag != 0) { 887 + printk(KERN_ERR "dev[%p]: SE Device emulation of restricted" 888 + " reordering not implemented\n", da->da_dev); 889 + return -ENOSYS; 890 + } 891 + da->emulate_rest_reord = flag; 892 + pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", 893 + da->da_dev, flag); 894 + return count; 895 + } 896 + 897 + /* 898 + * Note, this can only be called on unexported SE Device Object. 899 + */ 900 + static ssize_t store_queue_depth(struct se_dev_attrib *da, 901 + const char *page, size_t count) 902 + { 903 + struct se_device *dev = da->da_dev; 904 + u32 val; 905 + int ret; 906 + 907 + ret = kstrtou32(page, 0, &val); 908 + if (ret < 0) 909 + return ret; 910 + 911 + if (dev->export_count) { 912 + pr_err("dev[%p]: Unable to change SE Device TCQ while" 913 + " export_count is %d\n", 914 + dev, dev->export_count); 915 + return -EINVAL; 916 + } 917 + if (!val) { 918 + pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev); 919 + return -EINVAL; 920 + } 921 + 922 + if (val > dev->dev_attrib.queue_depth) { 923 + if (val > dev->dev_attrib.hw_queue_depth) { 924 + pr_err("dev[%p]: Passed queue_depth:" 925 + " %u exceeds TCM/SE_Device MAX" 926 + " TCQ: %u\n", dev, val, 927 + dev->dev_attrib.hw_queue_depth); 928 + return -EINVAL; 929 + } 930 + } 931 + da->queue_depth = dev->queue_depth = val; 932 + pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev, val); 933 + return count; 934 + } 935 + 936 + static ssize_t store_optimal_sectors(struct se_dev_attrib *da, 937 + const char *page, size_t count) 938 + { 939 + u32 val; 940 + int ret; 941 + 942 + ret = kstrtou32(page, 0, &val); 943 + if (ret < 0) 944 + return ret; 945 + 946 + if (da->da_dev->export_count) { 947 + pr_err("dev[%p]: Unable to change SE Device" 948 + " optimal_sectors while export_count is %d\n", 949 + da->da_dev, da->da_dev->export_count); 950 + return -EINVAL; 951 + } 952 + if (val > da->hw_max_sectors) { 953 + pr_err("dev[%p]: Passed optimal_sectors %u cannot be" 954 + " greater than hw_max_sectors: %u\n", 955 + da->da_dev, val, da->hw_max_sectors); 956 + return -EINVAL; 957 + } 958 + 959 + da->optimal_sectors = val; 960 + pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n", 961 + da->da_dev, val); 962 + return count; 963 + } 964 + 965 + static ssize_t store_block_size(struct se_dev_attrib *da, 966 + const char *page, size_t count) 967 + { 968 + u32 val; 969 + int ret; 970 + 971 + ret = kstrtou32(page, 0, &val); 972 + if (ret < 0) 973 + return ret; 974 + 975 + if (da->da_dev->export_count) { 976 + pr_err("dev[%p]: Unable to change SE Device block_size" 977 + " while export_count is %d\n", 978 + da->da_dev, da->da_dev->export_count); 979 + return -EINVAL; 980 + } 981 + 982 + if (val != 512 && val != 1024 && val != 2048 && val != 4096) { 983 + pr_err("dev[%p]: Illegal value for block_device: %u" 984 + " for SE device, must be 512, 1024, 2048 or 4096\n", 985 + da->da_dev, val); 986 + return -EINVAL; 987 + } 988 + 989 + da->block_size = val; 990 + if (da->max_bytes_per_io) 991 + da->hw_max_sectors = da->max_bytes_per_io / val; 992 + 993 + pr_debug("dev[%p]: SE Device block_size changed to %u\n", 994 + da->da_dev, val); 995 + return count; 996 + } 997 + 998 + CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib, se_dev_attrib); 999 + #define TB_DEV_ATTR(_backend, _name, _mode) \ 1000 + static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 1001 + __CONFIGFS_EATTR(_name, _mode, \ 1002 + show_##_name, \ 1003 + store_##_name); 1004 + 1005 + #define TB_DEV_ATTR_RO(_backend, _name) \ 1006 + static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 1007 + __CONFIGFS_EATTR_RO(_name, \ 1008 + show_##_name); 1009 + 1010 + TB_DEV_ATTR(target_core, emulate_model_alias, S_IRUGO | S_IWUSR); 1011 + TB_DEV_ATTR(target_core, emulate_dpo, S_IRUGO | S_IWUSR); 1012 + TB_DEV_ATTR(target_core, emulate_fua_write, S_IRUGO | S_IWUSR); 1013 + TB_DEV_ATTR(target_core, emulate_fua_read, S_IRUGO | S_IWUSR); 1014 + TB_DEV_ATTR(target_core, emulate_write_cache, S_IRUGO | S_IWUSR); 1015 + TB_DEV_ATTR(target_core, emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); 1016 + TB_DEV_ATTR(target_core, emulate_tas, S_IRUGO | S_IWUSR); 1017 + TB_DEV_ATTR(target_core, emulate_tpu, S_IRUGO | S_IWUSR); 1018 + TB_DEV_ATTR(target_core, emulate_tpws, S_IRUGO | S_IWUSR); 1019 + TB_DEV_ATTR(target_core, emulate_caw, S_IRUGO | S_IWUSR); 1020 + TB_DEV_ATTR(target_core, emulate_3pc, S_IRUGO | S_IWUSR); 1021 + TB_DEV_ATTR(target_core, pi_prot_type, S_IRUGO | S_IWUSR); 1022 + TB_DEV_ATTR_RO(target_core, hw_pi_prot_type); 1023 + TB_DEV_ATTR(target_core, pi_prot_format, S_IRUGO | S_IWUSR); 1024 + TB_DEV_ATTR(target_core, enforce_pr_isids, S_IRUGO | S_IWUSR); 1025 + TB_DEV_ATTR(target_core, is_nonrot, S_IRUGO | S_IWUSR); 1026 + TB_DEV_ATTR(target_core, emulate_rest_reord, S_IRUGO | S_IWUSR); 1027 + TB_DEV_ATTR(target_core, force_pr_aptpl, S_IRUGO | S_IWUSR) 1028 + TB_DEV_ATTR_RO(target_core, hw_block_size); 1029 + TB_DEV_ATTR(target_core, block_size, S_IRUGO | S_IWUSR) 1030 + TB_DEV_ATTR_RO(target_core, hw_max_sectors); 1031 + TB_DEV_ATTR(target_core, optimal_sectors, S_IRUGO | S_IWUSR); 1032 + TB_DEV_ATTR_RO(target_core, hw_queue_depth); 1033 + TB_DEV_ATTR(target_core, queue_depth, S_IRUGO | S_IWUSR); 1034 + TB_DEV_ATTR(target_core, max_unmap_lba_count, S_IRUGO | S_IWUSR); 1035 + TB_DEV_ATTR(target_core, max_unmap_block_desc_count, S_IRUGO | S_IWUSR); 1036 + TB_DEV_ATTR(target_core, unmap_granularity, S_IRUGO | S_IWUSR); 1037 + TB_DEV_ATTR(target_core, unmap_granularity_alignment, S_IRUGO | S_IWUSR); 1038 + TB_DEV_ATTR(target_core, max_write_same_len, S_IRUGO | S_IWUSR); 473 1039 474 1040 CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib); 475 1041 CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group); 1042 + 1043 + /* 1044 + * dev_attrib attributes for devices using the target core SBC/SPC 1045 + * interpreter. Any backend using spc_parse_cdb should be using 1046 + * these. 1047 + */ 1048 + struct configfs_attribute *sbc_attrib_attrs[] = { 1049 + &target_core_dev_attrib_emulate_model_alias.attr, 1050 + &target_core_dev_attrib_emulate_dpo.attr, 1051 + &target_core_dev_attrib_emulate_fua_write.attr, 1052 + &target_core_dev_attrib_emulate_fua_read.attr, 1053 + &target_core_dev_attrib_emulate_write_cache.attr, 1054 + &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr, 1055 + &target_core_dev_attrib_emulate_tas.attr, 1056 + &target_core_dev_attrib_emulate_tpu.attr, 1057 + &target_core_dev_attrib_emulate_tpws.attr, 1058 + &target_core_dev_attrib_emulate_caw.attr, 1059 + &target_core_dev_attrib_emulate_3pc.attr, 1060 + &target_core_dev_attrib_pi_prot_type.attr, 1061 + &target_core_dev_attrib_hw_pi_prot_type.attr, 1062 + &target_core_dev_attrib_pi_prot_format.attr, 1063 + &target_core_dev_attrib_enforce_pr_isids.attr, 1064 + &target_core_dev_attrib_is_nonrot.attr, 1065 + &target_core_dev_attrib_emulate_rest_reord.attr, 1066 + &target_core_dev_attrib_force_pr_aptpl.attr, 1067 + &target_core_dev_attrib_hw_block_size.attr, 1068 + &target_core_dev_attrib_block_size.attr, 1069 + &target_core_dev_attrib_hw_max_sectors.attr, 1070 + &target_core_dev_attrib_optimal_sectors.attr, 1071 + &target_core_dev_attrib_hw_queue_depth.attr, 1072 + &target_core_dev_attrib_queue_depth.attr, 1073 + &target_core_dev_attrib_max_unmap_lba_count.attr, 1074 + &target_core_dev_attrib_max_unmap_block_desc_count.attr, 1075 + &target_core_dev_attrib_unmap_granularity.attr, 1076 + &target_core_dev_attrib_unmap_granularity_alignment.attr, 1077 + &target_core_dev_attrib_max_write_same_len.attr, 1078 + NULL, 1079 + }; 1080 + EXPORT_SYMBOL(sbc_attrib_attrs); 1081 + 1082 + TB_DEV_ATTR_RO(target_pt, hw_pi_prot_type); 1083 + TB_DEV_ATTR_RO(target_pt, hw_block_size); 1084 + TB_DEV_ATTR_RO(target_pt, hw_max_sectors); 1085 + TB_DEV_ATTR_RO(target_pt, hw_queue_depth); 1086 + 1087 + /* 1088 + * Minimal dev_attrib attributes for devices passing through CDBs. 1089 + * In this case we only provide a few read-only attributes for 1090 + * backwards compatibility. 1091 + */ 1092 + struct configfs_attribute *passthrough_attrib_attrs[] = { 1093 + &target_pt_dev_attrib_hw_pi_prot_type.attr, 1094 + &target_pt_dev_attrib_hw_block_size.attr, 1095 + &target_pt_dev_attrib_hw_max_sectors.attr, 1096 + &target_pt_dev_attrib_hw_queue_depth.attr, 1097 + NULL, 1098 + }; 1099 + EXPORT_SYMBOL(passthrough_attrib_attrs); 476 1100 477 1101 static struct configfs_item_operations target_core_dev_attrib_ops = { 478 1102 .show_attribute = target_core_dev_attrib_attr_show, 479 1103 .store_attribute = target_core_dev_attrib_attr_store, 480 1104 }; 481 1105 482 - TB_CIT_SETUP(dev_attrib, &target_core_dev_attrib_ops, NULL, NULL); 1106 + TB_CIT_SETUP_DRV(dev_attrib, &target_core_dev_attrib_ops, NULL); 483 1107 484 1108 /* End functions for struct config_item_type tb_dev_attrib_cit */ 485 1109 ··· 1416 862 struct se_device *dev, char *page) 1417 863 { 1418 864 struct se_node_acl *se_nacl; 1419 - struct se_lun *lun; 1420 865 struct se_portal_group *se_tpg; 1421 866 struct t10_pr_registration *pr_reg; 1422 867 const struct target_core_fabric_ops *tfo; ··· 1430 877 1431 878 se_nacl = pr_reg->pr_reg_nacl; 1432 879 se_tpg = se_nacl->se_tpg; 1433 - lun = pr_reg->pr_reg_tg_pt_lun; 1434 880 tfo = se_tpg->se_tpg_tfo; 1435 881 1436 882 len += sprintf(page+len, "SPC-3 Reservation: %s" ··· 1437 885 tfo->tpg_get_wwn(se_tpg)); 1438 886 len += sprintf(page+len, "SPC-3 Reservation: Relative Port" 1439 887 " Identifier Tag: %hu %s Portal Group Tag: %hu" 1440 - " %s Logical Unit: %u\n", lun->lun_sep->sep_rtpi, 888 + " %s Logical Unit: %llu\n", pr_reg->tg_pt_sep_rtpi, 1441 889 tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), 1442 - tfo->get_fabric_name(), lun->unpacked_lun); 890 + tfo->get_fabric_name(), pr_reg->pr_aptpl_target_lun); 1443 891 1444 892 out_unlock: 1445 893 spin_unlock(&dev->dev_reservation_lock); ··· 1564 1012 {Opt_res_type, "res_type=%d"}, 1565 1013 {Opt_res_scope, "res_scope=%d"}, 1566 1014 {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, 1567 - {Opt_mapped_lun, "mapped_lun=%d"}, 1015 + {Opt_mapped_lun, "mapped_lun=%lld"}, 1568 1016 {Opt_target_fabric, "target_fabric=%s"}, 1569 1017 {Opt_target_node, "target_node=%s"}, 1570 1018 {Opt_tpgt, "tpgt=%d"}, 1571 1019 {Opt_port_rtpi, "port_rtpi=%d"}, 1572 - {Opt_target_lun, "target_lun=%d"}, 1020 + {Opt_target_lun, "target_lun=%lld"}, 1573 1021 {Opt_err, NULL} 1574 1022 }; 1575 1023 ··· 1584 1032 substring_t args[MAX_OPT_ARGS]; 1585 1033 unsigned long long tmp_ll; 1586 1034 u64 sa_res_key = 0; 1587 - u32 mapped_lun = 0, target_lun = 0; 1035 + u64 mapped_lun = 0, target_lun = 0; 1588 1036 int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token; 1589 - u16 port_rpti = 0, tpgt = 0; 1590 - u8 type = 0, scope; 1037 + u16 tpgt = 0; 1038 + u8 type = 0; 1591 1039 1592 1040 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) 1593 1041 return 0; ··· 1667 1115 break; 1668 1116 case Opt_res_scope: 1669 1117 match_int(args, &arg); 1670 - scope = (u8)arg; 1671 1118 break; 1672 1119 case Opt_res_all_tg_pt: 1673 1120 match_int(args, &arg); ··· 1674 1123 break; 1675 1124 case Opt_mapped_lun: 1676 1125 match_int(args, &arg); 1677 - mapped_lun = (u32)arg; 1126 + mapped_lun = (u64)arg; 1678 1127 break; 1679 1128 /* 1680 1129 * PR APTPL Metadata for Target Port ··· 1706 1155 break; 1707 1156 case Opt_port_rtpi: 1708 1157 match_int(args, &arg); 1709 - port_rpti = (u16)arg; 1710 1158 break; 1711 1159 case Opt_target_lun: 1712 1160 match_int(args, &arg); 1713 - target_lun = (u32)arg; 1161 + target_lun = (u64)arg; 1714 1162 break; 1715 1163 default: 1716 1164 break; ··· 1773 1223 static ssize_t target_core_show_dev_info(void *p, char *page) 1774 1224 { 1775 1225 struct se_device *dev = p; 1776 - struct se_subsystem_api *t = dev->transport; 1777 1226 int bl = 0; 1778 1227 ssize_t read_bytes = 0; 1779 1228 1780 1229 transport_dump_dev_state(dev, page, &bl); 1781 1230 read_bytes += bl; 1782 - read_bytes += t->show_configfs_dev_params(dev, page+read_bytes); 1231 + read_bytes += dev->transport->show_configfs_dev_params(dev, 1232 + page+read_bytes); 1783 1233 return read_bytes; 1784 1234 } 1785 1235 ··· 1797 1247 size_t count) 1798 1248 { 1799 1249 struct se_device *dev = p; 1800 - struct se_subsystem_api *t = dev->transport; 1801 1250 1802 - return t->set_configfs_dev_params(dev, page, count); 1251 + return dev->transport->set_configfs_dev_params(dev, page, count); 1803 1252 } 1804 1253 1805 1254 static struct target_core_configfs_attribute target_core_attr_dev_control = { ··· 2888 2339 struct t10_alua_tg_pt_gp *tg_pt_gp, 2889 2340 char *page) 2890 2341 { 2891 - struct se_port *port; 2892 - struct se_portal_group *tpg; 2893 2342 struct se_lun *lun; 2894 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 2895 2343 ssize_t len = 0, cur_len; 2896 2344 unsigned char buf[TG_PT_GROUP_NAME_BUF]; 2897 2345 2898 2346 memset(buf, 0, TG_PT_GROUP_NAME_BUF); 2899 2347 2900 2348 spin_lock(&tg_pt_gp->tg_pt_gp_lock); 2901 - list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list, 2902 - tg_pt_gp_mem_list) { 2903 - port = tg_pt_gp_mem->tg_pt; 2904 - tpg = port->sep_tpg; 2905 - lun = port->sep_lun; 2349 + list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list, 2350 + lun_tg_pt_gp_link) { 2351 + struct se_portal_group *tpg = lun->lun_tpg; 2906 2352 2907 2353 cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu" 2908 2354 "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), ··· 3070 2526 const char *name) 3071 2527 { 3072 2528 struct t10_alua_tg_pt_gp *tg_pt_gp; 3073 - struct se_subsystem_api *t; 3074 2529 struct config_item *hba_ci = &group->cg_item; 3075 2530 struct se_hba *hba = item_to_hba(hba_ci); 2531 + struct target_backend *tb = hba->backend; 3076 2532 struct se_device *dev; 3077 2533 struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL; 3078 2534 struct config_group *dev_stat_grp = NULL; ··· 3081 2537 ret = mutex_lock_interruptible(&hba->hba_access_mutex); 3082 2538 if (ret) 3083 2539 return ERR_PTR(ret); 3084 - /* 3085 - * Locate the struct se_subsystem_api from parent's struct se_hba. 3086 - */ 3087 - t = hba->transport; 3088 2540 3089 2541 dev = target_alloc_device(hba, name); 3090 2542 if (!dev) ··· 3093 2553 if (!dev_cg->default_groups) 3094 2554 goto out_free_device; 3095 2555 3096 - config_group_init_type_name(dev_cg, name, &t->tb_cits.tb_dev_cit); 2556 + config_group_init_type_name(dev_cg, name, &tb->tb_dev_cit); 3097 2557 config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", 3098 - &t->tb_cits.tb_dev_attrib_cit); 2558 + &tb->tb_dev_attrib_cit); 3099 2559 config_group_init_type_name(&dev->dev_pr_group, "pr", 3100 - &t->tb_cits.tb_dev_pr_cit); 2560 + &tb->tb_dev_pr_cit); 3101 2561 config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", 3102 - &t->tb_cits.tb_dev_wwn_cit); 2562 + &tb->tb_dev_wwn_cit); 3103 2563 config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, 3104 - "alua", &t->tb_cits.tb_dev_alua_tg_pt_gps_cit); 2564 + "alua", &tb->tb_dev_alua_tg_pt_gps_cit); 3105 2565 config_group_init_type_name(&dev->dev_stat_grps.stat_group, 3106 - "statistics", &t->tb_cits.tb_dev_stat_cit); 2566 + "statistics", &tb->tb_dev_stat_cit); 3107 2567 3108 2568 dev_cg->default_groups[0] = &dev->dev_attrib.da_group; 3109 2569 dev_cg->default_groups[1] = &dev->dev_pr_group; ··· 3233 2693 char *page) 3234 2694 { 3235 2695 return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", 3236 - hba->hba_id, hba->transport->name, 3237 - TARGET_CORE_CONFIGFS_VERSION); 2696 + hba->hba_id, hba->backend->ops->name, 2697 + TARGET_CORE_VERSION); 3238 2698 } 3239 2699 3240 2700 SE_HBA_ATTR_RO(hba_info); ··· 3253 2713 static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba, 3254 2714 const char *page, size_t count) 3255 2715 { 3256 - struct se_subsystem_api *transport = hba->transport; 3257 2716 unsigned long mode_flag; 3258 2717 int ret; 3259 2718 3260 - if (transport->pmode_enable_hba == NULL) 2719 + if (hba->backend->ops->pmode_enable_hba == NULL) 3261 2720 return -EINVAL; 3262 2721 3263 2722 ret = kstrtoul(page, 0, &mode_flag); ··· 3270 2731 return -EINVAL; 3271 2732 } 3272 2733 3273 - ret = transport->pmode_enable_hba(hba, mode_flag); 2734 + ret = hba->backend->ops->pmode_enable_hba(hba, mode_flag); 3274 2735 if (ret < 0) 3275 2736 return -EINVAL; 3276 2737 if (ret > 0) ··· 3396 2857 3397 2858 /* Stop functions for struct config_item_type target_core_hba_cit */ 3398 2859 3399 - void target_core_setup_sub_cits(struct se_subsystem_api *sa) 2860 + void target_setup_backend_cits(struct target_backend *tb) 3400 2861 { 3401 - target_core_setup_dev_cit(sa); 3402 - target_core_setup_dev_attrib_cit(sa); 3403 - target_core_setup_dev_pr_cit(sa); 3404 - target_core_setup_dev_wwn_cit(sa); 3405 - target_core_setup_dev_alua_tg_pt_gps_cit(sa); 3406 - target_core_setup_dev_stat_cit(sa); 2862 + target_core_setup_dev_cit(tb); 2863 + target_core_setup_dev_attrib_cit(tb); 2864 + target_core_setup_dev_pr_cit(tb); 2865 + target_core_setup_dev_wwn_cit(tb); 2866 + target_core_setup_dev_alua_tg_pt_gps_cit(tb); 2867 + target_core_setup_dev_stat_cit(tb); 3407 2868 } 3408 - EXPORT_SYMBOL(target_core_setup_sub_cits); 3409 2869 3410 2870 static int __init target_core_init_configfs(void) 3411 2871 { ··· 3506 2968 goto out_global; 3507 2969 } 3508 2970 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" 3509 - " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s" 2971 + " Infrastructure: "TARGET_CORE_VERSION" on %s/%s" 3510 2972 " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); 3511 2973 /* 3512 2974 * Register built-in RAMDISK subsystem logic for virtual LUN 0
+292 -1017
drivers/target/target_core_device.c
··· 56 56 struct se_device *g_lun0_dev; 57 57 58 58 sense_reason_t 59 - transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun) 59 + transport_lookup_cmd_lun(struct se_cmd *se_cmd, u64 unpacked_lun) 60 60 { 61 61 struct se_lun *se_lun = NULL; 62 62 struct se_session *se_sess = se_cmd->se_sess; 63 - struct se_device *dev; 64 - unsigned long flags; 63 + struct se_node_acl *nacl = se_sess->se_node_acl; 64 + struct se_dev_entry *deve; 65 65 66 - if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) 67 - return TCM_NON_EXISTENT_LUN; 68 - 69 - spin_lock_irqsave(&se_sess->se_node_acl->device_list_lock, flags); 70 - se_cmd->se_deve = se_sess->se_node_acl->device_list[unpacked_lun]; 71 - if (se_cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { 72 - struct se_dev_entry *deve = se_cmd->se_deve; 73 - 74 - deve->total_cmds++; 66 + rcu_read_lock(); 67 + deve = target_nacl_find_deve(nacl, unpacked_lun); 68 + if (deve) { 69 + atomic_long_inc(&deve->total_cmds); 75 70 76 71 if ((se_cmd->data_direction == DMA_TO_DEVICE) && 77 72 (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) { 78 73 pr_err("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN" 79 - " Access for 0x%08x\n", 74 + " Access for 0x%08llx\n", 80 75 se_cmd->se_tfo->get_fabric_name(), 81 76 unpacked_lun); 82 - spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags); 77 + rcu_read_unlock(); 83 78 return TCM_WRITE_PROTECTED; 84 79 } 85 80 86 81 if (se_cmd->data_direction == DMA_TO_DEVICE) 87 - deve->write_bytes += se_cmd->data_length; 82 + atomic_long_add(se_cmd->data_length, 83 + &deve->write_bytes); 88 84 else if (se_cmd->data_direction == DMA_FROM_DEVICE) 89 - deve->read_bytes += se_cmd->data_length; 85 + atomic_long_add(se_cmd->data_length, 86 + &deve->read_bytes); 90 87 91 - se_lun = deve->se_lun; 92 - se_cmd->se_lun = deve->se_lun; 88 + se_lun = rcu_dereference(deve->se_lun); 89 + se_cmd->se_lun = rcu_dereference(deve->se_lun); 93 90 se_cmd->pr_res_key = deve->pr_res_key; 94 91 se_cmd->orig_fe_lun = unpacked_lun; 95 92 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; ··· 94 97 percpu_ref_get(&se_lun->lun_ref); 95 98 se_cmd->lun_ref_active = true; 96 99 } 97 - spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags); 100 + rcu_read_unlock(); 98 101 99 102 if (!se_lun) { 100 103 /* ··· 104 107 */ 105 108 if (unpacked_lun != 0) { 106 109 pr_err("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN" 107 - " Access for 0x%08x\n", 110 + " Access for 0x%08llx\n", 108 111 se_cmd->se_tfo->get_fabric_name(), 109 112 unpacked_lun); 110 113 return TCM_NON_EXISTENT_LUN; ··· 116 119 (se_cmd->data_direction != DMA_NONE)) 117 120 return TCM_WRITE_PROTECTED; 118 121 119 - se_lun = &se_sess->se_tpg->tpg_virt_lun0; 120 - se_cmd->se_lun = &se_sess->se_tpg->tpg_virt_lun0; 122 + se_lun = se_sess->se_tpg->tpg_virt_lun0; 123 + se_cmd->se_lun = se_sess->se_tpg->tpg_virt_lun0; 121 124 se_cmd->orig_fe_lun = 0; 122 125 se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; 123 126 124 127 percpu_ref_get(&se_lun->lun_ref); 125 128 se_cmd->lun_ref_active = true; 126 129 } 130 + /* 131 + * RCU reference protected by percpu se_lun->lun_ref taken above that 132 + * must drop to zero (including initial reference) before this se_lun 133 + * pointer can be kfree_rcu() by the final se_lun->lun_group put via 134 + * target_core_fabric_configfs.c:target_fabric_port_release 135 + */ 136 + se_cmd->se_dev = rcu_dereference_raw(se_lun->lun_se_dev); 137 + atomic_long_inc(&se_cmd->se_dev->num_cmds); 127 138 128 - /* Directly associate cmd with se_dev */ 129 - se_cmd->se_dev = se_lun->lun_se_dev; 130 - 131 - dev = se_lun->lun_se_dev; 132 - atomic_long_inc(&dev->num_cmds); 133 139 if (se_cmd->data_direction == DMA_TO_DEVICE) 134 - atomic_long_add(se_cmd->data_length, &dev->write_bytes); 140 + atomic_long_add(se_cmd->data_length, 141 + &se_cmd->se_dev->write_bytes); 135 142 else if (se_cmd->data_direction == DMA_FROM_DEVICE) 136 - atomic_long_add(se_cmd->data_length, &dev->read_bytes); 143 + atomic_long_add(se_cmd->data_length, 144 + &se_cmd->se_dev->read_bytes); 137 145 138 146 return 0; 139 147 } 140 148 EXPORT_SYMBOL(transport_lookup_cmd_lun); 141 149 142 - int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u32 unpacked_lun) 150 + int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u64 unpacked_lun) 143 151 { 144 152 struct se_dev_entry *deve; 145 153 struct se_lun *se_lun = NULL; 146 154 struct se_session *se_sess = se_cmd->se_sess; 155 + struct se_node_acl *nacl = se_sess->se_node_acl; 147 156 struct se_tmr_req *se_tmr = se_cmd->se_tmr_req; 148 157 unsigned long flags; 149 158 150 - if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) 151 - return -ENODEV; 152 - 153 - spin_lock_irqsave(&se_sess->se_node_acl->device_list_lock, flags); 154 - se_cmd->se_deve = se_sess->se_node_acl->device_list[unpacked_lun]; 155 - deve = se_cmd->se_deve; 156 - 157 - if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { 158 - se_tmr->tmr_lun = deve->se_lun; 159 - se_cmd->se_lun = deve->se_lun; 160 - se_lun = deve->se_lun; 159 + rcu_read_lock(); 160 + deve = target_nacl_find_deve(nacl, unpacked_lun); 161 + if (deve) { 162 + se_tmr->tmr_lun = rcu_dereference(deve->se_lun); 163 + se_cmd->se_lun = rcu_dereference(deve->se_lun); 164 + se_lun = rcu_dereference(deve->se_lun); 161 165 se_cmd->pr_res_key = deve->pr_res_key; 162 166 se_cmd->orig_fe_lun = unpacked_lun; 163 167 } 164 - spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags); 168 + rcu_read_unlock(); 165 169 166 170 if (!se_lun) { 167 171 pr_debug("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN" 168 - " Access for 0x%08x\n", 172 + " Access for 0x%08llx\n", 169 173 se_cmd->se_tfo->get_fabric_name(), 170 174 unpacked_lun); 171 175 return -ENODEV; 172 176 } 173 - 174 - /* Directly associate cmd with se_dev */ 175 - se_cmd->se_dev = se_lun->lun_se_dev; 176 - se_tmr->tmr_dev = se_lun->lun_se_dev; 177 + /* 178 + * XXX: Add percpu se_lun->lun_ref reference count for TMR 179 + */ 180 + se_cmd->se_dev = rcu_dereference_raw(se_lun->lun_se_dev); 181 + se_tmr->tmr_dev = rcu_dereference_raw(se_lun->lun_se_dev); 177 182 178 183 spin_lock_irqsave(&se_tmr->tmr_dev->se_tmr_lock, flags); 179 184 list_add_tail(&se_tmr->tmr_list, &se_tmr->tmr_dev->dev_tmr_list); ··· 185 186 } 186 187 EXPORT_SYMBOL(transport_lookup_tmr_lun); 187 188 189 + bool target_lun_is_rdonly(struct se_cmd *cmd) 190 + { 191 + struct se_session *se_sess = cmd->se_sess; 192 + struct se_dev_entry *deve; 193 + bool ret; 194 + 195 + rcu_read_lock(); 196 + deve = target_nacl_find_deve(se_sess->se_node_acl, cmd->orig_fe_lun); 197 + ret = (deve && deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY); 198 + rcu_read_unlock(); 199 + 200 + return ret; 201 + } 202 + EXPORT_SYMBOL(target_lun_is_rdonly); 203 + 188 204 /* 189 205 * This function is called from core_scsi3_emulate_pro_register_and_move() 190 - * and core_scsi3_decode_spec_i_port(), and will increment &deve->pr_ref_count 206 + * and core_scsi3_decode_spec_i_port(), and will increment &deve->pr_kref 191 207 * when a matching rtpi is found. 192 208 */ 193 209 struct se_dev_entry *core_get_se_deve_from_rtpi( ··· 211 197 { 212 198 struct se_dev_entry *deve; 213 199 struct se_lun *lun; 214 - struct se_port *port; 215 200 struct se_portal_group *tpg = nacl->se_tpg; 216 - u32 i; 217 201 218 - spin_lock_irq(&nacl->device_list_lock); 219 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 220 - deve = nacl->device_list[i]; 221 - 222 - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) 223 - continue; 224 - 225 - lun = deve->se_lun; 202 + rcu_read_lock(); 203 + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 204 + lun = rcu_dereference(deve->se_lun); 226 205 if (!lun) { 227 206 pr_err("%s device entries device pointer is" 228 207 " NULL, but Initiator has access.\n", 229 208 tpg->se_tpg_tfo->get_fabric_name()); 230 209 continue; 231 210 } 232 - port = lun->lun_sep; 233 - if (!port) { 234 - pr_err("%s device entries device pointer is" 235 - " NULL, but Initiator has access.\n", 236 - tpg->se_tpg_tfo->get_fabric_name()); 237 - continue; 238 - } 239 - if (port->sep_rtpi != rtpi) 211 + if (lun->lun_rtpi != rtpi) 240 212 continue; 241 213 242 - atomic_inc_mb(&deve->pr_ref_count); 243 - spin_unlock_irq(&nacl->device_list_lock); 214 + kref_get(&deve->pr_kref); 215 + rcu_read_unlock(); 244 216 245 217 return deve; 246 218 } 247 - spin_unlock_irq(&nacl->device_list_lock); 219 + rcu_read_unlock(); 248 220 249 221 return NULL; 250 222 } 251 223 252 - int core_free_device_list_for_node( 224 + void core_free_device_list_for_node( 253 225 struct se_node_acl *nacl, 254 226 struct se_portal_group *tpg) 255 227 { 256 228 struct se_dev_entry *deve; 257 - struct se_lun *lun; 258 - u32 i; 259 229 260 - if (!nacl->device_list) 261 - return 0; 262 - 263 - spin_lock_irq(&nacl->device_list_lock); 264 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 265 - deve = nacl->device_list[i]; 266 - 267 - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) 268 - continue; 269 - 270 - if (!deve->se_lun) { 271 - pr_err("%s device entries device pointer is" 272 - " NULL, but Initiator has access.\n", 273 - tpg->se_tpg_tfo->get_fabric_name()); 274 - continue; 275 - } 276 - lun = deve->se_lun; 277 - 278 - spin_unlock_irq(&nacl->device_list_lock); 279 - core_disable_device_list_for_node(lun, NULL, deve->mapped_lun, 280 - TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); 281 - spin_lock_irq(&nacl->device_list_lock); 230 + mutex_lock(&nacl->lun_entry_mutex); 231 + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 232 + struct se_lun *lun = rcu_dereference_check(deve->se_lun, 233 + lockdep_is_held(&nacl->lun_entry_mutex)); 234 + core_disable_device_list_for_node(lun, deve, nacl, tpg); 282 235 } 283 - spin_unlock_irq(&nacl->device_list_lock); 284 - 285 - array_free(nacl->device_list, TRANSPORT_MAX_LUNS_PER_TPG); 286 - nacl->device_list = NULL; 287 - 288 - return 0; 236 + mutex_unlock(&nacl->lun_entry_mutex); 289 237 } 290 238 291 239 void core_update_device_list_access( 292 - u32 mapped_lun, 240 + u64 mapped_lun, 293 241 u32 lun_access, 294 242 struct se_node_acl *nacl) 295 243 { 296 244 struct se_dev_entry *deve; 297 245 298 - spin_lock_irq(&nacl->device_list_lock); 299 - deve = nacl->device_list[mapped_lun]; 300 - if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { 301 - deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; 302 - deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; 303 - } else { 304 - deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; 305 - deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; 306 - } 307 - spin_unlock_irq(&nacl->device_list_lock); 308 - } 309 - 310 - /* core_enable_device_list_for_node(): 311 - * 312 - * 313 - */ 314 - int core_enable_device_list_for_node( 315 - struct se_lun *lun, 316 - struct se_lun_acl *lun_acl, 317 - u32 mapped_lun, 318 - u32 lun_access, 319 - struct se_node_acl *nacl, 320 - struct se_portal_group *tpg) 321 - { 322 - struct se_port *port = lun->lun_sep; 323 - struct se_dev_entry *deve; 324 - 325 - spin_lock_irq(&nacl->device_list_lock); 326 - 327 - deve = nacl->device_list[mapped_lun]; 328 - 329 - /* 330 - * Check if the call is handling demo mode -> explicit LUN ACL 331 - * transition. This transition must be for the same struct se_lun 332 - * + mapped_lun that was setup in demo mode.. 333 - */ 334 - if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { 335 - if (deve->se_lun_acl != NULL) { 336 - pr_err("struct se_dev_entry->se_lun_acl" 337 - " already set for demo mode -> explicit" 338 - " LUN ACL transition\n"); 339 - spin_unlock_irq(&nacl->device_list_lock); 340 - return -EINVAL; 341 - } 342 - if (deve->se_lun != lun) { 343 - pr_err("struct se_dev_entry->se_lun does" 344 - " match passed struct se_lun for demo mode" 345 - " -> explicit LUN ACL transition\n"); 346 - spin_unlock_irq(&nacl->device_list_lock); 347 - return -EINVAL; 348 - } 349 - deve->se_lun_acl = lun_acl; 350 - 246 + mutex_lock(&nacl->lun_entry_mutex); 247 + deve = target_nacl_find_deve(nacl, mapped_lun); 248 + if (deve) { 351 249 if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { 352 250 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; 353 251 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; ··· 267 341 deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; 268 342 deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; 269 343 } 270 - 271 - spin_unlock_irq(&nacl->device_list_lock); 272 - return 0; 273 344 } 274 - 275 - deve->se_lun = lun; 276 - deve->se_lun_acl = lun_acl; 277 - deve->mapped_lun = mapped_lun; 278 - deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS; 279 - 280 - if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { 281 - deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; 282 - deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; 283 - } else { 284 - deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; 285 - deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; 286 - } 287 - 288 - deve->creation_time = get_jiffies_64(); 289 - deve->attach_count++; 290 - spin_unlock_irq(&nacl->device_list_lock); 291 - 292 - spin_lock_bh(&port->sep_alua_lock); 293 - list_add_tail(&deve->alua_port_list, &port->sep_alua_list); 294 - spin_unlock_bh(&port->sep_alua_lock); 295 - 296 - return 0; 345 + mutex_unlock(&nacl->lun_entry_mutex); 297 346 } 298 347 299 - /* core_disable_device_list_for_node(): 300 - * 301 - * 348 + /* 349 + * Called with rcu_read_lock or nacl->device_list_lock held. 302 350 */ 303 - int core_disable_device_list_for_node( 351 + struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *nacl, u64 mapped_lun) 352 + { 353 + struct se_dev_entry *deve; 354 + 355 + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) 356 + if (deve->mapped_lun == mapped_lun) 357 + return deve; 358 + 359 + return NULL; 360 + } 361 + EXPORT_SYMBOL(target_nacl_find_deve); 362 + 363 + void target_pr_kref_release(struct kref *kref) 364 + { 365 + struct se_dev_entry *deve = container_of(kref, struct se_dev_entry, 366 + pr_kref); 367 + complete(&deve->pr_comp); 368 + } 369 + 370 + static void 371 + target_luns_data_has_changed(struct se_node_acl *nacl, struct se_dev_entry *new, 372 + bool skip_new) 373 + { 374 + struct se_dev_entry *tmp; 375 + 376 + rcu_read_lock(); 377 + hlist_for_each_entry_rcu(tmp, &nacl->lun_entry_hlist, link) { 378 + if (skip_new && tmp == new) 379 + continue; 380 + core_scsi3_ua_allocate(tmp, 0x3F, 381 + ASCQ_3FH_REPORTED_LUNS_DATA_HAS_CHANGED); 382 + } 383 + rcu_read_unlock(); 384 + } 385 + 386 + int core_enable_device_list_for_node( 304 387 struct se_lun *lun, 305 388 struct se_lun_acl *lun_acl, 306 - u32 mapped_lun, 389 + u64 mapped_lun, 307 390 u32 lun_access, 308 391 struct se_node_acl *nacl, 309 392 struct se_portal_group *tpg) 310 393 { 311 - struct se_port *port = lun->lun_sep; 312 - struct se_dev_entry *deve = nacl->device_list[mapped_lun]; 394 + struct se_dev_entry *orig, *new; 313 395 396 + new = kzalloc(sizeof(*new), GFP_KERNEL); 397 + if (!new) { 398 + pr_err("Unable to allocate se_dev_entry memory\n"); 399 + return -ENOMEM; 400 + } 401 + 402 + atomic_set(&new->ua_count, 0); 403 + spin_lock_init(&new->ua_lock); 404 + INIT_LIST_HEAD(&new->ua_list); 405 + INIT_LIST_HEAD(&new->lun_link); 406 + 407 + new->mapped_lun = mapped_lun; 408 + kref_init(&new->pr_kref); 409 + init_completion(&new->pr_comp); 410 + 411 + if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) 412 + new->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; 413 + else 414 + new->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; 415 + 416 + new->creation_time = get_jiffies_64(); 417 + new->attach_count++; 418 + 419 + mutex_lock(&nacl->lun_entry_mutex); 420 + orig = target_nacl_find_deve(nacl, mapped_lun); 421 + if (orig && orig->se_lun) { 422 + struct se_lun *orig_lun = rcu_dereference_check(orig->se_lun, 423 + lockdep_is_held(&nacl->lun_entry_mutex)); 424 + 425 + if (orig_lun != lun) { 426 + pr_err("Existing orig->se_lun doesn't match new lun" 427 + " for dynamic -> explicit NodeACL conversion:" 428 + " %s\n", nacl->initiatorname); 429 + mutex_unlock(&nacl->lun_entry_mutex); 430 + kfree(new); 431 + return -EINVAL; 432 + } 433 + BUG_ON(orig->se_lun_acl != NULL); 434 + 435 + rcu_assign_pointer(new->se_lun, lun); 436 + rcu_assign_pointer(new->se_lun_acl, lun_acl); 437 + hlist_del_rcu(&orig->link); 438 + hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist); 439 + mutex_unlock(&nacl->lun_entry_mutex); 440 + 441 + spin_lock(&lun->lun_deve_lock); 442 + list_del(&orig->lun_link); 443 + list_add_tail(&new->lun_link, &lun->lun_deve_list); 444 + spin_unlock(&lun->lun_deve_lock); 445 + 446 + kref_put(&orig->pr_kref, target_pr_kref_release); 447 + wait_for_completion(&orig->pr_comp); 448 + 449 + target_luns_data_has_changed(nacl, new, true); 450 + kfree_rcu(orig, rcu_head); 451 + return 0; 452 + } 453 + 454 + rcu_assign_pointer(new->se_lun, lun); 455 + rcu_assign_pointer(new->se_lun_acl, lun_acl); 456 + hlist_add_head_rcu(&new->link, &nacl->lun_entry_hlist); 457 + mutex_unlock(&nacl->lun_entry_mutex); 458 + 459 + spin_lock(&lun->lun_deve_lock); 460 + list_add_tail(&new->lun_link, &lun->lun_deve_list); 461 + spin_unlock(&lun->lun_deve_lock); 462 + 463 + target_luns_data_has_changed(nacl, new, true); 464 + return 0; 465 + } 466 + 467 + /* 468 + * Called with se_node_acl->lun_entry_mutex held. 469 + */ 470 + void core_disable_device_list_for_node( 471 + struct se_lun *lun, 472 + struct se_dev_entry *orig, 473 + struct se_node_acl *nacl, 474 + struct se_portal_group *tpg) 475 + { 476 + /* 477 + * rcu_dereference_raw protected by se_lun->lun_group symlink 478 + * reference to se_device->dev_group. 479 + */ 480 + struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); 314 481 /* 315 482 * If the MappedLUN entry is being disabled, the entry in 316 - * port->sep_alua_list must be removed now before clearing the 483 + * lun->lun_deve_list must be removed now before clearing the 317 484 * struct se_dev_entry pointers below as logic in 318 485 * core_alua_do_transition_tg_pt() depends on these being present. 319 486 * 320 487 * deve->se_lun_acl will be NULL for demo-mode created LUNs 321 488 * that have not been explicitly converted to MappedLUNs -> 322 - * struct se_lun_acl, but we remove deve->alua_port_list from 323 - * port->sep_alua_list. This also means that active UAs and 489 + * struct se_lun_acl, but we remove deve->lun_link from 490 + * lun->lun_deve_list. This also means that active UAs and 324 491 * NodeACL context specific PR metadata for demo-mode 325 492 * MappedLUN *deve will be released below.. 326 493 */ 327 - spin_lock_bh(&port->sep_alua_lock); 328 - list_del(&deve->alua_port_list); 329 - spin_unlock_bh(&port->sep_alua_lock); 330 - /* 331 - * Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE 332 - * PR operation to complete. 333 - */ 334 - while (atomic_read(&deve->pr_ref_count) != 0) 335 - cpu_relax(); 336 - 337 - spin_lock_irq(&nacl->device_list_lock); 494 + spin_lock(&lun->lun_deve_lock); 495 + list_del(&orig->lun_link); 496 + spin_unlock(&lun->lun_deve_lock); 338 497 /* 339 498 * Disable struct se_dev_entry LUN ACL mapping 340 499 */ 341 - core_scsi3_ua_release_all(deve); 342 - deve->se_lun = NULL; 343 - deve->se_lun_acl = NULL; 344 - deve->lun_flags = 0; 345 - deve->creation_time = 0; 346 - deve->attach_count--; 347 - spin_unlock_irq(&nacl->device_list_lock); 500 + core_scsi3_ua_release_all(orig); 348 501 349 - core_scsi3_free_pr_reg_from_nacl(lun->lun_se_dev, nacl); 350 - return 0; 502 + hlist_del_rcu(&orig->link); 503 + clear_bit(DEF_PR_REG_ACTIVE, &orig->deve_flags); 504 + rcu_assign_pointer(orig->se_lun, NULL); 505 + rcu_assign_pointer(orig->se_lun_acl, NULL); 506 + orig->lun_flags = 0; 507 + orig->creation_time = 0; 508 + orig->attach_count--; 509 + /* 510 + * Before firing off RCU callback, wait for any in process SPEC_I_PT=1 511 + * or REGISTER_AND_MOVE PR operation to complete. 512 + */ 513 + kref_put(&orig->pr_kref, target_pr_kref_release); 514 + wait_for_completion(&orig->pr_comp); 515 + 516 + kfree_rcu(orig, rcu_head); 517 + 518 + core_scsi3_free_pr_reg_from_nacl(dev, nacl); 519 + target_luns_data_has_changed(nacl, NULL, false); 351 520 } 352 521 353 522 /* core_clear_lun_from_tpg(): ··· 453 432 { 454 433 struct se_node_acl *nacl; 455 434 struct se_dev_entry *deve; 456 - u32 i; 457 435 458 - spin_lock_irq(&tpg->acl_node_lock); 436 + mutex_lock(&tpg->acl_node_mutex); 459 437 list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) { 460 - spin_unlock_irq(&tpg->acl_node_lock); 461 438 462 - spin_lock_irq(&nacl->device_list_lock); 463 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 464 - deve = nacl->device_list[i]; 465 - if (lun != deve->se_lun) 439 + mutex_lock(&nacl->lun_entry_mutex); 440 + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 441 + struct se_lun *tmp_lun = rcu_dereference_check(deve->se_lun, 442 + lockdep_is_held(&nacl->lun_entry_mutex)); 443 + 444 + if (lun != tmp_lun) 466 445 continue; 467 - spin_unlock_irq(&nacl->device_list_lock); 468 446 469 - core_disable_device_list_for_node(lun, NULL, 470 - deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS, 471 - nacl, tpg); 472 - 473 - spin_lock_irq(&nacl->device_list_lock); 447 + core_disable_device_list_for_node(lun, deve, nacl, tpg); 474 448 } 475 - spin_unlock_irq(&nacl->device_list_lock); 476 - 477 - spin_lock_irq(&tpg->acl_node_lock); 449 + mutex_unlock(&nacl->lun_entry_mutex); 478 450 } 479 - spin_unlock_irq(&tpg->acl_node_lock); 451 + mutex_unlock(&tpg->acl_node_mutex); 480 452 } 481 453 482 - static struct se_port *core_alloc_port(struct se_device *dev) 454 + int core_alloc_rtpi(struct se_lun *lun, struct se_device *dev) 483 455 { 484 - struct se_port *port, *port_tmp; 485 - 486 - port = kzalloc(sizeof(struct se_port), GFP_KERNEL); 487 - if (!port) { 488 - pr_err("Unable to allocate struct se_port\n"); 489 - return ERR_PTR(-ENOMEM); 490 - } 491 - INIT_LIST_HEAD(&port->sep_alua_list); 492 - INIT_LIST_HEAD(&port->sep_list); 493 - atomic_set(&port->sep_tg_pt_secondary_offline, 0); 494 - spin_lock_init(&port->sep_alua_lock); 495 - mutex_init(&port->sep_tg_pt_md_mutex); 456 + struct se_lun *tmp; 496 457 497 458 spin_lock(&dev->se_port_lock); 498 - if (dev->dev_port_count == 0x0000ffff) { 459 + if (dev->export_count == 0x0000ffff) { 499 460 pr_warn("Reached dev->dev_port_count ==" 500 461 " 0x0000ffff\n"); 501 462 spin_unlock(&dev->se_port_lock); 502 - return ERR_PTR(-ENOSPC); 463 + return -ENOSPC; 503 464 } 504 465 again: 505 466 /* ··· 496 493 * 2h Relative port 2, historically known as port B 497 494 * 3h to FFFFh Relative port 3 through 65 535 498 495 */ 499 - port->sep_rtpi = dev->dev_rpti_counter++; 500 - if (!port->sep_rtpi) 496 + lun->lun_rtpi = dev->dev_rpti_counter++; 497 + if (!lun->lun_rtpi) 501 498 goto again; 502 499 503 - list_for_each_entry(port_tmp, &dev->dev_sep_list, sep_list) { 500 + list_for_each_entry(tmp, &dev->dev_sep_list, lun_dev_link) { 504 501 /* 505 502 * Make sure RELATIVE TARGET PORT IDENTIFIER is unique 506 503 * for 16-bit wrap.. 507 504 */ 508 - if (port->sep_rtpi == port_tmp->sep_rtpi) 505 + if (lun->lun_rtpi == tmp->lun_rtpi) 509 506 goto again; 510 507 } 511 508 spin_unlock(&dev->se_port_lock); 512 509 513 - return port; 514 - } 515 - 516 - static void core_export_port( 517 - struct se_device *dev, 518 - struct se_portal_group *tpg, 519 - struct se_port *port, 520 - struct se_lun *lun) 521 - { 522 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem = NULL; 523 - 524 - spin_lock(&dev->se_port_lock); 525 - spin_lock(&lun->lun_sep_lock); 526 - port->sep_tpg = tpg; 527 - port->sep_lun = lun; 528 - lun->lun_sep = port; 529 - spin_unlock(&lun->lun_sep_lock); 530 - 531 - list_add_tail(&port->sep_list, &dev->dev_sep_list); 532 - spin_unlock(&dev->se_port_lock); 533 - 534 - if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) && 535 - !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) { 536 - tg_pt_gp_mem = core_alua_allocate_tg_pt_gp_mem(port); 537 - if (IS_ERR(tg_pt_gp_mem) || !tg_pt_gp_mem) { 538 - pr_err("Unable to allocate t10_alua_tg_pt" 539 - "_gp_member_t\n"); 540 - return; 541 - } 542 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 543 - __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, 544 - dev->t10_alua.default_tg_pt_gp); 545 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 546 - pr_debug("%s/%s: Adding to default ALUA Target Port" 547 - " Group: alua/default_tg_pt_gp\n", 548 - dev->transport->name, tpg->se_tpg_tfo->get_fabric_name()); 549 - } 550 - 551 - dev->dev_port_count++; 552 - port->sep_index = port->sep_rtpi; /* RELATIVE TARGET PORT IDENTIFIER */ 553 - } 554 - 555 - /* 556 - * Called with struct se_device->se_port_lock spinlock held. 557 - */ 558 - static void core_release_port(struct se_device *dev, struct se_port *port) 559 - __releases(&dev->se_port_lock) __acquires(&dev->se_port_lock) 560 - { 561 - /* 562 - * Wait for any port reference for PR ALL_TG_PT=1 operation 563 - * to complete in __core_scsi3_alloc_registration() 564 - */ 565 - spin_unlock(&dev->se_port_lock); 566 - if (atomic_read(&port->sep_tg_pt_ref_cnt)) 567 - cpu_relax(); 568 - spin_lock(&dev->se_port_lock); 569 - 570 - core_alua_free_tg_pt_gp_mem(port); 571 - 572 - list_del(&port->sep_list); 573 - dev->dev_port_count--; 574 - kfree(port); 575 - } 576 - 577 - int core_dev_export( 578 - struct se_device *dev, 579 - struct se_portal_group *tpg, 580 - struct se_lun *lun) 581 - { 582 - struct se_hba *hba = dev->se_hba; 583 - struct se_port *port; 584 - 585 - port = core_alloc_port(dev); 586 - if (IS_ERR(port)) 587 - return PTR_ERR(port); 588 - 589 - lun->lun_se_dev = dev; 590 - 591 - spin_lock(&hba->device_lock); 592 - dev->export_count++; 593 - spin_unlock(&hba->device_lock); 594 - 595 - core_export_port(dev, tpg, port, lun); 596 510 return 0; 597 - } 598 - 599 - void core_dev_unexport( 600 - struct se_device *dev, 601 - struct se_portal_group *tpg, 602 - struct se_lun *lun) 603 - { 604 - struct se_hba *hba = dev->se_hba; 605 - struct se_port *port = lun->lun_sep; 606 - 607 - spin_lock(&lun->lun_sep_lock); 608 - if (lun->lun_se_dev == NULL) { 609 - spin_unlock(&lun->lun_sep_lock); 610 - return; 611 - } 612 - spin_unlock(&lun->lun_sep_lock); 613 - 614 - spin_lock(&dev->se_port_lock); 615 - core_release_port(dev, port); 616 - spin_unlock(&dev->se_port_lock); 617 - 618 - spin_lock(&hba->device_lock); 619 - dev->export_count--; 620 - spin_unlock(&hba->device_lock); 621 - 622 - lun->lun_sep = NULL; 623 - lun->lun_se_dev = NULL; 624 511 } 625 512 626 513 static void se_release_vpd_for_dev(struct se_device *dev) ··· 544 651 return aligned_max_sectors; 545 652 } 546 653 547 - bool se_dev_check_wce(struct se_device *dev) 548 - { 549 - bool wce = false; 550 - 551 - if (dev->transport->get_write_cache) 552 - wce = dev->transport->get_write_cache(dev); 553 - else if (dev->dev_attrib.emulate_write_cache > 0) 554 - wce = true; 555 - 556 - return wce; 557 - } 558 - 559 - int se_dev_set_max_unmap_lba_count( 560 - struct se_device *dev, 561 - u32 max_unmap_lba_count) 562 - { 563 - dev->dev_attrib.max_unmap_lba_count = max_unmap_lba_count; 564 - pr_debug("dev[%p]: Set max_unmap_lba_count: %u\n", 565 - dev, dev->dev_attrib.max_unmap_lba_count); 566 - return 0; 567 - } 568 - EXPORT_SYMBOL(se_dev_set_max_unmap_lba_count); 569 - 570 - int se_dev_set_max_unmap_block_desc_count( 571 - struct se_device *dev, 572 - u32 max_unmap_block_desc_count) 573 - { 574 - dev->dev_attrib.max_unmap_block_desc_count = 575 - max_unmap_block_desc_count; 576 - pr_debug("dev[%p]: Set max_unmap_block_desc_count: %u\n", 577 - dev, dev->dev_attrib.max_unmap_block_desc_count); 578 - return 0; 579 - } 580 - EXPORT_SYMBOL(se_dev_set_max_unmap_block_desc_count); 581 - 582 - int se_dev_set_unmap_granularity( 583 - struct se_device *dev, 584 - u32 unmap_granularity) 585 - { 586 - dev->dev_attrib.unmap_granularity = unmap_granularity; 587 - pr_debug("dev[%p]: Set unmap_granularity: %u\n", 588 - dev, dev->dev_attrib.unmap_granularity); 589 - return 0; 590 - } 591 - EXPORT_SYMBOL(se_dev_set_unmap_granularity); 592 - 593 - int se_dev_set_unmap_granularity_alignment( 594 - struct se_device *dev, 595 - u32 unmap_granularity_alignment) 596 - { 597 - dev->dev_attrib.unmap_granularity_alignment = unmap_granularity_alignment; 598 - pr_debug("dev[%p]: Set unmap_granularity_alignment: %u\n", 599 - dev, dev->dev_attrib.unmap_granularity_alignment); 600 - return 0; 601 - } 602 - EXPORT_SYMBOL(se_dev_set_unmap_granularity_alignment); 603 - 604 - int se_dev_set_max_write_same_len( 605 - struct se_device *dev, 606 - u32 max_write_same_len) 607 - { 608 - dev->dev_attrib.max_write_same_len = max_write_same_len; 609 - pr_debug("dev[%p]: Set max_write_same_len: %u\n", 610 - dev, dev->dev_attrib.max_write_same_len); 611 - return 0; 612 - } 613 - EXPORT_SYMBOL(se_dev_set_max_write_same_len); 614 - 615 - static void dev_set_t10_wwn_model_alias(struct se_device *dev) 616 - { 617 - const char *configname; 618 - 619 - configname = config_item_name(&dev->dev_group.cg_item); 620 - if (strlen(configname) >= 16) { 621 - pr_warn("dev[%p]: Backstore name '%s' is too long for " 622 - "INQUIRY_MODEL, truncating to 16 bytes\n", dev, 623 - configname); 624 - } 625 - snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); 626 - } 627 - 628 - int se_dev_set_emulate_model_alias(struct se_device *dev, int flag) 629 - { 630 - if (dev->export_count) { 631 - pr_err("dev[%p]: Unable to change model alias" 632 - " while export_count is %d\n", 633 - dev, dev->export_count); 634 - return -EINVAL; 635 - } 636 - 637 - if (flag != 0 && flag != 1) { 638 - pr_err("Illegal value %d\n", flag); 639 - return -EINVAL; 640 - } 641 - 642 - if (flag) { 643 - dev_set_t10_wwn_model_alias(dev); 644 - } else { 645 - strncpy(&dev->t10_wwn.model[0], 646 - dev->transport->inquiry_prod, 16); 647 - } 648 - dev->dev_attrib.emulate_model_alias = flag; 649 - 650 - return 0; 651 - } 652 - EXPORT_SYMBOL(se_dev_set_emulate_model_alias); 653 - 654 - int se_dev_set_emulate_dpo(struct se_device *dev, int flag) 655 - { 656 - if (flag != 0 && flag != 1) { 657 - pr_err("Illegal value %d\n", flag); 658 - return -EINVAL; 659 - } 660 - 661 - if (flag) { 662 - pr_err("dpo_emulated not supported\n"); 663 - return -EINVAL; 664 - } 665 - 666 - return 0; 667 - } 668 - EXPORT_SYMBOL(se_dev_set_emulate_dpo); 669 - 670 - int se_dev_set_emulate_fua_write(struct se_device *dev, int flag) 671 - { 672 - if (flag != 0 && flag != 1) { 673 - pr_err("Illegal value %d\n", flag); 674 - return -EINVAL; 675 - } 676 - if (flag && 677 - dev->transport->get_write_cache) { 678 - pr_warn("emulate_fua_write not supported for this device, ignoring\n"); 679 - return 0; 680 - } 681 - if (dev->export_count) { 682 - pr_err("emulate_fua_write cannot be changed with active" 683 - " exports: %d\n", dev->export_count); 684 - return -EINVAL; 685 - } 686 - dev->dev_attrib.emulate_fua_write = flag; 687 - pr_debug("dev[%p]: SE Device Forced Unit Access WRITEs: %d\n", 688 - dev, dev->dev_attrib.emulate_fua_write); 689 - return 0; 690 - } 691 - EXPORT_SYMBOL(se_dev_set_emulate_fua_write); 692 - 693 - int se_dev_set_emulate_fua_read(struct se_device *dev, int flag) 694 - { 695 - if (flag != 0 && flag != 1) { 696 - pr_err("Illegal value %d\n", flag); 697 - return -EINVAL; 698 - } 699 - 700 - if (flag) { 701 - pr_err("ua read emulated not supported\n"); 702 - return -EINVAL; 703 - } 704 - 705 - return 0; 706 - } 707 - EXPORT_SYMBOL(se_dev_set_emulate_fua_read); 708 - 709 - int se_dev_set_emulate_write_cache(struct se_device *dev, int flag) 710 - { 711 - if (flag != 0 && flag != 1) { 712 - pr_err("Illegal value %d\n", flag); 713 - return -EINVAL; 714 - } 715 - if (flag && 716 - dev->transport->get_write_cache) { 717 - pr_err("emulate_write_cache not supported for this device\n"); 718 - return -EINVAL; 719 - } 720 - if (dev->export_count) { 721 - pr_err("emulate_write_cache cannot be changed with active" 722 - " exports: %d\n", dev->export_count); 723 - return -EINVAL; 724 - } 725 - dev->dev_attrib.emulate_write_cache = flag; 726 - pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n", 727 - dev, dev->dev_attrib.emulate_write_cache); 728 - return 0; 729 - } 730 - EXPORT_SYMBOL(se_dev_set_emulate_write_cache); 731 - 732 - int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *dev, int flag) 733 - { 734 - if ((flag != 0) && (flag != 1) && (flag != 2)) { 735 - pr_err("Illegal value %d\n", flag); 736 - return -EINVAL; 737 - } 738 - 739 - if (dev->export_count) { 740 - pr_err("dev[%p]: Unable to change SE Device" 741 - " UA_INTRLCK_CTRL while export_count is %d\n", 742 - dev, dev->export_count); 743 - return -EINVAL; 744 - } 745 - dev->dev_attrib.emulate_ua_intlck_ctrl = flag; 746 - pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n", 747 - dev, dev->dev_attrib.emulate_ua_intlck_ctrl); 748 - 749 - return 0; 750 - } 751 - EXPORT_SYMBOL(se_dev_set_emulate_ua_intlck_ctrl); 752 - 753 - int se_dev_set_emulate_tas(struct se_device *dev, int flag) 754 - { 755 - if ((flag != 0) && (flag != 1)) { 756 - pr_err("Illegal value %d\n", flag); 757 - return -EINVAL; 758 - } 759 - 760 - if (dev->export_count) { 761 - pr_err("dev[%p]: Unable to change SE Device TAS while" 762 - " export_count is %d\n", 763 - dev, dev->export_count); 764 - return -EINVAL; 765 - } 766 - dev->dev_attrib.emulate_tas = flag; 767 - pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n", 768 - dev, (dev->dev_attrib.emulate_tas) ? "Enabled" : "Disabled"); 769 - 770 - return 0; 771 - } 772 - EXPORT_SYMBOL(se_dev_set_emulate_tas); 773 - 774 - int se_dev_set_emulate_tpu(struct se_device *dev, int flag) 775 - { 776 - if ((flag != 0) && (flag != 1)) { 777 - pr_err("Illegal value %d\n", flag); 778 - return -EINVAL; 779 - } 780 - /* 781 - * We expect this value to be non-zero when generic Block Layer 782 - * Discard supported is detected iblock_create_virtdevice(). 783 - */ 784 - if (flag && !dev->dev_attrib.max_unmap_block_desc_count) { 785 - pr_err("Generic Block Discard not supported\n"); 786 - return -ENOSYS; 787 - } 788 - 789 - dev->dev_attrib.emulate_tpu = flag; 790 - pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n", 791 - dev, flag); 792 - return 0; 793 - } 794 - EXPORT_SYMBOL(se_dev_set_emulate_tpu); 795 - 796 - int se_dev_set_emulate_tpws(struct se_device *dev, int flag) 797 - { 798 - if ((flag != 0) && (flag != 1)) { 799 - pr_err("Illegal value %d\n", flag); 800 - return -EINVAL; 801 - } 802 - /* 803 - * We expect this value to be non-zero when generic Block Layer 804 - * Discard supported is detected iblock_create_virtdevice(). 805 - */ 806 - if (flag && !dev->dev_attrib.max_unmap_block_desc_count) { 807 - pr_err("Generic Block Discard not supported\n"); 808 - return -ENOSYS; 809 - } 810 - 811 - dev->dev_attrib.emulate_tpws = flag; 812 - pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n", 813 - dev, flag); 814 - return 0; 815 - } 816 - EXPORT_SYMBOL(se_dev_set_emulate_tpws); 817 - 818 - int se_dev_set_emulate_caw(struct se_device *dev, int flag) 819 - { 820 - if (flag != 0 && flag != 1) { 821 - pr_err("Illegal value %d\n", flag); 822 - return -EINVAL; 823 - } 824 - dev->dev_attrib.emulate_caw = flag; 825 - pr_debug("dev[%p]: SE Device CompareAndWrite (AtomicTestandSet): %d\n", 826 - dev, flag); 827 - 828 - return 0; 829 - } 830 - EXPORT_SYMBOL(se_dev_set_emulate_caw); 831 - 832 - int se_dev_set_emulate_3pc(struct se_device *dev, int flag) 833 - { 834 - if (flag != 0 && flag != 1) { 835 - pr_err("Illegal value %d\n", flag); 836 - return -EINVAL; 837 - } 838 - dev->dev_attrib.emulate_3pc = flag; 839 - pr_debug("dev[%p]: SE Device 3rd Party Copy (EXTENDED_COPY): %d\n", 840 - dev, flag); 841 - 842 - return 0; 843 - } 844 - EXPORT_SYMBOL(se_dev_set_emulate_3pc); 845 - 846 - int se_dev_set_pi_prot_type(struct se_device *dev, int flag) 847 - { 848 - int rc, old_prot = dev->dev_attrib.pi_prot_type; 849 - 850 - if (flag != 0 && flag != 1 && flag != 2 && flag != 3) { 851 - pr_err("Illegal value %d for pi_prot_type\n", flag); 852 - return -EINVAL; 853 - } 854 - if (flag == 2) { 855 - pr_err("DIF TYPE2 protection currently not supported\n"); 856 - return -ENOSYS; 857 - } 858 - if (dev->dev_attrib.hw_pi_prot_type) { 859 - pr_warn("DIF protection enabled on underlying hardware," 860 - " ignoring\n"); 861 - return 0; 862 - } 863 - if (!dev->transport->init_prot || !dev->transport->free_prot) { 864 - /* 0 is only allowed value for non-supporting backends */ 865 - if (flag == 0) 866 - return 0; 867 - 868 - pr_err("DIF protection not supported by backend: %s\n", 869 - dev->transport->name); 870 - return -ENOSYS; 871 - } 872 - if (!(dev->dev_flags & DF_CONFIGURED)) { 873 - pr_err("DIF protection requires device to be configured\n"); 874 - return -ENODEV; 875 - } 876 - if (dev->export_count) { 877 - pr_err("dev[%p]: Unable to change SE Device PROT type while" 878 - " export_count is %d\n", dev, dev->export_count); 879 - return -EINVAL; 880 - } 881 - 882 - dev->dev_attrib.pi_prot_type = flag; 883 - 884 - if (flag && !old_prot) { 885 - rc = dev->transport->init_prot(dev); 886 - if (rc) { 887 - dev->dev_attrib.pi_prot_type = old_prot; 888 - return rc; 889 - } 890 - 891 - } else if (!flag && old_prot) { 892 - dev->transport->free_prot(dev); 893 - } 894 - pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev, flag); 895 - 896 - return 0; 897 - } 898 - EXPORT_SYMBOL(se_dev_set_pi_prot_type); 899 - 900 - int se_dev_set_pi_prot_format(struct se_device *dev, int flag) 901 - { 902 - int rc; 903 - 904 - if (!flag) 905 - return 0; 906 - 907 - if (flag != 1) { 908 - pr_err("Illegal value %d for pi_prot_format\n", flag); 909 - return -EINVAL; 910 - } 911 - if (!dev->transport->format_prot) { 912 - pr_err("DIF protection format not supported by backend %s\n", 913 - dev->transport->name); 914 - return -ENOSYS; 915 - } 916 - if (!(dev->dev_flags & DF_CONFIGURED)) { 917 - pr_err("DIF protection format requires device to be configured\n"); 918 - return -ENODEV; 919 - } 920 - if (dev->export_count) { 921 - pr_err("dev[%p]: Unable to format SE Device PROT type while" 922 - " export_count is %d\n", dev, dev->export_count); 923 - return -EINVAL; 924 - } 925 - 926 - rc = dev->transport->format_prot(dev); 927 - if (rc) 928 - return rc; 929 - 930 - pr_debug("dev[%p]: SE Device Protection Format complete\n", dev); 931 - 932 - return 0; 933 - } 934 - EXPORT_SYMBOL(se_dev_set_pi_prot_format); 935 - 936 - int se_dev_set_enforce_pr_isids(struct se_device *dev, int flag) 937 - { 938 - if ((flag != 0) && (flag != 1)) { 939 - pr_err("Illegal value %d\n", flag); 940 - return -EINVAL; 941 - } 942 - dev->dev_attrib.enforce_pr_isids = flag; 943 - pr_debug("dev[%p]: SE Device enforce_pr_isids bit: %s\n", dev, 944 - (dev->dev_attrib.enforce_pr_isids) ? "Enabled" : "Disabled"); 945 - return 0; 946 - } 947 - EXPORT_SYMBOL(se_dev_set_enforce_pr_isids); 948 - 949 - int se_dev_set_force_pr_aptpl(struct se_device *dev, int flag) 950 - { 951 - if ((flag != 0) && (flag != 1)) { 952 - printk(KERN_ERR "Illegal value %d\n", flag); 953 - return -EINVAL; 954 - } 955 - if (dev->export_count) { 956 - pr_err("dev[%p]: Unable to set force_pr_aptpl while" 957 - " export_count is %d\n", dev, dev->export_count); 958 - return -EINVAL; 959 - } 960 - 961 - dev->dev_attrib.force_pr_aptpl = flag; 962 - pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", dev, flag); 963 - return 0; 964 - } 965 - EXPORT_SYMBOL(se_dev_set_force_pr_aptpl); 966 - 967 - int se_dev_set_is_nonrot(struct se_device *dev, int flag) 968 - { 969 - if ((flag != 0) && (flag != 1)) { 970 - printk(KERN_ERR "Illegal value %d\n", flag); 971 - return -EINVAL; 972 - } 973 - dev->dev_attrib.is_nonrot = flag; 974 - pr_debug("dev[%p]: SE Device is_nonrot bit: %d\n", 975 - dev, flag); 976 - return 0; 977 - } 978 - EXPORT_SYMBOL(se_dev_set_is_nonrot); 979 - 980 - int se_dev_set_emulate_rest_reord(struct se_device *dev, int flag) 981 - { 982 - if (flag != 0) { 983 - printk(KERN_ERR "dev[%p]: SE Device emulatation of restricted" 984 - " reordering not implemented\n", dev); 985 - return -ENOSYS; 986 - } 987 - dev->dev_attrib.emulate_rest_reord = flag; 988 - pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", dev, flag); 989 - return 0; 990 - } 991 - EXPORT_SYMBOL(se_dev_set_emulate_rest_reord); 992 - 993 - /* 994 - * Note, this can only be called on unexported SE Device Object. 995 - */ 996 - int se_dev_set_queue_depth(struct se_device *dev, u32 queue_depth) 997 - { 998 - if (dev->export_count) { 999 - pr_err("dev[%p]: Unable to change SE Device TCQ while" 1000 - " export_count is %d\n", 1001 - dev, dev->export_count); 1002 - return -EINVAL; 1003 - } 1004 - if (!queue_depth) { 1005 - pr_err("dev[%p]: Illegal ZERO value for queue" 1006 - "_depth\n", dev); 1007 - return -EINVAL; 1008 - } 1009 - 1010 - if (queue_depth > dev->dev_attrib.queue_depth) { 1011 - if (queue_depth > dev->dev_attrib.hw_queue_depth) { 1012 - pr_err("dev[%p]: Passed queue_depth:" 1013 - " %u exceeds TCM/SE_Device MAX" 1014 - " TCQ: %u\n", dev, queue_depth, 1015 - dev->dev_attrib.hw_queue_depth); 1016 - return -EINVAL; 1017 - } 1018 - } 1019 - dev->dev_attrib.queue_depth = dev->queue_depth = queue_depth; 1020 - pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", 1021 - dev, queue_depth); 1022 - return 0; 1023 - } 1024 - EXPORT_SYMBOL(se_dev_set_queue_depth); 1025 - 1026 - int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors) 1027 - { 1028 - if (dev->export_count) { 1029 - pr_err("dev[%p]: Unable to change SE Device" 1030 - " optimal_sectors while export_count is %d\n", 1031 - dev, dev->export_count); 1032 - return -EINVAL; 1033 - } 1034 - if (optimal_sectors > dev->dev_attrib.hw_max_sectors) { 1035 - pr_err("dev[%p]: Passed optimal_sectors %u cannot be" 1036 - " greater than hw_max_sectors: %u\n", dev, 1037 - optimal_sectors, dev->dev_attrib.hw_max_sectors); 1038 - return -EINVAL; 1039 - } 1040 - 1041 - dev->dev_attrib.optimal_sectors = optimal_sectors; 1042 - pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n", 1043 - dev, optimal_sectors); 1044 - return 0; 1045 - } 1046 - EXPORT_SYMBOL(se_dev_set_optimal_sectors); 1047 - 1048 - int se_dev_set_block_size(struct se_device *dev, u32 block_size) 1049 - { 1050 - if (dev->export_count) { 1051 - pr_err("dev[%p]: Unable to change SE Device block_size" 1052 - " while export_count is %d\n", 1053 - dev, dev->export_count); 1054 - return -EINVAL; 1055 - } 1056 - 1057 - if ((block_size != 512) && 1058 - (block_size != 1024) && 1059 - (block_size != 2048) && 1060 - (block_size != 4096)) { 1061 - pr_err("dev[%p]: Illegal value for block_device: %u" 1062 - " for SE device, must be 512, 1024, 2048 or 4096\n", 1063 - dev, block_size); 1064 - return -EINVAL; 1065 - } 1066 - 1067 - dev->dev_attrib.block_size = block_size; 1068 - pr_debug("dev[%p]: SE Device block_size changed to %u\n", 1069 - dev, block_size); 1070 - 1071 - if (dev->dev_attrib.max_bytes_per_io) 1072 - dev->dev_attrib.hw_max_sectors = 1073 - dev->dev_attrib.max_bytes_per_io / block_size; 1074 - 1075 - return 0; 1076 - } 1077 - EXPORT_SYMBOL(se_dev_set_block_size); 1078 - 1079 - struct se_lun *core_dev_add_lun( 654 + int core_dev_add_lun( 1080 655 struct se_portal_group *tpg, 1081 656 struct se_device *dev, 1082 - u32 unpacked_lun) 657 + struct se_lun *lun) 1083 658 { 1084 - struct se_lun *lun; 1085 659 int rc; 1086 - 1087 - lun = core_tpg_alloc_lun(tpg, unpacked_lun); 1088 - if (IS_ERR(lun)) 1089 - return lun; 1090 660 1091 661 rc = core_tpg_add_lun(tpg, lun, 1092 662 TRANSPORT_LUNFLAGS_READ_WRITE, dev); 1093 663 if (rc < 0) 1094 - return ERR_PTR(rc); 664 + return rc; 1095 665 1096 - pr_debug("%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from" 666 + pr_debug("%s_TPG[%u]_LUN[%llu] - Activated %s Logical Unit from" 1097 667 " CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(), 1098 668 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, 1099 669 tpg->se_tpg_tfo->get_fabric_name(), dev->se_hba->hba_id); ··· 566 1210 */ 567 1211 if (tpg->se_tpg_tfo->tpg_check_demo_mode(tpg)) { 568 1212 struct se_node_acl *acl; 569 - spin_lock_irq(&tpg->acl_node_lock); 1213 + 1214 + mutex_lock(&tpg->acl_node_mutex); 570 1215 list_for_each_entry(acl, &tpg->acl_node_list, acl_list) { 571 1216 if (acl->dynamic_node_acl && 572 1217 (!tpg->se_tpg_tfo->tpg_check_demo_mode_login_only || 573 1218 !tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg))) { 574 - spin_unlock_irq(&tpg->acl_node_lock); 575 - core_tpg_add_node_to_devs(acl, tpg); 576 - spin_lock_irq(&tpg->acl_node_lock); 1219 + core_tpg_add_node_to_devs(acl, tpg, lun); 577 1220 } 578 1221 } 579 - spin_unlock_irq(&tpg->acl_node_lock); 1222 + mutex_unlock(&tpg->acl_node_mutex); 580 1223 } 581 1224 582 - return lun; 1225 + return 0; 583 1226 } 584 1227 585 1228 /* core_dev_del_lun(): ··· 589 1234 struct se_portal_group *tpg, 590 1235 struct se_lun *lun) 591 1236 { 592 - pr_debug("%s_TPG[%u]_LUN[%u] - Deactivating %s Logical Unit from" 1237 + pr_debug("%s_TPG[%u]_LUN[%llu] - Deactivating %s Logical Unit from" 593 1238 " device object\n", tpg->se_tpg_tfo->get_fabric_name(), 594 1239 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, 595 1240 tpg->se_tpg_tfo->get_fabric_name()); ··· 597 1242 core_tpg_remove_lun(tpg, lun); 598 1243 } 599 1244 600 - struct se_lun *core_get_lun_from_tpg(struct se_portal_group *tpg, u32 unpacked_lun) 601 - { 602 - struct se_lun *lun; 603 - 604 - spin_lock(&tpg->tpg_lun_lock); 605 - if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { 606 - pr_err("%s LUN: %u exceeds TRANSPORT_MAX_LUNS" 607 - "_PER_TPG-1: %u for Target Portal Group: %hu\n", 608 - tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, 609 - TRANSPORT_MAX_LUNS_PER_TPG-1, 610 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 611 - spin_unlock(&tpg->tpg_lun_lock); 612 - return NULL; 613 - } 614 - lun = tpg->tpg_lun_list[unpacked_lun]; 615 - 616 - if (lun->lun_status != TRANSPORT_LUN_STATUS_FREE) { 617 - pr_err("%s Logical Unit Number: %u is not free on" 618 - " Target Portal Group: %hu, ignoring request.\n", 619 - tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, 620 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 621 - spin_unlock(&tpg->tpg_lun_lock); 622 - return NULL; 623 - } 624 - spin_unlock(&tpg->tpg_lun_lock); 625 - 626 - return lun; 627 - } 628 - 629 - /* core_dev_get_lun(): 630 - * 631 - * 632 - */ 633 - static struct se_lun *core_dev_get_lun(struct se_portal_group *tpg, u32 unpacked_lun) 634 - { 635 - struct se_lun *lun; 636 - 637 - spin_lock(&tpg->tpg_lun_lock); 638 - if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { 639 - pr_err("%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER" 640 - "_TPG-1: %u for Target Portal Group: %hu\n", 641 - tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, 642 - TRANSPORT_MAX_LUNS_PER_TPG-1, 643 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 644 - spin_unlock(&tpg->tpg_lun_lock); 645 - return NULL; 646 - } 647 - lun = tpg->tpg_lun_list[unpacked_lun]; 648 - 649 - if (lun->lun_status != TRANSPORT_LUN_STATUS_ACTIVE) { 650 - pr_err("%s Logical Unit Number: %u is not active on" 651 - " Target Portal Group: %hu, ignoring request.\n", 652 - tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, 653 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 654 - spin_unlock(&tpg->tpg_lun_lock); 655 - return NULL; 656 - } 657 - spin_unlock(&tpg->tpg_lun_lock); 658 - 659 - return lun; 660 - } 661 - 662 1245 struct se_lun_acl *core_dev_init_initiator_node_lun_acl( 663 1246 struct se_portal_group *tpg, 664 1247 struct se_node_acl *nacl, 665 - u32 mapped_lun, 1248 + u64 mapped_lun, 666 1249 int *ret) 667 1250 { 668 1251 struct se_lun_acl *lacl; ··· 618 1325 return NULL; 619 1326 } 620 1327 621 - INIT_LIST_HEAD(&lacl->lacl_list); 622 1328 lacl->mapped_lun = mapped_lun; 623 1329 lacl->se_lun_nacl = nacl; 624 1330 snprintf(lacl->initiatorname, TRANSPORT_IQN_LEN, "%s", ··· 629 1337 int core_dev_add_initiator_node_lun_acl( 630 1338 struct se_portal_group *tpg, 631 1339 struct se_lun_acl *lacl, 632 - u32 unpacked_lun, 1340 + struct se_lun *lun, 633 1341 u32 lun_access) 634 1342 { 635 - struct se_lun *lun; 636 - struct se_node_acl *nacl; 1343 + struct se_node_acl *nacl = lacl->se_lun_nacl; 1344 + /* 1345 + * rcu_dereference_raw protected by se_lun->lun_group symlink 1346 + * reference to se_device->dev_group. 1347 + */ 1348 + struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); 637 1349 638 - lun = core_dev_get_lun(tpg, unpacked_lun); 639 - if (!lun) { 640 - pr_err("%s Logical Unit Number: %u is not active on" 641 - " Target Portal Group: %hu, ignoring request.\n", 642 - tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, 643 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 644 - return -EINVAL; 645 - } 646 - 647 - nacl = lacl->se_lun_nacl; 648 1350 if (!nacl) 649 1351 return -EINVAL; 650 1352 ··· 652 1366 lun_access, nacl, tpg) < 0) 653 1367 return -EINVAL; 654 1368 655 - spin_lock(&lun->lun_acl_lock); 656 - list_add_tail(&lacl->lacl_list, &lun->lun_acl_list); 657 - atomic_inc_mb(&lun->lun_acl_count); 658 - spin_unlock(&lun->lun_acl_lock); 659 - 660 - pr_debug("%s_TPG[%hu]_LUN[%u->%u] - Added %s ACL for " 1369 + pr_debug("%s_TPG[%hu]_LUN[%llu->%llu] - Added %s ACL for " 661 1370 " InitiatorNode: %s\n", tpg->se_tpg_tfo->get_fabric_name(), 662 - tpg->se_tpg_tfo->tpg_get_tag(tpg), unpacked_lun, lacl->mapped_lun, 1371 + tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, lacl->mapped_lun, 663 1372 (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) ? "RW" : "RO", 664 1373 lacl->initiatorname); 665 1374 /* 666 1375 * Check to see if there are any existing persistent reservation APTPL 667 1376 * pre-registrations that need to be enabled for this LUN ACL.. 668 1377 */ 669 - core_scsi3_check_aptpl_registration(lun->lun_se_dev, tpg, lun, nacl, 1378 + core_scsi3_check_aptpl_registration(dev, tpg, lun, nacl, 670 1379 lacl->mapped_lun); 671 1380 return 0; 672 1381 } 673 1382 674 - /* core_dev_del_initiator_node_lun_acl(): 675 - * 676 - * 677 - */ 678 1383 int core_dev_del_initiator_node_lun_acl( 679 - struct se_portal_group *tpg, 680 1384 struct se_lun *lun, 681 1385 struct se_lun_acl *lacl) 682 1386 { 1387 + struct se_portal_group *tpg = lun->lun_tpg; 683 1388 struct se_node_acl *nacl; 1389 + struct se_dev_entry *deve; 684 1390 685 1391 nacl = lacl->se_lun_nacl; 686 1392 if (!nacl) 687 1393 return -EINVAL; 688 1394 689 - spin_lock(&lun->lun_acl_lock); 690 - list_del(&lacl->lacl_list); 691 - atomic_dec_mb(&lun->lun_acl_count); 692 - spin_unlock(&lun->lun_acl_lock); 1395 + mutex_lock(&nacl->lun_entry_mutex); 1396 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1397 + if (deve) 1398 + core_disable_device_list_for_node(lun, deve, nacl, tpg); 1399 + mutex_unlock(&nacl->lun_entry_mutex); 693 1400 694 - core_disable_device_list_for_node(lun, NULL, lacl->mapped_lun, 695 - TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); 696 - 697 - lacl->se_lun = NULL; 698 - 699 - pr_debug("%s_TPG[%hu]_LUN[%u] - Removed ACL for" 700 - " InitiatorNode: %s Mapped LUN: %u\n", 1401 + pr_debug("%s_TPG[%hu]_LUN[%llu] - Removed ACL for" 1402 + " InitiatorNode: %s Mapped LUN: %llu\n", 701 1403 tpg->se_tpg_tfo->get_fabric_name(), 702 1404 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, 703 1405 lacl->initiatorname, lacl->mapped_lun); ··· 698 1424 struct se_lun_acl *lacl) 699 1425 { 700 1426 pr_debug("%s_TPG[%hu] - Freeing ACL for %s InitiatorNode: %s" 701 - " Mapped LUN: %u\n", tpg->se_tpg_tfo->get_fabric_name(), 1427 + " Mapped LUN: %llu\n", tpg->se_tpg_tfo->get_fabric_name(), 702 1428 tpg->se_tpg_tfo->tpg_get_tag(tpg), 703 1429 tpg->se_tpg_tfo->get_fabric_name(), 704 1430 lacl->initiatorname, lacl->mapped_lun); ··· 747 1473 struct se_device *dev; 748 1474 struct se_lun *xcopy_lun; 749 1475 750 - dev = hba->transport->alloc_device(hba, name); 1476 + dev = hba->backend->ops->alloc_device(hba, name); 751 1477 if (!dev) 752 1478 return NULL; 753 1479 754 1480 dev->dev_link_magic = SE_DEV_LINK_MAGIC; 755 1481 dev->se_hba = hba; 756 - dev->transport = hba->transport; 1482 + dev->transport = hba->backend->ops; 757 1483 dev->prot_length = sizeof(struct se_dif_v1_tuple); 1484 + dev->hba_index = hba->hba_index; 758 1485 759 1486 INIT_LIST_HEAD(&dev->dev_list); 760 1487 INIT_LIST_HEAD(&dev->dev_sep_list); ··· 788 1513 789 1514 dev->dev_attrib.da_dev = dev; 790 1515 dev->dev_attrib.emulate_model_alias = DA_EMULATE_MODEL_ALIAS; 791 - dev->dev_attrib.emulate_dpo = DA_EMULATE_DPO; 792 - dev->dev_attrib.emulate_fua_write = DA_EMULATE_FUA_WRITE; 793 - dev->dev_attrib.emulate_fua_read = DA_EMULATE_FUA_READ; 1516 + dev->dev_attrib.emulate_dpo = 1; 1517 + dev->dev_attrib.emulate_fua_write = 1; 1518 + dev->dev_attrib.emulate_fua_read = 1; 794 1519 dev->dev_attrib.emulate_write_cache = DA_EMULATE_WRITE_CACHE; 795 1520 dev->dev_attrib.emulate_ua_intlck_ctrl = DA_EMULATE_UA_INTLLCK_CTRL; 796 1521 dev->dev_attrib.emulate_tas = DA_EMULATE_TAS; ··· 812 1537 dev->dev_attrib.max_write_same_len = DA_MAX_WRITE_SAME_LEN; 813 1538 814 1539 xcopy_lun = &dev->xcopy_lun; 815 - xcopy_lun->lun_se_dev = dev; 816 - init_completion(&xcopy_lun->lun_shutdown_comp); 817 - INIT_LIST_HEAD(&xcopy_lun->lun_acl_list); 818 - spin_lock_init(&xcopy_lun->lun_acl_lock); 819 - spin_lock_init(&xcopy_lun->lun_sep_lock); 1540 + rcu_assign_pointer(xcopy_lun->lun_se_dev, dev); 820 1541 init_completion(&xcopy_lun->lun_ref_comp); 1542 + INIT_LIST_HEAD(&xcopy_lun->lun_deve_list); 1543 + INIT_LIST_HEAD(&xcopy_lun->lun_dev_link); 1544 + mutex_init(&xcopy_lun->lun_tg_pt_md_mutex); 1545 + xcopy_lun->lun_tpg = &xcopy_pt_tpg; 821 1546 822 1547 return dev; 823 1548 } ··· 954 1679 goto out_free_hba; 955 1680 } 956 1681 957 - hba->transport->set_configfs_dev_params(dev, buf, sizeof(buf)); 1682 + hba->backend->ops->set_configfs_dev_params(dev, buf, sizeof(buf)); 958 1683 959 1684 ret = target_configure_device(dev); 960 1685 if (ret)
+105 -125
drivers/target/target_core_fabric_configfs.c
··· 36 36 #include <target/target_core_base.h> 37 37 #include <target/target_core_fabric.h> 38 38 #include <target/target_core_fabric_configfs.h> 39 - #include <target/target_core_configfs.h> 40 39 #include <target/configfs_macros.h> 41 40 42 41 #include "target_core_internal.h" ··· 45 46 #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ 46 47 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ 47 48 { \ 48 - struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \ 49 - struct config_item_type *cit = &tfc->tfc_##_name##_cit; \ 49 + struct config_item_type *cit = &tf->tf_##_name##_cit; \ 50 50 \ 51 51 cit->ct_item_ops = _item_ops; \ 52 52 cit->ct_group_ops = _group_ops; \ 53 53 cit->ct_attrs = _attrs; \ 54 - cit->ct_owner = tf->tf_module; \ 54 + cit->ct_owner = tf->tf_ops->module; \ 55 55 pr_debug("Setup generic %s\n", __stringify(_name)); \ 56 56 } 57 57 58 58 #define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ 59 59 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ 60 60 { \ 61 - struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \ 62 - struct config_item_type *cit = &tfc->tfc_##_name##_cit; \ 63 - struct configfs_attribute **attrs = tf->tf_ops.tfc_##_name##_attrs; \ 61 + struct config_item_type *cit = &tf->tf_##_name##_cit; \ 62 + struct configfs_attribute **attrs = tf->tf_ops->tfc_##_name##_attrs; \ 64 63 \ 65 64 cit->ct_item_ops = _item_ops; \ 66 65 cit->ct_group_ops = _group_ops; \ 67 66 cit->ct_attrs = attrs; \ 68 - cit->ct_owner = tf->tf_module; \ 67 + cit->ct_owner = tf->tf_ops->module; \ 69 68 pr_debug("Setup generic %s\n", __stringify(_name)); \ 70 69 } 71 70 ··· 80 83 struct se_lun_acl, se_lun_group); 81 84 struct se_portal_group *se_tpg; 82 85 struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s; 83 - int ret = 0, lun_access; 86 + int lun_access; 84 87 85 88 if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) { 86 89 pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:" ··· 90 93 /* 91 94 * Ensure that the source port exists 92 95 */ 93 - if (!lun->lun_sep || !lun->lun_sep->sep_tpg) { 94 - pr_err("Source se_lun->lun_sep or lun->lun_sep->sep" 95 - "_tpg does not exist\n"); 96 + if (!lun->lun_se_dev) { 97 + pr_err("Source se_lun->lun_se_dev does not exist\n"); 96 98 return -EINVAL; 97 99 } 98 - se_tpg = lun->lun_sep->sep_tpg; 100 + se_tpg = lun->lun_tpg; 99 101 100 102 nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item; 101 103 tpg_ci = &nacl_ci->ci_group->cg_item; ··· 121 125 * which be will write protected (READ-ONLY) when 122 126 * tpg_1/attrib/demo_mode_write_protect=1 123 127 */ 124 - spin_lock_irq(&lacl->se_lun_nacl->device_list_lock); 125 - deve = lacl->se_lun_nacl->device_list[lacl->mapped_lun]; 126 - if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) 128 + rcu_read_lock(); 129 + deve = target_nacl_find_deve(lacl->se_lun_nacl, lacl->mapped_lun); 130 + if (deve) 127 131 lun_access = deve->lun_flags; 128 132 else 129 133 lun_access = 130 134 (se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect( 131 135 se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY : 132 136 TRANSPORT_LUNFLAGS_READ_WRITE; 133 - spin_unlock_irq(&lacl->se_lun_nacl->device_list_lock); 137 + rcu_read_unlock(); 134 138 /* 135 139 * Determine the actual mapped LUN value user wants.. 136 140 * 137 141 * This value is what the SCSI Initiator actually sees the 138 - * iscsi/$IQN/$TPGT/lun/lun_* as on their SCSI Initiator Ports. 142 + * $FABRIC/$WWPN/$TPGT/lun/lun_* as on their SCSI Initiator Ports. 139 143 */ 140 - ret = core_dev_add_initiator_node_lun_acl(se_tpg, lacl, 141 - lun->unpacked_lun, lun_access); 142 - 143 - return (ret < 0) ? -EINVAL : 0; 144 + return core_dev_add_initiator_node_lun_acl(se_tpg, lacl, lun, lun_access); 144 145 } 145 146 146 147 static int target_fabric_mappedlun_unlink( 147 148 struct config_item *lun_acl_ci, 148 149 struct config_item *lun_ci) 149 150 { 150 - struct se_lun *lun; 151 151 struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), 152 152 struct se_lun_acl, se_lun_group); 153 - struct se_node_acl *nacl = lacl->se_lun_nacl; 154 - struct se_dev_entry *deve = nacl->device_list[lacl->mapped_lun]; 155 - struct se_portal_group *se_tpg; 156 - /* 157 - * Determine if the underlying MappedLUN has already been released.. 158 - */ 159 - if (!deve->se_lun) 160 - return 0; 153 + struct se_lun *lun = container_of(to_config_group(lun_ci), 154 + struct se_lun, lun_group); 161 155 162 - lun = container_of(to_config_group(lun_ci), struct se_lun, lun_group); 163 - se_tpg = lun->lun_sep->sep_tpg; 164 - 165 - core_dev_del_initiator_node_lun_acl(se_tpg, lun, lacl); 166 - return 0; 156 + return core_dev_del_initiator_node_lun_acl(lun, lacl); 167 157 } 168 158 169 159 CONFIGFS_EATTR_STRUCT(target_fabric_mappedlun, se_lun_acl); ··· 165 183 { 166 184 struct se_node_acl *se_nacl = lacl->se_lun_nacl; 167 185 struct se_dev_entry *deve; 168 - ssize_t len; 186 + ssize_t len = 0; 169 187 170 - spin_lock_irq(&se_nacl->device_list_lock); 171 - deve = se_nacl->device_list[lacl->mapped_lun]; 172 - len = sprintf(page, "%d\n", 173 - (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ? 174 - 1 : 0); 175 - spin_unlock_irq(&se_nacl->device_list_lock); 188 + rcu_read_lock(); 189 + deve = target_nacl_find_deve(se_nacl, lacl->mapped_lun); 190 + if (deve) { 191 + len = sprintf(page, "%d\n", 192 + (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ? 1 : 0); 193 + } 194 + rcu_read_unlock(); 176 195 177 196 return len; 178 197 } ··· 201 218 lacl->se_lun_nacl); 202 219 203 220 pr_debug("%s_ConfigFS: Changed Initiator ACL: %s" 204 - " Mapped LUN: %u Write Protect bit to %s\n", 221 + " Mapped LUN: %llu Write Protect bit to %s\n", 205 222 se_tpg->se_tpg_tfo->get_fabric_name(), 206 223 lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF"); 207 224 ··· 321 338 struct config_item *acl_ci; 322 339 struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; 323 340 char *buf; 324 - unsigned long mapped_lun; 341 + unsigned long long mapped_lun; 325 342 int ret = 0; 326 343 327 344 acl_ci = &group->cg_item; ··· 349 366 * Determine the Mapped LUN value. This is what the SCSI Initiator 350 367 * Port will actually see. 351 368 */ 352 - ret = kstrtoul(buf + 4, 0, &mapped_lun); 369 + ret = kstrtoull(buf + 4, 0, &mapped_lun); 353 370 if (ret) 354 371 goto out; 355 - if (mapped_lun > UINT_MAX) { 356 - ret = -EINVAL; 357 - goto out; 358 - } 359 - if (mapped_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { 360 - pr_err("Mapped LUN: %lu exceeds TRANSPORT_MAX_LUNS_PER_TPG" 361 - "-1: %u for Target Portal Group: %u\n", mapped_lun, 362 - TRANSPORT_MAX_LUNS_PER_TPG-1, 363 - se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); 364 - ret = -EINVAL; 365 - goto out; 366 - } 367 372 368 373 lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl, 369 374 mapped_lun, &ret); ··· 370 399 } 371 400 372 401 config_group_init_type_name(&lacl->se_lun_group, name, 373 - &tf->tf_cit_tmpl.tfc_tpg_mappedlun_cit); 402 + &tf->tf_tpg_mappedlun_cit); 374 403 config_group_init_type_name(&lacl->ml_stat_grps.stat_group, 375 - "statistics", &tf->tf_cit_tmpl.tfc_tpg_mappedlun_stat_cit); 404 + "statistics", &tf->tf_tpg_mappedlun_stat_cit); 376 405 lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group; 377 406 lacl_cg->default_groups[1] = NULL; 378 407 ··· 429 458 { 430 459 struct se_node_acl *se_nacl = container_of(to_config_group(item), 431 460 struct se_node_acl, acl_group); 432 - struct se_portal_group *se_tpg = se_nacl->se_tpg; 433 - struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; 461 + struct target_fabric_configfs *tf = se_nacl->se_tpg->se_tpg_wwn->wwn_tf; 434 462 435 - tf->tf_ops.fabric_drop_nodeacl(se_nacl); 463 + if (tf->tf_ops->fabric_cleanup_nodeacl) 464 + tf->tf_ops->fabric_cleanup_nodeacl(se_nacl); 465 + core_tpg_del_initiator_node_acl(se_nacl); 436 466 } 437 467 438 468 static struct configfs_item_operations target_fabric_nacl_base_item_ops = { ··· 473 501 struct se_node_acl *se_nacl; 474 502 struct config_group *nacl_cg; 475 503 476 - if (!tf->tf_ops.fabric_make_nodeacl) { 477 - pr_err("tf->tf_ops.fabric_make_nodeacl is NULL\n"); 478 - return ERR_PTR(-ENOSYS); 479 - } 480 - 481 - se_nacl = tf->tf_ops.fabric_make_nodeacl(se_tpg, group, name); 504 + se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name); 482 505 if (IS_ERR(se_nacl)) 483 506 return ERR_CAST(se_nacl); 507 + 508 + if (tf->tf_ops->fabric_init_nodeacl) { 509 + int ret = tf->tf_ops->fabric_init_nodeacl(se_nacl, name); 510 + if (ret) { 511 + core_tpg_del_initiator_node_acl(se_nacl); 512 + return ERR_PTR(ret); 513 + } 514 + } 484 515 485 516 nacl_cg = &se_nacl->acl_group; 486 517 nacl_cg->default_groups = se_nacl->acl_default_groups; ··· 494 519 nacl_cg->default_groups[4] = NULL; 495 520 496 521 config_group_init_type_name(&se_nacl->acl_group, name, 497 - &tf->tf_cit_tmpl.tfc_tpg_nacl_base_cit); 522 + &tf->tf_tpg_nacl_base_cit); 498 523 config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib", 499 - &tf->tf_cit_tmpl.tfc_tpg_nacl_attrib_cit); 524 + &tf->tf_tpg_nacl_attrib_cit); 500 525 config_group_init_type_name(&se_nacl->acl_auth_group, "auth", 501 - &tf->tf_cit_tmpl.tfc_tpg_nacl_auth_cit); 526 + &tf->tf_tpg_nacl_auth_cit); 502 527 config_group_init_type_name(&se_nacl->acl_param_group, "param", 503 - &tf->tf_cit_tmpl.tfc_tpg_nacl_param_cit); 528 + &tf->tf_tpg_nacl_param_cit); 504 529 config_group_init_type_name(&se_nacl->acl_fabric_stat_group, 505 - "fabric_statistics", 506 - &tf->tf_cit_tmpl.tfc_tpg_nacl_stat_cit); 530 + "fabric_statistics", &tf->tf_tpg_nacl_stat_cit); 507 531 508 532 return &se_nacl->acl_group; 509 533 } ··· 549 575 struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent; 550 576 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; 551 577 552 - tf->tf_ops.fabric_drop_np(se_tpg_np); 578 + tf->tf_ops->fabric_drop_np(se_tpg_np); 553 579 } 554 580 555 581 static struct configfs_item_operations target_fabric_np_base_item_ops = { ··· 573 599 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; 574 600 struct se_tpg_np *se_tpg_np; 575 601 576 - if (!tf->tf_ops.fabric_make_np) { 602 + if (!tf->tf_ops->fabric_make_np) { 577 603 pr_err("tf->tf_ops.fabric_make_np is NULL\n"); 578 604 return ERR_PTR(-ENOSYS); 579 605 } 580 606 581 - se_tpg_np = tf->tf_ops.fabric_make_np(se_tpg, group, name); 607 + se_tpg_np = tf->tf_ops->fabric_make_np(se_tpg, group, name); 582 608 if (!se_tpg_np || IS_ERR(se_tpg_np)) 583 609 return ERR_PTR(-EINVAL); 584 610 585 611 se_tpg_np->tpg_np_parent = se_tpg; 586 612 config_group_init_type_name(&se_tpg_np->tpg_np_group, name, 587 - &tf->tf_cit_tmpl.tfc_tpg_np_base_cit); 613 + &tf->tf_tpg_np_base_cit); 588 614 589 615 return &se_tpg_np->tpg_np_group; 590 616 } ··· 628 654 struct se_lun *lun, 629 655 char *page) 630 656 { 631 - if (!lun || !lun->lun_sep) 657 + if (!lun || !lun->lun_se_dev) 632 658 return -ENODEV; 633 659 634 - return core_alua_show_tg_pt_gp_info(lun->lun_sep, page); 660 + return core_alua_show_tg_pt_gp_info(lun, page); 635 661 } 636 662 637 663 static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp( ··· 639 665 const char *page, 640 666 size_t count) 641 667 { 642 - if (!lun || !lun->lun_sep) 668 + if (!lun || !lun->lun_se_dev) 643 669 return -ENODEV; 644 670 645 - return core_alua_store_tg_pt_gp_info(lun->lun_sep, page, count); 671 + return core_alua_store_tg_pt_gp_info(lun, page, count); 646 672 } 647 673 648 674 TCM_PORT_ATTR(alua_tg_pt_gp, S_IRUGO | S_IWUSR); ··· 654 680 struct se_lun *lun, 655 681 char *page) 656 682 { 657 - if (!lun || !lun->lun_sep) 683 + if (!lun || !lun->lun_se_dev) 658 684 return -ENODEV; 659 685 660 686 return core_alua_show_offline_bit(lun, page); ··· 665 691 const char *page, 666 692 size_t count) 667 693 { 668 - if (!lun || !lun->lun_sep) 694 + if (!lun || !lun->lun_se_dev) 669 695 return -ENODEV; 670 696 671 697 return core_alua_store_offline_bit(lun, page, count); ··· 680 706 struct se_lun *lun, 681 707 char *page) 682 708 { 683 - if (!lun || !lun->lun_sep) 709 + if (!lun || !lun->lun_se_dev) 684 710 return -ENODEV; 685 711 686 712 return core_alua_show_secondary_status(lun, page); ··· 691 717 const char *page, 692 718 size_t count) 693 719 { 694 - if (!lun || !lun->lun_sep) 720 + if (!lun || !lun->lun_se_dev) 695 721 return -ENODEV; 696 722 697 723 return core_alua_store_secondary_status(lun, page, count); ··· 706 732 struct se_lun *lun, 707 733 char *page) 708 734 { 709 - if (!lun || !lun->lun_sep) 735 + if (!lun || !lun->lun_se_dev) 710 736 return -ENODEV; 711 737 712 738 return core_alua_show_secondary_write_metadata(lun, page); ··· 717 743 const char *page, 718 744 size_t count) 719 745 { 720 - if (!lun || !lun->lun_sep) 746 + if (!lun || !lun->lun_se_dev) 721 747 return -ENODEV; 722 748 723 749 return core_alua_store_secondary_write_metadata(lun, page, count); ··· 743 769 struct config_item *tpg_ci; 744 770 struct se_lun *lun = container_of(to_config_group(lun_ci), 745 771 struct se_lun, lun_group); 746 - struct se_lun *lun_p; 747 772 struct se_portal_group *se_tpg; 748 773 struct se_device *dev = 749 774 container_of(to_config_group(se_dev_ci), struct se_device, dev_group); ··· 770 797 return -EEXIST; 771 798 } 772 799 773 - lun_p = core_dev_add_lun(se_tpg, dev, lun->unpacked_lun); 774 - if (IS_ERR(lun_p)) { 775 - pr_err("core_dev_add_lun() failed\n"); 776 - ret = PTR_ERR(lun_p); 800 + ret = core_dev_add_lun(se_tpg, dev, lun); 801 + if (ret) { 802 + pr_err("core_dev_add_lun() failed: %d\n", ret); 777 803 goto out; 778 804 } 779 805 780 - if (tf->tf_ops.fabric_post_link) { 806 + if (tf->tf_ops->fabric_post_link) { 781 807 /* 782 808 * Call the optional fabric_post_link() to allow a 783 809 * fabric module to setup any additional state once 784 810 * core_dev_add_lun() has been called.. 785 811 */ 786 - tf->tf_ops.fabric_post_link(se_tpg, lun); 812 + tf->tf_ops->fabric_post_link(se_tpg, lun); 787 813 } 788 814 789 815 return 0; ··· 796 824 { 797 825 struct se_lun *lun = container_of(to_config_group(lun_ci), 798 826 struct se_lun, lun_group); 799 - struct se_portal_group *se_tpg = lun->lun_sep->sep_tpg; 827 + struct se_portal_group *se_tpg = lun->lun_tpg; 800 828 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; 801 829 802 - if (tf->tf_ops.fabric_pre_unlink) { 830 + if (tf->tf_ops->fabric_pre_unlink) { 803 831 /* 804 832 * Call the optional fabric_pre_unlink() to allow a 805 833 * fabric module to release any additional stat before 806 834 * core_dev_del_lun() is called. 807 835 */ 808 - tf->tf_ops.fabric_pre_unlink(se_tpg, lun); 836 + tf->tf_ops->fabric_pre_unlink(se_tpg, lun); 809 837 } 810 838 811 839 core_dev_del_lun(se_tpg, lun); 812 840 return 0; 813 841 } 814 842 843 + static void target_fabric_port_release(struct config_item *item) 844 + { 845 + struct se_lun *lun = container_of(to_config_group(item), 846 + struct se_lun, lun_group); 847 + 848 + kfree_rcu(lun, rcu_head); 849 + } 850 + 815 851 static struct configfs_item_operations target_fabric_port_item_ops = { 816 852 .show_attribute = target_fabric_port_attr_show, 817 853 .store_attribute = target_fabric_port_attr_store, 854 + .release = target_fabric_port_release, 818 855 .allow_link = target_fabric_port_link, 819 856 .drop_link = target_fabric_port_unlink, 820 857 }; ··· 868 887 struct se_portal_group, tpg_lun_group); 869 888 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; 870 889 struct config_group *lun_cg = NULL, *port_stat_grp = NULL; 871 - unsigned long unpacked_lun; 890 + unsigned long long unpacked_lun; 872 891 int errno; 873 892 874 893 if (strstr(name, "lun_") != name) { ··· 876 895 " \"lun_$LUN_NUMBER\"\n"); 877 896 return ERR_PTR(-EINVAL); 878 897 } 879 - errno = kstrtoul(name + 4, 0, &unpacked_lun); 898 + errno = kstrtoull(name + 4, 0, &unpacked_lun); 880 899 if (errno) 881 900 return ERR_PTR(errno); 882 - if (unpacked_lun > UINT_MAX) 883 - return ERR_PTR(-EINVAL); 884 901 885 - lun = core_get_lun_from_tpg(se_tpg, unpacked_lun); 886 - if (!lun) 887 - return ERR_PTR(-EINVAL); 902 + lun = core_tpg_alloc_lun(se_tpg, unpacked_lun); 903 + if (IS_ERR(lun)) 904 + return ERR_CAST(lun); 888 905 889 906 lun_cg = &lun->lun_group; 890 907 lun_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2, 891 908 GFP_KERNEL); 892 909 if (!lun_cg->default_groups) { 893 910 pr_err("Unable to allocate lun_cg->default_groups\n"); 911 + kfree(lun); 894 912 return ERR_PTR(-ENOMEM); 895 913 } 896 914 897 915 config_group_init_type_name(&lun->lun_group, name, 898 - &tf->tf_cit_tmpl.tfc_tpg_port_cit); 916 + &tf->tf_tpg_port_cit); 899 917 config_group_init_type_name(&lun->port_stat_grps.stat_group, 900 - "statistics", &tf->tf_cit_tmpl.tfc_tpg_port_stat_cit); 918 + "statistics", &tf->tf_tpg_port_stat_cit); 901 919 lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group; 902 920 lun_cg->default_groups[1] = NULL; 903 921 ··· 906 926 if (!port_stat_grp->default_groups) { 907 927 pr_err("Unable to allocate port_stat_grp->default_groups\n"); 908 928 kfree(lun_cg->default_groups); 929 + kfree(lun); 909 930 return ERR_PTR(-ENOMEM); 910 931 } 911 932 target_stat_setup_port_default_groups(lun); ··· 1004 1023 struct se_wwn *wwn = se_tpg->se_tpg_wwn; 1005 1024 struct target_fabric_configfs *tf = wwn->wwn_tf; 1006 1025 1007 - tf->tf_ops.fabric_drop_tpg(se_tpg); 1026 + tf->tf_ops->fabric_drop_tpg(se_tpg); 1008 1027 } 1009 1028 1010 1029 static struct configfs_item_operations target_fabric_tpg_base_item_ops = { ··· 1027 1046 struct target_fabric_configfs *tf = wwn->wwn_tf; 1028 1047 struct se_portal_group *se_tpg; 1029 1048 1030 - if (!tf->tf_ops.fabric_make_tpg) { 1031 - pr_err("tf->tf_ops.fabric_make_tpg is NULL\n"); 1049 + if (!tf->tf_ops->fabric_make_tpg) { 1050 + pr_err("tf->tf_ops->fabric_make_tpg is NULL\n"); 1032 1051 return ERR_PTR(-ENOSYS); 1033 1052 } 1034 1053 1035 - se_tpg = tf->tf_ops.fabric_make_tpg(wwn, group, name); 1054 + se_tpg = tf->tf_ops->fabric_make_tpg(wwn, group, name); 1036 1055 if (!se_tpg || IS_ERR(se_tpg)) 1037 1056 return ERR_PTR(-EINVAL); 1038 1057 /* ··· 1048 1067 se_tpg->tpg_group.default_groups[6] = NULL; 1049 1068 1050 1069 config_group_init_type_name(&se_tpg->tpg_group, name, 1051 - &tf->tf_cit_tmpl.tfc_tpg_base_cit); 1070 + &tf->tf_tpg_base_cit); 1052 1071 config_group_init_type_name(&se_tpg->tpg_lun_group, "lun", 1053 - &tf->tf_cit_tmpl.tfc_tpg_lun_cit); 1072 + &tf->tf_tpg_lun_cit); 1054 1073 config_group_init_type_name(&se_tpg->tpg_np_group, "np", 1055 - &tf->tf_cit_tmpl.tfc_tpg_np_cit); 1074 + &tf->tf_tpg_np_cit); 1056 1075 config_group_init_type_name(&se_tpg->tpg_acl_group, "acls", 1057 - &tf->tf_cit_tmpl.tfc_tpg_nacl_cit); 1076 + &tf->tf_tpg_nacl_cit); 1058 1077 config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib", 1059 - &tf->tf_cit_tmpl.tfc_tpg_attrib_cit); 1078 + &tf->tf_tpg_attrib_cit); 1060 1079 config_group_init_type_name(&se_tpg->tpg_auth_group, "auth", 1061 - &tf->tf_cit_tmpl.tfc_tpg_auth_cit); 1080 + &tf->tf_tpg_auth_cit); 1062 1081 config_group_init_type_name(&se_tpg->tpg_param_group, "param", 1063 - &tf->tf_cit_tmpl.tfc_tpg_param_cit); 1082 + &tf->tf_tpg_param_cit); 1064 1083 1065 1084 return &se_tpg->tpg_group; 1066 1085 } ··· 1093 1112 struct se_wwn, wwn_group); 1094 1113 struct target_fabric_configfs *tf = wwn->wwn_tf; 1095 1114 1096 - tf->tf_ops.fabric_drop_wwn(wwn); 1115 + tf->tf_ops->fabric_drop_wwn(wwn); 1097 1116 } 1098 1117 1099 1118 static struct configfs_item_operations target_fabric_tpg_item_ops = { ··· 1129 1148 struct target_fabric_configfs, tf_group); 1130 1149 struct se_wwn *wwn; 1131 1150 1132 - if (!tf->tf_ops.fabric_make_wwn) { 1151 + if (!tf->tf_ops->fabric_make_wwn) { 1133 1152 pr_err("tf->tf_ops.fabric_make_wwn is NULL\n"); 1134 1153 return ERR_PTR(-ENOSYS); 1135 1154 } 1136 1155 1137 - wwn = tf->tf_ops.fabric_make_wwn(tf, group, name); 1156 + wwn = tf->tf_ops->fabric_make_wwn(tf, group, name); 1138 1157 if (!wwn || IS_ERR(wwn)) 1139 1158 return ERR_PTR(-EINVAL); 1140 1159 ··· 1146 1165 wwn->wwn_group.default_groups[0] = &wwn->fabric_stat_group; 1147 1166 wwn->wwn_group.default_groups[1] = NULL; 1148 1167 1149 - config_group_init_type_name(&wwn->wwn_group, name, 1150 - &tf->tf_cit_tmpl.tfc_tpg_cit); 1168 + config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit); 1151 1169 config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics", 1152 - &tf->tf_cit_tmpl.tfc_wwn_fabric_stats_cit); 1170 + &tf->tf_wwn_fabric_stats_cit); 1153 1171 1154 1172 return &wwn->wwn_group; 1155 1173 }
+135 -150
drivers/target/target_core_fabric_lib.c
··· 24 24 * 25 25 ******************************************************************************/ 26 26 27 + /* 28 + * See SPC4, section 7.5 "Protocol specific parameters" for details 29 + * on the formats implemented in this file. 30 + */ 31 + 27 32 #include <linux/kernel.h> 28 33 #include <linux/string.h> 29 34 #include <linux/ctype.h> ··· 39 34 40 35 #include <target/target_core_base.h> 41 36 #include <target/target_core_fabric.h> 42 - #include <target/target_core_configfs.h> 43 37 44 38 #include "target_core_internal.h" 45 39 #include "target_core_pr.h" 46 40 47 - /* 48 - * Handlers for Serial Attached SCSI (SAS) 49 - */ 50 - u8 sas_get_fabric_proto_ident(struct se_portal_group *se_tpg) 51 - { 52 - /* 53 - * Return a SAS Serial SCSI Protocol identifier for loopback operations 54 - * This is defined in section 7.5.1 Table 362 in spc4r17 55 - */ 56 - return 0x6; 57 - } 58 - EXPORT_SYMBOL(sas_get_fabric_proto_ident); 59 41 60 - u32 sas_get_pr_transport_id( 61 - struct se_portal_group *se_tpg, 62 - struct se_node_acl *se_nacl, 63 - struct t10_pr_registration *pr_reg, 42 + static int sas_get_pr_transport_id( 43 + struct se_node_acl *nacl, 64 44 int *format_code, 65 45 unsigned char *buf) 66 46 { 67 - unsigned char *ptr; 68 47 int ret; 69 48 70 - /* 71 - * Set PROTOCOL IDENTIFIER to 6h for SAS 72 - */ 73 - buf[0] = 0x06; 74 - /* 75 - * From spc4r17, 7.5.4.7 TransportID for initiator ports using SCSI 76 - * over SAS Serial SCSI Protocol 77 - */ 78 - ptr = &se_nacl->initiatorname[4]; /* Skip over 'naa. prefix */ 49 + /* Skip over 'naa. prefix */ 50 + ret = hex2bin(&buf[4], &nacl->initiatorname[4], 8); 51 + if (ret) { 52 + pr_debug("%s: invalid hex string\n", __func__); 53 + return ret; 54 + } 79 55 80 - ret = hex2bin(&buf[4], ptr, 8); 81 - if (ret < 0) 82 - pr_debug("sas transport_id: invalid hex string\n"); 83 - 84 - /* 85 - * The SAS Transport ID is a hardcoded 24-byte length 86 - */ 87 56 return 24; 88 57 } 89 - EXPORT_SYMBOL(sas_get_pr_transport_id); 90 58 91 - u32 sas_get_pr_transport_id_len( 92 - struct se_portal_group *se_tpg, 59 + static int fc_get_pr_transport_id( 93 60 struct se_node_acl *se_nacl, 94 - struct t10_pr_registration *pr_reg, 95 - int *format_code) 96 - { 97 - *format_code = 0; 98 - /* 99 - * From spc4r17, 7.5.4.7 TransportID for initiator ports using SCSI 100 - * over SAS Serial SCSI Protocol 101 - * 102 - * The SAS Transport ID is a hardcoded 24-byte length 103 - */ 104 - return 24; 105 - } 106 - EXPORT_SYMBOL(sas_get_pr_transport_id_len); 107 - 108 - /* 109 - * Used for handling SCSI fabric dependent TransportIDs in SPC-3 and above 110 - * Persistent Reservation SPEC_I_PT=1 and PROUT REGISTER_AND_MOVE operations. 111 - */ 112 - char *sas_parse_pr_out_transport_id( 113 - struct se_portal_group *se_tpg, 114 - const char *buf, 115 - u32 *out_tid_len, 116 - char **port_nexus_ptr) 117 - { 118 - /* 119 - * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.7 TransportID 120 - * for initiator ports using SCSI over SAS Serial SCSI Protocol 121 - * 122 - * The TransportID for a SAS Initiator Port is of fixed size of 123 - * 24 bytes, and SAS does not contain a I_T nexus identifier, 124 - * so we return the **port_nexus_ptr set to NULL. 125 - */ 126 - *port_nexus_ptr = NULL; 127 - *out_tid_len = 24; 128 - 129 - return (char *)&buf[4]; 130 - } 131 - EXPORT_SYMBOL(sas_parse_pr_out_transport_id); 132 - 133 - /* 134 - * Handlers for Fibre Channel Protocol (FCP) 135 - */ 136 - u8 fc_get_fabric_proto_ident(struct se_portal_group *se_tpg) 137 - { 138 - return 0x0; /* 0 = fcp-2 per SPC4 section 7.5.1 */ 139 - } 140 - EXPORT_SYMBOL(fc_get_fabric_proto_ident); 141 - 142 - u32 fc_get_pr_transport_id_len( 143 - struct se_portal_group *se_tpg, 144 - struct se_node_acl *se_nacl, 145 - struct t10_pr_registration *pr_reg, 146 - int *format_code) 147 - { 148 - *format_code = 0; 149 - /* 150 - * The FC Transport ID is a hardcoded 24-byte length 151 - */ 152 - return 24; 153 - } 154 - EXPORT_SYMBOL(fc_get_pr_transport_id_len); 155 - 156 - u32 fc_get_pr_transport_id( 157 - struct se_portal_group *se_tpg, 158 - struct se_node_acl *se_nacl, 159 - struct t10_pr_registration *pr_reg, 160 61 int *format_code, 161 62 unsigned char *buf) 162 63 { ··· 71 160 u32 off = 8; 72 161 73 162 /* 74 - * PROTOCOL IDENTIFIER is 0h for FCP-2 75 - * 76 - * From spc4r17, 7.5.4.2 TransportID for initiator ports using 77 - * SCSI over Fibre Channel 78 - * 79 163 * We convert the ASCII formatted N Port name into a binary 80 164 * encoded TransportID. 81 165 */ 82 166 ptr = &se_nacl->initiatorname[0]; 83 - 84 167 for (i = 0; i < 24; ) { 85 168 if (!strncmp(&ptr[i], ":", 1)) { 86 169 i++; 87 170 continue; 88 171 } 89 172 ret = hex2bin(&buf[off++], &ptr[i], 1); 90 - if (ret < 0) 91 - pr_debug("fc transport_id: invalid hex string\n"); 173 + if (ret < 0) { 174 + pr_debug("%s: invalid hex string\n", __func__); 175 + return ret; 176 + } 92 177 i += 2; 93 178 } 94 179 /* ··· 92 185 */ 93 186 return 24; 94 187 } 95 - EXPORT_SYMBOL(fc_get_pr_transport_id); 96 188 97 - char *fc_parse_pr_out_transport_id( 98 - struct se_portal_group *se_tpg, 99 - const char *buf, 100 - u32 *out_tid_len, 101 - char **port_nexus_ptr) 189 + static int sbp_get_pr_transport_id( 190 + struct se_node_acl *nacl, 191 + int *format_code, 192 + unsigned char *buf) 102 193 { 103 - /* 104 - * The TransportID for a FC N Port is of fixed size of 105 - * 24 bytes, and FC does not contain a I_T nexus identifier, 106 - * so we return the **port_nexus_ptr set to NULL. 107 - */ 108 - *port_nexus_ptr = NULL; 109 - *out_tid_len = 24; 194 + int ret; 110 195 111 - return (char *)&buf[8]; 196 + ret = hex2bin(&buf[8], nacl->initiatorname, 8); 197 + if (ret) { 198 + pr_debug("%s: invalid hex string\n", __func__); 199 + return ret; 200 + } 201 + 202 + return 24; 112 203 } 113 - EXPORT_SYMBOL(fc_parse_pr_out_transport_id); 114 204 115 - /* 116 - * Handlers for Internet Small Computer Systems Interface (iSCSI) 117 - */ 118 - 119 - u8 iscsi_get_fabric_proto_ident(struct se_portal_group *se_tpg) 205 + static int srp_get_pr_transport_id( 206 + struct se_node_acl *nacl, 207 + int *format_code, 208 + unsigned char *buf) 120 209 { 121 - /* 122 - * This value is defined for "Internet SCSI (iSCSI)" 123 - * in spc4r17 section 7.5.1 Table 362 124 - */ 125 - return 0x5; 126 - } 127 - EXPORT_SYMBOL(iscsi_get_fabric_proto_ident); 210 + const char *p; 211 + unsigned len, count, leading_zero_bytes; 212 + int rc; 128 213 129 - u32 iscsi_get_pr_transport_id( 130 - struct se_portal_group *se_tpg, 214 + p = nacl->initiatorname; 215 + if (strncasecmp(p, "0x", 2) == 0) 216 + p += 2; 217 + len = strlen(p); 218 + if (len % 2) 219 + return -EINVAL; 220 + 221 + count = min(len / 2, 16U); 222 + leading_zero_bytes = 16 - count; 223 + memset(buf + 8, 0, leading_zero_bytes); 224 + rc = hex2bin(buf + 8 + leading_zero_bytes, p, count); 225 + if (rc < 0) { 226 + pr_debug("hex2bin failed for %s: %d\n", __func__, rc); 227 + return rc; 228 + } 229 + 230 + return 24; 231 + } 232 + 233 + static int iscsi_get_pr_transport_id( 131 234 struct se_node_acl *se_nacl, 132 235 struct t10_pr_registration *pr_reg, 133 236 int *format_code, ··· 147 230 u16 len = 0; 148 231 149 232 spin_lock_irq(&se_nacl->nacl_sess_lock); 150 - /* 151 - * Set PROTOCOL IDENTIFIER to 5h for iSCSI 152 - */ 153 - buf[0] = 0x05; 154 233 /* 155 234 * From spc4r17 Section 7.5.4.6: TransportID for initiator 156 235 * ports using SCSI over iSCSI. ··· 226 313 227 314 return len; 228 315 } 229 - EXPORT_SYMBOL(iscsi_get_pr_transport_id); 230 316 231 - u32 iscsi_get_pr_transport_id_len( 232 - struct se_portal_group *se_tpg, 317 + static int iscsi_get_pr_transport_id_len( 233 318 struct se_node_acl *se_nacl, 234 319 struct t10_pr_registration *pr_reg, 235 320 int *format_code) ··· 270 359 271 360 return len; 272 361 } 273 - EXPORT_SYMBOL(iscsi_get_pr_transport_id_len); 274 362 275 - char *iscsi_parse_pr_out_transport_id( 363 + static char *iscsi_parse_pr_out_transport_id( 276 364 struct se_portal_group *se_tpg, 277 365 const char *buf, 278 366 u32 *out_tid_len, ··· 358 448 359 449 return (char *)&buf[4]; 360 450 } 361 - EXPORT_SYMBOL(iscsi_parse_pr_out_transport_id); 451 + 452 + int target_get_pr_transport_id_len(struct se_node_acl *nacl, 453 + struct t10_pr_registration *pr_reg, int *format_code) 454 + { 455 + switch (nacl->se_tpg->proto_id) { 456 + case SCSI_PROTOCOL_FCP: 457 + case SCSI_PROTOCOL_SBP: 458 + case SCSI_PROTOCOL_SRP: 459 + case SCSI_PROTOCOL_SAS: 460 + break; 461 + case SCSI_PROTOCOL_ISCSI: 462 + return iscsi_get_pr_transport_id_len(nacl, pr_reg, format_code); 463 + default: 464 + pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id); 465 + return -EINVAL; 466 + } 467 + 468 + /* 469 + * Most transports use a fixed length 24 byte identifier. 470 + */ 471 + *format_code = 0; 472 + return 24; 473 + } 474 + 475 + int target_get_pr_transport_id(struct se_node_acl *nacl, 476 + struct t10_pr_registration *pr_reg, int *format_code, 477 + unsigned char *buf) 478 + { 479 + switch (nacl->se_tpg->proto_id) { 480 + case SCSI_PROTOCOL_SAS: 481 + return sas_get_pr_transport_id(nacl, format_code, buf); 482 + case SCSI_PROTOCOL_SBP: 483 + return sbp_get_pr_transport_id(nacl, format_code, buf); 484 + case SCSI_PROTOCOL_SRP: 485 + return srp_get_pr_transport_id(nacl, format_code, buf); 486 + case SCSI_PROTOCOL_FCP: 487 + return fc_get_pr_transport_id(nacl, format_code, buf); 488 + case SCSI_PROTOCOL_ISCSI: 489 + return iscsi_get_pr_transport_id(nacl, pr_reg, format_code, 490 + buf); 491 + default: 492 + pr_err("Unknown proto_id: 0x%02x\n", nacl->se_tpg->proto_id); 493 + return -EINVAL; 494 + } 495 + } 496 + 497 + const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, 498 + const char *buf, u32 *out_tid_len, char **port_nexus_ptr) 499 + { 500 + u32 offset; 501 + 502 + switch (tpg->proto_id) { 503 + case SCSI_PROTOCOL_SAS: 504 + /* 505 + * Assume the FORMAT CODE 00b from spc4r17, 7.5.4.7 TransportID 506 + * for initiator ports using SCSI over SAS Serial SCSI Protocol. 507 + */ 508 + offset = 4; 509 + break; 510 + case SCSI_PROTOCOL_SBP: 511 + case SCSI_PROTOCOL_SRP: 512 + case SCSI_PROTOCOL_FCP: 513 + offset = 8; 514 + break; 515 + case SCSI_PROTOCOL_ISCSI: 516 + return iscsi_parse_pr_out_transport_id(tpg, buf, out_tid_len, 517 + port_nexus_ptr); 518 + default: 519 + pr_err("Unknown proto_id: 0x%02x\n", tpg->proto_id); 520 + return NULL; 521 + } 522 + 523 + *port_nexus_ptr = NULL; 524 + *out_tid_len = 24; 525 + return buf + offset; 526 + }
+48 -189
drivers/target/target_core_file.c
··· 37 37 38 38 #include <target/target_core_base.h> 39 39 #include <target/target_core_backend.h> 40 - #include <target/target_core_backend_configfs.h> 41 40 42 41 #include "target_core_file.h" 43 42 ··· 45 46 return container_of(dev, struct fd_dev, dev); 46 47 } 47 48 48 - /* fd_attach_hba(): (Part of se_subsystem_api_t template) 49 - * 50 - * 51 - */ 52 49 static int fd_attach_hba(struct se_hba *hba, u32 host_id) 53 50 { 54 51 struct fd_host *fd_host; ··· 61 66 62 67 pr_debug("CORE_HBA[%d] - TCM FILEIO HBA Driver %s on Generic" 63 68 " Target Core Stack %s\n", hba->hba_id, FD_VERSION, 64 - TARGET_CORE_MOD_VERSION); 69 + TARGET_CORE_VERSION); 65 70 pr_debug("CORE_HBA[%d] - Attached FILEIO HBA: %u to Generic\n", 66 71 hba->hba_id, fd_host->fd_host_id); 67 72 ··· 241 246 return ret; 242 247 } 243 248 249 + static void fd_dev_call_rcu(struct rcu_head *p) 250 + { 251 + struct se_device *dev = container_of(p, struct se_device, rcu_head); 252 + struct fd_dev *fd_dev = FD_DEV(dev); 253 + 254 + kfree(fd_dev); 255 + } 256 + 244 257 static void fd_free_device(struct se_device *dev) 245 258 { 246 259 struct fd_dev *fd_dev = FD_DEV(dev); ··· 257 254 filp_close(fd_dev->fd_file, NULL); 258 255 fd_dev->fd_file = NULL; 259 256 } 260 - 261 - kfree(fd_dev); 257 + call_rcu(&dev->rcu_head, fd_dev_call_rcu); 262 258 } 263 259 264 - static int fd_do_prot_rw(struct se_cmd *cmd, struct fd_prot *fd_prot, 265 - int is_write) 260 + static int fd_do_rw(struct se_cmd *cmd, struct file *fd, 261 + u32 block_size, struct scatterlist *sgl, 262 + u32 sgl_nents, u32 data_length, int is_write) 266 263 { 267 - struct se_device *se_dev = cmd->se_dev; 268 - struct fd_dev *dev = FD_DEV(se_dev); 269 - struct file *prot_fd = dev->fd_prot_file; 270 - loff_t pos = (cmd->t_task_lba * se_dev->prot_length); 271 - unsigned char *buf; 272 - u32 prot_size; 273 - int rc, ret = 1; 274 - 275 - prot_size = (cmd->data_length / se_dev->dev_attrib.block_size) * 276 - se_dev->prot_length; 277 - 278 - if (!is_write) { 279 - fd_prot->prot_buf = kzalloc(prot_size, GFP_KERNEL); 280 - if (!fd_prot->prot_buf) { 281 - pr_err("Unable to allocate fd_prot->prot_buf\n"); 282 - return -ENOMEM; 283 - } 284 - buf = fd_prot->prot_buf; 285 - 286 - fd_prot->prot_sg_nents = 1; 287 - fd_prot->prot_sg = kzalloc(sizeof(struct scatterlist), 288 - GFP_KERNEL); 289 - if (!fd_prot->prot_sg) { 290 - pr_err("Unable to allocate fd_prot->prot_sg\n"); 291 - kfree(fd_prot->prot_buf); 292 - return -ENOMEM; 293 - } 294 - sg_init_table(fd_prot->prot_sg, fd_prot->prot_sg_nents); 295 - sg_set_buf(fd_prot->prot_sg, buf, prot_size); 296 - } 297 - 298 - if (is_write) { 299 - rc = kernel_write(prot_fd, fd_prot->prot_buf, prot_size, pos); 300 - if (rc < 0 || prot_size != rc) { 301 - pr_err("kernel_write() for fd_do_prot_rw failed:" 302 - " %d\n", rc); 303 - ret = -EINVAL; 304 - } 305 - } else { 306 - rc = kernel_read(prot_fd, pos, fd_prot->prot_buf, prot_size); 307 - if (rc < 0) { 308 - pr_err("kernel_read() for fd_do_prot_rw failed:" 309 - " %d\n", rc); 310 - ret = -EINVAL; 311 - } 312 - } 313 - 314 - if (is_write || ret < 0) { 315 - kfree(fd_prot->prot_sg); 316 - kfree(fd_prot->prot_buf); 317 - } 318 - 319 - return ret; 320 - } 321 - 322 - static int fd_do_rw(struct se_cmd *cmd, struct scatterlist *sgl, 323 - u32 sgl_nents, int is_write) 324 - { 325 - struct se_device *se_dev = cmd->se_dev; 326 - struct fd_dev *dev = FD_DEV(se_dev); 327 - struct file *fd = dev->fd_file; 328 264 struct scatterlist *sg; 329 265 struct iov_iter iter; 330 266 struct bio_vec *bvec; 331 267 ssize_t len = 0; 332 - loff_t pos = (cmd->t_task_lba * se_dev->dev_attrib.block_size); 268 + loff_t pos = (cmd->t_task_lba * block_size); 333 269 int ret = 0, i; 334 270 335 271 bvec = kcalloc(sgl_nents, sizeof(struct bio_vec), GFP_KERNEL); ··· 294 352 kfree(bvec); 295 353 296 354 if (is_write) { 297 - if (ret < 0 || ret != cmd->data_length) { 355 + if (ret < 0 || ret != data_length) { 298 356 pr_err("%s() write returned %d\n", __func__, ret); 299 357 return (ret < 0 ? ret : -EINVAL); 300 358 } ··· 305 363 * block_device. 306 364 */ 307 365 if (S_ISBLK(file_inode(fd)->i_mode)) { 308 - if (ret < 0 || ret != cmd->data_length) { 366 + if (ret < 0 || ret != data_length) { 309 367 pr_err("%s() returned %d, expecting %u for " 310 368 "S_ISBLK\n", __func__, ret, 311 - cmd->data_length); 369 + data_length); 312 370 return (ret < 0 ? ret : -EINVAL); 313 371 } 314 372 } else { ··· 475 533 } 476 534 477 535 static sense_reason_t 478 - fd_do_unmap(struct se_cmd *cmd, void *priv, sector_t lba, sector_t nolb) 536 + fd_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb) 479 537 { 480 - struct file *file = priv; 538 + struct file *file = FD_DEV(cmd->se_dev)->fd_file; 481 539 struct inode *inode = file->f_mapping->host; 482 540 int ret; 483 541 ··· 519 577 } 520 578 521 579 static sense_reason_t 522 - fd_execute_write_same_unmap(struct se_cmd *cmd) 523 - { 524 - struct se_device *se_dev = cmd->se_dev; 525 - struct fd_dev *fd_dev = FD_DEV(se_dev); 526 - struct file *file = fd_dev->fd_file; 527 - sector_t lba = cmd->t_task_lba; 528 - sector_t nolb = sbc_get_write_same_sectors(cmd); 529 - sense_reason_t ret; 530 - 531 - if (!nolb) { 532 - target_complete_cmd(cmd, SAM_STAT_GOOD); 533 - return 0; 534 - } 535 - 536 - ret = fd_do_unmap(cmd, file, lba, nolb); 537 - if (ret) 538 - return ret; 539 - 540 - target_complete_cmd(cmd, GOOD); 541 - return 0; 542 - } 543 - 544 - static sense_reason_t 545 - fd_execute_unmap(struct se_cmd *cmd) 546 - { 547 - struct file *file = FD_DEV(cmd->se_dev)->fd_file; 548 - 549 - return sbc_execute_unmap(cmd, fd_do_unmap, file); 550 - } 551 - 552 - static sense_reason_t 553 580 fd_execute_rw(struct se_cmd *cmd, struct scatterlist *sgl, u32 sgl_nents, 554 581 enum dma_data_direction data_direction) 555 582 { 556 583 struct se_device *dev = cmd->se_dev; 557 - struct fd_prot fd_prot; 584 + struct fd_dev *fd_dev = FD_DEV(dev); 585 + struct file *file = fd_dev->fd_file; 586 + struct file *pfile = fd_dev->fd_prot_file; 558 587 sense_reason_t rc; 559 588 int ret = 0; 560 589 /* ··· 543 630 * physical memory addresses to struct iovec virtual memory. 544 631 */ 545 632 if (data_direction == DMA_FROM_DEVICE) { 546 - memset(&fd_prot, 0, sizeof(struct fd_prot)); 547 - 548 633 if (cmd->prot_type && dev->dev_attrib.pi_prot_type) { 549 - ret = fd_do_prot_rw(cmd, &fd_prot, false); 634 + ret = fd_do_rw(cmd, pfile, dev->prot_length, 635 + cmd->t_prot_sg, cmd->t_prot_nents, 636 + cmd->prot_length, 0); 550 637 if (ret < 0) 551 638 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 552 639 } 553 640 554 - ret = fd_do_rw(cmd, sgl, sgl_nents, 0); 641 + ret = fd_do_rw(cmd, file, dev->dev_attrib.block_size, 642 + sgl, sgl_nents, cmd->data_length, 0); 555 643 556 644 if (ret > 0 && cmd->prot_type && dev->dev_attrib.pi_prot_type) { 557 - u32 sectors = cmd->data_length / dev->dev_attrib.block_size; 645 + u32 sectors = cmd->data_length >> 646 + ilog2(dev->dev_attrib.block_size); 558 647 559 - rc = sbc_dif_verify_read(cmd, cmd->t_task_lba, sectors, 560 - 0, fd_prot.prot_sg, 0); 561 - if (rc) { 562 - kfree(fd_prot.prot_sg); 563 - kfree(fd_prot.prot_buf); 648 + rc = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 649 + 0, cmd->t_prot_sg, 0); 650 + if (rc) 564 651 return rc; 565 - } 566 - kfree(fd_prot.prot_sg); 567 - kfree(fd_prot.prot_buf); 568 652 } 569 653 } else { 570 - memset(&fd_prot, 0, sizeof(struct fd_prot)); 571 - 572 654 if (cmd->prot_type && dev->dev_attrib.pi_prot_type) { 573 - u32 sectors = cmd->data_length / dev->dev_attrib.block_size; 655 + u32 sectors = cmd->data_length >> 656 + ilog2(dev->dev_attrib.block_size); 574 657 575 - ret = fd_do_prot_rw(cmd, &fd_prot, false); 576 - if (ret < 0) 577 - return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 578 - 579 - rc = sbc_dif_verify_write(cmd, cmd->t_task_lba, sectors, 580 - 0, fd_prot.prot_sg, 0); 581 - if (rc) { 582 - kfree(fd_prot.prot_sg); 583 - kfree(fd_prot.prot_buf); 658 + rc = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 659 + 0, cmd->t_prot_sg, 0); 660 + if (rc) 584 661 return rc; 585 - } 586 662 } 587 663 588 - ret = fd_do_rw(cmd, sgl, sgl_nents, 1); 664 + ret = fd_do_rw(cmd, file, dev->dev_attrib.block_size, 665 + sgl, sgl_nents, cmd->data_length, 1); 589 666 /* 590 667 * Perform implicit vfs_fsync_range() for fd_do_writev() ops 591 668 * for SCSI WRITEs with Forced Unit Access (FUA) set. 592 669 * Allow this to happen independent of WCE=0 setting. 593 670 */ 594 - if (ret > 0 && 595 - dev->dev_attrib.emulate_fua_write > 0 && 596 - (cmd->se_cmd_flags & SCF_FUA)) { 597 - struct fd_dev *fd_dev = FD_DEV(dev); 671 + if (ret > 0 && (cmd->se_cmd_flags & SCF_FUA)) { 598 672 loff_t start = cmd->t_task_lba * 599 673 dev->dev_attrib.block_size; 600 674 loff_t end; ··· 595 695 } 596 696 597 697 if (ret > 0 && cmd->prot_type && dev->dev_attrib.pi_prot_type) { 598 - ret = fd_do_prot_rw(cmd, &fd_prot, true); 698 + ret = fd_do_rw(cmd, pfile, dev->prot_length, 699 + cmd->t_prot_sg, cmd->t_prot_nents, 700 + cmd->prot_length, 1); 599 701 if (ret < 0) 600 702 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 601 703 } 602 704 } 603 705 604 - if (ret < 0) { 605 - kfree(fd_prot.prot_sg); 606 - kfree(fd_prot.prot_buf); 706 + if (ret < 0) 607 707 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 608 - } 609 708 610 709 if (ret) 611 710 target_complete_cmd(cmd, SAM_STAT_GOOD); ··· 807 908 .execute_rw = fd_execute_rw, 808 909 .execute_sync_cache = fd_execute_sync_cache, 809 910 .execute_write_same = fd_execute_write_same, 810 - .execute_write_same_unmap = fd_execute_write_same_unmap, 811 911 .execute_unmap = fd_execute_unmap, 812 912 }; 813 913 ··· 816 918 return sbc_parse_cdb(cmd, &fd_sbc_ops); 817 919 } 818 920 819 - DEF_TB_DEFAULT_ATTRIBS(fileio); 820 - 821 - static struct configfs_attribute *fileio_backend_dev_attrs[] = { 822 - &fileio_dev_attrib_emulate_model_alias.attr, 823 - &fileio_dev_attrib_emulate_dpo.attr, 824 - &fileio_dev_attrib_emulate_fua_write.attr, 825 - &fileio_dev_attrib_emulate_fua_read.attr, 826 - &fileio_dev_attrib_emulate_write_cache.attr, 827 - &fileio_dev_attrib_emulate_ua_intlck_ctrl.attr, 828 - &fileio_dev_attrib_emulate_tas.attr, 829 - &fileio_dev_attrib_emulate_tpu.attr, 830 - &fileio_dev_attrib_emulate_tpws.attr, 831 - &fileio_dev_attrib_emulate_caw.attr, 832 - &fileio_dev_attrib_emulate_3pc.attr, 833 - &fileio_dev_attrib_pi_prot_type.attr, 834 - &fileio_dev_attrib_hw_pi_prot_type.attr, 835 - &fileio_dev_attrib_pi_prot_format.attr, 836 - &fileio_dev_attrib_enforce_pr_isids.attr, 837 - &fileio_dev_attrib_is_nonrot.attr, 838 - &fileio_dev_attrib_emulate_rest_reord.attr, 839 - &fileio_dev_attrib_force_pr_aptpl.attr, 840 - &fileio_dev_attrib_hw_block_size.attr, 841 - &fileio_dev_attrib_block_size.attr, 842 - &fileio_dev_attrib_hw_max_sectors.attr, 843 - &fileio_dev_attrib_optimal_sectors.attr, 844 - &fileio_dev_attrib_hw_queue_depth.attr, 845 - &fileio_dev_attrib_queue_depth.attr, 846 - &fileio_dev_attrib_max_unmap_lba_count.attr, 847 - &fileio_dev_attrib_max_unmap_block_desc_count.attr, 848 - &fileio_dev_attrib_unmap_granularity.attr, 849 - &fileio_dev_attrib_unmap_granularity_alignment.attr, 850 - &fileio_dev_attrib_max_write_same_len.attr, 851 - NULL, 852 - }; 853 - 854 - static struct se_subsystem_api fileio_template = { 921 + static const struct target_backend_ops fileio_ops = { 855 922 .name = "fileio", 856 923 .inquiry_prod = "FILEIO", 857 924 .inquiry_rev = FD_VERSION, ··· 834 971 .init_prot = fd_init_prot, 835 972 .format_prot = fd_format_prot, 836 973 .free_prot = fd_free_prot, 974 + .tb_dev_attrib_attrs = sbc_attrib_attrs, 837 975 }; 838 976 839 977 static int __init fileio_module_init(void) 840 978 { 841 - struct target_backend_cits *tbc = &fileio_template.tb_cits; 842 - 843 - target_core_setup_sub_cits(&fileio_template); 844 - tbc->tb_dev_attrib_cit.ct_attrs = fileio_backend_dev_attrs; 845 - 846 - return transport_subsystem_register(&fileio_template); 979 + return transport_backend_register(&fileio_ops); 847 980 } 848 981 849 982 static void __exit fileio_module_exit(void) 850 983 { 851 - transport_subsystem_release(&fileio_template); 984 + target_backend_unregister(&fileio_ops); 852 985 } 853 986 854 987 MODULE_DESCRIPTION("TCM FILEIO subsystem plugin");
-6
drivers/target/target_core_file.h
··· 21 21 #define FDBD_HAS_BUFFERED_IO_WCE 0x04 22 22 #define FDBD_FORMAT_UNIT_SIZE 2048 23 23 24 - struct fd_prot { 25 - unsigned char *prot_buf; 26 - struct scatterlist *prot_sg; 27 - u32 prot_sg_nents; 28 - }; 29 - 30 24 struct fd_dev { 31 25 struct se_device dev; 32 26
+52 -41
drivers/target/target_core_hba.c
··· 36 36 #include <target/target_core_base.h> 37 37 #include <target/target_core_backend.h> 38 38 #include <target/target_core_fabric.h> 39 - #include <target/target_core_configfs.h> 40 39 41 40 #include "target_core_internal.h" 42 41 43 - static LIST_HEAD(subsystem_list); 44 - static DEFINE_MUTEX(subsystem_mutex); 42 + static LIST_HEAD(backend_list); 43 + static DEFINE_MUTEX(backend_mutex); 45 44 46 45 static u32 hba_id_counter; 47 46 48 47 static DEFINE_SPINLOCK(hba_lock); 49 48 static LIST_HEAD(hba_list); 50 49 51 - int transport_subsystem_register(struct se_subsystem_api *sub_api) 50 + 51 + int transport_backend_register(const struct target_backend_ops *ops) 52 52 { 53 - struct se_subsystem_api *s; 53 + struct target_backend *tb, *old; 54 54 55 - INIT_LIST_HEAD(&sub_api->sub_api_list); 55 + tb = kzalloc(sizeof(*tb), GFP_KERNEL); 56 + if (!tb) 57 + return -ENOMEM; 58 + tb->ops = ops; 56 59 57 - mutex_lock(&subsystem_mutex); 58 - list_for_each_entry(s, &subsystem_list, sub_api_list) { 59 - if (!strcmp(s->name, sub_api->name)) { 60 - pr_err("%p is already registered with" 61 - " duplicate name %s, unable to process" 62 - " request\n", s, s->name); 63 - mutex_unlock(&subsystem_mutex); 60 + mutex_lock(&backend_mutex); 61 + list_for_each_entry(old, &backend_list, list) { 62 + if (!strcmp(old->ops->name, ops->name)) { 63 + pr_err("backend %s already registered.\n", ops->name); 64 + mutex_unlock(&backend_mutex); 65 + kfree(tb); 64 66 return -EEXIST; 65 67 } 66 68 } 67 - list_add_tail(&sub_api->sub_api_list, &subsystem_list); 68 - mutex_unlock(&subsystem_mutex); 69 + target_setup_backend_cits(tb); 70 + list_add_tail(&tb->list, &backend_list); 71 + mutex_unlock(&backend_mutex); 69 72 70 - pr_debug("TCM: Registered subsystem plugin: %s struct module:" 71 - " %p\n", sub_api->name, sub_api->owner); 73 + pr_debug("TCM: Registered subsystem plugin: %s struct module: %p\n", 74 + ops->name, ops->owner); 72 75 return 0; 73 76 } 74 - EXPORT_SYMBOL(transport_subsystem_register); 77 + EXPORT_SYMBOL(transport_backend_register); 75 78 76 - void transport_subsystem_release(struct se_subsystem_api *sub_api) 79 + void target_backend_unregister(const struct target_backend_ops *ops) 77 80 { 78 - mutex_lock(&subsystem_mutex); 79 - list_del(&sub_api->sub_api_list); 80 - mutex_unlock(&subsystem_mutex); 81 + struct target_backend *tb; 82 + 83 + mutex_lock(&backend_mutex); 84 + list_for_each_entry(tb, &backend_list, list) { 85 + if (tb->ops == ops) { 86 + list_del(&tb->list); 87 + kfree(tb); 88 + break; 89 + } 90 + } 91 + mutex_unlock(&backend_mutex); 81 92 } 82 - EXPORT_SYMBOL(transport_subsystem_release); 93 + EXPORT_SYMBOL(target_backend_unregister); 83 94 84 - static struct se_subsystem_api *core_get_backend(const char *sub_name) 95 + static struct target_backend *core_get_backend(const char *name) 85 96 { 86 - struct se_subsystem_api *s; 97 + struct target_backend *tb; 87 98 88 - mutex_lock(&subsystem_mutex); 89 - list_for_each_entry(s, &subsystem_list, sub_api_list) { 90 - if (!strcmp(s->name, sub_name)) 99 + mutex_lock(&backend_mutex); 100 + list_for_each_entry(tb, &backend_list, list) { 101 + if (!strcmp(tb->ops->name, name)) 91 102 goto found; 92 103 } 93 - mutex_unlock(&subsystem_mutex); 104 + mutex_unlock(&backend_mutex); 94 105 return NULL; 95 106 found: 96 - if (s->owner && !try_module_get(s->owner)) 97 - s = NULL; 98 - mutex_unlock(&subsystem_mutex); 99 - return s; 107 + if (tb->ops->owner && !try_module_get(tb->ops->owner)) 108 + tb = NULL; 109 + mutex_unlock(&backend_mutex); 110 + return tb; 100 111 } 101 112 102 113 struct se_hba * ··· 128 117 hba->hba_index = scsi_get_new_index(SCSI_INST_INDEX); 129 118 hba->hba_flags |= hba_flags; 130 119 131 - hba->transport = core_get_backend(plugin_name); 132 - if (!hba->transport) { 120 + hba->backend = core_get_backend(plugin_name); 121 + if (!hba->backend) { 133 122 ret = -EINVAL; 134 123 goto out_free_hba; 135 124 } 136 125 137 - ret = hba->transport->attach_hba(hba, plugin_dep_id); 126 + ret = hba->backend->ops->attach_hba(hba, plugin_dep_id); 138 127 if (ret < 0) 139 128 goto out_module_put; 140 129 ··· 149 138 return hba; 150 139 151 140 out_module_put: 152 - module_put(hba->transport->owner); 153 - hba->transport = NULL; 141 + module_put(hba->backend->ops->owner); 142 + hba->backend = NULL; 154 143 out_free_hba: 155 144 kfree(hba); 156 145 return ERR_PTR(ret); ··· 161 150 { 162 151 WARN_ON(hba->dev_count); 163 152 164 - hba->transport->detach_hba(hba); 153 + hba->backend->ops->detach_hba(hba); 165 154 166 155 spin_lock(&hba_lock); 167 156 list_del(&hba->hba_node); ··· 170 159 pr_debug("CORE_HBA[%d] - Detached HBA from Generic Target" 171 160 " Core\n", hba->hba_id); 172 161 173 - module_put(hba->transport->owner); 162 + module_put(hba->backend->ops->owner); 174 163 175 - hba->transport = NULL; 164 + hba->backend = NULL; 176 165 kfree(hba); 177 166 return 0; 178 167 }
+16 -80
drivers/target/target_core_iblock.c
··· 40 40 41 41 #include <target/target_core_base.h> 42 42 #include <target/target_core_backend.h> 43 - #include <target/target_core_backend_configfs.h> 44 43 45 44 #include "target_core_iblock.h" 46 45 ··· 52 53 } 53 54 54 55 55 - static struct se_subsystem_api iblock_template; 56 - 57 - /* iblock_attach_hba(): (Part of se_subsystem_api_t template) 58 - * 59 - * 60 - */ 61 56 static int iblock_attach_hba(struct se_hba *hba, u32 host_id) 62 57 { 63 58 pr_debug("CORE_HBA[%d] - TCM iBlock HBA Driver %s on" 64 59 " Generic Target Core Stack %s\n", hba->hba_id, 65 - IBLOCK_VERSION, TARGET_CORE_MOD_VERSION); 60 + IBLOCK_VERSION, TARGET_CORE_VERSION); 66 61 return 0; 67 62 } 68 63 ··· 190 197 return ret; 191 198 } 192 199 200 + static void iblock_dev_call_rcu(struct rcu_head *p) 201 + { 202 + struct se_device *dev = container_of(p, struct se_device, rcu_head); 203 + struct iblock_dev *ib_dev = IBLOCK_DEV(dev); 204 + 205 + kfree(ib_dev); 206 + } 207 + 193 208 static void iblock_free_device(struct se_device *dev) 194 209 { 195 210 struct iblock_dev *ib_dev = IBLOCK_DEV(dev); ··· 207 206 if (ib_dev->ibd_bio_set != NULL) 208 207 bioset_free(ib_dev->ibd_bio_set); 209 208 210 - kfree(ib_dev); 209 + call_rcu(&dev->rcu_head, iblock_dev_call_rcu); 211 210 } 212 211 213 212 static unsigned long long iblock_emulate_read_cap_with_block_size( ··· 415 414 } 416 415 417 416 static sense_reason_t 418 - iblock_do_unmap(struct se_cmd *cmd, void *priv, 419 - sector_t lba, sector_t nolb) 417 + iblock_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb) 420 418 { 421 - struct block_device *bdev = priv; 419 + struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd; 422 420 int ret; 423 421 424 422 ret = blkdev_issue_discard(bdev, lba, nolb, GFP_KERNEL, 0); ··· 426 426 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 427 427 } 428 428 429 - return 0; 430 - } 431 - 432 - static sense_reason_t 433 - iblock_execute_unmap(struct se_cmd *cmd) 434 - { 435 - struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd; 436 - 437 - return sbc_execute_unmap(cmd, iblock_do_unmap, bdev); 438 - } 439 - 440 - static sense_reason_t 441 - iblock_execute_write_same_unmap(struct se_cmd *cmd) 442 - { 443 - struct block_device *bdev = IBLOCK_DEV(cmd->se_dev)->ibd_bd; 444 - sector_t lba = cmd->t_task_lba; 445 - sector_t nolb = sbc_get_write_same_sectors(cmd); 446 - sense_reason_t ret; 447 - 448 - ret = iblock_do_unmap(cmd, bdev, lba, nolb); 449 - if (ret) 450 - return ret; 451 - 452 - target_complete_cmd(cmd, GOOD); 453 429 return 0; 454 430 } 455 431 ··· 820 844 .execute_rw = iblock_execute_rw, 821 845 .execute_sync_cache = iblock_execute_sync_cache, 822 846 .execute_write_same = iblock_execute_write_same, 823 - .execute_write_same_unmap = iblock_execute_write_same_unmap, 824 847 .execute_unmap = iblock_execute_unmap, 825 848 }; 826 849 ··· 838 863 return q->flush_flags & REQ_FLUSH; 839 864 } 840 865 841 - DEF_TB_DEFAULT_ATTRIBS(iblock); 842 - 843 - static struct configfs_attribute *iblock_backend_dev_attrs[] = { 844 - &iblock_dev_attrib_emulate_model_alias.attr, 845 - &iblock_dev_attrib_emulate_dpo.attr, 846 - &iblock_dev_attrib_emulate_fua_write.attr, 847 - &iblock_dev_attrib_emulate_fua_read.attr, 848 - &iblock_dev_attrib_emulate_write_cache.attr, 849 - &iblock_dev_attrib_emulate_ua_intlck_ctrl.attr, 850 - &iblock_dev_attrib_emulate_tas.attr, 851 - &iblock_dev_attrib_emulate_tpu.attr, 852 - &iblock_dev_attrib_emulate_tpws.attr, 853 - &iblock_dev_attrib_emulate_caw.attr, 854 - &iblock_dev_attrib_emulate_3pc.attr, 855 - &iblock_dev_attrib_pi_prot_type.attr, 856 - &iblock_dev_attrib_hw_pi_prot_type.attr, 857 - &iblock_dev_attrib_pi_prot_format.attr, 858 - &iblock_dev_attrib_enforce_pr_isids.attr, 859 - &iblock_dev_attrib_is_nonrot.attr, 860 - &iblock_dev_attrib_emulate_rest_reord.attr, 861 - &iblock_dev_attrib_force_pr_aptpl.attr, 862 - &iblock_dev_attrib_hw_block_size.attr, 863 - &iblock_dev_attrib_block_size.attr, 864 - &iblock_dev_attrib_hw_max_sectors.attr, 865 - &iblock_dev_attrib_optimal_sectors.attr, 866 - &iblock_dev_attrib_hw_queue_depth.attr, 867 - &iblock_dev_attrib_queue_depth.attr, 868 - &iblock_dev_attrib_max_unmap_lba_count.attr, 869 - &iblock_dev_attrib_max_unmap_block_desc_count.attr, 870 - &iblock_dev_attrib_unmap_granularity.attr, 871 - &iblock_dev_attrib_unmap_granularity_alignment.attr, 872 - &iblock_dev_attrib_max_write_same_len.attr, 873 - NULL, 874 - }; 875 - 876 - static struct se_subsystem_api iblock_template = { 866 + static const struct target_backend_ops iblock_ops = { 877 867 .name = "iblock", 878 868 .inquiry_prod = "IBLOCK", 879 869 .inquiry_rev = IBLOCK_VERSION, ··· 858 918 .get_io_min = iblock_get_io_min, 859 919 .get_io_opt = iblock_get_io_opt, 860 920 .get_write_cache = iblock_get_write_cache, 921 + .tb_dev_attrib_attrs = sbc_attrib_attrs, 861 922 }; 862 923 863 924 static int __init iblock_module_init(void) 864 925 { 865 - struct target_backend_cits *tbc = &iblock_template.tb_cits; 866 - 867 - target_core_setup_sub_cits(&iblock_template); 868 - tbc->tb_dev_attrib_cit.ct_attrs = iblock_backend_dev_attrs; 869 - 870 - return transport_subsystem_register(&iblock_template); 926 + return transport_backend_register(&iblock_ops); 871 927 } 872 928 873 929 static void __exit iblock_module_exit(void) 874 930 { 875 - transport_subsystem_release(&iblock_template); 931 + target_backend_unregister(&iblock_ops); 876 932 } 877 933 878 934 MODULE_DESCRIPTION("TCM IBLOCK subsystem plugin");
+85 -18
drivers/target/target_core_internal.h
··· 1 1 #ifndef TARGET_CORE_INTERNAL_H 2 2 #define TARGET_CORE_INTERNAL_H 3 3 4 + #define TARGET_CORE_NAME_MAX_LEN 64 5 + #define TARGET_FABRIC_NAME_SIZE 32 6 + 7 + struct target_backend { 8 + struct list_head list; 9 + 10 + const struct target_backend_ops *ops; 11 + 12 + struct config_item_type tb_dev_cit; 13 + struct config_item_type tb_dev_attrib_cit; 14 + struct config_item_type tb_dev_pr_cit; 15 + struct config_item_type tb_dev_wwn_cit; 16 + struct config_item_type tb_dev_alua_tg_pt_gps_cit; 17 + struct config_item_type tb_dev_stat_cit; 18 + }; 19 + 20 + struct target_fabric_configfs { 21 + atomic_t tf_access_cnt; 22 + struct list_head tf_list; 23 + struct config_group tf_group; 24 + struct config_group tf_disc_group; 25 + struct config_group *tf_default_groups[2]; 26 + const struct target_core_fabric_ops *tf_ops; 27 + 28 + struct config_item_type tf_discovery_cit; 29 + struct config_item_type tf_wwn_cit; 30 + struct config_item_type tf_wwn_fabric_stats_cit; 31 + struct config_item_type tf_tpg_cit; 32 + struct config_item_type tf_tpg_base_cit; 33 + struct config_item_type tf_tpg_lun_cit; 34 + struct config_item_type tf_tpg_port_cit; 35 + struct config_item_type tf_tpg_port_stat_cit; 36 + struct config_item_type tf_tpg_np_cit; 37 + struct config_item_type tf_tpg_np_base_cit; 38 + struct config_item_type tf_tpg_attrib_cit; 39 + struct config_item_type tf_tpg_auth_cit; 40 + struct config_item_type tf_tpg_param_cit; 41 + struct config_item_type tf_tpg_nacl_cit; 42 + struct config_item_type tf_tpg_nacl_base_cit; 43 + struct config_item_type tf_tpg_nacl_attrib_cit; 44 + struct config_item_type tf_tpg_nacl_auth_cit; 45 + struct config_item_type tf_tpg_nacl_param_cit; 46 + struct config_item_type tf_tpg_nacl_stat_cit; 47 + struct config_item_type tf_tpg_mappedlun_cit; 48 + struct config_item_type tf_tpg_mappedlun_stat_cit; 49 + }; 50 + 4 51 /* target_core_alua.c */ 5 52 extern struct t10_alua_lu_gp *default_lu_gp; 6 53 ··· 55 8 extern struct mutex g_device_mutex; 56 9 extern struct list_head g_device_list; 57 10 11 + int core_alloc_rtpi(struct se_lun *lun, struct se_device *dev); 58 12 struct se_dev_entry *core_get_se_deve_from_rtpi(struct se_node_acl *, u16); 59 - int core_free_device_list_for_node(struct se_node_acl *, 13 + void target_pr_kref_release(struct kref *); 14 + void core_free_device_list_for_node(struct se_node_acl *, 60 15 struct se_portal_group *); 61 - void core_update_device_list_access(u32, u32, struct se_node_acl *); 16 + void core_update_device_list_access(u64, u32, struct se_node_acl *); 17 + struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *, u64); 62 18 int core_enable_device_list_for_node(struct se_lun *, struct se_lun_acl *, 63 - u32, u32, struct se_node_acl *, struct se_portal_group *); 64 - int core_disable_device_list_for_node(struct se_lun *, struct se_lun_acl *, 65 - u32, u32, struct se_node_acl *, struct se_portal_group *); 19 + u64, u32, struct se_node_acl *, struct se_portal_group *); 20 + void core_disable_device_list_for_node(struct se_lun *, struct se_dev_entry *, 21 + struct se_node_acl *, struct se_portal_group *); 66 22 void core_clear_lun_from_tpg(struct se_lun *, struct se_portal_group *); 67 - int core_dev_export(struct se_device *, struct se_portal_group *, 68 - struct se_lun *); 69 - void core_dev_unexport(struct se_device *, struct se_portal_group *, 70 - struct se_lun *); 71 - struct se_lun *core_dev_add_lun(struct se_portal_group *, struct se_device *, u32); 23 + int core_dev_add_lun(struct se_portal_group *, struct se_device *, 24 + struct se_lun *lun); 72 25 void core_dev_del_lun(struct se_portal_group *, struct se_lun *); 73 - struct se_lun *core_get_lun_from_tpg(struct se_portal_group *, u32); 74 26 struct se_lun_acl *core_dev_init_initiator_node_lun_acl(struct se_portal_group *, 75 - struct se_node_acl *, u32, int *); 27 + struct se_node_acl *, u64, int *); 76 28 int core_dev_add_initiator_node_lun_acl(struct se_portal_group *, 77 - struct se_lun_acl *, u32, u32); 78 - int core_dev_del_initiator_node_lun_acl(struct se_portal_group *, 79 - struct se_lun *, struct se_lun_acl *); 29 + struct se_lun_acl *, struct se_lun *lun, u32); 30 + int core_dev_del_initiator_node_lun_acl(struct se_lun *, 31 + struct se_lun_acl *); 80 32 void core_dev_free_initiator_node_lun_acl(struct se_portal_group *, 81 33 struct se_lun_acl *lacl); 82 34 int core_dev_setup_virtual_lun0(void); ··· 83 37 struct se_device *target_alloc_device(struct se_hba *hba, const char *name); 84 38 int target_configure_device(struct se_device *dev); 85 39 void target_free_device(struct se_device *); 40 + 41 + /* target_core_configfs.c */ 42 + void target_setup_backend_cits(struct target_backend *); 43 + 44 + /* target_core_fabric_lib.c */ 45 + int target_get_pr_transport_id_len(struct se_node_acl *nacl, 46 + struct t10_pr_registration *pr_reg, int *format_code); 47 + int target_get_pr_transport_id(struct se_node_acl *nacl, 48 + struct t10_pr_registration *pr_reg, int *format_code, 49 + unsigned char *buf); 50 + const char *target_parse_pr_out_transport_id(struct se_portal_group *tpg, 51 + const char *buf, u32 *out_tid_len, char **port_nexus_ptr); 86 52 87 53 /* target_core_hba.c */ 88 54 struct se_hba *core_alloc_hba(const char *, u32, u32); ··· 111 53 112 54 struct se_node_acl *__core_tpg_get_initiator_node_acl(struct se_portal_group *tpg, 113 55 const char *); 114 - void core_tpg_add_node_to_devs(struct se_node_acl *, struct se_portal_group *); 56 + void core_tpg_add_node_to_devs(struct se_node_acl *, struct se_portal_group *, 57 + struct se_lun *); 115 58 void core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *); 116 - struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u32); 59 + struct se_lun *core_tpg_alloc_lun(struct se_portal_group *, u64); 117 60 int core_tpg_add_lun(struct se_portal_group *, struct se_lun *, 118 61 u32, struct se_device *); 119 62 void core_tpg_remove_lun(struct se_portal_group *, struct se_lun *); 63 + struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg, 64 + const char *initiatorname); 65 + void core_tpg_del_initiator_node_acl(struct se_node_acl *acl); 120 66 121 67 /* target_core_transport.c */ 122 68 extern struct kmem_cache *se_tmr_req_cache; ··· 139 77 int transport_dump_vpd_ident_type(struct t10_vpd *, unsigned char *, int); 140 78 int transport_dump_vpd_ident(struct t10_vpd *, unsigned char *, int); 141 79 bool target_stop_cmd(struct se_cmd *cmd, unsigned long *flags); 142 - int transport_clear_lun_ref(struct se_lun *); 80 + void transport_clear_lun_ref(struct se_lun *); 143 81 void transport_send_task_abort(struct se_cmd *); 144 82 sense_reason_t target_cmd_size_check(struct se_cmd *cmd, unsigned int size); 145 83 void target_qf_do_work(struct work_struct *work); 84 + bool target_check_wce(struct se_device *dev); 85 + bool target_check_fua(struct se_device *dev); 146 86 147 87 /* target_core_stat.c */ 148 88 void target_stat_setup_dev_default_groups(struct se_device *); 149 89 void target_stat_setup_port_default_groups(struct se_lun *); 150 90 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *); 91 + 92 + /* target_core_xcopy.c */ 93 + extern struct se_portal_group xcopy_pt_tpg; 151 94 152 95 #endif /* TARGET_CORE_INTERNAL_H */
+198 -181
drivers/target/target_core_pr.c
··· 35 35 #include <target/target_core_base.h> 36 36 #include <target/target_core_backend.h> 37 37 #include <target/target_core_fabric.h> 38 - #include <target/target_core_configfs.h> 39 38 40 39 #include "target_core_internal.h" 41 40 #include "target_core_pr.h" ··· 44 45 * Used for Specify Initiator Ports Capable Bit (SPEC_I_PT) 45 46 */ 46 47 struct pr_transport_id_holder { 47 - int dest_local_nexus; 48 48 struct t10_pr_registration *dest_pr_reg; 49 49 struct se_portal_group *dest_tpg; 50 50 struct se_node_acl *dest_node_acl; ··· 229 231 dev->dev_reservation_flags &= ~DRF_SPC2_RESERVATIONS_WITH_ISID; 230 232 } 231 233 tpg = sess->se_tpg; 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(), 234 - cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun, 234 + pr_debug("SCSI-2 Released reservation for %s LUN: %llu ->" 235 + " MAPPED LUN: %llu for %s\n", 236 + tpg->se_tpg_tfo->get_fabric_name(), 237 + cmd->se_lun->unpacked_lun, cmd->orig_fe_lun, 235 238 sess->se_node_acl->initiatorname); 236 239 237 240 out_unlock: ··· 276 277 (dev->dev_reserved_node_acl != sess->se_node_acl)) { 277 278 pr_err("SCSI-2 RESERVATION CONFLIFT for %s fabric\n", 278 279 tpg->se_tpg_tfo->get_fabric_name()); 279 - pr_err("Original reserver LUN: %u %s\n", 280 + pr_err("Original reserver LUN: %llu %s\n", 280 281 cmd->se_lun->unpacked_lun, 281 282 dev->dev_reserved_node_acl->initiatorname); 282 - pr_err("Current attempt - LUN: %u -> MAPPED LUN: %u" 283 + pr_err("Current attempt - LUN: %llu -> MAPPED LUN: %llu" 283 284 " from %s \n", cmd->se_lun->unpacked_lun, 284 - cmd->se_deve->mapped_lun, 285 + cmd->orig_fe_lun, 285 286 sess->se_node_acl->initiatorname); 286 287 ret = TCM_RESERVATION_CONFLICT; 287 288 goto out_unlock; ··· 293 294 dev->dev_res_bin_isid = sess->sess_bin_isid; 294 295 dev->dev_reservation_flags |= DRF_SPC2_RESERVATIONS_WITH_ISID; 295 296 } 296 - pr_debug("SCSI-2 Reserved %s LUN: %u -> MAPPED LUN: %u" 297 + pr_debug("SCSI-2 Reserved %s LUN: %llu -> MAPPED LUN: %llu" 297 298 " for %s\n", tpg->se_tpg_tfo->get_fabric_name(), 298 - cmd->se_lun->unpacked_lun, cmd->se_deve->mapped_lun, 299 + cmd->se_lun->unpacked_lun, cmd->orig_fe_lun, 299 300 sess->se_node_acl->initiatorname); 300 301 301 302 out_unlock: ··· 313 314 * This function is called by those initiator ports who are *NOT* 314 315 * the active PR reservation holder when a reservation is present. 315 316 */ 316 - static int core_scsi3_pr_seq_non_holder( 317 - struct se_cmd *cmd, 318 - u32 pr_reg_type) 317 + static int core_scsi3_pr_seq_non_holder(struct se_cmd *cmd, u32 pr_reg_type, 318 + bool isid_mismatch) 319 319 { 320 320 unsigned char *cdb = cmd->t_task_cdb; 321 - struct se_dev_entry *se_deve; 322 321 struct se_session *se_sess = cmd->se_sess; 323 - int other_cdb = 0, ignore_reg; 322 + struct se_node_acl *nacl = se_sess->se_node_acl; 323 + int other_cdb = 0; 324 324 int registered_nexus = 0, ret = 1; /* Conflict by default */ 325 325 int all_reg = 0, reg_only = 0; /* ALL_REG, REG_ONLY */ 326 326 int we = 0; /* Write Exclusive */ 327 327 int legacy = 0; /* Act like a legacy device and return 328 328 * RESERVATION CONFLICT on some CDBs */ 329 329 330 - se_deve = se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 331 - /* 332 - * Determine if the registration should be ignored due to 333 - * non-matching ISIDs in target_scsi3_pr_reservation_check(). 334 - */ 335 - ignore_reg = (pr_reg_type & 0x80000000); 336 - if (ignore_reg) 337 - pr_reg_type &= ~0x80000000; 330 + if (isid_mismatch) { 331 + registered_nexus = 0; 332 + } else { 333 + struct se_dev_entry *se_deve; 334 + 335 + rcu_read_lock(); 336 + se_deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); 337 + if (se_deve) 338 + registered_nexus = test_bit(DEF_PR_REG_ACTIVE, 339 + &se_deve->deve_flags); 340 + rcu_read_unlock(); 341 + } 338 342 339 343 switch (pr_reg_type) { 340 344 case PR_TYPE_WRITE_EXCLUSIVE: ··· 347 345 * Some commands are only allowed for the persistent reservation 348 346 * holder. 349 347 */ 350 - if ((se_deve->def_pr_registered) && !(ignore_reg)) 351 - registered_nexus = 1; 352 348 break; 353 349 case PR_TYPE_WRITE_EXCLUSIVE_REGONLY: 354 350 we = 1; ··· 355 355 * Some commands are only allowed for registered I_T Nexuses. 356 356 */ 357 357 reg_only = 1; 358 - if ((se_deve->def_pr_registered) && !(ignore_reg)) 359 - registered_nexus = 1; 360 358 break; 361 359 case PR_TYPE_WRITE_EXCLUSIVE_ALLREG: 362 360 we = 1; ··· 363 365 * Each registered I_T Nexus is a reservation holder. 364 366 */ 365 367 all_reg = 1; 366 - if ((se_deve->def_pr_registered) && !(ignore_reg)) 367 - registered_nexus = 1; 368 368 break; 369 369 default: 370 370 return -EINVAL; ··· 568 572 struct se_device *dev = cmd->se_dev; 569 573 struct se_session *sess = cmd->se_sess; 570 574 u32 pr_reg_type; 575 + bool isid_mismatch = false; 571 576 572 577 if (!dev->dev_pr_res_holder) 573 578 return 0; ··· 581 584 if (dev->dev_pr_res_holder->isid_present_at_reg) { 582 585 if (dev->dev_pr_res_holder->pr_reg_bin_isid != 583 586 sess->sess_bin_isid) { 584 - pr_reg_type |= 0x80000000; 587 + isid_mismatch = true; 585 588 goto check_nonholder; 586 589 } 587 590 } ··· 589 592 return 0; 590 593 591 594 check_nonholder: 592 - if (core_scsi3_pr_seq_non_holder(cmd, pr_reg_type)) 595 + if (core_scsi3_pr_seq_non_holder(cmd, pr_reg_type, isid_mismatch)) 593 596 return TCM_RESERVATION_CONFLICT; 594 597 return 0; 595 598 } ··· 617 620 static struct t10_pr_registration *__core_scsi3_do_alloc_registration( 618 621 struct se_device *dev, 619 622 struct se_node_acl *nacl, 623 + struct se_lun *lun, 620 624 struct se_dev_entry *deve, 625 + u64 mapped_lun, 621 626 unsigned char *isid, 622 627 u64 sa_res_key, 623 628 int all_tg_pt, ··· 641 642 atomic_set(&pr_reg->pr_res_holders, 0); 642 643 pr_reg->pr_reg_nacl = nacl; 643 644 pr_reg->pr_reg_deve = deve; 644 - pr_reg->pr_res_mapped_lun = deve->mapped_lun; 645 - pr_reg->pr_aptpl_target_lun = deve->se_lun->unpacked_lun; 645 + pr_reg->pr_res_mapped_lun = mapped_lun; 646 + pr_reg->pr_aptpl_target_lun = lun->unpacked_lun; 647 + pr_reg->tg_pt_sep_rtpi = lun->lun_rtpi; 646 648 pr_reg->pr_res_key = sa_res_key; 647 649 pr_reg->pr_reg_all_tg_pt = all_tg_pt; 648 650 pr_reg->pr_reg_aptpl = aptpl; 649 - pr_reg->pr_reg_tg_pt_lun = deve->se_lun; 650 651 /* 651 652 * If an ISID value for this SCSI Initiator Port exists, 652 653 * save it to the registration now. ··· 670 671 static struct t10_pr_registration *__core_scsi3_alloc_registration( 671 672 struct se_device *dev, 672 673 struct se_node_acl *nacl, 674 + struct se_lun *lun, 673 675 struct se_dev_entry *deve, 676 + u64 mapped_lun, 674 677 unsigned char *isid, 675 678 u64 sa_res_key, 676 679 int all_tg_pt, ··· 680 679 { 681 680 struct se_dev_entry *deve_tmp; 682 681 struct se_node_acl *nacl_tmp; 683 - struct se_port *port, *port_tmp; 682 + struct se_lun_acl *lacl_tmp; 683 + struct se_lun *lun_tmp, *next, *dest_lun; 684 684 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; 685 685 struct t10_pr_registration *pr_reg, *pr_reg_atp, *pr_reg_tmp, *pr_reg_tmp_safe; 686 686 int ret; ··· 689 687 * Create a registration for the I_T Nexus upon which the 690 688 * PROUT REGISTER was received. 691 689 */ 692 - pr_reg = __core_scsi3_do_alloc_registration(dev, nacl, deve, isid, 693 - sa_res_key, all_tg_pt, aptpl); 690 + pr_reg = __core_scsi3_do_alloc_registration(dev, nacl, lun, deve, mapped_lun, 691 + isid, sa_res_key, all_tg_pt, 692 + aptpl); 694 693 if (!pr_reg) 695 694 return NULL; 696 695 /* ··· 704 701 * for ALL_TG_PT=1 705 702 */ 706 703 spin_lock(&dev->se_port_lock); 707 - list_for_each_entry_safe(port, port_tmp, &dev->dev_sep_list, sep_list) { 708 - atomic_inc_mb(&port->sep_tg_pt_ref_cnt); 704 + list_for_each_entry_safe(lun_tmp, next, &dev->dev_sep_list, lun_dev_link) { 705 + if (!percpu_ref_tryget_live(&lun_tmp->lun_ref)) 706 + continue; 709 707 spin_unlock(&dev->se_port_lock); 710 708 711 - spin_lock_bh(&port->sep_alua_lock); 712 - list_for_each_entry(deve_tmp, &port->sep_alua_list, 713 - alua_port_list) { 709 + spin_lock(&lun_tmp->lun_deve_lock); 710 + list_for_each_entry(deve_tmp, &lun_tmp->lun_deve_list, lun_link) { 714 711 /* 715 712 * This pointer will be NULL for demo mode MappedLUNs 716 713 * that have not been make explicit via a ConfigFS ··· 719 716 if (!deve_tmp->se_lun_acl) 720 717 continue; 721 718 722 - nacl_tmp = deve_tmp->se_lun_acl->se_lun_nacl; 719 + lacl_tmp = rcu_dereference_check(deve_tmp->se_lun_acl, 720 + lockdep_is_held(&lun_tmp->lun_deve_lock)); 721 + nacl_tmp = lacl_tmp->se_lun_nacl; 723 722 /* 724 723 * Skip the matching struct se_node_acl that is allocated 725 724 * above.. ··· 741 736 if (strcmp(nacl->initiatorname, nacl_tmp->initiatorname)) 742 737 continue; 743 738 744 - atomic_inc_mb(&deve_tmp->pr_ref_count); 745 - spin_unlock_bh(&port->sep_alua_lock); 739 + kref_get(&deve_tmp->pr_kref); 740 + spin_unlock(&lun_tmp->lun_deve_lock); 746 741 /* 747 742 * Grab a configfs group dependency that is released 748 743 * for the exception path at label out: below, or upon ··· 753 748 if (ret < 0) { 754 749 pr_err("core_scsi3_lunacl_depend" 755 750 "_item() failed\n"); 756 - atomic_dec_mb(&port->sep_tg_pt_ref_cnt); 757 - atomic_dec_mb(&deve_tmp->pr_ref_count); 751 + percpu_ref_put(&lun_tmp->lun_ref); 752 + kref_put(&deve_tmp->pr_kref, target_pr_kref_release); 758 753 goto out; 759 754 } 760 755 /* ··· 764 759 * the original *pr_reg is processed in 765 760 * __core_scsi3_add_registration() 766 761 */ 762 + dest_lun = rcu_dereference_check(deve_tmp->se_lun, 763 + atomic_read(&deve_tmp->pr_kref.refcount) != 0); 764 + 767 765 pr_reg_atp = __core_scsi3_do_alloc_registration(dev, 768 - nacl_tmp, deve_tmp, NULL, 766 + nacl_tmp, dest_lun, deve_tmp, 767 + deve_tmp->mapped_lun, NULL, 769 768 sa_res_key, all_tg_pt, aptpl); 770 769 if (!pr_reg_atp) { 771 - atomic_dec_mb(&port->sep_tg_pt_ref_cnt); 772 - atomic_dec_mb(&deve_tmp->pr_ref_count); 770 + percpu_ref_put(&lun_tmp->lun_ref); 773 771 core_scsi3_lunacl_undepend_item(deve_tmp); 774 772 goto out; 775 773 } 776 774 777 775 list_add_tail(&pr_reg_atp->pr_reg_atp_mem_list, 778 776 &pr_reg->pr_reg_atp_list); 779 - spin_lock_bh(&port->sep_alua_lock); 777 + spin_lock(&lun_tmp->lun_deve_lock); 780 778 } 781 - spin_unlock_bh(&port->sep_alua_lock); 779 + spin_unlock(&lun_tmp->lun_deve_lock); 782 780 783 781 spin_lock(&dev->se_port_lock); 784 - atomic_dec_mb(&port->sep_tg_pt_ref_cnt); 782 + percpu_ref_put(&lun_tmp->lun_ref); 785 783 } 786 784 spin_unlock(&dev->se_port_lock); 787 785 ··· 805 797 u64 sa_res_key, 806 798 unsigned char *i_port, 807 799 unsigned char *isid, 808 - u32 mapped_lun, 800 + u64 mapped_lun, 809 801 unsigned char *t_port, 810 802 u16 tpgt, 811 - u32 target_lun, 803 + u64 target_lun, 812 804 int res_holder, 813 805 int all_tg_pt, 814 806 u8 type) ··· 839 831 pr_reg->pr_res_key = sa_res_key; 840 832 pr_reg->pr_reg_all_tg_pt = all_tg_pt; 841 833 pr_reg->pr_reg_aptpl = 1; 842 - pr_reg->pr_reg_tg_pt_lun = NULL; 843 834 pr_reg->pr_res_scope = 0; /* Always LUN_SCOPE */ 844 835 pr_reg->pr_res_type = type; 845 836 /* ··· 902 895 struct se_device *dev, 903 896 struct se_portal_group *tpg, 904 897 struct se_lun *lun, 905 - u32 target_lun, 898 + u64 target_lun, 906 899 struct se_node_acl *nacl, 907 - struct se_dev_entry *deve) 900 + u64 mapped_lun) 908 901 { 909 902 struct t10_pr_registration *pr_reg, *pr_reg_tmp; 910 903 struct t10_reservation *pr_tmpl = &dev->t10_pr; ··· 932 925 pr_reg_aptpl_list) { 933 926 934 927 if (!strcmp(pr_reg->pr_iport, i_port) && 935 - (pr_reg->pr_res_mapped_lun == deve->mapped_lun) && 928 + (pr_reg->pr_res_mapped_lun == mapped_lun) && 936 929 !(strcmp(pr_reg->pr_tport, t_port)) && 937 930 (pr_reg->pr_reg_tpgt == tpgt) && 938 931 (pr_reg->pr_aptpl_target_lun == target_lun)) { 939 932 940 933 pr_reg->pr_reg_nacl = nacl; 941 - pr_reg->pr_reg_deve = deve; 942 - pr_reg->pr_reg_tg_pt_lun = lun; 934 + pr_reg->tg_pt_sep_rtpi = lun->lun_rtpi; 943 935 944 936 list_del(&pr_reg->pr_reg_aptpl_list); 945 937 spin_unlock(&pr_tmpl->aptpl_reg_lock); ··· 973 967 struct se_portal_group *tpg, 974 968 struct se_lun *lun, 975 969 struct se_node_acl *nacl, 976 - u32 mapped_lun) 970 + u64 mapped_lun) 977 971 { 978 - struct se_dev_entry *deve = nacl->device_list[mapped_lun]; 979 - 980 972 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 981 973 return 0; 982 974 983 975 return __core_scsi3_check_aptpl_registration(dev, tpg, lun, 984 - lun->unpacked_lun, nacl, deve); 976 + lun->unpacked_lun, nacl, 977 + mapped_lun); 985 978 } 986 979 987 980 static void __core_scsi3_dump_registration( ··· 1014 1009 pr_reg->pr_reg_aptpl); 1015 1010 } 1016 1011 1017 - /* 1018 - * this function can be called with struct se_device->dev_reservation_lock 1019 - * when register_move = 1 1020 - */ 1021 1012 static void __core_scsi3_add_registration( 1022 1013 struct se_device *dev, 1023 1014 struct se_node_acl *nacl, ··· 1024 1023 const struct target_core_fabric_ops *tfo = nacl->se_tpg->se_tpg_tfo; 1025 1024 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; 1026 1025 struct t10_reservation *pr_tmpl = &dev->t10_pr; 1026 + struct se_dev_entry *deve; 1027 1027 1028 1028 /* 1029 1029 * Increment PRgeneration counter for struct se_device upon a successful ··· 1041 1039 1042 1040 spin_lock(&pr_tmpl->registration_lock); 1043 1041 list_add_tail(&pr_reg->pr_reg_list, &pr_tmpl->registration_list); 1044 - pr_reg->pr_reg_deve->def_pr_registered = 1; 1045 1042 1046 1043 __core_scsi3_dump_registration(tfo, dev, nacl, pr_reg, register_type); 1047 1044 spin_unlock(&pr_tmpl->registration_lock); 1045 + 1046 + rcu_read_lock(); 1047 + deve = pr_reg->pr_reg_deve; 1048 + if (deve) 1049 + set_bit(DEF_PR_REG_ACTIVE, &deve->deve_flags); 1050 + rcu_read_unlock(); 1051 + 1048 1052 /* 1049 1053 * Skip extra processing for ALL_TG_PT=0 or REGISTER_AND_MOVE. 1050 1054 */ ··· 1062 1054 */ 1063 1055 list_for_each_entry_safe(pr_reg_tmp, pr_reg_tmp_safe, 1064 1056 &pr_reg->pr_reg_atp_list, pr_reg_atp_mem_list) { 1057 + struct se_node_acl *nacl_tmp = pr_reg_tmp->pr_reg_nacl; 1058 + 1065 1059 list_del(&pr_reg_tmp->pr_reg_atp_mem_list); 1066 1060 1067 1061 pr_reg_tmp->pr_res_generation = core_scsi3_pr_generation(dev); ··· 1071 1061 spin_lock(&pr_tmpl->registration_lock); 1072 1062 list_add_tail(&pr_reg_tmp->pr_reg_list, 1073 1063 &pr_tmpl->registration_list); 1074 - pr_reg_tmp->pr_reg_deve->def_pr_registered = 1; 1075 1064 1076 - __core_scsi3_dump_registration(tfo, dev, 1077 - pr_reg_tmp->pr_reg_nacl, pr_reg_tmp, 1078 - register_type); 1065 + __core_scsi3_dump_registration(tfo, dev, nacl_tmp, pr_reg_tmp, 1066 + register_type); 1079 1067 spin_unlock(&pr_tmpl->registration_lock); 1068 + 1069 + rcu_read_lock(); 1070 + deve = pr_reg_tmp->pr_reg_deve; 1071 + if (deve) 1072 + set_bit(DEF_PR_REG_ACTIVE, &deve->deve_flags); 1073 + rcu_read_unlock(); 1074 + 1080 1075 /* 1081 1076 * Drop configfs group dependency reference from 1082 1077 * __core_scsi3_alloc_registration() ··· 1093 1078 static int core_scsi3_alloc_registration( 1094 1079 struct se_device *dev, 1095 1080 struct se_node_acl *nacl, 1081 + struct se_lun *lun, 1096 1082 struct se_dev_entry *deve, 1083 + u64 mapped_lun, 1097 1084 unsigned char *isid, 1098 1085 u64 sa_res_key, 1099 1086 int all_tg_pt, ··· 1105 1088 { 1106 1089 struct t10_pr_registration *pr_reg; 1107 1090 1108 - pr_reg = __core_scsi3_alloc_registration(dev, nacl, deve, isid, 1109 - sa_res_key, all_tg_pt, aptpl); 1091 + pr_reg = __core_scsi3_alloc_registration(dev, nacl, lun, deve, mapped_lun, 1092 + isid, sa_res_key, all_tg_pt, 1093 + aptpl); 1110 1094 if (!pr_reg) 1111 1095 return -EPERM; 1112 1096 ··· 1260 1242 const struct target_core_fabric_ops *tfo = 1261 1243 pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; 1262 1244 struct t10_reservation *pr_tmpl = &dev->t10_pr; 1245 + struct se_node_acl *nacl = pr_reg->pr_reg_nacl; 1246 + struct se_dev_entry *deve; 1263 1247 char i_buf[PR_REG_ISID_ID_LEN]; 1264 1248 1265 1249 memset(i_buf, 0, PR_REG_ISID_ID_LEN); 1266 1250 core_pr_dump_initiator_port(pr_reg, i_buf, PR_REG_ISID_ID_LEN); 1267 1251 1268 - pr_reg->pr_reg_deve->def_pr_registered = 0; 1269 - pr_reg->pr_reg_deve->pr_res_key = 0; 1270 1252 if (!list_empty(&pr_reg->pr_reg_list)) 1271 1253 list_del(&pr_reg->pr_reg_list); 1272 1254 /* ··· 1275 1257 */ 1276 1258 if (dec_holders) 1277 1259 core_scsi3_put_pr_reg(pr_reg); 1260 + 1261 + spin_unlock(&pr_tmpl->registration_lock); 1278 1262 /* 1279 1263 * Wait until all reference from any other I_T nexuses for this 1280 1264 * *pr_reg have been released. Because list_del() is called above, ··· 1284 1264 * count back to zero, and we release *pr_reg. 1285 1265 */ 1286 1266 while (atomic_read(&pr_reg->pr_res_holders) != 0) { 1287 - spin_unlock(&pr_tmpl->registration_lock); 1288 1267 pr_debug("SPC-3 PR [%s] waiting for pr_res_holders\n", 1289 1268 tfo->get_fabric_name()); 1290 1269 cpu_relax(); 1291 - spin_lock(&pr_tmpl->registration_lock); 1292 1270 } 1293 1271 1272 + rcu_read_lock(); 1273 + deve = target_nacl_find_deve(nacl, pr_reg->pr_res_mapped_lun); 1274 + if (deve) 1275 + clear_bit(DEF_PR_REG_ACTIVE, &deve->deve_flags); 1276 + rcu_read_unlock(); 1277 + 1278 + spin_lock(&pr_tmpl->registration_lock); 1294 1279 pr_debug("SPC-3 PR [%s] Service Action: UNREGISTER Initiator" 1295 1280 " Node: %s%s\n", tfo->get_fabric_name(), 1296 1281 pr_reg->pr_reg_nacl->initiatorname, ··· 1417 1392 1418 1393 static int core_scsi3_lunacl_depend_item(struct se_dev_entry *se_deve) 1419 1394 { 1420 - struct se_lun_acl *lun_acl = se_deve->se_lun_acl; 1395 + struct se_lun_acl *lun_acl; 1421 1396 struct se_node_acl *nacl; 1422 1397 struct se_portal_group *tpg; 1423 1398 /* 1424 1399 * For nacl->dynamic_node_acl=1 1425 1400 */ 1401 + lun_acl = rcu_dereference_check(se_deve->se_lun_acl, 1402 + atomic_read(&se_deve->pr_kref.refcount) != 0); 1426 1403 if (!lun_acl) 1427 1404 return 0; 1428 1405 ··· 1436 1409 1437 1410 static void core_scsi3_lunacl_undepend_item(struct se_dev_entry *se_deve) 1438 1411 { 1439 - struct se_lun_acl *lun_acl = se_deve->se_lun_acl; 1412 + struct se_lun_acl *lun_acl; 1440 1413 struct se_node_acl *nacl; 1441 1414 struct se_portal_group *tpg; 1442 1415 /* 1443 1416 * For nacl->dynamic_node_acl=1 1444 1417 */ 1418 + lun_acl = rcu_dereference_check(se_deve->se_lun_acl, 1419 + atomic_read(&se_deve->pr_kref.refcount) != 0); 1445 1420 if (!lun_acl) { 1446 - atomic_dec_mb(&se_deve->pr_ref_count); 1421 + kref_put(&se_deve->pr_kref, target_pr_kref_release); 1447 1422 return; 1448 1423 } 1449 1424 nacl = lun_acl->se_lun_nacl; 1450 1425 tpg = nacl->se_tpg; 1451 1426 1452 1427 target_undepend_item(&lun_acl->se_lun_group.cg_item); 1453 - atomic_dec_mb(&se_deve->pr_ref_count); 1428 + kref_put(&se_deve->pr_kref, target_pr_kref_release); 1454 1429 } 1455 1430 1456 1431 static sense_reason_t ··· 1465 1436 int aptpl) 1466 1437 { 1467 1438 struct se_device *dev = cmd->se_dev; 1468 - struct se_port *tmp_port; 1469 1439 struct se_portal_group *dest_tpg = NULL, *tmp_tpg; 1470 1440 struct se_session *se_sess = cmd->se_sess; 1471 1441 struct se_node_acl *dest_node_acl = NULL; 1472 - struct se_dev_entry *dest_se_deve = NULL, *local_se_deve; 1442 + struct se_dev_entry *dest_se_deve = NULL; 1473 1443 struct t10_pr_registration *dest_pr_reg, *local_pr_reg, *pr_reg_e; 1474 1444 struct t10_pr_registration *pr_reg_tmp, *pr_reg_tmp_safe; 1475 1445 LIST_HEAD(tid_dest_list); 1476 1446 struct pr_transport_id_holder *tidh_new, *tidh, *tidh_tmp; 1477 - const struct target_core_fabric_ops *tmp_tf_ops; 1478 - unsigned char *buf; 1479 - unsigned char *ptr, *i_str = NULL, proto_ident, tmp_proto_ident; 1447 + unsigned char *buf, *ptr, proto_ident; 1448 + const unsigned char *i_str; 1480 1449 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 1481 1450 sense_reason_t ret; 1482 1451 u32 tpdl, tid_len = 0; 1483 - int dest_local_nexus; 1484 1452 u32 dest_rtpi = 0; 1485 1453 1486 - local_se_deve = se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 1487 1454 /* 1488 1455 * Allocate a struct pr_transport_id_holder and setup the 1489 - * local_node_acl and local_se_deve pointers and add to 1490 - * struct list_head tid_dest_list for add registration 1491 - * processing in the loop of tid_dest_list below. 1456 + * local_node_acl pointer and add to struct list_head tid_dest_list 1457 + * for add registration processing in the loop of tid_dest_list below. 1492 1458 */ 1493 1459 tidh_new = kzalloc(sizeof(struct pr_transport_id_holder), GFP_KERNEL); 1494 1460 if (!tidh_new) { ··· 1493 1469 INIT_LIST_HEAD(&tidh_new->dest_list); 1494 1470 tidh_new->dest_tpg = tpg; 1495 1471 tidh_new->dest_node_acl = se_sess->se_node_acl; 1496 - tidh_new->dest_se_deve = local_se_deve; 1497 1472 1498 1473 local_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev, 1499 - se_sess->se_node_acl, local_se_deve, l_isid, 1474 + se_sess->se_node_acl, cmd->se_lun, 1475 + NULL, cmd->orig_fe_lun, l_isid, 1500 1476 sa_res_key, all_tg_pt, aptpl); 1501 1477 if (!local_pr_reg) { 1502 1478 kfree(tidh_new); ··· 1505 1481 tidh_new->dest_pr_reg = local_pr_reg; 1506 1482 /* 1507 1483 * The local I_T nexus does not hold any configfs dependances, 1508 - * so we set tid_h->dest_local_nexus=1 to prevent the 1484 + * so we set tidh_new->dest_se_deve to NULL to prevent the 1509 1485 * configfs_undepend_item() calls in the tid_dest_list loops below. 1510 1486 */ 1511 - tidh_new->dest_local_nexus = 1; 1487 + tidh_new->dest_se_deve = NULL; 1512 1488 list_add_tail(&tidh_new->dest_list, &tid_dest_list); 1513 1489 1514 1490 if (cmd->data_length < 28) { ··· 1549 1525 ptr = &buf[28]; 1550 1526 1551 1527 while (tpdl > 0) { 1528 + struct se_lun *dest_lun, *tmp_lun; 1529 + 1552 1530 proto_ident = (ptr[0] & 0x0f); 1553 1531 dest_tpg = NULL; 1554 1532 1555 1533 spin_lock(&dev->se_port_lock); 1556 - list_for_each_entry(tmp_port, &dev->dev_sep_list, sep_list) { 1557 - tmp_tpg = tmp_port->sep_tpg; 1558 - if (!tmp_tpg) 1559 - continue; 1560 - tmp_tf_ops = tmp_tpg->se_tpg_tfo; 1561 - if (!tmp_tf_ops) 1562 - continue; 1563 - if (!tmp_tf_ops->get_fabric_proto_ident || 1564 - !tmp_tf_ops->tpg_parse_pr_out_transport_id) 1565 - continue; 1534 + list_for_each_entry(tmp_lun, &dev->dev_sep_list, lun_dev_link) { 1535 + tmp_tpg = tmp_lun->lun_tpg; 1536 + 1566 1537 /* 1567 1538 * Look for the matching proto_ident provided by 1568 1539 * the received TransportID 1569 1540 */ 1570 - tmp_proto_ident = tmp_tf_ops->get_fabric_proto_ident(tmp_tpg); 1571 - if (tmp_proto_ident != proto_ident) 1541 + if (tmp_tpg->proto_id != proto_ident) 1572 1542 continue; 1573 - dest_rtpi = tmp_port->sep_rtpi; 1543 + dest_rtpi = tmp_lun->lun_rtpi; 1574 1544 1575 - i_str = tmp_tf_ops->tpg_parse_pr_out_transport_id( 1576 - tmp_tpg, (const char *)ptr, &tid_len, 1577 - &iport_ptr); 1545 + i_str = target_parse_pr_out_transport_id(tmp_tpg, 1546 + (const char *)ptr, &tid_len, &iport_ptr); 1578 1547 if (!i_str) 1579 1548 continue; 1580 1549 ··· 1586 1569 * from the decoded fabric module specific TransportID 1587 1570 * at *i_str. 1588 1571 */ 1589 - spin_lock_irq(&tmp_tpg->acl_node_lock); 1572 + mutex_lock(&tmp_tpg->acl_node_mutex); 1590 1573 dest_node_acl = __core_tpg_get_initiator_node_acl( 1591 1574 tmp_tpg, i_str); 1592 1575 if (dest_node_acl) 1593 1576 atomic_inc_mb(&dest_node_acl->acl_pr_ref_count); 1594 - spin_unlock_irq(&tmp_tpg->acl_node_lock); 1577 + mutex_unlock(&tmp_tpg->acl_node_mutex); 1595 1578 1596 1579 if (!dest_node_acl) { 1597 1580 core_scsi3_tpg_undepend_item(tmp_tpg); ··· 1661 1644 if (core_scsi3_lunacl_depend_item(dest_se_deve)) { 1662 1645 pr_err("core_scsi3_lunacl_depend_item()" 1663 1646 " failed\n"); 1664 - atomic_dec_mb(&dest_se_deve->pr_ref_count); 1647 + kref_put(&dest_se_deve->pr_kref, target_pr_kref_release); 1665 1648 core_scsi3_nodeacl_undepend_item(dest_node_acl); 1666 1649 core_scsi3_tpg_undepend_item(dest_tpg); 1667 1650 ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; ··· 1669 1652 } 1670 1653 1671 1654 pr_debug("SPC-3 PR SPEC_I_PT: Located %s Node: %s" 1672 - " dest_se_deve mapped_lun: %u\n", 1655 + " dest_se_deve mapped_lun: %llu\n", 1673 1656 dest_tpg->se_tpg_tfo->get_fabric_name(), 1674 1657 dest_node_acl->initiatorname, dest_se_deve->mapped_lun); 1675 1658 ··· 1725 1708 * and then call __core_scsi3_add_registration() in the 1726 1709 * 2nd loop which will never fail. 1727 1710 */ 1711 + dest_lun = rcu_dereference_check(dest_se_deve->se_lun, 1712 + atomic_read(&dest_se_deve->pr_kref.refcount) != 0); 1713 + 1728 1714 dest_pr_reg = __core_scsi3_alloc_registration(cmd->se_dev, 1729 - dest_node_acl, dest_se_deve, iport_ptr, 1730 - sa_res_key, all_tg_pt, aptpl); 1715 + dest_node_acl, dest_lun, dest_se_deve, 1716 + dest_se_deve->mapped_lun, iport_ptr, 1717 + sa_res_key, all_tg_pt, aptpl); 1731 1718 if (!dest_pr_reg) { 1732 1719 core_scsi3_lunacl_undepend_item(dest_se_deve); 1733 1720 core_scsi3_nodeacl_undepend_item(dest_node_acl); ··· 1769 1748 dest_node_acl = tidh->dest_node_acl; 1770 1749 dest_se_deve = tidh->dest_se_deve; 1771 1750 dest_pr_reg = tidh->dest_pr_reg; 1772 - dest_local_nexus = tidh->dest_local_nexus; 1773 1751 1774 1752 list_del(&tidh->dest_list); 1775 1753 kfree(tidh); ··· 1781 1761 1782 1762 pr_debug("SPC-3 PR [%s] SPEC_I_PT: Successfully" 1783 1763 " registered Transport ID for Node: %s%s Mapped LUN:" 1784 - " %u\n", dest_tpg->se_tpg_tfo->get_fabric_name(), 1785 - dest_node_acl->initiatorname, i_buf, dest_se_deve->mapped_lun); 1764 + " %llu\n", dest_tpg->se_tpg_tfo->get_fabric_name(), 1765 + dest_node_acl->initiatorname, i_buf, (dest_se_deve) ? 1766 + dest_se_deve->mapped_lun : 0); 1786 1767 1787 - if (dest_local_nexus) 1768 + if (!dest_se_deve) 1788 1769 continue; 1789 1770 1790 1771 core_scsi3_lunacl_undepend_item(dest_se_deve); ··· 1806 1785 dest_node_acl = tidh->dest_node_acl; 1807 1786 dest_se_deve = tidh->dest_se_deve; 1808 1787 dest_pr_reg = tidh->dest_pr_reg; 1809 - dest_local_nexus = tidh->dest_local_nexus; 1810 1788 1811 1789 list_del(&tidh->dest_list); 1812 1790 kfree(tidh); ··· 1823 1803 1824 1804 kmem_cache_free(t10_pr_reg_cache, dest_pr_reg); 1825 1805 1826 - if (dest_local_nexus) 1806 + if (!dest_se_deve) 1827 1807 continue; 1828 1808 1829 1809 core_scsi3_lunacl_undepend_item(dest_se_deve); ··· 1838 1818 unsigned char *buf, 1839 1819 u32 pr_aptpl_buf_len) 1840 1820 { 1841 - struct se_lun *lun; 1842 1821 struct se_portal_group *tpg; 1843 1822 struct t10_pr_registration *pr_reg; 1844 1823 unsigned char tmp[512], isid_buf[32]; ··· 1856 1837 tmp[0] = '\0'; 1857 1838 isid_buf[0] = '\0'; 1858 1839 tpg = pr_reg->pr_reg_nacl->se_tpg; 1859 - lun = pr_reg->pr_reg_tg_pt_lun; 1860 1840 /* 1861 1841 * Write out any ISID value to APTPL metadata that was included 1862 1842 * in the original registration. ··· 1874 1856 "sa_res_key=%llu\n" 1875 1857 "res_holder=1\nres_type=%02x\n" 1876 1858 "res_scope=%02x\nres_all_tg_pt=%d\n" 1877 - "mapped_lun=%u\n", reg_count, 1859 + "mapped_lun=%llu\n", reg_count, 1878 1860 tpg->se_tpg_tfo->get_fabric_name(), 1879 1861 pr_reg->pr_reg_nacl->initiatorname, isid_buf, 1880 1862 pr_reg->pr_res_key, pr_reg->pr_res_type, ··· 1884 1866 snprintf(tmp, 512, "PR_REG_START: %d\n" 1885 1867 "initiator_fabric=%s\ninitiator_node=%s\n%s" 1886 1868 "sa_res_key=%llu\nres_holder=0\n" 1887 - "res_all_tg_pt=%d\nmapped_lun=%u\n", 1869 + "res_all_tg_pt=%d\nmapped_lun=%llu\n", 1888 1870 reg_count, tpg->se_tpg_tfo->get_fabric_name(), 1889 1871 pr_reg->pr_reg_nacl->initiatorname, isid_buf, 1890 1872 pr_reg->pr_res_key, pr_reg->pr_reg_all_tg_pt, ··· 1903 1885 * Include information about the associated SCSI target port. 1904 1886 */ 1905 1887 snprintf(tmp, 512, "target_fabric=%s\ntarget_node=%s\n" 1906 - "tpgt=%hu\nport_rtpi=%hu\ntarget_lun=%u\nPR_REG_END:" 1888 + "tpgt=%hu\nport_rtpi=%hu\ntarget_lun=%llu\nPR_REG_END:" 1907 1889 " %d\n", tpg->se_tpg_tfo->get_fabric_name(), 1908 1890 tpg->se_tpg_tfo->tpg_get_wwn(tpg), 1909 1891 tpg->se_tpg_tfo->tpg_get_tag(tpg), 1910 - lun->lun_sep->sep_rtpi, lun->unpacked_lun, reg_count); 1892 + pr_reg->tg_pt_sep_rtpi, pr_reg->pr_aptpl_target_lun, 1893 + reg_count); 1911 1894 1912 1895 if ((len + strlen(tmp) >= pr_aptpl_buf_len)) { 1913 1896 pr_err("Unable to update renaming APTPL metadata," ··· 2019 2000 { 2020 2001 struct se_session *se_sess = cmd->se_sess; 2021 2002 struct se_device *dev = cmd->se_dev; 2022 - struct se_dev_entry *se_deve; 2023 2003 struct se_lun *se_lun = cmd->se_lun; 2024 2004 struct se_portal_group *se_tpg; 2025 2005 struct t10_pr_registration *pr_reg, *pr_reg_p, *pr_reg_tmp; ··· 2032 2014 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 2033 2015 } 2034 2016 se_tpg = se_sess->se_tpg; 2035 - se_deve = se_sess->se_node_acl->device_list[cmd->orig_fe_lun]; 2036 2017 2037 2018 if (se_tpg->se_tpg_tfo->sess_get_initiator_sid) { 2038 2019 memset(&isid_buf[0], 0, PR_REG_ISID_LEN); ··· 2062 2045 * Logical Unit of the SCSI device server. 2063 2046 */ 2064 2047 if (core_scsi3_alloc_registration(cmd->se_dev, 2065 - se_sess->se_node_acl, se_deve, isid_ptr, 2048 + se_sess->se_node_acl, cmd->se_lun, 2049 + NULL, cmd->orig_fe_lun, isid_ptr, 2066 2050 sa_res_key, all_tg_pt, aptpl, 2067 2051 register_type, 0)) { 2068 2052 pr_err("Unable to allocate" ··· 2084 2066 if (ret != 0) 2085 2067 return ret; 2086 2068 } 2087 - 2088 2069 return core_scsi3_update_and_write_aptpl(dev, aptpl); 2089 2070 } 2090 2071 ··· 2197 2180 &pr_tmpl->registration_list, 2198 2181 pr_reg_list) { 2199 2182 2200 - core_scsi3_ua_allocate( 2183 + target_ua_allocate_lun( 2201 2184 pr_reg_p->pr_reg_nacl, 2202 2185 pr_reg_p->pr_res_mapped_lun, 2203 2186 0x2A, ··· 2624 2607 if (pr_reg_p == pr_reg) 2625 2608 continue; 2626 2609 2627 - core_scsi3_ua_allocate(pr_reg_p->pr_reg_nacl, 2610 + target_ua_allocate_lun(pr_reg_p->pr_reg_nacl, 2628 2611 pr_reg_p->pr_res_mapped_lun, 2629 2612 0x2A, ASCQ_2AH_RESERVATIONS_RELEASED); 2630 2613 } ··· 2647 2630 struct se_session *se_sess = cmd->se_sess; 2648 2631 struct t10_reservation *pr_tmpl = &dev->t10_pr; 2649 2632 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder; 2650 - u32 pr_res_mapped_lun = 0; 2633 + u64 pr_res_mapped_lun = 0; 2651 2634 int calling_it_nexus = 0; 2652 2635 /* 2653 2636 * Locate the existing *pr_reg via struct se_node_acl pointers ··· 2709 2692 * additional sense code set to RESERVATIONS PREEMPTED. 2710 2693 */ 2711 2694 if (!calling_it_nexus) 2712 - core_scsi3_ua_allocate(pr_reg_nacl, pr_res_mapped_lun, 2695 + target_ua_allocate_lun(pr_reg_nacl, pr_res_mapped_lun, 2713 2696 0x2A, ASCQ_2AH_RESERVATIONS_PREEMPTED); 2714 2697 } 2715 2698 spin_unlock(&pr_tmpl->registration_lock); ··· 2803 2786 LIST_HEAD(preempt_and_abort_list); 2804 2787 struct t10_pr_registration *pr_reg, *pr_reg_tmp, *pr_reg_n, *pr_res_holder; 2805 2788 struct t10_reservation *pr_tmpl = &dev->t10_pr; 2806 - u32 pr_res_mapped_lun = 0; 2789 + u64 pr_res_mapped_lun = 0; 2807 2790 int all_reg = 0, calling_it_nexus = 0; 2808 2791 bool sa_res_key_unmatched = sa_res_key != 0; 2809 2792 int prh_type = 0, prh_scope = 0; ··· 2918 2901 NULL, 0); 2919 2902 } 2920 2903 if (!calling_it_nexus) 2921 - core_scsi3_ua_allocate(pr_reg_nacl, 2904 + target_ua_allocate_lun(pr_reg_nacl, 2922 2905 pr_res_mapped_lun, 0x2A, 2923 2906 ASCQ_2AH_REGISTRATIONS_PREEMPTED); 2924 2907 } ··· 3024 3007 * persistent reservation and/or registration, with the 3025 3008 * additional sense code set to REGISTRATIONS PREEMPTED; 3026 3009 */ 3027 - core_scsi3_ua_allocate(pr_reg_nacl, pr_res_mapped_lun, 0x2A, 3010 + target_ua_allocate_lun(pr_reg_nacl, pr_res_mapped_lun, 0x2A, 3028 3011 ASCQ_2AH_REGISTRATIONS_PREEMPTED); 3029 3012 } 3030 3013 spin_unlock(&pr_tmpl->registration_lock); ··· 3057 3040 if (calling_it_nexus) 3058 3041 continue; 3059 3042 3060 - core_scsi3_ua_allocate(pr_reg->pr_reg_nacl, 3043 + target_ua_allocate_lun(pr_reg->pr_reg_nacl, 3061 3044 pr_reg->pr_res_mapped_lun, 0x2A, 3062 3045 ASCQ_2AH_RESERVATIONS_RELEASED); 3063 3046 } ··· 3116 3099 struct se_session *se_sess = cmd->se_sess; 3117 3100 struct se_device *dev = cmd->se_dev; 3118 3101 struct se_dev_entry *dest_se_deve = NULL; 3119 - struct se_lun *se_lun = cmd->se_lun; 3102 + struct se_lun *se_lun = cmd->se_lun, *tmp_lun; 3120 3103 struct se_node_acl *pr_res_nacl, *pr_reg_nacl, *dest_node_acl = NULL; 3121 - struct se_port *se_port; 3122 3104 struct se_portal_group *se_tpg, *dest_se_tpg = NULL; 3123 3105 const struct target_core_fabric_ops *dest_tf_ops = NULL, *tf_ops; 3124 3106 struct t10_pr_registration *pr_reg, *pr_res_holder, *dest_pr_reg; 3125 3107 struct t10_reservation *pr_tmpl = &dev->t10_pr; 3126 3108 unsigned char *buf; 3127 - unsigned char *initiator_str; 3109 + const unsigned char *initiator_str; 3128 3110 char *iport_ptr = NULL, i_buf[PR_REG_ISID_ID_LEN]; 3129 3111 u32 tid_len, tmp_tid_len; 3130 3112 int new_reg = 0, type, scope, matching_iname; ··· 3202 3186 } 3203 3187 3204 3188 spin_lock(&dev->se_port_lock); 3205 - list_for_each_entry(se_port, &dev->dev_sep_list, sep_list) { 3206 - if (se_port->sep_rtpi != rtpi) 3189 + list_for_each_entry(tmp_lun, &dev->dev_sep_list, lun_dev_link) { 3190 + if (tmp_lun->lun_rtpi != rtpi) 3207 3191 continue; 3208 - dest_se_tpg = se_port->sep_tpg; 3209 - if (!dest_se_tpg) 3210 - continue; 3192 + dest_se_tpg = tmp_lun->lun_tpg; 3211 3193 dest_tf_ops = dest_se_tpg->se_tpg_tfo; 3212 3194 if (!dest_tf_ops) 3213 3195 continue; ··· 3244 3230 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Extracted Protocol Identifier:" 3245 3231 " 0x%02x\n", proto_ident); 3246 3232 3247 - if (proto_ident != dest_tf_ops->get_fabric_proto_ident(dest_se_tpg)) { 3233 + if (proto_ident != dest_se_tpg->proto_id) { 3248 3234 pr_err("SPC-3 PR REGISTER_AND_MOVE: Received" 3249 3235 " proto_ident: 0x%02x does not match ident: 0x%02x" 3250 3236 " from fabric: %s\n", proto_ident, 3251 - dest_tf_ops->get_fabric_proto_ident(dest_se_tpg), 3237 + dest_se_tpg->proto_id, 3252 3238 dest_tf_ops->get_fabric_name()); 3253 3239 ret = TCM_INVALID_PARAMETER_LIST; 3254 3240 goto out; 3255 3241 } 3256 - if (dest_tf_ops->tpg_parse_pr_out_transport_id == NULL) { 3257 - pr_err("SPC-3 PR REGISTER_AND_MOVE: Fabric does not" 3258 - " containg a valid tpg_parse_pr_out_transport_id" 3259 - " function pointer\n"); 3260 - ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 3261 - goto out; 3262 - } 3263 - initiator_str = dest_tf_ops->tpg_parse_pr_out_transport_id(dest_se_tpg, 3242 + initiator_str = target_parse_pr_out_transport_id(dest_se_tpg, 3264 3243 (const char *)&buf[24], &tmp_tid_len, &iport_ptr); 3265 3244 if (!initiator_str) { 3266 3245 pr_err("SPC-3 PR REGISTER_AND_MOVE: Unable to locate" ··· 3302 3295 /* 3303 3296 * Locate the destination struct se_node_acl from the received Transport ID 3304 3297 */ 3305 - spin_lock_irq(&dest_se_tpg->acl_node_lock); 3298 + mutex_lock(&dest_se_tpg->acl_node_mutex); 3306 3299 dest_node_acl = __core_tpg_get_initiator_node_acl(dest_se_tpg, 3307 3300 initiator_str); 3308 3301 if (dest_node_acl) 3309 3302 atomic_inc_mb(&dest_node_acl->acl_pr_ref_count); 3310 - spin_unlock_irq(&dest_se_tpg->acl_node_lock); 3303 + mutex_unlock(&dest_se_tpg->acl_node_mutex); 3311 3304 3312 3305 if (!dest_node_acl) { 3313 3306 pr_err("Unable to locate %s dest_node_acl for" ··· 3344 3337 3345 3338 if (core_scsi3_lunacl_depend_item(dest_se_deve)) { 3346 3339 pr_err("core_scsi3_lunacl_depend_item() failed\n"); 3347 - atomic_dec_mb(&dest_se_deve->pr_ref_count); 3340 + kref_put(&dest_se_deve->pr_kref, target_pr_kref_release); 3348 3341 dest_se_deve = NULL; 3349 3342 ret = TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 3350 3343 goto out; 3351 3344 } 3352 3345 3353 3346 pr_debug("SPC-3 PR REGISTER_AND_MOVE: Located %s node %s LUN" 3354 - " ACL for dest_se_deve->mapped_lun: %u\n", 3347 + " ACL for dest_se_deve->mapped_lun: %llu\n", 3355 3348 dest_tf_ops->get_fabric_name(), dest_node_acl->initiatorname, 3356 3349 dest_se_deve->mapped_lun); 3357 3350 ··· 3428 3421 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl, 3429 3422 iport_ptr); 3430 3423 if (!dest_pr_reg) { 3431 - if (core_scsi3_alloc_registration(cmd->se_dev, 3432 - dest_node_acl, dest_se_deve, iport_ptr, 3433 - sa_res_key, 0, aptpl, 2, 1)) { 3434 - spin_unlock(&dev->dev_reservation_lock); 3424 + struct se_lun *dest_lun = rcu_dereference_check(dest_se_deve->se_lun, 3425 + atomic_read(&dest_se_deve->pr_kref.refcount) != 0); 3426 + 3427 + spin_unlock(&dev->dev_reservation_lock); 3428 + if (core_scsi3_alloc_registration(cmd->se_dev, dest_node_acl, 3429 + dest_lun, dest_se_deve, dest_se_deve->mapped_lun, 3430 + iport_ptr, sa_res_key, 0, aptpl, 2, 1)) { 3435 3431 ret = TCM_INVALID_PARAMETER_LIST; 3436 3432 goto out; 3437 3433 } 3434 + spin_lock(&dev->dev_reservation_lock); 3438 3435 dest_pr_reg = __core_scsi3_locate_pr_reg(dev, dest_node_acl, 3439 3436 iport_ptr); 3440 3437 new_reg = 1; ··· 3894 3883 struct t10_pr_registration *pr_reg, *pr_reg_tmp; 3895 3884 struct t10_reservation *pr_tmpl = &dev->t10_pr; 3896 3885 unsigned char *buf; 3897 - u32 add_desc_len = 0, add_len = 0, desc_len, exp_desc_len; 3886 + u32 add_desc_len = 0, add_len = 0; 3898 3887 u32 off = 8; /* off into first Full Status descriptor */ 3899 3888 int format_code = 0, pr_res_type = 0, pr_res_scope = 0; 3889 + int exp_desc_len, desc_len; 3900 3890 bool all_reg = false; 3901 3891 3902 3892 if (cmd->data_length < 8) { ··· 3942 3930 * Determine expected length of $FABRIC_MOD specific 3943 3931 * TransportID full status descriptor.. 3944 3932 */ 3945 - exp_desc_len = se_tpg->se_tpg_tfo->tpg_get_pr_transport_id_len( 3946 - se_tpg, se_nacl, pr_reg, &format_code); 3947 - 3948 - if ((exp_desc_len + add_len) > cmd->data_length) { 3933 + exp_desc_len = target_get_pr_transport_id_len(se_nacl, pr_reg, 3934 + &format_code); 3935 + if (exp_desc_len < 0 || 3936 + exp_desc_len + add_len > cmd->data_length) { 3949 3937 pr_warn("SPC-3 PRIN READ_FULL_STATUS ran" 3950 3938 " out of buffer: %d\n", cmd->data_length); 3951 3939 spin_lock(&pr_tmpl->registration_lock); ··· 4002 3990 * IDENTIFIER field are not defined by this standard. 4003 3991 */ 4004 3992 if (!pr_reg->pr_reg_all_tg_pt) { 4005 - struct se_port *port = pr_reg->pr_reg_tg_pt_lun->lun_sep; 3993 + u16 sep_rtpi = pr_reg->tg_pt_sep_rtpi; 4006 3994 4007 - buf[off++] = ((port->sep_rtpi >> 8) & 0xff); 4008 - buf[off++] = (port->sep_rtpi & 0xff); 3995 + buf[off++] = ((sep_rtpi >> 8) & 0xff); 3996 + buf[off++] = (sep_rtpi & 0xff); 4009 3997 } else 4010 3998 off += 2; /* Skip over RELATIVE TARGET PORT IDENTIFIER */ 4011 3999 4000 + buf[off+4] = se_tpg->proto_id; 4001 + 4012 4002 /* 4013 - * Now, have the $FABRIC_MOD fill in the protocol identifier 4003 + * Now, have the $FABRIC_MOD fill in the transport ID. 4014 4004 */ 4015 - desc_len = se_tpg->se_tpg_tfo->tpg_get_pr_transport_id(se_tpg, 4016 - se_nacl, pr_reg, &format_code, &buf[off+4]); 4005 + desc_len = target_get_pr_transport_id(se_nacl, pr_reg, 4006 + &format_code, &buf[off+4]); 4017 4007 4018 4008 spin_lock(&pr_tmpl->registration_lock); 4019 4009 atomic_dec_mb(&pr_reg->pr_res_holders); 4010 + 4011 + if (desc_len < 0) 4012 + break; 4020 4013 /* 4021 4014 * Set the ADDITIONAL DESCRIPTOR LENGTH 4022 4015 */
+3 -3
drivers/target/target_core_pr.h
··· 56 56 extern sense_reason_t target_scsi2_reservation_reserve(struct se_cmd *); 57 57 extern int core_scsi3_alloc_aptpl_registration( 58 58 struct t10_reservation *, u64, 59 - unsigned char *, unsigned char *, u32, 60 - unsigned char *, u16, u32, int, int, u8); 59 + unsigned char *, unsigned char *, u64, 60 + unsigned char *, u16, u64, int, int, u8); 61 61 extern int core_scsi3_check_aptpl_registration(struct se_device *, 62 62 struct se_portal_group *, struct se_lun *, 63 - struct se_node_acl *, u32); 63 + struct se_node_acl *, u64); 64 64 extern void core_scsi3_free_pr_reg_from_nacl(struct se_device *, 65 65 struct se_node_acl *); 66 66 extern void core_scsi3_free_all_registrations(struct se_device *);
+19 -36
drivers/target/target_core_pscsi.c
··· 42 42 43 43 #include <target/target_core_base.h> 44 44 #include <target/target_core_backend.h> 45 - #include <target/target_core_backend_configfs.h> 46 45 47 46 #include "target_core_alua.h" 47 + #include "target_core_internal.h" 48 48 #include "target_core_pscsi.h" 49 49 50 50 #define ISPRINT(a) ((a >= ' ') && (a <= '~')) ··· 53 53 { 54 54 return container_of(dev, struct pscsi_dev_virt, dev); 55 55 } 56 - 57 - static struct se_subsystem_api pscsi_template; 58 56 59 57 static sense_reason_t pscsi_execute_cmd(struct se_cmd *cmd); 60 58 static void pscsi_req_done(struct request *, int); ··· 78 80 79 81 pr_debug("CORE_HBA[%d] - TCM SCSI HBA Driver %s on" 80 82 " Generic Target Core Stack %s\n", hba->hba_id, 81 - PSCSI_VERSION, TARGET_CORE_MOD_VERSION); 83 + PSCSI_VERSION, TARGET_CORE_VERSION); 82 84 pr_debug("CORE_HBA[%d] - Attached SCSI HBA to Generic\n", 83 85 hba->hba_id); 84 86 ··· 577 579 return -ENODEV; 578 580 } 579 581 582 + static void pscsi_dev_call_rcu(struct rcu_head *p) 583 + { 584 + struct se_device *dev = container_of(p, struct se_device, rcu_head); 585 + struct pscsi_dev_virt *pdv = PSCSI_DEV(dev); 586 + 587 + kfree(pdv); 588 + } 589 + 580 590 static void pscsi_free_device(struct se_device *dev) 581 591 { 582 592 struct pscsi_dev_virt *pdv = PSCSI_DEV(dev); ··· 616 610 617 611 pdv->pdv_sd = NULL; 618 612 } 619 - 620 - kfree(pdv); 613 + call_rcu(&dev->rcu_head, pscsi_dev_call_rcu); 621 614 } 622 615 623 616 static void pscsi_transport_complete(struct se_cmd *cmd, struct scatterlist *sg, ··· 640 635 * Hack to make sure that Write-Protect modepage is set if R/O mode is 641 636 * forced. 642 637 */ 643 - if (!cmd->se_deve || !cmd->data_length) 638 + if (!cmd->data_length) 644 639 goto after_mode_sense; 645 640 646 641 if (((cdb[0] == MODE_SENSE) || (cdb[0] == MODE_SENSE_10)) && 647 642 (status_byte(result) << 1) == SAM_STAT_GOOD) { 648 - if (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) { 643 + bool read_only = target_lun_is_rdonly(cmd); 644 + 645 + if (read_only) { 649 646 unsigned char *buf; 650 647 651 648 buf = transport_kmap_data_sg(cmd); ··· 1123 1116 kfree(pt); 1124 1117 } 1125 1118 1126 - DEF_TB_DEV_ATTRIB_RO(pscsi, hw_pi_prot_type); 1127 - TB_DEV_ATTR_RO(pscsi, hw_pi_prot_type); 1128 - 1129 - DEF_TB_DEV_ATTRIB_RO(pscsi, hw_block_size); 1130 - TB_DEV_ATTR_RO(pscsi, hw_block_size); 1131 - 1132 - DEF_TB_DEV_ATTRIB_RO(pscsi, hw_max_sectors); 1133 - TB_DEV_ATTR_RO(pscsi, hw_max_sectors); 1134 - 1135 - DEF_TB_DEV_ATTRIB_RO(pscsi, hw_queue_depth); 1136 - TB_DEV_ATTR_RO(pscsi, hw_queue_depth); 1137 - 1138 - static struct configfs_attribute *pscsi_backend_dev_attrs[] = { 1139 - &pscsi_dev_attrib_hw_pi_prot_type.attr, 1140 - &pscsi_dev_attrib_hw_block_size.attr, 1141 - &pscsi_dev_attrib_hw_max_sectors.attr, 1142 - &pscsi_dev_attrib_hw_queue_depth.attr, 1143 - NULL, 1144 - }; 1145 - 1146 - static struct se_subsystem_api pscsi_template = { 1119 + static const struct target_backend_ops pscsi_ops = { 1147 1120 .name = "pscsi", 1148 1121 .owner = THIS_MODULE, 1149 1122 .transport_flags = TRANSPORT_FLAG_PASSTHROUGH, ··· 1139 1152 .show_configfs_dev_params = pscsi_show_configfs_dev_params, 1140 1153 .get_device_type = pscsi_get_device_type, 1141 1154 .get_blocks = pscsi_get_blocks, 1155 + .tb_dev_attrib_attrs = passthrough_attrib_attrs, 1142 1156 }; 1143 1157 1144 1158 static int __init pscsi_module_init(void) 1145 1159 { 1146 - struct target_backend_cits *tbc = &pscsi_template.tb_cits; 1147 - 1148 - target_core_setup_sub_cits(&pscsi_template); 1149 - tbc->tb_dev_attrib_cit.ct_attrs = pscsi_backend_dev_attrs; 1150 - 1151 - return transport_subsystem_register(&pscsi_template); 1160 + return transport_backend_register(&pscsi_ops); 1152 1161 } 1153 1162 1154 1163 static void __exit pscsi_module_exit(void) 1155 1164 { 1156 - transport_subsystem_release(&pscsi_template); 1165 + target_backend_unregister(&pscsi_ops); 1157 1166 } 1158 1167 1159 1168 MODULE_DESCRIPTION("TCM PSCSI subsystem plugin");
+27 -63
drivers/target/target_core_rd.c
··· 33 33 34 34 #include <target/target_core_base.h> 35 35 #include <target/target_core_backend.h> 36 - #include <target/target_core_backend_configfs.h> 37 36 38 37 #include "target_core_rd.h" 39 38 ··· 41 42 return container_of(dev, struct rd_dev, dev); 42 43 } 43 44 44 - /* rd_attach_hba(): (Part of se_subsystem_api_t template) 45 - * 46 - * 47 - */ 48 45 static int rd_attach_hba(struct se_hba *hba, u32 host_id) 49 46 { 50 47 struct rd_host *rd_host; ··· 57 62 58 63 pr_debug("CORE_HBA[%d] - TCM Ramdisk HBA Driver %s on" 59 64 " Generic Target Core Stack %s\n", hba->hba_id, 60 - RD_HBA_VERSION, TARGET_CORE_MOD_VERSION); 65 + RD_HBA_VERSION, TARGET_CORE_VERSION); 61 66 62 67 return 0; 63 68 } ··· 349 354 return ret; 350 355 } 351 356 357 + static void rd_dev_call_rcu(struct rcu_head *p) 358 + { 359 + struct se_device *dev = container_of(p, struct se_device, rcu_head); 360 + struct rd_dev *rd_dev = RD_DEV(dev); 361 + 362 + kfree(rd_dev); 363 + } 364 + 352 365 static void rd_free_device(struct se_device *dev) 353 366 { 354 367 struct rd_dev *rd_dev = RD_DEV(dev); 355 368 356 369 rd_release_device_space(rd_dev); 357 - kfree(rd_dev); 370 + call_rcu(&dev->rcu_head, rd_dev_call_rcu); 358 371 } 359 372 360 373 static struct rd_dev_sg_table *rd_get_sg_table(struct rd_dev *rd_dev, u32 page) ··· 405 402 return NULL; 406 403 } 407 404 408 - typedef sense_reason_t (*dif_verify)(struct se_cmd *, sector_t, unsigned int, 409 - unsigned int, struct scatterlist *, int); 410 - 411 - static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, dif_verify dif_verify) 405 + static sense_reason_t rd_do_prot_rw(struct se_cmd *cmd, bool is_read) 412 406 { 413 407 struct se_device *se_dev = cmd->se_dev; 414 408 struct rd_dev *dev = RD_DEV(se_dev); ··· 465 465 466 466 #endif /* !CONFIG_ARCH_HAS_SG_CHAIN */ 467 467 468 - rc = dif_verify(cmd, cmd->t_task_lba, sectors, 0, prot_sg, prot_offset); 468 + if (is_read) 469 + rc = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 0, 470 + prot_sg, prot_offset); 471 + else 472 + rc = sbc_dif_verify(cmd, cmd->t_task_lba, sectors, 0, 473 + cmd->t_prot_sg, 0); 474 + 475 + if (!rc) 476 + sbc_dif_copy_prot(cmd, sectors, is_read, prot_sg, prot_offset); 477 + 469 478 if (need_to_release) 470 479 kfree(prot_sg); 471 480 ··· 520 511 521 512 if (cmd->prot_type && se_dev->dev_attrib.pi_prot_type && 522 513 data_direction == DMA_TO_DEVICE) { 523 - rc = rd_do_prot_rw(cmd, sbc_dif_verify_write); 514 + rc = rd_do_prot_rw(cmd, false); 524 515 if (rc) 525 516 return rc; 526 517 } ··· 588 579 589 580 if (cmd->prot_type && se_dev->dev_attrib.pi_prot_type && 590 581 data_direction == DMA_FROM_DEVICE) { 591 - rc = rd_do_prot_rw(cmd, sbc_dif_verify_read); 582 + rc = rd_do_prot_rw(cmd, true); 592 583 if (rc) 593 584 return rc; 594 585 } ··· 702 693 return sbc_parse_cdb(cmd, &rd_sbc_ops); 703 694 } 704 695 705 - DEF_TB_DEFAULT_ATTRIBS(rd_mcp); 706 - 707 - static struct configfs_attribute *rd_mcp_backend_dev_attrs[] = { 708 - &rd_mcp_dev_attrib_emulate_model_alias.attr, 709 - &rd_mcp_dev_attrib_emulate_dpo.attr, 710 - &rd_mcp_dev_attrib_emulate_fua_write.attr, 711 - &rd_mcp_dev_attrib_emulate_fua_read.attr, 712 - &rd_mcp_dev_attrib_emulate_write_cache.attr, 713 - &rd_mcp_dev_attrib_emulate_ua_intlck_ctrl.attr, 714 - &rd_mcp_dev_attrib_emulate_tas.attr, 715 - &rd_mcp_dev_attrib_emulate_tpu.attr, 716 - &rd_mcp_dev_attrib_emulate_tpws.attr, 717 - &rd_mcp_dev_attrib_emulate_caw.attr, 718 - &rd_mcp_dev_attrib_emulate_3pc.attr, 719 - &rd_mcp_dev_attrib_pi_prot_type.attr, 720 - &rd_mcp_dev_attrib_hw_pi_prot_type.attr, 721 - &rd_mcp_dev_attrib_pi_prot_format.attr, 722 - &rd_mcp_dev_attrib_enforce_pr_isids.attr, 723 - &rd_mcp_dev_attrib_is_nonrot.attr, 724 - &rd_mcp_dev_attrib_emulate_rest_reord.attr, 725 - &rd_mcp_dev_attrib_force_pr_aptpl.attr, 726 - &rd_mcp_dev_attrib_hw_block_size.attr, 727 - &rd_mcp_dev_attrib_block_size.attr, 728 - &rd_mcp_dev_attrib_hw_max_sectors.attr, 729 - &rd_mcp_dev_attrib_optimal_sectors.attr, 730 - &rd_mcp_dev_attrib_hw_queue_depth.attr, 731 - &rd_mcp_dev_attrib_queue_depth.attr, 732 - &rd_mcp_dev_attrib_max_unmap_lba_count.attr, 733 - &rd_mcp_dev_attrib_max_unmap_block_desc_count.attr, 734 - &rd_mcp_dev_attrib_unmap_granularity.attr, 735 - &rd_mcp_dev_attrib_unmap_granularity_alignment.attr, 736 - &rd_mcp_dev_attrib_max_write_same_len.attr, 737 - NULL, 738 - }; 739 - 740 - static struct se_subsystem_api rd_mcp_template = { 696 + static const struct target_backend_ops rd_mcp_ops = { 741 697 .name = "rd_mcp", 742 698 .inquiry_prod = "RAMDISK-MCP", 743 699 .inquiry_rev = RD_MCP_VERSION, ··· 718 744 .get_blocks = rd_get_blocks, 719 745 .init_prot = rd_init_prot, 720 746 .free_prot = rd_free_prot, 747 + .tb_dev_attrib_attrs = sbc_attrib_attrs, 721 748 }; 722 749 723 750 int __init rd_module_init(void) 724 751 { 725 - struct target_backend_cits *tbc = &rd_mcp_template.tb_cits; 726 - int ret; 727 - 728 - target_core_setup_sub_cits(&rd_mcp_template); 729 - tbc->tb_dev_attrib_cit.ct_attrs = rd_mcp_backend_dev_attrs; 730 - 731 - ret = transport_subsystem_register(&rd_mcp_template); 732 - if (ret < 0) { 733 - return ret; 734 - } 735 - 736 - return 0; 752 + return transport_backend_register(&rd_mcp_ops); 737 753 } 738 754 739 755 void rd_module_exit(void) 740 756 { 741 - transport_subsystem_release(&rd_mcp_template); 757 + target_backend_unregister(&rd_mcp_ops); 742 758 }
+128 -155
drivers/target/target_core_sbc.c
··· 38 38 39 39 static sense_reason_t 40 40 sbc_check_prot(struct se_device *, struct se_cmd *, unsigned char *, u32, bool); 41 + static sense_reason_t sbc_execute_unmap(struct se_cmd *cmd); 41 42 42 43 static sense_reason_t 43 44 sbc_emulate_readcapacity(struct se_cmd *cmd) ··· 178 177 EXPORT_SYMBOL(sbc_get_write_same_sectors); 179 178 180 179 static sense_reason_t 180 + sbc_execute_write_same_unmap(struct se_cmd *cmd) 181 + { 182 + struct sbc_ops *ops = cmd->protocol_data; 183 + sector_t nolb = sbc_get_write_same_sectors(cmd); 184 + sense_reason_t ret; 185 + 186 + if (nolb) { 187 + ret = ops->execute_unmap(cmd, cmd->t_task_lba, nolb); 188 + if (ret) 189 + return ret; 190 + } 191 + 192 + target_complete_cmd(cmd, GOOD); 193 + return 0; 194 + } 195 + 196 + static sense_reason_t 181 197 sbc_emulate_noop(struct se_cmd *cmd) 182 198 { 183 199 target_complete_cmd(cmd, GOOD); ··· 317 299 * translated into block discard requests within backend code. 318 300 */ 319 301 if (flags[0] & 0x08) { 320 - if (!ops->execute_write_same_unmap) 302 + if (!ops->execute_unmap) 321 303 return TCM_UNSUPPORTED_SCSI_OPCODE; 322 304 323 305 if (!dev->dev_attrib.emulate_tpws) { ··· 325 307 " has emulate_tpws disabled\n"); 326 308 return TCM_UNSUPPORTED_SCSI_OPCODE; 327 309 } 328 - cmd->execute_cmd = ops->execute_write_same_unmap; 310 + cmd->execute_cmd = sbc_execute_write_same_unmap; 329 311 return 0; 330 312 } 331 313 if (!ops->execute_write_same) ··· 399 381 static sense_reason_t 400 382 sbc_execute_rw(struct se_cmd *cmd) 401 383 { 402 - return cmd->execute_rw(cmd, cmd->t_data_sg, cmd->t_data_nents, 384 + struct sbc_ops *ops = cmd->protocol_data; 385 + 386 + return ops->execute_rw(cmd, cmd->t_data_sg, cmd->t_data_nents, 403 387 cmd->data_direction); 404 388 } 405 389 ··· 580 560 static sense_reason_t 581 561 sbc_compare_and_write(struct se_cmd *cmd) 582 562 { 563 + struct sbc_ops *ops = cmd->protocol_data; 583 564 struct se_device *dev = cmd->se_dev; 584 565 sense_reason_t ret; 585 566 int rc; ··· 600 579 */ 601 580 cmd->data_length = cmd->t_task_nolb * dev->dev_attrib.block_size; 602 581 603 - ret = cmd->execute_rw(cmd, cmd->t_bidi_data_sg, cmd->t_bidi_data_nents, 582 + ret = ops->execute_rw(cmd, cmd->t_bidi_data_sg, cmd->t_bidi_data_nents, 604 583 DMA_FROM_DEVICE); 605 584 if (ret) { 606 585 cmd->transport_complete_callback = NULL; ··· 759 738 sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb) 760 739 { 761 740 if (cdb[1] & 0x10) { 762 - if (!dev->dev_attrib.emulate_dpo) { 741 + /* see explanation in spc_emulate_modesense */ 742 + if (!target_check_fua(dev)) { 763 743 pr_err("Got CDB: 0x%02x with DPO bit set, but device" 764 744 " does not advertise support for DPO\n", cdb[0]); 765 745 return -EINVAL; 766 746 } 767 747 } 768 748 if (cdb[1] & 0x8) { 769 - if (!dev->dev_attrib.emulate_fua_write || !se_dev_check_wce(dev)) { 749 + if (!target_check_fua(dev)) { 770 750 pr_err("Got CDB: 0x%02x with FUA bit set, but device" 771 751 " does not advertise support for FUA write\n", 772 752 cdb[0]); ··· 787 765 u32 sectors = 0; 788 766 sense_reason_t ret; 789 767 768 + cmd->protocol_data = ops; 769 + 790 770 switch (cdb[0]) { 791 771 case READ_6: 792 772 sectors = transport_get_sectors_6(cdb); 793 773 cmd->t_task_lba = transport_lba_21(cdb); 794 774 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 795 - cmd->execute_rw = ops->execute_rw; 796 775 cmd->execute_cmd = sbc_execute_rw; 797 776 break; 798 777 case READ_10: ··· 808 785 return ret; 809 786 810 787 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 811 - cmd->execute_rw = ops->execute_rw; 812 788 cmd->execute_cmd = sbc_execute_rw; 813 789 break; 814 790 case READ_12: ··· 822 800 return ret; 823 801 824 802 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 825 - cmd->execute_rw = ops->execute_rw; 826 803 cmd->execute_cmd = sbc_execute_rw; 827 804 break; 828 805 case READ_16: ··· 836 815 return ret; 837 816 838 817 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 839 - cmd->execute_rw = ops->execute_rw; 840 818 cmd->execute_cmd = sbc_execute_rw; 841 819 break; 842 820 case WRITE_6: 843 821 sectors = transport_get_sectors_6(cdb); 844 822 cmd->t_task_lba = transport_lba_21(cdb); 845 823 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 846 - cmd->execute_rw = ops->execute_rw; 847 824 cmd->execute_cmd = sbc_execute_rw; 848 825 break; 849 826 case WRITE_10: ··· 857 838 return ret; 858 839 859 840 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 860 - cmd->execute_rw = ops->execute_rw; 861 841 cmd->execute_cmd = sbc_execute_rw; 862 842 break; 863 843 case WRITE_12: ··· 871 853 return ret; 872 854 873 855 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 874 - cmd->execute_rw = ops->execute_rw; 875 856 cmd->execute_cmd = sbc_execute_rw; 876 857 break; 877 858 case WRITE_16: ··· 885 868 return ret; 886 869 887 870 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; 888 - cmd->execute_rw = ops->execute_rw; 889 871 cmd->execute_cmd = sbc_execute_rw; 890 872 break; 891 873 case XDWRITEREAD_10: ··· 902 886 /* 903 887 * Setup BIDI XOR callback to be run after I/O completion. 904 888 */ 905 - cmd->execute_rw = ops->execute_rw; 906 889 cmd->execute_cmd = sbc_execute_rw; 907 890 cmd->transport_complete_callback = &xdreadwrite_callback; 908 891 break; ··· 925 910 * Setup BIDI XOR callback to be run during after I/O 926 911 * completion. 927 912 */ 928 - cmd->execute_rw = ops->execute_rw; 929 913 cmd->execute_cmd = sbc_execute_rw; 930 914 cmd->transport_complete_callback = &xdreadwrite_callback; 931 915 break; ··· 968 954 cmd->t_task_lba = get_unaligned_be64(&cdb[2]); 969 955 cmd->t_task_nolb = sectors; 970 956 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB | SCF_COMPARE_AND_WRITE; 971 - cmd->execute_rw = ops->execute_rw; 972 957 cmd->execute_cmd = sbc_compare_and_write; 973 958 cmd->transport_complete_callback = compare_and_write_callback; 974 959 break; ··· 1017 1004 return TCM_UNSUPPORTED_SCSI_OPCODE; 1018 1005 } 1019 1006 size = get_unaligned_be16(&cdb[7]); 1020 - cmd->execute_cmd = ops->execute_unmap; 1007 + cmd->execute_cmd = sbc_execute_unmap; 1021 1008 break; 1022 1009 case WRITE_SAME_16: 1023 1010 sectors = transport_get_sectors_16(cdb); ··· 1105 1092 } 1106 1093 EXPORT_SYMBOL(sbc_get_device_type); 1107 1094 1108 - sense_reason_t 1109 - sbc_execute_unmap(struct se_cmd *cmd, 1110 - sense_reason_t (*do_unmap_fn)(struct se_cmd *, void *, 1111 - sector_t, sector_t), 1112 - void *priv) 1095 + static sense_reason_t 1096 + sbc_execute_unmap(struct se_cmd *cmd) 1113 1097 { 1098 + struct sbc_ops *ops = cmd->protocol_data; 1114 1099 struct se_device *dev = cmd->se_dev; 1115 1100 unsigned char *buf, *ptr = NULL; 1116 1101 sector_t lba; ··· 1172 1161 goto err; 1173 1162 } 1174 1163 1175 - ret = do_unmap_fn(cmd, priv, lba, range); 1164 + ret = ops->execute_unmap(cmd, lba, range); 1176 1165 if (ret) 1177 1166 goto err; 1178 1167 ··· 1186 1175 target_complete_cmd(cmd, GOOD); 1187 1176 return ret; 1188 1177 } 1189 - EXPORT_SYMBOL(sbc_execute_unmap); 1190 1178 1191 1179 void 1192 1180 sbc_dif_generate(struct se_cmd *cmd) 1193 1181 { 1194 1182 struct se_device *dev = cmd->se_dev; 1195 1183 struct se_dif_v1_tuple *sdt; 1196 - struct scatterlist *dsg, *psg = cmd->t_prot_sg; 1184 + struct scatterlist *dsg = cmd->t_data_sg, *psg; 1197 1185 sector_t sector = cmd->t_task_lba; 1198 1186 void *daddr, *paddr; 1199 1187 int i, j, offset = 0; 1188 + unsigned int block_size = dev->dev_attrib.block_size; 1200 1189 1201 - for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { 1202 - daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1190 + for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { 1203 1191 paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1192 + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1204 1193 1205 - for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) { 1194 + for (j = 0; j < psg->length; 1195 + j += sizeof(struct se_dif_v1_tuple)) { 1196 + __u16 crc; 1197 + unsigned int avail; 1206 1198 1207 - if (offset >= psg->length) { 1208 - kunmap_atomic(paddr); 1209 - psg = sg_next(psg); 1210 - paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1211 - offset = 0; 1199 + if (offset >= dsg->length) { 1200 + offset -= dsg->length; 1201 + kunmap_atomic(daddr - dsg->offset); 1202 + dsg = sg_next(dsg); 1203 + if (!dsg) { 1204 + kunmap_atomic(paddr - psg->offset); 1205 + return; 1206 + } 1207 + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1212 1208 } 1213 1209 1214 - sdt = paddr + offset; 1215 - sdt->guard_tag = cpu_to_be16(crc_t10dif(daddr + j, 1216 - dev->dev_attrib.block_size)); 1210 + sdt = paddr + j; 1211 + avail = min(block_size, dsg->length - offset); 1212 + crc = crc_t10dif(daddr + offset, avail); 1213 + if (avail < block_size) { 1214 + kunmap_atomic(daddr - dsg->offset); 1215 + dsg = sg_next(dsg); 1216 + if (!dsg) { 1217 + kunmap_atomic(paddr - psg->offset); 1218 + return; 1219 + } 1220 + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1221 + offset = block_size - avail; 1222 + crc = crc_t10dif_update(crc, daddr, offset); 1223 + } else { 1224 + offset += block_size; 1225 + } 1226 + 1227 + sdt->guard_tag = cpu_to_be16(crc); 1217 1228 if (cmd->prot_type == TARGET_DIF_TYPE1_PROT) 1218 1229 sdt->ref_tag = cpu_to_be32(sector & 0xffffffff); 1219 1230 sdt->app_tag = 0; ··· 1248 1215 be32_to_cpu(sdt->ref_tag)); 1249 1216 1250 1217 sector++; 1251 - offset += sizeof(struct se_dif_v1_tuple); 1252 1218 } 1253 1219 1254 - kunmap_atomic(paddr); 1255 - kunmap_atomic(daddr); 1220 + kunmap_atomic(daddr - dsg->offset); 1221 + kunmap_atomic(paddr - psg->offset); 1256 1222 } 1257 1223 } 1258 1224 1259 1225 static sense_reason_t 1260 1226 sbc_dif_v1_verify(struct se_cmd *cmd, struct se_dif_v1_tuple *sdt, 1261 - const void *p, sector_t sector, unsigned int ei_lba) 1227 + __u16 crc, sector_t sector, unsigned int ei_lba) 1262 1228 { 1263 - struct se_device *dev = cmd->se_dev; 1264 - int block_size = dev->dev_attrib.block_size; 1265 1229 __be16 csum; 1266 1230 1267 1231 if (!(cmd->prot_checks & TARGET_DIF_CHECK_GUARD)) 1268 1232 goto check_ref; 1269 1233 1270 - csum = cpu_to_be16(crc_t10dif(p, block_size)); 1234 + csum = cpu_to_be16(crc); 1271 1235 1272 1236 if (sdt->guard_tag != csum) { 1273 1237 pr_err("DIFv1 checksum failed on sector %llu guard tag 0x%04x" ··· 1296 1266 return 0; 1297 1267 } 1298 1268 1299 - static void 1300 - sbc_dif_copy_prot(struct se_cmd *cmd, unsigned int sectors, bool read, 1301 - struct scatterlist *sg, int sg_off) 1269 + void sbc_dif_copy_prot(struct se_cmd *cmd, unsigned int sectors, bool read, 1270 + struct scatterlist *sg, int sg_off) 1302 1271 { 1303 1272 struct se_device *dev = cmd->se_dev; 1304 1273 struct scatterlist *psg; ··· 1329 1300 copied += len; 1330 1301 psg_len -= len; 1331 1302 1303 + kunmap_atomic(addr - sg->offset - offset); 1304 + 1332 1305 if (offset >= sg->length) { 1333 1306 sg = sg_next(sg); 1334 1307 offset = 0; 1335 1308 } 1336 - kunmap_atomic(addr); 1337 1309 } 1338 - kunmap_atomic(paddr); 1310 + kunmap_atomic(paddr - psg->offset); 1339 1311 } 1340 1312 } 1313 + EXPORT_SYMBOL(sbc_dif_copy_prot); 1341 1314 1342 1315 sense_reason_t 1343 - sbc_dif_verify_write(struct se_cmd *cmd, sector_t start, unsigned int sectors, 1344 - unsigned int ei_lba, struct scatterlist *sg, int sg_off) 1316 + sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, 1317 + unsigned int ei_lba, struct scatterlist *psg, int psg_off) 1345 1318 { 1346 1319 struct se_device *dev = cmd->se_dev; 1347 1320 struct se_dif_v1_tuple *sdt; 1348 - struct scatterlist *dsg, *psg = cmd->t_prot_sg; 1321 + struct scatterlist *dsg = cmd->t_data_sg; 1349 1322 sector_t sector = start; 1350 1323 void *daddr, *paddr; 1351 - int i, j, offset = 0; 1324 + int i; 1352 1325 sense_reason_t rc; 1326 + int dsg_off = 0; 1327 + unsigned int block_size = dev->dev_attrib.block_size; 1353 1328 1354 - for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { 1355 - daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1329 + for (; psg && sector < start + sectors; psg = sg_next(psg)) { 1356 1330 paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1357 - 1358 - for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) { 1359 - 1360 - if (offset >= psg->length) { 1361 - kunmap_atomic(paddr); 1362 - psg = sg_next(psg); 1363 - paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1364 - offset = 0; 1365 - } 1366 - 1367 - sdt = paddr + offset; 1368 - 1369 - pr_debug("DIF WRITE sector: %llu guard_tag: 0x%04x" 1370 - " app_tag: 0x%04x ref_tag: %u\n", 1371 - (unsigned long long)sector, sdt->guard_tag, 1372 - sdt->app_tag, be32_to_cpu(sdt->ref_tag)); 1373 - 1374 - rc = sbc_dif_v1_verify(cmd, sdt, daddr + j, sector, 1375 - ei_lba); 1376 - if (rc) { 1377 - kunmap_atomic(paddr); 1378 - kunmap_atomic(daddr); 1379 - cmd->bad_sector = sector; 1380 - return rc; 1381 - } 1382 - 1383 - sector++; 1384 - ei_lba++; 1385 - offset += sizeof(struct se_dif_v1_tuple); 1386 - } 1387 - 1388 - kunmap_atomic(paddr); 1389 - kunmap_atomic(daddr); 1390 - } 1391 - if (!sg) 1392 - return 0; 1393 - 1394 - sbc_dif_copy_prot(cmd, sectors, false, sg, sg_off); 1395 - 1396 - return 0; 1397 - } 1398 - EXPORT_SYMBOL(sbc_dif_verify_write); 1399 - 1400 - static sense_reason_t 1401 - __sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors, 1402 - unsigned int ei_lba, struct scatterlist *sg, int sg_off) 1403 - { 1404 - struct se_device *dev = cmd->se_dev; 1405 - struct se_dif_v1_tuple *sdt; 1406 - struct scatterlist *dsg, *psg = sg; 1407 - sector_t sector = start; 1408 - void *daddr, *paddr; 1409 - int i, j, offset = sg_off; 1410 - sense_reason_t rc; 1411 - 1412 - for_each_sg(cmd->t_data_sg, dsg, cmd->t_data_nents, i) { 1413 1331 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1414 - paddr = kmap_atomic(sg_page(psg)) + sg->offset; 1415 1332 1416 - for (j = 0; j < dsg->length; j += dev->dev_attrib.block_size) { 1333 + for (i = psg_off; i < psg->length && 1334 + sector < start + sectors; 1335 + i += sizeof(struct se_dif_v1_tuple)) { 1336 + __u16 crc; 1337 + unsigned int avail; 1417 1338 1418 - if (offset >= psg->length) { 1419 - kunmap_atomic(paddr); 1420 - psg = sg_next(psg); 1421 - paddr = kmap_atomic(sg_page(psg)) + psg->offset; 1422 - offset = 0; 1339 + if (dsg_off >= dsg->length) { 1340 + dsg_off -= dsg->length; 1341 + kunmap_atomic(daddr - dsg->offset); 1342 + dsg = sg_next(dsg); 1343 + if (!dsg) { 1344 + kunmap_atomic(paddr - psg->offset); 1345 + return 0; 1346 + } 1347 + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1423 1348 } 1424 1349 1425 - sdt = paddr + offset; 1350 + sdt = paddr + i; 1426 1351 1427 1352 pr_debug("DIF READ sector: %llu guard_tag: 0x%04x" 1428 1353 " app_tag: 0x%04x ref_tag: %u\n", ··· 1384 1401 sdt->app_tag, be32_to_cpu(sdt->ref_tag)); 1385 1402 1386 1403 if (sdt->app_tag == cpu_to_be16(0xffff)) { 1387 - sector++; 1388 - offset += sizeof(struct se_dif_v1_tuple); 1389 - continue; 1404 + dsg_off += block_size; 1405 + goto next; 1390 1406 } 1391 1407 1392 - rc = sbc_dif_v1_verify(cmd, sdt, daddr + j, sector, 1393 - ei_lba); 1408 + avail = min(block_size, dsg->length - dsg_off); 1409 + crc = crc_t10dif(daddr + dsg_off, avail); 1410 + if (avail < block_size) { 1411 + kunmap_atomic(daddr - dsg->offset); 1412 + dsg = sg_next(dsg); 1413 + if (!dsg) { 1414 + kunmap_atomic(paddr - psg->offset); 1415 + return 0; 1416 + } 1417 + daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; 1418 + dsg_off = block_size - avail; 1419 + crc = crc_t10dif_update(crc, daddr, dsg_off); 1420 + } else { 1421 + dsg_off += block_size; 1422 + } 1423 + 1424 + rc = sbc_dif_v1_verify(cmd, sdt, crc, sector, ei_lba); 1394 1425 if (rc) { 1395 - kunmap_atomic(paddr); 1396 - kunmap_atomic(daddr); 1426 + kunmap_atomic(daddr - dsg->offset); 1427 + kunmap_atomic(paddr - psg->offset); 1397 1428 cmd->bad_sector = sector; 1398 1429 return rc; 1399 1430 } 1400 - 1431 + next: 1401 1432 sector++; 1402 1433 ei_lba++; 1403 - offset += sizeof(struct se_dif_v1_tuple); 1404 1434 } 1405 1435 1406 - kunmap_atomic(paddr); 1407 - kunmap_atomic(daddr); 1436 + psg_off = 0; 1437 + kunmap_atomic(daddr - dsg->offset); 1438 + kunmap_atomic(paddr - psg->offset); 1408 1439 } 1409 1440 1410 1441 return 0; 1411 1442 } 1412 - 1413 - sense_reason_t 1414 - sbc_dif_read_strip(struct se_cmd *cmd) 1415 - { 1416 - struct se_device *dev = cmd->se_dev; 1417 - u32 sectors = cmd->prot_length / dev->prot_length; 1418 - 1419 - return __sbc_dif_verify_read(cmd, cmd->t_task_lba, sectors, 0, 1420 - cmd->t_prot_sg, 0); 1421 - } 1422 - 1423 - sense_reason_t 1424 - sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors, 1425 - unsigned int ei_lba, struct scatterlist *sg, int sg_off) 1426 - { 1427 - sense_reason_t rc; 1428 - 1429 - rc = __sbc_dif_verify_read(cmd, start, sectors, ei_lba, sg, sg_off); 1430 - if (rc) 1431 - return rc; 1432 - 1433 - sbc_dif_copy_prot(cmd, sectors, true, sg, sg_off); 1434 - return 0; 1435 - } 1436 - EXPORT_SYMBOL(sbc_dif_verify_read); 1443 + EXPORT_SYMBOL(sbc_dif_verify);
+36 -54
drivers/target/target_core_spc.c
··· 38 38 #include "target_core_ua.h" 39 39 #include "target_core_xcopy.h" 40 40 41 - static void spc_fill_alua_data(struct se_port *port, unsigned char *buf) 41 + static void spc_fill_alua_data(struct se_lun *lun, unsigned char *buf) 42 42 { 43 43 struct t10_alua_tg_pt_gp *tg_pt_gp; 44 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 45 44 46 45 /* 47 46 * Set SCCS for MAINTENANCE_IN + REPORT_TARGET_PORT_GROUPS. ··· 53 54 * 54 55 * See spc4r17 section 6.4.2 Table 135 55 56 */ 56 - if (!port) 57 - return; 58 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 59 - if (!tg_pt_gp_mem) 60 - return; 61 - 62 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 63 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 57 + spin_lock(&lun->lun_tg_pt_gp_lock); 58 + tg_pt_gp = lun->lun_tg_pt_gp; 64 59 if (tg_pt_gp) 65 60 buf[5] |= tg_pt_gp->tg_pt_gp_alua_access_type; 66 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 61 + spin_unlock(&lun->lun_tg_pt_gp_lock); 67 62 } 68 63 69 64 sense_reason_t ··· 88 95 /* 89 96 * Enable SCCS and TPGS fields for Emulated ALUA 90 97 */ 91 - spc_fill_alua_data(lun->lun_sep, buf); 98 + spc_fill_alua_data(lun, buf); 92 99 93 100 /* 94 101 * Set Third-Party Copy (3PC) bit to indicate support for EXTENDED_COPY ··· 175 182 { 176 183 struct se_device *dev = cmd->se_dev; 177 184 struct se_lun *lun = cmd->se_lun; 178 - struct se_port *port = NULL; 179 185 struct se_portal_group *tpg = NULL; 180 186 struct t10_alua_lu_gp_member *lu_gp_mem; 181 187 struct t10_alua_tg_pt_gp *tg_pt_gp; 182 - struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; 183 188 unsigned char *prod = &dev->t10_wwn.model[0]; 184 189 u32 prod_len; 185 190 u32 unit_serial_len, off = 0; ··· 259 268 /* Header size for Designation descriptor */ 260 269 len += (id_len + 4); 261 270 off += (id_len + 4); 262 - /* 263 - * struct se_port is only set for INQUIRY VPD=1 through $FABRIC_MOD 264 - */ 265 - port = lun->lun_sep; 266 - if (port) { 271 + 272 + if (1) { 267 273 struct t10_alua_lu_gp *lu_gp; 268 274 u32 padding, scsi_name_len, scsi_target_len; 269 275 u16 lu_gp_id = 0; 270 276 u16 tg_pt_gp_id = 0; 271 277 u16 tpgt; 272 278 273 - tpg = port->sep_tpg; 279 + tpg = lun->lun_tpg; 274 280 /* 275 281 * Relative target port identifer, see spc4r17 276 282 * section 7.7.3.7 ··· 275 287 * Get the PROTOCOL IDENTIFIER as defined by spc4r17 276 288 * section 7.5.1 Table 362 277 289 */ 278 - buf[off] = 279 - (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4); 290 + buf[off] = tpg->proto_id << 4; 280 291 buf[off++] |= 0x1; /* CODE SET == Binary */ 281 292 buf[off] = 0x80; /* Set PIV=1 */ 282 293 /* Set ASSOCIATION == target port: 01b */ ··· 287 300 /* Skip over Obsolete field in RTPI payload 288 301 * in Table 472 */ 289 302 off += 2; 290 - buf[off++] = ((port->sep_rtpi >> 8) & 0xff); 291 - buf[off++] = (port->sep_rtpi & 0xff); 303 + buf[off++] = ((lun->lun_rtpi >> 8) & 0xff); 304 + buf[off++] = (lun->lun_rtpi & 0xff); 292 305 len += 8; /* Header size + Designation descriptor */ 293 306 /* 294 307 * Target port group identifier, see spc4r17 ··· 297 310 * Get the PROTOCOL IDENTIFIER as defined by spc4r17 298 311 * section 7.5.1 Table 362 299 312 */ 300 - tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; 301 - if (!tg_pt_gp_mem) 302 - goto check_lu_gp; 303 - 304 - spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 305 - tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; 313 + spin_lock(&lun->lun_tg_pt_gp_lock); 314 + tg_pt_gp = lun->lun_tg_pt_gp; 306 315 if (!tg_pt_gp) { 307 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 316 + spin_unlock(&lun->lun_tg_pt_gp_lock); 308 317 goto check_lu_gp; 309 318 } 310 319 tg_pt_gp_id = tg_pt_gp->tg_pt_gp_id; 311 - spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); 320 + spin_unlock(&lun->lun_tg_pt_gp_lock); 312 321 313 - buf[off] = 314 - (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4); 322 + buf[off] = tpg->proto_id << 4; 315 323 buf[off++] |= 0x1; /* CODE SET == Binary */ 316 324 buf[off] = 0x80; /* Set PIV=1 */ 317 325 /* Set ASSOCIATION == target port: 01b */ ··· 354 372 * section 7.5.1 Table 362 355 373 */ 356 374 check_scsi_name: 357 - buf[off] = 358 - (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4); 375 + buf[off] = tpg->proto_id << 4; 359 376 buf[off++] |= 0x3; /* CODE SET == UTF-8 */ 360 377 buf[off] = 0x80; /* Set PIV=1 */ 361 378 /* Set ASSOCIATION == target port: 01b */ ··· 394 413 /* 395 414 * Target device designator 396 415 */ 397 - buf[off] = 398 - (tpg->se_tpg_tfo->get_fabric_proto_ident(tpg) << 4); 416 + buf[off] = tpg->proto_id << 4; 399 417 buf[off++] |= 0x3; /* CODE SET == UTF-8 */ 400 418 buf[off] = 0x80; /* Set PIV=1 */ 401 419 /* Set ASSOCIATION == target device: 10b */ ··· 462 482 buf[5] = 0x07; 463 483 464 484 /* If WriteCache emulation is enabled, set V_SUP */ 465 - if (se_dev_check_wce(dev)) 485 + if (target_check_wce(dev)) 466 486 buf[6] = 0x01; 467 487 /* If an LBA map is present set R_SUP */ 468 488 spin_lock(&cmd->se_dev->t10_alua.lba_map_lock); ··· 679 699 spc_emulate_inquiry(struct se_cmd *cmd) 680 700 { 681 701 struct se_device *dev = cmd->se_dev; 682 - struct se_portal_group *tpg = cmd->se_lun->lun_sep->sep_tpg; 702 + struct se_portal_group *tpg = cmd->se_lun->lun_tpg; 683 703 unsigned char *rbuf; 684 704 unsigned char *cdb = cmd->t_task_cdb; 685 705 unsigned char *buf; ··· 693 713 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 694 714 } 695 715 696 - if (dev == tpg->tpg_virt_lun0.lun_se_dev) 716 + if (dev == rcu_access_pointer(tpg->tpg_virt_lun0->lun_se_dev)) 697 717 buf[0] = 0x3f; /* Not connected */ 698 718 else 699 719 buf[0] = dev->transport->get_device_type(dev); ··· 869 889 if (pc == 1) 870 890 goto out; 871 891 872 - if (se_dev_check_wce(dev)) 892 + if (target_check_wce(dev)) 873 893 p[2] = 0x04; /* Write Cache Enable */ 874 894 p[12] = 0x20; /* Disabled Read Ahead */ 875 895 ··· 966 986 int length = 0; 967 987 int ret; 968 988 int i; 989 + bool read_only = target_lun_is_rdonly(cmd);; 969 990 970 991 memset(buf, 0, SE_MODE_PAGE_BUF); 971 992 ··· 977 996 length = ten ? 3 : 2; 978 997 979 998 /* DEVICE-SPECIFIC PARAMETER */ 980 - if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) || 981 - (cmd->se_deve && 982 - (cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY))) 999 + if ((cmd->se_lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) || read_only) 983 1000 spc_modesense_write_protect(&buf[length], type); 984 1001 985 - if ((se_dev_check_wce(dev)) && 986 - (dev->dev_attrib.emulate_fua_write > 0)) 1002 + /* 1003 + * SBC only allows us to enable FUA and DPO together. Fortunately 1004 + * DPO is explicitly specified as a hint, so a noop is a perfectly 1005 + * valid implementation. 1006 + */ 1007 + if (target_check_fua(dev)) 987 1008 spc_modesense_dpofua(&buf[length], type); 988 1009 989 1010 ++length; ··· 1195 1212 { 1196 1213 struct se_dev_entry *deve; 1197 1214 struct se_session *sess = cmd->se_sess; 1215 + struct se_node_acl *nacl; 1198 1216 unsigned char *buf; 1199 - u32 lun_count = 0, offset = 8, i; 1217 + u32 lun_count = 0, offset = 8; 1200 1218 1201 1219 if (cmd->data_length < 16) { 1202 1220 pr_warn("REPORT LUNS allocation length %u too small\n", ··· 1219 1235 lun_count = 1; 1220 1236 goto done; 1221 1237 } 1238 + nacl = sess->se_node_acl; 1222 1239 1223 - spin_lock_irq(&sess->se_node_acl->device_list_lock); 1224 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 1225 - deve = sess->se_node_acl->device_list[i]; 1226 - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) 1227 - continue; 1240 + rcu_read_lock(); 1241 + hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) { 1228 1242 /* 1229 1243 * We determine the correct LUN LIST LENGTH even once we 1230 1244 * have reached the initial allocation length. ··· 1235 1253 int_to_scsilun(deve->mapped_lun, (struct scsi_lun *)&buf[offset]); 1236 1254 offset += 8; 1237 1255 } 1238 - spin_unlock_irq(&sess->se_node_acl->device_list_lock); 1256 + rcu_read_unlock(); 1239 1257 1240 1258 /* 1241 1259 * See SPC3 r07, page 159.
+249 -323
drivers/target/target_core_stat.c
··· 37 37 #include <target/target_core_base.h> 38 38 #include <target/target_core_backend.h> 39 39 #include <target/target_core_fabric.h> 40 - #include <target/target_core_configfs.h> 41 40 #include <target/configfs_macros.h> 42 41 43 42 #include "target_core_internal.h" ··· 103 104 struct se_device *dev = 104 105 container_of(sgrps, struct se_device, dev_stat_grps); 105 106 106 - return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count); 107 + return snprintf(page, PAGE_SIZE, "%u\n", dev->export_count); 107 108 } 108 109 DEV_STAT_SCSI_DEV_ATTR_RO(ports); 109 110 ··· 539 540 struct se_port_stat_grps *pgrps, char *page) 540 541 { 541 542 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 542 - struct se_port *sep; 543 - struct se_device *dev = lun->lun_se_dev; 544 - struct se_hba *hba; 545 - ssize_t ret; 543 + struct se_device *dev; 544 + ssize_t ret = -ENODEV; 546 545 547 - spin_lock(&lun->lun_sep_lock); 548 - sep = lun->lun_sep; 549 - if (!sep) { 550 - spin_unlock(&lun->lun_sep_lock); 551 - return -ENODEV; 552 - } 553 - hba = dev->se_hba; 554 - ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 555 - spin_unlock(&lun->lun_sep_lock); 546 + rcu_read_lock(); 547 + dev = rcu_dereference(lun->lun_se_dev); 548 + if (dev) 549 + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 550 + rcu_read_unlock(); 556 551 return ret; 557 552 } 558 553 DEV_STAT_SCSI_PORT_ATTR_RO(inst); ··· 555 562 struct se_port_stat_grps *pgrps, char *page) 556 563 { 557 564 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 558 - struct se_port *sep; 559 - struct se_device *dev = lun->lun_se_dev; 560 - ssize_t ret; 565 + struct se_device *dev; 566 + ssize_t ret = -ENODEV; 561 567 562 - spin_lock(&lun->lun_sep_lock); 563 - sep = lun->lun_sep; 564 - if (!sep) { 565 - spin_unlock(&lun->lun_sep_lock); 566 - return -ENODEV; 567 - } 568 - ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 569 - spin_unlock(&lun->lun_sep_lock); 568 + rcu_read_lock(); 569 + dev = rcu_dereference(lun->lun_se_dev); 570 + if (dev) 571 + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 572 + rcu_read_unlock(); 570 573 return ret; 571 574 } 572 575 DEV_STAT_SCSI_PORT_ATTR_RO(dev); ··· 571 582 struct se_port_stat_grps *pgrps, char *page) 572 583 { 573 584 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 574 - struct se_port *sep; 575 - ssize_t ret; 585 + struct se_device *dev; 586 + ssize_t ret = -ENODEV; 576 587 577 - spin_lock(&lun->lun_sep_lock); 578 - sep = lun->lun_sep; 579 - if (!sep) { 580 - spin_unlock(&lun->lun_sep_lock); 581 - return -ENODEV; 582 - } 583 - ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index); 584 - spin_unlock(&lun->lun_sep_lock); 588 + rcu_read_lock(); 589 + dev = rcu_dereference(lun->lun_se_dev); 590 + if (dev) 591 + ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); 592 + rcu_read_unlock(); 585 593 return ret; 586 594 } 587 595 DEV_STAT_SCSI_PORT_ATTR_RO(indx); ··· 587 601 struct se_port_stat_grps *pgrps, char *page) 588 602 { 589 603 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 590 - struct se_device *dev = lun->lun_se_dev; 591 - struct se_port *sep; 592 - ssize_t ret; 604 + struct se_device *dev; 605 + ssize_t ret = -ENODEV; 593 606 594 - if (!dev) 595 - return -ENODEV; 596 - 597 - spin_lock(&lun->lun_sep_lock); 598 - sep = lun->lun_sep; 599 - if (!sep) { 600 - spin_unlock(&lun->lun_sep_lock); 601 - return -ENODEV; 602 - } 603 - ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); 604 - spin_unlock(&lun->lun_sep_lock); 607 + rcu_read_lock(); 608 + dev = rcu_dereference(lun->lun_se_dev); 609 + if (dev) 610 + ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); 611 + rcu_read_unlock(); 605 612 return ret; 606 613 } 607 614 DEV_STAT_SCSI_PORT_ATTR_RO(role); ··· 603 624 struct se_port_stat_grps *pgrps, char *page) 604 625 { 605 626 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 606 - struct se_port *sep; 607 - ssize_t ret; 627 + struct se_device *dev; 628 + ssize_t ret = -ENODEV; 608 629 609 - spin_lock(&lun->lun_sep_lock); 610 - sep = lun->lun_sep; 611 - if (!sep) { 612 - spin_unlock(&lun->lun_sep_lock); 613 - return -ENODEV; 630 + rcu_read_lock(); 631 + dev = rcu_dereference(lun->lun_se_dev); 632 + if (dev) { 633 + /* FIXME: scsiPortBusyStatuses */ 634 + ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 614 635 } 615 - /* FIXME: scsiPortBusyStatuses */ 616 - ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 617 - spin_unlock(&lun->lun_sep_lock); 636 + rcu_read_unlock(); 618 637 return ret; 619 638 } 620 639 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count); ··· 660 683 struct se_port_stat_grps *pgrps, char *page) 661 684 { 662 685 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 663 - struct se_device *dev = lun->lun_se_dev; 664 - struct se_port *sep; 665 - struct se_hba *hba; 666 - ssize_t ret; 686 + struct se_device *dev; 687 + ssize_t ret = -ENODEV; 667 688 668 - spin_lock(&lun->lun_sep_lock); 669 - sep = lun->lun_sep; 670 - if (!sep) { 671 - spin_unlock(&lun->lun_sep_lock); 672 - return -ENODEV; 673 - } 674 - hba = dev->se_hba; 675 - ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 676 - spin_unlock(&lun->lun_sep_lock); 689 + rcu_read_lock(); 690 + dev = rcu_dereference(lun->lun_se_dev); 691 + if (dev) 692 + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 693 + rcu_read_unlock(); 677 694 return ret; 678 695 } 679 696 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst); ··· 676 705 struct se_port_stat_grps *pgrps, char *page) 677 706 { 678 707 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 679 - struct se_device *dev = lun->lun_se_dev; 680 - struct se_port *sep; 681 - ssize_t ret; 708 + struct se_device *dev; 709 + ssize_t ret = -ENODEV; 682 710 683 - spin_lock(&lun->lun_sep_lock); 684 - sep = lun->lun_sep; 685 - if (!sep) { 686 - spin_unlock(&lun->lun_sep_lock); 687 - return -ENODEV; 688 - } 689 - ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 690 - spin_unlock(&lun->lun_sep_lock); 711 + rcu_read_lock(); 712 + dev = rcu_dereference(lun->lun_se_dev); 713 + if (dev) 714 + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 715 + rcu_read_unlock(); 691 716 return ret; 692 717 } 693 718 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev); ··· 692 725 struct se_port_stat_grps *pgrps, char *page) 693 726 { 694 727 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 695 - struct se_port *sep; 696 - ssize_t ret; 728 + struct se_device *dev; 729 + ssize_t ret = -ENODEV; 697 730 698 - spin_lock(&lun->lun_sep_lock); 699 - sep = lun->lun_sep; 700 - if (!sep) { 701 - spin_unlock(&lun->lun_sep_lock); 702 - return -ENODEV; 703 - } 704 - ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index); 705 - spin_unlock(&lun->lun_sep_lock); 731 + rcu_read_lock(); 732 + dev = rcu_dereference(lun->lun_se_dev); 733 + if (dev) 734 + ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); 735 + rcu_read_unlock(); 706 736 return ret; 707 737 } 708 738 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx); ··· 708 744 struct se_port_stat_grps *pgrps, char *page) 709 745 { 710 746 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 711 - struct se_port *sep; 712 - struct se_portal_group *tpg; 713 - ssize_t ret; 747 + struct se_portal_group *tpg = lun->lun_tpg; 748 + struct se_device *dev; 749 + ssize_t ret = -ENODEV; 714 750 715 - spin_lock(&lun->lun_sep_lock); 716 - sep = lun->lun_sep; 717 - if (!sep) { 718 - spin_unlock(&lun->lun_sep_lock); 719 - return -ENODEV; 720 - } 721 - tpg = sep->sep_tpg; 722 - 723 - ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n", 724 - tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index); 725 - spin_unlock(&lun->lun_sep_lock); 751 + rcu_read_lock(); 752 + dev = rcu_dereference(lun->lun_se_dev); 753 + if (dev) 754 + ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n", 755 + tpg->se_tpg_tfo->get_fabric_name(), 756 + lun->lun_rtpi); 757 + rcu_read_unlock(); 726 758 return ret; 727 759 } 728 760 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name); ··· 727 767 struct se_port_stat_grps *pgrps, char *page) 728 768 { 729 769 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 730 - struct se_port *sep; 731 - struct se_portal_group *tpg; 732 - ssize_t ret; 770 + struct se_portal_group *tpg = lun->lun_tpg; 771 + struct se_device *dev; 772 + ssize_t ret = -ENODEV; 733 773 734 - spin_lock(&lun->lun_sep_lock); 735 - sep = lun->lun_sep; 736 - if (!sep) { 737 - spin_unlock(&lun->lun_sep_lock); 738 - return -ENODEV; 739 - } 740 - tpg = sep->sep_tpg; 741 - 742 - ret = snprintf(page, PAGE_SIZE, "%s%s%d\n", 743 - tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+", 744 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 745 - spin_unlock(&lun->lun_sep_lock); 774 + rcu_read_lock(); 775 + dev = rcu_dereference(lun->lun_se_dev); 776 + if (dev) 777 + ret = snprintf(page, PAGE_SIZE, "%s%s%d\n", 778 + tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+", 779 + tpg->se_tpg_tfo->tpg_get_tag(tpg)); 780 + rcu_read_unlock(); 746 781 return ret; 747 782 } 748 783 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index); ··· 746 791 struct se_port_stat_grps *pgrps, char *page) 747 792 { 748 793 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 749 - struct se_port *sep; 750 - ssize_t ret; 794 + struct se_device *dev; 795 + ssize_t ret = -ENODEV; 751 796 752 - spin_lock(&lun->lun_sep_lock); 753 - sep = lun->lun_sep; 754 - if (!sep) { 755 - spin_unlock(&lun->lun_sep_lock); 756 - return -ENODEV; 757 - } 758 - 759 - ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus); 760 - spin_unlock(&lun->lun_sep_lock); 797 + rcu_read_lock(); 798 + dev = rcu_dereference(lun->lun_se_dev); 799 + if (dev) 800 + ret = snprintf(page, PAGE_SIZE, "%lu\n", 801 + atomic_long_read(&lun->lun_stats.cmd_pdus)); 802 + rcu_read_unlock(); 761 803 return ret; 762 804 } 763 805 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds); ··· 763 811 struct se_port_stat_grps *pgrps, char *page) 764 812 { 765 813 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 766 - struct se_port *sep; 767 - ssize_t ret; 814 + struct se_device *dev; 815 + ssize_t ret = -ENODEV; 768 816 769 - spin_lock(&lun->lun_sep_lock); 770 - sep = lun->lun_sep; 771 - if (!sep) { 772 - spin_unlock(&lun->lun_sep_lock); 773 - return -ENODEV; 774 - } 775 - 776 - ret = snprintf(page, PAGE_SIZE, "%u\n", 777 - (u32)(sep->sep_stats.rx_data_octets >> 20)); 778 - spin_unlock(&lun->lun_sep_lock); 817 + rcu_read_lock(); 818 + dev = rcu_dereference(lun->lun_se_dev); 819 + if (dev) 820 + ret = snprintf(page, PAGE_SIZE, "%u\n", 821 + (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20)); 822 + rcu_read_unlock(); 779 823 return ret; 780 824 } 781 825 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes); ··· 780 832 struct se_port_stat_grps *pgrps, char *page) 781 833 { 782 834 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 783 - struct se_port *sep; 784 - ssize_t ret; 835 + struct se_device *dev; 836 + ssize_t ret = -ENODEV; 785 837 786 - spin_lock(&lun->lun_sep_lock); 787 - sep = lun->lun_sep; 788 - if (!sep) { 789 - spin_unlock(&lun->lun_sep_lock); 790 - return -ENODEV; 791 - } 792 - 793 - ret = snprintf(page, PAGE_SIZE, "%u\n", 794 - (u32)(sep->sep_stats.tx_data_octets >> 20)); 795 - spin_unlock(&lun->lun_sep_lock); 838 + rcu_read_lock(); 839 + dev = rcu_dereference(lun->lun_se_dev); 840 + if (dev) 841 + ret = snprintf(page, PAGE_SIZE, "%u\n", 842 + (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20)); 843 + rcu_read_unlock(); 796 844 return ret; 797 845 } 798 846 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes); ··· 797 853 struct se_port_stat_grps *pgrps, char *page) 798 854 { 799 855 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 800 - struct se_port *sep; 801 - ssize_t ret; 856 + struct se_device *dev; 857 + ssize_t ret = -ENODEV; 802 858 803 - spin_lock(&lun->lun_sep_lock); 804 - sep = lun->lun_sep; 805 - if (!sep) { 806 - spin_unlock(&lun->lun_sep_lock); 807 - return -ENODEV; 859 + rcu_read_lock(); 860 + dev = rcu_dereference(lun->lun_se_dev); 861 + if (dev) { 862 + /* FIXME: scsiTgtPortHsInCommands */ 863 + ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 808 864 } 809 - 810 - /* FIXME: scsiTgtPortHsInCommands */ 811 - ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 812 - spin_unlock(&lun->lun_sep_lock); 865 + rcu_read_unlock(); 813 866 return ret; 814 867 } 815 868 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds); ··· 860 919 struct se_port_stat_grps *pgrps, char *page) 861 920 { 862 921 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 863 - struct se_device *dev = lun->lun_se_dev; 864 - struct se_port *sep; 865 - struct se_hba *hba; 866 - ssize_t ret; 922 + struct se_device *dev; 923 + ssize_t ret = -ENODEV; 867 924 868 - spin_lock(&lun->lun_sep_lock); 869 - sep = lun->lun_sep; 870 - if (!sep) { 871 - spin_unlock(&lun->lun_sep_lock); 872 - return -ENODEV; 873 - } 874 - 875 - hba = dev->se_hba; 876 - ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 877 - spin_unlock(&lun->lun_sep_lock); 925 + rcu_read_lock(); 926 + dev = rcu_dereference(lun->lun_se_dev); 927 + if (dev) 928 + ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 929 + rcu_read_unlock(); 878 930 return ret; 879 931 } 880 932 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst); ··· 876 942 struct se_port_stat_grps *pgrps, char *page) 877 943 { 878 944 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 879 - struct se_port *sep; 880 - struct se_portal_group *tpg; 881 - ssize_t ret; 945 + struct se_device *dev; 946 + struct se_portal_group *tpg = lun->lun_tpg; 947 + ssize_t ret = -ENODEV; 882 948 883 - spin_lock(&lun->lun_sep_lock); 884 - sep = lun->lun_sep; 885 - if (!sep) { 886 - spin_unlock(&lun->lun_sep_lock); 887 - return -ENODEV; 949 + rcu_read_lock(); 950 + dev = rcu_dereference(lun->lun_se_dev); 951 + if (dev) { 952 + /* scsiTransportType */ 953 + ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", 954 + tpg->se_tpg_tfo->get_fabric_name()); 888 955 } 889 - tpg = sep->sep_tpg; 890 - /* scsiTransportType */ 891 - ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", 892 - tpg->se_tpg_tfo->get_fabric_name()); 893 - spin_unlock(&lun->lun_sep_lock); 956 + rcu_read_unlock(); 894 957 return ret; 895 958 } 896 959 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device); ··· 896 965 struct se_port_stat_grps *pgrps, char *page) 897 966 { 898 967 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 899 - struct se_port *sep; 900 - struct se_portal_group *tpg; 901 - ssize_t ret; 968 + struct se_device *dev; 969 + struct se_portal_group *tpg = lun->lun_tpg; 970 + ssize_t ret = -ENODEV; 902 971 903 - spin_lock(&lun->lun_sep_lock); 904 - sep = lun->lun_sep; 905 - if (!sep) { 906 - spin_unlock(&lun->lun_sep_lock); 907 - return -ENODEV; 908 - } 909 - tpg = sep->sep_tpg; 910 - ret = snprintf(page, PAGE_SIZE, "%u\n", 911 - tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 912 - spin_unlock(&lun->lun_sep_lock); 972 + rcu_read_lock(); 973 + dev = rcu_dereference(lun->lun_se_dev); 974 + if (dev) 975 + ret = snprintf(page, PAGE_SIZE, "%u\n", 976 + tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 977 + rcu_read_unlock(); 913 978 return ret; 914 979 } 915 980 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx); ··· 914 987 struct se_port_stat_grps *pgrps, char *page) 915 988 { 916 989 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 917 - struct se_device *dev = lun->lun_se_dev; 918 - struct se_port *sep; 919 - struct se_portal_group *tpg; 990 + struct se_device *dev; 991 + struct se_portal_group *tpg = lun->lun_tpg; 920 992 struct t10_wwn *wwn; 921 - ssize_t ret; 993 + ssize_t ret = -ENODEV; 922 994 923 - spin_lock(&lun->lun_sep_lock); 924 - sep = lun->lun_sep; 925 - if (!sep) { 926 - spin_unlock(&lun->lun_sep_lock); 927 - return -ENODEV; 995 + rcu_read_lock(); 996 + dev = rcu_dereference(lun->lun_se_dev); 997 + if (dev) { 998 + wwn = &dev->t10_wwn; 999 + /* scsiTransportDevName */ 1000 + ret = snprintf(page, PAGE_SIZE, "%s+%s\n", 1001 + tpg->se_tpg_tfo->tpg_get_wwn(tpg), 1002 + (strlen(wwn->unit_serial)) ? wwn->unit_serial : 1003 + wwn->vendor); 928 1004 } 929 - tpg = sep->sep_tpg; 930 - wwn = &dev->t10_wwn; 931 - /* scsiTransportDevName */ 932 - ret = snprintf(page, PAGE_SIZE, "%s+%s\n", 933 - tpg->se_tpg_tfo->tpg_get_wwn(tpg), 934 - (strlen(wwn->unit_serial)) ? wwn->unit_serial : 935 - wwn->vendor); 936 - spin_unlock(&lun->lun_sep_lock); 1005 + rcu_read_unlock(); 937 1006 return ret; 938 1007 } 939 1008 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name); ··· 1005 1082 struct se_portal_group *tpg; 1006 1083 ssize_t ret; 1007 1084 1008 - spin_lock_irq(&nacl->device_list_lock); 1009 - deve = nacl->device_list[lacl->mapped_lun]; 1010 - if (!deve->se_lun || !deve->se_lun_acl) { 1011 - spin_unlock_irq(&nacl->device_list_lock); 1085 + rcu_read_lock(); 1086 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1087 + if (!deve) { 1088 + rcu_read_unlock(); 1012 1089 return -ENODEV; 1013 1090 } 1014 1091 tpg = nacl->se_tpg; 1015 1092 /* scsiInstIndex */ 1016 1093 ret = snprintf(page, PAGE_SIZE, "%u\n", 1017 1094 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 1018 - spin_unlock_irq(&nacl->device_list_lock); 1095 + rcu_read_unlock(); 1019 1096 return ret; 1020 1097 } 1021 1098 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst); ··· 1030 1107 struct se_lun *lun; 1031 1108 ssize_t ret; 1032 1109 1033 - spin_lock_irq(&nacl->device_list_lock); 1034 - deve = nacl->device_list[lacl->mapped_lun]; 1035 - if (!deve->se_lun || !deve->se_lun_acl) { 1036 - spin_unlock_irq(&nacl->device_list_lock); 1110 + rcu_read_lock(); 1111 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1112 + if (!deve) { 1113 + rcu_read_unlock(); 1037 1114 return -ENODEV; 1038 1115 } 1039 - lun = deve->se_lun; 1116 + lun = rcu_dereference(deve->se_lun); 1040 1117 /* scsiDeviceIndex */ 1041 - ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index); 1042 - spin_unlock_irq(&nacl->device_list_lock); 1118 + ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); 1119 + rcu_read_unlock(); 1043 1120 return ret; 1044 1121 } 1045 1122 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev); ··· 1054 1131 struct se_portal_group *tpg; 1055 1132 ssize_t ret; 1056 1133 1057 - spin_lock_irq(&nacl->device_list_lock); 1058 - deve = nacl->device_list[lacl->mapped_lun]; 1059 - if (!deve->se_lun || !deve->se_lun_acl) { 1060 - spin_unlock_irq(&nacl->device_list_lock); 1134 + rcu_read_lock(); 1135 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1136 + if (!deve) { 1137 + rcu_read_unlock(); 1061 1138 return -ENODEV; 1062 1139 } 1063 1140 tpg = nacl->se_tpg; 1064 1141 /* scsiAuthIntrTgtPortIndex */ 1065 1142 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); 1066 - spin_unlock_irq(&nacl->device_list_lock); 1143 + rcu_read_unlock(); 1067 1144 return ret; 1068 1145 } 1069 1146 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port); ··· 1077 1154 struct se_dev_entry *deve; 1078 1155 ssize_t ret; 1079 1156 1080 - spin_lock_irq(&nacl->device_list_lock); 1081 - deve = nacl->device_list[lacl->mapped_lun]; 1082 - if (!deve->se_lun || !deve->se_lun_acl) { 1083 - spin_unlock_irq(&nacl->device_list_lock); 1157 + rcu_read_lock(); 1158 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1159 + if (!deve) { 1160 + rcu_read_unlock(); 1084 1161 return -ENODEV; 1085 1162 } 1086 1163 /* scsiAuthIntrIndex */ 1087 1164 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); 1088 - spin_unlock_irq(&nacl->device_list_lock); 1165 + rcu_read_unlock(); 1089 1166 return ret; 1090 1167 } 1091 1168 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx); ··· 1099 1176 struct se_dev_entry *deve; 1100 1177 ssize_t ret; 1101 1178 1102 - spin_lock_irq(&nacl->device_list_lock); 1103 - deve = nacl->device_list[lacl->mapped_lun]; 1104 - if (!deve->se_lun || !deve->se_lun_acl) { 1105 - spin_unlock_irq(&nacl->device_list_lock); 1179 + rcu_read_lock(); 1180 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1181 + if (!deve) { 1182 + rcu_read_unlock(); 1106 1183 return -ENODEV; 1107 1184 } 1108 1185 /* scsiAuthIntrDevOrPort */ 1109 1186 ret = snprintf(page, PAGE_SIZE, "%u\n", 1); 1110 - spin_unlock_irq(&nacl->device_list_lock); 1187 + rcu_read_unlock(); 1111 1188 return ret; 1112 1189 } 1113 1190 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port); ··· 1121 1198 struct se_dev_entry *deve; 1122 1199 ssize_t ret; 1123 1200 1124 - spin_lock_irq(&nacl->device_list_lock); 1125 - deve = nacl->device_list[lacl->mapped_lun]; 1126 - if (!deve->se_lun || !deve->se_lun_acl) { 1127 - spin_unlock_irq(&nacl->device_list_lock); 1201 + rcu_read_lock(); 1202 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1203 + if (!deve) { 1204 + rcu_read_unlock(); 1128 1205 return -ENODEV; 1129 1206 } 1130 1207 /* scsiAuthIntrName */ 1131 1208 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname); 1132 - spin_unlock_irq(&nacl->device_list_lock); 1209 + rcu_read_unlock(); 1133 1210 return ret; 1134 1211 } 1135 1212 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name); ··· 1143 1220 struct se_dev_entry *deve; 1144 1221 ssize_t ret; 1145 1222 1146 - spin_lock_irq(&nacl->device_list_lock); 1147 - deve = nacl->device_list[lacl->mapped_lun]; 1148 - if (!deve->se_lun || !deve->se_lun_acl) { 1149 - spin_unlock_irq(&nacl->device_list_lock); 1223 + rcu_read_lock(); 1224 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1225 + if (!deve) { 1226 + rcu_read_unlock(); 1150 1227 return -ENODEV; 1151 1228 } 1152 1229 /* FIXME: scsiAuthIntrLunMapIndex */ 1153 1230 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 1154 - spin_unlock_irq(&nacl->device_list_lock); 1231 + rcu_read_unlock(); 1155 1232 return ret; 1156 1233 } 1157 1234 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx); ··· 1165 1242 struct se_dev_entry *deve; 1166 1243 ssize_t ret; 1167 1244 1168 - spin_lock_irq(&nacl->device_list_lock); 1169 - deve = nacl->device_list[lacl->mapped_lun]; 1170 - if (!deve->se_lun || !deve->se_lun_acl) { 1171 - spin_unlock_irq(&nacl->device_list_lock); 1245 + rcu_read_lock(); 1246 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1247 + if (!deve) { 1248 + rcu_read_unlock(); 1172 1249 return -ENODEV; 1173 1250 } 1174 1251 /* scsiAuthIntrAttachedTimes */ 1175 1252 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count); 1176 - spin_unlock_irq(&nacl->device_list_lock); 1253 + rcu_read_unlock(); 1177 1254 return ret; 1178 1255 } 1179 1256 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count); ··· 1187 1264 struct se_dev_entry *deve; 1188 1265 ssize_t ret; 1189 1266 1190 - spin_lock_irq(&nacl->device_list_lock); 1191 - deve = nacl->device_list[lacl->mapped_lun]; 1192 - if (!deve->se_lun || !deve->se_lun_acl) { 1193 - spin_unlock_irq(&nacl->device_list_lock); 1267 + rcu_read_lock(); 1268 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1269 + if (!deve) { 1270 + rcu_read_unlock(); 1194 1271 return -ENODEV; 1195 1272 } 1196 1273 /* scsiAuthIntrOutCommands */ 1197 - ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds); 1198 - spin_unlock_irq(&nacl->device_list_lock); 1274 + ret = snprintf(page, PAGE_SIZE, "%lu\n", 1275 + atomic_long_read(&deve->total_cmds)); 1276 + rcu_read_unlock(); 1199 1277 return ret; 1200 1278 } 1201 1279 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds); ··· 1210 1286 struct se_dev_entry *deve; 1211 1287 ssize_t ret; 1212 1288 1213 - spin_lock_irq(&nacl->device_list_lock); 1214 - deve = nacl->device_list[lacl->mapped_lun]; 1215 - if (!deve->se_lun || !deve->se_lun_acl) { 1216 - spin_unlock_irq(&nacl->device_list_lock); 1289 + rcu_read_lock(); 1290 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1291 + if (!deve) { 1292 + rcu_read_unlock(); 1217 1293 return -ENODEV; 1218 1294 } 1219 1295 /* scsiAuthIntrReadMegaBytes */ 1220 - ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20)); 1221 - spin_unlock_irq(&nacl->device_list_lock); 1296 + ret = snprintf(page, PAGE_SIZE, "%u\n", 1297 + (u32)(atomic_long_read(&deve->read_bytes) >> 20)); 1298 + rcu_read_unlock(); 1222 1299 return ret; 1223 1300 } 1224 1301 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes); ··· 1233 1308 struct se_dev_entry *deve; 1234 1309 ssize_t ret; 1235 1310 1236 - spin_lock_irq(&nacl->device_list_lock); 1237 - deve = nacl->device_list[lacl->mapped_lun]; 1238 - if (!deve->se_lun || !deve->se_lun_acl) { 1239 - spin_unlock_irq(&nacl->device_list_lock); 1311 + rcu_read_lock(); 1312 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1313 + if (!deve) { 1314 + rcu_read_unlock(); 1240 1315 return -ENODEV; 1241 1316 } 1242 1317 /* scsiAuthIntrWrittenMegaBytes */ 1243 - ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20)); 1244 - spin_unlock_irq(&nacl->device_list_lock); 1318 + ret = snprintf(page, PAGE_SIZE, "%u\n", 1319 + (u32)(atomic_long_read(&deve->write_bytes) >> 20)); 1320 + rcu_read_unlock(); 1245 1321 return ret; 1246 1322 } 1247 1323 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes); ··· 1256 1330 struct se_dev_entry *deve; 1257 1331 ssize_t ret; 1258 1332 1259 - spin_lock_irq(&nacl->device_list_lock); 1260 - deve = nacl->device_list[lacl->mapped_lun]; 1261 - if (!deve->se_lun || !deve->se_lun_acl) { 1262 - spin_unlock_irq(&nacl->device_list_lock); 1333 + rcu_read_lock(); 1334 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1335 + if (!deve) { 1336 + rcu_read_unlock(); 1263 1337 return -ENODEV; 1264 1338 } 1265 1339 /* FIXME: scsiAuthIntrHSOutCommands */ 1266 1340 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 1267 - spin_unlock_irq(&nacl->device_list_lock); 1341 + rcu_read_unlock(); 1268 1342 return ret; 1269 1343 } 1270 1344 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds); ··· 1278 1352 struct se_dev_entry *deve; 1279 1353 ssize_t ret; 1280 1354 1281 - spin_lock_irq(&nacl->device_list_lock); 1282 - deve = nacl->device_list[lacl->mapped_lun]; 1283 - if (!deve->se_lun || !deve->se_lun_acl) { 1284 - spin_unlock_irq(&nacl->device_list_lock); 1355 + rcu_read_lock(); 1356 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1357 + if (!deve) { 1358 + rcu_read_unlock(); 1285 1359 return -ENODEV; 1286 1360 } 1287 1361 /* scsiAuthIntrLastCreation */ 1288 1362 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time - 1289 1363 INITIAL_JIFFIES) * 100 / HZ)); 1290 - spin_unlock_irq(&nacl->device_list_lock); 1364 + rcu_read_unlock(); 1291 1365 return ret; 1292 1366 } 1293 1367 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time); ··· 1301 1375 struct se_dev_entry *deve; 1302 1376 ssize_t ret; 1303 1377 1304 - spin_lock_irq(&nacl->device_list_lock); 1305 - deve = nacl->device_list[lacl->mapped_lun]; 1306 - if (!deve->se_lun || !deve->se_lun_acl) { 1307 - spin_unlock_irq(&nacl->device_list_lock); 1378 + rcu_read_lock(); 1379 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1380 + if (!deve) { 1381 + rcu_read_unlock(); 1308 1382 return -ENODEV; 1309 1383 } 1310 1384 /* FIXME: scsiAuthIntrRowStatus */ 1311 1385 ret = snprintf(page, PAGE_SIZE, "Ready\n"); 1312 - spin_unlock_irq(&nacl->device_list_lock); 1386 + rcu_read_unlock(); 1313 1387 return ret; 1314 1388 } 1315 1389 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status); ··· 1374 1448 struct se_portal_group *tpg; 1375 1449 ssize_t ret; 1376 1450 1377 - spin_lock_irq(&nacl->device_list_lock); 1378 - deve = nacl->device_list[lacl->mapped_lun]; 1379 - if (!deve->se_lun || !deve->se_lun_acl) { 1380 - spin_unlock_irq(&nacl->device_list_lock); 1451 + rcu_read_lock(); 1452 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1453 + if (!deve) { 1454 + rcu_read_unlock(); 1381 1455 return -ENODEV; 1382 1456 } 1383 1457 tpg = nacl->se_tpg; 1384 1458 /* scsiInstIndex */ 1385 1459 ret = snprintf(page, PAGE_SIZE, "%u\n", 1386 1460 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 1387 - spin_unlock_irq(&nacl->device_list_lock); 1461 + rcu_read_unlock(); 1388 1462 return ret; 1389 1463 } 1390 1464 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst); ··· 1399 1473 struct se_lun *lun; 1400 1474 ssize_t ret; 1401 1475 1402 - spin_lock_irq(&nacl->device_list_lock); 1403 - deve = nacl->device_list[lacl->mapped_lun]; 1404 - if (!deve->se_lun || !deve->se_lun_acl) { 1405 - spin_unlock_irq(&nacl->device_list_lock); 1476 + rcu_read_lock(); 1477 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1478 + if (!deve) { 1479 + rcu_read_unlock(); 1406 1480 return -ENODEV; 1407 1481 } 1408 - lun = deve->se_lun; 1482 + lun = rcu_dereference(deve->se_lun); 1409 1483 /* scsiDeviceIndex */ 1410 - ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index); 1411 - spin_unlock_irq(&nacl->device_list_lock); 1484 + ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); 1485 + rcu_read_unlock(); 1412 1486 return ret; 1413 1487 } 1414 1488 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev); ··· 1423 1497 struct se_portal_group *tpg; 1424 1498 ssize_t ret; 1425 1499 1426 - spin_lock_irq(&nacl->device_list_lock); 1427 - deve = nacl->device_list[lacl->mapped_lun]; 1428 - if (!deve->se_lun || !deve->se_lun_acl) { 1429 - spin_unlock_irq(&nacl->device_list_lock); 1500 + rcu_read_lock(); 1501 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1502 + if (!deve) { 1503 + rcu_read_unlock(); 1430 1504 return -ENODEV; 1431 1505 } 1432 1506 tpg = nacl->se_tpg; 1433 1507 /* scsiPortIndex */ 1434 1508 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); 1435 - spin_unlock_irq(&nacl->device_list_lock); 1509 + rcu_read_unlock(); 1436 1510 return ret; 1437 1511 } 1438 1512 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port); ··· 1472 1546 struct se_dev_entry *deve; 1473 1547 ssize_t ret; 1474 1548 1475 - spin_lock_irq(&nacl->device_list_lock); 1476 - deve = nacl->device_list[lacl->mapped_lun]; 1477 - if (!deve->se_lun || !deve->se_lun_acl) { 1478 - spin_unlock_irq(&nacl->device_list_lock); 1549 + rcu_read_lock(); 1550 + deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1551 + if (!deve) { 1552 + rcu_read_unlock(); 1479 1553 return -ENODEV; 1480 1554 } 1481 1555 /* scsiAttIntrPortAuthIntrIdx */ 1482 1556 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); 1483 - spin_unlock_irq(&nacl->device_list_lock); 1557 + rcu_read_unlock(); 1484 1558 return ret; 1485 1559 } 1486 1560 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
+12 -12
drivers/target/target_core_tmr.c
··· 31 31 #include <target/target_core_base.h> 32 32 #include <target/target_core_backend.h> 33 33 #include <target/target_core_fabric.h> 34 - #include <target/target_core_configfs.h> 35 34 36 35 #include "target_core_internal.h" 37 36 #include "target_core_alua.h" ··· 114 115 { 115 116 struct se_cmd *se_cmd; 116 117 unsigned long flags; 117 - int ref_tag; 118 + u64 ref_tag; 118 119 119 120 spin_lock_irqsave(&se_sess->sess_cmd_lock, flags); 120 121 list_for_each_entry(se_cmd, &se_sess->sess_cmd_list, se_cmd_list) { ··· 126 127 if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) 127 128 continue; 128 129 129 - ref_tag = se_cmd->se_tfo->get_task_tag(se_cmd); 130 + ref_tag = se_cmd->tag; 130 131 if (tmr->ref_task_tag != ref_tag) 131 132 continue; 132 133 133 - printk("ABORT_TASK: Found referenced %s task_tag: %u\n", 134 + printk("ABORT_TASK: Found referenced %s task_tag: %llu\n", 134 135 se_cmd->se_tfo->get_fabric_name(), ref_tag); 135 136 136 137 spin_lock(&se_cmd->t_state_lock); 137 138 if (se_cmd->transport_state & CMD_T_COMPLETE) { 138 - printk("ABORT_TASK: ref_tag: %u already complete, skipping\n", ref_tag); 139 + printk("ABORT_TASK: ref_tag: %llu already complete," 140 + " skipping\n", ref_tag); 139 141 spin_unlock(&se_cmd->t_state_lock); 140 142 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); 141 143 goto out; ··· 151 151 cancel_work_sync(&se_cmd->work); 152 152 transport_wait_for_tasks(se_cmd); 153 153 154 - target_put_sess_cmd(se_sess, se_cmd); 154 + target_put_sess_cmd(se_cmd); 155 155 transport_cmd_finish_abort(se_cmd, true); 156 156 157 157 printk("ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for" 158 - " ref_tag: %d\n", ref_tag); 158 + " ref_tag: %llu\n", ref_tag); 159 159 tmr->response = TMR_FUNCTION_COMPLETE; 160 160 return; 161 161 } 162 162 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); 163 163 164 164 out: 165 - printk("ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST for ref_tag: %d\n", 165 + printk("ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST for ref_tag: %lld\n", 166 166 tmr->ref_task_tag); 167 167 tmr->response = TMR_TASK_DOES_NOT_EXIST; 168 168 } ··· 287 287 list_del(&cmd->state_list); 288 288 289 289 pr_debug("LUN_RESET: %s cmd: %p" 290 - " ITT/CmdSN: 0x%08x/0x%08x, i_state: %d, t_state: %d" 290 + " ITT/CmdSN: 0x%08llx/0x%08x, i_state: %d, t_state: %d" 291 291 "cdb: 0x%02x\n", 292 292 (preempt_and_abort_list) ? "Preempt" : "", cmd, 293 - cmd->se_tfo->get_task_tag(cmd), 0, 293 + cmd->tag, 0, 294 294 cmd->se_tfo->get_cmd_state(cmd), cmd->t_state, 295 295 cmd->t_task_cdb[0]); 296 - pr_debug("LUN_RESET: ITT[0x%08x] - pr_res_key: 0x%016Lx" 296 + pr_debug("LUN_RESET: ITT[0x%08llx] - pr_res_key: 0x%016Lx" 297 297 " -- CMD_T_ACTIVE: %d" 298 298 " CMD_T_STOP: %d CMD_T_SENT: %d\n", 299 - cmd->se_tfo->get_task_tag(cmd), cmd->pr_res_key, 299 + cmd->tag, cmd->pr_res_key, 300 300 (cmd->transport_state & CMD_T_ACTIVE) != 0, 301 301 (cmd->transport_state & CMD_T_STOP) != 0, 302 302 (cmd->transport_state & CMD_T_SENT) != 0);
+209 -363
drivers/target/target_core_tpg.c
··· 39 39 #include <target/target_core_fabric.h> 40 40 41 41 #include "target_core_internal.h" 42 + #include "target_core_alua.h" 42 43 #include "target_core_pr.h" 43 44 44 45 extern struct se_device *g_lun0_dev; ··· 47 46 static DEFINE_SPINLOCK(tpg_lock); 48 47 static LIST_HEAD(tpg_list); 49 48 50 - /* core_clear_initiator_node_from_tpg(): 51 - * 52 - * 53 - */ 54 - static void core_clear_initiator_node_from_tpg( 55 - struct se_node_acl *nacl, 56 - struct se_portal_group *tpg) 57 - { 58 - int i; 59 - struct se_dev_entry *deve; 60 - struct se_lun *lun; 61 - 62 - spin_lock_irq(&nacl->device_list_lock); 63 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 64 - deve = nacl->device_list[i]; 65 - 66 - if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) 67 - continue; 68 - 69 - if (!deve->se_lun) { 70 - pr_err("%s device entries device pointer is" 71 - " NULL, but Initiator has access.\n", 72 - tpg->se_tpg_tfo->get_fabric_name()); 73 - continue; 74 - } 75 - 76 - lun = deve->se_lun; 77 - spin_unlock_irq(&nacl->device_list_lock); 78 - core_disable_device_list_for_node(lun, NULL, deve->mapped_lun, 79 - TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg); 80 - 81 - spin_lock_irq(&nacl->device_list_lock); 82 - } 83 - spin_unlock_irq(&nacl->device_list_lock); 84 - } 85 - 86 49 /* __core_tpg_get_initiator_node_acl(): 87 50 * 88 - * spin_lock_bh(&tpg->acl_node_lock); must be held when calling 51 + * mutex_lock(&tpg->acl_node_mutex); must be held when calling 89 52 */ 90 53 struct se_node_acl *__core_tpg_get_initiator_node_acl( 91 54 struct se_portal_group *tpg, ··· 75 110 { 76 111 struct se_node_acl *acl; 77 112 78 - spin_lock_irq(&tpg->acl_node_lock); 113 + mutex_lock(&tpg->acl_node_mutex); 79 114 acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname); 80 - spin_unlock_irq(&tpg->acl_node_lock); 115 + mutex_unlock(&tpg->acl_node_mutex); 81 116 82 117 return acl; 83 118 } ··· 89 124 */ 90 125 void core_tpg_add_node_to_devs( 91 126 struct se_node_acl *acl, 92 - struct se_portal_group *tpg) 127 + struct se_portal_group *tpg, 128 + struct se_lun *lun_orig) 93 129 { 94 - int i = 0; 95 130 u32 lun_access = 0; 96 131 struct se_lun *lun; 97 132 struct se_device *dev; 98 133 99 - spin_lock(&tpg->tpg_lun_lock); 100 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 101 - lun = tpg->tpg_lun_list[i]; 102 - if (lun->lun_status != TRANSPORT_LUN_STATUS_ACTIVE) 134 + mutex_lock(&tpg->tpg_lun_mutex); 135 + hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link) { 136 + if (lun_orig && lun != lun_orig) 103 137 continue; 104 138 105 - spin_unlock(&tpg->tpg_lun_lock); 106 - 107 - dev = lun->lun_se_dev; 139 + dev = rcu_dereference_check(lun->lun_se_dev, 140 + lockdep_is_held(&tpg->tpg_lun_mutex)); 108 141 /* 109 142 * By default in LIO-Target $FABRIC_MOD, 110 143 * demo_mode_write_protect is ON, or READ_ONLY; ··· 120 157 lun_access = TRANSPORT_LUNFLAGS_READ_WRITE; 121 158 } 122 159 123 - pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%u] - Adding %s" 160 + pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%llu] - Adding %s" 124 161 " access for LUN in Demo Mode\n", 125 162 tpg->se_tpg_tfo->get_fabric_name(), 126 163 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, ··· 128 165 "READ-WRITE" : "READ-ONLY"); 129 166 130 167 core_enable_device_list_for_node(lun, NULL, lun->unpacked_lun, 131 - lun_access, acl, tpg); 168 + lun_access, acl, tpg); 132 169 /* 133 170 * Check to see if there are any existing persistent reservation 134 171 * APTPL pre-registrations that need to be enabled for this dynamic ··· 136 173 */ 137 174 core_scsi3_check_aptpl_registration(dev, tpg, lun, acl, 138 175 lun->unpacked_lun); 139 - spin_lock(&tpg->tpg_lun_lock); 140 176 } 141 - spin_unlock(&tpg->tpg_lun_lock); 177 + mutex_unlock(&tpg->tpg_lun_mutex); 142 178 } 143 179 144 180 /* core_set_queue_depth_for_node(): ··· 158 196 return 0; 159 197 } 160 198 161 - void array_free(void *array, int n) 199 + static struct se_node_acl *target_alloc_node_acl(struct se_portal_group *tpg, 200 + const unsigned char *initiatorname) 162 201 { 163 - void **a = array; 164 - int i; 202 + struct se_node_acl *acl; 165 203 166 - for (i = 0; i < n; i++) 167 - kfree(a[i]); 168 - kfree(a); 169 - } 170 - 171 - static void *array_zalloc(int n, size_t size, gfp_t flags) 172 - { 173 - void **a; 174 - int i; 175 - 176 - a = kzalloc(n * sizeof(void*), flags); 177 - if (!a) 204 + acl = kzalloc(max(sizeof(*acl), tpg->se_tpg_tfo->node_acl_size), 205 + GFP_KERNEL); 206 + if (!acl) 178 207 return NULL; 179 - for (i = 0; i < n; i++) { 180 - a[i] = kzalloc(size, flags); 181 - if (!a[i]) { 182 - array_free(a, n); 183 - return NULL; 184 - } 185 - } 186 - return a; 208 + 209 + INIT_LIST_HEAD(&acl->acl_list); 210 + INIT_LIST_HEAD(&acl->acl_sess_list); 211 + INIT_HLIST_HEAD(&acl->lun_entry_hlist); 212 + kref_init(&acl->acl_kref); 213 + init_completion(&acl->acl_free_comp); 214 + spin_lock_init(&acl->nacl_sess_lock); 215 + mutex_init(&acl->lun_entry_mutex); 216 + atomic_set(&acl->acl_pr_ref_count, 0); 217 + if (tpg->se_tpg_tfo->tpg_get_default_depth) 218 + acl->queue_depth = tpg->se_tpg_tfo->tpg_get_default_depth(tpg); 219 + else 220 + acl->queue_depth = 1; 221 + snprintf(acl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname); 222 + acl->se_tpg = tpg; 223 + acl->acl_index = scsi_get_new_index(SCSI_AUTH_INTR_INDEX); 224 + 225 + tpg->se_tpg_tfo->set_default_node_attributes(acl); 226 + 227 + if (core_set_queue_depth_for_node(tpg, acl) < 0) 228 + goto out_free_acl; 229 + 230 + return acl; 231 + 232 + out_free_acl: 233 + kfree(acl); 234 + return NULL; 187 235 } 188 236 189 - /* core_create_device_list_for_node(): 190 - * 191 - * 192 - */ 193 - static int core_create_device_list_for_node(struct se_node_acl *nacl) 237 + static void target_add_node_acl(struct se_node_acl *acl) 194 238 { 195 - struct se_dev_entry *deve; 196 - int i; 239 + struct se_portal_group *tpg = acl->se_tpg; 197 240 198 - nacl->device_list = array_zalloc(TRANSPORT_MAX_LUNS_PER_TPG, 199 - sizeof(struct se_dev_entry), GFP_KERNEL); 200 - if (!nacl->device_list) { 201 - pr_err("Unable to allocate memory for" 202 - " struct se_node_acl->device_list\n"); 203 - return -ENOMEM; 204 - } 205 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 206 - deve = nacl->device_list[i]; 241 + mutex_lock(&tpg->acl_node_mutex); 242 + list_add_tail(&acl->acl_list, &tpg->acl_node_list); 243 + tpg->num_node_acls++; 244 + mutex_unlock(&tpg->acl_node_mutex); 207 245 208 - atomic_set(&deve->ua_count, 0); 209 - atomic_set(&deve->pr_ref_count, 0); 210 - spin_lock_init(&deve->ua_lock); 211 - INIT_LIST_HEAD(&deve->alua_port_list); 212 - INIT_LIST_HEAD(&deve->ua_list); 213 - } 214 - 215 - return 0; 246 + pr_debug("%s_TPG[%hu] - Added %s ACL with TCQ Depth: %d for %s" 247 + " Initiator Node: %s\n", 248 + tpg->se_tpg_tfo->get_fabric_name(), 249 + tpg->se_tpg_tfo->tpg_get_tag(tpg), 250 + acl->dynamic_node_acl ? "DYNAMIC" : "", 251 + acl->queue_depth, 252 + tpg->se_tpg_tfo->get_fabric_name(), 253 + acl->initiatorname); 216 254 } 217 255 218 - /* core_tpg_check_initiator_node_acl() 219 - * 220 - * 221 - */ 222 256 struct se_node_acl *core_tpg_check_initiator_node_acl( 223 257 struct se_portal_group *tpg, 224 258 unsigned char *initiatorname) ··· 228 270 if (!tpg->se_tpg_tfo->tpg_check_demo_mode(tpg)) 229 271 return NULL; 230 272 231 - acl = tpg->se_tpg_tfo->tpg_alloc_fabric_acl(tpg); 273 + acl = target_alloc_node_acl(tpg, initiatorname); 232 274 if (!acl) 233 275 return NULL; 234 - 235 - INIT_LIST_HEAD(&acl->acl_list); 236 - INIT_LIST_HEAD(&acl->acl_sess_list); 237 - kref_init(&acl->acl_kref); 238 - init_completion(&acl->acl_free_comp); 239 - spin_lock_init(&acl->device_list_lock); 240 - spin_lock_init(&acl->nacl_sess_lock); 241 - atomic_set(&acl->acl_pr_ref_count, 0); 242 - acl->queue_depth = tpg->se_tpg_tfo->tpg_get_default_depth(tpg); 243 - snprintf(acl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname); 244 - acl->se_tpg = tpg; 245 - acl->acl_index = scsi_get_new_index(SCSI_AUTH_INTR_INDEX); 246 276 acl->dynamic_node_acl = 1; 247 277 248 - tpg->se_tpg_tfo->set_default_node_attributes(acl); 249 - 250 - if (core_create_device_list_for_node(acl) < 0) { 251 - tpg->se_tpg_tfo->tpg_release_fabric_acl(tpg, acl); 252 - return NULL; 253 - } 254 - 255 - if (core_set_queue_depth_for_node(tpg, acl) < 0) { 256 - core_free_device_list_for_node(acl, tpg); 257 - tpg->se_tpg_tfo->tpg_release_fabric_acl(tpg, acl); 258 - return NULL; 259 - } 260 278 /* 261 279 * Here we only create demo-mode MappedLUNs from the active 262 280 * TPG LUNs if the fabric is not explicitly asking for ··· 240 306 */ 241 307 if ((tpg->se_tpg_tfo->tpg_check_demo_mode_login_only == NULL) || 242 308 (tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1)) 243 - core_tpg_add_node_to_devs(acl, tpg); 309 + core_tpg_add_node_to_devs(acl, tpg, NULL); 244 310 245 - spin_lock_irq(&tpg->acl_node_lock); 246 - list_add_tail(&acl->acl_list, &tpg->acl_node_list); 247 - tpg->num_node_acls++; 248 - spin_unlock_irq(&tpg->acl_node_lock); 249 - 250 - pr_debug("%s_TPG[%u] - Added DYNAMIC ACL with TCQ Depth: %d for %s" 251 - " Initiator Node: %s\n", tpg->se_tpg_tfo->get_fabric_name(), 252 - tpg->se_tpg_tfo->tpg_get_tag(tpg), acl->queue_depth, 253 - tpg->se_tpg_tfo->get_fabric_name(), initiatorname); 254 - 311 + target_add_node_acl(acl); 255 312 return acl; 256 313 } 257 314 EXPORT_SYMBOL(core_tpg_check_initiator_node_acl); ··· 253 328 cpu_relax(); 254 329 } 255 330 256 - void core_tpg_clear_object_luns(struct se_portal_group *tpg) 257 - { 258 - int i; 259 - struct se_lun *lun; 260 - 261 - spin_lock(&tpg->tpg_lun_lock); 262 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 263 - lun = tpg->tpg_lun_list[i]; 264 - 265 - if ((lun->lun_status != TRANSPORT_LUN_STATUS_ACTIVE) || 266 - (lun->lun_se_dev == NULL)) 267 - continue; 268 - 269 - spin_unlock(&tpg->tpg_lun_lock); 270 - core_dev_del_lun(tpg, lun); 271 - spin_lock(&tpg->tpg_lun_lock); 272 - } 273 - spin_unlock(&tpg->tpg_lun_lock); 274 - } 275 - EXPORT_SYMBOL(core_tpg_clear_object_luns); 276 - 277 - /* core_tpg_add_initiator_node_acl(): 278 - * 279 - * 280 - */ 281 331 struct se_node_acl *core_tpg_add_initiator_node_acl( 282 332 struct se_portal_group *tpg, 283 - struct se_node_acl *se_nacl, 284 - const char *initiatorname, 285 - u32 queue_depth) 333 + const char *initiatorname) 286 334 { 287 - struct se_node_acl *acl = NULL; 335 + struct se_node_acl *acl; 288 336 289 - spin_lock_irq(&tpg->acl_node_lock); 337 + mutex_lock(&tpg->acl_node_mutex); 290 338 acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname); 291 339 if (acl) { 292 340 if (acl->dynamic_node_acl) { ··· 267 369 pr_debug("%s_TPG[%u] - Replacing dynamic ACL" 268 370 " for %s\n", tpg->se_tpg_tfo->get_fabric_name(), 269 371 tpg->se_tpg_tfo->tpg_get_tag(tpg), initiatorname); 270 - spin_unlock_irq(&tpg->acl_node_lock); 271 - /* 272 - * Release the locally allocated struct se_node_acl 273 - * because * core_tpg_add_initiator_node_acl() returned 274 - * a pointer to an existing demo mode node ACL. 275 - */ 276 - if (se_nacl) 277 - tpg->se_tpg_tfo->tpg_release_fabric_acl(tpg, 278 - se_nacl); 279 - goto done; 372 + mutex_unlock(&tpg->acl_node_mutex); 373 + return acl; 280 374 } 281 375 282 376 pr_err("ACL entry for %s Initiator" 283 377 " Node %s already exists for TPG %u, ignoring" 284 378 " request.\n", tpg->se_tpg_tfo->get_fabric_name(), 285 379 initiatorname, tpg->se_tpg_tfo->tpg_get_tag(tpg)); 286 - spin_unlock_irq(&tpg->acl_node_lock); 380 + mutex_unlock(&tpg->acl_node_mutex); 287 381 return ERR_PTR(-EEXIST); 288 382 } 289 - spin_unlock_irq(&tpg->acl_node_lock); 383 + mutex_unlock(&tpg->acl_node_mutex); 290 384 291 - if (!se_nacl) { 292 - pr_err("struct se_node_acl pointer is NULL\n"); 293 - return ERR_PTR(-EINVAL); 294 - } 295 - /* 296 - * For v4.x logic the se_node_acl_s is hanging off a fabric 297 - * dependent structure allocated via 298 - * struct target_core_fabric_ops->fabric_make_nodeacl() 299 - */ 300 - acl = se_nacl; 301 - 302 - INIT_LIST_HEAD(&acl->acl_list); 303 - INIT_LIST_HEAD(&acl->acl_sess_list); 304 - kref_init(&acl->acl_kref); 305 - init_completion(&acl->acl_free_comp); 306 - spin_lock_init(&acl->device_list_lock); 307 - spin_lock_init(&acl->nacl_sess_lock); 308 - atomic_set(&acl->acl_pr_ref_count, 0); 309 - acl->queue_depth = queue_depth; 310 - snprintf(acl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname); 311 - acl->se_tpg = tpg; 312 - acl->acl_index = scsi_get_new_index(SCSI_AUTH_INTR_INDEX); 313 - 314 - tpg->se_tpg_tfo->set_default_node_attributes(acl); 315 - 316 - if (core_create_device_list_for_node(acl) < 0) { 317 - tpg->se_tpg_tfo->tpg_release_fabric_acl(tpg, acl); 385 + acl = target_alloc_node_acl(tpg, initiatorname); 386 + if (!acl) 318 387 return ERR_PTR(-ENOMEM); 319 - } 320 388 321 - if (core_set_queue_depth_for_node(tpg, acl) < 0) { 322 - core_free_device_list_for_node(acl, tpg); 323 - tpg->se_tpg_tfo->tpg_release_fabric_acl(tpg, acl); 324 - return ERR_PTR(-EINVAL); 325 - } 326 - 327 - spin_lock_irq(&tpg->acl_node_lock); 328 - list_add_tail(&acl->acl_list, &tpg->acl_node_list); 329 - tpg->num_node_acls++; 330 - spin_unlock_irq(&tpg->acl_node_lock); 331 - 332 - done: 333 - pr_debug("%s_TPG[%hu] - Added ACL with TCQ Depth: %d for %s" 334 - " Initiator Node: %s\n", tpg->se_tpg_tfo->get_fabric_name(), 335 - tpg->se_tpg_tfo->tpg_get_tag(tpg), acl->queue_depth, 336 - tpg->se_tpg_tfo->get_fabric_name(), initiatorname); 337 - 389 + target_add_node_acl(acl); 338 390 return acl; 339 391 } 340 - EXPORT_SYMBOL(core_tpg_add_initiator_node_acl); 341 392 342 - /* core_tpg_del_initiator_node_acl(): 343 - * 344 - * 345 - */ 346 - int core_tpg_del_initiator_node_acl( 347 - struct se_portal_group *tpg, 348 - struct se_node_acl *acl, 349 - int force) 393 + void core_tpg_del_initiator_node_acl(struct se_node_acl *acl) 350 394 { 395 + struct se_portal_group *tpg = acl->se_tpg; 351 396 LIST_HEAD(sess_list); 352 397 struct se_session *sess, *sess_tmp; 353 398 unsigned long flags; 354 399 int rc; 355 400 356 - spin_lock_irq(&tpg->acl_node_lock); 401 + mutex_lock(&tpg->acl_node_mutex); 357 402 if (acl->dynamic_node_acl) { 358 403 acl->dynamic_node_acl = 0; 359 404 } 360 405 list_del(&acl->acl_list); 361 406 tpg->num_node_acls--; 362 - spin_unlock_irq(&tpg->acl_node_lock); 407 + mutex_unlock(&tpg->acl_node_mutex); 363 408 364 409 spin_lock_irqsave(&acl->nacl_sess_lock, flags); 365 410 acl->acl_stop = 1; ··· 334 493 wait_for_completion(&acl->acl_free_comp); 335 494 336 495 core_tpg_wait_for_nacl_pr_ref(acl); 337 - core_clear_initiator_node_from_tpg(acl, tpg); 338 496 core_free_device_list_for_node(acl, tpg); 339 497 340 498 pr_debug("%s_TPG[%hu] - Deleted ACL with TCQ Depth: %d for %s" ··· 341 501 tpg->se_tpg_tfo->tpg_get_tag(tpg), acl->queue_depth, 342 502 tpg->se_tpg_tfo->get_fabric_name(), acl->initiatorname); 343 503 344 - return 0; 504 + kfree(acl); 345 505 } 346 - EXPORT_SYMBOL(core_tpg_del_initiator_node_acl); 347 506 348 507 /* core_tpg_set_initiator_node_queue_depth(): 349 508 * ··· 359 520 unsigned long flags; 360 521 int dynamic_acl = 0; 361 522 362 - spin_lock_irq(&tpg->acl_node_lock); 523 + mutex_lock(&tpg->acl_node_mutex); 363 524 acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname); 364 525 if (!acl) { 365 526 pr_err("Access Control List entry for %s Initiator" 366 527 " Node %s does not exists for TPG %hu, ignoring" 367 528 " request.\n", tpg->se_tpg_tfo->get_fabric_name(), 368 529 initiatorname, tpg->se_tpg_tfo->tpg_get_tag(tpg)); 369 - spin_unlock_irq(&tpg->acl_node_lock); 530 + mutex_unlock(&tpg->acl_node_mutex); 370 531 return -ENODEV; 371 532 } 372 533 if (acl->dynamic_node_acl) { 373 534 acl->dynamic_node_acl = 0; 374 535 dynamic_acl = 1; 375 536 } 376 - spin_unlock_irq(&tpg->acl_node_lock); 537 + mutex_unlock(&tpg->acl_node_mutex); 377 538 378 539 spin_lock_irqsave(&tpg->session_lock, flags); 379 540 list_for_each_entry(sess, &tpg->tpg_sess_list, sess_list) { ··· 389 550 tpg->se_tpg_tfo->get_fabric_name(), initiatorname); 390 551 spin_unlock_irqrestore(&tpg->session_lock, flags); 391 552 392 - spin_lock_irq(&tpg->acl_node_lock); 553 + mutex_lock(&tpg->acl_node_mutex); 393 554 if (dynamic_acl) 394 555 acl->dynamic_node_acl = 1; 395 - spin_unlock_irq(&tpg->acl_node_lock); 556 + mutex_unlock(&tpg->acl_node_mutex); 396 557 return -EEXIST; 397 558 } 398 559 /* ··· 427 588 if (init_sess) 428 589 tpg->se_tpg_tfo->close_session(init_sess); 429 590 430 - spin_lock_irq(&tpg->acl_node_lock); 591 + mutex_lock(&tpg->acl_node_mutex); 431 592 if (dynamic_acl) 432 593 acl->dynamic_node_acl = 1; 433 - spin_unlock_irq(&tpg->acl_node_lock); 594 + mutex_unlock(&tpg->acl_node_mutex); 434 595 return -EINVAL; 435 596 } 436 597 spin_unlock_irqrestore(&tpg->session_lock, flags); ··· 446 607 initiatorname, tpg->se_tpg_tfo->get_fabric_name(), 447 608 tpg->se_tpg_tfo->tpg_get_tag(tpg)); 448 609 449 - spin_lock_irq(&tpg->acl_node_lock); 610 + mutex_lock(&tpg->acl_node_mutex); 450 611 if (dynamic_acl) 451 612 acl->dynamic_node_acl = 1; 452 - spin_unlock_irq(&tpg->acl_node_lock); 613 + mutex_unlock(&tpg->acl_node_mutex); 453 614 454 615 return 0; 455 616 } ··· 485 646 complete(&lun->lun_ref_comp); 486 647 } 487 648 488 - static int core_tpg_setup_virtual_lun0(struct se_portal_group *se_tpg) 489 - { 490 - /* Set in core_dev_setup_virtual_lun0() */ 491 - struct se_device *dev = g_lun0_dev; 492 - struct se_lun *lun = &se_tpg->tpg_virt_lun0; 493 - u32 lun_access = TRANSPORT_LUNFLAGS_READ_ONLY; 494 - int ret; 495 - 496 - lun->unpacked_lun = 0; 497 - lun->lun_status = TRANSPORT_LUN_STATUS_FREE; 498 - atomic_set(&lun->lun_acl_count, 0); 499 - init_completion(&lun->lun_shutdown_comp); 500 - INIT_LIST_HEAD(&lun->lun_acl_list); 501 - spin_lock_init(&lun->lun_acl_lock); 502 - spin_lock_init(&lun->lun_sep_lock); 503 - init_completion(&lun->lun_ref_comp); 504 - 505 - ret = core_tpg_add_lun(se_tpg, lun, lun_access, dev); 506 - if (ret < 0) 507 - return ret; 508 - 509 - return 0; 510 - } 511 - 512 649 int core_tpg_register( 513 - const struct target_core_fabric_ops *tfo, 514 650 struct se_wwn *se_wwn, 515 651 struct se_portal_group *se_tpg, 516 - void *tpg_fabric_ptr, 517 - int se_tpg_type) 652 + int proto_id) 518 653 { 519 - struct se_lun *lun; 520 - u32 i; 654 + int ret; 521 655 522 - se_tpg->tpg_lun_list = array_zalloc(TRANSPORT_MAX_LUNS_PER_TPG, 523 - sizeof(struct se_lun), GFP_KERNEL); 524 - if (!se_tpg->tpg_lun_list) { 525 - pr_err("Unable to allocate struct se_portal_group->" 526 - "tpg_lun_list\n"); 527 - return -ENOMEM; 656 + if (!se_tpg) 657 + return -EINVAL; 658 + /* 659 + * For the typical case where core_tpg_register() is called by a 660 + * fabric driver from target_core_fabric_ops->fabric_make_tpg() 661 + * configfs context, use the original tf_ops pointer already saved 662 + * by target-core in target_fabric_make_wwn(). 663 + * 664 + * Otherwise, for special cases like iscsi-target discovery TPGs 665 + * the caller is responsible for setting ->se_tpg_tfo ahead of 666 + * calling core_tpg_register(). 667 + */ 668 + if (se_wwn) 669 + se_tpg->se_tpg_tfo = se_wwn->wwn_tf->tf_ops; 670 + 671 + if (!se_tpg->se_tpg_tfo) { 672 + pr_err("Unable to locate se_tpg->se_tpg_tfo pointer\n"); 673 + return -EINVAL; 528 674 } 529 675 530 - for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { 531 - lun = se_tpg->tpg_lun_list[i]; 532 - lun->unpacked_lun = i; 533 - lun->lun_link_magic = SE_LUN_LINK_MAGIC; 534 - lun->lun_status = TRANSPORT_LUN_STATUS_FREE; 535 - atomic_set(&lun->lun_acl_count, 0); 536 - init_completion(&lun->lun_shutdown_comp); 537 - INIT_LIST_HEAD(&lun->lun_acl_list); 538 - spin_lock_init(&lun->lun_acl_lock); 539 - spin_lock_init(&lun->lun_sep_lock); 540 - init_completion(&lun->lun_ref_comp); 541 - } 542 - 543 - se_tpg->se_tpg_type = se_tpg_type; 544 - se_tpg->se_tpg_fabric_ptr = tpg_fabric_ptr; 545 - se_tpg->se_tpg_tfo = tfo; 676 + INIT_HLIST_HEAD(&se_tpg->tpg_lun_hlist); 677 + se_tpg->proto_id = proto_id; 546 678 se_tpg->se_tpg_wwn = se_wwn; 547 679 atomic_set(&se_tpg->tpg_pr_ref_count, 0); 548 680 INIT_LIST_HEAD(&se_tpg->acl_node_list); 549 681 INIT_LIST_HEAD(&se_tpg->se_tpg_node); 550 682 INIT_LIST_HEAD(&se_tpg->tpg_sess_list); 551 - spin_lock_init(&se_tpg->acl_node_lock); 552 683 spin_lock_init(&se_tpg->session_lock); 553 - spin_lock_init(&se_tpg->tpg_lun_lock); 684 + mutex_init(&se_tpg->tpg_lun_mutex); 685 + mutex_init(&se_tpg->acl_node_mutex); 554 686 555 - if (se_tpg->se_tpg_type == TRANSPORT_TPG_TYPE_NORMAL) { 556 - if (core_tpg_setup_virtual_lun0(se_tpg) < 0) { 557 - array_free(se_tpg->tpg_lun_list, 558 - TRANSPORT_MAX_LUNS_PER_TPG); 559 - return -ENOMEM; 687 + if (se_tpg->proto_id >= 0) { 688 + se_tpg->tpg_virt_lun0 = core_tpg_alloc_lun(se_tpg, 0); 689 + if (IS_ERR(se_tpg->tpg_virt_lun0)) 690 + return PTR_ERR(se_tpg->tpg_virt_lun0); 691 + 692 + ret = core_tpg_add_lun(se_tpg, se_tpg->tpg_virt_lun0, 693 + TRANSPORT_LUNFLAGS_READ_ONLY, g_lun0_dev); 694 + if (ret < 0) { 695 + kfree(se_tpg->tpg_virt_lun0); 696 + return ret; 560 697 } 561 698 } 562 699 ··· 540 725 list_add_tail(&se_tpg->se_tpg_node, &tpg_list); 541 726 spin_unlock_bh(&tpg_lock); 542 727 543 - pr_debug("TARGET_CORE[%s]: Allocated %s struct se_portal_group for" 544 - " endpoint: %s, Portal Tag: %u\n", tfo->get_fabric_name(), 545 - (se_tpg->se_tpg_type == TRANSPORT_TPG_TYPE_NORMAL) ? 546 - "Normal" : "Discovery", (tfo->tpg_get_wwn(se_tpg) == NULL) ? 547 - "None" : tfo->tpg_get_wwn(se_tpg), tfo->tpg_get_tag(se_tpg)); 728 + pr_debug("TARGET_CORE[%s]: Allocated portal_group for endpoint: %s, " 729 + "Proto: %d, Portal Tag: %u\n", se_tpg->se_tpg_tfo->get_fabric_name(), 730 + se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg) ? 731 + se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg) : NULL, 732 + se_tpg->proto_id, se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); 548 733 549 734 return 0; 550 735 } ··· 552 737 553 738 int core_tpg_deregister(struct se_portal_group *se_tpg) 554 739 { 740 + const struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo; 555 741 struct se_node_acl *nacl, *nacl_tmp; 742 + LIST_HEAD(node_list); 556 743 557 - pr_debug("TARGET_CORE[%s]: Deallocating %s struct se_portal_group" 558 - " for endpoint: %s Portal Tag %u\n", 559 - (se_tpg->se_tpg_type == TRANSPORT_TPG_TYPE_NORMAL) ? 560 - "Normal" : "Discovery", se_tpg->se_tpg_tfo->get_fabric_name(), 561 - se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg), 562 - se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); 744 + pr_debug("TARGET_CORE[%s]: Deallocating portal_group for endpoint: %s, " 745 + "Proto: %d, Portal Tag: %u\n", tfo->get_fabric_name(), 746 + tfo->tpg_get_wwn(se_tpg) ? tfo->tpg_get_wwn(se_tpg) : NULL, 747 + se_tpg->proto_id, tfo->tpg_get_tag(se_tpg)); 563 748 564 749 spin_lock_bh(&tpg_lock); 565 750 list_del(&se_tpg->se_tpg_node); ··· 567 752 568 753 while (atomic_read(&se_tpg->tpg_pr_ref_count) != 0) 569 754 cpu_relax(); 755 + 756 + mutex_lock(&se_tpg->acl_node_mutex); 757 + list_splice_init(&se_tpg->acl_node_list, &node_list); 758 + mutex_unlock(&se_tpg->acl_node_mutex); 570 759 /* 571 760 * Release any remaining demo-mode generated se_node_acl that have 572 761 * not been released because of TFO->tpg_check_demo_mode_cache() == 1 573 762 * in transport_deregister_session(). 574 763 */ 575 - spin_lock_irq(&se_tpg->acl_node_lock); 576 - list_for_each_entry_safe(nacl, nacl_tmp, &se_tpg->acl_node_list, 577 - acl_list) { 764 + list_for_each_entry_safe(nacl, nacl_tmp, &node_list, acl_list) { 578 765 list_del(&nacl->acl_list); 579 766 se_tpg->num_node_acls--; 580 - spin_unlock_irq(&se_tpg->acl_node_lock); 581 767 582 768 core_tpg_wait_for_nacl_pr_ref(nacl); 583 769 core_free_device_list_for_node(nacl, se_tpg); 584 - se_tpg->se_tpg_tfo->tpg_release_fabric_acl(se_tpg, nacl); 585 - 586 - spin_lock_irq(&se_tpg->acl_node_lock); 770 + kfree(nacl); 587 771 } 588 - spin_unlock_irq(&se_tpg->acl_node_lock); 589 772 590 - if (se_tpg->se_tpg_type == TRANSPORT_TPG_TYPE_NORMAL) 591 - core_tpg_remove_lun(se_tpg, &se_tpg->tpg_virt_lun0); 773 + if (se_tpg->proto_id >= 0) { 774 + core_tpg_remove_lun(se_tpg, se_tpg->tpg_virt_lun0); 775 + kfree_rcu(se_tpg->tpg_virt_lun0, rcu_head); 776 + } 592 777 593 - se_tpg->se_tpg_fabric_ptr = NULL; 594 - array_free(se_tpg->tpg_lun_list, TRANSPORT_MAX_LUNS_PER_TPG); 595 778 return 0; 596 779 } 597 780 EXPORT_SYMBOL(core_tpg_deregister); 598 781 599 782 struct se_lun *core_tpg_alloc_lun( 600 783 struct se_portal_group *tpg, 601 - u32 unpacked_lun) 784 + u64 unpacked_lun) 602 785 { 603 786 struct se_lun *lun; 604 787 605 - if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { 606 - pr_err("%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER_TPG" 607 - "-1: %u for Target Portal Group: %u\n", 608 - tpg->se_tpg_tfo->get_fabric_name(), 609 - unpacked_lun, TRANSPORT_MAX_LUNS_PER_TPG-1, 610 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 611 - return ERR_PTR(-EOVERFLOW); 788 + lun = kzalloc(sizeof(*lun), GFP_KERNEL); 789 + if (!lun) { 790 + pr_err("Unable to allocate se_lun memory\n"); 791 + return ERR_PTR(-ENOMEM); 612 792 } 613 - 614 - spin_lock(&tpg->tpg_lun_lock); 615 - lun = tpg->tpg_lun_list[unpacked_lun]; 616 - if (lun->lun_status == TRANSPORT_LUN_STATUS_ACTIVE) { 617 - pr_err("TPG Logical Unit Number: %u is already active" 618 - " on %s Target Portal Group: %u, ignoring request.\n", 619 - unpacked_lun, tpg->se_tpg_tfo->get_fabric_name(), 620 - tpg->se_tpg_tfo->tpg_get_tag(tpg)); 621 - spin_unlock(&tpg->tpg_lun_lock); 622 - return ERR_PTR(-EINVAL); 623 - } 624 - spin_unlock(&tpg->tpg_lun_lock); 793 + lun->unpacked_lun = unpacked_lun; 794 + lun->lun_link_magic = SE_LUN_LINK_MAGIC; 795 + atomic_set(&lun->lun_acl_count, 0); 796 + init_completion(&lun->lun_ref_comp); 797 + INIT_LIST_HEAD(&lun->lun_deve_list); 798 + INIT_LIST_HEAD(&lun->lun_dev_link); 799 + atomic_set(&lun->lun_tg_pt_secondary_offline, 0); 800 + spin_lock_init(&lun->lun_deve_lock); 801 + mutex_init(&lun->lun_tg_pt_md_mutex); 802 + INIT_LIST_HEAD(&lun->lun_tg_pt_gp_link); 803 + spin_lock_init(&lun->lun_tg_pt_gp_lock); 804 + lun->lun_tpg = tpg; 625 805 626 806 return lun; 627 807 } ··· 632 822 ret = percpu_ref_init(&lun->lun_ref, core_tpg_lun_ref_release, 0, 633 823 GFP_KERNEL); 634 824 if (ret < 0) 635 - return ret; 825 + goto out; 636 826 637 - ret = core_dev_export(dev, tpg, lun); 638 - if (ret < 0) { 639 - percpu_ref_exit(&lun->lun_ref); 640 - return ret; 641 - } 827 + ret = core_alloc_rtpi(lun, dev); 828 + if (ret) 829 + goto out_kill_ref; 642 830 643 - spin_lock(&tpg->tpg_lun_lock); 831 + if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) && 832 + !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) 833 + target_attach_tg_pt_gp(lun, dev->t10_alua.default_tg_pt_gp); 834 + 835 + mutex_lock(&tpg->tpg_lun_mutex); 836 + 837 + spin_lock(&dev->se_port_lock); 838 + lun->lun_index = dev->dev_index; 839 + rcu_assign_pointer(lun->lun_se_dev, dev); 840 + dev->export_count++; 841 + list_add_tail(&lun->lun_dev_link, &dev->dev_sep_list); 842 + spin_unlock(&dev->se_port_lock); 843 + 644 844 lun->lun_access = lun_access; 645 - lun->lun_status = TRANSPORT_LUN_STATUS_ACTIVE; 646 - spin_unlock(&tpg->tpg_lun_lock); 845 + if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) 846 + hlist_add_head_rcu(&lun->link, &tpg->tpg_lun_hlist); 847 + mutex_unlock(&tpg->tpg_lun_mutex); 647 848 648 849 return 0; 850 + 851 + out_kill_ref: 852 + percpu_ref_exit(&lun->lun_ref); 853 + out: 854 + return ret; 649 855 } 650 856 651 857 void core_tpg_remove_lun( 652 858 struct se_portal_group *tpg, 653 859 struct se_lun *lun) 654 860 { 861 + /* 862 + * rcu_dereference_raw protected by se_lun->lun_group symlink 863 + * reference to se_device->dev_group. 864 + */ 865 + struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev); 866 + 655 867 core_clear_lun_from_tpg(lun, tpg); 868 + /* 869 + * Wait for any active I/O references to percpu se_lun->lun_ref to 870 + * be released. Also, se_lun->lun_ref is now used by PR and ALUA 871 + * logic when referencing a remote target port during ALL_TGT_PT=1 872 + * and generating UNIT_ATTENTIONs for ALUA access state transition. 873 + */ 656 874 transport_clear_lun_ref(lun); 657 875 658 - core_dev_unexport(lun->lun_se_dev, tpg, lun); 876 + mutex_lock(&tpg->tpg_lun_mutex); 877 + if (lun->lun_se_dev) { 878 + target_detach_tg_pt_gp(lun); 659 879 660 - spin_lock(&tpg->tpg_lun_lock); 661 - lun->lun_status = TRANSPORT_LUN_STATUS_FREE; 662 - spin_unlock(&tpg->tpg_lun_lock); 880 + spin_lock(&dev->se_port_lock); 881 + list_del(&lun->lun_dev_link); 882 + dev->export_count--; 883 + rcu_assign_pointer(lun->lun_se_dev, NULL); 884 + spin_unlock(&dev->se_port_lock); 885 + } 886 + if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) 887 + hlist_del_rcu(&lun->link); 888 + mutex_unlock(&tpg->tpg_lun_mutex); 663 889 664 890 percpu_ref_exit(&lun->lun_ref); 665 891 }
+108 -141
drivers/target/target_core_transport.c
··· 43 43 #include <target/target_core_base.h> 44 44 #include <target/target_core_backend.h> 45 45 #include <target/target_core_fabric.h> 46 - #include <target/target_core_configfs.h> 47 46 48 47 #include "target_core_internal.h" 49 48 #include "target_core_alua.h" ··· 59 60 struct kmem_cache *t10_alua_lu_gp_cache; 60 61 struct kmem_cache *t10_alua_lu_gp_mem_cache; 61 62 struct kmem_cache *t10_alua_tg_pt_gp_cache; 62 - struct kmem_cache *t10_alua_tg_pt_gp_mem_cache; 63 63 struct kmem_cache *t10_alua_lba_map_cache; 64 64 struct kmem_cache *t10_alua_lba_map_mem_cache; 65 65 ··· 117 119 "cache failed\n"); 118 120 goto out_free_lu_gp_mem_cache; 119 121 } 120 - t10_alua_tg_pt_gp_mem_cache = kmem_cache_create( 121 - "t10_alua_tg_pt_gp_mem_cache", 122 - sizeof(struct t10_alua_tg_pt_gp_member), 123 - __alignof__(struct t10_alua_tg_pt_gp_member), 124 - 0, NULL); 125 - if (!t10_alua_tg_pt_gp_mem_cache) { 126 - pr_err("kmem_cache_create() for t10_alua_tg_pt_gp_" 127 - "mem_t failed\n"); 128 - goto out_free_tg_pt_gp_cache; 129 - } 130 122 t10_alua_lba_map_cache = kmem_cache_create( 131 123 "t10_alua_lba_map_cache", 132 124 sizeof(struct t10_alua_lba_map), ··· 124 136 if (!t10_alua_lba_map_cache) { 125 137 pr_err("kmem_cache_create() for t10_alua_lba_map_" 126 138 "cache failed\n"); 127 - goto out_free_tg_pt_gp_mem_cache; 139 + goto out_free_tg_pt_gp_cache; 128 140 } 129 141 t10_alua_lba_map_mem_cache = kmem_cache_create( 130 142 "t10_alua_lba_map_mem_cache", ··· 147 159 kmem_cache_destroy(t10_alua_lba_map_mem_cache); 148 160 out_free_lba_map_cache: 149 161 kmem_cache_destroy(t10_alua_lba_map_cache); 150 - out_free_tg_pt_gp_mem_cache: 151 - kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache); 152 162 out_free_tg_pt_gp_cache: 153 163 kmem_cache_destroy(t10_alua_tg_pt_gp_cache); 154 164 out_free_lu_gp_mem_cache: ··· 172 186 kmem_cache_destroy(t10_alua_lu_gp_cache); 173 187 kmem_cache_destroy(t10_alua_lu_gp_mem_cache); 174 188 kmem_cache_destroy(t10_alua_tg_pt_gp_cache); 175 - kmem_cache_destroy(t10_alua_tg_pt_gp_mem_cache); 176 189 kmem_cache_destroy(t10_alua_lba_map_cache); 177 190 kmem_cache_destroy(t10_alua_lba_map_mem_cache); 178 191 } ··· 391 406 392 407 void target_put_session(struct se_session *se_sess) 393 408 { 394 - struct se_portal_group *tpg = se_sess->se_tpg; 395 - 396 - if (tpg->se_tpg_tfo->put_session != NULL) { 397 - tpg->se_tpg_tfo->put_session(se_sess); 398 - return; 399 - } 400 409 kref_put(&se_sess->sess_kref, target_release_session); 401 410 } 402 411 EXPORT_SYMBOL(target_put_session); ··· 477 498 const struct target_core_fabric_ops *se_tfo; 478 499 struct se_node_acl *se_nacl; 479 500 unsigned long flags; 480 - bool comp_nacl = true; 501 + bool comp_nacl = true, drop_nacl = false; 481 502 482 503 if (!se_tpg) { 483 504 transport_free_session(se_sess); ··· 497 518 */ 498 519 se_nacl = se_sess->se_node_acl; 499 520 500 - spin_lock_irqsave(&se_tpg->acl_node_lock, flags); 521 + mutex_lock(&se_tpg->acl_node_mutex); 501 522 if (se_nacl && se_nacl->dynamic_node_acl) { 502 523 if (!se_tfo->tpg_check_demo_mode_cache(se_tpg)) { 503 524 list_del(&se_nacl->acl_list); 504 525 se_tpg->num_node_acls--; 505 - spin_unlock_irqrestore(&se_tpg->acl_node_lock, flags); 506 - core_tpg_wait_for_nacl_pr_ref(se_nacl); 507 - core_free_device_list_for_node(se_nacl, se_tpg); 508 - se_tfo->tpg_release_fabric_acl(se_tpg, se_nacl); 509 - 510 - comp_nacl = false; 511 - spin_lock_irqsave(&se_tpg->acl_node_lock, flags); 526 + drop_nacl = true; 512 527 } 513 528 } 514 - spin_unlock_irqrestore(&se_tpg->acl_node_lock, flags); 529 + mutex_unlock(&se_tpg->acl_node_mutex); 515 530 531 + if (drop_nacl) { 532 + core_tpg_wait_for_nacl_pr_ref(se_nacl); 533 + core_free_device_list_for_node(se_nacl, se_tpg); 534 + kfree(se_nacl); 535 + comp_nacl = false; 536 + } 516 537 pr_debug("TARGET_CORE[%s]: Deregistered fabric_sess\n", 517 538 se_tpg->se_tpg_tfo->get_fabric_name()); 518 539 /* ··· 572 593 * this command for frontend exceptions. 573 594 */ 574 595 if (cmd->transport_state & CMD_T_STOP) { 575 - pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n", 576 - __func__, __LINE__, 577 - cmd->se_tfo->get_task_tag(cmd)); 596 + pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08llx\n", 597 + __func__, __LINE__, cmd->tag); 578 598 579 599 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 580 600 ··· 1126 1148 /* 1127 1149 * Used by fabric modules containing a local struct se_cmd within their 1128 1150 * fabric dependent per I/O descriptor. 1151 + * 1152 + * Preserves the value of @cmd->tag. 1129 1153 */ 1130 1154 void transport_init_se_cmd( 1131 1155 struct se_cmd *cmd, ··· 1254 1274 return ret; 1255 1275 1256 1276 cmd->se_cmd_flags |= SCF_SUPPORTED_SAM_OPCODE; 1257 - 1258 - spin_lock(&cmd->se_lun->lun_sep_lock); 1259 - if (cmd->se_lun->lun_sep) 1260 - cmd->se_lun->lun_sep->sep_stats.cmd_pdus++; 1261 - spin_unlock(&cmd->se_lun->lun_sep_lock); 1277 + atomic_long_inc(&cmd->se_lun->lun_stats.cmd_pdus); 1262 1278 return 0; 1263 1279 } 1264 1280 EXPORT_SYMBOL(target_setup_cmd_from_cdb); ··· 1322 1346 1323 1347 cmd->t_data_sg = sgl; 1324 1348 cmd->t_data_nents = sgl_count; 1349 + cmd->t_bidi_data_sg = sgl_bidi; 1350 + cmd->t_bidi_data_nents = sgl_bidi_count; 1325 1351 1326 - if (sgl_bidi && sgl_bidi_count) { 1327 - cmd->t_bidi_data_sg = sgl_bidi; 1328 - cmd->t_bidi_data_nents = sgl_bidi_count; 1329 - } 1330 1352 cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC; 1331 1353 return 0; 1332 1354 } ··· 1349 1375 * @sgl_prot: struct scatterlist memory protection information 1350 1376 * @sgl_prot_count: scatterlist count for protection information 1351 1377 * 1378 + * Task tags are supported if the caller has set @se_cmd->tag. 1379 + * 1352 1380 * Returns non zero to signal active I/O shutdown failure. All other 1353 1381 * setup exceptions will be returned as a SCSI CHECK_CONDITION response, 1354 1382 * but still return zero here. ··· 1359 1383 * assumes internal allocation of fabric payload buffer by target-core. 1360 1384 */ 1361 1385 int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess, 1362 - unsigned char *cdb, unsigned char *sense, u32 unpacked_lun, 1386 + unsigned char *cdb, unsigned char *sense, u64 unpacked_lun, 1363 1387 u32 data_length, int task_attr, int data_dir, int flags, 1364 1388 struct scatterlist *sgl, u32 sgl_count, 1365 1389 struct scatterlist *sgl_bidi, u32 sgl_bidi_count, ··· 1388 1412 * for fabrics using TARGET_SCF_ACK_KREF that expect a second 1389 1413 * kref_put() to happen during fabric packet acknowledgement. 1390 1414 */ 1391 - ret = target_get_sess_cmd(se_sess, se_cmd, (flags & TARGET_SCF_ACK_KREF)); 1415 + ret = target_get_sess_cmd(se_cmd, flags & TARGET_SCF_ACK_KREF); 1392 1416 if (ret) 1393 1417 return ret; 1394 1418 /* ··· 1402 1426 rc = transport_lookup_cmd_lun(se_cmd, unpacked_lun); 1403 1427 if (rc) { 1404 1428 transport_send_check_condition_and_sense(se_cmd, rc, 0); 1405 - target_put_sess_cmd(se_sess, se_cmd); 1429 + target_put_sess_cmd(se_cmd); 1406 1430 return 0; 1407 1431 } 1408 1432 ··· 1419 1443 if (sgl_prot_count) { 1420 1444 se_cmd->t_prot_sg = sgl_prot; 1421 1445 se_cmd->t_prot_nents = sgl_prot_count; 1446 + se_cmd->se_cmd_flags |= SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC; 1422 1447 } 1423 1448 1424 1449 /* ··· 1483 1506 * @data_dir: DMA data direction 1484 1507 * @flags: flags for command submission from target_sc_flags_tables 1485 1508 * 1509 + * Task tags are supported if the caller has set @se_cmd->tag. 1510 + * 1486 1511 * Returns non zero to signal active I/O shutdown failure. All other 1487 1512 * setup exceptions will be returned as a SCSI CHECK_CONDITION response, 1488 1513 * but still return zero here. ··· 1495 1516 * It also assumes interal target core SGL memory allocation. 1496 1517 */ 1497 1518 int target_submit_cmd(struct se_cmd *se_cmd, struct se_session *se_sess, 1498 - unsigned char *cdb, unsigned char *sense, u32 unpacked_lun, 1519 + unsigned char *cdb, unsigned char *sense, u64 unpacked_lun, 1499 1520 u32 data_length, int task_attr, int data_dir, int flags) 1500 1521 { 1501 1522 return target_submit_cmd_map_sgls(se_cmd, se_sess, cdb, sense, ··· 1532 1553 **/ 1533 1554 1534 1555 int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, 1535 - unsigned char *sense, u32 unpacked_lun, 1556 + unsigned char *sense, u64 unpacked_lun, 1536 1557 void *fabric_tmr_ptr, unsigned char tm_type, 1537 1558 gfp_t gfp, unsigned int tag, int flags) 1538 1559 { ··· 1556 1577 se_cmd->se_tmr_req->ref_task_tag = tag; 1557 1578 1558 1579 /* See target_submit_cmd for commentary */ 1559 - ret = target_get_sess_cmd(se_sess, se_cmd, (flags & TARGET_SCF_ACK_KREF)); 1580 + ret = target_get_sess_cmd(se_cmd, flags & TARGET_SCF_ACK_KREF); 1560 1581 if (ret) { 1561 1582 core_tmr_release_req(se_cmd->se_tmr_req); 1562 1583 return ret; ··· 1612 1633 { 1613 1634 int ret = 0; 1614 1635 1615 - pr_debug("-----[ Storage Engine Exception for cmd: %p ITT: 0x%08x" 1616 - " CDB: 0x%02x\n", cmd, cmd->se_tfo->get_task_tag(cmd), 1617 - cmd->t_task_cdb[0]); 1636 + pr_debug("-----[ Storage Engine Exception for cmd: %p ITT: 0x%08llx" 1637 + " CDB: 0x%02x\n", cmd, cmd->tag, cmd->t_task_cdb[0]); 1618 1638 pr_debug("-----[ i_state: %d t_state: %d sense_reason: %d\n", 1619 1639 cmd->se_tfo->get_cmd_state(cmd), 1620 1640 cmd->t_state, sense_reason); ··· 1670 1692 * See spc4r17, section 7.4.6 Control Mode Page, Table 349 1671 1693 */ 1672 1694 if (cmd->se_sess && 1673 - cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl == 2) 1674 - core_scsi3_ua_allocate(cmd->se_sess->se_node_acl, 1675 - cmd->orig_fe_lun, 0x2C, 1676 - ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS); 1677 - 1695 + cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl == 2) { 1696 + target_ua_allocate_lun(cmd->se_sess->se_node_acl, 1697 + cmd->orig_fe_lun, 0x2C, 1698 + ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS); 1699 + } 1678 1700 trace_target_cmd_complete(cmd); 1679 - ret = cmd->se_tfo-> queue_status(cmd); 1701 + ret = cmd->se_tfo->queue_status(cmd); 1680 1702 if (ret == -EAGAIN || ret == -ENOMEM) 1681 1703 goto queue_full; 1682 1704 goto check_stop; ··· 1737 1759 break; 1738 1760 1739 1761 sectors = cmd->data_length >> ilog2(cmd->se_dev->dev_attrib.block_size); 1740 - cmd->pi_err = sbc_dif_verify_write(cmd, cmd->t_task_lba, 1741 - sectors, 0, NULL, 0); 1762 + cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, 1763 + sectors, 0, cmd->t_prot_sg, 0); 1742 1764 if (unlikely(cmd->pi_err)) { 1743 1765 spin_lock_irq(&cmd->t_state_lock); 1744 1766 cmd->transport_state &= ~(CMD_T_BUSY|CMD_T_SENT); ··· 1821 1843 */ 1822 1844 spin_lock_irq(&cmd->t_state_lock); 1823 1845 if (cmd->transport_state & CMD_T_STOP) { 1824 - pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n", 1825 - __func__, __LINE__, 1826 - cmd->se_tfo->get_task_tag(cmd)); 1846 + pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08llx\n", 1847 + __func__, __LINE__, cmd->tag); 1827 1848 1828 1849 spin_unlock_irq(&cmd->t_state_lock); 1829 1850 complete_all(&cmd->t_transport_stop_comp); ··· 1961 1984 1962 1985 static bool target_read_prot_action(struct se_cmd *cmd) 1963 1986 { 1964 - sense_reason_t rc; 1965 - 1966 1987 switch (cmd->prot_op) { 1967 1988 case TARGET_PROT_DIN_STRIP: 1968 1989 if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_STRIP)) { 1969 - rc = sbc_dif_read_strip(cmd); 1970 - if (rc) { 1971 - cmd->pi_err = rc; 1990 + u32 sectors = cmd->data_length >> 1991 + ilog2(cmd->se_dev->dev_attrib.block_size); 1992 + 1993 + cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, 1994 + sectors, 0, cmd->t_prot_sg, 1995 + 0); 1996 + if (cmd->pi_err) 1972 1997 return true; 1973 - } 1974 1998 } 1975 1999 break; 1976 2000 case TARGET_PROT_DIN_INSERT: ··· 2050 2072 queue_rsp: 2051 2073 switch (cmd->data_direction) { 2052 2074 case DMA_FROM_DEVICE: 2053 - spin_lock(&cmd->se_lun->lun_sep_lock); 2054 - if (cmd->se_lun->lun_sep) { 2055 - cmd->se_lun->lun_sep->sep_stats.tx_data_octets += 2056 - cmd->data_length; 2057 - } 2058 - spin_unlock(&cmd->se_lun->lun_sep_lock); 2075 + atomic_long_add(cmd->data_length, 2076 + &cmd->se_lun->lun_stats.tx_data_octets); 2059 2077 /* 2060 2078 * Perform READ_STRIP of PI using software emulation when 2061 2079 * backend had PI enabled, if the transport will not be ··· 2074 2100 goto queue_full; 2075 2101 break; 2076 2102 case DMA_TO_DEVICE: 2077 - spin_lock(&cmd->se_lun->lun_sep_lock); 2078 - if (cmd->se_lun->lun_sep) { 2079 - cmd->se_lun->lun_sep->sep_stats.rx_data_octets += 2080 - cmd->data_length; 2081 - } 2082 - spin_unlock(&cmd->se_lun->lun_sep_lock); 2103 + atomic_long_add(cmd->data_length, 2104 + &cmd->se_lun->lun_stats.rx_data_octets); 2083 2105 /* 2084 2106 * Check if we need to send READ payload for BIDI-COMMAND 2085 2107 */ 2086 2108 if (cmd->se_cmd_flags & SCF_BIDI) { 2087 - spin_lock(&cmd->se_lun->lun_sep_lock); 2088 - if (cmd->se_lun->lun_sep) { 2089 - cmd->se_lun->lun_sep->sep_stats.tx_data_octets += 2090 - cmd->data_length; 2091 - } 2092 - spin_unlock(&cmd->se_lun->lun_sep_lock); 2109 + atomic_long_add(cmd->data_length, 2110 + &cmd->se_lun->lun_stats.tx_data_octets); 2093 2111 ret = cmd->se_tfo->queue_data_in(cmd); 2094 2112 if (ret == -EAGAIN || ret == -ENOMEM) 2095 2113 goto queue_full; ··· 2138 2172 2139 2173 static inline void transport_free_pages(struct se_cmd *cmd) 2140 2174 { 2175 + if (!(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) { 2176 + transport_free_sgl(cmd->t_prot_sg, cmd->t_prot_nents); 2177 + cmd->t_prot_sg = NULL; 2178 + cmd->t_prot_nents = 0; 2179 + } 2180 + 2141 2181 if (cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) { 2142 2182 /* 2143 2183 * Release special case READ buffer payload required for ··· 2167 2195 transport_free_sgl(cmd->t_bidi_data_sg, cmd->t_bidi_data_nents); 2168 2196 cmd->t_bidi_data_sg = NULL; 2169 2197 cmd->t_bidi_data_nents = 0; 2170 - 2171 - transport_free_sgl(cmd->t_prot_sg, cmd->t_prot_nents); 2172 - cmd->t_prot_sg = NULL; 2173 - cmd->t_prot_nents = 0; 2174 2198 } 2175 2199 2176 2200 /** ··· 2188 2220 * If this cmd has been setup with target_get_sess_cmd(), drop 2189 2221 * the kref and call ->release_cmd() in kref callback. 2190 2222 */ 2191 - return target_put_sess_cmd(cmd->se_sess, cmd); 2223 + return target_put_sess_cmd(cmd); 2192 2224 } 2193 2225 2194 2226 /** ··· 2305 2337 int ret = 0; 2306 2338 bool zero_flag = !(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB); 2307 2339 2340 + if (cmd->prot_op != TARGET_PROT_NORMAL && 2341 + !(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) { 2342 + ret = target_alloc_sgl(&cmd->t_prot_sg, &cmd->t_prot_nents, 2343 + cmd->prot_length, true); 2344 + if (ret < 0) 2345 + return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 2346 + } 2347 + 2308 2348 /* 2309 2349 * Determine is the TCM fabric module has already allocated physical 2310 2350 * memory, and is directly calling transport_generic_map_mem_to_cmd() ··· 2334 2358 ret = target_alloc_sgl(&cmd->t_bidi_data_sg, 2335 2359 &cmd->t_bidi_data_nents, 2336 2360 bidi_length, zero_flag); 2337 - if (ret < 0) 2338 - return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 2339 - } 2340 - 2341 - if (cmd->prot_op != TARGET_PROT_NORMAL) { 2342 - ret = target_alloc_sgl(&cmd->t_prot_sg, 2343 - &cmd->t_prot_nents, 2344 - cmd->prot_length, true); 2345 2361 if (ret < 0) 2346 2362 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; 2347 2363 } ··· 2432 2464 EXPORT_SYMBOL(transport_generic_free_cmd); 2433 2465 2434 2466 /* target_get_sess_cmd - Add command to active ->sess_cmd_list 2435 - * @se_sess: session to reference 2436 2467 * @se_cmd: command descriptor to add 2437 2468 * @ack_kref: Signal that fabric will perform an ack target_put_sess_cmd() 2438 2469 */ 2439 - int target_get_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd, 2440 - bool ack_kref) 2470 + int target_get_sess_cmd(struct se_cmd *se_cmd, bool ack_kref) 2441 2471 { 2472 + struct se_session *se_sess = se_cmd->se_sess; 2442 2473 unsigned long flags; 2443 2474 int ret = 0; 2444 2475 ··· 2459 2492 spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags); 2460 2493 2461 2494 if (ret && ack_kref) 2462 - target_put_sess_cmd(se_sess, se_cmd); 2495 + target_put_sess_cmd(se_cmd); 2463 2496 2464 2497 return ret; 2465 2498 } ··· 2488 2521 } 2489 2522 2490 2523 /* target_put_sess_cmd - Check for active I/O shutdown via kref_put 2491 - * @se_sess: session to reference 2492 2524 * @se_cmd: command descriptor to drop 2493 2525 */ 2494 - int target_put_sess_cmd(struct se_session *se_sess, struct se_cmd *se_cmd) 2526 + int target_put_sess_cmd(struct se_cmd *se_cmd) 2495 2527 { 2528 + struct se_session *se_sess = se_cmd->se_sess; 2529 + 2496 2530 if (!se_sess) { 2497 2531 se_cmd->se_tfo->release_cmd(se_cmd); 2498 2532 return 1; ··· 2559 2591 } 2560 2592 EXPORT_SYMBOL(target_wait_for_sess_cmds); 2561 2593 2562 - static int transport_clear_lun_ref_thread(void *p) 2594 + void transport_clear_lun_ref(struct se_lun *lun) 2563 2595 { 2564 - struct se_lun *lun = p; 2565 - 2566 2596 percpu_ref_kill(&lun->lun_ref); 2567 - 2568 2597 wait_for_completion(&lun->lun_ref_comp); 2569 - complete(&lun->lun_shutdown_comp); 2570 - 2571 - return 0; 2572 - } 2573 - 2574 - int transport_clear_lun_ref(struct se_lun *lun) 2575 - { 2576 - struct task_struct *kt; 2577 - 2578 - kt = kthread_run(transport_clear_lun_ref_thread, lun, 2579 - "tcm_cl_%u", lun->unpacked_lun); 2580 - if (IS_ERR(kt)) { 2581 - pr_err("Unable to start clear_lun thread\n"); 2582 - return PTR_ERR(kt); 2583 - } 2584 - wait_for_completion(&lun->lun_shutdown_comp); 2585 - 2586 - return 0; 2587 2598 } 2588 2599 2589 2600 /** ··· 2596 2649 2597 2650 cmd->transport_state |= CMD_T_STOP; 2598 2651 2599 - pr_debug("wait_for_tasks: Stopping %p ITT: 0x%08x" 2600 - " i_state: %d, t_state: %d, CMD_T_STOP\n", 2601 - cmd, cmd->se_tfo->get_task_tag(cmd), 2602 - cmd->se_tfo->get_cmd_state(cmd), cmd->t_state); 2652 + pr_debug("wait_for_tasks: Stopping %p ITT: 0x%08llx i_state: %d, t_state: %d, CMD_T_STOP\n", 2653 + cmd, cmd->tag, cmd->se_tfo->get_cmd_state(cmd), cmd->t_state); 2603 2654 2604 2655 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2605 2656 ··· 2606 2661 spin_lock_irqsave(&cmd->t_state_lock, flags); 2607 2662 cmd->transport_state &= ~(CMD_T_ACTIVE | CMD_T_STOP); 2608 2663 2609 - pr_debug("wait_for_tasks: Stopped wait_for_completion(" 2610 - "&cmd->t_transport_stop_comp) for ITT: 0x%08x\n", 2611 - cmd->se_tfo->get_task_tag(cmd)); 2664 + pr_debug("wait_for_tasks: Stopped wait_for_completion(&cmd->t_transport_stop_comp) for ITT: 0x%08llx\n", 2665 + cmd->tag); 2612 2666 2613 2667 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2614 2668 ··· 2909 2965 if (!send_status || !(cmd->se_cmd_flags & SCF_SEND_DELAYED_TAS)) 2910 2966 return 1; 2911 2967 2912 - pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB: 0x%02x ITT: 0x%08x\n", 2913 - cmd->t_task_cdb[0], cmd->se_tfo->get_task_tag(cmd)); 2968 + pr_debug("Sending delayed SAM_STAT_TASK_ABORTED status for CDB: 0x%02x ITT: 0x%08llx\n", 2969 + cmd->t_task_cdb[0], cmd->tag); 2914 2970 2915 2971 cmd->se_cmd_flags &= ~SCF_SEND_DELAYED_TAS; 2916 2972 cmd->scsi_status = SAM_STAT_TASK_ABORTED; ··· 2949 3005 2950 3006 transport_lun_remove_cmd(cmd); 2951 3007 2952 - pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x," 2953 - " ITT: 0x%08x\n", cmd->t_task_cdb[0], 2954 - cmd->se_tfo->get_task_tag(cmd)); 3008 + pr_debug("Setting SAM_STAT_TASK_ABORTED status for CDB: 0x%02x, ITT: 0x%08llx\n", 3009 + cmd->t_task_cdb[0], cmd->tag); 2955 3010 2956 3011 trace_target_cmd_complete(cmd); 2957 3012 cmd->se_tfo->queue_status(cmd); ··· 2976 3033 ret = core_tmr_lun_reset(dev, tmr, NULL, NULL); 2977 3034 tmr->response = (!ret) ? TMR_FUNCTION_COMPLETE : 2978 3035 TMR_FUNCTION_REJECTED; 3036 + if (tmr->response == TMR_FUNCTION_COMPLETE) { 3037 + target_ua_allocate_lun(cmd->se_sess->se_node_acl, 3038 + cmd->orig_fe_lun, 0x29, 3039 + ASCQ_29H_BUS_DEVICE_RESET_FUNCTION_OCCURRED); 3040 + } 2979 3041 break; 2980 3042 case TMR_TARGET_WARM_RESET: 2981 3043 tmr->response = TMR_FUNCTION_REJECTED; ··· 3015 3067 return 0; 3016 3068 } 3017 3069 EXPORT_SYMBOL(transport_generic_handle_tmr); 3070 + 3071 + bool 3072 + target_check_wce(struct se_device *dev) 3073 + { 3074 + bool wce = false; 3075 + 3076 + if (dev->transport->get_write_cache) 3077 + wce = dev->transport->get_write_cache(dev); 3078 + else if (dev->dev_attrib.emulate_write_cache > 0) 3079 + wce = true; 3080 + 3081 + return wce; 3082 + } 3083 + 3084 + bool 3085 + target_check_fua(struct se_device *dev) 3086 + { 3087 + return target_check_wce(dev) && dev->dev_attrib.emulate_fua_write > 0; 3088 + }
+50 -31
drivers/target/target_core_ua.c
··· 29 29 30 30 #include <target/target_core_base.h> 31 31 #include <target/target_core_fabric.h> 32 - #include <target/target_core_configfs.h> 33 32 34 33 #include "target_core_internal.h" 35 34 #include "target_core_alua.h" ··· 49 50 if (!nacl) 50 51 return 0; 51 52 52 - deve = nacl->device_list[cmd->orig_fe_lun]; 53 - if (!atomic_read(&deve->ua_count)) 53 + rcu_read_lock(); 54 + deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); 55 + if (!deve) { 56 + rcu_read_unlock(); 54 57 return 0; 58 + } 59 + if (!atomic_read(&deve->ua_count)) { 60 + rcu_read_unlock(); 61 + return 0; 62 + } 63 + rcu_read_unlock(); 55 64 /* 56 65 * From sam4r14, section 5.14 Unit attention condition: 57 66 * ··· 86 79 } 87 80 88 81 int core_scsi3_ua_allocate( 89 - struct se_node_acl *nacl, 90 - u32 unpacked_lun, 82 + struct se_dev_entry *deve, 91 83 u8 asc, 92 84 u8 ascq) 93 85 { 94 - struct se_dev_entry *deve; 95 86 struct se_ua *ua, *ua_p, *ua_tmp; 96 - /* 97 - * PASSTHROUGH OPS 98 - */ 99 - if (!nacl) 100 - return -EINVAL; 101 87 102 88 ua = kmem_cache_zalloc(se_ua_cache, GFP_ATOMIC); 103 89 if (!ua) { ··· 99 99 } 100 100 INIT_LIST_HEAD(&ua->ua_nacl_list); 101 101 102 - ua->ua_nacl = nacl; 103 102 ua->ua_asc = asc; 104 103 ua->ua_ascq = ascq; 105 - 106 - spin_lock_irq(&nacl->device_list_lock); 107 - deve = nacl->device_list[unpacked_lun]; 108 104 109 105 spin_lock(&deve->ua_lock); 110 106 list_for_each_entry_safe(ua_p, ua_tmp, &deve->ua_list, ua_nacl_list) { ··· 109 113 */ 110 114 if ((ua_p->ua_asc == asc) && (ua_p->ua_ascq == ascq)) { 111 115 spin_unlock(&deve->ua_lock); 112 - spin_unlock_irq(&nacl->device_list_lock); 113 116 kmem_cache_free(se_ua_cache, ua); 114 117 return 0; 115 118 } ··· 153 158 list_add_tail(&ua->ua_nacl_list, 154 159 &deve->ua_list); 155 160 spin_unlock(&deve->ua_lock); 156 - spin_unlock_irq(&nacl->device_list_lock); 157 161 158 162 atomic_inc_mb(&deve->ua_count); 159 163 return 0; 160 164 } 161 165 list_add_tail(&ua->ua_nacl_list, &deve->ua_list); 162 166 spin_unlock(&deve->ua_lock); 163 - spin_unlock_irq(&nacl->device_list_lock); 164 167 165 - pr_debug("[%s]: Allocated UNIT ATTENTION, mapped LUN: %u, ASC:" 166 - " 0x%02x, ASCQ: 0x%02x\n", 167 - nacl->se_tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, 168 + pr_debug("Allocated UNIT ATTENTION, mapped LUN: %llu, ASC:" 169 + " 0x%02x, ASCQ: 0x%02x\n", deve->mapped_lun, 168 170 asc, ascq); 169 171 170 172 atomic_inc_mb(&deve->ua_count); 171 173 return 0; 174 + } 175 + 176 + void target_ua_allocate_lun(struct se_node_acl *nacl, 177 + u32 unpacked_lun, u8 asc, u8 ascq) 178 + { 179 + struct se_dev_entry *deve; 180 + 181 + if (!nacl) 182 + return; 183 + 184 + rcu_read_lock(); 185 + deve = target_nacl_find_deve(nacl, unpacked_lun); 186 + if (!deve) { 187 + rcu_read_unlock(); 188 + return; 189 + } 190 + 191 + core_scsi3_ua_allocate(deve, asc, ascq); 192 + rcu_read_unlock(); 172 193 } 173 194 174 195 void core_scsi3_ua_release_all( ··· 221 210 if (!nacl) 222 211 return; 223 212 224 - spin_lock_irq(&nacl->device_list_lock); 225 - deve = nacl->device_list[cmd->orig_fe_lun]; 213 + rcu_read_lock(); 214 + deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); 215 + if (!deve) { 216 + rcu_read_unlock(); 217 + return; 218 + } 226 219 if (!atomic_read(&deve->ua_count)) { 227 - spin_unlock_irq(&nacl->device_list_lock); 220 + rcu_read_unlock(); 228 221 return; 229 222 } 230 223 /* ··· 264 249 atomic_dec_mb(&deve->ua_count); 265 250 } 266 251 spin_unlock(&deve->ua_lock); 267 - spin_unlock_irq(&nacl->device_list_lock); 252 + rcu_read_unlock(); 268 253 269 254 pr_debug("[%s]: %s UNIT ATTENTION condition with" 270 - " INTLCK_CTRL: %d, mapped LUN: %u, got CDB: 0x%02x" 255 + " INTLCK_CTRL: %d, mapped LUN: %llu, got CDB: 0x%02x" 271 256 " reported ASC: 0x%02x, ASCQ: 0x%02x\n", 272 257 nacl->se_tpg->se_tpg_tfo->get_fabric_name(), 273 258 (dev->dev_attrib.emulate_ua_intlck_ctrl != 0) ? "Reporting" : ··· 293 278 if (!nacl) 294 279 return -EINVAL; 295 280 296 - spin_lock_irq(&nacl->device_list_lock); 297 - deve = nacl->device_list[cmd->orig_fe_lun]; 281 + rcu_read_lock(); 282 + deve = target_nacl_find_deve(nacl, cmd->orig_fe_lun); 283 + if (!deve) { 284 + rcu_read_unlock(); 285 + return -EINVAL; 286 + } 298 287 if (!atomic_read(&deve->ua_count)) { 299 - spin_unlock_irq(&nacl->device_list_lock); 288 + rcu_read_unlock(); 300 289 return -EPERM; 301 290 } 302 291 /* ··· 326 307 atomic_dec_mb(&deve->ua_count); 327 308 } 328 309 spin_unlock(&deve->ua_lock); 329 - spin_unlock_irq(&nacl->device_list_lock); 310 + rcu_read_unlock(); 330 311 331 312 pr_debug("[%s]: Released UNIT ATTENTION condition, mapped" 332 - " LUN: %u, got REQUEST_SENSE reported ASC: 0x%02x," 313 + " LUN: %llu, got REQUEST_SENSE reported ASC: 0x%02x," 333 314 " ASCQ: 0x%02x\n", nacl->se_tpg->se_tpg_tfo->get_fabric_name(), 334 315 cmd->orig_fe_lun, *asc, *ascq); 335 316
+5 -1
drivers/target/target_core_ua.h
··· 25 25 26 26 #define ASCQ_2CH_PREVIOUS_RESERVATION_CONFLICT_STATUS 0x09 27 27 28 + #define ASCQ_3FH_INQUIRY_DATA_HAS_CHANGED 0x03 29 + #define ASCQ_3FH_REPORTED_LUNS_DATA_HAS_CHANGED 0x0E 30 + 28 31 extern struct kmem_cache *se_ua_cache; 29 32 30 33 extern sense_reason_t target_scsi3_ua_check(struct se_cmd *); 31 - extern int core_scsi3_ua_allocate(struct se_node_acl *, u32, u8, u8); 34 + extern int core_scsi3_ua_allocate(struct se_dev_entry *, u8, u8); 35 + extern void target_ua_allocate_lun(struct se_node_acl *, u32, u8, u8); 32 36 extern void core_scsi3_ua_release_all(struct se_dev_entry *); 33 37 extern void core_scsi3_ua_for_check_condition(struct se_cmd *, u8 *, u8 *); 34 38 extern int core_scsi3_ua_clear_for_request_sense(struct se_cmd *,
+146 -118
drivers/target/target_core_user.c
··· 1 1 /* 2 2 * Copyright (C) 2013 Shaohua Li <shli@kernel.org> 3 3 * Copyright (C) 2014 Red Hat, Inc. 4 + * Copyright (C) 2015 Arrikto, Inc. 4 5 * 5 6 * This program is free software; you can redistribute it and/or modify it 6 7 * under the terms and conditions of the GNU General Public License, ··· 31 30 #include <target/target_core_base.h> 32 31 #include <target/target_core_fabric.h> 33 32 #include <target/target_core_backend.h> 34 - #include <target/target_core_backend_configfs.h> 35 33 36 34 #include <linux/target_core_user.h> 37 35 ··· 168 168 tcmu_cmd->tcmu_dev = udev; 169 169 tcmu_cmd->data_length = se_cmd->data_length; 170 170 171 + if (se_cmd->se_cmd_flags & SCF_BIDI) { 172 + BUG_ON(!(se_cmd->t_bidi_data_sg && se_cmd->t_bidi_data_nents)); 173 + tcmu_cmd->data_length += se_cmd->t_bidi_data_sg->length; 174 + } 175 + 171 176 tcmu_cmd->deadline = jiffies + msecs_to_jiffies(TCMU_TIME_OUT); 172 177 173 178 idr_preload(GFP_KERNEL); ··· 231 226 232 227 #define UPDATE_HEAD(head, used, size) smp_store_release(&head, ((head % size) + used) % size) 233 228 229 + static void alloc_and_scatter_data_area(struct tcmu_dev *udev, 230 + struct scatterlist *data_sg, unsigned int data_nents, 231 + struct iovec **iov, int *iov_cnt, bool copy_data) 232 + { 233 + int i; 234 + void *from, *to; 235 + size_t copy_bytes; 236 + struct scatterlist *sg; 237 + 238 + for_each_sg(data_sg, sg, data_nents, i) { 239 + copy_bytes = min_t(size_t, sg->length, 240 + head_to_end(udev->data_head, udev->data_size)); 241 + from = kmap_atomic(sg_page(sg)) + sg->offset; 242 + to = (void *) udev->mb_addr + udev->data_off + udev->data_head; 243 + 244 + if (copy_data) { 245 + memcpy(to, from, copy_bytes); 246 + tcmu_flush_dcache_range(to, copy_bytes); 247 + } 248 + 249 + /* Even iov_base is relative to mb_addr */ 250 + (*iov)->iov_len = copy_bytes; 251 + (*iov)->iov_base = (void __user *) udev->data_off + 252 + udev->data_head; 253 + (*iov_cnt)++; 254 + (*iov)++; 255 + 256 + UPDATE_HEAD(udev->data_head, copy_bytes, udev->data_size); 257 + 258 + /* Uh oh, we wrapped the buffer. Must split sg across 2 iovs. */ 259 + if (sg->length != copy_bytes) { 260 + void *from_skip = from + copy_bytes; 261 + 262 + copy_bytes = sg->length - copy_bytes; 263 + 264 + (*iov)->iov_len = copy_bytes; 265 + (*iov)->iov_base = (void __user *) udev->data_off + 266 + udev->data_head; 267 + 268 + if (copy_data) { 269 + to = (void *) udev->mb_addr + 270 + udev->data_off + udev->data_head; 271 + memcpy(to, from_skip, copy_bytes); 272 + tcmu_flush_dcache_range(to, copy_bytes); 273 + } 274 + 275 + (*iov_cnt)++; 276 + (*iov)++; 277 + 278 + UPDATE_HEAD(udev->data_head, 279 + copy_bytes, udev->data_size); 280 + } 281 + 282 + kunmap_atomic(from - sg->offset); 283 + } 284 + } 285 + 286 + static void gather_and_free_data_area(struct tcmu_dev *udev, 287 + struct scatterlist *data_sg, unsigned int data_nents) 288 + { 289 + int i; 290 + void *from, *to; 291 + size_t copy_bytes; 292 + struct scatterlist *sg; 293 + 294 + /* It'd be easier to look at entry's iovec again, but UAM */ 295 + for_each_sg(data_sg, sg, data_nents, i) { 296 + copy_bytes = min_t(size_t, sg->length, 297 + head_to_end(udev->data_tail, udev->data_size)); 298 + 299 + to = kmap_atomic(sg_page(sg)) + sg->offset; 300 + WARN_ON(sg->length + sg->offset > PAGE_SIZE); 301 + from = (void *) udev->mb_addr + 302 + udev->data_off + udev->data_tail; 303 + tcmu_flush_dcache_range(from, copy_bytes); 304 + memcpy(to, from, copy_bytes); 305 + 306 + UPDATE_HEAD(udev->data_tail, copy_bytes, udev->data_size); 307 + 308 + /* Uh oh, wrapped the data buffer for this sg's data */ 309 + if (sg->length != copy_bytes) { 310 + void *to_skip = to + copy_bytes; 311 + 312 + from = (void *) udev->mb_addr + 313 + udev->data_off + udev->data_tail; 314 + WARN_ON(udev->data_tail); 315 + copy_bytes = sg->length - copy_bytes; 316 + tcmu_flush_dcache_range(from, copy_bytes); 317 + memcpy(to_skip, from, copy_bytes); 318 + 319 + UPDATE_HEAD(udev->data_tail, 320 + copy_bytes, udev->data_size); 321 + } 322 + kunmap_atomic(to - sg->offset); 323 + } 324 + } 325 + 234 326 /* 235 - * We can't queue a command until we have space available on the cmd ring *and* space 236 - * space avail on the data ring. 327 + * We can't queue a command until we have space available on the cmd ring *and* 328 + * space available on the data ring. 237 329 * 238 330 * Called with ring lock held. 239 331 */ ··· 378 276 size_t base_command_size, command_size; 379 277 struct tcmu_mailbox *mb; 380 278 struct tcmu_cmd_entry *entry; 381 - int i; 382 - struct scatterlist *sg; 383 279 struct iovec *iov; 384 - int iov_cnt = 0; 280 + int iov_cnt; 385 281 uint32_t cmd_head; 386 282 uint64_t cdb_off; 283 + bool copy_to_data_area; 387 284 388 285 if (test_bit(TCMU_DEV_BIT_BROKEN, &udev->flags)) 389 286 return -EINVAL; ··· 395 294 * b/c size == offsetof one-past-element. 396 295 */ 397 296 base_command_size = max(offsetof(struct tcmu_cmd_entry, 398 - req.iov[se_cmd->t_data_nents + 2]), 297 + req.iov[se_cmd->t_bidi_data_nents + 298 + se_cmd->t_data_nents + 2]), 399 299 sizeof(struct tcmu_cmd_entry)); 400 300 command_size = base_command_size 401 301 + round_up(scsi_command_size(se_cmd->t_task_cdb), TCMU_OP_ALIGN_SIZE); ··· 464 362 * Fix up iovecs, and handle if allocation in data ring wrapped. 465 363 */ 466 364 iov = &entry->req.iov[0]; 467 - for_each_sg(se_cmd->t_data_sg, sg, se_cmd->t_data_nents, i) { 468 - size_t copy_bytes = min((size_t)sg->length, 469 - head_to_end(udev->data_head, udev->data_size)); 470 - void *from = kmap_atomic(sg_page(sg)) + sg->offset; 471 - void *to = (void *) mb + udev->data_off + udev->data_head; 472 - 473 - if (tcmu_cmd->se_cmd->data_direction == DMA_TO_DEVICE) { 474 - memcpy(to, from, copy_bytes); 475 - tcmu_flush_dcache_range(to, copy_bytes); 476 - } 477 - 478 - /* Even iov_base is relative to mb_addr */ 479 - iov->iov_len = copy_bytes; 480 - iov->iov_base = (void __user *) udev->data_off + 481 - udev->data_head; 482 - iov_cnt++; 483 - iov++; 484 - 485 - UPDATE_HEAD(udev->data_head, copy_bytes, udev->data_size); 486 - 487 - /* Uh oh, we wrapped the buffer. Must split sg across 2 iovs. */ 488 - if (sg->length != copy_bytes) { 489 - from += copy_bytes; 490 - copy_bytes = sg->length - copy_bytes; 491 - 492 - iov->iov_len = copy_bytes; 493 - iov->iov_base = (void __user *) udev->data_off + 494 - udev->data_head; 495 - 496 - if (se_cmd->data_direction == DMA_TO_DEVICE) { 497 - to = (void *) mb + udev->data_off + udev->data_head; 498 - memcpy(to, from, copy_bytes); 499 - tcmu_flush_dcache_range(to, copy_bytes); 500 - } 501 - 502 - iov_cnt++; 503 - iov++; 504 - 505 - UPDATE_HEAD(udev->data_head, copy_bytes, udev->data_size); 506 - } 507 - 508 - kunmap_atomic(from); 509 - } 365 + iov_cnt = 0; 366 + copy_to_data_area = (se_cmd->data_direction == DMA_TO_DEVICE 367 + || se_cmd->se_cmd_flags & SCF_BIDI); 368 + alloc_and_scatter_data_area(udev, se_cmd->t_data_sg, 369 + se_cmd->t_data_nents, &iov, &iov_cnt, copy_to_data_area); 510 370 entry->req.iov_cnt = iov_cnt; 511 - entry->req.iov_bidi_cnt = 0; 512 371 entry->req.iov_dif_cnt = 0; 372 + 373 + /* Handle BIDI commands */ 374 + iov_cnt = 0; 375 + alloc_and_scatter_data_area(udev, se_cmd->t_bidi_data_sg, 376 + se_cmd->t_bidi_data_nents, &iov, &iov_cnt, false); 377 + entry->req.iov_bidi_cnt = iov_cnt; 513 378 514 379 /* All offsets relative to mb_addr, not start of entry! */ 515 380 cdb_off = CMDR_OFF + cmd_head + base_command_size; ··· 550 481 se_cmd->scsi_sense_length); 551 482 552 483 UPDATE_HEAD(udev->data_tail, cmd->data_length, udev->data_size); 553 - } 554 - else if (se_cmd->data_direction == DMA_FROM_DEVICE) { 555 - struct scatterlist *sg; 556 - int i; 484 + } else if (se_cmd->se_cmd_flags & SCF_BIDI) { 485 + /* Discard data_out buffer */ 486 + UPDATE_HEAD(udev->data_tail, 487 + (size_t)se_cmd->t_data_sg->length, udev->data_size); 557 488 558 - /* It'd be easier to look at entry's iovec again, but UAM */ 559 - for_each_sg(se_cmd->t_data_sg, sg, se_cmd->t_data_nents, i) { 560 - size_t copy_bytes; 561 - void *to; 562 - void *from; 563 - 564 - copy_bytes = min((size_t)sg->length, 565 - head_to_end(udev->data_tail, udev->data_size)); 566 - 567 - to = kmap_atomic(sg_page(sg)) + sg->offset; 568 - WARN_ON(sg->length + sg->offset > PAGE_SIZE); 569 - from = (void *) udev->mb_addr + udev->data_off + udev->data_tail; 570 - tcmu_flush_dcache_range(from, copy_bytes); 571 - memcpy(to, from, copy_bytes); 572 - 573 - UPDATE_HEAD(udev->data_tail, copy_bytes, udev->data_size); 574 - 575 - /* Uh oh, wrapped the data buffer for this sg's data */ 576 - if (sg->length != copy_bytes) { 577 - from = (void *) udev->mb_addr + udev->data_off + udev->data_tail; 578 - WARN_ON(udev->data_tail); 579 - to += copy_bytes; 580 - copy_bytes = sg->length - copy_bytes; 581 - tcmu_flush_dcache_range(from, copy_bytes); 582 - memcpy(to, from, copy_bytes); 583 - 584 - UPDATE_HEAD(udev->data_tail, copy_bytes, udev->data_size); 585 - } 586 - 587 - kunmap_atomic(to); 588 - } 589 - 489 + /* Get Data-In buffer */ 490 + gather_and_free_data_area(udev, 491 + se_cmd->t_bidi_data_sg, se_cmd->t_bidi_data_nents); 492 + } else if (se_cmd->data_direction == DMA_FROM_DEVICE) { 493 + gather_and_free_data_area(udev, 494 + se_cmd->t_data_sg, se_cmd->t_data_nents); 590 495 } else if (se_cmd->data_direction == DMA_TO_DEVICE) { 591 496 UPDATE_HEAD(udev->data_tail, cmd->data_length, udev->data_size); 592 - } else { 593 - pr_warn("TCMU: data direction was %d!\n", se_cmd->data_direction); 497 + } else if (se_cmd->data_direction != DMA_NONE) { 498 + pr_warn("TCMU: data direction was %d!\n", 499 + se_cmd->data_direction); 594 500 } 595 501 596 502 target_complete_cmd(cmd->se_cmd, entry->rsp.scsi_status); ··· 954 910 return -EINVAL; 955 911 } 956 912 913 + static void tcmu_dev_call_rcu(struct rcu_head *p) 914 + { 915 + struct se_device *dev = container_of(p, struct se_device, rcu_head); 916 + struct tcmu_dev *udev = TCMU_DEV(dev); 917 + 918 + kfree(udev); 919 + } 920 + 957 921 static void tcmu_free_device(struct se_device *dev) 958 922 { 959 923 struct tcmu_dev *udev = TCMU_DEV(dev); ··· 987 935 kfree(udev->uio_info.name); 988 936 kfree(udev->name); 989 937 } 990 - 991 - kfree(udev); 938 + call_rcu(&dev->rcu_head, tcmu_dev_call_rcu); 992 939 } 993 940 994 941 enum { ··· 1105 1054 return passthrough_parse_cdb(cmd, tcmu_pass_op); 1106 1055 } 1107 1056 1108 - DEF_TB_DEV_ATTRIB_RO(tcmu, hw_pi_prot_type); 1109 - TB_DEV_ATTR_RO(tcmu, hw_pi_prot_type); 1110 - 1111 - DEF_TB_DEV_ATTRIB_RO(tcmu, hw_block_size); 1112 - TB_DEV_ATTR_RO(tcmu, hw_block_size); 1113 - 1114 - DEF_TB_DEV_ATTRIB_RO(tcmu, hw_max_sectors); 1115 - TB_DEV_ATTR_RO(tcmu, hw_max_sectors); 1116 - 1117 - DEF_TB_DEV_ATTRIB_RO(tcmu, hw_queue_depth); 1118 - TB_DEV_ATTR_RO(tcmu, hw_queue_depth); 1119 - 1120 - static struct configfs_attribute *tcmu_backend_dev_attrs[] = { 1121 - &tcmu_dev_attrib_hw_pi_prot_type.attr, 1122 - &tcmu_dev_attrib_hw_block_size.attr, 1123 - &tcmu_dev_attrib_hw_max_sectors.attr, 1124 - &tcmu_dev_attrib_hw_queue_depth.attr, 1125 - NULL, 1126 - }; 1127 - 1128 - static struct se_subsystem_api tcmu_template = { 1057 + static const struct target_backend_ops tcmu_ops = { 1129 1058 .name = "user", 1130 1059 .inquiry_prod = "USER", 1131 1060 .inquiry_rev = TCMU_VERSION, ··· 1121 1090 .show_configfs_dev_params = tcmu_show_configfs_dev_params, 1122 1091 .get_device_type = sbc_get_device_type, 1123 1092 .get_blocks = tcmu_get_blocks, 1093 + .tb_dev_attrib_attrs = passthrough_attrib_attrs, 1124 1094 }; 1125 1095 1126 1096 static int __init tcmu_module_init(void) 1127 1097 { 1128 - struct target_backend_cits *tbc = &tcmu_template.tb_cits; 1129 1098 int ret; 1130 1099 1131 1100 BUILD_BUG_ON((sizeof(struct tcmu_cmd_entry) % TCMU_OP_ALIGN_SIZE) != 0); ··· 1148 1117 goto out_unreg_device; 1149 1118 } 1150 1119 1151 - target_core_setup_sub_cits(&tcmu_template); 1152 - tbc->tb_dev_attrib_cit.ct_attrs = tcmu_backend_dev_attrs; 1153 - 1154 - ret = transport_subsystem_register(&tcmu_template); 1120 + ret = transport_backend_register(&tcmu_ops); 1155 1121 if (ret) 1156 1122 goto out_unreg_genl; 1157 1123 ··· 1166 1138 1167 1139 static void __exit tcmu_module_exit(void) 1168 1140 { 1169 - transport_subsystem_release(&tcmu_template); 1141 + target_backend_unregister(&tcmu_ops); 1170 1142 genl_unregister_family(&tcmu_genl_family); 1171 1143 root_device_unregister(tcmu_root_device); 1172 1144 kmem_cache_destroy(tcmu_cmd_cache);
+2 -23
drivers/target/target_core_xcopy.c
··· 31 31 #include <target/target_core_base.h> 32 32 #include <target/target_core_backend.h> 33 33 #include <target/target_core_fabric.h> 34 - #include <target/target_core_configfs.h> 35 34 36 35 #include "target_core_internal.h" 37 36 #include "target_core_pr.h" ··· 347 348 unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER]; 348 349 }; 349 350 350 - static struct se_port xcopy_pt_port; 351 - static struct se_portal_group xcopy_pt_tpg; 351 + struct se_portal_group xcopy_pt_tpg; 352 352 static struct se_session xcopy_pt_sess; 353 353 static struct se_node_acl xcopy_pt_nacl; 354 354 355 355 static char *xcopy_pt_get_fabric_name(void) 356 356 { 357 357 return "xcopy-pt"; 358 - } 359 - 360 - static u32 xcopy_pt_get_tag(struct se_cmd *se_cmd) 361 - { 362 - return 0; 363 358 } 364 359 365 360 static int xcopy_pt_get_cmd_state(struct se_cmd *se_cmd) ··· 416 423 417 424 static const struct target_core_fabric_ops xcopy_pt_tfo = { 418 425 .get_fabric_name = xcopy_pt_get_fabric_name, 419 - .get_task_tag = xcopy_pt_get_tag, 420 426 .get_cmd_state = xcopy_pt_get_cmd_state, 421 427 .release_cmd = xcopy_pt_release_cmd, 422 428 .check_stop_free = xcopy_pt_check_stop_free, ··· 437 445 return -ENOMEM; 438 446 } 439 447 440 - memset(&xcopy_pt_port, 0, sizeof(struct se_port)); 441 - INIT_LIST_HEAD(&xcopy_pt_port.sep_alua_list); 442 - INIT_LIST_HEAD(&xcopy_pt_port.sep_list); 443 - mutex_init(&xcopy_pt_port.sep_tg_pt_md_mutex); 444 - 445 448 memset(&xcopy_pt_tpg, 0, sizeof(struct se_portal_group)); 446 449 INIT_LIST_HEAD(&xcopy_pt_tpg.se_tpg_node); 447 450 INIT_LIST_HEAD(&xcopy_pt_tpg.acl_node_list); 448 451 INIT_LIST_HEAD(&xcopy_pt_tpg.tpg_sess_list); 449 452 450 - xcopy_pt_port.sep_tpg = &xcopy_pt_tpg; 451 453 xcopy_pt_tpg.se_tpg_tfo = &xcopy_pt_tfo; 452 454 453 455 memset(&xcopy_pt_nacl, 0, sizeof(struct se_node_acl)); ··· 482 496 */ 483 497 if (remote_port) { 484 498 xpt_cmd->remote_port = remote_port; 485 - pt_cmd->se_lun->lun_sep = &xcopy_pt_port; 486 - pr_debug("Setup emulated remote DEST xcopy_pt_port: %p to" 487 - " cmd->se_lun->lun_sep for X-COPY data PUSH\n", 488 - pt_cmd->se_lun->lun_sep); 489 499 } else { 490 500 pt_cmd->se_lun = ec_cmd->se_lun; 491 501 pt_cmd->se_dev = ec_cmd->se_dev; ··· 501 519 */ 502 520 if (remote_port) { 503 521 xpt_cmd->remote_port = remote_port; 504 - pt_cmd->se_lun->lun_sep = &xcopy_pt_port; 505 - pr_debug("Setup emulated remote SRC xcopy_pt_port: %p to" 506 - " cmd->se_lun->lun_sep for X-COPY data PULL\n", 507 - pt_cmd->se_lun->lun_sep); 508 522 } else { 509 523 pt_cmd->se_lun = ec_cmd->se_lun; 510 524 pt_cmd->se_dev = ec_cmd->se_dev; ··· 552 574 xpt_cmd->xcopy_op = xop; 553 575 target_xcopy_setup_pt_port(xpt_cmd, xop, remote_port); 554 576 577 + cmd->tag = 0; 555 578 sense_rc = target_setup_cmd_from_cdb(cmd, cdb); 556 579 if (sense_rc) { 557 580 ret = -EINVAL;
+1 -2
drivers/target/tcm_fc/tcm_fc.h
··· 80 80 * Node ACL for FC remote port session. 81 81 */ 82 82 struct ft_node_acl { 83 - struct ft_node_auth node_auth; 84 83 struct se_node_acl se_node_acl; 84 + struct ft_node_auth node_auth; 85 85 }; 86 86 87 87 struct ft_lun { ··· 157 157 int ft_queue_data_in(struct se_cmd *); 158 158 int ft_write_pending(struct se_cmd *); 159 159 int ft_write_pending_status(struct se_cmd *); 160 - u32 ft_get_task_tag(struct se_cmd *); 161 160 int ft_get_cmd_state(struct se_cmd *); 162 161 void ft_queue_tm_resp(struct se_cmd *); 163 162 void ft_aborted_task(struct se_cmd *);
+1 -10
drivers/target/tcm_fc/tfc_cmd.c
··· 36 36 37 37 #include <target/target_core_base.h> 38 38 #include <target/target_core_fabric.h> 39 - #include <target/target_core_configfs.h> 40 39 #include <target/configfs_macros.h> 41 40 42 41 #include "tcm_fc.h" ··· 240 241 } 241 242 lport->tt.seq_send(lport, cmd->seq, fp); 242 243 return 0; 243 - } 244 - 245 - u32 ft_get_task_tag(struct se_cmd *se_cmd) 246 - { 247 - struct ft_cmd *cmd = container_of(se_cmd, struct ft_cmd, se_cmd); 248 - 249 - if (cmd->aborted) 250 - return ~0; 251 - return fc_seq_exch(cmd->seq)->rxid; 252 244 } 253 245 254 246 int ft_get_cmd_state(struct se_cmd *se_cmd) ··· 554 564 } 555 565 556 566 fc_seq_exch(cmd->seq)->lp->tt.seq_set_resp(cmd->seq, ft_recv_seq, cmd); 567 + cmd->se_cmd.tag = fc_seq_exch(cmd->seq)->rxid; 557 568 /* 558 569 * Use a single se_cmd->cmd_kref as we expect to release se_cmd 559 570 * directly from ft_check_stop_free callback in response path.
+18 -94
drivers/target/tcm_fc/tfc_conf.c
··· 39 39 #include <target/target_core_base.h> 40 40 #include <target/target_core_fabric.h> 41 41 #include <target/target_core_fabric_configfs.h> 42 - #include <target/target_core_configfs.h> 43 42 #include <target/configfs_macros.h> 44 43 45 44 #include "tcm_fc.h" 46 - 47 - static const struct target_core_fabric_ops ft_fabric_ops; 48 45 49 46 static LIST_HEAD(ft_wwn_list); 50 47 DEFINE_MUTEX(ft_lport_lock); ··· 191 194 * Add ACL for an initiator. The ACL is named arbitrarily. 192 195 * The port_name and/or node_name are attributes. 193 196 */ 194 - static struct se_node_acl *ft_add_acl( 195 - struct se_portal_group *se_tpg, 196 - struct config_group *group, 197 - const char *name) 197 + static int ft_init_nodeacl(struct se_node_acl *nacl, const char *name) 198 198 { 199 - struct ft_node_acl *acl; 200 - struct ft_tpg *tpg; 199 + struct ft_node_acl *acl = 200 + container_of(nacl, struct ft_node_acl, se_node_acl); 201 201 u64 wwpn; 202 - u32 q_depth; 203 - 204 - pr_debug("add acl %s\n", name); 205 - tpg = container_of(se_tpg, struct ft_tpg, se_tpg); 206 202 207 203 if (ft_parse_wwn(name, &wwpn, 1) < 0) 208 - return ERR_PTR(-EINVAL); 204 + return -EINVAL; 209 205 210 - acl = kzalloc(sizeof(struct ft_node_acl), GFP_KERNEL); 211 - if (!acl) 212 - return ERR_PTR(-ENOMEM); 213 206 acl->node_auth.port_name = wwpn; 214 - 215 - q_depth = 32; /* XXX bogus default - get from tpg? */ 216 - return core_tpg_add_initiator_node_acl(&tpg->se_tpg, 217 - &acl->se_node_acl, name, q_depth); 218 - } 219 - 220 - static void ft_del_acl(struct se_node_acl *se_acl) 221 - { 222 - struct se_portal_group *se_tpg = se_acl->se_tpg; 223 - struct ft_tpg *tpg; 224 - struct ft_node_acl *acl = container_of(se_acl, 225 - struct ft_node_acl, se_node_acl); 226 - 227 - pr_debug("del acl %s\n", 228 - config_item_name(&se_acl->acl_group.cg_item)); 229 - 230 - tpg = container_of(se_tpg, struct ft_tpg, se_tpg); 231 - pr_debug("del acl %p se_acl %p tpg %p se_tpg %p\n", 232 - acl, se_acl, tpg, &tpg->se_tpg); 233 - 234 - core_tpg_del_initiator_node_acl(&tpg->se_tpg, se_acl, 1); 235 - kfree(acl); 207 + return 0; 236 208 } 237 209 238 210 struct ft_node_acl *ft_acl_get(struct ft_tpg *tpg, struct fc_rport_priv *rdata) ··· 211 245 struct se_portal_group *se_tpg = &tpg->se_tpg; 212 246 struct se_node_acl *se_acl; 213 247 214 - spin_lock_irq(&se_tpg->acl_node_lock); 248 + mutex_lock(&se_tpg->acl_node_mutex); 215 249 list_for_each_entry(se_acl, &se_tpg->acl_node_list, acl_list) { 216 250 acl = container_of(se_acl, struct ft_node_acl, se_node_acl); 217 251 pr_debug("acl %p port_name %llx\n", ··· 225 259 break; 226 260 } 227 261 } 228 - spin_unlock_irq(&se_tpg->acl_node_lock); 262 + mutex_unlock(&se_tpg->acl_node_mutex); 229 263 return found; 230 - } 231 - 232 - static struct se_node_acl *ft_tpg_alloc_fabric_acl(struct se_portal_group *se_tpg) 233 - { 234 - struct ft_node_acl *acl; 235 - 236 - acl = kzalloc(sizeof(*acl), GFP_KERNEL); 237 - if (!acl) { 238 - pr_err("Unable to allocate struct ft_node_acl\n"); 239 - return NULL; 240 - } 241 - pr_debug("acl %p\n", acl); 242 - return &acl->se_node_acl; 243 - } 244 - 245 - static void ft_tpg_release_fabric_acl(struct se_portal_group *se_tpg, 246 - struct se_node_acl *se_acl) 247 - { 248 - struct ft_node_acl *acl = container_of(se_acl, 249 - struct ft_node_acl, se_node_acl); 250 - 251 - pr_debug("acl %p\n", acl); 252 - kfree(acl); 253 264 } 254 265 255 266 /* ··· 276 333 return NULL; 277 334 } 278 335 279 - ret = core_tpg_register(&ft_fabric_ops, wwn, &tpg->se_tpg, 280 - tpg, TRANSPORT_TPG_TYPE_NORMAL); 336 + ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_FCP); 281 337 if (ret < 0) { 282 338 destroy_workqueue(wq); 283 339 kfree(tpg); ··· 401 459 NULL, 402 460 }; 403 461 462 + static inline struct ft_tpg *ft_tpg(struct se_portal_group *se_tpg) 463 + { 464 + return container_of(se_tpg, struct ft_tpg, se_tpg); 465 + } 466 + 404 467 static char *ft_get_fabric_name(void) 405 468 { 406 469 return "fc"; ··· 413 466 414 467 static char *ft_get_fabric_wwn(struct se_portal_group *se_tpg) 415 468 { 416 - struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr; 417 - 418 - return tpg->lport_wwn->name; 469 + return ft_tpg(se_tpg)->lport_wwn->name; 419 470 } 420 471 421 472 static u16 ft_get_tag(struct se_portal_group *se_tpg) 422 473 { 423 - struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr; 424 - 425 474 /* 426 475 * This tag is used when forming SCSI Name identifier in EVPD=1 0x83 427 476 * to represent the SCSI Target Port. 428 477 */ 429 - return tpg->index; 430 - } 431 - 432 - static u32 ft_get_default_depth(struct se_portal_group *se_tpg) 433 - { 434 - return 1; 478 + return ft_tpg(se_tpg)->index; 435 479 } 436 480 437 481 static int ft_check_false(struct se_portal_group *se_tpg) ··· 436 498 437 499 static u32 ft_tpg_get_inst_index(struct se_portal_group *se_tpg) 438 500 { 439 - struct ft_tpg *tpg = se_tpg->se_tpg_fabric_ptr; 440 - 441 - return tpg->index; 501 + return ft_tpg(se_tpg)->index; 442 502 } 443 503 444 504 static const struct target_core_fabric_ops ft_fabric_ops = { 445 505 .module = THIS_MODULE, 446 506 .name = "fc", 507 + .node_acl_size = sizeof(struct ft_node_acl), 447 508 .get_fabric_name = ft_get_fabric_name, 448 - .get_fabric_proto_ident = fc_get_fabric_proto_ident, 449 509 .tpg_get_wwn = ft_get_fabric_wwn, 450 510 .tpg_get_tag = ft_get_tag, 451 - .tpg_get_default_depth = ft_get_default_depth, 452 - .tpg_get_pr_transport_id = fc_get_pr_transport_id, 453 - .tpg_get_pr_transport_id_len = fc_get_pr_transport_id_len, 454 - .tpg_parse_pr_out_transport_id = fc_parse_pr_out_transport_id, 455 511 .tpg_check_demo_mode = ft_check_false, 456 512 .tpg_check_demo_mode_cache = ft_check_false, 457 513 .tpg_check_demo_mode_write_protect = ft_check_false, 458 514 .tpg_check_prod_mode_write_protect = ft_check_false, 459 - .tpg_alloc_fabric_acl = ft_tpg_alloc_fabric_acl, 460 - .tpg_release_fabric_acl = ft_tpg_release_fabric_acl, 461 515 .tpg_get_inst_index = ft_tpg_get_inst_index, 462 516 .check_stop_free = ft_check_stop_free, 463 517 .release_cmd = ft_release_cmd, ··· 460 530 .write_pending = ft_write_pending, 461 531 .write_pending_status = ft_write_pending_status, 462 532 .set_default_node_attributes = ft_set_default_node_attr, 463 - .get_task_tag = ft_get_task_tag, 464 533 .get_cmd_state = ft_get_cmd_state, 465 534 .queue_data_in = ft_queue_data_in, 466 535 .queue_status = ft_queue_status, ··· 473 544 .fabric_drop_wwn = &ft_del_wwn, 474 545 .fabric_make_tpg = &ft_add_tpg, 475 546 .fabric_drop_tpg = &ft_del_tpg, 476 - .fabric_post_link = NULL, 477 - .fabric_pre_unlink = NULL, 478 - .fabric_make_np = NULL, 479 - .fabric_drop_np = NULL, 480 - .fabric_make_nodeacl = &ft_add_acl, 481 - .fabric_drop_nodeacl = &ft_del_acl, 547 + .fabric_init_nodeacl = &ft_init_nodeacl, 482 548 483 549 .tfc_wwn_attrs = ft_wwn_attrs, 484 550 .tfc_tpg_nacl_base_attrs = ft_nacl_base_attrs,
-1
drivers/target/tcm_fc/tfc_io.c
··· 44 44 45 45 #include <target/target_core_base.h> 46 46 #include <target/target_core_fabric.h> 47 - #include <target/target_core_configfs.h> 48 47 #include <target/configfs_macros.h> 49 48 50 49 #include "tcm_fc.h"
-1
drivers/target/tcm_fc/tfc_sess.c
··· 36 36 37 37 #include <target/target_core_base.h> 38 38 #include <target/target_core_fabric.h> 39 - #include <target/target_core_configfs.h> 40 39 #include <target/configfs_macros.h> 41 40 42 41 #include "tcm_fc.h"
+12 -180
drivers/usb/gadget/legacy/tcm_usb_gadget.c
··· 20 20 #include <target/target_core_base.h> 21 21 #include <target/target_core_fabric.h> 22 22 #include <target/target_core_fabric_configfs.h> 23 - #include <target/target_core_configfs.h> 24 23 #include <target/configfs_macros.h> 25 24 #include <asm/unaligned.h> 26 25 27 26 #include "tcm_usb_gadget.h" 28 27 29 28 USB_GADGET_COMPOSITE_OPTIONS(); 30 - 31 - static const struct target_core_fabric_ops usbg_ops; 32 29 33 30 static inline struct f_uas *to_f_uas(struct usb_function *f) 34 31 { ··· 1108 1111 memcpy(cmd->cmd_buf, cmd_iu->cdb, cmd_len); 1109 1112 1110 1113 cmd->tag = be16_to_cpup(&cmd_iu->tag); 1114 + cmd->se_cmd.tag = cmd->tag; 1111 1115 if (fu->flags & USBG_USE_STREAMS) { 1112 1116 if (cmd->tag > UASP_SS_EP_COMP_NUM_STREAMS) 1113 1117 goto err; ··· 1242 1244 cmd->unpacked_lun = cbw->Lun; 1243 1245 cmd->is_read = cbw->Flags & US_BULK_FLAG_IN ? 1 : 0; 1244 1246 cmd->data_len = le32_to_cpu(cbw->DataTransferLength); 1247 + cmd->se_cmd.tag = le32_to_cpu(cmd->bot_tag); 1245 1248 1246 1249 INIT_WORK(&cmd->work, bot_cmd_work); 1247 1250 ret = queue_work(tpg->workqueue, &cmd->work); ··· 1272 1273 return "usb_gadget"; 1273 1274 } 1274 1275 1275 - static u8 usbg_get_fabric_proto_ident(struct se_portal_group *se_tpg) 1276 - { 1277 - struct usbg_tpg *tpg = container_of(se_tpg, 1278 - struct usbg_tpg, se_tpg); 1279 - struct usbg_tport *tport = tpg->tport; 1280 - u8 proto_id; 1281 - 1282 - switch (tport->tport_proto_id) { 1283 - case SCSI_PROTOCOL_SAS: 1284 - default: 1285 - proto_id = sas_get_fabric_proto_ident(se_tpg); 1286 - break; 1287 - } 1288 - 1289 - return proto_id; 1290 - } 1291 - 1292 1276 static char *usbg_get_fabric_wwn(struct se_portal_group *se_tpg) 1293 1277 { 1294 1278 struct usbg_tpg *tpg = container_of(se_tpg, ··· 1286 1304 struct usbg_tpg *tpg = container_of(se_tpg, 1287 1305 struct usbg_tpg, se_tpg); 1288 1306 return tpg->tport_tpgt; 1289 - } 1290 - 1291 - static u32 usbg_get_default_depth(struct se_portal_group *se_tpg) 1292 - { 1293 - return 1; 1294 - } 1295 - 1296 - static u32 usbg_get_pr_transport_id( 1297 - struct se_portal_group *se_tpg, 1298 - struct se_node_acl *se_nacl, 1299 - struct t10_pr_registration *pr_reg, 1300 - int *format_code, 1301 - unsigned char *buf) 1302 - { 1303 - struct usbg_tpg *tpg = container_of(se_tpg, 1304 - struct usbg_tpg, se_tpg); 1305 - struct usbg_tport *tport = tpg->tport; 1306 - int ret = 0; 1307 - 1308 - switch (tport->tport_proto_id) { 1309 - case SCSI_PROTOCOL_SAS: 1310 - default: 1311 - ret = sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 1312 - format_code, buf); 1313 - break; 1314 - } 1315 - 1316 - return ret; 1317 - } 1318 - 1319 - static u32 usbg_get_pr_transport_id_len( 1320 - struct se_portal_group *se_tpg, 1321 - struct se_node_acl *se_nacl, 1322 - struct t10_pr_registration *pr_reg, 1323 - int *format_code) 1324 - { 1325 - struct usbg_tpg *tpg = container_of(se_tpg, 1326 - struct usbg_tpg, se_tpg); 1327 - struct usbg_tport *tport = tpg->tport; 1328 - int ret = 0; 1329 - 1330 - switch (tport->tport_proto_id) { 1331 - case SCSI_PROTOCOL_SAS: 1332 - default: 1333 - ret = sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 1334 - format_code); 1335 - break; 1336 - } 1337 - 1338 - return ret; 1339 - } 1340 - 1341 - static char *usbg_parse_pr_out_transport_id( 1342 - struct se_portal_group *se_tpg, 1343 - const char *buf, 1344 - u32 *out_tid_len, 1345 - char **port_nexus_ptr) 1346 - { 1347 - struct usbg_tpg *tpg = container_of(se_tpg, 1348 - struct usbg_tpg, se_tpg); 1349 - struct usbg_tport *tport = tpg->tport; 1350 - char *tid = NULL; 1351 - 1352 - switch (tport->tport_proto_id) { 1353 - case SCSI_PROTOCOL_SAS: 1354 - default: 1355 - tid = sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 1356 - port_nexus_ptr); 1357 - } 1358 - 1359 - return tid; 1360 - } 1361 - 1362 - static struct se_node_acl *usbg_alloc_fabric_acl(struct se_portal_group *se_tpg) 1363 - { 1364 - struct usbg_nacl *nacl; 1365 - 1366 - nacl = kzalloc(sizeof(struct usbg_nacl), GFP_KERNEL); 1367 - if (!nacl) 1368 - return NULL; 1369 - 1370 - return &nacl->se_node_acl; 1371 - } 1372 - 1373 - static void usbg_release_fabric_acl( 1374 - struct se_portal_group *se_tpg, 1375 - struct se_node_acl *se_nacl) 1376 - { 1377 - struct usbg_nacl *nacl = container_of(se_nacl, 1378 - struct usbg_nacl, se_node_acl); 1379 - kfree(nacl); 1380 1307 } 1381 1308 1382 1309 static u32 usbg_tpg_get_inst_index(struct se_portal_group *se_tpg) ··· 1338 1447 return; 1339 1448 } 1340 1449 1341 - static u32 usbg_get_task_tag(struct se_cmd *se_cmd) 1342 - { 1343 - struct usbg_cmd *cmd = container_of(se_cmd, struct usbg_cmd, 1344 - se_cmd); 1345 - struct f_uas *fu = cmd->fu; 1346 - 1347 - if (fu->flags & USBG_IS_BOT) 1348 - return le32_to_cpu(cmd->bot_tag); 1349 - else 1350 - return cmd->tag; 1351 - } 1352 - 1353 1450 static int usbg_get_cmd_state(struct se_cmd *se_cmd) 1354 1451 { 1355 1452 return 0; ··· 1367 1488 return n; 1368 1489 } 1369 1490 1370 - static struct se_node_acl *usbg_make_nodeacl( 1371 - struct se_portal_group *se_tpg, 1372 - struct config_group *group, 1373 - const char *name) 1491 + static int usbg_init_nodeacl(struct se_node_acl *se_nacl, const char *name) 1374 1492 { 1375 - struct se_node_acl *se_nacl, *se_nacl_new; 1376 - struct usbg_nacl *nacl; 1377 - u64 wwpn = 0; 1378 - u32 nexus_depth; 1379 - const char *wnn_name; 1380 - 1381 - wnn_name = usbg_check_wwn(name); 1382 - if (!wnn_name) 1383 - return ERR_PTR(-EINVAL); 1384 - se_nacl_new = usbg_alloc_fabric_acl(se_tpg); 1385 - if (!(se_nacl_new)) 1386 - return ERR_PTR(-ENOMEM); 1387 - 1388 - nexus_depth = 1; 1389 - /* 1390 - * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 1391 - * when converting a NodeACL from demo mode -> explict 1392 - */ 1393 - se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 1394 - name, nexus_depth); 1395 - if (IS_ERR(se_nacl)) { 1396 - usbg_release_fabric_acl(se_tpg, se_nacl_new); 1397 - return se_nacl; 1398 - } 1399 - /* 1400 - * Locate our struct usbg_nacl and set the FC Nport WWPN 1401 - */ 1402 - nacl = container_of(se_nacl, struct usbg_nacl, se_node_acl); 1403 - nacl->iport_wwpn = wwpn; 1404 - snprintf(nacl->iport_name, sizeof(nacl->iport_name), "%s", name); 1405 - return se_nacl; 1406 - } 1407 - 1408 - static void usbg_drop_nodeacl(struct se_node_acl *se_acl) 1409 - { 1410 - struct usbg_nacl *nacl = container_of(se_acl, 1411 - struct usbg_nacl, se_node_acl); 1412 - core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1); 1413 - kfree(nacl); 1493 + if (!usbg_check_wwn(name)) 1494 + return -EINVAL; 1495 + return 0; 1414 1496 } 1415 1497 1416 1498 struct usbg_tpg *the_only_tpg_I_currently_have; ··· 1411 1571 tpg->tport = tport; 1412 1572 tpg->tport_tpgt = tpgt; 1413 1573 1414 - ret = core_tpg_register(&usbg_ops, wwn, &tpg->se_tpg, tpg, 1415 - TRANSPORT_TPG_TYPE_NORMAL); 1574 + /* 1575 + * SPC doesn't assign a protocol identifier for USB-SCSI, so we 1576 + * pretend to be SAS.. 1577 + */ 1578 + ret = core_tpg_register(wwn, &tpg->se_tpg, SCSI_PROTOCOL_SAS); 1416 1579 if (ret < 0) { 1417 1580 destroy_workqueue(tpg->workqueue); 1418 1581 kfree(tpg); ··· 1709 1866 .module = THIS_MODULE, 1710 1867 .name = "usb_gadget", 1711 1868 .get_fabric_name = usbg_get_fabric_name, 1712 - .get_fabric_proto_ident = usbg_get_fabric_proto_ident, 1713 1869 .tpg_get_wwn = usbg_get_fabric_wwn, 1714 1870 .tpg_get_tag = usbg_get_tag, 1715 - .tpg_get_default_depth = usbg_get_default_depth, 1716 - .tpg_get_pr_transport_id = usbg_get_pr_transport_id, 1717 - .tpg_get_pr_transport_id_len = usbg_get_pr_transport_id_len, 1718 - .tpg_parse_pr_out_transport_id = usbg_parse_pr_out_transport_id, 1719 1871 .tpg_check_demo_mode = usbg_check_true, 1720 1872 .tpg_check_demo_mode_cache = usbg_check_false, 1721 1873 .tpg_check_demo_mode_write_protect = usbg_check_false, 1722 1874 .tpg_check_prod_mode_write_protect = usbg_check_false, 1723 - .tpg_alloc_fabric_acl = usbg_alloc_fabric_acl, 1724 - .tpg_release_fabric_acl = usbg_release_fabric_acl, 1725 1875 .tpg_get_inst_index = usbg_tpg_get_inst_index, 1726 1876 .release_cmd = usbg_release_cmd, 1727 1877 .shutdown_session = usbg_shutdown_session, ··· 1724 1888 .write_pending = usbg_send_write_request, 1725 1889 .write_pending_status = usbg_write_pending_status, 1726 1890 .set_default_node_attributes = usbg_set_default_node_attrs, 1727 - .get_task_tag = usbg_get_task_tag, 1728 1891 .get_cmd_state = usbg_get_cmd_state, 1729 1892 .queue_data_in = usbg_send_read_response, 1730 1893 .queue_status = usbg_send_status_response, ··· 1737 1902 .fabric_drop_tpg = usbg_drop_tpg, 1738 1903 .fabric_post_link = usbg_port_link, 1739 1904 .fabric_pre_unlink = usbg_port_unlink, 1740 - .fabric_make_np = NULL, 1741 - .fabric_drop_np = NULL, 1742 - .fabric_make_nodeacl = usbg_make_nodeacl, 1743 - .fabric_drop_nodeacl = usbg_drop_nodeacl, 1905 + .fabric_init_nodeacl = usbg_init_nodeacl, 1744 1906 1745 1907 .tfc_wwn_attrs = usbg_wwn_attrs, 1746 1908 .tfc_tpg_base_attrs = usbg_base_attrs,
-11
drivers/usb/gadget/legacy/tcm_usb_gadget.h
··· 24 24 #define USB_G_ALT_INT_BBB 0 25 25 #define USB_G_ALT_INT_UAS 1 26 26 27 - struct usbg_nacl { 28 - /* Binary World Wide unique Port Name for SAS Initiator port */ 29 - u64 iport_wwpn; 30 - /* ASCII formatted WWPN for Sas Initiator port */ 31 - char iport_name[USBG_NAMELEN]; 32 - /* Returned by usbg_make_nodeacl() */ 33 - struct se_node_acl se_node_acl; 34 - }; 35 - 36 27 struct tcm_usbg_nexus { 37 28 struct se_session *tvn_se_sess; 38 29 }; ··· 43 52 }; 44 53 45 54 struct usbg_tport { 46 - /* SCSI protocol the tport is providing */ 47 - u8 tport_proto_id; 48 55 /* Binary World Wide unique Port Name for SAS Target port */ 49 56 u64 tport_wwpn; 50 57 /* ASCII formatted WWPN for SAS Target port */
+3 -216
drivers/vhost/scsi.c
··· 43 43 #include <target/target_core_base.h> 44 44 #include <target/target_core_fabric.h> 45 45 #include <target/target_core_fabric_configfs.h> 46 - #include <target/target_core_configfs.h> 47 46 #include <target/configfs_macros.h> 48 47 #include <linux/vhost.h> 49 48 #include <linux/virtio_scsi.h> ··· 114 115 struct vhost_scsi_nexus { 115 116 /* Pointer to TCM session for I_T Nexus */ 116 117 struct se_session *tvn_se_sess; 117 - }; 118 - 119 - struct vhost_scsi_nacl { 120 - /* Binary World Wide unique Port Name for Vhost Initiator port */ 121 - u64 iport_wwpn; 122 - /* ASCII formatted WWPN for Sas Initiator port */ 123 - char iport_name[VHOST_SCSI_NAMELEN]; 124 - /* Returned by vhost_scsi_make_nodeacl() */ 125 - struct se_node_acl se_node_acl; 126 118 }; 127 119 128 120 struct vhost_scsi_tpg { ··· 208 218 int vs_events_nr; /* num of pending events, protected by vq->mutex */ 209 219 }; 210 220 211 - static struct target_core_fabric_ops vhost_scsi_ops; 212 221 static struct workqueue_struct *vhost_scsi_workqueue; 213 222 214 223 /* Global spinlock to protect vhost_scsi TPG list for vhost IOCTL access */ ··· 288 299 return "vhost"; 289 300 } 290 301 291 - static u8 vhost_scsi_get_fabric_proto_ident(struct se_portal_group *se_tpg) 292 - { 293 - struct vhost_scsi_tpg *tpg = container_of(se_tpg, 294 - struct vhost_scsi_tpg, se_tpg); 295 - struct vhost_scsi_tport *tport = tpg->tport; 296 - 297 - switch (tport->tport_proto_id) { 298 - case SCSI_PROTOCOL_SAS: 299 - return sas_get_fabric_proto_ident(se_tpg); 300 - case SCSI_PROTOCOL_FCP: 301 - return fc_get_fabric_proto_ident(se_tpg); 302 - case SCSI_PROTOCOL_ISCSI: 303 - return iscsi_get_fabric_proto_ident(se_tpg); 304 - default: 305 - pr_err("Unknown tport_proto_id: 0x%02x, using" 306 - " SAS emulation\n", tport->tport_proto_id); 307 - break; 308 - } 309 - 310 - return sas_get_fabric_proto_ident(se_tpg); 311 - } 312 - 313 302 static char *vhost_scsi_get_fabric_wwn(struct se_portal_group *se_tpg) 314 303 { 315 304 struct vhost_scsi_tpg *tpg = container_of(se_tpg, ··· 304 337 return tpg->tport_tpgt; 305 338 } 306 339 307 - static u32 vhost_scsi_get_default_depth(struct se_portal_group *se_tpg) 308 - { 309 - return 1; 310 - } 311 - 312 - static u32 313 - vhost_scsi_get_pr_transport_id(struct se_portal_group *se_tpg, 314 - struct se_node_acl *se_nacl, 315 - struct t10_pr_registration *pr_reg, 316 - int *format_code, 317 - unsigned char *buf) 318 - { 319 - struct vhost_scsi_tpg *tpg = container_of(se_tpg, 320 - struct vhost_scsi_tpg, se_tpg); 321 - struct vhost_scsi_tport *tport = tpg->tport; 322 - 323 - switch (tport->tport_proto_id) { 324 - case SCSI_PROTOCOL_SAS: 325 - return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 326 - format_code, buf); 327 - case SCSI_PROTOCOL_FCP: 328 - return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 329 - format_code, buf); 330 - case SCSI_PROTOCOL_ISCSI: 331 - return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 332 - format_code, buf); 333 - default: 334 - pr_err("Unknown tport_proto_id: 0x%02x, using" 335 - " SAS emulation\n", tport->tport_proto_id); 336 - break; 337 - } 338 - 339 - return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 340 - format_code, buf); 341 - } 342 - 343 - static u32 344 - vhost_scsi_get_pr_transport_id_len(struct se_portal_group *se_tpg, 345 - struct se_node_acl *se_nacl, 346 - struct t10_pr_registration *pr_reg, 347 - int *format_code) 348 - { 349 - struct vhost_scsi_tpg *tpg = container_of(se_tpg, 350 - struct vhost_scsi_tpg, se_tpg); 351 - struct vhost_scsi_tport *tport = tpg->tport; 352 - 353 - switch (tport->tport_proto_id) { 354 - case SCSI_PROTOCOL_SAS: 355 - return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 356 - format_code); 357 - case SCSI_PROTOCOL_FCP: 358 - return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 359 - format_code); 360 - case SCSI_PROTOCOL_ISCSI: 361 - return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 362 - format_code); 363 - default: 364 - pr_err("Unknown tport_proto_id: 0x%02x, using" 365 - " SAS emulation\n", tport->tport_proto_id); 366 - break; 367 - } 368 - 369 - return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 370 - format_code); 371 - } 372 - 373 - static char * 374 - vhost_scsi_parse_pr_out_transport_id(struct se_portal_group *se_tpg, 375 - const char *buf, 376 - u32 *out_tid_len, 377 - char **port_nexus_ptr) 378 - { 379 - struct vhost_scsi_tpg *tpg = container_of(se_tpg, 380 - struct vhost_scsi_tpg, se_tpg); 381 - struct vhost_scsi_tport *tport = tpg->tport; 382 - 383 - switch (tport->tport_proto_id) { 384 - case SCSI_PROTOCOL_SAS: 385 - return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 386 - port_nexus_ptr); 387 - case SCSI_PROTOCOL_FCP: 388 - return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 389 - port_nexus_ptr); 390 - case SCSI_PROTOCOL_ISCSI: 391 - return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 392 - port_nexus_ptr); 393 - default: 394 - pr_err("Unknown tport_proto_id: 0x%02x, using" 395 - " SAS emulation\n", tport->tport_proto_id); 396 - break; 397 - } 398 - 399 - return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 400 - port_nexus_ptr); 401 - } 402 - 403 340 static int vhost_scsi_check_prot_fabric_only(struct se_portal_group *se_tpg) 404 341 { 405 342 struct vhost_scsi_tpg *tpg = container_of(se_tpg, 406 343 struct vhost_scsi_tpg, se_tpg); 407 344 408 345 return tpg->tv_fabric_prot_type; 409 - } 410 - 411 - static struct se_node_acl * 412 - vhost_scsi_alloc_fabric_acl(struct se_portal_group *se_tpg) 413 - { 414 - struct vhost_scsi_nacl *nacl; 415 - 416 - nacl = kzalloc(sizeof(struct vhost_scsi_nacl), GFP_KERNEL); 417 - if (!nacl) { 418 - pr_err("Unable to allocate struct vhost_scsi_nacl\n"); 419 - return NULL; 420 - } 421 - 422 - return &nacl->se_node_acl; 423 - } 424 - 425 - static void 426 - vhost_scsi_release_fabric_acl(struct se_portal_group *se_tpg, 427 - struct se_node_acl *se_nacl) 428 - { 429 - struct vhost_scsi_nacl *nacl = container_of(se_nacl, 430 - struct vhost_scsi_nacl, se_node_acl); 431 - kfree(nacl); 432 346 } 433 347 434 348 static u32 vhost_scsi_tpg_get_inst_index(struct se_portal_group *se_tpg) ··· 367 519 static void vhost_scsi_set_default_node_attrs(struct se_node_acl *nacl) 368 520 { 369 521 return; 370 - } 371 - 372 - static u32 vhost_scsi_get_task_tag(struct se_cmd *se_cmd) 373 - { 374 - return 0; 375 522 } 376 523 377 524 static int vhost_scsi_get_cmd_state(struct se_cmd *se_cmd) ··· 452 609 453 610 static int vhost_scsi_check_stop_free(struct se_cmd *se_cmd) 454 611 { 455 - return target_put_sess_cmd(se_cmd->se_sess, se_cmd); 612 + return target_put_sess_cmd(se_cmd); 456 613 } 457 614 458 615 static void ··· 813 970 } 814 971 tv_nexus = cmd->tvc_nexus; 815 972 973 + se_cmd->tag = 0; 816 974 rc = target_submit_cmd_map_sgls(se_cmd, tv_nexus->tvn_se_sess, 817 975 cmd->tvc_cdb, &cmd->tvc_sense_buf[0], 818 976 cmd->tvc_lun, cmd->tvc_exp_data_len, ··· 1668 1824 mutex_unlock(&vhost_scsi_mutex); 1669 1825 } 1670 1826 1671 - static struct se_node_acl * 1672 - vhost_scsi_make_nodeacl(struct se_portal_group *se_tpg, 1673 - struct config_group *group, 1674 - const char *name) 1675 - { 1676 - struct se_node_acl *se_nacl, *se_nacl_new; 1677 - struct vhost_scsi_nacl *nacl; 1678 - u64 wwpn = 0; 1679 - u32 nexus_depth; 1680 - 1681 - /* vhost_scsi_parse_wwn(name, &wwpn, 1) < 0) 1682 - return ERR_PTR(-EINVAL); */ 1683 - se_nacl_new = vhost_scsi_alloc_fabric_acl(se_tpg); 1684 - if (!se_nacl_new) 1685 - return ERR_PTR(-ENOMEM); 1686 - 1687 - nexus_depth = 1; 1688 - /* 1689 - * se_nacl_new may be released by core_tpg_add_initiator_node_acl() 1690 - * when converting a NodeACL from demo mode -> explict 1691 - */ 1692 - se_nacl = core_tpg_add_initiator_node_acl(se_tpg, se_nacl_new, 1693 - name, nexus_depth); 1694 - if (IS_ERR(se_nacl)) { 1695 - vhost_scsi_release_fabric_acl(se_tpg, se_nacl_new); 1696 - return se_nacl; 1697 - } 1698 - /* 1699 - * Locate our struct vhost_scsi_nacl and set the FC Nport WWPN 1700 - */ 1701 - nacl = container_of(se_nacl, struct vhost_scsi_nacl, se_node_acl); 1702 - nacl->iport_wwpn = wwpn; 1703 - 1704 - return se_nacl; 1705 - } 1706 - 1707 - static void vhost_scsi_drop_nodeacl(struct se_node_acl *se_acl) 1708 - { 1709 - struct vhost_scsi_nacl *nacl = container_of(se_acl, 1710 - struct vhost_scsi_nacl, se_node_acl); 1711 - core_tpg_del_initiator_node_acl(se_acl->se_tpg, se_acl, 1); 1712 - kfree(nacl); 1713 - } 1714 - 1715 1827 static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus, 1716 1828 struct se_session *se_sess) 1717 1829 { ··· 2002 2202 tpg->tport = tport; 2003 2203 tpg->tport_tpgt = tpgt; 2004 2204 2005 - ret = core_tpg_register(&vhost_scsi_ops, wwn, 2006 - &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 2205 + ret = core_tpg_register(wwn, &tpg->se_tpg, tport->tport_proto_id); 2007 2206 if (ret < 0) { 2008 2207 kfree(tpg); 2009 2208 return NULL; ··· 2126 2327 .module = THIS_MODULE, 2127 2328 .name = "vhost", 2128 2329 .get_fabric_name = vhost_scsi_get_fabric_name, 2129 - .get_fabric_proto_ident = vhost_scsi_get_fabric_proto_ident, 2130 2330 .tpg_get_wwn = vhost_scsi_get_fabric_wwn, 2131 2331 .tpg_get_tag = vhost_scsi_get_tpgt, 2132 - .tpg_get_default_depth = vhost_scsi_get_default_depth, 2133 - .tpg_get_pr_transport_id = vhost_scsi_get_pr_transport_id, 2134 - .tpg_get_pr_transport_id_len = vhost_scsi_get_pr_transport_id_len, 2135 - .tpg_parse_pr_out_transport_id = vhost_scsi_parse_pr_out_transport_id, 2136 2332 .tpg_check_demo_mode = vhost_scsi_check_true, 2137 2333 .tpg_check_demo_mode_cache = vhost_scsi_check_true, 2138 2334 .tpg_check_demo_mode_write_protect = vhost_scsi_check_false, 2139 2335 .tpg_check_prod_mode_write_protect = vhost_scsi_check_false, 2140 2336 .tpg_check_prot_fabric_only = vhost_scsi_check_prot_fabric_only, 2141 - .tpg_alloc_fabric_acl = vhost_scsi_alloc_fabric_acl, 2142 - .tpg_release_fabric_acl = vhost_scsi_release_fabric_acl, 2143 2337 .tpg_get_inst_index = vhost_scsi_tpg_get_inst_index, 2144 2338 .release_cmd = vhost_scsi_release_cmd, 2145 2339 .check_stop_free = vhost_scsi_check_stop_free, ··· 2143 2351 .write_pending = vhost_scsi_write_pending, 2144 2352 .write_pending_status = vhost_scsi_write_pending_status, 2145 2353 .set_default_node_attributes = vhost_scsi_set_default_node_attrs, 2146 - .get_task_tag = vhost_scsi_get_task_tag, 2147 2354 .get_cmd_state = vhost_scsi_get_cmd_state, 2148 2355 .queue_data_in = vhost_scsi_queue_data_in, 2149 2356 .queue_status = vhost_scsi_queue_status, ··· 2157 2366 .fabric_drop_tpg = vhost_scsi_drop_tpg, 2158 2367 .fabric_post_link = vhost_scsi_port_link, 2159 2368 .fabric_pre_unlink = vhost_scsi_port_unlink, 2160 - .fabric_make_np = NULL, 2161 - .fabric_drop_np = NULL, 2162 - .fabric_make_nodeacl = vhost_scsi_make_nodeacl, 2163 - .fabric_drop_nodeacl = vhost_scsi_drop_nodeacl, 2164 2369 2165 2370 .tfc_wwn_attrs = vhost_scsi_wwn_attrs, 2166 2371 .tfc_tpg_base_attrs = vhost_scsi_tpg_attrs,
+19 -172
drivers/xen/xen-scsiback.c
··· 53 53 54 54 #include <target/target_core_base.h> 55 55 #include <target/target_core_fabric.h> 56 - #include <target/target_core_configfs.h> 57 56 #include <target/target_core_fabric_configfs.h> 58 57 59 58 #include <asm/hypervisor.h> ··· 199 200 /* Global spinlock to protect scsiback TPG list */ 200 201 static DEFINE_MUTEX(scsiback_mutex); 201 202 static LIST_HEAD(scsiback_list); 202 - 203 - static const struct target_core_fabric_ops scsiback_ops; 204 203 205 204 static void scsiback_get(struct vscsibk_info *info) 206 205 { ··· 394 397 memset(se_cmd, 0, sizeof(*se_cmd)); 395 398 396 399 scsiback_get(pending_req->info); 400 + se_cmd->tag = pending_req->rqid; 397 401 rc = target_submit_cmd_map_sgls(se_cmd, sess, pending_req->cmnd, 398 402 pending_req->sense_buffer, pending_req->v2p->lun, 399 403 pending_req->data_len, 0, ··· 861 863 struct list_head *head = &(info->v2p_entry_lists); 862 864 unsigned long flags; 863 865 char *lunp; 864 - unsigned int lun; 866 + unsigned long long unpacked_lun; 867 + struct se_lun *se_lun; 865 868 struct scsiback_tpg *tpg_entry, *tpg = NULL; 866 869 char *error = "doesn't exist"; 867 870 ··· 873 874 } 874 875 *lunp = 0; 875 876 lunp++; 876 - if (kstrtouint(lunp, 10, &lun) || lun >= TRANSPORT_MAX_LUNS_PER_TPG) { 877 + err = kstrtoull(lunp, 10, &unpacked_lun); 878 + if (err < 0) { 877 879 pr_err("lun number not valid: %s\n", lunp); 878 - return -EINVAL; 880 + return err; 879 881 } 880 882 881 883 mutex_lock(&scsiback_mutex); 882 884 list_for_each_entry(tpg_entry, &scsiback_list, tv_tpg_list) { 883 885 if (!strcmp(phy, tpg_entry->tport->tport_name) || 884 886 !strcmp(phy, tpg_entry->param_alias)) { 885 - spin_lock(&tpg_entry->se_tpg.tpg_lun_lock); 886 - if (tpg_entry->se_tpg.tpg_lun_list[lun]->lun_status == 887 - TRANSPORT_LUN_STATUS_ACTIVE) { 888 - if (!tpg_entry->tpg_nexus) 889 - error = "nexus undefined"; 890 - else 891 - tpg = tpg_entry; 887 + mutex_lock(&tpg_entry->se_tpg.tpg_lun_mutex); 888 + hlist_for_each_entry(se_lun, &tpg_entry->se_tpg.tpg_lun_hlist, link) { 889 + if (se_lun->unpacked_lun == unpacked_lun) { 890 + if (!tpg_entry->tpg_nexus) 891 + error = "nexus undefined"; 892 + else 893 + tpg = tpg_entry; 894 + break; 895 + } 892 896 } 893 - spin_unlock(&tpg_entry->se_tpg.tpg_lun_lock); 897 + mutex_unlock(&tpg_entry->se_tpg.tpg_lun_mutex); 894 898 break; 895 899 } 896 900 } ··· 905 903 mutex_unlock(&scsiback_mutex); 906 904 907 905 if (!tpg) { 908 - pr_err("%s:%d %s\n", phy, lun, error); 906 + pr_err("%s:%llu %s\n", phy, unpacked_lun, error); 909 907 return -ENODEV; 910 908 } 911 909 ··· 933 931 kref_init(&new->kref); 934 932 new->v = *v; 935 933 new->tpg = tpg; 936 - new->lun = lun; 934 + new->lun = unpacked_lun; 937 935 list_add_tail(&new->l, head); 938 936 939 937 out: ··· 1253 1251 return "Unknown"; 1254 1252 } 1255 1253 1256 - static u8 scsiback_get_fabric_proto_ident(struct se_portal_group *se_tpg) 1257 - { 1258 - struct scsiback_tpg *tpg = container_of(se_tpg, 1259 - struct scsiback_tpg, se_tpg); 1260 - struct scsiback_tport *tport = tpg->tport; 1261 - 1262 - switch (tport->tport_proto_id) { 1263 - case SCSI_PROTOCOL_SAS: 1264 - return sas_get_fabric_proto_ident(se_tpg); 1265 - case SCSI_PROTOCOL_FCP: 1266 - return fc_get_fabric_proto_ident(se_tpg); 1267 - case SCSI_PROTOCOL_ISCSI: 1268 - return iscsi_get_fabric_proto_ident(se_tpg); 1269 - default: 1270 - pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n", 1271 - tport->tport_proto_id); 1272 - break; 1273 - } 1274 - 1275 - return sas_get_fabric_proto_ident(se_tpg); 1276 - } 1277 - 1278 1254 static char *scsiback_get_fabric_wwn(struct se_portal_group *se_tpg) 1279 1255 { 1280 1256 struct scsiback_tpg *tpg = container_of(se_tpg, ··· 1267 1287 struct scsiback_tpg *tpg = container_of(se_tpg, 1268 1288 struct scsiback_tpg, se_tpg); 1269 1289 return tpg->tport_tpgt; 1270 - } 1271 - 1272 - static u32 scsiback_get_default_depth(struct se_portal_group *se_tpg) 1273 - { 1274 - return 1; 1275 - } 1276 - 1277 - static u32 1278 - scsiback_get_pr_transport_id(struct se_portal_group *se_tpg, 1279 - struct se_node_acl *se_nacl, 1280 - struct t10_pr_registration *pr_reg, 1281 - int *format_code, 1282 - unsigned char *buf) 1283 - { 1284 - struct scsiback_tpg *tpg = container_of(se_tpg, 1285 - struct scsiback_tpg, se_tpg); 1286 - struct scsiback_tport *tport = tpg->tport; 1287 - 1288 - switch (tport->tport_proto_id) { 1289 - case SCSI_PROTOCOL_SAS: 1290 - return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 1291 - format_code, buf); 1292 - case SCSI_PROTOCOL_FCP: 1293 - return fc_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 1294 - format_code, buf); 1295 - case SCSI_PROTOCOL_ISCSI: 1296 - return iscsi_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 1297 - format_code, buf); 1298 - default: 1299 - pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n", 1300 - tport->tport_proto_id); 1301 - break; 1302 - } 1303 - 1304 - return sas_get_pr_transport_id(se_tpg, se_nacl, pr_reg, 1305 - format_code, buf); 1306 - } 1307 - 1308 - static u32 1309 - scsiback_get_pr_transport_id_len(struct se_portal_group *se_tpg, 1310 - struct se_node_acl *se_nacl, 1311 - struct t10_pr_registration *pr_reg, 1312 - int *format_code) 1313 - { 1314 - struct scsiback_tpg *tpg = container_of(se_tpg, 1315 - struct scsiback_tpg, se_tpg); 1316 - struct scsiback_tport *tport = tpg->tport; 1317 - 1318 - switch (tport->tport_proto_id) { 1319 - case SCSI_PROTOCOL_SAS: 1320 - return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 1321 - format_code); 1322 - case SCSI_PROTOCOL_FCP: 1323 - return fc_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 1324 - format_code); 1325 - case SCSI_PROTOCOL_ISCSI: 1326 - return iscsi_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 1327 - format_code); 1328 - default: 1329 - pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n", 1330 - tport->tport_proto_id); 1331 - break; 1332 - } 1333 - 1334 - return sas_get_pr_transport_id_len(se_tpg, se_nacl, pr_reg, 1335 - format_code); 1336 - } 1337 - 1338 - static char * 1339 - scsiback_parse_pr_out_transport_id(struct se_portal_group *se_tpg, 1340 - const char *buf, 1341 - u32 *out_tid_len, 1342 - char **port_nexus_ptr) 1343 - { 1344 - struct scsiback_tpg *tpg = container_of(se_tpg, 1345 - struct scsiback_tpg, se_tpg); 1346 - struct scsiback_tport *tport = tpg->tport; 1347 - 1348 - switch (tport->tport_proto_id) { 1349 - case SCSI_PROTOCOL_SAS: 1350 - return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 1351 - port_nexus_ptr); 1352 - case SCSI_PROTOCOL_FCP: 1353 - return fc_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 1354 - port_nexus_ptr); 1355 - case SCSI_PROTOCOL_ISCSI: 1356 - return iscsi_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 1357 - port_nexus_ptr); 1358 - default: 1359 - pr_err("Unknown tport_proto_id: 0x%02x, using SAS emulation\n", 1360 - tport->tport_proto_id); 1361 - break; 1362 - } 1363 - 1364 - return sas_parse_pr_out_transport_id(se_tpg, buf, out_tid_len, 1365 - port_nexus_ptr); 1366 1290 } 1367 1291 1368 1292 static struct se_wwn * ··· 1335 1451 kfree(tport); 1336 1452 } 1337 1453 1338 - static struct se_node_acl * 1339 - scsiback_alloc_fabric_acl(struct se_portal_group *se_tpg) 1340 - { 1341 - return kzalloc(sizeof(struct se_node_acl), GFP_KERNEL); 1342 - } 1343 - 1344 - static void 1345 - scsiback_release_fabric_acl(struct se_portal_group *se_tpg, 1346 - struct se_node_acl *se_nacl) 1347 - { 1348 - kfree(se_nacl); 1349 - } 1350 - 1351 1454 static u32 scsiback_tpg_get_inst_index(struct se_portal_group *se_tpg) 1352 1455 { 1353 1456 return 1; ··· 1391 1520 1392 1521 static void scsiback_set_default_node_attrs(struct se_node_acl *nacl) 1393 1522 { 1394 - } 1395 - 1396 - static u32 scsiback_get_task_tag(struct se_cmd *se_cmd) 1397 - { 1398 - struct vscsibk_pend *pending_req = container_of(se_cmd, 1399 - struct vscsibk_pend, se_cmd); 1400 - 1401 - return pending_req->rqid; 1402 1523 } 1403 1524 1404 1525 static int scsiback_get_cmd_state(struct se_cmd *se_cmd) ··· 1761 1898 tpg->tport = tport; 1762 1899 tpg->tport_tpgt = tpgt; 1763 1900 1764 - ret = core_tpg_register(&scsiback_ops, wwn, 1765 - &tpg->se_tpg, tpg, TRANSPORT_TPG_TYPE_NORMAL); 1901 + ret = core_tpg_register(wwn, &tpg->se_tpg, tport->tport_proto_id); 1766 1902 if (ret < 0) { 1767 1903 kfree(tpg); 1768 1904 return NULL; ··· 1806 1944 .module = THIS_MODULE, 1807 1945 .name = "xen-pvscsi", 1808 1946 .get_fabric_name = scsiback_get_fabric_name, 1809 - .get_fabric_proto_ident = scsiback_get_fabric_proto_ident, 1810 1947 .tpg_get_wwn = scsiback_get_fabric_wwn, 1811 1948 .tpg_get_tag = scsiback_get_tag, 1812 - .tpg_get_default_depth = scsiback_get_default_depth, 1813 - .tpg_get_pr_transport_id = scsiback_get_pr_transport_id, 1814 - .tpg_get_pr_transport_id_len = scsiback_get_pr_transport_id_len, 1815 - .tpg_parse_pr_out_transport_id = scsiback_parse_pr_out_transport_id, 1816 1949 .tpg_check_demo_mode = scsiback_check_true, 1817 1950 .tpg_check_demo_mode_cache = scsiback_check_true, 1818 1951 .tpg_check_demo_mode_write_protect = scsiback_check_false, 1819 1952 .tpg_check_prod_mode_write_protect = scsiback_check_false, 1820 - .tpg_alloc_fabric_acl = scsiback_alloc_fabric_acl, 1821 - .tpg_release_fabric_acl = scsiback_release_fabric_acl, 1822 1953 .tpg_get_inst_index = scsiback_tpg_get_inst_index, 1823 1954 .check_stop_free = scsiback_check_stop_free, 1824 1955 .release_cmd = scsiback_release_cmd, 1825 - .put_session = NULL, 1826 1956 .shutdown_session = scsiback_shutdown_session, 1827 1957 .close_session = scsiback_close_session, 1828 1958 .sess_get_index = scsiback_sess_get_index, ··· 1822 1968 .write_pending = scsiback_write_pending, 1823 1969 .write_pending_status = scsiback_write_pending_status, 1824 1970 .set_default_node_attributes = scsiback_set_default_node_attrs, 1825 - .get_task_tag = scsiback_get_task_tag, 1826 1971 .get_cmd_state = scsiback_get_cmd_state, 1827 1972 .queue_data_in = scsiback_queue_data_in, 1828 1973 .queue_status = scsiback_queue_status, ··· 1836 1983 .fabric_drop_tpg = scsiback_drop_tpg, 1837 1984 .fabric_post_link = scsiback_port_link, 1838 1985 .fabric_pre_unlink = scsiback_port_unlink, 1839 - .fabric_make_np = NULL, 1840 - .fabric_drop_np = NULL, 1841 - #if 0 1842 - .fabric_make_nodeacl = scsiback_make_nodeacl, 1843 - .fabric_drop_nodeacl = scsiback_drop_nodeacl, 1844 - #endif 1845 1986 1846 1987 .tfc_wwn_attrs = scsiback_wwn_attrs, 1847 1988 .tfc_tpg_base_attrs = scsiback_tpg_attrs,
+1
include/linux/crc-t10dif.h
··· 9 9 extern __u16 crc_t10dif_generic(__u16 crc, const unsigned char *buffer, 10 10 size_t len); 11 11 extern __u16 crc_t10dif(unsigned char const *, size_t); 12 + extern __u16 crc_t10dif_update(__u16 crc, unsigned char const *, size_t); 12 13 13 14 #endif
+1 -11
include/target/iscsi/iscsi_target_core.h
··· 247 247 u8 DataDigest; /* [0,1] == [None,CRC32C] */ 248 248 u32 MaxRecvDataSegmentLength; /* [512..2**24-1] */ 249 249 u32 MaxXmitDataSegmentLength; /* [512..2**24-1] */ 250 - u8 OFMarker; /* [0,1] == [No,Yes] */ 251 - u8 IFMarker; /* [0,1] == [No,Yes] */ 252 - u32 OFMarkInt; /* [1..65535] */ 253 - u32 IFMarkInt; /* [1..65535] */ 254 250 /* 255 251 * iSER specific connection parameters 256 252 */ ··· 527 531 u32 exp_statsn; 528 532 /* Per connection status sequence number */ 529 533 u32 stat_sn; 530 - /* IFMarkInt's Current Value */ 531 - u32 if_marker; 532 - /* OFMarkInt's Current Value */ 533 - u32 of_marker; 534 - /* Used for calculating OFMarker offset to next PDU */ 535 - u32 of_marker_offset; 536 534 #define IPV6_ADDRESS_SPACE 48 537 535 unsigned char login_ip[IPV6_ADDRESS_SPACE]; 538 536 unsigned char local_ip[IPV6_ADDRESS_SPACE]; ··· 744 754 }; 745 755 746 756 struct iscsi_node_acl { 757 + struct se_node_acl se_node_acl; 747 758 struct iscsi_node_attrib node_attrib; 748 759 struct iscsi_node_auth node_auth; 749 760 struct iscsi_node_stat_grps node_stat_grps; 750 - struct se_node_acl se_node_acl; 751 761 }; 752 762 753 763 struct iscsi_tpg_attrib {
+13 -59
include/target/target_core_backend.h
··· 3 3 4 4 #define TRANSPORT_FLAG_PASSTHROUGH 1 5 5 6 - struct target_backend_cits { 7 - struct config_item_type tb_dev_cit; 8 - struct config_item_type tb_dev_attrib_cit; 9 - struct config_item_type tb_dev_pr_cit; 10 - struct config_item_type tb_dev_wwn_cit; 11 - struct config_item_type tb_dev_alua_tg_pt_gps_cit; 12 - struct config_item_type tb_dev_stat_cit; 13 - }; 14 - 15 - struct se_subsystem_api { 16 - struct list_head sub_api_list; 17 - 6 + struct target_backend_ops { 18 7 char name[16]; 19 8 char inquiry_prod[16]; 20 9 char inquiry_rev[4]; ··· 41 52 int (*format_prot)(struct se_device *); 42 53 void (*free_prot)(struct se_device *); 43 54 44 - struct target_backend_cits tb_cits; 55 + struct configfs_attribute **tb_dev_attrib_attrs; 45 56 }; 46 57 47 58 struct sbc_ops { ··· 49 60 u32, enum dma_data_direction); 50 61 sense_reason_t (*execute_sync_cache)(struct se_cmd *cmd); 51 62 sense_reason_t (*execute_write_same)(struct se_cmd *cmd); 52 - sense_reason_t (*execute_write_same_unmap)(struct se_cmd *cmd); 53 - sense_reason_t (*execute_unmap)(struct se_cmd *cmd); 63 + sense_reason_t (*execute_unmap)(struct se_cmd *cmd, 64 + sector_t lba, sector_t nolb); 54 65 }; 55 66 56 - int transport_subsystem_register(struct se_subsystem_api *); 57 - void transport_subsystem_release(struct se_subsystem_api *); 67 + int transport_backend_register(const struct target_backend_ops *); 68 + void target_backend_unregister(const struct target_backend_ops *); 58 69 59 70 void target_complete_cmd(struct se_cmd *, u8); 60 71 void target_complete_cmd_with_length(struct se_cmd *, u8, int); ··· 68 79 u32 sbc_get_device_rev(struct se_device *dev); 69 80 u32 sbc_get_device_type(struct se_device *dev); 70 81 sector_t sbc_get_write_same_sectors(struct se_cmd *cmd); 71 - sense_reason_t sbc_execute_unmap(struct se_cmd *cmd, 72 - sense_reason_t (*do_unmap_fn)(struct se_cmd *cmd, void *priv, 73 - sector_t lba, sector_t nolb), 74 - void *priv); 75 82 void sbc_dif_generate(struct se_cmd *); 76 - sense_reason_t sbc_dif_verify_write(struct se_cmd *, sector_t, unsigned int, 83 + sense_reason_t sbc_dif_verify(struct se_cmd *, sector_t, unsigned int, 77 84 unsigned int, struct scatterlist *, int); 78 - sense_reason_t sbc_dif_verify_read(struct se_cmd *, sector_t, unsigned int, 79 - unsigned int, struct scatterlist *, int); 80 - sense_reason_t sbc_dif_read_strip(struct se_cmd *); 81 - 85 + void sbc_dif_copy_prot(struct se_cmd *, unsigned int, bool, 86 + struct scatterlist *, int); 82 87 void transport_set_vpd_proto_id(struct t10_vpd *, unsigned char *); 83 88 int transport_set_vpd_assoc(struct t10_vpd *, unsigned char *); 84 89 int transport_set_vpd_ident_type(struct t10_vpd *, unsigned char *); 85 90 int transport_set_vpd_ident(struct t10_vpd *, unsigned char *); 91 + 92 + extern struct configfs_attribute *sbc_attrib_attrs[]; 93 + extern struct configfs_attribute *passthrough_attrib_attrs[]; 86 94 87 95 /* core helpers also used by command snooping in pscsi */ 88 96 void *transport_kmap_data_sg(struct se_cmd *); ··· 89 103 sense_reason_t transport_generic_map_mem_to_cmd(struct se_cmd *, 90 104 struct scatterlist *, u32, struct scatterlist *, u32); 91 105 92 - void array_free(void *array, int n); 93 - 94 - /* From target_core_configfs.c to setup default backend config_item_types */ 95 - void target_core_setup_sub_cits(struct se_subsystem_api *); 96 - 97 - /* attribute helpers from target_core_device.c for backend drivers */ 98 - bool se_dev_check_wce(struct se_device *); 99 - int se_dev_set_max_unmap_lba_count(struct se_device *, u32); 100 - int se_dev_set_max_unmap_block_desc_count(struct se_device *, u32); 101 - int se_dev_set_unmap_granularity(struct se_device *, u32); 102 - int se_dev_set_unmap_granularity_alignment(struct se_device *, u32); 103 - int se_dev_set_max_write_same_len(struct se_device *, u32); 104 - int se_dev_set_emulate_model_alias(struct se_device *, int); 105 - int se_dev_set_emulate_dpo(struct se_device *, int); 106 - int se_dev_set_emulate_fua_write(struct se_device *, int); 107 - int se_dev_set_emulate_fua_read(struct se_device *, int); 108 - int se_dev_set_emulate_write_cache(struct se_device *, int); 109 - int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *, int); 110 - int se_dev_set_emulate_tas(struct se_device *, int); 111 - int se_dev_set_emulate_tpu(struct se_device *, int); 112 - int se_dev_set_emulate_tpws(struct se_device *, int); 113 - int se_dev_set_emulate_caw(struct se_device *, int); 114 - int se_dev_set_emulate_3pc(struct se_device *, int); 115 - int se_dev_set_pi_prot_type(struct se_device *, int); 116 - int se_dev_set_pi_prot_format(struct se_device *, int); 117 - int se_dev_set_enforce_pr_isids(struct se_device *, int); 118 - int se_dev_set_force_pr_aptpl(struct se_device *, int); 119 - int se_dev_set_is_nonrot(struct se_device *, int); 120 - int se_dev_set_emulate_rest_reord(struct se_device *dev, int); 121 - int se_dev_set_queue_depth(struct se_device *, u32); 122 - int se_dev_set_max_sectors(struct se_device *, u32); 123 - int se_dev_set_optimal_sectors(struct se_device *, u32); 124 - int se_dev_set_block_size(struct se_device *, u32); 106 + bool target_lun_is_rdonly(struct se_cmd *); 125 107 sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd, 126 108 sense_reason_t (*exec_cmd)(struct se_cmd *cmd)); 127 109
-118
include/target/target_core_backend_configfs.h
··· 1 - #ifndef TARGET_CORE_BACKEND_CONFIGFS_H 2 - #define TARGET_CORE_BACKEND_CONFIGFS_H 3 - 4 - #include <target/configfs_macros.h> 5 - 6 - #define DEF_TB_DEV_ATTRIB_SHOW(_backend, _name) \ 7 - static ssize_t _backend##_dev_show_attr_##_name( \ 8 - struct se_dev_attrib *da, \ 9 - char *page) \ 10 - { \ 11 - return snprintf(page, PAGE_SIZE, "%u\n", \ 12 - (u32)da->da_dev->dev_attrib._name); \ 13 - } 14 - 15 - #define DEF_TB_DEV_ATTRIB_STORE(_backend, _name) \ 16 - static ssize_t _backend##_dev_store_attr_##_name( \ 17 - struct se_dev_attrib *da, \ 18 - const char *page, \ 19 - size_t count) \ 20 - { \ 21 - unsigned long val; \ 22 - int ret; \ 23 - \ 24 - ret = kstrtoul(page, 0, &val); \ 25 - if (ret < 0) { \ 26 - pr_err("kstrtoul() failed with ret: %d\n", ret); \ 27 - return -EINVAL; \ 28 - } \ 29 - ret = se_dev_set_##_name(da->da_dev, (u32)val); \ 30 - \ 31 - return (!ret) ? count : -EINVAL; \ 32 - } 33 - 34 - #define DEF_TB_DEV_ATTRIB(_backend, _name) \ 35 - DEF_TB_DEV_ATTRIB_SHOW(_backend, _name); \ 36 - DEF_TB_DEV_ATTRIB_STORE(_backend, _name); 37 - 38 - #define DEF_TB_DEV_ATTRIB_RO(_backend, name) \ 39 - DEF_TB_DEV_ATTRIB_SHOW(_backend, name); 40 - 41 - CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib, se_dev_attrib); 42 - #define TB_DEV_ATTR(_backend, _name, _mode) \ 43 - static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 44 - __CONFIGFS_EATTR(_name, _mode, \ 45 - _backend##_dev_show_attr_##_name, \ 46 - _backend##_dev_store_attr_##_name); 47 - 48 - #define TB_DEV_ATTR_RO(_backend, _name) \ 49 - static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 50 - __CONFIGFS_EATTR_RO(_name, \ 51 - _backend##_dev_show_attr_##_name); 52 - 53 - /* 54 - * Default list of target backend device attributes as defined by 55 - * struct se_dev_attrib 56 - */ 57 - 58 - #define DEF_TB_DEFAULT_ATTRIBS(_backend) \ 59 - DEF_TB_DEV_ATTRIB(_backend, emulate_model_alias); \ 60 - TB_DEV_ATTR(_backend, emulate_model_alias, S_IRUGO | S_IWUSR); \ 61 - DEF_TB_DEV_ATTRIB(_backend, emulate_dpo); \ 62 - TB_DEV_ATTR(_backend, emulate_dpo, S_IRUGO | S_IWUSR); \ 63 - DEF_TB_DEV_ATTRIB(_backend, emulate_fua_write); \ 64 - TB_DEV_ATTR(_backend, emulate_fua_write, S_IRUGO | S_IWUSR); \ 65 - DEF_TB_DEV_ATTRIB(_backend, emulate_fua_read); \ 66 - TB_DEV_ATTR(_backend, emulate_fua_read, S_IRUGO | S_IWUSR); \ 67 - DEF_TB_DEV_ATTRIB(_backend, emulate_write_cache); \ 68 - TB_DEV_ATTR(_backend, emulate_write_cache, S_IRUGO | S_IWUSR); \ 69 - DEF_TB_DEV_ATTRIB(_backend, emulate_ua_intlck_ctrl); \ 70 - TB_DEV_ATTR(_backend, emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); \ 71 - DEF_TB_DEV_ATTRIB(_backend, emulate_tas); \ 72 - TB_DEV_ATTR(_backend, emulate_tas, S_IRUGO | S_IWUSR); \ 73 - DEF_TB_DEV_ATTRIB(_backend, emulate_tpu); \ 74 - TB_DEV_ATTR(_backend, emulate_tpu, S_IRUGO | S_IWUSR); \ 75 - DEF_TB_DEV_ATTRIB(_backend, emulate_tpws); \ 76 - TB_DEV_ATTR(_backend, emulate_tpws, S_IRUGO | S_IWUSR); \ 77 - DEF_TB_DEV_ATTRIB(_backend, emulate_caw); \ 78 - TB_DEV_ATTR(_backend, emulate_caw, S_IRUGO | S_IWUSR); \ 79 - DEF_TB_DEV_ATTRIB(_backend, emulate_3pc); \ 80 - TB_DEV_ATTR(_backend, emulate_3pc, S_IRUGO | S_IWUSR); \ 81 - DEF_TB_DEV_ATTRIB(_backend, pi_prot_type); \ 82 - TB_DEV_ATTR(_backend, pi_prot_type, S_IRUGO | S_IWUSR); \ 83 - DEF_TB_DEV_ATTRIB_RO(_backend, hw_pi_prot_type); \ 84 - TB_DEV_ATTR_RO(_backend, hw_pi_prot_type); \ 85 - DEF_TB_DEV_ATTRIB(_backend, pi_prot_format); \ 86 - TB_DEV_ATTR(_backend, pi_prot_format, S_IRUGO | S_IWUSR); \ 87 - DEF_TB_DEV_ATTRIB(_backend, enforce_pr_isids); \ 88 - TB_DEV_ATTR(_backend, enforce_pr_isids, S_IRUGO | S_IWUSR); \ 89 - DEF_TB_DEV_ATTRIB(_backend, is_nonrot); \ 90 - TB_DEV_ATTR(_backend, is_nonrot, S_IRUGO | S_IWUSR); \ 91 - DEF_TB_DEV_ATTRIB(_backend, emulate_rest_reord); \ 92 - TB_DEV_ATTR(_backend, emulate_rest_reord, S_IRUGO | S_IWUSR); \ 93 - DEF_TB_DEV_ATTRIB(_backend, force_pr_aptpl); \ 94 - TB_DEV_ATTR(_backend, force_pr_aptpl, S_IRUGO | S_IWUSR); \ 95 - DEF_TB_DEV_ATTRIB_RO(_backend, hw_block_size); \ 96 - TB_DEV_ATTR_RO(_backend, hw_block_size); \ 97 - DEF_TB_DEV_ATTRIB(_backend, block_size); \ 98 - TB_DEV_ATTR(_backend, block_size, S_IRUGO | S_IWUSR); \ 99 - DEF_TB_DEV_ATTRIB_RO(_backend, hw_max_sectors); \ 100 - TB_DEV_ATTR_RO(_backend, hw_max_sectors); \ 101 - DEF_TB_DEV_ATTRIB(_backend, optimal_sectors); \ 102 - TB_DEV_ATTR(_backend, optimal_sectors, S_IRUGO | S_IWUSR); \ 103 - DEF_TB_DEV_ATTRIB_RO(_backend, hw_queue_depth); \ 104 - TB_DEV_ATTR_RO(_backend, hw_queue_depth); \ 105 - DEF_TB_DEV_ATTRIB(_backend, queue_depth); \ 106 - TB_DEV_ATTR(_backend, queue_depth, S_IRUGO | S_IWUSR); \ 107 - DEF_TB_DEV_ATTRIB(_backend, max_unmap_lba_count); \ 108 - TB_DEV_ATTR(_backend, max_unmap_lba_count, S_IRUGO | S_IWUSR); \ 109 - DEF_TB_DEV_ATTRIB(_backend, max_unmap_block_desc_count); \ 110 - TB_DEV_ATTR(_backend, max_unmap_block_desc_count, S_IRUGO | S_IWUSR); \ 111 - DEF_TB_DEV_ATTRIB(_backend, unmap_granularity); \ 112 - TB_DEV_ATTR(_backend, unmap_granularity, S_IRUGO | S_IWUSR); \ 113 - DEF_TB_DEV_ATTRIB(_backend, unmap_granularity_alignment); \ 114 - TB_DEV_ATTR(_backend, unmap_granularity_alignment, S_IRUGO | S_IWUSR); \ 115 - DEF_TB_DEV_ATTRIB(_backend, max_write_same_len); \ 116 - TB_DEV_ATTR(_backend, max_write_same_len, S_IRUGO | S_IWUSR); 117 - 118 - #endif /* TARGET_CORE_BACKEND_CONFIGFS_H */
+79 -107
include/target/target_core_base.h
··· 9 9 #include <net/sock.h> 10 10 #include <net/tcp.h> 11 11 12 - #define TARGET_CORE_MOD_VERSION "v4.1.0" 13 - #define TARGET_CORE_VERSION TARGET_CORE_MOD_VERSION 12 + #define TARGET_CORE_VERSION "v5.0" 14 13 15 - /* Maximum Number of LUNs per Target Portal Group */ 16 - /* Don't raise above 511 or REPORT_LUNS needs to handle >1 page */ 17 - #define TRANSPORT_MAX_LUNS_PER_TPG 256 18 14 /* 19 15 * Maximum size of a CDB that can be stored in se_cmd without allocating 20 16 * memory dynamically for the CDB. ··· 66 70 #define DA_MAX_WRITE_SAME_LEN 0 67 71 /* Use a model alias based on the configfs backend device name */ 68 72 #define DA_EMULATE_MODEL_ALIAS 0 69 - /* Emulation for Direct Page Out */ 70 - #define DA_EMULATE_DPO 0 71 - /* Emulation for Forced Unit Access WRITEs */ 72 - #define DA_EMULATE_FUA_WRITE 1 73 - /* Emulation for Forced Unit Access READs */ 74 - #define DA_EMULATE_FUA_READ 0 75 73 /* Emulation for WriteCache and SYNCHRONIZE_CACHE */ 76 74 #define DA_EMULATE_WRITE_CACHE 0 77 75 /* Emulation for UNIT ATTENTION Interlock Control */ ··· 106 116 HBA_FLAGS_PSCSI_MODE = 0x02, 107 117 }; 108 118 109 - /* struct se_lun->lun_status */ 110 - enum transport_lun_status_table { 111 - TRANSPORT_LUN_STATUS_FREE = 0, 112 - TRANSPORT_LUN_STATUS_ACTIVE = 1, 113 - }; 114 - 115 - /* struct se_portal_group->se_tpg_type */ 116 - enum transport_tpg_type_table { 117 - TRANSPORT_TPG_TYPE_NORMAL = 0, 118 - TRANSPORT_TPG_TYPE_DISCOVERY = 1, 119 - }; 120 - 121 119 /* Special transport agnostic struct se_cmd->t_states */ 122 120 enum transport_state_table { 123 121 TRANSPORT_NO_STATE = 0, ··· 136 158 SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC = 0x00020000, 137 159 SCF_COMPARE_AND_WRITE = 0x00080000, 138 160 SCF_COMPARE_AND_WRITE_POST = 0x00100000, 161 + SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC = 0x00200000, 139 162 }; 140 163 141 164 /* struct se_dev_entry->lun_flags and struct se_lun->lun_access */ 142 165 enum transport_lunflags_table { 143 - TRANSPORT_LUNFLAGS_NO_ACCESS = 0x00, 144 - TRANSPORT_LUNFLAGS_INITIATOR_ACCESS = 0x01, 145 - TRANSPORT_LUNFLAGS_READ_ONLY = 0x02, 146 - TRANSPORT_LUNFLAGS_READ_WRITE = 0x04, 166 + TRANSPORT_LUNFLAGS_READ_ONLY = 0x01, 167 + TRANSPORT_LUNFLAGS_READ_WRITE = 0x02, 147 168 }; 148 169 149 170 /* ··· 291 314 struct se_device *tg_pt_gp_dev; 292 315 struct config_group tg_pt_gp_group; 293 316 struct list_head tg_pt_gp_list; 294 - struct list_head tg_pt_gp_mem_list; 295 - struct se_port *tg_pt_gp_alua_port; 317 + struct list_head tg_pt_gp_lun_list; 318 + struct se_lun *tg_pt_gp_alua_lun; 296 319 struct se_node_acl *tg_pt_gp_alua_nacl; 297 320 struct delayed_work tg_pt_gp_transition_work; 298 321 struct completion *tg_pt_gp_transition_complete; 299 - }; 300 - 301 - struct t10_alua_tg_pt_gp_member { 302 - bool tg_pt_gp_assoc; 303 - atomic_t tg_pt_gp_mem_ref_cnt; 304 - spinlock_t tg_pt_gp_mem_lock; 305 - struct t10_alua_tg_pt_gp *tg_pt_gp; 306 - struct se_port *tg_pt; 307 - struct list_head tg_pt_gp_mem_list; 308 322 }; 309 323 310 324 struct t10_vpd { ··· 342 374 int pr_res_scope; 343 375 /* Used for fabric initiator WWPNs using a ISID */ 344 376 bool isid_present_at_reg; 345 - u32 pr_res_mapped_lun; 346 - u32 pr_aptpl_target_lun; 377 + u64 pr_res_mapped_lun; 378 + u64 pr_aptpl_target_lun; 379 + u16 tg_pt_sep_rtpi; 347 380 u32 pr_res_generation; 348 381 u64 pr_reg_bin_isid; 349 382 u64 pr_res_key; 350 383 atomic_t pr_res_holders; 351 384 struct se_node_acl *pr_reg_nacl; 385 + /* Used by ALL_TG_PT=1 registration with deve->pr_ref taken */ 352 386 struct se_dev_entry *pr_reg_deve; 353 - struct se_lun *pr_reg_tg_pt_lun; 354 387 struct list_head pr_reg_list; 355 388 struct list_head pr_reg_abort_list; 356 389 struct list_head pr_reg_aptpl_list; ··· 391 422 u8 response; 392 423 int call_transport; 393 424 /* Reference to ITT that Task Mgmt should be performed */ 394 - u32 ref_task_tag; 425 + u64 ref_task_tag; 395 426 void *fabric_tmr_ptr; 396 427 struct se_cmd *task_cmd; 397 428 struct se_device *tmr_dev; ··· 444 475 u8 scsi_asc; 445 476 u8 scsi_ascq; 446 477 u16 scsi_sense_length; 478 + u64 tag; /* SAM command identifier aka task tag */ 447 479 /* Delay for ALUA Active/NonOptimized state access in milliseconds */ 448 480 int alua_nonop_delay; 449 481 /* See include/linux/dma-mapping.h */ ··· 463 493 /* Total size in bytes associated with command */ 464 494 u32 data_length; 465 495 u32 residual_count; 466 - u32 orig_fe_lun; 496 + u64 orig_fe_lun; 467 497 /* Persistent Reservation key */ 468 498 u64 pr_res_key; 469 499 /* Used for sense data */ ··· 471 501 struct list_head se_delayed_node; 472 502 struct list_head se_qf_node; 473 503 struct se_device *se_dev; 474 - struct se_dev_entry *se_deve; 475 504 struct se_lun *se_lun; 476 505 /* Only used for internal passthrough and legacy TCM fabric modules */ 477 506 struct se_session *se_sess; ··· 480 511 struct kref cmd_kref; 481 512 const struct target_core_fabric_ops *se_tfo; 482 513 sense_reason_t (*execute_cmd)(struct se_cmd *); 483 - sense_reason_t (*execute_rw)(struct se_cmd *, struct scatterlist *, 484 - u32, enum dma_data_direction); 485 514 sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool); 515 + void *protocol_data; 486 516 487 517 unsigned char *t_task_cdb; 488 518 unsigned char __t_task_cdb[TCM_MAX_COMMAND_SIZE]; ··· 537 569 struct se_ua { 538 570 u8 ua_asc; 539 571 u8 ua_ascq; 540 - struct se_node_acl *ua_nacl; 541 572 struct list_head ua_nacl_list; 542 573 }; 543 574 ··· 552 585 char acl_tag[MAX_ACL_TAG_SIZE]; 553 586 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ 554 587 atomic_t acl_pr_ref_count; 555 - struct se_dev_entry **device_list; 588 + struct hlist_head lun_entry_hlist; 556 589 struct se_session *nacl_sess; 557 590 struct se_portal_group *se_tpg; 558 - spinlock_t device_list_lock; 591 + struct mutex lun_entry_mutex; 559 592 spinlock_t nacl_sess_lock; 560 593 struct config_group acl_group; 561 594 struct config_group acl_attrib_group; ··· 599 632 600 633 struct se_lun_acl { 601 634 char initiatorname[TRANSPORT_IQN_LEN]; 602 - u32 mapped_lun; 635 + u64 mapped_lun; 603 636 struct se_node_acl *se_lun_nacl; 604 637 struct se_lun *se_lun; 605 - struct list_head lacl_list; 606 638 struct config_group se_lun_group; 607 639 struct se_ml_stat_grps ml_stat_grps; 608 640 }; 609 641 610 642 struct se_dev_entry { 611 - bool def_pr_registered; 612 643 /* See transport_lunflags_table */ 613 - u32 lun_flags; 614 - u32 mapped_lun; 615 - u32 total_cmds; 644 + u64 mapped_lun; 616 645 u64 pr_res_key; 617 646 u64 creation_time; 647 + u32 lun_flags; 618 648 u32 attach_count; 619 - u64 read_bytes; 620 - u64 write_bytes; 649 + atomic_long_t total_cmds; 650 + atomic_long_t read_bytes; 651 + atomic_long_t write_bytes; 621 652 atomic_t ua_count; 622 653 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ 623 - atomic_t pr_ref_count; 624 - struct se_lun_acl *se_lun_acl; 654 + struct kref pr_kref; 655 + struct completion pr_comp; 656 + struct se_lun_acl __rcu *se_lun_acl; 625 657 spinlock_t ua_lock; 626 - struct se_lun *se_lun; 658 + struct se_lun __rcu *se_lun; 659 + #define DEF_PR_REG_ACTIVE 1 660 + unsigned long deve_flags; 627 661 struct list_head alua_port_list; 662 + struct list_head lun_link; 628 663 struct list_head ua_list; 664 + struct hlist_node link; 665 + struct rcu_head rcu_head; 629 666 }; 630 667 631 668 struct se_dev_attrib { ··· 674 703 struct config_group scsi_transport_group; 675 704 }; 676 705 706 + struct scsi_port_stats { 707 + atomic_long_t cmd_pdus; 708 + atomic_long_t tx_data_octets; 709 + atomic_long_t rx_data_octets; 710 + }; 711 + 677 712 struct se_lun { 713 + u64 unpacked_lun; 678 714 #define SE_LUN_LINK_MAGIC 0xffff7771 679 715 u32 lun_link_magic; 680 - /* See transport_lun_status_table */ 681 - enum transport_lun_status_table lun_status; 682 716 u32 lun_access; 683 717 u32 lun_flags; 684 - u32 unpacked_lun; 718 + u32 lun_index; 719 + 720 + /* RELATIVE TARGET PORT IDENTIFER */ 721 + u16 lun_rtpi; 685 722 atomic_t lun_acl_count; 686 - spinlock_t lun_acl_lock; 687 - spinlock_t lun_sep_lock; 688 - struct completion lun_shutdown_comp; 689 - struct list_head lun_acl_list; 690 - struct se_device *lun_se_dev; 691 - struct se_port *lun_sep; 723 + struct se_device __rcu *lun_se_dev; 724 + 725 + struct list_head lun_deve_list; 726 + spinlock_t lun_deve_lock; 727 + 728 + /* ALUA state */ 729 + int lun_tg_pt_secondary_stat; 730 + int lun_tg_pt_secondary_write_md; 731 + atomic_t lun_tg_pt_secondary_offline; 732 + struct mutex lun_tg_pt_md_mutex; 733 + 734 + /* ALUA target port group linkage */ 735 + struct list_head lun_tg_pt_gp_link; 736 + struct t10_alua_tg_pt_gp *lun_tg_pt_gp; 737 + spinlock_t lun_tg_pt_gp_lock; 738 + 739 + struct se_portal_group *lun_tpg; 740 + struct scsi_port_stats lun_stats; 692 741 struct config_group lun_group; 693 742 struct se_port_stat_grps port_stat_grps; 694 743 struct completion lun_ref_comp; 695 744 struct percpu_ref lun_ref; 745 + struct list_head lun_dev_link; 746 + struct hlist_node link; 747 + struct rcu_head rcu_head; 696 748 }; 697 749 698 750 struct se_dev_stat_grps { ··· 738 744 #define DF_EMULATED_VPD_UNIT_SERIAL 0x00000004 739 745 #define DF_USING_UDEV_PATH 0x00000008 740 746 #define DF_USING_ALIAS 0x00000010 741 - u32 dev_port_count; 742 747 /* Physical device queue depth */ 743 748 u32 queue_depth; 744 749 /* Used for SPC-2 reservations enforce of ISIDs */ ··· 754 761 atomic_t dev_ordered_id; 755 762 atomic_t dev_ordered_sync; 756 763 atomic_t dev_qf_count; 757 - int export_count; 764 + u32 export_count; 758 765 spinlock_t delayed_cmd_lock; 759 766 spinlock_t execute_task_lock; 760 767 spinlock_t dev_reservation_lock; ··· 796 803 #define SE_UDEV_PATH_LEN 512 /* must be less than PAGE_SIZE */ 797 804 unsigned char udev_path[SE_UDEV_PATH_LEN]; 798 805 /* Pointer to template of function pointers for transport */ 799 - struct se_subsystem_api *transport; 806 + const struct target_backend_ops *transport; 800 807 /* Linked list for struct se_hba struct se_device list */ 801 808 struct list_head dev_list; 802 809 struct se_lun xcopy_lun; 803 810 /* Protection Information */ 804 811 int prot_length; 812 + /* For se_lun->lun_se_dev RCU read-side critical access */ 813 + u32 hba_index; 814 + struct rcu_head rcu_head; 805 815 }; 806 816 807 817 struct se_hba { ··· 821 825 spinlock_t device_lock; 822 826 struct config_group hba_group; 823 827 struct mutex hba_access_mutex; 824 - struct se_subsystem_api *transport; 825 - }; 826 - 827 - struct scsi_port_stats { 828 - u64 cmd_pdus; 829 - u64 tx_data_octets; 830 - u64 rx_data_octets; 831 - }; 832 - 833 - struct se_port { 834 - /* RELATIVE TARGET PORT IDENTIFER */ 835 - u16 sep_rtpi; 836 - int sep_tg_pt_secondary_stat; 837 - int sep_tg_pt_secondary_write_md; 838 - u32 sep_index; 839 - struct scsi_port_stats sep_stats; 840 - /* Used for ALUA Target Port Groups membership */ 841 - atomic_t sep_tg_pt_secondary_offline; 842 - /* Used for PR ALL_TG_PT=1 */ 843 - atomic_t sep_tg_pt_ref_cnt; 844 - spinlock_t sep_alua_lock; 845 - struct mutex sep_tg_pt_md_mutex; 846 - struct t10_alua_tg_pt_gp_member *sep_alua_tg_pt_gp_mem; 847 - struct se_lun *sep_lun; 848 - struct se_portal_group *sep_tpg; 849 - struct list_head sep_alua_list; 850 - struct list_head sep_list; 828 + struct target_backend *backend; 851 829 }; 852 830 853 831 struct se_tpg_np { ··· 830 860 }; 831 861 832 862 struct se_portal_group { 833 - /* Type of target portal group, see transport_tpg_type_table */ 834 - enum transport_tpg_type_table se_tpg_type; 863 + /* 864 + * PROTOCOL IDENTIFIER value per SPC4, 7.5.1. 865 + * 866 + * Negative values can be used by fabric drivers for internal use TPGs. 867 + */ 868 + int proto_id; 835 869 /* Number of ACLed Initiator Nodes for this TPG */ 836 870 u32 num_node_acls; 837 871 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ 838 872 atomic_t tpg_pr_ref_count; 839 873 /* Spinlock for adding/removing ACLed Nodes */ 840 - spinlock_t acl_node_lock; 874 + struct mutex acl_node_mutex; 841 875 /* Spinlock for adding/removing sessions */ 842 876 spinlock_t session_lock; 843 - spinlock_t tpg_lun_lock; 844 - /* Pointer to $FABRIC_MOD portal group */ 845 - void *se_tpg_fabric_ptr; 877 + struct mutex tpg_lun_mutex; 846 878 struct list_head se_tpg_node; 847 879 /* linked list for initiator ACL list */ 848 880 struct list_head acl_node_list; 849 - struct se_lun **tpg_lun_list; 850 - struct se_lun tpg_virt_lun0; 881 + struct hlist_head tpg_lun_hlist; 882 + struct se_lun *tpg_virt_lun0; 851 883 /* List of TCM sessions associated wth this TPG */ 852 884 struct list_head tpg_sess_list; 853 885 /* Pointer to $FABRIC_MOD dependent code */
-48
include/target/target_core_configfs.h
··· 1 - #define TARGET_CORE_CONFIGFS_VERSION TARGET_CORE_MOD_VERSION 2 - 3 - #define TARGET_CORE_CONFIG_ROOT "/sys/kernel/config" 4 - 5 - #define TARGET_CORE_NAME_MAX_LEN 64 6 - #define TARGET_FABRIC_NAME_SIZE 32 7 - 8 - struct target_fabric_configfs_template { 9 - struct config_item_type tfc_discovery_cit; 10 - struct config_item_type tfc_wwn_cit; 11 - struct config_item_type tfc_wwn_fabric_stats_cit; 12 - struct config_item_type tfc_tpg_cit; 13 - struct config_item_type tfc_tpg_base_cit; 14 - struct config_item_type tfc_tpg_lun_cit; 15 - struct config_item_type tfc_tpg_port_cit; 16 - struct config_item_type tfc_tpg_port_stat_cit; 17 - struct config_item_type tfc_tpg_np_cit; 18 - struct config_item_type tfc_tpg_np_base_cit; 19 - struct config_item_type tfc_tpg_attrib_cit; 20 - struct config_item_type tfc_tpg_auth_cit; 21 - struct config_item_type tfc_tpg_param_cit; 22 - struct config_item_type tfc_tpg_nacl_cit; 23 - struct config_item_type tfc_tpg_nacl_base_cit; 24 - struct config_item_type tfc_tpg_nacl_attrib_cit; 25 - struct config_item_type tfc_tpg_nacl_auth_cit; 26 - struct config_item_type tfc_tpg_nacl_param_cit; 27 - struct config_item_type tfc_tpg_nacl_stat_cit; 28 - struct config_item_type tfc_tpg_mappedlun_cit; 29 - struct config_item_type tfc_tpg_mappedlun_stat_cit; 30 - }; 31 - 32 - struct target_fabric_configfs { 33 - char tf_name[TARGET_FABRIC_NAME_SIZE]; 34 - atomic_t tf_access_cnt; 35 - struct list_head tf_list; 36 - struct config_group tf_group; 37 - struct config_group tf_disc_group; 38 - struct config_group *tf_default_groups[2]; 39 - /* Pointer to fabric's config_item */ 40 - struct config_item *tf_fabric; 41 - /* Passed from fabric modules */ 42 - struct config_item_type *tf_fabric_cit; 43 - /* Pointer to fabric's struct module */ 44 - struct module *tf_module; 45 - struct target_core_fabric_ops tf_ops; 46 - struct target_fabric_configfs_template tf_cit_tmpl; 47 - }; 48 -
+11 -60
include/target/target_core_fabric.h
··· 4 4 struct target_core_fabric_ops { 5 5 struct module *module; 6 6 const char *name; 7 + size_t node_acl_size; 7 8 char *(*get_fabric_name)(void); 8 - u8 (*get_fabric_proto_ident)(struct se_portal_group *); 9 9 char *(*tpg_get_wwn)(struct se_portal_group *); 10 10 u16 (*tpg_get_tag)(struct se_portal_group *); 11 11 u32 (*tpg_get_default_depth)(struct se_portal_group *); 12 - u32 (*tpg_get_pr_transport_id)(struct se_portal_group *, 13 - struct se_node_acl *, 14 - struct t10_pr_registration *, int *, 15 - unsigned char *); 16 - u32 (*tpg_get_pr_transport_id_len)(struct se_portal_group *, 17 - struct se_node_acl *, 18 - struct t10_pr_registration *, int *); 19 - char *(*tpg_parse_pr_out_transport_id)(struct se_portal_group *, 20 - const char *, u32 *, char **); 21 12 int (*tpg_check_demo_mode)(struct se_portal_group *); 22 13 int (*tpg_check_demo_mode_cache)(struct se_portal_group *); 23 14 int (*tpg_check_demo_mode_write_protect)(struct se_portal_group *); ··· 27 36 * WRITE_STRIP and READ_INSERT operations. 28 37 */ 29 38 int (*tpg_check_prot_fabric_only)(struct se_portal_group *); 30 - struct se_node_acl *(*tpg_alloc_fabric_acl)( 31 - struct se_portal_group *); 32 - void (*tpg_release_fabric_acl)(struct se_portal_group *, 33 - struct se_node_acl *); 34 39 u32 (*tpg_get_inst_index)(struct se_portal_group *); 35 40 /* 36 41 * Optional to release struct se_cmd and fabric dependent allocated ··· 37 50 */ 38 51 int (*check_stop_free)(struct se_cmd *); 39 52 void (*release_cmd)(struct se_cmd *); 40 - void (*put_session)(struct se_session *); 41 53 /* 42 54 * Called with spin_lock_bh(struct se_portal_group->session_lock held. 43 55 */ ··· 52 66 int (*write_pending)(struct se_cmd *); 53 67 int (*write_pending_status)(struct se_cmd *); 54 68 void (*set_default_node_attributes)(struct se_node_acl *); 55 - u32 (*get_task_tag)(struct se_cmd *); 56 69 int (*get_cmd_state)(struct se_cmd *); 57 70 int (*queue_data_in)(struct se_cmd *); 58 71 int (*queue_status)(struct se_cmd *); ··· 73 88 struct se_tpg_np *(*fabric_make_np)(struct se_portal_group *, 74 89 struct config_group *, const char *); 75 90 void (*fabric_drop_np)(struct se_tpg_np *); 76 - struct se_node_acl *(*fabric_make_nodeacl)(struct se_portal_group *, 77 - struct config_group *, const char *); 78 - void (*fabric_drop_nodeacl)(struct se_node_acl *); 91 + int (*fabric_init_nodeacl)(struct se_node_acl *, const char *); 92 + void (*fabric_cleanup_nodeacl)(struct se_node_acl *); 79 93 80 94 struct configfs_attribute **tfc_discovery_attrs; 81 95 struct configfs_attribute **tfc_wwn_attrs; ··· 116 132 void transport_init_se_cmd(struct se_cmd *, 117 133 const struct target_core_fabric_ops *, 118 134 struct se_session *, u32, int, int, unsigned char *); 119 - sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u32); 135 + sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64); 120 136 sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); 121 137 int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *, 122 - unsigned char *, unsigned char *, u32, u32, int, int, int, 138 + unsigned char *, unsigned char *, u64, u32, int, int, int, 123 139 struct scatterlist *, u32, struct scatterlist *, u32, 124 140 struct scatterlist *, u32); 125 141 int target_submit_cmd(struct se_cmd *, struct se_session *, unsigned char *, 126 - unsigned char *, u32, u32, int, int, int); 142 + unsigned char *, u64, u32, int, int, int); 127 143 int target_submit_tmr(struct se_cmd *se_cmd, struct se_session *se_sess, 128 - unsigned char *sense, u32 unpacked_lun, 144 + unsigned char *sense, u64 unpacked_lun, 129 145 void *fabric_tmr_ptr, unsigned char tm_type, 130 146 gfp_t, unsigned int, int); 131 147 int transport_handle_cdb_direct(struct se_cmd *); ··· 139 155 int transport_check_aborted_status(struct se_cmd *, int); 140 156 int transport_send_check_condition_and_sense(struct se_cmd *, 141 157 sense_reason_t, int); 142 - int target_get_sess_cmd(struct se_session *, struct se_cmd *, bool); 143 - int target_put_sess_cmd(struct se_session *, struct se_cmd *); 158 + int target_get_sess_cmd(struct se_cmd *, bool); 159 + int target_put_sess_cmd(struct se_cmd *); 144 160 void target_sess_cmd_list_set_waiting(struct se_session *); 145 161 void target_wait_for_sess_cmds(struct se_session *); 146 162 ··· 151 167 int transport_generic_handle_tmr(struct se_cmd *); 152 168 void transport_generic_request_failure(struct se_cmd *, sense_reason_t); 153 169 void __target_execute_cmd(struct se_cmd *); 154 - int transport_lookup_tmr_lun(struct se_cmd *, u32); 170 + int transport_lookup_tmr_lun(struct se_cmd *, u64); 155 171 156 172 struct se_node_acl *core_tpg_get_initiator_node_acl(struct se_portal_group *tpg, 157 173 unsigned char *); 158 174 struct se_node_acl *core_tpg_check_initiator_node_acl(struct se_portal_group *, 159 175 unsigned char *); 160 - void core_tpg_clear_object_luns(struct se_portal_group *); 161 - struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *, 162 - struct se_node_acl *, const char *, u32); 163 - int core_tpg_del_initiator_node_acl(struct se_portal_group *, 164 - struct se_node_acl *, int); 165 176 int core_tpg_set_initiator_node_queue_depth(struct se_portal_group *, 166 177 unsigned char *, u32, int); 167 178 int core_tpg_set_initiator_node_tag(struct se_portal_group *, 168 179 struct se_node_acl *, const char *); 169 - int core_tpg_register(const struct target_core_fabric_ops *, 170 - struct se_wwn *, struct se_portal_group *, void *, int); 180 + int core_tpg_register(struct se_wwn *, struct se_portal_group *, int); 171 181 int core_tpg_deregister(struct se_portal_group *); 172 - 173 - /* SAS helpers */ 174 - u8 sas_get_fabric_proto_ident(struct se_portal_group *); 175 - u32 sas_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *, 176 - struct t10_pr_registration *, int *, unsigned char *); 177 - u32 sas_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *, 178 - struct t10_pr_registration *, int *); 179 - char *sas_parse_pr_out_transport_id(struct se_portal_group *, const char *, 180 - u32 *, char **); 181 - 182 - /* FC helpers */ 183 - u8 fc_get_fabric_proto_ident(struct se_portal_group *); 184 - u32 fc_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *, 185 - struct t10_pr_registration *, int *, unsigned char *); 186 - u32 fc_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *, 187 - struct t10_pr_registration *, int *); 188 - char *fc_parse_pr_out_transport_id(struct se_portal_group *, const char *, 189 - u32 *, char **); 190 - 191 - /* iSCSI helpers */ 192 - u8 iscsi_get_fabric_proto_ident(struct se_portal_group *); 193 - u32 iscsi_get_pr_transport_id(struct se_portal_group *, struct se_node_acl *, 194 - struct t10_pr_registration *, int *, unsigned char *); 195 - u32 iscsi_get_pr_transport_id_len(struct se_portal_group *, struct se_node_acl *, 196 - struct t10_pr_registration *, int *); 197 - char *iscsi_parse_pr_out_transport_id(struct se_portal_group *, const char *, 198 - u32 *, char **); 199 182 200 183 /* 201 184 * The LIO target core uses DMA_TO_DEVICE to mean that data is going
+9 -3
lib/crc-t10dif.c
··· 19 19 static struct crypto_shash *crct10dif_tfm; 20 20 static struct static_key crct10dif_fallback __read_mostly; 21 21 22 - __u16 crc_t10dif(const unsigned char *buffer, size_t len) 22 + __u16 crc_t10dif_update(__u16 crc, const unsigned char *buffer, size_t len) 23 23 { 24 24 struct { 25 25 struct shash_desc shash; ··· 28 28 int err; 29 29 30 30 if (static_key_false(&crct10dif_fallback)) 31 - return crc_t10dif_generic(0, buffer, len); 31 + return crc_t10dif_generic(crc, buffer, len); 32 32 33 33 desc.shash.tfm = crct10dif_tfm; 34 34 desc.shash.flags = 0; 35 - *(__u16 *)desc.ctx = 0; 35 + *(__u16 *)desc.ctx = crc; 36 36 37 37 err = crypto_shash_update(&desc.shash, buffer, len); 38 38 BUG_ON(err); 39 39 40 40 return *(__u16 *)desc.ctx; 41 + } 42 + EXPORT_SYMBOL(crc_t10dif_update); 43 + 44 + __u16 crc_t10dif(const unsigned char *buffer, size_t len) 45 + { 46 + return crc_t10dif_update(0, buffer, len); 41 47 } 42 48 EXPORT_SYMBOL(crc_t10dif); 43 49