aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2015-11-13 23:04:17 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-11-13 23:04:17 -0500
commit9aa3d651a9199103eb6451aeb0ac1b66a6d770a6 (patch)
tree42cc631c54e1fcbdeedee8e955c4797634a91af7
parent5d2eb548b309be34ecf3b91f0b7300a2b9d09b8c (diff)
parent517982229f78b2aebf00a8a337e84e8eeea70b8e (diff)
Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending
Pull SCSI target updates from Nicholas Bellinger: "This series contains HCH's changes to absorb configfs attribute ->show() + ->store() function pointer usage from it's original tree-wide consumers, into common configfs code. It includes usb-gadget, target w/ drivers, netconsole and ocfs2 changes to realize the improved simplicity, that now renders the original include/target/configfs_macros.h CPP magic for fabric drivers and others, unnecessary and obsolete. And with common code in place, new configfs attributes can be added easier than ever before. Note, there are further improvements in-flight from other folks for v4.5 code in configfs land, plus number of target fixes for post -rc1 code" In the meantime, a new user of the now-removed old configfs API came in through the char/misc tree in commit 7bd1d4093c2f ("stm class: Introduce an abstraction for System Trace Module devices"). This merge resolution comes from Alexander Shishkin, who updated his stm class tracing abstraction to account for the removal of the old show_attribute and store_attribute methods in commit 517982229f78 ("configfs: remove old API") from this pull. As Alexander says about that patch: "There's no need to keep an extra wrapper structure per item and the awkward show_attribute/store_attribute item ops are no longer needed. This patch converts policy code to the new api, all the while making the code quite a bit smaller and easier on the eyes. Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>" That patch was folded into the merge so that the tree should be fully bisectable. * 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending: (23 commits) configfs: remove old API ocfs2/cluster: use per-attribute show and store methods ocfs2/cluster: move locking into attribute store methods netconsole: use per-attribute show and store methods target: use per-attribute show and store methods spear13xx_pcie_gadget: use per-attribute show and store methods dlm: use per-attribute show and store methods usb-gadget/f_serial: use per-attribute show and store methods usb-gadget/f_phonet: use per-attribute show and store methods usb-gadget/f_obex: use per-attribute show and store methods usb-gadget/f_uac2: use per-attribute show and store methods usb-gadget/f_uac1: use per-attribute show and store methods usb-gadget/f_mass_storage: use per-attribute show and store methods usb-gadget/f_sourcesink: use per-attribute show and store methods usb-gadget/f_printer: use per-attribute show and store methods usb-gadget/f_midi: use per-attribute show and store methods usb-gadget/f_loopback: use per-attribute show and store methods usb-gadget/ether: use per-attribute show and store methods usb-gadget/f_acm: use per-attribute show and store methods usb-gadget/f_hid: use per-attribute show and store methods ...
-rw-r--r--Documentation/filesystems/Makefile2
-rw-r--r--Documentation/filesystems/configfs/Makefile3
-rw-r--r--Documentation/filesystems/configfs/configfs.txt38
-rw-r--r--Documentation/filesystems/configfs/configfs_example_explicit.c483
-rwxr-xr-xDocumentation/target/tcm_mod_builder.py17
-rw-r--r--drivers/hwtracing/stm/policy.c105
-rw-r--r--drivers/infiniband/ulp/srpt/ib_srpt.c78
-rw-r--r--drivers/misc/spear13xx_pcie_gadget.c216
-rw-r--r--drivers/net/netconsole.c271
-rw-r--r--drivers/scsi/qla2xxx/tcm_qla2xxx.c153
-rw-r--r--drivers/target/iscsi/iscsi_target_configfs.c791
-rw-r--r--drivers/target/iscsi/iscsi_target_stat.c666
-rw-r--r--drivers/target/loopback/tcm_loop.c60
-rw-r--r--drivers/target/sbp/sbp_target.c87
-rw-r--r--drivers/target/target_core_configfs.c1209
-rw-r--r--drivers/target/target_core_fabric_configfs.c275
-rw-r--r--drivers/target/target_core_internal.h3
-rw-r--r--drivers/target/target_core_stat.c918
-rw-r--r--drivers/target/tcm_fc/tfc_cmd.c1
-rw-r--r--drivers/target/tcm_fc/tfc_conf.c44
-rw-r--r--drivers/target/tcm_fc/tfc_io.c1
-rw-r--r--drivers/target/tcm_fc/tfc_sess.c1
-rw-r--r--drivers/usb/gadget/configfs.c295
-rw-r--r--drivers/usb/gadget/function/f_acm.c26
-rw-r--r--drivers/usb/gadget/function/f_ecm.c8
-rw-r--r--drivers/usb/gadget/function/f_eem.c8
-rw-r--r--drivers/usb/gadget/function/f_hid.c34
-rw-r--r--drivers/usb/gadget/function/f_loopback.c31
-rw-r--r--drivers/usb/gadget/function/f_mass_storage.c119
-rw-r--r--drivers/usb/gadget/function/f_midi.c37
-rw-r--r--drivers/usb/gadget/function/f_ncm.c8
-rw-r--r--drivers/usb/gadget/function/f_obex.c26
-rw-r--r--drivers/usb/gadget/function/f_phonet.c25
-rw-r--r--drivers/usb/gadget/function/f_printer.c30
-rw-r--r--drivers/usb/gadget/function/f_rndis.c8
-rw-r--r--drivers/usb/gadget/function/f_serial.c26
-rw-r--r--drivers/usb/gadget/function/f_sourcesink.c83
-rw-r--r--drivers/usb/gadget/function/f_subset.c8
-rw-r--r--drivers/usb/gadget/function/f_uac1.c39
-rw-r--r--drivers/usb/gadget/function/f_uac2.c28
-rw-r--r--drivers/usb/gadget/function/u_ether_configfs.h44
-rw-r--r--drivers/usb/gadget/function/uvc_configfs.c387
-rw-r--r--drivers/usb/gadget/legacy/tcm_usb_gadget.c44
-rw-r--r--drivers/vhost/scsi.c41
-rw-r--r--drivers/xen/xen-scsiback.c32
-rw-r--r--fs/configfs/file.c12
-rw-r--r--fs/dlm/config.c288
-rw-r--r--fs/ocfs2/cluster/heartbeat.c205
-rw-r--r--fs/ocfs2/cluster/nodemanager.c281
-rw-r--r--include/linux/configfs.h97
-rw-r--r--include/linux/usb/gadget_configfs.h19
-rw-r--r--include/target/configfs_macros.h147
-rw-r--r--include/target/target_core_base.h60
-rw-r--r--include/target/target_core_fabric_configfs.h122
-rw-r--r--samples/Kconfig6
-rw-r--r--samples/Makefile3
-rw-r--r--samples/configfs/Makefile2
-rw-r--r--samples/configfs/configfs_sample.c (renamed from Documentation/filesystems/configfs/configfs_example_macros.c)140
58 files changed, 2676 insertions, 5515 deletions
diff --git a/Documentation/filesystems/Makefile b/Documentation/filesystems/Makefile
index 13483d192ebb..883010ce5e35 100644
--- a/Documentation/filesystems/Makefile
+++ b/Documentation/filesystems/Makefile
@@ -1,5 +1,3 @@
1subdir-y := configfs
2
3# List of programs to build 1# List of programs to build
4hostprogs-y := dnotify_test 2hostprogs-y := dnotify_test
5 3
diff --git a/Documentation/filesystems/configfs/Makefile b/Documentation/filesystems/configfs/Makefile
deleted file mode 100644
index be7ec5e67dbc..000000000000
--- a/Documentation/filesystems/configfs/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1ifneq ($(CONFIG_CONFIGFS_FS),)
2obj-m += configfs_example_explicit.o configfs_example_macros.o
3endif
diff --git a/Documentation/filesystems/configfs/configfs.txt b/Documentation/filesystems/configfs/configfs.txt
index b40fec9d3f53..af68efdbbfad 100644
--- a/Documentation/filesystems/configfs/configfs.txt
+++ b/Documentation/filesystems/configfs/configfs.txt
@@ -160,12 +160,6 @@ among other things. For that, it needs a type.
160 160
161 struct configfs_item_operations { 161 struct configfs_item_operations {
162 void (*release)(struct config_item *); 162 void (*release)(struct config_item *);
163 ssize_t (*show_attribute)(struct config_item *,
164 struct configfs_attribute *,
165 char *);
166 ssize_t (*store_attribute)(struct config_item *,
167 struct configfs_attribute *,
168 const char *, size_t);
169 int (*allow_link)(struct config_item *src, 163 int (*allow_link)(struct config_item *src,
170 struct config_item *target); 164 struct config_item *target);
171 int (*drop_link)(struct config_item *src, 165 int (*drop_link)(struct config_item *src,
@@ -183,9 +177,7 @@ The most basic function of a config_item_type is to define what
183operations can be performed on a config_item. All items that have been 177operations can be performed on a config_item. All items that have been
184allocated dynamically will need to provide the ct_item_ops->release() 178allocated dynamically will need to provide the ct_item_ops->release()
185method. This method is called when the config_item's reference count 179method. This method is called when the config_item's reference count
186reaches zero. Items that wish to display an attribute need to provide 180reaches zero.
187the ct_item_ops->show_attribute() method. Similarly, storing a new
188attribute value uses the store_attribute() method.
189 181
190[struct configfs_attribute] 182[struct configfs_attribute]
191 183
@@ -193,6 +185,8 @@ attribute value uses the store_attribute() method.
193 char *ca_name; 185 char *ca_name;
194 struct module *ca_owner; 186 struct module *ca_owner;
195 umode_t ca_mode; 187 umode_t ca_mode;
188 ssize_t (*show)(struct config_item *, char *);
189 ssize_t (*store)(struct config_item *, const char *, size_t);
196 }; 190 };
197 191
198When a config_item wants an attribute to appear as a file in the item's 192When a config_item wants an attribute to appear as a file in the item's
@@ -202,10 +196,10 @@ config_item_type->ct_attrs. When the item appears in configfs, the
202attribute file will appear with the configfs_attribute->ca_name 196attribute file will appear with the configfs_attribute->ca_name
203filename. configfs_attribute->ca_mode specifies the file permissions. 197filename. configfs_attribute->ca_mode specifies the file permissions.
204 198
205If an attribute is readable and the config_item provides a 199If an attribute is readable and provides a ->show method, that method will
206ct_item_ops->show_attribute() method, that method will be called 200be called whenever userspace asks for a read(2) on the attribute. If an
207whenever userspace asks for a read(2) on the attribute. The converse 201attribute is writable and provides a ->store method, that method will be
208will happen for write(2). 202be called whenever userspace asks for a write(2) on the attribute.
209 203
210[struct config_group] 204[struct config_group]
211 205
@@ -311,20 +305,10 @@ the subsystem must be ready for it.
311[An Example] 305[An Example]
312 306
313The best example of these basic concepts is the simple_children 307The best example of these basic concepts is the simple_children
314subsystem/group and the simple_child item in configfs_example_explicit.c 308subsystem/group and the simple_child item in
315and configfs_example_macros.c. It shows a trivial object displaying and 309samples/configfs/configfs_sample.c. It shows a trivial object displaying
316storing an attribute, and a simple group creating and destroying these 310and storing an attribute, and a simple group creating and destroying
317children. 311these children.
318
319The only difference between configfs_example_explicit.c and
320configfs_example_macros.c is how the attributes of the childless item
321are defined. The childless item has extended attributes, each with
322their own show()/store() operation. This follows a convention commonly
323used in sysfs. configfs_example_explicit.c creates these attributes
324by explicitly defining the structures involved. Conversely
325configfs_example_macros.c uses some convenience macros from configfs.h
326to define the attributes. These macros are similar to their sysfs
327counterparts.
328 312
329[Hierarchy Navigation and the Subsystem Mutex] 313[Hierarchy Navigation and the Subsystem Mutex]
330 314
diff --git a/Documentation/filesystems/configfs/configfs_example_explicit.c b/Documentation/filesystems/configfs/configfs_example_explicit.c
deleted file mode 100644
index 1420233dfa55..000000000000
--- a/Documentation/filesystems/configfs/configfs_example_explicit.c
+++ /dev/null
@@ -1,483 +0,0 @@
1/*
2 * vim: noexpandtab ts=8 sts=0 sw=8:
3 *
4 * configfs_example_explicit.c - This file is a demonstration module
5 * containing a number of configfs subsystems. It explicitly defines
6 * each structure without using the helper macros defined in
7 * configfs.h.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public
20 * License along with this program; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 021110-1307, USA.
23 *
24 * Based on sysfs:
25 * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
26 *
27 * configfs Copyright (C) 2005 Oracle. All rights reserved.
28 */
29
30#include <linux/init.h>
31#include <linux/module.h>
32#include <linux/slab.h>
33
34#include <linux/configfs.h>
35
36
37
38/*
39 * 01-childless
40 *
41 * This first example is a childless subsystem. It cannot create
42 * any config_items. It just has attributes.
43 *
44 * Note that we are enclosing the configfs_subsystem inside a container.
45 * This is not necessary if a subsystem has no attributes directly
46 * on the subsystem. See the next example, 02-simple-children, for
47 * such a subsystem.
48 */
49
50struct childless {
51 struct configfs_subsystem subsys;
52 int showme;
53 int storeme;
54};
55
56struct childless_attribute {
57 struct configfs_attribute attr;
58 ssize_t (*show)(struct childless *, char *);
59 ssize_t (*store)(struct childless *, const char *, size_t);
60};
61
62static inline struct childless *to_childless(struct config_item *item)
63{
64 return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct childless, subsys) : NULL;
65}
66
67static ssize_t childless_showme_read(struct childless *childless,
68 char *page)
69{
70 ssize_t pos;
71
72 pos = sprintf(page, "%d\n", childless->showme);
73 childless->showme++;
74
75 return pos;
76}
77
78static ssize_t childless_storeme_read(struct childless *childless,
79 char *page)
80{
81 return sprintf(page, "%d\n", childless->storeme);
82}
83
84static ssize_t childless_storeme_write(struct childless *childless,
85 const char *page,
86 size_t count)
87{
88 unsigned long tmp;
89 char *p = (char *) page;
90
91 tmp = simple_strtoul(p, &p, 10);
92 if ((*p != '\0') && (*p != '\n'))
93 return -EINVAL;
94
95 if (tmp > INT_MAX)
96 return -ERANGE;
97
98 childless->storeme = tmp;
99
100 return count;
101}
102
103static ssize_t childless_description_read(struct childless *childless,
104 char *page)
105{
106 return sprintf(page,
107"[01-childless]\n"
108"\n"
109"The childless subsystem is the simplest possible subsystem in\n"
110"configfs. It does not support the creation of child config_items.\n"
111"It only has a few attributes. In fact, it isn't much different\n"
112"than a directory in /proc.\n");
113}
114
115static struct childless_attribute childless_attr_showme = {
116 .attr = { .ca_owner = THIS_MODULE, .ca_name = "showme", .ca_mode = S_IRUGO },
117 .show = childless_showme_read,
118};
119static struct childless_attribute childless_attr_storeme = {
120 .attr = { .ca_owner = THIS_MODULE, .ca_name = "storeme", .ca_mode = S_IRUGO | S_IWUSR },
121 .show = childless_storeme_read,
122 .store = childless_storeme_write,
123};
124static struct childless_attribute childless_attr_description = {
125 .attr = { .ca_owner = THIS_MODULE, .ca_name = "description", .ca_mode = S_IRUGO },
126 .show = childless_description_read,
127};
128
129static struct configfs_attribute *childless_attrs[] = {
130 &childless_attr_showme.attr,
131 &childless_attr_storeme.attr,
132 &childless_attr_description.attr,
133 NULL,
134};
135
136static ssize_t childless_attr_show(struct config_item *item,
137 struct configfs_attribute *attr,
138 char *page)
139{
140 struct childless *childless = to_childless(item);
141 struct childless_attribute *childless_attr =
142 container_of(attr, struct childless_attribute, attr);
143 ssize_t ret = 0;
144
145 if (childless_attr->show)
146 ret = childless_attr->show(childless, page);
147 return ret;
148}
149
150static ssize_t childless_attr_store(struct config_item *item,
151 struct configfs_attribute *attr,
152 const char *page, size_t count)
153{
154 struct childless *childless = to_childless(item);
155 struct childless_attribute *childless_attr =
156 container_of(attr, struct childless_attribute, attr);
157 ssize_t ret = -EINVAL;
158
159 if (childless_attr->store)
160 ret = childless_attr->store(childless, page, count);
161 return ret;
162}
163
164static struct configfs_item_operations childless_item_ops = {
165 .show_attribute = childless_attr_show,
166 .store_attribute = childless_attr_store,
167};
168
169static struct config_item_type childless_type = {
170 .ct_item_ops = &childless_item_ops,
171 .ct_attrs = childless_attrs,
172 .ct_owner = THIS_MODULE,
173};
174
175static struct childless childless_subsys = {
176 .subsys = {
177 .su_group = {
178 .cg_item = {
179 .ci_namebuf = "01-childless",
180 .ci_type = &childless_type,
181 },
182 },
183 },
184};
185
186
187/* ----------------------------------------------------------------- */
188
189/*
190 * 02-simple-children
191 *
192 * This example merely has a simple one-attribute child. Note that
193 * there is no extra attribute structure, as the child's attribute is
194 * known from the get-go. Also, there is no container for the
195 * subsystem, as it has no attributes of its own.
196 */
197
198struct simple_child {
199 struct config_item item;
200 int storeme;
201};
202
203static inline struct simple_child *to_simple_child(struct config_item *item)
204{
205 return item ? container_of(item, struct simple_child, item) : NULL;
206}
207
208static struct configfs_attribute simple_child_attr_storeme = {
209 .ca_owner = THIS_MODULE,
210 .ca_name = "storeme",
211 .ca_mode = S_IRUGO | S_IWUSR,
212};
213
214static struct configfs_attribute *simple_child_attrs[] = {
215 &simple_child_attr_storeme,
216 NULL,
217};
218
219static ssize_t simple_child_attr_show(struct config_item *item,
220 struct configfs_attribute *attr,
221 char *page)
222{
223 ssize_t count;
224 struct simple_child *simple_child = to_simple_child(item);
225
226 count = sprintf(page, "%d\n", simple_child->storeme);
227
228 return count;
229}
230
231static ssize_t simple_child_attr_store(struct config_item *item,
232 struct configfs_attribute *attr,
233 const char *page, size_t count)
234{
235 struct simple_child *simple_child = to_simple_child(item);
236 unsigned long tmp;
237 char *p = (char *) page;
238
239 tmp = simple_strtoul(p, &p, 10);
240 if (!p || (*p && (*p != '\n')))
241 return -EINVAL;
242
243 if (tmp > INT_MAX)
244 return -ERANGE;
245
246 simple_child->storeme = tmp;
247
248 return count;
249}
250
251static void simple_child_release(struct config_item *item)
252{
253 kfree(to_simple_child(item));
254}
255
256static struct configfs_item_operations simple_child_item_ops = {
257 .release = simple_child_release,
258 .show_attribute = simple_child_attr_show,
259 .store_attribute = simple_child_attr_store,
260};
261
262static struct config_item_type simple_child_type = {
263 .ct_item_ops = &simple_child_item_ops,
264 .ct_attrs = simple_child_attrs,
265 .ct_owner = THIS_MODULE,
266};
267
268
269struct simple_children {
270 struct config_group group;
271};
272
273static inline struct simple_children *to_simple_children(struct config_item *item)
274{
275 return item ? container_of(to_config_group(item), struct simple_children, group) : NULL;
276}
277
278static struct config_item *simple_children_make_item(struct config_group *group, const char *name)
279{
280 struct simple_child *simple_child;
281
282 simple_child = kzalloc(sizeof(struct simple_child), GFP_KERNEL);
283 if (!simple_child)
284 return ERR_PTR(-ENOMEM);
285
286 config_item_init_type_name(&simple_child->item, name,
287 &simple_child_type);
288
289 simple_child->storeme = 0;
290
291 return &simple_child->item;
292}
293
294static struct configfs_attribute simple_children_attr_description = {
295 .ca_owner = THIS_MODULE,
296 .ca_name = "description",
297 .ca_mode = S_IRUGO,
298};
299
300static struct configfs_attribute *simple_children_attrs[] = {
301 &simple_children_attr_description,
302 NULL,
303};
304
305static ssize_t simple_children_attr_show(struct config_item *item,
306 struct configfs_attribute *attr,
307 char *page)
308{
309 return sprintf(page,
310"[02-simple-children]\n"
311"\n"
312"This subsystem allows the creation of child config_items. These\n"
313"items have only one attribute that is readable and writeable.\n");
314}
315
316static void simple_children_release(struct config_item *item)
317{
318 kfree(to_simple_children(item));
319}
320
321static struct configfs_item_operations simple_children_item_ops = {
322 .release = simple_children_release,
323 .show_attribute = simple_children_attr_show,
324};
325
326/*
327 * Note that, since no extra work is required on ->drop_item(),
328 * no ->drop_item() is provided.
329 */
330static struct configfs_group_operations simple_children_group_ops = {
331 .make_item = simple_children_make_item,
332};
333
334static struct config_item_type simple_children_type = {
335 .ct_item_ops = &simple_children_item_ops,
336 .ct_group_ops = &simple_children_group_ops,
337 .ct_attrs = simple_children_attrs,
338 .ct_owner = THIS_MODULE,
339};
340
341static struct configfs_subsystem simple_children_subsys = {
342 .su_group = {
343 .cg_item = {
344 .ci_namebuf = "02-simple-children",
345 .ci_type = &simple_children_type,
346 },
347 },
348};
349
350
351/* ----------------------------------------------------------------- */
352
353/*
354 * 03-group-children
355 *
356 * This example reuses the simple_children group from above. However,
357 * the simple_children group is not the subsystem itself, it is a
358 * child of the subsystem. Creation of a group in the subsystem creates
359 * a new simple_children group. That group can then have simple_child
360 * children of its own.
361 */
362
363static struct config_group *group_children_make_group(struct config_group *group, const char *name)
364{
365 struct simple_children *simple_children;
366
367 simple_children = kzalloc(sizeof(struct simple_children),
368 GFP_KERNEL);
369 if (!simple_children)
370 return ERR_PTR(-ENOMEM);
371
372 config_group_init_type_name(&simple_children->group, name,
373 &simple_children_type);
374
375 return &simple_children->group;
376}
377
378static struct configfs_attribute group_children_attr_description = {
379 .ca_owner = THIS_MODULE,
380 .ca_name = "description",
381 .ca_mode = S_IRUGO,
382};
383
384static struct configfs_attribute *group_children_attrs[] = {
385 &group_children_attr_description,
386 NULL,
387};
388
389static ssize_t group_children_attr_show(struct config_item *item,
390 struct configfs_attribute *attr,
391 char *page)
392{
393 return sprintf(page,
394"[03-group-children]\n"
395"\n"
396"This subsystem allows the creation of child config_groups. These\n"
397"groups are like the subsystem simple-children.\n");
398}
399
400static struct configfs_item_operations group_children_item_ops = {
401 .show_attribute = group_children_attr_show,
402};
403
404/*
405 * Note that, since no extra work is required on ->drop_item(),
406 * no ->drop_item() is provided.
407 */
408static struct configfs_group_operations group_children_group_ops = {
409 .make_group = group_children_make_group,
410};
411
412static struct config_item_type group_children_type = {
413 .ct_item_ops = &group_children_item_ops,
414 .ct_group_ops = &group_children_group_ops,
415 .ct_attrs = group_children_attrs,
416 .ct_owner = THIS_MODULE,
417};
418
419static struct configfs_subsystem group_children_subsys = {
420 .su_group = {
421 .cg_item = {
422 .ci_namebuf = "03-group-children",
423 .ci_type = &group_children_type,
424 },
425 },
426};
427
428/* ----------------------------------------------------------------- */
429
430/*
431 * We're now done with our subsystem definitions.
432 * For convenience in this module, here's a list of them all. It
433 * allows the init function to easily register them. Most modules
434 * will only have one subsystem, and will only call register_subsystem
435 * on it directly.
436 */
437static struct configfs_subsystem *example_subsys[] = {
438 &childless_subsys.subsys,
439 &simple_children_subsys,
440 &group_children_subsys,
441 NULL,
442};
443
444static int __init configfs_example_init(void)
445{
446 int ret;
447 int i;
448 struct configfs_subsystem *subsys;
449
450 for (i = 0; example_subsys[i]; i++) {
451 subsys = example_subsys[i];
452
453 config_group_init(&subsys->su_group);
454 mutex_init(&subsys->su_mutex);
455 ret = configfs_register_subsystem(subsys);
456 if (ret) {
457 printk(KERN_ERR "Error %d while registering subsystem %s\n",
458 ret,
459 subsys->su_group.cg_item.ci_namebuf);
460 goto out_unregister;
461 }
462 }
463
464 return 0;
465
466out_unregister:
467 for (i--; i >= 0; i--)
468 configfs_unregister_subsystem(example_subsys[i]);
469
470 return ret;
471}
472
473static void __exit configfs_example_exit(void)
474{
475 int i;
476
477 for (i = 0; example_subsys[i]; i++)
478 configfs_unregister_subsystem(example_subsys[i]);
479}
480
481module_init(configfs_example_init);
482module_exit(configfs_example_exit);
483MODULE_LICENSE("GPL");
diff --git a/Documentation/target/tcm_mod_builder.py b/Documentation/target/tcm_mod_builder.py
index cda56df9b8a7..7d370c9b1450 100755
--- a/Documentation/target/tcm_mod_builder.py
+++ b/Documentation/target/tcm_mod_builder.py
@@ -203,8 +203,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
203 buf += "#include <scsi/scsi_proto.h>\n\n" 203 buf += "#include <scsi/scsi_proto.h>\n\n"
204 buf += "#include <target/target_core_base.h>\n" 204 buf += "#include <target/target_core_base.h>\n"
205 buf += "#include <target/target_core_fabric.h>\n" 205 buf += "#include <target/target_core_fabric.h>\n"
206 buf += "#include <target/target_core_fabric_configfs.h>\n"
207 buf += "#include <target/configfs_macros.h>\n\n"
208 buf += "#include \"" + fabric_mod_name + "_base.h\"\n" 206 buf += "#include \"" + fabric_mod_name + "_base.h\"\n"
209 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n" 207 buf += "#include \"" + fabric_mod_name + "_fabric.h\"\n\n"
210 208
@@ -283,19 +281,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
283 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n" 281 buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n"
284 buf += " kfree(" + fabric_mod_port + ");\n" 282 buf += " kfree(" + fabric_mod_port + ");\n"
285 buf += "}\n\n" 283 buf += "}\n\n"
286 buf += "static ssize_t " + fabric_mod_name + "_wwn_show_attr_version(\n"
287 buf += " struct target_fabric_configfs *tf,\n"
288 buf += " char *page)\n"
289 buf += "{\n"
290 buf += " return sprintf(page, \"" + fabric_mod_name.upper() + " fabric module %s on %s/%s\"\n"
291 buf += " \"on \"UTS_RELEASE\"\\n\", " + fabric_mod_name.upper() + "_VERSION, utsname()->sysname,\n"
292 buf += " utsname()->machine);\n"
293 buf += "}\n\n"
294 buf += "TF_WWN_ATTR_RO(" + fabric_mod_name + ", version);\n\n"
295 buf += "static struct configfs_attribute *" + fabric_mod_name + "_wwn_attrs[] = {\n"
296 buf += " &" + fabric_mod_name + "_wwn_version.attr,\n"
297 buf += " NULL,\n"
298 buf += "};\n\n"
299 284
300 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n" 285 buf += "static const struct target_core_fabric_ops " + fabric_mod_name + "_ops = {\n"
301 buf += " .module = THIS_MODULE,\n" 286 buf += " .module = THIS_MODULE,\n"
@@ -328,8 +313,6 @@ def tcm_mod_build_configfs(proto_ident, fabric_mod_dir_var, fabric_mod_name):
328 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" 313 buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n"
329 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" 314 buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n"
330 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" 315 buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n"
331 buf += "\n"
332 buf += " .tfc_wwn_attrs = " + fabric_mod_name + "_wwn_attrs,\n"
333 buf += "};\n\n" 316 buf += "};\n\n"
334 317
335 buf += "static int __init " + fabric_mod_name + "_init(void)\n" 318 buf += "static int __init " + fabric_mod_name + "_init(void)\n"
diff --git a/drivers/hwtracing/stm/policy.c b/drivers/hwtracing/stm/policy.c
index 6498a9dbb7bd..11ab6d01adf6 100644
--- a/drivers/hwtracing/stm/policy.c
+++ b/drivers/hwtracing/stm/policy.c
@@ -76,9 +76,10 @@ to_stp_policy_node(struct config_item *item)
76 NULL; 76 NULL;
77} 77}
78 78
79static ssize_t stp_policy_node_masters_show(struct stp_policy_node *policy_node, 79static ssize_t
80 char *page) 80stp_policy_node_masters_show(struct config_item *item, char *page)
81{ 81{
82 struct stp_policy_node *policy_node = to_stp_policy_node(item);
82 ssize_t count; 83 ssize_t count;
83 84
84 count = sprintf(page, "%u %u\n", policy_node->first_master, 85 count = sprintf(page, "%u %u\n", policy_node->first_master,
@@ -88,9 +89,10 @@ static ssize_t stp_policy_node_masters_show(struct stp_policy_node *policy_node,
88} 89}
89 90
90static ssize_t 91static ssize_t
91stp_policy_node_masters_store(struct stp_policy_node *policy_node, 92stp_policy_node_masters_store(struct config_item *item, const char *page,
92 const char *page, size_t count) 93 size_t count)
93{ 94{
95 struct stp_policy_node *policy_node = to_stp_policy_node(item);
94 unsigned int first, last; 96 unsigned int first, last;
95 struct stm_device *stm; 97 struct stm_device *stm;
96 char *p = (char *)page; 98 char *p = (char *)page;
@@ -123,8 +125,9 @@ unlock:
123} 125}
124 126
125static ssize_t 127static ssize_t
126stp_policy_node_channels_show(struct stp_policy_node *policy_node, char *page) 128stp_policy_node_channels_show(struct config_item *item, char *page)
127{ 129{
130 struct stp_policy_node *policy_node = to_stp_policy_node(item);
128 ssize_t count; 131 ssize_t count;
129 132
130 count = sprintf(page, "%u %u\n", policy_node->first_channel, 133 count = sprintf(page, "%u %u\n", policy_node->first_channel,
@@ -134,9 +137,10 @@ stp_policy_node_channels_show(struct stp_policy_node *policy_node, char *page)
134} 137}
135 138
136static ssize_t 139static ssize_t
137stp_policy_node_channels_store(struct stp_policy_node *policy_node, 140stp_policy_node_channels_store(struct config_item *item, const char *page,
138 const char *page, size_t count) 141 size_t count)
139{ 142{
143 struct stp_policy_node *policy_node = to_stp_policy_node(item);
140 unsigned int first, last; 144 unsigned int first, last;
141 struct stm_device *stm; 145 struct stm_device *stm;
142 char *p = (char *)page; 146 char *p = (char *)page;
@@ -171,71 +175,16 @@ static void stp_policy_node_release(struct config_item *item)
171 kfree(to_stp_policy_node(item)); 175 kfree(to_stp_policy_node(item));
172} 176}
173 177
174struct stp_policy_node_attribute {
175 struct configfs_attribute attr;
176 ssize_t (*show)(struct stp_policy_node *, char *);
177 ssize_t (*store)(struct stp_policy_node *, const char *, size_t);
178};
179
180static ssize_t stp_policy_node_attr_show(struct config_item *item,
181 struct configfs_attribute *attr,
182 char *page)
183{
184 struct stp_policy_node *policy_node = to_stp_policy_node(item);
185 struct stp_policy_node_attribute *pn_attr =
186 container_of(attr, struct stp_policy_node_attribute, attr);
187 ssize_t count = 0;
188
189 if (pn_attr->show)
190 count = pn_attr->show(policy_node, page);
191
192 return count;
193}
194
195static ssize_t stp_policy_node_attr_store(struct config_item *item,
196 struct configfs_attribute *attr,
197 const char *page, size_t len)
198{
199 struct stp_policy_node *policy_node = to_stp_policy_node(item);
200 struct stp_policy_node_attribute *pn_attr =
201 container_of(attr, struct stp_policy_node_attribute, attr);
202 ssize_t count = -EINVAL;
203
204 if (pn_attr->store)
205 count = pn_attr->store(policy_node, page, len);
206
207 return count;
208}
209
210static struct configfs_item_operations stp_policy_node_item_ops = { 178static struct configfs_item_operations stp_policy_node_item_ops = {
211 .release = stp_policy_node_release, 179 .release = stp_policy_node_release,
212 .show_attribute = stp_policy_node_attr_show,
213 .store_attribute = stp_policy_node_attr_store,
214}; 180};
215 181
216static struct stp_policy_node_attribute stp_policy_node_attr_range = { 182CONFIGFS_ATTR(stp_policy_node_, masters);
217 .attr = { 183CONFIGFS_ATTR(stp_policy_node_, channels);
218 .ca_owner = THIS_MODULE,
219 .ca_name = "masters",
220 .ca_mode = S_IRUGO | S_IWUSR,
221 },
222 .show = stp_policy_node_masters_show,
223 .store = stp_policy_node_masters_store,
224};
225
226static struct stp_policy_node_attribute stp_policy_node_attr_channels = {
227 .attr = {
228 .ca_owner = THIS_MODULE,
229 .ca_name = "channels",
230 .ca_mode = S_IRUGO | S_IWUSR,
231 },
232 .show = stp_policy_node_channels_show,
233 .store = stp_policy_node_channels_store,
234};
235 184
236static struct configfs_attribute *stp_policy_node_attrs[] = { 185static struct configfs_attribute *stp_policy_node_attrs[] = {
237 &stp_policy_node_attr_range.attr, 186 &stp_policy_node_attr_masters,
238 &stp_policy_node_attr_channels.attr, 187 &stp_policy_node_attr_channels,
239 NULL, 188 NULL,
240}; 189};
241 190
@@ -298,20 +247,8 @@ static struct config_item_type stp_policy_node_type = {
298/* 247/*
299 * Root group: policies. 248 * Root group: policies.
300 */ 249 */
301static struct configfs_attribute stp_policy_attr_device = { 250static ssize_t stp_policy_device_show(struct config_item *item,
302 .ca_owner = THIS_MODULE, 251 char *page)
303 .ca_name = "device",
304 .ca_mode = S_IRUGO,
305};
306
307static struct configfs_attribute *stp_policy_attrs[] = {
308 &stp_policy_attr_device,
309 NULL,
310};
311
312static ssize_t stp_policy_attr_show(struct config_item *item,
313 struct configfs_attribute *attr,
314 char *page)
315{ 252{
316 struct stp_policy *policy = to_stp_policy(item); 253 struct stp_policy *policy = to_stp_policy(item);
317 ssize_t count; 254 ssize_t count;
@@ -324,6 +261,13 @@ static ssize_t stp_policy_attr_show(struct config_item *item,
324 return count; 261 return count;
325} 262}
326 263
264CONFIGFS_ATTR_RO(stp_policy_, device);
265
266static struct configfs_attribute *stp_policy_attrs[] = {
267 &stp_policy_attr_device,
268 NULL,
269};
270
327void stp_policy_unbind(struct stp_policy *policy) 271void stp_policy_unbind(struct stp_policy *policy)
328{ 272{
329 struct stm_device *stm = policy->stm; 273 struct stm_device *stm = policy->stm;
@@ -350,7 +294,6 @@ static void stp_policy_release(struct config_item *item)
350 294
351static struct configfs_item_operations stp_policy_item_ops = { 295static struct configfs_item_operations stp_policy_item_ops = {
352 .release = stp_policy_release, 296 .release = stp_policy_release,
353 .show_attribute = stp_policy_attr_show,
354}; 297};
355 298
356static struct configfs_group_operations stp_policy_group_ops = { 299static struct configfs_group_operations stp_policy_group_ops = {
diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c
index 47c4022fda76..2e2fe818ca9f 100644
--- a/drivers/infiniband/ulp/srpt/ib_srpt.c
+++ b/drivers/infiniband/ulp/srpt/ib_srpt.c
@@ -43,9 +43,7 @@
43#include <linux/atomic.h> 43#include <linux/atomic.h>
44#include <scsi/scsi_proto.h> 44#include <scsi/scsi_proto.h>
45#include <scsi/scsi_tcq.h> 45#include <scsi/scsi_tcq.h>
46#include <target/configfs_macros.h>
47#include <target/target_core_base.h> 46#include <target/target_core_base.h>
48#include <target/target_core_fabric_configfs.h>
49#include <target/target_core_fabric.h> 47#include <target/target_core_fabric.h>
50#include "ib_srpt.h" 48#include "ib_srpt.h"
51 49
@@ -3546,20 +3544,19 @@ static void srpt_cleanup_nodeacl(struct se_node_acl *se_nacl)
3546 spin_unlock_irq(&sport->port_acl_lock); 3544 spin_unlock_irq(&sport->port_acl_lock);
3547} 3545}
3548 3546
3549static ssize_t srpt_tpg_attrib_show_srp_max_rdma_size( 3547static ssize_t srpt_tpg_attrib_srp_max_rdma_size_show(struct config_item *item,
3550 struct se_portal_group *se_tpg, 3548 char *page)
3551 char *page)
3552{ 3549{
3550 struct se_portal_group *se_tpg = attrib_to_tpg(item);
3553 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3551 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3554 3552
3555 return sprintf(page, "%u\n", sport->port_attrib.srp_max_rdma_size); 3553 return sprintf(page, "%u\n", sport->port_attrib.srp_max_rdma_size);
3556} 3554}
3557 3555
3558static ssize_t srpt_tpg_attrib_store_srp_max_rdma_size( 3556static ssize_t srpt_tpg_attrib_srp_max_rdma_size_store(struct config_item *item,
3559 struct se_portal_group *se_tpg, 3557 const char *page, size_t count)
3560 const char *page,
3561 size_t count)
3562{ 3558{
3559 struct se_portal_group *se_tpg = attrib_to_tpg(item);
3563 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3560 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3564 unsigned long val; 3561 unsigned long val;
3565 int ret; 3562 int ret;
@@ -3584,22 +3581,19 @@ static ssize_t srpt_tpg_attrib_store_srp_max_rdma_size(
3584 return count; 3581 return count;
3585} 3582}
3586 3583
3587TF_TPG_ATTRIB_ATTR(srpt, srp_max_rdma_size, S_IRUGO | S_IWUSR); 3584static ssize_t srpt_tpg_attrib_srp_max_rsp_size_show(struct config_item *item,
3588 3585 char *page)
3589static ssize_t srpt_tpg_attrib_show_srp_max_rsp_size(
3590 struct se_portal_group *se_tpg,
3591 char *page)
3592{ 3586{
3587 struct se_portal_group *se_tpg = attrib_to_tpg(item);
3593 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3588 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3594 3589
3595 return sprintf(page, "%u\n", sport->port_attrib.srp_max_rsp_size); 3590 return sprintf(page, "%u\n", sport->port_attrib.srp_max_rsp_size);
3596} 3591}
3597 3592
3598static ssize_t srpt_tpg_attrib_store_srp_max_rsp_size( 3593static ssize_t srpt_tpg_attrib_srp_max_rsp_size_store(struct config_item *item,
3599 struct se_portal_group *se_tpg, 3594 const char *page, size_t count)
3600 const char *page,
3601 size_t count)
3602{ 3595{
3596 struct se_portal_group *se_tpg = attrib_to_tpg(item);
3603 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3597 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3604 unsigned long val; 3598 unsigned long val;
3605 int ret; 3599 int ret;
@@ -3624,22 +3618,19 @@ static ssize_t srpt_tpg_attrib_store_srp_max_rsp_size(
3624 return count; 3618 return count;
3625} 3619}
3626 3620
3627TF_TPG_ATTRIB_ATTR(srpt, srp_max_rsp_size, S_IRUGO | S_IWUSR); 3621static ssize_t srpt_tpg_attrib_srp_sq_size_show(struct config_item *item,
3628 3622 char *page)
3629static ssize_t srpt_tpg_attrib_show_srp_sq_size(
3630 struct se_portal_group *se_tpg,
3631 char *page)
3632{ 3623{
3624 struct se_portal_group *se_tpg = attrib_to_tpg(item);
3633 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3625 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3634 3626
3635 return sprintf(page, "%u\n", sport->port_attrib.srp_sq_size); 3627 return sprintf(page, "%u\n", sport->port_attrib.srp_sq_size);
3636} 3628}
3637 3629
3638static ssize_t srpt_tpg_attrib_store_srp_sq_size( 3630static ssize_t srpt_tpg_attrib_srp_sq_size_store(struct config_item *item,
3639 struct se_portal_group *se_tpg, 3631 const char *page, size_t count)
3640 const char *page,
3641 size_t count)
3642{ 3632{
3633 struct se_portal_group *se_tpg = attrib_to_tpg(item);
3643 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3634 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3644 unsigned long val; 3635 unsigned long val;
3645 int ret; 3636 int ret;
@@ -3664,29 +3655,29 @@ static ssize_t srpt_tpg_attrib_store_srp_sq_size(
3664 return count; 3655 return count;
3665} 3656}
3666 3657
3667TF_TPG_ATTRIB_ATTR(srpt, srp_sq_size, S_IRUGO | S_IWUSR); 3658CONFIGFS_ATTR(srpt_tpg_attrib_, srp_max_rdma_size);
3659CONFIGFS_ATTR(srpt_tpg_attrib_, srp_max_rsp_size);
3660CONFIGFS_ATTR(srpt_tpg_attrib_, srp_sq_size);
3668 3661
3669static struct configfs_attribute *srpt_tpg_attrib_attrs[] = { 3662static struct configfs_attribute *srpt_tpg_attrib_attrs[] = {
3670 &srpt_tpg_attrib_srp_max_rdma_size.attr, 3663 &srpt_tpg_attrib_attr_srp_max_rdma_size,
3671 &srpt_tpg_attrib_srp_max_rsp_size.attr, 3664 &srpt_tpg_attrib_attr_srp_max_rsp_size,
3672 &srpt_tpg_attrib_srp_sq_size.attr, 3665 &srpt_tpg_attrib_attr_srp_sq_size,
3673 NULL, 3666 NULL,
3674}; 3667};
3675 3668
3676static ssize_t srpt_tpg_show_enable( 3669static ssize_t srpt_tpg_enable_show(struct config_item *item, char *page)
3677 struct se_portal_group *se_tpg,
3678 char *page)
3679{ 3670{
3671 struct se_portal_group *se_tpg = to_tpg(item);
3680 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3672 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3681 3673
3682 return snprintf(page, PAGE_SIZE, "%d\n", (sport->enabled) ? 1: 0); 3674 return snprintf(page, PAGE_SIZE, "%d\n", (sport->enabled) ? 1: 0);
3683} 3675}
3684 3676
3685static ssize_t srpt_tpg_store_enable( 3677static ssize_t srpt_tpg_enable_store(struct config_item *item,
3686 struct se_portal_group *se_tpg, 3678 const char *page, size_t count)
3687 const char *page,
3688 size_t count)
3689{ 3679{
3680 struct se_portal_group *se_tpg = to_tpg(item);
3690 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1); 3681 struct srpt_port *sport = container_of(se_tpg, struct srpt_port, port_tpg_1);
3691 unsigned long tmp; 3682 unsigned long tmp;
3692 int ret; 3683 int ret;
@@ -3709,10 +3700,10 @@ static ssize_t srpt_tpg_store_enable(
3709 return count; 3700 return count;
3710} 3701}
3711 3702
3712TF_TPG_BASE_ATTR(srpt, enable, S_IRUGO | S_IWUSR); 3703CONFIGFS_ATTR(srpt_tpg_, enable);
3713 3704
3714static struct configfs_attribute *srpt_tpg_attrs[] = { 3705static struct configfs_attribute *srpt_tpg_attrs[] = {
3715 &srpt_tpg_enable.attr, 3706 &srpt_tpg_attr_enable,
3716 NULL, 3707 NULL,
3717}; 3708};
3718 3709
@@ -3782,16 +3773,15 @@ static void srpt_drop_tport(struct se_wwn *wwn)
3782 pr_debug("drop_tport(%s\n", config_item_name(&sport->port_wwn.wwn_group.cg_item)); 3773 pr_debug("drop_tport(%s\n", config_item_name(&sport->port_wwn.wwn_group.cg_item));
3783} 3774}
3784 3775
3785static ssize_t srpt_wwn_show_attr_version(struct target_fabric_configfs *tf, 3776static ssize_t srpt_wwn_version_show(struct config_item *item, char *buf)
3786 char *buf)
3787{ 3777{
3788 return scnprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION); 3778 return scnprintf(buf, PAGE_SIZE, "%s\n", DRV_VERSION);
3789} 3779}
3790 3780
3791TF_WWN_ATTR_RO(srpt, version); 3781CONFIGFS_ATTR_RO(srpt_wwn_, version);
3792 3782
3793static struct configfs_attribute *srpt_wwn_attrs[] = { 3783static struct configfs_attribute *srpt_wwn_attrs[] = {
3794 &srpt_wwn_version.attr, 3784 &srpt_wwn_attr_version,
3795 NULL, 3785 NULL,
3796}; 3786};
3797 3787
diff --git a/drivers/misc/spear13xx_pcie_gadget.c b/drivers/misc/spear13xx_pcie_gadget.c
index b8374cdaf9c9..ee120dcbb3e6 100644
--- a/drivers/misc/spear13xx_pcie_gadget.c
+++ b/drivers/misc/spear13xx_pcie_gadget.c
@@ -220,11 +220,17 @@ static irqreturn_t spear_pcie_gadget_irq(int irq, void *dev_id)
220/* 220/*
221 * configfs interfaces show/store functions 221 * configfs interfaces show/store functions
222 */ 222 */
223static ssize_t pcie_gadget_show_link( 223
224 struct spear_pcie_gadget_config *config, 224static struct pcie_gadget_target *to_target(struct config_item *item)
225 char *buf)
226{ 225{
227 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 226 return item ?
227 container_of(to_configfs_subsystem(to_config_group(item)),
228 struct pcie_gadget_target, subsys) : NULL;
229}
230
231static ssize_t pcie_gadget_link_show(struct config_item *item, char *buf)
232{
233 struct pcie_app_reg __iomem *app_reg = to_target(item)->va_app_base;
228 234
229 if (readl(&app_reg->app_status_1) & ((u32)1 << XMLH_LINK_UP_ID)) 235 if (readl(&app_reg->app_status_1) & ((u32)1 << XMLH_LINK_UP_ID))
230 return sprintf(buf, "UP"); 236 return sprintf(buf, "UP");
@@ -232,11 +238,10 @@ static ssize_t pcie_gadget_show_link(
232 return sprintf(buf, "DOWN"); 238 return sprintf(buf, "DOWN");
233} 239}
234 240
235static ssize_t pcie_gadget_store_link( 241static ssize_t pcie_gadget_link_store(struct config_item *item,
236 struct spear_pcie_gadget_config *config,
237 const char *buf, size_t count) 242 const char *buf, size_t count)
238{ 243{
239 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 244 struct pcie_app_reg __iomem *app_reg = to_target(item)->va_app_base;
240 245
241 if (sysfs_streq(buf, "UP")) 246 if (sysfs_streq(buf, "UP"))
242 writel(readl(&app_reg->app_ctrl_0) | (1 << APP_LTSSM_ENABLE_ID), 247 writel(readl(&app_reg->app_ctrl_0) | (1 << APP_LTSSM_ENABLE_ID),
@@ -250,17 +255,15 @@ static ssize_t pcie_gadget_store_link(
250 return count; 255 return count;
251} 256}
252 257
253static ssize_t pcie_gadget_show_int_type( 258static ssize_t pcie_gadget_int_type_show(struct config_item *item, char *buf)
254 struct spear_pcie_gadget_config *config,
255 char *buf)
256{ 259{
257 return sprintf(buf, "%s", config->int_type); 260 return sprintf(buf, "%s", to_target(item)->int_type);
258} 261}
259 262
260static ssize_t pcie_gadget_store_int_type( 263static ssize_t pcie_gadget_int_type_store(struct config_item *item,
261 struct spear_pcie_gadget_config *config,
262 const char *buf, size_t count) 264 const char *buf, size_t count)
263{ 265{
266 struct spear_pcie_gadget_config *config = to_target(item)
264 u32 cap, vec, flags; 267 u32 cap, vec, flags;
265 ulong vector; 268 ulong vector;
266 269
@@ -288,11 +291,10 @@ static ssize_t pcie_gadget_store_int_type(
288 return count; 291 return count;
289} 292}
290 293
291static ssize_t pcie_gadget_show_no_of_msi( 294static ssize_t pcie_gadget_no_of_msi_show(struct config_item *item, char *buf)
292 struct spear_pcie_gadget_config *config,
293 char *buf)
294{ 295{
295 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 296 struct spear_pcie_gadget_config *config = to_target(item)
297 struct pcie_app_reg __iomem *app_reg = to_target(item)->va_app_base;
296 u32 cap, vec, flags; 298 u32 cap, vec, flags;
297 ulong vector; 299 ulong vector;
298 300
@@ -313,13 +315,12 @@ static ssize_t pcie_gadget_show_no_of_msi(
313 return sprintf(buf, "%lu", vector); 315 return sprintf(buf, "%lu", vector);
314} 316}
315 317
316static ssize_t pcie_gadget_store_no_of_msi( 318static ssize_t pcie_gadget_no_of_msi_store(struct config_item *item,
317 struct spear_pcie_gadget_config *config,
318 const char *buf, size_t count) 319 const char *buf, size_t count)
319{ 320{
320 int ret; 321 int ret;
321 322
322 ret = kstrtoul(buf, 0, &config->requested_msi); 323 ret = kstrtoul(buf, 0, &to_target(item)->requested_msi);
323 if (ret) 324 if (ret)
324 return ret; 325 return ret;
325 326
@@ -329,11 +330,10 @@ static ssize_t pcie_gadget_store_no_of_msi(
329 return count; 330 return count;
330} 331}
331 332
332static ssize_t pcie_gadget_store_inta( 333static ssize_t pcie_gadget_inta_store(struct config_item *item,
333 struct spear_pcie_gadget_config *config,
334 const char *buf, size_t count) 334 const char *buf, size_t count)
335{ 335{
336 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 336 struct pcie_app_reg __iomem *app_reg = to_target(item)->va_app_base;
337 ulong en; 337 ulong en;
338 int ret; 338 int ret;
339 339
@@ -351,10 +351,10 @@ static ssize_t pcie_gadget_store_inta(
351 return count; 351 return count;
352} 352}
353 353
354static ssize_t pcie_gadget_store_send_msi( 354static ssize_t pcie_gadget_send_msi_store(struct config_item *item,
355 struct spear_pcie_gadget_config *config,
356 const char *buf, size_t count) 355 const char *buf, size_t count)
357{ 356{
357 struct spear_pcie_gadget_config *config = to_target(item)
358 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 358 struct pcie_app_reg __iomem *app_reg = config->va_app_base;
359 ulong vector; 359 ulong vector;
360 u32 ven_msi; 360 u32 ven_msi;
@@ -388,19 +388,16 @@ static ssize_t pcie_gadget_store_send_msi(
388 return count; 388 return count;
389} 389}
390 390
391static ssize_t pcie_gadget_show_vendor_id( 391static ssize_t pcie_gadget_vendor_id_show(struct config_item *item, char *buf)
392 struct spear_pcie_gadget_config *config,
393 char *buf)
394{ 392{
395 u32 id; 393 u32 id;
396 394
397 spear_dbi_read_reg(config, PCI_VENDOR_ID, 2, &id); 395 spear_dbi_read_reg(to_target(item), PCI_VENDOR_ID, 2, &id);
398 396
399 return sprintf(buf, "%x", id); 397 return sprintf(buf, "%x", id);
400} 398}
401 399
402static ssize_t pcie_gadget_store_vendor_id( 400static ssize_t pcie_gadget_vendor_id_store(struct config_item *item,
403 struct spear_pcie_gadget_config *config,
404 const char *buf, size_t count) 401 const char *buf, size_t count)
405{ 402{
406 ulong id; 403 ulong id;
@@ -410,24 +407,21 @@ static ssize_t pcie_gadget_store_vendor_id(
410 if (ret) 407 if (ret)
411 return ret; 408 return ret;
412 409
413 spear_dbi_write_reg(config, PCI_VENDOR_ID, 2, id); 410 spear_dbi_write_reg(to_target(item), PCI_VENDOR_ID, 2, id);
414 411
415 return count; 412 return count;
416} 413}
417 414
418static ssize_t pcie_gadget_show_device_id( 415static ssize_t pcie_gadget_device_id_show(struct config_item *item, char *buf)
419 struct spear_pcie_gadget_config *config,
420 char *buf)
421{ 416{
422 u32 id; 417 u32 id;
423 418
424 spear_dbi_read_reg(config, PCI_DEVICE_ID, 2, &id); 419 spear_dbi_read_reg(to_target(item), PCI_DEVICE_ID, 2, &id);
425 420
426 return sprintf(buf, "%x", id); 421 return sprintf(buf, "%x", id);
427} 422}
428 423
429static ssize_t pcie_gadget_store_device_id( 424static ssize_t pcie_gadget_device_id_store(struct config_item *item,
430 struct spear_pcie_gadget_config *config,
431 const char *buf, size_t count) 425 const char *buf, size_t count)
432{ 426{
433 ulong id; 427 ulong id;
@@ -437,22 +431,20 @@ static ssize_t pcie_gadget_store_device_id(
437 if (ret) 431 if (ret)
438 return ret; 432 return ret;
439 433
440 spear_dbi_write_reg(config, PCI_DEVICE_ID, 2, id); 434 spear_dbi_write_reg(to_target(item), PCI_DEVICE_ID, 2, id);
441 435
442 return count; 436 return count;
443} 437}
444 438
445static ssize_t pcie_gadget_show_bar0_size( 439static ssize_t pcie_gadget_bar0_size_show(struct config_item *item, char *buf)
446 struct spear_pcie_gadget_config *config,
447 char *buf)
448{ 440{
449 return sprintf(buf, "%lx", config->bar0_size); 441 return sprintf(buf, "%lx", to_target(item)->bar0_size);
450} 442}
451 443
452static ssize_t pcie_gadget_store_bar0_size( 444static ssize_t pcie_gadget_bar0_size_store(struct config_item *item,
453 struct spear_pcie_gadget_config *config,
454 const char *buf, size_t count) 445 const char *buf, size_t count)
455{ 446{
447 struct spear_pcie_gadget_config *config = to_target(item)
456 ulong size; 448 ulong size;
457 u32 pos, pos1; 449 u32 pos, pos1;
458 u32 no_of_bit = 0; 450 u32 no_of_bit = 0;
@@ -489,21 +481,20 @@ static ssize_t pcie_gadget_store_bar0_size(
489 return count; 481 return count;
490} 482}
491 483
492static ssize_t pcie_gadget_show_bar0_address( 484static ssize_t pcie_gadget_bar0_address_show(struct config_item *item,
493 struct spear_pcie_gadget_config *config,
494 char *buf) 485 char *buf)
495{ 486{
496 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 487 struct pcie_app_reg __iomem *app_reg = to_target(item)->va_app_base;
497 488
498 u32 address = readl(&app_reg->pim0_mem_addr_start); 489 u32 address = readl(&app_reg->pim0_mem_addr_start);
499 490
500 return sprintf(buf, "%x", address); 491 return sprintf(buf, "%x", address);
501} 492}
502 493
503static ssize_t pcie_gadget_store_bar0_address( 494static ssize_t pcie_gadget_bar0_address_store(struct config_item *item,
504 struct spear_pcie_gadget_config *config,
505 const char *buf, size_t count) 495 const char *buf, size_t count)
506{ 496{
497 struct spear_pcie_gadget_config *config = to_target(item)
507 struct pcie_app_reg __iomem *app_reg = config->va_app_base; 498 struct pcie_app_reg __iomem *app_reg = config->va_app_base;
508 ulong address; 499 ulong address;
509 int ret; 500 int ret;
@@ -524,15 +515,13 @@ static ssize_t pcie_gadget_store_bar0_address(
524 return count; 515 return count;
525} 516}
526 517
527static ssize_t pcie_gadget_show_bar0_rw_offset( 518static ssize_t pcie_gadget_bar0_rw_offset_show(struct config_item *item,
528 struct spear_pcie_gadget_config *config,
529 char *buf) 519 char *buf)
530{ 520{
531 return sprintf(buf, "%lx", config->bar0_rw_offset); 521 return sprintf(buf, "%lx", to_target(item)->bar0_rw_offset);
532} 522}
533 523
534static ssize_t pcie_gadget_store_bar0_rw_offset( 524static ssize_t pcie_gadget_bar0_rw_offset_store(struct config_item *item,
535 struct spear_pcie_gadget_config *config,
536 const char *buf, size_t count) 525 const char *buf, size_t count)
537{ 526{
538 ulong offset; 527 ulong offset;
@@ -545,15 +534,14 @@ static ssize_t pcie_gadget_store_bar0_rw_offset(
545 if (offset % 4) 534 if (offset % 4)
546 return -EINVAL; 535 return -EINVAL;
547 536
548 config->bar0_rw_offset = offset; 537 to_target(item)->bar0_rw_offset = offset;
549 538
550 return count; 539 return count;
551} 540}
552 541
553static ssize_t pcie_gadget_show_bar0_data( 542static ssize_t pcie_gadget_bar0_data_show(struct config_item *item, char *buf)
554 struct spear_pcie_gadget_config *config,
555 char *buf)
556{ 543{
544 struct spear_pcie_gadget_config *config = to_target(item)
557 ulong data; 545 ulong data;
558 546
559 if (!config->va_bar0_address) 547 if (!config->va_bar0_address)
@@ -564,10 +552,10 @@ static ssize_t pcie_gadget_show_bar0_data(
564 return sprintf(buf, "%lx", data); 552 return sprintf(buf, "%lx", data);
565} 553}
566 554
567static ssize_t pcie_gadget_store_bar0_data( 555static ssize_t pcie_gadget_bar0_data_store(struct config_item *item,
568 struct spear_pcie_gadget_config *config,
569 const char *buf, size_t count) 556 const char *buf, size_t count)
570{ 557{
558 struct spear_pcie_gadget_config *config = to_target(item)
571 ulong data; 559 ulong data;
572 int ret; 560 int ret;
573 561
@@ -583,97 +571,35 @@ static ssize_t pcie_gadget_store_bar0_data(
583 return count; 571 return count;
584} 572}
585 573
586/* 574CONFIGFS_ATTR(pcie_gadget_, link);
587 * Attribute definitions. 575CONFIGFS_ATTR(pcie_gadget_, int_type);
588 */ 576CONFIGFS_ATTR(pcie_gadget_, no_of_msi);
589 577CONFIGFS_ATTR_WO(pcie_gadget_, inta);
590#define PCIE_GADGET_TARGET_ATTR_RO(_name) \ 578CONFIGFS_ATTR_WO(pcie_gadget_, send_msi);
591static struct pcie_gadget_target_attr pcie_gadget_target_##_name = \ 579CONFIGFS_ATTR(pcie_gadget_, vendor_id);
592 __CONFIGFS_ATTR(_name, S_IRUGO, pcie_gadget_show_##_name, NULL) 580CONFIGFS_ATTR(pcie_gadget_, device_id);
593 581CONFIGFS_ATTR(pcie_gadget_, bar0_size);
594#define PCIE_GADGET_TARGET_ATTR_WO(_name) \ 582CONFIGFS_ATTR(pcie_gadget_, bar0_address);
595static struct pcie_gadget_target_attr pcie_gadget_target_##_name = \ 583CONFIGFS_ATTR(pcie_gadget_, bar0_rw_offset);
596 __CONFIGFS_ATTR(_name, S_IWUSR, NULL, pcie_gadget_store_##_name) 584CONFIGFS_ATTR(pcie_gadget_, bar0_data);
597
598#define PCIE_GADGET_TARGET_ATTR_RW(_name) \
599static struct pcie_gadget_target_attr pcie_gadget_target_##_name = \
600 __CONFIGFS_ATTR(_name, S_IRUGO | S_IWUSR, pcie_gadget_show_##_name, \
601 pcie_gadget_store_##_name)
602PCIE_GADGET_TARGET_ATTR_RW(link);
603PCIE_GADGET_TARGET_ATTR_RW(int_type);
604PCIE_GADGET_TARGET_ATTR_RW(no_of_msi);
605PCIE_GADGET_TARGET_ATTR_WO(inta);
606PCIE_GADGET_TARGET_ATTR_WO(send_msi);
607PCIE_GADGET_TARGET_ATTR_RW(vendor_id);
608PCIE_GADGET_TARGET_ATTR_RW(device_id);
609PCIE_GADGET_TARGET_ATTR_RW(bar0_size);
610PCIE_GADGET_TARGET_ATTR_RW(bar0_address);
611PCIE_GADGET_TARGET_ATTR_RW(bar0_rw_offset);
612PCIE_GADGET_TARGET_ATTR_RW(bar0_data);
613 585
614static struct configfs_attribute *pcie_gadget_target_attrs[] = { 586static struct configfs_attribute *pcie_gadget_target_attrs[] = {
615 &pcie_gadget_target_link.attr, 587 &pcie_gadget_attr_link,
616 &pcie_gadget_target_int_type.attr, 588 &pcie_gadget_attr_int_type,
617 &pcie_gadget_target_no_of_msi.attr, 589 &pcie_gadget_attr_no_of_msi,
618 &pcie_gadget_target_inta.attr, 590 &pcie_gadget_attr_inta,
619 &pcie_gadget_target_send_msi.attr, 591 &pcie_gadget_attr_send_msi,
620 &pcie_gadget_target_vendor_id.attr, 592 &pcie_gadget_attr_vendor_id,
621 &pcie_gadget_target_device_id.attr, 593 &pcie_gadget_attr_device_id,
622 &pcie_gadget_target_bar0_size.attr, 594 &pcie_gadget_attr_bar0_size,
623 &pcie_gadget_target_bar0_address.attr, 595 &pcie_gadget_attr_bar0_address,
624 &pcie_gadget_target_bar0_rw_offset.attr, 596 &pcie_gadget_attr_bar0_rw_offset,
625 &pcie_gadget_target_bar0_data.attr, 597 &pcie_gadget_attr_bar0_data,
626 NULL, 598 NULL,
627}; 599};
628 600
629static struct pcie_gadget_target *to_target(struct config_item *item)
630{
631 return item ?
632 container_of(to_configfs_subsystem(to_config_group(item)),
633 struct pcie_gadget_target, subsys) : NULL;
634}
635
636/*
637 * Item operations and type for pcie_gadget_target.
638 */
639
640static ssize_t pcie_gadget_target_attr_show(struct config_item *item,
641 struct configfs_attribute *attr,
642 char *buf)
643{
644 ssize_t ret = -EINVAL;
645 struct pcie_gadget_target *target = to_target(item);
646 struct pcie_gadget_target_attr *t_attr =
647 container_of(attr, struct pcie_gadget_target_attr, attr);
648
649 if (t_attr->show)
650 ret = t_attr->show(&target->config, buf);
651 return ret;
652}
653
654static ssize_t pcie_gadget_target_attr_store(struct config_item *item,
655 struct configfs_attribute *attr,
656 const char *buf,
657 size_t count)
658{
659 ssize_t ret = -EINVAL;
660 struct pcie_gadget_target *target = to_target(item);
661 struct pcie_gadget_target_attr *t_attr =
662 container_of(attr, struct pcie_gadget_target_attr, attr);
663
664 if (t_attr->store)
665 ret = t_attr->store(&target->config, buf, count);
666 return ret;
667}
668
669static struct configfs_item_operations pcie_gadget_target_item_ops = {
670 .show_attribute = pcie_gadget_target_attr_show,
671 .store_attribute = pcie_gadget_target_attr_store,
672};
673
674static struct config_item_type pcie_gadget_target_type = { 601static struct config_item_type pcie_gadget_target_type = {
675 .ct_attrs = pcie_gadget_target_attrs, 602 .ct_attrs = pcie_gadget_target_attrs,
676 .ct_item_ops = &pcie_gadget_target_item_ops,
677 .ct_owner = THIS_MODULE, 603 .ct_owner = THIS_MODULE,
678}; 604};
679 605
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 97f3acd44798..06ee6395117f 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -244,15 +244,6 @@ static void free_param_target(struct netconsole_target *nt)
244 * <target>/... 244 * <target>/...
245 */ 245 */
246 246
247struct netconsole_target_attr {
248 struct configfs_attribute attr;
249 ssize_t (*show)(struct netconsole_target *nt,
250 char *buf);
251 ssize_t (*store)(struct netconsole_target *nt,
252 const char *buf,
253 size_t count);
254};
255
256static struct netconsole_target *to_target(struct config_item *item) 247static struct netconsole_target *to_target(struct config_item *item)
257{ 248{
258 return item ? 249 return item ?
@@ -264,58 +255,62 @@ static struct netconsole_target *to_target(struct config_item *item)
264 * Attribute operations for netconsole_target. 255 * Attribute operations for netconsole_target.
265 */ 256 */
266 257
267static ssize_t show_enabled(struct netconsole_target *nt, char *buf) 258static ssize_t enabled_show(struct config_item *item, char *buf)
268{ 259{
269 return snprintf(buf, PAGE_SIZE, "%d\n", nt->enabled); 260 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->enabled);
270} 261}
271 262
272static ssize_t show_extended(struct netconsole_target *nt, char *buf) 263static ssize_t extended_show(struct config_item *item, char *buf)
273{ 264{
274 return snprintf(buf, PAGE_SIZE, "%d\n", nt->extended); 265 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended);
275} 266}
276 267
277static ssize_t show_dev_name(struct netconsole_target *nt, char *buf) 268static ssize_t dev_name_show(struct config_item *item, char *buf)
278{ 269{
279 return snprintf(buf, PAGE_SIZE, "%s\n", nt->np.dev_name); 270 return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name);
280} 271}
281 272
282static ssize_t show_local_port(struct netconsole_target *nt, char *buf) 273static ssize_t local_port_show(struct config_item *item, char *buf)
283{ 274{
284 return snprintf(buf, PAGE_SIZE, "%d\n", nt->np.local_port); 275 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->np.local_port);
285} 276}
286 277
287static ssize_t show_remote_port(struct netconsole_target *nt, char *buf) 278static ssize_t remote_port_show(struct config_item *item, char *buf)
288{ 279{
289 return snprintf(buf, PAGE_SIZE, "%d\n", nt->np.remote_port); 280 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->np.remote_port);
290} 281}
291 282
292static ssize_t show_local_ip(struct netconsole_target *nt, char *buf) 283static ssize_t local_ip_show(struct config_item *item, char *buf)
293{ 284{
285 struct netconsole_target *nt = to_target(item);
286
294 if (nt->np.ipv6) 287 if (nt->np.ipv6)
295 return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.in6); 288 return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.in6);
296 else 289 else
297 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip); 290 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip);
298} 291}
299 292
300static ssize_t show_remote_ip(struct netconsole_target *nt, char *buf) 293static ssize_t remote_ip_show(struct config_item *item, char *buf)
301{ 294{
295 struct netconsole_target *nt = to_target(item);
296
302 if (nt->np.ipv6) 297 if (nt->np.ipv6)
303 return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.in6); 298 return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.in6);
304 else 299 else
305 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip); 300 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip);
306} 301}
307 302
308static ssize_t show_local_mac(struct netconsole_target *nt, char *buf) 303static ssize_t local_mac_show(struct config_item *item, char *buf)
309{ 304{
310 struct net_device *dev = nt->np.dev; 305 struct net_device *dev = to_target(item)->np.dev;
311 static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 306 static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
312 307
313 return snprintf(buf, PAGE_SIZE, "%pM\n", dev ? dev->dev_addr : bcast); 308 return snprintf(buf, PAGE_SIZE, "%pM\n", dev ? dev->dev_addr : bcast);
314} 309}
315 310
316static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf) 311static ssize_t remote_mac_show(struct config_item *item, char *buf)
317{ 312{
318 return snprintf(buf, PAGE_SIZE, "%pM\n", nt->np.remote_mac); 313 return snprintf(buf, PAGE_SIZE, "%pM\n", to_target(item)->np.remote_mac);
319} 314}
320 315
321/* 316/*
@@ -325,23 +320,26 @@ static ssize_t show_remote_mac(struct netconsole_target *nt, char *buf)
325 * would enable him to dynamically add new netpoll targets for new 320 * would enable him to dynamically add new netpoll targets for new
326 * network interfaces as and when they come up). 321 * network interfaces as and when they come up).
327 */ 322 */
328static ssize_t store_enabled(struct netconsole_target *nt, 323static ssize_t enabled_store(struct config_item *item,
329 const char *buf, 324 const char *buf, size_t count)
330 size_t count)
331{ 325{
326 struct netconsole_target *nt = to_target(item);
332 unsigned long flags; 327 unsigned long flags;
333 int enabled; 328 int enabled;
334 int err; 329 int err;
335 330
331 mutex_lock(&dynamic_netconsole_mutex);
336 err = kstrtoint(buf, 10, &enabled); 332 err = kstrtoint(buf, 10, &enabled);
337 if (err < 0) 333 if (err < 0)
338 return err; 334 goto out_unlock;
335
336 err = -EINVAL;
339 if (enabled < 0 || enabled > 1) 337 if (enabled < 0 || enabled > 1)
340 return -EINVAL; 338 goto out_unlock;
341 if ((bool)enabled == nt->enabled) { 339 if ((bool)enabled == nt->enabled) {
342 pr_info("network logging has already %s\n", 340 pr_info("network logging has already %s\n",
343 nt->enabled ? "started" : "stopped"); 341 nt->enabled ? "started" : "stopped");
344 return -EINVAL; 342 goto out_unlock;
345 } 343 }
346 344
347 if (enabled) { /* true */ 345 if (enabled) { /* true */
@@ -358,7 +356,7 @@ static ssize_t store_enabled(struct netconsole_target *nt,
358 356
359 err = netpoll_setup(&nt->np); 357 err = netpoll_setup(&nt->np);
360 if (err) 358 if (err)
361 return err; 359 goto out_unlock;
362 360
363 pr_info("netconsole: network logging started\n"); 361 pr_info("netconsole: network logging started\n");
364 } else { /* false */ 362 } else { /* false */
@@ -374,42 +372,56 @@ static ssize_t store_enabled(struct netconsole_target *nt,
374 372
375 nt->enabled = enabled; 373 nt->enabled = enabled;
376 374
375 mutex_unlock(&dynamic_netconsole_mutex);
377 return strnlen(buf, count); 376 return strnlen(buf, count);
377out_unlock:
378 mutex_unlock(&dynamic_netconsole_mutex);
379 return err;
378} 380}
379 381
380static ssize_t store_extended(struct netconsole_target *nt, 382static ssize_t extended_store(struct config_item *item, const char *buf,
381 const char *buf, 383 size_t count)
382 size_t count)
383{ 384{
385 struct netconsole_target *nt = to_target(item);
384 int extended; 386 int extended;
385 int err; 387 int err;
386 388
389 mutex_lock(&dynamic_netconsole_mutex);
387 if (nt->enabled) { 390 if (nt->enabled) {
388 pr_err("target (%s) is enabled, disable to update parameters\n", 391 pr_err("target (%s) is enabled, disable to update parameters\n",
389 config_item_name(&nt->item)); 392 config_item_name(&nt->item));
390 return -EINVAL; 393 err = -EINVAL;
394 goto out_unlock;
391 } 395 }
392 396
393 err = kstrtoint(buf, 10, &extended); 397 err = kstrtoint(buf, 10, &extended);
394 if (err < 0) 398 if (err < 0)
395 return err; 399 goto out_unlock;
396 if (extended < 0 || extended > 1) 400 if (extended < 0 || extended > 1) {
397 return -EINVAL; 401 err = -EINVAL;
402 goto out_unlock;
403 }
398 404
399 nt->extended = extended; 405 nt->extended = extended;
400 406
407 mutex_unlock(&dynamic_netconsole_mutex);
401 return strnlen(buf, count); 408 return strnlen(buf, count);
409out_unlock:
410 mutex_unlock(&dynamic_netconsole_mutex);
411 return err;
402} 412}
403 413
404static ssize_t store_dev_name(struct netconsole_target *nt, 414static ssize_t dev_name_store(struct config_item *item, const char *buf,
405 const char *buf, 415 size_t count)
406 size_t count)
407{ 416{
417 struct netconsole_target *nt = to_target(item);
408 size_t len; 418 size_t len;
409 419
420 mutex_lock(&dynamic_netconsole_mutex);
410 if (nt->enabled) { 421 if (nt->enabled) {
411 pr_err("target (%s) is enabled, disable to update parameters\n", 422 pr_err("target (%s) is enabled, disable to update parameters\n",
412 config_item_name(&nt->item)); 423 config_item_name(&nt->item));
424 mutex_unlock(&dynamic_netconsole_mutex);
413 return -EINVAL; 425 return -EINVAL;
414 } 426 }
415 427
@@ -420,53 +432,66 @@ static ssize_t store_dev_name(struct netconsole_target *nt,
420 if (nt->np.dev_name[len - 1] == '\n') 432 if (nt->np.dev_name[len - 1] == '\n')
421 nt->np.dev_name[len - 1] = '\0'; 433 nt->np.dev_name[len - 1] = '\0';
422 434
435 mutex_unlock(&dynamic_netconsole_mutex);
423 return strnlen(buf, count); 436 return strnlen(buf, count);
424} 437}
425 438
426static ssize_t store_local_port(struct netconsole_target *nt, 439static ssize_t local_port_store(struct config_item *item, const char *buf,
427 const char *buf, 440 size_t count)
428 size_t count)
429{ 441{
430 int rv; 442 struct netconsole_target *nt = to_target(item);
443 int rv = -EINVAL;
431 444
445 mutex_lock(&dynamic_netconsole_mutex);
432 if (nt->enabled) { 446 if (nt->enabled) {
433 pr_err("target (%s) is enabled, disable to update parameters\n", 447 pr_err("target (%s) is enabled, disable to update parameters\n",
434 config_item_name(&nt->item)); 448 config_item_name(&nt->item));
435 return -EINVAL; 449 goto out_unlock;
436 } 450 }
437 451
438 rv = kstrtou16(buf, 10, &nt->np.local_port); 452 rv = kstrtou16(buf, 10, &nt->np.local_port);
439 if (rv < 0) 453 if (rv < 0)
440 return rv; 454 goto out_unlock;
455 mutex_unlock(&dynamic_netconsole_mutex);
441 return strnlen(buf, count); 456 return strnlen(buf, count);
457out_unlock:
458 mutex_unlock(&dynamic_netconsole_mutex);
459 return rv;
442} 460}
443 461
444static ssize_t store_remote_port(struct netconsole_target *nt, 462static ssize_t remote_port_store(struct config_item *item,
445 const char *buf, 463 const char *buf, size_t count)
446 size_t count)
447{ 464{
448 int rv; 465 struct netconsole_target *nt = to_target(item);
466 int rv = -EINVAL;
449 467
468 mutex_lock(&dynamic_netconsole_mutex);
450 if (nt->enabled) { 469 if (nt->enabled) {
451 pr_err("target (%s) is enabled, disable to update parameters\n", 470 pr_err("target (%s) is enabled, disable to update parameters\n",
452 config_item_name(&nt->item)); 471 config_item_name(&nt->item));
453 return -EINVAL; 472 goto out_unlock;
454 } 473 }
455 474
456 rv = kstrtou16(buf, 10, &nt->np.remote_port); 475 rv = kstrtou16(buf, 10, &nt->np.remote_port);
457 if (rv < 0) 476 if (rv < 0)
458 return rv; 477 goto out_unlock;
478 mutex_unlock(&dynamic_netconsole_mutex);
459 return strnlen(buf, count); 479 return strnlen(buf, count);
480out_unlock:
481 mutex_unlock(&dynamic_netconsole_mutex);
482 return rv;
460} 483}
461 484
462static ssize_t store_local_ip(struct netconsole_target *nt, 485static ssize_t local_ip_store(struct config_item *item, const char *buf,
463 const char *buf, 486 size_t count)
464 size_t count)
465{ 487{
488 struct netconsole_target *nt = to_target(item);
489
490 mutex_lock(&dynamic_netconsole_mutex);
466 if (nt->enabled) { 491 if (nt->enabled) {
467 pr_err("target (%s) is enabled, disable to update parameters\n", 492 pr_err("target (%s) is enabled, disable to update parameters\n",
468 config_item_name(&nt->item)); 493 config_item_name(&nt->item));
469 return -EINVAL; 494 goto out_unlock;
470 } 495 }
471 496
472 if (strnchr(buf, count, ':')) { 497 if (strnchr(buf, count, ':')) {
@@ -474,29 +499,35 @@ static ssize_t store_local_ip(struct netconsole_target *nt,
474 if (in6_pton(buf, count, nt->np.local_ip.in6.s6_addr, -1, &end) > 0) { 499 if (in6_pton(buf, count, nt->np.local_ip.in6.s6_addr, -1, &end) > 0) {
475 if (*end && *end != '\n') { 500 if (*end && *end != '\n') {
476 pr_err("invalid IPv6 address at: <%c>\n", *end); 501 pr_err("invalid IPv6 address at: <%c>\n", *end);
477 return -EINVAL; 502 goto out_unlock;
478 } 503 }
479 nt->np.ipv6 = true; 504 nt->np.ipv6 = true;
480 } else 505 } else
481 return -EINVAL; 506 goto out_unlock;
482 } else { 507 } else {
483 if (!nt->np.ipv6) { 508 if (!nt->np.ipv6) {
484 nt->np.local_ip.ip = in_aton(buf); 509 nt->np.local_ip.ip = in_aton(buf);
485 } else 510 } else
486 return -EINVAL; 511 goto out_unlock;
487 } 512 }
488 513
514 mutex_unlock(&dynamic_netconsole_mutex);
489 return strnlen(buf, count); 515 return strnlen(buf, count);
516out_unlock:
517 mutex_unlock(&dynamic_netconsole_mutex);
518 return -EINVAL;
490} 519}
491 520
492static ssize_t store_remote_ip(struct netconsole_target *nt, 521static ssize_t remote_ip_store(struct config_item *item, const char *buf,
493 const char *buf, 522 size_t count)
494 size_t count)
495{ 523{
524 struct netconsole_target *nt = to_target(item);
525
526 mutex_lock(&dynamic_netconsole_mutex);
496 if (nt->enabled) { 527 if (nt->enabled) {
497 pr_err("target (%s) is enabled, disable to update parameters\n", 528 pr_err("target (%s) is enabled, disable to update parameters\n",
498 config_item_name(&nt->item)); 529 config_item_name(&nt->item));
499 return -EINVAL; 530 goto out_unlock;
500 } 531 }
501 532
502 if (strnchr(buf, count, ':')) { 533 if (strnchr(buf, count, ':')) {
@@ -504,74 +535,71 @@ static ssize_t store_remote_ip(struct netconsole_target *nt,
504 if (in6_pton(buf, count, nt->np.remote_ip.in6.s6_addr, -1, &end) > 0) { 535 if (in6_pton(buf, count, nt->np.remote_ip.in6.s6_addr, -1, &end) > 0) {
505 if (*end && *end != '\n') { 536 if (*end && *end != '\n') {
506 pr_err("invalid IPv6 address at: <%c>\n", *end); 537 pr_err("invalid IPv6 address at: <%c>\n", *end);
507 return -EINVAL; 538 goto out_unlock;
508 } 539 }
509 nt->np.ipv6 = true; 540 nt->np.ipv6 = true;
510 } else 541 } else
511 return -EINVAL; 542 goto out_unlock;
512 } else { 543 } else {
513 if (!nt->np.ipv6) { 544 if (!nt->np.ipv6) {
514 nt->np.remote_ip.ip = in_aton(buf); 545 nt->np.remote_ip.ip = in_aton(buf);
515 } else 546 } else
516 return -EINVAL; 547 goto out_unlock;
517 } 548 }
518 549
550 mutex_unlock(&dynamic_netconsole_mutex);
519 return strnlen(buf, count); 551 return strnlen(buf, count);
552out_unlock:
553 mutex_unlock(&dynamic_netconsole_mutex);
554 return -EINVAL;
520} 555}
521 556
522static ssize_t store_remote_mac(struct netconsole_target *nt, 557static ssize_t remote_mac_store(struct config_item *item, const char *buf,
523 const char *buf, 558 size_t count)
524 size_t count)
525{ 559{
560 struct netconsole_target *nt = to_target(item);
526 u8 remote_mac[ETH_ALEN]; 561 u8 remote_mac[ETH_ALEN];
527 562
563 mutex_lock(&dynamic_netconsole_mutex);
528 if (nt->enabled) { 564 if (nt->enabled) {
529 pr_err("target (%s) is enabled, disable to update parameters\n", 565 pr_err("target (%s) is enabled, disable to update parameters\n",
530 config_item_name(&nt->item)); 566 config_item_name(&nt->item));
531 return -EINVAL; 567 goto out_unlock;
532 } 568 }
533 569
534 if (!mac_pton(buf, remote_mac)) 570 if (!mac_pton(buf, remote_mac))
535 return -EINVAL; 571 goto out_unlock;
536 if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n') 572 if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n')
537 return -EINVAL; 573 goto out_unlock;
538 memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN); 574 memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN);
539 575
576 mutex_unlock(&dynamic_netconsole_mutex);
540 return strnlen(buf, count); 577 return strnlen(buf, count);
578out_unlock:
579 mutex_unlock(&dynamic_netconsole_mutex);
580 return -EINVAL;
541} 581}
542 582
543/* 583CONFIGFS_ATTR(, enabled);
544 * Attribute definitions for netconsole_target. 584CONFIGFS_ATTR(, extended);
545 */ 585CONFIGFS_ATTR(, dev_name);
546 586CONFIGFS_ATTR(, local_port);
547#define NETCONSOLE_TARGET_ATTR_RO(_name) \ 587CONFIGFS_ATTR(, remote_port);
548static struct netconsole_target_attr netconsole_target_##_name = \ 588CONFIGFS_ATTR(, local_ip);
549 __CONFIGFS_ATTR(_name, S_IRUGO, show_##_name, NULL) 589CONFIGFS_ATTR(, remote_ip);
550 590CONFIGFS_ATTR_RO(, local_mac);
551#define NETCONSOLE_TARGET_ATTR_RW(_name) \ 591CONFIGFS_ATTR(, remote_mac);
552static struct netconsole_target_attr netconsole_target_##_name = \
553 __CONFIGFS_ATTR(_name, S_IRUGO | S_IWUSR, show_##_name, store_##_name)
554
555NETCONSOLE_TARGET_ATTR_RW(enabled);
556NETCONSOLE_TARGET_ATTR_RW(extended);
557NETCONSOLE_TARGET_ATTR_RW(dev_name);
558NETCONSOLE_TARGET_ATTR_RW(local_port);
559NETCONSOLE_TARGET_ATTR_RW(remote_port);
560NETCONSOLE_TARGET_ATTR_RW(local_ip);
561NETCONSOLE_TARGET_ATTR_RW(remote_ip);
562NETCONSOLE_TARGET_ATTR_RO(local_mac);
563NETCONSOLE_TARGET_ATTR_RW(remote_mac);
564 592
565static struct configfs_attribute *netconsole_target_attrs[] = { 593static struct configfs_attribute *netconsole_target_attrs[] = {
566 &netconsole_target_enabled.attr, 594 &attr_enabled,
567 &netconsole_target_extended.attr, 595 &attr_extended,
568 &netconsole_target_dev_name.attr, 596 &attr_dev_name,
569 &netconsole_target_local_port.attr, 597 &attr_local_port,
570 &netconsole_target_remote_port.attr, 598 &attr_remote_port,
571 &netconsole_target_local_ip.attr, 599 &attr_local_ip,
572 &netconsole_target_remote_ip.attr, 600 &attr_remote_ip,
573 &netconsole_target_local_mac.attr, 601 &attr_local_mac,
574 &netconsole_target_remote_mac.attr, 602 &attr_remote_mac,
575 NULL, 603 NULL,
576}; 604};
577 605
@@ -584,43 +612,8 @@ static void netconsole_target_release(struct config_item *item)
584 kfree(to_target(item)); 612 kfree(to_target(item));
585} 613}
586 614
587static ssize_t netconsole_target_attr_show(struct config_item *item,
588 struct configfs_attribute *attr,
589 char *buf)
590{
591 ssize_t ret = -EINVAL;
592 struct netconsole_target *nt = to_target(item);
593 struct netconsole_target_attr *na =
594 container_of(attr, struct netconsole_target_attr, attr);
595
596 if (na->show)
597 ret = na->show(nt, buf);
598
599 return ret;
600}
601
602static ssize_t netconsole_target_attr_store(struct config_item *item,
603 struct configfs_attribute *attr,
604 const char *buf,
605 size_t count)
606{
607 ssize_t ret = -EINVAL;
608 struct netconsole_target *nt = to_target(item);
609 struct netconsole_target_attr *na =
610 container_of(attr, struct netconsole_target_attr, attr);
611
612 mutex_lock(&dynamic_netconsole_mutex);
613 if (na->store)
614 ret = na->store(nt, buf, count);
615 mutex_unlock(&dynamic_netconsole_mutex);
616
617 return ret;
618}
619
620static struct configfs_item_operations netconsole_target_item_ops = { 615static struct configfs_item_operations netconsole_target_item_ops = {
621 .release = netconsole_target_release, 616 .release = netconsole_target_release,
622 .show_attribute = netconsole_target_attr_show,
623 .store_attribute = netconsole_target_attr_store,
624}; 617};
625 618
626static struct config_item_type netconsole_target_type = { 619static struct config_item_type netconsole_target_type = {
diff --git a/drivers/scsi/qla2xxx/tcm_qla2xxx.c b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
index ac65cb7b4886..3ba2e9564b9a 100644
--- a/drivers/scsi/qla2xxx/tcm_qla2xxx.c
+++ b/drivers/scsi/qla2xxx/tcm_qla2xxx.c
@@ -43,8 +43,6 @@
43#include <scsi/scsi_cmnd.h> 43#include <scsi/scsi_cmnd.h>
44#include <target/target_core_base.h> 44#include <target/target_core_base.h>
45#include <target/target_core_fabric.h> 45#include <target/target_core_fabric.h>
46#include <target/target_core_fabric_configfs.h>
47#include <target/configfs_macros.h>
48 46
49#include "qla_def.h" 47#include "qla_def.h"
50#include "qla_target.h" 48#include "qla_target.h"
@@ -729,23 +727,23 @@ static int tcm_qla2xxx_init_nodeacl(struct se_node_acl *se_nacl,
729 727
730#define DEF_QLA_TPG_ATTRIB(name) \ 728#define DEF_QLA_TPG_ATTRIB(name) \
731 \ 729 \
732static ssize_t tcm_qla2xxx_tpg_attrib_show_##name( \ 730static ssize_t tcm_qla2xxx_tpg_attrib_##name##_show( \
733 struct se_portal_group *se_tpg, \ 731 struct config_item *item, char *page) \
734 char *page) \
735{ \ 732{ \
733 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
736 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \ 734 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
737 struct tcm_qla2xxx_tpg, se_tpg); \ 735 struct tcm_qla2xxx_tpg, se_tpg); \
738 \ 736 \
739 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \ 737 return sprintf(page, "%u\n", tpg->tpg_attrib.name); \
740} \ 738} \
741 \ 739 \
742static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \ 740static ssize_t tcm_qla2xxx_tpg_attrib_##name##_store( \
743 struct se_portal_group *se_tpg, \ 741 struct config_item *item, const char *page, size_t count) \
744 const char *page, \
745 size_t count) \
746{ \ 742{ \
743 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
747 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \ 744 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, \
748 struct tcm_qla2xxx_tpg, se_tpg); \ 745 struct tcm_qla2xxx_tpg, se_tpg); \
746 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
749 unsigned long val; \ 747 unsigned long val; \
750 int ret; \ 748 int ret; \
751 \ 749 \
@@ -755,81 +753,39 @@ static ssize_t tcm_qla2xxx_tpg_attrib_store_##name( \
755 " ret: %d\n", ret); \ 753 " ret: %d\n", ret); \
756 return -EINVAL; \ 754 return -EINVAL; \
757 } \ 755 } \
758 ret = tcm_qla2xxx_set_attrib_##name(tpg, val); \
759 \
760 return (!ret) ? count : -EINVAL; \
761}
762
763#define DEF_QLA_TPG_ATTR_BOOL(_name) \
764 \
765static int tcm_qla2xxx_set_attrib_##_name( \
766 struct tcm_qla2xxx_tpg *tpg, \
767 unsigned long val) \
768{ \
769 struct tcm_qla2xxx_tpg_attrib *a = &tpg->tpg_attrib; \
770 \ 756 \
771 if ((val != 0) && (val != 1)) { \ 757 if ((val != 0) && (val != 1)) { \
772 pr_err("Illegal boolean value %lu\n", val); \ 758 pr_err("Illegal boolean value %lu\n", val); \
773 return -EINVAL; \ 759 return -EINVAL; \
774 } \ 760 } \
775 \ 761 \
776 a->_name = val; \ 762 a->name = val; \
777 return 0; \ 763 \
778} 764 return count; \
779 765} \
780#define QLA_TPG_ATTR(_name, _mode) \ 766CONFIGFS_ATTR(tcm_qla2xxx_tpg_attrib_, name)
781 TF_TPG_ATTRIB_ATTR(tcm_qla2xxx, _name, _mode);
782 767
783/*
784 * Define tcm_qla2xxx_tpg_attrib_s_generate_node_acls
785 */
786DEF_QLA_TPG_ATTR_BOOL(generate_node_acls);
787DEF_QLA_TPG_ATTRIB(generate_node_acls); 768DEF_QLA_TPG_ATTRIB(generate_node_acls);
788QLA_TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
789
790/*
791 Define tcm_qla2xxx_attrib_s_cache_dynamic_acls
792 */
793DEF_QLA_TPG_ATTR_BOOL(cache_dynamic_acls);
794DEF_QLA_TPG_ATTRIB(cache_dynamic_acls); 769DEF_QLA_TPG_ATTRIB(cache_dynamic_acls);
795QLA_TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
796
797/*
798 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_write_protect
799 */
800DEF_QLA_TPG_ATTR_BOOL(demo_mode_write_protect);
801DEF_QLA_TPG_ATTRIB(demo_mode_write_protect); 770DEF_QLA_TPG_ATTRIB(demo_mode_write_protect);
802QLA_TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
803
804/*
805 * Define tcm_qla2xxx_tpg_attrib_s_prod_mode_write_protect
806 */
807DEF_QLA_TPG_ATTR_BOOL(prod_mode_write_protect);
808DEF_QLA_TPG_ATTRIB(prod_mode_write_protect); 771DEF_QLA_TPG_ATTRIB(prod_mode_write_protect);
809QLA_TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
810
811/*
812 * Define tcm_qla2xxx_tpg_attrib_s_demo_mode_login_only
813 */
814DEF_QLA_TPG_ATTR_BOOL(demo_mode_login_only);
815DEF_QLA_TPG_ATTRIB(demo_mode_login_only); 772DEF_QLA_TPG_ATTRIB(demo_mode_login_only);
816QLA_TPG_ATTR(demo_mode_login_only, S_IRUGO | S_IWUSR);
817 773
818static struct configfs_attribute *tcm_qla2xxx_tpg_attrib_attrs[] = { 774static struct configfs_attribute *tcm_qla2xxx_tpg_attrib_attrs[] = {
819 &tcm_qla2xxx_tpg_attrib_generate_node_acls.attr, 775 &tcm_qla2xxx_tpg_attrib_attr_generate_node_acls,
820 &tcm_qla2xxx_tpg_attrib_cache_dynamic_acls.attr, 776 &tcm_qla2xxx_tpg_attrib_attr_cache_dynamic_acls,
821 &tcm_qla2xxx_tpg_attrib_demo_mode_write_protect.attr, 777 &tcm_qla2xxx_tpg_attrib_attr_demo_mode_write_protect,
822 &tcm_qla2xxx_tpg_attrib_prod_mode_write_protect.attr, 778 &tcm_qla2xxx_tpg_attrib_attr_prod_mode_write_protect,
823 &tcm_qla2xxx_tpg_attrib_demo_mode_login_only.attr, 779 &tcm_qla2xxx_tpg_attrib_attr_demo_mode_login_only,
824 NULL, 780 NULL,
825}; 781};
826 782
827/* End items for tcm_qla2xxx_tpg_attrib_cit */ 783/* End items for tcm_qla2xxx_tpg_attrib_cit */
828 784
829static ssize_t tcm_qla2xxx_tpg_show_enable( 785static ssize_t tcm_qla2xxx_tpg_enable_show(struct config_item *item,
830 struct se_portal_group *se_tpg, 786 char *page)
831 char *page)
832{ 787{
788 struct se_portal_group *se_tpg = to_tpg(item);
833 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 789 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
834 struct tcm_qla2xxx_tpg, se_tpg); 790 struct tcm_qla2xxx_tpg, se_tpg);
835 791
@@ -865,11 +821,10 @@ static void tcm_qla2xxx_undepend_tpg(struct work_struct *work)
865 complete(&base_tpg->tpg_base_comp); 821 complete(&base_tpg->tpg_base_comp);
866} 822}
867 823
868static ssize_t tcm_qla2xxx_tpg_store_enable( 824static ssize_t tcm_qla2xxx_tpg_enable_store(struct config_item *item,
869 struct se_portal_group *se_tpg, 825 const char *page, size_t count)
870 const char *page,
871 size_t count)
872{ 826{
827 struct se_portal_group *se_tpg = to_tpg(item);
873 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 828 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
874 struct tcm_qla2xxx_tpg, se_tpg); 829 struct tcm_qla2xxx_tpg, se_tpg);
875 unsigned long op; 830 unsigned long op;
@@ -909,22 +864,16 @@ static ssize_t tcm_qla2xxx_tpg_store_enable(
909 return count; 864 return count;
910} 865}
911 866
912TF_TPG_BASE_ATTR(tcm_qla2xxx, enable, S_IRUGO | S_IWUSR); 867static ssize_t tcm_qla2xxx_tpg_dynamic_sessions_show(struct config_item *item,
913 868 char *page)
914static ssize_t tcm_qla2xxx_tpg_show_dynamic_sessions(
915 struct se_portal_group *se_tpg,
916 char *page)
917{ 869{
918 return target_show_dynamic_sessions(se_tpg, page); 870 return target_show_dynamic_sessions(to_tpg(item), page);
919} 871}
920 872
921TF_TPG_BASE_ATTR_RO(tcm_qla2xxx, dynamic_sessions); 873static ssize_t tcm_qla2xxx_tpg_fabric_prot_type_store(struct config_item *item,
922 874 const char *page, size_t count)
923static ssize_t tcm_qla2xxx_tpg_store_fabric_prot_type(
924 struct se_portal_group *se_tpg,
925 const char *page,
926 size_t count)
927{ 875{
876 struct se_portal_group *se_tpg = to_tpg(item);
928 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 877 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
929 struct tcm_qla2xxx_tpg, se_tpg); 878 struct tcm_qla2xxx_tpg, se_tpg);
930 unsigned long val; 879 unsigned long val;
@@ -943,21 +892,24 @@ static ssize_t tcm_qla2xxx_tpg_store_fabric_prot_type(
943 return count; 892 return count;
944} 893}
945 894
946static ssize_t tcm_qla2xxx_tpg_show_fabric_prot_type( 895static ssize_t tcm_qla2xxx_tpg_fabric_prot_type_show(struct config_item *item,
947 struct se_portal_group *se_tpg, 896 char *page)
948 char *page)
949{ 897{
898 struct se_portal_group *se_tpg = to_tpg(item);
950 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg, 899 struct tcm_qla2xxx_tpg *tpg = container_of(se_tpg,
951 struct tcm_qla2xxx_tpg, se_tpg); 900 struct tcm_qla2xxx_tpg, se_tpg);
952 901
953 return sprintf(page, "%d\n", tpg->tpg_attrib.fabric_prot_type); 902 return sprintf(page, "%d\n", tpg->tpg_attrib.fabric_prot_type);
954} 903}
955TF_TPG_BASE_ATTR(tcm_qla2xxx, fabric_prot_type, S_IRUGO | S_IWUSR); 904
905CONFIGFS_ATTR_WO(tcm_qla2xxx_tpg_, enable);
906CONFIGFS_ATTR_RO(tcm_qla2xxx_tpg_, dynamic_sessions);
907CONFIGFS_ATTR(tcm_qla2xxx_tpg_, fabric_prot_type);
956 908
957static struct configfs_attribute *tcm_qla2xxx_tpg_attrs[] = { 909static struct configfs_attribute *tcm_qla2xxx_tpg_attrs[] = {
958 &tcm_qla2xxx_tpg_enable.attr, 910 &tcm_qla2xxx_tpg_attr_enable,
959 &tcm_qla2xxx_tpg_dynamic_sessions.attr, 911 &tcm_qla2xxx_tpg_attr_dynamic_sessions,
960 &tcm_qla2xxx_tpg_fabric_prot_type.attr, 912 &tcm_qla2xxx_tpg_attr_fabric_prot_type,
961 NULL, 913 NULL,
962}; 914};
963 915
@@ -1030,18 +982,16 @@ static void tcm_qla2xxx_drop_tpg(struct se_portal_group *se_tpg)
1030 kfree(tpg); 982 kfree(tpg);
1031} 983}
1032 984
1033static ssize_t tcm_qla2xxx_npiv_tpg_show_enable( 985static ssize_t tcm_qla2xxx_npiv_tpg_enable_show(struct config_item *item,
1034 struct se_portal_group *se_tpg, 986 char *page)
1035 char *page)
1036{ 987{
1037 return tcm_qla2xxx_tpg_show_enable(se_tpg, page); 988 return tcm_qla2xxx_tpg_enable_show(item, page);
1038} 989}
1039 990
1040static ssize_t tcm_qla2xxx_npiv_tpg_store_enable( 991static ssize_t tcm_qla2xxx_npiv_tpg_enable_store(struct config_item *item,
1041 struct se_portal_group *se_tpg, 992 const char *page, size_t count)
1042 const char *page,
1043 size_t count)
1044{ 993{
994 struct se_portal_group *se_tpg = to_tpg(item);
1045 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn; 995 struct se_wwn *se_wwn = se_tpg->se_tpg_wwn;
1046 struct tcm_qla2xxx_lport *lport = container_of(se_wwn, 996 struct tcm_qla2xxx_lport *lport = container_of(se_wwn,
1047 struct tcm_qla2xxx_lport, lport_wwn); 997 struct tcm_qla2xxx_lport, lport_wwn);
@@ -1077,10 +1027,10 @@ static ssize_t tcm_qla2xxx_npiv_tpg_store_enable(
1077 return count; 1027 return count;
1078} 1028}
1079 1029
1080TF_TPG_BASE_ATTR(tcm_qla2xxx_npiv, enable, S_IRUGO | S_IWUSR); 1030CONFIGFS_ATTR(tcm_qla2xxx_npiv_tpg_, enable);
1081 1031
1082static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = { 1032static struct configfs_attribute *tcm_qla2xxx_npiv_tpg_attrs[] = {
1083 &tcm_qla2xxx_npiv_tpg_enable.attr, 1033 &tcm_qla2xxx_npiv_tpg_attr_enable,
1084 NULL, 1034 NULL,
1085}; 1035};
1086 1036
@@ -1783,9 +1733,8 @@ static void tcm_qla2xxx_npiv_drop_lport(struct se_wwn *wwn)
1783} 1733}
1784 1734
1785 1735
1786static ssize_t tcm_qla2xxx_wwn_show_attr_version( 1736static ssize_t tcm_qla2xxx_wwn_version_show(struct config_item *item,
1787 struct target_fabric_configfs *tf, 1737 char *page)
1788 char *page)
1789{ 1738{
1790 return sprintf(page, 1739 return sprintf(page,
1791 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on " 1740 "TCM QLOGIC QLA2XXX NPIV capable fabric module %s on %s/%s on "
@@ -1793,10 +1742,10 @@ static ssize_t tcm_qla2xxx_wwn_show_attr_version(
1793 utsname()->machine); 1742 utsname()->machine);
1794} 1743}
1795 1744
1796TF_WWN_ATTR_RO(tcm_qla2xxx, version); 1745CONFIGFS_ATTR_RO(tcm_qla2xxx_wwn_, version);
1797 1746
1798static struct configfs_attribute *tcm_qla2xxx_wwn_attrs[] = { 1747static struct configfs_attribute *tcm_qla2xxx_wwn_attrs[] = {
1799 &tcm_qla2xxx_wwn_version.attr, 1748 &tcm_qla2xxx_wwn_attr_version,
1800 NULL, 1749 NULL,
1801}; 1750};
1802 1751
diff --git a/drivers/target/iscsi/iscsi_target_configfs.c b/drivers/target/iscsi/iscsi_target_configfs.c
index c7461d770d3a..255204cc43e6 100644
--- a/drivers/target/iscsi/iscsi_target_configfs.c
+++ b/drivers/target/iscsi/iscsi_target_configfs.c
@@ -23,8 +23,6 @@
23#include <linux/inet.h> 23#include <linux/inet.h>
24#include <target/target_core_base.h> 24#include <target/target_core_base.h>
25#include <target/target_core_fabric.h> 25#include <target/target_core_fabric.h>
26#include <target/target_core_fabric_configfs.h>
27#include <target/configfs_macros.h>
28#include <target/iscsi/iscsi_transport.h> 26#include <target/iscsi/iscsi_transport.h>
29 27
30#include <target/iscsi/iscsi_target_core.h> 28#include <target/iscsi/iscsi_target_core.h>
@@ -37,20 +35,17 @@
37#include "iscsi_target.h" 35#include "iscsi_target.h"
38#include <target/iscsi/iscsi_target_stat.h> 36#include <target/iscsi/iscsi_target_stat.h>
39 37
40struct lio_target_configfs_attribute {
41 struct configfs_attribute attr;
42 ssize_t (*show)(void *, char *);
43 ssize_t (*store)(void *, const char *, size_t);
44};
45 38
46/* Start items for lio_target_portal_cit */ 39/* Start items for lio_target_portal_cit */
47 40
48static ssize_t lio_target_np_show_sctp( 41static inline struct iscsi_tpg_np *to_iscsi_tpg_np(struct config_item *item)
49 struct se_tpg_np *se_tpg_np, 42{
50 char *page) 43 return container_of(to_tpg_np(item), struct iscsi_tpg_np, se_tpg_np);
44}
45
46static ssize_t lio_target_np_sctp_show(struct config_item *item, char *page)
51{ 47{
52 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 48 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
53 struct iscsi_tpg_np, se_tpg_np);
54 struct iscsi_tpg_np *tpg_np_sctp; 49 struct iscsi_tpg_np *tpg_np_sctp;
55 ssize_t rb; 50 ssize_t rb;
56 51
@@ -63,15 +58,12 @@ static ssize_t lio_target_np_show_sctp(
63 return rb; 58 return rb;
64} 59}
65 60
66static ssize_t lio_target_np_store_sctp( 61static ssize_t lio_target_np_sctp_store(struct config_item *item,
67 struct se_tpg_np *se_tpg_np, 62 const char *page, size_t count)
68 const char *page,
69 size_t count)
70{ 63{
64 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
71 struct iscsi_np *np; 65 struct iscsi_np *np;
72 struct iscsi_portal_group *tpg; 66 struct iscsi_portal_group *tpg;
73 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
74 struct iscsi_tpg_np, se_tpg_np);
75 struct iscsi_tpg_np *tpg_np_sctp = NULL; 67 struct iscsi_tpg_np *tpg_np_sctp = NULL;
76 u32 op; 68 u32 op;
77 int ret; 69 int ret;
@@ -119,14 +111,9 @@ out:
119 return -EINVAL; 111 return -EINVAL;
120} 112}
121 113
122TF_NP_BASE_ATTR(lio_target, sctp, S_IRUGO | S_IWUSR); 114static ssize_t lio_target_np_iser_show(struct config_item *item, char *page)
123
124static ssize_t lio_target_np_show_iser(
125 struct se_tpg_np *se_tpg_np,
126 char *page)
127{ 115{
128 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np, 116 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
129 struct iscsi_tpg_np, se_tpg_np);
130 struct iscsi_tpg_np *tpg_np_iser; 117 struct iscsi_tpg_np *tpg_np_iser;
131 ssize_t rb; 118 ssize_t rb;
132 119
@@ -139,15 +126,12 @@ static ssize_t lio_target_np_show_iser(
139 return rb; 126 return rb;
140} 127}
141 128
142static ssize_t lio_target_np_store_iser( 129static ssize_t lio_target_np_iser_store(struct config_item *item,
143 struct se_tpg_np *se_tpg_np, 130 const char *page, size_t count)
144 const char *page,
145 size_t count)
146{ 131{
132 struct iscsi_tpg_np *tpg_np = to_iscsi_tpg_np(item);
147 struct iscsi_np *np; 133 struct iscsi_np *np;
148 struct iscsi_portal_group *tpg; 134 struct iscsi_portal_group *tpg;
149 struct iscsi_tpg_np *tpg_np = container_of(se_tpg_np,
150 struct iscsi_tpg_np, se_tpg_np);
151 struct iscsi_tpg_np *tpg_np_iser = NULL; 135 struct iscsi_tpg_np *tpg_np_iser = NULL;
152 char *endptr; 136 char *endptr;
153 u32 op; 137 u32 op;
@@ -198,11 +182,12 @@ out:
198 return rc; 182 return rc;
199} 183}
200 184
201TF_NP_BASE_ATTR(lio_target, iser, S_IRUGO | S_IWUSR); 185CONFIGFS_ATTR(lio_target_np_, sctp);
186CONFIGFS_ATTR(lio_target_np_, iser);
202 187
203static struct configfs_attribute *lio_target_portal_attrs[] = { 188static struct configfs_attribute *lio_target_portal_attrs[] = {
204 &lio_target_np_sctp.attr, 189 &lio_target_np_attr_sctp,
205 &lio_target_np_iser.attr, 190 &lio_target_np_attr_iser,
206 NULL, 191 NULL,
207}; 192};
208 193
@@ -360,22 +345,21 @@ out:
360 345
361/* Start items for lio_target_nacl_attrib_cit */ 346/* Start items for lio_target_nacl_attrib_cit */
362 347
363#define DEF_NACL_ATTRIB(name) \ 348#define ISCSI_NACL_ATTR(name) \
364static ssize_t iscsi_nacl_attrib_show_##name( \ 349static ssize_t iscsi_nacl_attrib_##name##_show(struct config_item *item,\
365 struct se_node_acl *se_nacl, \ 350 char *page) \
366 char *page) \
367{ \ 351{ \
352 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
368 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 353 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
369 se_node_acl); \ 354 se_node_acl); \
370 \ 355 \
371 return sprintf(page, "%u\n", nacl->node_attrib.name); \ 356 return sprintf(page, "%u\n", nacl->node_attrib.name); \
372} \ 357} \
373 \ 358 \
374static ssize_t iscsi_nacl_attrib_store_##name( \ 359static ssize_t iscsi_nacl_attrib_##name##_store(struct config_item *item,\
375 struct se_node_acl *se_nacl, \ 360 const char *page, size_t count) \
376 const char *page, \
377 size_t count) \
378{ \ 361{ \
362 struct se_node_acl *se_nacl = attrib_to_nacl(item); \
379 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \ 363 struct iscsi_node_acl *nacl = container_of(se_nacl, struct iscsi_node_acl, \
380 se_node_acl); \ 364 se_node_acl); \
381 u32 val; \ 365 u32 val; \
@@ -389,59 +373,28 @@ static ssize_t iscsi_nacl_attrib_store_##name( \
389 return ret; \ 373 return ret; \
390 \ 374 \
391 return count; \ 375 return count; \
392} 376} \
377 \
378CONFIGFS_ATTR(iscsi_nacl_attrib_, name)
393 379
394#define NACL_ATTR(_name, _mode) TF_NACL_ATTRIB_ATTR(iscsi, _name, _mode); 380ISCSI_NACL_ATTR(dataout_timeout);
395/* 381ISCSI_NACL_ATTR(dataout_timeout_retries);
396 * Define iscsi_node_attrib_s_dataout_timeout 382ISCSI_NACL_ATTR(default_erl);
397 */ 383ISCSI_NACL_ATTR(nopin_timeout);
398DEF_NACL_ATTRIB(dataout_timeout); 384ISCSI_NACL_ATTR(nopin_response_timeout);
399NACL_ATTR(dataout_timeout, S_IRUGO | S_IWUSR); 385ISCSI_NACL_ATTR(random_datain_pdu_offsets);
400/* 386ISCSI_NACL_ATTR(random_datain_seq_offsets);
401 * Define iscsi_node_attrib_s_dataout_timeout_retries 387ISCSI_NACL_ATTR(random_r2t_offsets);
402 */
403DEF_NACL_ATTRIB(dataout_timeout_retries);
404NACL_ATTR(dataout_timeout_retries, S_IRUGO | S_IWUSR);
405/*
406 * Define iscsi_node_attrib_s_default_erl
407 */
408DEF_NACL_ATTRIB(default_erl);
409NACL_ATTR(default_erl, S_IRUGO | S_IWUSR);
410/*
411 * Define iscsi_node_attrib_s_nopin_timeout
412 */
413DEF_NACL_ATTRIB(nopin_timeout);
414NACL_ATTR(nopin_timeout, S_IRUGO | S_IWUSR);
415/*
416 * Define iscsi_node_attrib_s_nopin_response_timeout
417 */
418DEF_NACL_ATTRIB(nopin_response_timeout);
419NACL_ATTR(nopin_response_timeout, S_IRUGO | S_IWUSR);
420/*
421 * Define iscsi_node_attrib_s_random_datain_pdu_offsets
422 */
423DEF_NACL_ATTRIB(random_datain_pdu_offsets);
424NACL_ATTR(random_datain_pdu_offsets, S_IRUGO | S_IWUSR);
425/*
426 * Define iscsi_node_attrib_s_random_datain_seq_offsets
427 */
428DEF_NACL_ATTRIB(random_datain_seq_offsets);
429NACL_ATTR(random_datain_seq_offsets, S_IRUGO | S_IWUSR);
430/*
431 * Define iscsi_node_attrib_s_random_r2t_offsets
432 */
433DEF_NACL_ATTRIB(random_r2t_offsets);
434NACL_ATTR(random_r2t_offsets, S_IRUGO | S_IWUSR);
435 388
436static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = { 389static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
437 &iscsi_nacl_attrib_dataout_timeout.attr, 390 &iscsi_nacl_attrib_attr_dataout_timeout,
438 &iscsi_nacl_attrib_dataout_timeout_retries.attr, 391 &iscsi_nacl_attrib_attr_dataout_timeout_retries,
439 &iscsi_nacl_attrib_default_erl.attr, 392 &iscsi_nacl_attrib_attr_default_erl,
440 &iscsi_nacl_attrib_nopin_timeout.attr, 393 &iscsi_nacl_attrib_attr_nopin_timeout,
441 &iscsi_nacl_attrib_nopin_response_timeout.attr, 394 &iscsi_nacl_attrib_attr_nopin_response_timeout,
442 &iscsi_nacl_attrib_random_datain_pdu_offsets.attr, 395 &iscsi_nacl_attrib_attr_random_datain_pdu_offsets,
443 &iscsi_nacl_attrib_random_datain_seq_offsets.attr, 396 &iscsi_nacl_attrib_attr_random_datain_seq_offsets,
444 &iscsi_nacl_attrib_random_r2t_offsets.attr, 397 &iscsi_nacl_attrib_attr_random_r2t_offsets,
445 NULL, 398 NULL,
446}; 399};
447 400
@@ -450,7 +403,7 @@ static struct configfs_attribute *lio_target_nacl_attrib_attrs[] = {
450/* Start items for lio_target_nacl_auth_cit */ 403/* Start items for lio_target_nacl_auth_cit */
451 404
452#define __DEF_NACL_AUTH_STR(prefix, name, flags) \ 405#define __DEF_NACL_AUTH_STR(prefix, name, flags) \
453static ssize_t __iscsi_##prefix##_show_##name( \ 406static ssize_t __iscsi_##prefix##_##name##_show( \
454 struct iscsi_node_acl *nacl, \ 407 struct iscsi_node_acl *nacl, \
455 char *page) \ 408 char *page) \
456{ \ 409{ \
@@ -461,7 +414,7 @@ static ssize_t __iscsi_##prefix##_show_##name( \
461 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 414 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
462} \ 415} \
463 \ 416 \
464static ssize_t __iscsi_##prefix##_store_##name( \ 417static ssize_t __iscsi_##prefix##_##name##_store( \
465 struct iscsi_node_acl *nacl, \ 418 struct iscsi_node_acl *nacl, \
466 const char *page, \ 419 const char *page, \
467 size_t count) \ 420 size_t count) \
@@ -487,8 +440,35 @@ static ssize_t __iscsi_##prefix##_store_##name( \
487 return count; \ 440 return count; \
488} 441}
489 442
443#define DEF_NACL_AUTH_STR(name, flags) \
444 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
445static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
446 char *page) \
447{ \
448 struct se_node_acl *nacl = auth_to_nacl(item); \
449 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
450 struct iscsi_node_acl, se_node_acl), page); \
451} \
452static ssize_t iscsi_nacl_auth_##name##_store(struct config_item *item, \
453 const char *page, size_t count) \
454{ \
455 struct se_node_acl *nacl = auth_to_nacl(item); \
456 return __iscsi_nacl_auth_##name##_store(container_of(nacl, \
457 struct iscsi_node_acl, se_node_acl), page, count); \
458} \
459 \
460CONFIGFS_ATTR(iscsi_nacl_auth_, name)
461
462/*
463 * One-way authentication userid
464 */
465DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
466DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
467DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
468DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
469
490#define __DEF_NACL_AUTH_INT(prefix, name) \ 470#define __DEF_NACL_AUTH_INT(prefix, name) \
491static ssize_t __iscsi_##prefix##_show_##name( \ 471static ssize_t __iscsi_##prefix##_##name##_show( \
492 struct iscsi_node_acl *nacl, \ 472 struct iscsi_node_acl *nacl, \
493 char *page) \ 473 char *page) \
494{ \ 474{ \
@@ -500,69 +480,26 @@ static ssize_t __iscsi_##prefix##_show_##name( \
500 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 480 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
501} 481}
502 482
503#define DEF_NACL_AUTH_STR(name, flags) \
504 __DEF_NACL_AUTH_STR(nacl_auth, name, flags) \
505static ssize_t iscsi_nacl_auth_show_##name( \
506 struct se_node_acl *nacl, \
507 char *page) \
508{ \
509 return __iscsi_nacl_auth_show_##name(container_of(nacl, \
510 struct iscsi_node_acl, se_node_acl), page); \
511} \
512static ssize_t iscsi_nacl_auth_store_##name( \
513 struct se_node_acl *nacl, \
514 const char *page, \
515 size_t count) \
516{ \
517 return __iscsi_nacl_auth_store_##name(container_of(nacl, \
518 struct iscsi_node_acl, se_node_acl), page, count); \
519}
520
521#define DEF_NACL_AUTH_INT(name) \ 483#define DEF_NACL_AUTH_INT(name) \
522 __DEF_NACL_AUTH_INT(nacl_auth, name) \ 484 __DEF_NACL_AUTH_INT(nacl_auth, name) \
523static ssize_t iscsi_nacl_auth_show_##name( \ 485static ssize_t iscsi_nacl_auth_##name##_show(struct config_item *item, \
524 struct se_node_acl *nacl, \ 486 char *page) \
525 char *page) \
526{ \ 487{ \
527 return __iscsi_nacl_auth_show_##name(container_of(nacl, \ 488 struct se_node_acl *nacl = auth_to_nacl(item); \
528 struct iscsi_node_acl, se_node_acl), page); \ 489 return __iscsi_nacl_auth_##name##_show(container_of(nacl, \
529} 490 struct iscsi_node_acl, se_node_acl), page); \
530 491} \
531#define AUTH_ATTR(_name, _mode) TF_NACL_AUTH_ATTR(iscsi, _name, _mode); 492 \
532#define AUTH_ATTR_RO(_name) TF_NACL_AUTH_ATTR_RO(iscsi, _name); 493CONFIGFS_ATTR_RO(iscsi_nacl_auth_, name)
533 494
534/*
535 * One-way authentication userid
536 */
537DEF_NACL_AUTH_STR(userid, NAF_USERID_SET);
538AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
539/*
540 * One-way authentication password
541 */
542DEF_NACL_AUTH_STR(password, NAF_PASSWORD_SET);
543AUTH_ATTR(password, S_IRUGO | S_IWUSR);
544/*
545 * Enforce mutual authentication
546 */
547DEF_NACL_AUTH_INT(authenticate_target); 495DEF_NACL_AUTH_INT(authenticate_target);
548AUTH_ATTR_RO(authenticate_target);
549/*
550 * Mutual authentication userid
551 */
552DEF_NACL_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
553AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
554/*
555 * Mutual authentication password
556 */
557DEF_NACL_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
558AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
559 496
560static struct configfs_attribute *lio_target_nacl_auth_attrs[] = { 497static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
561 &iscsi_nacl_auth_userid.attr, 498 &iscsi_nacl_auth_attr_userid,
562 &iscsi_nacl_auth_password.attr, 499 &iscsi_nacl_auth_attr_password,
563 &iscsi_nacl_auth_authenticate_target.attr, 500 &iscsi_nacl_auth_attr_authenticate_target,
564 &iscsi_nacl_auth_userid_mutual.attr, 501 &iscsi_nacl_auth_attr_userid_mutual,
565 &iscsi_nacl_auth_password_mutual.attr, 502 &iscsi_nacl_auth_attr_password_mutual,
566 NULL, 503 NULL,
567}; 504};
568 505
@@ -570,11 +507,11 @@ static struct configfs_attribute *lio_target_nacl_auth_attrs[] = {
570 507
571/* Start items for lio_target_nacl_param_cit */ 508/* Start items for lio_target_nacl_param_cit */
572 509
573#define DEF_NACL_PARAM(name) \ 510#define ISCSI_NACL_PARAM(name) \
574static ssize_t iscsi_nacl_param_show_##name( \ 511static ssize_t iscsi_nacl_param_##name##_show(struct config_item *item, \
575 struct se_node_acl *se_nacl, \ 512 char *page) \
576 char *page) \
577{ \ 513{ \
514 struct se_node_acl *se_nacl = param_to_nacl(item); \
578 struct iscsi_session *sess; \ 515 struct iscsi_session *sess; \
579 struct se_session *se_sess; \ 516 struct se_session *se_sess; \
580 ssize_t rb; \ 517 ssize_t rb; \
@@ -592,55 +529,34 @@ static ssize_t iscsi_nacl_param_show_##name( \
592 spin_unlock_bh(&se_nacl->nacl_sess_lock); \ 529 spin_unlock_bh(&se_nacl->nacl_sess_lock); \
593 \ 530 \
594 return rb; \ 531 return rb; \
595} 532} \
596 533 \
597#define NACL_PARAM_ATTR(_name) TF_NACL_PARAM_ATTR_RO(iscsi, _name); 534CONFIGFS_ATTR_RO(iscsi_nacl_param_, name)
598 535
599DEF_NACL_PARAM(MaxConnections); 536ISCSI_NACL_PARAM(MaxConnections);
600NACL_PARAM_ATTR(MaxConnections); 537ISCSI_NACL_PARAM(InitialR2T);
601 538ISCSI_NACL_PARAM(ImmediateData);
602DEF_NACL_PARAM(InitialR2T); 539ISCSI_NACL_PARAM(MaxBurstLength);
603NACL_PARAM_ATTR(InitialR2T); 540ISCSI_NACL_PARAM(FirstBurstLength);
604 541ISCSI_NACL_PARAM(DefaultTime2Wait);
605DEF_NACL_PARAM(ImmediateData); 542ISCSI_NACL_PARAM(DefaultTime2Retain);
606NACL_PARAM_ATTR(ImmediateData); 543ISCSI_NACL_PARAM(MaxOutstandingR2T);
607 544ISCSI_NACL_PARAM(DataPDUInOrder);
608DEF_NACL_PARAM(MaxBurstLength); 545ISCSI_NACL_PARAM(DataSequenceInOrder);
609NACL_PARAM_ATTR(MaxBurstLength); 546ISCSI_NACL_PARAM(ErrorRecoveryLevel);
610
611DEF_NACL_PARAM(FirstBurstLength);
612NACL_PARAM_ATTR(FirstBurstLength);
613
614DEF_NACL_PARAM(DefaultTime2Wait);
615NACL_PARAM_ATTR(DefaultTime2Wait);
616
617DEF_NACL_PARAM(DefaultTime2Retain);
618NACL_PARAM_ATTR(DefaultTime2Retain);
619
620DEF_NACL_PARAM(MaxOutstandingR2T);
621NACL_PARAM_ATTR(MaxOutstandingR2T);
622
623DEF_NACL_PARAM(DataPDUInOrder);
624NACL_PARAM_ATTR(DataPDUInOrder);
625
626DEF_NACL_PARAM(DataSequenceInOrder);
627NACL_PARAM_ATTR(DataSequenceInOrder);
628
629DEF_NACL_PARAM(ErrorRecoveryLevel);
630NACL_PARAM_ATTR(ErrorRecoveryLevel);
631 547
632static struct configfs_attribute *lio_target_nacl_param_attrs[] = { 548static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
633 &iscsi_nacl_param_MaxConnections.attr, 549 &iscsi_nacl_param_attr_MaxConnections,
634 &iscsi_nacl_param_InitialR2T.attr, 550 &iscsi_nacl_param_attr_InitialR2T,
635 &iscsi_nacl_param_ImmediateData.attr, 551 &iscsi_nacl_param_attr_ImmediateData,
636 &iscsi_nacl_param_MaxBurstLength.attr, 552 &iscsi_nacl_param_attr_MaxBurstLength,
637 &iscsi_nacl_param_FirstBurstLength.attr, 553 &iscsi_nacl_param_attr_FirstBurstLength,
638 &iscsi_nacl_param_DefaultTime2Wait.attr, 554 &iscsi_nacl_param_attr_DefaultTime2Wait,
639 &iscsi_nacl_param_DefaultTime2Retain.attr, 555 &iscsi_nacl_param_attr_DefaultTime2Retain,
640 &iscsi_nacl_param_MaxOutstandingR2T.attr, 556 &iscsi_nacl_param_attr_MaxOutstandingR2T,
641 &iscsi_nacl_param_DataPDUInOrder.attr, 557 &iscsi_nacl_param_attr_DataPDUInOrder,
642 &iscsi_nacl_param_DataSequenceInOrder.attr, 558 &iscsi_nacl_param_attr_DataSequenceInOrder,
643 &iscsi_nacl_param_ErrorRecoveryLevel.attr, 559 &iscsi_nacl_param_attr_ErrorRecoveryLevel,
644 NULL, 560 NULL,
645}; 561};
646 562
@@ -648,10 +564,9 @@ static struct configfs_attribute *lio_target_nacl_param_attrs[] = {
648 564
649/* Start items for lio_target_acl_cit */ 565/* Start items for lio_target_acl_cit */
650 566
651static ssize_t lio_target_nacl_show_info( 567static ssize_t lio_target_nacl_info_show(struct config_item *item, char *page)
652 struct se_node_acl *se_nacl,
653 char *page)
654{ 568{
569 struct se_node_acl *se_nacl = acl_to_nacl(item);
655 struct iscsi_session *sess; 570 struct iscsi_session *sess;
656 struct iscsi_conn *conn; 571 struct iscsi_conn *conn;
657 struct se_session *se_sess; 572 struct se_session *se_sess;
@@ -766,20 +681,16 @@ static ssize_t lio_target_nacl_show_info(
766 return rb; 681 return rb;
767} 682}
768 683
769TF_NACL_BASE_ATTR_RO(lio_target, info); 684static ssize_t lio_target_nacl_cmdsn_depth_show(struct config_item *item,
770 685 char *page)
771static ssize_t lio_target_nacl_show_cmdsn_depth(
772 struct se_node_acl *se_nacl,
773 char *page)
774{ 686{
775 return sprintf(page, "%u\n", se_nacl->queue_depth); 687 return sprintf(page, "%u\n", acl_to_nacl(item)->queue_depth);
776} 688}
777 689
778static ssize_t lio_target_nacl_store_cmdsn_depth( 690static ssize_t lio_target_nacl_cmdsn_depth_store(struct config_item *item,
779 struct se_node_acl *se_nacl, 691 const char *page, size_t count)
780 const char *page,
781 size_t count)
782{ 692{
693 struct se_node_acl *se_nacl = acl_to_nacl(item);
783 struct se_portal_group *se_tpg = se_nacl->se_tpg; 694 struct se_portal_group *se_tpg = se_nacl->se_tpg;
784 struct iscsi_portal_group *tpg = container_of(se_tpg, 695 struct iscsi_portal_group *tpg = container_of(se_tpg,
785 struct iscsi_portal_group, tpg_se_tpg); 696 struct iscsi_portal_group, tpg_se_tpg);
@@ -829,20 +740,15 @@ static ssize_t lio_target_nacl_store_cmdsn_depth(
829 return (!ret) ? count : (ssize_t)ret; 740 return (!ret) ? count : (ssize_t)ret;
830} 741}
831 742
832TF_NACL_BASE_ATTR(lio_target, cmdsn_depth, S_IRUGO | S_IWUSR); 743static ssize_t lio_target_nacl_tag_show(struct config_item *item, char *page)
833
834static ssize_t lio_target_nacl_show_tag(
835 struct se_node_acl *se_nacl,
836 char *page)
837{ 744{
838 return snprintf(page, PAGE_SIZE, "%s", se_nacl->acl_tag); 745 return snprintf(page, PAGE_SIZE, "%s", acl_to_nacl(item)->acl_tag);
839} 746}
840 747
841static ssize_t lio_target_nacl_store_tag( 748static ssize_t lio_target_nacl_tag_store(struct config_item *item,
842 struct se_node_acl *se_nacl, 749 const char *page, size_t count)
843 const char *page,
844 size_t count)
845{ 750{
751 struct se_node_acl *se_nacl = acl_to_nacl(item);
846 int ret; 752 int ret;
847 753
848 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page); 754 ret = core_tpg_set_initiator_node_tag(se_nacl->se_tpg, se_nacl, page);
@@ -852,12 +758,14 @@ static ssize_t lio_target_nacl_store_tag(
852 return count; 758 return count;
853} 759}
854 760
855TF_NACL_BASE_ATTR(lio_target, tag, S_IRUGO | S_IWUSR); 761CONFIGFS_ATTR_RO(lio_target_nacl_, info);
762CONFIGFS_ATTR(lio_target_nacl_, cmdsn_depth);
763CONFIGFS_ATTR(lio_target_nacl_, tag);
856 764
857static struct configfs_attribute *lio_target_initiator_attrs[] = { 765static struct configfs_attribute *lio_target_initiator_attrs[] = {
858 &lio_target_nacl_info.attr, 766 &lio_target_nacl_attr_info,
859 &lio_target_nacl_cmdsn_depth.attr, 767 &lio_target_nacl_attr_cmdsn_depth,
860 &lio_target_nacl_tag.attr, 768 &lio_target_nacl_attr_tag,
861 NULL, 769 NULL,
862}; 770};
863 771
@@ -907,10 +815,10 @@ static void lio_target_cleanup_nodeacl( struct se_node_acl *se_nacl)
907 815
908#define DEF_TPG_ATTRIB(name) \ 816#define DEF_TPG_ATTRIB(name) \
909 \ 817 \
910static ssize_t iscsi_tpg_attrib_show_##name( \ 818static ssize_t iscsi_tpg_attrib_##name##_show(struct config_item *item, \
911 struct se_portal_group *se_tpg, \ 819 char *page) \
912 char *page) \
913{ \ 820{ \
821 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
914 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 822 struct iscsi_portal_group *tpg = container_of(se_tpg, \
915 struct iscsi_portal_group, tpg_se_tpg); \ 823 struct iscsi_portal_group, tpg_se_tpg); \
916 ssize_t rb; \ 824 ssize_t rb; \
@@ -923,11 +831,10 @@ static ssize_t iscsi_tpg_attrib_show_##name( \
923 return rb; \ 831 return rb; \
924} \ 832} \
925 \ 833 \
926static ssize_t iscsi_tpg_attrib_store_##name( \ 834static ssize_t iscsi_tpg_attrib_##name##_store(struct config_item *item,\
927 struct se_portal_group *se_tpg, \ 835 const char *page, size_t count) \
928 const char *page, \
929 size_t count) \
930{ \ 836{ \
837 struct se_portal_group *se_tpg = attrib_to_tpg(item); \
931 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 838 struct iscsi_portal_group *tpg = container_of(se_tpg, \
932 struct iscsi_portal_group, tpg_se_tpg); \ 839 struct iscsi_portal_group, tpg_se_tpg); \
933 u32 val; \ 840 u32 val; \
@@ -948,90 +855,37 @@ static ssize_t iscsi_tpg_attrib_store_##name( \
948out: \ 855out: \
949 iscsit_put_tpg(tpg); \ 856 iscsit_put_tpg(tpg); \
950 return ret; \ 857 return ret; \
951} 858} \
952 859CONFIGFS_ATTR(iscsi_tpg_attrib_, name)
953#define TPG_ATTR(_name, _mode) TF_TPG_ATTRIB_ATTR(iscsi, _name, _mode);
954 860
955/*
956 * Define iscsi_tpg_attrib_s_authentication
957 */
958DEF_TPG_ATTRIB(authentication); 861DEF_TPG_ATTRIB(authentication);
959TPG_ATTR(authentication, S_IRUGO | S_IWUSR);
960/*
961 * Define iscsi_tpg_attrib_s_login_timeout
962 */
963DEF_TPG_ATTRIB(login_timeout); 862DEF_TPG_ATTRIB(login_timeout);
964TPG_ATTR(login_timeout, S_IRUGO | S_IWUSR);
965/*
966 * Define iscsi_tpg_attrib_s_netif_timeout
967 */
968DEF_TPG_ATTRIB(netif_timeout); 863DEF_TPG_ATTRIB(netif_timeout);
969TPG_ATTR(netif_timeout, S_IRUGO | S_IWUSR);
970/*
971 * Define iscsi_tpg_attrib_s_generate_node_acls
972 */
973DEF_TPG_ATTRIB(generate_node_acls); 864DEF_TPG_ATTRIB(generate_node_acls);
974TPG_ATTR(generate_node_acls, S_IRUGO | S_IWUSR);
975/*
976 * Define iscsi_tpg_attrib_s_default_cmdsn_depth
977 */
978DEF_TPG_ATTRIB(default_cmdsn_depth); 865DEF_TPG_ATTRIB(default_cmdsn_depth);
979TPG_ATTR(default_cmdsn_depth, S_IRUGO | S_IWUSR);
980/*
981 Define iscsi_tpg_attrib_s_cache_dynamic_acls
982 */
983DEF_TPG_ATTRIB(cache_dynamic_acls); 866DEF_TPG_ATTRIB(cache_dynamic_acls);
984TPG_ATTR(cache_dynamic_acls, S_IRUGO | S_IWUSR);
985/*
986 * Define iscsi_tpg_attrib_s_demo_mode_write_protect
987 */
988DEF_TPG_ATTRIB(demo_mode_write_protect); 867DEF_TPG_ATTRIB(demo_mode_write_protect);
989TPG_ATTR(demo_mode_write_protect, S_IRUGO | S_IWUSR);
990/*
991 * Define iscsi_tpg_attrib_s_prod_mode_write_protect
992 */
993DEF_TPG_ATTRIB(prod_mode_write_protect); 868DEF_TPG_ATTRIB(prod_mode_write_protect);
994TPG_ATTR(prod_mode_write_protect, S_IRUGO | S_IWUSR);
995/*
996 * Define iscsi_tpg_attrib_s_demo_mode_discovery,
997 */
998DEF_TPG_ATTRIB(demo_mode_discovery); 869DEF_TPG_ATTRIB(demo_mode_discovery);
999TPG_ATTR(demo_mode_discovery, S_IRUGO | S_IWUSR);
1000/*
1001 * Define iscsi_tpg_attrib_s_default_erl
1002 */
1003DEF_TPG_ATTRIB(default_erl); 870DEF_TPG_ATTRIB(default_erl);
1004TPG_ATTR(default_erl, S_IRUGO | S_IWUSR);
1005/*
1006 * Define iscsi_tpg_attrib_s_t10_pi
1007 */
1008DEF_TPG_ATTRIB(t10_pi); 871DEF_TPG_ATTRIB(t10_pi);
1009TPG_ATTR(t10_pi, S_IRUGO | S_IWUSR);
1010/*
1011 * Define iscsi_tpg_attrib_s_fabric_prot_type
1012 */
1013DEF_TPG_ATTRIB(fabric_prot_type); 872DEF_TPG_ATTRIB(fabric_prot_type);
1014TPG_ATTR(fabric_prot_type, S_IRUGO | S_IWUSR);
1015/*
1016 * Define iscsi_tpg_attrib_s_tpg_enabled_sendtargets
1017 */
1018DEF_TPG_ATTRIB(tpg_enabled_sendtargets); 873DEF_TPG_ATTRIB(tpg_enabled_sendtargets);
1019TPG_ATTR(tpg_enabled_sendtargets, S_IRUGO | S_IWUSR);
1020 874
1021static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = { 875static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
1022 &iscsi_tpg_attrib_authentication.attr, 876 &iscsi_tpg_attrib_attr_authentication,
1023 &iscsi_tpg_attrib_login_timeout.attr, 877 &iscsi_tpg_attrib_attr_login_timeout,
1024 &iscsi_tpg_attrib_netif_timeout.attr, 878 &iscsi_tpg_attrib_attr_netif_timeout,
1025 &iscsi_tpg_attrib_generate_node_acls.attr, 879 &iscsi_tpg_attrib_attr_generate_node_acls,
1026 &iscsi_tpg_attrib_default_cmdsn_depth.attr, 880 &iscsi_tpg_attrib_attr_default_cmdsn_depth,
1027 &iscsi_tpg_attrib_cache_dynamic_acls.attr, 881 &iscsi_tpg_attrib_attr_cache_dynamic_acls,
1028 &iscsi_tpg_attrib_demo_mode_write_protect.attr, 882 &iscsi_tpg_attrib_attr_demo_mode_write_protect,
1029 &iscsi_tpg_attrib_prod_mode_write_protect.attr, 883 &iscsi_tpg_attrib_attr_prod_mode_write_protect,
1030 &iscsi_tpg_attrib_demo_mode_discovery.attr, 884 &iscsi_tpg_attrib_attr_demo_mode_discovery,
1031 &iscsi_tpg_attrib_default_erl.attr, 885 &iscsi_tpg_attrib_attr_default_erl,
1032 &iscsi_tpg_attrib_t10_pi.attr, 886 &iscsi_tpg_attrib_attr_t10_pi,
1033 &iscsi_tpg_attrib_fabric_prot_type.attr, 887 &iscsi_tpg_attrib_attr_fabric_prot_type,
1034 &iscsi_tpg_attrib_tpg_enabled_sendtargets.attr, 888 &iscsi_tpg_attrib_attr_tpg_enabled_sendtargets,
1035 NULL, 889 NULL,
1036}; 890};
1037 891
@@ -1040,9 +894,8 @@ static struct configfs_attribute *lio_target_tpg_attrib_attrs[] = {
1040/* Start items for lio_target_tpg_auth_cit */ 894/* Start items for lio_target_tpg_auth_cit */
1041 895
1042#define __DEF_TPG_AUTH_STR(prefix, name, flags) \ 896#define __DEF_TPG_AUTH_STR(prefix, name, flags) \
1043static ssize_t __iscsi_##prefix##_show_##name( \ 897static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
1044 struct se_portal_group *se_tpg, \ 898 char *page) \
1045 char *page) \
1046{ \ 899{ \
1047 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 900 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1048 struct iscsi_portal_group, tpg_se_tpg); \ 901 struct iscsi_portal_group, tpg_se_tpg); \
@@ -1054,10 +907,8 @@ static ssize_t __iscsi_##prefix##_show_##name( \
1054 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \ 907 return snprintf(page, PAGE_SIZE, "%s\n", auth->name); \
1055} \ 908} \
1056 \ 909 \
1057static ssize_t __iscsi_##prefix##_store_##name( \ 910static ssize_t __iscsi_##prefix##_##name##_store(struct se_portal_group *se_tpg,\
1058 struct se_portal_group *se_tpg, \ 911 const char *page, size_t count) \
1059 const char *page, \
1060 size_t count) \
1061{ \ 912{ \
1062 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 913 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1063 struct iscsi_portal_group, tpg_se_tpg); \ 914 struct iscsi_portal_group, tpg_se_tpg); \
@@ -1081,10 +932,31 @@ static ssize_t __iscsi_##prefix##_store_##name( \
1081 return count; \ 932 return count; \
1082} 933}
1083 934
935#define DEF_TPG_AUTH_STR(name, flags) \
936 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
937static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
938 char *page) \
939{ \
940 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
941} \
942 \
943static ssize_t iscsi_tpg_auth_##name##_store(struct config_item *item, \
944 const char *page, size_t count) \
945{ \
946 return __iscsi_tpg_auth_##name##_store(auth_to_tpg(item), page, count); \
947} \
948 \
949CONFIGFS_ATTR(iscsi_tpg_auth_, name);
950
951
952DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
953DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
954DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
955DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
956
1084#define __DEF_TPG_AUTH_INT(prefix, name) \ 957#define __DEF_TPG_AUTH_INT(prefix, name) \
1085static ssize_t __iscsi_##prefix##_show_##name( \ 958static ssize_t __iscsi_##prefix##_##name##_show(struct se_portal_group *se_tpg, \
1086 struct se_portal_group *se_tpg, \ 959 char *page) \
1087 char *page) \
1088{ \ 960{ \
1089 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 961 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1090 struct iscsi_portal_group, tpg_se_tpg); \ 962 struct iscsi_portal_group, tpg_se_tpg); \
@@ -1096,67 +968,23 @@ static ssize_t __iscsi_##prefix##_show_##name( \
1096 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \ 968 return snprintf(page, PAGE_SIZE, "%d\n", auth->name); \
1097} 969}
1098 970
1099#define DEF_TPG_AUTH_STR(name, flags) \
1100 __DEF_TPG_AUTH_STR(tpg_auth, name, flags) \
1101static ssize_t iscsi_tpg_auth_show_##name( \
1102 struct se_portal_group *se_tpg, \
1103 char *page) \
1104{ \
1105 return __iscsi_tpg_auth_show_##name(se_tpg, page); \
1106} \
1107 \
1108static ssize_t iscsi_tpg_auth_store_##name( \
1109 struct se_portal_group *se_tpg, \
1110 const char *page, \
1111 size_t count) \
1112{ \
1113 return __iscsi_tpg_auth_store_##name(se_tpg, page, count); \
1114}
1115
1116#define DEF_TPG_AUTH_INT(name) \ 971#define DEF_TPG_AUTH_INT(name) \
1117 __DEF_TPG_AUTH_INT(tpg_auth, name) \ 972 __DEF_TPG_AUTH_INT(tpg_auth, name) \
1118static ssize_t iscsi_tpg_auth_show_##name( \ 973static ssize_t iscsi_tpg_auth_##name##_show(struct config_item *item, \
1119 struct se_portal_group *se_tpg, \ 974 char *page) \
1120 char *page) \
1121{ \ 975{ \
1122 return __iscsi_tpg_auth_show_##name(se_tpg, page); \ 976 return __iscsi_tpg_auth_##name##_show(auth_to_tpg(item), page); \
1123} 977} \
1124 978CONFIGFS_ATTR_RO(iscsi_tpg_auth_, name);
1125#define TPG_AUTH_ATTR(_name, _mode) TF_TPG_AUTH_ATTR(iscsi, _name, _mode);
1126#define TPG_AUTH_ATTR_RO(_name) TF_TPG_AUTH_ATTR_RO(iscsi, _name);
1127 979
1128/*
1129 * * One-way authentication userid
1130 * */
1131DEF_TPG_AUTH_STR(userid, NAF_USERID_SET);
1132TPG_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1133/*
1134 * * One-way authentication password
1135 * */
1136DEF_TPG_AUTH_STR(password, NAF_PASSWORD_SET);
1137TPG_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1138/*
1139 * * Enforce mutual authentication
1140 * */
1141DEF_TPG_AUTH_INT(authenticate_target); 980DEF_TPG_AUTH_INT(authenticate_target);
1142TPG_AUTH_ATTR_RO(authenticate_target);
1143/*
1144 * * Mutual authentication userid
1145 * */
1146DEF_TPG_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1147TPG_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1148/*
1149 * * Mutual authentication password
1150 * */
1151DEF_TPG_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1152TPG_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1153 981
1154static struct configfs_attribute *lio_target_tpg_auth_attrs[] = { 982static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
1155 &iscsi_tpg_auth_userid.attr, 983 &iscsi_tpg_auth_attr_userid,
1156 &iscsi_tpg_auth_password.attr, 984 &iscsi_tpg_auth_attr_password,
1157 &iscsi_tpg_auth_authenticate_target.attr, 985 &iscsi_tpg_auth_attr_authenticate_target,
1158 &iscsi_tpg_auth_userid_mutual.attr, 986 &iscsi_tpg_auth_attr_userid_mutual,
1159 &iscsi_tpg_auth_password_mutual.attr, 987 &iscsi_tpg_auth_attr_password_mutual,
1160 NULL, 988 NULL,
1161}; 989};
1162 990
@@ -1165,10 +993,10 @@ static struct configfs_attribute *lio_target_tpg_auth_attrs[] = {
1165/* Start items for lio_target_tpg_param_cit */ 993/* Start items for lio_target_tpg_param_cit */
1166 994
1167#define DEF_TPG_PARAM(name) \ 995#define DEF_TPG_PARAM(name) \
1168static ssize_t iscsi_tpg_param_show_##name( \ 996static ssize_t iscsi_tpg_param_##name##_show(struct config_item *item, \
1169 struct se_portal_group *se_tpg, \ 997 char *page) \
1170 char *page) \
1171{ \ 998{ \
999 struct se_portal_group *se_tpg = param_to_tpg(item); \
1172 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1000 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1173 struct iscsi_portal_group, tpg_se_tpg); \ 1001 struct iscsi_portal_group, tpg_se_tpg); \
1174 struct iscsi_param *param; \ 1002 struct iscsi_param *param; \
@@ -1188,11 +1016,10 @@ static ssize_t iscsi_tpg_param_show_##name( \
1188 iscsit_put_tpg(tpg); \ 1016 iscsit_put_tpg(tpg); \
1189 return rb; \ 1017 return rb; \
1190} \ 1018} \
1191static ssize_t iscsi_tpg_param_store_##name( \ 1019static ssize_t iscsi_tpg_param_##name##_store(struct config_item *item, \
1192 struct se_portal_group *se_tpg, \ 1020 const char *page, size_t count) \
1193 const char *page, \
1194 size_t count) \
1195{ \ 1021{ \
1022 struct se_portal_group *se_tpg = param_to_tpg(item); \
1196 struct iscsi_portal_group *tpg = container_of(se_tpg, \ 1023 struct iscsi_portal_group *tpg = container_of(se_tpg, \
1197 struct iscsi_portal_group, tpg_se_tpg); \ 1024 struct iscsi_portal_group, tpg_se_tpg); \
1198 char *buf; \ 1025 char *buf; \
@@ -1220,96 +1047,54 @@ static ssize_t iscsi_tpg_param_store_##name( \
1220out: \ 1047out: \
1221 kfree(buf); \ 1048 kfree(buf); \
1222 iscsit_put_tpg(tpg); \ 1049 iscsit_put_tpg(tpg); \
1223 return -EINVAL; \ 1050 return -EINVAL; \
1224} 1051} \
1225 1052CONFIGFS_ATTR(iscsi_tpg_param_, name)
1226#define TPG_PARAM_ATTR(_name, _mode) TF_TPG_PARAM_ATTR(iscsi, _name, _mode);
1227 1053
1228DEF_TPG_PARAM(AuthMethod); 1054DEF_TPG_PARAM(AuthMethod);
1229TPG_PARAM_ATTR(AuthMethod, S_IRUGO | S_IWUSR);
1230
1231DEF_TPG_PARAM(HeaderDigest); 1055DEF_TPG_PARAM(HeaderDigest);
1232TPG_PARAM_ATTR(HeaderDigest, S_IRUGO | S_IWUSR);
1233
1234DEF_TPG_PARAM(DataDigest); 1056DEF_TPG_PARAM(DataDigest);
1235TPG_PARAM_ATTR(DataDigest, S_IRUGO | S_IWUSR);
1236
1237DEF_TPG_PARAM(MaxConnections); 1057DEF_TPG_PARAM(MaxConnections);
1238TPG_PARAM_ATTR(MaxConnections, S_IRUGO | S_IWUSR);
1239
1240DEF_TPG_PARAM(TargetAlias); 1058DEF_TPG_PARAM(TargetAlias);
1241TPG_PARAM_ATTR(TargetAlias, S_IRUGO | S_IWUSR);
1242
1243DEF_TPG_PARAM(InitialR2T); 1059DEF_TPG_PARAM(InitialR2T);
1244TPG_PARAM_ATTR(InitialR2T, S_IRUGO | S_IWUSR);
1245
1246DEF_TPG_PARAM(ImmediateData); 1060DEF_TPG_PARAM(ImmediateData);
1247TPG_PARAM_ATTR(ImmediateData, S_IRUGO | S_IWUSR);
1248
1249DEF_TPG_PARAM(MaxRecvDataSegmentLength); 1061DEF_TPG_PARAM(MaxRecvDataSegmentLength);
1250TPG_PARAM_ATTR(MaxRecvDataSegmentLength, S_IRUGO | S_IWUSR);
1251
1252DEF_TPG_PARAM(MaxXmitDataSegmentLength); 1062DEF_TPG_PARAM(MaxXmitDataSegmentLength);
1253TPG_PARAM_ATTR(MaxXmitDataSegmentLength, S_IRUGO | S_IWUSR);
1254
1255DEF_TPG_PARAM(MaxBurstLength); 1063DEF_TPG_PARAM(MaxBurstLength);
1256TPG_PARAM_ATTR(MaxBurstLength, S_IRUGO | S_IWUSR);
1257
1258DEF_TPG_PARAM(FirstBurstLength); 1064DEF_TPG_PARAM(FirstBurstLength);
1259TPG_PARAM_ATTR(FirstBurstLength, S_IRUGO | S_IWUSR);
1260
1261DEF_TPG_PARAM(DefaultTime2Wait); 1065DEF_TPG_PARAM(DefaultTime2Wait);
1262TPG_PARAM_ATTR(DefaultTime2Wait, S_IRUGO | S_IWUSR);
1263
1264DEF_TPG_PARAM(DefaultTime2Retain); 1066DEF_TPG_PARAM(DefaultTime2Retain);
1265TPG_PARAM_ATTR(DefaultTime2Retain, S_IRUGO | S_IWUSR);
1266
1267DEF_TPG_PARAM(MaxOutstandingR2T); 1067DEF_TPG_PARAM(MaxOutstandingR2T);
1268TPG_PARAM_ATTR(MaxOutstandingR2T, S_IRUGO | S_IWUSR);
1269
1270DEF_TPG_PARAM(DataPDUInOrder); 1068DEF_TPG_PARAM(DataPDUInOrder);
1271TPG_PARAM_ATTR(DataPDUInOrder, S_IRUGO | S_IWUSR);
1272
1273DEF_TPG_PARAM(DataSequenceInOrder); 1069DEF_TPG_PARAM(DataSequenceInOrder);
1274TPG_PARAM_ATTR(DataSequenceInOrder, S_IRUGO | S_IWUSR);
1275
1276DEF_TPG_PARAM(ErrorRecoveryLevel); 1070DEF_TPG_PARAM(ErrorRecoveryLevel);
1277TPG_PARAM_ATTR(ErrorRecoveryLevel, S_IRUGO | S_IWUSR);
1278
1279DEF_TPG_PARAM(IFMarker); 1071DEF_TPG_PARAM(IFMarker);
1280TPG_PARAM_ATTR(IFMarker, S_IRUGO | S_IWUSR);
1281
1282DEF_TPG_PARAM(OFMarker); 1072DEF_TPG_PARAM(OFMarker);
1283TPG_PARAM_ATTR(OFMarker, S_IRUGO | S_IWUSR);
1284
1285DEF_TPG_PARAM(IFMarkInt); 1073DEF_TPG_PARAM(IFMarkInt);
1286TPG_PARAM_ATTR(IFMarkInt, S_IRUGO | S_IWUSR);
1287
1288DEF_TPG_PARAM(OFMarkInt); 1074DEF_TPG_PARAM(OFMarkInt);
1289TPG_PARAM_ATTR(OFMarkInt, S_IRUGO | S_IWUSR);
1290 1075
1291static struct configfs_attribute *lio_target_tpg_param_attrs[] = { 1076static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1292 &iscsi_tpg_param_AuthMethod.attr, 1077 &iscsi_tpg_param_attr_AuthMethod,
1293 &iscsi_tpg_param_HeaderDigest.attr, 1078 &iscsi_tpg_param_attr_HeaderDigest,
1294 &iscsi_tpg_param_DataDigest.attr, 1079 &iscsi_tpg_param_attr_DataDigest,
1295 &iscsi_tpg_param_MaxConnections.attr, 1080 &iscsi_tpg_param_attr_MaxConnections,
1296 &iscsi_tpg_param_TargetAlias.attr, 1081 &iscsi_tpg_param_attr_TargetAlias,
1297 &iscsi_tpg_param_InitialR2T.attr, 1082 &iscsi_tpg_param_attr_InitialR2T,
1298 &iscsi_tpg_param_ImmediateData.attr, 1083 &iscsi_tpg_param_attr_ImmediateData,
1299 &iscsi_tpg_param_MaxRecvDataSegmentLength.attr, 1084 &iscsi_tpg_param_attr_MaxRecvDataSegmentLength,
1300 &iscsi_tpg_param_MaxXmitDataSegmentLength.attr, 1085 &iscsi_tpg_param_attr_MaxXmitDataSegmentLength,
1301 &iscsi_tpg_param_MaxBurstLength.attr, 1086 &iscsi_tpg_param_attr_MaxBurstLength,
1302 &iscsi_tpg_param_FirstBurstLength.attr, 1087 &iscsi_tpg_param_attr_FirstBurstLength,
1303 &iscsi_tpg_param_DefaultTime2Wait.attr, 1088 &iscsi_tpg_param_attr_DefaultTime2Wait,
1304 &iscsi_tpg_param_DefaultTime2Retain.attr, 1089 &iscsi_tpg_param_attr_DefaultTime2Retain,
1305 &iscsi_tpg_param_MaxOutstandingR2T.attr, 1090 &iscsi_tpg_param_attr_MaxOutstandingR2T,
1306 &iscsi_tpg_param_DataPDUInOrder.attr, 1091 &iscsi_tpg_param_attr_DataPDUInOrder,
1307 &iscsi_tpg_param_DataSequenceInOrder.attr, 1092 &iscsi_tpg_param_attr_DataSequenceInOrder,
1308 &iscsi_tpg_param_ErrorRecoveryLevel.attr, 1093 &iscsi_tpg_param_attr_ErrorRecoveryLevel,
1309 &iscsi_tpg_param_IFMarker.attr, 1094 &iscsi_tpg_param_attr_IFMarker,
1310 &iscsi_tpg_param_OFMarker.attr, 1095 &iscsi_tpg_param_attr_OFMarker,
1311 &iscsi_tpg_param_IFMarkInt.attr, 1096 &iscsi_tpg_param_attr_IFMarkInt,
1312 &iscsi_tpg_param_OFMarkInt.attr, 1097 &iscsi_tpg_param_attr_OFMarkInt,
1313 NULL, 1098 NULL,
1314}; 1099};
1315 1100
@@ -1317,10 +1102,9 @@ static struct configfs_attribute *lio_target_tpg_param_attrs[] = {
1317 1102
1318/* Start items for lio_target_tpg_cit */ 1103/* Start items for lio_target_tpg_cit */
1319 1104
1320static ssize_t lio_target_tpg_show_enable( 1105static ssize_t lio_target_tpg_enable_show(struct config_item *item, char *page)
1321 struct se_portal_group *se_tpg,
1322 char *page)
1323{ 1106{
1107 struct se_portal_group *se_tpg = to_tpg(item);
1324 struct iscsi_portal_group *tpg = container_of(se_tpg, 1108 struct iscsi_portal_group *tpg = container_of(se_tpg,
1325 struct iscsi_portal_group, tpg_se_tpg); 1109 struct iscsi_portal_group, tpg_se_tpg);
1326 ssize_t len; 1110 ssize_t len;
@@ -1333,11 +1117,10 @@ static ssize_t lio_target_tpg_show_enable(
1333 return len; 1117 return len;
1334} 1118}
1335 1119
1336static ssize_t lio_target_tpg_store_enable( 1120static ssize_t lio_target_tpg_enable_store(struct config_item *item,
1337 struct se_portal_group *se_tpg, 1121 const char *page, size_t count)
1338 const char *page,
1339 size_t count)
1340{ 1122{
1123 struct se_portal_group *se_tpg = to_tpg(item);
1341 struct iscsi_portal_group *tpg = container_of(se_tpg, 1124 struct iscsi_portal_group *tpg = container_of(se_tpg,
1342 struct iscsi_portal_group, tpg_se_tpg); 1125 struct iscsi_portal_group, tpg_se_tpg);
1343 u32 op; 1126 u32 op;
@@ -1375,20 +1158,19 @@ out:
1375 return -EINVAL; 1158 return -EINVAL;
1376} 1159}
1377 1160
1378TF_TPG_BASE_ATTR(lio_target, enable, S_IRUGO | S_IWUSR);
1379 1161
1380static ssize_t lio_target_tpg_show_dynamic_sessions( 1162static ssize_t lio_target_tpg_dynamic_sessions_show(struct config_item *item,
1381 struct se_portal_group *se_tpg, 1163 char *page)
1382 char *page)
1383{ 1164{
1384 return target_show_dynamic_sessions(se_tpg, page); 1165 return target_show_dynamic_sessions(to_tpg(item), page);
1385} 1166}
1386 1167
1387TF_TPG_BASE_ATTR_RO(lio_target, dynamic_sessions); 1168CONFIGFS_ATTR(lio_target_tpg_, enable);
1169CONFIGFS_ATTR_RO(lio_target_tpg_, dynamic_sessions);
1388 1170
1389static struct configfs_attribute *lio_target_tpg_attrs[] = { 1171static struct configfs_attribute *lio_target_tpg_attrs[] = {
1390 &lio_target_tpg_enable.attr, 1172 &lio_target_tpg_attr_enable,
1391 &lio_target_tpg_dynamic_sessions.attr, 1173 &lio_target_tpg_attr_dynamic_sessions,
1392 NULL, 1174 NULL,
1393}; 1175};
1394 1176
@@ -1463,17 +1245,16 @@ static void lio_target_tiqn_deltpg(struct se_portal_group *se_tpg)
1463 1245
1464/* Start LIO-Target TIQN struct contig_item lio_target_cit */ 1246/* Start LIO-Target TIQN struct contig_item lio_target_cit */
1465 1247
1466static ssize_t lio_target_wwn_show_attr_lio_version( 1248static ssize_t lio_target_wwn_lio_version_show(struct config_item *item,
1467 struct target_fabric_configfs *tf, 1249 char *page)
1468 char *page)
1469{ 1250{
1470 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n"); 1251 return sprintf(page, "Datera Inc. iSCSI Target "ISCSIT_VERSION"\n");
1471} 1252}
1472 1253
1473TF_WWN_ATTR_RO(lio_target, lio_version); 1254CONFIGFS_ATTR_RO(lio_target_wwn_, lio_version);
1474 1255
1475static struct configfs_attribute *lio_target_wwn_attrs[] = { 1256static struct configfs_attribute *lio_target_wwn_attrs[] = {
1476 &lio_target_wwn_lio_version.attr, 1257 &lio_target_wwn_attr_lio_version,
1477 NULL, 1258 NULL,
1478}; 1259};
1479 1260
@@ -1552,77 +1333,47 @@ static void lio_target_call_coredeltiqn(
1552 1333
1553#define DEF_DISC_AUTH_STR(name, flags) \ 1334#define DEF_DISC_AUTH_STR(name, flags) \
1554 __DEF_NACL_AUTH_STR(disc, name, flags) \ 1335 __DEF_NACL_AUTH_STR(disc, name, flags) \
1555static ssize_t iscsi_disc_show_##name( \ 1336static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1556 struct target_fabric_configfs *tf, \
1557 char *page) \
1558{ \ 1337{ \
1559 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ 1338 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl,\
1560 page); \ 1339 page); \
1561} \ 1340} \
1562static ssize_t iscsi_disc_store_##name( \ 1341static ssize_t iscsi_disc_##name##_store(struct config_item *item, \
1563 struct target_fabric_configfs *tf, \ 1342 const char *page, size_t count) \
1564 const char *page, \
1565 size_t count) \
1566{ \ 1343{ \
1567 return __iscsi_disc_store_##name(&iscsit_global->discovery_acl, \ 1344 return __iscsi_disc_##name##_store(&iscsit_global->discovery_acl, \
1568 page, count); \ 1345 page, count); \
1569} 1346 \
1347} \
1348CONFIGFS_ATTR(iscsi_disc_, name)
1349
1350DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1351DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1352DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1353DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1570 1354
1571#define DEF_DISC_AUTH_INT(name) \ 1355#define DEF_DISC_AUTH_INT(name) \
1572 __DEF_NACL_AUTH_INT(disc, name) \ 1356 __DEF_NACL_AUTH_INT(disc, name) \
1573static ssize_t iscsi_disc_show_##name( \ 1357static ssize_t iscsi_disc_##name##_show(struct config_item *item, char *page) \
1574 struct target_fabric_configfs *tf, \
1575 char *page) \
1576{ \ 1358{ \
1577 return __iscsi_disc_show_##name(&iscsit_global->discovery_acl, \ 1359 return __iscsi_disc_##name##_show(&iscsit_global->discovery_acl, \
1578 page); \ 1360 page); \
1579} 1361} \
1580 1362CONFIGFS_ATTR_RO(iscsi_disc_, name)
1581#define DISC_AUTH_ATTR(_name, _mode) TF_DISC_ATTR(iscsi, _name, _mode)
1582#define DISC_AUTH_ATTR_RO(_name) TF_DISC_ATTR_RO(iscsi, _name)
1583 1363
1584/*
1585 * One-way authentication userid
1586 */
1587DEF_DISC_AUTH_STR(userid, NAF_USERID_SET);
1588DISC_AUTH_ATTR(userid, S_IRUGO | S_IWUSR);
1589/*
1590 * One-way authentication password
1591 */
1592DEF_DISC_AUTH_STR(password, NAF_PASSWORD_SET);
1593DISC_AUTH_ATTR(password, S_IRUGO | S_IWUSR);
1594/*
1595 * Enforce mutual authentication
1596 */
1597DEF_DISC_AUTH_INT(authenticate_target); 1364DEF_DISC_AUTH_INT(authenticate_target);
1598DISC_AUTH_ATTR_RO(authenticate_target);
1599/*
1600 * Mutual authentication userid
1601 */
1602DEF_DISC_AUTH_STR(userid_mutual, NAF_USERID_IN_SET);
1603DISC_AUTH_ATTR(userid_mutual, S_IRUGO | S_IWUSR);
1604/*
1605 * Mutual authentication password
1606 */
1607DEF_DISC_AUTH_STR(password_mutual, NAF_PASSWORD_IN_SET);
1608DISC_AUTH_ATTR(password_mutual, S_IRUGO | S_IWUSR);
1609 1365
1610/* 1366
1611 * enforce_discovery_auth 1367static ssize_t iscsi_disc_enforce_discovery_auth_show(struct config_item *item,
1612 */ 1368 char *page)
1613static ssize_t iscsi_disc_show_enforce_discovery_auth(
1614 struct target_fabric_configfs *tf,
1615 char *page)
1616{ 1369{
1617 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth; 1370 struct iscsi_node_auth *discovery_auth = &iscsit_global->discovery_acl.node_auth;
1618 1371
1619 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth); 1372 return sprintf(page, "%d\n", discovery_auth->enforce_discovery_auth);
1620} 1373}
1621 1374
1622static ssize_t iscsi_disc_store_enforce_discovery_auth( 1375static ssize_t iscsi_disc_enforce_discovery_auth_store(struct config_item *item,
1623 struct target_fabric_configfs *tf, 1376 const char *page, size_t count)
1624 const char *page,
1625 size_t count)
1626{ 1377{
1627 struct iscsi_param *param; 1378 struct iscsi_param *param;
1628 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg; 1379 struct iscsi_portal_group *discovery_tpg = iscsit_global->discovery_tpg;
@@ -1677,15 +1428,15 @@ static ssize_t iscsi_disc_store_enforce_discovery_auth(
1677 return count; 1428 return count;
1678} 1429}
1679 1430
1680DISC_AUTH_ATTR(enforce_discovery_auth, S_IRUGO | S_IWUSR); 1431CONFIGFS_ATTR(iscsi_disc_, enforce_discovery_auth);
1681 1432
1682static struct configfs_attribute *lio_target_discovery_auth_attrs[] = { 1433static struct configfs_attribute *lio_target_discovery_auth_attrs[] = {
1683 &iscsi_disc_userid.attr, 1434 &iscsi_disc_attr_userid,
1684 &iscsi_disc_password.attr, 1435 &iscsi_disc_attr_password,
1685 &iscsi_disc_authenticate_target.attr, 1436 &iscsi_disc_attr_authenticate_target,
1686 &iscsi_disc_userid_mutual.attr, 1437 &iscsi_disc_attr_userid_mutual,
1687 &iscsi_disc_password_mutual.attr, 1438 &iscsi_disc_attr_password_mutual,
1688 &iscsi_disc_enforce_discovery_auth.attr, 1439 &iscsi_disc_attr_enforce_discovery_auth,
1689 NULL, 1440 NULL,
1690}; 1441};
1691 1442
diff --git a/drivers/target/iscsi/iscsi_target_stat.c b/drivers/target/iscsi/iscsi_target_stat.c
index 9dd94ff0b62c..411cb266a47d 100644
--- a/drivers/target/iscsi/iscsi_target_stat.c
+++ b/drivers/target/iscsi/iscsi_target_stat.c
@@ -21,7 +21,6 @@
21#include <linux/export.h> 21#include <linux/export.h>
22#include <scsi/iscsi_proto.h> 22#include <scsi/iscsi_proto.h>
23#include <target/target_core_base.h> 23#include <target/target_core_base.h>
24#include <target/configfs_macros.h>
25 24
26#include <target/iscsi/iscsi_target_core.h> 25#include <target/iscsi/iscsi_target_core.h>
27#include "iscsi_target_parameters.h" 26#include "iscsi_target_parameters.h"
@@ -50,76 +49,56 @@
50/* 49/*
51 * Instance Attributes Table 50 * Instance Attributes Table
52 */ 51 */
53CONFIGFS_EATTR_STRUCT(iscsi_stat_instance, iscsi_wwn_stat_grps); 52static struct iscsi_tiqn *iscsi_instance_tiqn(struct config_item *item)
54#define ISCSI_STAT_INSTANCE_ATTR(_name, _mode) \ 53{
55static struct iscsi_stat_instance_attribute \ 54 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
56 iscsi_stat_instance_##_name = \ 55 struct iscsi_wwn_stat_grps, iscsi_instance_group);
57 __CONFIGFS_EATTR(_name, _mode, \ 56 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
58 iscsi_stat_instance_show_attr_##_name, \ 57}
59 iscsi_stat_instance_store_attr_##_name);
60
61#define ISCSI_STAT_INSTANCE_ATTR_RO(_name) \
62static struct iscsi_stat_instance_attribute \
63 iscsi_stat_instance_##_name = \
64 __CONFIGFS_EATTR_RO(_name, \
65 iscsi_stat_instance_show_attr_##_name);
66
67static ssize_t iscsi_stat_instance_show_attr_inst(
68 struct iscsi_wwn_stat_grps *igrps, char *page)
69{
70 struct iscsi_tiqn *tiqn = container_of(igrps,
71 struct iscsi_tiqn, tiqn_stat_grps);
72 58
73 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); 59static ssize_t iscsi_stat_instance_inst_show(struct config_item *item,
60 char *page)
61{
62 return snprintf(page, PAGE_SIZE, "%u\n",
63 iscsi_instance_tiqn(item)->tiqn_index);
74} 64}
75ISCSI_STAT_INSTANCE_ATTR_RO(inst);
76 65
77static ssize_t iscsi_stat_instance_show_attr_min_ver( 66static ssize_t iscsi_stat_instance_min_ver_show(struct config_item *item,
78 struct iscsi_wwn_stat_grps *igrps, char *page) 67 char *page)
79{ 68{
80 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION); 69 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
81} 70}
82ISCSI_STAT_INSTANCE_ATTR_RO(min_ver);
83 71
84static ssize_t iscsi_stat_instance_show_attr_max_ver( 72static ssize_t iscsi_stat_instance_max_ver_show(struct config_item *item,
85 struct iscsi_wwn_stat_grps *igrps, char *page) 73 char *page)
86{ 74{
87 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION); 75 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DRAFT20_VERSION);
88} 76}
89ISCSI_STAT_INSTANCE_ATTR_RO(max_ver);
90 77
91static ssize_t iscsi_stat_instance_show_attr_portals( 78static ssize_t iscsi_stat_instance_portals_show(struct config_item *item,
92 struct iscsi_wwn_stat_grps *igrps, char *page) 79 char *page)
93{ 80{
94 struct iscsi_tiqn *tiqn = container_of(igrps, 81 return snprintf(page, PAGE_SIZE, "%u\n",
95 struct iscsi_tiqn, tiqn_stat_grps); 82 iscsi_instance_tiqn(item)->tiqn_num_tpg_nps);
96
97 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_num_tpg_nps);
98} 83}
99ISCSI_STAT_INSTANCE_ATTR_RO(portals);
100 84
101static ssize_t iscsi_stat_instance_show_attr_nodes( 85static ssize_t iscsi_stat_instance_nodes_show(struct config_item *item,
102 struct iscsi_wwn_stat_grps *igrps, char *page) 86 char *page)
103{ 87{
104 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES); 88 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_INST_NUM_NODES);
105} 89}
106ISCSI_STAT_INSTANCE_ATTR_RO(nodes);
107 90
108static ssize_t iscsi_stat_instance_show_attr_sessions( 91static ssize_t iscsi_stat_instance_sessions_show(struct config_item *item,
109 struct iscsi_wwn_stat_grps *igrps, char *page) 92 char *page)
110{ 93{
111 struct iscsi_tiqn *tiqn = container_of(igrps, 94 return snprintf(page, PAGE_SIZE, "%u\n",
112 struct iscsi_tiqn, tiqn_stat_grps); 95 iscsi_instance_tiqn(item)->tiqn_nsessions);
113
114 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_nsessions);
115} 96}
116ISCSI_STAT_INSTANCE_ATTR_RO(sessions);
117 97
118static ssize_t iscsi_stat_instance_show_attr_fail_sess( 98static ssize_t iscsi_stat_instance_fail_sess_show(struct config_item *item,
119 struct iscsi_wwn_stat_grps *igrps, char *page) 99 char *page)
120{ 100{
121 struct iscsi_tiqn *tiqn = container_of(igrps, 101 struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
122 struct iscsi_tiqn, tiqn_stat_grps);
123 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; 102 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
124 u32 sess_err_count; 103 u32 sess_err_count;
125 104
@@ -131,88 +110,84 @@ static ssize_t iscsi_stat_instance_show_attr_fail_sess(
131 110
132 return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count); 111 return snprintf(page, PAGE_SIZE, "%u\n", sess_err_count);
133} 112}
134ISCSI_STAT_INSTANCE_ATTR_RO(fail_sess);
135 113
136static ssize_t iscsi_stat_instance_show_attr_fail_type( 114static ssize_t iscsi_stat_instance_fail_type_show(struct config_item *item,
137 struct iscsi_wwn_stat_grps *igrps, char *page) 115 char *page)
138{ 116{
139 struct iscsi_tiqn *tiqn = container_of(igrps, 117 struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
140 struct iscsi_tiqn, tiqn_stat_grps);
141 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; 118 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
142 119
143 return snprintf(page, PAGE_SIZE, "%u\n", 120 return snprintf(page, PAGE_SIZE, "%u\n",
144 sess_err->last_sess_failure_type); 121 sess_err->last_sess_failure_type);
145} 122}
146ISCSI_STAT_INSTANCE_ATTR_RO(fail_type);
147 123
148static ssize_t iscsi_stat_instance_show_attr_fail_rem_name( 124static ssize_t iscsi_stat_instance_fail_rem_name_show(struct config_item *item,
149 struct iscsi_wwn_stat_grps *igrps, char *page) 125 char *page)
150{ 126{
151 struct iscsi_tiqn *tiqn = container_of(igrps, 127 struct iscsi_tiqn *tiqn = iscsi_instance_tiqn(item);
152 struct iscsi_tiqn, tiqn_stat_grps);
153 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; 128 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
154 129
155 return snprintf(page, PAGE_SIZE, "%s\n", 130 return snprintf(page, PAGE_SIZE, "%s\n",
156 sess_err->last_sess_fail_rem_name[0] ? 131 sess_err->last_sess_fail_rem_name[0] ?
157 sess_err->last_sess_fail_rem_name : NONE); 132 sess_err->last_sess_fail_rem_name : NONE);
158} 133}
159ISCSI_STAT_INSTANCE_ATTR_RO(fail_rem_name);
160 134
161static ssize_t iscsi_stat_instance_show_attr_disc_time( 135static ssize_t iscsi_stat_instance_disc_time_show(struct config_item *item,
162 struct iscsi_wwn_stat_grps *igrps, char *page) 136 char *page)
163{ 137{
164 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME); 138 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_DISCONTINUITY_TIME);
165} 139}
166ISCSI_STAT_INSTANCE_ATTR_RO(disc_time);
167 140
168static ssize_t iscsi_stat_instance_show_attr_description( 141static ssize_t iscsi_stat_instance_description_show(struct config_item *item,
169 struct iscsi_wwn_stat_grps *igrps, char *page) 142 char *page)
170{ 143{
171 return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR); 144 return snprintf(page, PAGE_SIZE, "%s\n", ISCSI_INST_DESCR);
172} 145}
173ISCSI_STAT_INSTANCE_ATTR_RO(description);
174 146
175static ssize_t iscsi_stat_instance_show_attr_vendor( 147static ssize_t iscsi_stat_instance_vendor_show(struct config_item *item,
176 struct iscsi_wwn_stat_grps *igrps, char *page) 148 char *page)
177{ 149{
178 return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n"); 150 return snprintf(page, PAGE_SIZE, "Datera, Inc. iSCSI-Target\n");
179} 151}
180ISCSI_STAT_INSTANCE_ATTR_RO(vendor);
181 152
182static ssize_t iscsi_stat_instance_show_attr_version( 153static ssize_t iscsi_stat_instance_version_show(struct config_item *item,
183 struct iscsi_wwn_stat_grps *igrps, char *page) 154 char *page)
184{ 155{
185 return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION); 156 return snprintf(page, PAGE_SIZE, "%s\n", ISCSIT_VERSION);
186} 157}
187ISCSI_STAT_INSTANCE_ATTR_RO(version);
188 158
189CONFIGFS_EATTR_OPS(iscsi_stat_instance, iscsi_wwn_stat_grps, 159CONFIGFS_ATTR_RO(iscsi_stat_instance_, inst);
190 iscsi_instance_group); 160CONFIGFS_ATTR_RO(iscsi_stat_instance_, min_ver);
161CONFIGFS_ATTR_RO(iscsi_stat_instance_, max_ver);
162CONFIGFS_ATTR_RO(iscsi_stat_instance_, portals);
163CONFIGFS_ATTR_RO(iscsi_stat_instance_, nodes);
164CONFIGFS_ATTR_RO(iscsi_stat_instance_, sessions);
165CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_sess);
166CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_type);
167CONFIGFS_ATTR_RO(iscsi_stat_instance_, fail_rem_name);
168CONFIGFS_ATTR_RO(iscsi_stat_instance_, disc_time);
169CONFIGFS_ATTR_RO(iscsi_stat_instance_, description);
170CONFIGFS_ATTR_RO(iscsi_stat_instance_, vendor);
171CONFIGFS_ATTR_RO(iscsi_stat_instance_, version);
191 172
192static struct configfs_attribute *iscsi_stat_instance_attrs[] = { 173static struct configfs_attribute *iscsi_stat_instance_attrs[] = {
193 &iscsi_stat_instance_inst.attr, 174 &iscsi_stat_instance_attr_inst,
194 &iscsi_stat_instance_min_ver.attr, 175 &iscsi_stat_instance_attr_min_ver,
195 &iscsi_stat_instance_max_ver.attr, 176 &iscsi_stat_instance_attr_max_ver,
196 &iscsi_stat_instance_portals.attr, 177 &iscsi_stat_instance_attr_portals,
197 &iscsi_stat_instance_nodes.attr, 178 &iscsi_stat_instance_attr_nodes,
198 &iscsi_stat_instance_sessions.attr, 179 &iscsi_stat_instance_attr_sessions,
199 &iscsi_stat_instance_fail_sess.attr, 180 &iscsi_stat_instance_attr_fail_sess,
200 &iscsi_stat_instance_fail_type.attr, 181 &iscsi_stat_instance_attr_fail_type,
201 &iscsi_stat_instance_fail_rem_name.attr, 182 &iscsi_stat_instance_attr_fail_rem_name,
202 &iscsi_stat_instance_disc_time.attr, 183 &iscsi_stat_instance_attr_disc_time,
203 &iscsi_stat_instance_description.attr, 184 &iscsi_stat_instance_attr_description,
204 &iscsi_stat_instance_vendor.attr, 185 &iscsi_stat_instance_attr_vendor,
205 &iscsi_stat_instance_version.attr, 186 &iscsi_stat_instance_attr_version,
206 NULL, 187 NULL,
207}; 188};
208 189
209static struct configfs_item_operations iscsi_stat_instance_item_ops = {
210 .show_attribute = iscsi_stat_instance_attr_show,
211 .store_attribute = iscsi_stat_instance_attr_store,
212};
213
214struct config_item_type iscsi_stat_instance_cit = { 190struct config_item_type iscsi_stat_instance_cit = {
215 .ct_item_ops = &iscsi_stat_instance_item_ops,
216 .ct_attrs = iscsi_stat_instance_attrs, 191 .ct_attrs = iscsi_stat_instance_attrs,
217 .ct_owner = THIS_MODULE, 192 .ct_owner = THIS_MODULE,
218}; 193};
@@ -220,81 +195,61 @@ struct config_item_type iscsi_stat_instance_cit = {
220/* 195/*
221 * Instance Session Failure Stats Table 196 * Instance Session Failure Stats Table
222 */ 197 */
223CONFIGFS_EATTR_STRUCT(iscsi_stat_sess_err, iscsi_wwn_stat_grps); 198static struct iscsi_tiqn *iscsi_sess_err_tiqn(struct config_item *item)
224#define ISCSI_STAT_SESS_ERR_ATTR(_name, _mode) \ 199{
225static struct iscsi_stat_sess_err_attribute \ 200 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
226 iscsi_stat_sess_err_##_name = \ 201 struct iscsi_wwn_stat_grps, iscsi_sess_err_group);
227 __CONFIGFS_EATTR(_name, _mode, \ 202 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
228 iscsi_stat_sess_err_show_attr_##_name, \ 203}
229 iscsi_stat_sess_err_store_attr_##_name);
230
231#define ISCSI_STAT_SESS_ERR_ATTR_RO(_name) \
232static struct iscsi_stat_sess_err_attribute \
233 iscsi_stat_sess_err_##_name = \
234 __CONFIGFS_EATTR_RO(_name, \
235 iscsi_stat_sess_err_show_attr_##_name);
236
237static ssize_t iscsi_stat_sess_err_show_attr_inst(
238 struct iscsi_wwn_stat_grps *igrps, char *page)
239{
240 struct iscsi_tiqn *tiqn = container_of(igrps,
241 struct iscsi_tiqn, tiqn_stat_grps);
242 204
243 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); 205static ssize_t iscsi_stat_sess_err_inst_show(struct config_item *item,
206 char *page)
207{
208 return snprintf(page, PAGE_SIZE, "%u\n",
209 iscsi_sess_err_tiqn(item)->tiqn_index);
244} 210}
245ISCSI_STAT_SESS_ERR_ATTR_RO(inst);
246 211
247static ssize_t iscsi_stat_sess_err_show_attr_digest_errors( 212static ssize_t iscsi_stat_sess_err_digest_errors_show(struct config_item *item,
248 struct iscsi_wwn_stat_grps *igrps, char *page) 213 char *page)
249{ 214{
250 struct iscsi_tiqn *tiqn = container_of(igrps, 215 struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
251 struct iscsi_tiqn, tiqn_stat_grps);
252 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; 216 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
253 217
254 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors); 218 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->digest_errors);
255} 219}
256ISCSI_STAT_SESS_ERR_ATTR_RO(digest_errors);
257 220
258static ssize_t iscsi_stat_sess_err_show_attr_cxn_errors( 221static ssize_t iscsi_stat_sess_err_cxn_errors_show(struct config_item *item,
259 struct iscsi_wwn_stat_grps *igrps, char *page) 222 char *page)
260{ 223{
261 struct iscsi_tiqn *tiqn = container_of(igrps, 224 struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
262 struct iscsi_tiqn, tiqn_stat_grps);
263 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; 225 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
264 226
265 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors); 227 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->cxn_timeout_errors);
266} 228}
267ISCSI_STAT_SESS_ERR_ATTR_RO(cxn_errors);
268 229
269static ssize_t iscsi_stat_sess_err_show_attr_format_errors( 230static ssize_t iscsi_stat_sess_err_format_errors_show(struct config_item *item,
270 struct iscsi_wwn_stat_grps *igrps, char *page) 231 char *page)
271{ 232{
272 struct iscsi_tiqn *tiqn = container_of(igrps, 233 struct iscsi_tiqn *tiqn = iscsi_sess_err_tiqn(item);
273 struct iscsi_tiqn, tiqn_stat_grps);
274 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats; 234 struct iscsi_sess_err_stats *sess_err = &tiqn->sess_err_stats;
275 235
276 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors); 236 return snprintf(page, PAGE_SIZE, "%u\n", sess_err->pdu_format_errors);
277} 237}
278ISCSI_STAT_SESS_ERR_ATTR_RO(format_errors);
279 238
280CONFIGFS_EATTR_OPS(iscsi_stat_sess_err, iscsi_wwn_stat_grps, 239CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, inst);
281 iscsi_sess_err_group); 240CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, digest_errors);
241CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, cxn_errors);
242CONFIGFS_ATTR_RO(iscsi_stat_sess_err_, format_errors);
282 243
283static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = { 244static struct configfs_attribute *iscsi_stat_sess_err_attrs[] = {
284 &iscsi_stat_sess_err_inst.attr, 245 &iscsi_stat_sess_err_attr_inst,
285 &iscsi_stat_sess_err_digest_errors.attr, 246 &iscsi_stat_sess_err_attr_digest_errors,
286 &iscsi_stat_sess_err_cxn_errors.attr, 247 &iscsi_stat_sess_err_attr_cxn_errors,
287 &iscsi_stat_sess_err_format_errors.attr, 248 &iscsi_stat_sess_err_attr_format_errors,
288 NULL, 249 NULL,
289}; 250};
290 251
291static struct configfs_item_operations iscsi_stat_sess_err_item_ops = {
292 .show_attribute = iscsi_stat_sess_err_attr_show,
293 .store_attribute = iscsi_stat_sess_err_attr_store,
294};
295
296struct config_item_type iscsi_stat_sess_err_cit = { 252struct config_item_type iscsi_stat_sess_err_cit = {
297 .ct_item_ops = &iscsi_stat_sess_err_item_ops,
298 .ct_attrs = iscsi_stat_sess_err_attrs, 253 .ct_attrs = iscsi_stat_sess_err_attrs,
299 .ct_owner = THIS_MODULE, 254 .ct_owner = THIS_MODULE,
300}; 255};
@@ -302,42 +257,30 @@ struct config_item_type iscsi_stat_sess_err_cit = {
302/* 257/*
303 * Target Attributes Table 258 * Target Attributes Table
304 */ 259 */
305CONFIGFS_EATTR_STRUCT(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps); 260static struct iscsi_tiqn *iscsi_tgt_attr_tiqn(struct config_item *item)
306#define ISCSI_STAT_TGT_ATTR(_name, _mode) \ 261{
307static struct iscsi_stat_tgt_attr_attribute \ 262 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
308 iscsi_stat_tgt_attr_##_name = \ 263 struct iscsi_wwn_stat_grps, iscsi_tgt_attr_group);
309 __CONFIGFS_EATTR(_name, _mode, \ 264 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
310 iscsi_stat_tgt-attr_show_attr_##_name, \ 265}
311 iscsi_stat_tgt_attr_store_attr_##_name);
312
313#define ISCSI_STAT_TGT_ATTR_RO(_name) \
314static struct iscsi_stat_tgt_attr_attribute \
315 iscsi_stat_tgt_attr_##_name = \
316 __CONFIGFS_EATTR_RO(_name, \
317 iscsi_stat_tgt_attr_show_attr_##_name);
318
319static ssize_t iscsi_stat_tgt_attr_show_attr_inst(
320 struct iscsi_wwn_stat_grps *igrps, char *page)
321{
322 struct iscsi_tiqn *tiqn = container_of(igrps,
323 struct iscsi_tiqn, tiqn_stat_grps);
324 266
325 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); 267static ssize_t iscsi_stat_tgt_attr_inst_show(struct config_item *item,
268 char *page)
269{
270 return snprintf(page, PAGE_SIZE, "%u\n",
271 iscsi_tgt_attr_tiqn(item)->tiqn_index);
326} 272}
327ISCSI_STAT_TGT_ATTR_RO(inst);
328 273
329static ssize_t iscsi_stat_tgt_attr_show_attr_indx( 274static ssize_t iscsi_stat_tgt_attr_indx_show(struct config_item *item,
330 struct iscsi_wwn_stat_grps *igrps, char *page) 275 char *page)
331{ 276{
332 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX); 277 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
333} 278}
334ISCSI_STAT_TGT_ATTR_RO(indx);
335 279
336static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails( 280static ssize_t iscsi_stat_tgt_attr_login_fails_show(struct config_item *item,
337 struct iscsi_wwn_stat_grps *igrps, char *page) 281 char *page)
338{ 282{
339 struct iscsi_tiqn *tiqn = container_of(igrps, 283 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
340 struct iscsi_tiqn, tiqn_stat_grps);
341 struct iscsi_login_stats *lstat = &tiqn->login_stats; 284 struct iscsi_login_stats *lstat = &tiqn->login_stats;
342 u32 fail_count; 285 u32 fail_count;
343 286
@@ -349,13 +292,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_login_fails(
349 292
350 return snprintf(page, PAGE_SIZE, "%u\n", fail_count); 293 return snprintf(page, PAGE_SIZE, "%u\n", fail_count);
351} 294}
352ISCSI_STAT_TGT_ATTR_RO(login_fails);
353 295
354static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time( 296static ssize_t iscsi_stat_tgt_attr_last_fail_time_show(struct config_item *item,
355 struct iscsi_wwn_stat_grps *igrps, char *page) 297 char *page)
356{ 298{
357 struct iscsi_tiqn *tiqn = container_of(igrps, 299 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
358 struct iscsi_tiqn, tiqn_stat_grps);
359 struct iscsi_login_stats *lstat = &tiqn->login_stats; 300 struct iscsi_login_stats *lstat = &tiqn->login_stats;
360 u32 last_fail_time; 301 u32 last_fail_time;
361 302
@@ -367,13 +308,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_time(
367 308
368 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time); 309 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_time);
369} 310}
370ISCSI_STAT_TGT_ATTR_RO(last_fail_time);
371 311
372static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type( 312static ssize_t iscsi_stat_tgt_attr_last_fail_type_show(struct config_item *item,
373 struct iscsi_wwn_stat_grps *igrps, char *page) 313 char *page)
374{ 314{
375 struct iscsi_tiqn *tiqn = container_of(igrps, 315 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
376 struct iscsi_tiqn, tiqn_stat_grps);
377 struct iscsi_login_stats *lstat = &tiqn->login_stats; 316 struct iscsi_login_stats *lstat = &tiqn->login_stats;
378 u32 last_fail_type; 317 u32 last_fail_type;
379 318
@@ -383,13 +322,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_last_fail_type(
383 322
384 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type); 323 return snprintf(page, PAGE_SIZE, "%u\n", last_fail_type);
385} 324}
386ISCSI_STAT_TGT_ATTR_RO(last_fail_type);
387 325
388static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name( 326static ssize_t iscsi_stat_tgt_attr_fail_intr_name_show(struct config_item *item,
389 struct iscsi_wwn_stat_grps *igrps, char *page) 327 char *page)
390{ 328{
391 struct iscsi_tiqn *tiqn = container_of(igrps, 329 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
392 struct iscsi_tiqn, tiqn_stat_grps);
393 struct iscsi_login_stats *lstat = &tiqn->login_stats; 330 struct iscsi_login_stats *lstat = &tiqn->login_stats;
394 unsigned char buf[224]; 331 unsigned char buf[224];
395 332
@@ -400,13 +337,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_name(
400 337
401 return snprintf(page, PAGE_SIZE, "%s\n", buf); 338 return snprintf(page, PAGE_SIZE, "%s\n", buf);
402} 339}
403ISCSI_STAT_TGT_ATTR_RO(fail_intr_name);
404 340
405static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type( 341static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_type_show(struct config_item *item,
406 struct iscsi_wwn_stat_grps *igrps, char *page) 342 char *page)
407{ 343{
408 struct iscsi_tiqn *tiqn = container_of(igrps, 344 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
409 struct iscsi_tiqn, tiqn_stat_grps);
410 struct iscsi_login_stats *lstat = &tiqn->login_stats; 345 struct iscsi_login_stats *lstat = &tiqn->login_stats;
411 int ret; 346 int ret;
412 347
@@ -419,13 +354,11 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr_type(
419 354
420 return ret; 355 return ret;
421} 356}
422ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr_type);
423 357
424static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr( 358static ssize_t iscsi_stat_tgt_attr_fail_intr_addr_show(struct config_item *item,
425 struct iscsi_wwn_stat_grps *igrps, char *page) 359 char *page)
426{ 360{
427 struct iscsi_tiqn *tiqn = container_of(igrps, 361 struct iscsi_tiqn *tiqn = iscsi_tgt_attr_tiqn(item);
428 struct iscsi_tiqn, tiqn_stat_grps);
429 struct iscsi_login_stats *lstat = &tiqn->login_stats; 362 struct iscsi_login_stats *lstat = &tiqn->login_stats;
430 int ret; 363 int ret;
431 364
@@ -435,30 +368,29 @@ static ssize_t iscsi_stat_tgt_attr_show_attr_fail_intr_addr(
435 368
436 return ret; 369 return ret;
437} 370}
438ISCSI_STAT_TGT_ATTR_RO(fail_intr_addr);
439 371
440CONFIGFS_EATTR_OPS(iscsi_stat_tgt_attr, iscsi_wwn_stat_grps, 372CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, inst);
441 iscsi_tgt_attr_group); 373CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, indx);
374CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, login_fails);
375CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_time);
376CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, last_fail_type);
377CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_name);
378CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr_type);
379CONFIGFS_ATTR_RO(iscsi_stat_tgt_attr_, fail_intr_addr);
442 380
443static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = { 381static struct configfs_attribute *iscsi_stat_tgt_attr_attrs[] = {
444 &iscsi_stat_tgt_attr_inst.attr, 382 &iscsi_stat_tgt_attr_attr_inst,
445 &iscsi_stat_tgt_attr_indx.attr, 383 &iscsi_stat_tgt_attr_attr_indx,
446 &iscsi_stat_tgt_attr_login_fails.attr, 384 &iscsi_stat_tgt_attr_attr_login_fails,
447 &iscsi_stat_tgt_attr_last_fail_time.attr, 385 &iscsi_stat_tgt_attr_attr_last_fail_time,
448 &iscsi_stat_tgt_attr_last_fail_type.attr, 386 &iscsi_stat_tgt_attr_attr_last_fail_type,
449 &iscsi_stat_tgt_attr_fail_intr_name.attr, 387 &iscsi_stat_tgt_attr_attr_fail_intr_name,
450 &iscsi_stat_tgt_attr_fail_intr_addr_type.attr, 388 &iscsi_stat_tgt_attr_attr_fail_intr_addr_type,
451 &iscsi_stat_tgt_attr_fail_intr_addr.attr, 389 &iscsi_stat_tgt_attr_attr_fail_intr_addr,
452 NULL, 390 NULL,
453}; 391};
454 392
455static struct configfs_item_operations iscsi_stat_tgt_attr_item_ops = {
456 .show_attribute = iscsi_stat_tgt_attr_attr_show,
457 .store_attribute = iscsi_stat_tgt_attr_attr_store,
458};
459
460struct config_item_type iscsi_stat_tgt_attr_cit = { 393struct config_item_type iscsi_stat_tgt_attr_cit = {
461 .ct_item_ops = &iscsi_stat_tgt_attr_item_ops,
462 .ct_attrs = iscsi_stat_tgt_attr_attrs, 394 .ct_attrs = iscsi_stat_tgt_attr_attrs,
463 .ct_owner = THIS_MODULE, 395 .ct_owner = THIS_MODULE,
464}; 396};
@@ -466,42 +398,29 @@ struct config_item_type iscsi_stat_tgt_attr_cit = {
466/* 398/*
467 * Target Login Stats Table 399 * Target Login Stats Table
468 */ 400 */
469CONFIGFS_EATTR_STRUCT(iscsi_stat_login, iscsi_wwn_stat_grps); 401static struct iscsi_tiqn *iscsi_login_stat_tiqn(struct config_item *item)
470#define ISCSI_STAT_LOGIN(_name, _mode) \ 402{
471static struct iscsi_stat_login_attribute \ 403 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
472 iscsi_stat_login_##_name = \ 404 struct iscsi_wwn_stat_grps, iscsi_login_stats_group);
473 __CONFIGFS_EATTR(_name, _mode, \ 405 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
474 iscsi_stat_login_show_attr_##_name, \ 406}
475 iscsi_stat_login_store_attr_##_name);
476
477#define ISCSI_STAT_LOGIN_RO(_name) \
478static struct iscsi_stat_login_attribute \
479 iscsi_stat_login_##_name = \
480 __CONFIGFS_EATTR_RO(_name, \
481 iscsi_stat_login_show_attr_##_name);
482
483static ssize_t iscsi_stat_login_show_attr_inst(
484 struct iscsi_wwn_stat_grps *igrps, char *page)
485{
486 struct iscsi_tiqn *tiqn = container_of(igrps,
487 struct iscsi_tiqn, tiqn_stat_grps);
488 407
489 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); 408static ssize_t iscsi_stat_login_inst_show(struct config_item *item, char *page)
409{
410 return snprintf(page, PAGE_SIZE, "%u\n",
411 iscsi_login_stat_tiqn(item)->tiqn_index);
490} 412}
491ISCSI_STAT_LOGIN_RO(inst);
492 413
493static ssize_t iscsi_stat_login_show_attr_indx( 414static ssize_t iscsi_stat_login_indx_show(struct config_item *item,
494 struct iscsi_wwn_stat_grps *igrps, char *page) 415 char *page)
495{ 416{
496 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX); 417 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
497} 418}
498ISCSI_STAT_LOGIN_RO(indx);
499 419
500static ssize_t iscsi_stat_login_show_attr_accepts( 420static ssize_t iscsi_stat_login_accepts_show(struct config_item *item,
501 struct iscsi_wwn_stat_grps *igrps, char *page) 421 char *page)
502{ 422{
503 struct iscsi_tiqn *tiqn = container_of(igrps, 423 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
504 struct iscsi_tiqn, tiqn_stat_grps);
505 struct iscsi_login_stats *lstat = &tiqn->login_stats; 424 struct iscsi_login_stats *lstat = &tiqn->login_stats;
506 ssize_t ret; 425 ssize_t ret;
507 426
@@ -511,13 +430,11 @@ static ssize_t iscsi_stat_login_show_attr_accepts(
511 430
512 return ret; 431 return ret;
513} 432}
514ISCSI_STAT_LOGIN_RO(accepts);
515 433
516static ssize_t iscsi_stat_login_show_attr_other_fails( 434static ssize_t iscsi_stat_login_other_fails_show(struct config_item *item,
517 struct iscsi_wwn_stat_grps *igrps, char *page) 435 char *page)
518{ 436{
519 struct iscsi_tiqn *tiqn = container_of(igrps, 437 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
520 struct iscsi_tiqn, tiqn_stat_grps);
521 struct iscsi_login_stats *lstat = &tiqn->login_stats; 438 struct iscsi_login_stats *lstat = &tiqn->login_stats;
522 ssize_t ret; 439 ssize_t ret;
523 440
@@ -527,13 +444,11 @@ static ssize_t iscsi_stat_login_show_attr_other_fails(
527 444
528 return ret; 445 return ret;
529} 446}
530ISCSI_STAT_LOGIN_RO(other_fails);
531 447
532static ssize_t iscsi_stat_login_show_attr_redirects( 448static ssize_t iscsi_stat_login_redirects_show(struct config_item *item,
533 struct iscsi_wwn_stat_grps *igrps, char *page) 449 char *page)
534{ 450{
535 struct iscsi_tiqn *tiqn = container_of(igrps, 451 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
536 struct iscsi_tiqn, tiqn_stat_grps);
537 struct iscsi_login_stats *lstat = &tiqn->login_stats; 452 struct iscsi_login_stats *lstat = &tiqn->login_stats;
538 ssize_t ret; 453 ssize_t ret;
539 454
@@ -543,13 +458,11 @@ static ssize_t iscsi_stat_login_show_attr_redirects(
543 458
544 return ret; 459 return ret;
545} 460}
546ISCSI_STAT_LOGIN_RO(redirects);
547 461
548static ssize_t iscsi_stat_login_show_attr_authorize_fails( 462static ssize_t iscsi_stat_login_authorize_fails_show(struct config_item *item,
549 struct iscsi_wwn_stat_grps *igrps, char *page) 463 char *page)
550{ 464{
551 struct iscsi_tiqn *tiqn = container_of(igrps, 465 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
552 struct iscsi_tiqn, tiqn_stat_grps);
553 struct iscsi_login_stats *lstat = &tiqn->login_stats; 466 struct iscsi_login_stats *lstat = &tiqn->login_stats;
554 ssize_t ret; 467 ssize_t ret;
555 468
@@ -559,13 +472,11 @@ static ssize_t iscsi_stat_login_show_attr_authorize_fails(
559 472
560 return ret; 473 return ret;
561} 474}
562ISCSI_STAT_LOGIN_RO(authorize_fails);
563 475
564static ssize_t iscsi_stat_login_show_attr_authenticate_fails( 476static ssize_t iscsi_stat_login_authenticate_fails_show(
565 struct iscsi_wwn_stat_grps *igrps, char *page) 477 struct config_item *item, char *page)
566{ 478{
567 struct iscsi_tiqn *tiqn = container_of(igrps, 479 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
568 struct iscsi_tiqn, tiqn_stat_grps);
569 struct iscsi_login_stats *lstat = &tiqn->login_stats; 480 struct iscsi_login_stats *lstat = &tiqn->login_stats;
570 ssize_t ret; 481 ssize_t ret;
571 482
@@ -575,13 +486,11 @@ static ssize_t iscsi_stat_login_show_attr_authenticate_fails(
575 486
576 return ret; 487 return ret;
577} 488}
578ISCSI_STAT_LOGIN_RO(authenticate_fails);
579 489
580static ssize_t iscsi_stat_login_show_attr_negotiate_fails( 490static ssize_t iscsi_stat_login_negotiate_fails_show(struct config_item *item,
581 struct iscsi_wwn_stat_grps *igrps, char *page) 491 char *page)
582{ 492{
583 struct iscsi_tiqn *tiqn = container_of(igrps, 493 struct iscsi_tiqn *tiqn = iscsi_login_stat_tiqn(item);
584 struct iscsi_tiqn, tiqn_stat_grps);
585 struct iscsi_login_stats *lstat = &tiqn->login_stats; 494 struct iscsi_login_stats *lstat = &tiqn->login_stats;
586 ssize_t ret; 495 ssize_t ret;
587 496
@@ -591,30 +500,29 @@ static ssize_t iscsi_stat_login_show_attr_negotiate_fails(
591 500
592 return ret; 501 return ret;
593} 502}
594ISCSI_STAT_LOGIN_RO(negotiate_fails);
595 503
596CONFIGFS_EATTR_OPS(iscsi_stat_login, iscsi_wwn_stat_grps, 504CONFIGFS_ATTR_RO(iscsi_stat_login_, inst);
597 iscsi_login_stats_group); 505CONFIGFS_ATTR_RO(iscsi_stat_login_, indx);
506CONFIGFS_ATTR_RO(iscsi_stat_login_, accepts);
507CONFIGFS_ATTR_RO(iscsi_stat_login_, other_fails);
508CONFIGFS_ATTR_RO(iscsi_stat_login_, redirects);
509CONFIGFS_ATTR_RO(iscsi_stat_login_, authorize_fails);
510CONFIGFS_ATTR_RO(iscsi_stat_login_, authenticate_fails);
511CONFIGFS_ATTR_RO(iscsi_stat_login_, negotiate_fails);
598 512
599static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = { 513static struct configfs_attribute *iscsi_stat_login_stats_attrs[] = {
600 &iscsi_stat_login_inst.attr, 514 &iscsi_stat_login_attr_inst,
601 &iscsi_stat_login_indx.attr, 515 &iscsi_stat_login_attr_indx,
602 &iscsi_stat_login_accepts.attr, 516 &iscsi_stat_login_attr_accepts,
603 &iscsi_stat_login_other_fails.attr, 517 &iscsi_stat_login_attr_other_fails,
604 &iscsi_stat_login_redirects.attr, 518 &iscsi_stat_login_attr_redirects,
605 &iscsi_stat_login_authorize_fails.attr, 519 &iscsi_stat_login_attr_authorize_fails,
606 &iscsi_stat_login_authenticate_fails.attr, 520 &iscsi_stat_login_attr_authenticate_fails,
607 &iscsi_stat_login_negotiate_fails.attr, 521 &iscsi_stat_login_attr_negotiate_fails,
608 NULL, 522 NULL,
609}; 523};
610 524
611static struct configfs_item_operations iscsi_stat_login_stats_item_ops = {
612 .show_attribute = iscsi_stat_login_attr_show,
613 .store_attribute = iscsi_stat_login_attr_store,
614};
615
616struct config_item_type iscsi_stat_login_cit = { 525struct config_item_type iscsi_stat_login_cit = {
617 .ct_item_ops = &iscsi_stat_login_stats_item_ops,
618 .ct_attrs = iscsi_stat_login_stats_attrs, 526 .ct_attrs = iscsi_stat_login_stats_attrs,
619 .ct_owner = THIS_MODULE, 527 .ct_owner = THIS_MODULE,
620}; 528};
@@ -622,78 +530,56 @@ struct config_item_type iscsi_stat_login_cit = {
622/* 530/*
623 * Target Logout Stats Table 531 * Target Logout Stats Table
624 */ 532 */
625 533static struct iscsi_tiqn *iscsi_logout_stat_tiqn(struct config_item *item)
626CONFIGFS_EATTR_STRUCT(iscsi_stat_logout, iscsi_wwn_stat_grps);
627#define ISCSI_STAT_LOGOUT(_name, _mode) \
628static struct iscsi_stat_logout_attribute \
629 iscsi_stat_logout_##_name = \
630 __CONFIGFS_EATTR(_name, _mode, \
631 iscsi_stat_logout_show_attr_##_name, \
632 iscsi_stat_logout_store_attr_##_name);
633
634#define ISCSI_STAT_LOGOUT_RO(_name) \
635static struct iscsi_stat_logout_attribute \
636 iscsi_stat_logout_##_name = \
637 __CONFIGFS_EATTR_RO(_name, \
638 iscsi_stat_logout_show_attr_##_name);
639
640static ssize_t iscsi_stat_logout_show_attr_inst(
641 struct iscsi_wwn_stat_grps *igrps, char *page)
642{ 534{
643 struct iscsi_tiqn *tiqn = container_of(igrps, 535 struct iscsi_wwn_stat_grps *igrps = container_of(to_config_group(item),
644 struct iscsi_tiqn, tiqn_stat_grps); 536 struct iscsi_wwn_stat_grps, iscsi_logout_stats_group);
537 return container_of(igrps, struct iscsi_tiqn, tiqn_stat_grps);
538}
645 539
646 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); 540static ssize_t iscsi_stat_logout_inst_show(struct config_item *item, char *page)
541{
542 return snprintf(page, PAGE_SIZE, "%u\n",
543 iscsi_logout_stat_tiqn(item)->tiqn_index);
647} 544}
648ISCSI_STAT_LOGOUT_RO(inst);
649 545
650static ssize_t iscsi_stat_logout_show_attr_indx( 546static ssize_t iscsi_stat_logout_indx_show(struct config_item *item, char *page)
651 struct iscsi_wwn_stat_grps *igrps, char *page)
652{ 547{
653 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX); 548 return snprintf(page, PAGE_SIZE, "%u\n", ISCSI_NODE_INDEX);
654} 549}
655ISCSI_STAT_LOGOUT_RO(indx);
656 550
657static ssize_t iscsi_stat_logout_show_attr_normal_logouts( 551static ssize_t iscsi_stat_logout_normal_logouts_show(struct config_item *item,
658 struct iscsi_wwn_stat_grps *igrps, char *page) 552 char *page)
659{ 553{
660 struct iscsi_tiqn *tiqn = container_of(igrps, 554 struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
661 struct iscsi_tiqn, tiqn_stat_grps);
662 struct iscsi_logout_stats *lstats = &tiqn->logout_stats; 555 struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
663 556
664 return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts); 557 return snprintf(page, PAGE_SIZE, "%u\n", lstats->normal_logouts);
665} 558}
666ISCSI_STAT_LOGOUT_RO(normal_logouts);
667 559
668static ssize_t iscsi_stat_logout_show_attr_abnormal_logouts( 560static ssize_t iscsi_stat_logout_abnormal_logouts_show(struct config_item *item,
669 struct iscsi_wwn_stat_grps *igrps, char *page) 561 char *page)
670{ 562{
671 struct iscsi_tiqn *tiqn = container_of(igrps, 563 struct iscsi_tiqn *tiqn = iscsi_logout_stat_tiqn(item);
672 struct iscsi_tiqn, tiqn_stat_grps);
673 struct iscsi_logout_stats *lstats = &tiqn->logout_stats; 564 struct iscsi_logout_stats *lstats = &tiqn->logout_stats;
674 565
675 return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts); 566 return snprintf(page, PAGE_SIZE, "%u\n", lstats->abnormal_logouts);
676} 567}
677ISCSI_STAT_LOGOUT_RO(abnormal_logouts);
678 568
679CONFIGFS_EATTR_OPS(iscsi_stat_logout, iscsi_wwn_stat_grps, 569CONFIGFS_ATTR_RO(iscsi_stat_logout_, inst);
680 iscsi_logout_stats_group); 570CONFIGFS_ATTR_RO(iscsi_stat_logout_, indx);
571CONFIGFS_ATTR_RO(iscsi_stat_logout_, normal_logouts);
572CONFIGFS_ATTR_RO(iscsi_stat_logout_, abnormal_logouts);
681 573
682static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = { 574static struct configfs_attribute *iscsi_stat_logout_stats_attrs[] = {
683 &iscsi_stat_logout_inst.attr, 575 &iscsi_stat_logout_attr_inst,
684 &iscsi_stat_logout_indx.attr, 576 &iscsi_stat_logout_attr_indx,
685 &iscsi_stat_logout_normal_logouts.attr, 577 &iscsi_stat_logout_attr_normal_logouts,
686 &iscsi_stat_logout_abnormal_logouts.attr, 578 &iscsi_stat_logout_attr_abnormal_logouts,
687 NULL, 579 NULL,
688}; 580};
689 581
690static struct configfs_item_operations iscsi_stat_logout_stats_item_ops = {
691 .show_attribute = iscsi_stat_logout_attr_show,
692 .store_attribute = iscsi_stat_logout_attr_store,
693};
694
695struct config_item_type iscsi_stat_logout_cit = { 582struct config_item_type iscsi_stat_logout_cit = {
696 .ct_item_ops = &iscsi_stat_logout_stats_item_ops,
697 .ct_attrs = iscsi_stat_logout_stats_attrs, 583 .ct_attrs = iscsi_stat_logout_stats_attrs,
698 .ct_owner = THIS_MODULE, 584 .ct_owner = THIS_MODULE,
699}; 585};
@@ -701,39 +587,26 @@ struct config_item_type iscsi_stat_logout_cit = {
701/* 587/*
702 * Session Stats Table 588 * Session Stats Table
703 */ 589 */
590static struct iscsi_node_acl *iscsi_stat_nacl(struct config_item *item)
591{
592 struct iscsi_node_stat_grps *igrps = container_of(to_config_group(item),
593 struct iscsi_node_stat_grps, iscsi_sess_stats_group);
594 return container_of(igrps, struct iscsi_node_acl, node_stat_grps);
595}
704 596
705CONFIGFS_EATTR_STRUCT(iscsi_stat_sess, iscsi_node_stat_grps); 597static ssize_t iscsi_stat_sess_inst_show(struct config_item *item, char *page)
706#define ISCSI_STAT_SESS(_name, _mode) \ 598{
707static struct iscsi_stat_sess_attribute \ 599 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
708 iscsi_stat_sess_##_name = \
709 __CONFIGFS_EATTR(_name, _mode, \
710 iscsi_stat_sess_show_attr_##_name, \
711 iscsi_stat_sess_store_attr_##_name);
712
713#define ISCSI_STAT_SESS_RO(_name) \
714static struct iscsi_stat_sess_attribute \
715 iscsi_stat_sess_##_name = \
716 __CONFIGFS_EATTR_RO(_name, \
717 iscsi_stat_sess_show_attr_##_name);
718
719static ssize_t iscsi_stat_sess_show_attr_inst(
720 struct iscsi_node_stat_grps *igrps, char *page)
721{
722 struct iscsi_node_acl *acl = container_of(igrps,
723 struct iscsi_node_acl, node_stat_grps);
724 struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn; 600 struct se_wwn *wwn = acl->se_node_acl.se_tpg->se_tpg_wwn;
725 struct iscsi_tiqn *tiqn = container_of(wwn, 601 struct iscsi_tiqn *tiqn = container_of(wwn,
726 struct iscsi_tiqn, tiqn_wwn); 602 struct iscsi_tiqn, tiqn_wwn);
727 603
728 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index); 604 return snprintf(page, PAGE_SIZE, "%u\n", tiqn->tiqn_index);
729} 605}
730ISCSI_STAT_SESS_RO(inst);
731 606
732static ssize_t iscsi_stat_sess_show_attr_node( 607static ssize_t iscsi_stat_sess_node_show(struct config_item *item, char *page)
733 struct iscsi_node_stat_grps *igrps, char *page)
734{ 608{
735 struct iscsi_node_acl *acl = container_of(igrps, 609 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
736 struct iscsi_node_acl, node_stat_grps);
737 struct se_node_acl *se_nacl = &acl->se_node_acl; 610 struct se_node_acl *se_nacl = &acl->se_node_acl;
738 struct iscsi_session *sess; 611 struct iscsi_session *sess;
739 struct se_session *se_sess; 612 struct se_session *se_sess;
@@ -751,13 +624,10 @@ static ssize_t iscsi_stat_sess_show_attr_node(
751 624
752 return ret; 625 return ret;
753} 626}
754ISCSI_STAT_SESS_RO(node);
755 627
756static ssize_t iscsi_stat_sess_show_attr_indx( 628static ssize_t iscsi_stat_sess_indx_show(struct config_item *item, char *page)
757 struct iscsi_node_stat_grps *igrps, char *page)
758{ 629{
759 struct iscsi_node_acl *acl = container_of(igrps, 630 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
760 struct iscsi_node_acl, node_stat_grps);
761 struct se_node_acl *se_nacl = &acl->se_node_acl; 631 struct se_node_acl *se_nacl = &acl->se_node_acl;
762 struct iscsi_session *sess; 632 struct iscsi_session *sess;
763 struct se_session *se_sess; 633 struct se_session *se_sess;
@@ -775,13 +645,11 @@ static ssize_t iscsi_stat_sess_show_attr_indx(
775 645
776 return ret; 646 return ret;
777} 647}
778ISCSI_STAT_SESS_RO(indx);
779 648
780static ssize_t iscsi_stat_sess_show_attr_cmd_pdus( 649static ssize_t iscsi_stat_sess_cmd_pdus_show(struct config_item *item,
781 struct iscsi_node_stat_grps *igrps, char *page) 650 char *page)
782{ 651{
783 struct iscsi_node_acl *acl = container_of(igrps, 652 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
784 struct iscsi_node_acl, node_stat_grps);
785 struct se_node_acl *se_nacl = &acl->se_node_acl; 653 struct se_node_acl *se_nacl = &acl->se_node_acl;
786 struct iscsi_session *sess; 654 struct iscsi_session *sess;
787 struct se_session *se_sess; 655 struct se_session *se_sess;
@@ -799,13 +667,11 @@ static ssize_t iscsi_stat_sess_show_attr_cmd_pdus(
799 667
800 return ret; 668 return ret;
801} 669}
802ISCSI_STAT_SESS_RO(cmd_pdus);
803 670
804static ssize_t iscsi_stat_sess_show_attr_rsp_pdus( 671static ssize_t iscsi_stat_sess_rsp_pdus_show(struct config_item *item,
805 struct iscsi_node_stat_grps *igrps, char *page) 672 char *page)
806{ 673{
807 struct iscsi_node_acl *acl = container_of(igrps, 674 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
808 struct iscsi_node_acl, node_stat_grps);
809 struct se_node_acl *se_nacl = &acl->se_node_acl; 675 struct se_node_acl *se_nacl = &acl->se_node_acl;
810 struct iscsi_session *sess; 676 struct iscsi_session *sess;
811 struct se_session *se_sess; 677 struct se_session *se_sess;
@@ -823,13 +689,11 @@ static ssize_t iscsi_stat_sess_show_attr_rsp_pdus(
823 689
824 return ret; 690 return ret;
825} 691}
826ISCSI_STAT_SESS_RO(rsp_pdus);
827 692
828static ssize_t iscsi_stat_sess_show_attr_txdata_octs( 693static ssize_t iscsi_stat_sess_txdata_octs_show(struct config_item *item,
829 struct iscsi_node_stat_grps *igrps, char *page) 694 char *page)
830{ 695{
831 struct iscsi_node_acl *acl = container_of(igrps, 696 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
832 struct iscsi_node_acl, node_stat_grps);
833 struct se_node_acl *se_nacl = &acl->se_node_acl; 697 struct se_node_acl *se_nacl = &acl->se_node_acl;
834 struct iscsi_session *sess; 698 struct iscsi_session *sess;
835 struct se_session *se_sess; 699 struct se_session *se_sess;
@@ -847,13 +711,11 @@ static ssize_t iscsi_stat_sess_show_attr_txdata_octs(
847 711
848 return ret; 712 return ret;
849} 713}
850ISCSI_STAT_SESS_RO(txdata_octs);
851 714
852static ssize_t iscsi_stat_sess_show_attr_rxdata_octs( 715static ssize_t iscsi_stat_sess_rxdata_octs_show(struct config_item *item,
853 struct iscsi_node_stat_grps *igrps, char *page) 716 char *page)
854{ 717{
855 struct iscsi_node_acl *acl = container_of(igrps, 718 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
856 struct iscsi_node_acl, node_stat_grps);
857 struct se_node_acl *se_nacl = &acl->se_node_acl; 719 struct se_node_acl *se_nacl = &acl->se_node_acl;
858 struct iscsi_session *sess; 720 struct iscsi_session *sess;
859 struct se_session *se_sess; 721 struct se_session *se_sess;
@@ -871,13 +733,11 @@ static ssize_t iscsi_stat_sess_show_attr_rxdata_octs(
871 733
872 return ret; 734 return ret;
873} 735}
874ISCSI_STAT_SESS_RO(rxdata_octs);
875 736
876static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors( 737static ssize_t iscsi_stat_sess_conn_digest_errors_show(struct config_item *item,
877 struct iscsi_node_stat_grps *igrps, char *page) 738 char *page)
878{ 739{
879 struct iscsi_node_acl *acl = container_of(igrps, 740 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
880 struct iscsi_node_acl, node_stat_grps);
881 struct se_node_acl *se_nacl = &acl->se_node_acl; 741 struct se_node_acl *se_nacl = &acl->se_node_acl;
882 struct iscsi_session *sess; 742 struct iscsi_session *sess;
883 struct se_session *se_sess; 743 struct se_session *se_sess;
@@ -895,13 +755,11 @@ static ssize_t iscsi_stat_sess_show_attr_conn_digest_errors(
895 755
896 return ret; 756 return ret;
897} 757}
898ISCSI_STAT_SESS_RO(conn_digest_errors);
899 758
900static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors( 759static ssize_t iscsi_stat_sess_conn_timeout_errors_show(
901 struct iscsi_node_stat_grps *igrps, char *page) 760 struct config_item *item, char *page)
902{ 761{
903 struct iscsi_node_acl *acl = container_of(igrps, 762 struct iscsi_node_acl *acl = iscsi_stat_nacl(item);
904 struct iscsi_node_acl, node_stat_grps);
905 struct se_node_acl *se_nacl = &acl->se_node_acl; 763 struct se_node_acl *se_nacl = &acl->se_node_acl;
906 struct iscsi_session *sess; 764 struct iscsi_session *sess;
907 struct se_session *se_sess; 765 struct se_session *se_sess;
@@ -919,31 +777,31 @@ static ssize_t iscsi_stat_sess_show_attr_conn_timeout_errors(
919 777
920 return ret; 778 return ret;
921} 779}
922ISCSI_STAT_SESS_RO(conn_timeout_errors);
923 780
924CONFIGFS_EATTR_OPS(iscsi_stat_sess, iscsi_node_stat_grps, 781CONFIGFS_ATTR_RO(iscsi_stat_sess_, inst);
925 iscsi_sess_stats_group); 782CONFIGFS_ATTR_RO(iscsi_stat_sess_, node);
783CONFIGFS_ATTR_RO(iscsi_stat_sess_, indx);
784CONFIGFS_ATTR_RO(iscsi_stat_sess_, cmd_pdus);
785CONFIGFS_ATTR_RO(iscsi_stat_sess_, rsp_pdus);
786CONFIGFS_ATTR_RO(iscsi_stat_sess_, txdata_octs);
787CONFIGFS_ATTR_RO(iscsi_stat_sess_, rxdata_octs);
788CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_digest_errors);
789CONFIGFS_ATTR_RO(iscsi_stat_sess_, conn_timeout_errors);
926 790
927static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = { 791static struct configfs_attribute *iscsi_stat_sess_stats_attrs[] = {
928 &iscsi_stat_sess_inst.attr, 792 &iscsi_stat_sess_attr_inst,
929 &iscsi_stat_sess_node.attr, 793 &iscsi_stat_sess_attr_node,
930 &iscsi_stat_sess_indx.attr, 794 &iscsi_stat_sess_attr_indx,
931 &iscsi_stat_sess_cmd_pdus.attr, 795 &iscsi_stat_sess_attr_cmd_pdus,
932 &iscsi_stat_sess_rsp_pdus.attr, 796 &iscsi_stat_sess_attr_rsp_pdus,
933 &iscsi_stat_sess_txdata_octs.attr, 797 &iscsi_stat_sess_attr_txdata_octs,
934 &iscsi_stat_sess_rxdata_octs.attr, 798 &iscsi_stat_sess_attr_rxdata_octs,
935 &iscsi_stat_sess_conn_digest_errors.attr, 799 &iscsi_stat_sess_attr_conn_digest_errors,
936 &iscsi_stat_sess_conn_timeout_errors.attr, 800 &iscsi_stat_sess_attr_conn_timeout_errors,
937 NULL, 801 NULL,
938}; 802};
939 803
940static struct configfs_item_operations iscsi_stat_sess_stats_item_ops = {
941 .show_attribute = iscsi_stat_sess_attr_show,
942 .store_attribute = iscsi_stat_sess_attr_store,
943};
944
945struct config_item_type iscsi_stat_sess_cit = { 804struct config_item_type iscsi_stat_sess_cit = {
946 .ct_item_ops = &iscsi_stat_sess_stats_item_ops,
947 .ct_attrs = iscsi_stat_sess_stats_attrs, 805 .ct_attrs = iscsi_stat_sess_stats_attrs,
948 .ct_owner = THIS_MODULE, 806 .ct_owner = THIS_MODULE,
949}; 807};
diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 5bc85ffed720..999b6eba52e8 100644
--- a/drivers/target/loopback/tcm_loop.c
+++ b/drivers/target/loopback/tcm_loop.c
@@ -34,7 +34,6 @@
34 34
35#include <target/target_core_base.h> 35#include <target/target_core_base.h>
36#include <target/target_core_fabric.h> 36#include <target/target_core_fabric.h>
37#include <target/target_core_fabric_configfs.h>
38 37
39#include "tcm_loop.h" 38#include "tcm_loop.h"
40 39
@@ -763,21 +762,20 @@ static void tcm_loop_port_unlink(
763 762
764/* End items for tcm_loop_port_cit */ 763/* End items for tcm_loop_port_cit */
765 764
766static ssize_t tcm_loop_tpg_attrib_show_fabric_prot_type( 765static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_show(
767 struct se_portal_group *se_tpg, 766 struct config_item *item, char *page)
768 char *page)
769{ 767{
768 struct se_portal_group *se_tpg = attrib_to_tpg(item);
770 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, 769 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg,
771 tl_se_tpg); 770 tl_se_tpg);
772 771
773 return sprintf(page, "%d\n", tl_tpg->tl_fabric_prot_type); 772 return sprintf(page, "%d\n", tl_tpg->tl_fabric_prot_type);
774} 773}
775 774
776static ssize_t tcm_loop_tpg_attrib_store_fabric_prot_type( 775static ssize_t tcm_loop_tpg_attrib_fabric_prot_type_store(
777 struct se_portal_group *se_tpg, 776 struct config_item *item, const char *page, size_t count)
778 const char *page,
779 size_t count)
780{ 777{
778 struct se_portal_group *se_tpg = attrib_to_tpg(item);
781 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg, 779 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, struct tcm_loop_tpg,
782 tl_se_tpg); 780 tl_se_tpg);
783 unsigned long val; 781 unsigned long val;
@@ -796,10 +794,10 @@ static ssize_t tcm_loop_tpg_attrib_store_fabric_prot_type(
796 return count; 794 return count;
797} 795}
798 796
799TF_TPG_ATTRIB_ATTR(tcm_loop, fabric_prot_type, S_IRUGO | S_IWUSR); 797CONFIGFS_ATTR(tcm_loop_tpg_attrib_, fabric_prot_type);
800 798
801static struct configfs_attribute *tcm_loop_tpg_attrib_attrs[] = { 799static struct configfs_attribute *tcm_loop_tpg_attrib_attrs[] = {
802 &tcm_loop_tpg_attrib_fabric_prot_type.attr, 800 &tcm_loop_tpg_attrib_attr_fabric_prot_type,
803 NULL, 801 NULL,
804}; 802};
805 803
@@ -894,10 +892,9 @@ static int tcm_loop_drop_nexus(
894 892
895/* End items for tcm_loop_nexus_cit */ 893/* End items for tcm_loop_nexus_cit */
896 894
897static ssize_t tcm_loop_tpg_show_nexus( 895static ssize_t tcm_loop_tpg_nexus_show(struct config_item *item, char *page)
898 struct se_portal_group *se_tpg,
899 char *page)
900{ 896{
897 struct se_portal_group *se_tpg = to_tpg(item);
901 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, 898 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
902 struct tcm_loop_tpg, tl_se_tpg); 899 struct tcm_loop_tpg, tl_se_tpg);
903 struct tcm_loop_nexus *tl_nexus; 900 struct tcm_loop_nexus *tl_nexus;
@@ -913,11 +910,10 @@ static ssize_t tcm_loop_tpg_show_nexus(
913 return ret; 910 return ret;
914} 911}
915 912
916static ssize_t tcm_loop_tpg_store_nexus( 913static ssize_t tcm_loop_tpg_nexus_store(struct config_item *item,
917 struct se_portal_group *se_tpg, 914 const char *page, size_t count)
918 const char *page,
919 size_t count)
920{ 915{
916 struct se_portal_group *se_tpg = to_tpg(item);
921 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, 917 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
922 struct tcm_loop_tpg, tl_se_tpg); 918 struct tcm_loop_tpg, tl_se_tpg);
923 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba; 919 struct tcm_loop_hba *tl_hba = tl_tpg->tl_hba;
@@ -992,12 +988,10 @@ check_newline:
992 return count; 988 return count;
993} 989}
994 990
995TF_TPG_BASE_ATTR(tcm_loop, nexus, S_IRUGO | S_IWUSR); 991static ssize_t tcm_loop_tpg_transport_status_show(struct config_item *item,
996 992 char *page)
997static ssize_t tcm_loop_tpg_show_transport_status(
998 struct se_portal_group *se_tpg,
999 char *page)
1000{ 993{
994 struct se_portal_group *se_tpg = to_tpg(item);
1001 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, 995 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1002 struct tcm_loop_tpg, tl_se_tpg); 996 struct tcm_loop_tpg, tl_se_tpg);
1003 const char *status = NULL; 997 const char *status = NULL;
@@ -1020,11 +1014,10 @@ static ssize_t tcm_loop_tpg_show_transport_status(
1020 return ret; 1014 return ret;
1021} 1015}
1022 1016
1023static ssize_t tcm_loop_tpg_store_transport_status( 1017static ssize_t tcm_loop_tpg_transport_status_store(struct config_item *item,
1024 struct se_portal_group *se_tpg, 1018 const char *page, size_t count)
1025 const char *page,
1026 size_t count)
1027{ 1019{
1020 struct se_portal_group *se_tpg = to_tpg(item);
1028 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg, 1021 struct tcm_loop_tpg *tl_tpg = container_of(se_tpg,
1029 struct tcm_loop_tpg, tl_se_tpg); 1022 struct tcm_loop_tpg, tl_se_tpg);
1030 1023
@@ -1044,11 +1037,12 @@ static ssize_t tcm_loop_tpg_store_transport_status(
1044 return -EINVAL; 1037 return -EINVAL;
1045} 1038}
1046 1039
1047TF_TPG_BASE_ATTR(tcm_loop, transport_status, S_IRUGO | S_IWUSR); 1040CONFIGFS_ATTR(tcm_loop_tpg_, nexus);
1041CONFIGFS_ATTR(tcm_loop_tpg_, transport_status);
1048 1042
1049static struct configfs_attribute *tcm_loop_tpg_attrs[] = { 1043static struct configfs_attribute *tcm_loop_tpg_attrs[] = {
1050 &tcm_loop_tpg_nexus.attr, 1044 &tcm_loop_tpg_attr_nexus,
1051 &tcm_loop_tpg_transport_status.attr, 1045 &tcm_loop_tpg_attr_transport_status,
1052 NULL, 1046 NULL,
1053}; 1047};
1054 1048
@@ -1216,17 +1210,15 @@ static void tcm_loop_drop_scsi_hba(
1216} 1210}
1217 1211
1218/* Start items for tcm_loop_cit */ 1212/* Start items for tcm_loop_cit */
1219static ssize_t tcm_loop_wwn_show_attr_version( 1213static ssize_t tcm_loop_wwn_version_show(struct config_item *item, char *page)
1220 struct target_fabric_configfs *tf,
1221 char *page)
1222{ 1214{
1223 return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION); 1215 return sprintf(page, "TCM Loopback Fabric module %s\n", TCM_LOOP_VERSION);
1224} 1216}
1225 1217
1226TF_WWN_ATTR_RO(tcm_loop, version); 1218CONFIGFS_ATTR_RO(tcm_loop_wwn_, version);
1227 1219
1228static struct configfs_attribute *tcm_loop_wwn_attrs[] = { 1220static struct configfs_attribute *tcm_loop_wwn_attrs[] = {
1229 &tcm_loop_wwn_version.attr, 1221 &tcm_loop_wwn_attr_version,
1230 NULL, 1222 NULL,
1231}; 1223};
1232 1224
diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
index 0edf320fb685..35f7d31b29d2 100644
--- a/drivers/target/sbp/sbp_target.c
+++ b/drivers/target/sbp/sbp_target.c
@@ -35,8 +35,6 @@
35#include <target/target_core_base.h> 35#include <target/target_core_base.h>
36#include <target/target_core_backend.h> 36#include <target/target_core_backend.h>
37#include <target/target_core_fabric.h> 37#include <target/target_core_fabric.h>
38#include <target/target_core_fabric_configfs.h>
39#include <target/configfs_macros.h>
40#include <asm/unaligned.h> 38#include <asm/unaligned.h>
41 39
42#include "sbp_target.h" 40#include "sbp_target.h"
@@ -2111,24 +2109,21 @@ static void sbp_drop_tport(struct se_wwn *wwn)
2111 kfree(tport); 2109 kfree(tport);
2112} 2110}
2113 2111
2114static ssize_t sbp_wwn_show_attr_version( 2112static ssize_t sbp_wwn_version_show(struct config_item *item, char *page)
2115 struct target_fabric_configfs *tf,
2116 char *page)
2117{ 2113{
2118 return sprintf(page, "FireWire SBP fabric module %s\n", SBP_VERSION); 2114 return sprintf(page, "FireWire SBP fabric module %s\n", SBP_VERSION);
2119} 2115}
2120 2116
2121TF_WWN_ATTR_RO(sbp, version); 2117CONFIGFS_ATTR_RO(sbp_wwn_, version);
2122 2118
2123static struct configfs_attribute *sbp_wwn_attrs[] = { 2119static struct configfs_attribute *sbp_wwn_attrs[] = {
2124 &sbp_wwn_version.attr, 2120 &sbp_wwn_attr_version,
2125 NULL, 2121 NULL,
2126}; 2122};
2127 2123
2128static ssize_t sbp_tpg_show_directory_id( 2124static ssize_t sbp_tpg_directory_id_show(struct config_item *item, char *page)
2129 struct se_portal_group *se_tpg,
2130 char *page)
2131{ 2125{
2126 struct se_portal_group *se_tpg = to_tpg(item);
2132 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2127 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2133 struct sbp_tport *tport = tpg->tport; 2128 struct sbp_tport *tport = tpg->tport;
2134 2129
@@ -2138,11 +2133,10 @@ static ssize_t sbp_tpg_show_directory_id(
2138 return sprintf(page, "%06x\n", tport->directory_id); 2133 return sprintf(page, "%06x\n", tport->directory_id);
2139} 2134}
2140 2135
2141static ssize_t sbp_tpg_store_directory_id( 2136static ssize_t sbp_tpg_directory_id_store(struct config_item *item,
2142 struct se_portal_group *se_tpg, 2137 const char *page, size_t count)
2143 const char *page,
2144 size_t count)
2145{ 2138{
2139 struct se_portal_group *se_tpg = to_tpg(item);
2146 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2140 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2147 struct sbp_tport *tport = tpg->tport; 2141 struct sbp_tport *tport = tpg->tport;
2148 unsigned long val; 2142 unsigned long val;
@@ -2166,20 +2160,18 @@ static ssize_t sbp_tpg_store_directory_id(
2166 return count; 2160 return count;
2167} 2161}
2168 2162
2169static ssize_t sbp_tpg_show_enable( 2163static ssize_t sbp_tpg_enable_show(struct config_item *item, char *page)
2170 struct se_portal_group *se_tpg,
2171 char *page)
2172{ 2164{
2165 struct se_portal_group *se_tpg = to_tpg(item);
2173 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2166 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2174 struct sbp_tport *tport = tpg->tport; 2167 struct sbp_tport *tport = tpg->tport;
2175 return sprintf(page, "%d\n", tport->enable); 2168 return sprintf(page, "%d\n", tport->enable);
2176} 2169}
2177 2170
2178static ssize_t sbp_tpg_store_enable( 2171static ssize_t sbp_tpg_enable_store(struct config_item *item,
2179 struct se_portal_group *se_tpg, 2172 const char *page, size_t count)
2180 const char *page,
2181 size_t count)
2182{ 2173{
2174 struct se_portal_group *se_tpg = to_tpg(item);
2183 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2175 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2184 struct sbp_tport *tport = tpg->tport; 2176 struct sbp_tport *tport = tpg->tport;
2185 unsigned long val; 2177 unsigned long val;
@@ -2219,29 +2211,28 @@ static ssize_t sbp_tpg_store_enable(
2219 return count; 2211 return count;
2220} 2212}
2221 2213
2222TF_TPG_BASE_ATTR(sbp, directory_id, S_IRUGO | S_IWUSR); 2214CONFIGFS_ATTR(sbp_tpg_, directory_id);
2223TF_TPG_BASE_ATTR(sbp, enable, S_IRUGO | S_IWUSR); 2215CONFIGFS_ATTR(sbp_tpg_, enable);
2224 2216
2225static struct configfs_attribute *sbp_tpg_base_attrs[] = { 2217static struct configfs_attribute *sbp_tpg_base_attrs[] = {
2226 &sbp_tpg_directory_id.attr, 2218 &sbp_tpg_attr_directory_id,
2227 &sbp_tpg_enable.attr, 2219 &sbp_tpg_attr_enable,
2228 NULL, 2220 NULL,
2229}; 2221};
2230 2222
2231static ssize_t sbp_tpg_attrib_show_mgt_orb_timeout( 2223static ssize_t sbp_tpg_attrib_mgt_orb_timeout_show(struct config_item *item,
2232 struct se_portal_group *se_tpg,
2233 char *page) 2224 char *page)
2234{ 2225{
2226 struct se_portal_group *se_tpg = attrib_to_tpg(item);
2235 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2227 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2236 struct sbp_tport *tport = tpg->tport; 2228 struct sbp_tport *tport = tpg->tport;
2237 return sprintf(page, "%d\n", tport->mgt_orb_timeout); 2229 return sprintf(page, "%d\n", tport->mgt_orb_timeout);
2238} 2230}
2239 2231
2240static ssize_t sbp_tpg_attrib_store_mgt_orb_timeout( 2232static ssize_t sbp_tpg_attrib_mgt_orb_timeout_store(struct config_item *item,
2241 struct se_portal_group *se_tpg, 2233 const char *page, size_t count)
2242 const char *page,
2243 size_t count)
2244{ 2234{
2235 struct se_portal_group *se_tpg = attrib_to_tpg(item);
2245 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2236 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2246 struct sbp_tport *tport = tpg->tport; 2237 struct sbp_tport *tport = tpg->tport;
2247 unsigned long val; 2238 unsigned long val;
@@ -2264,20 +2255,19 @@ static ssize_t sbp_tpg_attrib_store_mgt_orb_timeout(
2264 return count; 2255 return count;
2265} 2256}
2266 2257
2267static ssize_t sbp_tpg_attrib_show_max_reconnect_timeout( 2258static ssize_t sbp_tpg_attrib_max_reconnect_timeout_show(struct config_item *item,
2268 struct se_portal_group *se_tpg,
2269 char *page) 2259 char *page)
2270{ 2260{
2261 struct se_portal_group *se_tpg = attrib_to_tpg(item);
2271 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2262 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2272 struct sbp_tport *tport = tpg->tport; 2263 struct sbp_tport *tport = tpg->tport;
2273 return sprintf(page, "%d\n", tport->max_reconnect_timeout); 2264 return sprintf(page, "%d\n", tport->max_reconnect_timeout);
2274} 2265}
2275 2266
2276static ssize_t sbp_tpg_attrib_store_max_reconnect_timeout( 2267static ssize_t sbp_tpg_attrib_max_reconnect_timeout_store(struct config_item *item,
2277 struct se_portal_group *se_tpg, 2268 const char *page, size_t count)
2278 const char *page,
2279 size_t count)
2280{ 2269{
2270 struct se_portal_group *se_tpg = attrib_to_tpg(item);
2281 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2271 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2282 struct sbp_tport *tport = tpg->tport; 2272 struct sbp_tport *tport = tpg->tport;
2283 unsigned long val; 2273 unsigned long val;
@@ -2300,20 +2290,19 @@ static ssize_t sbp_tpg_attrib_store_max_reconnect_timeout(
2300 return count; 2290 return count;
2301} 2291}
2302 2292
2303static ssize_t sbp_tpg_attrib_show_max_logins_per_lun( 2293static ssize_t sbp_tpg_attrib_max_logins_per_lun_show(struct config_item *item,
2304 struct se_portal_group *se_tpg,
2305 char *page) 2294 char *page)
2306{ 2295{
2296 struct se_portal_group *se_tpg = attrib_to_tpg(item);
2307 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2297 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2308 struct sbp_tport *tport = tpg->tport; 2298 struct sbp_tport *tport = tpg->tport;
2309 return sprintf(page, "%d\n", tport->max_logins_per_lun); 2299 return sprintf(page, "%d\n", tport->max_logins_per_lun);
2310} 2300}
2311 2301
2312static ssize_t sbp_tpg_attrib_store_max_logins_per_lun( 2302static ssize_t sbp_tpg_attrib_max_logins_per_lun_store(struct config_item *item,
2313 struct se_portal_group *se_tpg, 2303 const char *page, size_t count)
2314 const char *page,
2315 size_t count)
2316{ 2304{
2305 struct se_portal_group *se_tpg = attrib_to_tpg(item);
2317 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg); 2306 struct sbp_tpg *tpg = container_of(se_tpg, struct sbp_tpg, se_tpg);
2318 struct sbp_tport *tport = tpg->tport; 2307 struct sbp_tport *tport = tpg->tport;
2319 unsigned long val; 2308 unsigned long val;
@@ -2330,14 +2319,14 @@ static ssize_t sbp_tpg_attrib_store_max_logins_per_lun(
2330 return count; 2319 return count;
2331} 2320}
2332 2321
2333TF_TPG_ATTRIB_ATTR(sbp, mgt_orb_timeout, S_IRUGO | S_IWUSR); 2322CONFIGFS_ATTR(sbp_tpg_attrib_, mgt_orb_timeout);
2334TF_TPG_ATTRIB_ATTR(sbp, max_reconnect_timeout, S_IRUGO | S_IWUSR); 2323CONFIGFS_ATTR(sbp_tpg_attrib_, max_reconnect_timeout);
2335TF_TPG_ATTRIB_ATTR(sbp, max_logins_per_lun, S_IRUGO | S_IWUSR); 2324CONFIGFS_ATTR(sbp_tpg_attrib_, max_logins_per_lun);
2336 2325
2337static struct configfs_attribute *sbp_tpg_attrib_attrs[] = { 2326static struct configfs_attribute *sbp_tpg_attrib_attrs[] = {
2338 &sbp_tpg_attrib_mgt_orb_timeout.attr, 2327 &sbp_tpg_attrib_attr_mgt_orb_timeout,
2339 &sbp_tpg_attrib_max_reconnect_timeout.attr, 2328 &sbp_tpg_attrib_attr_max_reconnect_timeout,
2340 &sbp_tpg_attrib_max_logins_per_lun.attr, 2329 &sbp_tpg_attrib_attr_max_logins_per_lun,
2341 NULL, 2330 NULL,
2342}; 2331};
2343 2332
diff --git a/drivers/target/target_core_configfs.c b/drivers/target/target_core_configfs.c
index 860e84046177..b9b9ffde4c7a 100644
--- a/drivers/target/target_core_configfs.c
+++ b/drivers/target/target_core_configfs.c
@@ -40,8 +40,6 @@
40#include <target/target_core_base.h> 40#include <target/target_core_base.h>
41#include <target/target_core_backend.h> 41#include <target/target_core_backend.h>
42#include <target/target_core_fabric.h> 42#include <target/target_core_fabric.h>
43#include <target/target_core_fabric_configfs.h>
44#include <target/configfs_macros.h>
45 43
46#include "target_core_internal.h" 44#include "target_core_internal.h"
47#include "target_core_alua.h" 45#include "target_core_alua.h"
@@ -78,12 +76,6 @@ extern struct t10_alua_lu_gp *default_lu_gp;
78static LIST_HEAD(g_tf_list); 76static LIST_HEAD(g_tf_list);
79static DEFINE_MUTEX(g_tf_lock); 77static DEFINE_MUTEX(g_tf_lock);
80 78
81struct target_core_configfs_attribute {
82 struct configfs_attribute attr;
83 ssize_t (*show)(void *, char *);
84 ssize_t (*store)(void *, const char *, size_t);
85};
86
87static struct config_group target_core_hbagroup; 79static struct config_group target_core_hbagroup;
88static struct config_group alua_group; 80static struct config_group alua_group;
89static struct config_group alua_lu_gps_group; 81static struct config_group alua_lu_gps_group;
@@ -97,24 +89,15 @@ item_to_hba(struct config_item *item)
97/* 89/*
98 * Attributes for /sys/kernel/config/target/ 90 * Attributes for /sys/kernel/config/target/
99 */ 91 */
100static ssize_t target_core_attr_show(struct config_item *item, 92static ssize_t target_core_item_version_show(struct config_item *item,
101 struct configfs_attribute *attr, 93 char *page)
102 char *page)
103{ 94{
104 return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s" 95 return sprintf(page, "Target Engine Core ConfigFS Infrastructure %s"
105 " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_VERSION, 96 " on %s/%s on "UTS_RELEASE"\n", TARGET_CORE_VERSION,
106 utsname()->sysname, utsname()->machine); 97 utsname()->sysname, utsname()->machine);
107} 98}
108 99
109static struct configfs_item_operations target_core_fabric_item_ops = { 100CONFIGFS_ATTR_RO(target_core_item_, version);
110 .show_attribute = target_core_attr_show,
111};
112
113static struct configfs_attribute target_core_item_attr_version = {
114 .ca_owner = THIS_MODULE,
115 .ca_name = "version",
116 .ca_mode = S_IRUGO,
117};
118 101
119static struct target_fabric_configfs *target_core_get_fabric( 102static struct target_fabric_configfs *target_core_get_fabric(
120 const char *name) 103 const char *name)
@@ -273,7 +256,6 @@ static struct configfs_attribute *target_core_fabric_item_attrs[] = {
273 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/ 256 * Provides Fabrics Groups and Item Attributes for /sys/kernel/config/target/
274 */ 257 */
275static struct config_item_type target_core_fabrics_item = { 258static struct config_item_type target_core_fabrics_item = {
276 .ct_item_ops = &target_core_fabric_item_ops,
277 .ct_group_ops = &target_core_fabric_group_ops, 259 .ct_group_ops = &target_core_fabric_group_ops,
278 .ct_attrs = target_core_fabric_item_attrs, 260 .ct_attrs = target_core_fabric_item_attrs,
279 .ct_owner = THIS_MODULE, 261 .ct_owner = THIS_MODULE,
@@ -476,47 +458,54 @@ EXPORT_SYMBOL(target_unregister_template);
476// Stop functions called by external Target Fabrics Modules 458// Stop functions called by external Target Fabrics Modules
477//############################################################################*/ 459//############################################################################*/
478 460
461static inline struct se_dev_attrib *to_attrib(struct config_item *item)
462{
463 return container_of(to_config_group(item), struct se_dev_attrib,
464 da_group);
465}
466
479/* Start functions for struct config_item_type tb_dev_attrib_cit */ 467/* Start functions for struct config_item_type tb_dev_attrib_cit */
480#define DEF_TB_DEV_ATTRIB_SHOW(_name) \ 468#define DEF_CONFIGFS_ATTRIB_SHOW(_name) \
481static ssize_t show_##_name(struct se_dev_attrib *da, char *page) \ 469static ssize_t _name##_show(struct config_item *item, char *page) \
482{ \ 470{ \
483 return snprintf(page, PAGE_SIZE, "%u\n", da->_name); \ 471 return snprintf(page, PAGE_SIZE, "%u\n", to_attrib(item)->_name); \
484} 472}
485 473
486DEF_TB_DEV_ATTRIB_SHOW(emulate_model_alias); 474DEF_CONFIGFS_ATTRIB_SHOW(emulate_model_alias);
487DEF_TB_DEV_ATTRIB_SHOW(emulate_dpo); 475DEF_CONFIGFS_ATTRIB_SHOW(emulate_dpo);
488DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_write); 476DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_write);
489DEF_TB_DEV_ATTRIB_SHOW(emulate_fua_read); 477DEF_CONFIGFS_ATTRIB_SHOW(emulate_fua_read);
490DEF_TB_DEV_ATTRIB_SHOW(emulate_write_cache); 478DEF_CONFIGFS_ATTRIB_SHOW(emulate_write_cache);
491DEF_TB_DEV_ATTRIB_SHOW(emulate_ua_intlck_ctrl); 479DEF_CONFIGFS_ATTRIB_SHOW(emulate_ua_intlck_ctrl);
492DEF_TB_DEV_ATTRIB_SHOW(emulate_tas); 480DEF_CONFIGFS_ATTRIB_SHOW(emulate_tas);
493DEF_TB_DEV_ATTRIB_SHOW(emulate_tpu); 481DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpu);
494DEF_TB_DEV_ATTRIB_SHOW(emulate_tpws); 482DEF_CONFIGFS_ATTRIB_SHOW(emulate_tpws);
495DEF_TB_DEV_ATTRIB_SHOW(emulate_caw); 483DEF_CONFIGFS_ATTRIB_SHOW(emulate_caw);
496DEF_TB_DEV_ATTRIB_SHOW(emulate_3pc); 484DEF_CONFIGFS_ATTRIB_SHOW(emulate_3pc);
497DEF_TB_DEV_ATTRIB_SHOW(pi_prot_type); 485DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_type);
498DEF_TB_DEV_ATTRIB_SHOW(hw_pi_prot_type); 486DEF_CONFIGFS_ATTRIB_SHOW(hw_pi_prot_type);
499DEF_TB_DEV_ATTRIB_SHOW(pi_prot_format); 487DEF_CONFIGFS_ATTRIB_SHOW(pi_prot_format);
500DEF_TB_DEV_ATTRIB_SHOW(enforce_pr_isids); 488DEF_CONFIGFS_ATTRIB_SHOW(enforce_pr_isids);
501DEF_TB_DEV_ATTRIB_SHOW(is_nonrot); 489DEF_CONFIGFS_ATTRIB_SHOW(is_nonrot);
502DEF_TB_DEV_ATTRIB_SHOW(emulate_rest_reord); 490DEF_CONFIGFS_ATTRIB_SHOW(emulate_rest_reord);
503DEF_TB_DEV_ATTRIB_SHOW(force_pr_aptpl); 491DEF_CONFIGFS_ATTRIB_SHOW(force_pr_aptpl);
504DEF_TB_DEV_ATTRIB_SHOW(hw_block_size); 492DEF_CONFIGFS_ATTRIB_SHOW(hw_block_size);
505DEF_TB_DEV_ATTRIB_SHOW(block_size); 493DEF_CONFIGFS_ATTRIB_SHOW(block_size);
506DEF_TB_DEV_ATTRIB_SHOW(hw_max_sectors); 494DEF_CONFIGFS_ATTRIB_SHOW(hw_max_sectors);
507DEF_TB_DEV_ATTRIB_SHOW(optimal_sectors); 495DEF_CONFIGFS_ATTRIB_SHOW(optimal_sectors);
508DEF_TB_DEV_ATTRIB_SHOW(hw_queue_depth); 496DEF_CONFIGFS_ATTRIB_SHOW(hw_queue_depth);
509DEF_TB_DEV_ATTRIB_SHOW(queue_depth); 497DEF_CONFIGFS_ATTRIB_SHOW(queue_depth);
510DEF_TB_DEV_ATTRIB_SHOW(max_unmap_lba_count); 498DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_lba_count);
511DEF_TB_DEV_ATTRIB_SHOW(max_unmap_block_desc_count); 499DEF_CONFIGFS_ATTRIB_SHOW(max_unmap_block_desc_count);
512DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity); 500DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity);
513DEF_TB_DEV_ATTRIB_SHOW(unmap_granularity_alignment); 501DEF_CONFIGFS_ATTRIB_SHOW(unmap_granularity_alignment);
514DEF_TB_DEV_ATTRIB_SHOW(max_write_same_len); 502DEF_CONFIGFS_ATTRIB_SHOW(max_write_same_len);
515 503
516#define DEF_TB_DEV_ATTRIB_STORE_U32(_name) \ 504#define DEF_CONFIGFS_ATTRIB_STORE_U32(_name) \
517static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ 505static ssize_t _name##_store(struct config_item *item, const char *page,\
518 size_t count) \ 506 size_t count) \
519{ \ 507{ \
508 struct se_dev_attrib *da = to_attrib(item); \
520 u32 val; \ 509 u32 val; \
521 int ret; \ 510 int ret; \
522 \ 511 \
@@ -527,16 +516,17 @@ static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\
527 return count; \ 516 return count; \
528} 517}
529 518
530DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_lba_count); 519DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_lba_count);
531DEF_TB_DEV_ATTRIB_STORE_U32(max_unmap_block_desc_count); 520DEF_CONFIGFS_ATTRIB_STORE_U32(max_unmap_block_desc_count);
532DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity); 521DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity);
533DEF_TB_DEV_ATTRIB_STORE_U32(unmap_granularity_alignment); 522DEF_CONFIGFS_ATTRIB_STORE_U32(unmap_granularity_alignment);
534DEF_TB_DEV_ATTRIB_STORE_U32(max_write_same_len); 523DEF_CONFIGFS_ATTRIB_STORE_U32(max_write_same_len);
535 524
536#define DEF_TB_DEV_ATTRIB_STORE_BOOL(_name) \ 525#define DEF_CONFIGFS_ATTRIB_STORE_BOOL(_name) \
537static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ 526static ssize_t _name##_store(struct config_item *item, const char *page, \
538 size_t count) \ 527 size_t count) \
539{ \ 528{ \
529 struct se_dev_attrib *da = to_attrib(item); \
540 bool flag; \ 530 bool flag; \
541 int ret; \ 531 int ret; \
542 \ 532 \
@@ -547,14 +537,14 @@ static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\
547 return count; \ 537 return count; \
548} 538}
549 539
550DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_fua_write); 540DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_fua_write);
551DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_caw); 541DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_caw);
552DEF_TB_DEV_ATTRIB_STORE_BOOL(emulate_3pc); 542DEF_CONFIGFS_ATTRIB_STORE_BOOL(emulate_3pc);
553DEF_TB_DEV_ATTRIB_STORE_BOOL(enforce_pr_isids); 543DEF_CONFIGFS_ATTRIB_STORE_BOOL(enforce_pr_isids);
554DEF_TB_DEV_ATTRIB_STORE_BOOL(is_nonrot); 544DEF_CONFIGFS_ATTRIB_STORE_BOOL(is_nonrot);
555 545
556#define DEF_TB_DEV_ATTRIB_STORE_STUB(_name) \ 546#define DEF_CONFIGFS_ATTRIB_STORE_STUB(_name) \
557static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\ 547static ssize_t _name##_store(struct config_item *item, const char *page,\
558 size_t count) \ 548 size_t count) \
559{ \ 549{ \
560 printk_once(KERN_WARNING \ 550 printk_once(KERN_WARNING \
@@ -562,8 +552,8 @@ static ssize_t store_##_name(struct se_dev_attrib *da, const char *page,\
562 return count; \ 552 return count; \
563} 553}
564 554
565DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_dpo); 555DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_dpo);
566DEF_TB_DEV_ATTRIB_STORE_STUB(emulate_fua_read); 556DEF_CONFIGFS_ATTRIB_STORE_STUB(emulate_fua_read);
567 557
568static void dev_set_t10_wwn_model_alias(struct se_device *dev) 558static void dev_set_t10_wwn_model_alias(struct se_device *dev)
569{ 559{
@@ -578,9 +568,10 @@ static void dev_set_t10_wwn_model_alias(struct se_device *dev)
578 snprintf(&dev->t10_wwn.model[0], 16, "%s", configname); 568 snprintf(&dev->t10_wwn.model[0], 16, "%s", configname);
579} 569}
580 570
581static ssize_t store_emulate_model_alias(struct se_dev_attrib *da, 571static ssize_t emulate_model_alias_store(struct config_item *item,
582 const char *page, size_t count) 572 const char *page, size_t count)
583{ 573{
574 struct se_dev_attrib *da = to_attrib(item);
584 struct se_device *dev = da->da_dev; 575 struct se_device *dev = da->da_dev;
585 bool flag; 576 bool flag;
586 int ret; 577 int ret;
@@ -606,9 +597,10 @@ static ssize_t store_emulate_model_alias(struct se_dev_attrib *da,
606 return count; 597 return count;
607} 598}
608 599
609static ssize_t store_emulate_write_cache(struct se_dev_attrib *da, 600static ssize_t emulate_write_cache_store(struct config_item *item,
610 const char *page, size_t count) 601 const char *page, size_t count)
611{ 602{
603 struct se_dev_attrib *da = to_attrib(item);
612 bool flag; 604 bool flag;
613 int ret; 605 int ret;
614 606
@@ -627,9 +619,10 @@ static ssize_t store_emulate_write_cache(struct se_dev_attrib *da,
627 return count; 619 return count;
628} 620}
629 621
630static ssize_t store_emulate_ua_intlck_ctrl(struct se_dev_attrib *da, 622static ssize_t emulate_ua_intlck_ctrl_store(struct config_item *item,
631 const char *page, size_t count) 623 const char *page, size_t count)
632{ 624{
625 struct se_dev_attrib *da = to_attrib(item);
633 u32 val; 626 u32 val;
634 int ret; 627 int ret;
635 628
@@ -654,9 +647,10 @@ static ssize_t store_emulate_ua_intlck_ctrl(struct se_dev_attrib *da,
654 return count; 647 return count;
655} 648}
656 649
657static ssize_t store_emulate_tas(struct se_dev_attrib *da, 650static ssize_t emulate_tas_store(struct config_item *item,
658 const char *page, size_t count) 651 const char *page, size_t count)
659{ 652{
653 struct se_dev_attrib *da = to_attrib(item);
660 bool flag; 654 bool flag;
661 int ret; 655 int ret;
662 656
@@ -677,9 +671,10 @@ static ssize_t store_emulate_tas(struct se_dev_attrib *da,
677 return count; 671 return count;
678} 672}
679 673
680static ssize_t store_emulate_tpu(struct se_dev_attrib *da, 674static ssize_t emulate_tpu_store(struct config_item *item,
681 const char *page, size_t count) 675 const char *page, size_t count)
682{ 676{
677 struct se_dev_attrib *da = to_attrib(item);
683 bool flag; 678 bool flag;
684 int ret; 679 int ret;
685 680
@@ -702,9 +697,10 @@ static ssize_t store_emulate_tpu(struct se_dev_attrib *da,
702 return count; 697 return count;
703} 698}
704 699
705static ssize_t store_emulate_tpws(struct se_dev_attrib *da, 700static ssize_t emulate_tpws_store(struct config_item *item,
706 const char *page, size_t count) 701 const char *page, size_t count)
707{ 702{
703 struct se_dev_attrib *da = to_attrib(item);
708 bool flag; 704 bool flag;
709 int ret; 705 int ret;
710 706
@@ -727,9 +723,10 @@ static ssize_t store_emulate_tpws(struct se_dev_attrib *da,
727 return count; 723 return count;
728} 724}
729 725
730static ssize_t store_pi_prot_type(struct se_dev_attrib *da, 726static ssize_t pi_prot_type_store(struct config_item *item,
731 const char *page, size_t count) 727 const char *page, size_t count)
732{ 728{
729 struct se_dev_attrib *da = to_attrib(item);
733 int old_prot = da->pi_prot_type, ret; 730 int old_prot = da->pi_prot_type, ret;
734 struct se_device *dev = da->da_dev; 731 struct se_device *dev = da->da_dev;
735 u32 flag; 732 u32 flag;
@@ -787,9 +784,10 @@ static ssize_t store_pi_prot_type(struct se_dev_attrib *da,
787 return count; 784 return count;
788} 785}
789 786
790static ssize_t store_pi_prot_format(struct se_dev_attrib *da, 787static ssize_t pi_prot_format_store(struct config_item *item,
791 const char *page, size_t count) 788 const char *page, size_t count)
792{ 789{
790 struct se_dev_attrib *da = to_attrib(item);
793 struct se_device *dev = da->da_dev; 791 struct se_device *dev = da->da_dev;
794 bool flag; 792 bool flag;
795 int ret; 793 int ret;
@@ -824,9 +822,10 @@ static ssize_t store_pi_prot_format(struct se_dev_attrib *da,
824 return count; 822 return count;
825} 823}
826 824
827static ssize_t store_force_pr_aptpl(struct se_dev_attrib *da, 825static ssize_t force_pr_aptpl_store(struct config_item *item,
828 const char *page, size_t count) 826 const char *page, size_t count)
829{ 827{
828 struct se_dev_attrib *da = to_attrib(item);
830 bool flag; 829 bool flag;
831 int ret; 830 int ret;
832 831
@@ -845,9 +844,10 @@ static ssize_t store_force_pr_aptpl(struct se_dev_attrib *da,
845 return count; 844 return count;
846} 845}
847 846
848static ssize_t store_emulate_rest_reord(struct se_dev_attrib *da, 847static ssize_t emulate_rest_reord_store(struct config_item *item,
849 const char *page, size_t count) 848 const char *page, size_t count)
850{ 849{
850 struct se_dev_attrib *da = to_attrib(item);
851 bool flag; 851 bool flag;
852 int ret; 852 int ret;
853 853
@@ -869,9 +869,10 @@ static ssize_t store_emulate_rest_reord(struct se_dev_attrib *da,
869/* 869/*
870 * Note, this can only be called on unexported SE Device Object. 870 * Note, this can only be called on unexported SE Device Object.
871 */ 871 */
872static ssize_t store_queue_depth(struct se_dev_attrib *da, 872static ssize_t queue_depth_store(struct config_item *item,
873 const char *page, size_t count) 873 const char *page, size_t count)
874{ 874{
875 struct se_dev_attrib *da = to_attrib(item);
875 struct se_device *dev = da->da_dev; 876 struct se_device *dev = da->da_dev;
876 u32 val; 877 u32 val;
877 int ret; 878 int ret;
@@ -905,9 +906,10 @@ static ssize_t store_queue_depth(struct se_dev_attrib *da,
905 return count; 906 return count;
906} 907}
907 908
908static ssize_t store_optimal_sectors(struct se_dev_attrib *da, 909static ssize_t optimal_sectors_store(struct config_item *item,
909 const char *page, size_t count) 910 const char *page, size_t count)
910{ 911{
912 struct se_dev_attrib *da = to_attrib(item);
911 u32 val; 913 u32 val;
912 int ret; 914 int ret;
913 915
@@ -934,9 +936,10 @@ static ssize_t store_optimal_sectors(struct se_dev_attrib *da,
934 return count; 936 return count;
935} 937}
936 938
937static ssize_t store_block_size(struct se_dev_attrib *da, 939static ssize_t block_size_store(struct config_item *item,
938 const char *page, size_t count) 940 const char *page, size_t count)
939{ 941{
942 struct se_dev_attrib *da = to_attrib(item);
940 u32 val; 943 u32 val;
941 int ret; 944 int ret;
942 945
@@ -967,50 +970,35 @@ static ssize_t store_block_size(struct se_dev_attrib *da,
967 return count; 970 return count;
968} 971}
969 972
970CONFIGFS_EATTR_STRUCT(target_backend_dev_attrib, se_dev_attrib); 973CONFIGFS_ATTR(, emulate_model_alias);
971#define TB_DEV_ATTR(_backend, _name, _mode) \ 974CONFIGFS_ATTR(, emulate_dpo);
972static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 975CONFIGFS_ATTR(, emulate_fua_write);
973 __CONFIGFS_EATTR(_name, _mode, \ 976CONFIGFS_ATTR(, emulate_fua_read);
974 show_##_name, \ 977CONFIGFS_ATTR(, emulate_write_cache);
975 store_##_name); 978CONFIGFS_ATTR(, emulate_ua_intlck_ctrl);
976 979CONFIGFS_ATTR(, emulate_tas);
977#define TB_DEV_ATTR_RO(_backend, _name) \ 980CONFIGFS_ATTR(, emulate_tpu);
978static struct target_backend_dev_attrib_attribute _backend##_dev_attrib_##_name = \ 981CONFIGFS_ATTR(, emulate_tpws);
979 __CONFIGFS_EATTR_RO(_name, \ 982CONFIGFS_ATTR(, emulate_caw);
980 show_##_name); 983CONFIGFS_ATTR(, emulate_3pc);
981 984CONFIGFS_ATTR(, pi_prot_type);
982TB_DEV_ATTR(target_core, emulate_model_alias, S_IRUGO | S_IWUSR); 985CONFIGFS_ATTR_RO(, hw_pi_prot_type);
983TB_DEV_ATTR(target_core, emulate_dpo, S_IRUGO | S_IWUSR); 986CONFIGFS_ATTR(, pi_prot_format);
984TB_DEV_ATTR(target_core, emulate_fua_write, S_IRUGO | S_IWUSR); 987CONFIGFS_ATTR(, enforce_pr_isids);
985TB_DEV_ATTR(target_core, emulate_fua_read, S_IRUGO | S_IWUSR); 988CONFIGFS_ATTR(, is_nonrot);
986TB_DEV_ATTR(target_core, emulate_write_cache, S_IRUGO | S_IWUSR); 989CONFIGFS_ATTR(, emulate_rest_reord);
987TB_DEV_ATTR(target_core, emulate_ua_intlck_ctrl, S_IRUGO | S_IWUSR); 990CONFIGFS_ATTR(, force_pr_aptpl);
988TB_DEV_ATTR(target_core, emulate_tas, S_IRUGO | S_IWUSR); 991CONFIGFS_ATTR_RO(, hw_block_size);
989TB_DEV_ATTR(target_core, emulate_tpu, S_IRUGO | S_IWUSR); 992CONFIGFS_ATTR(, block_size);
990TB_DEV_ATTR(target_core, emulate_tpws, S_IRUGO | S_IWUSR); 993CONFIGFS_ATTR_RO(, hw_max_sectors);
991TB_DEV_ATTR(target_core, emulate_caw, S_IRUGO | S_IWUSR); 994CONFIGFS_ATTR(, optimal_sectors);
992TB_DEV_ATTR(target_core, emulate_3pc, S_IRUGO | S_IWUSR); 995CONFIGFS_ATTR_RO(, hw_queue_depth);
993TB_DEV_ATTR(target_core, pi_prot_type, S_IRUGO | S_IWUSR); 996CONFIGFS_ATTR(, queue_depth);
994TB_DEV_ATTR_RO(target_core, hw_pi_prot_type); 997CONFIGFS_ATTR(, max_unmap_lba_count);
995TB_DEV_ATTR(target_core, pi_prot_format, S_IRUGO | S_IWUSR); 998CONFIGFS_ATTR(, max_unmap_block_desc_count);
996TB_DEV_ATTR(target_core, enforce_pr_isids, S_IRUGO | S_IWUSR); 999CONFIGFS_ATTR(, unmap_granularity);
997TB_DEV_ATTR(target_core, is_nonrot, S_IRUGO | S_IWUSR); 1000CONFIGFS_ATTR(, unmap_granularity_alignment);
998TB_DEV_ATTR(target_core, emulate_rest_reord, S_IRUGO | S_IWUSR); 1001CONFIGFS_ATTR(, max_write_same_len);
999TB_DEV_ATTR(target_core, force_pr_aptpl, S_IRUGO | S_IWUSR)
1000TB_DEV_ATTR_RO(target_core, hw_block_size);
1001TB_DEV_ATTR(target_core, block_size, S_IRUGO | S_IWUSR)
1002TB_DEV_ATTR_RO(target_core, hw_max_sectors);
1003TB_DEV_ATTR(target_core, optimal_sectors, S_IRUGO | S_IWUSR);
1004TB_DEV_ATTR_RO(target_core, hw_queue_depth);
1005TB_DEV_ATTR(target_core, queue_depth, S_IRUGO | S_IWUSR);
1006TB_DEV_ATTR(target_core, max_unmap_lba_count, S_IRUGO | S_IWUSR);
1007TB_DEV_ATTR(target_core, max_unmap_block_desc_count, S_IRUGO | S_IWUSR);
1008TB_DEV_ATTR(target_core, unmap_granularity, S_IRUGO | S_IWUSR);
1009TB_DEV_ATTR(target_core, unmap_granularity_alignment, S_IRUGO | S_IWUSR);
1010TB_DEV_ATTR(target_core, max_write_same_len, S_IRUGO | S_IWUSR);
1011
1012CONFIGFS_EATTR_STRUCT(target_core_dev_attrib, se_dev_attrib);
1013CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group);
1014 1002
1015/* 1003/*
1016 * dev_attrib attributes for devices using the target core SBC/SPC 1004 * dev_attrib attributes for devices using the target core SBC/SPC
@@ -1018,100 +1006,78 @@ CONFIGFS_EATTR_OPS(target_core_dev_attrib, se_dev_attrib, da_group);
1018 * these. 1006 * these.
1019 */ 1007 */
1020struct configfs_attribute *sbc_attrib_attrs[] = { 1008struct configfs_attribute *sbc_attrib_attrs[] = {
1021 &target_core_dev_attrib_emulate_model_alias.attr, 1009 &attr_emulate_model_alias,
1022 &target_core_dev_attrib_emulate_dpo.attr, 1010 &attr_emulate_dpo,
1023 &target_core_dev_attrib_emulate_fua_write.attr, 1011 &attr_emulate_fua_write,
1024 &target_core_dev_attrib_emulate_fua_read.attr, 1012 &attr_emulate_fua_read,
1025 &target_core_dev_attrib_emulate_write_cache.attr, 1013 &attr_emulate_write_cache,
1026 &target_core_dev_attrib_emulate_ua_intlck_ctrl.attr, 1014 &attr_emulate_ua_intlck_ctrl,
1027 &target_core_dev_attrib_emulate_tas.attr, 1015 &attr_emulate_tas,
1028 &target_core_dev_attrib_emulate_tpu.attr, 1016 &attr_emulate_tpu,
1029 &target_core_dev_attrib_emulate_tpws.attr, 1017 &attr_emulate_tpws,
1030 &target_core_dev_attrib_emulate_caw.attr, 1018 &attr_emulate_caw,
1031 &target_core_dev_attrib_emulate_3pc.attr, 1019 &attr_emulate_3pc,
1032 &target_core_dev_attrib_pi_prot_type.attr, 1020 &attr_pi_prot_type,
1033 &target_core_dev_attrib_hw_pi_prot_type.attr, 1021 &attr_hw_pi_prot_type,
1034 &target_core_dev_attrib_pi_prot_format.attr, 1022 &attr_pi_prot_format,
1035 &target_core_dev_attrib_enforce_pr_isids.attr, 1023 &attr_enforce_pr_isids,
1036 &target_core_dev_attrib_is_nonrot.attr, 1024 &attr_is_nonrot,
1037 &target_core_dev_attrib_emulate_rest_reord.attr, 1025 &attr_emulate_rest_reord,
1038 &target_core_dev_attrib_force_pr_aptpl.attr, 1026 &attr_force_pr_aptpl,
1039 &target_core_dev_attrib_hw_block_size.attr, 1027 &attr_hw_block_size,
1040 &target_core_dev_attrib_block_size.attr, 1028 &attr_block_size,
1041 &target_core_dev_attrib_hw_max_sectors.attr, 1029 &attr_hw_max_sectors,
1042 &target_core_dev_attrib_optimal_sectors.attr, 1030 &attr_optimal_sectors,
1043 &target_core_dev_attrib_hw_queue_depth.attr, 1031 &attr_hw_queue_depth,
1044 &target_core_dev_attrib_queue_depth.attr, 1032 &attr_queue_depth,
1045 &target_core_dev_attrib_max_unmap_lba_count.attr, 1033 &attr_max_unmap_lba_count,
1046 &target_core_dev_attrib_max_unmap_block_desc_count.attr, 1034 &attr_max_unmap_block_desc_count,
1047 &target_core_dev_attrib_unmap_granularity.attr, 1035 &attr_unmap_granularity,
1048 &target_core_dev_attrib_unmap_granularity_alignment.attr, 1036 &attr_unmap_granularity_alignment,
1049 &target_core_dev_attrib_max_write_same_len.attr, 1037 &attr_max_write_same_len,
1050 NULL, 1038 NULL,
1051}; 1039};
1052EXPORT_SYMBOL(sbc_attrib_attrs); 1040EXPORT_SYMBOL(sbc_attrib_attrs);
1053 1041
1054TB_DEV_ATTR_RO(target_pt, hw_pi_prot_type);
1055TB_DEV_ATTR_RO(target_pt, hw_block_size);
1056TB_DEV_ATTR_RO(target_pt, hw_max_sectors);
1057TB_DEV_ATTR_RO(target_pt, hw_queue_depth);
1058
1059/* 1042/*
1060 * Minimal dev_attrib attributes for devices passing through CDBs. 1043 * Minimal dev_attrib attributes for devices passing through CDBs.
1061 * In this case we only provide a few read-only attributes for 1044 * In this case we only provide a few read-only attributes for
1062 * backwards compatibility. 1045 * backwards compatibility.
1063 */ 1046 */
1064struct configfs_attribute *passthrough_attrib_attrs[] = { 1047struct configfs_attribute *passthrough_attrib_attrs[] = {
1065 &target_pt_dev_attrib_hw_pi_prot_type.attr, 1048 &attr_hw_pi_prot_type,
1066 &target_pt_dev_attrib_hw_block_size.attr, 1049 &attr_hw_block_size,
1067 &target_pt_dev_attrib_hw_max_sectors.attr, 1050 &attr_hw_max_sectors,
1068 &target_pt_dev_attrib_hw_queue_depth.attr, 1051 &attr_hw_queue_depth,
1069 NULL, 1052 NULL,
1070}; 1053};
1071EXPORT_SYMBOL(passthrough_attrib_attrs); 1054EXPORT_SYMBOL(passthrough_attrib_attrs);
1072 1055
1073static struct configfs_item_operations target_core_dev_attrib_ops = { 1056TB_CIT_SETUP_DRV(dev_attrib, NULL, NULL);
1074 .show_attribute = target_core_dev_attrib_attr_show,
1075 .store_attribute = target_core_dev_attrib_attr_store,
1076};
1077
1078TB_CIT_SETUP_DRV(dev_attrib, &target_core_dev_attrib_ops, NULL);
1079 1057
1080/* End functions for struct config_item_type tb_dev_attrib_cit */ 1058/* End functions for struct config_item_type tb_dev_attrib_cit */
1081 1059
1082/* Start functions for struct config_item_type tb_dev_wwn_cit */ 1060/* Start functions for struct config_item_type tb_dev_wwn_cit */
1083 1061
1084CONFIGFS_EATTR_STRUCT(target_core_dev_wwn, t10_wwn); 1062static struct t10_wwn *to_t10_wwn(struct config_item *item)
1085#define SE_DEV_WWN_ATTR(_name, _mode) \ 1063{
1086static struct target_core_dev_wwn_attribute target_core_dev_wwn_##_name = \ 1064 return container_of(to_config_group(item), struct t10_wwn, t10_wwn_group);
1087 __CONFIGFS_EATTR(_name, _mode, \ 1065}
1088 target_core_dev_wwn_show_attr_##_name, \
1089 target_core_dev_wwn_store_attr_##_name);
1090
1091#define SE_DEV_WWN_ATTR_RO(_name); \
1092do { \
1093 static struct target_core_dev_wwn_attribute \
1094 target_core_dev_wwn_##_name = \
1095 __CONFIGFS_EATTR_RO(_name, \
1096 target_core_dev_wwn_show_attr_##_name); \
1097} while (0);
1098 1066
1099/* 1067/*
1100 * VPD page 0x80 Unit serial 1068 * VPD page 0x80 Unit serial
1101 */ 1069 */
1102static ssize_t target_core_dev_wwn_show_attr_vpd_unit_serial( 1070static ssize_t target_wwn_vpd_unit_serial_show(struct config_item *item,
1103 struct t10_wwn *t10_wwn, 1071 char *page)
1104 char *page)
1105{ 1072{
1106 return sprintf(page, "T10 VPD Unit Serial Number: %s\n", 1073 return sprintf(page, "T10 VPD Unit Serial Number: %s\n",
1107 &t10_wwn->unit_serial[0]); 1074 &to_t10_wwn(item)->unit_serial[0]);
1108} 1075}
1109 1076
1110static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial( 1077static ssize_t target_wwn_vpd_unit_serial_store(struct config_item *item,
1111 struct t10_wwn *t10_wwn, 1078 const char *page, size_t count)
1112 const char *page,
1113 size_t count)
1114{ 1079{
1080 struct t10_wwn *t10_wwn = to_t10_wwn(item);
1115 struct se_device *dev = t10_wwn->t10_dev; 1081 struct se_device *dev = t10_wwn->t10_dev;
1116 unsigned char buf[INQUIRY_VPD_SERIAL_LEN]; 1082 unsigned char buf[INQUIRY_VPD_SERIAL_LEN];
1117 1083
@@ -1167,15 +1133,13 @@ static ssize_t target_core_dev_wwn_store_attr_vpd_unit_serial(
1167 return count; 1133 return count;
1168} 1134}
1169 1135
1170SE_DEV_WWN_ATTR(vpd_unit_serial, S_IRUGO | S_IWUSR);
1171
1172/* 1136/*
1173 * VPD page 0x83 Protocol Identifier 1137 * VPD page 0x83 Protocol Identifier
1174 */ 1138 */
1175static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier( 1139static ssize_t target_wwn_vpd_protocol_identifier_show(struct config_item *item,
1176 struct t10_wwn *t10_wwn, 1140 char *page)
1177 char *page)
1178{ 1141{
1142 struct t10_wwn *t10_wwn = to_t10_wwn(item);
1179 struct t10_vpd *vpd; 1143 struct t10_vpd *vpd;
1180 unsigned char buf[VPD_TMP_BUF_SIZE]; 1144 unsigned char buf[VPD_TMP_BUF_SIZE];
1181 ssize_t len = 0; 1145 ssize_t len = 0;
@@ -1199,25 +1163,15 @@ static ssize_t target_core_dev_wwn_show_attr_vpd_protocol_identifier(
1199 return len; 1163 return len;
1200} 1164}
1201 1165
1202static ssize_t target_core_dev_wwn_store_attr_vpd_protocol_identifier(
1203 struct t10_wwn *t10_wwn,
1204 const char *page,
1205 size_t count)
1206{
1207 return -ENOSYS;
1208}
1209
1210SE_DEV_WWN_ATTR(vpd_protocol_identifier, S_IRUGO | S_IWUSR);
1211
1212/* 1166/*
1213 * Generic wrapper for dumping VPD identifiers by association. 1167 * Generic wrapper for dumping VPD identifiers by association.
1214 */ 1168 */
1215#define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \ 1169#define DEF_DEV_WWN_ASSOC_SHOW(_name, _assoc) \
1216static ssize_t target_core_dev_wwn_show_attr_##_name( \ 1170static ssize_t target_wwn_##_name##_show(struct config_item *item, \
1217 struct t10_wwn *t10_wwn, \ 1171 char *page) \
1218 char *page) \
1219{ \ 1172{ \
1220 struct t10_vpd *vpd; \ 1173 struct t10_wwn *t10_wwn = to_t10_wwn(item); \
1174 struct t10_vpd *vpd; \
1221 unsigned char buf[VPD_TMP_BUF_SIZE]; \ 1175 unsigned char buf[VPD_TMP_BUF_SIZE]; \
1222 ssize_t len = 0; \ 1176 ssize_t len = 0; \
1223 \ 1177 \
@@ -1249,84 +1203,39 @@ static ssize_t target_core_dev_wwn_show_attr_##_name( \
1249 return len; \ 1203 return len; \
1250} 1204}
1251 1205
1252/* 1206/* VPD page 0x83 Association: Logical Unit */
1253 * VPD page 0x83 Association: Logical Unit
1254 */
1255DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00); 1207DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_logical_unit, 0x00);
1256 1208/* VPD page 0x83 Association: Target Port */
1257static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_logical_unit(
1258 struct t10_wwn *t10_wwn,
1259 const char *page,
1260 size_t count)
1261{
1262 return -ENOSYS;
1263}
1264
1265SE_DEV_WWN_ATTR(vpd_assoc_logical_unit, S_IRUGO | S_IWUSR);
1266
1267/*
1268 * VPD page 0x83 Association: Target Port
1269 */
1270DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10); 1209DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_target_port, 0x10);
1271 1210/* VPD page 0x83 Association: SCSI Target Device */
1272static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_target_port(
1273 struct t10_wwn *t10_wwn,
1274 const char *page,
1275 size_t count)
1276{
1277 return -ENOSYS;
1278}
1279
1280SE_DEV_WWN_ATTR(vpd_assoc_target_port, S_IRUGO | S_IWUSR);
1281
1282/*
1283 * VPD page 0x83 Association: SCSI Target Device
1284 */
1285DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20); 1211DEF_DEV_WWN_ASSOC_SHOW(vpd_assoc_scsi_target_device, 0x20);
1286 1212
1287static ssize_t target_core_dev_wwn_store_attr_vpd_assoc_scsi_target_device( 1213CONFIGFS_ATTR(target_wwn_, vpd_unit_serial);
1288 struct t10_wwn *t10_wwn, 1214CONFIGFS_ATTR_RO(target_wwn_, vpd_protocol_identifier);
1289 const char *page, 1215CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_logical_unit);
1290 size_t count) 1216CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_target_port);
1291{ 1217CONFIGFS_ATTR_RO(target_wwn_, vpd_assoc_scsi_target_device);
1292 return -ENOSYS;
1293}
1294
1295SE_DEV_WWN_ATTR(vpd_assoc_scsi_target_device, S_IRUGO | S_IWUSR);
1296
1297CONFIGFS_EATTR_OPS(target_core_dev_wwn, t10_wwn, t10_wwn_group);
1298 1218
1299static struct configfs_attribute *target_core_dev_wwn_attrs[] = { 1219static struct configfs_attribute *target_core_dev_wwn_attrs[] = {
1300 &target_core_dev_wwn_vpd_unit_serial.attr, 1220 &target_wwn_attr_vpd_unit_serial,
1301 &target_core_dev_wwn_vpd_protocol_identifier.attr, 1221 &target_wwn_attr_vpd_protocol_identifier,
1302 &target_core_dev_wwn_vpd_assoc_logical_unit.attr, 1222 &target_wwn_attr_vpd_assoc_logical_unit,
1303 &target_core_dev_wwn_vpd_assoc_target_port.attr, 1223 &target_wwn_attr_vpd_assoc_target_port,
1304 &target_core_dev_wwn_vpd_assoc_scsi_target_device.attr, 1224 &target_wwn_attr_vpd_assoc_scsi_target_device,
1305 NULL, 1225 NULL,
1306}; 1226};
1307 1227
1308static struct configfs_item_operations target_core_dev_wwn_ops = { 1228TB_CIT_SETUP(dev_wwn, NULL, NULL, target_core_dev_wwn_attrs);
1309 .show_attribute = target_core_dev_wwn_attr_show,
1310 .store_attribute = target_core_dev_wwn_attr_store,
1311};
1312
1313TB_CIT_SETUP(dev_wwn, &target_core_dev_wwn_ops, NULL, target_core_dev_wwn_attrs);
1314 1229
1315/* End functions for struct config_item_type tb_dev_wwn_cit */ 1230/* End functions for struct config_item_type tb_dev_wwn_cit */
1316 1231
1317/* Start functions for struct config_item_type tb_dev_pr_cit */ 1232/* Start functions for struct config_item_type tb_dev_pr_cit */
1318 1233
1319CONFIGFS_EATTR_STRUCT(target_core_dev_pr, se_device); 1234static struct se_device *pr_to_dev(struct config_item *item)
1320#define SE_DEV_PR_ATTR(_name, _mode) \ 1235{
1321static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \ 1236 return container_of(to_config_group(item), struct se_device,
1322 __CONFIGFS_EATTR(_name, _mode, \ 1237 dev_pr_group);
1323 target_core_dev_pr_show_attr_##_name, \ 1238}
1324 target_core_dev_pr_store_attr_##_name);
1325
1326#define SE_DEV_PR_ATTR_RO(_name); \
1327static struct target_core_dev_pr_attribute target_core_dev_pr_##_name = \
1328 __CONFIGFS_EATTR_RO(_name, \
1329 target_core_dev_pr_show_attr_##_name);
1330 1239
1331static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev, 1240static ssize_t target_core_dev_pr_show_spc3_res(struct se_device *dev,
1332 char *page) 1241 char *page)
@@ -1367,9 +1276,9 @@ static ssize_t target_core_dev_pr_show_spc2_res(struct se_device *dev,
1367 return len; 1276 return len;
1368} 1277}
1369 1278
1370static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev, 1279static ssize_t target_pr_res_holder_show(struct config_item *item, char *page)
1371 char *page)
1372{ 1280{
1281 struct se_device *dev = pr_to_dev(item);
1373 int ret; 1282 int ret;
1374 1283
1375 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) 1284 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
@@ -1384,11 +1293,10 @@ static ssize_t target_core_dev_pr_show_attr_res_holder(struct se_device *dev,
1384 return ret; 1293 return ret;
1385} 1294}
1386 1295
1387SE_DEV_PR_ATTR_RO(res_holder); 1296static ssize_t target_pr_res_pr_all_tgt_pts_show(struct config_item *item,
1388 1297 char *page)
1389static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1390 struct se_device *dev, char *page)
1391{ 1298{
1299 struct se_device *dev = pr_to_dev(item);
1392 ssize_t len = 0; 1300 ssize_t len = 0;
1393 1301
1394 spin_lock(&dev->dev_reservation_lock); 1302 spin_lock(&dev->dev_reservation_lock);
@@ -1406,22 +1314,17 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_all_tgt_pts(
1406 return len; 1314 return len;
1407} 1315}
1408 1316
1409SE_DEV_PR_ATTR_RO(res_pr_all_tgt_pts); 1317static ssize_t target_pr_res_pr_generation_show(struct config_item *item,
1410 1318 char *page)
1411static ssize_t target_core_dev_pr_show_attr_res_pr_generation(
1412 struct se_device *dev, char *page)
1413{ 1319{
1414 return sprintf(page, "0x%08x\n", dev->t10_pr.pr_generation); 1320 return sprintf(page, "0x%08x\n", pr_to_dev(item)->t10_pr.pr_generation);
1415} 1321}
1416 1322
1417SE_DEV_PR_ATTR_RO(res_pr_generation);
1418 1323
1419/* 1324static ssize_t target_pr_res_pr_holder_tg_port_show(struct config_item *item,
1420 * res_pr_holder_tg_port 1325 char *page)
1421 */
1422static ssize_t target_core_dev_pr_show_attr_res_pr_holder_tg_port(
1423 struct se_device *dev, char *page)
1424{ 1326{
1327 struct se_device *dev = pr_to_dev(item);
1425 struct se_node_acl *se_nacl; 1328 struct se_node_acl *se_nacl;
1426 struct se_portal_group *se_tpg; 1329 struct se_portal_group *se_tpg;
1427 struct t10_pr_registration *pr_reg; 1330 struct t10_pr_registration *pr_reg;
@@ -1453,11 +1356,11 @@ out_unlock:
1453 return len; 1356 return len;
1454} 1357}
1455 1358
1456SE_DEV_PR_ATTR_RO(res_pr_holder_tg_port);
1457 1359
1458static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts( 1360static ssize_t target_pr_res_pr_registered_i_pts_show(struct config_item *item,
1459 struct se_device *dev, char *page) 1361 char *page)
1460{ 1362{
1363 struct se_device *dev = pr_to_dev(item);
1461 const struct target_core_fabric_ops *tfo; 1364 const struct target_core_fabric_ops *tfo;
1462 struct t10_pr_registration *pr_reg; 1365 struct t10_pr_registration *pr_reg;
1463 unsigned char buf[384]; 1366 unsigned char buf[384];
@@ -1495,11 +1398,9 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_registered_i_pts(
1495 return len; 1398 return len;
1496} 1399}
1497 1400
1498SE_DEV_PR_ATTR_RO(res_pr_registered_i_pts); 1401static ssize_t target_pr_res_pr_type_show(struct config_item *item, char *page)
1499
1500static ssize_t target_core_dev_pr_show_attr_res_pr_type(
1501 struct se_device *dev, char *page)
1502{ 1402{
1403 struct se_device *dev = pr_to_dev(item);
1503 struct t10_pr_registration *pr_reg; 1404 struct t10_pr_registration *pr_reg;
1504 ssize_t len = 0; 1405 ssize_t len = 0;
1505 1406
@@ -1516,11 +1417,10 @@ static ssize_t target_core_dev_pr_show_attr_res_pr_type(
1516 return len; 1417 return len;
1517} 1418}
1518 1419
1519SE_DEV_PR_ATTR_RO(res_pr_type); 1420static ssize_t target_pr_res_type_show(struct config_item *item, char *page)
1520
1521static ssize_t target_core_dev_pr_show_attr_res_type(
1522 struct se_device *dev, char *page)
1523{ 1421{
1422 struct se_device *dev = pr_to_dev(item);
1423
1524 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) 1424 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1525 return sprintf(page, "SPC_PASSTHROUGH\n"); 1425 return sprintf(page, "SPC_PASSTHROUGH\n");
1526 else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS) 1426 else if (dev->dev_reservation_flags & DRF_SPC2_RESERVATIONS)
@@ -1529,11 +1429,11 @@ static ssize_t target_core_dev_pr_show_attr_res_type(
1529 return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n"); 1429 return sprintf(page, "SPC3_PERSISTENT_RESERVATIONS\n");
1530} 1430}
1531 1431
1532SE_DEV_PR_ATTR_RO(res_type); 1432static ssize_t target_pr_res_aptpl_active_show(struct config_item *item,
1533 1433 char *page)
1534static ssize_t target_core_dev_pr_show_attr_res_aptpl_active(
1535 struct se_device *dev, char *page)
1536{ 1434{
1435 struct se_device *dev = pr_to_dev(item);
1436
1537 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) 1437 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1538 return 0; 1438 return 0;
1539 1439
@@ -1541,14 +1441,11 @@ static ssize_t target_core_dev_pr_show_attr_res_aptpl_active(
1541 (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled"); 1441 (dev->t10_pr.pr_aptpl_active) ? "Activated" : "Disabled");
1542} 1442}
1543 1443
1544SE_DEV_PR_ATTR_RO(res_aptpl_active); 1444static ssize_t target_pr_res_aptpl_metadata_show(struct config_item *item,
1545 1445 char *page)
1546/*
1547 * res_aptpl_metadata
1548 */
1549static ssize_t target_core_dev_pr_show_attr_res_aptpl_metadata(
1550 struct se_device *dev, char *page)
1551{ 1446{
1447 struct se_device *dev = pr_to_dev(item);
1448
1552 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH) 1449 if (dev->transport->transport_flags & TRANSPORT_FLAG_PASSTHROUGH)
1553 return 0; 1450 return 0;
1554 1451
@@ -1580,11 +1477,10 @@ static match_table_t tokens = {
1580 {Opt_err, NULL} 1477 {Opt_err, NULL}
1581}; 1478};
1582 1479
1583static ssize_t target_core_dev_pr_store_attr_res_aptpl_metadata( 1480static ssize_t target_pr_res_aptpl_metadata_store(struct config_item *item,
1584 struct se_device *dev, 1481 const char *page, size_t count)
1585 const char *page,
1586 size_t count)
1587{ 1482{
1483 struct se_device *dev = pr_to_dev(item);
1588 unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL; 1484 unsigned char *i_fabric = NULL, *i_port = NULL, *isid = NULL;
1589 unsigned char *t_fabric = NULL, *t_port = NULL; 1485 unsigned char *t_fabric = NULL, *t_port = NULL;
1590 char *orig, *ptr, *opts; 1486 char *orig, *ptr, *opts;
@@ -1765,37 +1661,44 @@ out:
1765 return (ret == 0) ? count : ret; 1661 return (ret == 0) ? count : ret;
1766} 1662}
1767 1663
1768SE_DEV_PR_ATTR(res_aptpl_metadata, S_IRUGO | S_IWUSR);
1769 1664
1770CONFIGFS_EATTR_OPS(target_core_dev_pr, se_device, dev_pr_group); 1665CONFIGFS_ATTR_RO(target_pr_, res_holder);
1666CONFIGFS_ATTR_RO(target_pr_, res_pr_all_tgt_pts);
1667CONFIGFS_ATTR_RO(target_pr_, res_pr_generation);
1668CONFIGFS_ATTR_RO(target_pr_, res_pr_holder_tg_port);
1669CONFIGFS_ATTR_RO(target_pr_, res_pr_registered_i_pts);
1670CONFIGFS_ATTR_RO(target_pr_, res_pr_type);
1671CONFIGFS_ATTR_RO(target_pr_, res_type);
1672CONFIGFS_ATTR_RO(target_pr_, res_aptpl_active);
1673CONFIGFS_ATTR(target_pr_, res_aptpl_metadata);
1771 1674
1772static struct configfs_attribute *target_core_dev_pr_attrs[] = { 1675static struct configfs_attribute *target_core_dev_pr_attrs[] = {
1773 &target_core_dev_pr_res_holder.attr, 1676 &target_pr_attr_res_holder,
1774 &target_core_dev_pr_res_pr_all_tgt_pts.attr, 1677 &target_pr_attr_res_pr_all_tgt_pts,
1775 &target_core_dev_pr_res_pr_generation.attr, 1678 &target_pr_attr_res_pr_generation,
1776 &target_core_dev_pr_res_pr_holder_tg_port.attr, 1679 &target_pr_attr_res_pr_holder_tg_port,
1777 &target_core_dev_pr_res_pr_registered_i_pts.attr, 1680 &target_pr_attr_res_pr_registered_i_pts,
1778 &target_core_dev_pr_res_pr_type.attr, 1681 &target_pr_attr_res_pr_type,
1779 &target_core_dev_pr_res_type.attr, 1682 &target_pr_attr_res_type,
1780 &target_core_dev_pr_res_aptpl_active.attr, 1683 &target_pr_attr_res_aptpl_active,
1781 &target_core_dev_pr_res_aptpl_metadata.attr, 1684 &target_pr_attr_res_aptpl_metadata,
1782 NULL, 1685 NULL,
1783}; 1686};
1784 1687
1785static struct configfs_item_operations target_core_dev_pr_ops = { 1688TB_CIT_SETUP(dev_pr, NULL, NULL, target_core_dev_pr_attrs);
1786 .show_attribute = target_core_dev_pr_attr_show,
1787 .store_attribute = target_core_dev_pr_attr_store,
1788};
1789
1790TB_CIT_SETUP(dev_pr, &target_core_dev_pr_ops, NULL, target_core_dev_pr_attrs);
1791 1689
1792/* End functions for struct config_item_type tb_dev_pr_cit */ 1690/* End functions for struct config_item_type tb_dev_pr_cit */
1793 1691
1794/* Start functions for struct config_item_type tb_dev_cit */ 1692/* Start functions for struct config_item_type tb_dev_cit */
1795 1693
1796static ssize_t target_core_show_dev_info(void *p, char *page) 1694static inline struct se_device *to_device(struct config_item *item)
1695{
1696 return container_of(to_config_group(item), struct se_device, dev_group);
1697}
1698
1699static ssize_t target_dev_info_show(struct config_item *item, char *page)
1797{ 1700{
1798 struct se_device *dev = p; 1701 struct se_device *dev = to_device(item);
1799 int bl = 0; 1702 int bl = 0;
1800 ssize_t read_bytes = 0; 1703 ssize_t read_bytes = 0;
1801 1704
@@ -1806,35 +1709,17 @@ static ssize_t target_core_show_dev_info(void *p, char *page)
1806 return read_bytes; 1709 return read_bytes;
1807} 1710}
1808 1711
1809static struct target_core_configfs_attribute target_core_attr_dev_info = { 1712static ssize_t target_dev_control_store(struct config_item *item,
1810 .attr = { .ca_owner = THIS_MODULE, 1713 const char *page, size_t count)
1811 .ca_name = "info",
1812 .ca_mode = S_IRUGO },
1813 .show = target_core_show_dev_info,
1814 .store = NULL,
1815};
1816
1817static ssize_t target_core_store_dev_control(
1818 void *p,
1819 const char *page,
1820 size_t count)
1821{ 1714{
1822 struct se_device *dev = p; 1715 struct se_device *dev = to_device(item);
1823 1716
1824 return dev->transport->set_configfs_dev_params(dev, page, count); 1717 return dev->transport->set_configfs_dev_params(dev, page, count);
1825} 1718}
1826 1719
1827static struct target_core_configfs_attribute target_core_attr_dev_control = { 1720static ssize_t target_dev_alias_show(struct config_item *item, char *page)
1828 .attr = { .ca_owner = THIS_MODULE,
1829 .ca_name = "control",
1830 .ca_mode = S_IWUSR },
1831 .show = NULL,
1832 .store = target_core_store_dev_control,
1833};
1834
1835static ssize_t target_core_show_dev_alias(void *p, char *page)
1836{ 1721{
1837 struct se_device *dev = p; 1722 struct se_device *dev = to_device(item);
1838 1723
1839 if (!(dev->dev_flags & DF_USING_ALIAS)) 1724 if (!(dev->dev_flags & DF_USING_ALIAS))
1840 return 0; 1725 return 0;
@@ -1842,12 +1727,10 @@ static ssize_t target_core_show_dev_alias(void *p, char *page)
1842 return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias); 1727 return snprintf(page, PAGE_SIZE, "%s\n", dev->dev_alias);
1843} 1728}
1844 1729
1845static ssize_t target_core_store_dev_alias( 1730static ssize_t target_dev_alias_store(struct config_item *item,
1846 void *p, 1731 const char *page, size_t count)
1847 const char *page,
1848 size_t count)
1849{ 1732{
1850 struct se_device *dev = p; 1733 struct se_device *dev = to_device(item);
1851 struct se_hba *hba = dev->se_hba; 1734 struct se_hba *hba = dev->se_hba;
1852 ssize_t read_bytes; 1735 ssize_t read_bytes;
1853 1736
@@ -1874,17 +1757,9 @@ static ssize_t target_core_store_dev_alias(
1874 return read_bytes; 1757 return read_bytes;
1875} 1758}
1876 1759
1877static struct target_core_configfs_attribute target_core_attr_dev_alias = { 1760static ssize_t target_dev_udev_path_show(struct config_item *item, char *page)
1878 .attr = { .ca_owner = THIS_MODULE,
1879 .ca_name = "alias",
1880 .ca_mode = S_IRUGO | S_IWUSR },
1881 .show = target_core_show_dev_alias,
1882 .store = target_core_store_dev_alias,
1883};
1884
1885static ssize_t target_core_show_dev_udev_path(void *p, char *page)
1886{ 1761{
1887 struct se_device *dev = p; 1762 struct se_device *dev = to_device(item);
1888 1763
1889 if (!(dev->dev_flags & DF_USING_UDEV_PATH)) 1764 if (!(dev->dev_flags & DF_USING_UDEV_PATH))
1890 return 0; 1765 return 0;
@@ -1892,12 +1767,10 @@ static ssize_t target_core_show_dev_udev_path(void *p, char *page)
1892 return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path); 1767 return snprintf(page, PAGE_SIZE, "%s\n", dev->udev_path);
1893} 1768}
1894 1769
1895static ssize_t target_core_store_dev_udev_path( 1770static ssize_t target_dev_udev_path_store(struct config_item *item,
1896 void *p, 1771 const char *page, size_t count)
1897 const char *page,
1898 size_t count)
1899{ 1772{
1900 struct se_device *dev = p; 1773 struct se_device *dev = to_device(item);
1901 struct se_hba *hba = dev->se_hba; 1774 struct se_hba *hba = dev->se_hba;
1902 ssize_t read_bytes; 1775 ssize_t read_bytes;
1903 1776
@@ -1925,27 +1798,17 @@ static ssize_t target_core_store_dev_udev_path(
1925 return read_bytes; 1798 return read_bytes;
1926} 1799}
1927 1800
1928static struct target_core_configfs_attribute target_core_attr_dev_udev_path = { 1801static ssize_t target_dev_enable_show(struct config_item *item, char *page)
1929 .attr = { .ca_owner = THIS_MODULE,
1930 .ca_name = "udev_path",
1931 .ca_mode = S_IRUGO | S_IWUSR },
1932 .show = target_core_show_dev_udev_path,
1933 .store = target_core_store_dev_udev_path,
1934};
1935
1936static ssize_t target_core_show_dev_enable(void *p, char *page)
1937{ 1802{
1938 struct se_device *dev = p; 1803 struct se_device *dev = to_device(item);
1939 1804
1940 return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED)); 1805 return snprintf(page, PAGE_SIZE, "%d\n", !!(dev->dev_flags & DF_CONFIGURED));
1941} 1806}
1942 1807
1943static ssize_t target_core_store_dev_enable( 1808static ssize_t target_dev_enable_store(struct config_item *item,
1944 void *p, 1809 const char *page, size_t count)
1945 const char *page,
1946 size_t count)
1947{ 1810{
1948 struct se_device *dev = p; 1811 struct se_device *dev = to_device(item);
1949 char *ptr; 1812 char *ptr;
1950 int ret; 1813 int ret;
1951 1814
@@ -1962,17 +1825,9 @@ static ssize_t target_core_store_dev_enable(
1962 return count; 1825 return count;
1963} 1826}
1964 1827
1965static struct target_core_configfs_attribute target_core_attr_dev_enable = { 1828static ssize_t target_dev_alua_lu_gp_show(struct config_item *item, char *page)
1966 .attr = { .ca_owner = THIS_MODULE,
1967 .ca_name = "enable",
1968 .ca_mode = S_IRUGO | S_IWUSR },
1969 .show = target_core_show_dev_enable,
1970 .store = target_core_store_dev_enable,
1971};
1972
1973static ssize_t target_core_show_alua_lu_gp(void *p, char *page)
1974{ 1829{
1975 struct se_device *dev = p; 1830 struct se_device *dev = to_device(item);
1976 struct config_item *lu_ci; 1831 struct config_item *lu_ci;
1977 struct t10_alua_lu_gp *lu_gp; 1832 struct t10_alua_lu_gp *lu_gp;
1978 struct t10_alua_lu_gp_member *lu_gp_mem; 1833 struct t10_alua_lu_gp_member *lu_gp_mem;
@@ -1994,12 +1849,10 @@ static ssize_t target_core_show_alua_lu_gp(void *p, char *page)
1994 return len; 1849 return len;
1995} 1850}
1996 1851
1997static ssize_t target_core_store_alua_lu_gp( 1852static ssize_t target_dev_alua_lu_gp_store(struct config_item *item,
1998 void *p, 1853 const char *page, size_t count)
1999 const char *page,
2000 size_t count)
2001{ 1854{
2002 struct se_device *dev = p; 1855 struct se_device *dev = to_device(item);
2003 struct se_hba *hba = dev->se_hba; 1856 struct se_hba *hba = dev->se_hba;
2004 struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL; 1857 struct t10_alua_lu_gp *lu_gp = NULL, *lu_gp_new = NULL;
2005 struct t10_alua_lu_gp_member *lu_gp_mem; 1858 struct t10_alua_lu_gp_member *lu_gp_mem;
@@ -2076,17 +1929,9 @@ static ssize_t target_core_store_alua_lu_gp(
2076 return count; 1929 return count;
2077} 1930}
2078 1931
2079static struct target_core_configfs_attribute target_core_attr_dev_alua_lu_gp = { 1932static ssize_t target_dev_lba_map_show(struct config_item *item, char *page)
2080 .attr = { .ca_owner = THIS_MODULE,
2081 .ca_name = "alua_lu_gp",
2082 .ca_mode = S_IRUGO | S_IWUSR },
2083 .show = target_core_show_alua_lu_gp,
2084 .store = target_core_store_alua_lu_gp,
2085};
2086
2087static ssize_t target_core_show_dev_lba_map(void *p, char *page)
2088{ 1933{
2089 struct se_device *dev = p; 1934 struct se_device *dev = to_device(item);
2090 struct t10_alua_lba_map *map; 1935 struct t10_alua_lba_map *map;
2091 struct t10_alua_lba_map_member *mem; 1936 struct t10_alua_lba_map_member *mem;
2092 char *b = page; 1937 char *b = page;
@@ -2129,12 +1974,10 @@ static ssize_t target_core_show_dev_lba_map(void *p, char *page)
2129 return bl; 1974 return bl;
2130} 1975}
2131 1976
2132static ssize_t target_core_store_dev_lba_map( 1977static ssize_t target_dev_lba_map_store(struct config_item *item,
2133 void *p, 1978 const char *page, size_t count)
2134 const char *page,
2135 size_t count)
2136{ 1979{
2137 struct se_device *dev = p; 1980 struct se_device *dev = to_device(item);
2138 struct t10_alua_lba_map *lba_map = NULL; 1981 struct t10_alua_lba_map *lba_map = NULL;
2139 struct list_head lba_list; 1982 struct list_head lba_list;
2140 char *map_entries, *ptr; 1983 char *map_entries, *ptr;
@@ -2246,22 +2089,22 @@ out:
2246 return count; 2089 return count;
2247} 2090}
2248 2091
2249static struct target_core_configfs_attribute target_core_attr_dev_lba_map = { 2092CONFIGFS_ATTR_RO(target_dev_, info);
2250 .attr = { .ca_owner = THIS_MODULE, 2093CONFIGFS_ATTR_WO(target_dev_, control);
2251 .ca_name = "lba_map", 2094CONFIGFS_ATTR(target_dev_, alias);
2252 .ca_mode = S_IRUGO | S_IWUSR }, 2095CONFIGFS_ATTR(target_dev_, udev_path);
2253 .show = target_core_show_dev_lba_map, 2096CONFIGFS_ATTR(target_dev_, enable);
2254 .store = target_core_store_dev_lba_map, 2097CONFIGFS_ATTR(target_dev_, alua_lu_gp);
2255}; 2098CONFIGFS_ATTR(target_dev_, lba_map);
2256 2099
2257static struct configfs_attribute *target_core_dev_attrs[] = { 2100static struct configfs_attribute *target_core_dev_attrs[] = {
2258 &target_core_attr_dev_info.attr, 2101 &target_dev_attr_info,
2259 &target_core_attr_dev_control.attr, 2102 &target_dev_attr_control,
2260 &target_core_attr_dev_alias.attr, 2103 &target_dev_attr_alias,
2261 &target_core_attr_dev_udev_path.attr, 2104 &target_dev_attr_udev_path,
2262 &target_core_attr_dev_enable.attr, 2105 &target_dev_attr_enable,
2263 &target_core_attr_dev_alua_lu_gp.attr, 2106 &target_dev_attr_alua_lu_gp,
2264 &target_core_attr_dev_lba_map.attr, 2107 &target_dev_attr_lba_map,
2265 NULL, 2108 NULL,
2266}; 2109};
2267 2110
@@ -2275,42 +2118,8 @@ static void target_core_dev_release(struct config_item *item)
2275 target_free_device(dev); 2118 target_free_device(dev);
2276} 2119}
2277 2120
2278static ssize_t target_core_dev_show(struct config_item *item,
2279 struct configfs_attribute *attr,
2280 char *page)
2281{
2282 struct config_group *dev_cg = to_config_group(item);
2283 struct se_device *dev =
2284 container_of(dev_cg, struct se_device, dev_group);
2285 struct target_core_configfs_attribute *tc_attr = container_of(
2286 attr, struct target_core_configfs_attribute, attr);
2287
2288 if (!tc_attr->show)
2289 return -EINVAL;
2290
2291 return tc_attr->show(dev, page);
2292}
2293
2294static ssize_t target_core_dev_store(struct config_item *item,
2295 struct configfs_attribute *attr,
2296 const char *page, size_t count)
2297{
2298 struct config_group *dev_cg = to_config_group(item);
2299 struct se_device *dev =
2300 container_of(dev_cg, struct se_device, dev_group);
2301 struct target_core_configfs_attribute *tc_attr = container_of(
2302 attr, struct target_core_configfs_attribute, attr);
2303
2304 if (!tc_attr->store)
2305 return -EINVAL;
2306
2307 return tc_attr->store(dev, page, count);
2308}
2309
2310static struct configfs_item_operations target_core_dev_item_ops = { 2121static struct configfs_item_operations target_core_dev_item_ops = {
2311 .release = target_core_dev_release, 2122 .release = target_core_dev_release,
2312 .show_attribute = target_core_dev_show,
2313 .store_attribute = target_core_dev_store,
2314}; 2123};
2315 2124
2316TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs); 2125TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs);
@@ -2319,38 +2128,25 @@ TB_CIT_SETUP(dev, &target_core_dev_item_ops, NULL, target_core_dev_attrs);
2319 2128
2320/* Start functions for struct config_item_type target_core_alua_lu_gp_cit */ 2129/* Start functions for struct config_item_type target_core_alua_lu_gp_cit */
2321 2130
2322CONFIGFS_EATTR_STRUCT(target_core_alua_lu_gp, t10_alua_lu_gp); 2131static inline struct t10_alua_lu_gp *to_lu_gp(struct config_item *item)
2323#define SE_DEV_ALUA_LU_ATTR(_name, _mode) \ 2132{
2324static struct target_core_alua_lu_gp_attribute \ 2133 return container_of(to_config_group(item), struct t10_alua_lu_gp,
2325 target_core_alua_lu_gp_##_name = \ 2134 lu_gp_group);
2326 __CONFIGFS_EATTR(_name, _mode, \ 2135}
2327 target_core_alua_lu_gp_show_attr_##_name, \
2328 target_core_alua_lu_gp_store_attr_##_name);
2329
2330#define SE_DEV_ALUA_LU_ATTR_RO(_name) \
2331static struct target_core_alua_lu_gp_attribute \
2332 target_core_alua_lu_gp_##_name = \
2333 __CONFIGFS_EATTR_RO(_name, \
2334 target_core_alua_lu_gp_show_attr_##_name);
2335 2136
2336/* 2137static ssize_t target_lu_gp_lu_gp_id_show(struct config_item *item, char *page)
2337 * lu_gp_id
2338 */
2339static ssize_t target_core_alua_lu_gp_show_attr_lu_gp_id(
2340 struct t10_alua_lu_gp *lu_gp,
2341 char *page)
2342{ 2138{
2139 struct t10_alua_lu_gp *lu_gp = to_lu_gp(item);
2140
2343 if (!lu_gp->lu_gp_valid_id) 2141 if (!lu_gp->lu_gp_valid_id)
2344 return 0; 2142 return 0;
2345
2346 return sprintf(page, "%hu\n", lu_gp->lu_gp_id); 2143 return sprintf(page, "%hu\n", lu_gp->lu_gp_id);
2347} 2144}
2348 2145
2349static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id( 2146static ssize_t target_lu_gp_lu_gp_id_store(struct config_item *item,
2350 struct t10_alua_lu_gp *lu_gp, 2147 const char *page, size_t count)
2351 const char *page,
2352 size_t count)
2353{ 2148{
2149 struct t10_alua_lu_gp *lu_gp = to_lu_gp(item);
2354 struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group; 2150 struct config_group *alua_lu_gp_cg = &lu_gp->lu_gp_group;
2355 unsigned long lu_gp_id; 2151 unsigned long lu_gp_id;
2356 int ret; 2152 int ret;
@@ -2379,15 +2175,9 @@ static ssize_t target_core_alua_lu_gp_store_attr_lu_gp_id(
2379 return count; 2175 return count;
2380} 2176}
2381 2177
2382SE_DEV_ALUA_LU_ATTR(lu_gp_id, S_IRUGO | S_IWUSR); 2178static ssize_t target_lu_gp_members_show(struct config_item *item, char *page)
2383
2384/*
2385 * members
2386 */
2387static ssize_t target_core_alua_lu_gp_show_attr_members(
2388 struct t10_alua_lu_gp *lu_gp,
2389 char *page)
2390{ 2179{
2180 struct t10_alua_lu_gp *lu_gp = to_lu_gp(item);
2391 struct se_device *dev; 2181 struct se_device *dev;
2392 struct se_hba *hba; 2182 struct se_hba *hba;
2393 struct t10_alua_lu_gp_member *lu_gp_mem; 2183 struct t10_alua_lu_gp_member *lu_gp_mem;
@@ -2419,13 +2209,12 @@ static ssize_t target_core_alua_lu_gp_show_attr_members(
2419 return len; 2209 return len;
2420} 2210}
2421 2211
2422SE_DEV_ALUA_LU_ATTR_RO(members); 2212CONFIGFS_ATTR(target_lu_gp_, lu_gp_id);
2423 2213CONFIGFS_ATTR_RO(target_lu_gp_, members);
2424CONFIGFS_EATTR_OPS(target_core_alua_lu_gp, t10_alua_lu_gp, lu_gp_group);
2425 2214
2426static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = { 2215static struct configfs_attribute *target_core_alua_lu_gp_attrs[] = {
2427 &target_core_alua_lu_gp_lu_gp_id.attr, 2216 &target_lu_gp_attr_lu_gp_id,
2428 &target_core_alua_lu_gp_members.attr, 2217 &target_lu_gp_attr_members,
2429 NULL, 2218 NULL,
2430}; 2219};
2431 2220
@@ -2439,8 +2228,6 @@ static void target_core_alua_lu_gp_release(struct config_item *item)
2439 2228
2440static struct configfs_item_operations target_core_alua_lu_gp_ops = { 2229static struct configfs_item_operations target_core_alua_lu_gp_ops = {
2441 .release = target_core_alua_lu_gp_release, 2230 .release = target_core_alua_lu_gp_release,
2442 .show_attribute = target_core_alua_lu_gp_attr_show,
2443 .store_attribute = target_core_alua_lu_gp_attr_store,
2444}; 2231};
2445 2232
2446static struct config_item_type target_core_alua_lu_gp_cit = { 2233static struct config_item_type target_core_alua_lu_gp_cit = {
@@ -2511,36 +2298,23 @@ static struct config_item_type target_core_alua_lu_gps_cit = {
2511 2298
2512/* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */ 2299/* Start functions for struct config_item_type target_core_alua_tg_pt_gp_cit */
2513 2300
2514CONFIGFS_EATTR_STRUCT(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp); 2301static inline struct t10_alua_tg_pt_gp *to_tg_pt_gp(struct config_item *item)
2515#define SE_DEV_ALUA_TG_PT_ATTR(_name, _mode) \ 2302{
2516static struct target_core_alua_tg_pt_gp_attribute \ 2303 return container_of(to_config_group(item), struct t10_alua_tg_pt_gp,
2517 target_core_alua_tg_pt_gp_##_name = \ 2304 tg_pt_gp_group);
2518 __CONFIGFS_EATTR(_name, _mode, \ 2305}
2519 target_core_alua_tg_pt_gp_show_attr_##_name, \
2520 target_core_alua_tg_pt_gp_store_attr_##_name);
2521
2522#define SE_DEV_ALUA_TG_PT_ATTR_RO(_name) \
2523static struct target_core_alua_tg_pt_gp_attribute \
2524 target_core_alua_tg_pt_gp_##_name = \
2525 __CONFIGFS_EATTR_RO(_name, \
2526 target_core_alua_tg_pt_gp_show_attr_##_name);
2527 2306
2528/* 2307static ssize_t target_tg_pt_gp_alua_access_state_show(struct config_item *item,
2529 * alua_access_state 2308 char *page)
2530 */
2531static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_state(
2532 struct t10_alua_tg_pt_gp *tg_pt_gp,
2533 char *page)
2534{ 2309{
2535 return sprintf(page, "%d\n", 2310 return sprintf(page, "%d\n",
2536 atomic_read(&tg_pt_gp->tg_pt_gp_alua_access_state)); 2311 atomic_read(&to_tg_pt_gp(item)->tg_pt_gp_alua_access_state));
2537} 2312}
2538 2313
2539static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state( 2314static ssize_t target_tg_pt_gp_alua_access_state_store(struct config_item *item,
2540 struct t10_alua_tg_pt_gp *tg_pt_gp, 2315 const char *page, size_t count)
2541 const char *page,
2542 size_t count)
2543{ 2316{
2317 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2544 struct se_device *dev = tg_pt_gp->tg_pt_gp_dev; 2318 struct se_device *dev = tg_pt_gp->tg_pt_gp_dev;
2545 unsigned long tmp; 2319 unsigned long tmp;
2546 int new_state, ret; 2320 int new_state, ret;
@@ -2582,24 +2356,18 @@ static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_state(
2582 return (!ret) ? count : -EINVAL; 2356 return (!ret) ? count : -EINVAL;
2583} 2357}
2584 2358
2585SE_DEV_ALUA_TG_PT_ATTR(alua_access_state, S_IRUGO | S_IWUSR); 2359static ssize_t target_tg_pt_gp_alua_access_status_show(struct config_item *item,
2586 2360 char *page)
2587/*
2588 * alua_access_status
2589 */
2590static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_status(
2591 struct t10_alua_tg_pt_gp *tg_pt_gp,
2592 char *page)
2593{ 2361{
2362 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2594 return sprintf(page, "%s\n", 2363 return sprintf(page, "%s\n",
2595 core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status)); 2364 core_alua_dump_status(tg_pt_gp->tg_pt_gp_alua_access_status));
2596} 2365}
2597 2366
2598static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status( 2367static ssize_t target_tg_pt_gp_alua_access_status_store(
2599 struct t10_alua_tg_pt_gp *tg_pt_gp, 2368 struct config_item *item, const char *page, size_t count)
2600 const char *page,
2601 size_t count)
2602{ 2369{
2370 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2603 unsigned long tmp; 2371 unsigned long tmp;
2604 int new_status, ret; 2372 int new_status, ret;
2605 2373
@@ -2630,43 +2398,31 @@ static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_status(
2630 return count; 2398 return count;
2631} 2399}
2632 2400
2633SE_DEV_ALUA_TG_PT_ATTR(alua_access_status, S_IRUGO | S_IWUSR); 2401static ssize_t target_tg_pt_gp_alua_access_type_show(struct config_item *item,
2634 2402 char *page)
2635/*
2636 * alua_access_type
2637 */
2638static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_access_type(
2639 struct t10_alua_tg_pt_gp *tg_pt_gp,
2640 char *page)
2641{ 2403{
2642 return core_alua_show_access_type(tg_pt_gp, page); 2404 return core_alua_show_access_type(to_tg_pt_gp(item), page);
2643} 2405}
2644 2406
2645static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_access_type( 2407static ssize_t target_tg_pt_gp_alua_access_type_store(struct config_item *item,
2646 struct t10_alua_tg_pt_gp *tg_pt_gp, 2408 const char *page, size_t count)
2647 const char *page,
2648 size_t count)
2649{ 2409{
2650 return core_alua_store_access_type(tg_pt_gp, page, count); 2410 return core_alua_store_access_type(to_tg_pt_gp(item), page, count);
2651} 2411}
2652 2412
2653SE_DEV_ALUA_TG_PT_ATTR(alua_access_type, S_IRUGO | S_IWUSR); 2413#define ALUA_SUPPORTED_STATE_ATTR(_name, _bit) \
2654 2414static ssize_t target_tg_pt_gp_alua_support_##_name##_show( \
2655/* 2415 struct config_item *item, char *p) \
2656 * alua_supported_states
2657 */
2658
2659#define SE_DEV_ALUA_SUPPORT_STATE_SHOW(_name, _var, _bit) \
2660static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_support_##_name( \
2661 struct t10_alua_tg_pt_gp *t, char *p) \
2662{ \ 2416{ \
2663 return sprintf(p, "%d\n", !!(t->_var & _bit)); \ 2417 struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \
2664} 2418 return sprintf(p, "%d\n", \
2665 2419 !!(t->tg_pt_gp_alua_supported_states & _bit)); \
2666#define SE_DEV_ALUA_SUPPORT_STATE_STORE(_name, _var, _bit) \ 2420} \
2667static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\ 2421 \
2668 struct t10_alua_tg_pt_gp *t, const char *p, size_t c) \ 2422static ssize_t target_tg_pt_gp_alua_support_##_name##_store( \
2423 struct config_item *item, const char *p, size_t c) \
2669{ \ 2424{ \
2425 struct t10_alua_tg_pt_gp *t = to_tg_pt_gp(item); \
2670 unsigned long tmp; \ 2426 unsigned long tmp; \
2671 int ret; \ 2427 int ret; \
2672 \ 2428 \
@@ -2687,70 +2443,32 @@ static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_support_##_name(\
2687 return -EINVAL; \ 2443 return -EINVAL; \
2688 } \ 2444 } \
2689 if (tmp) \ 2445 if (tmp) \
2690 t->_var |= _bit; \ 2446 t->tg_pt_gp_alua_supported_states |= _bit; \
2691 else \ 2447 else \
2692 t->_var &= ~_bit; \ 2448 t->tg_pt_gp_alua_supported_states &= ~_bit; \
2693 \ 2449 \
2694 return c; \ 2450 return c; \
2695} 2451}
2696 2452
2697SE_DEV_ALUA_SUPPORT_STATE_SHOW(transitioning, 2453ALUA_SUPPORTED_STATE_ATTR(transitioning, ALUA_T_SUP);
2698 tg_pt_gp_alua_supported_states, ALUA_T_SUP); 2454ALUA_SUPPORTED_STATE_ATTR(offline, ALUA_O_SUP);
2699SE_DEV_ALUA_SUPPORT_STATE_STORE(transitioning, 2455ALUA_SUPPORTED_STATE_ATTR(lba_dependent, ALUA_LBD_SUP);
2700 tg_pt_gp_alua_supported_states, ALUA_T_SUP); 2456ALUA_SUPPORTED_STATE_ATTR(unavailable, ALUA_U_SUP);
2701SE_DEV_ALUA_TG_PT_ATTR(alua_support_transitioning, S_IRUGO | S_IWUSR); 2457ALUA_SUPPORTED_STATE_ATTR(standby, ALUA_S_SUP);
2702 2458ALUA_SUPPORTED_STATE_ATTR(active_optimized, ALUA_AO_SUP);
2703SE_DEV_ALUA_SUPPORT_STATE_SHOW(offline, 2459ALUA_SUPPORTED_STATE_ATTR(active_nonoptimized, ALUA_AN_SUP);
2704 tg_pt_gp_alua_supported_states, ALUA_O_SUP);
2705SE_DEV_ALUA_SUPPORT_STATE_STORE(offline,
2706 tg_pt_gp_alua_supported_states, ALUA_O_SUP);
2707SE_DEV_ALUA_TG_PT_ATTR(alua_support_offline, S_IRUGO | S_IWUSR);
2708
2709SE_DEV_ALUA_SUPPORT_STATE_SHOW(lba_dependent,
2710 tg_pt_gp_alua_supported_states, ALUA_LBD_SUP);
2711SE_DEV_ALUA_SUPPORT_STATE_STORE(lba_dependent,
2712 tg_pt_gp_alua_supported_states, ALUA_LBD_SUP);
2713SE_DEV_ALUA_TG_PT_ATTR(alua_support_lba_dependent, S_IRUGO);
2714
2715SE_DEV_ALUA_SUPPORT_STATE_SHOW(unavailable,
2716 tg_pt_gp_alua_supported_states, ALUA_U_SUP);
2717SE_DEV_ALUA_SUPPORT_STATE_STORE(unavailable,
2718 tg_pt_gp_alua_supported_states, ALUA_U_SUP);
2719SE_DEV_ALUA_TG_PT_ATTR(alua_support_unavailable, S_IRUGO | S_IWUSR);
2720
2721SE_DEV_ALUA_SUPPORT_STATE_SHOW(standby,
2722 tg_pt_gp_alua_supported_states, ALUA_S_SUP);
2723SE_DEV_ALUA_SUPPORT_STATE_STORE(standby,
2724 tg_pt_gp_alua_supported_states, ALUA_S_SUP);
2725SE_DEV_ALUA_TG_PT_ATTR(alua_support_standby, S_IRUGO | S_IWUSR);
2726
2727SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_optimized,
2728 tg_pt_gp_alua_supported_states, ALUA_AO_SUP);
2729SE_DEV_ALUA_SUPPORT_STATE_STORE(active_optimized,
2730 tg_pt_gp_alua_supported_states, ALUA_AO_SUP);
2731SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_optimized, S_IRUGO | S_IWUSR);
2732
2733SE_DEV_ALUA_SUPPORT_STATE_SHOW(active_nonoptimized,
2734 tg_pt_gp_alua_supported_states, ALUA_AN_SUP);
2735SE_DEV_ALUA_SUPPORT_STATE_STORE(active_nonoptimized,
2736 tg_pt_gp_alua_supported_states, ALUA_AN_SUP);
2737SE_DEV_ALUA_TG_PT_ATTR(alua_support_active_nonoptimized, S_IRUGO | S_IWUSR);
2738 2460
2739/* 2461static ssize_t target_tg_pt_gp_alua_write_metadata_show(
2740 * alua_write_metadata 2462 struct config_item *item, char *page)
2741 */
2742static ssize_t target_core_alua_tg_pt_gp_show_attr_alua_write_metadata(
2743 struct t10_alua_tg_pt_gp *tg_pt_gp,
2744 char *page)
2745{ 2463{
2746 return sprintf(page, "%d\n", tg_pt_gp->tg_pt_gp_write_metadata); 2464 return sprintf(page, "%d\n",
2465 to_tg_pt_gp(item)->tg_pt_gp_write_metadata);
2747} 2466}
2748 2467
2749static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata( 2468static ssize_t target_tg_pt_gp_alua_write_metadata_store(
2750 struct t10_alua_tg_pt_gp *tg_pt_gp, 2469 struct config_item *item, const char *page, size_t count)
2751 const char *page,
2752 size_t count)
2753{ 2470{
2471 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2754 unsigned long tmp; 2472 unsigned long tmp;
2755 int ret; 2473 int ret;
2756 2474
@@ -2770,110 +2488,71 @@ static ssize_t target_core_alua_tg_pt_gp_store_attr_alua_write_metadata(
2770 return count; 2488 return count;
2771} 2489}
2772 2490
2773SE_DEV_ALUA_TG_PT_ATTR(alua_write_metadata, S_IRUGO | S_IWUSR); 2491static ssize_t target_tg_pt_gp_nonop_delay_msecs_show(struct config_item *item,
2774 2492 char *page)
2775
2776
2777/*
2778 * nonop_delay_msecs
2779 */
2780static ssize_t target_core_alua_tg_pt_gp_show_attr_nonop_delay_msecs(
2781 struct t10_alua_tg_pt_gp *tg_pt_gp,
2782 char *page)
2783{ 2493{
2784 return core_alua_show_nonop_delay_msecs(tg_pt_gp, page); 2494 return core_alua_show_nonop_delay_msecs(to_tg_pt_gp(item), page);
2785
2786} 2495}
2787 2496
2788static ssize_t target_core_alua_tg_pt_gp_store_attr_nonop_delay_msecs( 2497static ssize_t target_tg_pt_gp_nonop_delay_msecs_store(struct config_item *item,
2789 struct t10_alua_tg_pt_gp *tg_pt_gp, 2498 const char *page, size_t count)
2790 const char *page,
2791 size_t count)
2792{ 2499{
2793 return core_alua_store_nonop_delay_msecs(tg_pt_gp, page, count); 2500 return core_alua_store_nonop_delay_msecs(to_tg_pt_gp(item), page,
2501 count);
2794} 2502}
2795 2503
2796SE_DEV_ALUA_TG_PT_ATTR(nonop_delay_msecs, S_IRUGO | S_IWUSR); 2504static ssize_t target_tg_pt_gp_trans_delay_msecs_show(struct config_item *item,
2797 2505 char *page)
2798/*
2799 * trans_delay_msecs
2800 */
2801static ssize_t target_core_alua_tg_pt_gp_show_attr_trans_delay_msecs(
2802 struct t10_alua_tg_pt_gp *tg_pt_gp,
2803 char *page)
2804{ 2506{
2805 return core_alua_show_trans_delay_msecs(tg_pt_gp, page); 2507 return core_alua_show_trans_delay_msecs(to_tg_pt_gp(item), page);
2806} 2508}
2807 2509
2808static ssize_t target_core_alua_tg_pt_gp_store_attr_trans_delay_msecs( 2510static ssize_t target_tg_pt_gp_trans_delay_msecs_store(struct config_item *item,
2809 struct t10_alua_tg_pt_gp *tg_pt_gp, 2511 const char *page, size_t count)
2810 const char *page,
2811 size_t count)
2812{ 2512{
2813 return core_alua_store_trans_delay_msecs(tg_pt_gp, page, count); 2513 return core_alua_store_trans_delay_msecs(to_tg_pt_gp(item), page,
2514 count);
2814} 2515}
2815 2516
2816SE_DEV_ALUA_TG_PT_ATTR(trans_delay_msecs, S_IRUGO | S_IWUSR); 2517static ssize_t target_tg_pt_gp_implicit_trans_secs_show(
2817 2518 struct config_item *item, char *page)
2818/*
2819 * implicit_trans_secs
2820 */
2821static ssize_t target_core_alua_tg_pt_gp_show_attr_implicit_trans_secs(
2822 struct t10_alua_tg_pt_gp *tg_pt_gp,
2823 char *page)
2824{ 2519{
2825 return core_alua_show_implicit_trans_secs(tg_pt_gp, page); 2520 return core_alua_show_implicit_trans_secs(to_tg_pt_gp(item), page);
2826} 2521}
2827 2522
2828static ssize_t target_core_alua_tg_pt_gp_store_attr_implicit_trans_secs( 2523static ssize_t target_tg_pt_gp_implicit_trans_secs_store(
2829 struct t10_alua_tg_pt_gp *tg_pt_gp, 2524 struct config_item *item, const char *page, size_t count)
2830 const char *page,
2831 size_t count)
2832{ 2525{
2833 return core_alua_store_implicit_trans_secs(tg_pt_gp, page, count); 2526 return core_alua_store_implicit_trans_secs(to_tg_pt_gp(item), page,
2527 count);
2834} 2528}
2835 2529
2836SE_DEV_ALUA_TG_PT_ATTR(implicit_trans_secs, S_IRUGO | S_IWUSR); 2530static ssize_t target_tg_pt_gp_preferred_show(struct config_item *item,
2837 2531 char *page)
2838/*
2839 * preferred
2840 */
2841
2842static ssize_t target_core_alua_tg_pt_gp_show_attr_preferred(
2843 struct t10_alua_tg_pt_gp *tg_pt_gp,
2844 char *page)
2845{ 2532{
2846 return core_alua_show_preferred_bit(tg_pt_gp, page); 2533 return core_alua_show_preferred_bit(to_tg_pt_gp(item), page);
2847} 2534}
2848 2535
2849static ssize_t target_core_alua_tg_pt_gp_store_attr_preferred( 2536static ssize_t target_tg_pt_gp_preferred_store(struct config_item *item,
2850 struct t10_alua_tg_pt_gp *tg_pt_gp, 2537 const char *page, size_t count)
2851 const char *page,
2852 size_t count)
2853{ 2538{
2854 return core_alua_store_preferred_bit(tg_pt_gp, page, count); 2539 return core_alua_store_preferred_bit(to_tg_pt_gp(item), page, count);
2855} 2540}
2856 2541
2857SE_DEV_ALUA_TG_PT_ATTR(preferred, S_IRUGO | S_IWUSR); 2542static ssize_t target_tg_pt_gp_tg_pt_gp_id_show(struct config_item *item,
2858 2543 char *page)
2859/*
2860 * tg_pt_gp_id
2861 */
2862static ssize_t target_core_alua_tg_pt_gp_show_attr_tg_pt_gp_id(
2863 struct t10_alua_tg_pt_gp *tg_pt_gp,
2864 char *page)
2865{ 2544{
2545 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2546
2866 if (!tg_pt_gp->tg_pt_gp_valid_id) 2547 if (!tg_pt_gp->tg_pt_gp_valid_id)
2867 return 0; 2548 return 0;
2868
2869 return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id); 2549 return sprintf(page, "%hu\n", tg_pt_gp->tg_pt_gp_id);
2870} 2550}
2871 2551
2872static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id( 2552static ssize_t target_tg_pt_gp_tg_pt_gp_id_store(struct config_item *item,
2873 struct t10_alua_tg_pt_gp *tg_pt_gp, 2553 const char *page, size_t count)
2874 const char *page,
2875 size_t count)
2876{ 2554{
2555 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2877 struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group; 2556 struct config_group *alua_tg_pt_gp_cg = &tg_pt_gp->tg_pt_gp_group;
2878 unsigned long tg_pt_gp_id; 2557 unsigned long tg_pt_gp_id;
2879 int ret; 2558 int ret;
@@ -2902,15 +2581,10 @@ static ssize_t target_core_alua_tg_pt_gp_store_attr_tg_pt_gp_id(
2902 return count; 2581 return count;
2903} 2582}
2904 2583
2905SE_DEV_ALUA_TG_PT_ATTR(tg_pt_gp_id, S_IRUGO | S_IWUSR); 2584static ssize_t target_tg_pt_gp_members_show(struct config_item *item,
2906 2585 char *page)
2907/*
2908 * members
2909 */
2910static ssize_t target_core_alua_tg_pt_gp_show_attr_members(
2911 struct t10_alua_tg_pt_gp *tg_pt_gp,
2912 char *page)
2913{ 2586{
2587 struct t10_alua_tg_pt_gp *tg_pt_gp = to_tg_pt_gp(item);
2914 struct se_lun *lun; 2588 struct se_lun *lun;
2915 ssize_t len = 0, cur_len; 2589 ssize_t len = 0, cur_len;
2916 unsigned char buf[TG_PT_GROUP_NAME_BUF]; 2590 unsigned char buf[TG_PT_GROUP_NAME_BUF];
@@ -2942,29 +2616,42 @@ static ssize_t target_core_alua_tg_pt_gp_show_attr_members(
2942 return len; 2616 return len;
2943} 2617}
2944 2618
2945SE_DEV_ALUA_TG_PT_ATTR_RO(members); 2619CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_state);
2946 2620CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_status);
2947CONFIGFS_EATTR_OPS(target_core_alua_tg_pt_gp, t10_alua_tg_pt_gp, 2621CONFIGFS_ATTR(target_tg_pt_gp_, alua_access_type);
2948 tg_pt_gp_group); 2622CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_transitioning);
2623CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_offline);
2624CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_lba_dependent);
2625CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_unavailable);
2626CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_standby);
2627CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_active_optimized);
2628CONFIGFS_ATTR(target_tg_pt_gp_, alua_support_active_nonoptimized);
2629CONFIGFS_ATTR(target_tg_pt_gp_, alua_write_metadata);
2630CONFIGFS_ATTR(target_tg_pt_gp_, nonop_delay_msecs);
2631CONFIGFS_ATTR(target_tg_pt_gp_, trans_delay_msecs);
2632CONFIGFS_ATTR(target_tg_pt_gp_, implicit_trans_secs);
2633CONFIGFS_ATTR(target_tg_pt_gp_, preferred);
2634CONFIGFS_ATTR(target_tg_pt_gp_, tg_pt_gp_id);
2635CONFIGFS_ATTR_RO(target_tg_pt_gp_, members);
2949 2636
2950static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = { 2637static struct configfs_attribute *target_core_alua_tg_pt_gp_attrs[] = {
2951 &target_core_alua_tg_pt_gp_alua_access_state.attr, 2638 &target_tg_pt_gp_attr_alua_access_state,
2952 &target_core_alua_tg_pt_gp_alua_access_status.attr, 2639 &target_tg_pt_gp_attr_alua_access_status,
2953 &target_core_alua_tg_pt_gp_alua_access_type.attr, 2640 &target_tg_pt_gp_attr_alua_access_type,
2954 &target_core_alua_tg_pt_gp_alua_support_transitioning.attr, 2641 &target_tg_pt_gp_attr_alua_support_transitioning,
2955 &target_core_alua_tg_pt_gp_alua_support_offline.attr, 2642 &target_tg_pt_gp_attr_alua_support_offline,
2956 &target_core_alua_tg_pt_gp_alua_support_lba_dependent.attr, 2643 &target_tg_pt_gp_attr_alua_support_lba_dependent,
2957 &target_core_alua_tg_pt_gp_alua_support_unavailable.attr, 2644 &target_tg_pt_gp_attr_alua_support_unavailable,
2958 &target_core_alua_tg_pt_gp_alua_support_standby.attr, 2645 &target_tg_pt_gp_attr_alua_support_standby,
2959 &target_core_alua_tg_pt_gp_alua_support_active_nonoptimized.attr, 2646 &target_tg_pt_gp_attr_alua_support_active_nonoptimized,
2960 &target_core_alua_tg_pt_gp_alua_support_active_optimized.attr, 2647 &target_tg_pt_gp_attr_alua_support_active_optimized,
2961 &target_core_alua_tg_pt_gp_alua_write_metadata.attr, 2648 &target_tg_pt_gp_attr_alua_write_metadata,
2962 &target_core_alua_tg_pt_gp_nonop_delay_msecs.attr, 2649 &target_tg_pt_gp_attr_nonop_delay_msecs,
2963 &target_core_alua_tg_pt_gp_trans_delay_msecs.attr, 2650 &target_tg_pt_gp_attr_trans_delay_msecs,
2964 &target_core_alua_tg_pt_gp_implicit_trans_secs.attr, 2651 &target_tg_pt_gp_attr_implicit_trans_secs,
2965 &target_core_alua_tg_pt_gp_preferred.attr, 2652 &target_tg_pt_gp_attr_preferred,
2966 &target_core_alua_tg_pt_gp_tg_pt_gp_id.attr, 2653 &target_tg_pt_gp_attr_tg_pt_gp_id,
2967 &target_core_alua_tg_pt_gp_members.attr, 2654 &target_tg_pt_gp_attr_members,
2968 NULL, 2655 NULL,
2969}; 2656};
2970 2657
@@ -2978,8 +2665,6 @@ static void target_core_alua_tg_pt_gp_release(struct config_item *item)
2978 2665
2979static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = { 2666static struct configfs_item_operations target_core_alua_tg_pt_gp_ops = {
2980 .release = target_core_alua_tg_pt_gp_release, 2667 .release = target_core_alua_tg_pt_gp_release,
2981 .show_attribute = target_core_alua_tg_pt_gp_attr_show,
2982 .store_attribute = target_core_alua_tg_pt_gp_attr_store,
2983}; 2668};
2984 2669
2985static struct config_item_type target_core_alua_tg_pt_gp_cit = { 2670static struct config_item_type target_core_alua_tg_pt_gp_cit = {
@@ -3237,34 +2922,24 @@ static struct configfs_group_operations target_core_hba_group_ops = {
3237 .drop_item = target_core_drop_subdev, 2922 .drop_item = target_core_drop_subdev,
3238}; 2923};
3239 2924
3240CONFIGFS_EATTR_STRUCT(target_core_hba, se_hba);
3241#define SE_HBA_ATTR(_name, _mode) \
3242static struct target_core_hba_attribute \
3243 target_core_hba_##_name = \
3244 __CONFIGFS_EATTR(_name, _mode, \
3245 target_core_hba_show_attr_##_name, \
3246 target_core_hba_store_attr_##_name);
3247 2925
3248#define SE_HBA_ATTR_RO(_name) \ 2926static inline struct se_hba *to_hba(struct config_item *item)
3249static struct target_core_hba_attribute \ 2927{
3250 target_core_hba_##_name = \ 2928 return container_of(to_config_group(item), struct se_hba, hba_group);
3251 __CONFIGFS_EATTR_RO(_name, \ 2929}
3252 target_core_hba_show_attr_##_name);
3253 2930
3254static ssize_t target_core_hba_show_attr_hba_info( 2931static ssize_t target_hba_info_show(struct config_item *item, char *page)
3255 struct se_hba *hba,
3256 char *page)
3257{ 2932{
2933 struct se_hba *hba = to_hba(item);
2934
3258 return sprintf(page, "HBA Index: %d plugin: %s version: %s\n", 2935 return sprintf(page, "HBA Index: %d plugin: %s version: %s\n",
3259 hba->hba_id, hba->backend->ops->name, 2936 hba->hba_id, hba->backend->ops->name,
3260 TARGET_CORE_VERSION); 2937 TARGET_CORE_VERSION);
3261} 2938}
3262 2939
3263SE_HBA_ATTR_RO(hba_info); 2940static ssize_t target_hba_mode_show(struct config_item *item, char *page)
3264
3265static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba,
3266 char *page)
3267{ 2941{
2942 struct se_hba *hba = to_hba(item);
3268 int hba_mode = 0; 2943 int hba_mode = 0;
3269 2944
3270 if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE) 2945 if (hba->hba_flags & HBA_FLAGS_PSCSI_MODE)
@@ -3273,9 +2948,10 @@ static ssize_t target_core_hba_show_attr_hba_mode(struct se_hba *hba,
3273 return sprintf(page, "%d\n", hba_mode); 2948 return sprintf(page, "%d\n", hba_mode);
3274} 2949}
3275 2950
3276static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba, 2951static ssize_t target_hba_mode_store(struct config_item *item,
3277 const char *page, size_t count) 2952 const char *page, size_t count)
3278{ 2953{
2954 struct se_hba *hba = to_hba(item);
3279 unsigned long mode_flag; 2955 unsigned long mode_flag;
3280 int ret; 2956 int ret;
3281 2957
@@ -3304,9 +2980,8 @@ static ssize_t target_core_hba_store_attr_hba_mode(struct se_hba *hba,
3304 return count; 2980 return count;
3305} 2981}
3306 2982
3307SE_HBA_ATTR(hba_mode, S_IRUGO | S_IWUSR); 2983CONFIGFS_ATTR_RO(target_, hba_info);
3308 2984CONFIGFS_ATTR(target_, hba_mode);
3309CONFIGFS_EATTR_OPS(target_core_hba, se_hba, hba_group);
3310 2985
3311static void target_core_hba_release(struct config_item *item) 2986static void target_core_hba_release(struct config_item *item)
3312{ 2987{
@@ -3316,15 +2991,13 @@ static void target_core_hba_release(struct config_item *item)
3316} 2991}
3317 2992
3318static struct configfs_attribute *target_core_hba_attrs[] = { 2993static struct configfs_attribute *target_core_hba_attrs[] = {
3319 &target_core_hba_hba_info.attr, 2994 &target_attr_hba_info,
3320 &target_core_hba_hba_mode.attr, 2995 &target_attr_hba_mode,
3321 NULL, 2996 NULL,
3322}; 2997};
3323 2998
3324static struct configfs_item_operations target_core_hba_item_ops = { 2999static struct configfs_item_operations target_core_hba_item_ops = {
3325 .release = target_core_hba_release, 3000 .release = target_core_hba_release,
3326 .show_attribute = target_core_hba_attr_show,
3327 .store_attribute = target_core_hba_attr_store,
3328}; 3001};
3329 3002
3330static struct config_item_type target_core_hba_cit = { 3003static struct config_item_type target_core_hba_cit = {
diff --git a/drivers/target/target_core_fabric_configfs.c b/drivers/target/target_core_fabric_configfs.c
index be42429468e2..f916d18ccb48 100644
--- a/drivers/target/target_core_fabric_configfs.c
+++ b/drivers/target/target_core_fabric_configfs.c
@@ -35,8 +35,6 @@
35 35
36#include <target/target_core_base.h> 36#include <target/target_core_base.h>
37#include <target/target_core_fabric.h> 37#include <target/target_core_fabric.h>
38#include <target/target_core_fabric_configfs.h>
39#include <target/configfs_macros.h>
40 38
41#include "target_core_internal.h" 39#include "target_core_internal.h"
42#include "target_core_alua.h" 40#include "target_core_alua.h"
@@ -152,17 +150,16 @@ static int target_fabric_mappedlun_unlink(
152 return core_dev_del_initiator_node_lun_acl(lun, lacl); 150 return core_dev_del_initiator_node_lun_acl(lun, lacl);
153} 151}
154 152
155CONFIGFS_EATTR_STRUCT(target_fabric_mappedlun, se_lun_acl); 153static struct se_lun_acl *item_to_lun_acl(struct config_item *item)
156#define TCM_MAPPEDLUN_ATTR(_name, _mode) \ 154{
157static struct target_fabric_mappedlun_attribute target_fabric_mappedlun_##_name = \ 155 return container_of(to_config_group(item), struct se_lun_acl,
158 __CONFIGFS_EATTR(_name, _mode, \ 156 se_lun_group);
159 target_fabric_mappedlun_show_##_name, \ 157}
160 target_fabric_mappedlun_store_##_name);
161 158
162static ssize_t target_fabric_mappedlun_show_write_protect( 159static ssize_t target_fabric_mappedlun_write_protect_show(
163 struct se_lun_acl *lacl, 160 struct config_item *item, char *page)
164 char *page)
165{ 161{
162 struct se_lun_acl *lacl = item_to_lun_acl(item);
166 struct se_node_acl *se_nacl = lacl->se_lun_nacl; 163 struct se_node_acl *se_nacl = lacl->se_lun_nacl;
167 struct se_dev_entry *deve; 164 struct se_dev_entry *deve;
168 ssize_t len = 0; 165 ssize_t len = 0;
@@ -178,11 +175,10 @@ static ssize_t target_fabric_mappedlun_show_write_protect(
178 return len; 175 return len;
179} 176}
180 177
181static ssize_t target_fabric_mappedlun_store_write_protect( 178static ssize_t target_fabric_mappedlun_write_protect_store(
182 struct se_lun_acl *lacl, 179 struct config_item *item, const char *page, size_t count)
183 const char *page,
184 size_t count)
185{ 180{
181 struct se_lun_acl *lacl = item_to_lun_acl(item);
186 struct se_node_acl *se_nacl = lacl->se_lun_nacl; 182 struct se_node_acl *se_nacl = lacl->se_lun_nacl;
187 struct se_portal_group *se_tpg = se_nacl->se_tpg; 183 struct se_portal_group *se_tpg = se_nacl->se_tpg;
188 unsigned long op; 184 unsigned long op;
@@ -209,9 +205,12 @@ static ssize_t target_fabric_mappedlun_store_write_protect(
209 205
210} 206}
211 207
212TCM_MAPPEDLUN_ATTR(write_protect, S_IRUGO | S_IWUSR); 208CONFIGFS_ATTR(target_fabric_mappedlun_, write_protect);
213 209
214CONFIGFS_EATTR_OPS(target_fabric_mappedlun, se_lun_acl, se_lun_group); 210static struct configfs_attribute *target_fabric_mappedlun_attrs[] = {
211 &target_fabric_mappedlun_attr_write_protect,
212 NULL,
213};
215 214
216static void target_fabric_mappedlun_release(struct config_item *item) 215static void target_fabric_mappedlun_release(struct config_item *item)
217{ 216{
@@ -222,15 +221,8 @@ static void target_fabric_mappedlun_release(struct config_item *item)
222 core_dev_free_initiator_node_lun_acl(se_tpg, lacl); 221 core_dev_free_initiator_node_lun_acl(se_tpg, lacl);
223} 222}
224 223
225static struct configfs_attribute *target_fabric_mappedlun_attrs[] = {
226 &target_fabric_mappedlun_write_protect.attr,
227 NULL,
228};
229
230static struct configfs_item_operations target_fabric_mappedlun_item_ops = { 224static struct configfs_item_operations target_fabric_mappedlun_item_ops = {
231 .release = target_fabric_mappedlun_release, 225 .release = target_fabric_mappedlun_release,
232 .show_attribute = target_fabric_mappedlun_attr_show,
233 .store_attribute = target_fabric_mappedlun_attr_store,
234 .allow_link = target_fabric_mappedlun_link, 226 .allow_link = target_fabric_mappedlun_link,
235 .drop_link = target_fabric_mappedlun_unlink, 227 .drop_link = target_fabric_mappedlun_unlink,
236}; 228};
@@ -266,49 +258,12 @@ TF_CIT_SETUP(tpg_mappedlun_stat, NULL, &target_fabric_mappedlun_stat_group_ops,
266 258
267/* End of tfc_tpg_mappedlun_port_cit */ 259/* End of tfc_tpg_mappedlun_port_cit */
268 260
269/* Start of tfc_tpg_nacl_attrib_cit */ 261TF_CIT_SETUP_DRV(tpg_nacl_attrib, NULL, NULL);
270 262TF_CIT_SETUP_DRV(tpg_nacl_auth, NULL, NULL);
271CONFIGFS_EATTR_OPS(target_fabric_nacl_attrib, se_node_acl, acl_attrib_group); 263TF_CIT_SETUP_DRV(tpg_nacl_param, NULL, NULL);
272
273static struct configfs_item_operations target_fabric_nacl_attrib_item_ops = {
274 .show_attribute = target_fabric_nacl_attrib_attr_show,
275 .store_attribute = target_fabric_nacl_attrib_attr_store,
276};
277
278TF_CIT_SETUP_DRV(tpg_nacl_attrib, &target_fabric_nacl_attrib_item_ops, NULL);
279
280/* End of tfc_tpg_nacl_attrib_cit */
281
282/* Start of tfc_tpg_nacl_auth_cit */
283
284CONFIGFS_EATTR_OPS(target_fabric_nacl_auth, se_node_acl, acl_auth_group);
285
286static struct configfs_item_operations target_fabric_nacl_auth_item_ops = {
287 .show_attribute = target_fabric_nacl_auth_attr_show,
288 .store_attribute = target_fabric_nacl_auth_attr_store,
289};
290
291TF_CIT_SETUP_DRV(tpg_nacl_auth, &target_fabric_nacl_auth_item_ops, NULL);
292
293/* End of tfc_tpg_nacl_auth_cit */
294
295/* Start of tfc_tpg_nacl_param_cit */
296
297CONFIGFS_EATTR_OPS(target_fabric_nacl_param, se_node_acl, acl_param_group);
298
299static struct configfs_item_operations target_fabric_nacl_param_item_ops = {
300 .show_attribute = target_fabric_nacl_param_attr_show,
301 .store_attribute = target_fabric_nacl_param_attr_store,
302};
303
304TF_CIT_SETUP_DRV(tpg_nacl_param, &target_fabric_nacl_param_item_ops, NULL);
305
306/* End of tfc_tpg_nacl_param_cit */
307 264
308/* Start of tfc_tpg_nacl_base_cit */ 265/* Start of tfc_tpg_nacl_base_cit */
309 266
310CONFIGFS_EATTR_OPS(target_fabric_nacl_base, se_node_acl, acl_group);
311
312static struct config_group *target_fabric_make_mappedlun( 267static struct config_group *target_fabric_make_mappedlun(
313 struct config_group *group, 268 struct config_group *group,
314 const char *name) 269 const char *name)
@@ -438,8 +393,6 @@ static void target_fabric_nacl_base_release(struct config_item *item)
438 393
439static struct configfs_item_operations target_fabric_nacl_base_item_ops = { 394static struct configfs_item_operations target_fabric_nacl_base_item_ops = {
440 .release = target_fabric_nacl_base_release, 395 .release = target_fabric_nacl_base_release,
441 .show_attribute = target_fabric_nacl_base_attr_show,
442 .store_attribute = target_fabric_nacl_base_attr_store,
443}; 396};
444 397
445static struct configfs_group_operations target_fabric_nacl_base_group_ops = { 398static struct configfs_group_operations target_fabric_nacl_base_group_ops = {
@@ -540,8 +493,6 @@ TF_CIT_SETUP(tpg_nacl, NULL, &target_fabric_nacl_group_ops, NULL);
540 493
541/* Start of tfc_tpg_np_base_cit */ 494/* Start of tfc_tpg_np_base_cit */
542 495
543CONFIGFS_EATTR_OPS(target_fabric_np_base, se_tpg_np, tpg_np_group);
544
545static void target_fabric_np_base_release(struct config_item *item) 496static void target_fabric_np_base_release(struct config_item *item)
546{ 497{
547 struct se_tpg_np *se_tpg_np = container_of(to_config_group(item), 498 struct se_tpg_np *se_tpg_np = container_of(to_config_group(item),
@@ -554,8 +505,6 @@ static void target_fabric_np_base_release(struct config_item *item)
554 505
555static struct configfs_item_operations target_fabric_np_base_item_ops = { 506static struct configfs_item_operations target_fabric_np_base_item_ops = {
556 .release = target_fabric_np_base_release, 507 .release = target_fabric_np_base_release,
557 .show_attribute = target_fabric_np_base_attr_show,
558 .store_attribute = target_fabric_np_base_attr_store,
559}; 508};
560 509
561TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL); 510TF_CIT_SETUP_DRV(tpg_np_base, &target_fabric_np_base_item_ops, NULL);
@@ -610,132 +559,113 @@ TF_CIT_SETUP(tpg_np, NULL, &target_fabric_np_group_ops, NULL);
610 559
611/* Start of tfc_tpg_port_cit */ 560/* Start of tfc_tpg_port_cit */
612 561
613CONFIGFS_EATTR_STRUCT(target_fabric_port, se_lun); 562static struct se_lun *item_to_lun(struct config_item *item)
614#define TCM_PORT_ATTR(_name, _mode) \ 563{
615static struct target_fabric_port_attribute target_fabric_port_##_name = \ 564 return container_of(to_config_group(item), struct se_lun,
616 __CONFIGFS_EATTR(_name, _mode, \ 565 lun_group);
617 target_fabric_port_show_attr_##_name, \ 566}
618 target_fabric_port_store_attr_##_name);
619
620#define TCM_PORT_ATTOR_RO(_name) \
621 __CONFIGFS_EATTR_RO(_name, \
622 target_fabric_port_show_attr_##_name);
623 567
624/* 568static ssize_t target_fabric_port_alua_tg_pt_gp_show(struct config_item *item,
625 * alua_tg_pt_gp 569 char *page)
626 */
627static ssize_t target_fabric_port_show_attr_alua_tg_pt_gp(
628 struct se_lun *lun,
629 char *page)
630{ 570{
571 struct se_lun *lun = item_to_lun(item);
572
631 if (!lun || !lun->lun_se_dev) 573 if (!lun || !lun->lun_se_dev)
632 return -ENODEV; 574 return -ENODEV;
633 575
634 return core_alua_show_tg_pt_gp_info(lun, page); 576 return core_alua_show_tg_pt_gp_info(lun, page);
635} 577}
636 578
637static ssize_t target_fabric_port_store_attr_alua_tg_pt_gp( 579static ssize_t target_fabric_port_alua_tg_pt_gp_store(struct config_item *item,
638 struct se_lun *lun, 580 const char *page, size_t count)
639 const char *page,
640 size_t count)
641{ 581{
582 struct se_lun *lun = item_to_lun(item);
583
642 if (!lun || !lun->lun_se_dev) 584 if (!lun || !lun->lun_se_dev)
643 return -ENODEV; 585 return -ENODEV;
644 586
645 return core_alua_store_tg_pt_gp_info(lun, page, count); 587 return core_alua_store_tg_pt_gp_info(lun, page, count);
646} 588}
647 589
648TCM_PORT_ATTR(alua_tg_pt_gp, S_IRUGO | S_IWUSR); 590static ssize_t target_fabric_port_alua_tg_pt_offline_show(
649 591 struct config_item *item, char *page)
650/*
651 * alua_tg_pt_offline
652 */
653static ssize_t target_fabric_port_show_attr_alua_tg_pt_offline(
654 struct se_lun *lun,
655 char *page)
656{ 592{
593 struct se_lun *lun = item_to_lun(item);
594
657 if (!lun || !lun->lun_se_dev) 595 if (!lun || !lun->lun_se_dev)
658 return -ENODEV; 596 return -ENODEV;
659 597
660 return core_alua_show_offline_bit(lun, page); 598 return core_alua_show_offline_bit(lun, page);
661} 599}
662 600
663static ssize_t target_fabric_port_store_attr_alua_tg_pt_offline( 601static ssize_t target_fabric_port_alua_tg_pt_offline_store(
664 struct se_lun *lun, 602 struct config_item *item, const char *page, size_t count)
665 const char *page,
666 size_t count)
667{ 603{
604 struct se_lun *lun = item_to_lun(item);
605
668 if (!lun || !lun->lun_se_dev) 606 if (!lun || !lun->lun_se_dev)
669 return -ENODEV; 607 return -ENODEV;
670 608
671 return core_alua_store_offline_bit(lun, page, count); 609 return core_alua_store_offline_bit(lun, page, count);
672} 610}
673 611
674TCM_PORT_ATTR(alua_tg_pt_offline, S_IRUGO | S_IWUSR); 612static ssize_t target_fabric_port_alua_tg_pt_status_show(
675 613 struct config_item *item, char *page)
676/*
677 * alua_tg_pt_status
678 */
679static ssize_t target_fabric_port_show_attr_alua_tg_pt_status(
680 struct se_lun *lun,
681 char *page)
682{ 614{
615 struct se_lun *lun = item_to_lun(item);
616
683 if (!lun || !lun->lun_se_dev) 617 if (!lun || !lun->lun_se_dev)
684 return -ENODEV; 618 return -ENODEV;
685 619
686 return core_alua_show_secondary_status(lun, page); 620 return core_alua_show_secondary_status(lun, page);
687} 621}
688 622
689static ssize_t target_fabric_port_store_attr_alua_tg_pt_status( 623static ssize_t target_fabric_port_alua_tg_pt_status_store(
690 struct se_lun *lun, 624 struct config_item *item, const char *page, size_t count)
691 const char *page,
692 size_t count)
693{ 625{
626 struct se_lun *lun = item_to_lun(item);
627
694 if (!lun || !lun->lun_se_dev) 628 if (!lun || !lun->lun_se_dev)
695 return -ENODEV; 629 return -ENODEV;
696 630
697 return core_alua_store_secondary_status(lun, page, count); 631 return core_alua_store_secondary_status(lun, page, count);
698} 632}
699 633
700TCM_PORT_ATTR(alua_tg_pt_status, S_IRUGO | S_IWUSR); 634static ssize_t target_fabric_port_alua_tg_pt_write_md_show(
701 635 struct config_item *item, char *page)
702/*
703 * alua_tg_pt_write_md
704 */
705static ssize_t target_fabric_port_show_attr_alua_tg_pt_write_md(
706 struct se_lun *lun,
707 char *page)
708{ 636{
637 struct se_lun *lun = item_to_lun(item);
638
709 if (!lun || !lun->lun_se_dev) 639 if (!lun || !lun->lun_se_dev)
710 return -ENODEV; 640 return -ENODEV;
711 641
712 return core_alua_show_secondary_write_metadata(lun, page); 642 return core_alua_show_secondary_write_metadata(lun, page);
713} 643}
714 644
715static ssize_t target_fabric_port_store_attr_alua_tg_pt_write_md( 645static ssize_t target_fabric_port_alua_tg_pt_write_md_store(
716 struct se_lun *lun, 646 struct config_item *item, const char *page, size_t count)
717 const char *page,
718 size_t count)
719{ 647{
648 struct se_lun *lun = item_to_lun(item);
649
720 if (!lun || !lun->lun_se_dev) 650 if (!lun || !lun->lun_se_dev)
721 return -ENODEV; 651 return -ENODEV;
722 652
723 return core_alua_store_secondary_write_metadata(lun, page, count); 653 return core_alua_store_secondary_write_metadata(lun, page, count);
724} 654}
725 655
726TCM_PORT_ATTR(alua_tg_pt_write_md, S_IRUGO | S_IWUSR); 656CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_gp);
727 657CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_offline);
658CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_status);
659CONFIGFS_ATTR(target_fabric_port_, alua_tg_pt_write_md);
728 660
729static struct configfs_attribute *target_fabric_port_attrs[] = { 661static struct configfs_attribute *target_fabric_port_attrs[] = {
730 &target_fabric_port_alua_tg_pt_gp.attr, 662 &target_fabric_port_attr_alua_tg_pt_gp,
731 &target_fabric_port_alua_tg_pt_offline.attr, 663 &target_fabric_port_attr_alua_tg_pt_offline,
732 &target_fabric_port_alua_tg_pt_status.attr, 664 &target_fabric_port_attr_alua_tg_pt_status,
733 &target_fabric_port_alua_tg_pt_write_md.attr, 665 &target_fabric_port_attr_alua_tg_pt_write_md,
734 NULL, 666 NULL,
735}; 667};
736 668
737CONFIGFS_EATTR_OPS(target_fabric_port, se_lun, lun_group);
738
739static int target_fabric_port_link( 669static int target_fabric_port_link(
740 struct config_item *lun_ci, 670 struct config_item *lun_ci,
741 struct config_item *se_dev_ci) 671 struct config_item *se_dev_ci)
@@ -821,8 +751,6 @@ static void target_fabric_port_release(struct config_item *item)
821} 751}
822 752
823static struct configfs_item_operations target_fabric_port_item_ops = { 753static struct configfs_item_operations target_fabric_port_item_ops = {
824 .show_attribute = target_fabric_port_attr_show,
825 .store_attribute = target_fabric_port_attr_store,
826 .release = target_fabric_port_release, 754 .release = target_fabric_port_release,
827 .allow_link = target_fabric_port_link, 755 .allow_link = target_fabric_port_link,
828 .drop_link = target_fabric_port_unlink, 756 .drop_link = target_fabric_port_unlink,
@@ -952,50 +880,11 @@ TF_CIT_SETUP(tpg_lun, NULL, &target_fabric_lun_group_ops, NULL);
952 880
953/* End of tfc_tpg_lun_cit */ 881/* End of tfc_tpg_lun_cit */
954 882
955/* Start of tfc_tpg_attrib_cit */ 883TF_CIT_SETUP_DRV(tpg_attrib, NULL, NULL);
956 884TF_CIT_SETUP_DRV(tpg_auth, NULL, NULL);
957CONFIGFS_EATTR_OPS(target_fabric_tpg_attrib, se_portal_group, tpg_attrib_group); 885TF_CIT_SETUP_DRV(tpg_param, NULL, NULL);
958
959static struct configfs_item_operations target_fabric_tpg_attrib_item_ops = {
960 .show_attribute = target_fabric_tpg_attrib_attr_show,
961 .store_attribute = target_fabric_tpg_attrib_attr_store,
962};
963
964TF_CIT_SETUP_DRV(tpg_attrib, &target_fabric_tpg_attrib_item_ops, NULL);
965
966/* End of tfc_tpg_attrib_cit */
967
968/* Start of tfc_tpg_auth_cit */
969
970CONFIGFS_EATTR_OPS(target_fabric_tpg_auth, se_portal_group, tpg_auth_group);
971
972static struct configfs_item_operations target_fabric_tpg_auth_item_ops = {
973 .show_attribute = target_fabric_tpg_auth_attr_show,
974 .store_attribute = target_fabric_tpg_auth_attr_store,
975};
976
977TF_CIT_SETUP_DRV(tpg_auth, &target_fabric_tpg_auth_item_ops, NULL);
978
979/* End of tfc_tpg_attrib_cit */
980
981/* Start of tfc_tpg_param_cit */
982
983CONFIGFS_EATTR_OPS(target_fabric_tpg_param, se_portal_group, tpg_param_group);
984
985static struct configfs_item_operations target_fabric_tpg_param_item_ops = {
986 .show_attribute = target_fabric_tpg_param_attr_show,
987 .store_attribute = target_fabric_tpg_param_attr_store,
988};
989
990TF_CIT_SETUP_DRV(tpg_param, &target_fabric_tpg_param_item_ops, NULL);
991
992/* End of tfc_tpg_param_cit */
993 886
994/* Start of tfc_tpg_base_cit */ 887/* Start of tfc_tpg_base_cit */
995/*
996 * For use with TF_TPG_ATTR() and TF_TPG_ATTR_RO()
997 */
998CONFIGFS_EATTR_OPS(target_fabric_tpg, se_portal_group, tpg_group);
999 888
1000static void target_fabric_tpg_release(struct config_item *item) 889static void target_fabric_tpg_release(struct config_item *item)
1001{ 890{
@@ -1009,8 +898,6 @@ static void target_fabric_tpg_release(struct config_item *item)
1009 898
1010static struct configfs_item_operations target_fabric_tpg_base_item_ops = { 899static struct configfs_item_operations target_fabric_tpg_base_item_ops = {
1011 .release = target_fabric_tpg_release, 900 .release = target_fabric_tpg_release,
1012 .show_attribute = target_fabric_tpg_attr_show,
1013 .store_attribute = target_fabric_tpg_attr_store,
1014}; 901};
1015 902
1016TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL); 903TF_CIT_SETUP_DRV(tpg_base, &target_fabric_tpg_base_item_ops, NULL);
@@ -1176,33 +1063,9 @@ static struct configfs_group_operations target_fabric_wwn_group_ops = {
1176 .make_group = target_fabric_make_wwn, 1063 .make_group = target_fabric_make_wwn,
1177 .drop_item = target_fabric_drop_wwn, 1064 .drop_item = target_fabric_drop_wwn,
1178}; 1065};
1179/*
1180 * For use with TF_WWN_ATTR() and TF_WWN_ATTR_RO()
1181 */
1182CONFIGFS_EATTR_OPS(target_fabric_wwn, target_fabric_configfs, tf_group);
1183
1184static struct configfs_item_operations target_fabric_wwn_item_ops = {
1185 .show_attribute = target_fabric_wwn_attr_show,
1186 .store_attribute = target_fabric_wwn_attr_store,
1187};
1188
1189TF_CIT_SETUP_DRV(wwn, &target_fabric_wwn_item_ops, &target_fabric_wwn_group_ops);
1190
1191/* End of tfc_wwn_cit */
1192
1193/* Start of tfc_discovery_cit */
1194
1195CONFIGFS_EATTR_OPS(target_fabric_discovery, target_fabric_configfs,
1196 tf_disc_group);
1197
1198static struct configfs_item_operations target_fabric_discovery_item_ops = {
1199 .show_attribute = target_fabric_discovery_attr_show,
1200 .store_attribute = target_fabric_discovery_attr_store,
1201};
1202
1203TF_CIT_SETUP_DRV(discovery, &target_fabric_discovery_item_ops, NULL);
1204 1066
1205/* End of tfc_discovery_cit */ 1067TF_CIT_SETUP_DRV(wwn, NULL, &target_fabric_wwn_group_ops);
1068TF_CIT_SETUP_DRV(discovery, NULL, NULL);
1206 1069
1207int target_fabric_setup_cits(struct target_fabric_configfs *tf) 1070int target_fabric_setup_cits(struct target_fabric_configfs *tf)
1208{ 1071{
diff --git a/drivers/target/target_core_internal.h b/drivers/target/target_core_internal.h
index 99c24acfe676..dae0750c2032 100644
--- a/drivers/target/target_core_internal.h
+++ b/drivers/target/target_core_internal.h
@@ -87,6 +87,9 @@ void target_free_device(struct se_device *);
87/* target_core_configfs.c */ 87/* target_core_configfs.c */
88void target_setup_backend_cits(struct target_backend *); 88void target_setup_backend_cits(struct target_backend *);
89 89
90/* target_core_fabric_configfs.c */
91int target_fabric_setup_cits(struct target_fabric_configfs *);
92
90/* target_core_fabric_lib.c */ 93/* target_core_fabric_lib.c */
91int target_get_pr_transport_id_len(struct se_node_acl *nacl, 94int target_get_pr_transport_id_len(struct se_node_acl *nacl,
92 struct t10_pr_registration *pr_reg, int *format_code); 95 struct t10_pr_registration *pr_reg, int *format_code);
diff --git a/drivers/target/target_core_stat.c b/drivers/target/target_core_stat.c
index 20ed5d2e151a..273c72b2b83d 100644
--- a/drivers/target/target_core_stat.c
+++ b/drivers/target/target_core_stat.c
@@ -37,7 +37,6 @@
37#include <target/target_core_base.h> 37#include <target/target_core_base.h>
38#include <target/target_core_backend.h> 38#include <target/target_core_backend.h>
39#include <target/target_core_fabric.h> 39#include <target/target_core_fabric.h>
40#include <target/configfs_macros.h>
41 40
42#include "target_core_internal.h" 41#include "target_core_internal.h"
43 42
@@ -55,75 +54,49 @@
55 * SCSI Device Table 54 * SCSI Device Table
56 */ 55 */
57 56
58CONFIGFS_EATTR_STRUCT(target_stat_scsi_dev, se_dev_stat_grps); 57static struct se_device *to_stat_dev(struct config_item *item)
59#define DEV_STAT_SCSI_DEV_ATTR(_name, _mode) \ 58{
60static struct target_stat_scsi_dev_attribute \ 59 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
61 target_stat_scsi_dev_##_name = \ 60 struct se_dev_stat_grps, scsi_dev_group);
62 __CONFIGFS_EATTR(_name, _mode, \ 61 return container_of(sgrps, struct se_device, dev_stat_grps);
63 target_stat_scsi_dev_show_attr_##_name, \ 62}
64 target_stat_scsi_dev_store_attr_##_name);
65
66#define DEV_STAT_SCSI_DEV_ATTR_RO(_name) \
67static struct target_stat_scsi_dev_attribute \
68 target_stat_scsi_dev_##_name = \
69 __CONFIGFS_EATTR_RO(_name, \
70 target_stat_scsi_dev_show_attr_##_name);
71 63
72static ssize_t target_stat_scsi_dev_show_attr_inst( 64static ssize_t target_stat_inst_show(struct config_item *item, char *page)
73 struct se_dev_stat_grps *sgrps, char *page)
74{ 65{
75 struct se_device *dev = 66 struct se_hba *hba = to_stat_dev(item)->se_hba;
76 container_of(sgrps, struct se_device, dev_stat_grps);
77 struct se_hba *hba = dev->se_hba;
78 67
79 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 68 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
80} 69}
81DEV_STAT_SCSI_DEV_ATTR_RO(inst);
82 70
83static ssize_t target_stat_scsi_dev_show_attr_indx( 71static ssize_t target_stat_indx_show(struct config_item *item, char *page)
84 struct se_dev_stat_grps *sgrps, char *page)
85{ 72{
86 struct se_device *dev = 73 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->dev_index);
87 container_of(sgrps, struct se_device, dev_stat_grps);
88
89 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
90} 74}
91DEV_STAT_SCSI_DEV_ATTR_RO(indx);
92 75
93static ssize_t target_stat_scsi_dev_show_attr_role( 76static ssize_t target_stat_role_show(struct config_item *item, char *page)
94 struct se_dev_stat_grps *sgrps, char *page)
95{ 77{
96 return snprintf(page, PAGE_SIZE, "Target\n"); 78 return snprintf(page, PAGE_SIZE, "Target\n");
97} 79}
98DEV_STAT_SCSI_DEV_ATTR_RO(role);
99 80
100static ssize_t target_stat_scsi_dev_show_attr_ports( 81static ssize_t target_stat_ports_show(struct config_item *item, char *page)
101 struct se_dev_stat_grps *sgrps, char *page)
102{ 82{
103 struct se_device *dev = 83 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_dev(item)->export_count);
104 container_of(sgrps, struct se_device, dev_stat_grps);
105
106 return snprintf(page, PAGE_SIZE, "%u\n", dev->export_count);
107} 84}
108DEV_STAT_SCSI_DEV_ATTR_RO(ports);
109 85
110CONFIGFS_EATTR_OPS(target_stat_scsi_dev, se_dev_stat_grps, scsi_dev_group); 86CONFIGFS_ATTR_RO(target_stat_, inst);
87CONFIGFS_ATTR_RO(target_stat_, indx);
88CONFIGFS_ATTR_RO(target_stat_, role);
89CONFIGFS_ATTR_RO(target_stat_, ports);
111 90
112static struct configfs_attribute *target_stat_scsi_dev_attrs[] = { 91static struct configfs_attribute *target_stat_scsi_dev_attrs[] = {
113 &target_stat_scsi_dev_inst.attr, 92 &target_stat_attr_inst,
114 &target_stat_scsi_dev_indx.attr, 93 &target_stat_attr_indx,
115 &target_stat_scsi_dev_role.attr, 94 &target_stat_attr_role,
116 &target_stat_scsi_dev_ports.attr, 95 &target_stat_attr_ports,
117 NULL, 96 NULL,
118}; 97};
119 98
120static struct configfs_item_operations target_stat_scsi_dev_attrib_ops = {
121 .show_attribute = target_stat_scsi_dev_attr_show,
122 .store_attribute = target_stat_scsi_dev_attr_store,
123};
124
125static struct config_item_type target_stat_scsi_dev_cit = { 99static struct config_item_type target_stat_scsi_dev_cit = {
126 .ct_item_ops = &target_stat_scsi_dev_attrib_ops,
127 .ct_attrs = target_stat_scsi_dev_attrs, 100 .ct_attrs = target_stat_scsi_dev_attrs,
128 .ct_owner = THIS_MODULE, 101 .ct_owner = THIS_MODULE,
129}; 102};
@@ -131,109 +104,78 @@ static struct config_item_type target_stat_scsi_dev_cit = {
131/* 104/*
132 * SCSI Target Device Table 105 * SCSI Target Device Table
133 */ 106 */
107static struct se_device *to_stat_tgt_dev(struct config_item *item)
108{
109 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
110 struct se_dev_stat_grps, scsi_tgt_dev_group);
111 return container_of(sgrps, struct se_device, dev_stat_grps);
112}
134 113
135CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_dev, se_dev_stat_grps); 114static ssize_t target_stat_tgt_inst_show(struct config_item *item, char *page)
136#define DEV_STAT_SCSI_TGT_DEV_ATTR(_name, _mode) \
137static struct target_stat_scsi_tgt_dev_attribute \
138 target_stat_scsi_tgt_dev_##_name = \
139 __CONFIGFS_EATTR(_name, _mode, \
140 target_stat_scsi_tgt_dev_show_attr_##_name, \
141 target_stat_scsi_tgt_dev_store_attr_##_name);
142
143#define DEV_STAT_SCSI_TGT_DEV_ATTR_RO(_name) \
144static struct target_stat_scsi_tgt_dev_attribute \
145 target_stat_scsi_tgt_dev_##_name = \
146 __CONFIGFS_EATTR_RO(_name, \
147 target_stat_scsi_tgt_dev_show_attr_##_name);
148
149static ssize_t target_stat_scsi_tgt_dev_show_attr_inst(
150 struct se_dev_stat_grps *sgrps, char *page)
151{ 115{
152 struct se_device *dev = 116 struct se_hba *hba = to_stat_tgt_dev(item)->se_hba;
153 container_of(sgrps, struct se_device, dev_stat_grps);
154 struct se_hba *hba = dev->se_hba;
155 117
156 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 118 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
157} 119}
158DEV_STAT_SCSI_TGT_DEV_ATTR_RO(inst);
159 120
160static ssize_t target_stat_scsi_tgt_dev_show_attr_indx( 121static ssize_t target_stat_tgt_indx_show(struct config_item *item, char *page)
161 struct se_dev_stat_grps *sgrps, char *page)
162{ 122{
163 struct se_device *dev = 123 return snprintf(page, PAGE_SIZE, "%u\n", to_stat_tgt_dev(item)->dev_index);
164 container_of(sgrps, struct se_device, dev_stat_grps);
165
166 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
167} 124}
168DEV_STAT_SCSI_TGT_DEV_ATTR_RO(indx);
169 125
170static ssize_t target_stat_scsi_tgt_dev_show_attr_num_lus( 126static ssize_t target_stat_tgt_num_lus_show(struct config_item *item,
171 struct se_dev_stat_grps *sgrps, char *page) 127 char *page)
172{ 128{
173 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT); 129 return snprintf(page, PAGE_SIZE, "%u\n", LU_COUNT);
174} 130}
175DEV_STAT_SCSI_TGT_DEV_ATTR_RO(num_lus);
176 131
177static ssize_t target_stat_scsi_tgt_dev_show_attr_status( 132static ssize_t target_stat_tgt_status_show(struct config_item *item,
178 struct se_dev_stat_grps *sgrps, char *page) 133 char *page)
179{ 134{
180 struct se_device *dev = 135 if (to_stat_tgt_dev(item)->export_count)
181 container_of(sgrps, struct se_device, dev_stat_grps);
182
183 if (dev->export_count)
184 return snprintf(page, PAGE_SIZE, "activated"); 136 return snprintf(page, PAGE_SIZE, "activated");
185 else 137 else
186 return snprintf(page, PAGE_SIZE, "deactivated"); 138 return snprintf(page, PAGE_SIZE, "deactivated");
187} 139}
188DEV_STAT_SCSI_TGT_DEV_ATTR_RO(status);
189 140
190static ssize_t target_stat_scsi_tgt_dev_show_attr_non_access_lus( 141static ssize_t target_stat_tgt_non_access_lus_show(struct config_item *item,
191 struct se_dev_stat_grps *sgrps, char *page) 142 char *page)
192{ 143{
193 struct se_device *dev =
194 container_of(sgrps, struct se_device, dev_stat_grps);
195 int non_accessible_lus; 144 int non_accessible_lus;
196 145
197 if (dev->export_count) 146 if (to_stat_tgt_dev(item)->export_count)
198 non_accessible_lus = 0; 147 non_accessible_lus = 0;
199 else 148 else
200 non_accessible_lus = 1; 149 non_accessible_lus = 1;
201 150
202 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus); 151 return snprintf(page, PAGE_SIZE, "%u\n", non_accessible_lus);
203} 152}
204DEV_STAT_SCSI_TGT_DEV_ATTR_RO(non_access_lus);
205 153
206static ssize_t target_stat_scsi_tgt_dev_show_attr_resets( 154static ssize_t target_stat_tgt_resets_show(struct config_item *item,
207 struct se_dev_stat_grps *sgrps, char *page) 155 char *page)
208{ 156{
209 struct se_device *dev =
210 container_of(sgrps, struct se_device, dev_stat_grps);
211
212 return snprintf(page, PAGE_SIZE, "%lu\n", 157 return snprintf(page, PAGE_SIZE, "%lu\n",
213 atomic_long_read(&dev->num_resets)); 158 atomic_long_read(&to_stat_tgt_dev(item)->num_resets));
214} 159}
215DEV_STAT_SCSI_TGT_DEV_ATTR_RO(resets);
216 160
217 161CONFIGFS_ATTR_RO(target_stat_tgt_, inst);
218CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_dev, se_dev_stat_grps, scsi_tgt_dev_group); 162CONFIGFS_ATTR_RO(target_stat_tgt_, indx);
163CONFIGFS_ATTR_RO(target_stat_tgt_, num_lus);
164CONFIGFS_ATTR_RO(target_stat_tgt_, status);
165CONFIGFS_ATTR_RO(target_stat_tgt_, non_access_lus);
166CONFIGFS_ATTR_RO(target_stat_tgt_, resets);
219 167
220static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = { 168static struct configfs_attribute *target_stat_scsi_tgt_dev_attrs[] = {
221 &target_stat_scsi_tgt_dev_inst.attr, 169 &target_stat_tgt_attr_inst,
222 &target_stat_scsi_tgt_dev_indx.attr, 170 &target_stat_tgt_attr_indx,
223 &target_stat_scsi_tgt_dev_num_lus.attr, 171 &target_stat_tgt_attr_num_lus,
224 &target_stat_scsi_tgt_dev_status.attr, 172 &target_stat_tgt_attr_status,
225 &target_stat_scsi_tgt_dev_non_access_lus.attr, 173 &target_stat_tgt_attr_non_access_lus,
226 &target_stat_scsi_tgt_dev_resets.attr, 174 &target_stat_tgt_attr_resets,
227 NULL, 175 NULL,
228}; 176};
229 177
230static struct configfs_item_operations target_stat_scsi_tgt_dev_attrib_ops = {
231 .show_attribute = target_stat_scsi_tgt_dev_attr_show,
232 .store_attribute = target_stat_scsi_tgt_dev_attr_store,
233};
234
235static struct config_item_type target_stat_scsi_tgt_dev_cit = { 178static struct config_item_type target_stat_scsi_tgt_dev_cit = {
236 .ct_item_ops = &target_stat_scsi_tgt_dev_attrib_ops,
237 .ct_attrs = target_stat_scsi_tgt_dev_attrs, 179 .ct_attrs = target_stat_scsi_tgt_dev_attrs,
238 .ct_owner = THIS_MODULE, 180 .ct_owner = THIS_MODULE,
239}; 181};
@@ -242,72 +184,50 @@ static struct config_item_type target_stat_scsi_tgt_dev_cit = {
242 * SCSI Logical Unit Table 184 * SCSI Logical Unit Table
243 */ 185 */
244 186
245CONFIGFS_EATTR_STRUCT(target_stat_scsi_lu, se_dev_stat_grps); 187static struct se_device *to_stat_lu_dev(struct config_item *item)
246#define DEV_STAT_SCSI_LU_ATTR(_name, _mode) \ 188{
247static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \ 189 struct se_dev_stat_grps *sgrps = container_of(to_config_group(item),
248 __CONFIGFS_EATTR(_name, _mode, \ 190 struct se_dev_stat_grps, scsi_lu_group);
249 target_stat_scsi_lu_show_attr_##_name, \ 191 return container_of(sgrps, struct se_device, dev_stat_grps);
250 target_stat_scsi_lu_store_attr_##_name); 192}
251
252#define DEV_STAT_SCSI_LU_ATTR_RO(_name) \
253static struct target_stat_scsi_lu_attribute target_stat_scsi_lu_##_name = \
254 __CONFIGFS_EATTR_RO(_name, \
255 target_stat_scsi_lu_show_attr_##_name);
256 193
257static ssize_t target_stat_scsi_lu_show_attr_inst( 194static ssize_t target_stat_lu_inst_show(struct config_item *item, char *page)
258 struct se_dev_stat_grps *sgrps, char *page)
259{ 195{
260 struct se_device *dev = 196 struct se_hba *hba = to_stat_lu_dev(item)->se_hba;
261 container_of(sgrps, struct se_device, dev_stat_grps);
262 struct se_hba *hba = dev->se_hba;
263 197
264 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index); 198 return snprintf(page, PAGE_SIZE, "%u\n", hba->hba_index);
265} 199}
266DEV_STAT_SCSI_LU_ATTR_RO(inst);
267 200
268static ssize_t target_stat_scsi_lu_show_attr_dev( 201static ssize_t target_stat_lu_dev_show(struct config_item *item, char *page)
269 struct se_dev_stat_grps *sgrps, char *page)
270{ 202{
271 struct se_device *dev = 203 return snprintf(page, PAGE_SIZE, "%u\n",
272 container_of(sgrps, struct se_device, dev_stat_grps); 204 to_stat_lu_dev(item)->dev_index);
273
274 return snprintf(page, PAGE_SIZE, "%u\n", dev->dev_index);
275} 205}
276DEV_STAT_SCSI_LU_ATTR_RO(dev);
277 206
278static ssize_t target_stat_scsi_lu_show_attr_indx( 207static ssize_t target_stat_lu_indx_show(struct config_item *item, char *page)
279 struct se_dev_stat_grps *sgrps, char *page)
280{ 208{
281 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX); 209 return snprintf(page, PAGE_SIZE, "%u\n", SCSI_LU_INDEX);
282} 210}
283DEV_STAT_SCSI_LU_ATTR_RO(indx);
284 211
285static ssize_t target_stat_scsi_lu_show_attr_lun( 212static ssize_t target_stat_lu_lun_show(struct config_item *item, char *page)
286 struct se_dev_stat_grps *sgrps, char *page)
287{ 213{
288 /* FIXME: scsiLuDefaultLun */ 214 /* FIXME: scsiLuDefaultLun */
289 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0); 215 return snprintf(page, PAGE_SIZE, "%llu\n", (unsigned long long)0);
290} 216}
291DEV_STAT_SCSI_LU_ATTR_RO(lun);
292 217
293static ssize_t target_stat_scsi_lu_show_attr_lu_name( 218static ssize_t target_stat_lu_lu_name_show(struct config_item *item, char *page)
294 struct se_dev_stat_grps *sgrps, char *page)
295{ 219{
296 struct se_device *dev = 220 struct se_device *dev = to_stat_lu_dev(item);
297 container_of(sgrps, struct se_device, dev_stat_grps);
298 221
299 /* scsiLuWwnName */ 222 /* scsiLuWwnName */
300 return snprintf(page, PAGE_SIZE, "%s\n", 223 return snprintf(page, PAGE_SIZE, "%s\n",
301 (strlen(dev->t10_wwn.unit_serial)) ? 224 (strlen(dev->t10_wwn.unit_serial)) ?
302 dev->t10_wwn.unit_serial : "None"); 225 dev->t10_wwn.unit_serial : "None");
303} 226}
304DEV_STAT_SCSI_LU_ATTR_RO(lu_name);
305 227
306static ssize_t target_stat_scsi_lu_show_attr_vend( 228static ssize_t target_stat_lu_vend_show(struct config_item *item, char *page)
307 struct se_dev_stat_grps *sgrps, char *page)
308{ 229{
309 struct se_device *dev = 230 struct se_device *dev = to_stat_lu_dev(item);
310 container_of(sgrps, struct se_device, dev_stat_grps);
311 int i; 231 int i;
312 char str[sizeof(dev->t10_wwn.vendor)+1]; 232 char str[sizeof(dev->t10_wwn.vendor)+1];
313 233
@@ -318,13 +238,10 @@ static ssize_t target_stat_scsi_lu_show_attr_vend(
318 str[i] = '\0'; 238 str[i] = '\0';
319 return snprintf(page, PAGE_SIZE, "%s\n", str); 239 return snprintf(page, PAGE_SIZE, "%s\n", str);
320} 240}
321DEV_STAT_SCSI_LU_ATTR_RO(vend);
322 241
323static ssize_t target_stat_scsi_lu_show_attr_prod( 242static ssize_t target_stat_lu_prod_show(struct config_item *item, char *page)
324 struct se_dev_stat_grps *sgrps, char *page)
325{ 243{
326 struct se_device *dev = 244 struct se_device *dev = to_stat_lu_dev(item);
327 container_of(sgrps, struct se_device, dev_stat_grps);
328 int i; 245 int i;
329 char str[sizeof(dev->t10_wwn.model)+1]; 246 char str[sizeof(dev->t10_wwn.model)+1];
330 247
@@ -335,13 +252,10 @@ static ssize_t target_stat_scsi_lu_show_attr_prod(
335 str[i] = '\0'; 252 str[i] = '\0';
336 return snprintf(page, PAGE_SIZE, "%s\n", str); 253 return snprintf(page, PAGE_SIZE, "%s\n", str);
337} 254}
338DEV_STAT_SCSI_LU_ATTR_RO(prod);
339 255
340static ssize_t target_stat_scsi_lu_show_attr_rev( 256static ssize_t target_stat_lu_rev_show(struct config_item *item, char *page)
341 struct se_dev_stat_grps *sgrps, char *page)
342{ 257{
343 struct se_device *dev = 258 struct se_device *dev = to_stat_lu_dev(item);
344 container_of(sgrps, struct se_device, dev_stat_grps);
345 int i; 259 int i;
346 char str[sizeof(dev->t10_wwn.revision)+1]; 260 char str[sizeof(dev->t10_wwn.revision)+1];
347 261
@@ -352,146 +266,137 @@ static ssize_t target_stat_scsi_lu_show_attr_rev(
352 str[i] = '\0'; 266 str[i] = '\0';
353 return snprintf(page, PAGE_SIZE, "%s\n", str); 267 return snprintf(page, PAGE_SIZE, "%s\n", str);
354} 268}
355DEV_STAT_SCSI_LU_ATTR_RO(rev);
356 269
357static ssize_t target_stat_scsi_lu_show_attr_dev_type( 270static ssize_t target_stat_lu_dev_type_show(struct config_item *item, char *page)
358 struct se_dev_stat_grps *sgrps, char *page)
359{ 271{
360 struct se_device *dev = 272 struct se_device *dev = to_stat_lu_dev(item);
361 container_of(sgrps, struct se_device, dev_stat_grps);
362 273
363 /* scsiLuPeripheralType */ 274 /* scsiLuPeripheralType */
364 return snprintf(page, PAGE_SIZE, "%u\n", 275 return snprintf(page, PAGE_SIZE, "%u\n",
365 dev->transport->get_device_type(dev)); 276 dev->transport->get_device_type(dev));
366} 277}
367DEV_STAT_SCSI_LU_ATTR_RO(dev_type);
368 278
369static ssize_t target_stat_scsi_lu_show_attr_status( 279static ssize_t target_stat_lu_status_show(struct config_item *item, char *page)
370 struct se_dev_stat_grps *sgrps, char *page)
371{ 280{
372 struct se_device *dev = 281 struct se_device *dev = to_stat_lu_dev(item);
373 container_of(sgrps, struct se_device, dev_stat_grps);
374 282
375 /* scsiLuStatus */ 283 /* scsiLuStatus */
376 return snprintf(page, PAGE_SIZE, "%s\n", 284 return snprintf(page, PAGE_SIZE, "%s\n",
377 (dev->export_count) ? "available" : "notavailable"); 285 (dev->export_count) ? "available" : "notavailable");
378} 286}
379DEV_STAT_SCSI_LU_ATTR_RO(status);
380 287
381static ssize_t target_stat_scsi_lu_show_attr_state_bit( 288static ssize_t target_stat_lu_state_bit_show(struct config_item *item,
382 struct se_dev_stat_grps *sgrps, char *page) 289 char *page)
383{ 290{
384 /* scsiLuState */ 291 /* scsiLuState */
385 return snprintf(page, PAGE_SIZE, "exposed\n"); 292 return snprintf(page, PAGE_SIZE, "exposed\n");
386} 293}
387DEV_STAT_SCSI_LU_ATTR_RO(state_bit);
388 294
389static ssize_t target_stat_scsi_lu_show_attr_num_cmds( 295static ssize_t target_stat_lu_num_cmds_show(struct config_item *item,
390 struct se_dev_stat_grps *sgrps, char *page) 296 char *page)
391{ 297{
392 struct se_device *dev = 298 struct se_device *dev = to_stat_lu_dev(item);
393 container_of(sgrps, struct se_device, dev_stat_grps);
394 299
395 /* scsiLuNumCommands */ 300 /* scsiLuNumCommands */
396 return snprintf(page, PAGE_SIZE, "%lu\n", 301 return snprintf(page, PAGE_SIZE, "%lu\n",
397 atomic_long_read(&dev->num_cmds)); 302 atomic_long_read(&dev->num_cmds));
398} 303}
399DEV_STAT_SCSI_LU_ATTR_RO(num_cmds);
400 304
401static ssize_t target_stat_scsi_lu_show_attr_read_mbytes( 305static ssize_t target_stat_lu_read_mbytes_show(struct config_item *item,
402 struct se_dev_stat_grps *sgrps, char *page) 306 char *page)
403{ 307{
404 struct se_device *dev = 308 struct se_device *dev = to_stat_lu_dev(item);
405 container_of(sgrps, struct se_device, dev_stat_grps);
406 309
407 /* scsiLuReadMegaBytes */ 310 /* scsiLuReadMegaBytes */
408 return snprintf(page, PAGE_SIZE, "%lu\n", 311 return snprintf(page, PAGE_SIZE, "%lu\n",
409 atomic_long_read(&dev->read_bytes) >> 20); 312 atomic_long_read(&dev->read_bytes) >> 20);
410} 313}
411DEV_STAT_SCSI_LU_ATTR_RO(read_mbytes);
412 314
413static ssize_t target_stat_scsi_lu_show_attr_write_mbytes( 315static ssize_t target_stat_lu_write_mbytes_show(struct config_item *item,
414 struct se_dev_stat_grps *sgrps, char *page) 316 char *page)
415{ 317{
416 struct se_device *dev = 318 struct se_device *dev = to_stat_lu_dev(item);
417 container_of(sgrps, struct se_device, dev_stat_grps);
418 319
419 /* scsiLuWrittenMegaBytes */ 320 /* scsiLuWrittenMegaBytes */
420 return snprintf(page, PAGE_SIZE, "%lu\n", 321 return snprintf(page, PAGE_SIZE, "%lu\n",
421 atomic_long_read(&dev->write_bytes) >> 20); 322 atomic_long_read(&dev->write_bytes) >> 20);
422} 323}
423DEV_STAT_SCSI_LU_ATTR_RO(write_mbytes);
424 324
425static ssize_t target_stat_scsi_lu_show_attr_resets( 325static ssize_t target_stat_lu_resets_show(struct config_item *item, char *page)
426 struct se_dev_stat_grps *sgrps, char *page)
427{ 326{
428 struct se_device *dev = 327 struct se_device *dev = to_stat_lu_dev(item);
429 container_of(sgrps, struct se_device, dev_stat_grps);
430 328
431 /* scsiLuInResets */ 329 /* scsiLuInResets */
432 return snprintf(page, PAGE_SIZE, "%lu\n", atomic_long_read(&dev->num_resets)); 330 return snprintf(page, PAGE_SIZE, "%lu\n",
331 atomic_long_read(&dev->num_resets));
433} 332}
434DEV_STAT_SCSI_LU_ATTR_RO(resets);
435 333
436static ssize_t target_stat_scsi_lu_show_attr_full_stat( 334static ssize_t target_stat_lu_full_stat_show(struct config_item *item,
437 struct se_dev_stat_grps *sgrps, char *page) 335 char *page)
438{ 336{
439 /* FIXME: scsiLuOutTaskSetFullStatus */ 337 /* FIXME: scsiLuOutTaskSetFullStatus */
440 return snprintf(page, PAGE_SIZE, "%u\n", 0); 338 return snprintf(page, PAGE_SIZE, "%u\n", 0);
441} 339}
442DEV_STAT_SCSI_LU_ATTR_RO(full_stat);
443 340
444static ssize_t target_stat_scsi_lu_show_attr_hs_num_cmds( 341static ssize_t target_stat_lu_hs_num_cmds_show(struct config_item *item,
445 struct se_dev_stat_grps *sgrps, char *page) 342 char *page)
446{ 343{
447 /* FIXME: scsiLuHSInCommands */ 344 /* FIXME: scsiLuHSInCommands */
448 return snprintf(page, PAGE_SIZE, "%u\n", 0); 345 return snprintf(page, PAGE_SIZE, "%u\n", 0);
449} 346}
450DEV_STAT_SCSI_LU_ATTR_RO(hs_num_cmds);
451 347
452static ssize_t target_stat_scsi_lu_show_attr_creation_time( 348static ssize_t target_stat_lu_creation_time_show(struct config_item *item,
453 struct se_dev_stat_grps *sgrps, char *page) 349 char *page)
454{ 350{
455 struct se_device *dev = 351 struct se_device *dev = to_stat_lu_dev(item);
456 container_of(sgrps, struct se_device, dev_stat_grps);
457 352
458 /* scsiLuCreationTime */ 353 /* scsiLuCreationTime */
459 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time - 354 return snprintf(page, PAGE_SIZE, "%u\n", (u32)(((u32)dev->creation_time -
460 INITIAL_JIFFIES) * 100 / HZ)); 355 INITIAL_JIFFIES) * 100 / HZ));
461} 356}
462DEV_STAT_SCSI_LU_ATTR_RO(creation_time);
463 357
464CONFIGFS_EATTR_OPS(target_stat_scsi_lu, se_dev_stat_grps, scsi_lu_group); 358CONFIGFS_ATTR_RO(target_stat_lu_, inst);
359CONFIGFS_ATTR_RO(target_stat_lu_, dev);
360CONFIGFS_ATTR_RO(target_stat_lu_, indx);
361CONFIGFS_ATTR_RO(target_stat_lu_, lun);
362CONFIGFS_ATTR_RO(target_stat_lu_, lu_name);
363CONFIGFS_ATTR_RO(target_stat_lu_, vend);
364CONFIGFS_ATTR_RO(target_stat_lu_, prod);
365CONFIGFS_ATTR_RO(target_stat_lu_, rev);
366CONFIGFS_ATTR_RO(target_stat_lu_, dev_type);
367CONFIGFS_ATTR_RO(target_stat_lu_, status);
368CONFIGFS_ATTR_RO(target_stat_lu_, state_bit);
369CONFIGFS_ATTR_RO(target_stat_lu_, num_cmds);
370CONFIGFS_ATTR_RO(target_stat_lu_, read_mbytes);
371CONFIGFS_ATTR_RO(target_stat_lu_, write_mbytes);
372CONFIGFS_ATTR_RO(target_stat_lu_, resets);
373CONFIGFS_ATTR_RO(target_stat_lu_, full_stat);
374CONFIGFS_ATTR_RO(target_stat_lu_, hs_num_cmds);
375CONFIGFS_ATTR_RO(target_stat_lu_, creation_time);
465 376
466static struct configfs_attribute *target_stat_scsi_lu_attrs[] = { 377static struct configfs_attribute *target_stat_scsi_lu_attrs[] = {
467 &target_stat_scsi_lu_inst.attr, 378 &target_stat_lu_attr_inst,
468 &target_stat_scsi_lu_dev.attr, 379 &target_stat_lu_attr_dev,
469 &target_stat_scsi_lu_indx.attr, 380 &target_stat_lu_attr_indx,
470 &target_stat_scsi_lu_lun.attr, 381 &target_stat_lu_attr_lun,
471 &target_stat_scsi_lu_lu_name.attr, 382 &target_stat_lu_attr_lu_name,
472 &target_stat_scsi_lu_vend.attr, 383 &target_stat_lu_attr_vend,
473 &target_stat_scsi_lu_prod.attr, 384 &target_stat_lu_attr_prod,
474 &target_stat_scsi_lu_rev.attr, 385 &target_stat_lu_attr_rev,
475 &target_stat_scsi_lu_dev_type.attr, 386 &target_stat_lu_attr_dev_type,
476 &target_stat_scsi_lu_status.attr, 387 &target_stat_lu_attr_status,
477 &target_stat_scsi_lu_state_bit.attr, 388 &target_stat_lu_attr_state_bit,
478 &target_stat_scsi_lu_num_cmds.attr, 389 &target_stat_lu_attr_num_cmds,
479 &target_stat_scsi_lu_read_mbytes.attr, 390 &target_stat_lu_attr_read_mbytes,
480 &target_stat_scsi_lu_write_mbytes.attr, 391 &target_stat_lu_attr_write_mbytes,
481 &target_stat_scsi_lu_resets.attr, 392 &target_stat_lu_attr_resets,
482 &target_stat_scsi_lu_full_stat.attr, 393 &target_stat_lu_attr_full_stat,
483 &target_stat_scsi_lu_hs_num_cmds.attr, 394 &target_stat_lu_attr_hs_num_cmds,
484 &target_stat_scsi_lu_creation_time.attr, 395 &target_stat_lu_attr_creation_time,
485 NULL, 396 NULL,
486}; 397};
487 398
488static struct configfs_item_operations target_stat_scsi_lu_attrib_ops = {
489 .show_attribute = target_stat_scsi_lu_attr_show,
490 .store_attribute = target_stat_scsi_lu_attr_store,
491};
492
493static struct config_item_type target_stat_scsi_lu_cit = { 399static struct config_item_type target_stat_scsi_lu_cit = {
494 .ct_item_ops = &target_stat_scsi_lu_attrib_ops,
495 .ct_attrs = target_stat_scsi_lu_attrs, 400 .ct_attrs = target_stat_scsi_lu_attrs,
496 .ct_owner = THIS_MODULE, 401 .ct_owner = THIS_MODULE,
497}; 402};
@@ -521,24 +426,16 @@ void target_stat_setup_dev_default_groups(struct se_device *dev)
521 * SCSI Port Table 426 * SCSI Port Table
522 */ 427 */
523 428
524CONFIGFS_EATTR_STRUCT(target_stat_scsi_port, se_port_stat_grps); 429static struct se_lun *to_stat_port(struct config_item *item)
525#define DEV_STAT_SCSI_PORT_ATTR(_name, _mode) \ 430{
526static struct target_stat_scsi_port_attribute \ 431 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
527 target_stat_scsi_port_##_name = \ 432 struct se_port_stat_grps, scsi_port_group);
528 __CONFIGFS_EATTR(_name, _mode, \ 433 return container_of(pgrps, struct se_lun, port_stat_grps);
529 target_stat_scsi_port_show_attr_##_name, \ 434}
530 target_stat_scsi_port_store_attr_##_name);
531
532#define DEV_STAT_SCSI_PORT_ATTR_RO(_name) \
533static struct target_stat_scsi_port_attribute \
534 target_stat_scsi_port_##_name = \
535 __CONFIGFS_EATTR_RO(_name, \
536 target_stat_scsi_port_show_attr_##_name);
537 435
538static ssize_t target_stat_scsi_port_show_attr_inst( 436static ssize_t target_stat_port_inst_show(struct config_item *item, char *page)
539 struct se_port_stat_grps *pgrps, char *page)
540{ 437{
541 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 438 struct se_lun *lun = to_stat_port(item);
542 struct se_device *dev; 439 struct se_device *dev;
543 ssize_t ret = -ENODEV; 440 ssize_t ret = -ENODEV;
544 441
@@ -549,12 +446,10 @@ static ssize_t target_stat_scsi_port_show_attr_inst(
549 rcu_read_unlock(); 446 rcu_read_unlock();
550 return ret; 447 return ret;
551} 448}
552DEV_STAT_SCSI_PORT_ATTR_RO(inst);
553 449
554static ssize_t target_stat_scsi_port_show_attr_dev( 450static ssize_t target_stat_port_dev_show(struct config_item *item, char *page)
555 struct se_port_stat_grps *pgrps, char *page)
556{ 451{
557 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 452 struct se_lun *lun = to_stat_port(item);
558 struct se_device *dev; 453 struct se_device *dev;
559 ssize_t ret = -ENODEV; 454 ssize_t ret = -ENODEV;
560 455
@@ -565,12 +460,10 @@ static ssize_t target_stat_scsi_port_show_attr_dev(
565 rcu_read_unlock(); 460 rcu_read_unlock();
566 return ret; 461 return ret;
567} 462}
568DEV_STAT_SCSI_PORT_ATTR_RO(dev);
569 463
570static ssize_t target_stat_scsi_port_show_attr_indx( 464static ssize_t target_stat_port_indx_show(struct config_item *item, char *page)
571 struct se_port_stat_grps *pgrps, char *page)
572{ 465{
573 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 466 struct se_lun *lun = to_stat_port(item);
574 struct se_device *dev; 467 struct se_device *dev;
575 ssize_t ret = -ENODEV; 468 ssize_t ret = -ENODEV;
576 469
@@ -581,12 +474,10 @@ static ssize_t target_stat_scsi_port_show_attr_indx(
581 rcu_read_unlock(); 474 rcu_read_unlock();
582 return ret; 475 return ret;
583} 476}
584DEV_STAT_SCSI_PORT_ATTR_RO(indx);
585 477
586static ssize_t target_stat_scsi_port_show_attr_role( 478static ssize_t target_stat_port_role_show(struct config_item *item, char *page)
587 struct se_port_stat_grps *pgrps, char *page)
588{ 479{
589 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 480 struct se_lun *lun = to_stat_port(item);
590 struct se_device *dev; 481 struct se_device *dev;
591 ssize_t ret = -ENODEV; 482 ssize_t ret = -ENODEV;
592 483
@@ -597,12 +488,11 @@ static ssize_t target_stat_scsi_port_show_attr_role(
597 rcu_read_unlock(); 488 rcu_read_unlock();
598 return ret; 489 return ret;
599} 490}
600DEV_STAT_SCSI_PORT_ATTR_RO(role);
601 491
602static ssize_t target_stat_scsi_port_show_attr_busy_count( 492static ssize_t target_stat_port_busy_count_show(struct config_item *item,
603 struct se_port_stat_grps *pgrps, char *page) 493 char *page)
604{ 494{
605 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 495 struct se_lun *lun = to_stat_port(item);
606 struct se_device *dev; 496 struct se_device *dev;
607 ssize_t ret = -ENODEV; 497 ssize_t ret = -ENODEV;
608 498
@@ -615,26 +505,23 @@ static ssize_t target_stat_scsi_port_show_attr_busy_count(
615 rcu_read_unlock(); 505 rcu_read_unlock();
616 return ret; 506 return ret;
617} 507}
618DEV_STAT_SCSI_PORT_ATTR_RO(busy_count);
619 508
620CONFIGFS_EATTR_OPS(target_stat_scsi_port, se_port_stat_grps, scsi_port_group); 509CONFIGFS_ATTR_RO(target_stat_port_, inst);
510CONFIGFS_ATTR_RO(target_stat_port_, dev);
511CONFIGFS_ATTR_RO(target_stat_port_, indx);
512CONFIGFS_ATTR_RO(target_stat_port_, role);
513CONFIGFS_ATTR_RO(target_stat_port_, busy_count);
621 514
622static struct configfs_attribute *target_stat_scsi_port_attrs[] = { 515static struct configfs_attribute *target_stat_scsi_port_attrs[] = {
623 &target_stat_scsi_port_inst.attr, 516 &target_stat_port_attr_inst,
624 &target_stat_scsi_port_dev.attr, 517 &target_stat_port_attr_dev,
625 &target_stat_scsi_port_indx.attr, 518 &target_stat_port_attr_indx,
626 &target_stat_scsi_port_role.attr, 519 &target_stat_port_attr_role,
627 &target_stat_scsi_port_busy_count.attr, 520 &target_stat_port_attr_busy_count,
628 NULL, 521 NULL,
629}; 522};
630 523
631static struct configfs_item_operations target_stat_scsi_port_attrib_ops = {
632 .show_attribute = target_stat_scsi_port_attr_show,
633 .store_attribute = target_stat_scsi_port_attr_store,
634};
635
636static struct config_item_type target_stat_scsi_port_cit = { 524static struct config_item_type target_stat_scsi_port_cit = {
637 .ct_item_ops = &target_stat_scsi_port_attrib_ops,
638 .ct_attrs = target_stat_scsi_port_attrs, 525 .ct_attrs = target_stat_scsi_port_attrs,
639 .ct_owner = THIS_MODULE, 526 .ct_owner = THIS_MODULE,
640}; 527};
@@ -642,24 +529,17 @@ static struct config_item_type target_stat_scsi_port_cit = {
642/* 529/*
643 * SCSI Target Port Table 530 * SCSI Target Port Table
644 */ 531 */
645CONFIGFS_EATTR_STRUCT(target_stat_scsi_tgt_port, se_port_stat_grps); 532static struct se_lun *to_stat_tgt_port(struct config_item *item)
646#define DEV_STAT_SCSI_TGT_PORT_ATTR(_name, _mode) \ 533{
647static struct target_stat_scsi_tgt_port_attribute \ 534 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
648 target_stat_scsi_tgt_port_##_name = \ 535 struct se_port_stat_grps, scsi_tgt_port_group);
649 __CONFIGFS_EATTR(_name, _mode, \ 536 return container_of(pgrps, struct se_lun, port_stat_grps);
650 target_stat_scsi_tgt_port_show_attr_##_name, \ 537}
651 target_stat_scsi_tgt_port_store_attr_##_name); 538
652 539static ssize_t target_stat_tgt_port_inst_show(struct config_item *item,
653#define DEV_STAT_SCSI_TGT_PORT_ATTR_RO(_name) \ 540 char *page)
654static struct target_stat_scsi_tgt_port_attribute \ 541{
655 target_stat_scsi_tgt_port_##_name = \ 542 struct se_lun *lun = to_stat_tgt_port(item);
656 __CONFIGFS_EATTR_RO(_name, \
657 target_stat_scsi_tgt_port_show_attr_##_name);
658
659static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
660 struct se_port_stat_grps *pgrps, char *page)
661{
662 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
663 struct se_device *dev; 543 struct se_device *dev;
664 ssize_t ret = -ENODEV; 544 ssize_t ret = -ENODEV;
665 545
@@ -670,12 +550,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_inst(
670 rcu_read_unlock(); 550 rcu_read_unlock();
671 return ret; 551 return ret;
672} 552}
673DEV_STAT_SCSI_TGT_PORT_ATTR_RO(inst);
674 553
675static ssize_t target_stat_scsi_tgt_port_show_attr_dev( 554static ssize_t target_stat_tgt_port_dev_show(struct config_item *item,
676 struct se_port_stat_grps *pgrps, char *page) 555 char *page)
677{ 556{
678 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 557 struct se_lun *lun = to_stat_tgt_port(item);
679 struct se_device *dev; 558 struct se_device *dev;
680 ssize_t ret = -ENODEV; 559 ssize_t ret = -ENODEV;
681 560
@@ -686,12 +565,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_dev(
686 rcu_read_unlock(); 565 rcu_read_unlock();
687 return ret; 566 return ret;
688} 567}
689DEV_STAT_SCSI_TGT_PORT_ATTR_RO(dev);
690 568
691static ssize_t target_stat_scsi_tgt_port_show_attr_indx( 569static ssize_t target_stat_tgt_port_indx_show(struct config_item *item,
692 struct se_port_stat_grps *pgrps, char *page) 570 char *page)
693{ 571{
694 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 572 struct se_lun *lun = to_stat_tgt_port(item);
695 struct se_device *dev; 573 struct se_device *dev;
696 ssize_t ret = -ENODEV; 574 ssize_t ret = -ENODEV;
697 575
@@ -702,12 +580,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_indx(
702 rcu_read_unlock(); 580 rcu_read_unlock();
703 return ret; 581 return ret;
704} 582}
705DEV_STAT_SCSI_TGT_PORT_ATTR_RO(indx);
706 583
707static ssize_t target_stat_scsi_tgt_port_show_attr_name( 584static ssize_t target_stat_tgt_port_name_show(struct config_item *item,
708 struct se_port_stat_grps *pgrps, char *page) 585 char *page)
709{ 586{
710 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 587 struct se_lun *lun = to_stat_tgt_port(item);
711 struct se_portal_group *tpg = lun->lun_tpg; 588 struct se_portal_group *tpg = lun->lun_tpg;
712 struct se_device *dev; 589 struct se_device *dev;
713 ssize_t ret = -ENODEV; 590 ssize_t ret = -ENODEV;
@@ -721,12 +598,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_name(
721 rcu_read_unlock(); 598 rcu_read_unlock();
722 return ret; 599 return ret;
723} 600}
724DEV_STAT_SCSI_TGT_PORT_ATTR_RO(name);
725 601
726static ssize_t target_stat_scsi_tgt_port_show_attr_port_index( 602static ssize_t target_stat_tgt_port_port_index_show(struct config_item *item,
727 struct se_port_stat_grps *pgrps, char *page) 603 char *page)
728{ 604{
729 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 605 struct se_lun *lun = to_stat_tgt_port(item);
730 struct se_portal_group *tpg = lun->lun_tpg; 606 struct se_portal_group *tpg = lun->lun_tpg;
731 struct se_device *dev; 607 struct se_device *dev;
732 ssize_t ret = -ENODEV; 608 ssize_t ret = -ENODEV;
@@ -740,12 +616,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_port_index(
740 rcu_read_unlock(); 616 rcu_read_unlock();
741 return ret; 617 return ret;
742} 618}
743DEV_STAT_SCSI_TGT_PORT_ATTR_RO(port_index);
744 619
745static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds( 620static ssize_t target_stat_tgt_port_in_cmds_show(struct config_item *item,
746 struct se_port_stat_grps *pgrps, char *page) 621 char *page)
747{ 622{
748 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 623 struct se_lun *lun = to_stat_tgt_port(item);
749 struct se_device *dev; 624 struct se_device *dev;
750 ssize_t ret = -ENODEV; 625 ssize_t ret = -ENODEV;
751 626
@@ -757,12 +632,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_in_cmds(
757 rcu_read_unlock(); 632 rcu_read_unlock();
758 return ret; 633 return ret;
759} 634}
760DEV_STAT_SCSI_TGT_PORT_ATTR_RO(in_cmds);
761 635
762static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes( 636static ssize_t target_stat_tgt_port_write_mbytes_show(struct config_item *item,
763 struct se_port_stat_grps *pgrps, char *page) 637 char *page)
764{ 638{
765 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 639 struct se_lun *lun = to_stat_tgt_port(item);
766 struct se_device *dev; 640 struct se_device *dev;
767 ssize_t ret = -ENODEV; 641 ssize_t ret = -ENODEV;
768 642
@@ -774,12 +648,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_write_mbytes(
774 rcu_read_unlock(); 648 rcu_read_unlock();
775 return ret; 649 return ret;
776} 650}
777DEV_STAT_SCSI_TGT_PORT_ATTR_RO(write_mbytes);
778 651
779static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes( 652static ssize_t target_stat_tgt_port_read_mbytes_show(struct config_item *item,
780 struct se_port_stat_grps *pgrps, char *page) 653 char *page)
781{ 654{
782 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 655 struct se_lun *lun = to_stat_tgt_port(item);
783 struct se_device *dev; 656 struct se_device *dev;
784 ssize_t ret = -ENODEV; 657 ssize_t ret = -ENODEV;
785 658
@@ -791,12 +664,11 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_read_mbytes(
791 rcu_read_unlock(); 664 rcu_read_unlock();
792 return ret; 665 return ret;
793} 666}
794DEV_STAT_SCSI_TGT_PORT_ATTR_RO(read_mbytes);
795 667
796static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds( 668static ssize_t target_stat_tgt_port_hs_in_cmds_show(struct config_item *item,
797 struct se_port_stat_grps *pgrps, char *page) 669 char *page)
798{ 670{
799 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 671 struct se_lun *lun = to_stat_tgt_port(item);
800 struct se_device *dev; 672 struct se_device *dev;
801 ssize_t ret = -ENODEV; 673 ssize_t ret = -ENODEV;
802 674
@@ -809,57 +681,49 @@ static ssize_t target_stat_scsi_tgt_port_show_attr_hs_in_cmds(
809 rcu_read_unlock(); 681 rcu_read_unlock();
810 return ret; 682 return ret;
811} 683}
812DEV_STAT_SCSI_TGT_PORT_ATTR_RO(hs_in_cmds);
813 684
814CONFIGFS_EATTR_OPS(target_stat_scsi_tgt_port, se_port_stat_grps, 685CONFIGFS_ATTR_RO(target_stat_tgt_port_, inst);
815 scsi_tgt_port_group); 686CONFIGFS_ATTR_RO(target_stat_tgt_port_, dev);
687CONFIGFS_ATTR_RO(target_stat_tgt_port_, indx);
688CONFIGFS_ATTR_RO(target_stat_tgt_port_, name);
689CONFIGFS_ATTR_RO(target_stat_tgt_port_, port_index);
690CONFIGFS_ATTR_RO(target_stat_tgt_port_, in_cmds);
691CONFIGFS_ATTR_RO(target_stat_tgt_port_, write_mbytes);
692CONFIGFS_ATTR_RO(target_stat_tgt_port_, read_mbytes);
693CONFIGFS_ATTR_RO(target_stat_tgt_port_, hs_in_cmds);
816 694
817static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = { 695static struct configfs_attribute *target_stat_scsi_tgt_port_attrs[] = {
818 &target_stat_scsi_tgt_port_inst.attr, 696 &target_stat_tgt_port_attr_inst,
819 &target_stat_scsi_tgt_port_dev.attr, 697 &target_stat_tgt_port_attr_dev,
820 &target_stat_scsi_tgt_port_indx.attr, 698 &target_stat_tgt_port_attr_indx,
821 &target_stat_scsi_tgt_port_name.attr, 699 &target_stat_tgt_port_attr_name,
822 &target_stat_scsi_tgt_port_port_index.attr, 700 &target_stat_tgt_port_attr_port_index,
823 &target_stat_scsi_tgt_port_in_cmds.attr, 701 &target_stat_tgt_port_attr_in_cmds,
824 &target_stat_scsi_tgt_port_write_mbytes.attr, 702 &target_stat_tgt_port_attr_write_mbytes,
825 &target_stat_scsi_tgt_port_read_mbytes.attr, 703 &target_stat_tgt_port_attr_read_mbytes,
826 &target_stat_scsi_tgt_port_hs_in_cmds.attr, 704 &target_stat_tgt_port_attr_hs_in_cmds,
827 NULL, 705 NULL,
828}; 706};
829 707
830static struct configfs_item_operations target_stat_scsi_tgt_port_attrib_ops = {
831 .show_attribute = target_stat_scsi_tgt_port_attr_show,
832 .store_attribute = target_stat_scsi_tgt_port_attr_store,
833};
834
835static struct config_item_type target_stat_scsi_tgt_port_cit = { 708static struct config_item_type target_stat_scsi_tgt_port_cit = {
836 .ct_item_ops = &target_stat_scsi_tgt_port_attrib_ops,
837 .ct_attrs = target_stat_scsi_tgt_port_attrs, 709 .ct_attrs = target_stat_scsi_tgt_port_attrs,
838 .ct_owner = THIS_MODULE, 710 .ct_owner = THIS_MODULE,
839}; 711};
840 712
841/* 713/*
842 * SCSI Transport Table 714 * SCSI Transport Table
843o */ 715 */
844 716static struct se_lun *to_transport_stat(struct config_item *item)
845CONFIGFS_EATTR_STRUCT(target_stat_scsi_transport, se_port_stat_grps); 717{
846#define DEV_STAT_SCSI_TRANSPORT_ATTR(_name, _mode) \ 718 struct se_port_stat_grps *pgrps = container_of(to_config_group(item),
847static struct target_stat_scsi_transport_attribute \ 719 struct se_port_stat_grps, scsi_transport_group);
848 target_stat_scsi_transport_##_name = \ 720 return container_of(pgrps, struct se_lun, port_stat_grps);
849 __CONFIGFS_EATTR(_name, _mode, \ 721}
850 target_stat_scsi_transport_show_attr_##_name, \ 722
851 target_stat_scsi_transport_store_attr_##_name); 723static ssize_t target_stat_transport_inst_show(struct config_item *item,
852 724 char *page)
853#define DEV_STAT_SCSI_TRANSPORT_ATTR_RO(_name) \ 725{
854static struct target_stat_scsi_transport_attribute \ 726 struct se_lun *lun = to_transport_stat(item);
855 target_stat_scsi_transport_##_name = \
856 __CONFIGFS_EATTR_RO(_name, \
857 target_stat_scsi_transport_show_attr_##_name);
858
859static ssize_t target_stat_scsi_transport_show_attr_inst(
860 struct se_port_stat_grps *pgrps, char *page)
861{
862 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps);
863 struct se_device *dev; 727 struct se_device *dev;
864 ssize_t ret = -ENODEV; 728 ssize_t ret = -ENODEV;
865 729
@@ -870,12 +734,11 @@ static ssize_t target_stat_scsi_transport_show_attr_inst(
870 rcu_read_unlock(); 734 rcu_read_unlock();
871 return ret; 735 return ret;
872} 736}
873DEV_STAT_SCSI_TRANSPORT_ATTR_RO(inst);
874 737
875static ssize_t target_stat_scsi_transport_show_attr_device( 738static ssize_t target_stat_transport_device_show(struct config_item *item,
876 struct se_port_stat_grps *pgrps, char *page) 739 char *page)
877{ 740{
878 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 741 struct se_lun *lun = to_transport_stat(item);
879 struct se_device *dev; 742 struct se_device *dev;
880 struct se_portal_group *tpg = lun->lun_tpg; 743 struct se_portal_group *tpg = lun->lun_tpg;
881 ssize_t ret = -ENODEV; 744 ssize_t ret = -ENODEV;
@@ -890,12 +753,11 @@ static ssize_t target_stat_scsi_transport_show_attr_device(
890 rcu_read_unlock(); 753 rcu_read_unlock();
891 return ret; 754 return ret;
892} 755}
893DEV_STAT_SCSI_TRANSPORT_ATTR_RO(device);
894 756
895static ssize_t target_stat_scsi_transport_show_attr_indx( 757static ssize_t target_stat_transport_indx_show(struct config_item *item,
896 struct se_port_stat_grps *pgrps, char *page) 758 char *page)
897{ 759{
898 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 760 struct se_lun *lun = to_transport_stat(item);
899 struct se_device *dev; 761 struct se_device *dev;
900 struct se_portal_group *tpg = lun->lun_tpg; 762 struct se_portal_group *tpg = lun->lun_tpg;
901 ssize_t ret = -ENODEV; 763 ssize_t ret = -ENODEV;
@@ -908,12 +770,11 @@ static ssize_t target_stat_scsi_transport_show_attr_indx(
908 rcu_read_unlock(); 770 rcu_read_unlock();
909 return ret; 771 return ret;
910} 772}
911DEV_STAT_SCSI_TRANSPORT_ATTR_RO(indx);
912 773
913static ssize_t target_stat_scsi_transport_show_attr_dev_name( 774static ssize_t target_stat_transport_dev_name_show(struct config_item *item,
914 struct se_port_stat_grps *pgrps, char *page) 775 char *page)
915{ 776{
916 struct se_lun *lun = container_of(pgrps, struct se_lun, port_stat_grps); 777 struct se_lun *lun = to_transport_stat(item);
917 struct se_device *dev; 778 struct se_device *dev;
918 struct se_portal_group *tpg = lun->lun_tpg; 779 struct se_portal_group *tpg = lun->lun_tpg;
919 struct t10_wwn *wwn; 780 struct t10_wwn *wwn;
@@ -932,26 +793,21 @@ static ssize_t target_stat_scsi_transport_show_attr_dev_name(
932 rcu_read_unlock(); 793 rcu_read_unlock();
933 return ret; 794 return ret;
934} 795}
935DEV_STAT_SCSI_TRANSPORT_ATTR_RO(dev_name);
936 796
937CONFIGFS_EATTR_OPS(target_stat_scsi_transport, se_port_stat_grps, 797CONFIGFS_ATTR_RO(target_stat_transport_, inst);
938 scsi_transport_group); 798CONFIGFS_ATTR_RO(target_stat_transport_, device);
799CONFIGFS_ATTR_RO(target_stat_transport_, indx);
800CONFIGFS_ATTR_RO(target_stat_transport_, dev_name);
939 801
940static struct configfs_attribute *target_stat_scsi_transport_attrs[] = { 802static struct configfs_attribute *target_stat_scsi_transport_attrs[] = {
941 &target_stat_scsi_transport_inst.attr, 803 &target_stat_transport_attr_inst,
942 &target_stat_scsi_transport_device.attr, 804 &target_stat_transport_attr_device,
943 &target_stat_scsi_transport_indx.attr, 805 &target_stat_transport_attr_indx,
944 &target_stat_scsi_transport_dev_name.attr, 806 &target_stat_transport_attr_dev_name,
945 NULL, 807 NULL,
946}; 808};
947 809
948static struct configfs_item_operations target_stat_scsi_transport_attrib_ops = {
949 .show_attribute = target_stat_scsi_transport_attr_show,
950 .store_attribute = target_stat_scsi_transport_attr_store,
951};
952
953static struct config_item_type target_stat_scsi_transport_cit = { 810static struct config_item_type target_stat_scsi_transport_cit = {
954 .ct_item_ops = &target_stat_scsi_transport_attrib_ops,
955 .ct_attrs = target_stat_scsi_transport_attrs, 811 .ct_attrs = target_stat_scsi_transport_attrs,
956 .ct_owner = THIS_MODULE, 812 .ct_owner = THIS_MODULE,
957}; 813};
@@ -981,25 +837,17 @@ void target_stat_setup_port_default_groups(struct se_lun *lun)
981 * SCSI Authorized Initiator Table 837 * SCSI Authorized Initiator Table
982 */ 838 */
983 839
984CONFIGFS_EATTR_STRUCT(target_stat_scsi_auth_intr, se_ml_stat_grps); 840static struct se_lun_acl *auth_to_lacl(struct config_item *item)
985#define DEV_STAT_SCSI_AUTH_INTR_ATTR(_name, _mode) \ 841{
986static struct target_stat_scsi_auth_intr_attribute \ 842 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
987 target_stat_scsi_auth_intr_##_name = \ 843 struct se_ml_stat_grps, scsi_auth_intr_group);
988 __CONFIGFS_EATTR(_name, _mode, \ 844 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
989 target_stat_scsi_auth_intr_show_attr_##_name, \ 845}
990 target_stat_scsi_auth_intr_store_attr_##_name); 846
991 847static ssize_t target_stat_auth_inst_show(struct config_item *item,
992#define DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(_name) \ 848 char *page)
993static struct target_stat_scsi_auth_intr_attribute \ 849{
994 target_stat_scsi_auth_intr_##_name = \ 850 struct se_lun_acl *lacl = auth_to_lacl(item);
995 __CONFIGFS_EATTR_RO(_name, \
996 target_stat_scsi_auth_intr_show_attr_##_name);
997
998static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
999 struct se_ml_stat_grps *lgrps, char *page)
1000{
1001 struct se_lun_acl *lacl = container_of(lgrps,
1002 struct se_lun_acl, ml_stat_grps);
1003 struct se_node_acl *nacl = lacl->se_lun_nacl; 851 struct se_node_acl *nacl = lacl->se_lun_nacl;
1004 struct se_dev_entry *deve; 852 struct se_dev_entry *deve;
1005 struct se_portal_group *tpg; 853 struct se_portal_group *tpg;
@@ -1018,13 +866,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_inst(
1018 rcu_read_unlock(); 866 rcu_read_unlock();
1019 return ret; 867 return ret;
1020} 868}
1021DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(inst);
1022 869
1023static ssize_t target_stat_scsi_auth_intr_show_attr_dev( 870static ssize_t target_stat_auth_dev_show(struct config_item *item,
1024 struct se_ml_stat_grps *lgrps, char *page) 871 char *page)
1025{ 872{
1026 struct se_lun_acl *lacl = container_of(lgrps, 873 struct se_lun_acl *lacl = auth_to_lacl(item);
1027 struct se_lun_acl, ml_stat_grps);
1028 struct se_node_acl *nacl = lacl->se_lun_nacl; 874 struct se_node_acl *nacl = lacl->se_lun_nacl;
1029 struct se_dev_entry *deve; 875 struct se_dev_entry *deve;
1030 struct se_lun *lun; 876 struct se_lun *lun;
@@ -1042,13 +888,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_dev(
1042 rcu_read_unlock(); 888 rcu_read_unlock();
1043 return ret; 889 return ret;
1044} 890}
1045DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev);
1046 891
1047static ssize_t target_stat_scsi_auth_intr_show_attr_port( 892static ssize_t target_stat_auth_port_show(struct config_item *item,
1048 struct se_ml_stat_grps *lgrps, char *page) 893 char *page)
1049{ 894{
1050 struct se_lun_acl *lacl = container_of(lgrps, 895 struct se_lun_acl *lacl = auth_to_lacl(item);
1051 struct se_lun_acl, ml_stat_grps);
1052 struct se_node_acl *nacl = lacl->se_lun_nacl; 896 struct se_node_acl *nacl = lacl->se_lun_nacl;
1053 struct se_dev_entry *deve; 897 struct se_dev_entry *deve;
1054 struct se_portal_group *tpg; 898 struct se_portal_group *tpg;
@@ -1066,13 +910,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_port(
1066 rcu_read_unlock(); 910 rcu_read_unlock();
1067 return ret; 911 return ret;
1068} 912}
1069DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(port);
1070 913
1071static ssize_t target_stat_scsi_auth_intr_show_attr_indx( 914static ssize_t target_stat_auth_indx_show(struct config_item *item,
1072 struct se_ml_stat_grps *lgrps, char *page) 915 char *page)
1073{ 916{
1074 struct se_lun_acl *lacl = container_of(lgrps, 917 struct se_lun_acl *lacl = auth_to_lacl(item);
1075 struct se_lun_acl, ml_stat_grps);
1076 struct se_node_acl *nacl = lacl->se_lun_nacl; 918 struct se_node_acl *nacl = lacl->se_lun_nacl;
1077 struct se_dev_entry *deve; 919 struct se_dev_entry *deve;
1078 ssize_t ret; 920 ssize_t ret;
@@ -1088,13 +930,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_indx(
1088 rcu_read_unlock(); 930 rcu_read_unlock();
1089 return ret; 931 return ret;
1090} 932}
1091DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(indx);
1092 933
1093static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port( 934static ssize_t target_stat_auth_dev_or_port_show(struct config_item *item,
1094 struct se_ml_stat_grps *lgrps, char *page) 935 char *page)
1095{ 936{
1096 struct se_lun_acl *lacl = container_of(lgrps, 937 struct se_lun_acl *lacl = auth_to_lacl(item);
1097 struct se_lun_acl, ml_stat_grps);
1098 struct se_node_acl *nacl = lacl->se_lun_nacl; 938 struct se_node_acl *nacl = lacl->se_lun_nacl;
1099 struct se_dev_entry *deve; 939 struct se_dev_entry *deve;
1100 ssize_t ret; 940 ssize_t ret;
@@ -1110,13 +950,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_dev_or_port(
1110 rcu_read_unlock(); 950 rcu_read_unlock();
1111 return ret; 951 return ret;
1112} 952}
1113DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(dev_or_port);
1114 953
1115static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name( 954static ssize_t target_stat_auth_intr_name_show(struct config_item *item,
1116 struct se_ml_stat_grps *lgrps, char *page) 955 char *page)
1117{ 956{
1118 struct se_lun_acl *lacl = container_of(lgrps, 957 struct se_lun_acl *lacl = auth_to_lacl(item);
1119 struct se_lun_acl, ml_stat_grps);
1120 struct se_node_acl *nacl = lacl->se_lun_nacl; 958 struct se_node_acl *nacl = lacl->se_lun_nacl;
1121 struct se_dev_entry *deve; 959 struct se_dev_entry *deve;
1122 ssize_t ret; 960 ssize_t ret;
@@ -1132,13 +970,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_intr_name(
1132 rcu_read_unlock(); 970 rcu_read_unlock();
1133 return ret; 971 return ret;
1134} 972}
1135DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(intr_name);
1136 973
1137static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx( 974static ssize_t target_stat_auth_map_indx_show(struct config_item *item,
1138 struct se_ml_stat_grps *lgrps, char *page) 975 char *page)
1139{ 976{
1140 struct se_lun_acl *lacl = container_of(lgrps, 977 struct se_lun_acl *lacl = auth_to_lacl(item);
1141 struct se_lun_acl, ml_stat_grps);
1142 struct se_node_acl *nacl = lacl->se_lun_nacl; 978 struct se_node_acl *nacl = lacl->se_lun_nacl;
1143 struct se_dev_entry *deve; 979 struct se_dev_entry *deve;
1144 ssize_t ret; 980 ssize_t ret;
@@ -1154,13 +990,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_map_indx(
1154 rcu_read_unlock(); 990 rcu_read_unlock();
1155 return ret; 991 return ret;
1156} 992}
1157DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(map_indx);
1158 993
1159static ssize_t target_stat_scsi_auth_intr_show_attr_att_count( 994static ssize_t target_stat_auth_att_count_show(struct config_item *item,
1160 struct se_ml_stat_grps *lgrps, char *page) 995 char *page)
1161{ 996{
1162 struct se_lun_acl *lacl = container_of(lgrps, 997 struct se_lun_acl *lacl = auth_to_lacl(item);
1163 struct se_lun_acl, ml_stat_grps);
1164 struct se_node_acl *nacl = lacl->se_lun_nacl; 998 struct se_node_acl *nacl = lacl->se_lun_nacl;
1165 struct se_dev_entry *deve; 999 struct se_dev_entry *deve;
1166 ssize_t ret; 1000 ssize_t ret;
@@ -1176,13 +1010,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_att_count(
1176 rcu_read_unlock(); 1010 rcu_read_unlock();
1177 return ret; 1011 return ret;
1178} 1012}
1179DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(att_count);
1180 1013
1181static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds( 1014static ssize_t target_stat_auth_num_cmds_show(struct config_item *item,
1182 struct se_ml_stat_grps *lgrps, char *page) 1015 char *page)
1183{ 1016{
1184 struct se_lun_acl *lacl = container_of(lgrps, 1017 struct se_lun_acl *lacl = auth_to_lacl(item);
1185 struct se_lun_acl, ml_stat_grps);
1186 struct se_node_acl *nacl = lacl->se_lun_nacl; 1018 struct se_node_acl *nacl = lacl->se_lun_nacl;
1187 struct se_dev_entry *deve; 1019 struct se_dev_entry *deve;
1188 ssize_t ret; 1020 ssize_t ret;
@@ -1199,13 +1031,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_num_cmds(
1199 rcu_read_unlock(); 1031 rcu_read_unlock();
1200 return ret; 1032 return ret;
1201} 1033}
1202DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(num_cmds);
1203 1034
1204static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes( 1035static ssize_t target_stat_auth_read_mbytes_show(struct config_item *item,
1205 struct se_ml_stat_grps *lgrps, char *page) 1036 char *page)
1206{ 1037{
1207 struct se_lun_acl *lacl = container_of(lgrps, 1038 struct se_lun_acl *lacl = auth_to_lacl(item);
1208 struct se_lun_acl, ml_stat_grps);
1209 struct se_node_acl *nacl = lacl->se_lun_nacl; 1039 struct se_node_acl *nacl = lacl->se_lun_nacl;
1210 struct se_dev_entry *deve; 1040 struct se_dev_entry *deve;
1211 ssize_t ret; 1041 ssize_t ret;
@@ -1222,13 +1052,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_read_mbytes(
1222 rcu_read_unlock(); 1052 rcu_read_unlock();
1223 return ret; 1053 return ret;
1224} 1054}
1225DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(read_mbytes);
1226 1055
1227static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes( 1056static ssize_t target_stat_auth_write_mbytes_show(struct config_item *item,
1228 struct se_ml_stat_grps *lgrps, char *page) 1057 char *page)
1229{ 1058{
1230 struct se_lun_acl *lacl = container_of(lgrps, 1059 struct se_lun_acl *lacl = auth_to_lacl(item);
1231 struct se_lun_acl, ml_stat_grps);
1232 struct se_node_acl *nacl = lacl->se_lun_nacl; 1060 struct se_node_acl *nacl = lacl->se_lun_nacl;
1233 struct se_dev_entry *deve; 1061 struct se_dev_entry *deve;
1234 ssize_t ret; 1062 ssize_t ret;
@@ -1245,13 +1073,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_write_mbytes(
1245 rcu_read_unlock(); 1073 rcu_read_unlock();
1246 return ret; 1074 return ret;
1247} 1075}
1248DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(write_mbytes);
1249 1076
1250static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds( 1077static ssize_t target_stat_auth_hs_num_cmds_show(struct config_item *item,
1251 struct se_ml_stat_grps *lgrps, char *page) 1078 char *page)
1252{ 1079{
1253 struct se_lun_acl *lacl = container_of(lgrps, 1080 struct se_lun_acl *lacl = auth_to_lacl(item);
1254 struct se_lun_acl, ml_stat_grps);
1255 struct se_node_acl *nacl = lacl->se_lun_nacl; 1081 struct se_node_acl *nacl = lacl->se_lun_nacl;
1256 struct se_dev_entry *deve; 1082 struct se_dev_entry *deve;
1257 ssize_t ret; 1083 ssize_t ret;
@@ -1267,13 +1093,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_hs_num_cmds(
1267 rcu_read_unlock(); 1093 rcu_read_unlock();
1268 return ret; 1094 return ret;
1269} 1095}
1270DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(hs_num_cmds);
1271 1096
1272static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time( 1097static ssize_t target_stat_auth_creation_time_show(struct config_item *item,
1273 struct se_ml_stat_grps *lgrps, char *page) 1098 char *page)
1274{ 1099{
1275 struct se_lun_acl *lacl = container_of(lgrps, 1100 struct se_lun_acl *lacl = auth_to_lacl(item);
1276 struct se_lun_acl, ml_stat_grps);
1277 struct se_node_acl *nacl = lacl->se_lun_nacl; 1101 struct se_node_acl *nacl = lacl->se_lun_nacl;
1278 struct se_dev_entry *deve; 1102 struct se_dev_entry *deve;
1279 ssize_t ret; 1103 ssize_t ret;
@@ -1290,13 +1114,11 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_creation_time(
1290 rcu_read_unlock(); 1114 rcu_read_unlock();
1291 return ret; 1115 return ret;
1292} 1116}
1293DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(creation_time);
1294 1117
1295static ssize_t target_stat_scsi_auth_intr_show_attr_row_status( 1118static ssize_t target_stat_auth_row_status_show(struct config_item *item,
1296 struct se_ml_stat_grps *lgrps, char *page) 1119 char *page)
1297{ 1120{
1298 struct se_lun_acl *lacl = container_of(lgrps, 1121 struct se_lun_acl *lacl = auth_to_lacl(item);
1299 struct se_lun_acl, ml_stat_grps);
1300 struct se_node_acl *nacl = lacl->se_lun_nacl; 1122 struct se_node_acl *nacl = lacl->se_lun_nacl;
1301 struct se_dev_entry *deve; 1123 struct se_dev_entry *deve;
1302 ssize_t ret; 1124 ssize_t ret;
@@ -1312,36 +1134,41 @@ static ssize_t target_stat_scsi_auth_intr_show_attr_row_status(
1312 rcu_read_unlock(); 1134 rcu_read_unlock();
1313 return ret; 1135 return ret;
1314} 1136}
1315DEV_STAT_SCSI_AUTH_INTR_ATTR_RO(row_status);
1316 1137
1317CONFIGFS_EATTR_OPS(target_stat_scsi_auth_intr, se_ml_stat_grps, 1138CONFIGFS_ATTR_RO(target_stat_auth_, inst);
1318 scsi_auth_intr_group); 1139CONFIGFS_ATTR_RO(target_stat_auth_, dev);
1140CONFIGFS_ATTR_RO(target_stat_auth_, port);
1141CONFIGFS_ATTR_RO(target_stat_auth_, indx);
1142CONFIGFS_ATTR_RO(target_stat_auth_, dev_or_port);
1143CONFIGFS_ATTR_RO(target_stat_auth_, intr_name);
1144CONFIGFS_ATTR_RO(target_stat_auth_, map_indx);
1145CONFIGFS_ATTR_RO(target_stat_auth_, att_count);
1146CONFIGFS_ATTR_RO(target_stat_auth_, num_cmds);
1147CONFIGFS_ATTR_RO(target_stat_auth_, read_mbytes);
1148CONFIGFS_ATTR_RO(target_stat_auth_, write_mbytes);
1149CONFIGFS_ATTR_RO(target_stat_auth_, hs_num_cmds);
1150CONFIGFS_ATTR_RO(target_stat_auth_, creation_time);
1151CONFIGFS_ATTR_RO(target_stat_auth_, row_status);
1319 1152
1320static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = { 1153static struct configfs_attribute *target_stat_scsi_auth_intr_attrs[] = {
1321 &target_stat_scsi_auth_intr_inst.attr, 1154 &target_stat_auth_attr_inst,
1322 &target_stat_scsi_auth_intr_dev.attr, 1155 &target_stat_auth_attr_dev,
1323 &target_stat_scsi_auth_intr_port.attr, 1156 &target_stat_auth_attr_port,
1324 &target_stat_scsi_auth_intr_indx.attr, 1157 &target_stat_auth_attr_indx,
1325 &target_stat_scsi_auth_intr_dev_or_port.attr, 1158 &target_stat_auth_attr_dev_or_port,
1326 &target_stat_scsi_auth_intr_intr_name.attr, 1159 &target_stat_auth_attr_intr_name,
1327 &target_stat_scsi_auth_intr_map_indx.attr, 1160 &target_stat_auth_attr_map_indx,
1328 &target_stat_scsi_auth_intr_att_count.attr, 1161 &target_stat_auth_attr_att_count,
1329 &target_stat_scsi_auth_intr_num_cmds.attr, 1162 &target_stat_auth_attr_num_cmds,
1330 &target_stat_scsi_auth_intr_read_mbytes.attr, 1163 &target_stat_auth_attr_read_mbytes,
1331 &target_stat_scsi_auth_intr_write_mbytes.attr, 1164 &target_stat_auth_attr_write_mbytes,
1332 &target_stat_scsi_auth_intr_hs_num_cmds.attr, 1165 &target_stat_auth_attr_hs_num_cmds,
1333 &target_stat_scsi_auth_intr_creation_time.attr, 1166 &target_stat_auth_attr_creation_time,
1334 &target_stat_scsi_auth_intr_row_status.attr, 1167 &target_stat_auth_attr_row_status,
1335 NULL, 1168 NULL,
1336}; 1169};
1337 1170
1338static struct configfs_item_operations target_stat_scsi_auth_intr_attrib_ops = {
1339 .show_attribute = target_stat_scsi_auth_intr_attr_show,
1340 .store_attribute = target_stat_scsi_auth_intr_attr_store,
1341};
1342
1343static struct config_item_type target_stat_scsi_auth_intr_cit = { 1171static struct config_item_type target_stat_scsi_auth_intr_cit = {
1344 .ct_item_ops = &target_stat_scsi_auth_intr_attrib_ops,
1345 .ct_attrs = target_stat_scsi_auth_intr_attrs, 1172 .ct_attrs = target_stat_scsi_auth_intr_attrs,
1346 .ct_owner = THIS_MODULE, 1173 .ct_owner = THIS_MODULE,
1347}; 1174};
@@ -1350,25 +1177,17 @@ static struct config_item_type target_stat_scsi_auth_intr_cit = {
1350 * SCSI Attached Initiator Port Table 1177 * SCSI Attached Initiator Port Table
1351 */ 1178 */
1352 1179
1353CONFIGFS_EATTR_STRUCT(target_stat_scsi_att_intr_port, se_ml_stat_grps); 1180static struct se_lun_acl *iport_to_lacl(struct config_item *item)
1354#define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR(_name, _mode) \ 1181{
1355static struct target_stat_scsi_att_intr_port_attribute \ 1182 struct se_ml_stat_grps *lgrps = container_of(to_config_group(item),
1356 target_stat_scsi_att_intr_port_##_name = \ 1183 struct se_ml_stat_grps, scsi_att_intr_port_group);
1357 __CONFIGFS_EATTR(_name, _mode, \ 1184 return container_of(lgrps, struct se_lun_acl, ml_stat_grps);
1358 target_stat_scsi_att_intr_port_show_attr_##_name, \ 1185}
1359 target_stat_scsi_att_intr_port_store_attr_##_name); 1186
1360 1187static ssize_t target_stat_iport_inst_show(struct config_item *item,
1361#define DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(_name) \ 1188 char *page)
1362static struct target_stat_scsi_att_intr_port_attribute \ 1189{
1363 target_stat_scsi_att_intr_port_##_name = \ 1190 struct se_lun_acl *lacl = iport_to_lacl(item);
1364 __CONFIGFS_EATTR_RO(_name, \
1365 target_stat_scsi_att_intr_port_show_attr_##_name);
1366
1367static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1368 struct se_ml_stat_grps *lgrps, char *page)
1369{
1370 struct se_lun_acl *lacl = container_of(lgrps,
1371 struct se_lun_acl, ml_stat_grps);
1372 struct se_node_acl *nacl = lacl->se_lun_nacl; 1191 struct se_node_acl *nacl = lacl->se_lun_nacl;
1373 struct se_dev_entry *deve; 1192 struct se_dev_entry *deve;
1374 struct se_portal_group *tpg; 1193 struct se_portal_group *tpg;
@@ -1387,13 +1206,11 @@ static ssize_t target_stat_scsi_att_intr_port_show_attr_inst(
1387 rcu_read_unlock(); 1206 rcu_read_unlock();
1388 return ret; 1207 return ret;
1389} 1208}
1390DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(inst);
1391 1209
1392static ssize_t target_stat_scsi_att_intr_port_show_attr_dev( 1210static ssize_t target_stat_iport_dev_show(struct config_item *item,
1393 struct se_ml_stat_grps *lgrps, char *page) 1211 char *page)
1394{ 1212{
1395 struct se_lun_acl *lacl = container_of(lgrps, 1213 struct se_lun_acl *lacl = iport_to_lacl(item);
1396 struct se_lun_acl, ml_stat_grps);
1397 struct se_node_acl *nacl = lacl->se_lun_nacl; 1214 struct se_node_acl *nacl = lacl->se_lun_nacl;
1398 struct se_dev_entry *deve; 1215 struct se_dev_entry *deve;
1399 struct se_lun *lun; 1216 struct se_lun *lun;
@@ -1411,13 +1228,11 @@ static ssize_t target_stat_scsi_att_intr_port_show_attr_dev(
1411 rcu_read_unlock(); 1228 rcu_read_unlock();
1412 return ret; 1229 return ret;
1413} 1230}
1414DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(dev);
1415 1231
1416static ssize_t target_stat_scsi_att_intr_port_show_attr_port( 1232static ssize_t target_stat_iport_port_show(struct config_item *item,
1417 struct se_ml_stat_grps *lgrps, char *page) 1233 char *page)
1418{ 1234{
1419 struct se_lun_acl *lacl = container_of(lgrps, 1235 struct se_lun_acl *lacl = iport_to_lacl(item);
1420 struct se_lun_acl, ml_stat_grps);
1421 struct se_node_acl *nacl = lacl->se_lun_nacl; 1236 struct se_node_acl *nacl = lacl->se_lun_nacl;
1422 struct se_dev_entry *deve; 1237 struct se_dev_entry *deve;
1423 struct se_portal_group *tpg; 1238 struct se_portal_group *tpg;
@@ -1435,13 +1250,11 @@ static ssize_t target_stat_scsi_att_intr_port_show_attr_port(
1435 rcu_read_unlock(); 1250 rcu_read_unlock();
1436 return ret; 1251 return ret;
1437} 1252}
1438DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port);
1439 1253
1440static ssize_t target_stat_scsi_att_intr_port_show_attr_indx( 1254static ssize_t target_stat_iport_indx_show(struct config_item *item,
1441 struct se_ml_stat_grps *lgrps, char *page) 1255 char *page)
1442{ 1256{
1443 struct se_lun_acl *lacl = container_of(lgrps, 1257 struct se_lun_acl *lacl = iport_to_lacl(item);
1444 struct se_lun_acl, ml_stat_grps);
1445 struct se_node_acl *nacl = lacl->se_lun_nacl; 1258 struct se_node_acl *nacl = lacl->se_lun_nacl;
1446 struct se_session *se_sess; 1259 struct se_session *se_sess;
1447 struct se_portal_group *tpg; 1260 struct se_portal_group *tpg;
@@ -1461,13 +1274,11 @@ static ssize_t target_stat_scsi_att_intr_port_show_attr_indx(
1461 spin_unlock_irq(&nacl->nacl_sess_lock); 1274 spin_unlock_irq(&nacl->nacl_sess_lock);
1462 return ret; 1275 return ret;
1463} 1276}
1464DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(indx);
1465 1277
1466static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx( 1278static ssize_t target_stat_iport_port_auth_indx_show(struct config_item *item,
1467 struct se_ml_stat_grps *lgrps, char *page) 1279 char *page)
1468{ 1280{
1469 struct se_lun_acl *lacl = container_of(lgrps, 1281 struct se_lun_acl *lacl = iport_to_lacl(item);
1470 struct se_lun_acl, ml_stat_grps);
1471 struct se_node_acl *nacl = lacl->se_lun_nacl; 1282 struct se_node_acl *nacl = lacl->se_lun_nacl;
1472 struct se_dev_entry *deve; 1283 struct se_dev_entry *deve;
1473 ssize_t ret; 1284 ssize_t ret;
@@ -1483,13 +1294,11 @@ static ssize_t target_stat_scsi_att_intr_port_show_attr_port_auth_indx(
1483 rcu_read_unlock(); 1294 rcu_read_unlock();
1484 return ret; 1295 return ret;
1485} 1296}
1486DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_auth_indx);
1487 1297
1488static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident( 1298static ssize_t target_stat_iport_port_ident_show(struct config_item *item,
1489 struct se_ml_stat_grps *lgrps, char *page) 1299 char *page)
1490{ 1300{
1491 struct se_lun_acl *lacl = container_of(lgrps, 1301 struct se_lun_acl *lacl = iport_to_lacl(item);
1492 struct se_lun_acl, ml_stat_grps);
1493 struct se_node_acl *nacl = lacl->se_lun_nacl; 1302 struct se_node_acl *nacl = lacl->se_lun_nacl;
1494 struct se_session *se_sess; 1303 struct se_session *se_sess;
1495 struct se_portal_group *tpg; 1304 struct se_portal_group *tpg;
@@ -1513,28 +1322,25 @@ static ssize_t target_stat_scsi_att_intr_port_show_attr_port_ident(
1513 spin_unlock_irq(&nacl->nacl_sess_lock); 1322 spin_unlock_irq(&nacl->nacl_sess_lock);
1514 return ret; 1323 return ret;
1515} 1324}
1516DEV_STAT_SCSI_ATTR_INTR_PORT_ATTR_RO(port_ident);
1517 1325
1518CONFIGFS_EATTR_OPS(target_stat_scsi_att_intr_port, se_ml_stat_grps, 1326CONFIGFS_ATTR_RO(target_stat_iport_, inst);
1519 scsi_att_intr_port_group); 1327CONFIGFS_ATTR_RO(target_stat_iport_, dev);
1328CONFIGFS_ATTR_RO(target_stat_iport_, port);
1329CONFIGFS_ATTR_RO(target_stat_iport_, indx);
1330CONFIGFS_ATTR_RO(target_stat_iport_, port_auth_indx);
1331CONFIGFS_ATTR_RO(target_stat_iport_, port_ident);
1520 1332
1521static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = { 1333static struct configfs_attribute *target_stat_scsi_ath_intr_port_attrs[] = {
1522 &target_stat_scsi_att_intr_port_inst.attr, 1334 &target_stat_iport_attr_inst,
1523 &target_stat_scsi_att_intr_port_dev.attr, 1335 &target_stat_iport_attr_dev,
1524 &target_stat_scsi_att_intr_port_port.attr, 1336 &target_stat_iport_attr_port,
1525 &target_stat_scsi_att_intr_port_indx.attr, 1337 &target_stat_iport_attr_indx,
1526 &target_stat_scsi_att_intr_port_port_auth_indx.attr, 1338 &target_stat_iport_attr_port_auth_indx,
1527 &target_stat_scsi_att_intr_port_port_ident.attr, 1339 &target_stat_iport_attr_port_ident,
1528 NULL, 1340 NULL,
1529}; 1341};
1530 1342
1531static struct configfs_item_operations target_stat_scsi_att_intr_port_attrib_ops = {
1532 .show_attribute = target_stat_scsi_att_intr_port_attr_show,
1533 .store_attribute = target_stat_scsi_att_intr_port_attr_store,
1534};
1535
1536static struct config_item_type target_stat_scsi_att_intr_port_cit = { 1343static struct config_item_type target_stat_scsi_att_intr_port_cit = {
1537 .ct_item_ops = &target_stat_scsi_att_intr_port_attrib_ops,
1538 .ct_attrs = target_stat_scsi_ath_intr_port_attrs, 1344 .ct_attrs = target_stat_scsi_ath_intr_port_attrs,
1539 .ct_owner = THIS_MODULE, 1345 .ct_owner = THIS_MODULE,
1540}; 1346};
diff --git a/drivers/target/tcm_fc/tfc_cmd.c b/drivers/target/tcm_fc/tfc_cmd.c
index aa3caca8bace..064d6dfb5b6d 100644
--- a/drivers/target/tcm_fc/tfc_cmd.c
+++ b/drivers/target/tcm_fc/tfc_cmd.c
@@ -36,7 +36,6 @@
36 36
37#include <target/target_core_base.h> 37#include <target/target_core_base.h>
38#include <target/target_core_fabric.h> 38#include <target/target_core_fabric.h>
39#include <target/configfs_macros.h>
40 39
41#include "tcm_fc.h" 40#include "tcm_fc.h"
42 41
diff --git a/drivers/target/tcm_fc/tfc_conf.c b/drivers/target/tcm_fc/tfc_conf.c
index 16670933013b..85aeaa0ad303 100644
--- a/drivers/target/tcm_fc/tfc_conf.c
+++ b/drivers/target/tcm_fc/tfc_conf.c
@@ -38,8 +38,6 @@
38 38
39#include <target/target_core_base.h> 39#include <target/target_core_base.h>
40#include <target/target_core_fabric.h> 40#include <target/target_core_fabric.h>
41#include <target/target_core_fabric_configfs.h>
42#include <target/configfs_macros.h>
43 41
44#include "tcm_fc.h" 42#include "tcm_fc.h"
45 43
@@ -131,55 +129,51 @@ static ssize_t ft_wwn_store(void *arg, const char *buf, size_t len)
131 * ACL auth ops. 129 * ACL auth ops.
132 */ 130 */
133 131
134static ssize_t ft_nacl_show_port_name( 132static ssize_t ft_nacl_port_name_show(struct config_item *item, char *page)
135 struct se_node_acl *se_nacl,
136 char *page)
137{ 133{
134 struct se_node_acl *se_nacl = acl_to_nacl(item);
138 struct ft_node_acl *acl = container_of(se_nacl, 135 struct ft_node_acl *acl = container_of(se_nacl,
139 struct ft_node_acl, se_node_acl); 136 struct ft_node_acl, se_node_acl);
140 137
141 return ft_wwn_show(&acl->node_auth.port_name, page); 138 return ft_wwn_show(&acl->node_auth.port_name, page);
142} 139}
143 140
144static ssize_t ft_nacl_store_port_name( 141static ssize_t ft_nacl_port_name_store(struct config_item *item,
145 struct se_node_acl *se_nacl, 142 const char *page, size_t count)
146 const char *page,
147 size_t count)
148{ 143{
144 struct se_node_acl *se_nacl = acl_to_nacl(item);
149 struct ft_node_acl *acl = container_of(se_nacl, 145 struct ft_node_acl *acl = container_of(se_nacl,
150 struct ft_node_acl, se_node_acl); 146 struct ft_node_acl, se_node_acl);
151 147
152 return ft_wwn_store(&acl->node_auth.port_name, page, count); 148 return ft_wwn_store(&acl->node_auth.port_name, page, count);
153} 149}
154 150
155TF_NACL_BASE_ATTR(ft, port_name, S_IRUGO | S_IWUSR); 151static ssize_t ft_nacl_node_name_show(struct config_item *item,
156 152 char *page)
157static ssize_t ft_nacl_show_node_name(
158 struct se_node_acl *se_nacl,
159 char *page)
160{ 153{
154 struct se_node_acl *se_nacl = acl_to_nacl(item);
161 struct ft_node_acl *acl = container_of(se_nacl, 155 struct ft_node_acl *acl = container_of(se_nacl,
162 struct ft_node_acl, se_node_acl); 156 struct ft_node_acl, se_node_acl);
163 157
164 return ft_wwn_show(&acl->node_auth.node_name, page); 158 return ft_wwn_show(&acl->node_auth.node_name, page);
165} 159}
166 160
167static ssize_t ft_nacl_store_node_name( 161static ssize_t ft_nacl_node_name_store(struct config_item *item,
168 struct se_node_acl *se_nacl, 162 const char *page, size_t count)
169 const char *page,
170 size_t count)
171{ 163{
164 struct se_node_acl *se_nacl = acl_to_nacl(item);
172 struct ft_node_acl *acl = container_of(se_nacl, 165 struct ft_node_acl *acl = container_of(se_nacl,
173 struct ft_node_acl, se_node_acl); 166 struct ft_node_acl, se_node_acl);
174 167
175 return ft_wwn_store(&acl->node_auth.node_name, page, count); 168 return ft_wwn_store(&acl->node_auth.node_name, page, count);
176} 169}
177 170
178TF_NACL_BASE_ATTR(ft, node_name, S_IRUGO | S_IWUSR); 171CONFIGFS_ATTR(ft_nacl_, node_name);
172CONFIGFS_ATTR(ft_nacl_, port_name);
179 173
180static struct configfs_attribute *ft_nacl_base_attrs[] = { 174static struct configfs_attribute *ft_nacl_base_attrs[] = {
181 &ft_nacl_port_name.attr, 175 &ft_nacl_attr_port_name,
182 &ft_nacl_node_name.attr, 176 &ft_nacl_attr_node_name,
183 NULL, 177 NULL,
184}; 178};
185 179
@@ -386,18 +380,16 @@ static void ft_del_wwn(struct se_wwn *wwn)
386 kfree(ft_wwn); 380 kfree(ft_wwn);
387} 381}
388 382
389static ssize_t ft_wwn_show_attr_version( 383static ssize_t ft_wwn_version_show(struct config_item *item, char *page)
390 struct target_fabric_configfs *tf,
391 char *page)
392{ 384{
393 return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on " 385 return sprintf(page, "TCM FC " FT_VERSION " on %s/%s on "
394 ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine); 386 ""UTS_RELEASE"\n", utsname()->sysname, utsname()->machine);
395} 387}
396 388
397TF_WWN_ATTR_RO(ft, version); 389CONFIGFS_ATTR_RO(ft_wwn_, version);
398 390
399static struct configfs_attribute *ft_wwn_attrs[] = { 391static struct configfs_attribute *ft_wwn_attrs[] = {
400 &ft_wwn_version.attr, 392 &ft_wwn_attr_version,
401 NULL, 393 NULL,
402}; 394};
403 395
diff --git a/drivers/target/tcm_fc/tfc_io.c b/drivers/target/tcm_fc/tfc_io.c
index 4b0fedd6bd4b..847c1aa6fbf4 100644
--- a/drivers/target/tcm_fc/tfc_io.c
+++ b/drivers/target/tcm_fc/tfc_io.c
@@ -44,7 +44,6 @@
44 44
45#include <target/target_core_base.h> 45#include <target/target_core_base.h>
46#include <target/target_core_fabric.h> 46#include <target/target_core_fabric.h>
47#include <target/configfs_macros.h>
48 47
49#include "tcm_fc.h" 48#include "tcm_fc.h"
50 49
diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index 31a9e3fb98c5..7b934eac995d 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -36,7 +36,6 @@
36 36
37#include <target/target_core_base.h> 37#include <target/target_core_base.h>
38#include <target/target_core_fabric.h> 38#include <target/target_core_fabric.h>
39#include <target/configfs_macros.h>
40 39
41#include "tcm_fc.h" 40#include "tcm_fc.h"
42 41
diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 294eb74fb078..163d305e1200 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -64,6 +64,11 @@ struct gadget_info {
64 char qw_sign[OS_STRING_QW_SIGN_LEN]; 64 char qw_sign[OS_STRING_QW_SIGN_LEN];
65}; 65};
66 66
67static inline struct gadget_info *to_gadget_info(struct config_item *item)
68{
69 return container_of(to_config_group(item), struct gadget_info, group);
70}
71
67struct config_usb_cfg { 72struct config_usb_cfg {
68 struct config_group group; 73 struct config_group group;
69 struct config_group strings_group; 74 struct config_group strings_group;
@@ -74,6 +79,12 @@ struct config_usb_cfg {
74 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1]; 79 struct usb_gadget_strings *gstrings[MAX_USB_STRING_LANGS + 1];
75}; 80};
76 81
82static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item)
83{
84 return container_of(to_config_group(item), struct config_usb_cfg,
85 group);
86}
87
77struct gadget_strings { 88struct gadget_strings {
78 struct usb_gadget_strings stringtab_dev; 89 struct usb_gadget_strings stringtab_dev;
79 struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX]; 90 struct usb_string strings[USB_GADGET_FIRST_AVAIL_IDX];
@@ -117,32 +128,25 @@ static int usb_string_copy(const char *s, char **s_copy)
117 return 0; 128 return 0;
118} 129}
119 130
120CONFIGFS_ATTR_STRUCT(gadget_info);
121CONFIGFS_ATTR_STRUCT(config_usb_cfg);
122
123#define GI_DEVICE_DESC_ITEM_ATTR(name) \
124 static struct gadget_info_attribute gadget_cdev_desc_##name = \
125 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
126 gadget_dev_desc_##name##_show, \
127 gadget_dev_desc_##name##_store)
128
129#define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \ 131#define GI_DEVICE_DESC_SIMPLE_R_u8(__name) \
130 static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ 132static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \
131 char *page) \ 133 char *page) \
132{ \ 134{ \
133 return sprintf(page, "0x%02x\n", gi->cdev.desc.__name); \ 135 return sprintf(page, "0x%02x\n", \
136 to_gadget_info(item)->cdev.desc.__name); \
134} 137}
135 138
136#define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \ 139#define GI_DEVICE_DESC_SIMPLE_R_u16(__name) \
137 static ssize_t gadget_dev_desc_##__name##_show(struct gadget_info *gi, \ 140static ssize_t gadget_dev_desc_##__name##_show(struct config_item *item, \
138 char *page) \ 141 char *page) \
139{ \ 142{ \
140 return sprintf(page, "0x%04x\n", le16_to_cpup(&gi->cdev.desc.__name)); \ 143 return sprintf(page, "0x%04x\n", \
144 le16_to_cpup(&to_gadget_info(item)->cdev.desc.__name)); \
141} 145}
142 146
143 147
144#define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \ 148#define GI_DEVICE_DESC_SIMPLE_W_u8(_name) \
145 static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ 149static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \
146 const char *page, size_t len) \ 150 const char *page, size_t len) \
147{ \ 151{ \
148 u8 val; \ 152 u8 val; \
@@ -150,12 +154,12 @@ CONFIGFS_ATTR_STRUCT(config_usb_cfg);
150 ret = kstrtou8(page, 0, &val); \ 154 ret = kstrtou8(page, 0, &val); \
151 if (ret) \ 155 if (ret) \
152 return ret; \ 156 return ret; \
153 gi->cdev.desc._name = val; \ 157 to_gadget_info(item)->cdev.desc._name = val; \
154 return len; \ 158 return len; \
155} 159}
156 160
157#define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \ 161#define GI_DEVICE_DESC_SIMPLE_W_u16(_name) \
158 static ssize_t gadget_dev_desc_##_name##_store(struct gadget_info *gi, \ 162static ssize_t gadget_dev_desc_##_name##_store(struct config_item *item, \
159 const char *page, size_t len) \ 163 const char *page, size_t len) \
160{ \ 164{ \
161 u16 val; \ 165 u16 val; \
@@ -163,7 +167,7 @@ CONFIGFS_ATTR_STRUCT(config_usb_cfg);
163 ret = kstrtou16(page, 0, &val); \ 167 ret = kstrtou16(page, 0, &val); \
164 if (ret) \ 168 if (ret) \
165 return ret; \ 169 return ret; \
166 gi->cdev.desc._name = cpu_to_le16p(&val); \ 170 to_gadget_info(item)->cdev.desc._name = cpu_to_le16p(&val); \
167 return len; \ 171 return len; \
168} 172}
169 173
@@ -193,7 +197,7 @@ static ssize_t is_valid_bcd(u16 bcd_val)
193 return 0; 197 return 0;
194} 198}
195 199
196static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi, 200static ssize_t gadget_dev_desc_bcdDevice_store(struct config_item *item,
197 const char *page, size_t len) 201 const char *page, size_t len)
198{ 202{
199 u16 bcdDevice; 203 u16 bcdDevice;
@@ -206,11 +210,11 @@ static ssize_t gadget_dev_desc_bcdDevice_store(struct gadget_info *gi,
206 if (ret) 210 if (ret)
207 return ret; 211 return ret;
208 212
209 gi->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice); 213 to_gadget_info(item)->cdev.desc.bcdDevice = cpu_to_le16(bcdDevice);
210 return len; 214 return len;
211} 215}
212 216
213static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi, 217static ssize_t gadget_dev_desc_bcdUSB_store(struct config_item *item,
214 const char *page, size_t len) 218 const char *page, size_t len)
215{ 219{
216 u16 bcdUSB; 220 u16 bcdUSB;
@@ -223,13 +227,13 @@ static ssize_t gadget_dev_desc_bcdUSB_store(struct gadget_info *gi,
223 if (ret) 227 if (ret)
224 return ret; 228 return ret;
225 229
226 gi->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB); 230 to_gadget_info(item)->cdev.desc.bcdUSB = cpu_to_le16(bcdUSB);
227 return len; 231 return len;
228} 232}
229 233
230static ssize_t gadget_dev_desc_UDC_show(struct gadget_info *gi, char *page) 234static ssize_t gadget_dev_desc_UDC_show(struct config_item *item, char *page)
231{ 235{
232 return sprintf(page, "%s\n", gi->udc_name ?: ""); 236 return sprintf(page, "%s\n", to_gadget_info(item)->udc_name ?: "");
233} 237}
234 238
235static int unregister_gadget(struct gadget_info *gi) 239static int unregister_gadget(struct gadget_info *gi)
@@ -247,9 +251,10 @@ static int unregister_gadget(struct gadget_info *gi)
247 return 0; 251 return 0;
248} 252}
249 253
250static ssize_t gadget_dev_desc_UDC_store(struct gadget_info *gi, 254static ssize_t gadget_dev_desc_UDC_store(struct config_item *item,
251 const char *page, size_t len) 255 const char *page, size_t len)
252{ 256{
257 struct gadget_info *gi = to_gadget_info(item);
253 char *name; 258 char *name;
254 int ret; 259 int ret;
255 260
@@ -283,34 +288,29 @@ err:
283 return ret; 288 return ret;
284} 289}
285 290
286GI_DEVICE_DESC_ITEM_ATTR(bDeviceClass); 291CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass);
287GI_DEVICE_DESC_ITEM_ATTR(bDeviceSubClass); 292CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass);
288GI_DEVICE_DESC_ITEM_ATTR(bDeviceProtocol); 293CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol);
289GI_DEVICE_DESC_ITEM_ATTR(bMaxPacketSize0); 294CONFIGFS_ATTR(gadget_dev_desc_, bMaxPacketSize0);
290GI_DEVICE_DESC_ITEM_ATTR(idVendor); 295CONFIGFS_ATTR(gadget_dev_desc_, idVendor);
291GI_DEVICE_DESC_ITEM_ATTR(idProduct); 296CONFIGFS_ATTR(gadget_dev_desc_, idProduct);
292GI_DEVICE_DESC_ITEM_ATTR(bcdDevice); 297CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice);
293GI_DEVICE_DESC_ITEM_ATTR(bcdUSB); 298CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB);
294GI_DEVICE_DESC_ITEM_ATTR(UDC); 299CONFIGFS_ATTR(gadget_dev_desc_, UDC);
295 300
296static struct configfs_attribute *gadget_root_attrs[] = { 301static struct configfs_attribute *gadget_root_attrs[] = {
297 &gadget_cdev_desc_bDeviceClass.attr, 302 &gadget_dev_desc_attr_bDeviceClass,
298 &gadget_cdev_desc_bDeviceSubClass.attr, 303 &gadget_dev_desc_attr_bDeviceSubClass,
299 &gadget_cdev_desc_bDeviceProtocol.attr, 304 &gadget_dev_desc_attr_bDeviceProtocol,
300 &gadget_cdev_desc_bMaxPacketSize0.attr, 305 &gadget_dev_desc_attr_bMaxPacketSize0,
301 &gadget_cdev_desc_idVendor.attr, 306 &gadget_dev_desc_attr_idVendor,
302 &gadget_cdev_desc_idProduct.attr, 307 &gadget_dev_desc_attr_idProduct,
303 &gadget_cdev_desc_bcdDevice.attr, 308 &gadget_dev_desc_attr_bcdDevice,
304 &gadget_cdev_desc_bcdUSB.attr, 309 &gadget_dev_desc_attr_bcdUSB,
305 &gadget_cdev_desc_UDC.attr, 310 &gadget_dev_desc_attr_UDC,
306 NULL, 311 NULL,
307}; 312};
308 313
309static inline struct gadget_info *to_gadget_info(struct config_item *item)
310{
311 return container_of(to_config_group(item), struct gadget_info, group);
312}
313
314static inline struct gadget_strings *to_gadget_strings(struct config_item *item) 314static inline struct gadget_strings *to_gadget_strings(struct config_item *item)
315{ 315{
316 return container_of(to_config_group(item), struct gadget_strings, 316 return container_of(to_config_group(item), struct gadget_strings,
@@ -324,12 +324,6 @@ static inline struct gadget_config_name *to_gadget_config_name(
324 group); 324 group);
325} 325}
326 326
327static inline struct config_usb_cfg *to_config_usb_cfg(struct config_item *item)
328{
329 return container_of(to_config_group(item), struct config_usb_cfg,
330 group);
331}
332
333static inline struct usb_function_instance *to_usb_function_instance( 327static inline struct usb_function_instance *to_usb_function_instance(
334 struct config_item *item) 328 struct config_item *item)
335{ 329{
@@ -348,12 +342,8 @@ static void gadget_info_attr_release(struct config_item *item)
348 kfree(gi); 342 kfree(gi);
349} 343}
350 344
351CONFIGFS_ATTR_OPS(gadget_info);
352
353static struct configfs_item_operations gadget_root_item_ops = { 345static struct configfs_item_operations gadget_root_item_ops = {
354 .release = gadget_info_attr_release, 346 .release = gadget_info_attr_release,
355 .show_attribute = gadget_info_attr_show,
356 .store_attribute = gadget_info_attr_store,
357}; 347};
358 348
359static void gadget_config_attr_release(struct config_item *item) 349static void gadget_config_attr_release(struct config_item *item)
@@ -454,24 +444,20 @@ static int config_usb_cfg_unlink(
454 return 0; 444 return 0;
455} 445}
456 446
457CONFIGFS_ATTR_OPS(config_usb_cfg);
458
459static struct configfs_item_operations gadget_config_item_ops = { 447static struct configfs_item_operations gadget_config_item_ops = {
460 .release = gadget_config_attr_release, 448 .release = gadget_config_attr_release,
461 .show_attribute = config_usb_cfg_attr_show,
462 .store_attribute = config_usb_cfg_attr_store,
463 .allow_link = config_usb_cfg_link, 449 .allow_link = config_usb_cfg_link,
464 .drop_link = config_usb_cfg_unlink, 450 .drop_link = config_usb_cfg_unlink,
465}; 451};
466 452
467 453
468static ssize_t gadget_config_desc_MaxPower_show(struct config_usb_cfg *cfg, 454static ssize_t gadget_config_desc_MaxPower_show(struct config_item *item,
469 char *page) 455 char *page)
470{ 456{
471 return sprintf(page, "%u\n", cfg->c.MaxPower); 457 return sprintf(page, "%u\n", to_config_usb_cfg(item)->c.MaxPower);
472} 458}
473 459
474static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg, 460static ssize_t gadget_config_desc_MaxPower_store(struct config_item *item,
475 const char *page, size_t len) 461 const char *page, size_t len)
476{ 462{
477 u16 val; 463 u16 val;
@@ -481,17 +467,18 @@ static ssize_t gadget_config_desc_MaxPower_store(struct config_usb_cfg *cfg,
481 return ret; 467 return ret;
482 if (DIV_ROUND_UP(val, 8) > 0xff) 468 if (DIV_ROUND_UP(val, 8) > 0xff)
483 return -ERANGE; 469 return -ERANGE;
484 cfg->c.MaxPower = val; 470 to_config_usb_cfg(item)->c.MaxPower = val;
485 return len; 471 return len;
486} 472}
487 473
488static ssize_t gadget_config_desc_bmAttributes_show(struct config_usb_cfg *cfg, 474static ssize_t gadget_config_desc_bmAttributes_show(struct config_item *item,
489 char *page) 475 char *page)
490{ 476{
491 return sprintf(page, "0x%02x\n", cfg->c.bmAttributes); 477 return sprintf(page, "0x%02x\n",
478 to_config_usb_cfg(item)->c.bmAttributes);
492} 479}
493 480
494static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg, 481static ssize_t gadget_config_desc_bmAttributes_store(struct config_item *item,
495 const char *page, size_t len) 482 const char *page, size_t len)
496{ 483{
497 u8 val; 484 u8 val;
@@ -504,22 +491,16 @@ static ssize_t gadget_config_desc_bmAttributes_store(struct config_usb_cfg *cfg,
504 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER | 491 if (val & ~(USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER |
505 USB_CONFIG_ATT_WAKEUP)) 492 USB_CONFIG_ATT_WAKEUP))
506 return -EINVAL; 493 return -EINVAL;
507 cfg->c.bmAttributes = val; 494 to_config_usb_cfg(item)->c.bmAttributes = val;
508 return len; 495 return len;
509} 496}
510 497
511#define CFG_CONFIG_DESC_ITEM_ATTR(name) \ 498CONFIGFS_ATTR(gadget_config_desc_, MaxPower);
512 static struct config_usb_cfg_attribute gadget_usb_cfg_##name = \ 499CONFIGFS_ATTR(gadget_config_desc_, bmAttributes);
513 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
514 gadget_config_desc_##name##_show, \
515 gadget_config_desc_##name##_store)
516
517CFG_CONFIG_DESC_ITEM_ATTR(MaxPower);
518CFG_CONFIG_DESC_ITEM_ATTR(bmAttributes);
519 500
520static struct configfs_attribute *gadget_config_attrs[] = { 501static struct configfs_attribute *gadget_config_attrs[] = {
521 &gadget_usb_cfg_MaxPower.attr, 502 &gadget_config_desc_attr_MaxPower,
522 &gadget_usb_cfg_bmAttributes.attr, 503 &gadget_config_desc_attr_bmAttributes,
523 NULL, 504 NULL,
524}; 505};
525 506
@@ -616,11 +597,10 @@ static struct config_item_type functions_type = {
616 .ct_owner = THIS_MODULE, 597 .ct_owner = THIS_MODULE,
617}; 598};
618 599
619CONFIGFS_ATTR_STRUCT(gadget_config_name);
620GS_STRINGS_RW(gadget_config_name, configuration); 600GS_STRINGS_RW(gadget_config_name, configuration);
621 601
622static struct configfs_attribute *gadget_config_name_langid_attrs[] = { 602static struct configfs_attribute *gadget_config_name_langid_attrs[] = {
623 &gadget_config_name_configuration.attr, 603 &gadget_config_name_attr_configuration,
624 NULL, 604 NULL,
625}; 605};
626 606
@@ -719,15 +699,14 @@ static struct config_item_type config_desc_type = {
719 .ct_owner = THIS_MODULE, 699 .ct_owner = THIS_MODULE,
720}; 700};
721 701
722CONFIGFS_ATTR_STRUCT(gadget_strings);
723GS_STRINGS_RW(gadget_strings, manufacturer); 702GS_STRINGS_RW(gadget_strings, manufacturer);
724GS_STRINGS_RW(gadget_strings, product); 703GS_STRINGS_RW(gadget_strings, product);
725GS_STRINGS_RW(gadget_strings, serialnumber); 704GS_STRINGS_RW(gadget_strings, serialnumber);
726 705
727static struct configfs_attribute *gadget_strings_langid_attrs[] = { 706static struct configfs_attribute *gadget_strings_langid_attrs[] = {
728 &gadget_strings_manufacturer.attr, 707 &gadget_strings_attr_manufacturer,
729 &gadget_strings_product.attr, 708 &gadget_strings_attr_product,
730 &gadget_strings_serialnumber.attr, 709 &gadget_strings_attr_serialnumber,
731 NULL, 710 NULL,
732}; 711};
733 712
@@ -751,27 +730,25 @@ static inline struct os_desc *to_os_desc(struct config_item *item)
751 return container_of(to_config_group(item), struct os_desc, group); 730 return container_of(to_config_group(item), struct os_desc, group);
752} 731}
753 732
754CONFIGFS_ATTR_STRUCT(os_desc); 733static inline struct gadget_info *os_desc_item_to_gadget_info(
755CONFIGFS_ATTR_OPS(os_desc); 734 struct config_item *item)
756
757static ssize_t os_desc_use_show(struct os_desc *os_desc, char *page)
758{ 735{
759 struct gadget_info *gi; 736 return to_gadget_info(to_os_desc(item)->group.cg_item.ci_parent);
760 737}
761 gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
762 738
763 return sprintf(page, "%d", gi->use_os_desc); 739static ssize_t os_desc_use_show(struct config_item *item, char *page)
740{
741 return sprintf(page, "%d",
742 os_desc_item_to_gadget_info(item)->use_os_desc);
764} 743}
765 744
766static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page, 745static ssize_t os_desc_use_store(struct config_item *item, const char *page,
767 size_t len) 746 size_t len)
768{ 747{
769 struct gadget_info *gi; 748 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
770 int ret; 749 int ret;
771 bool use; 750 bool use;
772 751
773 gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
774
775 mutex_lock(&gi->lock); 752 mutex_lock(&gi->lock);
776 ret = strtobool(page, &use); 753 ret = strtobool(page, &use);
777 if (!ret) { 754 if (!ret) {
@@ -783,29 +760,19 @@ static ssize_t os_desc_use_store(struct os_desc *os_desc, const char *page,
783 return ret; 760 return ret;
784} 761}
785 762
786static struct os_desc_attribute os_desc_use = 763static ssize_t os_desc_b_vendor_code_show(struct config_item *item, char *page)
787 __CONFIGFS_ATTR(use, S_IRUGO | S_IWUSR,
788 os_desc_use_show,
789 os_desc_use_store);
790
791static ssize_t os_desc_b_vendor_code_show(struct os_desc *os_desc, char *page)
792{ 764{
793 struct gadget_info *gi; 765 return sprintf(page, "%d",
794 766 os_desc_item_to_gadget_info(item)->b_vendor_code);
795 gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
796
797 return sprintf(page, "%d", gi->b_vendor_code);
798} 767}
799 768
800static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc, 769static ssize_t os_desc_b_vendor_code_store(struct config_item *item,
801 const char *page, size_t len) 770 const char *page, size_t len)
802{ 771{
803 struct gadget_info *gi; 772 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
804 int ret; 773 int ret;
805 u8 b_vendor_code; 774 u8 b_vendor_code;
806 775
807 gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
808
809 mutex_lock(&gi->lock); 776 mutex_lock(&gi->lock);
810 ret = kstrtou8(page, 0, &b_vendor_code); 777 ret = kstrtou8(page, 0, &b_vendor_code);
811 if (!ret) { 778 if (!ret) {
@@ -817,29 +784,20 @@ static ssize_t os_desc_b_vendor_code_store(struct os_desc *os_desc,
817 return ret; 784 return ret;
818} 785}
819 786
820static struct os_desc_attribute os_desc_b_vendor_code = 787static ssize_t os_desc_qw_sign_show(struct config_item *item, char *page)
821 __CONFIGFS_ATTR(b_vendor_code, S_IRUGO | S_IWUSR,
822 os_desc_b_vendor_code_show,
823 os_desc_b_vendor_code_store);
824
825static ssize_t os_desc_qw_sign_show(struct os_desc *os_desc, char *page)
826{ 788{
827 struct gadget_info *gi; 789 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
828
829 gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
830 790
831 memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN); 791 memcpy(page, gi->qw_sign, OS_STRING_QW_SIGN_LEN);
832
833 return OS_STRING_QW_SIGN_LEN; 792 return OS_STRING_QW_SIGN_LEN;
834} 793}
835 794
836static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page, 795static ssize_t os_desc_qw_sign_store(struct config_item *item, const char *page,
837 size_t len) 796 size_t len)
838{ 797{
839 struct gadget_info *gi; 798 struct gadget_info *gi = os_desc_item_to_gadget_info(item);
840 int res, l; 799 int res, l;
841 800
842 gi = to_gadget_info(os_desc->group.cg_item.ci_parent);
843 l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1); 801 l = min((int)len, OS_STRING_QW_SIGN_LEN >> 1);
844 if (page[l - 1] == '\n') 802 if (page[l - 1] == '\n')
845 --l; 803 --l;
@@ -855,15 +813,14 @@ static ssize_t os_desc_qw_sign_store(struct os_desc *os_desc, const char *page,
855 return res; 813 return res;
856} 814}
857 815
858static struct os_desc_attribute os_desc_qw_sign = 816CONFIGFS_ATTR(os_desc_, use);
859 __CONFIGFS_ATTR(qw_sign, S_IRUGO | S_IWUSR, 817CONFIGFS_ATTR(os_desc_, b_vendor_code);
860 os_desc_qw_sign_show, 818CONFIGFS_ATTR(os_desc_, qw_sign);
861 os_desc_qw_sign_store);
862 819
863static struct configfs_attribute *os_desc_attrs[] = { 820static struct configfs_attribute *os_desc_attrs[] = {
864 &os_desc_use.attr, 821 &os_desc_attr_use,
865 &os_desc_b_vendor_code.attr, 822 &os_desc_attr_b_vendor_code,
866 &os_desc_qw_sign.attr, 823 &os_desc_attr_qw_sign,
867 NULL, 824 NULL,
868}; 825};
869 826
@@ -926,8 +883,6 @@ static int os_desc_unlink(struct config_item *os_desc_ci,
926 883
927static struct configfs_item_operations os_desc_ops = { 884static struct configfs_item_operations os_desc_ops = {
928 .release = os_desc_attr_release, 885 .release = os_desc_attr_release,
929 .show_attribute = os_desc_attr_show,
930 .store_attribute = os_desc_attr_store,
931 .allow_link = os_desc_link, 886 .allow_link = os_desc_link,
932 .drop_link = os_desc_unlink, 887 .drop_link = os_desc_unlink,
933}; 888};
@@ -938,28 +893,21 @@ static struct config_item_type os_desc_type = {
938 .ct_owner = THIS_MODULE, 893 .ct_owner = THIS_MODULE,
939}; 894};
940 895
941CONFIGFS_ATTR_STRUCT(usb_os_desc);
942CONFIGFS_ATTR_OPS(usb_os_desc);
943
944
945static inline struct usb_os_desc_ext_prop 896static inline struct usb_os_desc_ext_prop
946*to_usb_os_desc_ext_prop(struct config_item *item) 897*to_usb_os_desc_ext_prop(struct config_item *item)
947{ 898{
948 return container_of(item, struct usb_os_desc_ext_prop, item); 899 return container_of(item, struct usb_os_desc_ext_prop, item);
949} 900}
950 901
951CONFIGFS_ATTR_STRUCT(usb_os_desc_ext_prop); 902static ssize_t ext_prop_type_show(struct config_item *item, char *page)
952CONFIGFS_ATTR_OPS(usb_os_desc_ext_prop);
953
954static ssize_t ext_prop_type_show(struct usb_os_desc_ext_prop *ext_prop,
955 char *page)
956{ 903{
957 return sprintf(page, "%d", ext_prop->type); 904 return sprintf(page, "%d", to_usb_os_desc_ext_prop(item)->type);
958} 905}
959 906
960static ssize_t ext_prop_type_store(struct usb_os_desc_ext_prop *ext_prop, 907static ssize_t ext_prop_type_store(struct config_item *item,
961 const char *page, size_t len) 908 const char *page, size_t len)
962{ 909{
910 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
963 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); 911 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
964 u8 type; 912 u8 type;
965 int ret; 913 int ret;
@@ -997,9 +945,9 @@ end:
997 return ret; 945 return ret;
998} 946}
999 947
1000static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop, 948static ssize_t ext_prop_data_show(struct config_item *item, char *page)
1001 char *page)
1002{ 949{
950 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1003 int len = ext_prop->data_len; 951 int len = ext_prop->data_len;
1004 952
1005 if (ext_prop->type == USB_EXT_PROP_UNICODE || 953 if (ext_prop->type == USB_EXT_PROP_UNICODE ||
@@ -1011,9 +959,10 @@ static ssize_t ext_prop_data_show(struct usb_os_desc_ext_prop *ext_prop,
1011 return len; 959 return len;
1012} 960}
1013 961
1014static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop, 962static ssize_t ext_prop_data_store(struct config_item *item,
1015 const char *page, size_t len) 963 const char *page, size_t len)
1016{ 964{
965 struct usb_os_desc_ext_prop *ext_prop = to_usb_os_desc_ext_prop(item);
1017 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent); 966 struct usb_os_desc *desc = to_usb_os_desc(ext_prop->item.ci_parent);
1018 char *new_data; 967 char *new_data;
1019 size_t ret_len = len; 968 size_t ret_len = len;
@@ -1044,17 +993,12 @@ static ssize_t ext_prop_data_store(struct usb_os_desc_ext_prop *ext_prop,
1044 return ret_len; 993 return ret_len;
1045} 994}
1046 995
1047static struct usb_os_desc_ext_prop_attribute ext_prop_type = 996CONFIGFS_ATTR(ext_prop_, type);
1048 __CONFIGFS_ATTR(type, S_IRUGO | S_IWUSR, 997CONFIGFS_ATTR(ext_prop_, data);
1049 ext_prop_type_show, ext_prop_type_store);
1050
1051static struct usb_os_desc_ext_prop_attribute ext_prop_data =
1052 __CONFIGFS_ATTR(data, S_IRUGO | S_IWUSR,
1053 ext_prop_data_show, ext_prop_data_store);
1054 998
1055static struct configfs_attribute *ext_prop_attrs[] = { 999static struct configfs_attribute *ext_prop_attrs[] = {
1056 &ext_prop_type.attr, 1000 &ext_prop_attr_type,
1057 &ext_prop_data.attr, 1001 &ext_prop_attr_data,
1058 NULL, 1002 NULL,
1059}; 1003};
1060 1004
@@ -1067,8 +1011,6 @@ static void usb_os_desc_ext_prop_release(struct config_item *item)
1067 1011
1068static struct configfs_item_operations ext_prop_ops = { 1012static struct configfs_item_operations ext_prop_ops = {
1069 .release = usb_os_desc_ext_prop_release, 1013 .release = usb_os_desc_ext_prop_release,
1070 .show_attribute = usb_os_desc_ext_prop_attr_show,
1071 .store_attribute = usb_os_desc_ext_prop_attr_store,
1072}; 1014};
1073 1015
1074static struct config_item *ext_prop_make( 1016static struct config_item *ext_prop_make(
@@ -1137,21 +1079,17 @@ static struct configfs_group_operations interf_grp_ops = {
1137 .drop_item = &ext_prop_drop, 1079 .drop_item = &ext_prop_drop,
1138}; 1080};
1139 1081
1140static struct configfs_item_operations interf_item_ops = { 1082static ssize_t interf_grp_compatible_id_show(struct config_item *item,
1141 .show_attribute = usb_os_desc_attr_show,
1142 .store_attribute = usb_os_desc_attr_store,
1143};
1144
1145static ssize_t interf_grp_compatible_id_show(struct usb_os_desc *desc,
1146 char *page) 1083 char *page)
1147{ 1084{
1148 memcpy(page, desc->ext_compat_id, 8); 1085 memcpy(page, to_usb_os_desc(item)->ext_compat_id, 8);
1149 return 8; 1086 return 8;
1150} 1087}
1151 1088
1152static ssize_t interf_grp_compatible_id_store(struct usb_os_desc *desc, 1089static ssize_t interf_grp_compatible_id_store(struct config_item *item,
1153 const char *page, size_t len) 1090 const char *page, size_t len)
1154{ 1091{
1092 struct usb_os_desc *desc = to_usb_os_desc(item);
1155 int l; 1093 int l;
1156 1094
1157 l = min_t(int, 8, len); 1095 l = min_t(int, 8, len);
@@ -1167,21 +1105,17 @@ static ssize_t interf_grp_compatible_id_store(struct usb_os_desc *desc,
1167 return len; 1105 return len;
1168} 1106}
1169 1107
1170static struct usb_os_desc_attribute interf_grp_attr_compatible_id = 1108static ssize_t interf_grp_sub_compatible_id_show(struct config_item *item,
1171 __CONFIGFS_ATTR(compatible_id, S_IRUGO | S_IWUSR,
1172 interf_grp_compatible_id_show,
1173 interf_grp_compatible_id_store);
1174
1175static ssize_t interf_grp_sub_compatible_id_show(struct usb_os_desc *desc,
1176 char *page) 1109 char *page)
1177{ 1110{
1178 memcpy(page, desc->ext_compat_id + 8, 8); 1111 memcpy(page, to_usb_os_desc(item)->ext_compat_id + 8, 8);
1179 return 8; 1112 return 8;
1180} 1113}
1181 1114
1182static ssize_t interf_grp_sub_compatible_id_store(struct usb_os_desc *desc, 1115static ssize_t interf_grp_sub_compatible_id_store(struct config_item *item,
1183 const char *page, size_t len) 1116 const char *page, size_t len)
1184{ 1117{
1118 struct usb_os_desc *desc = to_usb_os_desc(item);
1185 int l; 1119 int l;
1186 1120
1187 l = min_t(int, 8, len); 1121 l = min_t(int, 8, len);
@@ -1197,14 +1131,12 @@ static ssize_t interf_grp_sub_compatible_id_store(struct usb_os_desc *desc,
1197 return len; 1131 return len;
1198} 1132}
1199 1133
1200static struct usb_os_desc_attribute interf_grp_attr_sub_compatible_id = 1134CONFIGFS_ATTR(interf_grp_, compatible_id);
1201 __CONFIGFS_ATTR(sub_compatible_id, S_IRUGO | S_IWUSR, 1135CONFIGFS_ATTR(interf_grp_, sub_compatible_id);
1202 interf_grp_sub_compatible_id_show,
1203 interf_grp_sub_compatible_id_store);
1204 1136
1205static struct configfs_attribute *interf_grp_attrs[] = { 1137static struct configfs_attribute *interf_grp_attrs[] = {
1206 &interf_grp_attr_compatible_id.attr, 1138 &interf_grp_attr_compatible_id,
1207 &interf_grp_attr_sub_compatible_id.attr, 1139 &interf_grp_attr_sub_compatible_id,
1208 NULL 1140 NULL
1209}; 1141};
1210 1142
@@ -1242,7 +1174,6 @@ int usb_os_desc_prepare_interf_dir(struct config_group *parent,
1242 f_default_groups[0] = os_desc_group; 1174 f_default_groups[0] = os_desc_group;
1243 1175
1244 os_desc_group->default_groups = interface_groups; 1176 os_desc_group->default_groups = interface_groups;
1245 interface_type->ct_item_ops = &interf_item_ops;
1246 interface_type->ct_group_ops = &interf_grp_ops; 1177 interface_type->ct_group_ops = &interf_grp_ops;
1247 interface_type->ct_attrs = interf_grp_attrs; 1178 interface_type->ct_attrs = interf_grp_attrs;
1248 interface_type->ct_owner = owner; 1179 interface_type->ct_owner = owner;
diff --git a/drivers/usb/gadget/function/f_acm.c b/drivers/usb/gadget/function/f_acm.c
index 22e723d12d36..2fa1e80a3ce7 100644
--- a/drivers/usb/gadget/function/f_acm.c
+++ b/drivers/usb/gadget/function/f_acm.c
@@ -761,21 +761,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
761 func_inst.group); 761 func_inst.group);
762} 762}
763 763
764CONFIGFS_ATTR_STRUCT(f_serial_opts);
765static ssize_t f_acm_attr_show(struct config_item *item,
766 struct configfs_attribute *attr,
767 char *page)
768{
769 struct f_serial_opts *opts = to_f_serial_opts(item);
770 struct f_serial_opts_attribute *f_serial_opts_attr =
771 container_of(attr, struct f_serial_opts_attribute, attr);
772 ssize_t ret = 0;
773
774 if (f_serial_opts_attr->show)
775 ret = f_serial_opts_attr->show(opts, page);
776 return ret;
777}
778
779static void acm_attr_release(struct config_item *item) 764static void acm_attr_release(struct config_item *item)
780{ 765{
781 struct f_serial_opts *opts = to_f_serial_opts(item); 766 struct f_serial_opts *opts = to_f_serial_opts(item);
@@ -785,20 +770,17 @@ static void acm_attr_release(struct config_item *item)
785 770
786static struct configfs_item_operations acm_item_ops = { 771static struct configfs_item_operations acm_item_ops = {
787 .release = acm_attr_release, 772 .release = acm_attr_release,
788 .show_attribute = f_acm_attr_show,
789}; 773};
790 774
791static ssize_t f_acm_port_num_show(struct f_serial_opts *opts, char *page) 775static ssize_t f_acm_port_num_show(struct config_item *item, char *page)
792{ 776{
793 return sprintf(page, "%u\n", opts->port_num); 777 return sprintf(page, "%u\n", to_f_serial_opts(item)->port_num);
794} 778}
795 779
796static struct f_serial_opts_attribute f_acm_port_num = 780CONFIGFS_ATTR_RO(f_acm_port_, num);
797 __CONFIGFS_ATTR_RO(port_num, f_acm_port_num_show);
798
799 781
800static struct configfs_attribute *acm_attrs[] = { 782static struct configfs_attribute *acm_attrs[] = {
801 &f_acm_port_num.attr, 783 &f_acm_port_attr_num,
802 NULL, 784 NULL,
803}; 785};
804 786
diff --git a/drivers/usb/gadget/function/f_ecm.c b/drivers/usb/gadget/function/f_ecm.c
index 4abca70cdaab..7ad60ee41914 100644
--- a/drivers/usb/gadget/function/f_ecm.c
+++ b/drivers/usb/gadget/function/f_ecm.c
@@ -838,10 +838,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ecm);
838USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ecm); 838USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ecm);
839 839
840static struct configfs_attribute *ecm_attrs[] = { 840static struct configfs_attribute *ecm_attrs[] = {
841 &f_ecm_opts_dev_addr.attr, 841 &ecm_opts_attr_dev_addr,
842 &f_ecm_opts_host_addr.attr, 842 &ecm_opts_attr_host_addr,
843 &f_ecm_opts_qmult.attr, 843 &ecm_opts_attr_qmult,
844 &f_ecm_opts_ifname.attr, 844 &ecm_opts_attr_ifname,
845 NULL, 845 NULL,
846}; 846};
847 847
diff --git a/drivers/usb/gadget/function/f_eem.c b/drivers/usb/gadget/function/f_eem.c
index 9a55757c729b..cad35a502d3f 100644
--- a/drivers/usb/gadget/function/f_eem.c
+++ b/drivers/usb/gadget/function/f_eem.c
@@ -545,10 +545,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(eem);
545USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(eem); 545USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(eem);
546 546
547static struct configfs_attribute *eem_attrs[] = { 547static struct configfs_attribute *eem_attrs[] = {
548 &f_eem_opts_dev_addr.attr, 548 &eem_opts_attr_dev_addr,
549 &f_eem_opts_host_addr.attr, 549 &eem_opts_attr_host_addr,
550 &f_eem_opts_qmult.attr, 550 &eem_opts_attr_qmult,
551 &f_eem_opts_ifname.attr, 551 &eem_opts_attr_ifname,
552 NULL, 552 NULL,
553}; 553};
554 554
diff --git a/drivers/usb/gadget/function/f_hid.c b/drivers/usb/gadget/function/f_hid.c
index 21fcf18f53a0..99285b416308 100644
--- a/drivers/usb/gadget/function/f_hid.c
+++ b/drivers/usb/gadget/function/f_hid.c
@@ -705,9 +705,6 @@ static inline struct f_hid_opts *to_f_hid_opts(struct config_item *item)
705 func_inst.group); 705 func_inst.group);
706} 706}
707 707
708CONFIGFS_ATTR_STRUCT(f_hid_opts);
709CONFIGFS_ATTR_OPS(f_hid_opts);
710
711static void hid_attr_release(struct config_item *item) 708static void hid_attr_release(struct config_item *item)
712{ 709{
713 struct f_hid_opts *opts = to_f_hid_opts(item); 710 struct f_hid_opts *opts = to_f_hid_opts(item);
@@ -717,13 +714,12 @@ static void hid_attr_release(struct config_item *item)
717 714
718static struct configfs_item_operations hidg_item_ops = { 715static struct configfs_item_operations hidg_item_ops = {
719 .release = hid_attr_release, 716 .release = hid_attr_release,
720 .show_attribute = f_hid_opts_attr_show,
721 .store_attribute = f_hid_opts_attr_store,
722}; 717};
723 718
724#define F_HID_OPT(name, prec, limit) \ 719#define F_HID_OPT(name, prec, limit) \
725static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\ 720static ssize_t f_hid_opts_##name##_show(struct config_item *item, char *page)\
726{ \ 721{ \
722 struct f_hid_opts *opts = to_f_hid_opts(item); \
727 int result; \ 723 int result; \
728 \ 724 \
729 mutex_lock(&opts->lock); \ 725 mutex_lock(&opts->lock); \
@@ -733,9 +729,10 @@ static ssize_t f_hid_opts_##name##_show(struct f_hid_opts *opts, char *page)\
733 return result; \ 729 return result; \
734} \ 730} \
735 \ 731 \
736static ssize_t f_hid_opts_##name##_store(struct f_hid_opts *opts, \ 732static ssize_t f_hid_opts_##name##_store(struct config_item *item, \
737 const char *page, size_t len) \ 733 const char *page, size_t len) \
738{ \ 734{ \
735 struct f_hid_opts *opts = to_f_hid_opts(item); \
739 int ret; \ 736 int ret; \
740 u##prec num; \ 737 u##prec num; \
741 \ 738 \
@@ -761,16 +758,15 @@ end: \
761 return ret; \ 758 return ret; \
762} \ 759} \
763 \ 760 \
764static struct f_hid_opts_attribute f_hid_opts_##name = \ 761CONFIGFS_ATTR(f_hid_opts_, name)
765 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_hid_opts_##name##_show,\
766 f_hid_opts_##name##_store)
767 762
768F_HID_OPT(subclass, 8, 255); 763F_HID_OPT(subclass, 8, 255);
769F_HID_OPT(protocol, 8, 255); 764F_HID_OPT(protocol, 8, 255);
770F_HID_OPT(report_length, 16, 65535); 765F_HID_OPT(report_length, 16, 65535);
771 766
772static ssize_t f_hid_opts_report_desc_show(struct f_hid_opts *opts, char *page) 767static ssize_t f_hid_opts_report_desc_show(struct config_item *item, char *page)
773{ 768{
769 struct f_hid_opts *opts = to_f_hid_opts(item);
774 int result; 770 int result;
775 771
776 mutex_lock(&opts->lock); 772 mutex_lock(&opts->lock);
@@ -781,9 +777,10 @@ static ssize_t f_hid_opts_report_desc_show(struct f_hid_opts *opts, char *page)
781 return result; 777 return result;
782} 778}
783 779
784static ssize_t f_hid_opts_report_desc_store(struct f_hid_opts *opts, 780static ssize_t f_hid_opts_report_desc_store(struct config_item *item,
785 const char *page, size_t len) 781 const char *page, size_t len)
786{ 782{
783 struct f_hid_opts *opts = to_f_hid_opts(item);
787 int ret = -EBUSY; 784 int ret = -EBUSY;
788 char *d; 785 char *d;
789 786
@@ -810,16 +807,13 @@ end:
810 return ret; 807 return ret;
811} 808}
812 809
813static struct f_hid_opts_attribute f_hid_opts_report_desc = 810CONFIGFS_ATTR(f_hid_opts_, report_desc);
814 __CONFIGFS_ATTR(report_desc, S_IRUGO | S_IWUSR,
815 f_hid_opts_report_desc_show,
816 f_hid_opts_report_desc_store);
817 811
818static struct configfs_attribute *hid_attrs[] = { 812static struct configfs_attribute *hid_attrs[] = {
819 &f_hid_opts_subclass.attr, 813 &f_hid_opts_attr_subclass,
820 &f_hid_opts_protocol.attr, 814 &f_hid_opts_attr_protocol,
821 &f_hid_opts_report_length.attr, 815 &f_hid_opts_attr_report_length,
822 &f_hid_opts_report_desc.attr, 816 &f_hid_opts_attr_report_desc,
823 NULL, 817 NULL,
824}; 818};
825 819
diff --git a/drivers/usb/gadget/function/f_loopback.c b/drivers/usb/gadget/function/f_loopback.c
index 6b2102bc0699..23933bdf2d9d 100644
--- a/drivers/usb/gadget/function/f_loopback.c
+++ b/drivers/usb/gadget/function/f_loopback.c
@@ -465,9 +465,6 @@ static inline struct f_lb_opts *to_f_lb_opts(struct config_item *item)
465 func_inst.group); 465 func_inst.group);
466} 466}
467 467
468CONFIGFS_ATTR_STRUCT(f_lb_opts);
469CONFIGFS_ATTR_OPS(f_lb_opts);
470
471static void lb_attr_release(struct config_item *item) 468static void lb_attr_release(struct config_item *item)
472{ 469{
473 struct f_lb_opts *lb_opts = to_f_lb_opts(item); 470 struct f_lb_opts *lb_opts = to_f_lb_opts(item);
@@ -477,12 +474,11 @@ static void lb_attr_release(struct config_item *item)
477 474
478static struct configfs_item_operations lb_item_ops = { 475static struct configfs_item_operations lb_item_ops = {
479 .release = lb_attr_release, 476 .release = lb_attr_release,
480 .show_attribute = f_lb_opts_attr_show,
481 .store_attribute = f_lb_opts_attr_store,
482}; 477};
483 478
484static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page) 479static ssize_t f_lb_opts_qlen_show(struct config_item *item, char *page)
485{ 480{
481 struct f_lb_opts *opts = to_f_lb_opts(item);
486 int result; 482 int result;
487 483
488 mutex_lock(&opts->lock); 484 mutex_lock(&opts->lock);
@@ -492,9 +488,10 @@ static ssize_t f_lb_opts_qlen_show(struct f_lb_opts *opts, char *page)
492 return result; 488 return result;
493} 489}
494 490
495static ssize_t f_lb_opts_qlen_store(struct f_lb_opts *opts, 491static ssize_t f_lb_opts_qlen_store(struct config_item *item,
496 const char *page, size_t len) 492 const char *page, size_t len)
497{ 493{
494 struct f_lb_opts *opts = to_f_lb_opts(item);
498 int ret; 495 int ret;
499 u32 num; 496 u32 num;
500 497
@@ -515,13 +512,11 @@ end:
515 return ret; 512 return ret;
516} 513}
517 514
518static struct f_lb_opts_attribute f_lb_opts_qlen = 515CONFIGFS_ATTR(f_lb_opts_, qlen);
519 __CONFIGFS_ATTR(qlen, S_IRUGO | S_IWUSR,
520 f_lb_opts_qlen_show,
521 f_lb_opts_qlen_store);
522 516
523static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page) 517static ssize_t f_lb_opts_bulk_buflen_show(struct config_item *item, char *page)
524{ 518{
519 struct f_lb_opts *opts = to_f_lb_opts(item);
525 int result; 520 int result;
526 521
527 mutex_lock(&opts->lock); 522 mutex_lock(&opts->lock);
@@ -531,9 +526,10 @@ static ssize_t f_lb_opts_bulk_buflen_show(struct f_lb_opts *opts, char *page)
531 return result; 526 return result;
532} 527}
533 528
534static ssize_t f_lb_opts_bulk_buflen_store(struct f_lb_opts *opts, 529static ssize_t f_lb_opts_bulk_buflen_store(struct config_item *item,
535 const char *page, size_t len) 530 const char *page, size_t len)
536{ 531{
532 struct f_lb_opts *opts = to_f_lb_opts(item);
537 int ret; 533 int ret;
538 u32 num; 534 u32 num;
539 535
@@ -554,14 +550,11 @@ end:
554 return ret; 550 return ret;
555} 551}
556 552
557static struct f_lb_opts_attribute f_lb_opts_bulk_buflen = 553CONFIGFS_ATTR(f_lb_opts_, bulk_buflen);
558 __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR,
559 f_lb_opts_bulk_buflen_show,
560 f_lb_opts_bulk_buflen_store);
561 554
562static struct configfs_attribute *lb_attrs[] = { 555static struct configfs_attribute *lb_attrs[] = {
563 &f_lb_opts_qlen.attr, 556 &f_lb_opts_attr_qlen,
564 &f_lb_opts_bulk_buflen.attr, 557 &f_lb_opts_attr_bulk_buflen,
565 NULL, 558 NULL,
566}; 559};
567 560
diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c
index 5ec533826621..223ccf89d226 100644
--- a/drivers/usb/gadget/function/f_mass_storage.c
+++ b/drivers/usb/gadget/function/f_mass_storage.c
@@ -3140,9 +3140,6 @@ static inline struct fsg_opts *to_fsg_opts(struct config_item *item)
3140 func_inst.group); 3140 func_inst.group);
3141} 3141}
3142 3142
3143CONFIGFS_ATTR_STRUCT(fsg_lun_opts);
3144CONFIGFS_ATTR_OPS(fsg_lun_opts);
3145
3146static void fsg_lun_attr_release(struct config_item *item) 3143static void fsg_lun_attr_release(struct config_item *item)
3147{ 3144{
3148 struct fsg_lun_opts *lun_opts; 3145 struct fsg_lun_opts *lun_opts;
@@ -3153,110 +3150,93 @@ static void fsg_lun_attr_release(struct config_item *item)
3153 3150
3154static struct configfs_item_operations fsg_lun_item_ops = { 3151static struct configfs_item_operations fsg_lun_item_ops = {
3155 .release = fsg_lun_attr_release, 3152 .release = fsg_lun_attr_release,
3156 .show_attribute = fsg_lun_opts_attr_show,
3157 .store_attribute = fsg_lun_opts_attr_store,
3158}; 3153};
3159 3154
3160static ssize_t fsg_lun_opts_file_show(struct fsg_lun_opts *opts, char *page) 3155static ssize_t fsg_lun_opts_file_show(struct config_item *item, char *page)
3161{ 3156{
3162 struct fsg_opts *fsg_opts; 3157 struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
3163 3158 struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3164 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3165 3159
3166 return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page); 3160 return fsg_show_file(opts->lun, &fsg_opts->common->filesem, page);
3167} 3161}
3168 3162
3169static ssize_t fsg_lun_opts_file_store(struct fsg_lun_opts *opts, 3163static ssize_t fsg_lun_opts_file_store(struct config_item *item,
3170 const char *page, size_t len) 3164 const char *page, size_t len)
3171{ 3165{
3172 struct fsg_opts *fsg_opts; 3166 struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
3173 3167 struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3174 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3175 3168
3176 return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len); 3169 return fsg_store_file(opts->lun, &fsg_opts->common->filesem, page, len);
3177} 3170}
3178 3171
3179static struct fsg_lun_opts_attribute fsg_lun_opts_file = 3172CONFIGFS_ATTR(fsg_lun_opts_, file);
3180 __CONFIGFS_ATTR(file, S_IRUGO | S_IWUSR, fsg_lun_opts_file_show,
3181 fsg_lun_opts_file_store);
3182 3173
3183static ssize_t fsg_lun_opts_ro_show(struct fsg_lun_opts *opts, char *page) 3174static ssize_t fsg_lun_opts_ro_show(struct config_item *item, char *page)
3184{ 3175{
3185 return fsg_show_ro(opts->lun, page); 3176 return fsg_show_ro(to_fsg_lun_opts(item)->lun, page);
3186} 3177}
3187 3178
3188static ssize_t fsg_lun_opts_ro_store(struct fsg_lun_opts *opts, 3179static ssize_t fsg_lun_opts_ro_store(struct config_item *item,
3189 const char *page, size_t len) 3180 const char *page, size_t len)
3190{ 3181{
3191 struct fsg_opts *fsg_opts; 3182 struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
3192 3183 struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3193 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3194 3184
3195 return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len); 3185 return fsg_store_ro(opts->lun, &fsg_opts->common->filesem, page, len);
3196} 3186}
3197 3187
3198static struct fsg_lun_opts_attribute fsg_lun_opts_ro = 3188CONFIGFS_ATTR(fsg_lun_opts_, ro);
3199 __CONFIGFS_ATTR(ro, S_IRUGO | S_IWUSR, fsg_lun_opts_ro_show,
3200 fsg_lun_opts_ro_store);
3201 3189
3202static ssize_t fsg_lun_opts_removable_show(struct fsg_lun_opts *opts, 3190static ssize_t fsg_lun_opts_removable_show(struct config_item *item,
3203 char *page) 3191 char *page)
3204{ 3192{
3205 return fsg_show_removable(opts->lun, page); 3193 return fsg_show_removable(to_fsg_lun_opts(item)->lun, page);
3206} 3194}
3207 3195
3208static ssize_t fsg_lun_opts_removable_store(struct fsg_lun_opts *opts, 3196static ssize_t fsg_lun_opts_removable_store(struct config_item *item,
3209 const char *page, size_t len) 3197 const char *page, size_t len)
3210{ 3198{
3211 return fsg_store_removable(opts->lun, page, len); 3199 return fsg_store_removable(to_fsg_lun_opts(item)->lun, page, len);
3212} 3200}
3213 3201
3214static struct fsg_lun_opts_attribute fsg_lun_opts_removable = 3202CONFIGFS_ATTR(fsg_lun_opts_, removable);
3215 __CONFIGFS_ATTR(removable, S_IRUGO | S_IWUSR,
3216 fsg_lun_opts_removable_show,
3217 fsg_lun_opts_removable_store);
3218 3203
3219static ssize_t fsg_lun_opts_cdrom_show(struct fsg_lun_opts *opts, char *page) 3204static ssize_t fsg_lun_opts_cdrom_show(struct config_item *item, char *page)
3220{ 3205{
3221 return fsg_show_cdrom(opts->lun, page); 3206 return fsg_show_cdrom(to_fsg_lun_opts(item)->lun, page);
3222} 3207}
3223 3208
3224static ssize_t fsg_lun_opts_cdrom_store(struct fsg_lun_opts *opts, 3209static ssize_t fsg_lun_opts_cdrom_store(struct config_item *item,
3225 const char *page, size_t len) 3210 const char *page, size_t len)
3226{ 3211{
3227 struct fsg_opts *fsg_opts; 3212 struct fsg_lun_opts *opts = to_fsg_lun_opts(item);
3228 3213 struct fsg_opts *fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3229 fsg_opts = to_fsg_opts(opts->group.cg_item.ci_parent);
3230 3214
3231 return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page, 3215 return fsg_store_cdrom(opts->lun, &fsg_opts->common->filesem, page,
3232 len); 3216 len);
3233} 3217}
3234 3218
3235static struct fsg_lun_opts_attribute fsg_lun_opts_cdrom = 3219CONFIGFS_ATTR(fsg_lun_opts_, cdrom);
3236 __CONFIGFS_ATTR(cdrom, S_IRUGO | S_IWUSR, fsg_lun_opts_cdrom_show,
3237 fsg_lun_opts_cdrom_store);
3238 3220
3239static ssize_t fsg_lun_opts_nofua_show(struct fsg_lun_opts *opts, char *page) 3221static ssize_t fsg_lun_opts_nofua_show(struct config_item *item, char *page)
3240{ 3222{
3241 return fsg_show_nofua(opts->lun, page); 3223 return fsg_show_nofua(to_fsg_lun_opts(item)->lun, page);
3242} 3224}
3243 3225
3244static ssize_t fsg_lun_opts_nofua_store(struct fsg_lun_opts *opts, 3226static ssize_t fsg_lun_opts_nofua_store(struct config_item *item,
3245 const char *page, size_t len) 3227 const char *page, size_t len)
3246{ 3228{
3247 return fsg_store_nofua(opts->lun, page, len); 3229 return fsg_store_nofua(to_fsg_lun_opts(item)->lun, page, len);
3248} 3230}
3249 3231
3250static struct fsg_lun_opts_attribute fsg_lun_opts_nofua = 3232CONFIGFS_ATTR(fsg_lun_opts_, nofua);
3251 __CONFIGFS_ATTR(nofua, S_IRUGO | S_IWUSR, fsg_lun_opts_nofua_show,
3252 fsg_lun_opts_nofua_store);
3253 3233
3254static struct configfs_attribute *fsg_lun_attrs[] = { 3234static struct configfs_attribute *fsg_lun_attrs[] = {
3255 &fsg_lun_opts_file.attr, 3235 &fsg_lun_opts_attr_file,
3256 &fsg_lun_opts_ro.attr, 3236 &fsg_lun_opts_attr_ro,
3257 &fsg_lun_opts_removable.attr, 3237 &fsg_lun_opts_attr_removable,
3258 &fsg_lun_opts_cdrom.attr, 3238 &fsg_lun_opts_attr_cdrom,
3259 &fsg_lun_opts_nofua.attr, 3239 &fsg_lun_opts_attr_nofua,
3260 NULL, 3240 NULL,
3261}; 3241};
3262 3242
@@ -3348,9 +3328,6 @@ static void fsg_lun_drop(struct config_group *group, struct config_item *item)
3348 config_item_put(item); 3328 config_item_put(item);
3349} 3329}
3350 3330
3351CONFIGFS_ATTR_STRUCT(fsg_opts);
3352CONFIGFS_ATTR_OPS(fsg_opts);
3353
3354static void fsg_attr_release(struct config_item *item) 3331static void fsg_attr_release(struct config_item *item)
3355{ 3332{
3356 struct fsg_opts *opts = to_fsg_opts(item); 3333 struct fsg_opts *opts = to_fsg_opts(item);
@@ -3360,12 +3337,11 @@ static void fsg_attr_release(struct config_item *item)
3360 3337
3361static struct configfs_item_operations fsg_item_ops = { 3338static struct configfs_item_operations fsg_item_ops = {
3362 .release = fsg_attr_release, 3339 .release = fsg_attr_release,
3363 .show_attribute = fsg_opts_attr_show,
3364 .store_attribute = fsg_opts_attr_store,
3365}; 3340};
3366 3341
3367static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page) 3342static ssize_t fsg_opts_stall_show(struct config_item *item, char *page)
3368{ 3343{
3344 struct fsg_opts *opts = to_fsg_opts(item);
3369 int result; 3345 int result;
3370 3346
3371 mutex_lock(&opts->lock); 3347 mutex_lock(&opts->lock);
@@ -3375,9 +3351,10 @@ static ssize_t fsg_opts_stall_show(struct fsg_opts *opts, char *page)
3375 return result; 3351 return result;
3376} 3352}
3377 3353
3378static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page, 3354static ssize_t fsg_opts_stall_store(struct config_item *item, const char *page,
3379 size_t len) 3355 size_t len)
3380{ 3356{
3357 struct fsg_opts *opts = to_fsg_opts(item);
3381 int ret; 3358 int ret;
3382 bool stall; 3359 bool stall;
3383 3360
@@ -3399,13 +3376,12 @@ static ssize_t fsg_opts_stall_store(struct fsg_opts *opts, const char *page,
3399 return ret; 3376 return ret;
3400} 3377}
3401 3378
3402static struct fsg_opts_attribute fsg_opts_stall = 3379CONFIGFS_ATTR(fsg_opts_, stall);
3403 __CONFIGFS_ATTR(stall, S_IRUGO | S_IWUSR, fsg_opts_stall_show,
3404 fsg_opts_stall_store);
3405 3380
3406#ifdef CONFIG_USB_GADGET_DEBUG_FILES 3381#ifdef CONFIG_USB_GADGET_DEBUG_FILES
3407static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page) 3382static ssize_t fsg_opts_num_buffers_show(struct config_item *item, char *page)
3408{ 3383{
3384 struct fsg_opts *opts = to_fsg_opts(item);
3409 int result; 3385 int result;
3410 3386
3411 mutex_lock(&opts->lock); 3387 mutex_lock(&opts->lock);
@@ -3415,9 +3391,10 @@ static ssize_t fsg_opts_num_buffers_show(struct fsg_opts *opts, char *page)
3415 return result; 3391 return result;
3416} 3392}
3417 3393
3418static ssize_t fsg_opts_num_buffers_store(struct fsg_opts *opts, 3394static ssize_t fsg_opts_num_buffers_store(struct config_item *item,
3419 const char *page, size_t len) 3395 const char *page, size_t len)
3420{ 3396{
3397 struct fsg_opts *opts = to_fsg_opts(item);
3421 int ret; 3398 int ret;
3422 u8 num; 3399 u8 num;
3423 3400
@@ -3442,17 +3419,13 @@ end:
3442 return ret; 3419 return ret;
3443} 3420}
3444 3421
3445static struct fsg_opts_attribute fsg_opts_num_buffers = 3422CONFIGFS_ATTR(fsg_opts_, num_buffers);
3446 __CONFIGFS_ATTR(num_buffers, S_IRUGO | S_IWUSR,
3447 fsg_opts_num_buffers_show,
3448 fsg_opts_num_buffers_store);
3449
3450#endif 3423#endif
3451 3424
3452static struct configfs_attribute *fsg_attrs[] = { 3425static struct configfs_attribute *fsg_attrs[] = {
3453 &fsg_opts_stall.attr, 3426 &fsg_opts_attr_stall,
3454#ifdef CONFIG_USB_GADGET_DEBUG_FILES 3427#ifdef CONFIG_USB_GADGET_DEBUG_FILES
3455 &fsg_opts_num_buffers.attr, 3428 &fsg_opts_attr_num_buffers,
3456#endif 3429#endif
3457 NULL, 3430 NULL,
3458}; 3431};
diff --git a/drivers/usb/gadget/function/f_midi.c b/drivers/usb/gadget/function/f_midi.c
index ce3c8a629266..42acb45e1ab4 100644
--- a/drivers/usb/gadget/function/f_midi.c
+++ b/drivers/usb/gadget/function/f_midi.c
@@ -902,9 +902,6 @@ static inline struct f_midi_opts *to_f_midi_opts(struct config_item *item)
902 func_inst.group); 902 func_inst.group);
903} 903}
904 904
905CONFIGFS_ATTR_STRUCT(f_midi_opts);
906CONFIGFS_ATTR_OPS(f_midi_opts);
907
908static void midi_attr_release(struct config_item *item) 905static void midi_attr_release(struct config_item *item)
909{ 906{
910 struct f_midi_opts *opts = to_f_midi_opts(item); 907 struct f_midi_opts *opts = to_f_midi_opts(item);
@@ -914,13 +911,12 @@ static void midi_attr_release(struct config_item *item)
914 911
915static struct configfs_item_operations midi_item_ops = { 912static struct configfs_item_operations midi_item_ops = {
916 .release = midi_attr_release, 913 .release = midi_attr_release,
917 .show_attribute = f_midi_opts_attr_show,
918 .store_attribute = f_midi_opts_attr_store,
919}; 914};
920 915
921#define F_MIDI_OPT(name, test_limit, limit) \ 916#define F_MIDI_OPT(name, test_limit, limit) \
922static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \ 917static ssize_t f_midi_opts_##name##_show(struct config_item *item, char *page) \
923{ \ 918{ \
919 struct f_midi_opts *opts = to_f_midi_opts(item); \
924 int result; \ 920 int result; \
925 \ 921 \
926 mutex_lock(&opts->lock); \ 922 mutex_lock(&opts->lock); \
@@ -930,9 +926,10 @@ static ssize_t f_midi_opts_##name##_show(struct f_midi_opts *opts, char *page) \
930 return result; \ 926 return result; \
931} \ 927} \
932 \ 928 \
933static ssize_t f_midi_opts_##name##_store(struct f_midi_opts *opts, \ 929static ssize_t f_midi_opts_##name##_store(struct config_item *item, \
934 const char *page, size_t len) \ 930 const char *page, size_t len) \
935{ \ 931{ \
932 struct f_midi_opts *opts = to_f_midi_opts(item); \
936 int ret; \ 933 int ret; \
937 u32 num; \ 934 u32 num; \
938 \ 935 \
@@ -958,9 +955,7 @@ end: \
958 return ret; \ 955 return ret; \
959} \ 956} \
960 \ 957 \
961static struct f_midi_opts_attribute f_midi_opts_##name = \ 958CONFIGFS_ATTR(f_midi_opts_, name);
962 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, f_midi_opts_##name##_show, \
963 f_midi_opts_##name##_store)
964 959
965F_MIDI_OPT(index, true, SNDRV_CARDS); 960F_MIDI_OPT(index, true, SNDRV_CARDS);
966F_MIDI_OPT(buflen, false, 0); 961F_MIDI_OPT(buflen, false, 0);
@@ -968,8 +963,9 @@ F_MIDI_OPT(qlen, false, 0);
968F_MIDI_OPT(in_ports, true, MAX_PORTS); 963F_MIDI_OPT(in_ports, true, MAX_PORTS);
969F_MIDI_OPT(out_ports, true, MAX_PORTS); 964F_MIDI_OPT(out_ports, true, MAX_PORTS);
970 965
971static ssize_t f_midi_opts_id_show(struct f_midi_opts *opts, char *page) 966static ssize_t f_midi_opts_id_show(struct config_item *item, char *page)
972{ 967{
968 struct f_midi_opts *opts = to_f_midi_opts(item);
973 int result; 969 int result;
974 970
975 mutex_lock(&opts->lock); 971 mutex_lock(&opts->lock);
@@ -985,9 +981,10 @@ static ssize_t f_midi_opts_id_show(struct f_midi_opts *opts, char *page)
985 return result; 981 return result;
986} 982}
987 983
988static ssize_t f_midi_opts_id_store(struct f_midi_opts *opts, 984static ssize_t f_midi_opts_id_store(struct config_item *item,
989 const char *page, size_t len) 985 const char *page, size_t len)
990{ 986{
987 struct f_midi_opts *opts = to_f_midi_opts(item);
991 int ret; 988 int ret;
992 char *c; 989 char *c;
993 990
@@ -1012,17 +1009,15 @@ end:
1012 return ret; 1009 return ret;
1013} 1010}
1014 1011
1015static struct f_midi_opts_attribute f_midi_opts_id = 1012CONFIGFS_ATTR(f_midi_opts_, id);
1016 __CONFIGFS_ATTR(id, S_IRUGO | S_IWUSR, f_midi_opts_id_show,
1017 f_midi_opts_id_store);
1018 1013
1019static struct configfs_attribute *midi_attrs[] = { 1014static struct configfs_attribute *midi_attrs[] = {
1020 &f_midi_opts_index.attr, 1015 &f_midi_opts_attr_index,
1021 &f_midi_opts_buflen.attr, 1016 &f_midi_opts_attr_buflen,
1022 &f_midi_opts_qlen.attr, 1017 &f_midi_opts_attr_qlen,
1023 &f_midi_opts_in_ports.attr, 1018 &f_midi_opts_attr_in_ports,
1024 &f_midi_opts_out_ports.attr, 1019 &f_midi_opts_attr_out_ports,
1025 &f_midi_opts_id.attr, 1020 &f_midi_opts_attr_id,
1026 NULL, 1021 NULL,
1027}; 1022};
1028 1023
diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
index b6f7ed7d48a7..7ad798ace1e5 100644
--- a/drivers/usb/gadget/function/f_ncm.c
+++ b/drivers/usb/gadget/function/f_ncm.c
@@ -1488,10 +1488,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(ncm);
1488USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm); 1488USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(ncm);
1489 1489
1490static struct configfs_attribute *ncm_attrs[] = { 1490static struct configfs_attribute *ncm_attrs[] = {
1491 &f_ncm_opts_dev_addr.attr, 1491 &ncm_opts_attr_dev_addr,
1492 &f_ncm_opts_host_addr.attr, 1492 &ncm_opts_attr_host_addr,
1493 &f_ncm_opts_qmult.attr, 1493 &ncm_opts_attr_qmult,
1494 &f_ncm_opts_ifname.attr, 1494 &ncm_opts_attr_ifname,
1495 NULL, 1495 NULL,
1496}; 1496};
1497 1497
diff --git a/drivers/usb/gadget/function/f_obex.c b/drivers/usb/gadget/function/f_obex.c
index 1c3d30ad2f92..d6396e0909ee 100644
--- a/drivers/usb/gadget/function/f_obex.c
+++ b/drivers/usb/gadget/function/f_obex.c
@@ -387,22 +387,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
387 func_inst.group); 387 func_inst.group);
388} 388}
389 389
390CONFIGFS_ATTR_STRUCT(f_serial_opts);
391static ssize_t f_obex_attr_show(struct config_item *item,
392 struct configfs_attribute *attr,
393 char *page)
394{
395 struct f_serial_opts *opts = to_f_serial_opts(item);
396 struct f_serial_opts_attribute *f_serial_opts_attr =
397 container_of(attr, struct f_serial_opts_attribute, attr);
398 ssize_t ret = 0;
399
400 if (f_serial_opts_attr->show)
401 ret = f_serial_opts_attr->show(opts, page);
402
403 return ret;
404}
405
406static void obex_attr_release(struct config_item *item) 390static void obex_attr_release(struct config_item *item)
407{ 391{
408 struct f_serial_opts *opts = to_f_serial_opts(item); 392 struct f_serial_opts *opts = to_f_serial_opts(item);
@@ -412,19 +396,17 @@ static void obex_attr_release(struct config_item *item)
412 396
413static struct configfs_item_operations obex_item_ops = { 397static struct configfs_item_operations obex_item_ops = {
414 .release = obex_attr_release, 398 .release = obex_attr_release,
415 .show_attribute = f_obex_attr_show,
416}; 399};
417 400
418static ssize_t f_obex_port_num_show(struct f_serial_opts *opts, char *page) 401static ssize_t f_obex_port_num_show(struct config_item *item, char *page)
419{ 402{
420 return sprintf(page, "%u\n", opts->port_num); 403 return sprintf(page, "%u\n", to_f_serial_opts(item)->port_num);
421} 404}
422 405
423static struct f_serial_opts_attribute f_obex_port_num = 406CONFIGFS_ATTR_RO(f_obex_, port_num);
424 __CONFIGFS_ATTR_RO(port_num, f_obex_port_num_show);
425 407
426static struct configfs_attribute *acm_attrs[] = { 408static struct configfs_attribute *acm_attrs[] = {
427 &f_obex_port_num.attr, 409 &f_obex_attr_port_num,
428 NULL, 410 NULL,
429}; 411};
430 412
diff --git a/drivers/usb/gadget/function/f_phonet.c b/drivers/usb/gadget/function/f_phonet.c
index 62a198754029..157441dbfeba 100644
--- a/drivers/usb/gadget/function/f_phonet.c
+++ b/drivers/usb/gadget/function/f_phonet.c
@@ -583,21 +583,6 @@ static inline struct f_phonet_opts *to_f_phonet_opts(struct config_item *item)
583 func_inst.group); 583 func_inst.group);
584} 584}
585 585
586CONFIGFS_ATTR_STRUCT(f_phonet_opts);
587static ssize_t f_phonet_attr_show(struct config_item *item,
588 struct configfs_attribute *attr,
589 char *page)
590{
591 struct f_phonet_opts *opts = to_f_phonet_opts(item);
592 struct f_phonet_opts_attribute *f_phonet_opts_attr =
593 container_of(attr, struct f_phonet_opts_attribute, attr);
594 ssize_t ret = 0;
595
596 if (f_phonet_opts_attr->show)
597 ret = f_phonet_opts_attr->show(opts, page);
598 return ret;
599}
600
601static void phonet_attr_release(struct config_item *item) 586static void phonet_attr_release(struct config_item *item)
602{ 587{
603 struct f_phonet_opts *opts = to_f_phonet_opts(item); 588 struct f_phonet_opts *opts = to_f_phonet_opts(item);
@@ -607,19 +592,17 @@ static void phonet_attr_release(struct config_item *item)
607 592
608static struct configfs_item_operations phonet_item_ops = { 593static struct configfs_item_operations phonet_item_ops = {
609 .release = phonet_attr_release, 594 .release = phonet_attr_release,
610 .show_attribute = f_phonet_attr_show,
611}; 595};
612 596
613static ssize_t f_phonet_ifname_show(struct f_phonet_opts *opts, char *page) 597static ssize_t f_phonet_ifname_show(struct config_item *item, char *page)
614{ 598{
615 return gether_get_ifname(opts->net, page, PAGE_SIZE); 599 return gether_get_ifname(to_f_phonet_opts(item)->net, page, PAGE_SIZE);
616} 600}
617 601
618static struct f_phonet_opts_attribute f_phonet_ifname = 602CONFIGFS_ATTR_RO(f_phonet_, ifname);
619 __CONFIGFS_ATTR_RO(ifname, f_phonet_ifname_show);
620 603
621static struct configfs_attribute *phonet_attrs[] = { 604static struct configfs_attribute *phonet_attrs[] = {
622 &f_phonet_ifname.attr, 605 &f_phonet_attr_ifname,
623 NULL, 606 NULL,
624}; 607};
625 608
diff --git a/drivers/usb/gadget/function/f_printer.c b/drivers/usb/gadget/function/f_printer.c
index 7fb3209ed52c..0fbfb2b2aa08 100644
--- a/drivers/usb/gadget/function/f_printer.c
+++ b/drivers/usb/gadget/function/f_printer.c
@@ -1146,9 +1146,6 @@ static inline struct f_printer_opts
1146 func_inst.group); 1146 func_inst.group);
1147} 1147}
1148 1148
1149CONFIGFS_ATTR_STRUCT(f_printer_opts);
1150CONFIGFS_ATTR_OPS(f_printer_opts);
1151
1152static void printer_attr_release(struct config_item *item) 1149static void printer_attr_release(struct config_item *item)
1153{ 1150{
1154 struct f_printer_opts *opts = to_f_printer_opts(item); 1151 struct f_printer_opts *opts = to_f_printer_opts(item);
@@ -1158,13 +1155,12 @@ static void printer_attr_release(struct config_item *item)
1158 1155
1159static struct configfs_item_operations printer_item_ops = { 1156static struct configfs_item_operations printer_item_ops = {
1160 .release = printer_attr_release, 1157 .release = printer_attr_release,
1161 .show_attribute = f_printer_opts_attr_show,
1162 .store_attribute = f_printer_opts_attr_store,
1163}; 1158};
1164 1159
1165static ssize_t f_printer_opts_pnp_string_show(struct f_printer_opts *opts, 1160static ssize_t f_printer_opts_pnp_string_show(struct config_item *item,
1166 char *page) 1161 char *page)
1167{ 1162{
1163 struct f_printer_opts *opts = to_f_printer_opts(item);
1168 int result; 1164 int result;
1169 1165
1170 mutex_lock(&opts->lock); 1166 mutex_lock(&opts->lock);
@@ -1174,9 +1170,10 @@ static ssize_t f_printer_opts_pnp_string_show(struct f_printer_opts *opts,
1174 return result; 1170 return result;
1175} 1171}
1176 1172
1177static ssize_t f_printer_opts_pnp_string_store(struct f_printer_opts *opts, 1173static ssize_t f_printer_opts_pnp_string_store(struct config_item *item,
1178 const char *page, size_t len) 1174 const char *page, size_t len)
1179{ 1175{
1176 struct f_printer_opts *opts = to_f_printer_opts(item);
1180 int result, l; 1177 int result, l;
1181 1178
1182 mutex_lock(&opts->lock); 1179 mutex_lock(&opts->lock);
@@ -1189,14 +1186,12 @@ static ssize_t f_printer_opts_pnp_string_store(struct f_printer_opts *opts,
1189 return result; 1186 return result;
1190} 1187}
1191 1188
1192static struct f_printer_opts_attribute f_printer_opts_pnp_string = 1189CONFIGFS_ATTR(f_printer_opts_, pnp_string);
1193 __CONFIGFS_ATTR(pnp_string, S_IRUGO | S_IWUSR,
1194 f_printer_opts_pnp_string_show,
1195 f_printer_opts_pnp_string_store);
1196 1190
1197static ssize_t f_printer_opts_q_len_show(struct f_printer_opts *opts, 1191static ssize_t f_printer_opts_q_len_show(struct config_item *item,
1198 char *page) 1192 char *page)
1199{ 1193{
1194 struct f_printer_opts *opts = to_f_printer_opts(item);
1200 int result; 1195 int result;
1201 1196
1202 mutex_lock(&opts->lock); 1197 mutex_lock(&opts->lock);
@@ -1206,9 +1201,10 @@ static ssize_t f_printer_opts_q_len_show(struct f_printer_opts *opts,
1206 return result; 1201 return result;
1207} 1202}
1208 1203
1209static ssize_t f_printer_opts_q_len_store(struct f_printer_opts *opts, 1204static ssize_t f_printer_opts_q_len_store(struct config_item *item,
1210 const char *page, size_t len) 1205 const char *page, size_t len)
1211{ 1206{
1207 struct f_printer_opts *opts = to_f_printer_opts(item);
1212 int ret; 1208 int ret;
1213 u16 num; 1209 u16 num;
1214 1210
@@ -1229,13 +1225,11 @@ end:
1229 return ret; 1225 return ret;
1230} 1226}
1231 1227
1232static struct f_printer_opts_attribute f_printer_opts_q_len = 1228CONFIGFS_ATTR(f_printer_opts_, q_len);
1233 __CONFIGFS_ATTR(q_len, S_IRUGO | S_IWUSR, f_printer_opts_q_len_show,
1234 f_printer_opts_q_len_store);
1235 1229
1236static struct configfs_attribute *printer_attrs[] = { 1230static struct configfs_attribute *printer_attrs[] = {
1237 &f_printer_opts_pnp_string.attr, 1231 &f_printer_opts_attr_pnp_string,
1238 &f_printer_opts_q_len.attr, 1232 &f_printer_opts_attr_q_len,
1239 NULL, 1233 NULL,
1240}; 1234};
1241 1235
diff --git a/drivers/usb/gadget/function/f_rndis.c b/drivers/usb/gadget/function/f_rndis.c
index fd301ed9e294..e587767e374c 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -864,10 +864,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(rndis);
864USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis); 864USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(rndis);
865 865
866static struct configfs_attribute *rndis_attrs[] = { 866static struct configfs_attribute *rndis_attrs[] = {
867 &f_rndis_opts_dev_addr.attr, 867 &rndis_opts_attr_dev_addr,
868 &f_rndis_opts_host_addr.attr, 868 &rndis_opts_attr_host_addr,
869 &f_rndis_opts_qmult.attr, 869 &rndis_opts_attr_qmult,
870 &f_rndis_opts_ifname.attr, 870 &rndis_opts_attr_ifname,
871 NULL, 871 NULL,
872}; 872};
873 873
diff --git a/drivers/usb/gadget/function/f_serial.c b/drivers/usb/gadget/function/f_serial.c
index ba705e047d7e..6bb44d613bab 100644
--- a/drivers/usb/gadget/function/f_serial.c
+++ b/drivers/usb/gadget/function/f_serial.c
@@ -258,22 +258,6 @@ static inline struct f_serial_opts *to_f_serial_opts(struct config_item *item)
258 func_inst.group); 258 func_inst.group);
259} 259}
260 260
261CONFIGFS_ATTR_STRUCT(f_serial_opts);
262static ssize_t f_serial_attr_show(struct config_item *item,
263 struct configfs_attribute *attr,
264 char *page)
265{
266 struct f_serial_opts *opts = to_f_serial_opts(item);
267 struct f_serial_opts_attribute *f_serial_opts_attr =
268 container_of(attr, struct f_serial_opts_attribute, attr);
269 ssize_t ret = 0;
270
271 if (f_serial_opts_attr->show)
272 ret = f_serial_opts_attr->show(opts, page);
273
274 return ret;
275}
276
277static void serial_attr_release(struct config_item *item) 261static void serial_attr_release(struct config_item *item)
278{ 262{
279 struct f_serial_opts *opts = to_f_serial_opts(item); 263 struct f_serial_opts *opts = to_f_serial_opts(item);
@@ -283,19 +267,17 @@ static void serial_attr_release(struct config_item *item)
283 267
284static struct configfs_item_operations serial_item_ops = { 268static struct configfs_item_operations serial_item_ops = {
285 .release = serial_attr_release, 269 .release = serial_attr_release,
286 .show_attribute = f_serial_attr_show,
287}; 270};
288 271
289static ssize_t f_serial_port_num_show(struct f_serial_opts *opts, char *page) 272static ssize_t f_serial_port_num_show(struct config_item *item, char *page)
290{ 273{
291 return sprintf(page, "%u\n", opts->port_num); 274 return sprintf(page, "%u\n", to_f_serial_opts(item)->port_num);
292} 275}
293 276
294static struct f_serial_opts_attribute f_serial_port_num = 277CONFIGFS_ATTR_RO(f_serial_, port_num);
295 __CONFIGFS_ATTR_RO(port_num, f_serial_port_num_show);
296 278
297static struct configfs_attribute *acm_attrs[] = { 279static struct configfs_attribute *acm_attrs[] = {
298 &f_serial_port_num.attr, 280 &f_serial_attr_port_num,
299 NULL, 281 NULL,
300}; 282};
301 283
diff --git a/drivers/usb/gadget/function/f_sourcesink.c b/drivers/usb/gadget/function/f_sourcesink.c
index d7646d3acd63..9f3ced62d916 100644
--- a/drivers/usb/gadget/function/f_sourcesink.c
+++ b/drivers/usb/gadget/function/f_sourcesink.c
@@ -889,9 +889,6 @@ static inline struct f_ss_opts *to_f_ss_opts(struct config_item *item)
889 func_inst.group); 889 func_inst.group);
890} 890}
891 891
892CONFIGFS_ATTR_STRUCT(f_ss_opts);
893CONFIGFS_ATTR_OPS(f_ss_opts);
894
895static void ss_attr_release(struct config_item *item) 892static void ss_attr_release(struct config_item *item)
896{ 893{
897 struct f_ss_opts *ss_opts = to_f_ss_opts(item); 894 struct f_ss_opts *ss_opts = to_f_ss_opts(item);
@@ -901,12 +898,11 @@ static void ss_attr_release(struct config_item *item)
901 898
902static struct configfs_item_operations ss_item_ops = { 899static struct configfs_item_operations ss_item_ops = {
903 .release = ss_attr_release, 900 .release = ss_attr_release,
904 .show_attribute = f_ss_opts_attr_show,
905 .store_attribute = f_ss_opts_attr_store,
906}; 901};
907 902
908static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page) 903static ssize_t f_ss_opts_pattern_show(struct config_item *item, char *page)
909{ 904{
905 struct f_ss_opts *opts = to_f_ss_opts(item);
910 int result; 906 int result;
911 907
912 mutex_lock(&opts->lock); 908 mutex_lock(&opts->lock);
@@ -916,9 +912,10 @@ static ssize_t f_ss_opts_pattern_show(struct f_ss_opts *opts, char *page)
916 return result; 912 return result;
917} 913}
918 914
919static ssize_t f_ss_opts_pattern_store(struct f_ss_opts *opts, 915static ssize_t f_ss_opts_pattern_store(struct config_item *item,
920 const char *page, size_t len) 916 const char *page, size_t len)
921{ 917{
918 struct f_ss_opts *opts = to_f_ss_opts(item);
922 int ret; 919 int ret;
923 u8 num; 920 u8 num;
924 921
@@ -944,13 +941,11 @@ end:
944 return ret; 941 return ret;
945} 942}
946 943
947static struct f_ss_opts_attribute f_ss_opts_pattern = 944CONFIGFS_ATTR(f_ss_opts_, pattern);
948 __CONFIGFS_ATTR(pattern, S_IRUGO | S_IWUSR,
949 f_ss_opts_pattern_show,
950 f_ss_opts_pattern_store);
951 945
952static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page) 946static ssize_t f_ss_opts_isoc_interval_show(struct config_item *item, char *page)
953{ 947{
948 struct f_ss_opts *opts = to_f_ss_opts(item);
954 int result; 949 int result;
955 950
956 mutex_lock(&opts->lock); 951 mutex_lock(&opts->lock);
@@ -960,9 +955,10 @@ static ssize_t f_ss_opts_isoc_interval_show(struct f_ss_opts *opts, char *page)
960 return result; 955 return result;
961} 956}
962 957
963static ssize_t f_ss_opts_isoc_interval_store(struct f_ss_opts *opts, 958static ssize_t f_ss_opts_isoc_interval_store(struct config_item *item,
964 const char *page, size_t len) 959 const char *page, size_t len)
965{ 960{
961 struct f_ss_opts *opts = to_f_ss_opts(item);
966 int ret; 962 int ret;
967 u8 num; 963 u8 num;
968 964
@@ -988,13 +984,11 @@ end:
988 return ret; 984 return ret;
989} 985}
990 986
991static struct f_ss_opts_attribute f_ss_opts_isoc_interval = 987CONFIGFS_ATTR(f_ss_opts_, isoc_interval);
992 __CONFIGFS_ATTR(isoc_interval, S_IRUGO | S_IWUSR,
993 f_ss_opts_isoc_interval_show,
994 f_ss_opts_isoc_interval_store);
995 988
996static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page) 989static ssize_t f_ss_opts_isoc_maxpacket_show(struct config_item *item, char *page)
997{ 990{
991 struct f_ss_opts *opts = to_f_ss_opts(item);
998 int result; 992 int result;
999 993
1000 mutex_lock(&opts->lock); 994 mutex_lock(&opts->lock);
@@ -1004,9 +998,10 @@ static ssize_t f_ss_opts_isoc_maxpacket_show(struct f_ss_opts *opts, char *page)
1004 return result; 998 return result;
1005} 999}
1006 1000
1007static ssize_t f_ss_opts_isoc_maxpacket_store(struct f_ss_opts *opts, 1001static ssize_t f_ss_opts_isoc_maxpacket_store(struct config_item *item,
1008 const char *page, size_t len) 1002 const char *page, size_t len)
1009{ 1003{
1004 struct f_ss_opts *opts = to_f_ss_opts(item);
1010 int ret; 1005 int ret;
1011 u16 num; 1006 u16 num;
1012 1007
@@ -1032,13 +1027,11 @@ end:
1032 return ret; 1027 return ret;
1033} 1028}
1034 1029
1035static struct f_ss_opts_attribute f_ss_opts_isoc_maxpacket = 1030CONFIGFS_ATTR(f_ss_opts_, isoc_maxpacket);
1036 __CONFIGFS_ATTR(isoc_maxpacket, S_IRUGO | S_IWUSR,
1037 f_ss_opts_isoc_maxpacket_show,
1038 f_ss_opts_isoc_maxpacket_store);
1039 1031
1040static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page) 1032static ssize_t f_ss_opts_isoc_mult_show(struct config_item *item, char *page)
1041{ 1033{
1034 struct f_ss_opts *opts = to_f_ss_opts(item);
1042 int result; 1035 int result;
1043 1036
1044 mutex_lock(&opts->lock); 1037 mutex_lock(&opts->lock);
@@ -1048,9 +1041,10 @@ static ssize_t f_ss_opts_isoc_mult_show(struct f_ss_opts *opts, char *page)
1048 return result; 1041 return result;
1049} 1042}
1050 1043
1051static ssize_t f_ss_opts_isoc_mult_store(struct f_ss_opts *opts, 1044static ssize_t f_ss_opts_isoc_mult_store(struct config_item *item,
1052 const char *page, size_t len) 1045 const char *page, size_t len)
1053{ 1046{
1047 struct f_ss_opts *opts = to_f_ss_opts(item);
1054 int ret; 1048 int ret;
1055 u8 num; 1049 u8 num;
1056 1050
@@ -1076,13 +1070,11 @@ end:
1076 return ret; 1070 return ret;
1077} 1071}
1078 1072
1079static struct f_ss_opts_attribute f_ss_opts_isoc_mult = 1073CONFIGFS_ATTR(f_ss_opts_, isoc_mult);
1080 __CONFIGFS_ATTR(isoc_mult, S_IRUGO | S_IWUSR,
1081 f_ss_opts_isoc_mult_show,
1082 f_ss_opts_isoc_mult_store);
1083 1074
1084static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page) 1075static ssize_t f_ss_opts_isoc_maxburst_show(struct config_item *item, char *page)
1085{ 1076{
1077 struct f_ss_opts *opts = to_f_ss_opts(item);
1086 int result; 1078 int result;
1087 1079
1088 mutex_lock(&opts->lock); 1080 mutex_lock(&opts->lock);
@@ -1092,9 +1084,10 @@ static ssize_t f_ss_opts_isoc_maxburst_show(struct f_ss_opts *opts, char *page)
1092 return result; 1084 return result;
1093} 1085}
1094 1086
1095static ssize_t f_ss_opts_isoc_maxburst_store(struct f_ss_opts *opts, 1087static ssize_t f_ss_opts_isoc_maxburst_store(struct config_item *item,
1096 const char *page, size_t len) 1088 const char *page, size_t len)
1097{ 1089{
1090 struct f_ss_opts *opts = to_f_ss_opts(item);
1098 int ret; 1091 int ret;
1099 u8 num; 1092 u8 num;
1100 1093
@@ -1120,13 +1113,11 @@ end:
1120 return ret; 1113 return ret;
1121} 1114}
1122 1115
1123static struct f_ss_opts_attribute f_ss_opts_isoc_maxburst = 1116CONFIGFS_ATTR(f_ss_opts_, isoc_maxburst);
1124 __CONFIGFS_ATTR(isoc_maxburst, S_IRUGO | S_IWUSR,
1125 f_ss_opts_isoc_maxburst_show,
1126 f_ss_opts_isoc_maxburst_store);
1127 1117
1128static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page) 1118static ssize_t f_ss_opts_bulk_buflen_show(struct config_item *item, char *page)
1129{ 1119{
1120 struct f_ss_opts *opts = to_f_ss_opts(item);
1130 int result; 1121 int result;
1131 1122
1132 mutex_lock(&opts->lock); 1123 mutex_lock(&opts->lock);
@@ -1136,9 +1127,10 @@ static ssize_t f_ss_opts_bulk_buflen_show(struct f_ss_opts *opts, char *page)
1136 return result; 1127 return result;
1137} 1128}
1138 1129
1139static ssize_t f_ss_opts_bulk_buflen_store(struct f_ss_opts *opts, 1130static ssize_t f_ss_opts_bulk_buflen_store(struct config_item *item,
1140 const char *page, size_t len) 1131 const char *page, size_t len)
1141{ 1132{
1133 struct f_ss_opts *opts = to_f_ss_opts(item);
1142 int ret; 1134 int ret;
1143 u32 num; 1135 u32 num;
1144 1136
@@ -1159,18 +1151,15 @@ end:
1159 return ret; 1151 return ret;
1160} 1152}
1161 1153
1162static struct f_ss_opts_attribute f_ss_opts_bulk_buflen = 1154CONFIGFS_ATTR(f_ss_opts_, bulk_buflen);
1163 __CONFIGFS_ATTR(buflen, S_IRUGO | S_IWUSR,
1164 f_ss_opts_bulk_buflen_show,
1165 f_ss_opts_bulk_buflen_store);
1166 1155
1167static struct configfs_attribute *ss_attrs[] = { 1156static struct configfs_attribute *ss_attrs[] = {
1168 &f_ss_opts_pattern.attr, 1157 &f_ss_opts_attr_pattern,
1169 &f_ss_opts_isoc_interval.attr, 1158 &f_ss_opts_attr_isoc_interval,
1170 &f_ss_opts_isoc_maxpacket.attr, 1159 &f_ss_opts_attr_isoc_maxpacket,
1171 &f_ss_opts_isoc_mult.attr, 1160 &f_ss_opts_attr_isoc_mult,
1172 &f_ss_opts_isoc_maxburst.attr, 1161 &f_ss_opts_attr_isoc_maxburst,
1173 &f_ss_opts_bulk_buflen.attr, 1162 &f_ss_opts_attr_bulk_buflen,
1174 NULL, 1163 NULL,
1175}; 1164};
1176 1165
diff --git a/drivers/usb/gadget/function/f_subset.c b/drivers/usb/gadget/function/f_subset.c
index 2e66e624e6e1..829c78de9eba 100644
--- a/drivers/usb/gadget/function/f_subset.c
+++ b/drivers/usb/gadget/function/f_subset.c
@@ -405,10 +405,10 @@ USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(gether);
405USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether); 405USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(gether);
406 406
407static struct configfs_attribute *gether_attrs[] = { 407static struct configfs_attribute *gether_attrs[] = {
408 &f_gether_opts_dev_addr.attr, 408 &gether_opts_attr_dev_addr,
409 &f_gether_opts_host_addr.attr, 409 &gether_opts_attr_host_addr,
410 &f_gether_opts_qmult.attr, 410 &gether_opts_attr_qmult,
411 &f_gether_opts_ifname.attr, 411 &gether_opts_attr_ifname,
412 NULL, 412 NULL,
413}; 413};
414 414
diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c
index 8ee701924d29..6a2346b99f55 100644
--- a/drivers/usb/gadget/function/f_uac1.c
+++ b/drivers/usb/gadget/function/f_uac1.c
@@ -769,9 +769,6 @@ static inline struct f_uac1_opts *to_f_uac1_opts(struct config_item *item)
769 func_inst.group); 769 func_inst.group);
770} 770}
771 771
772CONFIGFS_ATTR_STRUCT(f_uac1_opts);
773CONFIGFS_ATTR_OPS(f_uac1_opts);
774
775static void f_uac1_attr_release(struct config_item *item) 772static void f_uac1_attr_release(struct config_item *item)
776{ 773{
777 struct f_uac1_opts *opts = to_f_uac1_opts(item); 774 struct f_uac1_opts *opts = to_f_uac1_opts(item);
@@ -781,14 +778,13 @@ static void f_uac1_attr_release(struct config_item *item)
781 778
782static struct configfs_item_operations f_uac1_item_ops = { 779static struct configfs_item_operations f_uac1_item_ops = {
783 .release = f_uac1_attr_release, 780 .release = f_uac1_attr_release,
784 .show_attribute = f_uac1_opts_attr_show,
785 .store_attribute = f_uac1_opts_attr_store,
786}; 781};
787 782
788#define UAC1_INT_ATTRIBUTE(name) \ 783#define UAC1_INT_ATTRIBUTE(name) \
789static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ 784static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \
790 char *page) \ 785 char *page) \
791{ \ 786{ \
787 struct f_uac1_opts *opts = to_f_uac1_opts(item); \
792 int result; \ 788 int result; \
793 \ 789 \
794 mutex_lock(&opts->lock); \ 790 mutex_lock(&opts->lock); \
@@ -798,9 +794,10 @@ static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \
798 return result; \ 794 return result; \
799} \ 795} \
800 \ 796 \
801static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ 797static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \
802 const char *page, size_t len) \ 798 const char *page, size_t len) \
803{ \ 799{ \
800 struct f_uac1_opts *opts = to_f_uac1_opts(item); \
804 int ret; \ 801 int ret; \
805 u32 num; \ 802 u32 num; \
806 \ 803 \
@@ -822,19 +819,17 @@ end: \
822 return ret; \ 819 return ret; \
823} \ 820} \
824 \ 821 \
825static struct f_uac1_opts_attribute f_uac1_opts_##name = \ 822CONFIGFS_ATTR(f_uac1_opts_, name)
826 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
827 f_uac1_opts_##name##_show, \
828 f_uac1_opts_##name##_store)
829 823
830UAC1_INT_ATTRIBUTE(req_buf_size); 824UAC1_INT_ATTRIBUTE(req_buf_size);
831UAC1_INT_ATTRIBUTE(req_count); 825UAC1_INT_ATTRIBUTE(req_count);
832UAC1_INT_ATTRIBUTE(audio_buf_size); 826UAC1_INT_ATTRIBUTE(audio_buf_size);
833 827
834#define UAC1_STR_ATTRIBUTE(name) \ 828#define UAC1_STR_ATTRIBUTE(name) \
835static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \ 829static ssize_t f_uac1_opts_##name##_show(struct config_item *item, \
836 char *page) \ 830 char *page) \
837{ \ 831{ \
832 struct f_uac1_opts *opts = to_f_uac1_opts(item); \
838 int result; \ 833 int result; \
839 \ 834 \
840 mutex_lock(&opts->lock); \ 835 mutex_lock(&opts->lock); \
@@ -844,9 +839,10 @@ static ssize_t f_uac1_opts_##name##_show(struct f_uac1_opts *opts, \
844 return result; \ 839 return result; \
845} \ 840} \
846 \ 841 \
847static ssize_t f_uac1_opts_##name##_store(struct f_uac1_opts *opts, \ 842static ssize_t f_uac1_opts_##name##_store(struct config_item *item, \
848 const char *page, size_t len) \ 843 const char *page, size_t len) \
849{ \ 844{ \
845 struct f_uac1_opts *opts = to_f_uac1_opts(item); \
850 int ret = -EBUSY; \ 846 int ret = -EBUSY; \
851 char *tmp; \ 847 char *tmp; \
852 \ 848 \
@@ -870,22 +866,19 @@ end: \
870 return ret; \ 866 return ret; \
871} \ 867} \
872 \ 868 \
873static struct f_uac1_opts_attribute f_uac1_opts_##name = \ 869CONFIGFS_ATTR(f_uac1_opts_, name)
874 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
875 f_uac1_opts_##name##_show, \
876 f_uac1_opts_##name##_store)
877 870
878UAC1_STR_ATTRIBUTE(fn_play); 871UAC1_STR_ATTRIBUTE(fn_play);
879UAC1_STR_ATTRIBUTE(fn_cap); 872UAC1_STR_ATTRIBUTE(fn_cap);
880UAC1_STR_ATTRIBUTE(fn_cntl); 873UAC1_STR_ATTRIBUTE(fn_cntl);
881 874
882static struct configfs_attribute *f_uac1_attrs[] = { 875static struct configfs_attribute *f_uac1_attrs[] = {
883 &f_uac1_opts_req_buf_size.attr, 876 &f_uac1_opts_attr_req_buf_size,
884 &f_uac1_opts_req_count.attr, 877 &f_uac1_opts_attr_req_count,
885 &f_uac1_opts_audio_buf_size.attr, 878 &f_uac1_opts_attr_audio_buf_size,
886 &f_uac1_opts_fn_play.attr, 879 &f_uac1_opts_attr_fn_play,
887 &f_uac1_opts_fn_cap.attr, 880 &f_uac1_opts_attr_fn_cap,
888 &f_uac1_opts_fn_cntl.attr, 881 &f_uac1_opts_attr_fn_cntl,
889 NULL, 882 NULL,
890}; 883};
891 884
diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index 63336e269898..044ca79d3cb5 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -1439,9 +1439,6 @@ static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item)
1439 func_inst.group); 1439 func_inst.group);
1440} 1440}
1441 1441
1442CONFIGFS_ATTR_STRUCT(f_uac2_opts);
1443CONFIGFS_ATTR_OPS(f_uac2_opts);
1444
1445static void f_uac2_attr_release(struct config_item *item) 1442static void f_uac2_attr_release(struct config_item *item)
1446{ 1443{
1447 struct f_uac2_opts *opts = to_f_uac2_opts(item); 1444 struct f_uac2_opts *opts = to_f_uac2_opts(item);
@@ -1451,14 +1448,13 @@ static void f_uac2_attr_release(struct config_item *item)
1451 1448
1452static struct configfs_item_operations f_uac2_item_ops = { 1449static struct configfs_item_operations f_uac2_item_ops = {
1453 .release = f_uac2_attr_release, 1450 .release = f_uac2_attr_release,
1454 .show_attribute = f_uac2_opts_attr_show,
1455 .store_attribute = f_uac2_opts_attr_store,
1456}; 1451};
1457 1452
1458#define UAC2_ATTRIBUTE(name) \ 1453#define UAC2_ATTRIBUTE(name) \
1459static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \ 1454static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \
1460 char *page) \ 1455 char *page) \
1461{ \ 1456{ \
1457 struct f_uac2_opts *opts = to_f_uac2_opts(item); \
1462 int result; \ 1458 int result; \
1463 \ 1459 \
1464 mutex_lock(&opts->lock); \ 1460 mutex_lock(&opts->lock); \
@@ -1468,9 +1464,10 @@ static ssize_t f_uac2_opts_##name##_show(struct f_uac2_opts *opts, \
1468 return result; \ 1464 return result; \
1469} \ 1465} \
1470 \ 1466 \
1471static ssize_t f_uac2_opts_##name##_store(struct f_uac2_opts *opts, \ 1467static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
1472 const char *page, size_t len) \ 1468 const char *page, size_t len) \
1473{ \ 1469{ \
1470 struct f_uac2_opts *opts = to_f_uac2_opts(item); \
1474 int ret; \ 1471 int ret; \
1475 u32 num; \ 1472 u32 num; \
1476 \ 1473 \
@@ -1492,10 +1489,7 @@ end: \
1492 return ret; \ 1489 return ret; \
1493} \ 1490} \
1494 \ 1491 \
1495static struct f_uac2_opts_attribute f_uac2_opts_##name = \ 1492CONFIGFS_ATTR(f_uac2_opts_, name)
1496 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
1497 f_uac2_opts_##name##_show, \
1498 f_uac2_opts_##name##_store)
1499 1493
1500UAC2_ATTRIBUTE(p_chmask); 1494UAC2_ATTRIBUTE(p_chmask);
1501UAC2_ATTRIBUTE(p_srate); 1495UAC2_ATTRIBUTE(p_srate);
@@ -1505,12 +1499,12 @@ UAC2_ATTRIBUTE(c_srate);
1505UAC2_ATTRIBUTE(c_ssize); 1499UAC2_ATTRIBUTE(c_ssize);
1506 1500
1507static struct configfs_attribute *f_uac2_attrs[] = { 1501static struct configfs_attribute *f_uac2_attrs[] = {
1508 &f_uac2_opts_p_chmask.attr, 1502 &f_uac2_opts_attr_p_chmask,
1509 &f_uac2_opts_p_srate.attr, 1503 &f_uac2_opts_attr_p_srate,
1510 &f_uac2_opts_p_ssize.attr, 1504 &f_uac2_opts_attr_p_ssize,
1511 &f_uac2_opts_c_chmask.attr, 1505 &f_uac2_opts_attr_c_chmask,
1512 &f_uac2_opts_c_srate.attr, 1506 &f_uac2_opts_attr_c_srate,
1513 &f_uac2_opts_c_ssize.attr, 1507 &f_uac2_opts_attr_c_ssize,
1514 NULL, 1508 NULL,
1515}; 1509};
1516 1510
diff --git a/drivers/usb/gadget/function/u_ether_configfs.h b/drivers/usb/gadget/function/u_ether_configfs.h
index bcbd30146cfd..4f47289fcf7c 100644
--- a/drivers/usb/gadget/function/u_ether_configfs.h
+++ b/drivers/usb/gadget/function/u_ether_configfs.h
@@ -17,9 +17,6 @@
17#define __U_ETHER_CONFIGFS_H 17#define __U_ETHER_CONFIGFS_H
18 18
19#define USB_ETHERNET_CONFIGFS_ITEM(_f_) \ 19#define USB_ETHERNET_CONFIGFS_ITEM(_f_) \
20 CONFIGFS_ATTR_STRUCT(f_##_f_##_opts); \
21 CONFIGFS_ATTR_OPS(f_##_f_##_opts); \
22 \
23 static void _f_##_attr_release(struct config_item *item) \ 20 static void _f_##_attr_release(struct config_item *item) \
24 { \ 21 { \
25 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \ 22 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
@@ -29,14 +26,13 @@
29 \ 26 \
30 static struct configfs_item_operations _f_##_item_ops = { \ 27 static struct configfs_item_operations _f_##_item_ops = { \
31 .release = _f_##_attr_release, \ 28 .release = _f_##_attr_release, \
32 .show_attribute = f_##_f_##_opts_attr_show, \
33 .store_attribute = f_##_f_##_opts_attr_store, \
34 } 29 }
35 30
36#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \ 31#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_DEV_ADDR(_f_) \
37 static ssize_t _f_##_opts_dev_addr_show(struct f_##_f_##_opts *opts, \ 32 static ssize_t _f_##_opts_dev_addr_show(struct config_item *item, \
38 char *page) \ 33 char *page) \
39 { \ 34 { \
35 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
40 int result; \ 36 int result; \
41 \ 37 \
42 mutex_lock(&opts->lock); \ 38 mutex_lock(&opts->lock); \
@@ -46,9 +42,10 @@
46 return result; \ 42 return result; \
47 } \ 43 } \
48 \ 44 \
49 static ssize_t _f_##_opts_dev_addr_store(struct f_##_f_##_opts *opts, \ 45 static ssize_t _f_##_opts_dev_addr_store(struct config_item *item, \
50 const char *page, size_t len)\ 46 const char *page, size_t len)\
51 { \ 47 { \
48 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
52 int ret; \ 49 int ret; \
53 \ 50 \
54 mutex_lock(&opts->lock); \ 51 mutex_lock(&opts->lock); \
@@ -64,15 +61,13 @@
64 return ret; \ 61 return ret; \
65 } \ 62 } \
66 \ 63 \
67 static struct f_##_f_##_opts_attribute f_##_f_##_opts_dev_addr = \ 64 CONFIGFS_ATTR(_f_##_opts_, dev_addr)
68 __CONFIGFS_ATTR(dev_addr, S_IRUGO | S_IWUSR, \
69 _f_##_opts_dev_addr_show, \
70 _f_##_opts_dev_addr_store)
71 65
72#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(_f_) \ 66#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_HOST_ADDR(_f_) \
73 static ssize_t _f_##_opts_host_addr_show(struct f_##_f_##_opts *opts, \ 67 static ssize_t _f_##_opts_host_addr_show(struct config_item *item, \
74 char *page) \ 68 char *page) \
75 { \ 69 { \
70 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
76 int result; \ 71 int result; \
77 \ 72 \
78 mutex_lock(&opts->lock); \ 73 mutex_lock(&opts->lock); \
@@ -82,9 +77,10 @@
82 return result; \ 77 return result; \
83 } \ 78 } \
84 \ 79 \
85 static ssize_t _f_##_opts_host_addr_store(struct f_##_f_##_opts *opts, \ 80 static ssize_t _f_##_opts_host_addr_store(struct config_item *item, \
86 const char *page, size_t len)\ 81 const char *page, size_t len)\
87 { \ 82 { \
83 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
88 int ret; \ 84 int ret; \
89 \ 85 \
90 mutex_lock(&opts->lock); \ 86 mutex_lock(&opts->lock); \
@@ -100,15 +96,13 @@
100 return ret; \ 96 return ret; \
101 } \ 97 } \
102 \ 98 \
103 static struct f_##_f_##_opts_attribute f_##_f_##_opts_host_addr = \ 99 CONFIGFS_ATTR(_f_##_opts_, host_addr)
104 __CONFIGFS_ATTR(host_addr, S_IRUGO | S_IWUSR, \
105 _f_##_opts_host_addr_show, \
106 _f_##_opts_host_addr_store)
107 100
108#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(_f_) \ 101#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_QMULT(_f_) \
109 static ssize_t _f_##_opts_qmult_show(struct f_##_f_##_opts *opts, \ 102 static ssize_t _f_##_opts_qmult_show(struct config_item *item, \
110 char *page) \ 103 char *page) \
111 { \ 104 { \
105 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
112 unsigned qmult; \ 106 unsigned qmult; \
113 \ 107 \
114 mutex_lock(&opts->lock); \ 108 mutex_lock(&opts->lock); \
@@ -117,9 +111,10 @@
117 return sprintf(page, "%d", qmult); \ 111 return sprintf(page, "%d", qmult); \
118 } \ 112 } \
119 \ 113 \
120 static ssize_t _f_##_opts_qmult_store(struct f_##_f_##_opts *opts, \ 114 static ssize_t _f_##_opts_qmult_store(struct config_item *item, \
121 const char *page, size_t len)\ 115 const char *page, size_t len)\
122 { \ 116 { \
117 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
123 u8 val; \ 118 u8 val; \
124 int ret; \ 119 int ret; \
125 \ 120 \
@@ -140,15 +135,13 @@ out: \
140 return ret; \ 135 return ret; \
141 } \ 136 } \
142 \ 137 \
143 static struct f_##_f_##_opts_attribute f_##_f_##_opts_qmult = \ 138 CONFIGFS_ATTR(_f_##_opts_, qmult)
144 __CONFIGFS_ATTR(qmult, S_IRUGO | S_IWUSR, \
145 _f_##_opts_qmult_show, \
146 _f_##_opts_qmult_store)
147 139
148#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(_f_) \ 140#define USB_ETHERNET_CONFIGFS_ITEM_ATTR_IFNAME(_f_) \
149 static ssize_t _f_##_opts_ifname_show(struct f_##_f_##_opts *opts, \ 141 static ssize_t _f_##_opts_ifname_show(struct config_item *item, \
150 char *page) \ 142 char *page) \
151 { \ 143 { \
144 struct f_##_f_##_opts *opts = to_f_##_f_##_opts(item); \
152 int ret; \ 145 int ret; \
153 \ 146 \
154 mutex_lock(&opts->lock); \ 147 mutex_lock(&opts->lock); \
@@ -158,7 +151,6 @@ out: \
158 return ret; \ 151 return ret; \
159 } \ 152 } \
160 \ 153 \
161 static struct f_##_f_##_opts_attribute f_##_f_##_opts_ifname = \ 154 CONFIGFS_ATTR_RO(_f_##_opts_, ifname)
162 __CONFIGFS_ATTR_RO(ifname, _f_##_opts_ifname_show)
163 155
164#endif /* __U_ETHER_CONFIGFS_H */ 156#endif /* __U_ETHER_CONFIGFS_H */
diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadget/function/uvc_configfs.c
index 3c0467bcb14f..289ebca316d3 100644
--- a/drivers/usb/gadget/function/uvc_configfs.c
+++ b/drivers/usb/gadget/function/uvc_configfs.c
@@ -17,19 +17,21 @@
17 17
18#define UVCG_STREAMING_CONTROL_SIZE 1 18#define UVCG_STREAMING_CONTROL_SIZE 1
19 19
20#define CONFIGFS_ATTR_OPS_RO(_item) \ 20#define UVC_ATTR(prefix, cname, aname) \
21static ssize_t _item##_attr_show(struct config_item *item, \ 21static struct configfs_attribute prefix##attr_##cname = { \
22 struct configfs_attribute *attr, \ 22 .ca_name = __stringify(aname), \
23 char *page) \ 23 .ca_mode = S_IRUGO, \
24{ \ 24 .ca_owner = THIS_MODULE, \
25 struct _item *_item = to_##_item(item); \ 25 .show = prefix##cname##_show, \
26 struct _item##_attribute *_item##_attr = \ 26 .store = prefix##cname##_store, \
27 container_of(attr, struct _item##_attribute, attr); \ 27}
28 ssize_t ret = 0; \ 28
29 \ 29#define UVC_ATTR_RO(prefix, cname, aname) \
30 if (_item##_attr->show) \ 30static struct configfs_attribute prefix##attr_##cname = { \
31 ret = _item##_attr->show(_item, page); \ 31 .ca_name = __stringify(aname), \
32 return ret; \ 32 .ca_mode = S_IRUGO, \
33 .ca_owner = THIS_MODULE, \
34 .show = prefix##cname##_show, \
33} 35}
34 36
35static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item); 37static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item);
@@ -48,18 +50,11 @@ static struct uvcg_control_header *to_uvcg_control_header(struct config_item *it
48 return container_of(item, struct uvcg_control_header, item); 50 return container_of(item, struct uvcg_control_header, item);
49} 51}
50 52
51CONFIGFS_ATTR_STRUCT(uvcg_control_header);
52CONFIGFS_ATTR_OPS(uvcg_control_header);
53
54static struct configfs_item_operations uvcg_control_header_item_ops = {
55 .show_attribute = uvcg_control_header_attr_show,
56 .store_attribute = uvcg_control_header_attr_store,
57};
58
59#define UVCG_CTRL_HDR_ATTR(cname, aname, conv, str2u, uxx, vnoc, limit) \ 53#define UVCG_CTRL_HDR_ATTR(cname, aname, conv, str2u, uxx, vnoc, limit) \
60static ssize_t uvcg_control_header_##cname##_show( \ 54static ssize_t uvcg_control_header_##cname##_show( \
61 struct uvcg_control_header *ch, char *page) \ 55 struct config_item *item, char *page) \
62{ \ 56{ \
57 struct uvcg_control_header *ch = to_uvcg_control_header(item); \
63 struct f_uvc_opts *opts; \ 58 struct f_uvc_opts *opts; \
64 struct config_item *opts_item; \ 59 struct config_item *opts_item; \
65 struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\ 60 struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\
@@ -79,9 +74,10 @@ static ssize_t uvcg_control_header_##cname##_show( \
79} \ 74} \
80 \ 75 \
81static ssize_t \ 76static ssize_t \
82uvcg_control_header_##cname##_store(struct uvcg_control_header *ch, \ 77uvcg_control_header_##cname##_store(struct config_item *item, \
83 const char *page, size_t len) \ 78 const char *page, size_t len) \
84{ \ 79{ \
80 struct uvcg_control_header *ch = to_uvcg_control_header(item); \
85 struct f_uvc_opts *opts; \ 81 struct f_uvc_opts *opts; \
86 struct config_item *opts_item; \ 82 struct config_item *opts_item; \
87 struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\ 83 struct mutex *su_mutex = &ch->item.ci_group->cg_subsys->su_mutex;\
@@ -115,11 +111,7 @@ end: \
115 return ret; \ 111 return ret; \
116} \ 112} \
117 \ 113 \
118static struct uvcg_control_header_attribute \ 114UVC_ATTR(uvcg_control_header_, cname, aname)
119 uvcg_control_header_##cname = \
120 __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \
121 uvcg_control_header_##cname##_show, \
122 uvcg_control_header_##cname##_store)
123 115
124UVCG_CTRL_HDR_ATTR(bcd_uvc, bcdUVC, le16_to_cpu, kstrtou16, u16, cpu_to_le16, 116UVCG_CTRL_HDR_ATTR(bcd_uvc, bcdUVC, le16_to_cpu, kstrtou16, u16, cpu_to_le16,
125 0xffff); 117 0xffff);
@@ -130,13 +122,12 @@ UVCG_CTRL_HDR_ATTR(dw_clock_frequency, dwClockFrequency, le32_to_cpu, kstrtou32,
130#undef UVCG_CTRL_HDR_ATTR 122#undef UVCG_CTRL_HDR_ATTR
131 123
132static struct configfs_attribute *uvcg_control_header_attrs[] = { 124static struct configfs_attribute *uvcg_control_header_attrs[] = {
133 &uvcg_control_header_bcd_uvc.attr, 125 &uvcg_control_header_attr_bcd_uvc,
134 &uvcg_control_header_dw_clock_frequency.attr, 126 &uvcg_control_header_attr_dw_clock_frequency,
135 NULL, 127 NULL,
136}; 128};
137 129
138static struct config_item_type uvcg_control_header_type = { 130static struct config_item_type uvcg_control_header_type = {
139 .ct_item_ops = &uvcg_control_header_item_ops,
140 .ct_attrs = uvcg_control_header_attrs, 131 .ct_attrs = uvcg_control_header_attrs,
141 .ct_owner = THIS_MODULE, 132 .ct_owner = THIS_MODULE,
142}; 133};
@@ -196,17 +187,11 @@ static inline struct uvcg_default_processing
196 struct uvcg_default_processing, group); 187 struct uvcg_default_processing, group);
197} 188}
198 189
199CONFIGFS_ATTR_STRUCT(uvcg_default_processing);
200CONFIGFS_ATTR_OPS_RO(uvcg_default_processing);
201
202static struct configfs_item_operations uvcg_default_processing_item_ops = {
203 .show_attribute = uvcg_default_processing_attr_show,
204};
205
206#define UVCG_DEFAULT_PROCESSING_ATTR(cname, aname, conv) \ 190#define UVCG_DEFAULT_PROCESSING_ATTR(cname, aname, conv) \
207static ssize_t uvcg_default_processing_##cname##_show( \ 191static ssize_t uvcg_default_processing_##cname##_show( \
208 struct uvcg_default_processing *dp, char *page) \ 192 struct config_item *item, char *page) \
209{ \ 193{ \
194 struct uvcg_default_processing *dp = to_uvcg_default_processing(item); \
210 struct f_uvc_opts *opts; \ 195 struct f_uvc_opts *opts; \
211 struct config_item *opts_item; \ 196 struct config_item *opts_item; \
212 struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; \ 197 struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; \
@@ -227,9 +212,7 @@ static ssize_t uvcg_default_processing_##cname##_show( \
227 return result; \ 212 return result; \
228} \ 213} \
229 \ 214 \
230static struct uvcg_default_processing_attribute \ 215UVC_ATTR_RO(uvcg_default_processing_, cname, aname)
231 uvcg_default_processing_##cname = \
232 __CONFIGFS_ATTR_RO(aname, uvcg_default_processing_##cname##_show)
233 216
234#define identity_conv(x) (x) 217#define identity_conv(x) (x)
235 218
@@ -243,8 +226,9 @@ UVCG_DEFAULT_PROCESSING_ATTR(i_processing, iProcessing, identity_conv);
243#undef UVCG_DEFAULT_PROCESSING_ATTR 226#undef UVCG_DEFAULT_PROCESSING_ATTR
244 227
245static ssize_t uvcg_default_processing_bm_controls_show( 228static ssize_t uvcg_default_processing_bm_controls_show(
246 struct uvcg_default_processing *dp, char *page) 229 struct config_item *item, char *page)
247{ 230{
231 struct uvcg_default_processing *dp = to_uvcg_default_processing(item);
248 struct f_uvc_opts *opts; 232 struct f_uvc_opts *opts;
249 struct config_item *opts_item; 233 struct config_item *opts_item;
250 struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex; 234 struct mutex *su_mutex = &dp->group.cg_subsys->su_mutex;
@@ -270,22 +254,18 @@ static ssize_t uvcg_default_processing_bm_controls_show(
270 return result; 254 return result;
271} 255}
272 256
273static struct uvcg_default_processing_attribute 257UVC_ATTR_RO(uvcg_default_processing_, bm_controls, bmControls);
274 uvcg_default_processing_bm_controls =
275 __CONFIGFS_ATTR_RO(bmControls,
276 uvcg_default_processing_bm_controls_show);
277 258
278static struct configfs_attribute *uvcg_default_processing_attrs[] = { 259static struct configfs_attribute *uvcg_default_processing_attrs[] = {
279 &uvcg_default_processing_b_unit_id.attr, 260 &uvcg_default_processing_attr_b_unit_id,
280 &uvcg_default_processing_b_source_id.attr, 261 &uvcg_default_processing_attr_b_source_id,
281 &uvcg_default_processing_w_max_multiplier.attr, 262 &uvcg_default_processing_attr_w_max_multiplier,
282 &uvcg_default_processing_bm_controls.attr, 263 &uvcg_default_processing_attr_bm_controls,
283 &uvcg_default_processing_i_processing.attr, 264 &uvcg_default_processing_attr_i_processing,
284 NULL, 265 NULL,
285}; 266};
286 267
287static struct config_item_type uvcg_default_processing_type = { 268static struct config_item_type uvcg_default_processing_type = {
288 .ct_item_ops = &uvcg_default_processing_item_ops,
289 .ct_attrs = uvcg_default_processing_attrs, 269 .ct_attrs = uvcg_default_processing_attrs,
290 .ct_owner = THIS_MODULE, 270 .ct_owner = THIS_MODULE,
291}; 271};
@@ -318,17 +298,11 @@ static inline struct uvcg_default_camera
318 struct uvcg_default_camera, group); 298 struct uvcg_default_camera, group);
319} 299}
320 300
321CONFIGFS_ATTR_STRUCT(uvcg_default_camera);
322CONFIGFS_ATTR_OPS_RO(uvcg_default_camera);
323
324static struct configfs_item_operations uvcg_default_camera_item_ops = {
325 .show_attribute = uvcg_default_camera_attr_show,
326};
327
328#define UVCG_DEFAULT_CAMERA_ATTR(cname, aname, conv) \ 301#define UVCG_DEFAULT_CAMERA_ATTR(cname, aname, conv) \
329static ssize_t uvcg_default_camera_##cname##_show( \ 302static ssize_t uvcg_default_camera_##cname##_show( \
330 struct uvcg_default_camera *dc, char *page) \ 303 struct config_item *item, char *page) \
331{ \ 304{ \
305 struct uvcg_default_camera *dc = to_uvcg_default_camera(item); \
332 struct f_uvc_opts *opts; \ 306 struct f_uvc_opts *opts; \
333 struct config_item *opts_item; \ 307 struct config_item *opts_item; \
334 struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \ 308 struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \
@@ -351,9 +325,7 @@ static ssize_t uvcg_default_camera_##cname##_show( \
351 return result; \ 325 return result; \
352} \ 326} \
353 \ 327 \
354static struct uvcg_default_camera_attribute \ 328UVC_ATTR_RO(uvcg_default_camera_, cname, aname)
355 uvcg_default_camera_##cname = \
356 __CONFIGFS_ATTR_RO(aname, uvcg_default_camera_##cname##_show)
357 329
358#define identity_conv(x) (x) 330#define identity_conv(x) (x)
359 331
@@ -373,8 +345,9 @@ UVCG_DEFAULT_CAMERA_ATTR(w_ocular_focal_length, wOcularFocalLength,
373#undef UVCG_DEFAULT_CAMERA_ATTR 345#undef UVCG_DEFAULT_CAMERA_ATTR
374 346
375static ssize_t uvcg_default_camera_bm_controls_show( 347static ssize_t uvcg_default_camera_bm_controls_show(
376 struct uvcg_default_camera *dc, char *page) 348 struct config_item *item, char *page)
377{ 349{
350 struct uvcg_default_camera *dc = to_uvcg_default_camera(item);
378 struct f_uvc_opts *opts; 351 struct f_uvc_opts *opts;
379 struct config_item *opts_item; 352 struct config_item *opts_item;
380 struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; 353 struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex;
@@ -400,24 +373,21 @@ static ssize_t uvcg_default_camera_bm_controls_show(
400 return result; 373 return result;
401} 374}
402 375
403static struct uvcg_default_camera_attribute 376UVC_ATTR_RO(uvcg_default_camera_, bm_controls, bmControls);
404 uvcg_default_camera_bm_controls =
405 __CONFIGFS_ATTR_RO(bmControls, uvcg_default_camera_bm_controls_show);
406 377
407static struct configfs_attribute *uvcg_default_camera_attrs[] = { 378static struct configfs_attribute *uvcg_default_camera_attrs[] = {
408 &uvcg_default_camera_b_terminal_id.attr, 379 &uvcg_default_camera_attr_b_terminal_id,
409 &uvcg_default_camera_w_terminal_type.attr, 380 &uvcg_default_camera_attr_w_terminal_type,
410 &uvcg_default_camera_b_assoc_terminal.attr, 381 &uvcg_default_camera_attr_b_assoc_terminal,
411 &uvcg_default_camera_i_terminal.attr, 382 &uvcg_default_camera_attr_i_terminal,
412 &uvcg_default_camera_w_objective_focal_length_min.attr, 383 &uvcg_default_camera_attr_w_objective_focal_length_min,
413 &uvcg_default_camera_w_objective_focal_length_max.attr, 384 &uvcg_default_camera_attr_w_objective_focal_length_max,
414 &uvcg_default_camera_w_ocular_focal_length.attr, 385 &uvcg_default_camera_attr_w_ocular_focal_length,
415 &uvcg_default_camera_bm_controls.attr, 386 &uvcg_default_camera_attr_bm_controls,
416 NULL, 387 NULL,
417}; 388};
418 389
419static struct config_item_type uvcg_default_camera_type = { 390static struct config_item_type uvcg_default_camera_type = {
420 .ct_item_ops = &uvcg_default_camera_item_ops,
421 .ct_attrs = uvcg_default_camera_attrs, 391 .ct_attrs = uvcg_default_camera_attrs,
422 .ct_owner = THIS_MODULE, 392 .ct_owner = THIS_MODULE,
423}; 393};
@@ -450,17 +420,11 @@ static inline struct uvcg_default_output
450 struct uvcg_default_output, group); 420 struct uvcg_default_output, group);
451} 421}
452 422
453CONFIGFS_ATTR_STRUCT(uvcg_default_output);
454CONFIGFS_ATTR_OPS_RO(uvcg_default_output);
455
456static struct configfs_item_operations uvcg_default_output_item_ops = {
457 .show_attribute = uvcg_default_output_attr_show,
458};
459
460#define UVCG_DEFAULT_OUTPUT_ATTR(cname, aname, conv) \ 423#define UVCG_DEFAULT_OUTPUT_ATTR(cname, aname, conv) \
461static ssize_t uvcg_default_output_##cname##_show( \ 424static ssize_t uvcg_default_output_##cname##_show( \
462 struct uvcg_default_output *dout, char *page) \ 425 struct config_item *item, char *page) \
463{ \ 426{ \
427 struct uvcg_default_output *dout = to_uvcg_default_output(item); \
464 struct f_uvc_opts *opts; \ 428 struct f_uvc_opts *opts; \
465 struct config_item *opts_item; \ 429 struct config_item *opts_item; \
466 struct mutex *su_mutex = &dout->group.cg_subsys->su_mutex; \ 430 struct mutex *su_mutex = &dout->group.cg_subsys->su_mutex; \
@@ -483,9 +447,7 @@ static ssize_t uvcg_default_output_##cname##_show( \
483 return result; \ 447 return result; \
484} \ 448} \
485 \ 449 \
486static struct uvcg_default_output_attribute \ 450UVC_ATTR_RO(uvcg_default_output_, cname, aname)
487 uvcg_default_output_##cname = \
488 __CONFIGFS_ATTR_RO(aname, uvcg_default_output_##cname##_show)
489 451
490#define identity_conv(x) (x) 452#define identity_conv(x) (x)
491 453
@@ -500,16 +462,15 @@ UVCG_DEFAULT_OUTPUT_ATTR(i_terminal, iTerminal, identity_conv);
500#undef UVCG_DEFAULT_OUTPUT_ATTR 462#undef UVCG_DEFAULT_OUTPUT_ATTR
501 463
502static struct configfs_attribute *uvcg_default_output_attrs[] = { 464static struct configfs_attribute *uvcg_default_output_attrs[] = {
503 &uvcg_default_output_b_terminal_id.attr, 465 &uvcg_default_output_attr_b_terminal_id,
504 &uvcg_default_output_w_terminal_type.attr, 466 &uvcg_default_output_attr_w_terminal_type,
505 &uvcg_default_output_b_assoc_terminal.attr, 467 &uvcg_default_output_attr_b_assoc_terminal,
506 &uvcg_default_output_b_source_id.attr, 468 &uvcg_default_output_attr_b_source_id,
507 &uvcg_default_output_i_terminal.attr, 469 &uvcg_default_output_attr_i_terminal,
508 NULL, 470 NULL,
509}; 471};
510 472
511static struct config_item_type uvcg_default_output_type = { 473static struct config_item_type uvcg_default_output_type = {
512 .ct_item_ops = &uvcg_default_output_item_ops,
513 .ct_attrs = uvcg_default_output_attrs, 474 .ct_attrs = uvcg_default_output_attrs,
514 .ct_owner = THIS_MODULE, 475 .ct_owner = THIS_MODULE,
515}; 476};
@@ -800,9 +761,6 @@ static struct uvcg_streaming_header *to_uvcg_streaming_header(struct config_item
800 return container_of(item, struct uvcg_streaming_header, item); 761 return container_of(item, struct uvcg_streaming_header, item);
801} 762}
802 763
803CONFIGFS_ATTR_STRUCT(uvcg_streaming_header);
804CONFIGFS_ATTR_OPS(uvcg_streaming_header);
805
806static int uvcg_streaming_header_allow_link(struct config_item *src, 764static int uvcg_streaming_header_allow_link(struct config_item *src,
807 struct config_item *target) 765 struct config_item *target)
808{ 766{
@@ -893,16 +851,15 @@ out:
893} 851}
894 852
895static struct configfs_item_operations uvcg_streaming_header_item_ops = { 853static struct configfs_item_operations uvcg_streaming_header_item_ops = {
896 .show_attribute = uvcg_streaming_header_attr_show,
897 .store_attribute = uvcg_streaming_header_attr_store,
898 .allow_link = uvcg_streaming_header_allow_link, 854 .allow_link = uvcg_streaming_header_allow_link,
899 .drop_link = uvcg_streaming_header_drop_link, 855 .drop_link = uvcg_streaming_header_drop_link,
900}; 856};
901 857
902#define UVCG_STREAMING_HEADER_ATTR(cname, aname, conv) \ 858#define UVCG_STREAMING_HEADER_ATTR(cname, aname, conv) \
903static ssize_t uvcg_streaming_header_##cname##_show( \ 859static ssize_t uvcg_streaming_header_##cname##_show( \
904 struct uvcg_streaming_header *sh, char *page) \ 860 struct config_item *item, char *page) \
905{ \ 861{ \
862 struct uvcg_streaming_header *sh = to_uvcg_streaming_header(item); \
906 struct f_uvc_opts *opts; \ 863 struct f_uvc_opts *opts; \
907 struct config_item *opts_item; \ 864 struct config_item *opts_item; \
908 struct mutex *su_mutex = &sh->item.ci_group->cg_subsys->su_mutex;\ 865 struct mutex *su_mutex = &sh->item.ci_group->cg_subsys->su_mutex;\
@@ -921,9 +878,7 @@ static ssize_t uvcg_streaming_header_##cname##_show( \
921 return result; \ 878 return result; \
922} \ 879} \
923 \ 880 \
924static struct uvcg_streaming_header_attribute \ 881UVC_ATTR_RO(uvcg_streaming_header_, cname, aname)
925 uvcg_streaming_header_##cname = \
926 __CONFIGFS_ATTR_RO(aname, uvcg_streaming_header_##cname##_show)
927 882
928#define identity_conv(x) (x) 883#define identity_conv(x) (x)
929 884
@@ -939,11 +894,11 @@ UVCG_STREAMING_HEADER_ATTR(b_trigger_usage, bTriggerUsage, identity_conv);
939#undef UVCG_STREAMING_HEADER_ATTR 894#undef UVCG_STREAMING_HEADER_ATTR
940 895
941static struct configfs_attribute *uvcg_streaming_header_attrs[] = { 896static struct configfs_attribute *uvcg_streaming_header_attrs[] = {
942 &uvcg_streaming_header_bm_info.attr, 897 &uvcg_streaming_header_attr_bm_info,
943 &uvcg_streaming_header_b_terminal_link.attr, 898 &uvcg_streaming_header_attr_b_terminal_link,
944 &uvcg_streaming_header_b_still_capture_method.attr, 899 &uvcg_streaming_header_attr_b_still_capture_method,
945 &uvcg_streaming_header_b_trigger_support.attr, 900 &uvcg_streaming_header_attr_b_trigger_support,
946 &uvcg_streaming_header_b_trigger_usage.attr, 901 &uvcg_streaming_header_attr_b_trigger_usage,
947 NULL, 902 NULL,
948}; 903};
949 904
@@ -1022,17 +977,10 @@ static struct uvcg_frame *to_uvcg_frame(struct config_item *item)
1022 return container_of(item, struct uvcg_frame, item); 977 return container_of(item, struct uvcg_frame, item);
1023} 978}
1024 979
1025CONFIGFS_ATTR_STRUCT(uvcg_frame);
1026CONFIGFS_ATTR_OPS(uvcg_frame);
1027
1028static struct configfs_item_operations uvcg_frame_item_ops = {
1029 .show_attribute = uvcg_frame_attr_show,
1030 .store_attribute = uvcg_frame_attr_store,
1031};
1032
1033#define UVCG_FRAME_ATTR(cname, aname, to_cpu_endian, to_little_endian, bits) \ 980#define UVCG_FRAME_ATTR(cname, aname, to_cpu_endian, to_little_endian, bits) \
1034static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\ 981static ssize_t uvcg_frame_##cname##_show(struct config_item *item, char *page)\
1035{ \ 982{ \
983 struct uvcg_frame *f = to_uvcg_frame(item); \
1036 struct f_uvc_opts *opts; \ 984 struct f_uvc_opts *opts; \
1037 struct config_item *opts_item; \ 985 struct config_item *opts_item; \
1038 struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\ 986 struct mutex *su_mutex = &f->item.ci_group->cg_subsys->su_mutex;\
@@ -1051,9 +999,10 @@ static ssize_t uvcg_frame_##cname##_show(struct uvcg_frame *f, char *page)\
1051 return result; \ 999 return result; \
1052} \ 1000} \
1053 \ 1001 \
1054static ssize_t uvcg_frame_##cname##_store(struct uvcg_frame *f, \ 1002static ssize_t uvcg_frame_##cname##_store(struct config_item *item, \
1055 const char *page, size_t len)\ 1003 const char *page, size_t len)\
1056{ \ 1004{ \
1005 struct uvcg_frame *f = to_uvcg_frame(item); \
1057 struct f_uvc_opts *opts; \ 1006 struct f_uvc_opts *opts; \
1058 struct config_item *opts_item; \ 1007 struct config_item *opts_item; \
1059 struct uvcg_format *fmt; \ 1008 struct uvcg_format *fmt; \
@@ -1085,11 +1034,7 @@ end: \
1085 return ret; \ 1034 return ret; \
1086} \ 1035} \
1087 \ 1036 \
1088static struct uvcg_frame_attribute \ 1037UVC_ATTR(uvcg_frame_, cname, aname);
1089 uvcg_frame_##cname = \
1090 __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \
1091 uvcg_frame_##cname##_show, \
1092 uvcg_frame_##cname##_store)
1093 1038
1094#define noop_conversion(x) (x) 1039#define noop_conversion(x) (x)
1095 1040
@@ -1108,9 +1053,10 @@ UVCG_FRAME_ATTR(dw_default_frame_interval, dwDefaultFrameInterval,
1108 1053
1109#undef UVCG_FRAME_ATTR 1054#undef UVCG_FRAME_ATTR
1110 1055
1111static ssize_t uvcg_frame_dw_frame_interval_show(struct uvcg_frame *frm, 1056static ssize_t uvcg_frame_dw_frame_interval_show(struct config_item *item,
1112 char *page) 1057 char *page)
1113{ 1058{
1059 struct uvcg_frame *frm = to_uvcg_frame(item);
1114 struct f_uvc_opts *opts; 1060 struct f_uvc_opts *opts;
1115 struct config_item *opts_item; 1061 struct config_item *opts_item;
1116 struct mutex *su_mutex = &frm->item.ci_group->cg_subsys->su_mutex; 1062 struct mutex *su_mutex = &frm->item.ci_group->cg_subsys->su_mutex;
@@ -1185,9 +1131,10 @@ static int __uvcg_iter_frm_intrv(const char *page, size_t len,
1185 return 0; 1131 return 0;
1186} 1132}
1187 1133
1188static ssize_t uvcg_frame_dw_frame_interval_store(struct uvcg_frame *ch, 1134static ssize_t uvcg_frame_dw_frame_interval_store(struct config_item *item,
1189 const char *page, size_t len) 1135 const char *page, size_t len)
1190{ 1136{
1137 struct uvcg_frame *ch = to_uvcg_frame(item);
1191 struct f_uvc_opts *opts; 1138 struct f_uvc_opts *opts;
1192 struct config_item *opts_item; 1139 struct config_item *opts_item;
1193 struct uvcg_format *fmt; 1140 struct uvcg_format *fmt;
@@ -1234,26 +1181,21 @@ end:
1234 return ret; 1181 return ret;
1235} 1182}
1236 1183
1237static struct uvcg_frame_attribute 1184UVC_ATTR(uvcg_frame_, dw_frame_interval, dwFrameInterval);
1238 uvcg_frame_dw_frame_interval =
1239 __CONFIGFS_ATTR(dwFrameInterval, S_IRUGO | S_IWUSR,
1240 uvcg_frame_dw_frame_interval_show,
1241 uvcg_frame_dw_frame_interval_store);
1242 1185
1243static struct configfs_attribute *uvcg_frame_attrs[] = { 1186static struct configfs_attribute *uvcg_frame_attrs[] = {
1244 &uvcg_frame_bm_capabilities.attr, 1187 &uvcg_frame_attr_bm_capabilities,
1245 &uvcg_frame_w_width.attr, 1188 &uvcg_frame_attr_w_width,
1246 &uvcg_frame_w_height.attr, 1189 &uvcg_frame_attr_w_height,
1247 &uvcg_frame_dw_min_bit_rate.attr, 1190 &uvcg_frame_attr_dw_min_bit_rate,
1248 &uvcg_frame_dw_max_bit_rate.attr, 1191 &uvcg_frame_attr_dw_max_bit_rate,
1249 &uvcg_frame_dw_max_video_frame_buffer_size.attr, 1192 &uvcg_frame_attr_dw_max_video_frame_buffer_size,
1250 &uvcg_frame_dw_default_frame_interval.attr, 1193 &uvcg_frame_attr_dw_default_frame_interval,
1251 &uvcg_frame_dw_frame_interval.attr, 1194 &uvcg_frame_attr_dw_frame_interval,
1252 NULL, 1195 NULL,
1253}; 1196};
1254 1197
1255static struct config_item_type uvcg_frame_type = { 1198static struct config_item_type uvcg_frame_type = {
1256 .ct_item_ops = &uvcg_frame_item_ops,
1257 .ct_attrs = uvcg_frame_attrs, 1199 .ct_attrs = uvcg_frame_attrs,
1258 .ct_owner = THIS_MODULE, 1200 .ct_owner = THIS_MODULE,
1259}; 1201};
@@ -1333,22 +1275,15 @@ static struct uvcg_uncompressed *to_uvcg_uncompressed(struct config_item *item)
1333 struct uvcg_uncompressed, fmt); 1275 struct uvcg_uncompressed, fmt);
1334} 1276}
1335 1277
1336CONFIGFS_ATTR_STRUCT(uvcg_uncompressed);
1337CONFIGFS_ATTR_OPS(uvcg_uncompressed);
1338
1339static struct configfs_item_operations uvcg_uncompressed_item_ops = {
1340 .show_attribute = uvcg_uncompressed_attr_show,
1341 .store_attribute = uvcg_uncompressed_attr_store,
1342};
1343
1344static struct configfs_group_operations uvcg_uncompressed_group_ops = { 1278static struct configfs_group_operations uvcg_uncompressed_group_ops = {
1345 .make_item = uvcg_frame_make, 1279 .make_item = uvcg_frame_make,
1346 .drop_item = uvcg_frame_drop, 1280 .drop_item = uvcg_frame_drop,
1347}; 1281};
1348 1282
1349static ssize_t uvcg_uncompressed_guid_format_show(struct uvcg_uncompressed *ch, 1283static ssize_t uvcg_uncompressed_guid_format_show(struct config_item *item,
1350 char *page) 1284 char *page)
1351{ 1285{
1286 struct uvcg_uncompressed *ch = to_uvcg_uncompressed(item);
1352 struct f_uvc_opts *opts; 1287 struct f_uvc_opts *opts;
1353 struct config_item *opts_item; 1288 struct config_item *opts_item;
1354 struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex; 1289 struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex;
@@ -1367,9 +1302,10 @@ static ssize_t uvcg_uncompressed_guid_format_show(struct uvcg_uncompressed *ch,
1367 return sizeof(ch->desc.guidFormat); 1302 return sizeof(ch->desc.guidFormat);
1368} 1303}
1369 1304
1370static ssize_t uvcg_uncompressed_guid_format_store(struct uvcg_uncompressed *ch, 1305static ssize_t uvcg_uncompressed_guid_format_store(struct config_item *item,
1371 const char *page, size_t len) 1306 const char *page, size_t len)
1372{ 1307{
1308 struct uvcg_uncompressed *ch = to_uvcg_uncompressed(item);
1373 struct f_uvc_opts *opts; 1309 struct f_uvc_opts *opts;
1374 struct config_item *opts_item; 1310 struct config_item *opts_item;
1375 struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex; 1311 struct mutex *su_mutex = &ch->fmt.group.cg_subsys->su_mutex;
@@ -1396,16 +1332,13 @@ end:
1396 return ret; 1332 return ret;
1397} 1333}
1398 1334
1399static struct uvcg_uncompressed_attribute uvcg_uncompressed_guid_format = 1335UVC_ATTR(uvcg_uncompressed_, guid_format, guidFormat);
1400 __CONFIGFS_ATTR(guidFormat, S_IRUGO | S_IWUSR,
1401 uvcg_uncompressed_guid_format_show,
1402 uvcg_uncompressed_guid_format_store);
1403
1404 1336
1405#define UVCG_UNCOMPRESSED_ATTR_RO(cname, aname, conv) \ 1337#define UVCG_UNCOMPRESSED_ATTR_RO(cname, aname, conv) \
1406static ssize_t uvcg_uncompressed_##cname##_show( \ 1338static ssize_t uvcg_uncompressed_##cname##_show( \
1407 struct uvcg_uncompressed *u, char *page) \ 1339 struct config_item *item, char *page) \
1408{ \ 1340{ \
1341 struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \
1409 struct f_uvc_opts *opts; \ 1342 struct f_uvc_opts *opts; \
1410 struct config_item *opts_item; \ 1343 struct config_item *opts_item; \
1411 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \ 1344 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1424,14 +1357,13 @@ static ssize_t uvcg_uncompressed_##cname##_show( \
1424 return result; \ 1357 return result; \
1425} \ 1358} \
1426 \ 1359 \
1427static struct uvcg_uncompressed_attribute \ 1360UVC_ATTR_RO(uvcg_uncompressed_, cname, aname);
1428 uvcg_uncompressed_##cname = \
1429 __CONFIGFS_ATTR_RO(aname, uvcg_uncompressed_##cname##_show)
1430 1361
1431#define UVCG_UNCOMPRESSED_ATTR(cname, aname, conv) \ 1362#define UVCG_UNCOMPRESSED_ATTR(cname, aname, conv) \
1432static ssize_t uvcg_uncompressed_##cname##_show( \ 1363static ssize_t uvcg_uncompressed_##cname##_show( \
1433 struct uvcg_uncompressed *u, char *page) \ 1364 struct config_item *item, char *page) \
1434{ \ 1365{ \
1366 struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \
1435 struct f_uvc_opts *opts; \ 1367 struct f_uvc_opts *opts; \
1436 struct config_item *opts_item; \ 1368 struct config_item *opts_item; \
1437 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \ 1369 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1451,9 +1383,10 @@ static ssize_t uvcg_uncompressed_##cname##_show( \
1451} \ 1383} \
1452 \ 1384 \
1453static ssize_t \ 1385static ssize_t \
1454uvcg_uncompressed_##cname##_store(struct uvcg_uncompressed *u, \ 1386uvcg_uncompressed_##cname##_store(struct config_item *item, \
1455 const char *page, size_t len) \ 1387 const char *page, size_t len) \
1456{ \ 1388{ \
1389 struct uvcg_uncompressed *u = to_uvcg_uncompressed(item); \
1457 struct f_uvc_opts *opts; \ 1390 struct f_uvc_opts *opts; \
1458 struct config_item *opts_item; \ 1391 struct config_item *opts_item; \
1459 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \ 1392 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1487,11 +1420,7 @@ end: \
1487 return ret; \ 1420 return ret; \
1488} \ 1421} \
1489 \ 1422 \
1490static struct uvcg_uncompressed_attribute \ 1423UVC_ATTR(uvcg_uncompressed_, cname, aname);
1491 uvcg_uncompressed_##cname = \
1492 __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \
1493 uvcg_uncompressed_##cname##_show, \
1494 uvcg_uncompressed_##cname##_store)
1495 1424
1496#define identity_conv(x) (x) 1425#define identity_conv(x) (x)
1497 1426
@@ -1508,36 +1437,34 @@ UVCG_UNCOMPRESSED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, identity_conv);
1508#undef UVCG_UNCOMPRESSED_ATTR_RO 1437#undef UVCG_UNCOMPRESSED_ATTR_RO
1509 1438
1510static inline ssize_t 1439static inline ssize_t
1511uvcg_uncompressed_bma_controls_show(struct uvcg_uncompressed *unc, char *page) 1440uvcg_uncompressed_bma_controls_show(struct config_item *item, char *page)
1512{ 1441{
1442 struct uvcg_uncompressed *unc = to_uvcg_uncompressed(item);
1513 return uvcg_format_bma_controls_show(&unc->fmt, page); 1443 return uvcg_format_bma_controls_show(&unc->fmt, page);
1514} 1444}
1515 1445
1516static inline ssize_t 1446static inline ssize_t
1517uvcg_uncompressed_bma_controls_store(struct uvcg_uncompressed *ch, 1447uvcg_uncompressed_bma_controls_store(struct config_item *item,
1518 const char *page, size_t len) 1448 const char *page, size_t len)
1519{ 1449{
1520 return uvcg_format_bma_controls_store(&ch->fmt, page, len); 1450 struct uvcg_uncompressed *unc = to_uvcg_uncompressed(item);
1451 return uvcg_format_bma_controls_store(&unc->fmt, page, len);
1521} 1452}
1522 1453
1523static struct uvcg_uncompressed_attribute uvcg_uncompressed_bma_controls = 1454UVC_ATTR(uvcg_uncompressed_, bma_controls, bmaControls);
1524 __CONFIGFS_ATTR(bmaControls, S_IRUGO | S_IWUSR,
1525 uvcg_uncompressed_bma_controls_show,
1526 uvcg_uncompressed_bma_controls_store);
1527 1455
1528static struct configfs_attribute *uvcg_uncompressed_attrs[] = { 1456static struct configfs_attribute *uvcg_uncompressed_attrs[] = {
1529 &uvcg_uncompressed_guid_format.attr, 1457 &uvcg_uncompressed_attr_guid_format,
1530 &uvcg_uncompressed_b_bits_per_pixel.attr, 1458 &uvcg_uncompressed_attr_b_bits_per_pixel,
1531 &uvcg_uncompressed_b_default_frame_index.attr, 1459 &uvcg_uncompressed_attr_b_default_frame_index,
1532 &uvcg_uncompressed_b_aspect_ratio_x.attr, 1460 &uvcg_uncompressed_attr_b_aspect_ratio_x,
1533 &uvcg_uncompressed_b_aspect_ratio_y.attr, 1461 &uvcg_uncompressed_attr_b_aspect_ratio_y,
1534 &uvcg_uncompressed_bm_interface_flags.attr, 1462 &uvcg_uncompressed_attr_bm_interface_flags,
1535 &uvcg_uncompressed_bma_controls.attr, 1463 &uvcg_uncompressed_attr_bma_controls,
1536 NULL, 1464 NULL,
1537}; 1465};
1538 1466
1539static struct config_item_type uvcg_uncompressed_type = { 1467static struct config_item_type uvcg_uncompressed_type = {
1540 .ct_item_ops = &uvcg_uncompressed_item_ops,
1541 .ct_group_ops = &uvcg_uncompressed_group_ops, 1468 .ct_group_ops = &uvcg_uncompressed_group_ops,
1542 .ct_attrs = uvcg_uncompressed_attrs, 1469 .ct_attrs = uvcg_uncompressed_attrs,
1543 .ct_owner = THIS_MODULE, 1470 .ct_owner = THIS_MODULE,
@@ -1605,22 +1532,15 @@ static struct uvcg_mjpeg *to_uvcg_mjpeg(struct config_item *item)
1605 struct uvcg_mjpeg, fmt); 1532 struct uvcg_mjpeg, fmt);
1606} 1533}
1607 1534
1608CONFIGFS_ATTR_STRUCT(uvcg_mjpeg);
1609CONFIGFS_ATTR_OPS(uvcg_mjpeg);
1610
1611static struct configfs_item_operations uvcg_mjpeg_item_ops = {
1612 .show_attribute = uvcg_mjpeg_attr_show,
1613 .store_attribute = uvcg_mjpeg_attr_store,
1614};
1615
1616static struct configfs_group_operations uvcg_mjpeg_group_ops = { 1535static struct configfs_group_operations uvcg_mjpeg_group_ops = {
1617 .make_item = uvcg_frame_make, 1536 .make_item = uvcg_frame_make,
1618 .drop_item = uvcg_frame_drop, 1537 .drop_item = uvcg_frame_drop,
1619}; 1538};
1620 1539
1621#define UVCG_MJPEG_ATTR_RO(cname, aname, conv) \ 1540#define UVCG_MJPEG_ATTR_RO(cname, aname, conv) \
1622static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ 1541static ssize_t uvcg_mjpeg_##cname##_show(struct config_item *item, char *page)\
1623{ \ 1542{ \
1543 struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \
1624 struct f_uvc_opts *opts; \ 1544 struct f_uvc_opts *opts; \
1625 struct config_item *opts_item; \ 1545 struct config_item *opts_item; \
1626 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \ 1546 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1639,13 +1559,12 @@ static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\
1639 return result; \ 1559 return result; \
1640} \ 1560} \
1641 \ 1561 \
1642static struct uvcg_mjpeg_attribute \ 1562UVC_ATTR_RO(uvcg_mjpeg_, cname, aname)
1643 uvcg_mjpeg_##cname = \
1644 __CONFIGFS_ATTR_RO(aname, uvcg_mjpeg_##cname##_show)
1645 1563
1646#define UVCG_MJPEG_ATTR(cname, aname, conv) \ 1564#define UVCG_MJPEG_ATTR(cname, aname, conv) \
1647static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\ 1565static ssize_t uvcg_mjpeg_##cname##_show(struct config_item *item, char *page)\
1648{ \ 1566{ \
1567 struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \
1649 struct f_uvc_opts *opts; \ 1568 struct f_uvc_opts *opts; \
1650 struct config_item *opts_item; \ 1569 struct config_item *opts_item; \
1651 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \ 1570 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1665,9 +1584,10 @@ static ssize_t uvcg_mjpeg_##cname##_show(struct uvcg_mjpeg *u, char *page)\
1665} \ 1584} \
1666 \ 1585 \
1667static ssize_t \ 1586static ssize_t \
1668uvcg_mjpeg_##cname##_store(struct uvcg_mjpeg *u, \ 1587uvcg_mjpeg_##cname##_store(struct config_item *item, \
1669 const char *page, size_t len) \ 1588 const char *page, size_t len) \
1670{ \ 1589{ \
1590 struct uvcg_mjpeg *u = to_uvcg_mjpeg(item); \
1671 struct f_uvc_opts *opts; \ 1591 struct f_uvc_opts *opts; \
1672 struct config_item *opts_item; \ 1592 struct config_item *opts_item; \
1673 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \ 1593 struct mutex *su_mutex = &u->fmt.group.cg_subsys->su_mutex; \
@@ -1701,11 +1621,7 @@ end: \
1701 return ret; \ 1621 return ret; \
1702} \ 1622} \
1703 \ 1623 \
1704static struct uvcg_mjpeg_attribute \ 1624UVC_ATTR(uvcg_mjpeg_, cname, aname)
1705 uvcg_mjpeg_##cname = \
1706 __CONFIGFS_ATTR(aname, S_IRUGO | S_IWUSR, \
1707 uvcg_mjpeg_##cname##_show, \
1708 uvcg_mjpeg_##cname##_store)
1709 1625
1710#define identity_conv(x) (x) 1626#define identity_conv(x) (x)
1711 1627
@@ -1722,35 +1638,33 @@ UVCG_MJPEG_ATTR_RO(bm_interface_flags, bmInterfaceFlags, identity_conv);
1722#undef UVCG_MJPEG_ATTR_RO 1638#undef UVCG_MJPEG_ATTR_RO
1723 1639
1724static inline ssize_t 1640static inline ssize_t
1725uvcg_mjpeg_bma_controls_show(struct uvcg_mjpeg *unc, char *page) 1641uvcg_mjpeg_bma_controls_show(struct config_item *item, char *page)
1726{ 1642{
1727 return uvcg_format_bma_controls_show(&unc->fmt, page); 1643 struct uvcg_mjpeg *u = to_uvcg_mjpeg(item);
1644 return uvcg_format_bma_controls_show(&u->fmt, page);
1728} 1645}
1729 1646
1730static inline ssize_t 1647static inline ssize_t
1731uvcg_mjpeg_bma_controls_store(struct uvcg_mjpeg *ch, 1648uvcg_mjpeg_bma_controls_store(struct config_item *item,
1732 const char *page, size_t len) 1649 const char *page, size_t len)
1733{ 1650{
1734 return uvcg_format_bma_controls_store(&ch->fmt, page, len); 1651 struct uvcg_mjpeg *u = to_uvcg_mjpeg(item);
1652 return uvcg_format_bma_controls_store(&u->fmt, page, len);
1735} 1653}
1736 1654
1737static struct uvcg_mjpeg_attribute uvcg_mjpeg_bma_controls = 1655UVC_ATTR(uvcg_mjpeg_, bma_controls, bmaControls);
1738 __CONFIGFS_ATTR(bmaControls, S_IRUGO | S_IWUSR,
1739 uvcg_mjpeg_bma_controls_show,
1740 uvcg_mjpeg_bma_controls_store);
1741 1656
1742static struct configfs_attribute *uvcg_mjpeg_attrs[] = { 1657static struct configfs_attribute *uvcg_mjpeg_attrs[] = {
1743 &uvcg_mjpeg_b_default_frame_index.attr, 1658 &uvcg_mjpeg_attr_b_default_frame_index,
1744 &uvcg_mjpeg_bm_flags.attr, 1659 &uvcg_mjpeg_attr_bm_flags,
1745 &uvcg_mjpeg_b_aspect_ratio_x.attr, 1660 &uvcg_mjpeg_attr_b_aspect_ratio_x,
1746 &uvcg_mjpeg_b_aspect_ratio_y.attr, 1661 &uvcg_mjpeg_attr_b_aspect_ratio_y,
1747 &uvcg_mjpeg_bm_interface_flags.attr, 1662 &uvcg_mjpeg_attr_bm_interface_flags,
1748 &uvcg_mjpeg_bma_controls.attr, 1663 &uvcg_mjpeg_attr_bma_controls,
1749 NULL, 1664 NULL,
1750}; 1665};
1751 1666
1752static struct config_item_type uvcg_mjpeg_type = { 1667static struct config_item_type uvcg_mjpeg_type = {
1753 .ct_item_ops = &uvcg_mjpeg_item_ops,
1754 .ct_group_ops = &uvcg_mjpeg_group_ops, 1668 .ct_group_ops = &uvcg_mjpeg_group_ops,
1755 .ct_attrs = uvcg_mjpeg_attrs, 1669 .ct_attrs = uvcg_mjpeg_attrs,
1756 .ct_owner = THIS_MODULE, 1670 .ct_owner = THIS_MODULE,
@@ -1811,17 +1725,12 @@ static inline struct uvcg_default_color_matching
1811 struct uvcg_default_color_matching, group); 1725 struct uvcg_default_color_matching, group);
1812} 1726}
1813 1727
1814CONFIGFS_ATTR_STRUCT(uvcg_default_color_matching);
1815CONFIGFS_ATTR_OPS_RO(uvcg_default_color_matching);
1816
1817static struct configfs_item_operations uvcg_default_color_matching_item_ops = {
1818 .show_attribute = uvcg_default_color_matching_attr_show,
1819};
1820
1821#define UVCG_DEFAULT_COLOR_MATCHING_ATTR(cname, aname, conv) \ 1728#define UVCG_DEFAULT_COLOR_MATCHING_ATTR(cname, aname, conv) \
1822static ssize_t uvcg_default_color_matching_##cname##_show( \ 1729static ssize_t uvcg_default_color_matching_##cname##_show( \
1823 struct uvcg_default_color_matching *dc, char *page) \ 1730 struct config_item *item, char *page) \
1824{ \ 1731{ \
1732 struct uvcg_default_color_matching *dc = \
1733 to_uvcg_default_color_matching(item); \
1825 struct f_uvc_opts *opts; \ 1734 struct f_uvc_opts *opts; \
1826 struct config_item *opts_item; \ 1735 struct config_item *opts_item; \
1827 struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \ 1736 struct mutex *su_mutex = &dc->group.cg_subsys->su_mutex; \
@@ -1842,9 +1751,7 @@ static ssize_t uvcg_default_color_matching_##cname##_show( \
1842 return result; \ 1751 return result; \
1843} \ 1752} \
1844 \ 1753 \
1845static struct uvcg_default_color_matching_attribute \ 1754UVC_ATTR_RO(uvcg_default_color_matching_, cname, aname)
1846 uvcg_default_color_matching_##cname = \
1847 __CONFIGFS_ATTR_RO(aname, uvcg_default_color_matching_##cname##_show)
1848 1755
1849#define identity_conv(x) (x) 1756#define identity_conv(x) (x)
1850 1757
@@ -1860,14 +1767,13 @@ UVCG_DEFAULT_COLOR_MATCHING_ATTR(b_matrix_coefficients, bMatrixCoefficients,
1860#undef UVCG_DEFAULT_COLOR_MATCHING_ATTR 1767#undef UVCG_DEFAULT_COLOR_MATCHING_ATTR
1861 1768
1862static struct configfs_attribute *uvcg_default_color_matching_attrs[] = { 1769static struct configfs_attribute *uvcg_default_color_matching_attrs[] = {
1863 &uvcg_default_color_matching_b_color_primaries.attr, 1770 &uvcg_default_color_matching_attr_b_color_primaries,
1864 &uvcg_default_color_matching_b_transfer_characteristics.attr, 1771 &uvcg_default_color_matching_attr_b_transfer_characteristics,
1865 &uvcg_default_color_matching_b_matrix_coefficients.attr, 1772 &uvcg_default_color_matching_attr_b_matrix_coefficients,
1866 NULL, 1773 NULL,
1867}; 1774};
1868 1775
1869static struct config_item_type uvcg_default_color_matching_type = { 1776static struct config_item_type uvcg_default_color_matching_type = {
1870 .ct_item_ops = &uvcg_default_color_matching_item_ops,
1871 .ct_attrs = uvcg_default_color_matching_attrs, 1777 .ct_attrs = uvcg_default_color_matching_attrs,
1872 .ct_owner = THIS_MODULE, 1778 .ct_owner = THIS_MODULE,
1873}; 1779};
@@ -2285,9 +2191,6 @@ static inline struct f_uvc_opts *to_f_uvc_opts(struct config_item *item)
2285 func_inst.group); 2191 func_inst.group);
2286} 2192}
2287 2193
2288CONFIGFS_ATTR_STRUCT(f_uvc_opts);
2289CONFIGFS_ATTR_OPS(f_uvc_opts);
2290
2291static void uvc_attr_release(struct config_item *item) 2194static void uvc_attr_release(struct config_item *item)
2292{ 2195{
2293 struct f_uvc_opts *opts = to_f_uvc_opts(item); 2196 struct f_uvc_opts *opts = to_f_uvc_opts(item);
@@ -2297,14 +2200,13 @@ static void uvc_attr_release(struct config_item *item)
2297 2200
2298static struct configfs_item_operations uvc_item_ops = { 2201static struct configfs_item_operations uvc_item_ops = {
2299 .release = uvc_attr_release, 2202 .release = uvc_attr_release,
2300 .show_attribute = f_uvc_opts_attr_show,
2301 .store_attribute = f_uvc_opts_attr_store,
2302}; 2203};
2303 2204
2304#define UVCG_OPTS_ATTR(cname, conv, str2u, uxx, vnoc, limit) \ 2205#define UVCG_OPTS_ATTR(cname, conv, str2u, uxx, vnoc, limit) \
2305static ssize_t f_uvc_opts_##cname##_show( \ 2206static ssize_t f_uvc_opts_##cname##_show( \
2306 struct f_uvc_opts *opts, char *page) \ 2207 struct config_item *item, char *page) \
2307{ \ 2208{ \
2209 struct f_uvc_opts *opts = to_f_uvc_opts(item); \
2308 int result; \ 2210 int result; \
2309 \ 2211 \
2310 mutex_lock(&opts->lock); \ 2212 mutex_lock(&opts->lock); \
@@ -2315,9 +2217,10 @@ static ssize_t f_uvc_opts_##cname##_show( \
2315} \ 2217} \
2316 \ 2218 \
2317static ssize_t \ 2219static ssize_t \
2318f_uvc_opts_##cname##_store(struct f_uvc_opts *opts, \ 2220f_uvc_opts_##cname##_store(struct config_item *item, \
2319 const char *page, size_t len) \ 2221 const char *page, size_t len) \
2320{ \ 2222{ \
2223 struct f_uvc_opts *opts = to_f_uvc_opts(item); \
2321 int ret; \ 2224 int ret; \
2322 uxx num; \ 2225 uxx num; \
2323 \ 2226 \
@@ -2342,11 +2245,7 @@ end: \
2342 return ret; \ 2245 return ret; \
2343} \ 2246} \
2344 \ 2247 \
2345static struct f_uvc_opts_attribute \ 2248UVC_ATTR(f_uvc_opts_, cname, aname)
2346 f_uvc_opts_attribute_##cname = \
2347 __CONFIGFS_ATTR(cname, S_IRUGO | S_IWUSR, \
2348 f_uvc_opts_##cname##_show, \
2349 f_uvc_opts_##cname##_store)
2350 2249
2351#define identity_conv(x) (x) 2250#define identity_conv(x) (x)
2352 2251
@@ -2362,9 +2261,9 @@ UVCG_OPTS_ATTR(streaming_maxburst, identity_conv, kstrtou8, u8, identity_conv,
2362#undef UVCG_OPTS_ATTR 2261#undef UVCG_OPTS_ATTR
2363 2262
2364static struct configfs_attribute *uvc_attrs[] = { 2263static struct configfs_attribute *uvc_attrs[] = {
2365 &f_uvc_opts_attribute_streaming_interval.attr, 2264 &f_uvc_opts_attr_streaming_interval,
2366 &f_uvc_opts_attribute_streaming_maxpacket.attr, 2265 &f_uvc_opts_attr_streaming_maxpacket,
2367 &f_uvc_opts_attribute_streaming_maxburst.attr, 2266 &f_uvc_opts_attr_streaming_maxburst,
2368 NULL, 2267 NULL,
2369}; 2268};
2370 2269
diff --git a/drivers/usb/gadget/legacy/tcm_usb_gadget.c b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
index 778e42abb3cb..22e56158d585 100644
--- a/drivers/usb/gadget/legacy/tcm_usb_gadget.c
+++ b/drivers/usb/gadget/legacy/tcm_usb_gadget.c
@@ -19,8 +19,6 @@
19#include <scsi/scsi_tcq.h> 19#include <scsi/scsi_tcq.h>
20#include <target/target_core_base.h> 20#include <target/target_core_base.h>
21#include <target/target_core_fabric.h> 21#include <target/target_core_fabric.h>
22#include <target/target_core_fabric_configfs.h>
23#include <target/configfs_macros.h>
24#include <asm/unaligned.h> 22#include <asm/unaligned.h>
25 23
26#include "tcm_usb_gadget.h" 24#include "tcm_usb_gadget.h"
@@ -1467,23 +1465,21 @@ static void usbg_drop_tport(struct se_wwn *wwn)
1467/* 1465/*
1468 * If somebody feels like dropping the version property, go ahead. 1466 * If somebody feels like dropping the version property, go ahead.
1469 */ 1467 */
1470static ssize_t usbg_wwn_show_attr_version( 1468static ssize_t usbg_wwn_version_show(struct config_item *item, char *page)
1471 struct target_fabric_configfs *tf,
1472 char *page)
1473{ 1469{
1474 return sprintf(page, "usb-gadget fabric module\n"); 1470 return sprintf(page, "usb-gadget fabric module\n");
1475} 1471}
1476TF_WWN_ATTR_RO(usbg, version); 1472
1473CONFIGFS_ATTR_RO(usbg_wwn_, version);
1477 1474
1478static struct configfs_attribute *usbg_wwn_attrs[] = { 1475static struct configfs_attribute *usbg_wwn_attrs[] = {
1479 &usbg_wwn_version.attr, 1476 &usbg_wwn_attr_version,
1480 NULL, 1477 NULL,
1481}; 1478};
1482 1479
1483static ssize_t tcm_usbg_tpg_show_enable( 1480static ssize_t tcm_usbg_tpg_enable_show(struct config_item *item, char *page)
1484 struct se_portal_group *se_tpg,
1485 char *page)
1486{ 1481{
1482 struct se_portal_group *se_tpg = to_tpg(item);
1487 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); 1483 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
1488 1484
1489 return snprintf(page, PAGE_SIZE, "%u\n", tpg->gadget_connect); 1485 return snprintf(page, PAGE_SIZE, "%u\n", tpg->gadget_connect);
@@ -1492,11 +1488,10 @@ static ssize_t tcm_usbg_tpg_show_enable(
1492static int usbg_attach(struct usbg_tpg *); 1488static int usbg_attach(struct usbg_tpg *);
1493static void usbg_detach(struct usbg_tpg *); 1489static void usbg_detach(struct usbg_tpg *);
1494 1490
1495static ssize_t tcm_usbg_tpg_store_enable( 1491static ssize_t tcm_usbg_tpg_enable_store(struct config_item *item,
1496 struct se_portal_group *se_tpg, 1492 const char *page, size_t count)
1497 const char *page,
1498 size_t count)
1499{ 1493{
1494 struct se_portal_group *se_tpg = to_tpg(item);
1500 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); 1495 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
1501 unsigned long op; 1496 unsigned long op;
1502 ssize_t ret; 1497 ssize_t ret;
@@ -1523,12 +1518,10 @@ static ssize_t tcm_usbg_tpg_store_enable(
1523out: 1518out:
1524 return count; 1519 return count;
1525} 1520}
1526TF_TPG_BASE_ATTR(tcm_usbg, enable, S_IRUGO | S_IWUSR);
1527 1521
1528static ssize_t tcm_usbg_tpg_show_nexus( 1522static ssize_t tcm_usbg_tpg_nexus_show(struct config_item *item, char *page)
1529 struct se_portal_group *se_tpg,
1530 char *page)
1531{ 1523{
1524 struct se_portal_group *se_tpg = to_tpg(item);
1532 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); 1525 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
1533 struct tcm_usbg_nexus *tv_nexus; 1526 struct tcm_usbg_nexus *tv_nexus;
1534 ssize_t ret; 1527 ssize_t ret;
@@ -1636,11 +1629,10 @@ out:
1636 return ret; 1629 return ret;
1637} 1630}
1638 1631
1639static ssize_t tcm_usbg_tpg_store_nexus( 1632static ssize_t tcm_usbg_tpg_nexus_store(struct config_item *item,
1640 struct se_portal_group *se_tpg, 1633 const char *page, size_t count)
1641 const char *page,
1642 size_t count)
1643{ 1634{
1635 struct se_portal_group *se_tpg = to_tpg(item);
1644 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg); 1636 struct usbg_tpg *tpg = container_of(se_tpg, struct usbg_tpg, se_tpg);
1645 unsigned char i_port[USBG_NAMELEN], *ptr; 1637 unsigned char i_port[USBG_NAMELEN], *ptr;
1646 int ret; 1638 int ret;
@@ -1670,11 +1662,13 @@ static ssize_t tcm_usbg_tpg_store_nexus(
1670 return ret; 1662 return ret;
1671 return count; 1663 return count;
1672} 1664}
1673TF_TPG_BASE_ATTR(tcm_usbg, nexus, S_IRUGO | S_IWUSR); 1665
1666CONFIGFS_ATTR(tcm_usbg_tpg_, enable);
1667CONFIGFS_ATTR(tcm_usbg_tpg_, nexus);
1674 1668
1675static struct configfs_attribute *usbg_base_attrs[] = { 1669static struct configfs_attribute *usbg_base_attrs[] = {
1676 &tcm_usbg_tpg_enable.attr, 1670 &tcm_usbg_tpg_attr_enable,
1677 &tcm_usbg_tpg_nexus.attr, 1671 &tcm_usbg_tpg_attr_nexus,
1678 NULL, 1672 NULL,
1679}; 1673};
1680 1674
diff --git a/drivers/vhost/scsi.c b/drivers/vhost/scsi.c
index e25a23692822..29cfc57d496e 100644
--- a/drivers/vhost/scsi.c
+++ b/drivers/vhost/scsi.c
@@ -42,8 +42,6 @@
42#include <scsi/scsi_proto.h> 42#include <scsi/scsi_proto.h>
43#include <target/target_core_base.h> 43#include <target/target_core_base.h>
44#include <target/target_core_fabric.h> 44#include <target/target_core_fabric.h>
45#include <target/target_core_fabric_configfs.h>
46#include <target/configfs_macros.h>
47#include <linux/vhost.h> 45#include <linux/vhost.h>
48#include <linux/virtio_scsi.h> 46#include <linux/virtio_scsi.h>
49#include <linux/llist.h> 47#include <linux/llist.h>
@@ -1684,11 +1682,10 @@ static void vhost_scsi_free_cmd_map_res(struct vhost_scsi_nexus *nexus,
1684 } 1682 }
1685} 1683}
1686 1684
1687static ssize_t vhost_scsi_tpg_attrib_store_fabric_prot_type( 1685static ssize_t vhost_scsi_tpg_attrib_fabric_prot_type_store(
1688 struct se_portal_group *se_tpg, 1686 struct config_item *item, const char *page, size_t count)
1689 const char *page,
1690 size_t count)
1691{ 1687{
1688 struct se_portal_group *se_tpg = attrib_to_tpg(item);
1692 struct vhost_scsi_tpg *tpg = container_of(se_tpg, 1689 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
1693 struct vhost_scsi_tpg, se_tpg); 1690 struct vhost_scsi_tpg, se_tpg);
1694 unsigned long val; 1691 unsigned long val;
@@ -1707,19 +1704,20 @@ static ssize_t vhost_scsi_tpg_attrib_store_fabric_prot_type(
1707 return count; 1704 return count;
1708} 1705}
1709 1706
1710static ssize_t vhost_scsi_tpg_attrib_show_fabric_prot_type( 1707static ssize_t vhost_scsi_tpg_attrib_fabric_prot_type_show(
1711 struct se_portal_group *se_tpg, 1708 struct config_item *item, char *page)
1712 char *page)
1713{ 1709{
1710 struct se_portal_group *se_tpg = attrib_to_tpg(item);
1714 struct vhost_scsi_tpg *tpg = container_of(se_tpg, 1711 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
1715 struct vhost_scsi_tpg, se_tpg); 1712 struct vhost_scsi_tpg, se_tpg);
1716 1713
1717 return sprintf(page, "%d\n", tpg->tv_fabric_prot_type); 1714 return sprintf(page, "%d\n", tpg->tv_fabric_prot_type);
1718} 1715}
1719TF_TPG_ATTRIB_ATTR(vhost_scsi, fabric_prot_type, S_IRUGO | S_IWUSR); 1716
1717CONFIGFS_ATTR(vhost_scsi_tpg_attrib_, fabric_prot_type);
1720 1718
1721static struct configfs_attribute *vhost_scsi_tpg_attrib_attrs[] = { 1719static struct configfs_attribute *vhost_scsi_tpg_attrib_attrs[] = {
1722 &vhost_scsi_tpg_attrib_fabric_prot_type.attr, 1720 &vhost_scsi_tpg_attrib_attr_fabric_prot_type,
1723 NULL, 1721 NULL,
1724}; 1722};
1725 1723
@@ -1867,9 +1865,9 @@ static int vhost_scsi_drop_nexus(struct vhost_scsi_tpg *tpg)
1867 return 0; 1865 return 0;
1868} 1866}
1869 1867
1870static ssize_t vhost_scsi_tpg_show_nexus(struct se_portal_group *se_tpg, 1868static ssize_t vhost_scsi_tpg_nexus_show(struct config_item *item, char *page)
1871 char *page)
1872{ 1869{
1870 struct se_portal_group *se_tpg = to_tpg(item);
1873 struct vhost_scsi_tpg *tpg = container_of(se_tpg, 1871 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
1874 struct vhost_scsi_tpg, se_tpg); 1872 struct vhost_scsi_tpg, se_tpg);
1875 struct vhost_scsi_nexus *tv_nexus; 1873 struct vhost_scsi_nexus *tv_nexus;
@@ -1888,10 +1886,10 @@ static ssize_t vhost_scsi_tpg_show_nexus(struct se_portal_group *se_tpg,
1888 return ret; 1886 return ret;
1889} 1887}
1890 1888
1891static ssize_t vhost_scsi_tpg_store_nexus(struct se_portal_group *se_tpg, 1889static ssize_t vhost_scsi_tpg_nexus_store(struct config_item *item,
1892 const char *page, 1890 const char *page, size_t count)
1893 size_t count)
1894{ 1891{
1892 struct se_portal_group *se_tpg = to_tpg(item);
1895 struct vhost_scsi_tpg *tpg = container_of(se_tpg, 1893 struct vhost_scsi_tpg *tpg = container_of(se_tpg,
1896 struct vhost_scsi_tpg, se_tpg); 1894 struct vhost_scsi_tpg, se_tpg);
1897 struct vhost_scsi_tport *tport_wwn = tpg->tport; 1895 struct vhost_scsi_tport *tport_wwn = tpg->tport;
@@ -1966,10 +1964,10 @@ check_newline:
1966 return count; 1964 return count;
1967} 1965}
1968 1966
1969TF_TPG_BASE_ATTR(vhost_scsi, nexus, S_IRUGO | S_IWUSR); 1967CONFIGFS_ATTR(vhost_scsi_tpg_, nexus);
1970 1968
1971static struct configfs_attribute *vhost_scsi_tpg_attrs[] = { 1969static struct configfs_attribute *vhost_scsi_tpg_attrs[] = {
1972 &vhost_scsi_tpg_nexus.attr, 1970 &vhost_scsi_tpg_attr_nexus,
1973 NULL, 1971 NULL,
1974}; 1972};
1975 1973
@@ -2105,18 +2103,17 @@ static void vhost_scsi_drop_tport(struct se_wwn *wwn)
2105} 2103}
2106 2104
2107static ssize_t 2105static ssize_t
2108vhost_scsi_wwn_show_attr_version(struct target_fabric_configfs *tf, 2106vhost_scsi_wwn_version_show(struct config_item *item, char *page)
2109 char *page)
2110{ 2107{
2111 return sprintf(page, "TCM_VHOST fabric module %s on %s/%s" 2108 return sprintf(page, "TCM_VHOST fabric module %s on %s/%s"
2112 "on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname, 2109 "on "UTS_RELEASE"\n", VHOST_SCSI_VERSION, utsname()->sysname,
2113 utsname()->machine); 2110 utsname()->machine);
2114} 2111}
2115 2112
2116TF_WWN_ATTR_RO(vhost_scsi, version); 2113CONFIGFS_ATTR_RO(vhost_scsi_wwn_, version);
2117 2114
2118static struct configfs_attribute *vhost_scsi_wwn_attrs[] = { 2115static struct configfs_attribute *vhost_scsi_wwn_attrs[] = {
2119 &vhost_scsi_wwn_version.attr, 2116 &vhost_scsi_wwn_attr_version,
2120 NULL, 2117 NULL,
2121}; 2118};
2122 2119
diff --git a/drivers/xen/xen-scsiback.c b/drivers/xen/xen-scsiback.c
index 9eeefd7cad41..43bcae852546 100644
--- a/drivers/xen/xen-scsiback.c
+++ b/drivers/xen/xen-scsiback.c
@@ -53,7 +53,6 @@
53 53
54#include <target/target_core_base.h> 54#include <target/target_core_base.h>
55#include <target/target_core_fabric.h> 55#include <target/target_core_fabric.h>
56#include <target/target_core_fabric_configfs.h>
57 56
58#include <asm/hypervisor.h> 57#include <asm/hypervisor.h>
59 58
@@ -1438,9 +1437,10 @@ static void scsiback_aborted_task(struct se_cmd *se_cmd)
1438{ 1437{
1439} 1438}
1440 1439
1441static ssize_t scsiback_tpg_param_show_alias(struct se_portal_group *se_tpg, 1440static ssize_t scsiback_tpg_param_alias_show(struct config_item *item,
1442 char *page) 1441 char *page)
1443{ 1442{
1443 struct se_portal_group *se_tpg = param_to_tpg(item);
1444 struct scsiback_tpg *tpg = container_of(se_tpg, struct scsiback_tpg, 1444 struct scsiback_tpg *tpg = container_of(se_tpg, struct scsiback_tpg,
1445 se_tpg); 1445 se_tpg);
1446 ssize_t rb; 1446 ssize_t rb;
@@ -1452,9 +1452,10 @@ static ssize_t scsiback_tpg_param_show_alias(struct se_portal_group *se_tpg,
1452 return rb; 1452 return rb;
1453} 1453}
1454 1454
1455static ssize_t scsiback_tpg_param_store_alias(struct se_portal_group *se_tpg, 1455static ssize_t scsiback_tpg_param_alias_store(struct config_item *item,
1456 const char *page, size_t count) 1456 const char *page, size_t count)
1457{ 1457{
1458 struct se_portal_group *se_tpg = param_to_tpg(item);
1458 struct scsiback_tpg *tpg = container_of(se_tpg, struct scsiback_tpg, 1459 struct scsiback_tpg *tpg = container_of(se_tpg, struct scsiback_tpg,
1459 se_tpg); 1460 se_tpg);
1460 int len; 1461 int len;
@@ -1474,10 +1475,10 @@ static ssize_t scsiback_tpg_param_store_alias(struct se_portal_group *se_tpg,
1474 return count; 1475 return count;
1475} 1476}
1476 1477
1477TF_TPG_PARAM_ATTR(scsiback, alias, S_IRUGO | S_IWUSR); 1478CONFIGFS_ATTR(scsiback_tpg_param_, alias);
1478 1479
1479static struct configfs_attribute *scsiback_param_attrs[] = { 1480static struct configfs_attribute *scsiback_param_attrs[] = {
1480 &scsiback_tpg_param_alias.attr, 1481 &scsiback_tpg_param_attr_alias,
1481 NULL, 1482 NULL,
1482}; 1483};
1483 1484
@@ -1585,9 +1586,9 @@ static int scsiback_drop_nexus(struct scsiback_tpg *tpg)
1585 return 0; 1586 return 0;
1586} 1587}
1587 1588
1588static ssize_t scsiback_tpg_show_nexus(struct se_portal_group *se_tpg, 1589static ssize_t scsiback_tpg_nexus_show(struct config_item *item, char *page)
1589 char *page)
1590{ 1590{
1591 struct se_portal_group *se_tpg = to_tpg(item);
1591 struct scsiback_tpg *tpg = container_of(se_tpg, 1592 struct scsiback_tpg *tpg = container_of(se_tpg,
1592 struct scsiback_tpg, se_tpg); 1593 struct scsiback_tpg, se_tpg);
1593 struct scsiback_nexus *tv_nexus; 1594 struct scsiback_nexus *tv_nexus;
@@ -1606,10 +1607,10 @@ static ssize_t scsiback_tpg_show_nexus(struct se_portal_group *se_tpg,
1606 return ret; 1607 return ret;
1607} 1608}
1608 1609
1609static ssize_t scsiback_tpg_store_nexus(struct se_portal_group *se_tpg, 1610static ssize_t scsiback_tpg_nexus_store(struct config_item *item,
1610 const char *page, 1611 const char *page, size_t count)
1611 size_t count)
1612{ 1612{
1613 struct se_portal_group *se_tpg = to_tpg(item);
1613 struct scsiback_tpg *tpg = container_of(se_tpg, 1614 struct scsiback_tpg *tpg = container_of(se_tpg,
1614 struct scsiback_tpg, se_tpg); 1615 struct scsiback_tpg, se_tpg);
1615 struct scsiback_tport *tport_wwn = tpg->tport; 1616 struct scsiback_tport *tport_wwn = tpg->tport;
@@ -1681,26 +1682,25 @@ check_newline:
1681 return count; 1682 return count;
1682} 1683}
1683 1684
1684TF_TPG_BASE_ATTR(scsiback, nexus, S_IRUGO | S_IWUSR); 1685CONFIGFS_ATTR(scsiback_tpg_, nexus);
1685 1686
1686static struct configfs_attribute *scsiback_tpg_attrs[] = { 1687static struct configfs_attribute *scsiback_tpg_attrs[] = {
1687 &scsiback_tpg_nexus.attr, 1688 &scsiback_tpg_attr_nexus,
1688 NULL, 1689 NULL,
1689}; 1690};
1690 1691
1691static ssize_t 1692static ssize_t
1692scsiback_wwn_show_attr_version(struct target_fabric_configfs *tf, 1693scsiback_wwn_version_show(struct config_item *item, char *page)
1693 char *page)
1694{ 1694{
1695 return sprintf(page, "xen-pvscsi fabric module %s on %s/%s on " 1695 return sprintf(page, "xen-pvscsi fabric module %s on %s/%s on "
1696 UTS_RELEASE"\n", 1696 UTS_RELEASE"\n",
1697 VSCSI_VERSION, utsname()->sysname, utsname()->machine); 1697 VSCSI_VERSION, utsname()->sysname, utsname()->machine);
1698} 1698}
1699 1699
1700TF_WWN_ATTR_RO(scsiback, version); 1700CONFIGFS_ATTR_RO(scsiback_wwn_, version);
1701 1701
1702static struct configfs_attribute *scsiback_wwn_attrs[] = { 1702static struct configfs_attribute *scsiback_wwn_attrs[] = {
1703 &scsiback_wwn_version.attr, 1703 &scsiback_wwn_attr_version,
1704 NULL, 1704 NULL,
1705}; 1705};
1706 1706
diff --git a/fs/configfs/file.c b/fs/configfs/file.c
index 403269ffcdf3..d39099ea7df7 100644
--- a/fs/configfs/file.c
+++ b/fs/configfs/file.c
@@ -65,7 +65,6 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
65{ 65{
66 struct configfs_attribute * attr = to_attr(dentry); 66 struct configfs_attribute * attr = to_attr(dentry);
67 struct config_item * item = to_item(dentry->d_parent); 67 struct config_item * item = to_item(dentry->d_parent);
68 struct configfs_item_operations * ops = buffer->ops;
69 int ret = 0; 68 int ret = 0;
70 ssize_t count; 69 ssize_t count;
71 70
@@ -74,7 +73,8 @@ static int fill_read_buffer(struct dentry * dentry, struct configfs_buffer * buf
74 if (!buffer->page) 73 if (!buffer->page)
75 return -ENOMEM; 74 return -ENOMEM;
76 75
77 count = ops->show_attribute(item,attr,buffer->page); 76 count = attr->show(item, buffer->page);
77
78 buffer->needs_read_fill = 0; 78 buffer->needs_read_fill = 0;
79 BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE); 79 BUG_ON(count > (ssize_t)SIMPLE_ATTR_SIZE);
80 if (count >= 0) 80 if (count >= 0)
@@ -171,9 +171,8 @@ flush_write_buffer(struct dentry * dentry, struct configfs_buffer * buffer, size
171{ 171{
172 struct configfs_attribute * attr = to_attr(dentry); 172 struct configfs_attribute * attr = to_attr(dentry);
173 struct config_item * item = to_item(dentry->d_parent); 173 struct config_item * item = to_item(dentry->d_parent);
174 struct configfs_item_operations * ops = buffer->ops;
175 174
176 return ops->store_attribute(item,attr,buffer->page,count); 175 return attr->store(item, buffer->page, count);
177} 176}
178 177
179 178
@@ -237,8 +236,7 @@ static int check_perm(struct inode * inode, struct file * file)
237 * and we must have a store method. 236 * and we must have a store method.
238 */ 237 */
239 if (file->f_mode & FMODE_WRITE) { 238 if (file->f_mode & FMODE_WRITE) {
240 239 if (!(inode->i_mode & S_IWUGO) || !attr->store)
241 if (!(inode->i_mode & S_IWUGO) || !ops->store_attribute)
242 goto Eaccess; 240 goto Eaccess;
243 241
244 } 242 }
@@ -248,7 +246,7 @@ static int check_perm(struct inode * inode, struct file * file)
248 * must be a show method for it. 246 * must be a show method for it.
249 */ 247 */
250 if (file->f_mode & FMODE_READ) { 248 if (file->f_mode & FMODE_READ) {
251 if (!(inode->i_mode & S_IRUGO) || !ops->show_attribute) 249 if (!(inode->i_mode & S_IRUGO) || !attr->show)
252 goto Eaccess; 250 goto Eaccess;
253 } 251 }
254 252
diff --git a/fs/dlm/config.c b/fs/dlm/config.c
index d521bddf876d..8e294fbbac39 100644
--- a/fs/dlm/config.c
+++ b/fs/dlm/config.c
@@ -61,35 +61,8 @@ static struct config_item *make_node(struct config_group *, const char *);
61static void drop_node(struct config_group *, struct config_item *); 61static void drop_node(struct config_group *, struct config_item *);
62static void release_node(struct config_item *); 62static void release_node(struct config_item *);
63 63
64static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, 64static struct configfs_attribute *comm_attrs[];
65 char *buf); 65static struct configfs_attribute *node_attrs[];
66static ssize_t store_cluster(struct config_item *i,
67 struct configfs_attribute *a,
68 const char *buf, size_t len);
69static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
70 char *buf);
71static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
72 const char *buf, size_t len);
73static ssize_t show_node(struct config_item *i, struct configfs_attribute *a,
74 char *buf);
75static ssize_t store_node(struct config_item *i, struct configfs_attribute *a,
76 const char *buf, size_t len);
77
78static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf);
79static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
80 size_t len);
81static ssize_t comm_local_read(struct dlm_comm *cm, char *buf);
82static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
83 size_t len);
84static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf,
85 size_t len);
86static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf);
87static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf);
88static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
89 size_t len);
90static ssize_t node_weight_read(struct dlm_node *nd, char *buf);
91static ssize_t node_weight_write(struct dlm_node *nd, const char *buf,
92 size_t len);
93 66
94struct dlm_cluster { 67struct dlm_cluster {
95 struct config_group group; 68 struct config_group group;
@@ -108,6 +81,12 @@ struct dlm_cluster {
108 char cl_cluster_name[DLM_LOCKSPACE_LEN]; 81 char cl_cluster_name[DLM_LOCKSPACE_LEN];
109}; 82};
110 83
84static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
85{
86 return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
87 NULL;
88}
89
111enum { 90enum {
112 CLUSTER_ATTR_TCP_PORT = 0, 91 CLUSTER_ATTR_TCP_PORT = 0,
113 CLUSTER_ATTR_BUFFER_SIZE, 92 CLUSTER_ATTR_BUFFER_SIZE,
@@ -124,33 +103,24 @@ enum {
124 CLUSTER_ATTR_CLUSTER_NAME, 103 CLUSTER_ATTR_CLUSTER_NAME,
125}; 104};
126 105
127struct cluster_attribute { 106static ssize_t cluster_cluster_name_show(struct config_item *item, char *buf)
128 struct configfs_attribute attr;
129 ssize_t (*show)(struct dlm_cluster *, char *);
130 ssize_t (*store)(struct dlm_cluster *, const char *, size_t);
131};
132
133static ssize_t cluster_cluster_name_read(struct dlm_cluster *cl, char *buf)
134{ 107{
108 struct dlm_cluster *cl = config_item_to_cluster(item);
135 return sprintf(buf, "%s\n", cl->cl_cluster_name); 109 return sprintf(buf, "%s\n", cl->cl_cluster_name);
136} 110}
137 111
138static ssize_t cluster_cluster_name_write(struct dlm_cluster *cl, 112static ssize_t cluster_cluster_name_store(struct config_item *item,
139 const char *buf, size_t len) 113 const char *buf, size_t len)
140{ 114{
115 struct dlm_cluster *cl = config_item_to_cluster(item);
116
141 strlcpy(dlm_config.ci_cluster_name, buf, 117 strlcpy(dlm_config.ci_cluster_name, buf,
142 sizeof(dlm_config.ci_cluster_name)); 118 sizeof(dlm_config.ci_cluster_name));
143 strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name)); 119 strlcpy(cl->cl_cluster_name, buf, sizeof(cl->cl_cluster_name));
144 return len; 120 return len;
145} 121}
146 122
147static struct cluster_attribute cluster_attr_cluster_name = { 123CONFIGFS_ATTR(cluster_, cluster_name);
148 .attr = { .ca_owner = THIS_MODULE,
149 .ca_name = "cluster_name",
150 .ca_mode = S_IRUGO | S_IWUSR },
151 .show = cluster_cluster_name_read,
152 .store = cluster_cluster_name_write,
153};
154 124
155static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field, 125static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
156 int *info_field, int check_zero, 126 int *info_field, int check_zero,
@@ -175,17 +145,19 @@ static ssize_t cluster_set(struct dlm_cluster *cl, unsigned int *cl_field,
175} 145}
176 146
177#define CLUSTER_ATTR(name, check_zero) \ 147#define CLUSTER_ATTR(name, check_zero) \
178static ssize_t name##_write(struct dlm_cluster *cl, const char *buf, size_t len) \ 148static ssize_t cluster_##name##_store(struct config_item *item, \
149 const char *buf, size_t len) \
179{ \ 150{ \
151 struct dlm_cluster *cl = config_item_to_cluster(item); \
180 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \ 152 return cluster_set(cl, &cl->cl_##name, &dlm_config.ci_##name, \
181 check_zero, buf, len); \ 153 check_zero, buf, len); \
182} \ 154} \
183static ssize_t name##_read(struct dlm_cluster *cl, char *buf) \ 155static ssize_t cluster_##name##_show(struct config_item *item, char *buf) \
184{ \ 156{ \
157 struct dlm_cluster *cl = config_item_to_cluster(item); \
185 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \ 158 return snprintf(buf, PAGE_SIZE, "%u\n", cl->cl_##name); \
186} \ 159} \
187static struct cluster_attribute cluster_attr_##name = \ 160CONFIGFS_ATTR(cluster_, name);
188__CONFIGFS_ATTR(name, 0644, name##_read, name##_write)
189 161
190CLUSTER_ATTR(tcp_port, 1); 162CLUSTER_ATTR(tcp_port, 1);
191CLUSTER_ATTR(buffer_size, 1); 163CLUSTER_ATTR(buffer_size, 1);
@@ -201,19 +173,19 @@ CLUSTER_ATTR(new_rsb_count, 0);
201CLUSTER_ATTR(recover_callbacks, 0); 173CLUSTER_ATTR(recover_callbacks, 0);
202 174
203static struct configfs_attribute *cluster_attrs[] = { 175static struct configfs_attribute *cluster_attrs[] = {
204 [CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port.attr, 176 [CLUSTER_ATTR_TCP_PORT] = &cluster_attr_tcp_port,
205 [CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size.attr, 177 [CLUSTER_ATTR_BUFFER_SIZE] = &cluster_attr_buffer_size,
206 [CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size.attr, 178 [CLUSTER_ATTR_RSBTBL_SIZE] = &cluster_attr_rsbtbl_size,
207 [CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer.attr, 179 [CLUSTER_ATTR_RECOVER_TIMER] = &cluster_attr_recover_timer,
208 [CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs.attr, 180 [CLUSTER_ATTR_TOSS_SECS] = &cluster_attr_toss_secs,
209 [CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs.attr, 181 [CLUSTER_ATTR_SCAN_SECS] = &cluster_attr_scan_secs,
210 [CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug.attr, 182 [CLUSTER_ATTR_LOG_DEBUG] = &cluster_attr_log_debug,
211 [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol.attr, 183 [CLUSTER_ATTR_PROTOCOL] = &cluster_attr_protocol,
212 [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs.attr, 184 [CLUSTER_ATTR_TIMEWARN_CS] = &cluster_attr_timewarn_cs,
213 [CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us.attr, 185 [CLUSTER_ATTR_WAITWARN_US] = &cluster_attr_waitwarn_us,
214 [CLUSTER_ATTR_NEW_RSB_COUNT] = &cluster_attr_new_rsb_count.attr, 186 [CLUSTER_ATTR_NEW_RSB_COUNT] = &cluster_attr_new_rsb_count,
215 [CLUSTER_ATTR_RECOVER_CALLBACKS] = &cluster_attr_recover_callbacks.attr, 187 [CLUSTER_ATTR_RECOVER_CALLBACKS] = &cluster_attr_recover_callbacks,
216 [CLUSTER_ATTR_CLUSTER_NAME] = &cluster_attr_cluster_name.attr, 188 [CLUSTER_ATTR_CLUSTER_NAME] = &cluster_attr_cluster_name,
217 NULL, 189 NULL,
218}; 190};
219 191
@@ -224,83 +196,11 @@ enum {
224 COMM_ATTR_ADDR_LIST, 196 COMM_ATTR_ADDR_LIST,
225}; 197};
226 198
227struct comm_attribute {
228 struct configfs_attribute attr;
229 ssize_t (*show)(struct dlm_comm *, char *);
230 ssize_t (*store)(struct dlm_comm *, const char *, size_t);
231};
232
233static struct comm_attribute comm_attr_nodeid = {
234 .attr = { .ca_owner = THIS_MODULE,
235 .ca_name = "nodeid",
236 .ca_mode = S_IRUGO | S_IWUSR },
237 .show = comm_nodeid_read,
238 .store = comm_nodeid_write,
239};
240
241static struct comm_attribute comm_attr_local = {
242 .attr = { .ca_owner = THIS_MODULE,
243 .ca_name = "local",
244 .ca_mode = S_IRUGO | S_IWUSR },
245 .show = comm_local_read,
246 .store = comm_local_write,
247};
248
249static struct comm_attribute comm_attr_addr = {
250 .attr = { .ca_owner = THIS_MODULE,
251 .ca_name = "addr",
252 .ca_mode = S_IWUSR },
253 .store = comm_addr_write,
254};
255
256static struct comm_attribute comm_attr_addr_list = {
257 .attr = { .ca_owner = THIS_MODULE,
258 .ca_name = "addr_list",
259 .ca_mode = S_IRUGO },
260 .show = comm_addr_list_read,
261};
262
263static struct configfs_attribute *comm_attrs[] = {
264 [COMM_ATTR_NODEID] = &comm_attr_nodeid.attr,
265 [COMM_ATTR_LOCAL] = &comm_attr_local.attr,
266 [COMM_ATTR_ADDR] = &comm_attr_addr.attr,
267 [COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list.attr,
268 NULL,
269};
270
271enum { 199enum {
272 NODE_ATTR_NODEID = 0, 200 NODE_ATTR_NODEID = 0,
273 NODE_ATTR_WEIGHT, 201 NODE_ATTR_WEIGHT,
274}; 202};
275 203
276struct node_attribute {
277 struct configfs_attribute attr;
278 ssize_t (*show)(struct dlm_node *, char *);
279 ssize_t (*store)(struct dlm_node *, const char *, size_t);
280};
281
282static struct node_attribute node_attr_nodeid = {
283 .attr = { .ca_owner = THIS_MODULE,
284 .ca_name = "nodeid",
285 .ca_mode = S_IRUGO | S_IWUSR },
286 .show = node_nodeid_read,
287 .store = node_nodeid_write,
288};
289
290static struct node_attribute node_attr_weight = {
291 .attr = { .ca_owner = THIS_MODULE,
292 .ca_name = "weight",
293 .ca_mode = S_IRUGO | S_IWUSR },
294 .show = node_weight_read,
295 .store = node_weight_write,
296};
297
298static struct configfs_attribute *node_attrs[] = {
299 [NODE_ATTR_NODEID] = &node_attr_nodeid.attr,
300 [NODE_ATTR_WEIGHT] = &node_attr_weight.attr,
301 NULL,
302};
303
304struct dlm_clusters { 204struct dlm_clusters {
305 struct configfs_subsystem subsys; 205 struct configfs_subsystem subsys;
306}; 206};
@@ -349,8 +249,6 @@ static struct configfs_group_operations clusters_ops = {
349 249
350static struct configfs_item_operations cluster_ops = { 250static struct configfs_item_operations cluster_ops = {
351 .release = release_cluster, 251 .release = release_cluster,
352 .show_attribute = show_cluster,
353 .store_attribute = store_cluster,
354}; 252};
355 253
356static struct configfs_group_operations spaces_ops = { 254static struct configfs_group_operations spaces_ops = {
@@ -369,8 +267,6 @@ static struct configfs_group_operations comms_ops = {
369 267
370static struct configfs_item_operations comm_ops = { 268static struct configfs_item_operations comm_ops = {
371 .release = release_comm, 269 .release = release_comm,
372 .show_attribute = show_comm,
373 .store_attribute = store_comm,
374}; 270};
375 271
376static struct configfs_group_operations nodes_ops = { 272static struct configfs_group_operations nodes_ops = {
@@ -380,8 +276,6 @@ static struct configfs_group_operations nodes_ops = {
380 276
381static struct configfs_item_operations node_ops = { 277static struct configfs_item_operations node_ops = {
382 .release = release_node, 278 .release = release_node,
383 .show_attribute = show_node,
384 .store_attribute = store_node,
385}; 279};
386 280
387static struct config_item_type clusters_type = { 281static struct config_item_type clusters_type = {
@@ -427,12 +321,6 @@ static struct config_item_type node_type = {
427 .ct_owner = THIS_MODULE, 321 .ct_owner = THIS_MODULE,
428}; 322};
429 323
430static struct dlm_cluster *config_item_to_cluster(struct config_item *i)
431{
432 return i ? container_of(to_config_group(i), struct dlm_cluster, group) :
433 NULL;
434}
435
436static struct dlm_space *config_item_to_space(struct config_item *i) 324static struct dlm_space *config_item_to_space(struct config_item *i)
437{ 325{
438 return i ? container_of(to_config_group(i), struct dlm_space, group) : 326 return i ? container_of(to_config_group(i), struct dlm_space, group) :
@@ -687,66 +575,30 @@ void dlm_config_exit(void)
687 * Functions for user space to read/write attributes 575 * Functions for user space to read/write attributes
688 */ 576 */
689 577
690static ssize_t show_cluster(struct config_item *i, struct configfs_attribute *a, 578static ssize_t comm_nodeid_show(struct config_item *item, char *buf)
691 char *buf)
692{
693 struct dlm_cluster *cl = config_item_to_cluster(i);
694 struct cluster_attribute *cla =
695 container_of(a, struct cluster_attribute, attr);
696 return cla->show ? cla->show(cl, buf) : 0;
697}
698
699static ssize_t store_cluster(struct config_item *i,
700 struct configfs_attribute *a,
701 const char *buf, size_t len)
702{ 579{
703 struct dlm_cluster *cl = config_item_to_cluster(i); 580 return sprintf(buf, "%d\n", config_item_to_comm(item)->nodeid);
704 struct cluster_attribute *cla =
705 container_of(a, struct cluster_attribute, attr);
706 return cla->store ? cla->store(cl, buf, len) : -EINVAL;
707}
708
709static ssize_t show_comm(struct config_item *i, struct configfs_attribute *a,
710 char *buf)
711{
712 struct dlm_comm *cm = config_item_to_comm(i);
713 struct comm_attribute *cma =
714 container_of(a, struct comm_attribute, attr);
715 return cma->show ? cma->show(cm, buf) : 0;
716}
717
718static ssize_t store_comm(struct config_item *i, struct configfs_attribute *a,
719 const char *buf, size_t len)
720{
721 struct dlm_comm *cm = config_item_to_comm(i);
722 struct comm_attribute *cma =
723 container_of(a, struct comm_attribute, attr);
724 return cma->store ? cma->store(cm, buf, len) : -EINVAL;
725} 581}
726 582
727static ssize_t comm_nodeid_read(struct dlm_comm *cm, char *buf) 583static ssize_t comm_nodeid_store(struct config_item *item, const char *buf,
728{
729 return sprintf(buf, "%d\n", cm->nodeid);
730}
731
732static ssize_t comm_nodeid_write(struct dlm_comm *cm, const char *buf,
733 size_t len) 584 size_t len)
734{ 585{
735 int rc = kstrtoint(buf, 0, &cm->nodeid); 586 int rc = kstrtoint(buf, 0, &config_item_to_comm(item)->nodeid);
736 587
737 if (rc) 588 if (rc)
738 return rc; 589 return rc;
739 return len; 590 return len;
740} 591}
741 592
742static ssize_t comm_local_read(struct dlm_comm *cm, char *buf) 593static ssize_t comm_local_show(struct config_item *item, char *buf)
743{ 594{
744 return sprintf(buf, "%d\n", cm->local); 595 return sprintf(buf, "%d\n", config_item_to_comm(item)->local);
745} 596}
746 597
747static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf, 598static ssize_t comm_local_store(struct config_item *item, const char *buf,
748 size_t len) 599 size_t len)
749{ 600{
601 struct dlm_comm *cm = config_item_to_comm(item);
750 int rc = kstrtoint(buf, 0, &cm->local); 602 int rc = kstrtoint(buf, 0, &cm->local);
751 603
752 if (rc) 604 if (rc)
@@ -756,8 +608,10 @@ static ssize_t comm_local_write(struct dlm_comm *cm, const char *buf,
756 return len; 608 return len;
757} 609}
758 610
759static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len) 611static ssize_t comm_addr_store(struct config_item *item, const char *buf,
612 size_t len)
760{ 613{
614 struct dlm_comm *cm = config_item_to_comm(item);
761 struct sockaddr_storage *addr; 615 struct sockaddr_storage *addr;
762 int rv; 616 int rv;
763 617
@@ -783,8 +637,9 @@ static ssize_t comm_addr_write(struct dlm_comm *cm, const char *buf, size_t len)
783 return len; 637 return len;
784} 638}
785 639
786static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf) 640static ssize_t comm_addr_list_show(struct config_item *item, char *buf)
787{ 641{
642 struct dlm_comm *cm = config_item_to_comm(item);
788 ssize_t s; 643 ssize_t s;
789 ssize_t allowance; 644 ssize_t allowance;
790 int i; 645 int i;
@@ -827,32 +682,28 @@ static ssize_t comm_addr_list_read(struct dlm_comm *cm, char *buf)
827 return 4096 - allowance; 682 return 4096 - allowance;
828} 683}
829 684
830static ssize_t show_node(struct config_item *i, struct configfs_attribute *a, 685CONFIGFS_ATTR(comm_, nodeid);
831 char *buf) 686CONFIGFS_ATTR(comm_, local);
832{ 687CONFIGFS_ATTR_WO(comm_, addr);
833 struct dlm_node *nd = config_item_to_node(i); 688CONFIGFS_ATTR_RO(comm_, addr_list);
834 struct node_attribute *nda =
835 container_of(a, struct node_attribute, attr);
836 return nda->show ? nda->show(nd, buf) : 0;
837}
838 689
839static ssize_t store_node(struct config_item *i, struct configfs_attribute *a, 690static struct configfs_attribute *comm_attrs[] = {
840 const char *buf, size_t len) 691 [COMM_ATTR_NODEID] = &comm_attr_nodeid,
841{ 692 [COMM_ATTR_LOCAL] = &comm_attr_local,
842 struct dlm_node *nd = config_item_to_node(i); 693 [COMM_ATTR_ADDR] = &comm_attr_addr,
843 struct node_attribute *nda = 694 [COMM_ATTR_ADDR_LIST] = &comm_attr_addr_list,
844 container_of(a, struct node_attribute, attr); 695 NULL,
845 return nda->store ? nda->store(nd, buf, len) : -EINVAL; 696};
846}
847 697
848static ssize_t node_nodeid_read(struct dlm_node *nd, char *buf) 698static ssize_t node_nodeid_show(struct config_item *item, char *buf)
849{ 699{
850 return sprintf(buf, "%d\n", nd->nodeid); 700 return sprintf(buf, "%d\n", config_item_to_node(item)->nodeid);
851} 701}
852 702
853static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf, 703static ssize_t node_nodeid_store(struct config_item *item, const char *buf,
854 size_t len) 704 size_t len)
855{ 705{
706 struct dlm_node *nd = config_item_to_node(item);
856 uint32_t seq = 0; 707 uint32_t seq = 0;
857 int rc = kstrtoint(buf, 0, &nd->nodeid); 708 int rc = kstrtoint(buf, 0, &nd->nodeid);
858 709
@@ -863,21 +714,30 @@ static ssize_t node_nodeid_write(struct dlm_node *nd, const char *buf,
863 return len; 714 return len;
864} 715}
865 716
866static ssize_t node_weight_read(struct dlm_node *nd, char *buf) 717static ssize_t node_weight_show(struct config_item *item, char *buf)
867{ 718{
868 return sprintf(buf, "%d\n", nd->weight); 719 return sprintf(buf, "%d\n", config_item_to_node(item)->weight);
869} 720}
870 721
871static ssize_t node_weight_write(struct dlm_node *nd, const char *buf, 722static ssize_t node_weight_store(struct config_item *item, const char *buf,
872 size_t len) 723 size_t len)
873{ 724{
874 int rc = kstrtoint(buf, 0, &nd->weight); 725 int rc = kstrtoint(buf, 0, &config_item_to_node(item)->weight);
875 726
876 if (rc) 727 if (rc)
877 return rc; 728 return rc;
878 return len; 729 return len;
879} 730}
880 731
732CONFIGFS_ATTR(node_, nodeid);
733CONFIGFS_ATTR(node_, weight);
734
735static struct configfs_attribute *node_attrs[] = {
736 [NODE_ATTR_NODEID] = &node_attr_nodeid,
737 [NODE_ATTR_WEIGHT] = &node_attr_weight,
738 NULL,
739};
740
881/* 741/*
882 * Functions for the dlm to get the info that's been configured 742 * Functions for the dlm to get the info that's been configured
883 */ 743 */
diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c
index ddddef0021a0..709fbbd44c65 100644
--- a/fs/ocfs2/cluster/heartbeat.c
+++ b/fs/ocfs2/cluster/heartbeat.c
@@ -1480,16 +1480,17 @@ static int o2hb_read_block_input(struct o2hb_region *reg,
1480 return 0; 1480 return 0;
1481} 1481}
1482 1482
1483static ssize_t o2hb_region_block_bytes_read(struct o2hb_region *reg, 1483static ssize_t o2hb_region_block_bytes_show(struct config_item *item,
1484 char *page) 1484 char *page)
1485{ 1485{
1486 return sprintf(page, "%u\n", reg->hr_block_bytes); 1486 return sprintf(page, "%u\n", to_o2hb_region(item)->hr_block_bytes);
1487} 1487}
1488 1488
1489static ssize_t o2hb_region_block_bytes_write(struct o2hb_region *reg, 1489static ssize_t o2hb_region_block_bytes_store(struct config_item *item,
1490 const char *page, 1490 const char *page,
1491 size_t count) 1491 size_t count)
1492{ 1492{
1493 struct o2hb_region *reg = to_o2hb_region(item);
1493 int status; 1494 int status;
1494 unsigned long block_bytes; 1495 unsigned long block_bytes;
1495 unsigned int block_bits; 1496 unsigned int block_bits;
@@ -1508,16 +1509,17 @@ static ssize_t o2hb_region_block_bytes_write(struct o2hb_region *reg,
1508 return count; 1509 return count;
1509} 1510}
1510 1511
1511static ssize_t o2hb_region_start_block_read(struct o2hb_region *reg, 1512static ssize_t o2hb_region_start_block_show(struct config_item *item,
1512 char *page) 1513 char *page)
1513{ 1514{
1514 return sprintf(page, "%llu\n", reg->hr_start_block); 1515 return sprintf(page, "%llu\n", to_o2hb_region(item)->hr_start_block);
1515} 1516}
1516 1517
1517static ssize_t o2hb_region_start_block_write(struct o2hb_region *reg, 1518static ssize_t o2hb_region_start_block_store(struct config_item *item,
1518 const char *page, 1519 const char *page,
1519 size_t count) 1520 size_t count)
1520{ 1521{
1522 struct o2hb_region *reg = to_o2hb_region(item);
1521 unsigned long long tmp; 1523 unsigned long long tmp;
1522 char *p = (char *)page; 1524 char *p = (char *)page;
1523 1525
@@ -1533,16 +1535,16 @@ static ssize_t o2hb_region_start_block_write(struct o2hb_region *reg,
1533 return count; 1535 return count;
1534} 1536}
1535 1537
1536static ssize_t o2hb_region_blocks_read(struct o2hb_region *reg, 1538static ssize_t o2hb_region_blocks_show(struct config_item *item, char *page)
1537 char *page)
1538{ 1539{
1539 return sprintf(page, "%d\n", reg->hr_blocks); 1540 return sprintf(page, "%d\n", to_o2hb_region(item)->hr_blocks);
1540} 1541}
1541 1542
1542static ssize_t o2hb_region_blocks_write(struct o2hb_region *reg, 1543static ssize_t o2hb_region_blocks_store(struct config_item *item,
1543 const char *page, 1544 const char *page,
1544 size_t count) 1545 size_t count)
1545{ 1546{
1547 struct o2hb_region *reg = to_o2hb_region(item);
1546 unsigned long tmp; 1548 unsigned long tmp;
1547 char *p = (char *)page; 1549 char *p = (char *)page;
1548 1550
@@ -1561,13 +1563,12 @@ static ssize_t o2hb_region_blocks_write(struct o2hb_region *reg,
1561 return count; 1563 return count;
1562} 1564}
1563 1565
1564static ssize_t o2hb_region_dev_read(struct o2hb_region *reg, 1566static ssize_t o2hb_region_dev_show(struct config_item *item, char *page)
1565 char *page)
1566{ 1567{
1567 unsigned int ret = 0; 1568 unsigned int ret = 0;
1568 1569
1569 if (reg->hr_bdev) 1570 if (to_o2hb_region(item)->hr_bdev)
1570 ret = sprintf(page, "%s\n", reg->hr_dev_name); 1571 ret = sprintf(page, "%s\n", to_o2hb_region(item)->hr_dev_name);
1571 1572
1572 return ret; 1573 return ret;
1573} 1574}
@@ -1677,10 +1678,11 @@ out:
1677} 1678}
1678 1679
1679/* this is acting as commit; we set up all of hr_bdev and hr_task or nothing */ 1680/* this is acting as commit; we set up all of hr_bdev and hr_task or nothing */
1680static ssize_t o2hb_region_dev_write(struct o2hb_region *reg, 1681static ssize_t o2hb_region_dev_store(struct config_item *item,
1681 const char *page, 1682 const char *page,
1682 size_t count) 1683 size_t count)
1683{ 1684{
1685 struct o2hb_region *reg = to_o2hb_region(item);
1684 struct task_struct *hb_task; 1686 struct task_struct *hb_task;
1685 long fd; 1687 long fd;
1686 int sectsize; 1688 int sectsize;
@@ -1841,9 +1843,9 @@ out:
1841 return ret; 1843 return ret;
1842} 1844}
1843 1845
1844static ssize_t o2hb_region_pid_read(struct o2hb_region *reg, 1846static ssize_t o2hb_region_pid_show(struct config_item *item, char *page)
1845 char *page)
1846{ 1847{
1848 struct o2hb_region *reg = to_o2hb_region(item);
1847 pid_t pid = 0; 1849 pid_t pid = 0;
1848 1850
1849 spin_lock(&o2hb_live_lock); 1851 spin_lock(&o2hb_live_lock);
@@ -1857,92 +1859,23 @@ static ssize_t o2hb_region_pid_read(struct o2hb_region *reg,
1857 return sprintf(page, "%u\n", pid); 1859 return sprintf(page, "%u\n", pid);
1858} 1860}
1859 1861
1860struct o2hb_region_attribute { 1862CONFIGFS_ATTR(o2hb_region_, block_bytes);
1861 struct configfs_attribute attr; 1863CONFIGFS_ATTR(o2hb_region_, start_block);
1862 ssize_t (*show)(struct o2hb_region *, char *); 1864CONFIGFS_ATTR(o2hb_region_, blocks);
1863 ssize_t (*store)(struct o2hb_region *, const char *, size_t); 1865CONFIGFS_ATTR(o2hb_region_, dev);
1864}; 1866CONFIGFS_ATTR_RO(o2hb_region_, pid);
1865
1866static struct o2hb_region_attribute o2hb_region_attr_block_bytes = {
1867 .attr = { .ca_owner = THIS_MODULE,
1868 .ca_name = "block_bytes",
1869 .ca_mode = S_IRUGO | S_IWUSR },
1870 .show = o2hb_region_block_bytes_read,
1871 .store = o2hb_region_block_bytes_write,
1872};
1873
1874static struct o2hb_region_attribute o2hb_region_attr_start_block = {
1875 .attr = { .ca_owner = THIS_MODULE,
1876 .ca_name = "start_block",
1877 .ca_mode = S_IRUGO | S_IWUSR },
1878 .show = o2hb_region_start_block_read,
1879 .store = o2hb_region_start_block_write,
1880};
1881
1882static struct o2hb_region_attribute o2hb_region_attr_blocks = {
1883 .attr = { .ca_owner = THIS_MODULE,
1884 .ca_name = "blocks",
1885 .ca_mode = S_IRUGO | S_IWUSR },
1886 .show = o2hb_region_blocks_read,
1887 .store = o2hb_region_blocks_write,
1888};
1889
1890static struct o2hb_region_attribute o2hb_region_attr_dev = {
1891 .attr = { .ca_owner = THIS_MODULE,
1892 .ca_name = "dev",
1893 .ca_mode = S_IRUGO | S_IWUSR },
1894 .show = o2hb_region_dev_read,
1895 .store = o2hb_region_dev_write,
1896};
1897
1898static struct o2hb_region_attribute o2hb_region_attr_pid = {
1899 .attr = { .ca_owner = THIS_MODULE,
1900 .ca_name = "pid",
1901 .ca_mode = S_IRUGO | S_IRUSR },
1902 .show = o2hb_region_pid_read,
1903};
1904 1867
1905static struct configfs_attribute *o2hb_region_attrs[] = { 1868static struct configfs_attribute *o2hb_region_attrs[] = {
1906 &o2hb_region_attr_block_bytes.attr, 1869 &o2hb_region_attr_block_bytes,
1907 &o2hb_region_attr_start_block.attr, 1870 &o2hb_region_attr_start_block,
1908 &o2hb_region_attr_blocks.attr, 1871 &o2hb_region_attr_blocks,
1909 &o2hb_region_attr_dev.attr, 1872 &o2hb_region_attr_dev,
1910 &o2hb_region_attr_pid.attr, 1873 &o2hb_region_attr_pid,
1911 NULL, 1874 NULL,
1912}; 1875};
1913 1876
1914static ssize_t o2hb_region_show(struct config_item *item,
1915 struct configfs_attribute *attr,
1916 char *page)
1917{
1918 struct o2hb_region *reg = to_o2hb_region(item);
1919 struct o2hb_region_attribute *o2hb_region_attr =
1920 container_of(attr, struct o2hb_region_attribute, attr);
1921 ssize_t ret = 0;
1922
1923 if (o2hb_region_attr->show)
1924 ret = o2hb_region_attr->show(reg, page);
1925 return ret;
1926}
1927
1928static ssize_t o2hb_region_store(struct config_item *item,
1929 struct configfs_attribute *attr,
1930 const char *page, size_t count)
1931{
1932 struct o2hb_region *reg = to_o2hb_region(item);
1933 struct o2hb_region_attribute *o2hb_region_attr =
1934 container_of(attr, struct o2hb_region_attribute, attr);
1935 ssize_t ret = -EINVAL;
1936
1937 if (o2hb_region_attr->store)
1938 ret = o2hb_region_attr->store(reg, page, count);
1939 return ret;
1940}
1941
1942static struct configfs_item_operations o2hb_region_item_ops = { 1877static struct configfs_item_operations o2hb_region_item_ops = {
1943 .release = o2hb_region_release, 1878 .release = o2hb_region_release,
1944 .show_attribute = o2hb_region_show,
1945 .store_attribute = o2hb_region_store,
1946}; 1879};
1947 1880
1948static struct config_item_type o2hb_region_type = { 1881static struct config_item_type o2hb_region_type = {
@@ -2137,49 +2070,14 @@ unlock:
2137 spin_unlock(&o2hb_live_lock); 2070 spin_unlock(&o2hb_live_lock);
2138} 2071}
2139 2072
2140struct o2hb_heartbeat_group_attribute { 2073static ssize_t o2hb_heartbeat_group_threshold_show(struct config_item *item,
2141 struct configfs_attribute attr; 2074 char *page)
2142 ssize_t (*show)(struct o2hb_heartbeat_group *, char *);
2143 ssize_t (*store)(struct o2hb_heartbeat_group *, const char *, size_t);
2144};
2145
2146static ssize_t o2hb_heartbeat_group_show(struct config_item *item,
2147 struct configfs_attribute *attr,
2148 char *page)
2149{
2150 struct o2hb_heartbeat_group *reg = to_o2hb_heartbeat_group(to_config_group(item));
2151 struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr =
2152 container_of(attr, struct o2hb_heartbeat_group_attribute, attr);
2153 ssize_t ret = 0;
2154
2155 if (o2hb_heartbeat_group_attr->show)
2156 ret = o2hb_heartbeat_group_attr->show(reg, page);
2157 return ret;
2158}
2159
2160static ssize_t o2hb_heartbeat_group_store(struct config_item *item,
2161 struct configfs_attribute *attr,
2162 const char *page, size_t count)
2163{
2164 struct o2hb_heartbeat_group *reg = to_o2hb_heartbeat_group(to_config_group(item));
2165 struct o2hb_heartbeat_group_attribute *o2hb_heartbeat_group_attr =
2166 container_of(attr, struct o2hb_heartbeat_group_attribute, attr);
2167 ssize_t ret = -EINVAL;
2168
2169 if (o2hb_heartbeat_group_attr->store)
2170 ret = o2hb_heartbeat_group_attr->store(reg, page, count);
2171 return ret;
2172}
2173
2174static ssize_t o2hb_heartbeat_group_threshold_show(struct o2hb_heartbeat_group *group,
2175 char *page)
2176{ 2075{
2177 return sprintf(page, "%u\n", o2hb_dead_threshold); 2076 return sprintf(page, "%u\n", o2hb_dead_threshold);
2178} 2077}
2179 2078
2180static ssize_t o2hb_heartbeat_group_threshold_store(struct o2hb_heartbeat_group *group, 2079static ssize_t o2hb_heartbeat_group_threshold_store(struct config_item *item,
2181 const char *page, 2080 const char *page, size_t count)
2182 size_t count)
2183{ 2081{
2184 unsigned long tmp; 2082 unsigned long tmp;
2185 char *p = (char *)page; 2083 char *p = (char *)page;
@@ -2194,17 +2092,15 @@ static ssize_t o2hb_heartbeat_group_threshold_store(struct o2hb_heartbeat_group
2194 return count; 2092 return count;
2195} 2093}
2196 2094
2197static 2095static ssize_t o2hb_heartbeat_group_mode_show(struct config_item *item,
2198ssize_t o2hb_heartbeat_group_mode_show(struct o2hb_heartbeat_group *group, 2096 char *page)
2199 char *page)
2200{ 2097{
2201 return sprintf(page, "%s\n", 2098 return sprintf(page, "%s\n",
2202 o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]); 2099 o2hb_heartbeat_mode_desc[o2hb_heartbeat_mode]);
2203} 2100}
2204 2101
2205static 2102static ssize_t o2hb_heartbeat_group_mode_store(struct config_item *item,
2206ssize_t o2hb_heartbeat_group_mode_store(struct o2hb_heartbeat_group *group, 2103 const char *page, size_t count)
2207 const char *page, size_t count)
2208{ 2104{
2209 unsigned int i; 2105 unsigned int i;
2210 int ret; 2106 int ret;
@@ -2229,33 +2125,15 @@ ssize_t o2hb_heartbeat_group_mode_store(struct o2hb_heartbeat_group *group,
2229 2125
2230} 2126}
2231 2127
2232static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_threshold = { 2128CONFIGFS_ATTR(o2hb_heartbeat_group_, threshold);
2233 .attr = { .ca_owner = THIS_MODULE, 2129CONFIGFS_ATTR(o2hb_heartbeat_group_, mode);
2234 .ca_name = "dead_threshold",
2235 .ca_mode = S_IRUGO | S_IWUSR },
2236 .show = o2hb_heartbeat_group_threshold_show,
2237 .store = o2hb_heartbeat_group_threshold_store,
2238};
2239
2240static struct o2hb_heartbeat_group_attribute o2hb_heartbeat_group_attr_mode = {
2241 .attr = { .ca_owner = THIS_MODULE,
2242 .ca_name = "mode",
2243 .ca_mode = S_IRUGO | S_IWUSR },
2244 .show = o2hb_heartbeat_group_mode_show,
2245 .store = o2hb_heartbeat_group_mode_store,
2246};
2247 2130
2248static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = { 2131static struct configfs_attribute *o2hb_heartbeat_group_attrs[] = {
2249 &o2hb_heartbeat_group_attr_threshold.attr, 2132 &o2hb_heartbeat_group_attr_threshold,
2250 &o2hb_heartbeat_group_attr_mode.attr, 2133 &o2hb_heartbeat_group_attr_mode,
2251 NULL, 2134 NULL,
2252}; 2135};
2253 2136
2254static struct configfs_item_operations o2hb_heartbeat_group_item_ops = {
2255 .show_attribute = o2hb_heartbeat_group_show,
2256 .store_attribute = o2hb_heartbeat_group_store,
2257};
2258
2259static struct configfs_group_operations o2hb_heartbeat_group_group_ops = { 2137static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
2260 .make_item = o2hb_heartbeat_group_make_item, 2138 .make_item = o2hb_heartbeat_group_make_item,
2261 .drop_item = o2hb_heartbeat_group_drop_item, 2139 .drop_item = o2hb_heartbeat_group_drop_item,
@@ -2263,7 +2141,6 @@ static struct configfs_group_operations o2hb_heartbeat_group_group_ops = {
2263 2141
2264static struct config_item_type o2hb_heartbeat_group_type = { 2142static struct config_item_type o2hb_heartbeat_group_type = {
2265 .ct_group_ops = &o2hb_heartbeat_group_group_ops, 2143 .ct_group_ops = &o2hb_heartbeat_group_group_ops,
2266 .ct_item_ops = &o2hb_heartbeat_group_item_ops,
2267 .ct_attrs = o2hb_heartbeat_group_attrs, 2144 .ct_attrs = o2hb_heartbeat_group_attrs,
2268 .ct_owner = THIS_MODULE, 2145 .ct_owner = THIS_MODULE,
2269}; 2146};
diff --git a/fs/ocfs2/cluster/nodemanager.c b/fs/ocfs2/cluster/nodemanager.c
index 441c84e169e6..72afdca3cea7 100644
--- a/fs/ocfs2/cluster/nodemanager.c
+++ b/fs/ocfs2/cluster/nodemanager.c
@@ -172,9 +172,9 @@ static void o2nm_node_release(struct config_item *item)
172 kfree(node); 172 kfree(node);
173} 173}
174 174
175static ssize_t o2nm_node_num_read(struct o2nm_node *node, char *page) 175static ssize_t o2nm_node_num_show(struct config_item *item, char *page)
176{ 176{
177 return sprintf(page, "%d\n", node->nd_num); 177 return sprintf(page, "%d\n", to_o2nm_node(item)->nd_num);
178} 178}
179 179
180static struct o2nm_cluster *to_o2nm_cluster_from_node(struct o2nm_node *node) 180static struct o2nm_cluster *to_o2nm_cluster_from_node(struct o2nm_node *node)
@@ -188,15 +188,16 @@ enum {
188 O2NM_NODE_ATTR_NUM = 0, 188 O2NM_NODE_ATTR_NUM = 0,
189 O2NM_NODE_ATTR_PORT, 189 O2NM_NODE_ATTR_PORT,
190 O2NM_NODE_ATTR_ADDRESS, 190 O2NM_NODE_ATTR_ADDRESS,
191 O2NM_NODE_ATTR_LOCAL,
192}; 191};
193 192
194static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page, 193static ssize_t o2nm_node_num_store(struct config_item *item, const char *page,
195 size_t count) 194 size_t count)
196{ 195{
196 struct o2nm_node *node = to_o2nm_node(item);
197 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node); 197 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
198 unsigned long tmp; 198 unsigned long tmp;
199 char *p = (char *)page; 199 char *p = (char *)page;
200 int ret = 0;
200 201
201 tmp = simple_strtoul(p, &p, 0); 202 tmp = simple_strtoul(p, &p, 0);
202 if (!p || (*p && (*p != '\n'))) 203 if (!p || (*p && (*p != '\n')))
@@ -215,26 +216,30 @@ static ssize_t o2nm_node_num_write(struct o2nm_node *node, const char *page,
215 216
216 write_lock(&cluster->cl_nodes_lock); 217 write_lock(&cluster->cl_nodes_lock);
217 if (cluster->cl_nodes[tmp]) 218 if (cluster->cl_nodes[tmp])
218 p = NULL; 219 ret = -EEXIST;
220 else if (test_and_set_bit(O2NM_NODE_ATTR_NUM,
221 &node->nd_set_attributes))
222 ret = -EBUSY;
219 else { 223 else {
220 cluster->cl_nodes[tmp] = node; 224 cluster->cl_nodes[tmp] = node;
221 node->nd_num = tmp; 225 node->nd_num = tmp;
222 set_bit(tmp, cluster->cl_nodes_bitmap); 226 set_bit(tmp, cluster->cl_nodes_bitmap);
223 } 227 }
224 write_unlock(&cluster->cl_nodes_lock); 228 write_unlock(&cluster->cl_nodes_lock);
225 if (p == NULL) 229 if (ret)
226 return -EEXIST; 230 return ret;
227 231
228 return count; 232 return count;
229} 233}
230static ssize_t o2nm_node_ipv4_port_read(struct o2nm_node *node, char *page) 234static ssize_t o2nm_node_ipv4_port_show(struct config_item *item, char *page)
231{ 235{
232 return sprintf(page, "%u\n", ntohs(node->nd_ipv4_port)); 236 return sprintf(page, "%u\n", ntohs(to_o2nm_node(item)->nd_ipv4_port));
233} 237}
234 238
235static ssize_t o2nm_node_ipv4_port_write(struct o2nm_node *node, 239static ssize_t o2nm_node_ipv4_port_store(struct config_item *item,
236 const char *page, size_t count) 240 const char *page, size_t count)
237{ 241{
242 struct o2nm_node *node = to_o2nm_node(item);
238 unsigned long tmp; 243 unsigned long tmp;
239 char *p = (char *)page; 244 char *p = (char *)page;
240 245
@@ -247,20 +252,23 @@ static ssize_t o2nm_node_ipv4_port_write(struct o2nm_node *node,
247 if (tmp >= (u16)-1) 252 if (tmp >= (u16)-1)
248 return -ERANGE; 253 return -ERANGE;
249 254
255 if (test_and_set_bit(O2NM_NODE_ATTR_PORT, &node->nd_set_attributes))
256 return -EBUSY;
250 node->nd_ipv4_port = htons(tmp); 257 node->nd_ipv4_port = htons(tmp);
251 258
252 return count; 259 return count;
253} 260}
254 261
255static ssize_t o2nm_node_ipv4_address_read(struct o2nm_node *node, char *page) 262static ssize_t o2nm_node_ipv4_address_show(struct config_item *item, char *page)
256{ 263{
257 return sprintf(page, "%pI4\n", &node->nd_ipv4_address); 264 return sprintf(page, "%pI4\n", &to_o2nm_node(item)->nd_ipv4_address);
258} 265}
259 266
260static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node, 267static ssize_t o2nm_node_ipv4_address_store(struct config_item *item,
261 const char *page, 268 const char *page,
262 size_t count) 269 size_t count)
263{ 270{
271 struct o2nm_node *node = to_o2nm_node(item);
264 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node); 272 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
265 int ret, i; 273 int ret, i;
266 struct rb_node **p, *parent; 274 struct rb_node **p, *parent;
@@ -282,6 +290,9 @@ static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node,
282 write_lock(&cluster->cl_nodes_lock); 290 write_lock(&cluster->cl_nodes_lock);
283 if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent)) 291 if (o2nm_node_ip_tree_lookup(cluster, ipv4_addr, &p, &parent))
284 ret = -EEXIST; 292 ret = -EEXIST;
293 else if (test_and_set_bit(O2NM_NODE_ATTR_ADDRESS,
294 &node->nd_set_attributes))
295 ret = -EBUSY;
285 else { 296 else {
286 rb_link_node(&node->nd_ip_node, parent, p); 297 rb_link_node(&node->nd_ip_node, parent, p);
287 rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree); 298 rb_insert_color(&node->nd_ip_node, &cluster->cl_node_ip_tree);
@@ -295,14 +306,15 @@ static ssize_t o2nm_node_ipv4_address_write(struct o2nm_node *node,
295 return count; 306 return count;
296} 307}
297 308
298static ssize_t o2nm_node_local_read(struct o2nm_node *node, char *page) 309static ssize_t o2nm_node_local_show(struct config_item *item, char *page)
299{ 310{
300 return sprintf(page, "%d\n", node->nd_local); 311 return sprintf(page, "%d\n", to_o2nm_node(item)->nd_local);
301} 312}
302 313
303static ssize_t o2nm_node_local_write(struct o2nm_node *node, const char *page, 314static ssize_t o2nm_node_local_store(struct config_item *item, const char *page,
304 size_t count) 315 size_t count)
305{ 316{
317 struct o2nm_node *node = to_o2nm_node(item);
306 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node); 318 struct o2nm_cluster *cluster = to_o2nm_cluster_from_node(node);
307 unsigned long tmp; 319 unsigned long tmp;
308 char *p = (char *)page; 320 char *p = (char *)page;
@@ -349,108 +361,21 @@ static ssize_t o2nm_node_local_write(struct o2nm_node *node, const char *page,
349 return count; 361 return count;
350} 362}
351 363
352struct o2nm_node_attribute { 364CONFIGFS_ATTR(o2nm_node_, num);
353 struct configfs_attribute attr; 365CONFIGFS_ATTR(o2nm_node_, ipv4_port);
354 ssize_t (*show)(struct o2nm_node *, char *); 366CONFIGFS_ATTR(o2nm_node_, ipv4_address);
355 ssize_t (*store)(struct o2nm_node *, const char *, size_t); 367CONFIGFS_ATTR(o2nm_node_, local);
356};
357
358static struct o2nm_node_attribute o2nm_node_attr_num = {
359 .attr = { .ca_owner = THIS_MODULE,
360 .ca_name = "num",
361 .ca_mode = S_IRUGO | S_IWUSR },
362 .show = o2nm_node_num_read,
363 .store = o2nm_node_num_write,
364};
365
366static struct o2nm_node_attribute o2nm_node_attr_ipv4_port = {
367 .attr = { .ca_owner = THIS_MODULE,
368 .ca_name = "ipv4_port",
369 .ca_mode = S_IRUGO | S_IWUSR },
370 .show = o2nm_node_ipv4_port_read,
371 .store = o2nm_node_ipv4_port_write,
372};
373
374static struct o2nm_node_attribute o2nm_node_attr_ipv4_address = {
375 .attr = { .ca_owner = THIS_MODULE,
376 .ca_name = "ipv4_address",
377 .ca_mode = S_IRUGO | S_IWUSR },
378 .show = o2nm_node_ipv4_address_read,
379 .store = o2nm_node_ipv4_address_write,
380};
381
382static struct o2nm_node_attribute o2nm_node_attr_local = {
383 .attr = { .ca_owner = THIS_MODULE,
384 .ca_name = "local",
385 .ca_mode = S_IRUGO | S_IWUSR },
386 .show = o2nm_node_local_read,
387 .store = o2nm_node_local_write,
388};
389 368
390static struct configfs_attribute *o2nm_node_attrs[] = { 369static struct configfs_attribute *o2nm_node_attrs[] = {
391 [O2NM_NODE_ATTR_NUM] = &o2nm_node_attr_num.attr, 370 &o2nm_node_attr_num,
392 [O2NM_NODE_ATTR_PORT] = &o2nm_node_attr_ipv4_port.attr, 371 &o2nm_node_attr_ipv4_port,
393 [O2NM_NODE_ATTR_ADDRESS] = &o2nm_node_attr_ipv4_address.attr, 372 &o2nm_node_attr_ipv4_address,
394 [O2NM_NODE_ATTR_LOCAL] = &o2nm_node_attr_local.attr, 373 &o2nm_node_attr_local,
395 NULL, 374 NULL,
396}; 375};
397 376
398static int o2nm_attr_index(struct configfs_attribute *attr)
399{
400 int i;
401 for (i = 0; i < ARRAY_SIZE(o2nm_node_attrs); i++) {
402 if (attr == o2nm_node_attrs[i])
403 return i;
404 }
405 BUG();
406 return 0;
407}
408
409static ssize_t o2nm_node_show(struct config_item *item,
410 struct configfs_attribute *attr,
411 char *page)
412{
413 struct o2nm_node *node = to_o2nm_node(item);
414 struct o2nm_node_attribute *o2nm_node_attr =
415 container_of(attr, struct o2nm_node_attribute, attr);
416 ssize_t ret = 0;
417
418 if (o2nm_node_attr->show)
419 ret = o2nm_node_attr->show(node, page);
420 return ret;
421}
422
423static ssize_t o2nm_node_store(struct config_item *item,
424 struct configfs_attribute *attr,
425 const char *page, size_t count)
426{
427 struct o2nm_node *node = to_o2nm_node(item);
428 struct o2nm_node_attribute *o2nm_node_attr =
429 container_of(attr, struct o2nm_node_attribute, attr);
430 ssize_t ret;
431 int attr_index = o2nm_attr_index(attr);
432
433 if (o2nm_node_attr->store == NULL) {
434 ret = -EINVAL;
435 goto out;
436 }
437
438 if (test_bit(attr_index, &node->nd_set_attributes))
439 return -EBUSY;
440
441 ret = o2nm_node_attr->store(node, page, count);
442 if (ret < count)
443 goto out;
444
445 set_bit(attr_index, &node->nd_set_attributes);
446out:
447 return ret;
448}
449
450static struct configfs_item_operations o2nm_node_item_ops = { 377static struct configfs_item_operations o2nm_node_item_ops = {
451 .release = o2nm_node_release, 378 .release = o2nm_node_release,
452 .show_attribute = o2nm_node_show,
453 .store_attribute = o2nm_node_store,
454}; 379};
455 380
456static struct config_item_type o2nm_node_type = { 381static struct config_item_type o2nm_node_type = {
@@ -475,12 +400,6 @@ static struct o2nm_node_group *to_o2nm_node_group(struct config_group *group)
475} 400}
476#endif 401#endif
477 402
478struct o2nm_cluster_attribute {
479 struct configfs_attribute attr;
480 ssize_t (*show)(struct o2nm_cluster *, char *);
481 ssize_t (*store)(struct o2nm_cluster *, const char *, size_t);
482};
483
484static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count, 403static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
485 unsigned int *val) 404 unsigned int *val)
486{ 405{
@@ -501,15 +420,16 @@ static ssize_t o2nm_cluster_attr_write(const char *page, ssize_t count,
501 return count; 420 return count;
502} 421}
503 422
504static ssize_t o2nm_cluster_attr_idle_timeout_ms_read( 423static ssize_t o2nm_cluster_idle_timeout_ms_show(struct config_item *item,
505 struct o2nm_cluster *cluster, char *page) 424 char *page)
506{ 425{
507 return sprintf(page, "%u\n", cluster->cl_idle_timeout_ms); 426 return sprintf(page, "%u\n", to_o2nm_cluster(item)->cl_idle_timeout_ms);
508} 427}
509 428
510static ssize_t o2nm_cluster_attr_idle_timeout_ms_write( 429static ssize_t o2nm_cluster_idle_timeout_ms_store(struct config_item *item,
511 struct o2nm_cluster *cluster, const char *page, size_t count) 430 const char *page, size_t count)
512{ 431{
432 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
513 ssize_t ret; 433 ssize_t ret;
514 unsigned int val; 434 unsigned int val;
515 435
@@ -536,15 +456,17 @@ static ssize_t o2nm_cluster_attr_idle_timeout_ms_write(
536 return ret; 456 return ret;
537} 457}
538 458
539static ssize_t o2nm_cluster_attr_keepalive_delay_ms_read( 459static ssize_t o2nm_cluster_keepalive_delay_ms_show(
540 struct o2nm_cluster *cluster, char *page) 460 struct config_item *item, char *page)
541{ 461{
542 return sprintf(page, "%u\n", cluster->cl_keepalive_delay_ms); 462 return sprintf(page, "%u\n",
463 to_o2nm_cluster(item)->cl_keepalive_delay_ms);
543} 464}
544 465
545static ssize_t o2nm_cluster_attr_keepalive_delay_ms_write( 466static ssize_t o2nm_cluster_keepalive_delay_ms_store(
546 struct o2nm_cluster *cluster, const char *page, size_t count) 467 struct config_item *item, const char *page, size_t count)
547{ 468{
469 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
548 ssize_t ret; 470 ssize_t ret;
549 unsigned int val; 471 unsigned int val;
550 472
@@ -571,22 +493,24 @@ static ssize_t o2nm_cluster_attr_keepalive_delay_ms_write(
571 return ret; 493 return ret;
572} 494}
573 495
574static ssize_t o2nm_cluster_attr_reconnect_delay_ms_read( 496static ssize_t o2nm_cluster_reconnect_delay_ms_show(
575 struct o2nm_cluster *cluster, char *page) 497 struct config_item *item, char *page)
576{ 498{
577 return sprintf(page, "%u\n", cluster->cl_reconnect_delay_ms); 499 return sprintf(page, "%u\n",
500 to_o2nm_cluster(item)->cl_reconnect_delay_ms);
578} 501}
579 502
580static ssize_t o2nm_cluster_attr_reconnect_delay_ms_write( 503static ssize_t o2nm_cluster_reconnect_delay_ms_store(
581 struct o2nm_cluster *cluster, const char *page, size_t count) 504 struct config_item *item, const char *page, size_t count)
582{ 505{
583 return o2nm_cluster_attr_write(page, count, 506 return o2nm_cluster_attr_write(page, count,
584 &cluster->cl_reconnect_delay_ms); 507 &to_o2nm_cluster(item)->cl_reconnect_delay_ms);
585} 508}
586 509
587static ssize_t o2nm_cluster_attr_fence_method_read( 510static ssize_t o2nm_cluster_fence_method_show(
588 struct o2nm_cluster *cluster, char *page) 511 struct config_item *item, char *page)
589{ 512{
513 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
590 ssize_t ret = 0; 514 ssize_t ret = 0;
591 515
592 if (cluster) 516 if (cluster)
@@ -595,8 +519,8 @@ static ssize_t o2nm_cluster_attr_fence_method_read(
595 return ret; 519 return ret;
596} 520}
597 521
598static ssize_t o2nm_cluster_attr_fence_method_write( 522static ssize_t o2nm_cluster_fence_method_store(
599 struct o2nm_cluster *cluster, const char *page, size_t count) 523 struct config_item *item, const char *page, size_t count)
600{ 524{
601 unsigned int i; 525 unsigned int i;
602 526
@@ -608,10 +532,10 @@ static ssize_t o2nm_cluster_attr_fence_method_write(
608 continue; 532 continue;
609 if (strncasecmp(page, o2nm_fence_method_desc[i], count - 1)) 533 if (strncasecmp(page, o2nm_fence_method_desc[i], count - 1))
610 continue; 534 continue;
611 if (cluster->cl_fence_method != i) { 535 if (to_o2nm_cluster(item)->cl_fence_method != i) {
612 printk(KERN_INFO "ocfs2: Changing fence method to %s\n", 536 printk(KERN_INFO "ocfs2: Changing fence method to %s\n",
613 o2nm_fence_method_desc[i]); 537 o2nm_fence_method_desc[i]);
614 cluster->cl_fence_method = i; 538 to_o2nm_cluster(item)->cl_fence_method = i;
615 } 539 }
616 return count; 540 return count;
617 } 541 }
@@ -620,79 +544,18 @@ bail:
620 return -EINVAL; 544 return -EINVAL;
621} 545}
622 546
623static struct o2nm_cluster_attribute o2nm_cluster_attr_idle_timeout_ms = { 547CONFIGFS_ATTR(o2nm_cluster_, idle_timeout_ms);
624 .attr = { .ca_owner = THIS_MODULE, 548CONFIGFS_ATTR(o2nm_cluster_, keepalive_delay_ms);
625 .ca_name = "idle_timeout_ms", 549CONFIGFS_ATTR(o2nm_cluster_, reconnect_delay_ms);
626 .ca_mode = S_IRUGO | S_IWUSR }, 550CONFIGFS_ATTR(o2nm_cluster_, fence_method);
627 .show = o2nm_cluster_attr_idle_timeout_ms_read,
628 .store = o2nm_cluster_attr_idle_timeout_ms_write,
629};
630
631static struct o2nm_cluster_attribute o2nm_cluster_attr_keepalive_delay_ms = {
632 .attr = { .ca_owner = THIS_MODULE,
633 .ca_name = "keepalive_delay_ms",
634 .ca_mode = S_IRUGO | S_IWUSR },
635 .show = o2nm_cluster_attr_keepalive_delay_ms_read,
636 .store = o2nm_cluster_attr_keepalive_delay_ms_write,
637};
638
639static struct o2nm_cluster_attribute o2nm_cluster_attr_reconnect_delay_ms = {
640 .attr = { .ca_owner = THIS_MODULE,
641 .ca_name = "reconnect_delay_ms",
642 .ca_mode = S_IRUGO | S_IWUSR },
643 .show = o2nm_cluster_attr_reconnect_delay_ms_read,
644 .store = o2nm_cluster_attr_reconnect_delay_ms_write,
645};
646
647static struct o2nm_cluster_attribute o2nm_cluster_attr_fence_method = {
648 .attr = { .ca_owner = THIS_MODULE,
649 .ca_name = "fence_method",
650 .ca_mode = S_IRUGO | S_IWUSR },
651 .show = o2nm_cluster_attr_fence_method_read,
652 .store = o2nm_cluster_attr_fence_method_write,
653};
654 551
655static struct configfs_attribute *o2nm_cluster_attrs[] = { 552static struct configfs_attribute *o2nm_cluster_attrs[] = {
656 &o2nm_cluster_attr_idle_timeout_ms.attr, 553 &o2nm_cluster_attr_idle_timeout_ms,
657 &o2nm_cluster_attr_keepalive_delay_ms.attr, 554 &o2nm_cluster_attr_keepalive_delay_ms,
658 &o2nm_cluster_attr_reconnect_delay_ms.attr, 555 &o2nm_cluster_attr_reconnect_delay_ms,
659 &o2nm_cluster_attr_fence_method.attr, 556 &o2nm_cluster_attr_fence_method,
660 NULL, 557 NULL,
661}; 558};
662static ssize_t o2nm_cluster_show(struct config_item *item,
663 struct configfs_attribute *attr,
664 char *page)
665{
666 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
667 struct o2nm_cluster_attribute *o2nm_cluster_attr =
668 container_of(attr, struct o2nm_cluster_attribute, attr);
669 ssize_t ret = 0;
670
671 if (o2nm_cluster_attr->show)
672 ret = o2nm_cluster_attr->show(cluster, page);
673 return ret;
674}
675
676static ssize_t o2nm_cluster_store(struct config_item *item,
677 struct configfs_attribute *attr,
678 const char *page, size_t count)
679{
680 struct o2nm_cluster *cluster = to_o2nm_cluster(item);
681 struct o2nm_cluster_attribute *o2nm_cluster_attr =
682 container_of(attr, struct o2nm_cluster_attribute, attr);
683 ssize_t ret;
684
685 if (o2nm_cluster_attr->store == NULL) {
686 ret = -EINVAL;
687 goto out;
688 }
689
690 ret = o2nm_cluster_attr->store(cluster, page, count);
691 if (ret < count)
692 goto out;
693out:
694 return ret;
695}
696 559
697static struct config_item *o2nm_node_group_make_item(struct config_group *group, 560static struct config_item *o2nm_node_group_make_item(struct config_group *group,
698 const char *name) 561 const char *name)
@@ -773,8 +636,6 @@ static void o2nm_cluster_release(struct config_item *item)
773 636
774static struct configfs_item_operations o2nm_cluster_item_ops = { 637static struct configfs_item_operations o2nm_cluster_item_ops = {
775 .release = o2nm_cluster_release, 638 .release = o2nm_cluster_release,
776 .show_attribute = o2nm_cluster_show,
777 .store_attribute = o2nm_cluster_store,
778}; 639};
779 640
780static struct config_item_type o2nm_cluster_type = { 641static struct config_item_type o2nm_cluster_type = {
diff --git a/include/linux/configfs.h b/include/linux/configfs.h
index 63a36e89d0eb..a8a335b7fce0 100644
--- a/include/linux/configfs.h
+++ b/include/linux/configfs.h
@@ -125,86 +125,33 @@ struct configfs_attribute {
125 const char *ca_name; 125 const char *ca_name;
126 struct module *ca_owner; 126 struct module *ca_owner;
127 umode_t ca_mode; 127 umode_t ca_mode;
128 ssize_t (*show)(struct config_item *, char *);
129 ssize_t (*store)(struct config_item *, const char *, size_t);
128}; 130};
129 131
130/* 132#define CONFIGFS_ATTR(_pfx, _name) \
131 * Users often need to create attribute structures for their configurable 133static struct configfs_attribute _pfx##attr_##_name = { \
132 * attributes, containing a configfs_attribute member and function pointers 134 .ca_name = __stringify(_name), \
133 * for the show() and store() operations on that attribute. If they don't 135 .ca_mode = S_IRUGO | S_IWUSR, \
134 * need anything else on the extended attribute structure, they can use 136 .ca_owner = THIS_MODULE, \
135 * this macro to define it The argument _item is the name of the 137 .show = _pfx##_name##_show, \
136 * config_item structure. 138 .store = _pfx##_name##_store, \
137 */
138#define CONFIGFS_ATTR_STRUCT(_item) \
139struct _item##_attribute { \
140 struct configfs_attribute attr; \
141 ssize_t (*show)(struct _item *, char *); \
142 ssize_t (*store)(struct _item *, const char *, size_t); \
143} 139}
144 140
145/* 141#define CONFIGFS_ATTR_RO(_pfx, _name) \
146 * With the extended attribute structure, users can use this macro 142static struct configfs_attribute _pfx##attr_##_name = { \
147 * (similar to sysfs' __ATTR) to make defining attributes easier. 143 .ca_name = __stringify(_name), \
148 * An example: 144 .ca_mode = S_IRUGO, \
149 * #define MYITEM_ATTR(_name, _mode, _show, _store) \ 145 .ca_owner = THIS_MODULE, \
150 * struct myitem_attribute childless_attr_##_name = \ 146 .show = _pfx##_name##_show, \
151 * __CONFIGFS_ATTR(_name, _mode, _show, _store)
152 */
153#define __CONFIGFS_ATTR(_name, _mode, _show, _store) \
154{ \
155 .attr = { \
156 .ca_name = __stringify(_name), \
157 .ca_mode = _mode, \
158 .ca_owner = THIS_MODULE, \
159 }, \
160 .show = _show, \
161 .store = _store, \
162}
163/* Here is a readonly version, only requiring a show() operation */
164#define __CONFIGFS_ATTR_RO(_name, _show) \
165{ \
166 .attr = { \
167 .ca_name = __stringify(_name), \
168 .ca_mode = 0444, \
169 .ca_owner = THIS_MODULE, \
170 }, \
171 .show = _show, \
172} 147}
173 148
174/* 149#define CONFIGFS_ATTR_WO(_pfx, _name) \
175 * With these extended attributes, the simple show_attribute() and 150static struct configfs_attribute _pfx##attr_##_name = { \
176 * store_attribute() operations need to call the show() and store() of the 151 .ca_name = __stringify(_name), \
177 * attributes. This is a common pattern, so we provide a macro to define 152 .ca_mode = S_IWUSR, \
178 * them. The argument _item is the name of the config_item structure. 153 .ca_owner = THIS_MODULE, \
179 * This macro expects the attributes to be named "struct <name>_attribute" 154 .store = _pfx##_name##_store, \
180 * and the function to_<name>() to exist;
181 */
182#define CONFIGFS_ATTR_OPS(_item) \
183static ssize_t _item##_attr_show(struct config_item *item, \
184 struct configfs_attribute *attr, \
185 char *page) \
186{ \
187 struct _item *_item = to_##_item(item); \
188 struct _item##_attribute *_item##_attr = \
189 container_of(attr, struct _item##_attribute, attr); \
190 ssize_t ret = 0; \
191 \
192 if (_item##_attr->show) \
193 ret = _item##_attr->show(_item, page); \
194 return ret; \
195} \
196static ssize_t _item##_attr_store(struct config_item *item, \
197 struct configfs_attribute *attr, \
198 const char *page, size_t count) \
199{ \
200 struct _item *_item = to_##_item(item); \
201 struct _item##_attribute *_item##_attr = \
202 container_of(attr, struct _item##_attribute, attr); \
203 ssize_t ret = -EINVAL; \
204 \
205 if (_item##_attr->store) \
206 ret = _item##_attr->store(_item, page, count); \
207 return ret; \
208} 155}
209 156
210/* 157/*
@@ -223,8 +170,6 @@ static ssize_t _item##_attr_store(struct config_item *item, \
223 */ 170 */
224struct configfs_item_operations { 171struct configfs_item_operations {
225 void (*release)(struct config_item *); 172 void (*release)(struct config_item *);
226 ssize_t (*show_attribute)(struct config_item *, struct configfs_attribute *,char *);
227 ssize_t (*store_attribute)(struct config_item *,struct configfs_attribute *,const char *, size_t);
228 int (*allow_link)(struct config_item *src, struct config_item *target); 173 int (*allow_link)(struct config_item *src, struct config_item *target);
229 int (*drop_link)(struct config_item *src, struct config_item *target); 174 int (*drop_link)(struct config_item *src, struct config_item *target);
230}; 175};
diff --git a/include/linux/usb/gadget_configfs.h b/include/linux/usb/gadget_configfs.h
index d74c0ae989d5..c36e95730de1 100644
--- a/include/linux/usb/gadget_configfs.h
+++ b/include/linux/usb/gadget_configfs.h
@@ -7,9 +7,10 @@ int check_user_usb_string(const char *name,
7 struct usb_gadget_strings *stringtab_dev); 7 struct usb_gadget_strings *stringtab_dev);
8 8
9#define GS_STRINGS_W(__struct, __name) \ 9#define GS_STRINGS_W(__struct, __name) \
10 static ssize_t __struct##_##__name##_store(struct __struct *gs, \ 10static ssize_t __struct##_##__name##_store(struct config_item *item, \
11 const char *page, size_t len) \ 11 const char *page, size_t len) \
12{ \ 12{ \
13 struct __struct *gs = to_##__struct(item); \
13 int ret; \ 14 int ret; \
14 \ 15 \
15 ret = usb_string_copy(page, &gs->__name); \ 16 ret = usb_string_copy(page, &gs->__name); \
@@ -19,30 +20,20 @@ int check_user_usb_string(const char *name,
19} 20}
20 21
21#define GS_STRINGS_R(__struct, __name) \ 22#define GS_STRINGS_R(__struct, __name) \
22 static ssize_t __struct##_##__name##_show(struct __struct *gs, \ 23static ssize_t __struct##_##__name##_show(struct config_item *item, char *page) \
23 char *page) \
24{ \ 24{ \
25 struct __struct *gs = to_##__struct(item); \
25 return sprintf(page, "%s\n", gs->__name ?: ""); \ 26 return sprintf(page, "%s\n", gs->__name ?: ""); \
26} 27}
27 28
28#define GS_STRING_ITEM_ATTR(struct_name, name) \
29 static struct struct_name##_attribute struct_name##_##name = \
30 __CONFIGFS_ATTR(name, S_IRUGO | S_IWUSR, \
31 struct_name##_##name##_show, \
32 struct_name##_##name##_store)
33
34#define GS_STRINGS_RW(struct_name, _name) \ 29#define GS_STRINGS_RW(struct_name, _name) \
35 GS_STRINGS_R(struct_name, _name) \ 30 GS_STRINGS_R(struct_name, _name) \
36 GS_STRINGS_W(struct_name, _name) \ 31 GS_STRINGS_W(struct_name, _name) \
37 GS_STRING_ITEM_ATTR(struct_name, _name) 32 CONFIGFS_ATTR(struct_name##_, _name)
38 33
39#define USB_CONFIG_STRING_RW_OPS(struct_in) \ 34#define USB_CONFIG_STRING_RW_OPS(struct_in) \
40 CONFIGFS_ATTR_OPS(struct_in); \
41 \
42static struct configfs_item_operations struct_in##_langid_item_ops = { \ 35static struct configfs_item_operations struct_in##_langid_item_ops = { \
43 .release = struct_in##_attr_release, \ 36 .release = struct_in##_attr_release, \
44 .show_attribute = struct_in##_attr_show, \
45 .store_attribute = struct_in##_attr_store, \
46}; \ 37}; \
47 \ 38 \
48static struct config_item_type struct_in##_langid_type = { \ 39static struct config_item_type struct_in##_langid_type = { \
diff --git a/include/target/configfs_macros.h b/include/target/configfs_macros.h
deleted file mode 100644
index a0fc85bbe2da..000000000000
--- a/include/target/configfs_macros.h
+++ /dev/null
@@ -1,147 +0,0 @@
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * configfs_macros.h - extends macros for configfs
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public
17 * License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 021110-1307, USA.
20 *
21 * Based on sysfs:
22 * sysfs is Copyright (C) 2001, 2002, 2003 Patrick Mochel
23 *
24 * Based on kobject.h:
25 * Copyright (c) 2002-2003 Patrick Mochel
26 * Copyright (c) 2002-2003 Open Source Development Labs
27 *
28 * configfs Copyright (C) 2005 Oracle. All rights reserved.
29 *
30 * Added CONFIGFS_EATTR() macros from original configfs.h macros
31 * Copright (C) 2008-2009 Nicholas A. Bellinger <nab@linux-iscsi.org>
32 *
33 * Please read Documentation/filesystems/configfs/configfs.txt before using
34 * the configfs interface, ESPECIALLY the parts about reference counts and
35 * item destructors.
36 */
37
38#ifndef _CONFIGFS_MACROS_H_
39#define _CONFIGFS_MACROS_H_
40
41#include <linux/configfs.h>
42
43/*
44 * Users often need to create attribute structures for their configurable
45 * attributes, containing a configfs_attribute member and function pointers
46 * for the show() and store() operations on that attribute. If they don't
47 * need anything else on the extended attribute structure, they can use
48 * this macro to define it. The argument _name isends up as
49 * 'struct _name_attribute, as well as names of to CONFIGFS_ATTR_OPS() below.
50 * The argument _item is the name of the structure containing the
51 * struct config_item or struct config_group structure members
52 */
53#define CONFIGFS_EATTR_STRUCT(_name, _item) \
54struct _name##_attribute { \
55 struct configfs_attribute attr; \
56 ssize_t (*show)(struct _item *, char *); \
57 ssize_t (*store)(struct _item *, const char *, size_t); \
58}
59
60/*
61 * With the extended attribute structure, users can use this macro
62 * (similar to sysfs' __ATTR) to make defining attributes easier.
63 * An example:
64 * #define MYITEM_EATTR(_name, _mode, _show, _store) \
65 * struct myitem_attribute childless_attr_##_name = \
66 * __CONFIGFS_EATTR(_name, _mode, _show, _store)
67 */
68#define __CONFIGFS_EATTR(_name, _mode, _show, _store) \
69{ \
70 .attr = { \
71 .ca_name = __stringify(_name), \
72 .ca_mode = _mode, \
73 .ca_owner = THIS_MODULE, \
74 }, \
75 .show = _show, \
76 .store = _store, \
77}
78/* Here is a readonly version, only requiring a show() operation */
79#define __CONFIGFS_EATTR_RO(_name, _show) \
80{ \
81 .attr = { \
82 .ca_name = __stringify(_name), \
83 .ca_mode = 0444, \
84 .ca_owner = THIS_MODULE, \
85 }, \
86 .show = _show, \
87}
88
89/*
90 * With these extended attributes, the simple show_attribute() and
91 * store_attribute() operations need to call the show() and store() of the
92 * attributes. This is a common pattern, so we provide a macro to define
93 * them. The argument _name is the name of the attribute defined by
94 * CONFIGFS_ATTR_STRUCT(). The argument _item is the name of the structure
95 * containing the struct config_item or struct config_group structure member.
96 * The argument _item_member is the actual name of the struct config_* struct
97 * in your _item structure. Meaning my_structure->some_config_group.
98 * ^^_item^^^^^ ^^_item_member^^^
99 * This macro expects the attributes to be named "struct <name>_attribute".
100 */
101#define CONFIGFS_EATTR_OPS_TO_FUNC(_name, _item, _item_member) \
102static struct _item *to_##_name(struct config_item *ci) \
103{ \
104 return (ci) ? container_of(to_config_group(ci), struct _item, \
105 _item_member) : NULL; \
106}
107
108#define CONFIGFS_EATTR_OPS_SHOW(_name, _item) \
109static ssize_t _name##_attr_show(struct config_item *item, \
110 struct configfs_attribute *attr, \
111 char *page) \
112{ \
113 struct _item *_item = to_##_name(item); \
114 struct _name##_attribute * _name##_attr = \
115 container_of(attr, struct _name##_attribute, attr); \
116 ssize_t ret = 0; \
117 \
118 if (_name##_attr->show) \
119 ret = _name##_attr->show(_item, page); \
120 return ret; \
121}
122
123#define CONFIGFS_EATTR_OPS_STORE(_name, _item) \
124static ssize_t _name##_attr_store(struct config_item *item, \
125 struct configfs_attribute *attr, \
126 const char *page, size_t count) \
127{ \
128 struct _item *_item = to_##_name(item); \
129 struct _name##_attribute * _name##_attr = \
130 container_of(attr, struct _name##_attribute, attr); \
131 ssize_t ret = -EINVAL; \
132 \
133 if (_name##_attr->store) \
134 ret = _name##_attr->store(_item, page, count); \
135 return ret; \
136}
137
138#define CONFIGFS_EATTR_OPS(_name, _item, _item_member) \
139 CONFIGFS_EATTR_OPS_TO_FUNC(_name, _item, _item_member); \
140 CONFIGFS_EATTR_OPS_SHOW(_name, _item); \
141 CONFIGFS_EATTR_OPS_STORE(_name, _item);
142
143#define CONFIGFS_EATTR_OPS_RO(_name, _item, _item_member) \
144 CONFIGFS_EATTR_OPS_TO_FUNC(_name, _item, _item_member); \
145 CONFIGFS_EATTR_OPS_SHOW(_name, _item);
146
147#endif /* _CONFIGFS_MACROS_H_ */
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 5f48754dc36a..0a2c74008e53 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -563,6 +563,36 @@ struct se_node_acl {
563 struct kref acl_kref; 563 struct kref acl_kref;
564}; 564};
565 565
566static inline struct se_node_acl *acl_to_nacl(struct config_item *item)
567{
568 return container_of(to_config_group(item), struct se_node_acl,
569 acl_group);
570}
571
572static inline struct se_node_acl *attrib_to_nacl(struct config_item *item)
573{
574 return container_of(to_config_group(item), struct se_node_acl,
575 acl_attrib_group);
576}
577
578static inline struct se_node_acl *auth_to_nacl(struct config_item *item)
579{
580 return container_of(to_config_group(item), struct se_node_acl,
581 acl_auth_group);
582}
583
584static inline struct se_node_acl *param_to_nacl(struct config_item *item)
585{
586 return container_of(to_config_group(item), struct se_node_acl,
587 acl_param_group);
588}
589
590static inline struct se_node_acl *fabric_stat_to_nacl(struct config_item *item)
591{
592 return container_of(to_config_group(item), struct se_node_acl,
593 acl_fabric_stat_group);
594}
595
566struct se_session { 596struct se_session {
567 unsigned sess_tearing_down:1; 597 unsigned sess_tearing_down:1;
568 u64 sess_bin_isid; 598 u64 sess_bin_isid;
@@ -821,6 +851,12 @@ struct se_tpg_np {
821 struct config_group tpg_np_group; 851 struct config_group tpg_np_group;
822}; 852};
823 853
854static inline struct se_tpg_np *to_tpg_np(struct config_item *item)
855{
856 return container_of(to_config_group(item), struct se_tpg_np,
857 tpg_np_group);
858}
859
824struct se_portal_group { 860struct se_portal_group {
825 /* 861 /*
826 * PROTOCOL IDENTIFIER value per SPC4, 7.5.1. 862 * PROTOCOL IDENTIFIER value per SPC4, 7.5.1.
@@ -857,6 +893,30 @@ struct se_portal_group {
857 struct config_group tpg_param_group; 893 struct config_group tpg_param_group;
858}; 894};
859 895
896static inline struct se_portal_group *to_tpg(struct config_item *item)
897{
898 return container_of(to_config_group(item), struct se_portal_group,
899 tpg_group);
900}
901
902static inline struct se_portal_group *attrib_to_tpg(struct config_item *item)
903{
904 return container_of(to_config_group(item), struct se_portal_group,
905 tpg_attrib_group);
906}
907
908static inline struct se_portal_group *auth_to_tpg(struct config_item *item)
909{
910 return container_of(to_config_group(item), struct se_portal_group,
911 tpg_auth_group);
912}
913
914static inline struct se_portal_group *param_to_tpg(struct config_item *item)
915{
916 return container_of(to_config_group(item), struct se_portal_group,
917 tpg_param_group);
918}
919
860struct se_wwn { 920struct se_wwn {
861 struct target_fabric_configfs *wwn_tf; 921 struct target_fabric_configfs *wwn_tf;
862 struct config_group wwn_group; 922 struct config_group wwn_group;
diff --git a/include/target/target_core_fabric_configfs.h b/include/target/target_core_fabric_configfs.h
deleted file mode 100644
index 7a0649c09e79..000000000000
--- a/include/target/target_core_fabric_configfs.h
+++ /dev/null
@@ -1,122 +0,0 @@
1/*
2 * Used for tfc_wwn_cit attributes
3 */
4
5#include <target/configfs_macros.h>
6
7CONFIGFS_EATTR_STRUCT(target_fabric_nacl_attrib, se_node_acl);
8#define TF_NACL_ATTRIB_ATTR(_fabric, _name, _mode) \
9static struct target_fabric_nacl_attrib_attribute _fabric##_nacl_attrib_##_name = \
10 __CONFIGFS_EATTR(_name, _mode, \
11 _fabric##_nacl_attrib_show_##_name, \
12 _fabric##_nacl_attrib_store_##_name);
13
14CONFIGFS_EATTR_STRUCT(target_fabric_nacl_auth, se_node_acl);
15#define TF_NACL_AUTH_ATTR(_fabric, _name, _mode) \
16static struct target_fabric_nacl_auth_attribute _fabric##_nacl_auth_##_name = \
17 __CONFIGFS_EATTR(_name, _mode, \
18 _fabric##_nacl_auth_show_##_name, \
19 _fabric##_nacl_auth_store_##_name);
20
21#define TF_NACL_AUTH_ATTR_RO(_fabric, _name) \
22static struct target_fabric_nacl_auth_attribute _fabric##_nacl_auth_##_name = \
23 __CONFIGFS_EATTR_RO(_name, \
24 _fabric##_nacl_auth_show_##_name);
25
26CONFIGFS_EATTR_STRUCT(target_fabric_nacl_param, se_node_acl);
27#define TF_NACL_PARAM_ATTR(_fabric, _name, _mode) \
28static struct target_fabric_nacl_param_attribute _fabric##_nacl_param_##_name = \
29 __CONFIGFS_EATTR(_name, _mode, \
30 _fabric##_nacl_param_show_##_name, \
31 _fabric##_nacl_param_store_##_name);
32
33#define TF_NACL_PARAM_ATTR_RO(_fabric, _name) \
34static struct target_fabric_nacl_param_attribute _fabric##_nacl_param_##_name = \
35 __CONFIGFS_EATTR_RO(_name, \
36 _fabric##_nacl_param_show_##_name);
37
38
39CONFIGFS_EATTR_STRUCT(target_fabric_nacl_base, se_node_acl);
40#define TF_NACL_BASE_ATTR(_fabric, _name, _mode) \
41static struct target_fabric_nacl_base_attribute _fabric##_nacl_##_name = \
42 __CONFIGFS_EATTR(_name, _mode, \
43 _fabric##_nacl_show_##_name, \
44 _fabric##_nacl_store_##_name);
45
46#define TF_NACL_BASE_ATTR_RO(_fabric, _name) \
47static struct target_fabric_nacl_base_attribute _fabric##_nacl_##_name = \
48 __CONFIGFS_EATTR_RO(_name, \
49 _fabric##_nacl_show_##_name);
50
51CONFIGFS_EATTR_STRUCT(target_fabric_np_base, se_tpg_np);
52#define TF_NP_BASE_ATTR(_fabric, _name, _mode) \
53static struct target_fabric_np_base_attribute _fabric##_np_##_name = \
54 __CONFIGFS_EATTR(_name, _mode, \
55 _fabric##_np_show_##_name, \
56 _fabric##_np_store_##_name);
57
58CONFIGFS_EATTR_STRUCT(target_fabric_tpg_attrib, se_portal_group);
59#define TF_TPG_ATTRIB_ATTR(_fabric, _name, _mode) \
60static struct target_fabric_tpg_attrib_attribute _fabric##_tpg_attrib_##_name = \
61 __CONFIGFS_EATTR(_name, _mode, \
62 _fabric##_tpg_attrib_show_##_name, \
63 _fabric##_tpg_attrib_store_##_name);
64
65CONFIGFS_EATTR_STRUCT(target_fabric_tpg_auth, se_portal_group);
66#define TF_TPG_AUTH_ATTR(_fabric, _name, _mode) \
67static struct target_fabric_tpg_auth_attribute _fabric##_tpg_auth_##_name = \
68 __CONFIGFS_EATTR(_name, _mode, \
69 _fabric##_tpg_auth_show_##_name, \
70 _fabric##_tpg_auth_store_##_name);
71
72#define TF_TPG_AUTH_ATTR_RO(_fabric, _name) \
73static struct target_fabric_tpg_auth_attribute _fabric##_tpg_auth_##_name = \
74 __CONFIGFS_EATTR_RO(_name, \
75 _fabric##_tpg_auth_show_##_name);
76
77CONFIGFS_EATTR_STRUCT(target_fabric_tpg_param, se_portal_group);
78#define TF_TPG_PARAM_ATTR(_fabric, _name, _mode) \
79static struct target_fabric_tpg_param_attribute _fabric##_tpg_param_##_name = \
80 __CONFIGFS_EATTR(_name, _mode, \
81 _fabric##_tpg_param_show_##_name, \
82 _fabric##_tpg_param_store_##_name);
83
84
85CONFIGFS_EATTR_STRUCT(target_fabric_tpg, se_portal_group);
86#define TF_TPG_BASE_ATTR(_fabric, _name, _mode) \
87static struct target_fabric_tpg_attribute _fabric##_tpg_##_name = \
88 __CONFIGFS_EATTR(_name, _mode, \
89 _fabric##_tpg_show_##_name, \
90 _fabric##_tpg_store_##_name);
91
92
93#define TF_TPG_BASE_ATTR_RO(_fabric, _name) \
94static struct target_fabric_tpg_attribute _fabric##_tpg_##_name = \
95 __CONFIGFS_EATTR_RO(_name, \
96 _fabric##_tpg_show_##_name);
97
98CONFIGFS_EATTR_STRUCT(target_fabric_wwn, target_fabric_configfs);
99#define TF_WWN_ATTR(_fabric, _name, _mode) \
100static struct target_fabric_wwn_attribute _fabric##_wwn_##_name = \
101 __CONFIGFS_EATTR(_name, _mode, \
102 _fabric##_wwn_show_attr_##_name, \
103 _fabric##_wwn_store_attr_##_name);
104
105#define TF_WWN_ATTR_RO(_fabric, _name) \
106static struct target_fabric_wwn_attribute _fabric##_wwn_##_name = \
107 __CONFIGFS_EATTR_RO(_name, \
108 _fabric##_wwn_show_attr_##_name);
109
110CONFIGFS_EATTR_STRUCT(target_fabric_discovery, target_fabric_configfs);
111#define TF_DISC_ATTR(_fabric, _name, _mode) \
112static struct target_fabric_discovery_attribute _fabric##_disc_##_name = \
113 __CONFIGFS_EATTR(_name, _mode, \
114 _fabric##_disc_show_##_name, \
115 _fabric##_disc_store_##_name);
116
117#define TF_DISC_ATTR_RO(_fabric, _name) \
118static struct target_fabric_discovery_attribute _fabric##_disc_##_name = \
119 __CONFIGFS_EATTR_RO(_name, \
120 _fabric##_disc_show_##_name);
121
122extern int target_fabric_setup_cits(struct target_fabric_configfs *);
diff --git a/samples/Kconfig b/samples/Kconfig
index 224ebb46bed5..d54f28c6dc5e 100644
--- a/samples/Kconfig
+++ b/samples/Kconfig
@@ -70,4 +70,10 @@ config SAMPLE_LIVEPATCH
70 Builds a sample live patch that replaces the procfs handler 70 Builds a sample live patch that replaces the procfs handler
71 for /proc/cmdline to print "this has been live patched". 71 for /proc/cmdline to print "this has been live patched".
72 72
73config SAMPLE_CONFIGFS
74 tristate "Build configfs patching sample -- loadable modules only"
75 depends on CONFIGFS_FS && m
76 help
77 Builds a sample configfs interface.
78
73endif # SAMPLES 79endif # SAMPLES
diff --git a/samples/Makefile b/samples/Makefile
index f00257bcc5a7..48001d7e23f0 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -1,4 +1,5 @@
1# Makefile for Linux samples code 1# Makefile for Linux samples code
2 2
3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ 3obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \
4 hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ 4 hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \
5 configfs/
diff --git a/samples/configfs/Makefile b/samples/configfs/Makefile
new file mode 100644
index 000000000000..a9afd99630fc
--- /dev/null
+++ b/samples/configfs/Makefile
@@ -0,0 +1,2 @@
1
2obj-$(CONFIG_SAMPLE_CONFIGFS) += configfs_sample.o
diff --git a/Documentation/filesystems/configfs/configfs_example_macros.c b/samples/configfs/configfs_sample.c
index 327dfbc640a9..1ea33119e532 100644
--- a/Documentation/filesystems/configfs/configfs_example_macros.c
+++ b/samples/configfs/configfs_sample.c
@@ -54,18 +54,13 @@ struct childless {
54 54
55static inline struct childless *to_childless(struct config_item *item) 55static inline struct childless *to_childless(struct config_item *item)
56{ 56{
57 return item ? container_of(to_configfs_subsystem(to_config_group(item)), struct childless, subsys) : NULL; 57 return item ? container_of(to_configfs_subsystem(to_config_group(item)),
58 struct childless, subsys) : NULL;
58} 59}
59 60
60CONFIGFS_ATTR_STRUCT(childless); 61static ssize_t childless_showme_show(struct config_item *item, char *page)
61#define CHILDLESS_ATTR(_name, _mode, _show, _store) \
62struct childless_attribute childless_attr_##_name = __CONFIGFS_ATTR(_name, _mode, _show, _store)
63#define CHILDLESS_ATTR_RO(_name, _show) \
64struct childless_attribute childless_attr_##_name = __CONFIGFS_ATTR_RO(_name, _show);
65
66static ssize_t childless_showme_read(struct childless *childless,
67 char *page)
68{ 62{
63 struct childless *childless = to_childless(item);
69 ssize_t pos; 64 ssize_t pos;
70 65
71 pos = sprintf(page, "%d\n", childless->showme); 66 pos = sprintf(page, "%d\n", childless->showme);
@@ -74,16 +69,15 @@ static ssize_t childless_showme_read(struct childless *childless,
74 return pos; 69 return pos;
75} 70}
76 71
77static ssize_t childless_storeme_read(struct childless *childless, 72static ssize_t childless_storeme_show(struct config_item *item, char *page)
78 char *page)
79{ 73{
80 return sprintf(page, "%d\n", childless->storeme); 74 return sprintf(page, "%d\n", to_childless(item)->storeme);
81} 75}
82 76
83static ssize_t childless_storeme_write(struct childless *childless, 77static ssize_t childless_storeme_store(struct config_item *item,
84 const char *page, 78 const char *page, size_t count)
85 size_t count)
86{ 79{
80 struct childless *childless = to_childless(item);
87 unsigned long tmp; 81 unsigned long tmp;
88 char *p = (char *) page; 82 char *p = (char *) page;
89 83
@@ -99,8 +93,7 @@ static ssize_t childless_storeme_write(struct childless *childless,
99 return count; 93 return count;
100} 94}
101 95
102static ssize_t childless_description_read(struct childless *childless, 96static ssize_t childless_description_show(struct config_item *item, char *page)
103 char *page)
104{ 97{
105 return sprintf(page, 98 return sprintf(page,
106"[01-childless]\n" 99"[01-childless]\n"
@@ -111,26 +104,18 @@ static ssize_t childless_description_read(struct childless *childless,
111"than a directory in /proc.\n"); 104"than a directory in /proc.\n");
112} 105}
113 106
114CHILDLESS_ATTR_RO(showme, childless_showme_read); 107CONFIGFS_ATTR_RO(childless_, showme);
115CHILDLESS_ATTR(storeme, S_IRUGO | S_IWUSR, childless_storeme_read, 108CONFIGFS_ATTR(childless_, storeme);
116 childless_storeme_write); 109CONFIGFS_ATTR_RO(childless_, description);
117CHILDLESS_ATTR_RO(description, childless_description_read);
118 110
119static struct configfs_attribute *childless_attrs[] = { 111static struct configfs_attribute *childless_attrs[] = {
120 &childless_attr_showme.attr, 112 &childless_attr_showme,
121 &childless_attr_storeme.attr, 113 &childless_attr_storeme,
122 &childless_attr_description.attr, 114 &childless_attr_description,
123 NULL, 115 NULL,
124}; 116};
125 117
126CONFIGFS_ATTR_OPS(childless);
127static struct configfs_item_operations childless_item_ops = {
128 .show_attribute = childless_attr_show,
129 .store_attribute = childless_attr_store,
130};
131
132static struct config_item_type childless_type = { 118static struct config_item_type childless_type = {
133 .ct_item_ops = &childless_item_ops,
134 .ct_attrs = childless_attrs, 119 .ct_attrs = childless_attrs,
135 .ct_owner = THIS_MODULE, 120 .ct_owner = THIS_MODULE,
136}; 121};
@@ -168,32 +153,13 @@ static inline struct simple_child *to_simple_child(struct config_item *item)
168 return item ? container_of(item, struct simple_child, item) : NULL; 153 return item ? container_of(item, struct simple_child, item) : NULL;
169} 154}
170 155
171static struct configfs_attribute simple_child_attr_storeme = { 156static ssize_t simple_child_storeme_show(struct config_item *item, char *page)
172 .ca_owner = THIS_MODULE,
173 .ca_name = "storeme",
174 .ca_mode = S_IRUGO | S_IWUSR,
175};
176
177static struct configfs_attribute *simple_child_attrs[] = {
178 &simple_child_attr_storeme,
179 NULL,
180};
181
182static ssize_t simple_child_attr_show(struct config_item *item,
183 struct configfs_attribute *attr,
184 char *page)
185{ 157{
186 ssize_t count; 158 return sprintf(page, "%d\n", to_simple_child(item)->storeme);
187 struct simple_child *simple_child = to_simple_child(item);
188
189 count = sprintf(page, "%d\n", simple_child->storeme);
190
191 return count;
192} 159}
193 160
194static ssize_t simple_child_attr_store(struct config_item *item, 161static ssize_t simple_child_storeme_store(struct config_item *item,
195 struct configfs_attribute *attr, 162 const char *page, size_t count)
196 const char *page, size_t count)
197{ 163{
198 struct simple_child *simple_child = to_simple_child(item); 164 struct simple_child *simple_child = to_simple_child(item);
199 unsigned long tmp; 165 unsigned long tmp;
@@ -211,6 +177,13 @@ static ssize_t simple_child_attr_store(struct config_item *item,
211 return count; 177 return count;
212} 178}
213 179
180CONFIGFS_ATTR(simple_child_, storeme);
181
182static struct configfs_attribute *simple_child_attrs[] = {
183 &simple_child_attr_storeme,
184 NULL,
185};
186
214static void simple_child_release(struct config_item *item) 187static void simple_child_release(struct config_item *item)
215{ 188{
216 kfree(to_simple_child(item)); 189 kfree(to_simple_child(item));
@@ -218,8 +191,6 @@ static void simple_child_release(struct config_item *item)
218 191
219static struct configfs_item_operations simple_child_item_ops = { 192static struct configfs_item_operations simple_child_item_ops = {
220 .release = simple_child_release, 193 .release = simple_child_release,
221 .show_attribute = simple_child_attr_show,
222 .store_attribute = simple_child_attr_store,
223}; 194};
224 195
225static struct config_item_type simple_child_type = { 196static struct config_item_type simple_child_type = {
@@ -235,10 +206,12 @@ struct simple_children {
235 206
236static inline struct simple_children *to_simple_children(struct config_item *item) 207static inline struct simple_children *to_simple_children(struct config_item *item)
237{ 208{
238 return item ? container_of(to_config_group(item), struct simple_children, group) : NULL; 209 return item ? container_of(to_config_group(item),
210 struct simple_children, group) : NULL;
239} 211}
240 212
241static struct config_item *simple_children_make_item(struct config_group *group, const char *name) 213static struct config_item *simple_children_make_item(struct config_group *group,
214 const char *name)
242{ 215{
243 struct simple_child *simple_child; 216 struct simple_child *simple_child;
244 217
@@ -254,20 +227,8 @@ static struct config_item *simple_children_make_item(struct config_group *group,
254 return &simple_child->item; 227 return &simple_child->item;
255} 228}
256 229
257static struct configfs_attribute simple_children_attr_description = { 230static ssize_t simple_children_description_show(struct config_item *item,
258 .ca_owner = THIS_MODULE, 231 char *page)
259 .ca_name = "description",
260 .ca_mode = S_IRUGO,
261};
262
263static struct configfs_attribute *simple_children_attrs[] = {
264 &simple_children_attr_description,
265 NULL,
266};
267
268static ssize_t simple_children_attr_show(struct config_item *item,
269 struct configfs_attribute *attr,
270 char *page)
271{ 232{
272 return sprintf(page, 233 return sprintf(page,
273"[02-simple-children]\n" 234"[02-simple-children]\n"
@@ -276,6 +237,13 @@ static ssize_t simple_children_attr_show(struct config_item *item,
276"items have only one attribute that is readable and writeable.\n"); 237"items have only one attribute that is readable and writeable.\n");
277} 238}
278 239
240CONFIGFS_ATTR_RO(simple_children_, description);
241
242static struct configfs_attribute *simple_children_attrs[] = {
243 &simple_children_attr_description,
244 NULL,
245};
246
279static void simple_children_release(struct config_item *item) 247static void simple_children_release(struct config_item *item)
280{ 248{
281 kfree(to_simple_children(item)); 249 kfree(to_simple_children(item));
@@ -283,7 +251,6 @@ static void simple_children_release(struct config_item *item)
283 251
284static struct configfs_item_operations simple_children_item_ops = { 252static struct configfs_item_operations simple_children_item_ops = {
285 .release = simple_children_release, 253 .release = simple_children_release,
286 .show_attribute = simple_children_attr_show,
287}; 254};
288 255
289/* 256/*
@@ -323,7 +290,8 @@ static struct configfs_subsystem simple_children_subsys = {
323 * children of its own. 290 * children of its own.
324 */ 291 */
325 292
326static struct config_group *group_children_make_group(struct config_group *group, const char *name) 293static struct config_group *group_children_make_group(
294 struct config_group *group, const char *name)
327{ 295{
328 struct simple_children *simple_children; 296 struct simple_children *simple_children;
329 297
@@ -338,20 +306,8 @@ static struct config_group *group_children_make_group(struct config_group *group
338 return &simple_children->group; 306 return &simple_children->group;
339} 307}
340 308
341static struct configfs_attribute group_children_attr_description = { 309static ssize_t group_children_description_show(struct config_item *item,
342 .ca_owner = THIS_MODULE, 310 char *page)
343 .ca_name = "description",
344 .ca_mode = S_IRUGO,
345};
346
347static struct configfs_attribute *group_children_attrs[] = {
348 &group_children_attr_description,
349 NULL,
350};
351
352static ssize_t group_children_attr_show(struct config_item *item,
353 struct configfs_attribute *attr,
354 char *page)
355{ 311{
356 return sprintf(page, 312 return sprintf(page,
357"[03-group-children]\n" 313"[03-group-children]\n"
@@ -360,8 +316,11 @@ static ssize_t group_children_attr_show(struct config_item *item,
360"groups are like the subsystem simple-children.\n"); 316"groups are like the subsystem simple-children.\n");
361} 317}
362 318
363static struct configfs_item_operations group_children_item_ops = { 319CONFIGFS_ATTR_RO(group_children_, description);
364 .show_attribute = group_children_attr_show, 320
321static struct configfs_attribute *group_children_attrs[] = {
322 &group_children_attr_description,
323 NULL,
365}; 324};
366 325
367/* 326/*
@@ -373,7 +332,6 @@ static struct configfs_group_operations group_children_group_ops = {
373}; 332};
374 333
375static struct config_item_type group_children_type = { 334static struct config_item_type group_children_type = {
376 .ct_item_ops = &group_children_item_ops,
377 .ct_group_ops = &group_children_group_ops, 335 .ct_group_ops = &group_children_group_ops,
378 .ct_attrs = group_children_attrs, 336 .ct_attrs = group_children_attrs,
379 .ct_owner = THIS_MODULE, 337 .ct_owner = THIS_MODULE,