Merge tag 'char-misc-3.9-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh...
[linux/fpc-iii.git] / drivers / target / target_core_stat.c
blobd154ce7971801c54a86bcf6f510246826aa67371
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-2012 RisingTide Systems LLC.
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/blkdev.h>
36 #include <linux/configfs.h>
37 #include <scsi/scsi.h>
38 #include <scsi/scsi_device.h>
39 #include <scsi/scsi_host.h>
41 #include <target/target_core_base.h>
42 #include <target/target_core_backend.h>
43 #include <target/target_core_fabric.h>
44 #include <target/target_core_configfs.h>
45 #include <target/configfs_macros.h>
47 #include "target_core_internal.h"
49 #ifndef INITIAL_JIFFIES
50 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
51 #endif
53 #define NONE "None"
54 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
56 #define SCSI_LU_INDEX 1
57 #define LU_COUNT 1
60 * SCSI Device Table
63 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
64 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
65 static struct target_stat_scsi_dev_attribute \
66 target_stat_scsi_dev_##_name = \
67 __CONFIGFS_EATTR(_name, _mode, \
68 target_stat_scsi_dev_show_attr_##_name, \
69 target_stat_scsi_dev_store_attr_##_name);
71 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
72 static struct target_stat_scsi_dev_attribute \
73 target_stat_scsi_dev_##_name = \
74 __CONFIGFS_EATTR_RO(_name, \
75 target_stat_scsi_dev_show_attr_##_name);
77 static ssize_t target_stat_scsi_dev_show_attr_inst(
78 struct se_dev_stat_grps *sgrps, char *page)
80 struct se_device *dev =
81 container_of(sgrps, struct se_device, dev_stat_grps);
82 struct se_hba *hba = dev->se_hba;
84 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
86 DEV_STAT_SCSI_DEV_ATTR_RO(inst);
88 static ssize_t target_stat_scsi_dev_show_attr_indx(
89 struct se_dev_stat_grps *sgrps, char *page)
91 struct se_device *dev =
92 container_of(sgrps, struct se_device, dev_stat_grps);
94 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
96 DEV_STAT_SCSI_DEV_ATTR_RO(indx);
98 static ssize_t target_stat_scsi_dev_show_attr_role(
99 struct se_dev_stat_grps *sgrps, char *page)
101 return snprintf(page, PAGE_SIZE, "Target\n");
103 DEV_STAT_SCSI_DEV_ATTR_RO(role);
105 static ssize_t target_stat_scsi_dev_show_attr_ports(
106 struct se_dev_stat_grps *sgrps, char *page)
108 struct se_device *dev =
109 container_of(sgrps, struct se_device, dev_stat_grps);
111 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
113 DEV_STAT_SCSI_DEV_ATTR_RO(ports);
115 CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
117 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
118 &target_stat_scsi_dev_inst.attr,
119 &target_stat_scsi_dev_indx.attr,
120 &target_stat_scsi_dev_role.attr,
121 &target_stat_scsi_dev_ports.attr,
122 NULL,
125 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
126 .show_attribute = target_stat_scsi_dev_attr_show,
127 .store_attribute = target_stat_scsi_dev_attr_store,
130 static struct config_item_type target_stat_scsi_dev_cit = {
131 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
132 .ct_attrs = target_stat_scsi_dev_attrs,
133 .ct_owner = THIS_MODULE,
137 * SCSI Target Device Table
140 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
141 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
142 static struct target_stat_scsi_tgt_dev_attribute \
143 target_stat_scsi_tgt_dev_##_name = \
144 __CONFIGFS_EATTR(_name, _mode, \
145 target_stat_scsi_tgt_dev_show_attr_##_name, \
146 target_stat_scsi_tgt_dev_store_attr_##_name);
148 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
149 static struct target_stat_scsi_tgt_dev_attribute \
150 target_stat_scsi_tgt_dev_##_name = \
151 __CONFIGFS_EATTR_RO(_name, \
152 target_stat_scsi_tgt_dev_show_attr_##_name);
154 static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
155 struct se_dev_stat_grps *sgrps, char *page)
157 struct se_device *dev =
158 container_of(sgrps, struct se_device, dev_stat_grps);
159 struct se_hba *hba = dev->se_hba;
161 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
163 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
165 static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
166 struct se_dev_stat_grps *sgrps, char *page)
168 struct se_device *dev =
169 container_of(sgrps, struct se_device, dev_stat_grps);
171 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
173 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
175 static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
176 struct se_dev_stat_grps *sgrps, char *page)
178 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
180 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
182 static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
183 struct se_dev_stat_grps *sgrps, char *page)
185 struct se_device *dev =
186 container_of(sgrps, struct se_device, dev_stat_grps);
188 if (dev->export_count)
189 return snprintf(page, PAGE_SIZE, "activated");
190 else
191 return snprintf(page, PAGE_SIZE, "deactivated");
193 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
195 static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
196 struct se_dev_stat_grps *sgrps, char *page)
198 struct se_device *dev =
199 container_of(sgrps, struct se_device, dev_stat_grps);
200 int non_accessible_lus;
202 if (dev->export_count)
203 non_accessible_lus = 0;
204 else
205 non_accessible_lus = 1;
207 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
209 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
211 static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
212 struct se_dev_stat_grps *sgrps, char *page)
214 struct se_device *dev =
215 container_of(sgrps, struct se_device, dev_stat_grps);
217 return snprintf(page, PAGE_SIZE, "%u\n", 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, "%llu\n",
401 (unsigned long long)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, "%u\n", (u32)(dev->read_bytes >> 20));
414 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
416 static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
417 struct se_dev_stat_grps *sgrps, char *page)
419 struct se_device *dev =
420 container_of(sgrps, struct se_device, dev_stat_grps);
422 /* scsiLuWrittenMegaBytes */
423 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
425 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
427 static ssize_t target_stat_scsi_lu_show_attr_resets(
428 struct se_dev_stat_grps *sgrps, char *page)
430 struct se_device *dev =
431 container_of(sgrps, struct se_device, dev_stat_grps);
433 /* scsiLuInResets */
434 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
436 DEV_STAT_SCSI_LU_ATTR_RO(resets);
438 static ssize_t target_stat_scsi_lu_show_attr_full_stat(
439 struct se_dev_stat_grps *sgrps, char *page)
441 /* FIXME: scsiLuOutTaskSetFullStatus */
442 return snprintf(page, PAGE_SIZE, "%u\n", 0);
444 DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
446 static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
447 struct se_dev_stat_grps *sgrps, char *page)
449 /* FIXME: scsiLuHSInCommands */
450 return snprintf(page, PAGE_SIZE, "%u\n", 0);
452 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
454 static ssize_t target_stat_scsi_lu_show_attr_creation_time(
455 struct se_dev_stat_grps *sgrps, char *page)
457 struct se_device *dev =
458 container_of(sgrps, struct se_device, dev_stat_grps);
460 /* scsiLuCreationTime */
461 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
462 INITIAL_JIFFIES) * 100 / HZ));
464 DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
466 CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
468 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
469 &target_stat_scsi_lu_inst.attr,
470 &target_stat_scsi_lu_dev.attr,
471 &target_stat_scsi_lu_indx.attr,
472 &target_stat_scsi_lu_lun.attr,
473 &target_stat_scsi_lu_lu_name.attr,
474 &target_stat_scsi_lu_vend.attr,
475 &target_stat_scsi_lu_prod.attr,
476 &target_stat_scsi_lu_rev.attr,
477 &target_stat_scsi_lu_dev_type.attr,
478 &target_stat_scsi_lu_status.attr,
479 &target_stat_scsi_lu_state_bit.attr,
480 &target_stat_scsi_lu_num_cmds.attr,
481 &target_stat_scsi_lu_read_mbytes.attr,
482 &target_stat_scsi_lu_write_mbytes.attr,
483 &target_stat_scsi_lu_resets.attr,
484 &target_stat_scsi_lu_full_stat.attr,
485 &target_stat_scsi_lu_hs_num_cmds.attr,
486 &target_stat_scsi_lu_creation_time.attr,
487 NULL,
490 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
491 .show_attribute = target_stat_scsi_lu_attr_show,
492 .store_attribute = target_stat_scsi_lu_attr_store,
495 static struct config_item_type target_stat_scsi_lu_cit = {
496 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
497 .ct_attrs = target_stat_scsi_lu_attrs,
498 .ct_owner = THIS_MODULE,
502 * Called from target_core_configfs.c:target_core_make_subdev() to setup
503 * the target statistics groups + configfs CITs located in target_core_stat.c
505 void target_stat_setup_dev_default_groups(struct se_device *dev)
507 struct config_group *dev_stat_grp = &dev->dev_stat_grps.stat_group;
509 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
510 "scsi_dev", &target_stat_scsi_dev_cit);
511 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
512 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
513 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
514 "scsi_lu", &target_stat_scsi_lu_cit);
516 dev_stat_grp->default_groups[0] = &dev->dev_stat_grps.scsi_dev_group;
517 dev_stat_grp->default_groups[1] = &dev->dev_stat_grps.scsi_tgt_dev_group;
518 dev_stat_grp->default_groups[2] = &dev->dev_stat_grps.scsi_lu_group;
519 dev_stat_grp->default_groups[3] = NULL;
523 * SCSI Port Table
526 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
527 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
528 static struct target_stat_scsi_port_attribute \
529 target_stat_scsi_port_##_name = \
530 __CONFIGFS_EATTR(_name, _mode, \
531 target_stat_scsi_port_show_attr_##_name, \
532 target_stat_scsi_port_store_attr_##_name);
534 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
535 static struct target_stat_scsi_port_attribute \
536 target_stat_scsi_port_##_name = \
537 __CONFIGFS_EATTR_RO(_name, \
538 target_stat_scsi_port_show_attr_##_name);
540 static ssize_t target_stat_scsi_port_show_attr_inst(
541 struct se_port_stat_grps *pgrps, char *page)
543 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
544 struct se_port *sep;
545 struct se_device *dev = lun->lun_se_dev;
546 struct se_hba *hba;
547 ssize_t ret;
549 spin_lock(&lun->lun_sep_lock);
550 sep = lun->lun_sep;
551 if (!sep) {
552 spin_unlock(&lun->lun_sep_lock);
553 return -ENODEV;
555 hba = dev->se_hba;
556 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
557 spin_unlock(&lun->lun_sep_lock);
558 return ret;
560 DEV_STAT_SCSI_PORT_ATTR_RO(inst);
562 static ssize_t target_stat_scsi_port_show_attr_dev(
563 struct se_port_stat_grps *pgrps, char *page)
565 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
566 struct se_port *sep;
567 struct se_device *dev = lun->lun_se_dev;
568 ssize_t ret;
570 spin_lock(&lun->lun_sep_lock);
571 sep = lun->lun_sep;
572 if (!sep) {
573 spin_unlock(&lun->lun_sep_lock);
574 return -ENODEV;
576 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
577 spin_unlock(&lun->lun_sep_lock);
578 return ret;
580 DEV_STAT_SCSI_PORT_ATTR_RO(dev);
582 static ssize_t target_stat_scsi_port_show_attr_indx(
583 struct se_port_stat_grps *pgrps, char *page)
585 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
586 struct se_port *sep;
587 ssize_t ret;
589 spin_lock(&lun->lun_sep_lock);
590 sep = lun->lun_sep;
591 if (!sep) {
592 spin_unlock(&lun->lun_sep_lock);
593 return -ENODEV;
595 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
596 spin_unlock(&lun->lun_sep_lock);
597 return ret;
599 DEV_STAT_SCSI_PORT_ATTR_RO(indx);
601 static ssize_t target_stat_scsi_port_show_attr_role(
602 struct se_port_stat_grps *pgrps, char *page)
604 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
605 struct se_device *dev = lun->lun_se_dev;
606 struct se_port *sep;
607 ssize_t ret;
609 if (!dev)
610 return -ENODEV;
612 spin_lock(&lun->lun_sep_lock);
613 sep = lun->lun_sep;
614 if (!sep) {
615 spin_unlock(&lun->lun_sep_lock);
616 return -ENODEV;
618 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
619 spin_unlock(&lun->lun_sep_lock);
620 return ret;
622 DEV_STAT_SCSI_PORT_ATTR_RO(role);
624 static ssize_t target_stat_scsi_port_show_attr_busy_count(
625 struct se_port_stat_grps *pgrps, char *page)
627 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
628 struct se_port *sep;
629 ssize_t ret;
631 spin_lock(&lun->lun_sep_lock);
632 sep = lun->lun_sep;
633 if (!sep) {
634 spin_unlock(&lun->lun_sep_lock);
635 return -ENODEV;
637 /* FIXME: scsiPortBusyStatuses */
638 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
639 spin_unlock(&lun->lun_sep_lock);
640 return ret;
642 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
644 CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
646 static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
647 &target_stat_scsi_port_inst.attr,
648 &target_stat_scsi_port_dev.attr,
649 &target_stat_scsi_port_indx.attr,
650 &target_stat_scsi_port_role.attr,
651 &target_stat_scsi_port_busy_count.attr,
652 NULL,
655 static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
656 .show_attribute = target_stat_scsi_port_attr_show,
657 .store_attribute = target_stat_scsi_port_attr_store,
660 static struct config_item_type target_stat_scsi_port_cit = {
661 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
662 .ct_attrs = target_stat_scsi_port_attrs,
663 .ct_owner = THIS_MODULE,
667 * SCSI Target Port Table
669 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
670 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
671 static struct target_stat_scsi_tgt_port_attribute \
672 target_stat_scsi_tgt_port_##_name = \
673 __CONFIGFS_EATTR(_name, _mode, \
674 target_stat_scsi_tgt_port_show_attr_##_name, \
675 target_stat_scsi_tgt_port_store_attr_##_name);
677 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
678 static struct target_stat_scsi_tgt_port_attribute \
679 target_stat_scsi_tgt_port_##_name = \
680 __CONFIGFS_EATTR_RO(_name, \
681 target_stat_scsi_tgt_port_show_attr_##_name);
683 static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
684 struct se_port_stat_grps *pgrps, char *page)
686 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
687 struct se_device *dev = lun->lun_se_dev;
688 struct se_port *sep;
689 struct se_hba *hba;
690 ssize_t ret;
692 spin_lock(&lun->lun_sep_lock);
693 sep = lun->lun_sep;
694 if (!sep) {
695 spin_unlock(&lun->lun_sep_lock);
696 return -ENODEV;
698 hba = dev->se_hba;
699 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
700 spin_unlock(&lun->lun_sep_lock);
701 return ret;
703 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
705 static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
706 struct se_port_stat_grps *pgrps, char *page)
708 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
709 struct se_device *dev = lun->lun_se_dev;
710 struct se_port *sep;
711 ssize_t ret;
713 spin_lock(&lun->lun_sep_lock);
714 sep = lun->lun_sep;
715 if (!sep) {
716 spin_unlock(&lun->lun_sep_lock);
717 return -ENODEV;
719 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
720 spin_unlock(&lun->lun_sep_lock);
721 return ret;
723 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
725 static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
726 struct se_port_stat_grps *pgrps, char *page)
728 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
729 struct se_port *sep;
730 ssize_t ret;
732 spin_lock(&lun->lun_sep_lock);
733 sep = lun->lun_sep;
734 if (!sep) {
735 spin_unlock(&lun->lun_sep_lock);
736 return -ENODEV;
738 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
739 spin_unlock(&lun->lun_sep_lock);
740 return ret;
742 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
744 static ssize_t target_stat_scsi_tgt_port_show_attr_name(
745 struct se_port_stat_grps *pgrps, char *page)
747 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
748 struct se_port *sep;
749 struct se_portal_group *tpg;
750 ssize_t ret;
752 spin_lock(&lun->lun_sep_lock);
753 sep = lun->lun_sep;
754 if (!sep) {
755 spin_unlock(&lun->lun_sep_lock);
756 return -ENODEV;
758 tpg = sep->sep_tpg;
760 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
761 tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
762 spin_unlock(&lun->lun_sep_lock);
763 return ret;
765 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
767 static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
768 struct se_port_stat_grps *pgrps, char *page)
770 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
771 struct se_port *sep;
772 struct se_portal_group *tpg;
773 ssize_t ret;
775 spin_lock(&lun->lun_sep_lock);
776 sep = lun->lun_sep;
777 if (!sep) {
778 spin_unlock(&lun->lun_sep_lock);
779 return -ENODEV;
781 tpg = sep->sep_tpg;
783 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
784 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
785 tpg->se_tpg_tfo->tpg_get_tag(tpg));
786 spin_unlock(&lun->lun_sep_lock);
787 return ret;
789 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
791 static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
792 struct se_port_stat_grps *pgrps, char *page)
794 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
795 struct se_port *sep;
796 ssize_t ret;
798 spin_lock(&lun->lun_sep_lock);
799 sep = lun->lun_sep;
800 if (!sep) {
801 spin_unlock(&lun->lun_sep_lock);
802 return -ENODEV;
805 ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
806 spin_unlock(&lun->lun_sep_lock);
807 return ret;
809 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
811 static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
812 struct se_port_stat_grps *pgrps, char *page)
814 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
815 struct se_port *sep;
816 ssize_t ret;
818 spin_lock(&lun->lun_sep_lock);
819 sep = lun->lun_sep;
820 if (!sep) {
821 spin_unlock(&lun->lun_sep_lock);
822 return -ENODEV;
825 ret = snprintf(page, PAGE_SIZE, "%u\n",
826 (u32)(sep->sep_stats.rx_data_octets >> 20));
827 spin_unlock(&lun->lun_sep_lock);
828 return ret;
830 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
832 static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
833 struct se_port_stat_grps *pgrps, char *page)
835 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
836 struct se_port *sep;
837 ssize_t ret;
839 spin_lock(&lun->lun_sep_lock);
840 sep = lun->lun_sep;
841 if (!sep) {
842 spin_unlock(&lun->lun_sep_lock);
843 return -ENODEV;
846 ret = snprintf(page, PAGE_SIZE, "%u\n",
847 (u32)(sep->sep_stats.tx_data_octets >> 20));
848 spin_unlock(&lun->lun_sep_lock);
849 return ret;
851 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
853 static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
854 struct se_port_stat_grps *pgrps, char *page)
856 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
857 struct se_port *sep;
858 ssize_t ret;
860 spin_lock(&lun->lun_sep_lock);
861 sep = lun->lun_sep;
862 if (!sep) {
863 spin_unlock(&lun->lun_sep_lock);
864 return -ENODEV;
867 /* FIXME: scsiTgtPortHsInCommands */
868 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
869 spin_unlock(&lun->lun_sep_lock);
870 return ret;
872 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
874 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
875 scsi_tgt_port_group);
877 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
878 &target_stat_scsi_tgt_port_inst.attr,
879 &target_stat_scsi_tgt_port_dev.attr,
880 &target_stat_scsi_tgt_port_indx.attr,
881 &target_stat_scsi_tgt_port_name.attr,
882 &target_stat_scsi_tgt_port_port_index.attr,
883 &target_stat_scsi_tgt_port_in_cmds.attr,
884 &target_stat_scsi_tgt_port_write_mbytes.attr,
885 &target_stat_scsi_tgt_port_read_mbytes.attr,
886 &target_stat_scsi_tgt_port_hs_in_cmds.attr,
887 NULL,
890 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
891 .show_attribute = target_stat_scsi_tgt_port_attr_show,
892 .store_attribute = target_stat_scsi_tgt_port_attr_store,
895 static struct config_item_type target_stat_scsi_tgt_port_cit = {
896 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
897 .ct_attrs = target_stat_scsi_tgt_port_attrs,
898 .ct_owner = THIS_MODULE,
902 * SCSI Transport Table
903 o */
905 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
906 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
907 static struct target_stat_scsi_transport_attribute \
908 target_stat_scsi_transport_##_name = \
909 __CONFIGFS_EATTR(_name, _mode, \
910 target_stat_scsi_transport_show_attr_##_name, \
911 target_stat_scsi_transport_store_attr_##_name);
913 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
914 static struct target_stat_scsi_transport_attribute \
915 target_stat_scsi_transport_##_name = \
916 __CONFIGFS_EATTR_RO(_name, \
917 target_stat_scsi_transport_show_attr_##_name);
919 static ssize_t target_stat_scsi_transport_show_attr_inst(
920 struct se_port_stat_grps *pgrps, char *page)
922 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
923 struct se_device *dev = lun->lun_se_dev;
924 struct se_port *sep;
925 struct se_hba *hba;
926 ssize_t ret;
928 spin_lock(&lun->lun_sep_lock);
929 sep = lun->lun_sep;
930 if (!sep) {
931 spin_unlock(&lun->lun_sep_lock);
932 return -ENODEV;
935 hba = dev->se_hba;
936 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
937 spin_unlock(&lun->lun_sep_lock);
938 return ret;
940 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
942 static ssize_t target_stat_scsi_transport_show_attr_device(
943 struct se_port_stat_grps *pgrps, char *page)
945 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
946 struct se_port *sep;
947 struct se_portal_group *tpg;
948 ssize_t ret;
950 spin_lock(&lun->lun_sep_lock);
951 sep = lun->lun_sep;
952 if (!sep) {
953 spin_unlock(&lun->lun_sep_lock);
954 return -ENODEV;
956 tpg = sep->sep_tpg;
957 /* scsiTransportType */
958 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
959 tpg->se_tpg_tfo->get_fabric_name());
960 spin_unlock(&lun->lun_sep_lock);
961 return ret;
963 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
965 static ssize_t target_stat_scsi_transport_show_attr_indx(
966 struct se_port_stat_grps *pgrps, char *page)
968 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
969 struct se_port *sep;
970 struct se_portal_group *tpg;
971 ssize_t ret;
973 spin_lock(&lun->lun_sep_lock);
974 sep = lun->lun_sep;
975 if (!sep) {
976 spin_unlock(&lun->lun_sep_lock);
977 return -ENODEV;
979 tpg = sep->sep_tpg;
980 ret = snprintf(page, PAGE_SIZE, "%u\n",
981 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
982 spin_unlock(&lun->lun_sep_lock);
983 return ret;
985 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
987 static ssize_t target_stat_scsi_transport_show_attr_dev_name(
988 struct se_port_stat_grps *pgrps, char *page)
990 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
991 struct se_device *dev = lun->lun_se_dev;
992 struct se_port *sep;
993 struct se_portal_group *tpg;
994 struct t10_wwn *wwn;
995 ssize_t ret;
997 spin_lock(&lun->lun_sep_lock);
998 sep = lun->lun_sep;
999 if (!sep) {
1000 spin_unlock(&lun->lun_sep_lock);
1001 return -ENODEV;
1003 tpg = sep->sep_tpg;
1004 wwn = &dev->t10_wwn;
1005 /* scsiTransportDevName */
1006 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1007 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1008 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
1009 wwn->vendor);
1010 spin_unlock(&lun->lun_sep_lock);
1011 return ret;
1013 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1015 CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1016 scsi_transport_group);
1018 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1019 &target_stat_scsi_transport_inst.attr,
1020 &target_stat_scsi_transport_device.attr,
1021 &target_stat_scsi_transport_indx.attr,
1022 &target_stat_scsi_transport_dev_name.attr,
1023 NULL,
1026 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1027 .show_attribute = target_stat_scsi_transport_attr_show,
1028 .store_attribute = target_stat_scsi_transport_attr_store,
1031 static struct config_item_type target_stat_scsi_transport_cit = {
1032 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
1033 .ct_attrs = target_stat_scsi_transport_attrs,
1034 .ct_owner = THIS_MODULE,
1038 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1039 * the target port statistics groups + configfs CITs located in target_core_stat.c
1041 void target_stat_setup_port_default_groups(struct se_lun *lun)
1043 struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
1045 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
1046 "scsi_port", &target_stat_scsi_port_cit);
1047 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
1048 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1049 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
1050 "scsi_transport", &target_stat_scsi_transport_cit);
1052 port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
1053 port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
1054 port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
1055 port_stat_grp->default_groups[3] = NULL;
1059 * SCSI Authorized Initiator Table
1062 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1063 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1064 static struct target_stat_scsi_auth_intr_attribute \
1065 target_stat_scsi_auth_intr_##_name = \
1066 __CONFIGFS_EATTR(_name, _mode, \
1067 target_stat_scsi_auth_intr_show_attr_##_name, \
1068 target_stat_scsi_auth_intr_store_attr_##_name);
1070 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1071 static struct target_stat_scsi_auth_intr_attribute \
1072 target_stat_scsi_auth_intr_##_name = \
1073 __CONFIGFS_EATTR_RO(_name, \
1074 target_stat_scsi_auth_intr_show_attr_##_name);
1076 static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1077 struct se_ml_stat_grps *lgrps, char *page)
1079 struct se_lun_acl *lacl = container_of(lgrps,
1080 struct se_lun_acl, ml_stat_grps);
1081 struct se_node_acl *nacl = lacl->se_lun_nacl;
1082 struct se_dev_entry *deve;
1083 struct se_portal_group *tpg;
1084 ssize_t ret;
1086 spin_lock_irq(&nacl->device_list_lock);
1087 deve = nacl->device_list[lacl->mapped_lun];
1088 if (!deve->se_lun || !deve->se_lun_acl) {
1089 spin_unlock_irq(&nacl->device_list_lock);
1090 return -ENODEV;
1092 tpg = nacl->se_tpg;
1093 /* scsiInstIndex */
1094 ret = snprintf(page, PAGE_SIZE, "%u\n",
1095 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1096 spin_unlock_irq(&nacl->device_list_lock);
1097 return ret;
1099 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1101 static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1102 struct se_ml_stat_grps *lgrps, char *page)
1104 struct se_lun_acl *lacl = container_of(lgrps,
1105 struct se_lun_acl, ml_stat_grps);
1106 struct se_node_acl *nacl = lacl->se_lun_nacl;
1107 struct se_dev_entry *deve;
1108 struct se_lun *lun;
1109 ssize_t ret;
1111 spin_lock_irq(&nacl->device_list_lock);
1112 deve = nacl->device_list[lacl->mapped_lun];
1113 if (!deve->se_lun || !deve->se_lun_acl) {
1114 spin_unlock_irq(&nacl->device_list_lock);
1115 return -ENODEV;
1117 lun = deve->se_lun;
1118 /* scsiDeviceIndex */
1119 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1120 spin_unlock_irq(&nacl->device_list_lock);
1121 return ret;
1123 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1125 static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1126 struct se_ml_stat_grps *lgrps, char *page)
1128 struct se_lun_acl *lacl = container_of(lgrps,
1129 struct se_lun_acl, ml_stat_grps);
1130 struct se_node_acl *nacl = lacl->se_lun_nacl;
1131 struct se_dev_entry *deve;
1132 struct se_portal_group *tpg;
1133 ssize_t ret;
1135 spin_lock_irq(&nacl->device_list_lock);
1136 deve = nacl->device_list[lacl->mapped_lun];
1137 if (!deve->se_lun || !deve->se_lun_acl) {
1138 spin_unlock_irq(&nacl->device_list_lock);
1139 return -ENODEV;
1141 tpg = nacl->se_tpg;
1142 /* scsiAuthIntrTgtPortIndex */
1143 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1144 spin_unlock_irq(&nacl->device_list_lock);
1145 return ret;
1147 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1149 static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1150 struct se_ml_stat_grps *lgrps, char *page)
1152 struct se_lun_acl *lacl = container_of(lgrps,
1153 struct se_lun_acl, ml_stat_grps);
1154 struct se_node_acl *nacl = lacl->se_lun_nacl;
1155 struct se_dev_entry *deve;
1156 ssize_t ret;
1158 spin_lock_irq(&nacl->device_list_lock);
1159 deve = nacl->device_list[lacl->mapped_lun];
1160 if (!deve->se_lun || !deve->se_lun_acl) {
1161 spin_unlock_irq(&nacl->device_list_lock);
1162 return -ENODEV;
1164 /* scsiAuthIntrIndex */
1165 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1166 spin_unlock_irq(&nacl->device_list_lock);
1167 return ret;
1169 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1171 static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1172 struct se_ml_stat_grps *lgrps, char *page)
1174 struct se_lun_acl *lacl = container_of(lgrps,
1175 struct se_lun_acl, ml_stat_grps);
1176 struct se_node_acl *nacl = lacl->se_lun_nacl;
1177 struct se_dev_entry *deve;
1178 ssize_t ret;
1180 spin_lock_irq(&nacl->device_list_lock);
1181 deve = nacl->device_list[lacl->mapped_lun];
1182 if (!deve->se_lun || !deve->se_lun_acl) {
1183 spin_unlock_irq(&nacl->device_list_lock);
1184 return -ENODEV;
1186 /* scsiAuthIntrDevOrPort */
1187 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1188 spin_unlock_irq(&nacl->device_list_lock);
1189 return ret;
1191 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1193 static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1194 struct se_ml_stat_grps *lgrps, char *page)
1196 struct se_lun_acl *lacl = container_of(lgrps,
1197 struct se_lun_acl, ml_stat_grps);
1198 struct se_node_acl *nacl = lacl->se_lun_nacl;
1199 struct se_dev_entry *deve;
1200 ssize_t ret;
1202 spin_lock_irq(&nacl->device_list_lock);
1203 deve = nacl->device_list[lacl->mapped_lun];
1204 if (!deve->se_lun || !deve->se_lun_acl) {
1205 spin_unlock_irq(&nacl->device_list_lock);
1206 return -ENODEV;
1208 /* scsiAuthIntrName */
1209 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1210 spin_unlock_irq(&nacl->device_list_lock);
1211 return ret;
1213 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1215 static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1216 struct se_ml_stat_grps *lgrps, char *page)
1218 struct se_lun_acl *lacl = container_of(lgrps,
1219 struct se_lun_acl, ml_stat_grps);
1220 struct se_node_acl *nacl = lacl->se_lun_nacl;
1221 struct se_dev_entry *deve;
1222 ssize_t ret;
1224 spin_lock_irq(&nacl->device_list_lock);
1225 deve = nacl->device_list[lacl->mapped_lun];
1226 if (!deve->se_lun || !deve->se_lun_acl) {
1227 spin_unlock_irq(&nacl->device_list_lock);
1228 return -ENODEV;
1230 /* FIXME: scsiAuthIntrLunMapIndex */
1231 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1232 spin_unlock_irq(&nacl->device_list_lock);
1233 return ret;
1235 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1237 static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1238 struct se_ml_stat_grps *lgrps, char *page)
1240 struct se_lun_acl *lacl = container_of(lgrps,
1241 struct se_lun_acl, ml_stat_grps);
1242 struct se_node_acl *nacl = lacl->se_lun_nacl;
1243 struct se_dev_entry *deve;
1244 ssize_t ret;
1246 spin_lock_irq(&nacl->device_list_lock);
1247 deve = nacl->device_list[lacl->mapped_lun];
1248 if (!deve->se_lun || !deve->se_lun_acl) {
1249 spin_unlock_irq(&nacl->device_list_lock);
1250 return -ENODEV;
1252 /* scsiAuthIntrAttachedTimes */
1253 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1254 spin_unlock_irq(&nacl->device_list_lock);
1255 return ret;
1257 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1259 static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1260 struct se_ml_stat_grps *lgrps, char *page)
1262 struct se_lun_acl *lacl = container_of(lgrps,
1263 struct se_lun_acl, ml_stat_grps);
1264 struct se_node_acl *nacl = lacl->se_lun_nacl;
1265 struct se_dev_entry *deve;
1266 ssize_t ret;
1268 spin_lock_irq(&nacl->device_list_lock);
1269 deve = nacl->device_list[lacl->mapped_lun];
1270 if (!deve->se_lun || !deve->se_lun_acl) {
1271 spin_unlock_irq(&nacl->device_list_lock);
1272 return -ENODEV;
1274 /* scsiAuthIntrOutCommands */
1275 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1276 spin_unlock_irq(&nacl->device_list_lock);
1277 return ret;
1279 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1281 static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1282 struct se_ml_stat_grps *lgrps, char *page)
1284 struct se_lun_acl *lacl = container_of(lgrps,
1285 struct se_lun_acl, ml_stat_grps);
1286 struct se_node_acl *nacl = lacl->se_lun_nacl;
1287 struct se_dev_entry *deve;
1288 ssize_t ret;
1290 spin_lock_irq(&nacl->device_list_lock);
1291 deve = nacl->device_list[lacl->mapped_lun];
1292 if (!deve->se_lun || !deve->se_lun_acl) {
1293 spin_unlock_irq(&nacl->device_list_lock);
1294 return -ENODEV;
1296 /* scsiAuthIntrReadMegaBytes */
1297 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1298 spin_unlock_irq(&nacl->device_list_lock);
1299 return ret;
1301 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1303 static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1304 struct se_ml_stat_grps *lgrps, char *page)
1306 struct se_lun_acl *lacl = container_of(lgrps,
1307 struct se_lun_acl, ml_stat_grps);
1308 struct se_node_acl *nacl = lacl->se_lun_nacl;
1309 struct se_dev_entry *deve;
1310 ssize_t ret;
1312 spin_lock_irq(&nacl->device_list_lock);
1313 deve = nacl->device_list[lacl->mapped_lun];
1314 if (!deve->se_lun || !deve->se_lun_acl) {
1315 spin_unlock_irq(&nacl->device_list_lock);
1316 return -ENODEV;
1318 /* scsiAuthIntrWrittenMegaBytes */
1319 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1320 spin_unlock_irq(&nacl->device_list_lock);
1321 return ret;
1323 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1325 static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1326 struct se_ml_stat_grps *lgrps, char *page)
1328 struct se_lun_acl *lacl = container_of(lgrps,
1329 struct se_lun_acl, ml_stat_grps);
1330 struct se_node_acl *nacl = lacl->se_lun_nacl;
1331 struct se_dev_entry *deve;
1332 ssize_t ret;
1334 spin_lock_irq(&nacl->device_list_lock);
1335 deve = nacl->device_list[lacl->mapped_lun];
1336 if (!deve->se_lun || !deve->se_lun_acl) {
1337 spin_unlock_irq(&nacl->device_list_lock);
1338 return -ENODEV;
1340 /* FIXME: scsiAuthIntrHSOutCommands */
1341 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1342 spin_unlock_irq(&nacl->device_list_lock);
1343 return ret;
1345 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1347 static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1348 struct se_ml_stat_grps *lgrps, char *page)
1350 struct se_lun_acl *lacl = container_of(lgrps,
1351 struct se_lun_acl, ml_stat_grps);
1352 struct se_node_acl *nacl = lacl->se_lun_nacl;
1353 struct se_dev_entry *deve;
1354 ssize_t ret;
1356 spin_lock_irq(&nacl->device_list_lock);
1357 deve = nacl->device_list[lacl->mapped_lun];
1358 if (!deve->se_lun || !deve->se_lun_acl) {
1359 spin_unlock_irq(&nacl->device_list_lock);
1360 return -ENODEV;
1362 /* scsiAuthIntrLastCreation */
1363 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1364 INITIAL_JIFFIES) * 100 / HZ));
1365 spin_unlock_irq(&nacl->device_list_lock);
1366 return ret;
1368 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1370 static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1371 struct se_ml_stat_grps *lgrps, char *page)
1373 struct se_lun_acl *lacl = container_of(lgrps,
1374 struct se_lun_acl, ml_stat_grps);
1375 struct se_node_acl *nacl = lacl->se_lun_nacl;
1376 struct se_dev_entry *deve;
1377 ssize_t ret;
1379 spin_lock_irq(&nacl->device_list_lock);
1380 deve = nacl->device_list[lacl->mapped_lun];
1381 if (!deve->se_lun || !deve->se_lun_acl) {
1382 spin_unlock_irq(&nacl->device_list_lock);
1383 return -ENODEV;
1385 /* FIXME: scsiAuthIntrRowStatus */
1386 ret = snprintf(page, PAGE_SIZE, "Ready\n");
1387 spin_unlock_irq(&nacl->device_list_lock);
1388 return ret;
1390 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1392 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1393 scsi_auth_intr_group);
1395 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1396 &target_stat_scsi_auth_intr_inst.attr,
1397 &target_stat_scsi_auth_intr_dev.attr,
1398 &target_stat_scsi_auth_intr_port.attr,
1399 &target_stat_scsi_auth_intr_indx.attr,
1400 &target_stat_scsi_auth_intr_dev_or_port.attr,
1401 &target_stat_scsi_auth_intr_intr_name.attr,
1402 &target_stat_scsi_auth_intr_map_indx.attr,
1403 &target_stat_scsi_auth_intr_att_count.attr,
1404 &target_stat_scsi_auth_intr_num_cmds.attr,
1405 &target_stat_scsi_auth_intr_read_mbytes.attr,
1406 &target_stat_scsi_auth_intr_write_mbytes.attr,
1407 &target_stat_scsi_auth_intr_hs_num_cmds.attr,
1408 &target_stat_scsi_auth_intr_creation_time.attr,
1409 &target_stat_scsi_auth_intr_row_status.attr,
1410 NULL,
1413 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1414 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1415 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1418 static struct config_item_type target_stat_scsi_auth_intr_cit = {
1419 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1420 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1421 .ct_owner = THIS_MODULE,
1425 * SCSI Attached Initiator Port Table
1428 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1429 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1430 static struct target_stat_scsi_att_intr_port_attribute \
1431 target_stat_scsi_att_intr_port_##_name = \
1432 __CONFIGFS_EATTR(_name, _mode, \
1433 target_stat_scsi_att_intr_port_show_attr_##_name, \
1434 target_stat_scsi_att_intr_port_store_attr_##_name);
1436 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1437 static struct target_stat_scsi_att_intr_port_attribute \
1438 target_stat_scsi_att_intr_port_##_name = \
1439 __CONFIGFS_EATTR_RO(_name, \
1440 target_stat_scsi_att_intr_port_show_attr_##_name);
1442 static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1443 struct se_ml_stat_grps *lgrps, char *page)
1445 struct se_lun_acl *lacl = container_of(lgrps,
1446 struct se_lun_acl, ml_stat_grps);
1447 struct se_node_acl *nacl = lacl->se_lun_nacl;
1448 struct se_dev_entry *deve;
1449 struct se_portal_group *tpg;
1450 ssize_t ret;
1452 spin_lock_irq(&nacl->device_list_lock);
1453 deve = nacl->device_list[lacl->mapped_lun];
1454 if (!deve->se_lun || !deve->se_lun_acl) {
1455 spin_unlock_irq(&nacl->device_list_lock);
1456 return -ENODEV;
1458 tpg = nacl->se_tpg;
1459 /* scsiInstIndex */
1460 ret = snprintf(page, PAGE_SIZE, "%u\n",
1461 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1462 spin_unlock_irq(&nacl->device_list_lock);
1463 return ret;
1465 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1467 static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1468 struct se_ml_stat_grps *lgrps, char *page)
1470 struct se_lun_acl *lacl = container_of(lgrps,
1471 struct se_lun_acl, ml_stat_grps);
1472 struct se_node_acl *nacl = lacl->se_lun_nacl;
1473 struct se_dev_entry *deve;
1474 struct se_lun *lun;
1475 ssize_t ret;
1477 spin_lock_irq(&nacl->device_list_lock);
1478 deve = nacl->device_list[lacl->mapped_lun];
1479 if (!deve->se_lun || !deve->se_lun_acl) {
1480 spin_unlock_irq(&nacl->device_list_lock);
1481 return -ENODEV;
1483 lun = deve->se_lun;
1484 /* scsiDeviceIndex */
1485 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1486 spin_unlock_irq(&nacl->device_list_lock);
1487 return ret;
1489 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1491 static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1492 struct se_ml_stat_grps *lgrps, char *page)
1494 struct se_lun_acl *lacl = container_of(lgrps,
1495 struct se_lun_acl, ml_stat_grps);
1496 struct se_node_acl *nacl = lacl->se_lun_nacl;
1497 struct se_dev_entry *deve;
1498 struct se_portal_group *tpg;
1499 ssize_t ret;
1501 spin_lock_irq(&nacl->device_list_lock);
1502 deve = nacl->device_list[lacl->mapped_lun];
1503 if (!deve->se_lun || !deve->se_lun_acl) {
1504 spin_unlock_irq(&nacl->device_list_lock);
1505 return -ENODEV;
1507 tpg = nacl->se_tpg;
1508 /* scsiPortIndex */
1509 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1510 spin_unlock_irq(&nacl->device_list_lock);
1511 return ret;
1513 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1515 static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1516 struct se_ml_stat_grps *lgrps, char *page)
1518 struct se_lun_acl *lacl = container_of(lgrps,
1519 struct se_lun_acl, ml_stat_grps);
1520 struct se_node_acl *nacl = lacl->se_lun_nacl;
1521 struct se_session *se_sess;
1522 struct se_portal_group *tpg;
1523 ssize_t ret;
1525 spin_lock_irq(&nacl->nacl_sess_lock);
1526 se_sess = nacl->nacl_sess;
1527 if (!se_sess) {
1528 spin_unlock_irq(&nacl->nacl_sess_lock);
1529 return -ENODEV;
1532 tpg = nacl->se_tpg;
1533 /* scsiAttIntrPortIndex */
1534 ret = snprintf(page, PAGE_SIZE, "%u\n",
1535 tpg->se_tpg_tfo->sess_get_index(se_sess));
1536 spin_unlock_irq(&nacl->nacl_sess_lock);
1537 return ret;
1539 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1541 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1542 struct se_ml_stat_grps *lgrps, char *page)
1544 struct se_lun_acl *lacl = container_of(lgrps,
1545 struct se_lun_acl, ml_stat_grps);
1546 struct se_node_acl *nacl = lacl->se_lun_nacl;
1547 struct se_dev_entry *deve;
1548 ssize_t ret;
1550 spin_lock_irq(&nacl->device_list_lock);
1551 deve = nacl->device_list[lacl->mapped_lun];
1552 if (!deve->se_lun || !deve->se_lun_acl) {
1553 spin_unlock_irq(&nacl->device_list_lock);
1554 return -ENODEV;
1556 /* scsiAttIntrPortAuthIntrIdx */
1557 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1558 spin_unlock_irq(&nacl->device_list_lock);
1559 return ret;
1561 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1563 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1564 struct se_ml_stat_grps *lgrps, char *page)
1566 struct se_lun_acl *lacl = container_of(lgrps,
1567 struct se_lun_acl, ml_stat_grps);
1568 struct se_node_acl *nacl = lacl->se_lun_nacl;
1569 struct se_session *se_sess;
1570 struct se_portal_group *tpg;
1571 ssize_t ret;
1572 unsigned char buf[64];
1574 spin_lock_irq(&nacl->nacl_sess_lock);
1575 se_sess = nacl->nacl_sess;
1576 if (!se_sess) {
1577 spin_unlock_irq(&nacl->nacl_sess_lock);
1578 return -ENODEV;
1581 tpg = nacl->se_tpg;
1582 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1583 memset(buf, 0, 64);
1584 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1585 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
1587 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1588 spin_unlock_irq(&nacl->nacl_sess_lock);
1589 return ret;
1591 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1593 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1594 scsi_att_intr_port_group);
1596 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1597 &target_stat_scsi_att_intr_port_inst.attr,
1598 &target_stat_scsi_att_intr_port_dev.attr,
1599 &target_stat_scsi_att_intr_port_port.attr,
1600 &target_stat_scsi_att_intr_port_indx.attr,
1601 &target_stat_scsi_att_intr_port_port_auth_indx.attr,
1602 &target_stat_scsi_att_intr_port_port_ident.attr,
1603 NULL,
1606 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1607 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1608 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1611 static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1612 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1613 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1614 .ct_owner = THIS_MODULE,
1618 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1619 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1621 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1623 struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
1625 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1626 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1627 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1628 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1630 ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1631 ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
1632 ml_stat_grp->default_groups[2] = NULL;