spi-topcliff-pch: supports a spi mode setup and bit order setup by IO control
[zen-stable.git] / drivers / target / iscsi / iscsi_target_stat.c
blob421d6947dc64247c2bc02a1136f8bb2e0489c64a
1 /*******************************************************************************
2 * Modern ConfigFS group context specific iSCSI statistics based on original
3 * iscsi_target_mib.c code
5 * Copyright (c) 2011 Rising Tide Systems
7 * Licensed to the Linux Foundation under the General Public License (GPL) version 2.
9 * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 ******************************************************************************/
22 #include <linux/configfs.h>
23 #include <linux/export.h>
24 #include <scsi/iscsi_proto.h>
25 #include <target/target_core_base.h>
26 #include <target/configfs_macros.h>
28 #include "iscsi_target_core.h"
29 #include "iscsi_target_parameters.h"
30 #include "iscsi_target_device.h"
31 #include "iscsi_target_tpg.h"
32 #include "iscsi_target_util.h"
33 #include "iscsi_target_stat.h"
35 #ifndef INITIAL_JIFFIES
36 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
37 #endif
39 /* Instance Attributes Table */
40 #define ISCSI_INST_NUM_NODES 1
41 #define ISCSI_INST_DESCR "Storage Engine Target"
42 #define ISCSI_INST_LAST_FAILURE_TYPE 0
43 #define ISCSI_DISCONTINUITY_TIME 0
45 #define ISCSI_NODE_INDEX 1
47 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
49 /****************************************************************************
50 * iSCSI MIB Tables
51 ****************************************************************************/
53 * Instance Attributes Table
55 CONFIGFS_EATTR_STRUCT(iscsi_stat_instance, iscsi_wwn_stat_grps);
56 #define ISCSI_STAT_INSTANCE_ATTR(_name, _mode) \
57 static struct iscsi_stat_instance_attribute \
58 iscsi_stat_instance_##_name = \
59 __CONFIGFS_EATTR(_name, _mode, \
60 iscsi_stat_instance_show_attr_##_name, \
61 iscsi_stat_instance_store_attr_##_name);
63 #define ISCSI_STAT_INSTANCE_ATTR_RO(_name) \
64 static struct iscsi_stat_instance_attribute \
65 iscsi_stat_instance_##_name = \
66 __CONFIGFS_EATTR_RO(_name, \
67 iscsi_stat_instance_show_attr_##_name);
69 static ssize_t iscsi_stat_instance_show_attr_inst(
70 struct iscsi_wwn_stat_grps *igrps, char *page)
72 struct iscsi_tiqn *tiqn = container_of(igrps,
73 struct iscsi_tiqn, tiqn_stat_grps);
75 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
77 ISCSI_STAT_INSTANCE_ATTR_RO(inst);
79 static ssize_t iscsi_stat_instance_show_attr_min_ver(
80 struct iscsi_wwn_stat_grps *igrps, char *page)
82 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
84 ISCSI_STAT_INSTANCE_ATTR_RO(min_ver);
86 static ssize_t iscsi_stat_instance_show_attr_max_ver(
87 struct iscsi_wwn_stat_grps *igrps, char *page)
89 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
91 ISCSI_STAT_INSTANCE_ATTR_RO(max_ver);
93 static ssize_t iscsi_stat_instance_show_attr_portals(
94 struct iscsi_wwn_stat_grps *igrps, char *page)
96 struct iscsi_tiqn *tiqn = container_of(igrps,
97 struct iscsi_tiqn, tiqn_stat_grps);
99 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_num_tpg_nps);
101 ISCSI_STAT_INSTANCE_ATTR_RO(portals);
103 static ssize_t iscsi_stat_instance_show_attr_nodes(
104 struct iscsi_wwn_stat_grps *igrps, char *page)
106 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
108 ISCSI_STAT_INSTANCE_ATTR_RO(nodes);
110 static ssize_t iscsi_stat_instance_show_attr_sessions(
111 struct iscsi_wwn_stat_grps *igrps, char *page)
113 struct iscsi_tiqn *tiqn = container_of(igrps,
114 struct iscsi_tiqn, tiqn_stat_grps);
116 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_nsessions);
118 ISCSI_STAT_INSTANCE_ATTR_RO(sessions);
120 static ssize_t iscsi_stat_instance_show_attr_fail_sess(
121 struct iscsi_wwn_stat_grps *igrps, char *page)
123 struct iscsi_tiqn *tiqn = container_of(igrps,
124 struct iscsi_tiqn, tiqn_stat_grps);
125 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
126 u32 sess_err_count;
128 spin_lock_bh(&sess_err->lock);
129 sess_err_count = (sess_err->digest_errors +
130 sess_err->cxn_timeout_errors +
131 sess_err->pdu_format_errors);
132 spin_unlock_bh(&sess_err->lock);
134 return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
136 ISCSI_STAT_INSTANCE_ATTR_RO(fail_sess);
138 static ssize_t iscsi_stat_instance_show_attr_fail_type(
139 struct iscsi_wwn_stat_grps *igrps, char *page)
141 struct iscsi_tiqn *tiqn = container_of(igrps,
142 struct iscsi_tiqn, tiqn_stat_grps);
143 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
145 return snprintf(page, PAGE_SIZE, "%u\n",
146 sess_err->last_sess_failure_type);
148 ISCSI_STAT_INSTANCE_ATTR_RO(fail_type);
150 static ssize_t iscsi_stat_instance_show_attr_fail_rem_name(
151 struct iscsi_wwn_stat_grps *igrps, char *page)
153 struct iscsi_tiqn *tiqn = container_of(igrps,
154 struct iscsi_tiqn, tiqn_stat_grps);
155 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
157 return snprintf(page, PAGE_SIZE, "%s\n",
158 sess_err->last_sess_fail_rem_name[0] ?
159 sess_err->last_sess_fail_rem_name : NONE);
161 ISCSI_STAT_INSTANCE_ATTR_RO(fail_rem_name);
163 static ssize_t iscsi_stat_instance_show_attr_disc_time(
164 struct iscsi_wwn_stat_grps *igrps, char *page)
166 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
168 ISCSI_STAT_INSTANCE_ATTR_RO(disc_time);
170 static ssize_t iscsi_stat_instance_show_attr_description(
171 struct iscsi_wwn_stat_grps *igrps, char *page)
173 return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
175 ISCSI_STAT_INSTANCE_ATTR_RO(description);
177 static ssize_t iscsi_stat_instance_show_attr_vendor(
178 struct iscsi_wwn_stat_grps *igrps, char *page)
180 return snprintf(page, PAGE_SIZE, "RisingTide Systems iSCSI-Target\n");
182 ISCSI_STAT_INSTANCE_ATTR_RO(vendor);
184 static ssize_t iscsi_stat_instance_show_attr_version(
185 struct iscsi_wwn_stat_grps *igrps, char *page)
187 return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
189 ISCSI_STAT_INSTANCE_ATTR_RO(version);
191 CONFIGFS_EATTR_OPS(iscsi_stat_instance, iscsi_wwn_stat_grps,
192 iscsi_instance_group);
194 static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
195 &iscsi_stat_instance_inst.attr,
196 &iscsi_stat_instance_min_ver.attr,
197 &iscsi_stat_instance_max_ver.attr,
198 &iscsi_stat_instance_portals.attr,
199 &iscsi_stat_instance_nodes.attr,
200 &iscsi_stat_instance_sessions.attr,
201 &iscsi_stat_instance_fail_sess.attr,
202 &iscsi_stat_instance_fail_type.attr,
203 &iscsi_stat_instance_fail_rem_name.attr,
204 &iscsi_stat_instance_disc_time.attr,
205 &iscsi_stat_instance_description.attr,
206 &iscsi_stat_instance_vendor.attr,
207 &iscsi_stat_instance_version.attr,
208 NULL,
211 static struct configfs_item_operations iscsi_stat_instance_item_ops = {
212 .show_attribute = iscsi_stat_instance_attr_show,
213 .store_attribute = iscsi_stat_instance_attr_store,
216 struct config_item_type iscsi_stat_instance_cit = {
217 .ct_item_ops = &iscsi_stat_instance_item_ops,
218 .ct_attrs = iscsi_stat_instance_attrs,
219 .ct_owner = THIS_MODULE,
223 * Instance Session Failure Stats Table
225 CONFIGFS_EATTR_STRUCT(iscsi_stat_sess_err, iscsi_wwn_stat_grps);
226 #define ISCSI_STAT_SESS_ERR_ATTR(_name, _mode) \
227 static struct iscsi_stat_sess_err_attribute \
228 iscsi_stat_sess_err_##_name = \
229 __CONFIGFS_EATTR(_name, _mode, \
230 iscsi_stat_sess_err_show_attr_##_name, \
231 iscsi_stat_sess_err_store_attr_##_name);
233 #define ISCSI_STAT_SESS_ERR_ATTR_RO(_name) \
234 static struct iscsi_stat_sess_err_attribute \
235 iscsi_stat_sess_err_##_name = \
236 __CONFIGFS_EATTR_RO(_name, \
237 iscsi_stat_sess_err_show_attr_##_name);
239 static ssize_t iscsi_stat_sess_err_show_attr_inst(
240 struct iscsi_wwn_stat_grps *igrps, char *page)
242 struct iscsi_tiqn *tiqn = container_of(igrps,
243 struct iscsi_tiqn, tiqn_stat_grps);
245 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
247 ISCSI_STAT_SESS_ERR_ATTR_RO(inst);
249 static ssize_t iscsi_stat_sess_err_show_attr_digest_errors(
250 struct iscsi_wwn_stat_grps *igrps, char *page)
252 struct iscsi_tiqn *tiqn = container_of(igrps,
253 struct iscsi_tiqn, tiqn_stat_grps);
254 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
256 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
258 ISCSI_STAT_SESS_ERR_ATTR_RO(digest_errors);
260 static ssize_t iscsi_stat_sess_err_show_attr_cxn_errors(
261 struct iscsi_wwn_stat_grps *igrps, char *page)
263 struct iscsi_tiqn *tiqn = container_of(igrps,
264 struct iscsi_tiqn, tiqn_stat_grps);
265 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
267 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
269 ISCSI_STAT_SESS_ERR_ATTR_RO(cxn_errors);
271 static ssize_t iscsi_stat_sess_err_show_attr_format_errors(
272 struct iscsi_wwn_stat_grps *igrps, char *page)
274 struct iscsi_tiqn *tiqn = container_of(igrps,
275 struct iscsi_tiqn, tiqn_stat_grps);
276 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
278 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
280 ISCSI_STAT_SESS_ERR_ATTR_RO(format_errors);
282 CONFIGFS_EATTR_OPS(iscsi_stat_sess_err, iscsi_wwn_stat_grps,
283 iscsi_sess_err_group);
285 static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
286 &iscsi_stat_sess_err_inst.attr,
287 &iscsi_stat_sess_err_digest_errors.attr,
288 &iscsi_stat_sess_err_cxn_errors.attr,
289 &iscsi_stat_sess_err_format_errors.attr,
290 NULL,
293 static struct configfs_item_operations iscsi_stat_sess_err_item_ops = {
294 .show_attribute = iscsi_stat_sess_err_attr_show,
295 .store_attribute = iscsi_stat_sess_err_attr_store,
298 struct config_item_type iscsi_stat_sess_err_cit = {
299 .ct_item_ops = &iscsi_stat_sess_err_item_ops,
300 .ct_attrs = iscsi_stat_sess_err_attrs,
301 .ct_owner = THIS_MODULE,
305 * Target Attributes Table
307 CONFIGFS_EATTR_STRUCT(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps);
308 #define ISCSI_STAT_TGT_ATTR(_name, _mode) \
309 static struct iscsi_stat_tgt_attr_attribute \
310 iscsi_stat_tgt_attr_##_name = \
311 __CONFIGFS_EATTR(_name, _mode, \
312 iscsi_stat_tgt-attr_show_attr_##_name, \
313 iscsi_stat_tgt_attr_store_attr_##_name);
315 #define ISCSI_STAT_TGT_ATTR_RO(_name) \
316 static struct iscsi_stat_tgt_attr_attribute \
317 iscsi_stat_tgt_attr_##_name = \
318 __CONFIGFS_EATTR_RO(_name, \
319 iscsi_stat_tgt_attr_show_attr_##_name);
321 static ssize_t iscsi_stat_tgt_attr_show_attr_inst(
322 struct iscsi_wwn_stat_grps *igrps, char *page)
324 struct iscsi_tiqn *tiqn = container_of(igrps,
325 struct iscsi_tiqn, tiqn_stat_grps);
327 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
329 ISCSI_STAT_TGT_ATTR_RO(inst);
331 static ssize_t iscsi_stat_tgt_attr_show_attr_indx(
332 struct iscsi_wwn_stat_grps *igrps, char *page)
334 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
336 ISCSI_STAT_TGT_ATTR_RO(indx);
338 static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails(
339 struct iscsi_wwn_stat_grps *igrps, char *page)
341 struct iscsi_tiqn *tiqn = container_of(igrps,
342 struct iscsi_tiqn, tiqn_stat_grps);
343 struct iscsi_login_stats *lstat = &tiqn->login_stats;
344 u32 fail_count;
346 spin_lock(&lstat->lock);
347 fail_count = (lstat->redirects + lstat->authorize_fails +
348 lstat->authenticate_fails + lstat->negotiate_fails +
349 lstat->other_fails);
350 spin_unlock(&lstat->lock);
352 return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
354 ISCSI_STAT_TGT_ATTR_RO(login_fails);
356 static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time(
357 struct iscsi_wwn_stat_grps *igrps, char *page)
359 struct iscsi_tiqn *tiqn = container_of(igrps,
360 struct iscsi_tiqn, tiqn_stat_grps);
361 struct iscsi_login_stats *lstat = &tiqn->login_stats;
362 u32 last_fail_time;
364 spin_lock(&lstat->lock);
365 last_fail_time = lstat->last_fail_time ?
366 (u32)(((u32)lstat->last_fail_time -
367 INITIAL_JIFFIES) * 100 / HZ) : 0;
368 spin_unlock(&lstat->lock);
370 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
372 ISCSI_STAT_TGT_ATTR_RO(last_fail_time);
374 static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type(
375 struct iscsi_wwn_stat_grps *igrps, char *page)
377 struct iscsi_tiqn *tiqn = container_of(igrps,
378 struct iscsi_tiqn, tiqn_stat_grps);
379 struct iscsi_login_stats *lstat = &tiqn->login_stats;
380 u32 last_fail_type;
382 spin_lock(&lstat->lock);
383 last_fail_type = lstat->last_fail_type;
384 spin_unlock(&lstat->lock);
386 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
388 ISCSI_STAT_TGT_ATTR_RO(last_fail_type);
390 static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name(
391 struct iscsi_wwn_stat_grps *igrps, char *page)
393 struct iscsi_tiqn *tiqn = container_of(igrps,
394 struct iscsi_tiqn, tiqn_stat_grps);
395 struct iscsi_login_stats *lstat = &tiqn->login_stats;
396 unsigned char buf[224];
398 spin_lock(&lstat->lock);
399 snprintf(buf, 224, "%s", lstat->last_intr_fail_name[0] ?
400 lstat->last_intr_fail_name : NONE);
401 spin_unlock(&lstat->lock);
403 return snprintf(page, PAGE_SIZE, "%s\n", buf);
405 ISCSI_STAT_TGT_ATTR_RO(fail_intr_name);
407 static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type(
408 struct iscsi_wwn_stat_grps *igrps, char *page)
410 struct iscsi_tiqn *tiqn = container_of(igrps,
411 struct iscsi_tiqn, tiqn_stat_grps);
412 struct iscsi_login_stats *lstat = &tiqn->login_stats;
413 unsigned char buf[8];
415 spin_lock(&lstat->lock);
416 snprintf(buf, 8, "%s", (lstat->last_intr_fail_ip_addr != NULL) ?
417 "ipv6" : "ipv4");
418 spin_unlock(&lstat->lock);
420 return snprintf(page, PAGE_SIZE, "%s\n", buf);
422 ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr_type);
424 static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr(
425 struct iscsi_wwn_stat_grps *igrps, char *page)
427 struct iscsi_tiqn *tiqn = container_of(igrps,
428 struct iscsi_tiqn, tiqn_stat_grps);
429 struct iscsi_login_stats *lstat = &tiqn->login_stats;
430 unsigned char buf[32];
432 spin_lock(&lstat->lock);
433 if (lstat->last_intr_fail_ip_family == AF_INET6)
434 snprintf(buf, 32, "[%s]", lstat->last_intr_fail_ip_addr);
435 else
436 snprintf(buf, 32, "%s", lstat->last_intr_fail_ip_addr);
437 spin_unlock(&lstat->lock);
439 return snprintf(page, PAGE_SIZE, "%s\n", buf);
441 ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr);
443 CONFIGFS_EATTR_OPS(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps,
444 iscsi_tgt_attr_group);
446 static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
447 &iscsi_stat_tgt_attr_inst.attr,
448 &iscsi_stat_tgt_attr_indx.attr,
449 &iscsi_stat_tgt_attr_login_fails.attr,
450 &iscsi_stat_tgt_attr_last_fail_time.attr,
451 &iscsi_stat_tgt_attr_last_fail_type.attr,
452 &iscsi_stat_tgt_attr_fail_intr_name.attr,
453 &iscsi_stat_tgt_attr_fail_intr_addr_type.attr,
454 &iscsi_stat_tgt_attr_fail_intr_addr.attr,
455 NULL,
458 static struct configfs_item_operations iscsi_stat_tgt_attr_item_ops = {
459 .show_attribute = iscsi_stat_tgt_attr_attr_show,
460 .store_attribute = iscsi_stat_tgt_attr_attr_store,
463 struct config_item_type iscsi_stat_tgt_attr_cit = {
464 .ct_item_ops = &iscsi_stat_tgt_attr_item_ops,
465 .ct_attrs = iscsi_stat_tgt_attr_attrs,
466 .ct_owner = THIS_MODULE,
470 * Target Login Stats Table
472 CONFIGFS_EATTR_STRUCT(iscsi_stat_login, iscsi_wwn_stat_grps);
473 #define ISCSI_STAT_LOGIN(_name, _mode) \
474 static struct iscsi_stat_login_attribute \
475 iscsi_stat_login_##_name = \
476 __CONFIGFS_EATTR(_name, _mode, \
477 iscsi_stat_login_show_attr_##_name, \
478 iscsi_stat_login_store_attr_##_name);
480 #define ISCSI_STAT_LOGIN_RO(_name) \
481 static struct iscsi_stat_login_attribute \
482 iscsi_stat_login_##_name = \
483 __CONFIGFS_EATTR_RO(_name, \
484 iscsi_stat_login_show_attr_##_name);
486 static ssize_t iscsi_stat_login_show_attr_inst(
487 struct iscsi_wwn_stat_grps *igrps, char *page)
489 struct iscsi_tiqn *tiqn = container_of(igrps,
490 struct iscsi_tiqn, tiqn_stat_grps);
492 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
494 ISCSI_STAT_LOGIN_RO(inst);
496 static ssize_t iscsi_stat_login_show_attr_indx(
497 struct iscsi_wwn_stat_grps *igrps, char *page)
499 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
501 ISCSI_STAT_LOGIN_RO(indx);
503 static ssize_t iscsi_stat_login_show_attr_accepts(
504 struct iscsi_wwn_stat_grps *igrps, char *page)
506 struct iscsi_tiqn *tiqn = container_of(igrps,
507 struct iscsi_tiqn, tiqn_stat_grps);
508 struct iscsi_login_stats *lstat = &tiqn->login_stats;
509 ssize_t ret;
511 spin_lock(&lstat->lock);
512 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
513 spin_unlock(&lstat->lock);
515 return ret;
517 ISCSI_STAT_LOGIN_RO(accepts);
519 static ssize_t iscsi_stat_login_show_attr_other_fails(
520 struct iscsi_wwn_stat_grps *igrps, char *page)
522 struct iscsi_tiqn *tiqn = container_of(igrps,
523 struct iscsi_tiqn, tiqn_stat_grps);
524 struct iscsi_login_stats *lstat = &tiqn->login_stats;
525 ssize_t ret;
527 spin_lock(&lstat->lock);
528 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
529 spin_unlock(&lstat->lock);
531 return ret;
533 ISCSI_STAT_LOGIN_RO(other_fails);
535 static ssize_t iscsi_stat_login_show_attr_redirects(
536 struct iscsi_wwn_stat_grps *igrps, char *page)
538 struct iscsi_tiqn *tiqn = container_of(igrps,
539 struct iscsi_tiqn, tiqn_stat_grps);
540 struct iscsi_login_stats *lstat = &tiqn->login_stats;
541 ssize_t ret;
543 spin_lock(&lstat->lock);
544 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
545 spin_unlock(&lstat->lock);
547 return ret;
549 ISCSI_STAT_LOGIN_RO(redirects);
551 static ssize_t iscsi_stat_login_show_attr_authorize_fails(
552 struct iscsi_wwn_stat_grps *igrps, char *page)
554 struct iscsi_tiqn *tiqn = container_of(igrps,
555 struct iscsi_tiqn, tiqn_stat_grps);
556 struct iscsi_login_stats *lstat = &tiqn->login_stats;
557 ssize_t ret;
559 spin_lock(&lstat->lock);
560 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
561 spin_unlock(&lstat->lock);
563 return ret;
565 ISCSI_STAT_LOGIN_RO(authorize_fails);
567 static ssize_t iscsi_stat_login_show_attr_authenticate_fails(
568 struct iscsi_wwn_stat_grps *igrps, char *page)
570 struct iscsi_tiqn *tiqn = container_of(igrps,
571 struct iscsi_tiqn, tiqn_stat_grps);
572 struct iscsi_login_stats *lstat = &tiqn->login_stats;
573 ssize_t ret;
575 spin_lock(&lstat->lock);
576 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
577 spin_unlock(&lstat->lock);
579 return ret;
581 ISCSI_STAT_LOGIN_RO(authenticate_fails);
583 static ssize_t iscsi_stat_login_show_attr_negotiate_fails(
584 struct iscsi_wwn_stat_grps *igrps, char *page)
586 struct iscsi_tiqn *tiqn = container_of(igrps,
587 struct iscsi_tiqn, tiqn_stat_grps);
588 struct iscsi_login_stats *lstat = &tiqn->login_stats;
589 ssize_t ret;
591 spin_lock(&lstat->lock);
592 ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
593 spin_unlock(&lstat->lock);
595 return ret;
597 ISCSI_STAT_LOGIN_RO(negotiate_fails);
599 CONFIGFS_EATTR_OPS(iscsi_stat_login, iscsi_wwn_stat_grps,
600 iscsi_login_stats_group);
602 static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
603 &iscsi_stat_login_inst.attr,
604 &iscsi_stat_login_indx.attr,
605 &iscsi_stat_login_accepts.attr,
606 &iscsi_stat_login_other_fails.attr,
607 &iscsi_stat_login_redirects.attr,
608 &iscsi_stat_login_authorize_fails.attr,
609 &iscsi_stat_login_authenticate_fails.attr,
610 &iscsi_stat_login_negotiate_fails.attr,
611 NULL,
614 static struct configfs_item_operations iscsi_stat_login_stats_item_ops = {
615 .show_attribute = iscsi_stat_login_attr_show,
616 .store_attribute = iscsi_stat_login_attr_store,
619 struct config_item_type iscsi_stat_login_cit = {
620 .ct_item_ops = &iscsi_stat_login_stats_item_ops,
621 .ct_attrs = iscsi_stat_login_stats_attrs,
622 .ct_owner = THIS_MODULE,
626 * Target Logout Stats Table
629 CONFIGFS_EATTR_STRUCT(iscsi_stat_logout, iscsi_wwn_stat_grps);
630 #define ISCSI_STAT_LOGOUT(_name, _mode) \
631 static struct iscsi_stat_logout_attribute \
632 iscsi_stat_logout_##_name = \
633 __CONFIGFS_EATTR(_name, _mode, \
634 iscsi_stat_logout_show_attr_##_name, \
635 iscsi_stat_logout_store_attr_##_name);
637 #define ISCSI_STAT_LOGOUT_RO(_name) \
638 static struct iscsi_stat_logout_attribute \
639 iscsi_stat_logout_##_name = \
640 __CONFIGFS_EATTR_RO(_name, \
641 iscsi_stat_logout_show_attr_##_name);
643 static ssize_t iscsi_stat_logout_show_attr_inst(
644 struct iscsi_wwn_stat_grps *igrps, char *page)
646 struct iscsi_tiqn *tiqn = container_of(igrps,
647 struct iscsi_tiqn, tiqn_stat_grps);
649 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
651 ISCSI_STAT_LOGOUT_RO(inst);
653 static ssize_t iscsi_stat_logout_show_attr_indx(
654 struct iscsi_wwn_stat_grps *igrps, char *page)
656 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
658 ISCSI_STAT_LOGOUT_RO(indx);
660 static ssize_t iscsi_stat_logout_show_attr_normal_logouts(
661 struct iscsi_wwn_stat_grps *igrps, char *page)
663 struct iscsi_tiqn *tiqn = container_of(igrps,
664 struct iscsi_tiqn, tiqn_stat_grps);
665 struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
667 return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
669 ISCSI_STAT_LOGOUT_RO(normal_logouts);
671 static ssize_t iscsi_stat_logout_show_attr_abnormal_logouts(
672 struct iscsi_wwn_stat_grps *igrps, char *page)
674 struct iscsi_tiqn *tiqn = container_of(igrps,
675 struct iscsi_tiqn, tiqn_stat_grps);
676 struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
678 return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
680 ISCSI_STAT_LOGOUT_RO(abnormal_logouts);
682 CONFIGFS_EATTR_OPS(iscsi_stat_logout, iscsi_wwn_stat_grps,
683 iscsi_logout_stats_group);
685 static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
686 &iscsi_stat_logout_inst.attr,
687 &iscsi_stat_logout_indx.attr,
688 &iscsi_stat_logout_normal_logouts.attr,
689 &iscsi_stat_logout_abnormal_logouts.attr,
690 NULL,
693 static struct configfs_item_operations iscsi_stat_logout_stats_item_ops = {
694 .show_attribute = iscsi_stat_logout_attr_show,
695 .store_attribute = iscsi_stat_logout_attr_store,
698 struct config_item_type iscsi_stat_logout_cit = {
699 .ct_item_ops = &iscsi_stat_logout_stats_item_ops,
700 .ct_attrs = iscsi_stat_logout_stats_attrs,
701 .ct_owner = THIS_MODULE,
705 * Session Stats Table
708 CONFIGFS_EATTR_STRUCT(iscsi_stat_sess, iscsi_node_stat_grps);
709 #define ISCSI_STAT_SESS(_name, _mode) \
710 static struct iscsi_stat_sess_attribute \
711 iscsi_stat_sess_##_name = \
712 __CONFIGFS_EATTR(_name, _mode, \
713 iscsi_stat_sess_show_attr_##_name, \
714 iscsi_stat_sess_store_attr_##_name);
716 #define ISCSI_STAT_SESS_RO(_name) \
717 static struct iscsi_stat_sess_attribute \
718 iscsi_stat_sess_##_name = \
719 __CONFIGFS_EATTR_RO(_name, \
720 iscsi_stat_sess_show_attr_##_name);
722 static ssize_t iscsi_stat_sess_show_attr_inst(
723 struct iscsi_node_stat_grps *igrps, char *page)
725 struct iscsi_node_acl *acl = container_of(igrps,
726 struct iscsi_node_acl, node_stat_grps);
727 struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
728 struct iscsi_tiqn *tiqn = container_of(wwn,
729 struct iscsi_tiqn, tiqn_wwn);
731 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
733 ISCSI_STAT_SESS_RO(inst);
735 static ssize_t iscsi_stat_sess_show_attr_node(
736 struct iscsi_node_stat_grps *igrps, char *page)
738 struct iscsi_node_acl *acl = container_of(igrps,
739 struct iscsi_node_acl, node_stat_grps);
740 struct se_node_acl *se_nacl = &acl->se_node_acl;
741 struct iscsi_session *sess;
742 struct se_session *se_sess;
743 ssize_t ret = 0;
745 spin_lock_bh(&se_nacl->nacl_sess_lock);
746 se_sess = se_nacl->nacl_sess;
747 if (se_sess) {
748 sess = se_sess->fabric_sess_ptr;
749 if (sess)
750 ret = snprintf(page, PAGE_SIZE, "%u\n",
751 sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
753 spin_unlock_bh(&se_nacl->nacl_sess_lock);
755 return ret;
757 ISCSI_STAT_SESS_RO(node);
759 static ssize_t iscsi_stat_sess_show_attr_indx(
760 struct iscsi_node_stat_grps *igrps, char *page)
762 struct iscsi_node_acl *acl = container_of(igrps,
763 struct iscsi_node_acl, node_stat_grps);
764 struct se_node_acl *se_nacl = &acl->se_node_acl;
765 struct iscsi_session *sess;
766 struct se_session *se_sess;
767 ssize_t ret = 0;
769 spin_lock_bh(&se_nacl->nacl_sess_lock);
770 se_sess = se_nacl->nacl_sess;
771 if (se_sess) {
772 sess = se_sess->fabric_sess_ptr;
773 if (sess)
774 ret = snprintf(page, PAGE_SIZE, "%u\n",
775 sess->session_index);
777 spin_unlock_bh(&se_nacl->nacl_sess_lock);
779 return ret;
781 ISCSI_STAT_SESS_RO(indx);
783 static ssize_t iscsi_stat_sess_show_attr_cmd_pdus(
784 struct iscsi_node_stat_grps *igrps, char *page)
786 struct iscsi_node_acl *acl = container_of(igrps,
787 struct iscsi_node_acl, node_stat_grps);
788 struct se_node_acl *se_nacl = &acl->se_node_acl;
789 struct iscsi_session *sess;
790 struct se_session *se_sess;
791 ssize_t ret = 0;
793 spin_lock_bh(&se_nacl->nacl_sess_lock);
794 se_sess = se_nacl->nacl_sess;
795 if (se_sess) {
796 sess = se_sess->fabric_sess_ptr;
797 if (sess)
798 ret = snprintf(page, PAGE_SIZE, "%u\n", sess->cmd_pdus);
800 spin_unlock_bh(&se_nacl->nacl_sess_lock);
802 return ret;
804 ISCSI_STAT_SESS_RO(cmd_pdus);
806 static ssize_t iscsi_stat_sess_show_attr_rsp_pdus(
807 struct iscsi_node_stat_grps *igrps, char *page)
809 struct iscsi_node_acl *acl = container_of(igrps,
810 struct iscsi_node_acl, node_stat_grps);
811 struct se_node_acl *se_nacl = &acl->se_node_acl;
812 struct iscsi_session *sess;
813 struct se_session *se_sess;
814 ssize_t ret = 0;
816 spin_lock_bh(&se_nacl->nacl_sess_lock);
817 se_sess = se_nacl->nacl_sess;
818 if (se_sess) {
819 sess = se_sess->fabric_sess_ptr;
820 if (sess)
821 ret = snprintf(page, PAGE_SIZE, "%u\n", sess->rsp_pdus);
823 spin_unlock_bh(&se_nacl->nacl_sess_lock);
825 return ret;
827 ISCSI_STAT_SESS_RO(rsp_pdus);
829 static ssize_t iscsi_stat_sess_show_attr_txdata_octs(
830 struct iscsi_node_stat_grps *igrps, char *page)
832 struct iscsi_node_acl *acl = container_of(igrps,
833 struct iscsi_node_acl, node_stat_grps);
834 struct se_node_acl *se_nacl = &acl->se_node_acl;
835 struct iscsi_session *sess;
836 struct se_session *se_sess;
837 ssize_t ret = 0;
839 spin_lock_bh(&se_nacl->nacl_sess_lock);
840 se_sess = se_nacl->nacl_sess;
841 if (se_sess) {
842 sess = se_sess->fabric_sess_ptr;
843 if (sess)
844 ret = snprintf(page, PAGE_SIZE, "%llu\n",
845 (unsigned long long)sess->tx_data_octets);
847 spin_unlock_bh(&se_nacl->nacl_sess_lock);
849 return ret;
851 ISCSI_STAT_SESS_RO(txdata_octs);
853 static ssize_t iscsi_stat_sess_show_attr_rxdata_octs(
854 struct iscsi_node_stat_grps *igrps, char *page)
856 struct iscsi_node_acl *acl = container_of(igrps,
857 struct iscsi_node_acl, node_stat_grps);
858 struct se_node_acl *se_nacl = &acl->se_node_acl;
859 struct iscsi_session *sess;
860 struct se_session *se_sess;
861 ssize_t ret = 0;
863 spin_lock_bh(&se_nacl->nacl_sess_lock);
864 se_sess = se_nacl->nacl_sess;
865 if (se_sess) {
866 sess = se_sess->fabric_sess_ptr;
867 if (sess)
868 ret = snprintf(page, PAGE_SIZE, "%llu\n",
869 (unsigned long long)sess->rx_data_octets);
871 spin_unlock_bh(&se_nacl->nacl_sess_lock);
873 return ret;
875 ISCSI_STAT_SESS_RO(rxdata_octs);
877 static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors(
878 struct iscsi_node_stat_grps *igrps, char *page)
880 struct iscsi_node_acl *acl = container_of(igrps,
881 struct iscsi_node_acl, node_stat_grps);
882 struct se_node_acl *se_nacl = &acl->se_node_acl;
883 struct iscsi_session *sess;
884 struct se_session *se_sess;
885 ssize_t ret = 0;
887 spin_lock_bh(&se_nacl->nacl_sess_lock);
888 se_sess = se_nacl->nacl_sess;
889 if (se_sess) {
890 sess = se_sess->fabric_sess_ptr;
891 if (sess)
892 ret = snprintf(page, PAGE_SIZE, "%u\n",
893 sess->conn_digest_errors);
895 spin_unlock_bh(&se_nacl->nacl_sess_lock);
897 return ret;
899 ISCSI_STAT_SESS_RO(conn_digest_errors);
901 static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors(
902 struct iscsi_node_stat_grps *igrps, char *page)
904 struct iscsi_node_acl *acl = container_of(igrps,
905 struct iscsi_node_acl, node_stat_grps);
906 struct se_node_acl *se_nacl = &acl->se_node_acl;
907 struct iscsi_session *sess;
908 struct se_session *se_sess;
909 ssize_t ret = 0;
911 spin_lock_bh(&se_nacl->nacl_sess_lock);
912 se_sess = se_nacl->nacl_sess;
913 if (se_sess) {
914 sess = se_sess->fabric_sess_ptr;
915 if (sess)
916 ret = snprintf(page, PAGE_SIZE, "%u\n",
917 sess->conn_timeout_errors);
919 spin_unlock_bh(&se_nacl->nacl_sess_lock);
921 return ret;
923 ISCSI_STAT_SESS_RO(conn_timeout_errors);
925 CONFIGFS_EATTR_OPS(iscsi_stat_sess, iscsi_node_stat_grps,
926 iscsi_sess_stats_group);
928 static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
929 &iscsi_stat_sess_inst.attr,
930 &iscsi_stat_sess_node.attr,
931 &iscsi_stat_sess_indx.attr,
932 &iscsi_stat_sess_cmd_pdus.attr,
933 &iscsi_stat_sess_rsp_pdus.attr,
934 &iscsi_stat_sess_txdata_octs.attr,
935 &iscsi_stat_sess_rxdata_octs.attr,
936 &iscsi_stat_sess_conn_digest_errors.attr,
937 &iscsi_stat_sess_conn_timeout_errors.attr,
938 NULL,
941 static struct configfs_item_operations iscsi_stat_sess_stats_item_ops = {
942 .show_attribute = iscsi_stat_sess_attr_show,
943 .store_attribute = iscsi_stat_sess_attr_store,
946 struct config_item_type iscsi_stat_sess_cit = {
947 .ct_item_ops = &iscsi_stat_sess_stats_item_ops,
948 .ct_attrs = iscsi_stat_sess_stats_attrs,
949 .ct_owner = THIS_MODULE,