Thomas Gleixner | 55716d2 | 2019-06-01 10:08:42 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 2 | /* |
| 3 | * kernfs.h - pseudo filesystem decoupled from vfs locking |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef __LINUX_KERNFS_H |
| 7 | #define __LINUX_KERNFS_H |
| 8 | |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 9 | #include <linux/kernel.h> |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 10 | #include <linux/err.h> |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 11 | #include <linux/list.h> |
| 12 | #include <linux/mutex.h> |
Tejun Heo | bc75555 | 2013-11-28 14:54:41 -0500 | [diff] [blame] | 13 | #include <linux/idr.h> |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 14 | #include <linux/lockdep.h> |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 15 | #include <linux/rbtree.h> |
| 16 | #include <linux/atomic.h> |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 17 | #include <linux/uidgid.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; |
Johannes Weiner | 147e1a9 | 2019-03-05 15:45:45 -0800 | [diff] [blame] | 27 | struct poll_table_struct; |
David Howells | 23bf1b6 | 2018-11-01 23:07:26 +0000 | [diff] [blame] | 28 | struct fs_context; |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 29 | |
David Howells | 23bf1b6 | 2018-11-01 23:07:26 +0000 | [diff] [blame] | 30 | struct kernfs_fs_context; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 31 | struct kernfs_open_node; |
| 32 | struct kernfs_iattrs; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 33 | |
| 34 | enum kernfs_node_type { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 35 | KERNFS_DIR = 0x0001, |
| 36 | KERNFS_FILE = 0x0002, |
| 37 | KERNFS_LINK = 0x0004, |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 38 | }; |
| 39 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 40 | #define KERNFS_TYPE_MASK 0x000f |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 41 | #define KERNFS_FLAG_MASK ~KERNFS_TYPE_MASK |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 42 | |
| 43 | enum kernfs_node_flag { |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 44 | KERNFS_ACTIVATED = 0x0010, |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 45 | KERNFS_NS = 0x0020, |
| 46 | KERNFS_HAS_SEQ_SHOW = 0x0040, |
| 47 | KERNFS_HAS_MMAP = 0x0080, |
| 48 | KERNFS_LOCKDEP = 0x0100, |
Tejun Heo | 6b0afc2 | 2014-02-03 14:03:01 -0500 | [diff] [blame] | 49 | KERNFS_SUICIDAL = 0x0400, |
| 50 | KERNFS_SUICIDED = 0x0800, |
Eric W. Biederman | ea01521 | 2015-05-13 16:09:29 -0500 | [diff] [blame] | 51 | KERNFS_EMPTY_DIR = 0x1000, |
Tejun Heo | 0e67db2 | 2016-12-27 14:49:03 -0500 | [diff] [blame] | 52 | KERNFS_HAS_RELEASE = 0x2000, |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 53 | }; |
| 54 | |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 55 | /* @flags for kernfs_create_root() */ |
| 56 | enum kernfs_root_flag { |
Tejun Heo | 555724a | 2014-05-12 13:56:27 -0400 | [diff] [blame] | 57 | /* |
| 58 | * kernfs_nodes are created in the deactivated state and invisible. |
| 59 | * They require explicit kernfs_activate() to become visible. This |
| 60 | * can be used to make related nodes become visible atomically |
| 61 | * after all nodes are created successfully. |
| 62 | */ |
| 63 | KERNFS_ROOT_CREATE_DEACTIVATED = 0x0001, |
| 64 | |
| 65 | /* |
Christina Quast | 0d1a393 | 2019-04-02 16:01:46 +0200 | [diff] [blame] | 66 | * For regular files, if the opener has CAP_DAC_OVERRIDE, open(2) |
Tejun Heo | 555724a | 2014-05-12 13:56:27 -0400 | [diff] [blame] | 67 | * succeeds regardless of the RW permissions. sysfs had an extra |
| 68 | * layer of enforcement where open(2) fails with -EACCES regardless |
| 69 | * of CAP_DAC_OVERRIDE if the permission doesn't have the |
| 70 | * respective read or write access at all (none of S_IRUGO or |
| 71 | * S_IWUGO) or the respective operation isn't implemented. The |
| 72 | * following flag enables that behavior. |
| 73 | */ |
| 74 | KERNFS_ROOT_EXTRA_OPEN_PERM_CHECK = 0x0002, |
Shaohua Li | aa81882 | 2017-07-12 11:49:51 -0700 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * The filesystem supports exportfs operation, so userspace can use |
| 78 | * fhandle to access nodes of the fs. |
| 79 | */ |
| 80 | KERNFS_ROOT_SUPPORT_EXPORTOP = 0x0004, |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 81 | }; |
| 82 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 83 | /* type-specific structures for kernfs_node union members */ |
| 84 | struct kernfs_elem_dir { |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 85 | unsigned long subdirs; |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 86 | /* children rbtree starts here and goes through kn->rb */ |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 87 | struct rb_root children; |
| 88 | |
| 89 | /* |
| 90 | * The kernfs hierarchy this directory belongs to. This fits |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 91 | * better directly in kernfs_node but is here to save space. |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 92 | */ |
| 93 | struct kernfs_root *root; |
| 94 | }; |
| 95 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 96 | struct kernfs_elem_symlink { |
| 97 | struct kernfs_node *target_kn; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 98 | }; |
| 99 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 100 | struct kernfs_elem_attr { |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 101 | const struct kernfs_ops *ops; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 102 | struct kernfs_open_node *open; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 103 | loff_t size; |
Tejun Heo | ecca47c | 2014-07-01 16:41:03 -0400 | [diff] [blame] | 104 | struct kernfs_node *notify_next; /* for kernfs_notify() */ |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /* |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 108 | * kernfs_node - the building block of kernfs hierarchy. Each and every |
| 109 | * kernfs node is represented by single kernfs_node. Most fields are |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 110 | * private to kernfs and shouldn't be accessed directly by kernfs users. |
| 111 | * |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 112 | * As long as s_count reference is held, the kernfs_node itself is |
| 113 | * accessible. Dereferencing elem or any other outer entity requires |
| 114 | * active reference. |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 115 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 116 | struct kernfs_node { |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 117 | atomic_t count; |
| 118 | atomic_t active; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 119 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 120 | struct lockdep_map dep_map; |
| 121 | #endif |
Tejun Heo | 3eef34a | 2014-02-07 13:32:07 -0500 | [diff] [blame] | 122 | /* |
| 123 | * Use kernfs_get_parent() and kernfs_name/path() instead of |
| 124 | * accessing the following two fields directly. If the node is |
| 125 | * never moved to a different parent, it is safe to access the |
| 126 | * parent directly. |
| 127 | */ |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 128 | struct kernfs_node *parent; |
| 129 | const char *name; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 130 | |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 131 | struct rb_node rb; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 132 | |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 133 | const void *ns; /* namespace tag */ |
Greg Kroah-Hartman | 9b0925a | 2014-01-13 14:09:38 -0800 | [diff] [blame] | 134 | unsigned int hash; /* ns + name hash */ |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 135 | union { |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 136 | struct kernfs_elem_dir dir; |
| 137 | struct kernfs_elem_symlink symlink; |
| 138 | struct kernfs_elem_attr attr; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | void *priv; |
| 142 | |
Tejun Heo | 67c0496 | 2019-11-04 15:54:30 -0800 | [diff] [blame] | 143 | /* |
| 144 | * 64bit unique ID. Lower 32bits carry the inode number and lower |
| 145 | * generation. |
| 146 | */ |
| 147 | u64 id; |
| 148 | |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 149 | unsigned short flags; |
| 150 | umode_t mode; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 151 | struct kernfs_iattrs *iattr; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 152 | }; |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 153 | |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 154 | /* |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame] | 155 | * kernfs_syscall_ops may be specified on kernfs_create_root() to support |
| 156 | * syscalls. These optional callbacks are invoked on the matching syscalls |
| 157 | * and can perform any kernfs operations which don't necessarily have to be |
| 158 | * the exact operation requested. An active reference is held for each |
| 159 | * kernfs_node parameter. |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 160 | */ |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame] | 161 | struct kernfs_syscall_ops { |
Tejun Heo | 6a7fed4 | 2014-02-03 14:09:10 -0500 | [diff] [blame] | 162 | int (*show_options)(struct seq_file *sf, struct kernfs_root *root); |
| 163 | |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 164 | int (*mkdir)(struct kernfs_node *parent, const char *name, |
| 165 | umode_t mode); |
| 166 | int (*rmdir)(struct kernfs_node *kn); |
| 167 | int (*rename)(struct kernfs_node *kn, struct kernfs_node *new_parent, |
| 168 | const char *new_name); |
Serge E. Hallyn | 4f41fc5 | 2016-05-09 09:59:55 -0500 | [diff] [blame] | 169 | int (*show_path)(struct seq_file *sf, struct kernfs_node *kn, |
| 170 | struct kernfs_root *root); |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 171 | }; |
| 172 | |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 173 | struct kernfs_root { |
| 174 | /* published fields */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 175 | struct kernfs_node *kn; |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 176 | unsigned int flags; /* KERNFS_ROOT_* flags */ |
Tejun Heo | bc75555 | 2013-11-28 14:54:41 -0500 | [diff] [blame] | 177 | |
| 178 | /* private fields, do not use outside kernfs proper */ |
Shaohua Li | 7d35079 | 2017-07-12 11:49:46 -0700 | [diff] [blame] | 179 | struct idr ino_idr; |
Tejun Heo | e23f568 | 2019-11-04 15:54:29 -0800 | [diff] [blame] | 180 | u32 last_ino; |
Shaohua Li | 4a3ef68 | 2017-07-12 11:49:47 -0700 | [diff] [blame] | 181 | u32 next_generation; |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame] | 182 | struct kernfs_syscall_ops *syscall_ops; |
Tejun Heo | 7d568a8 | 2014-04-09 11:07:30 -0400 | [diff] [blame] | 183 | |
| 184 | /* list of kernfs_super_info of this root, protected by kernfs_mutex */ |
| 185 | struct list_head supers; |
| 186 | |
Tejun Heo | abd54f0 | 2014-02-03 14:02:55 -0500 | [diff] [blame] | 187 | wait_queue_head_t deactivate_waitq; |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 188 | }; |
| 189 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 190 | struct kernfs_open_file { |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 191 | /* published fields */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 192 | struct kernfs_node *kn; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 193 | struct file *file; |
Tejun Heo | 0e67db2 | 2016-12-27 14:49:03 -0500 | [diff] [blame] | 194 | struct seq_file *seq_file; |
Tejun Heo | 2536390 | 2014-02-03 14:09:14 -0500 | [diff] [blame] | 195 | void *priv; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 196 | |
| 197 | /* private fields, do not use outside kernfs proper */ |
| 198 | struct mutex mutex; |
Chris Wilson | e4234a1 | 2016-03-31 11:45:06 +0100 | [diff] [blame] | 199 | struct mutex prealloc_mutex; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 200 | int event; |
| 201 | struct list_head list; |
NeilBrown | 2b75869 | 2014-10-13 16:41:28 +1100 | [diff] [blame] | 202 | char *prealloc_buf; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 203 | |
Tejun Heo | b7ce40c | 2014-03-04 15:38:46 -0500 | [diff] [blame] | 204 | size_t atomic_write_len; |
Tejun Heo | a1d82af | 2016-12-27 14:49:02 -0500 | [diff] [blame] | 205 | bool mmapped:1; |
Tejun Heo | 0e67db2 | 2016-12-27 14:49:03 -0500 | [diff] [blame] | 206 | bool released:1; |
Tejun Heo | dd8a5b0 | 2013-11-28 14:54:20 -0500 | [diff] [blame] | 207 | const struct vm_operations_struct *vm_ops; |
| 208 | }; |
| 209 | |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 210 | struct kernfs_ops { |
| 211 | /* |
Tejun Heo | 0e67db2 | 2016-12-27 14:49:03 -0500 | [diff] [blame] | 212 | * Optional open/release methods. Both are called with |
| 213 | * @of->seq_file populated. |
| 214 | */ |
| 215 | int (*open)(struct kernfs_open_file *of); |
| 216 | void (*release)(struct kernfs_open_file *of); |
| 217 | |
| 218 | /* |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 219 | * Read is handled by either seq_file or raw_read(). |
| 220 | * |
Tejun Heo | d19b984 | 2013-11-28 14:54:26 -0500 | [diff] [blame] | 221 | * If seq_show() is present, seq_file path is active. Other seq |
| 222 | * operations are optional and if not implemented, the behavior is |
| 223 | * equivalent to single_open(). @sf->private points to the |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 224 | * associated kernfs_open_file. |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 225 | * |
| 226 | * read() is bounced through kernel buffer and a read larger than |
| 227 | * PAGE_SIZE results in partial operation of PAGE_SIZE. |
| 228 | */ |
| 229 | int (*seq_show)(struct seq_file *sf, void *v); |
| 230 | |
Tejun Heo | d19b984 | 2013-11-28 14:54:26 -0500 | [diff] [blame] | 231 | void *(*seq_start)(struct seq_file *sf, loff_t *ppos); |
| 232 | void *(*seq_next)(struct seq_file *sf, void *v, loff_t *ppos); |
| 233 | void (*seq_stop)(struct seq_file *sf, void *v); |
| 234 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 235 | 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] | 236 | loff_t off); |
| 237 | |
| 238 | /* |
Tejun Heo | 4d3773c | 2014-02-03 14:09:13 -0500 | [diff] [blame] | 239 | * write() is bounced through kernel buffer. If atomic_write_len |
| 240 | * is not set, a write larger than PAGE_SIZE results in partial |
| 241 | * operations of PAGE_SIZE chunks. If atomic_write_len is set, |
| 242 | * writes upto the specified size are executed atomically but |
| 243 | * larger ones are rejected with -E2BIG. |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 244 | */ |
Tejun Heo | 4d3773c | 2014-02-03 14:09:13 -0500 | [diff] [blame] | 245 | size_t atomic_write_len; |
NeilBrown | 2b75869 | 2014-10-13 16:41:28 +1100 | [diff] [blame] | 246 | /* |
| 247 | * "prealloc" causes a buffer to be allocated at open for |
| 248 | * all read/write requests. As ->seq_show uses seq_read() |
| 249 | * which does its own allocation, it is incompatible with |
| 250 | * ->prealloc. Provide ->read and ->write with ->prealloc. |
| 251 | */ |
| 252 | bool prealloc; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 253 | 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] | 254 | loff_t off); |
| 255 | |
Johannes Weiner | 147e1a9 | 2019-03-05 15:45:45 -0800 | [diff] [blame] | 256 | __poll_t (*poll)(struct kernfs_open_file *of, |
| 257 | struct poll_table_struct *pt); |
| 258 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 259 | int (*mmap)(struct kernfs_open_file *of, struct vm_area_struct *vma); |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 260 | |
| 261 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 262 | struct lock_class_key lockdep_key; |
| 263 | #endif |
Tejun Heo | f6acf8b | 2013-11-28 14:54:21 -0500 | [diff] [blame] | 264 | }; |
| 265 | |
David Howells | 23bf1b6 | 2018-11-01 23:07:26 +0000 | [diff] [blame] | 266 | /* |
| 267 | * The kernfs superblock creation/mount parameter context. |
| 268 | */ |
| 269 | struct kernfs_fs_context { |
| 270 | struct kernfs_root *root; /* Root of the hierarchy being mounted */ |
| 271 | void *ns_tag; /* Namespace tag of the mount (or NULL) */ |
| 272 | unsigned long magic; /* File system specific magic number */ |
| 273 | |
| 274 | /* The following are set/used by kernfs_mount() */ |
| 275 | bool new_sb_created; /* Set to T if we allocated a new sb */ |
| 276 | }; |
| 277 | |
Tejun Heo | ba341d5 | 2014-02-03 14:09:17 -0500 | [diff] [blame] | 278 | #ifdef CONFIG_KERNFS |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 279 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 280 | static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 281 | { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 282 | return kn->flags & KERNFS_TYPE_MASK; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 283 | } |
| 284 | |
Tejun Heo | 67c0496 | 2019-11-04 15:54:30 -0800 | [diff] [blame] | 285 | static inline ino_t kernfs_id_ino(u64 id) |
| 286 | { |
| 287 | return (u32)id; |
| 288 | } |
| 289 | |
| 290 | static inline u32 kernfs_id_gen(u64 id) |
| 291 | { |
| 292 | return id >> 32; |
| 293 | } |
| 294 | |
| 295 | static inline ino_t kernfs_ino(struct kernfs_node *kn) |
| 296 | { |
| 297 | return kernfs_id_ino(kn->id); |
| 298 | } |
| 299 | |
| 300 | static inline ino_t kernfs_gen(struct kernfs_node *kn) |
| 301 | { |
| 302 | return kernfs_id_gen(kn->id); |
| 303 | } |
| 304 | |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 305 | /** |
| 306 | * kernfs_enable_ns - enable namespace under a directory |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 307 | * @kn: directory of interest, should be empty |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 308 | * |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 309 | * This is to be called right after @kn is created to enable namespace |
| 310 | * 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] | 311 | * only the ones which match the super_block's tag will be visible. |
| 312 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 313 | static inline void kernfs_enable_ns(struct kernfs_node *kn) |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 314 | { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 315 | WARN_ON_ONCE(kernfs_type(kn) != KERNFS_DIR); |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 316 | WARN_ON_ONCE(!RB_EMPTY_ROOT(&kn->dir.children)); |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 317 | kn->flags |= KERNFS_NS; |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 318 | } |
| 319 | |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 320 | /** |
| 321 | * kernfs_ns_enabled - test whether namespace is enabled |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 322 | * @kn: the node to test |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 323 | * |
| 324 | * Test whether namespace filtering is enabled for the children of @ns. |
| 325 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 326 | static inline bool kernfs_ns_enabled(struct kernfs_node *kn) |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 327 | { |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 328 | return kn->flags & KERNFS_NS; |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 329 | } |
| 330 | |
Tejun Heo | 3eef34a | 2014-02-07 13:32:07 -0500 | [diff] [blame] | 331 | int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen); |
Aditya Kali | 9f6df57 | 2016-01-29 02:54:04 -0600 | [diff] [blame] | 332 | int kernfs_path_from_node(struct kernfs_node *root_kn, struct kernfs_node *kn, |
| 333 | char *buf, size_t buflen); |
Tejun Heo | 3eef34a | 2014-02-07 13:32:07 -0500 | [diff] [blame] | 334 | void pr_cont_kernfs_name(struct kernfs_node *kn); |
| 335 | void pr_cont_kernfs_path(struct kernfs_node *kn); |
| 336 | struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 337 | struct kernfs_node *kernfs_find_and_get_ns(struct kernfs_node *parent, |
| 338 | const char *name, const void *ns); |
Tejun Heo | bd96f76 | 2015-11-20 15:55:52 -0500 | [diff] [blame] | 339 | struct kernfs_node *kernfs_walk_and_get_ns(struct kernfs_node *parent, |
| 340 | const char *path, const void *ns); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 341 | void kernfs_get(struct kernfs_node *kn); |
| 342 | void kernfs_put(struct kernfs_node *kn); |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 343 | |
Tejun Heo | 0c23b22 | 2014-02-03 14:09:15 -0500 | [diff] [blame] | 344 | struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry); |
| 345 | struct kernfs_root *kernfs_root_from_sb(struct super_block *sb); |
Tejun Heo | fb02915 | 2015-06-18 16:54:28 -0400 | [diff] [blame] | 346 | struct inode *kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn); |
Tejun Heo | 0c23b22 | 2014-02-03 14:09:15 -0500 | [diff] [blame] | 347 | |
Aditya Kali | fb3c831 | 2016-01-29 02:54:08 -0600 | [diff] [blame] | 348 | struct dentry *kernfs_node_dentry(struct kernfs_node *kn, |
| 349 | struct super_block *sb); |
Tejun Heo | 90c07c8 | 2014-02-03 14:09:09 -0500 | [diff] [blame] | 350 | struct kernfs_root *kernfs_create_root(struct kernfs_syscall_ops *scops, |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 351 | unsigned int flags, void *priv); |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 352 | void kernfs_destroy_root(struct kernfs_root *root); |
| 353 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 354 | struct kernfs_node *kernfs_create_dir_ns(struct kernfs_node *parent, |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 355 | const char *name, umode_t mode, |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 356 | kuid_t uid, kgid_t gid, |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 357 | void *priv, const void *ns); |
Eric W. Biederman | ea01521 | 2015-05-13 16:09:29 -0500 | [diff] [blame] | 358 | struct kernfs_node *kernfs_create_empty_dir(struct kernfs_node *parent, |
| 359 | const char *name); |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 360 | struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent, |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 361 | const char *name, umode_t mode, |
| 362 | kuid_t uid, kgid_t gid, |
| 363 | loff_t size, |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 364 | const struct kernfs_ops *ops, |
| 365 | void *priv, const void *ns, |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 366 | struct lock_class_key *key); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 367 | struct kernfs_node *kernfs_create_link(struct kernfs_node *parent, |
| 368 | const char *name, |
| 369 | struct kernfs_node *target); |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 370 | void kernfs_activate(struct kernfs_node *kn); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 371 | void kernfs_remove(struct kernfs_node *kn); |
Tejun Heo | 6b0afc2 | 2014-02-03 14:03:01 -0500 | [diff] [blame] | 372 | void kernfs_break_active_protection(struct kernfs_node *kn); |
| 373 | void kernfs_unbreak_active_protection(struct kernfs_node *kn); |
| 374 | bool kernfs_remove_self(struct kernfs_node *kn); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 375 | 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] | 376 | const void *ns); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 377 | 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] | 378 | const char *new_name, const void *new_ns); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 379 | int kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); |
Johannes Weiner | 147e1a9 | 2019-03-05 15:45:45 -0800 | [diff] [blame] | 380 | __poll_t kernfs_generic_poll(struct kernfs_open_file *of, |
| 381 | struct poll_table_struct *pt); |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 382 | void kernfs_notify(struct kernfs_node *kn); |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 383 | |
Ondrej Mosnacek | 1537ad1 | 2019-04-03 09:29:41 +0200 | [diff] [blame] | 384 | int kernfs_xattr_get(struct kernfs_node *kn, const char *name, |
| 385 | void *value, size_t size); |
| 386 | int kernfs_xattr_set(struct kernfs_node *kn, const char *name, |
| 387 | const void *value, size_t size, int flags); |
Ondrej Mosnacek | b230d5a | 2019-02-22 15:57:16 +0100 | [diff] [blame] | 388 | |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 389 | const void *kernfs_super_ns(struct super_block *sb); |
David Howells | 23bf1b6 | 2018-11-01 23:07:26 +0000 | [diff] [blame] | 390 | int kernfs_get_tree(struct fs_context *fc); |
| 391 | void kernfs_free_fs_context(struct fs_context *fc); |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 392 | void kernfs_kill_sb(struct super_block *sb); |
| 393 | |
| 394 | void kernfs_init(void); |
| 395 | |
Tejun Heo | fe0f726 | 2019-11-04 15:54:30 -0800 | [diff] [blame^] | 396 | struct kernfs_node *kernfs_find_and_get_node_by_id(struct kernfs_root *root, |
| 397 | u64 id); |
Tejun Heo | ba341d5 | 2014-02-03 14:09:17 -0500 | [diff] [blame] | 398 | #else /* CONFIG_KERNFS */ |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 399 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 400 | static inline enum kernfs_node_type kernfs_type(struct kernfs_node *kn) |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 401 | { return 0; } /* whatever */ |
| 402 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 403 | static inline void kernfs_enable_ns(struct kernfs_node *kn) { } |
Tejun Heo | cf9e5a7 | 2013-11-29 17:18:32 -0500 | [diff] [blame] | 404 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 405 | static inline bool kernfs_ns_enabled(struct kernfs_node *kn) |
Tejun Heo | ac9bba0 | 2013-11-29 17:19:09 -0500 | [diff] [blame] | 406 | { return false; } |
| 407 | |
Tejun Heo | 3eef34a | 2014-02-07 13:32:07 -0500 | [diff] [blame] | 408 | static inline int kernfs_name(struct kernfs_node *kn, char *buf, size_t buflen) |
| 409 | { return -ENOSYS; } |
| 410 | |
Tejun Heo | 0e0b2af | 2016-08-10 11:23:43 -0400 | [diff] [blame] | 411 | static inline int kernfs_path_from_node(struct kernfs_node *root_kn, |
| 412 | struct kernfs_node *kn, |
| 413 | char *buf, size_t buflen) |
| 414 | { return -ENOSYS; } |
| 415 | |
Tejun Heo | 3eef34a | 2014-02-07 13:32:07 -0500 | [diff] [blame] | 416 | static inline void pr_cont_kernfs_name(struct kernfs_node *kn) { } |
| 417 | static inline void pr_cont_kernfs_path(struct kernfs_node *kn) { } |
| 418 | |
| 419 | static inline struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn) |
| 420 | { return NULL; } |
| 421 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 422 | static inline struct kernfs_node * |
| 423 | kernfs_find_and_get_ns(struct kernfs_node *parent, const char *name, |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 424 | const void *ns) |
| 425 | { return NULL; } |
Tejun Heo | bd96f76 | 2015-11-20 15:55:52 -0500 | [diff] [blame] | 426 | static inline struct kernfs_node * |
| 427 | kernfs_walk_and_get_ns(struct kernfs_node *parent, const char *path, |
| 428 | const void *ns) |
| 429 | { return NULL; } |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 430 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 431 | static inline void kernfs_get(struct kernfs_node *kn) { } |
| 432 | static inline void kernfs_put(struct kernfs_node *kn) { } |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 433 | |
Tejun Heo | 0c23b22 | 2014-02-03 14:09:15 -0500 | [diff] [blame] | 434 | static inline struct kernfs_node *kernfs_node_from_dentry(struct dentry *dentry) |
| 435 | { return NULL; } |
| 436 | |
| 437 | static inline struct kernfs_root *kernfs_root_from_sb(struct super_block *sb) |
| 438 | { return NULL; } |
| 439 | |
Tejun Heo | fb02915 | 2015-06-18 16:54:28 -0400 | [diff] [blame] | 440 | static inline struct inode * |
| 441 | kernfs_get_inode(struct super_block *sb, struct kernfs_node *kn) |
| 442 | { return NULL; } |
| 443 | |
Tejun Heo | 80b9bbe | 2013-12-11 16:03:00 -0500 | [diff] [blame] | 444 | static inline struct kernfs_root * |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 445 | kernfs_create_root(struct kernfs_syscall_ops *scops, unsigned int flags, |
| 446 | void *priv) |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 447 | { return ERR_PTR(-ENOSYS); } |
| 448 | |
| 449 | static inline void kernfs_destroy_root(struct kernfs_root *root) { } |
| 450 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 451 | static inline struct kernfs_node * |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 452 | kernfs_create_dir_ns(struct kernfs_node *parent, const char *name, |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 453 | umode_t mode, kuid_t uid, kgid_t gid, |
| 454 | void *priv, const void *ns) |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 455 | { return ERR_PTR(-ENOSYS); } |
| 456 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 457 | static inline struct kernfs_node * |
Tejun Heo | 2063d60 | 2013-12-11 16:02:57 -0500 | [diff] [blame] | 458 | __kernfs_create_file(struct kernfs_node *parent, const char *name, |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 459 | umode_t mode, kuid_t uid, kgid_t gid, |
| 460 | loff_t size, const struct kernfs_ops *ops, |
Tejun Heo | dfeb0750 | 2015-02-13 14:36:31 -0800 | [diff] [blame] | 461 | void *priv, const void *ns, struct lock_class_key *key) |
Tejun Heo | 496f739 | 2013-11-28 14:54:24 -0500 | [diff] [blame] | 462 | { return ERR_PTR(-ENOSYS); } |
| 463 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 464 | static inline struct kernfs_node * |
| 465 | kernfs_create_link(struct kernfs_node *parent, const char *name, |
| 466 | struct kernfs_node *target) |
Tejun Heo | 5d0e26b | 2013-11-23 17:21:50 -0500 | [diff] [blame] | 467 | { return ERR_PTR(-ENOSYS); } |
| 468 | |
Tejun Heo | d35258e | 2014-02-03 14:09:12 -0500 | [diff] [blame] | 469 | static inline void kernfs_activate(struct kernfs_node *kn) { } |
| 470 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 471 | static inline void kernfs_remove(struct kernfs_node *kn) { } |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 472 | |
Tejun Heo | 6b0afc2 | 2014-02-03 14:03:01 -0500 | [diff] [blame] | 473 | static inline bool kernfs_remove_self(struct kernfs_node *kn) |
| 474 | { return false; } |
| 475 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 476 | static inline int kernfs_remove_by_name_ns(struct kernfs_node *kn, |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 477 | const char *name, const void *ns) |
| 478 | { return -ENOSYS; } |
| 479 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 480 | static inline int kernfs_rename_ns(struct kernfs_node *kn, |
| 481 | struct kernfs_node *new_parent, |
Tejun Heo | 890ece1 | 2013-11-23 17:21:51 -0500 | [diff] [blame] | 482 | const char *new_name, const void *new_ns) |
| 483 | { return -ENOSYS; } |
| 484 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 485 | static inline int kernfs_setattr(struct kernfs_node *kn, |
Tejun Heo | 5d60418 | 2013-11-23 17:21:52 -0500 | [diff] [blame] | 486 | const struct iattr *iattr) |
| 487 | { return -ENOSYS; } |
| 488 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 489 | static inline void kernfs_notify(struct kernfs_node *kn) { } |
Tejun Heo | 024f647 | 2013-11-28 14:54:27 -0500 | [diff] [blame] | 490 | |
Ondrej Mosnacek | 1537ad1 | 2019-04-03 09:29:41 +0200 | [diff] [blame] | 491 | static inline int kernfs_xattr_get(struct kernfs_node *kn, const char *name, |
| 492 | void *value, size_t size) |
Ondrej Mosnacek | b230d5a | 2019-02-22 15:57:16 +0100 | [diff] [blame] | 493 | { return -ENOSYS; } |
| 494 | |
Ondrej Mosnacek | 1537ad1 | 2019-04-03 09:29:41 +0200 | [diff] [blame] | 495 | static inline int kernfs_xattr_set(struct kernfs_node *kn, const char *name, |
| 496 | const void *value, size_t size, int flags) |
Ondrej Mosnacek | b230d5a | 2019-02-22 15:57:16 +0100 | [diff] [blame] | 497 | { return -ENOSYS; } |
| 498 | |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 499 | static inline const void *kernfs_super_ns(struct super_block *sb) |
| 500 | { return NULL; } |
| 501 | |
David Howells | 23bf1b6 | 2018-11-01 23:07:26 +0000 | [diff] [blame] | 502 | static inline int kernfs_get_tree(struct fs_context *fc) |
| 503 | { return -ENOSYS; } |
| 504 | |
| 505 | static inline void kernfs_free_fs_context(struct fs_context *fc) { } |
Tejun Heo | 4b93dc9 | 2013-11-28 14:54:43 -0500 | [diff] [blame] | 506 | |
| 507 | static inline void kernfs_kill_sb(struct super_block *sb) { } |
| 508 | |
| 509 | static inline void kernfs_init(void) { } |
| 510 | |
Tejun Heo | ba341d5 | 2014-02-03 14:09:17 -0500 | [diff] [blame] | 511 | #endif /* CONFIG_KERNFS */ |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 512 | |
Tejun Heo | 3abb1d9 | 2016-08-10 11:23:44 -0400 | [diff] [blame] | 513 | /** |
| 514 | * kernfs_path - build full path of a given node |
| 515 | * @kn: kernfs_node of interest |
| 516 | * @buf: buffer to copy @kn's name into |
| 517 | * @buflen: size of @buf |
| 518 | * |
Konstantin Khlebnikov | 8f5be0e | 2018-08-13 09:52:09 +0300 | [diff] [blame] | 519 | * If @kn is NULL result will be "(null)". |
| 520 | * |
| 521 | * Returns the length of the full path. If the full length is equal to or |
| 522 | * greater than @buflen, @buf contains the truncated path with the trailing |
| 523 | * '\0'. On error, -errno is returned. |
Tejun Heo | 3abb1d9 | 2016-08-10 11:23:44 -0400 | [diff] [blame] | 524 | */ |
| 525 | static inline int kernfs_path(struct kernfs_node *kn, char *buf, size_t buflen) |
| 526 | { |
| 527 | return kernfs_path_from_node(kn, NULL, buf, buflen); |
| 528 | } |
| 529 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 530 | static inline struct kernfs_node * |
| 531 | kernfs_find_and_get(struct kernfs_node *kn, const char *name) |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 532 | { |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 533 | return kernfs_find_and_get_ns(kn, name, NULL); |
Tejun Heo | ccf73cf | 2013-11-28 14:54:30 -0500 | [diff] [blame] | 534 | } |
| 535 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 536 | static inline struct kernfs_node * |
Tejun Heo | bd96f76 | 2015-11-20 15:55:52 -0500 | [diff] [blame] | 537 | kernfs_walk_and_get(struct kernfs_node *kn, const char *path) |
| 538 | { |
| 539 | return kernfs_walk_and_get_ns(kn, path, NULL); |
| 540 | } |
| 541 | |
| 542 | static inline struct kernfs_node * |
Tejun Heo | bb8b9d0 | 2013-12-11 16:02:55 -0500 | [diff] [blame] | 543 | kernfs_create_dir(struct kernfs_node *parent, const char *name, umode_t mode, |
| 544 | void *priv) |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 545 | { |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 546 | return kernfs_create_dir_ns(parent, name, mode, |
| 547 | GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, |
| 548 | priv, NULL); |
Tejun Heo | 93b2b8e | 2013-11-28 14:54:15 -0500 | [diff] [blame] | 549 | } |
| 550 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 551 | static inline struct kernfs_node * |
| 552 | kernfs_create_file_ns(struct kernfs_node *parent, const char *name, |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 553 | umode_t mode, kuid_t uid, kgid_t gid, |
| 554 | loff_t size, const struct kernfs_ops *ops, |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 555 | void *priv, const void *ns) |
| 556 | { |
| 557 | struct lock_class_key *key = NULL; |
| 558 | |
| 559 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 560 | key = (struct lock_class_key *)&ops->lockdep_key; |
| 561 | #endif |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 562 | return __kernfs_create_file(parent, name, mode, uid, gid, |
| 563 | size, ops, priv, ns, key); |
Tejun Heo | 517e64f | 2013-11-28 14:54:29 -0500 | [diff] [blame] | 564 | } |
| 565 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 566 | static inline struct kernfs_node * |
| 567 | 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] | 568 | loff_t size, const struct kernfs_ops *ops, void *priv) |
| 569 | { |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 570 | return kernfs_create_file_ns(parent, name, mode, |
| 571 | GLOBAL_ROOT_UID, GLOBAL_ROOT_GID, |
| 572 | size, ops, priv, NULL); |
Tejun Heo | 496f739 | 2013-11-28 14:54:24 -0500 | [diff] [blame] | 573 | } |
| 574 | |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 575 | static inline int kernfs_remove_by_name(struct kernfs_node *parent, |
Tejun Heo | 879f40d | 2013-11-23 17:21:49 -0500 | [diff] [blame] | 576 | const char *name) |
| 577 | { |
| 578 | return kernfs_remove_by_name_ns(parent, name, NULL); |
| 579 | } |
| 580 | |
Tejun Heo | 0c23b22 | 2014-02-03 14:09:15 -0500 | [diff] [blame] | 581 | static inline int kernfs_rename(struct kernfs_node *kn, |
| 582 | struct kernfs_node *new_parent, |
| 583 | const char *new_name) |
| 584 | { |
| 585 | return kernfs_rename_ns(kn, new_parent, new_name, NULL); |
| 586 | } |
| 587 | |
Tejun Heo | b8441ed | 2013-11-24 09:54:58 -0500 | [diff] [blame] | 588 | #endif /* __LINUX_KERNFS_H */ |