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 SCSI_LU_INDEX 1 35 #define LU_COUNT 1 36 37 /* 38 * SCSI Device Table 39 */ 40 41 static struct se_device *to_stat_dev(struct config_item *item) 42 { 43 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item), 44 struct se_dev_stat_grps, scsi_dev_group); 45 return container_of(sgrps, struct se_device, dev_stat_grps); 46 } 47 48 static ssize_t target_stat_inst_show(struct config_item *item, char *page) 49 { 50 struct se_hba *hba = to_stat_dev(item)->se_hba; 51 52 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 53 } 54 55 static ssize_t target_stat_indx_show(struct config_item *item, char *page) 56 { 57 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index); 58 } 59 60 static ssize_t target_stat_role_show(struct config_item *item, char *page) 61 { 62 return snprintf(page, PAGE_SIZE, "Target\n"); 63 } 64 65 static ssize_t target_stat_ports_show(struct config_item *item, char *page) 66 { 67 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count); 68 } 69 70 CONFIGFS_ATTR_RO(target_stat_, inst); 71 CONFIGFS_ATTR_RO(target_stat_, indx); 72 CONFIGFS_ATTR_RO(target_stat_, role); 73 CONFIGFS_ATTR_RO(target_stat_, ports); 74 75 static struct configfs_attribute *target_stat_scsi_dev_attrs[] = { 76 &target_stat_attr_inst, 77 &target_stat_attr_indx, 78 &target_stat_attr_role, 79 &target_stat_attr_ports, 80 NULL, 81 }; 82 83 static const struct config_item_type target_stat_scsi_dev_cit = { 84 .ct_attrs = target_stat_scsi_dev_attrs, 85 .ct_owner = THIS_MODULE, 86 }; 87 88 /* 89 * SCSI Target Device Table 90 */ 91 static struct se_device *to_stat_tgt_dev(struct config_item *item) 92 { 93 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item), 94 struct se_dev_stat_grps, scsi_tgt_dev_group); 95 return container_of(sgrps, struct se_device, dev_stat_grps); 96 } 97 98 static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page) 99 { 100 struct se_hba *hba = to_stat_tgt_dev(item)->se_hba; 101 102 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 103 } 104 105 static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page) 106 { 107 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index); 108 } 109 110 static ssize_t target_stat_tgt_num_lus_show(struct config_item *item, 111 char *page) 112 { 113 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT); 114 } 115 116 static ssize_t target_stat_tgt_status_show(struct config_item *item, 117 char *page) 118 { 119 if (to_stat_tgt_dev(item)->export_count) 120 return snprintf(page, PAGE_SIZE, "activated\n"); 121 else 122 return snprintf(page, PAGE_SIZE, "deactivated\n"); 123 } 124 125 static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item, 126 char *page) 127 { 128 int non_accessible_lus; 129 130 if (to_stat_tgt_dev(item)->export_count) 131 non_accessible_lus = 0; 132 else 133 non_accessible_lus = 1; 134 135 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus); 136 } 137 138 static ssize_t target_stat_tgt_resets_show(struct config_item *item, 139 char *page) 140 { 141 return snprintf(page, PAGE_SIZE, "%lu\n", 142 atomic_long_read(&to_stat_tgt_dev(item)->num_resets)); 143 } 144 145 static ssize_t target_stat_tgt_aborts_complete_show(struct config_item *item, 146 char *page) 147 { 148 return snprintf(page, PAGE_SIZE, "%lu\n", 149 atomic_long_read(&to_stat_tgt_dev(item)->aborts_complete)); 150 } 151 152 static ssize_t target_stat_tgt_aborts_no_task_show(struct config_item *item, 153 char *page) 154 { 155 return snprintf(page, PAGE_SIZE, "%lu\n", 156 atomic_long_read(&to_stat_tgt_dev(item)->aborts_no_task)); 157 } 158 159 CONFIGFS_ATTR_RO(target_stat_tgt_, inst); 160 CONFIGFS_ATTR_RO(target_stat_tgt_, indx); 161 CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus); 162 CONFIGFS_ATTR_RO(target_stat_tgt_, status); 163 CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus); 164 CONFIGFS_ATTR_RO(target_stat_tgt_, resets); 165 CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_complete); 166 CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_no_task); 167 168 static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = { 169 &target_stat_tgt_attr_inst, 170 &target_stat_tgt_attr_indx, 171 &target_stat_tgt_attr_num_lus, 172 &target_stat_tgt_attr_status, 173 &target_stat_tgt_attr_non_access_lus, 174 &target_stat_tgt_attr_resets, 175 &target_stat_tgt_attr_aborts_complete, 176 &target_stat_tgt_attr_aborts_no_task, 177 NULL, 178 }; 179 180 static const struct config_item_type target_stat_scsi_tgt_dev_cit = { 181 .ct_attrs = target_stat_scsi_tgt_dev_attrs, 182 .ct_owner = THIS_MODULE, 183 }; 184 185 /* 186 * SCSI Logical Unit Table 187 */ 188 189 static struct se_device *to_stat_lu_dev(struct config_item *item) 190 { 191 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item), 192 struct se_dev_stat_grps, scsi_lu_group); 193 return container_of(sgrps, struct se_device, dev_stat_grps); 194 } 195 196 static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page) 197 { 198 struct se_hba *hba = to_stat_lu_dev(item)->se_hba; 199 200 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 201 } 202 203 static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page) 204 { 205 return snprintf(page, PAGE_SIZE, "%u\n", 206 to_stat_lu_dev(item)->dev_index); 207 } 208 209 static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page) 210 { 211 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX); 212 } 213 214 static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page) 215 { 216 /* FIXME: scsiLuDefaultLun */ 217 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0); 218 } 219 220 static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page) 221 { 222 struct se_device *dev = to_stat_lu_dev(item); 223 224 /* scsiLuWwnName */ 225 return snprintf(page, PAGE_SIZE, "%s\n", 226 (strlen(dev->t10_wwn.unit_serial)) ? 227 dev->t10_wwn.unit_serial : "None"); 228 } 229 230 static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page) 231 { 232 struct se_device *dev = to_stat_lu_dev(item); 233 234 return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_VENDOR_LEN) 235 "s\n", dev->t10_wwn.vendor); 236 } 237 238 static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page) 239 { 240 struct se_device *dev = to_stat_lu_dev(item); 241 242 return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_MODEL_LEN) 243 "s\n", dev->t10_wwn.model); 244 } 245 246 static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page) 247 { 248 struct se_device *dev = to_stat_lu_dev(item); 249 250 return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_REVISION_LEN) 251 "s\n", dev->t10_wwn.revision); 252 } 253 254 static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page) 255 { 256 struct se_device *dev = to_stat_lu_dev(item); 257 258 /* scsiLuPeripheralType */ 259 return snprintf(page, PAGE_SIZE, "%u\n", 260 dev->transport->get_device_type(dev)); 261 } 262 263 static ssize_t target_stat_lu_status_show(struct config_item *item, char *page) 264 { 265 struct se_device *dev = to_stat_lu_dev(item); 266 267 /* scsiLuStatus */ 268 return snprintf(page, PAGE_SIZE, "%s\n", 269 (dev->export_count) ? "available" : "notavailable"); 270 } 271 272 static ssize_t target_stat_lu_state_bit_show(struct config_item *item, 273 char *page) 274 { 275 /* scsiLuState */ 276 return snprintf(page, PAGE_SIZE, "exposed\n"); 277 } 278 279 static ssize_t target_stat_lu_num_cmds_show(struct config_item *item, 280 char *page) 281 { 282 struct se_device *dev = to_stat_lu_dev(item); 283 struct se_dev_io_stats *stats; 284 unsigned int cpu; 285 u32 cmds = 0; 286 287 for_each_possible_cpu(cpu) { 288 stats = per_cpu_ptr(dev->stats, cpu); 289 cmds += stats->total_cmds; 290 } 291 292 /* scsiLuNumCommands */ 293 return snprintf(page, PAGE_SIZE, "%u\n", cmds); 294 } 295 296 static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item, 297 char *page) 298 { 299 struct se_device *dev = to_stat_lu_dev(item); 300 struct se_dev_io_stats *stats; 301 unsigned int cpu; 302 u32 bytes = 0; 303 304 for_each_possible_cpu(cpu) { 305 stats = per_cpu_ptr(dev->stats, cpu); 306 bytes += stats->read_bytes; 307 } 308 309 /* scsiLuReadMegaBytes */ 310 return snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 311 } 312 313 static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item, 314 char *page) 315 { 316 struct se_device *dev = to_stat_lu_dev(item); 317 struct se_dev_io_stats *stats; 318 unsigned int cpu; 319 u32 bytes = 0; 320 321 for_each_possible_cpu(cpu) { 322 stats = per_cpu_ptr(dev->stats, cpu); 323 bytes += stats->write_bytes; 324 } 325 326 /* scsiLuWrittenMegaBytes */ 327 return snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 328 } 329 330 static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page) 331 { 332 struct se_device *dev = to_stat_lu_dev(item); 333 334 /* scsiLuInResets */ 335 return snprintf(page, PAGE_SIZE, "%lu\n", 336 atomic_long_read(&dev->num_resets)); 337 } 338 339 static ssize_t target_stat_lu_full_stat_show(struct config_item *item, 340 char *page) 341 { 342 /* FIXME: scsiLuOutTaskSetFullStatus */ 343 return snprintf(page, PAGE_SIZE, "%u\n", 0); 344 } 345 346 static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item, 347 char *page) 348 { 349 /* FIXME: scsiLuHSInCommands */ 350 return snprintf(page, PAGE_SIZE, "%u\n", 0); 351 } 352 353 static ssize_t target_stat_lu_creation_time_show(struct config_item *item, 354 char *page) 355 { 356 struct se_device *dev = to_stat_lu_dev(item); 357 358 /* scsiLuCreationTime */ 359 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time - 360 INITIAL_JIFFIES) * 100 / HZ)); 361 } 362 363 CONFIGFS_ATTR_RO(target_stat_lu_, inst); 364 CONFIGFS_ATTR_RO(target_stat_lu_, dev); 365 CONFIGFS_ATTR_RO(target_stat_lu_, indx); 366 CONFIGFS_ATTR_RO(target_stat_lu_, lun); 367 CONFIGFS_ATTR_RO(target_stat_lu_, lu_name); 368 CONFIGFS_ATTR_RO(target_stat_lu_, vend); 369 CONFIGFS_ATTR_RO(target_stat_lu_, prod); 370 CONFIGFS_ATTR_RO(target_stat_lu_, rev); 371 CONFIGFS_ATTR_RO(target_stat_lu_, dev_type); 372 CONFIGFS_ATTR_RO(target_stat_lu_, status); 373 CONFIGFS_ATTR_RO(target_stat_lu_, state_bit); 374 CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds); 375 CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes); 376 CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes); 377 CONFIGFS_ATTR_RO(target_stat_lu_, resets); 378 CONFIGFS_ATTR_RO(target_stat_lu_, full_stat); 379 CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds); 380 CONFIGFS_ATTR_RO(target_stat_lu_, creation_time); 381 382 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = { 383 &target_stat_lu_attr_inst, 384 &target_stat_lu_attr_dev, 385 &target_stat_lu_attr_indx, 386 &target_stat_lu_attr_lun, 387 &target_stat_lu_attr_lu_name, 388 &target_stat_lu_attr_vend, 389 &target_stat_lu_attr_prod, 390 &target_stat_lu_attr_rev, 391 &target_stat_lu_attr_dev_type, 392 &target_stat_lu_attr_status, 393 &target_stat_lu_attr_state_bit, 394 &target_stat_lu_attr_num_cmds, 395 &target_stat_lu_attr_read_mbytes, 396 &target_stat_lu_attr_write_mbytes, 397 &target_stat_lu_attr_resets, 398 &target_stat_lu_attr_full_stat, 399 &target_stat_lu_attr_hs_num_cmds, 400 &target_stat_lu_attr_creation_time, 401 NULL, 402 }; 403 404 static const struct config_item_type target_stat_scsi_lu_cit = { 405 .ct_attrs = target_stat_scsi_lu_attrs, 406 .ct_owner = THIS_MODULE, 407 }; 408 409 /* 410 * Called from target_core_configfs.c:target_core_make_subdev() to setup 411 * the target statistics groups + configfs CITs located in target_core_stat.c 412 */ 413 void target_stat_setup_dev_default_groups(struct se_device *dev) 414 { 415 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group, 416 "scsi_dev", &target_stat_scsi_dev_cit); 417 configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group, 418 &dev->dev_stat_grps.stat_group); 419 420 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group, 421 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit); 422 configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group, 423 &dev->dev_stat_grps.stat_group); 424 425 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group, 426 "scsi_lu", &target_stat_scsi_lu_cit); 427 configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group, 428 &dev->dev_stat_grps.stat_group); 429 } 430 431 /* 432 * SCSI Port Table 433 */ 434 435 static struct se_lun *to_stat_port(struct config_item *item) 436 { 437 struct se_port_stat_grps *pgrps = container_of(to_config_group(item), 438 struct se_port_stat_grps, scsi_port_group); 439 return container_of(pgrps, struct se_lun, port_stat_grps); 440 } 441 442 static ssize_t target_stat_port_inst_show(struct config_item *item, char *page) 443 { 444 struct se_lun *lun = to_stat_port(item); 445 struct se_device *dev; 446 ssize_t ret = -ENODEV; 447 448 rcu_read_lock(); 449 dev = rcu_dereference(lun->lun_se_dev); 450 if (dev) 451 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 452 rcu_read_unlock(); 453 return ret; 454 } 455 456 static ssize_t target_stat_port_dev_show(struct config_item *item, char *page) 457 { 458 struct se_lun *lun = to_stat_port(item); 459 struct se_device *dev; 460 ssize_t ret = -ENODEV; 461 462 rcu_read_lock(); 463 dev = rcu_dereference(lun->lun_se_dev); 464 if (dev) 465 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 466 rcu_read_unlock(); 467 return ret; 468 } 469 470 static ssize_t target_stat_port_indx_show(struct config_item *item, char *page) 471 { 472 struct se_lun *lun = to_stat_port(item); 473 struct se_device *dev; 474 ssize_t ret = -ENODEV; 475 476 rcu_read_lock(); 477 dev = rcu_dereference(lun->lun_se_dev); 478 if (dev) 479 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_tpg->tpg_rtpi); 480 rcu_read_unlock(); 481 return ret; 482 } 483 484 static ssize_t target_stat_port_role_show(struct config_item *item, char *page) 485 { 486 struct se_lun *lun = to_stat_port(item); 487 struct se_device *dev; 488 ssize_t ret = -ENODEV; 489 490 rcu_read_lock(); 491 dev = rcu_dereference(lun->lun_se_dev); 492 if (dev) 493 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); 494 rcu_read_unlock(); 495 return ret; 496 } 497 498 static ssize_t target_stat_port_busy_count_show(struct config_item *item, 499 char *page) 500 { 501 struct se_lun *lun = to_stat_port(item); 502 struct se_device *dev; 503 ssize_t ret = -ENODEV; 504 505 rcu_read_lock(); 506 dev = rcu_dereference(lun->lun_se_dev); 507 if (dev) { 508 /* FIXME: scsiPortBusyStatuses */ 509 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 510 } 511 rcu_read_unlock(); 512 return ret; 513 } 514 515 CONFIGFS_ATTR_RO(target_stat_port_, inst); 516 CONFIGFS_ATTR_RO(target_stat_port_, dev); 517 CONFIGFS_ATTR_RO(target_stat_port_, indx); 518 CONFIGFS_ATTR_RO(target_stat_port_, role); 519 CONFIGFS_ATTR_RO(target_stat_port_, busy_count); 520 521 static struct configfs_attribute *target_stat_scsi_port_attrs[] = { 522 &target_stat_port_attr_inst, 523 &target_stat_port_attr_dev, 524 &target_stat_port_attr_indx, 525 &target_stat_port_attr_role, 526 &target_stat_port_attr_busy_count, 527 NULL, 528 }; 529 530 static const struct config_item_type target_stat_scsi_port_cit = { 531 .ct_attrs = target_stat_scsi_port_attrs, 532 .ct_owner = THIS_MODULE, 533 }; 534 535 /* 536 * SCSI Target Port Table 537 */ 538 static struct se_lun *to_stat_tgt_port(struct config_item *item) 539 { 540 struct se_port_stat_grps *pgrps = container_of(to_config_group(item), 541 struct se_port_stat_grps, scsi_tgt_port_group); 542 return container_of(pgrps, struct se_lun, port_stat_grps); 543 } 544 545 static ssize_t target_stat_tgt_port_inst_show(struct config_item *item, 546 char *page) 547 { 548 struct se_lun *lun = to_stat_tgt_port(item); 549 struct se_device *dev; 550 ssize_t ret = -ENODEV; 551 552 rcu_read_lock(); 553 dev = rcu_dereference(lun->lun_se_dev); 554 if (dev) 555 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 556 rcu_read_unlock(); 557 return ret; 558 } 559 560 static ssize_t target_stat_tgt_port_dev_show(struct config_item *item, 561 char *page) 562 { 563 struct se_lun *lun = to_stat_tgt_port(item); 564 struct se_device *dev; 565 ssize_t ret = -ENODEV; 566 567 rcu_read_lock(); 568 dev = rcu_dereference(lun->lun_se_dev); 569 if (dev) 570 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 571 rcu_read_unlock(); 572 return ret; 573 } 574 575 static ssize_t target_stat_tgt_port_indx_show(struct config_item *item, 576 char *page) 577 { 578 struct se_lun *lun = to_stat_tgt_port(item); 579 struct se_device *dev; 580 ssize_t ret = -ENODEV; 581 582 rcu_read_lock(); 583 dev = rcu_dereference(lun->lun_se_dev); 584 if (dev) 585 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_tpg->tpg_rtpi); 586 rcu_read_unlock(); 587 return ret; 588 } 589 590 static ssize_t target_stat_tgt_port_name_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, "%sPort#%u\n", 602 tpg->se_tpg_tfo->fabric_name, 603 lun->lun_tpg->tpg_rtpi); 604 rcu_read_unlock(); 605 return ret; 606 } 607 608 static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item, 609 char *page) 610 { 611 struct se_lun *lun = to_stat_tgt_port(item); 612 struct se_portal_group *tpg = lun->lun_tpg; 613 struct se_device *dev; 614 ssize_t ret = -ENODEV; 615 616 rcu_read_lock(); 617 dev = rcu_dereference(lun->lun_se_dev); 618 if (dev) 619 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n", 620 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+", 621 tpg->se_tpg_tfo->tpg_get_tag(tpg)); 622 rcu_read_unlock(); 623 return ret; 624 } 625 626 static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item, 627 char *page) 628 { 629 struct se_lun *lun = to_stat_tgt_port(item); 630 struct se_device *dev; 631 ssize_t ret = -ENODEV; 632 633 rcu_read_lock(); 634 dev = rcu_dereference(lun->lun_se_dev); 635 if (dev) 636 ret = snprintf(page, PAGE_SIZE, "%lu\n", 637 atomic_long_read(&lun->lun_stats.cmd_pdus)); 638 rcu_read_unlock(); 639 return ret; 640 } 641 642 static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item, 643 char *page) 644 { 645 struct se_lun *lun = to_stat_tgt_port(item); 646 struct se_device *dev; 647 ssize_t ret = -ENODEV; 648 649 rcu_read_lock(); 650 dev = rcu_dereference(lun->lun_se_dev); 651 if (dev) 652 ret = snprintf(page, PAGE_SIZE, "%u\n", 653 (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20)); 654 rcu_read_unlock(); 655 return ret; 656 } 657 658 static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item, 659 char *page) 660 { 661 struct se_lun *lun = to_stat_tgt_port(item); 662 struct se_device *dev; 663 ssize_t ret = -ENODEV; 664 665 rcu_read_lock(); 666 dev = rcu_dereference(lun->lun_se_dev); 667 if (dev) 668 ret = snprintf(page, PAGE_SIZE, "%u\n", 669 (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20)); 670 rcu_read_unlock(); 671 return ret; 672 } 673 674 static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item, 675 char *page) 676 { 677 struct se_lun *lun = to_stat_tgt_port(item); 678 struct se_device *dev; 679 ssize_t ret = -ENODEV; 680 681 rcu_read_lock(); 682 dev = rcu_dereference(lun->lun_se_dev); 683 if (dev) { 684 /* FIXME: scsiTgtPortHsInCommands */ 685 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 686 } 687 rcu_read_unlock(); 688 return ret; 689 } 690 691 CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst); 692 CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev); 693 CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx); 694 CONFIGFS_ATTR_RO(target_stat_tgt_port_, name); 695 CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index); 696 CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds); 697 CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes); 698 CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes); 699 CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds); 700 701 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = { 702 &target_stat_tgt_port_attr_inst, 703 &target_stat_tgt_port_attr_dev, 704 &target_stat_tgt_port_attr_indx, 705 &target_stat_tgt_port_attr_name, 706 &target_stat_tgt_port_attr_port_index, 707 &target_stat_tgt_port_attr_in_cmds, 708 &target_stat_tgt_port_attr_write_mbytes, 709 &target_stat_tgt_port_attr_read_mbytes, 710 &target_stat_tgt_port_attr_hs_in_cmds, 711 NULL, 712 }; 713 714 static const struct config_item_type target_stat_scsi_tgt_port_cit = { 715 .ct_attrs = target_stat_scsi_tgt_port_attrs, 716 .ct_owner = THIS_MODULE, 717 }; 718 719 /* 720 * SCSI Transport Table 721 */ 722 static struct se_lun *to_transport_stat(struct config_item *item) 723 { 724 struct se_port_stat_grps *pgrps = container_of(to_config_group(item), 725 struct se_port_stat_grps, scsi_transport_group); 726 return container_of(pgrps, struct se_lun, port_stat_grps); 727 } 728 729 static ssize_t target_stat_transport_inst_show(struct config_item *item, 730 char *page) 731 { 732 struct se_lun *lun = to_transport_stat(item); 733 struct se_device *dev; 734 ssize_t ret = -ENODEV; 735 736 rcu_read_lock(); 737 dev = rcu_dereference(lun->lun_se_dev); 738 if (dev) 739 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 740 rcu_read_unlock(); 741 return ret; 742 } 743 744 static ssize_t target_stat_transport_device_show(struct config_item *item, 745 char *page) 746 { 747 struct se_lun *lun = to_transport_stat(item); 748 struct se_device *dev; 749 struct se_portal_group *tpg = lun->lun_tpg; 750 ssize_t ret = -ENODEV; 751 752 rcu_read_lock(); 753 dev = rcu_dereference(lun->lun_se_dev); 754 if (dev) { 755 /* scsiTransportType */ 756 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", 757 tpg->se_tpg_tfo->fabric_name); 758 } 759 rcu_read_unlock(); 760 return ret; 761 } 762 763 static ssize_t target_stat_transport_indx_show(struct config_item *item, 764 char *page) 765 { 766 struct se_lun *lun = to_transport_stat(item); 767 struct se_device *dev; 768 struct se_portal_group *tpg = lun->lun_tpg; 769 ssize_t ret = -ENODEV; 770 771 rcu_read_lock(); 772 dev = rcu_dereference(lun->lun_se_dev); 773 if (dev) 774 ret = snprintf(page, PAGE_SIZE, "%u\n", 775 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 776 rcu_read_unlock(); 777 return ret; 778 } 779 780 static ssize_t target_stat_transport_dev_name_show(struct config_item *item, 781 char *page) 782 { 783 struct se_lun *lun = to_transport_stat(item); 784 struct se_device *dev; 785 struct se_portal_group *tpg = lun->lun_tpg; 786 struct t10_wwn *wwn; 787 ssize_t ret = -ENODEV; 788 789 rcu_read_lock(); 790 dev = rcu_dereference(lun->lun_se_dev); 791 if (dev) { 792 wwn = &dev->t10_wwn; 793 /* scsiTransportDevName */ 794 ret = snprintf(page, PAGE_SIZE, "%s+%s\n", 795 tpg->se_tpg_tfo->tpg_get_wwn(tpg), 796 (strlen(wwn->unit_serial)) ? wwn->unit_serial : 797 wwn->vendor); 798 } 799 rcu_read_unlock(); 800 return ret; 801 } 802 803 static ssize_t target_stat_transport_proto_id_show(struct config_item *item, 804 char *page) 805 { 806 struct se_lun *lun = to_transport_stat(item); 807 struct se_device *dev; 808 struct se_portal_group *tpg = lun->lun_tpg; 809 ssize_t ret = -ENODEV; 810 811 rcu_read_lock(); 812 dev = rcu_dereference(lun->lun_se_dev); 813 if (dev) 814 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->proto_id); 815 rcu_read_unlock(); 816 return ret; 817 } 818 819 CONFIGFS_ATTR_RO(target_stat_transport_, inst); 820 CONFIGFS_ATTR_RO(target_stat_transport_, device); 821 CONFIGFS_ATTR_RO(target_stat_transport_, indx); 822 CONFIGFS_ATTR_RO(target_stat_transport_, dev_name); 823 CONFIGFS_ATTR_RO(target_stat_transport_, proto_id); 824 825 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = { 826 &target_stat_transport_attr_inst, 827 &target_stat_transport_attr_device, 828 &target_stat_transport_attr_indx, 829 &target_stat_transport_attr_dev_name, 830 &target_stat_transport_attr_proto_id, 831 NULL, 832 }; 833 834 static const struct config_item_type target_stat_scsi_transport_cit = { 835 .ct_attrs = target_stat_scsi_transport_attrs, 836 .ct_owner = THIS_MODULE, 837 }; 838 839 /* 840 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup 841 * the target port statistics groups + configfs CITs located in target_core_stat.c 842 */ 843 void target_stat_setup_port_default_groups(struct se_lun *lun) 844 { 845 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group, 846 "scsi_port", &target_stat_scsi_port_cit); 847 configfs_add_default_group(&lun->port_stat_grps.scsi_port_group, 848 &lun->port_stat_grps.stat_group); 849 850 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group, 851 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit); 852 configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group, 853 &lun->port_stat_grps.stat_group); 854 855 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group, 856 "scsi_transport", &target_stat_scsi_transport_cit); 857 configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group, 858 &lun->port_stat_grps.stat_group); 859 } 860 861 /* 862 * SCSI Authorized Initiator Table 863 */ 864 865 static struct se_lun_acl *auth_to_lacl(struct config_item *item) 866 { 867 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item), 868 struct se_ml_stat_grps, scsi_auth_intr_group); 869 return container_of(lgrps, struct se_lun_acl, ml_stat_grps); 870 } 871 872 static ssize_t target_stat_auth_inst_show(struct config_item *item, 873 char *page) 874 { 875 struct se_lun_acl *lacl = auth_to_lacl(item); 876 struct se_node_acl *nacl = lacl->se_lun_nacl; 877 struct se_dev_entry *deve; 878 struct se_portal_group *tpg; 879 ssize_t ret; 880 881 rcu_read_lock(); 882 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 883 if (!deve) { 884 rcu_read_unlock(); 885 return -ENODEV; 886 } 887 tpg = nacl->se_tpg; 888 /* scsiInstIndex */ 889 ret = snprintf(page, PAGE_SIZE, "%u\n", 890 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 891 rcu_read_unlock(); 892 return ret; 893 } 894 895 static ssize_t target_stat_auth_dev_show(struct config_item *item, 896 char *page) 897 { 898 struct se_lun_acl *lacl = auth_to_lacl(item); 899 struct se_node_acl *nacl = lacl->se_lun_nacl; 900 struct se_dev_entry *deve; 901 ssize_t ret; 902 903 rcu_read_lock(); 904 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 905 if (!deve) { 906 rcu_read_unlock(); 907 return -ENODEV; 908 } 909 910 /* scsiDeviceIndex */ 911 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index); 912 rcu_read_unlock(); 913 return ret; 914 } 915 916 static ssize_t target_stat_auth_port_show(struct config_item *item, 917 char *page) 918 { 919 struct se_lun_acl *lacl = auth_to_lacl(item); 920 struct se_node_acl *nacl = lacl->se_lun_nacl; 921 struct se_dev_entry *deve; 922 struct se_portal_group *tpg; 923 ssize_t ret; 924 925 rcu_read_lock(); 926 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 927 if (!deve) { 928 rcu_read_unlock(); 929 return -ENODEV; 930 } 931 tpg = nacl->se_tpg; 932 /* scsiAuthIntrTgtPortIndex */ 933 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); 934 rcu_read_unlock(); 935 return ret; 936 } 937 938 static ssize_t target_stat_auth_indx_show(struct config_item *item, 939 char *page) 940 { 941 struct se_lun_acl *lacl = auth_to_lacl(item); 942 struct se_node_acl *nacl = lacl->se_lun_nacl; 943 struct se_dev_entry *deve; 944 ssize_t ret; 945 946 rcu_read_lock(); 947 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 948 if (!deve) { 949 rcu_read_unlock(); 950 return -ENODEV; 951 } 952 /* scsiAuthIntrIndex */ 953 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); 954 rcu_read_unlock(); 955 return ret; 956 } 957 958 static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item, 959 char *page) 960 { 961 struct se_lun_acl *lacl = auth_to_lacl(item); 962 struct se_node_acl *nacl = lacl->se_lun_nacl; 963 struct se_dev_entry *deve; 964 ssize_t ret; 965 966 rcu_read_lock(); 967 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 968 if (!deve) { 969 rcu_read_unlock(); 970 return -ENODEV; 971 } 972 /* scsiAuthIntrDevOrPort */ 973 ret = snprintf(page, PAGE_SIZE, "%u\n", 1); 974 rcu_read_unlock(); 975 return ret; 976 } 977 978 static ssize_t target_stat_auth_intr_name_show(struct config_item *item, 979 char *page) 980 { 981 struct se_lun_acl *lacl = auth_to_lacl(item); 982 struct se_node_acl *nacl = lacl->se_lun_nacl; 983 struct se_dev_entry *deve; 984 ssize_t ret; 985 986 rcu_read_lock(); 987 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 988 if (!deve) { 989 rcu_read_unlock(); 990 return -ENODEV; 991 } 992 /* scsiAuthIntrName */ 993 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname); 994 rcu_read_unlock(); 995 return ret; 996 } 997 998 static ssize_t target_stat_auth_map_indx_show(struct config_item *item, 999 char *page) 1000 { 1001 struct se_lun_acl *lacl = auth_to_lacl(item); 1002 struct se_node_acl *nacl = lacl->se_lun_nacl; 1003 struct se_dev_entry *deve; 1004 ssize_t ret; 1005 1006 rcu_read_lock(); 1007 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1008 if (!deve) { 1009 rcu_read_unlock(); 1010 return -ENODEV; 1011 } 1012 /* FIXME: scsiAuthIntrLunMapIndex */ 1013 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 1014 rcu_read_unlock(); 1015 return ret; 1016 } 1017 1018 static ssize_t target_stat_auth_att_count_show(struct config_item *item, 1019 char *page) 1020 { 1021 struct se_lun_acl *lacl = auth_to_lacl(item); 1022 struct se_node_acl *nacl = lacl->se_lun_nacl; 1023 struct se_dev_entry *deve; 1024 ssize_t ret; 1025 1026 rcu_read_lock(); 1027 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1028 if (!deve) { 1029 rcu_read_unlock(); 1030 return -ENODEV; 1031 } 1032 /* scsiAuthIntrAttachedTimes */ 1033 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count); 1034 rcu_read_unlock(); 1035 return ret; 1036 } 1037 1038 static ssize_t target_stat_auth_num_cmds_show(struct config_item *item, 1039 char *page) 1040 { 1041 struct se_lun_acl *lacl = auth_to_lacl(item); 1042 struct se_node_acl *nacl = lacl->se_lun_nacl; 1043 struct se_dev_entry_io_stats *stats; 1044 struct se_dev_entry *deve; 1045 unsigned int cpu; 1046 ssize_t ret; 1047 u32 cmds = 0; 1048 1049 rcu_read_lock(); 1050 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1051 if (!deve) { 1052 rcu_read_unlock(); 1053 return -ENODEV; 1054 } 1055 1056 for_each_possible_cpu(cpu) { 1057 stats = per_cpu_ptr(deve->stats, cpu); 1058 cmds += stats->total_cmds; 1059 } 1060 1061 /* scsiAuthIntrOutCommands */ 1062 ret = snprintf(page, PAGE_SIZE, "%u\n", cmds); 1063 rcu_read_unlock(); 1064 return ret; 1065 } 1066 1067 static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item, 1068 char *page) 1069 { 1070 struct se_lun_acl *lacl = auth_to_lacl(item); 1071 struct se_node_acl *nacl = lacl->se_lun_nacl; 1072 struct se_dev_entry_io_stats *stats; 1073 struct se_dev_entry *deve; 1074 unsigned int cpu; 1075 ssize_t ret; 1076 u32 bytes = 0; 1077 1078 rcu_read_lock(); 1079 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1080 if (!deve) { 1081 rcu_read_unlock(); 1082 return -ENODEV; 1083 } 1084 1085 for_each_possible_cpu(cpu) { 1086 stats = per_cpu_ptr(deve->stats, cpu); 1087 bytes += stats->read_bytes; 1088 } 1089 1090 /* scsiAuthIntrReadMegaBytes */ 1091 ret = snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 1092 rcu_read_unlock(); 1093 return ret; 1094 } 1095 1096 static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item, 1097 char *page) 1098 { 1099 struct se_lun_acl *lacl = auth_to_lacl(item); 1100 struct se_node_acl *nacl = lacl->se_lun_nacl; 1101 struct se_dev_entry_io_stats *stats; 1102 struct se_dev_entry *deve; 1103 unsigned int cpu; 1104 ssize_t ret; 1105 u32 bytes = 0; 1106 1107 rcu_read_lock(); 1108 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1109 if (!deve) { 1110 rcu_read_unlock(); 1111 return -ENODEV; 1112 } 1113 1114 for_each_possible_cpu(cpu) { 1115 stats = per_cpu_ptr(deve->stats, cpu); 1116 bytes += stats->write_bytes; 1117 } 1118 1119 /* scsiAuthIntrWrittenMegaBytes */ 1120 ret = snprintf(page, PAGE_SIZE, "%u\n", bytes >> 20); 1121 rcu_read_unlock(); 1122 return ret; 1123 } 1124 1125 static ssize_t target_stat_auth_hs_num_cmds_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: scsiAuthIntrHSOutCommands */ 1140 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 1141 rcu_read_unlock(); 1142 return ret; 1143 } 1144 1145 static ssize_t target_stat_auth_creation_time_show(struct config_item *item, 1146 char *page) 1147 { 1148 struct se_lun_acl *lacl = auth_to_lacl(item); 1149 struct se_node_acl *nacl = lacl->se_lun_nacl; 1150 struct se_dev_entry *deve; 1151 ssize_t ret; 1152 1153 rcu_read_lock(); 1154 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1155 if (!deve) { 1156 rcu_read_unlock(); 1157 return -ENODEV; 1158 } 1159 /* scsiAuthIntrLastCreation */ 1160 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time - 1161 INITIAL_JIFFIES) * 100 / HZ)); 1162 rcu_read_unlock(); 1163 return ret; 1164 } 1165 1166 static ssize_t target_stat_auth_row_status_show(struct config_item *item, 1167 char *page) 1168 { 1169 struct se_lun_acl *lacl = auth_to_lacl(item); 1170 struct se_node_acl *nacl = lacl->se_lun_nacl; 1171 struct se_dev_entry *deve; 1172 ssize_t ret; 1173 1174 rcu_read_lock(); 1175 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1176 if (!deve) { 1177 rcu_read_unlock(); 1178 return -ENODEV; 1179 } 1180 /* FIXME: scsiAuthIntrRowStatus */ 1181 ret = snprintf(page, PAGE_SIZE, "Ready\n"); 1182 rcu_read_unlock(); 1183 return ret; 1184 } 1185 1186 CONFIGFS_ATTR_RO(target_stat_auth_, inst); 1187 CONFIGFS_ATTR_RO(target_stat_auth_, dev); 1188 CONFIGFS_ATTR_RO(target_stat_auth_, port); 1189 CONFIGFS_ATTR_RO(target_stat_auth_, indx); 1190 CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port); 1191 CONFIGFS_ATTR_RO(target_stat_auth_, intr_name); 1192 CONFIGFS_ATTR_RO(target_stat_auth_, map_indx); 1193 CONFIGFS_ATTR_RO(target_stat_auth_, att_count); 1194 CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds); 1195 CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes); 1196 CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes); 1197 CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds); 1198 CONFIGFS_ATTR_RO(target_stat_auth_, creation_time); 1199 CONFIGFS_ATTR_RO(target_stat_auth_, row_status); 1200 1201 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = { 1202 &target_stat_auth_attr_inst, 1203 &target_stat_auth_attr_dev, 1204 &target_stat_auth_attr_port, 1205 &target_stat_auth_attr_indx, 1206 &target_stat_auth_attr_dev_or_port, 1207 &target_stat_auth_attr_intr_name, 1208 &target_stat_auth_attr_map_indx, 1209 &target_stat_auth_attr_att_count, 1210 &target_stat_auth_attr_num_cmds, 1211 &target_stat_auth_attr_read_mbytes, 1212 &target_stat_auth_attr_write_mbytes, 1213 &target_stat_auth_attr_hs_num_cmds, 1214 &target_stat_auth_attr_creation_time, 1215 &target_stat_auth_attr_row_status, 1216 NULL, 1217 }; 1218 1219 static const struct config_item_type target_stat_scsi_auth_intr_cit = { 1220 .ct_attrs = target_stat_scsi_auth_intr_attrs, 1221 .ct_owner = THIS_MODULE, 1222 }; 1223 1224 /* 1225 * SCSI Attached Initiator Port Table 1226 */ 1227 1228 static struct se_lun_acl *iport_to_lacl(struct config_item *item) 1229 { 1230 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item), 1231 struct se_ml_stat_grps, scsi_att_intr_port_group); 1232 return container_of(lgrps, struct se_lun_acl, ml_stat_grps); 1233 } 1234 1235 static ssize_t target_stat_iport_inst_show(struct config_item *item, 1236 char *page) 1237 { 1238 struct se_lun_acl *lacl = iport_to_lacl(item); 1239 struct se_node_acl *nacl = lacl->se_lun_nacl; 1240 struct se_dev_entry *deve; 1241 struct se_portal_group *tpg; 1242 ssize_t ret; 1243 1244 rcu_read_lock(); 1245 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1246 if (!deve) { 1247 rcu_read_unlock(); 1248 return -ENODEV; 1249 } 1250 tpg = nacl->se_tpg; 1251 /* scsiInstIndex */ 1252 ret = snprintf(page, PAGE_SIZE, "%u\n", 1253 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 1254 rcu_read_unlock(); 1255 return ret; 1256 } 1257 1258 static ssize_t target_stat_iport_dev_show(struct config_item *item, 1259 char *page) 1260 { 1261 struct se_lun_acl *lacl = iport_to_lacl(item); 1262 struct se_node_acl *nacl = lacl->se_lun_nacl; 1263 struct se_dev_entry *deve; 1264 ssize_t ret; 1265 1266 rcu_read_lock(); 1267 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1268 if (!deve) { 1269 rcu_read_unlock(); 1270 return -ENODEV; 1271 } 1272 1273 /* scsiDeviceIndex */ 1274 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index); 1275 rcu_read_unlock(); 1276 return ret; 1277 } 1278 1279 static ssize_t target_stat_iport_port_show(struct config_item *item, 1280 char *page) 1281 { 1282 struct se_lun_acl *lacl = iport_to_lacl(item); 1283 struct se_node_acl *nacl = lacl->se_lun_nacl; 1284 struct se_dev_entry *deve; 1285 struct se_portal_group *tpg; 1286 ssize_t ret; 1287 1288 rcu_read_lock(); 1289 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1290 if (!deve) { 1291 rcu_read_unlock(); 1292 return -ENODEV; 1293 } 1294 tpg = nacl->se_tpg; 1295 /* scsiPortIndex */ 1296 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); 1297 rcu_read_unlock(); 1298 return ret; 1299 } 1300 1301 static ssize_t target_stat_iport_indx_show(struct config_item *item, 1302 char *page) 1303 { 1304 struct se_lun_acl *lacl = iport_to_lacl(item); 1305 struct se_node_acl *nacl = lacl->se_lun_nacl; 1306 struct se_session *se_sess; 1307 struct se_portal_group *tpg; 1308 ssize_t ret; 1309 1310 spin_lock_irq(&nacl->nacl_sess_lock); 1311 se_sess = nacl->nacl_sess; 1312 if (!se_sess) { 1313 spin_unlock_irq(&nacl->nacl_sess_lock); 1314 return -ENODEV; 1315 } 1316 1317 tpg = nacl->se_tpg; 1318 /* scsiAttIntrPortIndex */ 1319 ret = snprintf(page, PAGE_SIZE, "%u\n", 1320 tpg->se_tpg_tfo->sess_get_index(se_sess)); 1321 spin_unlock_irq(&nacl->nacl_sess_lock); 1322 return ret; 1323 } 1324 1325 static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item, 1326 char *page) 1327 { 1328 struct se_lun_acl *lacl = iport_to_lacl(item); 1329 struct se_node_acl *nacl = lacl->se_lun_nacl; 1330 struct se_dev_entry *deve; 1331 ssize_t ret; 1332 1333 rcu_read_lock(); 1334 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1335 if (!deve) { 1336 rcu_read_unlock(); 1337 return -ENODEV; 1338 } 1339 /* scsiAttIntrPortAuthIntrIdx */ 1340 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); 1341 rcu_read_unlock(); 1342 return ret; 1343 } 1344 1345 static ssize_t target_stat_iport_port_ident_show(struct config_item *item, 1346 char *page) 1347 { 1348 struct se_lun_acl *lacl = iport_to_lacl(item); 1349 struct se_node_acl *nacl = lacl->se_lun_nacl; 1350 struct se_session *se_sess; 1351 struct se_portal_group *tpg; 1352 ssize_t ret; 1353 unsigned char buf[64]; 1354 1355 spin_lock_irq(&nacl->nacl_sess_lock); 1356 se_sess = nacl->nacl_sess; 1357 if (!se_sess) { 1358 spin_unlock_irq(&nacl->nacl_sess_lock); 1359 return -ENODEV; 1360 } 1361 1362 tpg = nacl->se_tpg; 1363 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */ 1364 memset(buf, 0, 64); 1365 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) 1366 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64); 1367 1368 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf); 1369 spin_unlock_irq(&nacl->nacl_sess_lock); 1370 return ret; 1371 } 1372 1373 CONFIGFS_ATTR_RO(target_stat_iport_, inst); 1374 CONFIGFS_ATTR_RO(target_stat_iport_, dev); 1375 CONFIGFS_ATTR_RO(target_stat_iport_, port); 1376 CONFIGFS_ATTR_RO(target_stat_iport_, indx); 1377 CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx); 1378 CONFIGFS_ATTR_RO(target_stat_iport_, port_ident); 1379 1380 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = { 1381 &target_stat_iport_attr_inst, 1382 &target_stat_iport_attr_dev, 1383 &target_stat_iport_attr_port, 1384 &target_stat_iport_attr_indx, 1385 &target_stat_iport_attr_port_auth_indx, 1386 &target_stat_iport_attr_port_ident, 1387 NULL, 1388 }; 1389 1390 static const struct config_item_type target_stat_scsi_att_intr_port_cit = { 1391 .ct_attrs = target_stat_scsi_ath_intr_port_attrs, 1392 .ct_owner = THIS_MODULE, 1393 }; 1394 1395 /* 1396 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup 1397 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c 1398 */ 1399 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl) 1400 { 1401 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group, 1402 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit); 1403 configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group, 1404 &lacl->ml_stat_grps.stat_group); 1405 1406 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group, 1407 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit); 1408 configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group, 1409 &lacl->ml_stat_grps.stat_group); 1410 } 1411