Linux Audio

Check our new training course

Loading...
v3.1
 
   1/*******************************************************************************
   2 * Filename:  target_core_stat.c
   3 *
   4 * Copyright (c) 2011 Rising Tide Systems
   5 * Copyright (c) 2011 Linux-iSCSI.org
   6 *
   7 * Modern ConfigFS group context specific statistics based on original
   8 * target_core_mib.c code
   9 *
  10 * Copyright (c) 2006-2007 SBE, Inc.  All Rights Reserved.
  11 *
  12 * Nicholas A. Bellinger <nab@linux-iscsi.org>
  13 *
  14 * This program is free software; you can redistribute it and/or modify
  15 * it under the terms of the GNU General Public License as published by
  16 * the Free Software Foundation; either version 2 of the License, or
  17 * (at your option) any later version.
  18 *
  19 * This program is distributed in the hope that it will be useful,
  20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  22 * GNU General Public License for more details.
  23 *
  24 * You should have received a copy of the GNU General Public License
  25 * along with this program; if not, write to the Free Software
  26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27 *
  28 ******************************************************************************/
  29
  30#include <linux/kernel.h>
  31#include <linux/module.h>
  32#include <linux/delay.h>
  33#include <linux/timer.h>
  34#include <linux/string.h>
  35#include <linux/version.h>
  36#include <generated/utsrelease.h>
  37#include <linux/utsname.h>
  38#include <linux/proc_fs.h>
  39#include <linux/seq_file.h>
  40#include <linux/blkdev.h>
  41#include <linux/configfs.h>
  42#include <scsi/scsi.h>
  43#include <scsi/scsi_device.h>
  44#include <scsi/scsi_host.h>
  45
  46#include <target/target_core_base.h>
  47#include <target/target_core_transport.h>
  48#include <target/target_core_fabric_ops.h>
  49#include <target/target_core_configfs.h>
  50#include <target/configfs_macros.h>
  51
  52#include "target_core_hba.h"
  53
  54#ifndef INITIAL_JIFFIES
  55#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
  56#endif
  57
  58#define NONE		"None"
  59#define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
  60
  61#define SCSI_LU_INDEX			1
  62#define LU_COUNT			1
  63
  64/*
  65 * SCSI Device Table
  66 */
  67
  68CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps);
  69#define DEV_STAT_SCSI_DEV_ATTR(_name, _mode)				\
  70static struct target_stat_scsi_dev_attribute				\
  71			target_stat_scsi_dev_##_name =			\
  72	__CONFIGFS_EATTR(_name, _mode,					\
  73	target_stat_scsi_dev_show_attr_##_name,				\
  74	target_stat_scsi_dev_store_attr_##_name);
  75
  76#define DEV_STAT_SCSI_DEV_ATTR_RO(_name)				\
  77static struct target_stat_scsi_dev_attribute				\
  78			target_stat_scsi_dev_##_name =			\
  79	__CONFIGFS_EATTR_RO(_name,					\
  80	target_stat_scsi_dev_show_attr_##_name);
  81
  82static ssize_t target_stat_scsi_dev_show_attr_inst(
  83	struct se_dev_stat_grps *sgrps, char *page)
  84{
  85	struct se_subsystem_dev *se_subdev = container_of(sgrps,
  86			struct se_subsystem_dev, dev_stat_grps);
  87	struct se_hba *hba = se_subdev->se_dev_hba;
  88	struct se_device *dev = se_subdev->se_dev_ptr;
  89
  90	if (!dev)
  91		return -ENODEV;
 
  92
  93	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  94}
  95DEV_STAT_SCSI_DEV_ATTR_RO(inst);
  96
  97static ssize_t target_stat_scsi_dev_show_attr_indx(
  98	struct se_dev_stat_grps *sgrps, char *page)
  99{
 100	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 101			struct se_subsystem_dev, dev_stat_grps);
 102	struct se_device *dev = se_subdev->se_dev_ptr;
 103
 104	if (!dev)
 105		return -ENODEV;
 106
 107	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 108}
 109DEV_STAT_SCSI_DEV_ATTR_RO(indx);
 110
 111static ssize_t target_stat_scsi_dev_show_attr_role(
 112	struct se_dev_stat_grps *sgrps, char *page)
 113{
 114	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 115			struct se_subsystem_dev, dev_stat_grps);
 116	struct se_device *dev = se_subdev->se_dev_ptr;
 117
 118	if (!dev)
 119		return -ENODEV;
 120
 121	return snprintf(page, PAGE_SIZE, "Target\n");
 122}
 123DEV_STAT_SCSI_DEV_ATTR_RO(role);
 124
 125static ssize_t target_stat_scsi_dev_show_attr_ports(
 126	struct se_dev_stat_grps *sgrps, char *page)
 127{
 128	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 129			struct se_subsystem_dev, dev_stat_grps);
 130	struct se_device *dev = se_subdev->se_dev_ptr;
 131
 132	if (!dev)
 133		return -ENODEV;
 134
 135	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_port_count);
 136}
 137DEV_STAT_SCSI_DEV_ATTR_RO(ports);
 138
 139CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group);
 
 
 
 140
 141static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
 142	&target_stat_scsi_dev_inst.attr,
 143	&target_stat_scsi_dev_indx.attr,
 144	&target_stat_scsi_dev_role.attr,
 145	&target_stat_scsi_dev_ports.attr,
 146	NULL,
 147};
 148
 149static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
 150	.show_attribute		= target_stat_scsi_dev_attr_show,
 151	.store_attribute	= target_stat_scsi_dev_attr_store,
 152};
 153
 154static struct config_item_type target_stat_scsi_dev_cit = {
 155	.ct_item_ops		= &target_stat_scsi_dev_attrib_ops,
 156	.ct_attrs		= target_stat_scsi_dev_attrs,
 157	.ct_owner		= THIS_MODULE,
 158};
 159
 160/*
 161 * SCSI Target Device Table
 162 */
 
 
 
 
 
 
 163
 164CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps);
 165#define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode)			\
 166static struct target_stat_scsi_tgt_dev_attribute			\
 167			target_stat_scsi_tgt_dev_##_name =		\
 168	__CONFIGFS_EATTR(_name, _mode,					\
 169	target_stat_scsi_tgt_dev_show_attr_##_name,			\
 170	target_stat_scsi_tgt_dev_store_attr_##_name);
 171
 172#define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name)				\
 173static struct target_stat_scsi_tgt_dev_attribute			\
 174			target_stat_scsi_tgt_dev_##_name =		\
 175	__CONFIGFS_EATTR_RO(_name,					\
 176	target_stat_scsi_tgt_dev_show_attr_##_name);
 177
 178static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
 179	struct se_dev_stat_grps *sgrps, char *page)
 180{
 181	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 182			struct se_subsystem_dev, dev_stat_grps);
 183	struct se_hba *hba = se_subdev->se_dev_hba;
 184	struct se_device *dev = se_subdev->se_dev_ptr;
 185
 186	if (!dev)
 187		return -ENODEV;
 188
 189	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
 190}
 191DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
 192
 193static ssize_t target_stat_scsi_tgt_dev_show_attr_indx(
 194	struct se_dev_stat_grps *sgrps, char *page)
 195{
 196	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 197			struct se_subsystem_dev, dev_stat_grps);
 198	struct se_device *dev = se_subdev->se_dev_ptr;
 199
 200	if (!dev)
 201		return -ENODEV;
 202
 203	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 204}
 205DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
 206
 207static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus(
 208	struct se_dev_stat_grps *sgrps, char *page)
 209{
 210	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 211			struct se_subsystem_dev, dev_stat_grps);
 212	struct se_device *dev = se_subdev->se_dev_ptr;
 213
 214	if (!dev)
 215		return -ENODEV;
 216
 217	return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
 218}
 219DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
 220
 221static ssize_t target_stat_scsi_tgt_dev_show_attr_status(
 222	struct se_dev_stat_grps *sgrps, char *page)
 223{
 224	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 225			struct se_subsystem_dev, dev_stat_grps);
 226	struct se_device *dev = se_subdev->se_dev_ptr;
 227	char status[16];
 228
 229	if (!dev)
 230		return -ENODEV;
 231
 232	switch (dev->dev_status) {
 233	case TRANSPORT_DEVICE_ACTIVATED:
 234		strcpy(status, "activated");
 235		break;
 236	case TRANSPORT_DEVICE_DEACTIVATED:
 237		strcpy(status, "deactivated");
 238		break;
 239	case TRANSPORT_DEVICE_SHUTDOWN:
 240		strcpy(status, "shutdown");
 241		break;
 242	case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
 243	case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
 244		strcpy(status, "offline");
 245		break;
 246	default:
 247		sprintf(status, "unknown(%d)", dev->dev_status);
 248		break;
 249	}
 250
 251	return snprintf(page, PAGE_SIZE, "%s\n", status);
 252}
 253DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
 254
 255static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus(
 256	struct se_dev_stat_grps *sgrps, char *page)
 257{
 258	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 259			struct se_subsystem_dev, dev_stat_grps);
 260	struct se_device *dev = se_subdev->se_dev_ptr;
 261	int non_accessible_lus;
 262
 263	if (!dev)
 264		return -ENODEV;
 265
 266	switch (dev->dev_status) {
 267	case TRANSPORT_DEVICE_ACTIVATED:
 268		non_accessible_lus = 0;
 269		break;
 270	case TRANSPORT_DEVICE_DEACTIVATED:
 271	case TRANSPORT_DEVICE_SHUTDOWN:
 272	case TRANSPORT_DEVICE_OFFLINE_ACTIVATED:
 273	case TRANSPORT_DEVICE_OFFLINE_DEACTIVATED:
 274	default:
 275		non_accessible_lus = 1;
 276		break;
 277	}
 278
 279	return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
 280}
 281DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
 282
 283static ssize_t target_stat_scsi_tgt_dev_show_attr_resets(
 284	struct se_dev_stat_grps *sgrps, char *page)
 285{
 286	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 287			struct se_subsystem_dev, dev_stat_grps);
 288	struct se_device *dev = se_subdev->se_dev_ptr;
 289
 290	if (!dev)
 291		return -ENODEV;
 292
 293	return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
 
 
 
 
 294}
 295DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
 296
 
 
 
 
 
 
 297
 298CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group);
 
 
 
 
 
 
 
 299
 300static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
 301	&target_stat_scsi_tgt_dev_inst.attr,
 302	&target_stat_scsi_tgt_dev_indx.attr,
 303	&target_stat_scsi_tgt_dev_num_lus.attr,
 304	&target_stat_scsi_tgt_dev_status.attr,
 305	&target_stat_scsi_tgt_dev_non_access_lus.attr,
 306	&target_stat_scsi_tgt_dev_resets.attr,
 
 
 307	NULL,
 308};
 309
 310static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
 311	.show_attribute		= target_stat_scsi_tgt_dev_attr_show,
 312	.store_attribute	= target_stat_scsi_tgt_dev_attr_store,
 313};
 314
 315static struct config_item_type target_stat_scsi_tgt_dev_cit = {
 316	.ct_item_ops		= &target_stat_scsi_tgt_dev_attrib_ops,
 317	.ct_attrs		= target_stat_scsi_tgt_dev_attrs,
 318	.ct_owner		= THIS_MODULE,
 319};
 320
 321/*
 322 * SCSI Logical Unit Table
 323 */
 324
 325CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps);
 326#define DEV_STAT_SCSI_LU_ATTR(_name, _mode)				\
 327static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
 328	__CONFIGFS_EATTR(_name, _mode,					\
 329	target_stat_scsi_lu_show_attr_##_name,				\
 330	target_stat_scsi_lu_store_attr_##_name);
 331
 332#define DEV_STAT_SCSI_LU_ATTR_RO(_name)					\
 333static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
 334	__CONFIGFS_EATTR_RO(_name,					\
 335	target_stat_scsi_lu_show_attr_##_name);
 336
 337static ssize_t target_stat_scsi_lu_show_attr_inst(
 338	struct se_dev_stat_grps *sgrps, char *page)
 339{
 340	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 341			struct se_subsystem_dev, dev_stat_grps);
 342	struct se_hba *hba = se_subdev->se_dev_hba;
 343	struct se_device *dev = se_subdev->se_dev_ptr;
 344
 345	if (!dev)
 346		return -ENODEV;
 
 347
 348	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
 349}
 350DEV_STAT_SCSI_LU_ATTR_RO(inst);
 351
 352static ssize_t target_stat_scsi_lu_show_attr_dev(
 353	struct se_dev_stat_grps *sgrps, char *page)
 354{
 355	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 356			struct se_subsystem_dev, dev_stat_grps);
 357	struct se_device *dev = se_subdev->se_dev_ptr;
 358
 359	if (!dev)
 360		return -ENODEV;
 361
 362	return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 363}
 364DEV_STAT_SCSI_LU_ATTR_RO(dev);
 365
 366static ssize_t target_stat_scsi_lu_show_attr_indx(
 367	struct se_dev_stat_grps *sgrps, char *page)
 368{
 369	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 370			struct se_subsystem_dev, dev_stat_grps);
 371	struct se_device *dev = se_subdev->se_dev_ptr;
 372
 373	if (!dev)
 374		return -ENODEV;
 375
 376	return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
 377}
 378DEV_STAT_SCSI_LU_ATTR_RO(indx);
 379
 380static ssize_t target_stat_scsi_lu_show_attr_lun(
 381	struct se_dev_stat_grps *sgrps, char *page)
 382{
 383	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 384			struct se_subsystem_dev, dev_stat_grps);
 385	struct se_device *dev = se_subdev->se_dev_ptr;
 386
 387	if (!dev)
 388		return -ENODEV;
 389	/* FIXME: scsiLuDefaultLun */
 390	return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
 391}
 392DEV_STAT_SCSI_LU_ATTR_RO(lun);
 393
 394static ssize_t target_stat_scsi_lu_show_attr_lu_name(
 395	struct se_dev_stat_grps *sgrps, char *page)
 396{
 397	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 398			struct se_subsystem_dev, dev_stat_grps);
 399	struct se_device *dev = se_subdev->se_dev_ptr;
 400
 401	if (!dev)
 402		return -ENODEV;
 403	/* scsiLuWwnName */
 404	return snprintf(page, PAGE_SIZE, "%s\n",
 405			(strlen(dev->se_sub_dev->t10_wwn.unit_serial)) ?
 406			dev->se_sub_dev->t10_wwn.unit_serial : "None");
 407}
 408DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
 409
 410static ssize_t target_stat_scsi_lu_show_attr_vend(
 411	struct se_dev_stat_grps *sgrps, char *page)
 412{
 413	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 414			struct se_subsystem_dev, dev_stat_grps);
 415	struct se_device *dev = se_subdev->se_dev_ptr;
 416	int i;
 417	char str[sizeof(dev->se_sub_dev->t10_wwn.vendor)+1];
 418
 419	if (!dev)
 420		return -ENODEV;
 421
 422	/* scsiLuVendorId */
 423	for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
 424		str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.vendor[i]) ?
 425			dev->se_sub_dev->t10_wwn.vendor[i] : ' ';
 426	str[i] = '\0';
 427	return snprintf(page, PAGE_SIZE, "%s\n", str);
 428}
 429DEV_STAT_SCSI_LU_ATTR_RO(vend);
 430
 431static ssize_t target_stat_scsi_lu_show_attr_prod(
 432	struct se_dev_stat_grps *sgrps, char *page)
 433{
 434	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 435			struct se_subsystem_dev, dev_stat_grps);
 436	struct se_device *dev = se_subdev->se_dev_ptr;
 437	int i;
 438	char str[sizeof(dev->se_sub_dev->t10_wwn.model)+1];
 439
 440	if (!dev)
 441		return -ENODEV;
 
 442
 443	/* scsiLuProductId */
 444	for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.vendor); i++)
 445		str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.model[i]) ?
 446			dev->se_sub_dev->t10_wwn.model[i] : ' ';
 447	str[i] = '\0';
 448	return snprintf(page, PAGE_SIZE, "%s\n", str);
 449}
 450DEV_STAT_SCSI_LU_ATTR_RO(prod);
 451
 452static ssize_t target_stat_scsi_lu_show_attr_rev(
 453	struct se_dev_stat_grps *sgrps, char *page)
 454{
 455	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 456			struct se_subsystem_dev, dev_stat_grps);
 457	struct se_device *dev = se_subdev->se_dev_ptr;
 458	int i;
 459	char str[sizeof(dev->se_sub_dev->t10_wwn.revision)+1];
 460
 461	if (!dev)
 462		return -ENODEV;
 
 463
 464	/* scsiLuRevisionId */
 465	for (i = 0; i < sizeof(dev->se_sub_dev->t10_wwn.revision); i++)
 466		str[i] = ISPRINT(dev->se_sub_dev->t10_wwn.revision[i]) ?
 467			dev->se_sub_dev->t10_wwn.revision[i] : ' ';
 468	str[i] = '\0';
 469	return snprintf(page, PAGE_SIZE, "%s\n", str);
 470}
 471DEV_STAT_SCSI_LU_ATTR_RO(rev);
 472
 473static ssize_t target_stat_scsi_lu_show_attr_dev_type(
 474	struct se_dev_stat_grps *sgrps, char *page)
 475{
 476	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 477			struct se_subsystem_dev, dev_stat_grps);
 478	struct se_device *dev = se_subdev->se_dev_ptr;
 479
 480	if (!dev)
 481		return -ENODEV;
 
 482
 483	/* scsiLuPeripheralType */
 484	return snprintf(page, PAGE_SIZE, "%u\n",
 485			dev->transport->get_device_type(dev));
 486}
 487DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
 488
 489static ssize_t target_stat_scsi_lu_show_attr_status(
 490	struct se_dev_stat_grps *sgrps, char *page)
 491{
 492	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 493			struct se_subsystem_dev, dev_stat_grps);
 494	struct se_device *dev = se_subdev->se_dev_ptr;
 495
 496	if (!dev)
 497		return -ENODEV;
 498
 499	/* scsiLuStatus */
 500	return snprintf(page, PAGE_SIZE, "%s\n",
 501		(dev->dev_status == TRANSPORT_DEVICE_ACTIVATED) ?
 502		"available" : "notavailable");
 503}
 504DEV_STAT_SCSI_LU_ATTR_RO(status);
 505
 506static ssize_t target_stat_scsi_lu_show_attr_state_bit(
 507	struct se_dev_stat_grps *sgrps, char *page)
 508{
 509	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 510			struct se_subsystem_dev, dev_stat_grps);
 511	struct se_device *dev = se_subdev->se_dev_ptr;
 512
 513	if (!dev)
 514		return -ENODEV;
 515
 516	/* scsiLuState */
 517	return snprintf(page, PAGE_SIZE, "exposed\n");
 518}
 519DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
 520
 521static ssize_t target_stat_scsi_lu_show_attr_num_cmds(
 522	struct se_dev_stat_grps *sgrps, char *page)
 523{
 524	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 525			struct se_subsystem_dev, dev_stat_grps);
 526	struct se_device *dev = se_subdev->se_dev_ptr;
 527
 528	if (!dev)
 529		return -ENODEV;
 530
 531	/* scsiLuNumCommands */
 532	return snprintf(page, PAGE_SIZE, "%llu\n",
 533			(unsigned long long)dev->num_cmds);
 534}
 535DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
 536
 537static ssize_t target_stat_scsi_lu_show_attr_read_mbytes(
 538	struct se_dev_stat_grps *sgrps, char *page)
 539{
 540	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 541			struct se_subsystem_dev, dev_stat_grps);
 542	struct se_device *dev = se_subdev->se_dev_ptr;
 543
 544	if (!dev)
 545		return -ENODEV;
 546
 547	/* scsiLuReadMegaBytes */
 548	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->read_bytes >> 20));
 
 549}
 550DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
 551
 552static ssize_t target_stat_scsi_lu_show_attr_write_mbytes(
 553	struct se_dev_stat_grps *sgrps, char *page)
 554{
 555	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 556			struct se_subsystem_dev, dev_stat_grps);
 557	struct se_device *dev = se_subdev->se_dev_ptr;
 558
 559	if (!dev)
 560		return -ENODEV;
 561
 562	/* scsiLuWrittenMegaBytes */
 563	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(dev->write_bytes >> 20));
 
 564}
 565DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
 566
 567static ssize_t target_stat_scsi_lu_show_attr_resets(
 568	struct se_dev_stat_grps *sgrps, char *page)
 569{
 570	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 571			struct se_subsystem_dev, dev_stat_grps);
 572	struct se_device *dev = se_subdev->se_dev_ptr;
 573
 574	if (!dev)
 575		return -ENODEV;
 576
 577	/* scsiLuInResets */
 578	return snprintf(page, PAGE_SIZE, "%u\n", dev->num_resets);
 
 579}
 580DEV_STAT_SCSI_LU_ATTR_RO(resets);
 581
 582static ssize_t target_stat_scsi_lu_show_attr_full_stat(
 583	struct se_dev_stat_grps *sgrps, char *page)
 584{
 585	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 586			struct se_subsystem_dev, dev_stat_grps);
 587	struct se_device *dev = se_subdev->se_dev_ptr;
 588
 589	if (!dev)
 590		return -ENODEV;
 591
 592	/* FIXME: scsiLuOutTaskSetFullStatus */
 593	return snprintf(page, PAGE_SIZE, "%u\n", 0);
 594}
 595DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
 596
 597static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds(
 598	struct se_dev_stat_grps *sgrps, char *page)
 599{
 600	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 601			struct se_subsystem_dev, dev_stat_grps);
 602	struct se_device *dev = se_subdev->se_dev_ptr;
 603
 604	if (!dev)
 605		return -ENODEV;
 606
 607	/* FIXME: scsiLuHSInCommands */
 608	return snprintf(page, PAGE_SIZE, "%u\n", 0);
 609}
 610DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
 611
 612static ssize_t target_stat_scsi_lu_show_attr_creation_time(
 613	struct se_dev_stat_grps *sgrps, char *page)
 614{
 615	struct se_subsystem_dev *se_subdev = container_of(sgrps,
 616			struct se_subsystem_dev, dev_stat_grps);
 617	struct se_device *dev = se_subdev->se_dev_ptr;
 618
 619	if (!dev)
 620		return -ENODEV;
 621
 622	/* scsiLuCreationTime */
 623	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
 624				INITIAL_JIFFIES) * 100 / HZ));
 625}
 626DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
 627
 628CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 629
 630static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
 631	&target_stat_scsi_lu_inst.attr,
 632	&target_stat_scsi_lu_dev.attr,
 633	&target_stat_scsi_lu_indx.attr,
 634	&target_stat_scsi_lu_lun.attr,
 635	&target_stat_scsi_lu_lu_name.attr,
 636	&target_stat_scsi_lu_vend.attr,
 637	&target_stat_scsi_lu_prod.attr,
 638	&target_stat_scsi_lu_rev.attr,
 639	&target_stat_scsi_lu_dev_type.attr,
 640	&target_stat_scsi_lu_status.attr,
 641	&target_stat_scsi_lu_state_bit.attr,
 642	&target_stat_scsi_lu_num_cmds.attr,
 643	&target_stat_scsi_lu_read_mbytes.attr,
 644	&target_stat_scsi_lu_write_mbytes.attr,
 645	&target_stat_scsi_lu_resets.attr,
 646	&target_stat_scsi_lu_full_stat.attr,
 647	&target_stat_scsi_lu_hs_num_cmds.attr,
 648	&target_stat_scsi_lu_creation_time.attr,
 649	NULL,
 650};
 651
 652static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
 653	.show_attribute		= target_stat_scsi_lu_attr_show,
 654	.store_attribute	= target_stat_scsi_lu_attr_store,
 655};
 656
 657static struct config_item_type target_stat_scsi_lu_cit = {
 658	.ct_item_ops		= &target_stat_scsi_lu_attrib_ops,
 659	.ct_attrs		= target_stat_scsi_lu_attrs,
 660	.ct_owner		= THIS_MODULE,
 661};
 662
 663/*
 664 * Called from target_core_configfs.c:target_core_make_subdev() to setup
 665 * the target statistics groups + configfs CITs located in target_core_stat.c
 666 */
 667void target_stat_setup_dev_default_groups(struct se_subsystem_dev *se_subdev)
 668{
 669	struct config_group *dev_stat_grp = &se_subdev->dev_stat_grps.stat_group;
 670
 671	config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_dev_group,
 672			"scsi_dev", &target_stat_scsi_dev_cit);
 673	config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_tgt_dev_group,
 
 
 
 674			"scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
 675	config_group_init_type_name(&se_subdev->dev_stat_grps.scsi_lu_group,
 676			"scsi_lu", &target_stat_scsi_lu_cit);
 677
 678	dev_stat_grp->default_groups[0] = &se_subdev->dev_stat_grps.scsi_dev_group;
 679	dev_stat_grp->default_groups[1] = &se_subdev->dev_stat_grps.scsi_tgt_dev_group;
 680	dev_stat_grp->default_groups[2] = &se_subdev->dev_stat_grps.scsi_lu_group;
 681	dev_stat_grp->default_groups[3] = NULL;
 682}
 683
 684/*
 685 * SCSI Port Table
 686 */
 687
 688CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps);
 689#define DEV_STAT_SCSI_PORT_ATTR(_name, _mode)				\
 690static struct target_stat_scsi_port_attribute				\
 691			target_stat_scsi_port_##_name =			\
 692	__CONFIGFS_EATTR(_name, _mode,					\
 693	target_stat_scsi_port_show_attr_##_name,			\
 694	target_stat_scsi_port_store_attr_##_name);
 695
 696#define DEV_STAT_SCSI_PORT_ATTR_RO(_name)				\
 697static struct target_stat_scsi_port_attribute				\
 698			target_stat_scsi_port_##_name =			\
 699	__CONFIGFS_EATTR_RO(_name,					\
 700	target_stat_scsi_port_show_attr_##_name);
 701
 702static ssize_t target_stat_scsi_port_show_attr_inst(
 703	struct se_port_stat_grps *pgrps, char *page)
 704{
 705	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 706	struct se_port *sep;
 707	struct se_device *dev = lun->lun_se_dev;
 708	struct se_hba *hba;
 709	ssize_t ret;
 710
 711	spin_lock(&lun->lun_sep_lock);
 712	sep = lun->lun_sep;
 713	if (!sep) {
 714		spin_unlock(&lun->lun_sep_lock);
 715		return -ENODEV;
 716	}
 717	hba = dev->se_hba;
 718	ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
 719	spin_unlock(&lun->lun_sep_lock);
 
 
 720	return ret;
 721}
 722DEV_STAT_SCSI_PORT_ATTR_RO(inst);
 723
 724static ssize_t target_stat_scsi_port_show_attr_dev(
 725	struct se_port_stat_grps *pgrps, char *page)
 726{
 727	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 728	struct se_port *sep;
 729	struct se_device *dev = lun->lun_se_dev;
 730	ssize_t ret;
 731
 732	spin_lock(&lun->lun_sep_lock);
 733	sep = lun->lun_sep;
 734	if (!sep) {
 735		spin_unlock(&lun->lun_sep_lock);
 736		return -ENODEV;
 737	}
 738	ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 739	spin_unlock(&lun->lun_sep_lock);
 740	return ret;
 741}
 742DEV_STAT_SCSI_PORT_ATTR_RO(dev);
 743
 744static ssize_t target_stat_scsi_port_show_attr_indx(
 745	struct se_port_stat_grps *pgrps, char *page)
 746{
 747	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 748	struct se_port *sep;
 749	ssize_t ret;
 750
 751	spin_lock(&lun->lun_sep_lock);
 752	sep = lun->lun_sep;
 753	if (!sep) {
 754		spin_unlock(&lun->lun_sep_lock);
 755		return -ENODEV;
 756	}
 757	ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
 758	spin_unlock(&lun->lun_sep_lock);
 759	return ret;
 760}
 761DEV_STAT_SCSI_PORT_ATTR_RO(indx);
 762
 763static ssize_t target_stat_scsi_port_show_attr_role(
 764	struct se_port_stat_grps *pgrps, char *page)
 765{
 766	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 767	struct se_device *dev = lun->lun_se_dev;
 768	struct se_port *sep;
 769	ssize_t ret;
 770
 771	if (!dev)
 772		return -ENODEV;
 773
 774	spin_lock(&lun->lun_sep_lock);
 775	sep = lun->lun_sep;
 776	if (!sep) {
 777		spin_unlock(&lun->lun_sep_lock);
 778		return -ENODEV;
 779	}
 780	ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
 781	spin_unlock(&lun->lun_sep_lock);
 782	return ret;
 783}
 784DEV_STAT_SCSI_PORT_ATTR_RO(role);
 785
 786static ssize_t target_stat_scsi_port_show_attr_busy_count(
 787	struct se_port_stat_grps *pgrps, char *page)
 788{
 789	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 790	struct se_port *sep;
 791	ssize_t ret;
 792
 793	spin_lock(&lun->lun_sep_lock);
 794	sep = lun->lun_sep;
 795	if (!sep) {
 796		spin_unlock(&lun->lun_sep_lock);
 797		return -ENODEV;
 798	}
 799	/* FIXME: scsiPortBusyStatuses  */
 800	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
 801	spin_unlock(&lun->lun_sep_lock);
 802	return ret;
 803}
 804DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
 805
 806CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group);
 
 
 
 
 807
 808static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
 809	&target_stat_scsi_port_inst.attr,
 810	&target_stat_scsi_port_dev.attr,
 811	&target_stat_scsi_port_indx.attr,
 812	&target_stat_scsi_port_role.attr,
 813	&target_stat_scsi_port_busy_count.attr,
 814	NULL,
 815};
 816
 817static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
 818	.show_attribute		= target_stat_scsi_port_attr_show,
 819	.store_attribute	= target_stat_scsi_port_attr_store,
 820};
 821
 822static struct config_item_type target_stat_scsi_port_cit = {
 823	.ct_item_ops		= &target_stat_scsi_port_attrib_ops,
 824	.ct_attrs		= target_stat_scsi_port_attrs,
 825	.ct_owner		= THIS_MODULE,
 826};
 827
 828/*
 829 * SCSI Target Port Table
 830 */
 831CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps);
 832#define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode)			\
 833static struct target_stat_scsi_tgt_port_attribute			\
 834			target_stat_scsi_tgt_port_##_name =		\
 835	__CONFIGFS_EATTR(_name, _mode,					\
 836	target_stat_scsi_tgt_port_show_attr_##_name,			\
 837	target_stat_scsi_tgt_port_store_attr_##_name);
 838
 839#define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name)				\
 840static struct target_stat_scsi_tgt_port_attribute			\
 841			target_stat_scsi_tgt_port_##_name =		\
 842	__CONFIGFS_EATTR_RO(_name,					\
 843	target_stat_scsi_tgt_port_show_attr_##_name);
 844
 845static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
 846	struct se_port_stat_grps *pgrps, char *page)
 847{
 848	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 849	struct se_device *dev = lun->lun_se_dev;
 850	struct se_port *sep;
 851	struct se_hba *hba;
 852	ssize_t ret;
 853
 854	spin_lock(&lun->lun_sep_lock);
 855	sep = lun->lun_sep;
 856	if (!sep) {
 857		spin_unlock(&lun->lun_sep_lock);
 858		return -ENODEV;
 859	}
 860	hba = dev->se_hba;
 861	ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
 862	spin_unlock(&lun->lun_sep_lock);
 
 
 
 863	return ret;
 864}
 865DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
 866
 867static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
 868	struct se_port_stat_grps *pgrps, char *page)
 869{
 870	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 871	struct se_device *dev = lun->lun_se_dev;
 872	struct se_port *sep;
 873	ssize_t ret;
 874
 875	spin_lock(&lun->lun_sep_lock);
 876	sep = lun->lun_sep;
 877	if (!sep) {
 878		spin_unlock(&lun->lun_sep_lock);
 879		return -ENODEV;
 880	}
 881	ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 882	spin_unlock(&lun->lun_sep_lock);
 883	return ret;
 884}
 885DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
 886
 887static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
 888	struct se_port_stat_grps *pgrps, char *page)
 889{
 890	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 891	struct se_port *sep;
 892	ssize_t ret;
 893
 894	spin_lock(&lun->lun_sep_lock);
 895	sep = lun->lun_sep;
 896	if (!sep) {
 897		spin_unlock(&lun->lun_sep_lock);
 898		return -ENODEV;
 899	}
 900	ret = snprintf(page, PAGE_SIZE, "%u\n", sep->sep_index);
 901	spin_unlock(&lun->lun_sep_lock);
 902	return ret;
 903}
 904DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
 905
 906static ssize_t target_stat_scsi_tgt_port_show_attr_name(
 907	struct se_port_stat_grps *pgrps, char *page)
 908{
 909	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 910	struct se_port *sep;
 911	struct se_portal_group *tpg;
 912	ssize_t ret;
 913
 914	spin_lock(&lun->lun_sep_lock);
 915	sep = lun->lun_sep;
 916	if (!sep) {
 917		spin_unlock(&lun->lun_sep_lock);
 918		return -ENODEV;
 919	}
 920	tpg = sep->sep_tpg;
 921
 922	ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n",
 923		tpg->se_tpg_tfo->get_fabric_name(), sep->sep_index);
 924	spin_unlock(&lun->lun_sep_lock);
 925	return ret;
 926}
 927DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
 928
 929static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
 930	struct se_port_stat_grps *pgrps, char *page)
 931{
 932	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 933	struct se_port *sep;
 934	struct se_portal_group *tpg;
 935	ssize_t ret;
 936
 937	spin_lock(&lun->lun_sep_lock);
 938	sep = lun->lun_sep;
 939	if (!sep) {
 940		spin_unlock(&lun->lun_sep_lock);
 941		return -ENODEV;
 942	}
 943	tpg = sep->sep_tpg;
 944
 945	ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
 946		tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
 947		tpg->se_tpg_tfo->tpg_get_tag(tpg));
 948	spin_unlock(&lun->lun_sep_lock);
 
 
 
 949	return ret;
 950}
 951DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
 952
 953static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
 954	struct se_port_stat_grps *pgrps, char *page)
 955{
 956	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 957	struct se_port *sep;
 958	struct se_portal_group *tpg;
 959	ssize_t ret;
 960
 961	spin_lock(&lun->lun_sep_lock);
 962	sep = lun->lun_sep;
 963	if (!sep) {
 964		spin_unlock(&lun->lun_sep_lock);
 965		return -ENODEV;
 966	}
 967	tpg = sep->sep_tpg;
 968
 969	ret = snprintf(page, PAGE_SIZE, "%llu\n", sep->sep_stats.cmd_pdus);
 970	spin_unlock(&lun->lun_sep_lock);
 971	return ret;
 972}
 973DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
 974
 975static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
 976	struct se_port_stat_grps *pgrps, char *page)
 977{
 978	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
 979	struct se_port *sep;
 980	struct se_portal_group *tpg;
 981	ssize_t ret;
 982
 983	spin_lock(&lun->lun_sep_lock);
 984	sep = lun->lun_sep;
 985	if (!sep) {
 986		spin_unlock(&lun->lun_sep_lock);
 987		return -ENODEV;
 988	}
 989	tpg = sep->sep_tpg;
 990
 991	ret = snprintf(page, PAGE_SIZE, "%u\n",
 992			(u32)(sep->sep_stats.rx_data_octets >> 20));
 993	spin_unlock(&lun->lun_sep_lock);
 
 
 
 994	return ret;
 995}
 996DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
 997
 998static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
 999	struct se_port_stat_grps *pgrps, char *page)
1000{
1001	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1002	struct se_port *sep;
1003	struct se_portal_group *tpg;
1004	ssize_t ret;
1005
1006	spin_lock(&lun->lun_sep_lock);
1007	sep = lun->lun_sep;
1008	if (!sep) {
1009		spin_unlock(&lun->lun_sep_lock);
1010		return -ENODEV;
1011	}
1012	tpg = sep->sep_tpg;
1013
1014	ret = snprintf(page, PAGE_SIZE, "%u\n",
1015			(u32)(sep->sep_stats.tx_data_octets >> 20));
1016	spin_unlock(&lun->lun_sep_lock);
1017	return ret;
1018}
1019DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
1020
1021static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
1022	struct se_port_stat_grps *pgrps, char *page)
1023{
1024	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1025	struct se_port *sep;
1026	struct se_portal_group *tpg;
1027	ssize_t ret;
1028
1029	spin_lock(&lun->lun_sep_lock);
1030	sep = lun->lun_sep;
1031	if (!sep) {
1032		spin_unlock(&lun->lun_sep_lock);
1033		return -ENODEV;
1034	}
1035	tpg = sep->sep_tpg;
1036
1037	/* FIXME: scsiTgtPortHsInCommands */
1038	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1039	spin_unlock(&lun->lun_sep_lock);
1040	return ret;
1041}
1042DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
1043
1044CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps,
1045		scsi_tgt_port_group);
 
 
 
 
 
 
 
1046
1047static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
1048	&target_stat_scsi_tgt_port_inst.attr,
1049	&target_stat_scsi_tgt_port_dev.attr,
1050	&target_stat_scsi_tgt_port_indx.attr,
1051	&target_stat_scsi_tgt_port_name.attr,
1052	&target_stat_scsi_tgt_port_port_index.attr,
1053	&target_stat_scsi_tgt_port_in_cmds.attr,
1054	&target_stat_scsi_tgt_port_write_mbytes.attr,
1055	&target_stat_scsi_tgt_port_read_mbytes.attr,
1056	&target_stat_scsi_tgt_port_hs_in_cmds.attr,
1057	NULL,
1058};
1059
1060static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
1061	.show_attribute		= target_stat_scsi_tgt_port_attr_show,
1062	.store_attribute	= target_stat_scsi_tgt_port_attr_store,
1063};
1064
1065static struct config_item_type target_stat_scsi_tgt_port_cit = {
1066	.ct_item_ops		= &target_stat_scsi_tgt_port_attrib_ops,
1067	.ct_attrs		= target_stat_scsi_tgt_port_attrs,
1068	.ct_owner		= THIS_MODULE,
1069};
1070
1071/*
1072 * SCSI Transport Table
1073o */
1074
1075CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps);
1076#define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode)			\
1077static struct target_stat_scsi_transport_attribute			\
1078			target_stat_scsi_transport_##_name =		\
1079	__CONFIGFS_EATTR(_name, _mode,					\
1080	target_stat_scsi_transport_show_attr_##_name,			\
1081	target_stat_scsi_transport_store_attr_##_name);
1082
1083#define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name)				\
1084static struct target_stat_scsi_transport_attribute			\
1085			target_stat_scsi_transport_##_name =		\
1086	__CONFIGFS_EATTR_RO(_name,					\
1087	target_stat_scsi_transport_show_attr_##_name);
1088
1089static ssize_t target_stat_scsi_transport_show_attr_inst(
1090	struct se_port_stat_grps *pgrps, char *page)
1091{
1092	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1093	struct se_device *dev = lun->lun_se_dev;
1094	struct se_port *sep;
1095	struct se_hba *hba;
1096	ssize_t ret;
1097
1098	spin_lock(&lun->lun_sep_lock);
1099	sep = lun->lun_sep;
1100	if (!sep) {
1101		spin_unlock(&lun->lun_sep_lock);
1102		return -ENODEV;
1103	}
1104
1105	hba = dev->se_hba;
1106	ret = snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
1107	spin_unlock(&lun->lun_sep_lock);
 
 
1108	return ret;
1109}
1110DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
1111
1112static ssize_t target_stat_scsi_transport_show_attr_device(
1113	struct se_port_stat_grps *pgrps, char *page)
1114{
1115	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1116	struct se_port *sep;
1117	struct se_portal_group *tpg;
1118	ssize_t ret;
1119
1120	spin_lock(&lun->lun_sep_lock);
1121	sep = lun->lun_sep;
1122	if (!sep) {
1123		spin_unlock(&lun->lun_sep_lock);
1124		return -ENODEV;
 
1125	}
1126	tpg = sep->sep_tpg;
1127	/* scsiTransportType */
1128	ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
1129			tpg->se_tpg_tfo->get_fabric_name());
1130	spin_unlock(&lun->lun_sep_lock);
1131	return ret;
1132}
1133DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
1134
1135static ssize_t target_stat_scsi_transport_show_attr_indx(
1136	struct se_port_stat_grps *pgrps, char *page)
1137{
1138	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1139	struct se_port *sep;
1140	struct se_portal_group *tpg;
1141	ssize_t ret;
1142
1143	spin_lock(&lun->lun_sep_lock);
1144	sep = lun->lun_sep;
1145	if (!sep) {
1146		spin_unlock(&lun->lun_sep_lock);
1147		return -ENODEV;
1148	}
1149	tpg = sep->sep_tpg;
1150	ret = snprintf(page, PAGE_SIZE, "%u\n",
1151			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1152	spin_unlock(&lun->lun_sep_lock);
1153	return ret;
1154}
1155DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
1156
1157static ssize_t target_stat_scsi_transport_show_attr_dev_name(
1158	struct se_port_stat_grps *pgrps, char *page)
1159{
1160	struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
1161	struct se_device *dev = lun->lun_se_dev;
1162	struct se_port *sep;
1163	struct se_portal_group *tpg;
1164	struct t10_wwn *wwn;
1165	ssize_t ret;
1166
1167	spin_lock(&lun->lun_sep_lock);
1168	sep = lun->lun_sep;
1169	if (!sep) {
1170		spin_unlock(&lun->lun_sep_lock);
1171		return -ENODEV;
 
 
 
 
1172	}
1173	tpg = sep->sep_tpg;
1174	wwn = &dev->se_sub_dev->t10_wwn;
1175	/* scsiTransportDevName */
1176	ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
1177			tpg->se_tpg_tfo->tpg_get_wwn(tpg),
1178			(strlen(wwn->unit_serial)) ? wwn->unit_serial :
1179			wwn->vendor);
1180	spin_unlock(&lun->lun_sep_lock);
1181	return ret;
1182}
1183DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
1184
1185CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps,
1186		scsi_transport_group);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1187
1188static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
1189	&target_stat_scsi_transport_inst.attr,
1190	&target_stat_scsi_transport_device.attr,
1191	&target_stat_scsi_transport_indx.attr,
1192	&target_stat_scsi_transport_dev_name.attr,
 
1193	NULL,
1194};
1195
1196static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
1197	.show_attribute		= target_stat_scsi_transport_attr_show,
1198	.store_attribute	= target_stat_scsi_transport_attr_store,
1199};
1200
1201static struct config_item_type target_stat_scsi_transport_cit = {
1202	.ct_item_ops		= &target_stat_scsi_transport_attrib_ops,
1203	.ct_attrs		= target_stat_scsi_transport_attrs,
1204	.ct_owner		= THIS_MODULE,
1205};
1206
1207/*
1208 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
1209 * the target port statistics groups + configfs CITs located in target_core_stat.c
1210 */
1211void target_stat_setup_port_default_groups(struct se_lun *lun)
1212{
1213	struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group;
1214
1215	config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
1216			"scsi_port", &target_stat_scsi_port_cit);
 
 
 
1217	config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
1218			"scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
 
 
 
1219	config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
1220			"scsi_transport", &target_stat_scsi_transport_cit);
1221
1222	port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group;
1223	port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group;
1224	port_stat_grp->default_groups[2] = &lun->port_stat_grps.scsi_transport_group;
1225	port_stat_grp->default_groups[3] = NULL;
1226}
1227
1228/*
1229 * SCSI Authorized Initiator Table
1230 */
1231
1232CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps);
1233#define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode)			\
1234static struct target_stat_scsi_auth_intr_attribute			\
1235			target_stat_scsi_auth_intr_##_name =		\
1236	__CONFIGFS_EATTR(_name, _mode,					\
1237	target_stat_scsi_auth_intr_show_attr_##_name,			\
1238	target_stat_scsi_auth_intr_store_attr_##_name);
1239
1240#define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name)				\
1241static struct target_stat_scsi_auth_intr_attribute			\
1242			target_stat_scsi_auth_intr_##_name =		\
1243	__CONFIGFS_EATTR_RO(_name,					\
1244	target_stat_scsi_auth_intr_show_attr_##_name);
1245
1246static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1247	struct se_ml_stat_grps *lgrps, char *page)
1248{
1249	struct se_lun_acl *lacl = container_of(lgrps,
1250			struct se_lun_acl, ml_stat_grps);
1251	struct se_node_acl *nacl = lacl->se_lun_nacl;
1252	struct se_dev_entry *deve;
1253	struct se_portal_group *tpg;
1254	ssize_t ret;
1255
1256	spin_lock_irq(&nacl->device_list_lock);
1257	deve = &nacl->device_list[lacl->mapped_lun];
1258	if (!deve->se_lun || !deve->se_lun_acl) {
1259		spin_unlock_irq(&nacl->device_list_lock);
1260		return -ENODEV;
1261	}
1262	tpg = nacl->se_tpg;
1263	/* scsiInstIndex */
1264	ret = snprintf(page, PAGE_SIZE, "%u\n",
1265			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1266	spin_unlock_irq(&nacl->device_list_lock);
1267	return ret;
1268}
1269DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1270
1271static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1272	struct se_ml_stat_grps *lgrps, char *page)
1273{
1274	struct se_lun_acl *lacl = container_of(lgrps,
1275			struct se_lun_acl, ml_stat_grps);
1276	struct se_node_acl *nacl = lacl->se_lun_nacl;
1277	struct se_dev_entry *deve;
1278	struct se_lun *lun;
1279	struct se_portal_group *tpg;
1280	ssize_t ret;
1281
1282	spin_lock_irq(&nacl->device_list_lock);
1283	deve = &nacl->device_list[lacl->mapped_lun];
1284	if (!deve->se_lun || !deve->se_lun_acl) {
1285		spin_unlock_irq(&nacl->device_list_lock);
1286		return -ENODEV;
1287	}
1288	tpg = nacl->se_tpg;
1289	lun = deve->se_lun;
1290	/* scsiDeviceIndex */
1291	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1292	spin_unlock_irq(&nacl->device_list_lock);
1293	return ret;
1294}
1295DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1296
1297static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1298	struct se_ml_stat_grps *lgrps, char *page)
1299{
1300	struct se_lun_acl *lacl = container_of(lgrps,
1301			struct se_lun_acl, ml_stat_grps);
1302	struct se_node_acl *nacl = lacl->se_lun_nacl;
1303	struct se_dev_entry *deve;
1304	struct se_portal_group *tpg;
1305	ssize_t ret;
1306
1307	spin_lock_irq(&nacl->device_list_lock);
1308	deve = &nacl->device_list[lacl->mapped_lun];
1309	if (!deve->se_lun || !deve->se_lun_acl) {
1310		spin_unlock_irq(&nacl->device_list_lock);
1311		return -ENODEV;
1312	}
1313	tpg = nacl->se_tpg;
1314	/* scsiAuthIntrTgtPortIndex */
1315	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1316	spin_unlock_irq(&nacl->device_list_lock);
1317	return ret;
1318}
1319DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1320
1321static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1322	struct se_ml_stat_grps *lgrps, char *page)
1323{
1324	struct se_lun_acl *lacl = container_of(lgrps,
1325			struct se_lun_acl, ml_stat_grps);
1326	struct se_node_acl *nacl = lacl->se_lun_nacl;
1327	struct se_dev_entry *deve;
1328	ssize_t ret;
1329
1330	spin_lock_irq(&nacl->device_list_lock);
1331	deve = &nacl->device_list[lacl->mapped_lun];
1332	if (!deve->se_lun || !deve->se_lun_acl) {
1333		spin_unlock_irq(&nacl->device_list_lock);
1334		return -ENODEV;
1335	}
1336	/* scsiAuthIntrIndex */
1337	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1338	spin_unlock_irq(&nacl->device_list_lock);
1339	return ret;
1340}
1341DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1342
1343static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1344	struct se_ml_stat_grps *lgrps, char *page)
1345{
1346	struct se_lun_acl *lacl = container_of(lgrps,
1347			struct se_lun_acl, ml_stat_grps);
1348	struct se_node_acl *nacl = lacl->se_lun_nacl;
1349	struct se_dev_entry *deve;
1350	ssize_t ret;
1351
1352	spin_lock_irq(&nacl->device_list_lock);
1353	deve = &nacl->device_list[lacl->mapped_lun];
1354	if (!deve->se_lun || !deve->se_lun_acl) {
1355		spin_unlock_irq(&nacl->device_list_lock);
1356		return -ENODEV;
1357	}
1358	/* scsiAuthIntrDevOrPort */
1359	ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
1360	spin_unlock_irq(&nacl->device_list_lock);
1361	return ret;
1362}
1363DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1364
1365static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1366	struct se_ml_stat_grps *lgrps, char *page)
1367{
1368	struct se_lun_acl *lacl = container_of(lgrps,
1369			struct se_lun_acl, ml_stat_grps);
1370	struct se_node_acl *nacl = lacl->se_lun_nacl;
1371	struct se_dev_entry *deve;
1372	ssize_t ret;
1373
1374	spin_lock_irq(&nacl->device_list_lock);
1375	deve = &nacl->device_list[lacl->mapped_lun];
1376	if (!deve->se_lun || !deve->se_lun_acl) {
1377		spin_unlock_irq(&nacl->device_list_lock);
1378		return -ENODEV;
1379	}
1380	/* scsiAuthIntrName */
1381	ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
1382	spin_unlock_irq(&nacl->device_list_lock);
1383	return ret;
1384}
1385DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1386
1387static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1388	struct se_ml_stat_grps *lgrps, char *page)
1389{
1390	struct se_lun_acl *lacl = container_of(lgrps,
1391			struct se_lun_acl, ml_stat_grps);
1392	struct se_node_acl *nacl = lacl->se_lun_nacl;
1393	struct se_dev_entry *deve;
1394	ssize_t ret;
1395
1396	spin_lock_irq(&nacl->device_list_lock);
1397	deve = &nacl->device_list[lacl->mapped_lun];
1398	if (!deve->se_lun || !deve->se_lun_acl) {
1399		spin_unlock_irq(&nacl->device_list_lock);
1400		return -ENODEV;
1401	}
1402	/* FIXME: scsiAuthIntrLunMapIndex */
1403	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1404	spin_unlock_irq(&nacl->device_list_lock);
1405	return ret;
1406}
1407DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1408
1409static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1410	struct se_ml_stat_grps *lgrps, char *page)
1411{
1412	struct se_lun_acl *lacl = container_of(lgrps,
1413			struct se_lun_acl, ml_stat_grps);
1414	struct se_node_acl *nacl = lacl->se_lun_nacl;
1415	struct se_dev_entry *deve;
1416	ssize_t ret;
1417
1418	spin_lock_irq(&nacl->device_list_lock);
1419	deve = &nacl->device_list[lacl->mapped_lun];
1420	if (!deve->se_lun || !deve->se_lun_acl) {
1421		spin_unlock_irq(&nacl->device_list_lock);
1422		return -ENODEV;
1423	}
1424	/* scsiAuthIntrAttachedTimes */
1425	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1426	spin_unlock_irq(&nacl->device_list_lock);
1427	return ret;
1428}
1429DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1430
1431static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1432	struct se_ml_stat_grps *lgrps, char *page)
1433{
1434	struct se_lun_acl *lacl = container_of(lgrps,
1435			struct se_lun_acl, ml_stat_grps);
1436	struct se_node_acl *nacl = lacl->se_lun_nacl;
1437	struct se_dev_entry *deve;
1438	ssize_t ret;
1439
1440	spin_lock_irq(&nacl->device_list_lock);
1441	deve = &nacl->device_list[lacl->mapped_lun];
1442	if (!deve->se_lun || !deve->se_lun_acl) {
1443		spin_unlock_irq(&nacl->device_list_lock);
1444		return -ENODEV;
1445	}
1446	/* scsiAuthIntrOutCommands */
1447	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->total_cmds);
1448	spin_unlock_irq(&nacl->device_list_lock);
 
1449	return ret;
1450}
1451DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1452
1453static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1454	struct se_ml_stat_grps *lgrps, char *page)
1455{
1456	struct se_lun_acl *lacl = container_of(lgrps,
1457			struct se_lun_acl, ml_stat_grps);
1458	struct se_node_acl *nacl = lacl->se_lun_nacl;
1459	struct se_dev_entry *deve;
1460	ssize_t ret;
1461
1462	spin_lock_irq(&nacl->device_list_lock);
1463	deve = &nacl->device_list[lacl->mapped_lun];
1464	if (!deve->se_lun || !deve->se_lun_acl) {
1465		spin_unlock_irq(&nacl->device_list_lock);
1466		return -ENODEV;
1467	}
1468	/* scsiAuthIntrReadMegaBytes */
1469	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->read_bytes >> 20));
1470	spin_unlock_irq(&nacl->device_list_lock);
 
1471	return ret;
1472}
1473DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1474
1475static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1476	struct se_ml_stat_grps *lgrps, char *page)
1477{
1478	struct se_lun_acl *lacl = container_of(lgrps,
1479			struct se_lun_acl, ml_stat_grps);
1480	struct se_node_acl *nacl = lacl->se_lun_nacl;
1481	struct se_dev_entry *deve;
1482	ssize_t ret;
1483
1484	spin_lock_irq(&nacl->device_list_lock);
1485	deve = &nacl->device_list[lacl->mapped_lun];
1486	if (!deve->se_lun || !deve->se_lun_acl) {
1487		spin_unlock_irq(&nacl->device_list_lock);
1488		return -ENODEV;
1489	}
1490	/* scsiAuthIntrWrittenMegaBytes */
1491	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(deve->write_bytes >> 20));
1492	spin_unlock_irq(&nacl->device_list_lock);
 
1493	return ret;
1494}
1495DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1496
1497static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1498	struct se_ml_stat_grps *lgrps, char *page)
1499{
1500	struct se_lun_acl *lacl = container_of(lgrps,
1501			struct se_lun_acl, ml_stat_grps);
1502	struct se_node_acl *nacl = lacl->se_lun_nacl;
1503	struct se_dev_entry *deve;
1504	ssize_t ret;
1505
1506	spin_lock_irq(&nacl->device_list_lock);
1507	deve = &nacl->device_list[lacl->mapped_lun];
1508	if (!deve->se_lun || !deve->se_lun_acl) {
1509		spin_unlock_irq(&nacl->device_list_lock);
1510		return -ENODEV;
1511	}
1512	/* FIXME: scsiAuthIntrHSOutCommands */
1513	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1514	spin_unlock_irq(&nacl->device_list_lock);
1515	return ret;
1516}
1517DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1518
1519static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1520	struct se_ml_stat_grps *lgrps, char *page)
1521{
1522	struct se_lun_acl *lacl = container_of(lgrps,
1523			struct se_lun_acl, ml_stat_grps);
1524	struct se_node_acl *nacl = lacl->se_lun_nacl;
1525	struct se_dev_entry *deve;
1526	ssize_t ret;
1527
1528	spin_lock_irq(&nacl->device_list_lock);
1529	deve = &nacl->device_list[lacl->mapped_lun];
1530	if (!deve->se_lun || !deve->se_lun_acl) {
1531		spin_unlock_irq(&nacl->device_list_lock);
1532		return -ENODEV;
1533	}
1534	/* scsiAuthIntrLastCreation */
1535	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1536				INITIAL_JIFFIES) * 100 / HZ));
1537	spin_unlock_irq(&nacl->device_list_lock);
1538	return ret;
1539}
1540DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1541
1542static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1543	struct se_ml_stat_grps *lgrps, char *page)
1544{
1545	struct se_lun_acl *lacl = container_of(lgrps,
1546			struct se_lun_acl, ml_stat_grps);
1547	struct se_node_acl *nacl = lacl->se_lun_nacl;
1548	struct se_dev_entry *deve;
1549	ssize_t ret;
1550
1551	spin_lock_irq(&nacl->device_list_lock);
1552	deve = &nacl->device_list[lacl->mapped_lun];
1553	if (!deve->se_lun || !deve->se_lun_acl) {
1554		spin_unlock_irq(&nacl->device_list_lock);
1555		return -ENODEV;
1556	}
1557	/* FIXME: scsiAuthIntrRowStatus */
1558	ret = snprintf(page, PAGE_SIZE, "Ready\n");
1559	spin_unlock_irq(&nacl->device_list_lock);
1560	return ret;
1561}
1562DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1563
1564CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps,
1565		scsi_auth_intr_group);
 
 
 
 
 
 
 
 
 
 
 
 
1566
1567static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1568	&target_stat_scsi_auth_intr_inst.attr,
1569	&target_stat_scsi_auth_intr_dev.attr,
1570	&target_stat_scsi_auth_intr_port.attr,
1571	&target_stat_scsi_auth_intr_indx.attr,
1572	&target_stat_scsi_auth_intr_dev_or_port.attr,
1573	&target_stat_scsi_auth_intr_intr_name.attr,
1574	&target_stat_scsi_auth_intr_map_indx.attr,
1575	&target_stat_scsi_auth_intr_att_count.attr,
1576	&target_stat_scsi_auth_intr_num_cmds.attr,
1577	&target_stat_scsi_auth_intr_read_mbytes.attr,
1578	&target_stat_scsi_auth_intr_write_mbytes.attr,
1579	&target_stat_scsi_auth_intr_hs_num_cmds.attr,
1580	&target_stat_scsi_auth_intr_creation_time.attr,
1581	&target_stat_scsi_auth_intr_row_status.attr,
1582	NULL,
1583};
1584
1585static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1586	.show_attribute		= target_stat_scsi_auth_intr_attr_show,
1587	.store_attribute	= target_stat_scsi_auth_intr_attr_store,
1588};
1589
1590static struct config_item_type target_stat_scsi_auth_intr_cit = {
1591	.ct_item_ops		= &target_stat_scsi_auth_intr_attrib_ops,
1592	.ct_attrs		= target_stat_scsi_auth_intr_attrs,
1593	.ct_owner		= THIS_MODULE,
1594};
1595
1596/*
1597 * SCSI Attached Initiator Port Table
1598 */
1599
1600CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps);
1601#define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode)			\
1602static struct target_stat_scsi_att_intr_port_attribute			\
1603		target_stat_scsi_att_intr_port_##_name =		\
1604	__CONFIGFS_EATTR(_name, _mode,					\
1605	target_stat_scsi_att_intr_port_show_attr_##_name,		\
1606	target_stat_scsi_att_intr_port_store_attr_##_name);
1607
1608#define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name)			\
1609static struct target_stat_scsi_att_intr_port_attribute			\
1610		target_stat_scsi_att_intr_port_##_name =		\
1611	__CONFIGFS_EATTR_RO(_name,					\
1612	target_stat_scsi_att_intr_port_show_attr_##_name);
1613
1614static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1615	struct se_ml_stat_grps *lgrps, char *page)
1616{
1617	struct se_lun_acl *lacl = container_of(lgrps,
1618			struct se_lun_acl, ml_stat_grps);
1619	struct se_node_acl *nacl = lacl->se_lun_nacl;
1620	struct se_dev_entry *deve;
1621	struct se_portal_group *tpg;
1622	ssize_t ret;
1623
1624	spin_lock_irq(&nacl->device_list_lock);
1625	deve = &nacl->device_list[lacl->mapped_lun];
1626	if (!deve->se_lun || !deve->se_lun_acl) {
1627		spin_unlock_irq(&nacl->device_list_lock);
1628		return -ENODEV;
1629	}
1630	tpg = nacl->se_tpg;
1631	/* scsiInstIndex */
1632	ret = snprintf(page, PAGE_SIZE, "%u\n",
1633			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1634	spin_unlock_irq(&nacl->device_list_lock);
1635	return ret;
1636}
1637DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1638
1639static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1640	struct se_ml_stat_grps *lgrps, char *page)
1641{
1642	struct se_lun_acl *lacl = container_of(lgrps,
1643			struct se_lun_acl, ml_stat_grps);
1644	struct se_node_acl *nacl = lacl->se_lun_nacl;
1645	struct se_dev_entry *deve;
1646	struct se_lun *lun;
1647	struct se_portal_group *tpg;
1648	ssize_t ret;
1649
1650	spin_lock_irq(&nacl->device_list_lock);
1651	deve = &nacl->device_list[lacl->mapped_lun];
1652	if (!deve->se_lun || !deve->se_lun_acl) {
1653		spin_unlock_irq(&nacl->device_list_lock);
1654		return -ENODEV;
1655	}
1656	tpg = nacl->se_tpg;
1657	lun = deve->se_lun;
1658	/* scsiDeviceIndex */
1659	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_se_dev->dev_index);
1660	spin_unlock_irq(&nacl->device_list_lock);
1661	return ret;
1662}
1663DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1664
1665static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1666	struct se_ml_stat_grps *lgrps, char *page)
1667{
1668	struct se_lun_acl *lacl = container_of(lgrps,
1669			struct se_lun_acl, ml_stat_grps);
1670	struct se_node_acl *nacl = lacl->se_lun_nacl;
1671	struct se_dev_entry *deve;
1672	struct se_portal_group *tpg;
1673	ssize_t ret;
1674
1675	spin_lock_irq(&nacl->device_list_lock);
1676	deve = &nacl->device_list[lacl->mapped_lun];
1677	if (!deve->se_lun || !deve->se_lun_acl) {
1678		spin_unlock_irq(&nacl->device_list_lock);
1679		return -ENODEV;
1680	}
1681	tpg = nacl->se_tpg;
1682	/* scsiPortIndex */
1683	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1684	spin_unlock_irq(&nacl->device_list_lock);
1685	return ret;
1686}
1687DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1688
1689static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1690	struct se_ml_stat_grps *lgrps, char *page)
1691{
1692	struct se_lun_acl *lacl = container_of(lgrps,
1693			struct se_lun_acl, ml_stat_grps);
1694	struct se_node_acl *nacl = lacl->se_lun_nacl;
1695	struct se_session *se_sess;
1696	struct se_portal_group *tpg;
1697	ssize_t ret;
1698
1699	spin_lock_irq(&nacl->nacl_sess_lock);
1700	se_sess = nacl->nacl_sess;
1701	if (!se_sess) {
1702		spin_unlock_irq(&nacl->nacl_sess_lock);
1703		return -ENODEV;
1704	}
1705
1706	tpg = nacl->se_tpg;
1707	/* scsiAttIntrPortIndex */
1708	ret = snprintf(page, PAGE_SIZE, "%u\n",
1709			tpg->se_tpg_tfo->sess_get_index(se_sess));
1710	spin_unlock_irq(&nacl->nacl_sess_lock);
1711	return ret;
1712}
1713DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1714
1715static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1716	struct se_ml_stat_grps *lgrps, char *page)
1717{
1718	struct se_lun_acl *lacl = container_of(lgrps,
1719			struct se_lun_acl, ml_stat_grps);
1720	struct se_node_acl *nacl = lacl->se_lun_nacl;
1721	struct se_dev_entry *deve;
1722	ssize_t ret;
1723
1724	spin_lock_irq(&nacl->device_list_lock);
1725	deve = &nacl->device_list[lacl->mapped_lun];
1726	if (!deve->se_lun || !deve->se_lun_acl) {
1727		spin_unlock_irq(&nacl->device_list_lock);
1728		return -ENODEV;
1729	}
1730	/* scsiAttIntrPortAuthIntrIdx */
1731	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1732	spin_unlock_irq(&nacl->device_list_lock);
1733	return ret;
1734}
1735DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1736
1737static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1738	struct se_ml_stat_grps *lgrps, char *page)
1739{
1740	struct se_lun_acl *lacl = container_of(lgrps,
1741			struct se_lun_acl, ml_stat_grps);
1742	struct se_node_acl *nacl = lacl->se_lun_nacl;
1743	struct se_session *se_sess;
1744	struct se_portal_group *tpg;
1745	ssize_t ret;
1746	unsigned char buf[64];
1747
1748	spin_lock_irq(&nacl->nacl_sess_lock);
1749	se_sess = nacl->nacl_sess;
1750	if (!se_sess) {
1751		spin_unlock_irq(&nacl->nacl_sess_lock);
1752		return -ENODEV;
1753	}
1754
1755	tpg = nacl->se_tpg;
1756	/* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1757	memset(buf, 0, 64);
1758	if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1759		tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess,
1760				(unsigned char *)&buf[0], 64);
1761
1762	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1763	spin_unlock_irq(&nacl->nacl_sess_lock);
1764	return ret;
1765}
1766DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1767
1768CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps,
1769		scsi_att_intr_port_group);
 
 
 
 
1770
1771static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1772	&target_stat_scsi_att_intr_port_inst.attr,
1773	&target_stat_scsi_att_intr_port_dev.attr,
1774	&target_stat_scsi_att_intr_port_port.attr,
1775	&target_stat_scsi_att_intr_port_indx.attr,
1776	&target_stat_scsi_att_intr_port_port_auth_indx.attr,
1777	&target_stat_scsi_att_intr_port_port_ident.attr,
1778	NULL,
1779};
1780
1781static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1782	.show_attribute		= target_stat_scsi_att_intr_port_attr_show,
1783	.store_attribute	= target_stat_scsi_att_intr_port_attr_store,
1784};
1785
1786static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1787	.ct_item_ops		= &target_stat_scsi_att_intr_port_attrib_ops,
1788	.ct_attrs		= target_stat_scsi_ath_intr_port_attrs,
1789	.ct_owner		= THIS_MODULE,
1790};
1791
1792/*
1793 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1794 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1795 */
1796void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1797{
1798	struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group;
1799
1800	config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1801			"scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
 
 
 
1802	config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1803			"scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1804
1805	ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group;
1806	ml_stat_grp->default_groups[1] = &lacl->ml_stat_grps.scsi_att_intr_port_group;
1807	ml_stat_grp->default_groups[2] = NULL;
1808}
v5.4
   1// SPDX-License-Identifier: GPL-2.0-or-later
   2/*******************************************************************************
   3 * Filename:  target_core_stat.c
   4 *
 
 
 
   5 * Modern ConfigFS group context specific statistics based on original
   6 * target_core_mib.c code
   7 *
   8 * (c) Copyright 2006-2013 Datera, Inc.
   9 *
  10 * Nicholas A. Bellinger <nab@linux-iscsi.org>
  11 *
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  12 ******************************************************************************/
  13
  14#include <linux/kernel.h>
  15#include <linux/module.h>
  16#include <linux/delay.h>
  17#include <linux/timer.h>
  18#include <linux/string.h>
 
 
  19#include <linux/utsname.h>
  20#include <linux/proc_fs.h>
  21#include <linux/seq_file.h>
 
  22#include <linux/configfs.h>
 
 
 
  23
  24#include <target/target_core_base.h>
  25#include <target/target_core_backend.h>
  26#include <target/target_core_fabric.h>
 
 
  27
  28#include "target_core_internal.h"
  29
  30#ifndef INITIAL_JIFFIES
  31#define INITIAL_JIFFIES ((unsigned long)(unsigned int) (-300*HZ))
  32#endif
  33
  34#define NONE		"None"
  35#define ISPRINT(a)   ((a >= ' ') && (a <= '~'))
  36
  37#define SCSI_LU_INDEX			1
  38#define LU_COUNT			1
  39
  40/*
  41 * SCSI Device Table
  42 */
  43
  44static struct se_device *to_stat_dev(struct config_item *item)
  45{
  46	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
  47			struct se_dev_stat_grps, scsi_dev_group);
  48	return container_of(sgrps, struct se_device, dev_stat_grps);
  49}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  50
  51static ssize_t target_stat_inst_show(struct config_item *item, char *page)
  52{
  53	struct se_hba *hba = to_stat_dev(item)->se_hba;
  54
  55	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
  56}
 
  57
  58static ssize_t target_stat_indx_show(struct config_item *item, char *page)
 
  59{
  60	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
 
 
 
 
 
 
 
  61}
 
  62
  63static ssize_t target_stat_role_show(struct config_item *item, char *page)
 
  64{
 
 
 
 
 
 
 
  65	return snprintf(page, PAGE_SIZE, "Target\n");
  66}
 
  67
  68static ssize_t target_stat_ports_show(struct config_item *item, char *page)
 
  69{
  70	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
 
 
 
 
 
 
 
  71}
 
  72
  73CONFIGFS_ATTR_RO(target_stat_, inst);
  74CONFIGFS_ATTR_RO(target_stat_, indx);
  75CONFIGFS_ATTR_RO(target_stat_, role);
  76CONFIGFS_ATTR_RO(target_stat_, ports);
  77
  78static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
  79	&target_stat_attr_inst,
  80	&target_stat_attr_indx,
  81	&target_stat_attr_role,
  82	&target_stat_attr_ports,
  83	NULL,
  84};
  85
  86static const struct config_item_type target_stat_scsi_dev_cit = {
 
 
 
 
 
 
  87	.ct_attrs		= target_stat_scsi_dev_attrs,
  88	.ct_owner		= THIS_MODULE,
  89};
  90
  91/*
  92 * SCSI Target Device Table
  93 */
  94static struct se_device *to_stat_tgt_dev(struct config_item *item)
  95{
  96	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
  97			struct se_dev_stat_grps, scsi_tgt_dev_group);
  98	return container_of(sgrps, struct se_device, dev_stat_grps);
  99}
 100
 101static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
 102{
 103	struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 104
 105	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
 106}
 
 107
 108static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
 
 109{
 110	return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
 
 
 
 
 
 
 
 111}
 
 112
 113static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
 114		char *page)
 115{
 
 
 
 
 
 
 
 116	return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
 117}
 
 118
 119static ssize_t target_stat_tgt_status_show(struct config_item *item,
 120		char *page)
 121{
 122	if (to_stat_tgt_dev(item)->export_count)
 123		return snprintf(page, PAGE_SIZE, "activated");
 124	else
 125		return snprintf(page, PAGE_SIZE, "deactivated");
 126}
 
 
 127
 128static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
 129		char *page)
 130{
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 131	int non_accessible_lus;
 132
 133	if (to_stat_tgt_dev(item)->export_count)
 
 
 
 
 134		non_accessible_lus = 0;
 135	else
 
 
 
 
 
 136		non_accessible_lus = 1;
 
 
 137
 138	return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
 139}
 
 140
 141static ssize_t target_stat_tgt_resets_show(struct config_item *item,
 142		char *page)
 143{
 144	return snprintf(page, PAGE_SIZE, "%lu\n",
 145			atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
 146}
 
 
 
 147
 148static ssize_t target_stat_tgt_aborts_complete_show(struct config_item *item,
 149		char *page)
 150{
 151	return snprintf(page, PAGE_SIZE, "%lu\n",
 152			atomic_long_read(&to_stat_tgt_dev(item)->aborts_complete));
 153}
 
 154
 155static ssize_t target_stat_tgt_aborts_no_task_show(struct config_item *item,
 156		char *page)
 157{
 158	return snprintf(page, PAGE_SIZE, "%lu\n",
 159			atomic_long_read(&to_stat_tgt_dev(item)->aborts_no_task));
 160}
 161
 162CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
 163CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
 164CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
 165CONFIGFS_ATTR_RO(target_stat_tgt_, status);
 166CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
 167CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
 168CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_complete);
 169CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_no_task);
 170
 171static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
 172	&target_stat_tgt_attr_inst,
 173	&target_stat_tgt_attr_indx,
 174	&target_stat_tgt_attr_num_lus,
 175	&target_stat_tgt_attr_status,
 176	&target_stat_tgt_attr_non_access_lus,
 177	&target_stat_tgt_attr_resets,
 178	&target_stat_tgt_attr_aborts_complete,
 179	&target_stat_tgt_attr_aborts_no_task,
 180	NULL,
 181};
 182
 183static const struct config_item_type target_stat_scsi_tgt_dev_cit = {
 
 
 
 
 
 
 184	.ct_attrs		= target_stat_scsi_tgt_dev_attrs,
 185	.ct_owner		= THIS_MODULE,
 186};
 187
 188/*
 189 * SCSI Logical Unit Table
 190 */
 191
 192static struct se_device *to_stat_lu_dev(struct config_item *item)
 193{
 194	struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
 195			struct se_dev_stat_grps, scsi_lu_group);
 196	return container_of(sgrps, struct se_device, dev_stat_grps);
 197}
 
 
 
 
 
 
 
 
 
 
 
 
 
 198
 199static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
 200{
 201	struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
 202
 203	return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
 204}
 
 205
 206static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
 
 207{
 208	return snprintf(page, PAGE_SIZE, "%u\n",
 209			to_stat_lu_dev(item)->dev_index);
 
 
 
 
 
 
 210}
 
 211
 212static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
 
 213{
 
 
 
 
 
 
 
 214	return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
 215}
 
 216
 217static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
 
 218{
 
 
 
 
 
 
 219	/* FIXME: scsiLuDefaultLun */
 220	return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
 221}
 
 222
 223static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
 
 224{
 225	struct se_device *dev = to_stat_lu_dev(item);
 
 
 226
 
 
 227	/* scsiLuWwnName */
 228	return snprintf(page, PAGE_SIZE, "%s\n",
 229			(strlen(dev->t10_wwn.unit_serial)) ?
 230			dev->t10_wwn.unit_serial : "None");
 231}
 
 232
 233static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
 
 234{
 235	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 
 
 236
 237	return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_VENDOR_LEN)
 238			"s\n", dev->t10_wwn.vendor);
 239}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 240
 241static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
 242{
 243	struct se_device *dev = to_stat_lu_dev(item);
 244
 245	return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_MODEL_LEN)
 246			"s\n", dev->t10_wwn.model);
 247}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 248
 249static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
 250{
 251	struct se_device *dev = to_stat_lu_dev(item);
 252
 253	return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_REVISION_LEN)
 254			"s\n", dev->t10_wwn.revision);
 255}
 
 
 
 
 
 
 
 
 
 
 
 
 256
 257static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
 258{
 259	struct se_device *dev = to_stat_lu_dev(item);
 260
 261	/* scsiLuPeripheralType */
 262	return snprintf(page, PAGE_SIZE, "%u\n",
 263			dev->transport->get_device_type(dev));
 264}
 
 265
 266static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
 
 267{
 268	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 269
 270	/* scsiLuStatus */
 271	return snprintf(page, PAGE_SIZE, "%s\n",
 272		(dev->export_count) ? "available" : "notavailable");
 
 273}
 
 274
 275static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
 276		char *page)
 277{
 
 
 
 
 
 
 
 278	/* scsiLuState */
 279	return snprintf(page, PAGE_SIZE, "exposed\n");
 280}
 
 281
 282static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
 283		char *page)
 284{
 285	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 286
 287	/* scsiLuNumCommands */
 288	return snprintf(page, PAGE_SIZE, "%lu\n",
 289			atomic_long_read(&dev->num_cmds));
 290}
 
 291
 292static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
 293		char *page)
 294{
 295	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 296
 297	/* scsiLuReadMegaBytes */
 298	return snprintf(page, PAGE_SIZE, "%lu\n",
 299			atomic_long_read(&dev->read_bytes) >> 20);
 300}
 
 301
 302static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
 303		char *page)
 304{
 305	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 306
 307	/* scsiLuWrittenMegaBytes */
 308	return snprintf(page, PAGE_SIZE, "%lu\n",
 309			atomic_long_read(&dev->write_bytes) >> 20);
 310}
 
 311
 312static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
 
 313{
 314	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 315
 316	/* scsiLuInResets */
 317	return snprintf(page, PAGE_SIZE, "%lu\n",
 318		atomic_long_read(&dev->num_resets));
 319}
 
 320
 321static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
 322		char *page)
 323{
 
 
 
 
 
 
 
 324	/* FIXME: scsiLuOutTaskSetFullStatus */
 325	return snprintf(page, PAGE_SIZE, "%u\n", 0);
 326}
 
 327
 328static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
 329		char *page)
 330{
 
 
 
 
 
 
 
 331	/* FIXME: scsiLuHSInCommands */
 332	return snprintf(page, PAGE_SIZE, "%u\n", 0);
 333}
 
 334
 335static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
 336		char *page)
 337{
 338	struct se_device *dev = to_stat_lu_dev(item);
 
 
 
 
 
 339
 340	/* scsiLuCreationTime */
 341	return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
 342				INITIAL_JIFFIES) * 100 / HZ));
 343}
 
 344
 345CONFIGFS_ATTR_RO(target_stat_lu_, inst);
 346CONFIGFS_ATTR_RO(target_stat_lu_, dev);
 347CONFIGFS_ATTR_RO(target_stat_lu_, indx);
 348CONFIGFS_ATTR_RO(target_stat_lu_, lun);
 349CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
 350CONFIGFS_ATTR_RO(target_stat_lu_, vend);
 351CONFIGFS_ATTR_RO(target_stat_lu_, prod);
 352CONFIGFS_ATTR_RO(target_stat_lu_, rev);
 353CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
 354CONFIGFS_ATTR_RO(target_stat_lu_, status);
 355CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
 356CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
 357CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
 358CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
 359CONFIGFS_ATTR_RO(target_stat_lu_, resets);
 360CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
 361CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
 362CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
 363
 364static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
 365	&target_stat_lu_attr_inst,
 366	&target_stat_lu_attr_dev,
 367	&target_stat_lu_attr_indx,
 368	&target_stat_lu_attr_lun,
 369	&target_stat_lu_attr_lu_name,
 370	&target_stat_lu_attr_vend,
 371	&target_stat_lu_attr_prod,
 372	&target_stat_lu_attr_rev,
 373	&target_stat_lu_attr_dev_type,
 374	&target_stat_lu_attr_status,
 375	&target_stat_lu_attr_state_bit,
 376	&target_stat_lu_attr_num_cmds,
 377	&target_stat_lu_attr_read_mbytes,
 378	&target_stat_lu_attr_write_mbytes,
 379	&target_stat_lu_attr_resets,
 380	&target_stat_lu_attr_full_stat,
 381	&target_stat_lu_attr_hs_num_cmds,
 382	&target_stat_lu_attr_creation_time,
 383	NULL,
 384};
 385
 386static const struct config_item_type target_stat_scsi_lu_cit = {
 
 
 
 
 
 
 387	.ct_attrs		= target_stat_scsi_lu_attrs,
 388	.ct_owner		= THIS_MODULE,
 389};
 390
 391/*
 392 * Called from target_core_configfs.c:target_core_make_subdev() to setup
 393 * the target statistics groups + configfs CITs located in target_core_stat.c
 394 */
 395void target_stat_setup_dev_default_groups(struct se_device *dev)
 396{
 397	config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group,
 
 
 398			"scsi_dev", &target_stat_scsi_dev_cit);
 399	configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group,
 400			&dev->dev_stat_grps.stat_group);
 401
 402	config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group,
 403			"scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit);
 404	configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group,
 405			&dev->dev_stat_grps.stat_group);
 406
 407	config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group,
 408			"scsi_lu", &target_stat_scsi_lu_cit);
 409	configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group,
 410			&dev->dev_stat_grps.stat_group);
 411}
 412
 413/*
 414 * SCSI Port Table
 415 */
 416
 417static struct se_lun *to_stat_port(struct config_item *item)
 418{
 419	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
 420			struct se_port_stat_grps, scsi_port_group);
 421	return container_of(pgrps, struct se_lun, port_stat_grps);
 422}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 423
 424static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
 425{
 426	struct se_lun *lun = to_stat_port(item);
 427	struct se_device *dev;
 428	ssize_t ret = -ENODEV;
 429
 430	rcu_read_lock();
 431	dev = rcu_dereference(lun->lun_se_dev);
 432	if (dev)
 433		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
 434	rcu_read_unlock();
 435	return ret;
 436}
 
 437
 438static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
 
 439{
 440	struct se_lun *lun = to_stat_port(item);
 441	struct se_device *dev;
 442	ssize_t ret = -ENODEV;
 
 443
 444	rcu_read_lock();
 445	dev = rcu_dereference(lun->lun_se_dev);
 446	if (dev)
 447		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 448	rcu_read_unlock();
 
 
 
 449	return ret;
 450}
 
 451
 452static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
 
 453{
 454	struct se_lun *lun = to_stat_port(item);
 455	struct se_device *dev;
 456	ssize_t ret = -ENODEV;
 457
 458	rcu_read_lock();
 459	dev = rcu_dereference(lun->lun_se_dev);
 460	if (dev)
 461		ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
 462	rcu_read_unlock();
 
 
 
 463	return ret;
 464}
 
 465
 466static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
 
 467{
 468	struct se_lun *lun = to_stat_port(item);
 469	struct se_device *dev;
 470	ssize_t ret = -ENODEV;
 
 471
 472	rcu_read_lock();
 473	dev = rcu_dereference(lun->lun_se_dev);
 474	if (dev)
 475		ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index);
 476	rcu_read_unlock();
 
 
 
 
 
 
 477	return ret;
 478}
 
 479
 480static ssize_t target_stat_port_busy_count_show(struct config_item *item,
 481		char *page)
 482{
 483	struct se_lun *lun = to_stat_port(item);
 484	struct se_device *dev;
 485	ssize_t ret = -ENODEV;
 486
 487	rcu_read_lock();
 488	dev = rcu_dereference(lun->lun_se_dev);
 489	if (dev) {
 490		/* FIXME: scsiPortBusyStatuses  */
 491		ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
 492	}
 493	rcu_read_unlock();
 
 
 494	return ret;
 495}
 
 496
 497CONFIGFS_ATTR_RO(target_stat_port_, inst);
 498CONFIGFS_ATTR_RO(target_stat_port_, dev);
 499CONFIGFS_ATTR_RO(target_stat_port_, indx);
 500CONFIGFS_ATTR_RO(target_stat_port_, role);
 501CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
 502
 503static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
 504	&target_stat_port_attr_inst,
 505	&target_stat_port_attr_dev,
 506	&target_stat_port_attr_indx,
 507	&target_stat_port_attr_role,
 508	&target_stat_port_attr_busy_count,
 509	NULL,
 510};
 511
 512static const struct config_item_type target_stat_scsi_port_cit = {
 
 
 
 
 
 
 513	.ct_attrs		= target_stat_scsi_port_attrs,
 514	.ct_owner		= THIS_MODULE,
 515};
 516
 517/*
 518 * SCSI Target Port Table
 519 */
 520static struct se_lun *to_stat_tgt_port(struct config_item *item)
 521{
 522	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
 523			struct se_port_stat_grps, scsi_tgt_port_group);
 524	return container_of(pgrps, struct se_lun, port_stat_grps);
 525}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 526
 527static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
 528		char *page)
 529{
 530	struct se_lun *lun = to_stat_tgt_port(item);
 531	struct se_device *dev;
 532	ssize_t ret = -ENODEV;
 533
 534	rcu_read_lock();
 535	dev = rcu_dereference(lun->lun_se_dev);
 536	if (dev)
 537		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
 538	rcu_read_unlock();
 539	return ret;
 540}
 
 541
 542static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
 543		char *page)
 544{
 545	struct se_lun *lun = to_stat_tgt_port(item);
 546	struct se_device *dev;
 547	ssize_t ret = -ENODEV;
 
 548
 549	rcu_read_lock();
 550	dev = rcu_dereference(lun->lun_se_dev);
 551	if (dev)
 552		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
 553	rcu_read_unlock();
 
 
 
 554	return ret;
 555}
 
 556
 557static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
 558		char *page)
 559{
 560	struct se_lun *lun = to_stat_tgt_port(item);
 561	struct se_device *dev;
 562	ssize_t ret = -ENODEV;
 563
 564	rcu_read_lock();
 565	dev = rcu_dereference(lun->lun_se_dev);
 566	if (dev)
 567		ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi);
 568	rcu_read_unlock();
 
 
 
 569	return ret;
 570}
 
 571
 572static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
 573		char *page)
 574{
 575	struct se_lun *lun = to_stat_tgt_port(item);
 576	struct se_portal_group *tpg = lun->lun_tpg;
 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, "%sPort#%u\n",
 584			tpg->se_tpg_tfo->fabric_name,
 585			lun->lun_rtpi);
 586	rcu_read_unlock();
 
 
 
 
 587	return ret;
 588}
 
 589
 590static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
 591		char *page)
 592{
 593	struct se_lun *lun = to_stat_tgt_port(item);
 594	struct se_portal_group *tpg = lun->lun_tpg;
 595	struct se_device *dev;
 596	ssize_t ret = -ENODEV;
 
 
 
 
 
 
 
 
 597
 598	rcu_read_lock();
 599	dev = rcu_dereference(lun->lun_se_dev);
 600	if (dev)
 601		ret = snprintf(page, PAGE_SIZE, "%s%s%d\n",
 602			tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+",
 603			tpg->se_tpg_tfo->tpg_get_tag(tpg));
 604	rcu_read_unlock();
 605	return ret;
 606}
 
 607
 608static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
 609		char *page)
 610{
 611	struct se_lun *lun = to_stat_tgt_port(item);
 612	struct se_device *dev;
 613	ssize_t ret = -ENODEV;
 
 614
 615	rcu_read_lock();
 616	dev = rcu_dereference(lun->lun_se_dev);
 617	if (dev)
 618		ret = snprintf(page, PAGE_SIZE, "%lu\n",
 619			       atomic_long_read(&lun->lun_stats.cmd_pdus));
 620	rcu_read_unlock();
 
 
 
 
 621	return ret;
 622}
 
 623
 624static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
 625		char *page)
 626{
 627	struct se_lun *lun = to_stat_tgt_port(item);
 628	struct se_device *dev;
 629	ssize_t ret = -ENODEV;
 
 
 
 
 
 
 
 
 
 630
 631	rcu_read_lock();
 632	dev = rcu_dereference(lun->lun_se_dev);
 633	if (dev)
 634		ret = snprintf(page, PAGE_SIZE, "%u\n",
 635			(u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20));
 636	rcu_read_unlock();
 637	return ret;
 638}
 
 639
 640static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
 641		char *page)
 642{
 643	struct se_lun *lun = to_stat_tgt_port(item);
 644	struct se_device *dev;
 645	ssize_t ret = -ENODEV;
 
 646
 647	rcu_read_lock();
 648	dev = rcu_dereference(lun->lun_se_dev);
 649	if (dev)
 650		ret = snprintf(page, PAGE_SIZE, "%u\n",
 651				(u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20));
 652	rcu_read_unlock();
 
 
 
 
 
 653	return ret;
 654}
 
 655
 656static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
 657		char *page)
 658{
 659	struct se_lun *lun = to_stat_tgt_port(item);
 660	struct se_device *dev;
 661	ssize_t ret = -ENODEV;
 
 662
 663	rcu_read_lock();
 664	dev = rcu_dereference(lun->lun_se_dev);
 665	if (dev) {
 666		/* FIXME: scsiTgtPortHsInCommands */
 667		ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
 668	}
 669	rcu_read_unlock();
 
 
 
 
 670	return ret;
 671}
 
 672
 673CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
 674CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
 675CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
 676CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
 677CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
 678CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
 679CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
 680CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
 681CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
 682
 683static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
 684	&target_stat_tgt_port_attr_inst,
 685	&target_stat_tgt_port_attr_dev,
 686	&target_stat_tgt_port_attr_indx,
 687	&target_stat_tgt_port_attr_name,
 688	&target_stat_tgt_port_attr_port_index,
 689	&target_stat_tgt_port_attr_in_cmds,
 690	&target_stat_tgt_port_attr_write_mbytes,
 691	&target_stat_tgt_port_attr_read_mbytes,
 692	&target_stat_tgt_port_attr_hs_in_cmds,
 693	NULL,
 694};
 695
 696static const struct config_item_type target_stat_scsi_tgt_port_cit = {
 
 
 
 
 
 
 697	.ct_attrs		= target_stat_scsi_tgt_port_attrs,
 698	.ct_owner		= THIS_MODULE,
 699};
 700
 701/*
 702 * SCSI Transport Table
 703 */
 704static struct se_lun *to_transport_stat(struct config_item *item)
 705{
 706	struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
 707			struct se_port_stat_grps, scsi_transport_group);
 708	return container_of(pgrps, struct se_lun, port_stat_grps);
 709}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 710
 711static ssize_t target_stat_transport_inst_show(struct config_item *item,
 712		char *page)
 713{
 714	struct se_lun *lun = to_transport_stat(item);
 715	struct se_device *dev;
 716	ssize_t ret = -ENODEV;
 717
 718	rcu_read_lock();
 719	dev = rcu_dereference(lun->lun_se_dev);
 720	if (dev)
 721		ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index);
 722	rcu_read_unlock();
 723	return ret;
 724}
 
 725
 726static ssize_t target_stat_transport_device_show(struct config_item *item,
 727		char *page)
 728{
 729	struct se_lun *lun = to_transport_stat(item);
 730	struct se_device *dev;
 731	struct se_portal_group *tpg = lun->lun_tpg;
 732	ssize_t ret = -ENODEV;
 733
 734	rcu_read_lock();
 735	dev = rcu_dereference(lun->lun_se_dev);
 736	if (dev) {
 737		/* scsiTransportType */
 738		ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n",
 739			       tpg->se_tpg_tfo->fabric_name);
 740	}
 741	rcu_read_unlock();
 
 
 
 
 742	return ret;
 743}
 
 744
 745static ssize_t target_stat_transport_indx_show(struct config_item *item,
 746		char *page)
 747{
 748	struct se_lun *lun = to_transport_stat(item);
 749	struct se_device *dev;
 750	struct se_portal_group *tpg = lun->lun_tpg;
 751	ssize_t ret = -ENODEV;
 752
 753	rcu_read_lock();
 754	dev = rcu_dereference(lun->lun_se_dev);
 755	if (dev)
 756		ret = snprintf(page, PAGE_SIZE, "%u\n",
 757			       tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
 758	rcu_read_unlock();
 
 
 
 
 759	return ret;
 760}
 
 761
 762static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
 763		char *page)
 764{
 765	struct se_lun *lun = to_transport_stat(item);
 766	struct se_device *dev;
 767	struct se_portal_group *tpg = lun->lun_tpg;
 
 768	struct t10_wwn *wwn;
 769	ssize_t ret = -ENODEV;
 770
 771	rcu_read_lock();
 772	dev = rcu_dereference(lun->lun_se_dev);
 773	if (dev) {
 774		wwn = &dev->t10_wwn;
 775		/* scsiTransportDevName */
 776		ret = snprintf(page, PAGE_SIZE, "%s+%s\n",
 777				tpg->se_tpg_tfo->tpg_get_wwn(tpg),
 778				(strlen(wwn->unit_serial)) ? wwn->unit_serial :
 779				wwn->vendor);
 780	}
 781	rcu_read_unlock();
 
 
 
 
 
 
 
 782	return ret;
 783}
 
 784
 785static ssize_t target_stat_transport_proto_id_show(struct config_item *item,
 786		char *page)
 787{
 788	struct se_lun *lun = to_transport_stat(item);
 789	struct se_device *dev;
 790	struct se_portal_group *tpg = lun->lun_tpg;
 791	ssize_t ret = -ENODEV;
 792
 793	rcu_read_lock();
 794	dev = rcu_dereference(lun->lun_se_dev);
 795	if (dev)
 796		ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->proto_id);
 797	rcu_read_unlock();
 798	return ret;
 799}
 800
 801CONFIGFS_ATTR_RO(target_stat_transport_, inst);
 802CONFIGFS_ATTR_RO(target_stat_transport_, device);
 803CONFIGFS_ATTR_RO(target_stat_transport_, indx);
 804CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
 805CONFIGFS_ATTR_RO(target_stat_transport_, proto_id);
 806
 807static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
 808	&target_stat_transport_attr_inst,
 809	&target_stat_transport_attr_device,
 810	&target_stat_transport_attr_indx,
 811	&target_stat_transport_attr_dev_name,
 812	&target_stat_transport_attr_proto_id,
 813	NULL,
 814};
 815
 816static const struct config_item_type target_stat_scsi_transport_cit = {
 
 
 
 
 
 
 817	.ct_attrs		= target_stat_scsi_transport_attrs,
 818	.ct_owner		= THIS_MODULE,
 819};
 820
 821/*
 822 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup
 823 * the target port statistics groups + configfs CITs located in target_core_stat.c
 824 */
 825void target_stat_setup_port_default_groups(struct se_lun *lun)
 826{
 
 
 827	config_group_init_type_name(&lun->port_stat_grps.scsi_port_group,
 828			"scsi_port", &target_stat_scsi_port_cit);
 829	configfs_add_default_group(&lun->port_stat_grps.scsi_port_group,
 830			&lun->port_stat_grps.stat_group);
 831
 832	config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group,
 833			"scsi_tgt_port", &target_stat_scsi_tgt_port_cit);
 834	configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group,
 835			&lun->port_stat_grps.stat_group);
 836
 837	config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group,
 838			"scsi_transport", &target_stat_scsi_transport_cit);
 839	configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group,
 840			&lun->port_stat_grps.stat_group);
 
 
 
 841}
 842
 843/*
 844 * SCSI Authorized Initiator Table
 845 */
 846
 847static struct se_lun_acl *auth_to_lacl(struct config_item *item)
 848{
 849	struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
 850			struct se_ml_stat_grps, scsi_auth_intr_group);
 851	return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
 852}
 
 
 
 
 
 
 
 853
 854static ssize_t target_stat_auth_inst_show(struct config_item *item,
 855		char *page)
 856{
 857	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 858	struct se_node_acl *nacl = lacl->se_lun_nacl;
 859	struct se_dev_entry *deve;
 860	struct se_portal_group *tpg;
 861	ssize_t ret;
 862
 863	rcu_read_lock();
 864	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 865	if (!deve) {
 866		rcu_read_unlock();
 867		return -ENODEV;
 868	}
 869	tpg = nacl->se_tpg;
 870	/* scsiInstIndex */
 871	ret = snprintf(page, PAGE_SIZE, "%u\n",
 872			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
 873	rcu_read_unlock();
 874	return ret;
 875}
 
 876
 877static ssize_t target_stat_auth_dev_show(struct config_item *item,
 878		char *page)
 879{
 880	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 881	struct se_node_acl *nacl = lacl->se_lun_nacl;
 882	struct se_dev_entry *deve;
 883	struct se_lun *lun;
 
 884	ssize_t ret;
 885
 886	rcu_read_lock();
 887	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 888	if (!deve) {
 889		rcu_read_unlock();
 890		return -ENODEV;
 891	}
 892	lun = rcu_dereference(deve->se_lun);
 
 893	/* scsiDeviceIndex */
 894	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
 895	rcu_read_unlock();
 896	return ret;
 897}
 
 898
 899static ssize_t target_stat_auth_port_show(struct config_item *item,
 900		char *page)
 901{
 902	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 903	struct se_node_acl *nacl = lacl->se_lun_nacl;
 904	struct se_dev_entry *deve;
 905	struct se_portal_group *tpg;
 906	ssize_t ret;
 907
 908	rcu_read_lock();
 909	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 910	if (!deve) {
 911		rcu_read_unlock();
 912		return -ENODEV;
 913	}
 914	tpg = nacl->se_tpg;
 915	/* scsiAuthIntrTgtPortIndex */
 916	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
 917	rcu_read_unlock();
 918	return ret;
 919}
 
 920
 921static ssize_t target_stat_auth_indx_show(struct config_item *item,
 922		char *page)
 923{
 924	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 925	struct se_node_acl *nacl = lacl->se_lun_nacl;
 926	struct se_dev_entry *deve;
 927	ssize_t ret;
 928
 929	rcu_read_lock();
 930	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 931	if (!deve) {
 932		rcu_read_unlock();
 933		return -ENODEV;
 934	}
 935	/* scsiAuthIntrIndex */
 936	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
 937	rcu_read_unlock();
 938	return ret;
 939}
 
 940
 941static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
 942		char *page)
 943{
 944	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 945	struct se_node_acl *nacl = lacl->se_lun_nacl;
 946	struct se_dev_entry *deve;
 947	ssize_t ret;
 948
 949	rcu_read_lock();
 950	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 951	if (!deve) {
 952		rcu_read_unlock();
 953		return -ENODEV;
 954	}
 955	/* scsiAuthIntrDevOrPort */
 956	ret = snprintf(page, PAGE_SIZE, "%u\n", 1);
 957	rcu_read_unlock();
 958	return ret;
 959}
 
 960
 961static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
 962		char *page)
 963{
 964	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 965	struct se_node_acl *nacl = lacl->se_lun_nacl;
 966	struct se_dev_entry *deve;
 967	ssize_t ret;
 968
 969	rcu_read_lock();
 970	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 971	if (!deve) {
 972		rcu_read_unlock();
 973		return -ENODEV;
 974	}
 975	/* scsiAuthIntrName */
 976	ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname);
 977	rcu_read_unlock();
 978	return ret;
 979}
 
 980
 981static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
 982		char *page)
 983{
 984	struct se_lun_acl *lacl = auth_to_lacl(item);
 
 985	struct se_node_acl *nacl = lacl->se_lun_nacl;
 986	struct se_dev_entry *deve;
 987	ssize_t ret;
 988
 989	rcu_read_lock();
 990	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
 991	if (!deve) {
 992		rcu_read_unlock();
 993		return -ENODEV;
 994	}
 995	/* FIXME: scsiAuthIntrLunMapIndex */
 996	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
 997	rcu_read_unlock();
 998	return ret;
 999}
 
1000
1001static ssize_t target_stat_auth_att_count_show(struct config_item *item,
1002		char *page)
1003{
1004	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1005	struct se_node_acl *nacl = lacl->se_lun_nacl;
1006	struct se_dev_entry *deve;
1007	ssize_t ret;
1008
1009	rcu_read_lock();
1010	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1011	if (!deve) {
1012		rcu_read_unlock();
1013		return -ENODEV;
1014	}
1015	/* scsiAuthIntrAttachedTimes */
1016	ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count);
1017	rcu_read_unlock();
1018	return ret;
1019}
 
1020
1021static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
1022		char *page)
1023{
1024	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1025	struct se_node_acl *nacl = lacl->se_lun_nacl;
1026	struct se_dev_entry *deve;
1027	ssize_t ret;
1028
1029	rcu_read_lock();
1030	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1031	if (!deve) {
1032		rcu_read_unlock();
1033		return -ENODEV;
1034	}
1035	/* scsiAuthIntrOutCommands */
1036	ret = snprintf(page, PAGE_SIZE, "%lu\n",
1037		       atomic_long_read(&deve->total_cmds));
1038	rcu_read_unlock();
1039	return ret;
1040}
 
1041
1042static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
1043		char *page)
1044{
1045	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1046	struct se_node_acl *nacl = lacl->se_lun_nacl;
1047	struct se_dev_entry *deve;
1048	ssize_t ret;
1049
1050	rcu_read_lock();
1051	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1052	if (!deve) {
1053		rcu_read_unlock();
1054		return -ENODEV;
1055	}
1056	/* scsiAuthIntrReadMegaBytes */
1057	ret = snprintf(page, PAGE_SIZE, "%u\n",
1058		      (u32)(atomic_long_read(&deve->read_bytes) >> 20));
1059	rcu_read_unlock();
1060	return ret;
1061}
 
1062
1063static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
1064		char *page)
1065{
1066	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1067	struct se_node_acl *nacl = lacl->se_lun_nacl;
1068	struct se_dev_entry *deve;
1069	ssize_t ret;
1070
1071	rcu_read_lock();
1072	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1073	if (!deve) {
1074		rcu_read_unlock();
1075		return -ENODEV;
1076	}
1077	/* scsiAuthIntrWrittenMegaBytes */
1078	ret = snprintf(page, PAGE_SIZE, "%u\n",
1079		      (u32)(atomic_long_read(&deve->write_bytes) >> 20));
1080	rcu_read_unlock();
1081	return ret;
1082}
 
1083
1084static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
1085		char *page)
1086{
1087	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1088	struct se_node_acl *nacl = lacl->se_lun_nacl;
1089	struct se_dev_entry *deve;
1090	ssize_t ret;
1091
1092	rcu_read_lock();
1093	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1094	if (!deve) {
1095		rcu_read_unlock();
1096		return -ENODEV;
1097	}
1098	/* FIXME: scsiAuthIntrHSOutCommands */
1099	ret = snprintf(page, PAGE_SIZE, "%u\n", 0);
1100	rcu_read_unlock();
1101	return ret;
1102}
 
1103
1104static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
1105		char *page)
1106{
1107	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1108	struct se_node_acl *nacl = lacl->se_lun_nacl;
1109	struct se_dev_entry *deve;
1110	ssize_t ret;
1111
1112	rcu_read_lock();
1113	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1114	if (!deve) {
1115		rcu_read_unlock();
1116		return -ENODEV;
1117	}
1118	/* scsiAuthIntrLastCreation */
1119	ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time -
1120				INITIAL_JIFFIES) * 100 / HZ));
1121	rcu_read_unlock();
1122	return ret;
1123}
 
1124
1125static ssize_t target_stat_auth_row_status_show(struct config_item *item,
1126		char *page)
1127{
1128	struct se_lun_acl *lacl = auth_to_lacl(item);
 
1129	struct se_node_acl *nacl = lacl->se_lun_nacl;
1130	struct se_dev_entry *deve;
1131	ssize_t ret;
1132
1133	rcu_read_lock();
1134	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1135	if (!deve) {
1136		rcu_read_unlock();
1137		return -ENODEV;
1138	}
1139	/* FIXME: scsiAuthIntrRowStatus */
1140	ret = snprintf(page, PAGE_SIZE, "Ready\n");
1141	rcu_read_unlock();
1142	return ret;
1143}
 
1144
1145CONFIGFS_ATTR_RO(target_stat_auth_, inst);
1146CONFIGFS_ATTR_RO(target_stat_auth_, dev);
1147CONFIGFS_ATTR_RO(target_stat_auth_, port);
1148CONFIGFS_ATTR_RO(target_stat_auth_, indx);
1149CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
1150CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
1151CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
1152CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
1153CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
1154CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
1155CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
1156CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
1157CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
1158CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
1159
1160static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1161	&target_stat_auth_attr_inst,
1162	&target_stat_auth_attr_dev,
1163	&target_stat_auth_attr_port,
1164	&target_stat_auth_attr_indx,
1165	&target_stat_auth_attr_dev_or_port,
1166	&target_stat_auth_attr_intr_name,
1167	&target_stat_auth_attr_map_indx,
1168	&target_stat_auth_attr_att_count,
1169	&target_stat_auth_attr_num_cmds,
1170	&target_stat_auth_attr_read_mbytes,
1171	&target_stat_auth_attr_write_mbytes,
1172	&target_stat_auth_attr_hs_num_cmds,
1173	&target_stat_auth_attr_creation_time,
1174	&target_stat_auth_attr_row_status,
1175	NULL,
1176};
1177
1178static const struct config_item_type target_stat_scsi_auth_intr_cit = {
 
 
 
 
 
 
1179	.ct_attrs		= target_stat_scsi_auth_intr_attrs,
1180	.ct_owner		= THIS_MODULE,
1181};
1182
1183/*
1184 * SCSI Attached Initiator Port Table
1185 */
1186
1187static struct se_lun_acl *iport_to_lacl(struct config_item *item)
1188{
1189	struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
1190			struct se_ml_stat_grps, scsi_att_intr_port_group);
1191	return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
1192}
 
 
 
 
 
 
 
1193
1194static ssize_t target_stat_iport_inst_show(struct config_item *item,
1195		char *page)
1196{
1197	struct se_lun_acl *lacl = iport_to_lacl(item);
 
1198	struct se_node_acl *nacl = lacl->se_lun_nacl;
1199	struct se_dev_entry *deve;
1200	struct se_portal_group *tpg;
1201	ssize_t ret;
1202
1203	rcu_read_lock();
1204	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1205	if (!deve) {
1206		rcu_read_unlock();
1207		return -ENODEV;
1208	}
1209	tpg = nacl->se_tpg;
1210	/* scsiInstIndex */
1211	ret = snprintf(page, PAGE_SIZE, "%u\n",
1212			tpg->se_tpg_tfo->tpg_get_inst_index(tpg));
1213	rcu_read_unlock();
1214	return ret;
1215}
 
1216
1217static ssize_t target_stat_iport_dev_show(struct config_item *item,
1218		char *page)
1219{
1220	struct se_lun_acl *lacl = iport_to_lacl(item);
 
1221	struct se_node_acl *nacl = lacl->se_lun_nacl;
1222	struct se_dev_entry *deve;
1223	struct se_lun *lun;
 
1224	ssize_t ret;
1225
1226	rcu_read_lock();
1227	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1228	if (!deve) {
1229		rcu_read_unlock();
1230		return -ENODEV;
1231	}
1232	lun = rcu_dereference(deve->se_lun);
 
1233	/* scsiDeviceIndex */
1234	ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index);
1235	rcu_read_unlock();
1236	return ret;
1237}
 
1238
1239static ssize_t target_stat_iport_port_show(struct config_item *item,
1240		char *page)
1241{
1242	struct se_lun_acl *lacl = iport_to_lacl(item);
 
1243	struct se_node_acl *nacl = lacl->se_lun_nacl;
1244	struct se_dev_entry *deve;
1245	struct se_portal_group *tpg;
1246	ssize_t ret;
1247
1248	rcu_read_lock();
1249	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1250	if (!deve) {
1251		rcu_read_unlock();
1252		return -ENODEV;
1253	}
1254	tpg = nacl->se_tpg;
1255	/* scsiPortIndex */
1256	ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg));
1257	rcu_read_unlock();
1258	return ret;
1259}
 
1260
1261static ssize_t target_stat_iport_indx_show(struct config_item *item,
1262		char *page)
1263{
1264	struct se_lun_acl *lacl = iport_to_lacl(item);
 
1265	struct se_node_acl *nacl = lacl->se_lun_nacl;
1266	struct se_session *se_sess;
1267	struct se_portal_group *tpg;
1268	ssize_t ret;
1269
1270	spin_lock_irq(&nacl->nacl_sess_lock);
1271	se_sess = nacl->nacl_sess;
1272	if (!se_sess) {
1273		spin_unlock_irq(&nacl->nacl_sess_lock);
1274		return -ENODEV;
1275	}
1276
1277	tpg = nacl->se_tpg;
1278	/* scsiAttIntrPortIndex */
1279	ret = snprintf(page, PAGE_SIZE, "%u\n",
1280			tpg->se_tpg_tfo->sess_get_index(se_sess));
1281	spin_unlock_irq(&nacl->nacl_sess_lock);
1282	return ret;
1283}
 
1284
1285static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
1286		char *page)
1287{
1288	struct se_lun_acl *lacl = iport_to_lacl(item);
 
1289	struct se_node_acl *nacl = lacl->se_lun_nacl;
1290	struct se_dev_entry *deve;
1291	ssize_t ret;
1292
1293	rcu_read_lock();
1294	deve = target_nacl_find_deve(nacl, lacl->mapped_lun);
1295	if (!deve) {
1296		rcu_read_unlock();
1297		return -ENODEV;
1298	}
1299	/* scsiAttIntrPortAuthIntrIdx */
1300	ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index);
1301	rcu_read_unlock();
1302	return ret;
1303}
 
1304
1305static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
1306		char *page)
1307{
1308	struct se_lun_acl *lacl = iport_to_lacl(item);
 
1309	struct se_node_acl *nacl = lacl->se_lun_nacl;
1310	struct se_session *se_sess;
1311	struct se_portal_group *tpg;
1312	ssize_t ret;
1313	unsigned char buf[64];
1314
1315	spin_lock_irq(&nacl->nacl_sess_lock);
1316	se_sess = nacl->nacl_sess;
1317	if (!se_sess) {
1318		spin_unlock_irq(&nacl->nacl_sess_lock);
1319		return -ENODEV;
1320	}
1321
1322	tpg = nacl->se_tpg;
1323	/* scsiAttIntrPortName+scsiAttIntrPortIdentifier */
1324	memset(buf, 0, 64);
1325	if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL)
1326		tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64);
 
1327
1328	ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf);
1329	spin_unlock_irq(&nacl->nacl_sess_lock);
1330	return ret;
1331}
 
1332
1333CONFIGFS_ATTR_RO(target_stat_iport_, inst);
1334CONFIGFS_ATTR_RO(target_stat_iport_, dev);
1335CONFIGFS_ATTR_RO(target_stat_iport_, port);
1336CONFIGFS_ATTR_RO(target_stat_iport_, indx);
1337CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
1338CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
1339
1340static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1341	&target_stat_iport_attr_inst,
1342	&target_stat_iport_attr_dev,
1343	&target_stat_iport_attr_port,
1344	&target_stat_iport_attr_indx,
1345	&target_stat_iport_attr_port_auth_indx,
1346	&target_stat_iport_attr_port_ident,
1347	NULL,
1348};
1349
1350static const struct config_item_type target_stat_scsi_att_intr_port_cit = {
 
 
 
 
 
 
1351	.ct_attrs		= target_stat_scsi_ath_intr_port_attrs,
1352	.ct_owner		= THIS_MODULE,
1353};
1354
1355/*
1356 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup
1357 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c
1358 */
1359void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl)
1360{
 
 
1361	config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group,
1362			"scsi_auth_intr", &target_stat_scsi_auth_intr_cit);
1363	configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group,
1364			&lacl->ml_stat_grps.stat_group);
1365
1366	config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1367			"scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit);
1368	configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group,
1369			&lacl->ml_stat_grps.stat_group);
 
 
1370}