1 /*******************************************************************************
2 * Filename: target_core_stat.c
4 * Modern ConfigFS group context specific statistics based on original
5 * target_core_mib.c code
7 * (c) Copyright 2006-2013 Datera, Inc.
9 * Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ******************************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/delay.h>
30 #include <linux/timer.h>
31 #include <linux/string.h>
32 #include <linux/utsname.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/configfs.h>
37 #include <target/target_core_base.h>
38 #include <target/target_core_backend.h>
39 #include <target/target_core_fabric.h>
41 #include "target_core_internal.h"
43 #ifndef INITIAL_JIFFIES
44 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
48 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
50 #define SCSI_LU_INDEX 1
57 static struct se_device
*to_stat_dev(struct config_item
*item
)
59 struct se_dev_stat_grps
*sgrps
= container_of(to_config_group(item
),
60 struct se_dev_stat_grps
, scsi_dev_group
);
61 return container_of(sgrps
, struct se_device
, dev_stat_grps
);
64 static ssize_t
target_stat_inst_show(struct config_item
*item
, char *page
)
66 struct se_hba
*hba
= to_stat_dev(item
)->se_hba
;
68 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
71 static ssize_t
target_stat_indx_show(struct config_item
*item
, char *page
)
73 return snprintf(page
, PAGE_SIZE
, "%u\n", to_stat_dev(item
)->dev_index
);
76 static ssize_t
target_stat_role_show(struct config_item
*item
, char *page
)
78 return snprintf(page
, PAGE_SIZE
, "Target\n");
81 static ssize_t
target_stat_ports_show(struct config_item
*item
, char *page
)
83 return snprintf(page
, PAGE_SIZE
, "%u\n", to_stat_dev(item
)->export_count
);
86 CONFIGFS_ATTR_RO(target_stat_
, inst
);
87 CONFIGFS_ATTR_RO(target_stat_
, indx
);
88 CONFIGFS_ATTR_RO(target_stat_
, role
);
89 CONFIGFS_ATTR_RO(target_stat_
, ports
);
91 static struct configfs_attribute
*target_stat_scsi_dev_attrs
[] = {
92 &target_stat_attr_inst
,
93 &target_stat_attr_indx
,
94 &target_stat_attr_role
,
95 &target_stat_attr_ports
,
99 static const struct config_item_type target_stat_scsi_dev_cit
= {
100 .ct_attrs
= target_stat_scsi_dev_attrs
,
101 .ct_owner
= THIS_MODULE
,
105 * SCSI Target Device Table
107 static struct se_device
*to_stat_tgt_dev(struct config_item
*item
)
109 struct se_dev_stat_grps
*sgrps
= container_of(to_config_group(item
),
110 struct se_dev_stat_grps
, scsi_tgt_dev_group
);
111 return container_of(sgrps
, struct se_device
, dev_stat_grps
);
114 static ssize_t
target_stat_tgt_inst_show(struct config_item
*item
, char *page
)
116 struct se_hba
*hba
= to_stat_tgt_dev(item
)->se_hba
;
118 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
121 static ssize_t
target_stat_tgt_indx_show(struct config_item
*item
, char *page
)
123 return snprintf(page
, PAGE_SIZE
, "%u\n", to_stat_tgt_dev(item
)->dev_index
);
126 static ssize_t
target_stat_tgt_num_lus_show(struct config_item
*item
,
129 return snprintf(page
, PAGE_SIZE
, "%u\n", LU_COUNT
);
132 static ssize_t
target_stat_tgt_status_show(struct config_item
*item
,
135 if (to_stat_tgt_dev(item
)->export_count
)
136 return snprintf(page
, PAGE_SIZE
, "activated");
138 return snprintf(page
, PAGE_SIZE
, "deactivated");
141 static ssize_t
target_stat_tgt_non_access_lus_show(struct config_item
*item
,
144 int non_accessible_lus
;
146 if (to_stat_tgt_dev(item
)->export_count
)
147 non_accessible_lus
= 0;
149 non_accessible_lus
= 1;
151 return snprintf(page
, PAGE_SIZE
, "%u\n", non_accessible_lus
);
154 static ssize_t
target_stat_tgt_resets_show(struct config_item
*item
,
157 return snprintf(page
, PAGE_SIZE
, "%lu\n",
158 atomic_long_read(&to_stat_tgt_dev(item
)->num_resets
));
161 static ssize_t
target_stat_tgt_aborts_complete_show(struct config_item
*item
,
164 return snprintf(page
, PAGE_SIZE
, "%lu\n",
165 atomic_long_read(&to_stat_tgt_dev(item
)->aborts_complete
));
168 static ssize_t
target_stat_tgt_aborts_no_task_show(struct config_item
*item
,
171 return snprintf(page
, PAGE_SIZE
, "%lu\n",
172 atomic_long_read(&to_stat_tgt_dev(item
)->aborts_no_task
));
175 CONFIGFS_ATTR_RO(target_stat_tgt_
, inst
);
176 CONFIGFS_ATTR_RO(target_stat_tgt_
, indx
);
177 CONFIGFS_ATTR_RO(target_stat_tgt_
, num_lus
);
178 CONFIGFS_ATTR_RO(target_stat_tgt_
, status
);
179 CONFIGFS_ATTR_RO(target_stat_tgt_
, non_access_lus
);
180 CONFIGFS_ATTR_RO(target_stat_tgt_
, resets
);
181 CONFIGFS_ATTR_RO(target_stat_tgt_
, aborts_complete
);
182 CONFIGFS_ATTR_RO(target_stat_tgt_
, aborts_no_task
);
184 static struct configfs_attribute
*target_stat_scsi_tgt_dev_attrs
[] = {
185 &target_stat_tgt_attr_inst
,
186 &target_stat_tgt_attr_indx
,
187 &target_stat_tgt_attr_num_lus
,
188 &target_stat_tgt_attr_status
,
189 &target_stat_tgt_attr_non_access_lus
,
190 &target_stat_tgt_attr_resets
,
191 &target_stat_tgt_attr_aborts_complete
,
192 &target_stat_tgt_attr_aborts_no_task
,
196 static const struct config_item_type target_stat_scsi_tgt_dev_cit
= {
197 .ct_attrs
= target_stat_scsi_tgt_dev_attrs
,
198 .ct_owner
= THIS_MODULE
,
202 * SCSI Logical Unit Table
205 static struct se_device
*to_stat_lu_dev(struct config_item
*item
)
207 struct se_dev_stat_grps
*sgrps
= container_of(to_config_group(item
),
208 struct se_dev_stat_grps
, scsi_lu_group
);
209 return container_of(sgrps
, struct se_device
, dev_stat_grps
);
212 static ssize_t
target_stat_lu_inst_show(struct config_item
*item
, char *page
)
214 struct se_hba
*hba
= to_stat_lu_dev(item
)->se_hba
;
216 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
219 static ssize_t
target_stat_lu_dev_show(struct config_item
*item
, char *page
)
221 return snprintf(page
, PAGE_SIZE
, "%u\n",
222 to_stat_lu_dev(item
)->dev_index
);
225 static ssize_t
target_stat_lu_indx_show(struct config_item
*item
, char *page
)
227 return snprintf(page
, PAGE_SIZE
, "%u\n", SCSI_LU_INDEX
);
230 static ssize_t
target_stat_lu_lun_show(struct config_item
*item
, char *page
)
232 /* FIXME: scsiLuDefaultLun */
233 return snprintf(page
, PAGE_SIZE
, "%llu\n", (unsigned long long)0);
236 static ssize_t
target_stat_lu_lu_name_show(struct config_item
*item
, char *page
)
238 struct se_device
*dev
= to_stat_lu_dev(item
);
241 return snprintf(page
, PAGE_SIZE
, "%s\n",
242 (strlen(dev
->t10_wwn
.unit_serial
)) ?
243 dev
->t10_wwn
.unit_serial
: "None");
246 static ssize_t
target_stat_lu_vend_show(struct config_item
*item
, char *page
)
248 struct se_device
*dev
= to_stat_lu_dev(item
);
250 char str
[sizeof(dev
->t10_wwn
.vendor
)+1];
253 for (i
= 0; i
< sizeof(dev
->t10_wwn
.vendor
); i
++)
254 str
[i
] = ISPRINT(dev
->t10_wwn
.vendor
[i
]) ?
255 dev
->t10_wwn
.vendor
[i
] : ' ';
257 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
260 static ssize_t
target_stat_lu_prod_show(struct config_item
*item
, char *page
)
262 struct se_device
*dev
= to_stat_lu_dev(item
);
264 char str
[sizeof(dev
->t10_wwn
.model
)+1];
266 /* scsiLuProductId */
267 for (i
= 0; i
< sizeof(dev
->t10_wwn
.model
); i
++)
268 str
[i
] = ISPRINT(dev
->t10_wwn
.model
[i
]) ?
269 dev
->t10_wwn
.model
[i
] : ' ';
271 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
274 static ssize_t
target_stat_lu_rev_show(struct config_item
*item
, char *page
)
276 struct se_device
*dev
= to_stat_lu_dev(item
);
278 char str
[sizeof(dev
->t10_wwn
.revision
)+1];
280 /* scsiLuRevisionId */
281 for (i
= 0; i
< sizeof(dev
->t10_wwn
.revision
); i
++)
282 str
[i
] = ISPRINT(dev
->t10_wwn
.revision
[i
]) ?
283 dev
->t10_wwn
.revision
[i
] : ' ';
285 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
288 static ssize_t
target_stat_lu_dev_type_show(struct config_item
*item
, char *page
)
290 struct se_device
*dev
= to_stat_lu_dev(item
);
292 /* scsiLuPeripheralType */
293 return snprintf(page
, PAGE_SIZE
, "%u\n",
294 dev
->transport
->get_device_type(dev
));
297 static ssize_t
target_stat_lu_status_show(struct config_item
*item
, char *page
)
299 struct se_device
*dev
= to_stat_lu_dev(item
);
302 return snprintf(page
, PAGE_SIZE
, "%s\n",
303 (dev
->export_count
) ? "available" : "notavailable");
306 static ssize_t
target_stat_lu_state_bit_show(struct config_item
*item
,
310 return snprintf(page
, PAGE_SIZE
, "exposed\n");
313 static ssize_t
target_stat_lu_num_cmds_show(struct config_item
*item
,
316 struct se_device
*dev
= to_stat_lu_dev(item
);
318 /* scsiLuNumCommands */
319 return snprintf(page
, PAGE_SIZE
, "%lu\n",
320 atomic_long_read(&dev
->num_cmds
));
323 static ssize_t
target_stat_lu_read_mbytes_show(struct config_item
*item
,
326 struct se_device
*dev
= to_stat_lu_dev(item
);
328 /* scsiLuReadMegaBytes */
329 return snprintf(page
, PAGE_SIZE
, "%lu\n",
330 atomic_long_read(&dev
->read_bytes
) >> 20);
333 static ssize_t
target_stat_lu_write_mbytes_show(struct config_item
*item
,
336 struct se_device
*dev
= to_stat_lu_dev(item
);
338 /* scsiLuWrittenMegaBytes */
339 return snprintf(page
, PAGE_SIZE
, "%lu\n",
340 atomic_long_read(&dev
->write_bytes
) >> 20);
343 static ssize_t
target_stat_lu_resets_show(struct config_item
*item
, char *page
)
345 struct se_device
*dev
= to_stat_lu_dev(item
);
348 return snprintf(page
, PAGE_SIZE
, "%lu\n",
349 atomic_long_read(&dev
->num_resets
));
352 static ssize_t
target_stat_lu_full_stat_show(struct config_item
*item
,
355 /* FIXME: scsiLuOutTaskSetFullStatus */
356 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
359 static ssize_t
target_stat_lu_hs_num_cmds_show(struct config_item
*item
,
362 /* FIXME: scsiLuHSInCommands */
363 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
366 static ssize_t
target_stat_lu_creation_time_show(struct config_item
*item
,
369 struct se_device
*dev
= to_stat_lu_dev(item
);
371 /* scsiLuCreationTime */
372 return snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)dev
->creation_time
-
373 INITIAL_JIFFIES
) * 100 / HZ
));
376 CONFIGFS_ATTR_RO(target_stat_lu_
, inst
);
377 CONFIGFS_ATTR_RO(target_stat_lu_
, dev
);
378 CONFIGFS_ATTR_RO(target_stat_lu_
, indx
);
379 CONFIGFS_ATTR_RO(target_stat_lu_
, lun
);
380 CONFIGFS_ATTR_RO(target_stat_lu_
, lu_name
);
381 CONFIGFS_ATTR_RO(target_stat_lu_
, vend
);
382 CONFIGFS_ATTR_RO(target_stat_lu_
, prod
);
383 CONFIGFS_ATTR_RO(target_stat_lu_
, rev
);
384 CONFIGFS_ATTR_RO(target_stat_lu_
, dev_type
);
385 CONFIGFS_ATTR_RO(target_stat_lu_
, status
);
386 CONFIGFS_ATTR_RO(target_stat_lu_
, state_bit
);
387 CONFIGFS_ATTR_RO(target_stat_lu_
, num_cmds
);
388 CONFIGFS_ATTR_RO(target_stat_lu_
, read_mbytes
);
389 CONFIGFS_ATTR_RO(target_stat_lu_
, write_mbytes
);
390 CONFIGFS_ATTR_RO(target_stat_lu_
, resets
);
391 CONFIGFS_ATTR_RO(target_stat_lu_
, full_stat
);
392 CONFIGFS_ATTR_RO(target_stat_lu_
, hs_num_cmds
);
393 CONFIGFS_ATTR_RO(target_stat_lu_
, creation_time
);
395 static struct configfs_attribute
*target_stat_scsi_lu_attrs
[] = {
396 &target_stat_lu_attr_inst
,
397 &target_stat_lu_attr_dev
,
398 &target_stat_lu_attr_indx
,
399 &target_stat_lu_attr_lun
,
400 &target_stat_lu_attr_lu_name
,
401 &target_stat_lu_attr_vend
,
402 &target_stat_lu_attr_prod
,
403 &target_stat_lu_attr_rev
,
404 &target_stat_lu_attr_dev_type
,
405 &target_stat_lu_attr_status
,
406 &target_stat_lu_attr_state_bit
,
407 &target_stat_lu_attr_num_cmds
,
408 &target_stat_lu_attr_read_mbytes
,
409 &target_stat_lu_attr_write_mbytes
,
410 &target_stat_lu_attr_resets
,
411 &target_stat_lu_attr_full_stat
,
412 &target_stat_lu_attr_hs_num_cmds
,
413 &target_stat_lu_attr_creation_time
,
417 static const struct config_item_type target_stat_scsi_lu_cit
= {
418 .ct_attrs
= target_stat_scsi_lu_attrs
,
419 .ct_owner
= THIS_MODULE
,
423 * Called from target_core_configfs.c:target_core_make_subdev() to setup
424 * the target statistics groups + configfs CITs located in target_core_stat.c
426 void target_stat_setup_dev_default_groups(struct se_device
*dev
)
428 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_dev_group
,
429 "scsi_dev", &target_stat_scsi_dev_cit
);
430 configfs_add_default_group(&dev
->dev_stat_grps
.scsi_dev_group
,
431 &dev
->dev_stat_grps
.stat_group
);
433 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_tgt_dev_group
,
434 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit
);
435 configfs_add_default_group(&dev
->dev_stat_grps
.scsi_tgt_dev_group
,
436 &dev
->dev_stat_grps
.stat_group
);
438 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_lu_group
,
439 "scsi_lu", &target_stat_scsi_lu_cit
);
440 configfs_add_default_group(&dev
->dev_stat_grps
.scsi_lu_group
,
441 &dev
->dev_stat_grps
.stat_group
);
448 static struct se_lun
*to_stat_port(struct config_item
*item
)
450 struct se_port_stat_grps
*pgrps
= container_of(to_config_group(item
),
451 struct se_port_stat_grps
, scsi_port_group
);
452 return container_of(pgrps
, struct se_lun
, port_stat_grps
);
455 static ssize_t
target_stat_port_inst_show(struct config_item
*item
, char *page
)
457 struct se_lun
*lun
= to_stat_port(item
);
458 struct se_device
*dev
;
459 ssize_t ret
= -ENODEV
;
462 dev
= rcu_dereference(lun
->lun_se_dev
);
464 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
469 static ssize_t
target_stat_port_dev_show(struct config_item
*item
, char *page
)
471 struct se_lun
*lun
= to_stat_port(item
);
472 struct se_device
*dev
;
473 ssize_t ret
= -ENODEV
;
476 dev
= rcu_dereference(lun
->lun_se_dev
);
478 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
483 static ssize_t
target_stat_port_indx_show(struct config_item
*item
, char *page
)
485 struct se_lun
*lun
= to_stat_port(item
);
486 struct se_device
*dev
;
487 ssize_t ret
= -ENODEV
;
490 dev
= rcu_dereference(lun
->lun_se_dev
);
492 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_rtpi
);
497 static ssize_t
target_stat_port_role_show(struct config_item
*item
, char *page
)
499 struct se_lun
*lun
= to_stat_port(item
);
500 struct se_device
*dev
;
501 ssize_t ret
= -ENODEV
;
504 dev
= rcu_dereference(lun
->lun_se_dev
);
506 ret
= snprintf(page
, PAGE_SIZE
, "%s%u\n", "Device", dev
->dev_index
);
511 static ssize_t
target_stat_port_busy_count_show(struct config_item
*item
,
514 struct se_lun
*lun
= to_stat_port(item
);
515 struct se_device
*dev
;
516 ssize_t ret
= -ENODEV
;
519 dev
= rcu_dereference(lun
->lun_se_dev
);
521 /* FIXME: scsiPortBusyStatuses */
522 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
528 CONFIGFS_ATTR_RO(target_stat_port_
, inst
);
529 CONFIGFS_ATTR_RO(target_stat_port_
, dev
);
530 CONFIGFS_ATTR_RO(target_stat_port_
, indx
);
531 CONFIGFS_ATTR_RO(target_stat_port_
, role
);
532 CONFIGFS_ATTR_RO(target_stat_port_
, busy_count
);
534 static struct configfs_attribute
*target_stat_scsi_port_attrs
[] = {
535 &target_stat_port_attr_inst
,
536 &target_stat_port_attr_dev
,
537 &target_stat_port_attr_indx
,
538 &target_stat_port_attr_role
,
539 &target_stat_port_attr_busy_count
,
543 static const struct config_item_type target_stat_scsi_port_cit
= {
544 .ct_attrs
= target_stat_scsi_port_attrs
,
545 .ct_owner
= THIS_MODULE
,
549 * SCSI Target Port Table
551 static struct se_lun
*to_stat_tgt_port(struct config_item
*item
)
553 struct se_port_stat_grps
*pgrps
= container_of(to_config_group(item
),
554 struct se_port_stat_grps
, scsi_tgt_port_group
);
555 return container_of(pgrps
, struct se_lun
, port_stat_grps
);
558 static ssize_t
target_stat_tgt_port_inst_show(struct config_item
*item
,
561 struct se_lun
*lun
= to_stat_tgt_port(item
);
562 struct se_device
*dev
;
563 ssize_t ret
= -ENODEV
;
566 dev
= rcu_dereference(lun
->lun_se_dev
);
568 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
573 static ssize_t
target_stat_tgt_port_dev_show(struct config_item
*item
,
576 struct se_lun
*lun
= to_stat_tgt_port(item
);
577 struct se_device
*dev
;
578 ssize_t ret
= -ENODEV
;
581 dev
= rcu_dereference(lun
->lun_se_dev
);
583 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
588 static ssize_t
target_stat_tgt_port_indx_show(struct config_item
*item
,
591 struct se_lun
*lun
= to_stat_tgt_port(item
);
592 struct se_device
*dev
;
593 ssize_t ret
= -ENODEV
;
596 dev
= rcu_dereference(lun
->lun_se_dev
);
598 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_rtpi
);
603 static ssize_t
target_stat_tgt_port_name_show(struct config_item
*item
,
606 struct se_lun
*lun
= to_stat_tgt_port(item
);
607 struct se_portal_group
*tpg
= lun
->lun_tpg
;
608 struct se_device
*dev
;
609 ssize_t ret
= -ENODEV
;
612 dev
= rcu_dereference(lun
->lun_se_dev
);
614 ret
= snprintf(page
, PAGE_SIZE
, "%sPort#%u\n",
615 tpg
->se_tpg_tfo
->get_fabric_name(),
621 static ssize_t
target_stat_tgt_port_port_index_show(struct config_item
*item
,
624 struct se_lun
*lun
= to_stat_tgt_port(item
);
625 struct se_portal_group
*tpg
= lun
->lun_tpg
;
626 struct se_device
*dev
;
627 ssize_t ret
= -ENODEV
;
630 dev
= rcu_dereference(lun
->lun_se_dev
);
632 ret
= snprintf(page
, PAGE_SIZE
, "%s%s%d\n",
633 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
), "+t+",
634 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
639 static ssize_t
target_stat_tgt_port_in_cmds_show(struct config_item
*item
,
642 struct se_lun
*lun
= to_stat_tgt_port(item
);
643 struct se_device
*dev
;
644 ssize_t ret
= -ENODEV
;
647 dev
= rcu_dereference(lun
->lun_se_dev
);
649 ret
= snprintf(page
, PAGE_SIZE
, "%lu\n",
650 atomic_long_read(&lun
->lun_stats
.cmd_pdus
));
655 static ssize_t
target_stat_tgt_port_write_mbytes_show(struct config_item
*item
,
658 struct se_lun
*lun
= to_stat_tgt_port(item
);
659 struct se_device
*dev
;
660 ssize_t ret
= -ENODEV
;
663 dev
= rcu_dereference(lun
->lun_se_dev
);
665 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
666 (u32
)(atomic_long_read(&lun
->lun_stats
.rx_data_octets
) >> 20));
671 static ssize_t
target_stat_tgt_port_read_mbytes_show(struct config_item
*item
,
674 struct se_lun
*lun
= to_stat_tgt_port(item
);
675 struct se_device
*dev
;
676 ssize_t ret
= -ENODEV
;
679 dev
= rcu_dereference(lun
->lun_se_dev
);
681 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
682 (u32
)(atomic_long_read(&lun
->lun_stats
.tx_data_octets
) >> 20));
687 static ssize_t
target_stat_tgt_port_hs_in_cmds_show(struct config_item
*item
,
690 struct se_lun
*lun
= to_stat_tgt_port(item
);
691 struct se_device
*dev
;
692 ssize_t ret
= -ENODEV
;
695 dev
= rcu_dereference(lun
->lun_se_dev
);
697 /* FIXME: scsiTgtPortHsInCommands */
698 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
704 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, inst
);
705 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, dev
);
706 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, indx
);
707 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, name
);
708 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, port_index
);
709 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, in_cmds
);
710 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, write_mbytes
);
711 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, read_mbytes
);
712 CONFIGFS_ATTR_RO(target_stat_tgt_port_
, hs_in_cmds
);
714 static struct configfs_attribute
*target_stat_scsi_tgt_port_attrs
[] = {
715 &target_stat_tgt_port_attr_inst
,
716 &target_stat_tgt_port_attr_dev
,
717 &target_stat_tgt_port_attr_indx
,
718 &target_stat_tgt_port_attr_name
,
719 &target_stat_tgt_port_attr_port_index
,
720 &target_stat_tgt_port_attr_in_cmds
,
721 &target_stat_tgt_port_attr_write_mbytes
,
722 &target_stat_tgt_port_attr_read_mbytes
,
723 &target_stat_tgt_port_attr_hs_in_cmds
,
727 static const struct config_item_type target_stat_scsi_tgt_port_cit
= {
728 .ct_attrs
= target_stat_scsi_tgt_port_attrs
,
729 .ct_owner
= THIS_MODULE
,
733 * SCSI Transport Table
735 static struct se_lun
*to_transport_stat(struct config_item
*item
)
737 struct se_port_stat_grps
*pgrps
= container_of(to_config_group(item
),
738 struct se_port_stat_grps
, scsi_transport_group
);
739 return container_of(pgrps
, struct se_lun
, port_stat_grps
);
742 static ssize_t
target_stat_transport_inst_show(struct config_item
*item
,
745 struct se_lun
*lun
= to_transport_stat(item
);
746 struct se_device
*dev
;
747 ssize_t ret
= -ENODEV
;
750 dev
= rcu_dereference(lun
->lun_se_dev
);
752 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
757 static ssize_t
target_stat_transport_device_show(struct config_item
*item
,
760 struct se_lun
*lun
= to_transport_stat(item
);
761 struct se_device
*dev
;
762 struct se_portal_group
*tpg
= lun
->lun_tpg
;
763 ssize_t ret
= -ENODEV
;
766 dev
= rcu_dereference(lun
->lun_se_dev
);
768 /* scsiTransportType */
769 ret
= snprintf(page
, PAGE_SIZE
, "scsiTransport%s\n",
770 tpg
->se_tpg_tfo
->get_fabric_name());
776 static ssize_t
target_stat_transport_indx_show(struct config_item
*item
,
779 struct se_lun
*lun
= to_transport_stat(item
);
780 struct se_device
*dev
;
781 struct se_portal_group
*tpg
= lun
->lun_tpg
;
782 ssize_t ret
= -ENODEV
;
785 dev
= rcu_dereference(lun
->lun_se_dev
);
787 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
788 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
793 static ssize_t
target_stat_transport_dev_name_show(struct config_item
*item
,
796 struct se_lun
*lun
= to_transport_stat(item
);
797 struct se_device
*dev
;
798 struct se_portal_group
*tpg
= lun
->lun_tpg
;
800 ssize_t ret
= -ENODEV
;
803 dev
= rcu_dereference(lun
->lun_se_dev
);
806 /* scsiTransportDevName */
807 ret
= snprintf(page
, PAGE_SIZE
, "%s+%s\n",
808 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
809 (strlen(wwn
->unit_serial
)) ? wwn
->unit_serial
:
816 static ssize_t
target_stat_transport_proto_id_show(struct config_item
*item
,
819 struct se_lun
*lun
= to_transport_stat(item
);
820 struct se_device
*dev
;
821 struct se_portal_group
*tpg
= lun
->lun_tpg
;
822 ssize_t ret
= -ENODEV
;
825 dev
= rcu_dereference(lun
->lun_se_dev
);
827 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->proto_id
);
832 CONFIGFS_ATTR_RO(target_stat_transport_
, inst
);
833 CONFIGFS_ATTR_RO(target_stat_transport_
, device
);
834 CONFIGFS_ATTR_RO(target_stat_transport_
, indx
);
835 CONFIGFS_ATTR_RO(target_stat_transport_
, dev_name
);
836 CONFIGFS_ATTR_RO(target_stat_transport_
, proto_id
);
838 static struct configfs_attribute
*target_stat_scsi_transport_attrs
[] = {
839 &target_stat_transport_attr_inst
,
840 &target_stat_transport_attr_device
,
841 &target_stat_transport_attr_indx
,
842 &target_stat_transport_attr_dev_name
,
843 &target_stat_transport_attr_proto_id
,
847 static const struct config_item_type target_stat_scsi_transport_cit
= {
848 .ct_attrs
= target_stat_scsi_transport_attrs
,
849 .ct_owner
= THIS_MODULE
,
853 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
854 * the target port statistics groups + configfs CITs located in target_core_stat.c
856 void target_stat_setup_port_default_groups(struct se_lun
*lun
)
858 config_group_init_type_name(&lun
->port_stat_grps
.scsi_port_group
,
859 "scsi_port", &target_stat_scsi_port_cit
);
860 configfs_add_default_group(&lun
->port_stat_grps
.scsi_port_group
,
861 &lun
->port_stat_grps
.stat_group
);
863 config_group_init_type_name(&lun
->port_stat_grps
.scsi_tgt_port_group
,
864 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit
);
865 configfs_add_default_group(&lun
->port_stat_grps
.scsi_tgt_port_group
,
866 &lun
->port_stat_grps
.stat_group
);
868 config_group_init_type_name(&lun
->port_stat_grps
.scsi_transport_group
,
869 "scsi_transport", &target_stat_scsi_transport_cit
);
870 configfs_add_default_group(&lun
->port_stat_grps
.scsi_transport_group
,
871 &lun
->port_stat_grps
.stat_group
);
875 * SCSI Authorized Initiator Table
878 static struct se_lun_acl
*auth_to_lacl(struct config_item
*item
)
880 struct se_ml_stat_grps
*lgrps
= container_of(to_config_group(item
),
881 struct se_ml_stat_grps
, scsi_auth_intr_group
);
882 return container_of(lgrps
, struct se_lun_acl
, ml_stat_grps
);
885 static ssize_t
target_stat_auth_inst_show(struct config_item
*item
,
888 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
889 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
890 struct se_dev_entry
*deve
;
891 struct se_portal_group
*tpg
;
895 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
902 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
903 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
908 static ssize_t
target_stat_auth_dev_show(struct config_item
*item
,
911 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
912 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
913 struct se_dev_entry
*deve
;
918 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
923 lun
= rcu_dereference(deve
->se_lun
);
924 /* scsiDeviceIndex */
925 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_index
);
930 static ssize_t
target_stat_auth_port_show(struct config_item
*item
,
933 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
934 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
935 struct se_dev_entry
*deve
;
936 struct se_portal_group
*tpg
;
940 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
946 /* scsiAuthIntrTgtPortIndex */
947 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
952 static ssize_t
target_stat_auth_indx_show(struct config_item
*item
,
955 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
956 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
957 struct se_dev_entry
*deve
;
961 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
966 /* scsiAuthIntrIndex */
967 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
972 static ssize_t
target_stat_auth_dev_or_port_show(struct config_item
*item
,
975 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
976 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
977 struct se_dev_entry
*deve
;
981 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
986 /* scsiAuthIntrDevOrPort */
987 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 1);
992 static ssize_t
target_stat_auth_intr_name_show(struct config_item
*item
,
995 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
996 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
997 struct se_dev_entry
*deve
;
1001 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1006 /* scsiAuthIntrName */
1007 ret
= snprintf(page
, PAGE_SIZE
, "%s\n", nacl
->initiatorname
);
1012 static ssize_t
target_stat_auth_map_indx_show(struct config_item
*item
,
1015 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1016 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1017 struct se_dev_entry
*deve
;
1021 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1026 /* FIXME: scsiAuthIntrLunMapIndex */
1027 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1032 static ssize_t
target_stat_auth_att_count_show(struct config_item
*item
,
1035 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1036 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1037 struct se_dev_entry
*deve
;
1041 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1046 /* scsiAuthIntrAttachedTimes */
1047 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->attach_count
);
1052 static ssize_t
target_stat_auth_num_cmds_show(struct config_item
*item
,
1055 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1056 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1057 struct se_dev_entry
*deve
;
1061 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1066 /* scsiAuthIntrOutCommands */
1067 ret
= snprintf(page
, PAGE_SIZE
, "%lu\n",
1068 atomic_long_read(&deve
->total_cmds
));
1073 static ssize_t
target_stat_auth_read_mbytes_show(struct config_item
*item
,
1076 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1077 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1078 struct se_dev_entry
*deve
;
1082 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1087 /* scsiAuthIntrReadMegaBytes */
1088 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1089 (u32
)(atomic_long_read(&deve
->read_bytes
) >> 20));
1094 static ssize_t
target_stat_auth_write_mbytes_show(struct config_item
*item
,
1097 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1098 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1099 struct se_dev_entry
*deve
;
1103 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1108 /* scsiAuthIntrWrittenMegaBytes */
1109 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1110 (u32
)(atomic_long_read(&deve
->write_bytes
) >> 20));
1115 static ssize_t
target_stat_auth_hs_num_cmds_show(struct config_item
*item
,
1118 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1119 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1120 struct se_dev_entry
*deve
;
1124 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1129 /* FIXME: scsiAuthIntrHSOutCommands */
1130 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1135 static ssize_t
target_stat_auth_creation_time_show(struct config_item
*item
,
1138 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1139 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1140 struct se_dev_entry
*deve
;
1144 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1149 /* scsiAuthIntrLastCreation */
1150 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)deve
->creation_time
-
1151 INITIAL_JIFFIES
) * 100 / HZ
));
1156 static ssize_t
target_stat_auth_row_status_show(struct config_item
*item
,
1159 struct se_lun_acl
*lacl
= auth_to_lacl(item
);
1160 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1161 struct se_dev_entry
*deve
;
1165 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1170 /* FIXME: scsiAuthIntrRowStatus */
1171 ret
= snprintf(page
, PAGE_SIZE
, "Ready\n");
1176 CONFIGFS_ATTR_RO(target_stat_auth_
, inst
);
1177 CONFIGFS_ATTR_RO(target_stat_auth_
, dev
);
1178 CONFIGFS_ATTR_RO(target_stat_auth_
, port
);
1179 CONFIGFS_ATTR_RO(target_stat_auth_
, indx
);
1180 CONFIGFS_ATTR_RO(target_stat_auth_
, dev_or_port
);
1181 CONFIGFS_ATTR_RO(target_stat_auth_
, intr_name
);
1182 CONFIGFS_ATTR_RO(target_stat_auth_
, map_indx
);
1183 CONFIGFS_ATTR_RO(target_stat_auth_
, att_count
);
1184 CONFIGFS_ATTR_RO(target_stat_auth_
, num_cmds
);
1185 CONFIGFS_ATTR_RO(target_stat_auth_
, read_mbytes
);
1186 CONFIGFS_ATTR_RO(target_stat_auth_
, write_mbytes
);
1187 CONFIGFS_ATTR_RO(target_stat_auth_
, hs_num_cmds
);
1188 CONFIGFS_ATTR_RO(target_stat_auth_
, creation_time
);
1189 CONFIGFS_ATTR_RO(target_stat_auth_
, row_status
);
1191 static struct configfs_attribute
*target_stat_scsi_auth_intr_attrs
[] = {
1192 &target_stat_auth_attr_inst
,
1193 &target_stat_auth_attr_dev
,
1194 &target_stat_auth_attr_port
,
1195 &target_stat_auth_attr_indx
,
1196 &target_stat_auth_attr_dev_or_port
,
1197 &target_stat_auth_attr_intr_name
,
1198 &target_stat_auth_attr_map_indx
,
1199 &target_stat_auth_attr_att_count
,
1200 &target_stat_auth_attr_num_cmds
,
1201 &target_stat_auth_attr_read_mbytes
,
1202 &target_stat_auth_attr_write_mbytes
,
1203 &target_stat_auth_attr_hs_num_cmds
,
1204 &target_stat_auth_attr_creation_time
,
1205 &target_stat_auth_attr_row_status
,
1209 static const struct config_item_type target_stat_scsi_auth_intr_cit
= {
1210 .ct_attrs
= target_stat_scsi_auth_intr_attrs
,
1211 .ct_owner
= THIS_MODULE
,
1215 * SCSI Attached Initiator Port Table
1218 static struct se_lun_acl
*iport_to_lacl(struct config_item
*item
)
1220 struct se_ml_stat_grps
*lgrps
= container_of(to_config_group(item
),
1221 struct se_ml_stat_grps
, scsi_att_intr_port_group
);
1222 return container_of(lgrps
, struct se_lun_acl
, ml_stat_grps
);
1225 static ssize_t
target_stat_iport_inst_show(struct config_item
*item
,
1228 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1229 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1230 struct se_dev_entry
*deve
;
1231 struct se_portal_group
*tpg
;
1235 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1242 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1243 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
1248 static ssize_t
target_stat_iport_dev_show(struct config_item
*item
,
1251 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1252 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1253 struct se_dev_entry
*deve
;
1258 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1263 lun
= rcu_dereference(deve
->se_lun
);
1264 /* scsiDeviceIndex */
1265 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_index
);
1270 static ssize_t
target_stat_iport_port_show(struct config_item
*item
,
1273 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1274 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1275 struct se_dev_entry
*deve
;
1276 struct se_portal_group
*tpg
;
1280 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1287 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
1292 static ssize_t
target_stat_iport_indx_show(struct config_item
*item
,
1295 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1296 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1297 struct se_session
*se_sess
;
1298 struct se_portal_group
*tpg
;
1301 spin_lock_irq(&nacl
->nacl_sess_lock
);
1302 se_sess
= nacl
->nacl_sess
;
1304 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1309 /* scsiAttIntrPortIndex */
1310 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1311 tpg
->se_tpg_tfo
->sess_get_index(se_sess
));
1312 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1316 static ssize_t
target_stat_iport_port_auth_indx_show(struct config_item
*item
,
1319 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1320 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1321 struct se_dev_entry
*deve
;
1325 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1330 /* scsiAttIntrPortAuthIntrIdx */
1331 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
1336 static ssize_t
target_stat_iport_port_ident_show(struct config_item
*item
,
1339 struct se_lun_acl
*lacl
= iport_to_lacl(item
);
1340 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1341 struct se_session
*se_sess
;
1342 struct se_portal_group
*tpg
;
1344 unsigned char buf
[64];
1346 spin_lock_irq(&nacl
->nacl_sess_lock
);
1347 se_sess
= nacl
->nacl_sess
;
1349 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1354 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1356 if (tpg
->se_tpg_tfo
->sess_get_initiator_sid
!= NULL
)
1357 tpg
->se_tpg_tfo
->sess_get_initiator_sid(se_sess
, buf
, 64);
1359 ret
= snprintf(page
, PAGE_SIZE
, "%s+i+%s\n", nacl
->initiatorname
, buf
);
1360 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1364 CONFIGFS_ATTR_RO(target_stat_iport_
, inst
);
1365 CONFIGFS_ATTR_RO(target_stat_iport_
, dev
);
1366 CONFIGFS_ATTR_RO(target_stat_iport_
, port
);
1367 CONFIGFS_ATTR_RO(target_stat_iport_
, indx
);
1368 CONFIGFS_ATTR_RO(target_stat_iport_
, port_auth_indx
);
1369 CONFIGFS_ATTR_RO(target_stat_iport_
, port_ident
);
1371 static struct configfs_attribute
*target_stat_scsi_ath_intr_port_attrs
[] = {
1372 &target_stat_iport_attr_inst
,
1373 &target_stat_iport_attr_dev
,
1374 &target_stat_iport_attr_port
,
1375 &target_stat_iport_attr_indx
,
1376 &target_stat_iport_attr_port_auth_indx
,
1377 &target_stat_iport_attr_port_ident
,
1381 static const struct config_item_type target_stat_scsi_att_intr_port_cit
= {
1382 .ct_attrs
= target_stat_scsi_ath_intr_port_attrs
,
1383 .ct_owner
= THIS_MODULE
,
1387 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1388 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1390 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl
*lacl
)
1392 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_auth_intr_group
,
1393 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit
);
1394 configfs_add_default_group(&lacl
->ml_stat_grps
.scsi_auth_intr_group
,
1395 &lacl
->ml_stat_grps
.stat_group
);
1397 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_att_intr_port_group
,
1398 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit
);
1399 configfs_add_default_group(&lacl
->ml_stat_grps
.scsi_att_intr_port_group
,
1400 &lacl
->ml_stat_grps
.stat_group
);