MIPS: Yosemite, Emma: Fix off-by-two in arcs_cmdline buffer size check
[linux-2.6/linux-mips.git] / drivers / target / target_core_stat.c
blob874152aed94af013de0bc5762f0959ea25281e05
1 /*******************************************************************************
2 * Filename: target_core_stat.c
4 * Copyright (c) 2011 Rising Tide Systems
5 * Copyright (c) 2011 Linux-iSCSI.org
7 * Modern ConfigFS group context specific statistics based on original
8 * target_core_mib.c code
10 * Copyright (c) 2006-2007 SBE, Inc. All Rights Reserved.
12 * Nicholas A. Bellinger <nab@linux-iscsi.org>
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 ******************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/delay.h>
33 #include <linux/timer.h>
34 #include <linux/string.h>
35 #include <generated/utsrelease.h>
36 #include <linux/utsname.h>
37 #include <linux/proc_fs.h>
38 #include <linux/seq_file.h>
39 #include <linux/blkdev.h>
40 #include <linux/configfs.h>
41 #include <scsi/scsi.h>
42 #include <scsi/scsi_device.h>
43 #include <scsi/scsi_host.h>
45 #include <target/target_core_base.h>
46 #include <target/target_core_transport.h>
47 #include <target/target_core_fabric_ops.h>
48 #include <target/target_core_configfs.h>
49 #include <target/configfs_macros.h>
51 #include "target_core_hba.h"
53 #ifndef INITIAL_JIFFIES
54 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
55 #endif
57 #define NONE "None"
58 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
60 #define SCSI_LU_INDEX 1
61 #define LU_COUNT 1
64 * SCSI Device Table
67 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
68 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
69 static struct target_stat_scsi_dev_attribute \
70 target_stat_scsi_dev_##_name = \
71 __CONFIGFS_EATTR(_name, _mode, \
72 target_stat_scsi_dev_show_attr_##_name, \
73 target_stat_scsi_dev_store_attr_##_name);
75 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
76 static struct target_stat_scsi_dev_attribute \
77 target_stat_scsi_dev_##_name = \
78 __CONFIGFS_EATTR_RO(_name, \
79 target_stat_scsi_dev_show_attr_##_name);
81 static ssize_t target_stat_scsi_dev_show_attr_inst(
82 struct se_dev_stat_grps *sgrps, char *page)
84 struct se_subsystem_dev *se_subdev = container_of(sgrps,
85 struct se_subsystem_dev, dev_stat_grps);
86 struct se_hba *hba = se_subdev->se_dev_hba;
87 struct se_device *dev = se_subdev->se_dev_ptr;
89 if (!dev)
90 return -ENODEV;
92 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
94 DEV_STAT_SCSI_DEV_ATTR_RO(inst);
96 static ssize_t target_stat_scsi_dev_show_attr_indx(
97 struct se_dev_stat_grps *sgrps, char *page)
99 struct se_subsystem_dev *se_subdev = container_of(sgrps,
100 struct se_subsystem_dev, dev_stat_grps);
101 struct se_device *dev = se_subdev->se_dev_ptr;
103 if (!dev)
104 return -ENODEV;
106 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
108 DEV_STAT_SCSI_DEV_ATTR_RO(indx);
110 static ssize_t target_stat_scsi_dev_show_attr_role(
111 struct se_dev_stat_grps *sgrps, char *page)
113 struct se_subsystem_dev *se_subdev = container_of(sgrps,
114 struct se_subsystem_dev, dev_stat_grps);
115 struct se_device *dev = se_subdev->se_dev_ptr;
117 if (!dev)
118 return -ENODEV;
120 return snprintf(page, PAGE_SIZE, "Target\n");
122 DEV_STAT_SCSI_DEV_ATTR_RO(role);
124 static ssize_t target_stat_scsi_dev_show_attr_ports(
125 struct se_dev_stat_grps *sgrps, char *page)
127 struct se_subsystem_dev *se_subdev = container_of(sgrps,
128 struct se_subsystem_dev, dev_stat_grps);
129 struct se_device *dev = se_subdev->se_dev_ptr;
131 if (!dev)
132 return -ENODEV;
134 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
136 DEV_STAT_SCSI_DEV_ATTR_RO(ports);
138 CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
140 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
141 &target_stat_scsi_dev_inst.attr,
142 &target_stat_scsi_dev_indx.attr,
143 &target_stat_scsi_dev_role.attr,
144 &target_stat_scsi_dev_ports.attr,
145 NULL,
148 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
149 .show_attribute = target_stat_scsi_dev_attr_show,
150 .store_attribute = target_stat_scsi_dev_attr_store,
153 static struct config_item_type target_stat_scsi_dev_cit = {
154 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
155 .ct_attrs = target_stat_scsi_dev_attrs,
156 .ct_owner = THIS_MODULE,
160 * SCSI Target Device Table
163 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
164 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
165 static struct target_stat_scsi_tgt_dev_attribute \
166 target_stat_scsi_tgt_dev_##_name = \
167 __CONFIGFS_EATTR(_name, _mode, \
168 target_stat_scsi_tgt_dev_show_attr_##_name, \
169 target_stat_scsi_tgt_dev_store_attr_##_name);
171 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
172 static struct target_stat_scsi_tgt_dev_attribute \
173 target_stat_scsi_tgt_dev_##_name = \
174 __CONFIGFS_EATTR_RO(_name, \
175 target_stat_scsi_tgt_dev_show_attr_##_name);
177 static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
178 struct se_dev_stat_grps *sgrps, char *page)
180 struct se_subsystem_dev *se_subdev = container_of(sgrps,
181 struct se_subsystem_dev, dev_stat_grps);
182 struct se_hba *hba = se_subdev->se_dev_hba;
183 struct se_device *dev = se_subdev->se_dev_ptr;
185 if (!dev)
186 return -ENODEV;
188 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
190 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
192 static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
193 struct se_dev_stat_grps *sgrps, char *page)
195 struct se_subsystem_dev *se_subdev = container_of(sgrps,
196 struct se_subsystem_dev, dev_stat_grps);
197 struct se_device *dev = se_subdev->se_dev_ptr;
199 if (!dev)
200 return -ENODEV;
202 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
204 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
206 static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
207 struct se_dev_stat_grps *sgrps, char *page)
209 struct se_subsystem_dev *se_subdev = container_of(sgrps,
210 struct se_subsystem_dev, dev_stat_grps);
211 struct se_device *dev = se_subdev->se_dev_ptr;
213 if (!dev)
214 return -ENODEV;
216 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
218 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
220 static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
221 struct se_dev_stat_grps *sgrps, char *page)
223 struct se_subsystem_dev *se_subdev = container_of(sgrps,
224 struct se_subsystem_dev, dev_stat_grps);
225 struct se_device *dev = se_subdev->se_dev_ptr;
226 char status[16];
228 if (!dev)
229 return -ENODEV;
231 switch (dev->dev_status) {
232 case TRANSPORT_DEVICE_ACTIVATED:
233 strcpy(status, "activated");
234 break;
235 case TRANSPORT_DEVICE_DEACTIVATED:
236 strcpy(status, "deactivated");
237 break;
238 case TRANSPORT_DEVICE_SHUTDOWN:
239 strcpy(status, "shutdown");
240 break;
241 case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
242 case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
243 strcpy(status, "offline");
244 break;
245 default:
246 sprintf(status, "unknown(%d)", dev->dev_status);
247 break;
250 return snprintf(page, PAGE_SIZE, "%s\n", status);
252 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
254 static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
255 struct se_dev_stat_grps *sgrps, char *page)
257 struct se_subsystem_dev *se_subdev = container_of(sgrps,
258 struct se_subsystem_dev, dev_stat_grps);
259 struct se_device *dev = se_subdev->se_dev_ptr;
260 int non_accessible_lus;
262 if (!dev)
263 return -ENODEV;
265 switch (dev->dev_status) {
266 case TRANSPORT_DEVICE_ACTIVATED:
267 non_accessible_lus = 0;
268 break;
269 case TRANSPORT_DEVICE_DEACTIVATED:
270 case TRANSPORT_DEVICE_SHUTDOWN:
271 case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
272 case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
273 default:
274 non_accessible_lus = 1;
275 break;
278 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
280 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
282 static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
283 struct se_dev_stat_grps *sgrps, char *page)
285 struct se_subsystem_dev *se_subdev = container_of(sgrps,
286 struct se_subsystem_dev, dev_stat_grps);
287 struct se_device *dev = se_subdev->se_dev_ptr;
289 if (!dev)
290 return -ENODEV;
292 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
294 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
297 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
299 static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
300 &target_stat_scsi_tgt_dev_inst.attr,
301 &target_stat_scsi_tgt_dev_indx.attr,
302 &target_stat_scsi_tgt_dev_num_lus.attr,
303 &target_stat_scsi_tgt_dev_status.attr,
304 &target_stat_scsi_tgt_dev_non_access_lus.attr,
305 &target_stat_scsi_tgt_dev_resets.attr,
306 NULL,
309 static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
310 .show_attribute = target_stat_scsi_tgt_dev_attr_show,
311 .store_attribute = target_stat_scsi_tgt_dev_attr_store,
314 static struct config_item_type target_stat_scsi_tgt_dev_cit = {
315 .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
316 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
317 .ct_owner = THIS_MODULE,
321 * SCSI Logical Unit Table
324 CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
325 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
326 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
327 __CONFIGFS_EATTR(_name, _mode, \
328 target_stat_scsi_lu_show_attr_##_name, \
329 target_stat_scsi_lu_store_attr_##_name);
331 #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
332 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
333 __CONFIGFS_EATTR_RO(_name, \
334 target_stat_scsi_lu_show_attr_##_name);
336 static ssize_t target_stat_scsi_lu_show_attr_inst(
337 struct se_dev_stat_grps *sgrps, char *page)
339 struct se_subsystem_dev *se_subdev = container_of(sgrps,
340 struct se_subsystem_dev, dev_stat_grps);
341 struct se_hba *hba = se_subdev->se_dev_hba;
342 struct se_device *dev = se_subdev->se_dev_ptr;
344 if (!dev)
345 return -ENODEV;
347 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
349 DEV_STAT_SCSI_LU_ATTR_RO(inst);
351 static ssize_t target_stat_scsi_lu_show_attr_dev(
352 struct se_dev_stat_grps *sgrps, char *page)
354 struct se_subsystem_dev *se_subdev = container_of(sgrps,
355 struct se_subsystem_dev, dev_stat_grps);
356 struct se_device *dev = se_subdev->se_dev_ptr;
358 if (!dev)
359 return -ENODEV;
361 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
363 DEV_STAT_SCSI_LU_ATTR_RO(dev);
365 static ssize_t target_stat_scsi_lu_show_attr_indx(
366 struct se_dev_stat_grps *sgrps, char *page)
368 struct se_subsystem_dev *se_subdev = container_of(sgrps,
369 struct se_subsystem_dev, dev_stat_grps);
370 struct se_device *dev = se_subdev->se_dev_ptr;
372 if (!dev)
373 return -ENODEV;
375 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
377 DEV_STAT_SCSI_LU_ATTR_RO(indx);
379 static ssize_t target_stat_scsi_lu_show_attr_lun(
380 struct se_dev_stat_grps *sgrps, char *page)
382 struct se_subsystem_dev *se_subdev = container_of(sgrps,
383 struct se_subsystem_dev, dev_stat_grps);
384 struct se_device *dev = se_subdev->se_dev_ptr;
386 if (!dev)
387 return -ENODEV;
388 /* FIXME: scsiLuDefaultLun */
389 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
391 DEV_STAT_SCSI_LU_ATTR_RO(lun);
393 static ssize_t target_stat_scsi_lu_show_attr_lu_name(
394 struct se_dev_stat_grps *sgrps, char *page)
396 struct se_subsystem_dev *se_subdev = container_of(sgrps,
397 struct se_subsystem_dev, dev_stat_grps);
398 struct se_device *dev = se_subdev->se_dev_ptr;
400 if (!dev)
401 return -ENODEV;
402 /* scsiLuWwnName */
403 return snprintf(page, PAGE_SIZE, "%s\n",
404 (strlen(dev->se_sub_dev->t10_wwn.unit_serial)) ?
405 dev->se_sub_dev->t10_wwn.unit_serial : "None");
407 DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
409 static ssize_t target_stat_scsi_lu_show_attr_vend(
410 struct se_dev_stat_grps *sgrps, char *page)
412 struct se_subsystem_dev *se_subdev = container_of(sgrps,
413 struct se_subsystem_dev, dev_stat_grps);
414 struct se_device *dev = se_subdev->se_dev_ptr;
415 int i;
416 char str[sizeof(dev->se_sub_dev->t10_wwn.vendor)+1];
418 if (!dev)
419 return -ENODEV;
421 /* scsiLuVendorId */
422 for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
423 str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.vendor[i]) ?
424 dev->se_sub_dev->t10_wwn.vendor[i] : ' ';
425 str[i] = '\0';
426 return snprintf(page, PAGE_SIZE, "%s\n", str);
428 DEV_STAT_SCSI_LU_ATTR_RO(vend);
430 static ssize_t target_stat_scsi_lu_show_attr_prod(
431 struct se_dev_stat_grps *sgrps, char *page)
433 struct se_subsystem_dev *se_subdev = container_of(sgrps,
434 struct se_subsystem_dev, dev_stat_grps);
435 struct se_device *dev = se_subdev->se_dev_ptr;
436 int i;
437 char str[sizeof(dev->se_sub_dev->t10_wwn.model)+1];
439 if (!dev)
440 return -ENODEV;
442 /* scsiLuProductId */
443 for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
444 str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.model[i]) ?
445 dev->se_sub_dev->t10_wwn.model[i] : ' ';
446 str[i] = '\0';
447 return snprintf(page, PAGE_SIZE, "%s\n", str);
449 DEV_STAT_SCSI_LU_ATTR_RO(prod);
451 static ssize_t target_stat_scsi_lu_show_attr_rev(
452 struct se_dev_stat_grps *sgrps, char *page)
454 struct se_subsystem_dev *se_subdev = container_of(sgrps,
455 struct se_subsystem_dev, dev_stat_grps);
456 struct se_device *dev = se_subdev->se_dev_ptr;
457 int i;
458 char str[sizeof(dev->se_sub_dev->t10_wwn.revision)+1];
460 if (!dev)
461 return -ENODEV;
463 /* scsiLuRevisionId */
464 for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.revision); i++)
465 str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.revision[i]) ?
466 dev->se_sub_dev->t10_wwn.revision[i] : ' ';
467 str[i] = '\0';
468 return snprintf(page, PAGE_SIZE, "%s\n", str);
470 DEV_STAT_SCSI_LU_ATTR_RO(rev);
472 static ssize_t target_stat_scsi_lu_show_attr_dev_type(
473 struct se_dev_stat_grps *sgrps, char *page)
475 struct se_subsystem_dev *se_subdev = container_of(sgrps,
476 struct se_subsystem_dev, dev_stat_grps);
477 struct se_device *dev = se_subdev->se_dev_ptr;
479 if (!dev)
480 return -ENODEV;
482 /* scsiLuPeripheralType */
483 return snprintf(page, PAGE_SIZE, "%u\n",
484 dev->transport->get_device_type(dev));
486 DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
488 static ssize_t target_stat_scsi_lu_show_attr_status(
489 struct se_dev_stat_grps *sgrps, char *page)
491 struct se_subsystem_dev *se_subdev = container_of(sgrps,
492 struct se_subsystem_dev, dev_stat_grps);
493 struct se_device *dev = se_subdev->se_dev_ptr;
495 if (!dev)
496 return -ENODEV;
498 /* scsiLuStatus */
499 return snprintf(page, PAGE_SIZE, "%s\n",
500 (dev->dev_status == TRANSPORT_DEVICE_ACTIVATED) ?
501 "available" : "notavailable");
503 DEV_STAT_SCSI_LU_ATTR_RO(status);
505 static ssize_t target_stat_scsi_lu_show_attr_state_bit(
506 struct se_dev_stat_grps *sgrps, char *page)
508 struct se_subsystem_dev *se_subdev = container_of(sgrps,
509 struct se_subsystem_dev, dev_stat_grps);
510 struct se_device *dev = se_subdev->se_dev_ptr;
512 if (!dev)
513 return -ENODEV;
515 /* scsiLuState */
516 return snprintf(page, PAGE_SIZE, "exposed\n");
518 DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
520 static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
521 struct se_dev_stat_grps *sgrps, char *page)
523 struct se_subsystem_dev *se_subdev = container_of(sgrps,
524 struct se_subsystem_dev, dev_stat_grps);
525 struct se_device *dev = se_subdev->se_dev_ptr;
527 if (!dev)
528 return -ENODEV;
530 /* scsiLuNumCommands */
531 return snprintf(page, PAGE_SIZE, "%llu\n",
532 (unsigned long long)dev->num_cmds);
534 DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
536 static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
537 struct se_dev_stat_grps *sgrps, char *page)
539 struct se_subsystem_dev *se_subdev = container_of(sgrps,
540 struct se_subsystem_dev, dev_stat_grps);
541 struct se_device *dev = se_subdev->se_dev_ptr;
543 if (!dev)
544 return -ENODEV;
546 /* scsiLuReadMegaBytes */
547 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
549 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
551 static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
552 struct se_dev_stat_grps *sgrps, char *page)
554 struct se_subsystem_dev *se_subdev = container_of(sgrps,
555 struct se_subsystem_dev, dev_stat_grps);
556 struct se_device *dev = se_subdev->se_dev_ptr;
558 if (!dev)
559 return -ENODEV;
561 /* scsiLuWrittenMegaBytes */
562 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
564 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
566 static ssize_t target_stat_scsi_lu_show_attr_resets(
567 struct se_dev_stat_grps *sgrps, char *page)
569 struct se_subsystem_dev *se_subdev = container_of(sgrps,
570 struct se_subsystem_dev, dev_stat_grps);
571 struct se_device *dev = se_subdev->se_dev_ptr;
573 if (!dev)
574 return -ENODEV;
576 /* scsiLuInResets */
577 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
579 DEV_STAT_SCSI_LU_ATTR_RO(resets);
581 static ssize_t target_stat_scsi_lu_show_attr_full_stat(
582 struct se_dev_stat_grps *sgrps, char *page)
584 struct se_subsystem_dev *se_subdev = container_of(sgrps,
585 struct se_subsystem_dev, dev_stat_grps);
586 struct se_device *dev = se_subdev->se_dev_ptr;
588 if (!dev)
589 return -ENODEV;
591 /* FIXME: scsiLuOutTaskSetFullStatus */
592 return snprintf(page, PAGE_SIZE, "%u\n", 0);
594 DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
596 static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
597 struct se_dev_stat_grps *sgrps, char *page)
599 struct se_subsystem_dev *se_subdev = container_of(sgrps,
600 struct se_subsystem_dev, dev_stat_grps);
601 struct se_device *dev = se_subdev->se_dev_ptr;
603 if (!dev)
604 return -ENODEV;
606 /* FIXME: scsiLuHSInCommands */
607 return snprintf(page, PAGE_SIZE, "%u\n", 0);
609 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
611 static ssize_t target_stat_scsi_lu_show_attr_creation_time(
612 struct se_dev_stat_grps *sgrps, char *page)
614 struct se_subsystem_dev *se_subdev = container_of(sgrps,
615 struct se_subsystem_dev, dev_stat_grps);
616 struct se_device *dev = se_subdev->se_dev_ptr;
618 if (!dev)
619 return -ENODEV;
621 /* scsiLuCreationTime */
622 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
623 INITIAL_JIFFIES) * 100 / HZ));
625 DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
627 CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
629 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
630 &target_stat_scsi_lu_inst.attr,
631 &target_stat_scsi_lu_dev.attr,
632 &target_stat_scsi_lu_indx.attr,
633 &target_stat_scsi_lu_lun.attr,
634 &target_stat_scsi_lu_lu_name.attr,
635 &target_stat_scsi_lu_vend.attr,
636 &target_stat_scsi_lu_prod.attr,
637 &target_stat_scsi_lu_rev.attr,
638 &target_stat_scsi_lu_dev_type.attr,
639 &target_stat_scsi_lu_status.attr,
640 &target_stat_scsi_lu_state_bit.attr,
641 &target_stat_scsi_lu_num_cmds.attr,
642 &target_stat_scsi_lu_read_mbytes.attr,
643 &target_stat_scsi_lu_write_mbytes.attr,
644 &target_stat_scsi_lu_resets.attr,
645 &target_stat_scsi_lu_full_stat.attr,
646 &target_stat_scsi_lu_hs_num_cmds.attr,
647 &target_stat_scsi_lu_creation_time.attr,
648 NULL,
651 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
652 .show_attribute = target_stat_scsi_lu_attr_show,
653 .store_attribute = target_stat_scsi_lu_attr_store,
656 static struct config_item_type target_stat_scsi_lu_cit = {
657 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
658 .ct_attrs = target_stat_scsi_lu_attrs,
659 .ct_owner = THIS_MODULE,
663 * Called from target_core_configfs.c:target_core_make_subdev() to setup
664 * the target statistics groups + configfs CITs located in target_core_stat.c
666 void target_stat_setup_dev_default_groups(struct se_subsystem_dev *se_subdev)
668 struct config_group *dev_stat_grp = &se_subdev->dev_stat_grps.stat_group;
670 config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_dev_group,
671 "scsi_dev", &target_stat_scsi_dev_cit);
672 config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_tgt_dev_group,
673 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
674 config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_lu_group,
675 "scsi_lu", &target_stat_scsi_lu_cit);
677 dev_stat_grp->default_groups[0] = &se_subdev->dev_stat_grps.scsi_dev_group;
678 dev_stat_grp->default_groups[1] = &se_subdev->dev_stat_grps.scsi_tgt_dev_group;
679 dev_stat_grp->default_groups[2] = &se_subdev->dev_stat_grps.scsi_lu_group;
680 dev_stat_grp->default_groups[3] = NULL;
684 * SCSI Port Table
687 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
688 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
689 static struct target_stat_scsi_port_attribute \
690 target_stat_scsi_port_##_name = \
691 __CONFIGFS_EATTR(_name, _mode, \
692 target_stat_scsi_port_show_attr_##_name, \
693 target_stat_scsi_port_store_attr_##_name);
695 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
696 static struct target_stat_scsi_port_attribute \
697 target_stat_scsi_port_##_name = \
698 __CONFIGFS_EATTR_RO(_name, \
699 target_stat_scsi_port_show_attr_##_name);
701 static ssize_t target_stat_scsi_port_show_attr_inst(
702 struct se_port_stat_grps *pgrps, char *page)
704 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
705 struct se_port *sep;
706 struct se_device *dev = lun->lun_se_dev;
707 struct se_hba *hba;
708 ssize_t ret;
710 spin_lock(&lun->lun_sep_lock);
711 sep = lun->lun_sep;
712 if (!sep) {
713 spin_unlock(&lun->lun_sep_lock);
714 return -ENODEV;
716 hba = dev->se_hba;
717 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
718 spin_unlock(&lun->lun_sep_lock);
719 return ret;
721 DEV_STAT_SCSI_PORT_ATTR_RO(inst);
723 static ssize_t target_stat_scsi_port_show_attr_dev(
724 struct se_port_stat_grps *pgrps, char *page)
726 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
727 struct se_port *sep;
728 struct se_device *dev = lun->lun_se_dev;
729 ssize_t ret;
731 spin_lock(&lun->lun_sep_lock);
732 sep = lun->lun_sep;
733 if (!sep) {
734 spin_unlock(&lun->lun_sep_lock);
735 return -ENODEV;
737 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
738 spin_unlock(&lun->lun_sep_lock);
739 return ret;
741 DEV_STAT_SCSI_PORT_ATTR_RO(dev);
743 static ssize_t target_stat_scsi_port_show_attr_indx(
744 struct se_port_stat_grps *pgrps, char *page)
746 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
747 struct se_port *sep;
748 ssize_t ret;
750 spin_lock(&lun->lun_sep_lock);
751 sep = lun->lun_sep;
752 if (!sep) {
753 spin_unlock(&lun->lun_sep_lock);
754 return -ENODEV;
756 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
757 spin_unlock(&lun->lun_sep_lock);
758 return ret;
760 DEV_STAT_SCSI_PORT_ATTR_RO(indx);
762 static ssize_t target_stat_scsi_port_show_attr_role(
763 struct se_port_stat_grps *pgrps, char *page)
765 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
766 struct se_device *dev = lun->lun_se_dev;
767 struct se_port *sep;
768 ssize_t ret;
770 if (!dev)
771 return -ENODEV;
773 spin_lock(&lun->lun_sep_lock);
774 sep = lun->lun_sep;
775 if (!sep) {
776 spin_unlock(&lun->lun_sep_lock);
777 return -ENODEV;
779 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
780 spin_unlock(&lun->lun_sep_lock);
781 return ret;
783 DEV_STAT_SCSI_PORT_ATTR_RO(role);
785 static ssize_t target_stat_scsi_port_show_attr_busy_count(
786 struct se_port_stat_grps *pgrps, char *page)
788 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
789 struct se_port *sep;
790 ssize_t ret;
792 spin_lock(&lun->lun_sep_lock);
793 sep = lun->lun_sep;
794 if (!sep) {
795 spin_unlock(&lun->lun_sep_lock);
796 return -ENODEV;
798 /* FIXME: scsiPortBusyStatuses */
799 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
800 spin_unlock(&lun->lun_sep_lock);
801 return ret;
803 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
805 CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
807 static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
808 &target_stat_scsi_port_inst.attr,
809 &target_stat_scsi_port_dev.attr,
810 &target_stat_scsi_port_indx.attr,
811 &target_stat_scsi_port_role.attr,
812 &target_stat_scsi_port_busy_count.attr,
813 NULL,
816 static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
817 .show_attribute = target_stat_scsi_port_attr_show,
818 .store_attribute = target_stat_scsi_port_attr_store,
821 static struct config_item_type target_stat_scsi_port_cit = {
822 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
823 .ct_attrs = target_stat_scsi_port_attrs,
824 .ct_owner = THIS_MODULE,
828 * SCSI Target Port Table
830 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
831 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
832 static struct target_stat_scsi_tgt_port_attribute \
833 target_stat_scsi_tgt_port_##_name = \
834 __CONFIGFS_EATTR(_name, _mode, \
835 target_stat_scsi_tgt_port_show_attr_##_name, \
836 target_stat_scsi_tgt_port_store_attr_##_name);
838 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
839 static struct target_stat_scsi_tgt_port_attribute \
840 target_stat_scsi_tgt_port_##_name = \
841 __CONFIGFS_EATTR_RO(_name, \
842 target_stat_scsi_tgt_port_show_attr_##_name);
844 static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
845 struct se_port_stat_grps *pgrps, char *page)
847 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
848 struct se_device *dev = lun->lun_se_dev;
849 struct se_port *sep;
850 struct se_hba *hba;
851 ssize_t ret;
853 spin_lock(&lun->lun_sep_lock);
854 sep = lun->lun_sep;
855 if (!sep) {
856 spin_unlock(&lun->lun_sep_lock);
857 return -ENODEV;
859 hba = dev->se_hba;
860 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
861 spin_unlock(&lun->lun_sep_lock);
862 return ret;
864 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
866 static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
867 struct se_port_stat_grps *pgrps, char *page)
869 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
870 struct se_device *dev = lun->lun_se_dev;
871 struct se_port *sep;
872 ssize_t ret;
874 spin_lock(&lun->lun_sep_lock);
875 sep = lun->lun_sep;
876 if (!sep) {
877 spin_unlock(&lun->lun_sep_lock);
878 return -ENODEV;
880 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
881 spin_unlock(&lun->lun_sep_lock);
882 return ret;
884 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
886 static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
887 struct se_port_stat_grps *pgrps, char *page)
889 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
890 struct se_port *sep;
891 ssize_t ret;
893 spin_lock(&lun->lun_sep_lock);
894 sep = lun->lun_sep;
895 if (!sep) {
896 spin_unlock(&lun->lun_sep_lock);
897 return -ENODEV;
899 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
900 spin_unlock(&lun->lun_sep_lock);
901 return ret;
903 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
905 static ssize_t target_stat_scsi_tgt_port_show_attr_name(
906 struct se_port_stat_grps *pgrps, char *page)
908 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
909 struct se_port *sep;
910 struct se_portal_group *tpg;
911 ssize_t ret;
913 spin_lock(&lun->lun_sep_lock);
914 sep = lun->lun_sep;
915 if (!sep) {
916 spin_unlock(&lun->lun_sep_lock);
917 return -ENODEV;
919 tpg = sep->sep_tpg;
921 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
922 tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
923 spin_unlock(&lun->lun_sep_lock);
924 return ret;
926 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
928 static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
929 struct se_port_stat_grps *pgrps, char *page)
931 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
932 struct se_port *sep;
933 struct se_portal_group *tpg;
934 ssize_t ret;
936 spin_lock(&lun->lun_sep_lock);
937 sep = lun->lun_sep;
938 if (!sep) {
939 spin_unlock(&lun->lun_sep_lock);
940 return -ENODEV;
942 tpg = sep->sep_tpg;
944 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
945 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
946 tpg->se_tpg_tfo->tpg_get_tag(tpg));
947 spin_unlock(&lun->lun_sep_lock);
948 return ret;
950 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
952 static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
953 struct se_port_stat_grps *pgrps, char *page)
955 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
956 struct se_port *sep;
957 struct se_portal_group *tpg;
958 ssize_t ret;
960 spin_lock(&lun->lun_sep_lock);
961 sep = lun->lun_sep;
962 if (!sep) {
963 spin_unlock(&lun->lun_sep_lock);
964 return -ENODEV;
966 tpg = sep->sep_tpg;
968 ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
969 spin_unlock(&lun->lun_sep_lock);
970 return ret;
972 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
974 static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
975 struct se_port_stat_grps *pgrps, char *page)
977 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
978 struct se_port *sep;
979 struct se_portal_group *tpg;
980 ssize_t ret;
982 spin_lock(&lun->lun_sep_lock);
983 sep = lun->lun_sep;
984 if (!sep) {
985 spin_unlock(&lun->lun_sep_lock);
986 return -ENODEV;
988 tpg = sep->sep_tpg;
990 ret = snprintf(page, PAGE_SIZE, "%u\n",
991 (u32)(sep->sep_stats.rx_data_octets >> 20));
992 spin_unlock(&lun->lun_sep_lock);
993 return ret;
995 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
997 static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
998 struct se_port_stat_grps *pgrps, char *page)
1000 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1001 struct se_port *sep;
1002 struct se_portal_group *tpg;
1003 ssize_t ret;
1005 spin_lock(&lun->lun_sep_lock);
1006 sep = lun->lun_sep;
1007 if (!sep) {
1008 spin_unlock(&lun->lun_sep_lock);
1009 return -ENODEV;
1011 tpg = sep->sep_tpg;
1013 ret = snprintf(page, PAGE_SIZE, "%u\n",
1014 (u32)(sep->sep_stats.tx_data_octets >> 20));
1015 spin_unlock(&lun->lun_sep_lock);
1016 return ret;
1018 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
1020 static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
1021 struct se_port_stat_grps *pgrps, char *page)
1023 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1024 struct se_port *sep;
1025 struct se_portal_group *tpg;
1026 ssize_t ret;
1028 spin_lock(&lun->lun_sep_lock);
1029 sep = lun->lun_sep;
1030 if (!sep) {
1031 spin_unlock(&lun->lun_sep_lock);
1032 return -ENODEV;
1034 tpg = sep->sep_tpg;
1036 /* FIXME: scsiTgtPortHsInCommands */
1037 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1038 spin_unlock(&lun->lun_sep_lock);
1039 return ret;
1041 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
1043 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
1044 scsi_tgt_port_group);
1046 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
1047 &target_stat_scsi_tgt_port_inst.attr,
1048 &target_stat_scsi_tgt_port_dev.attr,
1049 &target_stat_scsi_tgt_port_indx.attr,
1050 &target_stat_scsi_tgt_port_name.attr,
1051 &target_stat_scsi_tgt_port_port_index.attr,
1052 &target_stat_scsi_tgt_port_in_cmds.attr,
1053 &target_stat_scsi_tgt_port_write_mbytes.attr,
1054 &target_stat_scsi_tgt_port_read_mbytes.attr,
1055 &target_stat_scsi_tgt_port_hs_in_cmds.attr,
1056 NULL,
1059 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
1060 .show_attribute = target_stat_scsi_tgt_port_attr_show,
1061 .store_attribute = target_stat_scsi_tgt_port_attr_store,
1064 static struct config_item_type target_stat_scsi_tgt_port_cit = {
1065 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
1066 .ct_attrs = target_stat_scsi_tgt_port_attrs,
1067 .ct_owner = THIS_MODULE,
1071 * SCSI Transport Table
1072 o */
1074 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
1075 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
1076 static struct target_stat_scsi_transport_attribute \
1077 target_stat_scsi_transport_##_name = \
1078 __CONFIGFS_EATTR(_name, _mode, \
1079 target_stat_scsi_transport_show_attr_##_name, \
1080 target_stat_scsi_transport_store_attr_##_name);
1082 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
1083 static struct target_stat_scsi_transport_attribute \
1084 target_stat_scsi_transport_##_name = \
1085 __CONFIGFS_EATTR_RO(_name, \
1086 target_stat_scsi_transport_show_attr_##_name);
1088 static ssize_t target_stat_scsi_transport_show_attr_inst(
1089 struct se_port_stat_grps *pgrps, char *page)
1091 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1092 struct se_device *dev = lun->lun_se_dev;
1093 struct se_port *sep;
1094 struct se_hba *hba;
1095 ssize_t ret;
1097 spin_lock(&lun->lun_sep_lock);
1098 sep = lun->lun_sep;
1099 if (!sep) {
1100 spin_unlock(&lun->lun_sep_lock);
1101 return -ENODEV;
1104 hba = dev->se_hba;
1105 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
1106 spin_unlock(&lun->lun_sep_lock);
1107 return ret;
1109 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
1111 static ssize_t target_stat_scsi_transport_show_attr_device(
1112 struct se_port_stat_grps *pgrps, char *page)
1114 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1115 struct se_port *sep;
1116 struct se_portal_group *tpg;
1117 ssize_t ret;
1119 spin_lock(&lun->lun_sep_lock);
1120 sep = lun->lun_sep;
1121 if (!sep) {
1122 spin_unlock(&lun->lun_sep_lock);
1123 return -ENODEV;
1125 tpg = sep->sep_tpg;
1126 /* scsiTransportType */
1127 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
1128 tpg->se_tpg_tfo->get_fabric_name());
1129 spin_unlock(&lun->lun_sep_lock);
1130 return ret;
1132 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
1134 static ssize_t target_stat_scsi_transport_show_attr_indx(
1135 struct se_port_stat_grps *pgrps, char *page)
1137 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1138 struct se_port *sep;
1139 struct se_portal_group *tpg;
1140 ssize_t ret;
1142 spin_lock(&lun->lun_sep_lock);
1143 sep = lun->lun_sep;
1144 if (!sep) {
1145 spin_unlock(&lun->lun_sep_lock);
1146 return -ENODEV;
1148 tpg = sep->sep_tpg;
1149 ret = snprintf(page, PAGE_SIZE, "%u\n",
1150 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1151 spin_unlock(&lun->lun_sep_lock);
1152 return ret;
1154 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
1156 static ssize_t target_stat_scsi_transport_show_attr_dev_name(
1157 struct se_port_stat_grps *pgrps, char *page)
1159 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1160 struct se_device *dev = lun->lun_se_dev;
1161 struct se_port *sep;
1162 struct se_portal_group *tpg;
1163 struct t10_wwn *wwn;
1164 ssize_t ret;
1166 spin_lock(&lun->lun_sep_lock);
1167 sep = lun->lun_sep;
1168 if (!sep) {
1169 spin_unlock(&lun->lun_sep_lock);
1170 return -ENODEV;
1172 tpg = sep->sep_tpg;
1173 wwn = &dev->se_sub_dev->t10_wwn;
1174 /* scsiTransportDevName */
1175 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1176 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1177 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
1178 wwn->vendor);
1179 spin_unlock(&lun->lun_sep_lock);
1180 return ret;
1182 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1184 CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1185 scsi_transport_group);
1187 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1188 &target_stat_scsi_transport_inst.attr,
1189 &target_stat_scsi_transport_device.attr,
1190 &target_stat_scsi_transport_indx.attr,
1191 &target_stat_scsi_transport_dev_name.attr,
1192 NULL,
1195 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1196 .show_attribute = target_stat_scsi_transport_attr_show,
1197 .store_attribute = target_stat_scsi_transport_attr_store,
1200 static struct config_item_type target_stat_scsi_transport_cit = {
1201 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
1202 .ct_attrs = target_stat_scsi_transport_attrs,
1203 .ct_owner = THIS_MODULE,
1207 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1208 * the target port statistics groups + configfs CITs located in target_core_stat.c
1210 void target_stat_setup_port_default_groups(struct se_lun *lun)
1212 struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
1214 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
1215 "scsi_port", &target_stat_scsi_port_cit);
1216 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
1217 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1218 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
1219 "scsi_transport", &target_stat_scsi_transport_cit);
1221 port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
1222 port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
1223 port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
1224 port_stat_grp->default_groups[3] = NULL;
1228 * SCSI Authorized Initiator Table
1231 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1232 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1233 static struct target_stat_scsi_auth_intr_attribute \
1234 target_stat_scsi_auth_intr_##_name = \
1235 __CONFIGFS_EATTR(_name, _mode, \
1236 target_stat_scsi_auth_intr_show_attr_##_name, \
1237 target_stat_scsi_auth_intr_store_attr_##_name);
1239 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1240 static struct target_stat_scsi_auth_intr_attribute \
1241 target_stat_scsi_auth_intr_##_name = \
1242 __CONFIGFS_EATTR_RO(_name, \
1243 target_stat_scsi_auth_intr_show_attr_##_name);
1245 static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1246 struct se_ml_stat_grps *lgrps, char *page)
1248 struct se_lun_acl *lacl = container_of(lgrps,
1249 struct se_lun_acl, ml_stat_grps);
1250 struct se_node_acl *nacl = lacl->se_lun_nacl;
1251 struct se_dev_entry *deve;
1252 struct se_portal_group *tpg;
1253 ssize_t ret;
1255 spin_lock_irq(&nacl->device_list_lock);
1256 deve = &nacl->device_list[lacl->mapped_lun];
1257 if (!deve->se_lun || !deve->se_lun_acl) {
1258 spin_unlock_irq(&nacl->device_list_lock);
1259 return -ENODEV;
1261 tpg = nacl->se_tpg;
1262 /* scsiInstIndex */
1263 ret = snprintf(page, PAGE_SIZE, "%u\n",
1264 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1265 spin_unlock_irq(&nacl->device_list_lock);
1266 return ret;
1268 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1270 static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1271 struct se_ml_stat_grps *lgrps, char *page)
1273 struct se_lun_acl *lacl = container_of(lgrps,
1274 struct se_lun_acl, ml_stat_grps);
1275 struct se_node_acl *nacl = lacl->se_lun_nacl;
1276 struct se_dev_entry *deve;
1277 struct se_lun *lun;
1278 struct se_portal_group *tpg;
1279 ssize_t ret;
1281 spin_lock_irq(&nacl->device_list_lock);
1282 deve = &nacl->device_list[lacl->mapped_lun];
1283 if (!deve->se_lun || !deve->se_lun_acl) {
1284 spin_unlock_irq(&nacl->device_list_lock);
1285 return -ENODEV;
1287 tpg = nacl->se_tpg;
1288 lun = deve->se_lun;
1289 /* scsiDeviceIndex */
1290 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1291 spin_unlock_irq(&nacl->device_list_lock);
1292 return ret;
1294 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1296 static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1297 struct se_ml_stat_grps *lgrps, char *page)
1299 struct se_lun_acl *lacl = container_of(lgrps,
1300 struct se_lun_acl, ml_stat_grps);
1301 struct se_node_acl *nacl = lacl->se_lun_nacl;
1302 struct se_dev_entry *deve;
1303 struct se_portal_group *tpg;
1304 ssize_t ret;
1306 spin_lock_irq(&nacl->device_list_lock);
1307 deve = &nacl->device_list[lacl->mapped_lun];
1308 if (!deve->se_lun || !deve->se_lun_acl) {
1309 spin_unlock_irq(&nacl->device_list_lock);
1310 return -ENODEV;
1312 tpg = nacl->se_tpg;
1313 /* scsiAuthIntrTgtPortIndex */
1314 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1315 spin_unlock_irq(&nacl->device_list_lock);
1316 return ret;
1318 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1320 static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1321 struct se_ml_stat_grps *lgrps, char *page)
1323 struct se_lun_acl *lacl = container_of(lgrps,
1324 struct se_lun_acl, ml_stat_grps);
1325 struct se_node_acl *nacl = lacl->se_lun_nacl;
1326 struct se_dev_entry *deve;
1327 ssize_t ret;
1329 spin_lock_irq(&nacl->device_list_lock);
1330 deve = &nacl->device_list[lacl->mapped_lun];
1331 if (!deve->se_lun || !deve->se_lun_acl) {
1332 spin_unlock_irq(&nacl->device_list_lock);
1333 return -ENODEV;
1335 /* scsiAuthIntrIndex */
1336 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1337 spin_unlock_irq(&nacl->device_list_lock);
1338 return ret;
1340 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1342 static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1343 struct se_ml_stat_grps *lgrps, char *page)
1345 struct se_lun_acl *lacl = container_of(lgrps,
1346 struct se_lun_acl, ml_stat_grps);
1347 struct se_node_acl *nacl = lacl->se_lun_nacl;
1348 struct se_dev_entry *deve;
1349 ssize_t ret;
1351 spin_lock_irq(&nacl->device_list_lock);
1352 deve = &nacl->device_list[lacl->mapped_lun];
1353 if (!deve->se_lun || !deve->se_lun_acl) {
1354 spin_unlock_irq(&nacl->device_list_lock);
1355 return -ENODEV;
1357 /* scsiAuthIntrDevOrPort */
1358 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1359 spin_unlock_irq(&nacl->device_list_lock);
1360 return ret;
1362 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1364 static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1365 struct se_ml_stat_grps *lgrps, char *page)
1367 struct se_lun_acl *lacl = container_of(lgrps,
1368 struct se_lun_acl, ml_stat_grps);
1369 struct se_node_acl *nacl = lacl->se_lun_nacl;
1370 struct se_dev_entry *deve;
1371 ssize_t ret;
1373 spin_lock_irq(&nacl->device_list_lock);
1374 deve = &nacl->device_list[lacl->mapped_lun];
1375 if (!deve->se_lun || !deve->se_lun_acl) {
1376 spin_unlock_irq(&nacl->device_list_lock);
1377 return -ENODEV;
1379 /* scsiAuthIntrName */
1380 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1381 spin_unlock_irq(&nacl->device_list_lock);
1382 return ret;
1384 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1386 static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1387 struct se_ml_stat_grps *lgrps, char *page)
1389 struct se_lun_acl *lacl = container_of(lgrps,
1390 struct se_lun_acl, ml_stat_grps);
1391 struct se_node_acl *nacl = lacl->se_lun_nacl;
1392 struct se_dev_entry *deve;
1393 ssize_t ret;
1395 spin_lock_irq(&nacl->device_list_lock);
1396 deve = &nacl->device_list[lacl->mapped_lun];
1397 if (!deve->se_lun || !deve->se_lun_acl) {
1398 spin_unlock_irq(&nacl->device_list_lock);
1399 return -ENODEV;
1401 /* FIXME: scsiAuthIntrLunMapIndex */
1402 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1403 spin_unlock_irq(&nacl->device_list_lock);
1404 return ret;
1406 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1408 static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1409 struct se_ml_stat_grps *lgrps, char *page)
1411 struct se_lun_acl *lacl = container_of(lgrps,
1412 struct se_lun_acl, ml_stat_grps);
1413 struct se_node_acl *nacl = lacl->se_lun_nacl;
1414 struct se_dev_entry *deve;
1415 ssize_t ret;
1417 spin_lock_irq(&nacl->device_list_lock);
1418 deve = &nacl->device_list[lacl->mapped_lun];
1419 if (!deve->se_lun || !deve->se_lun_acl) {
1420 spin_unlock_irq(&nacl->device_list_lock);
1421 return -ENODEV;
1423 /* scsiAuthIntrAttachedTimes */
1424 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1425 spin_unlock_irq(&nacl->device_list_lock);
1426 return ret;
1428 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1430 static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1431 struct se_ml_stat_grps *lgrps, char *page)
1433 struct se_lun_acl *lacl = container_of(lgrps,
1434 struct se_lun_acl, ml_stat_grps);
1435 struct se_node_acl *nacl = lacl->se_lun_nacl;
1436 struct se_dev_entry *deve;
1437 ssize_t ret;
1439 spin_lock_irq(&nacl->device_list_lock);
1440 deve = &nacl->device_list[lacl->mapped_lun];
1441 if (!deve->se_lun || !deve->se_lun_acl) {
1442 spin_unlock_irq(&nacl->device_list_lock);
1443 return -ENODEV;
1445 /* scsiAuthIntrOutCommands */
1446 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1447 spin_unlock_irq(&nacl->device_list_lock);
1448 return ret;
1450 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1452 static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1453 struct se_ml_stat_grps *lgrps, char *page)
1455 struct se_lun_acl *lacl = container_of(lgrps,
1456 struct se_lun_acl, ml_stat_grps);
1457 struct se_node_acl *nacl = lacl->se_lun_nacl;
1458 struct se_dev_entry *deve;
1459 ssize_t ret;
1461 spin_lock_irq(&nacl->device_list_lock);
1462 deve = &nacl->device_list[lacl->mapped_lun];
1463 if (!deve->se_lun || !deve->se_lun_acl) {
1464 spin_unlock_irq(&nacl->device_list_lock);
1465 return -ENODEV;
1467 /* scsiAuthIntrReadMegaBytes */
1468 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1469 spin_unlock_irq(&nacl->device_list_lock);
1470 return ret;
1472 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1474 static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1475 struct se_ml_stat_grps *lgrps, char *page)
1477 struct se_lun_acl *lacl = container_of(lgrps,
1478 struct se_lun_acl, ml_stat_grps);
1479 struct se_node_acl *nacl = lacl->se_lun_nacl;
1480 struct se_dev_entry *deve;
1481 ssize_t ret;
1483 spin_lock_irq(&nacl->device_list_lock);
1484 deve = &nacl->device_list[lacl->mapped_lun];
1485 if (!deve->se_lun || !deve->se_lun_acl) {
1486 spin_unlock_irq(&nacl->device_list_lock);
1487 return -ENODEV;
1489 /* scsiAuthIntrWrittenMegaBytes */
1490 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1491 spin_unlock_irq(&nacl->device_list_lock);
1492 return ret;
1494 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1496 static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1497 struct se_ml_stat_grps *lgrps, char *page)
1499 struct se_lun_acl *lacl = container_of(lgrps,
1500 struct se_lun_acl, ml_stat_grps);
1501 struct se_node_acl *nacl = lacl->se_lun_nacl;
1502 struct se_dev_entry *deve;
1503 ssize_t ret;
1505 spin_lock_irq(&nacl->device_list_lock);
1506 deve = &nacl->device_list[lacl->mapped_lun];
1507 if (!deve->se_lun || !deve->se_lun_acl) {
1508 spin_unlock_irq(&nacl->device_list_lock);
1509 return -ENODEV;
1511 /* FIXME: scsiAuthIntrHSOutCommands */
1512 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1513 spin_unlock_irq(&nacl->device_list_lock);
1514 return ret;
1516 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1518 static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1519 struct se_ml_stat_grps *lgrps, char *page)
1521 struct se_lun_acl *lacl = container_of(lgrps,
1522 struct se_lun_acl, ml_stat_grps);
1523 struct se_node_acl *nacl = lacl->se_lun_nacl;
1524 struct se_dev_entry *deve;
1525 ssize_t ret;
1527 spin_lock_irq(&nacl->device_list_lock);
1528 deve = &nacl->device_list[lacl->mapped_lun];
1529 if (!deve->se_lun || !deve->se_lun_acl) {
1530 spin_unlock_irq(&nacl->device_list_lock);
1531 return -ENODEV;
1533 /* scsiAuthIntrLastCreation */
1534 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1535 INITIAL_JIFFIES) * 100 / HZ));
1536 spin_unlock_irq(&nacl->device_list_lock);
1537 return ret;
1539 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1541 static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
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 /* FIXME: scsiAuthIntrRowStatus */
1557 ret = snprintf(page, PAGE_SIZE, "Ready\n");
1558 spin_unlock_irq(&nacl->device_list_lock);
1559 return ret;
1561 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1563 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1564 scsi_auth_intr_group);
1566 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1567 &target_stat_scsi_auth_intr_inst.attr,
1568 &target_stat_scsi_auth_intr_dev.attr,
1569 &target_stat_scsi_auth_intr_port.attr,
1570 &target_stat_scsi_auth_intr_indx.attr,
1571 &target_stat_scsi_auth_intr_dev_or_port.attr,
1572 &target_stat_scsi_auth_intr_intr_name.attr,
1573 &target_stat_scsi_auth_intr_map_indx.attr,
1574 &target_stat_scsi_auth_intr_att_count.attr,
1575 &target_stat_scsi_auth_intr_num_cmds.attr,
1576 &target_stat_scsi_auth_intr_read_mbytes.attr,
1577 &target_stat_scsi_auth_intr_write_mbytes.attr,
1578 &target_stat_scsi_auth_intr_hs_num_cmds.attr,
1579 &target_stat_scsi_auth_intr_creation_time.attr,
1580 &target_stat_scsi_auth_intr_row_status.attr,
1581 NULL,
1584 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1585 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1586 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1589 static struct config_item_type target_stat_scsi_auth_intr_cit = {
1590 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1591 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1592 .ct_owner = THIS_MODULE,
1596 * SCSI Attached Initiator Port Table
1599 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1600 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1601 static struct target_stat_scsi_att_intr_port_attribute \
1602 target_stat_scsi_att_intr_port_##_name = \
1603 __CONFIGFS_EATTR(_name, _mode, \
1604 target_stat_scsi_att_intr_port_show_attr_##_name, \
1605 target_stat_scsi_att_intr_port_store_attr_##_name);
1607 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1608 static struct target_stat_scsi_att_intr_port_attribute \
1609 target_stat_scsi_att_intr_port_##_name = \
1610 __CONFIGFS_EATTR_RO(_name, \
1611 target_stat_scsi_att_intr_port_show_attr_##_name);
1613 static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1614 struct se_ml_stat_grps *lgrps, char *page)
1616 struct se_lun_acl *lacl = container_of(lgrps,
1617 struct se_lun_acl, ml_stat_grps);
1618 struct se_node_acl *nacl = lacl->se_lun_nacl;
1619 struct se_dev_entry *deve;
1620 struct se_portal_group *tpg;
1621 ssize_t ret;
1623 spin_lock_irq(&nacl->device_list_lock);
1624 deve = &nacl->device_list[lacl->mapped_lun];
1625 if (!deve->se_lun || !deve->se_lun_acl) {
1626 spin_unlock_irq(&nacl->device_list_lock);
1627 return -ENODEV;
1629 tpg = nacl->se_tpg;
1630 /* scsiInstIndex */
1631 ret = snprintf(page, PAGE_SIZE, "%u\n",
1632 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1633 spin_unlock_irq(&nacl->device_list_lock);
1634 return ret;
1636 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1638 static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1639 struct se_ml_stat_grps *lgrps, char *page)
1641 struct se_lun_acl *lacl = container_of(lgrps,
1642 struct se_lun_acl, ml_stat_grps);
1643 struct se_node_acl *nacl = lacl->se_lun_nacl;
1644 struct se_dev_entry *deve;
1645 struct se_lun *lun;
1646 struct se_portal_group *tpg;
1647 ssize_t ret;
1649 spin_lock_irq(&nacl->device_list_lock);
1650 deve = &nacl->device_list[lacl->mapped_lun];
1651 if (!deve->se_lun || !deve->se_lun_acl) {
1652 spin_unlock_irq(&nacl->device_list_lock);
1653 return -ENODEV;
1655 tpg = nacl->se_tpg;
1656 lun = deve->se_lun;
1657 /* scsiDeviceIndex */
1658 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1659 spin_unlock_irq(&nacl->device_list_lock);
1660 return ret;
1662 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1664 static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1665 struct se_ml_stat_grps *lgrps, char *page)
1667 struct se_lun_acl *lacl = container_of(lgrps,
1668 struct se_lun_acl, ml_stat_grps);
1669 struct se_node_acl *nacl = lacl->se_lun_nacl;
1670 struct se_dev_entry *deve;
1671 struct se_portal_group *tpg;
1672 ssize_t ret;
1674 spin_lock_irq(&nacl->device_list_lock);
1675 deve = &nacl->device_list[lacl->mapped_lun];
1676 if (!deve->se_lun || !deve->se_lun_acl) {
1677 spin_unlock_irq(&nacl->device_list_lock);
1678 return -ENODEV;
1680 tpg = nacl->se_tpg;
1681 /* scsiPortIndex */
1682 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1683 spin_unlock_irq(&nacl->device_list_lock);
1684 return ret;
1686 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1688 static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1689 struct se_ml_stat_grps *lgrps, char *page)
1691 struct se_lun_acl *lacl = container_of(lgrps,
1692 struct se_lun_acl, ml_stat_grps);
1693 struct se_node_acl *nacl = lacl->se_lun_nacl;
1694 struct se_session *se_sess;
1695 struct se_portal_group *tpg;
1696 ssize_t ret;
1698 spin_lock_irq(&nacl->nacl_sess_lock);
1699 se_sess = nacl->nacl_sess;
1700 if (!se_sess) {
1701 spin_unlock_irq(&nacl->nacl_sess_lock);
1702 return -ENODEV;
1705 tpg = nacl->se_tpg;
1706 /* scsiAttIntrPortIndex */
1707 ret = snprintf(page, PAGE_SIZE, "%u\n",
1708 tpg->se_tpg_tfo->sess_get_index(se_sess));
1709 spin_unlock_irq(&nacl->nacl_sess_lock);
1710 return ret;
1712 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1714 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1715 struct se_ml_stat_grps *lgrps, char *page)
1717 struct se_lun_acl *lacl = container_of(lgrps,
1718 struct se_lun_acl, ml_stat_grps);
1719 struct se_node_acl *nacl = lacl->se_lun_nacl;
1720 struct se_dev_entry *deve;
1721 ssize_t ret;
1723 spin_lock_irq(&nacl->device_list_lock);
1724 deve = &nacl->device_list[lacl->mapped_lun];
1725 if (!deve->se_lun || !deve->se_lun_acl) {
1726 spin_unlock_irq(&nacl->device_list_lock);
1727 return -ENODEV;
1729 /* scsiAttIntrPortAuthIntrIdx */
1730 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1731 spin_unlock_irq(&nacl->device_list_lock);
1732 return ret;
1734 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1736 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1737 struct se_ml_stat_grps *lgrps, char *page)
1739 struct se_lun_acl *lacl = container_of(lgrps,
1740 struct se_lun_acl, ml_stat_grps);
1741 struct se_node_acl *nacl = lacl->se_lun_nacl;
1742 struct se_session *se_sess;
1743 struct se_portal_group *tpg;
1744 ssize_t ret;
1745 unsigned char buf[64];
1747 spin_lock_irq(&nacl->nacl_sess_lock);
1748 se_sess = nacl->nacl_sess;
1749 if (!se_sess) {
1750 spin_unlock_irq(&nacl->nacl_sess_lock);
1751 return -ENODEV;
1754 tpg = nacl->se_tpg;
1755 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1756 memset(buf, 0, 64);
1757 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1758 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess,
1759 (unsigned char *)&buf[0], 64);
1761 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1762 spin_unlock_irq(&nacl->nacl_sess_lock);
1763 return ret;
1765 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1767 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1768 scsi_att_intr_port_group);
1770 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1771 &target_stat_scsi_att_intr_port_inst.attr,
1772 &target_stat_scsi_att_intr_port_dev.attr,
1773 &target_stat_scsi_att_intr_port_port.attr,
1774 &target_stat_scsi_att_intr_port_indx.attr,
1775 &target_stat_scsi_att_intr_port_port_auth_indx.attr,
1776 &target_stat_scsi_att_intr_port_port_ident.attr,
1777 NULL,
1780 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1781 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1782 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1785 static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1786 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1787 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1788 .ct_owner = THIS_MODULE,
1792 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1793 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1795 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1797 struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
1799 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1800 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1801 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1802 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1804 ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1805 ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
1806 ml_stat_grp->default_groups[2] = NULL;