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 | |
| 548 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 549 | dev = lun->lun_se_dev; |
| 550 | if (dev) |
| 551 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->se_hba->hba_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 552 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 564 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 565 | dev = lun->lun_se_dev; |
| 566 | if (dev) |
| 567 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 568 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 580 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 581 | dev = lun->lun_se_dev; |
| 582 | if (dev) |
| 583 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 584 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 596 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 597 | dev = lun->lun_se_dev; |
| 598 | if (dev) |
| 599 | ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 600 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 612 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 613 | dev = lun->lun_se_dev; |
| 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 | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 618 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 669 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 670 | dev = lun->lun_se_dev; |
| 671 | if (dev) |
| 672 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->se_hba->hba_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 673 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 685 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 686 | dev = lun->lun_se_dev; |
| 687 | if (dev) |
| 688 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 689 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 701 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 702 | dev = lun->lun_se_dev; |
| 703 | if (dev) |
| 704 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 705 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 718 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 719 | dev = lun->lun_se_dev; |
| 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 | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 724 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 737 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 738 | dev = lun->lun_se_dev; |
| 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 | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 743 | spin_unlock(&lun->lun_sep_lock); |
| 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 | |
| 755 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 756 | dev = lun->lun_se_dev; |
| 757 | if (dev) |
| 758 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_stats.cmd_pdus); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 759 | spin_unlock(&lun->lun_sep_lock); |
| 760 | return ret; |
| 761 | } |
| 762 | DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds); |
| 763 | |
| 764 | static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes( |
| 765 | struct se_port_stat_grps *pgrps, char *page) |
| 766 | { |
| 767 | 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^] | 768 | struct se_device *dev; |
| 769 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 770 | |
| 771 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 772 | dev = lun->lun_se_dev; |
| 773 | if (dev) |
| 774 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 775 | (u32)(lun->lun_stats.rx_data_octets >> 20)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 776 | spin_unlock(&lun->lun_sep_lock); |
| 777 | return ret; |
| 778 | } |
| 779 | DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes); |
| 780 | |
| 781 | static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes( |
| 782 | struct se_port_stat_grps *pgrps, char *page) |
| 783 | { |
| 784 | 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^] | 785 | struct se_device *dev; |
| 786 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 787 | |
| 788 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 789 | dev = lun->lun_se_dev; |
| 790 | if (dev) |
| 791 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 792 | (u32)(lun->lun_stats.tx_data_octets >> 20)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 793 | spin_unlock(&lun->lun_sep_lock); |
| 794 | return ret; |
| 795 | } |
| 796 | DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes); |
| 797 | |
| 798 | static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds( |
| 799 | struct se_port_stat_grps *pgrps, char *page) |
| 800 | { |
| 801 | 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^] | 802 | struct se_device *dev; |
| 803 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 804 | |
| 805 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 806 | dev = lun->lun_se_dev; |
| 807 | if (dev) { |
| 808 | /* FIXME: scsiTgtPortHsInCommands */ |
| 809 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 810 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 811 | spin_unlock(&lun->lun_sep_lock); |
| 812 | return ret; |
| 813 | } |
| 814 | DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds); |
| 815 | |
| 816 | CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps, |
| 817 | scsi_tgt_port_group); |
| 818 | |
| 819 | static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = { |
| 820 | &target_stat_scsi_tgt_port_inst.attr, |
| 821 | &target_stat_scsi_tgt_port_dev.attr, |
| 822 | &target_stat_scsi_tgt_port_indx.attr, |
| 823 | &target_stat_scsi_tgt_port_name.attr, |
| 824 | &target_stat_scsi_tgt_port_port_index.attr, |
| 825 | &target_stat_scsi_tgt_port_in_cmds.attr, |
| 826 | &target_stat_scsi_tgt_port_write_mbytes.attr, |
| 827 | &target_stat_scsi_tgt_port_read_mbytes.attr, |
| 828 | &target_stat_scsi_tgt_port_hs_in_cmds.attr, |
| 829 | NULL, |
| 830 | }; |
| 831 | |
| 832 | static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = { |
| 833 | .show_attribute = target_stat_scsi_tgt_port_attr_show, |
| 834 | .store_attribute = target_stat_scsi_tgt_port_attr_store, |
| 835 | }; |
| 836 | |
| 837 | static struct config_item_type target_stat_scsi_tgt_port_cit = { |
| 838 | .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops, |
| 839 | .ct_attrs = target_stat_scsi_tgt_port_attrs, |
| 840 | .ct_owner = THIS_MODULE, |
| 841 | }; |
| 842 | |
| 843 | /* |
| 844 | * SCSI Transport Table |
| 845 | o */ |
| 846 | |
| 847 | CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps); |
| 848 | #define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \ |
| 849 | static struct target_stat_scsi_transport_attribute \ |
| 850 | target_stat_scsi_transport_##_name = \ |
| 851 | __CONFIGFS_EATTR(_name, _mode, \ |
| 852 | target_stat_scsi_transport_show_attr_##_name, \ |
| 853 | target_stat_scsi_transport_store_attr_##_name); |
| 854 | |
| 855 | #define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \ |
| 856 | static struct target_stat_scsi_transport_attribute \ |
| 857 | target_stat_scsi_transport_##_name = \ |
| 858 | __CONFIGFS_EATTR_RO(_name, \ |
| 859 | target_stat_scsi_transport_show_attr_##_name); |
| 860 | |
| 861 | static ssize_t target_stat_scsi_transport_show_attr_inst( |
| 862 | struct se_port_stat_grps *pgrps, char *page) |
| 863 | { |
| 864 | 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^] | 865 | struct se_device *dev; |
| 866 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 867 | |
| 868 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 869 | dev = lun->lun_se_dev; |
| 870 | if (dev) |
| 871 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->se_hba->hba_index); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 872 | spin_unlock(&lun->lun_sep_lock); |
| 873 | return ret; |
| 874 | } |
| 875 | DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst); |
| 876 | |
| 877 | static ssize_t target_stat_scsi_transport_show_attr_device( |
| 878 | struct se_port_stat_grps *pgrps, char *page) |
| 879 | { |
| 880 | 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^] | 881 | struct se_device *dev; |
| 882 | struct se_portal_group *tpg = lun->lun_tpg; |
| 883 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 884 | |
| 885 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 886 | dev = lun->lun_se_dev; |
| 887 | if (dev) { |
| 888 | /* scsiTransportType */ |
| 889 | ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", |
| 890 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 891 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 892 | spin_unlock(&lun->lun_sep_lock); |
| 893 | return ret; |
| 894 | } |
| 895 | DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device); |
| 896 | |
| 897 | static ssize_t target_stat_scsi_transport_show_attr_indx( |
| 898 | struct se_port_stat_grps *pgrps, char *page) |
| 899 | { |
| 900 | 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^] | 901 | struct se_device *dev; |
| 902 | struct se_portal_group *tpg = lun->lun_tpg; |
| 903 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 904 | |
| 905 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 906 | dev = lun->lun_se_dev; |
| 907 | if (dev) |
| 908 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 909 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 910 | spin_unlock(&lun->lun_sep_lock); |
| 911 | return ret; |
| 912 | } |
| 913 | DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx); |
| 914 | |
| 915 | static ssize_t target_stat_scsi_transport_show_attr_dev_name( |
| 916 | struct se_port_stat_grps *pgrps, char *page) |
| 917 | { |
| 918 | struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); |
| 919 | struct se_device *dev = lun->lun_se_dev; |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 920 | struct se_portal_group *tpg = lun->lun_tpg; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 921 | struct t10_wwn *wwn; |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 922 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 923 | |
| 924 | spin_lock(&lun->lun_sep_lock); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame^] | 925 | dev = lun->lun_se_dev; |
| 926 | if (dev) { |
| 927 | wwn = &dev->t10_wwn; |
| 928 | /* scsiTransportDevName */ |
| 929 | ret = snprintf(page, PAGE_SIZE, "%s+%s\n", |
| 930 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 931 | (strlen(wwn->unit_serial)) ? wwn->unit_serial : |
| 932 | wwn->vendor); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 933 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 934 | spin_unlock(&lun->lun_sep_lock); |
| 935 | return ret; |
| 936 | } |
| 937 | DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name); |
| 938 | |
| 939 | CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps, |
| 940 | scsi_transport_group); |
| 941 | |
| 942 | static struct configfs_attribute *target_stat_scsi_transport_attrs[] = { |
| 943 | &target_stat_scsi_transport_inst.attr, |
| 944 | &target_stat_scsi_transport_device.attr, |
| 945 | &target_stat_scsi_transport_indx.attr, |
| 946 | &target_stat_scsi_transport_dev_name.attr, |
| 947 | NULL, |
| 948 | }; |
| 949 | |
| 950 | static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = { |
| 951 | .show_attribute = target_stat_scsi_transport_attr_show, |
| 952 | .store_attribute = target_stat_scsi_transport_attr_store, |
| 953 | }; |
| 954 | |
| 955 | static struct config_item_type target_stat_scsi_transport_cit = { |
| 956 | .ct_item_ops = &target_stat_scsi_transport_attrib_ops, |
| 957 | .ct_attrs = target_stat_scsi_transport_attrs, |
| 958 | .ct_owner = THIS_MODULE, |
| 959 | }; |
| 960 | |
| 961 | /* |
| 962 | * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup |
| 963 | * the target port statistics groups + configfs CITs located in target_core_stat.c |
| 964 | */ |
| 965 | void target_stat_setup_port_default_groups(struct se_lun *lun) |
| 966 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 967 | struct config_group *port_stat_grp = &lun->port_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 968 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 969 | config_group_init_type_name(&lun->port_stat_grps.scsi_port_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 970 | "scsi_port", &target_stat_scsi_port_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 971 | 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] | 972 | "scsi_tgt_port", &target_stat_scsi_tgt_port_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 973 | config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 974 | "scsi_transport", &target_stat_scsi_transport_cit); |
| 975 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 976 | port_stat_grp->default_groups[0] = &lun->port_stat_grps.scsi_port_group; |
| 977 | port_stat_grp->default_groups[1] = &lun->port_stat_grps.scsi_tgt_port_group; |
| 978 | 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] | 979 | port_stat_grp->default_groups[3] = NULL; |
| 980 | } |
| 981 | |
| 982 | /* |
| 983 | * SCSI Authorized Initiator Table |
| 984 | */ |
| 985 | |
| 986 | CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps); |
| 987 | #define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \ |
| 988 | static struct target_stat_scsi_auth_intr_attribute \ |
| 989 | target_stat_scsi_auth_intr_##_name = \ |
| 990 | __CONFIGFS_EATTR(_name, _mode, \ |
| 991 | target_stat_scsi_auth_intr_show_attr_##_name, \ |
| 992 | target_stat_scsi_auth_intr_store_attr_##_name); |
| 993 | |
| 994 | #define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \ |
| 995 | static struct target_stat_scsi_auth_intr_attribute \ |
| 996 | target_stat_scsi_auth_intr_##_name = \ |
| 997 | __CONFIGFS_EATTR_RO(_name, \ |
| 998 | target_stat_scsi_auth_intr_show_attr_##_name); |
| 999 | |
| 1000 | static ssize_t target_stat_scsi_auth_intr_show_attr_inst( |
| 1001 | struct se_ml_stat_grps *lgrps, char *page) |
| 1002 | { |
| 1003 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1004 | struct se_lun_acl, ml_stat_grps); |
| 1005 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1006 | struct se_dev_entry *deve; |
| 1007 | struct se_portal_group *tpg; |
| 1008 | ssize_t ret; |
| 1009 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1010 | rcu_read_lock(); |
| 1011 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1012 | if (!deve) { |
| 1013 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1014 | return -ENODEV; |
| 1015 | } |
| 1016 | tpg = nacl->se_tpg; |
| 1017 | /* scsiInstIndex */ |
| 1018 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1019 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1020 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1021 | return ret; |
| 1022 | } |
| 1023 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst); |
| 1024 | |
| 1025 | static ssize_t target_stat_scsi_auth_intr_show_attr_dev( |
| 1026 | struct se_ml_stat_grps *lgrps, char *page) |
| 1027 | { |
| 1028 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1029 | struct se_lun_acl, ml_stat_grps); |
| 1030 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1031 | struct se_dev_entry *deve; |
| 1032 | struct se_lun *lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1033 | ssize_t ret; |
| 1034 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1035 | rcu_read_lock(); |
| 1036 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1037 | if (!deve) { |
| 1038 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1039 | return -ENODEV; |
| 1040 | } |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1041 | lun = rcu_dereference(deve->se_lun); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1042 | /* scsiDeviceIndex */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1043 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); |
| 1044 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1045 | return ret; |
| 1046 | } |
| 1047 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev); |
| 1048 | |
| 1049 | static ssize_t target_stat_scsi_auth_intr_show_attr_port( |
| 1050 | struct se_ml_stat_grps *lgrps, char *page) |
| 1051 | { |
| 1052 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1053 | struct se_lun_acl, ml_stat_grps); |
| 1054 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1055 | struct se_dev_entry *deve; |
| 1056 | struct se_portal_group *tpg; |
| 1057 | ssize_t ret; |
| 1058 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1059 | rcu_read_lock(); |
| 1060 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1061 | if (!deve) { |
| 1062 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1063 | return -ENODEV; |
| 1064 | } |
| 1065 | tpg = nacl->se_tpg; |
| 1066 | /* scsiAuthIntrTgtPortIndex */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1067 | 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] | 1068 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1069 | return ret; |
| 1070 | } |
| 1071 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port); |
| 1072 | |
| 1073 | static ssize_t target_stat_scsi_auth_intr_show_attr_indx( |
| 1074 | struct se_ml_stat_grps *lgrps, char *page) |
| 1075 | { |
| 1076 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1077 | struct se_lun_acl, ml_stat_grps); |
| 1078 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1079 | struct se_dev_entry *deve; |
| 1080 | ssize_t ret; |
| 1081 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1082 | rcu_read_lock(); |
| 1083 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1084 | if (!deve) { |
| 1085 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1086 | return -ENODEV; |
| 1087 | } |
| 1088 | /* scsiAuthIntrIndex */ |
| 1089 | ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1090 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
| 1093 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx); |
| 1094 | |
| 1095 | static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port( |
| 1096 | struct se_ml_stat_grps *lgrps, char *page) |
| 1097 | { |
| 1098 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1099 | struct se_lun_acl, ml_stat_grps); |
| 1100 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1101 | struct se_dev_entry *deve; |
| 1102 | ssize_t ret; |
| 1103 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1104 | rcu_read_lock(); |
| 1105 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1106 | if (!deve) { |
| 1107 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1108 | return -ENODEV; |
| 1109 | } |
| 1110 | /* scsiAuthIntrDevOrPort */ |
| 1111 | ret = snprintf(page, PAGE_SIZE, "%u\n", 1); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1112 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1113 | return ret; |
| 1114 | } |
| 1115 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port); |
| 1116 | |
| 1117 | static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name( |
| 1118 | struct se_ml_stat_grps *lgrps, char *page) |
| 1119 | { |
| 1120 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1121 | struct se_lun_acl, ml_stat_grps); |
| 1122 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1123 | struct se_dev_entry *deve; |
| 1124 | ssize_t ret; |
| 1125 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1126 | rcu_read_lock(); |
| 1127 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1128 | if (!deve) { |
| 1129 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1130 | return -ENODEV; |
| 1131 | } |
| 1132 | /* scsiAuthIntrName */ |
| 1133 | ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1134 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1135 | return ret; |
| 1136 | } |
| 1137 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name); |
| 1138 | |
| 1139 | static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx( |
| 1140 | struct se_ml_stat_grps *lgrps, char *page) |
| 1141 | { |
| 1142 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1143 | struct se_lun_acl, ml_stat_grps); |
| 1144 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1145 | struct se_dev_entry *deve; |
| 1146 | ssize_t ret; |
| 1147 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1148 | rcu_read_lock(); |
| 1149 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1150 | if (!deve) { |
| 1151 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1152 | return -ENODEV; |
| 1153 | } |
| 1154 | /* FIXME: scsiAuthIntrLunMapIndex */ |
| 1155 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1156 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1157 | return ret; |
| 1158 | } |
| 1159 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx); |
| 1160 | |
| 1161 | static ssize_t target_stat_scsi_auth_intr_show_attr_att_count( |
| 1162 | struct se_ml_stat_grps *lgrps, char *page) |
| 1163 | { |
| 1164 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1165 | struct se_lun_acl, ml_stat_grps); |
| 1166 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1167 | struct se_dev_entry *deve; |
| 1168 | ssize_t ret; |
| 1169 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1170 | rcu_read_lock(); |
| 1171 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1172 | if (!deve) { |
| 1173 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1174 | return -ENODEV; |
| 1175 | } |
| 1176 | /* scsiAuthIntrAttachedTimes */ |
| 1177 | ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1178 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1179 | return ret; |
| 1180 | } |
| 1181 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count); |
| 1182 | |
| 1183 | static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds( |
| 1184 | struct se_ml_stat_grps *lgrps, char *page) |
| 1185 | { |
| 1186 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1187 | struct se_lun_acl, ml_stat_grps); |
| 1188 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1189 | struct se_dev_entry *deve; |
| 1190 | ssize_t ret; |
| 1191 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1192 | rcu_read_lock(); |
| 1193 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1194 | if (!deve) { |
| 1195 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1196 | return -ENODEV; |
| 1197 | } |
| 1198 | /* scsiAuthIntrOutCommands */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1199 | ret = snprintf(page, PAGE_SIZE, "%lu\n", |
| 1200 | atomic_long_read(&deve->total_cmds)); |
| 1201 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1202 | return ret; |
| 1203 | } |
| 1204 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds); |
| 1205 | |
| 1206 | static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes( |
| 1207 | struct se_ml_stat_grps *lgrps, char *page) |
| 1208 | { |
| 1209 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1210 | struct se_lun_acl, ml_stat_grps); |
| 1211 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1212 | struct se_dev_entry *deve; |
| 1213 | ssize_t ret; |
| 1214 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1215 | rcu_read_lock(); |
| 1216 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1217 | if (!deve) { |
| 1218 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1219 | return -ENODEV; |
| 1220 | } |
| 1221 | /* scsiAuthIntrReadMegaBytes */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1222 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 1223 | (u32)(atomic_long_read(&deve->read_bytes) >> 20)); |
| 1224 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1225 | return ret; |
| 1226 | } |
| 1227 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes); |
| 1228 | |
| 1229 | static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes( |
| 1230 | struct se_ml_stat_grps *lgrps, char *page) |
| 1231 | { |
| 1232 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1233 | struct se_lun_acl, ml_stat_grps); |
| 1234 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1235 | struct se_dev_entry *deve; |
| 1236 | ssize_t ret; |
| 1237 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1238 | rcu_read_lock(); |
| 1239 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1240 | if (!deve) { |
| 1241 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1242 | return -ENODEV; |
| 1243 | } |
| 1244 | /* scsiAuthIntrWrittenMegaBytes */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1245 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 1246 | (u32)(atomic_long_read(&deve->write_bytes) >> 20)); |
| 1247 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1248 | return ret; |
| 1249 | } |
| 1250 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes); |
| 1251 | |
| 1252 | static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds( |
| 1253 | struct se_ml_stat_grps *lgrps, char *page) |
| 1254 | { |
| 1255 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1256 | struct se_lun_acl, ml_stat_grps); |
| 1257 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1258 | struct se_dev_entry *deve; |
| 1259 | ssize_t ret; |
| 1260 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1261 | rcu_read_lock(); |
| 1262 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1263 | if (!deve) { |
| 1264 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1265 | return -ENODEV; |
| 1266 | } |
| 1267 | /* FIXME: scsiAuthIntrHSOutCommands */ |
| 1268 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1269 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1270 | return ret; |
| 1271 | } |
| 1272 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds); |
| 1273 | |
| 1274 | static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time( |
| 1275 | struct se_ml_stat_grps *lgrps, char *page) |
| 1276 | { |
| 1277 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1278 | struct se_lun_acl, ml_stat_grps); |
| 1279 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1280 | struct se_dev_entry *deve; |
| 1281 | ssize_t ret; |
| 1282 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1283 | rcu_read_lock(); |
| 1284 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1285 | if (!deve) { |
| 1286 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1287 | return -ENODEV; |
| 1288 | } |
| 1289 | /* scsiAuthIntrLastCreation */ |
| 1290 | ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time - |
| 1291 | INITIAL_JIFFIES) * 100 / HZ)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1292 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1293 | return ret; |
| 1294 | } |
| 1295 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time); |
| 1296 | |
| 1297 | static ssize_t target_stat_scsi_auth_intr_show_attr_row_status( |
| 1298 | struct se_ml_stat_grps *lgrps, char *page) |
| 1299 | { |
| 1300 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1301 | struct se_lun_acl, ml_stat_grps); |
| 1302 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1303 | struct se_dev_entry *deve; |
| 1304 | ssize_t ret; |
| 1305 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1306 | rcu_read_lock(); |
| 1307 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1308 | if (!deve) { |
| 1309 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1310 | return -ENODEV; |
| 1311 | } |
| 1312 | /* FIXME: scsiAuthIntrRowStatus */ |
| 1313 | ret = snprintf(page, PAGE_SIZE, "Ready\n"); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1314 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1315 | return ret; |
| 1316 | } |
| 1317 | DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status); |
| 1318 | |
| 1319 | CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps, |
| 1320 | scsi_auth_intr_group); |
| 1321 | |
| 1322 | static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = { |
| 1323 | &target_stat_scsi_auth_intr_inst.attr, |
| 1324 | &target_stat_scsi_auth_intr_dev.attr, |
| 1325 | &target_stat_scsi_auth_intr_port.attr, |
| 1326 | &target_stat_scsi_auth_intr_indx.attr, |
| 1327 | &target_stat_scsi_auth_intr_dev_or_port.attr, |
| 1328 | &target_stat_scsi_auth_intr_intr_name.attr, |
| 1329 | &target_stat_scsi_auth_intr_map_indx.attr, |
| 1330 | &target_stat_scsi_auth_intr_att_count.attr, |
| 1331 | &target_stat_scsi_auth_intr_num_cmds.attr, |
| 1332 | &target_stat_scsi_auth_intr_read_mbytes.attr, |
| 1333 | &target_stat_scsi_auth_intr_write_mbytes.attr, |
| 1334 | &target_stat_scsi_auth_intr_hs_num_cmds.attr, |
| 1335 | &target_stat_scsi_auth_intr_creation_time.attr, |
| 1336 | &target_stat_scsi_auth_intr_row_status.attr, |
| 1337 | NULL, |
| 1338 | }; |
| 1339 | |
| 1340 | static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = { |
| 1341 | .show_attribute = target_stat_scsi_auth_intr_attr_show, |
| 1342 | .store_attribute = target_stat_scsi_auth_intr_attr_store, |
| 1343 | }; |
| 1344 | |
| 1345 | static struct config_item_type target_stat_scsi_auth_intr_cit = { |
| 1346 | .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops, |
| 1347 | .ct_attrs = target_stat_scsi_auth_intr_attrs, |
| 1348 | .ct_owner = THIS_MODULE, |
| 1349 | }; |
| 1350 | |
| 1351 | /* |
| 1352 | * SCSI Attached Initiator Port Table |
| 1353 | */ |
| 1354 | |
| 1355 | CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps); |
| 1356 | #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \ |
| 1357 | static struct target_stat_scsi_att_intr_port_attribute \ |
| 1358 | target_stat_scsi_att_intr_port_##_name = \ |
| 1359 | __CONFIGFS_EATTR(_name, _mode, \ |
| 1360 | target_stat_scsi_att_intr_port_show_attr_##_name, \ |
| 1361 | target_stat_scsi_att_intr_port_store_attr_##_name); |
| 1362 | |
| 1363 | #define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \ |
| 1364 | static struct target_stat_scsi_att_intr_port_attribute \ |
| 1365 | target_stat_scsi_att_intr_port_##_name = \ |
| 1366 | __CONFIGFS_EATTR_RO(_name, \ |
| 1367 | target_stat_scsi_att_intr_port_show_attr_##_name); |
| 1368 | |
| 1369 | static ssize_t target_stat_scsi_att_intr_port_show_attr_inst( |
| 1370 | struct se_ml_stat_grps *lgrps, char *page) |
| 1371 | { |
| 1372 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1373 | struct se_lun_acl, ml_stat_grps); |
| 1374 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1375 | struct se_dev_entry *deve; |
| 1376 | struct se_portal_group *tpg; |
| 1377 | ssize_t ret; |
| 1378 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1379 | rcu_read_lock(); |
| 1380 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1381 | if (!deve) { |
| 1382 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1383 | return -ENODEV; |
| 1384 | } |
| 1385 | tpg = nacl->se_tpg; |
| 1386 | /* scsiInstIndex */ |
| 1387 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1388 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1389 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1390 | return ret; |
| 1391 | } |
| 1392 | DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst); |
| 1393 | |
| 1394 | static ssize_t target_stat_scsi_att_intr_port_show_attr_dev( |
| 1395 | struct se_ml_stat_grps *lgrps, char *page) |
| 1396 | { |
| 1397 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1398 | struct se_lun_acl, ml_stat_grps); |
| 1399 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1400 | struct se_dev_entry *deve; |
| 1401 | struct se_lun *lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1402 | ssize_t ret; |
| 1403 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1404 | rcu_read_lock(); |
| 1405 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1406 | if (!deve) { |
| 1407 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1408 | return -ENODEV; |
| 1409 | } |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1410 | lun = rcu_dereference(deve->se_lun); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1411 | /* scsiDeviceIndex */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1412 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); |
| 1413 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1414 | return ret; |
| 1415 | } |
| 1416 | DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev); |
| 1417 | |
| 1418 | static ssize_t target_stat_scsi_att_intr_port_show_attr_port( |
| 1419 | struct se_ml_stat_grps *lgrps, char *page) |
| 1420 | { |
| 1421 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1422 | struct se_lun_acl, ml_stat_grps); |
| 1423 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1424 | struct se_dev_entry *deve; |
| 1425 | struct se_portal_group *tpg; |
| 1426 | ssize_t ret; |
| 1427 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1428 | rcu_read_lock(); |
| 1429 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1430 | if (!deve) { |
| 1431 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1432 | return -ENODEV; |
| 1433 | } |
| 1434 | tpg = nacl->se_tpg; |
| 1435 | /* scsiPortIndex */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1436 | 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] | 1437 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1438 | return ret; |
| 1439 | } |
| 1440 | DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port); |
| 1441 | |
| 1442 | static ssize_t target_stat_scsi_att_intr_port_show_attr_indx( |
| 1443 | struct se_ml_stat_grps *lgrps, char *page) |
| 1444 | { |
| 1445 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1446 | struct se_lun_acl, ml_stat_grps); |
| 1447 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1448 | struct se_session *se_sess; |
| 1449 | struct se_portal_group *tpg; |
| 1450 | ssize_t ret; |
| 1451 | |
| 1452 | spin_lock_irq(&nacl->nacl_sess_lock); |
| 1453 | se_sess = nacl->nacl_sess; |
| 1454 | if (!se_sess) { |
| 1455 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1456 | return -ENODEV; |
| 1457 | } |
| 1458 | |
| 1459 | tpg = nacl->se_tpg; |
| 1460 | /* scsiAttIntrPortIndex */ |
| 1461 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1462 | tpg->se_tpg_tfo->sess_get_index(se_sess)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1463 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1464 | return ret; |
| 1465 | } |
| 1466 | DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx); |
| 1467 | |
| 1468 | static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx( |
| 1469 | struct se_ml_stat_grps *lgrps, char *page) |
| 1470 | { |
| 1471 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1472 | struct se_lun_acl, ml_stat_grps); |
| 1473 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1474 | struct se_dev_entry *deve; |
| 1475 | ssize_t ret; |
| 1476 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1477 | rcu_read_lock(); |
| 1478 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1479 | if (!deve) { |
| 1480 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1481 | return -ENODEV; |
| 1482 | } |
| 1483 | /* scsiAttIntrPortAuthIntrIdx */ |
| 1484 | ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1485 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1486 | return ret; |
| 1487 | } |
| 1488 | DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx); |
| 1489 | |
| 1490 | static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident( |
| 1491 | struct se_ml_stat_grps *lgrps, char *page) |
| 1492 | { |
| 1493 | struct se_lun_acl *lacl = container_of(lgrps, |
| 1494 | struct se_lun_acl, ml_stat_grps); |
| 1495 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1496 | struct se_session *se_sess; |
| 1497 | struct se_portal_group *tpg; |
| 1498 | ssize_t ret; |
| 1499 | unsigned char buf[64]; |
| 1500 | |
| 1501 | spin_lock_irq(&nacl->nacl_sess_lock); |
| 1502 | se_sess = nacl->nacl_sess; |
| 1503 | if (!se_sess) { |
| 1504 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1505 | return -ENODEV; |
| 1506 | } |
| 1507 | |
| 1508 | tpg = nacl->se_tpg; |
| 1509 | /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */ |
| 1510 | memset(buf, 0, 64); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1511 | if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 1512 | tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1513 | |
| 1514 | ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf); |
| 1515 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1516 | return ret; |
| 1517 | } |
| 1518 | DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident); |
| 1519 | |
| 1520 | CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps, |
| 1521 | scsi_att_intr_port_group); |
| 1522 | |
| 1523 | static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = { |
| 1524 | &target_stat_scsi_att_intr_port_inst.attr, |
| 1525 | &target_stat_scsi_att_intr_port_dev.attr, |
| 1526 | &target_stat_scsi_att_intr_port_port.attr, |
| 1527 | &target_stat_scsi_att_intr_port_indx.attr, |
| 1528 | &target_stat_scsi_att_intr_port_port_auth_indx.attr, |
| 1529 | &target_stat_scsi_att_intr_port_port_ident.attr, |
| 1530 | NULL, |
| 1531 | }; |
| 1532 | |
| 1533 | static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = { |
| 1534 | .show_attribute = target_stat_scsi_att_intr_port_attr_show, |
| 1535 | .store_attribute = target_stat_scsi_att_intr_port_attr_store, |
| 1536 | }; |
| 1537 | |
| 1538 | static struct config_item_type target_stat_scsi_att_intr_port_cit = { |
| 1539 | .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops, |
| 1540 | .ct_attrs = target_stat_scsi_ath_intr_port_attrs, |
| 1541 | .ct_owner = THIS_MODULE, |
| 1542 | }; |
| 1543 | |
| 1544 | /* |
| 1545 | * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup |
| 1546 | * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c |
| 1547 | */ |
| 1548 | void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl) |
| 1549 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1550 | struct config_group *ml_stat_grp = &lacl->ml_stat_grps.stat_group; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1551 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1552 | 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] | 1553 | "scsi_auth_intr", &target_stat_scsi_auth_intr_cit); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1554 | 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] | 1555 | "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit); |
| 1556 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1557 | ml_stat_grp->default_groups[0] = &lacl->ml_stat_grps.scsi_auth_intr_group; |
| 1558 | 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] | 1559 | ml_stat_grp->default_groups[2] = NULL; |
| 1560 | } |