1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
3 * Filename: target_core_stat.c
5 * Modern ConfigFS group context specific statistics based on original
6 * target_core_mib.c code
8 * (c) Copyright 2006-2013 Datera, Inc.
10 * Nicholas A. Bellinger <nab@linux-iscsi.org>
12 ******************************************************************************/
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/delay.h>
17 #include <linux/timer.h>
18 #include <linux/string.h>
19 #include <linux/utsname.h>
20 #include <linux/proc_fs.h>
21 #include <linux/seq_file.h>
22 #include <linux/configfs.h>
24 #include <target/target_core_base.h>
25 #include <target/target_core_backend.h>
26 #include <target/target_core_fabric.h>
28 #include "target_core_internal.h"
30 #ifndef INITIAL_JIFFIES
31 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
34 #define SCSI_LU_INDEX 1
41 static struct se_device
*to_stat_dev(struct config_item
*item
)
43 struct se_dev_stat_grps
*sgrps
= container_of(to_config_group(item
),
44 struct se_dev_stat_grps
, scsi_dev_group
);
45 return container_of(sgrps
, struct se_device
, dev_stat_grps
);
48 static ssize_t
target_stat_inst_show(struct config_item
*item
, char *page
)
50 struct se_hba
*hba
= to_stat_dev(item
)->se_hba
;
52 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
55 static ssize_t
target_stat_indx_show(struct config_item
*item
, char *page
)
57 return snprintf(page
, PAGE_SIZE
, "%u\n", to_stat_dev(item
)->dev_index
);
60 static ssize_t
target_stat_role_show(struct config_item
*item
, char *page
)
62 return snprintf(page
, PAGE_SIZE
, "Target\n");
65 static ssize_t
target_stat_ports_show(struct config_item
*item
, char *page
)
67 return snprintf(page
, PAGE_SIZE
, "%u\n", to_stat_dev(item
)->export_count
);
70 CONFIGFS_ATTR_RO(target_stat_
, inst
);
71 CONFIGFS_ATTR_RO(target_stat_
, indx
);
72 CONFIGFS_ATTR_RO(target_stat_
, role
);
73 CONFIGFS_ATTR_RO(target_stat_
, ports
);
75 static struct configfs_attribute
*target_stat_scsi_dev_attrs
[] = {
76 &target_stat_attr_inst
,
77 &target_stat_attr_indx
,
78 &target_stat_attr_role
,
79 &target_stat_attr_ports
,
83 static const struct config_item_type target_stat_scsi_dev_cit
= {
84 .ct_attrs
= target_stat_scsi_dev_attrs
,
85 .ct_owner
= THIS_MODULE
,
89 * SCSI Target Device Table
91 static struct se_device
*to_stat_tgt_dev(struct config_item
*item
)
93 struct se_dev_stat_grps
*sgrps
= container_of(to_config_group(item
),
94 struct se_dev_stat_grps
, scsi_tgt_dev_group
);
95 return container_of(sgrps
, struct se_device
, dev_stat_grps
);
98 static ssize_t
target_stat_tgt_inst_show(struct config_item
*item
, char *page
)
100 struct se_hba
*hba
= to_stat_tgt_dev(item
)->se_hba
;
102 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
105 static ssize_t
target_stat_tgt_indx_show(struct config_item
*item
, char *page
)
107 return snprintf(page
, PAGE_SIZE
, "%u\n", to_stat_tgt_dev(item
)->dev_index
);
110 static ssize_t
target_stat_tgt_num_lus_show(struct config_item
*item
,
113 return snprintf(page
, PAGE_SIZE
, "%u\n", LU_COUNT
);
116 static ssize_t
target_stat_tgt_status_show(struct config_item
*item
,
119 if (to_stat_tgt_dev(item
)->export_count
)
120 return snprintf(page
, PAGE_SIZE
, "activated");
122 return snprintf(page
, PAGE_SIZE
, "deactivated");
125 static ssize_t
target_stat_tgt_non_access_lus_show(struct config_item
*item
,
128 int non_accessible_lus
;
130 if (to_stat_tgt_dev(item
)->export_count
)
131 non_accessible_lus
= 0;
133 non_accessible_lus
= 1;
135 return snprintf(page
, PAGE_SIZE
, "%u\n", non_accessible_lus
);
138 static ssize_t
target_stat_tgt_resets_show(struct config_item
*item
,
141 return snprintf(page
, PAGE_SIZE
, "%lu\n",
142 atomic_long_read(&to_stat_tgt_dev(item
)->num_resets
));
145 static ssize_t
target_stat_tgt_aborts_complete_show(struct config_item
*item
,
148 return snprintf(page
, PAGE_SIZE
, "%lu\n",
149 atomic_long_read(&to_stat_tgt_dev(item
)->aborts_complete
));
152 static ssize_t
target_stat_tgt_aborts_no_task_show(struct config_item
*item
,
155 return snprintf(page
, PAGE_SIZE
, "%lu\n",
156 atomic_long_read(&to_stat_tgt_dev(item
)->aborts_no_task
));
159 CONFIGFS_ATTR_RO(target_stat_tgt_
, inst
);
160 CONFIGFS_ATTR_RO(target_stat_tgt_
, indx
);
161 CONFIGFS_ATTR_RO(target_stat_tgt_
, num_lus
);
162 CONFIGFS_ATTR_RO(target_stat_tgt_
, status
);
163 CONFIGFS_ATTR_RO(target_stat_tgt_
, non_access_lus
);
164 CONFIGFS_ATTR_RO(target_stat_tgt_
, resets
);
165 CONFIGFS_ATTR_RO(target_stat_tgt_
, aborts_complete
);
166 CONFIGFS_ATTR_RO(target_stat_tgt_
, aborts_no_task
);
168 static struct configfs_attribute
*target_stat_scsi_tgt_dev_attrs
[] = {
169 &target_stat_tgt_attr_inst
,
170 &target_stat_tgt_attr_indx
,
171 &target_stat_tgt_attr_num_lus
,
172 &target_stat_tgt_attr_status
,
173 &target_stat_tgt_attr_non_access_lus
,
174 &target_stat_tgt_attr_resets
,
175 &target_stat_tgt_attr_aborts_complete
,
176 &target_stat_tgt_attr_aborts_no_task
,
180 static const struct config_item_type target_stat_scsi_tgt_dev_cit
= {
181 .ct_attrs
= target_stat_scsi_tgt_dev_attrs
,
182 .ct_owner
= THIS_MODULE
,
186 * SCSI Logical Unit Table
189 static struct se_device
*to_stat_lu_dev(struct config_item
*item
)
191 struct se_dev_stat_grps
*sgrps
= container_of(to_config_group(item
),
192 struct se_dev_stat_grps
, scsi_lu_group
);
193 return container_of(sgrps
, struct se_device
, dev_stat_grps
);
196 static ssize_t
target_stat_lu_inst_show(struct config_item
*item
, char *page
)
198 struct se_hba
*hba
= to_stat_lu_dev(item
)->se_hba
;
200 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
203 static ssize_t
target_stat_lu_dev_show(struct config_item
*item
, char *page
)
205 return snprintf(page
, PAGE_SIZE
, "%u\n",
206 to_stat_lu_dev(item
)->dev_index
);
209 static ssize_t
target_stat_lu_indx_show(struct config_item
*item
, char *page
)
211 return snprintf(page
, PAGE_SIZE
, "%u\n", SCSI_LU_INDEX
);
214 static ssize_t
target_stat_lu_lun_show(struct config_item
*item
, char *page
)
216 /* FIXME: scsiLuDefaultLun */
217 return snprintf(page
, PAGE_SIZE
, "%llu\n", (unsigned long long)0);
220 static ssize_t
target_stat_lu_lu_name_show(struct config_item
*item
, char *page
)
222 struct se_device
*dev
= to_stat_lu_dev(item
);
225 return snprintf(page
, PAGE_SIZE
, "%s\n",
226 (strlen(dev
->t10_wwn
.unit_serial
)) ?
227 dev
->t10_wwn
.unit_serial
: "None");
230 static ssize_t
target_stat_lu_vend_show(struct config_item
*item
, char *page
)
232 struct se_device
*dev
= to_stat_lu_dev(item
);
234 return snprintf(page
, PAGE_SIZE
, "%-" __stringify(INQUIRY_VENDOR_LEN
)
235 "s\n", dev
->t10_wwn
.vendor
);
238 static ssize_t
target_stat_lu_prod_show(struct config_item
*item
, char *page
)
240 struct se_device
*dev
= to_stat_lu_dev(item
);
242 return snprintf(page
, PAGE_SIZE
, "%-" __stringify(INQUIRY_MODEL_LEN
)
243 "s\n", dev
->t10_wwn
.model
);
246 static ssize_t
target_stat_lu_rev_show(struct config_item
*item
, char *page
)
248 struct se_device
*dev
= to_stat_lu_dev(item
);
250 return snprintf(page
, PAGE_SIZE
, "%-" __stringify(INQUIRY_REVISION_LEN
)
251 "s\n", dev
->t10_wwn
.revision
);
254 static ssize_t
target_stat_lu_dev_type_show(struct config_item
*item
, char *page
)
256 struct se_device
*dev
= to_stat_lu_dev(item
);
258 /* scsiLuPeripheralType */
259 return snprintf(page
, PAGE_SIZE
, "%u\n",
260 dev
->transport
->get_device_type(dev
));
263 static ssize_t
target_stat_lu_status_show(struct config_item
*item
, char *page
)
265 struct se_device
*dev
= to_stat_lu_dev(item
);
268 return snprintf(page
, PAGE_SIZE
, "%s\n",
269 (dev
->export_count
) ? "available" : "notavailable");
272 static ssize_t
target_stat_lu_state_bit_show(struct config_item
*item
,
276 return snprintf(page
, PAGE_SIZE
, "exposed\n");
279 static ssize_t
target_stat_lu_num_cmds_show(struct config_item
*item
,
282 struct se_device
*dev
= to_stat_lu_dev(item
);
284 /* scsiLuNumCommands */
285 return snprintf(page
, PAGE_SIZE
, "%lu\n",
286 atomic_long_read(&dev
->num_cmds
));
289 static ssize_t
target_stat_lu_read_mbytes_show(struct config_item
*item
,
292 struct se_device
*dev
= to_stat_lu_dev(item
);
294 /* scsiLuReadMegaBytes */
295 return snprintf(page
, PAGE_SIZE
, "%lu\n",
296 atomic_long_read(&dev
->read_bytes
) >> 20);
299 static ssize_t
target_stat_lu_write_mbytes_show(struct config_item
*item
,
302 struct se_device
*dev
= to_stat_lu_dev(item
);
304 /* scsiLuWrittenMegaBytes */
305 return snprintf(page
, PAGE_SIZE
, "%lu\n",
306 atomic_long_read(&dev
->write_bytes
) >> 20);
309 static ssize_t
target_stat_lu_resets_show(struct config_item
*item
, char *page
)
311 struct se_device
*dev
= to_stat_lu_dev(item
);
314 return snprintf(page
, PAGE_SIZE
, "%lu\n",
315 atomic_long_read(&dev
->num_resets
));
318 static ssize_t
target_stat_lu_full_stat_show(struct config_item
*item
,
321 /* FIXME: scsiLuOutTaskSetFullStatus */
322 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
325 static ssize_t
target_stat_lu_hs_num_cmds_show(struct config_item
*item
,
328 /* FIXME: scsiLuHSInCommands */
329 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
332 static ssize_t
target_stat_lu_creation_time_show(struct config_item
*item
,
335 struct se_device
*dev
= to_stat_lu_dev(item
);
337 /* scsiLuCreationTime */
338 return snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)dev
->creation_time
-
339 INITIAL_JIFFIES
) * 100 / HZ
));
342 CONFIGFS_ATTR_RO(target_stat_lu_
, inst
);
343 CONFIGFS_ATTR_RO(target_stat_lu_
, dev
);
344 CONFIGFS_ATTR_RO(target_stat_lu_
, indx
);
345 CONFIGFS_ATTR_RO(target_stat_lu_
, lun
);
346 CONFIGFS_ATTR_RO(target_stat_lu_
, lu_name
);
347 CONFIGFS_ATTR_RO(target_stat_lu_
, vend
);
348 CONFIGFS_ATTR_RO(target_stat_lu_
, prod
);
349 CONFIGFS_ATTR_RO(target_stat_lu_
, rev
);
350 CONFIGFS_ATTR_RO(target_stat_lu_
, dev_type
);
351 CONFIGFS_ATTR_RO(target_stat_lu_
, status
);
352 CONFIGFS_ATTR_RO(target_stat_lu_
, state_bit
);
353 CONFIGFS_ATTR_RO(target_stat_lu_
, num_cmds
);
354 CONFIGFS_ATTR_RO(target_stat_lu_
, read_mbytes
);
355 CONFIGFS_ATTR_RO(target_stat_lu_
, write_mbytes
);
356 CONFIGFS_ATTR_RO(target_stat_lu_
, resets
);
357 CONFIGFS_ATTR_RO(target_stat_lu_
, full_stat
);
358 CONFIGFS_ATTR_RO(target_stat_lu_
, hs_num_cmds
);
359 CONFIGFS_ATTR_RO(target_stat_lu_
, creation_time
);
361 static struct configfs_attribute
*target_stat_scsi_lu_attrs
[] = {
362 &target_stat_lu_attr_inst
,
363 &target_stat_lu_attr_dev
,
364 &target_stat_lu_attr_indx
,
365 &target_stat_lu_attr_lun
,
366 &target_stat_lu_attr_lu_name
,
367 &target_stat_lu_attr_vend
,
368 &target_stat_lu_attr_prod
,
369 &target_stat_lu_attr_rev
,
370 &target_stat_lu_attr_dev_type
,
371 &target_stat_lu_attr_status
,
372 &target_stat_lu_attr_state_bit
,
373 &target_stat_lu_attr_num_cmds
,
374 &target_stat_lu_attr_read_mbytes
,
375 &target_stat_lu_attr_write_mbytes
,
376 &target_stat_lu_attr_resets
,
377 &target_stat_lu_attr_full_stat
,
378 &target_stat_lu_attr_hs_num_cmds
,
379 &target_stat_lu_attr_creation_time
,
383 static const struct config_item_type target_stat_scsi_lu_cit
= {
384 .ct_attrs
= target_stat_scsi_lu_attrs
,
385 .ct_owner
= THIS_MODULE
,
389 * Called from target_core_configfs.c:target_core_make_subdev() to setup
390 * the target statistics groups + configfs CITs located in target_core_stat.c
392 void target_stat_setup_dev_default_groups(struct se_device
*dev
)
394 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_dev_group
,
395 "scsi_dev", &target_stat_scsi_dev_cit
);
396 configfs_add_default_group(&dev
->dev_stat_grps
.scsi_dev_group
,
397 &dev
->dev_stat_grps
.stat_group
);
399 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_tgt_dev_group
,
400 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit
);
401 configfs_add_default_group(&dev
->dev_stat_grps
.scsi_tgt_dev_group
,
402 &dev
->dev_stat_grps
.stat_group
);
404 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_lu_group
,
405 "scsi_lu", &target_stat_scsi_lu_cit
);
406 configfs_add_default_group(&dev
->dev_stat_grps
.scsi_lu_group
,
407 &dev
->dev_stat_grps
.stat_group
);
414 static struct se_lun
*to_stat_port(struct config_item
*item
)
416 struct se_port_stat_grps
*pgrps
= container_of(to_config_group(item
),
417 struct se_port_stat_grps
, scsi_port_group
);
418 return container_of(pgrps
, struct se_lun
, port_stat_grps
);
421 static ssize_t
target_stat_port_inst_show(struct config_item
*item
, char *page
)
423 struct se_lun
*lun
= to_stat_port(item
);
424 struct se_device
*dev
;
425 ssize_t ret
= -ENODEV
;
428 dev
= rcu_dereference(lun
->lun_se_dev
);
430 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
435 static ssize_t
target_stat_port_dev_show(struct config_item
*item
, char *page
)
437 struct se_lun
*lun
= to_stat_port(item
);
438 struct se_device
*dev
;
439 ssize_t ret
= -ENODEV
;
442 dev
= rcu_dereference(lun
->lun_se_dev
);
444 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
449 static ssize_t
target_stat_port_indx_show(struct config_item
*item
, char *page
)
451 struct se_lun
*lun
= to_stat_port(item
);
452 struct se_device
*dev
;
453 ssize_t ret
= -ENODEV
;
456 dev
= rcu_dereference(lun
->lun_se_dev
);
458 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_tpg
->tpg_rtpi
);
463 static ssize_t
target_stat_port_role_show(struct config_item
*item
, char *page
)
465 struct se_lun
*lun
= to_stat_port(item
);
466 struct se_device
*dev
;
467 ssize_t ret
= -ENODEV
;
470 dev
= rcu_dereference(lun
->lun_se_dev
);
472 ret
= snprintf(page
, PAGE_SIZE
, "%s%u\n", "Device", dev
->dev_index
);
477 static ssize_t
target_stat_port_busy_count_show(struct config_item
*item
,
480 struct se_lun
*lun
= to_stat_port(item
);
481 struct se_device
*dev
;
482 ssize_t ret
= -ENODEV
;
485 dev
= rcu_dereference(lun
->lun_se_dev
);
487 /* FIXME: scsiPortBusyStatuses */
488 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
494 CONFIGFS_ATTR_RO(target_stat_port_
, inst
);
495 CONFIGFS_ATTR_RO(target_stat_port_
, dev
);
496 CONFIGFS_ATTR_RO(target_stat_port_
, indx
);
497 CONFIGFS_ATTR_RO(target_stat_port_
, role
);
498 CONFIGFS_ATTR_RO(target_stat_port_
, busy_count
);
500 static struct configfs_attribute
*target_stat_scsi_port_attrs
[] = {
501 &target_stat_port_attr_inst
,
502 &target_stat_port_attr_dev
,
503 &target_stat_port_attr_indx
,
504 &target_stat_port_attr_role
,
505 &target_stat_port_attr_busy_count
,
509 static const struct config_item_type target_stat_scsi_port_cit
= {
510 .ct_attrs
= target_stat_scsi_port_attrs
,
511 .ct_owner
= THIS_MODULE
,
515 * SCSI Target Port Table
517 static struct se_lun
*to_stat_tgt_port(struct config_item
*item
)
519 struct se_port_stat_grps
*pgrps
= container_of(to_config_group(item
),
520 struct se_port_stat_grps
, scsi_tgt_port_group
);
521 return container_of(pgrps
, struct se_lun
, port_stat_grps
);
524 static ssize_t
target_stat_tgt_port_inst_show(struct config_item
*item
,
527 struct se_lun
*lun
= to_stat_tgt_port(item
);
528 struct se_device
*dev
;
529 ssize_t ret
= -ENODEV
;
532 dev
= rcu_dereference(lun
->lun_se_dev
);
534 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
539 static ssize_t
target_stat_tgt_port_dev_show(struct config_item
*item
,
542 struct se_lun
*lun
= to_stat_tgt_port(item
);
543 struct se_device
*dev
;
544 ssize_t ret
= -ENODEV
;
547 dev
= rcu_dereference(lun
->lun_se_dev
);
549 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
554 static ssize_t
target_stat_tgt_port_indx_show(struct config_item
*item
,
557 struct se_lun
*lun
= to_stat_tgt_port(item
);
558 struct se_device
*dev
;
559 ssize_t ret
= -ENODEV
;
562 dev
= rcu_dereference(lun
->lun_se_dev
);
564 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_tpg
->tpg_rtpi
);
569 static ssize_t
target_stat_tgt_port_name_show(struct config_item
*item
,
572 struct se_lun
*lun
= to_stat_tgt_port(item
);
573 struct se_portal_group
*tpg
= lun
->lun_tpg
;
574 struct se_device
*dev
;
575 ssize_t ret
= -ENODEV
;
578 dev
= rcu_dereference(lun
->lun_se_dev
);
580 ret
= snprintf(page
, PAGE_SIZE
, "%sPort#%u\n",
581 tpg
->se_tpg_tfo
->fabric_name
,
582 lun
->lun_tpg
->tpg_rtpi
);
587 static ssize_t
target_stat_tgt_port_port_index_show(struct config_item
*item
,
590 struct se_lun
*lun
= to_stat_tgt_port(item
);
591 struct se_portal_group
*tpg
= lun
->lun_tpg
;
592 struct se_device
*dev
;
593 ssize_t ret
= -ENODEV
;
596 dev
= rcu_dereference(lun
->lun_se_dev
);
598 ret
= snprintf(page
, PAGE_SIZE
, "%s%s%d\n",
599 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
), "+t+",
600 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
605 static ssize_t
target_stat_tgt_port_in_cmds_show(struct config_item
*item
,
608 struct se_lun
*lun
= to_stat_tgt_port(item
);
609 struct se_device
*dev
;
610 ssize_t ret
= -ENODEV
;
613 dev
= rcu_dereference(lun
->lun_se_dev
);
615 ret
= snprintf(page
, PAGE_SIZE
, "%lu\n",
616 atomic_long_read(&lun
->lun_stats
.cmd_pdus
));
621 static ssize_t
target_stat_tgt_port_write_mbytes_show(struct config_item
*item
,
624 struct se_lun
*lun
= to_stat_tgt_port(item
);
625 struct se_device
*dev
;
626 ssize_t ret
= -ENODEV
;
629 dev
= rcu_dereference(lun
->lun_se_dev
);
631 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
632 (u32
)(atomic_long_read(&lun
->lun_stats
.rx_data_octets
) >> 20));
637 static ssize_t
target_stat_tgt_port_read_mbytes_show(struct config_item
*item
,
640 struct se_lun
*lun
= to_stat_tgt_port(item
);
641 struct se_device
*dev
;
642 ssize_t ret
= -ENODEV
;
645 dev
= rcu_dereference(lun
->lun_se_dev
);
647 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
648 (u32
)(atomic_long_read(&lun
->lun_stats
.tx_data_octets
) >> 20));
653 static ssize_t
target_stat_tgt_port_hs_in_cmds_show(struct config_item
*item
,
656 struct se_lun
*lun
= to_stat_tgt_port(item
);
657 struct se_device
*dev
;
658 ssize_t ret
= -ENODEV
;
661 dev
= rcu_dereference(lun
->lun_se_dev
);
663 /* FIXME: scsiTgtPortHsInCommands */
664 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
670 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, inst
);
671 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, dev
);
672 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, indx
);
673 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, name
);
674 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, port_index
);
675 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, in_cmds
);
676 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, write_mbytes
);
677 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, read_mbytes
);
678 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, hs_in_cmds
);
680 static struct configfs_attribute
*target_stat_scsi_tgt_port_attrs
[] = {
681 &target_stat_tgt_port_attr_inst
,
682 &target_stat_tgt_port_attr_dev
,
683 &target_stat_tgt_port_attr_indx
,
684 &target_stat_tgt_port_attr_name
,
685 &target_stat_tgt_port_attr_port_index
,
686 &target_stat_tgt_port_attr_in_cmds
,
687 &target_stat_tgt_port_attr_write_mbytes
,
688 &target_stat_tgt_port_attr_read_mbytes
,
689 &target_stat_tgt_port_attr_hs_in_cmds
,
693 static const struct config_item_type target_stat_scsi_tgt_port_cit
= {
694 .ct_attrs
= target_stat_scsi_tgt_port_attrs
,
695 .ct_owner
= THIS_MODULE
,
699 * SCSI Transport Table
701 static struct se_lun
*to_transport_stat(struct config_item
*item
)
703 struct se_port_stat_grps
*pgrps
= container_of(to_config_group(item
),
704 struct se_port_stat_grps
, scsi_transport_group
);
705 return container_of(pgrps
, struct se_lun
, port_stat_grps
);
708 static ssize_t
target_stat_transport_inst_show(struct config_item
*item
,
711 struct se_lun
*lun
= to_transport_stat(item
);
712 struct se_device
*dev
;
713 ssize_t ret
= -ENODEV
;
716 dev
= rcu_dereference(lun
->lun_se_dev
);
718 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
723 static ssize_t
target_stat_transport_device_show(struct config_item
*item
,
726 struct se_lun
*lun
= to_transport_stat(item
);
727 struct se_device
*dev
;
728 struct se_portal_group
*tpg
= lun
->lun_tpg
;
729 ssize_t ret
= -ENODEV
;
732 dev
= rcu_dereference(lun
->lun_se_dev
);
734 /* scsiTransportType */
735 ret
= snprintf(page
, PAGE_SIZE
, "scsiTransport%s\n",
736 tpg
->se_tpg_tfo
->fabric_name
);
742 static ssize_t
target_stat_transport_indx_show(struct config_item
*item
,
745 struct se_lun
*lun
= to_transport_stat(item
);
746 struct se_device
*dev
;
747 struct se_portal_group
*tpg
= lun
->lun_tpg
;
748 ssize_t ret
= -ENODEV
;
751 dev
= rcu_dereference(lun
->lun_se_dev
);
753 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
754 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
759 static ssize_t
target_stat_transport_dev_name_show(struct config_item
*item
,
762 struct se_lun
*lun
= to_transport_stat(item
);
763 struct se_device
*dev
;
764 struct se_portal_group
*tpg
= lun
->lun_tpg
;
766 ssize_t ret
= -ENODEV
;
769 dev
= rcu_dereference(lun
->lun_se_dev
);
772 /* scsiTransportDevName */
773 ret
= snprintf(page
, PAGE_SIZE
, "%s+%s\n",
774 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
775 (strlen(wwn
->unit_serial
)) ? wwn
->unit_serial
:
782 static ssize_t
target_stat_transport_proto_id_show(struct config_item
*item
,
785 struct se_lun
*lun
= to_transport_stat(item
);
786 struct se_device
*dev
;
787 struct se_portal_group
*tpg
= lun
->lun_tpg
;
788 ssize_t ret
= -ENODEV
;
791 dev
= rcu_dereference(lun
->lun_se_dev
);
793 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->proto_id
);
798 CONFIGFS_ATTR_RO(target_stat_transport_
, inst
);
799 CONFIGFS_ATTR_RO(target_stat_transport_
, device
);
800 CONFIGFS_ATTR_RO(target_stat_transport_
, indx
);
801 CONFIGFS_ATTR_RO(target_stat_transport_
, dev_name
);
802 CONFIGFS_ATTR_RO(target_stat_transport_
, proto_id
);
804 static struct configfs_attribute
*target_stat_scsi_transport_attrs
[] = {
805 &target_stat_transport_attr_inst
,
806 &target_stat_transport_attr_device
,
807 &target_stat_transport_attr_indx
,
808 &target_stat_transport_attr_dev_name
,
809 &target_stat_transport_attr_proto_id
,
813 static const struct config_item_type target_stat_scsi_transport_cit
= {
814 .ct_attrs
= target_stat_scsi_transport_attrs
,
815 .ct_owner
= THIS_MODULE
,
819 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
820 * the target port statistics groups + configfs CITs located in target_core_stat.c
822 void target_stat_setup_port_default_groups(struct se_lun
*lun
)
824 config_group_init_type_name(&lun
->port_stat_grps
.scsi_port_group
,
825 "scsi_port", &target_stat_scsi_port_cit
);
826 configfs_add_default_group(&lun
->port_stat_grps
.scsi_port_group
,
827 &lun
->port_stat_grps
.stat_group
);
829 config_group_init_type_name(&lun
->port_stat_grps
.scsi_tgt_port_group
,
830 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit
);
831 configfs_add_default_group(&lun
->port_stat_grps
.scsi_tgt_port_group
,
832 &lun
->port_stat_grps
.stat_group
);
834 config_group_init_type_name(&lun
->port_stat_grps
.scsi_transport_group
,
835 "scsi_transport", &target_stat_scsi_transport_cit
);
836 configfs_add_default_group(&lun
->port_stat_grps
.scsi_transport_group
,
837 &lun
->port_stat_grps
.stat_group
);
841 * SCSI Authorized Initiator Table
844 static struct se_lun_acl
*auth_to_lacl(struct config_item
*item
)
846 struct se_ml_stat_grps
*lgrps
= container_of(to_config_group(item
),
847 struct se_ml_stat_grps
, scsi_auth_intr_group
);
848 return container_of(lgrps
, struct se_lun_acl
, ml_stat_grps
);
851 static ssize_t
target_stat_auth_inst_show(struct config_item
*item
,
854 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
855 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
856 struct se_dev_entry
*deve
;
857 struct se_portal_group
*tpg
;
861 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
868 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
869 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
874 static ssize_t
target_stat_auth_dev_show(struct config_item
*item
,
877 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
878 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
879 struct se_dev_entry
*deve
;
883 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
889 /* scsiDeviceIndex */
890 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->se_lun
->lun_index
);
895 static ssize_t
target_stat_auth_port_show(struct config_item
*item
,
898 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
899 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
900 struct se_dev_entry
*deve
;
901 struct se_portal_group
*tpg
;
905 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
911 /* scsiAuthIntrTgtPortIndex */
912 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
917 static ssize_t
target_stat_auth_indx_show(struct config_item
*item
,
920 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
921 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
922 struct se_dev_entry
*deve
;
926 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
931 /* scsiAuthIntrIndex */
932 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
937 static ssize_t
target_stat_auth_dev_or_port_show(struct config_item
*item
,
940 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
941 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
942 struct se_dev_entry
*deve
;
946 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
951 /* scsiAuthIntrDevOrPort */
952 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 1);
957 static ssize_t
target_stat_auth_intr_name_show(struct config_item
*item
,
960 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
961 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
962 struct se_dev_entry
*deve
;
966 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
971 /* scsiAuthIntrName */
972 ret
= snprintf(page
, PAGE_SIZE
, "%s\n", nacl
->initiatorname
);
977 static ssize_t
target_stat_auth_map_indx_show(struct config_item
*item
,
980 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
981 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
982 struct se_dev_entry
*deve
;
986 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
991 /* FIXME: scsiAuthIntrLunMapIndex */
992 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
997 static ssize_t
target_stat_auth_att_count_show(struct config_item
*item
,
1000 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1001 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1002 struct se_dev_entry
*deve
;
1006 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1011 /* scsiAuthIntrAttachedTimes */
1012 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->attach_count
);
1017 static ssize_t
target_stat_auth_num_cmds_show(struct config_item
*item
,
1020 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1021 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1022 struct se_dev_entry
*deve
;
1026 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1031 /* scsiAuthIntrOutCommands */
1032 ret
= snprintf(page
, PAGE_SIZE
, "%lu\n",
1033 atomic_long_read(&deve
->total_cmds
));
1038 static ssize_t
target_stat_auth_read_mbytes_show(struct config_item
*item
,
1041 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1042 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1043 struct se_dev_entry
*deve
;
1047 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1052 /* scsiAuthIntrReadMegaBytes */
1053 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1054 (u32
)(atomic_long_read(&deve
->read_bytes
) >> 20));
1059 static ssize_t
target_stat_auth_write_mbytes_show(struct config_item
*item
,
1062 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1063 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1064 struct se_dev_entry
*deve
;
1068 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1073 /* scsiAuthIntrWrittenMegaBytes */
1074 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1075 (u32
)(atomic_long_read(&deve
->write_bytes
) >> 20));
1080 static ssize_t
target_stat_auth_hs_num_cmds_show(struct config_item
*item
,
1083 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1084 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1085 struct se_dev_entry
*deve
;
1089 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1094 /* FIXME: scsiAuthIntrHSOutCommands */
1095 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1100 static ssize_t
target_stat_auth_creation_time_show(struct config_item
*item
,
1103 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1104 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1105 struct se_dev_entry
*deve
;
1109 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1114 /* scsiAuthIntrLastCreation */
1115 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)deve
->creation_time
-
1116 INITIAL_JIFFIES
) * 100 / HZ
));
1121 static ssize_t
target_stat_auth_row_status_show(struct config_item
*item
,
1124 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1125 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1126 struct se_dev_entry
*deve
;
1130 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1135 /* FIXME: scsiAuthIntrRowStatus */
1136 ret
= snprintf(page
, PAGE_SIZE
, "Ready\n");
1141 CONFIGFS_ATTR_RO(target_stat_auth_
, inst
);
1142 CONFIGFS_ATTR_RO(target_stat_auth_
, dev
);
1143 CONFIGFS_ATTR_RO(target_stat_auth_
, port
);
1144 CONFIGFS_ATTR_RO(target_stat_auth_
, indx
);
1145 CONFIGFS_ATTR_RO(target_stat_auth_
, dev_or_port
);
1146 CONFIGFS_ATTR_RO(target_stat_auth_
, intr_name
);
1147 CONFIGFS_ATTR_RO(target_stat_auth_
, map_indx
);
1148 CONFIGFS_ATTR_RO(target_stat_auth_
, att_count
);
1149 CONFIGFS_ATTR_RO(target_stat_auth_
, num_cmds
);
1150 CONFIGFS_ATTR_RO(target_stat_auth_
, read_mbytes
);
1151 CONFIGFS_ATTR_RO(target_stat_auth_
, write_mbytes
);
1152 CONFIGFS_ATTR_RO(target_stat_auth_
, hs_num_cmds
);
1153 CONFIGFS_ATTR_RO(target_stat_auth_
, creation_time
);
1154 CONFIGFS_ATTR_RO(target_stat_auth_
, row_status
);
1156 static struct configfs_attribute
*target_stat_scsi_auth_intr_attrs
[] = {
1157 &target_stat_auth_attr_inst
,
1158 &target_stat_auth_attr_dev
,
1159 &target_stat_auth_attr_port
,
1160 &target_stat_auth_attr_indx
,
1161 &target_stat_auth_attr_dev_or_port
,
1162 &target_stat_auth_attr_intr_name
,
1163 &target_stat_auth_attr_map_indx
,
1164 &target_stat_auth_attr_att_count
,
1165 &target_stat_auth_attr_num_cmds
,
1166 &target_stat_auth_attr_read_mbytes
,
1167 &target_stat_auth_attr_write_mbytes
,
1168 &target_stat_auth_attr_hs_num_cmds
,
1169 &target_stat_auth_attr_creation_time
,
1170 &target_stat_auth_attr_row_status
,
1174 static const struct config_item_type target_stat_scsi_auth_intr_cit
= {
1175 .ct_attrs
= target_stat_scsi_auth_intr_attrs
,
1176 .ct_owner
= THIS_MODULE
,
1180 * SCSI Attached Initiator Port Table
1183 static struct se_lun_acl
*iport_to_lacl(struct config_item
*item
)
1185 struct se_ml_stat_grps
*lgrps
= container_of(to_config_group(item
),
1186 struct se_ml_stat_grps
, scsi_att_intr_port_group
);
1187 return container_of(lgrps
, struct se_lun_acl
, ml_stat_grps
);
1190 static ssize_t
target_stat_iport_inst_show(struct config_item
*item
,
1193 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1194 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1195 struct se_dev_entry
*deve
;
1196 struct se_portal_group
*tpg
;
1200 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1207 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1208 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
1213 static ssize_t
target_stat_iport_dev_show(struct config_item
*item
,
1216 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1217 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1218 struct se_dev_entry
*deve
;
1222 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1228 /* scsiDeviceIndex */
1229 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->se_lun
->lun_index
);
1234 static ssize_t
target_stat_iport_port_show(struct config_item
*item
,
1237 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1238 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1239 struct se_dev_entry
*deve
;
1240 struct se_portal_group
*tpg
;
1244 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1251 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
1256 static ssize_t
target_stat_iport_indx_show(struct config_item
*item
,
1259 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1260 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1261 struct se_session
*se_sess
;
1262 struct se_portal_group
*tpg
;
1265 spin_lock_irq(&nacl
->nacl_sess_lock
);
1266 se_sess
= nacl
->nacl_sess
;
1268 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1273 /* scsiAttIntrPortIndex */
1274 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1275 tpg
->se_tpg_tfo
->sess_get_index(se_sess
));
1276 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1280 static ssize_t
target_stat_iport_port_auth_indx_show(struct config_item
*item
,
1283 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1284 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1285 struct se_dev_entry
*deve
;
1289 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1294 /* scsiAttIntrPortAuthIntrIdx */
1295 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
1300 static ssize_t
target_stat_iport_port_ident_show(struct config_item
*item
,
1303 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1304 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1305 struct se_session
*se_sess
;
1306 struct se_portal_group
*tpg
;
1308 unsigned char buf
[64];
1310 spin_lock_irq(&nacl
->nacl_sess_lock
);
1311 se_sess
= nacl
->nacl_sess
;
1313 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1318 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1320 if (tpg
->se_tpg_tfo
->sess_get_initiator_sid
!= NULL
)
1321 tpg
->se_tpg_tfo
->sess_get_initiator_sid(se_sess
, buf
, 64);
1323 ret
= snprintf(page
, PAGE_SIZE
, "%s+i+%s\n", nacl
->initiatorname
, buf
);
1324 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1328 CONFIGFS_ATTR_RO(target_stat_iport_
, inst
);
1329 CONFIGFS_ATTR_RO(target_stat_iport_
, dev
);
1330 CONFIGFS_ATTR_RO(target_stat_iport_
, port
);
1331 CONFIGFS_ATTR_RO(target_stat_iport_
, indx
);
1332 CONFIGFS_ATTR_RO(target_stat_iport_
, port_auth_indx
);
1333 CONFIGFS_ATTR_RO(target_stat_iport_
, port_ident
);
1335 static struct configfs_attribute
*target_stat_scsi_ath_intr_port_attrs
[] = {
1336 &target_stat_iport_attr_inst
,
1337 &target_stat_iport_attr_dev
,
1338 &target_stat_iport_attr_port
,
1339 &target_stat_iport_attr_indx
,
1340 &target_stat_iport_attr_port_auth_indx
,
1341 &target_stat_iport_attr_port_ident
,
1345 static const struct config_item_type target_stat_scsi_att_intr_port_cit
= {
1346 .ct_attrs
= target_stat_scsi_ath_intr_port_attrs
,
1347 .ct_owner
= THIS_MODULE
,
1351 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1352 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1354 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl
*lacl
)
1356 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_auth_intr_group
,
1357 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit
);
1358 configfs_add_default_group(&lacl
->ml_stat_grps
.scsi_auth_intr_group
,
1359 &lacl
->ml_stat_grps
.stat_group
);
1361 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_att_intr_port_group
,
1362 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit
);
1363 configfs_add_default_group(&lacl
->ml_stat_grps
.scsi_att_intr_port_group
,
1364 &lacl
->ml_stat_grps
.stat_group
);