RELATIVE TARGET PORT IDENTIFIER can be read and configured via configfs: $ echo 0x10 > $TARGET/tpgt_N/attrib/rtpi RTPI can be changed only on disabled target ports. Signed-off-by: Roman Bolshakov <r.bolshakov@xxxxxxxxx> Signed-off-by: Dmitry Bogdanov <d.bogdanov@xxxxxxxxx> --- drivers/target/target_core_tpg.c | 55 +++++++++++++++++++++++++++++-- include/target/target_core_base.h | 1 + 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c index f39e69050db6..24ca10b455fb 100644 --- a/drivers/target/target_core_tpg.c +++ b/drivers/target/target_core_tpg.c @@ -442,8 +442,23 @@ static void core_tpg_lun_ref_release(struct percpu_ref *ref) static int target_tpg_register_rtpi(struct se_portal_group *se_tpg) { - return xa_alloc(&tpg_xa, &se_tpg->tpg_rtpi, se_tpg, + int ret; + + if (se_tpg->rtpi_manual) { + ret = xa_insert(&tpg_xa, se_tpg->tpg_rtpi, se_tpg, GFP_KERNEL); + if (ret) { + pr_info("%s_TPG[%hu] - Can not set RTPI %#x, it is already busy", + se_tpg->se_tpg_tfo->fabric_name, + se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg), + se_tpg->tpg_rtpi); + return -EINVAL; + } + } else { + ret = xa_alloc(&tpg_xa, &se_tpg->tpg_rtpi, se_tpg, XA_LIMIT(1, USHRT_MAX), GFP_KERNEL); + } + + return ret; } static void target_tpg_deregister_rtpi(struct se_portal_group *se_tpg) @@ -652,7 +667,7 @@ int core_tpg_add_lun( return ret; } -void core_tpg_remove_lun( +void target_tpg_remove_lun( struct se_portal_group *tpg, struct se_lun *lun) { @@ -692,6 +707,42 @@ void core_tpg_remove_lun( percpu_ref_exit(&lun->lun_ref); } +static ssize_t target_tpg_rtpi_show(struct config_item *item, char *page) +{ + struct se_portal_group *se_tpg = attrib_to_tpg(item); + + return sysfs_emit(page, "%#x\n", se_tpg->tpg_rtpi); +} + +static ssize_t target_tpg_rtpi_store(struct config_item *item, + const char *page, size_t count) +{ + struct se_portal_group *se_tpg = attrib_to_tpg(item); + u16 val; + int ret; + + ret = kstrtou16(page, 0, &val); + if (ret < 0) + return ret; + if (val == 0) + return -EINVAL; + + if (se_tpg->enabled) { + pr_info("%s_TPG[%hu] - Can not change RTPI on enabled TPG", + se_tpg->se_tpg_tfo->fabric_name, + se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); + return -EINVAL; + } + + se_tpg->tpg_rtpi = val; + se_tpg->rtpi_manual = true; + + return count; +} + +CONFIGFS_ATTR(target_tpg_, rtpi); + struct configfs_attribute *core_tpg_attrib_attrs[] = { + &target_tpg_attr_rtpi, NULL, }; diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h index 2e6de5ba8172..29fb036511e5 100644 --- a/include/target/target_core_base.h +++ b/include/target/target_core_base.h @@ -918,6 +918,7 @@ struct se_portal_group { bool enabled; /* RELATIVE TARGET PORT IDENTIFIER */ u32 tpg_rtpi; + bool rtpi_manual; /* Used for PR SPEC_I_PT=1 and REGISTER_AND_MOVE */ atomic_t tpg_pr_ref_count; /* Spinlock for adding/removing ACLed Nodes */ -- 2.25.1