Thomas Gleixner | 55716d2 | 2019-06-01 10:08:42 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 2 | /* |
| 3 | * fs/kernfs/kernfs-internal.h - kernfs internal header file |
| 4 | * |
| 5 | * Copyright (c) 2001-3 Patrick Mochel |
| 6 | * Copyright (c) 2007 SUSE Linux Products GmbH |
| 7 | * Copyright (c) 2007, 2013 Tejun Heo <teheo@suse.de> |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #ifndef __KERNFS_INTERNAL_H |
| 11 | #define __KERNFS_INTERNAL_H |
| 12 | |
| 13 | #include <linux/lockdep.h> |
| 14 | #include <linux/fs.h> |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 15 | #include <linux/mutex.h> |
Ian Kent | 7ba0273 | 2021-07-16 17:28:29 +0800 | [diff] [blame] | 16 | #include <linux/rwsem.h> |
Tejun Heo | 2322392 | 2013-11-23 17:40:02 -0500 | [diff] [blame] | 17 | #include <linux/xattr.h> |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 18 | |
| 19 | #include <linux/kernfs.h> |
David Howells | 23bf1b6 | 2018-11-01 23:07:26 +0000 | [diff] [blame] | 20 | #include <linux/fs_context.h> |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 21 | |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 22 | struct kernfs_iattrs { |
Ondrej Mosnacek | 0589521 | 2019-02-22 15:57:12 +0100 | [diff] [blame] | 23 | kuid_t ia_uid; |
| 24 | kgid_t ia_gid; |
| 25 | struct timespec64 ia_atime; |
| 26 | struct timespec64 ia_mtime; |
| 27 | struct timespec64 ia_ctime; |
Tejun Heo | 2322392 | 2013-11-23 17:40:02 -0500 | [diff] [blame] | 28 | |
| 29 | struct simple_xattrs xattrs; |
Daniel Xu | 0c47383 | 2020-03-12 13:03:16 -0700 | [diff] [blame] | 30 | atomic_t nr_user_xattrs; |
| 31 | atomic_t user_xattr_size; |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 32 | }; |
| 33 | |
Tejun Heo | 81c173c | 2014-02-03 14:03:00 -0500 | [diff] [blame] | 34 | /* +1 to avoid triggering overflow warning when negating it */ |
| 35 | #define KN_DEACTIVATED_BIAS (INT_MIN + 1) |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 36 | |
Tejun Heo | df23fc3 | 2013-12-11 14:11:56 -0500 | [diff] [blame] | 37 | /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 38 | |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 39 | /** |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 40 | * kernfs_root - find out the kernfs_root a kernfs_node belongs to |
| 41 | * @kn: kernfs_node of interest |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 42 | * |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 43 | * Return the kernfs_root @kn belongs to. |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 44 | */ |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 45 | static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn) |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 46 | { |
| 47 | /* if parent exists, it's always a dir; otherwise, @sd is a dir */ |
Tejun Heo | adc5e8b | 2013-12-11 14:11:54 -0500 | [diff] [blame] | 48 | if (kn->parent) |
| 49 | kn = kn->parent; |
| 50 | return kn->dir.root; |
Tejun Heo | ba7443b | 2013-11-28 14:54:40 -0500 | [diff] [blame] | 51 | } |
| 52 | |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 53 | /* |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame] | 54 | * mount.c |
| 55 | */ |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 56 | struct kernfs_super_info { |
Tejun Heo | 7d568a8 | 2014-04-09 11:07:30 -0400 | [diff] [blame] | 57 | struct super_block *sb; |
| 58 | |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame] | 59 | /* |
| 60 | * The root associated with this super_block. Each super_block is |
| 61 | * identified by the root and ns it's associated with. |
| 62 | */ |
| 63 | struct kernfs_root *root; |
| 64 | |
| 65 | /* |
Tejun Heo | 324a56e | 2013-12-11 14:11:53 -0500 | [diff] [blame] | 66 | * Each sb is associated with one namespace tag, currently the |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 67 | * network namespace of the task which mounted this kernfs |
| 68 | * instance. If multiple tags become necessary, make the following |
| 69 | * an array and compare kernfs_node tag against every entry. |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame] | 70 | */ |
| 71 | const void *ns; |
Tejun Heo | 7d568a8 | 2014-04-09 11:07:30 -0400 | [diff] [blame] | 72 | |
Ian Kent | 7ba0273 | 2021-07-16 17:28:29 +0800 | [diff] [blame] | 73 | /* anchored at kernfs_root->supers, protected by kernfs_rwsem */ |
Tejun Heo | 7d568a8 | 2014-04-09 11:07:30 -0400 | [diff] [blame] | 74 | struct list_head node; |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame] | 75 | }; |
Tejun Heo | c525aad | 2013-12-11 14:11:55 -0500 | [diff] [blame] | 76 | #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info)) |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame] | 77 | |
Shaohua Li | 319ba91 | 2017-07-12 11:49:49 -0700 | [diff] [blame] | 78 | static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry) |
| 79 | { |
| 80 | if (d_really_is_negative(dentry)) |
| 81 | return NULL; |
| 82 | return d_inode(dentry)->i_private; |
| 83 | } |
| 84 | |
Ian Kent | 895adbe | 2021-07-16 17:28:18 +0800 | [diff] [blame] | 85 | static inline void kernfs_set_rev(struct kernfs_node *parent, |
| 86 | struct dentry *dentry) |
| 87 | { |
| 88 | dentry->d_time = parent->dir.rev; |
| 89 | } |
| 90 | |
| 91 | static inline void kernfs_inc_rev(struct kernfs_node *parent) |
| 92 | { |
| 93 | parent->dir.rev++; |
| 94 | } |
| 95 | |
| 96 | static inline bool kernfs_dir_changed(struct kernfs_node *parent, |
| 97 | struct dentry *dentry) |
| 98 | { |
| 99 | if (parent->dir.rev != dentry->d_time) |
| 100 | return true; |
| 101 | return false; |
| 102 | } |
| 103 | |
Li Zefan | f41c593 | 2014-02-14 16:57:27 +0800 | [diff] [blame] | 104 | extern const struct super_operations kernfs_sops; |
Ayush Mittal | 26e28d6 | 2019-02-06 10:25:42 +0530 | [diff] [blame] | 105 | extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache; |
Tejun Heo | fa736a9 | 2013-11-28 14:54:44 -0500 | [diff] [blame] | 106 | |
| 107 | /* |
Tejun Heo | ffed24e | 2013-11-28 14:54:32 -0500 | [diff] [blame] | 108 | * inode.c |
| 109 | */ |
Andreas Gruenbacher | e72a1a8 | 2016-09-29 17:48:33 +0200 | [diff] [blame] | 110 | extern const struct xattr_handler *kernfs_xattr_handlers[]; |
Tejun Heo | c637b8a | 2013-12-11 14:11:58 -0500 | [diff] [blame] | 111 | void kernfs_evict_inode(struct inode *inode); |
Christian Brauner | 549c729 | 2021-01-21 14:19:43 +0100 | [diff] [blame] | 112 | int kernfs_iop_permission(struct user_namespace *mnt_userns, |
| 113 | struct inode *inode, int mask); |
| 114 | int kernfs_iop_setattr(struct user_namespace *mnt_userns, struct dentry *dentry, |
| 115 | struct iattr *iattr); |
| 116 | int kernfs_iop_getattr(struct user_namespace *mnt_userns, |
| 117 | const struct path *path, struct kstat *stat, |
David Howells | a528d35 | 2017-01-31 16:46:22 +0000 | [diff] [blame] | 118 | u32 request_mask, unsigned int query_flags); |
Tejun Heo | c637b8a | 2013-12-11 14:11:58 -0500 | [diff] [blame] | 119 | ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size); |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 120 | int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); |
Tejun Heo | ffed24e | 2013-11-28 14:54:32 -0500 | [diff] [blame] | 121 | |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 122 | /* |
| 123 | * dir.c |
| 124 | */ |
Ian Kent | 7ba0273 | 2021-07-16 17:28:29 +0800 | [diff] [blame] | 125 | extern struct rw_semaphore kernfs_rwsem; |
Tejun Heo | a797bfc | 2013-12-11 14:11:57 -0500 | [diff] [blame] | 126 | extern const struct dentry_operations kernfs_dops; |
| 127 | extern const struct file_operations kernfs_dir_fops; |
| 128 | extern const struct inode_operations kernfs_dir_iops; |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 129 | |
Tejun Heo | c637b8a | 2013-12-11 14:11:58 -0500 | [diff] [blame] | 130 | struct kernfs_node *kernfs_get_active(struct kernfs_node *kn); |
| 131 | void kernfs_put_active(struct kernfs_node *kn); |
Tejun Heo | 988cd7a | 2014-02-03 14:02:58 -0500 | [diff] [blame] | 132 | int kernfs_add_one(struct kernfs_node *kn); |
Tejun Heo | db4aad2 | 2014-01-17 09:58:25 -0500 | [diff] [blame] | 133 | struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, |
| 134 | const char *name, umode_t mode, |
Dmitry Torokhov | 488dee9 | 2018-07-20 21:56:47 +0000 | [diff] [blame] | 135 | kuid_t uid, kgid_t gid, |
Tejun Heo | db4aad2 | 2014-01-17 09:58:25 -0500 | [diff] [blame] | 136 | unsigned flags); |
Tejun Heo | fd7b9f7 | 2013-11-28 14:54:33 -0500 | [diff] [blame] | 137 | |
Tejun Heo | 414985a | 2013-11-28 14:54:34 -0500 | [diff] [blame] | 138 | /* |
| 139 | * file.c |
| 140 | */ |
Tejun Heo | a797bfc | 2013-12-11 14:11:57 -0500 | [diff] [blame] | 141 | extern const struct file_operations kernfs_file_fops; |
Tejun Heo | 414985a | 2013-11-28 14:54:34 -0500 | [diff] [blame] | 142 | |
Tejun Heo | 0e67db2 | 2016-12-27 14:49:03 -0500 | [diff] [blame] | 143 | void kernfs_drain_open_files(struct kernfs_node *kn); |
Tejun Heo | 414985a | 2013-11-28 14:54:34 -0500 | [diff] [blame] | 144 | |
Tejun Heo | 2072f1a | 2013-11-28 14:54:35 -0500 | [diff] [blame] | 145 | /* |
| 146 | * symlink.c |
| 147 | */ |
Tejun Heo | a797bfc | 2013-12-11 14:11:57 -0500 | [diff] [blame] | 148 | extern const struct inode_operations kernfs_symlink_iops; |
Tejun Heo | 2072f1a | 2013-11-28 14:54:35 -0500 | [diff] [blame] | 149 | |
Tejun Heo | ae6621b | 2013-11-28 14:54:31 -0500 | [diff] [blame] | 150 | #endif /* __KERNFS_INTERNAL_H */ |