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