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