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