diff mbox series

[v3,5/5] scsi: target: core: Add RTPI attribute for target port

Message ID 20221202121139.28180-6-d.bogdanov@yadro.com (mailing list archive)
State New, archived
Headers show
Series scsi: target: make RTPI an TPG identifier | expand

Commit Message

Dmitry Bogdanov Dec. 2, 2022, 12:11 p.m. UTC
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@yadro.com>
Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>
---
 drivers/target/target_core_tpg.c  | 55 +++++++++++++++++++++++++++++--
 include/target/target_core_base.h |  1 +
 2 files changed, 54 insertions(+), 2 deletions(-)

Comments

kernel test robot Dec. 2, 2022, 5:05 p.m. UTC | #1
Hi Dmitry,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on linus/master v6.1-rc7 next-20221202]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dmitry-Bogdanov/scsi-target-make-RTPI-an-TPG-identifier/20221202-201253
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20221202121139.28180-6-d.bogdanov%40yadro.com
patch subject: [PATCH v3 5/5] scsi: target: core: Add RTPI attribute for target port
config: m68k-allyesconfig
compiler: m68k-linux-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/723c027e6e5ae5c1455eaae52815c696cc7cc38b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Dmitry-Bogdanov/scsi-target-make-RTPI-an-TPG-identifier/20221202-201253
        git checkout 723c027e6e5ae5c1455eaae52815c696cc7cc38b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=m68k SHELL=/bin/bash drivers/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/target/target_core_tpg.c: In function 'target_tpg_disable':
   drivers/target/target_core_tpg.c:491:13: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
     491 |         int ret;
         |             ^~~
   drivers/target/target_core_tpg.c: At top level:
>> drivers/target/target_core_tpg.c:670:6: warning: no previous prototype for 'target_tpg_remove_lun' [-Wmissing-prototypes]
     670 | void target_tpg_remove_lun(
         |      ^~~~~~~~~~~~~~~~~~~~~


vim +/target_tpg_remove_lun +670 drivers/target/target_core_tpg.c

   669	
 > 670	void target_tpg_remove_lun(
   671		struct se_portal_group *tpg,
   672		struct se_lun *lun)
   673	{
   674		/*
   675		 * rcu_dereference_raw protected by se_lun->lun_group symlink
   676		 * reference to se_device->dev_group.
   677		 */
   678		struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev);
   679	
   680		lun->lun_shutdown = true;
   681	
   682		core_clear_lun_from_tpg(lun, tpg);
   683		/*
   684		 * Wait for any active I/O references to percpu se_lun->lun_ref to
   685		 * be released.  Also, se_lun->lun_ref is now used by PR and ALUA
   686		 * logic when referencing a remote target port during ALL_TGT_PT=1
   687		 * and generating UNIT_ATTENTIONs for ALUA access state transition.
   688		 */
   689		transport_clear_lun_ref(lun);
   690	
   691		mutex_lock(&tpg->tpg_lun_mutex);
   692		if (lun->lun_se_dev) {
   693			target_detach_tg_pt_gp(lun);
   694	
   695			spin_lock(&dev->se_port_lock);
   696			list_del(&lun->lun_dev_link);
   697			dev->export_count--;
   698			rcu_assign_pointer(lun->lun_se_dev, NULL);
   699			spin_unlock(&dev->se_port_lock);
   700		}
   701		if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE))
   702			hlist_del_rcu(&lun->link);
   703	
   704		lun->lun_shutdown = false;
   705		mutex_unlock(&tpg->tpg_lun_mutex);
   706	
   707		percpu_ref_exit(&lun->lun_ref);
   708	}
   709
kernel test robot Dec. 2, 2022, 7:17 p.m. UTC | #2
Hi Dmitry,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on linus/master v6.1-rc7 next-20221202]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dmitry-Bogdanov/scsi-target-make-RTPI-an-TPG-identifier/20221202-201253
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20221202121139.28180-6-d.bogdanov%40yadro.com
patch subject: [PATCH v3 5/5] scsi: target: core: Add RTPI attribute for target port
config: arm-randconfig-r026-20221201
compiler: clang version 16.0.0 (https://github.com/llvm/llvm-project 6e4cea55f0d1104408b26ac574566a0e4de48036)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/intel-lab-lkp/linux/commit/723c027e6e5ae5c1455eaae52815c696cc7cc38b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Dmitry-Bogdanov/scsi-target-make-RTPI-an-TPG-identifier/20221202-201253
        git checkout 723c027e6e5ae5c1455eaae52815c696cc7cc38b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash drivers/target/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/target/target_core_tpg.c:491:6: warning: variable 'ret' set but not used [-Wunused-but-set-variable]
           int ret;
               ^
>> drivers/target/target_core_tpg.c:670:6: warning: no previous prototype for function 'target_tpg_remove_lun' [-Wmissing-prototypes]
   void target_tpg_remove_lun(
        ^
   drivers/target/target_core_tpg.c:670:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void target_tpg_remove_lun(
   ^
   static 
   2 warnings generated.


vim +/target_tpg_remove_lun +670 drivers/target/target_core_tpg.c

   669	
 > 670	void target_tpg_remove_lun(
   671		struct se_portal_group *tpg,
   672		struct se_lun *lun)
   673	{
   674		/*
   675		 * rcu_dereference_raw protected by se_lun->lun_group symlink
   676		 * reference to se_device->dev_group.
   677		 */
   678		struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev);
   679	
   680		lun->lun_shutdown = true;
   681	
   682		core_clear_lun_from_tpg(lun, tpg);
   683		/*
   684		 * Wait for any active I/O references to percpu se_lun->lun_ref to
   685		 * be released.  Also, se_lun->lun_ref is now used by PR and ALUA
   686		 * logic when referencing a remote target port during ALL_TGT_PT=1
   687		 * and generating UNIT_ATTENTIONs for ALUA access state transition.
   688		 */
   689		transport_clear_lun_ref(lun);
   690	
   691		mutex_lock(&tpg->tpg_lun_mutex);
   692		if (lun->lun_se_dev) {
   693			target_detach_tg_pt_gp(lun);
   694	
   695			spin_lock(&dev->se_port_lock);
   696			list_del(&lun->lun_dev_link);
   697			dev->export_count--;
   698			rcu_assign_pointer(lun->lun_se_dev, NULL);
   699			spin_unlock(&dev->se_port_lock);
   700		}
   701		if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE))
   702			hlist_del_rcu(&lun->link);
   703	
   704		lun->lun_shutdown = false;
   705		mutex_unlock(&tpg->tpg_lun_mutex);
   706	
   707		percpu_ref_exit(&lun->lun_ref);
   708	}
   709
kernel test robot Dec. 2, 2022, 9:18 p.m. UTC | #3
Hi Dmitry,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on linus/master v6.1-rc7 next-20221202]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Dmitry-Bogdanov/scsi-target-make-RTPI-an-TPG-identifier/20221202-201253
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
patch link:    https://lore.kernel.org/r/20221202121139.28180-6-d.bogdanov%40yadro.com
patch subject: [PATCH v3 5/5] scsi: target: core: Add RTPI attribute for target port
config: arm-randconfig-c041-20221201
compiler: arm-linux-gnueabi-gcc (GCC) 12.1.0
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/723c027e6e5ae5c1455eaae52815c696cc7cc38b
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Dmitry-Bogdanov/scsi-target-make-RTPI-an-TPG-identifier/20221202-201253
        git checkout 723c027e6e5ae5c1455eaae52815c696cc7cc38b
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-12.1.0 make.cross W=1 O=build_dir ARCH=arm SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

   arm-linux-gnueabi-ld: drivers/target/target_core_device.o: in function `core_dev_del_lun':
   target_core_device.c:(.text+0xa40): undefined reference to `core_tpg_remove_lun'
>> arm-linux-gnueabi-ld: target_core_device.c:(.text+0xa72): undefined reference to `core_tpg_remove_lun'
   arm-linux-gnueabi-ld: drivers/target/target_core_tpg.o: in function `core_tpg_deregister':
   target_core_tpg.c:(.text+0xa42): undefined reference to `core_tpg_remove_lun'
Mike Christie Dec. 21, 2022, 12:15 a.m. UTC | #4
On 12/2/22 6:11 AM, Dmitry Bogdanov wrote:
> RELATIVE TARGET PORT IDENTIFIER can be read and configured via configfs:
> $ echo 0x10 > $TARGET/tpgt_N/attrib/rtpi
> 

Hey Dimitry, I think your idea to place this on the tpgt_n is nicer
because you can more easily set it and there is already code for
that type of thing.
diff mbox series

Patch

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 */