Merge tag 'riscv-for-linus-4.15-rc4-riscv_fixes' of git://git.kernel.org/pub/scm...
[linux/fpc-iii.git] / drivers / target / target_core_stat.c
blobf0db91ebd735d65fd102453ef2417560fb7229df
1 /*******************************************************************************
2 * Filename: target_core_stat.c
4 * Modern ConfigFS group context specific statistics based on original
5 * target_core_mib.c code
7 * (c) Copyright 2006-2013 Datera, Inc.
9 * Nicholas A. Bellinger <nab@linux-iscsi.org>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 ******************************************************************************/
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/delay.h>
30 #include <linux/timer.h>
31 #include <linux/string.h>
32 #include <linux/utsname.h>
33 #include <linux/proc_fs.h>
34 #include <linux/seq_file.h>
35 #include <linux/configfs.h>
37 #include <target/target_core_base.h>
38 #include <target/target_core_backend.h>
39 #include <target/target_core_fabric.h>
41 #include "target_core_internal.h"
43 #ifndef INITIAL_JIFFIES
44 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
45 #endif
47 #define NONE "None"
48 #define ISPRINT(a) ((a >= ' ') && (a <= '~'))
50 #define SCSI_LU_INDEX 1
51 #define LU_COUNT 1
54 * SCSI Device Table
57 static struct se_device *to_stat_dev(struct config_item *item)
59 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
60 struct se_dev_stat_grps, scsi_dev_group);
61 return container_of(sgrps, struct se_device, dev_stat_grps);
64 static ssize_t target_stat_inst_show(struct config_item *item, char *page)
66 struct se_hba *hba = to_stat_dev(item)->se_hba;
68 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
71 static ssize_t target_stat_indx_show(struct config_item *item, char *page)
73 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
76 static ssize_t target_stat_role_show(struct config_item *item, char *page)
78 return snprintf(page, PAGE_SIZE, "Target\n");
81 static ssize_t target_stat_ports_show(struct config_item *item, char *page)
83 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
86 CONFIGFS_ATTR_RO(target_stat_, inst);
87 CONFIGFS_ATTR_RO(target_stat_, indx);
88 CONFIGFS_ATTR_RO(target_stat_, role);
89 CONFIGFS_ATTR_RO(target_stat_, ports);
91 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
92 &target_stat_attr_inst,
93 &target_stat_attr_indx,
94 &target_stat_attr_role,
95 &target_stat_attr_ports,
96 NULL,
99 static const struct config_item_type target_stat_scsi_dev_cit = {
100 .ct_attrs = target_stat_scsi_dev_attrs,
101 .ct_owner = THIS_MODULE,
105 * SCSI Target Device Table
107 static struct se_device *to_stat_tgt_dev(struct config_item *item)
109 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
110 struct se_dev_stat_grps, scsi_tgt_dev_group);
111 return container_of(sgrps, struct se_device, dev_stat_grps);
114 static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
116 struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
118 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
121 static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
123 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
126 static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
127 char *page)
129 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
132 static ssize_t target_stat_tgt_status_show(struct config_item *item,
133 char *page)
135 if (to_stat_tgt_dev(item)->export_count)
136 return snprintf(page, PAGE_SIZE, "activated");
137 else
138 return snprintf(page, PAGE_SIZE, "deactivated");
141 static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
142 char *page)
144 int non_accessible_lus;
146 if (to_stat_tgt_dev(item)->export_count)
147 non_accessible_lus = 0;
148 else
149 non_accessible_lus = 1;
151 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
154 static ssize_t target_stat_tgt_resets_show(struct config_item *item,
155 char *page)
157 return snprintf(page, PAGE_SIZE, "%lu\n",
158 atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
161 static ssize_t target_stat_tgt_aborts_complete_show(struct config_item *item,
162 char *page)
164 return snprintf(page, PAGE_SIZE, "%lu\n",
165 atomic_long_read(&to_stat_tgt_dev(item)->aborts_complete));
168 static ssize_t target_stat_tgt_aborts_no_task_show(struct config_item *item,
169 char *page)
171 return snprintf(page, PAGE_SIZE, "%lu\n",
172 atomic_long_read(&to_stat_tgt_dev(item)->aborts_no_task));
175 CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
176 CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
177 CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
178 CONFIGFS_ATTR_RO(target_stat_tgt_, status);
179 CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
180 CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
181 CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_complete);
182 CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_no_task);
184 static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
185 &target_stat_tgt_attr_inst,
186 &target_stat_tgt_attr_indx,
187 &target_stat_tgt_attr_num_lus,
188 &target_stat_tgt_attr_status,
189 &target_stat_tgt_attr_non_access_lus,
190 &target_stat_tgt_attr_resets,
191 &target_stat_tgt_attr_aborts_complete,
192 &target_stat_tgt_attr_aborts_no_task,
193 NULL,
196 static const struct config_item_type target_stat_scsi_tgt_dev_cit = {
197 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
198 .ct_owner = THIS_MODULE,
202 * SCSI Logical Unit Table
205 static struct se_device *to_stat_lu_dev(struct config_item *item)
207 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
208 struct se_dev_stat_grps, scsi_lu_group);
209 return container_of(sgrps, struct se_device, dev_stat_grps);
212 static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
214 struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
216 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
219 static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
221 return snprintf(page, PAGE_SIZE, "%u\n",
222 to_stat_lu_dev(item)->dev_index);
225 static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
227 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
230 static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
232 /* FIXME: scsiLuDefaultLun */
233 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
236 static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
238 struct se_device *dev = to_stat_lu_dev(item);
240 /* scsiLuWwnName */
241 return snprintf(page, PAGE_SIZE, "%s\n",
242 (strlen(dev->t10_wwn.unit_serial)) ?
243 dev->t10_wwn.unit_serial : "None");
246 static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
248 struct se_device *dev = to_stat_lu_dev(item);
249 int i;
250 char str[sizeof(dev->t10_wwn.vendor)+1];
252 /* scsiLuVendorId */
253 for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
254 str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ?
255 dev->t10_wwn.vendor[i] : ' ';
256 str[i] = '\0';
257 return snprintf(page, PAGE_SIZE, "%s\n", str);
260 static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
262 struct se_device *dev = to_stat_lu_dev(item);
263 int i;
264 char str[sizeof(dev->t10_wwn.model)+1];
266 /* scsiLuProductId */
267 for (i = 0; i < sizeof(dev->t10_wwn.model); i++)
268 str[i] = ISPRINT(dev->t10_wwn.model[i]) ?
269 dev->t10_wwn.model[i] : ' ';
270 str[i] = '\0';
271 return snprintf(page, PAGE_SIZE, "%s\n", str);
274 static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
276 struct se_device *dev = to_stat_lu_dev(item);
277 int i;
278 char str[sizeof(dev->t10_wwn.revision)+1];
280 /* scsiLuRevisionId */
281 for (i = 0; i < sizeof(dev->t10_wwn.revision); i++)
282 str[i] = ISPRINT(dev->t10_wwn.revision[i]) ?
283 dev->t10_wwn.revision[i] : ' ';
284 str[i] = '\0';
285 return snprintf(page, PAGE_SIZE, "%s\n", str);
288 static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
290 struct se_device *dev = to_stat_lu_dev(item);
292 /* scsiLuPeripheralType */
293 return snprintf(page, PAGE_SIZE, "%u\n",
294 dev->transport->get_device_type(dev));
297 static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
299 struct se_device *dev = to_stat_lu_dev(item);
301 /* scsiLuStatus */
302 return snprintf(page, PAGE_SIZE, "%s\n",
303 (dev->export_count) ? "available" : "notavailable");
306 static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
307 char *page)
309 /* scsiLuState */
310 return snprintf(page, PAGE_SIZE, "exposed\n");
313 static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
314 char *page)
316 struct se_device *dev = to_stat_lu_dev(item);
318 /* scsiLuNumCommands */
319 return snprintf(page, PAGE_SIZE, "%lu\n",
320 atomic_long_read(&dev->num_cmds));
323 static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
324 char *page)
326 struct se_device *dev = to_stat_lu_dev(item);
328 /* scsiLuReadMegaBytes */
329 return snprintf(page, PAGE_SIZE, "%lu\n",
330 atomic_long_read(&dev->read_bytes) >> 20);
333 static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
334 char *page)
336 struct se_device *dev = to_stat_lu_dev(item);
338 /* scsiLuWrittenMegaBytes */
339 return snprintf(page, PAGE_SIZE, "%lu\n",
340 atomic_long_read(&dev->write_bytes) >> 20);
343 static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
345 struct se_device *dev = to_stat_lu_dev(item);
347 /* scsiLuInResets */
348 return snprintf(page, PAGE_SIZE, "%lu\n",
349 atomic_long_read(&dev->num_resets));
352 static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
353 char *page)
355 /* FIXME: scsiLuOutTaskSetFullStatus */
356 return snprintf(page, PAGE_SIZE, "%u\n", 0);
359 static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
360 char *page)
362 /* FIXME: scsiLuHSInCommands */
363 return snprintf(page, PAGE_SIZE, "%u\n", 0);
366 static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
367 char *page)
369 struct se_device *dev = to_stat_lu_dev(item);
371 /* scsiLuCreationTime */
372 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
373 INITIAL_JIFFIES) * 100 / HZ));
376 CONFIGFS_ATTR_RO(target_stat_lu_, inst);
377 CONFIGFS_ATTR_RO(target_stat_lu_, dev);
378 CONFIGFS_ATTR_RO(target_stat_lu_, indx);
379 CONFIGFS_ATTR_RO(target_stat_lu_, lun);
380 CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
381 CONFIGFS_ATTR_RO(target_stat_lu_, vend);
382 CONFIGFS_ATTR_RO(target_stat_lu_, prod);
383 CONFIGFS_ATTR_RO(target_stat_lu_, rev);
384 CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
385 CONFIGFS_ATTR_RO(target_stat_lu_, status);
386 CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
387 CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
388 CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
389 CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
390 CONFIGFS_ATTR_RO(target_stat_lu_, resets);
391 CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
392 CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
393 CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
395 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
396 &target_stat_lu_attr_inst,
397 &target_stat_lu_attr_dev,
398 &target_stat_lu_attr_indx,
399 &target_stat_lu_attr_lun,
400 &target_stat_lu_attr_lu_name,
401 &target_stat_lu_attr_vend,
402 &target_stat_lu_attr_prod,
403 &target_stat_lu_attr_rev,
404 &target_stat_lu_attr_dev_type,
405 &target_stat_lu_attr_status,
406 &target_stat_lu_attr_state_bit,
407 &target_stat_lu_attr_num_cmds,
408 &target_stat_lu_attr_read_mbytes,
409 &target_stat_lu_attr_write_mbytes,
410 &target_stat_lu_attr_resets,
411 &target_stat_lu_attr_full_stat,
412 &target_stat_lu_attr_hs_num_cmds,
413 &target_stat_lu_attr_creation_time,
414 NULL,
417 static const struct config_item_type target_stat_scsi_lu_cit = {
418 .ct_attrs = target_stat_scsi_lu_attrs,
419 .ct_owner = THIS_MODULE,
423 * Called from target_core_configfs.c:target_core_make_subdev() to setup
424 * the target statistics groups + configfs CITs located in target_core_stat.c
426 void target_stat_setup_dev_default_groups(struct se_device *dev)
428 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
429 "scsi_dev", &target_stat_scsi_dev_cit);
430 configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group,
431 &dev->dev_stat_grps.stat_group);
433 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
434 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
435 configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group,
436 &dev->dev_stat_grps.stat_group);
438 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
439 "scsi_lu", &target_stat_scsi_lu_cit);
440 configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group,
441 &dev->dev_stat_grps.stat_group);
445 * SCSI Port Table
448 static struct se_lun *to_stat_port(struct config_item *item)
450 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
451 struct se_port_stat_grps, scsi_port_group);
452 return container_of(pgrps, struct se_lun, port_stat_grps);
455 static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
457 struct se_lun *lun = to_stat_port(item);
458 struct se_device *dev;
459 ssize_t ret = -ENODEV;
461 rcu_read_lock();
462 dev = rcu_dereference(lun->lun_se_dev);
463 if (dev)
464 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
465 rcu_read_unlock();
466 return ret;
469 static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
471 struct se_lun *lun = to_stat_port(item);
472 struct se_device *dev;
473 ssize_t ret = -ENODEV;
475 rcu_read_lock();
476 dev = rcu_dereference(lun->lun_se_dev);
477 if (dev)
478 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
479 rcu_read_unlock();
480 return ret;
483 static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
485 struct se_lun *lun = to_stat_port(item);
486 struct se_device *dev;
487 ssize_t ret = -ENODEV;
489 rcu_read_lock();
490 dev = rcu_dereference(lun->lun_se_dev);
491 if (dev)
492 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
493 rcu_read_unlock();
494 return ret;
497 static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
499 struct se_lun *lun = to_stat_port(item);
500 struct se_device *dev;
501 ssize_t ret = -ENODEV;
503 rcu_read_lock();
504 dev = rcu_dereference(lun->lun_se_dev);
505 if (dev)
506 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
507 rcu_read_unlock();
508 return ret;
511 static ssize_t target_stat_port_busy_count_show(struct config_item *item,
512 char *page)
514 struct se_lun *lun = to_stat_port(item);
515 struct se_device *dev;
516 ssize_t ret = -ENODEV;
518 rcu_read_lock();
519 dev = rcu_dereference(lun->lun_se_dev);
520 if (dev) {
521 /* FIXME: scsiPortBusyStatuses */
522 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
524 rcu_read_unlock();
525 return ret;
528 CONFIGFS_ATTR_RO(target_stat_port_, inst);
529 CONFIGFS_ATTR_RO(target_stat_port_, dev);
530 CONFIGFS_ATTR_RO(target_stat_port_, indx);
531 CONFIGFS_ATTR_RO(target_stat_port_, role);
532 CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
534 static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
535 &target_stat_port_attr_inst,
536 &target_stat_port_attr_dev,
537 &target_stat_port_attr_indx,
538 &target_stat_port_attr_role,
539 &target_stat_port_attr_busy_count,
540 NULL,
543 static const struct config_item_type target_stat_scsi_port_cit = {
544 .ct_attrs = target_stat_scsi_port_attrs,
545 .ct_owner = THIS_MODULE,
549 * SCSI Target Port Table
551 static struct se_lun *to_stat_tgt_port(struct config_item *item)
553 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
554 struct se_port_stat_grps, scsi_tgt_port_group);
555 return container_of(pgrps, struct se_lun, port_stat_grps);
558 static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
559 char *page)
561 struct se_lun *lun = to_stat_tgt_port(item);
562 struct se_device *dev;
563 ssize_t ret = -ENODEV;
565 rcu_read_lock();
566 dev = rcu_dereference(lun->lun_se_dev);
567 if (dev)
568 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
569 rcu_read_unlock();
570 return ret;
573 static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
574 char *page)
576 struct se_lun *lun = to_stat_tgt_port(item);
577 struct se_device *dev;
578 ssize_t ret = -ENODEV;
580 rcu_read_lock();
581 dev = rcu_dereference(lun->lun_se_dev);
582 if (dev)
583 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
584 rcu_read_unlock();
585 return ret;
588 static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
589 char *page)
591 struct se_lun *lun = to_stat_tgt_port(item);
592 struct se_device *dev;
593 ssize_t ret = -ENODEV;
595 rcu_read_lock();
596 dev = rcu_dereference(lun->lun_se_dev);
597 if (dev)
598 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
599 rcu_read_unlock();
600 return ret;
603 static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
604 char *page)
606 struct se_lun *lun = to_stat_tgt_port(item);
607 struct se_portal_group *tpg = lun->lun_tpg;
608 struct se_device *dev;
609 ssize_t ret = -ENODEV;
611 rcu_read_lock();
612 dev = rcu_dereference(lun->lun_se_dev);
613 if (dev)
614 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
615 tpg->se_tpg_tfo->get_fabric_name(),
616 lun->lun_rtpi);
617 rcu_read_unlock();
618 return ret;
621 static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
622 char *page)
624 struct se_lun *lun = to_stat_tgt_port(item);
625 struct se_portal_group *tpg = lun->lun_tpg;
626 struct se_device *dev;
627 ssize_t ret = -ENODEV;
629 rcu_read_lock();
630 dev = rcu_dereference(lun->lun_se_dev);
631 if (dev)
632 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
633 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
634 tpg->se_tpg_tfo->tpg_get_tag(tpg));
635 rcu_read_unlock();
636 return ret;
639 static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
640 char *page)
642 struct se_lun *lun = to_stat_tgt_port(item);
643 struct se_device *dev;
644 ssize_t ret = -ENODEV;
646 rcu_read_lock();
647 dev = rcu_dereference(lun->lun_se_dev);
648 if (dev)
649 ret = snprintf(page, PAGE_SIZE, "%lu\n",
650 atomic_long_read(&lun->lun_stats.cmd_pdus));
651 rcu_read_unlock();
652 return ret;
655 static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
656 char *page)
658 struct se_lun *lun = to_stat_tgt_port(item);
659 struct se_device *dev;
660 ssize_t ret = -ENODEV;
662 rcu_read_lock();
663 dev = rcu_dereference(lun->lun_se_dev);
664 if (dev)
665 ret = snprintf(page, PAGE_SIZE, "%u\n",
666 (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
667 rcu_read_unlock();
668 return ret;
671 static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
672 char *page)
674 struct se_lun *lun = to_stat_tgt_port(item);
675 struct se_device *dev;
676 ssize_t ret = -ENODEV;
678 rcu_read_lock();
679 dev = rcu_dereference(lun->lun_se_dev);
680 if (dev)
681 ret = snprintf(page, PAGE_SIZE, "%u\n",
682 (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
683 rcu_read_unlock();
684 return ret;
687 static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
688 char *page)
690 struct se_lun *lun = to_stat_tgt_port(item);
691 struct se_device *dev;
692 ssize_t ret = -ENODEV;
694 rcu_read_lock();
695 dev = rcu_dereference(lun->lun_se_dev);
696 if (dev) {
697 /* FIXME: scsiTgtPortHsInCommands */
698 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
700 rcu_read_unlock();
701 return ret;
704 CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
705 CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
706 CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
707 CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
708 CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
709 CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
710 CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
711 CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
712 CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
714 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
715 &target_stat_tgt_port_attr_inst,
716 &target_stat_tgt_port_attr_dev,
717 &target_stat_tgt_port_attr_indx,
718 &target_stat_tgt_port_attr_name,
719 &target_stat_tgt_port_attr_port_index,
720 &target_stat_tgt_port_attr_in_cmds,
721 &target_stat_tgt_port_attr_write_mbytes,
722 &target_stat_tgt_port_attr_read_mbytes,
723 &target_stat_tgt_port_attr_hs_in_cmds,
724 NULL,
727 static const struct config_item_type target_stat_scsi_tgt_port_cit = {
728 .ct_attrs = target_stat_scsi_tgt_port_attrs,
729 .ct_owner = THIS_MODULE,
733 * SCSI Transport Table
735 static struct se_lun *to_transport_stat(struct config_item *item)
737 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
738 struct se_port_stat_grps, scsi_transport_group);
739 return container_of(pgrps, struct se_lun, port_stat_grps);
742 static ssize_t target_stat_transport_inst_show(struct config_item *item,
743 char *page)
745 struct se_lun *lun = to_transport_stat(item);
746 struct se_device *dev;
747 ssize_t ret = -ENODEV;
749 rcu_read_lock();
750 dev = rcu_dereference(lun->lun_se_dev);
751 if (dev)
752 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
753 rcu_read_unlock();
754 return ret;
757 static ssize_t target_stat_transport_device_show(struct config_item *item,
758 char *page)
760 struct se_lun *lun = to_transport_stat(item);
761 struct se_device *dev;
762 struct se_portal_group *tpg = lun->lun_tpg;
763 ssize_t ret = -ENODEV;
765 rcu_read_lock();
766 dev = rcu_dereference(lun->lun_se_dev);
767 if (dev) {
768 /* scsiTransportType */
769 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
770 tpg->se_tpg_tfo->get_fabric_name());
772 rcu_read_unlock();
773 return ret;
776 static ssize_t target_stat_transport_indx_show(struct config_item *item,
777 char *page)
779 struct se_lun *lun = to_transport_stat(item);
780 struct se_device *dev;
781 struct se_portal_group *tpg = lun->lun_tpg;
782 ssize_t ret = -ENODEV;
784 rcu_read_lock();
785 dev = rcu_dereference(lun->lun_se_dev);
786 if (dev)
787 ret = snprintf(page, PAGE_SIZE, "%u\n",
788 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
789 rcu_read_unlock();
790 return ret;
793 static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
794 char *page)
796 struct se_lun *lun = to_transport_stat(item);
797 struct se_device *dev;
798 struct se_portal_group *tpg = lun->lun_tpg;
799 struct t10_wwn *wwn;
800 ssize_t ret = -ENODEV;
802 rcu_read_lock();
803 dev = rcu_dereference(lun->lun_se_dev);
804 if (dev) {
805 wwn = &dev->t10_wwn;
806 /* scsiTransportDevName */
807 ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
808 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
809 (strlen(wwn->unit_serial)) ? wwn->unit_serial :
810 wwn->vendor);
812 rcu_read_unlock();
813 return ret;
816 static ssize_t target_stat_transport_proto_id_show(struct config_item *item,
817 char *page)
819 struct se_lun *lun = to_transport_stat(item);
820 struct se_device *dev;
821 struct se_portal_group *tpg = lun->lun_tpg;
822 ssize_t ret = -ENODEV;
824 rcu_read_lock();
825 dev = rcu_dereference(lun->lun_se_dev);
826 if (dev)
827 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->proto_id);
828 rcu_read_unlock();
829 return ret;
832 CONFIGFS_ATTR_RO(target_stat_transport_, inst);
833 CONFIGFS_ATTR_RO(target_stat_transport_, device);
834 CONFIGFS_ATTR_RO(target_stat_transport_, indx);
835 CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
836 CONFIGFS_ATTR_RO(target_stat_transport_, proto_id);
838 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
839 &target_stat_transport_attr_inst,
840 &target_stat_transport_attr_device,
841 &target_stat_transport_attr_indx,
842 &target_stat_transport_attr_dev_name,
843 &target_stat_transport_attr_proto_id,
844 NULL,
847 static const struct config_item_type target_stat_scsi_transport_cit = {
848 .ct_attrs = target_stat_scsi_transport_attrs,
849 .ct_owner = THIS_MODULE,
853 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
854 * the target port statistics groups + configfs CITs located in target_core_stat.c
856 void target_stat_setup_port_default_groups(struct se_lun *lun)
858 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
859 "scsi_port", &target_stat_scsi_port_cit);
860 configfs_add_default_group(&lun->port_stat_grps.scsi_port_group,
861 &lun->port_stat_grps.stat_group);
863 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
864 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
865 configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group,
866 &lun->port_stat_grps.stat_group);
868 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
869 "scsi_transport", &target_stat_scsi_transport_cit);
870 configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group,
871 &lun->port_stat_grps.stat_group);
875 * SCSI Authorized Initiator Table
878 static struct se_lun_acl *auth_to_lacl(struct config_item *item)
880 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
881 struct se_ml_stat_grps, scsi_auth_intr_group);
882 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
885 static ssize_t target_stat_auth_inst_show(struct config_item *item,
886 char *page)
888 struct se_lun_acl *lacl = auth_to_lacl(item);
889 struct se_node_acl *nacl = lacl->se_lun_nacl;
890 struct se_dev_entry *deve;
891 struct se_portal_group *tpg;
892 ssize_t ret;
894 rcu_read_lock();
895 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
896 if (!deve) {
897 rcu_read_unlock();
898 return -ENODEV;
900 tpg = nacl->se_tpg;
901 /* scsiInstIndex */
902 ret = snprintf(page, PAGE_SIZE, "%u\n",
903 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
904 rcu_read_unlock();
905 return ret;
908 static ssize_t target_stat_auth_dev_show(struct config_item *item,
909 char *page)
911 struct se_lun_acl *lacl = auth_to_lacl(item);
912 struct se_node_acl *nacl = lacl->se_lun_nacl;
913 struct se_dev_entry *deve;
914 struct se_lun *lun;
915 ssize_t ret;
917 rcu_read_lock();
918 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
919 if (!deve) {
920 rcu_read_unlock();
921 return -ENODEV;
923 lun = rcu_dereference(deve->se_lun);
924 /* scsiDeviceIndex */
925 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
926 rcu_read_unlock();
927 return ret;
930 static ssize_t target_stat_auth_port_show(struct config_item *item,
931 char *page)
933 struct se_lun_acl *lacl = auth_to_lacl(item);
934 struct se_node_acl *nacl = lacl->se_lun_nacl;
935 struct se_dev_entry *deve;
936 struct se_portal_group *tpg;
937 ssize_t ret;
939 rcu_read_lock();
940 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
941 if (!deve) {
942 rcu_read_unlock();
943 return -ENODEV;
945 tpg = nacl->se_tpg;
946 /* scsiAuthIntrTgtPortIndex */
947 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
948 rcu_read_unlock();
949 return ret;
952 static ssize_t target_stat_auth_indx_show(struct config_item *item,
953 char *page)
955 struct se_lun_acl *lacl = auth_to_lacl(item);
956 struct se_node_acl *nacl = lacl->se_lun_nacl;
957 struct se_dev_entry *deve;
958 ssize_t ret;
960 rcu_read_lock();
961 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
962 if (!deve) {
963 rcu_read_unlock();
964 return -ENODEV;
966 /* scsiAuthIntrIndex */
967 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
968 rcu_read_unlock();
969 return ret;
972 static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
973 char *page)
975 struct se_lun_acl *lacl = auth_to_lacl(item);
976 struct se_node_acl *nacl = lacl->se_lun_nacl;
977 struct se_dev_entry *deve;
978 ssize_t ret;
980 rcu_read_lock();
981 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
982 if (!deve) {
983 rcu_read_unlock();
984 return -ENODEV;
986 /* scsiAuthIntrDevOrPort */
987 ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
988 rcu_read_unlock();
989 return ret;
992 static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
993 char *page)
995 struct se_lun_acl *lacl = auth_to_lacl(item);
996 struct se_node_acl *nacl = lacl->se_lun_nacl;
997 struct se_dev_entry *deve;
998 ssize_t ret;
1000 rcu_read_lock();
1001 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1002 if (!deve) {
1003 rcu_read_unlock();
1004 return -ENODEV;
1006 /* scsiAuthIntrName */
1007 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1008 rcu_read_unlock();
1009 return ret;
1012 static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
1013 char *page)
1015 struct se_lun_acl *lacl = auth_to_lacl(item);
1016 struct se_node_acl *nacl = lacl->se_lun_nacl;
1017 struct se_dev_entry *deve;
1018 ssize_t ret;
1020 rcu_read_lock();
1021 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1022 if (!deve) {
1023 rcu_read_unlock();
1024 return -ENODEV;
1026 /* FIXME: scsiAuthIntrLunMapIndex */
1027 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1028 rcu_read_unlock();
1029 return ret;
1032 static ssize_t target_stat_auth_att_count_show(struct config_item *item,
1033 char *page)
1035 struct se_lun_acl *lacl = auth_to_lacl(item);
1036 struct se_node_acl *nacl = lacl->se_lun_nacl;
1037 struct se_dev_entry *deve;
1038 ssize_t ret;
1040 rcu_read_lock();
1041 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1042 if (!deve) {
1043 rcu_read_unlock();
1044 return -ENODEV;
1046 /* scsiAuthIntrAttachedTimes */
1047 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1048 rcu_read_unlock();
1049 return ret;
1052 static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
1053 char *page)
1055 struct se_lun_acl *lacl = auth_to_lacl(item);
1056 struct se_node_acl *nacl = lacl->se_lun_nacl;
1057 struct se_dev_entry *deve;
1058 ssize_t ret;
1060 rcu_read_lock();
1061 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1062 if (!deve) {
1063 rcu_read_unlock();
1064 return -ENODEV;
1066 /* scsiAuthIntrOutCommands */
1067 ret = snprintf(page, PAGE_SIZE, "%lu\n",
1068 atomic_long_read(&deve->total_cmds));
1069 rcu_read_unlock();
1070 return ret;
1073 static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
1074 char *page)
1076 struct se_lun_acl *lacl = auth_to_lacl(item);
1077 struct se_node_acl *nacl = lacl->se_lun_nacl;
1078 struct se_dev_entry *deve;
1079 ssize_t ret;
1081 rcu_read_lock();
1082 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1083 if (!deve) {
1084 rcu_read_unlock();
1085 return -ENODEV;
1087 /* scsiAuthIntrReadMegaBytes */
1088 ret = snprintf(page, PAGE_SIZE, "%u\n",
1089 (u32)(atomic_long_read(&deve->read_bytes) >> 20));
1090 rcu_read_unlock();
1091 return ret;
1094 static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
1095 char *page)
1097 struct se_lun_acl *lacl = auth_to_lacl(item);
1098 struct se_node_acl *nacl = lacl->se_lun_nacl;
1099 struct se_dev_entry *deve;
1100 ssize_t ret;
1102 rcu_read_lock();
1103 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1104 if (!deve) {
1105 rcu_read_unlock();
1106 return -ENODEV;
1108 /* scsiAuthIntrWrittenMegaBytes */
1109 ret = snprintf(page, PAGE_SIZE, "%u\n",
1110 (u32)(atomic_long_read(&deve->write_bytes) >> 20));
1111 rcu_read_unlock();
1112 return ret;
1115 static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
1116 char *page)
1118 struct se_lun_acl *lacl = auth_to_lacl(item);
1119 struct se_node_acl *nacl = lacl->se_lun_nacl;
1120 struct se_dev_entry *deve;
1121 ssize_t ret;
1123 rcu_read_lock();
1124 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1125 if (!deve) {
1126 rcu_read_unlock();
1127 return -ENODEV;
1129 /* FIXME: scsiAuthIntrHSOutCommands */
1130 ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1131 rcu_read_unlock();
1132 return ret;
1135 static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
1136 char *page)
1138 struct se_lun_acl *lacl = auth_to_lacl(item);
1139 struct se_node_acl *nacl = lacl->se_lun_nacl;
1140 struct se_dev_entry *deve;
1141 ssize_t ret;
1143 rcu_read_lock();
1144 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1145 if (!deve) {
1146 rcu_read_unlock();
1147 return -ENODEV;
1149 /* scsiAuthIntrLastCreation */
1150 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1151 INITIAL_JIFFIES) * 100 / HZ));
1152 rcu_read_unlock();
1153 return ret;
1156 static ssize_t target_stat_auth_row_status_show(struct config_item *item,
1157 char *page)
1159 struct se_lun_acl *lacl = auth_to_lacl(item);
1160 struct se_node_acl *nacl = lacl->se_lun_nacl;
1161 struct se_dev_entry *deve;
1162 ssize_t ret;
1164 rcu_read_lock();
1165 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1166 if (!deve) {
1167 rcu_read_unlock();
1168 return -ENODEV;
1170 /* FIXME: scsiAuthIntrRowStatus */
1171 ret = snprintf(page, PAGE_SIZE, "Ready\n");
1172 rcu_read_unlock();
1173 return ret;
1176 CONFIGFS_ATTR_RO(target_stat_auth_, inst);
1177 CONFIGFS_ATTR_RO(target_stat_auth_, dev);
1178 CONFIGFS_ATTR_RO(target_stat_auth_, port);
1179 CONFIGFS_ATTR_RO(target_stat_auth_, indx);
1180 CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
1181 CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
1182 CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
1183 CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
1184 CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
1185 CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
1186 CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
1187 CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
1188 CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
1189 CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
1191 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1192 &target_stat_auth_attr_inst,
1193 &target_stat_auth_attr_dev,
1194 &target_stat_auth_attr_port,
1195 &target_stat_auth_attr_indx,
1196 &target_stat_auth_attr_dev_or_port,
1197 &target_stat_auth_attr_intr_name,
1198 &target_stat_auth_attr_map_indx,
1199 &target_stat_auth_attr_att_count,
1200 &target_stat_auth_attr_num_cmds,
1201 &target_stat_auth_attr_read_mbytes,
1202 &target_stat_auth_attr_write_mbytes,
1203 &target_stat_auth_attr_hs_num_cmds,
1204 &target_stat_auth_attr_creation_time,
1205 &target_stat_auth_attr_row_status,
1206 NULL,
1209 static const struct config_item_type target_stat_scsi_auth_intr_cit = {
1210 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1211 .ct_owner = THIS_MODULE,
1215 * SCSI Attached Initiator Port Table
1218 static struct se_lun_acl *iport_to_lacl(struct config_item *item)
1220 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
1221 struct se_ml_stat_grps, scsi_att_intr_port_group);
1222 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
1225 static ssize_t target_stat_iport_inst_show(struct config_item *item,
1226 char *page)
1228 struct se_lun_acl *lacl = iport_to_lacl(item);
1229 struct se_node_acl *nacl = lacl->se_lun_nacl;
1230 struct se_dev_entry *deve;
1231 struct se_portal_group *tpg;
1232 ssize_t ret;
1234 rcu_read_lock();
1235 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1236 if (!deve) {
1237 rcu_read_unlock();
1238 return -ENODEV;
1240 tpg = nacl->se_tpg;
1241 /* scsiInstIndex */
1242 ret = snprintf(page, PAGE_SIZE, "%u\n",
1243 tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1244 rcu_read_unlock();
1245 return ret;
1248 static ssize_t target_stat_iport_dev_show(struct config_item *item,
1249 char *page)
1251 struct se_lun_acl *lacl = iport_to_lacl(item);
1252 struct se_node_acl *nacl = lacl->se_lun_nacl;
1253 struct se_dev_entry *deve;
1254 struct se_lun *lun;
1255 ssize_t ret;
1257 rcu_read_lock();
1258 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1259 if (!deve) {
1260 rcu_read_unlock();
1261 return -ENODEV;
1263 lun = rcu_dereference(deve->se_lun);
1264 /* scsiDeviceIndex */
1265 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
1266 rcu_read_unlock();
1267 return ret;
1270 static ssize_t target_stat_iport_port_show(struct config_item *item,
1271 char *page)
1273 struct se_lun_acl *lacl = iport_to_lacl(item);
1274 struct se_node_acl *nacl = lacl->se_lun_nacl;
1275 struct se_dev_entry *deve;
1276 struct se_portal_group *tpg;
1277 ssize_t ret;
1279 rcu_read_lock();
1280 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1281 if (!deve) {
1282 rcu_read_unlock();
1283 return -ENODEV;
1285 tpg = nacl->se_tpg;
1286 /* scsiPortIndex */
1287 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1288 rcu_read_unlock();
1289 return ret;
1292 static ssize_t target_stat_iport_indx_show(struct config_item *item,
1293 char *page)
1295 struct se_lun_acl *lacl = iport_to_lacl(item);
1296 struct se_node_acl *nacl = lacl->se_lun_nacl;
1297 struct se_session *se_sess;
1298 struct se_portal_group *tpg;
1299 ssize_t ret;
1301 spin_lock_irq(&nacl->nacl_sess_lock);
1302 se_sess = nacl->nacl_sess;
1303 if (!se_sess) {
1304 spin_unlock_irq(&nacl->nacl_sess_lock);
1305 return -ENODEV;
1308 tpg = nacl->se_tpg;
1309 /* scsiAttIntrPortIndex */
1310 ret = snprintf(page, PAGE_SIZE, "%u\n",
1311 tpg->se_tpg_tfo->sess_get_index(se_sess));
1312 spin_unlock_irq(&nacl->nacl_sess_lock);
1313 return ret;
1316 static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
1317 char *page)
1319 struct se_lun_acl *lacl = iport_to_lacl(item);
1320 struct se_node_acl *nacl = lacl->se_lun_nacl;
1321 struct se_dev_entry *deve;
1322 ssize_t ret;
1324 rcu_read_lock();
1325 deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1326 if (!deve) {
1327 rcu_read_unlock();
1328 return -ENODEV;
1330 /* scsiAttIntrPortAuthIntrIdx */
1331 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1332 rcu_read_unlock();
1333 return ret;
1336 static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
1337 char *page)
1339 struct se_lun_acl *lacl = iport_to_lacl(item);
1340 struct se_node_acl *nacl = lacl->se_lun_nacl;
1341 struct se_session *se_sess;
1342 struct se_portal_group *tpg;
1343 ssize_t ret;
1344 unsigned char buf[64];
1346 spin_lock_irq(&nacl->nacl_sess_lock);
1347 se_sess = nacl->nacl_sess;
1348 if (!se_sess) {
1349 spin_unlock_irq(&nacl->nacl_sess_lock);
1350 return -ENODEV;
1353 tpg = nacl->se_tpg;
1354 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1355 memset(buf, 0, 64);
1356 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1357 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
1359 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1360 spin_unlock_irq(&nacl->nacl_sess_lock);
1361 return ret;
1364 CONFIGFS_ATTR_RO(target_stat_iport_, inst);
1365 CONFIGFS_ATTR_RO(target_stat_iport_, dev);
1366 CONFIGFS_ATTR_RO(target_stat_iport_, port);
1367 CONFIGFS_ATTR_RO(target_stat_iport_, indx);
1368 CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
1369 CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
1371 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1372 &target_stat_iport_attr_inst,
1373 &target_stat_iport_attr_dev,
1374 &target_stat_iport_attr_port,
1375 &target_stat_iport_attr_indx,
1376 &target_stat_iport_attr_port_auth_indx,
1377 &target_stat_iport_attr_port_ident,
1378 NULL,
1381 static const struct config_item_type target_stat_scsi_att_intr_port_cit = {
1382 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1383 .ct_owner = THIS_MODULE,
1387 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1388 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1390 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1392 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1393 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1394 configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group,
1395 &lacl->ml_stat_grps.stat_group);
1397 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1398 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1399 configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1400 &lacl->ml_stat_grps.stat_group);