Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Filename: target_core_alua.c |
| 3 | * |
| 4 | * This file contains SPC-3 compliant asymmetric logical unit assigntment (ALUA) |
| 5 | * |
Nicholas Bellinger | 4c76251 | 2013-09-05 15:29:12 -0700 | [diff] [blame] | 6 | * (c) Copyright 2009-2013 Datera, Inc. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 7 | * |
| 8 | * Nicholas A. Bellinger <nab@kernel.org> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 23 | * |
| 24 | ******************************************************************************/ |
| 25 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 26 | #include <linux/slab.h> |
| 27 | #include <linux/spinlock.h> |
| 28 | #include <linux/configfs.h> |
Paul Gortmaker | c53181a | 2011-08-30 18:16:43 -0400 | [diff] [blame] | 29 | #include <linux/export.h> |
Al Viro | 0e9b10a | 2013-02-23 15:22:43 -0500 | [diff] [blame] | 30 | #include <linux/file.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 31 | #include <scsi/scsi.h> |
| 32 | #include <scsi/scsi_cmnd.h> |
Roland Dreier | 33395fb | 2012-02-23 17:22:12 -0800 | [diff] [blame] | 33 | #include <asm/unaligned.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 34 | |
| 35 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 36 | #include <target/target_core_backend.h> |
| 37 | #include <target/target_core_fabric.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 38 | #include <target/target_core_configfs.h> |
| 39 | |
Christoph Hellwig | e26d99a | 2011-11-14 12:30:30 -0500 | [diff] [blame] | 40 | #include "target_core_internal.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 41 | #include "target_core_alua.h" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 42 | #include "target_core_ua.h" |
| 43 | |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 44 | static sense_reason_t core_alua_check_transition(int state, int valid, |
| 45 | int *primary); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 46 | static int core_alua_set_tg_pt_secondary_state( |
| 47 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 48 | struct se_port *port, int explicit, int offline); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 49 | |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 50 | static char *core_alua_dump_state(int state); |
| 51 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 52 | static u16 alua_lu_gps_counter; |
| 53 | static u32 alua_lu_gps_count; |
| 54 | |
| 55 | static DEFINE_SPINLOCK(lu_gps_lock); |
| 56 | static LIST_HEAD(lu_gps_list); |
| 57 | |
| 58 | struct t10_alua_lu_gp *default_lu_gp; |
| 59 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 60 | /* |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 61 | * REPORT REFERRALS |
| 62 | * |
| 63 | * See sbc3r35 section 5.23 |
| 64 | */ |
| 65 | sense_reason_t |
| 66 | target_emulate_report_referrals(struct se_cmd *cmd) |
| 67 | { |
| 68 | struct se_device *dev = cmd->se_dev; |
| 69 | struct t10_alua_lba_map *map; |
| 70 | struct t10_alua_lba_map_member *map_mem; |
| 71 | unsigned char *buf; |
| 72 | u32 rd_len = 0, off; |
| 73 | |
| 74 | if (cmd->data_length < 4) { |
| 75 | pr_warn("REPORT REFERRALS allocation length %u too" |
| 76 | " small\n", cmd->data_length); |
| 77 | return TCM_INVALID_CDB_FIELD; |
| 78 | } |
| 79 | |
| 80 | buf = transport_kmap_data_sg(cmd); |
| 81 | if (!buf) |
| 82 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
| 83 | |
| 84 | off = 4; |
| 85 | spin_lock(&dev->t10_alua.lba_map_lock); |
| 86 | if (list_empty(&dev->t10_alua.lba_map_list)) { |
| 87 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 88 | transport_kunmap_data_sg(cmd); |
| 89 | |
| 90 | return TCM_UNSUPPORTED_SCSI_OPCODE; |
| 91 | } |
| 92 | |
| 93 | list_for_each_entry(map, &dev->t10_alua.lba_map_list, |
| 94 | lba_map_list) { |
| 95 | int desc_num = off + 3; |
| 96 | int pg_num; |
| 97 | |
| 98 | off += 4; |
Hannes Reinecke | 38edd72 | 2013-12-19 14:36:11 +0100 | [diff] [blame] | 99 | if (cmd->data_length > off) |
| 100 | put_unaligned_be64(map->lba_map_first_lba, &buf[off]); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 101 | off += 8; |
Hannes Reinecke | 38edd72 | 2013-12-19 14:36:11 +0100 | [diff] [blame] | 102 | if (cmd->data_length > off) |
| 103 | put_unaligned_be64(map->lba_map_last_lba, &buf[off]); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 104 | off += 8; |
| 105 | rd_len += 20; |
| 106 | pg_num = 0; |
| 107 | list_for_each_entry(map_mem, &map->lba_map_mem_list, |
| 108 | lba_map_mem_list) { |
Hannes Reinecke | 38edd72 | 2013-12-19 14:36:11 +0100 | [diff] [blame] | 109 | int alua_state = map_mem->lba_map_mem_alua_state; |
| 110 | int alua_pg_id = map_mem->lba_map_mem_alua_pg_id; |
| 111 | |
| 112 | if (cmd->data_length > off) |
| 113 | buf[off] = alua_state & 0x0f; |
| 114 | off += 2; |
| 115 | if (cmd->data_length > off) |
| 116 | buf[off] = (alua_pg_id >> 8) & 0xff; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 117 | off++; |
Hannes Reinecke | 38edd72 | 2013-12-19 14:36:11 +0100 | [diff] [blame] | 118 | if (cmd->data_length > off) |
| 119 | buf[off] = (alua_pg_id & 0xff); |
| 120 | off++; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 121 | rd_len += 4; |
| 122 | pg_num++; |
| 123 | } |
Hannes Reinecke | 38edd72 | 2013-12-19 14:36:11 +0100 | [diff] [blame] | 124 | if (cmd->data_length > desc_num) |
| 125 | buf[desc_num] = pg_num; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 126 | } |
| 127 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 128 | |
| 129 | /* |
| 130 | * Set the RETURN DATA LENGTH set in the header of the DataIN Payload |
| 131 | */ |
| 132 | put_unaligned_be16(rd_len, &buf[2]); |
| 133 | |
| 134 | transport_kunmap_data_sg(cmd); |
| 135 | |
| 136 | target_complete_cmd(cmd, GOOD); |
| 137 | return 0; |
| 138 | } |
| 139 | |
| 140 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 141 | * REPORT_TARGET_PORT_GROUPS |
| 142 | * |
| 143 | * See spc4r17 section 6.27 |
| 144 | */ |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 145 | sense_reason_t |
| 146 | target_emulate_report_target_port_groups(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 147 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 148 | struct se_device *dev = cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 149 | struct se_port *port; |
| 150 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 151 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 152 | unsigned char *buf; |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 153 | u32 rd_len = 0, off; |
| 154 | int ext_hdr = (cmd->t_task_cdb[1] & 0x20); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 155 | |
Nicholas Bellinger | 6b20fa9 | 2011-10-18 23:48:04 -0700 | [diff] [blame] | 156 | /* |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 157 | * Skip over RESERVED area to first Target port group descriptor |
| 158 | * depending on the PARAMETER DATA FORMAT type.. |
Nicholas Bellinger | 6b20fa9 | 2011-10-18 23:48:04 -0700 | [diff] [blame] | 159 | */ |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 160 | if (ext_hdr != 0) |
| 161 | off = 8; |
| 162 | else |
| 163 | off = 4; |
| 164 | |
| 165 | if (cmd->data_length < off) { |
| 166 | pr_warn("REPORT TARGET PORT GROUPS allocation length %u too" |
| 167 | " small for %s header\n", cmd->data_length, |
| 168 | (ext_hdr) ? "extended" : "normal"); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 169 | return TCM_INVALID_CDB_FIELD; |
Nicholas Bellinger | 6b20fa9 | 2011-10-18 23:48:04 -0700 | [diff] [blame] | 170 | } |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 171 | buf = transport_kmap_data_sg(cmd); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 172 | if (!buf) |
| 173 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 174 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 175 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
| 176 | list_for_each_entry(tg_pt_gp, &dev->t10_alua.tg_pt_gps_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 177 | tg_pt_gp_list) { |
| 178 | /* |
Nicholas Bellinger | 6b20fa9 | 2011-10-18 23:48:04 -0700 | [diff] [blame] | 179 | * Check if the Target port group and Target port descriptor list |
| 180 | * based on tg_pt_gp_members count will fit into the response payload. |
| 181 | * Otherwise, bump rd_len to let the initiator know we have exceeded |
| 182 | * the allocation length and the response is truncated. |
| 183 | */ |
| 184 | if ((off + 8 + (tg_pt_gp->tg_pt_gp_members * 4)) > |
| 185 | cmd->data_length) { |
| 186 | rd_len += 8 + (tg_pt_gp->tg_pt_gp_members * 4); |
| 187 | continue; |
| 188 | } |
| 189 | /* |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 190 | * PREF: Preferred target port bit, determine if this |
| 191 | * bit should be set for port group. |
| 192 | */ |
| 193 | if (tg_pt_gp->tg_pt_gp_pref) |
| 194 | buf[off] = 0x80; |
| 195 | /* |
| 196 | * Set the ASYMMETRIC ACCESS State |
| 197 | */ |
| 198 | buf[off++] |= (atomic_read( |
| 199 | &tg_pt_gp->tg_pt_gp_alua_access_state) & 0xff); |
| 200 | /* |
| 201 | * Set supported ASYMMETRIC ACCESS State bits |
| 202 | */ |
Hannes Reinecke | c0dc941 | 2013-11-19 09:07:49 +0100 | [diff] [blame] | 203 | buf[off++] |= tg_pt_gp->tg_pt_gp_alua_supported_states; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 204 | /* |
| 205 | * TARGET PORT GROUP |
| 206 | */ |
| 207 | buf[off++] = ((tg_pt_gp->tg_pt_gp_id >> 8) & 0xff); |
| 208 | buf[off++] = (tg_pt_gp->tg_pt_gp_id & 0xff); |
| 209 | |
| 210 | off++; /* Skip over Reserved */ |
| 211 | /* |
| 212 | * STATUS CODE |
| 213 | */ |
| 214 | buf[off++] = (tg_pt_gp->tg_pt_gp_alua_access_status & 0xff); |
| 215 | /* |
| 216 | * Vendor Specific field |
| 217 | */ |
| 218 | buf[off++] = 0x00; |
| 219 | /* |
| 220 | * TARGET PORT COUNT |
| 221 | */ |
| 222 | buf[off++] = (tg_pt_gp->tg_pt_gp_members & 0xff); |
| 223 | rd_len += 8; |
| 224 | |
| 225 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 226 | list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list, |
| 227 | tg_pt_gp_mem_list) { |
| 228 | port = tg_pt_gp_mem->tg_pt; |
| 229 | /* |
| 230 | * Start Target Port descriptor format |
| 231 | * |
| 232 | * See spc4r17 section 6.2.7 Table 247 |
| 233 | */ |
| 234 | off += 2; /* Skip over Obsolete */ |
| 235 | /* |
| 236 | * Set RELATIVE TARGET PORT IDENTIFIER |
| 237 | */ |
| 238 | buf[off++] = ((port->sep_rtpi >> 8) & 0xff); |
| 239 | buf[off++] = (port->sep_rtpi & 0xff); |
| 240 | rd_len += 4; |
| 241 | } |
| 242 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 243 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 244 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 245 | /* |
| 246 | * Set the RETURN DATA LENGTH set in the header of the DataIN Payload |
| 247 | */ |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 248 | put_unaligned_be32(rd_len, &buf[0]); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 249 | |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 250 | /* |
| 251 | * Fill in the Extended header parameter data format if requested |
| 252 | */ |
| 253 | if (ext_hdr != 0) { |
| 254 | buf[4] = 0x10; |
| 255 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 256 | * Set the implicit transition time (in seconds) for the application |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 257 | * client to use as a base for it's transition timeout value. |
| 258 | * |
| 259 | * Use the current tg_pt_gp_mem -> tg_pt_gp membership from the LUN |
| 260 | * this CDB was received upon to determine this value individually |
| 261 | * for ALUA target port group. |
| 262 | */ |
| 263 | port = cmd->se_lun->lun_sep; |
| 264 | tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; |
| 265 | if (tg_pt_gp_mem) { |
| 266 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 267 | tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; |
| 268 | if (tg_pt_gp) |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 269 | buf[5] = tg_pt_gp->tg_pt_gp_implicit_trans_secs; |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 270 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 271 | } |
| 272 | } |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 273 | transport_kunmap_data_sg(cmd); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 274 | |
Christoph Hellwig | 6bb35e0 | 2012-04-23 11:35:33 -0400 | [diff] [blame] | 275 | target_complete_cmd(cmd, GOOD); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 280 | * SET_TARGET_PORT_GROUPS for explicit ALUA operation. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 281 | * |
| 282 | * See spc4r17 section 6.35 |
| 283 | */ |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 284 | sense_reason_t |
| 285 | target_emulate_set_target_port_groups(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 286 | { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 287 | struct se_device *dev = cmd->se_dev; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 288 | struct se_port *port, *l_port = cmd->se_lun->lun_sep; |
| 289 | struct se_node_acl *nacl = cmd->se_sess->se_node_acl; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 290 | struct t10_alua_tg_pt_gp *tg_pt_gp = NULL, *l_tg_pt_gp; |
| 291 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, *l_tg_pt_gp_mem; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 292 | unsigned char *buf; |
| 293 | unsigned char *ptr; |
Hannes Reinecke | a0d50f6 | 2012-12-17 09:53:34 +0100 | [diff] [blame] | 294 | sense_reason_t rc = TCM_NO_SENSE; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 295 | u32 len = 4; /* Skip over RESERVED area in header */ |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 296 | int alua_access_state, primary = 0, valid_states; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 297 | u16 tg_pt_id, rtpi; |
| 298 | |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 299 | if (!l_port) |
| 300 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
| 301 | |
Paolo Bonzini | 0d7f129 | 2012-09-07 17:30:33 +0200 | [diff] [blame] | 302 | if (cmd->data_length < 4) { |
| 303 | pr_warn("SET TARGET PORT GROUPS parameter list length %u too" |
| 304 | " small\n", cmd->data_length); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 305 | return TCM_INVALID_PARAMETER_LIST; |
Paolo Bonzini | 0d7f129 | 2012-09-07 17:30:33 +0200 | [diff] [blame] | 306 | } |
| 307 | |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 308 | buf = transport_kmap_data_sg(cmd); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 309 | if (!buf) |
| 310 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 311 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 312 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 313 | * Determine if explicit ALUA via SET_TARGET_PORT_GROUPS is allowed |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 314 | * for the local tg_pt_gp. |
| 315 | */ |
| 316 | l_tg_pt_gp_mem = l_port->sep_alua_tg_pt_gp_mem; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 317 | if (!l_tg_pt_gp_mem) { |
| 318 | pr_err("Unable to access l_port->sep_alua_tg_pt_gp_mem\n"); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 319 | rc = TCM_UNSUPPORTED_SCSI_OPCODE; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 320 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 321 | } |
| 322 | spin_lock(&l_tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 323 | l_tg_pt_gp = l_tg_pt_gp_mem->tg_pt_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 324 | if (!l_tg_pt_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 325 | spin_unlock(&l_tg_pt_gp_mem->tg_pt_gp_mem_lock); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 326 | pr_err("Unable to access *l_tg_pt_gp_mem->tg_pt_gp\n"); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 327 | rc = TCM_UNSUPPORTED_SCSI_OPCODE; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 328 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 329 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 330 | spin_unlock(&l_tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 331 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 332 | if (!(l_tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 333 | pr_debug("Unable to process SET_TARGET_PORT_GROUPS" |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 334 | " while TPGS_EXPLICIT_ALUA is disabled\n"); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 335 | rc = TCM_UNSUPPORTED_SCSI_OPCODE; |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 336 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 337 | } |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 338 | valid_states = l_tg_pt_gp->tg_pt_gp_alua_supported_states; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 339 | |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 340 | ptr = &buf[4]; /* Skip over RESERVED area in header */ |
| 341 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 342 | while (len < cmd->data_length) { |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 343 | bool found = false; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 344 | alua_access_state = (ptr[0] & 0x0f); |
| 345 | /* |
| 346 | * Check the received ALUA access state, and determine if |
| 347 | * the state is a primary or secondary target port asymmetric |
| 348 | * access state. |
| 349 | */ |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 350 | rc = core_alua_check_transition(alua_access_state, |
| 351 | valid_states, &primary); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 352 | if (rc) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 353 | /* |
| 354 | * If the SET TARGET PORT GROUPS attempts to establish |
| 355 | * an invalid combination of target port asymmetric |
| 356 | * access states or attempts to establish an |
| 357 | * unsupported target port asymmetric access state, |
| 358 | * then the command shall be terminated with CHECK |
| 359 | * CONDITION status, with the sense key set to ILLEGAL |
| 360 | * REQUEST, and the additional sense code set to INVALID |
| 361 | * FIELD IN PARAMETER LIST. |
| 362 | */ |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 363 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 364 | } |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 365 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 366 | /* |
| 367 | * If the ASYMMETRIC ACCESS STATE field (see table 267) |
| 368 | * specifies a primary target port asymmetric access state, |
| 369 | * then the TARGET PORT GROUP OR TARGET PORT field specifies |
| 370 | * a primary target port group for which the primary target |
| 371 | * port asymmetric access state shall be changed. If the |
| 372 | * ASYMMETRIC ACCESS STATE field specifies a secondary target |
| 373 | * port asymmetric access state, then the TARGET PORT GROUP OR |
| 374 | * TARGET PORT field specifies the relative target port |
| 375 | * identifier (see 3.1.120) of the target port for which the |
| 376 | * secondary target port asymmetric access state shall be |
| 377 | * changed. |
| 378 | */ |
| 379 | if (primary) { |
Roland Dreier | 33395fb | 2012-02-23 17:22:12 -0800 | [diff] [blame] | 380 | tg_pt_id = get_unaligned_be16(ptr + 2); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 381 | /* |
| 382 | * Locate the matching target port group ID from |
| 383 | * the global tg_pt_gp list |
| 384 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 385 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 386 | list_for_each_entry(tg_pt_gp, |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 387 | &dev->t10_alua.tg_pt_gps_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 388 | tg_pt_gp_list) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 389 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 390 | continue; |
| 391 | |
| 392 | if (tg_pt_id != tg_pt_gp->tg_pt_gp_id) |
| 393 | continue; |
| 394 | |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 395 | atomic_inc_mb(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 396 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 397 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 398 | |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 399 | if (!core_alua_do_port_transition(tg_pt_gp, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 400 | dev, l_port, nacl, |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 401 | alua_access_state, 1)) |
| 402 | found = true; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 403 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 404 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 405 | atomic_dec_mb(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 406 | break; |
| 407 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 408 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 409 | } else { |
| 410 | /* |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 411 | * Extract the RELATIVE TARGET PORT IDENTIFIER to identify |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 412 | * the Target Port in question for the the incoming |
| 413 | * SET_TARGET_PORT_GROUPS op. |
| 414 | */ |
Roland Dreier | 33395fb | 2012-02-23 17:22:12 -0800 | [diff] [blame] | 415 | rtpi = get_unaligned_be16(ptr + 2); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 416 | /* |
Masanari Iida | 35d1efe | 2012-08-16 22:43:13 +0900 | [diff] [blame] | 417 | * Locate the matching relative target port identifier |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 418 | * for the struct se_device storage object. |
| 419 | */ |
| 420 | spin_lock(&dev->se_port_lock); |
| 421 | list_for_each_entry(port, &dev->dev_sep_list, |
| 422 | sep_list) { |
| 423 | if (port->sep_rtpi != rtpi) |
| 424 | continue; |
| 425 | |
| 426 | tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 427 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 428 | spin_unlock(&dev->se_port_lock); |
| 429 | |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 430 | if (!core_alua_set_tg_pt_secondary_state( |
| 431 | tg_pt_gp_mem, port, 1, 1)) |
| 432 | found = true; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 433 | |
| 434 | spin_lock(&dev->se_port_lock); |
| 435 | break; |
| 436 | } |
| 437 | spin_unlock(&dev->se_port_lock); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | if (!found) { |
| 441 | rc = TCM_INVALID_PARAMETER_LIST; |
| 442 | goto out; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | ptr += 4; |
| 446 | len += 4; |
| 447 | } |
| 448 | |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 449 | out: |
Andy Grover | 4949314 | 2012-01-16 16:57:08 -0800 | [diff] [blame] | 450 | transport_kunmap_data_sg(cmd); |
Roland Dreier | 59e4f54 | 2012-06-04 23:24:51 -0700 | [diff] [blame] | 451 | if (!rc) |
| 452 | target_complete_cmd(cmd, GOOD); |
| 453 | return rc; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 456 | static inline void set_ascq(struct se_cmd *cmd, u8 alua_ascq) |
| 457 | { |
| 458 | /* |
| 459 | * Set SCSI additional sense code (ASC) to 'LUN Not Accessible'; |
| 460 | * The ALUA additional sense code qualifier (ASCQ) is determined |
| 461 | * by the ALUA primary or secondary access state.. |
| 462 | */ |
| 463 | pr_debug("[%s]: ALUA TG Port not available, " |
| 464 | "SenseKey: NOT_READY, ASC/ASCQ: " |
| 465 | "0x04/0x%02x\n", |
| 466 | cmd->se_tfo->get_fabric_name(), alua_ascq); |
| 467 | |
| 468 | cmd->scsi_asc = 0x04; |
| 469 | cmd->scsi_ascq = alua_ascq; |
| 470 | } |
| 471 | |
| 472 | static inline void core_alua_state_nonoptimized( |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 473 | struct se_cmd *cmd, |
| 474 | unsigned char *cdb, |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 475 | int nonop_delay_msecs) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 476 | { |
| 477 | /* |
| 478 | * Set SCF_ALUA_NON_OPTIMIZED here, this value will be checked |
| 479 | * later to determine if processing of this cmd needs to be |
| 480 | * temporarily delayed for the Active/NonOptimized primary access state. |
| 481 | */ |
| 482 | cmd->se_cmd_flags |= SCF_ALUA_NON_OPTIMIZED; |
| 483 | cmd->alua_nonop_delay = nonop_delay_msecs; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 486 | static inline int core_alua_state_lba_dependent( |
| 487 | struct se_cmd *cmd, |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 488 | struct t10_alua_tg_pt_gp *tg_pt_gp) |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 489 | { |
| 490 | struct se_device *dev = cmd->se_dev; |
| 491 | u64 segment_size, segment_mult, sectors, lba; |
| 492 | |
| 493 | /* Only need to check for cdb actually containing LBAs */ |
| 494 | if (!(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB)) |
| 495 | return 0; |
| 496 | |
| 497 | spin_lock(&dev->t10_alua.lba_map_lock); |
| 498 | segment_size = dev->t10_alua.lba_map_segment_size; |
| 499 | segment_mult = dev->t10_alua.lba_map_segment_multiplier; |
| 500 | sectors = cmd->data_length / dev->dev_attrib.block_size; |
| 501 | |
| 502 | lba = cmd->t_task_lba; |
| 503 | while (lba < cmd->t_task_lba + sectors) { |
| 504 | struct t10_alua_lba_map *cur_map = NULL, *map; |
| 505 | struct t10_alua_lba_map_member *map_mem; |
| 506 | |
| 507 | list_for_each_entry(map, &dev->t10_alua.lba_map_list, |
| 508 | lba_map_list) { |
| 509 | u64 start_lba, last_lba; |
| 510 | u64 first_lba = map->lba_map_first_lba; |
| 511 | |
| 512 | if (segment_mult) { |
| 513 | u64 tmp = lba; |
Nicholas Bellinger | cdf5594 | 2014-01-30 14:05:16 -0800 | [diff] [blame] | 514 | start_lba = do_div(tmp, segment_size * segment_mult); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 515 | |
| 516 | last_lba = first_lba + segment_size - 1; |
| 517 | if (start_lba >= first_lba && |
| 518 | start_lba <= last_lba) { |
| 519 | lba += segment_size; |
| 520 | cur_map = map; |
| 521 | break; |
| 522 | } |
| 523 | } else { |
| 524 | last_lba = map->lba_map_last_lba; |
| 525 | if (lba >= first_lba && lba <= last_lba) { |
| 526 | lba = last_lba + 1; |
| 527 | cur_map = map; |
| 528 | break; |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | if (!cur_map) { |
| 533 | spin_unlock(&dev->t10_alua.lba_map_lock); |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 534 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_UNAVAILABLE); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 535 | return 1; |
| 536 | } |
| 537 | list_for_each_entry(map_mem, &cur_map->lba_map_mem_list, |
| 538 | lba_map_mem_list) { |
| 539 | if (map_mem->lba_map_mem_alua_pg_id != |
| 540 | tg_pt_gp->tg_pt_gp_id) |
| 541 | continue; |
| 542 | switch(map_mem->lba_map_mem_alua_state) { |
| 543 | case ALUA_ACCESS_STATE_STANDBY: |
| 544 | spin_unlock(&dev->t10_alua.lba_map_lock); |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 545 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_STANDBY); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 546 | return 1; |
| 547 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
| 548 | spin_unlock(&dev->t10_alua.lba_map_lock); |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 549 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_UNAVAILABLE); |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 550 | return 1; |
| 551 | default: |
| 552 | break; |
| 553 | } |
| 554 | } |
| 555 | } |
| 556 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 557 | return 0; |
| 558 | } |
| 559 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 560 | static inline int core_alua_state_standby( |
| 561 | struct se_cmd *cmd, |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 562 | unsigned char *cdb) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 563 | { |
| 564 | /* |
| 565 | * Allowed CDBs for ALUA_ACCESS_STATE_STANDBY as defined by |
| 566 | * spc4r17 section 5.9.2.4.4 |
| 567 | */ |
| 568 | switch (cdb[0]) { |
| 569 | case INQUIRY: |
| 570 | case LOG_SELECT: |
| 571 | case LOG_SENSE: |
| 572 | case MODE_SELECT: |
| 573 | case MODE_SENSE: |
| 574 | case REPORT_LUNS: |
| 575 | case RECEIVE_DIAGNOSTIC: |
| 576 | case SEND_DIAGNOSTIC: |
Nicholas Bellinger | e7810c2 | 2014-06-05 23:37:00 -0700 | [diff] [blame] | 577 | case READ_CAPACITY: |
Nicholas Bellinger | 30f359a | 2013-04-10 15:00:27 -0700 | [diff] [blame] | 578 | return 0; |
Hannes Reinecke | eb846d9 | 2014-11-17 14:25:19 +0100 | [diff] [blame] | 579 | case SERVICE_ACTION_IN_16: |
Nicholas Bellinger | e7810c2 | 2014-06-05 23:37:00 -0700 | [diff] [blame] | 580 | switch (cdb[1] & 0x1f) { |
| 581 | case SAI_READ_CAPACITY_16: |
| 582 | return 0; |
| 583 | default: |
| 584 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_STANDBY); |
| 585 | return 1; |
| 586 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 587 | case MAINTENANCE_IN: |
Nicholas Bellinger | ba53974 | 2012-05-16 21:52:10 -0700 | [diff] [blame] | 588 | switch (cdb[1] & 0x1f) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 589 | case MI_REPORT_TARGET_PGS: |
| 590 | return 0; |
| 591 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 592 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_STANDBY); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 593 | return 1; |
| 594 | } |
| 595 | case MAINTENANCE_OUT: |
| 596 | switch (cdb[1]) { |
| 597 | case MO_SET_TARGET_PGS: |
| 598 | return 0; |
| 599 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 600 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_STANDBY); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 601 | return 1; |
| 602 | } |
| 603 | case REQUEST_SENSE: |
| 604 | case PERSISTENT_RESERVE_IN: |
| 605 | case PERSISTENT_RESERVE_OUT: |
| 606 | case READ_BUFFER: |
| 607 | case WRITE_BUFFER: |
| 608 | return 0; |
| 609 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 610 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_STANDBY); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 611 | return 1; |
| 612 | } |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | static inline int core_alua_state_unavailable( |
| 618 | struct se_cmd *cmd, |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 619 | unsigned char *cdb) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 620 | { |
| 621 | /* |
| 622 | * Allowed CDBs for ALUA_ACCESS_STATE_UNAVAILABLE as defined by |
| 623 | * spc4r17 section 5.9.2.4.5 |
| 624 | */ |
| 625 | switch (cdb[0]) { |
| 626 | case INQUIRY: |
| 627 | case REPORT_LUNS: |
Nicholas Bellinger | 30f359a | 2013-04-10 15:00:27 -0700 | [diff] [blame] | 628 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 629 | case MAINTENANCE_IN: |
Nicholas Bellinger | ba53974 | 2012-05-16 21:52:10 -0700 | [diff] [blame] | 630 | switch (cdb[1] & 0x1f) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 631 | case MI_REPORT_TARGET_PGS: |
| 632 | return 0; |
| 633 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 634 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_UNAVAILABLE); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 635 | return 1; |
| 636 | } |
| 637 | case MAINTENANCE_OUT: |
| 638 | switch (cdb[1]) { |
| 639 | case MO_SET_TARGET_PGS: |
| 640 | return 0; |
| 641 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 642 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_UNAVAILABLE); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 643 | return 1; |
| 644 | } |
| 645 | case REQUEST_SENSE: |
| 646 | case READ_BUFFER: |
| 647 | case WRITE_BUFFER: |
| 648 | return 0; |
| 649 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 650 | set_ascq(cmd, ASCQ_04H_ALUA_TG_PT_UNAVAILABLE); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 651 | return 1; |
| 652 | } |
| 653 | |
| 654 | return 0; |
| 655 | } |
| 656 | |
| 657 | static inline int core_alua_state_transition( |
| 658 | struct se_cmd *cmd, |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 659 | unsigned char *cdb) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 660 | { |
| 661 | /* |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 662 | * Allowed CDBs for ALUA_ACCESS_STATE_TRANSITION as defined by |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 663 | * spc4r17 section 5.9.2.5 |
| 664 | */ |
| 665 | switch (cdb[0]) { |
| 666 | case INQUIRY: |
| 667 | case REPORT_LUNS: |
Nicholas Bellinger | 30f359a | 2013-04-10 15:00:27 -0700 | [diff] [blame] | 668 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 669 | case MAINTENANCE_IN: |
Nicholas Bellinger | ba53974 | 2012-05-16 21:52:10 -0700 | [diff] [blame] | 670 | switch (cdb[1] & 0x1f) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 671 | case MI_REPORT_TARGET_PGS: |
| 672 | return 0; |
| 673 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 674 | set_ascq(cmd, ASCQ_04H_ALUA_STATE_TRANSITION); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 675 | return 1; |
| 676 | } |
| 677 | case REQUEST_SENSE: |
| 678 | case READ_BUFFER: |
| 679 | case WRITE_BUFFER: |
| 680 | return 0; |
| 681 | default: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 682 | set_ascq(cmd, ASCQ_04H_ALUA_STATE_TRANSITION); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 683 | return 1; |
| 684 | } |
| 685 | |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | /* |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 690 | * return 1: Is used to signal LUN not accessible, and check condition/not ready |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 691 | * return 0: Used to signal success |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 692 | * return -1: Used to signal failure, and invalid cdb field |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 693 | */ |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 694 | sense_reason_t |
| 695 | target_alua_state_check(struct se_cmd *cmd) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 696 | { |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 697 | struct se_device *dev = cmd->se_dev; |
| 698 | unsigned char *cdb = cmd->t_task_cdb; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 699 | struct se_lun *lun = cmd->se_lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 700 | struct se_port *port = lun->lun_sep; |
| 701 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 702 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 703 | int out_alua_state, nonop_delay_msecs; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 704 | |
| 705 | if (dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE) |
| 706 | return 0; |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 707 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 708 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 709 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 710 | if (!port) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 711 | return 0; |
| 712 | /* |
| 713 | * First, check for a struct se_port specific secondary ALUA target port |
| 714 | * access state: OFFLINE |
| 715 | */ |
| 716 | if (atomic_read(&port->sep_tg_pt_secondary_offline)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 717 | pr_debug("ALUA: Got secondary offline status for local" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 718 | " target port\n"); |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 719 | set_ascq(cmd, ASCQ_04H_ALUA_OFFLINE); |
| 720 | return TCM_CHECK_CONDITION_NOT_READY; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 721 | } |
| 722 | /* |
| 723 | * Second, obtain the struct t10_alua_tg_pt_gp_member pointer to the |
| 724 | * ALUA target port group, to obtain current ALUA access state. |
| 725 | * Otherwise look for the underlying struct se_device association with |
| 726 | * a ALUA logical unit group. |
| 727 | */ |
| 728 | tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; |
Nicholas Bellinger | 89c12cc | 2013-08-22 15:35:45 -0700 | [diff] [blame] | 729 | if (!tg_pt_gp_mem) |
| 730 | return 0; |
| 731 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 732 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 733 | tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; |
| 734 | out_alua_state = atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state); |
| 735 | nonop_delay_msecs = tg_pt_gp->tg_pt_gp_nonop_delay_msecs; |
| 736 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 737 | /* |
Hannes Reinecke | 73f3bf5 | 2013-11-19 09:07:48 +0100 | [diff] [blame] | 738 | * Process ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED in a separate conditional |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 739 | * statement so the compiler knows explicitly to check this case first. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 740 | * For the Optimized ALUA access state case, we want to process the |
| 741 | * incoming fabric cmd ASAP.. |
| 742 | */ |
Hannes Reinecke | 73f3bf5 | 2013-11-19 09:07:48 +0100 | [diff] [blame] | 743 | if (out_alua_state == ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 744 | return 0; |
| 745 | |
| 746 | switch (out_alua_state) { |
| 747 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 748 | core_alua_state_nonoptimized(cmd, cdb, nonop_delay_msecs); |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 749 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 750 | case ALUA_ACCESS_STATE_STANDBY: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 751 | if (core_alua_state_standby(cmd, cdb)) |
| 752 | return TCM_CHECK_CONDITION_NOT_READY; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 753 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 754 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 755 | if (core_alua_state_unavailable(cmd, cdb)) |
| 756 | return TCM_CHECK_CONDITION_NOT_READY; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 757 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 758 | case ALUA_ACCESS_STATE_TRANSITION: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 759 | if (core_alua_state_transition(cmd, cdb)) |
| 760 | return TCM_CHECK_CONDITION_NOT_READY; |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 761 | break; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 762 | case ALUA_ACCESS_STATE_LBA_DEPENDENT: |
Paul Bolle | 1e3ab99 | 2014-02-20 09:07:52 +0100 | [diff] [blame] | 763 | if (core_alua_state_lba_dependent(cmd, tg_pt_gp)) |
| 764 | return TCM_CHECK_CONDITION_NOT_READY; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 765 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 766 | /* |
| 767 | * OFFLINE is a secondary ALUA target port group access state, that is |
| 768 | * handled above with struct se_port->sep_tg_pt_secondary_offline=1 |
| 769 | */ |
| 770 | case ALUA_ACCESS_STATE_OFFLINE: |
| 771 | default: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 772 | pr_err("Unknown ALUA access state: 0x%02x\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 773 | out_alua_state); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 774 | return TCM_INVALID_CDB_FIELD; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 775 | } |
| 776 | |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 777 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 781 | * Check implicit and explicit ALUA state change request. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 782 | */ |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 783 | static sense_reason_t |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 784 | core_alua_check_transition(int state, int valid, int *primary) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 785 | { |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 786 | /* |
| 787 | * OPTIMIZED, NON-OPTIMIZED, STANDBY and UNAVAILABLE are |
| 788 | * defined as primary target port asymmetric access states. |
| 789 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 790 | switch (state) { |
Hannes Reinecke | 73f3bf5 | 2013-11-19 09:07:48 +0100 | [diff] [blame] | 791 | case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 792 | if (!(valid & ALUA_AO_SUP)) |
| 793 | goto not_supported; |
| 794 | *primary = 1; |
| 795 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 796 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 797 | if (!(valid & ALUA_AN_SUP)) |
| 798 | goto not_supported; |
| 799 | *primary = 1; |
| 800 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 801 | case ALUA_ACCESS_STATE_STANDBY: |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 802 | if (!(valid & ALUA_S_SUP)) |
| 803 | goto not_supported; |
| 804 | *primary = 1; |
| 805 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 806 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 807 | if (!(valid & ALUA_U_SUP)) |
| 808 | goto not_supported; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 809 | *primary = 1; |
| 810 | break; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 811 | case ALUA_ACCESS_STATE_LBA_DEPENDENT: |
| 812 | if (!(valid & ALUA_LBD_SUP)) |
| 813 | goto not_supported; |
| 814 | *primary = 1; |
| 815 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 816 | case ALUA_ACCESS_STATE_OFFLINE: |
| 817 | /* |
| 818 | * OFFLINE state is defined as a secondary target port |
| 819 | * asymmetric access state. |
| 820 | */ |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 821 | if (!(valid & ALUA_O_SUP)) |
| 822 | goto not_supported; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 823 | *primary = 0; |
| 824 | break; |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 825 | case ALUA_ACCESS_STATE_TRANSITION: |
| 826 | /* |
| 827 | * Transitioning is set internally, and |
| 828 | * cannot be selected manually. |
| 829 | */ |
| 830 | goto not_supported; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 831 | default: |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 832 | pr_err("Unknown ALUA access state: 0x%02x\n", state); |
Christoph Hellwig | de103c9 | 2012-11-06 12:24:09 -0800 | [diff] [blame] | 833 | return TCM_INVALID_PARAMETER_LIST; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 834 | } |
| 835 | |
| 836 | return 0; |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 837 | |
| 838 | not_supported: |
| 839 | pr_err("ALUA access state %s not supported", |
| 840 | core_alua_dump_state(state)); |
| 841 | return TCM_INVALID_PARAMETER_LIST; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static char *core_alua_dump_state(int state) |
| 845 | { |
| 846 | switch (state) { |
Hannes Reinecke | 73f3bf5 | 2013-11-19 09:07:48 +0100 | [diff] [blame] | 847 | case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 848 | return "Active/Optimized"; |
| 849 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: |
| 850 | return "Active/NonOptimized"; |
Hannes Reinecke | c66094b | 2013-12-17 09:18:49 +0100 | [diff] [blame] | 851 | case ALUA_ACCESS_STATE_LBA_DEPENDENT: |
| 852 | return "LBA Dependent"; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 853 | case ALUA_ACCESS_STATE_STANDBY: |
| 854 | return "Standby"; |
| 855 | case ALUA_ACCESS_STATE_UNAVAILABLE: |
| 856 | return "Unavailable"; |
| 857 | case ALUA_ACCESS_STATE_OFFLINE: |
| 858 | return "Offline"; |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 859 | case ALUA_ACCESS_STATE_TRANSITION: |
| 860 | return "Transitioning"; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 861 | default: |
| 862 | return "Unknown"; |
| 863 | } |
| 864 | |
| 865 | return NULL; |
| 866 | } |
| 867 | |
| 868 | char *core_alua_dump_status(int status) |
| 869 | { |
| 870 | switch (status) { |
| 871 | case ALUA_STATUS_NONE: |
| 872 | return "None"; |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 873 | case ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG: |
| 874 | return "Altered by Explicit STPG"; |
| 875 | case ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA: |
| 876 | return "Altered by Implicit ALUA"; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 877 | default: |
| 878 | return "Unknown"; |
| 879 | } |
| 880 | |
| 881 | return NULL; |
| 882 | } |
| 883 | |
| 884 | /* |
| 885 | * Used by fabric modules to determine when we need to delay processing |
| 886 | * for the Active/NonOptimized paths.. |
| 887 | */ |
| 888 | int core_alua_check_nonop_delay( |
| 889 | struct se_cmd *cmd) |
| 890 | { |
| 891 | if (!(cmd->se_cmd_flags & SCF_ALUA_NON_OPTIMIZED)) |
| 892 | return 0; |
| 893 | if (in_interrupt()) |
| 894 | return 0; |
| 895 | /* |
| 896 | * The ALUA Active/NonOptimized access state delay can be disabled |
| 897 | * in via configfs with a value of zero |
| 898 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 899 | if (!cmd->alua_nonop_delay) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 900 | return 0; |
| 901 | /* |
| 902 | * struct se_cmd->alua_nonop_delay gets set by a target port group |
| 903 | * defined interval in core_alua_state_nonoptimized() |
| 904 | */ |
| 905 | msleep_interruptible(cmd->alua_nonop_delay); |
| 906 | return 0; |
| 907 | } |
| 908 | EXPORT_SYMBOL(core_alua_check_nonop_delay); |
| 909 | |
| 910 | /* |
| 911 | * Called with tg_pt_gp->tg_pt_gp_md_mutex or tg_pt_gp_mem->sep_tg_pt_md_mutex |
| 912 | * |
| 913 | */ |
| 914 | static int core_alua_write_tpg_metadata( |
| 915 | const char *path, |
| 916 | unsigned char *md_buf, |
| 917 | u32 md_buf_len) |
| 918 | { |
Al Viro | 0e9b10a | 2013-02-23 15:22:43 -0500 | [diff] [blame] | 919 | struct file *file = filp_open(path, O_RDWR | O_CREAT | O_TRUNC, 0600); |
| 920 | int ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 921 | |
Al Viro | 0e9b10a | 2013-02-23 15:22:43 -0500 | [diff] [blame] | 922 | if (IS_ERR(file)) { |
| 923 | pr_err("filp_open(%s) for ALUA metadata failed\n", path); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 924 | return -ENODEV; |
| 925 | } |
Al Viro | 0e9b10a | 2013-02-23 15:22:43 -0500 | [diff] [blame] | 926 | ret = kernel_write(file, md_buf, md_buf_len, 0); |
| 927 | if (ret < 0) |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 928 | pr_err("Error writing ALUA metadata file: %s\n", path); |
Al Viro | 0e9b10a | 2013-02-23 15:22:43 -0500 | [diff] [blame] | 929 | fput(file); |
Gera Kazakov | f730f91 | 2013-09-09 15:47:06 -0700 | [diff] [blame] | 930 | return (ret < 0) ? -EIO : 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /* |
| 934 | * Called with tg_pt_gp->tg_pt_gp_md_mutex held |
| 935 | */ |
| 936 | static int core_alua_update_tpg_primary_metadata( |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 937 | struct t10_alua_tg_pt_gp *tg_pt_gp) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 938 | { |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 939 | unsigned char *md_buf; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 940 | struct t10_wwn *wwn = &tg_pt_gp->tg_pt_gp_dev->t10_wwn; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 941 | char path[ALUA_METADATA_PATH_LEN]; |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 942 | int len, rc; |
| 943 | |
| 944 | md_buf = kzalloc(ALUA_MD_BUF_LEN, GFP_KERNEL); |
| 945 | if (!md_buf) { |
| 946 | pr_err("Unable to allocate buf for ALUA metadata\n"); |
| 947 | return -ENOMEM; |
| 948 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 949 | |
| 950 | memset(path, 0, ALUA_METADATA_PATH_LEN); |
| 951 | |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 952 | len = snprintf(md_buf, ALUA_MD_BUF_LEN, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 953 | "tg_pt_gp_id=%hu\n" |
| 954 | "alua_access_state=0x%02x\n" |
| 955 | "alua_access_status=0x%02x\n", |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 956 | tg_pt_gp->tg_pt_gp_id, |
| 957 | tg_pt_gp->tg_pt_gp_alua_pending_state, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 958 | tg_pt_gp->tg_pt_gp_alua_access_status); |
| 959 | |
| 960 | snprintf(path, ALUA_METADATA_PATH_LEN, |
| 961 | "/var/target/alua/tpgs_%s/%s", &wwn->unit_serial[0], |
| 962 | config_item_name(&tg_pt_gp->tg_pt_gp_group.cg_item)); |
| 963 | |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 964 | rc = core_alua_write_tpg_metadata(path, md_buf, len); |
| 965 | kfree(md_buf); |
| 966 | return rc; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 969 | static void core_alua_do_transition_tg_pt_work(struct work_struct *work) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 970 | { |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 971 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(work, |
| 972 | struct t10_alua_tg_pt_gp, tg_pt_gp_transition_work.work); |
| 973 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 974 | struct se_dev_entry *se_deve; |
| 975 | struct se_lun_acl *lacl; |
| 976 | struct se_port *port; |
| 977 | struct t10_alua_tg_pt_gp_member *mem; |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 978 | bool explicit = (tg_pt_gp->tg_pt_gp_alua_access_status == |
| 979 | ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 980 | |
| 981 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 982 | list_for_each_entry(mem, &tg_pt_gp->tg_pt_gp_mem_list, |
| 983 | tg_pt_gp_mem_list) { |
| 984 | port = mem->tg_pt; |
| 985 | /* |
| 986 | * After an implicit target port asymmetric access state |
| 987 | * change, a device server shall establish a unit attention |
| 988 | * condition for the initiator port associated with every I_T |
| 989 | * nexus with the additional sense code set to ASYMMETRIC |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 990 | * ACCESS STATE CHANGED. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 991 | * |
| 992 | * After an explicit target port asymmetric access state |
| 993 | * change, a device server shall establish a unit attention |
| 994 | * condition with the additional sense code set to ASYMMETRIC |
| 995 | * ACCESS STATE CHANGED for the initiator port associated with |
| 996 | * every I_T nexus other than the I_T nexus on which the SET |
| 997 | * TARGET PORT GROUPS command |
| 998 | */ |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 999 | atomic_inc_mb(&mem->tg_pt_gp_mem_ref_cnt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1000 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1001 | |
| 1002 | spin_lock_bh(&port->sep_alua_lock); |
| 1003 | list_for_each_entry(se_deve, &port->sep_alua_list, |
| 1004 | alua_port_list) { |
| 1005 | lacl = se_deve->se_lun_acl; |
| 1006 | /* |
| 1007 | * se_deve->se_lun_acl pointer may be NULL for a |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1008 | * entry created without explicit Node+MappedLUN ACLs |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1009 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1010 | if (!lacl) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1011 | continue; |
| 1012 | |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1013 | if ((tg_pt_gp->tg_pt_gp_alua_access_status == |
| 1014 | ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && |
| 1015 | (tg_pt_gp->tg_pt_gp_alua_nacl != NULL) && |
| 1016 | (tg_pt_gp->tg_pt_gp_alua_nacl == lacl->se_lun_nacl) && |
| 1017 | (tg_pt_gp->tg_pt_gp_alua_port != NULL) && |
| 1018 | (tg_pt_gp->tg_pt_gp_alua_port == port)) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1019 | continue; |
| 1020 | |
| 1021 | core_scsi3_ua_allocate(lacl->se_lun_nacl, |
| 1022 | se_deve->mapped_lun, 0x2A, |
| 1023 | ASCQ_2AH_ASYMMETRIC_ACCESS_STATE_CHANGED); |
| 1024 | } |
| 1025 | spin_unlock_bh(&port->sep_alua_lock); |
| 1026 | |
| 1027 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1028 | atomic_dec_mb(&mem->tg_pt_gp_mem_ref_cnt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1029 | } |
| 1030 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1031 | /* |
| 1032 | * Update the ALUA metadata buf that has been allocated in |
| 1033 | * core_alua_do_port_transition(), this metadata will be written |
| 1034 | * to struct file. |
| 1035 | * |
| 1036 | * Note that there is the case where we do not want to update the |
| 1037 | * metadata when the saved metadata is being parsed in userspace |
| 1038 | * when setting the existing port access state and access status. |
| 1039 | * |
| 1040 | * Also note that the failure to write out the ALUA metadata to |
| 1041 | * struct file does NOT affect the actual ALUA transition. |
| 1042 | */ |
| 1043 | if (tg_pt_gp->tg_pt_gp_write_metadata) { |
| 1044 | mutex_lock(&tg_pt_gp->tg_pt_gp_md_mutex); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1045 | core_alua_update_tpg_primary_metadata(tg_pt_gp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1046 | mutex_unlock(&tg_pt_gp->tg_pt_gp_md_mutex); |
| 1047 | } |
| 1048 | /* |
| 1049 | * Set the current primary ALUA access state to the requested new state |
| 1050 | */ |
Hannes Reinecke | dfbce75 | 2013-12-17 09:18:45 +0100 | [diff] [blame] | 1051 | atomic_set(&tg_pt_gp->tg_pt_gp_alua_access_state, |
| 1052 | tg_pt_gp->tg_pt_gp_alua_pending_state); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1053 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1054 | pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu" |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1055 | " from primary access state %s to %s\n", (explicit) ? "explicit" : |
| 1056 | "implicit", config_item_name(&tg_pt_gp->tg_pt_gp_group.cg_item), |
Hannes Reinecke | dfbce75 | 2013-12-17 09:18:45 +0100 | [diff] [blame] | 1057 | tg_pt_gp->tg_pt_gp_id, |
| 1058 | core_alua_dump_state(tg_pt_gp->tg_pt_gp_alua_previous_state), |
| 1059 | core_alua_dump_state(tg_pt_gp->tg_pt_gp_alua_pending_state)); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1060 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
| 1061 | atomic_dec(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1062 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
| 1063 | |
| 1064 | if (tg_pt_gp->tg_pt_gp_transition_complete) |
| 1065 | complete(tg_pt_gp->tg_pt_gp_transition_complete); |
| 1066 | } |
| 1067 | |
| 1068 | static int core_alua_do_transition_tg_pt( |
| 1069 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 1070 | int new_state, |
| 1071 | int explicit) |
| 1072 | { |
| 1073 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
| 1074 | DECLARE_COMPLETION_ONSTACK(wait); |
| 1075 | |
| 1076 | /* Nothing to be done here */ |
| 1077 | if (atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state) == new_state) |
| 1078 | return 0; |
| 1079 | |
| 1080 | if (new_state == ALUA_ACCESS_STATE_TRANSITION) |
| 1081 | return -EAGAIN; |
| 1082 | |
| 1083 | /* |
| 1084 | * Flush any pending transitions |
| 1085 | */ |
| 1086 | if (!explicit && tg_pt_gp->tg_pt_gp_implicit_trans_secs && |
| 1087 | atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state) == |
| 1088 | ALUA_ACCESS_STATE_TRANSITION) { |
| 1089 | /* Just in case */ |
| 1090 | tg_pt_gp->tg_pt_gp_alua_pending_state = new_state; |
| 1091 | tg_pt_gp->tg_pt_gp_transition_complete = &wait; |
| 1092 | flush_delayed_work(&tg_pt_gp->tg_pt_gp_transition_work); |
| 1093 | wait_for_completion(&wait); |
| 1094 | tg_pt_gp->tg_pt_gp_transition_complete = NULL; |
| 1095 | return 0; |
| 1096 | } |
| 1097 | |
| 1098 | /* |
| 1099 | * Save the old primary ALUA access state, and set the current state |
| 1100 | * to ALUA_ACCESS_STATE_TRANSITION. |
| 1101 | */ |
| 1102 | tg_pt_gp->tg_pt_gp_alua_previous_state = |
| 1103 | atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state); |
| 1104 | tg_pt_gp->tg_pt_gp_alua_pending_state = new_state; |
| 1105 | |
| 1106 | atomic_set(&tg_pt_gp->tg_pt_gp_alua_access_state, |
| 1107 | ALUA_ACCESS_STATE_TRANSITION); |
| 1108 | tg_pt_gp->tg_pt_gp_alua_access_status = (explicit) ? |
| 1109 | ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG : |
| 1110 | ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA; |
| 1111 | |
| 1112 | /* |
| 1113 | * Check for the optional ALUA primary state transition delay |
| 1114 | */ |
| 1115 | if (tg_pt_gp->tg_pt_gp_trans_delay_msecs != 0) |
| 1116 | msleep_interruptible(tg_pt_gp->tg_pt_gp_trans_delay_msecs); |
| 1117 | |
| 1118 | /* |
| 1119 | * Take a reference for workqueue item |
| 1120 | */ |
| 1121 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
| 1122 | atomic_inc(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1123 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
| 1124 | |
| 1125 | if (!explicit && tg_pt_gp->tg_pt_gp_implicit_trans_secs) { |
| 1126 | unsigned long transition_tmo; |
| 1127 | |
| 1128 | transition_tmo = tg_pt_gp->tg_pt_gp_implicit_trans_secs * HZ; |
| 1129 | queue_delayed_work(tg_pt_gp->tg_pt_gp_dev->tmr_wq, |
| 1130 | &tg_pt_gp->tg_pt_gp_transition_work, |
| 1131 | transition_tmo); |
| 1132 | } else { |
| 1133 | tg_pt_gp->tg_pt_gp_transition_complete = &wait; |
| 1134 | queue_delayed_work(tg_pt_gp->tg_pt_gp_dev->tmr_wq, |
| 1135 | &tg_pt_gp->tg_pt_gp_transition_work, 0); |
| 1136 | wait_for_completion(&wait); |
| 1137 | tg_pt_gp->tg_pt_gp_transition_complete = NULL; |
| 1138 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1139 | |
| 1140 | return 0; |
| 1141 | } |
| 1142 | |
| 1143 | int core_alua_do_port_transition( |
| 1144 | struct t10_alua_tg_pt_gp *l_tg_pt_gp, |
| 1145 | struct se_device *l_dev, |
| 1146 | struct se_port *l_port, |
| 1147 | struct se_node_acl *l_nacl, |
| 1148 | int new_state, |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1149 | int explicit) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1150 | { |
| 1151 | struct se_device *dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1152 | struct t10_alua_lu_gp *lu_gp; |
| 1153 | struct t10_alua_lu_gp_member *lu_gp_mem, *local_lu_gp_mem; |
| 1154 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1155 | int primary, valid_states, rc = 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1156 | |
Hannes Reinecke | bb91c1a | 2013-12-17 09:18:43 +0100 | [diff] [blame] | 1157 | valid_states = l_tg_pt_gp->tg_pt_gp_alua_supported_states; |
| 1158 | if (core_alua_check_transition(new_state, valid_states, &primary) != 0) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1159 | return -EINVAL; |
| 1160 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1161 | local_lu_gp_mem = l_dev->dev_alua_lu_gp_mem; |
| 1162 | spin_lock(&local_lu_gp_mem->lu_gp_mem_lock); |
| 1163 | lu_gp = local_lu_gp_mem->lu_gp; |
| 1164 | atomic_inc(&lu_gp->lu_gp_ref_cnt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1165 | spin_unlock(&local_lu_gp_mem->lu_gp_mem_lock); |
| 1166 | /* |
| 1167 | * For storage objects that are members of the 'default_lu_gp', |
| 1168 | * we only do transition on the passed *l_tp_pt_gp, and not |
| 1169 | * on all of the matching target port groups IDs in default_lu_gp. |
| 1170 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1171 | if (!lu_gp->lu_gp_id) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1172 | /* |
| 1173 | * core_alua_do_transition_tg_pt() will always return |
| 1174 | * success. |
| 1175 | */ |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1176 | l_tg_pt_gp->tg_pt_gp_alua_port = l_port; |
| 1177 | l_tg_pt_gp->tg_pt_gp_alua_nacl = l_nacl; |
| 1178 | rc = core_alua_do_transition_tg_pt(l_tg_pt_gp, |
| 1179 | new_state, explicit); |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1180 | atomic_dec_mb(&lu_gp->lu_gp_ref_cnt); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1181 | return rc; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1182 | } |
| 1183 | /* |
| 1184 | * For all other LU groups aside from 'default_lu_gp', walk all of |
| 1185 | * the associated storage objects looking for a matching target port |
| 1186 | * group ID from the local target port group. |
| 1187 | */ |
| 1188 | spin_lock(&lu_gp->lu_gp_lock); |
| 1189 | list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, |
| 1190 | lu_gp_mem_list) { |
| 1191 | |
| 1192 | dev = lu_gp_mem->lu_gp_mem_dev; |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1193 | atomic_inc_mb(&lu_gp_mem->lu_gp_mem_ref_cnt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1194 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1195 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1196 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1197 | list_for_each_entry(tg_pt_gp, |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1198 | &dev->t10_alua.tg_pt_gps_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1199 | tg_pt_gp_list) { |
| 1200 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1201 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1202 | continue; |
| 1203 | /* |
| 1204 | * If the target behavior port asymmetric access state |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 1205 | * is changed for any target port group accessible via |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1206 | * a logical unit within a LU group, the target port |
| 1207 | * behavior group asymmetric access states for the same |
| 1208 | * target port group accessible via other logical units |
| 1209 | * in that LU group will also change. |
| 1210 | */ |
| 1211 | if (l_tg_pt_gp->tg_pt_gp_id != tg_pt_gp->tg_pt_gp_id) |
| 1212 | continue; |
| 1213 | |
| 1214 | if (l_tg_pt_gp == tg_pt_gp) { |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1215 | tg_pt_gp->tg_pt_gp_alua_port = l_port; |
| 1216 | tg_pt_gp->tg_pt_gp_alua_nacl = l_nacl; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1217 | } else { |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1218 | tg_pt_gp->tg_pt_gp_alua_port = NULL; |
| 1219 | tg_pt_gp->tg_pt_gp_alua_nacl = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1220 | } |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1221 | atomic_inc_mb(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1222 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1223 | /* |
| 1224 | * core_alua_do_transition_tg_pt() will always return |
| 1225 | * success. |
| 1226 | */ |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1227 | rc = core_alua_do_transition_tg_pt(tg_pt_gp, |
| 1228 | new_state, explicit); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1229 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1230 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1231 | atomic_dec_mb(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1232 | if (rc) |
| 1233 | break; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1234 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1235 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1236 | |
| 1237 | spin_lock(&lu_gp->lu_gp_lock); |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1238 | atomic_dec_mb(&lu_gp_mem->lu_gp_mem_ref_cnt); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1239 | } |
| 1240 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1241 | |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1242 | if (!rc) { |
| 1243 | pr_debug("Successfully processed LU Group: %s all ALUA TG PT" |
| 1244 | " Group IDs: %hu %s transition to primary state: %s\n", |
| 1245 | config_item_name(&lu_gp->lu_gp_group.cg_item), |
| 1246 | l_tg_pt_gp->tg_pt_gp_id, |
| 1247 | (explicit) ? "explicit" : "implicit", |
| 1248 | core_alua_dump_state(new_state)); |
| 1249 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1250 | |
Joern Engel | 33940d0 | 2014-09-16 16:23:12 -0400 | [diff] [blame] | 1251 | atomic_dec_mb(&lu_gp->lu_gp_ref_cnt); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1252 | return rc; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1253 | } |
| 1254 | |
| 1255 | /* |
| 1256 | * Called with tg_pt_gp_mem->sep_tg_pt_md_mutex held |
| 1257 | */ |
| 1258 | static int core_alua_update_tpg_secondary_metadata( |
| 1259 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 1260 | struct se_port *port) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1261 | { |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 1262 | unsigned char *md_buf; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1263 | struct se_portal_group *se_tpg = port->sep_tpg; |
| 1264 | char path[ALUA_METADATA_PATH_LEN], wwn[ALUA_SECONDARY_METADATA_WWN_LEN]; |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 1265 | int len, rc; |
| 1266 | |
| 1267 | md_buf = kzalloc(ALUA_MD_BUF_LEN, GFP_KERNEL); |
| 1268 | if (!md_buf) { |
| 1269 | pr_err("Unable to allocate buf for ALUA metadata\n"); |
| 1270 | return -ENOMEM; |
| 1271 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1272 | |
| 1273 | memset(path, 0, ALUA_METADATA_PATH_LEN); |
| 1274 | memset(wwn, 0, ALUA_SECONDARY_METADATA_WWN_LEN); |
| 1275 | |
| 1276 | len = snprintf(wwn, ALUA_SECONDARY_METADATA_WWN_LEN, "%s", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1277 | se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1278 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1279 | if (se_tpg->se_tpg_tfo->tpg_get_tag != NULL) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1280 | snprintf(wwn+len, ALUA_SECONDARY_METADATA_WWN_LEN-len, "+%hu", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1281 | se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1282 | |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 1283 | len = snprintf(md_buf, ALUA_MD_BUF_LEN, "alua_tg_pt_offline=%d\n" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1284 | "alua_tg_pt_status=0x%02x\n", |
| 1285 | atomic_read(&port->sep_tg_pt_secondary_offline), |
| 1286 | port->sep_tg_pt_secondary_stat); |
| 1287 | |
| 1288 | snprintf(path, ALUA_METADATA_PATH_LEN, "/var/target/alua/%s/%s/lun_%u", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1289 | se_tpg->se_tpg_tfo->get_fabric_name(), wwn, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1290 | port->sep_lun->unpacked_lun); |
| 1291 | |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 1292 | rc = core_alua_write_tpg_metadata(path, md_buf, len); |
| 1293 | kfree(md_buf); |
| 1294 | |
| 1295 | return rc; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | static int core_alua_set_tg_pt_secondary_state( |
| 1299 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, |
| 1300 | struct se_port *port, |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1301 | int explicit, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1302 | int offline) |
| 1303 | { |
| 1304 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1305 | int trans_delay_msecs; |
| 1306 | |
| 1307 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1308 | tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1309 | if (!tg_pt_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1310 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1311 | pr_err("Unable to complete secondary state" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1312 | " transition\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1313 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1314 | } |
| 1315 | trans_delay_msecs = tg_pt_gp->tg_pt_gp_trans_delay_msecs; |
| 1316 | /* |
| 1317 | * Set the secondary ALUA target port access state to OFFLINE |
| 1318 | * or release the previously secondary state for struct se_port |
| 1319 | */ |
| 1320 | if (offline) |
| 1321 | atomic_set(&port->sep_tg_pt_secondary_offline, 1); |
| 1322 | else |
| 1323 | atomic_set(&port->sep_tg_pt_secondary_offline, 0); |
| 1324 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1325 | port->sep_tg_pt_secondary_stat = (explicit) ? |
| 1326 | ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG : |
| 1327 | ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1328 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1329 | pr_debug("Successful %s ALUA transition TG PT Group: %s ID: %hu" |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1330 | " to secondary access state: %s\n", (explicit) ? "explicit" : |
| 1331 | "implicit", config_item_name(&tg_pt_gp->tg_pt_gp_group.cg_item), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1332 | tg_pt_gp->tg_pt_gp_id, (offline) ? "OFFLINE" : "ONLINE"); |
| 1333 | |
| 1334 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1335 | /* |
| 1336 | * Do the optional transition delay after we set the secondary |
| 1337 | * ALUA access state. |
| 1338 | */ |
| 1339 | if (trans_delay_msecs != 0) |
| 1340 | msleep_interruptible(trans_delay_msecs); |
| 1341 | /* |
| 1342 | * See if we need to update the ALUA fabric port metadata for |
| 1343 | * secondary state and status |
| 1344 | */ |
| 1345 | if (port->sep_tg_pt_secondary_write_md) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1346 | mutex_lock(&port->sep_tg_pt_md_mutex); |
Hannes Reinecke | 1e0b940 | 2013-12-17 09:18:44 +0100 | [diff] [blame] | 1347 | core_alua_update_tpg_secondary_metadata(tg_pt_gp_mem, port); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1348 | mutex_unlock(&port->sep_tg_pt_md_mutex); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | return 0; |
| 1352 | } |
| 1353 | |
Hannes Reinecke | 229d4f1 | 2013-12-17 09:18:50 +0100 | [diff] [blame] | 1354 | struct t10_alua_lba_map * |
| 1355 | core_alua_allocate_lba_map(struct list_head *list, |
| 1356 | u64 first_lba, u64 last_lba) |
| 1357 | { |
| 1358 | struct t10_alua_lba_map *lba_map; |
| 1359 | |
| 1360 | lba_map = kmem_cache_zalloc(t10_alua_lba_map_cache, GFP_KERNEL); |
| 1361 | if (!lba_map) { |
| 1362 | pr_err("Unable to allocate struct t10_alua_lba_map\n"); |
| 1363 | return ERR_PTR(-ENOMEM); |
| 1364 | } |
| 1365 | INIT_LIST_HEAD(&lba_map->lba_map_mem_list); |
| 1366 | lba_map->lba_map_first_lba = first_lba; |
| 1367 | lba_map->lba_map_last_lba = last_lba; |
| 1368 | |
| 1369 | list_add_tail(&lba_map->lba_map_list, list); |
| 1370 | return lba_map; |
| 1371 | } |
| 1372 | |
| 1373 | int |
| 1374 | core_alua_allocate_lba_map_mem(struct t10_alua_lba_map *lba_map, |
| 1375 | int pg_id, int state) |
| 1376 | { |
| 1377 | struct t10_alua_lba_map_member *lba_map_mem; |
| 1378 | |
| 1379 | list_for_each_entry(lba_map_mem, &lba_map->lba_map_mem_list, |
| 1380 | lba_map_mem_list) { |
| 1381 | if (lba_map_mem->lba_map_mem_alua_pg_id == pg_id) { |
| 1382 | pr_err("Duplicate pg_id %d in lba_map\n", pg_id); |
| 1383 | return -EINVAL; |
| 1384 | } |
| 1385 | } |
| 1386 | |
| 1387 | lba_map_mem = kmem_cache_zalloc(t10_alua_lba_map_mem_cache, GFP_KERNEL); |
| 1388 | if (!lba_map_mem) { |
| 1389 | pr_err("Unable to allocate struct t10_alua_lba_map_mem\n"); |
| 1390 | return -ENOMEM; |
| 1391 | } |
| 1392 | lba_map_mem->lba_map_mem_alua_state = state; |
| 1393 | lba_map_mem->lba_map_mem_alua_pg_id = pg_id; |
| 1394 | |
| 1395 | list_add_tail(&lba_map_mem->lba_map_mem_list, |
| 1396 | &lba_map->lba_map_mem_list); |
| 1397 | return 0; |
| 1398 | } |
| 1399 | |
| 1400 | void |
| 1401 | core_alua_free_lba_map(struct list_head *lba_list) |
| 1402 | { |
| 1403 | struct t10_alua_lba_map *lba_map, *lba_map_tmp; |
| 1404 | struct t10_alua_lba_map_member *lba_map_mem, *lba_map_mem_tmp; |
| 1405 | |
| 1406 | list_for_each_entry_safe(lba_map, lba_map_tmp, lba_list, |
| 1407 | lba_map_list) { |
| 1408 | list_for_each_entry_safe(lba_map_mem, lba_map_mem_tmp, |
| 1409 | &lba_map->lba_map_mem_list, |
| 1410 | lba_map_mem_list) { |
| 1411 | list_del(&lba_map_mem->lba_map_mem_list); |
| 1412 | kmem_cache_free(t10_alua_lba_map_mem_cache, |
| 1413 | lba_map_mem); |
| 1414 | } |
| 1415 | list_del(&lba_map->lba_map_list); |
| 1416 | kmem_cache_free(t10_alua_lba_map_cache, lba_map); |
| 1417 | } |
| 1418 | } |
| 1419 | |
| 1420 | void |
| 1421 | core_alua_set_lba_map(struct se_device *dev, struct list_head *lba_map_list, |
| 1422 | int segment_size, int segment_mult) |
| 1423 | { |
| 1424 | struct list_head old_lba_map_list; |
| 1425 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 1426 | int activate = 0, supported; |
| 1427 | |
| 1428 | INIT_LIST_HEAD(&old_lba_map_list); |
| 1429 | spin_lock(&dev->t10_alua.lba_map_lock); |
| 1430 | dev->t10_alua.lba_map_segment_size = segment_size; |
| 1431 | dev->t10_alua.lba_map_segment_multiplier = segment_mult; |
| 1432 | list_splice_init(&dev->t10_alua.lba_map_list, &old_lba_map_list); |
| 1433 | if (lba_map_list) { |
| 1434 | list_splice_init(lba_map_list, &dev->t10_alua.lba_map_list); |
| 1435 | activate = 1; |
| 1436 | } |
| 1437 | spin_unlock(&dev->t10_alua.lba_map_lock); |
| 1438 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
| 1439 | list_for_each_entry(tg_pt_gp, &dev->t10_alua.tg_pt_gps_list, |
| 1440 | tg_pt_gp_list) { |
| 1441 | |
| 1442 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
| 1443 | continue; |
| 1444 | supported = tg_pt_gp->tg_pt_gp_alua_supported_states; |
| 1445 | if (activate) |
| 1446 | supported |= ALUA_LBD_SUP; |
| 1447 | else |
| 1448 | supported &= ~ALUA_LBD_SUP; |
| 1449 | tg_pt_gp->tg_pt_gp_alua_supported_states = supported; |
| 1450 | } |
| 1451 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
| 1452 | core_alua_free_lba_map(&old_lba_map_list); |
| 1453 | } |
| 1454 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1455 | struct t10_alua_lu_gp * |
| 1456 | core_alua_allocate_lu_gp(const char *name, int def_group) |
| 1457 | { |
| 1458 | struct t10_alua_lu_gp *lu_gp; |
| 1459 | |
| 1460 | lu_gp = kmem_cache_zalloc(t10_alua_lu_gp_cache, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1461 | if (!lu_gp) { |
| 1462 | pr_err("Unable to allocate struct t10_alua_lu_gp\n"); |
Justin P. Mattock | 6eab04a | 2011-04-08 19:49:08 -0700 | [diff] [blame] | 1463 | return ERR_PTR(-ENOMEM); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1464 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1465 | INIT_LIST_HEAD(&lu_gp->lu_gp_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1466 | INIT_LIST_HEAD(&lu_gp->lu_gp_mem_list); |
| 1467 | spin_lock_init(&lu_gp->lu_gp_lock); |
| 1468 | atomic_set(&lu_gp->lu_gp_ref_cnt, 0); |
| 1469 | |
| 1470 | if (def_group) { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1471 | lu_gp->lu_gp_id = alua_lu_gps_counter++; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1472 | lu_gp->lu_gp_valid_id = 1; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1473 | alua_lu_gps_count++; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | return lu_gp; |
| 1477 | } |
| 1478 | |
| 1479 | int core_alua_set_lu_gp_id(struct t10_alua_lu_gp *lu_gp, u16 lu_gp_id) |
| 1480 | { |
| 1481 | struct t10_alua_lu_gp *lu_gp_tmp; |
| 1482 | u16 lu_gp_id_tmp; |
| 1483 | /* |
| 1484 | * The lu_gp->lu_gp_id may only be set once.. |
| 1485 | */ |
| 1486 | if (lu_gp->lu_gp_valid_id) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1487 | pr_warn("ALUA LU Group already has a valid ID," |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1488 | " ignoring request\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1489 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1490 | } |
| 1491 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1492 | spin_lock(&lu_gps_lock); |
| 1493 | if (alua_lu_gps_count == 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1494 | pr_err("Maximum ALUA alua_lu_gps_count:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1495 | " 0x0000ffff reached\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1496 | spin_unlock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1497 | kmem_cache_free(t10_alua_lu_gp_cache, lu_gp); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1498 | return -ENOSPC; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1499 | } |
| 1500 | again: |
| 1501 | lu_gp_id_tmp = (lu_gp_id != 0) ? lu_gp_id : |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1502 | alua_lu_gps_counter++; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1503 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1504 | list_for_each_entry(lu_gp_tmp, &lu_gps_list, lu_gp_node) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1505 | if (lu_gp_tmp->lu_gp_id == lu_gp_id_tmp) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1506 | if (!lu_gp_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1507 | goto again; |
| 1508 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1509 | pr_warn("ALUA Logical Unit Group ID: %hu" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1510 | " already exists, ignoring request\n", |
| 1511 | lu_gp_id); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1512 | spin_unlock(&lu_gps_lock); |
| 1513 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1514 | } |
| 1515 | } |
| 1516 | |
| 1517 | lu_gp->lu_gp_id = lu_gp_id_tmp; |
| 1518 | lu_gp->lu_gp_valid_id = 1; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1519 | list_add_tail(&lu_gp->lu_gp_node, &lu_gps_list); |
| 1520 | alua_lu_gps_count++; |
| 1521 | spin_unlock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1522 | |
| 1523 | return 0; |
| 1524 | } |
| 1525 | |
| 1526 | static struct t10_alua_lu_gp_member * |
| 1527 | core_alua_allocate_lu_gp_mem(struct se_device *dev) |
| 1528 | { |
| 1529 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1530 | |
| 1531 | lu_gp_mem = kmem_cache_zalloc(t10_alua_lu_gp_mem_cache, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1532 | if (!lu_gp_mem) { |
| 1533 | pr_err("Unable to allocate struct t10_alua_lu_gp_member\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1534 | return ERR_PTR(-ENOMEM); |
| 1535 | } |
| 1536 | INIT_LIST_HEAD(&lu_gp_mem->lu_gp_mem_list); |
| 1537 | spin_lock_init(&lu_gp_mem->lu_gp_mem_lock); |
| 1538 | atomic_set(&lu_gp_mem->lu_gp_mem_ref_cnt, 0); |
| 1539 | |
| 1540 | lu_gp_mem->lu_gp_mem_dev = dev; |
| 1541 | dev->dev_alua_lu_gp_mem = lu_gp_mem; |
| 1542 | |
| 1543 | return lu_gp_mem; |
| 1544 | } |
| 1545 | |
| 1546 | void core_alua_free_lu_gp(struct t10_alua_lu_gp *lu_gp) |
| 1547 | { |
| 1548 | struct t10_alua_lu_gp_member *lu_gp_mem, *lu_gp_mem_tmp; |
| 1549 | /* |
| 1550 | * Once we have reached this point, config_item_put() has |
| 1551 | * already been called from target_core_alua_drop_lu_gp(). |
| 1552 | * |
| 1553 | * Here, we remove the *lu_gp from the global list so that |
| 1554 | * no associations can be made while we are releasing |
| 1555 | * struct t10_alua_lu_gp. |
| 1556 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1557 | spin_lock(&lu_gps_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1558 | list_del(&lu_gp->lu_gp_node); |
| 1559 | alua_lu_gps_count--; |
| 1560 | spin_unlock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1561 | /* |
| 1562 | * Allow struct t10_alua_lu_gp * referenced by core_alua_get_lu_gp_by_name() |
| 1563 | * in target_core_configfs.c:target_core_store_alua_lu_gp() to be |
| 1564 | * released with core_alua_put_lu_gp_from_name() |
| 1565 | */ |
| 1566 | while (atomic_read(&lu_gp->lu_gp_ref_cnt)) |
| 1567 | cpu_relax(); |
| 1568 | /* |
| 1569 | * Release reference to struct t10_alua_lu_gp * from all associated |
| 1570 | * struct se_device. |
| 1571 | */ |
| 1572 | spin_lock(&lu_gp->lu_gp_lock); |
| 1573 | list_for_each_entry_safe(lu_gp_mem, lu_gp_mem_tmp, |
| 1574 | &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { |
| 1575 | if (lu_gp_mem->lu_gp_assoc) { |
| 1576 | list_del(&lu_gp_mem->lu_gp_mem_list); |
| 1577 | lu_gp->lu_gp_members--; |
| 1578 | lu_gp_mem->lu_gp_assoc = 0; |
| 1579 | } |
| 1580 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1581 | /* |
| 1582 | * |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1583 | * lu_gp_mem is associated with a single |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1584 | * struct se_device->dev_alua_lu_gp_mem, and is released when |
| 1585 | * struct se_device is released via core_alua_free_lu_gp_mem(). |
| 1586 | * |
| 1587 | * If the passed lu_gp does NOT match the default_lu_gp, assume |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 1588 | * we want to re-associate a given lu_gp_mem with default_lu_gp. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1589 | */ |
| 1590 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1591 | if (lu_gp != default_lu_gp) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1592 | __core_alua_attach_lu_gp_mem(lu_gp_mem, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1593 | default_lu_gp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1594 | else |
| 1595 | lu_gp_mem->lu_gp = NULL; |
| 1596 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1597 | |
| 1598 | spin_lock(&lu_gp->lu_gp_lock); |
| 1599 | } |
| 1600 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1601 | |
| 1602 | kmem_cache_free(t10_alua_lu_gp_cache, lu_gp); |
| 1603 | } |
| 1604 | |
| 1605 | void core_alua_free_lu_gp_mem(struct se_device *dev) |
| 1606 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1607 | struct t10_alua_lu_gp *lu_gp; |
| 1608 | struct t10_alua_lu_gp_member *lu_gp_mem; |
| 1609 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1610 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1611 | if (!lu_gp_mem) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1612 | return; |
| 1613 | |
| 1614 | while (atomic_read(&lu_gp_mem->lu_gp_mem_ref_cnt)) |
| 1615 | cpu_relax(); |
| 1616 | |
| 1617 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 1618 | lu_gp = lu_gp_mem->lu_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1619 | if (lu_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1620 | spin_lock(&lu_gp->lu_gp_lock); |
| 1621 | if (lu_gp_mem->lu_gp_assoc) { |
| 1622 | list_del(&lu_gp_mem->lu_gp_mem_list); |
| 1623 | lu_gp->lu_gp_members--; |
| 1624 | lu_gp_mem->lu_gp_assoc = 0; |
| 1625 | } |
| 1626 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1627 | lu_gp_mem->lu_gp = NULL; |
| 1628 | } |
| 1629 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 1630 | |
| 1631 | kmem_cache_free(t10_alua_lu_gp_mem_cache, lu_gp_mem); |
| 1632 | } |
| 1633 | |
| 1634 | struct t10_alua_lu_gp *core_alua_get_lu_gp_by_name(const char *name) |
| 1635 | { |
| 1636 | struct t10_alua_lu_gp *lu_gp; |
| 1637 | struct config_item *ci; |
| 1638 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1639 | spin_lock(&lu_gps_lock); |
| 1640 | list_for_each_entry(lu_gp, &lu_gps_list, lu_gp_node) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1641 | if (!lu_gp->lu_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1642 | continue; |
| 1643 | ci = &lu_gp->lu_gp_group.cg_item; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1644 | if (!strcmp(config_item_name(ci), name)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1645 | atomic_inc(&lu_gp->lu_gp_ref_cnt); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1646 | spin_unlock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1647 | return lu_gp; |
| 1648 | } |
| 1649 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1650 | spin_unlock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1651 | |
| 1652 | return NULL; |
| 1653 | } |
| 1654 | |
| 1655 | void core_alua_put_lu_gp_from_name(struct t10_alua_lu_gp *lu_gp) |
| 1656 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1657 | spin_lock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1658 | atomic_dec(&lu_gp->lu_gp_ref_cnt); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1659 | spin_unlock(&lu_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | /* |
| 1663 | * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock |
| 1664 | */ |
| 1665 | void __core_alua_attach_lu_gp_mem( |
| 1666 | struct t10_alua_lu_gp_member *lu_gp_mem, |
| 1667 | struct t10_alua_lu_gp *lu_gp) |
| 1668 | { |
| 1669 | spin_lock(&lu_gp->lu_gp_lock); |
| 1670 | lu_gp_mem->lu_gp = lu_gp; |
| 1671 | lu_gp_mem->lu_gp_assoc = 1; |
| 1672 | list_add_tail(&lu_gp_mem->lu_gp_mem_list, &lu_gp->lu_gp_mem_list); |
| 1673 | lu_gp->lu_gp_members++; |
| 1674 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1675 | } |
| 1676 | |
| 1677 | /* |
| 1678 | * Called with struct t10_alua_lu_gp_member->lu_gp_mem_lock |
| 1679 | */ |
| 1680 | void __core_alua_drop_lu_gp_mem( |
| 1681 | struct t10_alua_lu_gp_member *lu_gp_mem, |
| 1682 | struct t10_alua_lu_gp *lu_gp) |
| 1683 | { |
| 1684 | spin_lock(&lu_gp->lu_gp_lock); |
| 1685 | list_del(&lu_gp_mem->lu_gp_mem_list); |
| 1686 | lu_gp_mem->lu_gp = NULL; |
| 1687 | lu_gp_mem->lu_gp_assoc = 0; |
| 1688 | lu_gp->lu_gp_members--; |
| 1689 | spin_unlock(&lu_gp->lu_gp_lock); |
| 1690 | } |
| 1691 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1692 | struct t10_alua_tg_pt_gp *core_alua_allocate_tg_pt_gp(struct se_device *dev, |
| 1693 | const char *name, int def_group) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1694 | { |
| 1695 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 1696 | |
| 1697 | tg_pt_gp = kmem_cache_zalloc(t10_alua_tg_pt_gp_cache, GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1698 | if (!tg_pt_gp) { |
| 1699 | pr_err("Unable to allocate struct t10_alua_tg_pt_gp\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1700 | return NULL; |
| 1701 | } |
| 1702 | INIT_LIST_HEAD(&tg_pt_gp->tg_pt_gp_list); |
| 1703 | INIT_LIST_HEAD(&tg_pt_gp->tg_pt_gp_mem_list); |
| 1704 | mutex_init(&tg_pt_gp->tg_pt_gp_md_mutex); |
| 1705 | spin_lock_init(&tg_pt_gp->tg_pt_gp_lock); |
| 1706 | atomic_set(&tg_pt_gp->tg_pt_gp_ref_cnt, 0); |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1707 | INIT_DELAYED_WORK(&tg_pt_gp->tg_pt_gp_transition_work, |
| 1708 | core_alua_do_transition_tg_pt_work); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1709 | tg_pt_gp->tg_pt_gp_dev = dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1710 | atomic_set(&tg_pt_gp->tg_pt_gp_alua_access_state, |
Hannes Reinecke | 73f3bf5 | 2013-11-19 09:07:48 +0100 | [diff] [blame] | 1711 | ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1712 | /* |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1713 | * Enable both explicit and implicit ALUA support by default |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1714 | */ |
| 1715 | tg_pt_gp->tg_pt_gp_alua_access_type = |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1716 | TPGS_EXPLICIT_ALUA | TPGS_IMPLICIT_ALUA; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1717 | /* |
| 1718 | * Set the default Active/NonOptimized Delay in milliseconds |
| 1719 | */ |
| 1720 | tg_pt_gp->tg_pt_gp_nonop_delay_msecs = ALUA_DEFAULT_NONOP_DELAY_MSECS; |
| 1721 | tg_pt_gp->tg_pt_gp_trans_delay_msecs = ALUA_DEFAULT_TRANS_DELAY_MSECS; |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 1722 | tg_pt_gp->tg_pt_gp_implicit_trans_secs = ALUA_DEFAULT_IMPLICIT_TRANS_SECS; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1723 | |
Hannes Reinecke | c0dc941 | 2013-11-19 09:07:49 +0100 | [diff] [blame] | 1724 | /* |
| 1725 | * Enable all supported states |
| 1726 | */ |
| 1727 | tg_pt_gp->tg_pt_gp_alua_supported_states = |
| 1728 | ALUA_T_SUP | ALUA_O_SUP | |
| 1729 | ALUA_U_SUP | ALUA_S_SUP | ALUA_AN_SUP | ALUA_AO_SUP; |
| 1730 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1731 | if (def_group) { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1732 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1733 | tg_pt_gp->tg_pt_gp_id = |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1734 | dev->t10_alua.alua_tg_pt_gps_counter++; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1735 | tg_pt_gp->tg_pt_gp_valid_id = 1; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1736 | dev->t10_alua.alua_tg_pt_gps_count++; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1737 | list_add_tail(&tg_pt_gp->tg_pt_gp_list, |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1738 | &dev->t10_alua.tg_pt_gps_list); |
| 1739 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1740 | } |
| 1741 | |
| 1742 | return tg_pt_gp; |
| 1743 | } |
| 1744 | |
| 1745 | int core_alua_set_tg_pt_gp_id( |
| 1746 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 1747 | u16 tg_pt_gp_id) |
| 1748 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1749 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1750 | struct t10_alua_tg_pt_gp *tg_pt_gp_tmp; |
| 1751 | u16 tg_pt_gp_id_tmp; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1752 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1753 | /* |
| 1754 | * The tg_pt_gp->tg_pt_gp_id may only be set once.. |
| 1755 | */ |
| 1756 | if (tg_pt_gp->tg_pt_gp_valid_id) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1757 | pr_warn("ALUA TG PT Group already has a valid ID," |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1758 | " ignoring request\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1759 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1760 | } |
| 1761 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1762 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
| 1763 | if (dev->t10_alua.alua_tg_pt_gps_count == 0x0000ffff) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1764 | pr_err("Maximum ALUA alua_tg_pt_gps_count:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1765 | " 0x0000ffff reached\n"); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1766 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1767 | kmem_cache_free(t10_alua_tg_pt_gp_cache, tg_pt_gp); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1768 | return -ENOSPC; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1769 | } |
| 1770 | again: |
| 1771 | tg_pt_gp_id_tmp = (tg_pt_gp_id != 0) ? tg_pt_gp_id : |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1772 | dev->t10_alua.alua_tg_pt_gps_counter++; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1773 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1774 | list_for_each_entry(tg_pt_gp_tmp, &dev->t10_alua.tg_pt_gps_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1775 | tg_pt_gp_list) { |
| 1776 | if (tg_pt_gp_tmp->tg_pt_gp_id == tg_pt_gp_id_tmp) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1777 | if (!tg_pt_gp_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1778 | goto again; |
| 1779 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1780 | pr_err("ALUA Target Port Group ID: %hu already" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1781 | " exists, ignoring request\n", tg_pt_gp_id); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1782 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1783 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1784 | } |
| 1785 | } |
| 1786 | |
| 1787 | tg_pt_gp->tg_pt_gp_id = tg_pt_gp_id_tmp; |
| 1788 | tg_pt_gp->tg_pt_gp_valid_id = 1; |
| 1789 | list_add_tail(&tg_pt_gp->tg_pt_gp_list, |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1790 | &dev->t10_alua.tg_pt_gps_list); |
| 1791 | dev->t10_alua.alua_tg_pt_gps_count++; |
| 1792 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1793 | |
| 1794 | return 0; |
| 1795 | } |
| 1796 | |
| 1797 | struct t10_alua_tg_pt_gp_member *core_alua_allocate_tg_pt_gp_mem( |
| 1798 | struct se_port *port) |
| 1799 | { |
| 1800 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 1801 | |
| 1802 | tg_pt_gp_mem = kmem_cache_zalloc(t10_alua_tg_pt_gp_mem_cache, |
| 1803 | GFP_KERNEL); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1804 | if (!tg_pt_gp_mem) { |
| 1805 | pr_err("Unable to allocate struct t10_alua_tg_pt_gp_member\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1806 | return ERR_PTR(-ENOMEM); |
| 1807 | } |
| 1808 | INIT_LIST_HEAD(&tg_pt_gp_mem->tg_pt_gp_mem_list); |
| 1809 | spin_lock_init(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1810 | atomic_set(&tg_pt_gp_mem->tg_pt_gp_mem_ref_cnt, 0); |
| 1811 | |
| 1812 | tg_pt_gp_mem->tg_pt = port; |
| 1813 | port->sep_alua_tg_pt_gp_mem = tg_pt_gp_mem; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1814 | |
| 1815 | return tg_pt_gp_mem; |
| 1816 | } |
| 1817 | |
| 1818 | void core_alua_free_tg_pt_gp( |
| 1819 | struct t10_alua_tg_pt_gp *tg_pt_gp) |
| 1820 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1821 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1822 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, *tg_pt_gp_mem_tmp; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1823 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1824 | /* |
| 1825 | * Once we have reached this point, config_item_put() has already |
| 1826 | * been called from target_core_alua_drop_tg_pt_gp(). |
| 1827 | * |
| 1828 | * Here we remove *tg_pt_gp from the global list so that |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 1829 | * no associations *OR* explicit ALUA via SET_TARGET_PORT_GROUPS |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1830 | * can be made while we are releasing struct t10_alua_tg_pt_gp. |
| 1831 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1832 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1833 | list_del(&tg_pt_gp->tg_pt_gp_list); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1834 | dev->t10_alua.alua_tg_pt_gps_counter--; |
| 1835 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
| 1836 | |
Hannes Reinecke | 9c6e164 | 2013-12-17 09:18:46 +0100 | [diff] [blame] | 1837 | flush_delayed_work(&tg_pt_gp->tg_pt_gp_transition_work); |
| 1838 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1839 | /* |
| 1840 | * Allow a struct t10_alua_tg_pt_gp_member * referenced by |
| 1841 | * core_alua_get_tg_pt_gp_by_name() in |
| 1842 | * target_core_configfs.c:target_core_store_alua_tg_pt_gp() |
| 1843 | * to be released with core_alua_put_tg_pt_gp_from_name(). |
| 1844 | */ |
| 1845 | while (atomic_read(&tg_pt_gp->tg_pt_gp_ref_cnt)) |
| 1846 | cpu_relax(); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1847 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1848 | /* |
| 1849 | * Release reference to struct t10_alua_tg_pt_gp from all associated |
| 1850 | * struct se_port. |
| 1851 | */ |
| 1852 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 1853 | list_for_each_entry_safe(tg_pt_gp_mem, tg_pt_gp_mem_tmp, |
| 1854 | &tg_pt_gp->tg_pt_gp_mem_list, tg_pt_gp_mem_list) { |
| 1855 | if (tg_pt_gp_mem->tg_pt_gp_assoc) { |
| 1856 | list_del(&tg_pt_gp_mem->tg_pt_gp_mem_list); |
| 1857 | tg_pt_gp->tg_pt_gp_members--; |
| 1858 | tg_pt_gp_mem->tg_pt_gp_assoc = 0; |
| 1859 | } |
| 1860 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1861 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1862 | * tg_pt_gp_mem is associated with a single |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1863 | * se_port->sep_alua_tg_pt_gp_mem, and is released via |
| 1864 | * core_alua_free_tg_pt_gp_mem(). |
| 1865 | * |
| 1866 | * If the passed tg_pt_gp does NOT match the default_tg_pt_gp, |
Hannes Reinecke | f1ae05d | 2013-11-19 09:07:47 +0100 | [diff] [blame] | 1867 | * assume we want to re-associate a given tg_pt_gp_mem with |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1868 | * default_tg_pt_gp. |
| 1869 | */ |
| 1870 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1871 | if (tg_pt_gp != dev->t10_alua.default_tg_pt_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1872 | __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1873 | dev->t10_alua.default_tg_pt_gp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1874 | } else |
| 1875 | tg_pt_gp_mem->tg_pt_gp = NULL; |
| 1876 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1877 | |
| 1878 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 1879 | } |
| 1880 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1881 | |
| 1882 | kmem_cache_free(t10_alua_tg_pt_gp_cache, tg_pt_gp); |
| 1883 | } |
| 1884 | |
| 1885 | void core_alua_free_tg_pt_gp_mem(struct se_port *port) |
| 1886 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1887 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 1888 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 1889 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1890 | tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1891 | if (!tg_pt_gp_mem) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1892 | return; |
| 1893 | |
| 1894 | while (atomic_read(&tg_pt_gp_mem->tg_pt_gp_mem_ref_cnt)) |
| 1895 | cpu_relax(); |
| 1896 | |
| 1897 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1898 | tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1899 | if (tg_pt_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1900 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 1901 | if (tg_pt_gp_mem->tg_pt_gp_assoc) { |
| 1902 | list_del(&tg_pt_gp_mem->tg_pt_gp_mem_list); |
| 1903 | tg_pt_gp->tg_pt_gp_members--; |
| 1904 | tg_pt_gp_mem->tg_pt_gp_assoc = 0; |
| 1905 | } |
| 1906 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1907 | tg_pt_gp_mem->tg_pt_gp = NULL; |
| 1908 | } |
| 1909 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1910 | |
| 1911 | kmem_cache_free(t10_alua_tg_pt_gp_mem_cache, tg_pt_gp_mem); |
| 1912 | } |
| 1913 | |
| 1914 | static struct t10_alua_tg_pt_gp *core_alua_get_tg_pt_gp_by_name( |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1915 | struct se_device *dev, const char *name) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1916 | { |
| 1917 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 1918 | struct config_item *ci; |
| 1919 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1920 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
| 1921 | list_for_each_entry(tg_pt_gp, &dev->t10_alua.tg_pt_gps_list, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1922 | tg_pt_gp_list) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1923 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1924 | continue; |
| 1925 | ci = &tg_pt_gp->tg_pt_gp_group.cg_item; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1926 | if (!strcmp(config_item_name(ci), name)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1927 | atomic_inc(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1928 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1929 | return tg_pt_gp; |
| 1930 | } |
| 1931 | } |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1932 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1933 | |
| 1934 | return NULL; |
| 1935 | } |
| 1936 | |
| 1937 | static void core_alua_put_tg_pt_gp_from_name( |
| 1938 | struct t10_alua_tg_pt_gp *tg_pt_gp) |
| 1939 | { |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1940 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1941 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1942 | spin_lock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1943 | atomic_dec(&tg_pt_gp->tg_pt_gp_ref_cnt); |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 1944 | spin_unlock(&dev->t10_alua.tg_pt_gps_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1945 | } |
| 1946 | |
| 1947 | /* |
| 1948 | * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held |
| 1949 | */ |
| 1950 | void __core_alua_attach_tg_pt_gp_mem( |
| 1951 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, |
| 1952 | struct t10_alua_tg_pt_gp *tg_pt_gp) |
| 1953 | { |
| 1954 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 1955 | tg_pt_gp_mem->tg_pt_gp = tg_pt_gp; |
| 1956 | tg_pt_gp_mem->tg_pt_gp_assoc = 1; |
| 1957 | list_add_tail(&tg_pt_gp_mem->tg_pt_gp_mem_list, |
| 1958 | &tg_pt_gp->tg_pt_gp_mem_list); |
| 1959 | tg_pt_gp->tg_pt_gp_members++; |
| 1960 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1961 | } |
| 1962 | |
| 1963 | /* |
| 1964 | * Called with struct t10_alua_tg_pt_gp_member->tg_pt_gp_mem_lock held |
| 1965 | */ |
| 1966 | static void __core_alua_drop_tg_pt_gp_mem( |
| 1967 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem, |
| 1968 | struct t10_alua_tg_pt_gp *tg_pt_gp) |
| 1969 | { |
| 1970 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); |
| 1971 | list_del(&tg_pt_gp_mem->tg_pt_gp_mem_list); |
| 1972 | tg_pt_gp_mem->tg_pt_gp = NULL; |
| 1973 | tg_pt_gp_mem->tg_pt_gp_assoc = 0; |
| 1974 | tg_pt_gp->tg_pt_gp_members--; |
| 1975 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); |
| 1976 | } |
| 1977 | |
| 1978 | ssize_t core_alua_show_tg_pt_gp_info(struct se_port *port, char *page) |
| 1979 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1980 | struct config_item *tg_pt_ci; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1981 | struct t10_alua_tg_pt_gp *tg_pt_gp; |
| 1982 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 1983 | ssize_t len = 0; |
| 1984 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1985 | tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1986 | if (!tg_pt_gp_mem) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1987 | return len; |
| 1988 | |
| 1989 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 1990 | tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 1991 | if (tg_pt_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1992 | tg_pt_ci = &tg_pt_gp->tg_pt_gp_group.cg_item; |
| 1993 | len += sprintf(page, "TG Port Alias: %s\nTG Port Group ID:" |
| 1994 | " %hu\nTG Port Primary Access State: %s\nTG Port " |
| 1995 | "Primary Access Status: %s\nTG Port Secondary Access" |
| 1996 | " State: %s\nTG Port Secondary Access Status: %s\n", |
| 1997 | config_item_name(tg_pt_ci), tg_pt_gp->tg_pt_gp_id, |
| 1998 | core_alua_dump_state(atomic_read( |
| 1999 | &tg_pt_gp->tg_pt_gp_alua_access_state)), |
| 2000 | core_alua_dump_status( |
| 2001 | tg_pt_gp->tg_pt_gp_alua_access_status), |
| 2002 | (atomic_read(&port->sep_tg_pt_secondary_offline)) ? |
| 2003 | "Offline" : "None", |
| 2004 | core_alua_dump_status(port->sep_tg_pt_secondary_stat)); |
| 2005 | } |
| 2006 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 2007 | |
| 2008 | return len; |
| 2009 | } |
| 2010 | |
| 2011 | ssize_t core_alua_store_tg_pt_gp_info( |
| 2012 | struct se_port *port, |
| 2013 | const char *page, |
| 2014 | size_t count) |
| 2015 | { |
| 2016 | struct se_portal_group *tpg; |
| 2017 | struct se_lun *lun; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2018 | struct se_device *dev = port->sep_lun->lun_se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2019 | struct t10_alua_tg_pt_gp *tg_pt_gp = NULL, *tg_pt_gp_new = NULL; |
| 2020 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 2021 | unsigned char buf[TG_PT_GROUP_NAME_BUF]; |
| 2022 | int move = 0; |
| 2023 | |
| 2024 | tpg = port->sep_tpg; |
| 2025 | lun = port->sep_lun; |
| 2026 | |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 2027 | tg_pt_gp_mem = port->sep_alua_tg_pt_gp_mem; |
| 2028 | if (!tg_pt_gp_mem) |
| 2029 | return 0; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2030 | |
| 2031 | if (count > TG_PT_GROUP_NAME_BUF) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2032 | pr_err("ALUA Target Port Group alias too large!\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2033 | return -EINVAL; |
| 2034 | } |
| 2035 | memset(buf, 0, TG_PT_GROUP_NAME_BUF); |
| 2036 | memcpy(buf, page, count); |
| 2037 | /* |
| 2038 | * Any ALUA target port group alias besides "NULL" means we will be |
| 2039 | * making a new group association. |
| 2040 | */ |
| 2041 | if (strcmp(strstrip(buf), "NULL")) { |
| 2042 | /* |
| 2043 | * core_alua_get_tg_pt_gp_by_name() will increment reference to |
| 2044 | * struct t10_alua_tg_pt_gp. This reference is released with |
| 2045 | * core_alua_put_tg_pt_gp_from_name() below. |
| 2046 | */ |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2047 | tg_pt_gp_new = core_alua_get_tg_pt_gp_by_name(dev, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2048 | strstrip(buf)); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2049 | if (!tg_pt_gp_new) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2050 | return -ENODEV; |
| 2051 | } |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2052 | |
| 2053 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 2054 | tg_pt_gp = tg_pt_gp_mem->tg_pt_gp; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2055 | if (tg_pt_gp) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2056 | /* |
| 2057 | * Clearing an existing tg_pt_gp association, and replacing |
| 2058 | * with the default_tg_pt_gp. |
| 2059 | */ |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2060 | if (!tg_pt_gp_new) { |
| 2061 | pr_debug("Target_Core_ConfigFS: Moving" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2062 | " %s/tpgt_%hu/%s from ALUA Target Port Group:" |
| 2063 | " alua/%s, ID: %hu back to" |
| 2064 | " default_tg_pt_gp\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2065 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 2066 | tpg->se_tpg_tfo->tpg_get_tag(tpg), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2067 | config_item_name(&lun->lun_group.cg_item), |
| 2068 | config_item_name( |
| 2069 | &tg_pt_gp->tg_pt_gp_group.cg_item), |
| 2070 | tg_pt_gp->tg_pt_gp_id); |
| 2071 | |
| 2072 | __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem, tg_pt_gp); |
| 2073 | __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2074 | dev->t10_alua.default_tg_pt_gp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2075 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 2076 | |
| 2077 | return count; |
| 2078 | } |
| 2079 | /* |
| 2080 | * Removing existing association of tg_pt_gp_mem with tg_pt_gp |
| 2081 | */ |
| 2082 | __core_alua_drop_tg_pt_gp_mem(tg_pt_gp_mem, tg_pt_gp); |
| 2083 | move = 1; |
| 2084 | } |
| 2085 | /* |
| 2086 | * Associate tg_pt_gp_mem with tg_pt_gp_new. |
| 2087 | */ |
| 2088 | __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, tg_pt_gp_new); |
| 2089 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2090 | pr_debug("Target_Core_ConfigFS: %s %s/tpgt_%hu/%s to ALUA" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2091 | " Target Port Group: alua/%s, ID: %hu\n", (move) ? |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2092 | "Moving" : "Adding", tpg->se_tpg_tfo->tpg_get_wwn(tpg), |
| 2093 | tpg->se_tpg_tfo->tpg_get_tag(tpg), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2094 | config_item_name(&lun->lun_group.cg_item), |
| 2095 | config_item_name(&tg_pt_gp_new->tg_pt_gp_group.cg_item), |
| 2096 | tg_pt_gp_new->tg_pt_gp_id); |
| 2097 | |
| 2098 | core_alua_put_tg_pt_gp_from_name(tg_pt_gp_new); |
| 2099 | return count; |
| 2100 | } |
| 2101 | |
| 2102 | ssize_t core_alua_show_access_type( |
| 2103 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2104 | char *page) |
| 2105 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2106 | if ((tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA) && |
| 2107 | (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA)) |
| 2108 | return sprintf(page, "Implicit and Explicit\n"); |
| 2109 | else if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA) |
| 2110 | return sprintf(page, "Implicit\n"); |
| 2111 | else if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA) |
| 2112 | return sprintf(page, "Explicit\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2113 | else |
| 2114 | return sprintf(page, "None\n"); |
| 2115 | } |
| 2116 | |
| 2117 | ssize_t core_alua_store_access_type( |
| 2118 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2119 | const char *page, |
| 2120 | size_t count) |
| 2121 | { |
| 2122 | unsigned long tmp; |
| 2123 | int ret; |
| 2124 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2125 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2126 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2127 | pr_err("Unable to extract alua_access_type\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2128 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2129 | } |
| 2130 | if ((tmp != 0) && (tmp != 1) && (tmp != 2) && (tmp != 3)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2131 | pr_err("Illegal value for alua_access_type:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2132 | " %lu\n", tmp); |
| 2133 | return -EINVAL; |
| 2134 | } |
| 2135 | if (tmp == 3) |
| 2136 | tg_pt_gp->tg_pt_gp_alua_access_type = |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2137 | TPGS_IMPLICIT_ALUA | TPGS_EXPLICIT_ALUA; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2138 | else if (tmp == 2) |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2139 | tg_pt_gp->tg_pt_gp_alua_access_type = TPGS_EXPLICIT_ALUA; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2140 | else if (tmp == 1) |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2141 | tg_pt_gp->tg_pt_gp_alua_access_type = TPGS_IMPLICIT_ALUA; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2142 | else |
| 2143 | tg_pt_gp->tg_pt_gp_alua_access_type = 0; |
| 2144 | |
| 2145 | return count; |
| 2146 | } |
| 2147 | |
| 2148 | ssize_t core_alua_show_nonop_delay_msecs( |
| 2149 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2150 | char *page) |
| 2151 | { |
| 2152 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_nonop_delay_msecs); |
| 2153 | } |
| 2154 | |
| 2155 | ssize_t core_alua_store_nonop_delay_msecs( |
| 2156 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2157 | const char *page, |
| 2158 | size_t count) |
| 2159 | { |
| 2160 | unsigned long tmp; |
| 2161 | int ret; |
| 2162 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2163 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2164 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2165 | pr_err("Unable to extract nonop_delay_msecs\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2166 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2167 | } |
| 2168 | if (tmp > ALUA_MAX_NONOP_DELAY_MSECS) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2169 | pr_err("Passed nonop_delay_msecs: %lu, exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2170 | " ALUA_MAX_NONOP_DELAY_MSECS: %d\n", tmp, |
| 2171 | ALUA_MAX_NONOP_DELAY_MSECS); |
| 2172 | return -EINVAL; |
| 2173 | } |
| 2174 | tg_pt_gp->tg_pt_gp_nonop_delay_msecs = (int)tmp; |
| 2175 | |
| 2176 | return count; |
| 2177 | } |
| 2178 | |
| 2179 | ssize_t core_alua_show_trans_delay_msecs( |
| 2180 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2181 | char *page) |
| 2182 | { |
| 2183 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_trans_delay_msecs); |
| 2184 | } |
| 2185 | |
| 2186 | ssize_t core_alua_store_trans_delay_msecs( |
| 2187 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2188 | const char *page, |
| 2189 | size_t count) |
| 2190 | { |
| 2191 | unsigned long tmp; |
| 2192 | int ret; |
| 2193 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2194 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2195 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2196 | pr_err("Unable to extract trans_delay_msecs\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2197 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2198 | } |
| 2199 | if (tmp > ALUA_MAX_TRANS_DELAY_MSECS) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2200 | pr_err("Passed trans_delay_msecs: %lu, exceeds" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2201 | " ALUA_MAX_TRANS_DELAY_MSECS: %d\n", tmp, |
| 2202 | ALUA_MAX_TRANS_DELAY_MSECS); |
| 2203 | return -EINVAL; |
| 2204 | } |
| 2205 | tg_pt_gp->tg_pt_gp_trans_delay_msecs = (int)tmp; |
| 2206 | |
| 2207 | return count; |
| 2208 | } |
| 2209 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2210 | ssize_t core_alua_show_implicit_trans_secs( |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2211 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2212 | char *page) |
| 2213 | { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2214 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_implicit_trans_secs); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2215 | } |
| 2216 | |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2217 | ssize_t core_alua_store_implicit_trans_secs( |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2218 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2219 | const char *page, |
| 2220 | size_t count) |
| 2221 | { |
| 2222 | unsigned long tmp; |
| 2223 | int ret; |
| 2224 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2225 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2226 | if (ret < 0) { |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2227 | pr_err("Unable to extract implicit_trans_secs\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2228 | return ret; |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2229 | } |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2230 | if (tmp > ALUA_MAX_IMPLICIT_TRANS_SECS) { |
| 2231 | pr_err("Passed implicit_trans_secs: %lu, exceeds" |
| 2232 | " ALUA_MAX_IMPLICIT_TRANS_SECS: %d\n", tmp, |
| 2233 | ALUA_MAX_IMPLICIT_TRANS_SECS); |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2234 | return -EINVAL; |
| 2235 | } |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2236 | tg_pt_gp->tg_pt_gp_implicit_trans_secs = (int)tmp; |
Nicholas Bellinger | 5b9a4d7 | 2012-05-16 22:02:34 -0700 | [diff] [blame] | 2237 | |
| 2238 | return count; |
| 2239 | } |
| 2240 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2241 | ssize_t core_alua_show_preferred_bit( |
| 2242 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2243 | char *page) |
| 2244 | { |
| 2245 | return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_pref); |
| 2246 | } |
| 2247 | |
| 2248 | ssize_t core_alua_store_preferred_bit( |
| 2249 | struct t10_alua_tg_pt_gp *tg_pt_gp, |
| 2250 | const char *page, |
| 2251 | size_t count) |
| 2252 | { |
| 2253 | unsigned long tmp; |
| 2254 | int ret; |
| 2255 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2256 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2257 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2258 | pr_err("Unable to extract preferred ALUA value\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2259 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2260 | } |
| 2261 | if ((tmp != 0) && (tmp != 1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2262 | pr_err("Illegal value for preferred ALUA: %lu\n", tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2263 | return -EINVAL; |
| 2264 | } |
| 2265 | tg_pt_gp->tg_pt_gp_pref = (int)tmp; |
| 2266 | |
| 2267 | return count; |
| 2268 | } |
| 2269 | |
| 2270 | ssize_t core_alua_show_offline_bit(struct se_lun *lun, char *page) |
| 2271 | { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2272 | if (!lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2273 | return -ENODEV; |
| 2274 | |
| 2275 | return sprintf(page, "%d\n", |
| 2276 | atomic_read(&lun->lun_sep->sep_tg_pt_secondary_offline)); |
| 2277 | } |
| 2278 | |
| 2279 | ssize_t core_alua_store_offline_bit( |
| 2280 | struct se_lun *lun, |
| 2281 | const char *page, |
| 2282 | size_t count) |
| 2283 | { |
| 2284 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem; |
| 2285 | unsigned long tmp; |
| 2286 | int ret; |
| 2287 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2288 | if (!lun->lun_sep) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2289 | return -ENODEV; |
| 2290 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2291 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2292 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2293 | pr_err("Unable to extract alua_tg_pt_offline value\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2294 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2295 | } |
| 2296 | if ((tmp != 0) && (tmp != 1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2297 | pr_err("Illegal value for alua_tg_pt_offline: %lu\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2298 | tmp); |
| 2299 | return -EINVAL; |
| 2300 | } |
| 2301 | tg_pt_gp_mem = lun->lun_sep->sep_alua_tg_pt_gp_mem; |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2302 | if (!tg_pt_gp_mem) { |
| 2303 | pr_err("Unable to locate *tg_pt_gp_mem\n"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2304 | return -EINVAL; |
| 2305 | } |
| 2306 | |
| 2307 | ret = core_alua_set_tg_pt_secondary_state(tg_pt_gp_mem, |
| 2308 | lun->lun_sep, 0, (int)tmp); |
| 2309 | if (ret < 0) |
| 2310 | return -EINVAL; |
| 2311 | |
| 2312 | return count; |
| 2313 | } |
| 2314 | |
| 2315 | ssize_t core_alua_show_secondary_status( |
| 2316 | struct se_lun *lun, |
| 2317 | char *page) |
| 2318 | { |
| 2319 | return sprintf(page, "%d\n", lun->lun_sep->sep_tg_pt_secondary_stat); |
| 2320 | } |
| 2321 | |
| 2322 | ssize_t core_alua_store_secondary_status( |
| 2323 | struct se_lun *lun, |
| 2324 | const char *page, |
| 2325 | size_t count) |
| 2326 | { |
| 2327 | unsigned long tmp; |
| 2328 | int ret; |
| 2329 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2330 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2331 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2332 | pr_err("Unable to extract alua_tg_pt_status\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2333 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2334 | } |
| 2335 | if ((tmp != ALUA_STATUS_NONE) && |
Hannes Reinecke | 125d011 | 2013-11-19 09:07:46 +0100 | [diff] [blame] | 2336 | (tmp != ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && |
| 2337 | (tmp != ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2338 | pr_err("Illegal value for alua_tg_pt_status: %lu\n", |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2339 | tmp); |
| 2340 | return -EINVAL; |
| 2341 | } |
| 2342 | lun->lun_sep->sep_tg_pt_secondary_stat = (int)tmp; |
| 2343 | |
| 2344 | return count; |
| 2345 | } |
| 2346 | |
| 2347 | ssize_t core_alua_show_secondary_write_metadata( |
| 2348 | struct se_lun *lun, |
| 2349 | char *page) |
| 2350 | { |
| 2351 | return sprintf(page, "%d\n", |
| 2352 | lun->lun_sep->sep_tg_pt_secondary_write_md); |
| 2353 | } |
| 2354 | |
| 2355 | ssize_t core_alua_store_secondary_write_metadata( |
| 2356 | struct se_lun *lun, |
| 2357 | const char *page, |
| 2358 | size_t count) |
| 2359 | { |
| 2360 | unsigned long tmp; |
| 2361 | int ret; |
| 2362 | |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2363 | ret = kstrtoul(page, 0, &tmp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2364 | if (ret < 0) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2365 | pr_err("Unable to extract alua_tg_pt_write_md\n"); |
Jingoo Han | 57103d7 | 2013-07-19 16:22:19 +0900 | [diff] [blame] | 2366 | return ret; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2367 | } |
| 2368 | if ((tmp != 0) && (tmp != 1)) { |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2369 | pr_err("Illegal value for alua_tg_pt_write_md:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2370 | " %lu\n", tmp); |
| 2371 | return -EINVAL; |
| 2372 | } |
| 2373 | lun->lun_sep->sep_tg_pt_secondary_write_md = (int)tmp; |
| 2374 | |
| 2375 | return count; |
| 2376 | } |
| 2377 | |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2378 | int core_setup_alua(struct se_device *dev) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2379 | { |
Andy Grover | a354170 | 2015-05-19 14:44:41 -0700 | [diff] [blame] | 2380 | if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) && |
Christoph Hellwig | c87fbd5 | 2012-10-10 17:37:16 -0400 | [diff] [blame] | 2381 | !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE)) { |
| 2382 | struct t10_alua_lu_gp_member *lu_gp_mem; |
Christoph Hellwig | 0fd97cc | 2012-10-08 00:03:19 -0400 | [diff] [blame] | 2383 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2384 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2385 | * Associate this struct se_device with the default ALUA |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2386 | * LUN Group. |
| 2387 | */ |
| 2388 | lu_gp_mem = core_alua_allocate_lu_gp_mem(dev); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2389 | if (IS_ERR(lu_gp_mem)) |
| 2390 | return PTR_ERR(lu_gp_mem); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2391 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2392 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); |
| 2393 | __core_alua_attach_lu_gp_mem(lu_gp_mem, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2394 | default_lu_gp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2395 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); |
| 2396 | |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 2397 | pr_debug("%s: Adding to default ALUA LU Group:" |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2398 | " core/alua/lu_gps/default_lu_gp\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 2399 | dev->transport->name); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 2400 | } |
| 2401 | |
| 2402 | return 0; |
| 2403 | } |