18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*******************************************************************************
38c2ecf20Sopenharmony_ci * Modern ConfigFS group context specific iSCSI statistics based on original
48c2ecf20Sopenharmony_ci * iscsi_target_mib.c code
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (c) 2011-2013 Datera, Inc.
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * Author: Nicholas A. Bellinger <nab@linux-iscsi.org>
98c2ecf20Sopenharmony_ci *
108c2ecf20Sopenharmony_ci ******************************************************************************/
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/configfs.h>
138c2ecf20Sopenharmony_ci#include <linux/export.h>
148c2ecf20Sopenharmony_ci#include <scsi/iscsi_proto.h>
158c2ecf20Sopenharmony_ci#include <target/target_core_base.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <target/iscsi/iscsi_target_core.h>
188c2ecf20Sopenharmony_ci#include "iscsi_target_parameters.h"
198c2ecf20Sopenharmony_ci#include "iscsi_target_device.h"
208c2ecf20Sopenharmony_ci#include "iscsi_target_tpg.h"
218c2ecf20Sopenharmony_ci#include "iscsi_target_util.h"
228c2ecf20Sopenharmony_ci#include <target/iscsi/iscsi_target_stat.h>
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#ifndef INITIAL_JIFFIES
258c2ecf20Sopenharmony_ci#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
268c2ecf20Sopenharmony_ci#endif
278c2ecf20Sopenharmony_ci
288c2ecf20Sopenharmony_ci/* Instance Attributes Table */
298c2ecf20Sopenharmony_ci#define ISCSI_INST_NUM_NODES		1
308c2ecf20Sopenharmony_ci#define ISCSI_INST_DESCR		"Storage Engine Target"
318c2ecf20Sopenharmony_ci#define ISCSI_INST_LAST_FAILURE_TYPE	0
328c2ecf20Sopenharmony_ci#define ISCSI_DISCONTINUITY_TIME	0
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#define ISCSI_NODE_INDEX		1
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci#define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_ci/****************************************************************************
398c2ecf20Sopenharmony_ci * iSCSI MIB Tables
408c2ecf20Sopenharmony_ci ****************************************************************************/
418c2ecf20Sopenharmony_ci/*
428c2ecf20Sopenharmony_ci * Instance Attributes Table
438c2ecf20Sopenharmony_ci */
448c2ecf20Sopenharmony_cistatic struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item)
458c2ecf20Sopenharmony_ci{
468c2ecf20Sopenharmony_ci	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
478c2ecf20Sopenharmony_ci			struct iscsi_wwn_stat_grps, iscsi_instance_group);
488c2ecf20Sopenharmony_ci	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
498c2ecf20Sopenharmony_ci}
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_inst_show(struct config_item *item,
528c2ecf20Sopenharmony_ci		char *page)
538c2ecf20Sopenharmony_ci{
548c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
558c2ecf20Sopenharmony_ci			iscsi_instance_tiqn(item)->tiqn_index);
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item,
598c2ecf20Sopenharmony_ci		char *page)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item,
658c2ecf20Sopenharmony_ci		char *page)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_portals_show(struct config_item *item,
718c2ecf20Sopenharmony_ci		char *page)
728c2ecf20Sopenharmony_ci{
738c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
748c2ecf20Sopenharmony_ci			iscsi_instance_tiqn(item)->tiqn_num_tpg_nps);
758c2ecf20Sopenharmony_ci}
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_nodes_show(struct config_item *item,
788c2ecf20Sopenharmony_ci		char *page)
798c2ecf20Sopenharmony_ci{
808c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
818c2ecf20Sopenharmony_ci}
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_sessions_show(struct config_item *item,
848c2ecf20Sopenharmony_ci		char *page)
858c2ecf20Sopenharmony_ci{
868c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
878c2ecf20Sopenharmony_ci		iscsi_instance_tiqn(item)->tiqn_nsessions);
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item,
918c2ecf20Sopenharmony_ci		char *page)
928c2ecf20Sopenharmony_ci{
938c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
948c2ecf20Sopenharmony_ci	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
958c2ecf20Sopenharmony_ci	u32 sess_err_count;
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	spin_lock_bh(&sess_err->lock);
988c2ecf20Sopenharmony_ci	sess_err_count = (sess_err->digest_errors +
998c2ecf20Sopenharmony_ci			  sess_err->cxn_timeout_errors +
1008c2ecf20Sopenharmony_ci			  sess_err->pdu_format_errors);
1018c2ecf20Sopenharmony_ci	spin_unlock_bh(&sess_err->lock);
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
1078c2ecf20Sopenharmony_ci		char *page)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
1108c2ecf20Sopenharmony_ci	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
1138c2ecf20Sopenharmony_ci			sess_err->last_sess_failure_type);
1148c2ecf20Sopenharmony_ci}
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
1178c2ecf20Sopenharmony_ci		char *page)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
1208c2ecf20Sopenharmony_ci	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%s\n",
1238c2ecf20Sopenharmony_ci			sess_err->last_sess_fail_rem_name[0] ?
1248c2ecf20Sopenharmony_ci			sess_err->last_sess_fail_rem_name : NONE);
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item,
1288c2ecf20Sopenharmony_ci		char *page)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
1318c2ecf20Sopenharmony_ci}
1328c2ecf20Sopenharmony_ci
1338c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_description_show(struct config_item *item,
1348c2ecf20Sopenharmony_ci		char *page)
1358c2ecf20Sopenharmony_ci{
1368c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
1378c2ecf20Sopenharmony_ci}
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_vendor_show(struct config_item *item,
1408c2ecf20Sopenharmony_ci		char *page)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_instance_version_show(struct config_item *item,
1468c2ecf20Sopenharmony_ci		char *page)
1478c2ecf20Sopenharmony_ci{
1488c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, inst);
1528c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, min_ver);
1538c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, max_ver);
1548c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, portals);
1558c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, nodes);
1568c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, sessions);
1578c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_sess);
1588c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_type);
1598c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_rem_name);
1608c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, disc_time);
1618c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, description);
1628c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, vendor);
1638c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_instance_, version);
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_cistatic struct configfs_attribute *iscsi_stat_instance_attrs[] = {
1668c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_inst,
1678c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_min_ver,
1688c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_max_ver,
1698c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_portals,
1708c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_nodes,
1718c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_sessions,
1728c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_fail_sess,
1738c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_fail_type,
1748c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_fail_rem_name,
1758c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_disc_time,
1768c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_description,
1778c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_vendor,
1788c2ecf20Sopenharmony_ci	&iscsi_stat_instance_attr_version,
1798c2ecf20Sopenharmony_ci	NULL,
1808c2ecf20Sopenharmony_ci};
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ciconst struct config_item_type iscsi_stat_instance_cit = {
1838c2ecf20Sopenharmony_ci	.ct_attrs		= iscsi_stat_instance_attrs,
1848c2ecf20Sopenharmony_ci	.ct_owner		= THIS_MODULE,
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci/*
1888c2ecf20Sopenharmony_ci * Instance Session Failure Stats Table
1898c2ecf20Sopenharmony_ci */
1908c2ecf20Sopenharmony_cistatic struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
1938c2ecf20Sopenharmony_ci			struct iscsi_wwn_stat_grps, iscsi_sess_err_group);
1948c2ecf20Sopenharmony_ci	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
1958c2ecf20Sopenharmony_ci}
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item,
1988c2ecf20Sopenharmony_ci		char *page)
1998c2ecf20Sopenharmony_ci{
2008c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
2018c2ecf20Sopenharmony_ci		iscsi_sess_err_tiqn(item)->tiqn_index);
2028c2ecf20Sopenharmony_ci}
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item,
2058c2ecf20Sopenharmony_ci		char *page)
2068c2ecf20Sopenharmony_ci{
2078c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
2088c2ecf20Sopenharmony_ci	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
2118c2ecf20Sopenharmony_ci}
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item,
2148c2ecf20Sopenharmony_ci		char *page)
2158c2ecf20Sopenharmony_ci{
2168c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
2178c2ecf20Sopenharmony_ci	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
2208c2ecf20Sopenharmony_ci}
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
2238c2ecf20Sopenharmony_ci		char *page)
2248c2ecf20Sopenharmony_ci{
2258c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
2268c2ecf20Sopenharmony_ci	struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
2298c2ecf20Sopenharmony_ci}
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst);
2328c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_err_, digest_errors);
2338c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_err_, cxn_errors);
2348c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_err_, format_errors);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_cistatic struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
2378c2ecf20Sopenharmony_ci	&iscsi_stat_sess_err_attr_inst,
2388c2ecf20Sopenharmony_ci	&iscsi_stat_sess_err_attr_digest_errors,
2398c2ecf20Sopenharmony_ci	&iscsi_stat_sess_err_attr_cxn_errors,
2408c2ecf20Sopenharmony_ci	&iscsi_stat_sess_err_attr_format_errors,
2418c2ecf20Sopenharmony_ci	NULL,
2428c2ecf20Sopenharmony_ci};
2438c2ecf20Sopenharmony_ci
2448c2ecf20Sopenharmony_ciconst struct config_item_type iscsi_stat_sess_err_cit = {
2458c2ecf20Sopenharmony_ci	.ct_attrs		= iscsi_stat_sess_err_attrs,
2468c2ecf20Sopenharmony_ci	.ct_owner		= THIS_MODULE,
2478c2ecf20Sopenharmony_ci};
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci/*
2508c2ecf20Sopenharmony_ci * Target Attributes Table
2518c2ecf20Sopenharmony_ci */
2528c2ecf20Sopenharmony_cistatic struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item)
2538c2ecf20Sopenharmony_ci{
2548c2ecf20Sopenharmony_ci	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
2558c2ecf20Sopenharmony_ci			struct iscsi_wwn_stat_grps, iscsi_tgt_attr_group);
2568c2ecf20Sopenharmony_ci	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
2578c2ecf20Sopenharmony_ci}
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item,
2608c2ecf20Sopenharmony_ci		char *page)
2618c2ecf20Sopenharmony_ci{
2628c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
2638c2ecf20Sopenharmony_ci			iscsi_tgt_attr_tiqn(item)->tiqn_index);
2648c2ecf20Sopenharmony_ci}
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item,
2678c2ecf20Sopenharmony_ci		char *page)
2688c2ecf20Sopenharmony_ci{
2698c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
2708c2ecf20Sopenharmony_ci}
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
2738c2ecf20Sopenharmony_ci		char *page)
2748c2ecf20Sopenharmony_ci{
2758c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
2768c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
2778c2ecf20Sopenharmony_ci	u32 fail_count;
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
2808c2ecf20Sopenharmony_ci	fail_count = (lstat->redirects + lstat->authorize_fails +
2818c2ecf20Sopenharmony_ci			lstat->authenticate_fails + lstat->negotiate_fails +
2828c2ecf20Sopenharmony_ci			lstat->other_fails);
2838c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
2868c2ecf20Sopenharmony_ci}
2878c2ecf20Sopenharmony_ci
2888c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
2898c2ecf20Sopenharmony_ci		char *page)
2908c2ecf20Sopenharmony_ci{
2918c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
2928c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
2938c2ecf20Sopenharmony_ci	u32 last_fail_time;
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
2968c2ecf20Sopenharmony_ci	last_fail_time = lstat->last_fail_time ?
2978c2ecf20Sopenharmony_ci			(u32)(((u32)lstat->last_fail_time -
2988c2ecf20Sopenharmony_ci				INITIAL_JIFFIES) * 100 / HZ) : 0;
2998c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
3008c2ecf20Sopenharmony_ci
3018c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
3028c2ecf20Sopenharmony_ci}
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
3058c2ecf20Sopenharmony_ci		char *page)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
3088c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
3098c2ecf20Sopenharmony_ci	u32 last_fail_type;
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
3128c2ecf20Sopenharmony_ci	last_fail_type = lstat->last_fail_type;
3138c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
3148c2ecf20Sopenharmony_ci
3158c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
3168c2ecf20Sopenharmony_ci}
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
3198c2ecf20Sopenharmony_ci		char *page)
3208c2ecf20Sopenharmony_ci{
3218c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
3228c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
3238c2ecf20Sopenharmony_ci	unsigned char buf[ISCSI_IQN_LEN];
3248c2ecf20Sopenharmony_ci
3258c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
3268c2ecf20Sopenharmony_ci	snprintf(buf, ISCSI_IQN_LEN, "%s", lstat->last_intr_fail_name[0] ?
3278c2ecf20Sopenharmony_ci				lstat->last_intr_fail_name : NONE);
3288c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%s\n", buf);
3318c2ecf20Sopenharmony_ci}
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item,
3348c2ecf20Sopenharmony_ci		char *page)
3358c2ecf20Sopenharmony_ci{
3368c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
3378c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
3388c2ecf20Sopenharmony_ci	int ret;
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
3418c2ecf20Sopenharmony_ci	if (lstat->last_intr_fail_ip_family == AF_INET6)
3428c2ecf20Sopenharmony_ci		ret = snprintf(page, PAGE_SIZE, "ipv6\n");
3438c2ecf20Sopenharmony_ci	else
3448c2ecf20Sopenharmony_ci		ret = snprintf(page, PAGE_SIZE, "ipv4\n");
3458c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ci	return ret;
3488c2ecf20Sopenharmony_ci}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item,
3518c2ecf20Sopenharmony_ci		char *page)
3528c2ecf20Sopenharmony_ci{
3538c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
3548c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
3558c2ecf20Sopenharmony_ci	int ret;
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
3588c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%pISc\n", &lstat->last_intr_fail_sockaddr);
3598c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci	return ret;
3628c2ecf20Sopenharmony_ci}
3638c2ecf20Sopenharmony_ci
3648c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, inst);
3658c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, indx);
3668c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, login_fails);
3678c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_time);
3688c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_type);
3698c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_name);
3708c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr_type);
3718c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr);
3728c2ecf20Sopenharmony_ci
3738c2ecf20Sopenharmony_cistatic struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
3748c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_inst,
3758c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_indx,
3768c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_login_fails,
3778c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_last_fail_time,
3788c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_last_fail_type,
3798c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_fail_intr_name,
3808c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_fail_intr_addr_type,
3818c2ecf20Sopenharmony_ci	&iscsi_stat_tgt_attr_attr_fail_intr_addr,
3828c2ecf20Sopenharmony_ci	NULL,
3838c2ecf20Sopenharmony_ci};
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ciconst struct config_item_type iscsi_stat_tgt_attr_cit = {
3868c2ecf20Sopenharmony_ci	.ct_attrs		= iscsi_stat_tgt_attr_attrs,
3878c2ecf20Sopenharmony_ci	.ct_owner		= THIS_MODULE,
3888c2ecf20Sopenharmony_ci};
3898c2ecf20Sopenharmony_ci
3908c2ecf20Sopenharmony_ci/*
3918c2ecf20Sopenharmony_ci * Target Login Stats Table
3928c2ecf20Sopenharmony_ci */
3938c2ecf20Sopenharmony_cistatic struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item)
3948c2ecf20Sopenharmony_ci{
3958c2ecf20Sopenharmony_ci	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
3968c2ecf20Sopenharmony_ci			struct iscsi_wwn_stat_grps, iscsi_login_stats_group);
3978c2ecf20Sopenharmony_ci	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
3988c2ecf20Sopenharmony_ci}
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page)
4018c2ecf20Sopenharmony_ci{
4028c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
4038c2ecf20Sopenharmony_ci		iscsi_login_stat_tiqn(item)->tiqn_index);
4048c2ecf20Sopenharmony_ci}
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_indx_show(struct config_item *item,
4078c2ecf20Sopenharmony_ci		char *page)
4088c2ecf20Sopenharmony_ci{
4098c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
4108c2ecf20Sopenharmony_ci}
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
4138c2ecf20Sopenharmony_ci		char *page)
4148c2ecf20Sopenharmony_ci{
4158c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
4168c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4178c2ecf20Sopenharmony_ci	ssize_t ret;
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
4208c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->accepts);
4218c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
4228c2ecf20Sopenharmony_ci
4238c2ecf20Sopenharmony_ci	return ret;
4248c2ecf20Sopenharmony_ci}
4258c2ecf20Sopenharmony_ci
4268c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_other_fails_show(struct config_item *item,
4278c2ecf20Sopenharmony_ci		char *page)
4288c2ecf20Sopenharmony_ci{
4298c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
4308c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4318c2ecf20Sopenharmony_ci	ssize_t ret;
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
4348c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->other_fails);
4358c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	return ret;
4388c2ecf20Sopenharmony_ci}
4398c2ecf20Sopenharmony_ci
4408c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_redirects_show(struct config_item *item,
4418c2ecf20Sopenharmony_ci		char *page)
4428c2ecf20Sopenharmony_ci{
4438c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
4448c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4458c2ecf20Sopenharmony_ci	ssize_t ret;
4468c2ecf20Sopenharmony_ci
4478c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
4488c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->redirects);
4498c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	return ret;
4528c2ecf20Sopenharmony_ci}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item,
4558c2ecf20Sopenharmony_ci		char *page)
4568c2ecf20Sopenharmony_ci{
4578c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
4588c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4598c2ecf20Sopenharmony_ci	ssize_t ret;
4608c2ecf20Sopenharmony_ci
4618c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
4628c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authorize_fails);
4638c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
4648c2ecf20Sopenharmony_ci
4658c2ecf20Sopenharmony_ci	return ret;
4668c2ecf20Sopenharmony_ci}
4678c2ecf20Sopenharmony_ci
4688c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_authenticate_fails_show(
4698c2ecf20Sopenharmony_ci		struct config_item *item, char *page)
4708c2ecf20Sopenharmony_ci{
4718c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
4728c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4738c2ecf20Sopenharmony_ci	ssize_t ret;
4748c2ecf20Sopenharmony_ci
4758c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
4768c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->authenticate_fails);
4778c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_ci	return ret;
4808c2ecf20Sopenharmony_ci}
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item,
4838c2ecf20Sopenharmony_ci		char *page)
4848c2ecf20Sopenharmony_ci{
4858c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
4868c2ecf20Sopenharmony_ci	struct iscsi_login_stats *lstat = &tiqn->login_stats;
4878c2ecf20Sopenharmony_ci	ssize_t ret;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci	spin_lock(&lstat->lock);
4908c2ecf20Sopenharmony_ci	ret = snprintf(page, PAGE_SIZE, "%u\n", lstat->negotiate_fails);
4918c2ecf20Sopenharmony_ci	spin_unlock(&lstat->lock);
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	return ret;
4948c2ecf20Sopenharmony_ci}
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, inst);
4978c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, indx);
4988c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, accepts);
4998c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, other_fails);
5008c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, redirects);
5018c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, authorize_fails);
5028c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, authenticate_fails);
5038c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_login_, negotiate_fails);
5048c2ecf20Sopenharmony_ci
5058c2ecf20Sopenharmony_cistatic struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
5068c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_inst,
5078c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_indx,
5088c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_accepts,
5098c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_other_fails,
5108c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_redirects,
5118c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_authorize_fails,
5128c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_authenticate_fails,
5138c2ecf20Sopenharmony_ci	&iscsi_stat_login_attr_negotiate_fails,
5148c2ecf20Sopenharmony_ci	NULL,
5158c2ecf20Sopenharmony_ci};
5168c2ecf20Sopenharmony_ci
5178c2ecf20Sopenharmony_ciconst struct config_item_type iscsi_stat_login_cit = {
5188c2ecf20Sopenharmony_ci	.ct_attrs		= iscsi_stat_login_stats_attrs,
5198c2ecf20Sopenharmony_ci	.ct_owner		= THIS_MODULE,
5208c2ecf20Sopenharmony_ci};
5218c2ecf20Sopenharmony_ci
5228c2ecf20Sopenharmony_ci/*
5238c2ecf20Sopenharmony_ci * Target Logout Stats Table
5248c2ecf20Sopenharmony_ci */
5258c2ecf20Sopenharmony_cistatic struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item)
5268c2ecf20Sopenharmony_ci{
5278c2ecf20Sopenharmony_ci	struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
5288c2ecf20Sopenharmony_ci			struct iscsi_wwn_stat_grps, iscsi_logout_stats_group);
5298c2ecf20Sopenharmony_ci	return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
5308c2ecf20Sopenharmony_ci}
5318c2ecf20Sopenharmony_ci
5328c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page)
5338c2ecf20Sopenharmony_ci{
5348c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n",
5358c2ecf20Sopenharmony_ci		iscsi_logout_stat_tiqn(item)->tiqn_index);
5368c2ecf20Sopenharmony_ci}
5378c2ecf20Sopenharmony_ci
5388c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page)
5398c2ecf20Sopenharmony_ci{
5408c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
5418c2ecf20Sopenharmony_ci}
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item,
5448c2ecf20Sopenharmony_ci		char *page)
5458c2ecf20Sopenharmony_ci{
5468c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
5478c2ecf20Sopenharmony_ci	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
5508c2ecf20Sopenharmony_ci}
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
5538c2ecf20Sopenharmony_ci		char *page)
5548c2ecf20Sopenharmony_ci{
5558c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
5568c2ecf20Sopenharmony_ci	struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
5578c2ecf20Sopenharmony_ci
5588c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
5598c2ecf20Sopenharmony_ci}
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_logout_, inst);
5628c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_logout_, indx);
5638c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_logout_, normal_logouts);
5648c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_logout_, abnormal_logouts);
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_cistatic struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
5678c2ecf20Sopenharmony_ci	&iscsi_stat_logout_attr_inst,
5688c2ecf20Sopenharmony_ci	&iscsi_stat_logout_attr_indx,
5698c2ecf20Sopenharmony_ci	&iscsi_stat_logout_attr_normal_logouts,
5708c2ecf20Sopenharmony_ci	&iscsi_stat_logout_attr_abnormal_logouts,
5718c2ecf20Sopenharmony_ci	NULL,
5728c2ecf20Sopenharmony_ci};
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ciconst struct config_item_type iscsi_stat_logout_cit = {
5758c2ecf20Sopenharmony_ci	.ct_attrs		= iscsi_stat_logout_stats_attrs,
5768c2ecf20Sopenharmony_ci	.ct_owner		= THIS_MODULE,
5778c2ecf20Sopenharmony_ci};
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci/*
5808c2ecf20Sopenharmony_ci * Session Stats Table
5818c2ecf20Sopenharmony_ci */
5828c2ecf20Sopenharmony_cistatic struct iscsi_node_acl *iscsi_stat_nacl(struct config_item *item)
5838c2ecf20Sopenharmony_ci{
5848c2ecf20Sopenharmony_ci	struct iscsi_node_stat_grps *igrps = container_of(to_config_group(item),
5858c2ecf20Sopenharmony_ci			struct iscsi_node_stat_grps, iscsi_sess_stats_group);
5868c2ecf20Sopenharmony_ci	return container_of(igrps, struct iscsi_node_acl, node_stat_grps);
5878c2ecf20Sopenharmony_ci}
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page)
5908c2ecf20Sopenharmony_ci{
5918c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
5928c2ecf20Sopenharmony_ci	struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
5938c2ecf20Sopenharmony_ci	struct iscsi_tiqn *tiqn = container_of(wwn,
5948c2ecf20Sopenharmony_ci			struct iscsi_tiqn, tiqn_wwn);
5958c2ecf20Sopenharmony_ci
5968c2ecf20Sopenharmony_ci	return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
5978c2ecf20Sopenharmony_ci}
5988c2ecf20Sopenharmony_ci
5998c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
6008c2ecf20Sopenharmony_ci{
6018c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
6028c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
6038c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
6048c2ecf20Sopenharmony_ci	struct se_session *se_sess;
6058c2ecf20Sopenharmony_ci	ssize_t ret = 0;
6068c2ecf20Sopenharmony_ci
6078c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
6088c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
6098c2ecf20Sopenharmony_ci	if (se_sess) {
6108c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
6118c2ecf20Sopenharmony_ci		if (sess)
6128c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%u\n",
6138c2ecf20Sopenharmony_ci				sess->sess_ops->SessionType ? 0 : ISCSI_NODE_INDEX);
6148c2ecf20Sopenharmony_ci	}
6158c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
6168c2ecf20Sopenharmony_ci
6178c2ecf20Sopenharmony_ci	return ret;
6188c2ecf20Sopenharmony_ci}
6198c2ecf20Sopenharmony_ci
6208c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
6218c2ecf20Sopenharmony_ci{
6228c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
6238c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
6248c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
6258c2ecf20Sopenharmony_ci	struct se_session *se_sess;
6268c2ecf20Sopenharmony_ci	ssize_t ret = 0;
6278c2ecf20Sopenharmony_ci
6288c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
6298c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
6308c2ecf20Sopenharmony_ci	if (se_sess) {
6318c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
6328c2ecf20Sopenharmony_ci		if (sess)
6338c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%u\n",
6348c2ecf20Sopenharmony_ci					sess->session_index);
6358c2ecf20Sopenharmony_ci	}
6368c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
6378c2ecf20Sopenharmony_ci
6388c2ecf20Sopenharmony_ci	return ret;
6398c2ecf20Sopenharmony_ci}
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item,
6428c2ecf20Sopenharmony_ci		char *page)
6438c2ecf20Sopenharmony_ci{
6448c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
6458c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
6468c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
6478c2ecf20Sopenharmony_ci	struct se_session *se_sess;
6488c2ecf20Sopenharmony_ci	ssize_t ret = 0;
6498c2ecf20Sopenharmony_ci
6508c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
6518c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
6528c2ecf20Sopenharmony_ci	if (se_sess) {
6538c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
6548c2ecf20Sopenharmony_ci		if (sess)
6558c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%lu\n",
6568c2ecf20Sopenharmony_ci				       atomic_long_read(&sess->cmd_pdus));
6578c2ecf20Sopenharmony_ci	}
6588c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
6598c2ecf20Sopenharmony_ci
6608c2ecf20Sopenharmony_ci	return ret;
6618c2ecf20Sopenharmony_ci}
6628c2ecf20Sopenharmony_ci
6638c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item,
6648c2ecf20Sopenharmony_ci		char *page)
6658c2ecf20Sopenharmony_ci{
6668c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
6678c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
6688c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
6698c2ecf20Sopenharmony_ci	struct se_session *se_sess;
6708c2ecf20Sopenharmony_ci	ssize_t ret = 0;
6718c2ecf20Sopenharmony_ci
6728c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
6738c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
6748c2ecf20Sopenharmony_ci	if (se_sess) {
6758c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
6768c2ecf20Sopenharmony_ci		if (sess)
6778c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%lu\n",
6788c2ecf20Sopenharmony_ci				       atomic_long_read(&sess->rsp_pdus));
6798c2ecf20Sopenharmony_ci	}
6808c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
6818c2ecf20Sopenharmony_ci
6828c2ecf20Sopenharmony_ci	return ret;
6838c2ecf20Sopenharmony_ci}
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item,
6868c2ecf20Sopenharmony_ci		char *page)
6878c2ecf20Sopenharmony_ci{
6888c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
6898c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
6908c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
6918c2ecf20Sopenharmony_ci	struct se_session *se_sess;
6928c2ecf20Sopenharmony_ci	ssize_t ret = 0;
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
6958c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
6968c2ecf20Sopenharmony_ci	if (se_sess) {
6978c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
6988c2ecf20Sopenharmony_ci		if (sess)
6998c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%lu\n",
7008c2ecf20Sopenharmony_ci				       atomic_long_read(&sess->tx_data_octets));
7018c2ecf20Sopenharmony_ci	}
7028c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
7038c2ecf20Sopenharmony_ci
7048c2ecf20Sopenharmony_ci	return ret;
7058c2ecf20Sopenharmony_ci}
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item,
7088c2ecf20Sopenharmony_ci		char *page)
7098c2ecf20Sopenharmony_ci{
7108c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
7118c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
7128c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
7138c2ecf20Sopenharmony_ci	struct se_session *se_sess;
7148c2ecf20Sopenharmony_ci	ssize_t ret = 0;
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
7178c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
7188c2ecf20Sopenharmony_ci	if (se_sess) {
7198c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
7208c2ecf20Sopenharmony_ci		if (sess)
7218c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%lu\n",
7228c2ecf20Sopenharmony_ci				       atomic_long_read(&sess->rx_data_octets));
7238c2ecf20Sopenharmony_ci	}
7248c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
7258c2ecf20Sopenharmony_ci
7268c2ecf20Sopenharmony_ci	return ret;
7278c2ecf20Sopenharmony_ci}
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item,
7308c2ecf20Sopenharmony_ci		char *page)
7318c2ecf20Sopenharmony_ci{
7328c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
7338c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
7348c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
7358c2ecf20Sopenharmony_ci	struct se_session *se_sess;
7368c2ecf20Sopenharmony_ci	ssize_t ret = 0;
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
7398c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
7408c2ecf20Sopenharmony_ci	if (se_sess) {
7418c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
7428c2ecf20Sopenharmony_ci		if (sess)
7438c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%lu\n",
7448c2ecf20Sopenharmony_ci				       atomic_long_read(&sess->conn_digest_errors));
7458c2ecf20Sopenharmony_ci	}
7468c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	return ret;
7498c2ecf20Sopenharmony_ci}
7508c2ecf20Sopenharmony_ci
7518c2ecf20Sopenharmony_cistatic ssize_t iscsi_stat_sess_conn_timeout_errors_show(
7528c2ecf20Sopenharmony_ci		struct config_item *item, char *page)
7538c2ecf20Sopenharmony_ci{
7548c2ecf20Sopenharmony_ci	struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
7558c2ecf20Sopenharmony_ci	struct se_node_acl *se_nacl = &acl->se_node_acl;
7568c2ecf20Sopenharmony_ci	struct iscsi_session *sess;
7578c2ecf20Sopenharmony_ci	struct se_session *se_sess;
7588c2ecf20Sopenharmony_ci	ssize_t ret = 0;
7598c2ecf20Sopenharmony_ci
7608c2ecf20Sopenharmony_ci	spin_lock_bh(&se_nacl->nacl_sess_lock);
7618c2ecf20Sopenharmony_ci	se_sess = se_nacl->nacl_sess;
7628c2ecf20Sopenharmony_ci	if (se_sess) {
7638c2ecf20Sopenharmony_ci		sess = se_sess->fabric_sess_ptr;
7648c2ecf20Sopenharmony_ci		if (sess)
7658c2ecf20Sopenharmony_ci			ret = snprintf(page, PAGE_SIZE, "%lu\n",
7668c2ecf20Sopenharmony_ci				       atomic_long_read(&sess->conn_timeout_errors));
7678c2ecf20Sopenharmony_ci	}
7688c2ecf20Sopenharmony_ci	spin_unlock_bh(&se_nacl->nacl_sess_lock);
7698c2ecf20Sopenharmony_ci
7708c2ecf20Sopenharmony_ci	return ret;
7718c2ecf20Sopenharmony_ci}
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, inst);
7748c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, node);
7758c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, indx);
7768c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, cmd_pdus);
7778c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, rsp_pdus);
7788c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, txdata_octs);
7798c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, rxdata_octs);
7808c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_digest_errors);
7818c2ecf20Sopenharmony_ciCONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_timeout_errors);
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_cistatic struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
7848c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_inst,
7858c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_node,
7868c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_indx,
7878c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_cmd_pdus,
7888c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_rsp_pdus,
7898c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_txdata_octs,
7908c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_rxdata_octs,
7918c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_conn_digest_errors,
7928c2ecf20Sopenharmony_ci	&iscsi_stat_sess_attr_conn_timeout_errors,
7938c2ecf20Sopenharmony_ci	NULL,
7948c2ecf20Sopenharmony_ci};
7958c2ecf20Sopenharmony_ci
7968c2ecf20Sopenharmony_ciconst struct config_item_type iscsi_stat_sess_cit = {
7978c2ecf20Sopenharmony_ci	.ct_attrs		= iscsi_stat_sess_stats_attrs,
7988c2ecf20Sopenharmony_ci	.ct_owner		= THIS_MODULE,
7998c2ecf20Sopenharmony_ci};
800