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