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

scsi: target: core: Add RTPI field to target port

SAM-5 4.6.5.2 (Relative Port Identifier attribute) defines the attribute as
unique across SCSI target ports.

The change introduces RTPI attribute to se_portal group. The value is
unique across all enabled SCSI target ports. It also limits number of SCSI
target ports to 65535.

Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
Link: https://lore.kernel.org/r/20230301084512.21956-2-d.bogdanov@yadro.com
Reviewed-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Dmitry Bogdanov and committed by
Martin K. Petersen
3f4b9cb4 fe15c26e

+62 -5
+4 -5
drivers/target/target_core_fabric_configfs.c
··· 836 836 837 837 if (se_tpg->enabled == op) 838 838 return count; 839 - 840 - ret = se_tpg->se_tpg_tfo->fabric_enable_tpg(se_tpg, op); 839 + if (op) 840 + ret = target_tpg_enable(se_tpg); 841 + else 842 + ret = target_tpg_disable(se_tpg); 841 843 if (ret) 842 844 return ret; 843 - 844 - se_tpg->enabled = op; 845 - 846 845 return count; 847 846 } 848 847
+2
drivers/target/target_core_internal.h
··· 132 132 struct se_node_acl *core_tpg_add_initiator_node_acl(struct se_portal_group *tpg, 133 133 const char *initiatorname); 134 134 void core_tpg_del_initiator_node_acl(struct se_node_acl *acl); 135 + int target_tpg_enable(struct se_portal_group *se_tpg); 136 + int target_tpg_disable(struct se_portal_group *se_tpg); 135 137 136 138 /* target_core_transport.c */ 137 139 int init_se_kmem_caches(void);
+54
drivers/target/target_core_tpg.c
··· 31 31 #include "target_core_ua.h" 32 32 33 33 extern struct se_device *g_lun0_dev; 34 + static DEFINE_XARRAY_ALLOC(tpg_xa); 34 35 35 36 /* __core_tpg_get_initiator_node_acl(): 36 37 * ··· 440 439 complete(&lun->lun_shutdown_comp); 441 440 } 442 441 442 + static int target_tpg_register_rtpi(struct se_portal_group *se_tpg) 443 + { 444 + u32 val; 445 + int ret; 446 + 447 + ret = xa_alloc(&tpg_xa, &val, se_tpg, 448 + XA_LIMIT(1, USHRT_MAX), GFP_KERNEL); 449 + if (!ret) 450 + se_tpg->tpg_rtpi = val; 451 + 452 + return ret; 453 + } 454 + 455 + static void target_tpg_deregister_rtpi(struct se_portal_group *se_tpg) 456 + { 457 + if (se_tpg->tpg_rtpi && se_tpg->enabled) 458 + xa_erase(&tpg_xa, se_tpg->tpg_rtpi); 459 + } 460 + 461 + int target_tpg_enable(struct se_portal_group *se_tpg) 462 + { 463 + int ret; 464 + 465 + ret = target_tpg_register_rtpi(se_tpg); 466 + if (ret) 467 + return ret; 468 + 469 + ret = se_tpg->se_tpg_tfo->fabric_enable_tpg(se_tpg, true); 470 + if (ret) { 471 + target_tpg_deregister_rtpi(se_tpg); 472 + return ret; 473 + } 474 + 475 + se_tpg->enabled = true; 476 + 477 + return 0; 478 + } 479 + 480 + int target_tpg_disable(struct se_portal_group *se_tpg) 481 + { 482 + int ret; 483 + 484 + target_tpg_deregister_rtpi(se_tpg); 485 + 486 + ret = se_tpg->se_tpg_tfo->fabric_enable_tpg(se_tpg, false); 487 + if (!ret) 488 + se_tpg->enabled = false; 489 + 490 + return ret; 491 + } 492 + 443 493 /* Does not change se_wwn->priv. */ 444 494 int core_tpg_register( 445 495 struct se_wwn *se_wwn, ··· 586 534 core_tpg_remove_lun(se_tpg, se_tpg->tpg_virt_lun0); 587 535 kfree_rcu(se_tpg->tpg_virt_lun0, rcu_head); 588 536 } 537 + 538 + target_tpg_deregister_rtpi(se_tpg); 589 539 590 540 return 0; 591 541 }
+2
include/target/target_core_base.h
··· 920 920 */ 921 921 int proto_id; 922 922 bool enabled; 923 + /* RELATIVE TARGET PORT IDENTIFIER */ 924 + u16 tpg_rtpi; 923 925 /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ 924 926 atomic_t tpg_pr_ref_count; 925 927 /* Spinlock for adding/removing ACLed Nodes */