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