sparc: Don't do expensive hypervisor PCR write unless necessary.
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / target / target_core_stat.c
blob5e3a067a7475ff25fce01b72fc67d96660997c00
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 <linux/version.h>
36 #include <generated/utsrelease.h>
37 #include <linux/utsname.h>
38 #include <linux/proc_fs.h>
39 #include <linux/seq_file.h>
40 #include <linux/blkdev.h>
41 #include <linux/configfs.h>
42 #include <scsi/scsi.h>
43 #include <scsi/scsi_device.h>
44 #include <scsi/scsi_host.h>
46 #include <target/target_core_base.h>
47 #include <target/target_core_transport.h>
48 #include <target/target_core_fabric_ops.h>
49 #include <target/target_core_configfs.h>
50 #include <target/configfs_macros.h>
52 #include "target_core_hba.h"
54 #ifndef INITIAL_JIFFIES
55 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
56 #endif
58 #define NONE "None"
59 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
61 #define SCSI_LU_INDEX 1
62 #define LU_COUNT 1
65 * SCSI Device Table
68 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
69 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
70 static struct target_stat_scsi_dev_attribute \
71 target_stat_scsi_dev_##_name = \
72 __CONFIGFS_EATTR(_name, _mode, \
73 target_stat_scsi_dev_show_attr_##_name, \
74 target_stat_scsi_dev_store_attr_##_name);
76 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
77 static struct target_stat_scsi_dev_attribute \
78 target_stat_scsi_dev_##_name = \
79 __CONFIGFS_EATTR_RO(_name, \
80 target_stat_scsi_dev_show_attr_##_name);
82 static ssize_t target_stat_scsi_dev_show_attr_inst(
83 struct se_dev_stat_grps *sgrps, char *page)
85 struct se_subsystem_dev *se_subdev = container_of(sgrps,
86 struct se_subsystem_dev, dev_stat_grps);
87 struct se_hba *hba = se_subdev->se_dev_hba;
88 struct se_device *dev = se_subdev->se_dev_ptr;
90 if (!dev)
91 return -ENODEV;
93 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
95 DEV_STAT_SCSI_DEV_ATTR_RO(inst);
97 static ssize_t target_stat_scsi_dev_show_attr_indx(
98 struct se_dev_stat_grps *sgrps, char *page)
100 struct se_subsystem_dev *se_subdev = container_of(sgrps,
101 struct se_subsystem_dev, dev_stat_grps);
102 struct se_device *dev = se_subdev->se_dev_ptr;
104 if (!dev)
105 return -ENODEV;
107 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
109 DEV_STAT_SCSI_DEV_ATTR_RO(indx);
111 static ssize_t target_stat_scsi_dev_show_attr_role(
112 struct se_dev_stat_grps *sgrps, char *page)
114 struct se_subsystem_dev *se_subdev = container_of(sgrps,
115 struct se_subsystem_dev, dev_stat_grps);
116 struct se_device *dev = se_subdev->se_dev_ptr;
118 if (!dev)
119 return -ENODEV;
121 return snprintf(page, PAGE_SIZE, "Target\n");
123 DEV_STAT_SCSI_DEV_ATTR_RO(role);
125 static ssize_t target_stat_scsi_dev_show_attr_ports(
126 struct se_dev_stat_grps *sgrps, char *page)
128 struct se_subsystem_dev *se_subdev = container_of(sgrps,
129 struct se_subsystem_dev, dev_stat_grps);
130 struct se_device *dev = se_subdev->se_dev_ptr;
132 if (!dev)
133 return -ENODEV;
135 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
137 DEV_STAT_SCSI_DEV_ATTR_RO(ports);
139 CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
141 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
142 &target_stat_scsi_dev_inst.attr,
143 &target_stat_scsi_dev_indx.attr,
144 &target_stat_scsi_dev_role.attr,
145 &target_stat_scsi_dev_ports.attr,
146 NULL,
149 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
150 .show_attribute = target_stat_scsi_dev_attr_show,
151 .store_attribute = target_stat_scsi_dev_attr_store,
154 static struct config_item_type target_stat_scsi_dev_cit = {
155 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
156 .ct_attrs = target_stat_scsi_dev_attrs,
157 .ct_owner = THIS_MODULE,
161 * SCSI Target Device Table
164 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
165 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
166 static struct target_stat_scsi_tgt_dev_attribute \
167 target_stat_scsi_tgt_dev_##_name = \
168 __CONFIGFS_EATTR(_name, _mode, \
169 target_stat_scsi_tgt_dev_show_attr_##_name, \
170 target_stat_scsi_tgt_dev_store_attr_##_name);
172 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
173 static struct target_stat_scsi_tgt_dev_attribute \
174 target_stat_scsi_tgt_dev_##_name = \
175 __CONFIGFS_EATTR_RO(_name, \
176 target_stat_scsi_tgt_dev_show_attr_##_name);
178 static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
179 struct se_dev_stat_grps *sgrps, char *page)
181 struct se_subsystem_dev *se_subdev = container_of(sgrps,
182 struct se_subsystem_dev, dev_stat_grps);
183 struct se_hba *hba = se_subdev->se_dev_hba;
184 struct se_device *dev = se_subdev->se_dev_ptr;
186 if (!dev)
187 return -ENODEV;
189 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
191 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
193 static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
194 struct se_dev_stat_grps *sgrps, char *page)
196 struct se_subsystem_dev *se_subdev = container_of(sgrps,
197 struct se_subsystem_dev, dev_stat_grps);
198 struct se_device *dev = se_subdev->se_dev_ptr;
200 if (!dev)
201 return -ENODEV;
203 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
205 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
207 static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
208 struct se_dev_stat_grps *sgrps, char *page)
210 struct se_subsystem_dev *se_subdev = container_of(sgrps,
211 struct se_subsystem_dev, dev_stat_grps);
212 struct se_device *dev = se_subdev->se_dev_ptr;
214 if (!dev)
215 return -ENODEV;
217 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
219 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
221 static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
222 struct se_dev_stat_grps *sgrps, char *page)
224 struct se_subsystem_dev *se_subdev = container_of(sgrps,
225 struct se_subsystem_dev, dev_stat_grps);
226 struct se_device *dev = se_subdev->se_dev_ptr;
227 char status[16];
229 if (!dev)
230 return -ENODEV;
232 switch (dev->dev_status) {
233 case TRANSPORT_DEVICE_ACTIVATED:
234 strcpy(status, "activated");
235 break;
236 case TRANSPORT_DEVICE_DEACTIVATED:
237 strcpy(status, "deactivated");
238 break;
239 case TRANSPORT_DEVICE_SHUTDOWN:
240 strcpy(status, "shutdown");
241 break;
242 case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
243 case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
244 strcpy(status, "offline");
245 break;
246 default:
247 sprintf(status, "unknown(%d)", dev->dev_status);
248 break;
251 return snprintf(page, PAGE_SIZE, "%s\n", status);
253 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
255 static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
256 struct se_dev_stat_grps *sgrps, char *page)
258 struct se_subsystem_dev *se_subdev = container_of(sgrps,
259 struct se_subsystem_dev, dev_stat_grps);
260 struct se_device *dev = se_subdev->se_dev_ptr;
261 int non_accessible_lus;
263 if (!dev)
264 return -ENODEV;
266 switch (dev->dev_status) {
267 case TRANSPORT_DEVICE_ACTIVATED:
268 non_accessible_lus = 0;
269 break;
270 case TRANSPORT_DEVICE_DEACTIVATED:
271 case TRANSPORT_DEVICE_SHUTDOWN:
272 case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
273 case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
274 default:
275 non_accessible_lus = 1;
276 break;
279 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
281 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
283 static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
284 struct se_dev_stat_grps *sgrps, char *page)
286 struct se_subsystem_dev *se_subdev = container_of(sgrps,
287 struct se_subsystem_dev, dev_stat_grps);
288 struct se_device *dev = se_subdev->se_dev_ptr;
290 if (!dev)
291 return -ENODEV;
293 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
295 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
298 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
300 static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
301 &target_stat_scsi_tgt_dev_inst.attr,
302 &target_stat_scsi_tgt_dev_indx.attr,
303 &target_stat_scsi_tgt_dev_num_lus.attr,
304 &target_stat_scsi_tgt_dev_status.attr,
305 &target_stat_scsi_tgt_dev_non_access_lus.attr,
306 &target_stat_scsi_tgt_dev_resets.attr,
307 NULL,
310 static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
311 .show_attribute = target_stat_scsi_tgt_dev_attr_show,
312 .store_attribute = target_stat_scsi_tgt_dev_attr_store,
315 static struct config_item_type target_stat_scsi_tgt_dev_cit = {
316 .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
317 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
318 .ct_owner = THIS_MODULE,
322 * SCSI Logical Unit Table
325 CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
326 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
327 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
328 __CONFIGFS_EATTR(_name, _mode, \
329 target_stat_scsi_lu_show_attr_##_name, \
330 target_stat_scsi_lu_store_attr_##_name);
332 #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
333 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
334 __CONFIGFS_EATTR_RO(_name, \
335 target_stat_scsi_lu_show_attr_##_name);
337 static ssize_t target_stat_scsi_lu_show_attr_inst(
338 struct se_dev_stat_grps *sgrps, char *page)
340 struct se_subsystem_dev *se_subdev = container_of(sgrps,
341 struct se_subsystem_dev, dev_stat_grps);
342 struct se_hba *hba = se_subdev->se_dev_hba;
343 struct se_device *dev = se_subdev->se_dev_ptr;
345 if (!dev)
346 return -ENODEV;
348 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
350 DEV_STAT_SCSI_LU_ATTR_RO(inst);
352 static ssize_t target_stat_scsi_lu_show_attr_dev(
353 struct se_dev_stat_grps *sgrps, char *page)
355 struct se_subsystem_dev *se_subdev = container_of(sgrps,
356 struct se_subsystem_dev, dev_stat_grps);
357 struct se_device *dev = se_subdev->se_dev_ptr;
359 if (!dev)
360 return -ENODEV;
362 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
364 DEV_STAT_SCSI_LU_ATTR_RO(dev);
366 static ssize_t target_stat_scsi_lu_show_attr_indx(
367 struct se_dev_stat_grps *sgrps, char *page)
369 struct se_subsystem_dev *se_subdev = container_of(sgrps,
370 struct se_subsystem_dev, dev_stat_grps);
371 struct se_device *dev = se_subdev->se_dev_ptr;
373 if (!dev)
374 return -ENODEV;
376 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
378 DEV_STAT_SCSI_LU_ATTR_RO(indx);
380 static ssize_t target_stat_scsi_lu_show_attr_lun(
381 struct se_dev_stat_grps *sgrps, char *page)
383 struct se_subsystem_dev *se_subdev = container_of(sgrps,
384 struct se_subsystem_dev, dev_stat_grps);
385 struct se_device *dev = se_subdev->se_dev_ptr;
387 if (!dev)
388 return -ENODEV;
389 /* FIXME: scsiLuDefaultLun */
390 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
392 DEV_STAT_SCSI_LU_ATTR_RO(lun);
394 static ssize_t target_stat_scsi_lu_show_attr_lu_name(
395 struct se_dev_stat_grps *sgrps, char *page)
397 struct se_subsystem_dev *se_subdev = container_of(sgrps,
398 struct se_subsystem_dev, dev_stat_grps);
399 struct se_device *dev = se_subdev->se_dev_ptr;
401 if (!dev)
402 return -ENODEV;
403 /* scsiLuWwnName */
404 return snprintf(page, PAGE_SIZE, "%s\n",
405 (strlen(DEV_T10_WWN(dev)->unit_serial)) ?
406 (char *)&DEV_T10_WWN(dev)->unit_serial[0] : "None");
408 DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
410 static ssize_t target_stat_scsi_lu_show_attr_vend(
411 struct se_dev_stat_grps *sgrps, char *page)
413 struct se_subsystem_dev *se_subdev = container_of(sgrps,
414 struct se_subsystem_dev, dev_stat_grps);
415 struct se_device *dev = se_subdev->se_dev_ptr;
416 int j;
417 char str[28];
419 if (!dev)
420 return -ENODEV;
421 /* scsiLuVendorId */
422 memcpy(&str[0], (void *)DEV_T10_WWN(dev), 28);
423 for (j = 0; j < 8; j++)
424 str[j] = ISPRINT(DEV_T10_WWN(dev)->vendor[j]) ?
425 DEV_T10_WWN(dev)->vendor[j] : 0x20;
426 str[8] = 0;
427 return snprintf(page, PAGE_SIZE, "%s\n", str);
429 DEV_STAT_SCSI_LU_ATTR_RO(vend);
431 static ssize_t target_stat_scsi_lu_show_attr_prod(
432 struct se_dev_stat_grps *sgrps, char *page)
434 struct se_subsystem_dev *se_subdev = container_of(sgrps,
435 struct se_subsystem_dev, dev_stat_grps);
436 struct se_device *dev = se_subdev->se_dev_ptr;
437 int j;
438 char str[28];
440 if (!dev)
441 return -ENODEV;
443 /* scsiLuProductId */
444 memcpy(&str[0], (void *)DEV_T10_WWN(dev), 28);
445 for (j = 0; j < 16; j++)
446 str[j] = ISPRINT(DEV_T10_WWN(dev)->model[j]) ?
447 DEV_T10_WWN(dev)->model[j] : 0x20;
448 str[16] = 0;
449 return snprintf(page, PAGE_SIZE, "%s\n", str);
451 DEV_STAT_SCSI_LU_ATTR_RO(prod);
453 static ssize_t target_stat_scsi_lu_show_attr_rev(
454 struct se_dev_stat_grps *sgrps, char *page)
456 struct se_subsystem_dev *se_subdev = container_of(sgrps,
457 struct se_subsystem_dev, dev_stat_grps);
458 struct se_device *dev = se_subdev->se_dev_ptr;
459 int j;
460 char str[28];
462 if (!dev)
463 return -ENODEV;
465 /* scsiLuRevisionId */
466 memcpy(&str[0], (void *)DEV_T10_WWN(dev), 28);
467 for (j = 0; j < 4; j++)
468 str[j] = ISPRINT(DEV_T10_WWN(dev)->revision[j]) ?
469 DEV_T10_WWN(dev)->revision[j] : 0x20;
470 str[4] = 0;
471 return snprintf(page, PAGE_SIZE, "%s\n", str);
473 DEV_STAT_SCSI_LU_ATTR_RO(rev);
475 static ssize_t target_stat_scsi_lu_show_attr_dev_type(
476 struct se_dev_stat_grps *sgrps, char *page)
478 struct se_subsystem_dev *se_subdev = container_of(sgrps,
479 struct se_subsystem_dev, dev_stat_grps);
480 struct se_device *dev = se_subdev->se_dev_ptr;
482 if (!dev)
483 return -ENODEV;
485 /* scsiLuPeripheralType */
486 return snprintf(page, PAGE_SIZE, "%u\n",
487 TRANSPORT(dev)->get_device_type(dev));
489 DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
491 static ssize_t target_stat_scsi_lu_show_attr_status(
492 struct se_dev_stat_grps *sgrps, char *page)
494 struct se_subsystem_dev *se_subdev = container_of(sgrps,
495 struct se_subsystem_dev, dev_stat_grps);
496 struct se_device *dev = se_subdev->se_dev_ptr;
498 if (!dev)
499 return -ENODEV;
501 /* scsiLuStatus */
502 return snprintf(page, PAGE_SIZE, "%s\n",
503 (dev->dev_status == TRANSPORT_DEVICE_ACTIVATED) ?
504 "available" : "notavailable");
506 DEV_STAT_SCSI_LU_ATTR_RO(status);
508 static ssize_t target_stat_scsi_lu_show_attr_state_bit(
509 struct se_dev_stat_grps *sgrps, char *page)
511 struct se_subsystem_dev *se_subdev = container_of(sgrps,
512 struct se_subsystem_dev, dev_stat_grps);
513 struct se_device *dev = se_subdev->se_dev_ptr;
515 if (!dev)
516 return -ENODEV;
518 /* scsiLuState */
519 return snprintf(page, PAGE_SIZE, "exposed\n");
521 DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
523 static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
524 struct se_dev_stat_grps *sgrps, char *page)
526 struct se_subsystem_dev *se_subdev = container_of(sgrps,
527 struct se_subsystem_dev, dev_stat_grps);
528 struct se_device *dev = se_subdev->se_dev_ptr;
530 if (!dev)
531 return -ENODEV;
533 /* scsiLuNumCommands */
534 return snprintf(page, PAGE_SIZE, "%llu\n",
535 (unsigned long long)dev->num_cmds);
537 DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
539 static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
540 struct se_dev_stat_grps *sgrps, char *page)
542 struct se_subsystem_dev *se_subdev = container_of(sgrps,
543 struct se_subsystem_dev, dev_stat_grps);
544 struct se_device *dev = se_subdev->se_dev_ptr;
546 if (!dev)
547 return -ENODEV;
549 /* scsiLuReadMegaBytes */
550 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
552 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
554 static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
555 struct se_dev_stat_grps *sgrps, char *page)
557 struct se_subsystem_dev *se_subdev = container_of(sgrps,
558 struct se_subsystem_dev, dev_stat_grps);
559 struct se_device *dev = se_subdev->se_dev_ptr;
561 if (!dev)
562 return -ENODEV;
564 /* scsiLuWrittenMegaBytes */
565 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
567 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
569 static ssize_t target_stat_scsi_lu_show_attr_resets(
570 struct se_dev_stat_grps *sgrps, char *page)
572 struct se_subsystem_dev *se_subdev = container_of(sgrps,
573 struct se_subsystem_dev, dev_stat_grps);
574 struct se_device *dev = se_subdev->se_dev_ptr;
576 if (!dev)
577 return -ENODEV;
579 /* scsiLuInResets */
580 return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
582 DEV_STAT_SCSI_LU_ATTR_RO(resets);
584 static ssize_t target_stat_scsi_lu_show_attr_full_stat(
585 struct se_dev_stat_grps *sgrps, char *page)
587 struct se_subsystem_dev *se_subdev = container_of(sgrps,
588 struct se_subsystem_dev, dev_stat_grps);
589 struct se_device *dev = se_subdev->se_dev_ptr;
591 if (!dev)
592 return -ENODEV;
594 /* FIXME: scsiLuOutTaskSetFullStatus */
595 return snprintf(page, PAGE_SIZE, "%u\n", 0);
597 DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
599 static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
600 struct se_dev_stat_grps *sgrps, char *page)
602 struct se_subsystem_dev *se_subdev = container_of(sgrps,
603 struct se_subsystem_dev, dev_stat_grps);
604 struct se_device *dev = se_subdev->se_dev_ptr;
606 if (!dev)
607 return -ENODEV;
609 /* FIXME: scsiLuHSInCommands */
610 return snprintf(page, PAGE_SIZE, "%u\n", 0);
612 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
614 static ssize_t target_stat_scsi_lu_show_attr_creation_time(
615 struct se_dev_stat_grps *sgrps, char *page)
617 struct se_subsystem_dev *se_subdev = container_of(sgrps,
618 struct se_subsystem_dev, dev_stat_grps);
619 struct se_device *dev = se_subdev->se_dev_ptr;
621 if (!dev)
622 return -ENODEV;
624 /* scsiLuCreationTime */
625 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
626 INITIAL_JIFFIES) * 100 / HZ));
628 DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
630 CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
632 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
633 &target_stat_scsi_lu_inst.attr,
634 &target_stat_scsi_lu_dev.attr,
635 &target_stat_scsi_lu_indx.attr,
636 &target_stat_scsi_lu_lun.attr,
637 &target_stat_scsi_lu_lu_name.attr,
638 &target_stat_scsi_lu_vend.attr,
639 &target_stat_scsi_lu_prod.attr,
640 &target_stat_scsi_lu_rev.attr,
641 &target_stat_scsi_lu_dev_type.attr,
642 &target_stat_scsi_lu_status.attr,
643 &target_stat_scsi_lu_state_bit.attr,
644 &target_stat_scsi_lu_num_cmds.attr,
645 &target_stat_scsi_lu_read_mbytes.attr,
646 &target_stat_scsi_lu_write_mbytes.attr,
647 &target_stat_scsi_lu_resets.attr,
648 &target_stat_scsi_lu_full_stat.attr,
649 &target_stat_scsi_lu_hs_num_cmds.attr,
650 &target_stat_scsi_lu_creation_time.attr,
651 NULL,
654 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
655 .show_attribute = target_stat_scsi_lu_attr_show,
656 .store_attribute = target_stat_scsi_lu_attr_store,
659 static struct config_item_type target_stat_scsi_lu_cit = {
660 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
661 .ct_attrs = target_stat_scsi_lu_attrs,
662 .ct_owner = THIS_MODULE,
666 * Called from target_core_configfs.c:target_core_make_subdev() to setup
667 * the target statistics groups + configfs CITs located in target_core_stat.c
669 void target_stat_setup_dev_default_groups(struct se_subsystem_dev *se_subdev)
671 struct config_group *dev_stat_grp = &DEV_STAT_GRP(se_subdev)->stat_group;
673 config_group_init_type_name(&DEV_STAT_GRP(se_subdev)->scsi_dev_group,
674 "scsi_dev", &target_stat_scsi_dev_cit);
675 config_group_init_type_name(&DEV_STAT_GRP(se_subdev)->scsi_tgt_dev_group,
676 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
677 config_group_init_type_name(&DEV_STAT_GRP(se_subdev)->scsi_lu_group,
678 "scsi_lu", &target_stat_scsi_lu_cit);
680 dev_stat_grp->default_groups[0] = &DEV_STAT_GRP(se_subdev)->scsi_dev_group;
681 dev_stat_grp->default_groups[1] = &DEV_STAT_GRP(se_subdev)->scsi_tgt_dev_group;
682 dev_stat_grp->default_groups[2] = &DEV_STAT_GRP(se_subdev)->scsi_lu_group;
683 dev_stat_grp->default_groups[3] = NULL;
687 * SCSI Port Table
690 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
691 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
692 static struct target_stat_scsi_port_attribute \
693 target_stat_scsi_port_##_name = \
694 __CONFIGFS_EATTR(_name, _mode, \
695 target_stat_scsi_port_show_attr_##_name, \
696 target_stat_scsi_port_store_attr_##_name);
698 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
699 static struct target_stat_scsi_port_attribute \
700 target_stat_scsi_port_##_name = \
701 __CONFIGFS_EATTR_RO(_name, \
702 target_stat_scsi_port_show_attr_##_name);
704 static ssize_t target_stat_scsi_port_show_attr_inst(
705 struct se_port_stat_grps *pgrps, char *page)
707 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
708 struct se_port *sep;
709 struct se_device *dev = lun->lun_se_dev;
710 struct se_hba *hba;
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 hba = dev->se_hba;
720 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
721 spin_unlock(&lun->lun_sep_lock);
722 return ret;
724 DEV_STAT_SCSI_PORT_ATTR_RO(inst);
726 static ssize_t target_stat_scsi_port_show_attr_dev(
727 struct se_port_stat_grps *pgrps, char *page)
729 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
730 struct se_port *sep;
731 struct se_device *dev = lun->lun_se_dev;
732 ssize_t ret;
734 spin_lock(&lun->lun_sep_lock);
735 sep = lun->lun_sep;
736 if (!sep) {
737 spin_unlock(&lun->lun_sep_lock);
738 return -ENODEV;
740 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
741 spin_unlock(&lun->lun_sep_lock);
742 return ret;
744 DEV_STAT_SCSI_PORT_ATTR_RO(dev);
746 static ssize_t target_stat_scsi_port_show_attr_indx(
747 struct se_port_stat_grps *pgrps, char *page)
749 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
750 struct se_port *sep;
751 ssize_t ret;
753 spin_lock(&lun->lun_sep_lock);
754 sep = lun->lun_sep;
755 if (!sep) {
756 spin_unlock(&lun->lun_sep_lock);
757 return -ENODEV;
759 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
760 spin_unlock(&lun->lun_sep_lock);
761 return ret;
763 DEV_STAT_SCSI_PORT_ATTR_RO(indx);
765 static ssize_t target_stat_scsi_port_show_attr_role(
766 struct se_port_stat_grps *pgrps, char *page)
768 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
769 struct se_device *dev = lun->lun_se_dev;
770 struct se_port *sep;
771 ssize_t ret;
773 if (!dev)
774 return -ENODEV;
776 spin_lock(&lun->lun_sep_lock);
777 sep = lun->lun_sep;
778 if (!sep) {
779 spin_unlock(&lun->lun_sep_lock);
780 return -ENODEV;
782 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
783 spin_unlock(&lun->lun_sep_lock);
784 return ret;
786 DEV_STAT_SCSI_PORT_ATTR_RO(role);
788 static ssize_t target_stat_scsi_port_show_attr_busy_count(
789 struct se_port_stat_grps *pgrps, char *page)
791 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
792 struct se_port *sep;
793 ssize_t ret;
795 spin_lock(&lun->lun_sep_lock);
796 sep = lun->lun_sep;
797 if (!sep) {
798 spin_unlock(&lun->lun_sep_lock);
799 return -ENODEV;
801 /* FIXME: scsiPortBusyStatuses */
802 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
803 spin_unlock(&lun->lun_sep_lock);
804 return ret;
806 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
808 CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
810 static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
811 &target_stat_scsi_port_inst.attr,
812 &target_stat_scsi_port_dev.attr,
813 &target_stat_scsi_port_indx.attr,
814 &target_stat_scsi_port_role.attr,
815 &target_stat_scsi_port_busy_count.attr,
816 NULL,
819 static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
820 .show_attribute = target_stat_scsi_port_attr_show,
821 .store_attribute = target_stat_scsi_port_attr_store,
824 static struct config_item_type target_stat_scsi_port_cit = {
825 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
826 .ct_attrs = target_stat_scsi_port_attrs,
827 .ct_owner = THIS_MODULE,
831 * SCSI Target Port Table
833 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
834 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
835 static struct target_stat_scsi_tgt_port_attribute \
836 target_stat_scsi_tgt_port_##_name = \
837 __CONFIGFS_EATTR(_name, _mode, \
838 target_stat_scsi_tgt_port_show_attr_##_name, \
839 target_stat_scsi_tgt_port_store_attr_##_name);
841 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
842 static struct target_stat_scsi_tgt_port_attribute \
843 target_stat_scsi_tgt_port_##_name = \
844 __CONFIGFS_EATTR_RO(_name, \
845 target_stat_scsi_tgt_port_show_attr_##_name);
847 static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
848 struct se_port_stat_grps *pgrps, char *page)
850 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
851 struct se_device *dev = lun->lun_se_dev;
852 struct se_port *sep;
853 struct se_hba *hba;
854 ssize_t ret;
856 spin_lock(&lun->lun_sep_lock);
857 sep = lun->lun_sep;
858 if (!sep) {
859 spin_unlock(&lun->lun_sep_lock);
860 return -ENODEV;
862 hba = dev->se_hba;
863 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
864 spin_unlock(&lun->lun_sep_lock);
865 return ret;
867 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
869 static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
870 struct se_port_stat_grps *pgrps, char *page)
872 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
873 struct se_device *dev = lun->lun_se_dev;
874 struct se_port *sep;
875 ssize_t ret;
877 spin_lock(&lun->lun_sep_lock);
878 sep = lun->lun_sep;
879 if (!sep) {
880 spin_unlock(&lun->lun_sep_lock);
881 return -ENODEV;
883 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
884 spin_unlock(&lun->lun_sep_lock);
885 return ret;
887 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
889 static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
890 struct se_port_stat_grps *pgrps, char *page)
892 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
893 struct se_port *sep;
894 ssize_t ret;
896 spin_lock(&lun->lun_sep_lock);
897 sep = lun->lun_sep;
898 if (!sep) {
899 spin_unlock(&lun->lun_sep_lock);
900 return -ENODEV;
902 ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
903 spin_unlock(&lun->lun_sep_lock);
904 return ret;
906 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
908 static ssize_t target_stat_scsi_tgt_port_show_attr_name(
909 struct se_port_stat_grps *pgrps, char *page)
911 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
912 struct se_port *sep;
913 struct se_portal_group *tpg;
914 ssize_t ret;
916 spin_lock(&lun->lun_sep_lock);
917 sep = lun->lun_sep;
918 if (!sep) {
919 spin_unlock(&lun->lun_sep_lock);
920 return -ENODEV;
922 tpg = sep->sep_tpg;
924 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
925 TPG_TFO(tpg)->get_fabric_name(), sep->sep_index);
926 spin_unlock(&lun->lun_sep_lock);
927 return ret;
929 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
931 static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
932 struct se_port_stat_grps *pgrps, char *page)
934 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
935 struct se_port *sep;
936 struct se_portal_group *tpg;
937 ssize_t ret;
939 spin_lock(&lun->lun_sep_lock);
940 sep = lun->lun_sep;
941 if (!sep) {
942 spin_unlock(&lun->lun_sep_lock);
943 return -ENODEV;
945 tpg = sep->sep_tpg;
947 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
948 TPG_TFO(tpg)->tpg_get_wwn(tpg), "+t+",
949 TPG_TFO(tpg)->tpg_get_tag(tpg));
950 spin_unlock(&lun->lun_sep_lock);
951 return ret;
953 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
955 static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
956 struct se_port_stat_grps *pgrps, char *page)
958 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
959 struct se_port *sep;
960 struct se_portal_group *tpg;
961 ssize_t ret;
963 spin_lock(&lun->lun_sep_lock);
964 sep = lun->lun_sep;
965 if (!sep) {
966 spin_unlock(&lun->lun_sep_lock);
967 return -ENODEV;
969 tpg = sep->sep_tpg;
971 ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
972 spin_unlock(&lun->lun_sep_lock);
973 return ret;
975 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
977 static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
978 struct se_port_stat_grps *pgrps, char *page)
980 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
981 struct se_port *sep;
982 struct se_portal_group *tpg;
983 ssize_t ret;
985 spin_lock(&lun->lun_sep_lock);
986 sep = lun->lun_sep;
987 if (!sep) {
988 spin_unlock(&lun->lun_sep_lock);
989 return -ENODEV;
991 tpg = sep->sep_tpg;
993 ret = snprintf(page, PAGE_SIZE, "%u\n",
994 (u32)(sep->sep_stats.rx_data_octets >> 20));
995 spin_unlock(&lun->lun_sep_lock);
996 return ret;
998 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
1000 static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
1001 struct se_port_stat_grps *pgrps, char *page)
1003 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1004 struct se_port *sep;
1005 struct se_portal_group *tpg;
1006 ssize_t ret;
1008 spin_lock(&lun->lun_sep_lock);
1009 sep = lun->lun_sep;
1010 if (!sep) {
1011 spin_unlock(&lun->lun_sep_lock);
1012 return -ENODEV;
1014 tpg = sep->sep_tpg;
1016 ret = snprintf(page, PAGE_SIZE, "%u\n",
1017 (u32)(sep->sep_stats.tx_data_octets >> 20));
1018 spin_unlock(&lun->lun_sep_lock);
1019 return ret;
1021 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
1023 static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
1024 struct se_port_stat_grps *pgrps, char *page)
1026 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1027 struct se_port *sep;
1028 struct se_portal_group *tpg;
1029 ssize_t ret;
1031 spin_lock(&lun->lun_sep_lock);
1032 sep = lun->lun_sep;
1033 if (!sep) {
1034 spin_unlock(&lun->lun_sep_lock);
1035 return -ENODEV;
1037 tpg = sep->sep_tpg;
1039 /* FIXME: scsiTgtPortHsInCommands */
1040 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1041 spin_unlock(&lun->lun_sep_lock);
1042 return ret;
1044 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
1046 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
1047 scsi_tgt_port_group);
1049 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
1050 &target_stat_scsi_tgt_port_inst.attr,
1051 &target_stat_scsi_tgt_port_dev.attr,
1052 &target_stat_scsi_tgt_port_indx.attr,
1053 &target_stat_scsi_tgt_port_name.attr,
1054 &target_stat_scsi_tgt_port_port_index.attr,
1055 &target_stat_scsi_tgt_port_in_cmds.attr,
1056 &target_stat_scsi_tgt_port_write_mbytes.attr,
1057 &target_stat_scsi_tgt_port_read_mbytes.attr,
1058 &target_stat_scsi_tgt_port_hs_in_cmds.attr,
1059 NULL,
1062 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
1063 .show_attribute = target_stat_scsi_tgt_port_attr_show,
1064 .store_attribute = target_stat_scsi_tgt_port_attr_store,
1067 static struct config_item_type target_stat_scsi_tgt_port_cit = {
1068 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
1069 .ct_attrs = target_stat_scsi_tgt_port_attrs,
1070 .ct_owner = THIS_MODULE,
1074 * SCSI Transport Table
1075 o */
1077 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
1078 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
1079 static struct target_stat_scsi_transport_attribute \
1080 target_stat_scsi_transport_##_name = \
1081 __CONFIGFS_EATTR(_name, _mode, \
1082 target_stat_scsi_transport_show_attr_##_name, \
1083 target_stat_scsi_transport_store_attr_##_name);
1085 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
1086 static struct target_stat_scsi_transport_attribute \
1087 target_stat_scsi_transport_##_name = \
1088 __CONFIGFS_EATTR_RO(_name, \
1089 target_stat_scsi_transport_show_attr_##_name);
1091 static ssize_t target_stat_scsi_transport_show_attr_inst(
1092 struct se_port_stat_grps *pgrps, char *page)
1094 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1095 struct se_device *dev = lun->lun_se_dev;
1096 struct se_port *sep;
1097 struct se_hba *hba;
1098 ssize_t ret;
1100 spin_lock(&lun->lun_sep_lock);
1101 sep = lun->lun_sep;
1102 if (!sep) {
1103 spin_unlock(&lun->lun_sep_lock);
1104 return -ENODEV;
1107 hba = dev->se_hba;
1108 ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
1109 spin_unlock(&lun->lun_sep_lock);
1110 return ret;
1112 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
1114 static ssize_t target_stat_scsi_transport_show_attr_device(
1115 struct se_port_stat_grps *pgrps, char *page)
1117 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1118 struct se_port *sep;
1119 struct se_portal_group *tpg;
1120 ssize_t ret;
1122 spin_lock(&lun->lun_sep_lock);
1123 sep = lun->lun_sep;
1124 if (!sep) {
1125 spin_unlock(&lun->lun_sep_lock);
1126 return -ENODEV;
1128 tpg = sep->sep_tpg;
1129 /* scsiTransportType */
1130 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
1131 TPG_TFO(tpg)->get_fabric_name());
1132 spin_unlock(&lun->lun_sep_lock);
1133 return ret;
1135 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
1137 static ssize_t target_stat_scsi_transport_show_attr_indx(
1138 struct se_port_stat_grps *pgrps, char *page)
1140 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1141 struct se_port *sep;
1142 struct se_portal_group *tpg;
1143 ssize_t ret;
1145 spin_lock(&lun->lun_sep_lock);
1146 sep = lun->lun_sep;
1147 if (!sep) {
1148 spin_unlock(&lun->lun_sep_lock);
1149 return -ENODEV;
1151 tpg = sep->sep_tpg;
1152 ret = snprintf(page, PAGE_SIZE, "%u\n",
1153 TPG_TFO(tpg)->tpg_get_inst_index(tpg));
1154 spin_unlock(&lun->lun_sep_lock);
1155 return ret;
1157 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
1159 static ssize_t target_stat_scsi_transport_show_attr_dev_name(
1160 struct se_port_stat_grps *pgrps, char *page)
1162 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1163 struct se_device *dev = lun->lun_se_dev;
1164 struct se_port *sep;
1165 struct se_portal_group *tpg;
1166 struct t10_wwn *wwn;
1167 ssize_t ret;
1169 spin_lock(&lun->lun_sep_lock);
1170 sep = lun->lun_sep;
1171 if (!sep) {
1172 spin_unlock(&lun->lun_sep_lock);
1173 return -ENODEV;
1175 tpg = sep->sep_tpg;
1176 wwn = DEV_T10_WWN(dev);
1177 /* scsiTransportDevName */
1178 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1179 TPG_TFO(tpg)->tpg_get_wwn(tpg),
1180 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
1181 wwn->vendor);
1182 spin_unlock(&lun->lun_sep_lock);
1183 return ret;
1185 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1187 CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1188 scsi_transport_group);
1190 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1191 &target_stat_scsi_transport_inst.attr,
1192 &target_stat_scsi_transport_device.attr,
1193 &target_stat_scsi_transport_indx.attr,
1194 &target_stat_scsi_transport_dev_name.attr,
1195 NULL,
1198 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1199 .show_attribute = target_stat_scsi_transport_attr_show,
1200 .store_attribute = target_stat_scsi_transport_attr_store,
1203 static struct config_item_type target_stat_scsi_transport_cit = {
1204 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
1205 .ct_attrs = target_stat_scsi_transport_attrs,
1206 .ct_owner = THIS_MODULE,
1210 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1211 * the target port statistics groups + configfs CITs located in target_core_stat.c
1213 void target_stat_setup_port_default_groups(struct se_lun *lun)
1215 struct config_group *port_stat_grp = &PORT_STAT_GRP(lun)->stat_group;
1217 config_group_init_type_name(&PORT_STAT_GRP(lun)->scsi_port_group,
1218 "scsi_port", &target_stat_scsi_port_cit);
1219 config_group_init_type_name(&PORT_STAT_GRP(lun)->scsi_tgt_port_group,
1220 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
1221 config_group_init_type_name(&PORT_STAT_GRP(lun)->scsi_transport_group,
1222 "scsi_transport", &target_stat_scsi_transport_cit);
1224 port_stat_grp->default_groups[0] = &PORT_STAT_GRP(lun)->scsi_port_group;
1225 port_stat_grp->default_groups[1] = &PORT_STAT_GRP(lun)->scsi_tgt_port_group;
1226 port_stat_grp->default_groups[2] = &PORT_STAT_GRP(lun)->scsi_transport_group;
1227 port_stat_grp->default_groups[3] = NULL;
1231 * SCSI Authorized Initiator Table
1234 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1235 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1236 static struct target_stat_scsi_auth_intr_attribute \
1237 target_stat_scsi_auth_intr_##_name = \
1238 __CONFIGFS_EATTR(_name, _mode, \
1239 target_stat_scsi_auth_intr_show_attr_##_name, \
1240 target_stat_scsi_auth_intr_store_attr_##_name);
1242 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1243 static struct target_stat_scsi_auth_intr_attribute \
1244 target_stat_scsi_auth_intr_##_name = \
1245 __CONFIGFS_EATTR_RO(_name, \
1246 target_stat_scsi_auth_intr_show_attr_##_name);
1248 static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1249 struct se_ml_stat_grps *lgrps, char *page)
1251 struct se_lun_acl *lacl = container_of(lgrps,
1252 struct se_lun_acl, ml_stat_grps);
1253 struct se_node_acl *nacl = lacl->se_lun_nacl;
1254 struct se_dev_entry *deve;
1255 struct se_portal_group *tpg;
1256 ssize_t ret;
1258 spin_lock_irq(&nacl->device_list_lock);
1259 deve = &nacl->device_list[lacl->mapped_lun];
1260 if (!deve->se_lun || !deve->se_lun_acl) {
1261 spin_unlock_irq(&nacl->device_list_lock);
1262 return -ENODEV;
1264 tpg = nacl->se_tpg;
1265 /* scsiInstIndex */
1266 ret = snprintf(page, PAGE_SIZE, "%u\n",
1267 TPG_TFO(tpg)->tpg_get_inst_index(tpg));
1268 spin_unlock_irq(&nacl->device_list_lock);
1269 return ret;
1271 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1273 static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1274 struct se_ml_stat_grps *lgrps, char *page)
1276 struct se_lun_acl *lacl = container_of(lgrps,
1277 struct se_lun_acl, ml_stat_grps);
1278 struct se_node_acl *nacl = lacl->se_lun_nacl;
1279 struct se_dev_entry *deve;
1280 struct se_lun *lun;
1281 struct se_portal_group *tpg;
1282 ssize_t ret;
1284 spin_lock_irq(&nacl->device_list_lock);
1285 deve = &nacl->device_list[lacl->mapped_lun];
1286 if (!deve->se_lun || !deve->se_lun_acl) {
1287 spin_unlock_irq(&nacl->device_list_lock);
1288 return -ENODEV;
1290 tpg = nacl->se_tpg;
1291 lun = deve->se_lun;
1292 /* scsiDeviceIndex */
1293 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1294 spin_unlock_irq(&nacl->device_list_lock);
1295 return ret;
1297 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1299 static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1300 struct se_ml_stat_grps *lgrps, char *page)
1302 struct se_lun_acl *lacl = container_of(lgrps,
1303 struct se_lun_acl, ml_stat_grps);
1304 struct se_node_acl *nacl = lacl->se_lun_nacl;
1305 struct se_dev_entry *deve;
1306 struct se_portal_group *tpg;
1307 ssize_t ret;
1309 spin_lock_irq(&nacl->device_list_lock);
1310 deve = &nacl->device_list[lacl->mapped_lun];
1311 if (!deve->se_lun || !deve->se_lun_acl) {
1312 spin_unlock_irq(&nacl->device_list_lock);
1313 return -ENODEV;
1315 tpg = nacl->se_tpg;
1316 /* scsiAuthIntrTgtPortIndex */
1317 ret = snprintf(page, PAGE_SIZE, "%u\n", TPG_TFO(tpg)->tpg_get_tag(tpg));
1318 spin_unlock_irq(&nacl->device_list_lock);
1319 return ret;
1321 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1323 static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1324 struct se_ml_stat_grps *lgrps, char *page)
1326 struct se_lun_acl *lacl = container_of(lgrps,
1327 struct se_lun_acl, ml_stat_grps);
1328 struct se_node_acl *nacl = lacl->se_lun_nacl;
1329 struct se_dev_entry *deve;
1330 ssize_t ret;
1332 spin_lock_irq(&nacl->device_list_lock);
1333 deve = &nacl->device_list[lacl->mapped_lun];
1334 if (!deve->se_lun || !deve->se_lun_acl) {
1335 spin_unlock_irq(&nacl->device_list_lock);
1336 return -ENODEV;
1338 /* scsiAuthIntrIndex */
1339 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1340 spin_unlock_irq(&nacl->device_list_lock);
1341 return ret;
1343 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1345 static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1346 struct se_ml_stat_grps *lgrps, char *page)
1348 struct se_lun_acl *lacl = container_of(lgrps,
1349 struct se_lun_acl, ml_stat_grps);
1350 struct se_node_acl *nacl = lacl->se_lun_nacl;
1351 struct se_dev_entry *deve;
1352 ssize_t ret;
1354 spin_lock_irq(&nacl->device_list_lock);
1355 deve = &nacl->device_list[lacl->mapped_lun];
1356 if (!deve->se_lun || !deve->se_lun_acl) {
1357 spin_unlock_irq(&nacl->device_list_lock);
1358 return -ENODEV;
1360 /* scsiAuthIntrDevOrPort */
1361 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1362 spin_unlock_irq(&nacl->device_list_lock);
1363 return ret;
1365 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1367 static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1368 struct se_ml_stat_grps *lgrps, char *page)
1370 struct se_lun_acl *lacl = container_of(lgrps,
1371 struct se_lun_acl, ml_stat_grps);
1372 struct se_node_acl *nacl = lacl->se_lun_nacl;
1373 struct se_dev_entry *deve;
1374 ssize_t ret;
1376 spin_lock_irq(&nacl->device_list_lock);
1377 deve = &nacl->device_list[lacl->mapped_lun];
1378 if (!deve->se_lun || !deve->se_lun_acl) {
1379 spin_unlock_irq(&nacl->device_list_lock);
1380 return -ENODEV;
1382 /* scsiAuthIntrName */
1383 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1384 spin_unlock_irq(&nacl->device_list_lock);
1385 return ret;
1387 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1389 static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1390 struct se_ml_stat_grps *lgrps, char *page)
1392 struct se_lun_acl *lacl = container_of(lgrps,
1393 struct se_lun_acl, ml_stat_grps);
1394 struct se_node_acl *nacl = lacl->se_lun_nacl;
1395 struct se_dev_entry *deve;
1396 ssize_t ret;
1398 spin_lock_irq(&nacl->device_list_lock);
1399 deve = &nacl->device_list[lacl->mapped_lun];
1400 if (!deve->se_lun || !deve->se_lun_acl) {
1401 spin_unlock_irq(&nacl->device_list_lock);
1402 return -ENODEV;
1404 /* FIXME: scsiAuthIntrLunMapIndex */
1405 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1406 spin_unlock_irq(&nacl->device_list_lock);
1407 return ret;
1409 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1411 static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1412 struct se_ml_stat_grps *lgrps, char *page)
1414 struct se_lun_acl *lacl = container_of(lgrps,
1415 struct se_lun_acl, ml_stat_grps);
1416 struct se_node_acl *nacl = lacl->se_lun_nacl;
1417 struct se_dev_entry *deve;
1418 ssize_t ret;
1420 spin_lock_irq(&nacl->device_list_lock);
1421 deve = &nacl->device_list[lacl->mapped_lun];
1422 if (!deve->se_lun || !deve->se_lun_acl) {
1423 spin_unlock_irq(&nacl->device_list_lock);
1424 return -ENODEV;
1426 /* scsiAuthIntrAttachedTimes */
1427 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1428 spin_unlock_irq(&nacl->device_list_lock);
1429 return ret;
1431 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1433 static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1434 struct se_ml_stat_grps *lgrps, char *page)
1436 struct se_lun_acl *lacl = container_of(lgrps,
1437 struct se_lun_acl, ml_stat_grps);
1438 struct se_node_acl *nacl = lacl->se_lun_nacl;
1439 struct se_dev_entry *deve;
1440 ssize_t ret;
1442 spin_lock_irq(&nacl->device_list_lock);
1443 deve = &nacl->device_list[lacl->mapped_lun];
1444 if (!deve->se_lun || !deve->se_lun_acl) {
1445 spin_unlock_irq(&nacl->device_list_lock);
1446 return -ENODEV;
1448 /* scsiAuthIntrOutCommands */
1449 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1450 spin_unlock_irq(&nacl->device_list_lock);
1451 return ret;
1453 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1455 static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1456 struct se_ml_stat_grps *lgrps, char *page)
1458 struct se_lun_acl *lacl = container_of(lgrps,
1459 struct se_lun_acl, ml_stat_grps);
1460 struct se_node_acl *nacl = lacl->se_lun_nacl;
1461 struct se_dev_entry *deve;
1462 ssize_t ret;
1464 spin_lock_irq(&nacl->device_list_lock);
1465 deve = &nacl->device_list[lacl->mapped_lun];
1466 if (!deve->se_lun || !deve->se_lun_acl) {
1467 spin_unlock_irq(&nacl->device_list_lock);
1468 return -ENODEV;
1470 /* scsiAuthIntrReadMegaBytes */
1471 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1472 spin_unlock_irq(&nacl->device_list_lock);
1473 return ret;
1475 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1477 static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1478 struct se_ml_stat_grps *lgrps, char *page)
1480 struct se_lun_acl *lacl = container_of(lgrps,
1481 struct se_lun_acl, ml_stat_grps);
1482 struct se_node_acl *nacl = lacl->se_lun_nacl;
1483 struct se_dev_entry *deve;
1484 ssize_t ret;
1486 spin_lock_irq(&nacl->device_list_lock);
1487 deve = &nacl->device_list[lacl->mapped_lun];
1488 if (!deve->se_lun || !deve->se_lun_acl) {
1489 spin_unlock_irq(&nacl->device_list_lock);
1490 return -ENODEV;
1492 /* scsiAuthIntrWrittenMegaBytes */
1493 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1494 spin_unlock_irq(&nacl->device_list_lock);
1495 return ret;
1497 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1499 static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1500 struct se_ml_stat_grps *lgrps, char *page)
1502 struct se_lun_acl *lacl = container_of(lgrps,
1503 struct se_lun_acl, ml_stat_grps);
1504 struct se_node_acl *nacl = lacl->se_lun_nacl;
1505 struct se_dev_entry *deve;
1506 ssize_t ret;
1508 spin_lock_irq(&nacl->device_list_lock);
1509 deve = &nacl->device_list[lacl->mapped_lun];
1510 if (!deve->se_lun || !deve->se_lun_acl) {
1511 spin_unlock_irq(&nacl->device_list_lock);
1512 return -ENODEV;
1514 /* FIXME: scsiAuthIntrHSOutCommands */
1515 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1516 spin_unlock_irq(&nacl->device_list_lock);
1517 return ret;
1519 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1521 static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1522 struct se_ml_stat_grps *lgrps, char *page)
1524 struct se_lun_acl *lacl = container_of(lgrps,
1525 struct se_lun_acl, ml_stat_grps);
1526 struct se_node_acl *nacl = lacl->se_lun_nacl;
1527 struct se_dev_entry *deve;
1528 ssize_t ret;
1530 spin_lock_irq(&nacl->device_list_lock);
1531 deve = &nacl->device_list[lacl->mapped_lun];
1532 if (!deve->se_lun || !deve->se_lun_acl) {
1533 spin_unlock_irq(&nacl->device_list_lock);
1534 return -ENODEV;
1536 /* scsiAuthIntrLastCreation */
1537 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1538 INITIAL_JIFFIES) * 100 / HZ));
1539 spin_unlock_irq(&nacl->device_list_lock);
1540 return ret;
1542 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1544 static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1545 struct se_ml_stat_grps *lgrps, char *page)
1547 struct se_lun_acl *lacl = container_of(lgrps,
1548 struct se_lun_acl, ml_stat_grps);
1549 struct se_node_acl *nacl = lacl->se_lun_nacl;
1550 struct se_dev_entry *deve;
1551 ssize_t ret;
1553 spin_lock_irq(&nacl->device_list_lock);
1554 deve = &nacl->device_list[lacl->mapped_lun];
1555 if (!deve->se_lun || !deve->se_lun_acl) {
1556 spin_unlock_irq(&nacl->device_list_lock);
1557 return -ENODEV;
1559 /* FIXME: scsiAuthIntrRowStatus */
1560 ret = snprintf(page, PAGE_SIZE, "Ready\n");
1561 spin_unlock_irq(&nacl->device_list_lock);
1562 return ret;
1564 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1566 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1567 scsi_auth_intr_group);
1569 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1570 &target_stat_scsi_auth_intr_inst.attr,
1571 &target_stat_scsi_auth_intr_dev.attr,
1572 &target_stat_scsi_auth_intr_port.attr,
1573 &target_stat_scsi_auth_intr_indx.attr,
1574 &target_stat_scsi_auth_intr_dev_or_port.attr,
1575 &target_stat_scsi_auth_intr_intr_name.attr,
1576 &target_stat_scsi_auth_intr_map_indx.attr,
1577 &target_stat_scsi_auth_intr_att_count.attr,
1578 &target_stat_scsi_auth_intr_num_cmds.attr,
1579 &target_stat_scsi_auth_intr_read_mbytes.attr,
1580 &target_stat_scsi_auth_intr_write_mbytes.attr,
1581 &target_stat_scsi_auth_intr_hs_num_cmds.attr,
1582 &target_stat_scsi_auth_intr_creation_time.attr,
1583 &target_stat_scsi_auth_intr_row_status.attr,
1584 NULL,
1587 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1588 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1589 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1592 static struct config_item_type target_stat_scsi_auth_intr_cit = {
1593 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1594 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1595 .ct_owner = THIS_MODULE,
1599 * SCSI Attached Initiator Port Table
1602 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1603 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1604 static struct target_stat_scsi_att_intr_port_attribute \
1605 target_stat_scsi_att_intr_port_##_name = \
1606 __CONFIGFS_EATTR(_name, _mode, \
1607 target_stat_scsi_att_intr_port_show_attr_##_name, \
1608 target_stat_scsi_att_intr_port_store_attr_##_name);
1610 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1611 static struct target_stat_scsi_att_intr_port_attribute \
1612 target_stat_scsi_att_intr_port_##_name = \
1613 __CONFIGFS_EATTR_RO(_name, \
1614 target_stat_scsi_att_intr_port_show_attr_##_name);
1616 static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1617 struct se_ml_stat_grps *lgrps, char *page)
1619 struct se_lun_acl *lacl = container_of(lgrps,
1620 struct se_lun_acl, ml_stat_grps);
1621 struct se_node_acl *nacl = lacl->se_lun_nacl;
1622 struct se_dev_entry *deve;
1623 struct se_portal_group *tpg;
1624 ssize_t ret;
1626 spin_lock_irq(&nacl->device_list_lock);
1627 deve = &nacl->device_list[lacl->mapped_lun];
1628 if (!deve->se_lun || !deve->se_lun_acl) {
1629 spin_unlock_irq(&nacl->device_list_lock);
1630 return -ENODEV;
1632 tpg = nacl->se_tpg;
1633 /* scsiInstIndex */
1634 ret = snprintf(page, PAGE_SIZE, "%u\n",
1635 TPG_TFO(tpg)->tpg_get_inst_index(tpg));
1636 spin_unlock_irq(&nacl->device_list_lock);
1637 return ret;
1639 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1641 static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1642 struct se_ml_stat_grps *lgrps, char *page)
1644 struct se_lun_acl *lacl = container_of(lgrps,
1645 struct se_lun_acl, ml_stat_grps);
1646 struct se_node_acl *nacl = lacl->se_lun_nacl;
1647 struct se_dev_entry *deve;
1648 struct se_lun *lun;
1649 struct se_portal_group *tpg;
1650 ssize_t ret;
1652 spin_lock_irq(&nacl->device_list_lock);
1653 deve = &nacl->device_list[lacl->mapped_lun];
1654 if (!deve->se_lun || !deve->se_lun_acl) {
1655 spin_unlock_irq(&nacl->device_list_lock);
1656 return -ENODEV;
1658 tpg = nacl->se_tpg;
1659 lun = deve->se_lun;
1660 /* scsiDeviceIndex */
1661 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1662 spin_unlock_irq(&nacl->device_list_lock);
1663 return ret;
1665 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1667 static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1668 struct se_ml_stat_grps *lgrps, char *page)
1670 struct se_lun_acl *lacl = container_of(lgrps,
1671 struct se_lun_acl, ml_stat_grps);
1672 struct se_node_acl *nacl = lacl->se_lun_nacl;
1673 struct se_dev_entry *deve;
1674 struct se_portal_group *tpg;
1675 ssize_t ret;
1677 spin_lock_irq(&nacl->device_list_lock);
1678 deve = &nacl->device_list[lacl->mapped_lun];
1679 if (!deve->se_lun || !deve->se_lun_acl) {
1680 spin_unlock_irq(&nacl->device_list_lock);
1681 return -ENODEV;
1683 tpg = nacl->se_tpg;
1684 /* scsiPortIndex */
1685 ret = snprintf(page, PAGE_SIZE, "%u\n", TPG_TFO(tpg)->tpg_get_tag(tpg));
1686 spin_unlock_irq(&nacl->device_list_lock);
1687 return ret;
1689 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1691 static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1692 struct se_ml_stat_grps *lgrps, char *page)
1694 struct se_lun_acl *lacl = container_of(lgrps,
1695 struct se_lun_acl, ml_stat_grps);
1696 struct se_node_acl *nacl = lacl->se_lun_nacl;
1697 struct se_session *se_sess;
1698 struct se_portal_group *tpg;
1699 ssize_t ret;
1701 spin_lock_irq(&nacl->nacl_sess_lock);
1702 se_sess = nacl->nacl_sess;
1703 if (!se_sess) {
1704 spin_unlock_irq(&nacl->nacl_sess_lock);
1705 return -ENODEV;
1708 tpg = nacl->se_tpg;
1709 /* scsiAttIntrPortIndex */
1710 ret = snprintf(page, PAGE_SIZE, "%u\n",
1711 TPG_TFO(tpg)->sess_get_index(se_sess));
1712 spin_unlock_irq(&nacl->nacl_sess_lock);
1713 return ret;
1715 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1717 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1718 struct se_ml_stat_grps *lgrps, char *page)
1720 struct se_lun_acl *lacl = container_of(lgrps,
1721 struct se_lun_acl, ml_stat_grps);
1722 struct se_node_acl *nacl = lacl->se_lun_nacl;
1723 struct se_dev_entry *deve;
1724 ssize_t ret;
1726 spin_lock_irq(&nacl->device_list_lock);
1727 deve = &nacl->device_list[lacl->mapped_lun];
1728 if (!deve->se_lun || !deve->se_lun_acl) {
1729 spin_unlock_irq(&nacl->device_list_lock);
1730 return -ENODEV;
1732 /* scsiAttIntrPortAuthIntrIdx */
1733 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1734 spin_unlock_irq(&nacl->device_list_lock);
1735 return ret;
1737 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1739 static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1740 struct se_ml_stat_grps *lgrps, char *page)
1742 struct se_lun_acl *lacl = container_of(lgrps,
1743 struct se_lun_acl, ml_stat_grps);
1744 struct se_node_acl *nacl = lacl->se_lun_nacl;
1745 struct se_session *se_sess;
1746 struct se_portal_group *tpg;
1747 ssize_t ret;
1748 unsigned char buf[64];
1750 spin_lock_irq(&nacl->nacl_sess_lock);
1751 se_sess = nacl->nacl_sess;
1752 if (!se_sess) {
1753 spin_unlock_irq(&nacl->nacl_sess_lock);
1754 return -ENODEV;
1757 tpg = nacl->se_tpg;
1758 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1759 memset(buf, 0, 64);
1760 if (TPG_TFO(tpg)->sess_get_initiator_sid != NULL)
1761 TPG_TFO(tpg)->sess_get_initiator_sid(se_sess,
1762 (unsigned char *)&buf[0], 64);
1764 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1765 spin_unlock_irq(&nacl->nacl_sess_lock);
1766 return ret;
1768 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1770 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1771 scsi_att_intr_port_group);
1773 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1774 &target_stat_scsi_att_intr_port_inst.attr,
1775 &target_stat_scsi_att_intr_port_dev.attr,
1776 &target_stat_scsi_att_intr_port_port.attr,
1777 &target_stat_scsi_att_intr_port_indx.attr,
1778 &target_stat_scsi_att_intr_port_port_auth_indx.attr,
1779 &target_stat_scsi_att_intr_port_port_ident.attr,
1780 NULL,
1783 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1784 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1785 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1788 static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1789 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1790 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1791 .ct_owner = THIS_MODULE,
1795 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1796 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1798 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1800 struct config_group *ml_stat_grp = &ML_STAT_GRPS(lacl)->stat_group;
1802 config_group_init_type_name(&ML_STAT_GRPS(lacl)->scsi_auth_intr_group,
1803 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1804 config_group_init_type_name(&ML_STAT_GRPS(lacl)->scsi_att_intr_port_group,
1805 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1807 ml_stat_grp->default_groups[0] = &ML_STAT_GRPS(lacl)->scsi_auth_intr_group;
1808 ml_stat_grp->default_groups[1] = &ML_STAT_GRPS(lacl)->scsi_att_intr_port_group;
1809 ml_stat_grp->default_groups[2] = NULL;