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 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 99 | static 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 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 196 | static 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 | int i; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 250 | char str[sizeof(dev->t10_wwn.vendor)+1]; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 251 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 252 | /* scsiLuVendorId */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 253 | for (i = 0; i < sizeof(dev->t10_wwn.vendor); i++) |
| 254 | str[i] = ISPRINT(dev->t10_wwn.vendor[i]) ? |
| 255 | dev->t10_wwn.vendor[i] : ' '; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 256 | str[i] = '\0'; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 257 | return snprintf(page, PAGE_SIZE, "%s\n", str); |
| 258 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 259 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 260 | 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] | 261 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 262 | struct se_device *dev = to_stat_lu_dev(item); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 263 | int i; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 264 | char str[sizeof(dev->t10_wwn.model)+1]; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 265 | |
| 266 | /* scsiLuProductId */ |
David Disseldorp | 8f90353 | 2015-11-27 18:37:47 +0100 | [diff] [blame] | 267 | for (i = 0; i < sizeof(dev->t10_wwn.model); i++) |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 268 | str[i] = ISPRINT(dev->t10_wwn.model[i]) ? |
| 269 | dev->t10_wwn.model[i] : ' '; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 270 | str[i] = '\0'; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 271 | return snprintf(page, PAGE_SIZE, "%s\n", str); |
| 272 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 273 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 274 | 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] | 275 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 276 | struct se_device *dev = to_stat_lu_dev(item); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 277 | int i; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 278 | char str[sizeof(dev->t10_wwn.revision)+1]; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 279 | |
| 280 | /* scsiLuRevisionId */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 281 | for (i = 0; i < sizeof(dev->t10_wwn.revision); i++) |
| 282 | str[i] = ISPRINT(dev->t10_wwn.revision[i]) ? |
| 283 | dev->t10_wwn.revision[i] : ' '; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 284 | str[i] = '\0'; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 285 | return snprintf(page, PAGE_SIZE, "%s\n", str); |
| 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_dev_type_show(struct config_item *item, char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 289 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 290 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 291 | |
| 292 | /* scsiLuPeripheralType */ |
| 293 | return snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 294 | dev->transport->get_device_type(dev)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 295 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 296 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 297 | 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] | 298 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 299 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 300 | |
| 301 | /* scsiLuStatus */ |
| 302 | return snprintf(page, PAGE_SIZE, "%s\n", |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 303 | (dev->export_count) ? "available" : "notavailable"); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 304 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 305 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 306 | static ssize_t target_stat_lu_state_bit_show(struct config_item *item, |
| 307 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 308 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 309 | /* scsiLuState */ |
| 310 | return snprintf(page, PAGE_SIZE, "exposed\n"); |
| 311 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 312 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 313 | static ssize_t target_stat_lu_num_cmds_show(struct config_item *item, |
| 314 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 315 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 316 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 317 | |
| 318 | /* scsiLuNumCommands */ |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 319 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 320 | atomic_long_read(&dev->num_cmds)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 321 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 322 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 323 | static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item, |
| 324 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 325 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 326 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 327 | |
| 328 | /* scsiLuReadMegaBytes */ |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 329 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 330 | atomic_long_read(&dev->read_bytes) >> 20); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 331 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 332 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 333 | static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item, |
| 334 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 335 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 336 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 337 | |
| 338 | /* scsiLuWrittenMegaBytes */ |
Nicholas Bellinger | ee48068 | 2013-11-13 18:34:55 -0800 | [diff] [blame] | 339 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 340 | atomic_long_read(&dev->write_bytes) >> 20); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 341 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 342 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 343 | 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] | 344 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 345 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 346 | |
| 347 | /* scsiLuInResets */ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 348 | return snprintf(page, PAGE_SIZE, "%lu\n", |
| 349 | atomic_long_read(&dev->num_resets)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 350 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 351 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 352 | static ssize_t target_stat_lu_full_stat_show(struct config_item *item, |
| 353 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 354 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 355 | /* FIXME: scsiLuOutTaskSetFullStatus */ |
| 356 | return snprintf(page, PAGE_SIZE, "%u\n", 0); |
| 357 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 358 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 359 | static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item, |
| 360 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 361 | { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 362 | /* FIXME: scsiLuHSInCommands */ |
| 363 | return snprintf(page, PAGE_SIZE, "%u\n", 0); |
| 364 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 365 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 366 | static ssize_t target_stat_lu_creation_time_show(struct config_item *item, |
| 367 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 368 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 369 | struct se_device *dev = to_stat_lu_dev(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 370 | |
| 371 | /* scsiLuCreationTime */ |
| 372 | return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time - |
| 373 | INITIAL_JIFFIES) * 100 / HZ)); |
| 374 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 375 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 376 | CONFIGFS_ATTR_RO(target_stat_lu_, inst); |
| 377 | CONFIGFS_ATTR_RO(target_stat_lu_, dev); |
| 378 | CONFIGFS_ATTR_RO(target_stat_lu_, indx); |
| 379 | CONFIGFS_ATTR_RO(target_stat_lu_, lun); |
| 380 | CONFIGFS_ATTR_RO(target_stat_lu_, lu_name); |
| 381 | CONFIGFS_ATTR_RO(target_stat_lu_, vend); |
| 382 | CONFIGFS_ATTR_RO(target_stat_lu_, prod); |
| 383 | CONFIGFS_ATTR_RO(target_stat_lu_, rev); |
| 384 | CONFIGFS_ATTR_RO(target_stat_lu_, dev_type); |
| 385 | CONFIGFS_ATTR_RO(target_stat_lu_, status); |
| 386 | CONFIGFS_ATTR_RO(target_stat_lu_, state_bit); |
| 387 | CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds); |
| 388 | CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes); |
| 389 | CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes); |
| 390 | CONFIGFS_ATTR_RO(target_stat_lu_, resets); |
| 391 | CONFIGFS_ATTR_RO(target_stat_lu_, full_stat); |
| 392 | CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds); |
| 393 | CONFIGFS_ATTR_RO(target_stat_lu_, creation_time); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 394 | |
| 395 | static struct configfs_attribute *target_stat_scsi_lu_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 396 | &target_stat_lu_attr_inst, |
| 397 | &target_stat_lu_attr_dev, |
| 398 | &target_stat_lu_attr_indx, |
| 399 | &target_stat_lu_attr_lun, |
| 400 | &target_stat_lu_attr_lu_name, |
| 401 | &target_stat_lu_attr_vend, |
| 402 | &target_stat_lu_attr_prod, |
| 403 | &target_stat_lu_attr_rev, |
| 404 | &target_stat_lu_attr_dev_type, |
| 405 | &target_stat_lu_attr_status, |
| 406 | &target_stat_lu_attr_state_bit, |
| 407 | &target_stat_lu_attr_num_cmds, |
| 408 | &target_stat_lu_attr_read_mbytes, |
| 409 | &target_stat_lu_attr_write_mbytes, |
| 410 | &target_stat_lu_attr_resets, |
| 411 | &target_stat_lu_attr_full_stat, |
| 412 | &target_stat_lu_attr_hs_num_cmds, |
| 413 | &target_stat_lu_attr_creation_time, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 414 | NULL, |
| 415 | }; |
| 416 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 417 | static struct config_item_type target_stat_scsi_lu_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 418 | .ct_attrs = target_stat_scsi_lu_attrs, |
| 419 | .ct_owner = THIS_MODULE, |
| 420 | }; |
| 421 | |
| 422 | /* |
| 423 | * Called from target_core_configfs.c:target_core_make_subdev() to setup |
| 424 | * the target statistics groups + configfs CITs located in target_core_stat.c |
| 425 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 426 | void target_stat_setup_dev_default_groups(struct se_device *dev) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 427 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 428 | config_group_init_type_name(&dev->dev_stat_grps.scsi_dev_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 429 | "scsi_dev", &target_stat_scsi_dev_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 430 | configfs_add_default_group(&dev->dev_stat_grps.scsi_dev_group, |
| 431 | &dev->dev_stat_grps.stat_group); |
| 432 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 433 | 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] | 434 | "scsi_tgt_dev", &target_stat_scsi_tgt_dev_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 435 | configfs_add_default_group(&dev->dev_stat_grps.scsi_tgt_dev_group, |
| 436 | &dev->dev_stat_grps.stat_group); |
| 437 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 438 | config_group_init_type_name(&dev->dev_stat_grps.scsi_lu_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 439 | "scsi_lu", &target_stat_scsi_lu_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 440 | configfs_add_default_group(&dev->dev_stat_grps.scsi_lu_group, |
| 441 | &dev->dev_stat_grps.stat_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 442 | } |
| 443 | |
| 444 | /* |
| 445 | * SCSI Port Table |
| 446 | */ |
| 447 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 448 | static struct se_lun *to_stat_port(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 449 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 450 | struct se_port_stat_grps *pgrps = container_of(to_config_group(item), |
| 451 | struct se_port_stat_grps, scsi_port_group); |
| 452 | return container_of(pgrps, struct se_lun, port_stat_grps); |
| 453 | } |
| 454 | |
| 455 | static ssize_t target_stat_port_inst_show(struct config_item *item, char *page) |
| 456 | { |
| 457 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 458 | struct se_device *dev; |
| 459 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 460 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 461 | rcu_read_lock(); |
| 462 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 463 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 464 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); |
| 465 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 466 | return ret; |
| 467 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 468 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 469 | 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] | 470 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 471 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 472 | struct se_device *dev; |
| 473 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 474 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 475 | rcu_read_lock(); |
| 476 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 477 | if (dev) |
| 478 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 479 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 480 | return ret; |
| 481 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 482 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 483 | 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] | 484 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 485 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 486 | struct se_device *dev; |
| 487 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 488 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 489 | rcu_read_lock(); |
| 490 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 491 | if (dev) |
| 492 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_rtpi); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 493 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 494 | return ret; |
| 495 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 496 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 497 | 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] | 498 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 499 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 500 | struct se_device *dev; |
| 501 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 502 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 503 | rcu_read_lock(); |
| 504 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 505 | if (dev) |
| 506 | ret = snprintf(page, PAGE_SIZE, "%s%u\n", "Device", dev->dev_index); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 507 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 508 | return ret; |
| 509 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 510 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 511 | static ssize_t target_stat_port_busy_count_show(struct config_item *item, |
| 512 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 513 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 514 | struct se_lun *lun = to_stat_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 515 | struct se_device *dev; |
| 516 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 517 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 518 | rcu_read_lock(); |
| 519 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 520 | if (dev) { |
| 521 | /* FIXME: scsiPortBusyStatuses */ |
| 522 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 523 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 524 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 525 | return ret; |
| 526 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 527 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 528 | CONFIGFS_ATTR_RO(target_stat_port_, inst); |
| 529 | CONFIGFS_ATTR_RO(target_stat_port_, dev); |
| 530 | CONFIGFS_ATTR_RO(target_stat_port_, indx); |
| 531 | CONFIGFS_ATTR_RO(target_stat_port_, role); |
| 532 | CONFIGFS_ATTR_RO(target_stat_port_, busy_count); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 533 | |
| 534 | static struct configfs_attribute *target_stat_scsi_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 535 | &target_stat_port_attr_inst, |
| 536 | &target_stat_port_attr_dev, |
| 537 | &target_stat_port_attr_indx, |
| 538 | &target_stat_port_attr_role, |
| 539 | &target_stat_port_attr_busy_count, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 540 | NULL, |
| 541 | }; |
| 542 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 543 | static struct config_item_type target_stat_scsi_port_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 544 | .ct_attrs = target_stat_scsi_port_attrs, |
| 545 | .ct_owner = THIS_MODULE, |
| 546 | }; |
| 547 | |
| 548 | /* |
| 549 | * SCSI Target Port Table |
| 550 | */ |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 551 | static struct se_lun *to_stat_tgt_port(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 552 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 553 | struct se_port_stat_grps *pgrps = container_of(to_config_group(item), |
| 554 | struct se_port_stat_grps, scsi_tgt_port_group); |
| 555 | return container_of(pgrps, struct se_lun, port_stat_grps); |
| 556 | } |
| 557 | |
| 558 | static ssize_t target_stat_tgt_port_inst_show(struct config_item *item, |
| 559 | char *page) |
| 560 | { |
| 561 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 562 | struct se_device *dev; |
| 563 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 564 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 565 | rcu_read_lock(); |
| 566 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 567 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 568 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); |
| 569 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 570 | return ret; |
| 571 | } |
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 | static ssize_t target_stat_tgt_port_dev_show(struct config_item *item, |
| 574 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 575 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 576 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 577 | struct se_device *dev; |
| 578 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 579 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 580 | rcu_read_lock(); |
| 581 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 582 | if (dev) |
| 583 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 584 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 585 | return ret; |
| 586 | } |
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 | static ssize_t target_stat_tgt_port_indx_show(struct config_item *item, |
| 589 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 590 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 591 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 592 | struct se_device *dev; |
| 593 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 594 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 595 | rcu_read_lock(); |
| 596 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 597 | if (dev) |
| 598 | ret = snprintf(page, PAGE_SIZE, "%u\n", 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_name_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, "%sPort#%u\n", |
| 615 | tpg->se_tpg_tfo->get_fabric_name(), |
| 616 | lun->lun_rtpi); |
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_port_index_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_portal_group *tpg = lun->lun_tpg; |
| 626 | struct se_device *dev; |
| 627 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 628 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 629 | rcu_read_lock(); |
| 630 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 631 | if (dev) |
| 632 | ret = snprintf(page, PAGE_SIZE, "%s%s%d\n", |
| 633 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), "+t+", |
| 634 | tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 635 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 636 | return ret; |
| 637 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 638 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 639 | static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item, |
| 640 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 641 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 642 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 643 | struct se_device *dev; |
| 644 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 645 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 646 | rcu_read_lock(); |
| 647 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 648 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 649 | ret = snprintf(page, PAGE_SIZE, "%lu\n", |
| 650 | atomic_long_read(&lun->lun_stats.cmd_pdus)); |
| 651 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 652 | return ret; |
| 653 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 654 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 655 | static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item, |
| 656 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 657 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 658 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 659 | struct se_device *dev; |
| 660 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 661 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 662 | rcu_read_lock(); |
| 663 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 664 | if (dev) |
| 665 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 666 | (u32)(atomic_long_read(&lun->lun_stats.rx_data_octets) >> 20)); |
| 667 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 668 | return ret; |
| 669 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 670 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 671 | static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item, |
| 672 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 673 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 674 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 675 | struct se_device *dev; |
| 676 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 677 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 678 | rcu_read_lock(); |
| 679 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 680 | if (dev) |
| 681 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 682 | (u32)(atomic_long_read(&lun->lun_stats.tx_data_octets) >> 20)); |
| 683 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 684 | return ret; |
| 685 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 686 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 687 | static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item, |
| 688 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 689 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 690 | struct se_lun *lun = to_stat_tgt_port(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 691 | struct se_device *dev; |
| 692 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 693 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 694 | rcu_read_lock(); |
| 695 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 696 | if (dev) { |
| 697 | /* FIXME: scsiTgtPortHsInCommands */ |
| 698 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 699 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 700 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 701 | return ret; |
| 702 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 703 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 704 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst); |
| 705 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev); |
| 706 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx); |
| 707 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, name); |
| 708 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index); |
| 709 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds); |
| 710 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes); |
| 711 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes); |
| 712 | CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 713 | |
| 714 | static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 715 | &target_stat_tgt_port_attr_inst, |
| 716 | &target_stat_tgt_port_attr_dev, |
| 717 | &target_stat_tgt_port_attr_indx, |
| 718 | &target_stat_tgt_port_attr_name, |
| 719 | &target_stat_tgt_port_attr_port_index, |
| 720 | &target_stat_tgt_port_attr_in_cmds, |
| 721 | &target_stat_tgt_port_attr_write_mbytes, |
| 722 | &target_stat_tgt_port_attr_read_mbytes, |
| 723 | &target_stat_tgt_port_attr_hs_in_cmds, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 724 | NULL, |
| 725 | }; |
| 726 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 727 | static struct config_item_type target_stat_scsi_tgt_port_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 728 | .ct_attrs = target_stat_scsi_tgt_port_attrs, |
| 729 | .ct_owner = THIS_MODULE, |
| 730 | }; |
| 731 | |
| 732 | /* |
| 733 | * SCSI Transport Table |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 734 | */ |
| 735 | static struct se_lun *to_transport_stat(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 736 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 737 | struct se_port_stat_grps *pgrps = container_of(to_config_group(item), |
| 738 | struct se_port_stat_grps, scsi_transport_group); |
| 739 | return container_of(pgrps, struct se_lun, port_stat_grps); |
| 740 | } |
| 741 | |
| 742 | static ssize_t target_stat_transport_inst_show(struct config_item *item, |
| 743 | char *page) |
| 744 | { |
| 745 | struct se_lun *lun = to_transport_stat(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 746 | struct se_device *dev; |
| 747 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 748 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 749 | rcu_read_lock(); |
| 750 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 751 | if (dev) |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 752 | ret = snprintf(page, PAGE_SIZE, "%u\n", dev->hba_index); |
| 753 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 754 | return ret; |
| 755 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 756 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 757 | static ssize_t target_stat_transport_device_show(struct config_item *item, |
| 758 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 759 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 760 | struct se_lun *lun = to_transport_stat(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 761 | struct se_device *dev; |
| 762 | struct se_portal_group *tpg = lun->lun_tpg; |
| 763 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 764 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 765 | rcu_read_lock(); |
| 766 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 767 | if (dev) { |
| 768 | /* scsiTransportType */ |
| 769 | ret = snprintf(page, PAGE_SIZE, "scsiTransport%s\n", |
| 770 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 771 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 772 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 773 | return ret; |
| 774 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 775 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 776 | static ssize_t target_stat_transport_indx_show(struct config_item *item, |
| 777 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 778 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 779 | struct se_lun *lun = to_transport_stat(item); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 780 | struct se_device *dev; |
| 781 | struct se_portal_group *tpg = lun->lun_tpg; |
| 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 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 788 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 789 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 790 | return ret; |
| 791 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 792 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 793 | static ssize_t target_stat_transport_dev_name_show(struct config_item *item, |
| 794 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 795 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 796 | struct se_lun *lun = to_transport_stat(item); |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 797 | struct se_device *dev; |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 798 | struct se_portal_group *tpg = lun->lun_tpg; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 799 | struct t10_wwn *wwn; |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 800 | ssize_t ret = -ENODEV; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 801 | |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 802 | rcu_read_lock(); |
| 803 | dev = rcu_dereference(lun->lun_se_dev); |
Christoph Hellwig | adf653f | 2015-05-25 21:33:08 -0700 | [diff] [blame] | 804 | if (dev) { |
| 805 | wwn = &dev->t10_wwn; |
| 806 | /* scsiTransportDevName */ |
| 807 | ret = snprintf(page, PAGE_SIZE, "%s+%s\n", |
| 808 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 809 | (strlen(wwn->unit_serial)) ? wwn->unit_serial : |
| 810 | wwn->vendor); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 811 | } |
Nicholas Bellinger | 4cc987e | 2015-05-19 00:03:07 -0700 | [diff] [blame] | 812 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 813 | return ret; |
| 814 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 815 | |
Mike Christie | 0ab8ac6 | 2017-01-13 04:47:48 -0600 | [diff] [blame] | 816 | static ssize_t target_stat_transport_proto_id_show(struct config_item *item, |
| 817 | char *page) |
| 818 | { |
| 819 | struct se_lun *lun = to_transport_stat(item); |
| 820 | struct se_device *dev; |
| 821 | struct se_portal_group *tpg = lun->lun_tpg; |
| 822 | ssize_t ret = -ENODEV; |
| 823 | |
| 824 | rcu_read_lock(); |
| 825 | dev = rcu_dereference(lun->lun_se_dev); |
| 826 | if (dev) |
| 827 | ret = snprintf(page, PAGE_SIZE, "%u\n", tpg->proto_id); |
| 828 | rcu_read_unlock(); |
| 829 | return ret; |
| 830 | } |
| 831 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 832 | CONFIGFS_ATTR_RO(target_stat_transport_, inst); |
| 833 | CONFIGFS_ATTR_RO(target_stat_transport_, device); |
| 834 | CONFIGFS_ATTR_RO(target_stat_transport_, indx); |
| 835 | CONFIGFS_ATTR_RO(target_stat_transport_, dev_name); |
Mike Christie | 0ab8ac6 | 2017-01-13 04:47:48 -0600 | [diff] [blame] | 836 | CONFIGFS_ATTR_RO(target_stat_transport_, proto_id); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 837 | |
| 838 | static struct configfs_attribute *target_stat_scsi_transport_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 839 | &target_stat_transport_attr_inst, |
| 840 | &target_stat_transport_attr_device, |
| 841 | &target_stat_transport_attr_indx, |
| 842 | &target_stat_transport_attr_dev_name, |
Mike Christie | 0ab8ac6 | 2017-01-13 04:47:48 -0600 | [diff] [blame] | 843 | &target_stat_transport_attr_proto_id, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 844 | NULL, |
| 845 | }; |
| 846 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 847 | static struct config_item_type target_stat_scsi_transport_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 848 | .ct_attrs = target_stat_scsi_transport_attrs, |
| 849 | .ct_owner = THIS_MODULE, |
| 850 | }; |
| 851 | |
| 852 | /* |
| 853 | * Called from target_core_fabric_configfs.c:target_fabric_make_lun() to setup |
| 854 | * the target port statistics groups + configfs CITs located in target_core_stat.c |
| 855 | */ |
| 856 | void target_stat_setup_port_default_groups(struct se_lun *lun) |
| 857 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 858 | config_group_init_type_name(&lun->port_stat_grps.scsi_port_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 859 | "scsi_port", &target_stat_scsi_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 860 | configfs_add_default_group(&lun->port_stat_grps.scsi_port_group, |
| 861 | &lun->port_stat_grps.stat_group); |
| 862 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 863 | 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] | 864 | "scsi_tgt_port", &target_stat_scsi_tgt_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 865 | configfs_add_default_group(&lun->port_stat_grps.scsi_tgt_port_group, |
| 866 | &lun->port_stat_grps.stat_group); |
| 867 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 868 | config_group_init_type_name(&lun->port_stat_grps.scsi_transport_group, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 869 | "scsi_transport", &target_stat_scsi_transport_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 870 | configfs_add_default_group(&lun->port_stat_grps.scsi_transport_group, |
| 871 | &lun->port_stat_grps.stat_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /* |
| 875 | * SCSI Authorized Initiator Table |
| 876 | */ |
| 877 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 878 | static struct se_lun_acl *auth_to_lacl(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 879 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 880 | struct se_ml_stat_grps *lgrps = container_of(to_config_group(item), |
| 881 | struct se_ml_stat_grps, scsi_auth_intr_group); |
| 882 | return container_of(lgrps, struct se_lun_acl, ml_stat_grps); |
| 883 | } |
| 884 | |
| 885 | static ssize_t target_stat_auth_inst_show(struct config_item *item, |
| 886 | char *page) |
| 887 | { |
| 888 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 889 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 890 | struct se_dev_entry *deve; |
| 891 | struct se_portal_group *tpg; |
| 892 | ssize_t ret; |
| 893 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 894 | rcu_read_lock(); |
| 895 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 896 | if (!deve) { |
| 897 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 898 | return -ENODEV; |
| 899 | } |
| 900 | tpg = nacl->se_tpg; |
| 901 | /* scsiInstIndex */ |
| 902 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 903 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 904 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 905 | return ret; |
| 906 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 907 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 908 | static ssize_t target_stat_auth_dev_show(struct config_item *item, |
| 909 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 910 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 911 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 912 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 913 | struct se_dev_entry *deve; |
| 914 | struct se_lun *lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 915 | ssize_t ret; |
| 916 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 917 | rcu_read_lock(); |
| 918 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 919 | if (!deve) { |
| 920 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 921 | return -ENODEV; |
| 922 | } |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 923 | lun = rcu_dereference(deve->se_lun); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 924 | /* scsiDeviceIndex */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 925 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); |
| 926 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 927 | return ret; |
| 928 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 929 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 930 | static ssize_t target_stat_auth_port_show(struct config_item *item, |
| 931 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 932 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 933 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 934 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 935 | struct se_dev_entry *deve; |
| 936 | struct se_portal_group *tpg; |
| 937 | ssize_t ret; |
| 938 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 939 | rcu_read_lock(); |
| 940 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 941 | if (!deve) { |
| 942 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 943 | return -ENODEV; |
| 944 | } |
| 945 | tpg = nacl->se_tpg; |
| 946 | /* scsiAuthIntrTgtPortIndex */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 947 | 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] | 948 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 949 | return ret; |
| 950 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 951 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 952 | static ssize_t target_stat_auth_indx_show(struct config_item *item, |
| 953 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 954 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 955 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 956 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 957 | struct se_dev_entry *deve; |
| 958 | ssize_t ret; |
| 959 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 960 | rcu_read_lock(); |
| 961 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 962 | if (!deve) { |
| 963 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 964 | return -ENODEV; |
| 965 | } |
| 966 | /* scsiAuthIntrIndex */ |
| 967 | ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 968 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 969 | return ret; |
| 970 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 971 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 972 | static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item, |
| 973 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 974 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 975 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 976 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 977 | struct se_dev_entry *deve; |
| 978 | ssize_t ret; |
| 979 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 980 | rcu_read_lock(); |
| 981 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 982 | if (!deve) { |
| 983 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 984 | return -ENODEV; |
| 985 | } |
| 986 | /* scsiAuthIntrDevOrPort */ |
| 987 | ret = snprintf(page, PAGE_SIZE, "%u\n", 1); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 988 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 989 | return ret; |
| 990 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 991 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 992 | static ssize_t target_stat_auth_intr_name_show(struct config_item *item, |
| 993 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 994 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 995 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 996 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 997 | struct se_dev_entry *deve; |
| 998 | ssize_t ret; |
| 999 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1000 | rcu_read_lock(); |
| 1001 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1002 | if (!deve) { |
| 1003 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1004 | return -ENODEV; |
| 1005 | } |
| 1006 | /* scsiAuthIntrName */ |
| 1007 | ret = snprintf(page, PAGE_SIZE, "%s\n", nacl->initiatorname); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1008 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1009 | return ret; |
| 1010 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1011 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1012 | static ssize_t target_stat_auth_map_indx_show(struct config_item *item, |
| 1013 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1014 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1015 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1016 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1017 | struct se_dev_entry *deve; |
| 1018 | ssize_t ret; |
| 1019 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1020 | rcu_read_lock(); |
| 1021 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1022 | if (!deve) { |
| 1023 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1024 | return -ENODEV; |
| 1025 | } |
| 1026 | /* FIXME: scsiAuthIntrLunMapIndex */ |
| 1027 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1028 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1029 | return ret; |
| 1030 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1031 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1032 | static ssize_t target_stat_auth_att_count_show(struct config_item *item, |
| 1033 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1034 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1035 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1036 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1037 | struct se_dev_entry *deve; |
| 1038 | ssize_t ret; |
| 1039 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1040 | rcu_read_lock(); |
| 1041 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1042 | if (!deve) { |
| 1043 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1044 | return -ENODEV; |
| 1045 | } |
| 1046 | /* scsiAuthIntrAttachedTimes */ |
| 1047 | ret = snprintf(page, PAGE_SIZE, "%u\n", deve->attach_count); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1048 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1049 | return ret; |
| 1050 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1051 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1052 | static ssize_t target_stat_auth_num_cmds_show(struct config_item *item, |
| 1053 | char *page) |
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 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1056 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1057 | struct se_dev_entry *deve; |
| 1058 | ssize_t ret; |
| 1059 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1060 | rcu_read_lock(); |
| 1061 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1062 | if (!deve) { |
| 1063 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1064 | return -ENODEV; |
| 1065 | } |
| 1066 | /* scsiAuthIntrOutCommands */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1067 | ret = snprintf(page, PAGE_SIZE, "%lu\n", |
| 1068 | atomic_long_read(&deve->total_cmds)); |
| 1069 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1070 | return ret; |
| 1071 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1072 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1073 | static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item, |
| 1074 | char *page) |
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 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1077 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1078 | struct se_dev_entry *deve; |
| 1079 | ssize_t ret; |
| 1080 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1081 | rcu_read_lock(); |
| 1082 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1083 | if (!deve) { |
| 1084 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1085 | return -ENODEV; |
| 1086 | } |
| 1087 | /* scsiAuthIntrReadMegaBytes */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1088 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 1089 | (u32)(atomic_long_read(&deve->read_bytes) >> 20)); |
| 1090 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1091 | return ret; |
| 1092 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1093 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1094 | static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item, |
| 1095 | char *page) |
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 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1098 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1099 | struct se_dev_entry *deve; |
| 1100 | ssize_t ret; |
| 1101 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1102 | rcu_read_lock(); |
| 1103 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1104 | if (!deve) { |
| 1105 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1106 | return -ENODEV; |
| 1107 | } |
| 1108 | /* scsiAuthIntrWrittenMegaBytes */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1109 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
| 1110 | (u32)(atomic_long_read(&deve->write_bytes) >> 20)); |
| 1111 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1112 | return ret; |
| 1113 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1114 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1115 | static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item, |
| 1116 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1117 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1118 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1119 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1120 | struct se_dev_entry *deve; |
| 1121 | ssize_t ret; |
| 1122 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1123 | rcu_read_lock(); |
| 1124 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1125 | if (!deve) { |
| 1126 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1127 | return -ENODEV; |
| 1128 | } |
| 1129 | /* FIXME: scsiAuthIntrHSOutCommands */ |
| 1130 | ret = snprintf(page, PAGE_SIZE, "%u\n", 0); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1131 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1132 | return ret; |
| 1133 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1134 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1135 | static ssize_t target_stat_auth_creation_time_show(struct config_item *item, |
| 1136 | char *page) |
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 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1139 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1140 | struct se_dev_entry *deve; |
| 1141 | ssize_t ret; |
| 1142 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1143 | rcu_read_lock(); |
| 1144 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1145 | if (!deve) { |
| 1146 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1147 | return -ENODEV; |
| 1148 | } |
| 1149 | /* scsiAuthIntrLastCreation */ |
| 1150 | ret = snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)deve->creation_time - |
| 1151 | INITIAL_JIFFIES) * 100 / HZ)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1152 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1153 | return ret; |
| 1154 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1155 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1156 | static ssize_t target_stat_auth_row_status_show(struct config_item *item, |
| 1157 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1158 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1159 | struct se_lun_acl *lacl = auth_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1160 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1161 | struct se_dev_entry *deve; |
| 1162 | ssize_t ret; |
| 1163 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1164 | rcu_read_lock(); |
| 1165 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1166 | if (!deve) { |
| 1167 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1168 | return -ENODEV; |
| 1169 | } |
| 1170 | /* FIXME: scsiAuthIntrRowStatus */ |
| 1171 | ret = snprintf(page, PAGE_SIZE, "Ready\n"); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1172 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1173 | return ret; |
| 1174 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1175 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1176 | CONFIGFS_ATTR_RO(target_stat_auth_, inst); |
| 1177 | CONFIGFS_ATTR_RO(target_stat_auth_, dev); |
| 1178 | CONFIGFS_ATTR_RO(target_stat_auth_, port); |
| 1179 | CONFIGFS_ATTR_RO(target_stat_auth_, indx); |
| 1180 | CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port); |
| 1181 | CONFIGFS_ATTR_RO(target_stat_auth_, intr_name); |
| 1182 | CONFIGFS_ATTR_RO(target_stat_auth_, map_indx); |
| 1183 | CONFIGFS_ATTR_RO(target_stat_auth_, att_count); |
| 1184 | CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds); |
| 1185 | CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes); |
| 1186 | CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes); |
| 1187 | CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds); |
| 1188 | CONFIGFS_ATTR_RO(target_stat_auth_, creation_time); |
| 1189 | CONFIGFS_ATTR_RO(target_stat_auth_, row_status); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1190 | |
| 1191 | static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1192 | &target_stat_auth_attr_inst, |
| 1193 | &target_stat_auth_attr_dev, |
| 1194 | &target_stat_auth_attr_port, |
| 1195 | &target_stat_auth_attr_indx, |
| 1196 | &target_stat_auth_attr_dev_or_port, |
| 1197 | &target_stat_auth_attr_intr_name, |
| 1198 | &target_stat_auth_attr_map_indx, |
| 1199 | &target_stat_auth_attr_att_count, |
| 1200 | &target_stat_auth_attr_num_cmds, |
| 1201 | &target_stat_auth_attr_read_mbytes, |
| 1202 | &target_stat_auth_attr_write_mbytes, |
| 1203 | &target_stat_auth_attr_hs_num_cmds, |
| 1204 | &target_stat_auth_attr_creation_time, |
| 1205 | &target_stat_auth_attr_row_status, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1206 | NULL, |
| 1207 | }; |
| 1208 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1209 | static struct config_item_type target_stat_scsi_auth_intr_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1210 | .ct_attrs = target_stat_scsi_auth_intr_attrs, |
| 1211 | .ct_owner = THIS_MODULE, |
| 1212 | }; |
| 1213 | |
| 1214 | /* |
| 1215 | * SCSI Attached Initiator Port Table |
| 1216 | */ |
| 1217 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1218 | static struct se_lun_acl *iport_to_lacl(struct config_item *item) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1219 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1220 | struct se_ml_stat_grps *lgrps = container_of(to_config_group(item), |
| 1221 | struct se_ml_stat_grps, scsi_att_intr_port_group); |
| 1222 | return container_of(lgrps, struct se_lun_acl, ml_stat_grps); |
| 1223 | } |
| 1224 | |
| 1225 | static ssize_t target_stat_iport_inst_show(struct config_item *item, |
| 1226 | char *page) |
| 1227 | { |
| 1228 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1229 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1230 | struct se_dev_entry *deve; |
| 1231 | struct se_portal_group *tpg; |
| 1232 | ssize_t ret; |
| 1233 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1234 | rcu_read_lock(); |
| 1235 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1236 | if (!deve) { |
| 1237 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1238 | return -ENODEV; |
| 1239 | } |
| 1240 | tpg = nacl->se_tpg; |
| 1241 | /* scsiInstIndex */ |
| 1242 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1243 | tpg->se_tpg_tfo->tpg_get_inst_index(tpg)); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1244 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1245 | return ret; |
| 1246 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1247 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1248 | static ssize_t target_stat_iport_dev_show(struct config_item *item, |
| 1249 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1250 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1251 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1252 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1253 | struct se_dev_entry *deve; |
| 1254 | struct se_lun *lun; |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1255 | ssize_t ret; |
| 1256 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1257 | rcu_read_lock(); |
| 1258 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1259 | if (!deve) { |
| 1260 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1261 | return -ENODEV; |
| 1262 | } |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1263 | lun = rcu_dereference(deve->se_lun); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1264 | /* scsiDeviceIndex */ |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1265 | ret = snprintf(page, PAGE_SIZE, "%u\n", lun->lun_index); |
| 1266 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1267 | return ret; |
| 1268 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1269 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1270 | static ssize_t target_stat_iport_port_show(struct config_item *item, |
| 1271 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1272 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1273 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1274 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1275 | struct se_dev_entry *deve; |
| 1276 | struct se_portal_group *tpg; |
| 1277 | ssize_t ret; |
| 1278 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1279 | rcu_read_lock(); |
| 1280 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1281 | if (!deve) { |
| 1282 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1283 | return -ENODEV; |
| 1284 | } |
| 1285 | tpg = nacl->se_tpg; |
| 1286 | /* scsiPortIndex */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1287 | 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] | 1288 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1289 | return ret; |
| 1290 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1291 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1292 | static ssize_t target_stat_iport_indx_show(struct config_item *item, |
| 1293 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1294 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1295 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1296 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1297 | struct se_session *se_sess; |
| 1298 | struct se_portal_group *tpg; |
| 1299 | ssize_t ret; |
| 1300 | |
| 1301 | spin_lock_irq(&nacl->nacl_sess_lock); |
| 1302 | se_sess = nacl->nacl_sess; |
| 1303 | if (!se_sess) { |
| 1304 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1305 | return -ENODEV; |
| 1306 | } |
| 1307 | |
| 1308 | tpg = nacl->se_tpg; |
| 1309 | /* scsiAttIntrPortIndex */ |
| 1310 | ret = snprintf(page, PAGE_SIZE, "%u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1311 | tpg->se_tpg_tfo->sess_get_index(se_sess)); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1312 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1313 | return ret; |
| 1314 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1315 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1316 | static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item, |
| 1317 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1318 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1319 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1320 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1321 | struct se_dev_entry *deve; |
| 1322 | ssize_t ret; |
| 1323 | |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1324 | rcu_read_lock(); |
| 1325 | deve = target_nacl_find_deve(nacl, lacl->mapped_lun); |
| 1326 | if (!deve) { |
| 1327 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1328 | return -ENODEV; |
| 1329 | } |
| 1330 | /* scsiAttIntrPortAuthIntrIdx */ |
| 1331 | ret = snprintf(page, PAGE_SIZE, "%u\n", nacl->acl_index); |
Nicholas Bellinger | 29a05de | 2015-03-22 20:42:19 -0700 | [diff] [blame] | 1332 | rcu_read_unlock(); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1333 | return ret; |
| 1334 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1335 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1336 | static ssize_t target_stat_iport_port_ident_show(struct config_item *item, |
| 1337 | char *page) |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1338 | { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1339 | struct se_lun_acl *lacl = iport_to_lacl(item); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1340 | struct se_node_acl *nacl = lacl->se_lun_nacl; |
| 1341 | struct se_session *se_sess; |
| 1342 | struct se_portal_group *tpg; |
| 1343 | ssize_t ret; |
| 1344 | unsigned char buf[64]; |
| 1345 | |
| 1346 | spin_lock_irq(&nacl->nacl_sess_lock); |
| 1347 | se_sess = nacl->nacl_sess; |
| 1348 | if (!se_sess) { |
| 1349 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1350 | return -ENODEV; |
| 1351 | } |
| 1352 | |
| 1353 | tpg = nacl->se_tpg; |
| 1354 | /* scsiAttIntrPortName+scsiAttIntrPortIdentifier */ |
| 1355 | memset(buf, 0, 64); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1356 | if (tpg->se_tpg_tfo->sess_get_initiator_sid != NULL) |
Jörn Engel | 8359cf4 | 2011-11-24 02:05:51 +0100 | [diff] [blame] | 1357 | tpg->se_tpg_tfo->sess_get_initiator_sid(se_sess, buf, 64); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1358 | |
| 1359 | ret = snprintf(page, PAGE_SIZE, "%s+i+%s\n", nacl->initiatorname, buf); |
| 1360 | spin_unlock_irq(&nacl->nacl_sess_lock); |
| 1361 | return ret; |
| 1362 | } |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1363 | |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1364 | CONFIGFS_ATTR_RO(target_stat_iport_, inst); |
| 1365 | CONFIGFS_ATTR_RO(target_stat_iport_, dev); |
| 1366 | CONFIGFS_ATTR_RO(target_stat_iport_, port); |
| 1367 | CONFIGFS_ATTR_RO(target_stat_iport_, indx); |
| 1368 | CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx); |
| 1369 | CONFIGFS_ATTR_RO(target_stat_iport_, port_ident); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1370 | |
| 1371 | static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = { |
Christoph Hellwig | 2eafd72 | 2015-10-03 15:32:55 +0200 | [diff] [blame] | 1372 | &target_stat_iport_attr_inst, |
| 1373 | &target_stat_iport_attr_dev, |
| 1374 | &target_stat_iport_attr_port, |
| 1375 | &target_stat_iport_attr_indx, |
| 1376 | &target_stat_iport_attr_port_auth_indx, |
| 1377 | &target_stat_iport_attr_port_ident, |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1378 | NULL, |
| 1379 | }; |
| 1380 | |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1381 | static struct config_item_type target_stat_scsi_att_intr_port_cit = { |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1382 | .ct_attrs = target_stat_scsi_ath_intr_port_attrs, |
| 1383 | .ct_owner = THIS_MODULE, |
| 1384 | }; |
| 1385 | |
| 1386 | /* |
| 1387 | * Called from target_core_fabric_configfs.c:target_fabric_make_mappedlun() to setup |
| 1388 | * the target MappedLUN statistics groups + configfs CITs located in target_core_stat.c |
| 1389 | */ |
| 1390 | void target_stat_setup_mappedlun_default_groups(struct se_lun_acl *lacl) |
| 1391 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1392 | 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] | 1393 | "scsi_auth_intr", &target_stat_scsi_auth_intr_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1394 | configfs_add_default_group(&lacl->ml_stat_grps.scsi_auth_intr_group, |
| 1395 | &lacl->ml_stat_grps.stat_group); |
| 1396 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1397 | 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] | 1398 | "scsi_att_intr_port", &target_stat_scsi_att_intr_port_cit); |
Christoph Hellwig | 1ae1602 | 2016-02-26 11:02:14 +0100 | [diff] [blame] | 1399 | configfs_add_default_group(&lacl->ml_stat_grps.scsi_att_intr_port_group, |
| 1400 | &lacl->ml_stat_grps.stat_group); |
Nicholas Bellinger | 12d233842 | 2011-03-14 04:06:11 -0700 | [diff] [blame] | 1401 | } |