blob: 411cb266a47d5c39bd7df5ec4b705bce68ef0ca2 [file] [log] [blame]
Nicholas Bellingere48354c2011-07-23 06:43:04 +00001/*******************************************************************************
2 * Modern ConfigFS group context specific iSCSI statistics based on original
3 * iscsi_target_mib.c code
4 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07005 * Copyright (c) 2011-2013 Datera, Inc.
Nicholas Bellingere48354c2011-07-23 06:43:04 +00006 *
7 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 ******************************************************************************/
19
20#include <linux/configfs.h>
Paul Gortmakerc53181a2011-08-30 18:16:43 -040021#include <linux/export.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000022#include <scsi/iscsi_proto.h>
23#include <target/target_core_base.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000024
Sagi Grimberg67f091f2015-01-07 14:57:31 +020025#include <target/iscsi/iscsi_target_core.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000026#include "iscsi_target_parameters.h"
27#include "iscsi_target_device.h"
28#include "iscsi_target_tpg.h"
29#include "iscsi_target_util.h"
Sagi Grimberg67f091f2015-01-07 14:57:31 +020030#include <target/iscsi/iscsi_target_stat.h>
Nicholas Bellingere48354c2011-07-23 06:43:04 +000031
32#ifndef INITIAL_JIFFIES
33#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
34#endif
35
36/* Instance Attributes Table */
37#define ISCSI_INST_NUM_NODES 1
38#define ISCSI_INST_DESCR "Storage Engine Target"
39#define ISCSI_INST_LAST_FAILURE_TYPE 0
40#define ISCSI_DISCONTINUITY_TIME 0
41
42#define ISCSI_NODE_INDEX 1
43
44#define ISPRINT(a) ((a >= ' ') && (a <= '~'))
45
46/****************************************************************************
47 * iSCSI MIB Tables
48 ****************************************************************************/
49/*
50 * Instance Attributes Table
51 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +020052static struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000053{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020054 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
55 struct iscsi_wwn_stat_grps, iscsi_instance_group);
56 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000057}
Nicholas Bellingere48354c2011-07-23 06:43:04 +000058
Christoph Hellwig2eafd722015-10-03 15:32:55 +020059static ssize_t iscsi_stat_instance_inst_show(struct config_item *item,
60 char *page)
61{
62 return snprintf(page, PAGE_SIZE, "%u\n",
63 iscsi_instance_tiqn(item)->tiqn_index);
64}
65
66static ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item,
67 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000068{
69 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
70}
Nicholas Bellingere48354c2011-07-23 06:43:04 +000071
Christoph Hellwig2eafd722015-10-03 15:32:55 +020072static ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item,
73 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000074{
75 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
76}
Nicholas Bellingere48354c2011-07-23 06:43:04 +000077
Christoph Hellwig2eafd722015-10-03 15:32:55 +020078static ssize_t iscsi_stat_instance_portals_show(struct config_item *item,
79 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000080{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020081 return snprintf(page, PAGE_SIZE, "%u\n",
82 iscsi_instance_tiqn(item)->tiqn_num_tpg_nps);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000083}
Nicholas Bellingere48354c2011-07-23 06:43:04 +000084
Christoph Hellwig2eafd722015-10-03 15:32:55 +020085static ssize_t iscsi_stat_instance_nodes_show(struct config_item *item,
86 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000087{
88 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
89}
Nicholas Bellingere48354c2011-07-23 06:43:04 +000090
Christoph Hellwig2eafd722015-10-03 15:32:55 +020091static ssize_t iscsi_stat_instance_sessions_show(struct config_item *item,
92 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +000093{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020094 return snprintf(page, PAGE_SIZE, "%u\n",
95 iscsi_instance_tiqn(item)->tiqn_nsessions);
Nicholas Bellingere48354c2011-07-23 06:43:04 +000096}
Nicholas Bellingere48354c2011-07-23 06:43:04 +000097
Christoph Hellwig2eafd722015-10-03 15:32:55 +020098static ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item,
99 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000100{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200101 struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000102 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
103 u32 sess_err_count;
104
105 spin_lock_bh(&sess_err->lock);
106 sess_err_count = (sess_err->digest_errors +
107 sess_err->cxn_timeout_errors +
108 sess_err->pdu_format_errors);
109 spin_unlock_bh(&sess_err->lock);
110
111 return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
112}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000113
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200114static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
115 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000116{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200117 struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000118 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
119
120 return snprintf(page, PAGE_SIZE, "%u\n",
121 sess_err->last_sess_failure_type);
122}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000123
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200124static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
125 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000126{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200127 struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000128 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
129
130 return snprintf(page, PAGE_SIZE, "%s\n",
131 sess_err->last_sess_fail_rem_name[0] ?
132 sess_err->last_sess_fail_rem_name : NONE);
133}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000134
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200135static ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item,
136 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000137{
138 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
139}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000140
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200141static ssize_t iscsi_stat_instance_description_show(struct config_item *item,
142 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000143{
144 return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
145}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000146
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200147static ssize_t iscsi_stat_instance_vendor_show(struct config_item *item,
148 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000149{
Nicholas Bellinger4c762512013-09-05 15:29:12 -0700150 return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000151}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000152
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200153static ssize_t iscsi_stat_instance_version_show(struct config_item *item,
154 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000155{
156 return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
157}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000158
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200159CONFIGFS_ATTR_RO(iscsi_stat_instance_, inst);
160CONFIGFS_ATTR_RO(iscsi_stat_instance_, min_ver);
161CONFIGFS_ATTR_RO(iscsi_stat_instance_, max_ver);
162CONFIGFS_ATTR_RO(iscsi_stat_instance_, portals);
163CONFIGFS_ATTR_RO(iscsi_stat_instance_, nodes);
164CONFIGFS_ATTR_RO(iscsi_stat_instance_, sessions);
165CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_sess);
166CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_type);
167CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_rem_name);
168CONFIGFS_ATTR_RO(iscsi_stat_instance_, disc_time);
169CONFIGFS_ATTR_RO(iscsi_stat_instance_, description);
170CONFIGFS_ATTR_RO(iscsi_stat_instance_, vendor);
171CONFIGFS_ATTR_RO(iscsi_stat_instance_, version);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000172
173static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200174 &iscsi_stat_instance_attr_inst,
175 &iscsi_stat_instance_attr_min_ver,
176 &iscsi_stat_instance_attr_max_ver,
177 &iscsi_stat_instance_attr_portals,
178 &iscsi_stat_instance_attr_nodes,
179 &iscsi_stat_instance_attr_sessions,
180 &iscsi_stat_instance_attr_fail_sess,
181 &iscsi_stat_instance_attr_fail_type,
182 &iscsi_stat_instance_attr_fail_rem_name,
183 &iscsi_stat_instance_attr_disc_time,
184 &iscsi_stat_instance_attr_description,
185 &iscsi_stat_instance_attr_vendor,
186 &iscsi_stat_instance_attr_version,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000187 NULL,
188};
189
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000190struct config_item_type iscsi_stat_instance_cit = {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000191 .ct_attrs = iscsi_stat_instance_attrs,
192 .ct_owner = THIS_MODULE,
193};
194
195/*
196 * Instance Session Failure Stats Table
197 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200198static struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000199{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200200 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
201 struct iscsi_wwn_stat_grps, iscsi_sess_err_group);
202 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000203}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000204
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200205static ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item,
206 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000207{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200208 return snprintf(page, PAGE_SIZE, "%u\n",
209 iscsi_sess_err_tiqn(item)->tiqn_index);
210}
211
212static ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item,
213 char *page)
214{
215 struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000216 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
217
218 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
219}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000220
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200221static ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item,
222 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000223{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200224 struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000225 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
226
227 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
228}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000229
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200230static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
231 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000232{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200233 struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000234 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
235
236 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
237}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000238
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200239CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst);
240CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, digest_errors);
241CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, cxn_errors);
242CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, format_errors);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000243
244static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200245 &iscsi_stat_sess_err_attr_inst,
246 &iscsi_stat_sess_err_attr_digest_errors,
247 &iscsi_stat_sess_err_attr_cxn_errors,
248 &iscsi_stat_sess_err_attr_format_errors,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000249 NULL,
250};
251
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000252struct config_item_type iscsi_stat_sess_err_cit = {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000253 .ct_attrs = iscsi_stat_sess_err_attrs,
254 .ct_owner = THIS_MODULE,
255};
256
257/*
258 * Target Attributes Table
259 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200260static struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000261{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200262 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
263 struct iscsi_wwn_stat_grps, iscsi_tgt_attr_group);
264 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000265}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000266
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200267static ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item,
268 char *page)
269{
270 return snprintf(page, PAGE_SIZE, "%u\n",
271 iscsi_tgt_attr_tiqn(item)->tiqn_index);
272}
273
274static ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item,
275 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000276{
277 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
278}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000279
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200280static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
281 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000282{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200283 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000284 struct iscsi_login_stats *lstat = &tiqn->login_stats;
285 u32 fail_count;
286
287 spin_lock(&lstat->lock);
288 fail_count = (lstat->redirects + lstat->authorize_fails +
289 lstat->authenticate_fails + lstat->negotiate_fails +
290 lstat->other_fails);
291 spin_unlock(&lstat->lock);
292
293 return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
294}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000295
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200296static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
297 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000298{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200299 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000300 struct iscsi_login_stats *lstat = &tiqn->login_stats;
301 u32 last_fail_time;
302
303 spin_lock(&lstat->lock);
304 last_fail_time = lstat->last_fail_time ?
305 (u32)(((u32)lstat->last_fail_time -
306 INITIAL_JIFFIES) * 100 / HZ) : 0;
307 spin_unlock(&lstat->lock);
308
309 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
310}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000311
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200312static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
313 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000314{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200315 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000316 struct iscsi_login_stats *lstat = &tiqn->login_stats;
317 u32 last_fail_type;
318
319 spin_lock(&lstat->lock);
320 last_fail_type = lstat->last_fail_type;
321 spin_unlock(&lstat->lock);
322
323 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
324}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000325
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200326static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
327 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000328{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200329 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000330 struct iscsi_login_stats *lstat = &tiqn->login_stats;
331 unsigned char buf[224];
332
333 spin_lock(&lstat->lock);
334 snprintf(buf, 224, "%s", lstat->last_intr_fail_name[0] ?
335 lstat->last_intr_fail_name : NONE);
336 spin_unlock(&lstat->lock);
337
338 return snprintf(page, PAGE_SIZE, "%s\n", buf);
339}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000340
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200341static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item,
342 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000343{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200344 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000345 struct iscsi_login_stats *lstat = &tiqn->login_stats;
Dan Carpenter07ea81b2013-01-31 11:17:54 +0300346 int ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000347
348 spin_lock(&lstat->lock);
Dan Carpenter07ea81b2013-01-31 11:17:54 +0300349 if (lstat->last_intr_fail_ip_family == AF_INET6)
350 ret = snprintf(page, PAGE_SIZE, "ipv6\n");
351 else
352 ret = snprintf(page, PAGE_SIZE, "ipv4\n");
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000353 spin_unlock(&lstat->lock);
354
Dan Carpenter07ea81b2013-01-31 11:17:54 +0300355 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000356}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000357
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200358static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item,
359 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000360{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200361 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000362 struct iscsi_login_stats *lstat = &tiqn->login_stats;
Dan Carpenter0e48e7a2013-01-31 11:19:09 +0300363 int ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000364
365 spin_lock(&lstat->lock);
Andy Groverdc58f762015-08-24 10:26:05 -0700366 ret = snprintf(page, PAGE_SIZE, "%pISc\n", &lstat->last_intr_fail_sockaddr);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000367 spin_unlock(&lstat->lock);
368
Dan Carpenter0e48e7a2013-01-31 11:19:09 +0300369 return ret;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000370}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000371
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200372CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, inst);
373CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, indx);
374CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, login_fails);
375CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_time);
376CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_type);
377CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_name);
378CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr_type);
379CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000380
381static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200382 &iscsi_stat_tgt_attr_attr_inst,
383 &iscsi_stat_tgt_attr_attr_indx,
384 &iscsi_stat_tgt_attr_attr_login_fails,
385 &iscsi_stat_tgt_attr_attr_last_fail_time,
386 &iscsi_stat_tgt_attr_attr_last_fail_type,
387 &iscsi_stat_tgt_attr_attr_fail_intr_name,
388 &iscsi_stat_tgt_attr_attr_fail_intr_addr_type,
389 &iscsi_stat_tgt_attr_attr_fail_intr_addr,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000390 NULL,
391};
392
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000393struct config_item_type iscsi_stat_tgt_attr_cit = {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000394 .ct_attrs = iscsi_stat_tgt_attr_attrs,
395 .ct_owner = THIS_MODULE,
396};
397
398/*
399 * Target Login Stats Table
400 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200401static struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000402{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200403 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
404 struct iscsi_wwn_stat_grps, iscsi_login_stats_group);
405 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000406}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000407
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200408static ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page)
409{
410 return snprintf(page, PAGE_SIZE, "%u\n",
411 iscsi_login_stat_tiqn(item)->tiqn_index);
412}
413
414static ssize_t iscsi_stat_login_indx_show(struct config_item *item,
415 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000416{
417 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
418}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000419
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200420static ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
421 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000422{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200423 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000424 struct iscsi_login_stats *lstat = &tiqn->login_stats;
425 ssize_t ret;
426
427 spin_lock(&lstat->lock);
428 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
429 spin_unlock(&lstat->lock);
430
431 return ret;
432}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000433
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200434static ssize_t iscsi_stat_login_other_fails_show(struct config_item *item,
435 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000436{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200437 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000438 struct iscsi_login_stats *lstat = &tiqn->login_stats;
439 ssize_t ret;
440
441 spin_lock(&lstat->lock);
442 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
443 spin_unlock(&lstat->lock);
444
445 return ret;
446}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000447
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200448static ssize_t iscsi_stat_login_redirects_show(struct config_item *item,
449 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000450{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200451 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000452 struct iscsi_login_stats *lstat = &tiqn->login_stats;
453 ssize_t ret;
454
455 spin_lock(&lstat->lock);
456 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
457 spin_unlock(&lstat->lock);
458
459 return ret;
460}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000461
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200462static ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item,
463 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000464{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200465 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000466 struct iscsi_login_stats *lstat = &tiqn->login_stats;
467 ssize_t ret;
468
469 spin_lock(&lstat->lock);
470 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
471 spin_unlock(&lstat->lock);
472
473 return ret;
474}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000475
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200476static ssize_t iscsi_stat_login_authenticate_fails_show(
477 struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000478{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200479 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000480 struct iscsi_login_stats *lstat = &tiqn->login_stats;
481 ssize_t ret;
482
483 spin_lock(&lstat->lock);
484 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
485 spin_unlock(&lstat->lock);
486
487 return ret;
488}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000489
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200490static ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item,
491 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000492{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200493 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000494 struct iscsi_login_stats *lstat = &tiqn->login_stats;
495 ssize_t ret;
496
497 spin_lock(&lstat->lock);
498 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
499 spin_unlock(&lstat->lock);
500
501 return ret;
502}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000503
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200504CONFIGFS_ATTR_RO(iscsi_stat_login_, inst);
505CONFIGFS_ATTR_RO(iscsi_stat_login_, indx);
506CONFIGFS_ATTR_RO(iscsi_stat_login_, accepts);
507CONFIGFS_ATTR_RO(iscsi_stat_login_, other_fails);
508CONFIGFS_ATTR_RO(iscsi_stat_login_, redirects);
509CONFIGFS_ATTR_RO(iscsi_stat_login_, authorize_fails);
510CONFIGFS_ATTR_RO(iscsi_stat_login_, authenticate_fails);
511CONFIGFS_ATTR_RO(iscsi_stat_login_, negotiate_fails);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000512
513static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200514 &iscsi_stat_login_attr_inst,
515 &iscsi_stat_login_attr_indx,
516 &iscsi_stat_login_attr_accepts,
517 &iscsi_stat_login_attr_other_fails,
518 &iscsi_stat_login_attr_redirects,
519 &iscsi_stat_login_attr_authorize_fails,
520 &iscsi_stat_login_attr_authenticate_fails,
521 &iscsi_stat_login_attr_negotiate_fails,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000522 NULL,
523};
524
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000525struct config_item_type iscsi_stat_login_cit = {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000526 .ct_attrs = iscsi_stat_login_stats_attrs,
527 .ct_owner = THIS_MODULE,
528};
529
530/*
531 * Target Logout Stats Table
532 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200533static struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000534{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200535 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
536 struct iscsi_wwn_stat_grps, iscsi_logout_stats_group);
537 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000538}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000539
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200540static ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page)
541{
542 return snprintf(page, PAGE_SIZE, "%u\n",
543 iscsi_logout_stat_tiqn(item)->tiqn_index);
544}
545
546static ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000547{
548 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
549}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000550
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200551static ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item,
552 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000553{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200554 struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000555 struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
556
557 return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
558}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000559
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200560static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
561 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000562{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200563 struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000564 struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
565
566 return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
567}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000568
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200569CONFIGFS_ATTR_RO(iscsi_stat_logout_, inst);
570CONFIGFS_ATTR_RO(iscsi_stat_logout_, indx);
571CONFIGFS_ATTR_RO(iscsi_stat_logout_, normal_logouts);
572CONFIGFS_ATTR_RO(iscsi_stat_logout_, abnormal_logouts);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000573
574static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200575 &iscsi_stat_logout_attr_inst,
576 &iscsi_stat_logout_attr_indx,
577 &iscsi_stat_logout_attr_normal_logouts,
578 &iscsi_stat_logout_attr_abnormal_logouts,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000579 NULL,
580};
581
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000582struct config_item_type iscsi_stat_logout_cit = {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000583 .ct_attrs = iscsi_stat_logout_stats_attrs,
584 .ct_owner = THIS_MODULE,
585};
586
587/*
588 * Session Stats Table
589 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200590static struct iscsi_node_acl *iscsi_stat_nacl(struct config_item *item)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000591{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200592 struct iscsi_node_stat_grps *igrps = container_of(to_config_group(item),
593 struct iscsi_node_stat_grps, iscsi_sess_stats_group);
594 return container_of(igrps, struct iscsi_node_acl, node_stat_grps);
595}
596
597static ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page)
598{
599 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000600 struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
601 struct iscsi_tiqn *tiqn = container_of(wwn,
602 struct iscsi_tiqn, tiqn_wwn);
603
604 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
605}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000606
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200607static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000608{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200609 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000610 struct se_node_acl *se_nacl = &acl->se_node_acl;
611 struct iscsi_session *sess;
612 struct se_session *se_sess;
613 ssize_t ret = 0;
614
615 spin_lock_bh(&se_nacl->nacl_sess_lock);
616 se_sess = se_nacl->nacl_sess;
617 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100618 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000619 if (sess)
620 ret = snprintf(page, PAGE_SIZE, "%u\n",
621 sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
622 }
623 spin_unlock_bh(&se_nacl->nacl_sess_lock);
624
625 return ret;
626}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000627
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200628static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000629{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200630 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000631 struct se_node_acl *se_nacl = &acl->se_node_acl;
632 struct iscsi_session *sess;
633 struct se_session *se_sess;
634 ssize_t ret = 0;
635
636 spin_lock_bh(&se_nacl->nacl_sess_lock);
637 se_sess = se_nacl->nacl_sess;
638 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100639 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000640 if (sess)
641 ret = snprintf(page, PAGE_SIZE, "%u\n",
642 sess->session_index);
643 }
644 spin_unlock_bh(&se_nacl->nacl_sess_lock);
645
646 return ret;
647}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000648
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200649static ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item,
650 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000651{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200652 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000653 struct se_node_acl *se_nacl = &acl->se_node_acl;
654 struct iscsi_session *sess;
655 struct se_session *se_sess;
656 ssize_t ret = 0;
657
658 spin_lock_bh(&se_nacl->nacl_sess_lock);
659 se_sess = se_nacl->nacl_sess;
660 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100661 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000662 if (sess)
Nicholas Bellinger04f3b312013-11-13 18:54:45 -0800663 ret = snprintf(page, PAGE_SIZE, "%lu\n",
664 atomic_long_read(&sess->cmd_pdus));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000665 }
666 spin_unlock_bh(&se_nacl->nacl_sess_lock);
667
668 return ret;
669}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000670
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200671static ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item,
672 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000673{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200674 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000675 struct se_node_acl *se_nacl = &acl->se_node_acl;
676 struct iscsi_session *sess;
677 struct se_session *se_sess;
678 ssize_t ret = 0;
679
680 spin_lock_bh(&se_nacl->nacl_sess_lock);
681 se_sess = se_nacl->nacl_sess;
682 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100683 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000684 if (sess)
Nicholas Bellinger04f3b312013-11-13 18:54:45 -0800685 ret = snprintf(page, PAGE_SIZE, "%lu\n",
686 atomic_long_read(&sess->rsp_pdus));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000687 }
688 spin_unlock_bh(&se_nacl->nacl_sess_lock);
689
690 return ret;
691}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000692
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200693static ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item,
694 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000695{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200696 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000697 struct se_node_acl *se_nacl = &acl->se_node_acl;
698 struct iscsi_session *sess;
699 struct se_session *se_sess;
700 ssize_t ret = 0;
701
702 spin_lock_bh(&se_nacl->nacl_sess_lock);
703 se_sess = se_nacl->nacl_sess;
704 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100705 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000706 if (sess)
Nicholas Bellinger04f3b312013-11-13 18:54:45 -0800707 ret = snprintf(page, PAGE_SIZE, "%lu\n",
708 atomic_long_read(&sess->tx_data_octets));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000709 }
710 spin_unlock_bh(&se_nacl->nacl_sess_lock);
711
712 return ret;
713}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000714
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200715static ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item,
716 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000717{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200718 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000719 struct se_node_acl *se_nacl = &acl->se_node_acl;
720 struct iscsi_session *sess;
721 struct se_session *se_sess;
722 ssize_t ret = 0;
723
724 spin_lock_bh(&se_nacl->nacl_sess_lock);
725 se_sess = se_nacl->nacl_sess;
726 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100727 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000728 if (sess)
Nicholas Bellinger04f3b312013-11-13 18:54:45 -0800729 ret = snprintf(page, PAGE_SIZE, "%lu\n",
730 atomic_long_read(&sess->rx_data_octets));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000731 }
732 spin_unlock_bh(&se_nacl->nacl_sess_lock);
733
734 return ret;
735}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000736
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200737static ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item,
738 char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000739{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200740 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000741 struct se_node_acl *se_nacl = &acl->se_node_acl;
742 struct iscsi_session *sess;
743 struct se_session *se_sess;
744 ssize_t ret = 0;
745
746 spin_lock_bh(&se_nacl->nacl_sess_lock);
747 se_sess = se_nacl->nacl_sess;
748 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100749 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000750 if (sess)
Nicholas Bellinger04f3b312013-11-13 18:54:45 -0800751 ret = snprintf(page, PAGE_SIZE, "%lu\n",
752 atomic_long_read(&sess->conn_digest_errors));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000753 }
754 spin_unlock_bh(&se_nacl->nacl_sess_lock);
755
756 return ret;
757}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000758
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200759static ssize_t iscsi_stat_sess_conn_timeout_errors_show(
760 struct config_item *item, char *page)
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000761{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200762 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000763 struct se_node_acl *se_nacl = &acl->se_node_acl;
764 struct iscsi_session *sess;
765 struct se_session *se_sess;
766 ssize_t ret = 0;
767
768 spin_lock_bh(&se_nacl->nacl_sess_lock);
769 se_sess = se_nacl->nacl_sess;
770 if (se_sess) {
Jörn Engel8359cf42011-11-24 02:05:51 +0100771 sess = se_sess->fabric_sess_ptr;
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000772 if (sess)
Nicholas Bellinger04f3b312013-11-13 18:54:45 -0800773 ret = snprintf(page, PAGE_SIZE, "%lu\n",
774 atomic_long_read(&sess->conn_timeout_errors));
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000775 }
776 spin_unlock_bh(&se_nacl->nacl_sess_lock);
777
778 return ret;
779}
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000780
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200781CONFIGFS_ATTR_RO(iscsi_stat_sess_, inst);
782CONFIGFS_ATTR_RO(iscsi_stat_sess_, node);
783CONFIGFS_ATTR_RO(iscsi_stat_sess_, indx);
784CONFIGFS_ATTR_RO(iscsi_stat_sess_, cmd_pdus);
785CONFIGFS_ATTR_RO(iscsi_stat_sess_, rsp_pdus);
786CONFIGFS_ATTR_RO(iscsi_stat_sess_, txdata_octs);
787CONFIGFS_ATTR_RO(iscsi_stat_sess_, rxdata_octs);
788CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_digest_errors);
789CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_timeout_errors);
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000790
791static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200792 &iscsi_stat_sess_attr_inst,
793 &iscsi_stat_sess_attr_node,
794 &iscsi_stat_sess_attr_indx,
795 &iscsi_stat_sess_attr_cmd_pdus,
796 &iscsi_stat_sess_attr_rsp_pdus,
797 &iscsi_stat_sess_attr_txdata_octs,
798 &iscsi_stat_sess_attr_rxdata_octs,
799 &iscsi_stat_sess_attr_conn_digest_errors,
800 &iscsi_stat_sess_attr_conn_timeout_errors,
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000801 NULL,
802};
803
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000804struct config_item_type iscsi_stat_sess_cit = {
Nicholas Bellingere48354c2011-07-23 06:43:04 +0000805 .ct_attrs = iscsi_stat_sess_stats_attrs,
806 .ct_owner = THIS_MODULE,
807};