23 #include <linux/module.h>
25 #include <linux/utsname.h>
29 #include <linux/slab.h>
30 #include <linux/types.h>
33 #include <linux/string.h>
47 #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
48 static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
50 struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \
51 struct config_item_type *cit = &tfc->tfc_##_name##_cit; \
53 cit->ct_item_ops = _item_ops; \
54 cit->ct_group_ops = _group_ops; \
55 cit->ct_attrs = _attrs; \
56 cit->ct_owner = tf->tf_module; \
57 pr_debug("Setup generic %s\n", __stringify(_name)); \
62 static int target_fabric_mappedlun_link(
72 struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s;
73 int ret = 0, lun_access;
78 pr_err(
"Source se_lun->lun_sep or lun->lun_sep->sep"
79 "_tpg does not exist\n");
84 nacl_ci = &lun_acl_ci->
ci_parent->ci_group->cg_item;
85 tpg_ci = &nacl_ci->
ci_group->cg_item;
87 tpg_ci_s = &lun_ci->
ci_parent->ci_group->cg_item;
88 wwn_ci_s = &tpg_ci_s->
ci_group->cg_item;
92 if (
strcmp(config_item_name(wwn_ci), config_item_name(wwn_ci_s))) {
93 pr_err(
"Illegal Initiator ACL SymLink outside of %s\n",
94 config_item_name(wwn_ci));
97 if (
strcmp(config_item_name(tpg_ci), config_item_name(tpg_ci_s))) {
98 pr_err(
"Illegal Initiator ACL Symlink outside of %s"
99 " TPGT: %s\n", config_item_name(wwn_ci),
100 config_item_name(tpg_ci));
109 spin_lock_irq(&lacl->
se_lun_nacl->device_list_lock);
115 (se_tpg->
se_tpg_tfo->tpg_check_prod_mode_write_protect(
118 spin_unlock_irq(&lacl->
se_lun_nacl->device_list_lock);
128 return (ret < 0) ? -
EINVAL : 0;
131 static int target_fabric_mappedlun_unlink(
148 se_tpg = lun->
lun_sep->sep_tpg;
155 #define TCM_MAPPEDLUN_ATTR(_name, _mode) \
156 static struct target_fabric_mappedlun_attribute target_fabric_mappedlun_##_name = \
157 __CONFIGFS_EATTR(_name, _mode, \
158 target_fabric_mappedlun_show_##_name, \
159 target_fabric_mappedlun_store_##_name);
161 static ssize_t target_fabric_mappedlun_show_write_protect(
179 static ssize_t target_fabric_mappedlun_store_write_protect(
191 if ((op != 1) && (op != 0))
199 pr_debug(
"%s_ConfigFS: Changed Initiator ACL: %s"
200 " Mapped LUN: %u Write Protect bit to %s\n",
222 &target_fabric_mappedlun_write_protect.attr,
227 .release = target_fabric_mappedlun_release,
228 .show_attribute = target_fabric_mappedlun_attr_show,
229 .store_attribute = target_fabric_mappedlun_attr_store,
230 .allow_link = target_fabric_mappedlun_link,
231 .drop_link = target_fabric_mappedlun_unlink,
235 target_fabric_mappedlun_attrs);
241 static struct config_group *target_core_mappedlun_stat_mkdir(
248 static void target_core_mappedlun_stat_rmdir(
256 .make_group = target_core_mappedlun_stat_mkdir,
257 .drop_item = target_core_mappedlun_stat_rmdir,
260 TF_CIT_SETUP(tpg_mappedlun_stat,
NULL, &target_fabric_mappedlun_stat_group_ops,
270 .show_attribute = target_fabric_nacl_attrib_attr_show,
271 .store_attribute = target_fabric_nacl_attrib_attr_store,
283 .show_attribute = target_fabric_nacl_auth_attr_show,
284 .store_attribute = target_fabric_nacl_auth_attr_store,
296 .show_attribute = target_fabric_nacl_param_attr_show,
297 .store_attribute = target_fabric_nacl_param_attr_store,
308 static struct config_group *target_fabric_make_mappedlun(
320 unsigned long mapped_lun;
325 pr_err(
"Unable to locatel acl_ci\n");
331 pr_err(
"Unable to allocate memory for name buf\n");
338 if (
strstr(buf,
"lun_") != buf) {
339 pr_err(
"Unable to locate \"lun_\" from buf: %s"
340 " name: %s\n", buf, name);
354 config_item_name(acl_ci), &ret);
364 pr_err(
"Unable to allocate lacl_cg->default_groups\n");
372 "statistics", &
TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_stat_cit);
377 ml_stat_grp->default_groups = kzalloc(
sizeof(
struct config_group) * 3,
379 if (!ml_stat_grp->default_groups) {
380 pr_err(
"Unable to allocate ml_stat_grp->default_groups\n");
395 static void target_fabric_drop_mappedlun(
406 for (i = 0; ml_stat_grp->default_groups[
i]; i++) {
407 df_item = &ml_stat_grp->default_groups[
i]->cg_item;
408 ml_stat_grp->default_groups[
i] =
NULL;
411 kfree(ml_stat_grp->default_groups);
424 static void target_fabric_nacl_base_release(
struct config_item *item)
431 tf->
tf_ops.fabric_drop_nodeacl(se_nacl);
435 .release = target_fabric_nacl_base_release,
436 .show_attribute = target_fabric_nacl_base_attr_show,
437 .store_attribute = target_fabric_nacl_base_attr_store,
441 .make_group = target_fabric_make_mappedlun,
442 .drop_item = target_fabric_drop_mappedlun,
445 TF_CIT_SETUP(tpg_nacl_base, &target_fabric_nacl_base_item_ops,
446 &target_fabric_nacl_base_group_ops,
NULL);
471 if (!tf->
tf_ops.fabric_make_nodeacl) {
472 pr_err(
"tf->tf_ops.fabric_make_nodeacl is NULL\n");
476 se_nacl = tf->
tf_ops.fabric_make_nodeacl(se_tpg, group, name);
478 return ERR_CAST(se_nacl);
503 static void target_fabric_drop_nodeacl(
526 .make_group = target_fabric_make_nodeacl,
527 .drop_item = target_fabric_drop_nodeacl,
538 static void target_fabric_np_base_release(
struct config_item *item)
545 tf->
tf_ops.fabric_drop_np(se_tpg_np);
549 .release = target_fabric_np_base_release,
550 .show_attribute = target_fabric_np_base_attr_show,
551 .store_attribute = target_fabric_np_base_attr_store,
567 struct se_tpg_np *se_tpg_np;
569 if (!tf->
tf_ops.fabric_make_np) {
570 pr_err(
"tf->tf_ops.fabric_make_np is NULL\n");
574 se_tpg_np = tf->
tf_ops.fabric_make_np(se_tpg, group, name);
575 if (!se_tpg_np || IS_ERR(se_tpg_np))
585 static void target_fabric_drop_np(
596 .make_group = &target_fabric_make_np,
597 .drop_item = &target_fabric_drop_np,
607 #define TCM_PORT_ATTR(_name, _mode) \
608 static struct target_fabric_port_attribute target_fabric_port_##_name = \
609 __CONFIGFS_EATTR(_name, _mode, \
610 target_fabric_port_show_attr_##_name, \
611 target_fabric_port_store_attr_##_name);
613 #define TCM_PORT_ATTOR_RO(_name) \
614 __CONFIGFS_EATTR_RO(_name, \
615 target_fabric_port_show_attr_##_name);
620 static ssize_t target_fabric_port_show_attr_alua_tg_pt_gp(
630 static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp(
646 static ssize_t target_fabric_port_show_attr_alua_tg_pt_offline(
656 static ssize_t target_fabric_port_store_attr_alua_tg_pt_offline(
672 static ssize_t target_fabric_port_show_attr_alua_tg_pt_status(
682 static ssize_t target_fabric_port_store_attr_alua_tg_pt_status(
698 static ssize_t target_fabric_port_show_attr_alua_tg_pt_write_md(
708 static ssize_t target_fabric_port_store_attr_alua_tg_pt_write_md(
723 &target_fabric_port_alua_tg_pt_gp.attr,
724 &target_fabric_port_alua_tg_pt_offline.attr,
725 &target_fabric_port_alua_tg_pt_status.attr,
726 &target_fabric_port_alua_tg_pt_write_md.attr,
732 static int target_fabric_port_link(
748 tpg_ci = &lun_ci->
ci_parent->ci_group->cg_item;
754 pr_err(
"Port Symlink already exists\n");
760 pr_err(
"Unable to locate struct se_device pointer from"
761 " %s\n", config_item_name(se_dev_ci));
768 pr_err(
"core_dev_add_lun() failed\n");
769 ret = PTR_ERR(lun_p);
773 if (tf->
tf_ops.fabric_post_link) {
779 tf->
tf_ops.fabric_post_link(se_tpg, lun);
787 static int target_fabric_port_unlink(
796 if (tf->
tf_ops.fabric_pre_unlink) {
802 tf->
tf_ops.fabric_pre_unlink(se_tpg, lun);
810 .show_attribute = target_fabric_port_attr_show,
811 .store_attribute = target_fabric_port_attr_store,
812 .allow_link = target_fabric_port_link,
813 .drop_link = target_fabric_port_unlink,
816 TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops,
NULL, target_fabric_port_attrs);
822 static struct config_group *target_core_port_stat_mkdir(
829 static void target_core_port_stat_rmdir(
837 .make_group = target_core_port_stat_mkdir,
838 .drop_item = target_core_port_stat_rmdir,
856 unsigned long unpacked_lun;
859 if (
strstr(name,
"lun_") != name) {
860 pr_err(
"Unable to locate \'_\" in"
861 " \"lun_$LUN_NUMBER\"\n");
875 pr_err(
"Unable to allocate lun_cg->default_groups\n");
882 "statistics", &
TF_CIT_TMPL(tf)->tfc_tpg_port_stat_cit);
887 port_stat_grp->default_groups = kzalloc(
sizeof(
struct config_group) * 3,
889 if (!port_stat_grp->default_groups) {
890 pr_err(
"Unable to allocate port_stat_grp->default_groups\n");
900 return ERR_PTR(errno);
903 static void target_fabric_drop_lun(
933 .make_group = &target_fabric_make_lun,
934 .drop_item = &target_fabric_drop_lun,
946 .show_attribute = target_fabric_tpg_attrib_attr_show,
947 .store_attribute = target_fabric_tpg_attrib_attr_store,
959 .show_attribute = target_fabric_tpg_param_attr_show,
960 .store_attribute = target_fabric_tpg_param_attr_store,
973 static void target_fabric_tpg_release(
struct config_item *item)
980 tf->
tf_ops.fabric_drop_tpg(se_tpg);
984 .release = target_fabric_tpg_release,
985 .show_attribute = target_fabric_tpg_attr_show,
986 .store_attribute = target_fabric_tpg_attr_store,
1003 if (!tf->
tf_ops.fabric_make_tpg) {
1004 pr_err(
"tf->tf_ops.fabric_make_tpg is NULL\n");
1008 se_tpg = tf->
tf_ops.fabric_make_tpg(wwn, group, name);
1009 if (!se_tpg || IS_ERR(se_tpg))
1038 static void target_fabric_drop_tpg(
1060 static void target_fabric_release_wwn(
struct config_item *item)
1066 tf->
tf_ops.fabric_drop_wwn(wwn);
1070 .release = target_fabric_release_wwn,
1074 .make_group = target_fabric_make_tpg,
1075 .drop_item = target_fabric_drop_tpg,
1078 TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops,
1102 if (!tf->
tf_ops.fabric_make_wwn) {
1103 pr_err(
"tf->tf_ops.fabric_make_wwn is NULL\n");
1107 wwn = tf->
tf_ops.fabric_make_wwn(tf, group, name);
1108 if (!wwn || IS_ERR(wwn))
1127 static void target_fabric_drop_wwn(
1147 .make_group = target_fabric_make_wwn,
1148 .drop_item = target_fabric_drop_wwn,
1156 .show_attribute = target_fabric_wwn_attr_show,
1157 .store_attribute = target_fabric_wwn_attr_store,
1160 TF_CIT_SETUP(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops,
NULL);
1170 .show_attribute = target_fabric_discovery_attr_show,
1171 .store_attribute = target_fabric_discovery_attr_store,
1180 target_fabric_setup_discovery_cit(tf);
1181 target_fabric_setup_wwn_cit(tf);
1182 target_fabric_setup_wwn_fabric_stats_cit(tf);
1183 target_fabric_setup_tpg_cit(tf);
1184 target_fabric_setup_tpg_base_cit(tf);
1185 target_fabric_setup_tpg_port_cit(tf);
1186 target_fabric_setup_tpg_port_stat_cit(tf);
1187 target_fabric_setup_tpg_lun_cit(tf);
1188 target_fabric_setup_tpg_np_cit(tf);
1189 target_fabric_setup_tpg_np_base_cit(tf);
1190 target_fabric_setup_tpg_attrib_cit(tf);
1191 target_fabric_setup_tpg_param_cit(tf);
1192 target_fabric_setup_tpg_nacl_cit(tf);
1193 target_fabric_setup_tpg_nacl_base_cit(tf);
1194 target_fabric_setup_tpg_nacl_attrib_cit(tf);
1195 target_fabric_setup_tpg_nacl_auth_cit(tf);
1196 target_fabric_setup_tpg_nacl_param_cit(tf);
1197 target_fabric_setup_tpg_nacl_stat_cit(tf);
1198 target_fabric_setup_tpg_mappedlun_cit(tf);
1199 target_fabric_setup_tpg_mappedlun_stat_cit(tf);