Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 2 | /******************************************************************************* |
| 3 | * Filename: target_core_stat.c |
| 4 | * |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 5 | * Modern ConfigFS group context specific statistics based on original |
| 6 | * target_core_mib.c code |
| 7 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 8 | * (c) Copyright 2006-2013 Datera, Inc. |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 9 | * |
| 10 | * Nicholas A. Bellinger <nab@linux-iscsi.org> |
| 11 | * |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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> |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 19 | #include <linux/utsname.h> |
| 20 | #include <linux/proc_fs.h> |
| 21 | #include <linux/seq_file.h> |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 22 | #include <linux/configfs.h> |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 23 | |
| 24 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 25 | #include <target/target_core_backend.h> |
| 26 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 27 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 28 | #include "target_core_internal.h" |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 44 | static struct se_device *to_stat_dev(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 45 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 51 | static ssize_t target_stat_inst_show(struct config_item *item, char *page) |
| 52 | { |
| 53 | struct se_hba *hba = to_stat_dev(item)->se_hba; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 54 | |
| 55 | return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); |
| 56 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 57 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 58 | static ssize_t target_stat_indx_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 59 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 60 | return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 61 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 62 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 63 | static ssize_t target_stat_role_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 64 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 65 | return snprintf(page, PAGE_SIZE, "Target\n"); |
| 66 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 67 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 68 | static ssize_t target_stat_ports_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 69 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 70 | return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 71 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 72 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 73 | CONFIGFS_ATTR_RO(target_stat_, inst); |
| 74 | CONFIGFS_ATTR_RO(target_stat_, indx); |
| 75 | CONFIGFS_ATTR_RO(target_stat_, role); |
| 76 | CONFIGFS_ATTR_RO(target_stat_, ports); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 77 | |
| 78 | static struct configfs_attribute *target_stat_scsi_dev_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 79 | &target_stat_attr_inst, |
| 80 | &target_stat_attr_indx, |
| 81 | &target_stat_attr_role, |
| 82 | &target_stat_attr_ports, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 83 | NULL, |
| 84 | }; |
| 85 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 86 | static const struct config_item_type target_stat_scsi_dev_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 87 | .ct_attrs = target_stat_scsi_dev_attrs, |
| 88 | .ct_owner = THIS_MODULE, |
| 89 | }; |
| 90 | |
| 91 | /* |
| 92 | * SCSI Target Device Table |
| 93 | */ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 94 | static struct se_device *to_stat_tgt_dev(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 95 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 101 | static 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; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 104 | |
| 105 | return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); |
| 106 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 107 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 108 | static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 109 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 110 | return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 111 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 112 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 113 | static ssize_t target_stat_tgt_num_lus_show(struct config_item *item, |
| 114 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 115 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 116 | return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT); |
| 117 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 118 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 119 | static ssize_t target_stat_tgt_status_show(struct config_item *item, |
| 120 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 121 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 122 | if (to_stat_tgt_dev(item)->export_count) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 123 | return snprintf(page, PAGE_SIZE, "activated"); |
| 124 | else |
| 125 | return snprintf(page, PAGE_SIZE, "deactivated"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 126 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 127 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 128 | static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item, |
| 129 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 130 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 131 | int non_accessible_lus; |
| 132 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 133 | if (to_stat_tgt_dev(item)->export_count) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 134 | non_accessible_lus = 0; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 135 | else |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 136 | non_accessible_lus = 1; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 137 | |
| 138 | return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus); |
| 139 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 140 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 141 | static ssize_t target_stat_tgt_resets_show(struct config_item *item, |
| 142 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 143 | { |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 144 | return snprintf(page, PAGE_SIZE, "%lu\n", |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 145 | atomic_long_read(&to_stat_tgt_dev(item)->num_resets)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 146 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 147 | |
Nicholas Bellinger | c87ba9c | 2017-01-19 15:45:57 -0800 | [diff] [blame] | 148 | static 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 | |
| 155 | static 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 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 162 | CONFIGFS_ATTR_RO(target_stat_tgt_, inst); |
| 163 | CONFIGFS_ATTR_RO(target_stat_tgt_, indx); |
| 164 | CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus); |
| 165 | CONFIGFS_ATTR_RO(target_stat_tgt_, status); |
| 166 | CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus); |
| 167 | CONFIGFS_ATTR_RO(target_stat_tgt_, resets); |
Nicholas Bellinger | c87ba9c | 2017-01-19 15:45:57 -0800 | [diff] [blame] | 168 | CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_complete); |
| 169 | CONFIGFS_ATTR_RO(target_stat_tgt_, aborts_no_task); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 170 | |
| 171 | static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Nicholas Bellinger | c87ba9c | 2017-01-19 15:45:57 -0800 | [diff] [blame] | 178 | &target_stat_tgt_attr_aborts_complete, |
| 179 | &target_stat_tgt_attr_aborts_no_task, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 180 | NULL, |
| 181 | }; |
| 182 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 183 | static const struct config_item_type target_stat_scsi_tgt_dev_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 184 | .ct_attrs = target_stat_scsi_tgt_dev_attrs, |
| 185 | .ct_owner = THIS_MODULE, |
| 186 | }; |
| 187 | |
| 188 | /* |
| 189 | * SCSI Logical Unit Table |
| 190 | */ |
| 191 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 192 | static struct se_device *to_stat_lu_dev(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 193 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 199 | static 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; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 202 | |
| 203 | return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); |
| 204 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 205 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 206 | static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 207 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 208 | return snprintf(page, PAGE_SIZE, "%u\n", |
| 209 | to_stat_lu_dev(item)->dev_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 210 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 211 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 212 | static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 213 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 214 | return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX); |
| 215 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 216 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 217 | static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 218 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 219 | /* FIXME: scsiLuDefaultLun */ |
| 220 | return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0); |
| 221 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 222 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 223 | static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 224 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 225 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 226 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 227 | /* scsiLuWwnName */ |
| 228 | return snprintf(page, PAGE_SIZE, "%s\n", |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 229 | (strlen(dev->t10_wwn.unit_serial)) ? |
| 230 | dev->t10_wwn.unit_serial : "None"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 231 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 232 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 233 | static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 234 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 235 | struct se_device *dev = to_stat_lu_dev(item); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 236 | |
David Disseldorp | b2da4ab | 2018-12-05 13:18:35 +0100 | [diff] [blame] | 237 | return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_VENDOR_LEN) |
| 238 | "s\n", dev->t10_wwn.vendor); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 239 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 240 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 241 | static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 242 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 243 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 244 | |
David Disseldorp | b2da4ab | 2018-12-05 13:18:35 +0100 | [diff] [blame] | 245 | return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_MODEL_LEN) |
| 246 | "s\n", dev->t10_wwn.model); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 247 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 248 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 249 | static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 250 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 251 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 252 | |
David Disseldorp | b2da4ab | 2018-12-05 13:18:35 +0100 | [diff] [blame] | 253 | return snprintf(page, PAGE_SIZE, "%-" __stringify(INQUIRY_REVISION_LEN) |
| 254 | "s\n", dev->t10_wwn.revision); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 255 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 256 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 257 | static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 258 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 259 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 260 | |
| 261 | /* scsiLuPeripheralType */ |
| 262 | return snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 263 | dev->transport->get_device_type(dev)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 264 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 265 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 266 | static ssize_t target_stat_lu_status_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 267 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 268 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 269 | |
| 270 | /* scsiLuStatus */ |
| 271 | return snprintf(page, PAGE_SIZE, "%s\n", |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 272 | (dev->export_count) ? "available" : "notavailable"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 273 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 274 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 275 | static ssize_t target_stat_lu_state_bit_show(struct config_item *item, |
| 276 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 277 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 278 | /* scsiLuState */ |
| 279 | return snprintf(page, PAGE_SIZE, "exposed\n"); |
| 280 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 281 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 282 | static ssize_t target_stat_lu_num_cmds_show(struct config_item *item, |
| 283 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 284 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 285 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 286 | |
| 287 | /* scsiLuNumCommands */ |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 288 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 289 | atomic_long_read(&dev->num_cmds)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 290 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 291 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 292 | static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item, |
| 293 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 294 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 295 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 296 | |
| 297 | /* scsiLuReadMegaBytes */ |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 298 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 299 | atomic_long_read(&dev->read_bytes) >> 20); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 300 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 301 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 302 | static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item, |
| 303 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 304 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 305 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 306 | |
| 307 | /* scsiLuWrittenMegaBytes */ |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 308 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 309 | atomic_long_read(&dev->write_bytes) >> 20); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 310 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 311 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 312 | static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 313 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 314 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 315 | |
| 316 | /* scsiLuInResets */ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 317 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 318 | atomic_long_read(&dev->num_resets)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 319 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 320 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 321 | static ssize_t target_stat_lu_full_stat_show(struct config_item *item, |
| 322 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 323 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 324 | /* FIXME: scsiLuOutTaskSetFullStatus */ |
| 325 | return snprintf(page, PAGE_SIZE, "%u\n", 0); |
| 326 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 327 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 328 | static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item, |
| 329 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 330 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 331 | /* FIXME: scsiLuHSInCommands */ |
| 332 | return snprintf(page, PAGE_SIZE, "%u\n", 0); |
| 333 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 334 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 335 | static ssize_t target_stat_lu_creation_time_show(struct config_item *item, |
| 336 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 337 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 338 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 339 | |
| 340 | /* scsiLuCreationTime */ |
| 341 | return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time - |
| 342 | INITIAL_JIFFIES) * 100 / HZ)); |
| 343 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 344 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 345 | CONFIGFS_ATTR_RO(target_stat_lu_, inst); |
| 346 | CONFIGFS_ATTR_RO(target_stat_lu_, dev); |
| 347 | CONFIGFS_ATTR_RO(target_stat_lu_, indx); |
| 348 | CONFIGFS_ATTR_RO(target_stat_lu_, lun); |
| 349 | CONFIGFS_ATTR_RO(target_stat_lu_, lu_name); |
| 350 | CONFIGFS_ATTR_RO(target_stat_lu_, vend); |
| 351 | CONFIGFS_ATTR_RO(target_stat_lu_, prod); |
| 352 | CONFIGFS_ATTR_RO(target_stat_lu_, rev); |
| 353 | CONFIGFS_ATTR_RO(target_stat_lu_, dev_type); |
| 354 | CONFIGFS_ATTR_RO(target_stat_lu_, status); |
| 355 | CONFIGFS_ATTR_RO(target_stat_lu_, state_bit); |
| 356 | CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds); |
| 357 | CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes); |
| 358 | CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes); |
| 359 | CONFIGFS_ATTR_RO(target_stat_lu_, resets); |
| 360 | CONFIGFS_ATTR_RO(target_stat_lu_, full_stat); |
| 361 | CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds); |
| 362 | CONFIGFS_ATTR_RO(target_stat_lu_, creation_time); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 363 | |
| 364 | static struct configfs_attribute *target_stat_scsi_lu_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 383 | NULL, |
| 384 | }; |
| 385 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 386 | static const struct config_item_type target_stat_scsi_lu_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 395 | void target_stat_setup_dev_default_groups(struct se_device *dev) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 396 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 397 | config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 398 | "scsi_dev", &target_stat_scsi_dev_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 399 | configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group, |
| 400 | &dev->dev_stat_grps.stat_group); |
| 401 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 402 | config_group_init_type_name(&dev->dev_stat_grps.scsi_tgt_dev_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 403 | "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 404 | configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group, |
| 405 | &dev->dev_stat_grps.stat_group); |
| 406 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 407 | config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 408 | "scsi_lu", &target_stat_scsi_lu_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 409 | configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group, |
| 410 | &dev->dev_stat_grps.stat_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | /* |
| 414 | * SCSI Port Table |
| 415 | */ |
| 416 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 417 | static struct se_lun *to_stat_port(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 418 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 424 | static ssize_t target_stat_port_inst_show(struct config_item *item, char *page) |
| 425 | { |
| 426 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 427 | struct se_device *dev; |
| 428 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 429 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 430 | rcu_read_lock(); |
| 431 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 432 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 433 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); |
| 434 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 435 | return ret; |
| 436 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 437 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 438 | static ssize_t target_stat_port_dev_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 439 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 440 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 441 | struct se_device *dev; |
| 442 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 443 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 444 | rcu_read_lock(); |
| 445 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 446 | if (dev) |
| 447 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 448 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 449 | return ret; |
| 450 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 451 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 452 | static ssize_t target_stat_port_indx_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 453 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 454 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 455 | struct se_device *dev; |
| 456 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 457 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 458 | rcu_read_lock(); |
| 459 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 460 | if (dev) |
| 461 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 462 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 463 | return ret; |
| 464 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 465 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 466 | static ssize_t target_stat_port_role_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 467 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 468 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 469 | struct se_device *dev; |
| 470 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 471 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 472 | rcu_read_lock(); |
| 473 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 474 | if (dev) |
| 475 | ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 476 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 477 | return ret; |
| 478 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 479 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 480 | static ssize_t target_stat_port_busy_count_show(struct config_item *item, |
| 481 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 482 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 483 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 484 | struct se_device *dev; |
| 485 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 486 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 487 | rcu_read_lock(); |
| 488 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 489 | if (dev) { |
| 490 | /* FIXME: scsiPortBusyStatuses */ |
| 491 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 492 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 493 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 494 | return ret; |
| 495 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 496 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 497 | CONFIGFS_ATTR_RO(target_stat_port_, inst); |
| 498 | CONFIGFS_ATTR_RO(target_stat_port_, dev); |
| 499 | CONFIGFS_ATTR_RO(target_stat_port_, indx); |
| 500 | CONFIGFS_ATTR_RO(target_stat_port_, role); |
| 501 | CONFIGFS_ATTR_RO(target_stat_port_, busy_count); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 502 | |
| 503 | static struct configfs_attribute *target_stat_scsi_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 509 | NULL, |
| 510 | }; |
| 511 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 512 | static const struct config_item_type target_stat_scsi_port_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 513 | .ct_attrs = target_stat_scsi_port_attrs, |
| 514 | .ct_owner = THIS_MODULE, |
| 515 | }; |
| 516 | |
| 517 | /* |
| 518 | * SCSI Target Port Table |
| 519 | */ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 520 | static struct se_lun *to_stat_tgt_port(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 521 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 527 | static 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); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 531 | struct se_device *dev; |
| 532 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 533 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 534 | rcu_read_lock(); |
| 535 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 536 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 537 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); |
| 538 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 539 | return ret; |
| 540 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 541 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 542 | static ssize_t target_stat_tgt_port_dev_show(struct config_item *item, |
| 543 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 544 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 545 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 546 | struct se_device *dev; |
| 547 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 548 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 549 | rcu_read_lock(); |
| 550 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 551 | if (dev) |
| 552 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 553 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 554 | return ret; |
| 555 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 556 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 557 | static ssize_t target_stat_tgt_port_indx_show(struct config_item *item, |
| 558 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 559 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 560 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 561 | struct se_device *dev; |
| 562 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 563 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 564 | rcu_read_lock(); |
| 565 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 566 | if (dev) |
| 567 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 568 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 569 | return ret; |
| 570 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 571 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 572 | static ssize_t target_stat_tgt_port_name_show(struct config_item *item, |
| 573 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 574 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 575 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 576 | struct se_portal_group *tpg = lun->lun_tpg; |
| 577 | struct se_device *dev; |
| 578 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 579 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 580 | rcu_read_lock(); |
| 581 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 582 | if (dev) |
| 583 | ret = snprintf(page, PAGE_SIZE, "%sPort#%u\n", |
David Disseldorp | 30c7ca9 | 2018-11-23 18:36:12 +0100 | [diff] [blame] | 584 | tpg->se_tpg_tfo->fabric_name, |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 585 | lun->lun_rtpi); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 586 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 587 | return ret; |
| 588 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 589 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 590 | static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item, |
| 591 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 592 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 593 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 594 | struct se_portal_group *tpg = lun->lun_tpg; |
| 595 | struct se_device *dev; |
| 596 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 597 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 598 | rcu_read_lock(); |
| 599 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 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)); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 604 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 605 | return ret; |
| 606 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 607 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 608 | static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item, |
| 609 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 610 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 611 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 612 | struct se_device *dev; |
| 613 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 614 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 615 | rcu_read_lock(); |
| 616 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 617 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 618 | ret = snprintf(page, PAGE_SIZE, "%lu\n", |
| 619 | atomic_long_read(&lun->lun_stats.cmd_pdus)); |
| 620 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 621 | return ret; |
| 622 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 623 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 624 | static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item, |
| 625 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 626 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 627 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 628 | struct se_device *dev; |
| 629 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 630 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 631 | rcu_read_lock(); |
| 632 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 633 | if (dev) |
| 634 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 635 | (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20)); |
| 636 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 637 | return ret; |
| 638 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 639 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 640 | static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item, |
| 641 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 642 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 643 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 644 | struct se_device *dev; |
| 645 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 646 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 647 | rcu_read_lock(); |
| 648 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 649 | if (dev) |
| 650 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 651 | (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20)); |
| 652 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 653 | return ret; |
| 654 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 655 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 656 | static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item, |
| 657 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 658 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 659 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 660 | struct se_device *dev; |
| 661 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 662 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 663 | rcu_read_lock(); |
| 664 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 665 | if (dev) { |
| 666 | /* FIXME: scsiTgtPortHsInCommands */ |
| 667 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 668 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 669 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 670 | return ret; |
| 671 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 672 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 673 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst); |
| 674 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev); |
| 675 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx); |
| 676 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, name); |
| 677 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index); |
| 678 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds); |
| 679 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes); |
| 680 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes); |
| 681 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 682 | |
| 683 | static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 693 | NULL, |
| 694 | }; |
| 695 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 696 | static const struct config_item_type target_stat_scsi_tgt_port_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 697 | .ct_attrs = target_stat_scsi_tgt_port_attrs, |
| 698 | .ct_owner = THIS_MODULE, |
| 699 | }; |
| 700 | |
| 701 | /* |
| 702 | * SCSI Transport Table |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 703 | */ |
| 704 | static struct se_lun *to_transport_stat(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 705 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 711 | static ssize_t target_stat_transport_inst_show(struct config_item *item, |
| 712 | char *page) |
| 713 | { |
| 714 | struct se_lun *lun = to_transport_stat(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 715 | struct se_device *dev; |
| 716 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 717 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 718 | rcu_read_lock(); |
| 719 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 720 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 721 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); |
| 722 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 723 | return ret; |
| 724 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 725 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 726 | static ssize_t target_stat_transport_device_show(struct config_item *item, |
| 727 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 728 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 729 | struct se_lun *lun = to_transport_stat(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 730 | struct se_device *dev; |
| 731 | struct se_portal_group *tpg = lun->lun_tpg; |
| 732 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 733 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 734 | rcu_read_lock(); |
| 735 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 736 | if (dev) { |
| 737 | /* scsiTransportType */ |
| 738 | ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", |
David Disseldorp | 30c7ca9 | 2018-11-23 18:36:12 +0100 | [diff] [blame] | 739 | tpg->se_tpg_tfo->fabric_name); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 740 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 741 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 742 | return ret; |
| 743 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 744 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 745 | static ssize_t target_stat_transport_indx_show(struct config_item *item, |
| 746 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 747 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 748 | struct se_lun *lun = to_transport_stat(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 749 | struct se_device *dev; |
| 750 | struct se_portal_group *tpg = lun->lun_tpg; |
| 751 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 752 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 753 | rcu_read_lock(); |
| 754 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 755 | if (dev) |
| 756 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 757 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 758 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 759 | return ret; |
| 760 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 761 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 762 | static ssize_t target_stat_transport_dev_name_show(struct config_item *item, |
| 763 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 764 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 765 | struct se_lun *lun = to_transport_stat(item); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 766 | struct se_device *dev; |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 767 | struct se_portal_group *tpg = lun->lun_tpg; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 768 | struct t10_wwn *wwn; |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 769 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 770 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 771 | rcu_read_lock(); |
| 772 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 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); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 780 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 781 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 782 | return ret; |
| 783 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 784 | |
Mike Christie | 0ab8ac6 | 2017-01-13 04:47:48 -0600 | [diff] [blame] | 785 | static 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 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 801 | CONFIGFS_ATTR_RO(target_stat_transport_, inst); |
| 802 | CONFIGFS_ATTR_RO(target_stat_transport_, device); |
| 803 | CONFIGFS_ATTR_RO(target_stat_transport_, indx); |
| 804 | CONFIGFS_ATTR_RO(target_stat_transport_, dev_name); |
Mike Christie | 0ab8ac6 | 2017-01-13 04:47:48 -0600 | [diff] [blame] | 805 | CONFIGFS_ATTR_RO(target_stat_transport_, proto_id); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 806 | |
| 807 | static struct configfs_attribute *target_stat_scsi_transport_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Mike Christie | 0ab8ac6 | 2017-01-13 04:47:48 -0600 | [diff] [blame] | 812 | &target_stat_transport_attr_proto_id, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 813 | NULL, |
| 814 | }; |
| 815 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 816 | static const struct config_item_type target_stat_scsi_transport_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | */ |
| 825 | void target_stat_setup_port_default_groups(struct se_lun *lun) |
| 826 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 827 | config_group_init_type_name(&lun->port_stat_grps.scsi_port_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 828 | "scsi_port", &target_stat_scsi_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 829 | configfs_add_default_group(&lun->port_stat_grps.scsi_port_group, |
| 830 | &lun->port_stat_grps.stat_group); |
| 831 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 832 | config_group_init_type_name(&lun->port_stat_grps.scsi_tgt_port_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 833 | "scsi_tgt_port", &target_stat_scsi_tgt_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 834 | configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group, |
| 835 | &lun->port_stat_grps.stat_group); |
| 836 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 837 | config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 838 | "scsi_transport", &target_stat_scsi_transport_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 839 | configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group, |
| 840 | &lun->port_stat_grps.stat_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | /* |
| 844 | * SCSI Authorized Initiator Table |
| 845 | */ |
| 846 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 847 | static struct se_lun_acl *auth_to_lacl(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 848 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 854 | static 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); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 863 | rcu_read_lock(); |
| 864 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 865 | if (!deve) { |
| 866 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 867 | return -ENODEV; |
| 868 | } |
| 869 | tpg = nacl->se_tpg; |
| 870 | /* scsiInstIndex */ |
| 871 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 872 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 873 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 874 | return ret; |
| 875 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 876 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 877 | static ssize_t target_stat_auth_dev_show(struct config_item *item, |
| 878 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 879 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 880 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 881 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 882 | struct se_dev_entry *deve; |
| 883 | struct se_lun *lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 884 | ssize_t ret; |
| 885 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 886 | rcu_read_lock(); |
| 887 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 888 | if (!deve) { |
| 889 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 890 | return -ENODEV; |
| 891 | } |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 892 | lun = rcu_dereference(deve->se_lun); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 893 | /* scsiDeviceIndex */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 894 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); |
| 895 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 896 | return ret; |
| 897 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 898 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 899 | static ssize_t target_stat_auth_port_show(struct config_item *item, |
| 900 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 901 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 902 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 908 | rcu_read_lock(); |
| 909 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 910 | if (!deve) { |
| 911 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 912 | return -ENODEV; |
| 913 | } |
| 914 | tpg = nacl->se_tpg; |
| 915 | /* scsiAuthIntrTgtPortIndex */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 916 | ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 917 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 918 | return ret; |
| 919 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 920 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 921 | static ssize_t target_stat_auth_indx_show(struct config_item *item, |
| 922 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 923 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 924 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 925 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 926 | struct se_dev_entry *deve; |
| 927 | ssize_t ret; |
| 928 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 929 | rcu_read_lock(); |
| 930 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 931 | if (!deve) { |
| 932 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 933 | return -ENODEV; |
| 934 | } |
| 935 | /* scsiAuthIntrIndex */ |
| 936 | ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 937 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 938 | return ret; |
| 939 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 940 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 941 | static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item, |
| 942 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 943 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 944 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 945 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 946 | struct se_dev_entry *deve; |
| 947 | ssize_t ret; |
| 948 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 949 | rcu_read_lock(); |
| 950 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 951 | if (!deve) { |
| 952 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 953 | return -ENODEV; |
| 954 | } |
| 955 | /* scsiAuthIntrDevOrPort */ |
| 956 | ret = snprintf(page, PAGE_SIZE, "%u\n", 1); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 957 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 958 | return ret; |
| 959 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 960 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 961 | static ssize_t target_stat_auth_intr_name_show(struct config_item *item, |
| 962 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 963 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 964 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 965 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 966 | struct se_dev_entry *deve; |
| 967 | ssize_t ret; |
| 968 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 969 | rcu_read_lock(); |
| 970 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 971 | if (!deve) { |
| 972 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 973 | return -ENODEV; |
| 974 | } |
| 975 | /* scsiAuthIntrName */ |
| 976 | ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 977 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 978 | return ret; |
| 979 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 980 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 981 | static ssize_t target_stat_auth_map_indx_show(struct config_item *item, |
| 982 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 983 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 984 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 985 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 986 | struct se_dev_entry *deve; |
| 987 | ssize_t ret; |
| 988 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 989 | rcu_read_lock(); |
| 990 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 991 | if (!deve) { |
| 992 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 993 | return -ENODEV; |
| 994 | } |
| 995 | /* FIXME: scsiAuthIntrLunMapIndex */ |
| 996 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 997 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 998 | return ret; |
| 999 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1000 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1001 | static ssize_t target_stat_auth_att_count_show(struct config_item *item, |
| 1002 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1003 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1004 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1005 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1006 | struct se_dev_entry *deve; |
| 1007 | ssize_t ret; |
| 1008 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1009 | rcu_read_lock(); |
| 1010 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1011 | if (!deve) { |
| 1012 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1013 | return -ENODEV; |
| 1014 | } |
| 1015 | /* scsiAuthIntrAttachedTimes */ |
| 1016 | ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1017 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1018 | return ret; |
| 1019 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1020 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1021 | static ssize_t target_stat_auth_num_cmds_show(struct config_item *item, |
| 1022 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1023 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1024 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1025 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1026 | struct se_dev_entry *deve; |
| 1027 | ssize_t ret; |
| 1028 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1029 | rcu_read_lock(); |
| 1030 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1031 | if (!deve) { |
| 1032 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1033 | return -ENODEV; |
| 1034 | } |
| 1035 | /* scsiAuthIntrOutCommands */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1036 | ret = snprintf(page, PAGE_SIZE, "%lu\n", |
| 1037 | atomic_long_read(&deve->total_cmds)); |
| 1038 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1039 | return ret; |
| 1040 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1041 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1042 | static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item, |
| 1043 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1044 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1045 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1046 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1047 | struct se_dev_entry *deve; |
| 1048 | ssize_t ret; |
| 1049 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1050 | rcu_read_lock(); |
| 1051 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1052 | if (!deve) { |
| 1053 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1054 | return -ENODEV; |
| 1055 | } |
| 1056 | /* scsiAuthIntrReadMegaBytes */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1057 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 1058 | (u32)(atomic_long_read(&deve->read_bytes) >> 20)); |
| 1059 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1060 | return ret; |
| 1061 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1062 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1063 | static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item, |
| 1064 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1065 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1066 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1067 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1068 | struct se_dev_entry *deve; |
| 1069 | ssize_t ret; |
| 1070 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1071 | rcu_read_lock(); |
| 1072 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1073 | if (!deve) { |
| 1074 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1075 | return -ENODEV; |
| 1076 | } |
| 1077 | /* scsiAuthIntrWrittenMegaBytes */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1078 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 1079 | (u32)(atomic_long_read(&deve->write_bytes) >> 20)); |
| 1080 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1081 | return ret; |
| 1082 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1083 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1084 | static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item, |
| 1085 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1086 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1087 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1088 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1089 | struct se_dev_entry *deve; |
| 1090 | ssize_t ret; |
| 1091 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1092 | rcu_read_lock(); |
| 1093 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1094 | if (!deve) { |
| 1095 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1096 | return -ENODEV; |
| 1097 | } |
| 1098 | /* FIXME: scsiAuthIntrHSOutCommands */ |
| 1099 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1100 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1101 | return ret; |
| 1102 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1103 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1104 | static ssize_t target_stat_auth_creation_time_show(struct config_item *item, |
| 1105 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1106 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1107 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1108 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1109 | struct se_dev_entry *deve; |
| 1110 | ssize_t ret; |
| 1111 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1112 | rcu_read_lock(); |
| 1113 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1114 | if (!deve) { |
| 1115 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1116 | return -ENODEV; |
| 1117 | } |
| 1118 | /* scsiAuthIntrLastCreation */ |
| 1119 | ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time - |
| 1120 | INITIAL_JIFFIES) * 100 / HZ)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1121 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1122 | return ret; |
| 1123 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1124 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1125 | static ssize_t target_stat_auth_row_status_show(struct config_item *item, |
| 1126 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1127 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1128 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1129 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1130 | struct se_dev_entry *deve; |
| 1131 | ssize_t ret; |
| 1132 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1133 | rcu_read_lock(); |
| 1134 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1135 | if (!deve) { |
| 1136 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1137 | return -ENODEV; |
| 1138 | } |
| 1139 | /* FIXME: scsiAuthIntrRowStatus */ |
| 1140 | ret = snprintf(page, PAGE_SIZE, "Ready\n"); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1141 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1142 | return ret; |
| 1143 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1144 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1145 | CONFIGFS_ATTR_RO(target_stat_auth_, inst); |
| 1146 | CONFIGFS_ATTR_RO(target_stat_auth_, dev); |
| 1147 | CONFIGFS_ATTR_RO(target_stat_auth_, port); |
| 1148 | CONFIGFS_ATTR_RO(target_stat_auth_, indx); |
| 1149 | CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port); |
| 1150 | CONFIGFS_ATTR_RO(target_stat_auth_, intr_name); |
| 1151 | CONFIGFS_ATTR_RO(target_stat_auth_, map_indx); |
| 1152 | CONFIGFS_ATTR_RO(target_stat_auth_, att_count); |
| 1153 | CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds); |
| 1154 | CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes); |
| 1155 | CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes); |
| 1156 | CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds); |
| 1157 | CONFIGFS_ATTR_RO(target_stat_auth_, creation_time); |
| 1158 | CONFIGFS_ATTR_RO(target_stat_auth_, row_status); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1159 | |
| 1160 | static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1175 | NULL, |
| 1176 | }; |
| 1177 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 1178 | static const struct config_item_type target_stat_scsi_auth_intr_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1187 | static struct se_lun_acl *iport_to_lacl(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1188 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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 | |
| 1194 | static 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); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1203 | rcu_read_lock(); |
| 1204 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1205 | if (!deve) { |
| 1206 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1207 | return -ENODEV; |
| 1208 | } |
| 1209 | tpg = nacl->se_tpg; |
| 1210 | /* scsiInstIndex */ |
| 1211 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1212 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1213 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1214 | return ret; |
| 1215 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1216 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1217 | static ssize_t target_stat_iport_dev_show(struct config_item *item, |
| 1218 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1219 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1220 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1221 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1222 | struct se_dev_entry *deve; |
| 1223 | struct se_lun *lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1224 | ssize_t ret; |
| 1225 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1226 | rcu_read_lock(); |
| 1227 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1228 | if (!deve) { |
| 1229 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1230 | return -ENODEV; |
| 1231 | } |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1232 | lun = rcu_dereference(deve->se_lun); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1233 | /* scsiDeviceIndex */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1234 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); |
| 1235 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1236 | return ret; |
| 1237 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1238 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1239 | static ssize_t target_stat_iport_port_show(struct config_item *item, |
| 1240 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1241 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1242 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1248 | rcu_read_lock(); |
| 1249 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1250 | if (!deve) { |
| 1251 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1252 | return -ENODEV; |
| 1253 | } |
| 1254 | tpg = nacl->se_tpg; |
| 1255 | /* scsiPortIndex */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1256 | ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1257 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1258 | return ret; |
| 1259 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1260 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1261 | static ssize_t target_stat_iport_indx_show(struct config_item *item, |
| 1262 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1263 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1264 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1280 | tpg->se_tpg_tfo->sess_get_index(se_sess)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1281 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1282 | return ret; |
| 1283 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1284 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1285 | static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item, |
| 1286 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1287 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1288 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1289 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1290 | struct se_dev_entry *deve; |
| 1291 | ssize_t ret; |
| 1292 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1293 | rcu_read_lock(); |
| 1294 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1295 | if (!deve) { |
| 1296 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1297 | return -ENODEV; |
| 1298 | } |
| 1299 | /* scsiAttIntrPortAuthIntrIdx */ |
| 1300 | ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1301 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1302 | return ret; |
| 1303 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1304 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1305 | static ssize_t target_stat_iport_port_ident_show(struct config_item *item, |
| 1306 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1307 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1308 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1325 | if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 1326 | tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1332 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1333 | CONFIGFS_ATTR_RO(target_stat_iport_, inst); |
| 1334 | CONFIGFS_ATTR_RO(target_stat_iport_, dev); |
| 1335 | CONFIGFS_ATTR_RO(target_stat_iport_, port); |
| 1336 | CONFIGFS_ATTR_RO(target_stat_iport_, indx); |
| 1337 | CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx); |
| 1338 | CONFIGFS_ATTR_RO(target_stat_iport_, port_ident); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1339 | |
| 1340 | static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 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, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1347 | NULL, |
| 1348 | }; |
| 1349 | |
Bhumika Goyal | ece550b | 2017-10-16 17:18:42 +0200 | [diff] [blame] | 1350 | static const struct config_item_type target_stat_scsi_att_intr_port_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 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 | */ |
| 1359 | void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl) |
| 1360 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1361 | config_group_init_type_name(&lacl->ml_stat_grps.scsi_auth_intr_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1362 | "scsi_auth_intr", &target_stat_scsi_auth_intr_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1363 | configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group, |
| 1364 | &lacl->ml_stat_grps.stat_group); |
| 1365 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1366 | config_group_init_type_name(&lacl->ml_stat_grps.scsi_att_intr_port_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1367 | "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1368 | configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group, |
| 1369 | &lacl->ml_stat_grps.stat_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1370 | } |