1e48354ceSNicholas Bellinger /*******************************************************************************
2e48354ceSNicholas Bellinger  * Modern ConfigFS group context specific iSCSI statistics based on original
3e48354ceSNicholas Bellinger  * iscsi_target_mib.c code
4e48354ceSNicholas Bellinger  *
5e48354ceSNicholas Bellinger  * Copyright (c) 2011 Rising Tide Systems
6e48354ceSNicholas Bellinger  *
7e48354ceSNicholas Bellinger  * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
8e48354ceSNicholas Bellinger  *
9e48354ceSNicholas Bellinger  * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
10e48354ceSNicholas Bellinger  *
11e48354ceSNicholas Bellinger  * This program is free software; you can redistribute it and/or modify
12e48354ceSNicholas Bellinger  * it under the terms of the GNU General Public License as published by
13e48354ceSNicholas Bellinger  * the Free Software Foundation; either version 2 of the License, or
14e48354ceSNicholas Bellinger  * (at your option) any later version.
15e48354ceSNicholas Bellinger  *
16e48354ceSNicholas Bellinger  * This program is distributed in the hope that it will be useful,
17e48354ceSNicholas Bellinger  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18e48354ceSNicholas Bellinger  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19e48354ceSNicholas Bellinger  * GNU General Public License for more details.
20e48354ceSNicholas Bellinger  ******************************************************************************/
21e48354ceSNicholas Bellinger 
22e48354ceSNicholas Bellinger #include <linux/configfs.h>
23c53181afSPaul Gortmaker #include <linux/export.h>
24e48354ceSNicholas Bellinger #include <scsi/iscsi_proto.h>
25e48354ceSNicholas Bellinger #include <target/target_core_base.h>
26e48354ceSNicholas Bellinger #include <target/configfs_macros.h>
27e48354ceSNicholas Bellinger 
28e48354ceSNicholas Bellinger #include "iscsi_target_core.h"
29e48354ceSNicholas Bellinger #include "iscsi_target_parameters.h"
30e48354ceSNicholas Bellinger #include "iscsi_target_device.h"
31e48354ceSNicholas Bellinger #include "iscsi_target_tpg.h"
32e48354ceSNicholas Bellinger #include "iscsi_target_util.h"
33e48354ceSNicholas Bellinger #include "iscsi_target_stat.h"
34e48354ceSNicholas Bellinger 
35e48354ceSNicholas Bellinger #ifndef INITIAL_JIFFIES
36e48354ceSNicholas Bellinger #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
37e48354ceSNicholas Bellinger #endif
38e48354ceSNicholas Bellinger 
39e48354ceSNicholas Bellinger /* Instance Attributes Table */
40e48354ceSNicholas Bellinger #define ISCSI_INST_NUM_NODES		1
41e48354ceSNicholas Bellinger #define ISCSI_INST_DESCR		"Storage Engine Target"
42e48354ceSNicholas Bellinger #define ISCSI_INST_LAST_FAILURE_TYPE	0
43e48354ceSNicholas Bellinger #define ISCSI_DISCONTINUITY_TIME	0
44e48354ceSNicholas Bellinger 
45e48354ceSNicholas Bellinger #define ISCSI_NODE_INDEX		1
46e48354ceSNicholas Bellinger 
47e48354ceSNicholas Bellinger #define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
48e48354ceSNicholas Bellinger 
49e48354ceSNicholas Bellinger /****************************************************************************
50e48354ceSNicholas Bellinger  * iSCSI MIB Tables
51e48354ceSNicholas Bellinger  ****************************************************************************/
52e48354ceSNicholas Bellinger /*
53e48354ceSNicholas Bellinger  * Instance Attributes Table
54e48354ceSNicholas Bellinger  */
55e48354ceSNicholas Bellinger CONFIGFS_EATTR_STRUCT(iscsi_stat_instance, iscsi_wwn_stat_grps);
56e48354ceSNicholas Bellinger #define ISCSI_STAT_INSTANCE_ATTR(_name, _mode)			\
57e48354ceSNicholas Bellinger static struct iscsi_stat_instance_attribute			\
58e48354ceSNicholas Bellinger 			iscsi_stat_instance_##_name =		\
59e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR(_name, _mode,				\
60e48354ceSNicholas Bellinger 	iscsi_stat_instance_show_attr_##_name,			\
61e48354ceSNicholas Bellinger 	iscsi_stat_instance_store_attr_##_name);
62e48354ceSNicholas Bellinger 
63e48354ceSNicholas Bellinger #define ISCSI_STAT_INSTANCE_ATTR_RO(_name)			\
64e48354ceSNicholas Bellinger static struct iscsi_stat_instance_attribute			\
65e48354ceSNicholas Bellinger 			iscsi_stat_instance_##_name =		\
66e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR_RO(_name,				\
67e48354ceSNicholas Bellinger 	iscsi_stat_instance_show_attr_##_name);
68e48354ceSNicholas Bellinger 
69e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_inst(
70e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
71e48354ceSNicholas Bellinger {
72e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
73e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
74e48354ceSNicholas Bellinger 
75e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
76e48354ceSNicholas Bellinger }
77e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(inst);
78e48354ceSNicholas Bellinger 
79e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_min_ver(
80e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
81e48354ceSNicholas Bellinger {
82e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
83e48354ceSNicholas Bellinger }
84e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(min_ver);
85e48354ceSNicholas Bellinger 
86e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_max_ver(
87e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
88e48354ceSNicholas Bellinger {
89e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
90e48354ceSNicholas Bellinger }
91e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(max_ver);
92e48354ceSNicholas Bellinger 
93e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_portals(
94e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
95e48354ceSNicholas Bellinger {
96e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
97e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
98e48354ceSNicholas Bellinger 
99e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_num_tpg_nps);
100e48354ceSNicholas Bellinger }
101e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(portals);
102e48354ceSNicholas Bellinger 
103e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_nodes(
104e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
105e48354ceSNicholas Bellinger {
106e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
107e48354ceSNicholas Bellinger }
108e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(nodes);
109e48354ceSNicholas Bellinger 
110e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_sessions(
111e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
112e48354ceSNicholas Bellinger {
113e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
114e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
115e48354ceSNicholas Bellinger 
116e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_nsessions);
117e48354ceSNicholas Bellinger }
118e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(sessions);
119e48354ceSNicholas Bellinger 
120e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_fail_sess(
121e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
122e48354ceSNicholas Bellinger {
123e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
124e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
125e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
126e48354ceSNicholas Bellinger 	u32 sess_err_count;
127e48354ceSNicholas Bellinger 
128e48354ceSNicholas Bellinger 	spin_lock_bh(&sess_err->lock);
129e48354ceSNicholas Bellinger 	sess_err_count = (sess_err->digest_errors +
130e48354ceSNicholas Bellinger 			  sess_err->cxn_timeout_errors +
131e48354ceSNicholas Bellinger 			  sess_err->pdu_format_errors);
132e48354ceSNicholas Bellinger 	spin_unlock_bh(&sess_err->lock);
133e48354ceSNicholas Bellinger 
134e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
135e48354ceSNicholas Bellinger }
136e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(fail_sess);
137e48354ceSNicholas Bellinger 
138e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_fail_type(
139e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
140e48354ceSNicholas Bellinger {
141e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
142e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
143e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
144e48354ceSNicholas Bellinger 
145e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n",
146e48354ceSNicholas Bellinger 			sess_err->last_sess_failure_type);
147e48354ceSNicholas Bellinger }
148e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(fail_type);
149e48354ceSNicholas Bellinger 
150e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_fail_rem_name(
151e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
152e48354ceSNicholas Bellinger {
153e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
154e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
155e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
156e48354ceSNicholas Bellinger 
157e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n",
158e48354ceSNicholas Bellinger 			sess_err->last_sess_fail_rem_name[0] ?
159e48354ceSNicholas Bellinger 			sess_err->last_sess_fail_rem_name : NONE);
160e48354ceSNicholas Bellinger }
161e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(fail_rem_name);
162e48354ceSNicholas Bellinger 
163e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_disc_time(
164e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
165e48354ceSNicholas Bellinger {
166e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
167e48354ceSNicholas Bellinger }
168e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(disc_time);
169e48354ceSNicholas Bellinger 
170e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_description(
171e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
172e48354ceSNicholas Bellinger {
173e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
174e48354ceSNicholas Bellinger }
175e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(description);
176e48354ceSNicholas Bellinger 
177e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_vendor(
178e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
179e48354ceSNicholas Bellinger {
180e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "RisingTide Systems iSCSI-Target\n");
181e48354ceSNicholas Bellinger }
182e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(vendor);
183e48354ceSNicholas Bellinger 
184e48354ceSNicholas Bellinger static ssize_t iscsi_stat_instance_show_attr_version(
185e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
186e48354ceSNicholas Bellinger {
187e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
188e48354ceSNicholas Bellinger }
189e48354ceSNicholas Bellinger ISCSI_STAT_INSTANCE_ATTR_RO(version);
190e48354ceSNicholas Bellinger 
191e48354ceSNicholas Bellinger CONFIGFS_EATTR_OPS(iscsi_stat_instance, iscsi_wwn_stat_grps,
192e48354ceSNicholas Bellinger 		iscsi_instance_group);
193e48354ceSNicholas Bellinger 
194e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
195e48354ceSNicholas Bellinger 	&iscsi_stat_instance_inst.attr,
196e48354ceSNicholas Bellinger 	&iscsi_stat_instance_min_ver.attr,
197e48354ceSNicholas Bellinger 	&iscsi_stat_instance_max_ver.attr,
198e48354ceSNicholas Bellinger 	&iscsi_stat_instance_portals.attr,
199e48354ceSNicholas Bellinger 	&iscsi_stat_instance_nodes.attr,
200e48354ceSNicholas Bellinger 	&iscsi_stat_instance_sessions.attr,
201e48354ceSNicholas Bellinger 	&iscsi_stat_instance_fail_sess.attr,
202e48354ceSNicholas Bellinger 	&iscsi_stat_instance_fail_type.attr,
203e48354ceSNicholas Bellinger 	&iscsi_stat_instance_fail_rem_name.attr,
204e48354ceSNicholas Bellinger 	&iscsi_stat_instance_disc_time.attr,
205e48354ceSNicholas Bellinger 	&iscsi_stat_instance_description.attr,
206e48354ceSNicholas Bellinger 	&iscsi_stat_instance_vendor.attr,
207e48354ceSNicholas Bellinger 	&iscsi_stat_instance_version.attr,
208e48354ceSNicholas Bellinger 	NULL,
209e48354ceSNicholas Bellinger };
210e48354ceSNicholas Bellinger 
211e48354ceSNicholas Bellinger static struct configfs_item_operations iscsi_stat_instance_item_ops = {
212e48354ceSNicholas Bellinger 	.show_attribute		= iscsi_stat_instance_attr_show,
213e48354ceSNicholas Bellinger 	.store_attribute	= iscsi_stat_instance_attr_store,
214e48354ceSNicholas Bellinger };
215e48354ceSNicholas Bellinger 
216e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_instance_cit = {
217e48354ceSNicholas Bellinger 	.ct_item_ops		= &iscsi_stat_instance_item_ops,
218e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_instance_attrs,
219e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
220e48354ceSNicholas Bellinger };
221e48354ceSNicholas Bellinger 
222e48354ceSNicholas Bellinger /*
223e48354ceSNicholas Bellinger  * Instance Session Failure Stats Table
224e48354ceSNicholas Bellinger  */
225e48354ceSNicholas Bellinger CONFIGFS_EATTR_STRUCT(iscsi_stat_sess_err, iscsi_wwn_stat_grps);
226e48354ceSNicholas Bellinger #define ISCSI_STAT_SESS_ERR_ATTR(_name, _mode)			\
227e48354ceSNicholas Bellinger static struct iscsi_stat_sess_err_attribute			\
228e48354ceSNicholas Bellinger 			iscsi_stat_sess_err_##_name =		\
229e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR(_name, _mode,				\
230e48354ceSNicholas Bellinger 	iscsi_stat_sess_err_show_attr_##_name,			\
231e48354ceSNicholas Bellinger 	iscsi_stat_sess_err_store_attr_##_name);
232e48354ceSNicholas Bellinger 
233e48354ceSNicholas Bellinger #define ISCSI_STAT_SESS_ERR_ATTR_RO(_name)			\
234e48354ceSNicholas Bellinger static struct iscsi_stat_sess_err_attribute			\
235e48354ceSNicholas Bellinger 			iscsi_stat_sess_err_##_name =		\
236e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR_RO(_name,				\
237e48354ceSNicholas Bellinger 	iscsi_stat_sess_err_show_attr_##_name);
238e48354ceSNicholas Bellinger 
239e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_err_show_attr_inst(
240e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
241e48354ceSNicholas Bellinger {
242e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
243e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
244e48354ceSNicholas Bellinger 
245e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
246e48354ceSNicholas Bellinger }
247e48354ceSNicholas Bellinger ISCSI_STAT_SESS_ERR_ATTR_RO(inst);
248e48354ceSNicholas Bellinger 
249e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_err_show_attr_digest_errors(
250e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
251e48354ceSNicholas Bellinger {
252e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
253e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
254e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
255e48354ceSNicholas Bellinger 
256e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
257e48354ceSNicholas Bellinger }
258e48354ceSNicholas Bellinger ISCSI_STAT_SESS_ERR_ATTR_RO(digest_errors);
259e48354ceSNicholas Bellinger 
260e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_err_show_attr_cxn_errors(
261e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
262e48354ceSNicholas Bellinger {
263e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
264e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
265e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
266e48354ceSNicholas Bellinger 
267e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
268e48354ceSNicholas Bellinger }
269e48354ceSNicholas Bellinger ISCSI_STAT_SESS_ERR_ATTR_RO(cxn_errors);
270e48354ceSNicholas Bellinger 
271e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_err_show_attr_format_errors(
272e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
273e48354ceSNicholas Bellinger {
274e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
275e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
276e48354ceSNicholas Bellinger 	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
277e48354ceSNicholas Bellinger 
278e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
279e48354ceSNicholas Bellinger }
280e48354ceSNicholas Bellinger ISCSI_STAT_SESS_ERR_ATTR_RO(format_errors);
281e48354ceSNicholas Bellinger 
282e48354ceSNicholas Bellinger CONFIGFS_EATTR_OPS(iscsi_stat_sess_err, iscsi_wwn_stat_grps,
283e48354ceSNicholas Bellinger 		iscsi_sess_err_group);
284e48354ceSNicholas Bellinger 
285e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
286e48354ceSNicholas Bellinger 	&iscsi_stat_sess_err_inst.attr,
287e48354ceSNicholas Bellinger 	&iscsi_stat_sess_err_digest_errors.attr,
288e48354ceSNicholas Bellinger 	&iscsi_stat_sess_err_cxn_errors.attr,
289e48354ceSNicholas Bellinger 	&iscsi_stat_sess_err_format_errors.attr,
290e48354ceSNicholas Bellinger 	NULL,
291e48354ceSNicholas Bellinger };
292e48354ceSNicholas Bellinger 
293e48354ceSNicholas Bellinger static struct configfs_item_operations iscsi_stat_sess_err_item_ops = {
294e48354ceSNicholas Bellinger 	.show_attribute		= iscsi_stat_sess_err_attr_show,
295e48354ceSNicholas Bellinger 	.store_attribute	= iscsi_stat_sess_err_attr_store,
296e48354ceSNicholas Bellinger };
297e48354ceSNicholas Bellinger 
298e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_sess_err_cit = {
299e48354ceSNicholas Bellinger 	.ct_item_ops		= &iscsi_stat_sess_err_item_ops,
300e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_sess_err_attrs,
301e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
302e48354ceSNicholas Bellinger };
303e48354ceSNicholas Bellinger 
304e48354ceSNicholas Bellinger /*
305e48354ceSNicholas Bellinger  * Target Attributes Table
306e48354ceSNicholas Bellinger  */
307e48354ceSNicholas Bellinger CONFIGFS_EATTR_STRUCT(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps);
308e48354ceSNicholas Bellinger #define ISCSI_STAT_TGT_ATTR(_name, _mode)			\
309e48354ceSNicholas Bellinger static struct iscsi_stat_tgt_attr_attribute			\
310e48354ceSNicholas Bellinger 			iscsi_stat_tgt_attr_##_name =		\
311e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR(_name, _mode,				\
312e48354ceSNicholas Bellinger 	iscsi_stat_tgt-attr_show_attr_##_name,			\
313e48354ceSNicholas Bellinger 	iscsi_stat_tgt_attr_store_attr_##_name);
314e48354ceSNicholas Bellinger 
315e48354ceSNicholas Bellinger #define ISCSI_STAT_TGT_ATTR_RO(_name)				\
316e48354ceSNicholas Bellinger static struct iscsi_stat_tgt_attr_attribute			\
317e48354ceSNicholas Bellinger 			iscsi_stat_tgt_attr_##_name =		\
318e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR_RO(_name,				\
319e48354ceSNicholas Bellinger 	iscsi_stat_tgt_attr_show_attr_##_name);
320e48354ceSNicholas Bellinger 
321e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_inst(
322e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
323e48354ceSNicholas Bellinger {
324e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
325e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
326e48354ceSNicholas Bellinger 
327e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
328e48354ceSNicholas Bellinger }
329e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(inst);
330e48354ceSNicholas Bellinger 
331e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_indx(
332e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
333e48354ceSNicholas Bellinger {
334e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
335e48354ceSNicholas Bellinger }
336e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(indx);
337e48354ceSNicholas Bellinger 
338e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails(
339e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
340e48354ceSNicholas Bellinger {
341e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
342e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
343e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
344e48354ceSNicholas Bellinger 	u32 fail_count;
345e48354ceSNicholas Bellinger 
346e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
347e48354ceSNicholas Bellinger 	fail_count = (lstat->redirects + lstat->authorize_fails +
348e48354ceSNicholas Bellinger 			lstat->authenticate_fails + lstat->negotiate_fails +
349e48354ceSNicholas Bellinger 			lstat->other_fails);
350e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
351e48354ceSNicholas Bellinger 
352e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
353e48354ceSNicholas Bellinger }
354e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(login_fails);
355e48354ceSNicholas Bellinger 
356e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time(
357e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
358e48354ceSNicholas Bellinger {
359e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
360e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
361e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
362e48354ceSNicholas Bellinger 	u32 last_fail_time;
363e48354ceSNicholas Bellinger 
364e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
365e48354ceSNicholas Bellinger 	last_fail_time = lstat->last_fail_time ?
366e48354ceSNicholas Bellinger 			(u32)(((u32)lstat->last_fail_time -
367e48354ceSNicholas Bellinger 				INITIAL_JIFFIES) * 100 / HZ) : 0;
368e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
369e48354ceSNicholas Bellinger 
370e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
371e48354ceSNicholas Bellinger }
372e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(last_fail_time);
373e48354ceSNicholas Bellinger 
374e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type(
375e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
376e48354ceSNicholas Bellinger {
377e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
378e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
379e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
380e48354ceSNicholas Bellinger 	u32 last_fail_type;
381e48354ceSNicholas Bellinger 
382e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
383e48354ceSNicholas Bellinger 	last_fail_type = lstat->last_fail_type;
384e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
385e48354ceSNicholas Bellinger 
386e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
387e48354ceSNicholas Bellinger }
388e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(last_fail_type);
389e48354ceSNicholas Bellinger 
390e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name(
391e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
392e48354ceSNicholas Bellinger {
393e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
394e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
395e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
396e48354ceSNicholas Bellinger 	unsigned char buf[224];
397e48354ceSNicholas Bellinger 
398e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
399e48354ceSNicholas Bellinger 	snprintf(buf, 224, "%s", lstat->last_intr_fail_name[0] ?
400e48354ceSNicholas Bellinger 				lstat->last_intr_fail_name : NONE);
401e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
402e48354ceSNicholas Bellinger 
403e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%s\n", buf);
404e48354ceSNicholas Bellinger }
405e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(fail_intr_name);
406e48354ceSNicholas Bellinger 
407e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type(
408e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
409e48354ceSNicholas Bellinger {
410e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
411e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_stat_grps);
412e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
41307ea81b6SDan Carpenter 	int ret;
414e48354ceSNicholas Bellinger 
415e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
41607ea81b6SDan Carpenter 	if (lstat->last_intr_fail_ip_family == AF_INET6)
41707ea81b6SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "ipv6\n");
41807ea81b6SDan Carpenter 	else
41907ea81b6SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "ipv4\n");
420e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
421e48354ceSNicholas Bellinger 
42207ea81b6SDan Carpenter 	return ret;
423e48354ceSNicholas Bellinger }
424e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr_type);
425e48354ceSNicholas Bellinger 
426e48354ceSNicholas Bellinger static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr(
427e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
428e48354ceSNicholas Bellinger {
429e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
430e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_stat_grps);
431e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4320e48e7a5SDan Carpenter 	int ret;
433e48354ceSNicholas Bellinger 
434e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
4350e48e7a5SDan Carpenter 	if (lstat->last_intr_fail_ip_family == AF_INET6) {
4360e48e7a5SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "[%s]\n",
4370e48e7a5SDan Carpenter 			       lstat->last_intr_fail_ip_addr);
4380e48e7a5SDan Carpenter 	} else {
4390e48e7a5SDan Carpenter 		ret = snprintf(page, PAGE_SIZE, "%s\n",
4400e48e7a5SDan Carpenter 			       lstat->last_intr_fail_ip_addr);
4410e48e7a5SDan Carpenter 	}
442e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
443e48354ceSNicholas Bellinger 
4440e48e7a5SDan Carpenter 	return ret;
445e48354ceSNicholas Bellinger }
446e48354ceSNicholas Bellinger ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr);
447e48354ceSNicholas Bellinger 
448e48354ceSNicholas Bellinger CONFIGFS_EATTR_OPS(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps,
449e48354ceSNicholas Bellinger 		iscsi_tgt_attr_group);
450e48354ceSNicholas Bellinger 
451e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
452e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_inst.attr,
453e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_indx.attr,
454e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_login_fails.attr,
455e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_last_fail_time.attr,
456e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_last_fail_type.attr,
457e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_fail_intr_name.attr,
458e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_fail_intr_addr_type.attr,
459e48354ceSNicholas Bellinger 	&iscsi_stat_tgt_attr_fail_intr_addr.attr,
460e48354ceSNicholas Bellinger 	NULL,
461e48354ceSNicholas Bellinger };
462e48354ceSNicholas Bellinger 
463e48354ceSNicholas Bellinger static struct configfs_item_operations iscsi_stat_tgt_attr_item_ops = {
464e48354ceSNicholas Bellinger 	.show_attribute		= iscsi_stat_tgt_attr_attr_show,
465e48354ceSNicholas Bellinger 	.store_attribute	= iscsi_stat_tgt_attr_attr_store,
466e48354ceSNicholas Bellinger };
467e48354ceSNicholas Bellinger 
468e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_tgt_attr_cit = {
469e48354ceSNicholas Bellinger 	.ct_item_ops		= &iscsi_stat_tgt_attr_item_ops,
470e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_tgt_attr_attrs,
471e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
472e48354ceSNicholas Bellinger };
473e48354ceSNicholas Bellinger 
474e48354ceSNicholas Bellinger /*
475e48354ceSNicholas Bellinger  * Target Login Stats Table
476e48354ceSNicholas Bellinger  */
477e48354ceSNicholas Bellinger CONFIGFS_EATTR_STRUCT(iscsi_stat_login, iscsi_wwn_stat_grps);
478e48354ceSNicholas Bellinger #define ISCSI_STAT_LOGIN(_name, _mode)				\
479e48354ceSNicholas Bellinger static struct iscsi_stat_login_attribute			\
480e48354ceSNicholas Bellinger 			iscsi_stat_login_##_name =		\
481e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR(_name, _mode,				\
482e48354ceSNicholas Bellinger 	iscsi_stat_login_show_attr_##_name,			\
483e48354ceSNicholas Bellinger 	iscsi_stat_login_store_attr_##_name);
484e48354ceSNicholas Bellinger 
485e48354ceSNicholas Bellinger #define ISCSI_STAT_LOGIN_RO(_name)				\
486e48354ceSNicholas Bellinger static struct iscsi_stat_login_attribute			\
487e48354ceSNicholas Bellinger 			iscsi_stat_login_##_name =		\
488e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR_RO(_name,				\
489e48354ceSNicholas Bellinger 	iscsi_stat_login_show_attr_##_name);
490e48354ceSNicholas Bellinger 
491e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_inst(
492e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
493e48354ceSNicholas Bellinger {
494e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
495e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
496e48354ceSNicholas Bellinger 
497e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
498e48354ceSNicholas Bellinger }
499e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(inst);
500e48354ceSNicholas Bellinger 
501e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_indx(
502e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
503e48354ceSNicholas Bellinger {
504e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
505e48354ceSNicholas Bellinger }
506e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(indx);
507e48354ceSNicholas Bellinger 
508e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_accepts(
509e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
510e48354ceSNicholas Bellinger {
511e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
512e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
513e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
514e48354ceSNicholas Bellinger 	ssize_t ret;
515e48354ceSNicholas Bellinger 
516e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
517e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
518e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
519e48354ceSNicholas Bellinger 
520e48354ceSNicholas Bellinger 	return ret;
521e48354ceSNicholas Bellinger }
522e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(accepts);
523e48354ceSNicholas Bellinger 
524e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_other_fails(
525e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
526e48354ceSNicholas Bellinger {
527e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
528e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
529e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
530e48354ceSNicholas Bellinger 	ssize_t ret;
531e48354ceSNicholas Bellinger 
532e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
533e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
534e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
535e48354ceSNicholas Bellinger 
536e48354ceSNicholas Bellinger 	return ret;
537e48354ceSNicholas Bellinger }
538e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(other_fails);
539e48354ceSNicholas Bellinger 
540e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_redirects(
541e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
542e48354ceSNicholas Bellinger {
543e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
544e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
545e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
546e48354ceSNicholas Bellinger 	ssize_t ret;
547e48354ceSNicholas Bellinger 
548e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
549e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
550e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
551e48354ceSNicholas Bellinger 
552e48354ceSNicholas Bellinger 	return ret;
553e48354ceSNicholas Bellinger }
554e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(redirects);
555e48354ceSNicholas Bellinger 
556e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_authorize_fails(
557e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
558e48354ceSNicholas Bellinger {
559e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
560e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
561e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
562e48354ceSNicholas Bellinger 	ssize_t ret;
563e48354ceSNicholas Bellinger 
564e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
565e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
566e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
567e48354ceSNicholas Bellinger 
568e48354ceSNicholas Bellinger 	return ret;
569e48354ceSNicholas Bellinger }
570e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(authorize_fails);
571e48354ceSNicholas Bellinger 
572e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_authenticate_fails(
573e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
574e48354ceSNicholas Bellinger {
575e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
576e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
577e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
578e48354ceSNicholas Bellinger 	ssize_t ret;
579e48354ceSNicholas Bellinger 
580e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
581e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
582e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
583e48354ceSNicholas Bellinger 
584e48354ceSNicholas Bellinger 	return ret;
585e48354ceSNicholas Bellinger }
586e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(authenticate_fails);
587e48354ceSNicholas Bellinger 
588e48354ceSNicholas Bellinger static ssize_t iscsi_stat_login_show_attr_negotiate_fails(
589e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
590e48354ceSNicholas Bellinger {
591e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
592e48354ceSNicholas Bellinger 				struct iscsi_tiqn, tiqn_stat_grps);
593e48354ceSNicholas Bellinger 	struct iscsi_login_stats *lstat = &tiqn->login_stats;
594e48354ceSNicholas Bellinger 	ssize_t ret;
595e48354ceSNicholas Bellinger 
596e48354ceSNicholas Bellinger 	spin_lock(&lstat->lock);
597e48354ceSNicholas Bellinger 	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
598e48354ceSNicholas Bellinger 	spin_unlock(&lstat->lock);
599e48354ceSNicholas Bellinger 
600e48354ceSNicholas Bellinger 	return ret;
601e48354ceSNicholas Bellinger }
602e48354ceSNicholas Bellinger ISCSI_STAT_LOGIN_RO(negotiate_fails);
603e48354ceSNicholas Bellinger 
604e48354ceSNicholas Bellinger CONFIGFS_EATTR_OPS(iscsi_stat_login, iscsi_wwn_stat_grps,
605e48354ceSNicholas Bellinger 		iscsi_login_stats_group);
606e48354ceSNicholas Bellinger 
607e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
608e48354ceSNicholas Bellinger 	&iscsi_stat_login_inst.attr,
609e48354ceSNicholas Bellinger 	&iscsi_stat_login_indx.attr,
610e48354ceSNicholas Bellinger 	&iscsi_stat_login_accepts.attr,
611e48354ceSNicholas Bellinger 	&iscsi_stat_login_other_fails.attr,
612e48354ceSNicholas Bellinger 	&iscsi_stat_login_redirects.attr,
613e48354ceSNicholas Bellinger 	&iscsi_stat_login_authorize_fails.attr,
614e48354ceSNicholas Bellinger 	&iscsi_stat_login_authenticate_fails.attr,
615e48354ceSNicholas Bellinger 	&iscsi_stat_login_negotiate_fails.attr,
616e48354ceSNicholas Bellinger 	NULL,
617e48354ceSNicholas Bellinger };
618e48354ceSNicholas Bellinger 
619e48354ceSNicholas Bellinger static struct configfs_item_operations iscsi_stat_login_stats_item_ops = {
620e48354ceSNicholas Bellinger 	.show_attribute		= iscsi_stat_login_attr_show,
621e48354ceSNicholas Bellinger 	.store_attribute	= iscsi_stat_login_attr_store,
622e48354ceSNicholas Bellinger };
623e48354ceSNicholas Bellinger 
624e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_login_cit = {
625e48354ceSNicholas Bellinger 	.ct_item_ops		= &iscsi_stat_login_stats_item_ops,
626e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_login_stats_attrs,
627e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
628e48354ceSNicholas Bellinger };
629e48354ceSNicholas Bellinger 
630e48354ceSNicholas Bellinger /*
631e48354ceSNicholas Bellinger  * Target Logout Stats Table
632e48354ceSNicholas Bellinger  */
633e48354ceSNicholas Bellinger 
634e48354ceSNicholas Bellinger CONFIGFS_EATTR_STRUCT(iscsi_stat_logout, iscsi_wwn_stat_grps);
635e48354ceSNicholas Bellinger #define ISCSI_STAT_LOGOUT(_name, _mode)				\
636e48354ceSNicholas Bellinger static struct iscsi_stat_logout_attribute			\
637e48354ceSNicholas Bellinger 			iscsi_stat_logout_##_name =		\
638e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR(_name, _mode,				\
639e48354ceSNicholas Bellinger 	iscsi_stat_logout_show_attr_##_name,			\
640e48354ceSNicholas Bellinger 	iscsi_stat_logout_store_attr_##_name);
641e48354ceSNicholas Bellinger 
642e48354ceSNicholas Bellinger #define ISCSI_STAT_LOGOUT_RO(_name)				\
643e48354ceSNicholas Bellinger static struct iscsi_stat_logout_attribute			\
644e48354ceSNicholas Bellinger 			iscsi_stat_logout_##_name =		\
645e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR_RO(_name,				\
646e48354ceSNicholas Bellinger 	iscsi_stat_logout_show_attr_##_name);
647e48354ceSNicholas Bellinger 
648e48354ceSNicholas Bellinger static ssize_t iscsi_stat_logout_show_attr_inst(
649e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
650e48354ceSNicholas Bellinger {
651e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
652e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_stat_grps);
653e48354ceSNicholas Bellinger 
654e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
655e48354ceSNicholas Bellinger }
656e48354ceSNicholas Bellinger ISCSI_STAT_LOGOUT_RO(inst);
657e48354ceSNicholas Bellinger 
658e48354ceSNicholas Bellinger static ssize_t iscsi_stat_logout_show_attr_indx(
659e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
660e48354ceSNicholas Bellinger {
661e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
662e48354ceSNicholas Bellinger }
663e48354ceSNicholas Bellinger ISCSI_STAT_LOGOUT_RO(indx);
664e48354ceSNicholas Bellinger 
665e48354ceSNicholas Bellinger static ssize_t iscsi_stat_logout_show_attr_normal_logouts(
666e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
667e48354ceSNicholas Bellinger {
668e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
669e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_stat_grps);
670e48354ceSNicholas Bellinger 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
671e48354ceSNicholas Bellinger 
672e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
673e48354ceSNicholas Bellinger }
674e48354ceSNicholas Bellinger ISCSI_STAT_LOGOUT_RO(normal_logouts);
675e48354ceSNicholas Bellinger 
676e48354ceSNicholas Bellinger static ssize_t iscsi_stat_logout_show_attr_abnormal_logouts(
677e48354ceSNicholas Bellinger 	struct iscsi_wwn_stat_grps *igrps, char *page)
678e48354ceSNicholas Bellinger {
679e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(igrps,
680e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_stat_grps);
681e48354ceSNicholas Bellinger 	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
682e48354ceSNicholas Bellinger 
683e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
684e48354ceSNicholas Bellinger }
685e48354ceSNicholas Bellinger ISCSI_STAT_LOGOUT_RO(abnormal_logouts);
686e48354ceSNicholas Bellinger 
687e48354ceSNicholas Bellinger CONFIGFS_EATTR_OPS(iscsi_stat_logout, iscsi_wwn_stat_grps,
688e48354ceSNicholas Bellinger 		iscsi_logout_stats_group);
689e48354ceSNicholas Bellinger 
690e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
691e48354ceSNicholas Bellinger 	&iscsi_stat_logout_inst.attr,
692e48354ceSNicholas Bellinger 	&iscsi_stat_logout_indx.attr,
693e48354ceSNicholas Bellinger 	&iscsi_stat_logout_normal_logouts.attr,
694e48354ceSNicholas Bellinger 	&iscsi_stat_logout_abnormal_logouts.attr,
695e48354ceSNicholas Bellinger 	NULL,
696e48354ceSNicholas Bellinger };
697e48354ceSNicholas Bellinger 
698e48354ceSNicholas Bellinger static struct configfs_item_operations iscsi_stat_logout_stats_item_ops = {
699e48354ceSNicholas Bellinger 	.show_attribute		= iscsi_stat_logout_attr_show,
700e48354ceSNicholas Bellinger 	.store_attribute	= iscsi_stat_logout_attr_store,
701e48354ceSNicholas Bellinger };
702e48354ceSNicholas Bellinger 
703e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_logout_cit = {
704e48354ceSNicholas Bellinger 	.ct_item_ops		= &iscsi_stat_logout_stats_item_ops,
705e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_logout_stats_attrs,
706e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
707e48354ceSNicholas Bellinger };
708e48354ceSNicholas Bellinger 
709e48354ceSNicholas Bellinger /*
710e48354ceSNicholas Bellinger  * Session Stats Table
711e48354ceSNicholas Bellinger  */
712e48354ceSNicholas Bellinger 
713e48354ceSNicholas Bellinger CONFIGFS_EATTR_STRUCT(iscsi_stat_sess, iscsi_node_stat_grps);
714e48354ceSNicholas Bellinger #define ISCSI_STAT_SESS(_name, _mode)				\
715e48354ceSNicholas Bellinger static struct iscsi_stat_sess_attribute				\
716e48354ceSNicholas Bellinger 			iscsi_stat_sess_##_name =		\
717e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR(_name, _mode,				\
718e48354ceSNicholas Bellinger 	iscsi_stat_sess_show_attr_##_name,			\
719e48354ceSNicholas Bellinger 	iscsi_stat_sess_store_attr_##_name);
720e48354ceSNicholas Bellinger 
721e48354ceSNicholas Bellinger #define ISCSI_STAT_SESS_RO(_name)				\
722e48354ceSNicholas Bellinger static struct iscsi_stat_sess_attribute				\
723e48354ceSNicholas Bellinger 			iscsi_stat_sess_##_name =		\
724e48354ceSNicholas Bellinger 	__CONFIGFS_EATTR_RO(_name,				\
725e48354ceSNicholas Bellinger 	iscsi_stat_sess_show_attr_##_name);
726e48354ceSNicholas Bellinger 
727e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_inst(
728e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
729e48354ceSNicholas Bellinger {
730e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
731e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
732e48354ceSNicholas Bellinger 	struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
733e48354ceSNicholas Bellinger 	struct iscsi_tiqn *tiqn = container_of(wwn,
734e48354ceSNicholas Bellinger 			struct iscsi_tiqn, tiqn_wwn);
735e48354ceSNicholas Bellinger 
736e48354ceSNicholas Bellinger 	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
737e48354ceSNicholas Bellinger }
738e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(inst);
739e48354ceSNicholas Bellinger 
740e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_node(
741e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
742e48354ceSNicholas Bellinger {
743e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
744e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
745e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
746e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
747e48354ceSNicholas Bellinger 	struct se_session *se_sess;
748e48354ceSNicholas Bellinger 	ssize_t ret = 0;
749e48354ceSNicholas Bellinger 
750e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
751e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
752e48354ceSNicholas Bellinger 	if (se_sess) {
7538359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
754e48354ceSNicholas Bellinger 		if (sess)
755e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
756e48354ceSNicholas Bellinger 				sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
757e48354ceSNicholas Bellinger 	}
758e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
759e48354ceSNicholas Bellinger 
760e48354ceSNicholas Bellinger 	return ret;
761e48354ceSNicholas Bellinger }
762e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(node);
763e48354ceSNicholas Bellinger 
764e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_indx(
765e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
766e48354ceSNicholas Bellinger {
767e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
768e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
769e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
770e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
771e48354ceSNicholas Bellinger 	struct se_session *se_sess;
772e48354ceSNicholas Bellinger 	ssize_t ret = 0;
773e48354ceSNicholas Bellinger 
774e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
775e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
776e48354ceSNicholas Bellinger 	if (se_sess) {
7778359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
778e48354ceSNicholas Bellinger 		if (sess)
779e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
780e48354ceSNicholas Bellinger 					sess->session_index);
781e48354ceSNicholas Bellinger 	}
782e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
783e48354ceSNicholas Bellinger 
784e48354ceSNicholas Bellinger 	return ret;
785e48354ceSNicholas Bellinger }
786e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(indx);
787e48354ceSNicholas Bellinger 
788e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_cmd_pdus(
789e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
790e48354ceSNicholas Bellinger {
791e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
792e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
793e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
794e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
795e48354ceSNicholas Bellinger 	struct se_session *se_sess;
796e48354ceSNicholas Bellinger 	ssize_t ret = 0;
797e48354ceSNicholas Bellinger 
798e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
799e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
800e48354ceSNicholas Bellinger 	if (se_sess) {
8018359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
802e48354ceSNicholas Bellinger 		if (sess)
803e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n", sess->cmd_pdus);
804e48354ceSNicholas Bellinger 	}
805e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
806e48354ceSNicholas Bellinger 
807e48354ceSNicholas Bellinger 	return ret;
808e48354ceSNicholas Bellinger }
809e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(cmd_pdus);
810e48354ceSNicholas Bellinger 
811e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_rsp_pdus(
812e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
813e48354ceSNicholas Bellinger {
814e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
815e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
816e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
817e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
818e48354ceSNicholas Bellinger 	struct se_session *se_sess;
819e48354ceSNicholas Bellinger 	ssize_t ret = 0;
820e48354ceSNicholas Bellinger 
821e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
822e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
823e48354ceSNicholas Bellinger 	if (se_sess) {
8248359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
825e48354ceSNicholas Bellinger 		if (sess)
826e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n", sess->rsp_pdus);
827e48354ceSNicholas Bellinger 	}
828e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
829e48354ceSNicholas Bellinger 
830e48354ceSNicholas Bellinger 	return ret;
831e48354ceSNicholas Bellinger }
832e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(rsp_pdus);
833e48354ceSNicholas Bellinger 
834e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_txdata_octs(
835e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
836e48354ceSNicholas Bellinger {
837e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
838e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
839e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
840e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
841e48354ceSNicholas Bellinger 	struct se_session *se_sess;
842e48354ceSNicholas Bellinger 	ssize_t ret = 0;
843e48354ceSNicholas Bellinger 
844e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
845e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
846e48354ceSNicholas Bellinger 	if (se_sess) {
8478359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
848e48354ceSNicholas Bellinger 		if (sess)
849e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%llu\n",
850e48354ceSNicholas Bellinger 				(unsigned long long)sess->tx_data_octets);
851e48354ceSNicholas Bellinger 	}
852e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
853e48354ceSNicholas Bellinger 
854e48354ceSNicholas Bellinger 	return ret;
855e48354ceSNicholas Bellinger }
856e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(txdata_octs);
857e48354ceSNicholas Bellinger 
858e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_rxdata_octs(
859e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
860e48354ceSNicholas Bellinger {
861e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
862e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
863e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
864e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
865e48354ceSNicholas Bellinger 	struct se_session *se_sess;
866e48354ceSNicholas Bellinger 	ssize_t ret = 0;
867e48354ceSNicholas Bellinger 
868e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
869e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
870e48354ceSNicholas Bellinger 	if (se_sess) {
8718359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
872e48354ceSNicholas Bellinger 		if (sess)
873e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%llu\n",
874e48354ceSNicholas Bellinger 				(unsigned long long)sess->rx_data_octets);
875e48354ceSNicholas Bellinger 	}
876e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
877e48354ceSNicholas Bellinger 
878e48354ceSNicholas Bellinger 	return ret;
879e48354ceSNicholas Bellinger }
880e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(rxdata_octs);
881e48354ceSNicholas Bellinger 
882e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors(
883e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
884e48354ceSNicholas Bellinger {
885e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
886e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
887e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
888e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
889e48354ceSNicholas Bellinger 	struct se_session *se_sess;
890e48354ceSNicholas Bellinger 	ssize_t ret = 0;
891e48354ceSNicholas Bellinger 
892e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
893e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
894e48354ceSNicholas Bellinger 	if (se_sess) {
8958359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
896e48354ceSNicholas Bellinger 		if (sess)
897e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
898e48354ceSNicholas Bellinger 					sess->conn_digest_errors);
899e48354ceSNicholas Bellinger 	}
900e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
901e48354ceSNicholas Bellinger 
902e48354ceSNicholas Bellinger 	return ret;
903e48354ceSNicholas Bellinger }
904e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(conn_digest_errors);
905e48354ceSNicholas Bellinger 
906e48354ceSNicholas Bellinger static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors(
907e48354ceSNicholas Bellinger 	struct iscsi_node_stat_grps *igrps, char *page)
908e48354ceSNicholas Bellinger {
909e48354ceSNicholas Bellinger 	struct iscsi_node_acl *acl = container_of(igrps,
910e48354ceSNicholas Bellinger 			struct iscsi_node_acl, node_stat_grps);
911e48354ceSNicholas Bellinger 	struct se_node_acl *se_nacl = &acl->se_node_acl;
912e48354ceSNicholas Bellinger 	struct iscsi_session *sess;
913e48354ceSNicholas Bellinger 	struct se_session *se_sess;
914e48354ceSNicholas Bellinger 	ssize_t ret = 0;
915e48354ceSNicholas Bellinger 
916e48354ceSNicholas Bellinger 	spin_lock_bh(&se_nacl->nacl_sess_lock);
917e48354ceSNicholas Bellinger 	se_sess = se_nacl->nacl_sess;
918e48354ceSNicholas Bellinger 	if (se_sess) {
9198359cf43SJörn Engel 		sess = se_sess->fabric_sess_ptr;
920e48354ceSNicholas Bellinger 		if (sess)
921e48354ceSNicholas Bellinger 			ret = snprintf(page, PAGE_SIZE, "%u\n",
922e48354ceSNicholas Bellinger 					sess->conn_timeout_errors);
923e48354ceSNicholas Bellinger 	}
924e48354ceSNicholas Bellinger 	spin_unlock_bh(&se_nacl->nacl_sess_lock);
925e48354ceSNicholas Bellinger 
926e48354ceSNicholas Bellinger 	return ret;
927e48354ceSNicholas Bellinger }
928e48354ceSNicholas Bellinger ISCSI_STAT_SESS_RO(conn_timeout_errors);
929e48354ceSNicholas Bellinger 
930e48354ceSNicholas Bellinger CONFIGFS_EATTR_OPS(iscsi_stat_sess, iscsi_node_stat_grps,
931e48354ceSNicholas Bellinger 		iscsi_sess_stats_group);
932e48354ceSNicholas Bellinger 
933e48354ceSNicholas Bellinger static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
934e48354ceSNicholas Bellinger 	&iscsi_stat_sess_inst.attr,
935e48354ceSNicholas Bellinger 	&iscsi_stat_sess_node.attr,
936e48354ceSNicholas Bellinger 	&iscsi_stat_sess_indx.attr,
937e48354ceSNicholas Bellinger 	&iscsi_stat_sess_cmd_pdus.attr,
938e48354ceSNicholas Bellinger 	&iscsi_stat_sess_rsp_pdus.attr,
939e48354ceSNicholas Bellinger 	&iscsi_stat_sess_txdata_octs.attr,
940e48354ceSNicholas Bellinger 	&iscsi_stat_sess_rxdata_octs.attr,
941e48354ceSNicholas Bellinger 	&iscsi_stat_sess_conn_digest_errors.attr,
942e48354ceSNicholas Bellinger 	&iscsi_stat_sess_conn_timeout_errors.attr,
943e48354ceSNicholas Bellinger 	NULL,
944e48354ceSNicholas Bellinger };
945e48354ceSNicholas Bellinger 
946e48354ceSNicholas Bellinger static struct configfs_item_operations iscsi_stat_sess_stats_item_ops = {
947e48354ceSNicholas Bellinger 	.show_attribute		= iscsi_stat_sess_attr_show,
948e48354ceSNicholas Bellinger 	.store_attribute	= iscsi_stat_sess_attr_store,
949e48354ceSNicholas Bellinger };
950e48354ceSNicholas Bellinger 
951e48354ceSNicholas Bellinger struct config_item_type iscsi_stat_sess_cit = {
952e48354ceSNicholas Bellinger 	.ct_item_ops		= &iscsi_stat_sess_stats_item_ops,
953e48354ceSNicholas Bellinger 	.ct_attrs		= iscsi_stat_sess_stats_attrs,
954e48354ceSNicholas Bellinger 	.ct_owner		= THIS_MODULE,
955e48354ceSNicholas Bellinger };
956