Commit | Line | Data |
---|---|---|
c66ac9db NB |
1 | /******************************************************************************* |
2 | * Filename: target_core_configfs.c | |
3 | * | |
4 | * This file contains ConfigFS logic for the Generic Target Engine project. | |
5 | * | |
4c76251e | 6 | * (c) Copyright 2008-2013 Datera, Inc. |
c66ac9db NB |
7 | * |
8 | * Nicholas A. Bellinger <nab@kernel.org> | |
9 | * | |
10 | * based on configfs Copyright (C) 2005 Oracle. All rights reserved. | |
11 | * | |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | ****************************************************************************/ | |
22 | ||
23 | #include <linux/module.h> | |
24 | #include <linux/moduleparam.h> | |
c66ac9db NB |
25 | #include <generated/utsrelease.h> |
26 | #include <linux/utsname.h> | |
27 | #include <linux/init.h> | |
28 | #include <linux/fs.h> | |
29 | #include <linux/namei.h> | |
30 | #include <linux/slab.h> | |
31 | #include <linux/types.h> | |
32 | #include <linux/delay.h> | |
33 | #include <linux/unistd.h> | |
34 | #include <linux/string.h> | |
35 | #include <linux/parser.h> | |
36 | #include <linux/syscalls.h> | |
37 | #include <linux/configfs.h> | |
e3d6f909 | 38 | #include <linux/spinlock.h> |
c66ac9db NB |
39 | |
40 | #include <target/target_core_base.h> | |
c4795fb2 CH |
41 | #include <target/target_core_backend.h> |
42 | #include <target/target_core_fabric.h> | |
c66ac9db | 43 | |
e26d99ae | 44 | #include "target_core_internal.h" |
c66ac9db | 45 | #include "target_core_alua.h" |
c66ac9db NB |
46 | #include "target_core_pr.h" |
47 | #include "target_core_rd.h" | |
f99715ac | 48 | #include "target_core_xcopy.h" |
c66ac9db | 49 | |
73112edc | 50 | #define TB_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ |
0a06d430 | 51 | static void target_core_setup_##_name##_cit(struct target_backend *tb) \ |
73112edc | 52 | { \ |
0a06d430 | 53 | struct config_item_type *cit = &tb->tb_##_name##_cit; \ |
73112edc NB |
54 | \ |
55 | cit->ct_item_ops = _item_ops; \ | |
56 | cit->ct_group_ops = _group_ops; \ | |
57 | cit->ct_attrs = _attrs; \ | |
0a06d430 CH |
58 | cit->ct_owner = tb->ops->owner; \ |
59 | pr_debug("Setup generic %s\n", __stringify(_name)); \ | |
60 | } | |
61 | ||
62 | #define TB_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \ | |
63 | static void target_core_setup_##_name##_cit(struct target_backend *tb) \ | |
64 | { \ | |
65 | struct config_item_type *cit = &tb->tb_##_name##_cit; \ | |
66 | \ | |
67 | cit->ct_item_ops = _item_ops; \ | |
68 | cit->ct_group_ops = _group_ops; \ | |
69 | cit->ct_attrs = tb->ops->tb_##_name##_attrs; \ | |
70 | cit->ct_owner = tb->ops->owner; \ | |
73112edc NB |
71 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
72 | } | |
73 | ||
e3d6f909 AG |
74 | extern struct t10_alua_lu_gp *default_lu_gp; |
75 | ||
d0f474e5 RD |
76 | static LIST_HEAD(g_tf_list); |
77 | static DEFINE_MUTEX(g_tf_lock); | |
c66ac9db | 78 | |
e3d6f909 AG |
79 | static struct config_group target_core_hbagroup; |
80 | static struct config_group alua_group; | |
81 | static struct config_group alua_lu_gps_group; | |
82 | ||
c66ac9db NB |
83 | static inline struct se_hba * |
84 | item_to_hba(struct config_item *item) | |
85 | { | |
86 | return container_of(to_config_group(item), struct se_hba, hba_group); | |
87 | } | |
88 | ||
89 | /* | |
90 | * Attributes for /sys/kernel/config/target/ | |
91 | */ | |
2eafd729 CH |
92 | static ssize_t target_core_item_version_show(struct config_item *item, |
93 | char *page) | |
c66ac9db NB |
94 | { |
95 | return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s" | |
ce8dd25d | 96 | " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_VERSION, |
c66ac9db NB |
97 | utsname()->sysname, utsname()->machine); |
98 | } | |
99 | ||
2eafd729 | 100 | CONFIGFS_ATTR_RO(target_core_item_, version); |
c66ac9db NB |
101 | |
102 | static struct target_fabric_configfs *target_core_get_fabric( | |
103 | const char *name) | |
104 | { | |
105 | struct target_fabric_configfs *tf; | |
106 | ||
6708bb27 | 107 | if (!name) |
c66ac9db NB |
108 | return NULL; |
109 | ||
110 | mutex_lock(&g_tf_lock); | |
111 | list_for_each_entry(tf, &g_tf_list, tf_list) { | |
0dc2e8d1 | 112 | if (!strcmp(tf->tf_ops->name, name)) { |
c66ac9db NB |
113 | atomic_inc(&tf->tf_access_cnt); |
114 | mutex_unlock(&g_tf_lock); | |
115 | return tf; | |
116 | } | |
117 | } | |
118 | mutex_unlock(&g_tf_lock); | |
119 | ||
120 | return NULL; | |
121 | } | |
122 | ||
123 | /* | |
124 | * Called from struct target_core_group_ops->make_group() | |
125 | */ | |
126 | static struct config_group *target_core_register_fabric( | |
127 | struct config_group *group, | |
128 | const char *name) | |
129 | { | |
130 | struct target_fabric_configfs *tf; | |
131 | int ret; | |
132 | ||
6708bb27 | 133 | pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:" |
c66ac9db | 134 | " %s\n", group, name); |
e7b7af6e RD |
135 | |
136 | tf = target_core_get_fabric(name); | |
137 | if (!tf) { | |
62554910 NB |
138 | pr_debug("target_core_register_fabric() trying autoload for %s\n", |
139 | name); | |
e7b7af6e | 140 | |
c66ac9db | 141 | /* |
e7b7af6e RD |
142 | * Below are some hardcoded request_module() calls to automatically |
143 | * local fabric modules when the following is called: | |
c66ac9db | 144 | * |
e7b7af6e | 145 | * mkdir -p /sys/kernel/config/target/$MODULE_NAME |
c66ac9db | 146 | * |
e7b7af6e RD |
147 | * Note that this does not limit which TCM fabric module can be |
148 | * registered, but simply provids auto loading logic for modules with | |
149 | * mkdir(2) system calls with known TCM fabric modules. | |
c66ac9db | 150 | */ |
e7b7af6e RD |
151 | |
152 | if (!strncmp(name, "iscsi", 5)) { | |
153 | /* | |
154 | * Automatically load the LIO Target fabric module when the | |
155 | * following is called: | |
156 | * | |
157 | * mkdir -p $CONFIGFS/target/iscsi | |
158 | */ | |
159 | ret = request_module("iscsi_target_mod"); | |
160 | if (ret < 0) { | |
62554910 NB |
161 | pr_debug("request_module() failed for" |
162 | " iscsi_target_mod.ko: %d\n", ret); | |
e7b7af6e RD |
163 | return ERR_PTR(-EINVAL); |
164 | } | |
165 | } else if (!strncmp(name, "loopback", 8)) { | |
166 | /* | |
167 | * Automatically load the tcm_loop fabric module when the | |
168 | * following is called: | |
169 | * | |
170 | * mkdir -p $CONFIGFS/target/loopback | |
171 | */ | |
172 | ret = request_module("tcm_loop"); | |
173 | if (ret < 0) { | |
62554910 NB |
174 | pr_debug("request_module() failed for" |
175 | " tcm_loop.ko: %d\n", ret); | |
e7b7af6e RD |
176 | return ERR_PTR(-EINVAL); |
177 | } | |
c66ac9db | 178 | } |
e7b7af6e RD |
179 | |
180 | tf = target_core_get_fabric(name); | |
c66ac9db NB |
181 | } |
182 | ||
6708bb27 | 183 | if (!tf) { |
62554910 NB |
184 | pr_debug("target_core_get_fabric() failed for %s\n", |
185 | name); | |
c66ac9db NB |
186 | return ERR_PTR(-EINVAL); |
187 | } | |
6708bb27 | 188 | pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:" |
0dc2e8d1 | 189 | " %s\n", tf->tf_ops->name); |
c66ac9db NB |
190 | /* |
191 | * On a successful target_core_get_fabric() look, the returned | |
192 | * struct target_fabric_configfs *tf will contain a usage reference. | |
193 | */ | |
6708bb27 | 194 | pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n", |
968ebe75 | 195 | &tf->tf_wwn_cit); |
c66ac9db | 196 | |
968ebe75 | 197 | config_group_init_type_name(&tf->tf_group, name, &tf->tf_wwn_cit); |
1ae1602d | 198 | |
c66ac9db | 199 | config_group_init_type_name(&tf->tf_disc_group, "discovery_auth", |
968ebe75 | 200 | &tf->tf_discovery_cit); |
1ae1602d | 201 | configfs_add_default_group(&tf->tf_disc_group, &tf->tf_group); |
c66ac9db | 202 | |
6708bb27 | 203 | pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:" |
c66ac9db | 204 | " %s\n", tf->tf_group.cg_item.ci_name); |
c66ac9db NB |
205 | return &tf->tf_group; |
206 | } | |
207 | ||
208 | /* | |
209 | * Called from struct target_core_group_ops->drop_item() | |
210 | */ | |
211 | static void target_core_deregister_fabric( | |
212 | struct config_group *group, | |
213 | struct config_item *item) | |
214 | { | |
215 | struct target_fabric_configfs *tf = container_of( | |
216 | to_config_group(item), struct target_fabric_configfs, tf_group); | |
c66ac9db | 217 | |
6708bb27 | 218 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in" |
c66ac9db NB |
219 | " tf list\n", config_item_name(item)); |
220 | ||
6708bb27 | 221 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:" |
0dc2e8d1 | 222 | " %s\n", tf->tf_ops->name); |
c66ac9db NB |
223 | atomic_dec(&tf->tf_access_cnt); |
224 | ||
6708bb27 | 225 | pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci" |
c66ac9db NB |
226 | " %s\n", config_item_name(item)); |
227 | ||
1ae1602d | 228 | configfs_remove_default_groups(&tf->tf_group); |
c66ac9db NB |
229 | config_item_put(item); |
230 | } | |
231 | ||
232 | static struct configfs_group_operations target_core_fabric_group_ops = { | |
233 | .make_group = &target_core_register_fabric, | |
234 | .drop_item = &target_core_deregister_fabric, | |
235 | }; | |
236 | ||
237 | /* | |
238 | * All item attributes appearing in /sys/kernel/target/ appear here. | |
239 | */ | |
240 | static struct configfs_attribute *target_core_fabric_item_attrs[] = { | |
241 | &target_core_item_attr_version, | |
242 | NULL, | |
243 | }; | |
244 | ||
245 | /* | |
246 | * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/ | |
247 | */ | |
248 | static struct config_item_type target_core_fabrics_item = { | |
c66ac9db NB |
249 | .ct_group_ops = &target_core_fabric_group_ops, |
250 | .ct_attrs = target_core_fabric_item_attrs, | |
251 | .ct_owner = THIS_MODULE, | |
252 | }; | |
253 | ||
254 | static struct configfs_subsystem target_core_fabrics = { | |
255 | .su_group = { | |
256 | .cg_item = { | |
257 | .ci_namebuf = "target", | |
258 | .ci_type = &target_core_fabrics_item, | |
259 | }, | |
260 | }, | |
261 | }; | |
262 | ||
d588cf8f CH |
263 | int target_depend_item(struct config_item *item) |
264 | { | |
265 | return configfs_depend_item(&target_core_fabrics, item); | |
266 | } | |
267 | EXPORT_SYMBOL(target_depend_item); | |
268 | ||
269 | void target_undepend_item(struct config_item *item) | |
270 | { | |
9a9e3415 | 271 | return configfs_undepend_item(item); |
d588cf8f CH |
272 | } |
273 | EXPORT_SYMBOL(target_undepend_item); | |
c66ac9db NB |
274 | |
275 | /*############################################################################## | |
276 | // Start functions called by external Target Fabrics Modules | |
277 | //############################################################################*/ | |
278 | ||
9ac8928e | 279 | static int target_fabric_tf_ops_check(const struct target_core_fabric_ops *tfo) |
c66ac9db | 280 | { |
9ac8928e CH |
281 | if (!tfo->name) { |
282 | pr_err("Missing tfo->name\n"); | |
283 | return -EINVAL; | |
c66ac9db | 284 | } |
9ac8928e | 285 | if (strlen(tfo->name) >= TARGET_FABRIC_NAME_SIZE) { |
6708bb27 | 286 | pr_err("Passed name: %s exceeds TARGET_FABRIC" |
9ac8928e CH |
287 | "_NAME_SIZE\n", tfo->name); |
288 | return -EINVAL; | |
c66ac9db | 289 | } |
6708bb27 AG |
290 | if (!tfo->get_fabric_name) { |
291 | pr_err("Missing tfo->get_fabric_name()\n"); | |
c66ac9db NB |
292 | return -EINVAL; |
293 | } | |
6708bb27 AG |
294 | if (!tfo->tpg_get_wwn) { |
295 | pr_err("Missing tfo->tpg_get_wwn()\n"); | |
c66ac9db NB |
296 | return -EINVAL; |
297 | } | |
6708bb27 AG |
298 | if (!tfo->tpg_get_tag) { |
299 | pr_err("Missing tfo->tpg_get_tag()\n"); | |
c66ac9db NB |
300 | return -EINVAL; |
301 | } | |
6708bb27 AG |
302 | if (!tfo->tpg_check_demo_mode) { |
303 | pr_err("Missing tfo->tpg_check_demo_mode()\n"); | |
c66ac9db NB |
304 | return -EINVAL; |
305 | } | |
6708bb27 AG |
306 | if (!tfo->tpg_check_demo_mode_cache) { |
307 | pr_err("Missing tfo->tpg_check_demo_mode_cache()\n"); | |
c66ac9db NB |
308 | return -EINVAL; |
309 | } | |
6708bb27 AG |
310 | if (!tfo->tpg_check_demo_mode_write_protect) { |
311 | pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n"); | |
c66ac9db NB |
312 | return -EINVAL; |
313 | } | |
6708bb27 AG |
314 | if (!tfo->tpg_check_prod_mode_write_protect) { |
315 | pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n"); | |
c66ac9db NB |
316 | return -EINVAL; |
317 | } | |
6708bb27 AG |
318 | if (!tfo->tpg_get_inst_index) { |
319 | pr_err("Missing tfo->tpg_get_inst_index()\n"); | |
c66ac9db NB |
320 | return -EINVAL; |
321 | } | |
35462975 | 322 | if (!tfo->release_cmd) { |
6708bb27 | 323 | pr_err("Missing tfo->release_cmd()\n"); |
c66ac9db NB |
324 | return -EINVAL; |
325 | } | |
6708bb27 AG |
326 | if (!tfo->shutdown_session) { |
327 | pr_err("Missing tfo->shutdown_session()\n"); | |
c66ac9db NB |
328 | return -EINVAL; |
329 | } | |
6708bb27 AG |
330 | if (!tfo->close_session) { |
331 | pr_err("Missing tfo->close_session()\n"); | |
c66ac9db NB |
332 | return -EINVAL; |
333 | } | |
6708bb27 AG |
334 | if (!tfo->sess_get_index) { |
335 | pr_err("Missing tfo->sess_get_index()\n"); | |
c66ac9db NB |
336 | return -EINVAL; |
337 | } | |
6708bb27 AG |
338 | if (!tfo->write_pending) { |
339 | pr_err("Missing tfo->write_pending()\n"); | |
c66ac9db NB |
340 | return -EINVAL; |
341 | } | |
6708bb27 AG |
342 | if (!tfo->write_pending_status) { |
343 | pr_err("Missing tfo->write_pending_status()\n"); | |
c66ac9db NB |
344 | return -EINVAL; |
345 | } | |
6708bb27 AG |
346 | if (!tfo->set_default_node_attributes) { |
347 | pr_err("Missing tfo->set_default_node_attributes()\n"); | |
c66ac9db NB |
348 | return -EINVAL; |
349 | } | |
6708bb27 AG |
350 | if (!tfo->get_cmd_state) { |
351 | pr_err("Missing tfo->get_cmd_state()\n"); | |
c66ac9db NB |
352 | return -EINVAL; |
353 | } | |
6708bb27 AG |
354 | if (!tfo->queue_data_in) { |
355 | pr_err("Missing tfo->queue_data_in()\n"); | |
c66ac9db NB |
356 | return -EINVAL; |
357 | } | |
6708bb27 AG |
358 | if (!tfo->queue_status) { |
359 | pr_err("Missing tfo->queue_status()\n"); | |
c66ac9db NB |
360 | return -EINVAL; |
361 | } | |
6708bb27 AG |
362 | if (!tfo->queue_tm_rsp) { |
363 | pr_err("Missing tfo->queue_tm_rsp()\n"); | |
c66ac9db NB |
364 | return -EINVAL; |
365 | } | |
131e6abc NB |
366 | if (!tfo->aborted_task) { |
367 | pr_err("Missing tfo->aborted_task()\n"); | |
368 | return -EINVAL; | |
369 | } | |
c66ac9db NB |
370 | /* |
371 | * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn() | |
372 | * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in | |
373 | * target_core_fabric_configfs.c WWN+TPG group context code. | |
374 | */ | |
6708bb27 AG |
375 | if (!tfo->fabric_make_wwn) { |
376 | pr_err("Missing tfo->fabric_make_wwn()\n"); | |
c66ac9db NB |
377 | return -EINVAL; |
378 | } | |
6708bb27 AG |
379 | if (!tfo->fabric_drop_wwn) { |
380 | pr_err("Missing tfo->fabric_drop_wwn()\n"); | |
c66ac9db NB |
381 | return -EINVAL; |
382 | } | |
6708bb27 AG |
383 | if (!tfo->fabric_make_tpg) { |
384 | pr_err("Missing tfo->fabric_make_tpg()\n"); | |
c66ac9db NB |
385 | return -EINVAL; |
386 | } | |
6708bb27 AG |
387 | if (!tfo->fabric_drop_tpg) { |
388 | pr_err("Missing tfo->fabric_drop_tpg()\n"); | |
c66ac9db NB |
389 | return -EINVAL; |
390 | } | |
391 | ||
392 | return 0; | |
393 | } | |
394 | ||
9ac8928e | 395 | int target_register_template(const struct target_core_fabric_ops *fo) |
c66ac9db | 396 | { |
9ac8928e | 397 | struct target_fabric_configfs *tf; |
c66ac9db NB |
398 | int ret; |
399 | ||
9ac8928e CH |
400 | ret = target_fabric_tf_ops_check(fo); |
401 | if (ret) | |
402 | return ret; | |
403 | ||
404 | tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL); | |
6708bb27 | 405 | if (!tf) { |
9ac8928e CH |
406 | pr_err("%s: could not allocate memory!\n", __func__); |
407 | return -ENOMEM; | |
c66ac9db | 408 | } |
c66ac9db | 409 | |
9ac8928e CH |
410 | INIT_LIST_HEAD(&tf->tf_list); |
411 | atomic_set(&tf->tf_access_cnt, 0); | |
ef0caf8d | 412 | tf->tf_ops = fo; |
9ac8928e CH |
413 | target_fabric_setup_cits(tf); |
414 | ||
415 | mutex_lock(&g_tf_lock); | |
416 | list_add_tail(&tf->tf_list, &g_tf_list); | |
417 | mutex_unlock(&g_tf_lock); | |
418 | ||
c66ac9db NB |
419 | return 0; |
420 | } | |
9ac8928e | 421 | EXPORT_SYMBOL(target_register_template); |
c66ac9db | 422 | |
9ac8928e | 423 | void target_unregister_template(const struct target_core_fabric_ops *fo) |
c66ac9db | 424 | { |
9ac8928e | 425 | struct target_fabric_configfs *t; |
c66ac9db | 426 | |
c66ac9db | 427 | mutex_lock(&g_tf_lock); |
9ac8928e | 428 | list_for_each_entry(t, &g_tf_list, tf_list) { |
0dc2e8d1 | 429 | if (!strcmp(t->tf_ops->name, fo->name)) { |
9ac8928e CH |
430 | BUG_ON(atomic_read(&t->tf_access_cnt)); |
431 | list_del(&t->tf_list); | |
94509182 NB |
432 | mutex_unlock(&g_tf_lock); |
433 | /* | |
434 | * Wait for any outstanding fabric se_deve_entry->rcu_head | |
435 | * callbacks to complete post kfree_rcu(), before allowing | |
436 | * fabric driver unload of TFO->module to proceed. | |
437 | */ | |
438 | rcu_barrier(); | |
9ac8928e | 439 | kfree(t); |
94509182 | 440 | return; |
9ac8928e | 441 | } |
c66ac9db | 442 | } |
c66ac9db | 443 | mutex_unlock(&g_tf_lock); |
c66ac9db | 444 | } |
9ac8928e | 445 | EXPORT_SYMBOL(target_unregister_template); |
c66ac9db NB |
446 | |
447 | /*############################################################################## | |
448 | // Stop functions called by external Target Fabrics Modules | |
449 | //############################################################################*/ | |
450 | ||
2eafd729 CH |
451 | static inline struct se_dev_attrib *to_attrib(struct config_item *item) |
452 | { | |
453 | return container_of(to_config_group(item), struct se_dev_attrib, | |
454 | da_group); | |
455 | } | |
456 | ||
f79a897e | 457 | /* Start functions for struct config_item_type tb_dev_attrib_cit */ |
2eafd729 CH |
458 | #define DEF_CONFIGFS_ATTRIB_SHOW(_name) \ |
459 | static ssize_t _name##_show(struct config_item *item, char *page) \ | |
5873c4d1 | 460 | { \ |
2eafd729 CH |
461 | return snprintf(page, PAGE_SIZE, "%u\n", to_attrib(item)->_name); \ |
462 | } | |
463 | ||
464 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_model_alias); | |
465 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_dpo); | |
466 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_write); | |
467 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_read); | |
468 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_write_cache); | |
469 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_ua_intlck_ctrl); | |
470 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_tas); | |
471 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpu); | |
472 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpws); | |
473 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_caw); | |
474 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_3pc); | |
475 | DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_type); | |
476 | DEF_CONFIGFS_ATTRIB_SHOW(hw_pi_prot_type); | |
477 | DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_format); | |
478 | DEF_CONFIGFS_ATTRIB_SHOW(enforce_pr_isids); | |
479 | DEF_CONFIGFS_ATTRIB_SHOW(is_nonrot); | |
480 | DEF_CONFIGFS_ATTRIB_SHOW(emulate_rest_reord); | |
481 | DEF_CONFIGFS_ATTRIB_SHOW(force_pr_aptpl); | |
482 | DEF_CONFIGFS_ATTRIB_SHOW(hw_block_size); | |
483 | DEF_CONFIGFS_ATTRIB_SHOW(block_size); | |
484 | DEF_CONFIGFS_ATTRIB_SHOW(hw_max_sectors); | |
485 | DEF_CONFIGFS_ATTRIB_SHOW(optimal_sectors); | |
486 | DEF_CONFIGFS_ATTRIB_SHOW(hw_queue_depth); | |
487 | DEF_CONFIGFS_ATTRIB_SHOW(queue_depth); | |
488 | DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_lba_count); | |
489 | DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_block_desc_count); | |
490 | DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity); | |
491 | DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity_alignment); | |
e6f41633 | 492 | DEF_CONFIGFS_ATTRIB_SHOW(unmap_zeroes_data); |
2eafd729 CH |
493 | DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len); |
494 | ||
495 | #define DEF_CONFIGFS_ATTRIB_STORE_U32(_name) \ | |
496 | static ssize_t _name##_store(struct config_item *item, const char *page,\ | |
3effdb90 | 497 | size_t count) \ |
5873c4d1 | 498 | { \ |
2eafd729 | 499 | struct se_dev_attrib *da = to_attrib(item); \ |
3effdb90 | 500 | u32 val; \ |
5873c4d1 CH |
501 | int ret; \ |
502 | \ | |
3effdb90 CH |
503 | ret = kstrtou32(page, 0, &val); \ |
504 | if (ret < 0) \ | |
505 | return ret; \ | |
506 | da->_name = val; \ | |
507 | return count; \ | |
508 | } | |
509 | ||
2eafd729 CH |
510 | DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_lba_count); |
511 | DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_block_desc_count); | |
512 | DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity); | |
513 | DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity_alignment); | |
514 | DEF_CONFIGFS_ATTRIB_STORE_U32(max_write_same_len); | |
3effdb90 | 515 | |
2eafd729 CH |
516 | #define DEF_CONFIGFS_ATTRIB_STORE_BOOL(_name) \ |
517 | static ssize_t _name##_store(struct config_item *item, const char *page, \ | |
3effdb90 CH |
518 | size_t count) \ |
519 | { \ | |
2eafd729 | 520 | struct se_dev_attrib *da = to_attrib(item); \ |
3effdb90 CH |
521 | bool flag; \ |
522 | int ret; \ | |
5873c4d1 | 523 | \ |
3effdb90 CH |
524 | ret = strtobool(page, &flag); \ |
525 | if (ret < 0) \ | |
526 | return ret; \ | |
527 | da->_name = flag; \ | |
528 | return count; \ | |
529 | } | |
530 | ||
2eafd729 CH |
531 | DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_fua_write); |
532 | DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_caw); | |
533 | DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_3pc); | |
534 | DEF_CONFIGFS_ATTRIB_STORE_BOOL(enforce_pr_isids); | |
535 | DEF_CONFIGFS_ATTRIB_STORE_BOOL(is_nonrot); | |
3effdb90 | 536 | |
2eafd729 CH |
537 | #define DEF_CONFIGFS_ATTRIB_STORE_STUB(_name) \ |
538 | static ssize_t _name##_store(struct config_item *item, const char *page,\ | |
3effdb90 CH |
539 | size_t count) \ |
540 | { \ | |
541 | printk_once(KERN_WARNING \ | |
234bdbc4 CVB |
542 | "ignoring deprecated %s attribute\n", \ |
543 | __stringify(_name)); \ | |
3effdb90 CH |
544 | return count; \ |
545 | } | |
546 | ||
2eafd729 CH |
547 | DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_dpo); |
548 | DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_fua_read); | |
3effdb90 CH |
549 | |
550 | static void dev_set_t10_wwn_model_alias(struct se_device *dev) | |
551 | { | |
552 | const char *configname; | |
553 | ||
554 | configname = config_item_name(&dev->dev_group.cg_item); | |
555 | if (strlen(configname) >= 16) { | |
556 | pr_warn("dev[%p]: Backstore name '%s' is too long for " | |
557 | "INQUIRY_MODEL, truncating to 16 bytes\n", dev, | |
558 | configname); | |
559 | } | |
560 | snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); | |
561 | } | |
562 | ||
2eafd729 | 563 | static ssize_t emulate_model_alias_store(struct config_item *item, |
3effdb90 CH |
564 | const char *page, size_t count) |
565 | { | |
2eafd729 | 566 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
567 | struct se_device *dev = da->da_dev; |
568 | bool flag; | |
569 | int ret; | |
570 | ||
571 | if (dev->export_count) { | |
572 | pr_err("dev[%p]: Unable to change model alias" | |
573 | " while export_count is %d\n", | |
574 | dev, dev->export_count); | |
575 | return -EINVAL; | |
576 | } | |
577 | ||
578 | ret = strtobool(page, &flag); | |
579 | if (ret < 0) | |
580 | return ret; | |
581 | ||
582 | if (flag) { | |
583 | dev_set_t10_wwn_model_alias(dev); | |
584 | } else { | |
585 | strncpy(&dev->t10_wwn.model[0], | |
586 | dev->transport->inquiry_prod, 16); | |
587 | } | |
588 | da->emulate_model_alias = flag; | |
589 | return count; | |
590 | } | |
591 | ||
2eafd729 | 592 | static ssize_t emulate_write_cache_store(struct config_item *item, |
3effdb90 CH |
593 | const char *page, size_t count) |
594 | { | |
2eafd729 | 595 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
596 | bool flag; |
597 | int ret; | |
598 | ||
599 | ret = strtobool(page, &flag); | |
600 | if (ret < 0) | |
601 | return ret; | |
602 | ||
603 | if (flag && da->da_dev->transport->get_write_cache) { | |
604 | pr_err("emulate_write_cache not supported for this device\n"); | |
605 | return -EINVAL; | |
606 | } | |
607 | ||
608 | da->emulate_write_cache = flag; | |
609 | pr_debug("dev[%p]: SE Device WRITE_CACHE_EMULATION flag: %d\n", | |
610 | da->da_dev, flag); | |
611 | return count; | |
612 | } | |
613 | ||
2eafd729 | 614 | static ssize_t emulate_ua_intlck_ctrl_store(struct config_item *item, |
3effdb90 CH |
615 | const char *page, size_t count) |
616 | { | |
2eafd729 | 617 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
618 | u32 val; |
619 | int ret; | |
620 | ||
621 | ret = kstrtou32(page, 0, &val); | |
622 | if (ret < 0) | |
623 | return ret; | |
624 | ||
625 | if (val != 0 && val != 1 && val != 2) { | |
626 | pr_err("Illegal value %d\n", val); | |
627 | return -EINVAL; | |
628 | } | |
629 | ||
630 | if (da->da_dev->export_count) { | |
631 | pr_err("dev[%p]: Unable to change SE Device" | |
632 | " UA_INTRLCK_CTRL while export_count is %d\n", | |
633 | da->da_dev, da->da_dev->export_count); | |
634 | return -EINVAL; | |
635 | } | |
636 | da->emulate_ua_intlck_ctrl = val; | |
637 | pr_debug("dev[%p]: SE Device UA_INTRLCK_CTRL flag: %d\n", | |
638 | da->da_dev, val); | |
639 | return count; | |
640 | } | |
641 | ||
2eafd729 | 642 | static ssize_t emulate_tas_store(struct config_item *item, |
3effdb90 CH |
643 | const char *page, size_t count) |
644 | { | |
2eafd729 | 645 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
646 | bool flag; |
647 | int ret; | |
648 | ||
649 | ret = strtobool(page, &flag); | |
650 | if (ret < 0) | |
651 | return ret; | |
652 | ||
653 | if (da->da_dev->export_count) { | |
654 | pr_err("dev[%p]: Unable to change SE Device TAS while" | |
655 | " export_count is %d\n", | |
656 | da->da_dev, da->da_dev->export_count); | |
657 | return -EINVAL; | |
658 | } | |
659 | da->emulate_tas = flag; | |
660 | pr_debug("dev[%p]: SE Device TASK_ABORTED status bit: %s\n", | |
661 | da->da_dev, flag ? "Enabled" : "Disabled"); | |
662 | ||
663 | return count; | |
664 | } | |
665 | ||
2eafd729 | 666 | static ssize_t emulate_tpu_store(struct config_item *item, |
3effdb90 CH |
667 | const char *page, size_t count) |
668 | { | |
2eafd729 | 669 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
670 | bool flag; |
671 | int ret; | |
672 | ||
673 | ret = strtobool(page, &flag); | |
674 | if (ret < 0) | |
675 | return ret; | |
676 | ||
677 | /* | |
678 | * We expect this value to be non-zero when generic Block Layer | |
679 | * Discard supported is detected iblock_create_virtdevice(). | |
680 | */ | |
681 | if (flag && !da->max_unmap_block_desc_count) { | |
682 | pr_err("Generic Block Discard not supported\n"); | |
683 | return -ENOSYS; | |
684 | } | |
685 | ||
686 | da->emulate_tpu = flag; | |
687 | pr_debug("dev[%p]: SE Device Thin Provisioning UNMAP bit: %d\n", | |
688 | da->da_dev, flag); | |
689 | return count; | |
690 | } | |
691 | ||
2eafd729 | 692 | static ssize_t emulate_tpws_store(struct config_item *item, |
3effdb90 CH |
693 | const char *page, size_t count) |
694 | { | |
2eafd729 | 695 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
696 | bool flag; |
697 | int ret; | |
698 | ||
699 | ret = strtobool(page, &flag); | |
700 | if (ret < 0) | |
701 | return ret; | |
702 | ||
703 | /* | |
704 | * We expect this value to be non-zero when generic Block Layer | |
705 | * Discard supported is detected iblock_create_virtdevice(). | |
706 | */ | |
707 | if (flag && !da->max_unmap_block_desc_count) { | |
708 | pr_err("Generic Block Discard not supported\n"); | |
709 | return -ENOSYS; | |
710 | } | |
711 | ||
712 | da->emulate_tpws = flag; | |
713 | pr_debug("dev[%p]: SE Device Thin Provisioning WRITE_SAME: %d\n", | |
714 | da->da_dev, flag); | |
715 | return count; | |
716 | } | |
717 | ||
2eafd729 | 718 | static ssize_t pi_prot_type_store(struct config_item *item, |
3effdb90 CH |
719 | const char *page, size_t count) |
720 | { | |
2eafd729 | 721 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
722 | int old_prot = da->pi_prot_type, ret; |
723 | struct se_device *dev = da->da_dev; | |
724 | u32 flag; | |
725 | ||
726 | ret = kstrtou32(page, 0, &flag); | |
727 | if (ret < 0) | |
728 | return ret; | |
729 | ||
730 | if (flag != 0 && flag != 1 && flag != 2 && flag != 3) { | |
731 | pr_err("Illegal value %d for pi_prot_type\n", flag); | |
732 | return -EINVAL; | |
733 | } | |
734 | if (flag == 2) { | |
735 | pr_err("DIF TYPE2 protection currently not supported\n"); | |
736 | return -ENOSYS; | |
737 | } | |
738 | if (da->hw_pi_prot_type) { | |
739 | pr_warn("DIF protection enabled on underlying hardware," | |
740 | " ignoring\n"); | |
741 | return count; | |
742 | } | |
743 | if (!dev->transport->init_prot || !dev->transport->free_prot) { | |
744 | /* 0 is only allowed value for non-supporting backends */ | |
745 | if (flag == 0) | |
bc1a7d6a | 746 | return count; |
3effdb90 CH |
747 | |
748 | pr_err("DIF protection not supported by backend: %s\n", | |
749 | dev->transport->name); | |
750 | return -ENOSYS; | |
751 | } | |
752 | if (!(dev->dev_flags & DF_CONFIGURED)) { | |
753 | pr_err("DIF protection requires device to be configured\n"); | |
754 | return -ENODEV; | |
755 | } | |
756 | if (dev->export_count) { | |
757 | pr_err("dev[%p]: Unable to change SE Device PROT type while" | |
758 | " export_count is %d\n", dev, dev->export_count); | |
759 | return -EINVAL; | |
760 | } | |
761 | ||
762 | da->pi_prot_type = flag; | |
763 | ||
764 | if (flag && !old_prot) { | |
765 | ret = dev->transport->init_prot(dev); | |
766 | if (ret) { | |
767 | da->pi_prot_type = old_prot; | |
768 | return ret; | |
769 | } | |
770 | ||
771 | } else if (!flag && old_prot) { | |
772 | dev->transport->free_prot(dev); | |
773 | } | |
774 | ||
775 | pr_debug("dev[%p]: SE Device Protection Type: %d\n", dev, flag); | |
776 | return count; | |
777 | } | |
778 | ||
2eafd729 | 779 | static ssize_t pi_prot_format_store(struct config_item *item, |
3effdb90 CH |
780 | const char *page, size_t count) |
781 | { | |
2eafd729 | 782 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
783 | struct se_device *dev = da->da_dev; |
784 | bool flag; | |
785 | int ret; | |
786 | ||
787 | ret = strtobool(page, &flag); | |
788 | if (ret < 0) | |
789 | return ret; | |
790 | ||
791 | if (!flag) | |
792 | return count; | |
793 | ||
794 | if (!dev->transport->format_prot) { | |
795 | pr_err("DIF protection format not supported by backend %s\n", | |
796 | dev->transport->name); | |
797 | return -ENOSYS; | |
798 | } | |
799 | if (!(dev->dev_flags & DF_CONFIGURED)) { | |
800 | pr_err("DIF protection format requires device to be configured\n"); | |
801 | return -ENODEV; | |
802 | } | |
803 | if (dev->export_count) { | |
804 | pr_err("dev[%p]: Unable to format SE Device PROT type while" | |
805 | " export_count is %d\n", dev, dev->export_count); | |
806 | return -EINVAL; | |
807 | } | |
808 | ||
809 | ret = dev->transport->format_prot(dev); | |
810 | if (ret) | |
811 | return ret; | |
812 | ||
813 | pr_debug("dev[%p]: SE Device Protection Format complete\n", dev); | |
814 | return count; | |
815 | } | |
816 | ||
2eafd729 | 817 | static ssize_t force_pr_aptpl_store(struct config_item *item, |
3effdb90 CH |
818 | const char *page, size_t count) |
819 | { | |
2eafd729 | 820 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
821 | bool flag; |
822 | int ret; | |
823 | ||
824 | ret = strtobool(page, &flag); | |
825 | if (ret < 0) | |
826 | return ret; | |
827 | if (da->da_dev->export_count) { | |
828 | pr_err("dev[%p]: Unable to set force_pr_aptpl while" | |
829 | " export_count is %d\n", | |
830 | da->da_dev, da->da_dev->export_count); | |
831 | return -EINVAL; | |
832 | } | |
833 | ||
834 | da->force_pr_aptpl = flag; | |
835 | pr_debug("dev[%p]: SE Device force_pr_aptpl: %d\n", da->da_dev, flag); | |
836 | return count; | |
837 | } | |
838 | ||
2eafd729 | 839 | static ssize_t emulate_rest_reord_store(struct config_item *item, |
3effdb90 CH |
840 | const char *page, size_t count) |
841 | { | |
2eafd729 | 842 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
843 | bool flag; |
844 | int ret; | |
845 | ||
846 | ret = strtobool(page, &flag); | |
847 | if (ret < 0) | |
848 | return ret; | |
849 | ||
850 | if (flag != 0) { | |
851 | printk(KERN_ERR "dev[%p]: SE Device emulation of restricted" | |
852 | " reordering not implemented\n", da->da_dev); | |
853 | return -ENOSYS; | |
854 | } | |
855 | da->emulate_rest_reord = flag; | |
856 | pr_debug("dev[%p]: SE Device emulate_rest_reord: %d\n", | |
857 | da->da_dev, flag); | |
858 | return count; | |
859 | } | |
860 | ||
e6f41633 JP |
861 | static ssize_t unmap_zeroes_data_store(struct config_item *item, |
862 | const char *page, size_t count) | |
863 | { | |
864 | struct se_dev_attrib *da = to_attrib(item); | |
865 | bool flag; | |
866 | int ret; | |
867 | ||
868 | ret = strtobool(page, &flag); | |
869 | if (ret < 0) | |
870 | return ret; | |
871 | ||
872 | if (da->da_dev->export_count) { | |
873 | pr_err("dev[%p]: Unable to change SE Device" | |
874 | " unmap_zeroes_data while export_count is %d\n", | |
875 | da->da_dev, da->da_dev->export_count); | |
876 | return -EINVAL; | |
877 | } | |
878 | /* | |
879 | * We expect this value to be non-zero when generic Block Layer | |
880 | * Discard supported is detected iblock_configure_device(). | |
881 | */ | |
882 | if (flag && !da->max_unmap_block_desc_count) { | |
883 | pr_err("dev[%p]: Thin Provisioning LBPRZ will not be set" | |
884 | " because max_unmap_block_desc_count is zero\n", | |
885 | da->da_dev); | |
9b3118ce | 886 | return -ENOSYS; |
e6f41633 JP |
887 | } |
888 | da->unmap_zeroes_data = flag; | |
889 | pr_debug("dev[%p]: SE Device Thin Provisioning LBPRZ bit: %d\n", | |
890 | da->da_dev, flag); | |
2e498f25 | 891 | return count; |
e6f41633 JP |
892 | } |
893 | ||
3effdb90 CH |
894 | /* |
895 | * Note, this can only be called on unexported SE Device Object. | |
896 | */ | |
2eafd729 | 897 | static ssize_t queue_depth_store(struct config_item *item, |
3effdb90 CH |
898 | const char *page, size_t count) |
899 | { | |
2eafd729 | 900 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
901 | struct se_device *dev = da->da_dev; |
902 | u32 val; | |
903 | int ret; | |
904 | ||
905 | ret = kstrtou32(page, 0, &val); | |
906 | if (ret < 0) | |
907 | return ret; | |
908 | ||
909 | if (dev->export_count) { | |
910 | pr_err("dev[%p]: Unable to change SE Device TCQ while" | |
911 | " export_count is %d\n", | |
912 | dev, dev->export_count); | |
913 | return -EINVAL; | |
914 | } | |
915 | if (!val) { | |
916 | pr_err("dev[%p]: Illegal ZERO value for queue_depth\n", dev); | |
917 | return -EINVAL; | |
918 | } | |
919 | ||
920 | if (val > dev->dev_attrib.queue_depth) { | |
921 | if (val > dev->dev_attrib.hw_queue_depth) { | |
922 | pr_err("dev[%p]: Passed queue_depth:" | |
923 | " %u exceeds TCM/SE_Device MAX" | |
924 | " TCQ: %u\n", dev, val, | |
925 | dev->dev_attrib.hw_queue_depth); | |
926 | return -EINVAL; | |
927 | } | |
928 | } | |
929 | da->queue_depth = dev->queue_depth = val; | |
930 | pr_debug("dev[%p]: SE Device TCQ Depth changed to: %u\n", dev, val); | |
931 | return count; | |
932 | } | |
933 | ||
2eafd729 | 934 | static ssize_t optimal_sectors_store(struct config_item *item, |
3effdb90 CH |
935 | const char *page, size_t count) |
936 | { | |
2eafd729 | 937 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
938 | u32 val; |
939 | int ret; | |
940 | ||
941 | ret = kstrtou32(page, 0, &val); | |
942 | if (ret < 0) | |
943 | return ret; | |
944 | ||
945 | if (da->da_dev->export_count) { | |
946 | pr_err("dev[%p]: Unable to change SE Device" | |
947 | " optimal_sectors while export_count is %d\n", | |
948 | da->da_dev, da->da_dev->export_count); | |
949 | return -EINVAL; | |
950 | } | |
951 | if (val > da->hw_max_sectors) { | |
952 | pr_err("dev[%p]: Passed optimal_sectors %u cannot be" | |
953 | " greater than hw_max_sectors: %u\n", | |
954 | da->da_dev, val, da->hw_max_sectors); | |
955 | return -EINVAL; | |
956 | } | |
957 | ||
958 | da->optimal_sectors = val; | |
959 | pr_debug("dev[%p]: SE Device optimal_sectors changed to %u\n", | |
960 | da->da_dev, val); | |
961 | return count; | |
5873c4d1 CH |
962 | } |
963 | ||
2eafd729 | 964 | static ssize_t block_size_store(struct config_item *item, |
3effdb90 CH |
965 | const char *page, size_t count) |
966 | { | |
2eafd729 | 967 | struct se_dev_attrib *da = to_attrib(item); |
3effdb90 CH |
968 | u32 val; |
969 | int ret; | |
970 | ||
971 | ret = kstrtou32(page, 0, &val); | |
972 | if (ret < 0) | |
973 | return ret; | |
5873c4d1 | 974 | |
3effdb90 CH |
975 | if (da->da_dev->export_count) { |
976 | pr_err("dev[%p]: Unable to change SE Device block_size" | |
977 | " while export_count is %d\n", | |
978 | da->da_dev, da->da_dev->export_count); | |
979 | return -EINVAL; | |
980 | } | |
981 | ||
982 | if (val != 512 && val != 1024 && val != 2048 && val != 4096) { | |
983 | pr_err("dev[%p]: Illegal value for block_device: %u" | |
984 | " for SE device, must be 512, 1024, 2048 or 4096\n", | |
985 | da->da_dev, val); | |
986 | return -EINVAL; | |
987 | } | |
988 | ||
989 | da->block_size = val; | |
990 | if (da->max_bytes_per_io) | |
991 | da->hw_max_sectors = da->max_bytes_per_io / val; | |
992 | ||
993 | pr_debug("dev[%p]: SE Device block_size changed to %u\n", | |
994 | da->da_dev, val); | |
995 | return count; | |
996 | } | |
5873c4d1 | 997 | |
2eafd729 CH |
998 | CONFIGFS_ATTR(, emulate_model_alias); |
999 | CONFIGFS_ATTR(, emulate_dpo); | |
1000 | CONFIGFS_ATTR(, emulate_fua_write); | |
1001 | CONFIGFS_ATTR(, emulate_fua_read); | |
1002 | CONFIGFS_ATTR(, emulate_write_cache); | |
1003 | CONFIGFS_ATTR(, emulate_ua_intlck_ctrl); | |
1004 | CONFIGFS_ATTR(, emulate_tas); | |
1005 | CONFIGFS_ATTR(, emulate_tpu); | |
1006 | CONFIGFS_ATTR(, emulate_tpws); | |
1007 | CONFIGFS_ATTR(, emulate_caw); | |
1008 | CONFIGFS_ATTR(, emulate_3pc); | |
1009 | CONFIGFS_ATTR(, pi_prot_type); | |
1010 | CONFIGFS_ATTR_RO(, hw_pi_prot_type); | |
1011 | CONFIGFS_ATTR(, pi_prot_format); | |
1012 | CONFIGFS_ATTR(, enforce_pr_isids); | |
1013 | CONFIGFS_ATTR(, is_nonrot); | |
1014 | CONFIGFS_ATTR(, emulate_rest_reord); | |
1015 | CONFIGFS_ATTR(, force_pr_aptpl); | |
1016 | CONFIGFS_ATTR_RO(, hw_block_size); | |
1017 | CONFIGFS_ATTR(, block_size); | |
1018 | CONFIGFS_ATTR_RO(, hw_max_sectors); | |
1019 | CONFIGFS_ATTR(, optimal_sectors); | |
1020 | CONFIGFS_ATTR_RO(, hw_queue_depth); | |
1021 | CONFIGFS_ATTR(, queue_depth); | |
1022 | CONFIGFS_ATTR(, max_unmap_lba_count); | |
1023 | CONFIGFS_ATTR(, max_unmap_block_desc_count); | |
1024 | CONFIGFS_ATTR(, unmap_granularity); | |
1025 | CONFIGFS_ATTR(, unmap_granularity_alignment); | |
e6f41633 | 1026 | CONFIGFS_ATTR(, unmap_zeroes_data); |
2eafd729 | 1027 | CONFIGFS_ATTR(, max_write_same_len); |
c66ac9db | 1028 | |
5873c4d1 CH |
1029 | /* |
1030 | * dev_attrib attributes for devices using the target core SBC/SPC | |
1031 | * interpreter. Any backend using spc_parse_cdb should be using | |
1032 | * these. | |
1033 | */ | |
1034 | struct configfs_attribute *sbc_attrib_attrs[] = { | |
2eafd729 CH |
1035 | &attr_emulate_model_alias, |
1036 | &attr_emulate_dpo, | |
1037 | &attr_emulate_fua_write, | |
1038 | &attr_emulate_fua_read, | |
1039 | &attr_emulate_write_cache, | |
1040 | &attr_emulate_ua_intlck_ctrl, | |
1041 | &attr_emulate_tas, | |
1042 | &attr_emulate_tpu, | |
1043 | &attr_emulate_tpws, | |
1044 | &attr_emulate_caw, | |
1045 | &attr_emulate_3pc, | |
1046 | &attr_pi_prot_type, | |
1047 | &attr_hw_pi_prot_type, | |
1048 | &attr_pi_prot_format, | |
1049 | &attr_enforce_pr_isids, | |
1050 | &attr_is_nonrot, | |
1051 | &attr_emulate_rest_reord, | |
1052 | &attr_force_pr_aptpl, | |
1053 | &attr_hw_block_size, | |
1054 | &attr_block_size, | |
1055 | &attr_hw_max_sectors, | |
1056 | &attr_optimal_sectors, | |
1057 | &attr_hw_queue_depth, | |
1058 | &attr_queue_depth, | |
1059 | &attr_max_unmap_lba_count, | |
1060 | &attr_max_unmap_block_desc_count, | |
1061 | &attr_unmap_granularity, | |
1062 | &attr_unmap_granularity_alignment, | |
e6f41633 | 1063 | &attr_unmap_zeroes_data, |
2eafd729 | 1064 | &attr_max_write_same_len, |
5873c4d1 CH |
1065 | NULL, |
1066 | }; | |
1067 | EXPORT_SYMBOL(sbc_attrib_attrs); | |
1068 | ||
5873c4d1 CH |
1069 | /* |
1070 | * Minimal dev_attrib attributes for devices passing through CDBs. | |
1071 | * In this case we only provide a few read-only attributes for | |
1072 | * backwards compatibility. | |
1073 | */ | |
1074 | struct configfs_attribute *passthrough_attrib_attrs[] = { | |
2eafd729 CH |
1075 | &attr_hw_pi_prot_type, |
1076 | &attr_hw_block_size, | |
1077 | &attr_hw_max_sectors, | |
1078 | &attr_hw_queue_depth, | |
5873c4d1 CH |
1079 | NULL, |
1080 | }; | |
1081 | EXPORT_SYMBOL(passthrough_attrib_attrs); | |
1082 | ||
2eafd729 | 1083 | TB_CIT_SETUP_DRV(dev_attrib, NULL, NULL); |
c66ac9db | 1084 | |
f79a897e | 1085 | /* End functions for struct config_item_type tb_dev_attrib_cit */ |
c66ac9db | 1086 | |
f8d389c6 | 1087 | /* Start functions for struct config_item_type tb_dev_wwn_cit */ |
c66ac9db | 1088 | |
2eafd729 CH |
1089 | static struct t10_wwn *to_t10_wwn(struct config_item *item) |
1090 | { | |
1091 | return container_of(to_config_group(item), struct t10_wwn, t10_wwn_group); | |
1092 | } | |
c66ac9db NB |
1093 | |
1094 | /* | |
1095 | * VPD page 0x80 Unit serial | |
1096 | */ | |
2eafd729 CH |
1097 | static ssize_t target_wwn_vpd_unit_serial_show(struct config_item *item, |
1098 | char *page) | |
c66ac9db | 1099 | { |
c66ac9db | 1100 | return sprintf(page, "T10 VPD Unit Serial Number: %s\n", |
2eafd729 | 1101 | &to_t10_wwn(item)->unit_serial[0]); |
c66ac9db NB |
1102 | } |
1103 | ||
2eafd729 CH |
1104 | static ssize_t target_wwn_vpd_unit_serial_store(struct config_item *item, |
1105 | const char *page, size_t count) | |
c66ac9db | 1106 | { |
2eafd729 | 1107 | struct t10_wwn *t10_wwn = to_t10_wwn(item); |
0fd97ccf | 1108 | struct se_device *dev = t10_wwn->t10_dev; |
c66ac9db NB |
1109 | unsigned char buf[INQUIRY_VPD_SERIAL_LEN]; |
1110 | ||
1111 | /* | |
1112 | * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial | |
1113 | * from the struct scsi_device level firmware, do not allow | |
1114 | * VPD Unit Serial to be emulated. | |
1115 | * | |
1116 | * Note this struct scsi_device could also be emulating VPD | |
1117 | * information from its drivers/scsi LLD. But for now we assume | |
1118 | * it is doing 'the right thing' wrt a world wide unique | |
1119 | * VPD Unit Serial Number that OS dependent multipath can depend on. | |
1120 | */ | |
0fd97ccf | 1121 | if (dev->dev_flags & DF_FIRMWARE_VPD_UNIT_SERIAL) { |
6708bb27 | 1122 | pr_err("Underlying SCSI device firmware provided VPD" |
c66ac9db NB |
1123 | " Unit Serial, ignoring request\n"); |
1124 | return -EOPNOTSUPP; | |
1125 | } | |
1126 | ||
60d645a4 | 1127 | if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) { |
6708bb27 | 1128 | pr_err("Emulated VPD Unit Serial exceeds" |
c66ac9db NB |
1129 | " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN); |
1130 | return -EOVERFLOW; | |
1131 | } | |
1132 | /* | |
1133 | * Check to see if any active $FABRIC_MOD exports exist. If they | |
1134 | * do exist, fail here as changing this information on the fly | |
1135 | * (underneath the initiator side OS dependent multipath code) | |
1136 | * could cause negative effects. | |
1137 | */ | |
0fd97ccf CH |
1138 | if (dev->export_count) { |
1139 | pr_err("Unable to set VPD Unit Serial while" | |
1140 | " active %d $FABRIC_MOD exports exist\n", | |
1141 | dev->export_count); | |
1142 | return -EINVAL; | |
c66ac9db | 1143 | } |
0fd97ccf | 1144 | |
c66ac9db NB |
1145 | /* |
1146 | * This currently assumes ASCII encoding for emulated VPD Unit Serial. | |
1147 | * | |
1148 | * Also, strip any newline added from the userspace | |
1149 | * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial | |
1150 | */ | |
1151 | memset(buf, 0, INQUIRY_VPD_SERIAL_LEN); | |
1152 | snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page); | |
0fd97ccf | 1153 | snprintf(dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN, |
c66ac9db | 1154 | "%s", strstrip(buf)); |
0fd97ccf | 1155 | dev->dev_flags |= DF_EMULATED_VPD_UNIT_SERIAL; |
c66ac9db | 1156 | |
6708bb27 | 1157 | pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:" |
0fd97ccf | 1158 | " %s\n", dev->t10_wwn.unit_serial); |
c66ac9db NB |
1159 | |
1160 | return count; | |
1161 | } | |
1162 | ||
c66ac9db NB |
1163 | /* |
1164 | * VPD page 0x83 Protocol Identifier | |
1165 | */ | |
2eafd729 CH |
1166 | static ssize_t target_wwn_vpd_protocol_identifier_show(struct config_item *item, |
1167 | char *page) | |
c66ac9db | 1168 | { |
2eafd729 | 1169 | struct t10_wwn *t10_wwn = to_t10_wwn(item); |
c66ac9db NB |
1170 | struct t10_vpd *vpd; |
1171 | unsigned char buf[VPD_TMP_BUF_SIZE]; | |
1172 | ssize_t len = 0; | |
1173 | ||
c66ac9db NB |
1174 | memset(buf, 0, VPD_TMP_BUF_SIZE); |
1175 | ||
1176 | spin_lock(&t10_wwn->t10_vpd_lock); | |
1177 | list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { | |
6708bb27 | 1178 | if (!vpd->protocol_identifier_set) |
c66ac9db NB |
1179 | continue; |
1180 | ||
1181 | transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE); | |
1182 | ||
6708bb27 | 1183 | if (len + strlen(buf) >= PAGE_SIZE) |
c66ac9db NB |
1184 | break; |
1185 | ||
1186 | len += sprintf(page+len, "%s", buf); | |
1187 | } | |
1188 | spin_unlock(&t10_wwn->t10_vpd_lock); | |
1189 | ||
1190 | return len; | |
1191 | } | |
1192 | ||
c66ac9db NB |
1193 | /* |
1194 | * Generic wrapper for dumping VPD identifiers by association. | |
1195 | */ | |
1196 | #define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \ | |
2eafd729 CH |
1197 | static ssize_t target_wwn_##_name##_show(struct config_item *item, \ |
1198 | char *page) \ | |
c66ac9db | 1199 | { \ |
2eafd729 CH |
1200 | struct t10_wwn *t10_wwn = to_t10_wwn(item); \ |
1201 | struct t10_vpd *vpd; \ | |
c66ac9db NB |
1202 | unsigned char buf[VPD_TMP_BUF_SIZE]; \ |
1203 | ssize_t len = 0; \ | |
1204 | \ | |
c66ac9db NB |
1205 | spin_lock(&t10_wwn->t10_vpd_lock); \ |
1206 | list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \ | |
1207 | if (vpd->association != _assoc) \ | |
1208 | continue; \ | |
1209 | \ | |
1210 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ | |
1211 | transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \ | |
6708bb27 | 1212 | if (len + strlen(buf) >= PAGE_SIZE) \ |
c66ac9db NB |
1213 | break; \ |
1214 | len += sprintf(page+len, "%s", buf); \ | |
1215 | \ | |
1216 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ | |
1217 | transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \ | |
6708bb27 | 1218 | if (len + strlen(buf) >= PAGE_SIZE) \ |
c66ac9db NB |
1219 | break; \ |
1220 | len += sprintf(page+len, "%s", buf); \ | |
1221 | \ | |
1222 | memset(buf, 0, VPD_TMP_BUF_SIZE); \ | |
1223 | transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \ | |
6708bb27 | 1224 | if (len + strlen(buf) >= PAGE_SIZE) \ |
c66ac9db NB |
1225 | break; \ |
1226 | len += sprintf(page+len, "%s", buf); \ | |
1227 | } \ | |
1228 | spin_unlock(&t10_wwn->t10_vpd_lock); \ | |
1229 | \ | |
1230 | return len; \ | |
1231 | } | |
1232 | ||
2eafd729 | 1233 | /* VPD page 0x83 Association: Logical Unit */ |
c66ac9db | 1234 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00); |
2eafd729 | 1235 | /* VPD page 0x83 Association: Target Port */ |
c66ac9db | 1236 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); |
2eafd729 | 1237 | /* VPD page 0x83 Association: SCSI Target Device */ |
c66ac9db NB |
1238 | DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); |
1239 | ||
2eafd729 CH |
1240 | CONFIGFS_ATTR(target_wwn_, vpd_unit_serial); |
1241 | CONFIGFS_ATTR_RO(target_wwn_, vpd_protocol_identifier); | |
1242 | CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit); | |
1243 | CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_target_port); | |
1244 | CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_scsi_target_device); | |
c66ac9db NB |
1245 | |
1246 | static struct configfs_attribute *target_core_dev_wwn_attrs[] = { | |
2eafd729 CH |
1247 | &target_wwn_attr_vpd_unit_serial, |
1248 | &target_wwn_attr_vpd_protocol_identifier, | |
1249 | &target_wwn_attr_vpd_assoc_logical_unit, | |
1250 | &target_wwn_attr_vpd_assoc_target_port, | |
1251 | &target_wwn_attr_vpd_assoc_scsi_target_device, | |
c66ac9db NB |
1252 | NULL, |
1253 | }; | |
1254 | ||
2eafd729 | 1255 | TB_CIT_SETUP(dev_wwn, NULL, NULL, target_core_dev_wwn_attrs); |
c66ac9db | 1256 | |
f8d389c6 | 1257 | /* End functions for struct config_item_type tb_dev_wwn_cit */ |
c66ac9db | 1258 | |
91e2e39b | 1259 | /* Start functions for struct config_item_type tb_dev_pr_cit */ |
c66ac9db | 1260 | |
2eafd729 CH |
1261 | static struct se_device *pr_to_dev(struct config_item *item) |
1262 | { | |
1263 | return container_of(to_config_group(item), struct se_device, | |
1264 | dev_pr_group); | |
1265 | } | |
c66ac9db | 1266 | |
d977f437 CH |
1267 | static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, |
1268 | char *page) | |
c66ac9db NB |
1269 | { |
1270 | struct se_node_acl *se_nacl; | |
1271 | struct t10_pr_registration *pr_reg; | |
1272 | char i_buf[PR_REG_ISID_ID_LEN]; | |
c66ac9db NB |
1273 | |
1274 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); | |
1275 | ||
c66ac9db | 1276 | pr_reg = dev->dev_pr_res_holder; |
d977f437 CH |
1277 | if (!pr_reg) |
1278 | return sprintf(page, "No SPC-3 Reservation holder\n"); | |
1279 | ||
c66ac9db | 1280 | se_nacl = pr_reg->pr_reg_nacl; |
d2843c17 | 1281 | core_pr_dump_initiator_port(pr_reg, i_buf, PR_REG_ISID_ID_LEN); |
c66ac9db | 1282 | |
d977f437 | 1283 | return sprintf(page, "SPC-3 Reservation: %s Initiator: %s%s\n", |
e3d6f909 | 1284 | se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), |
d2843c17 | 1285 | se_nacl->initiatorname, i_buf); |
c66ac9db NB |
1286 | } |
1287 | ||
d977f437 CH |
1288 | static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev, |
1289 | char *page) | |
c66ac9db NB |
1290 | { |
1291 | struct se_node_acl *se_nacl; | |
d977f437 | 1292 | ssize_t len; |
c66ac9db | 1293 | |
c66ac9db | 1294 | se_nacl = dev->dev_reserved_node_acl; |
d977f437 CH |
1295 | if (se_nacl) { |
1296 | len = sprintf(page, | |
1297 | "SPC-2 Reservation: %s Initiator: %s\n", | |
1298 | se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(), | |
1299 | se_nacl->initiatorname); | |
1300 | } else { | |
1301 | len = sprintf(page, "No SPC-2 Reservation holder\n"); | |
c66ac9db | 1302 | } |
d977f437 | 1303 | return len; |
c66ac9db NB |
1304 | } |
1305 | ||
2eafd729 | 1306 | static ssize_t target_pr_res_holder_show(struct config_item *item, char *page) |
c66ac9db | 1307 | { |
2eafd729 | 1308 | struct se_device *dev = pr_to_dev(item); |
d977f437 | 1309 | int ret; |
c66ac9db | 1310 | |
a3541703 | 1311 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
d977f437 | 1312 | return sprintf(page, "Passthrough\n"); |
c66ac9db | 1313 | |
d977f437 CH |
1314 | spin_lock(&dev->dev_reservation_lock); |
1315 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) | |
1316 | ret = target_core_dev_pr_show_spc2_res(dev, page); | |
1317 | else | |
1318 | ret = target_core_dev_pr_show_spc3_res(dev, page); | |
1319 | spin_unlock(&dev->dev_reservation_lock); | |
1320 | return ret; | |
c66ac9db NB |
1321 | } |
1322 | ||
2eafd729 CH |
1323 | static ssize_t target_pr_res_pr_all_tgt_pts_show(struct config_item *item, |
1324 | char *page) | |
c66ac9db | 1325 | { |
2eafd729 | 1326 | struct se_device *dev = pr_to_dev(item); |
c66ac9db NB |
1327 | ssize_t len = 0; |
1328 | ||
c66ac9db | 1329 | spin_lock(&dev->dev_reservation_lock); |
d977f437 | 1330 | if (!dev->dev_pr_res_holder) { |
c66ac9db | 1331 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
d977f437 | 1332 | } else if (dev->dev_pr_res_holder->pr_reg_all_tg_pt) { |
c66ac9db NB |
1333 | len = sprintf(page, "SPC-3 Reservation: All Target" |
1334 | " Ports registration\n"); | |
d977f437 | 1335 | } else { |
c66ac9db NB |
1336 | len = sprintf(page, "SPC-3 Reservation: Single" |
1337 | " Target Port registration\n"); | |
d977f437 | 1338 | } |
c66ac9db | 1339 | |
d977f437 | 1340 | spin_unlock(&dev->dev_reservation_lock); |
c66ac9db NB |
1341 | return len; |
1342 | } | |
1343 | ||
2eafd729 CH |
1344 | static ssize_t target_pr_res_pr_generation_show(struct config_item *item, |
1345 | char *page) | |
c66ac9db | 1346 | { |
2eafd729 | 1347 | return sprintf(page, "0x%08x\n", pr_to_dev(item)->t10_pr.pr_generation); |
c66ac9db NB |
1348 | } |
1349 | ||
c66ac9db | 1350 | |
2eafd729 CH |
1351 | static ssize_t target_pr_res_pr_holder_tg_port_show(struct config_item *item, |
1352 | char *page) | |
c66ac9db | 1353 | { |
2eafd729 | 1354 | struct se_device *dev = pr_to_dev(item); |
c66ac9db | 1355 | struct se_node_acl *se_nacl; |
c66ac9db NB |
1356 | struct se_portal_group *se_tpg; |
1357 | struct t10_pr_registration *pr_reg; | |
9ac8928e | 1358 | const struct target_core_fabric_ops *tfo; |
c66ac9db NB |
1359 | ssize_t len = 0; |
1360 | ||
c66ac9db NB |
1361 | spin_lock(&dev->dev_reservation_lock); |
1362 | pr_reg = dev->dev_pr_res_holder; | |
6708bb27 | 1363 | if (!pr_reg) { |
c66ac9db | 1364 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
d977f437 | 1365 | goto out_unlock; |
c66ac9db | 1366 | } |
d977f437 | 1367 | |
c66ac9db NB |
1368 | se_nacl = pr_reg->pr_reg_nacl; |
1369 | se_tpg = se_nacl->se_tpg; | |
e3d6f909 | 1370 | tfo = se_tpg->se_tpg_tfo; |
c66ac9db NB |
1371 | |
1372 | len += sprintf(page+len, "SPC-3 Reservation: %s" | |
1373 | " Target Node Endpoint: %s\n", tfo->get_fabric_name(), | |
1374 | tfo->tpg_get_wwn(se_tpg)); | |
1375 | len += sprintf(page+len, "SPC-3 Reservation: Relative Port" | |
35d1efe8 | 1376 | " Identifier Tag: %hu %s Portal Group Tag: %hu" |
f2d30680 | 1377 | " %s Logical Unit: %llu\n", pr_reg->tg_pt_sep_rtpi, |
c66ac9db | 1378 | tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg), |
79dc9c9e | 1379 | tfo->get_fabric_name(), pr_reg->pr_aptpl_target_lun); |
c66ac9db | 1380 | |
d977f437 CH |
1381 | out_unlock: |
1382 | spin_unlock(&dev->dev_reservation_lock); | |
c66ac9db NB |
1383 | return len; |
1384 | } | |
1385 | ||
c66ac9db | 1386 | |
2eafd729 CH |
1387 | static ssize_t target_pr_res_pr_registered_i_pts_show(struct config_item *item, |
1388 | char *page) | |
c66ac9db | 1389 | { |
2eafd729 | 1390 | struct se_device *dev = pr_to_dev(item); |
9ac8928e | 1391 | const struct target_core_fabric_ops *tfo; |
c66ac9db NB |
1392 | struct t10_pr_registration *pr_reg; |
1393 | unsigned char buf[384]; | |
1394 | char i_buf[PR_REG_ISID_ID_LEN]; | |
1395 | ssize_t len = 0; | |
d2843c17 | 1396 | int reg_count = 0; |
c66ac9db | 1397 | |
c66ac9db NB |
1398 | len += sprintf(page+len, "SPC-3 PR Registrations:\n"); |
1399 | ||
0fd97ccf CH |
1400 | spin_lock(&dev->t10_pr.registration_lock); |
1401 | list_for_each_entry(pr_reg, &dev->t10_pr.registration_list, | |
c66ac9db NB |
1402 | pr_reg_list) { |
1403 | ||
1404 | memset(buf, 0, 384); | |
1405 | memset(i_buf, 0, PR_REG_ISID_ID_LEN); | |
1406 | tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo; | |
d2843c17 | 1407 | core_pr_dump_initiator_port(pr_reg, i_buf, |
c66ac9db NB |
1408 | PR_REG_ISID_ID_LEN); |
1409 | sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n", | |
1410 | tfo->get_fabric_name(), | |
d2843c17 | 1411 | pr_reg->pr_reg_nacl->initiatorname, i_buf, pr_reg->pr_res_key, |
c66ac9db NB |
1412 | pr_reg->pr_res_generation); |
1413 | ||
6708bb27 | 1414 | if (len + strlen(buf) >= PAGE_SIZE) |
c66ac9db NB |
1415 | break; |
1416 | ||
1417 | len += sprintf(page+len, "%s", buf); | |
1418 | reg_count++; | |
1419 | } | |
0fd97ccf | 1420 | spin_unlock(&dev->t10_pr.registration_lock); |
c66ac9db | 1421 | |
6708bb27 | 1422 | if (!reg_count) |
c66ac9db NB |
1423 | len += sprintf(page+len, "None\n"); |
1424 | ||
1425 | return len; | |
1426 | } | |
1427 | ||
2eafd729 | 1428 | static ssize_t target_pr_res_pr_type_show(struct config_item *item, char *page) |
c66ac9db | 1429 | { |
2eafd729 | 1430 | struct se_device *dev = pr_to_dev(item); |
c66ac9db NB |
1431 | struct t10_pr_registration *pr_reg; |
1432 | ssize_t len = 0; | |
1433 | ||
c66ac9db NB |
1434 | spin_lock(&dev->dev_reservation_lock); |
1435 | pr_reg = dev->dev_pr_res_holder; | |
d977f437 CH |
1436 | if (pr_reg) { |
1437 | len = sprintf(page, "SPC-3 Reservation Type: %s\n", | |
1438 | core_scsi3_pr_dump_type(pr_reg->pr_res_type)); | |
1439 | } else { | |
c66ac9db | 1440 | len = sprintf(page, "No SPC-3 Reservation holder\n"); |
c66ac9db | 1441 | } |
c66ac9db | 1442 | |
d977f437 | 1443 | spin_unlock(&dev->dev_reservation_lock); |
c66ac9db NB |
1444 | return len; |
1445 | } | |
1446 | ||
2eafd729 | 1447 | static ssize_t target_pr_res_type_show(struct config_item *item, char *page) |
c66ac9db | 1448 | { |
2eafd729 CH |
1449 | struct se_device *dev = pr_to_dev(item); |
1450 | ||
a3541703 | 1451 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
d977f437 CH |
1452 | return sprintf(page, "SPC_PASSTHROUGH\n"); |
1453 | else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) | |
1454 | return sprintf(page, "SPC2_RESERVATIONS\n"); | |
1455 | else | |
1456 | return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); | |
c66ac9db NB |
1457 | } |
1458 | ||
2eafd729 CH |
1459 | static ssize_t target_pr_res_aptpl_active_show(struct config_item *item, |
1460 | char *page) | |
c66ac9db | 1461 | { |
2eafd729 CH |
1462 | struct se_device *dev = pr_to_dev(item); |
1463 | ||
a3541703 | 1464 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
c66ac9db NB |
1465 | return 0; |
1466 | ||
1467 | return sprintf(page, "APTPL Bit Status: %s\n", | |
0fd97ccf | 1468 | (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); |
c66ac9db NB |
1469 | } |
1470 | ||
2eafd729 CH |
1471 | static ssize_t target_pr_res_aptpl_metadata_show(struct config_item *item, |
1472 | char *page) | |
c66ac9db | 1473 | { |
2eafd729 CH |
1474 | struct se_device *dev = pr_to_dev(item); |
1475 | ||
a3541703 | 1476 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
c66ac9db NB |
1477 | return 0; |
1478 | ||
1479 | return sprintf(page, "Ready to process PR APTPL metadata..\n"); | |
1480 | } | |
1481 | ||
1482 | enum { | |
1483 | Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid, | |
1484 | Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope, | |
1485 | Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric, | |
1486 | Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err | |
1487 | }; | |
1488 | ||
1489 | static match_table_t tokens = { | |
1490 | {Opt_initiator_fabric, "initiator_fabric=%s"}, | |
1491 | {Opt_initiator_node, "initiator_node=%s"}, | |
1492 | {Opt_initiator_sid, "initiator_sid=%s"}, | |
1493 | {Opt_sa_res_key, "sa_res_key=%s"}, | |
1494 | {Opt_res_holder, "res_holder=%d"}, | |
1495 | {Opt_res_type, "res_type=%d"}, | |
1496 | {Opt_res_scope, "res_scope=%d"}, | |
1497 | {Opt_res_all_tg_pt, "res_all_tg_pt=%d"}, | |
f2d30680 | 1498 | {Opt_mapped_lun, "mapped_lun=%lld"}, |
c66ac9db NB |
1499 | {Opt_target_fabric, "target_fabric=%s"}, |
1500 | {Opt_target_node, "target_node=%s"}, | |
1501 | {Opt_tpgt, "tpgt=%d"}, | |
1502 | {Opt_port_rtpi, "port_rtpi=%d"}, | |
f2d30680 | 1503 | {Opt_target_lun, "target_lun=%lld"}, |
c66ac9db NB |
1504 | {Opt_err, NULL} |
1505 | }; | |
1506 | ||
2eafd729 CH |
1507 | static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item, |
1508 | const char *page, size_t count) | |
c66ac9db | 1509 | { |
2eafd729 | 1510 | struct se_device *dev = pr_to_dev(item); |
6d180253 JJ |
1511 | unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; |
1512 | unsigned char *t_fabric = NULL, *t_port = NULL; | |
8d213559 | 1513 | char *orig, *ptr, *opts; |
c66ac9db NB |
1514 | substring_t args[MAX_OPT_ARGS]; |
1515 | unsigned long long tmp_ll; | |
1516 | u64 sa_res_key = 0; | |
f2d30680 | 1517 | u64 mapped_lun = 0, target_lun = 0; |
c66ac9db | 1518 | int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token; |
45fb94c2 BVA |
1519 | u16 tpgt = 0; |
1520 | u8 type = 0; | |
c66ac9db | 1521 | |
a3541703 | 1522 | if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) |
9105bfc0 | 1523 | return count; |
d977f437 | 1524 | if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) |
9105bfc0 | 1525 | return count; |
c66ac9db | 1526 | |
0fd97ccf | 1527 | if (dev->export_count) { |
6708bb27 | 1528 | pr_debug("Unable to process APTPL metadata while" |
c66ac9db NB |
1529 | " active fabric exports exist\n"); |
1530 | return -EINVAL; | |
1531 | } | |
1532 | ||
1533 | opts = kstrdup(page, GFP_KERNEL); | |
1534 | if (!opts) | |
1535 | return -ENOMEM; | |
1536 | ||
1537 | orig = opts; | |
90c161b6 | 1538 | while ((ptr = strsep(&opts, ",\n")) != NULL) { |
c66ac9db NB |
1539 | if (!*ptr) |
1540 | continue; | |
1541 | ||
1542 | token = match_token(ptr, tokens, args); | |
1543 | switch (token) { | |
1544 | case Opt_initiator_fabric: | |
8d213559 | 1545 | i_fabric = match_strdup(args); |
6d180253 JJ |
1546 | if (!i_fabric) { |
1547 | ret = -ENOMEM; | |
1548 | goto out; | |
1549 | } | |
c66ac9db NB |
1550 | break; |
1551 | case Opt_initiator_node: | |
8d213559 | 1552 | i_port = match_strdup(args); |
6d180253 JJ |
1553 | if (!i_port) { |
1554 | ret = -ENOMEM; | |
1555 | goto out; | |
1556 | } | |
60d645a4 | 1557 | if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) { |
6708bb27 | 1558 | pr_err("APTPL metadata initiator_node=" |
c66ac9db NB |
1559 | " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n", |
1560 | PR_APTPL_MAX_IPORT_LEN); | |
1561 | ret = -EINVAL; | |
1562 | break; | |
1563 | } | |
1564 | break; | |
1565 | case Opt_initiator_sid: | |
8d213559 | 1566 | isid = match_strdup(args); |
6d180253 JJ |
1567 | if (!isid) { |
1568 | ret = -ENOMEM; | |
1569 | goto out; | |
1570 | } | |
60d645a4 | 1571 | if (strlen(isid) >= PR_REG_ISID_LEN) { |
6708bb27 | 1572 | pr_err("APTPL metadata initiator_isid" |
c66ac9db NB |
1573 | "= exceeds PR_REG_ISID_LEN: %d\n", |
1574 | PR_REG_ISID_LEN); | |
1575 | ret = -EINVAL; | |
1576 | break; | |
1577 | } | |
1578 | break; | |
1579 | case Opt_sa_res_key: | |
8d213559 | 1580 | ret = kstrtoull(args->from, 0, &tmp_ll); |
c66ac9db | 1581 | if (ret < 0) { |
8d213559 | 1582 | pr_err("kstrtoull() failed for sa_res_key=\n"); |
c66ac9db NB |
1583 | goto out; |
1584 | } | |
1585 | sa_res_key = (u64)tmp_ll; | |
1586 | break; | |
1587 | /* | |
1588 | * PR APTPL Metadata for Reservation | |
1589 | */ | |
1590 | case Opt_res_holder: | |
c2091026 DD |
1591 | ret = match_int(args, &arg); |
1592 | if (ret) | |
1593 | goto out; | |
c66ac9db NB |
1594 | res_holder = arg; |
1595 | break; | |
1596 | case Opt_res_type: | |
c2091026 DD |
1597 | ret = match_int(args, &arg); |
1598 | if (ret) | |
1599 | goto out; | |
c66ac9db NB |
1600 | type = (u8)arg; |
1601 | break; | |
1602 | case Opt_res_scope: | |
c2091026 DD |
1603 | ret = match_int(args, &arg); |
1604 | if (ret) | |
1605 | goto out; | |
c66ac9db NB |
1606 | break; |
1607 | case Opt_res_all_tg_pt: | |
c2091026 DD |
1608 | ret = match_int(args, &arg); |
1609 | if (ret) | |
1610 | goto out; | |
c66ac9db NB |
1611 | all_tg_pt = (int)arg; |
1612 | break; | |
1613 | case Opt_mapped_lun: | |
c2091026 DD |
1614 | ret = match_int(args, &arg); |
1615 | if (ret) | |
1616 | goto out; | |
f2d30680 | 1617 | mapped_lun = (u64)arg; |
c66ac9db NB |
1618 | break; |
1619 | /* | |
1620 | * PR APTPL Metadata for Target Port | |
1621 | */ | |
1622 | case Opt_target_fabric: | |
8d213559 | 1623 | t_fabric = match_strdup(args); |
6d180253 JJ |
1624 | if (!t_fabric) { |
1625 | ret = -ENOMEM; | |
1626 | goto out; | |
1627 | } | |
c66ac9db NB |
1628 | break; |
1629 | case Opt_target_node: | |
8d213559 | 1630 | t_port = match_strdup(args); |
6d180253 JJ |
1631 | if (!t_port) { |
1632 | ret = -ENOMEM; | |
1633 | goto out; | |
1634 | } | |
60d645a4 | 1635 | if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) { |
6708bb27 | 1636 | pr_err("APTPL metadata target_node=" |
c66ac9db NB |
1637 | " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n", |
1638 | PR_APTPL_MAX_TPORT_LEN); | |
1639 | ret = -EINVAL; | |
1640 | break; | |
1641 | } | |
1642 | break; | |
1643 | case Opt_tpgt: | |
c2091026 DD |
1644 | ret = match_int(args, &arg); |
1645 | if (ret) | |
1646 | goto out; | |
c66ac9db NB |
1647 | tpgt = (u16)arg; |
1648 | break; | |
1649 | case Opt_port_rtpi: | |
c2091026 DD |
1650 | ret = match_int(args, &arg); |
1651 | if (ret) | |
1652 | goto out; | |
c66ac9db NB |
1653 | break; |
1654 | case Opt_target_lun: | |
c2091026 DD |
1655 | ret = match_int(args, &arg); |
1656 | if (ret) | |
1657 | goto out; | |
f2d30680 | 1658 | target_lun = (u64)arg; |
c66ac9db NB |
1659 | break; |
1660 | default: | |
1661 | break; | |
1662 | } | |
1663 | } | |
1664 | ||
6708bb27 AG |
1665 | if (!i_port || !t_port || !sa_res_key) { |
1666 | pr_err("Illegal parameters for APTPL registration\n"); | |
c66ac9db NB |
1667 | ret = -EINVAL; |
1668 | goto out; | |
1669 | } | |
1670 | ||
1671 | if (res_holder && !(type)) { | |
6708bb27 | 1672 | pr_err("Illegal PR type: 0x%02x for reservation" |
c66ac9db NB |
1673 | " holder\n", type); |
1674 | ret = -EINVAL; | |
1675 | goto out; | |
1676 | } | |
1677 | ||
0fd97ccf | 1678 | ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key, |
c66ac9db NB |
1679 | i_port, isid, mapped_lun, t_port, tpgt, target_lun, |
1680 | res_holder, all_tg_pt, type); | |
1681 | out: | |
6d180253 JJ |
1682 | kfree(i_fabric); |
1683 | kfree(i_port); | |
1684 | kfree(isid); | |
1685 | kfree(t_fabric); | |
1686 | kfree(t_port); | |
c66ac9db NB |
1687 | kfree(orig); |
1688 | return (ret == 0) ? count : ret; | |
1689 | } | |
1690 | ||
c66ac9db | 1691 | |
2eafd729 CH |
1692 | CONFIGFS_ATTR_RO(target_pr_, res_holder); |
1693 | CONFIGFS_ATTR_RO(target_pr_, res_pr_all_tgt_pts); | |
1694 | CONFIGFS_ATTR_RO(target_pr_, res_pr_generation); | |
1695 | CONFIGFS_ATTR_RO(target_pr_, res_pr_holder_tg_port); | |
1696 | CONFIGFS_ATTR_RO(target_pr_, res_pr_registered_i_pts); | |
1697 | CONFIGFS_ATTR_RO(target_pr_, res_pr_type); | |
1698 | CONFIGFS_ATTR_RO(target_pr_, res_type); | |
1699 | CONFIGFS_ATTR_RO(target_pr_, res_aptpl_active); | |
1700 | CONFIGFS_ATTR(target_pr_, res_aptpl_metadata); | |
c66ac9db NB |
1701 | |
1702 | static struct configfs_attribute *target_core_dev_pr_attrs[] = { | |
2eafd729 CH |
1703 | &target_pr_attr_res_holder, |
1704 | &target_pr_attr_res_pr_all_tgt_pts, | |
1705 | &target_pr_attr_res_pr_generation, | |
1706 | &target_pr_attr_res_pr_holder_tg_port, | |
1707 | &target_pr_attr_res_pr_registered_i_pts, | |
1708 | &target_pr_attr_res_pr_type, | |
1709 | &target_pr_attr_res_type, | |
1710 | &target_pr_attr_res_aptpl_active, | |
1711 | &target_pr_attr_res_aptpl_metadata, | |
c66ac9db NB |
1712 | NULL, |
1713 | }; | |
1714 | ||
2eafd729 | 1715 | TB_CIT_SETUP(dev_pr, NULL, NULL, target_core_dev_pr_attrs); |
c66ac9db | 1716 | |
91e2e39b | 1717 | /* End functions for struct config_item_type tb_dev_pr_cit */ |
c66ac9db | 1718 | |
73112edc | 1719 | /* Start functions for struct config_item_type tb_dev_cit */ |
c66ac9db | 1720 | |
2eafd729 CH |
1721 | static inline struct se_device *to_device(struct config_item *item) |
1722 | { | |
1723 | return container_of(to_config_group(item), struct se_device, dev_group); | |
1724 | } | |
1725 | ||
1726 | static ssize_t target_dev_info_show(struct config_item *item, char *page) | |
c66ac9db | 1727 | { |
2eafd729 | 1728 | struct se_device *dev = to_device(item); |
c66ac9db NB |
1729 | int bl = 0; |
1730 | ssize_t read_bytes = 0; | |
1731 | ||
0fd97ccf | 1732 | transport_dump_dev_state(dev, page, &bl); |
c66ac9db | 1733 | read_bytes += bl; |
0a06d430 CH |
1734 | read_bytes += dev->transport->show_configfs_dev_params(dev, |
1735 | page+read_bytes); | |
c66ac9db NB |
1736 | return read_bytes; |
1737 | } | |
1738 | ||
2eafd729 CH |
1739 | static ssize_t target_dev_control_store(struct config_item *item, |
1740 | const char *page, size_t count) | |
c66ac9db | 1741 | { |
2eafd729 | 1742 | struct se_device *dev = to_device(item); |
c66ac9db | 1743 | |
0a06d430 | 1744 | return dev->transport->set_configfs_dev_params(dev, page, count); |
c66ac9db NB |
1745 | } |
1746 | ||
2eafd729 | 1747 | static ssize_t target_dev_alias_show(struct config_item *item, char *page) |
c66ac9db | 1748 | { |
2eafd729 | 1749 | struct se_device *dev = to_device(item); |
c66ac9db | 1750 | |
0fd97ccf | 1751 | if (!(dev->dev_flags & DF_USING_ALIAS)) |
c66ac9db NB |
1752 | return 0; |
1753 | ||
0fd97ccf | 1754 | return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); |
c66ac9db NB |
1755 | } |
1756 | ||
2eafd729 CH |
1757 | static ssize_t target_dev_alias_store(struct config_item *item, |
1758 | const char *page, size_t count) | |
c66ac9db | 1759 | { |
2eafd729 | 1760 | struct se_device *dev = to_device(item); |
0fd97ccf | 1761 | struct se_hba *hba = dev->se_hba; |
c66ac9db NB |
1762 | ssize_t read_bytes; |
1763 | ||
1764 | if (count > (SE_DEV_ALIAS_LEN-1)) { | |
6708bb27 | 1765 | pr_err("alias count: %d exceeds" |
c66ac9db NB |
1766 | " SE_DEV_ALIAS_LEN-1: %u\n", (int)count, |
1767 | SE_DEV_ALIAS_LEN-1); | |
1768 | return -EINVAL; | |
1769 | } | |
1770 | ||
0fd97ccf | 1771 | read_bytes = snprintf(&dev->dev_alias[0], SE_DEV_ALIAS_LEN, "%s", page); |
3011684c DC |
1772 | if (!read_bytes) |
1773 | return -EINVAL; | |
0fd97ccf CH |
1774 | if (dev->dev_alias[read_bytes - 1] == '\n') |
1775 | dev->dev_alias[read_bytes - 1] = '\0'; | |
0877eafd | 1776 | |
0fd97ccf | 1777 | dev->dev_flags |= DF_USING_ALIAS; |
3011684c | 1778 | |
6708bb27 | 1779 | pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n", |
c66ac9db | 1780 | config_item_name(&hba->hba_group.cg_item), |
0fd97ccf CH |
1781 | config_item_name(&dev->dev_group.cg_item), |
1782 | dev->dev_alias); | |
c66ac9db NB |
1783 | |
1784 | return read_bytes; | |
1785 | } | |
1786 | ||
2eafd729 | 1787 | static ssize_t target_dev_udev_path_show(struct config_item *item, char *page) |
c66ac9db | 1788 | { |
2eafd729 | 1789 | struct se_device *dev = to_device(item); |
c66ac9db | 1790 | |
0fd97ccf | 1791 | if (!(dev->dev_flags & DF_USING_UDEV_PATH)) |
c66ac9db NB |
1792 | return 0; |
1793 | ||
0fd97ccf | 1794 | return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); |
c66ac9db NB |
1795 | } |
1796 | ||
2eafd729 CH |
1797 | static ssize_t target_dev_udev_path_store(struct config_item *item, |
1798 | const char *page, size_t count) | |
c66ac9db | 1799 | { |
2eafd729 | 1800 | struct se_device *dev = to_device(item); |
0fd97ccf | 1801 | struct se_hba *hba = dev->se_hba; |
c66ac9db NB |
1802 | ssize_t read_bytes; |
1803 | ||
1804 | if (count > (SE_UDEV_PATH_LEN-1)) { | |
6708bb27 | 1805 | pr_err("udev_path count: %d exceeds" |
c66ac9db NB |
1806 | " SE_UDEV_PATH_LEN-1: %u\n", (int)count, |
1807 | SE_UDEV_PATH_LEN-1); | |
1808 | return -EINVAL; | |
1809 | } | |
1810 | ||
0fd97ccf | 1811 | read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN, |
c66ac9db | 1812 | "%s", page); |
3011684c DC |
1813 | if (!read_bytes) |
1814 | return -EINVAL; | |
0fd97ccf CH |
1815 | if (dev->udev_path[read_bytes - 1] == '\n') |
1816 | dev->udev_path[read_bytes - 1] = '\0'; | |
0877eafd | 1817 | |
0fd97ccf | 1818 | dev->dev_flags |= DF_USING_UDEV_PATH; |
3011684c | 1819 | |
6708bb27 | 1820 | pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n", |
c66ac9db | 1821 | config_item_name(&hba->hba_group.cg_item), |
0fd97ccf CH |
1822 | config_item_name(&dev->dev_group.cg_item), |
1823 | dev->udev_path); | |
c66ac9db NB |
1824 | |
1825 | return read_bytes; | |
1826 | } | |
1827 | ||
2eafd729 | 1828 | static ssize_t target_dev_enable_show(struct config_item *item, char *page) |
64146db7 | 1829 | { |
2eafd729 | 1830 | struct se_device *dev = to_device(item); |
64146db7 AG |
1831 | |
1832 | return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); | |
1833 | } | |
1834 | ||
2eafd729 CH |
1835 | static ssize_t target_dev_enable_store(struct config_item *item, |
1836 | const char *page, size_t count) | |
c66ac9db | 1837 | { |
2eafd729 | 1838 | struct se_device *dev = to_device(item); |
c66ac9db | 1839 | char *ptr; |
0fd97ccf | 1840 | int ret; |
c66ac9db NB |
1841 | |
1842 | ptr = strstr(page, "1"); | |
6708bb27 AG |
1843 | if (!ptr) { |
1844 | pr_err("For dev_enable ops, only valid value" | |
c66ac9db NB |
1845 | " is \"1\"\n"); |
1846 | return -EINVAL; | |
1847 | } | |
c66ac9db | 1848 | |
0fd97ccf CH |
1849 | ret = target_configure_device(dev); |
1850 | if (ret) | |
1851 | return ret; | |
c66ac9db NB |
1852 | return count; |
1853 | } | |
1854 | ||
2eafd729 | 1855 | static ssize_t target_dev_alua_lu_gp_show(struct config_item *item, char *page) |
c66ac9db | 1856 | { |
2eafd729 | 1857 | struct se_device *dev = to_device(item); |
c66ac9db NB |
1858 | struct config_item *lu_ci; |
1859 | struct t10_alua_lu_gp *lu_gp; | |
1860 | struct t10_alua_lu_gp_member *lu_gp_mem; | |
1861 | ssize_t len = 0; | |
1862 | ||
c66ac9db | 1863 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
c87fbd56 CH |
1864 | if (!lu_gp_mem) |
1865 | return 0; | |
c66ac9db NB |
1866 | |
1867 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); | |
1868 | lu_gp = lu_gp_mem->lu_gp; | |
6708bb27 | 1869 | if (lu_gp) { |
c66ac9db NB |
1870 | lu_ci = &lu_gp->lu_gp_group.cg_item; |
1871 | len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n", | |
1872 | config_item_name(lu_ci), lu_gp->lu_gp_id); | |
1873 | } | |
1874 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); | |
1875 | ||
1876 | return len; | |
1877 | } | |
1878 | ||
2eafd729 CH |
1879 | static ssize_t target_dev_alua_lu_gp_store(struct config_item *item, |
1880 | const char *page, size_t count) | |
c66ac9db | 1881 | { |
2eafd729 | 1882 | struct se_device *dev = to_device(item); |
0fd97ccf | 1883 | struct se_hba *hba = dev->se_hba; |
c66ac9db NB |
1884 | struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; |
1885 | struct t10_alua_lu_gp_member *lu_gp_mem; | |
1886 | unsigned char buf[LU_GROUP_NAME_BUF]; | |
1887 | int move = 0; | |
1888 | ||
c87fbd56 CH |
1889 | lu_gp_mem = dev->dev_alua_lu_gp_mem; |
1890 | if (!lu_gp_mem) | |
9105bfc0 | 1891 | return count; |
c87fbd56 | 1892 | |
c66ac9db | 1893 | if (count > LU_GROUP_NAME_BUF) { |
6708bb27 | 1894 | pr_err("ALUA LU Group Alias too large!\n"); |
c66ac9db NB |
1895 | return -EINVAL; |
1896 | } | |
1897 | memset(buf, 0, LU_GROUP_NAME_BUF); | |
1898 | memcpy(buf, page, count); | |
1899 | /* | |
1900 | * Any ALUA logical unit alias besides "NULL" means we will be | |
1901 | * making a new group association. | |
1902 | */ | |
1903 | if (strcmp(strstrip(buf), "NULL")) { | |
1904 | /* | |
1905 | * core_alua_get_lu_gp_by_name() will increment reference to | |
1906 | * struct t10_alua_lu_gp. This reference is released with | |
1907 | * core_alua_get_lu_gp_by_name below(). | |
1908 | */ | |
1909 | lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf)); | |
6708bb27 | 1910 | if (!lu_gp_new) |
c66ac9db NB |
1911 | return -ENODEV; |
1912 | } | |
c66ac9db NB |
1913 | |
1914 | spin_lock(&lu_gp_mem->lu_gp_mem_lock); | |
1915 | lu_gp = lu_gp_mem->lu_gp; | |
6708bb27 | 1916 | if (lu_gp) { |
c66ac9db NB |
1917 | /* |
1918 | * Clearing an existing lu_gp association, and replacing | |
1919 | * with NULL | |
1920 | */ | |
6708bb27 AG |
1921 | if (!lu_gp_new) { |
1922 | pr_debug("Target_Core_ConfigFS: Releasing %s/%s" | |
c66ac9db NB |
1923 | " from ALUA LU Group: core/alua/lu_gps/%s, ID:" |
1924 | " %hu\n", | |
1925 | config_item_name(&hba->hba_group.cg_item), | |
0fd97ccf | 1926 | config_item_name(&dev->dev_group.cg_item), |
c66ac9db NB |
1927 | config_item_name(&lu_gp->lu_gp_group.cg_item), |
1928 | lu_gp->lu_gp_id); | |
1929 | ||
1930 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); | |
1931 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); | |
1932 | ||
1933 | return count; | |
1934 | } | |
1935 | /* | |
1936 | * Removing existing association of lu_gp_mem with lu_gp | |
1937 | */ | |
1938 | __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp); | |
1939 | move = 1; | |
1940 | } | |
1941 | /* | |
1942 | * Associate lu_gp_mem with lu_gp_new. | |
1943 | */ | |
1944 | __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new); | |
1945 | spin_unlock(&lu_gp_mem->lu_gp_mem_lock); | |
1946 | ||
6708bb27 | 1947 | pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:" |
c66ac9db NB |
1948 | " core/alua/lu_gps/%s, ID: %hu\n", |
1949 | (move) ? "Moving" : "Adding", | |
1950 | config_item_name(&hba->hba_group.cg_item), | |
0fd97ccf | 1951 | config_item_name(&dev->dev_group.cg_item), |
c66ac9db NB |
1952 | config_item_name(&lu_gp_new->lu_gp_group.cg_item), |
1953 | lu_gp_new->lu_gp_id); | |
1954 | ||
1955 | core_alua_put_lu_gp_from_name(lu_gp_new); | |
1956 | return count; | |
1957 | } | |
1958 | ||
2eafd729 | 1959 | static ssize_t target_dev_lba_map_show(struct config_item *item, char *page) |
229d4f11 | 1960 | { |
2eafd729 | 1961 | struct se_device *dev = to_device(item); |
229d4f11 HR |
1962 | struct t10_alua_lba_map *map; |
1963 | struct t10_alua_lba_map_member *mem; | |
1964 | char *b = page; | |
1965 | int bl = 0; | |
1966 | char state; | |
1967 | ||
1968 | spin_lock(&dev->t10_alua.lba_map_lock); | |
1969 | if (!list_empty(&dev->t10_alua.lba_map_list)) | |
1970 | bl += sprintf(b + bl, "%u %u\n", | |
1971 | dev->t10_alua.lba_map_segment_size, | |
1972 | dev->t10_alua.lba_map_segment_multiplier); | |
1973 | list_for_each_entry(map, &dev->t10_alua.lba_map_list, lba_map_list) { | |
1974 | bl += sprintf(b + bl, "%llu %llu", | |
1975 | map->lba_map_first_lba, map->lba_map_last_lba); | |
1976 | list_for_each_entry(mem, &map->lba_map_mem_list, | |
1977 | lba_map_mem_list) { | |
1978 | switch (mem->lba_map_mem_alua_state) { | |
1979 | case ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED: | |
1980 | state = 'O'; | |
1981 | break; | |
1982 | case ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED: | |
1983 | state = 'A'; | |
1984 | break; | |
1985 | case ALUA_ACCESS_STATE_STANDBY: | |
1986 | state = 'S'; | |
1987 | break; | |
1988 | case ALUA_ACCESS_STATE_UNAVAILABLE: | |
1989 | state = 'U'; | |
1990 | break; | |
1991 | default: | |
1992 | state = '.'; | |
1993 | break; | |
1994 | } | |
1995 | bl += sprintf(b + bl, " %d:%c", | |
1996 | mem->lba_map_mem_alua_pg_id, state); | |
1997 | } | |
1998 | bl += sprintf(b + bl, "\n"); | |
1999 | } | |
2000 | spin_unlock(&dev->t10_alua.lba_map_lock); | |
2001 | return bl; | |
2002 | } | |
2003 | ||
2eafd729 CH |
2004 | static ssize_t target_dev_lba_map_store(struct config_item *item, |
2005 | const char *page, size_t count) | |
229d4f11 | 2006 | { |
2eafd729 | 2007 | struct se_device *dev = to_device(item); |
229d4f11 HR |
2008 | struct t10_alua_lba_map *lba_map = NULL; |
2009 | struct list_head lba_list; | |
f0a8afec | 2010 | char *map_entries, *orig, *ptr; |
229d4f11 HR |
2011 | char state; |
2012 | int pg_num = -1, pg; | |
2013 | int ret = 0, num = 0, pg_id, alua_state; | |
2014 | unsigned long start_lba = -1, end_lba = -1; | |
2015 | unsigned long segment_size = -1, segment_mult = -1; | |
2016 | ||
f0a8afec | 2017 | orig = map_entries = kstrdup(page, GFP_KERNEL); |
229d4f11 HR |
2018 | if (!map_entries) |
2019 | return -ENOMEM; | |
2020 | ||
2021 | INIT_LIST_HEAD(&lba_list); | |
2022 | while ((ptr = strsep(&map_entries, "\n")) != NULL) { | |
2023 | if (!*ptr) | |
2024 | continue; | |
2025 | ||
2026 | if (num == 0) { | |
2027 | if (sscanf(ptr, "%lu %lu\n", | |
2028 | &segment_size, &segment_mult) != 2) { | |
2029 | pr_err("Invalid line %d\n", num); | |
2030 | ret = -EINVAL; | |
2031 | break; | |
2032 | } | |
2033 | num++; | |
2034 | continue; | |
2035 | } | |
2036 | if (sscanf(ptr, "%lu %lu", &start_lba, &end_lba) != 2) { | |
2037 | pr_err("Invalid line %d\n", num); | |
2038 | ret = -EINVAL; | |
2039 | break; | |
2040 | } | |
2041 | ptr = strchr(ptr, ' '); | |
2042 | if (!ptr) { | |
2043 | pr_err("Invalid line %d, missing end lba\n", num); | |
2044 | ret = -EINVAL; | |
2045 | break; | |
2046 | } | |
2047 | ptr++; | |
2048 | ptr = strchr(ptr, ' '); | |
2049 | if (!ptr) { | |
2050 | pr_err("Invalid line %d, missing state definitions\n", | |
2051 | num); | |
2052 | ret = -EINVAL; | |
2053 | break; | |
2054 | } | |
2055 | ptr++; | |
2056 | lba_map = core_alua_allocate_lba_map(&lba_list, | |
2057 | start_lba, end_lba); | |
2058 | if (IS_ERR(lba_map)) { | |
2059 | ret = PTR_ERR(lba_map); | |
2060 | break; | |
2061 | } | |
2062 | pg = 0; | |
2063 | while (sscanf(ptr, "%d:%c", &pg_id, &state) == 2) { | |
2064 | switch (state) { | |
2065 | case 'O': | |
2066 | alua_state = ALUA_ACCESS_STATE_ACTIVE_OPTIMIZED; | |
2067 | break; | |
2068 | case 'A': | |
2069 | alua_state = ALUA_ACCESS_STATE_ACTIVE_NON_OPTIMIZED; | |
2070 | break; | |
2071 | case 'S': | |
2072 | alua_state = ALUA_ACCESS_STATE_STANDBY; | |
2073 | break; | |
2074 | case 'U': | |
2075 | alua_state = ALUA_ACCESS_STATE_UNAVAILABLE; | |
2076 | break; | |
2077 | default: | |
2078 | pr_err("Invalid ALUA state '%c'\n", state); | |
2079 | ret = -EINVAL; | |
2080 | goto out; | |
2081 | } | |
2082 | ||
2083 | ret = core_alua_allocate_lba_map_mem(lba_map, | |
2084 | pg_id, alua_state); | |
2085 | if (ret) { | |
2086 | pr_err("Invalid target descriptor %d:%c " | |
2087 | "at line %d\n", | |
2088 | pg_id, state, num); | |
2089 | break; | |
2090 | } | |
2091 | pg++; | |
2092 | ptr = strchr(ptr, ' '); | |
2093 | if (ptr) | |
2094 | ptr++; | |
2095 | else | |
2096 | break; | |
2097 | } | |
2098 | if (pg_num == -1) | |
2099 | pg_num = pg; | |
2100 | else if (pg != pg_num) { | |
2101 | pr_err("Only %d from %d port groups definitions " | |
2102 | "at line %d\n", pg, pg_num, num); | |
2103 | ret = -EINVAL; | |
2104 | break; | |
2105 | } | |
2106 | num++; | |
2107 | } | |
2108 | out: | |
2109 | if (ret) { | |
2110 | core_alua_free_lba_map(&lba_list); | |
2111 | count = ret; | |
2112 | } else | |
2113 | core_alua_set_lba_map(dev, &lba_list, | |
2114 | segment_size, segment_mult); | |
f0a8afec | 2115 | kfree(orig); |
229d4f11 HR |
2116 | return count; |
2117 | } | |
2118 | ||
2eafd729 CH |
2119 | CONFIGFS_ATTR_RO(target_dev_, info); |
2120 | CONFIGFS_ATTR_WO(target_dev_, control); | |
2121 | CONFIGFS_ATTR(target_dev_, alias); | |
2122 | CONFIGFS_ATTR(target_dev_, udev_path); | |
2123 | CONFIGFS_ATTR(target_dev_, enable); | |
2124 | CONFIGFS_ATTR(target_dev_, alua_lu_gp); | |
2125 | CONFIGFS_ATTR(target_dev_, lba_map); | |
229d4f11 | 2126 | |
73112edc | 2127 | static struct configfs_attribute *target_core_dev_attrs[] = { |
2eafd729 CH |
2128 | &target_dev_attr_info, |
2129 | &target_dev_attr_control, | |
2130 | &target_dev_attr_alias, | |
2131 | &target_dev_attr_udev_path, | |
2132 | &target_dev_attr_enable, | |
2133 | &target_dev_attr_alua_lu_gp, | |
2134 | &target_dev_attr_lba_map, | |
c66ac9db NB |
2135 | NULL, |
2136 | }; | |
2137 | ||
2138 | static void target_core_dev_release(struct config_item *item) | |
2139 | { | |
0fd97ccf CH |
2140 | struct config_group *dev_cg = to_config_group(item); |
2141 | struct se_device *dev = | |
2142 | container_of(dev_cg, struct se_device, dev_group); | |
c66ac9db | 2143 | |
0fd97ccf | 2144 | target_free_device(dev); |
c66ac9db NB |
2145 | } |
2146 | ||
c66ac9db NB |
2147 | static struct configfs_item_operations target_core_dev_item_ops = { |
2148 | .release = target_core_dev_release, | |
c66ac9db NB |
2149 | }; |
2150 | ||
73112edc | 2151 | TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs); |
c66ac9db | 2152 | |
73112edc | 2153 | /* End functions for struct config_item_type tb_dev_cit */ |
c66ac9db NB |
2154 | |
2155 | /* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ | |
2156 | ||
2eafd729 CH |
2157 | static inline struct t10_alua_lu_gp *to_lu_gp(struct config_item *item) |
2158 | { | |
2159 | return container_of(to_config_group(item), struct t10_alua_lu_gp, | |
2160 | lu_gp_group); | |
2161 | } | |
c66ac9db | 2162 | |
2eafd729 | 2163 | static ssize_t target_lu_gp_lu_gp_id_show(struct config_item *item, char *page) |
c66ac9db | 2164 | { |
2eafd729 CH |
2165 | struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); |
2166 | ||
6708bb27 | 2167 | if (!lu_gp->lu_gp_valid_id) |
c66ac9db | 2168 | return 0; |
c66ac9db NB |
2169 | return sprintf(page, "%hu\n", lu_gp->lu_gp_id); |
2170 | } | |
2171 | ||
2eafd729 CH |
2172 | static ssize_t target_lu_gp_lu_gp_id_store(struct config_item *item, |
2173 | const char *page, size_t count) | |
c66ac9db | 2174 | { |
2eafd729 | 2175 | struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); |
c66ac9db NB |
2176 | struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; |
2177 | unsigned long lu_gp_id; | |
2178 | int ret; | |
2179 | ||
57103d7f | 2180 | ret = kstrtoul(page, 0, &lu_gp_id); |
c66ac9db | 2181 | if (ret < 0) { |
57103d7f | 2182 | pr_err("kstrtoul() returned %d for" |
c66ac9db | 2183 | " lu_gp_id\n", ret); |
57103d7f | 2184 | return ret; |
c66ac9db NB |
2185 | } |
2186 | if (lu_gp_id > 0x0000ffff) { | |
6708bb27 | 2187 | pr_err("ALUA lu_gp_id: %lu exceeds maximum:" |
c66ac9db NB |
2188 | " 0x0000ffff\n", lu_gp_id); |
2189 | return -EINVAL; | |
2190 | } | |
2191 | ||
2192 | ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id); | |
2193 | if (ret < 0) | |
2194 | return -EINVAL; | |
2195 | ||
6708bb27 | 2196 | pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit" |
c66ac9db NB |
2197 | " Group: core/alua/lu_gps/%s to ID: %hu\n", |
2198 | config_item_name(&alua_lu_gp_cg->cg_item), | |
2199 | lu_gp->lu_gp_id); | |
2200 | ||
2201 | return count; | |
2202 | } | |
2203 | ||
2eafd729 | 2204 | static ssize_t target_lu_gp_members_show(struct config_item *item, char *page) |
c66ac9db | 2205 | { |
2eafd729 | 2206 | struct t10_alua_lu_gp *lu_gp = to_lu_gp(item); |
c66ac9db NB |
2207 | struct se_device *dev; |
2208 | struct se_hba *hba; | |
c66ac9db NB |
2209 | struct t10_alua_lu_gp_member *lu_gp_mem; |
2210 | ssize_t len = 0, cur_len; | |
2211 | unsigned char buf[LU_GROUP_NAME_BUF]; | |
2212 | ||
2213 | memset(buf, 0, LU_GROUP_NAME_BUF); | |
2214 | ||
2215 | spin_lock(&lu_gp->lu_gp_lock); | |
2216 | list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) { | |
2217 | dev = lu_gp_mem->lu_gp_mem_dev; | |
0fd97ccf | 2218 | hba = dev->se_hba; |
c66ac9db NB |
2219 | |
2220 | cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n", | |
2221 | config_item_name(&hba->hba_group.cg_item), | |
0fd97ccf | 2222 | config_item_name(&dev->dev_group.cg_item)); |
c66ac9db NB |
2223 | cur_len++; /* Extra byte for NULL terminator */ |
2224 | ||
2225 | if ((cur_len + len) > PAGE_SIZE) { | |
6708bb27 | 2226 | pr_warn("Ran out of lu_gp_show_attr" |
c66ac9db NB |
2227 | "_members buffer\n"); |
2228 | break; | |
2229 | } | |
2230 | memcpy(page+len, buf, cur_len); | |
2231 | len += cur_len; | |
2232 | } | |
2233 | spin_unlock(&lu_gp->lu_gp_lock); | |
2234 | ||
2235 | return len; | |
2236 | } | |
2237 | ||
2eafd729 CH |
2238 | CONFIGFS_ATTR(target_lu_gp_, lu_gp_id); |
2239 | CONFIGFS_ATTR_RO(target_lu_gp_, members); | |
c66ac9db NB |
2240 | |
2241 | static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { | |
2eafd729 CH |
2242 | &target_lu_gp_attr_lu_gp_id, |
2243 | &target_lu_gp_attr_members, | |
c66ac9db NB |
2244 | NULL, |
2245 | }; | |
2246 | ||
1f6fe7cb NB |
2247 | static void target_core_alua_lu_gp_release(struct config_item *item) |
2248 | { | |
2249 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), | |
2250 | struct t10_alua_lu_gp, lu_gp_group); | |
2251 | ||
2252 | core_alua_free_lu_gp(lu_gp); | |
2253 | } | |
2254 | ||
c66ac9db | 2255 | static struct configfs_item_operations target_core_alua_lu_gp_ops = { |
1f6fe7cb | 2256 | .release = target_core_alua_lu_gp_release, |
c66ac9db NB |
2257 | }; |
2258 | ||
2259 | static struct config_item_type target_core_alua_lu_gp_cit = { | |
2260 | .ct_item_ops = &target_core_alua_lu_gp_ops, | |
2261 | .ct_attrs = target_core_alua_lu_gp_attrs, | |
2262 | .ct_owner = THIS_MODULE, | |
2263 | }; | |
2264 | ||
2265 | /* End functions for struct config_item_type target_core_alua_lu_gp_cit */ | |
2266 | ||
2267 | /* Start functions for struct config_item_type target_core_alua_lu_gps_cit */ | |
2268 | ||
2269 | static struct config_group *target_core_alua_create_lu_gp( | |
2270 | struct config_group *group, | |
2271 | const char *name) | |
2272 | { | |
2273 | struct t10_alua_lu_gp *lu_gp; | |
2274 | struct config_group *alua_lu_gp_cg = NULL; | |
2275 | struct config_item *alua_lu_gp_ci = NULL; | |
2276 | ||
2277 | lu_gp = core_alua_allocate_lu_gp(name, 0); | |
2278 | if (IS_ERR(lu_gp)) | |
2279 | return NULL; | |
2280 | ||
2281 | alua_lu_gp_cg = &lu_gp->lu_gp_group; | |
2282 | alua_lu_gp_ci = &alua_lu_gp_cg->cg_item; | |
2283 | ||
2284 | config_group_init_type_name(alua_lu_gp_cg, name, | |
2285 | &target_core_alua_lu_gp_cit); | |
2286 | ||
6708bb27 | 2287 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit" |
c66ac9db NB |
2288 | " Group: core/alua/lu_gps/%s\n", |
2289 | config_item_name(alua_lu_gp_ci)); | |
2290 | ||
2291 | return alua_lu_gp_cg; | |
2292 | ||
2293 | } | |
2294 | ||
2295 | static void target_core_alua_drop_lu_gp( | |
2296 | struct config_group *group, | |
2297 | struct config_item *item) | |
2298 | { | |
2299 | struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item), | |
2300 | struct t10_alua_lu_gp, lu_gp_group); | |
2301 | ||
6708bb27 | 2302 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit" |
c66ac9db NB |
2303 | " Group: core/alua/lu_gps/%s, ID: %hu\n", |
2304 | config_item_name(item), lu_gp->lu_gp_id); | |
1f6fe7cb NB |
2305 | /* |
2306 | * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release() | |
2307 | * -> target_core_alua_lu_gp_release() | |
2308 | */ | |
c66ac9db | 2309 | config_item_put(item); |
c66ac9db NB |
2310 | } |
2311 | ||
2312 | static struct configfs_group_operations target_core_alua_lu_gps_group_ops = { | |
2313 | .make_group = &target_core_alua_create_lu_gp, | |
2314 | .drop_item = &target_core_alua_drop_lu_gp, | |
2315 | }; | |
2316 | ||
2317 | static struct config_item_type target_core_alua_lu_gps_cit = { | |
2318 | .ct_item_ops = NULL, | |
2319 | .ct_group_ops = &target_core_alua_lu_gps_group_ops, | |
2320 | .ct_owner = THIS_MODULE, | |
2321 | }; | |
2322 | ||
2323 | /* End functions for struct config_item_type target_core_alua_lu_gps_cit */ | |
2324 | ||
2325 | /* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ | |
2326 | ||
2eafd729 CH |
2327 | static inline struct t10_alua_tg_pt_gp *to_tg_pt_gp(struct config_item *item) |
2328 | { | |
2329 | return container_of(to_config_group(item), struct t10_alua_tg_pt_gp, | |
2330 | tg_pt_gp_group); | |
2331 | } | |
c66ac9db | 2332 | |
2eafd729 CH |
2333 | static ssize_t target_tg_pt_gp_alua_access_state_show(struct config_item *item, |
2334 | char *page) | |
c66ac9db NB |
2335 | { |
2336 | return sprintf(page, "%d\n", | |
2eafd729 | 2337 | atomic_read(&to_tg_pt_gp(item)->tg_pt_gp_alua_access_state)); |
c66ac9db NB |
2338 | } |
2339 | ||
2eafd729 CH |
2340 | static ssize_t target_tg_pt_gp_alua_access_state_store(struct config_item *item, |
2341 | const char *page, size_t count) | |
c66ac9db | 2342 | { |
2eafd729 | 2343 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
0fd97ccf | 2344 | struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; |
c66ac9db NB |
2345 | unsigned long tmp; |
2346 | int new_state, ret; | |
2347 | ||
6708bb27 | 2348 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
125d0119 | 2349 | pr_err("Unable to do implicit ALUA on non valid" |
c66ac9db NB |
2350 | " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id); |
2351 | return -EINVAL; | |
2352 | } | |
f1453773 NB |
2353 | if (!(dev->dev_flags & DF_CONFIGURED)) { |
2354 | pr_err("Unable to set alua_access_state while device is" | |
2355 | " not configured\n"); | |
2356 | return -ENODEV; | |
2357 | } | |
c66ac9db | 2358 | |
57103d7f | 2359 | ret = kstrtoul(page, 0, &tmp); |
c66ac9db | 2360 | if (ret < 0) { |
6708bb27 | 2361 | pr_err("Unable to extract new ALUA access state from" |
c66ac9db | 2362 | " %s\n", page); |
57103d7f | 2363 | return ret; |
c66ac9db NB |
2364 | } |
2365 | new_state = (int)tmp; | |
2366 | ||
125d0119 HR |
2367 | if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICIT_ALUA)) { |
2368 | pr_err("Unable to process implicit configfs ALUA" | |
2369 | " transition while TPGS_IMPLICIT_ALUA is disabled\n"); | |
c66ac9db NB |
2370 | return -EINVAL; |
2371 | } | |
c66094bf HR |
2372 | if (tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_EXPLICIT_ALUA && |
2373 | new_state == ALUA_ACCESS_STATE_LBA_DEPENDENT) { | |
2374 | /* LBA DEPENDENT is only allowed with implicit ALUA */ | |
2375 | pr_err("Unable to process implicit configfs ALUA transition" | |
2376 | " while explicit ALUA management is enabled\n"); | |
2377 | return -EINVAL; | |
2378 | } | |
c66ac9db | 2379 | |
0fd97ccf | 2380 | ret = core_alua_do_port_transition(tg_pt_gp, dev, |
c66ac9db NB |
2381 | NULL, NULL, new_state, 0); |
2382 | return (!ret) ? count : -EINVAL; | |
2383 | } | |
2384 | ||
2eafd729 CH |
2385 | static ssize_t target_tg_pt_gp_alua_access_status_show(struct config_item *item, |
2386 | char *page) | |
c66ac9db | 2387 | { |
2eafd729 | 2388 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
c66ac9db NB |
2389 | return sprintf(page, "%s\n", |
2390 | core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); | |
2391 | } | |
2392 | ||
2eafd729 CH |
2393 | static ssize_t target_tg_pt_gp_alua_access_status_store( |
2394 | struct config_item *item, const char *page, size_t count) | |
c66ac9db | 2395 | { |
2eafd729 | 2396 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
c66ac9db NB |
2397 | unsigned long tmp; |
2398 | int new_status, ret; | |
2399 | ||
6708bb27 AG |
2400 | if (!tg_pt_gp->tg_pt_gp_valid_id) { |
2401 | pr_err("Unable to do set ALUA access status on non" | |
c66ac9db NB |
2402 | " valid tg_pt_gp ID: %hu\n", |
2403 | tg_pt_gp->tg_pt_gp_valid_id); | |
2404 | return -EINVAL; | |
2405 | } | |
2406 | ||
57103d7f | 2407 | ret = kstrtoul(page, 0, &tmp); |
c66ac9db | 2408 | if (ret < 0) { |
6708bb27 | 2409 | pr_err("Unable to extract new ALUA access status" |
c66ac9db | 2410 | " from %s\n", page); |
57103d7f | 2411 | return ret; |
c66ac9db NB |
2412 | } |
2413 | new_status = (int)tmp; | |
2414 | ||
2415 | if ((new_status != ALUA_STATUS_NONE) && | |
125d0119 HR |
2416 | (new_status != ALUA_STATUS_ALTERED_BY_EXPLICIT_STPG) && |
2417 | (new_status != ALUA_STATUS_ALTERED_BY_IMPLICIT_ALUA)) { | |
6708bb27 | 2418 | pr_err("Illegal ALUA access status: 0x%02x\n", |
c66ac9db NB |
2419 | new_status); |
2420 | return -EINVAL; | |
2421 | } | |
2422 | ||
2423 | tg_pt_gp->tg_pt_gp_alua_access_status = new_status; | |
2424 | return count; | |
2425 | } | |
2426 | ||
2eafd729 CH |
2427 | static ssize_t target_tg_pt_gp_alua_access_type_show(struct config_item *item, |
2428 | char *page) | |
c66ac9db | 2429 | { |
2eafd729 | 2430 | return core_alua_show_access_type(to_tg_pt_gp(item), page); |
c66ac9db NB |
2431 | } |
2432 | ||
2eafd729 CH |
2433 | static ssize_t target_tg_pt_gp_alua_access_type_store(struct config_item *item, |
2434 | const char *page, size_t count) | |
c66ac9db | 2435 | { |
2eafd729 | 2436 | return core_alua_store_access_type(to_tg_pt_gp(item), page, count); |
c66ac9db NB |
2437 | } |
2438 | ||
2eafd729 CH |
2439 | #define ALUA_SUPPORTED_STATE_ATTR(_name, _bit) \ |
2440 | static ssize_t target_tg_pt_gp_alua_support_##_name##_show( \ | |
2441 | struct config_item *item, char *p) \ | |
b0a382c5 | 2442 | { \ |
2eafd729 CH |
2443 | struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \ |
2444 | return sprintf(p, "%d\n", \ | |
2445 | !!(t->tg_pt_gp_alua_supported_states & _bit)); \ | |
2446 | } \ | |
2447 | \ | |
2448 | static ssize_t target_tg_pt_gp_alua_support_##_name##_store( \ | |
2449 | struct config_item *item, const char *p, size_t c) \ | |
b0a382c5 | 2450 | { \ |
2eafd729 | 2451 | struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \ |
b0a382c5 HR |
2452 | unsigned long tmp; \ |
2453 | int ret; \ | |
2454 | \ | |
2455 | if (!t->tg_pt_gp_valid_id) { \ | |
2456 | pr_err("Unable to do set ##_name ALUA state on non" \ | |
2457 | " valid tg_pt_gp ID: %hu\n", \ | |
2458 | t->tg_pt_gp_valid_id); \ | |
2459 | return -EINVAL; \ | |
2460 | } \ | |
2461 | \ | |
2462 | ret = kstrtoul(p, 0, &tmp); \ | |
2463 | if (ret < 0) { \ | |
2464 | pr_err("Invalid value '%s', must be '0' or '1'\n", p); \ | |
2465 | return -EINVAL; \ | |
2466 | } \ | |
2467 | if (tmp > 1) { \ | |
2468 | pr_err("Invalid value '%ld', must be '0' or '1'\n", tmp); \ | |
2469 | return -EINVAL; \ | |
2470 | } \ | |
1f0b030c | 2471 | if (tmp) \ |
2eafd729 | 2472 | t->tg_pt_gp_alua_supported_states |= _bit; \ |
b0a382c5 | 2473 | else \ |
2eafd729 | 2474 | t->tg_pt_gp_alua_supported_states &= ~_bit; \ |
b0a382c5 HR |
2475 | \ |
2476 | return c; \ | |
2477 | } | |
2478 | ||
2eafd729 CH |
2479 | ALUA_SUPPORTED_STATE_ATTR(transitioning, ALUA_T_SUP); |
2480 | ALUA_SUPPORTED_STATE_ATTR(offline, ALUA_O_SUP); | |
2481 | ALUA_SUPPORTED_STATE_ATTR(lba_dependent, ALUA_LBD_SUP); | |
2482 | ALUA_SUPPORTED_STATE_ATTR(unavailable, ALUA_U_SUP); | |
2483 | ALUA_SUPPORTED_STATE_ATTR(standby, ALUA_S_SUP); | |
2484 | ALUA_SUPPORTED_STATE_ATTR(active_optimized, ALUA_AO_SUP); | |
2485 | ALUA_SUPPORTED_STATE_ATTR(active_nonoptimized, ALUA_AN_SUP); | |
6be526c4 | 2486 | |
2eafd729 CH |
2487 | static ssize_t target_tg_pt_gp_alua_write_metadata_show( |
2488 | struct config_item *item, char *page) | |
c66ac9db | 2489 | { |
2eafd729 CH |
2490 | return sprintf(page, "%d\n", |
2491 | to_tg_pt_gp(item)->tg_pt_gp_write_metadata); | |
c66ac9db NB |
2492 | } |
2493 | ||
2eafd729 CH |
2494 | static ssize_t target_tg_pt_gp_alua_write_metadata_store( |
2495 | struct config_item *item, const char *page, size_t count) | |
c66ac9db | 2496 | { |
2eafd729 | 2497 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
c66ac9db NB |
2498 | unsigned long tmp; |
2499 | int ret; | |
2500 | ||
57103d7f | 2501 | ret = kstrtoul(page, 0, &tmp); |
c66ac9db | 2502 | if (ret < 0) { |
6708bb27 | 2503 | pr_err("Unable to extract alua_write_metadata\n"); |
57103d7f | 2504 | return ret; |
c66ac9db NB |
2505 | } |
2506 | ||
2507 | if ((tmp != 0) && (tmp != 1)) { | |
6708bb27 | 2508 | pr_err("Illegal value for alua_write_metadata:" |
c66ac9db NB |
2509 | " %lu\n", tmp); |
2510 | return -EINVAL; | |
2511 | } | |
2512 | tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp; | |
2513 | ||
2514 | return count; | |
2515 | } | |
2516 | ||
2eafd729 CH |
2517 | static ssize_t target_tg_pt_gp_nonop_delay_msecs_show(struct config_item *item, |
2518 | char *page) | |
c66ac9db | 2519 | { |
2eafd729 | 2520 | return core_alua_show_nonop_delay_msecs(to_tg_pt_gp(item), page); |
c66ac9db NB |
2521 | } |
2522 | ||
2eafd729 CH |
2523 | static ssize_t target_tg_pt_gp_nonop_delay_msecs_store(struct config_item *item, |
2524 | const char *page, size_t count) | |
c66ac9db | 2525 | { |
2eafd729 CH |
2526 | return core_alua_store_nonop_delay_msecs(to_tg_pt_gp(item), page, |
2527 | count); | |
c66ac9db NB |
2528 | } |
2529 | ||
2eafd729 CH |
2530 | static ssize_t target_tg_pt_gp_trans_delay_msecs_show(struct config_item *item, |
2531 | char *page) | |
c66ac9db | 2532 | { |
2eafd729 | 2533 | return core_alua_show_trans_delay_msecs(to_tg_pt_gp(item), page); |
c66ac9db NB |
2534 | } |
2535 | ||
2eafd729 CH |
2536 | static ssize_t target_tg_pt_gp_trans_delay_msecs_store(struct config_item *item, |
2537 | const char *page, size_t count) | |
c66ac9db | 2538 | { |
2eafd729 CH |
2539 | return core_alua_store_trans_delay_msecs(to_tg_pt_gp(item), page, |
2540 | count); | |
c66ac9db NB |
2541 | } |
2542 | ||
2eafd729 CH |
2543 | static ssize_t target_tg_pt_gp_implicit_trans_secs_show( |
2544 | struct config_item *item, char *page) | |
5b9a4d72 | 2545 | { |
2eafd729 | 2546 | return core_alua_show_implicit_trans_secs(to_tg_pt_gp(item), page); |
5b9a4d72 NB |
2547 | } |
2548 | ||
2eafd729 CH |
2549 | static ssize_t target_tg_pt_gp_implicit_trans_secs_store( |
2550 | struct config_item *item, const char *page, size_t count) | |
5b9a4d72 | 2551 | { |
2eafd729 CH |
2552 | return core_alua_store_implicit_trans_secs(to_tg_pt_gp(item), page, |
2553 | count); | |
5b9a4d72 NB |
2554 | } |
2555 | ||
2eafd729 CH |
2556 | static ssize_t target_tg_pt_gp_preferred_show(struct config_item *item, |
2557 | char *page) | |
c66ac9db | 2558 | { |
2eafd729 | 2559 | return core_alua_show_preferred_bit(to_tg_pt_gp(item), page); |
c66ac9db NB |
2560 | } |
2561 | ||
2eafd729 CH |
2562 | static ssize_t target_tg_pt_gp_preferred_store(struct config_item *item, |
2563 | const char *page, size_t count) | |
c66ac9db | 2564 | { |
2eafd729 | 2565 | return core_alua_store_preferred_bit(to_tg_pt_gp(item), page, count); |
c66ac9db NB |
2566 | } |
2567 | ||
2eafd729 CH |
2568 | static ssize_t target_tg_pt_gp_tg_pt_gp_id_show(struct config_item *item, |
2569 | char *page) | |
c66ac9db | 2570 | { |
2eafd729 CH |
2571 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
2572 | ||
6708bb27 | 2573 | if (!tg_pt_gp->tg_pt_gp_valid_id) |
c66ac9db | 2574 | return 0; |
c66ac9db NB |
2575 | return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); |
2576 | } | |
2577 | ||
2eafd729 CH |
2578 | static ssize_t target_tg_pt_gp_tg_pt_gp_id_store(struct config_item *item, |
2579 | const char *page, size_t count) | |
c66ac9db | 2580 | { |
2eafd729 | 2581 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
c66ac9db NB |
2582 | struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; |
2583 | unsigned long tg_pt_gp_id; | |
2584 | int ret; | |
2585 | ||
57103d7f | 2586 | ret = kstrtoul(page, 0, &tg_pt_gp_id); |
c66ac9db | 2587 | if (ret < 0) { |
57103d7f | 2588 | pr_err("kstrtoul() returned %d for" |
c66ac9db | 2589 | " tg_pt_gp_id\n", ret); |
57103d7f | 2590 | return ret; |
c66ac9db NB |
2591 | } |
2592 | if (tg_pt_gp_id > 0x0000ffff) { | |
6708bb27 | 2593 | pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:" |
c66ac9db NB |
2594 | " 0x0000ffff\n", tg_pt_gp_id); |
2595 | return -EINVAL; | |
2596 | } | |
2597 | ||
2598 | ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id); | |
2599 | if (ret < 0) | |
2600 | return -EINVAL; | |
2601 | ||
6708bb27 | 2602 | pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: " |
c66ac9db NB |
2603 | "core/alua/tg_pt_gps/%s to ID: %hu\n", |
2604 | config_item_name(&alua_tg_pt_gp_cg->cg_item), | |
2605 | tg_pt_gp->tg_pt_gp_id); | |
2606 | ||
2607 | return count; | |
2608 | } | |
2609 | ||
2eafd729 CH |
2610 | static ssize_t target_tg_pt_gp_members_show(struct config_item *item, |
2611 | char *page) | |
c66ac9db | 2612 | { |
2eafd729 | 2613 | struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item); |
c66ac9db | 2614 | struct se_lun *lun; |
c66ac9db NB |
2615 | ssize_t len = 0, cur_len; |
2616 | unsigned char buf[TG_PT_GROUP_NAME_BUF]; | |
2617 | ||
2618 | memset(buf, 0, TG_PT_GROUP_NAME_BUF); | |
2619 | ||
2620 | spin_lock(&tg_pt_gp->tg_pt_gp_lock); | |
adf653f9 CH |
2621 | list_for_each_entry(lun, &tg_pt_gp->tg_pt_gp_lun_list, |
2622 | lun_tg_pt_gp_link) { | |
2623 | struct se_portal_group *tpg = lun->lun_tpg; | |
c66ac9db NB |
2624 | |
2625 | cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu" | |
e3d6f909 AG |
2626 | "/%s\n", tpg->se_tpg_tfo->get_fabric_name(), |
2627 | tpg->se_tpg_tfo->tpg_get_wwn(tpg), | |
2628 | tpg->se_tpg_tfo->tpg_get_tag(tpg), | |
c66ac9db NB |
2629 | config_item_name(&lun->lun_group.cg_item)); |
2630 | cur_len++; /* Extra byte for NULL terminator */ | |
2631 | ||
2632 | if ((cur_len + len) > PAGE_SIZE) { | |
6708bb27 | 2633 | pr_warn("Ran out of lu_gp_show_attr" |
c66ac9db NB |
2634 | "_members buffer\n"); |
2635 | break; | |
2636 | } | |
2637 | memcpy(page+len, buf, cur_len); | |
2638 | len += cur_len; | |
2639 | } | |
2640 | spin_unlock(&tg_pt_gp->tg_pt_gp_lock); | |
2641 | ||
2642 | return len; | |
2643 | } | |
2644 | ||
2eafd729 CH |
2645 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_state); |
2646 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_status); | |
2647 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_type); | |
2648 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_transitioning); | |
2649 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_offline); | |
2650 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_lba_dependent); | |
2651 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_unavailable); | |
2652 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_standby); | |
2653 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_active_optimized); | |
2654 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_active_nonoptimized); | |
2655 | CONFIGFS_ATTR(target_tg_pt_gp_, alua_write_metadata); | |
2656 | CONFIGFS_ATTR(target_tg_pt_gp_, nonop_delay_msecs); | |
2657 | CONFIGFS_ATTR(target_tg_pt_gp_, trans_delay_msecs); | |
2658 | CONFIGFS_ATTR(target_tg_pt_gp_, implicit_trans_secs); | |
2659 | CONFIGFS_ATTR(target_tg_pt_gp_, preferred); | |
2660 | CONFIGFS_ATTR(target_tg_pt_gp_, tg_pt_gp_id); | |
2661 | CONFIGFS_ATTR_RO(target_tg_pt_gp_, members); | |
c66ac9db NB |
2662 | |
2663 | static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { | |
2eafd729 CH |
2664 | &target_tg_pt_gp_attr_alua_access_state, |
2665 | &target_tg_pt_gp_attr_alua_access_status, | |
2666 | &target_tg_pt_gp_attr_alua_access_type, | |
2667 | &target_tg_pt_gp_attr_alua_support_transitioning, | |
2668 | &target_tg_pt_gp_attr_alua_support_offline, | |
2669 | &target_tg_pt_gp_attr_alua_support_lba_dependent, | |
2670 | &target_tg_pt_gp_attr_alua_support_unavailable, | |
2671 | &target_tg_pt_gp_attr_alua_support_standby, | |
2672 | &target_tg_pt_gp_attr_alua_support_active_nonoptimized, | |
2673 | &target_tg_pt_gp_attr_alua_support_active_optimized, | |
2674 | &target_tg_pt_gp_attr_alua_write_metadata, | |
2675 | &target_tg_pt_gp_attr_nonop_delay_msecs, | |
2676 | &target_tg_pt_gp_attr_trans_delay_msecs, | |
2677 | &target_tg_pt_gp_attr_implicit_trans_secs, | |
2678 | &target_tg_pt_gp_attr_preferred, | |
2679 | &target_tg_pt_gp_attr_tg_pt_gp_id, | |
2680 | &target_tg_pt_gp_attr_members, | |
c66ac9db NB |
2681 | NULL, |
2682 | }; | |
2683 | ||
1f6fe7cb NB |
2684 | static void target_core_alua_tg_pt_gp_release(struct config_item *item) |
2685 | { | |
2686 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), | |
2687 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); | |
2688 | ||
2689 | core_alua_free_tg_pt_gp(tg_pt_gp); | |
2690 | } | |
2691 | ||
c66ac9db | 2692 | static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { |
1f6fe7cb | 2693 | .release = target_core_alua_tg_pt_gp_release, |
c66ac9db NB |
2694 | }; |
2695 | ||
2696 | static struct config_item_type target_core_alua_tg_pt_gp_cit = { | |
2697 | .ct_item_ops = &target_core_alua_tg_pt_gp_ops, | |
2698 | .ct_attrs = target_core_alua_tg_pt_gp_attrs, | |
2699 | .ct_owner = THIS_MODULE, | |
2700 | }; | |
2701 | ||
2702 | /* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ | |
2703 | ||
72aca57b | 2704 | /* Start functions for struct config_item_type tb_alua_tg_pt_gps_cit */ |
c66ac9db NB |
2705 | |
2706 | static struct config_group *target_core_alua_create_tg_pt_gp( | |
2707 | struct config_group *group, | |
2708 | const char *name) | |
2709 | { | |
2710 | struct t10_alua *alua = container_of(group, struct t10_alua, | |
2711 | alua_tg_pt_gps_group); | |
2712 | struct t10_alua_tg_pt_gp *tg_pt_gp; | |
c66ac9db NB |
2713 | struct config_group *alua_tg_pt_gp_cg = NULL; |
2714 | struct config_item *alua_tg_pt_gp_ci = NULL; | |
2715 | ||
0fd97ccf | 2716 | tg_pt_gp = core_alua_allocate_tg_pt_gp(alua->t10_dev, name, 0); |
6708bb27 | 2717 | if (!tg_pt_gp) |
c66ac9db NB |
2718 | return NULL; |
2719 | ||
2720 | alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; | |
2721 | alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item; | |
2722 | ||
2723 | config_group_init_type_name(alua_tg_pt_gp_cg, name, | |
2724 | &target_core_alua_tg_pt_gp_cit); | |
2725 | ||
6708bb27 | 2726 | pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port" |
c66ac9db NB |
2727 | " Group: alua/tg_pt_gps/%s\n", |
2728 | config_item_name(alua_tg_pt_gp_ci)); | |
2729 | ||
2730 | return alua_tg_pt_gp_cg; | |
2731 | } | |
2732 | ||
2733 | static void target_core_alua_drop_tg_pt_gp( | |
2734 | struct config_group *group, | |
2735 | struct config_item *item) | |
2736 | { | |
2737 | struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item), | |
2738 | struct t10_alua_tg_pt_gp, tg_pt_gp_group); | |
2739 | ||
6708bb27 | 2740 | pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port" |
c66ac9db NB |
2741 | " Group: alua/tg_pt_gps/%s, ID: %hu\n", |
2742 | config_item_name(item), tg_pt_gp->tg_pt_gp_id); | |
1f6fe7cb NB |
2743 | /* |
2744 | * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release() | |
2745 | * -> target_core_alua_tg_pt_gp_release(). | |
2746 | */ | |
c66ac9db | 2747 | config_item_put(item); |
c66ac9db NB |
2748 | } |
2749 | ||
2750 | static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = { | |
2751 | .make_group = &target_core_alua_create_tg_pt_gp, | |
2752 | .drop_item = &target_core_alua_drop_tg_pt_gp, | |
2753 | }; | |
2754 | ||
72aca57b | 2755 | TB_CIT_SETUP(dev_alua_tg_pt_gps, NULL, &target_core_alua_tg_pt_gps_group_ops, NULL); |
c66ac9db | 2756 | |
72aca57b | 2757 | /* End functions for struct config_item_type tb_alua_tg_pt_gps_cit */ |
c66ac9db NB |
2758 | |
2759 | /* Start functions for struct config_item_type target_core_alua_cit */ | |
2760 | ||
2761 | /* | |
2762 | * target_core_alua_cit is a ConfigFS group that lives under | |
2763 | * /sys/kernel/config/target/core/alua. There are default groups | |
2764 | * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to | |
2765 | * target_core_alua_cit in target_core_init_configfs() below. | |
2766 | */ | |
2767 | static struct config_item_type target_core_alua_cit = { | |
2768 | .ct_item_ops = NULL, | |
2769 | .ct_attrs = NULL, | |
2770 | .ct_owner = THIS_MODULE, | |
2771 | }; | |
2772 | ||
2773 | /* End functions for struct config_item_type target_core_alua_cit */ | |
2774 | ||
d23ab570 | 2775 | /* Start functions for struct config_item_type tb_dev_stat_cit */ |
12d23384 NB |
2776 | |
2777 | static struct config_group *target_core_stat_mkdir( | |
2778 | struct config_group *group, | |
2779 | const char *name) | |
2780 | { | |
2781 | return ERR_PTR(-ENOSYS); | |
2782 | } | |
2783 | ||
2784 | static void target_core_stat_rmdir( | |
2785 | struct config_group *group, | |
2786 | struct config_item *item) | |
2787 | { | |
2788 | return; | |
2789 | } | |
2790 | ||
2791 | static struct configfs_group_operations target_core_stat_group_ops = { | |
2792 | .make_group = &target_core_stat_mkdir, | |
2793 | .drop_item = &target_core_stat_rmdir, | |
2794 | }; | |
2795 | ||
d23ab570 | 2796 | TB_CIT_SETUP(dev_stat, NULL, &target_core_stat_group_ops, NULL); |
12d23384 | 2797 | |
d23ab570 | 2798 | /* End functions for struct config_item_type tb_dev_stat_cit */ |
12d23384 | 2799 | |
c66ac9db NB |
2800 | /* Start functions for struct config_item_type target_core_hba_cit */ |
2801 | ||
2802 | static struct config_group *target_core_make_subdev( | |
2803 | struct config_group *group, | |
2804 | const char *name) | |
2805 | { | |
2806 | struct t10_alua_tg_pt_gp *tg_pt_gp; | |
c66ac9db NB |
2807 | struct config_item *hba_ci = &group->cg_item; |
2808 | struct se_hba *hba = item_to_hba(hba_ci); | |
0a06d430 | 2809 | struct target_backend *tb = hba->backend; |
0fd97ccf | 2810 | struct se_device *dev; |
12d23384 | 2811 | int errno = -ENOMEM, ret; |
c66ac9db | 2812 | |
12d23384 NB |
2813 | ret = mutex_lock_interruptible(&hba->hba_access_mutex); |
2814 | if (ret) | |
2815 | return ERR_PTR(ret); | |
c66ac9db | 2816 | |
0fd97ccf CH |
2817 | dev = target_alloc_device(hba, name); |
2818 | if (!dev) | |
2819 | goto out_unlock; | |
2820 | ||
1ae1602d | 2821 | config_group_init_type_name(&dev->dev_group, name, &tb->tb_dev_cit); |
c66ac9db | 2822 | |
0fd97ccf | 2823 | config_group_init_type_name(&dev->dev_attrib.da_group, "attrib", |
0a06d430 | 2824 | &tb->tb_dev_attrib_cit); |
1ae1602d CH |
2825 | configfs_add_default_group(&dev->dev_attrib.da_group, &dev->dev_group); |
2826 | ||
0fd97ccf | 2827 | config_group_init_type_name(&dev->dev_pr_group, "pr", |
0a06d430 | 2828 | &tb->tb_dev_pr_cit); |
1ae1602d CH |
2829 | configfs_add_default_group(&dev->dev_pr_group, &dev->dev_group); |
2830 | ||
0fd97ccf | 2831 | config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn", |
0a06d430 | 2832 | &tb->tb_dev_wwn_cit); |
1ae1602d CH |
2833 | configfs_add_default_group(&dev->t10_wwn.t10_wwn_group, |
2834 | &dev->dev_group); | |
2835 | ||
0fd97ccf | 2836 | config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group, |
0a06d430 | 2837 | "alua", &tb->tb_dev_alua_tg_pt_gps_cit); |
1ae1602d CH |
2838 | configfs_add_default_group(&dev->t10_alua.alua_tg_pt_gps_group, |
2839 | &dev->dev_group); | |
2840 | ||
0fd97ccf | 2841 | config_group_init_type_name(&dev->dev_stat_grps.stat_group, |
0a06d430 | 2842 | "statistics", &tb->tb_dev_stat_cit); |
1ae1602d CH |
2843 | configfs_add_default_group(&dev->dev_stat_grps.stat_group, |
2844 | &dev->dev_group); | |
12d23384 | 2845 | |
c66ac9db | 2846 | /* |
12d23384 | 2847 | * Add core/$HBA/$DEV/alua/default_tg_pt_gp |
c66ac9db | 2848 | */ |
0fd97ccf | 2849 | tg_pt_gp = core_alua_allocate_tg_pt_gp(dev, "default_tg_pt_gp", 1); |
6708bb27 | 2850 | if (!tg_pt_gp) |
1ae1602d | 2851 | goto out_free_device; |
0fd97ccf | 2852 | dev->t10_alua.default_tg_pt_gp = tg_pt_gp; |
c66ac9db | 2853 | |
c66ac9db NB |
2854 | config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group, |
2855 | "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit); | |
1ae1602d CH |
2856 | configfs_add_default_group(&tg_pt_gp->tg_pt_gp_group, |
2857 | &dev->t10_alua.alua_tg_pt_gps_group); | |
2858 | ||
12d23384 NB |
2859 | /* |
2860 | * Add core/$HBA/$DEV/statistics/ default groups | |
2861 | */ | |
0fd97ccf | 2862 | target_stat_setup_dev_default_groups(dev); |
c66ac9db NB |
2863 | |
2864 | mutex_unlock(&hba->hba_access_mutex); | |
1ae1602d | 2865 | return &dev->dev_group; |
0fd97ccf | 2866 | |
0fd97ccf CH |
2867 | out_free_device: |
2868 | target_free_device(dev); | |
2869 | out_unlock: | |
c66ac9db | 2870 | mutex_unlock(&hba->hba_access_mutex); |
12d23384 | 2871 | return ERR_PTR(errno); |
c66ac9db NB |
2872 | } |
2873 | ||
2874 | static void target_core_drop_subdev( | |
2875 | struct config_group *group, | |
2876 | struct config_item *item) | |
2877 | { | |
0fd97ccf CH |
2878 | struct config_group *dev_cg = to_config_group(item); |
2879 | struct se_device *dev = | |
2880 | container_of(dev_cg, struct se_device, dev_group); | |
c66ac9db | 2881 | struct se_hba *hba; |
c66ac9db | 2882 | |
0fd97ccf | 2883 | hba = item_to_hba(&dev->se_hba->hba_group.cg_item); |
c66ac9db | 2884 | |
1f6fe7cb | 2885 | mutex_lock(&hba->hba_access_mutex); |
c66ac9db | 2886 | |
1ae1602d CH |
2887 | configfs_remove_default_groups(&dev->dev_stat_grps.stat_group); |
2888 | configfs_remove_default_groups(&dev->t10_alua.alua_tg_pt_gps_group); | |
12d23384 | 2889 | |
1f6fe7cb NB |
2890 | /* |
2891 | * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp | |
2892 | * directly from target_core_alua_tg_pt_gp_release(). | |
2893 | */ | |
0fd97ccf | 2894 | dev->t10_alua.default_tg_pt_gp = NULL; |
c66ac9db | 2895 | |
1ae1602d CH |
2896 | configfs_remove_default_groups(dev_cg); |
2897 | ||
c66ac9db | 2898 | /* |
0fd97ccf | 2899 | * se_dev is released from target_core_dev_item_ops->release() |
c66ac9db | 2900 | */ |
1f6fe7cb | 2901 | config_item_put(item); |
c66ac9db | 2902 | mutex_unlock(&hba->hba_access_mutex); |
c66ac9db NB |
2903 | } |
2904 | ||
2905 | static struct configfs_group_operations target_core_hba_group_ops = { | |
2906 | .make_group = target_core_make_subdev, | |
2907 | .drop_item = target_core_drop_subdev, | |
2908 | }; | |
2909 | ||
c66ac9db | 2910 | |
2eafd729 CH |
2911 | static inline struct se_hba *to_hba(struct config_item *item) |
2912 | { | |
2913 | return container_of(to_config_group(item), struct se_hba, hba_group); | |
2914 | } | |
c66ac9db | 2915 | |
2eafd729 | 2916 | static ssize_t target_hba_info_show(struct config_item *item, char *page) |
c66ac9db | 2917 | { |
2eafd729 CH |
2918 | struct se_hba *hba = to_hba(item); |
2919 | ||
c66ac9db | 2920 | return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", |
0a06d430 | 2921 | hba->hba_id, hba->backend->ops->name, |
ce8dd25d | 2922 | TARGET_CORE_VERSION); |
c66ac9db NB |
2923 | } |
2924 | ||
2eafd729 | 2925 | static ssize_t target_hba_mode_show(struct config_item *item, char *page) |
c66ac9db | 2926 | { |
2eafd729 | 2927 | struct se_hba *hba = to_hba(item); |
c66ac9db NB |
2928 | int hba_mode = 0; |
2929 | ||
2930 | if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) | |
2931 | hba_mode = 1; | |
2932 | ||
2933 | return sprintf(page, "%d\n", hba_mode); | |
2934 | } | |
2935 | ||
2eafd729 CH |
2936 | static ssize_t target_hba_mode_store(struct config_item *item, |
2937 | const char *page, size_t count) | |
c66ac9db | 2938 | { |
2eafd729 | 2939 | struct se_hba *hba = to_hba(item); |
c66ac9db NB |
2940 | unsigned long mode_flag; |
2941 | int ret; | |
2942 | ||
0a06d430 | 2943 | if (hba->backend->ops->pmode_enable_hba == NULL) |
c66ac9db NB |
2944 | return -EINVAL; |
2945 | ||
57103d7f | 2946 | ret = kstrtoul(page, 0, &mode_flag); |
c66ac9db | 2947 | if (ret < 0) { |
6708bb27 | 2948 | pr_err("Unable to extract hba mode flag: %d\n", ret); |
57103d7f | 2949 | return ret; |
c66ac9db NB |
2950 | } |
2951 | ||
0fd97ccf | 2952 | if (hba->dev_count) { |
6708bb27 | 2953 | pr_err("Unable to set hba_mode with active devices\n"); |
c66ac9db NB |
2954 | return -EINVAL; |
2955 | } | |
c66ac9db | 2956 | |
0a06d430 | 2957 | ret = hba->backend->ops->pmode_enable_hba(hba, mode_flag); |
c66ac9db NB |
2958 | if (ret < 0) |
2959 | return -EINVAL; | |
2960 | if (ret > 0) | |
2961 | hba->hba_flags |= HBA_FLAGS_PSCSI_MODE; | |
2962 | else if (ret == 0) | |
2963 | hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE; | |
2964 | ||
2965 | return count; | |
2966 | } | |
2967 | ||
2eafd729 CH |
2968 | CONFIGFS_ATTR_RO(target_, hba_info); |
2969 | CONFIGFS_ATTR(target_, hba_mode); | |
c66ac9db | 2970 | |
1f6fe7cb NB |
2971 | static void target_core_hba_release(struct config_item *item) |
2972 | { | |
2973 | struct se_hba *hba = container_of(to_config_group(item), | |
2974 | struct se_hba, hba_group); | |
2975 | core_delete_hba(hba); | |
2976 | } | |
2977 | ||
c66ac9db | 2978 | static struct configfs_attribute *target_core_hba_attrs[] = { |
2eafd729 CH |
2979 | &target_attr_hba_info, |
2980 | &target_attr_hba_mode, | |
c66ac9db NB |
2981 | NULL, |
2982 | }; | |
2983 | ||
2984 | static struct configfs_item_operations target_core_hba_item_ops = { | |
1f6fe7cb | 2985 | .release = target_core_hba_release, |
c66ac9db NB |
2986 | }; |
2987 | ||
2988 | static struct config_item_type target_core_hba_cit = { | |
2989 | .ct_item_ops = &target_core_hba_item_ops, | |
2990 | .ct_group_ops = &target_core_hba_group_ops, | |
2991 | .ct_attrs = target_core_hba_attrs, | |
2992 | .ct_owner = THIS_MODULE, | |
2993 | }; | |
2994 | ||
2995 | static struct config_group *target_core_call_addhbatotarget( | |
2996 | struct config_group *group, | |
2997 | const char *name) | |
2998 | { | |
2999 | char *se_plugin_str, *str, *str2; | |
3000 | struct se_hba *hba; | |
3001 | char buf[TARGET_CORE_NAME_MAX_LEN]; | |
3002 | unsigned long plugin_dep_id = 0; | |
3003 | int ret; | |
3004 | ||
3005 | memset(buf, 0, TARGET_CORE_NAME_MAX_LEN); | |
60d645a4 | 3006 | if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) { |
6708bb27 | 3007 | pr_err("Passed *name strlen(): %d exceeds" |
c66ac9db NB |
3008 | " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name), |
3009 | TARGET_CORE_NAME_MAX_LEN); | |
3010 | return ERR_PTR(-ENAMETOOLONG); | |
3011 | } | |
3012 | snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name); | |
3013 | ||
3014 | str = strstr(buf, "_"); | |
6708bb27 AG |
3015 | if (!str) { |
3016 | pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n"); | |
c66ac9db NB |
3017 | return ERR_PTR(-EINVAL); |
3018 | } | |
3019 | se_plugin_str = buf; | |
3020 | /* | |
3021 | * Special case for subsystem plugins that have "_" in their names. | |
3022 | * Namely rd_direct and rd_mcp.. | |
3023 | */ | |
3024 | str2 = strstr(str+1, "_"); | |
6708bb27 | 3025 | if (str2) { |
c66ac9db NB |
3026 | *str2 = '\0'; /* Terminate for *se_plugin_str */ |
3027 | str2++; /* Skip to start of plugin dependent ID */ | |
3028 | str = str2; | |
3029 | } else { | |
3030 | *str = '\0'; /* Terminate for *se_plugin_str */ | |
3031 | str++; /* Skip to start of plugin dependent ID */ | |
3032 | } | |
3033 | ||
57103d7f | 3034 | ret = kstrtoul(str, 0, &plugin_dep_id); |
c66ac9db | 3035 | if (ret < 0) { |
57103d7f | 3036 | pr_err("kstrtoul() returned %d for" |
c66ac9db | 3037 | " plugin_dep_id\n", ret); |
57103d7f | 3038 | return ERR_PTR(ret); |
c66ac9db NB |
3039 | } |
3040 | /* | |
3041 | * Load up TCM subsystem plugins if they have not already been loaded. | |
3042 | */ | |
dbc5623e | 3043 | transport_subsystem_check_init(); |
c66ac9db NB |
3044 | |
3045 | hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0); | |
3046 | if (IS_ERR(hba)) | |
3047 | return ERR_CAST(hba); | |
3048 | ||
3049 | config_group_init_type_name(&hba->hba_group, name, | |
3050 | &target_core_hba_cit); | |
3051 | ||
3052 | return &hba->hba_group; | |
3053 | } | |
3054 | ||
3055 | static void target_core_call_delhbafromtarget( | |
3056 | struct config_group *group, | |
3057 | struct config_item *item) | |
3058 | { | |
1f6fe7cb NB |
3059 | /* |
3060 | * core_delete_hba() is called from target_core_hba_item_ops->release() | |
3061 | * -> target_core_hba_release() | |
3062 | */ | |
c66ac9db | 3063 | config_item_put(item); |
c66ac9db NB |
3064 | } |
3065 | ||
3066 | static struct configfs_group_operations target_core_group_ops = { | |
3067 | .make_group = target_core_call_addhbatotarget, | |
3068 | .drop_item = target_core_call_delhbafromtarget, | |
3069 | }; | |
3070 | ||
3071 | static struct config_item_type target_core_cit = { | |
3072 | .ct_item_ops = NULL, | |
3073 | .ct_group_ops = &target_core_group_ops, | |
3074 | .ct_attrs = NULL, | |
3075 | .ct_owner = THIS_MODULE, | |
3076 | }; | |
3077 | ||
3078 | /* Stop functions for struct config_item_type target_core_hba_cit */ | |
3079 | ||
0a06d430 | 3080 | void target_setup_backend_cits(struct target_backend *tb) |
73112edc | 3081 | { |
0a06d430 CH |
3082 | target_core_setup_dev_cit(tb); |
3083 | target_core_setup_dev_attrib_cit(tb); | |
3084 | target_core_setup_dev_pr_cit(tb); | |
3085 | target_core_setup_dev_wwn_cit(tb); | |
3086 | target_core_setup_dev_alua_tg_pt_gps_cit(tb); | |
3087 | target_core_setup_dev_stat_cit(tb); | |
73112edc | 3088 | } |
73112edc | 3089 | |
54550fab | 3090 | static int __init target_core_init_configfs(void) |
c66ac9db | 3091 | { |
d588cf8f | 3092 | struct configfs_subsystem *subsys = &target_core_fabrics; |
c66ac9db NB |
3093 | struct t10_alua_lu_gp *lu_gp; |
3094 | int ret; | |
3095 | ||
6708bb27 | 3096 | pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage" |
c66ac9db NB |
3097 | " Engine: %s on %s/%s on "UTS_RELEASE"\n", |
3098 | TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine); | |
3099 | ||
c66ac9db NB |
3100 | config_group_init(&subsys->su_group); |
3101 | mutex_init(&subsys->su_mutex); | |
3102 | ||
e3d6f909 | 3103 | ret = init_se_kmem_caches(); |
c66ac9db | 3104 | if (ret < 0) |
e3d6f909 | 3105 | return ret; |
c66ac9db NB |
3106 | /* |
3107 | * Create $CONFIGFS/target/core default group for HBA <-> Storage Object | |
3108 | * and ALUA Logical Unit Group and Target Port Group infrastructure. | |
3109 | */ | |
1ae1602d CH |
3110 | config_group_init_type_name(&target_core_hbagroup, "core", |
3111 | &target_core_cit); | |
3112 | configfs_add_default_group(&target_core_hbagroup, &subsys->su_group); | |
c66ac9db | 3113 | |
c66ac9db NB |
3114 | /* |
3115 | * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/ | |
3116 | */ | |
1ae1602d CH |
3117 | config_group_init_type_name(&alua_group, "alua", &target_core_alua_cit); |
3118 | configfs_add_default_group(&alua_group, &target_core_hbagroup); | |
3119 | ||
c66ac9db NB |
3120 | /* |
3121 | * Add ALUA Logical Unit Group and Target Port Group ConfigFS | |
3122 | * groups under /sys/kernel/config/target/core/alua/ | |
3123 | */ | |
1ae1602d CH |
3124 | config_group_init_type_name(&alua_lu_gps_group, "lu_gps", |
3125 | &target_core_alua_lu_gps_cit); | |
3126 | configfs_add_default_group(&alua_lu_gps_group, &alua_group); | |
c66ac9db | 3127 | |
c66ac9db NB |
3128 | /* |
3129 | * Add core/alua/lu_gps/default_lu_gp | |
3130 | */ | |
3131 | lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1); | |
37bb7899 PST |
3132 | if (IS_ERR(lu_gp)) { |
3133 | ret = -ENOMEM; | |
c66ac9db | 3134 | goto out_global; |
37bb7899 | 3135 | } |
c66ac9db | 3136 | |
c66ac9db NB |
3137 | config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp", |
3138 | &target_core_alua_lu_gp_cit); | |
1ae1602d CH |
3139 | configfs_add_default_group(&lu_gp->lu_gp_group, &alua_lu_gps_group); |
3140 | ||
e3d6f909 | 3141 | default_lu_gp = lu_gp; |
1ae1602d | 3142 | |
c66ac9db NB |
3143 | /* |
3144 | * Register the target_core_mod subsystem with configfs. | |
3145 | */ | |
3146 | ret = configfs_register_subsystem(subsys); | |
3147 | if (ret < 0) { | |
6708bb27 | 3148 | pr_err("Error %d while registering subsystem %s\n", |
c66ac9db NB |
3149 | ret, subsys->su_group.cg_item.ci_namebuf); |
3150 | goto out_global; | |
3151 | } | |
6708bb27 | 3152 | pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric" |
ce8dd25d | 3153 | " Infrastructure: "TARGET_CORE_VERSION" on %s/%s" |
c66ac9db NB |
3154 | " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); |
3155 | /* | |
3156 | * Register built-in RAMDISK subsystem logic for virtual LUN 0 | |
3157 | */ | |
3158 | ret = rd_module_init(); | |
3159 | if (ret < 0) | |
3160 | goto out; | |
3161 | ||
0d0f9dfb RD |
3162 | ret = core_dev_setup_virtual_lun0(); |
3163 | if (ret < 0) | |
c66ac9db NB |
3164 | goto out; |
3165 | ||
f99715ac NB |
3166 | ret = target_xcopy_setup_pt(); |
3167 | if (ret < 0) | |
3168 | goto out; | |
3169 | ||
c66ac9db NB |
3170 | return 0; |
3171 | ||
3172 | out: | |
3173 | configfs_unregister_subsystem(subsys); | |
c66ac9db NB |
3174 | core_dev_release_virtual_lun0(); |
3175 | rd_module_exit(); | |
3176 | out_global: | |
e3d6f909 AG |
3177 | if (default_lu_gp) { |
3178 | core_alua_free_lu_gp(default_lu_gp); | |
3179 | default_lu_gp = NULL; | |
c66ac9db | 3180 | } |
e3d6f909 AG |
3181 | release_se_kmem_caches(); |
3182 | return ret; | |
c66ac9db NB |
3183 | } |
3184 | ||
54550fab | 3185 | static void __exit target_core_exit_configfs(void) |
c66ac9db | 3186 | { |
1ae1602d CH |
3187 | configfs_remove_default_groups(&alua_lu_gps_group); |
3188 | configfs_remove_default_groups(&alua_group); | |
3189 | configfs_remove_default_groups(&target_core_hbagroup); | |
c66ac9db | 3190 | |
7c2bf6e9 NB |
3191 | /* |
3192 | * We expect subsys->su_group.default_groups to be released | |
3193 | * by configfs subsystem provider logic.. | |
3194 | */ | |
d588cf8f | 3195 | configfs_unregister_subsystem(&target_core_fabrics); |
c66ac9db | 3196 | |
e3d6f909 AG |
3197 | core_alua_free_lu_gp(default_lu_gp); |
3198 | default_lu_gp = NULL; | |
7c2bf6e9 | 3199 | |
6708bb27 | 3200 | pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric" |
c66ac9db NB |
3201 | " Infrastructure\n"); |
3202 | ||
c66ac9db NB |
3203 | core_dev_release_virtual_lun0(); |
3204 | rd_module_exit(); | |
f99715ac | 3205 | target_xcopy_release_pt(); |
e3d6f909 | 3206 | release_se_kmem_caches(); |
c66ac9db NB |
3207 | } |
3208 | ||
3209 | MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS"); | |
3210 | MODULE_AUTHOR("nab@Linux-iSCSI.org"); | |
3211 | MODULE_LICENSE("GPL"); | |
3212 | ||
3213 | module_init(target_core_init_configfs); | |
3214 | module_exit(target_core_exit_configfs); |