Merge tag 'ntb-4.5' of git://github.com/jonmason/ntb
[deliverable/linux.git] / include / linux / configfs.h
CommitLineData
7063fbf2
JB
1/* -*- mode: c; c-basic-offset: 8; -*-
2 * vim: noexpandtab sw=8 ts=8 sts=0:
3 *
4 * configfs.h - definitions for the device driver filesystem
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 *
55dff495
RD
30 * Please read Documentation/filesystems/configfs/configfs.txt before using
31 * the configfs interface, ESPECIALLY the parts about reference counts and
7063fbf2
JB
32 * item destructors.
33 */
34
35#ifndef _CONFIGFS_H_
36#define _CONFIGFS_H_
37
07783618 38#include <linux/kernel.h>
7063fbf2
JB
39#include <linux/types.h>
40#include <linux/list.h>
41#include <linux/kref.h>
e6bd07ae 42#include <linux/mutex.h>
dacdd0e0 43#include <linux/err.h>
7063fbf2 44
60063497 45#include <linux/atomic.h>
7063fbf2
JB
46
47#define CONFIGFS_ITEM_NAME_LEN 20
48
49struct module;
50
51struct configfs_item_operations;
52struct configfs_group_operations;
53struct configfs_attribute;
03607ace 54struct configfs_bin_attribute;
7063fbf2
JB
55struct configfs_subsystem;
56
57struct config_item {
58 char *ci_name;
59 char ci_namebuf[CONFIGFS_ITEM_NAME_LEN];
60 struct kref ci_kref;
61 struct list_head ci_entry;
62 struct config_item *ci_parent;
63 struct config_group *ci_group;
64 struct config_item_type *ci_type;
65 struct dentry *ci_dentry;
66};
67
8db14860
NI
68extern __printf(2, 3)
69int config_item_set_name(struct config_item *, const char *, ...);
7063fbf2
JB
70
71static inline char *config_item_name(struct config_item * item)
72{
73 return item->ci_name;
74}
75
7063fbf2
JB
76extern void config_item_init_type_name(struct config_item *item,
77 const char *name,
78 struct config_item_type *type);
7063fbf2
JB
79
80extern struct config_item * config_item_get(struct config_item *);
81extern void config_item_put(struct config_item *);
82
83struct config_item_type {
84 struct module *ct_owner;
85 struct configfs_item_operations *ct_item_ops;
86 struct configfs_group_operations *ct_group_ops;
87 struct configfs_attribute **ct_attrs;
03607ace 88 struct configfs_bin_attribute **ct_bin_attrs;
7063fbf2
JB
89};
90
7063fbf2
JB
91/**
92 * group - a group of config_items of a specific type, belonging
93 * to a specific subsystem.
94 */
7063fbf2
JB
95struct config_group {
96 struct config_item cg_item;
97 struct list_head cg_children;
98 struct configfs_subsystem *cg_subsys;
99 struct config_group **default_groups;
100};
101
7063fbf2
JB
102extern void config_group_init(struct config_group *group);
103extern void config_group_init_type_name(struct config_group *group,
104 const char *name,
105 struct config_item_type *type);
106
7063fbf2
JB
107static inline struct config_group *to_config_group(struct config_item *item)
108{
109 return item ? container_of(item,struct config_group,cg_item) : NULL;
110}
111
112static inline struct config_group *config_group_get(struct config_group *group)
113{
114 return group ? to_config_group(config_item_get(&group->cg_item)) : NULL;
115}
116
117static inline void config_group_put(struct config_group *group)
118{
119 config_item_put(&group->cg_item);
120}
121
3fe6c5ce
SS
122extern struct config_item *config_group_find_item(struct config_group *,
123 const char *);
7063fbf2
JB
124
125
126struct configfs_attribute {
3d0f89bb 127 const char *ca_name;
7063fbf2 128 struct module *ca_owner;
43947514 129 umode_t ca_mode;
870823e6
CH
130 ssize_t (*show)(struct config_item *, char *);
131 ssize_t (*store)(struct config_item *, const char *, size_t);
7063fbf2
JB
132};
133
870823e6
CH
134#define CONFIGFS_ATTR(_pfx, _name) \
135static struct configfs_attribute _pfx##attr_##_name = { \
136 .ca_name = __stringify(_name), \
137 .ca_mode = S_IRUGO | S_IWUSR, \
138 .ca_owner = THIS_MODULE, \
139 .show = _pfx##_name##_show, \
140 .store = _pfx##_name##_store, \
141}
142
143#define CONFIGFS_ATTR_RO(_pfx, _name) \
144static struct configfs_attribute _pfx##attr_##_name = { \
145 .ca_name = __stringify(_name), \
146 .ca_mode = S_IRUGO, \
147 .ca_owner = THIS_MODULE, \
148 .show = _pfx##_name##_show, \
149}
150
151#define CONFIGFS_ATTR_WO(_pfx, _name) \
152static struct configfs_attribute _pfx##attr_##_name = { \
153 .ca_name = __stringify(_name), \
154 .ca_mode = S_IWUSR, \
155 .ca_owner = THIS_MODULE, \
156 .store = _pfx##_name##_store, \
157}
158
03607ace
PA
159struct file;
160struct vm_area_struct;
161
162struct configfs_bin_attribute {
163 struct configfs_attribute cb_attr; /* std. attribute */
164 void *cb_private; /* for user */
165 size_t cb_max_size; /* max core size */
166 ssize_t (*read)(struct config_item *, void *, size_t);
167 ssize_t (*write)(struct config_item *, const void *, size_t);
168};
169
170#define CONFIGFS_BIN_ATTR(_pfx, _name, _priv, _maxsz) \
171static struct configfs_bin_attribute _pfx##attr_##_name = { \
172 .cb_attr = { \
173 .ca_name = __stringify(_name), \
174 .ca_mode = S_IRUGO | S_IWUSR, \
175 .ca_owner = THIS_MODULE, \
176 }, \
177 .cb_private = _priv, \
178 .cb_max_size = _maxsz, \
179 .read = _pfx##_name##_read, \
180 .write = _pfx##_name##_write, \
181}
182
183#define CONFIGFS_BIN_ATTR_RO(_pfx, _name, _priv, _maxsz) \
184static struct configfs_attribute _pfx##attr_##_name = { \
185 .cb_attr = { \
186 .ca_name = __stringify(_name), \
187 .ca_mode = S_IRUGO, \
188 .ca_owner = THIS_MODULE, \
189 }, \
190 .cb_private = _priv, \
191 .cb_max_size = _maxsz, \
192 .read = _pfx##_name##_read, \
193}
194
195#define CONFIGFS_BIN_ATTR_WO(_pfx, _name, _priv, _maxsz) \
196static struct configfs_attribute _pfx##attr_##_name = { \
197 .cb_attr = { \
198 .ca_name = __stringify(_name), \
199 .ca_mode = S_IWUSR, \
200 .ca_owner = THIS_MODULE, \
201 }, \
202 .cb_private = _priv, \
203 .cb_max_size = _maxsz, \
204 .write = _pfx##_name##_write, \
205}
206
7063fbf2
JB
207/*
208 * If allow_link() exists, the item can symlink(2) out to other
209 * items. If the item is a group, it may support mkdir(2).
210 * Groups supply one of make_group() and make_item(). If the
211 * group supports make_group(), one can create group children. If it
a6795e9e
JB
212 * supports make_item(), one can create config_item children. make_group()
213 * and make_item() return ERR_PTR() on errors. If it has
7063fbf2
JB
214 * default_groups on group->default_groups, it has automatically created
215 * group children. default_groups may coexist alongsize make_group() or
216 * make_item(), but if the group wishes to have only default_groups
217 * children (disallowing mkdir(2)), it need not provide either function.
25985edc 218 * If the group has commit(), it supports pending and committed (active)
7063fbf2
JB
219 * items.
220 */
221struct configfs_item_operations {
222 void (*release)(struct config_item *);
7063fbf2
JB
223 int (*allow_link)(struct config_item *src, struct config_item *target);
224 int (*drop_link)(struct config_item *src, struct config_item *target);
225};
226
227struct configfs_group_operations {
f89ab861
JB
228 struct config_item *(*make_item)(struct config_group *group, const char *name);
229 struct config_group *(*make_group)(struct config_group *group, const char *name);
7063fbf2 230 int (*commit_item)(struct config_item *item);
299894cc 231 void (*disconnect_notify)(struct config_group *group, struct config_item *item);
7063fbf2
JB
232 void (*drop_item)(struct config_group *group, struct config_item *item);
233};
234
7063fbf2
JB
235struct configfs_subsystem {
236 struct config_group su_group;
e6bd07ae 237 struct mutex su_mutex;
7063fbf2
JB
238};
239
240static inline struct configfs_subsystem *to_configfs_subsystem(struct config_group *group)
241{
242 return group ?
243 container_of(group, struct configfs_subsystem, su_group) :
244 NULL;
245}
246
247int configfs_register_subsystem(struct configfs_subsystem *subsys);
248void configfs_unregister_subsystem(struct configfs_subsystem *subsys);
249
5cf6a51e
DB
250int configfs_register_group(struct config_group *parent_group,
251 struct config_group *group);
252void configfs_unregister_group(struct config_group *group);
253
254struct config_group *
255configfs_register_default_group(struct config_group *parent_group,
256 const char *name,
257 struct config_item_type *item_type);
258void configfs_unregister_default_group(struct config_group *group);
259
631d1feb
JB
260/* These functions can sleep and can alloc with GFP_KERNEL */
261/* WARNING: These cannot be called underneath configfs callbacks!! */
9a9e3415
KO
262int configfs_depend_item(struct configfs_subsystem *subsys,
263 struct config_item *target);
264void configfs_undepend_item(struct config_item *target);
631d1feb 265
d79d75b5
KO
266/*
267 * These functions can sleep and can alloc with GFP_KERNEL
268 * NOTE: These should be called only underneath configfs callbacks.
269 * NOTE: First parameter is a caller's subsystem, not target's.
270 * WARNING: These cannot be called on newly created item
271 * (in make_group()/make_item() callback)
272 */
273int configfs_depend_item_unlocked(struct configfs_subsystem *caller_subsys,
274 struct config_item *target);
275
276
277static inline void configfs_undepend_item_unlocked(struct config_item *target)
278{
279 configfs_undepend_item(target);
280}
631d1feb 281
7063fbf2 282#endif /* _CONFIGFS_H_ */
This page took 1.214865 seconds and 5 git commands to generate.