blob: 1a39033d2bffaa84e72eac485811656d1a3bb6d5 [file] [log] [blame]
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001/*******************************************************************************
2 * Filename: target_core_stat.c
3 *
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07004 * Modern ConfigFS group context specific statistics based on original
5 * target_core_mib.c code
6 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07007 * (c) Copyright 2006-2013 Datera, Inc.
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07008 *
9 * Nicholas A. Bellinger <nab@linux-iscsi.org>
10 *
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.
15 *
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 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 *
25 ******************************************************************************/
26
27#include <linux/kernel.h>
28#include <linux/module.h>
29#include <linux/delay.h>
30#include <linux/timer.h>
31#include <linux/string.h>
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070032#include <linux/utsname.h>
33#include <linux/proc_fs.h>
34#include <linux/seq_file.h>
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070035#include <linux/configfs.h>
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070036
37#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050038#include <target/target_core_backend.h>
39#include <target/target_core_fabric.h>
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070040
Christoph Hellwige26d99a2011-11-14 12:30:30 -050041#include "target_core_internal.h"
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070042
43#ifndef INITIAL_JIFFIES
44#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
45#endif
46
47#define NONE "None"
48#define ISPRINT(a) ((a >= ' ') && (a <= '~'))
49
50#define SCSI_LU_INDEX 1
51#define LU_COUNT 1
52
53/*
54 * SCSI Device Table
55 */
56
Christoph Hellwig2eafd722015-10-03 15:32:55 +020057static struct se_device *to_stat_dev(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070058{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020059 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
60 struct se_dev_stat_grps, scsi_dev_group);
61 return container_of(sgrps, struct se_device, dev_stat_grps);
62}
63
64static ssize_t target_stat_inst_show(struct config_item *item, char *page)
65{
66 struct se_hba *hba = to_stat_dev(item)->se_hba;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070067
68 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
69}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070070
Christoph Hellwig2eafd722015-10-03 15:32:55 +020071static ssize_t target_stat_indx_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070072{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020073 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070074}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070075
Christoph Hellwig2eafd722015-10-03 15:32:55 +020076static ssize_t target_stat_role_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070077{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070078 return snprintf(page, PAGE_SIZE, "Target\n");
79}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070080
Christoph Hellwig2eafd722015-10-03 15:32:55 +020081static ssize_t target_stat_ports_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070082{
Christoph Hellwig2eafd722015-10-03 15:32:55 +020083 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070084}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070085
Christoph Hellwig2eafd722015-10-03 15:32:55 +020086CONFIGFS_ATTR_RO(target_stat_, inst);
87CONFIGFS_ATTR_RO(target_stat_, indx);
88CONFIGFS_ATTR_RO(target_stat_, role);
89CONFIGFS_ATTR_RO(target_stat_, ports);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070090
91static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +020092 &target_stat_attr_inst,
93 &target_stat_attr_indx,
94 &target_stat_attr_role,
95 &target_stat_attr_ports,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070096 NULL,
97};
98
Nicholas Bellinger12d2338422011-03-14 04:06:11 -070099static struct config_item_type target_stat_scsi_dev_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700100 .ct_attrs = target_stat_scsi_dev_attrs,
101 .ct_owner = THIS_MODULE,
102};
103
104/*
105 * SCSI Target Device Table
106 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200107static struct se_device *to_stat_tgt_dev(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700108{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200109 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
110 struct se_dev_stat_grps, scsi_tgt_dev_group);
111 return container_of(sgrps, struct se_device, dev_stat_grps);
112}
113
114static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
115{
116 struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700117
118 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
119}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700120
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200121static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700122{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200123 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700124}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700125
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200126static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
127 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700128{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700129 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
130}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700131
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200132static ssize_t target_stat_tgt_status_show(struct config_item *item,
133 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700134{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200135 if (to_stat_tgt_dev(item)->export_count)
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400136 return snprintf(page, PAGE_SIZE, "activated");
137 else
138 return snprintf(page, PAGE_SIZE, "deactivated");
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700139}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700140
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200141static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
142 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700143{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700144 int non_accessible_lus;
145
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200146 if (to_stat_tgt_dev(item)->export_count)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700147 non_accessible_lus = 0;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400148 else
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700149 non_accessible_lus = 1;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700150
151 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
152}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700153
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200154static ssize_t target_stat_tgt_resets_show(struct config_item *item,
155 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700156{
Nicholas Bellingeree480682013-11-13 18:34:55 -0800157 return snprintf(page, PAGE_SIZE, "%lu\n",
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200158 atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700159}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700160
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200161CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
162CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
163CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
164CONFIGFS_ATTR_RO(target_stat_tgt_, status);
165CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
166CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700167
168static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200169 &target_stat_tgt_attr_inst,
170 &target_stat_tgt_attr_indx,
171 &target_stat_tgt_attr_num_lus,
172 &target_stat_tgt_attr_status,
173 &target_stat_tgt_attr_non_access_lus,
174 &target_stat_tgt_attr_resets,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700175 NULL,
176};
177
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700178static struct config_item_type target_stat_scsi_tgt_dev_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700179 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
180 .ct_owner = THIS_MODULE,
181};
182
183/*
184 * SCSI Logical Unit Table
185 */
186
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200187static struct se_device *to_stat_lu_dev(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700188{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200189 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
190 struct se_dev_stat_grps, scsi_lu_group);
191 return container_of(sgrps, struct se_device, dev_stat_grps);
192}
193
194static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
195{
196 struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700197
198 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
199}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700200
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200201static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700202{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200203 return snprintf(page, PAGE_SIZE, "%u\n",
204 to_stat_lu_dev(item)->dev_index);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700205}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700206
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200207static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700208{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700209 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
210}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700211
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200212static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700213{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700214 /* FIXME: scsiLuDefaultLun */
215 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
216}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700217
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200218static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700219{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200220 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700221
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700222 /* scsiLuWwnName */
223 return snprintf(page, PAGE_SIZE, "%s\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400224 (strlen(dev->t10_wwn.unit_serial)) ?
225 dev->t10_wwn.unit_serial : "None");
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700226}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700227
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200228static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700229{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200230 struct se_device *dev = to_stat_lu_dev(item);
Andy Grovere3d6f902011-07-19 08:55:10 +0000231 int i;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400232 char str[sizeof(dev->t10_wwn.vendor)+1];
Andy Grovere3d6f902011-07-19 08:55:10 +0000233
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700234 /* scsiLuVendorId */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400235 for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
236 str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ?
237 dev->t10_wwn.vendor[i] : ' ';
Andy Grovere3d6f902011-07-19 08:55:10 +0000238 str[i] = '\0';
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700239 return snprintf(page, PAGE_SIZE, "%s\n", str);
240}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700241
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200242static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700243{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200244 struct se_device *dev = to_stat_lu_dev(item);
Andy Grovere3d6f902011-07-19 08:55:10 +0000245 int i;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400246 char str[sizeof(dev->t10_wwn.model)+1];
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700247
248 /* scsiLuProductId */
David Disseldorp8f903532015-11-27 18:37:47 +0100249 for (i = 0; i < sizeof(dev->t10_wwn.model); i++)
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400250 str[i] = ISPRINT(dev->t10_wwn.model[i]) ?
251 dev->t10_wwn.model[i] : ' ';
Andy Grovere3d6f902011-07-19 08:55:10 +0000252 str[i] = '\0';
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700253 return snprintf(page, PAGE_SIZE, "%s\n", str);
254}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700255
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200256static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700257{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200258 struct se_device *dev = to_stat_lu_dev(item);
Andy Grovere3d6f902011-07-19 08:55:10 +0000259 int i;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400260 char str[sizeof(dev->t10_wwn.revision)+1];
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700261
262 /* scsiLuRevisionId */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400263 for (i = 0; i < sizeof(dev->t10_wwn.revision); i++)
264 str[i] = ISPRINT(dev->t10_wwn.revision[i]) ?
265 dev->t10_wwn.revision[i] : ' ';
Andy Grovere3d6f902011-07-19 08:55:10 +0000266 str[i] = '\0';
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700267 return snprintf(page, PAGE_SIZE, "%s\n", str);
268}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700269
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200270static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700271{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200272 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700273
274 /* scsiLuPeripheralType */
275 return snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000276 dev->transport->get_device_type(dev));
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700277}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700278
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200279static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700280{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200281 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700282
283 /* scsiLuStatus */
284 return snprintf(page, PAGE_SIZE, "%s\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400285 (dev->export_count) ? "available" : "notavailable");
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700286}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700287
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200288static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
289 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700290{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700291 /* scsiLuState */
292 return snprintf(page, PAGE_SIZE, "exposed\n");
293}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700294
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200295static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
296 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700297{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200298 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700299
300 /* scsiLuNumCommands */
Nicholas Bellingeree480682013-11-13 18:34:55 -0800301 return snprintf(page, PAGE_SIZE, "%lu\n",
302 atomic_long_read(&dev->num_cmds));
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700303}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700304
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200305static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
306 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700307{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200308 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700309
310 /* scsiLuReadMegaBytes */
Nicholas Bellingeree480682013-11-13 18:34:55 -0800311 return snprintf(page, PAGE_SIZE, "%lu\n",
312 atomic_long_read(&dev->read_bytes) >> 20);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700313}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700314
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200315static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
316 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700317{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200318 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700319
320 /* scsiLuWrittenMegaBytes */
Nicholas Bellingeree480682013-11-13 18:34:55 -0800321 return snprintf(page, PAGE_SIZE, "%lu\n",
322 atomic_long_read(&dev->write_bytes) >> 20);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700323}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700324
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200325static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700326{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200327 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700328
329 /* scsiLuInResets */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200330 return snprintf(page, PAGE_SIZE, "%lu\n",
331 atomic_long_read(&dev->num_resets));
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700332}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700333
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200334static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
335 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700336{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700337 /* FIXME: scsiLuOutTaskSetFullStatus */
338 return snprintf(page, PAGE_SIZE, "%u\n", 0);
339}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700340
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200341static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
342 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700343{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700344 /* FIXME: scsiLuHSInCommands */
345 return snprintf(page, PAGE_SIZE, "%u\n", 0);
346}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700347
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200348static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
349 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700350{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200351 struct se_device *dev = to_stat_lu_dev(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700352
353 /* scsiLuCreationTime */
354 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
355 INITIAL_JIFFIES) * 100 / HZ));
356}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700357
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200358CONFIGFS_ATTR_RO(target_stat_lu_, inst);
359CONFIGFS_ATTR_RO(target_stat_lu_, dev);
360CONFIGFS_ATTR_RO(target_stat_lu_, indx);
361CONFIGFS_ATTR_RO(target_stat_lu_, lun);
362CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
363CONFIGFS_ATTR_RO(target_stat_lu_, vend);
364CONFIGFS_ATTR_RO(target_stat_lu_, prod);
365CONFIGFS_ATTR_RO(target_stat_lu_, rev);
366CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
367CONFIGFS_ATTR_RO(target_stat_lu_, status);
368CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
369CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
370CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
371CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
372CONFIGFS_ATTR_RO(target_stat_lu_, resets);
373CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
374CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
375CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700376
377static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200378 &target_stat_lu_attr_inst,
379 &target_stat_lu_attr_dev,
380 &target_stat_lu_attr_indx,
381 &target_stat_lu_attr_lun,
382 &target_stat_lu_attr_lu_name,
383 &target_stat_lu_attr_vend,
384 &target_stat_lu_attr_prod,
385 &target_stat_lu_attr_rev,
386 &target_stat_lu_attr_dev_type,
387 &target_stat_lu_attr_status,
388 &target_stat_lu_attr_state_bit,
389 &target_stat_lu_attr_num_cmds,
390 &target_stat_lu_attr_read_mbytes,
391 &target_stat_lu_attr_write_mbytes,
392 &target_stat_lu_attr_resets,
393 &target_stat_lu_attr_full_stat,
394 &target_stat_lu_attr_hs_num_cmds,
395 &target_stat_lu_attr_creation_time,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700396 NULL,
397};
398
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700399static struct config_item_type target_stat_scsi_lu_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700400 .ct_attrs = target_stat_scsi_lu_attrs,
401 .ct_owner = THIS_MODULE,
402};
403
404/*
405 * Called from target_core_configfs.c:target_core_make_subdev() to setup
406 * the target statistics groups + configfs CITs located in target_core_stat.c
407 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400408void target_stat_setup_dev_default_groups(struct se_device *dev)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700409{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400410 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700411 "scsi_dev", &target_stat_scsi_dev_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100412 configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group,
413 &dev->dev_stat_grps.stat_group);
414
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400415 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700416 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100417 configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group,
418 &dev->dev_stat_grps.stat_group);
419
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400420 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700421 "scsi_lu", &target_stat_scsi_lu_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100422 configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group,
423 &dev->dev_stat_grps.stat_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700424}
425
426/*
427 * SCSI Port Table
428 */
429
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200430static struct se_lun *to_stat_port(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700431{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200432 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
433 struct se_port_stat_grps, scsi_port_group);
434 return container_of(pgrps, struct se_lun, port_stat_grps);
435}
436
437static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
438{
439 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700440 struct se_device *dev;
441 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700442
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700443 rcu_read_lock();
444 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700445 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700446 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
447 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700448 return ret;
449}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700450
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200451static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700452{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200453 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700454 struct se_device *dev;
455 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700456
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700457 rcu_read_lock();
458 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700459 if (dev)
460 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700461 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700462 return ret;
463}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700464
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200465static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700466{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200467 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700468 struct se_device *dev;
469 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700470
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700471 rcu_read_lock();
472 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700473 if (dev)
474 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700475 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700476 return ret;
477}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700478
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200479static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700480{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200481 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700482 struct se_device *dev;
483 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700484
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700485 rcu_read_lock();
486 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700487 if (dev)
488 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700489 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700490 return ret;
491}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700492
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200493static ssize_t target_stat_port_busy_count_show(struct config_item *item,
494 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700495{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200496 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700497 struct se_device *dev;
498 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700499
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700500 rcu_read_lock();
501 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700502 if (dev) {
503 /* FIXME: scsiPortBusyStatuses */
504 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700505 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700506 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700507 return ret;
508}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700509
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200510CONFIGFS_ATTR_RO(target_stat_port_, inst);
511CONFIGFS_ATTR_RO(target_stat_port_, dev);
512CONFIGFS_ATTR_RO(target_stat_port_, indx);
513CONFIGFS_ATTR_RO(target_stat_port_, role);
514CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700515
516static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200517 &target_stat_port_attr_inst,
518 &target_stat_port_attr_dev,
519 &target_stat_port_attr_indx,
520 &target_stat_port_attr_role,
521 &target_stat_port_attr_busy_count,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700522 NULL,
523};
524
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700525static struct config_item_type target_stat_scsi_port_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700526 .ct_attrs = target_stat_scsi_port_attrs,
527 .ct_owner = THIS_MODULE,
528};
529
530/*
531 * SCSI Target Port Table
532 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200533static struct se_lun *to_stat_tgt_port(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700534{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200535 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
536 struct se_port_stat_grps, scsi_tgt_port_group);
537 return container_of(pgrps, struct se_lun, port_stat_grps);
538}
539
540static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
541 char *page)
542{
543 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700544 struct se_device *dev;
545 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700546
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700547 rcu_read_lock();
548 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700549 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700550 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
551 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700552 return ret;
553}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700554
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200555static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
556 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700557{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200558 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700559 struct se_device *dev;
560 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700561
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700562 rcu_read_lock();
563 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700564 if (dev)
565 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700566 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700567 return ret;
568}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700569
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200570static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
571 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700572{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200573 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700574 struct se_device *dev;
575 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700576
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700577 rcu_read_lock();
578 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700579 if (dev)
580 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700581 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700582 return ret;
583}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700584
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200585static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
586 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700587{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200588 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700589 struct se_portal_group *tpg = lun->lun_tpg;
590 struct se_device *dev;
591 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700592
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700593 rcu_read_lock();
594 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700595 if (dev)
596 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
597 tpg->se_tpg_tfo->get_fabric_name(),
598 lun->lun_rtpi);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700599 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700600 return ret;
601}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700602
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200603static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
604 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700605{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200606 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700607 struct se_portal_group *tpg = lun->lun_tpg;
608 struct se_device *dev;
609 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700610
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700611 rcu_read_lock();
612 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700613 if (dev)
614 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
615 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
616 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700617 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700618 return ret;
619}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700620
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200621static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
622 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700623{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200624 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700625 struct se_device *dev;
626 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700627
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700628 rcu_read_lock();
629 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700630 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700631 ret = snprintf(page, PAGE_SIZE, "%lu\n",
632 atomic_long_read(&lun->lun_stats.cmd_pdus));
633 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700634 return ret;
635}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700636
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200637static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
638 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700639{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200640 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700641 struct se_device *dev;
642 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700643
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700644 rcu_read_lock();
645 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700646 if (dev)
647 ret = snprintf(page, PAGE_SIZE, "%u\n",
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700648 (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
649 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700650 return ret;
651}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700652
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200653static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
654 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700655{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200656 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700657 struct se_device *dev;
658 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700659
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700660 rcu_read_lock();
661 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700662 if (dev)
663 ret = snprintf(page, PAGE_SIZE, "%u\n",
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700664 (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
665 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700666 return ret;
667}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700668
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200669static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
670 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700671{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200672 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700673 struct se_device *dev;
674 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700675
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700676 rcu_read_lock();
677 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700678 if (dev) {
679 /* FIXME: scsiTgtPortHsInCommands */
680 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700681 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700682 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700683 return ret;
684}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700685
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200686CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
687CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
688CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
689CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
690CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
691CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
692CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
693CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
694CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700695
696static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200697 &target_stat_tgt_port_attr_inst,
698 &target_stat_tgt_port_attr_dev,
699 &target_stat_tgt_port_attr_indx,
700 &target_stat_tgt_port_attr_name,
701 &target_stat_tgt_port_attr_port_index,
702 &target_stat_tgt_port_attr_in_cmds,
703 &target_stat_tgt_port_attr_write_mbytes,
704 &target_stat_tgt_port_attr_read_mbytes,
705 &target_stat_tgt_port_attr_hs_in_cmds,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700706 NULL,
707};
708
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700709static struct config_item_type target_stat_scsi_tgt_port_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700710 .ct_attrs = target_stat_scsi_tgt_port_attrs,
711 .ct_owner = THIS_MODULE,
712};
713
714/*
715 * SCSI Transport Table
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200716 */
717static struct se_lun *to_transport_stat(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700718{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200719 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
720 struct se_port_stat_grps, scsi_transport_group);
721 return container_of(pgrps, struct se_lun, port_stat_grps);
722}
723
724static ssize_t target_stat_transport_inst_show(struct config_item *item,
725 char *page)
726{
727 struct se_lun *lun = to_transport_stat(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700728 struct se_device *dev;
729 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700730
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700731 rcu_read_lock();
732 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700733 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700734 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
735 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700736 return ret;
737}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700738
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200739static ssize_t target_stat_transport_device_show(struct config_item *item,
740 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700741{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200742 struct se_lun *lun = to_transport_stat(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700743 struct se_device *dev;
744 struct se_portal_group *tpg = lun->lun_tpg;
745 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700746
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700747 rcu_read_lock();
748 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700749 if (dev) {
750 /* scsiTransportType */
751 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
752 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700753 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700754 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700755 return ret;
756}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700757
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200758static ssize_t target_stat_transport_indx_show(struct config_item *item,
759 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700760{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200761 struct se_lun *lun = to_transport_stat(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700762 struct se_device *dev;
763 struct se_portal_group *tpg = lun->lun_tpg;
764 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700765
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700766 rcu_read_lock();
767 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700768 if (dev)
769 ret = snprintf(page, PAGE_SIZE, "%u\n",
770 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700771 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700772 return ret;
773}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700774
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200775static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
776 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700777{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200778 struct se_lun *lun = to_transport_stat(item);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700779 struct se_device *dev;
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700780 struct se_portal_group *tpg = lun->lun_tpg;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700781 struct t10_wwn *wwn;
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700782 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700783
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700784 rcu_read_lock();
785 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700786 if (dev) {
787 wwn = &dev->t10_wwn;
788 /* scsiTransportDevName */
789 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
790 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
791 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
792 wwn->vendor);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700793 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700794 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700795 return ret;
796}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700797
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200798CONFIGFS_ATTR_RO(target_stat_transport_, inst);
799CONFIGFS_ATTR_RO(target_stat_transport_, device);
800CONFIGFS_ATTR_RO(target_stat_transport_, indx);
801CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700802
803static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200804 &target_stat_transport_attr_inst,
805 &target_stat_transport_attr_device,
806 &target_stat_transport_attr_indx,
807 &target_stat_transport_attr_dev_name,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700808 NULL,
809};
810
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700811static struct config_item_type target_stat_scsi_transport_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700812 .ct_attrs = target_stat_scsi_transport_attrs,
813 .ct_owner = THIS_MODULE,
814};
815
816/*
817 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
818 * the target port statistics groups + configfs CITs located in target_core_stat.c
819 */
820void target_stat_setup_port_default_groups(struct se_lun *lun)
821{
Andy Grovere3d6f902011-07-19 08:55:10 +0000822 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700823 "scsi_port", &target_stat_scsi_port_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100824 configfs_add_default_group(&lun->port_stat_grps.scsi_port_group,
825 &lun->port_stat_grps.stat_group);
826
Andy Grovere3d6f902011-07-19 08:55:10 +0000827 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700828 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100829 configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group,
830 &lun->port_stat_grps.stat_group);
831
Andy Grovere3d6f902011-07-19 08:55:10 +0000832 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700833 "scsi_transport", &target_stat_scsi_transport_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100834 configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group,
835 &lun->port_stat_grps.stat_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700836}
837
838/*
839 * SCSI Authorized Initiator Table
840 */
841
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200842static struct se_lun_acl *auth_to_lacl(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700843{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200844 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
845 struct se_ml_stat_grps, scsi_auth_intr_group);
846 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
847}
848
849static ssize_t target_stat_auth_inst_show(struct config_item *item,
850 char *page)
851{
852 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700853 struct se_node_acl *nacl = lacl->se_lun_nacl;
854 struct se_dev_entry *deve;
855 struct se_portal_group *tpg;
856 ssize_t ret;
857
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700858 rcu_read_lock();
859 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
860 if (!deve) {
861 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700862 return -ENODEV;
863 }
864 tpg = nacl->se_tpg;
865 /* scsiInstIndex */
866 ret = snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000867 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700868 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700869 return ret;
870}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700871
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200872static ssize_t target_stat_auth_dev_show(struct config_item *item,
873 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700874{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200875 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700876 struct se_node_acl *nacl = lacl->se_lun_nacl;
877 struct se_dev_entry *deve;
878 struct se_lun *lun;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700879 ssize_t ret;
880
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700881 rcu_read_lock();
882 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
883 if (!deve) {
884 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700885 return -ENODEV;
886 }
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700887 lun = rcu_dereference(deve->se_lun);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700888 /* scsiDeviceIndex */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700889 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
890 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700891 return ret;
892}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700893
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200894static ssize_t target_stat_auth_port_show(struct config_item *item,
895 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700896{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200897 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700898 struct se_node_acl *nacl = lacl->se_lun_nacl;
899 struct se_dev_entry *deve;
900 struct se_portal_group *tpg;
901 ssize_t ret;
902
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700903 rcu_read_lock();
904 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
905 if (!deve) {
906 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700907 return -ENODEV;
908 }
909 tpg = nacl->se_tpg;
910 /* scsiAuthIntrTgtPortIndex */
Andy Grovere3d6f902011-07-19 08:55:10 +0000911 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700912 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700913 return ret;
914}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700915
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200916static ssize_t target_stat_auth_indx_show(struct config_item *item,
917 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700918{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200919 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700920 struct se_node_acl *nacl = lacl->se_lun_nacl;
921 struct se_dev_entry *deve;
922 ssize_t ret;
923
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700924 rcu_read_lock();
925 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
926 if (!deve) {
927 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700928 return -ENODEV;
929 }
930 /* scsiAuthIntrIndex */
931 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700932 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700933 return ret;
934}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700935
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200936static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
937 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700938{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200939 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700940 struct se_node_acl *nacl = lacl->se_lun_nacl;
941 struct se_dev_entry *deve;
942 ssize_t ret;
943
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700944 rcu_read_lock();
945 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
946 if (!deve) {
947 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700948 return -ENODEV;
949 }
950 /* scsiAuthIntrDevOrPort */
951 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700952 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700953 return ret;
954}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700955
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200956static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
957 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700958{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200959 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700960 struct se_node_acl *nacl = lacl->se_lun_nacl;
961 struct se_dev_entry *deve;
962 ssize_t ret;
963
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700964 rcu_read_lock();
965 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
966 if (!deve) {
967 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700968 return -ENODEV;
969 }
970 /* scsiAuthIntrName */
971 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700972 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700973 return ret;
974}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700975
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200976static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
977 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700978{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200979 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700980 struct se_node_acl *nacl = lacl->se_lun_nacl;
981 struct se_dev_entry *deve;
982 ssize_t ret;
983
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700984 rcu_read_lock();
985 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
986 if (!deve) {
987 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700988 return -ENODEV;
989 }
990 /* FIXME: scsiAuthIntrLunMapIndex */
991 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700992 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700993 return ret;
994}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700995
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200996static ssize_t target_stat_auth_att_count_show(struct config_item *item,
997 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700998{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200999 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001000 struct se_node_acl *nacl = lacl->se_lun_nacl;
1001 struct se_dev_entry *deve;
1002 ssize_t ret;
1003
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001004 rcu_read_lock();
1005 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1006 if (!deve) {
1007 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001008 return -ENODEV;
1009 }
1010 /* scsiAuthIntrAttachedTimes */
1011 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001012 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001013 return ret;
1014}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001015
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001016static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
1017 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001018{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001019 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001020 struct se_node_acl *nacl = lacl->se_lun_nacl;
1021 struct se_dev_entry *deve;
1022 ssize_t ret;
1023
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001024 rcu_read_lock();
1025 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1026 if (!deve) {
1027 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001028 return -ENODEV;
1029 }
1030 /* scsiAuthIntrOutCommands */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001031 ret = snprintf(page, PAGE_SIZE, "%lu\n",
1032 atomic_long_read(&deve->total_cmds));
1033 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001034 return ret;
1035}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001036
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001037static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
1038 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001039{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001040 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001041 struct se_node_acl *nacl = lacl->se_lun_nacl;
1042 struct se_dev_entry *deve;
1043 ssize_t ret;
1044
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001045 rcu_read_lock();
1046 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1047 if (!deve) {
1048 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001049 return -ENODEV;
1050 }
1051 /* scsiAuthIntrReadMegaBytes */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001052 ret = snprintf(page, PAGE_SIZE, "%u\n",
1053 (u32)(atomic_long_read(&deve->read_bytes) >> 20));
1054 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001055 return ret;
1056}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001057
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001058static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
1059 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001060{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001061 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001062 struct se_node_acl *nacl = lacl->se_lun_nacl;
1063 struct se_dev_entry *deve;
1064 ssize_t ret;
1065
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001066 rcu_read_lock();
1067 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1068 if (!deve) {
1069 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001070 return -ENODEV;
1071 }
1072 /* scsiAuthIntrWrittenMegaBytes */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001073 ret = snprintf(page, PAGE_SIZE, "%u\n",
1074 (u32)(atomic_long_read(&deve->write_bytes) >> 20));
1075 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001076 return ret;
1077}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001078
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001079static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
1080 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001081{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001082 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001083 struct se_node_acl *nacl = lacl->se_lun_nacl;
1084 struct se_dev_entry *deve;
1085 ssize_t ret;
1086
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001087 rcu_read_lock();
1088 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1089 if (!deve) {
1090 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001091 return -ENODEV;
1092 }
1093 /* FIXME: scsiAuthIntrHSOutCommands */
1094 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001095 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001096 return ret;
1097}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001098
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001099static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
1100 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001101{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001102 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001103 struct se_node_acl *nacl = lacl->se_lun_nacl;
1104 struct se_dev_entry *deve;
1105 ssize_t ret;
1106
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001107 rcu_read_lock();
1108 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1109 if (!deve) {
1110 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001111 return -ENODEV;
1112 }
1113 /* scsiAuthIntrLastCreation */
1114 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1115 INITIAL_JIFFIES) * 100 / HZ));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001116 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001117 return ret;
1118}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001119
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001120static ssize_t target_stat_auth_row_status_show(struct config_item *item,
1121 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001122{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001123 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001124 struct se_node_acl *nacl = lacl->se_lun_nacl;
1125 struct se_dev_entry *deve;
1126 ssize_t ret;
1127
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001128 rcu_read_lock();
1129 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1130 if (!deve) {
1131 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001132 return -ENODEV;
1133 }
1134 /* FIXME: scsiAuthIntrRowStatus */
1135 ret = snprintf(page, PAGE_SIZE, "Ready\n");
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001136 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001137 return ret;
1138}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001139
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001140CONFIGFS_ATTR_RO(target_stat_auth_, inst);
1141CONFIGFS_ATTR_RO(target_stat_auth_, dev);
1142CONFIGFS_ATTR_RO(target_stat_auth_, port);
1143CONFIGFS_ATTR_RO(target_stat_auth_, indx);
1144CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
1145CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
1146CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
1147CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
1148CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
1149CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
1150CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
1151CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
1152CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
1153CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001154
1155static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001156 &target_stat_auth_attr_inst,
1157 &target_stat_auth_attr_dev,
1158 &target_stat_auth_attr_port,
1159 &target_stat_auth_attr_indx,
1160 &target_stat_auth_attr_dev_or_port,
1161 &target_stat_auth_attr_intr_name,
1162 &target_stat_auth_attr_map_indx,
1163 &target_stat_auth_attr_att_count,
1164 &target_stat_auth_attr_num_cmds,
1165 &target_stat_auth_attr_read_mbytes,
1166 &target_stat_auth_attr_write_mbytes,
1167 &target_stat_auth_attr_hs_num_cmds,
1168 &target_stat_auth_attr_creation_time,
1169 &target_stat_auth_attr_row_status,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001170 NULL,
1171};
1172
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001173static struct config_item_type target_stat_scsi_auth_intr_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001174 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1175 .ct_owner = THIS_MODULE,
1176};
1177
1178/*
1179 * SCSI Attached Initiator Port Table
1180 */
1181
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001182static struct se_lun_acl *iport_to_lacl(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001183{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001184 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
1185 struct se_ml_stat_grps, scsi_att_intr_port_group);
1186 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
1187}
1188
1189static ssize_t target_stat_iport_inst_show(struct config_item *item,
1190 char *page)
1191{
1192 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001193 struct se_node_acl *nacl = lacl->se_lun_nacl;
1194 struct se_dev_entry *deve;
1195 struct se_portal_group *tpg;
1196 ssize_t ret;
1197
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001198 rcu_read_lock();
1199 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1200 if (!deve) {
1201 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001202 return -ENODEV;
1203 }
1204 tpg = nacl->se_tpg;
1205 /* scsiInstIndex */
1206 ret = snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001207 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001208 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001209 return ret;
1210}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001211
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001212static ssize_t target_stat_iport_dev_show(struct config_item *item,
1213 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001214{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001215 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001216 struct se_node_acl *nacl = lacl->se_lun_nacl;
1217 struct se_dev_entry *deve;
1218 struct se_lun *lun;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001219 ssize_t ret;
1220
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001221 rcu_read_lock();
1222 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1223 if (!deve) {
1224 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001225 return -ENODEV;
1226 }
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001227 lun = rcu_dereference(deve->se_lun);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001228 /* scsiDeviceIndex */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001229 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
1230 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001231 return ret;
1232}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001233
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001234static ssize_t target_stat_iport_port_show(struct config_item *item,
1235 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001236{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001237 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001238 struct se_node_acl *nacl = lacl->se_lun_nacl;
1239 struct se_dev_entry *deve;
1240 struct se_portal_group *tpg;
1241 ssize_t ret;
1242
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001243 rcu_read_lock();
1244 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1245 if (!deve) {
1246 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001247 return -ENODEV;
1248 }
1249 tpg = nacl->se_tpg;
1250 /* scsiPortIndex */
Andy Grovere3d6f902011-07-19 08:55:10 +00001251 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001252 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001253 return ret;
1254}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001255
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001256static ssize_t target_stat_iport_indx_show(struct config_item *item,
1257 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001258{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001259 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001260 struct se_node_acl *nacl = lacl->se_lun_nacl;
1261 struct se_session *se_sess;
1262 struct se_portal_group *tpg;
1263 ssize_t ret;
1264
1265 spin_lock_irq(&nacl->nacl_sess_lock);
1266 se_sess = nacl->nacl_sess;
1267 if (!se_sess) {
1268 spin_unlock_irq(&nacl->nacl_sess_lock);
1269 return -ENODEV;
1270 }
1271
1272 tpg = nacl->se_tpg;
1273 /* scsiAttIntrPortIndex */
1274 ret = snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001275 tpg->se_tpg_tfo->sess_get_index(se_sess));
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001276 spin_unlock_irq(&nacl->nacl_sess_lock);
1277 return ret;
1278}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001279
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001280static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
1281 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001282{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001283 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001284 struct se_node_acl *nacl = lacl->se_lun_nacl;
1285 struct se_dev_entry *deve;
1286 ssize_t ret;
1287
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001288 rcu_read_lock();
1289 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1290 if (!deve) {
1291 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001292 return -ENODEV;
1293 }
1294 /* scsiAttIntrPortAuthIntrIdx */
1295 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001296 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001297 return ret;
1298}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001299
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001300static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
1301 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001302{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001303 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001304 struct se_node_acl *nacl = lacl->se_lun_nacl;
1305 struct se_session *se_sess;
1306 struct se_portal_group *tpg;
1307 ssize_t ret;
1308 unsigned char buf[64];
1309
1310 spin_lock_irq(&nacl->nacl_sess_lock);
1311 se_sess = nacl->nacl_sess;
1312 if (!se_sess) {
1313 spin_unlock_irq(&nacl->nacl_sess_lock);
1314 return -ENODEV;
1315 }
1316
1317 tpg = nacl->se_tpg;
1318 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1319 memset(buf, 0, 64);
Andy Grovere3d6f902011-07-19 08:55:10 +00001320 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
Jörn Engel8359cf42011-11-24 02:05:51 +01001321 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001322
1323 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1324 spin_unlock_irq(&nacl->nacl_sess_lock);
1325 return ret;
1326}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001327
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001328CONFIGFS_ATTR_RO(target_stat_iport_, inst);
1329CONFIGFS_ATTR_RO(target_stat_iport_, dev);
1330CONFIGFS_ATTR_RO(target_stat_iport_, port);
1331CONFIGFS_ATTR_RO(target_stat_iport_, indx);
1332CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
1333CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001334
1335static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001336 &target_stat_iport_attr_inst,
1337 &target_stat_iport_attr_dev,
1338 &target_stat_iport_attr_port,
1339 &target_stat_iport_attr_indx,
1340 &target_stat_iport_attr_port_auth_indx,
1341 &target_stat_iport_attr_port_ident,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001342 NULL,
1343};
1344
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001345static struct config_item_type target_stat_scsi_att_intr_port_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001346 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1347 .ct_owner = THIS_MODULE,
1348};
1349
1350/*
1351 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1352 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1353 */
1354void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1355{
Andy Grovere3d6f902011-07-19 08:55:10 +00001356 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001357 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001358 configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group,
1359 &lacl->ml_stat_grps.stat_group);
1360
Andy Grovere3d6f902011-07-19 08:55:10 +00001361 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001362 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +01001363 configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1364 &lacl->ml_stat_grps.stat_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001365}