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