Commit | Line | Data |
---|---|---|
55716d26 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
ae6621b0 TH |
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> | |
ae6621b0 TH |
8 | */ |
9 | ||
10 | #ifndef __KERNFS_INTERNAL_H | |
11 | #define __KERNFS_INTERNAL_H | |
12 | ||
13 | #include <linux/lockdep.h> | |
14 | #include <linux/fs.h> | |
fd7b9f7b | 15 | #include <linux/mutex.h> |
7ba0273b | 16 | #include <linux/rwsem.h> |
2322392b | 17 | #include <linux/xattr.h> |
ae6621b0 TH |
18 | |
19 | #include <linux/kernfs.h> | |
23bf1b6b | 20 | #include <linux/fs_context.h> |
ae6621b0 | 21 | |
c525aadd | 22 | struct kernfs_iattrs { |
05895219 OM |
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; | |
2322392b TH |
28 | |
29 | struct simple_xattrs xattrs; | |
0c47383b DX |
30 | atomic_t nr_user_xattrs; |
31 | atomic_t user_xattr_size; | |
ae6621b0 TH |
32 | }; |
33 | ||
f2eb478f GKH |
34 | struct kernfs_root { |
35 | /* published fields */ | |
36 | struct kernfs_node *kn; | |
37 | unsigned int flags; /* KERNFS_ROOT_* flags */ | |
38 | ||
39 | /* private fields, do not use outside kernfs proper */ | |
40 | struct idr ino_idr; | |
41 | u32 last_id_lowbits; | |
42 | u32 id_highbits; | |
43 | struct kernfs_syscall_ops *syscall_ops; | |
44 | ||
45 | /* list of kernfs_super_info of this root, protected by kernfs_rwsem */ | |
46 | struct list_head supers; | |
47 | ||
48 | wait_queue_head_t deactivate_waitq; | |
49 | struct rw_semaphore kernfs_rwsem; | |
9caf6961 | 50 | struct rw_semaphore kernfs_iattr_rwsem; |
c9f2dfb7 | 51 | struct rw_semaphore kernfs_supers_rwsem; |
f2eb478f GKH |
52 | }; |
53 | ||
81c173cb TH |
54 | /* +1 to avoid triggering overflow warning when negating it */ |
55 | #define KN_DEACTIVATED_BIAS (INT_MIN + 1) | |
ae6621b0 | 56 | |
df23fc39 | 57 | /* KERNFS_TYPE_MASK and types are defined in include/linux/kernfs.h */ |
ae6621b0 | 58 | |
ba7443bc | 59 | /** |
324a56e1 TH |
60 | * kernfs_root - find out the kernfs_root a kernfs_node belongs to |
61 | * @kn: kernfs_node of interest | |
ba7443bc | 62 | * |
24b3e3dd | 63 | * Return: the kernfs_root @kn belongs to. |
ba7443bc | 64 | */ |
324a56e1 | 65 | static inline struct kernfs_root *kernfs_root(struct kernfs_node *kn) |
ba7443bc TH |
66 | { |
67 | /* if parent exists, it's always a dir; otherwise, @sd is a dir */ | |
adc5e8b5 TH |
68 | if (kn->parent) |
69 | kn = kn->parent; | |
70 | return kn->dir.root; | |
ba7443bc TH |
71 | } |
72 | ||
fa736a95 TH |
73 | /* |
74 | * mount.c | |
75 | */ | |
c525aadd | 76 | struct kernfs_super_info { |
7d568a83 TH |
77 | struct super_block *sb; |
78 | ||
fa736a95 TH |
79 | /* |
80 | * The root associated with this super_block. Each super_block is | |
81 | * identified by the root and ns it's associated with. | |
82 | */ | |
83 | struct kernfs_root *root; | |
84 | ||
85 | /* | |
324a56e1 | 86 | * Each sb is associated with one namespace tag, currently the |
c525aadd TH |
87 | * network namespace of the task which mounted this kernfs |
88 | * instance. If multiple tags become necessary, make the following | |
89 | * an array and compare kernfs_node tag against every entry. | |
fa736a95 TH |
90 | */ |
91 | const void *ns; | |
7d568a83 | 92 | |
7ba0273b | 93 | /* anchored at kernfs_root->supers, protected by kernfs_rwsem */ |
7d568a83 | 94 | struct list_head node; |
fa736a95 | 95 | }; |
c525aadd | 96 | #define kernfs_info(SB) ((struct kernfs_super_info *)(SB->s_fs_info)) |
fa736a95 | 97 | |
319ba91d SL |
98 | static inline struct kernfs_node *kernfs_dentry_node(struct dentry *dentry) |
99 | { | |
100 | if (d_really_is_negative(dentry)) | |
101 | return NULL; | |
102 | return d_inode(dentry)->i_private; | |
103 | } | |
104 | ||
895adbec IK |
105 | static inline void kernfs_set_rev(struct kernfs_node *parent, |
106 | struct dentry *dentry) | |
107 | { | |
108 | dentry->d_time = parent->dir.rev; | |
109 | } | |
110 | ||
111 | static inline void kernfs_inc_rev(struct kernfs_node *parent) | |
112 | { | |
113 | parent->dir.rev++; | |
114 | } | |
115 | ||
116 | static inline bool kernfs_dir_changed(struct kernfs_node *parent, | |
117 | struct dentry *dentry) | |
118 | { | |
119 | if (parent->dir.rev != dentry->d_time) | |
120 | return true; | |
121 | return false; | |
122 | } | |
123 | ||
f41c5934 | 124 | extern const struct super_operations kernfs_sops; |
26e28d68 | 125 | extern struct kmem_cache *kernfs_node_cache, *kernfs_iattrs_cache; |
fa736a95 | 126 | |
ffed24e2 TH |
127 | /* |
128 | * inode.c | |
129 | */ | |
e72a1a8b | 130 | extern const struct xattr_handler *kernfs_xattr_handlers[]; |
c637b8ac | 131 | void kernfs_evict_inode(struct inode *inode); |
4609e1f1 | 132 | int kernfs_iop_permission(struct mnt_idmap *idmap, |
549c7297 | 133 | struct inode *inode, int mask); |
c1632a0f | 134 | int kernfs_iop_setattr(struct mnt_idmap *idmap, struct dentry *dentry, |
549c7297 | 135 | struct iattr *iattr); |
b74d24f7 | 136 | int kernfs_iop_getattr(struct mnt_idmap *idmap, |
549c7297 | 137 | const struct path *path, struct kstat *stat, |
a528d35e | 138 | u32 request_mask, unsigned int query_flags); |
c637b8ac | 139 | ssize_t kernfs_iop_listxattr(struct dentry *dentry, char *buf, size_t size); |
488dee96 | 140 | int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr); |
ffed24e2 | 141 | |
fd7b9f7b TH |
142 | /* |
143 | * dir.c | |
144 | */ | |
a797bfc3 TH |
145 | extern const struct dentry_operations kernfs_dops; |
146 | extern const struct file_operations kernfs_dir_fops; | |
147 | extern const struct inode_operations kernfs_dir_iops; | |
fd7b9f7b | 148 | |
c637b8ac TH |
149 | struct kernfs_node *kernfs_get_active(struct kernfs_node *kn); |
150 | void kernfs_put_active(struct kernfs_node *kn); | |
988cd7af | 151 | int kernfs_add_one(struct kernfs_node *kn); |
db4aad20 TH |
152 | struct kernfs_node *kernfs_new_node(struct kernfs_node *parent, |
153 | const char *name, umode_t mode, | |
488dee96 | 154 | kuid_t uid, kgid_t gid, |
db4aad20 | 155 | unsigned flags); |
fd7b9f7b | 156 | |
414985ae TH |
157 | /* |
158 | * file.c | |
159 | */ | |
a797bfc3 | 160 | extern const struct file_operations kernfs_file_fops; |
414985ae | 161 | |
bdb2fd7f | 162 | bool kernfs_should_drain_open_files(struct kernfs_node *kn); |
0e67db2f | 163 | void kernfs_drain_open_files(struct kernfs_node *kn); |
414985ae | 164 | |
2072f1af TH |
165 | /* |
166 | * symlink.c | |
167 | */ | |
a797bfc3 | 168 | extern const struct inode_operations kernfs_symlink_iops; |
2072f1af | 169 | |
1d25b84e IK |
170 | /* |
171 | * kernfs locks | |
172 | */ | |
173 | extern struct kernfs_global_locks *kernfs_locks; | |
ae6621b0 | 174 | #endif /* __KERNFS_INTERNAL_H */ |