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