blob: 6e456de5e5646aa77c0676bf8fa21cbd66a5ba90 [file] [log] [blame]
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001/*******************************************************************************
2* Filename: target_core_fabric_configfs.c
3 *
4 * This file contains generic fabric module configfs infrastructure for
5 * TCM v4.x code
6 *
Nicholas Bellinger4c762512013-09-05 15:29:12 -07007 * (c) Copyright 2010-2013 Datera, Inc.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08008 *
Nicholas Bellingerfd9a11d2012-11-09 14:51:48 -08009 * Nicholas A. Bellinger <nab@linux-iscsi.org>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080010*
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 ****************************************************************************/
21
22#include <linux/module.h>
23#include <linux/moduleparam.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080024#include <linux/utsname.h>
25#include <linux/init.h>
26#include <linux/fs.h>
27#include <linux/namei.h>
28#include <linux/slab.h>
29#include <linux/types.h>
30#include <linux/delay.h>
31#include <linux/unistd.h>
32#include <linux/string.h>
33#include <linux/syscalls.h>
34#include <linux/configfs.h>
35
36#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050037#include <target/target_core_fabric.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080038
Christoph Hellwige26d99a2011-11-14 12:30:30 -050039#include "target_core_internal.h"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080040#include "target_core_alua.h"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080041#include "target_core_pr.h"
42
43#define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \
44static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
45{ \
Christoph Hellwig968ebe72015-05-03 08:50:55 +020046 struct config_item_type *cit = &tf->tf_##_name##_cit; \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080047 \
48 cit->ct_item_ops = _item_ops; \
49 cit->ct_group_ops = _group_ops; \
50 cit->ct_attrs = _attrs; \
Christoph Hellwig0dc2e8d2015-05-03 08:50:54 +020051 cit->ct_owner = tf->tf_ops->module; \
Andy Grover6708bb22011-06-08 10:36:43 -070052 pr_debug("Setup generic %s\n", __stringify(_name)); \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080053}
54
Christoph Hellwig9ac89282015-04-08 20:01:35 +020055#define TF_CIT_SETUP_DRV(_name, _item_ops, _group_ops) \
56static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \
57{ \
Christoph Hellwig968ebe72015-05-03 08:50:55 +020058 struct config_item_type *cit = &tf->tf_##_name##_cit; \
Christoph Hellwigef0caf82015-05-03 08:50:53 +020059 struct configfs_attribute **attrs = tf->tf_ops->tfc_##_name##_attrs; \
Christoph Hellwig9ac89282015-04-08 20:01:35 +020060 \
61 cit->ct_item_ops = _item_ops; \
62 cit->ct_group_ops = _group_ops; \
63 cit->ct_attrs = attrs; \
Christoph Hellwig0dc2e8d2015-05-03 08:50:54 +020064 cit->ct_owner = tf->tf_ops->module; \
Christoph Hellwig9ac89282015-04-08 20:01:35 +020065 pr_debug("Setup generic %s\n", __stringify(_name)); \
66}
67
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080068/* Start of tfc_tpg_mappedlun_cit */
69
70static int target_fabric_mappedlun_link(
71 struct config_item *lun_acl_ci,
72 struct config_item *lun_ci)
73{
74 struct se_dev_entry *deve;
75 struct se_lun *lun = container_of(to_config_group(lun_ci),
76 struct se_lun, lun_group);
77 struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci),
78 struct se_lun_acl, se_lun_group);
79 struct se_portal_group *se_tpg;
80 struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s;
Andy Grover03a68b42016-02-25 15:14:32 -080081 bool lun_access_ro;
Nicholas Bellinger0ff87542012-12-04 23:43:57 -080082
83 if (lun->lun_link_magic != SE_LUN_LINK_MAGIC) {
84 pr_err("Bad lun->lun_link_magic, not a valid lun_ci pointer:"
85 " %p to struct lun: %p\n", lun_ci, lun);
86 return -EFAULT;
87 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080088 /*
89 * Ensure that the source port exists
90 */
Christoph Hellwigadf653f2015-05-25 21:33:08 -070091 if (!lun->lun_se_dev) {
92 pr_err("Source se_lun->lun_se_dev does not exist\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080093 return -EINVAL;
94 }
Nicholas Bellinger92f8aa72017-03-27 16:12:43 -070095 if (lun->lun_shutdown) {
96 pr_err("Unable to create mappedlun symlink because"
97 " lun->lun_shutdown=true\n");
98 return -EINVAL;
99 }
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700100 se_tpg = lun->lun_tpg;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800101
102 nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item;
103 tpg_ci = &nacl_ci->ci_group->cg_item;
104 wwn_ci = &tpg_ci->ci_group->cg_item;
105 tpg_ci_s = &lun_ci->ci_parent->ci_group->cg_item;
106 wwn_ci_s = &tpg_ci_s->ci_group->cg_item;
107 /*
108 * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT
109 */
110 if (strcmp(config_item_name(wwn_ci), config_item_name(wwn_ci_s))) {
Andy Grover6708bb22011-06-08 10:36:43 -0700111 pr_err("Illegal Initiator ACL SymLink outside of %s\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800112 config_item_name(wwn_ci));
113 return -EINVAL;
114 }
115 if (strcmp(config_item_name(tpg_ci), config_item_name(tpg_ci_s))) {
Andy Grover6708bb22011-06-08 10:36:43 -0700116 pr_err("Illegal Initiator ACL Symlink outside of %s"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800117 " TPGT: %s\n", config_item_name(wwn_ci),
118 config_item_name(tpg_ci));
119 return -EINVAL;
120 }
121 /*
122 * If this struct se_node_acl was dynamically generated with
Andy Grover03a68b42016-02-25 15:14:32 -0800123 * tpg_1/attrib/generate_node_acls=1, use the existing
124 * deve->lun_access_ro value, which will be true when
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800125 * tpg_1/attrib/demo_mode_write_protect=1
126 */
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700127 rcu_read_lock();
128 deve = target_nacl_find_deve(lacl->se_lun_nacl, lacl->mapped_lun);
129 if (deve)
Andy Grover03a68b42016-02-25 15:14:32 -0800130 lun_access_ro = deve->lun_access_ro;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800131 else
Andy Grover03a68b42016-02-25 15:14:32 -0800132 lun_access_ro =
Andy Grovere3d6f902011-07-19 08:55:10 +0000133 (se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect(
Andy Grover03a68b42016-02-25 15:14:32 -0800134 se_tpg)) ? true : false;
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700135 rcu_read_unlock();
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800136 /*
137 * Determine the actual mapped LUN value user wants..
138 *
139 * This value is what the SCSI Initiator actually sees the
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700140 * $FABRIC/$WWPN/$TPGT/lun/lun_* as on their SCSI Initiator Ports.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800141 */
Andy Grover03a68b42016-02-25 15:14:32 -0800142 return core_dev_add_initiator_node_lun_acl(se_tpg, lacl, lun, lun_access_ro);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800143}
144
145static int target_fabric_mappedlun_unlink(
146 struct config_item *lun_acl_ci,
147 struct config_item *lun_ci)
148{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800149 struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci),
150 struct se_lun_acl, se_lun_group);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700151 struct se_lun *lun = container_of(to_config_group(lun_ci),
152 struct se_lun, lun_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800153
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700154 return core_dev_del_initiator_node_lun_acl(lun, lacl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800155}
156
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200157static struct se_lun_acl *item_to_lun_acl(struct config_item *item)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800158{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200159 return container_of(to_config_group(item), struct se_lun_acl,
160 se_lun_group);
161}
162
163static ssize_t target_fabric_mappedlun_write_protect_show(
164 struct config_item *item, char *page)
165{
166 struct se_lun_acl *lacl = item_to_lun_acl(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800167 struct se_node_acl *se_nacl = lacl->se_lun_nacl;
168 struct se_dev_entry *deve;
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700169 ssize_t len = 0;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800170
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700171 rcu_read_lock();
172 deve = target_nacl_find_deve(se_nacl, lacl->mapped_lun);
173 if (deve) {
Andy Grover03a68b42016-02-25 15:14:32 -0800174 len = sprintf(page, "%d\n", deve->lun_access_ro);
Nicholas Bellinger29a05de2015-03-22 20:42:19 -0700175 }
176 rcu_read_unlock();
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800177
178 return len;
179}
180
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200181static ssize_t target_fabric_mappedlun_write_protect_store(
182 struct config_item *item, const char *page, size_t count)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800183{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200184 struct se_lun_acl *lacl = item_to_lun_acl(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800185 struct se_node_acl *se_nacl = lacl->se_lun_nacl;
186 struct se_portal_group *se_tpg = se_nacl->se_tpg;
Andy Grover03a68b42016-02-25 15:14:32 -0800187 unsigned long wp;
Jingoo Han57103d72013-07-19 16:22:19 +0900188 int ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800189
Andy Grover03a68b42016-02-25 15:14:32 -0800190 ret = kstrtoul(page, 0, &wp);
Jingoo Han57103d72013-07-19 16:22:19 +0900191 if (ret)
192 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800193
Andy Grover03a68b42016-02-25 15:14:32 -0800194 if ((wp != 1) && (wp != 0))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800195 return -EINVAL;
196
Andy Grover03a68b42016-02-25 15:14:32 -0800197 /* wp=1 means lun_access_ro=true */
198 core_update_device_list_access(lacl->mapped_lun, wp, lacl->se_lun_nacl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800199
Andy Grover6708bb22011-06-08 10:36:43 -0700200 pr_debug("%s_ConfigFS: Changed Initiator ACL: %s"
Hannes Reineckef2d30682015-06-10 08:41:22 +0200201 " Mapped LUN: %llu Write Protect bit to %s\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000202 se_tpg->se_tpg_tfo->get_fabric_name(),
Andy Grover03a68b42016-02-25 15:14:32 -0800203 se_nacl->initiatorname, lacl->mapped_lun, (wp) ? "ON" : "OFF");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800204
205 return count;
206
207}
208
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200209CONFIGFS_ATTR(target_fabric_mappedlun_, write_protect);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800210
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200211static struct configfs_attribute *target_fabric_mappedlun_attrs[] = {
212 &target_fabric_mappedlun_attr_write_protect,
213 NULL,
214};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800215
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800216static void target_fabric_mappedlun_release(struct config_item *item)
217{
218 struct se_lun_acl *lacl = container_of(to_config_group(item),
219 struct se_lun_acl, se_lun_group);
220 struct se_portal_group *se_tpg = lacl->se_lun_nacl->se_tpg;
221
222 core_dev_free_initiator_node_lun_acl(se_tpg, lacl);
223}
224
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800225static struct configfs_item_operations target_fabric_mappedlun_item_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800226 .release = target_fabric_mappedlun_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800227 .allow_link = target_fabric_mappedlun_link,
228 .drop_link = target_fabric_mappedlun_unlink,
229};
230
231TF_CIT_SETUP(tpg_mappedlun, &target_fabric_mappedlun_item_ops, NULL,
232 target_fabric_mappedlun_attrs);
233
234/* End of tfc_tpg_mappedlun_cit */
235
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700236/* Start of tfc_tpg_mappedlun_port_cit */
237
238static struct config_group *target_core_mappedlun_stat_mkdir(
239 struct config_group *group,
240 const char *name)
241{
242 return ERR_PTR(-ENOSYS);
243}
244
245static void target_core_mappedlun_stat_rmdir(
246 struct config_group *group,
247 struct config_item *item)
248{
249 return;
250}
251
252static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops = {
253 .make_group = target_core_mappedlun_stat_mkdir,
254 .drop_item = target_core_mappedlun_stat_rmdir,
255};
256
257TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops,
258 NULL);
259
260/* End of tfc_tpg_mappedlun_port_cit */
261
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200262TF_CIT_SETUP_DRV(tpg_nacl_attrib, NULL, NULL);
263TF_CIT_SETUP_DRV(tpg_nacl_auth, NULL, NULL);
264TF_CIT_SETUP_DRV(tpg_nacl_param, NULL, NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800265
266/* Start of tfc_tpg_nacl_base_cit */
267
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800268static struct config_group *target_fabric_make_mappedlun(
269 struct config_group *group,
270 const char *name)
271{
272 struct se_node_acl *se_nacl = container_of(group,
273 struct se_node_acl, acl_group);
274 struct se_portal_group *se_tpg = se_nacl->se_tpg;
275 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
Joern Engelda0abae2014-09-02 17:49:57 -0400276 struct se_lun_acl *lacl = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800277 char *buf;
Hannes Reineckef2d30682015-06-10 08:41:22 +0200278 unsigned long long mapped_lun;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800279 int ret = 0;
280
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800281 buf = kzalloc(strlen(name) + 1, GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -0700282 if (!buf) {
283 pr_err("Unable to allocate memory for name buf\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800284 return ERR_PTR(-ENOMEM);
285 }
286 snprintf(buf, strlen(name) + 1, "%s", name);
287 /*
288 * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID.
289 */
290 if (strstr(buf, "lun_") != buf) {
Andy Grover6708bb22011-06-08 10:36:43 -0700291 pr_err("Unable to locate \"lun_\" from buf: %s"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800292 " name: %s\n", buf, name);
293 ret = -EINVAL;
294 goto out;
295 }
296 /*
297 * Determine the Mapped LUN value. This is what the SCSI Initiator
298 * Port will actually see.
299 */
Hannes Reineckef2d30682015-06-10 08:41:22 +0200300 ret = kstrtoull(buf + 4, 0, &mapped_lun);
Jingoo Han57103d72013-07-19 16:22:19 +0900301 if (ret)
302 goto out;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800303
Nicholas Bellingerfcf29482013-02-18 18:00:33 -0800304 lacl = core_dev_init_initiator_node_lun_acl(se_tpg, se_nacl,
305 mapped_lun, &ret);
Andy Grover6708bb22011-06-08 10:36:43 -0700306 if (!lacl) {
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700307 ret = -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800308 goto out;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700309 }
310
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800311 config_group_init_type_name(&lacl->se_lun_group, name,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200312 &tf->tf_tpg_mappedlun_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100313
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700314 config_group_init_type_name(&lacl->ml_stat_grps.stat_group,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200315 "statistics", &tf->tf_tpg_mappedlun_stat_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100316 configfs_add_default_group(&lacl->ml_stat_grps.stat_group,
317 &lacl->se_lun_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700318
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700319 target_stat_setup_mappedlun_default_groups(lacl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800320
321 kfree(buf);
322 return &lacl->se_lun_group;
323out:
Joern Engelda0abae2014-09-02 17:49:57 -0400324 kfree(lacl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800325 kfree(buf);
326 return ERR_PTR(ret);
327}
328
329static void target_fabric_drop_mappedlun(
330 struct config_group *group,
331 struct config_item *item)
332{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700333 struct se_lun_acl *lacl = container_of(to_config_group(item),
334 struct se_lun_acl, se_lun_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700335
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100336 configfs_remove_default_groups(&lacl->ml_stat_grps.stat_group);
337 configfs_remove_default_groups(&lacl->se_lun_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700338
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800339 config_item_put(item);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800340}
341
342static void target_fabric_nacl_base_release(struct config_item *item)
343{
344 struct se_node_acl *se_nacl = container_of(to_config_group(item),
345 struct se_node_acl, acl_group);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800346
Christoph Hellwigce7043f2016-03-29 13:03:33 +0200347 configfs_remove_default_groups(&se_nacl->acl_fabric_stat_group);
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200348 core_tpg_del_initiator_node_acl(se_nacl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800349}
350
351static struct configfs_item_operations target_fabric_nacl_base_item_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800352 .release = target_fabric_nacl_base_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800353};
354
355static struct configfs_group_operations target_fabric_nacl_base_group_ops = {
356 .make_group = target_fabric_make_mappedlun,
357 .drop_item = target_fabric_drop_mappedlun,
358};
359
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200360TF_CIT_SETUP_DRV(tpg_nacl_base, &target_fabric_nacl_base_item_ops,
361 &target_fabric_nacl_base_group_ops);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800362
363/* End of tfc_tpg_nacl_base_cit */
364
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700365/* Start of tfc_node_fabric_stats_cit */
366/*
367 * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group
368 * to allow fabrics access to ->acl_fabric_stat_group->default_groups[]
369 */
370TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL);
371
372/* End of tfc_wwn_fabric_stats_cit */
373
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800374/* Start of tfc_tpg_nacl_cit */
375
376static struct config_group *target_fabric_make_nodeacl(
377 struct config_group *group,
378 const char *name)
379{
380 struct se_portal_group *se_tpg = container_of(group,
381 struct se_portal_group, tpg_acl_group);
382 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
383 struct se_node_acl *se_nacl;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800384
Christoph Hellwigc7d6a802015-04-13 19:51:14 +0200385 se_nacl = core_tpg_add_initiator_node_acl(se_tpg, name);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800386 if (IS_ERR(se_nacl))
Thomas Meyere1750ba2011-08-01 23:58:18 +0200387 return ERR_CAST(se_nacl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800388
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800389 config_group_init_type_name(&se_nacl->acl_group, name,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200390 &tf->tf_tpg_nacl_base_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100391
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800392 config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200393 &tf->tf_tpg_nacl_attrib_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100394 configfs_add_default_group(&se_nacl->acl_attrib_group,
395 &se_nacl->acl_group);
396
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800397 config_group_init_type_name(&se_nacl->acl_auth_group, "auth",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200398 &tf->tf_tpg_nacl_auth_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100399 configfs_add_default_group(&se_nacl->acl_auth_group,
400 &se_nacl->acl_group);
401
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800402 config_group_init_type_name(&se_nacl->acl_param_group, "param",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200403 &tf->tf_tpg_nacl_param_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100404 configfs_add_default_group(&se_nacl->acl_param_group,
405 &se_nacl->acl_group);
406
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700407 config_group_init_type_name(&se_nacl->acl_fabric_stat_group,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200408 "fabric_statistics", &tf->tf_tpg_nacl_stat_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100409 configfs_add_default_group(&se_nacl->acl_fabric_stat_group,
410 &se_nacl->acl_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800411
Christoph Hellwige6e202e2016-03-29 13:03:34 +0200412 if (tf->tf_ops->fabric_init_nodeacl) {
413 int ret = tf->tf_ops->fabric_init_nodeacl(se_nacl, name);
414 if (ret) {
415 configfs_remove_default_groups(&se_nacl->acl_fabric_stat_group);
416 core_tpg_del_initiator_node_acl(se_nacl);
417 return ERR_PTR(ret);
418 }
419 }
420
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800421 return &se_nacl->acl_group;
422}
423
424static void target_fabric_drop_nodeacl(
425 struct config_group *group,
426 struct config_item *item)
427{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800428 struct se_node_acl *se_nacl = container_of(to_config_group(item),
429 struct se_node_acl, acl_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800430
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100431 configfs_remove_default_groups(&se_nacl->acl_group);
432
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800433 /*
434 * struct se_node_acl free is done in target_fabric_nacl_base_release()
435 */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800436 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800437}
438
439static struct configfs_group_operations target_fabric_nacl_group_ops = {
440 .make_group = target_fabric_make_nodeacl,
441 .drop_item = target_fabric_drop_nodeacl,
442};
443
444TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL);
445
446/* End of tfc_tpg_nacl_cit */
447
448/* Start of tfc_tpg_np_base_cit */
449
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800450static void target_fabric_np_base_release(struct config_item *item)
451{
452 struct se_tpg_np *se_tpg_np = container_of(to_config_group(item),
453 struct se_tpg_np, tpg_np_group);
454 struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent;
455 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
456
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200457 tf->tf_ops->fabric_drop_np(se_tpg_np);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800458}
459
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800460static struct configfs_item_operations target_fabric_np_base_item_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800461 .release = target_fabric_np_base_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800462};
463
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200464TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800465
466/* End of tfc_tpg_np_base_cit */
467
468/* Start of tfc_tpg_np_cit */
469
470static struct config_group *target_fabric_make_np(
471 struct config_group *group,
472 const char *name)
473{
474 struct se_portal_group *se_tpg = container_of(group,
475 struct se_portal_group, tpg_np_group);
476 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
477 struct se_tpg_np *se_tpg_np;
478
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200479 if (!tf->tf_ops->fabric_make_np) {
Andy Grover6708bb22011-06-08 10:36:43 -0700480 pr_err("tf->tf_ops.fabric_make_np is NULL\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800481 return ERR_PTR(-ENOSYS);
482 }
483
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200484 se_tpg_np = tf->tf_ops->fabric_make_np(se_tpg, group, name);
Andy Grover6708bb22011-06-08 10:36:43 -0700485 if (!se_tpg_np || IS_ERR(se_tpg_np))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800486 return ERR_PTR(-EINVAL);
487
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800488 se_tpg_np->tpg_np_parent = se_tpg;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800489 config_group_init_type_name(&se_tpg_np->tpg_np_group, name,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200490 &tf->tf_tpg_np_base_cit);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800491
492 return &se_tpg_np->tpg_np_group;
493}
494
495static void target_fabric_drop_np(
496 struct config_group *group,
497 struct config_item *item)
498{
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800499 /*
500 * struct se_tpg_np is released via target_fabric_np_base_release()
501 */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800502 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800503}
504
505static struct configfs_group_operations target_fabric_np_group_ops = {
506 .make_group = &target_fabric_make_np,
507 .drop_item = &target_fabric_drop_np,
508};
509
510TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL);
511
512/* End of tfc_tpg_np_cit */
513
514/* Start of tfc_tpg_port_cit */
515
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200516static struct se_lun *item_to_lun(struct config_item *item)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800517{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200518 return container_of(to_config_group(item), struct se_lun,
519 lun_group);
520}
521
522static ssize_t target_fabric_port_alua_tg_pt_gp_show(struct config_item *item,
523 char *page)
524{
525 struct se_lun *lun = item_to_lun(item);
526
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700527 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800528 return -ENODEV;
529
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700530 return core_alua_show_tg_pt_gp_info(lun, page);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800531}
532
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200533static ssize_t target_fabric_port_alua_tg_pt_gp_store(struct config_item *item,
534 const char *page, size_t count)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800535{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200536 struct se_lun *lun = item_to_lun(item);
537
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700538 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800539 return -ENODEV;
540
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700541 return core_alua_store_tg_pt_gp_info(lun, page, count);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800542}
543
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200544static ssize_t target_fabric_port_alua_tg_pt_offline_show(
545 struct config_item *item, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800546{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200547 struct se_lun *lun = item_to_lun(item);
548
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700549 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800550 return -ENODEV;
551
552 return core_alua_show_offline_bit(lun, page);
553}
554
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200555static ssize_t target_fabric_port_alua_tg_pt_offline_store(
556 struct config_item *item, const char *page, size_t count)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800557{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200558 struct se_lun *lun = item_to_lun(item);
559
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700560 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800561 return -ENODEV;
562
563 return core_alua_store_offline_bit(lun, page, count);
564}
565
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200566static ssize_t target_fabric_port_alua_tg_pt_status_show(
567 struct config_item *item, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800568{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200569 struct se_lun *lun = item_to_lun(item);
570
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700571 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800572 return -ENODEV;
573
574 return core_alua_show_secondary_status(lun, page);
575}
576
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200577static ssize_t target_fabric_port_alua_tg_pt_status_store(
578 struct config_item *item, const char *page, size_t count)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800579{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200580 struct se_lun *lun = item_to_lun(item);
581
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700582 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800583 return -ENODEV;
584
585 return core_alua_store_secondary_status(lun, page, count);
586}
587
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200588static ssize_t target_fabric_port_alua_tg_pt_write_md_show(
589 struct config_item *item, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800590{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200591 struct se_lun *lun = item_to_lun(item);
592
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700593 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800594 return -ENODEV;
595
596 return core_alua_show_secondary_write_metadata(lun, page);
597}
598
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200599static ssize_t target_fabric_port_alua_tg_pt_write_md_store(
600 struct config_item *item, const char *page, size_t count)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800601{
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200602 struct se_lun *lun = item_to_lun(item);
603
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700604 if (!lun || !lun->lun_se_dev)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800605 return -ENODEV;
606
607 return core_alua_store_secondary_write_metadata(lun, page, count);
608}
609
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200610CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_gp);
611CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_offline);
612CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_status);
613CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_write_md);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800614
615static struct configfs_attribute *target_fabric_port_attrs[] = {
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200616 &target_fabric_port_attr_alua_tg_pt_gp,
617 &target_fabric_port_attr_alua_tg_pt_offline,
618 &target_fabric_port_attr_alua_tg_pt_status,
619 &target_fabric_port_attr_alua_tg_pt_write_md,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800620 NULL,
621};
622
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800623static int target_fabric_port_link(
624 struct config_item *lun_ci,
625 struct config_item *se_dev_ci)
626{
627 struct config_item *tpg_ci;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800628 struct se_lun *lun = container_of(to_config_group(lun_ci),
629 struct se_lun, lun_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800630 struct se_portal_group *se_tpg;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400631 struct se_device *dev =
632 container_of(to_config_group(se_dev_ci), struct se_device, dev_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800633 struct target_fabric_configfs *tf;
634 int ret;
635
Nicholas Bellinger0ff87542012-12-04 23:43:57 -0800636 if (dev->dev_link_magic != SE_DEV_LINK_MAGIC) {
637 pr_err("Bad dev->dev_link_magic, not a valid se_dev_ci pointer:"
638 " %p to struct se_device: %p\n", se_dev_ci, dev);
639 return -EFAULT;
640 }
641
Nicholas Bellingerfaa06ab2013-01-31 14:56:12 -0800642 if (!(dev->dev_flags & DF_CONFIGURED)) {
643 pr_err("se_device not configured yet, cannot port link\n");
644 return -ENODEV;
645 }
646
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800647 tpg_ci = &lun_ci->ci_parent->ci_group->cg_item;
648 se_tpg = container_of(to_config_group(tpg_ci),
649 struct se_portal_group, tpg_group);
650 tf = se_tpg->se_tpg_wwn->wwn_tf;
651
652 if (lun->lun_se_dev != NULL) {
Andy Grover6708bb22011-06-08 10:36:43 -0700653 pr_err("Port Symlink already exists\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800654 return -EEXIST;
655 }
656
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700657 ret = core_dev_add_lun(se_tpg, dev, lun);
658 if (ret) {
659 pr_err("core_dev_add_lun() failed: %d\n", ret);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800660 goto out;
661 }
662
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200663 if (tf->tf_ops->fabric_post_link) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800664 /*
665 * Call the optional fabric_post_link() to allow a
666 * fabric module to setup any additional state once
667 * core_dev_add_lun() has been called..
668 */
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200669 tf->tf_ops->fabric_post_link(se_tpg, lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800670 }
671
672 return 0;
673out:
674 return ret;
675}
676
677static int target_fabric_port_unlink(
678 struct config_item *lun_ci,
679 struct config_item *se_dev_ci)
680{
681 struct se_lun *lun = container_of(to_config_group(lun_ci),
682 struct se_lun, lun_group);
Christoph Hellwigadf653f2015-05-25 21:33:08 -0700683 struct se_portal_group *se_tpg = lun->lun_tpg;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800684 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
685
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200686 if (tf->tf_ops->fabric_pre_unlink) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800687 /*
688 * Call the optional fabric_pre_unlink() to allow a
689 * fabric module to release any additional stat before
690 * core_dev_del_lun() is called.
691 */
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200692 tf->tf_ops->fabric_pre_unlink(se_tpg, lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800693 }
694
Andy Grovercd9d7cb2014-06-30 16:39:44 -0700695 core_dev_del_lun(se_tpg, lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800696 return 0;
697}
698
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700699static void target_fabric_port_release(struct config_item *item)
700{
701 struct se_lun *lun = container_of(to_config_group(item),
702 struct se_lun, lun_group);
703
704 kfree_rcu(lun, rcu_head);
705}
706
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800707static struct configfs_item_operations target_fabric_port_item_ops = {
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700708 .release = target_fabric_port_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800709 .allow_link = target_fabric_port_link,
710 .drop_link = target_fabric_port_unlink,
711};
712
713TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs);
714
715/* End of tfc_tpg_port_cit */
716
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700717/* Start of tfc_tpg_port_stat_cit */
718
719static struct config_group *target_core_port_stat_mkdir(
720 struct config_group *group,
721 const char *name)
722{
723 return ERR_PTR(-ENOSYS);
724}
725
726static void target_core_port_stat_rmdir(
727 struct config_group *group,
728 struct config_item *item)
729{
730 return;
731}
732
733static struct configfs_group_operations target_fabric_port_stat_group_ops = {
734 .make_group = target_core_port_stat_mkdir,
735 .drop_item = target_core_port_stat_rmdir,
736};
737
738TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL);
739
740/* End of tfc_tpg_port_stat_cit */
741
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800742/* Start of tfc_tpg_lun_cit */
743
744static struct config_group *target_fabric_make_lun(
745 struct config_group *group,
746 const char *name)
747{
748 struct se_lun *lun;
749 struct se_portal_group *se_tpg = container_of(group,
750 struct se_portal_group, tpg_lun_group);
751 struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf;
Hannes Reineckef2d30682015-06-10 08:41:22 +0200752 unsigned long long unpacked_lun;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700753 int errno;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800754
755 if (strstr(name, "lun_") != name) {
Andy Grover6708bb22011-06-08 10:36:43 -0700756 pr_err("Unable to locate \'_\" in"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800757 " \"lun_$LUN_NUMBER\"\n");
758 return ERR_PTR(-EINVAL);
759 }
Hannes Reineckef2d30682015-06-10 08:41:22 +0200760 errno = kstrtoull(name + 4, 0, &unpacked_lun);
Jingoo Han57103d72013-07-19 16:22:19 +0900761 if (errno)
762 return ERR_PTR(errno);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800763
Nicholas Bellinger6bb82612015-05-10 19:31:10 -0700764 lun = core_tpg_alloc_lun(se_tpg, unpacked_lun);
765 if (IS_ERR(lun))
766 return ERR_CAST(lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800767
768 config_group_init_type_name(&lun->lun_group, name,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200769 &tf->tf_tpg_port_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100770
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700771 config_group_init_type_name(&lun->port_stat_grps.stat_group,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200772 "statistics", &tf->tf_tpg_port_stat_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100773 configfs_add_default_group(&lun->port_stat_grps.stat_group,
774 &lun->lun_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700775
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700776 target_stat_setup_port_default_groups(lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800777
778 return &lun->lun_group;
779}
780
781static void target_fabric_drop_lun(
782 struct config_group *group,
783 struct config_item *item)
784{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700785 struct se_lun *lun = container_of(to_config_group(item),
786 struct se_lun, lun_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700787
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100788 configfs_remove_default_groups(&lun->port_stat_grps.stat_group);
789 configfs_remove_default_groups(&lun->lun_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700790
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800791 config_item_put(item);
792}
793
794static struct configfs_group_operations target_fabric_lun_group_ops = {
795 .make_group = &target_fabric_make_lun,
796 .drop_item = &target_fabric_drop_lun,
797};
798
799TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL);
800
801/* End of tfc_tpg_lun_cit */
802
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200803TF_CIT_SETUP_DRV(tpg_attrib, NULL, NULL);
804TF_CIT_SETUP_DRV(tpg_auth, NULL, NULL);
805TF_CIT_SETUP_DRV(tpg_param, NULL, NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800806
807/* Start of tfc_tpg_base_cit */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800808
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800809static void target_fabric_tpg_release(struct config_item *item)
810{
811 struct se_portal_group *se_tpg = container_of(to_config_group(item),
812 struct se_portal_group, tpg_group);
813 struct se_wwn *wwn = se_tpg->se_tpg_wwn;
814 struct target_fabric_configfs *tf = wwn->wwn_tf;
815
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200816 tf->tf_ops->fabric_drop_tpg(se_tpg);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800817}
818
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800819static struct configfs_item_operations target_fabric_tpg_base_item_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800820 .release = target_fabric_tpg_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800821};
822
Christoph Hellwig9ac89282015-04-08 20:01:35 +0200823TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800824
825/* End of tfc_tpg_base_cit */
826
827/* Start of tfc_tpg_cit */
828
829static struct config_group *target_fabric_make_tpg(
830 struct config_group *group,
831 const char *name)
832{
833 struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group);
834 struct target_fabric_configfs *tf = wwn->wwn_tf;
835 struct se_portal_group *se_tpg;
836
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200837 if (!tf->tf_ops->fabric_make_tpg) {
838 pr_err("tf->tf_ops->fabric_make_tpg is NULL\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800839 return ERR_PTR(-ENOSYS);
840 }
841
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200842 se_tpg = tf->tf_ops->fabric_make_tpg(wwn, group, name);
Andy Grover6708bb22011-06-08 10:36:43 -0700843 if (!se_tpg || IS_ERR(se_tpg))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800844 return ERR_PTR(-EINVAL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800845
846 config_group_init_type_name(&se_tpg->tpg_group, name,
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200847 &tf->tf_tpg_base_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100848
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800849 config_group_init_type_name(&se_tpg->tpg_lun_group, "lun",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200850 &tf->tf_tpg_lun_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100851 configfs_add_default_group(&se_tpg->tpg_lun_group,
852 &se_tpg->tpg_group);
853
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800854 config_group_init_type_name(&se_tpg->tpg_np_group, "np",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200855 &tf->tf_tpg_np_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100856 configfs_add_default_group(&se_tpg->tpg_np_group,
857 &se_tpg->tpg_group);
858
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800859 config_group_init_type_name(&se_tpg->tpg_acl_group, "acls",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200860 &tf->tf_tpg_nacl_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100861 configfs_add_default_group(&se_tpg->tpg_acl_group,
862 &se_tpg->tpg_group);
863
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800864 config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200865 &tf->tf_tpg_attrib_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100866 configfs_add_default_group(&se_tpg->tpg_attrib_group,
867 &se_tpg->tpg_group);
868
Nicholas Bellingere4b512e2013-06-19 18:37:00 -0700869 config_group_init_type_name(&se_tpg->tpg_auth_group, "auth",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200870 &tf->tf_tpg_auth_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100871 configfs_add_default_group(&se_tpg->tpg_auth_group,
872 &se_tpg->tpg_group);
873
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800874 config_group_init_type_name(&se_tpg->tpg_param_group, "param",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200875 &tf->tf_tpg_param_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100876 configfs_add_default_group(&se_tpg->tpg_param_group,
877 &se_tpg->tpg_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800878
879 return &se_tpg->tpg_group;
880}
881
882static void target_fabric_drop_tpg(
883 struct config_group *group,
884 struct config_item *item)
885{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800886 struct se_portal_group *se_tpg = container_of(to_config_group(item),
887 struct se_portal_group, tpg_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800888
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100889 configfs_remove_default_groups(&se_tpg->tpg_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800890 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800891}
892
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800893static void target_fabric_release_wwn(struct config_item *item)
894{
895 struct se_wwn *wwn = container_of(to_config_group(item),
896 struct se_wwn, wwn_group);
897 struct target_fabric_configfs *tf = wwn->wwn_tf;
898
Christoph Hellwig839559e2016-03-29 13:03:35 +0200899 configfs_remove_default_groups(&wwn->fabric_stat_group);
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200900 tf->tf_ops->fabric_drop_wwn(wwn);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800901}
902
903static struct configfs_item_operations target_fabric_tpg_item_ops = {
904 .release = target_fabric_release_wwn,
905};
906
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800907static struct configfs_group_operations target_fabric_tpg_group_ops = {
908 .make_group = target_fabric_make_tpg,
909 .drop_item = target_fabric_drop_tpg,
910};
911
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -0800912TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops,
913 NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800914
915/* End of tfc_tpg_cit */
916
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700917/* Start of tfc_wwn_fabric_stats_cit */
918/*
919 * This is used as a placeholder for struct se_wwn->fabric_stat_group
920 * to allow fabrics access to ->fabric_stat_group->default_groups[]
921 */
922TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL);
923
924/* End of tfc_wwn_fabric_stats_cit */
925
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800926/* Start of tfc_wwn_cit */
927
928static struct config_group *target_fabric_make_wwn(
929 struct config_group *group,
930 const char *name)
931{
932 struct target_fabric_configfs *tf = container_of(group,
933 struct target_fabric_configfs, tf_group);
934 struct se_wwn *wwn;
935
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200936 if (!tf->tf_ops->fabric_make_wwn) {
Andy Grover6708bb22011-06-08 10:36:43 -0700937 pr_err("tf->tf_ops.fabric_make_wwn is NULL\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800938 return ERR_PTR(-ENOSYS);
939 }
940
Christoph Hellwigef0caf82015-05-03 08:50:53 +0200941 wwn = tf->tf_ops->fabric_make_wwn(tf, group, name);
Andy Grover6708bb22011-06-08 10:36:43 -0700942 if (!wwn || IS_ERR(wwn))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800943 return ERR_PTR(-EINVAL);
944
945 wwn->wwn_tf = tf;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700946
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200947 config_group_init_type_name(&wwn->wwn_group, name, &tf->tf_tpg_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100948
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700949 config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics",
Christoph Hellwig968ebe72015-05-03 08:50:55 +0200950 &tf->tf_wwn_fabric_stats_cit);
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100951 configfs_add_default_group(&wwn->fabric_stat_group, &wwn->wwn_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800952
Christoph Hellwig839559e2016-03-29 13:03:35 +0200953 if (tf->tf_ops->add_wwn_groups)
954 tf->tf_ops->add_wwn_groups(wwn);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800955 return &wwn->wwn_group;
956}
957
958static void target_fabric_drop_wwn(
959 struct config_group *group,
960 struct config_item *item)
961{
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700962 struct se_wwn *wwn = container_of(to_config_group(item),
963 struct se_wwn, wwn_group);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700964
Christoph Hellwig1ae16022016-02-26 11:02:14 +0100965 configfs_remove_default_groups(&wwn->wwn_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800966 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800967}
968
969static struct configfs_group_operations target_fabric_wwn_group_ops = {
970 .make_group = target_fabric_make_wwn,
971 .drop_item = target_fabric_drop_wwn,
972};
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800973
Christoph Hellwig2eafd722015-10-03 15:32:55 +0200974TF_CIT_SETUP_DRV(wwn, NULL, &target_fabric_wwn_group_ops);
975TF_CIT_SETUP_DRV(discovery, NULL, NULL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800976
977int target_fabric_setup_cits(struct target_fabric_configfs *tf)
978{
979 target_fabric_setup_discovery_cit(tf);
980 target_fabric_setup_wwn_cit(tf);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700981 target_fabric_setup_wwn_fabric_stats_cit(tf);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800982 target_fabric_setup_tpg_cit(tf);
983 target_fabric_setup_tpg_base_cit(tf);
984 target_fabric_setup_tpg_port_cit(tf);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700985 target_fabric_setup_tpg_port_stat_cit(tf);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800986 target_fabric_setup_tpg_lun_cit(tf);
987 target_fabric_setup_tpg_np_cit(tf);
988 target_fabric_setup_tpg_np_base_cit(tf);
989 target_fabric_setup_tpg_attrib_cit(tf);
Nicholas Bellingere4b512e2013-06-19 18:37:00 -0700990 target_fabric_setup_tpg_auth_cit(tf);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800991 target_fabric_setup_tpg_param_cit(tf);
992 target_fabric_setup_tpg_nacl_cit(tf);
993 target_fabric_setup_tpg_nacl_base_cit(tf);
994 target_fabric_setup_tpg_nacl_attrib_cit(tf);
995 target_fabric_setup_tpg_nacl_auth_cit(tf);
996 target_fabric_setup_tpg_nacl_param_cit(tf);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700997 target_fabric_setup_tpg_nacl_stat_cit(tf);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800998 target_fabric_setup_tpg_mappedlun_cit(tf);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -0700999 target_fabric_setup_tpg_mappedlun_stat_cit(tf);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001000
1001 return 0;
1002}