1e48354ceSNicholas Bellinger /*******************************************************************************
2e48354ceSNicholas Bellinger  * Modern ConfigFS group context specific iSCSI statistics based on original
3e48354ceSNicholas Bellinger  * iscsi_target_mib.c code
4e48354ceSNicholas Bellinger  *
54c76251eSNicholas Bellinger  * Copyright (c) 2011-2013 Datera, Inc.
6e48354ceSNicholas Bellinger  *
7e48354ceSNicholas Bellinger  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8e48354ceSNicholas Bellinger  *
9e48354ceSNicholas Bellinger  * This program is free software; you can redistribute it and/or modify
10e48354ceSNicholas Bellinger  * it under the terms of the GNU General Public License as published by
11e48354ceSNicholas Bellinger  * the Free Software Foundation; either version 2 of the License, or
12e48354ceSNicholas Bellinger  * (at your option) any later version.
13e48354ceSNicholas Bellinger  *
14e48354ceSNicholas Bellinger  * This program is distributed in the hope that it will be useful,
15e48354ceSNicholas Bellinger  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16e48354ceSNicholas Bellinger  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17e48354ceSNicholas Bellinger  * GNU General Public License for more details.
18e48354ceSNicholas Bellinger  ******************************************************************************/
19e48354ceSNicholas Bellinger 
20e48354ceSNicholas Bellinger #include <linux/configfs.h>
21c53181afSPaul Gortmaker #include <linux/export.h>
22e48354ceSNicholas Bellinger #include <scsi/iscsi_proto.h>
23e48354ceSNicholas Bellinger #include <target/target_core_base.h>
24e48354ceSNicholas Bellinger 
2567f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_core.h>
26e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h"
27e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
28e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
29e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
3067f091f2SSagi Grimberg #include <target/iscsi/iscsi_target_stat.h>
31e48354ceSNicholas Bellinger 
32e48354ceSNicholas Bellinger #ifndef INITIAL_JIFFIES
33e48354ceSNicholas Bellinger #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
34e48354ceSNicholas Bellinger #endif
35e48354ceSNicholas Bellinger 
36e48354ceSNicholas Bellinger /* Instance Attributes Table */
37e48354ceSNicholas Bellinger #define ISCSI_INST_NUM_NODES		1
38e48354ceSNicholas Bellinger #define ISCSI_INST_DESCR		"Storage Engine Target"
39e48354ceSNicholas Bellinger #define ISCSI_INST_LAST_FAILURE_TYPE	0
40e48354ceSNicholas Bellinger #define ISCSI_DISCONTINUITY_TIME	0
41e48354ceSNicholas Bellinger 
42e48354ceSNicholas Bellinger #define ISCSI_NODE_INDEX		1
43e48354ceSNicholas Bellinger 
44e48354ceSNicholas Bellinger #define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
45e48354ceSNicholas Bellinger 
46e48354ceSNicholas Bellinger /****************************************************************************
47e48354ceSNicholas Bellinger  * iSCSI MIB Tables
48e48354ceSNicholas Bellinger  ****************************************************************************/
49e48354ceSNicholas Bellinger /*
50e48354ceSNicholas Bellinger  * Instance Attributes Table
51e48354ceSNicholas Bellinger  */
522eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item)
53e48354ceSNicholas Bellinger {
542eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
552eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_instance_group);
562eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
57e48354ceSNicholas Bellinger }
58e48354ceSNicholas Bellinger 
592eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_inst_show(struct config_item *item,
602eafd729SChristoph Hellwig 		char *page)
612eafd729SChristoph Hellwig {
622eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
632eafd729SChristoph Hellwig 			iscsi_instance_tiqn(item)->tiqn_index);
642eafd729SChristoph Hellwig }
652eafd729SChristoph Hellwig 
662eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item,
672eafd729SChristoph Hellwig 		char *page)
68e48354ceSNicholas Bellinger {
69e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
70e48354ceSNicholas Bellinger }
71e48354ceSNicholas Bellinger 
722eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item,
732eafd729SChristoph Hellwig 		char *page)
74e48354ceSNicholas Bellinger {
75e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
76e48354ceSNicholas Bellinger }
77e48354ceSNicholas Bellinger 
782eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_portals_show(struct config_item *item,
792eafd729SChristoph Hellwig 		char *page)
80e48354ceSNicholas Bellinger {
812eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
822eafd729SChristoph Hellwig 			iscsi_instance_tiqn(item)->tiqn_num_tpg_nps);
83e48354ceSNicholas Bellinger }
84e48354ceSNicholas Bellinger 
852eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_nodes_show(struct config_item *item,
862eafd729SChristoph Hellwig 		char *page)
87e48354ceSNicholas Bellinger {
88e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
89e48354ceSNicholas Bellinger }
90e48354ceSNicholas Bellinger 
912eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_sessions_show(struct config_item *item,
922eafd729SChristoph Hellwig 		char *page)
93e48354ceSNicholas Bellinger {
942eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
952eafd729SChristoph Hellwig 		iscsi_instance_tiqn(item)->tiqn_nsessions);
96e48354ceSNicholas Bellinger }
97e48354ceSNicholas Bellinger 
982eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item,
992eafd729SChristoph Hellwig 		char *page)
100e48354ceSNicholas Bellinger {
1012eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
102e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
103e48354ceSNicholas Bellinger 	u32 sess_err_count;
104e48354ceSNicholas Bellinger 
105e48354ceSNicholas Bellinger 	spin_lock_bh(&sess_err->lock);
106e48354ceSNicholas Bellinger 	sess_err_count = (sess_err->digest_errors +
107e48354ceSNicholas Bellinger 			  sess_err->cxn_timeout_errors +
108e48354ceSNicholas Bellinger 			  sess_err->pdu_format_errors);
109e48354ceSNicholas Bellinger 	spin_unlock_bh(&sess_err->lock);
110e48354ceSNicholas Bellinger 
111e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
112e48354ceSNicholas Bellinger }
113e48354ceSNicholas Bellinger 
1142eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
1152eafd729SChristoph Hellwig 		char *page)
116e48354ceSNicholas Bellinger {
1172eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
118e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
119e48354ceSNicholas Bellinger 
120e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n",
121e48354ceSNicholas Bellinger 			sess_err->last_sess_failure_type);
122e48354ceSNicholas Bellinger }
123e48354ceSNicholas Bellinger 
1242eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
1252eafd729SChristoph Hellwig 		char *page)
126e48354ceSNicholas Bellinger {
1272eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
128e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
129e48354ceSNicholas Bellinger 
130e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n",
131e48354ceSNicholas Bellinger 			sess_err->last_sess_fail_rem_name[0] ?
132e48354ceSNicholas Bellinger 			sess_err->last_sess_fail_rem_name : NONE);
133e48354ceSNicholas Bellinger }
134e48354ceSNicholas Bellinger 
1352eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item,
1362eafd729SChristoph Hellwig 		char *page)
137e48354ceSNicholas Bellinger {
138e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
139e48354ceSNicholas Bellinger }
140e48354ceSNicholas Bellinger 
1412eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_description_show(struct config_item *item,
1422eafd729SChristoph Hellwig 		char *page)
143e48354ceSNicholas Bellinger {
144e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
145e48354ceSNicholas Bellinger }
146e48354ceSNicholas Bellinger 
1472eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_vendor_show(struct config_item *item,
1482eafd729SChristoph Hellwig 		char *page)
149e48354ceSNicholas Bellinger {
1504c76251eSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
151e48354ceSNicholas Bellinger }
152e48354ceSNicholas Bellinger 
1532eafd729SChristoph Hellwig static ssize_t iscsi_stat_instance_version_show(struct config_item *item,
1542eafd729SChristoph Hellwig 		char *page)
155e48354ceSNicholas Bellinger {
156e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
157e48354ceSNicholas Bellinger }
158e48354ceSNicholas Bellinger 
1592eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, inst);
1602eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, min_ver);
1612eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, max_ver);
1622eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, portals);
1632eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, nodes);
1642eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, sessions);
1652eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_sess);
1662eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_type);
1672eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_rem_name);
1682eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, disc_time);
1692eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, description);
1702eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, vendor);
1712eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_instance_, version);
172e48354ceSNicholas Bellinger 
173e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
1742eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_inst,
1752eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_min_ver,
1762eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_max_ver,
1772eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_portals,
1782eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_nodes,
1792eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_sessions,
1802eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_fail_sess,
1812eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_fail_type,
1822eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_fail_rem_name,
1832eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_disc_time,
1842eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_description,
1852eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_vendor,
1862eafd729SChristoph Hellwig 	&iscsi_stat_instance_attr_version,
187e48354ceSNicholas Bellinger 	NULL,
188e48354ceSNicholas Bellinger };
189e48354ceSNicholas Bellinger 
190e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_instance_cit = {
191e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_instance_attrs,
192e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
193e48354ceSNicholas Bellinger };
194e48354ceSNicholas Bellinger 
195e48354ceSNicholas Bellinger /*
196e48354ceSNicholas Bellinger  * Instance Session Failure Stats Table
197e48354ceSNicholas Bellinger  */
1982eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item)
199e48354ceSNicholas Bellinger {
2002eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
2012eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_sess_err_group);
2022eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
203e48354ceSNicholas Bellinger }
204e48354ceSNicholas Bellinger 
2052eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item,
2062eafd729SChristoph Hellwig 		char *page)
207e48354ceSNicholas Bellinger {
2082eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
2092eafd729SChristoph Hellwig 		iscsi_sess_err_tiqn(item)->tiqn_index);
2102eafd729SChristoph Hellwig }
2112eafd729SChristoph Hellwig 
2122eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item,
2132eafd729SChristoph Hellwig 		char *page)
2142eafd729SChristoph Hellwig {
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->digest_errors);
219e48354ceSNicholas Bellinger }
220e48354ceSNicholas Bellinger 
2212eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_cxn_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->cxn_timeout_errors);
228e48354ceSNicholas Bellinger }
229e48354ceSNicholas Bellinger 
2302eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
2312eafd729SChristoph Hellwig 		char *page)
232e48354ceSNicholas Bellinger {
2332eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
234e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
235e48354ceSNicholas Bellinger 
236e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
237e48354ceSNicholas Bellinger }
238e48354ceSNicholas Bellinger 
2392eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst);
2402eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, digest_errors);
2412eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, cxn_errors);
2422eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, format_errors);
243e48354ceSNicholas Bellinger 
244e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
2452eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_inst,
2462eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_digest_errors,
2472eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_cxn_errors,
2482eafd729SChristoph Hellwig 	&iscsi_stat_sess_err_attr_format_errors,
249e48354ceSNicholas Bellinger 	NULL,
250e48354ceSNicholas Bellinger };
251e48354ceSNicholas Bellinger 
252e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_sess_err_cit = {
253e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_sess_err_attrs,
254e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
255e48354ceSNicholas Bellinger };
256e48354ceSNicholas Bellinger 
257e48354ceSNicholas Bellinger /*
258e48354ceSNicholas Bellinger  * Target Attributes Table
259e48354ceSNicholas Bellinger  */
2602eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item)
261e48354ceSNicholas Bellinger {
2622eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
2632eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_tgt_attr_group);
2642eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
265e48354ceSNicholas Bellinger }
266e48354ceSNicholas Bellinger 
2672eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item,
2682eafd729SChristoph Hellwig 		char *page)
2692eafd729SChristoph Hellwig {
2702eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
2712eafd729SChristoph Hellwig 			iscsi_tgt_attr_tiqn(item)->tiqn_index);
2722eafd729SChristoph Hellwig }
2732eafd729SChristoph Hellwig 
2742eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item,
2752eafd729SChristoph Hellwig 		char *page)
276e48354ceSNicholas Bellinger {
277e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
278e48354ceSNicholas Bellinger }
279e48354ceSNicholas Bellinger 
2802eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
2812eafd729SChristoph Hellwig 		char *page)
282e48354ceSNicholas Bellinger {
2832eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
284e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
285e48354ceSNicholas Bellinger 	u32 fail_count;
286e48354ceSNicholas Bellinger 
287e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
288e48354ceSNicholas Bellinger 	fail_count = (lstat->redirects + lstat->authorize_fails +
289e48354ceSNicholas Bellinger 			lstat->authenticate_fails + lstat->negotiate_fails +
290e48354ceSNicholas Bellinger 			lstat->other_fails);
291e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
292e48354ceSNicholas Bellinger 
293e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
294e48354ceSNicholas Bellinger }
295e48354ceSNicholas Bellinger 
2962eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
2972eafd729SChristoph Hellwig 		char *page)
298e48354ceSNicholas Bellinger {
2992eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
300e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
301e48354ceSNicholas Bellinger 	u32 last_fail_time;
302e48354ceSNicholas Bellinger 
303e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
304e48354ceSNicholas Bellinger 	last_fail_time = lstat->last_fail_time ?
305e48354ceSNicholas Bellinger 			(u32)(((u32)lstat->last_fail_time -
306e48354ceSNicholas Bellinger 				INITIAL_JIFFIES) * 100 / HZ) : 0;
307e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
308e48354ceSNicholas Bellinger 
309e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
310e48354ceSNicholas Bellinger }
311e48354ceSNicholas Bellinger 
3122eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
3132eafd729SChristoph Hellwig 		char *page)
314e48354ceSNicholas Bellinger {
3152eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
316e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
317e48354ceSNicholas Bellinger 	u32 last_fail_type;
318e48354ceSNicholas Bellinger 
319e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
320e48354ceSNicholas Bellinger 	last_fail_type = lstat->last_fail_type;
321e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
322e48354ceSNicholas Bellinger 
323e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
324e48354ceSNicholas Bellinger }
325e48354ceSNicholas Bellinger 
3262eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
3272eafd729SChristoph Hellwig 		char *page)
328e48354ceSNicholas Bellinger {
3292eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
330e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
331e48354ceSNicholas Bellinger 	unsigned char buf[224];
332e48354ceSNicholas Bellinger 
333e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
334e48354ceSNicholas Bellinger 	snprintf(buf, 224, "%s", lstat->last_intr_fail_name[0] ?
335e48354ceSNicholas Bellinger 				lstat->last_intr_fail_name : NONE);
336e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
337e48354ceSNicholas Bellinger 
338e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", buf);
339e48354ceSNicholas Bellinger }
340e48354ceSNicholas Bellinger 
3412eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item,
3422eafd729SChristoph Hellwig 		char *page)
343e48354ceSNicholas Bellinger {
3442eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
345e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
34607ea81b6SDan Carpenter 	int ret;
347e48354ceSNicholas Bellinger 
348e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
34907ea81b6SDan Carpenter 	if (lstat->last_intr_fail_ip_family == AF_INET6)
35007ea81b6SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "ipv6\n");
35107ea81b6SDan Carpenter 	else
35207ea81b6SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "ipv4\n");
353e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
354e48354ceSNicholas Bellinger 
35507ea81b6SDan Carpenter 	return ret;
356e48354ceSNicholas Bellinger }
357e48354ceSNicholas Bellinger 
3582eafd729SChristoph Hellwig static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item,
3592eafd729SChristoph Hellwig 		char *page)
360e48354ceSNicholas Bellinger {
3612eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
362e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
3630e48e7a5SDan Carpenter 	int ret;
364e48354ceSNicholas Bellinger 
365e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
366dc58f760SAndy Grover 	ret = snprintf(page, PAGE_SIZE, "%pISc\n", &lstat->last_intr_fail_sockaddr);
367e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
368e48354ceSNicholas Bellinger 
3690e48e7a5SDan Carpenter 	return ret;
370e48354ceSNicholas Bellinger }
371e48354ceSNicholas Bellinger 
3722eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, inst);
3732eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, indx);
3742eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, login_fails);
3752eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_time);
3762eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_type);
3772eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_name);
3782eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr_type);
3792eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr);
380e48354ceSNicholas Bellinger 
381e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
3822eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_inst,
3832eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_indx,
3842eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_login_fails,
3852eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_last_fail_time,
3862eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_last_fail_type,
3872eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_fail_intr_name,
3882eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_fail_intr_addr_type,
3892eafd729SChristoph Hellwig 	&iscsi_stat_tgt_attr_attr_fail_intr_addr,
390e48354ceSNicholas Bellinger 	NULL,
391e48354ceSNicholas Bellinger };
392e48354ceSNicholas Bellinger 
393e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_tgt_attr_cit = {
394e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_tgt_attr_attrs,
395e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
396e48354ceSNicholas Bellinger };
397e48354ceSNicholas Bellinger 
398e48354ceSNicholas Bellinger /*
399e48354ceSNicholas Bellinger  * Target Login Stats Table
400e48354ceSNicholas Bellinger  */
4012eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item)
402e48354ceSNicholas Bellinger {
4032eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
4042eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_login_stats_group);
4052eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
406e48354ceSNicholas Bellinger }
407e48354ceSNicholas Bellinger 
4082eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page)
4092eafd729SChristoph Hellwig {
4102eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
4112eafd729SChristoph Hellwig 		iscsi_login_stat_tiqn(item)->tiqn_index);
4122eafd729SChristoph Hellwig }
4132eafd729SChristoph Hellwig 
4142eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_indx_show(struct config_item *item,
4152eafd729SChristoph Hellwig 		char *page)
416e48354ceSNicholas Bellinger {
417e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
418e48354ceSNicholas Bellinger }
419e48354ceSNicholas Bellinger 
4202eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
4212eafd729SChristoph Hellwig 		char *page)
422e48354ceSNicholas Bellinger {
4232eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
424e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
425e48354ceSNicholas Bellinger 	ssize_t ret;
426e48354ceSNicholas Bellinger 
427e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
428e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
429e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
430e48354ceSNicholas Bellinger 
431e48354ceSNicholas Bellinger 	return ret;
432e48354ceSNicholas Bellinger }
433e48354ceSNicholas Bellinger 
4342eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_other_fails_show(struct config_item *item,
4352eafd729SChristoph Hellwig 		char *page)
436e48354ceSNicholas Bellinger {
4372eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
438e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
439e48354ceSNicholas Bellinger 	ssize_t ret;
440e48354ceSNicholas Bellinger 
441e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
442e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
443e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
444e48354ceSNicholas Bellinger 
445e48354ceSNicholas Bellinger 	return ret;
446e48354ceSNicholas Bellinger }
447e48354ceSNicholas Bellinger 
4482eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_redirects_show(struct config_item *item,
4492eafd729SChristoph Hellwig 		char *page)
450e48354ceSNicholas Bellinger {
4512eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
452e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
453e48354ceSNicholas Bellinger 	ssize_t ret;
454e48354ceSNicholas Bellinger 
455e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
456e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
457e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
458e48354ceSNicholas Bellinger 
459e48354ceSNicholas Bellinger 	return ret;
460e48354ceSNicholas Bellinger }
461e48354ceSNicholas Bellinger 
4622eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item,
4632eafd729SChristoph Hellwig 		char *page)
464e48354ceSNicholas Bellinger {
4652eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
466e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
467e48354ceSNicholas Bellinger 	ssize_t ret;
468e48354ceSNicholas Bellinger 
469e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
470e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
471e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
472e48354ceSNicholas Bellinger 
473e48354ceSNicholas Bellinger 	return ret;
474e48354ceSNicholas Bellinger }
475e48354ceSNicholas Bellinger 
4762eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_authenticate_fails_show(
4772eafd729SChristoph Hellwig 		struct config_item *item, char *page)
478e48354ceSNicholas Bellinger {
4792eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
480e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
481e48354ceSNicholas Bellinger 	ssize_t ret;
482e48354ceSNicholas Bellinger 
483e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
484e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
485e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
486e48354ceSNicholas Bellinger 
487e48354ceSNicholas Bellinger 	return ret;
488e48354ceSNicholas Bellinger }
489e48354ceSNicholas Bellinger 
4902eafd729SChristoph Hellwig static ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item,
4912eafd729SChristoph Hellwig 		char *page)
492e48354ceSNicholas Bellinger {
4932eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
494e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
495e48354ceSNicholas Bellinger 	ssize_t ret;
496e48354ceSNicholas Bellinger 
497e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
498e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
499e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
500e48354ceSNicholas Bellinger 
501e48354ceSNicholas Bellinger 	return ret;
502e48354ceSNicholas Bellinger }
503e48354ceSNicholas Bellinger 
5042eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, inst);
5052eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, indx);
5062eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, accepts);
5072eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, other_fails);
5082eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, redirects);
5092eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, authorize_fails);
5102eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, authenticate_fails);
5112eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_login_, negotiate_fails);
512e48354ceSNicholas Bellinger 
513e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
5142eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_inst,
5152eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_indx,
5162eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_accepts,
5172eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_other_fails,
5182eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_redirects,
5192eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_authorize_fails,
5202eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_authenticate_fails,
5212eafd729SChristoph Hellwig 	&iscsi_stat_login_attr_negotiate_fails,
522e48354ceSNicholas Bellinger 	NULL,
523e48354ceSNicholas Bellinger };
524e48354ceSNicholas Bellinger 
525e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_login_cit = {
526e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_login_stats_attrs,
527e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
528e48354ceSNicholas Bellinger };
529e48354ceSNicholas Bellinger 
530e48354ceSNicholas Bellinger /*
531e48354ceSNicholas Bellinger  * Target Logout Stats Table
532e48354ceSNicholas Bellinger  */
5332eafd729SChristoph Hellwig static struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item)
534e48354ceSNicholas Bellinger {
5352eafd729SChristoph Hellwig 	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
5362eafd729SChristoph Hellwig 			struct iscsi_wwn_stat_grps, iscsi_logout_stats_group);
5372eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
538e48354ceSNicholas Bellinger }
539e48354ceSNicholas Bellinger 
5402eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page)
5412eafd729SChristoph Hellwig {
5422eafd729SChristoph Hellwig 	return snprintf(page, PAGE_SIZE, "%u\n",
5432eafd729SChristoph Hellwig 		iscsi_logout_stat_tiqn(item)->tiqn_index);
5442eafd729SChristoph Hellwig }
5452eafd729SChristoph Hellwig 
5462eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page)
547e48354ceSNicholas Bellinger {
548e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
549e48354ceSNicholas Bellinger }
550e48354ceSNicholas Bellinger 
5512eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_normal_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->normal_logouts);
558e48354ceSNicholas Bellinger }
559e48354ceSNicholas Bellinger 
5602eafd729SChristoph Hellwig static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
5612eafd729SChristoph Hellwig 		char *page)
562e48354ceSNicholas Bellinger {
5632eafd729SChristoph Hellwig 	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
564e48354ceSNicholas Bellinger 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
565e48354ceSNicholas Bellinger 
566e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
567e48354ceSNicholas Bellinger }
568e48354ceSNicholas Bellinger 
5692eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, inst);
5702eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, indx);
5712eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, normal_logouts);
5722eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_logout_, abnormal_logouts);
573e48354ceSNicholas Bellinger 
574e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
5752eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_inst,
5762eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_indx,
5772eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_normal_logouts,
5782eafd729SChristoph Hellwig 	&iscsi_stat_logout_attr_abnormal_logouts,
579e48354ceSNicholas Bellinger 	NULL,
580e48354ceSNicholas Bellinger };
581e48354ceSNicholas Bellinger 
582e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_logout_cit = {
583e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_logout_stats_attrs,
584e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
585e48354ceSNicholas Bellinger };
586e48354ceSNicholas Bellinger 
587e48354ceSNicholas Bellinger /*
588e48354ceSNicholas Bellinger  * Session Stats Table
589e48354ceSNicholas Bellinger  */
5902eafd729SChristoph Hellwig static struct iscsi_node_acl *iscsi_stat_nacl(struct config_item *item)
591e48354ceSNicholas Bellinger {
5922eafd729SChristoph Hellwig 	struct iscsi_node_stat_grps *igrps = container_of(to_config_group(item),
5932eafd729SChristoph Hellwig 			struct iscsi_node_stat_grps, iscsi_sess_stats_group);
5942eafd729SChristoph Hellwig 	return container_of(igrps, struct iscsi_node_acl, node_stat_grps);
5952eafd729SChristoph Hellwig }
5962eafd729SChristoph Hellwig 
5972eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page)
5982eafd729SChristoph Hellwig {
5992eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
600e48354ceSNicholas Bellinger 	struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
601e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(wwn,
602e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_wwn);
603e48354ceSNicholas Bellinger 
604e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
605e48354ceSNicholas Bellinger }
606e48354ceSNicholas Bellinger 
6072eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
608e48354ceSNicholas Bellinger {
6092eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
610e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
611e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
612e48354ceSNicholas Bellinger 	struct se_session *se_sess;
613e48354ceSNicholas Bellinger 	ssize_t ret = 0;
614e48354ceSNicholas Bellinger 
615e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
616e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
617e48354ceSNicholas Bellinger 	if (se_sess) {
6188359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
619e48354ceSNicholas Bellinger 		if (sess)
620e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
621e48354ceSNicholas Bellinger 				sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
622e48354ceSNicholas Bellinger 	}
623e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
624e48354ceSNicholas Bellinger 
625e48354ceSNicholas Bellinger 	return ret;
626e48354ceSNicholas Bellinger }
627e48354ceSNicholas Bellinger 
6282eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
629e48354ceSNicholas Bellinger {
6302eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
631e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
632e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
633e48354ceSNicholas Bellinger 	struct se_session *se_sess;
634e48354ceSNicholas Bellinger 	ssize_t ret = 0;
635e48354ceSNicholas Bellinger 
636e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
637e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
638e48354ceSNicholas Bellinger 	if (se_sess) {
6398359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
640e48354ceSNicholas Bellinger 		if (sess)
641e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
642e48354ceSNicholas Bellinger 					sess->session_index);
643e48354ceSNicholas Bellinger 	}
644e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
645e48354ceSNicholas Bellinger 
646e48354ceSNicholas Bellinger 	return ret;
647e48354ceSNicholas Bellinger }
648e48354ceSNicholas Bellinger 
6492eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item,
6502eafd729SChristoph Hellwig 		char *page)
651e48354ceSNicholas Bellinger {
6522eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
653e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
654e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
655e48354ceSNicholas Bellinger 	struct se_session *se_sess;
656e48354ceSNicholas Bellinger 	ssize_t ret = 0;
657e48354ceSNicholas Bellinger 
658e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
659e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
660e48354ceSNicholas Bellinger 	if (se_sess) {
6618359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
662e48354ceSNicholas Bellinger 		if (sess)
66304f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
66404f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->cmd_pdus));
665e48354ceSNicholas Bellinger 	}
666e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
667e48354ceSNicholas Bellinger 
668e48354ceSNicholas Bellinger 	return ret;
669e48354ceSNicholas Bellinger }
670e48354ceSNicholas Bellinger 
6712eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item,
6722eafd729SChristoph Hellwig 		char *page)
673e48354ceSNicholas Bellinger {
6742eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
675e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
676e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
677e48354ceSNicholas Bellinger 	struct se_session *se_sess;
678e48354ceSNicholas Bellinger 	ssize_t ret = 0;
679e48354ceSNicholas Bellinger 
680e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
681e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
682e48354ceSNicholas Bellinger 	if (se_sess) {
6838359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
684e48354ceSNicholas Bellinger 		if (sess)
68504f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
68604f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->rsp_pdus));
687e48354ceSNicholas Bellinger 	}
688e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
689e48354ceSNicholas Bellinger 
690e48354ceSNicholas Bellinger 	return ret;
691e48354ceSNicholas Bellinger }
692e48354ceSNicholas Bellinger 
6932eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item,
6942eafd729SChristoph Hellwig 		char *page)
695e48354ceSNicholas Bellinger {
6962eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
697e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
698e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
699e48354ceSNicholas Bellinger 	struct se_session *se_sess;
700e48354ceSNicholas Bellinger 	ssize_t ret = 0;
701e48354ceSNicholas Bellinger 
702e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
703e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
704e48354ceSNicholas Bellinger 	if (se_sess) {
7058359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
706e48354ceSNicholas Bellinger 		if (sess)
70704f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
70804f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->tx_data_octets));
709e48354ceSNicholas Bellinger 	}
710e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
711e48354ceSNicholas Bellinger 
712e48354ceSNicholas Bellinger 	return ret;
713e48354ceSNicholas Bellinger }
714e48354ceSNicholas Bellinger 
7152eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item,
7162eafd729SChristoph Hellwig 		char *page)
717e48354ceSNicholas Bellinger {
7182eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
719e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
720e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
721e48354ceSNicholas Bellinger 	struct se_session *se_sess;
722e48354ceSNicholas Bellinger 	ssize_t ret = 0;
723e48354ceSNicholas Bellinger 
724e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
725e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
726e48354ceSNicholas Bellinger 	if (se_sess) {
7278359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
728e48354ceSNicholas Bellinger 		if (sess)
72904f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
73004f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->rx_data_octets));
731e48354ceSNicholas Bellinger 	}
732e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
733e48354ceSNicholas Bellinger 
734e48354ceSNicholas Bellinger 	return ret;
735e48354ceSNicholas Bellinger }
736e48354ceSNicholas Bellinger 
7372eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item,
7382eafd729SChristoph Hellwig 		char *page)
739e48354ceSNicholas Bellinger {
7402eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
741e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
742e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
743e48354ceSNicholas Bellinger 	struct se_session *se_sess;
744e48354ceSNicholas Bellinger 	ssize_t ret = 0;
745e48354ceSNicholas Bellinger 
746e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
747e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
748e48354ceSNicholas Bellinger 	if (se_sess) {
7498359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
750e48354ceSNicholas Bellinger 		if (sess)
75104f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
75204f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->conn_digest_errors));
753e48354ceSNicholas Bellinger 	}
754e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
755e48354ceSNicholas Bellinger 
756e48354ceSNicholas Bellinger 	return ret;
757e48354ceSNicholas Bellinger }
758e48354ceSNicholas Bellinger 
7592eafd729SChristoph Hellwig static ssize_t iscsi_stat_sess_conn_timeout_errors_show(
7602eafd729SChristoph Hellwig 		struct config_item *item, char *page)
761e48354ceSNicholas Bellinger {
7622eafd729SChristoph Hellwig 	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
763e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
764e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
765e48354ceSNicholas Bellinger 	struct se_session *se_sess;
766e48354ceSNicholas Bellinger 	ssize_t ret = 0;
767e48354ceSNicholas Bellinger 
768e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
769e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
770e48354ceSNicholas Bellinger 	if (se_sess) {
7718359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
772e48354ceSNicholas Bellinger 		if (sess)
77304f3b31bSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%lu\n",
77404f3b31bSNicholas Bellinger 				       atomic_long_read(&sess->conn_timeout_errors));
775e48354ceSNicholas Bellinger 	}
776e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
777e48354ceSNicholas Bellinger 
778e48354ceSNicholas Bellinger 	return ret;
779e48354ceSNicholas Bellinger }
780e48354ceSNicholas Bellinger 
7812eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, inst);
7822eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, node);
7832eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, indx);
7842eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, cmd_pdus);
7852eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, rsp_pdus);
7862eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, txdata_octs);
7872eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, rxdata_octs);
7882eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_digest_errors);
7892eafd729SChristoph Hellwig CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_timeout_errors);
790e48354ceSNicholas Bellinger 
791e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
7922eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_inst,
7932eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_node,
7942eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_indx,
7952eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_cmd_pdus,
7962eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_rsp_pdus,
7972eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_txdata_octs,
7982eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_rxdata_octs,
7992eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_conn_digest_errors,
8002eafd729SChristoph Hellwig 	&iscsi_stat_sess_attr_conn_timeout_errors,
801e48354ceSNicholas Bellinger 	NULL,
802e48354ceSNicholas Bellinger };
803e48354ceSNicholas Bellinger 
804e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_sess_cit = {
805e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_sess_stats_attrs,
806e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
807e48354ceSNicholas Bellinger };
808