PM / sleep: Asynchronous threads for suspend_noirq
[linux/fpc-iii.git] / drivers / target / target_core_stat.c
blob03538994d2f7e1ee817d5b594fd33174079abaf3
1 /*******************************************************************************
2 * Filename: target_core_stat.c
4 * Modern ConfigFS group context specific statistics based on original
5 * target_core_mib.c code
7 * (c) Copyright 2006-2013 Datera, Inc.
9 * Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
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.
25 ******************************************************************************/
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>
32 #include <linux/utsname.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/configfs.h>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
40 #include <target/target_core_base.h>
41 #include <target/target_core_backend.h>
42 #include <target/target_core_fabric.h>
43 #include <target/target_core_configfs.h>
44 #include <target/configfs_macros.h>
46 #include "target_core_internal.h"
48 #ifndef INITIAL_JIFFIES
49 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
50 #endif
52 #define NONE "None"
53 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
55 #define SCSI_LU_INDEX 1
56 #define LU_COUNT 1
59 * SCSI Device Table
62 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
63 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
64 static struct target_stat_scsi_dev_attribute \
65 target_stat_scsi_dev_##_name = \
66 __CONFIGFS_EATTR(_name, _mode, \
67 target_stat_scsi_dev_show_attr_##_name, \
68 target_stat_scsi_dev_store_attr_##_name);
70 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
71 static struct target_stat_scsi_dev_attribute \
72 target_stat_scsi_dev_##_name = \
73 __CONFIGFS_EATTR_RO(_name, \
74 target_stat_scsi_dev_show_attr_##_name);
76 static ssize_t target_stat_scsi_dev_show_attr_inst(
77 struct se_dev_stat_grps *sgrps, char *page)
79 struct se_device *dev =
80 container_of(sgrps, struct se_device, dev_stat_grps);
81 struct se_hba *hba = dev->se_hba;
83 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
85 DEV_STAT_SCSI_DEV_ATTR_RO(inst);
87 static ssize_t target_stat_scsi_dev_show_attr_indx(
88 struct se_dev_stat_grps *sgrps, char *page)
90 struct se_device *dev =
91 container_of(sgrps, struct se_device, dev_stat_grps);
93 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
95 DEV_STAT_SCSI_DEV_ATTR_RO(indx);
97 static ssize_t target_stat_scsi_dev_show_attr_role(
98 struct se_dev_stat_grps *sgrps, char *page)
100 return snprintf(page, PAGE_SIZE, "Target\n");
102 DEV_STAT_SCSI_DEV_ATTR_RO(role);
104 static ssize_t target_stat_scsi_dev_show_attr_ports(
105 struct se_dev_stat_grps *sgrps, char *page)
107 struct se_device *dev =
108 container_of(sgrps, struct se_device, dev_stat_grps);
110 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
112 DEV_STAT_SCSI_DEV_ATTR_RO(ports);
114 CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
116 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
117 &target_stat_scsi_dev_inst.attr,
118 &target_stat_scsi_dev_indx.attr,
119 &target_stat_scsi_dev_role.attr,
120 &target_stat_scsi_dev_ports.attr,
121 NULL,
124 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
125 .show_attribute = target_stat_scsi_dev_attr_show,
126 .store_attribute = target_stat_scsi_dev_attr_store,
129 static struct config_item_type target_stat_scsi_dev_cit = {
130 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
131 .ct_attrs = target_stat_scsi_dev_attrs,
132 .ct_owner = THIS_MODULE,
136 * SCSI Target Device Table
139 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
140 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
141 static struct target_stat_scsi_tgt_dev_attribute \
142 target_stat_scsi_tgt_dev_##_name = \
143 __CONFIGFS_EATTR(_name, _mode, \
144 target_stat_scsi_tgt_dev_show_attr_##_name, \
145 target_stat_scsi_tgt_dev_store_attr_##_name);
147 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
148 static struct target_stat_scsi_tgt_dev_attribute \
149 target_stat_scsi_tgt_dev_##_name = \
150 __CONFIGFS_EATTR_RO(_name, \
151 target_stat_scsi_tgt_dev_show_attr_##_name);
153 static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
154 struct se_dev_stat_grps *sgrps, char *page)
156 struct se_device *dev =
157 container_of(sgrps, struct se_device, dev_stat_grps);
158 struct se_hba *hba = dev->se_hba;
160 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
162 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
164 static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
165 struct se_dev_stat_grps *sgrps, char *page)
167 struct se_device *dev =
168 container_of(sgrps, struct se_device, dev_stat_grps);
170 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
172 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
174 static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
175 struct se_dev_stat_grps *sgrps, char *page)
177 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
179 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
181 static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
182 struct se_dev_stat_grps *sgrps, char *page)
184 struct se_device *dev =
185 container_of(sgrps, struct se_device, dev_stat_grps);
187 if (dev->export_count)
188 return snprintf(page, PAGE_SIZE, "activated");
189 else
190 return snprintf(page, PAGE_SIZE, "deactivated");
192 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
194 static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
195 struct se_dev_stat_grps *sgrps, char *page)
197 struct se_device *dev =
198 container_of(sgrps, struct se_device, dev_stat_grps);
199 int non_accessible_lus;
201 if (dev->export_count)
202 non_accessible_lus = 0;
203 else
204 non_accessible_lus = 1;
206 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
208 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
210 static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
211 struct se_dev_stat_grps *sgrps, char *page)
213 struct se_device *dev =
214 container_of(sgrps, struct se_device, dev_stat_grps);
216 return snprintf(page, PAGE_SIZE, "%lu\n",
217 atomic_long_read(&dev->num_resets));
219 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
222 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
224 static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
225 &target_stat_scsi_tgt_dev_inst.attr,
226 &target_stat_scsi_tgt_dev_indx.attr,
227 &target_stat_scsi_tgt_dev_num_lus.attr,
228 &target_stat_scsi_tgt_dev_status.attr,
229 &target_stat_scsi_tgt_dev_non_access_lus.attr,
230 &target_stat_scsi_tgt_dev_resets.attr,
231 NULL,
234 static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
235 .show_attribute = target_stat_scsi_tgt_dev_attr_show,
236 .store_attribute = target_stat_scsi_tgt_dev_attr_store,
239 static struct config_item_type target_stat_scsi_tgt_dev_cit = {
240 .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
241 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
242 .ct_owner = THIS_MODULE,
246 * SCSI Logical Unit Table
249 CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
250 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
251 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
252 __CONFIGFS_EATTR(_name, _mode, \
253 target_stat_scsi_lu_show_attr_##_name, \
254 target_stat_scsi_lu_store_attr_##_name);
256 #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
257 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
258 __CONFIGFS_EATTR_RO(_name, \
259 target_stat_scsi_lu_show_attr_##_name);
261 static ssize_t target_stat_scsi_lu_show_attr_inst(
262 struct se_dev_stat_grps *sgrps, char *page)
264 struct se_device *dev =
265 container_of(sgrps, struct se_device, dev_stat_grps);
266 struct se_hba *hba = dev->se_hba;
268 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
270 DEV_STAT_SCSI_LU_ATTR_RO(inst);
272 static ssize_t target_stat_scsi_lu_show_attr_dev(
273 struct se_dev_stat_grps *sgrps, char *page)
275 struct se_device *dev =
276 container_of(sgrps, struct se_device, dev_stat_grps);
278 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
280 DEV_STAT_SCSI_LU_ATTR_RO(dev);
282 static ssize_t target_stat_scsi_lu_show_attr_indx(
283 struct se_dev_stat_grps *sgrps, char *page)
285 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
287 DEV_STAT_SCSI_LU_ATTR_RO(indx);
289 static ssize_t target_stat_scsi_lu_show_attr_lun(
290 struct se_dev_stat_grps *sgrps, char *page)
292 /* FIXME: scsiLuDefaultLun */
293 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
295 DEV_STAT_SCSI_LU_ATTR_RO(lun);
297 static ssize_t target_stat_scsi_lu_show_attr_lu_name(
298 struct se_dev_stat_grps *sgrps, char *page)
300 struct se_device *dev =
301 container_of(sgrps, struct se_device, dev_stat_grps);
303 /* scsiLuWwnName */
304 return snprintf(page, PAGE_SIZE, "%s\n",
305 (strlen(dev->t10_wwn.unit_serial)) ?
306 dev->t10_wwn.unit_serial : "None");
308 DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
310 static ssize_t target_stat_scsi_lu_show_attr_vend(
311 struct se_dev_stat_grps *sgrps, char *page)
313 struct se_device *dev =
314 container_of(sgrps, struct se_device, dev_stat_grps);
315 int i;
316 char str[sizeof(dev->t10_wwn.vendor)+1];
318 /* scsiLuVendorId */
319 for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
320 str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ?
321 dev->t10_wwn.vendor[i] : ' ';
322 str[i] = '\0';
323 return snprintf(page, PAGE_SIZE, "%s\n", str);
325 DEV_STAT_SCSI_LU_ATTR_RO(vend);
327 static ssize_t target_stat_scsi_lu_show_attr_prod(
328 struct se_dev_stat_grps *sgrps, char *page)
330 struct se_device *dev =
331 container_of(sgrps, struct se_device, dev_stat_grps);
332 int i;
333 char str[sizeof(dev->t10_wwn.model)+1];
335 /* scsiLuProductId */
336 for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
337 str[i] = ISPRINT(dev->t10_wwn.model[i]) ?
338 dev->t10_wwn.model[i] : ' ';
339 str[i] = '\0';
340 return snprintf(page, PAGE_SIZE, "%s\n", str);
342 DEV_STAT_SCSI_LU_ATTR_RO(prod);
344 static ssize_t target_stat_scsi_lu_show_attr_rev(
345 struct se_dev_stat_grps *sgrps, char *page)
347 struct se_device *dev =
348 container_of(sgrps, struct se_device, dev_stat_grps);
349 int i;
350 char str[sizeof(dev->t10_wwn.revision)+1];
352 /* scsiLuRevisionId */
353 for (i = 0; i < sizeof(dev->t10_wwn.revision); i++)
354 str[i] = ISPRINT(dev->t10_wwn.revision[i]) ?
355 dev->t10_wwn.revision[i] : ' ';
356 str[i] = '\0';
357 return snprintf(page, PAGE_SIZE, "%s\n", str);
359 DEV_STAT_SCSI_LU_ATTR_RO(rev);
361 static ssize_t target_stat_scsi_lu_show_attr_dev_type(
362 struct se_dev_stat_grps *sgrps, char *page)
364 struct se_device *dev =
365 container_of(sgrps, struct se_device, dev_stat_grps);
367 /* scsiLuPeripheralType */
368 return snprintf(page, PAGE_SIZE, "%u\n",
369 dev->transport->get_device_type(dev));
371 DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
373 static ssize_t target_stat_scsi_lu_show_attr_status(
374 struct se_dev_stat_grps *sgrps, char *page)
376 struct se_device *dev =
377 container_of(sgrps, struct se_device, dev_stat_grps);
379 /* scsiLuStatus */
380 return snprintf(page, PAGE_SIZE, "%s\n",
381 (dev->export_count) ? "available" : "notavailable");
383 DEV_STAT_SCSI_LU_ATTR_RO(status);
385 static ssize_t target_stat_scsi_lu_show_attr_state_bit(
386 struct se_dev_stat_grps *sgrps, char *page)
388 /* scsiLuState */
389 return snprintf(page, PAGE_SIZE, "exposed\n");
391 DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
393 static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
394 struct se_dev_stat_grps *sgrps, char *page)
396 struct se_device *dev =
397 container_of(sgrps, struct se_device, dev_stat_grps);
399 /* scsiLuNumCommands */
400 return snprintf(page, PAGE_SIZE, "%lu\n",
401 atomic_long_read(&dev->num_cmds));
403 DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
405 static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
406 struct se_dev_stat_grps *sgrps, char *page)
408 struct se_device *dev =
409 container_of(sgrps, struct se_device, dev_stat_grps);
411 /* scsiLuReadMegaBytes */
412 return snprintf(page, PAGE_SIZE, "%lu\n",
413 atomic_long_read(&dev->read_bytes) >> 20);
415 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
417 static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
418 struct se_dev_stat_grps *sgrps, char *page)
420 struct se_device *dev =
421 container_of(sgrps, struct se_device, dev_stat_grps);
423 /* scsiLuWrittenMegaBytes */
424 return snprintf(page, PAGE_SIZE, "%lu\n",
425 atomic_long_read(&dev->write_bytes) >> 20);
427 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
429 static ssize_t target_stat_scsi_lu_show_attr_resets(
430 struct se_dev_stat_grps *sgrps, char *page)
432 struct se_device *dev =
433 container_of(sgrps, struct se_device, dev_stat_grps);
435 /* scsiLuInResets */
436 return snprintf(page, PAGE_SIZE, "%lu\n", atomic_long_read(&dev->num_resets));
438 DEV_STAT_SCSI_LU_ATTR_RO(resets);
440 static ssize_t target_stat_scsi_lu_show_attr_full_stat(
441 struct se_dev_stat_grps *sgrps, char *page)
443 /* FIXME: scsiLuOutTaskSetFullStatus */
444 return snprintf(page, PAGE_SIZE, "%u\n", 0);
446 DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
448 static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
449 struct se_dev_stat_grps *sgrps, char *page)
451 /* FIXME: scsiLuHSInCommands */
452 return snprintf(page, PAGE_SIZE, "%u\n", 0);
454 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
456 static ssize_t target_stat_scsi_lu_show_attr_creation_time(
457 struct se_dev_stat_grps *sgrps, char *page)
459 struct se_device *dev =
460 container_of(sgrps, struct se_device, dev_stat_grps);
462 /* scsiLuCreationTime */
463 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
464 INITIAL_JIFFIES) * 100 / HZ));
466 DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
468 CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
470 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
471 &target_stat_scsi_lu_inst.attr,
472 &target_stat_scsi_lu_dev.attr,
473 &target_stat_scsi_lu_indx.attr,
474 &target_stat_scsi_lu_lun.attr,
475 &target_stat_scsi_lu_lu_name.attr,
476 &target_stat_scsi_lu_vend.attr,
477 &target_stat_scsi_lu_prod.attr,
478 &target_stat_scsi_lu_rev.attr,
479 &target_stat_scsi_lu_dev_type.attr,
480 &target_stat_scsi_lu_status.attr,
481 &target_stat_scsi_lu_state_bit.attr,
482 &target_stat_scsi_lu_num_cmds.attr,
483 &target_stat_scsi_lu_read_mbytes.attr,
484 &target_stat_scsi_lu_write_mbytes.attr,
485 &target_stat_scsi_lu_resets.attr,
486 &target_stat_scsi_lu_full_stat.attr,
487 &target_stat_scsi_lu_hs_num_cmds.attr,
488 &target_stat_scsi_lu_creation_time.attr,
489 NULL,
492 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
493 .show_attribute = target_stat_scsi_lu_attr_show,
494 .store_attribute = target_stat_scsi_lu_attr_store,
497 static struct config_item_type target_stat_scsi_lu_cit = {
498 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
499 .ct_attrs = target_stat_scsi_lu_attrs,
500 .ct_owner = THIS_MODULE,
504 * Called from target_core_configfs.c:target_core_make_subdev() to setup
505 * the target statistics groups + configfs CITs located in target_core_stat.c
507 void target_stat_setup_dev_default_groups(struct se_device *dev)
509 struct config_group *dev_stat_grp = &dev->dev_stat_grps.stat_group;
511 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
512 "scsi_dev", &target_stat_scsi_dev_cit);
513 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
514 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
515 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
516 "scsi_lu", &target_stat_scsi_lu_cit);
518 dev_stat_grp->default_groups[0] = &dev->dev_stat_grps.scsi_dev_group;
519 dev_stat_grp->default_groups[1] = &dev->dev_stat_grps.scsi_tgt_dev_group;
520 dev_stat_grp->default_groups[2] = &dev->dev_stat_grps.scsi_lu_group;
521 dev_stat_grp->default_groups[3] = NULL;
525 * SCSI Port Table
528 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
529 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
530 static struct target_stat_scsi_port_attribute \
531 target_stat_scsi_port_##_name = \
532 __CONFIGFS_EATTR(_name, _mode, \
533 target_stat_scsi_port_show_attr_##_name, \
534 target_stat_scsi_port_store_attr_##_name);
536 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
537 static struct target_stat_scsi_port_attribute \
538 target_stat_scsi_port_##_name = \
539 __CONFIGFS_EATTR_RO(_name, \
540 target_stat_scsi_port_show_attr_##_name);
542 static ssize_t target_stat_scsi_port_show_attr_inst(
543 struct se_port_stat_grps *pgrps, char *page)
545 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
546 struct se_port *sep;
547 struct se_device *dev = lun->lun_se_dev;
548 struct se_hba *hba;
549 ssize_t ret;
551 spin_lock(&lun->lun_sep_lock);
552 sep = lun->lun_sep;
553 if (!sep) {
554 spin_unlock(&lun->lun_sep_lock);
555 return -ENODEV;
557 hba = dev->se_hba;
558 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
559 spin_unlock(&lun->lun_sep_lock);
560 return ret;
562 DEV_STAT_SCSI_PORT_ATTR_RO(inst);
564 static ssize_t target_stat_scsi_port_show_attr_dev(
565 struct se_port_stat_grps *pgrps, char *page)
567 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
568 struct se_port *sep;
569 struct se_device *dev = lun->lun_se_dev;
570 ssize_t ret;
572 spin_lock(&lun->lun_sep_lock);
573 sep = lun->lun_sep;
574 if (!sep) {
575 spin_unlock(&lun->lun_sep_lock);
576 return -ENODEV;
578 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
579 spin_unlock(&lun->lun_sep_lock);
580 return ret;
582 DEV_STAT_SCSI_PORT_ATTR_RO(dev);
584 static ssize_t target_stat_scsi_port_show_attr_indx(
585 struct se_port_stat_grps *pgrps, char *page)
587 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
588 struct se_port *sep;
589 ssize_t ret;
591 spin_lock(&lun->lun_sep_lock);
592 sep = lun->lun_sep;
593 if (!sep) {
594 spin_unlock(&lun->lun_sep_lock);
595 return -ENODEV;
597 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
598 spin_unlock(&lun->lun_sep_lock);
599 return ret;
601 DEV_STAT_SCSI_PORT_ATTR_RO(indx);
603 static ssize_t target_stat_scsi_port_show_attr_role(
604 struct se_port_stat_grps *pgrps, char *page)
606 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
607 struct se_device *dev = lun->lun_se_dev;
608 struct se_port *sep;
609 ssize_t ret;
611 if (!dev)
612 return -ENODEV;
614 spin_lock(&lun->lun_sep_lock);
615 sep = lun->lun_sep;
616 if (!sep) {
617 spin_unlock(&lun->lun_sep_lock);
618 return -ENODEV;
620 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
621 spin_unlock(&lun->lun_sep_lock);
622 return ret;
624 DEV_STAT_SCSI_PORT_ATTR_RO(role);
626 static ssize_t target_stat_scsi_port_show_attr_busy_count(
627 struct se_port_stat_grps *pgrps, char *page)
629 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
630 struct se_port *sep;
631 ssize_t ret;
633 spin_lock(&lun->lun_sep_lock);
634 sep = lun->lun_sep;
635 if (!sep) {
636 spin_unlock(&lun->lun_sep_lock);
637 return -ENODEV;
639 /* FIXME: scsiPortBusyStatuses */
640 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
641 spin_unlock(&lun->lun_sep_lock);
642 return ret;
644 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
646 CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
648 static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
649 &target_stat_scsi_port_inst.attr,
650 &target_stat_scsi_port_dev.attr,
651 &target_stat_scsi_port_indx.attr,
652 &target_stat_scsi_port_role.attr,
653 &target_stat_scsi_port_busy_count.attr,
654 NULL,
657 static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
658 .show_attribute = target_stat_scsi_port_attr_show,
659 .store_attribute = target_stat_scsi_port_attr_store,
662 static struct config_item_type target_stat_scsi_port_cit = {
663 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
664 .ct_attrs = target_stat_scsi_port_attrs,
665 .ct_owner = THIS_MODULE,
669 * SCSI Target Port Table
671 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
672 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
673 static struct target_stat_scsi_tgt_port_attribute \
674 target_stat_scsi_tgt_port_##_name = \
675 __CONFIGFS_EATTR(_name, _mode, \
676 target_stat_scsi_tgt_port_show_attr_##_name, \
677 target_stat_scsi_tgt_port_store_attr_##_name);
679 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
680 static struct target_stat_scsi_tgt_port_attribute \
681 target_stat_scsi_tgt_port_##_name = \
682 __CONFIGFS_EATTR_RO(_name, \
683 target_stat_scsi_tgt_port_show_attr_##_name);
685 static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
686 struct se_port_stat_grps *pgrps, char *page)
688 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
689 struct se_device *dev = lun->lun_se_dev;
690 struct se_port *sep;
691 struct se_hba *hba;
692 ssize_t ret;
694 spin_lock(&lun->lun_sep_lock);
695 sep = lun->lun_sep;
696 if (!sep) {
697 spin_unlock(&lun->lun_sep_lock);
698 return -ENODEV;
700 hba = dev->se_hba;
701 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
702 spin_unlock(&lun->lun_sep_lock);
703 return ret;
705 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
707 static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
708 struct se_port_stat_grps *pgrps, char *page)
710 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
711 struct se_device *dev = lun->lun_se_dev;
712 struct se_port *sep;
713 ssize_t ret;
715 spin_lock(&lun->lun_sep_lock);
716 sep = lun->lun_sep;
717 if (!sep) {
718 spin_unlock(&lun->lun_sep_lock);
719 return -ENODEV;
721 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
722 spin_unlock(&lun->lun_sep_lock);
723 return ret;
725 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
727 static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
728 struct se_port_stat_grps *pgrps, char *page)
730 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
731 struct se_port *sep;
732 ssize_t ret;
734 spin_lock(&lun->lun_sep_lock);
735 sep = lun->lun_sep;
736 if (!sep) {
737 spin_unlock(&lun->lun_sep_lock);
738 return -ENODEV;
740 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
741 spin_unlock(&lun->lun_sep_lock);
742 return ret;
744 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
746 static ssize_t target_stat_scsi_tgt_port_show_attr_name(
747 struct se_port_stat_grps *pgrps, char *page)
749 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
750 struct se_port *sep;
751 struct se_portal_group *tpg;
752 ssize_t ret;
754 spin_lock(&lun->lun_sep_lock);
755 sep = lun->lun_sep;
756 if (!sep) {
757 spin_unlock(&lun->lun_sep_lock);
758 return -ENODEV;
760 tpg = sep->sep_tpg;
762 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
763 tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
764 spin_unlock(&lun->lun_sep_lock);
765 return ret;
767 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
769 static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
770 struct se_port_stat_grps *pgrps, char *page)
772 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
773 struct se_port *sep;
774 struct se_portal_group *tpg;
775 ssize_t ret;
777 spin_lock(&lun->lun_sep_lock);
778 sep = lun->lun_sep;
779 if (!sep) {
780 spin_unlock(&lun->lun_sep_lock);
781 return -ENODEV;
783 tpg = sep->sep_tpg;
785 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
786 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
787 tpg->se_tpg_tfo->tpg_get_tag(tpg));
788 spin_unlock(&lun->lun_sep_lock);
789 return ret;
791 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
793 static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
794 struct se_port_stat_grps *pgrps, char *page)
796 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
797 struct se_port *sep;
798 ssize_t ret;
800 spin_lock(&lun->lun_sep_lock);
801 sep = lun->lun_sep;
802 if (!sep) {
803 spin_unlock(&lun->lun_sep_lock);
804 return -ENODEV;
807 ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
808 spin_unlock(&lun->lun_sep_lock);
809 return ret;
811 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
813 static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
814 struct se_port_stat_grps *pgrps, char *page)
816 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
817 struct se_port *sep;
818 ssize_t ret;
820 spin_lock(&lun->lun_sep_lock);
821 sep = lun->lun_sep;
822 if (!sep) {
823 spin_unlock(&lun->lun_sep_lock);
824 return -ENODEV;
827 ret = snprintf(page, PAGE_SIZE, "%u\n",
828 (u32)(sep->sep_stats.rx_data_octets >> 20));
829 spin_unlock(&lun->lun_sep_lock);
830 return ret;
832 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
834 static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
835 struct se_port_stat_grps *pgrps, char *page)
837 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
838 struct se_port *sep;
839 ssize_t ret;
841 spin_lock(&lun->lun_sep_lock);
842 sep = lun->lun_sep;
843 if (!sep) {
844 spin_unlock(&lun->lun_sep_lock);
845 return -ENODEV;
848 ret = snprintf(page, PAGE_SIZE, "%u\n",
849 (u32)(sep->sep_stats.tx_data_octets >> 20));
850 spin_unlock(&lun->lun_sep_lock);
851 return ret;
853 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
855 static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
856 struct se_port_stat_grps *pgrps, char *page)
858 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
859 struct se_port *sep;
860 ssize_t ret;
862 spin_lock(&lun->lun_sep_lock);
863 sep = lun->lun_sep;
864 if (!sep) {
865 spin_unlock(&lun->lun_sep_lock);
866 return -ENODEV;
869 /* FIXME: scsiTgtPortHsInCommands */
870 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
871 spin_unlock(&lun->lun_sep_lock);
872 return ret;
874 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
876 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
877 scsi_tgt_port_group);
879 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
880 &target_stat_scsi_tgt_port_inst.attr,
881 &target_stat_scsi_tgt_port_dev.attr,
882 &target_stat_scsi_tgt_port_indx.attr,
883 &target_stat_scsi_tgt_port_name.attr,
884 &target_stat_scsi_tgt_port_port_index.attr,
885 &target_stat_scsi_tgt_port_in_cmds.attr,
886 &target_stat_scsi_tgt_port_write_mbytes.attr,
887 &target_stat_scsi_tgt_port_read_mbytes.attr,
888 &target_stat_scsi_tgt_port_hs_in_cmds.attr,
889 NULL,
892 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
893 .show_attribute = target_stat_scsi_tgt_port_attr_show,
894 .store_attribute = target_stat_scsi_tgt_port_attr_store,
897 static struct config_item_type target_stat_scsi_tgt_port_cit = {
898 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
899 .ct_attrs = target_stat_scsi_tgt_port_attrs,
900 .ct_owner = THIS_MODULE,
904 * SCSI Transport Table
905 o */
907 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
908 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
909 static struct target_stat_scsi_transport_attribute \
910 target_stat_scsi_transport_##_name = \
911 __CONFIGFS_EATTR(_name, _mode, \
912 target_stat_scsi_transport_show_attr_##_name, \
913 target_stat_scsi_transport_store_attr_##_name);
915 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
916 static struct target_stat_scsi_transport_attribute \
917 target_stat_scsi_transport_##_name = \
918 __CONFIGFS_EATTR_RO(_name, \
919 target_stat_scsi_transport_show_attr_##_name);
921 static ssize_t target_stat_scsi_transport_show_attr_inst(
922 struct se_port_stat_grps *pgrps, char *page)
924 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
925 struct se_device *dev = lun->lun_se_dev;
926 struct se_port *sep;
927 struct se_hba *hba;
928 ssize_t ret;
930 spin_lock(&lun->lun_sep_lock);
931 sep = lun->lun_sep;
932 if (!sep) {
933 spin_unlock(&lun->lun_sep_lock);
934 return -ENODEV;
937 hba = dev->se_hba;
938 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
939 spin_unlock(&lun->lun_sep_lock);
940 return ret;
942 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
944 static ssize_t target_stat_scsi_transport_show_attr_device(
945 struct se_port_stat_grps *pgrps, char *page)
947 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
948 struct se_port *sep;
949 struct se_portal_group *tpg;
950 ssize_t ret;
952 spin_lock(&lun->lun_sep_lock);
953 sep = lun->lun_sep;
954 if (!sep) {
955 spin_unlock(&lun->lun_sep_lock);
956 return -ENODEV;
958 tpg = sep->sep_tpg;
959 /* scsiTransportType */
960 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
961 tpg->se_tpg_tfo->get_fabric_name());
962 spin_unlock(&lun->lun_sep_lock);
963 return ret;
965 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
967 static ssize_t target_stat_scsi_transport_show_attr_indx(
968 struct se_port_stat_grps *pgrps, char *page)
970 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
971 struct se_port *sep;
972 struct se_portal_group *tpg;
973 ssize_t ret;
975 spin_lock(&lun->lun_sep_lock);
976 sep = lun->lun_sep;
977 if (!sep) {
978 spin_unlock(&lun->lun_sep_lock);
979 return -ENODEV;
981 tpg = sep->sep_tpg;
982 ret = snprintf(page, PAGE_SIZE, "%u\n",
983 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
984 spin_unlock(&lun->lun_sep_lock);
985 return ret;
987 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
989 static ssize_t target_stat_scsi_transport_show_attr_dev_name(
990 struct se_port_stat_grps *pgrps, char *page)
992 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
993 struct se_device *dev = lun->lun_se_dev;
994 struct se_port *sep;
995 struct se_portal_group *tpg;
996 struct t10_wwn *wwn;
997 ssize_t ret;
999 spin_lock(&lun->lun_sep_lock);
1000 sep = lun->lun_sep;
1001 if (!sep) {
1002 spin_unlock(&lun->lun_sep_lock);
1003 return -ENODEV;
1005 tpg = sep->sep_tpg;
1006 wwn = &dev->t10_wwn;
1007 /* scsiTransportDevName */
1008 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1009 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1010 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
1011 wwn->vendor);
1012 spin_unlock(&lun->lun_sep_lock);
1013 return ret;
1015 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1017 CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1018 scsi_transport_group);
1020 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1021 &target_stat_scsi_transport_inst.attr,
1022 &target_stat_scsi_transport_device.attr,
1023 &target_stat_scsi_transport_indx.attr,
1024 &target_stat_scsi_transport_dev_name.attr,
1025 NULL,
1028 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1029 .show_attribute = target_stat_scsi_transport_attr_show,
1030 .store_attribute = target_stat_scsi_transport_attr_store,
1033 static struct config_item_type target_stat_scsi_transport_cit = {
1034 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
1035 .ct_attrs = target_stat_scsi_transport_attrs,
1036 .ct_owner = THIS_MODULE,
1040 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1041 * the target port statistics groups + configfs CITs located in target_core_stat.c
1043 void target_stat_setup_port_default_groups(struct se_lun *lun)
1045 struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
1047 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
1048 "scsi_port", &target_stat_scsi_port_cit);
1049 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
1050 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1051 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
1052 "scsi_transport", &target_stat_scsi_transport_cit);
1054 port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
1055 port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
1056 port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
1057 port_stat_grp->default_groups[3] = NULL;
1061 * SCSI Authorized Initiator Table
1064 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1065 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1066 static struct target_stat_scsi_auth_intr_attribute \
1067 target_stat_scsi_auth_intr_##_name = \
1068 __CONFIGFS_EATTR(_name, _mode, \
1069 target_stat_scsi_auth_intr_show_attr_##_name, \
1070 target_stat_scsi_auth_intr_store_attr_##_name);
1072 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1073 static struct target_stat_scsi_auth_intr_attribute \
1074 target_stat_scsi_auth_intr_##_name = \
1075 __CONFIGFS_EATTR_RO(_name, \
1076 target_stat_scsi_auth_intr_show_attr_##_name);
1078 static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1079 struct se_ml_stat_grps *lgrps, char *page)
1081 struct se_lun_acl *lacl = container_of(lgrps,
1082 struct se_lun_acl, ml_stat_grps);
1083 struct se_node_acl *nacl = lacl->se_lun_nacl;
1084 struct se_dev_entry *deve;
1085 struct se_portal_group *tpg;
1086 ssize_t ret;
1088 spin_lock_irq(&nacl->device_list_lock);
1089 deve = nacl->device_list[lacl->mapped_lun];
1090 if (!deve->se_lun || !deve->se_lun_acl) {
1091 spin_unlock_irq(&nacl->device_list_lock);
1092 return -ENODEV;
1094 tpg = nacl->se_tpg;
1095 /* scsiInstIndex */
1096 ret = snprintf(page, PAGE_SIZE, "%u\n",
1097 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1098 spin_unlock_irq(&nacl->device_list_lock);
1099 return ret;
1101 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1103 static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1104 struct se_ml_stat_grps *lgrps, char *page)
1106 struct se_lun_acl *lacl = container_of(lgrps,
1107 struct se_lun_acl, ml_stat_grps);
1108 struct se_node_acl *nacl = lacl->se_lun_nacl;
1109 struct se_dev_entry *deve;
1110 struct se_lun *lun;
1111 ssize_t ret;
1113 spin_lock_irq(&nacl->device_list_lock);
1114 deve = nacl->device_list[lacl->mapped_lun];
1115 if (!deve->se_lun || !deve->se_lun_acl) {
1116 spin_unlock_irq(&nacl->device_list_lock);
1117 return -ENODEV;
1119 lun = deve->se_lun;
1120 /* scsiDeviceIndex */
1121 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1122 spin_unlock_irq(&nacl->device_list_lock);
1123 return ret;
1125 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1127 static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1128 struct se_ml_stat_grps *lgrps, char *page)
1130 struct se_lun_acl *lacl = container_of(lgrps,
1131 struct se_lun_acl, ml_stat_grps);
1132 struct se_node_acl *nacl = lacl->se_lun_nacl;
1133 struct se_dev_entry *deve;
1134 struct se_portal_group *tpg;
1135 ssize_t ret;
1137 spin_lock_irq(&nacl->device_list_lock);
1138 deve = nacl->device_list[lacl->mapped_lun];
1139 if (!deve->se_lun || !deve->se_lun_acl) {
1140 spin_unlock_irq(&nacl->device_list_lock);
1141 return -ENODEV;
1143 tpg = nacl->se_tpg;
1144 /* scsiAuthIntrTgtPortIndex */
1145 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1146 spin_unlock_irq(&nacl->device_list_lock);
1147 return ret;
1149 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1151 static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1152 struct se_ml_stat_grps *lgrps, char *page)
1154 struct se_lun_acl *lacl = container_of(lgrps,
1155 struct se_lun_acl, ml_stat_grps);
1156 struct se_node_acl *nacl = lacl->se_lun_nacl;
1157 struct se_dev_entry *deve;
1158 ssize_t ret;
1160 spin_lock_irq(&nacl->device_list_lock);
1161 deve = nacl->device_list[lacl->mapped_lun];
1162 if (!deve->se_lun || !deve->se_lun_acl) {
1163 spin_unlock_irq(&nacl->device_list_lock);
1164 return -ENODEV;
1166 /* scsiAuthIntrIndex */
1167 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1168 spin_unlock_irq(&nacl->device_list_lock);
1169 return ret;
1171 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1173 static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1174 struct se_ml_stat_grps *lgrps, char *page)
1176 struct se_lun_acl *lacl = container_of(lgrps,
1177 struct se_lun_acl, ml_stat_grps);
1178 struct se_node_acl *nacl = lacl->se_lun_nacl;
1179 struct se_dev_entry *deve;
1180 ssize_t ret;
1182 spin_lock_irq(&nacl->device_list_lock);
1183 deve = nacl->device_list[lacl->mapped_lun];
1184 if (!deve->se_lun || !deve->se_lun_acl) {
1185 spin_unlock_irq(&nacl->device_list_lock);
1186 return -ENODEV;
1188 /* scsiAuthIntrDevOrPort */
1189 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1190 spin_unlock_irq(&nacl->device_list_lock);
1191 return ret;
1193 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1195 static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1196 struct se_ml_stat_grps *lgrps, char *page)
1198 struct se_lun_acl *lacl = container_of(lgrps,
1199 struct se_lun_acl, ml_stat_grps);
1200 struct se_node_acl *nacl = lacl->se_lun_nacl;
1201 struct se_dev_entry *deve;
1202 ssize_t ret;
1204 spin_lock_irq(&nacl->device_list_lock);
1205 deve = nacl->device_list[lacl->mapped_lun];
1206 if (!deve->se_lun || !deve->se_lun_acl) {
1207 spin_unlock_irq(&nacl->device_list_lock);
1208 return -ENODEV;
1210 /* scsiAuthIntrName */
1211 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1212 spin_unlock_irq(&nacl->device_list_lock);
1213 return ret;
1215 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1217 static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1218 struct se_ml_stat_grps *lgrps, char *page)
1220 struct se_lun_acl *lacl = container_of(lgrps,
1221 struct se_lun_acl, ml_stat_grps);
1222 struct se_node_acl *nacl = lacl->se_lun_nacl;
1223 struct se_dev_entry *deve;
1224 ssize_t ret;
1226 spin_lock_irq(&nacl->device_list_lock);
1227 deve = nacl->device_list[lacl->mapped_lun];
1228 if (!deve->se_lun || !deve->se_lun_acl) {
1229 spin_unlock_irq(&nacl->device_list_lock);
1230 return -ENODEV;
1232 /* FIXME: scsiAuthIntrLunMapIndex */
1233 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1234 spin_unlock_irq(&nacl->device_list_lock);
1235 return ret;
1237 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1239 static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1240 struct se_ml_stat_grps *lgrps, char *page)
1242 struct se_lun_acl *lacl = container_of(lgrps,
1243 struct se_lun_acl, ml_stat_grps);
1244 struct se_node_acl *nacl = lacl->se_lun_nacl;
1245 struct se_dev_entry *deve;
1246 ssize_t ret;
1248 spin_lock_irq(&nacl->device_list_lock);
1249 deve = nacl->device_list[lacl->mapped_lun];
1250 if (!deve->se_lun || !deve->se_lun_acl) {
1251 spin_unlock_irq(&nacl->device_list_lock);
1252 return -ENODEV;
1254 /* scsiAuthIntrAttachedTimes */
1255 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1256 spin_unlock_irq(&nacl->device_list_lock);
1257 return ret;
1259 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1261 static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1262 struct se_ml_stat_grps *lgrps, char *page)
1264 struct se_lun_acl *lacl = container_of(lgrps,
1265 struct se_lun_acl, ml_stat_grps);
1266 struct se_node_acl *nacl = lacl->se_lun_nacl;
1267 struct se_dev_entry *deve;
1268 ssize_t ret;
1270 spin_lock_irq(&nacl->device_list_lock);
1271 deve = nacl->device_list[lacl->mapped_lun];
1272 if (!deve->se_lun || !deve->se_lun_acl) {
1273 spin_unlock_irq(&nacl->device_list_lock);
1274 return -ENODEV;
1276 /* scsiAuthIntrOutCommands */
1277 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1278 spin_unlock_irq(&nacl->device_list_lock);
1279 return ret;
1281 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1283 static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1284 struct se_ml_stat_grps *lgrps, char *page)
1286 struct se_lun_acl *lacl = container_of(lgrps,
1287 struct se_lun_acl, ml_stat_grps);
1288 struct se_node_acl *nacl = lacl->se_lun_nacl;
1289 struct se_dev_entry *deve;
1290 ssize_t ret;
1292 spin_lock_irq(&nacl->device_list_lock);
1293 deve = nacl->device_list[lacl->mapped_lun];
1294 if (!deve->se_lun || !deve->se_lun_acl) {
1295 spin_unlock_irq(&nacl->device_list_lock);
1296 return -ENODEV;
1298 /* scsiAuthIntrReadMegaBytes */
1299 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1300 spin_unlock_irq(&nacl->device_list_lock);
1301 return ret;
1303 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1305 static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1306 struct se_ml_stat_grps *lgrps, char *page)
1308 struct se_lun_acl *lacl = container_of(lgrps,
1309 struct se_lun_acl, ml_stat_grps);
1310 struct se_node_acl *nacl = lacl->se_lun_nacl;
1311 struct se_dev_entry *deve;
1312 ssize_t ret;
1314 spin_lock_irq(&nacl->device_list_lock);
1315 deve = nacl->device_list[lacl->mapped_lun];
1316 if (!deve->se_lun || !deve->se_lun_acl) {
1317 spin_unlock_irq(&nacl->device_list_lock);
1318 return -ENODEV;
1320 /* scsiAuthIntrWrittenMegaBytes */
1321 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1322 spin_unlock_irq(&nacl->device_list_lock);
1323 return ret;
1325 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1327 static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1328 struct se_ml_stat_grps *lgrps, char *page)
1330 struct se_lun_acl *lacl = container_of(lgrps,
1331 struct se_lun_acl, ml_stat_grps);
1332 struct se_node_acl *nacl = lacl->se_lun_nacl;
1333 struct se_dev_entry *deve;
1334 ssize_t ret;
1336 spin_lock_irq(&nacl->device_list_lock);
1337 deve = nacl->device_list[lacl->mapped_lun];
1338 if (!deve->se_lun || !deve->se_lun_acl) {
1339 spin_unlock_irq(&nacl->device_list_lock);
1340 return -ENODEV;
1342 /* FIXME: scsiAuthIntrHSOutCommands */
1343 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1344 spin_unlock_irq(&nacl->device_list_lock);
1345 return ret;
1347 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1349 static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1350 struct se_ml_stat_grps *lgrps, char *page)
1352 struct se_lun_acl *lacl = container_of(lgrps,
1353 struct se_lun_acl, ml_stat_grps);
1354 struct se_node_acl *nacl = lacl->se_lun_nacl;
1355 struct se_dev_entry *deve;
1356 ssize_t ret;
1358 spin_lock_irq(&nacl->device_list_lock);
1359 deve = nacl->device_list[lacl->mapped_lun];
1360 if (!deve->se_lun || !deve->se_lun_acl) {
1361 spin_unlock_irq(&nacl->device_list_lock);
1362 return -ENODEV;
1364 /* scsiAuthIntrLastCreation */
1365 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1366 INITIAL_JIFFIES) * 100 / HZ));
1367 spin_unlock_irq(&nacl->device_list_lock);
1368 return ret;
1370 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1372 static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1373 struct se_ml_stat_grps *lgrps, char *page)
1375 struct se_lun_acl *lacl = container_of(lgrps,
1376 struct se_lun_acl, ml_stat_grps);
1377 struct se_node_acl *nacl = lacl->se_lun_nacl;
1378 struct se_dev_entry *deve;
1379 ssize_t ret;
1381 spin_lock_irq(&nacl->device_list_lock);
1382 deve = nacl->device_list[lacl->mapped_lun];
1383 if (!deve->se_lun || !deve->se_lun_acl) {
1384 spin_unlock_irq(&nacl->device_list_lock);
1385 return -ENODEV;
1387 /* FIXME: scsiAuthIntrRowStatus */
1388 ret = snprintf(page, PAGE_SIZE, "Ready\n");
1389 spin_unlock_irq(&nacl->device_list_lock);
1390 return ret;
1392 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1394 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1395 scsi_auth_intr_group);
1397 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1398 &target_stat_scsi_auth_intr_inst.attr,
1399 &target_stat_scsi_auth_intr_dev.attr,
1400 &target_stat_scsi_auth_intr_port.attr,
1401 &target_stat_scsi_auth_intr_indx.attr,
1402 &target_stat_scsi_auth_intr_dev_or_port.attr,
1403 &target_stat_scsi_auth_intr_intr_name.attr,
1404 &target_stat_scsi_auth_intr_map_indx.attr,
1405 &target_stat_scsi_auth_intr_att_count.attr,
1406 &target_stat_scsi_auth_intr_num_cmds.attr,
1407 &target_stat_scsi_auth_intr_read_mbytes.attr,
1408 &target_stat_scsi_auth_intr_write_mbytes.attr,
1409 &target_stat_scsi_auth_intr_hs_num_cmds.attr,
1410 &target_stat_scsi_auth_intr_creation_time.attr,
1411 &target_stat_scsi_auth_intr_row_status.attr,
1412 NULL,
1415 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1416 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1417 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1420 static struct config_item_type target_stat_scsi_auth_intr_cit = {
1421 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1422 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1423 .ct_owner = THIS_MODULE,
1427 * SCSI Attached Initiator Port Table
1430 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1431 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1432 static struct target_stat_scsi_att_intr_port_attribute \
1433 target_stat_scsi_att_intr_port_##_name = \
1434 __CONFIGFS_EATTR(_name, _mode, \
1435 target_stat_scsi_att_intr_port_show_attr_##_name, \
1436 target_stat_scsi_att_intr_port_store_attr_##_name);
1438 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1439 static struct target_stat_scsi_att_intr_port_attribute \
1440 target_stat_scsi_att_intr_port_##_name = \
1441 __CONFIGFS_EATTR_RO(_name, \
1442 target_stat_scsi_att_intr_port_show_attr_##_name);
1444 static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1445 struct se_ml_stat_grps *lgrps, char *page)
1447 struct se_lun_acl *lacl = container_of(lgrps,
1448 struct se_lun_acl, ml_stat_grps);
1449 struct se_node_acl *nacl = lacl->se_lun_nacl;
1450 struct se_dev_entry *deve;
1451 struct se_portal_group *tpg;
1452 ssize_t ret;
1454 spin_lock_irq(&nacl->device_list_lock);
1455 deve = nacl->device_list[lacl->mapped_lun];
1456 if (!deve->se_lun || !deve->se_lun_acl) {
1457 spin_unlock_irq(&nacl->device_list_lock);
1458 return -ENODEV;
1460 tpg = nacl->se_tpg;
1461 /* scsiInstIndex */
1462 ret = snprintf(page, PAGE_SIZE, "%u\n",
1463 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1464 spin_unlock_irq(&nacl->device_list_lock);
1465 return ret;
1467 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1469 static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1470 struct se_ml_stat_grps *lgrps, char *page)
1472 struct se_lun_acl *lacl = container_of(lgrps,
1473 struct se_lun_acl, ml_stat_grps);
1474 struct se_node_acl *nacl = lacl->se_lun_nacl;
1475 struct se_dev_entry *deve;
1476 struct se_lun *lun;
1477 ssize_t ret;
1479 spin_lock_irq(&nacl->device_list_lock);
1480 deve = nacl->device_list[lacl->mapped_lun];
1481 if (!deve->se_lun || !deve->se_lun_acl) {
1482 spin_unlock_irq(&nacl->device_list_lock);
1483 return -ENODEV;
1485 lun = deve->se_lun;
1486 /* scsiDeviceIndex */
1487 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1488 spin_unlock_irq(&nacl->device_list_lock);
1489 return ret;
1491 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1493 static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1494 struct se_ml_stat_grps *lgrps, char *page)
1496 struct se_lun_acl *lacl = container_of(lgrps,
1497 struct se_lun_acl, ml_stat_grps);
1498 struct se_node_acl *nacl = lacl->se_lun_nacl;
1499 struct se_dev_entry *deve;
1500 struct se_portal_group *tpg;
1501 ssize_t ret;
1503 spin_lock_irq(&nacl->device_list_lock);
1504 deve = nacl->device_list[lacl->mapped_lun];
1505 if (!deve->se_lun || !deve->se_lun_acl) {
1506 spin_unlock_irq(&nacl->device_list_lock);
1507 return -ENODEV;
1509 tpg = nacl->se_tpg;
1510 /* scsiPortIndex */
1511 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1512 spin_unlock_irq(&nacl->device_list_lock);
1513 return ret;
1515 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1517 static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1518 struct se_ml_stat_grps *lgrps, char *page)
1520 struct se_lun_acl *lacl = container_of(lgrps,
1521 struct se_lun_acl, ml_stat_grps);
1522 struct se_node_acl *nacl = lacl->se_lun_nacl;
1523 struct se_session *se_sess;
1524 struct se_portal_group *tpg;
1525 ssize_t ret;
1527 spin_lock_irq(&nacl->nacl_sess_lock);
1528 se_sess = nacl->nacl_sess;
1529 if (!se_sess) {
1530 spin_unlock_irq(&nacl->nacl_sess_lock);
1531 return -ENODEV;
1534 tpg = nacl->se_tpg;
1535 /* scsiAttIntrPortIndex */
1536 ret = snprintf(page, PAGE_SIZE, "%u\n",
1537 tpg->se_tpg_tfo->sess_get_index(se_sess));
1538 spin_unlock_irq(&nacl->nacl_sess_lock);
1539 return ret;
1541 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1543 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1544 struct se_ml_stat_grps *lgrps, char *page)
1546 struct se_lun_acl *lacl = container_of(lgrps,
1547 struct se_lun_acl, ml_stat_grps);
1548 struct se_node_acl *nacl = lacl->se_lun_nacl;
1549 struct se_dev_entry *deve;
1550 ssize_t ret;
1552 spin_lock_irq(&nacl->device_list_lock);
1553 deve = nacl->device_list[lacl->mapped_lun];
1554 if (!deve->se_lun || !deve->se_lun_acl) {
1555 spin_unlock_irq(&nacl->device_list_lock);
1556 return -ENODEV;
1558 /* scsiAttIntrPortAuthIntrIdx */
1559 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1560 spin_unlock_irq(&nacl->device_list_lock);
1561 return ret;
1563 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1565 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1566 struct se_ml_stat_grps *lgrps, char *page)
1568 struct se_lun_acl *lacl = container_of(lgrps,
1569 struct se_lun_acl, ml_stat_grps);
1570 struct se_node_acl *nacl = lacl->se_lun_nacl;
1571 struct se_session *se_sess;
1572 struct se_portal_group *tpg;
1573 ssize_t ret;
1574 unsigned char buf[64];
1576 spin_lock_irq(&nacl->nacl_sess_lock);
1577 se_sess = nacl->nacl_sess;
1578 if (!se_sess) {
1579 spin_unlock_irq(&nacl->nacl_sess_lock);
1580 return -ENODEV;
1583 tpg = nacl->se_tpg;
1584 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1585 memset(buf, 0, 64);
1586 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1587 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
1589 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1590 spin_unlock_irq(&nacl->nacl_sess_lock);
1591 return ret;
1593 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1595 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1596 scsi_att_intr_port_group);
1598 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1599 &target_stat_scsi_att_intr_port_inst.attr,
1600 &target_stat_scsi_att_intr_port_dev.attr,
1601 &target_stat_scsi_att_intr_port_port.attr,
1602 &target_stat_scsi_att_intr_port_indx.attr,
1603 &target_stat_scsi_att_intr_port_port_auth_indx.attr,
1604 &target_stat_scsi_att_intr_port_port_ident.attr,
1605 NULL,
1608 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1609 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1610 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1613 static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1614 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1615 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1616 .ct_owner = THIS_MODULE,
1620 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1621 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1623 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1625 struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
1627 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1628 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1629 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1630 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1632 ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1633 ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
1634 ml_stat_grp->default_groups[2] = NULL;