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>
40 #include <target/configfs_macros.h>
42 #include "target_core_internal.h"
44 #ifndef INITIAL_JIFFIES
45 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
49 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
51 #define SCSI_LU_INDEX 1
58 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev
, se_dev_stat_grps
);
59 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
60 static struct target_stat_scsi_dev_attribute \
61 target_stat_scsi_dev_##_name = \
62 __CONFIGFS_EATTR(_name, _mode, \
63 target_stat_scsi_dev_show_attr_##_name, \
64 target_stat_scsi_dev_store_attr_##_name);
66 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
67 static struct target_stat_scsi_dev_attribute \
68 target_stat_scsi_dev_##_name = \
69 __CONFIGFS_EATTR_RO(_name, \
70 target_stat_scsi_dev_show_attr_##_name);
72 static ssize_t
target_stat_scsi_dev_show_attr_inst(
73 struct se_dev_stat_grps
*sgrps
, char *page
)
75 struct se_device
*dev
=
76 container_of(sgrps
, struct se_device
, dev_stat_grps
);
77 struct se_hba
*hba
= dev
->se_hba
;
79 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
81 DEV_STAT_SCSI_DEV_ATTR_RO(inst
);
83 static ssize_t
target_stat_scsi_dev_show_attr_indx(
84 struct se_dev_stat_grps
*sgrps
, char *page
)
86 struct se_device
*dev
=
87 container_of(sgrps
, struct se_device
, dev_stat_grps
);
89 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
91 DEV_STAT_SCSI_DEV_ATTR_RO(indx
);
93 static ssize_t
target_stat_scsi_dev_show_attr_role(
94 struct se_dev_stat_grps
*sgrps
, char *page
)
96 return snprintf(page
, PAGE_SIZE
, "Target\n");
98 DEV_STAT_SCSI_DEV_ATTR_RO(role
);
100 static ssize_t
target_stat_scsi_dev_show_attr_ports(
101 struct se_dev_stat_grps
*sgrps
, char *page
)
103 struct se_device
*dev
=
104 container_of(sgrps
, struct se_device
, dev_stat_grps
);
106 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->export_count
);
108 DEV_STAT_SCSI_DEV_ATTR_RO(ports
);
110 CONFIGFS_EATTR_OPS(target_stat_scsi_dev
, se_dev_stat_grps
, scsi_dev_group
);
112 static struct configfs_attribute
*target_stat_scsi_dev_attrs
[] = {
113 &target_stat_scsi_dev_inst
.attr
,
114 &target_stat_scsi_dev_indx
.attr
,
115 &target_stat_scsi_dev_role
.attr
,
116 &target_stat_scsi_dev_ports
.attr
,
120 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops
= {
121 .show_attribute
= target_stat_scsi_dev_attr_show
,
122 .store_attribute
= target_stat_scsi_dev_attr_store
,
125 static struct config_item_type target_stat_scsi_dev_cit
= {
126 .ct_item_ops
= &target_stat_scsi_dev_attrib_ops
,
127 .ct_attrs
= target_stat_scsi_dev_attrs
,
128 .ct_owner
= THIS_MODULE
,
132 * SCSI Target Device Table
135 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev
, se_dev_stat_grps
);
136 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
137 static struct target_stat_scsi_tgt_dev_attribute \
138 target_stat_scsi_tgt_dev_##_name = \
139 __CONFIGFS_EATTR(_name, _mode, \
140 target_stat_scsi_tgt_dev_show_attr_##_name, \
141 target_stat_scsi_tgt_dev_store_attr_##_name);
143 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
144 static struct target_stat_scsi_tgt_dev_attribute \
145 target_stat_scsi_tgt_dev_##_name = \
146 __CONFIGFS_EATTR_RO(_name, \
147 target_stat_scsi_tgt_dev_show_attr_##_name);
149 static ssize_t
target_stat_scsi_tgt_dev_show_attr_inst(
150 struct se_dev_stat_grps
*sgrps
, char *page
)
152 struct se_device
*dev
=
153 container_of(sgrps
, struct se_device
, dev_stat_grps
);
154 struct se_hba
*hba
= dev
->se_hba
;
156 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
158 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst
);
160 static ssize_t
target_stat_scsi_tgt_dev_show_attr_indx(
161 struct se_dev_stat_grps
*sgrps
, char *page
)
163 struct se_device
*dev
=
164 container_of(sgrps
, struct se_device
, dev_stat_grps
);
166 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
168 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx
);
170 static ssize_t
target_stat_scsi_tgt_dev_show_attr_num_lus(
171 struct se_dev_stat_grps
*sgrps
, char *page
)
173 return snprintf(page
, PAGE_SIZE
, "%u\n", LU_COUNT
);
175 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus
);
177 static ssize_t
target_stat_scsi_tgt_dev_show_attr_status(
178 struct se_dev_stat_grps
*sgrps
, char *page
)
180 struct se_device
*dev
=
181 container_of(sgrps
, struct se_device
, dev_stat_grps
);
183 if (dev
->export_count
)
184 return snprintf(page
, PAGE_SIZE
, "activated");
186 return snprintf(page
, PAGE_SIZE
, "deactivated");
188 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status
);
190 static ssize_t
target_stat_scsi_tgt_dev_show_attr_non_access_lus(
191 struct se_dev_stat_grps
*sgrps
, char *page
)
193 struct se_device
*dev
=
194 container_of(sgrps
, struct se_device
, dev_stat_grps
);
195 int non_accessible_lus
;
197 if (dev
->export_count
)
198 non_accessible_lus
= 0;
200 non_accessible_lus
= 1;
202 return snprintf(page
, PAGE_SIZE
, "%u\n", non_accessible_lus
);
204 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus
);
206 static ssize_t
target_stat_scsi_tgt_dev_show_attr_resets(
207 struct se_dev_stat_grps
*sgrps
, char *page
)
209 struct se_device
*dev
=
210 container_of(sgrps
, struct se_device
, dev_stat_grps
);
212 return snprintf(page
, PAGE_SIZE
, "%lu\n",
213 atomic_long_read(&dev
->num_resets
));
215 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets
);
218 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev
, se_dev_stat_grps
, scsi_tgt_dev_group
);
220 static struct configfs_attribute
*target_stat_scsi_tgt_dev_attrs
[] = {
221 &target_stat_scsi_tgt_dev_inst
.attr
,
222 &target_stat_scsi_tgt_dev_indx
.attr
,
223 &target_stat_scsi_tgt_dev_num_lus
.attr
,
224 &target_stat_scsi_tgt_dev_status
.attr
,
225 &target_stat_scsi_tgt_dev_non_access_lus
.attr
,
226 &target_stat_scsi_tgt_dev_resets
.attr
,
230 static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops
= {
231 .show_attribute
= target_stat_scsi_tgt_dev_attr_show
,
232 .store_attribute
= target_stat_scsi_tgt_dev_attr_store
,
235 static struct config_item_type target_stat_scsi_tgt_dev_cit
= {
236 .ct_item_ops
= &target_stat_scsi_tgt_dev_attrib_ops
,
237 .ct_attrs
= target_stat_scsi_tgt_dev_attrs
,
238 .ct_owner
= THIS_MODULE
,
242 * SCSI Logical Unit Table
245 CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu
, se_dev_stat_grps
);
246 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
247 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
248 __CONFIGFS_EATTR(_name, _mode, \
249 target_stat_scsi_lu_show_attr_##_name, \
250 target_stat_scsi_lu_store_attr_##_name);
252 #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
253 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
254 __CONFIGFS_EATTR_RO(_name, \
255 target_stat_scsi_lu_show_attr_##_name);
257 static ssize_t
target_stat_scsi_lu_show_attr_inst(
258 struct se_dev_stat_grps
*sgrps
, char *page
)
260 struct se_device
*dev
=
261 container_of(sgrps
, struct se_device
, dev_stat_grps
);
262 struct se_hba
*hba
= dev
->se_hba
;
264 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
266 DEV_STAT_SCSI_LU_ATTR_RO(inst
);
268 static ssize_t
target_stat_scsi_lu_show_attr_dev(
269 struct se_dev_stat_grps
*sgrps
, char *page
)
271 struct se_device
*dev
=
272 container_of(sgrps
, struct se_device
, dev_stat_grps
);
274 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
276 DEV_STAT_SCSI_LU_ATTR_RO(dev
);
278 static ssize_t
target_stat_scsi_lu_show_attr_indx(
279 struct se_dev_stat_grps
*sgrps
, char *page
)
281 return snprintf(page
, PAGE_SIZE
, "%u\n", SCSI_LU_INDEX
);
283 DEV_STAT_SCSI_LU_ATTR_RO(indx
);
285 static ssize_t
target_stat_scsi_lu_show_attr_lun(
286 struct se_dev_stat_grps
*sgrps
, char *page
)
288 /* FIXME: scsiLuDefaultLun */
289 return snprintf(page
, PAGE_SIZE
, "%llu\n", (unsigned long long)0);
291 DEV_STAT_SCSI_LU_ATTR_RO(lun
);
293 static ssize_t
target_stat_scsi_lu_show_attr_lu_name(
294 struct se_dev_stat_grps
*sgrps
, char *page
)
296 struct se_device
*dev
=
297 container_of(sgrps
, struct se_device
, dev_stat_grps
);
300 return snprintf(page
, PAGE_SIZE
, "%s\n",
301 (strlen(dev
->t10_wwn
.unit_serial
)) ?
302 dev
->t10_wwn
.unit_serial
: "None");
304 DEV_STAT_SCSI_LU_ATTR_RO(lu_name
);
306 static ssize_t
target_stat_scsi_lu_show_attr_vend(
307 struct se_dev_stat_grps
*sgrps
, char *page
)
309 struct se_device
*dev
=
310 container_of(sgrps
, struct se_device
, dev_stat_grps
);
312 char str
[sizeof(dev
->t10_wwn
.vendor
)+1];
315 for (i
= 0; i
< sizeof(dev
->t10_wwn
.vendor
); i
++)
316 str
[i
] = ISPRINT(dev
->t10_wwn
.vendor
[i
]) ?
317 dev
->t10_wwn
.vendor
[i
] : ' ';
319 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
321 DEV_STAT_SCSI_LU_ATTR_RO(vend
);
323 static ssize_t
target_stat_scsi_lu_show_attr_prod(
324 struct se_dev_stat_grps
*sgrps
, char *page
)
326 struct se_device
*dev
=
327 container_of(sgrps
, struct se_device
, dev_stat_grps
);
329 char str
[sizeof(dev
->t10_wwn
.model
)+1];
331 /* scsiLuProductId */
332 for (i
= 0; i
< sizeof(dev
->t10_wwn
.vendor
); i
++)
333 str
[i
] = ISPRINT(dev
->t10_wwn
.model
[i
]) ?
334 dev
->t10_wwn
.model
[i
] : ' ';
336 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
338 DEV_STAT_SCSI_LU_ATTR_RO(prod
);
340 static ssize_t
target_stat_scsi_lu_show_attr_rev(
341 struct se_dev_stat_grps
*sgrps
, char *page
)
343 struct se_device
*dev
=
344 container_of(sgrps
, struct se_device
, dev_stat_grps
);
346 char str
[sizeof(dev
->t10_wwn
.revision
)+1];
348 /* scsiLuRevisionId */
349 for (i
= 0; i
< sizeof(dev
->t10_wwn
.revision
); i
++)
350 str
[i
] = ISPRINT(dev
->t10_wwn
.revision
[i
]) ?
351 dev
->t10_wwn
.revision
[i
] : ' ';
353 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
355 DEV_STAT_SCSI_LU_ATTR_RO(rev
);
357 static ssize_t
target_stat_scsi_lu_show_attr_dev_type(
358 struct se_dev_stat_grps
*sgrps
, char *page
)
360 struct se_device
*dev
=
361 container_of(sgrps
, struct se_device
, dev_stat_grps
);
363 /* scsiLuPeripheralType */
364 return snprintf(page
, PAGE_SIZE
, "%u\n",
365 dev
->transport
->get_device_type(dev
));
367 DEV_STAT_SCSI_LU_ATTR_RO(dev_type
);
369 static ssize_t
target_stat_scsi_lu_show_attr_status(
370 struct se_dev_stat_grps
*sgrps
, char *page
)
372 struct se_device
*dev
=
373 container_of(sgrps
, struct se_device
, dev_stat_grps
);
376 return snprintf(page
, PAGE_SIZE
, "%s\n",
377 (dev
->export_count
) ? "available" : "notavailable");
379 DEV_STAT_SCSI_LU_ATTR_RO(status
);
381 static ssize_t
target_stat_scsi_lu_show_attr_state_bit(
382 struct se_dev_stat_grps
*sgrps
, char *page
)
385 return snprintf(page
, PAGE_SIZE
, "exposed\n");
387 DEV_STAT_SCSI_LU_ATTR_RO(state_bit
);
389 static ssize_t
target_stat_scsi_lu_show_attr_num_cmds(
390 struct se_dev_stat_grps
*sgrps
, char *page
)
392 struct se_device
*dev
=
393 container_of(sgrps
, struct se_device
, dev_stat_grps
);
395 /* scsiLuNumCommands */
396 return snprintf(page
, PAGE_SIZE
, "%lu\n",
397 atomic_long_read(&dev
->num_cmds
));
399 DEV_STAT_SCSI_LU_ATTR_RO(num_cmds
);
401 static ssize_t
target_stat_scsi_lu_show_attr_read_mbytes(
402 struct se_dev_stat_grps
*sgrps
, char *page
)
404 struct se_device
*dev
=
405 container_of(sgrps
, struct se_device
, dev_stat_grps
);
407 /* scsiLuReadMegaBytes */
408 return snprintf(page
, PAGE_SIZE
, "%lu\n",
409 atomic_long_read(&dev
->read_bytes
) >> 20);
411 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes
);
413 static ssize_t
target_stat_scsi_lu_show_attr_write_mbytes(
414 struct se_dev_stat_grps
*sgrps
, char *page
)
416 struct se_device
*dev
=
417 container_of(sgrps
, struct se_device
, dev_stat_grps
);
419 /* scsiLuWrittenMegaBytes */
420 return snprintf(page
, PAGE_SIZE
, "%lu\n",
421 atomic_long_read(&dev
->write_bytes
) >> 20);
423 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes
);
425 static ssize_t
target_stat_scsi_lu_show_attr_resets(
426 struct se_dev_stat_grps
*sgrps
, char *page
)
428 struct se_device
*dev
=
429 container_of(sgrps
, struct se_device
, dev_stat_grps
);
432 return snprintf(page
, PAGE_SIZE
, "%lu\n", atomic_long_read(&dev
->num_resets
));
434 DEV_STAT_SCSI_LU_ATTR_RO(resets
);
436 static ssize_t
target_stat_scsi_lu_show_attr_full_stat(
437 struct se_dev_stat_grps
*sgrps
, char *page
)
439 /* FIXME: scsiLuOutTaskSetFullStatus */
440 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
442 DEV_STAT_SCSI_LU_ATTR_RO(full_stat
);
444 static ssize_t
target_stat_scsi_lu_show_attr_hs_num_cmds(
445 struct se_dev_stat_grps
*sgrps
, char *page
)
447 /* FIXME: scsiLuHSInCommands */
448 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
450 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds
);
452 static ssize_t
target_stat_scsi_lu_show_attr_creation_time(
453 struct se_dev_stat_grps
*sgrps
, char *page
)
455 struct se_device
*dev
=
456 container_of(sgrps
, struct se_device
, dev_stat_grps
);
458 /* scsiLuCreationTime */
459 return snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)dev
->creation_time
-
460 INITIAL_JIFFIES
) * 100 / HZ
));
462 DEV_STAT_SCSI_LU_ATTR_RO(creation_time
);
464 CONFIGFS_EATTR_OPS(target_stat_scsi_lu
, se_dev_stat_grps
, scsi_lu_group
);
466 static struct configfs_attribute
*target_stat_scsi_lu_attrs
[] = {
467 &target_stat_scsi_lu_inst
.attr
,
468 &target_stat_scsi_lu_dev
.attr
,
469 &target_stat_scsi_lu_indx
.attr
,
470 &target_stat_scsi_lu_lun
.attr
,
471 &target_stat_scsi_lu_lu_name
.attr
,
472 &target_stat_scsi_lu_vend
.attr
,
473 &target_stat_scsi_lu_prod
.attr
,
474 &target_stat_scsi_lu_rev
.attr
,
475 &target_stat_scsi_lu_dev_type
.attr
,
476 &target_stat_scsi_lu_status
.attr
,
477 &target_stat_scsi_lu_state_bit
.attr
,
478 &target_stat_scsi_lu_num_cmds
.attr
,
479 &target_stat_scsi_lu_read_mbytes
.attr
,
480 &target_stat_scsi_lu_write_mbytes
.attr
,
481 &target_stat_scsi_lu_resets
.attr
,
482 &target_stat_scsi_lu_full_stat
.attr
,
483 &target_stat_scsi_lu_hs_num_cmds
.attr
,
484 &target_stat_scsi_lu_creation_time
.attr
,
488 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops
= {
489 .show_attribute
= target_stat_scsi_lu_attr_show
,
490 .store_attribute
= target_stat_scsi_lu_attr_store
,
493 static struct config_item_type target_stat_scsi_lu_cit
= {
494 .ct_item_ops
= &target_stat_scsi_lu_attrib_ops
,
495 .ct_attrs
= target_stat_scsi_lu_attrs
,
496 .ct_owner
= THIS_MODULE
,
500 * Called from target_core_configfs.c:target_core_make_subdev() to setup
501 * the target statistics groups + configfs CITs located in target_core_stat.c
503 void target_stat_setup_dev_default_groups(struct se_device
*dev
)
505 struct config_group
*dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
507 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_dev_group
,
508 "scsi_dev", &target_stat_scsi_dev_cit
);
509 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_tgt_dev_group
,
510 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit
);
511 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_lu_group
,
512 "scsi_lu", &target_stat_scsi_lu_cit
);
514 dev_stat_grp
->default_groups
[0] = &dev
->dev_stat_grps
.scsi_dev_group
;
515 dev_stat_grp
->default_groups
[1] = &dev
->dev_stat_grps
.scsi_tgt_dev_group
;
516 dev_stat_grp
->default_groups
[2] = &dev
->dev_stat_grps
.scsi_lu_group
;
517 dev_stat_grp
->default_groups
[3] = NULL
;
524 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port
, se_port_stat_grps
);
525 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
526 static struct target_stat_scsi_port_attribute \
527 target_stat_scsi_port_##_name = \
528 __CONFIGFS_EATTR(_name, _mode, \
529 target_stat_scsi_port_show_attr_##_name, \
530 target_stat_scsi_port_store_attr_##_name);
532 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
533 static struct target_stat_scsi_port_attribute \
534 target_stat_scsi_port_##_name = \
535 __CONFIGFS_EATTR_RO(_name, \
536 target_stat_scsi_port_show_attr_##_name);
538 static ssize_t
target_stat_scsi_port_show_attr_inst(
539 struct se_port_stat_grps
*pgrps
, char *page
)
541 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
542 struct se_device
*dev
;
543 ssize_t ret
= -ENODEV
;
546 dev
= rcu_dereference(lun
->lun_se_dev
);
548 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
552 DEV_STAT_SCSI_PORT_ATTR_RO(inst
);
554 static ssize_t
target_stat_scsi_port_show_attr_dev(
555 struct se_port_stat_grps
*pgrps
, char *page
)
557 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
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", dev
->dev_index
);
568 DEV_STAT_SCSI_PORT_ATTR_RO(dev
);
570 static ssize_t
target_stat_scsi_port_show_attr_indx(
571 struct se_port_stat_grps
*pgrps
, char *page
)
573 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
574 struct se_device
*dev
;
575 ssize_t ret
= -ENODEV
;
578 dev
= rcu_dereference(lun
->lun_se_dev
);
580 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_rtpi
);
584 DEV_STAT_SCSI_PORT_ATTR_RO(indx
);
586 static ssize_t
target_stat_scsi_port_show_attr_role(
587 struct se_port_stat_grps
*pgrps
, char *page
)
589 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
590 struct se_device
*dev
;
591 ssize_t ret
= -ENODEV
;
594 dev
= rcu_dereference(lun
->lun_se_dev
);
596 ret
= snprintf(page
, PAGE_SIZE
, "%s%u\n", "Device", dev
->dev_index
);
600 DEV_STAT_SCSI_PORT_ATTR_RO(role
);
602 static ssize_t
target_stat_scsi_port_show_attr_busy_count(
603 struct se_port_stat_grps
*pgrps
, char *page
)
605 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
606 struct se_device
*dev
;
607 ssize_t ret
= -ENODEV
;
610 dev
= rcu_dereference(lun
->lun_se_dev
);
612 /* FIXME: scsiPortBusyStatuses */
613 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
618 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count
);
620 CONFIGFS_EATTR_OPS(target_stat_scsi_port
, se_port_stat_grps
, scsi_port_group
);
622 static struct configfs_attribute
*target_stat_scsi_port_attrs
[] = {
623 &target_stat_scsi_port_inst
.attr
,
624 &target_stat_scsi_port_dev
.attr
,
625 &target_stat_scsi_port_indx
.attr
,
626 &target_stat_scsi_port_role
.attr
,
627 &target_stat_scsi_port_busy_count
.attr
,
631 static struct configfs_item_operations target_stat_scsi_port_attrib_ops
= {
632 .show_attribute
= target_stat_scsi_port_attr_show
,
633 .store_attribute
= target_stat_scsi_port_attr_store
,
636 static struct config_item_type target_stat_scsi_port_cit
= {
637 .ct_item_ops
= &target_stat_scsi_port_attrib_ops
,
638 .ct_attrs
= target_stat_scsi_port_attrs
,
639 .ct_owner
= THIS_MODULE
,
643 * SCSI Target Port Table
645 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port
, se_port_stat_grps
);
646 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
647 static struct target_stat_scsi_tgt_port_attribute \
648 target_stat_scsi_tgt_port_##_name = \
649 __CONFIGFS_EATTR(_name, _mode, \
650 target_stat_scsi_tgt_port_show_attr_##_name, \
651 target_stat_scsi_tgt_port_store_attr_##_name);
653 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
654 static struct target_stat_scsi_tgt_port_attribute \
655 target_stat_scsi_tgt_port_##_name = \
656 __CONFIGFS_EATTR_RO(_name, \
657 target_stat_scsi_tgt_port_show_attr_##_name);
659 static ssize_t
target_stat_scsi_tgt_port_show_attr_inst(
660 struct se_port_stat_grps
*pgrps
, char *page
)
662 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
663 struct se_device
*dev
;
664 ssize_t ret
= -ENODEV
;
667 dev
= rcu_dereference(lun
->lun_se_dev
);
669 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
673 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst
);
675 static ssize_t
target_stat_scsi_tgt_port_show_attr_dev(
676 struct se_port_stat_grps
*pgrps
, char *page
)
678 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
679 struct se_device
*dev
;
680 ssize_t ret
= -ENODEV
;
683 dev
= rcu_dereference(lun
->lun_se_dev
);
685 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
689 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev
);
691 static ssize_t
target_stat_scsi_tgt_port_show_attr_indx(
692 struct se_port_stat_grps
*pgrps
, char *page
)
694 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
695 struct se_device
*dev
;
696 ssize_t ret
= -ENODEV
;
699 dev
= rcu_dereference(lun
->lun_se_dev
);
701 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_rtpi
);
705 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx
);
707 static ssize_t
target_stat_scsi_tgt_port_show_attr_name(
708 struct se_port_stat_grps
*pgrps
, char *page
)
710 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
711 struct se_portal_group
*tpg
= lun
->lun_tpg
;
712 struct se_device
*dev
;
713 ssize_t ret
= -ENODEV
;
716 dev
= rcu_dereference(lun
->lun_se_dev
);
718 ret
= snprintf(page
, PAGE_SIZE
, "%sPort#%u\n",
719 tpg
->se_tpg_tfo
->get_fabric_name(),
724 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name
);
726 static ssize_t
target_stat_scsi_tgt_port_show_attr_port_index(
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_portal_group
*tpg
= lun
->lun_tpg
;
731 struct se_device
*dev
;
732 ssize_t ret
= -ENODEV
;
735 dev
= rcu_dereference(lun
->lun_se_dev
);
737 ret
= snprintf(page
, PAGE_SIZE
, "%s%s%d\n",
738 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
), "+t+",
739 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
743 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index
);
745 static ssize_t
target_stat_scsi_tgt_port_show_attr_in_cmds(
746 struct se_port_stat_grps
*pgrps
, char *page
)
748 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
749 struct se_device
*dev
;
750 ssize_t ret
= -ENODEV
;
753 dev
= rcu_dereference(lun
->lun_se_dev
);
755 ret
= snprintf(page
, PAGE_SIZE
, "%lu\n",
756 atomic_long_read(&lun
->lun_stats
.cmd_pdus
));
760 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds
);
762 static ssize_t
target_stat_scsi_tgt_port_show_attr_write_mbytes(
763 struct se_port_stat_grps
*pgrps
, char *page
)
765 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
766 struct se_device
*dev
;
767 ssize_t ret
= -ENODEV
;
770 dev
= rcu_dereference(lun
->lun_se_dev
);
772 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
773 (u32
)(atomic_long_read(&lun
->lun_stats
.rx_data_octets
) >> 20));
777 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes
);
779 static ssize_t
target_stat_scsi_tgt_port_show_attr_read_mbytes(
780 struct se_port_stat_grps
*pgrps
, char *page
)
782 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
783 struct se_device
*dev
;
784 ssize_t ret
= -ENODEV
;
787 dev
= rcu_dereference(lun
->lun_se_dev
);
789 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
790 (u32
)(atomic_long_read(&lun
->lun_stats
.tx_data_octets
) >> 20));
794 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes
);
796 static ssize_t
target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
797 struct se_port_stat_grps
*pgrps
, char *page
)
799 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
800 struct se_device
*dev
;
801 ssize_t ret
= -ENODEV
;
804 dev
= rcu_dereference(lun
->lun_se_dev
);
806 /* FIXME: scsiTgtPortHsInCommands */
807 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
812 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds
);
814 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port
, se_port_stat_grps
,
815 scsi_tgt_port_group
);
817 static struct configfs_attribute
*target_stat_scsi_tgt_port_attrs
[] = {
818 &target_stat_scsi_tgt_port_inst
.attr
,
819 &target_stat_scsi_tgt_port_dev
.attr
,
820 &target_stat_scsi_tgt_port_indx
.attr
,
821 &target_stat_scsi_tgt_port_name
.attr
,
822 &target_stat_scsi_tgt_port_port_index
.attr
,
823 &target_stat_scsi_tgt_port_in_cmds
.attr
,
824 &target_stat_scsi_tgt_port_write_mbytes
.attr
,
825 &target_stat_scsi_tgt_port_read_mbytes
.attr
,
826 &target_stat_scsi_tgt_port_hs_in_cmds
.attr
,
830 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops
= {
831 .show_attribute
= target_stat_scsi_tgt_port_attr_show
,
832 .store_attribute
= target_stat_scsi_tgt_port_attr_store
,
835 static struct config_item_type target_stat_scsi_tgt_port_cit
= {
836 .ct_item_ops
= &target_stat_scsi_tgt_port_attrib_ops
,
837 .ct_attrs
= target_stat_scsi_tgt_port_attrs
,
838 .ct_owner
= THIS_MODULE
,
842 * SCSI Transport Table
845 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport
, se_port_stat_grps
);
846 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
847 static struct target_stat_scsi_transport_attribute \
848 target_stat_scsi_transport_##_name = \
849 __CONFIGFS_EATTR(_name, _mode, \
850 target_stat_scsi_transport_show_attr_##_name, \
851 target_stat_scsi_transport_store_attr_##_name);
853 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
854 static struct target_stat_scsi_transport_attribute \
855 target_stat_scsi_transport_##_name = \
856 __CONFIGFS_EATTR_RO(_name, \
857 target_stat_scsi_transport_show_attr_##_name);
859 static ssize_t
target_stat_scsi_transport_show_attr_inst(
860 struct se_port_stat_grps
*pgrps
, char *page
)
862 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
863 struct se_device
*dev
;
864 ssize_t ret
= -ENODEV
;
867 dev
= rcu_dereference(lun
->lun_se_dev
);
869 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->hba_index
);
873 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst
);
875 static ssize_t
target_stat_scsi_transport_show_attr_device(
876 struct se_port_stat_grps
*pgrps
, char *page
)
878 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
879 struct se_device
*dev
;
880 struct se_portal_group
*tpg
= lun
->lun_tpg
;
881 ssize_t ret
= -ENODEV
;
884 dev
= rcu_dereference(lun
->lun_se_dev
);
886 /* scsiTransportType */
887 ret
= snprintf(page
, PAGE_SIZE
, "scsiTransport%s\n",
888 tpg
->se_tpg_tfo
->get_fabric_name());
893 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device
);
895 static ssize_t
target_stat_scsi_transport_show_attr_indx(
896 struct se_port_stat_grps
*pgrps
, char *page
)
898 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
899 struct se_device
*dev
;
900 struct se_portal_group
*tpg
= lun
->lun_tpg
;
901 ssize_t ret
= -ENODEV
;
904 dev
= rcu_dereference(lun
->lun_se_dev
);
906 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
907 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
911 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx
);
913 static ssize_t
target_stat_scsi_transport_show_attr_dev_name(
914 struct se_port_stat_grps
*pgrps
, char *page
)
916 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
917 struct se_device
*dev
;
918 struct se_portal_group
*tpg
= lun
->lun_tpg
;
920 ssize_t ret
= -ENODEV
;
923 dev
= rcu_dereference(lun
->lun_se_dev
);
926 /* scsiTransportDevName */
927 ret
= snprintf(page
, PAGE_SIZE
, "%s+%s\n",
928 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
929 (strlen(wwn
->unit_serial
)) ? wwn
->unit_serial
:
935 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name
);
937 CONFIGFS_EATTR_OPS(target_stat_scsi_transport
, se_port_stat_grps
,
938 scsi_transport_group
);
940 static struct configfs_attribute
*target_stat_scsi_transport_attrs
[] = {
941 &target_stat_scsi_transport_inst
.attr
,
942 &target_stat_scsi_transport_device
.attr
,
943 &target_stat_scsi_transport_indx
.attr
,
944 &target_stat_scsi_transport_dev_name
.attr
,
948 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops
= {
949 .show_attribute
= target_stat_scsi_transport_attr_show
,
950 .store_attribute
= target_stat_scsi_transport_attr_store
,
953 static struct config_item_type target_stat_scsi_transport_cit
= {
954 .ct_item_ops
= &target_stat_scsi_transport_attrib_ops
,
955 .ct_attrs
= target_stat_scsi_transport_attrs
,
956 .ct_owner
= THIS_MODULE
,
960 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
961 * the target port statistics groups + configfs CITs located in target_core_stat.c
963 void target_stat_setup_port_default_groups(struct se_lun
*lun
)
965 struct config_group
*port_stat_grp
= &lun
->port_stat_grps
.stat_group
;
967 config_group_init_type_name(&lun
->port_stat_grps
.scsi_port_group
,
968 "scsi_port", &target_stat_scsi_port_cit
);
969 config_group_init_type_name(&lun
->port_stat_grps
.scsi_tgt_port_group
,
970 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit
);
971 config_group_init_type_name(&lun
->port_stat_grps
.scsi_transport_group
,
972 "scsi_transport", &target_stat_scsi_transport_cit
);
974 port_stat_grp
->default_groups
[0] = &lun
->port_stat_grps
.scsi_port_group
;
975 port_stat_grp
->default_groups
[1] = &lun
->port_stat_grps
.scsi_tgt_port_group
;
976 port_stat_grp
->default_groups
[2] = &lun
->port_stat_grps
.scsi_transport_group
;
977 port_stat_grp
->default_groups
[3] = NULL
;
981 * SCSI Authorized Initiator Table
984 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr
, se_ml_stat_grps
);
985 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
986 static struct target_stat_scsi_auth_intr_attribute \
987 target_stat_scsi_auth_intr_##_name = \
988 __CONFIGFS_EATTR(_name, _mode, \
989 target_stat_scsi_auth_intr_show_attr_##_name, \
990 target_stat_scsi_auth_intr_store_attr_##_name);
992 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
993 static struct target_stat_scsi_auth_intr_attribute \
994 target_stat_scsi_auth_intr_##_name = \
995 __CONFIGFS_EATTR_RO(_name, \
996 target_stat_scsi_auth_intr_show_attr_##_name);
998 static ssize_t
target_stat_scsi_auth_intr_show_attr_inst(
999 struct se_ml_stat_grps
*lgrps
, char *page
)
1001 struct se_lun_acl
*lacl
= container_of(lgrps
,
1002 struct se_lun_acl
, ml_stat_grps
);
1003 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1004 struct se_dev_entry
*deve
;
1005 struct se_portal_group
*tpg
;
1009 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1016 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1017 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
1021 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst
);
1023 static ssize_t
target_stat_scsi_auth_intr_show_attr_dev(
1024 struct se_ml_stat_grps
*lgrps
, char *page
)
1026 struct se_lun_acl
*lacl
= container_of(lgrps
,
1027 struct se_lun_acl
, ml_stat_grps
);
1028 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1029 struct se_dev_entry
*deve
;
1034 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1039 lun
= rcu_dereference(deve
->se_lun
);
1040 /* scsiDeviceIndex */
1041 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_index
);
1045 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev
);
1047 static ssize_t
target_stat_scsi_auth_intr_show_attr_port(
1048 struct se_ml_stat_grps
*lgrps
, char *page
)
1050 struct se_lun_acl
*lacl
= container_of(lgrps
,
1051 struct se_lun_acl
, ml_stat_grps
);
1052 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1053 struct se_dev_entry
*deve
;
1054 struct se_portal_group
*tpg
;
1058 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1064 /* scsiAuthIntrTgtPortIndex */
1065 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
1069 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port
);
1071 static ssize_t
target_stat_scsi_auth_intr_show_attr_indx(
1072 struct se_ml_stat_grps
*lgrps
, char *page
)
1074 struct se_lun_acl
*lacl
= container_of(lgrps
,
1075 struct se_lun_acl
, ml_stat_grps
);
1076 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1077 struct se_dev_entry
*deve
;
1081 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1086 /* scsiAuthIntrIndex */
1087 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
1091 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx
);
1093 static ssize_t
target_stat_scsi_auth_intr_show_attr_dev_or_port(
1094 struct se_ml_stat_grps
*lgrps
, char *page
)
1096 struct se_lun_acl
*lacl
= container_of(lgrps
,
1097 struct se_lun_acl
, ml_stat_grps
);
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 /* scsiAuthIntrDevOrPort */
1109 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 1);
1113 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port
);
1115 static ssize_t
target_stat_scsi_auth_intr_show_attr_intr_name(
1116 struct se_ml_stat_grps
*lgrps
, char *page
)
1118 struct se_lun_acl
*lacl
= container_of(lgrps
,
1119 struct se_lun_acl
, ml_stat_grps
);
1120 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1121 struct se_dev_entry
*deve
;
1125 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1130 /* scsiAuthIntrName */
1131 ret
= snprintf(page
, PAGE_SIZE
, "%s\n", nacl
->initiatorname
);
1135 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name
);
1137 static ssize_t
target_stat_scsi_auth_intr_show_attr_map_indx(
1138 struct se_ml_stat_grps
*lgrps
, char *page
)
1140 struct se_lun_acl
*lacl
= container_of(lgrps
,
1141 struct se_lun_acl
, ml_stat_grps
);
1142 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1143 struct se_dev_entry
*deve
;
1147 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1152 /* FIXME: scsiAuthIntrLunMapIndex */
1153 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1157 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx
);
1159 static ssize_t
target_stat_scsi_auth_intr_show_attr_att_count(
1160 struct se_ml_stat_grps
*lgrps
, char *page
)
1162 struct se_lun_acl
*lacl
= container_of(lgrps
,
1163 struct se_lun_acl
, ml_stat_grps
);
1164 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1165 struct se_dev_entry
*deve
;
1169 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1174 /* scsiAuthIntrAttachedTimes */
1175 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->attach_count
);
1179 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count
);
1181 static ssize_t
target_stat_scsi_auth_intr_show_attr_num_cmds(
1182 struct se_ml_stat_grps
*lgrps
, char *page
)
1184 struct se_lun_acl
*lacl
= container_of(lgrps
,
1185 struct se_lun_acl
, ml_stat_grps
);
1186 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1187 struct se_dev_entry
*deve
;
1191 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1196 /* scsiAuthIntrOutCommands */
1197 ret
= snprintf(page
, PAGE_SIZE
, "%lu\n",
1198 atomic_long_read(&deve
->total_cmds
));
1202 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds
);
1204 static ssize_t
target_stat_scsi_auth_intr_show_attr_read_mbytes(
1205 struct se_ml_stat_grps
*lgrps
, char *page
)
1207 struct se_lun_acl
*lacl
= container_of(lgrps
,
1208 struct se_lun_acl
, ml_stat_grps
);
1209 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1210 struct se_dev_entry
*deve
;
1214 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1219 /* scsiAuthIntrReadMegaBytes */
1220 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1221 (u32
)(atomic_long_read(&deve
->read_bytes
) >> 20));
1225 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes
);
1227 static ssize_t
target_stat_scsi_auth_intr_show_attr_write_mbytes(
1228 struct se_ml_stat_grps
*lgrps
, char *page
)
1230 struct se_lun_acl
*lacl
= container_of(lgrps
,
1231 struct se_lun_acl
, ml_stat_grps
);
1232 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1233 struct se_dev_entry
*deve
;
1237 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1242 /* scsiAuthIntrWrittenMegaBytes */
1243 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1244 (u32
)(atomic_long_read(&deve
->write_bytes
) >> 20));
1248 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes
);
1250 static ssize_t
target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1251 struct se_ml_stat_grps
*lgrps
, char *page
)
1253 struct se_lun_acl
*lacl
= container_of(lgrps
,
1254 struct se_lun_acl
, ml_stat_grps
);
1255 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1256 struct se_dev_entry
*deve
;
1260 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1265 /* FIXME: scsiAuthIntrHSOutCommands */
1266 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1270 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds
);
1272 static ssize_t
target_stat_scsi_auth_intr_show_attr_creation_time(
1273 struct se_ml_stat_grps
*lgrps
, char *page
)
1275 struct se_lun_acl
*lacl
= container_of(lgrps
,
1276 struct se_lun_acl
, ml_stat_grps
);
1277 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1278 struct se_dev_entry
*deve
;
1282 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1287 /* scsiAuthIntrLastCreation */
1288 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)deve
->creation_time
-
1289 INITIAL_JIFFIES
) * 100 / HZ
));
1293 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time
);
1295 static ssize_t
target_stat_scsi_auth_intr_show_attr_row_status(
1296 struct se_ml_stat_grps
*lgrps
, char *page
)
1298 struct se_lun_acl
*lacl
= container_of(lgrps
,
1299 struct se_lun_acl
, ml_stat_grps
);
1300 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1301 struct se_dev_entry
*deve
;
1305 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1310 /* FIXME: scsiAuthIntrRowStatus */
1311 ret
= snprintf(page
, PAGE_SIZE
, "Ready\n");
1315 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status
);
1317 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr
, se_ml_stat_grps
,
1318 scsi_auth_intr_group
);
1320 static struct configfs_attribute
*target_stat_scsi_auth_intr_attrs
[] = {
1321 &target_stat_scsi_auth_intr_inst
.attr
,
1322 &target_stat_scsi_auth_intr_dev
.attr
,
1323 &target_stat_scsi_auth_intr_port
.attr
,
1324 &target_stat_scsi_auth_intr_indx
.attr
,
1325 &target_stat_scsi_auth_intr_dev_or_port
.attr
,
1326 &target_stat_scsi_auth_intr_intr_name
.attr
,
1327 &target_stat_scsi_auth_intr_map_indx
.attr
,
1328 &target_stat_scsi_auth_intr_att_count
.attr
,
1329 &target_stat_scsi_auth_intr_num_cmds
.attr
,
1330 &target_stat_scsi_auth_intr_read_mbytes
.attr
,
1331 &target_stat_scsi_auth_intr_write_mbytes
.attr
,
1332 &target_stat_scsi_auth_intr_hs_num_cmds
.attr
,
1333 &target_stat_scsi_auth_intr_creation_time
.attr
,
1334 &target_stat_scsi_auth_intr_row_status
.attr
,
1338 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops
= {
1339 .show_attribute
= target_stat_scsi_auth_intr_attr_show
,
1340 .store_attribute
= target_stat_scsi_auth_intr_attr_store
,
1343 static struct config_item_type target_stat_scsi_auth_intr_cit
= {
1344 .ct_item_ops
= &target_stat_scsi_auth_intr_attrib_ops
,
1345 .ct_attrs
= target_stat_scsi_auth_intr_attrs
,
1346 .ct_owner
= THIS_MODULE
,
1350 * SCSI Attached Initiator Port Table
1353 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port
, se_ml_stat_grps
);
1354 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1355 static struct target_stat_scsi_att_intr_port_attribute \
1356 target_stat_scsi_att_intr_port_##_name = \
1357 __CONFIGFS_EATTR(_name, _mode, \
1358 target_stat_scsi_att_intr_port_show_attr_##_name, \
1359 target_stat_scsi_att_intr_port_store_attr_##_name);
1361 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1362 static struct target_stat_scsi_att_intr_port_attribute \
1363 target_stat_scsi_att_intr_port_##_name = \
1364 __CONFIGFS_EATTR_RO(_name, \
1365 target_stat_scsi_att_intr_port_show_attr_##_name);
1367 static ssize_t
target_stat_scsi_att_intr_port_show_attr_inst(
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 struct se_portal_group
*tpg
;
1378 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1385 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1386 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
1390 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst
);
1392 static ssize_t
target_stat_scsi_att_intr_port_show_attr_dev(
1393 struct se_ml_stat_grps
*lgrps
, char *page
)
1395 struct se_lun_acl
*lacl
= container_of(lgrps
,
1396 struct se_lun_acl
, ml_stat_grps
);
1397 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1398 struct se_dev_entry
*deve
;
1403 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1408 lun
= rcu_dereference(deve
->se_lun
);
1409 /* scsiDeviceIndex */
1410 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_index
);
1414 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev
);
1416 static ssize_t
target_stat_scsi_att_intr_port_show_attr_port(
1417 struct se_ml_stat_grps
*lgrps
, char *page
)
1419 struct se_lun_acl
*lacl
= container_of(lgrps
,
1420 struct se_lun_acl
, ml_stat_grps
);
1421 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1422 struct se_dev_entry
*deve
;
1423 struct se_portal_group
*tpg
;
1427 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1434 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
1438 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port
);
1440 static ssize_t
target_stat_scsi_att_intr_port_show_attr_indx(
1441 struct se_ml_stat_grps
*lgrps
, char *page
)
1443 struct se_lun_acl
*lacl
= container_of(lgrps
,
1444 struct se_lun_acl
, ml_stat_grps
);
1445 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1446 struct se_session
*se_sess
;
1447 struct se_portal_group
*tpg
;
1450 spin_lock_irq(&nacl
->nacl_sess_lock
);
1451 se_sess
= nacl
->nacl_sess
;
1453 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1458 /* scsiAttIntrPortIndex */
1459 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1460 tpg
->se_tpg_tfo
->sess_get_index(se_sess
));
1461 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1464 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx
);
1466 static ssize_t
target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1467 struct se_ml_stat_grps
*lgrps
, char *page
)
1469 struct se_lun_acl
*lacl
= container_of(lgrps
,
1470 struct se_lun_acl
, ml_stat_grps
);
1471 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1472 struct se_dev_entry
*deve
;
1476 deve
= target_nacl_find_deve(nacl
, lacl
->mapped_lun
);
1481 /* scsiAttIntrPortAuthIntrIdx */
1482 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
1486 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx
);
1488 static ssize_t
target_stat_scsi_att_intr_port_show_attr_port_ident(
1489 struct se_ml_stat_grps
*lgrps
, char *page
)
1491 struct se_lun_acl
*lacl
= container_of(lgrps
,
1492 struct se_lun_acl
, ml_stat_grps
);
1493 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1494 struct se_session
*se_sess
;
1495 struct se_portal_group
*tpg
;
1497 unsigned char buf
[64];
1499 spin_lock_irq(&nacl
->nacl_sess_lock
);
1500 se_sess
= nacl
->nacl_sess
;
1502 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1507 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1509 if (tpg
->se_tpg_tfo
->sess_get_initiator_sid
!= NULL
)
1510 tpg
->se_tpg_tfo
->sess_get_initiator_sid(se_sess
, buf
, 64);
1512 ret
= snprintf(page
, PAGE_SIZE
, "%s+i+%s\n", nacl
->initiatorname
, buf
);
1513 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1516 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident
);
1518 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port
, se_ml_stat_grps
,
1519 scsi_att_intr_port_group
);
1521 static struct configfs_attribute
*target_stat_scsi_ath_intr_port_attrs
[] = {
1522 &target_stat_scsi_att_intr_port_inst
.attr
,
1523 &target_stat_scsi_att_intr_port_dev
.attr
,
1524 &target_stat_scsi_att_intr_port_port
.attr
,
1525 &target_stat_scsi_att_intr_port_indx
.attr
,
1526 &target_stat_scsi_att_intr_port_port_auth_indx
.attr
,
1527 &target_stat_scsi_att_intr_port_port_ident
.attr
,
1531 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops
= {
1532 .show_attribute
= target_stat_scsi_att_intr_port_attr_show
,
1533 .store_attribute
= target_stat_scsi_att_intr_port_attr_store
,
1536 static struct config_item_type target_stat_scsi_att_intr_port_cit
= {
1537 .ct_item_ops
= &target_stat_scsi_att_intr_port_attrib_ops
,
1538 .ct_attrs
= target_stat_scsi_ath_intr_port_attrs
,
1539 .ct_owner
= THIS_MODULE
,
1543 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1544 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1546 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl
*lacl
)
1548 struct config_group
*ml_stat_grp
= &lacl
->ml_stat_grps
.stat_group
;
1550 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_auth_intr_group
,
1551 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit
);
1552 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_att_intr_port_group
,
1553 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit
);
1555 ml_stat_grp
->default_groups
[0] = &lacl
->ml_stat_grps
.scsi_auth_intr_group
;
1556 ml_stat_grp
->default_groups
[1] = &lacl
->ml_stat_grps
.scsi_att_intr_port_group
;
1557 ml_stat_grp
->default_groups
[2] = NULL
;