diff mbox series

[12/17] target: hook most target users into sysfs API

Message ID 1591562164-9766-13-git-send-email-michael.christie@oracle.com (mailing list archive)
State Changes Requested
Headers show
Series [01/17] target: check enforce_pr_isids during registration | expand

Commit Message

Mike Christie June 7, 2020, 8:35 p.m. UTC
This hooks lio core and all the targets but iscsi into the sysfs API.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/target/Makefile                |  1 +
 drivers/target/target_core_configfs.c  |  3 +++
 drivers/target/target_core_internal.h  |  1 +
 drivers/target/target_core_transport.c | 38 ++++++++++++++++++++++++++++------
 4 files changed, 37 insertions(+), 6 deletions(-)

Comments

Hannes Reinecke June 8, 2020, 6:15 a.m. UTC | #1
On 6/7/20 10:35 PM, Mike Christie wrote:
> This hooks lio core and all the targets but iscsi into the sysfs API.
> 
> Signed-off-by: Mike Christie <michael.christie@oracle.com>
> ---
>   drivers/target/Makefile                |  1 +
>   drivers/target/target_core_configfs.c  |  3 +++
>   drivers/target/target_core_internal.h  |  1 +
>   drivers/target/target_core_transport.c | 38 ++++++++++++++++++++++++++++------
>   4 files changed, 37 insertions(+), 6 deletions(-)
> Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
kernel test robot June 8, 2020, 10:20 a.m. UTC | #2
Hi Mike,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on mkp-scsi/for-next]
[also build test ERROR on scsi/for-next vhost/linux-next xen-tip/linux-next v5.7 next-20200605]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Mike-Christie/target-add-sysfs-support/20200608-044027
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: sparc-allyesconfig (attached as .config)
compiler: sparc64-linux-gcc (GCC) 9.3.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
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=sparc 

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

Note: the linux-review/Mike-Christie/target-add-sysfs-support/20200608-044027 HEAD fc08cd1eb111346ece0dceae6f01be21509d2c49 builds fine.
      It only hurts bisectibility.

All errors (new ones prefixed by >>, old ones prefixed by <<):

drivers/target/target_core_sysfs.c: In function 'target_cp_endpoint_strs':
>> drivers/target/target_core_sysfs.c:172:13: error: 'struct se_session' has no member named 'tfo'
172 |  if (se_sess->tfo->fabric_alias)
|             ^~
drivers/target/target_core_sysfs.c:173:41: error: 'struct se_session' has no member named 'tfo'
173 |   se_sess->fabric_name = kstrdup(se_sess->tfo->fabric_alias,
|                                         ^~
drivers/target/target_core_sysfs.c:176:41: error: 'struct se_session' has no member named 'tfo'
176 |   se_sess->fabric_name = kstrdup(se_sess->tfo->fabric_name,
|                                         ^~
drivers/target/target_core_sysfs.c: In function 'target_sysfs_add_session':
drivers/target/target_core_sysfs.c:206:29: error: 'struct se_session' has no member named 'tfo'
206 |  if (!try_module_get(se_sess->tfo->module))
|                             ^~
drivers/target/target_core_sysfs.c:213:31: error: 'struct se_session' has no member named 'tfo'
213 |  se_sess->dev.groups = se_sess->tfo->session_attr_groups;
|                               ^~
drivers/target/target_core_sysfs.c:233:20: error: 'struct se_session' has no member named 'tfo'
233 |  module_put(se_sess->tfo->module);
|                    ^~

vim +172 drivers/target/target_core_sysfs.c

03975f2939ad69 Mike Christie 2020-06-07  151  
03975f2939ad69 Mike Christie 2020-06-07  152  static int target_cp_endpoint_strs(struct se_portal_group *se_tpg,
03975f2939ad69 Mike Christie 2020-06-07  153  				   struct se_session *se_sess)
03975f2939ad69 Mike Christie 2020-06-07  154  {
03975f2939ad69 Mike Christie 2020-06-07  155  	/*
03975f2939ad69 Mike Christie 2020-06-07  156  	 * Copy configfs dir/object names so userspace can match the session
03975f2939ad69 Mike Christie 2020-06-07  157  	 * to its target, and we also don't have to worry about mixing configfs
03975f2939ad69 Mike Christie 2020-06-07  158  	 * refcounts with sysfs.
03975f2939ad69 Mike Christie 2020-06-07  159  	 */
03975f2939ad69 Mike Christie 2020-06-07  160  	if (!se_sess->se_node_acl->dynamic_node_acl) {
03975f2939ad69 Mike Christie 2020-06-07  161  		se_sess->acl_name = kstrdup(se_sess->se_node_acl->initiatorname,
03975f2939ad69 Mike Christie 2020-06-07  162  					    GFP_KERNEL);
03975f2939ad69 Mike Christie 2020-06-07  163  		if (!se_sess->acl_name)
03975f2939ad69 Mike Christie 2020-06-07  164  			return -ENOMEM;
03975f2939ad69 Mike Christie 2020-06-07  165  	}
03975f2939ad69 Mike Christie 2020-06-07  166  
03975f2939ad69 Mike Christie 2020-06-07  167  	se_sess->target_name = kstrdup(se_tpg->se_tpg_wwn->wwn_group.cg_item.ci_name,
03975f2939ad69 Mike Christie 2020-06-07  168  				       GFP_KERNEL);
03975f2939ad69 Mike Christie 2020-06-07  169  	if (!se_sess->target_name)
03975f2939ad69 Mike Christie 2020-06-07  170  		goto free_acl;
03975f2939ad69 Mike Christie 2020-06-07  171  
03975f2939ad69 Mike Christie 2020-06-07 @172  	if (se_sess->tfo->fabric_alias)
03975f2939ad69 Mike Christie 2020-06-07  173  		se_sess->fabric_name = kstrdup(se_sess->tfo->fabric_alias,
03975f2939ad69 Mike Christie 2020-06-07  174  					       GFP_KERNEL);
03975f2939ad69 Mike Christie 2020-06-07  175  	else
03975f2939ad69 Mike Christie 2020-06-07  176  		se_sess->fabric_name = kstrdup(se_sess->tfo->fabric_name,
03975f2939ad69 Mike Christie 2020-06-07  177  					       GFP_KERNEL);
03975f2939ad69 Mike Christie 2020-06-07  178  	if (!se_sess->fabric_name)
03975f2939ad69 Mike Christie 2020-06-07  179  		goto free_target;
03975f2939ad69 Mike Christie 2020-06-07  180  
03975f2939ad69 Mike Christie 2020-06-07  181  	se_sess->tpg_name = kstrdup(se_tpg->tpg_group.cg_item.ci_name,
03975f2939ad69 Mike Christie 2020-06-07  182  				    GFP_KERNEL);
03975f2939ad69 Mike Christie 2020-06-07  183  	if (!se_sess->tpg_name)
03975f2939ad69 Mike Christie 2020-06-07  184  		goto free_fabric;
03975f2939ad69 Mike Christie 2020-06-07  185  
03975f2939ad69 Mike Christie 2020-06-07  186  	return 0;
03975f2939ad69 Mike Christie 2020-06-07  187  
03975f2939ad69 Mike Christie 2020-06-07  188  free_fabric:
03975f2939ad69 Mike Christie 2020-06-07  189  	kfree(se_sess->fabric_name);
03975f2939ad69 Mike Christie 2020-06-07  190  	se_sess->fabric_name = NULL;
03975f2939ad69 Mike Christie 2020-06-07  191  free_target:
03975f2939ad69 Mike Christie 2020-06-07  192  	kfree(se_sess->target_name);
03975f2939ad69 Mike Christie 2020-06-07  193  	se_sess->target_name = NULL;
03975f2939ad69 Mike Christie 2020-06-07  194  free_acl:
03975f2939ad69 Mike Christie 2020-06-07  195  	kfree(se_sess->acl_name);
03975f2939ad69 Mike Christie 2020-06-07  196  	se_sess->acl_name = NULL;
03975f2939ad69 Mike Christie 2020-06-07  197  	return -ENOMEM;
03975f2939ad69 Mike Christie 2020-06-07  198  }
03975f2939ad69 Mike Christie 2020-06-07  199  

:::::: The code at line 172 was first introduced by commit
:::::: 03975f2939ad69a19b1a7cdd49cb83e66258688e target: add session sysfs class support

:::::: TO: Mike Christie <michael.christie@oracle.com>
:::::: CC: 0day robot <lkp@intel.com>

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
diff mbox series

Patch

diff --git a/drivers/target/Makefile b/drivers/target/Makefile
index 4563474..4a7246e 100644
--- a/drivers/target/Makefile
+++ b/drivers/target/Makefile
@@ -1,6 +1,7 @@ 
 # SPDX-License-Identifier: GPL-2.0
 
 target_core_mod-y		:= target_core_configfs.o \
+				   target_core_sysfs.o \
 				   target_core_device.o \
 				   target_core_fabric_configfs.o \
 				   target_core_fabric_lib.o \
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index ff82b21f..c23552b 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -3537,6 +3537,7 @@  static int __init target_core_init_configfs(void)
 		goto out;
 
 	target_init_dbroot();
+	target_sysfs_init();
 
 	return 0;
 
@@ -3555,6 +3556,8 @@  static int __init target_core_init_configfs(void)
 
 static void __exit target_core_exit_configfs(void)
 {
+	target_sysfs_exit();
+
 	configfs_remove_default_groups(&alua_lu_gps_group);
 	configfs_remove_default_groups(&alua_group);
 	configfs_remove_default_groups(&target_core_hbagroup);
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 93bf5fed..23d9a0e 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -157,6 +157,7 @@  void	transport_dump_dev_info(struct se_device *, struct se_lun *,
 bool	target_check_wce(struct se_device *dev);
 bool	target_check_fua(struct se_device *dev);
 void	__target_execute_cmd(struct se_cmd *, bool);
+void	__target_free_session(struct se_session *se_sess);
 
 /* target_core_stat.c */
 void	target_stat_setup_dev_default_groups(struct se_device *);
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 5d6d736..34da12a 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -22,6 +22,7 @@ 
 #include <linux/module.h>
 #include <linux/ratelimit.h>
 #include <linux/vmalloc.h>
+#include <linux/device.h>
 #include <asm/unaligned.h>
 #include <net/sock.h>
 #include <net/tcp.h>
@@ -251,14 +252,27 @@  struct se_session *transport_alloc_session(enum target_prot_op sup_prot_ops)
 				" se_sess_cache\n");
 		return ERR_PTR(-ENOMEM);
 	}
-	ret = transport_init_session(se_sess);
-	if (ret < 0) {
+
+	ret = target_sysfs_init_session(se_sess);
+	if (ret) {
 		kmem_cache_free(se_sess_cache, se_sess);
 		return ERR_PTR(ret);
 	}
-	se_sess->sup_prot_ops = sup_prot_ops;
+	/*
+	 * After this point we switch from handlng the freeing of the sess
+	 * to using the se_sess->dev refcounting.
+	 */
 
+	ret = transport_init_session(se_sess);
+	if (ret < 0)
+		goto put_dev;
+
+	se_sess->sup_prot_ops = sup_prot_ops;
 	return se_sess;
+
+put_dev:
+	put_device(&se_sess->dev);
+	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL(transport_alloc_session);
 
@@ -457,6 +471,10 @@  struct se_session *
 		rc = -EACCES;
 		goto free_sess;
 	}
+
+	rc = target_sysfs_add_session(tpg, sess);
+	if (rc)
+		goto free_sess;
 	/*
 	 * Go ahead and perform any remaining fabric setup that is
 	 * required before transport_register_session().
@@ -464,12 +482,14 @@  struct se_session *
 	if (callback != NULL) {
 		rc = callback(tpg, sess, private);
 		if (rc)
-			goto free_sess;
+			goto rm_sysfs;
 	}
 
 	transport_register_session(tpg, sess->se_node_acl, sess, private);
 	return sess;
 
+rm_sysfs:
+	target_sysfs_remove_session(sess);
 free_sess:
 	transport_free_session(sess);
 	return ERR_PTR(rc);
@@ -597,12 +617,17 @@  void transport_free_session(struct se_session *se_sess)
 		sbitmap_queue_free(&se_sess->sess_tag_pool);
 		kvfree(se_sess->sess_cmd_map);
 	}
-	target_free_transport_id(se_sess->tpt_id);
 	percpu_ref_exit(&se_sess->cmd_count);
-	kmem_cache_free(se_sess_cache, se_sess);
+	put_device(&se_sess->dev);
 }
 EXPORT_SYMBOL(transport_free_session);
 
+void __target_free_session(struct se_session *se_sess)
+{
+	target_free_transport_id(se_sess->tpt_id);
+	kmem_cache_free(se_sess_cache, se_sess);
+}
+
 static int target_release_res(struct se_device *dev, void *data)
 {
 	struct se_session *sess = data;
@@ -651,6 +676,7 @@  void transport_deregister_session(struct se_session *se_sess)
 
 void target_remove_session(struct se_session *se_sess)
 {
+	target_sysfs_remove_session(se_sess);
 	transport_deregister_session_configfs(se_sess);
 	transport_deregister_session(se_sess);
 }