1c942fddfSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
2e48354ceSNicholas Bellinger /*******************************************************************************
3e48354ceSNicholas Bellinger  * Modern ConfigFS group context specific iSCSI statistics based on original
4e48354ceSNicholas Bellinger  * iscsi_target_mib.c code
5e48354ceSNicholas Bellinger  *
64c76251eSNicholas Bellinger  * Copyright (c) 2011-2013 Datera, Inc.
7e48354ceSNicholas Bellinger  *
8e48354ceSNicholas Bellinger  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
9e48354ceSNicholas Bellinger  *
10e48354ceSNicholas Bellinger  ******************************************************************************/
11e48354ceSNicholas Bellinger 
12e48354ceSNicholas Bellinger #include <linux/configfs.h>
13c53181afSPaul Gortmaker #include <linux/export.h>
14e48354ceSNicholas Bellinger #include <scsi/iscsi_proto.h>
15e48354ceSNicholas Bellinger #include <target/target_core_base.h>
16e48354ceSNicholas Bellinger 
1767f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h>
18e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h"
19e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
20e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
21e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
2267f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h>
23e48354ceSNicholas Bellinger 
24e48354ceSNicholas Bellinger #ifndef INITIAL_JIFFIES
25e48354ceSNicholas Bellinger #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
26e48354ceSNicholas Bellinger #endif
27e48354ceSNicholas Bellinger 
28e48354ceSNicholas Bellinger /* Instance Attributes Table */
29e48354ceSNicholas Bellinger #define ISCSI_INST_NUM_NODES		1
30e48354ceSNicholas Bellinger #define ISCSI_INST_DESCR		"Storage Engine Target"
31e48354ceSNicholas Bellinger #define ISCSI_DISCONTINUITY_TIME	0
32e48354ceSNicholas Bellinger 
33e48354ceSNicholas Bellinger #define ISCSI_NODE_INDEX		1
34e48354ceSNicholas Bellinger 
35e48354ceSNicholas Bellinger #define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
36e48354ceSNicholas Bellinger 
37e48354ceSNicholas Bellinger /****************************************************************************
38e48354ceSNicholas Bellinger  * iSCSI MIB Tables
39e48354ceSNicholas Bellinger  ****************************************************************************/
40e48354ceSNicholas Bellinger /*
41e48354ceSNicholas Bellinger  * Instance Attributes Table
42e48354ceSNicholas Bellinger  */
iscsi_instance_tiqn(struct config_item * item)432eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item)
44e48354ceSNicholas Bellinger {
452eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
462eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_instance_group);
472eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
48e48354ceSNicholas Bellinger }
49e48354ceSNicholas Bellinger 
iscsi_stat_instance_inst_show(struct config_item * item,char * page)502eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_inst_show(struct config_item *item,
512eafd729SChristoph Hellwig 		char *page)
522eafd729SChristoph Hellwig {
532eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
542eafd729SChristoph Hellwig 			iscsi_instance_tiqn(item)->tiqn_index);
552eafd729SChristoph Hellwig }
562eafd729SChristoph Hellwig 
iscsi_stat_instance_min_ver_show(struct config_item * item,char * page)572eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item,
582eafd729SChristoph Hellwig 		char *page)
59e48354ceSNicholas Bellinger {
60e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
61e48354ceSNicholas Bellinger }
62e48354ceSNicholas Bellinger 
iscsi_stat_instance_max_ver_show(struct config_item * item,char * page)632eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item,
642eafd729SChristoph Hellwig 		char *page)
65e48354ceSNicholas Bellinger {
66e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
67e48354ceSNicholas Bellinger }
68e48354ceSNicholas Bellinger 
iscsi_stat_instance_portals_show(struct config_item * item,char * page)692eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_portals_show(struct config_item *item,
702eafd729SChristoph Hellwig 		char *page)
71e48354ceSNicholas Bellinger {
722eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
732eafd729SChristoph Hellwig 			iscsi_instance_tiqn(item)->tiqn_num_tpg_nps);
74e48354ceSNicholas Bellinger }
75e48354ceSNicholas Bellinger 
iscsi_stat_instance_nodes_show(struct config_item * item,char * page)762eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_nodes_show(struct config_item *item,
772eafd729SChristoph Hellwig 		char *page)
78e48354ceSNicholas Bellinger {
79e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
80e48354ceSNicholas Bellinger }
81e48354ceSNicholas Bellinger 
iscsi_stat_instance_sessions_show(struct config_item * item,char * page)822eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_sessions_show(struct config_item *item,
832eafd729SChristoph Hellwig 		char *page)
84e48354ceSNicholas Bellinger {
852eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
862eafd729SChristoph Hellwig 		iscsi_instance_tiqn(item)->tiqn_nsessions);
87e48354ceSNicholas Bellinger }
88e48354ceSNicholas Bellinger 
iscsi_stat_instance_fail_sess_show(struct config_item * item,char * page)892eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item,
902eafd729SChristoph Hellwig 		char *page)
91e48354ceSNicholas Bellinger {
922eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
93e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
94e48354ceSNicholas Bellinger 	u32 sess_err_count;
95e48354ceSNicholas Bellinger 
96e48354ceSNicholas Bellinger 	spin_lock_bh(&sess_err->lock);
97e48354ceSNicholas Bellinger 	sess_err_count = (sess_err->digest_errors +
98e48354ceSNicholas Bellinger 			  sess_err->cxn_timeout_errors +
99e48354ceSNicholas Bellinger 			  sess_err->pdu_format_errors);
100e48354ceSNicholas Bellinger 	spin_unlock_bh(&sess_err->lock);
101e48354ceSNicholas Bellinger 
102e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
103e48354ceSNicholas Bellinger }
104e48354ceSNicholas Bellinger 
iscsi_stat_instance_fail_type_show(struct config_item * item,char * page)1052eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
1062eafd729SChristoph Hellwig 		char *page)
107e48354ceSNicholas Bellinger {
1082eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
109e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
110e48354ceSNicholas Bellinger 
111e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n",
112e48354ceSNicholas Bellinger 			sess_err->last_sess_failure_type);
113e48354ceSNicholas Bellinger }
114e48354ceSNicholas Bellinger 
iscsi_stat_instance_fail_rem_name_show(struct config_item * item,char * page)1152eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
1162eafd729SChristoph Hellwig 		char *page)
117e48354ceSNicholas Bellinger {
1182eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
119e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
120e48354ceSNicholas Bellinger 
121e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n",
122e48354ceSNicholas Bellinger 			sess_err->last_sess_fail_rem_name[0] ?
123e48354ceSNicholas Bellinger 			sess_err->last_sess_fail_rem_name : NONE);
124e48354ceSNicholas Bellinger }
125e48354ceSNicholas Bellinger 
iscsi_stat_instance_disc_time_show(struct config_item * item,char * page)1262eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item,
1272eafd729SChristoph Hellwig 		char *page)
128e48354ceSNicholas Bellinger {
129e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
130e48354ceSNicholas Bellinger }
131e48354ceSNicholas Bellinger 
iscsi_stat_instance_description_show(struct config_item * item,char * page)1322eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_description_show(struct config_item *item,
1332eafd729SChristoph Hellwig 		char *page)
134e48354ceSNicholas Bellinger {
135e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
136e48354ceSNicholas Bellinger }
137e48354ceSNicholas Bellinger 
iscsi_stat_instance_vendor_show(struct config_item * item,char * page)1382eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_vendor_show(struct config_item *item,
1392eafd729SChristoph Hellwig 		char *page)
140e48354ceSNicholas Bellinger {
1414c76251eSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
142e48354ceSNicholas Bellinger }
143e48354ceSNicholas Bellinger 
iscsi_stat_instance_version_show(struct config_item * item,char * page)1442eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_version_show(struct config_item *item,
1452eafd729SChristoph Hellwig 		char *page)
146e48354ceSNicholas Bellinger {
147e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
148e48354ceSNicholas Bellinger }
149e48354ceSNicholas Bellinger 
1502eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, inst);
1512eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, min_ver);
1522eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, max_ver);
1532eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, portals);
1542eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, nodes);
1552eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, sessions);
1562eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_sess);
1572eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_type);
1582eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_rem_name);
1592eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, disc_time);
1602eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, description);
1612eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, vendor);
1622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, version);
163e48354ceSNicholas Bellinger 
164e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
1652eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_inst,
1662eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_min_ver,
1672eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_max_ver,
1682eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_portals,
1692eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_nodes,
1702eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_sessions,
1712eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_fail_sess,
1722eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_fail_type,
1732eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_fail_rem_name,
1742eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_disc_time,
1752eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_description,
1762eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_vendor,
1772eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_version,
178e48354ceSNicholas Bellinger 	NULL,
179e48354ceSNicholas Bellinger };
180e48354ceSNicholas Bellinger 
181ece550b5SBhumika Goyal const struct config_item_type iscsi_stat_instance_cit = {
182e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_instance_attrs,
183e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
184e48354ceSNicholas Bellinger };
185e48354ceSNicholas Bellinger 
186e48354ceSNicholas Bellinger /*
187e48354ceSNicholas Bellinger  * Instance Session Failure Stats Table
188e48354ceSNicholas Bellinger  */
iscsi_sess_err_tiqn(struct config_item * item)1892eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item)
190e48354ceSNicholas Bellinger {
1912eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
1922eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_sess_err_group);
1932eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
194e48354ceSNicholas Bellinger }
195e48354ceSNicholas Bellinger 
iscsi_stat_sess_err_inst_show(struct config_item * item,char * page)1962eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item,
1972eafd729SChristoph Hellwig 		char *page)
198e48354ceSNicholas Bellinger {
1992eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
2002eafd729SChristoph Hellwig 		iscsi_sess_err_tiqn(item)->tiqn_index);
2012eafd729SChristoph Hellwig }
2022eafd729SChristoph Hellwig 
iscsi_stat_sess_err_digest_errors_show(struct config_item * item,char * page)2032eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item,
2042eafd729SChristoph Hellwig 		char *page)
2052eafd729SChristoph Hellwig {
2062eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
207e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
208e48354ceSNicholas Bellinger 
209e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
210e48354ceSNicholas Bellinger }
211e48354ceSNicholas Bellinger 
iscsi_stat_sess_err_cxn_errors_show(struct config_item * item,char * page)2122eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item,
2132eafd729SChristoph Hellwig 		char *page)
214e48354ceSNicholas Bellinger {
2152eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
216e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
217e48354ceSNicholas Bellinger 
218e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
219e48354ceSNicholas Bellinger }
220e48354ceSNicholas Bellinger 
iscsi_stat_sess_err_format_errors_show(struct config_item * item,char * page)2212eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
2222eafd729SChristoph Hellwig 		char *page)
223e48354ceSNicholas Bellinger {
2242eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
225e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
226e48354ceSNicholas Bellinger 
227e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
228e48354ceSNicholas Bellinger }
229e48354ceSNicholas Bellinger 
2302eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst);
2312eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, digest_errors);
2322eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, cxn_errors);
2332eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, format_errors);
234e48354ceSNicholas Bellinger 
235e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
2362eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_inst,
2372eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_digest_errors,
2382eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_cxn_errors,
2392eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_format_errors,
240e48354ceSNicholas Bellinger 	NULL,
241e48354ceSNicholas Bellinger };
242e48354ceSNicholas Bellinger 
243ece550b5SBhumika Goyal const struct config_item_type iscsi_stat_sess_err_cit = {
244e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_sess_err_attrs,
245e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
246e48354ceSNicholas Bellinger };
247e48354ceSNicholas Bellinger 
248e48354ceSNicholas Bellinger /*
249e48354ceSNicholas Bellinger  * Target Attributes Table
250e48354ceSNicholas Bellinger  */
iscsi_tgt_attr_tiqn(struct config_item * item)2512eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item)
252e48354ceSNicholas Bellinger {
2532eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
2542eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_tgt_attr_group);
2552eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
256e48354ceSNicholas Bellinger }
257e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_inst_show(struct config_item * item,char * page)2582eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item,
2592eafd729SChristoph Hellwig 		char *page)
2602eafd729SChristoph Hellwig {
2612eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
2622eafd729SChristoph Hellwig 			iscsi_tgt_attr_tiqn(item)->tiqn_index);
2632eafd729SChristoph Hellwig }
2642eafd729SChristoph Hellwig 
iscsi_stat_tgt_attr_indx_show(struct config_item * item,char * page)2652eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item,
2662eafd729SChristoph Hellwig 		char *page)
267e48354ceSNicholas Bellinger {
268e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
269e48354ceSNicholas Bellinger }
270e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_login_fails_show(struct config_item * item,char * page)2712eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
2722eafd729SChristoph Hellwig 		char *page)
273e48354ceSNicholas Bellinger {
2742eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
275e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
276e48354ceSNicholas Bellinger 	u32 fail_count;
277e48354ceSNicholas Bellinger 
278e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
279e48354ceSNicholas Bellinger 	fail_count = (lstat->redirects + lstat->authorize_fails +
280e48354ceSNicholas Bellinger 			lstat->authenticate_fails + lstat->negotiate_fails +
281e48354ceSNicholas Bellinger 			lstat->other_fails);
282e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
283e48354ceSNicholas Bellinger 
284e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
285e48354ceSNicholas Bellinger }
286e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_last_fail_time_show(struct config_item * item,char * page)2872eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
2882eafd729SChristoph Hellwig 		char *page)
289e48354ceSNicholas Bellinger {
2902eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
291e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
292e48354ceSNicholas Bellinger 	u32 last_fail_time;
293e48354ceSNicholas Bellinger 
294e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
295e48354ceSNicholas Bellinger 	last_fail_time = lstat->last_fail_time ?
296e48354ceSNicholas Bellinger 			(u32)(((u32)lstat->last_fail_time -
297e48354ceSNicholas Bellinger 				INITIAL_JIFFIES) * 100 / HZ) : 0;
298e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
299e48354ceSNicholas Bellinger 
300e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
301e48354ceSNicholas Bellinger }
302e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_last_fail_type_show(struct config_item * item,char * page)3032eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
3042eafd729SChristoph Hellwig 		char *page)
305e48354ceSNicholas Bellinger {
3062eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
307e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
308e48354ceSNicholas Bellinger 	u32 last_fail_type;
309e48354ceSNicholas Bellinger 
310e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
311e48354ceSNicholas Bellinger 	last_fail_type = lstat->last_fail_type;
312e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
313e48354ceSNicholas Bellinger 
314e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
315e48354ceSNicholas Bellinger }
316e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item * item,char * page)3172eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
3182eafd729SChristoph Hellwig 		char *page)
319e48354ceSNicholas Bellinger {
3202eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
321e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
322df711553SDavid Disseldorp 	unsigned char buf[ISCSI_IQN_LEN];
323e48354ceSNicholas Bellinger 
324e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
325df711553SDavid Disseldorp 	snprintf(buf, ISCSI_IQN_LEN, "%s", lstat->last_intr_fail_name[0] ?
326e48354ceSNicholas Bellinger 				lstat->last_intr_fail_name : NONE);
327e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
328e48354ceSNicholas Bellinger 
329e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", buf);
330e48354ceSNicholas Bellinger }
331e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item * item,char * page)3322eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item,
3332eafd729SChristoph Hellwig 		char *page)
334e48354ceSNicholas Bellinger {
3352eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
336e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
33707ea81b6SDan Carpenter 	int ret;
338e48354ceSNicholas Bellinger 
339e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
34007ea81b6SDan Carpenter 	if (lstat->last_intr_fail_ip_family == AF_INET6)
34107ea81b6SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "ipv6\n");
34207ea81b6SDan Carpenter 	else
34307ea81b6SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "ipv4\n");
344e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
345e48354ceSNicholas Bellinger 
34607ea81b6SDan Carpenter 	return ret;
347e48354ceSNicholas Bellinger }
348e48354ceSNicholas Bellinger 
iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item * item,char * page)3492eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item,
3502eafd729SChristoph Hellwig 		char *page)
351e48354ceSNicholas Bellinger {
3522eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
353e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
3540e48e7a5SDan Carpenter 	int ret;
355e48354ceSNicholas Bellinger 
356e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
357dc58f760SAndy Grover 	ret = snprintf(page, PAGE_SIZE, "%pISc\n", &lstat->last_intr_fail_sockaddr);
358e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
359e48354ceSNicholas Bellinger 
3600e48e7a5SDan Carpenter 	return ret;
361e48354ceSNicholas Bellinger }
362e48354ceSNicholas Bellinger 
3632eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, inst);
3642eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, indx);
3652eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, login_fails);
3662eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_time);
3672eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_type);
3682eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_name);
3692eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr_type);
3702eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr);
371e48354ceSNicholas Bellinger 
372e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
3732eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_inst,
3742eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_indx,
3752eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_login_fails,
3762eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_last_fail_time,
3772eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_last_fail_type,
3782eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_fail_intr_name,
3792eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_fail_intr_addr_type,
3802eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_fail_intr_addr,
381e48354ceSNicholas Bellinger 	NULL,
382e48354ceSNicholas Bellinger };
383e48354ceSNicholas Bellinger 
384ece550b5SBhumika Goyal const struct config_item_type iscsi_stat_tgt_attr_cit = {
385e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_tgt_attr_attrs,
386e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
387e48354ceSNicholas Bellinger };
388e48354ceSNicholas Bellinger 
389e48354ceSNicholas Bellinger /*
390e48354ceSNicholas Bellinger  * Target Login Stats Table
391e48354ceSNicholas Bellinger  */
iscsi_login_stat_tiqn(struct config_item * item)3922eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item)
393e48354ceSNicholas Bellinger {
3942eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
3952eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_login_stats_group);
3962eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
397e48354ceSNicholas Bellinger }
398e48354ceSNicholas Bellinger 
iscsi_stat_login_inst_show(struct config_item * item,char * page)3992eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page)
4002eafd729SChristoph Hellwig {
4012eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
4022eafd729SChristoph Hellwig 		iscsi_login_stat_tiqn(item)->tiqn_index);
4032eafd729SChristoph Hellwig }
4042eafd729SChristoph Hellwig 
iscsi_stat_login_indx_show(struct config_item * item,char * page)4052eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_indx_show(struct config_item *item,
4062eafd729SChristoph Hellwig 		char *page)
407e48354ceSNicholas Bellinger {
408e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
409e48354ceSNicholas Bellinger }
410e48354ceSNicholas Bellinger 
iscsi_stat_login_accepts_show(struct config_item * item,char * page)4112eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
4122eafd729SChristoph Hellwig 		char *page)
413e48354ceSNicholas Bellinger {
4142eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
415e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
416e48354ceSNicholas Bellinger 	ssize_t ret;
417e48354ceSNicholas Bellinger 
418e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
419e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
420e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
421e48354ceSNicholas Bellinger 
422e48354ceSNicholas Bellinger 	return ret;
423e48354ceSNicholas Bellinger }
424e48354ceSNicholas Bellinger 
iscsi_stat_login_other_fails_show(struct config_item * item,char * page)4252eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_other_fails_show(struct config_item *item,
4262eafd729SChristoph Hellwig 		char *page)
427e48354ceSNicholas Bellinger {
4282eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
429e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
430e48354ceSNicholas Bellinger 	ssize_t ret;
431e48354ceSNicholas Bellinger 
432e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
433e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
434e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
435e48354ceSNicholas Bellinger 
436e48354ceSNicholas Bellinger 	return ret;
437e48354ceSNicholas Bellinger }
438e48354ceSNicholas Bellinger 
iscsi_stat_login_redirects_show(struct config_item * item,char * page)4392eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_redirects_show(struct config_item *item,
4402eafd729SChristoph Hellwig 		char *page)
441e48354ceSNicholas Bellinger {
4422eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
443e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
444e48354ceSNicholas Bellinger 	ssize_t ret;
445e48354ceSNicholas Bellinger 
446e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
447e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
448e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
449e48354ceSNicholas Bellinger 
450e48354ceSNicholas Bellinger 	return ret;
451e48354ceSNicholas Bellinger }
452e48354ceSNicholas Bellinger 
iscsi_stat_login_authorize_fails_show(struct config_item * item,char * page)4532eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item,
4542eafd729SChristoph Hellwig 		char *page)
455e48354ceSNicholas Bellinger {
4562eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
457e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
458e48354ceSNicholas Bellinger 	ssize_t ret;
459e48354ceSNicholas Bellinger 
460e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
461e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
462e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
463e48354ceSNicholas Bellinger 
464e48354ceSNicholas Bellinger 	return ret;
465e48354ceSNicholas Bellinger }
466e48354ceSNicholas Bellinger 
iscsi_stat_login_authenticate_fails_show(struct config_item * item,char * page)4672eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_authenticate_fails_show(
4682eafd729SChristoph Hellwig 		struct config_item *item, char *page)
469e48354ceSNicholas Bellinger {
4702eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
471e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
472e48354ceSNicholas Bellinger 	ssize_t ret;
473e48354ceSNicholas Bellinger 
474e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
475e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
476e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
477e48354ceSNicholas Bellinger 
478e48354ceSNicholas Bellinger 	return ret;
479e48354ceSNicholas Bellinger }
480e48354ceSNicholas Bellinger 
iscsi_stat_login_negotiate_fails_show(struct config_item * item,char * page)4812eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item,
4822eafd729SChristoph Hellwig 		char *page)
483e48354ceSNicholas Bellinger {
4842eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
485e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
486e48354ceSNicholas Bellinger 	ssize_t ret;
487e48354ceSNicholas Bellinger 
488e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
489e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
490e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
491e48354ceSNicholas Bellinger 
492e48354ceSNicholas Bellinger 	return ret;
493e48354ceSNicholas Bellinger }
494e48354ceSNicholas Bellinger 
4952eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, inst);
4962eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, indx);
4972eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, accepts);
4982eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, other_fails);
4992eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, redirects);
5002eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, authorize_fails);
5012eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, authenticate_fails);
5022eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, negotiate_fails);
503e48354ceSNicholas Bellinger 
504e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
5052eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_inst,
5062eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_indx,
5072eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_accepts,
5082eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_other_fails,
5092eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_redirects,
5102eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_authorize_fails,
5112eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_authenticate_fails,
5122eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_negotiate_fails,
513e48354ceSNicholas Bellinger 	NULL,
514e48354ceSNicholas Bellinger };
515e48354ceSNicholas Bellinger 
516ece550b5SBhumika Goyal const struct config_item_type iscsi_stat_login_cit = {
517e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_login_stats_attrs,
518e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
519e48354ceSNicholas Bellinger };
520e48354ceSNicholas Bellinger 
521e48354ceSNicholas Bellinger /*
522e48354ceSNicholas Bellinger  * Target Logout Stats Table
523e48354ceSNicholas Bellinger  */
iscsi_logout_stat_tiqn(struct config_item * item)5242eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item)
525e48354ceSNicholas Bellinger {
5262eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
5272eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_logout_stats_group);
5282eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
529e48354ceSNicholas Bellinger }
530e48354ceSNicholas Bellinger 
iscsi_stat_logout_inst_show(struct config_item * item,char * page)5312eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page)
5322eafd729SChristoph Hellwig {
5332eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
5342eafd729SChristoph Hellwig 		iscsi_logout_stat_tiqn(item)->tiqn_index);
5352eafd729SChristoph Hellwig }
5362eafd729SChristoph Hellwig 
iscsi_stat_logout_indx_show(struct config_item * item,char * page)5372eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page)
538e48354ceSNicholas Bellinger {
539e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
540e48354ceSNicholas Bellinger }
541e48354ceSNicholas Bellinger 
iscsi_stat_logout_normal_logouts_show(struct config_item * item,char * page)5422eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item,
5432eafd729SChristoph Hellwig 		char *page)
544e48354ceSNicholas Bellinger {
5452eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
546e48354ceSNicholas Bellinger 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
547e48354ceSNicholas Bellinger 
548e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
549e48354ceSNicholas Bellinger }
550e48354ceSNicholas Bellinger 
iscsi_stat_logout_abnormal_logouts_show(struct config_item * item,char * page)5512eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
5522eafd729SChristoph Hellwig 		char *page)
553e48354ceSNicholas Bellinger {
5542eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
555e48354ceSNicholas Bellinger 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
556e48354ceSNicholas Bellinger 
557e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
558e48354ceSNicholas Bellinger }
559e48354ceSNicholas Bellinger 
5602eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, inst);
5612eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, indx);
5622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, normal_logouts);
5632eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, abnormal_logouts);
564e48354ceSNicholas Bellinger 
565e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
5662eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_inst,
5672eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_indx,
5682eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_normal_logouts,
5692eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_abnormal_logouts,
570e48354ceSNicholas Bellinger 	NULL,
571e48354ceSNicholas Bellinger };
572e48354ceSNicholas Bellinger 
573ece550b5SBhumika Goyal const struct config_item_type iscsi_stat_logout_cit = {
574e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_logout_stats_attrs,
575e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
576e48354ceSNicholas Bellinger };
577e48354ceSNicholas Bellinger 
578e48354ceSNicholas Bellinger /*
579e48354ceSNicholas Bellinger  * Session Stats Table
580e48354ceSNicholas Bellinger  */
iscsi_stat_nacl(struct config_item * item)5812eafd729SChristoph Hellwig static struct iscsi_node_acl *iscsi_stat_nacl(struct config_item *item)
582e48354ceSNicholas Bellinger {
5832eafd729SChristoph Hellwig 	struct iscsi_node_stat_grps *igrps = container_of(to_config_group(item),
5842eafd729SChristoph Hellwig 			struct iscsi_node_stat_grps, iscsi_sess_stats_group);
5852eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_node_acl, node_stat_grps);
5862eafd729SChristoph Hellwig }
5872eafd729SChristoph Hellwig 
iscsi_stat_sess_inst_show(struct config_item * item,char * page)5882eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page)
5892eafd729SChristoph Hellwig {
5902eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
591e48354ceSNicholas Bellinger 	struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
592e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(wwn,
593e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_wwn);
594e48354ceSNicholas Bellinger 
595e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
596e48354ceSNicholas Bellinger }
597e48354ceSNicholas Bellinger 
iscsi_stat_sess_node_show(struct config_item * item,char * page)5982eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
599e48354ceSNicholas Bellinger {
6002eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
601e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
602*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
603e48354ceSNicholas Bellinger 	struct se_session *se_sess;
604e48354ceSNicholas Bellinger 	ssize_t ret = 0;
605e48354ceSNicholas Bellinger 
606e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
607e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
608e48354ceSNicholas Bellinger 	if (se_sess) {
6098359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
610e48354ceSNicholas Bellinger 		if (sess)
611e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
612e48354ceSNicholas Bellinger 				sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
613e48354ceSNicholas Bellinger 	}
614e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
615e48354ceSNicholas Bellinger 
616e48354ceSNicholas Bellinger 	return ret;
617e48354ceSNicholas Bellinger }
618e48354ceSNicholas Bellinger 
iscsi_stat_sess_indx_show(struct config_item * item,char * page)6192eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
620e48354ceSNicholas Bellinger {
6212eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
622e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
623*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
624e48354ceSNicholas Bellinger 	struct se_session *se_sess;
625e48354ceSNicholas Bellinger 	ssize_t ret = 0;
626e48354ceSNicholas Bellinger 
627e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
628e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
629e48354ceSNicholas Bellinger 	if (se_sess) {
6308359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
631e48354ceSNicholas Bellinger 		if (sess)
632e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
633e48354ceSNicholas Bellinger 					sess->session_index);
634e48354ceSNicholas Bellinger 	}
635e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
636e48354ceSNicholas Bellinger 
637e48354ceSNicholas Bellinger 	return ret;
638e48354ceSNicholas Bellinger }
639e48354ceSNicholas Bellinger 
iscsi_stat_sess_cmd_pdus_show(struct config_item * item,char * page)6402eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item,
6412eafd729SChristoph Hellwig 		char *page)
642e48354ceSNicholas Bellinger {
6432eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
644e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
645*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
646e48354ceSNicholas Bellinger 	struct se_session *se_sess;
647e48354ceSNicholas Bellinger 	ssize_t ret = 0;
648e48354ceSNicholas Bellinger 
649e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
650e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
651e48354ceSNicholas Bellinger 	if (se_sess) {
6528359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
653e48354ceSNicholas Bellinger 		if (sess)
65404f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
65504f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->cmd_pdus));
656e48354ceSNicholas Bellinger 	}
657e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
658e48354ceSNicholas Bellinger 
659e48354ceSNicholas Bellinger 	return ret;
660e48354ceSNicholas Bellinger }
661e48354ceSNicholas Bellinger 
iscsi_stat_sess_rsp_pdus_show(struct config_item * item,char * page)6622eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item,
6632eafd729SChristoph Hellwig 		char *page)
664e48354ceSNicholas Bellinger {
6652eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
666e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
667*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
668e48354ceSNicholas Bellinger 	struct se_session *se_sess;
669e48354ceSNicholas Bellinger 	ssize_t ret = 0;
670e48354ceSNicholas Bellinger 
671e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
672e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
673e48354ceSNicholas Bellinger 	if (se_sess) {
6748359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
675e48354ceSNicholas Bellinger 		if (sess)
67604f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
67704f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->rsp_pdus));
678e48354ceSNicholas Bellinger 	}
679e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
680e48354ceSNicholas Bellinger 
681e48354ceSNicholas Bellinger 	return ret;
682e48354ceSNicholas Bellinger }
683e48354ceSNicholas Bellinger 
iscsi_stat_sess_txdata_octs_show(struct config_item * item,char * page)6842eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item,
6852eafd729SChristoph Hellwig 		char *page)
686e48354ceSNicholas Bellinger {
6872eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
688e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
689*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
690e48354ceSNicholas Bellinger 	struct se_session *se_sess;
691e48354ceSNicholas Bellinger 	ssize_t ret = 0;
692e48354ceSNicholas Bellinger 
693e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
694e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
695e48354ceSNicholas Bellinger 	if (se_sess) {
6968359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
697e48354ceSNicholas Bellinger 		if (sess)
69804f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
69904f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->tx_data_octets));
700e48354ceSNicholas Bellinger 	}
701e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
702e48354ceSNicholas Bellinger 
703e48354ceSNicholas Bellinger 	return ret;
704e48354ceSNicholas Bellinger }
705e48354ceSNicholas Bellinger 
iscsi_stat_sess_rxdata_octs_show(struct config_item * item,char * page)7062eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item,
7072eafd729SChristoph Hellwig 		char *page)
708e48354ceSNicholas Bellinger {
7092eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
710e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
711*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
712e48354ceSNicholas Bellinger 	struct se_session *se_sess;
713e48354ceSNicholas Bellinger 	ssize_t ret = 0;
714e48354ceSNicholas Bellinger 
715e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
716e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
717e48354ceSNicholas Bellinger 	if (se_sess) {
7188359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
719e48354ceSNicholas Bellinger 		if (sess)
72004f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
72104f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->rx_data_octets));
722e48354ceSNicholas Bellinger 	}
723e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
724e48354ceSNicholas Bellinger 
725e48354ceSNicholas Bellinger 	return ret;
726e48354ceSNicholas Bellinger }
727e48354ceSNicholas Bellinger 
iscsi_stat_sess_conn_digest_errors_show(struct config_item * item,char * page)7282eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item,
7292eafd729SChristoph Hellwig 		char *page)
730e48354ceSNicholas Bellinger {
7312eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
732e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
733*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
734e48354ceSNicholas Bellinger 	struct se_session *se_sess;
735e48354ceSNicholas Bellinger 	ssize_t ret = 0;
736e48354ceSNicholas Bellinger 
737e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
738e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
739e48354ceSNicholas Bellinger 	if (se_sess) {
7408359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
741e48354ceSNicholas Bellinger 		if (sess)
74204f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
74304f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->conn_digest_errors));
744e48354ceSNicholas Bellinger 	}
745e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
746e48354ceSNicholas Bellinger 
747e48354ceSNicholas Bellinger 	return ret;
748e48354ceSNicholas Bellinger }
749e48354ceSNicholas Bellinger 
iscsi_stat_sess_conn_timeout_errors_show(struct config_item * item,char * page)7502eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_conn_timeout_errors_show(
7512eafd729SChristoph Hellwig 		struct config_item *item, char *page)
752e48354ceSNicholas Bellinger {
7532eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
754e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
755*0873fe44SMax Gurtovoy 	struct iscsit_session *sess;
756e48354ceSNicholas Bellinger 	struct se_session *se_sess;
757e48354ceSNicholas Bellinger 	ssize_t ret = 0;
758e48354ceSNicholas Bellinger 
759e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
760e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
761e48354ceSNicholas Bellinger 	if (se_sess) {
7628359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
763e48354ceSNicholas Bellinger 		if (sess)
76404f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
76504f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->conn_timeout_errors));
766e48354ceSNicholas Bellinger 	}
767e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
768e48354ceSNicholas Bellinger 
769e48354ceSNicholas Bellinger 	return ret;
770e48354ceSNicholas Bellinger }
771e48354ceSNicholas Bellinger 
7722eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, inst);
7732eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, node);
7742eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, indx);
7752eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, cmd_pdus);
7762eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, rsp_pdus);
7772eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, txdata_octs);
7782eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, rxdata_octs);
7792eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_digest_errors);
7802eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_timeout_errors);
781e48354ceSNicholas Bellinger 
782e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
7832eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_inst,
7842eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_node,
7852eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_indx,
7862eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_cmd_pdus,
7872eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_rsp_pdus,
7882eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_txdata_octs,
7892eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_rxdata_octs,
7902eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_conn_digest_errors,
7912eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_conn_timeout_errors,
792e48354ceSNicholas Bellinger 	NULL,
793e48354ceSNicholas Bellinger };
794e48354ceSNicholas Bellinger 
795ece550b5SBhumika Goyal const struct config_item_type iscsi_stat_sess_cit = {
796e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_sess_stats_attrs,
797e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
798e48354ceSNicholas Bellinger };
799