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