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