blob: 43b7ac6c5b1c80e5132bb793d4a447abf11f443c [file] [log] [blame]
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001/*******************************************************************************
2 * Filename: target_core_configfs.c
3 *
4 * This file contains ConfigFS logic for the Generic Target Engine project.
5 *
Nicholas Bellingerfd9a11d2012-11-09 14:51:48 -08006 * (c) Copyright 2008-2012 RisingTide Systems LLC.
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08007 *
8 * Nicholas A. Bellinger <nab@kernel.org>
9 *
10 * based on configfs Copyright (C) 2005 Oracle. All rights reserved.
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>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080025#include <generated/utsrelease.h>
26#include <linux/utsname.h>
27#include <linux/init.h>
28#include <linux/fs.h>
29#include <linux/namei.h>
30#include <linux/slab.h>
31#include <linux/types.h>
32#include <linux/delay.h>
33#include <linux/unistd.h>
34#include <linux/string.h>
35#include <linux/parser.h>
36#include <linux/syscalls.h>
37#include <linux/configfs.h>
Andy Grovere3d6f902011-07-19 08:55:10 +000038#include <linux/spinlock.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080039
40#include <target/target_core_base.h>
Christoph Hellwigc4795fb2011-11-16 09:46:48 -050041#include <target/target_core_backend.h>
42#include <target/target_core_fabric.h>
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080043#include <target/target_core_fabric_configfs.h>
44#include <target/target_core_configfs.h>
45#include <target/configfs_macros.h>
46
Christoph Hellwige26d99a2011-11-14 12:30:30 -050047#include "target_core_internal.h"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080048#include "target_core_alua.h"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080049#include "target_core_pr.h"
50#include "target_core_rd.h"
51
Andy Grovere3d6f902011-07-19 08:55:10 +000052extern struct t10_alua_lu_gp *default_lu_gp;
53
Roland Dreierd0f474e2012-01-12 10:41:18 -080054static LIST_HEAD(g_tf_list);
55static DEFINE_MUTEX(g_tf_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080056
57struct target_core_configfs_attribute {
58 struct configfs_attribute attr;
59 ssize_t (*show)(void *, char *);
60 ssize_t (*store)(void *, const char *, size_t);
61};
62
Andy Grovere3d6f902011-07-19 08:55:10 +000063static struct config_group target_core_hbagroup;
64static struct config_group alua_group;
65static struct config_group alua_lu_gps_group;
66
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -080067static inline struct se_hba *
68item_to_hba(struct config_item *item)
69{
70 return container_of(to_config_group(item), struct se_hba, hba_group);
71}
72
73/*
74 * Attributes for /sys/kernel/config/target/
75 */
76static ssize_t target_core_attr_show(struct config_item *item,
77 struct configfs_attribute *attr,
78 char *page)
79{
80 return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s"
81 " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_CONFIGFS_VERSION,
82 utsname()->sysname, utsname()->machine);
83}
84
85static struct configfs_item_operations target_core_fabric_item_ops = {
86 .show_attribute = target_core_attr_show,
87};
88
89static struct configfs_attribute target_core_item_attr_version = {
90 .ca_owner = THIS_MODULE,
91 .ca_name = "version",
92 .ca_mode = S_IRUGO,
93};
94
95static struct target_fabric_configfs *target_core_get_fabric(
96 const char *name)
97{
98 struct target_fabric_configfs *tf;
99
Andy Grover6708bb22011-06-08 10:36:43 -0700100 if (!name)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800101 return NULL;
102
103 mutex_lock(&g_tf_lock);
104 list_for_each_entry(tf, &g_tf_list, tf_list) {
Andy Grover6708bb22011-06-08 10:36:43 -0700105 if (!strcmp(tf->tf_name, name)) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800106 atomic_inc(&tf->tf_access_cnt);
107 mutex_unlock(&g_tf_lock);
108 return tf;
109 }
110 }
111 mutex_unlock(&g_tf_lock);
112
113 return NULL;
114}
115
116/*
117 * Called from struct target_core_group_ops->make_group()
118 */
119static struct config_group *target_core_register_fabric(
120 struct config_group *group,
121 const char *name)
122{
123 struct target_fabric_configfs *tf;
124 int ret;
125
Andy Grover6708bb22011-06-08 10:36:43 -0700126 pr_debug("Target_Core_ConfigFS: REGISTER -> group: %p name:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800127 " %s\n", group, name);
128 /*
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800129 * Below are some hardcoded request_module() calls to automatically
130 * local fabric modules when the following is called:
131 *
132 * mkdir -p /sys/kernel/config/target/$MODULE_NAME
133 *
134 * Note that this does not limit which TCM fabric module can be
135 * registered, but simply provids auto loading logic for modules with
136 * mkdir(2) system calls with known TCM fabric modules.
137 */
Andy Grover6708bb22011-06-08 10:36:43 -0700138 if (!strncmp(name, "iscsi", 5)) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800139 /*
140 * Automatically load the LIO Target fabric module when the
141 * following is called:
142 *
143 * mkdir -p $CONFIGFS/target/iscsi
144 */
145 ret = request_module("iscsi_target_mod");
146 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -0700147 pr_err("request_module() failed for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800148 " iscsi_target_mod.ko: %d\n", ret);
149 return ERR_PTR(-EINVAL);
150 }
Andy Grover6708bb22011-06-08 10:36:43 -0700151 } else if (!strncmp(name, "loopback", 8)) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800152 /*
153 * Automatically load the tcm_loop fabric module when the
154 * following is called:
155 *
156 * mkdir -p $CONFIGFS/target/loopback
157 */
158 ret = request_module("tcm_loop");
159 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -0700160 pr_err("request_module() failed for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800161 " tcm_loop.ko: %d\n", ret);
162 return ERR_PTR(-EINVAL);
163 }
164 }
165
166 tf = target_core_get_fabric(name);
Andy Grover6708bb22011-06-08 10:36:43 -0700167 if (!tf) {
168 pr_err("target_core_get_fabric() failed for %s\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800169 name);
170 return ERR_PTR(-EINVAL);
171 }
Andy Grover6708bb22011-06-08 10:36:43 -0700172 pr_debug("Target_Core_ConfigFS: REGISTER -> Located fabric:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800173 " %s\n", tf->tf_name);
174 /*
175 * On a successful target_core_get_fabric() look, the returned
176 * struct target_fabric_configfs *tf will contain a usage reference.
177 */
Andy Grover6708bb22011-06-08 10:36:43 -0700178 pr_debug("Target_Core_ConfigFS: REGISTER tfc_wwn_cit -> %p\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800179 &TF_CIT_TMPL(tf)->tfc_wwn_cit);
180
181 tf->tf_group.default_groups = tf->tf_default_groups;
182 tf->tf_group.default_groups[0] = &tf->tf_disc_group;
183 tf->tf_group.default_groups[1] = NULL;
184
185 config_group_init_type_name(&tf->tf_group, name,
186 &TF_CIT_TMPL(tf)->tfc_wwn_cit);
187 config_group_init_type_name(&tf->tf_disc_group, "discovery_auth",
188 &TF_CIT_TMPL(tf)->tfc_discovery_cit);
189
Andy Grover6708bb22011-06-08 10:36:43 -0700190 pr_debug("Target_Core_ConfigFS: REGISTER -> Allocated Fabric:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800191 " %s\n", tf->tf_group.cg_item.ci_name);
192 /*
193 * Setup tf_ops.tf_subsys pointer for usage with configfs_depend_item()
194 */
195 tf->tf_ops.tf_subsys = tf->tf_subsys;
196 tf->tf_fabric = &tf->tf_group.cg_item;
Andy Grover6708bb22011-06-08 10:36:43 -0700197 pr_debug("Target_Core_ConfigFS: REGISTER -> Set tf->tf_fabric"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800198 " for %s\n", name);
199
200 return &tf->tf_group;
201}
202
203/*
204 * Called from struct target_core_group_ops->drop_item()
205 */
206static void target_core_deregister_fabric(
207 struct config_group *group,
208 struct config_item *item)
209{
210 struct target_fabric_configfs *tf = container_of(
211 to_config_group(item), struct target_fabric_configfs, tf_group);
212 struct config_group *tf_group;
213 struct config_item *df_item;
214 int i;
215
Andy Grover6708bb22011-06-08 10:36:43 -0700216 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Looking up %s in"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800217 " tf list\n", config_item_name(item));
218
Andy Grover6708bb22011-06-08 10:36:43 -0700219 pr_debug("Target_Core_ConfigFS: DEREGISTER -> located fabric:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800220 " %s\n", tf->tf_name);
221 atomic_dec(&tf->tf_access_cnt);
222
Andy Grover6708bb22011-06-08 10:36:43 -0700223 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800224 " tf->tf_fabric for %s\n", tf->tf_name);
225 tf->tf_fabric = NULL;
226
Andy Grover6708bb22011-06-08 10:36:43 -0700227 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing ci"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800228 " %s\n", config_item_name(item));
229
230 tf_group = &tf->tf_group;
231 for (i = 0; tf_group->default_groups[i]; i++) {
232 df_item = &tf_group->default_groups[i]->cg_item;
233 tf_group->default_groups[i] = NULL;
234 config_item_put(df_item);
235 }
236 config_item_put(item);
237}
238
239static struct configfs_group_operations target_core_fabric_group_ops = {
240 .make_group = &target_core_register_fabric,
241 .drop_item = &target_core_deregister_fabric,
242};
243
244/*
245 * All item attributes appearing in /sys/kernel/target/ appear here.
246 */
247static struct configfs_attribute *target_core_fabric_item_attrs[] = {
248 &target_core_item_attr_version,
249 NULL,
250};
251
252/*
253 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
254 */
255static struct config_item_type target_core_fabrics_item = {
256 .ct_item_ops = &target_core_fabric_item_ops,
257 .ct_group_ops = &target_core_fabric_group_ops,
258 .ct_attrs = target_core_fabric_item_attrs,
259 .ct_owner = THIS_MODULE,
260};
261
262static struct configfs_subsystem target_core_fabrics = {
263 .su_group = {
264 .cg_item = {
265 .ci_namebuf = "target",
266 .ci_type = &target_core_fabrics_item,
267 },
268 },
269};
270
271static struct configfs_subsystem *target_core_subsystem[] = {
272 &target_core_fabrics,
273 NULL,
274};
275
276/*##############################################################################
277// Start functions called by external Target Fabrics Modules
278//############################################################################*/
279
280/*
281 * First function called by fabric modules to:
282 *
283 * 1) Allocate a struct target_fabric_configfs and save the *fabric_cit pointer.
284 * 2) Add struct target_fabric_configfs to g_tf_list
285 * 3) Return struct target_fabric_configfs to fabric module to be passed
286 * into target_fabric_configfs_register().
287 */
288struct target_fabric_configfs *target_fabric_configfs_init(
289 struct module *fabric_mod,
290 const char *name)
291{
292 struct target_fabric_configfs *tf;
293
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800294 if (!(name)) {
Andy Grover6708bb22011-06-08 10:36:43 -0700295 pr_err("Unable to locate passed fabric name\n");
Andy Grovere3d6f902011-07-19 08:55:10 +0000296 return ERR_PTR(-EINVAL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800297 }
Dan Carpenter60d645a2011-06-15 10:03:05 -0700298 if (strlen(name) >= TARGET_FABRIC_NAME_SIZE) {
Andy Grover6708bb22011-06-08 10:36:43 -0700299 pr_err("Passed name: %s exceeds TARGET_FABRIC"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800300 "_NAME_SIZE\n", name);
Andy Grovere3d6f902011-07-19 08:55:10 +0000301 return ERR_PTR(-EINVAL);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800302 }
303
304 tf = kzalloc(sizeof(struct target_fabric_configfs), GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -0700305 if (!tf)
Andy Grovere3d6f902011-07-19 08:55:10 +0000306 return ERR_PTR(-ENOMEM);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800307
308 INIT_LIST_HEAD(&tf->tf_list);
309 atomic_set(&tf->tf_access_cnt, 0);
310 /*
311 * Setup the default generic struct config_item_type's (cits) in
312 * struct target_fabric_configfs->tf_cit_tmpl
313 */
314 tf->tf_module = fabric_mod;
315 target_fabric_setup_cits(tf);
316
317 tf->tf_subsys = target_core_subsystem[0];
318 snprintf(tf->tf_name, TARGET_FABRIC_NAME_SIZE, "%s", name);
319
320 mutex_lock(&g_tf_lock);
321 list_add_tail(&tf->tf_list, &g_tf_list);
322 mutex_unlock(&g_tf_lock);
323
Andy Grover6708bb22011-06-08 10:36:43 -0700324 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800325 ">>>>>>>>>>>>>>\n");
Andy Grover6708bb22011-06-08 10:36:43 -0700326 pr_debug("Initialized struct target_fabric_configfs: %p for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800327 " %s\n", tf, tf->tf_name);
328 return tf;
329}
330EXPORT_SYMBOL(target_fabric_configfs_init);
331
332/*
333 * Called by fabric plugins after FAILED target_fabric_configfs_register() call.
334 */
335void target_fabric_configfs_free(
336 struct target_fabric_configfs *tf)
337{
338 mutex_lock(&g_tf_lock);
339 list_del(&tf->tf_list);
340 mutex_unlock(&g_tf_lock);
341
342 kfree(tf);
343}
344EXPORT_SYMBOL(target_fabric_configfs_free);
345
346/*
347 * Perform a sanity check of the passed tf->tf_ops before completing
348 * TCM fabric module registration.
349 */
350static int target_fabric_tf_ops_check(
351 struct target_fabric_configfs *tf)
352{
353 struct target_core_fabric_ops *tfo = &tf->tf_ops;
354
Andy Grover6708bb22011-06-08 10:36:43 -0700355 if (!tfo->get_fabric_name) {
356 pr_err("Missing tfo->get_fabric_name()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800357 return -EINVAL;
358 }
Andy Grover6708bb22011-06-08 10:36:43 -0700359 if (!tfo->get_fabric_proto_ident) {
360 pr_err("Missing tfo->get_fabric_proto_ident()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800361 return -EINVAL;
362 }
Andy Grover6708bb22011-06-08 10:36:43 -0700363 if (!tfo->tpg_get_wwn) {
364 pr_err("Missing tfo->tpg_get_wwn()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800365 return -EINVAL;
366 }
Andy Grover6708bb22011-06-08 10:36:43 -0700367 if (!tfo->tpg_get_tag) {
368 pr_err("Missing tfo->tpg_get_tag()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800369 return -EINVAL;
370 }
Andy Grover6708bb22011-06-08 10:36:43 -0700371 if (!tfo->tpg_get_default_depth) {
372 pr_err("Missing tfo->tpg_get_default_depth()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800373 return -EINVAL;
374 }
Andy Grover6708bb22011-06-08 10:36:43 -0700375 if (!tfo->tpg_get_pr_transport_id) {
376 pr_err("Missing tfo->tpg_get_pr_transport_id()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800377 return -EINVAL;
378 }
Andy Grover6708bb22011-06-08 10:36:43 -0700379 if (!tfo->tpg_get_pr_transport_id_len) {
380 pr_err("Missing tfo->tpg_get_pr_transport_id_len()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800381 return -EINVAL;
382 }
Andy Grover6708bb22011-06-08 10:36:43 -0700383 if (!tfo->tpg_check_demo_mode) {
384 pr_err("Missing tfo->tpg_check_demo_mode()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800385 return -EINVAL;
386 }
Andy Grover6708bb22011-06-08 10:36:43 -0700387 if (!tfo->tpg_check_demo_mode_cache) {
388 pr_err("Missing tfo->tpg_check_demo_mode_cache()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800389 return -EINVAL;
390 }
Andy Grover6708bb22011-06-08 10:36:43 -0700391 if (!tfo->tpg_check_demo_mode_write_protect) {
392 pr_err("Missing tfo->tpg_check_demo_mode_write_protect()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800393 return -EINVAL;
394 }
Andy Grover6708bb22011-06-08 10:36:43 -0700395 if (!tfo->tpg_check_prod_mode_write_protect) {
396 pr_err("Missing tfo->tpg_check_prod_mode_write_protect()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800397 return -EINVAL;
398 }
Andy Grover6708bb22011-06-08 10:36:43 -0700399 if (!tfo->tpg_alloc_fabric_acl) {
400 pr_err("Missing tfo->tpg_alloc_fabric_acl()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800401 return -EINVAL;
402 }
Andy Grover6708bb22011-06-08 10:36:43 -0700403 if (!tfo->tpg_release_fabric_acl) {
404 pr_err("Missing tfo->tpg_release_fabric_acl()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800405 return -EINVAL;
406 }
Andy Grover6708bb22011-06-08 10:36:43 -0700407 if (!tfo->tpg_get_inst_index) {
408 pr_err("Missing tfo->tpg_get_inst_index()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800409 return -EINVAL;
410 }
Christoph Hellwig35462972011-05-31 23:56:57 -0400411 if (!tfo->release_cmd) {
Andy Grover6708bb22011-06-08 10:36:43 -0700412 pr_err("Missing tfo->release_cmd()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800413 return -EINVAL;
414 }
Andy Grover6708bb22011-06-08 10:36:43 -0700415 if (!tfo->shutdown_session) {
416 pr_err("Missing tfo->shutdown_session()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800417 return -EINVAL;
418 }
Andy Grover6708bb22011-06-08 10:36:43 -0700419 if (!tfo->close_session) {
420 pr_err("Missing tfo->close_session()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800421 return -EINVAL;
422 }
Andy Grover6708bb22011-06-08 10:36:43 -0700423 if (!tfo->sess_get_index) {
424 pr_err("Missing tfo->sess_get_index()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800425 return -EINVAL;
426 }
Andy Grover6708bb22011-06-08 10:36:43 -0700427 if (!tfo->write_pending) {
428 pr_err("Missing tfo->write_pending()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800429 return -EINVAL;
430 }
Andy Grover6708bb22011-06-08 10:36:43 -0700431 if (!tfo->write_pending_status) {
432 pr_err("Missing tfo->write_pending_status()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800433 return -EINVAL;
434 }
Andy Grover6708bb22011-06-08 10:36:43 -0700435 if (!tfo->set_default_node_attributes) {
436 pr_err("Missing tfo->set_default_node_attributes()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800437 return -EINVAL;
438 }
Andy Grover6708bb22011-06-08 10:36:43 -0700439 if (!tfo->get_task_tag) {
440 pr_err("Missing tfo->get_task_tag()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800441 return -EINVAL;
442 }
Andy Grover6708bb22011-06-08 10:36:43 -0700443 if (!tfo->get_cmd_state) {
444 pr_err("Missing tfo->get_cmd_state()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800445 return -EINVAL;
446 }
Andy Grover6708bb22011-06-08 10:36:43 -0700447 if (!tfo->queue_data_in) {
448 pr_err("Missing tfo->queue_data_in()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800449 return -EINVAL;
450 }
Andy Grover6708bb22011-06-08 10:36:43 -0700451 if (!tfo->queue_status) {
452 pr_err("Missing tfo->queue_status()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800453 return -EINVAL;
454 }
Andy Grover6708bb22011-06-08 10:36:43 -0700455 if (!tfo->queue_tm_rsp) {
456 pr_err("Missing tfo->queue_tm_rsp()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800457 return -EINVAL;
458 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800459 /*
460 * We at least require tfo->fabric_make_wwn(), tfo->fabric_drop_wwn()
461 * tfo->fabric_make_tpg() and tfo->fabric_drop_tpg() in
462 * target_core_fabric_configfs.c WWN+TPG group context code.
463 */
Andy Grover6708bb22011-06-08 10:36:43 -0700464 if (!tfo->fabric_make_wwn) {
465 pr_err("Missing tfo->fabric_make_wwn()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800466 return -EINVAL;
467 }
Andy Grover6708bb22011-06-08 10:36:43 -0700468 if (!tfo->fabric_drop_wwn) {
469 pr_err("Missing tfo->fabric_drop_wwn()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800470 return -EINVAL;
471 }
Andy Grover6708bb22011-06-08 10:36:43 -0700472 if (!tfo->fabric_make_tpg) {
473 pr_err("Missing tfo->fabric_make_tpg()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800474 return -EINVAL;
475 }
Andy Grover6708bb22011-06-08 10:36:43 -0700476 if (!tfo->fabric_drop_tpg) {
477 pr_err("Missing tfo->fabric_drop_tpg()\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800478 return -EINVAL;
479 }
480
481 return 0;
482}
483
484/*
485 * Called 2nd from fabric module with returned parameter of
486 * struct target_fabric_configfs * from target_fabric_configfs_init().
487 *
488 * Upon a successful registration, the new fabric's struct config_item is
489 * return. Also, a pointer to this struct is set in the passed
490 * struct target_fabric_configfs.
491 */
492int target_fabric_configfs_register(
493 struct target_fabric_configfs *tf)
494{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800495 int ret;
496
Andy Grover6708bb22011-06-08 10:36:43 -0700497 if (!tf) {
498 pr_err("Unable to locate target_fabric_configfs"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800499 " pointer\n");
500 return -EINVAL;
501 }
Andy Grover6708bb22011-06-08 10:36:43 -0700502 if (!tf->tf_subsys) {
503 pr_err("Unable to target struct config_subsystem"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800504 " pointer\n");
505 return -EINVAL;
506 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800507 ret = target_fabric_tf_ops_check(tf);
508 if (ret < 0)
509 return ret;
510
Andy Grover6708bb22011-06-08 10:36:43 -0700511 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800512 ">>>>>>>>>>\n");
513 return 0;
514}
515EXPORT_SYMBOL(target_fabric_configfs_register);
516
517void target_fabric_configfs_deregister(
518 struct target_fabric_configfs *tf)
519{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800520 struct configfs_subsystem *su;
521
Andy Grover6708bb22011-06-08 10:36:43 -0700522 if (!tf) {
523 pr_err("Unable to locate passed target_fabric_"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800524 "configfs\n");
525 return;
526 }
527 su = tf->tf_subsys;
Andy Grover6708bb22011-06-08 10:36:43 -0700528 if (!su) {
529 pr_err("Unable to locate passed tf->tf_subsys"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800530 " pointer\n");
531 return;
532 }
Andy Grover6708bb22011-06-08 10:36:43 -0700533 pr_debug("<<<<<<<<<<<<<<<<<<<<<< BEGIN FABRIC API >>>>>>>>>>"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800534 ">>>>>>>>>>>>\n");
535 mutex_lock(&g_tf_lock);
536 if (atomic_read(&tf->tf_access_cnt)) {
537 mutex_unlock(&g_tf_lock);
Andy Grover6708bb22011-06-08 10:36:43 -0700538 pr_err("Non zero tf->tf_access_cnt for fabric %s\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800539 tf->tf_name);
540 BUG();
541 }
542 list_del(&tf->tf_list);
543 mutex_unlock(&g_tf_lock);
544
Andy Grover6708bb22011-06-08 10:36:43 -0700545 pr_debug("Target_Core_ConfigFS: DEREGISTER -> Releasing tf:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800546 " %s\n", tf->tf_name);
547 tf->tf_module = NULL;
548 tf->tf_subsys = NULL;
549 kfree(tf);
550
Andy Grover6708bb22011-06-08 10:36:43 -0700551 pr_debug("<<<<<<<<<<<<<<<<<<<<<< END FABRIC API >>>>>>>>>>>>>>>>>"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800552 ">>>>>\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800553}
554EXPORT_SYMBOL(target_fabric_configfs_deregister);
555
556/*##############################################################################
557// Stop functions called by external Target Fabrics Modules
558//############################################################################*/
559
560/* Start functions for struct config_item_type target_core_dev_attrib_cit */
561
562#define DEF_DEV_ATTRIB_SHOW(_name) \
563static ssize_t target_core_dev_show_attr_##_name( \
564 struct se_dev_attrib *da, \
565 char *page) \
566{ \
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400567 return snprintf(page, PAGE_SIZE, "%u\n", \
568 (u32)da->da_dev->dev_attrib._name); \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800569}
570
571#define DEF_DEV_ATTRIB_STORE(_name) \
572static ssize_t target_core_dev_store_attr_##_name( \
573 struct se_dev_attrib *da, \
574 const char *page, \
575 size_t count) \
576{ \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800577 unsigned long val; \
578 int ret; \
579 \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800580 ret = strict_strtoul(page, 0, &val); \
581 if (ret < 0) { \
Andy Grover6708bb22011-06-08 10:36:43 -0700582 pr_err("strict_strtoul() failed with" \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800583 " ret: %d\n", ret); \
584 return -EINVAL; \
585 } \
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400586 ret = se_dev_set_##_name(da->da_dev, (u32)val); \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800587 \
588 return (!ret) ? count : -EINVAL; \
589}
590
591#define DEF_DEV_ATTRIB(_name) \
592DEF_DEV_ATTRIB_SHOW(_name); \
593DEF_DEV_ATTRIB_STORE(_name);
594
595#define DEF_DEV_ATTRIB_RO(_name) \
596DEF_DEV_ATTRIB_SHOW(_name);
597
598CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib);
599#define SE_DEV_ATTR(_name, _mode) \
600static struct target_core_dev_attrib_attribute \
601 target_core_dev_attrib_##_name = \
602 __CONFIGFS_EATTR(_name, _mode, \
603 target_core_dev_show_attr_##_name, \
604 target_core_dev_store_attr_##_name);
605
606#define SE_DEV_ATTR_RO(_name); \
607static struct target_core_dev_attrib_attribute \
608 target_core_dev_attrib_##_name = \
609 __CONFIGFS_EATTR_RO(_name, \
610 target_core_dev_show_attr_##_name);
611
Tregaron Baylyadfa9572013-01-31 15:30:24 -0700612DEF_DEV_ATTRIB(emulate_model_alias);
613SE_DEV_ATTR(emulate_model_alias, S_IRUGO | S_IWUSR);
614
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800615DEF_DEV_ATTRIB(emulate_dpo);
616SE_DEV_ATTR(emulate_dpo, S_IRUGO | S_IWUSR);
617
618DEF_DEV_ATTRIB(emulate_fua_write);
619SE_DEV_ATTR(emulate_fua_write, S_IRUGO | S_IWUSR);
620
621DEF_DEV_ATTRIB(emulate_fua_read);
622SE_DEV_ATTR(emulate_fua_read, S_IRUGO | S_IWUSR);
623
624DEF_DEV_ATTRIB(emulate_write_cache);
625SE_DEV_ATTR(emulate_write_cache, S_IRUGO | S_IWUSR);
626
627DEF_DEV_ATTRIB(emulate_ua_intlck_ctrl);
628SE_DEV_ATTR(emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR);
629
630DEF_DEV_ATTRIB(emulate_tas);
631SE_DEV_ATTR(emulate_tas, S_IRUGO | S_IWUSR);
632
633DEF_DEV_ATTRIB(emulate_tpu);
634SE_DEV_ATTR(emulate_tpu, S_IRUGO | S_IWUSR);
635
636DEF_DEV_ATTRIB(emulate_tpws);
637SE_DEV_ATTR(emulate_tpws, S_IRUGO | S_IWUSR);
638
639DEF_DEV_ATTRIB(enforce_pr_isids);
640SE_DEV_ATTR(enforce_pr_isids, S_IRUGO | S_IWUSR);
641
Roland Dreiere22a7f02011-07-05 13:34:52 -0700642DEF_DEV_ATTRIB(is_nonrot);
643SE_DEV_ATTR(is_nonrot, S_IRUGO | S_IWUSR);
644
Nicholas Bellinger5de619a2011-07-17 02:57:58 -0700645DEF_DEV_ATTRIB(emulate_rest_reord);
646SE_DEV_ATTR(emulate_rest_reord, S_IRUGO | S_IWUSR);
647
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800648DEF_DEV_ATTRIB_RO(hw_block_size);
649SE_DEV_ATTR_RO(hw_block_size);
650
651DEF_DEV_ATTRIB(block_size);
652SE_DEV_ATTR(block_size, S_IRUGO | S_IWUSR);
653
654DEF_DEV_ATTRIB_RO(hw_max_sectors);
655SE_DEV_ATTR_RO(hw_max_sectors);
656
Roland Dreier015487b2012-02-13 16:18:17 -0800657DEF_DEV_ATTRIB(fabric_max_sectors);
658SE_DEV_ATTR(fabric_max_sectors, S_IRUGO | S_IWUSR);
659
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800660DEF_DEV_ATTRIB(optimal_sectors);
661SE_DEV_ATTR(optimal_sectors, S_IRUGO | S_IWUSR);
662
663DEF_DEV_ATTRIB_RO(hw_queue_depth);
664SE_DEV_ATTR_RO(hw_queue_depth);
665
666DEF_DEV_ATTRIB(queue_depth);
667SE_DEV_ATTR(queue_depth, S_IRUGO | S_IWUSR);
668
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800669DEF_DEV_ATTRIB(max_unmap_lba_count);
670SE_DEV_ATTR(max_unmap_lba_count, S_IRUGO | S_IWUSR);
671
672DEF_DEV_ATTRIB(max_unmap_block_desc_count);
673SE_DEV_ATTR(max_unmap_block_desc_count, S_IRUGO | S_IWUSR);
674
675DEF_DEV_ATTRIB(unmap_granularity);
676SE_DEV_ATTR(unmap_granularity, S_IRUGO | S_IWUSR);
677
678DEF_DEV_ATTRIB(unmap_granularity_alignment);
679SE_DEV_ATTR(unmap_granularity_alignment, S_IRUGO | S_IWUSR);
680
Nicholas Bellinger773cbaf2012-11-15 11:02:49 -0800681DEF_DEV_ATTRIB(max_write_same_len);
682SE_DEV_ATTR(max_write_same_len, S_IRUGO | S_IWUSR);
683
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800684CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group);
685
686static struct configfs_attribute *target_core_dev_attrib_attrs[] = {
Tregaron Baylyadfa9572013-01-31 15:30:24 -0700687 &target_core_dev_attrib_emulate_model_alias.attr,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800688 &target_core_dev_attrib_emulate_dpo.attr,
689 &target_core_dev_attrib_emulate_fua_write.attr,
690 &target_core_dev_attrib_emulate_fua_read.attr,
691 &target_core_dev_attrib_emulate_write_cache.attr,
692 &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr,
693 &target_core_dev_attrib_emulate_tas.attr,
694 &target_core_dev_attrib_emulate_tpu.attr,
695 &target_core_dev_attrib_emulate_tpws.attr,
696 &target_core_dev_attrib_enforce_pr_isids.attr,
Roland Dreiere22a7f02011-07-05 13:34:52 -0700697 &target_core_dev_attrib_is_nonrot.attr,
Nicholas Bellinger5de619a2011-07-17 02:57:58 -0700698 &target_core_dev_attrib_emulate_rest_reord.attr,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800699 &target_core_dev_attrib_hw_block_size.attr,
700 &target_core_dev_attrib_block_size.attr,
701 &target_core_dev_attrib_hw_max_sectors.attr,
Roland Dreier015487b2012-02-13 16:18:17 -0800702 &target_core_dev_attrib_fabric_max_sectors.attr,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800703 &target_core_dev_attrib_optimal_sectors.attr,
704 &target_core_dev_attrib_hw_queue_depth.attr,
705 &target_core_dev_attrib_queue_depth.attr,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800706 &target_core_dev_attrib_max_unmap_lba_count.attr,
707 &target_core_dev_attrib_max_unmap_block_desc_count.attr,
708 &target_core_dev_attrib_unmap_granularity.attr,
709 &target_core_dev_attrib_unmap_granularity_alignment.attr,
Nicholas Bellinger773cbaf2012-11-15 11:02:49 -0800710 &target_core_dev_attrib_max_write_same_len.attr,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800711 NULL,
712};
713
714static struct configfs_item_operations target_core_dev_attrib_ops = {
715 .show_attribute = target_core_dev_attrib_attr_show,
716 .store_attribute = target_core_dev_attrib_attr_store,
717};
718
719static struct config_item_type target_core_dev_attrib_cit = {
720 .ct_item_ops = &target_core_dev_attrib_ops,
721 .ct_attrs = target_core_dev_attrib_attrs,
722 .ct_owner = THIS_MODULE,
723};
724
725/* End functions for struct config_item_type target_core_dev_attrib_cit */
726
727/* Start functions for struct config_item_type target_core_dev_wwn_cit */
728
729CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn);
730#define SE_DEV_WWN_ATTR(_name, _mode) \
731static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \
732 __CONFIGFS_EATTR(_name, _mode, \
733 target_core_dev_wwn_show_attr_##_name, \
734 target_core_dev_wwn_store_attr_##_name);
735
736#define SE_DEV_WWN_ATTR_RO(_name); \
737do { \
738 static struct target_core_dev_wwn_attribute \
739 target_core_dev_wwn_##_name = \
740 __CONFIGFS_EATTR_RO(_name, \
741 target_core_dev_wwn_show_attr_##_name); \
742} while (0);
743
744/*
745 * VPD page 0x80 Unit serial
746 */
747static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial(
748 struct t10_wwn *t10_wwn,
749 char *page)
750{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800751 return sprintf(page, "T10 VPD Unit Serial Number: %s\n",
752 &t10_wwn->unit_serial[0]);
753}
754
755static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial(
756 struct t10_wwn *t10_wwn,
757 const char *page,
758 size_t count)
759{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400760 struct se_device *dev = t10_wwn->t10_dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800761 unsigned char buf[INQUIRY_VPD_SERIAL_LEN];
762
763 /*
764 * If Linux/SCSI subsystem_api_t plugin got a VPD Unit Serial
765 * from the struct scsi_device level firmware, do not allow
766 * VPD Unit Serial to be emulated.
767 *
768 * Note this struct scsi_device could also be emulating VPD
769 * information from its drivers/scsi LLD. But for now we assume
770 * it is doing 'the right thing' wrt a world wide unique
771 * VPD Unit Serial Number that OS dependent multipath can depend on.
772 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400773 if (dev->dev_flags & DF_FIRMWARE_VPD_UNIT_SERIAL) {
Andy Grover6708bb22011-06-08 10:36:43 -0700774 pr_err("Underlying SCSI device firmware provided VPD"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800775 " Unit Serial, ignoring request\n");
776 return -EOPNOTSUPP;
777 }
778
Dan Carpenter60d645a2011-06-15 10:03:05 -0700779 if (strlen(page) >= INQUIRY_VPD_SERIAL_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -0700780 pr_err("Emulated VPD Unit Serial exceeds"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800781 " INQUIRY_VPD_SERIAL_LEN: %d\n", INQUIRY_VPD_SERIAL_LEN);
782 return -EOVERFLOW;
783 }
784 /*
785 * Check to see if any active $FABRIC_MOD exports exist. If they
786 * do exist, fail here as changing this information on the fly
787 * (underneath the initiator side OS dependent multipath code)
788 * could cause negative effects.
789 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400790 if (dev->export_count) {
791 pr_err("Unable to set VPD Unit Serial while"
792 " active %d $FABRIC_MOD exports exist\n",
793 dev->export_count);
794 return -EINVAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800795 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400796
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800797 /*
798 * This currently assumes ASCII encoding for emulated VPD Unit Serial.
799 *
800 * Also, strip any newline added from the userspace
801 * echo $UUID > $TARGET/$HBA/$STORAGE_OBJECT/wwn/vpd_unit_serial
802 */
803 memset(buf, 0, INQUIRY_VPD_SERIAL_LEN);
804 snprintf(buf, INQUIRY_VPD_SERIAL_LEN, "%s", page);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400805 snprintf(dev->t10_wwn.unit_serial, INQUIRY_VPD_SERIAL_LEN,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800806 "%s", strstrip(buf));
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400807 dev->dev_flags |= DF_EMULATED_VPD_UNIT_SERIAL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800808
Andy Grover6708bb22011-06-08 10:36:43 -0700809 pr_debug("Target_Core_ConfigFS: Set emulated VPD Unit Serial:"
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400810 " %s\n", dev->t10_wwn.unit_serial);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800811
812 return count;
813}
814
815SE_DEV_WWN_ATTR(vpd_unit_serial, S_IRUGO | S_IWUSR);
816
817/*
818 * VPD page 0x83 Protocol Identifier
819 */
820static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier(
821 struct t10_wwn *t10_wwn,
822 char *page)
823{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800824 struct t10_vpd *vpd;
825 unsigned char buf[VPD_TMP_BUF_SIZE];
826 ssize_t len = 0;
827
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800828 memset(buf, 0, VPD_TMP_BUF_SIZE);
829
830 spin_lock(&t10_wwn->t10_vpd_lock);
831 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) {
Andy Grover6708bb22011-06-08 10:36:43 -0700832 if (!vpd->protocol_identifier_set)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800833 continue;
834
835 transport_dump_vpd_proto_id(vpd, buf, VPD_TMP_BUF_SIZE);
836
Andy Grover6708bb22011-06-08 10:36:43 -0700837 if (len + strlen(buf) >= PAGE_SIZE)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800838 break;
839
840 len += sprintf(page+len, "%s", buf);
841 }
842 spin_unlock(&t10_wwn->t10_vpd_lock);
843
844 return len;
845}
846
847static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier(
848 struct t10_wwn *t10_wwn,
849 const char *page,
850 size_t count)
851{
852 return -ENOSYS;
853}
854
855SE_DEV_WWN_ATTR(vpd_protocol_identifier, S_IRUGO | S_IWUSR);
856
857/*
858 * Generic wrapper for dumping VPD identifiers by association.
859 */
860#define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
861static ssize_t target_core_dev_wwn_show_attr_##_name( \
862 struct t10_wwn *t10_wwn, \
863 char *page) \
864{ \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800865 struct t10_vpd *vpd; \
866 unsigned char buf[VPD_TMP_BUF_SIZE]; \
867 ssize_t len = 0; \
868 \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800869 spin_lock(&t10_wwn->t10_vpd_lock); \
870 list_for_each_entry(vpd, &t10_wwn->t10_vpd_list, vpd_list) { \
871 if (vpd->association != _assoc) \
872 continue; \
873 \
874 memset(buf, 0, VPD_TMP_BUF_SIZE); \
875 transport_dump_vpd_assoc(vpd, buf, VPD_TMP_BUF_SIZE); \
Andy Grover6708bb22011-06-08 10:36:43 -0700876 if (len + strlen(buf) >= PAGE_SIZE) \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800877 break; \
878 len += sprintf(page+len, "%s", buf); \
879 \
880 memset(buf, 0, VPD_TMP_BUF_SIZE); \
881 transport_dump_vpd_ident_type(vpd, buf, VPD_TMP_BUF_SIZE); \
Andy Grover6708bb22011-06-08 10:36:43 -0700882 if (len + strlen(buf) >= PAGE_SIZE) \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800883 break; \
884 len += sprintf(page+len, "%s", buf); \
885 \
886 memset(buf, 0, VPD_TMP_BUF_SIZE); \
887 transport_dump_vpd_ident(vpd, buf, VPD_TMP_BUF_SIZE); \
Andy Grover6708bb22011-06-08 10:36:43 -0700888 if (len + strlen(buf) >= PAGE_SIZE) \
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800889 break; \
890 len += sprintf(page+len, "%s", buf); \
891 } \
892 spin_unlock(&t10_wwn->t10_vpd_lock); \
893 \
894 return len; \
895}
896
897/*
Andy Shevchenko163cd5f2011-07-18 22:17:43 -0700898 * VPD page 0x83 Association: Logical Unit
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800899 */
900DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00);
901
902static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
903 struct t10_wwn *t10_wwn,
904 const char *page,
905 size_t count)
906{
907 return -ENOSYS;
908}
909
910SE_DEV_WWN_ATTR(vpd_assoc_logical_unit, S_IRUGO | S_IWUSR);
911
912/*
913 * VPD page 0x83 Association: Target Port
914 */
915DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10);
916
917static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port(
918 struct t10_wwn *t10_wwn,
919 const char *page,
920 size_t count)
921{
922 return -ENOSYS;
923}
924
925SE_DEV_WWN_ATTR(vpd_assoc_target_port, S_IRUGO | S_IWUSR);
926
927/*
928 * VPD page 0x83 Association: SCSI Target Device
929 */
930DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20);
931
932static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device(
933 struct t10_wwn *t10_wwn,
934 const char *page,
935 size_t count)
936{
937 return -ENOSYS;
938}
939
940SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device, S_IRUGO | S_IWUSR);
941
942CONFIGFS_EATTR_OPS(target_core_dev_wwn, t10_wwn, t10_wwn_group);
943
944static struct configfs_attribute *target_core_dev_wwn_attrs[] = {
945 &target_core_dev_wwn_vpd_unit_serial.attr,
946 &target_core_dev_wwn_vpd_protocol_identifier.attr,
947 &target_core_dev_wwn_vpd_assoc_logical_unit.attr,
948 &target_core_dev_wwn_vpd_assoc_target_port.attr,
949 &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr,
950 NULL,
951};
952
953static struct configfs_item_operations target_core_dev_wwn_ops = {
954 .show_attribute = target_core_dev_wwn_attr_show,
955 .store_attribute = target_core_dev_wwn_attr_store,
956};
957
958static struct config_item_type target_core_dev_wwn_cit = {
959 .ct_item_ops = &target_core_dev_wwn_ops,
960 .ct_attrs = target_core_dev_wwn_attrs,
961 .ct_owner = THIS_MODULE,
962};
963
964/* End functions for struct config_item_type target_core_dev_wwn_cit */
965
966/* Start functions for struct config_item_type target_core_dev_pr_cit */
967
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -0400968CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_device);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800969#define SE_DEV_PR_ATTR(_name, _mode) \
970static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
971 __CONFIGFS_EATTR(_name, _mode, \
972 target_core_dev_pr_show_attr_##_name, \
973 target_core_dev_pr_store_attr_##_name);
974
975#define SE_DEV_PR_ATTR_RO(_name); \
976static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
977 __CONFIGFS_EATTR_RO(_name, \
978 target_core_dev_pr_show_attr_##_name);
979
Christoph Hellwigd977f432012-10-10 17:37:15 -0400980static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev,
981 char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800982{
983 struct se_node_acl *se_nacl;
984 struct t10_pr_registration *pr_reg;
985 char i_buf[PR_REG_ISID_ID_LEN];
986 int prf_isid;
987
988 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
989
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800990 pr_reg = dev->dev_pr_res_holder;
Christoph Hellwigd977f432012-10-10 17:37:15 -0400991 if (!pr_reg)
992 return sprintf(page, "No SPC-3 Reservation holder\n");
993
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -0800994 se_nacl = pr_reg->pr_reg_nacl;
995 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0],
996 PR_REG_ISID_ID_LEN);
997
Christoph Hellwigd977f432012-10-10 17:37:15 -0400998 return sprintf(page, "SPC-3 Reservation: %s Initiator: %s%s\n",
Andy Grovere3d6f902011-07-19 08:55:10 +0000999 se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001000 se_nacl->initiatorname, (prf_isid) ? &i_buf[0] : "");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001001}
1002
Christoph Hellwigd977f432012-10-10 17:37:15 -04001003static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev,
1004 char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001005{
1006 struct se_node_acl *se_nacl;
Christoph Hellwigd977f432012-10-10 17:37:15 -04001007 ssize_t len;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001008
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001009 se_nacl = dev->dev_reserved_node_acl;
Christoph Hellwigd977f432012-10-10 17:37:15 -04001010 if (se_nacl) {
1011 len = sprintf(page,
1012 "SPC-2 Reservation: %s Initiator: %s\n",
1013 se_nacl->se_tpg->se_tpg_tfo->get_fabric_name(),
1014 se_nacl->initiatorname);
1015 } else {
1016 len = sprintf(page, "No SPC-2 Reservation holder\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001017 }
Christoph Hellwigd977f432012-10-10 17:37:15 -04001018 return len;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001019}
1020
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001021static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev,
1022 char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001023{
Christoph Hellwigd977f432012-10-10 17:37:15 -04001024 int ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001025
Christoph Hellwigd977f432012-10-10 17:37:15 -04001026 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV)
1027 return sprintf(page, "Passthrough\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001028
Christoph Hellwigd977f432012-10-10 17:37:15 -04001029 spin_lock(&dev->dev_reservation_lock);
1030 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)
1031 ret = target_core_dev_pr_show_spc2_res(dev, page);
1032 else
1033 ret = target_core_dev_pr_show_spc3_res(dev, page);
1034 spin_unlock(&dev->dev_reservation_lock);
1035 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001036}
1037
1038SE_DEV_PR_ATTR_RO(res_holder);
1039
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001040static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001041 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001042{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001043 ssize_t len = 0;
1044
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001045 spin_lock(&dev->dev_reservation_lock);
Christoph Hellwigd977f432012-10-10 17:37:15 -04001046 if (!dev->dev_pr_res_holder) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001047 len = sprintf(page, "No SPC-3 Reservation holder\n");
Christoph Hellwigd977f432012-10-10 17:37:15 -04001048 } else if (dev->dev_pr_res_holder->pr_reg_all_tg_pt) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001049 len = sprintf(page, "SPC-3 Reservation: All Target"
1050 " Ports registration\n");
Christoph Hellwigd977f432012-10-10 17:37:15 -04001051 } else {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001052 len = sprintf(page, "SPC-3 Reservation: Single"
1053 " Target Port registration\n");
Christoph Hellwigd977f432012-10-10 17:37:15 -04001054 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001055
Christoph Hellwigd977f432012-10-10 17:37:15 -04001056 spin_unlock(&dev->dev_reservation_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001057 return len;
1058}
1059
1060SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts);
1061
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001062static ssize_t target_core_dev_pr_show_attr_res_pr_generation(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001063 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001064{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001065 return sprintf(page, "0x%08x\n", dev->t10_pr.pr_generation);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001066}
1067
1068SE_DEV_PR_ATTR_RO(res_pr_generation);
1069
1070/*
1071 * res_pr_holder_tg_port
1072 */
1073static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001074 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001075{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001076 struct se_node_acl *se_nacl;
1077 struct se_lun *lun;
1078 struct se_portal_group *se_tpg;
1079 struct t10_pr_registration *pr_reg;
1080 struct target_core_fabric_ops *tfo;
1081 ssize_t len = 0;
1082
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001083 spin_lock(&dev->dev_reservation_lock);
1084 pr_reg = dev->dev_pr_res_holder;
Andy Grover6708bb22011-06-08 10:36:43 -07001085 if (!pr_reg) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001086 len = sprintf(page, "No SPC-3 Reservation holder\n");
Christoph Hellwigd977f432012-10-10 17:37:15 -04001087 goto out_unlock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001088 }
Christoph Hellwigd977f432012-10-10 17:37:15 -04001089
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001090 se_nacl = pr_reg->pr_reg_nacl;
1091 se_tpg = se_nacl->se_tpg;
1092 lun = pr_reg->pr_reg_tg_pt_lun;
Andy Grovere3d6f902011-07-19 08:55:10 +00001093 tfo = se_tpg->se_tpg_tfo;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001094
1095 len += sprintf(page+len, "SPC-3 Reservation: %s"
1096 " Target Node Endpoint: %s\n", tfo->get_fabric_name(),
1097 tfo->tpg_get_wwn(se_tpg));
1098 len += sprintf(page+len, "SPC-3 Reservation: Relative Port"
Masanari Iida35d1efe2012-08-16 22:43:13 +09001099 " Identifier Tag: %hu %s Portal Group Tag: %hu"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001100 " %s Logical Unit: %u\n", lun->lun_sep->sep_rtpi,
1101 tfo->get_fabric_name(), tfo->tpg_get_tag(se_tpg),
1102 tfo->get_fabric_name(), lun->unpacked_lun);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001103
Christoph Hellwigd977f432012-10-10 17:37:15 -04001104out_unlock:
1105 spin_unlock(&dev->dev_reservation_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001106 return len;
1107}
1108
1109SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port);
1110
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001111static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001112 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001113{
1114 struct target_core_fabric_ops *tfo;
1115 struct t10_pr_registration *pr_reg;
1116 unsigned char buf[384];
1117 char i_buf[PR_REG_ISID_ID_LEN];
1118 ssize_t len = 0;
1119 int reg_count = 0, prf_isid;
1120
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001121 len += sprintf(page+len, "SPC-3 PR Registrations:\n");
1122
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001123 spin_lock(&dev->t10_pr.registration_lock);
1124 list_for_each_entry(pr_reg, &dev->t10_pr.registration_list,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001125 pr_reg_list) {
1126
1127 memset(buf, 0, 384);
1128 memset(i_buf, 0, PR_REG_ISID_ID_LEN);
1129 tfo = pr_reg->pr_reg_nacl->se_tpg->se_tpg_tfo;
1130 prf_isid = core_pr_dump_initiator_port(pr_reg, &i_buf[0],
1131 PR_REG_ISID_ID_LEN);
1132 sprintf(buf, "%s Node: %s%s Key: 0x%016Lx PRgen: 0x%08x\n",
1133 tfo->get_fabric_name(),
1134 pr_reg->pr_reg_nacl->initiatorname, (prf_isid) ?
1135 &i_buf[0] : "", pr_reg->pr_res_key,
1136 pr_reg->pr_res_generation);
1137
Andy Grover6708bb22011-06-08 10:36:43 -07001138 if (len + strlen(buf) >= PAGE_SIZE)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001139 break;
1140
1141 len += sprintf(page+len, "%s", buf);
1142 reg_count++;
1143 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001144 spin_unlock(&dev->t10_pr.registration_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001145
Andy Grover6708bb22011-06-08 10:36:43 -07001146 if (!reg_count)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001147 len += sprintf(page+len, "None\n");
1148
1149 return len;
1150}
1151
1152SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts);
1153
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001154static ssize_t target_core_dev_pr_show_attr_res_pr_type(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001155 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001156{
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001157 struct t10_pr_registration *pr_reg;
1158 ssize_t len = 0;
1159
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001160 spin_lock(&dev->dev_reservation_lock);
1161 pr_reg = dev->dev_pr_res_holder;
Christoph Hellwigd977f432012-10-10 17:37:15 -04001162 if (pr_reg) {
1163 len = sprintf(page, "SPC-3 Reservation Type: %s\n",
1164 core_scsi3_pr_dump_type(pr_reg->pr_res_type));
1165 } else {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001166 len = sprintf(page, "No SPC-3 Reservation holder\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001167 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001168
Christoph Hellwigd977f432012-10-10 17:37:15 -04001169 spin_unlock(&dev->dev_reservation_lock);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001170 return len;
1171}
1172
1173SE_DEV_PR_ATTR_RO(res_pr_type);
1174
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001175static ssize_t target_core_dev_pr_show_attr_res_type(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001176 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001177{
Christoph Hellwigd977f432012-10-10 17:37:15 -04001178 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV)
1179 return sprintf(page, "SPC_PASSTHROUGH\n");
1180 else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)
1181 return sprintf(page, "SPC2_RESERVATIONS\n");
1182 else
1183 return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001184}
1185
1186SE_DEV_PR_ATTR_RO(res_type);
1187
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001188static ssize_t target_core_dev_pr_show_attr_res_aptpl_active(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001189 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001190{
Christoph Hellwigd977f432012-10-10 17:37:15 -04001191 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001192 return 0;
1193
1194 return sprintf(page, "APTPL Bit Status: %s\n",
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001195 (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001196}
1197
1198SE_DEV_PR_ATTR_RO(res_aptpl_active);
1199
1200/*
1201 * res_aptpl_metadata
1202 */
1203static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001204 struct se_device *dev, char *page)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001205{
Christoph Hellwigd977f432012-10-10 17:37:15 -04001206 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001207 return 0;
1208
1209 return sprintf(page, "Ready to process PR APTPL metadata..\n");
1210}
1211
1212enum {
1213 Opt_initiator_fabric, Opt_initiator_node, Opt_initiator_sid,
1214 Opt_sa_res_key, Opt_res_holder, Opt_res_type, Opt_res_scope,
1215 Opt_res_all_tg_pt, Opt_mapped_lun, Opt_target_fabric,
1216 Opt_target_node, Opt_tpgt, Opt_port_rtpi, Opt_target_lun, Opt_err
1217};
1218
1219static match_table_t tokens = {
1220 {Opt_initiator_fabric, "initiator_fabric=%s"},
1221 {Opt_initiator_node, "initiator_node=%s"},
1222 {Opt_initiator_sid, "initiator_sid=%s"},
1223 {Opt_sa_res_key, "sa_res_key=%s"},
1224 {Opt_res_holder, "res_holder=%d"},
1225 {Opt_res_type, "res_type=%d"},
1226 {Opt_res_scope, "res_scope=%d"},
1227 {Opt_res_all_tg_pt, "res_all_tg_pt=%d"},
1228 {Opt_mapped_lun, "mapped_lun=%d"},
1229 {Opt_target_fabric, "target_fabric=%s"},
1230 {Opt_target_node, "target_node=%s"},
1231 {Opt_tpgt, "tpgt=%d"},
1232 {Opt_port_rtpi, "port_rtpi=%d"},
1233 {Opt_target_lun, "target_lun=%d"},
1234 {Opt_err, NULL}
1235};
1236
1237static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata(
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001238 struct se_device *dev,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001239 const char *page,
1240 size_t count)
1241{
Jesper Juhl6d180252011-03-14 04:05:56 -07001242 unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL;
1243 unsigned char *t_fabric = NULL, *t_port = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001244 char *orig, *ptr, *arg_p, *opts;
1245 substring_t args[MAX_OPT_ARGS];
1246 unsigned long long tmp_ll;
1247 u64 sa_res_key = 0;
1248 u32 mapped_lun = 0, target_lun = 0;
1249 int ret = -1, res_holder = 0, all_tg_pt = 0, arg, token;
1250 u16 port_rpti = 0, tpgt = 0;
1251 u8 type = 0, scope;
1252
Christoph Hellwigd977f432012-10-10 17:37:15 -04001253 if (dev->transport->transport_type == TRANSPORT_PLUGIN_PHBA_PDEV)
1254 return 0;
1255 if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001256 return 0;
1257
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001258 if (dev->export_count) {
Andy Grover6708bb22011-06-08 10:36:43 -07001259 pr_debug("Unable to process APTPL metadata while"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001260 " active fabric exports exist\n");
1261 return -EINVAL;
1262 }
1263
1264 opts = kstrdup(page, GFP_KERNEL);
1265 if (!opts)
1266 return -ENOMEM;
1267
1268 orig = opts;
Sebastian Andrzej Siewior90c161b2011-11-23 20:53:17 +01001269 while ((ptr = strsep(&opts, ",\n")) != NULL) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001270 if (!*ptr)
1271 continue;
1272
1273 token = match_token(ptr, tokens, args);
1274 switch (token) {
1275 case Opt_initiator_fabric:
1276 i_fabric = match_strdup(&args[0]);
Jesper Juhl6d180252011-03-14 04:05:56 -07001277 if (!i_fabric) {
1278 ret = -ENOMEM;
1279 goto out;
1280 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001281 break;
1282 case Opt_initiator_node:
1283 i_port = match_strdup(&args[0]);
Jesper Juhl6d180252011-03-14 04:05:56 -07001284 if (!i_port) {
1285 ret = -ENOMEM;
1286 goto out;
1287 }
Dan Carpenter60d645a2011-06-15 10:03:05 -07001288 if (strlen(i_port) >= PR_APTPL_MAX_IPORT_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001289 pr_err("APTPL metadata initiator_node="
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001290 " exceeds PR_APTPL_MAX_IPORT_LEN: %d\n",
1291 PR_APTPL_MAX_IPORT_LEN);
1292 ret = -EINVAL;
1293 break;
1294 }
1295 break;
1296 case Opt_initiator_sid:
1297 isid = match_strdup(&args[0]);
Jesper Juhl6d180252011-03-14 04:05:56 -07001298 if (!isid) {
1299 ret = -ENOMEM;
1300 goto out;
1301 }
Dan Carpenter60d645a2011-06-15 10:03:05 -07001302 if (strlen(isid) >= PR_REG_ISID_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001303 pr_err("APTPL metadata initiator_isid"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001304 "= exceeds PR_REG_ISID_LEN: %d\n",
1305 PR_REG_ISID_LEN);
1306 ret = -EINVAL;
1307 break;
1308 }
1309 break;
1310 case Opt_sa_res_key:
1311 arg_p = match_strdup(&args[0]);
Jesper Juhl6d180252011-03-14 04:05:56 -07001312 if (!arg_p) {
1313 ret = -ENOMEM;
1314 goto out;
1315 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001316 ret = strict_strtoull(arg_p, 0, &tmp_ll);
1317 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07001318 pr_err("strict_strtoull() failed for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001319 " sa_res_key=\n");
1320 goto out;
1321 }
1322 sa_res_key = (u64)tmp_ll;
1323 break;
1324 /*
1325 * PR APTPL Metadata for Reservation
1326 */
1327 case Opt_res_holder:
1328 match_int(args, &arg);
1329 res_holder = arg;
1330 break;
1331 case Opt_res_type:
1332 match_int(args, &arg);
1333 type = (u8)arg;
1334 break;
1335 case Opt_res_scope:
1336 match_int(args, &arg);
1337 scope = (u8)arg;
1338 break;
1339 case Opt_res_all_tg_pt:
1340 match_int(args, &arg);
1341 all_tg_pt = (int)arg;
1342 break;
1343 case Opt_mapped_lun:
1344 match_int(args, &arg);
1345 mapped_lun = (u32)arg;
1346 break;
1347 /*
1348 * PR APTPL Metadata for Target Port
1349 */
1350 case Opt_target_fabric:
1351 t_fabric = match_strdup(&args[0]);
Jesper Juhl6d180252011-03-14 04:05:56 -07001352 if (!t_fabric) {
1353 ret = -ENOMEM;
1354 goto out;
1355 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001356 break;
1357 case Opt_target_node:
1358 t_port = match_strdup(&args[0]);
Jesper Juhl6d180252011-03-14 04:05:56 -07001359 if (!t_port) {
1360 ret = -ENOMEM;
1361 goto out;
1362 }
Dan Carpenter60d645a2011-06-15 10:03:05 -07001363 if (strlen(t_port) >= PR_APTPL_MAX_TPORT_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07001364 pr_err("APTPL metadata target_node="
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001365 " exceeds PR_APTPL_MAX_TPORT_LEN: %d\n",
1366 PR_APTPL_MAX_TPORT_LEN);
1367 ret = -EINVAL;
1368 break;
1369 }
1370 break;
1371 case Opt_tpgt:
1372 match_int(args, &arg);
1373 tpgt = (u16)arg;
1374 break;
1375 case Opt_port_rtpi:
1376 match_int(args, &arg);
1377 port_rpti = (u16)arg;
1378 break;
1379 case Opt_target_lun:
1380 match_int(args, &arg);
1381 target_lun = (u32)arg;
1382 break;
1383 default:
1384 break;
1385 }
1386 }
1387
Andy Grover6708bb22011-06-08 10:36:43 -07001388 if (!i_port || !t_port || !sa_res_key) {
1389 pr_err("Illegal parameters for APTPL registration\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001390 ret = -EINVAL;
1391 goto out;
1392 }
1393
1394 if (res_holder && !(type)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001395 pr_err("Illegal PR type: 0x%02x for reservation"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001396 " holder\n", type);
1397 ret = -EINVAL;
1398 goto out;
1399 }
1400
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001401 ret = core_scsi3_alloc_aptpl_registration(&dev->t10_pr, sa_res_key,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001402 i_port, isid, mapped_lun, t_port, tpgt, target_lun,
1403 res_holder, all_tg_pt, type);
1404out:
Jesper Juhl6d180252011-03-14 04:05:56 -07001405 kfree(i_fabric);
1406 kfree(i_port);
1407 kfree(isid);
1408 kfree(t_fabric);
1409 kfree(t_port);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001410 kfree(orig);
1411 return (ret == 0) ? count : ret;
1412}
1413
1414SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR);
1415
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001416CONFIGFS_EATTR_OPS(target_core_dev_pr, se_device, dev_pr_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001417
1418static struct configfs_attribute *target_core_dev_pr_attrs[] = {
1419 &target_core_dev_pr_res_holder.attr,
1420 &target_core_dev_pr_res_pr_all_tgt_pts.attr,
1421 &target_core_dev_pr_res_pr_generation.attr,
1422 &target_core_dev_pr_res_pr_holder_tg_port.attr,
1423 &target_core_dev_pr_res_pr_registered_i_pts.attr,
1424 &target_core_dev_pr_res_pr_type.attr,
1425 &target_core_dev_pr_res_type.attr,
1426 &target_core_dev_pr_res_aptpl_active.attr,
1427 &target_core_dev_pr_res_aptpl_metadata.attr,
1428 NULL,
1429};
1430
1431static struct configfs_item_operations target_core_dev_pr_ops = {
1432 .show_attribute = target_core_dev_pr_attr_show,
1433 .store_attribute = target_core_dev_pr_attr_store,
1434};
1435
1436static struct config_item_type target_core_dev_pr_cit = {
1437 .ct_item_ops = &target_core_dev_pr_ops,
1438 .ct_attrs = target_core_dev_pr_attrs,
1439 .ct_owner = THIS_MODULE,
1440};
1441
1442/* End functions for struct config_item_type target_core_dev_pr_cit */
1443
1444/* Start functions for struct config_item_type target_core_dev_cit */
1445
1446static ssize_t target_core_show_dev_info(void *p, char *page)
1447{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001448 struct se_device *dev = p;
1449 struct se_subsystem_api *t = dev->transport;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001450 int bl = 0;
1451 ssize_t read_bytes = 0;
1452
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001453 transport_dump_dev_state(dev, page, &bl);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001454 read_bytes += bl;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001455 read_bytes += t->show_configfs_dev_params(dev, page+read_bytes);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001456 return read_bytes;
1457}
1458
1459static struct target_core_configfs_attribute target_core_attr_dev_info = {
1460 .attr = { .ca_owner = THIS_MODULE,
1461 .ca_name = "info",
1462 .ca_mode = S_IRUGO },
1463 .show = target_core_show_dev_info,
1464 .store = NULL,
1465};
1466
1467static ssize_t target_core_store_dev_control(
1468 void *p,
1469 const char *page,
1470 size_t count)
1471{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001472 struct se_device *dev = p;
1473 struct se_subsystem_api *t = dev->transport;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001474
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001475 return t->set_configfs_dev_params(dev, page, count);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001476}
1477
1478static struct target_core_configfs_attribute target_core_attr_dev_control = {
1479 .attr = { .ca_owner = THIS_MODULE,
1480 .ca_name = "control",
1481 .ca_mode = S_IWUSR },
1482 .show = NULL,
1483 .store = target_core_store_dev_control,
1484};
1485
1486static ssize_t target_core_show_dev_alias(void *p, char *page)
1487{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001488 struct se_device *dev = p;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001489
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001490 if (!(dev->dev_flags & DF_USING_ALIAS))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001491 return 0;
1492
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001493 return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001494}
1495
1496static ssize_t target_core_store_dev_alias(
1497 void *p,
1498 const char *page,
1499 size_t count)
1500{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001501 struct se_device *dev = p;
1502 struct se_hba *hba = dev->se_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001503 ssize_t read_bytes;
1504
1505 if (count > (SE_DEV_ALIAS_LEN-1)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001506 pr_err("alias count: %d exceeds"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001507 " SE_DEV_ALIAS_LEN-1: %u\n", (int)count,
1508 SE_DEV_ALIAS_LEN-1);
1509 return -EINVAL;
1510 }
1511
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001512 read_bytes = snprintf(&dev->dev_alias[0], SE_DEV_ALIAS_LEN, "%s", page);
Dan Carpenter30116842012-01-27 15:50:55 +03001513 if (!read_bytes)
1514 return -EINVAL;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001515 if (dev->dev_alias[read_bytes - 1] == '\n')
1516 dev->dev_alias[read_bytes - 1] = '\0';
Sebastian Andrzej Siewior0877eafd2011-11-28 13:57:25 +01001517
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001518 dev->dev_flags |= DF_USING_ALIAS;
Dan Carpenter30116842012-01-27 15:50:55 +03001519
Andy Grover6708bb22011-06-08 10:36:43 -07001520 pr_debug("Target_Core_ConfigFS: %s/%s set alias: %s\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001521 config_item_name(&hba->hba_group.cg_item),
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001522 config_item_name(&dev->dev_group.cg_item),
1523 dev->dev_alias);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001524
1525 return read_bytes;
1526}
1527
1528static struct target_core_configfs_attribute target_core_attr_dev_alias = {
1529 .attr = { .ca_owner = THIS_MODULE,
1530 .ca_name = "alias",
1531 .ca_mode = S_IRUGO | S_IWUSR },
1532 .show = target_core_show_dev_alias,
1533 .store = target_core_store_dev_alias,
1534};
1535
1536static ssize_t target_core_show_dev_udev_path(void *p, char *page)
1537{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001538 struct se_device *dev = p;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001539
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001540 if (!(dev->dev_flags & DF_USING_UDEV_PATH))
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001541 return 0;
1542
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001543 return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001544}
1545
1546static ssize_t target_core_store_dev_udev_path(
1547 void *p,
1548 const char *page,
1549 size_t count)
1550{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001551 struct se_device *dev = p;
1552 struct se_hba *hba = dev->se_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001553 ssize_t read_bytes;
1554
1555 if (count > (SE_UDEV_PATH_LEN-1)) {
Andy Grover6708bb22011-06-08 10:36:43 -07001556 pr_err("udev_path count: %d exceeds"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001557 " SE_UDEV_PATH_LEN-1: %u\n", (int)count,
1558 SE_UDEV_PATH_LEN-1);
1559 return -EINVAL;
1560 }
1561
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001562 read_bytes = snprintf(&dev->udev_path[0], SE_UDEV_PATH_LEN,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001563 "%s", page);
Dan Carpenter30116842012-01-27 15:50:55 +03001564 if (!read_bytes)
1565 return -EINVAL;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001566 if (dev->udev_path[read_bytes - 1] == '\n')
1567 dev->udev_path[read_bytes - 1] = '\0';
Sebastian Andrzej Siewior0877eafd2011-11-28 13:57:25 +01001568
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001569 dev->dev_flags |= DF_USING_UDEV_PATH;
Dan Carpenter30116842012-01-27 15:50:55 +03001570
Andy Grover6708bb22011-06-08 10:36:43 -07001571 pr_debug("Target_Core_ConfigFS: %s/%s set udev_path: %s\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001572 config_item_name(&hba->hba_group.cg_item),
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001573 config_item_name(&dev->dev_group.cg_item),
1574 dev->udev_path);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001575
1576 return read_bytes;
1577}
1578
1579static struct target_core_configfs_attribute target_core_attr_dev_udev_path = {
1580 .attr = { .ca_owner = THIS_MODULE,
1581 .ca_name = "udev_path",
1582 .ca_mode = S_IRUGO | S_IWUSR },
1583 .show = target_core_show_dev_udev_path,
1584 .store = target_core_store_dev_udev_path,
1585};
1586
1587static ssize_t target_core_store_dev_enable(
1588 void *p,
1589 const char *page,
1590 size_t count)
1591{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001592 struct se_device *dev = p;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001593 char *ptr;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001594 int ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001595
1596 ptr = strstr(page, "1");
Andy Grover6708bb22011-06-08 10:36:43 -07001597 if (!ptr) {
1598 pr_err("For dev_enable ops, only valid value"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001599 " is \"1\"\n");
1600 return -EINVAL;
1601 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001602
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001603 ret = target_configure_device(dev);
1604 if (ret)
1605 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001606 return count;
1607}
1608
1609static struct target_core_configfs_attribute target_core_attr_dev_enable = {
1610 .attr = { .ca_owner = THIS_MODULE,
1611 .ca_name = "enable",
1612 .ca_mode = S_IWUSR },
1613 .show = NULL,
1614 .store = target_core_store_dev_enable,
1615};
1616
1617static ssize_t target_core_show_alua_lu_gp(void *p, char *page)
1618{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001619 struct se_device *dev = p;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001620 struct config_item *lu_ci;
1621 struct t10_alua_lu_gp *lu_gp;
1622 struct t10_alua_lu_gp_member *lu_gp_mem;
1623 ssize_t len = 0;
1624
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001625 lu_gp_mem = dev->dev_alua_lu_gp_mem;
Christoph Hellwigc87fbd52012-10-10 17:37:16 -04001626 if (!lu_gp_mem)
1627 return 0;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001628
1629 spin_lock(&lu_gp_mem->lu_gp_mem_lock);
1630 lu_gp = lu_gp_mem->lu_gp;
Andy Grover6708bb22011-06-08 10:36:43 -07001631 if (lu_gp) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001632 lu_ci = &lu_gp->lu_gp_group.cg_item;
1633 len += sprintf(page, "LU Group Alias: %s\nLU Group ID: %hu\n",
1634 config_item_name(lu_ci), lu_gp->lu_gp_id);
1635 }
1636 spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
1637
1638 return len;
1639}
1640
1641static ssize_t target_core_store_alua_lu_gp(
1642 void *p,
1643 const char *page,
1644 size_t count)
1645{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001646 struct se_device *dev = p;
1647 struct se_hba *hba = dev->se_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001648 struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL;
1649 struct t10_alua_lu_gp_member *lu_gp_mem;
1650 unsigned char buf[LU_GROUP_NAME_BUF];
1651 int move = 0;
1652
Christoph Hellwigc87fbd52012-10-10 17:37:16 -04001653 lu_gp_mem = dev->dev_alua_lu_gp_mem;
1654 if (!lu_gp_mem)
1655 return 0;
1656
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001657 if (count > LU_GROUP_NAME_BUF) {
Andy Grover6708bb22011-06-08 10:36:43 -07001658 pr_err("ALUA LU Group Alias too large!\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001659 return -EINVAL;
1660 }
1661 memset(buf, 0, LU_GROUP_NAME_BUF);
1662 memcpy(buf, page, count);
1663 /*
1664 * Any ALUA logical unit alias besides "NULL" means we will be
1665 * making a new group association.
1666 */
1667 if (strcmp(strstrip(buf), "NULL")) {
1668 /*
1669 * core_alua_get_lu_gp_by_name() will increment reference to
1670 * struct t10_alua_lu_gp. This reference is released with
1671 * core_alua_get_lu_gp_by_name below().
1672 */
1673 lu_gp_new = core_alua_get_lu_gp_by_name(strstrip(buf));
Andy Grover6708bb22011-06-08 10:36:43 -07001674 if (!lu_gp_new)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001675 return -ENODEV;
1676 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001677
1678 spin_lock(&lu_gp_mem->lu_gp_mem_lock);
1679 lu_gp = lu_gp_mem->lu_gp;
Andy Grover6708bb22011-06-08 10:36:43 -07001680 if (lu_gp) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001681 /*
1682 * Clearing an existing lu_gp association, and replacing
1683 * with NULL
1684 */
Andy Grover6708bb22011-06-08 10:36:43 -07001685 if (!lu_gp_new) {
1686 pr_debug("Target_Core_ConfigFS: Releasing %s/%s"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001687 " from ALUA LU Group: core/alua/lu_gps/%s, ID:"
1688 " %hu\n",
1689 config_item_name(&hba->hba_group.cg_item),
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001690 config_item_name(&dev->dev_group.cg_item),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001691 config_item_name(&lu_gp->lu_gp_group.cg_item),
1692 lu_gp->lu_gp_id);
1693
1694 __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp);
1695 spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
1696
1697 return count;
1698 }
1699 /*
1700 * Removing existing association of lu_gp_mem with lu_gp
1701 */
1702 __core_alua_drop_lu_gp_mem(lu_gp_mem, lu_gp);
1703 move = 1;
1704 }
1705 /*
1706 * Associate lu_gp_mem with lu_gp_new.
1707 */
1708 __core_alua_attach_lu_gp_mem(lu_gp_mem, lu_gp_new);
1709 spin_unlock(&lu_gp_mem->lu_gp_mem_lock);
1710
Andy Grover6708bb22011-06-08 10:36:43 -07001711 pr_debug("Target_Core_ConfigFS: %s %s/%s to ALUA LU Group:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001712 " core/alua/lu_gps/%s, ID: %hu\n",
1713 (move) ? "Moving" : "Adding",
1714 config_item_name(&hba->hba_group.cg_item),
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001715 config_item_name(&dev->dev_group.cg_item),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001716 config_item_name(&lu_gp_new->lu_gp_group.cg_item),
1717 lu_gp_new->lu_gp_id);
1718
1719 core_alua_put_lu_gp_from_name(lu_gp_new);
1720 return count;
1721}
1722
1723static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = {
1724 .attr = { .ca_owner = THIS_MODULE,
1725 .ca_name = "alua_lu_gp",
1726 .ca_mode = S_IRUGO | S_IWUSR },
1727 .show = target_core_show_alua_lu_gp,
1728 .store = target_core_store_alua_lu_gp,
1729};
1730
1731static struct configfs_attribute *lio_core_dev_attrs[] = {
1732 &target_core_attr_dev_info.attr,
1733 &target_core_attr_dev_control.attr,
1734 &target_core_attr_dev_alias.attr,
1735 &target_core_attr_dev_udev_path.attr,
1736 &target_core_attr_dev_enable.attr,
1737 &target_core_attr_dev_alua_lu_gp.attr,
1738 NULL,
1739};
1740
1741static void target_core_dev_release(struct config_item *item)
1742{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001743 struct config_group *dev_cg = to_config_group(item);
1744 struct se_device *dev =
1745 container_of(dev_cg, struct se_device, dev_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001746
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001747 kfree(dev_cg->default_groups);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001748 target_free_device(dev);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001749}
1750
1751static ssize_t target_core_dev_show(struct config_item *item,
1752 struct configfs_attribute *attr,
1753 char *page)
1754{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001755 struct config_group *dev_cg = to_config_group(item);
1756 struct se_device *dev =
1757 container_of(dev_cg, struct se_device, dev_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001758 struct target_core_configfs_attribute *tc_attr = container_of(
1759 attr, struct target_core_configfs_attribute, attr);
1760
Andy Grover6708bb22011-06-08 10:36:43 -07001761 if (!tc_attr->show)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001762 return -EINVAL;
1763
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001764 return tc_attr->show(dev, page);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001765}
1766
1767static ssize_t target_core_dev_store(struct config_item *item,
1768 struct configfs_attribute *attr,
1769 const char *page, size_t count)
1770{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001771 struct config_group *dev_cg = to_config_group(item);
1772 struct se_device *dev =
1773 container_of(dev_cg, struct se_device, dev_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001774 struct target_core_configfs_attribute *tc_attr = container_of(
1775 attr, struct target_core_configfs_attribute, attr);
1776
Andy Grover6708bb22011-06-08 10:36:43 -07001777 if (!tc_attr->store)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001778 return -EINVAL;
1779
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001780 return tc_attr->store(dev, page, count);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001781}
1782
1783static struct configfs_item_operations target_core_dev_item_ops = {
1784 .release = target_core_dev_release,
1785 .show_attribute = target_core_dev_show,
1786 .store_attribute = target_core_dev_store,
1787};
1788
1789static struct config_item_type target_core_dev_cit = {
1790 .ct_item_ops = &target_core_dev_item_ops,
1791 .ct_attrs = lio_core_dev_attrs,
1792 .ct_owner = THIS_MODULE,
1793};
1794
1795/* End functions for struct config_item_type target_core_dev_cit */
1796
1797/* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
1798
1799CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp);
1800#define SE_DEV_ALUA_LU_ATTR(_name, _mode) \
1801static struct target_core_alua_lu_gp_attribute \
1802 target_core_alua_lu_gp_##_name = \
1803 __CONFIGFS_EATTR(_name, _mode, \
1804 target_core_alua_lu_gp_show_attr_##_name, \
1805 target_core_alua_lu_gp_store_attr_##_name);
1806
1807#define SE_DEV_ALUA_LU_ATTR_RO(_name) \
1808static struct target_core_alua_lu_gp_attribute \
1809 target_core_alua_lu_gp_##_name = \
1810 __CONFIGFS_EATTR_RO(_name, \
1811 target_core_alua_lu_gp_show_attr_##_name);
1812
1813/*
1814 * lu_gp_id
1815 */
1816static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id(
1817 struct t10_alua_lu_gp *lu_gp,
1818 char *page)
1819{
Andy Grover6708bb22011-06-08 10:36:43 -07001820 if (!lu_gp->lu_gp_valid_id)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001821 return 0;
1822
1823 return sprintf(page, "%hu\n", lu_gp->lu_gp_id);
1824}
1825
1826static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id(
1827 struct t10_alua_lu_gp *lu_gp,
1828 const char *page,
1829 size_t count)
1830{
1831 struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group;
1832 unsigned long lu_gp_id;
1833 int ret;
1834
1835 ret = strict_strtoul(page, 0, &lu_gp_id);
1836 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07001837 pr_err("strict_strtoul() returned %d for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001838 " lu_gp_id\n", ret);
1839 return -EINVAL;
1840 }
1841 if (lu_gp_id > 0x0000ffff) {
Andy Grover6708bb22011-06-08 10:36:43 -07001842 pr_err("ALUA lu_gp_id: %lu exceeds maximum:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001843 " 0x0000ffff\n", lu_gp_id);
1844 return -EINVAL;
1845 }
1846
1847 ret = core_alua_set_lu_gp_id(lu_gp, (u16)lu_gp_id);
1848 if (ret < 0)
1849 return -EINVAL;
1850
Andy Grover6708bb22011-06-08 10:36:43 -07001851 pr_debug("Target_Core_ConfigFS: Set ALUA Logical Unit"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001852 " Group: core/alua/lu_gps/%s to ID: %hu\n",
1853 config_item_name(&alua_lu_gp_cg->cg_item),
1854 lu_gp->lu_gp_id);
1855
1856 return count;
1857}
1858
1859SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR);
1860
1861/*
1862 * members
1863 */
1864static ssize_t target_core_alua_lu_gp_show_attr_members(
1865 struct t10_alua_lu_gp *lu_gp,
1866 char *page)
1867{
1868 struct se_device *dev;
1869 struct se_hba *hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001870 struct t10_alua_lu_gp_member *lu_gp_mem;
1871 ssize_t len = 0, cur_len;
1872 unsigned char buf[LU_GROUP_NAME_BUF];
1873
1874 memset(buf, 0, LU_GROUP_NAME_BUF);
1875
1876 spin_lock(&lu_gp->lu_gp_lock);
1877 list_for_each_entry(lu_gp_mem, &lu_gp->lu_gp_mem_list, lu_gp_mem_list) {
1878 dev = lu_gp_mem->lu_gp_mem_dev;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001879 hba = dev->se_hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001880
1881 cur_len = snprintf(buf, LU_GROUP_NAME_BUF, "%s/%s\n",
1882 config_item_name(&hba->hba_group.cg_item),
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04001883 config_item_name(&dev->dev_group.cg_item));
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001884 cur_len++; /* Extra byte for NULL terminator */
1885
1886 if ((cur_len + len) > PAGE_SIZE) {
Andy Grover6708bb22011-06-08 10:36:43 -07001887 pr_warn("Ran out of lu_gp_show_attr"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001888 "_members buffer\n");
1889 break;
1890 }
1891 memcpy(page+len, buf, cur_len);
1892 len += cur_len;
1893 }
1894 spin_unlock(&lu_gp->lu_gp_lock);
1895
1896 return len;
1897}
1898
1899SE_DEV_ALUA_LU_ATTR_RO(members);
1900
1901CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group);
1902
1903static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = {
1904 &target_core_alua_lu_gp_lu_gp_id.attr,
1905 &target_core_alua_lu_gp_members.attr,
1906 NULL,
1907};
1908
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08001909static void target_core_alua_lu_gp_release(struct config_item *item)
1910{
1911 struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item),
1912 struct t10_alua_lu_gp, lu_gp_group);
1913
1914 core_alua_free_lu_gp(lu_gp);
1915}
1916
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001917static struct configfs_item_operations target_core_alua_lu_gp_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08001918 .release = target_core_alua_lu_gp_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001919 .show_attribute = target_core_alua_lu_gp_attr_show,
1920 .store_attribute = target_core_alua_lu_gp_attr_store,
1921};
1922
1923static struct config_item_type target_core_alua_lu_gp_cit = {
1924 .ct_item_ops = &target_core_alua_lu_gp_ops,
1925 .ct_attrs = target_core_alua_lu_gp_attrs,
1926 .ct_owner = THIS_MODULE,
1927};
1928
1929/* End functions for struct config_item_type target_core_alua_lu_gp_cit */
1930
1931/* Start functions for struct config_item_type target_core_alua_lu_gps_cit */
1932
1933static struct config_group *target_core_alua_create_lu_gp(
1934 struct config_group *group,
1935 const char *name)
1936{
1937 struct t10_alua_lu_gp *lu_gp;
1938 struct config_group *alua_lu_gp_cg = NULL;
1939 struct config_item *alua_lu_gp_ci = NULL;
1940
1941 lu_gp = core_alua_allocate_lu_gp(name, 0);
1942 if (IS_ERR(lu_gp))
1943 return NULL;
1944
1945 alua_lu_gp_cg = &lu_gp->lu_gp_group;
1946 alua_lu_gp_ci = &alua_lu_gp_cg->cg_item;
1947
1948 config_group_init_type_name(alua_lu_gp_cg, name,
1949 &target_core_alua_lu_gp_cit);
1950
Andy Grover6708bb22011-06-08 10:36:43 -07001951 pr_debug("Target_Core_ConfigFS: Allocated ALUA Logical Unit"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001952 " Group: core/alua/lu_gps/%s\n",
1953 config_item_name(alua_lu_gp_ci));
1954
1955 return alua_lu_gp_cg;
1956
1957}
1958
1959static void target_core_alua_drop_lu_gp(
1960 struct config_group *group,
1961 struct config_item *item)
1962{
1963 struct t10_alua_lu_gp *lu_gp = container_of(to_config_group(item),
1964 struct t10_alua_lu_gp, lu_gp_group);
1965
Andy Grover6708bb22011-06-08 10:36:43 -07001966 pr_debug("Target_Core_ConfigFS: Releasing ALUA Logical Unit"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001967 " Group: core/alua/lu_gps/%s, ID: %hu\n",
1968 config_item_name(item), lu_gp->lu_gp_id);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08001969 /*
1970 * core_alua_free_lu_gp() is called from target_core_alua_lu_gp_ops->release()
1971 * -> target_core_alua_lu_gp_release()
1972 */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001973 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08001974}
1975
1976static struct configfs_group_operations target_core_alua_lu_gps_group_ops = {
1977 .make_group = &target_core_alua_create_lu_gp,
1978 .drop_item = &target_core_alua_drop_lu_gp,
1979};
1980
1981static struct config_item_type target_core_alua_lu_gps_cit = {
1982 .ct_item_ops = NULL,
1983 .ct_group_ops = &target_core_alua_lu_gps_group_ops,
1984 .ct_owner = THIS_MODULE,
1985};
1986
1987/* End functions for struct config_item_type target_core_alua_lu_gps_cit */
1988
1989/* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
1990
1991CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp);
1992#define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \
1993static struct target_core_alua_tg_pt_gp_attribute \
1994 target_core_alua_tg_pt_gp_##_name = \
1995 __CONFIGFS_EATTR(_name, _mode, \
1996 target_core_alua_tg_pt_gp_show_attr_##_name, \
1997 target_core_alua_tg_pt_gp_store_attr_##_name);
1998
1999#define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2000static struct target_core_alua_tg_pt_gp_attribute \
2001 target_core_alua_tg_pt_gp_##_name = \
2002 __CONFIGFS_EATTR_RO(_name, \
2003 target_core_alua_tg_pt_gp_show_attr_##_name);
2004
2005/*
2006 * alua_access_state
2007 */
2008static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2009 struct t10_alua_tg_pt_gp *tg_pt_gp,
2010 char *page)
2011{
2012 return sprintf(page, "%d\n",
2013 atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state));
2014}
2015
2016static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2017 struct t10_alua_tg_pt_gp *tg_pt_gp,
2018 const char *page,
2019 size_t count)
2020{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002021 struct se_device *dev = tg_pt_gp->tg_pt_gp_dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002022 unsigned long tmp;
2023 int new_state, ret;
2024
Andy Grover6708bb22011-06-08 10:36:43 -07002025 if (!tg_pt_gp->tg_pt_gp_valid_id) {
2026 pr_err("Unable to do implict ALUA on non valid"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002027 " tg_pt_gp ID: %hu\n", tg_pt_gp->tg_pt_gp_valid_id);
2028 return -EINVAL;
2029 }
2030
2031 ret = strict_strtoul(page, 0, &tmp);
2032 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002033 pr_err("Unable to extract new ALUA access state from"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002034 " %s\n", page);
2035 return -EINVAL;
2036 }
2037 new_state = (int)tmp;
2038
2039 if (!(tg_pt_gp->tg_pt_gp_alua_access_type & TPGS_IMPLICT_ALUA)) {
Andy Grover6708bb22011-06-08 10:36:43 -07002040 pr_err("Unable to process implict configfs ALUA"
Masanari Iida5e58b022012-02-27 23:18:15 +09002041 " transition while TPGS_IMPLICT_ALUA is disabled\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002042 return -EINVAL;
2043 }
2044
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002045 ret = core_alua_do_port_transition(tg_pt_gp, dev,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002046 NULL, NULL, new_state, 0);
2047 return (!ret) ? count : -EINVAL;
2048}
2049
2050SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR);
2051
2052/*
2053 * alua_access_status
2054 */
2055static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2056 struct t10_alua_tg_pt_gp *tg_pt_gp,
2057 char *page)
2058{
2059 return sprintf(page, "%s\n",
2060 core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status));
2061}
2062
2063static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2064 struct t10_alua_tg_pt_gp *tg_pt_gp,
2065 const char *page,
2066 size_t count)
2067{
2068 unsigned long tmp;
2069 int new_status, ret;
2070
Andy Grover6708bb22011-06-08 10:36:43 -07002071 if (!tg_pt_gp->tg_pt_gp_valid_id) {
2072 pr_err("Unable to do set ALUA access status on non"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002073 " valid tg_pt_gp ID: %hu\n",
2074 tg_pt_gp->tg_pt_gp_valid_id);
2075 return -EINVAL;
2076 }
2077
2078 ret = strict_strtoul(page, 0, &tmp);
2079 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002080 pr_err("Unable to extract new ALUA access status"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002081 " from %s\n", page);
2082 return -EINVAL;
2083 }
2084 new_status = (int)tmp;
2085
2086 if ((new_status != ALUA_STATUS_NONE) &&
2087 (new_status != ALUA_STATUS_ALTERED_BY_EXPLICT_STPG) &&
2088 (new_status != ALUA_STATUS_ALTERED_BY_IMPLICT_ALUA)) {
Andy Grover6708bb22011-06-08 10:36:43 -07002089 pr_err("Illegal ALUA access status: 0x%02x\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002090 new_status);
2091 return -EINVAL;
2092 }
2093
2094 tg_pt_gp->tg_pt_gp_alua_access_status = new_status;
2095 return count;
2096}
2097
2098SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR);
2099
2100/*
2101 * alua_access_type
2102 */
2103static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2104 struct t10_alua_tg_pt_gp *tg_pt_gp,
2105 char *page)
2106{
2107 return core_alua_show_access_type(tg_pt_gp, page);
2108}
2109
2110static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type(
2111 struct t10_alua_tg_pt_gp *tg_pt_gp,
2112 const char *page,
2113 size_t count)
2114{
2115 return core_alua_store_access_type(tg_pt_gp, page, count);
2116}
2117
2118SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR);
2119
2120/*
2121 * alua_write_metadata
2122 */
2123static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2124 struct t10_alua_tg_pt_gp *tg_pt_gp,
2125 char *page)
2126{
2127 return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata);
2128}
2129
2130static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2131 struct t10_alua_tg_pt_gp *tg_pt_gp,
2132 const char *page,
2133 size_t count)
2134{
2135 unsigned long tmp;
2136 int ret;
2137
2138 ret = strict_strtoul(page, 0, &tmp);
2139 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002140 pr_err("Unable to extract alua_write_metadata\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002141 return -EINVAL;
2142 }
2143
2144 if ((tmp != 0) && (tmp != 1)) {
Andy Grover6708bb22011-06-08 10:36:43 -07002145 pr_err("Illegal value for alua_write_metadata:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002146 " %lu\n", tmp);
2147 return -EINVAL;
2148 }
2149 tg_pt_gp->tg_pt_gp_write_metadata = (int)tmp;
2150
2151 return count;
2152}
2153
2154SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR);
2155
2156
2157
2158/*
2159 * nonop_delay_msecs
2160 */
2161static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2162 struct t10_alua_tg_pt_gp *tg_pt_gp,
2163 char *page)
2164{
2165 return core_alua_show_nonop_delay_msecs(tg_pt_gp, page);
2166
2167}
2168
2169static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs(
2170 struct t10_alua_tg_pt_gp *tg_pt_gp,
2171 const char *page,
2172 size_t count)
2173{
2174 return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count);
2175}
2176
2177SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR);
2178
2179/*
2180 * trans_delay_msecs
2181 */
2182static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2183 struct t10_alua_tg_pt_gp *tg_pt_gp,
2184 char *page)
2185{
2186 return core_alua_show_trans_delay_msecs(tg_pt_gp, page);
2187}
2188
2189static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs(
2190 struct t10_alua_tg_pt_gp *tg_pt_gp,
2191 const char *page,
2192 size_t count)
2193{
2194 return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count);
2195}
2196
2197SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR);
2198
2199/*
Nicholas Bellinger5b9a4d72012-05-16 22:02:34 -07002200 * implict_trans_secs
2201 */
2202static ssize_t target_core_alua_tg_pt_gp_show_attr_implict_trans_secs(
2203 struct t10_alua_tg_pt_gp *tg_pt_gp,
2204 char *page)
2205{
2206 return core_alua_show_implict_trans_secs(tg_pt_gp, page);
2207}
2208
2209static ssize_t target_core_alua_tg_pt_gp_store_attr_implict_trans_secs(
2210 struct t10_alua_tg_pt_gp *tg_pt_gp,
2211 const char *page,
2212 size_t count)
2213{
2214 return core_alua_store_implict_trans_secs(tg_pt_gp, page, count);
2215}
2216
2217SE_DEV_ALUA_TG_PT_ATTR(implict_trans_secs, S_IRUGO | S_IWUSR);
2218
2219/*
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002220 * preferred
2221 */
2222
2223static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred(
2224 struct t10_alua_tg_pt_gp *tg_pt_gp,
2225 char *page)
2226{
2227 return core_alua_show_preferred_bit(tg_pt_gp, page);
2228}
2229
2230static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred(
2231 struct t10_alua_tg_pt_gp *tg_pt_gp,
2232 const char *page,
2233 size_t count)
2234{
2235 return core_alua_store_preferred_bit(tg_pt_gp, page, count);
2236}
2237
2238SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR);
2239
2240/*
2241 * tg_pt_gp_id
2242 */
2243static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2244 struct t10_alua_tg_pt_gp *tg_pt_gp,
2245 char *page)
2246{
Andy Grover6708bb22011-06-08 10:36:43 -07002247 if (!tg_pt_gp->tg_pt_gp_valid_id)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002248 return 0;
2249
2250 return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id);
2251}
2252
2253static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2254 struct t10_alua_tg_pt_gp *tg_pt_gp,
2255 const char *page,
2256 size_t count)
2257{
2258 struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group;
2259 unsigned long tg_pt_gp_id;
2260 int ret;
2261
2262 ret = strict_strtoul(page, 0, &tg_pt_gp_id);
2263 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002264 pr_err("strict_strtoul() returned %d for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002265 " tg_pt_gp_id\n", ret);
2266 return -EINVAL;
2267 }
2268 if (tg_pt_gp_id > 0x0000ffff) {
Andy Grover6708bb22011-06-08 10:36:43 -07002269 pr_err("ALUA tg_pt_gp_id: %lu exceeds maximum:"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002270 " 0x0000ffff\n", tg_pt_gp_id);
2271 return -EINVAL;
2272 }
2273
2274 ret = core_alua_set_tg_pt_gp_id(tg_pt_gp, (u16)tg_pt_gp_id);
2275 if (ret < 0)
2276 return -EINVAL;
2277
Andy Grover6708bb22011-06-08 10:36:43 -07002278 pr_debug("Target_Core_ConfigFS: Set ALUA Target Port Group: "
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002279 "core/alua/tg_pt_gps/%s to ID: %hu\n",
2280 config_item_name(&alua_tg_pt_gp_cg->cg_item),
2281 tg_pt_gp->tg_pt_gp_id);
2282
2283 return count;
2284}
2285
2286SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR);
2287
2288/*
2289 * members
2290 */
2291static ssize_t target_core_alua_tg_pt_gp_show_attr_members(
2292 struct t10_alua_tg_pt_gp *tg_pt_gp,
2293 char *page)
2294{
2295 struct se_port *port;
2296 struct se_portal_group *tpg;
2297 struct se_lun *lun;
2298 struct t10_alua_tg_pt_gp_member *tg_pt_gp_mem;
2299 ssize_t len = 0, cur_len;
2300 unsigned char buf[TG_PT_GROUP_NAME_BUF];
2301
2302 memset(buf, 0, TG_PT_GROUP_NAME_BUF);
2303
2304 spin_lock(&tg_pt_gp->tg_pt_gp_lock);
2305 list_for_each_entry(tg_pt_gp_mem, &tg_pt_gp->tg_pt_gp_mem_list,
2306 tg_pt_gp_mem_list) {
2307 port = tg_pt_gp_mem->tg_pt;
2308 tpg = port->sep_tpg;
2309 lun = port->sep_lun;
2310
2311 cur_len = snprintf(buf, TG_PT_GROUP_NAME_BUF, "%s/%s/tpgt_%hu"
Andy Grovere3d6f902011-07-19 08:55:10 +00002312 "/%s\n", tpg->se_tpg_tfo->get_fabric_name(),
2313 tpg->se_tpg_tfo->tpg_get_wwn(tpg),
2314 tpg->se_tpg_tfo->tpg_get_tag(tpg),
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002315 config_item_name(&lun->lun_group.cg_item));
2316 cur_len++; /* Extra byte for NULL terminator */
2317
2318 if ((cur_len + len) > PAGE_SIZE) {
Andy Grover6708bb22011-06-08 10:36:43 -07002319 pr_warn("Ran out of lu_gp_show_attr"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002320 "_members buffer\n");
2321 break;
2322 }
2323 memcpy(page+len, buf, cur_len);
2324 len += cur_len;
2325 }
2326 spin_unlock(&tg_pt_gp->tg_pt_gp_lock);
2327
2328 return len;
2329}
2330
2331SE_DEV_ALUA_TG_PT_ATTR_RO(members);
2332
2333CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp,
2334 tg_pt_gp_group);
2335
2336static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = {
2337 &target_core_alua_tg_pt_gp_alua_access_state.attr,
2338 &target_core_alua_tg_pt_gp_alua_access_status.attr,
2339 &target_core_alua_tg_pt_gp_alua_access_type.attr,
2340 &target_core_alua_tg_pt_gp_alua_write_metadata.attr,
2341 &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr,
2342 &target_core_alua_tg_pt_gp_trans_delay_msecs.attr,
Nicholas Bellinger5b9a4d72012-05-16 22:02:34 -07002343 &target_core_alua_tg_pt_gp_implict_trans_secs.attr,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002344 &target_core_alua_tg_pt_gp_preferred.attr,
2345 &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr,
2346 &target_core_alua_tg_pt_gp_members.attr,
2347 NULL,
2348};
2349
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002350static void target_core_alua_tg_pt_gp_release(struct config_item *item)
2351{
2352 struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item),
2353 struct t10_alua_tg_pt_gp, tg_pt_gp_group);
2354
2355 core_alua_free_tg_pt_gp(tg_pt_gp);
2356}
2357
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002358static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002359 .release = target_core_alua_tg_pt_gp_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002360 .show_attribute = target_core_alua_tg_pt_gp_attr_show,
2361 .store_attribute = target_core_alua_tg_pt_gp_attr_store,
2362};
2363
2364static struct config_item_type target_core_alua_tg_pt_gp_cit = {
2365 .ct_item_ops = &target_core_alua_tg_pt_gp_ops,
2366 .ct_attrs = target_core_alua_tg_pt_gp_attrs,
2367 .ct_owner = THIS_MODULE,
2368};
2369
2370/* End functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2371
2372/* Start functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2373
2374static struct config_group *target_core_alua_create_tg_pt_gp(
2375 struct config_group *group,
2376 const char *name)
2377{
2378 struct t10_alua *alua = container_of(group, struct t10_alua,
2379 alua_tg_pt_gps_group);
2380 struct t10_alua_tg_pt_gp *tg_pt_gp;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002381 struct config_group *alua_tg_pt_gp_cg = NULL;
2382 struct config_item *alua_tg_pt_gp_ci = NULL;
2383
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002384 tg_pt_gp = core_alua_allocate_tg_pt_gp(alua->t10_dev, name, 0);
Andy Grover6708bb22011-06-08 10:36:43 -07002385 if (!tg_pt_gp)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002386 return NULL;
2387
2388 alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group;
2389 alua_tg_pt_gp_ci = &alua_tg_pt_gp_cg->cg_item;
2390
2391 config_group_init_type_name(alua_tg_pt_gp_cg, name,
2392 &target_core_alua_tg_pt_gp_cit);
2393
Andy Grover6708bb22011-06-08 10:36:43 -07002394 pr_debug("Target_Core_ConfigFS: Allocated ALUA Target Port"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002395 " Group: alua/tg_pt_gps/%s\n",
2396 config_item_name(alua_tg_pt_gp_ci));
2397
2398 return alua_tg_pt_gp_cg;
2399}
2400
2401static void target_core_alua_drop_tg_pt_gp(
2402 struct config_group *group,
2403 struct config_item *item)
2404{
2405 struct t10_alua_tg_pt_gp *tg_pt_gp = container_of(to_config_group(item),
2406 struct t10_alua_tg_pt_gp, tg_pt_gp_group);
2407
Andy Grover6708bb22011-06-08 10:36:43 -07002408 pr_debug("Target_Core_ConfigFS: Releasing ALUA Target Port"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002409 " Group: alua/tg_pt_gps/%s, ID: %hu\n",
2410 config_item_name(item), tg_pt_gp->tg_pt_gp_id);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002411 /*
2412 * core_alua_free_tg_pt_gp() is called from target_core_alua_tg_pt_gp_ops->release()
2413 * -> target_core_alua_tg_pt_gp_release().
2414 */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002415 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002416}
2417
2418static struct configfs_group_operations target_core_alua_tg_pt_gps_group_ops = {
2419 .make_group = &target_core_alua_create_tg_pt_gp,
2420 .drop_item = &target_core_alua_drop_tg_pt_gp,
2421};
2422
2423static struct config_item_type target_core_alua_tg_pt_gps_cit = {
2424 .ct_group_ops = &target_core_alua_tg_pt_gps_group_ops,
2425 .ct_owner = THIS_MODULE,
2426};
2427
2428/* End functions for struct config_item_type target_core_alua_tg_pt_gps_cit */
2429
2430/* Start functions for struct config_item_type target_core_alua_cit */
2431
2432/*
2433 * target_core_alua_cit is a ConfigFS group that lives under
2434 * /sys/kernel/config/target/core/alua. There are default groups
2435 * core/alua/lu_gps and core/alua/tg_pt_gps that are attached to
2436 * target_core_alua_cit in target_core_init_configfs() below.
2437 */
2438static struct config_item_type target_core_alua_cit = {
2439 .ct_item_ops = NULL,
2440 .ct_attrs = NULL,
2441 .ct_owner = THIS_MODULE,
2442};
2443
2444/* End functions for struct config_item_type target_core_alua_cit */
2445
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002446/* Start functions for struct config_item_type target_core_stat_cit */
2447
2448static struct config_group *target_core_stat_mkdir(
2449 struct config_group *group,
2450 const char *name)
2451{
2452 return ERR_PTR(-ENOSYS);
2453}
2454
2455static void target_core_stat_rmdir(
2456 struct config_group *group,
2457 struct config_item *item)
2458{
2459 return;
2460}
2461
2462static struct configfs_group_operations target_core_stat_group_ops = {
2463 .make_group = &target_core_stat_mkdir,
2464 .drop_item = &target_core_stat_rmdir,
2465};
2466
2467static struct config_item_type target_core_stat_cit = {
2468 .ct_group_ops = &target_core_stat_group_ops,
2469 .ct_owner = THIS_MODULE,
2470};
2471
2472/* End functions for struct config_item_type target_core_stat_cit */
2473
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002474/* Start functions for struct config_item_type target_core_hba_cit */
2475
2476static struct config_group *target_core_make_subdev(
2477 struct config_group *group,
2478 const char *name)
2479{
2480 struct t10_alua_tg_pt_gp *tg_pt_gp;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002481 struct se_subsystem_api *t;
2482 struct config_item *hba_ci = &group->cg_item;
2483 struct se_hba *hba = item_to_hba(hba_ci);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002484 struct se_device *dev;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002485 struct config_group *dev_cg = NULL, *tg_pt_gp_cg = NULL;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002486 struct config_group *dev_stat_grp = NULL;
2487 int errno = -ENOMEM, ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002488
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002489 ret = mutex_lock_interruptible(&hba->hba_access_mutex);
2490 if (ret)
2491 return ERR_PTR(ret);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002492 /*
2493 * Locate the struct se_subsystem_api from parent's struct se_hba.
2494 */
2495 t = hba->transport;
2496
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002497 dev = target_alloc_device(hba, name);
2498 if (!dev)
2499 goto out_unlock;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002500
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002501 dev_cg = &dev->dev_group;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002502
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002503 dev_cg->default_groups = kmalloc(sizeof(struct config_group *) * 6,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002504 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07002505 if (!dev_cg->default_groups)
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002506 goto out_free_device;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002507
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002508 config_group_init_type_name(dev_cg, name, &target_core_dev_cit);
2509 config_group_init_type_name(&dev->dev_attrib.da_group, "attrib",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002510 &target_core_dev_attrib_cit);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002511 config_group_init_type_name(&dev->dev_pr_group, "pr",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002512 &target_core_dev_pr_cit);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002513 config_group_init_type_name(&dev->t10_wwn.t10_wwn_group, "wwn",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002514 &target_core_dev_wwn_cit);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002515 config_group_init_type_name(&dev->t10_alua.alua_tg_pt_gps_group,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002516 "alua", &target_core_alua_tg_pt_gps_cit);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002517 config_group_init_type_name(&dev->dev_stat_grps.stat_group,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002518 "statistics", &target_core_stat_cit);
2519
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002520 dev_cg->default_groups[0] = &dev->dev_attrib.da_group;
2521 dev_cg->default_groups[1] = &dev->dev_pr_group;
2522 dev_cg->default_groups[2] = &dev->t10_wwn.t10_wwn_group;
2523 dev_cg->default_groups[3] = &dev->t10_alua.alua_tg_pt_gps_group;
2524 dev_cg->default_groups[4] = &dev->dev_stat_grps.stat_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002525 dev_cg->default_groups[5] = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002526 /*
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002527 * Add core/$HBA/$DEV/alua/default_tg_pt_gp
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002528 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002529 tg_pt_gp = core_alua_allocate_tg_pt_gp(dev, "default_tg_pt_gp", 1);
Andy Grover6708bb22011-06-08 10:36:43 -07002530 if (!tg_pt_gp)
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002531 goto out_free_dev_cg_default_groups;
2532 dev->t10_alua.default_tg_pt_gp = tg_pt_gp;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002533
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002534 tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group;
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002535 tg_pt_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002536 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07002537 if (!tg_pt_gp_cg->default_groups) {
2538 pr_err("Unable to allocate tg_pt_gp_cg->"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002539 "default_groups\n");
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002540 goto out_free_tg_pt_gp;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002541 }
2542
2543 config_group_init_type_name(&tg_pt_gp->tg_pt_gp_group,
2544 "default_tg_pt_gp", &target_core_alua_tg_pt_gp_cit);
2545 tg_pt_gp_cg->default_groups[0] = &tg_pt_gp->tg_pt_gp_group;
2546 tg_pt_gp_cg->default_groups[1] = NULL;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002547 /*
2548 * Add core/$HBA/$DEV/statistics/ default groups
2549 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002550 dev_stat_grp = &dev->dev_stat_grps.stat_group;
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002551 dev_stat_grp->default_groups = kmalloc(sizeof(struct config_group *) * 4,
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002552 GFP_KERNEL);
2553 if (!dev_stat_grp->default_groups) {
Andy Grover6708bb22011-06-08 10:36:43 -07002554 pr_err("Unable to allocate dev_stat_grp->default_groups\n");
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002555 goto out_free_tg_pt_gp_cg_default_groups;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002556 }
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002557 target_stat_setup_dev_default_groups(dev);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002558
2559 mutex_unlock(&hba->hba_access_mutex);
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002560 return dev_cg;
2561
2562out_free_tg_pt_gp_cg_default_groups:
2563 kfree(tg_pt_gp_cg->default_groups);
2564out_free_tg_pt_gp:
2565 core_alua_free_tg_pt_gp(tg_pt_gp);
2566out_free_dev_cg_default_groups:
2567 kfree(dev_cg->default_groups);
2568out_free_device:
2569 target_free_device(dev);
2570out_unlock:
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002571 mutex_unlock(&hba->hba_access_mutex);
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002572 return ERR_PTR(errno);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002573}
2574
2575static void target_core_drop_subdev(
2576 struct config_group *group,
2577 struct config_item *item)
2578{
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002579 struct config_group *dev_cg = to_config_group(item);
2580 struct se_device *dev =
2581 container_of(dev_cg, struct se_device, dev_group);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002582 struct se_hba *hba;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002583 struct config_item *df_item;
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002584 struct config_group *tg_pt_gp_cg, *dev_stat_grp;
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002585 int i;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002586
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002587 hba = item_to_hba(&dev->se_hba->hba_group.cg_item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002588
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002589 mutex_lock(&hba->hba_access_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002590
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002591 dev_stat_grp = &dev->dev_stat_grps.stat_group;
Nicholas Bellinger12d2338422011-03-14 04:06:11 -07002592 for (i = 0; dev_stat_grp->default_groups[i]; i++) {
2593 df_item = &dev_stat_grp->default_groups[i]->cg_item;
2594 dev_stat_grp->default_groups[i] = NULL;
2595 config_item_put(df_item);
2596 }
2597 kfree(dev_stat_grp->default_groups);
2598
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002599 tg_pt_gp_cg = &dev->t10_alua.alua_tg_pt_gps_group;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002600 for (i = 0; tg_pt_gp_cg->default_groups[i]; i++) {
2601 df_item = &tg_pt_gp_cg->default_groups[i]->cg_item;
2602 tg_pt_gp_cg->default_groups[i] = NULL;
2603 config_item_put(df_item);
2604 }
2605 kfree(tg_pt_gp_cg->default_groups);
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002606 /*
2607 * core_alua_free_tg_pt_gp() is called from ->default_tg_pt_gp
2608 * directly from target_core_alua_tg_pt_gp_release().
2609 */
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002610 dev->t10_alua.default_tg_pt_gp = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002611
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002612 for (i = 0; dev_cg->default_groups[i]; i++) {
2613 df_item = &dev_cg->default_groups[i]->cg_item;
2614 dev_cg->default_groups[i] = NULL;
2615 config_item_put(df_item);
2616 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002617 /*
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002618 * se_dev is released from target_core_dev_item_ops->release()
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002619 */
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002620 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002621 mutex_unlock(&hba->hba_access_mutex);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002622}
2623
2624static struct configfs_group_operations target_core_hba_group_ops = {
2625 .make_group = target_core_make_subdev,
2626 .drop_item = target_core_drop_subdev,
2627};
2628
2629CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba);
2630#define SE_HBA_ATTR(_name, _mode) \
2631static struct target_core_hba_attribute \
2632 target_core_hba_##_name = \
2633 __CONFIGFS_EATTR(_name, _mode, \
2634 target_core_hba_show_attr_##_name, \
2635 target_core_hba_store_attr_##_name);
2636
2637#define SE_HBA_ATTR_RO(_name) \
2638static struct target_core_hba_attribute \
2639 target_core_hba_##_name = \
2640 __CONFIGFS_EATTR_RO(_name, \
2641 target_core_hba_show_attr_##_name);
2642
2643static ssize_t target_core_hba_show_attr_hba_info(
2644 struct se_hba *hba,
2645 char *page)
2646{
2647 return sprintf(page, "HBA Index: %d plugin: %s version: %s\n",
2648 hba->hba_id, hba->transport->name,
2649 TARGET_CORE_CONFIGFS_VERSION);
2650}
2651
2652SE_HBA_ATTR_RO(hba_info);
2653
2654static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba,
2655 char *page)
2656{
2657 int hba_mode = 0;
2658
2659 if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE)
2660 hba_mode = 1;
2661
2662 return sprintf(page, "%d\n", hba_mode);
2663}
2664
2665static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba,
2666 const char *page, size_t count)
2667{
2668 struct se_subsystem_api *transport = hba->transport;
2669 unsigned long mode_flag;
2670 int ret;
2671
2672 if (transport->pmode_enable_hba == NULL)
2673 return -EINVAL;
2674
2675 ret = strict_strtoul(page, 0, &mode_flag);
2676 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002677 pr_err("Unable to extract hba mode flag: %d\n", ret);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002678 return -EINVAL;
2679 }
2680
Christoph Hellwig0fd97cc2012-10-08 00:03:19 -04002681 if (hba->dev_count) {
Andy Grover6708bb22011-06-08 10:36:43 -07002682 pr_err("Unable to set hba_mode with active devices\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002683 return -EINVAL;
2684 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002685
2686 ret = transport->pmode_enable_hba(hba, mode_flag);
2687 if (ret < 0)
2688 return -EINVAL;
2689 if (ret > 0)
2690 hba->hba_flags |= HBA_FLAGS_PSCSI_MODE;
2691 else if (ret == 0)
2692 hba->hba_flags &= ~HBA_FLAGS_PSCSI_MODE;
2693
2694 return count;
2695}
2696
2697SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR);
2698
2699CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group);
2700
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002701static void target_core_hba_release(struct config_item *item)
2702{
2703 struct se_hba *hba = container_of(to_config_group(item),
2704 struct se_hba, hba_group);
2705 core_delete_hba(hba);
2706}
2707
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002708static struct configfs_attribute *target_core_hba_attrs[] = {
2709 &target_core_hba_hba_info.attr,
2710 &target_core_hba_hba_mode.attr,
2711 NULL,
2712};
2713
2714static struct configfs_item_operations target_core_hba_item_ops = {
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002715 .release = target_core_hba_release,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002716 .show_attribute = target_core_hba_attr_show,
2717 .store_attribute = target_core_hba_attr_store,
2718};
2719
2720static struct config_item_type target_core_hba_cit = {
2721 .ct_item_ops = &target_core_hba_item_ops,
2722 .ct_group_ops = &target_core_hba_group_ops,
2723 .ct_attrs = target_core_hba_attrs,
2724 .ct_owner = THIS_MODULE,
2725};
2726
2727static struct config_group *target_core_call_addhbatotarget(
2728 struct config_group *group,
2729 const char *name)
2730{
2731 char *se_plugin_str, *str, *str2;
2732 struct se_hba *hba;
2733 char buf[TARGET_CORE_NAME_MAX_LEN];
2734 unsigned long plugin_dep_id = 0;
2735 int ret;
2736
2737 memset(buf, 0, TARGET_CORE_NAME_MAX_LEN);
Dan Carpenter60d645a2011-06-15 10:03:05 -07002738 if (strlen(name) >= TARGET_CORE_NAME_MAX_LEN) {
Andy Grover6708bb22011-06-08 10:36:43 -07002739 pr_err("Passed *name strlen(): %d exceeds"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002740 " TARGET_CORE_NAME_MAX_LEN: %d\n", (int)strlen(name),
2741 TARGET_CORE_NAME_MAX_LEN);
2742 return ERR_PTR(-ENAMETOOLONG);
2743 }
2744 snprintf(buf, TARGET_CORE_NAME_MAX_LEN, "%s", name);
2745
2746 str = strstr(buf, "_");
Andy Grover6708bb22011-06-08 10:36:43 -07002747 if (!str) {
2748 pr_err("Unable to locate \"_\" for $SUBSYSTEM_PLUGIN_$HOST_ID\n");
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002749 return ERR_PTR(-EINVAL);
2750 }
2751 se_plugin_str = buf;
2752 /*
2753 * Special case for subsystem plugins that have "_" in their names.
2754 * Namely rd_direct and rd_mcp..
2755 */
2756 str2 = strstr(str+1, "_");
Andy Grover6708bb22011-06-08 10:36:43 -07002757 if (str2) {
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002758 *str2 = '\0'; /* Terminate for *se_plugin_str */
2759 str2++; /* Skip to start of plugin dependent ID */
2760 str = str2;
2761 } else {
2762 *str = '\0'; /* Terminate for *se_plugin_str */
2763 str++; /* Skip to start of plugin dependent ID */
2764 }
2765
2766 ret = strict_strtoul(str, 0, &plugin_dep_id);
2767 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002768 pr_err("strict_strtoul() returned %d for"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002769 " plugin_dep_id\n", ret);
2770 return ERR_PTR(-EINVAL);
2771 }
2772 /*
2773 * Load up TCM subsystem plugins if they have not already been loaded.
2774 */
Nicholas Bellingerdbc56232011-10-22 01:03:54 -07002775 transport_subsystem_check_init();
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002776
2777 hba = core_alloc_hba(se_plugin_str, plugin_dep_id, 0);
2778 if (IS_ERR(hba))
2779 return ERR_CAST(hba);
2780
2781 config_group_init_type_name(&hba->hba_group, name,
2782 &target_core_hba_cit);
2783
2784 return &hba->hba_group;
2785}
2786
2787static void target_core_call_delhbafromtarget(
2788 struct config_group *group,
2789 struct config_item *item)
2790{
Nicholas Bellinger1f6fe7c2011-02-09 15:34:54 -08002791 /*
2792 * core_delete_hba() is called from target_core_hba_item_ops->release()
2793 * -> target_core_hba_release()
2794 */
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002795 config_item_put(item);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002796}
2797
2798static struct configfs_group_operations target_core_group_ops = {
2799 .make_group = target_core_call_addhbatotarget,
2800 .drop_item = target_core_call_delhbafromtarget,
2801};
2802
2803static struct config_item_type target_core_cit = {
2804 .ct_item_ops = NULL,
2805 .ct_group_ops = &target_core_group_ops,
2806 .ct_attrs = NULL,
2807 .ct_owner = THIS_MODULE,
2808};
2809
2810/* Stop functions for struct config_item_type target_core_hba_cit */
2811
Axel Lin54550fa2011-03-14 04:06:09 -07002812static int __init target_core_init_configfs(void)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002813{
2814 struct config_group *target_cg, *hba_cg = NULL, *alua_cg = NULL;
2815 struct config_group *lu_gp_cg = NULL;
2816 struct configfs_subsystem *subsys;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002817 struct t10_alua_lu_gp *lu_gp;
2818 int ret;
2819
Andy Grover6708bb22011-06-08 10:36:43 -07002820 pr_debug("TARGET_CORE[0]: Loading Generic Kernel Storage"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002821 " Engine: %s on %s/%s on "UTS_RELEASE"\n",
2822 TARGET_CORE_VERSION, utsname()->sysname, utsname()->machine);
2823
2824 subsys = target_core_subsystem[0];
2825 config_group_init(&subsys->su_group);
2826 mutex_init(&subsys->su_mutex);
2827
Andy Grovere3d6f902011-07-19 08:55:10 +00002828 ret = init_se_kmem_caches();
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002829 if (ret < 0)
Andy Grovere3d6f902011-07-19 08:55:10 +00002830 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002831 /*
2832 * Create $CONFIGFS/target/core default group for HBA <-> Storage Object
2833 * and ALUA Logical Unit Group and Target Port Group infrastructure.
2834 */
2835 target_cg = &subsys->su_group;
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002836 target_cg->default_groups = kmalloc(sizeof(struct config_group) * 2,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002837 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07002838 if (!target_cg->default_groups) {
2839 pr_err("Unable to allocate target_cg->default_groups\n");
Peter Senna Tschudin37bb7892012-09-17 20:05:33 +02002840 ret = -ENOMEM;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002841 goto out_global;
2842 }
2843
Andy Grovere3d6f902011-07-19 08:55:10 +00002844 config_group_init_type_name(&target_core_hbagroup,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002845 "core", &target_core_cit);
Andy Grovere3d6f902011-07-19 08:55:10 +00002846 target_cg->default_groups[0] = &target_core_hbagroup;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002847 target_cg->default_groups[1] = NULL;
2848 /*
2849 * Create ALUA infrastructure under /sys/kernel/config/target/core/alua/
2850 */
Andy Grovere3d6f902011-07-19 08:55:10 +00002851 hba_cg = &target_core_hbagroup;
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002852 hba_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002853 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07002854 if (!hba_cg->default_groups) {
2855 pr_err("Unable to allocate hba_cg->default_groups\n");
Peter Senna Tschudin37bb7892012-09-17 20:05:33 +02002856 ret = -ENOMEM;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002857 goto out_global;
2858 }
Andy Grovere3d6f902011-07-19 08:55:10 +00002859 config_group_init_type_name(&alua_group,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002860 "alua", &target_core_alua_cit);
Andy Grovere3d6f902011-07-19 08:55:10 +00002861 hba_cg->default_groups[0] = &alua_group;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002862 hba_cg->default_groups[1] = NULL;
2863 /*
2864 * Add ALUA Logical Unit Group and Target Port Group ConfigFS
2865 * groups under /sys/kernel/config/target/core/alua/
2866 */
Andy Grovere3d6f902011-07-19 08:55:10 +00002867 alua_cg = &alua_group;
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002868 alua_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002869 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07002870 if (!alua_cg->default_groups) {
2871 pr_err("Unable to allocate alua_cg->default_groups\n");
Peter Senna Tschudin37bb7892012-09-17 20:05:33 +02002872 ret = -ENOMEM;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002873 goto out_global;
2874 }
2875
Andy Grovere3d6f902011-07-19 08:55:10 +00002876 config_group_init_type_name(&alua_lu_gps_group,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002877 "lu_gps", &target_core_alua_lu_gps_cit);
Andy Grovere3d6f902011-07-19 08:55:10 +00002878 alua_cg->default_groups[0] = &alua_lu_gps_group;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002879 alua_cg->default_groups[1] = NULL;
2880 /*
2881 * Add core/alua/lu_gps/default_lu_gp
2882 */
2883 lu_gp = core_alua_allocate_lu_gp("default_lu_gp", 1);
Peter Senna Tschudin37bb7892012-09-17 20:05:33 +02002884 if (IS_ERR(lu_gp)) {
2885 ret = -ENOMEM;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002886 goto out_global;
Peter Senna Tschudin37bb7892012-09-17 20:05:33 +02002887 }
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002888
Andy Grovere3d6f902011-07-19 08:55:10 +00002889 lu_gp_cg = &alua_lu_gps_group;
Sebastian Andrzej Siewior13f6a912012-11-27 18:54:21 +01002890 lu_gp_cg->default_groups = kmalloc(sizeof(struct config_group *) * 2,
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002891 GFP_KERNEL);
Andy Grover6708bb22011-06-08 10:36:43 -07002892 if (!lu_gp_cg->default_groups) {
2893 pr_err("Unable to allocate lu_gp_cg->default_groups\n");
Peter Senna Tschudin37bb7892012-09-17 20:05:33 +02002894 ret = -ENOMEM;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002895 goto out_global;
2896 }
2897
2898 config_group_init_type_name(&lu_gp->lu_gp_group, "default_lu_gp",
2899 &target_core_alua_lu_gp_cit);
2900 lu_gp_cg->default_groups[0] = &lu_gp->lu_gp_group;
2901 lu_gp_cg->default_groups[1] = NULL;
Andy Grovere3d6f902011-07-19 08:55:10 +00002902 default_lu_gp = lu_gp;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002903 /*
2904 * Register the target_core_mod subsystem with configfs.
2905 */
2906 ret = configfs_register_subsystem(subsys);
2907 if (ret < 0) {
Andy Grover6708bb22011-06-08 10:36:43 -07002908 pr_err("Error %d while registering subsystem %s\n",
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002909 ret, subsys->su_group.cg_item.ci_namebuf);
2910 goto out_global;
2911 }
Andy Grover6708bb22011-06-08 10:36:43 -07002912 pr_debug("TARGET_CORE[0]: Initialized ConfigFS Fabric"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002913 " Infrastructure: "TARGET_CORE_CONFIGFS_VERSION" on %s/%s"
2914 " on "UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
2915 /*
2916 * Register built-in RAMDISK subsystem logic for virtual LUN 0
2917 */
2918 ret = rd_module_init();
2919 if (ret < 0)
2920 goto out;
2921
Roland Dreier0d0f9df2012-10-31 09:16:44 -07002922 ret = core_dev_setup_virtual_lun0();
2923 if (ret < 0)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002924 goto out;
2925
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002926 return 0;
2927
2928out:
2929 configfs_unregister_subsystem(subsys);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002930 core_dev_release_virtual_lun0();
2931 rd_module_exit();
2932out_global:
Andy Grovere3d6f902011-07-19 08:55:10 +00002933 if (default_lu_gp) {
2934 core_alua_free_lu_gp(default_lu_gp);
2935 default_lu_gp = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002936 }
2937 if (lu_gp_cg)
2938 kfree(lu_gp_cg->default_groups);
2939 if (alua_cg)
2940 kfree(alua_cg->default_groups);
2941 if (hba_cg)
2942 kfree(hba_cg->default_groups);
2943 kfree(target_cg->default_groups);
Andy Grovere3d6f902011-07-19 08:55:10 +00002944 release_se_kmem_caches();
2945 return ret;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002946}
2947
Axel Lin54550fa2011-03-14 04:06:09 -07002948static void __exit target_core_exit_configfs(void)
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002949{
2950 struct configfs_subsystem *subsys;
2951 struct config_group *hba_cg, *alua_cg, *lu_gp_cg;
2952 struct config_item *item;
2953 int i;
2954
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002955 subsys = target_core_subsystem[0];
2956
Andy Grovere3d6f902011-07-19 08:55:10 +00002957 lu_gp_cg = &alua_lu_gps_group;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002958 for (i = 0; lu_gp_cg->default_groups[i]; i++) {
2959 item = &lu_gp_cg->default_groups[i]->cg_item;
2960 lu_gp_cg->default_groups[i] = NULL;
2961 config_item_put(item);
2962 }
2963 kfree(lu_gp_cg->default_groups);
Nicholas Bellinger7c2bf6e2011-02-09 15:34:53 -08002964 lu_gp_cg->default_groups = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002965
Andy Grovere3d6f902011-07-19 08:55:10 +00002966 alua_cg = &alua_group;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002967 for (i = 0; alua_cg->default_groups[i]; i++) {
2968 item = &alua_cg->default_groups[i]->cg_item;
2969 alua_cg->default_groups[i] = NULL;
2970 config_item_put(item);
2971 }
2972 kfree(alua_cg->default_groups);
Nicholas Bellinger7c2bf6e2011-02-09 15:34:53 -08002973 alua_cg->default_groups = NULL;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002974
Andy Grovere3d6f902011-07-19 08:55:10 +00002975 hba_cg = &target_core_hbagroup;
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002976 for (i = 0; hba_cg->default_groups[i]; i++) {
2977 item = &hba_cg->default_groups[i]->cg_item;
2978 hba_cg->default_groups[i] = NULL;
2979 config_item_put(item);
2980 }
2981 kfree(hba_cg->default_groups);
Nicholas Bellinger7c2bf6e2011-02-09 15:34:53 -08002982 hba_cg->default_groups = NULL;
2983 /*
2984 * We expect subsys->su_group.default_groups to be released
2985 * by configfs subsystem provider logic..
2986 */
2987 configfs_unregister_subsystem(subsys);
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002988 kfree(subsys->su_group.default_groups);
2989
Andy Grovere3d6f902011-07-19 08:55:10 +00002990 core_alua_free_lu_gp(default_lu_gp);
2991 default_lu_gp = NULL;
Nicholas Bellinger7c2bf6e2011-02-09 15:34:53 -08002992
Andy Grover6708bb22011-06-08 10:36:43 -07002993 pr_debug("TARGET_CORE[0]: Released ConfigFS Fabric"
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002994 " Infrastructure\n");
2995
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002996 core_dev_release_virtual_lun0();
2997 rd_module_exit();
Andy Grovere3d6f902011-07-19 08:55:10 +00002998 release_se_kmem_caches();
Nicholas Bellingerc66ac9d2010-12-17 11:11:26 -08002999}
3000
3001MODULE_DESCRIPTION("Target_Core_Mod/ConfigFS");
3002MODULE_AUTHOR("nab@Linux-iSCSI.org");
3003MODULE_LICENSE("GPL");
3004
3005module_init(target_core_init_configfs);
3006module_exit(target_core_exit_configfs);