blob: babde4ad841f18a7956c7d56b1d23ff1f075e3d3 [file] [log] [blame]
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001/*******************************************************************************
2 * Filename: target_core_tpg.c
3 *
4 * This file contains generic Target Portal Group related functions.
5 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07006 * (c) Copyright 2002-2013 Datera, Inc.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08007 *
8 * Nicholas A. Bellinger <nab@kernel.org>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 *
24 ******************************************************************************/
25
26#include <linux/net.h>
27#include <linux/string.h>
28#include <linux/timer.h>
29#include <linux/slab.h>
30#include <linux/spinlock.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080031#include <linux/in.h>
Paul Gortmakerc53181a2011-08-30 18:16:43 -040032#include <linux/export.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080033#include <net/sock.h>
34#include <net/tcp.h>
Bart Van Asscheba929992015-05-08 10:11:12 +020035#include <scsi/scsi_proto.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080036
37#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050038#include <target/target_core_backend.h>
39#include <target/target_core_fabric.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080040
Christoph Hellwige26d99a2011-11-14 12:30:30 -050041#include "target_core_internal.h"
Christoph Hellwigadf653f2015-05-25 21:33:08 -070042#include "target_core_alua.h"
Nicholas Bellingere2480562014-10-04 04:23:15 +000043#include "target_core_pr.h"
Andy Grovere3d6f902011-07-19 08:55:10 +000044
45extern struct se_device *g_lun0_dev;
46
47static DEFINE_SPINLOCK(tpg_lock);
48static LIST_HEAD(tpg_list);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080049
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080050/* __core_tpg_get_initiator_node_acl():
51 *
Nicholas Bellinger403edd72015-03-08 22:33:47 +000052 * mutex_lock(&tpg->acl_node_mutex); must be held when calling
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080053 */
54struct se_node_acl *__core_tpg_get_initiator_node_acl(
55 struct se_portal_group *tpg,
56 const char *initiatorname)
57{
58 struct se_node_acl *acl;
59
60 list_for_each_entry(acl, &tpg->acl_node_list, acl_list) {
Andy Grover6708bb22011-06-08 10:36:43 -070061 if (!strcmp(acl->initiatorname, initiatorname))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080062 return acl;
63 }
64
65 return NULL;
66}
67
68/* core_tpg_get_initiator_node_acl():
69 *
70 *
71 */
72struct se_node_acl *core_tpg_get_initiator_node_acl(
73 struct se_portal_group *tpg,
74 unsigned char *initiatorname)
75{
76 struct se_node_acl *acl;
77
Nicholas Bellinger403edd72015-03-08 22:33:47 +000078 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerfcf29482013-02-18 18:00:33 -080079 acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname);
Nicholas Bellinger403edd72015-03-08 22:33:47 +000080 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080081
Nicholas Bellingerfcf29482013-02-18 18:00:33 -080082 return acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080083}
Thomas Glanzmannb3fde032013-10-07 23:13:02 +020084EXPORT_SYMBOL(core_tpg_get_initiator_node_acl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080085
86/* core_tpg_add_node_to_devs():
87 *
88 *
89 */
90void core_tpg_add_node_to_devs(
91 struct se_node_acl *acl,
Nicholas Bellingerdf9766c2015-05-22 02:05:19 +000092 struct se_portal_group *tpg,
93 struct se_lun *lun_orig)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080094{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080095 u32 lun_access = 0;
96 struct se_lun *lun;
97 struct se_device *dev;
98
Nicholas Bellinger6bb82612015-05-10 19:31:10 -070099 mutex_lock(&tpg->tpg_lun_mutex);
100 hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link) {
Nicholas Bellingerdf9766c2015-05-22 02:05:19 +0000101 if (lun_orig && lun != lun_orig)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800102 continue;
103
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700104 dev = rcu_dereference_check(lun->lun_se_dev,
105 lockdep_is_held(&tpg->tpg_lun_mutex));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800106 /*
107 * By default in LIO-Target $FABRIC_MOD,
108 * demo_mode_write_protect is ON, or READ_ONLY;
109 */
Andy Grover6708bb22011-06-08 10:36:43 -0700110 if (!tpg->se_tpg_tfo->tpg_check_demo_mode_write_protect(tpg)) {
Nicholas Bellinger58d92612012-03-20 21:26:48 -0700111 lun_access = TRANSPORT_LUNFLAGS_READ_WRITE;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800112 } else {
113 /*
114 * Allow only optical drives to issue R/W in default RO
115 * demo mode.
116 */
Andy Grovere3d6f902011-07-19 08:55:10 +0000117 if (dev->transport->get_device_type(dev) == TYPE_DISK)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800118 lun_access = TRANSPORT_LUNFLAGS_READ_ONLY;
119 else
120 lun_access = TRANSPORT_LUNFLAGS_READ_WRITE;
121 }
122
Hannes Reineckef2d30682015-06-10 08:41:22 +0200123 pr_debug("TARGET_CORE[%s]->TPG[%u]_LUN[%llu] - Adding %s"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800124 " access for LUN in Demo Mode\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000125 tpg->se_tpg_tfo->get_fabric_name(),
126 tpg->se_tpg_tfo->tpg_get_tag(tpg), lun->unpacked_lun,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800127 (lun_access == TRANSPORT_LUNFLAGS_READ_WRITE) ?
128 "READ-WRITE" : "READ-ONLY");
129
Andy Grovere80ac6c2012-07-12 17:34:58 -0700130 core_enable_device_list_for_node(lun, NULL, lun->unpacked_lun,
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700131 lun_access, acl, tpg);
Nicholas Bellingere2480562014-10-04 04:23:15 +0000132 /*
133 * Check to see if there are any existing persistent reservation
134 * APTPL pre-registrations that need to be enabled for this dynamic
135 * LUN ACL now..
136 */
137 core_scsi3_check_aptpl_registration(dev, tpg, lun, acl,
138 lun->unpacked_lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800139 }
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700140 mutex_unlock(&tpg->tpg_lun_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800141}
142
143/* core_set_queue_depth_for_node():
144 *
145 *
146 */
147static int core_set_queue_depth_for_node(
148 struct se_portal_group *tpg,
149 struct se_node_acl *acl)
150{
151 if (!acl->queue_depth) {
Andy Grover6708bb22011-06-08 10:36:43 -0700152 pr_err("Queue depth for %s Initiator Node: %s is 0,"
Andy Grovere3d6f902011-07-19 08:55:10 +0000153 "defaulting to 1.\n", tpg->se_tpg_tfo->get_fabric_name(),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800154 acl->initiatorname);
155 acl->queue_depth = 1;
156 }
157
158 return 0;
159}
160
Christoph Hellwige413f472015-04-13 19:51:15 +0200161static struct se_node_acl *target_alloc_node_acl(struct se_portal_group *tpg,
162 const unsigned char *initiatorname)
Jörn Engel4a5a75f2012-03-15 15:05:12 -0400163{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800164 struct se_node_acl *acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800165
Christoph Hellwig144bc4c2015-04-13 19:51:16 +0200166 acl = kzalloc(max(sizeof(*acl), tpg->se_tpg_tfo->node_acl_size),
167 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -0700168 if (!acl)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800169 return NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800170
171 INIT_LIST_HEAD(&acl->acl_list);
172 INIT_LIST_HEAD(&acl->acl_sess_list);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700173 INIT_HLIST_HEAD(&acl->lun_entry_hlist);
Nicholas Bellingerafb999f2012-03-08 23:45:02 -0800174 kref_init(&acl->acl_kref);
Nicholas Bellinger01468342012-03-10 14:32:52 -0800175 init_completion(&acl->acl_free_comp);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800176 spin_lock_init(&acl->nacl_sess_lock);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700177 mutex_init(&acl->lun_entry_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800178 atomic_set(&acl->acl_pr_ref_count, 0);
Christoph Hellwige1750d22015-04-13 19:51:13 +0200179 if (tpg->se_tpg_tfo->tpg_get_default_depth)
180 acl->queue_depth = tpg->se_tpg_tfo->tpg_get_default_depth(tpg);
181 else
182 acl->queue_depth = 1;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800183 snprintf(acl->initiatorname, TRANSPORT_IQN_LEN, "%s", initiatorname);
184 acl->se_tpg = tpg;
185 acl->acl_index = scsi_get_new_index(SCSI_AUTH_INTR_INDEX);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800186
Andy Grovere3d6f902011-07-19 08:55:10 +0000187 tpg->se_tpg_tfo->set_default_node_attributes(acl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800188
Christoph Hellwige413f472015-04-13 19:51:15 +0200189 if (core_set_queue_depth_for_node(tpg, acl) < 0)
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700190 goto out_free_acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800191
Christoph Hellwige413f472015-04-13 19:51:15 +0200192 return acl;
193
Christoph Hellwige413f472015-04-13 19:51:15 +0200194out_free_acl:
Christoph Hellwig144bc4c2015-04-13 19:51:16 +0200195 kfree(acl);
Christoph Hellwige413f472015-04-13 19:51:15 +0200196 return NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800197}
198
Christoph Hellwige413f472015-04-13 19:51:15 +0200199static void target_add_node_acl(struct se_node_acl *acl)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800200{
Christoph Hellwige413f472015-04-13 19:51:15 +0200201 struct se_portal_group *tpg = acl->se_tpg;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800202
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000203 mutex_lock(&tpg->acl_node_mutex);
Christoph Hellwige413f472015-04-13 19:51:15 +0200204 list_add_tail(&acl->acl_list, &tpg->acl_node_list);
205 tpg->num_node_acls++;
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000206 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800207
Christoph Hellwige413f472015-04-13 19:51:15 +0200208 pr_debug("%s_TPG[%hu] - Added %s ACL with TCQ Depth: %d for %s"
209 " Initiator Node: %s\n",
210 tpg->se_tpg_tfo->get_fabric_name(),
211 tpg->se_tpg_tfo->tpg_get_tag(tpg),
212 acl->dynamic_node_acl ? "DYNAMIC" : "",
213 acl->queue_depth,
214 tpg->se_tpg_tfo->get_fabric_name(),
215 acl->initiatorname);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800216}
217
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800218struct se_node_acl *core_tpg_check_initiator_node_acl(
219 struct se_portal_group *tpg,
220 unsigned char *initiatorname)
221{
222 struct se_node_acl *acl;
223
224 acl = core_tpg_get_initiator_node_acl(tpg, initiatorname);
225 if (acl)
226 return acl;
227
228 if (!tpg->se_tpg_tfo->tpg_check_demo_mode(tpg))
229 return NULL;
230
Christoph Hellwige413f472015-04-13 19:51:15 +0200231 acl = target_alloc_node_acl(tpg, initiatorname);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800232 if (!acl)
233 return NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800234 acl->dynamic_node_acl = 1;
235
Nicholas Bellinger052605c2011-07-26 17:48:43 -0700236 /*
237 * Here we only create demo-mode MappedLUNs from the active
Masanari Iida35d1efe2012-08-16 22:43:13 +0900238 * TPG LUNs if the fabric is not explicitly asking for
Nicholas Bellinger052605c2011-07-26 17:48:43 -0700239 * tpg_check_demo_mode_login_only() == 1.
240 */
Andy Grovercdf88a22012-07-12 17:34:57 -0700241 if ((tpg->se_tpg_tfo->tpg_check_demo_mode_login_only == NULL) ||
242 (tpg->se_tpg_tfo->tpg_check_demo_mode_login_only(tpg) != 1))
Nicholas Bellingerdf9766c2015-05-22 02:05:19 +0000243 core_tpg_add_node_to_devs(acl, tpg, NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800244
Christoph Hellwige413f472015-04-13 19:51:15 +0200245 target_add_node_acl(acl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800246 return acl;
247}
248EXPORT_SYMBOL(core_tpg_check_initiator_node_acl);
249
250void core_tpg_wait_for_nacl_pr_ref(struct se_node_acl *nacl)
251{
252 while (atomic_read(&nacl->acl_pr_ref_count) != 0)
253 cpu_relax();
254}
255
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800256struct se_node_acl *core_tpg_add_initiator_node_acl(
257 struct se_portal_group *tpg,
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200258 const char *initiatorname)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800259{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200260 struct se_node_acl *acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800261
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000262 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800263 acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname);
Andy Grover6708bb22011-06-08 10:36:43 -0700264 if (acl) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800265 if (acl->dynamic_node_acl) {
266 acl->dynamic_node_acl = 0;
Andy Grover6708bb22011-06-08 10:36:43 -0700267 pr_debug("%s_TPG[%u] - Replacing dynamic ACL"
Andy Grovere3d6f902011-07-19 08:55:10 +0000268 " for %s\n", tpg->se_tpg_tfo->get_fabric_name(),
269 tpg->se_tpg_tfo->tpg_get_tag(tpg), initiatorname);
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000270 mutex_unlock(&tpg->acl_node_mutex);
Christoph Hellwige413f472015-04-13 19:51:15 +0200271 return acl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800272 }
273
Andy Grover6708bb22011-06-08 10:36:43 -0700274 pr_err("ACL entry for %s Initiator"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800275 " Node %s already exists for TPG %u, ignoring"
Andy Grovere3d6f902011-07-19 08:55:10 +0000276 " request.\n", tpg->se_tpg_tfo->get_fabric_name(),
277 initiatorname, tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000278 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800279 return ERR_PTR(-EEXIST);
280 }
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000281 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800282
Christoph Hellwige413f472015-04-13 19:51:15 +0200283 acl = target_alloc_node_acl(tpg, initiatorname);
284 if (!acl)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800285 return ERR_PTR(-ENOMEM);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800286
Christoph Hellwige413f472015-04-13 19:51:15 +0200287 target_add_node_acl(acl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800288 return acl;
289}
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800290
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200291void core_tpg_del_initiator_node_acl(struct se_node_acl *acl)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800292{
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200293 struct se_portal_group *tpg = acl->se_tpg;
Nicholas Bellinger337c0602012-03-10 14:36:21 -0800294 LIST_HEAD(sess_list);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800295 struct se_session *sess, *sess_tmp;
Nicholas Bellinger140854c2011-08-31 12:34:39 -0700296 unsigned long flags;
Jörn Engel28168902012-03-15 15:06:58 -0400297 int rc;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800298
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000299 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800300 if (acl->dynamic_node_acl) {
301 acl->dynamic_node_acl = 0;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800302 }
303 list_del(&acl->acl_list);
304 tpg->num_node_acls--;
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000305 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800306
Nicholas Bellinger337c0602012-03-10 14:36:21 -0800307 spin_lock_irqsave(&acl->nacl_sess_lock, flags);
308 acl->acl_stop = 1;
309
310 list_for_each_entry_safe(sess, sess_tmp, &acl->acl_sess_list,
311 sess_acl_list) {
312 if (sess->sess_tearing_down != 0)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800313 continue;
314
Nicholas Bellinger337c0602012-03-10 14:36:21 -0800315 target_get_session(sess);
316 list_move(&sess->sess_acl_list, &sess_list);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800317 }
Nicholas Bellinger337c0602012-03-10 14:36:21 -0800318 spin_unlock_irqrestore(&acl->nacl_sess_lock, flags);
319
320 list_for_each_entry_safe(sess, sess_tmp, &sess_list, sess_acl_list) {
321 list_del(&sess->sess_acl_list);
322
323 rc = tpg->se_tpg_tfo->shutdown_session(sess);
324 target_put_session(sess);
325 if (!rc)
326 continue;
327 target_put_session(sess);
328 }
329 target_put_nacl(acl);
330 /*
331 * Wait for last target_put_nacl() to complete in target_complete_nacl()
332 * for active fabric session transport_deregister_session() callbacks.
333 */
334 wait_for_completion(&acl->acl_free_comp);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800335
336 core_tpg_wait_for_nacl_pr_ref(acl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800337 core_free_device_list_for_node(acl, tpg);
338
Andy Grover6708bb22011-06-08 10:36:43 -0700339 pr_debug("%s_TPG[%hu] - Deleted ACL with TCQ Depth: %d for %s"
Andy Grovere3d6f902011-07-19 08:55:10 +0000340 " Initiator Node: %s\n", tpg->se_tpg_tfo->get_fabric_name(),
341 tpg->se_tpg_tfo->tpg_get_tag(tpg), acl->queue_depth,
342 tpg->se_tpg_tfo->get_fabric_name(), acl->initiatorname);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800343
Christoph Hellwig144bc4c2015-04-13 19:51:16 +0200344 kfree(acl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800345}
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800346
347/* core_tpg_set_initiator_node_queue_depth():
348 *
349 *
350 */
351int core_tpg_set_initiator_node_queue_depth(
352 struct se_portal_group *tpg,
353 unsigned char *initiatorname,
354 u32 queue_depth,
355 int force)
356{
357 struct se_session *sess, *init_sess = NULL;
358 struct se_node_acl *acl;
Nicholas Bellinger140854c2011-08-31 12:34:39 -0700359 unsigned long flags;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800360 int dynamic_acl = 0;
361
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000362 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800363 acl = __core_tpg_get_initiator_node_acl(tpg, initiatorname);
Andy Grover6708bb22011-06-08 10:36:43 -0700364 if (!acl) {
365 pr_err("Access Control List entry for %s Initiator"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800366 " Node %s does not exists for TPG %hu, ignoring"
Andy Grovere3d6f902011-07-19 08:55:10 +0000367 " request.\n", tpg->se_tpg_tfo->get_fabric_name(),
368 initiatorname, tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000369 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800370 return -ENODEV;
371 }
372 if (acl->dynamic_node_acl) {
373 acl->dynamic_node_acl = 0;
374 dynamic_acl = 1;
375 }
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000376 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800377
Nicholas Bellinger140854c2011-08-31 12:34:39 -0700378 spin_lock_irqsave(&tpg->session_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800379 list_for_each_entry(sess, &tpg->tpg_sess_list, sess_list) {
380 if (sess->se_node_acl != acl)
381 continue;
382
383 if (!force) {
Andy Grover6708bb22011-06-08 10:36:43 -0700384 pr_err("Unable to change queue depth for %s"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800385 " Initiator Node: %s while session is"
386 " operational. To forcefully change the queue"
387 " depth and force session reinstatement"
388 " use the \"force=1\" parameter.\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000389 tpg->se_tpg_tfo->get_fabric_name(), initiatorname);
Nicholas Bellinger140854c2011-08-31 12:34:39 -0700390 spin_unlock_irqrestore(&tpg->session_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800391
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000392 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800393 if (dynamic_acl)
394 acl->dynamic_node_acl = 1;
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000395 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800396 return -EEXIST;
397 }
398 /*
399 * Determine if the session needs to be closed by our context.
400 */
Andy Grover6708bb22011-06-08 10:36:43 -0700401 if (!tpg->se_tpg_tfo->shutdown_session(sess))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800402 continue;
403
404 init_sess = sess;
405 break;
406 }
407
408 /*
409 * User has requested to change the queue depth for a Initiator Node.
410 * Change the value in the Node's struct se_node_acl, and call
411 * core_set_queue_depth_for_node() to add the requested queue depth.
412 *
Andy Grovere3d6f902011-07-19 08:55:10 +0000413 * Finally call tpg->se_tpg_tfo->close_session() to force session
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800414 * reinstatement to occur if there is an active session for the
415 * $FABRIC_MOD Initiator Node in question.
416 */
417 acl->queue_depth = queue_depth;
418
419 if (core_set_queue_depth_for_node(tpg, acl) < 0) {
Nicholas Bellinger140854c2011-08-31 12:34:39 -0700420 spin_unlock_irqrestore(&tpg->session_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800421 /*
422 * Force session reinstatement if
423 * core_set_queue_depth_for_node() failed, because we assume
424 * the $FABRIC_MOD has already the set session reinstatement
Andy Grovere3d6f902011-07-19 08:55:10 +0000425 * bit from tpg->se_tpg_tfo->shutdown_session() called above.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800426 */
427 if (init_sess)
Andy Grovere3d6f902011-07-19 08:55:10 +0000428 tpg->se_tpg_tfo->close_session(init_sess);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800429
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000430 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800431 if (dynamic_acl)
432 acl->dynamic_node_acl = 1;
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000433 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800434 return -EINVAL;
435 }
Nicholas Bellinger140854c2011-08-31 12:34:39 -0700436 spin_unlock_irqrestore(&tpg->session_lock, flags);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800437 /*
438 * If the $FABRIC_MOD session for the Initiator Node ACL exists,
439 * forcefully shutdown the $FABRIC_MOD session/nexus.
440 */
441 if (init_sess)
Andy Grovere3d6f902011-07-19 08:55:10 +0000442 tpg->se_tpg_tfo->close_session(init_sess);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800443
Joe Perchesbfb90352011-08-17 06:58:04 -0700444 pr_debug("Successfully changed queue depth to: %d for Initiator"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800445 " Node: %s on %s Target Portal Group: %u\n", queue_depth,
Andy Grovere3d6f902011-07-19 08:55:10 +0000446 initiatorname, tpg->se_tpg_tfo->get_fabric_name(),
447 tpg->se_tpg_tfo->tpg_get_tag(tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800448
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000449 mutex_lock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800450 if (dynamic_acl)
451 acl->dynamic_node_acl = 1;
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000452 mutex_unlock(&tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800453
454 return 0;
455}
456EXPORT_SYMBOL(core_tpg_set_initiator_node_queue_depth);
457
Andy Grover79e62fc2012-12-11 16:30:53 -0800458/* core_tpg_set_initiator_node_tag():
459 *
460 * Initiator nodeacl tags are not used internally, but may be used by
461 * userspace to emulate aliases or groups.
462 * Returns length of newly-set tag or -EINVAL.
463 */
464int core_tpg_set_initiator_node_tag(
465 struct se_portal_group *tpg,
466 struct se_node_acl *acl,
467 const char *new_tag)
468{
469 if (strlen(new_tag) >= MAX_ACL_TAG_SIZE)
470 return -EINVAL;
471
472 if (!strncmp("NULL", new_tag, 4)) {
473 acl->acl_tag[0] = '\0';
474 return 0;
475 }
476
477 return snprintf(acl->acl_tag, MAX_ACL_TAG_SIZE, "%s", new_tag);
478}
479EXPORT_SYMBOL(core_tpg_set_initiator_node_tag);
480
Nicholas Bellinger52777972013-11-06 21:03:43 -0800481static void core_tpg_lun_ref_release(struct percpu_ref *ref)
482{
483 struct se_lun *lun = container_of(ref, struct se_lun, lun_ref);
484
485 complete(&lun->lun_ref_comp);
486}
487
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800488int core_tpg_register(
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800489 struct se_wwn *se_wwn,
490 struct se_portal_group *se_tpg,
Christoph Hellwige4aae5a2015-05-01 17:47:56 +0200491 int proto_id)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800492{
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700493 int ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800494
Nicholas Bellingerbc0c94b2015-05-20 21:48:03 -0700495 if (!se_tpg)
496 return -EINVAL;
497 /*
498 * For the typical case where core_tpg_register() is called by a
499 * fabric driver from target_core_fabric_ops->fabric_make_tpg()
500 * configfs context, use the original tf_ops pointer already saved
501 * by target-core in target_fabric_make_wwn().
502 *
503 * Otherwise, for special cases like iscsi-target discovery TPGs
504 * the caller is responsible for setting ->se_tpg_tfo ahead of
505 * calling core_tpg_register().
506 */
507 if (se_wwn)
508 se_tpg->se_tpg_tfo = se_wwn->wwn_tf->tf_ops;
509
510 if (!se_tpg->se_tpg_tfo) {
511 pr_err("Unable to locate se_tpg->se_tpg_tfo pointer\n");
512 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800513 }
514
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700515 INIT_HLIST_HEAD(&se_tpg->tpg_lun_hlist);
Christoph Hellwige4aae5a2015-05-01 17:47:56 +0200516 se_tpg->proto_id = proto_id;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800517 se_tpg->se_tpg_wwn = se_wwn;
518 atomic_set(&se_tpg->tpg_pr_ref_count, 0);
519 INIT_LIST_HEAD(&se_tpg->acl_node_list);
Andy Grovere3d6f902011-07-19 08:55:10 +0000520 INIT_LIST_HEAD(&se_tpg->se_tpg_node);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800521 INIT_LIST_HEAD(&se_tpg->tpg_sess_list);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800522 spin_lock_init(&se_tpg->session_lock);
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700523 mutex_init(&se_tpg->tpg_lun_mutex);
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000524 mutex_init(&se_tpg->acl_node_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800525
Christoph Hellwige4aae5a2015-05-01 17:47:56 +0200526 if (se_tpg->proto_id >= 0) {
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700527 se_tpg->tpg_virt_lun0 = core_tpg_alloc_lun(se_tpg, 0);
528 if (IS_ERR(se_tpg->tpg_virt_lun0))
529 return PTR_ERR(se_tpg->tpg_virt_lun0);
530
531 ret = core_tpg_add_lun(se_tpg, se_tpg->tpg_virt_lun0,
532 TRANSPORT_LUNFLAGS_READ_ONLY, g_lun0_dev);
533 if (ret < 0) {
534 kfree(se_tpg->tpg_virt_lun0);
535 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800536 }
537 }
538
Andy Grovere3d6f902011-07-19 08:55:10 +0000539 spin_lock_bh(&tpg_lock);
540 list_add_tail(&se_tpg->se_tpg_node, &tpg_list);
541 spin_unlock_bh(&tpg_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800542
Christoph Hellwige4aae5a2015-05-01 17:47:56 +0200543 pr_debug("TARGET_CORE[%s]: Allocated portal_group for endpoint: %s, "
Nicholas Bellingerbc0c94b2015-05-20 21:48:03 -0700544 "Proto: %d, Portal Tag: %u\n", se_tpg->se_tpg_tfo->get_fabric_name(),
545 se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg) ?
546 se_tpg->se_tpg_tfo->tpg_get_wwn(se_tpg) : NULL,
547 se_tpg->proto_id, se_tpg->se_tpg_tfo->tpg_get_tag(se_tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800548
549 return 0;
550}
551EXPORT_SYMBOL(core_tpg_register);
552
553int core_tpg_deregister(struct se_portal_group *se_tpg)
554{
Christoph Hellwige4aae5a2015-05-01 17:47:56 +0200555 const struct target_core_fabric_ops *tfo = se_tpg->se_tpg_tfo;
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800556 struct se_node_acl *nacl, *nacl_tmp;
Nicholas Bellinger22793de2015-03-06 10:23:25 +0000557 LIST_HEAD(node_list);
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800558
Christoph Hellwige4aae5a2015-05-01 17:47:56 +0200559 pr_debug("TARGET_CORE[%s]: Deallocating portal_group for endpoint: %s, "
560 "Proto: %d, Portal Tag: %u\n", tfo->get_fabric_name(),
561 tfo->tpg_get_wwn(se_tpg) ? tfo->tpg_get_wwn(se_tpg) : NULL,
562 se_tpg->proto_id, tfo->tpg_get_tag(se_tpg));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800563
Andy Grovere3d6f902011-07-19 08:55:10 +0000564 spin_lock_bh(&tpg_lock);
565 list_del(&se_tpg->se_tpg_node);
566 spin_unlock_bh(&tpg_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800567
568 while (atomic_read(&se_tpg->tpg_pr_ref_count) != 0)
569 cpu_relax();
Nicholas Bellinger403edd72015-03-08 22:33:47 +0000570
Nicholas Bellinger22793de2015-03-06 10:23:25 +0000571 mutex_lock(&se_tpg->acl_node_mutex);
572 list_splice_init(&se_tpg->acl_node_list, &node_list);
573 mutex_unlock(&se_tpg->acl_node_mutex);
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800574 /*
575 * Release any remaining demo-mode generated se_node_acl that have
576 * not been released because of TFO->tpg_check_demo_mode_cache() == 1
577 * in transport_deregister_session().
578 */
Nicholas Bellinger22793de2015-03-06 10:23:25 +0000579 list_for_each_entry_safe(nacl, nacl_tmp, &node_list, acl_list) {
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800580 list_del(&nacl->acl_list);
581 se_tpg->num_node_acls--;
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800582
583 core_tpg_wait_for_nacl_pr_ref(nacl);
584 core_free_device_list_for_node(nacl, se_tpg);
Christoph Hellwig144bc4c2015-04-13 19:51:16 +0200585 kfree(nacl);
Nicholas Bellingere89d15e2011-02-09 15:35:03 -0800586 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800587
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700588 if (se_tpg->proto_id >= 0) {
589 core_tpg_remove_lun(se_tpg, se_tpg->tpg_virt_lun0);
590 kfree_rcu(se_tpg->tpg_virt_lun0, rcu_head);
591 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800592
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800593 return 0;
594}
595EXPORT_SYMBOL(core_tpg_deregister);
596
Andy Groverd344f8a2013-11-26 12:07:54 -0800597struct se_lun *core_tpg_alloc_lun(
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800598 struct se_portal_group *tpg,
Hannes Reineckef2d30682015-06-10 08:41:22 +0200599 u64 unpacked_lun)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800600{
601 struct se_lun *lun;
602
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700603 lun = kzalloc(sizeof(*lun), GFP_KERNEL);
604 if (!lun) {
605 pr_err("Unable to allocate se_lun memory\n");
606 return ERR_PTR(-ENOMEM);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800607 }
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700608 lun->unpacked_lun = unpacked_lun;
609 lun->lun_link_magic = SE_LUN_LINK_MAGIC;
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700610 atomic_set(&lun->lun_acl_count, 0);
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700611 init_completion(&lun->lun_ref_comp);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700612 INIT_LIST_HEAD(&lun->lun_deve_list);
613 INIT_LIST_HEAD(&lun->lun_dev_link);
614 atomic_set(&lun->lun_tg_pt_secondary_offline, 0);
615 spin_lock_init(&lun->lun_deve_lock);
616 mutex_init(&lun->lun_tg_pt_md_mutex);
617 INIT_LIST_HEAD(&lun->lun_tg_pt_gp_link);
618 spin_lock_init(&lun->lun_tg_pt_gp_lock);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700619 lun->lun_tpg = tpg;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800620
621 return lun;
622}
623
Andy Groverd344f8a2013-11-26 12:07:54 -0800624int core_tpg_add_lun(
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800625 struct se_portal_group *tpg,
626 struct se_lun *lun,
627 u32 lun_access,
Andy Grover340dbf72013-12-12 16:12:33 -0800628 struct se_device *dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800629{
Andy Grovere3d6f902011-07-19 08:55:10 +0000630 int ret;
631
Tejun Heo2aad2a82014-09-24 13:31:50 -0400632 ret = percpu_ref_init(&lun->lun_ref, core_tpg_lun_ref_release, 0,
Tejun Heoa34375e2014-09-08 09:51:30 +0900633 GFP_KERNEL);
Andy Grovere3d6f902011-07-19 08:55:10 +0000634 if (ret < 0)
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700635 goto out;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800636
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700637 ret = core_alloc_rtpi(lun, dev);
638 if (ret)
639 goto out_kill_ref;
Nicholas Bellinger52777972013-11-06 21:03:43 -0800640
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700641 if (!(dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) &&
642 !(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE))
643 target_attach_tg_pt_gp(lun, dev->t10_alua.default_tg_pt_gp);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800644
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700645 mutex_lock(&tpg->tpg_lun_mutex);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700646
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700647 spin_lock(&dev->se_port_lock);
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700648 lun->lun_index = dev->dev_index;
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700649 rcu_assign_pointer(lun->lun_se_dev, dev);
650 dev->export_count++;
651 list_add_tail(&lun->lun_dev_link, &dev->dev_sep_list);
652 spin_unlock(&dev->se_port_lock);
653
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800654 lun->lun_access = lun_access;
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700655 if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE))
656 hlist_add_head_rcu(&lun->link, &tpg->tpg_lun_hlist);
657 mutex_unlock(&tpg->tpg_lun_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800658
659 return 0;
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700660
661out_kill_ref:
662 percpu_ref_exit(&lun->lun_ref);
663out:
664 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800665}
666
Andy Grovercd9d7cb2014-06-30 16:39:44 -0700667void core_tpg_remove_lun(
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800668 struct se_portal_group *tpg,
669 struct se_lun *lun)
670{
Nicholas Bellinger4cc987e2015-05-19 00:03:07 -0700671 /*
672 * rcu_dereference_raw protected by se_lun->lun_group symlink
673 * reference to se_device->dev_group.
674 */
675 struct se_device *dev = rcu_dereference_raw(lun->lun_se_dev);
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700676
Nicholas Bellinger4a9a6c82013-11-06 21:05:19 -0800677 core_clear_lun_from_tpg(lun, tpg);
Nicholas Bellinger9e37d042015-05-20 21:21:08 -0700678 /*
679 * Wait for any active I/O references to percpu se_lun->lun_ref to
680 * be released. Also, se_lun->lun_ref is now used by PR and ALUA
681 * logic when referencing a remote target port during ALL_TGT_PT=1
682 * and generating UNIT_ATTENTIONs for ALUA access state transition.
683 */
Nicholas Bellinger4a9a6c82013-11-06 21:05:19 -0800684 transport_clear_lun_ref(lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800685
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700686 mutex_lock(&tpg->tpg_lun_mutex);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700687 if (lun->lun_se_dev) {
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700688 target_detach_tg_pt_gp(lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800689
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700690 spin_lock(&dev->se_port_lock);
691 list_del(&lun->lun_dev_link);
692 dev->export_count--;
693 rcu_assign_pointer(lun->lun_se_dev, NULL);
694 spin_unlock(&dev->se_port_lock);
695 }
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700696 if (!(dev->se_hba->hba_flags & HBA_FLAGS_INTERNAL_USE))
697 hlist_del_rcu(&lun->link);
698 mutex_unlock(&tpg->tpg_lun_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800699
Tejun Heo9a1049d2014-06-28 08:10:14 -0400700 percpu_ref_exit(&lun->lun_ref);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800701}