Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * kernfs.h - pseudo filesystem decoupled from vfs locking |
| 3 | * |
| 4 | * This file is released under the GPLv2. |
| 5 | */ |
| 6 | |
| 7 | #ifndef __LINUX_KERNFS_H |
| 8 | #define __LINUX_KERNFS_H |
| 9 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 10 | #include <linux/kernel.h> |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 11 | #include <linux/err.h> |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 12 | #include <linux/list.h> |
| 13 | #include <linux/mutex.h> |
Tejun Heo | bc75555 | 2013-11-28 14:54:41 -0500 | [diff] [blame] | 14 | #include <linux/idr.h> |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 15 | #include <linux/lockdep.h> |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 16 | #include <linux/rbtree.h> |
| 17 | #include <linux/atomic.h> |
Tejun Heo | abd54f0 | 2014-02-03 14:02:55 -0500 | [diff] [blame] | 18 | #include <linux/wait.h> |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 19 | |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 20 | struct file; |
Tejun Heo | 917f56c | 2014-01-17 09:57:49 -0500 | [diff] [blame] | 21 | struct dentry; |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 22 | struct iattr; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 23 | struct seq_file; |
| 24 | struct vm_area_struct; |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 25 | struct super_block; |
| 26 | struct file_system_type; |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 27 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 28 | struct kernfs_open_node; |
| 29 | struct kernfs_iattrs; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 30 | |
| 31 | enum kernfs_node_type { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 32 | KERNFS_DIR = 0x0001, |
| 33 | KERNFS_FILE = 0x0002, |
| 34 | KERNFS_LINK = 0x0004, |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 35 | }; |
| 36 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 37 | #define KERNFS_TYPE_MASK 0x000f |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 38 | #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 39 | |
| 40 | enum kernfs_node_flag { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 41 | KERNFS_NS = 0x0020, |
| 42 | KERNFS_HAS_SEQ_SHOW = 0x0040, |
| 43 | KERNFS_HAS_MMAP = 0x0080, |
| 44 | KERNFS_LOCKDEP = 0x0100, |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 45 | KERNFS_STATIC_NAME = 0x0200, |
Tejun Heo | 6b0afc2 | 2014-02-03 14:03:01 -0500 | [diff] [blame] | 46 | KERNFS_SUICIDAL = 0x0400, |
| 47 | KERNFS_SUICIDED = 0x0800, |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 48 | }; |
| 49 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 50 | /* type-specific structures for kernfs_node union members */ |
| 51 | struct kernfs_elem_dir { |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 52 | unsigned long subdirs; |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 53 | /* children rbtree starts here and goes through kn->rb */ |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 54 | struct rb_root children; |
| 55 | |
| 56 | /* |
| 57 | * The kernfs hierarchy this directory belongs to. This fits |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 58 | * better directly in kernfs_node but is here to save space. |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 59 | */ |
| 60 | struct kernfs_root *root; |
| 61 | }; |
| 62 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 63 | struct kernfs_elem_symlink { |
| 64 | struct kernfs_node *target_kn; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 65 | }; |
| 66 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 67 | struct kernfs_elem_attr { |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 68 | const struct kernfs_ops *ops; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 69 | struct kernfs_open_node *open; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 70 | loff_t size; |
| 71 | }; |
| 72 | |
| 73 | /* |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 74 | * kernfs_node - the building block of kernfs hierarchy. Each and every |
| 75 | * kernfs node is represented by single kernfs_node. Most fields are |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 76 | * private to kernfs and shouldn't be accessed directly by kernfs users. |
| 77 | * |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 78 | * As long as s_count reference is held, the kernfs_node itself is |
| 79 | * accessible. Dereferencing elem or any other outer entity requires |
| 80 | * active reference. |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 81 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 82 | struct kernfs_node { |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 83 | atomic_t count; |
| 84 | atomic_t active; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 85 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 86 | struct lockdep_map dep_map; |
| 87 | #endif |
| 88 | /* the following two fields are published */ |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 89 | struct kernfs_node *parent; |
| 90 | const char *name; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 91 | |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 92 | struct rb_node rb; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 93 | |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 94 | const void *ns; /* namespace tag */ |
Greg Kroah-Hartman | 9b0925a | 2014-01-13 14:09:38 -0800 | [diff] [blame] | 95 | unsigned int hash; /* ns + name hash */ |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 96 | union { |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 97 | struct kernfs_elem_dir dir; |
| 98 | struct kernfs_elem_symlink symlink; |
| 99 | struct kernfs_elem_attr attr; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | void *priv; |
| 103 | |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 104 | unsigned short flags; |
| 105 | umode_t mode; |
| 106 | unsigned int ino; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 107 | struct kernfs_iattrs *iattr; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 108 | }; |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 109 | |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 110 | /* |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame^] | 111 | * kernfs_syscall_ops may be specified on kernfs_create_root() to support |
| 112 | * syscalls. These optional callbacks are invoked on the matching syscalls |
| 113 | * and can perform any kernfs operations which don't necessarily have to be |
| 114 | * the exact operation requested. An active reference is held for each |
| 115 | * kernfs_node parameter. |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 116 | */ |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame^] | 117 | struct kernfs_syscall_ops { |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 118 | int (*mkdir)(struct kernfs_node *parent, const char *name, |
| 119 | umode_t mode); |
| 120 | int (*rmdir)(struct kernfs_node *kn); |
| 121 | int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent, |
| 122 | const char *new_name); |
| 123 | }; |
| 124 | |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 125 | struct kernfs_root { |
| 126 | /* published fields */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 127 | struct kernfs_node *kn; |
Tejun Heo | bc75555 | 2013-11-28 14:54:41 -0500 | [diff] [blame] | 128 | |
| 129 | /* private fields, do not use outside kernfs proper */ |
| 130 | struct ida ino_ida; |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame^] | 131 | struct kernfs_syscall_ops *syscall_ops; |
Tejun Heo | abd54f0 | 2014-02-03 14:02:55 -0500 | [diff] [blame] | 132 | wait_queue_head_t deactivate_waitq; |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 133 | }; |
| 134 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 135 | struct kernfs_open_file { |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 136 | /* published fields */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 137 | struct kernfs_node *kn; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 138 | struct file *file; |
| 139 | |
| 140 | /* private fields, do not use outside kernfs proper */ |
| 141 | struct mutex mutex; |
| 142 | int event; |
| 143 | struct list_head list; |
| 144 | |
| 145 | bool mmapped; |
| 146 | const struct vm_operations_struct *vm_ops; |
| 147 | }; |
| 148 | |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 149 | struct kernfs_ops { |
| 150 | /* |
| 151 | * Read is handled by either seq_file or raw_read(). |
| 152 | * |
Tejun Heo | d19b984 | 2013-11-28 14:54:26 -0500 | [diff] [blame] | 153 | * If seq_show() is present, seq_file path is active. Other seq |
| 154 | * operations are optional and if not implemented, the behavior is |
| 155 | * equivalent to single_open(). @sf->private points to the |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 156 | * associated kernfs_open_file. |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 157 | * |
| 158 | * read() is bounced through kernel buffer and a read larger than |
| 159 | * PAGE_SIZE results in partial operation of PAGE_SIZE. |
| 160 | */ |
| 161 | int (*seq_show)(struct seq_file *sf, void *v); |
| 162 | |
Tejun Heo | d19b984 | 2013-11-28 14:54:26 -0500 | [diff] [blame] | 163 | void *(*seq_start)(struct seq_file *sf, loff_t *ppos); |
| 164 | void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos); |
| 165 | void (*seq_stop)(struct seq_file *sf, void *v); |
| 166 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 167 | ssize_t (*read)(struct kernfs_open_file *of, char *buf, size_t bytes, |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 168 | loff_t off); |
| 169 | |
| 170 | /* |
| 171 | * write() is bounced through kernel buffer and a write larger than |
| 172 | * PAGE_SIZE results in partial operation of PAGE_SIZE. |
| 173 | */ |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 174 | ssize_t (*write)(struct kernfs_open_file *of, char *buf, size_t bytes, |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 175 | loff_t off); |
| 176 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 177 | int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma); |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 178 | |
| 179 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 180 | struct lock_class_key lockdep_key; |
| 181 | #endif |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 182 | }; |
| 183 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 184 | #ifdef CONFIG_SYSFS |
| 185 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 186 | static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 187 | { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 188 | return kn->flags & KERNFS_TYPE_MASK; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | /** |
| 192 | * kernfs_enable_ns - enable namespace under a directory |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 193 | * @kn: directory of interest, should be empty |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 194 | * |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 195 | * This is to be called right after @kn is created to enable namespace |
| 196 | * under it. All children of @kn must have non-NULL namespace tags and |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 197 | * only the ones which match the super_block's tag will be visible. |
| 198 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 199 | static inline void kernfs_enable_ns(struct kernfs_node *kn) |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 200 | { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 201 | WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR); |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 202 | WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children)); |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 203 | kn->flags |= KERNFS_NS; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 204 | } |
| 205 | |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 206 | /** |
| 207 | * kernfs_ns_enabled - test whether namespace is enabled |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 208 | * @kn: the node to test |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 209 | * |
| 210 | * Test whether namespace filtering is enabled for the children of @ns. |
| 211 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 212 | static inline bool kernfs_ns_enabled(struct kernfs_node *kn) |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 213 | { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 214 | return kn->flags & KERNFS_NS; |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 215 | } |
| 216 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 217 | struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, |
| 218 | const char *name, const void *ns); |
| 219 | void kernfs_get(struct kernfs_node *kn); |
| 220 | void kernfs_put(struct kernfs_node *kn); |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 221 | |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame^] | 222 | struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 223 | void *priv); |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 224 | void kernfs_destroy_root(struct kernfs_root *root); |
| 225 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 226 | struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 227 | const char *name, umode_t mode, |
| 228 | void *priv, const void *ns); |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 229 | struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent, |
| 230 | const char *name, |
| 231 | umode_t mode, loff_t size, |
| 232 | const struct kernfs_ops *ops, |
| 233 | void *priv, const void *ns, |
| 234 | bool name_is_static, |
| 235 | struct lock_class_key *key); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 236 | struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, |
| 237 | const char *name, |
| 238 | struct kernfs_node *target); |
| 239 | void kernfs_remove(struct kernfs_node *kn); |
Tejun Heo | 6b0afc2 | 2014-02-03 14:03:01 -0500 | [diff] [blame] | 240 | void kernfs_break_active_protection(struct kernfs_node *kn); |
| 241 | void kernfs_unbreak_active_protection(struct kernfs_node *kn); |
| 242 | bool kernfs_remove_self(struct kernfs_node *kn); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 243 | int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 244 | const void *ns); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 245 | int kernfs_rename_ns(struct kernfs_node *kn, struct kernfs_node *new_parent, |
Tejun Heo | 890ece1 | 2013-11-23 17:21:51 -0500 | [diff] [blame] | 246 | const char *new_name, const void *new_ns); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 247 | int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); |
| 248 | void kernfs_notify(struct kernfs_node *kn); |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 249 | |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 250 | const void *kernfs_super_ns(struct super_block *sb); |
| 251 | struct dentry *kernfs_mount_ns(struct file_system_type *fs_type, int flags, |
| 252 | struct kernfs_root *root, const void *ns); |
| 253 | void kernfs_kill_sb(struct super_block *sb); |
| 254 | |
| 255 | void kernfs_init(void); |
| 256 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 257 | #else /* CONFIG_SYSFS */ |
| 258 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 259 | static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 260 | { return 0; } /* whatever */ |
| 261 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 262 | static inline void kernfs_enable_ns(struct kernfs_node *kn) { } |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 263 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 264 | static inline bool kernfs_ns_enabled(struct kernfs_node *kn) |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 265 | { return false; } |
| 266 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 267 | static inline struct kernfs_node * |
| 268 | kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 269 | const void *ns) |
| 270 | { return NULL; } |
| 271 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 272 | static inline void kernfs_get(struct kernfs_node *kn) { } |
| 273 | static inline void kernfs_put(struct kernfs_node *kn) { } |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 274 | |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 275 | static inline struct kernfs_root * |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame^] | 276 | kernfs_create_root(struct kernfs_syscall_ops *scops, void *priv) |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 277 | { return ERR_PTR(-ENOSYS); } |
| 278 | |
| 279 | static inline void kernfs_destroy_root(struct kernfs_root *root) { } |
| 280 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 281 | static inline struct kernfs_node * |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 282 | kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, |
| 283 | umode_t mode, void *priv, const void *ns) |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 284 | { return ERR_PTR(-ENOSYS); } |
| 285 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 286 | static inline struct kernfs_node * |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 287 | __kernfs_create_file(struct kernfs_node *parent, const char *name, |
| 288 | umode_t mode, loff_t size, const struct kernfs_ops *ops, |
| 289 | void *priv, const void *ns, bool name_is_static, |
| 290 | struct lock_class_key *key) |
Tejun Heo | 496f739 | 2013-11-28 14:54:24 -0500 | [diff] [blame] | 291 | { return ERR_PTR(-ENOSYS); } |
| 292 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 293 | static inline struct kernfs_node * |
| 294 | kernfs_create_link(struct kernfs_node *parent, const char *name, |
| 295 | struct kernfs_node *target) |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 296 | { return ERR_PTR(-ENOSYS); } |
| 297 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 298 | static inline void kernfs_remove(struct kernfs_node *kn) { } |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 299 | |
Tejun Heo | 6b0afc2 | 2014-02-03 14:03:01 -0500 | [diff] [blame] | 300 | static inline bool kernfs_remove_self(struct kernfs_node *kn) |
| 301 | { return false; } |
| 302 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 303 | static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn, |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 304 | const char *name, const void *ns) |
| 305 | { return -ENOSYS; } |
| 306 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 307 | static inline int kernfs_rename_ns(struct kernfs_node *kn, |
| 308 | struct kernfs_node *new_parent, |
Tejun Heo | 890ece1 | 2013-11-23 17:21:51 -0500 | [diff] [blame] | 309 | const char *new_name, const void *new_ns) |
| 310 | { return -ENOSYS; } |
| 311 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 312 | static inline int kernfs_setattr(struct kernfs_node *kn, |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 313 | const struct iattr *iattr) |
| 314 | { return -ENOSYS; } |
| 315 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 316 | static inline void kernfs_notify(struct kernfs_node *kn) { } |
Tejun Heo | 024f647 | 2013-11-28 14:54:27 -0500 | [diff] [blame] | 317 | |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 318 | static inline const void *kernfs_super_ns(struct super_block *sb) |
| 319 | { return NULL; } |
| 320 | |
| 321 | static inline struct dentry * |
| 322 | kernfs_mount_ns(struct file_system_type *fs_type, int flags, |
| 323 | struct kernfs_root *root, const void *ns) |
| 324 | { return ERR_PTR(-ENOSYS); } |
| 325 | |
| 326 | static inline void kernfs_kill_sb(struct super_block *sb) { } |
| 327 | |
| 328 | static inline void kernfs_init(void) { } |
| 329 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 330 | #endif /* CONFIG_SYSFS */ |
| 331 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 332 | static inline struct kernfs_node * |
| 333 | kernfs_find_and_get(struct kernfs_node *kn, const char *name) |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 334 | { |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 335 | return kernfs_find_and_get_ns(kn, name, NULL); |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 336 | } |
| 337 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 338 | static inline struct kernfs_node * |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 339 | kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode, |
| 340 | void *priv) |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 341 | { |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 342 | return kernfs_create_dir_ns(parent, name, mode, priv, NULL); |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 343 | } |
| 344 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 345 | static inline struct kernfs_node * |
| 346 | kernfs_create_file_ns(struct kernfs_node *parent, const char *name, |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 347 | umode_t mode, loff_t size, const struct kernfs_ops *ops, |
| 348 | void *priv, const void *ns) |
| 349 | { |
| 350 | struct lock_class_key *key = NULL; |
| 351 | |
| 352 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 353 | key = (struct lock_class_key *)&ops->lockdep_key; |
| 354 | #endif |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 355 | return __kernfs_create_file(parent, name, mode, size, ops, priv, ns, |
| 356 | false, key); |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 357 | } |
| 358 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 359 | static inline struct kernfs_node * |
| 360 | kernfs_create_file(struct kernfs_node *parent, const char *name, umode_t mode, |
Tejun Heo | 496f739 | 2013-11-28 14:54:24 -0500 | [diff] [blame] | 361 | loff_t size, const struct kernfs_ops *ops, void *priv) |
| 362 | { |
| 363 | return kernfs_create_file_ns(parent, name, mode, size, ops, priv, NULL); |
| 364 | } |
| 365 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 366 | static inline int kernfs_remove_by_name(struct kernfs_node *parent, |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 367 | const char *name) |
| 368 | { |
| 369 | return kernfs_remove_by_name_ns(parent, name, NULL); |
| 370 | } |
| 371 | |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 372 | static inline struct dentry * |
| 373 | kernfs_mount(struct file_system_type *fs_type, int flags, |
| 374 | struct kernfs_root *root) |
| 375 | { |
| 376 | return kernfs_mount_ns(fs_type, flags, root, NULL); |
| 377 | } |
| 378 | |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 379 | #endif /* __LINUX_KERNFS_H */ |