Commit | Line | Data |
---|---|---|
c66ac9db NB |
1 | /******************************************************************************* |
2 | * Filename: target_core_fabric_configfs.c | |
3 | * | |
4 | * This file contains generic fabric module configfs infrastructure for | |
5 | * TCM v4.x code | |
6 | * | |
12d23384 NB |
7 | * Copyright (c) 2010,2011 Rising Tide Systems |
8 | * Copyright (c) 2010,2011 Linux-iSCSI.org | |
c66ac9db | 9 | * |
12d23384 | 10 | * Copyright (c) Nicholas A. Bellinger <nab@linux-iscsi.org> |
c66ac9db NB |
11 | * |
12 | * This program is free software; you can redistribute it and/or modify | |
13 | * it under the terms of the GNU General Public License as published by | |
14 | * the Free Software Foundation; either version 2 of the License, or | |
15 | * (at your option) any later version. | |
16 | * | |
17 | * This program is distributed in the hope that it will be useful, | |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 | * GNU General Public License for more details. | |
21 | ****************************************************************************/ | |
22 | ||
23 | #include <linux/module.h> | |
24 | #include <linux/moduleparam.h> | |
c66ac9db NB |
25 | #include <linux/utsname.h> |
26 | #include <linux/init.h> | |
27 | #include <linux/fs.h> | |
28 | #include <linux/namei.h> | |
29 | #include <linux/slab.h> | |
30 | #include <linux/types.h> | |
31 | #include <linux/delay.h> | |
32 | #include <linux/unistd.h> | |
33 | #include <linux/string.h> | |
34 | #include <linux/syscalls.h> | |
35 | #include <linux/configfs.h> | |
36 | ||
37 | #include <target/target_core_base.h> | |
c4795fb2 | 38 | #include <target/target_core_fabric.h> |
c66ac9db NB |
39 | #include <target/target_core_fabric_configfs.h> |
40 | #include <target/target_core_configfs.h> | |
41 | #include <target/configfs_macros.h> | |
42 | ||
e26d99ae | 43 | #include "target_core_internal.h" |
c66ac9db | 44 | #include "target_core_alua.h" |
c66ac9db NB |
45 | #include "target_core_pr.h" |
46 | ||
47 | #define TF_CIT_SETUP(_name, _item_ops, _group_ops, _attrs) \ | |
48 | static void target_fabric_setup_##_name##_cit(struct target_fabric_configfs *tf) \ | |
49 | { \ | |
50 | struct target_fabric_configfs_template *tfc = &tf->tf_cit_tmpl; \ | |
51 | struct config_item_type *cit = &tfc->tfc_##_name##_cit; \ | |
52 | \ | |
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; \ | |
6708bb27 | 57 | pr_debug("Setup generic %s\n", __stringify(_name)); \ |
c66ac9db NB |
58 | } |
59 | ||
60 | /* Start of tfc_tpg_mappedlun_cit */ | |
61 | ||
62 | static int target_fabric_mappedlun_link( | |
63 | struct config_item *lun_acl_ci, | |
64 | struct config_item *lun_ci) | |
65 | { | |
66 | struct se_dev_entry *deve; | |
67 | struct se_lun *lun = container_of(to_config_group(lun_ci), | |
68 | struct se_lun, lun_group); | |
69 | struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), | |
70 | struct se_lun_acl, se_lun_group); | |
71 | struct se_portal_group *se_tpg; | |
72 | struct config_item *nacl_ci, *tpg_ci, *tpg_ci_s, *wwn_ci, *wwn_ci_s; | |
73 | int ret = 0, lun_access; | |
74 | /* | |
75 | * Ensure that the source port exists | |
76 | */ | |
6708bb27 AG |
77 | if (!lun->lun_sep || !lun->lun_sep->sep_tpg) { |
78 | pr_err("Source se_lun->lun_sep or lun->lun_sep->sep" | |
c66ac9db NB |
79 | "_tpg does not exist\n"); |
80 | return -EINVAL; | |
81 | } | |
82 | se_tpg = lun->lun_sep->sep_tpg; | |
83 | ||
84 | nacl_ci = &lun_acl_ci->ci_parent->ci_group->cg_item; | |
85 | tpg_ci = &nacl_ci->ci_group->cg_item; | |
86 | wwn_ci = &tpg_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; | |
89 | /* | |
90 | * Make sure the SymLink is going to the same $FABRIC/$WWN/tpgt_$TPGT | |
91 | */ | |
92 | if (strcmp(config_item_name(wwn_ci), config_item_name(wwn_ci_s))) { | |
6708bb27 | 93 | pr_err("Illegal Initiator ACL SymLink outside of %s\n", |
c66ac9db NB |
94 | config_item_name(wwn_ci)); |
95 | return -EINVAL; | |
96 | } | |
97 | if (strcmp(config_item_name(tpg_ci), config_item_name(tpg_ci_s))) { | |
6708bb27 | 98 | pr_err("Illegal Initiator ACL Symlink outside of %s" |
c66ac9db NB |
99 | " TPGT: %s\n", config_item_name(wwn_ci), |
100 | config_item_name(tpg_ci)); | |
101 | return -EINVAL; | |
102 | } | |
103 | /* | |
104 | * If this struct se_node_acl was dynamically generated with | |
105 | * tpg_1/attrib/generate_node_acls=1, use the existing deve->lun_flags, | |
106 | * which be will write protected (READ-ONLY) when | |
107 | * tpg_1/attrib/demo_mode_write_protect=1 | |
108 | */ | |
109 | spin_lock_irq(&lacl->se_lun_nacl->device_list_lock); | |
f2083241 | 110 | deve = lacl->se_lun_nacl->device_list[lacl->mapped_lun]; |
c66ac9db NB |
111 | if (deve->lun_flags & TRANSPORT_LUNFLAGS_INITIATOR_ACCESS) |
112 | lun_access = deve->lun_flags; | |
113 | else | |
114 | lun_access = | |
e3d6f909 | 115 | (se_tpg->se_tpg_tfo->tpg_check_prod_mode_write_protect( |
c66ac9db NB |
116 | se_tpg)) ? TRANSPORT_LUNFLAGS_READ_ONLY : |
117 | TRANSPORT_LUNFLAGS_READ_WRITE; | |
118 | spin_unlock_irq(&lacl->se_lun_nacl->device_list_lock); | |
119 | /* | |
120 | * Determine the actual mapped LUN value user wants.. | |
121 | * | |
122 | * This value is what the SCSI Initiator actually sees the | |
123 | * iscsi/$IQN/$TPGT/lun/lun_* as on their SCSI Initiator Ports. | |
124 | */ | |
125 | ret = core_dev_add_initiator_node_lun_acl(se_tpg, lacl, | |
126 | lun->unpacked_lun, lun_access); | |
127 | ||
128 | return (ret < 0) ? -EINVAL : 0; | |
129 | } | |
130 | ||
131 | static int target_fabric_mappedlun_unlink( | |
132 | struct config_item *lun_acl_ci, | |
133 | struct config_item *lun_ci) | |
134 | { | |
135 | struct se_lun *lun; | |
136 | struct se_lun_acl *lacl = container_of(to_config_group(lun_acl_ci), | |
137 | struct se_lun_acl, se_lun_group); | |
138 | struct se_node_acl *nacl = lacl->se_lun_nacl; | |
f2083241 | 139 | struct se_dev_entry *deve = nacl->device_list[lacl->mapped_lun]; |
c66ac9db NB |
140 | struct se_portal_group *se_tpg; |
141 | /* | |
142 | * Determine if the underlying MappedLUN has already been released.. | |
143 | */ | |
6708bb27 | 144 | if (!deve->se_lun) |
c66ac9db NB |
145 | return 0; |
146 | ||
147 | lun = container_of(to_config_group(lun_ci), struct se_lun, lun_group); | |
148 | se_tpg = lun->lun_sep->sep_tpg; | |
149 | ||
150 | core_dev_del_initiator_node_lun_acl(se_tpg, lun, lacl); | |
151 | return 0; | |
152 | } | |
153 | ||
154 | CONFIGFS_EATTR_STRUCT(target_fabric_mappedlun, se_lun_acl); | |
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); | |
160 | ||
161 | static ssize_t target_fabric_mappedlun_show_write_protect( | |
162 | struct se_lun_acl *lacl, | |
163 | char *page) | |
164 | { | |
165 | struct se_node_acl *se_nacl = lacl->se_lun_nacl; | |
166 | struct se_dev_entry *deve; | |
167 | ssize_t len; | |
168 | ||
169 | spin_lock_irq(&se_nacl->device_list_lock); | |
f2083241 | 170 | deve = se_nacl->device_list[lacl->mapped_lun]; |
c66ac9db NB |
171 | len = sprintf(page, "%d\n", |
172 | (deve->lun_flags & TRANSPORT_LUNFLAGS_READ_ONLY) ? | |
173 | 1 : 0); | |
174 | spin_unlock_irq(&se_nacl->device_list_lock); | |
175 | ||
176 | return len; | |
177 | } | |
178 | ||
179 | static ssize_t target_fabric_mappedlun_store_write_protect( | |
180 | struct se_lun_acl *lacl, | |
181 | const char *page, | |
182 | size_t count) | |
183 | { | |
184 | struct se_node_acl *se_nacl = lacl->se_lun_nacl; | |
185 | struct se_portal_group *se_tpg = se_nacl->se_tpg; | |
186 | unsigned long op; | |
187 | ||
188 | if (strict_strtoul(page, 0, &op)) | |
189 | return -EINVAL; | |
190 | ||
191 | if ((op != 1) && (op != 0)) | |
192 | return -EINVAL; | |
193 | ||
194 | core_update_device_list_access(lacl->mapped_lun, (op) ? | |
195 | TRANSPORT_LUNFLAGS_READ_ONLY : | |
196 | TRANSPORT_LUNFLAGS_READ_WRITE, | |
197 | lacl->se_lun_nacl); | |
198 | ||
6708bb27 | 199 | pr_debug("%s_ConfigFS: Changed Initiator ACL: %s" |
c66ac9db | 200 | " Mapped LUN: %u Write Protect bit to %s\n", |
e3d6f909 | 201 | se_tpg->se_tpg_tfo->get_fabric_name(), |
c66ac9db NB |
202 | lacl->initiatorname, lacl->mapped_lun, (op) ? "ON" : "OFF"); |
203 | ||
204 | return count; | |
205 | ||
206 | } | |
207 | ||
208 | TCM_MAPPEDLUN_ATTR(write_protect, S_IRUGO | S_IWUSR); | |
209 | ||
210 | CONFIGFS_EATTR_OPS(target_fabric_mappedlun, se_lun_acl, se_lun_group); | |
211 | ||
1f6fe7cb NB |
212 | static void target_fabric_mappedlun_release(struct config_item *item) |
213 | { | |
214 | struct se_lun_acl *lacl = container_of(to_config_group(item), | |
215 | struct se_lun_acl, se_lun_group); | |
216 | struct se_portal_group *se_tpg = lacl->se_lun_nacl->se_tpg; | |
217 | ||
218 | core_dev_free_initiator_node_lun_acl(se_tpg, lacl); | |
219 | } | |
220 | ||
c66ac9db NB |
221 | static struct configfs_attribute *target_fabric_mappedlun_attrs[] = { |
222 | &target_fabric_mappedlun_write_protect.attr, | |
223 | NULL, | |
224 | }; | |
225 | ||
226 | static struct configfs_item_operations target_fabric_mappedlun_item_ops = { | |
1f6fe7cb | 227 | .release = target_fabric_mappedlun_release, |
c66ac9db NB |
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, | |
232 | }; | |
233 | ||
234 | TF_CIT_SETUP(tpg_mappedlun, &target_fabric_mappedlun_item_ops, NULL, | |
235 | target_fabric_mappedlun_attrs); | |
236 | ||
237 | /* End of tfc_tpg_mappedlun_cit */ | |
238 | ||
12d23384 NB |
239 | /* Start of tfc_tpg_mappedlun_port_cit */ |
240 | ||
241 | static struct config_group *target_core_mappedlun_stat_mkdir( | |
242 | struct config_group *group, | |
243 | const char *name) | |
244 | { | |
245 | return ERR_PTR(-ENOSYS); | |
246 | } | |
247 | ||
248 | static void target_core_mappedlun_stat_rmdir( | |
249 | struct config_group *group, | |
250 | struct config_item *item) | |
251 | { | |
252 | return; | |
253 | } | |
254 | ||
255 | static struct configfs_group_operations target_fabric_mappedlun_stat_group_ops = { | |
256 | .make_group = target_core_mappedlun_stat_mkdir, | |
257 | .drop_item = target_core_mappedlun_stat_rmdir, | |
258 | }; | |
259 | ||
260 | TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops, | |
261 | NULL); | |
262 | ||
263 | /* End of tfc_tpg_mappedlun_port_cit */ | |
264 | ||
c66ac9db NB |
265 | /* Start of tfc_tpg_nacl_attrib_cit */ |
266 | ||
267 | CONFIGFS_EATTR_OPS(target_fabric_nacl_attrib, se_node_acl, acl_attrib_group); | |
268 | ||
269 | static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = { | |
270 | .show_attribute = target_fabric_nacl_attrib_attr_show, | |
271 | .store_attribute = target_fabric_nacl_attrib_attr_store, | |
272 | }; | |
273 | ||
274 | TF_CIT_SETUP(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL, NULL); | |
275 | ||
276 | /* End of tfc_tpg_nacl_attrib_cit */ | |
277 | ||
278 | /* Start of tfc_tpg_nacl_auth_cit */ | |
279 | ||
280 | CONFIGFS_EATTR_OPS(target_fabric_nacl_auth, se_node_acl, acl_auth_group); | |
281 | ||
282 | static struct configfs_item_operations target_fabric_nacl_auth_item_ops = { | |
283 | .show_attribute = target_fabric_nacl_auth_attr_show, | |
284 | .store_attribute = target_fabric_nacl_auth_attr_store, | |
285 | }; | |
286 | ||
287 | TF_CIT_SETUP(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL, NULL); | |
288 | ||
289 | /* End of tfc_tpg_nacl_auth_cit */ | |
290 | ||
291 | /* Start of tfc_tpg_nacl_param_cit */ | |
292 | ||
293 | CONFIGFS_EATTR_OPS(target_fabric_nacl_param, se_node_acl, acl_param_group); | |
294 | ||
295 | static struct configfs_item_operations target_fabric_nacl_param_item_ops = { | |
296 | .show_attribute = target_fabric_nacl_param_attr_show, | |
297 | .store_attribute = target_fabric_nacl_param_attr_store, | |
298 | }; | |
299 | ||
300 | TF_CIT_SETUP(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL, NULL); | |
301 | ||
302 | /* End of tfc_tpg_nacl_param_cit */ | |
303 | ||
304 | /* Start of tfc_tpg_nacl_base_cit */ | |
305 | ||
306 | CONFIGFS_EATTR_OPS(target_fabric_nacl_base, se_node_acl, acl_group); | |
307 | ||
308 | static struct config_group *target_fabric_make_mappedlun( | |
309 | struct config_group *group, | |
310 | const char *name) | |
311 | { | |
312 | struct se_node_acl *se_nacl = container_of(group, | |
313 | struct se_node_acl, acl_group); | |
314 | struct se_portal_group *se_tpg = se_nacl->se_tpg; | |
315 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
316 | struct se_lun_acl *lacl; | |
317 | struct config_item *acl_ci; | |
12d23384 | 318 | struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; |
c66ac9db NB |
319 | char *buf; |
320 | unsigned long mapped_lun; | |
321 | int ret = 0; | |
322 | ||
323 | acl_ci = &group->cg_item; | |
6708bb27 AG |
324 | if (!acl_ci) { |
325 | pr_err("Unable to locatel acl_ci\n"); | |
c66ac9db NB |
326 | return NULL; |
327 | } | |
328 | ||
329 | buf = kzalloc(strlen(name) + 1, GFP_KERNEL); | |
6708bb27 AG |
330 | if (!buf) { |
331 | pr_err("Unable to allocate memory for name buf\n"); | |
c66ac9db NB |
332 | return ERR_PTR(-ENOMEM); |
333 | } | |
334 | snprintf(buf, strlen(name) + 1, "%s", name); | |
335 | /* | |
336 | * Make sure user is creating iscsi/$IQN/$TPGT/acls/$INITIATOR/lun_$ID. | |
337 | */ | |
338 | if (strstr(buf, "lun_") != buf) { | |
6708bb27 | 339 | pr_err("Unable to locate \"lun_\" from buf: %s" |
c66ac9db NB |
340 | " name: %s\n", buf, name); |
341 | ret = -EINVAL; | |
342 | goto out; | |
343 | } | |
344 | /* | |
345 | * Determine the Mapped LUN value. This is what the SCSI Initiator | |
346 | * Port will actually see. | |
347 | */ | |
348 | if (strict_strtoul(buf + 4, 0, &mapped_lun) || mapped_lun > UINT_MAX) { | |
349 | ret = -EINVAL; | |
350 | goto out; | |
351 | } | |
352 | ||
353 | lacl = core_dev_init_initiator_node_lun_acl(se_tpg, mapped_lun, | |
354 | config_item_name(acl_ci), &ret); | |
6708bb27 | 355 | if (!lacl) { |
12d23384 | 356 | ret = -EINVAL; |
c66ac9db | 357 | goto out; |
12d23384 NB |
358 | } |
359 | ||
360 | lacl_cg = &lacl->se_lun_group; | |
361 | lacl_cg->default_groups = kzalloc(sizeof(struct config_group) * 2, | |
362 | GFP_KERNEL); | |
363 | if (!lacl_cg->default_groups) { | |
6708bb27 | 364 | pr_err("Unable to allocate lacl_cg->default_groups\n"); |
12d23384 NB |
365 | ret = -ENOMEM; |
366 | goto out; | |
367 | } | |
c66ac9db NB |
368 | |
369 | config_group_init_type_name(&lacl->se_lun_group, name, | |
370 | &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_cit); | |
12d23384 NB |
371 | config_group_init_type_name(&lacl->ml_stat_grps.stat_group, |
372 | "statistics", &TF_CIT_TMPL(tf)->tfc_tpg_mappedlun_stat_cit); | |
373 | lacl_cg->default_groups[0] = &lacl->ml_stat_grps.stat_group; | |
374 | lacl_cg->default_groups[1] = NULL; | |
375 | ||
e3d6f909 | 376 | ml_stat_grp = &lacl->ml_stat_grps.stat_group; |
12d23384 NB |
377 | ml_stat_grp->default_groups = kzalloc(sizeof(struct config_group) * 3, |
378 | GFP_KERNEL); | |
379 | if (!ml_stat_grp->default_groups) { | |
6708bb27 | 380 | pr_err("Unable to allocate ml_stat_grp->default_groups\n"); |
12d23384 NB |
381 | ret = -ENOMEM; |
382 | goto out; | |
383 | } | |
384 | target_stat_setup_mappedlun_default_groups(lacl); | |
c66ac9db NB |
385 | |
386 | kfree(buf); | |
387 | return &lacl->se_lun_group; | |
388 | out: | |
12d23384 NB |
389 | if (lacl_cg) |
390 | kfree(lacl_cg->default_groups); | |
c66ac9db NB |
391 | kfree(buf); |
392 | return ERR_PTR(ret); | |
393 | } | |
394 | ||
395 | static void target_fabric_drop_mappedlun( | |
396 | struct config_group *group, | |
397 | struct config_item *item) | |
398 | { | |
12d23384 NB |
399 | struct se_lun_acl *lacl = container_of(to_config_group(item), |
400 | struct se_lun_acl, se_lun_group); | |
401 | struct config_item *df_item; | |
402 | struct config_group *lacl_cg = NULL, *ml_stat_grp = NULL; | |
403 | int i; | |
404 | ||
e3d6f909 | 405 | ml_stat_grp = &lacl->ml_stat_grps.stat_group; |
12d23384 NB |
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; | |
409 | config_item_put(df_item); | |
410 | } | |
411 | kfree(ml_stat_grp->default_groups); | |
412 | ||
413 | lacl_cg = &lacl->se_lun_group; | |
414 | for (i = 0; lacl_cg->default_groups[i]; i++) { | |
415 | df_item = &lacl_cg->default_groups[i]->cg_item; | |
416 | lacl_cg->default_groups[i] = NULL; | |
417 | config_item_put(df_item); | |
418 | } | |
419 | kfree(lacl_cg->default_groups); | |
420 | ||
c66ac9db | 421 | config_item_put(item); |
1f6fe7cb NB |
422 | } |
423 | ||
424 | static void target_fabric_nacl_base_release(struct config_item *item) | |
425 | { | |
426 | struct se_node_acl *se_nacl = container_of(to_config_group(item), | |
427 | struct se_node_acl, acl_group); | |
428 | struct se_portal_group *se_tpg = se_nacl->se_tpg; | |
429 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
430 | ||
431 | tf->tf_ops.fabric_drop_nodeacl(se_nacl); | |
c66ac9db NB |
432 | } |
433 | ||
434 | static struct configfs_item_operations target_fabric_nacl_base_item_ops = { | |
1f6fe7cb | 435 | .release = target_fabric_nacl_base_release, |
c66ac9db NB |
436 | .show_attribute = target_fabric_nacl_base_attr_show, |
437 | .store_attribute = target_fabric_nacl_base_attr_store, | |
438 | }; | |
439 | ||
440 | static struct configfs_group_operations target_fabric_nacl_base_group_ops = { | |
441 | .make_group = target_fabric_make_mappedlun, | |
442 | .drop_item = target_fabric_drop_mappedlun, | |
443 | }; | |
444 | ||
445 | TF_CIT_SETUP(tpg_nacl_base, &target_fabric_nacl_base_item_ops, | |
446 | &target_fabric_nacl_base_group_ops, NULL); | |
447 | ||
448 | /* End of tfc_tpg_nacl_base_cit */ | |
449 | ||
12d23384 NB |
450 | /* Start of tfc_node_fabric_stats_cit */ |
451 | /* | |
452 | * This is used as a placeholder for struct se_node_acl->acl_fabric_stat_group | |
453 | * to allow fabrics access to ->acl_fabric_stat_group->default_groups[] | |
454 | */ | |
455 | TF_CIT_SETUP(tpg_nacl_stat, NULL, NULL, NULL); | |
456 | ||
457 | /* End of tfc_wwn_fabric_stats_cit */ | |
458 | ||
c66ac9db NB |
459 | /* Start of tfc_tpg_nacl_cit */ |
460 | ||
461 | static struct config_group *target_fabric_make_nodeacl( | |
462 | struct config_group *group, | |
463 | const char *name) | |
464 | { | |
465 | struct se_portal_group *se_tpg = container_of(group, | |
466 | struct se_portal_group, tpg_acl_group); | |
467 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
468 | struct se_node_acl *se_nacl; | |
469 | struct config_group *nacl_cg; | |
470 | ||
6708bb27 AG |
471 | if (!tf->tf_ops.fabric_make_nodeacl) { |
472 | pr_err("tf->tf_ops.fabric_make_nodeacl is NULL\n"); | |
c66ac9db NB |
473 | return ERR_PTR(-ENOSYS); |
474 | } | |
475 | ||
476 | se_nacl = tf->tf_ops.fabric_make_nodeacl(se_tpg, group, name); | |
477 | if (IS_ERR(se_nacl)) | |
e1750ba2 | 478 | return ERR_CAST(se_nacl); |
c66ac9db NB |
479 | |
480 | nacl_cg = &se_nacl->acl_group; | |
481 | nacl_cg->default_groups = se_nacl->acl_default_groups; | |
482 | nacl_cg->default_groups[0] = &se_nacl->acl_attrib_group; | |
483 | nacl_cg->default_groups[1] = &se_nacl->acl_auth_group; | |
484 | nacl_cg->default_groups[2] = &se_nacl->acl_param_group; | |
12d23384 NB |
485 | nacl_cg->default_groups[3] = &se_nacl->acl_fabric_stat_group; |
486 | nacl_cg->default_groups[4] = NULL; | |
c66ac9db NB |
487 | |
488 | config_group_init_type_name(&se_nacl->acl_group, name, | |
489 | &TF_CIT_TMPL(tf)->tfc_tpg_nacl_base_cit); | |
490 | config_group_init_type_name(&se_nacl->acl_attrib_group, "attrib", | |
491 | &TF_CIT_TMPL(tf)->tfc_tpg_nacl_attrib_cit); | |
492 | config_group_init_type_name(&se_nacl->acl_auth_group, "auth", | |
493 | &TF_CIT_TMPL(tf)->tfc_tpg_nacl_auth_cit); | |
494 | config_group_init_type_name(&se_nacl->acl_param_group, "param", | |
495 | &TF_CIT_TMPL(tf)->tfc_tpg_nacl_param_cit); | |
12d23384 NB |
496 | config_group_init_type_name(&se_nacl->acl_fabric_stat_group, |
497 | "fabric_statistics", | |
498 | &TF_CIT_TMPL(tf)->tfc_tpg_nacl_stat_cit); | |
c66ac9db NB |
499 | |
500 | return &se_nacl->acl_group; | |
501 | } | |
502 | ||
503 | static void target_fabric_drop_nodeacl( | |
504 | struct config_group *group, | |
505 | struct config_item *item) | |
506 | { | |
c66ac9db NB |
507 | struct se_node_acl *se_nacl = container_of(to_config_group(item), |
508 | struct se_node_acl, acl_group); | |
509 | struct config_item *df_item; | |
510 | struct config_group *nacl_cg; | |
511 | int i; | |
512 | ||
513 | nacl_cg = &se_nacl->acl_group; | |
514 | for (i = 0; nacl_cg->default_groups[i]; i++) { | |
515 | df_item = &nacl_cg->default_groups[i]->cg_item; | |
516 | nacl_cg->default_groups[i] = NULL; | |
517 | config_item_put(df_item); | |
518 | } | |
1f6fe7cb NB |
519 | /* |
520 | * struct se_node_acl free is done in target_fabric_nacl_base_release() | |
521 | */ | |
c66ac9db | 522 | config_item_put(item); |
c66ac9db NB |
523 | } |
524 | ||
525 | static struct configfs_group_operations target_fabric_nacl_group_ops = { | |
526 | .make_group = target_fabric_make_nodeacl, | |
527 | .drop_item = target_fabric_drop_nodeacl, | |
528 | }; | |
529 | ||
530 | TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL); | |
531 | ||
532 | /* End of tfc_tpg_nacl_cit */ | |
533 | ||
534 | /* Start of tfc_tpg_np_base_cit */ | |
535 | ||
536 | CONFIGFS_EATTR_OPS(target_fabric_np_base, se_tpg_np, tpg_np_group); | |
537 | ||
1f6fe7cb NB |
538 | static void target_fabric_np_base_release(struct config_item *item) |
539 | { | |
540 | struct se_tpg_np *se_tpg_np = container_of(to_config_group(item), | |
541 | struct se_tpg_np, tpg_np_group); | |
542 | struct se_portal_group *se_tpg = se_tpg_np->tpg_np_parent; | |
543 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
544 | ||
545 | tf->tf_ops.fabric_drop_np(se_tpg_np); | |
546 | } | |
547 | ||
c66ac9db | 548 | static struct configfs_item_operations target_fabric_np_base_item_ops = { |
1f6fe7cb | 549 | .release = target_fabric_np_base_release, |
c66ac9db NB |
550 | .show_attribute = target_fabric_np_base_attr_show, |
551 | .store_attribute = target_fabric_np_base_attr_store, | |
552 | }; | |
553 | ||
554 | TF_CIT_SETUP(tpg_np_base, &target_fabric_np_base_item_ops, NULL, NULL); | |
555 | ||
556 | /* End of tfc_tpg_np_base_cit */ | |
557 | ||
558 | /* Start of tfc_tpg_np_cit */ | |
559 | ||
560 | static struct config_group *target_fabric_make_np( | |
561 | struct config_group *group, | |
562 | const char *name) | |
563 | { | |
564 | struct se_portal_group *se_tpg = container_of(group, | |
565 | struct se_portal_group, tpg_np_group); | |
566 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
567 | struct se_tpg_np *se_tpg_np; | |
568 | ||
6708bb27 AG |
569 | if (!tf->tf_ops.fabric_make_np) { |
570 | pr_err("tf->tf_ops.fabric_make_np is NULL\n"); | |
c66ac9db NB |
571 | return ERR_PTR(-ENOSYS); |
572 | } | |
573 | ||
574 | se_tpg_np = tf->tf_ops.fabric_make_np(se_tpg, group, name); | |
6708bb27 | 575 | if (!se_tpg_np || IS_ERR(se_tpg_np)) |
c66ac9db NB |
576 | return ERR_PTR(-EINVAL); |
577 | ||
1f6fe7cb | 578 | se_tpg_np->tpg_np_parent = se_tpg; |
c66ac9db NB |
579 | config_group_init_type_name(&se_tpg_np->tpg_np_group, name, |
580 | &TF_CIT_TMPL(tf)->tfc_tpg_np_base_cit); | |
581 | ||
582 | return &se_tpg_np->tpg_np_group; | |
583 | } | |
584 | ||
585 | static void target_fabric_drop_np( | |
586 | struct config_group *group, | |
587 | struct config_item *item) | |
588 | { | |
1f6fe7cb NB |
589 | /* |
590 | * struct se_tpg_np is released via target_fabric_np_base_release() | |
591 | */ | |
c66ac9db | 592 | config_item_put(item); |
c66ac9db NB |
593 | } |
594 | ||
595 | static struct configfs_group_operations target_fabric_np_group_ops = { | |
596 | .make_group = &target_fabric_make_np, | |
597 | .drop_item = &target_fabric_drop_np, | |
598 | }; | |
599 | ||
600 | TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL); | |
601 | ||
602 | /* End of tfc_tpg_np_cit */ | |
603 | ||
604 | /* Start of tfc_tpg_port_cit */ | |
605 | ||
606 | CONFIGFS_EATTR_STRUCT(target_fabric_port, se_lun); | |
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); | |
612 | ||
613 | #define TCM_PORT_ATTOR_RO(_name) \ | |
614 | __CONFIGFS_EATTR_RO(_name, \ | |
615 | target_fabric_port_show_attr_##_name); | |
616 | ||
617 | /* | |
618 | * alua_tg_pt_gp | |
619 | */ | |
620 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_gp( | |
621 | struct se_lun *lun, | |
622 | char *page) | |
623 | { | |
6708bb27 | 624 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
625 | return -ENODEV; |
626 | ||
627 | return core_alua_show_tg_pt_gp_info(lun->lun_sep, page); | |
628 | } | |
629 | ||
630 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp( | |
631 | struct se_lun *lun, | |
632 | const char *page, | |
633 | size_t count) | |
634 | { | |
6708bb27 | 635 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
636 | return -ENODEV; |
637 | ||
638 | return core_alua_store_tg_pt_gp_info(lun->lun_sep, page, count); | |
639 | } | |
640 | ||
641 | TCM_PORT_ATTR(alua_tg_pt_gp, S_IRUGO | S_IWUSR); | |
642 | ||
643 | /* | |
644 | * alua_tg_pt_offline | |
645 | */ | |
646 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_offline( | |
647 | struct se_lun *lun, | |
648 | char *page) | |
649 | { | |
6708bb27 | 650 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
651 | return -ENODEV; |
652 | ||
653 | return core_alua_show_offline_bit(lun, page); | |
654 | } | |
655 | ||
656 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_offline( | |
657 | struct se_lun *lun, | |
658 | const char *page, | |
659 | size_t count) | |
660 | { | |
6708bb27 | 661 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
662 | return -ENODEV; |
663 | ||
664 | return core_alua_store_offline_bit(lun, page, count); | |
665 | } | |
666 | ||
667 | TCM_PORT_ATTR(alua_tg_pt_offline, S_IRUGO | S_IWUSR); | |
668 | ||
669 | /* | |
670 | * alua_tg_pt_status | |
671 | */ | |
672 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_status( | |
673 | struct se_lun *lun, | |
674 | char *page) | |
675 | { | |
6708bb27 | 676 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
677 | return -ENODEV; |
678 | ||
679 | return core_alua_show_secondary_status(lun, page); | |
680 | } | |
681 | ||
682 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_status( | |
683 | struct se_lun *lun, | |
684 | const char *page, | |
685 | size_t count) | |
686 | { | |
6708bb27 | 687 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
688 | return -ENODEV; |
689 | ||
690 | return core_alua_store_secondary_status(lun, page, count); | |
691 | } | |
692 | ||
693 | TCM_PORT_ATTR(alua_tg_pt_status, S_IRUGO | S_IWUSR); | |
694 | ||
695 | /* | |
696 | * alua_tg_pt_write_md | |
697 | */ | |
698 | static ssize_t target_fabric_port_show_attr_alua_tg_pt_write_md( | |
699 | struct se_lun *lun, | |
700 | char *page) | |
701 | { | |
6708bb27 | 702 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
703 | return -ENODEV; |
704 | ||
705 | return core_alua_show_secondary_write_metadata(lun, page); | |
706 | } | |
707 | ||
708 | static ssize_t target_fabric_port_store_attr_alua_tg_pt_write_md( | |
709 | struct se_lun *lun, | |
710 | const char *page, | |
711 | size_t count) | |
712 | { | |
6708bb27 | 713 | if (!lun || !lun->lun_sep) |
c66ac9db NB |
714 | return -ENODEV; |
715 | ||
716 | return core_alua_store_secondary_write_metadata(lun, page, count); | |
717 | } | |
718 | ||
719 | TCM_PORT_ATTR(alua_tg_pt_write_md, S_IRUGO | S_IWUSR); | |
720 | ||
721 | ||
722 | static struct configfs_attribute *target_fabric_port_attrs[] = { | |
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, | |
727 | NULL, | |
728 | }; | |
729 | ||
730 | CONFIGFS_EATTR_OPS(target_fabric_port, se_lun, lun_group); | |
731 | ||
732 | static int target_fabric_port_link( | |
733 | struct config_item *lun_ci, | |
734 | struct config_item *se_dev_ci) | |
735 | { | |
736 | struct config_item *tpg_ci; | |
c66ac9db NB |
737 | struct se_lun *lun = container_of(to_config_group(lun_ci), |
738 | struct se_lun, lun_group); | |
739 | struct se_lun *lun_p; | |
740 | struct se_portal_group *se_tpg; | |
0fd97ccf CH |
741 | struct se_device *dev = |
742 | container_of(to_config_group(se_dev_ci), struct se_device, dev_group); | |
c66ac9db NB |
743 | struct target_fabric_configfs *tf; |
744 | int ret; | |
745 | ||
746 | tpg_ci = &lun_ci->ci_parent->ci_group->cg_item; | |
747 | se_tpg = container_of(to_config_group(tpg_ci), | |
748 | struct se_portal_group, tpg_group); | |
749 | tf = se_tpg->se_tpg_wwn->wwn_tf; | |
750 | ||
751 | if (lun->lun_se_dev != NULL) { | |
6708bb27 | 752 | pr_err("Port Symlink already exists\n"); |
c66ac9db NB |
753 | return -EEXIST; |
754 | } | |
755 | ||
2dca673b | 756 | lun_p = core_dev_add_lun(se_tpg, dev, lun->unpacked_lun); |
8d9efe53 | 757 | if (IS_ERR(lun_p)) { |
6708bb27 | 758 | pr_err("core_dev_add_lun() failed\n"); |
8d9efe53 | 759 | ret = PTR_ERR(lun_p); |
c66ac9db NB |
760 | goto out; |
761 | } | |
762 | ||
763 | if (tf->tf_ops.fabric_post_link) { | |
764 | /* | |
765 | * Call the optional fabric_post_link() to allow a | |
766 | * fabric module to setup any additional state once | |
767 | * core_dev_add_lun() has been called.. | |
768 | */ | |
769 | tf->tf_ops.fabric_post_link(se_tpg, lun); | |
770 | } | |
771 | ||
772 | return 0; | |
773 | out: | |
774 | return ret; | |
775 | } | |
776 | ||
777 | static int target_fabric_port_unlink( | |
778 | struct config_item *lun_ci, | |
779 | struct config_item *se_dev_ci) | |
780 | { | |
781 | struct se_lun *lun = container_of(to_config_group(lun_ci), | |
782 | struct se_lun, lun_group); | |
783 | struct se_portal_group *se_tpg = lun->lun_sep->sep_tpg; | |
784 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
785 | ||
786 | if (tf->tf_ops.fabric_pre_unlink) { | |
787 | /* | |
788 | * Call the optional fabric_pre_unlink() to allow a | |
789 | * fabric module to release any additional stat before | |
790 | * core_dev_del_lun() is called. | |
791 | */ | |
792 | tf->tf_ops.fabric_pre_unlink(se_tpg, lun); | |
793 | } | |
794 | ||
795 | core_dev_del_lun(se_tpg, lun->unpacked_lun); | |
796 | return 0; | |
797 | } | |
798 | ||
799 | static struct configfs_item_operations target_fabric_port_item_ops = { | |
800 | .show_attribute = target_fabric_port_attr_show, | |
801 | .store_attribute = target_fabric_port_attr_store, | |
802 | .allow_link = target_fabric_port_link, | |
803 | .drop_link = target_fabric_port_unlink, | |
804 | }; | |
805 | ||
806 | TF_CIT_SETUP(tpg_port, &target_fabric_port_item_ops, NULL, target_fabric_port_attrs); | |
807 | ||
808 | /* End of tfc_tpg_port_cit */ | |
809 | ||
12d23384 NB |
810 | /* Start of tfc_tpg_port_stat_cit */ |
811 | ||
812 | static struct config_group *target_core_port_stat_mkdir( | |
813 | struct config_group *group, | |
814 | const char *name) | |
815 | { | |
816 | return ERR_PTR(-ENOSYS); | |
817 | } | |
818 | ||
819 | static void target_core_port_stat_rmdir( | |
820 | struct config_group *group, | |
821 | struct config_item *item) | |
822 | { | |
823 | return; | |
824 | } | |
825 | ||
826 | static struct configfs_group_operations target_fabric_port_stat_group_ops = { | |
827 | .make_group = target_core_port_stat_mkdir, | |
828 | .drop_item = target_core_port_stat_rmdir, | |
829 | }; | |
830 | ||
831 | TF_CIT_SETUP(tpg_port_stat, NULL, &target_fabric_port_stat_group_ops, NULL); | |
832 | ||
833 | /* End of tfc_tpg_port_stat_cit */ | |
834 | ||
c66ac9db NB |
835 | /* Start of tfc_tpg_lun_cit */ |
836 | ||
837 | static struct config_group *target_fabric_make_lun( | |
838 | struct config_group *group, | |
839 | const char *name) | |
840 | { | |
841 | struct se_lun *lun; | |
842 | struct se_portal_group *se_tpg = container_of(group, | |
843 | struct se_portal_group, tpg_lun_group); | |
844 | struct target_fabric_configfs *tf = se_tpg->se_tpg_wwn->wwn_tf; | |
12d23384 | 845 | struct config_group *lun_cg = NULL, *port_stat_grp = NULL; |
c66ac9db | 846 | unsigned long unpacked_lun; |
12d23384 | 847 | int errno; |
c66ac9db NB |
848 | |
849 | if (strstr(name, "lun_") != name) { | |
6708bb27 | 850 | pr_err("Unable to locate \'_\" in" |
c66ac9db NB |
851 | " \"lun_$LUN_NUMBER\"\n"); |
852 | return ERR_PTR(-EINVAL); | |
853 | } | |
854 | if (strict_strtoul(name + 4, 0, &unpacked_lun) || unpacked_lun > UINT_MAX) | |
855 | return ERR_PTR(-EINVAL); | |
856 | ||
857 | lun = core_get_lun_from_tpg(se_tpg, unpacked_lun); | |
6708bb27 | 858 | if (!lun) |
c66ac9db NB |
859 | return ERR_PTR(-EINVAL); |
860 | ||
12d23384 NB |
861 | lun_cg = &lun->lun_group; |
862 | lun_cg->default_groups = kzalloc(sizeof(struct config_group) * 2, | |
863 | GFP_KERNEL); | |
864 | if (!lun_cg->default_groups) { | |
6708bb27 | 865 | pr_err("Unable to allocate lun_cg->default_groups\n"); |
12d23384 NB |
866 | return ERR_PTR(-ENOMEM); |
867 | } | |
868 | ||
c66ac9db NB |
869 | config_group_init_type_name(&lun->lun_group, name, |
870 | &TF_CIT_TMPL(tf)->tfc_tpg_port_cit); | |
12d23384 NB |
871 | config_group_init_type_name(&lun->port_stat_grps.stat_group, |
872 | "statistics", &TF_CIT_TMPL(tf)->tfc_tpg_port_stat_cit); | |
873 | lun_cg->default_groups[0] = &lun->port_stat_grps.stat_group; | |
874 | lun_cg->default_groups[1] = NULL; | |
875 | ||
e3d6f909 | 876 | port_stat_grp = &lun->port_stat_grps.stat_group; |
12d23384 NB |
877 | port_stat_grp->default_groups = kzalloc(sizeof(struct config_group) * 3, |
878 | GFP_KERNEL); | |
879 | if (!port_stat_grp->default_groups) { | |
6708bb27 | 880 | pr_err("Unable to allocate port_stat_grp->default_groups\n"); |
12d23384 NB |
881 | errno = -ENOMEM; |
882 | goto out; | |
883 | } | |
884 | target_stat_setup_port_default_groups(lun); | |
c66ac9db NB |
885 | |
886 | return &lun->lun_group; | |
12d23384 NB |
887 | out: |
888 | if (lun_cg) | |
889 | kfree(lun_cg->default_groups); | |
890 | return ERR_PTR(errno); | |
c66ac9db NB |
891 | } |
892 | ||
893 | static void target_fabric_drop_lun( | |
894 | struct config_group *group, | |
895 | struct config_item *item) | |
896 | { | |
12d23384 NB |
897 | struct se_lun *lun = container_of(to_config_group(item), |
898 | struct se_lun, lun_group); | |
899 | struct config_item *df_item; | |
900 | struct config_group *lun_cg, *port_stat_grp; | |
901 | int i; | |
902 | ||
e3d6f909 | 903 | port_stat_grp = &lun->port_stat_grps.stat_group; |
12d23384 NB |
904 | for (i = 0; port_stat_grp->default_groups[i]; i++) { |
905 | df_item = &port_stat_grp->default_groups[i]->cg_item; | |
906 | port_stat_grp->default_groups[i] = NULL; | |
907 | config_item_put(df_item); | |
908 | } | |
909 | kfree(port_stat_grp->default_groups); | |
910 | ||
911 | lun_cg = &lun->lun_group; | |
912 | for (i = 0; lun_cg->default_groups[i]; i++) { | |
913 | df_item = &lun_cg->default_groups[i]->cg_item; | |
914 | lun_cg->default_groups[i] = NULL; | |
915 | config_item_put(df_item); | |
916 | } | |
917 | kfree(lun_cg->default_groups); | |
918 | ||
c66ac9db NB |
919 | config_item_put(item); |
920 | } | |
921 | ||
922 | static struct configfs_group_operations target_fabric_lun_group_ops = { | |
923 | .make_group = &target_fabric_make_lun, | |
924 | .drop_item = &target_fabric_drop_lun, | |
925 | }; | |
926 | ||
927 | TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL); | |
928 | ||
929 | /* End of tfc_tpg_lun_cit */ | |
930 | ||
931 | /* Start of tfc_tpg_attrib_cit */ | |
932 | ||
933 | CONFIGFS_EATTR_OPS(target_fabric_tpg_attrib, se_portal_group, tpg_attrib_group); | |
934 | ||
935 | static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = { | |
936 | .show_attribute = target_fabric_tpg_attrib_attr_show, | |
937 | .store_attribute = target_fabric_tpg_attrib_attr_store, | |
938 | }; | |
939 | ||
940 | TF_CIT_SETUP(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL, NULL); | |
941 | ||
942 | /* End of tfc_tpg_attrib_cit */ | |
943 | ||
944 | /* Start of tfc_tpg_param_cit */ | |
945 | ||
946 | CONFIGFS_EATTR_OPS(target_fabric_tpg_param, se_portal_group, tpg_param_group); | |
947 | ||
948 | static struct configfs_item_operations target_fabric_tpg_param_item_ops = { | |
949 | .show_attribute = target_fabric_tpg_param_attr_show, | |
950 | .store_attribute = target_fabric_tpg_param_attr_store, | |
951 | }; | |
952 | ||
953 | TF_CIT_SETUP(tpg_param, &target_fabric_tpg_param_item_ops, NULL, NULL); | |
954 | ||
955 | /* End of tfc_tpg_param_cit */ | |
956 | ||
957 | /* Start of tfc_tpg_base_cit */ | |
958 | /* | |
959 | * For use with TF_TPG_ATTR() and TF_TPG_ATTR_RO() | |
960 | */ | |
961 | CONFIGFS_EATTR_OPS(target_fabric_tpg, se_portal_group, tpg_group); | |
962 | ||
1f6fe7cb NB |
963 | static void target_fabric_tpg_release(struct config_item *item) |
964 | { | |
965 | struct se_portal_group *se_tpg = container_of(to_config_group(item), | |
966 | struct se_portal_group, tpg_group); | |
967 | struct se_wwn *wwn = se_tpg->se_tpg_wwn; | |
968 | struct target_fabric_configfs *tf = wwn->wwn_tf; | |
969 | ||
970 | tf->tf_ops.fabric_drop_tpg(se_tpg); | |
971 | } | |
972 | ||
c66ac9db | 973 | static struct configfs_item_operations target_fabric_tpg_base_item_ops = { |
1f6fe7cb | 974 | .release = target_fabric_tpg_release, |
c66ac9db NB |
975 | .show_attribute = target_fabric_tpg_attr_show, |
976 | .store_attribute = target_fabric_tpg_attr_store, | |
977 | }; | |
978 | ||
979 | TF_CIT_SETUP(tpg_base, &target_fabric_tpg_base_item_ops, NULL, NULL); | |
980 | ||
981 | /* End of tfc_tpg_base_cit */ | |
982 | ||
983 | /* Start of tfc_tpg_cit */ | |
984 | ||
985 | static struct config_group *target_fabric_make_tpg( | |
986 | struct config_group *group, | |
987 | const char *name) | |
988 | { | |
989 | struct se_wwn *wwn = container_of(group, struct se_wwn, wwn_group); | |
990 | struct target_fabric_configfs *tf = wwn->wwn_tf; | |
991 | struct se_portal_group *se_tpg; | |
992 | ||
6708bb27 AG |
993 | if (!tf->tf_ops.fabric_make_tpg) { |
994 | pr_err("tf->tf_ops.fabric_make_tpg is NULL\n"); | |
c66ac9db NB |
995 | return ERR_PTR(-ENOSYS); |
996 | } | |
997 | ||
998 | se_tpg = tf->tf_ops.fabric_make_tpg(wwn, group, name); | |
6708bb27 | 999 | if (!se_tpg || IS_ERR(se_tpg)) |
c66ac9db NB |
1000 | return ERR_PTR(-EINVAL); |
1001 | /* | |
1002 | * Setup default groups from pre-allocated se_tpg->tpg_default_groups | |
1003 | */ | |
1004 | se_tpg->tpg_group.default_groups = se_tpg->tpg_default_groups; | |
1005 | se_tpg->tpg_group.default_groups[0] = &se_tpg->tpg_lun_group; | |
1006 | se_tpg->tpg_group.default_groups[1] = &se_tpg->tpg_np_group; | |
1007 | se_tpg->tpg_group.default_groups[2] = &se_tpg->tpg_acl_group; | |
1008 | se_tpg->tpg_group.default_groups[3] = &se_tpg->tpg_attrib_group; | |
1009 | se_tpg->tpg_group.default_groups[4] = &se_tpg->tpg_param_group; | |
1010 | se_tpg->tpg_group.default_groups[5] = NULL; | |
1011 | ||
1012 | config_group_init_type_name(&se_tpg->tpg_group, name, | |
1013 | &TF_CIT_TMPL(tf)->tfc_tpg_base_cit); | |
1014 | config_group_init_type_name(&se_tpg->tpg_lun_group, "lun", | |
1015 | &TF_CIT_TMPL(tf)->tfc_tpg_lun_cit); | |
1016 | config_group_init_type_name(&se_tpg->tpg_np_group, "np", | |
1017 | &TF_CIT_TMPL(tf)->tfc_tpg_np_cit); | |
1018 | config_group_init_type_name(&se_tpg->tpg_acl_group, "acls", | |
1019 | &TF_CIT_TMPL(tf)->tfc_tpg_nacl_cit); | |
1020 | config_group_init_type_name(&se_tpg->tpg_attrib_group, "attrib", | |
1021 | &TF_CIT_TMPL(tf)->tfc_tpg_attrib_cit); | |
1022 | config_group_init_type_name(&se_tpg->tpg_param_group, "param", | |
1023 | &TF_CIT_TMPL(tf)->tfc_tpg_param_cit); | |
1024 | ||
1025 | return &se_tpg->tpg_group; | |
1026 | } | |
1027 | ||
1028 | static void target_fabric_drop_tpg( | |
1029 | struct config_group *group, | |
1030 | struct config_item *item) | |
1031 | { | |
c66ac9db NB |
1032 | struct se_portal_group *se_tpg = container_of(to_config_group(item), |
1033 | struct se_portal_group, tpg_group); | |
1034 | struct config_group *tpg_cg = &se_tpg->tpg_group; | |
1035 | struct config_item *df_item; | |
1036 | int i; | |
1037 | /* | |
1038 | * Release default groups, but do not release tpg_cg->default_groups | |
1039 | * memory as it is statically allocated at se_tpg->tpg_default_groups. | |
1040 | */ | |
1041 | for (i = 0; tpg_cg->default_groups[i]; i++) { | |
1042 | df_item = &tpg_cg->default_groups[i]->cg_item; | |
1043 | tpg_cg->default_groups[i] = NULL; | |
1044 | config_item_put(df_item); | |
1045 | } | |
1046 | ||
1047 | config_item_put(item); | |
c66ac9db NB |
1048 | } |
1049 | ||
1f6fe7cb NB |
1050 | static void target_fabric_release_wwn(struct config_item *item) |
1051 | { | |
1052 | struct se_wwn *wwn = container_of(to_config_group(item), | |
1053 | struct se_wwn, wwn_group); | |
1054 | struct target_fabric_configfs *tf = wwn->wwn_tf; | |
1055 | ||
1056 | tf->tf_ops.fabric_drop_wwn(wwn); | |
1057 | } | |
1058 | ||
1059 | static struct configfs_item_operations target_fabric_tpg_item_ops = { | |
1060 | .release = target_fabric_release_wwn, | |
1061 | }; | |
1062 | ||
c66ac9db NB |
1063 | static struct configfs_group_operations target_fabric_tpg_group_ops = { |
1064 | .make_group = target_fabric_make_tpg, | |
1065 | .drop_item = target_fabric_drop_tpg, | |
1066 | }; | |
1067 | ||
1f6fe7cb NB |
1068 | TF_CIT_SETUP(tpg, &target_fabric_tpg_item_ops, &target_fabric_tpg_group_ops, |
1069 | NULL); | |
c66ac9db NB |
1070 | |
1071 | /* End of tfc_tpg_cit */ | |
1072 | ||
12d23384 NB |
1073 | /* Start of tfc_wwn_fabric_stats_cit */ |
1074 | /* | |
1075 | * This is used as a placeholder for struct se_wwn->fabric_stat_group | |
1076 | * to allow fabrics access to ->fabric_stat_group->default_groups[] | |
1077 | */ | |
1078 | TF_CIT_SETUP(wwn_fabric_stats, NULL, NULL, NULL); | |
1079 | ||
1080 | /* End of tfc_wwn_fabric_stats_cit */ | |
1081 | ||
c66ac9db NB |
1082 | /* Start of tfc_wwn_cit */ |
1083 | ||
1084 | static struct config_group *target_fabric_make_wwn( | |
1085 | struct config_group *group, | |
1086 | const char *name) | |
1087 | { | |
1088 | struct target_fabric_configfs *tf = container_of(group, | |
1089 | struct target_fabric_configfs, tf_group); | |
1090 | struct se_wwn *wwn; | |
1091 | ||
6708bb27 AG |
1092 | if (!tf->tf_ops.fabric_make_wwn) { |
1093 | pr_err("tf->tf_ops.fabric_make_wwn is NULL\n"); | |
c66ac9db NB |
1094 | return ERR_PTR(-ENOSYS); |
1095 | } | |
1096 | ||
1097 | wwn = tf->tf_ops.fabric_make_wwn(tf, group, name); | |
6708bb27 | 1098 | if (!wwn || IS_ERR(wwn)) |
c66ac9db NB |
1099 | return ERR_PTR(-EINVAL); |
1100 | ||
1101 | wwn->wwn_tf = tf; | |
12d23384 NB |
1102 | /* |
1103 | * Setup default groups from pre-allocated wwn->wwn_default_groups | |
1104 | */ | |
1105 | wwn->wwn_group.default_groups = wwn->wwn_default_groups; | |
1106 | wwn->wwn_group.default_groups[0] = &wwn->fabric_stat_group; | |
1107 | wwn->wwn_group.default_groups[1] = NULL; | |
1108 | ||
c66ac9db NB |
1109 | config_group_init_type_name(&wwn->wwn_group, name, |
1110 | &TF_CIT_TMPL(tf)->tfc_tpg_cit); | |
12d23384 NB |
1111 | config_group_init_type_name(&wwn->fabric_stat_group, "fabric_statistics", |
1112 | &TF_CIT_TMPL(tf)->tfc_wwn_fabric_stats_cit); | |
c66ac9db NB |
1113 | |
1114 | return &wwn->wwn_group; | |
1115 | } | |
1116 | ||
1117 | static void target_fabric_drop_wwn( | |
1118 | struct config_group *group, | |
1119 | struct config_item *item) | |
1120 | { | |
12d23384 NB |
1121 | struct se_wwn *wwn = container_of(to_config_group(item), |
1122 | struct se_wwn, wwn_group); | |
1123 | struct config_item *df_item; | |
1124 | struct config_group *cg = &wwn->wwn_group; | |
1125 | int i; | |
1126 | ||
1127 | for (i = 0; cg->default_groups[i]; i++) { | |
1128 | df_item = &cg->default_groups[i]->cg_item; | |
1129 | cg->default_groups[i] = NULL; | |
1130 | config_item_put(df_item); | |
1131 | } | |
1132 | ||
c66ac9db | 1133 | config_item_put(item); |
c66ac9db NB |
1134 | } |
1135 | ||
1136 | static struct configfs_group_operations target_fabric_wwn_group_ops = { | |
1137 | .make_group = target_fabric_make_wwn, | |
1138 | .drop_item = target_fabric_drop_wwn, | |
1139 | }; | |
1140 | /* | |
1141 | * For use with TF_WWN_ATTR() and TF_WWN_ATTR_RO() | |
1142 | */ | |
1143 | CONFIGFS_EATTR_OPS(target_fabric_wwn, target_fabric_configfs, tf_group); | |
1144 | ||
1145 | static struct configfs_item_operations target_fabric_wwn_item_ops = { | |
1146 | .show_attribute = target_fabric_wwn_attr_show, | |
1147 | .store_attribute = target_fabric_wwn_attr_store, | |
1148 | }; | |
1149 | ||
1150 | TF_CIT_SETUP(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops, NULL); | |
1151 | ||
1152 | /* End of tfc_wwn_cit */ | |
1153 | ||
1154 | /* Start of tfc_discovery_cit */ | |
1155 | ||
1156 | CONFIGFS_EATTR_OPS(target_fabric_discovery, target_fabric_configfs, | |
1157 | tf_disc_group); | |
1158 | ||
1159 | static struct configfs_item_operations target_fabric_discovery_item_ops = { | |
1160 | .show_attribute = target_fabric_discovery_attr_show, | |
1161 | .store_attribute = target_fabric_discovery_attr_store, | |
1162 | }; | |
1163 | ||
1164 | TF_CIT_SETUP(discovery, &target_fabric_discovery_item_ops, NULL, NULL); | |
1165 | ||
1166 | /* End of tfc_discovery_cit */ | |
1167 | ||
1168 | int target_fabric_setup_cits(struct target_fabric_configfs *tf) | |
1169 | { | |
1170 | target_fabric_setup_discovery_cit(tf); | |
1171 | target_fabric_setup_wwn_cit(tf); | |
12d23384 | 1172 | target_fabric_setup_wwn_fabric_stats_cit(tf); |
c66ac9db NB |
1173 | target_fabric_setup_tpg_cit(tf); |
1174 | target_fabric_setup_tpg_base_cit(tf); | |
1175 | target_fabric_setup_tpg_port_cit(tf); | |
12d23384 | 1176 | target_fabric_setup_tpg_port_stat_cit(tf); |
c66ac9db NB |
1177 | target_fabric_setup_tpg_lun_cit(tf); |
1178 | target_fabric_setup_tpg_np_cit(tf); | |
1179 | target_fabric_setup_tpg_np_base_cit(tf); | |
1180 | target_fabric_setup_tpg_attrib_cit(tf); | |
1181 | target_fabric_setup_tpg_param_cit(tf); | |
1182 | target_fabric_setup_tpg_nacl_cit(tf); | |
1183 | target_fabric_setup_tpg_nacl_base_cit(tf); | |
1184 | target_fabric_setup_tpg_nacl_attrib_cit(tf); | |
1185 | target_fabric_setup_tpg_nacl_auth_cit(tf); | |
1186 | target_fabric_setup_tpg_nacl_param_cit(tf); | |
12d23384 | 1187 | target_fabric_setup_tpg_nacl_stat_cit(tf); |
c66ac9db | 1188 | target_fabric_setup_tpg_mappedlun_cit(tf); |
12d23384 | 1189 | target_fabric_setup_tpg_mappedlun_stat_cit(tf); |
c66ac9db NB |
1190 | |
1191 | return 0; | |
1192 | } |