Blame view

include/linux/kernfs.h 13 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,
2063d608f   Tejun Heo   kernfs: mark stat...
44
  	KERNFS_STATIC_NAME	= 0x0200,
6b0afc2a2   Tejun Heo   kernfs, sysfs, dr...
45
46
  	KERNFS_SUICIDAL		= 0x0400,
  	KERNFS_SUICIDED		= 0x0800,
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
47
  };
d35258ef7   Tejun Heo   kernfs: allow nod...
48
49
50
51
  /* @flags for kernfs_create_root() */
  enum kernfs_root_flag {
  	KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001,
  };
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
52
53
  /* type-specific structures for kernfs_node union members */
  struct kernfs_elem_dir {
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
54
  	unsigned long		subdirs;
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
55
  	/* children rbtree starts here and goes through kn->rb */
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
56
57
58
59
  	struct rb_root		children;
  
  	/*
  	 * The kernfs hierarchy this directory belongs to.  This fits
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
60
  	 * better directly in kernfs_node but is here to save space.
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
61
62
63
  	 */
  	struct kernfs_root	*root;
  };
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
64
65
  struct kernfs_elem_symlink {
  	struct kernfs_node	*target_kn;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
66
  };
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
67
  struct kernfs_elem_attr {
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
68
  	const struct kernfs_ops	*ops;
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
69
  	struct kernfs_open_node	*open;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
70
71
72
73
  	loff_t			size;
  };
  
  /*
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
74
75
   * 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...
76
77
   * private to kernfs and shouldn't be accessed directly by kernfs users.
   *
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
78
79
80
   * 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...
81
   */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
82
  struct kernfs_node {
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
83
84
  	atomic_t		count;
  	atomic_t		active;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
85
86
87
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  	struct lockdep_map	dep_map;
  #endif
3eef34ad7   Tejun Heo   kernfs: implement...
88
89
90
91
92
93
  	/*
  	 * 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...
94
95
  	struct kernfs_node	*parent;
  	const char		*name;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
96

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

adc5e8b58   Tejun Heo   kernfs: drop s_ p...
99
  	const void		*ns;	/* namespace tag */
9b0925a6f   Greg Kroah-Hartman   Revert "kernfs: i...
100
  	unsigned int		hash;	/* ns + name hash */
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
101
  	union {
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
102
103
104
  		struct kernfs_elem_dir		dir;
  		struct kernfs_elem_symlink	symlink;
  		struct kernfs_elem_attr		attr;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
105
106
107
  	};
  
  	void			*priv;
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
108
109
110
  	unsigned short		flags;
  	umode_t			mode;
  	unsigned int		ino;
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
111
  	struct kernfs_iattrs	*iattr;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
112
  };
b8441ed27   Tejun Heo   sysfs, kernfs: ad...
113

80b9bbefc   Tejun Heo   kernfs: add kernf...
114
  /*
90c07c895   Tejun Heo   kernfs: rename ke...
115
116
117
118
119
   * 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...
120
   */
90c07c895   Tejun Heo   kernfs: rename ke...
121
  struct kernfs_syscall_ops {
6a7fed4ee   Tejun Heo   kernfs: implement...
122
123
  	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...
124
125
126
127
128
129
  	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...
130
131
  struct kernfs_root {
  	/* published fields */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
132
  	struct kernfs_node	*kn;
d35258ef7   Tejun Heo   kernfs: allow nod...
133
  	unsigned int		flags;	/* KERNFS_ROOT_* flags */
bc755553d   Tejun Heo   sysfs, kernfs: ma...
134
135
136
  
  	/* private fields, do not use outside kernfs proper */
  	struct ida		ino_ida;
90c07c895   Tejun Heo   kernfs: rename ke...
137
  	struct kernfs_syscall_ops *syscall_ops;
abd54f028   Tejun Heo   kernfs: replace k...
138
  	wait_queue_head_t	deactivate_waitq;
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
139
  };
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
140
  struct kernfs_open_file {
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
141
  	/* published fields */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
142
  	struct kernfs_node	*kn;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
143
  	struct file		*file;
2536390da   Tejun Heo   kernfs: add kernf...
144
  	void			*priv;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
145
146
147
148
149
  
  	/* private fields, do not use outside kernfs proper */
  	struct mutex		mutex;
  	int			event;
  	struct list_head	list;
b7ce40cff   Tejun Heo   kernfs: cache ato...
150
  	size_t			atomic_write_len;
dd8a5b036   Tejun Heo   sysfs, kernfs: mo...
151
152
153
  	bool			mmapped;
  	const struct vm_operations_struct *vm_ops;
  };
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
154
155
156
157
  struct kernfs_ops {
  	/*
  	 * Read is handled by either seq_file or raw_read().
  	 *
d19b9846d   Tejun Heo   sysfs, kernfs: ad...
158
159
160
  	 * 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...
161
  	 * associated kernfs_open_file.
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
162
163
164
165
166
  	 *
  	 * 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...
167
168
169
170
  
  	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...
171

c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
172
  	ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes,
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
173
174
175
  			loff_t off);
  
  	/*
4d3773c4b   Tejun Heo   kernfs: implement...
176
177
178
179
180
  	 * 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...
181
  	 */
4d3773c4b   Tejun Heo   kernfs: implement...
182
  	size_t atomic_write_len;
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
183
  	ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes,
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
184
  			 loff_t off);
c525aaddc   Tejun Heo   kernfs: s/sysfs/k...
185
  	int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma);
517e64f57   Tejun Heo   sysfs, kernfs: re...
186
187
188
189
  
  #ifdef CONFIG_DEBUG_LOCK_ALLOC
  	struct lock_class_key	lockdep_key;
  #endif
f6acf8bb6   Tejun Heo   sysfs, kernfs: in...
190
  };
ba341d55a   Tejun Heo   kernfs: add CONFI...
191
  #ifdef CONFIG_KERNFS
879f40d19   Tejun Heo   sysfs, kernfs: in...
192

df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
193
  static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
194
  {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
195
  	return kn->flags & KERNFS_TYPE_MASK;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
196
197
198
199
  }
  
  /**
   * kernfs_enable_ns - enable namespace under a directory
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
200
   * @kn: directory of interest, should be empty
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
201
   *
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
202
203
   * 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...
204
205
   * only the ones which match the super_block's tag will be visible.
   */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
206
  static inline void kernfs_enable_ns(struct kernfs_node *kn)
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
207
  {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
208
  	WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
adc5e8b58   Tejun Heo   kernfs: drop s_ p...
209
  	WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
210
  	kn->flags |= KERNFS_NS;
cf9e5a73a   Tejun Heo   sysfs, kernfs: ma...
211
  }
ac9bba031   Tejun Heo   sysfs, kernfs: im...
212
213
  /**
   * kernfs_ns_enabled - test whether namespace is enabled
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
214
   * @kn: the node to test
ac9bba031   Tejun Heo   sysfs, kernfs: im...
215
216
217
   *
   * Test whether namespace filtering is enabled for the children of @ns.
   */
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
218
  static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
ac9bba031   Tejun Heo   sysfs, kernfs: im...
219
  {
df23fc39b   Tejun Heo   kernfs: s/sysfs/k...
220
  	return kn->flags & KERNFS_NS;
ac9bba031   Tejun Heo   sysfs, kernfs: im...
221
  }
3eef34ad7   Tejun Heo   kernfs: implement...
222
223
224
225
226
227
  int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
  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...
228
229
230
231
  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...
232

0c23b2259   Tejun Heo   kernfs: implement...
233
234
  struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
  struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
90c07c895   Tejun Heo   kernfs: rename ke...
235
  struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
d35258ef7   Tejun Heo   kernfs: allow nod...
236
  				       unsigned int flags, void *priv);
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
237
  void kernfs_destroy_root(struct kernfs_root *root);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
238
  struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
bb8b9d095   Tejun Heo   kernfs: add @mode...
239
240
  					 const char *name, umode_t mode,
  					 void *priv, const void *ns);
2063d608f   Tejun Heo   kernfs: mark stat...
241
242
243
244
245
246
247
  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,
  					 bool name_is_static,
  					 struct lock_class_key *key);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
248
249
250
  struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
  				       const char *name,
  				       struct kernfs_node *target);
d35258ef7   Tejun Heo   kernfs: allow nod...
251
  void kernfs_activate(struct kernfs_node *kn);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
252
  void kernfs_remove(struct kernfs_node *kn);
6b0afc2a2   Tejun Heo   kernfs, sysfs, dr...
253
254
255
  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...
256
  int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
879f40d19   Tejun Heo   sysfs, kernfs: in...
257
  			     const void *ns);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
258
  int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
890ece160   Tejun Heo   sysfs, kernfs: in...
259
  		     const char *new_name, const void *new_ns);
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
260
261
  int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
  void kernfs_notify(struct kernfs_node *kn);
879f40d19   Tejun Heo   sysfs, kernfs: in...
262

4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
263
264
  const void *kernfs_super_ns(struct super_block *sb);
  struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags,
fed95bab8   Li Zefan   sysfs: fix namesp...
265
266
  			       struct kernfs_root *root, bool *new_sb_created,
  			       const void *ns);
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
267
268
269
  void kernfs_kill_sb(struct super_block *sb);
  
  void kernfs_init(void);
ba341d55a   Tejun Heo   kernfs: add CONFI...
270
  #else	/* CONFIG_KERNFS */
879f40d19   Tejun Heo   sysfs, kernfs: in...
271

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

324a56e16   Tejun Heo   kernfs: s/sysfs_d...
276
  static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
ac9bba031   Tejun Heo   sysfs, kernfs: im...
277
  { return false; }
3eef34ad7   Tejun Heo   kernfs: implement...
278
279
280
281
282
283
284
285
286
287
288
289
  static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
  { return -ENOSYS; }
  
  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...
290
291
  static inline struct kernfs_node *
  kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
292
293
  		       const void *ns)
  { return NULL; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
294
295
  static inline void kernfs_get(struct kernfs_node *kn) { }
  static inline void kernfs_put(struct kernfs_node *kn) { }
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
296

0c23b2259   Tejun Heo   kernfs: implement...
297
298
299
300
301
  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; }
80b9bbefc   Tejun Heo   kernfs: add kernf...
302
  static inline struct kernfs_root *
d35258ef7   Tejun Heo   kernfs: allow nod...
303
304
  kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
  		   void *priv)
ba7443bc6   Tejun Heo   sysfs, kernfs: im...
305
306
307
  { return ERR_PTR(-ENOSYS); }
  
  static inline void kernfs_destroy_root(struct kernfs_root *root) { }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
308
  static inline struct kernfs_node *
bb8b9d095   Tejun Heo   kernfs: add @mode...
309
310
  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...
311
  { return ERR_PTR(-ENOSYS); }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
312
  static inline struct kernfs_node *
2063d608f   Tejun Heo   kernfs: mark stat...
313
314
315
316
  __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, bool name_is_static,
  		     struct lock_class_key *key)
496f73944   Tejun Heo   sysfs, kernfs: in...
317
  { return ERR_PTR(-ENOSYS); }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
318
319
320
  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...
321
  { return ERR_PTR(-ENOSYS); }
d35258ef7   Tejun Heo   kernfs: allow nod...
322
  static inline void kernfs_activate(struct kernfs_node *kn) { }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
323
  static inline void kernfs_remove(struct kernfs_node *kn) { }
879f40d19   Tejun Heo   sysfs, kernfs: in...
324

6b0afc2a2   Tejun Heo   kernfs, sysfs, dr...
325
326
  static inline bool kernfs_remove_self(struct kernfs_node *kn)
  { return false; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
327
  static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
879f40d19   Tejun Heo   sysfs, kernfs: in...
328
329
  					   const char *name, const void *ns)
  { return -ENOSYS; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
330
331
  static inline int kernfs_rename_ns(struct kernfs_node *kn,
  				   struct kernfs_node *new_parent,
890ece160   Tejun Heo   sysfs, kernfs: in...
332
333
  				   const char *new_name, const void *new_ns)
  { return -ENOSYS; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
334
  static inline int kernfs_setattr(struct kernfs_node *kn,
5d60418e5   Tejun Heo   sysfs, kernfs: in...
335
336
  				 const struct iattr *iattr)
  { return -ENOSYS; }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
337
  static inline void kernfs_notify(struct kernfs_node *kn) { }
024f64711   Tejun Heo   sysfs, kernfs: in...
338

4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
339
340
341
342
343
  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,
fed95bab8   Li Zefan   sysfs: fix namesp...
344
  		struct kernfs_root *root, bool *new_sb_created, const void *ns)
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
345
346
347
348
349
  { 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...
350
  #endif	/* CONFIG_KERNFS */
879f40d19   Tejun Heo   sysfs, kernfs: in...
351

324a56e16   Tejun Heo   kernfs: s/sysfs_d...
352
353
  static inline struct kernfs_node *
  kernfs_find_and_get(struct kernfs_node *kn, const char *name)
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
354
  {
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
355
  	return kernfs_find_and_get_ns(kn, name, NULL);
ccf73cf33   Tejun Heo   sysfs, kernfs: in...
356
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
357
  static inline struct kernfs_node *
bb8b9d095   Tejun Heo   kernfs: add @mode...
358
359
  kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
  		  void *priv)
93b2b8e4a   Tejun Heo   sysfs, kernfs: in...
360
  {
bb8b9d095   Tejun Heo   kernfs: add @mode...
361
  	return kernfs_create_dir_ns(parent, name, mode, priv, NULL);
93b2b8e4a   Tejun Heo   sysfs, kernfs: in...
362
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
363
364
  static inline struct kernfs_node *
  kernfs_create_file_ns(struct kernfs_node *parent, const char *name,
517e64f57   Tejun Heo   sysfs, kernfs: re...
365
366
367
368
369
370
371
372
  		      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...
373
374
  	return __kernfs_create_file(parent, name, mode, size, ops, priv, ns,
  				    false, key);
517e64f57   Tejun Heo   sysfs, kernfs: re...
375
  }
324a56e16   Tejun Heo   kernfs: s/sysfs_d...
376
377
  static inline struct kernfs_node *
  kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode,
496f73944   Tejun Heo   sysfs, kernfs: in...
378
379
380
381
  		   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...
382
  static inline int kernfs_remove_by_name(struct kernfs_node *parent,
879f40d19   Tejun Heo   sysfs, kernfs: in...
383
384
385
386
  					const char *name)
  {
  	return kernfs_remove_by_name_ns(parent, name, NULL);
  }
0c23b2259   Tejun Heo   kernfs: implement...
387
388
389
390
391
392
  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...
393
394
  static inline struct dentry *
  kernfs_mount(struct file_system_type *fs_type, int flags,
fed95bab8   Li Zefan   sysfs: fix namesp...
395
  	     struct kernfs_root *root, bool *new_sb_created)
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
396
  {
fed95bab8   Li Zefan   sysfs: fix namesp...
397
  	return kernfs_mount_ns(fs_type, flags, root, new_sb_created, NULL);
4b93dc9b1   Tejun Heo   sysfs, kernfs: pr...
398
  }
b8441ed27   Tejun Heo   sysfs, kernfs: ad...
399
  #endif	/* __LINUX_KERNFS_H */