kernfs: Factor out kernfs_activate_one()
[linux-block.git] / include / linux / kernfs.h
CommitLineData
55716d26 1/* SPDX-License-Identifier: GPL-2.0-only */
b8441ed2
TH
2/*
3 * kernfs.h - pseudo filesystem decoupled from vfs locking
b8441ed2
TH
4 */
5
6#ifndef __LINUX_KERNFS_H
7#define __LINUX_KERNFS_H
8
5d0e26bb 9#include <linux/err.h>
dd8a5b03
TH
10#include <linux/list.h>
11#include <linux/mutex.h>
bc755553 12#include <linux/idr.h>
517e64f5 13#include <linux/lockdep.h>
cf9e5a73
TH
14#include <linux/rbtree.h>
15#include <linux/atomic.h>
79f1c730
AS
16#include <linux/bug.h>
17#include <linux/types.h>
488dee96 18#include <linux/uidgid.h>
abd54f02 19#include <linux/wait.h>
393c3714 20#include <linux/rwsem.h>
1d25b84e 21#include <linux/cache.h>
879f40d1 22
5d60418e 23struct file;
917f56ca 24struct dentry;
5d60418e 25struct iattr;
dd8a5b03
TH
26struct seq_file;
27struct vm_area_struct;
79f1c730 28struct vm_operations_struct;
4b93dc9b
TH
29struct super_block;
30struct file_system_type;
147e1a97 31struct poll_table_struct;
23bf1b6b 32struct fs_context;
5d60418e 33
23bf1b6b 34struct kernfs_fs_context;
c525aadd
TH
35struct kernfs_open_node;
36struct kernfs_iattrs;
cf9e5a73 37
1d25b84e
IK
38/*
39 * NR_KERNFS_LOCK_BITS determines size (NR_KERNFS_LOCKS) of hash
40 * table of locks.
41 * Having a small hash table would impact scalability, since
42 * more and more kernfs_node objects will end up using same lock
43 * and having a very large hash table would waste memory.
44 *
45 * At the moment size of hash table of locks is being set based on
46 * the number of CPUs as follows:
47 *
48 * NR_CPU NR_KERNFS_LOCK_BITS NR_KERNFS_LOCKS
49 * 1 1 2
50 * 2-3 2 4
51 * 4-7 4 16
52 * 8-15 6 64
53 * 16-31 8 256
54 * 32 and more 10 1024
55 *
56 * The above relation between NR_CPU and number of locks is based
57 * on some internal experimentation which involved booting qemu
58 * with different values of smp, performing some sysfs operations
59 * on all CPUs and observing how increase in number of locks impacts
60 * completion time of these sysfs operations on each CPU.
61 */
62#ifdef CONFIG_SMP
63#define NR_KERNFS_LOCK_BITS (2 * (ilog2(NR_CPUS < 32 ? NR_CPUS : 32)))
64#else
65#define NR_KERNFS_LOCK_BITS 1
66#endif
67
68#define NR_KERNFS_LOCKS (1 << NR_KERNFS_LOCK_BITS)
69
70/*
71 * There's one kernfs_open_file for each open file and one kernfs_open_node
72 * for each kernfs_node with one or more open files.
73 *
74 * filp->private_data points to seq_file whose ->private points to
75 * kernfs_open_file.
76 *
77 * kernfs_open_files are chained at kernfs_open_node->files, which is
78 * protected by kernfs_global_locks.open_file_mutex[i].
79 *
80 * To reduce possible contention in sysfs access, arising due to single
81 * locks, use an array of locks (e.g. open_file_mutex) and use kernfs_node
82 * object address as hash keys to get the index of these locks.
83 *
84 * Hashed mutexes are safe to use here because operations using these don't
85 * rely on global exclusion.
86 *
87 * In future we intend to replace other global locks with hashed ones as well.
88 * kernfs_global_locks acts as a holder for all such hash tables.
89 */
90struct kernfs_global_locks {
91 struct mutex open_file_mutex[NR_KERNFS_LOCKS];
92};
93
cf9e5a73 94enum kernfs_node_type {
df23fc39
TH
95 KERNFS_DIR = 0x0001,
96 KERNFS_FILE = 0x0002,
97 KERNFS_LINK = 0x0004,
cf9e5a73
TH
98};
99
0c47383b
DX
100#define KERNFS_TYPE_MASK 0x000f
101#define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK
102#define KERNFS_MAX_USER_XATTRS 128
103#define KERNFS_USER_XATTR_SIZE_LIMIT (128 << 10)
cf9e5a73
TH
104
105enum kernfs_node_flag {
d35258ef 106 KERNFS_ACTIVATED = 0x0010,
df23fc39
TH
107 KERNFS_NS = 0x0020,
108 KERNFS_HAS_SEQ_SHOW = 0x0040,
109 KERNFS_HAS_MMAP = 0x0080,
110 KERNFS_LOCKDEP = 0x0100,
6b0afc2a
TH
111 KERNFS_SUICIDAL = 0x0400,
112 KERNFS_SUICIDED = 0x0800,
ea015218 113 KERNFS_EMPTY_DIR = 0x1000,
0e67db2f 114 KERNFS_HAS_RELEASE = 0x2000,
c2549174 115 KERNFS_REMOVING = 0x4000,
cf9e5a73
TH
116};
117
d35258ef
TH
118/* @flags for kernfs_create_root() */
119enum kernfs_root_flag {
555724a8
TH
120 /*
121 * kernfs_nodes are created in the deactivated state and invisible.
122 * They require explicit kernfs_activate() to become visible. This
123 * can be used to make related nodes become visible atomically
124 * after all nodes are created successfully.
125 */
126 KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001,
127
128 /*
0d1a393d 129 * For regular files, if the opener has CAP_DAC_OVERRIDE, open(2)
555724a8
TH
130 * succeeds regardless of the RW permissions. sysfs had an extra
131 * layer of enforcement where open(2) fails with -EACCES regardless
132 * of CAP_DAC_OVERRIDE if the permission doesn't have the
133 * respective read or write access at all (none of S_IRUGO or
134 * S_IWUGO) or the respective operation isn't implemented. The
135 * following flag enables that behavior.
136 */
137 KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK = 0x0002,
aa818825
SL
138
139 /*
140 * The filesystem supports exportfs operation, so userspace can use
141 * fhandle to access nodes of the fs.
142 */
143 KERNFS_ROOT_SUPPORT_EXPORTOP = 0x0004,
0c47383b
DX
144
145 /*
146 * Support user xattrs to be written to nodes rooted at this root.
147 */
148 KERNFS_ROOT_SUPPORT_USER_XATTR = 0x0008,
d35258ef
TH
149};
150
324a56e1
TH
151/* type-specific structures for kernfs_node union members */
152struct kernfs_elem_dir {
cf9e5a73 153 unsigned long subdirs;
adc5e8b5 154 /* children rbtree starts here and goes through kn->rb */
cf9e5a73
TH
155 struct rb_root children;
156
157 /*
158 * The kernfs hierarchy this directory belongs to. This fits
324a56e1 159 * better directly in kernfs_node but is here to save space.
cf9e5a73
TH
160 */
161 struct kernfs_root *root;
895adbec
IK
162 /*
163 * Monotonic revision counter, used to identify if a directory
164 * node has changed during negative dentry revalidation.
165 */
166 unsigned long rev;
cf9e5a73
TH
167};
168
324a56e1
TH
169struct kernfs_elem_symlink {
170 struct kernfs_node *target_kn;
cf9e5a73
TH
171};
172
324a56e1 173struct kernfs_elem_attr {
cf9e5a73 174 const struct kernfs_ops *ops;
086c00c7 175 struct kernfs_open_node __rcu *open;
cf9e5a73 176 loff_t size;
2fd26970 177 struct kernfs_node *notify_next; /* for kernfs_notify() */
cf9e5a73
TH
178};
179
180/*
324a56e1
TH
181 * kernfs_node - the building block of kernfs hierarchy. Each and every
182 * kernfs node is represented by single kernfs_node. Most fields are
cf9e5a73
TH
183 * private to kernfs and shouldn't be accessed directly by kernfs users.
184 *
21774fd8 185 * As long as count reference is held, the kernfs_node itself is
324a56e1
TH
186 * accessible. Dereferencing elem or any other outer entity requires
187 * active reference.
cf9e5a73 188 */
324a56e1 189struct kernfs_node {
adc5e8b5
TH
190 atomic_t count;
191 atomic_t active;
cf9e5a73
TH
192#ifdef CONFIG_DEBUG_LOCK_ALLOC
193 struct lockdep_map dep_map;
194#endif
3eef34ad
TH
195 /*
196 * Use kernfs_get_parent() and kernfs_name/path() instead of
197 * accessing the following two fields directly. If the node is
198 * never moved to a different parent, it is safe to access the
199 * parent directly.
200 */
adc5e8b5
TH
201 struct kernfs_node *parent;
202 const char *name;
cf9e5a73 203
adc5e8b5 204 struct rb_node rb;
cf9e5a73 205
adc5e8b5 206 const void *ns; /* namespace tag */
9b0925a6 207 unsigned int hash; /* ns + name hash */
cf9e5a73 208 union {
adc5e8b5
TH
209 struct kernfs_elem_dir dir;
210 struct kernfs_elem_symlink symlink;
211 struct kernfs_elem_attr attr;
cf9e5a73
TH
212 };
213
214 void *priv;
215
67c0496e 216 /*
40430452
TH
217 * 64bit unique ID. On 64bit ino setups, id is the ino. On 32bit,
218 * the low 32bits are ino and upper generation.
67c0496e
TH
219 */
220 u64 id;
221
adc5e8b5
TH
222 unsigned short flags;
223 umode_t mode;
c525aadd 224 struct kernfs_iattrs *iattr;
cf9e5a73 225};
b8441ed2 226
80b9bbef 227/*
90c07c89
TH
228 * kernfs_syscall_ops may be specified on kernfs_create_root() to support
229 * syscalls. These optional callbacks are invoked on the matching syscalls
230 * and can perform any kernfs operations which don't necessarily have to be
231 * the exact operation requested. An active reference is held for each
232 * kernfs_node parameter.
80b9bbef 233 */
90c07c89 234struct kernfs_syscall_ops {
6a7fed4e
TH
235 int (*show_options)(struct seq_file *sf, struct kernfs_root *root);
236
80b9bbef
TH
237 int (*mkdir)(struct kernfs_node *parent, const char *name,
238 umode_t mode);
239 int (*rmdir)(struct kernfs_node *kn);
240 int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent,
241 const char *new_name);
4f41fc59
SH
242 int (*show_path)(struct seq_file *sf, struct kernfs_node *kn,
243 struct kernfs_root *root);
80b9bbef
TH
244};
245
f2eb478f 246struct kernfs_node *kernfs_root_to_node(struct kernfs_root *root);
ba7443bc 247
c525aadd 248struct kernfs_open_file {
dd8a5b03 249 /* published fields */
324a56e1 250 struct kernfs_node *kn;
dd8a5b03 251 struct file *file;
0e67db2f 252 struct seq_file *seq_file;
2536390d 253 void *priv;
dd8a5b03
TH
254
255 /* private fields, do not use outside kernfs proper */
256 struct mutex mutex;
e4234a1f 257 struct mutex prealloc_mutex;
dd8a5b03
TH
258 int event;
259 struct list_head list;
2b75869b 260 char *prealloc_buf;
dd8a5b03 261
b7ce40cf 262 size_t atomic_write_len;
a1d82aff 263 bool mmapped:1;
0e67db2f 264 bool released:1;
dd8a5b03
TH
265 const struct vm_operations_struct *vm_ops;
266};
267
f6acf8bb 268struct kernfs_ops {
0e67db2f
TH
269 /*
270 * Optional open/release methods. Both are called with
271 * @of->seq_file populated.
272 */
273 int (*open)(struct kernfs_open_file *of);
274 void (*release)(struct kernfs_open_file *of);
275
f6acf8bb
TH
276 /*
277 * Read is handled by either seq_file or raw_read().
278 *
d19b9846
TH
279 * If seq_show() is present, seq_file path is active. Other seq
280 * operations are optional and if not implemented, the behavior is
281 * equivalent to single_open(). @sf->private points to the
c525aadd 282 * associated kernfs_open_file.
f6acf8bb
TH
283 *
284 * read() is bounced through kernel buffer and a read larger than
285 * PAGE_SIZE results in partial operation of PAGE_SIZE.
286 */
287 int (*seq_show)(struct seq_file *sf, void *v);
d19b9846
TH
288
289 void *(*seq_start)(struct seq_file *sf, loff_t *ppos);
290 void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos);
291 void (*seq_stop)(struct seq_file *sf, void *v);
f6acf8bb 292
c525aadd 293 ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes,
f6acf8bb
TH
294 loff_t off);
295
296 /*
4d3773c4
TH
297 * write() is bounced through kernel buffer. If atomic_write_len
298 * is not set, a write larger than PAGE_SIZE results in partial
299 * operations of PAGE_SIZE chunks. If atomic_write_len is set,
300 * writes upto the specified size are executed atomically but
301 * larger ones are rejected with -E2BIG.
f6acf8bb 302 */
4d3773c4 303 size_t atomic_write_len;
2b75869b
N
304 /*
305 * "prealloc" causes a buffer to be allocated at open for
306 * all read/write requests. As ->seq_show uses seq_read()
307 * which does its own allocation, it is incompatible with
308 * ->prealloc. Provide ->read and ->write with ->prealloc.
309 */
310 bool prealloc;
c525aadd 311 ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes,
f6acf8bb
TH
312 loff_t off);
313
147e1a97
JW
314 __poll_t (*poll)(struct kernfs_open_file *of,
315 struct poll_table_struct *pt);
316
c525aadd 317 int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma);
f6acf8bb
TH
318};
319
23bf1b6b
DH
320/*
321 * The kernfs superblock creation/mount parameter context.
322 */
323struct kernfs_fs_context {
324 struct kernfs_root *root; /* Root of the hierarchy being mounted */
325 void *ns_tag; /* Namespace tag of the mount (or NULL) */
326 unsigned long magic; /* File system specific magic number */
327
328 /* The following are set/used by kernfs_mount() */
329 bool new_sb_created; /* Set to T if we allocated a new sb */
330};
331
ba341d55 332#ifdef CONFIG_KERNFS
879f40d1 333
df23fc39 334static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
cf9e5a73 335{
df23fc39 336 return kn->flags & KERNFS_TYPE_MASK;
cf9e5a73
TH
337}
338
67c0496e
TH
339static inline ino_t kernfs_id_ino(u64 id)
340{
40430452
TH
341 /* id is ino if ino_t is 64bit; otherwise, low 32bits */
342 if (sizeof(ino_t) >= sizeof(u64))
343 return id;
344 else
345 return (u32)id;
67c0496e
TH
346}
347
348static inline u32 kernfs_id_gen(u64 id)
349{
40430452
TH
350 /* gen is fixed at 1 if ino_t is 64bit; otherwise, high 32bits */
351 if (sizeof(ino_t) >= sizeof(u64))
352 return 1;
353 else
354 return id >> 32;
67c0496e
TH
355}
356
357static inline ino_t kernfs_ino(struct kernfs_node *kn)
358{
359 return kernfs_id_ino(kn->id);
360}
361
362static inline ino_t kernfs_gen(struct kernfs_node *kn)
363{
364 return kernfs_id_gen(kn->id);
365}
366
cf9e5a73
TH
367/**
368 * kernfs_enable_ns - enable namespace under a directory
324a56e1 369 * @kn: directory of interest, should be empty
cf9e5a73 370 *
324a56e1
TH
371 * This is to be called right after @kn is created to enable namespace
372 * under it. All children of @kn must have non-NULL namespace tags and
cf9e5a73
TH
373 * only the ones which match the super_block's tag will be visible.
374 */
324a56e1 375static inline void kernfs_enable_ns(struct kernfs_node *kn)
cf9e5a73 376{
df23fc39 377 WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR);
adc5e8b5 378 WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children));
df23fc39 379 kn->flags |= KERNFS_NS;
cf9e5a73
TH
380}
381
ac9bba03
TH
382/**
383 * kernfs_ns_enabled - test whether namespace is enabled
324a56e1 384 * @kn: the node to test
ac9bba03
TH
385 *
386 * Test whether namespace filtering is enabled for the children of @ns.
387 */
324a56e1 388static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
ac9bba03 389{
df23fc39 390 return kn->flags & KERNFS_NS;
ac9bba03
TH
391}
392
3eef34ad 393int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen);
9f6df573
AK
394int kernfs_path_from_node(struct kernfs_node *root_kn, struct kernfs_node *kn,
395 char *buf, size_t buflen);
3eef34ad
TH
396void pr_cont_kernfs_name(struct kernfs_node *kn);
397void pr_cont_kernfs_path(struct kernfs_node *kn);
398struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn);
324a56e1
TH
399struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent,
400 const char *name, const void *ns);
bd96f76a
TH
401struct kernfs_node *kernfs_walk_and_get_ns(struct kernfs_node *parent,
402 const char *path, const void *ns);
324a56e1
TH
403void kernfs_get(struct kernfs_node *kn);
404void kernfs_put(struct kernfs_node *kn);
ccf73cf3 405
0c23b225
TH
406struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry);
407struct kernfs_root *kernfs_root_from_sb(struct super_block *sb);
fb02915f 408struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn);
0c23b225 409
fb3c8315
AK
410struct dentry *kernfs_node_dentry(struct kernfs_node *kn,
411 struct super_block *sb);
90c07c89 412struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops,
d35258ef 413 unsigned int flags, void *priv);
ba7443bc
TH
414void kernfs_destroy_root(struct kernfs_root *root);
415
324a56e1 416struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent,
bb8b9d09 417 const char *name, umode_t mode,
488dee96 418 kuid_t uid, kgid_t gid,
bb8b9d09 419 void *priv, const void *ns);
ea015218
EB
420struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent,
421 const char *name);
2063d608 422struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
488dee96
DT
423 const char *name, umode_t mode,
424 kuid_t uid, kgid_t gid,
425 loff_t size,
2063d608
TH
426 const struct kernfs_ops *ops,
427 void *priv, const void *ns,
2063d608 428 struct lock_class_key *key);
324a56e1
TH
429struct kernfs_node *kernfs_create_link(struct kernfs_node *parent,
430 const char *name,
431 struct kernfs_node *target);
d35258ef 432void kernfs_activate(struct kernfs_node *kn);
324a56e1 433void kernfs_remove(struct kernfs_node *kn);
6b0afc2a
TH
434void kernfs_break_active_protection(struct kernfs_node *kn);
435void kernfs_unbreak_active_protection(struct kernfs_node *kn);
436bool kernfs_remove_self(struct kernfs_node *kn);
324a56e1 437int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name,
879f40d1 438 const void *ns);
324a56e1 439int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent,
890ece16 440 const char *new_name, const void *new_ns);
324a56e1 441int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr);
147e1a97
JW
442__poll_t kernfs_generic_poll(struct kernfs_open_file *of,
443 struct poll_table_struct *pt);
324a56e1 444void kernfs_notify(struct kernfs_node *kn);
879f40d1 445
1537ad15
OM
446int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
447 void *value, size_t size);
448int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
449 const void *value, size_t size, int flags);
b230d5ab 450
4b93dc9b 451const void *kernfs_super_ns(struct super_block *sb);
23bf1b6b
DH
452int kernfs_get_tree(struct fs_context *fc);
453void kernfs_free_fs_context(struct fs_context *fc);
4b93dc9b
TH
454void kernfs_kill_sb(struct super_block *sb);
455
456void kernfs_init(void);
457
fe0f726c
TH
458struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root,
459 u64 id);
ba341d55 460#else /* CONFIG_KERNFS */
879f40d1 461
df23fc39 462static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn)
cf9e5a73
TH
463{ return 0; } /* whatever */
464
324a56e1 465static inline void kernfs_enable_ns(struct kernfs_node *kn) { }
cf9e5a73 466
324a56e1 467static inline bool kernfs_ns_enabled(struct kernfs_node *kn)
ac9bba03
TH
468{ return false; }
469
3eef34ad
TH
470static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen)
471{ return -ENOSYS; }
472
0e0b2afd
TH
473static inline int kernfs_path_from_node(struct kernfs_node *root_kn,
474 struct kernfs_node *kn,
475 char *buf, size_t buflen)
476{ return -ENOSYS; }
477
3eef34ad
TH
478static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { }
479static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { }
480
481static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
482{ return NULL; }
483
324a56e1
TH
484static inline struct kernfs_node *
485kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name,
ccf73cf3
TH
486 const void *ns)
487{ return NULL; }
bd96f76a
TH
488static inline struct kernfs_node *
489kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path,
490 const void *ns)
491{ return NULL; }
ccf73cf3 492
324a56e1
TH
493static inline void kernfs_get(struct kernfs_node *kn) { }
494static inline void kernfs_put(struct kernfs_node *kn) { }
ccf73cf3 495
0c23b225
TH
496static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry)
497{ return NULL; }
498
499static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb)
500{ return NULL; }
501
fb02915f
TH
502static inline struct inode *
503kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn)
504{ return NULL; }
505
80b9bbef 506static inline struct kernfs_root *
d35258ef
TH
507kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags,
508 void *priv)
ba7443bc
TH
509{ return ERR_PTR(-ENOSYS); }
510
511static inline void kernfs_destroy_root(struct kernfs_root *root) { }
512
324a56e1 513static inline struct kernfs_node *
bb8b9d09 514kernfs_create_dir_ns(struct kernfs_node *parent, const char *name,
488dee96
DT
515 umode_t mode, kuid_t uid, kgid_t gid,
516 void *priv, const void *ns)
93b2b8e4
TH
517{ return ERR_PTR(-ENOSYS); }
518
324a56e1 519static inline struct kernfs_node *
2063d608 520__kernfs_create_file(struct kernfs_node *parent, const char *name,
488dee96
DT
521 umode_t mode, kuid_t uid, kgid_t gid,
522 loff_t size, const struct kernfs_ops *ops,
dfeb0750 523 void *priv, const void *ns, struct lock_class_key *key)
496f7394
TH
524{ return ERR_PTR(-ENOSYS); }
525
324a56e1
TH
526static inline struct kernfs_node *
527kernfs_create_link(struct kernfs_node *parent, const char *name,
528 struct kernfs_node *target)
5d0e26bb
TH
529{ return ERR_PTR(-ENOSYS); }
530
d35258ef
TH
531static inline void kernfs_activate(struct kernfs_node *kn) { }
532
324a56e1 533static inline void kernfs_remove(struct kernfs_node *kn) { }
879f40d1 534
6b0afc2a
TH
535static inline bool kernfs_remove_self(struct kernfs_node *kn)
536{ return false; }
537
324a56e1 538static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn,
879f40d1
TH
539 const char *name, const void *ns)
540{ return -ENOSYS; }
541
324a56e1
TH
542static inline int kernfs_rename_ns(struct kernfs_node *kn,
543 struct kernfs_node *new_parent,
890ece16
TH
544 const char *new_name, const void *new_ns)
545{ return -ENOSYS; }
546
324a56e1 547static inline int kernfs_setattr(struct kernfs_node *kn,
5d60418e
TH
548 const struct iattr *iattr)
549{ return -ENOSYS; }
550
324a56e1 551static inline void kernfs_notify(struct kernfs_node *kn) { }
024f6471 552
1537ad15
OM
553static inline int kernfs_xattr_get(struct kernfs_node *kn, const char *name,
554 void *value, size_t size)
b230d5ab
OM
555{ return -ENOSYS; }
556
1537ad15
OM
557static inline int kernfs_xattr_set(struct kernfs_node *kn, const char *name,
558 const void *value, size_t size, int flags)
b230d5ab
OM
559{ return -ENOSYS; }
560
4b93dc9b
TH
561static inline const void *kernfs_super_ns(struct super_block *sb)
562{ return NULL; }
563
23bf1b6b
DH
564static inline int kernfs_get_tree(struct fs_context *fc)
565{ return -ENOSYS; }
566
567static inline void kernfs_free_fs_context(struct fs_context *fc) { }
4b93dc9b
TH
568
569static inline void kernfs_kill_sb(struct super_block *sb) { }
570
571static inline void kernfs_init(void) { }
572
ba341d55 573#endif /* CONFIG_KERNFS */
879f40d1 574
3abb1d90
TH
575/**
576 * kernfs_path - build full path of a given node
577 * @kn: kernfs_node of interest
578 * @buf: buffer to copy @kn's name into
579 * @buflen: size of @buf
580 *
8f5be0ec
KK
581 * If @kn is NULL result will be "(null)".
582 *
583 * Returns the length of the full path. If the full length is equal to or
584 * greater than @buflen, @buf contains the truncated path with the trailing
585 * '\0'. On error, -errno is returned.
3abb1d90
TH
586 */
587static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen)
588{
589 return kernfs_path_from_node(kn, NULL, buf, buflen);
590}
591
324a56e1
TH
592static inline struct kernfs_node *
593kernfs_find_and_get(struct kernfs_node *kn, const char *name)
ccf73cf3 594{
324a56e1 595 return kernfs_find_and_get_ns(kn, name, NULL);
ccf73cf3
TH
596}
597
bd96f76a
TH
598static inline struct kernfs_node *
599kernfs_walk_and_get(struct kernfs_node *kn, const char *path)
600{
601 return kernfs_walk_and_get_ns(kn, path, NULL);
602}
603
324a56e1 604static inline struct kernfs_node *
bb8b9d09
TH
605kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode,
606 void *priv)
93b2b8e4 607{
488dee96
DT
608 return kernfs_create_dir_ns(parent, name, mode,
609 GLOBAL_ROOT_UID, GLOBAL_ROOT_GID,
610 priv, NULL);
93b2b8e4
TH
611}
612
324a56e1 613static inline int kernfs_remove_by_name(struct kernfs_node *parent,
879f40d1
TH
614 const char *name)
615{
616 return kernfs_remove_by_name_ns(parent, name, NULL);
617}
618
0c23b225
TH
619static inline int kernfs_rename(struct kernfs_node *kn,
620 struct kernfs_node *new_parent,
621 const char *new_name)
622{
623 return kernfs_rename_ns(kn, new_parent, new_name, NULL);
624}
625
b8441ed2 626#endif /* __LINUX_KERNFS_H */