Blame view

include/linux/kernfs.h 14.6 KB
b8441ed27   Tejun Heo   sysfs, kernfs: ad...
1
2
3
4
5
6
7
8
  /*
   * kernfs.h - pseudo filesystem decoupled from vfs locking
   *
   * This file is released under the GPLv2.
   */
  
  #ifndef __LINUX_KERNFS_H
  #define __LINUX_KERNFS_H
879f40d19   Tejun Heo   sysfs, kernfs: in...
9
  #include <linux/kernel.h>
5d0e26bb5   Tejun Heo   sysfs, kernfs: in...
10
  #include <linux/err.h>
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
11
12
  #include <linux/list.h>
  #include <linux/mutex.h>
bc755553d   Tejun Heo   sysfs, kernfs: ma...
13
  #include <linux/idr.h>
517e64f57   Tejun Heo   sysfs, kernfs: re...
14
  #include <linux/lockdep.h>
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
15
16
  #include <linux/rbtree.h>
  #include <linux/atomic.h>
abd54f028   Tejun Heo   kernfs: replace k...
17
  #include <linux/wait.h>
879f40d19   Tejun Heo   sysfs, kernfs: in...
18

5d60418e5   Tejun Heo   sysfs, kernfs: in...
19
  struct file;
917f56caa   Tejun Heo   kernfs: add struc...
20
  struct dentry;
5d60418e5   Tejun Heo   sysfs, kernfs: in...
21
  struct iattr;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
22
23
  struct seq_file;
  struct vm_area_struct;
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
24
25
  struct super_block;
  struct file_system_type;
5d60418e5   Tejun Heo   sysfs, kernfs: in...
26

c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
27
28
  struct kernfs_open_node;
  struct kernfs_iattrs;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
29
30
  
  enum kernfs_node_type {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
31
32
33
  	KERNFS_DIR		= 0x0001,
  	KERNFS_FILE		= 0x0002,
  	KERNFS_LINK		= 0x0004,
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
34
  };
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
35
  #define KERNFS_TYPE_MASK	0x000f
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
36
  #define KERNFS_FLAG_MASK	~KERNFS_TYPE_MASK
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
37
38
  
  enum kernfs_node_flag {
d35258ef7   Tejun Heo   kernfs: allow nod...
39
  	KERNFS_ACTIVATED	= 0x0010,
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
40
41
42
43
  	KERNFS_NS		= 0x0020,
  	KERNFS_HAS_SEQ_SHOW	= 0x0040,
  	KERNFS_HAS_MMAP		= 0x0080,
  	KERNFS_LOCKDEP		= 0x0100,
6b0afc2a2   Tejun Heo   kernfs, sysfs, dr...
44
45
  	KERNFS_SUICIDAL		= 0x0400,
  	KERNFS_SUICIDED		= 0x0800,
ea015218f   Eric W. Biederman   kernfs: Add suppo...
46
  	KERNFS_EMPTY_DIR	= 0x1000,
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
47
  };
d35258ef7   Tejun Heo   kernfs: allow nod...
48
49
  /* @flags for kernfs_create_root() */
  enum kernfs_root_flag {
555724a83   Tejun Heo   kernfs, sysfs, cg...
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  	/*
  	 * kernfs_nodes are created in the deactivated state and invisible.
  	 * They require explicit kernfs_activate() to become visible.  This
  	 * can be used to make related nodes become visible atomically
  	 * after all nodes are created successfully.
  	 */
  	KERNFS_ROOT_CREATE_DEACTIVATED		= 0x0001,
  
  	/*
  	 * For regular flies, if the opener has CAP_DAC_OVERRIDE, open(2)
  	 * succeeds regardless of the RW permissions.  sysfs had an extra
  	 * layer of enforcement where open(2) fails with -EACCES regardless
  	 * of CAP_DAC_OVERRIDE if the permission doesn't have the
  	 * respective read or write access at all (none of S_IRUGO or
  	 * S_IWUGO) or the respective operation isn't implemented.  The
  	 * following flag enables that behavior.
  	 */
  	KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK	= 0x0002,
d35258ef7   Tejun Heo   kernfs: allow nod...
68
  };
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
69
70
  /* type-specific structures for kernfs_node union members */
  struct kernfs_elem_dir {
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
71
  	unsigned long		subdirs;
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
72
  	/* children rbtree starts here and goes through kn->rb */
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
73
74
75
76
  	struct rb_root		children;
  
  	/*
  	 * The kernfs hierarchy this directory belongs to.  This fits
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
77
  	 * better directly in kernfs_node but is here to save space.
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
78
79
80
  	 */
  	struct kernfs_root	*root;
  };
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
81
82
  struct kernfs_elem_symlink {
  	struct kernfs_node	*target_kn;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
83
  };
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
84
  struct kernfs_elem_attr {
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
85
  	const struct kernfs_ops	*ops;
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
86
  	struct kernfs_open_node	*open;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
87
  	loff_t			size;
ecca47ce8   Tejun Heo   kernfs: kernfs_no...
88
  	struct kernfs_node	*notify_next;	/* for kernfs_notify() */
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
89
90
91
  };
  
  /*
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
92
93
   * kernfs_node - the building block of kernfs hierarchy.  Each and every
   * kernfs node is represented by single kernfs_node.  Most fields are
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
94
95
   * private to kernfs and shouldn't be accessed directly by kernfs users.
   *
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
96
97
98
   * As long as s_count reference is held, the kernfs_node itself is
   * accessible.  Dereferencing elem or any other outer entity requires
   * active reference.
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
99
   */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
100
  struct kernfs_node {
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
101
102
  	atomic_t		count;
  	atomic_t		active;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
103
104
105
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  	struct lockdep_map	dep_map;
  #endif
3eef34ad7   Tejun Heo   kernfs: implement...
106
107
108
109
110
111
  	/*
  	 * Use kernfs_get_parent() and kernfs_name/path() instead of
  	 * accessing the following two fields directly.  If the node is
  	 * never moved to a different parent, it is safe to access the
  	 * parent directly.
  	 */
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
112
113
  	struct kernfs_node	*parent;
  	const char		*name;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
114

adc5e8b58   Tejun Heo   kernfs: drop s_ p...
115
  	struct rb_node		rb;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
116

adc5e8b58   Tejun Heo   kernfs: drop s_ p...
117
  	const void		*ns;	/* namespace tag */
9b0925a6f   Greg Kroah-Hartman   Revert "kernfs: i...
118
  	unsigned int		hash;	/* ns + name hash */
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
119
  	union {
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
120
121
122
  		struct kernfs_elem_dir		dir;
  		struct kernfs_elem_symlink	symlink;
  		struct kernfs_elem_attr		attr;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
123
124
125
  	};
  
  	void			*priv;
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
126
127
128
  	unsigned short		flags;
  	umode_t			mode;
  	unsigned int		ino;
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
129
  	struct kernfs_iattrs	*iattr;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
130
  };
b8441ed27   Tejun Heo   sysfs, kernfs: ad...
131

80b9bbefc   Tejun Heo   kernfs: add kernf...
132
  /*
90c07c895   Tejun Heo   kernfs: rename ke...
133
134
135
136
137
   * kernfs_syscall_ops may be specified on kernfs_create_root() to support
   * syscalls.  These optional callbacks are invoked on the matching syscalls
   * and can perform any kernfs operations which don't necessarily have to be
   * the exact operation requested.  An active reference is held for each
   * kernfs_node parameter.
80b9bbefc   Tejun Heo   kernfs: add kernf...
138
   */
90c07c895   Tejun Heo   kernfs: rename ke...
139
  struct kernfs_syscall_ops {
6a7fed4ee   Tejun Heo   kernfs: implement...
140
141
  	int (*remount_fs)(struct kernfs_root *root, int *flags, char *data);
  	int (*show_options)(struct seq_file *sf, struct kernfs_root *root);
80b9bbefc   Tejun Heo   kernfs: add kernf...
142
143
144
145
146
147
  	int (*mkdir)(struct kernfs_node *parent, const char *name,
  		     umode_t mode);
  	int (*rmdir)(struct kernfs_node *kn);
  	int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent,
  		      const char *new_name);
  };
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
148
149
  struct kernfs_root {
  	/* published fields */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
150
  	struct kernfs_node	*kn;
d35258ef7   Tejun Heo   kernfs: allow nod...
151
  	unsigned int		flags;	/* KERNFS_ROOT_* flags */
bc755553d   Tejun Heo   sysfs, kernfs: ma...
152
153
154
  
  	/* private fields, do not use outside kernfs proper */
  	struct ida		ino_ida;
90c07c895   Tejun Heo   kernfs: rename ke...
155
  	struct kernfs_syscall_ops *syscall_ops;
7d568a838   Tejun Heo   kernfs: implement...
156
157
158
  
  	/* list of kernfs_super_info of this root, protected by kernfs_mutex */
  	struct list_head	supers;
abd54f028   Tejun Heo   kernfs: replace k...
159
  	wait_queue_head_t	deactivate_waitq;
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
160
  };
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
161
  struct kernfs_open_file {
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
162
  	/* published fields */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
163
  	struct kernfs_node	*kn;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
164
  	struct file		*file;
2536390da   Tejun Heo   kernfs: add kernf...
165
  	void			*priv;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
166
167
168
169
170
  
  	/* private fields, do not use outside kernfs proper */
  	struct mutex		mutex;
  	int			event;
  	struct list_head	list;
2b75869bb   NeilBrown   sysfs/kernfs: all...
171
  	char			*prealloc_buf;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
172

b7ce40cff   Tejun Heo   kernfs: cache ato...
173
  	size_t			atomic_write_len;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
174
175
176
  	bool			mmapped;
  	const struct vm_operations_struct *vm_ops;
  };
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
177
178
179
180
  struct kernfs_ops {
  	/*
  	 * Read is handled by either seq_file or raw_read().
  	 *
d19b9846d   Tejun Heo   sysfs, kernfs: ad...
181
182
183
  	 * If seq_show() is present, seq_file path is active.  Other seq
  	 * operations are optional and if not implemented, the behavior is
  	 * equivalent to single_open().  @sf->private points to the
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
184
  	 * associated kernfs_open_file.
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
185
186
187
188
189
  	 *
  	 * read() is bounced through kernel buffer and a read larger than
  	 * PAGE_SIZE results in partial operation of PAGE_SIZE.
  	 */
  	int (*seq_show)(struct seq_file *sf, void *v);
d19b9846d   Tejun Heo   sysfs, kernfs: ad...
190
191
192
193
  
  	void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
  	void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
  	void (*seq_stop)(struct seq_file *sf, void *v);
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
194

c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
195
  	ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes,
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
196
197
198
  			loff_t off);
  
  	/*
4d3773c4b   Tejun Heo   kernfs: implement...
199
200
201
202
203
  	 * write() is bounced through kernel buffer.  If atomic_write_len
  	 * is not set, a write larger than PAGE_SIZE results in partial
  	 * operations of PAGE_SIZE chunks.  If atomic_write_len is set,
  	 * writes upto the specified size are executed atomically but
  	 * larger ones are rejected with -E2BIG.
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
204
  	 */
4d3773c4b   Tejun Heo   kernfs: implement...
205
  	size_t atomic_write_len;
2b75869bb   NeilBrown   sysfs/kernfs: all...
206
207
208
209
210
211
212
  	/*
  	 * "prealloc" causes a buffer to be allocated at open for
  	 * all read/write requests.  As ->seq_show uses seq_read()
  	 * which does its own allocation, it is incompatible with
  	 * ->prealloc.  Provide ->read and ->write with ->prealloc.
  	 */
  	bool prealloc;
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
213
  	ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes,
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
214
  			 loff_t off);
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
215
  	int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma);
517e64f57   Tejun Heo   sysfs, kernfs: re...
216
217
218
219
  
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  	struct lock_class_key	lockdep_key;
  #endif
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
220
  };
ba341d55a   Tejun Heo   kernfs: add CONFI...
221
  #ifdef CONFIG_KERNFS
879f40d19   Tejun Heo   sysfs, kernfs: in...
222

df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
223
  static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
224
  {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
225
  	return kn->flags & KERNFS_TYPE_MASK;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
226
227
228
229
  }
  
  /**
   * kernfs_enable_ns - enable namespace under a directory
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
230
   * @kn: directory of interest, should be empty
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
231
   *
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
232
233
   * This is to be called right after @kn is created to enable namespace
   * under it.  All children of @kn must have non-NULL namespace tags and
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
234
235
   * only the ones which match the super_block's tag will be visible.
   */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
236
  static inline void kernfs_enable_ns(struct kernfs_node *kn)
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
237
  {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
238
  	WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
239
  	WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
240
  	kn->flags |= KERNFS_NS;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
241
  }
ac9bba031   Tejun Heo   sysfs, kernfs: im...
242
243
  /**
   * kernfs_ns_enabled - test whether namespace is enabled
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
244
   * @kn: the node to test
ac9bba031   Tejun Heo   sysfs, kernfs: im...
245
246
247
   *
   * Test whether namespace filtering is enabled for the children of @ns.
   */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
248
  static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
ac9bba031   Tejun Heo   sysfs, kernfs: im...
249
  {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
250
  	return kn->flags & KERNFS_NS;
ac9bba031   Tejun Heo   sysfs, kernfs: im...
251
  }
3eef34ad7   Tejun Heo   kernfs: implement...
252
  int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
9acee9c55   Tejun Heo   kernfs: implement...
253
  size_t kernfs_path_len(struct kernfs_node *kn);
3eef34ad7   Tejun Heo   kernfs: implement...
254
255
256
257
258
  char * __must_check kernfs_path(struct kernfs_node *kn, char *buf,
  				size_t buflen);
  void pr_cont_kernfs_name(struct kernfs_node *kn);
  void pr_cont_kernfs_path(struct kernfs_node *kn);
  struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
259
260
261
262
  struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
  					   const char *name, const void *ns);
  void kernfs_get(struct kernfs_node *kn);
  void kernfs_put(struct kernfs_node *kn);
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
263

0c23b2259   Tejun Heo   kernfs: implement...
264
265
  struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
  struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
fb02915f4   Tejun Heo   kernfs: make kern...
266
  struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
0c23b2259   Tejun Heo   kernfs: implement...
267

90c07c895   Tejun Heo   kernfs: rename ke...
268
  struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
d35258ef7   Tejun Heo   kernfs: allow nod...
269
  				       unsigned int flags, void *priv);
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
270
  void kernfs_destroy_root(struct kernfs_root *root);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
271
  struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
bb8b9d095   Tejun Heo   kernfs: add @mode...
272
273
  					 const char *name, umode_t mode,
  					 void *priv, const void *ns);
ea015218f   Eric W. Biederman   kernfs: Add suppo...
274
275
  struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
  					    const char *name);
2063d608f   Tejun Heo   kernfs: mark stat...
276
277
278
279
280
  struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
  					 const char *name,
  					 umode_t mode, loff_t size,
  					 const struct kernfs_ops *ops,
  					 void *priv, const void *ns,
2063d608f   Tejun Heo   kernfs: mark stat...
281
  					 struct lock_class_key *key);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
282
283
284
  struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
  				       const char *name,
  				       struct kernfs_node *target);
d35258ef7   Tejun Heo   kernfs: allow nod...
285
  void kernfs_activate(struct kernfs_node *kn);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
286
  void kernfs_remove(struct kernfs_node *kn);
6b0afc2a2   Tejun Heo   kernfs, sysfs, dr...
287
288
289
  void kernfs_break_active_protection(struct kernfs_node *kn);
  void kernfs_unbreak_active_protection(struct kernfs_node *kn);
  bool kernfs_remove_self(struct kernfs_node *kn);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
290
  int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
879f40d19   Tejun Heo   sysfs, kernfs: in...
291
  			     const void *ns);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
292
  int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
890ece160   Tejun Heo   sysfs, kernfs: in...
293
  		     const char *new_name, const void *new_ns);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
294
295
  int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
  void kernfs_notify(struct kernfs_node *kn);
879f40d19   Tejun Heo   sysfs, kernfs: in...
296

4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
297
298
  const void *kernfs_super_ns(struct super_block *sb);
  struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
26fc9cd20   Jianyu Zhan   kernfs: move the ...
299
300
  			       struct kernfs_root *root, unsigned long magic,
  			       bool *new_sb_created, const void *ns);
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
301
  void kernfs_kill_sb(struct super_block *sb);
4e26445fa   Li Zefan   kernfs: introduce...
302
  struct super_block *kernfs_pin_sb(struct kernfs_root *root, const void *ns);
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
303
304
  
  void kernfs_init(void);
ba341d55a   Tejun Heo   kernfs: add CONFI...
305
  #else	/* CONFIG_KERNFS */
879f40d19   Tejun Heo   sysfs, kernfs: in...
306

df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
307
  static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
308
  { return 0; }	/* whatever */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
309
  static inline void kernfs_enable_ns(struct kernfs_node *kn) { }
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
310

324a56e16   Tejun Heo   kernfs: s/sysfs_d...
311
  static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
ac9bba031   Tejun Heo   sysfs, kernfs: im...
312
  { return false; }
3eef34ad7   Tejun Heo   kernfs: implement...
313
314
  static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
  { return -ENOSYS; }
9acee9c55   Tejun Heo   kernfs: implement...
315
316
  static inline size_t kernfs_path_len(struct kernfs_node *kn)
  { return 0; }
3eef34ad7   Tejun Heo   kernfs: implement...
317
318
319
320
321
322
323
324
325
  static inline char * __must_check kernfs_path(struct kernfs_node *kn, char *buf,
  					      size_t buflen)
  { return NULL; }
  
  static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { }
  static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { }
  
  static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
  { return NULL; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
326
327
  static inline struct kernfs_node *
  kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
328
329
  		       const void *ns)
  { return NULL; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
330
331
  static inline void kernfs_get(struct kernfs_node *kn) { }
  static inline void kernfs_put(struct kernfs_node *kn) { }
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
332

0c23b2259   Tejun Heo   kernfs: implement...
333
334
335
336
337
  static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry)
  { return NULL; }
  
  static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
  { return NULL; }
fb02915f4   Tejun Heo   kernfs: make kern...
338
339
340
  static inline struct inode *
  kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
  { return NULL; }
80b9bbefc   Tejun Heo   kernfs: add kernf...
341
  static inline struct kernfs_root *
d35258ef7   Tejun Heo   kernfs: allow nod...
342
343
  kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
  		   void *priv)
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
344
345
346
  { return ERR_PTR(-ENOSYS); }
  
  static inline void kernfs_destroy_root(struct kernfs_root *root) { }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
347
  static inline struct kernfs_node *
bb8b9d095   Tejun Heo   kernfs: add @mode...
348
349
  kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
  		     umode_t mode, void *priv, const void *ns)
93b2b8e4a   Tejun Heo   sysfs, kernfs: in...
350
  { return ERR_PTR(-ENOSYS); }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
351
  static inline struct kernfs_node *
2063d608f   Tejun Heo   kernfs: mark stat...
352
353
  __kernfs_create_file(struct kernfs_node *parent, const char *name,
  		     umode_t mode, loff_t size, const struct kernfs_ops *ops,
dfeb0750b   Tejun Heo   kernfs: remove KE...
354
  		     void *priv, const void *ns, struct lock_class_key *key)
496f73944   Tejun Heo   sysfs, kernfs: in...
355
  { return ERR_PTR(-ENOSYS); }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
356
357
358
  static inline struct kernfs_node *
  kernfs_create_link(struct kernfs_node *parent, const char *name,
  		   struct kernfs_node *target)
5d0e26bb5   Tejun Heo   sysfs, kernfs: in...
359
  { return ERR_PTR(-ENOSYS); }
d35258ef7   Tejun Heo   kernfs: allow nod...
360
  static inline void kernfs_activate(struct kernfs_node *kn) { }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
361
  static inline void kernfs_remove(struct kernfs_node *kn) { }
879f40d19   Tejun Heo   sysfs, kernfs: in...
362

6b0afc2a2   Tejun Heo   kernfs, sysfs, dr...
363
364
  static inline bool kernfs_remove_self(struct kernfs_node *kn)
  { return false; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
365
  static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
879f40d19   Tejun Heo   sysfs, kernfs: in...
366
367
  					   const char *name, const void *ns)
  { return -ENOSYS; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
368
369
  static inline int kernfs_rename_ns(struct kernfs_node *kn,
  				   struct kernfs_node *new_parent,
890ece160   Tejun Heo   sysfs, kernfs: in...
370
371
  				   const char *new_name, const void *new_ns)
  { return -ENOSYS; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
372
  static inline int kernfs_setattr(struct kernfs_node *kn,
5d60418e5   Tejun Heo   sysfs, kernfs: in...
373
374
  				 const struct iattr *iattr)
  { return -ENOSYS; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
375
  static inline void kernfs_notify(struct kernfs_node *kn) { }
024f64711   Tejun Heo   sysfs, kernfs: in...
376

4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
377
378
379
380
381
  static inline const void *kernfs_super_ns(struct super_block *sb)
  { return NULL; }
  
  static inline struct dentry *
  kernfs_mount_ns(struct file_system_type *fs_type, int flags,
26fc9cd20   Jianyu Zhan   kernfs: move the ...
382
383
  		struct kernfs_root *root, unsigned long magic,
  		bool *new_sb_created, const void *ns)
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
384
385
386
387
388
  { return ERR_PTR(-ENOSYS); }
  
  static inline void kernfs_kill_sb(struct super_block *sb) { }
  
  static inline void kernfs_init(void) { }
ba341d55a   Tejun Heo   kernfs: add CONFI...
389
  #endif	/* CONFIG_KERNFS */
879f40d19   Tejun Heo   sysfs, kernfs: in...
390

324a56e16   Tejun Heo   kernfs: s/sysfs_d...
391
392
  static inline struct kernfs_node *
  kernfs_find_and_get(struct kernfs_node *kn, const char *name)
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
393
  {
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
394
  	return kernfs_find_and_get_ns(kn, name, NULL);
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
395
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
396
  static inline struct kernfs_node *
bb8b9d095   Tejun Heo   kernfs: add @mode...
397
398
  kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
  		  void *priv)
93b2b8e4a   Tejun Heo   sysfs, kernfs: in...
399
  {
bb8b9d095   Tejun Heo   kernfs: add @mode...
400
  	return kernfs_create_dir_ns(parent, name, mode, priv, NULL);
93b2b8e4a   Tejun Heo   sysfs, kernfs: in...
401
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
402
403
  static inline struct kernfs_node *
  kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
517e64f57   Tejun Heo   sysfs, kernfs: re...
404
405
406
407
408
409
410
411
  		      umode_t mode, loff_t size, const struct kernfs_ops *ops,
  		      void *priv, const void *ns)
  {
  	struct lock_class_key *key = NULL;
  
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  	key = (struct lock_class_key *)&ops->lockdep_key;
  #endif
2063d608f   Tejun Heo   kernfs: mark stat...
412
  	return __kernfs_create_file(parent, name, mode, size, ops, priv, ns,
dfeb0750b   Tejun Heo   kernfs: remove KE...
413
  				    key);
517e64f57   Tejun Heo   sysfs, kernfs: re...
414
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
415
416
  static inline struct kernfs_node *
  kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode,
496f73944   Tejun Heo   sysfs, kernfs: in...
417
418
419
420
  		   loff_t size, const struct kernfs_ops *ops, void *priv)
  {
  	return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL);
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
421
  static inline int kernfs_remove_by_name(struct kernfs_node *parent,
879f40d19   Tejun Heo   sysfs, kernfs: in...
422
423
424
425
  					const char *name)
  {
  	return kernfs_remove_by_name_ns(parent, name, NULL);
  }
0c23b2259   Tejun Heo   kernfs: implement...
426
427
428
429
430
431
  static inline int kernfs_rename(struct kernfs_node *kn,
  				struct kernfs_node *new_parent,
  				const char *new_name)
  {
  	return kernfs_rename_ns(kn, new_parent, new_name, NULL);
  }
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
432
433
  static inline struct dentry *
  kernfs_mount(struct file_system_type *fs_type, int flags,
26fc9cd20   Jianyu Zhan   kernfs: move the ...
434
435
  		struct kernfs_root *root, unsigned long magic,
  		bool *new_sb_created)
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
436
  {
26fc9cd20   Jianyu Zhan   kernfs: move the ...
437
438
  	return kernfs_mount_ns(fs_type, flags, root,
  				magic, new_sb_created, NULL);
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
439
  }
b8441ed27   Tejun Heo   sysfs, kernfs: ad...
440
  #endif	/* __LINUX_KERNFS_H */