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