target_core_stat.c 36.5 KB
Newer Older
1 2 3 4 5 6
/*******************************************************************************
 * Filename:  target_core_stat.c
 *
 * Modern ConfigFS group context specific statistics based on original
 * target_core_mib.c code
 *
7
 * (c) Copyright 2006-2013 Datera, Inc.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
 *
 * Nicholas A. Bellinger <nab@linux-iscsi.org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 ******************************************************************************/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/utsname.h>
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/configfs.h>

#include <target/target_core_base.h>
38 39
#include <target/target_core_backend.h>
#include <target/target_core_fabric.h>
40

41
#include "target_core_internal.h"
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

#ifndef INITIAL_JIFFIES
#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
#endif

#define NONE		"None"
#define ISPRINT(a)   ((a >= ' ') && (a <= '~'))

#define SCSI_LU_INDEX			1
#define LU_COUNT			1

/*
 * SCSI Device Table
 */

57 58 59 60 61 62
static struct se_device *to_stat_dev(struct config_item *item)
{
	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
			struct se_dev_stat_grps, scsi_dev_group);
	return container_of(sgrps, struct se_device, dev_stat_grps);
}
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 69 70

	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
}

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 79 80
{
	return snprintf(page, PAGE_SIZE, "Target\n");
}

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 87 88 89
CONFIGFS_ATTR_RO(target_stat_, inst);
CONFIGFS_ATTR_RO(target_stat_, indx);
CONFIGFS_ATTR_RO(target_stat_, role);
CONFIGFS_ATTR_RO(target_stat_, ports);
90 91

static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
92 93 94 95
	&target_stat_attr_inst,
	&target_stat_attr_indx,
	&target_stat_attr_role,
	&target_stat_attr_ports,
96 97 98 99 100 101 102 103 104 105 106
	NULL,
};

static struct config_item_type target_stat_scsi_dev_cit = {
	.ct_attrs		= target_stat_scsi_dev_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * SCSI Target Device Table
 */
107 108 109 110 111 112
static struct se_device *to_stat_tgt_dev(struct config_item *item)
{
	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
			struct se_dev_stat_grps, scsi_tgt_dev_group);
	return container_of(sgrps, struct se_device, dev_stat_grps);
}
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 119 120

	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)
122
{
123
	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
124 125
}

126 127
static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
		char *page)
128 129 130 131
{
	return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
}

132 133
static ssize_t target_stat_tgt_status_show(struct config_item *item,
		char *page)
134
{
135
	if (to_stat_tgt_dev(item)->export_count)
136 137 138
		return snprintf(page, PAGE_SIZE, "activated");
	else
		return snprintf(page, PAGE_SIZE, "deactivated");
139 140
}

141 142
static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
		char *page)
143 144 145
{
	int non_accessible_lus;

146
	if (to_stat_tgt_dev(item)->export_count)
147
		non_accessible_lus = 0;
148
	else
149 150 151 152 153
		non_accessible_lus = 1;

	return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
}

154 155
static ssize_t target_stat_tgt_resets_show(struct config_item *item,
		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 162 163 164 165 166
CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
CONFIGFS_ATTR_RO(target_stat_tgt_, status);
CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
167 168

static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
169 170 171 172 173 174
	&target_stat_tgt_attr_inst,
	&target_stat_tgt_attr_indx,
	&target_stat_tgt_attr_num_lus,
	&target_stat_tgt_attr_status,
	&target_stat_tgt_attr_non_access_lus,
	&target_stat_tgt_attr_resets,
175 176 177 178 179 180 181 182 183 184 185 186
	NULL,
};

static struct config_item_type target_stat_scsi_tgt_dev_cit = {
	.ct_attrs		= target_stat_scsi_tgt_dev_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * SCSI Logical Unit Table
 */

187 188 189 190 191 192
static struct se_device *to_stat_lu_dev(struct config_item *item)
{
	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
			struct se_dev_stat_grps, scsi_lu_group);
	return container_of(sgrps, struct se_device, dev_stat_grps);
}
193

194
static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
195
{
196
	struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
197 198 199 200

	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
}

201
static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
202
{
203 204
	return snprintf(page, PAGE_SIZE, "%u\n",
			to_stat_lu_dev(item)->dev_index);
205 206
}

207
static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
208 209 210 211
{
	return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
}

212
static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
213 214 215 216 217
{
	/* FIXME: scsiLuDefaultLun */
	return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
}

218
static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
219
{
220
	struct se_device *dev = to_stat_lu_dev(item);
221 222 223

	/* scsiLuWwnName */
	return snprintf(page, PAGE_SIZE, "%s\n",
224 225
			(strlen(dev->t10_wwn.unit_serial)) ?
			dev->t10_wwn.unit_serial : "None");
226 227
}

228
static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
229
{
230
	struct se_device *dev = to_stat_lu_dev(item);
231
	int i;
232
	char str[sizeof(dev->t10_wwn.vendor)+1];
233

234
	/* scsiLuVendorId */
235 236 237
	for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++)
		str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ?
			dev->t10_wwn.vendor[i] : ' ';
238
	str[i] = '\0';
239 240 241
	return snprintf(page, PAGE_SIZE, "%s\n", str);
}

242
static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
243
{
244
	struct se_device *dev = to_stat_lu_dev(item);
245
	int i;
246
	char str[sizeof(dev->t10_wwn.model)+1];
247 248

	/* scsiLuProductId */
249
	for (i = 0; i < sizeof(dev->t10_wwn.model); i++)
250 251
		str[i] = ISPRINT(dev->t10_wwn.model[i]) ?
			dev->t10_wwn.model[i] : ' ';
252
	str[i] = '\0';
253 254 255
	return snprintf(page, PAGE_SIZE, "%s\n", str);
}

256
static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
257
{
258
	struct se_device *dev = to_stat_lu_dev(item);
259
	int i;
260
	char str[sizeof(dev->t10_wwn.revision)+1];
261 262

	/* scsiLuRevisionId */
263 264 265
	for (i = 0; i < sizeof(dev->t10_wwn.revision); i++)
		str[i] = ISPRINT(dev->t10_wwn.revision[i]) ?
			dev->t10_wwn.revision[i] : ' ';
266
	str[i] = '\0';
267 268 269
	return snprintf(page, PAGE_SIZE, "%s\n", str);
}

270
static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
271
{
272
	struct se_device *dev = to_stat_lu_dev(item);
273 274 275

	/* scsiLuPeripheralType */
	return snprintf(page, PAGE_SIZE, "%u\n",
276
			dev->transport->get_device_type(dev));
277 278
}

279
static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
280
{
281
	struct se_device *dev = to_stat_lu_dev(item);
282 283 284

	/* scsiLuStatus */
	return snprintf(page, PAGE_SIZE, "%s\n",
285
		(dev->export_count) ? "available" : "notavailable");
286 287
}

288 289
static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
		char *page)
290 291 292 293 294
{
	/* scsiLuState */
	return snprintf(page, PAGE_SIZE, "exposed\n");
}

295 296
static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
		char *page)
297
{
298
	struct se_device *dev = to_stat_lu_dev(item);
299 300

	/* scsiLuNumCommands */
301 302
	return snprintf(page, PAGE_SIZE, "%lu\n",
			atomic_long_read(&dev->num_cmds));
303 304
}

305 306
static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
		char *page)
307
{
308
	struct se_device *dev = to_stat_lu_dev(item);
309 310

	/* scsiLuReadMegaBytes */
311 312
	return snprintf(page, PAGE_SIZE, "%lu\n",
			atomic_long_read(&dev->read_bytes) >> 20);
313 314
}

315 316
static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
		char *page)
317
{
318
	struct se_device *dev = to_stat_lu_dev(item);
319 320

	/* scsiLuWrittenMegaBytes */
321 322
	return snprintf(page, PAGE_SIZE, "%lu\n",
			atomic_long_read(&dev->write_bytes) >> 20);
323 324
}

325
static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
326
{
327
	struct se_device *dev = to_stat_lu_dev(item);
328 329

	/* scsiLuInResets */
330 331
	return snprintf(page, PAGE_SIZE, "%lu\n",
		atomic_long_read(&dev->num_resets));
332 333
}

334 335
static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
		char *page)
336 337 338 339 340
{
	/* FIXME: scsiLuOutTaskSetFullStatus */
	return snprintf(page, PAGE_SIZE, "%u\n", 0);
}

341 342
static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
		char *page)
343 344 345 346 347
{
	/* FIXME: scsiLuHSInCommands */
	return snprintf(page, PAGE_SIZE, "%u\n", 0);
}

348 349
static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
		char *page)
350
{
351
	struct se_device *dev = to_stat_lu_dev(item);
352 353 354 355 356 357

	/* scsiLuCreationTime */
	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
				INITIAL_JIFFIES) * 100 / HZ));
}

358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375
CONFIGFS_ATTR_RO(target_stat_lu_, inst);
CONFIGFS_ATTR_RO(target_stat_lu_, dev);
CONFIGFS_ATTR_RO(target_stat_lu_, indx);
CONFIGFS_ATTR_RO(target_stat_lu_, lun);
CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
CONFIGFS_ATTR_RO(target_stat_lu_, vend);
CONFIGFS_ATTR_RO(target_stat_lu_, prod);
CONFIGFS_ATTR_RO(target_stat_lu_, rev);
CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
CONFIGFS_ATTR_RO(target_stat_lu_, status);
CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
CONFIGFS_ATTR_RO(target_stat_lu_, resets);
CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
376 377

static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
	&target_stat_lu_attr_inst,
	&target_stat_lu_attr_dev,
	&target_stat_lu_attr_indx,
	&target_stat_lu_attr_lun,
	&target_stat_lu_attr_lu_name,
	&target_stat_lu_attr_vend,
	&target_stat_lu_attr_prod,
	&target_stat_lu_attr_rev,
	&target_stat_lu_attr_dev_type,
	&target_stat_lu_attr_status,
	&target_stat_lu_attr_state_bit,
	&target_stat_lu_attr_num_cmds,
	&target_stat_lu_attr_read_mbytes,
	&target_stat_lu_attr_write_mbytes,
	&target_stat_lu_attr_resets,
	&target_stat_lu_attr_full_stat,
	&target_stat_lu_attr_hs_num_cmds,
	&target_stat_lu_attr_creation_time,
396 397 398 399 400 401 402 403 404 405 406 407
	NULL,
};

static struct config_item_type target_stat_scsi_lu_cit = {
	.ct_attrs		= target_stat_scsi_lu_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * Called from target_core_configfs.c:target_core_make_subdev() to setup
 * the target statistics groups + configfs CITs located in target_core_stat.c
 */
408
void target_stat_setup_dev_default_groups(struct se_device *dev)
409
{
410
	config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
411
			"scsi_dev", &target_stat_scsi_dev_cit);
412 413 414
	configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group,
			&dev->dev_stat_grps.stat_group);

415
	config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
416
			"scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
417 418 419
	configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group,
			&dev->dev_stat_grps.stat_group);

420
	config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
421
			"scsi_lu", &target_stat_scsi_lu_cit);
422 423
	configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group,
			&dev->dev_stat_grps.stat_group);
424 425 426 427 428 429
}

/*
 * SCSI Port Table
 */

430 431 432 433 434 435
static struct se_lun *to_stat_port(struct config_item *item)
{
	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
			struct se_port_stat_grps, scsi_port_group);
	return container_of(pgrps, struct se_lun, port_stat_grps);
}
436

437
static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
438
{
439
	struct se_lun *lun = to_stat_port(item);
440 441
	struct se_device *dev;
	ssize_t ret = -ENODEV;
442

443 444
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
445
	if (dev)
446 447
		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
	rcu_read_unlock();
448 449 450
	return ret;
}

451
static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
452
{
453
	struct se_lun *lun = to_stat_port(item);
454 455
	struct se_device *dev;
	ssize_t ret = -ENODEV;
456

457 458
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
459 460
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
461
	rcu_read_unlock();
462 463 464
	return ret;
}

465
static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
466
{
467
	struct se_lun *lun = to_stat_port(item);
468 469
	struct se_device *dev;
	ssize_t ret = -ENODEV;
470

471 472
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
473 474
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
475
	rcu_read_unlock();
476 477 478
	return ret;
}

479
static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
480
{
481
	struct se_lun *lun = to_stat_port(item);
482 483
	struct se_device *dev;
	ssize_t ret = -ENODEV;
484

485 486
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
487 488
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
489
	rcu_read_unlock();
490 491 492
	return ret;
}

493 494
static ssize_t target_stat_port_busy_count_show(struct config_item *item,
		char *page)
495
{
496
	struct se_lun *lun = to_stat_port(item);
497 498
	struct se_device *dev;
	ssize_t ret = -ENODEV;
499

500 501
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
502 503 504
	if (dev) {
		/* FIXME: scsiPortBusyStatuses  */
		ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
505
	}
506
	rcu_read_unlock();
507 508 509
	return ret;
}

510 511 512 513 514
CONFIGFS_ATTR_RO(target_stat_port_, inst);
CONFIGFS_ATTR_RO(target_stat_port_, dev);
CONFIGFS_ATTR_RO(target_stat_port_, indx);
CONFIGFS_ATTR_RO(target_stat_port_, role);
CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
515 516

static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
517 518 519 520 521
	&target_stat_port_attr_inst,
	&target_stat_port_attr_dev,
	&target_stat_port_attr_indx,
	&target_stat_port_attr_role,
	&target_stat_port_attr_busy_count,
522 523 524 525 526 527 528 529 530 531 532
	NULL,
};

static struct config_item_type target_stat_scsi_port_cit = {
	.ct_attrs		= target_stat_scsi_port_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * SCSI Target Port Table
 */
533 534 535 536 537 538 539 540 541 542 543
static struct se_lun *to_stat_tgt_port(struct config_item *item)
{
	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
			struct se_port_stat_grps, scsi_tgt_port_group);
	return container_of(pgrps, struct se_lun, port_stat_grps);
}

static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
		char *page)
{
	struct se_lun *lun = to_stat_tgt_port(item);
544 545
	struct se_device *dev;
	ssize_t ret = -ENODEV;
546

547 548
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
549
	if (dev)
550 551
		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
	rcu_read_unlock();
552 553 554
	return ret;
}

555 556
static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
		char *page)
557
{
558
	struct se_lun *lun = to_stat_tgt_port(item);
559 560
	struct se_device *dev;
	ssize_t ret = -ENODEV;
561

562 563
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
564 565
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
566
	rcu_read_unlock();
567 568 569
	return ret;
}

570 571
static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
		char *page)
572
{
573
	struct se_lun *lun = to_stat_tgt_port(item);
574 575
	struct se_device *dev;
	ssize_t ret = -ENODEV;
576

577 578
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
579 580
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
581
	rcu_read_unlock();
582 583 584
	return ret;
}

585 586
static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
		char *page)
587
{
588
	struct se_lun *lun = to_stat_tgt_port(item);
589 590 591
	struct se_portal_group *tpg = lun->lun_tpg;
	struct se_device *dev;
	ssize_t ret = -ENODEV;
592

593 594
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
595 596 597 598
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
			tpg->se_tpg_tfo->get_fabric_name(),
			lun->lun_rtpi);
599
	rcu_read_unlock();
600 601 602
	return ret;
}

603 604
static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
		char *page)
605
{
606
	struct se_lun *lun = to_stat_tgt_port(item);
607 608 609
	struct se_portal_group *tpg = lun->lun_tpg;
	struct se_device *dev;
	ssize_t ret = -ENODEV;
610

611 612
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
613 614 615 616
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
			tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
			tpg->se_tpg_tfo->tpg_get_tag(tpg));
617
	rcu_read_unlock();
618 619 620
	return ret;
}

621 622
static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
		char *page)
623
{
624
	struct se_lun *lun = to_stat_tgt_port(item);
625 626
	struct se_device *dev;
	ssize_t ret = -ENODEV;
627

628 629
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
630
	if (dev)
631 632 633
		ret = snprintf(page, PAGE_SIZE, "%lu\n",
			       atomic_long_read(&lun->lun_stats.cmd_pdus));
	rcu_read_unlock();
634 635 636
	return ret;
}

637 638
static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
		char *page)
639
{
640
	struct se_lun *lun = to_stat_tgt_port(item);
641 642
	struct se_device *dev;
	ssize_t ret = -ENODEV;
643

644 645
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
646 647
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n",
648 649
			(u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
	rcu_read_unlock();
650 651 652
	return ret;
}

653 654
static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
		char *page)
655
{
656
	struct se_lun *lun = to_stat_tgt_port(item);
657 658
	struct se_device *dev;
	ssize_t ret = -ENODEV;
659

660 661
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
662 663
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n",
664 665
				(u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
	rcu_read_unlock();
666 667 668
	return ret;
}

669 670
static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
		char *page)
671
{
672
	struct se_lun *lun = to_stat_tgt_port(item);
673 674
	struct se_device *dev;
	ssize_t ret = -ENODEV;
675

676 677
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
678 679 680
	if (dev) {
		/* FIXME: scsiTgtPortHsInCommands */
		ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
681
	}
682
	rcu_read_unlock();
683 684 685
	return ret;
}

686 687 688 689 690 691 692 693 694
CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
695 696

static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
697 698 699 700 701 702 703 704 705
	&target_stat_tgt_port_attr_inst,
	&target_stat_tgt_port_attr_dev,
	&target_stat_tgt_port_attr_indx,
	&target_stat_tgt_port_attr_name,
	&target_stat_tgt_port_attr_port_index,
	&target_stat_tgt_port_attr_in_cmds,
	&target_stat_tgt_port_attr_write_mbytes,
	&target_stat_tgt_port_attr_read_mbytes,
	&target_stat_tgt_port_attr_hs_in_cmds,
706 707 708 709 710 711 712 713 714 715
	NULL,
};

static struct config_item_type target_stat_scsi_tgt_port_cit = {
	.ct_attrs		= target_stat_scsi_tgt_port_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * SCSI Transport Table
716 717 718 719 720 721 722 723 724 725 726 727
 */
static struct se_lun *to_transport_stat(struct config_item *item)
{
	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
			struct se_port_stat_grps, scsi_transport_group);
	return container_of(pgrps, struct se_lun, port_stat_grps);
}

static ssize_t target_stat_transport_inst_show(struct config_item *item,
		char *page)
{
	struct se_lun *lun = to_transport_stat(item);
728 729
	struct se_device *dev;
	ssize_t ret = -ENODEV;
730

731 732
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
733
	if (dev)
734 735
		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
	rcu_read_unlock();
736 737 738
	return ret;
}

739 740
static ssize_t target_stat_transport_device_show(struct config_item *item,
		char *page)
741
{
742
	struct se_lun *lun = to_transport_stat(item);
743 744 745
	struct se_device *dev;
	struct se_portal_group *tpg = lun->lun_tpg;
	ssize_t ret = -ENODEV;
746

747 748
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
749 750 751 752
	if (dev) {
		/* scsiTransportType */
		ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
			       tpg->se_tpg_tfo->get_fabric_name());
753
	}
754
	rcu_read_unlock();
755 756 757
	return ret;
}

758 759
static ssize_t target_stat_transport_indx_show(struct config_item *item,
		char *page)
760
{
761
	struct se_lun *lun = to_transport_stat(item);
762 763 764
	struct se_device *dev;
	struct se_portal_group *tpg = lun->lun_tpg;
	ssize_t ret = -ENODEV;
765

766 767
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
768 769 770
	if (dev)
		ret = snprintf(page, PAGE_SIZE, "%u\n",
			       tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
771
	rcu_read_unlock();
772 773 774
	return ret;
}

775 776
static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
		char *page)
777
{
778
	struct se_lun *lun = to_transport_stat(item);
779
	struct se_device *dev;
780
	struct se_portal_group *tpg = lun->lun_tpg;
781
	struct t10_wwn *wwn;
782
	ssize_t ret = -ENODEV;
783

784 785
	rcu_read_lock();
	dev = rcu_dereference(lun->lun_se_dev);
786 787 788 789 790 791 792
	if (dev) {
		wwn = &dev->t10_wwn;
		/* scsiTransportDevName */
		ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
				tpg->se_tpg_tfo->tpg_get_wwn(tpg),
				(strlen(wwn->unit_serial)) ? wwn->unit_serial :
				wwn->vendor);
793
	}
794
	rcu_read_unlock();
795 796 797
	return ret;
}

798 799 800 801
CONFIGFS_ATTR_RO(target_stat_transport_, inst);
CONFIGFS_ATTR_RO(target_stat_transport_, device);
CONFIGFS_ATTR_RO(target_stat_transport_, indx);
CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
802 803

static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
804 805 806 807
	&target_stat_transport_attr_inst,
	&target_stat_transport_attr_device,
	&target_stat_transport_attr_indx,
	&target_stat_transport_attr_dev_name,
808 809 810 811 812 813 814 815 816 817 818 819 820 821
	NULL,
};

static struct config_item_type target_stat_scsi_transport_cit = {
	.ct_attrs		= target_stat_scsi_transport_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
 * the target port statistics groups + configfs CITs located in target_core_stat.c
 */
void target_stat_setup_port_default_groups(struct se_lun *lun)
{
822
	config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
823
			"scsi_port", &target_stat_scsi_port_cit);
824 825 826
	configfs_add_default_group(&lun->port_stat_grps.scsi_port_group,
			&lun->port_stat_grps.stat_group);

827
	config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
828
			"scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
829 830 831
	configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group,
			&lun->port_stat_grps.stat_group);

832
	config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
833
			"scsi_transport", &target_stat_scsi_transport_cit);
834 835
	configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group,
			&lun->port_stat_grps.stat_group);
836 837 838 839 840 841
}

/*
 * SCSI Authorized Initiator Table
 */

842 843 844 845 846 847 848 849 850 851 852
static struct se_lun_acl *auth_to_lacl(struct config_item *item)
{
	struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
			struct se_ml_stat_grps, scsi_auth_intr_group);
	return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
}

static ssize_t target_stat_auth_inst_show(struct config_item *item,
		char *page)
{
	struct se_lun_acl *lacl = auth_to_lacl(item);
853 854 855 856 857
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	struct se_portal_group *tpg;
	ssize_t ret;

858 859 860 861
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
862 863 864 865 866
		return -ENODEV;
	}
	tpg = nacl->se_tpg;
	/* scsiInstIndex */
	ret = snprintf(page, PAGE_SIZE, "%u\n",
867
			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
868
	rcu_read_unlock();
869 870 871
	return ret;
}

872 873
static ssize_t target_stat_auth_dev_show(struct config_item *item,
		char *page)
874
{
875
	struct se_lun_acl *lacl = auth_to_lacl(item);
876 877 878 879 880
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	struct se_lun *lun;
	ssize_t ret;

881 882 883 884
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
885 886
		return -ENODEV;
	}
887
	lun = rcu_dereference(deve->se_lun);
888
	/* scsiDeviceIndex */
889 890
	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
	rcu_read_unlock();
891 892 893
	return ret;
}

894 895
static ssize_t target_stat_auth_port_show(struct config_item *item,
		char *page)
896
{
897
	struct se_lun_acl *lacl = auth_to_lacl(item);
898 899 900 901 902
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	struct se_portal_group *tpg;
	ssize_t ret;

903 904 905 906
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
907 908 909 910
		return -ENODEV;
	}
	tpg = nacl->se_tpg;
	/* scsiAuthIntrTgtPortIndex */
911
	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
912
	rcu_read_unlock();
913 914 915
	return ret;
}

916 917
static ssize_t target_stat_auth_indx_show(struct config_item *item,
		char *page)
918
{
919
	struct se_lun_acl *lacl = auth_to_lacl(item);
920 921 922 923
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

924 925 926 927
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
928 929 930 931
		return -ENODEV;
	}
	/* scsiAuthIntrIndex */
	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
932
	rcu_read_unlock();
933 934 935
	return ret;
}

936 937
static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
		char *page)
938
{
939
	struct se_lun_acl *lacl = auth_to_lacl(item);
940 941 942 943
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

944 945 946 947
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
948 949 950 951
		return -ENODEV;
	}
	/* scsiAuthIntrDevOrPort */
	ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
952
	rcu_read_unlock();
953 954 955
	return ret;
}

956 957
static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
		char *page)
958
{
959
	struct se_lun_acl *lacl = auth_to_lacl(item);
960 961 962 963
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

964 965 966 967
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
968 969 970 971
		return -ENODEV;
	}
	/* scsiAuthIntrName */
	ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
972
	rcu_read_unlock();
973 974 975
	return ret;
}

976 977
static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
		char *page)
978
{
979
	struct se_lun_acl *lacl = auth_to_lacl(item);
980 981 982 983
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

984 985 986 987
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
988 989 990 991
		return -ENODEV;
	}
	/* FIXME: scsiAuthIntrLunMapIndex */
	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
992
	rcu_read_unlock();
993 994 995
	return ret;
}

996 997
static ssize_t target_stat_auth_att_count_show(struct config_item *item,
		char *page)
998
{
999
	struct se_lun_acl *lacl = auth_to_lacl(item);
1000 1001 1002 1003
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1004 1005 1006 1007
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1008 1009 1010 1011
		return -ENODEV;
	}
	/* scsiAuthIntrAttachedTimes */
	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1012
	rcu_read_unlock();
1013 1014 1015
	return ret;
}

1016 1017
static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
		char *page)
1018
{
1019
	struct se_lun_acl *lacl = auth_to_lacl(item);
1020 1021 1022 1023
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1024 1025 1026 1027
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1028 1029 1030
		return -ENODEV;
	}
	/* scsiAuthIntrOutCommands */
1031 1032 1033
	ret = snprintf(page, PAGE_SIZE, "%lu\n",
		       atomic_long_read(&deve->total_cmds));
	rcu_read_unlock();
1034 1035 1036
	return ret;
}

1037 1038
static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
		char *page)
1039
{
1040
	struct se_lun_acl *lacl = auth_to_lacl(item);
1041 1042 1043 1044
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1045 1046 1047 1048
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1049 1050 1051
		return -ENODEV;
	}
	/* scsiAuthIntrReadMegaBytes */
1052 1053 1054
	ret = snprintf(page, PAGE_SIZE, "%u\n",
		      (u32)(atomic_long_read(&deve->read_bytes) >> 20));
	rcu_read_unlock();
1055 1056 1057
	return ret;
}

1058 1059
static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
		char *page)
1060
{
1061
	struct se_lun_acl *lacl = auth_to_lacl(item);
1062 1063 1064 1065
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1066 1067 1068 1069
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1070 1071 1072
		return -ENODEV;
	}
	/* scsiAuthIntrWrittenMegaBytes */
1073 1074 1075
	ret = snprintf(page, PAGE_SIZE, "%u\n",
		      (u32)(atomic_long_read(&deve->write_bytes) >> 20));
	rcu_read_unlock();
1076 1077 1078
	return ret;
}

1079 1080
static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
		char *page)
1081
{
1082
	struct se_lun_acl *lacl = auth_to_lacl(item);
1083 1084 1085 1086
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1087 1088 1089 1090
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1091 1092 1093 1094
		return -ENODEV;
	}
	/* FIXME: scsiAuthIntrHSOutCommands */
	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1095
	rcu_read_unlock();
1096 1097 1098
	return ret;
}

1099 1100
static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
		char *page)
1101
{
1102
	struct se_lun_acl *lacl = auth_to_lacl(item);
1103 1104 1105 1106
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1107 1108 1109 1110
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1111 1112 1113 1114 1115
		return -ENODEV;
	}
	/* scsiAuthIntrLastCreation */
	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
				INITIAL_JIFFIES) * 100 / HZ));
1116
	rcu_read_unlock();
1117 1118 1119
	return ret;
}

1120 1121
static ssize_t target_stat_auth_row_status_show(struct config_item *item,
		char *page)
1122
{
1123
	struct se_lun_acl *lacl = auth_to_lacl(item);
1124 1125 1126 1127
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	ssize_t ret;

1128 1129 1130 1131
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1132 1133 1134 1135
		return -ENODEV;
	}
	/* FIXME: scsiAuthIntrRowStatus */
	ret = snprintf(page, PAGE_SIZE, "Ready\n");
1136
	rcu_read_unlock();
1137 1138 1139
	return ret;
}

1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
CONFIGFS_ATTR_RO(target_stat_auth_, inst);
CONFIGFS_ATTR_RO(target_stat_auth_, dev);
CONFIGFS_ATTR_RO(target_stat_auth_, port);
CONFIGFS_ATTR_RO(target_stat_auth_, indx);
CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
1154 1155

static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169
	&target_stat_auth_attr_inst,
	&target_stat_auth_attr_dev,
	&target_stat_auth_attr_port,
	&target_stat_auth_attr_indx,
	&target_stat_auth_attr_dev_or_port,
	&target_stat_auth_attr_intr_name,
	&target_stat_auth_attr_map_indx,
	&target_stat_auth_attr_att_count,
	&target_stat_auth_attr_num_cmds,
	&target_stat_auth_attr_read_mbytes,
	&target_stat_auth_attr_write_mbytes,
	&target_stat_auth_attr_hs_num_cmds,
	&target_stat_auth_attr_creation_time,
	&target_stat_auth_attr_row_status,
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181
	NULL,
};

static struct config_item_type target_stat_scsi_auth_intr_cit = {
	.ct_attrs		= target_stat_scsi_auth_intr_attrs,
	.ct_owner		= THIS_MODULE,
};

/*
 * SCSI Attached Initiator Port Table
 */

1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192
static struct se_lun_acl *iport_to_lacl(struct config_item *item)
{
	struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
			struct se_ml_stat_grps, scsi_att_intr_port_group);
	return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
}

static ssize_t target_stat_iport_inst_show(struct config_item *item,
		char *page)
{
	struct se_lun_acl *lacl = iport_to_lacl(item);
1193 1194 1195 1196 1197
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	struct se_portal_group *tpg;
	ssize_t ret;

1198 1199 1200 1201
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1202 1203 1204 1205 1206
		return -ENODEV;
	}
	tpg = nacl->se_tpg;
	/* scsiInstIndex */
	ret = snprintf(page, PAGE_SIZE, "%u\n",
1207
			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1208
	rcu_read_unlock();
1209 1210 1211
	return ret;
}

1212 1213
static ssize_t target_stat_iport_dev_show(struct config_item *item,
		char *page)
1214
{
1215
	struct se_lun_acl *lacl = iport_to_lacl(item);
1216 1217 1218 1219 1220
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	struct se_lun *lun;
	ssize_t ret;

1221 1222 1223 1224
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1225 1226
		return -ENODEV;
	}
1227
	lun = rcu_dereference(deve->se_lun);
1228
	/* scsiDeviceIndex */
1229 1230
	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
	rcu_read_unlock();
1231 1232 1233
	return ret;
}

1234 1235
static ssize_t target_stat_iport_port_show(struct config_item *item,
		char *page)
1236
{
1237
	struct se_lun_acl *lacl = iport_to_lacl(item);
1238 1239 1240 1241 1242
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_dev_entry *deve;
	struct se_portal_group *tpg;
	ssize_t ret;

1243 1244 1245 1246
	rcu_read_lock();
	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
	if (!deve) {
		rcu_read_unlock();
1247 1248 1249 1250
		return -ENODEV;
	}
	tpg = nacl->se_tpg;
	/* scsiPortIndex */
1251
	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1252
	rcu_read_unlock();
1253 1254 1255
	return ret;
}

1256 1257
static ssize_t target_stat_iport_indx_show(struct config_item *item,
		char *page)
1258
{
1259
	struct se_lun_acl *lacl = iport_to_lacl(item);
1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274
	struct se_node_acl *nacl = lacl->se_lun_nacl;
	struct se_session *se_sess;
	struct se_portal_group *tpg;
	ssize_t ret;

	spin_lock_irq(&nacl->nacl_sess_lock);
	se_sess = nacl->nacl_sess;
	if (!se_sess) {
		spin_unlock_irq(&nacl->nacl_sess_lock);
		return -ENODEV;
	}

	tpg = nacl->se_tpg;
	/* scsiAttIntrPortIndex */
	ret = snprintf(page, PAGE_SIZE, "%u\n",
1275
			tpg->se_tpg_tfo->sess_get_index(se_sess));
1276 1277 1278 1279
	spin_unlock_irq(&nacl->nacl_sess_lock);
	return ret;
}

1280 1281
static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
		char *page)
1282
{
1283
	struct se_lun_acl *lacl