Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Filename: target_core_device.c (based on iscsi_target_device.c) |
| 3 | * |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 4 | * This file contains the TCM Virtual Device and Disk Transport |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 5 | * agnostic related functions. |
| 6 | * |
| 7 | * Copyright (c) 2003, 2004, 2005 PyX Technologies, Inc. |
| 8 | * Copyright (c) 2005-2006 SBE, Inc. All Rights Reserved. |
| 9 | * Copyright (c) 2007-2010 Rising Tide Systems |
| 10 | * Copyright (c) 2008-2010 Linux-iSCSI.org |
| 11 | * |
| 12 | * Nicholas A. Bellinger <nab@kernel.org> |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 27 | * |
| 28 | ******************************************************************************/ |
| 29 | |
| 30 | #include <linux/net.h> |
| 31 | #include <linux/string.h> |
| 32 | #include <linux/delay.h> |
| 33 | #include <linux/timer.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/spinlock.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 36 | #include <linux/kthread.h> |
| 37 | #include <linux/in.h> |
| 38 | #include <net/sock.h> |
| 39 | #include <net/tcp.h> |
| 40 | #include <scsi/scsi.h> |
Nicholas Bellinger | 1078da1 | 2011-05-19 20:19:13 -0700 | [diff] [blame] | 41 | #include <scsi/scsi_device.h> |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 42 | |
| 43 | #include <target/target_core_base.h> |
| 44 | #include <target/target_core_device.h> |
| 45 | #include <target/target_core_tpg.h> |
| 46 | #include <target/target_core_transport.h> |
| 47 | #include <target/target_core_fabric_ops.h> |
| 48 | |
| 49 | #include "target_core_alua.h" |
| 50 | #include "target_core_hba.h" |
| 51 | #include "target_core_pr.h" |
| 52 | #include "target_core_ua.h" |
| 53 | |
| 54 | static void se_dev_start(struct se_device *dev); |
| 55 | static void se_dev_stop(struct se_device *dev); |
| 56 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 57 | static struct se_hba *lun0_hba; |
| 58 | static struct se_subsystem_dev *lun0_su_dev; |
| 59 | /* not static, needed by tpg.c */ |
| 60 | struct se_device *g_lun0_dev; |
| 61 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 62 | int transport_lookup_cmd_lun(struct se_cmd *se_cmd, u32 unpacked_lun) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 63 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 64 | struct se_lun *se_lun = NULL; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 65 | struct se_session *se_sess = se_cmd->se_sess; |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 66 | struct se_device *dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 67 | unsigned long flags; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 68 | |
Fubo Chen | d814495 | 2011-02-13 15:13:42 -0800 | [diff] [blame] | 69 | if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) { |
| 70 | se_cmd->scsi_sense_reason = TCM_NON_EXISTENT_LUN; |
| 71 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 72 | return -ENODEV; |
Fubo Chen | d814495 | 2011-02-13 15:13:42 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Roland Dreier | 78faae3 | 2011-07-20 09:09:10 +0000 | [diff] [blame] | 75 | spin_lock_irqsave(&se_sess->se_node_acl->device_list_lock, flags); |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 76 | se_cmd->se_deve = &se_sess->se_node_acl->device_list[unpacked_lun]; |
| 77 | if (se_cmd->se_deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { |
| 78 | struct se_dev_entry *deve = se_cmd->se_deve; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 79 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 80 | deve->total_cmds++; |
| 81 | deve->total_bytes += se_cmd->data_length; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 82 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 83 | if ((se_cmd->data_direction == DMA_TO_DEVICE) && |
| 84 | (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 85 | se_cmd->scsi_sense_reason = TCM_WRITE_PROTECTED; |
| 86 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 87 | printk("TARGET_CORE[%s]: Detected WRITE_PROTECTED LUN" |
| 88 | " Access for 0x%08x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 89 | se_cmd->se_tfo->get_fabric_name(), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 90 | unpacked_lun); |
Roland Dreier | 78faae3 | 2011-07-20 09:09:10 +0000 | [diff] [blame] | 91 | spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 92 | return -EACCES; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 93 | } |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 94 | |
| 95 | if (se_cmd->data_direction == DMA_TO_DEVICE) |
| 96 | deve->write_bytes += se_cmd->data_length; |
| 97 | else if (se_cmd->data_direction == DMA_FROM_DEVICE) |
| 98 | deve->read_bytes += se_cmd->data_length; |
| 99 | |
| 100 | deve->deve_cmds++; |
| 101 | |
| 102 | se_lun = deve->se_lun; |
| 103 | se_cmd->se_lun = deve->se_lun; |
| 104 | se_cmd->pr_res_key = deve->pr_res_key; |
| 105 | se_cmd->orig_fe_lun = unpacked_lun; |
| 106 | se_cmd->se_orig_obj_ptr = se_cmd->se_lun->lun_se_dev; |
| 107 | se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; |
| 108 | } |
Roland Dreier | 78faae3 | 2011-07-20 09:09:10 +0000 | [diff] [blame] | 109 | spin_unlock_irqrestore(&se_sess->se_node_acl->device_list_lock, flags); |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 110 | |
| 111 | if (!se_lun) { |
| 112 | /* |
| 113 | * Use the se_portal_group->tpg_virt_lun0 to allow for |
| 114 | * REPORT_LUNS, et al to be returned when no active |
| 115 | * MappedLUN=0 exists for this Initiator Port. |
| 116 | */ |
| 117 | if (unpacked_lun != 0) { |
| 118 | se_cmd->scsi_sense_reason = TCM_NON_EXISTENT_LUN; |
| 119 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 120 | printk("TARGET_CORE[%s]: Detected NON_EXISTENT_LUN" |
| 121 | " Access for 0x%08x\n", |
| 122 | se_cmd->se_tfo->get_fabric_name(), |
| 123 | unpacked_lun); |
| 124 | return -ENODEV; |
| 125 | } |
| 126 | /* |
| 127 | * Force WRITE PROTECT for virtual LUN 0 |
| 128 | */ |
| 129 | if ((se_cmd->data_direction != DMA_FROM_DEVICE) && |
| 130 | (se_cmd->data_direction != DMA_NONE)) { |
| 131 | se_cmd->scsi_sense_reason = TCM_WRITE_PROTECTED; |
| 132 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
| 133 | return -EACCES; |
| 134 | } |
| 135 | |
| 136 | se_lun = &se_sess->se_tpg->tpg_virt_lun0; |
| 137 | se_cmd->se_lun = &se_sess->se_tpg->tpg_virt_lun0; |
| 138 | se_cmd->orig_fe_lun = 0; |
| 139 | se_cmd->se_orig_obj_ptr = se_cmd->se_lun->lun_se_dev; |
| 140 | se_cmd->se_cmd_flags |= SCF_SE_LUN_CMD; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 141 | } |
| 142 | /* |
| 143 | * Determine if the struct se_lun is online. |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 144 | * FIXME: Check for LUN_RESET + UNIT Attention |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 145 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 146 | if (se_dev_check_online(se_lun->lun_se_dev) != 0) { |
| 147 | se_cmd->scsi_sense_reason = TCM_NON_EXISTENT_LUN; |
| 148 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 149 | return -ENODEV; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 150 | } |
| 151 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 152 | /* Directly associate cmd with se_dev */ |
| 153 | se_cmd->se_dev = se_lun->lun_se_dev; |
| 154 | |
| 155 | /* TODO: get rid of this and use atomics for stats */ |
| 156 | dev = se_lun->lun_se_dev; |
Roland Dreier | 78faae3 | 2011-07-20 09:09:10 +0000 | [diff] [blame] | 157 | spin_lock_irqsave(&dev->stats_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 158 | dev->num_cmds++; |
| 159 | if (se_cmd->data_direction == DMA_TO_DEVICE) |
| 160 | dev->write_bytes += se_cmd->data_length; |
| 161 | else if (se_cmd->data_direction == DMA_FROM_DEVICE) |
| 162 | dev->read_bytes += se_cmd->data_length; |
Roland Dreier | 78faae3 | 2011-07-20 09:09:10 +0000 | [diff] [blame] | 163 | spin_unlock_irqrestore(&dev->stats_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 164 | |
| 165 | /* |
| 166 | * Add the iscsi_cmd_t to the struct se_lun's cmd list. This list is used |
| 167 | * for tracking state of struct se_cmds during LUN shutdown events. |
| 168 | */ |
| 169 | spin_lock_irqsave(&se_lun->lun_cmd_lock, flags); |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 170 | list_add_tail(&se_cmd->se_lun_node, &se_lun->lun_cmd_list); |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 171 | atomic_set(&se_cmd->transport_lun_active, 1); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 172 | spin_unlock_irqrestore(&se_lun->lun_cmd_lock, flags); |
| 173 | |
| 174 | return 0; |
| 175 | } |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 176 | EXPORT_SYMBOL(transport_lookup_cmd_lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 177 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 178 | int transport_lookup_tmr_lun(struct se_cmd *se_cmd, u32 unpacked_lun) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 179 | { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 180 | struct se_dev_entry *deve; |
| 181 | struct se_lun *se_lun = NULL; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 182 | struct se_session *se_sess = se_cmd->se_sess; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 183 | struct se_tmr_req *se_tmr = se_cmd->se_tmr_req; |
| 184 | |
Fubo Chen | d814495 | 2011-02-13 15:13:42 -0800 | [diff] [blame] | 185 | if (unpacked_lun >= TRANSPORT_MAX_LUNS_PER_TPG) { |
| 186 | se_cmd->scsi_sense_reason = TCM_NON_EXISTENT_LUN; |
| 187 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 188 | return -ENODEV; |
Fubo Chen | d814495 | 2011-02-13 15:13:42 -0800 | [diff] [blame] | 189 | } |
| 190 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 191 | spin_lock_irq(&se_sess->se_node_acl->device_list_lock); |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 192 | se_cmd->se_deve = &se_sess->se_node_acl->device_list[unpacked_lun]; |
| 193 | deve = se_cmd->se_deve; |
| 194 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 195 | if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 196 | se_tmr->tmr_lun = deve->se_lun; |
| 197 | se_cmd->se_lun = deve->se_lun; |
| 198 | se_lun = deve->se_lun; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 199 | se_cmd->pr_res_key = deve->pr_res_key; |
| 200 | se_cmd->orig_fe_lun = unpacked_lun; |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 201 | se_cmd->se_orig_obj_ptr = se_cmd->se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 202 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 203 | spin_unlock_irq(&se_sess->se_node_acl->device_list_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 204 | |
| 205 | if (!se_lun) { |
| 206 | printk(KERN_INFO "TARGET_CORE[%s]: Detected NON_EXISTENT_LUN" |
| 207 | " Access for 0x%08x\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 208 | se_cmd->se_tfo->get_fabric_name(), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 209 | unpacked_lun); |
| 210 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 211 | return -ENODEV; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 212 | } |
| 213 | /* |
| 214 | * Determine if the struct se_lun is online. |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 215 | * FIXME: Check for LUN_RESET + UNIT Attention |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 216 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 217 | if (se_dev_check_online(se_lun->lun_se_dev) != 0) { |
| 218 | se_cmd->se_cmd_flags |= SCF_SCSI_CDB_EXCEPTION; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 219 | return -ENODEV; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 220 | } |
| 221 | |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 222 | /* Directly associate cmd with se_dev */ |
| 223 | se_cmd->se_dev = se_lun->lun_se_dev; |
| 224 | se_tmr->tmr_dev = se_lun->lun_se_dev; |
| 225 | |
| 226 | spin_lock(&se_tmr->tmr_dev->se_tmr_lock); |
| 227 | list_add_tail(&se_tmr->tmr_list, &se_tmr->tmr_dev->dev_tmr_list); |
| 228 | spin_unlock(&se_tmr->tmr_dev->se_tmr_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 229 | |
| 230 | return 0; |
| 231 | } |
Andy Grover | 5951146d | 2011-07-19 10:26:37 +0000 | [diff] [blame] | 232 | EXPORT_SYMBOL(transport_lookup_tmr_lun); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 233 | |
| 234 | /* |
| 235 | * This function is called from core_scsi3_emulate_pro_register_and_move() |
| 236 | * and core_scsi3_decode_spec_i_port(), and will increment &deve->pr_ref_count |
| 237 | * when a matching rtpi is found. |
| 238 | */ |
| 239 | struct se_dev_entry *core_get_se_deve_from_rtpi( |
| 240 | struct se_node_acl *nacl, |
| 241 | u16 rtpi) |
| 242 | { |
| 243 | struct se_dev_entry *deve; |
| 244 | struct se_lun *lun; |
| 245 | struct se_port *port; |
| 246 | struct se_portal_group *tpg = nacl->se_tpg; |
| 247 | u32 i; |
| 248 | |
| 249 | spin_lock_irq(&nacl->device_list_lock); |
| 250 | for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { |
| 251 | deve = &nacl->device_list[i]; |
| 252 | |
| 253 | if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) |
| 254 | continue; |
| 255 | |
| 256 | lun = deve->se_lun; |
| 257 | if (!(lun)) { |
| 258 | printk(KERN_ERR "%s device entries device pointer is" |
| 259 | " NULL, but Initiator has access.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 260 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 261 | continue; |
| 262 | } |
| 263 | port = lun->lun_sep; |
| 264 | if (!(port)) { |
| 265 | printk(KERN_ERR "%s device entries device pointer is" |
| 266 | " NULL, but Initiator has access.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 267 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 268 | continue; |
| 269 | } |
| 270 | if (port->sep_rtpi != rtpi) |
| 271 | continue; |
| 272 | |
| 273 | atomic_inc(&deve->pr_ref_count); |
| 274 | smp_mb__after_atomic_inc(); |
| 275 | spin_unlock_irq(&nacl->device_list_lock); |
| 276 | |
| 277 | return deve; |
| 278 | } |
| 279 | spin_unlock_irq(&nacl->device_list_lock); |
| 280 | |
| 281 | return NULL; |
| 282 | } |
| 283 | |
| 284 | int core_free_device_list_for_node( |
| 285 | struct se_node_acl *nacl, |
| 286 | struct se_portal_group *tpg) |
| 287 | { |
| 288 | struct se_dev_entry *deve; |
| 289 | struct se_lun *lun; |
| 290 | u32 i; |
| 291 | |
| 292 | if (!nacl->device_list) |
| 293 | return 0; |
| 294 | |
| 295 | spin_lock_irq(&nacl->device_list_lock); |
| 296 | for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { |
| 297 | deve = &nacl->device_list[i]; |
| 298 | |
| 299 | if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) |
| 300 | continue; |
| 301 | |
| 302 | if (!deve->se_lun) { |
| 303 | printk(KERN_ERR "%s device entries device pointer is" |
| 304 | " NULL, but Initiator has access.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 305 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 306 | continue; |
| 307 | } |
| 308 | lun = deve->se_lun; |
| 309 | |
| 310 | spin_unlock_irq(&nacl->device_list_lock); |
| 311 | core_update_device_list_for_node(lun, NULL, deve->mapped_lun, |
| 312 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); |
| 313 | spin_lock_irq(&nacl->device_list_lock); |
| 314 | } |
| 315 | spin_unlock_irq(&nacl->device_list_lock); |
| 316 | |
| 317 | kfree(nacl->device_list); |
| 318 | nacl->device_list = NULL; |
| 319 | |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | void core_dec_lacl_count(struct se_node_acl *se_nacl, struct se_cmd *se_cmd) |
| 324 | { |
| 325 | struct se_dev_entry *deve; |
| 326 | |
| 327 | spin_lock_irq(&se_nacl->device_list_lock); |
| 328 | deve = &se_nacl->device_list[se_cmd->orig_fe_lun]; |
| 329 | deve->deve_cmds--; |
| 330 | spin_unlock_irq(&se_nacl->device_list_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | void core_update_device_list_access( |
| 334 | u32 mapped_lun, |
| 335 | u32 lun_access, |
| 336 | struct se_node_acl *nacl) |
| 337 | { |
| 338 | struct se_dev_entry *deve; |
| 339 | |
| 340 | spin_lock_irq(&nacl->device_list_lock); |
| 341 | deve = &nacl->device_list[mapped_lun]; |
| 342 | if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { |
| 343 | deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; |
| 344 | deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; |
| 345 | } else { |
| 346 | deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; |
| 347 | deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; |
| 348 | } |
| 349 | spin_unlock_irq(&nacl->device_list_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /* core_update_device_list_for_node(): |
| 353 | * |
| 354 | * |
| 355 | */ |
| 356 | int core_update_device_list_for_node( |
| 357 | struct se_lun *lun, |
| 358 | struct se_lun_acl *lun_acl, |
| 359 | u32 mapped_lun, |
| 360 | u32 lun_access, |
| 361 | struct se_node_acl *nacl, |
| 362 | struct se_portal_group *tpg, |
| 363 | int enable) |
| 364 | { |
| 365 | struct se_port *port = lun->lun_sep; |
| 366 | struct se_dev_entry *deve = &nacl->device_list[mapped_lun]; |
| 367 | int trans = 0; |
| 368 | /* |
| 369 | * If the MappedLUN entry is being disabled, the entry in |
| 370 | * port->sep_alua_list must be removed now before clearing the |
| 371 | * struct se_dev_entry pointers below as logic in |
| 372 | * core_alua_do_transition_tg_pt() depends on these being present. |
| 373 | */ |
| 374 | if (!(enable)) { |
| 375 | /* |
| 376 | * deve->se_lun_acl will be NULL for demo-mode created LUNs |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 377 | * that have not been explicitly concerted to MappedLUNs -> |
Nicholas Bellinger | 29fe609 | 2011-02-09 15:34:43 -0800 | [diff] [blame] | 378 | * struct se_lun_acl, but we remove deve->alua_port_list from |
| 379 | * port->sep_alua_list. This also means that active UAs and |
| 380 | * NodeACL context specific PR metadata for demo-mode |
| 381 | * MappedLUN *deve will be released below.. |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 382 | */ |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 383 | spin_lock_bh(&port->sep_alua_lock); |
| 384 | list_del(&deve->alua_port_list); |
| 385 | spin_unlock_bh(&port->sep_alua_lock); |
| 386 | } |
| 387 | |
| 388 | spin_lock_irq(&nacl->device_list_lock); |
| 389 | if (enable) { |
| 390 | /* |
| 391 | * Check if the call is handling demo mode -> explict LUN ACL |
| 392 | * transition. This transition must be for the same struct se_lun |
| 393 | * + mapped_lun that was setup in demo mode.. |
| 394 | */ |
| 395 | if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) { |
| 396 | if (deve->se_lun_acl != NULL) { |
| 397 | printk(KERN_ERR "struct se_dev_entry->se_lun_acl" |
| 398 | " already set for demo mode -> explict" |
| 399 | " LUN ACL transition\n"); |
Fubo Chen | 85dc98d | 2011-02-09 15:34:48 -0800 | [diff] [blame] | 400 | spin_unlock_irq(&nacl->device_list_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 401 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 402 | } |
| 403 | if (deve->se_lun != lun) { |
| 404 | printk(KERN_ERR "struct se_dev_entry->se_lun does" |
| 405 | " match passed struct se_lun for demo mode" |
| 406 | " -> explict LUN ACL transition\n"); |
Fubo Chen | 85dc98d | 2011-02-09 15:34:48 -0800 | [diff] [blame] | 407 | spin_unlock_irq(&nacl->device_list_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 408 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 409 | } |
| 410 | deve->se_lun_acl = lun_acl; |
| 411 | trans = 1; |
| 412 | } else { |
| 413 | deve->se_lun = lun; |
| 414 | deve->se_lun_acl = lun_acl; |
| 415 | deve->mapped_lun = mapped_lun; |
| 416 | deve->lun_flags |= TRANSPORT_LUNFLAGS_INITIATOR_ACCESS; |
| 417 | } |
| 418 | |
| 419 | if (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) { |
| 420 | deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_ONLY; |
| 421 | deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_WRITE; |
| 422 | } else { |
| 423 | deve->lun_flags &= ~TRANSPORT_LUNFLAGS_READ_WRITE; |
| 424 | deve->lun_flags |= TRANSPORT_LUNFLAGS_READ_ONLY; |
| 425 | } |
| 426 | |
| 427 | if (trans) { |
| 428 | spin_unlock_irq(&nacl->device_list_lock); |
| 429 | return 0; |
| 430 | } |
| 431 | deve->creation_time = get_jiffies_64(); |
| 432 | deve->attach_count++; |
| 433 | spin_unlock_irq(&nacl->device_list_lock); |
| 434 | |
| 435 | spin_lock_bh(&port->sep_alua_lock); |
| 436 | list_add_tail(&deve->alua_port_list, &port->sep_alua_list); |
| 437 | spin_unlock_bh(&port->sep_alua_lock); |
| 438 | |
| 439 | return 0; |
| 440 | } |
| 441 | /* |
| 442 | * Wait for any in process SPEC_I_PT=1 or REGISTER_AND_MOVE |
| 443 | * PR operation to complete. |
| 444 | */ |
| 445 | spin_unlock_irq(&nacl->device_list_lock); |
| 446 | while (atomic_read(&deve->pr_ref_count) != 0) |
| 447 | cpu_relax(); |
| 448 | spin_lock_irq(&nacl->device_list_lock); |
| 449 | /* |
| 450 | * Disable struct se_dev_entry LUN ACL mapping |
| 451 | */ |
| 452 | core_scsi3_ua_release_all(deve); |
| 453 | deve->se_lun = NULL; |
| 454 | deve->se_lun_acl = NULL; |
| 455 | deve->lun_flags = 0; |
| 456 | deve->creation_time = 0; |
| 457 | deve->attach_count--; |
| 458 | spin_unlock_irq(&nacl->device_list_lock); |
| 459 | |
| 460 | core_scsi3_free_pr_reg_from_nacl(lun->lun_se_dev, nacl); |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | /* core_clear_lun_from_tpg(): |
| 465 | * |
| 466 | * |
| 467 | */ |
| 468 | void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg) |
| 469 | { |
| 470 | struct se_node_acl *nacl; |
| 471 | struct se_dev_entry *deve; |
| 472 | u32 i; |
| 473 | |
| 474 | spin_lock_bh(&tpg->acl_node_lock); |
| 475 | list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) { |
| 476 | spin_unlock_bh(&tpg->acl_node_lock); |
| 477 | |
| 478 | spin_lock_irq(&nacl->device_list_lock); |
| 479 | for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { |
| 480 | deve = &nacl->device_list[i]; |
| 481 | if (lun != deve->se_lun) |
| 482 | continue; |
| 483 | spin_unlock_irq(&nacl->device_list_lock); |
| 484 | |
| 485 | core_update_device_list_for_node(lun, NULL, |
| 486 | deve->mapped_lun, TRANSPORT_LUNFLAGS_NO_ACCESS, |
| 487 | nacl, tpg, 0); |
| 488 | |
| 489 | spin_lock_irq(&nacl->device_list_lock); |
| 490 | } |
| 491 | spin_unlock_irq(&nacl->device_list_lock); |
| 492 | |
| 493 | spin_lock_bh(&tpg->acl_node_lock); |
| 494 | } |
| 495 | spin_unlock_bh(&tpg->acl_node_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | static struct se_port *core_alloc_port(struct se_device *dev) |
| 499 | { |
| 500 | struct se_port *port, *port_tmp; |
| 501 | |
| 502 | port = kzalloc(sizeof(struct se_port), GFP_KERNEL); |
| 503 | if (!(port)) { |
| 504 | printk(KERN_ERR "Unable to allocate struct se_port\n"); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 505 | return ERR_PTR(-ENOMEM); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 506 | } |
| 507 | INIT_LIST_HEAD(&port->sep_alua_list); |
| 508 | INIT_LIST_HEAD(&port->sep_list); |
| 509 | atomic_set(&port->sep_tg_pt_secondary_offline, 0); |
| 510 | spin_lock_init(&port->sep_alua_lock); |
| 511 | mutex_init(&port->sep_tg_pt_md_mutex); |
| 512 | |
| 513 | spin_lock(&dev->se_port_lock); |
| 514 | if (dev->dev_port_count == 0x0000ffff) { |
| 515 | printk(KERN_WARNING "Reached dev->dev_port_count ==" |
| 516 | " 0x0000ffff\n"); |
| 517 | spin_unlock(&dev->se_port_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 518 | return ERR_PTR(-ENOSPC); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 519 | } |
| 520 | again: |
| 521 | /* |
| 522 | * Allocate the next RELATIVE TARGET PORT IDENTIFER for this struct se_device |
| 523 | * Here is the table from spc4r17 section 7.7.3.8. |
| 524 | * |
| 525 | * Table 473 -- RELATIVE TARGET PORT IDENTIFIER field |
| 526 | * |
| 527 | * Code Description |
| 528 | * 0h Reserved |
| 529 | * 1h Relative port 1, historically known as port A |
| 530 | * 2h Relative port 2, historically known as port B |
| 531 | * 3h to FFFFh Relative port 3 through 65 535 |
| 532 | */ |
| 533 | port->sep_rtpi = dev->dev_rpti_counter++; |
| 534 | if (!(port->sep_rtpi)) |
| 535 | goto again; |
| 536 | |
| 537 | list_for_each_entry(port_tmp, &dev->dev_sep_list, sep_list) { |
| 538 | /* |
| 539 | * Make sure RELATIVE TARGET PORT IDENTIFER is unique |
| 540 | * for 16-bit wrap.. |
| 541 | */ |
| 542 | if (port->sep_rtpi == port_tmp->sep_rtpi) |
| 543 | goto again; |
| 544 | } |
| 545 | spin_unlock(&dev->se_port_lock); |
| 546 | |
| 547 | return port; |
| 548 | } |
| 549 | |
| 550 | static void core_export_port( |
| 551 | struct se_device *dev, |
| 552 | struct se_portal_group *tpg, |
| 553 | struct se_port *port, |
| 554 | struct se_lun *lun) |
| 555 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 556 | struct se_subsystem_dev *su_dev = dev->se_sub_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 557 | struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem = NULL; |
| 558 | |
| 559 | spin_lock(&dev->se_port_lock); |
| 560 | spin_lock(&lun->lun_sep_lock); |
| 561 | port->sep_tpg = tpg; |
| 562 | port->sep_lun = lun; |
| 563 | lun->lun_sep = port; |
| 564 | spin_unlock(&lun->lun_sep_lock); |
| 565 | |
| 566 | list_add_tail(&port->sep_list, &dev->dev_sep_list); |
| 567 | spin_unlock(&dev->se_port_lock); |
| 568 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 569 | if (su_dev->t10_alua.alua_type == SPC3_ALUA_EMULATED) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 570 | tg_pt_gp_mem = core_alua_allocate_tg_pt_gp_mem(port); |
| 571 | if (IS_ERR(tg_pt_gp_mem) || !tg_pt_gp_mem) { |
| 572 | printk(KERN_ERR "Unable to allocate t10_alua_tg_pt" |
| 573 | "_gp_member_t\n"); |
| 574 | return; |
| 575 | } |
| 576 | spin_lock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 577 | __core_alua_attach_tg_pt_gp_mem(tg_pt_gp_mem, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 578 | su_dev->t10_alua.default_tg_pt_gp); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 579 | spin_unlock(&tg_pt_gp_mem->tg_pt_gp_mem_lock); |
| 580 | printk(KERN_INFO "%s/%s: Adding to default ALUA Target Port" |
| 581 | " Group: alua/default_tg_pt_gp\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 582 | dev->transport->name, tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 583 | } |
| 584 | |
| 585 | dev->dev_port_count++; |
| 586 | port->sep_index = port->sep_rtpi; /* RELATIVE TARGET PORT IDENTIFER */ |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | * Called with struct se_device->se_port_lock spinlock held. |
| 591 | */ |
| 592 | static void core_release_port(struct se_device *dev, struct se_port *port) |
Dan Carpenter | 5dd7ed2 | 2011-03-14 04:06:01 -0700 | [diff] [blame] | 593 | __releases(&dev->se_port_lock) __acquires(&dev->se_port_lock) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 594 | { |
| 595 | /* |
| 596 | * Wait for any port reference for PR ALL_TG_PT=1 operation |
| 597 | * to complete in __core_scsi3_alloc_registration() |
| 598 | */ |
| 599 | spin_unlock(&dev->se_port_lock); |
| 600 | if (atomic_read(&port->sep_tg_pt_ref_cnt)) |
| 601 | cpu_relax(); |
| 602 | spin_lock(&dev->se_port_lock); |
| 603 | |
| 604 | core_alua_free_tg_pt_gp_mem(port); |
| 605 | |
| 606 | list_del(&port->sep_list); |
| 607 | dev->dev_port_count--; |
| 608 | kfree(port); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | int core_dev_export( |
| 612 | struct se_device *dev, |
| 613 | struct se_portal_group *tpg, |
| 614 | struct se_lun *lun) |
| 615 | { |
| 616 | struct se_port *port; |
| 617 | |
| 618 | port = core_alloc_port(dev); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 619 | if (IS_ERR(port)) |
| 620 | return PTR_ERR(port); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 621 | |
| 622 | lun->lun_se_dev = dev; |
| 623 | se_dev_start(dev); |
| 624 | |
| 625 | atomic_inc(&dev->dev_export_obj.obj_access_count); |
| 626 | core_export_port(dev, tpg, port, lun); |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | void core_dev_unexport( |
| 631 | struct se_device *dev, |
| 632 | struct se_portal_group *tpg, |
| 633 | struct se_lun *lun) |
| 634 | { |
| 635 | struct se_port *port = lun->lun_sep; |
| 636 | |
| 637 | spin_lock(&lun->lun_sep_lock); |
| 638 | if (lun->lun_se_dev == NULL) { |
| 639 | spin_unlock(&lun->lun_sep_lock); |
| 640 | return; |
| 641 | } |
| 642 | spin_unlock(&lun->lun_sep_lock); |
| 643 | |
| 644 | spin_lock(&dev->se_port_lock); |
| 645 | atomic_dec(&dev->dev_export_obj.obj_access_count); |
| 646 | core_release_port(dev, port); |
| 647 | spin_unlock(&dev->se_port_lock); |
| 648 | |
| 649 | se_dev_stop(dev); |
| 650 | lun->lun_se_dev = NULL; |
| 651 | } |
| 652 | |
| 653 | int transport_core_report_lun_response(struct se_cmd *se_cmd) |
| 654 | { |
| 655 | struct se_dev_entry *deve; |
| 656 | struct se_lun *se_lun; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 657 | struct se_session *se_sess = se_cmd->se_sess; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 658 | struct se_task *se_task; |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 659 | unsigned char *buf = se_cmd->t_task_buf; |
Nicholas Bellinger | 1078da1 | 2011-05-19 20:19:13 -0700 | [diff] [blame] | 660 | u32 cdb_offset = 0, lun_count = 0, offset = 8, i; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 661 | |
Andy Grover | a1d8b49 | 2011-05-02 17:12:10 -0700 | [diff] [blame] | 662 | list_for_each_entry(se_task, &se_cmd->t_task_list, t_list) |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 663 | break; |
| 664 | |
| 665 | if (!(se_task)) { |
| 666 | printk(KERN_ERR "Unable to locate struct se_task for struct se_cmd\n"); |
| 667 | return PYX_TRANSPORT_LU_COMM_FAILURE; |
| 668 | } |
| 669 | |
| 670 | /* |
| 671 | * If no struct se_session pointer is present, this struct se_cmd is |
| 672 | * coming via a target_core_mod PASSTHROUGH op, and not through |
| 673 | * a $FABRIC_MOD. In that case, report LUN=0 only. |
| 674 | */ |
| 675 | if (!(se_sess)) { |
Nicholas Bellinger | 1078da1 | 2011-05-19 20:19:13 -0700 | [diff] [blame] | 676 | int_to_scsilun(0, (struct scsi_lun *)&buf[offset]); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 677 | lun_count = 1; |
| 678 | goto done; |
| 679 | } |
| 680 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 681 | spin_lock_irq(&se_sess->se_node_acl->device_list_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 682 | for (i = 0; i < TRANSPORT_MAX_LUNS_PER_TPG; i++) { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 683 | deve = &se_sess->se_node_acl->device_list[i]; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 684 | if (!(deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS)) |
| 685 | continue; |
| 686 | se_lun = deve->se_lun; |
| 687 | /* |
| 688 | * We determine the correct LUN LIST LENGTH even once we |
| 689 | * have reached the initial allocation length. |
| 690 | * See SPC2-R20 7.19. |
| 691 | */ |
| 692 | lun_count++; |
| 693 | if ((cdb_offset + 8) >= se_cmd->data_length) |
| 694 | continue; |
| 695 | |
Nicholas Bellinger | 1078da1 | 2011-05-19 20:19:13 -0700 | [diff] [blame] | 696 | int_to_scsilun(deve->mapped_lun, (struct scsi_lun *)&buf[offset]); |
| 697 | offset += 8; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 698 | cdb_offset += 8; |
| 699 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 700 | spin_unlock_irq(&se_sess->se_node_acl->device_list_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 701 | |
| 702 | /* |
| 703 | * See SPC3 r07, page 159. |
| 704 | */ |
| 705 | done: |
| 706 | lun_count *= 8; |
| 707 | buf[0] = ((lun_count >> 24) & 0xff); |
| 708 | buf[1] = ((lun_count >> 16) & 0xff); |
| 709 | buf[2] = ((lun_count >> 8) & 0xff); |
| 710 | buf[3] = (lun_count & 0xff); |
| 711 | |
| 712 | return PYX_TRANSPORT_SENT_TO_TRANSPORT; |
| 713 | } |
| 714 | |
| 715 | /* se_release_device_for_hba(): |
| 716 | * |
| 717 | * |
| 718 | */ |
| 719 | void se_release_device_for_hba(struct se_device *dev) |
| 720 | { |
| 721 | struct se_hba *hba = dev->se_hba; |
| 722 | |
| 723 | if ((dev->dev_status & TRANSPORT_DEVICE_ACTIVATED) || |
| 724 | (dev->dev_status & TRANSPORT_DEVICE_DEACTIVATED) || |
| 725 | (dev->dev_status & TRANSPORT_DEVICE_SHUTDOWN) || |
| 726 | (dev->dev_status & TRANSPORT_DEVICE_OFFLINE_ACTIVATED) || |
| 727 | (dev->dev_status & TRANSPORT_DEVICE_OFFLINE_DEACTIVATED)) |
| 728 | se_dev_stop(dev); |
| 729 | |
| 730 | if (dev->dev_ptr) { |
| 731 | kthread_stop(dev->process_thread); |
| 732 | if (dev->transport->free_device) |
| 733 | dev->transport->free_device(dev->dev_ptr); |
| 734 | } |
| 735 | |
| 736 | spin_lock(&hba->device_lock); |
| 737 | list_del(&dev->dev_list); |
| 738 | hba->dev_count--; |
| 739 | spin_unlock(&hba->device_lock); |
| 740 | |
| 741 | core_scsi3_free_all_registrations(dev); |
| 742 | se_release_vpd_for_dev(dev); |
| 743 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 744 | kfree(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 745 | } |
| 746 | |
| 747 | void se_release_vpd_for_dev(struct se_device *dev) |
| 748 | { |
| 749 | struct t10_vpd *vpd, *vpd_tmp; |
| 750 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 751 | spin_lock(&dev->se_sub_dev->t10_wwn.t10_vpd_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 752 | list_for_each_entry_safe(vpd, vpd_tmp, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 753 | &dev->se_sub_dev->t10_wwn.t10_vpd_list, vpd_list) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 754 | list_del(&vpd->vpd_list); |
| 755 | kfree(vpd); |
| 756 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 757 | spin_unlock(&dev->se_sub_dev->t10_wwn.t10_vpd_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 758 | } |
| 759 | |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 760 | /* se_free_virtual_device(): |
| 761 | * |
| 762 | * Used for IBLOCK, RAMDISK, and FILEIO Transport Drivers. |
| 763 | */ |
| 764 | int se_free_virtual_device(struct se_device *dev, struct se_hba *hba) |
| 765 | { |
Fubo Chen | 05aea6e | 2011-03-14 04:06:00 -0700 | [diff] [blame] | 766 | if (!list_empty(&dev->dev_sep_list)) |
| 767 | dump_stack(); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 768 | |
| 769 | core_alua_free_lu_gp_mem(dev); |
| 770 | se_release_device_for_hba(dev); |
| 771 | |
| 772 | return 0; |
| 773 | } |
| 774 | |
| 775 | static void se_dev_start(struct se_device *dev) |
| 776 | { |
| 777 | struct se_hba *hba = dev->se_hba; |
| 778 | |
| 779 | spin_lock(&hba->device_lock); |
| 780 | atomic_inc(&dev->dev_obj.obj_access_count); |
| 781 | if (atomic_read(&dev->dev_obj.obj_access_count) == 1) { |
| 782 | if (dev->dev_status & TRANSPORT_DEVICE_DEACTIVATED) { |
| 783 | dev->dev_status &= ~TRANSPORT_DEVICE_DEACTIVATED; |
| 784 | dev->dev_status |= TRANSPORT_DEVICE_ACTIVATED; |
| 785 | } else if (dev->dev_status & |
| 786 | TRANSPORT_DEVICE_OFFLINE_DEACTIVATED) { |
| 787 | dev->dev_status &= |
| 788 | ~TRANSPORT_DEVICE_OFFLINE_DEACTIVATED; |
| 789 | dev->dev_status |= TRANSPORT_DEVICE_OFFLINE_ACTIVATED; |
| 790 | } |
| 791 | } |
| 792 | spin_unlock(&hba->device_lock); |
| 793 | } |
| 794 | |
| 795 | static void se_dev_stop(struct se_device *dev) |
| 796 | { |
| 797 | struct se_hba *hba = dev->se_hba; |
| 798 | |
| 799 | spin_lock(&hba->device_lock); |
| 800 | atomic_dec(&dev->dev_obj.obj_access_count); |
| 801 | if (atomic_read(&dev->dev_obj.obj_access_count) == 0) { |
| 802 | if (dev->dev_status & TRANSPORT_DEVICE_ACTIVATED) { |
| 803 | dev->dev_status &= ~TRANSPORT_DEVICE_ACTIVATED; |
| 804 | dev->dev_status |= TRANSPORT_DEVICE_DEACTIVATED; |
| 805 | } else if (dev->dev_status & |
| 806 | TRANSPORT_DEVICE_OFFLINE_ACTIVATED) { |
| 807 | dev->dev_status &= ~TRANSPORT_DEVICE_OFFLINE_ACTIVATED; |
| 808 | dev->dev_status |= TRANSPORT_DEVICE_OFFLINE_DEACTIVATED; |
| 809 | } |
| 810 | } |
| 811 | spin_unlock(&hba->device_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | int se_dev_check_online(struct se_device *dev) |
| 815 | { |
Roland Dreier | 56e34ee | 2011-06-13 20:55:06 -0700 | [diff] [blame^] | 816 | unsigned long flags; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 817 | int ret; |
| 818 | |
Roland Dreier | 56e34ee | 2011-06-13 20:55:06 -0700 | [diff] [blame^] | 819 | spin_lock_irqsave(&dev->dev_status_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 820 | ret = ((dev->dev_status & TRANSPORT_DEVICE_ACTIVATED) || |
| 821 | (dev->dev_status & TRANSPORT_DEVICE_DEACTIVATED)) ? 0 : 1; |
Roland Dreier | 56e34ee | 2011-06-13 20:55:06 -0700 | [diff] [blame^] | 822 | spin_unlock_irqrestore(&dev->dev_status_lock, flags); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 823 | |
| 824 | return ret; |
| 825 | } |
| 826 | |
| 827 | int se_dev_check_shutdown(struct se_device *dev) |
| 828 | { |
| 829 | int ret; |
| 830 | |
| 831 | spin_lock_irq(&dev->dev_status_lock); |
| 832 | ret = (dev->dev_status & TRANSPORT_DEVICE_SHUTDOWN); |
| 833 | spin_unlock_irq(&dev->dev_status_lock); |
| 834 | |
| 835 | return ret; |
| 836 | } |
| 837 | |
| 838 | void se_dev_set_default_attribs( |
| 839 | struct se_device *dev, |
| 840 | struct se_dev_limits *dev_limits) |
| 841 | { |
| 842 | struct queue_limits *limits = &dev_limits->limits; |
| 843 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 844 | dev->se_sub_dev->se_dev_attrib.emulate_dpo = DA_EMULATE_DPO; |
| 845 | dev->se_sub_dev->se_dev_attrib.emulate_fua_write = DA_EMULATE_FUA_WRITE; |
| 846 | dev->se_sub_dev->se_dev_attrib.emulate_fua_read = DA_EMULATE_FUA_READ; |
| 847 | dev->se_sub_dev->se_dev_attrib.emulate_write_cache = DA_EMULATE_WRITE_CACHE; |
| 848 | dev->se_sub_dev->se_dev_attrib.emulate_ua_intlck_ctrl = DA_EMULATE_UA_INTLLCK_CTRL; |
| 849 | dev->se_sub_dev->se_dev_attrib.emulate_tas = DA_EMULATE_TAS; |
| 850 | dev->se_sub_dev->se_dev_attrib.emulate_tpu = DA_EMULATE_TPU; |
| 851 | dev->se_sub_dev->se_dev_attrib.emulate_tpws = DA_EMULATE_TPWS; |
| 852 | dev->se_sub_dev->se_dev_attrib.emulate_reservations = DA_EMULATE_RESERVATIONS; |
| 853 | dev->se_sub_dev->se_dev_attrib.emulate_alua = DA_EMULATE_ALUA; |
| 854 | dev->se_sub_dev->se_dev_attrib.enforce_pr_isids = DA_ENFORCE_PR_ISIDS; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 855 | /* |
| 856 | * The TPU=1 and TPWS=1 settings will be set in TCM/IBLOCK |
| 857 | * iblock_create_virtdevice() from struct queue_limits values |
| 858 | * if blk_queue_discard()==1 |
| 859 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 860 | dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count = DA_MAX_UNMAP_LBA_COUNT; |
| 861 | dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count = |
| 862 | DA_MAX_UNMAP_BLOCK_DESC_COUNT; |
| 863 | dev->se_sub_dev->se_dev_attrib.unmap_granularity = DA_UNMAP_GRANULARITY_DEFAULT; |
| 864 | dev->se_sub_dev->se_dev_attrib.unmap_granularity_alignment = |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 865 | DA_UNMAP_GRANULARITY_ALIGNMENT_DEFAULT; |
| 866 | /* |
| 867 | * block_size is based on subsystem plugin dependent requirements. |
| 868 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 869 | dev->se_sub_dev->se_dev_attrib.hw_block_size = limits->logical_block_size; |
| 870 | dev->se_sub_dev->se_dev_attrib.block_size = limits->logical_block_size; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 871 | /* |
| 872 | * max_sectors is based on subsystem plugin dependent requirements. |
| 873 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 874 | dev->se_sub_dev->se_dev_attrib.hw_max_sectors = limits->max_hw_sectors; |
| 875 | dev->se_sub_dev->se_dev_attrib.max_sectors = limits->max_sectors; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 876 | /* |
| 877 | * Set optimal_sectors from max_sectors, which can be lowered via |
| 878 | * configfs. |
| 879 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 880 | dev->se_sub_dev->se_dev_attrib.optimal_sectors = limits->max_sectors; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 881 | /* |
| 882 | * queue_depth is based on subsystem plugin dependent requirements. |
| 883 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 884 | dev->se_sub_dev->se_dev_attrib.hw_queue_depth = dev_limits->hw_queue_depth; |
| 885 | dev->se_sub_dev->se_dev_attrib.queue_depth = dev_limits->queue_depth; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | int se_dev_set_task_timeout(struct se_device *dev, u32 task_timeout) |
| 889 | { |
| 890 | if (task_timeout > DA_TASK_TIMEOUT_MAX) { |
| 891 | printk(KERN_ERR "dev[%p]: Passed task_timeout: %u larger then" |
| 892 | " DA_TASK_TIMEOUT_MAX\n", dev, task_timeout); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 893 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 894 | } else { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 895 | dev->se_sub_dev->se_dev_attrib.task_timeout = task_timeout; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 896 | printk(KERN_INFO "dev[%p]: Set SE Device task_timeout: %u\n", |
| 897 | dev, task_timeout); |
| 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
| 903 | int se_dev_set_max_unmap_lba_count( |
| 904 | struct se_device *dev, |
| 905 | u32 max_unmap_lba_count) |
| 906 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 907 | dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count = max_unmap_lba_count; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 908 | printk(KERN_INFO "dev[%p]: Set max_unmap_lba_count: %u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 909 | dev, dev->se_sub_dev->se_dev_attrib.max_unmap_lba_count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 910 | return 0; |
| 911 | } |
| 912 | |
| 913 | int se_dev_set_max_unmap_block_desc_count( |
| 914 | struct se_device *dev, |
| 915 | u32 max_unmap_block_desc_count) |
| 916 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 917 | dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count = |
| 918 | max_unmap_block_desc_count; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 919 | printk(KERN_INFO "dev[%p]: Set max_unmap_block_desc_count: %u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 920 | dev, dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | int se_dev_set_unmap_granularity( |
| 925 | struct se_device *dev, |
| 926 | u32 unmap_granularity) |
| 927 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 928 | dev->se_sub_dev->se_dev_attrib.unmap_granularity = unmap_granularity; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 929 | printk(KERN_INFO "dev[%p]: Set unmap_granularity: %u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 930 | dev, dev->se_sub_dev->se_dev_attrib.unmap_granularity); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 931 | return 0; |
| 932 | } |
| 933 | |
| 934 | int se_dev_set_unmap_granularity_alignment( |
| 935 | struct se_device *dev, |
| 936 | u32 unmap_granularity_alignment) |
| 937 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 938 | dev->se_sub_dev->se_dev_attrib.unmap_granularity_alignment = unmap_granularity_alignment; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 939 | printk(KERN_INFO "dev[%p]: Set unmap_granularity_alignment: %u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 940 | dev, dev->se_sub_dev->se_dev_attrib.unmap_granularity_alignment); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 941 | return 0; |
| 942 | } |
| 943 | |
| 944 | int se_dev_set_emulate_dpo(struct se_device *dev, int flag) |
| 945 | { |
| 946 | if ((flag != 0) && (flag != 1)) { |
| 947 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 948 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 949 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 950 | if (dev->transport->dpo_emulated == NULL) { |
| 951 | printk(KERN_ERR "dev->transport->dpo_emulated is NULL\n"); |
| 952 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 953 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 954 | if (dev->transport->dpo_emulated(dev) == 0) { |
| 955 | printk(KERN_ERR "dev->transport->dpo_emulated not supported\n"); |
| 956 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 957 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 958 | dev->se_sub_dev->se_dev_attrib.emulate_dpo = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 959 | printk(KERN_INFO "dev[%p]: SE Device Page Out (DPO) Emulation" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 960 | " bit: %d\n", dev, dev->se_sub_dev->se_dev_attrib.emulate_dpo); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | int se_dev_set_emulate_fua_write(struct se_device *dev, int flag) |
| 965 | { |
| 966 | if ((flag != 0) && (flag != 1)) { |
| 967 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 968 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 969 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 970 | if (dev->transport->fua_write_emulated == NULL) { |
| 971 | printk(KERN_ERR "dev->transport->fua_write_emulated is NULL\n"); |
| 972 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 973 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 974 | if (dev->transport->fua_write_emulated(dev) == 0) { |
| 975 | printk(KERN_ERR "dev->transport->fua_write_emulated not supported\n"); |
| 976 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 977 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 978 | dev->se_sub_dev->se_dev_attrib.emulate_fua_write = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 979 | printk(KERN_INFO "dev[%p]: SE Device Forced Unit Access WRITEs: %d\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 980 | dev, dev->se_sub_dev->se_dev_attrib.emulate_fua_write); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 981 | return 0; |
| 982 | } |
| 983 | |
| 984 | int se_dev_set_emulate_fua_read(struct se_device *dev, int flag) |
| 985 | { |
| 986 | if ((flag != 0) && (flag != 1)) { |
| 987 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 988 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 989 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 990 | if (dev->transport->fua_read_emulated == NULL) { |
| 991 | printk(KERN_ERR "dev->transport->fua_read_emulated is NULL\n"); |
| 992 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 993 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 994 | if (dev->transport->fua_read_emulated(dev) == 0) { |
| 995 | printk(KERN_ERR "dev->transport->fua_read_emulated not supported\n"); |
| 996 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 997 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 998 | dev->se_sub_dev->se_dev_attrib.emulate_fua_read = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 999 | printk(KERN_INFO "dev[%p]: SE Device Forced Unit Access READs: %d\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1000 | dev, dev->se_sub_dev->se_dev_attrib.emulate_fua_read); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1001 | return 0; |
| 1002 | } |
| 1003 | |
| 1004 | int se_dev_set_emulate_write_cache(struct se_device *dev, int flag) |
| 1005 | { |
| 1006 | if ((flag != 0) && (flag != 1)) { |
| 1007 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1008 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1009 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1010 | if (dev->transport->write_cache_emulated == NULL) { |
| 1011 | printk(KERN_ERR "dev->transport->write_cache_emulated is NULL\n"); |
| 1012 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1013 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1014 | if (dev->transport->write_cache_emulated(dev) == 0) { |
| 1015 | printk(KERN_ERR "dev->transport->write_cache_emulated not supported\n"); |
| 1016 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1017 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1018 | dev->se_sub_dev->se_dev_attrib.emulate_write_cache = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1019 | printk(KERN_INFO "dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1020 | dev, dev->se_sub_dev->se_dev_attrib.emulate_write_cache); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
| 1023 | |
| 1024 | int se_dev_set_emulate_ua_intlck_ctrl(struct se_device *dev, int flag) |
| 1025 | { |
| 1026 | if ((flag != 0) && (flag != 1) && (flag != 2)) { |
| 1027 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1028 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1029 | } |
| 1030 | |
| 1031 | if (atomic_read(&dev->dev_export_obj.obj_access_count)) { |
| 1032 | printk(KERN_ERR "dev[%p]: Unable to change SE Device" |
| 1033 | " UA_INTRLCK_CTRL while dev_export_obj: %d count" |
| 1034 | " exists\n", dev, |
| 1035 | atomic_read(&dev->dev_export_obj.obj_access_count)); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1036 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1037 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1038 | dev->se_sub_dev->se_dev_attrib.emulate_ua_intlck_ctrl = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1039 | printk(KERN_INFO "dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1040 | dev, dev->se_sub_dev->se_dev_attrib.emulate_ua_intlck_ctrl); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1041 | |
| 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | int se_dev_set_emulate_tas(struct se_device *dev, int flag) |
| 1046 | { |
| 1047 | if ((flag != 0) && (flag != 1)) { |
| 1048 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1049 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1050 | } |
| 1051 | |
| 1052 | if (atomic_read(&dev->dev_export_obj.obj_access_count)) { |
| 1053 | printk(KERN_ERR "dev[%p]: Unable to change SE Device TAS while" |
| 1054 | " dev_export_obj: %d count exists\n", dev, |
| 1055 | atomic_read(&dev->dev_export_obj.obj_access_count)); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1056 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1057 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1058 | dev->se_sub_dev->se_dev_attrib.emulate_tas = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1059 | printk(KERN_INFO "dev[%p]: SE Device TASK_ABORTED status bit: %s\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1060 | dev, (dev->se_sub_dev->se_dev_attrib.emulate_tas) ? "Enabled" : "Disabled"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | int se_dev_set_emulate_tpu(struct se_device *dev, int flag) |
| 1066 | { |
| 1067 | if ((flag != 0) && (flag != 1)) { |
| 1068 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1069 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1070 | } |
| 1071 | /* |
| 1072 | * We expect this value to be non-zero when generic Block Layer |
| 1073 | * Discard supported is detected iblock_create_virtdevice(). |
| 1074 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1075 | if (!(dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1076 | printk(KERN_ERR "Generic Block Discard not supported\n"); |
| 1077 | return -ENOSYS; |
| 1078 | } |
| 1079 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1080 | dev->se_sub_dev->se_dev_attrib.emulate_tpu = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1081 | printk(KERN_INFO "dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n", |
| 1082 | dev, flag); |
| 1083 | return 0; |
| 1084 | } |
| 1085 | |
| 1086 | int se_dev_set_emulate_tpws(struct se_device *dev, int flag) |
| 1087 | { |
| 1088 | if ((flag != 0) && (flag != 1)) { |
| 1089 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1090 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1091 | } |
| 1092 | /* |
| 1093 | * We expect this value to be non-zero when generic Block Layer |
| 1094 | * Discard supported is detected iblock_create_virtdevice(). |
| 1095 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1096 | if (!(dev->se_sub_dev->se_dev_attrib.max_unmap_block_desc_count)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1097 | printk(KERN_ERR "Generic Block Discard not supported\n"); |
| 1098 | return -ENOSYS; |
| 1099 | } |
| 1100 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1101 | dev->se_sub_dev->se_dev_attrib.emulate_tpws = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1102 | printk(KERN_INFO "dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n", |
| 1103 | dev, flag); |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | int se_dev_set_enforce_pr_isids(struct se_device *dev, int flag) |
| 1108 | { |
| 1109 | if ((flag != 0) && (flag != 1)) { |
| 1110 | printk(KERN_ERR "Illegal value %d\n", flag); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1111 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1112 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1113 | dev->se_sub_dev->se_dev_attrib.enforce_pr_isids = flag; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1114 | printk(KERN_INFO "dev[%p]: SE Device enforce_pr_isids bit: %s\n", dev, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1115 | (dev->se_sub_dev->se_dev_attrib.enforce_pr_isids) ? "Enabled" : "Disabled"); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1116 | return 0; |
| 1117 | } |
| 1118 | |
| 1119 | /* |
| 1120 | * Note, this can only be called on unexported SE Device Object. |
| 1121 | */ |
| 1122 | int se_dev_set_queue_depth(struct se_device *dev, u32 queue_depth) |
| 1123 | { |
| 1124 | u32 orig_queue_depth = dev->queue_depth; |
| 1125 | |
| 1126 | if (atomic_read(&dev->dev_export_obj.obj_access_count)) { |
| 1127 | printk(KERN_ERR "dev[%p]: Unable to change SE Device TCQ while" |
| 1128 | " dev_export_obj: %d count exists\n", dev, |
| 1129 | atomic_read(&dev->dev_export_obj.obj_access_count)); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1130 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1131 | } |
| 1132 | if (!(queue_depth)) { |
| 1133 | printk(KERN_ERR "dev[%p]: Illegal ZERO value for queue" |
| 1134 | "_depth\n", dev); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1135 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1136 | } |
| 1137 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1138 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { |
| 1139 | if (queue_depth > dev->se_sub_dev->se_dev_attrib.hw_queue_depth) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1140 | printk(KERN_ERR "dev[%p]: Passed queue_depth: %u" |
| 1141 | " exceeds TCM/SE_Device TCQ: %u\n", |
| 1142 | dev, queue_depth, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1143 | dev->se_sub_dev->se_dev_attrib.hw_queue_depth); |
| 1144 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1145 | } |
| 1146 | } else { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1147 | if (queue_depth > dev->se_sub_dev->se_dev_attrib.queue_depth) { |
| 1148 | if (queue_depth > dev->se_sub_dev->se_dev_attrib.hw_queue_depth) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1149 | printk(KERN_ERR "dev[%p]: Passed queue_depth:" |
| 1150 | " %u exceeds TCM/SE_Device MAX" |
| 1151 | " TCQ: %u\n", dev, queue_depth, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1152 | dev->se_sub_dev->se_dev_attrib.hw_queue_depth); |
| 1153 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1154 | } |
| 1155 | } |
| 1156 | } |
| 1157 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1158 | dev->se_sub_dev->se_dev_attrib.queue_depth = dev->queue_depth = queue_depth; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1159 | if (queue_depth > orig_queue_depth) |
| 1160 | atomic_add(queue_depth - orig_queue_depth, &dev->depth_left); |
| 1161 | else if (queue_depth < orig_queue_depth) |
| 1162 | atomic_sub(orig_queue_depth - queue_depth, &dev->depth_left); |
| 1163 | |
| 1164 | printk(KERN_INFO "dev[%p]: SE Device TCQ Depth changed to: %u\n", |
| 1165 | dev, queue_depth); |
| 1166 | return 0; |
| 1167 | } |
| 1168 | |
| 1169 | int se_dev_set_max_sectors(struct se_device *dev, u32 max_sectors) |
| 1170 | { |
| 1171 | int force = 0; /* Force setting for VDEVS */ |
| 1172 | |
| 1173 | if (atomic_read(&dev->dev_export_obj.obj_access_count)) { |
| 1174 | printk(KERN_ERR "dev[%p]: Unable to change SE Device" |
| 1175 | " max_sectors while dev_export_obj: %d count exists\n", |
| 1176 | dev, atomic_read(&dev->dev_export_obj.obj_access_count)); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1177 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1178 | } |
| 1179 | if (!(max_sectors)) { |
| 1180 | printk(KERN_ERR "dev[%p]: Illegal ZERO value for" |
| 1181 | " max_sectors\n", dev); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1182 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1183 | } |
| 1184 | if (max_sectors < DA_STATUS_MAX_SECTORS_MIN) { |
| 1185 | printk(KERN_ERR "dev[%p]: Passed max_sectors: %u less than" |
| 1186 | " DA_STATUS_MAX_SECTORS_MIN: %u\n", dev, max_sectors, |
| 1187 | DA_STATUS_MAX_SECTORS_MIN); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1188 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1189 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1190 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { |
| 1191 | if (max_sectors > dev->se_sub_dev->se_dev_attrib.hw_max_sectors) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1192 | printk(KERN_ERR "dev[%p]: Passed max_sectors: %u" |
| 1193 | " greater than TCM/SE_Device max_sectors:" |
| 1194 | " %u\n", dev, max_sectors, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1195 | dev->se_sub_dev->se_dev_attrib.hw_max_sectors); |
| 1196 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1197 | } |
| 1198 | } else { |
| 1199 | if (!(force) && (max_sectors > |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1200 | dev->se_sub_dev->se_dev_attrib.hw_max_sectors)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1201 | printk(KERN_ERR "dev[%p]: Passed max_sectors: %u" |
| 1202 | " greater than TCM/SE_Device max_sectors" |
| 1203 | ": %u, use force=1 to override.\n", dev, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1204 | max_sectors, dev->se_sub_dev->se_dev_attrib.hw_max_sectors); |
| 1205 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1206 | } |
| 1207 | if (max_sectors > DA_STATUS_MAX_SECTORS_MAX) { |
| 1208 | printk(KERN_ERR "dev[%p]: Passed max_sectors: %u" |
| 1209 | " greater than DA_STATUS_MAX_SECTORS_MAX:" |
| 1210 | " %u\n", dev, max_sectors, |
| 1211 | DA_STATUS_MAX_SECTORS_MAX); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1212 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1213 | } |
| 1214 | } |
| 1215 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1216 | dev->se_sub_dev->se_dev_attrib.max_sectors = max_sectors; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1217 | printk("dev[%p]: SE Device max_sectors changed to %u\n", |
| 1218 | dev, max_sectors); |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | int se_dev_set_optimal_sectors(struct se_device *dev, u32 optimal_sectors) |
| 1223 | { |
| 1224 | if (atomic_read(&dev->dev_export_obj.obj_access_count)) { |
| 1225 | printk(KERN_ERR "dev[%p]: Unable to change SE Device" |
| 1226 | " optimal_sectors while dev_export_obj: %d count exists\n", |
| 1227 | dev, atomic_read(&dev->dev_export_obj.obj_access_count)); |
| 1228 | return -EINVAL; |
| 1229 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1230 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1231 | printk(KERN_ERR "dev[%p]: Passed optimal_sectors cannot be" |
| 1232 | " changed for TCM/pSCSI\n", dev); |
| 1233 | return -EINVAL; |
| 1234 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1235 | if (optimal_sectors > dev->se_sub_dev->se_dev_attrib.max_sectors) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1236 | printk(KERN_ERR "dev[%p]: Passed optimal_sectors %u cannot be" |
| 1237 | " greater than max_sectors: %u\n", dev, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1238 | optimal_sectors, dev->se_sub_dev->se_dev_attrib.max_sectors); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1239 | return -EINVAL; |
| 1240 | } |
| 1241 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1242 | dev->se_sub_dev->se_dev_attrib.optimal_sectors = optimal_sectors; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1243 | printk(KERN_INFO "dev[%p]: SE Device optimal_sectors changed to %u\n", |
| 1244 | dev, optimal_sectors); |
| 1245 | return 0; |
| 1246 | } |
| 1247 | |
| 1248 | int se_dev_set_block_size(struct se_device *dev, u32 block_size) |
| 1249 | { |
| 1250 | if (atomic_read(&dev->dev_export_obj.obj_access_count)) { |
| 1251 | printk(KERN_ERR "dev[%p]: Unable to change SE Device block_size" |
| 1252 | " while dev_export_obj: %d count exists\n", dev, |
| 1253 | atomic_read(&dev->dev_export_obj.obj_access_count)); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1254 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1255 | } |
| 1256 | |
| 1257 | if ((block_size != 512) && |
| 1258 | (block_size != 1024) && |
| 1259 | (block_size != 2048) && |
| 1260 | (block_size != 4096)) { |
| 1261 | printk(KERN_ERR "dev[%p]: Illegal value for block_device: %u" |
| 1262 | " for SE device, must be 512, 1024, 2048 or 4096\n", |
| 1263 | dev, block_size); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1264 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1265 | } |
| 1266 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1267 | if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1268 | printk(KERN_ERR "dev[%p]: Not allowed to change block_size for" |
| 1269 | " Physical Device, use for Linux/SCSI to change" |
| 1270 | " block_size for underlying hardware\n", dev); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1271 | return -EINVAL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1274 | dev->se_sub_dev->se_dev_attrib.block_size = block_size; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1275 | printk(KERN_INFO "dev[%p]: SE Device block_size changed to %u\n", |
| 1276 | dev, block_size); |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | struct se_lun *core_dev_add_lun( |
| 1281 | struct se_portal_group *tpg, |
| 1282 | struct se_hba *hba, |
| 1283 | struct se_device *dev, |
| 1284 | u32 lun) |
| 1285 | { |
| 1286 | struct se_lun *lun_p; |
| 1287 | u32 lun_access = 0; |
| 1288 | |
| 1289 | if (atomic_read(&dev->dev_access_obj.obj_access_count) != 0) { |
| 1290 | printk(KERN_ERR "Unable to export struct se_device while dev_access_obj: %d\n", |
| 1291 | atomic_read(&dev->dev_access_obj.obj_access_count)); |
| 1292 | return NULL; |
| 1293 | } |
| 1294 | |
| 1295 | lun_p = core_tpg_pre_addlun(tpg, lun); |
| 1296 | if ((IS_ERR(lun_p)) || !(lun_p)) |
| 1297 | return NULL; |
| 1298 | |
| 1299 | if (dev->dev_flags & DF_READ_ONLY) |
| 1300 | lun_access = TRANSPORT_LUNFLAGS_READ_ONLY; |
| 1301 | else |
| 1302 | lun_access = TRANSPORT_LUNFLAGS_READ_WRITE; |
| 1303 | |
| 1304 | if (core_tpg_post_addlun(tpg, lun_p, lun_access, dev) < 0) |
| 1305 | return NULL; |
| 1306 | |
| 1307 | printk(KERN_INFO "%s_TPG[%u]_LUN[%u] - Activated %s Logical Unit from" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1308 | " CORE HBA: %u\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 1309 | tpg->se_tpg_tfo->tpg_get_tag(tpg), lun_p->unpacked_lun, |
| 1310 | tpg->se_tpg_tfo->get_fabric_name(), hba->hba_id); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1311 | /* |
| 1312 | * Update LUN maps for dynamically added initiators when |
| 1313 | * generate_node_acl is enabled. |
| 1314 | */ |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1315 | if (tpg->se_tpg_tfo->tpg_check_demo_mode(tpg)) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1316 | struct se_node_acl *acl; |
| 1317 | spin_lock_bh(&tpg->acl_node_lock); |
| 1318 | list_for_each_entry(acl, &tpg->acl_node_list, acl_list) { |
| 1319 | if (acl->dynamic_node_acl) { |
| 1320 | spin_unlock_bh(&tpg->acl_node_lock); |
| 1321 | core_tpg_add_node_to_devs(acl, tpg); |
| 1322 | spin_lock_bh(&tpg->acl_node_lock); |
| 1323 | } |
| 1324 | } |
| 1325 | spin_unlock_bh(&tpg->acl_node_lock); |
| 1326 | } |
| 1327 | |
| 1328 | return lun_p; |
| 1329 | } |
| 1330 | |
| 1331 | /* core_dev_del_lun(): |
| 1332 | * |
| 1333 | * |
| 1334 | */ |
| 1335 | int core_dev_del_lun( |
| 1336 | struct se_portal_group *tpg, |
| 1337 | u32 unpacked_lun) |
| 1338 | { |
| 1339 | struct se_lun *lun; |
| 1340 | int ret = 0; |
| 1341 | |
| 1342 | lun = core_tpg_pre_dellun(tpg, unpacked_lun, &ret); |
| 1343 | if (!(lun)) |
| 1344 | return ret; |
| 1345 | |
| 1346 | core_tpg_post_dellun(tpg, lun); |
| 1347 | |
| 1348 | printk(KERN_INFO "%s_TPG[%u]_LUN[%u] - Deactivated %s Logical Unit from" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1349 | " device object\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 1350 | tpg->se_tpg_tfo->tpg_get_tag(tpg), unpacked_lun, |
| 1351 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1352 | |
| 1353 | return 0; |
| 1354 | } |
| 1355 | |
| 1356 | struct se_lun *core_get_lun_from_tpg(struct se_portal_group *tpg, u32 unpacked_lun) |
| 1357 | { |
| 1358 | struct se_lun *lun; |
| 1359 | |
| 1360 | spin_lock(&tpg->tpg_lun_lock); |
| 1361 | if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { |
| 1362 | printk(KERN_ERR "%s LUN: %u exceeds TRANSPORT_MAX_LUNS" |
| 1363 | "_PER_TPG-1: %u for Target Portal Group: %hu\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1364 | tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1365 | TRANSPORT_MAX_LUNS_PER_TPG-1, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1366 | tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1367 | spin_unlock(&tpg->tpg_lun_lock); |
| 1368 | return NULL; |
| 1369 | } |
| 1370 | lun = &tpg->tpg_lun_list[unpacked_lun]; |
| 1371 | |
| 1372 | if (lun->lun_status != TRANSPORT_LUN_STATUS_FREE) { |
| 1373 | printk(KERN_ERR "%s Logical Unit Number: %u is not free on" |
| 1374 | " Target Portal Group: %hu, ignoring request.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1375 | tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, |
| 1376 | tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1377 | spin_unlock(&tpg->tpg_lun_lock); |
| 1378 | return NULL; |
| 1379 | } |
| 1380 | spin_unlock(&tpg->tpg_lun_lock); |
| 1381 | |
| 1382 | return lun; |
| 1383 | } |
| 1384 | |
| 1385 | /* core_dev_get_lun(): |
| 1386 | * |
| 1387 | * |
| 1388 | */ |
| 1389 | static struct se_lun *core_dev_get_lun(struct se_portal_group *tpg, u32 unpacked_lun) |
| 1390 | { |
| 1391 | struct se_lun *lun; |
| 1392 | |
| 1393 | spin_lock(&tpg->tpg_lun_lock); |
| 1394 | if (unpacked_lun > (TRANSPORT_MAX_LUNS_PER_TPG-1)) { |
| 1395 | printk(KERN_ERR "%s LUN: %u exceeds TRANSPORT_MAX_LUNS_PER" |
| 1396 | "_TPG-1: %u for Target Portal Group: %hu\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1397 | tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1398 | TRANSPORT_MAX_LUNS_PER_TPG-1, |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1399 | tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1400 | spin_unlock(&tpg->tpg_lun_lock); |
| 1401 | return NULL; |
| 1402 | } |
| 1403 | lun = &tpg->tpg_lun_list[unpacked_lun]; |
| 1404 | |
| 1405 | if (lun->lun_status != TRANSPORT_LUN_STATUS_ACTIVE) { |
| 1406 | printk(KERN_ERR "%s Logical Unit Number: %u is not active on" |
| 1407 | " Target Portal Group: %hu, ignoring request.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1408 | tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, |
| 1409 | tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1410 | spin_unlock(&tpg->tpg_lun_lock); |
| 1411 | return NULL; |
| 1412 | } |
| 1413 | spin_unlock(&tpg->tpg_lun_lock); |
| 1414 | |
| 1415 | return lun; |
| 1416 | } |
| 1417 | |
| 1418 | struct se_lun_acl *core_dev_init_initiator_node_lun_acl( |
| 1419 | struct se_portal_group *tpg, |
| 1420 | u32 mapped_lun, |
| 1421 | char *initiatorname, |
| 1422 | int *ret) |
| 1423 | { |
| 1424 | struct se_lun_acl *lacl; |
| 1425 | struct se_node_acl *nacl; |
| 1426 | |
Dan Carpenter | 60d645a | 2011-06-15 10:03:05 -0700 | [diff] [blame] | 1427 | if (strlen(initiatorname) >= TRANSPORT_IQN_LEN) { |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1428 | printk(KERN_ERR "%s InitiatorName exceeds maximum size.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1429 | tpg->se_tpg_tfo->get_fabric_name()); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1430 | *ret = -EOVERFLOW; |
| 1431 | return NULL; |
| 1432 | } |
| 1433 | nacl = core_tpg_get_initiator_node_acl(tpg, initiatorname); |
| 1434 | if (!(nacl)) { |
| 1435 | *ret = -EINVAL; |
| 1436 | return NULL; |
| 1437 | } |
| 1438 | lacl = kzalloc(sizeof(struct se_lun_acl), GFP_KERNEL); |
| 1439 | if (!(lacl)) { |
| 1440 | printk(KERN_ERR "Unable to allocate memory for struct se_lun_acl.\n"); |
| 1441 | *ret = -ENOMEM; |
| 1442 | return NULL; |
| 1443 | } |
| 1444 | |
| 1445 | INIT_LIST_HEAD(&lacl->lacl_list); |
| 1446 | lacl->mapped_lun = mapped_lun; |
| 1447 | lacl->se_lun_nacl = nacl; |
| 1448 | snprintf(lacl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname); |
| 1449 | |
| 1450 | return lacl; |
| 1451 | } |
| 1452 | |
| 1453 | int core_dev_add_initiator_node_lun_acl( |
| 1454 | struct se_portal_group *tpg, |
| 1455 | struct se_lun_acl *lacl, |
| 1456 | u32 unpacked_lun, |
| 1457 | u32 lun_access) |
| 1458 | { |
| 1459 | struct se_lun *lun; |
| 1460 | struct se_node_acl *nacl; |
| 1461 | |
| 1462 | lun = core_dev_get_lun(tpg, unpacked_lun); |
| 1463 | if (!(lun)) { |
| 1464 | printk(KERN_ERR "%s Logical Unit Number: %u is not active on" |
| 1465 | " Target Portal Group: %hu, ignoring request.\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1466 | tpg->se_tpg_tfo->get_fabric_name(), unpacked_lun, |
| 1467 | tpg->se_tpg_tfo->tpg_get_tag(tpg)); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1468 | return -EINVAL; |
| 1469 | } |
| 1470 | |
| 1471 | nacl = lacl->se_lun_nacl; |
| 1472 | if (!(nacl)) |
| 1473 | return -EINVAL; |
| 1474 | |
| 1475 | if ((lun->lun_access & TRANSPORT_LUNFLAGS_READ_ONLY) && |
| 1476 | (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE)) |
| 1477 | lun_access = TRANSPORT_LUNFLAGS_READ_ONLY; |
| 1478 | |
| 1479 | lacl->se_lun = lun; |
| 1480 | |
| 1481 | if (core_update_device_list_for_node(lun, lacl, lacl->mapped_lun, |
| 1482 | lun_access, nacl, tpg, 1) < 0) |
| 1483 | return -EINVAL; |
| 1484 | |
| 1485 | spin_lock(&lun->lun_acl_lock); |
| 1486 | list_add_tail(&lacl->lacl_list, &lun->lun_acl_list); |
| 1487 | atomic_inc(&lun->lun_acl_count); |
| 1488 | smp_mb__after_atomic_inc(); |
| 1489 | spin_unlock(&lun->lun_acl_lock); |
| 1490 | |
| 1491 | printk(KERN_INFO "%s_TPG[%hu]_LUN[%u->%u] - Added %s ACL for " |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1492 | " InitiatorNode: %s\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 1493 | tpg->se_tpg_tfo->tpg_get_tag(tpg), unpacked_lun, lacl->mapped_lun, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1494 | (lun_access & TRANSPORT_LUNFLAGS_READ_WRITE) ? "RW" : "RO", |
| 1495 | lacl->initiatorname); |
| 1496 | /* |
| 1497 | * Check to see if there are any existing persistent reservation APTPL |
| 1498 | * pre-registrations that need to be enabled for this LUN ACL.. |
| 1499 | */ |
| 1500 | core_scsi3_check_aptpl_registration(lun->lun_se_dev, tpg, lun, lacl); |
| 1501 | return 0; |
| 1502 | } |
| 1503 | |
| 1504 | /* core_dev_del_initiator_node_lun_acl(): |
| 1505 | * |
| 1506 | * |
| 1507 | */ |
| 1508 | int core_dev_del_initiator_node_lun_acl( |
| 1509 | struct se_portal_group *tpg, |
| 1510 | struct se_lun *lun, |
| 1511 | struct se_lun_acl *lacl) |
| 1512 | { |
| 1513 | struct se_node_acl *nacl; |
| 1514 | |
| 1515 | nacl = lacl->se_lun_nacl; |
| 1516 | if (!(nacl)) |
| 1517 | return -EINVAL; |
| 1518 | |
| 1519 | spin_lock(&lun->lun_acl_lock); |
| 1520 | list_del(&lacl->lacl_list); |
| 1521 | atomic_dec(&lun->lun_acl_count); |
| 1522 | smp_mb__after_atomic_dec(); |
| 1523 | spin_unlock(&lun->lun_acl_lock); |
| 1524 | |
| 1525 | core_update_device_list_for_node(lun, NULL, lacl->mapped_lun, |
| 1526 | TRANSPORT_LUNFLAGS_NO_ACCESS, nacl, tpg, 0); |
| 1527 | |
| 1528 | lacl->se_lun = NULL; |
| 1529 | |
| 1530 | printk(KERN_INFO "%s_TPG[%hu]_LUN[%u] - Removed ACL for" |
| 1531 | " InitiatorNode: %s Mapped LUN: %u\n", |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1532 | tpg->se_tpg_tfo->get_fabric_name(), |
| 1533 | tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun, |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1534 | lacl->initiatorname, lacl->mapped_lun); |
| 1535 | |
| 1536 | return 0; |
| 1537 | } |
| 1538 | |
| 1539 | void core_dev_free_initiator_node_lun_acl( |
| 1540 | struct se_portal_group *tpg, |
| 1541 | struct se_lun_acl *lacl) |
| 1542 | { |
| 1543 | printk("%s_TPG[%hu] - Freeing ACL for %s InitiatorNode: %s" |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1544 | " Mapped LUN: %u\n", tpg->se_tpg_tfo->get_fabric_name(), |
| 1545 | tpg->se_tpg_tfo->tpg_get_tag(tpg), |
| 1546 | tpg->se_tpg_tfo->get_fabric_name(), |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1547 | lacl->initiatorname, lacl->mapped_lun); |
| 1548 | |
| 1549 | kfree(lacl); |
| 1550 | } |
| 1551 | |
| 1552 | int core_dev_setup_virtual_lun0(void) |
| 1553 | { |
| 1554 | struct se_hba *hba; |
| 1555 | struct se_device *dev; |
| 1556 | struct se_subsystem_dev *se_dev = NULL; |
| 1557 | struct se_subsystem_api *t; |
| 1558 | char buf[16]; |
| 1559 | int ret; |
| 1560 | |
| 1561 | hba = core_alloc_hba("rd_dr", 0, HBA_FLAGS_INTERNAL_USE); |
| 1562 | if (IS_ERR(hba)) |
| 1563 | return PTR_ERR(hba); |
| 1564 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1565 | lun0_hba = hba; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1566 | t = hba->transport; |
| 1567 | |
| 1568 | se_dev = kzalloc(sizeof(struct se_subsystem_dev), GFP_KERNEL); |
| 1569 | if (!(se_dev)) { |
| 1570 | printk(KERN_ERR "Unable to allocate memory for" |
| 1571 | " struct se_subsystem_dev\n"); |
| 1572 | ret = -ENOMEM; |
| 1573 | goto out; |
| 1574 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1575 | INIT_LIST_HEAD(&se_dev->se_dev_node); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1576 | INIT_LIST_HEAD(&se_dev->t10_wwn.t10_vpd_list); |
| 1577 | spin_lock_init(&se_dev->t10_wwn.t10_vpd_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1578 | INIT_LIST_HEAD(&se_dev->t10_pr.registration_list); |
| 1579 | INIT_LIST_HEAD(&se_dev->t10_pr.aptpl_reg_list); |
| 1580 | spin_lock_init(&se_dev->t10_pr.registration_lock); |
| 1581 | spin_lock_init(&se_dev->t10_pr.aptpl_reg_lock); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1582 | INIT_LIST_HEAD(&se_dev->t10_alua.tg_pt_gps_list); |
| 1583 | spin_lock_init(&se_dev->t10_alua.tg_pt_gps_lock); |
| 1584 | spin_lock_init(&se_dev->se_dev_lock); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1585 | se_dev->t10_pr.pr_aptpl_buf_len = PR_APTPL_BUF_LEN; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1586 | se_dev->t10_wwn.t10_sub_dev = se_dev; |
| 1587 | se_dev->t10_alua.t10_sub_dev = se_dev; |
| 1588 | se_dev->se_dev_attrib.da_sub_dev = se_dev; |
| 1589 | se_dev->se_dev_hba = hba; |
| 1590 | |
| 1591 | se_dev->se_dev_su_ptr = t->allocate_virtdevice(hba, "virt_lun0"); |
| 1592 | if (!(se_dev->se_dev_su_ptr)) { |
| 1593 | printk(KERN_ERR "Unable to locate subsystem dependent pointer" |
| 1594 | " from allocate_virtdevice()\n"); |
| 1595 | ret = -ENOMEM; |
| 1596 | goto out; |
| 1597 | } |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1598 | lun0_su_dev = se_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1599 | |
| 1600 | memset(buf, 0, 16); |
| 1601 | sprintf(buf, "rd_pages=8"); |
| 1602 | t->set_configfs_dev_params(hba, se_dev, buf, sizeof(buf)); |
| 1603 | |
| 1604 | dev = t->create_virtdevice(hba, se_dev, se_dev->se_dev_su_ptr); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1605 | if (IS_ERR(dev)) { |
| 1606 | ret = PTR_ERR(dev); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1607 | goto out; |
| 1608 | } |
| 1609 | se_dev->se_dev_ptr = dev; |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1610 | g_lun0_dev = dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1611 | |
| 1612 | return 0; |
| 1613 | out: |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1614 | lun0_su_dev = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1615 | kfree(se_dev); |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1616 | if (lun0_hba) { |
| 1617 | core_delete_hba(lun0_hba); |
| 1618 | lun0_hba = NULL; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1619 | } |
| 1620 | return ret; |
| 1621 | } |
| 1622 | |
| 1623 | |
| 1624 | void core_dev_release_virtual_lun0(void) |
| 1625 | { |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1626 | struct se_hba *hba = lun0_hba; |
| 1627 | struct se_subsystem_dev *su_dev = lun0_su_dev; |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1628 | |
| 1629 | if (!(hba)) |
| 1630 | return; |
| 1631 | |
Andy Grover | e3d6f90 | 2011-07-19 08:55:10 +0000 | [diff] [blame] | 1632 | if (g_lun0_dev) |
| 1633 | se_free_virtual_device(g_lun0_dev, hba); |
Nicholas Bellinger | c66ac9d | 2010-12-17 11:11:26 -0800 | [diff] [blame] | 1634 | |
| 1635 | kfree(su_dev); |
| 1636 | core_delete_hba(hba); |
| 1637 | } |