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