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>
36 #include <scsi/scsi.h>
37 #include <scsi/scsi_device.h>
38 #include <scsi/scsi_host.h>
40 #include <target/target_core_base.h>
41 #include <target/target_core_backend.h>
42 #include <target/target_core_fabric.h>
43 #include <target/target_core_configfs.h>
44 #include <target/configfs_macros.h>
46 #include "target_core_internal.h"
48 #ifndef INITIAL_JIFFIES
49 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
53 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
55 #define SCSI_LU_INDEX 1
62 CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev
, se_dev_stat_grps
);
63 #define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \
64 static struct target_stat_scsi_dev_attribute \
65 target_stat_scsi_dev_##_name = \
66 __CONFIGFS_EATTR(_name, _mode, \
67 target_stat_scsi_dev_show_attr_##_name, \
68 target_stat_scsi_dev_store_attr_##_name);
70 #define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
71 static struct target_stat_scsi_dev_attribute \
72 target_stat_scsi_dev_##_name = \
73 __CONFIGFS_EATTR_RO(_name, \
74 target_stat_scsi_dev_show_attr_##_name);
76 static ssize_t
target_stat_scsi_dev_show_attr_inst(
77 struct se_dev_stat_grps
*sgrps
, char *page
)
79 struct se_device
*dev
=
80 container_of(sgrps
, struct se_device
, dev_stat_grps
);
81 struct se_hba
*hba
= dev
->se_hba
;
83 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
85 DEV_STAT_SCSI_DEV_ATTR_RO(inst
);
87 static ssize_t
target_stat_scsi_dev_show_attr_indx(
88 struct se_dev_stat_grps
*sgrps
, char *page
)
90 struct se_device
*dev
=
91 container_of(sgrps
, struct se_device
, dev_stat_grps
);
93 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
95 DEV_STAT_SCSI_DEV_ATTR_RO(indx
);
97 static ssize_t
target_stat_scsi_dev_show_attr_role(
98 struct se_dev_stat_grps
*sgrps
, char *page
)
100 return snprintf(page
, PAGE_SIZE
, "Target\n");
102 DEV_STAT_SCSI_DEV_ATTR_RO(role
);
104 static ssize_t
target_stat_scsi_dev_show_attr_ports(
105 struct se_dev_stat_grps
*sgrps
, char *page
)
107 struct se_device
*dev
=
108 container_of(sgrps
, struct se_device
, dev_stat_grps
);
110 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_port_count
);
112 DEV_STAT_SCSI_DEV_ATTR_RO(ports
);
114 CONFIGFS_EATTR_OPS(target_stat_scsi_dev
, se_dev_stat_grps
, scsi_dev_group
);
116 static struct configfs_attribute
*target_stat_scsi_dev_attrs
[] = {
117 &target_stat_scsi_dev_inst
.attr
,
118 &target_stat_scsi_dev_indx
.attr
,
119 &target_stat_scsi_dev_role
.attr
,
120 &target_stat_scsi_dev_ports
.attr
,
124 static struct configfs_item_operations target_stat_scsi_dev_attrib_ops
= {
125 .show_attribute
= target_stat_scsi_dev_attr_show
,
126 .store_attribute
= target_stat_scsi_dev_attr_store
,
129 static struct config_item_type target_stat_scsi_dev_cit
= {
130 .ct_item_ops
= &target_stat_scsi_dev_attrib_ops
,
131 .ct_attrs
= target_stat_scsi_dev_attrs
,
132 .ct_owner
= THIS_MODULE
,
136 * SCSI Target Device Table
139 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev
, se_dev_stat_grps
);
140 #define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
141 static struct target_stat_scsi_tgt_dev_attribute \
142 target_stat_scsi_tgt_dev_##_name = \
143 __CONFIGFS_EATTR(_name, _mode, \
144 target_stat_scsi_tgt_dev_show_attr_##_name, \
145 target_stat_scsi_tgt_dev_store_attr_##_name);
147 #define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
148 static struct target_stat_scsi_tgt_dev_attribute \
149 target_stat_scsi_tgt_dev_##_name = \
150 __CONFIGFS_EATTR_RO(_name, \
151 target_stat_scsi_tgt_dev_show_attr_##_name);
153 static ssize_t
target_stat_scsi_tgt_dev_show_attr_inst(
154 struct se_dev_stat_grps
*sgrps
, char *page
)
156 struct se_device
*dev
=
157 container_of(sgrps
, struct se_device
, dev_stat_grps
);
158 struct se_hba
*hba
= dev
->se_hba
;
160 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
162 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst
);
164 static ssize_t
target_stat_scsi_tgt_dev_show_attr_indx(
165 struct se_dev_stat_grps
*sgrps
, char *page
)
167 struct se_device
*dev
=
168 container_of(sgrps
, struct se_device
, dev_stat_grps
);
170 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
172 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx
);
174 static ssize_t
target_stat_scsi_tgt_dev_show_attr_num_lus(
175 struct se_dev_stat_grps
*sgrps
, char *page
)
177 return snprintf(page
, PAGE_SIZE
, "%u\n", LU_COUNT
);
179 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus
);
181 static ssize_t
target_stat_scsi_tgt_dev_show_attr_status(
182 struct se_dev_stat_grps
*sgrps
, char *page
)
184 struct se_device
*dev
=
185 container_of(sgrps
, struct se_device
, dev_stat_grps
);
187 if (dev
->export_count
)
188 return snprintf(page
, PAGE_SIZE
, "activated");
190 return snprintf(page
, PAGE_SIZE
, "deactivated");
192 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status
);
194 static ssize_t
target_stat_scsi_tgt_dev_show_attr_non_access_lus(
195 struct se_dev_stat_grps
*sgrps
, char *page
)
197 struct se_device
*dev
=
198 container_of(sgrps
, struct se_device
, dev_stat_grps
);
199 int non_accessible_lus
;
201 if (dev
->export_count
)
202 non_accessible_lus
= 0;
204 non_accessible_lus
= 1;
206 return snprintf(page
, PAGE_SIZE
, "%u\n", non_accessible_lus
);
208 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus
);
210 static ssize_t
target_stat_scsi_tgt_dev_show_attr_resets(
211 struct se_dev_stat_grps
*sgrps
, char *page
)
213 struct se_device
*dev
=
214 container_of(sgrps
, struct se_device
, dev_stat_grps
);
216 return snprintf(page
, PAGE_SIZE
, "%lu\n",
217 atomic_long_read(&dev
->num_resets
));
219 DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets
);
222 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev
, se_dev_stat_grps
, scsi_tgt_dev_group
);
224 static struct configfs_attribute
*target_stat_scsi_tgt_dev_attrs
[] = {
225 &target_stat_scsi_tgt_dev_inst
.attr
,
226 &target_stat_scsi_tgt_dev_indx
.attr
,
227 &target_stat_scsi_tgt_dev_num_lus
.attr
,
228 &target_stat_scsi_tgt_dev_status
.attr
,
229 &target_stat_scsi_tgt_dev_non_access_lus
.attr
,
230 &target_stat_scsi_tgt_dev_resets
.attr
,
234 static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops
= {
235 .show_attribute
= target_stat_scsi_tgt_dev_attr_show
,
236 .store_attribute
= target_stat_scsi_tgt_dev_attr_store
,
239 static struct config_item_type target_stat_scsi_tgt_dev_cit
= {
240 .ct_item_ops
= &target_stat_scsi_tgt_dev_attrib_ops
,
241 .ct_attrs
= target_stat_scsi_tgt_dev_attrs
,
242 .ct_owner
= THIS_MODULE
,
246 * SCSI Logical Unit Table
249 CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu
, se_dev_stat_grps
);
250 #define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \
251 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
252 __CONFIGFS_EATTR(_name, _mode, \
253 target_stat_scsi_lu_show_attr_##_name, \
254 target_stat_scsi_lu_store_attr_##_name);
256 #define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
257 static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
258 __CONFIGFS_EATTR_RO(_name, \
259 target_stat_scsi_lu_show_attr_##_name);
261 static ssize_t
target_stat_scsi_lu_show_attr_inst(
262 struct se_dev_stat_grps
*sgrps
, char *page
)
264 struct se_device
*dev
=
265 container_of(sgrps
, struct se_device
, dev_stat_grps
);
266 struct se_hba
*hba
= dev
->se_hba
;
268 return snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
270 DEV_STAT_SCSI_LU_ATTR_RO(inst
);
272 static ssize_t
target_stat_scsi_lu_show_attr_dev(
273 struct se_dev_stat_grps
*sgrps
, char *page
)
275 struct se_device
*dev
=
276 container_of(sgrps
, struct se_device
, dev_stat_grps
);
278 return snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
280 DEV_STAT_SCSI_LU_ATTR_RO(dev
);
282 static ssize_t
target_stat_scsi_lu_show_attr_indx(
283 struct se_dev_stat_grps
*sgrps
, char *page
)
285 return snprintf(page
, PAGE_SIZE
, "%u\n", SCSI_LU_INDEX
);
287 DEV_STAT_SCSI_LU_ATTR_RO(indx
);
289 static ssize_t
target_stat_scsi_lu_show_attr_lun(
290 struct se_dev_stat_grps
*sgrps
, char *page
)
292 /* FIXME: scsiLuDefaultLun */
293 return snprintf(page
, PAGE_SIZE
, "%llu\n", (unsigned long long)0);
295 DEV_STAT_SCSI_LU_ATTR_RO(lun
);
297 static ssize_t
target_stat_scsi_lu_show_attr_lu_name(
298 struct se_dev_stat_grps
*sgrps
, char *page
)
300 struct se_device
*dev
=
301 container_of(sgrps
, struct se_device
, dev_stat_grps
);
304 return snprintf(page
, PAGE_SIZE
, "%s\n",
305 (strlen(dev
->t10_wwn
.unit_serial
)) ?
306 dev
->t10_wwn
.unit_serial
: "None");
308 DEV_STAT_SCSI_LU_ATTR_RO(lu_name
);
310 static ssize_t
target_stat_scsi_lu_show_attr_vend(
311 struct se_dev_stat_grps
*sgrps
, char *page
)
313 struct se_device
*dev
=
314 container_of(sgrps
, struct se_device
, dev_stat_grps
);
316 char str
[sizeof(dev
->t10_wwn
.vendor
)+1];
319 for (i
= 0; i
< sizeof(dev
->t10_wwn
.vendor
); i
++)
320 str
[i
] = ISPRINT(dev
->t10_wwn
.vendor
[i
]) ?
321 dev
->t10_wwn
.vendor
[i
] : ' ';
323 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
325 DEV_STAT_SCSI_LU_ATTR_RO(vend
);
327 static ssize_t
target_stat_scsi_lu_show_attr_prod(
328 struct se_dev_stat_grps
*sgrps
, char *page
)
330 struct se_device
*dev
=
331 container_of(sgrps
, struct se_device
, dev_stat_grps
);
333 char str
[sizeof(dev
->t10_wwn
.model
)+1];
335 /* scsiLuProductId */
336 for (i
= 0; i
< sizeof(dev
->t10_wwn
.vendor
); i
++)
337 str
[i
] = ISPRINT(dev
->t10_wwn
.model
[i
]) ?
338 dev
->t10_wwn
.model
[i
] : ' ';
340 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
342 DEV_STAT_SCSI_LU_ATTR_RO(prod
);
344 static ssize_t
target_stat_scsi_lu_show_attr_rev(
345 struct se_dev_stat_grps
*sgrps
, char *page
)
347 struct se_device
*dev
=
348 container_of(sgrps
, struct se_device
, dev_stat_grps
);
350 char str
[sizeof(dev
->t10_wwn
.revision
)+1];
352 /* scsiLuRevisionId */
353 for (i
= 0; i
< sizeof(dev
->t10_wwn
.revision
); i
++)
354 str
[i
] = ISPRINT(dev
->t10_wwn
.revision
[i
]) ?
355 dev
->t10_wwn
.revision
[i
] : ' ';
357 return snprintf(page
, PAGE_SIZE
, "%s\n", str
);
359 DEV_STAT_SCSI_LU_ATTR_RO(rev
);
361 static ssize_t
target_stat_scsi_lu_show_attr_dev_type(
362 struct se_dev_stat_grps
*sgrps
, char *page
)
364 struct se_device
*dev
=
365 container_of(sgrps
, struct se_device
, dev_stat_grps
);
367 /* scsiLuPeripheralType */
368 return snprintf(page
, PAGE_SIZE
, "%u\n",
369 dev
->transport
->get_device_type(dev
));
371 DEV_STAT_SCSI_LU_ATTR_RO(dev_type
);
373 static ssize_t
target_stat_scsi_lu_show_attr_status(
374 struct se_dev_stat_grps
*sgrps
, char *page
)
376 struct se_device
*dev
=
377 container_of(sgrps
, struct se_device
, dev_stat_grps
);
380 return snprintf(page
, PAGE_SIZE
, "%s\n",
381 (dev
->export_count
) ? "available" : "notavailable");
383 DEV_STAT_SCSI_LU_ATTR_RO(status
);
385 static ssize_t
target_stat_scsi_lu_show_attr_state_bit(
386 struct se_dev_stat_grps
*sgrps
, char *page
)
389 return snprintf(page
, PAGE_SIZE
, "exposed\n");
391 DEV_STAT_SCSI_LU_ATTR_RO(state_bit
);
393 static ssize_t
target_stat_scsi_lu_show_attr_num_cmds(
394 struct se_dev_stat_grps
*sgrps
, char *page
)
396 struct se_device
*dev
=
397 container_of(sgrps
, struct se_device
, dev_stat_grps
);
399 /* scsiLuNumCommands */
400 return snprintf(page
, PAGE_SIZE
, "%lu\n",
401 atomic_long_read(&dev
->num_cmds
));
403 DEV_STAT_SCSI_LU_ATTR_RO(num_cmds
);
405 static ssize_t
target_stat_scsi_lu_show_attr_read_mbytes(
406 struct se_dev_stat_grps
*sgrps
, char *page
)
408 struct se_device
*dev
=
409 container_of(sgrps
, struct se_device
, dev_stat_grps
);
411 /* scsiLuReadMegaBytes */
412 return snprintf(page
, PAGE_SIZE
, "%lu\n",
413 atomic_long_read(&dev
->read_bytes
) >> 20);
415 DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes
);
417 static ssize_t
target_stat_scsi_lu_show_attr_write_mbytes(
418 struct se_dev_stat_grps
*sgrps
, char *page
)
420 struct se_device
*dev
=
421 container_of(sgrps
, struct se_device
, dev_stat_grps
);
423 /* scsiLuWrittenMegaBytes */
424 return snprintf(page
, PAGE_SIZE
, "%lu\n",
425 atomic_long_read(&dev
->write_bytes
) >> 20);
427 DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes
);
429 static ssize_t
target_stat_scsi_lu_show_attr_resets(
430 struct se_dev_stat_grps
*sgrps
, char *page
)
432 struct se_device
*dev
=
433 container_of(sgrps
, struct se_device
, dev_stat_grps
);
436 return snprintf(page
, PAGE_SIZE
, "%lu\n", atomic_long_read(&dev
->num_resets
));
438 DEV_STAT_SCSI_LU_ATTR_RO(resets
);
440 static ssize_t
target_stat_scsi_lu_show_attr_full_stat(
441 struct se_dev_stat_grps
*sgrps
, char *page
)
443 /* FIXME: scsiLuOutTaskSetFullStatus */
444 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
446 DEV_STAT_SCSI_LU_ATTR_RO(full_stat
);
448 static ssize_t
target_stat_scsi_lu_show_attr_hs_num_cmds(
449 struct se_dev_stat_grps
*sgrps
, char *page
)
451 /* FIXME: scsiLuHSInCommands */
452 return snprintf(page
, PAGE_SIZE
, "%u\n", 0);
454 DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds
);
456 static ssize_t
target_stat_scsi_lu_show_attr_creation_time(
457 struct se_dev_stat_grps
*sgrps
, char *page
)
459 struct se_device
*dev
=
460 container_of(sgrps
, struct se_device
, dev_stat_grps
);
462 /* scsiLuCreationTime */
463 return snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)dev
->creation_time
-
464 INITIAL_JIFFIES
) * 100 / HZ
));
466 DEV_STAT_SCSI_LU_ATTR_RO(creation_time
);
468 CONFIGFS_EATTR_OPS(target_stat_scsi_lu
, se_dev_stat_grps
, scsi_lu_group
);
470 static struct configfs_attribute
*target_stat_scsi_lu_attrs
[] = {
471 &target_stat_scsi_lu_inst
.attr
,
472 &target_stat_scsi_lu_dev
.attr
,
473 &target_stat_scsi_lu_indx
.attr
,
474 &target_stat_scsi_lu_lun
.attr
,
475 &target_stat_scsi_lu_lu_name
.attr
,
476 &target_stat_scsi_lu_vend
.attr
,
477 &target_stat_scsi_lu_prod
.attr
,
478 &target_stat_scsi_lu_rev
.attr
,
479 &target_stat_scsi_lu_dev_type
.attr
,
480 &target_stat_scsi_lu_status
.attr
,
481 &target_stat_scsi_lu_state_bit
.attr
,
482 &target_stat_scsi_lu_num_cmds
.attr
,
483 &target_stat_scsi_lu_read_mbytes
.attr
,
484 &target_stat_scsi_lu_write_mbytes
.attr
,
485 &target_stat_scsi_lu_resets
.attr
,
486 &target_stat_scsi_lu_full_stat
.attr
,
487 &target_stat_scsi_lu_hs_num_cmds
.attr
,
488 &target_stat_scsi_lu_creation_time
.attr
,
492 static struct configfs_item_operations target_stat_scsi_lu_attrib_ops
= {
493 .show_attribute
= target_stat_scsi_lu_attr_show
,
494 .store_attribute
= target_stat_scsi_lu_attr_store
,
497 static struct config_item_type target_stat_scsi_lu_cit
= {
498 .ct_item_ops
= &target_stat_scsi_lu_attrib_ops
,
499 .ct_attrs
= target_stat_scsi_lu_attrs
,
500 .ct_owner
= THIS_MODULE
,
504 * Called from target_core_configfs.c:target_core_make_subdev() to setup
505 * the target statistics groups + configfs CITs located in target_core_stat.c
507 void target_stat_setup_dev_default_groups(struct se_device
*dev
)
509 struct config_group
*dev_stat_grp
= &dev
->dev_stat_grps
.stat_group
;
511 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_dev_group
,
512 "scsi_dev", &target_stat_scsi_dev_cit
);
513 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_tgt_dev_group
,
514 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit
);
515 config_group_init_type_name(&dev
->dev_stat_grps
.scsi_lu_group
,
516 "scsi_lu", &target_stat_scsi_lu_cit
);
518 dev_stat_grp
->default_groups
[0] = &dev
->dev_stat_grps
.scsi_dev_group
;
519 dev_stat_grp
->default_groups
[1] = &dev
->dev_stat_grps
.scsi_tgt_dev_group
;
520 dev_stat_grp
->default_groups
[2] = &dev
->dev_stat_grps
.scsi_lu_group
;
521 dev_stat_grp
->default_groups
[3] = NULL
;
528 CONFIGFS_EATTR_STRUCT(target_stat_scsi_port
, se_port_stat_grps
);
529 #define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \
530 static struct target_stat_scsi_port_attribute \
531 target_stat_scsi_port_##_name = \
532 __CONFIGFS_EATTR(_name, _mode, \
533 target_stat_scsi_port_show_attr_##_name, \
534 target_stat_scsi_port_store_attr_##_name);
536 #define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
537 static struct target_stat_scsi_port_attribute \
538 target_stat_scsi_port_##_name = \
539 __CONFIGFS_EATTR_RO(_name, \
540 target_stat_scsi_port_show_attr_##_name);
542 static ssize_t
target_stat_scsi_port_show_attr_inst(
543 struct se_port_stat_grps
*pgrps
, char *page
)
545 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
547 struct se_device
*dev
= lun
->lun_se_dev
;
551 spin_lock(&lun
->lun_sep_lock
);
554 spin_unlock(&lun
->lun_sep_lock
);
558 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
559 spin_unlock(&lun
->lun_sep_lock
);
562 DEV_STAT_SCSI_PORT_ATTR_RO(inst
);
564 static ssize_t
target_stat_scsi_port_show_attr_dev(
565 struct se_port_stat_grps
*pgrps
, char *page
)
567 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
569 struct se_device
*dev
= lun
->lun_se_dev
;
572 spin_lock(&lun
->lun_sep_lock
);
575 spin_unlock(&lun
->lun_sep_lock
);
578 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
579 spin_unlock(&lun
->lun_sep_lock
);
582 DEV_STAT_SCSI_PORT_ATTR_RO(dev
);
584 static ssize_t
target_stat_scsi_port_show_attr_indx(
585 struct se_port_stat_grps
*pgrps
, char *page
)
587 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
591 spin_lock(&lun
->lun_sep_lock
);
594 spin_unlock(&lun
->lun_sep_lock
);
597 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", sep
->sep_index
);
598 spin_unlock(&lun
->lun_sep_lock
);
601 DEV_STAT_SCSI_PORT_ATTR_RO(indx
);
603 static ssize_t
target_stat_scsi_port_show_attr_role(
604 struct se_port_stat_grps
*pgrps
, char *page
)
606 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
607 struct se_device
*dev
= lun
->lun_se_dev
;
614 spin_lock(&lun
->lun_sep_lock
);
617 spin_unlock(&lun
->lun_sep_lock
);
620 ret
= snprintf(page
, PAGE_SIZE
, "%s%u\n", "Device", dev
->dev_index
);
621 spin_unlock(&lun
->lun_sep_lock
);
624 DEV_STAT_SCSI_PORT_ATTR_RO(role
);
626 static ssize_t
target_stat_scsi_port_show_attr_busy_count(
627 struct se_port_stat_grps
*pgrps
, char *page
)
629 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
633 spin_lock(&lun
->lun_sep_lock
);
636 spin_unlock(&lun
->lun_sep_lock
);
639 /* FIXME: scsiPortBusyStatuses */
640 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
641 spin_unlock(&lun
->lun_sep_lock
);
644 DEV_STAT_SCSI_PORT_ATTR_RO(busy_count
);
646 CONFIGFS_EATTR_OPS(target_stat_scsi_port
, se_port_stat_grps
, scsi_port_group
);
648 static struct configfs_attribute
*target_stat_scsi_port_attrs
[] = {
649 &target_stat_scsi_port_inst
.attr
,
650 &target_stat_scsi_port_dev
.attr
,
651 &target_stat_scsi_port_indx
.attr
,
652 &target_stat_scsi_port_role
.attr
,
653 &target_stat_scsi_port_busy_count
.attr
,
657 static struct configfs_item_operations target_stat_scsi_port_attrib_ops
= {
658 .show_attribute
= target_stat_scsi_port_attr_show
,
659 .store_attribute
= target_stat_scsi_port_attr_store
,
662 static struct config_item_type target_stat_scsi_port_cit
= {
663 .ct_item_ops
= &target_stat_scsi_port_attrib_ops
,
664 .ct_attrs
= target_stat_scsi_port_attrs
,
665 .ct_owner
= THIS_MODULE
,
669 * SCSI Target Port Table
671 CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port
, se_port_stat_grps
);
672 #define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \
673 static struct target_stat_scsi_tgt_port_attribute \
674 target_stat_scsi_tgt_port_##_name = \
675 __CONFIGFS_EATTR(_name, _mode, \
676 target_stat_scsi_tgt_port_show_attr_##_name, \
677 target_stat_scsi_tgt_port_store_attr_##_name);
679 #define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \
680 static struct target_stat_scsi_tgt_port_attribute \
681 target_stat_scsi_tgt_port_##_name = \
682 __CONFIGFS_EATTR_RO(_name, \
683 target_stat_scsi_tgt_port_show_attr_##_name);
685 static ssize_t
target_stat_scsi_tgt_port_show_attr_inst(
686 struct se_port_stat_grps
*pgrps
, char *page
)
688 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
689 struct se_device
*dev
= lun
->lun_se_dev
;
694 spin_lock(&lun
->lun_sep_lock
);
697 spin_unlock(&lun
->lun_sep_lock
);
701 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
702 spin_unlock(&lun
->lun_sep_lock
);
705 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst
);
707 static ssize_t
target_stat_scsi_tgt_port_show_attr_dev(
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_device
*dev
= lun
->lun_se_dev
;
715 spin_lock(&lun
->lun_sep_lock
);
718 spin_unlock(&lun
->lun_sep_lock
);
721 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", dev
->dev_index
);
722 spin_unlock(&lun
->lun_sep_lock
);
725 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev
);
727 static ssize_t
target_stat_scsi_tgt_port_show_attr_indx(
728 struct se_port_stat_grps
*pgrps
, char *page
)
730 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
734 spin_lock(&lun
->lun_sep_lock
);
737 spin_unlock(&lun
->lun_sep_lock
);
740 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", sep
->sep_index
);
741 spin_unlock(&lun
->lun_sep_lock
);
744 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx
);
746 static ssize_t
target_stat_scsi_tgt_port_show_attr_name(
747 struct se_port_stat_grps
*pgrps
, char *page
)
749 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
751 struct se_portal_group
*tpg
;
754 spin_lock(&lun
->lun_sep_lock
);
757 spin_unlock(&lun
->lun_sep_lock
);
762 ret
= snprintf(page
, PAGE_SIZE
, "%sPort#%u\n",
763 tpg
->se_tpg_tfo
->get_fabric_name(), sep
->sep_index
);
764 spin_unlock(&lun
->lun_sep_lock
);
767 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name
);
769 static ssize_t
target_stat_scsi_tgt_port_show_attr_port_index(
770 struct se_port_stat_grps
*pgrps
, char *page
)
772 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
774 struct se_portal_group
*tpg
;
777 spin_lock(&lun
->lun_sep_lock
);
780 spin_unlock(&lun
->lun_sep_lock
);
785 ret
= snprintf(page
, PAGE_SIZE
, "%s%s%d\n",
786 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
), "+t+",
787 tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
788 spin_unlock(&lun
->lun_sep_lock
);
791 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index
);
793 static ssize_t
target_stat_scsi_tgt_port_show_attr_in_cmds(
794 struct se_port_stat_grps
*pgrps
, char *page
)
796 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
800 spin_lock(&lun
->lun_sep_lock
);
803 spin_unlock(&lun
->lun_sep_lock
);
807 ret
= snprintf(page
, PAGE_SIZE
, "%llu\n", sep
->sep_stats
.cmd_pdus
);
808 spin_unlock(&lun
->lun_sep_lock
);
811 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds
);
813 static ssize_t
target_stat_scsi_tgt_port_show_attr_write_mbytes(
814 struct se_port_stat_grps
*pgrps
, char *page
)
816 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
820 spin_lock(&lun
->lun_sep_lock
);
823 spin_unlock(&lun
->lun_sep_lock
);
827 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
828 (u32
)(sep
->sep_stats
.rx_data_octets
>> 20));
829 spin_unlock(&lun
->lun_sep_lock
);
832 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes
);
834 static ssize_t
target_stat_scsi_tgt_port_show_attr_read_mbytes(
835 struct se_port_stat_grps
*pgrps
, char *page
)
837 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
841 spin_lock(&lun
->lun_sep_lock
);
844 spin_unlock(&lun
->lun_sep_lock
);
848 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
849 (u32
)(sep
->sep_stats
.tx_data_octets
>> 20));
850 spin_unlock(&lun
->lun_sep_lock
);
853 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes
);
855 static ssize_t
target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
856 struct se_port_stat_grps
*pgrps
, char *page
)
858 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
862 spin_lock(&lun
->lun_sep_lock
);
865 spin_unlock(&lun
->lun_sep_lock
);
869 /* FIXME: scsiTgtPortHsInCommands */
870 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
871 spin_unlock(&lun
->lun_sep_lock
);
874 DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds
);
876 CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port
, se_port_stat_grps
,
877 scsi_tgt_port_group
);
879 static struct configfs_attribute
*target_stat_scsi_tgt_port_attrs
[] = {
880 &target_stat_scsi_tgt_port_inst
.attr
,
881 &target_stat_scsi_tgt_port_dev
.attr
,
882 &target_stat_scsi_tgt_port_indx
.attr
,
883 &target_stat_scsi_tgt_port_name
.attr
,
884 &target_stat_scsi_tgt_port_port_index
.attr
,
885 &target_stat_scsi_tgt_port_in_cmds
.attr
,
886 &target_stat_scsi_tgt_port_write_mbytes
.attr
,
887 &target_stat_scsi_tgt_port_read_mbytes
.attr
,
888 &target_stat_scsi_tgt_port_hs_in_cmds
.attr
,
892 static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops
= {
893 .show_attribute
= target_stat_scsi_tgt_port_attr_show
,
894 .store_attribute
= target_stat_scsi_tgt_port_attr_store
,
897 static struct config_item_type target_stat_scsi_tgt_port_cit
= {
898 .ct_item_ops
= &target_stat_scsi_tgt_port_attrib_ops
,
899 .ct_attrs
= target_stat_scsi_tgt_port_attrs
,
900 .ct_owner
= THIS_MODULE
,
904 * SCSI Transport Table
907 CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport
, se_port_stat_grps
);
908 #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \
909 static struct target_stat_scsi_transport_attribute \
910 target_stat_scsi_transport_##_name = \
911 __CONFIGFS_EATTR(_name, _mode, \
912 target_stat_scsi_transport_show_attr_##_name, \
913 target_stat_scsi_transport_store_attr_##_name);
915 #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \
916 static struct target_stat_scsi_transport_attribute \
917 target_stat_scsi_transport_##_name = \
918 __CONFIGFS_EATTR_RO(_name, \
919 target_stat_scsi_transport_show_attr_##_name);
921 static ssize_t
target_stat_scsi_transport_show_attr_inst(
922 struct se_port_stat_grps
*pgrps
, char *page
)
924 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
925 struct se_device
*dev
= lun
->lun_se_dev
;
930 spin_lock(&lun
->lun_sep_lock
);
933 spin_unlock(&lun
->lun_sep_lock
);
938 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", hba
->hba_index
);
939 spin_unlock(&lun
->lun_sep_lock
);
942 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst
);
944 static ssize_t
target_stat_scsi_transport_show_attr_device(
945 struct se_port_stat_grps
*pgrps
, char *page
)
947 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
949 struct se_portal_group
*tpg
;
952 spin_lock(&lun
->lun_sep_lock
);
955 spin_unlock(&lun
->lun_sep_lock
);
959 /* scsiTransportType */
960 ret
= snprintf(page
, PAGE_SIZE
, "scsiTransport%s\n",
961 tpg
->se_tpg_tfo
->get_fabric_name());
962 spin_unlock(&lun
->lun_sep_lock
);
965 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device
);
967 static ssize_t
target_stat_scsi_transport_show_attr_indx(
968 struct se_port_stat_grps
*pgrps
, char *page
)
970 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
972 struct se_portal_group
*tpg
;
975 spin_lock(&lun
->lun_sep_lock
);
978 spin_unlock(&lun
->lun_sep_lock
);
982 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
983 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
984 spin_unlock(&lun
->lun_sep_lock
);
987 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx
);
989 static ssize_t
target_stat_scsi_transport_show_attr_dev_name(
990 struct se_port_stat_grps
*pgrps
, char *page
)
992 struct se_lun
*lun
= container_of(pgrps
, struct se_lun
, port_stat_grps
);
993 struct se_device
*dev
= lun
->lun_se_dev
;
995 struct se_portal_group
*tpg
;
999 spin_lock(&lun
->lun_sep_lock
);
1002 spin_unlock(&lun
->lun_sep_lock
);
1006 wwn
= &dev
->t10_wwn
;
1007 /* scsiTransportDevName */
1008 ret
= snprintf(page
, PAGE_SIZE
, "%s+%s\n",
1009 tpg
->se_tpg_tfo
->tpg_get_wwn(tpg
),
1010 (strlen(wwn
->unit_serial
)) ? wwn
->unit_serial
:
1012 spin_unlock(&lun
->lun_sep_lock
);
1015 DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name
);
1017 CONFIGFS_EATTR_OPS(target_stat_scsi_transport
, se_port_stat_grps
,
1018 scsi_transport_group
);
1020 static struct configfs_attribute
*target_stat_scsi_transport_attrs
[] = {
1021 &target_stat_scsi_transport_inst
.attr
,
1022 &target_stat_scsi_transport_device
.attr
,
1023 &target_stat_scsi_transport_indx
.attr
,
1024 &target_stat_scsi_transport_dev_name
.attr
,
1028 static struct configfs_item_operations target_stat_scsi_transport_attrib_ops
= {
1029 .show_attribute
= target_stat_scsi_transport_attr_show
,
1030 .store_attribute
= target_stat_scsi_transport_attr_store
,
1033 static struct config_item_type target_stat_scsi_transport_cit
= {
1034 .ct_item_ops
= &target_stat_scsi_transport_attrib_ops
,
1035 .ct_attrs
= target_stat_scsi_transport_attrs
,
1036 .ct_owner
= THIS_MODULE
,
1040 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1041 * the target port statistics groups + configfs CITs located in target_core_stat.c
1043 void target_stat_setup_port_default_groups(struct se_lun
*lun
)
1045 struct config_group
*port_stat_grp
= &lun
->port_stat_grps
.stat_group
;
1047 config_group_init_type_name(&lun
->port_stat_grps
.scsi_port_group
,
1048 "scsi_port", &target_stat_scsi_port_cit
);
1049 config_group_init_type_name(&lun
->port_stat_grps
.scsi_tgt_port_group
,
1050 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit
);
1051 config_group_init_type_name(&lun
->port_stat_grps
.scsi_transport_group
,
1052 "scsi_transport", &target_stat_scsi_transport_cit
);
1054 port_stat_grp
->default_groups
[0] = &lun
->port_stat_grps
.scsi_port_group
;
1055 port_stat_grp
->default_groups
[1] = &lun
->port_stat_grps
.scsi_tgt_port_group
;
1056 port_stat_grp
->default_groups
[2] = &lun
->port_stat_grps
.scsi_transport_group
;
1057 port_stat_grp
->default_groups
[3] = NULL
;
1061 * SCSI Authorized Initiator Table
1064 CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr
, se_ml_stat_grps
);
1065 #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \
1066 static struct target_stat_scsi_auth_intr_attribute \
1067 target_stat_scsi_auth_intr_##_name = \
1068 __CONFIGFS_EATTR(_name, _mode, \
1069 target_stat_scsi_auth_intr_show_attr_##_name, \
1070 target_stat_scsi_auth_intr_store_attr_##_name);
1072 #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \
1073 static struct target_stat_scsi_auth_intr_attribute \
1074 target_stat_scsi_auth_intr_##_name = \
1075 __CONFIGFS_EATTR_RO(_name, \
1076 target_stat_scsi_auth_intr_show_attr_##_name);
1078 static ssize_t
target_stat_scsi_auth_intr_show_attr_inst(
1079 struct se_ml_stat_grps
*lgrps
, char *page
)
1081 struct se_lun_acl
*lacl
= container_of(lgrps
,
1082 struct se_lun_acl
, ml_stat_grps
);
1083 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1084 struct se_dev_entry
*deve
;
1085 struct se_portal_group
*tpg
;
1088 spin_lock_irq(&nacl
->device_list_lock
);
1089 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1090 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1091 spin_unlock_irq(&nacl
->device_list_lock
);
1096 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1097 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
1098 spin_unlock_irq(&nacl
->device_list_lock
);
1101 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst
);
1103 static ssize_t
target_stat_scsi_auth_intr_show_attr_dev(
1104 struct se_ml_stat_grps
*lgrps
, char *page
)
1106 struct se_lun_acl
*lacl
= container_of(lgrps
,
1107 struct se_lun_acl
, ml_stat_grps
);
1108 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1109 struct se_dev_entry
*deve
;
1113 spin_lock_irq(&nacl
->device_list_lock
);
1114 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1115 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1116 spin_unlock_irq(&nacl
->device_list_lock
);
1120 /* scsiDeviceIndex */
1121 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_se_dev
->dev_index
);
1122 spin_unlock_irq(&nacl
->device_list_lock
);
1125 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev
);
1127 static ssize_t
target_stat_scsi_auth_intr_show_attr_port(
1128 struct se_ml_stat_grps
*lgrps
, char *page
)
1130 struct se_lun_acl
*lacl
= container_of(lgrps
,
1131 struct se_lun_acl
, ml_stat_grps
);
1132 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1133 struct se_dev_entry
*deve
;
1134 struct se_portal_group
*tpg
;
1137 spin_lock_irq(&nacl
->device_list_lock
);
1138 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1139 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1140 spin_unlock_irq(&nacl
->device_list_lock
);
1144 /* scsiAuthIntrTgtPortIndex */
1145 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
1146 spin_unlock_irq(&nacl
->device_list_lock
);
1149 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port
);
1151 static ssize_t
target_stat_scsi_auth_intr_show_attr_indx(
1152 struct se_ml_stat_grps
*lgrps
, char *page
)
1154 struct se_lun_acl
*lacl
= container_of(lgrps
,
1155 struct se_lun_acl
, ml_stat_grps
);
1156 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1157 struct se_dev_entry
*deve
;
1160 spin_lock_irq(&nacl
->device_list_lock
);
1161 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1162 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1163 spin_unlock_irq(&nacl
->device_list_lock
);
1166 /* scsiAuthIntrIndex */
1167 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
1168 spin_unlock_irq(&nacl
->device_list_lock
);
1171 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx
);
1173 static ssize_t
target_stat_scsi_auth_intr_show_attr_dev_or_port(
1174 struct se_ml_stat_grps
*lgrps
, char *page
)
1176 struct se_lun_acl
*lacl
= container_of(lgrps
,
1177 struct se_lun_acl
, ml_stat_grps
);
1178 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1179 struct se_dev_entry
*deve
;
1182 spin_lock_irq(&nacl
->device_list_lock
);
1183 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1184 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1185 spin_unlock_irq(&nacl
->device_list_lock
);
1188 /* scsiAuthIntrDevOrPort */
1189 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 1);
1190 spin_unlock_irq(&nacl
->device_list_lock
);
1193 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port
);
1195 static ssize_t
target_stat_scsi_auth_intr_show_attr_intr_name(
1196 struct se_ml_stat_grps
*lgrps
, char *page
)
1198 struct se_lun_acl
*lacl
= container_of(lgrps
,
1199 struct se_lun_acl
, ml_stat_grps
);
1200 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1201 struct se_dev_entry
*deve
;
1204 spin_lock_irq(&nacl
->device_list_lock
);
1205 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1206 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1207 spin_unlock_irq(&nacl
->device_list_lock
);
1210 /* scsiAuthIntrName */
1211 ret
= snprintf(page
, PAGE_SIZE
, "%s\n", nacl
->initiatorname
);
1212 spin_unlock_irq(&nacl
->device_list_lock
);
1215 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name
);
1217 static ssize_t
target_stat_scsi_auth_intr_show_attr_map_indx(
1218 struct se_ml_stat_grps
*lgrps
, char *page
)
1220 struct se_lun_acl
*lacl
= container_of(lgrps
,
1221 struct se_lun_acl
, ml_stat_grps
);
1222 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1223 struct se_dev_entry
*deve
;
1226 spin_lock_irq(&nacl
->device_list_lock
);
1227 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1228 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1229 spin_unlock_irq(&nacl
->device_list_lock
);
1232 /* FIXME: scsiAuthIntrLunMapIndex */
1233 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1234 spin_unlock_irq(&nacl
->device_list_lock
);
1237 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx
);
1239 static ssize_t
target_stat_scsi_auth_intr_show_attr_att_count(
1240 struct se_ml_stat_grps
*lgrps
, char *page
)
1242 struct se_lun_acl
*lacl
= container_of(lgrps
,
1243 struct se_lun_acl
, ml_stat_grps
);
1244 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1245 struct se_dev_entry
*deve
;
1248 spin_lock_irq(&nacl
->device_list_lock
);
1249 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1250 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1251 spin_unlock_irq(&nacl
->device_list_lock
);
1254 /* scsiAuthIntrAttachedTimes */
1255 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->attach_count
);
1256 spin_unlock_irq(&nacl
->device_list_lock
);
1259 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count
);
1261 static ssize_t
target_stat_scsi_auth_intr_show_attr_num_cmds(
1262 struct se_ml_stat_grps
*lgrps
, char *page
)
1264 struct se_lun_acl
*lacl
= container_of(lgrps
,
1265 struct se_lun_acl
, ml_stat_grps
);
1266 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1267 struct se_dev_entry
*deve
;
1270 spin_lock_irq(&nacl
->device_list_lock
);
1271 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1272 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1273 spin_unlock_irq(&nacl
->device_list_lock
);
1276 /* scsiAuthIntrOutCommands */
1277 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", deve
->total_cmds
);
1278 spin_unlock_irq(&nacl
->device_list_lock
);
1281 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds
);
1283 static ssize_t
target_stat_scsi_auth_intr_show_attr_read_mbytes(
1284 struct se_ml_stat_grps
*lgrps
, char *page
)
1286 struct se_lun_acl
*lacl
= container_of(lgrps
,
1287 struct se_lun_acl
, ml_stat_grps
);
1288 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1289 struct se_dev_entry
*deve
;
1292 spin_lock_irq(&nacl
->device_list_lock
);
1293 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1294 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1295 spin_unlock_irq(&nacl
->device_list_lock
);
1298 /* scsiAuthIntrReadMegaBytes */
1299 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(deve
->read_bytes
>> 20));
1300 spin_unlock_irq(&nacl
->device_list_lock
);
1303 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes
);
1305 static ssize_t
target_stat_scsi_auth_intr_show_attr_write_mbytes(
1306 struct se_ml_stat_grps
*lgrps
, char *page
)
1308 struct se_lun_acl
*lacl
= container_of(lgrps
,
1309 struct se_lun_acl
, ml_stat_grps
);
1310 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1311 struct se_dev_entry
*deve
;
1314 spin_lock_irq(&nacl
->device_list_lock
);
1315 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1316 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1317 spin_unlock_irq(&nacl
->device_list_lock
);
1320 /* scsiAuthIntrWrittenMegaBytes */
1321 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(deve
->write_bytes
>> 20));
1322 spin_unlock_irq(&nacl
->device_list_lock
);
1325 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes
);
1327 static ssize_t
target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1328 struct se_ml_stat_grps
*lgrps
, char *page
)
1330 struct se_lun_acl
*lacl
= container_of(lgrps
,
1331 struct se_lun_acl
, ml_stat_grps
);
1332 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1333 struct se_dev_entry
*deve
;
1336 spin_lock_irq(&nacl
->device_list_lock
);
1337 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1338 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1339 spin_unlock_irq(&nacl
->device_list_lock
);
1342 /* FIXME: scsiAuthIntrHSOutCommands */
1343 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", 0);
1344 spin_unlock_irq(&nacl
->device_list_lock
);
1347 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds
);
1349 static ssize_t
target_stat_scsi_auth_intr_show_attr_creation_time(
1350 struct se_ml_stat_grps
*lgrps
, char *page
)
1352 struct se_lun_acl
*lacl
= container_of(lgrps
,
1353 struct se_lun_acl
, ml_stat_grps
);
1354 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1355 struct se_dev_entry
*deve
;
1358 spin_lock_irq(&nacl
->device_list_lock
);
1359 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1360 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1361 spin_unlock_irq(&nacl
->device_list_lock
);
1364 /* scsiAuthIntrLastCreation */
1365 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", (u32
)(((u32
)deve
->creation_time
-
1366 INITIAL_JIFFIES
) * 100 / HZ
));
1367 spin_unlock_irq(&nacl
->device_list_lock
);
1370 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time
);
1372 static ssize_t
target_stat_scsi_auth_intr_show_attr_row_status(
1373 struct se_ml_stat_grps
*lgrps
, char *page
)
1375 struct se_lun_acl
*lacl
= container_of(lgrps
,
1376 struct se_lun_acl
, ml_stat_grps
);
1377 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1378 struct se_dev_entry
*deve
;
1381 spin_lock_irq(&nacl
->device_list_lock
);
1382 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1383 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1384 spin_unlock_irq(&nacl
->device_list_lock
);
1387 /* FIXME: scsiAuthIntrRowStatus */
1388 ret
= snprintf(page
, PAGE_SIZE
, "Ready\n");
1389 spin_unlock_irq(&nacl
->device_list_lock
);
1392 DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status
);
1394 CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr
, se_ml_stat_grps
,
1395 scsi_auth_intr_group
);
1397 static struct configfs_attribute
*target_stat_scsi_auth_intr_attrs
[] = {
1398 &target_stat_scsi_auth_intr_inst
.attr
,
1399 &target_stat_scsi_auth_intr_dev
.attr
,
1400 &target_stat_scsi_auth_intr_port
.attr
,
1401 &target_stat_scsi_auth_intr_indx
.attr
,
1402 &target_stat_scsi_auth_intr_dev_or_port
.attr
,
1403 &target_stat_scsi_auth_intr_intr_name
.attr
,
1404 &target_stat_scsi_auth_intr_map_indx
.attr
,
1405 &target_stat_scsi_auth_intr_att_count
.attr
,
1406 &target_stat_scsi_auth_intr_num_cmds
.attr
,
1407 &target_stat_scsi_auth_intr_read_mbytes
.attr
,
1408 &target_stat_scsi_auth_intr_write_mbytes
.attr
,
1409 &target_stat_scsi_auth_intr_hs_num_cmds
.attr
,
1410 &target_stat_scsi_auth_intr_creation_time
.attr
,
1411 &target_stat_scsi_auth_intr_row_status
.attr
,
1415 static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops
= {
1416 .show_attribute
= target_stat_scsi_auth_intr_attr_show
,
1417 .store_attribute
= target_stat_scsi_auth_intr_attr_store
,
1420 static struct config_item_type target_stat_scsi_auth_intr_cit
= {
1421 .ct_item_ops
= &target_stat_scsi_auth_intr_attrib_ops
,
1422 .ct_attrs
= target_stat_scsi_auth_intr_attrs
,
1423 .ct_owner
= THIS_MODULE
,
1427 * SCSI Attached Initiator Port Table
1430 CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port
, se_ml_stat_grps
);
1431 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \
1432 static struct target_stat_scsi_att_intr_port_attribute \
1433 target_stat_scsi_att_intr_port_##_name = \
1434 __CONFIGFS_EATTR(_name, _mode, \
1435 target_stat_scsi_att_intr_port_show_attr_##_name, \
1436 target_stat_scsi_att_intr_port_store_attr_##_name);
1438 #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \
1439 static struct target_stat_scsi_att_intr_port_attribute \
1440 target_stat_scsi_att_intr_port_##_name = \
1441 __CONFIGFS_EATTR_RO(_name, \
1442 target_stat_scsi_att_intr_port_show_attr_##_name);
1444 static ssize_t
target_stat_scsi_att_intr_port_show_attr_inst(
1445 struct se_ml_stat_grps
*lgrps
, char *page
)
1447 struct se_lun_acl
*lacl
= container_of(lgrps
,
1448 struct se_lun_acl
, ml_stat_grps
);
1449 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1450 struct se_dev_entry
*deve
;
1451 struct se_portal_group
*tpg
;
1454 spin_lock_irq(&nacl
->device_list_lock
);
1455 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1456 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1457 spin_unlock_irq(&nacl
->device_list_lock
);
1462 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1463 tpg
->se_tpg_tfo
->tpg_get_inst_index(tpg
));
1464 spin_unlock_irq(&nacl
->device_list_lock
);
1467 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst
);
1469 static ssize_t
target_stat_scsi_att_intr_port_show_attr_dev(
1470 struct se_ml_stat_grps
*lgrps
, char *page
)
1472 struct se_lun_acl
*lacl
= container_of(lgrps
,
1473 struct se_lun_acl
, ml_stat_grps
);
1474 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1475 struct se_dev_entry
*deve
;
1479 spin_lock_irq(&nacl
->device_list_lock
);
1480 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1481 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1482 spin_unlock_irq(&nacl
->device_list_lock
);
1486 /* scsiDeviceIndex */
1487 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", lun
->lun_se_dev
->dev_index
);
1488 spin_unlock_irq(&nacl
->device_list_lock
);
1491 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev
);
1493 static ssize_t
target_stat_scsi_att_intr_port_show_attr_port(
1494 struct se_ml_stat_grps
*lgrps
, char *page
)
1496 struct se_lun_acl
*lacl
= container_of(lgrps
,
1497 struct se_lun_acl
, ml_stat_grps
);
1498 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1499 struct se_dev_entry
*deve
;
1500 struct se_portal_group
*tpg
;
1503 spin_lock_irq(&nacl
->device_list_lock
);
1504 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1505 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1506 spin_unlock_irq(&nacl
->device_list_lock
);
1511 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", tpg
->se_tpg_tfo
->tpg_get_tag(tpg
));
1512 spin_unlock_irq(&nacl
->device_list_lock
);
1515 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port
);
1517 static ssize_t
target_stat_scsi_att_intr_port_show_attr_indx(
1518 struct se_ml_stat_grps
*lgrps
, char *page
)
1520 struct se_lun_acl
*lacl
= container_of(lgrps
,
1521 struct se_lun_acl
, ml_stat_grps
);
1522 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1523 struct se_session
*se_sess
;
1524 struct se_portal_group
*tpg
;
1527 spin_lock_irq(&nacl
->nacl_sess_lock
);
1528 se_sess
= nacl
->nacl_sess
;
1530 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1535 /* scsiAttIntrPortIndex */
1536 ret
= snprintf(page
, PAGE_SIZE
, "%u\n",
1537 tpg
->se_tpg_tfo
->sess_get_index(se_sess
));
1538 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1541 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx
);
1543 static ssize_t
target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1544 struct se_ml_stat_grps
*lgrps
, char *page
)
1546 struct se_lun_acl
*lacl
= container_of(lgrps
,
1547 struct se_lun_acl
, ml_stat_grps
);
1548 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1549 struct se_dev_entry
*deve
;
1552 spin_lock_irq(&nacl
->device_list_lock
);
1553 deve
= nacl
->device_list
[lacl
->mapped_lun
];
1554 if (!deve
->se_lun
|| !deve
->se_lun_acl
) {
1555 spin_unlock_irq(&nacl
->device_list_lock
);
1558 /* scsiAttIntrPortAuthIntrIdx */
1559 ret
= snprintf(page
, PAGE_SIZE
, "%u\n", nacl
->acl_index
);
1560 spin_unlock_irq(&nacl
->device_list_lock
);
1563 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx
);
1565 static ssize_t
target_stat_scsi_att_intr_port_show_attr_port_ident(
1566 struct se_ml_stat_grps
*lgrps
, char *page
)
1568 struct se_lun_acl
*lacl
= container_of(lgrps
,
1569 struct se_lun_acl
, ml_stat_grps
);
1570 struct se_node_acl
*nacl
= lacl
->se_lun_nacl
;
1571 struct se_session
*se_sess
;
1572 struct se_portal_group
*tpg
;
1574 unsigned char buf
[64];
1576 spin_lock_irq(&nacl
->nacl_sess_lock
);
1577 se_sess
= nacl
->nacl_sess
;
1579 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1584 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1586 if (tpg
->se_tpg_tfo
->sess_get_initiator_sid
!= NULL
)
1587 tpg
->se_tpg_tfo
->sess_get_initiator_sid(se_sess
, buf
, 64);
1589 ret
= snprintf(page
, PAGE_SIZE
, "%s+i+%s\n", nacl
->initiatorname
, buf
);
1590 spin_unlock_irq(&nacl
->nacl_sess_lock
);
1593 DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident
);
1595 CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port
, se_ml_stat_grps
,
1596 scsi_att_intr_port_group
);
1598 static struct configfs_attribute
*target_stat_scsi_ath_intr_port_attrs
[] = {
1599 &target_stat_scsi_att_intr_port_inst
.attr
,
1600 &target_stat_scsi_att_intr_port_dev
.attr
,
1601 &target_stat_scsi_att_intr_port_port
.attr
,
1602 &target_stat_scsi_att_intr_port_indx
.attr
,
1603 &target_stat_scsi_att_intr_port_port_auth_indx
.attr
,
1604 &target_stat_scsi_att_intr_port_port_ident
.attr
,
1608 static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops
= {
1609 .show_attribute
= target_stat_scsi_att_intr_port_attr_show
,
1610 .store_attribute
= target_stat_scsi_att_intr_port_attr_store
,
1613 static struct config_item_type target_stat_scsi_att_intr_port_cit
= {
1614 .ct_item_ops
= &target_stat_scsi_att_intr_port_attrib_ops
,
1615 .ct_attrs
= target_stat_scsi_ath_intr_port_attrs
,
1616 .ct_owner
= THIS_MODULE
,
1620 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1621 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1623 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl
*lacl
)
1625 struct config_group
*ml_stat_grp
= &lacl
->ml_stat_grps
.stat_group
;
1627 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_auth_intr_group
,
1628 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit
);
1629 config_group_init_type_name(&lacl
->ml_stat_grps
.scsi_att_intr_port_group
,
1630 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit
);
1632 ml_stat_grp
->default_groups
[0] = &lacl
->ml_stat_grps
.scsi_auth_intr_group
;
1633 ml_stat_grp
->default_groups
[1] = &lacl
->ml_stat_grps
.scsi_att_intr_port_group
;
1634 ml_stat_grp
->default_groups
[2] = NULL
;