blob: 273c72b2b83dc016b2a317b778a8c391eebcb9c8 [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 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400249 for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
250 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 struct config_group *dev_stat_grp = &dev->dev_stat_grps.stat_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700411
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400412 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700413 "scsi_dev", &target_stat_scsi_dev_cit);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400414 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700415 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400416 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700417 "scsi_lu", &target_stat_scsi_lu_cit);
418
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400419 dev_stat_grp->default_groups[0] = &dev->dev_stat_grps.scsi_dev_group;
420 dev_stat_grp->default_groups[1] = &dev->dev_stat_grps.scsi_tgt_dev_group;
421 dev_stat_grp->default_groups[2] = &dev->dev_stat_grps.scsi_lu_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700422 dev_stat_grp->default_groups[3] = NULL;
423}
424
425/*
426 * SCSI Port Table
427 */
428
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200429static struct se_lun *to_stat_port(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700430{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200431 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
432 struct se_port_stat_grps, scsi_port_group);
433 return container_of(pgrps, struct se_lun, port_stat_grps);
434}
435
436static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
437{
438 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700439 struct se_device *dev;
440 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700441
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700442 rcu_read_lock();
443 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700444 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700445 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
446 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700447 return ret;
448}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700449
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200450static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700451{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200452 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700453 struct se_device *dev;
454 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700455
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700456 rcu_read_lock();
457 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700458 if (dev)
459 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700460 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700461 return ret;
462}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700463
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200464static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700465{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200466 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700467 struct se_device *dev;
468 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700469
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700470 rcu_read_lock();
471 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700472 if (dev)
473 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700474 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700475 return ret;
476}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700477
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200478static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700479{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200480 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700481 struct se_device *dev;
482 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700483
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700484 rcu_read_lock();
485 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700486 if (dev)
487 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700488 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700489 return ret;
490}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700491
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200492static ssize_t target_stat_port_busy_count_show(struct config_item *item,
493 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700494{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200495 struct se_lun *lun = to_stat_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700496 struct se_device *dev;
497 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700498
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700499 rcu_read_lock();
500 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700501 if (dev) {
502 /* FIXME: scsiPortBusyStatuses */
503 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700504 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700505 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700506 return ret;
507}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700508
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200509CONFIGFS_ATTR_RO(target_stat_port_, inst);
510CONFIGFS_ATTR_RO(target_stat_port_, dev);
511CONFIGFS_ATTR_RO(target_stat_port_, indx);
512CONFIGFS_ATTR_RO(target_stat_port_, role);
513CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700514
515static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200516 &target_stat_port_attr_inst,
517 &target_stat_port_attr_dev,
518 &target_stat_port_attr_indx,
519 &target_stat_port_attr_role,
520 &target_stat_port_attr_busy_count,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700521 NULL,
522};
523
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700524static struct config_item_type target_stat_scsi_port_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700525 .ct_attrs = target_stat_scsi_port_attrs,
526 .ct_owner = THIS_MODULE,
527};
528
529/*
530 * SCSI Target Port Table
531 */
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200532static struct se_lun *to_stat_tgt_port(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700533{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200534 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
535 struct se_port_stat_grps, scsi_tgt_port_group);
536 return container_of(pgrps, struct se_lun, port_stat_grps);
537}
538
539static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
540 char *page)
541{
542 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700543 struct se_device *dev;
544 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700545
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700546 rcu_read_lock();
547 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700548 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700549 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
550 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700551 return ret;
552}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700553
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200554static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
555 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700556{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200557 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700558 struct se_device *dev;
559 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700560
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700561 rcu_read_lock();
562 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700563 if (dev)
564 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700565 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700566 return ret;
567}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700568
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200569static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
570 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700571{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200572 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700573 struct se_device *dev;
574 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700575
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700576 rcu_read_lock();
577 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700578 if (dev)
579 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700580 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700581 return ret;
582}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700583
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200584static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
585 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700586{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200587 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700588 struct se_portal_group *tpg = lun->lun_tpg;
589 struct se_device *dev;
590 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700591
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700592 rcu_read_lock();
593 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700594 if (dev)
595 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
596 tpg->se_tpg_tfo->get_fabric_name(),
597 lun->lun_rtpi);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700598 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700599 return ret;
600}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700601
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200602static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
603 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700604{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200605 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700606 struct se_portal_group *tpg = lun->lun_tpg;
607 struct se_device *dev;
608 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700609
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700610 rcu_read_lock();
611 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700612 if (dev)
613 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
614 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
615 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700616 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700617 return ret;
618}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700619
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200620static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
621 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700622{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200623 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700624 struct se_device *dev;
625 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700626
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700627 rcu_read_lock();
628 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700629 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700630 ret = snprintf(page, PAGE_SIZE, "%lu\n",
631 atomic_long_read(&lun->lun_stats.cmd_pdus));
632 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700633 return ret;
634}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700635
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200636static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
637 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700638{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200639 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700640 struct se_device *dev;
641 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700642
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700643 rcu_read_lock();
644 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700645 if (dev)
646 ret = snprintf(page, PAGE_SIZE, "%u\n",
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700647 (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
648 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700649 return ret;
650}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700651
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200652static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
653 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700654{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200655 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700656 struct se_device *dev;
657 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700658
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700659 rcu_read_lock();
660 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700661 if (dev)
662 ret = snprintf(page, PAGE_SIZE, "%u\n",
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700663 (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
664 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700665 return ret;
666}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700667
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200668static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
669 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700670{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200671 struct se_lun *lun = to_stat_tgt_port(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700672 struct se_device *dev;
673 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700674
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700675 rcu_read_lock();
676 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700677 if (dev) {
678 /* FIXME: scsiTgtPortHsInCommands */
679 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700680 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700681 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700682 return ret;
683}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700684
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200685CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
686CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
687CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
688CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
689CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
690CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
691CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
692CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
693CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700694
695static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200696 &target_stat_tgt_port_attr_inst,
697 &target_stat_tgt_port_attr_dev,
698 &target_stat_tgt_port_attr_indx,
699 &target_stat_tgt_port_attr_name,
700 &target_stat_tgt_port_attr_port_index,
701 &target_stat_tgt_port_attr_in_cmds,
702 &target_stat_tgt_port_attr_write_mbytes,
703 &target_stat_tgt_port_attr_read_mbytes,
704 &target_stat_tgt_port_attr_hs_in_cmds,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700705 NULL,
706};
707
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700708static struct config_item_type target_stat_scsi_tgt_port_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700709 .ct_attrs = target_stat_scsi_tgt_port_attrs,
710 .ct_owner = THIS_MODULE,
711};
712
713/*
714 * SCSI Transport Table
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200715 */
716static struct se_lun *to_transport_stat(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700717{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200718 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
719 struct se_port_stat_grps, scsi_transport_group);
720 return container_of(pgrps, struct se_lun, port_stat_grps);
721}
722
723static ssize_t target_stat_transport_inst_show(struct config_item *item,
724 char *page)
725{
726 struct se_lun *lun = to_transport_stat(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700727 struct se_device *dev;
728 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700729
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700730 rcu_read_lock();
731 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700732 if (dev)
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700733 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
734 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700735 return ret;
736}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700737
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200738static ssize_t target_stat_transport_device_show(struct config_item *item,
739 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700740{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200741 struct se_lun *lun = to_transport_stat(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700742 struct se_device *dev;
743 struct se_portal_group *tpg = lun->lun_tpg;
744 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700745
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700746 rcu_read_lock();
747 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700748 if (dev) {
749 /* scsiTransportType */
750 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
751 tpg->se_tpg_tfo->get_fabric_name());
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700752 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700753 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700754 return ret;
755}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700756
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200757static ssize_t target_stat_transport_indx_show(struct config_item *item,
758 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700759{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200760 struct se_lun *lun = to_transport_stat(item);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700761 struct se_device *dev;
762 struct se_portal_group *tpg = lun->lun_tpg;
763 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700764
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700765 rcu_read_lock();
766 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700767 if (dev)
768 ret = snprintf(page, PAGE_SIZE, "%u\n",
769 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700770 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700771 return ret;
772}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700773
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200774static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
775 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700776{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200777 struct se_lun *lun = to_transport_stat(item);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700778 struct se_device *dev;
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700779 struct se_portal_group *tpg = lun->lun_tpg;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700780 struct t10_wwn *wwn;
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700781 ssize_t ret = -ENODEV;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700782
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700783 rcu_read_lock();
784 dev = rcu_dereference(lun->lun_se_dev);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700785 if (dev) {
786 wwn = &dev->t10_wwn;
787 /* scsiTransportDevName */
788 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
789 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
790 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
791 wwn->vendor);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700792 }
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700793 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700794 return ret;
795}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700796
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200797CONFIGFS_ATTR_RO(target_stat_transport_, inst);
798CONFIGFS_ATTR_RO(target_stat_transport_, device);
799CONFIGFS_ATTR_RO(target_stat_transport_, indx);
800CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700801
802static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200803 &target_stat_transport_attr_inst,
804 &target_stat_transport_attr_device,
805 &target_stat_transport_attr_indx,
806 &target_stat_transport_attr_dev_name,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700807 NULL,
808};
809
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700810static struct config_item_type target_stat_scsi_transport_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700811 .ct_attrs = target_stat_scsi_transport_attrs,
812 .ct_owner = THIS_MODULE,
813};
814
815/*
816 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
817 * the target port statistics groups + configfs CITs located in target_core_stat.c
818 */
819void target_stat_setup_port_default_groups(struct se_lun *lun)
820{
Andy Grovere3d6f902011-07-19 08:55:10 +0000821 struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700822
Andy Grovere3d6f902011-07-19 08:55:10 +0000823 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700824 "scsi_port", &target_stat_scsi_port_cit);
Andy Grovere3d6f902011-07-19 08:55:10 +0000825 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700826 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
Andy Grovere3d6f902011-07-19 08:55:10 +0000827 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700828 "scsi_transport", &target_stat_scsi_transport_cit);
829
Andy Grovere3d6f902011-07-19 08:55:10 +0000830 port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
831 port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
832 port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700833 port_stat_grp->default_groups[3] = NULL;
834}
835
836/*
837 * SCSI Authorized Initiator Table
838 */
839
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200840static struct se_lun_acl *auth_to_lacl(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700841{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200842 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
843 struct se_ml_stat_grps, scsi_auth_intr_group);
844 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
845}
846
847static ssize_t target_stat_auth_inst_show(struct config_item *item,
848 char *page)
849{
850 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700851 struct se_node_acl *nacl = lacl->se_lun_nacl;
852 struct se_dev_entry *deve;
853 struct se_portal_group *tpg;
854 ssize_t ret;
855
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700856 rcu_read_lock();
857 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
858 if (!deve) {
859 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700860 return -ENODEV;
861 }
862 tpg = nacl->se_tpg;
863 /* scsiInstIndex */
864 ret = snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000865 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700866 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700867 return ret;
868}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700869
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200870static ssize_t target_stat_auth_dev_show(struct config_item *item,
871 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700872{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200873 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700874 struct se_node_acl *nacl = lacl->se_lun_nacl;
875 struct se_dev_entry *deve;
876 struct se_lun *lun;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700877 ssize_t ret;
878
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700879 rcu_read_lock();
880 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
881 if (!deve) {
882 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700883 return -ENODEV;
884 }
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700885 lun = rcu_dereference(deve->se_lun);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700886 /* scsiDeviceIndex */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700887 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
888 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700889 return ret;
890}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700891
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200892static ssize_t target_stat_auth_port_show(struct config_item *item,
893 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700894{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200895 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700896 struct se_node_acl *nacl = lacl->se_lun_nacl;
897 struct se_dev_entry *deve;
898 struct se_portal_group *tpg;
899 ssize_t ret;
900
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700901 rcu_read_lock();
902 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
903 if (!deve) {
904 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700905 return -ENODEV;
906 }
907 tpg = nacl->se_tpg;
908 /* scsiAuthIntrTgtPortIndex */
Andy Grovere3d6f902011-07-19 08:55:10 +0000909 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700910 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700911 return ret;
912}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700913
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200914static ssize_t target_stat_auth_indx_show(struct config_item *item,
915 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700916{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200917 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700918 struct se_node_acl *nacl = lacl->se_lun_nacl;
919 struct se_dev_entry *deve;
920 ssize_t ret;
921
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700922 rcu_read_lock();
923 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
924 if (!deve) {
925 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700926 return -ENODEV;
927 }
928 /* scsiAuthIntrIndex */
929 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700930 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700931 return ret;
932}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700933
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200934static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
935 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700936{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200937 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700938 struct se_node_acl *nacl = lacl->se_lun_nacl;
939 struct se_dev_entry *deve;
940 ssize_t ret;
941
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700942 rcu_read_lock();
943 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
944 if (!deve) {
945 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700946 return -ENODEV;
947 }
948 /* scsiAuthIntrDevOrPort */
949 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700950 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700951 return ret;
952}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700953
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200954static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
955 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700956{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200957 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700958 struct se_node_acl *nacl = lacl->se_lun_nacl;
959 struct se_dev_entry *deve;
960 ssize_t ret;
961
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700962 rcu_read_lock();
963 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
964 if (!deve) {
965 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700966 return -ENODEV;
967 }
968 /* scsiAuthIntrName */
969 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700970 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700971 return ret;
972}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700973
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200974static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
975 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700976{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200977 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700978 struct se_node_acl *nacl = lacl->se_lun_nacl;
979 struct se_dev_entry *deve;
980 ssize_t ret;
981
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700982 rcu_read_lock();
983 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
984 if (!deve) {
985 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700986 return -ENODEV;
987 }
988 /* FIXME: scsiAuthIntrLunMapIndex */
989 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700990 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700991 return ret;
992}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700993
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200994static ssize_t target_stat_auth_att_count_show(struct config_item *item,
995 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700996{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200997 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700998 struct se_node_acl *nacl = lacl->se_lun_nacl;
999 struct se_dev_entry *deve;
1000 ssize_t ret;
1001
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001002 rcu_read_lock();
1003 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1004 if (!deve) {
1005 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001006 return -ENODEV;
1007 }
1008 /* scsiAuthIntrAttachedTimes */
1009 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001010 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001011 return ret;
1012}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001013
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001014static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
1015 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001016{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001017 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001018 struct se_node_acl *nacl = lacl->se_lun_nacl;
1019 struct se_dev_entry *deve;
1020 ssize_t ret;
1021
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001022 rcu_read_lock();
1023 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1024 if (!deve) {
1025 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001026 return -ENODEV;
1027 }
1028 /* scsiAuthIntrOutCommands */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001029 ret = snprintf(page, PAGE_SIZE, "%lu\n",
1030 atomic_long_read(&deve->total_cmds));
1031 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001032 return ret;
1033}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001034
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001035static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
1036 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001037{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001038 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001039 struct se_node_acl *nacl = lacl->se_lun_nacl;
1040 struct se_dev_entry *deve;
1041 ssize_t ret;
1042
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001043 rcu_read_lock();
1044 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1045 if (!deve) {
1046 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001047 return -ENODEV;
1048 }
1049 /* scsiAuthIntrReadMegaBytes */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001050 ret = snprintf(page, PAGE_SIZE, "%u\n",
1051 (u32)(atomic_long_read(&deve->read_bytes) >> 20));
1052 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001053 return ret;
1054}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001055
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001056static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
1057 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001058{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001059 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001060 struct se_node_acl *nacl = lacl->se_lun_nacl;
1061 struct se_dev_entry *deve;
1062 ssize_t ret;
1063
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001064 rcu_read_lock();
1065 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1066 if (!deve) {
1067 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001068 return -ENODEV;
1069 }
1070 /* scsiAuthIntrWrittenMegaBytes */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001071 ret = snprintf(page, PAGE_SIZE, "%u\n",
1072 (u32)(atomic_long_read(&deve->write_bytes) >> 20));
1073 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001074 return ret;
1075}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001076
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001077static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
1078 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001079{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001080 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001081 struct se_node_acl *nacl = lacl->se_lun_nacl;
1082 struct se_dev_entry *deve;
1083 ssize_t ret;
1084
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001085 rcu_read_lock();
1086 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1087 if (!deve) {
1088 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001089 return -ENODEV;
1090 }
1091 /* FIXME: scsiAuthIntrHSOutCommands */
1092 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001093 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001094 return ret;
1095}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001096
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001097static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
1098 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001099{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001100 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001101 struct se_node_acl *nacl = lacl->se_lun_nacl;
1102 struct se_dev_entry *deve;
1103 ssize_t ret;
1104
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001105 rcu_read_lock();
1106 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1107 if (!deve) {
1108 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001109 return -ENODEV;
1110 }
1111 /* scsiAuthIntrLastCreation */
1112 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1113 INITIAL_JIFFIES) * 100 / HZ));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001114 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001115 return ret;
1116}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001117
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001118static ssize_t target_stat_auth_row_status_show(struct config_item *item,
1119 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001120{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001121 struct se_lun_acl *lacl = auth_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001122 struct se_node_acl *nacl = lacl->se_lun_nacl;
1123 struct se_dev_entry *deve;
1124 ssize_t ret;
1125
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001126 rcu_read_lock();
1127 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1128 if (!deve) {
1129 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001130 return -ENODEV;
1131 }
1132 /* FIXME: scsiAuthIntrRowStatus */
1133 ret = snprintf(page, PAGE_SIZE, "Ready\n");
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001134 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001135 return ret;
1136}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001137
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001138CONFIGFS_ATTR_RO(target_stat_auth_, inst);
1139CONFIGFS_ATTR_RO(target_stat_auth_, dev);
1140CONFIGFS_ATTR_RO(target_stat_auth_, port);
1141CONFIGFS_ATTR_RO(target_stat_auth_, indx);
1142CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
1143CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
1144CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
1145CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
1146CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
1147CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
1148CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
1149CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
1150CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
1151CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001152
1153static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001154 &target_stat_auth_attr_inst,
1155 &target_stat_auth_attr_dev,
1156 &target_stat_auth_attr_port,
1157 &target_stat_auth_attr_indx,
1158 &target_stat_auth_attr_dev_or_port,
1159 &target_stat_auth_attr_intr_name,
1160 &target_stat_auth_attr_map_indx,
1161 &target_stat_auth_attr_att_count,
1162 &target_stat_auth_attr_num_cmds,
1163 &target_stat_auth_attr_read_mbytes,
1164 &target_stat_auth_attr_write_mbytes,
1165 &target_stat_auth_attr_hs_num_cmds,
1166 &target_stat_auth_attr_creation_time,
1167 &target_stat_auth_attr_row_status,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001168 NULL,
1169};
1170
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001171static struct config_item_type target_stat_scsi_auth_intr_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001172 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1173 .ct_owner = THIS_MODULE,
1174};
1175
1176/*
1177 * SCSI Attached Initiator Port Table
1178 */
1179
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001180static struct se_lun_acl *iport_to_lacl(struct config_item *item)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001181{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001182 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
1183 struct se_ml_stat_grps, scsi_att_intr_port_group);
1184 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
1185}
1186
1187static ssize_t target_stat_iport_inst_show(struct config_item *item,
1188 char *page)
1189{
1190 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001191 struct se_node_acl *nacl = lacl->se_lun_nacl;
1192 struct se_dev_entry *deve;
1193 struct se_portal_group *tpg;
1194 ssize_t ret;
1195
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001196 rcu_read_lock();
1197 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1198 if (!deve) {
1199 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001200 return -ENODEV;
1201 }
1202 tpg = nacl->se_tpg;
1203 /* scsiInstIndex */
1204 ret = snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001205 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001206 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001207 return ret;
1208}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001209
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001210static ssize_t target_stat_iport_dev_show(struct config_item *item,
1211 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001212{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001213 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001214 struct se_node_acl *nacl = lacl->se_lun_nacl;
1215 struct se_dev_entry *deve;
1216 struct se_lun *lun;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001217 ssize_t ret;
1218
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001219 rcu_read_lock();
1220 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1221 if (!deve) {
1222 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001223 return -ENODEV;
1224 }
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001225 lun = rcu_dereference(deve->se_lun);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001226 /* scsiDeviceIndex */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001227 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
1228 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001229 return ret;
1230}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001231
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001232static ssize_t target_stat_iport_port_show(struct config_item *item,
1233 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001234{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001235 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001236 struct se_node_acl *nacl = lacl->se_lun_nacl;
1237 struct se_dev_entry *deve;
1238 struct se_portal_group *tpg;
1239 ssize_t ret;
1240
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001241 rcu_read_lock();
1242 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1243 if (!deve) {
1244 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001245 return -ENODEV;
1246 }
1247 tpg = nacl->se_tpg;
1248 /* scsiPortIndex */
Andy Grovere3d6f902011-07-19 08:55:10 +00001249 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001250 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001251 return ret;
1252}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001253
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001254static ssize_t target_stat_iport_indx_show(struct config_item *item,
1255 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001256{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001257 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001258 struct se_node_acl *nacl = lacl->se_lun_nacl;
1259 struct se_session *se_sess;
1260 struct se_portal_group *tpg;
1261 ssize_t ret;
1262
1263 spin_lock_irq(&nacl->nacl_sess_lock);
1264 se_sess = nacl->nacl_sess;
1265 if (!se_sess) {
1266 spin_unlock_irq(&nacl->nacl_sess_lock);
1267 return -ENODEV;
1268 }
1269
1270 tpg = nacl->se_tpg;
1271 /* scsiAttIntrPortIndex */
1272 ret = snprintf(page, PAGE_SIZE, "%u\n",
Andy Grovere3d6f902011-07-19 08:55:10 +00001273 tpg->se_tpg_tfo->sess_get_index(se_sess));
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001274 spin_unlock_irq(&nacl->nacl_sess_lock);
1275 return ret;
1276}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001277
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001278static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
1279 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001280{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001281 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001282 struct se_node_acl *nacl = lacl->se_lun_nacl;
1283 struct se_dev_entry *deve;
1284 ssize_t ret;
1285
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001286 rcu_read_lock();
1287 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1288 if (!deve) {
1289 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001290 return -ENODEV;
1291 }
1292 /* scsiAttIntrPortAuthIntrIdx */
1293 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -07001294 rcu_read_unlock();
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001295 return ret;
1296}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001297
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001298static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
1299 char *page)
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001300{
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001301 struct se_lun_acl *lacl = iport_to_lacl(item);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001302 struct se_node_acl *nacl = lacl->se_lun_nacl;
1303 struct se_session *se_sess;
1304 struct se_portal_group *tpg;
1305 ssize_t ret;
1306 unsigned char buf[64];
1307
1308 spin_lock_irq(&nacl->nacl_sess_lock);
1309 se_sess = nacl->nacl_sess;
1310 if (!se_sess) {
1311 spin_unlock_irq(&nacl->nacl_sess_lock);
1312 return -ENODEV;
1313 }
1314
1315 tpg = nacl->se_tpg;
1316 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1317 memset(buf, 0, 64);
Andy Grovere3d6f902011-07-19 08:55:10 +00001318 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
Jörn Engel8359cf42011-11-24 02:05:51 +01001319 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001320
1321 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1322 spin_unlock_irq(&nacl->nacl_sess_lock);
1323 return ret;
1324}
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001325
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001326CONFIGFS_ATTR_RO(target_stat_iport_, inst);
1327CONFIGFS_ATTR_RO(target_stat_iport_, dev);
1328CONFIGFS_ATTR_RO(target_stat_iport_, port);
1329CONFIGFS_ATTR_RO(target_stat_iport_, indx);
1330CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
1331CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001332
1333static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +02001334 &target_stat_iport_attr_inst,
1335 &target_stat_iport_attr_dev,
1336 &target_stat_iport_attr_port,
1337 &target_stat_iport_attr_indx,
1338 &target_stat_iport_attr_port_auth_indx,
1339 &target_stat_iport_attr_port_ident,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001340 NULL,
1341};
1342
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001343static struct config_item_type target_stat_scsi_att_intr_port_cit = {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001344 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1345 .ct_owner = THIS_MODULE,
1346};
1347
1348/*
1349 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1350 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1351 */
1352void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1353{
Andy Grovere3d6f902011-07-19 08:55:10 +00001354 struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001355
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);
Andy Grovere3d6f902011-07-19 08:55:10 +00001358 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001359 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1360
Andy Grovere3d6f902011-07-19 08:55:10 +00001361 ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1362 ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07001363 ml_stat_grp->default_groups[2] = NULL;
1364}