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 #define per_cpu_stat_snprintf(stats_struct, prefix, field, shift) \ 280 static ssize_t \ 281 per_cpu_stat_##prefix##_snprintf(struct stats_struct __percpu *per_cpu_stats, \ 282 char *page) \ 283 { \ 284 struct stats_struct *stats; \ 285 unsigned int cpu; \ 286 u64 sum = 0; \ 287 \ 288 for_each_possible_cpu(cpu) { \ 289 stats = per_cpu_ptr(per_cpu_stats, cpu); \ 290 sum += stats->field; \ 291 } \ 292 \ 293 return snprintf(page, PAGE_SIZE, "%llu\n", sum >> shift); \ 294 } 295 296 #define lu_show_per_cpu_stat(prefix, field, shift) \ 297 per_cpu_stat_snprintf(se_dev_io_stats, prefix, field, shift); \ 298 static ssize_t \ 299 target_stat_##prefix##_show(struct config_item *item, char *page) \ 300 { \ 301 struct se_device *dev = to_stat_lu_dev(item); \ 302 \ 303 return per_cpu_stat_##prefix##_snprintf(dev->stats, page); \ 304 } \ 305 306 /* scsiLuNumCommands */ 307 lu_show_per_cpu_stat(lu_num_cmds, total_cmds, 0); 308 /* scsiLuReadMegaBytes */ 309 lu_show_per_cpu_stat(lu_read_mbytes, read_bytes, 20); 310 /* scsiLuWrittenMegaBytes */ 311 lu_show_per_cpu_stat(lu_write_mbytes, write_bytes, 20); 312 313 static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page) 314 { 315 struct se_device *dev = to_stat_lu_dev(item); 316 317 /* scsiLuInResets */ 318 return snprintf(page, PAGE_SIZE, "%lu\n", 319 atomic_long_read(&dev->num_resets)); 320 } 321 322 static ssize_t target_stat_lu_full_stat_show(struct config_item *item, 323 char *page) 324 { 325 /* FIXME: scsiLuOutTaskSetFullStatus */ 326 return snprintf(page, PAGE_SIZE, "%u\n", 0); 327 } 328 329 static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item, 330 char *page) 331 { 332 /* FIXME: scsiLuHSInCommands */ 333 return snprintf(page, PAGE_SIZE, "%u\n", 0); 334 } 335 336 static ssize_t target_stat_lu_creation_time_show(struct config_item *item, 337 char *page) 338 { 339 struct se_device *dev = to_stat_lu_dev(item); 340 341 /* scsiLuCreationTime */ 342 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time - 343 INITIAL_JIFFIES) * 100 / HZ)); 344 } 345 346 CONFIGFS_ATTR_RO(target_stat_lu_, inst); 347 CONFIGFS_ATTR_RO(target_stat_lu_, dev); 348 CONFIGFS_ATTR_RO(target_stat_lu_, indx); 349 CONFIGFS_ATTR_RO(target_stat_lu_, lun); 350 CONFIGFS_ATTR_RO(target_stat_lu_, lu_name); 351 CONFIGFS_ATTR_RO(target_stat_lu_, vend); 352 CONFIGFS_ATTR_RO(target_stat_lu_, prod); 353 CONFIGFS_ATTR_RO(target_stat_lu_, rev); 354 CONFIGFS_ATTR_RO(target_stat_lu_, dev_type); 355 CONFIGFS_ATTR_RO(target_stat_lu_, status); 356 CONFIGFS_ATTR_RO(target_stat_lu_, state_bit); 357 CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds); 358 CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes); 359 CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes); 360 CONFIGFS_ATTR_RO(target_stat_lu_, resets); 361 CONFIGFS_ATTR_RO(target_stat_lu_, full_stat); 362 CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds); 363 CONFIGFS_ATTR_RO(target_stat_lu_, creation_time); 364 365 static struct configfs_attribute *target_stat_scsi_lu_attrs[] = { 366 &target_stat_lu_attr_inst, 367 &target_stat_lu_attr_dev, 368 &target_stat_lu_attr_indx, 369 &target_stat_lu_attr_lun, 370 &target_stat_lu_attr_lu_name, 371 &target_stat_lu_attr_vend, 372 &target_stat_lu_attr_prod, 373 &target_stat_lu_attr_rev, 374 &target_stat_lu_attr_dev_type, 375 &target_stat_lu_attr_status, 376 &target_stat_lu_attr_state_bit, 377 &target_stat_lu_attr_num_cmds, 378 &target_stat_lu_attr_read_mbytes, 379 &target_stat_lu_attr_write_mbytes, 380 &target_stat_lu_attr_resets, 381 &target_stat_lu_attr_full_stat, 382 &target_stat_lu_attr_hs_num_cmds, 383 &target_stat_lu_attr_creation_time, 384 NULL, 385 }; 386 387 static const struct config_item_type target_stat_scsi_lu_cit = { 388 .ct_attrs = target_stat_scsi_lu_attrs, 389 .ct_owner = THIS_MODULE, 390 }; 391 392 /* 393 * Called from target_core_configfs.c:target_core_make_subdev() to setup 394 * the target statistics groups + configfs CITs located in target_core_stat.c 395 */ 396 void target_stat_setup_dev_default_groups(struct se_device *dev) 397 { 398 config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group, 399 "scsi_dev", &target_stat_scsi_dev_cit); 400 configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group, 401 &dev->dev_stat_grps.stat_group); 402 403 config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group, 404 "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit); 405 configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group, 406 &dev->dev_stat_grps.stat_group); 407 408 config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group, 409 "scsi_lu", &target_stat_scsi_lu_cit); 410 configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group, 411 &dev->dev_stat_grps.stat_group); 412 } 413 414 /* 415 * SCSI Port Table 416 */ 417 418 static struct se_lun *to_stat_port(struct config_item *item) 419 { 420 struct se_port_stat_grps *pgrps = container_of(to_config_group(item), 421 struct se_port_stat_grps, scsi_port_group); 422 return container_of(pgrps, struct se_lun, port_stat_grps); 423 } 424 425 static ssize_t target_stat_port_inst_show(struct config_item *item, char *page) 426 { 427 struct se_lun *lun = to_stat_port(item); 428 struct se_device *dev; 429 ssize_t ret = -ENODEV; 430 431 rcu_read_lock(); 432 dev = rcu_dereference(lun->lun_se_dev); 433 if (dev) 434 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 435 rcu_read_unlock(); 436 return ret; 437 } 438 439 static ssize_t target_stat_port_dev_show(struct config_item *item, char *page) 440 { 441 struct se_lun *lun = to_stat_port(item); 442 struct se_device *dev; 443 ssize_t ret = -ENODEV; 444 445 rcu_read_lock(); 446 dev = rcu_dereference(lun->lun_se_dev); 447 if (dev) 448 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 449 rcu_read_unlock(); 450 return ret; 451 } 452 453 static ssize_t target_stat_port_indx_show(struct config_item *item, char *page) 454 { 455 struct se_lun *lun = to_stat_port(item); 456 struct se_device *dev; 457 ssize_t ret = -ENODEV; 458 459 rcu_read_lock(); 460 dev = rcu_dereference(lun->lun_se_dev); 461 if (dev) 462 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_tpg->tpg_rtpi); 463 rcu_read_unlock(); 464 return ret; 465 } 466 467 static ssize_t target_stat_port_role_show(struct config_item *item, char *page) 468 { 469 struct se_lun *lun = to_stat_port(item); 470 struct se_device *dev; 471 ssize_t ret = -ENODEV; 472 473 rcu_read_lock(); 474 dev = rcu_dereference(lun->lun_se_dev); 475 if (dev) 476 ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); 477 rcu_read_unlock(); 478 return ret; 479 } 480 481 static ssize_t target_stat_port_busy_count_show(struct config_item *item, 482 char *page) 483 { 484 struct se_lun *lun = to_stat_port(item); 485 struct se_device *dev; 486 ssize_t ret = -ENODEV; 487 488 rcu_read_lock(); 489 dev = rcu_dereference(lun->lun_se_dev); 490 if (dev) { 491 /* FIXME: scsiPortBusyStatuses */ 492 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 493 } 494 rcu_read_unlock(); 495 return ret; 496 } 497 498 CONFIGFS_ATTR_RO(target_stat_port_, inst); 499 CONFIGFS_ATTR_RO(target_stat_port_, dev); 500 CONFIGFS_ATTR_RO(target_stat_port_, indx); 501 CONFIGFS_ATTR_RO(target_stat_port_, role); 502 CONFIGFS_ATTR_RO(target_stat_port_, busy_count); 503 504 static struct configfs_attribute *target_stat_scsi_port_attrs[] = { 505 &target_stat_port_attr_inst, 506 &target_stat_port_attr_dev, 507 &target_stat_port_attr_indx, 508 &target_stat_port_attr_role, 509 &target_stat_port_attr_busy_count, 510 NULL, 511 }; 512 513 static const struct config_item_type target_stat_scsi_port_cit = { 514 .ct_attrs = target_stat_scsi_port_attrs, 515 .ct_owner = THIS_MODULE, 516 }; 517 518 /* 519 * SCSI Target Port Table 520 */ 521 static struct se_lun *to_stat_tgt_port(struct config_item *item) 522 { 523 struct se_port_stat_grps *pgrps = container_of(to_config_group(item), 524 struct se_port_stat_grps, scsi_tgt_port_group); 525 return container_of(pgrps, struct se_lun, port_stat_grps); 526 } 527 528 static ssize_t target_stat_tgt_port_inst_show(struct config_item *item, 529 char *page) 530 { 531 struct se_lun *lun = to_stat_tgt_port(item); 532 struct se_device *dev; 533 ssize_t ret = -ENODEV; 534 535 rcu_read_lock(); 536 dev = rcu_dereference(lun->lun_se_dev); 537 if (dev) 538 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 539 rcu_read_unlock(); 540 return ret; 541 } 542 543 static ssize_t target_stat_tgt_port_dev_show(struct config_item *item, 544 char *page) 545 { 546 struct se_lun *lun = to_stat_tgt_port(item); 547 struct se_device *dev; 548 ssize_t ret = -ENODEV; 549 550 rcu_read_lock(); 551 dev = rcu_dereference(lun->lun_se_dev); 552 if (dev) 553 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); 554 rcu_read_unlock(); 555 return ret; 556 } 557 558 static ssize_t target_stat_tgt_port_indx_show(struct config_item *item, 559 char *page) 560 { 561 struct se_lun *lun = to_stat_tgt_port(item); 562 struct se_device *dev; 563 ssize_t ret = -ENODEV; 564 565 rcu_read_lock(); 566 dev = rcu_dereference(lun->lun_se_dev); 567 if (dev) 568 ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_tpg->tpg_rtpi); 569 rcu_read_unlock(); 570 return ret; 571 } 572 573 static ssize_t target_stat_tgt_port_name_show(struct config_item *item, 574 char *page) 575 { 576 struct se_lun *lun = to_stat_tgt_port(item); 577 struct se_portal_group *tpg = lun->lun_tpg; 578 struct se_device *dev; 579 ssize_t ret = -ENODEV; 580 581 rcu_read_lock(); 582 dev = rcu_dereference(lun->lun_se_dev); 583 if (dev) 584 ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n", 585 tpg->se_tpg_tfo->fabric_name, 586 lun->lun_tpg->tpg_rtpi); 587 rcu_read_unlock(); 588 return ret; 589 } 590 591 static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item, 592 char *page) 593 { 594 struct se_lun *lun = to_stat_tgt_port(item); 595 struct se_portal_group *tpg = lun->lun_tpg; 596 struct se_device *dev; 597 ssize_t ret = -ENODEV; 598 599 rcu_read_lock(); 600 dev = rcu_dereference(lun->lun_se_dev); 601 if (dev) 602 ret = snprintf(page, PAGE_SIZE, "%s%s%d\n", 603 tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+", 604 tpg->se_tpg_tfo->tpg_get_tag(tpg)); 605 rcu_read_unlock(); 606 return ret; 607 } 608 609 #define tgt_port_show_per_cpu_stat(prefix, field, shift) \ 610 per_cpu_stat_snprintf(scsi_port_stats, prefix, field, shift); \ 611 static ssize_t \ 612 target_stat_##prefix##_show(struct config_item *item, char *page) \ 613 { \ 614 struct se_lun *lun = to_stat_tgt_port(item); \ 615 struct se_device *dev; \ 616 int ret; \ 617 \ 618 rcu_read_lock(); \ 619 dev = rcu_dereference(lun->lun_se_dev); \ 620 if (!dev) { \ 621 rcu_read_unlock(); \ 622 return -ENODEV; \ 623 } \ 624 \ 625 ret = per_cpu_stat_##prefix##_snprintf(lun->lun_stats, page); \ 626 rcu_read_unlock(); \ 627 return ret; \ 628 } 629 630 tgt_port_show_per_cpu_stat(tgt_port_in_cmds, cmd_pdus, 0); 631 tgt_port_show_per_cpu_stat(tgt_port_write_mbytes, rx_data_octets, 20); 632 tgt_port_show_per_cpu_stat(tgt_port_read_mbytes, tx_data_octets, 20); 633 634 static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item, 635 char *page) 636 { 637 struct se_lun *lun = to_stat_tgt_port(item); 638 struct se_device *dev; 639 ssize_t ret = -ENODEV; 640 641 rcu_read_lock(); 642 dev = rcu_dereference(lun->lun_se_dev); 643 if (dev) { 644 /* FIXME: scsiTgtPortHsInCommands */ 645 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 646 } 647 rcu_read_unlock(); 648 return ret; 649 } 650 651 CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst); 652 CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev); 653 CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx); 654 CONFIGFS_ATTR_RO(target_stat_tgt_port_, name); 655 CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index); 656 CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds); 657 CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes); 658 CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes); 659 CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds); 660 661 static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = { 662 &target_stat_tgt_port_attr_inst, 663 &target_stat_tgt_port_attr_dev, 664 &target_stat_tgt_port_attr_indx, 665 &target_stat_tgt_port_attr_name, 666 &target_stat_tgt_port_attr_port_index, 667 &target_stat_tgt_port_attr_in_cmds, 668 &target_stat_tgt_port_attr_write_mbytes, 669 &target_stat_tgt_port_attr_read_mbytes, 670 &target_stat_tgt_port_attr_hs_in_cmds, 671 NULL, 672 }; 673 674 static const struct config_item_type target_stat_scsi_tgt_port_cit = { 675 .ct_attrs = target_stat_scsi_tgt_port_attrs, 676 .ct_owner = THIS_MODULE, 677 }; 678 679 /* 680 * SCSI Transport Table 681 */ 682 static struct se_lun *to_transport_stat(struct config_item *item) 683 { 684 struct se_port_stat_grps *pgrps = container_of(to_config_group(item), 685 struct se_port_stat_grps, scsi_transport_group); 686 return container_of(pgrps, struct se_lun, port_stat_grps); 687 } 688 689 static ssize_t target_stat_transport_inst_show(struct config_item *item, 690 char *page) 691 { 692 struct se_lun *lun = to_transport_stat(item); 693 struct se_device *dev; 694 ssize_t ret = -ENODEV; 695 696 rcu_read_lock(); 697 dev = rcu_dereference(lun->lun_se_dev); 698 if (dev) 699 ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); 700 rcu_read_unlock(); 701 return ret; 702 } 703 704 static ssize_t target_stat_transport_device_show(struct config_item *item, 705 char *page) 706 { 707 struct se_lun *lun = to_transport_stat(item); 708 struct se_device *dev; 709 struct se_portal_group *tpg = lun->lun_tpg; 710 ssize_t ret = -ENODEV; 711 712 rcu_read_lock(); 713 dev = rcu_dereference(lun->lun_se_dev); 714 if (dev) { 715 /* scsiTransportType */ 716 ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", 717 tpg->se_tpg_tfo->fabric_name); 718 } 719 rcu_read_unlock(); 720 return ret; 721 } 722 723 static ssize_t target_stat_transport_indx_show(struct config_item *item, 724 char *page) 725 { 726 struct se_lun *lun = to_transport_stat(item); 727 struct se_device *dev; 728 struct se_portal_group *tpg = lun->lun_tpg; 729 ssize_t ret = -ENODEV; 730 731 rcu_read_lock(); 732 dev = rcu_dereference(lun->lun_se_dev); 733 if (dev) 734 ret = snprintf(page, PAGE_SIZE, "%u\n", 735 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 736 rcu_read_unlock(); 737 return ret; 738 } 739 740 static ssize_t target_stat_transport_dev_name_show(struct config_item *item, 741 char *page) 742 { 743 struct se_lun *lun = to_transport_stat(item); 744 struct se_device *dev; 745 struct se_portal_group *tpg = lun->lun_tpg; 746 struct t10_wwn *wwn; 747 ssize_t ret = -ENODEV; 748 749 rcu_read_lock(); 750 dev = rcu_dereference(lun->lun_se_dev); 751 if (dev) { 752 wwn = &dev->t10_wwn; 753 /* scsiTransportDevName */ 754 ret = snprintf(page, PAGE_SIZE, "%s+%s\n", 755 tpg->se_tpg_tfo->tpg_get_wwn(tpg), 756 (strlen(wwn->unit_serial)) ? wwn->unit_serial : 757 wwn->vendor); 758 } 759 rcu_read_unlock(); 760 return ret; 761 } 762 763 static ssize_t target_stat_transport_proto_id_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", tpg->proto_id); 775 rcu_read_unlock(); 776 return ret; 777 } 778 779 CONFIGFS_ATTR_RO(target_stat_transport_, inst); 780 CONFIGFS_ATTR_RO(target_stat_transport_, device); 781 CONFIGFS_ATTR_RO(target_stat_transport_, indx); 782 CONFIGFS_ATTR_RO(target_stat_transport_, dev_name); 783 CONFIGFS_ATTR_RO(target_stat_transport_, proto_id); 784 785 static struct configfs_attribute *target_stat_scsi_transport_attrs[] = { 786 &target_stat_transport_attr_inst, 787 &target_stat_transport_attr_device, 788 &target_stat_transport_attr_indx, 789 &target_stat_transport_attr_dev_name, 790 &target_stat_transport_attr_proto_id, 791 NULL, 792 }; 793 794 static const struct config_item_type target_stat_scsi_transport_cit = { 795 .ct_attrs = target_stat_scsi_transport_attrs, 796 .ct_owner = THIS_MODULE, 797 }; 798 799 /* 800 * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup 801 * the target port statistics groups + configfs CITs located in target_core_stat.c 802 */ 803 void target_stat_setup_port_default_groups(struct se_lun *lun) 804 { 805 config_group_init_type_name(&lun->port_stat_grps.scsi_port_group, 806 "scsi_port", &target_stat_scsi_port_cit); 807 configfs_add_default_group(&lun->port_stat_grps.scsi_port_group, 808 &lun->port_stat_grps.stat_group); 809 810 config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group, 811 "scsi_tgt_port", &target_stat_scsi_tgt_port_cit); 812 configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group, 813 &lun->port_stat_grps.stat_group); 814 815 config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group, 816 "scsi_transport", &target_stat_scsi_transport_cit); 817 configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group, 818 &lun->port_stat_grps.stat_group); 819 } 820 821 /* 822 * SCSI Authorized Initiator Table 823 */ 824 825 static struct se_lun_acl *auth_to_lacl(struct config_item *item) 826 { 827 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item), 828 struct se_ml_stat_grps, scsi_auth_intr_group); 829 return container_of(lgrps, struct se_lun_acl, ml_stat_grps); 830 } 831 832 static ssize_t target_stat_auth_inst_show(struct config_item *item, 833 char *page) 834 { 835 struct se_lun_acl *lacl = auth_to_lacl(item); 836 struct se_node_acl *nacl = lacl->se_lun_nacl; 837 struct se_dev_entry *deve; 838 struct se_portal_group *tpg; 839 ssize_t ret; 840 841 rcu_read_lock(); 842 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 843 if (!deve) { 844 rcu_read_unlock(); 845 return -ENODEV; 846 } 847 tpg = nacl->se_tpg; 848 /* scsiInstIndex */ 849 ret = snprintf(page, PAGE_SIZE, "%u\n", 850 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 851 rcu_read_unlock(); 852 return ret; 853 } 854 855 static ssize_t target_stat_auth_dev_show(struct config_item *item, 856 char *page) 857 { 858 struct se_lun_acl *lacl = auth_to_lacl(item); 859 struct se_node_acl *nacl = lacl->se_lun_nacl; 860 struct se_dev_entry *deve; 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 870 /* scsiDeviceIndex */ 871 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index); 872 rcu_read_unlock(); 873 return ret; 874 } 875 876 static ssize_t target_stat_auth_port_show(struct config_item *item, 877 char *page) 878 { 879 struct se_lun_acl *lacl = auth_to_lacl(item); 880 struct se_node_acl *nacl = lacl->se_lun_nacl; 881 struct se_dev_entry *deve; 882 struct se_portal_group *tpg; 883 ssize_t ret; 884 885 rcu_read_lock(); 886 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 887 if (!deve) { 888 rcu_read_unlock(); 889 return -ENODEV; 890 } 891 tpg = nacl->se_tpg; 892 /* scsiAuthIntrTgtPortIndex */ 893 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); 894 rcu_read_unlock(); 895 return ret; 896 } 897 898 static ssize_t target_stat_auth_indx_show(struct config_item *item, 899 char *page) 900 { 901 struct se_lun_acl *lacl = auth_to_lacl(item); 902 struct se_node_acl *nacl = lacl->se_lun_nacl; 903 struct se_dev_entry *deve; 904 ssize_t ret; 905 906 rcu_read_lock(); 907 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 908 if (!deve) { 909 rcu_read_unlock(); 910 return -ENODEV; 911 } 912 /* scsiAuthIntrIndex */ 913 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); 914 rcu_read_unlock(); 915 return ret; 916 } 917 918 static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item, 919 char *page) 920 { 921 struct se_lun_acl *lacl = auth_to_lacl(item); 922 struct se_node_acl *nacl = lacl->se_lun_nacl; 923 struct se_dev_entry *deve; 924 ssize_t ret; 925 926 rcu_read_lock(); 927 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 928 if (!deve) { 929 rcu_read_unlock(); 930 return -ENODEV; 931 } 932 /* scsiAuthIntrDevOrPort */ 933 ret = snprintf(page, PAGE_SIZE, "%u\n", 1); 934 rcu_read_unlock(); 935 return ret; 936 } 937 938 static ssize_t target_stat_auth_intr_name_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 /* scsiAuthIntrName */ 953 ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname); 954 rcu_read_unlock(); 955 return ret; 956 } 957 958 static ssize_t target_stat_auth_map_indx_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 /* FIXME: scsiAuthIntrLunMapIndex */ 973 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 974 rcu_read_unlock(); 975 return ret; 976 } 977 978 static ssize_t target_stat_auth_att_count_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 /* scsiAuthIntrAttachedTimes */ 993 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count); 994 rcu_read_unlock(); 995 return ret; 996 } 997 998 #define auth_show_per_cpu_stat(prefix, field, shift) \ 999 per_cpu_stat_snprintf(se_dev_entry_io_stats, prefix, field, shift); \ 1000 static ssize_t \ 1001 target_stat_##prefix##_show(struct config_item *item, char *page) \ 1002 { \ 1003 struct se_lun_acl *lacl = auth_to_lacl(item); \ 1004 struct se_node_acl *nacl = lacl->se_lun_nacl; \ 1005 struct se_dev_entry *deve; \ 1006 int ret; \ 1007 \ 1008 rcu_read_lock(); \ 1009 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); \ 1010 if (!deve) { \ 1011 rcu_read_unlock(); \ 1012 return -ENODEV; \ 1013 } \ 1014 \ 1015 ret = per_cpu_stat_##prefix##_snprintf(deve->stats, page); \ 1016 rcu_read_unlock(); \ 1017 return ret; \ 1018 } 1019 1020 /* scsiAuthIntrOutCommands */ 1021 auth_show_per_cpu_stat(auth_num_cmds, total_cmds, 0); 1022 /* scsiAuthIntrReadMegaBytes */ 1023 auth_show_per_cpu_stat(auth_read_mbytes, read_bytes, 20); 1024 /* scsiAuthIntrWrittenMegaBytes */ 1025 auth_show_per_cpu_stat(auth_write_mbytes, write_bytes, 20); 1026 1027 static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item, 1028 char *page) 1029 { 1030 struct se_lun_acl *lacl = auth_to_lacl(item); 1031 struct se_node_acl *nacl = lacl->se_lun_nacl; 1032 struct se_dev_entry *deve; 1033 ssize_t ret; 1034 1035 rcu_read_lock(); 1036 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1037 if (!deve) { 1038 rcu_read_unlock(); 1039 return -ENODEV; 1040 } 1041 /* FIXME: scsiAuthIntrHSOutCommands */ 1042 ret = snprintf(page, PAGE_SIZE, "%u\n", 0); 1043 rcu_read_unlock(); 1044 return ret; 1045 } 1046 1047 static ssize_t target_stat_auth_creation_time_show(struct config_item *item, 1048 char *page) 1049 { 1050 struct se_lun_acl *lacl = auth_to_lacl(item); 1051 struct se_node_acl *nacl = lacl->se_lun_nacl; 1052 struct se_dev_entry *deve; 1053 ssize_t ret; 1054 1055 rcu_read_lock(); 1056 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1057 if (!deve) { 1058 rcu_read_unlock(); 1059 return -ENODEV; 1060 } 1061 /* scsiAuthIntrLastCreation */ 1062 ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time - 1063 INITIAL_JIFFIES) * 100 / HZ)); 1064 rcu_read_unlock(); 1065 return ret; 1066 } 1067 1068 static ssize_t target_stat_auth_row_status_show(struct config_item *item, 1069 char *page) 1070 { 1071 struct se_lun_acl *lacl = auth_to_lacl(item); 1072 struct se_node_acl *nacl = lacl->se_lun_nacl; 1073 struct se_dev_entry *deve; 1074 ssize_t ret; 1075 1076 rcu_read_lock(); 1077 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1078 if (!deve) { 1079 rcu_read_unlock(); 1080 return -ENODEV; 1081 } 1082 /* FIXME: scsiAuthIntrRowStatus */ 1083 ret = snprintf(page, PAGE_SIZE, "Ready\n"); 1084 rcu_read_unlock(); 1085 return ret; 1086 } 1087 1088 CONFIGFS_ATTR_RO(target_stat_auth_, inst); 1089 CONFIGFS_ATTR_RO(target_stat_auth_, dev); 1090 CONFIGFS_ATTR_RO(target_stat_auth_, port); 1091 CONFIGFS_ATTR_RO(target_stat_auth_, indx); 1092 CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port); 1093 CONFIGFS_ATTR_RO(target_stat_auth_, intr_name); 1094 CONFIGFS_ATTR_RO(target_stat_auth_, map_indx); 1095 CONFIGFS_ATTR_RO(target_stat_auth_, att_count); 1096 CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds); 1097 CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes); 1098 CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes); 1099 CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds); 1100 CONFIGFS_ATTR_RO(target_stat_auth_, creation_time); 1101 CONFIGFS_ATTR_RO(target_stat_auth_, row_status); 1102 1103 static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = { 1104 &target_stat_auth_attr_inst, 1105 &target_stat_auth_attr_dev, 1106 &target_stat_auth_attr_port, 1107 &target_stat_auth_attr_indx, 1108 &target_stat_auth_attr_dev_or_port, 1109 &target_stat_auth_attr_intr_name, 1110 &target_stat_auth_attr_map_indx, 1111 &target_stat_auth_attr_att_count, 1112 &target_stat_auth_attr_num_cmds, 1113 &target_stat_auth_attr_read_mbytes, 1114 &target_stat_auth_attr_write_mbytes, 1115 &target_stat_auth_attr_hs_num_cmds, 1116 &target_stat_auth_attr_creation_time, 1117 &target_stat_auth_attr_row_status, 1118 NULL, 1119 }; 1120 1121 static const struct config_item_type target_stat_scsi_auth_intr_cit = { 1122 .ct_attrs = target_stat_scsi_auth_intr_attrs, 1123 .ct_owner = THIS_MODULE, 1124 }; 1125 1126 /* 1127 * SCSI Attached Initiator Port Table 1128 */ 1129 1130 static struct se_lun_acl *iport_to_lacl(struct config_item *item) 1131 { 1132 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item), 1133 struct se_ml_stat_grps, scsi_att_intr_port_group); 1134 return container_of(lgrps, struct se_lun_acl, ml_stat_grps); 1135 } 1136 1137 static ssize_t target_stat_iport_inst_show(struct config_item *item, 1138 char *page) 1139 { 1140 struct se_lun_acl *lacl = iport_to_lacl(item); 1141 struct se_node_acl *nacl = lacl->se_lun_nacl; 1142 struct se_dev_entry *deve; 1143 struct se_portal_group *tpg; 1144 ssize_t ret; 1145 1146 rcu_read_lock(); 1147 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1148 if (!deve) { 1149 rcu_read_unlock(); 1150 return -ENODEV; 1151 } 1152 tpg = nacl->se_tpg; 1153 /* scsiInstIndex */ 1154 ret = snprintf(page, PAGE_SIZE, "%u\n", 1155 tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); 1156 rcu_read_unlock(); 1157 return ret; 1158 } 1159 1160 static ssize_t target_stat_iport_dev_show(struct config_item *item, 1161 char *page) 1162 { 1163 struct se_lun_acl *lacl = iport_to_lacl(item); 1164 struct se_node_acl *nacl = lacl->se_lun_nacl; 1165 struct se_dev_entry *deve; 1166 ssize_t ret; 1167 1168 rcu_read_lock(); 1169 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1170 if (!deve) { 1171 rcu_read_unlock(); 1172 return -ENODEV; 1173 } 1174 1175 /* scsiDeviceIndex */ 1176 ret = snprintf(page, PAGE_SIZE, "%u\n", deve->se_lun->lun_index); 1177 rcu_read_unlock(); 1178 return ret; 1179 } 1180 1181 static ssize_t target_stat_iport_port_show(struct config_item *item, 1182 char *page) 1183 { 1184 struct se_lun_acl *lacl = iport_to_lacl(item); 1185 struct se_node_acl *nacl = lacl->se_lun_nacl; 1186 struct se_dev_entry *deve; 1187 struct se_portal_group *tpg; 1188 ssize_t ret; 1189 1190 rcu_read_lock(); 1191 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1192 if (!deve) { 1193 rcu_read_unlock(); 1194 return -ENODEV; 1195 } 1196 tpg = nacl->se_tpg; 1197 /* scsiPortIndex */ 1198 ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); 1199 rcu_read_unlock(); 1200 return ret; 1201 } 1202 1203 static ssize_t target_stat_iport_indx_show(struct config_item *item, 1204 char *page) 1205 { 1206 struct se_lun_acl *lacl = iport_to_lacl(item); 1207 struct se_node_acl *nacl = lacl->se_lun_nacl; 1208 struct se_session *se_sess; 1209 struct se_portal_group *tpg; 1210 ssize_t ret; 1211 1212 spin_lock_irq(&nacl->nacl_sess_lock); 1213 se_sess = nacl->nacl_sess; 1214 if (!se_sess) { 1215 spin_unlock_irq(&nacl->nacl_sess_lock); 1216 return -ENODEV; 1217 } 1218 1219 tpg = nacl->se_tpg; 1220 /* scsiAttIntrPortIndex */ 1221 ret = snprintf(page, PAGE_SIZE, "%u\n", 1222 tpg->se_tpg_tfo->sess_get_index(se_sess)); 1223 spin_unlock_irq(&nacl->nacl_sess_lock); 1224 return ret; 1225 } 1226 1227 static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item, 1228 char *page) 1229 { 1230 struct se_lun_acl *lacl = iport_to_lacl(item); 1231 struct se_node_acl *nacl = lacl->se_lun_nacl; 1232 struct se_dev_entry *deve; 1233 ssize_t ret; 1234 1235 rcu_read_lock(); 1236 deve = target_nacl_find_deve(nacl, lacl->mapped_lun); 1237 if (!deve) { 1238 rcu_read_unlock(); 1239 return -ENODEV; 1240 } 1241 /* scsiAttIntrPortAuthIntrIdx */ 1242 ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); 1243 rcu_read_unlock(); 1244 return ret; 1245 } 1246 1247 static ssize_t target_stat_iport_port_ident_show(struct config_item *item, 1248 char *page) 1249 { 1250 struct se_lun_acl *lacl = iport_to_lacl(item); 1251 struct se_node_acl *nacl = lacl->se_lun_nacl; 1252 struct se_session *se_sess; 1253 struct se_portal_group *tpg; 1254 ssize_t ret; 1255 unsigned char buf[64]; 1256 1257 spin_lock_irq(&nacl->nacl_sess_lock); 1258 se_sess = nacl->nacl_sess; 1259 if (!se_sess) { 1260 spin_unlock_irq(&nacl->nacl_sess_lock); 1261 return -ENODEV; 1262 } 1263 1264 tpg = nacl->se_tpg; 1265 /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */ 1266 memset(buf, 0, 64); 1267 if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) 1268 tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64); 1269 1270 ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf); 1271 spin_unlock_irq(&nacl->nacl_sess_lock); 1272 return ret; 1273 } 1274 1275 CONFIGFS_ATTR_RO(target_stat_iport_, inst); 1276 CONFIGFS_ATTR_RO(target_stat_iport_, dev); 1277 CONFIGFS_ATTR_RO(target_stat_iport_, port); 1278 CONFIGFS_ATTR_RO(target_stat_iport_, indx); 1279 CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx); 1280 CONFIGFS_ATTR_RO(target_stat_iport_, port_ident); 1281 1282 static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = { 1283 &target_stat_iport_attr_inst, 1284 &target_stat_iport_attr_dev, 1285 &target_stat_iport_attr_port, 1286 &target_stat_iport_attr_indx, 1287 &target_stat_iport_attr_port_auth_indx, 1288 &target_stat_iport_attr_port_ident, 1289 NULL, 1290 }; 1291 1292 static const struct config_item_type target_stat_scsi_att_intr_port_cit = { 1293 .ct_attrs = target_stat_scsi_ath_intr_port_attrs, 1294 .ct_owner = THIS_MODULE, 1295 }; 1296 1297 /* 1298 * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup 1299 * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c 1300 */ 1301 void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl) 1302 { 1303 config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group, 1304 "scsi_auth_intr", &target_stat_scsi_auth_intr_cit); 1305 configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group, 1306 &lacl->ml_stat_grps.stat_group); 1307 1308 config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group, 1309 "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit); 1310 configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group, 1311 &lacl->ml_stat_grps.stat_group); 1312 } 1313