xref: /linux/drivers/target/target_core_stat.c (revision e5c86679d5e864947a52fb31e45a425dea3e7fa9)
1 /*******************************************************************************
2  * Filename:  target_core_stat.c
3  *
4  * Modern ConfigFS group context specific statistics based on original
5  * target_core_mib.c code
6  *
7  * (c) Copyright 2006-2013 Datera, Inc.
8  *
9  * Nicholas A. Bellinger <nab@linux-iscsi.org>
10  *
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.
15  *
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.
20  *
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.
24  *
25  ******************************************************************************/
26 
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 
37 #include <target/target_core_base.h>
38 #include <target/target_core_backend.h>
39 #include <target/target_core_fabric.h>
40 
41 #include "target_core_internal.h"
42 
43 #ifndef INITIAL_JIFFIES
44 #define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
45 #endif
46 
47 #define NONE		"None"
48 #define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
49 
50 #define SCSI_LU_INDEX			1
51 #define LU_COUNT			1
52 
53 /*
54  * SCSI Device Table
55  */
56 
57 static struct se_device *to_stat_dev(struct config_item *item)
58 {
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);
62 }
63 
64 static ssize_t target_stat_inst_show(struct config_item *item, char *page)
65 {
66 	struct se_hba *hba = to_stat_dev(item)->se_hba;
67 
68 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
69 }
70 
71 static ssize_t target_stat_indx_show(struct config_item *item, char *page)
72 {
73 	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
74 }
75 
76 static ssize_t target_stat_role_show(struct config_item *item, char *page)
77 {
78 	return snprintf(page, PAGE_SIZE, "Target\n");
79 }
80 
81 static ssize_t target_stat_ports_show(struct config_item *item, char *page)
82 {
83 	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
84 }
85 
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);
90 
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,
97 };
98 
99 static struct config_item_type target_stat_scsi_dev_cit = {
100 	.ct_attrs		= target_stat_scsi_dev_attrs,
101 	.ct_owner		= THIS_MODULE,
102 };
103 
104 /*
105  * SCSI Target Device Table
106  */
107 static struct se_device *to_stat_tgt_dev(struct config_item *item)
108 {
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);
112 }
113 
114 static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
115 {
116 	struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
117 
118 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
119 }
120 
121 static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
122 {
123 	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
124 }
125 
126 static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
127 		char *page)
128 {
129 	return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
130 }
131 
132 static ssize_t target_stat_tgt_status_show(struct config_item *item,
133 		char *page)
134 {
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");
139 }
140 
141 static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
142 		char *page)
143 {
144 	int non_accessible_lus;
145 
146 	if (to_stat_tgt_dev(item)->export_count)
147 		non_accessible_lus = 0;
148 	else
149 		non_accessible_lus = 1;
150 
151 	return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
152 }
153 
154 static ssize_t target_stat_tgt_resets_show(struct config_item *item,
155 		char *page)
156 {
157 	return snprintf(page, PAGE_SIZE, "%lu\n",
158 			atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
159 }
160 
161 static ssize_t target_stat_tgt_aborts_complete_show(struct config_item *item,
162 		char *page)
163 {
164 	return snprintf(page, PAGE_SIZE, "%lu\n",
165 			atomic_long_read(&to_stat_tgt_dev(item)->aborts_complete));
166 }
167 
168 static ssize_t target_stat_tgt_aborts_no_task_show(struct config_item *item,
169 		char *page)
170 {
171 	return snprintf(page, PAGE_SIZE, "%lu\n",
172 			atomic_long_read(&to_stat_tgt_dev(item)->aborts_no_task));
173 }
174 
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);
183 
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,
194 };
195 
196 static struct config_item_type target_stat_scsi_tgt_dev_cit = {
197 	.ct_attrs		= target_stat_scsi_tgt_dev_attrs,
198 	.ct_owner		= THIS_MODULE,
199 };
200 
201 /*
202  * SCSI Logical Unit Table
203  */
204 
205 static struct se_device *to_stat_lu_dev(struct config_item *item)
206 {
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);
210 }
211 
212 static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
213 {
214 	struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
215 
216 	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
217 }
218 
219 static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
220 {
221 	return snprintf(page, PAGE_SIZE, "%u\n",
222 			to_stat_lu_dev(item)->dev_index);
223 }
224 
225 static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
226 {
227 	return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
228 }
229 
230 static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
231 {
232 	/* FIXME: scsiLuDefaultLun */
233 	return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
234 }
235 
236 static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
237 {
238 	struct se_device *dev = to_stat_lu_dev(item);
239 
240 	/* scsiLuWwnName */
241 	return snprintf(page, PAGE_SIZE, "%s\n",
242 			(strlen(dev->t10_wwn.unit_serial)) ?
243 			dev->t10_wwn.unit_serial : "None");
244 }
245 
246 static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
247 {
248 	struct se_device *dev = to_stat_lu_dev(item);
249 	int i;
250 	char str[sizeof(dev->t10_wwn.vendor)+1];
251 
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);
258 }
259 
260 static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
261 {
262 	struct se_device *dev = to_stat_lu_dev(item);
263 	int i;
264 	char str[sizeof(dev->t10_wwn.model)+1];
265 
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);
272 }
273 
274 static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
275 {
276 	struct se_device *dev = to_stat_lu_dev(item);
277 	int i;
278 	char str[sizeof(dev->t10_wwn.revision)+1];
279 
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);
286 }
287 
288 static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
289 {
290 	struct se_device *dev = to_stat_lu_dev(item);
291 
292 	/* scsiLuPeripheralType */
293 	return snprintf(page, PAGE_SIZE, "%u\n",
294 			dev->transport->get_device_type(dev));
295 }
296 
297 static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
298 {
299 	struct se_device *dev = to_stat_lu_dev(item);
300 
301 	/* scsiLuStatus */
302 	return snprintf(page, PAGE_SIZE, "%s\n",
303 		(dev->export_count) ? "available" : "notavailable");
304 }
305 
306 static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
307 		char *page)
308 {
309 	/* scsiLuState */
310 	return snprintf(page, PAGE_SIZE, "exposed\n");
311 }
312 
313 static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
314 		char *page)
315 {
316 	struct se_device *dev = to_stat_lu_dev(item);
317 
318 	/* scsiLuNumCommands */
319 	return snprintf(page, PAGE_SIZE, "%lu\n",
320 			atomic_long_read(&dev->num_cmds));
321 }
322 
323 static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
324 		char *page)
325 {
326 	struct se_device *dev = to_stat_lu_dev(item);
327 
328 	/* scsiLuReadMegaBytes */
329 	return snprintf(page, PAGE_SIZE, "%lu\n",
330 			atomic_long_read(&dev->read_bytes) >> 20);
331 }
332 
333 static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
334 		char *page)
335 {
336 	struct se_device *dev = to_stat_lu_dev(item);
337 
338 	/* scsiLuWrittenMegaBytes */
339 	return snprintf(page, PAGE_SIZE, "%lu\n",
340 			atomic_long_read(&dev->write_bytes) >> 20);
341 }
342 
343 static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
344 {
345 	struct se_device *dev = to_stat_lu_dev(item);
346 
347 	/* scsiLuInResets */
348 	return snprintf(page, PAGE_SIZE, "%lu\n",
349 		atomic_long_read(&dev->num_resets));
350 }
351 
352 static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
353 		char *page)
354 {
355 	/* FIXME: scsiLuOutTaskSetFullStatus */
356 	return snprintf(page, PAGE_SIZE, "%u\n", 0);
357 }
358 
359 static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
360 		char *page)
361 {
362 	/* FIXME: scsiLuHSInCommands */
363 	return snprintf(page, PAGE_SIZE, "%u\n", 0);
364 }
365 
366 static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
367 		char *page)
368 {
369 	struct se_device *dev = to_stat_lu_dev(item);
370 
371 	/* scsiLuCreationTime */
372 	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
373 				INITIAL_JIFFIES) * 100 / HZ));
374 }
375 
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);
394 
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,
415 };
416 
417 static struct config_item_type target_stat_scsi_lu_cit = {
418 	.ct_attrs		= target_stat_scsi_lu_attrs,
419 	.ct_owner		= THIS_MODULE,
420 };
421 
422 /*
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
425  */
426 void target_stat_setup_dev_default_groups(struct se_device *dev)
427 {
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);
432 
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);
437 
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);
442 }
443 
444 /*
445  * SCSI Port Table
446  */
447 
448 static struct se_lun *to_stat_port(struct config_item *item)
449 {
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);
453 }
454 
455 static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
456 {
457 	struct se_lun *lun = to_stat_port(item);
458 	struct se_device *dev;
459 	ssize_t ret = -ENODEV;
460 
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;
467 }
468 
469 static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
470 {
471 	struct se_lun *lun = to_stat_port(item);
472 	struct se_device *dev;
473 	ssize_t ret = -ENODEV;
474 
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;
481 }
482 
483 static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
484 {
485 	struct se_lun *lun = to_stat_port(item);
486 	struct se_device *dev;
487 	ssize_t ret = -ENODEV;
488 
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;
495 }
496 
497 static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
498 {
499 	struct se_lun *lun = to_stat_port(item);
500 	struct se_device *dev;
501 	ssize_t ret = -ENODEV;
502 
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;
509 }
510 
511 static ssize_t target_stat_port_busy_count_show(struct config_item *item,
512 		char *page)
513 {
514 	struct se_lun *lun = to_stat_port(item);
515 	struct se_device *dev;
516 	ssize_t ret = -ENODEV;
517 
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);
523 	}
524 	rcu_read_unlock();
525 	return ret;
526 }
527 
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);
533 
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,
541 };
542 
543 static struct config_item_type target_stat_scsi_port_cit = {
544 	.ct_attrs		= target_stat_scsi_port_attrs,
545 	.ct_owner		= THIS_MODULE,
546 };
547 
548 /*
549  * SCSI Target Port Table
550  */
551 static struct se_lun *to_stat_tgt_port(struct config_item *item)
552 {
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);
556 }
557 
558 static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
559 		char *page)
560 {
561 	struct se_lun *lun = to_stat_tgt_port(item);
562 	struct se_device *dev;
563 	ssize_t ret = -ENODEV;
564 
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;
571 }
572 
573 static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
574 		char *page)
575 {
576 	struct se_lun *lun = to_stat_tgt_port(item);
577 	struct se_device *dev;
578 	ssize_t ret = -ENODEV;
579 
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;
586 }
587 
588 static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
589 		char *page)
590 {
591 	struct se_lun *lun = to_stat_tgt_port(item);
592 	struct se_device *dev;
593 	ssize_t ret = -ENODEV;
594 
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;
601 }
602 
603 static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
604 		char *page)
605 {
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;
610 
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;
619 }
620 
621 static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
622 		char *page)
623 {
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;
628 
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;
637 }
638 
639 static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
640 		char *page)
641 {
642 	struct se_lun *lun = to_stat_tgt_port(item);
643 	struct se_device *dev;
644 	ssize_t ret = -ENODEV;
645 
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;
653 }
654 
655 static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
656 		char *page)
657 {
658 	struct se_lun *lun = to_stat_tgt_port(item);
659 	struct se_device *dev;
660 	ssize_t ret = -ENODEV;
661 
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;
669 }
670 
671 static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
672 		char *page)
673 {
674 	struct se_lun *lun = to_stat_tgt_port(item);
675 	struct se_device *dev;
676 	ssize_t ret = -ENODEV;
677 
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;
685 }
686 
687 static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
688 		char *page)
689 {
690 	struct se_lun *lun = to_stat_tgt_port(item);
691 	struct se_device *dev;
692 	ssize_t ret = -ENODEV;
693 
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);
699 	}
700 	rcu_read_unlock();
701 	return ret;
702 }
703 
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);
713 
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,
725 };
726 
727 static struct config_item_type target_stat_scsi_tgt_port_cit = {
728 	.ct_attrs		= target_stat_scsi_tgt_port_attrs,
729 	.ct_owner		= THIS_MODULE,
730 };
731 
732 /*
733  * SCSI Transport Table
734  */
735 static struct se_lun *to_transport_stat(struct config_item *item)
736 {
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);
740 }
741 
742 static ssize_t target_stat_transport_inst_show(struct config_item *item,
743 		char *page)
744 {
745 	struct se_lun *lun = to_transport_stat(item);
746 	struct se_device *dev;
747 	ssize_t ret = -ENODEV;
748 
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;
755 }
756 
757 static ssize_t target_stat_transport_device_show(struct config_item *item,
758 		char *page)
759 {
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;
764 
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());
771 	}
772 	rcu_read_unlock();
773 	return ret;
774 }
775 
776 static ssize_t target_stat_transport_indx_show(struct config_item *item,
777 		char *page)
778 {
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;
783 
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;
791 }
792 
793 static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
794 		char *page)
795 {
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;
801 
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);
811 	}
812 	rcu_read_unlock();
813 	return ret;
814 }
815 
816 static ssize_t target_stat_transport_proto_id_show(struct config_item *item,
817 		char *page)
818 {
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;
823 
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;
830 }
831 
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);
837 
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,
845 };
846 
847 static struct config_item_type target_stat_scsi_transport_cit = {
848 	.ct_attrs		= target_stat_scsi_transport_attrs,
849 	.ct_owner		= THIS_MODULE,
850 };
851 
852 /*
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
855  */
856 void target_stat_setup_port_default_groups(struct se_lun *lun)
857 {
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);
862 
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);
867 
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);
872 }
873 
874 /*
875  * SCSI Authorized Initiator Table
876  */
877 
878 static struct se_lun_acl *auth_to_lacl(struct config_item *item)
879 {
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);
883 }
884 
885 static ssize_t target_stat_auth_inst_show(struct config_item *item,
886 		char *page)
887 {
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;
893 
894 	rcu_read_lock();
895 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
896 	if (!deve) {
897 		rcu_read_unlock();
898 		return -ENODEV;
899 	}
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;
906 }
907 
908 static ssize_t target_stat_auth_dev_show(struct config_item *item,
909 		char *page)
910 {
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;
916 
917 	rcu_read_lock();
918 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
919 	if (!deve) {
920 		rcu_read_unlock();
921 		return -ENODEV;
922 	}
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;
928 }
929 
930 static ssize_t target_stat_auth_port_show(struct config_item *item,
931 		char *page)
932 {
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;
938 
939 	rcu_read_lock();
940 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
941 	if (!deve) {
942 		rcu_read_unlock();
943 		return -ENODEV;
944 	}
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;
950 }
951 
952 static ssize_t target_stat_auth_indx_show(struct config_item *item,
953 		char *page)
954 {
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;
959 
960 	rcu_read_lock();
961 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
962 	if (!deve) {
963 		rcu_read_unlock();
964 		return -ENODEV;
965 	}
966 	/* scsiAuthIntrIndex */
967 	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
968 	rcu_read_unlock();
969 	return ret;
970 }
971 
972 static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
973 		char *page)
974 {
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;
979 
980 	rcu_read_lock();
981 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
982 	if (!deve) {
983 		rcu_read_unlock();
984 		return -ENODEV;
985 	}
986 	/* scsiAuthIntrDevOrPort */
987 	ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
988 	rcu_read_unlock();
989 	return ret;
990 }
991 
992 static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
993 		char *page)
994 {
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;
999 
1000 	rcu_read_lock();
1001 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1002 	if (!deve) {
1003 		rcu_read_unlock();
1004 		return -ENODEV;
1005 	}
1006 	/* scsiAuthIntrName */
1007 	ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1008 	rcu_read_unlock();
1009 	return ret;
1010 }
1011 
1012 static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
1013 		char *page)
1014 {
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;
1019 
1020 	rcu_read_lock();
1021 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1022 	if (!deve) {
1023 		rcu_read_unlock();
1024 		return -ENODEV;
1025 	}
1026 	/* FIXME: scsiAuthIntrLunMapIndex */
1027 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1028 	rcu_read_unlock();
1029 	return ret;
1030 }
1031 
1032 static ssize_t target_stat_auth_att_count_show(struct config_item *item,
1033 		char *page)
1034 {
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;
1039 
1040 	rcu_read_lock();
1041 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1042 	if (!deve) {
1043 		rcu_read_unlock();
1044 		return -ENODEV;
1045 	}
1046 	/* scsiAuthIntrAttachedTimes */
1047 	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1048 	rcu_read_unlock();
1049 	return ret;
1050 }
1051 
1052 static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
1053 		char *page)
1054 {
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;
1059 
1060 	rcu_read_lock();
1061 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1062 	if (!deve) {
1063 		rcu_read_unlock();
1064 		return -ENODEV;
1065 	}
1066 	/* scsiAuthIntrOutCommands */
1067 	ret = snprintf(page, PAGE_SIZE, "%lu\n",
1068 		       atomic_long_read(&deve->total_cmds));
1069 	rcu_read_unlock();
1070 	return ret;
1071 }
1072 
1073 static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
1074 		char *page)
1075 {
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;
1080 
1081 	rcu_read_lock();
1082 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1083 	if (!deve) {
1084 		rcu_read_unlock();
1085 		return -ENODEV;
1086 	}
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;
1092 }
1093 
1094 static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
1095 		char *page)
1096 {
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;
1101 
1102 	rcu_read_lock();
1103 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1104 	if (!deve) {
1105 		rcu_read_unlock();
1106 		return -ENODEV;
1107 	}
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;
1113 }
1114 
1115 static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
1116 		char *page)
1117 {
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;
1122 
1123 	rcu_read_lock();
1124 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1125 	if (!deve) {
1126 		rcu_read_unlock();
1127 		return -ENODEV;
1128 	}
1129 	/* FIXME: scsiAuthIntrHSOutCommands */
1130 	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1131 	rcu_read_unlock();
1132 	return ret;
1133 }
1134 
1135 static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
1136 		char *page)
1137 {
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;
1142 
1143 	rcu_read_lock();
1144 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1145 	if (!deve) {
1146 		rcu_read_unlock();
1147 		return -ENODEV;
1148 	}
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;
1154 }
1155 
1156 static ssize_t target_stat_auth_row_status_show(struct config_item *item,
1157 		char *page)
1158 {
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;
1163 
1164 	rcu_read_lock();
1165 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1166 	if (!deve) {
1167 		rcu_read_unlock();
1168 		return -ENODEV;
1169 	}
1170 	/* FIXME: scsiAuthIntrRowStatus */
1171 	ret = snprintf(page, PAGE_SIZE, "Ready\n");
1172 	rcu_read_unlock();
1173 	return ret;
1174 }
1175 
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);
1190 
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,
1207 };
1208 
1209 static struct config_item_type target_stat_scsi_auth_intr_cit = {
1210 	.ct_attrs		= target_stat_scsi_auth_intr_attrs,
1211 	.ct_owner		= THIS_MODULE,
1212 };
1213 
1214 /*
1215  * SCSI Attached Initiator Port Table
1216  */
1217 
1218 static struct se_lun_acl *iport_to_lacl(struct config_item *item)
1219 {
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);
1223 }
1224 
1225 static ssize_t target_stat_iport_inst_show(struct config_item *item,
1226 		char *page)
1227 {
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;
1233 
1234 	rcu_read_lock();
1235 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1236 	if (!deve) {
1237 		rcu_read_unlock();
1238 		return -ENODEV;
1239 	}
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;
1246 }
1247 
1248 static ssize_t target_stat_iport_dev_show(struct config_item *item,
1249 		char *page)
1250 {
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;
1256 
1257 	rcu_read_lock();
1258 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1259 	if (!deve) {
1260 		rcu_read_unlock();
1261 		return -ENODEV;
1262 	}
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;
1268 }
1269 
1270 static ssize_t target_stat_iport_port_show(struct config_item *item,
1271 		char *page)
1272 {
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;
1278 
1279 	rcu_read_lock();
1280 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1281 	if (!deve) {
1282 		rcu_read_unlock();
1283 		return -ENODEV;
1284 	}
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;
1290 }
1291 
1292 static ssize_t target_stat_iport_indx_show(struct config_item *item,
1293 		char *page)
1294 {
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;
1300 
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;
1306 	}
1307 
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;
1314 }
1315 
1316 static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
1317 		char *page)
1318 {
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;
1323 
1324 	rcu_read_lock();
1325 	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1326 	if (!deve) {
1327 		rcu_read_unlock();
1328 		return -ENODEV;
1329 	}
1330 	/* scsiAttIntrPortAuthIntrIdx */
1331 	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1332 	rcu_read_unlock();
1333 	return ret;
1334 }
1335 
1336 static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
1337 		char *page)
1338 {
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];
1345 
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;
1351 	}
1352 
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);
1358 
1359 	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1360 	spin_unlock_irq(&nacl->nacl_sess_lock);
1361 	return ret;
1362 }
1363 
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);
1370 
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,
1379 };
1380 
1381 static 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,
1384 };
1385 
1386 /*
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
1389  */
1390 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1391 {
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);
1396 
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);
1401 }
1402