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