Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Generic SCSI-3 ALUA SCSI Device Handler |
| 3 | * |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 4 | * Copyright (C) 2007-2010 Hannes Reinecke, SUSE Linux Products GmbH. |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 5 | * All rights reserved. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 20 | * |
| 21 | */ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 22 | #include <linux/slab.h> |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 23 | #include <linux/delay.h> |
Paul Gortmaker | acf3368f | 2011-05-27 09:47:43 -0400 | [diff] [blame] | 24 | #include <linux/module.h> |
Hannes Reinecke | a708977 | 2015-12-01 10:16:52 +0100 | [diff] [blame] | 25 | #include <asm/unaligned.h> |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 26 | #include <scsi/scsi.h> |
Hannes Reinecke | 80bd68d | 2015-12-01 10:16:47 +0100 | [diff] [blame] | 27 | #include <scsi/scsi_dbg.h> |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 28 | #include <scsi/scsi_eh.h> |
| 29 | #include <scsi/scsi_dh.h> |
| 30 | |
| 31 | #define ALUA_DH_NAME "alua" |
Hannes Reinecke | e79c82c | 2016-02-19 09:17:20 +0100 | [diff] [blame] | 32 | #define ALUA_DH_VER "2.0" |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 33 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 34 | #define TPGS_SUPPORT_NONE 0x00 |
| 35 | #define TPGS_SUPPORT_OPTIMIZED 0x01 |
| 36 | #define TPGS_SUPPORT_NONOPTIMIZED 0x02 |
| 37 | #define TPGS_SUPPORT_STANDBY 0x04 |
| 38 | #define TPGS_SUPPORT_UNAVAILABLE 0x08 |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 39 | #define TPGS_SUPPORT_LBA_DEPENDENT 0x10 |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 40 | #define TPGS_SUPPORT_OFFLINE 0x40 |
| 41 | #define TPGS_SUPPORT_TRANSITION 0x80 |
| 42 | |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 43 | #define RTPG_FMT_MASK 0x70 |
| 44 | #define RTPG_FMT_EXT_HDR 0x10 |
| 45 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 46 | #define TPGS_MODE_UNINITIALIZED -1 |
| 47 | #define TPGS_MODE_NONE 0x0 |
| 48 | #define TPGS_MODE_IMPLICIT 0x1 |
| 49 | #define TPGS_MODE_EXPLICIT 0x2 |
| 50 | |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 51 | #define ALUA_RTPG_SIZE 128 |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 52 | #define ALUA_FAILOVER_TIMEOUT 60 |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 53 | #define ALUA_FAILOVER_RETRIES 5 |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 54 | #define ALUA_RTPG_DELAY_MSECS 5 |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 55 | |
Hannes Reinecke | 6c4fc04 | 2015-12-01 10:16:51 +0100 | [diff] [blame] | 56 | /* device handler flags */ |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 57 | #define ALUA_OPTIMIZE_STPG 0x01 |
| 58 | #define ALUA_RTPG_EXT_HDR_UNSUPP 0x02 |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 59 | #define ALUA_SYNC_STPG 0x04 |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 60 | /* State machine flags */ |
| 61 | #define ALUA_PG_RUN_RTPG 0x10 |
| 62 | #define ALUA_PG_RUN_STPG 0x20 |
| 63 | #define ALUA_PG_RUNNING 0x40 |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 64 | |
Hannes Reinecke | aa90f49 | 2016-02-19 09:17:08 +0100 | [diff] [blame] | 65 | static uint optimize_stpg; |
| 66 | module_param(optimize_stpg, uint, S_IRUGO|S_IWUSR); |
| 67 | MODULE_PARM_DESC(optimize_stpg, "Allow use of a non-optimized path, rather than sending a STPG, when implicit TPGS is supported (0=No,1=Yes). Default is 0."); |
| 68 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 69 | static LIST_HEAD(port_group_list); |
| 70 | static DEFINE_SPINLOCK(port_group_lock); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 71 | static struct workqueue_struct *kaluad_wq; |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 72 | static struct workqueue_struct *kaluad_sync_wq; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 73 | |
| 74 | struct alua_port_group { |
| 75 | struct kref kref; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 76 | struct rcu_head rcu; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 77 | struct list_head node; |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 78 | unsigned char device_id_str[256]; |
| 79 | int device_id_len; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 80 | int group_id; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 81 | int tpgs; |
| 82 | int state; |
Moger, Babu | dcd3a75 | 2012-03-27 20:56:08 +0000 | [diff] [blame] | 83 | int pref; |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 84 | unsigned flags; /* used for optimizing STPG */ |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 85 | unsigned char transition_tmo; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 86 | unsigned long expiry; |
| 87 | unsigned long interval; |
| 88 | struct delayed_work rtpg_work; |
| 89 | spinlock_t lock; |
| 90 | struct list_head rtpg_list; |
| 91 | struct scsi_device *rtpg_sdev; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 92 | }; |
| 93 | |
| 94 | struct alua_dh_data { |
| 95 | struct alua_port_group *pg; |
| 96 | int group_id; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 97 | spinlock_t pg_lock; |
Chandra Seetharaman | 96e6586 | 2009-10-21 09:23:04 -0700 | [diff] [blame] | 98 | struct scsi_device *sdev; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 99 | int init_error; |
| 100 | struct mutex init_mutex; |
| 101 | }; |
| 102 | |
| 103 | struct alua_queue_data { |
| 104 | struct list_head entry; |
Chandra Seetharaman | 96e6586 | 2009-10-21 09:23:04 -0700 | [diff] [blame] | 105 | activate_complete callback_fn; |
| 106 | void *callback_data; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | #define ALUA_POLICY_SWITCH_CURRENT 0 |
| 110 | #define ALUA_POLICY_SWITCH_ALL 1 |
| 111 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 112 | static void alua_rtpg_work(struct work_struct *work); |
| 113 | static void alua_rtpg_queue(struct alua_port_group *pg, |
| 114 | struct scsi_device *sdev, |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 115 | struct alua_queue_data *qdata, bool force); |
| 116 | static void alua_check(struct scsi_device *sdev, bool force); |
Chandra Seetharaman | 96e6586 | 2009-10-21 09:23:04 -0700 | [diff] [blame] | 117 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 118 | static void release_port_group(struct kref *kref) |
| 119 | { |
| 120 | struct alua_port_group *pg; |
| 121 | |
| 122 | pg = container_of(kref, struct alua_port_group, kref); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 123 | if (pg->rtpg_sdev) |
| 124 | flush_delayed_work(&pg->rtpg_work); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 125 | spin_lock(&port_group_lock); |
| 126 | list_del(&pg->node); |
| 127 | spin_unlock(&port_group_lock); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 128 | kfree_rcu(pg, rcu); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 129 | } |
| 130 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 131 | /* |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 132 | * submit_rtpg - Issue a REPORT TARGET GROUP STATES command |
| 133 | * @sdev: sdev the command should be sent to |
| 134 | */ |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 135 | static int submit_rtpg(struct scsi_device *sdev, unsigned char *buff, |
| 136 | int bufflen, struct scsi_sense_hdr *sshdr, int flags) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 137 | { |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 138 | u8 cdb[COMMAND_SIZE(MAINTENANCE_IN)]; |
| 139 | int req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
| 140 | REQ_FAILFAST_DRIVER; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 141 | |
| 142 | /* Prepare the command. */ |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 143 | memset(cdb, 0x0, COMMAND_SIZE(MAINTENANCE_IN)); |
| 144 | cdb[0] = MAINTENANCE_IN; |
Hannes Reinecke | d42ae5f | 2016-02-19 09:16:58 +0100 | [diff] [blame] | 145 | if (!(flags & ALUA_RTPG_EXT_HDR_UNSUPP)) |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 146 | cdb[1] = MI_REPORT_TARGET_PGS | MI_EXT_HDR_PARAM_FMT; |
Rob Evers | 8e67ce6 | 2012-05-18 14:08:55 -0400 | [diff] [blame] | 147 | else |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 148 | cdb[1] = MI_REPORT_TARGET_PGS; |
| 149 | put_unaligned_be32(bufflen, &cdb[6]); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 150 | |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 151 | return scsi_execute_req_flags(sdev, cdb, DMA_FROM_DEVICE, |
| 152 | buff, bufflen, sshdr, |
| 153 | ALUA_FAILOVER_TIMEOUT * HZ, |
| 154 | ALUA_FAILOVER_RETRIES, NULL, req_flags); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 158 | * submit_stpg - Issue a SET TARGET PORT GROUP command |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 159 | * |
| 160 | * Currently we're only setting the current target port group state |
| 161 | * to 'active/optimized' and let the array firmware figure out |
| 162 | * the states of the remaining groups. |
| 163 | */ |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 164 | static int submit_stpg(struct scsi_device *sdev, int group_id, |
| 165 | struct scsi_sense_hdr *sshdr) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 166 | { |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 167 | u8 cdb[COMMAND_SIZE(MAINTENANCE_OUT)]; |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 168 | unsigned char stpg_data[8]; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 169 | int stpg_len = 8; |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 170 | int req_flags = REQ_FAILFAST_DEV | REQ_FAILFAST_TRANSPORT | |
| 171 | REQ_FAILFAST_DRIVER; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 172 | |
| 173 | /* Prepare the data buffer */ |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 174 | memset(stpg_data, 0, stpg_len); |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 175 | stpg_data[4] = SCSI_ACCESS_STATE_OPTIMAL; |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 176 | put_unaligned_be16(group_id, &stpg_data[6]); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 177 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 178 | /* Prepare the command. */ |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 179 | memset(cdb, 0x0, COMMAND_SIZE(MAINTENANCE_OUT)); |
| 180 | cdb[0] = MAINTENANCE_OUT; |
| 181 | cdb[1] = MO_SET_TARGET_PGS; |
| 182 | put_unaligned_be32(stpg_len, &cdb[6]); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 183 | |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 184 | return scsi_execute_req_flags(sdev, cdb, DMA_TO_DEVICE, |
| 185 | stpg_data, stpg_len, |
| 186 | sshdr, ALUA_FAILOVER_TIMEOUT * HZ, |
| 187 | ALUA_FAILOVER_RETRIES, NULL, req_flags); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 190 | struct alua_port_group *alua_find_get_pg(char *id_str, size_t id_size, |
| 191 | int group_id) |
| 192 | { |
| 193 | struct alua_port_group *pg; |
| 194 | |
| 195 | list_for_each_entry(pg, &port_group_list, node) { |
| 196 | if (pg->group_id != group_id) |
| 197 | continue; |
| 198 | if (pg->device_id_len != id_size) |
| 199 | continue; |
| 200 | if (strncmp(pg->device_id_str, id_str, id_size)) |
| 201 | continue; |
| 202 | if (!kref_get_unless_zero(&pg->kref)) |
| 203 | continue; |
| 204 | return pg; |
| 205 | } |
| 206 | |
| 207 | return NULL; |
| 208 | } |
| 209 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 210 | /* |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 211 | * alua_alloc_pg - Allocate a new port_group structure |
| 212 | * @sdev: scsi device |
| 213 | * @h: alua device_handler data |
| 214 | * @group_id: port group id |
| 215 | * |
| 216 | * Allocate a new port_group structure for a given |
| 217 | * device. |
| 218 | */ |
| 219 | struct alua_port_group *alua_alloc_pg(struct scsi_device *sdev, |
| 220 | int group_id, int tpgs) |
| 221 | { |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 222 | struct alua_port_group *pg, *tmp_pg; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 223 | |
| 224 | pg = kzalloc(sizeof(struct alua_port_group), GFP_KERNEL); |
| 225 | if (!pg) |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 226 | return ERR_PTR(-ENOMEM); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 227 | |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 228 | pg->device_id_len = scsi_vpd_lun_id(sdev, pg->device_id_str, |
| 229 | sizeof(pg->device_id_str)); |
| 230 | if (pg->device_id_len <= 0) { |
| 231 | /* |
| 232 | * Internal error: TPGS supported but no device |
| 233 | * identifcation found. Disable ALUA support. |
| 234 | */ |
| 235 | kfree(pg); |
| 236 | sdev_printk(KERN_INFO, sdev, |
| 237 | "%s: No device descriptors found\n", |
| 238 | ALUA_DH_NAME); |
| 239 | return ERR_PTR(-ENXIO); |
| 240 | } |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 241 | pg->group_id = group_id; |
| 242 | pg->tpgs = tpgs; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 243 | pg->state = SCSI_ACCESS_STATE_OPTIMAL; |
Hannes Reinecke | aa90f49 | 2016-02-19 09:17:08 +0100 | [diff] [blame] | 244 | if (optimize_stpg) |
| 245 | pg->flags |= ALUA_OPTIMIZE_STPG; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 246 | kref_init(&pg->kref); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 247 | INIT_DELAYED_WORK(&pg->rtpg_work, alua_rtpg_work); |
| 248 | INIT_LIST_HEAD(&pg->rtpg_list); |
| 249 | INIT_LIST_HEAD(&pg->node); |
| 250 | spin_lock_init(&pg->lock); |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 251 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 252 | spin_lock(&port_group_lock); |
Hannes Reinecke | 0047220 | 2016-02-19 09:17:05 +0100 | [diff] [blame] | 253 | tmp_pg = alua_find_get_pg(pg->device_id_str, pg->device_id_len, |
| 254 | group_id); |
| 255 | if (tmp_pg) { |
| 256 | spin_unlock(&port_group_lock); |
| 257 | kfree(pg); |
| 258 | return tmp_pg; |
| 259 | } |
| 260 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 261 | list_add(&pg->node, &port_group_list); |
| 262 | spin_unlock(&port_group_lock); |
| 263 | |
| 264 | return pg; |
| 265 | } |
| 266 | |
| 267 | /* |
Hannes Reinecke | d7c48fe | 2011-08-24 10:51:13 +0200 | [diff] [blame] | 268 | * alua_check_tpgs - Evaluate TPGS setting |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 269 | * @sdev: device to be checked |
| 270 | * |
Hannes Reinecke | d7c48fe | 2011-08-24 10:51:13 +0200 | [diff] [blame] | 271 | * Examine the TPGS setting of the sdev to find out if ALUA |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 272 | * is supported. |
| 273 | */ |
Hannes Reinecke | ad0ea64 | 2015-12-01 10:16:53 +0100 | [diff] [blame] | 274 | static int alua_check_tpgs(struct scsi_device *sdev) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 275 | { |
Hannes Reinecke | ad0ea64 | 2015-12-01 10:16:53 +0100 | [diff] [blame] | 276 | int tpgs = TPGS_MODE_NONE; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 277 | |
Hannes Reinecke | db5a6a6 | 2015-12-01 10:16:43 +0100 | [diff] [blame] | 278 | /* |
| 279 | * ALUA support for non-disk devices is fraught with |
| 280 | * difficulties, so disable it for now. |
| 281 | */ |
| 282 | if (sdev->type != TYPE_DISK) { |
Hannes Reinecke | db5a6a6 | 2015-12-01 10:16:43 +0100 | [diff] [blame] | 283 | sdev_printk(KERN_INFO, sdev, |
| 284 | "%s: disable for non-disk devices\n", |
| 285 | ALUA_DH_NAME); |
Hannes Reinecke | ad0ea64 | 2015-12-01 10:16:53 +0100 | [diff] [blame] | 286 | return tpgs; |
Hannes Reinecke | db5a6a6 | 2015-12-01 10:16:43 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Hannes Reinecke | ad0ea64 | 2015-12-01 10:16:53 +0100 | [diff] [blame] | 289 | tpgs = scsi_device_tpgs(sdev); |
| 290 | switch (tpgs) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 291 | case TPGS_MODE_EXPLICIT|TPGS_MODE_IMPLICIT: |
| 292 | sdev_printk(KERN_INFO, sdev, |
| 293 | "%s: supports implicit and explicit TPGS\n", |
| 294 | ALUA_DH_NAME); |
| 295 | break; |
| 296 | case TPGS_MODE_EXPLICIT: |
| 297 | sdev_printk(KERN_INFO, sdev, "%s: supports explicit TPGS\n", |
| 298 | ALUA_DH_NAME); |
| 299 | break; |
| 300 | case TPGS_MODE_IMPLICIT: |
| 301 | sdev_printk(KERN_INFO, sdev, "%s: supports implicit TPGS\n", |
| 302 | ALUA_DH_NAME); |
| 303 | break; |
Hannes Reinecke | 6cc05d4 | 2015-12-01 10:16:45 +0100 | [diff] [blame] | 304 | case TPGS_MODE_NONE: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 305 | sdev_printk(KERN_INFO, sdev, "%s: not supported\n", |
| 306 | ALUA_DH_NAME); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 307 | break; |
Hannes Reinecke | 6cc05d4 | 2015-12-01 10:16:45 +0100 | [diff] [blame] | 308 | default: |
| 309 | sdev_printk(KERN_INFO, sdev, |
| 310 | "%s: unsupported TPGS setting %d\n", |
Hannes Reinecke | ad0ea64 | 2015-12-01 10:16:53 +0100 | [diff] [blame] | 311 | ALUA_DH_NAME, tpgs); |
| 312 | tpgs = TPGS_MODE_NONE; |
Hannes Reinecke | 6cc05d4 | 2015-12-01 10:16:45 +0100 | [diff] [blame] | 313 | break; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 314 | } |
| 315 | |
Hannes Reinecke | ad0ea64 | 2015-12-01 10:16:53 +0100 | [diff] [blame] | 316 | return tpgs; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | /* |
Hannes Reinecke | 9b80dce | 2015-12-01 10:16:44 +0100 | [diff] [blame] | 320 | * alua_check_vpd - Evaluate INQUIRY vpd page 0x83 |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 321 | * @sdev: device to be checked |
| 322 | * |
| 323 | * Extract the relative target port and the target port group |
| 324 | * descriptor from the list of identificators. |
| 325 | */ |
Hannes Reinecke | a4253fd | 2016-02-19 09:17:06 +0100 | [diff] [blame] | 326 | static int alua_check_vpd(struct scsi_device *sdev, struct alua_dh_data *h, |
| 327 | int tpgs) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 328 | { |
Hannes Reinecke | 83ea0e5 | 2015-12-01 10:16:58 +0100 | [diff] [blame] | 329 | int rel_port = -1, group_id; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 330 | struct alua_port_group *pg, *old_pg = NULL; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 331 | |
Hannes Reinecke | 83ea0e5 | 2015-12-01 10:16:58 +0100 | [diff] [blame] | 332 | group_id = scsi_vpd_tpg_id(sdev, &rel_port); |
| 333 | if (group_id < 0) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 334 | /* |
| 335 | * Internal error; TPGS supported but required |
| 336 | * VPD identification descriptors not present. |
| 337 | * Disable ALUA support |
| 338 | */ |
| 339 | sdev_printk(KERN_INFO, sdev, |
| 340 | "%s: No target port descriptors found\n", |
| 341 | ALUA_DH_NAME); |
Hannes Reinecke | 9b80dce | 2015-12-01 10:16:44 +0100 | [diff] [blame] | 342 | return SCSI_DH_DEV_UNSUPP; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 343 | } |
Hannes Reinecke | a4253fd | 2016-02-19 09:17:06 +0100 | [diff] [blame] | 344 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 345 | pg = alua_alloc_pg(sdev, group_id, tpgs); |
| 346 | if (IS_ERR(pg)) { |
| 347 | if (PTR_ERR(pg) == -ENOMEM) |
Hannes Reinecke | a4253fd | 2016-02-19 09:17:06 +0100 | [diff] [blame] | 348 | return SCSI_DH_NOMEM; |
| 349 | return SCSI_DH_DEV_UNSUPP; |
| 350 | } |
Hannes Reinecke | 9b80dce | 2015-12-01 10:16:44 +0100 | [diff] [blame] | 351 | sdev_printk(KERN_INFO, sdev, |
Hannes Reinecke | a4253fd | 2016-02-19 09:17:06 +0100 | [diff] [blame] | 352 | "%s: device %s port group %x rel port %x\n", |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 353 | ALUA_DH_NAME, pg->device_id_str, group_id, rel_port); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 354 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 355 | /* Check for existing port group references */ |
| 356 | spin_lock(&h->pg_lock); |
| 357 | old_pg = h->pg; |
| 358 | if (old_pg != pg) { |
| 359 | /* port group has changed. Update to new port group */ |
| 360 | rcu_assign_pointer(h->pg, pg); |
| 361 | } |
Hannes Reinecke | 851cde9 | 2016-02-19 09:17:12 +0100 | [diff] [blame] | 362 | if (sdev->synchronous_alua) |
| 363 | pg->flags |= ALUA_SYNC_STPG; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 364 | alua_rtpg_queue(h->pg, sdev, NULL, true); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 365 | spin_unlock(&h->pg_lock); |
| 366 | |
| 367 | if (old_pg) |
| 368 | kref_put(&old_pg->kref, release_port_group); |
| 369 | |
| 370 | return SCSI_DH_OK; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 373 | static char print_alua_state(unsigned char state) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 374 | { |
| 375 | switch (state) { |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 376 | case SCSI_ACCESS_STATE_OPTIMAL: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 377 | return 'A'; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 378 | case SCSI_ACCESS_STATE_ACTIVE: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 379 | return 'N'; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 380 | case SCSI_ACCESS_STATE_STANDBY: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 381 | return 'S'; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 382 | case SCSI_ACCESS_STATE_UNAVAILABLE: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 383 | return 'U'; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 384 | case SCSI_ACCESS_STATE_LBA: |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 385 | return 'L'; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 386 | case SCSI_ACCESS_STATE_OFFLINE: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 387 | return 'O'; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 388 | case SCSI_ACCESS_STATE_TRANSITIONING: |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 389 | return 'T'; |
| 390 | default: |
| 391 | return 'X'; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | static int alua_check_sense(struct scsi_device *sdev, |
| 396 | struct scsi_sense_hdr *sense_hdr) |
| 397 | { |
| 398 | switch (sense_hdr->sense_key) { |
| 399 | case NOT_READY: |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 400 | if (sense_hdr->asc == 0x04 && sense_hdr->ascq == 0x0a) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 401 | /* |
| 402 | * LUN Not Accessible - ALUA state transition |
| 403 | */ |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 404 | alua_check(sdev, false); |
| 405 | return NEEDS_RETRY; |
| 406 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 407 | break; |
| 408 | case UNIT_ATTENTION: |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 409 | if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x00) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 410 | /* |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 411 | * Power On, Reset, or Bus Device Reset. |
| 412 | * Might have obscured a state transition, |
| 413 | * so schedule a recheck. |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 414 | */ |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 415 | alua_check(sdev, true); |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 416 | return ADD_TO_MLQUEUE; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 417 | } |
Stewart, Sean | c20ee7b | 2013-10-15 15:52:39 +0000 | [diff] [blame] | 418 | if (sense_hdr->asc == 0x29 && sense_hdr->ascq == 0x04) |
| 419 | /* |
| 420 | * Device internal reset |
| 421 | */ |
| 422 | return ADD_TO_MLQUEUE; |
Moger, Babu | 410f02d | 2011-12-21 18:01:37 -0500 | [diff] [blame] | 423 | if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x01) |
| 424 | /* |
| 425 | * Mode Parameters Changed |
| 426 | */ |
| 427 | return ADD_TO_MLQUEUE; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 428 | if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x06) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 429 | /* |
| 430 | * ALUA state changed |
| 431 | */ |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 432 | alua_check(sdev, true); |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 433 | return ADD_TO_MLQUEUE; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 434 | } |
| 435 | if (sense_hdr->asc == 0x2a && sense_hdr->ascq == 0x07) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 436 | /* |
| 437 | * Implicit ALUA state transition failed |
| 438 | */ |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 439 | alua_check(sdev, true); |
Mike Anderson | c7dbb62 | 2008-08-12 12:11:57 -0700 | [diff] [blame] | 440 | return ADD_TO_MLQUEUE; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 441 | } |
Moger, Babu | bf81973 | 2011-10-06 13:22:07 -0400 | [diff] [blame] | 442 | if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x03) |
| 443 | /* |
| 444 | * Inquiry data has changed |
| 445 | */ |
| 446 | return ADD_TO_MLQUEUE; |
| 447 | if (sense_hdr->asc == 0x3f && sense_hdr->ascq == 0x0e) |
Ilgu Hong | 4d086f6 | 2009-01-30 17:00:11 -0600 | [diff] [blame] | 448 | /* |
| 449 | * REPORTED_LUNS_DATA_HAS_CHANGED is reported |
| 450 | * when switching controllers on targets like |
| 451 | * Intel Multi-Flex. We can just retry. |
| 452 | */ |
| 453 | return ADD_TO_MLQUEUE; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | |
| 457 | return SCSI_RETURN_NOT_HANDLED; |
| 458 | } |
| 459 | |
| 460 | /* |
Hannes Reinecke | 9d2c303 | 2016-02-19 09:17:15 +0100 | [diff] [blame] | 461 | * alua_tur - Send a TEST UNIT READY |
| 462 | * @sdev: device to which the TEST UNIT READY command should be send |
| 463 | * |
| 464 | * Send a TEST UNIT READY to @sdev to figure out the device state |
| 465 | * Returns SCSI_DH_RETRY if the sense code is NOT READY/ALUA TRANSITIONING, |
| 466 | * SCSI_DH_OK if no error occurred, and SCSI_DH_IO otherwise. |
| 467 | */ |
| 468 | static int alua_tur(struct scsi_device *sdev) |
| 469 | { |
| 470 | struct scsi_sense_hdr sense_hdr; |
| 471 | int retval; |
| 472 | |
| 473 | retval = scsi_test_unit_ready(sdev, ALUA_FAILOVER_TIMEOUT * HZ, |
| 474 | ALUA_FAILOVER_RETRIES, &sense_hdr); |
| 475 | if (sense_hdr.sense_key == NOT_READY && |
| 476 | sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x0a) |
| 477 | return SCSI_DH_RETRY; |
| 478 | else if (retval) |
| 479 | return SCSI_DH_IO; |
| 480 | else |
| 481 | return SCSI_DH_OK; |
| 482 | } |
| 483 | |
| 484 | /* |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 485 | * alua_rtpg - Evaluate REPORT TARGET GROUP STATES |
| 486 | * @sdev: the device to be evaluated. |
| 487 | * |
| 488 | * Evaluate the Target Port Group State. |
| 489 | * Returns SCSI_DH_DEV_OFFLINED if the path is |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 490 | * found to be unusable. |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 491 | */ |
Hannes Reinecke | 2826140 | 2016-02-19 09:17:07 +0100 | [diff] [blame] | 492 | static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 493 | { |
| 494 | struct scsi_sense_hdr sense_hdr; |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 495 | struct alua_port_group *tmp_pg; |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 496 | int len, k, off, valid_states = 0, bufflen = ALUA_RTPG_SIZE; |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 497 | unsigned char *desc, *buff; |
Hannes Reinecke | 5597caf | 2015-12-01 10:16:48 +0100 | [diff] [blame] | 498 | unsigned err, retval; |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 499 | unsigned int tpg_desc_tbl_off; |
| 500 | unsigned char orig_transition_tmo; |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 501 | unsigned long flags; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 502 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 503 | if (!pg->expiry) { |
| 504 | unsigned long transition_tmo = ALUA_FAILOVER_TIMEOUT * HZ; |
| 505 | |
| 506 | if (pg->transition_tmo) |
| 507 | transition_tmo = pg->transition_tmo * HZ; |
| 508 | |
| 509 | pg->expiry = round_jiffies_up(jiffies + transition_tmo); |
| 510 | } |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 511 | |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 512 | buff = kzalloc(bufflen, GFP_KERNEL); |
| 513 | if (!buff) |
| 514 | return SCSI_DH_DEV_TEMP_BUSY; |
| 515 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 516 | retry: |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 517 | retval = submit_rtpg(sdev, buff, bufflen, &sense_hdr, pg->flags); |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 518 | |
Hannes Reinecke | 5597caf | 2015-12-01 10:16:48 +0100 | [diff] [blame] | 519 | if (retval) { |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 520 | if (!scsi_sense_valid(&sense_hdr)) { |
Hannes Reinecke | 5597caf | 2015-12-01 10:16:48 +0100 | [diff] [blame] | 521 | sdev_printk(KERN_INFO, sdev, |
| 522 | "%s: rtpg failed, result %d\n", |
| 523 | ALUA_DH_NAME, retval); |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 524 | kfree(buff); |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 525 | if (driver_byte(retval) == DRIVER_ERROR) |
Hannes Reinecke | 5597caf | 2015-12-01 10:16:48 +0100 | [diff] [blame] | 526 | return SCSI_DH_DEV_TEMP_BUSY; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 527 | return SCSI_DH_IO; |
Hannes Reinecke | 5597caf | 2015-12-01 10:16:48 +0100 | [diff] [blame] | 528 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 529 | |
Rob Evers | 8e67ce6 | 2012-05-18 14:08:55 -0400 | [diff] [blame] | 530 | /* |
| 531 | * submit_rtpg() has failed on existing arrays |
| 532 | * when requesting extended header info, and |
| 533 | * the array doesn't support extended headers, |
| 534 | * even though it shouldn't according to T10. |
| 535 | * The retry without rtpg_ext_hdr_req set |
| 536 | * handles this. |
| 537 | */ |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 538 | if (!(pg->flags & ALUA_RTPG_EXT_HDR_UNSUPP) && |
Rob Evers | 8e67ce6 | 2012-05-18 14:08:55 -0400 | [diff] [blame] | 539 | sense_hdr.sense_key == ILLEGAL_REQUEST && |
| 540 | sense_hdr.asc == 0x24 && sense_hdr.ascq == 0) { |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 541 | pg->flags |= ALUA_RTPG_EXT_HDR_UNSUPP; |
Rob Evers | 8e67ce6 | 2012-05-18 14:08:55 -0400 | [diff] [blame] | 542 | goto retry; |
| 543 | } |
Hannes Reinecke | e2d817d | 2015-12-01 10:16:54 +0100 | [diff] [blame] | 544 | /* |
| 545 | * Retry on ALUA state transition or if any |
| 546 | * UNIT ATTENTION occurred. |
| 547 | */ |
| 548 | if (sense_hdr.sense_key == NOT_READY && |
| 549 | sense_hdr.asc == 0x04 && sense_hdr.ascq == 0x0a) |
| 550 | err = SCSI_DH_RETRY; |
| 551 | else if (sense_hdr.sense_key == UNIT_ATTENTION) |
| 552 | err = SCSI_DH_RETRY; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 553 | if (err == SCSI_DH_RETRY && |
| 554 | pg->expiry != 0 && time_before(jiffies, pg->expiry)) { |
Hannes Reinecke | 80bd68d | 2015-12-01 10:16:47 +0100 | [diff] [blame] | 555 | sdev_printk(KERN_ERR, sdev, "%s: rtpg retry\n", |
| 556 | ALUA_DH_NAME); |
| 557 | scsi_print_sense_hdr(sdev, ALUA_DH_NAME, &sense_hdr); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 558 | return err; |
Hannes Reinecke | 80bd68d | 2015-12-01 10:16:47 +0100 | [diff] [blame] | 559 | } |
| 560 | sdev_printk(KERN_ERR, sdev, "%s: rtpg failed\n", |
| 561 | ALUA_DH_NAME); |
| 562 | scsi_print_sense_hdr(sdev, ALUA_DH_NAME, &sense_hdr); |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 563 | kfree(buff); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 564 | pg->expiry = 0; |
Hannes Reinecke | 80bd68d | 2015-12-01 10:16:47 +0100 | [diff] [blame] | 565 | return SCSI_DH_IO; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 566 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 567 | |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 568 | len = get_unaligned_be32(&buff[0]) + 4; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 569 | |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 570 | if (len > bufflen) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 571 | /* Resubmit with the correct length */ |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 572 | kfree(buff); |
| 573 | bufflen = len; |
| 574 | buff = kmalloc(bufflen, GFP_KERNEL); |
| 575 | if (!buff) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 576 | sdev_printk(KERN_WARNING, sdev, |
Harvey Harrison | cadbd4a | 2008-07-03 23:47:27 -0700 | [diff] [blame] | 577 | "%s: kmalloc buffer failed\n",__func__); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 578 | /* Temporary failure, bypass */ |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 579 | pg->expiry = 0; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 580 | return SCSI_DH_DEV_TEMP_BUSY; |
| 581 | } |
| 582 | goto retry; |
| 583 | } |
| 584 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 585 | orig_transition_tmo = pg->transition_tmo; |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 586 | if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR && buff[5] != 0) |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 587 | pg->transition_tmo = buff[5]; |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 588 | else |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 589 | pg->transition_tmo = ALUA_FAILOVER_TIMEOUT; |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 590 | |
Hannes Reinecke | 2826140 | 2016-02-19 09:17:07 +0100 | [diff] [blame] | 591 | if (orig_transition_tmo != pg->transition_tmo) { |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 592 | sdev_printk(KERN_INFO, sdev, |
| 593 | "%s: transition timeout set to %d seconds\n", |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 594 | ALUA_DH_NAME, pg->transition_tmo); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 595 | pg->expiry = jiffies + pg->transition_tmo * HZ; |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 596 | } |
| 597 | |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 598 | if ((buff[4] & RTPG_FMT_MASK) == RTPG_FMT_EXT_HDR) |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 599 | tpg_desc_tbl_off = 8; |
| 600 | else |
| 601 | tpg_desc_tbl_off = 4; |
| 602 | |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 603 | for (k = tpg_desc_tbl_off, desc = buff + tpg_desc_tbl_off; |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 604 | k < len; |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 605 | k += off, desc += off) { |
| 606 | u16 group_id = get_unaligned_be16(&desc[2]); |
Rob Evers | 3588c5a | 2012-05-18 14:08:54 -0400 | [diff] [blame] | 607 | |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 608 | spin_lock_irqsave(&port_group_lock, flags); |
| 609 | tmp_pg = alua_find_get_pg(pg->device_id_str, pg->device_id_len, |
| 610 | group_id); |
| 611 | spin_unlock_irqrestore(&port_group_lock, flags); |
| 612 | if (tmp_pg) { |
| 613 | if (spin_trylock_irqsave(&tmp_pg->lock, flags)) { |
| 614 | if ((tmp_pg == pg) || |
| 615 | !(tmp_pg->flags & ALUA_PG_RUNNING)) { |
| 616 | tmp_pg->state = desc[0] & 0x0f; |
| 617 | tmp_pg->pref = desc[0] >> 7; |
| 618 | } |
| 619 | if (tmp_pg == pg) |
| 620 | valid_states = desc[1]; |
| 621 | spin_unlock_irqrestore(&tmp_pg->lock, flags); |
| 622 | } |
| 623 | kref_put(&tmp_pg->kref, release_port_group); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 624 | } |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 625 | off = 8 + (desc[7] * 4); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 626 | } |
| 627 | |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 628 | spin_lock_irqsave(&pg->lock, flags); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 629 | sdev_printk(KERN_INFO, sdev, |
Moger, Babu | dcd3a75 | 2012-03-27 20:56:08 +0000 | [diff] [blame] | 630 | "%s: port group %02x state %c %s supports %c%c%c%c%c%c%c\n", |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 631 | ALUA_DH_NAME, pg->group_id, print_alua_state(pg->state), |
| 632 | pg->pref ? "preferred" : "non-preferred", |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 633 | valid_states&TPGS_SUPPORT_TRANSITION?'T':'t', |
| 634 | valid_states&TPGS_SUPPORT_OFFLINE?'O':'o', |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 635 | valid_states&TPGS_SUPPORT_LBA_DEPENDENT?'L':'l', |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 636 | valid_states&TPGS_SUPPORT_UNAVAILABLE?'U':'u', |
| 637 | valid_states&TPGS_SUPPORT_STANDBY?'S':'s', |
| 638 | valid_states&TPGS_SUPPORT_NONOPTIMIZED?'N':'n', |
| 639 | valid_states&TPGS_SUPPORT_OPTIMIZED?'A':'a'); |
| 640 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 641 | switch (pg->state) { |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 642 | case SCSI_ACCESS_STATE_TRANSITIONING: |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 643 | if (time_before(jiffies, pg->expiry)) { |
Hannes Reinecke | 2826140 | 2016-02-19 09:17:07 +0100 | [diff] [blame] | 644 | /* State transition, retry */ |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 645 | pg->interval = 2; |
| 646 | err = SCSI_DH_RETRY; |
| 647 | } else { |
| 648 | /* Transitioning time exceeded, set port to standby */ |
| 649 | err = SCSI_DH_IO; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 650 | pg->state = SCSI_ACCESS_STATE_STANDBY; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 651 | pg->expiry = 0; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 652 | } |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 653 | break; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 654 | case SCSI_ACCESS_STATE_OFFLINE: |
Bart Van Assche | e47f897 | 2012-08-24 09:08:41 +0000 | [diff] [blame] | 655 | /* Path unusable */ |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 656 | err = SCSI_DH_DEV_OFFLINED; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 657 | pg->expiry = 0; |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 658 | break; |
| 659 | default: |
| 660 | /* Useable path if active */ |
| 661 | err = SCSI_DH_OK; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 662 | pg->expiry = 0; |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 663 | break; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 664 | } |
Hannes Reinecke | c57168a | 2016-02-19 09:17:14 +0100 | [diff] [blame] | 665 | spin_unlock_irqrestore(&pg->lock, flags); |
Hannes Reinecke | c49c834 | 2016-02-19 09:17:03 +0100 | [diff] [blame] | 666 | kfree(buff); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 667 | return err; |
| 668 | } |
| 669 | |
| 670 | /* |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 671 | * alua_stpg - Issue a SET TARGET PORT GROUP command |
| 672 | * |
| 673 | * Issue a SET TARGET PORT GROUP command and evaluate the |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 674 | * response. Returns SCSI_DH_RETRY per default to trigger |
| 675 | * a re-evaluation of the target group state or SCSI_DH_OK |
| 676 | * if no further action needs to be taken. |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 677 | */ |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 678 | static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg) |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 679 | { |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 680 | int retval; |
| 681 | struct scsi_sense_hdr sense_hdr; |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 682 | |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 683 | if (!(pg->tpgs & TPGS_MODE_EXPLICIT)) { |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 684 | /* Only implicit ALUA supported, retry */ |
| 685 | return SCSI_DH_RETRY; |
| 686 | } |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 687 | switch (pg->state) { |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 688 | case SCSI_ACCESS_STATE_OPTIMAL: |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 689 | return SCSI_DH_OK; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 690 | case SCSI_ACCESS_STATE_ACTIVE: |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 691 | if ((pg->flags & ALUA_OPTIMIZE_STPG) && |
| 692 | !pg->pref && |
| 693 | (pg->tpgs & TPGS_MODE_IMPLICIT)) |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 694 | return SCSI_DH_OK; |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 695 | break; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 696 | case SCSI_ACCESS_STATE_STANDBY: |
| 697 | case SCSI_ACCESS_STATE_UNAVAILABLE: |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 698 | break; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 699 | case SCSI_ACCESS_STATE_OFFLINE: |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 700 | return SCSI_DH_IO; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 701 | case SCSI_ACCESS_STATE_TRANSITIONING: |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 702 | break; |
| 703 | default: |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 704 | sdev_printk(KERN_INFO, sdev, |
| 705 | "%s: stpg failed, unhandled TPGS state %d", |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 706 | ALUA_DH_NAME, pg->state); |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 707 | return SCSI_DH_NOSYS; |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 708 | } |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 709 | retval = submit_stpg(sdev, pg->group_id, &sense_hdr); |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 710 | |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 711 | if (retval) { |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 712 | if (!scsi_sense_valid(&sense_hdr)) { |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 713 | sdev_printk(KERN_INFO, sdev, |
| 714 | "%s: stpg failed, result %d", |
| 715 | ALUA_DH_NAME, retval); |
Hannes Reinecke | 40bb61a | 2016-02-19 09:17:02 +0100 | [diff] [blame] | 716 | if (driver_byte(retval) == DRIVER_ERROR) |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 717 | return SCSI_DH_DEV_TEMP_BUSY; |
| 718 | } else { |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 719 | sdev_printk(KERN_INFO, sdev, "%s: stpg failed\n", |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 720 | ALUA_DH_NAME); |
| 721 | scsi_print_sense_hdr(sdev, ALUA_DH_NAME, &sense_hdr); |
| 722 | } |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 723 | } |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 724 | /* Retry RTPG */ |
| 725 | return SCSI_DH_RETRY; |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 726 | } |
| 727 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 728 | static void alua_rtpg_work(struct work_struct *work) |
| 729 | { |
| 730 | struct alua_port_group *pg = |
| 731 | container_of(work, struct alua_port_group, rtpg_work.work); |
| 732 | struct scsi_device *sdev; |
| 733 | LIST_HEAD(qdata_list); |
| 734 | int err = SCSI_DH_OK; |
| 735 | struct alua_queue_data *qdata, *tmp; |
| 736 | unsigned long flags; |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 737 | struct workqueue_struct *alua_wq = kaluad_wq; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 738 | |
| 739 | spin_lock_irqsave(&pg->lock, flags); |
| 740 | sdev = pg->rtpg_sdev; |
| 741 | if (!sdev) { |
| 742 | WARN_ON(pg->flags & ALUA_PG_RUN_RTPG); |
| 743 | WARN_ON(pg->flags & ALUA_PG_RUN_STPG); |
| 744 | spin_unlock_irqrestore(&pg->lock, flags); |
| 745 | return; |
| 746 | } |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 747 | if (pg->flags & ALUA_SYNC_STPG) |
| 748 | alua_wq = kaluad_sync_wq; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 749 | pg->flags |= ALUA_PG_RUNNING; |
| 750 | if (pg->flags & ALUA_PG_RUN_RTPG) { |
Hannes Reinecke | 9d2c303 | 2016-02-19 09:17:15 +0100 | [diff] [blame] | 751 | int state = pg->state; |
| 752 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 753 | pg->flags &= ~ALUA_PG_RUN_RTPG; |
| 754 | spin_unlock_irqrestore(&pg->lock, flags); |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 755 | if (state == SCSI_ACCESS_STATE_TRANSITIONING) { |
Hannes Reinecke | 9d2c303 | 2016-02-19 09:17:15 +0100 | [diff] [blame] | 756 | if (alua_tur(sdev) == SCSI_DH_RETRY) { |
| 757 | spin_lock_irqsave(&pg->lock, flags); |
| 758 | pg->flags &= ~ALUA_PG_RUNNING; |
| 759 | pg->flags |= ALUA_PG_RUN_RTPG; |
| 760 | spin_unlock_irqrestore(&pg->lock, flags); |
| 761 | queue_delayed_work(alua_wq, &pg->rtpg_work, |
| 762 | pg->interval * HZ); |
| 763 | return; |
| 764 | } |
| 765 | /* Send RTPG on failure or if TUR indicates SUCCESS */ |
| 766 | } |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 767 | err = alua_rtpg(sdev, pg); |
| 768 | spin_lock_irqsave(&pg->lock, flags); |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 769 | if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) { |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 770 | pg->flags &= ~ALUA_PG_RUNNING; |
| 771 | pg->flags |= ALUA_PG_RUN_RTPG; |
| 772 | spin_unlock_irqrestore(&pg->lock, flags); |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 773 | queue_delayed_work(alua_wq, &pg->rtpg_work, |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 774 | pg->interval * HZ); |
| 775 | return; |
| 776 | } |
| 777 | if (err != SCSI_DH_OK) |
| 778 | pg->flags &= ~ALUA_PG_RUN_STPG; |
| 779 | } |
| 780 | if (pg->flags & ALUA_PG_RUN_STPG) { |
| 781 | pg->flags &= ~ALUA_PG_RUN_STPG; |
| 782 | spin_unlock_irqrestore(&pg->lock, flags); |
| 783 | err = alua_stpg(sdev, pg); |
| 784 | spin_lock_irqsave(&pg->lock, flags); |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 785 | if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) { |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 786 | pg->flags |= ALUA_PG_RUN_RTPG; |
| 787 | pg->interval = 0; |
| 788 | pg->flags &= ~ALUA_PG_RUNNING; |
| 789 | spin_unlock_irqrestore(&pg->lock, flags); |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 790 | queue_delayed_work(alua_wq, &pg->rtpg_work, |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 791 | pg->interval * HZ); |
| 792 | return; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | list_splice_init(&pg->rtpg_list, &qdata_list); |
| 797 | pg->rtpg_sdev = NULL; |
| 798 | spin_unlock_irqrestore(&pg->lock, flags); |
| 799 | |
| 800 | list_for_each_entry_safe(qdata, tmp, &qdata_list, entry) { |
| 801 | list_del(&qdata->entry); |
| 802 | if (qdata->callback_fn) |
| 803 | qdata->callback_fn(qdata->callback_data, err); |
| 804 | kfree(qdata); |
| 805 | } |
| 806 | spin_lock_irqsave(&pg->lock, flags); |
| 807 | pg->flags &= ~ALUA_PG_RUNNING; |
| 808 | spin_unlock_irqrestore(&pg->lock, flags); |
| 809 | scsi_device_put(sdev); |
| 810 | kref_put(&pg->kref, release_port_group); |
| 811 | } |
| 812 | |
| 813 | static void alua_rtpg_queue(struct alua_port_group *pg, |
| 814 | struct scsi_device *sdev, |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 815 | struct alua_queue_data *qdata, bool force) |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 816 | { |
| 817 | int start_queue = 0; |
| 818 | unsigned long flags; |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 819 | struct workqueue_struct *alua_wq = kaluad_wq; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 820 | |
| 821 | if (!pg) |
| 822 | return; |
| 823 | |
| 824 | spin_lock_irqsave(&pg->lock, flags); |
| 825 | if (qdata) { |
| 826 | list_add_tail(&qdata->entry, &pg->rtpg_list); |
| 827 | pg->flags |= ALUA_PG_RUN_STPG; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 828 | force = true; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 829 | } |
| 830 | if (pg->rtpg_sdev == NULL) { |
| 831 | pg->interval = 0; |
| 832 | pg->flags |= ALUA_PG_RUN_RTPG; |
| 833 | kref_get(&pg->kref); |
| 834 | pg->rtpg_sdev = sdev; |
| 835 | scsi_device_get(sdev); |
| 836 | start_queue = 1; |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 837 | } else if (!(pg->flags & ALUA_PG_RUN_RTPG) && force) { |
| 838 | pg->flags |= ALUA_PG_RUN_RTPG; |
| 839 | /* Do not queue if the worker is already running */ |
| 840 | if (!(pg->flags & ALUA_PG_RUNNING)) { |
| 841 | kref_get(&pg->kref); |
| 842 | start_queue = 1; |
| 843 | } |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 844 | } |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 845 | |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 846 | if (pg->flags & ALUA_SYNC_STPG) |
| 847 | alua_wq = kaluad_sync_wq; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 848 | spin_unlock_irqrestore(&pg->lock, flags); |
| 849 | |
| 850 | if (start_queue && |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 851 | !queue_delayed_work(alua_wq, &pg->rtpg_work, |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 852 | msecs_to_jiffies(ALUA_RTPG_DELAY_MSECS))) { |
| 853 | scsi_device_put(sdev); |
| 854 | kref_put(&pg->kref, release_port_group); |
| 855 | } |
| 856 | } |
| 857 | |
Hannes Reinecke | f2ecf13 | 2016-02-19 09:16:59 +0100 | [diff] [blame] | 858 | /* |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 859 | * alua_initialize - Initialize ALUA state |
| 860 | * @sdev: the device to be initialized |
| 861 | * |
| 862 | * For the prep_fn to work correctly we have |
| 863 | * to initialize the ALUA state for the device. |
| 864 | */ |
| 865 | static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h) |
| 866 | { |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 867 | int err = SCSI_DH_DEV_UNSUPP, tpgs; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 868 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 869 | mutex_lock(&h->init_mutex); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 870 | tpgs = alua_check_tpgs(sdev); |
Hannes Reinecke | a4253fd | 2016-02-19 09:17:06 +0100 | [diff] [blame] | 871 | if (tpgs != TPGS_MODE_NONE) |
| 872 | err = alua_check_vpd(sdev, h, tpgs); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 873 | h->init_error = err; |
| 874 | mutex_unlock(&h->init_mutex); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 875 | return err; |
| 876 | } |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 877 | /* |
| 878 | * alua_set_params - set/unset the optimize flag |
| 879 | * @sdev: device on the path to be activated |
| 880 | * params - parameters in the following format |
| 881 | * "no_of_params\0param1\0param2\0param3\0...\0" |
| 882 | * For example, to set the flag pass the following parameters |
| 883 | * from multipath.conf |
| 884 | * hardware_handler "2 alua 1" |
| 885 | */ |
| 886 | static int alua_set_params(struct scsi_device *sdev, const char *params) |
| 887 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 888 | struct alua_dh_data *h = sdev->handler_data; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 889 | struct alua_port_group __rcu *pg = NULL; |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 890 | unsigned int optimize = 0, argc; |
| 891 | const char *p = params; |
| 892 | int result = SCSI_DH_OK; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 893 | unsigned long flags; |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 894 | |
| 895 | if ((sscanf(params, "%u", &argc) != 1) || (argc != 1)) |
| 896 | return -EINVAL; |
| 897 | |
| 898 | while (*p++) |
| 899 | ; |
| 900 | if ((sscanf(p, "%u", &optimize) != 1) || (optimize > 1)) |
| 901 | return -EINVAL; |
| 902 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 903 | rcu_read_lock(); |
| 904 | pg = rcu_dereference(h->pg); |
| 905 | if (!pg) { |
| 906 | rcu_read_unlock(); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 907 | return -ENXIO; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 908 | } |
| 909 | spin_lock_irqsave(&pg->lock, flags); |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 910 | if (optimize) |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 911 | pg->flags |= ALUA_OPTIMIZE_STPG; |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 912 | else |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 913 | pg->flags &= ~ALUA_OPTIMIZE_STPG; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 914 | spin_unlock_irqrestore(&pg->lock, flags); |
| 915 | rcu_read_unlock(); |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 916 | |
| 917 | return result; |
| 918 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 919 | |
| 920 | /* |
| 921 | * alua_activate - activate a path |
| 922 | * @sdev: device on the path to be activated |
| 923 | * |
| 924 | * We're currently switching the port group to be activated only and |
| 925 | * let the array figure out the rest. |
| 926 | * There may be other arrays which require us to switch all port groups |
| 927 | * based on a certain policy. But until we actually encounter them it |
| 928 | * should be okay. |
| 929 | */ |
Chandra Seetharaman | 3ae31f6 | 2009-10-21 09:22:46 -0700 | [diff] [blame] | 930 | static int alua_activate(struct scsi_device *sdev, |
| 931 | activate_complete fn, void *data) |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 932 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 933 | struct alua_dh_data *h = sdev->handler_data; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 934 | int err = SCSI_DH_OK; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 935 | struct alua_queue_data *qdata; |
| 936 | struct alua_port_group __rcu *pg; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 937 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 938 | qdata = kzalloc(sizeof(*qdata), GFP_KERNEL); |
| 939 | if (!qdata) { |
| 940 | err = SCSI_DH_RES_TEMP_UNAVAIL; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 941 | goto out; |
| 942 | } |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 943 | qdata->callback_fn = fn; |
| 944 | qdata->callback_data = data; |
| 945 | |
| 946 | mutex_lock(&h->init_mutex); |
| 947 | rcu_read_lock(); |
| 948 | pg = rcu_dereference(h->pg); |
| 949 | if (!pg || !kref_get_unless_zero(&pg->kref)) { |
| 950 | rcu_read_unlock(); |
| 951 | kfree(qdata); |
| 952 | err = h->init_error; |
| 953 | mutex_unlock(&h->init_mutex); |
| 954 | goto out; |
| 955 | } |
| 956 | fn = NULL; |
| 957 | rcu_read_unlock(); |
| 958 | mutex_unlock(&h->init_mutex); |
| 959 | |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 960 | alua_rtpg_queue(pg, sdev, qdata, true); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 961 | kref_put(&pg->kref, release_port_group); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 962 | out: |
Hannes Reinecke | b246075 | 2016-02-19 09:17:00 +0100 | [diff] [blame] | 963 | if (fn) |
Chandra Seetharaman | 3ae31f6 | 2009-10-21 09:22:46 -0700 | [diff] [blame] | 964 | fn(data, err); |
| 965 | return 0; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /* |
Hannes Reinecke | 2b35865 | 2016-02-19 09:17:13 +0100 | [diff] [blame] | 969 | * alua_check - check path status |
| 970 | * @sdev: device on the path to be checked |
| 971 | * |
| 972 | * Check the device status |
| 973 | */ |
| 974 | static void alua_check(struct scsi_device *sdev, bool force) |
| 975 | { |
| 976 | struct alua_dh_data *h = sdev->handler_data; |
| 977 | struct alua_port_group *pg; |
| 978 | |
| 979 | rcu_read_lock(); |
| 980 | pg = rcu_dereference(h->pg); |
| 981 | if (!pg || !kref_get_unless_zero(&pg->kref)) { |
| 982 | rcu_read_unlock(); |
| 983 | return; |
| 984 | } |
| 985 | rcu_read_unlock(); |
| 986 | |
| 987 | alua_rtpg_queue(pg, sdev, NULL, force); |
| 988 | kref_put(&pg->kref, release_port_group); |
| 989 | } |
| 990 | |
| 991 | /* |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 992 | * alua_prep_fn - request callback |
| 993 | * |
| 994 | * Fail I/O to all paths not in state |
| 995 | * active/optimized or active/non-optimized. |
| 996 | */ |
| 997 | static int alua_prep_fn(struct scsi_device *sdev, struct request *req) |
| 998 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 999 | struct alua_dh_data *h = sdev->handler_data; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1000 | struct alua_port_group __rcu *pg; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 1001 | unsigned char state = SCSI_ACCESS_STATE_OPTIMAL; |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1002 | int ret = BLKPREP_OK; |
| 1003 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1004 | rcu_read_lock(); |
| 1005 | pg = rcu_dereference(h->pg); |
| 1006 | if (pg) |
| 1007 | state = pg->state; |
| 1008 | rcu_read_unlock(); |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 1009 | if (state == SCSI_ACCESS_STATE_TRANSITIONING) |
Hannes Reinecke | 69723d1 | 2010-09-24 15:57:04 +0200 | [diff] [blame] | 1010 | ret = BLKPREP_DEFER; |
Hannes Reinecke | 5115fc7 | 2016-03-03 07:54:08 +0100 | [diff] [blame^] | 1011 | else if (state != SCSI_ACCESS_STATE_OPTIMAL && |
| 1012 | state != SCSI_ACCESS_STATE_ACTIVE && |
| 1013 | state != SCSI_ACCESS_STATE_LBA) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1014 | ret = BLKPREP_KILL; |
| 1015 | req->cmd_flags |= REQ_QUIET; |
| 1016 | } |
| 1017 | return ret; |
| 1018 | |
| 1019 | } |
| 1020 | |
Hannes Reinecke | d3d3289 | 2016-02-19 09:17:16 +0100 | [diff] [blame] | 1021 | static void alua_rescan(struct scsi_device *sdev) |
| 1022 | { |
| 1023 | struct alua_dh_data *h = sdev->handler_data; |
| 1024 | |
| 1025 | alua_initialize(sdev, h); |
| 1026 | } |
| 1027 | |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1028 | /* |
| 1029 | * alua_bus_attach - Attach device handler |
| 1030 | * @sdev: device to be attached to |
| 1031 | */ |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 1032 | static int alua_bus_attach(struct scsi_device *sdev) |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1033 | { |
| 1034 | struct alua_dh_data *h; |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 1035 | int err, ret = -EINVAL; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1036 | |
| 1037 | h = kzalloc(sizeof(*h) , GFP_KERNEL); |
| 1038 | if (!h) |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 1039 | return -ENOMEM; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1040 | spin_lock_init(&h->pg_lock); |
| 1041 | rcu_assign_pointer(h->pg, NULL); |
| 1042 | h->init_error = SCSI_DH_OK; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1043 | h->sdev = sdev; |
| 1044 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1045 | mutex_init(&h->init_mutex); |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1046 | err = alua_initialize(sdev, h); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 1047 | if (err == SCSI_DH_NOMEM) |
| 1048 | ret = -ENOMEM; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1049 | if (err != SCSI_DH_OK && err != SCSI_DH_DEV_OFFLINED) |
| 1050 | goto failed; |
| 1051 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 1052 | sdev->handler_data = h; |
| 1053 | return 0; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1054 | failed: |
| 1055 | kfree(h); |
Hannes Reinecke | 43394c6 | 2016-02-19 09:17:04 +0100 | [diff] [blame] | 1056 | return ret; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | /* |
| 1060 | * alua_bus_detach - Detach device handler |
| 1061 | * @sdev: device to be detached from |
| 1062 | */ |
| 1063 | static void alua_bus_detach(struct scsi_device *sdev) |
| 1064 | { |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 1065 | struct alua_dh_data *h = sdev->handler_data; |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1066 | struct alua_port_group *pg; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1067 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1068 | spin_lock(&h->pg_lock); |
| 1069 | pg = h->pg; |
| 1070 | rcu_assign_pointer(h->pg, NULL); |
| 1071 | h->sdev = NULL; |
| 1072 | spin_unlock(&h->pg_lock); |
| 1073 | if (pg) |
| 1074 | kref_put(&pg->kref, release_port_group); |
| 1075 | |
Christoph Hellwig | ee14c67 | 2015-08-27 14:16:59 +0200 | [diff] [blame] | 1076 | sdev->handler_data = NULL; |
Christoph Hellwig | 1d52032 | 2014-09-14 11:08:21 -0700 | [diff] [blame] | 1077 | kfree(h); |
| 1078 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1079 | |
| 1080 | static struct scsi_device_handler alua_dh = { |
| 1081 | .name = ALUA_DH_NAME, |
| 1082 | .module = THIS_MODULE, |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1083 | .attach = alua_bus_attach, |
| 1084 | .detach = alua_bus_detach, |
| 1085 | .prep_fn = alua_prep_fn, |
| 1086 | .check_sense = alua_check_sense, |
| 1087 | .activate = alua_activate, |
Hannes Reinecke | d3d3289 | 2016-02-19 09:17:16 +0100 | [diff] [blame] | 1088 | .rescan = alua_rescan, |
Moger, Babu | 4335d09 | 2012-03-27 20:55:49 +0000 | [diff] [blame] | 1089 | .set_params = alua_set_params, |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1090 | }; |
| 1091 | |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1092 | static int __init alua_init(void) |
| 1093 | { |
| 1094 | int r; |
| 1095 | |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1096 | kaluad_wq = alloc_workqueue("kaluad", WQ_MEM_RECLAIM, 0); |
| 1097 | if (!kaluad_wq) { |
| 1098 | /* Temporary failure, bypass */ |
| 1099 | return SCSI_DH_DEV_TEMP_BUSY; |
| 1100 | } |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 1101 | kaluad_sync_wq = create_workqueue("kaluad_sync"); |
| 1102 | if (!kaluad_sync_wq) { |
| 1103 | destroy_workqueue(kaluad_wq); |
| 1104 | return SCSI_DH_DEV_TEMP_BUSY; |
| 1105 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1106 | r = scsi_register_device_handler(&alua_dh); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1107 | if (r != 0) { |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1108 | printk(KERN_ERR "%s: Failed to register scsi device handler", |
| 1109 | ALUA_DH_NAME); |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 1110 | destroy_workqueue(kaluad_sync_wq); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1111 | destroy_workqueue(kaluad_wq); |
| 1112 | } |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1113 | return r; |
| 1114 | } |
| 1115 | |
| 1116 | static void __exit alua_exit(void) |
| 1117 | { |
| 1118 | scsi_unregister_device_handler(&alua_dh); |
Hannes Reinecke | 00642a1 | 2016-02-19 09:17:11 +0100 | [diff] [blame] | 1119 | destroy_workqueue(kaluad_sync_wq); |
Hannes Reinecke | 03197b6 | 2016-02-19 09:17:10 +0100 | [diff] [blame] | 1120 | destroy_workqueue(kaluad_wq); |
Hannes Reinecke | 057ea7c | 2008-07-17 16:53:21 -0700 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | module_init(alua_init); |
| 1124 | module_exit(alua_exit); |
| 1125 | |
| 1126 | MODULE_DESCRIPTION("DM Multipath ALUA support"); |
| 1127 | MODULE_AUTHOR("Hannes Reinecke <hare@suse.de>"); |
| 1128 | MODULE_LICENSE("GPL"); |
| 1129 | MODULE_VERSION(ALUA_DH_VER); |