]>
Commit | Line | Data |
---|---|---|
2121bcd9 | 1 | SPDX-License-Identifier: GPL-2.0 |
d58c55f2 | 2 | aufs5.x-rcN kbuild patch |
7f207e10 | 3 | |
fbc438ed | 4 | diff --git a/fs/Kconfig b/fs/Kconfig |
d58c55f2 | 5 | index 7b623e9fc1b0..9070b9159188 100644 |
fbc438ed JR |
6 | --- a/fs/Kconfig |
7 | +++ b/fs/Kconfig | |
43982f53 | 8 | @@ -264,6 +264,7 @@ source "fs/pstore/Kconfig" |
5527c038 | 9 | source "fs/sysv/Kconfig" |
7e9cd9fe | 10 | source "fs/ufs/Kconfig" |
9d41a5bf | 11 | source "fs/erofs/Kconfig" |
7f207e10 AM |
12 | +source "fs/aufs/Kconfig" |
13 | ||
14 | endif # MISC_FILESYSTEMS | |
15 | ||
16 | diff --git a/fs/Makefile b/fs/Makefile | |
d58c55f2 | 17 | index 1148c555c4d3..ed6ff7ddc478 100644 |
7f207e10 AM |
18 | --- a/fs/Makefile |
19 | +++ b/fs/Makefile | |
d58c55f2 | 20 | @@ -133,3 +133,4 @@ obj-$(CONFIG_CEPH_FS) += ceph/ |
bf0370f2 | 21 | obj-$(CONFIG_PSTORE) += pstore/ |
c06a8ce3 | 22 | obj-$(CONFIG_EFIVAR_FS) += efivarfs/ |
9d41a5bf | 23 | obj-$(CONFIG_EROFS_FS) += erofs/ |
86dc4139 | 24 | +obj-$(CONFIG_AUFS_FS) += aufs/ |
2121bcd9 | 25 | SPDX-License-Identifier: GPL-2.0 |
d58c55f2 | 26 | aufs5.x-rcN base patch |
7f207e10 | 27 | |
c1595e42 | 28 | diff --git a/MAINTAINERS b/MAINTAINERS |
d58c55f2 | 29 | index cf6ccca6e61c..c3b9b0d405fd 100644 |
c1595e42 JR |
30 | --- a/MAINTAINERS |
31 | +++ b/MAINTAINERS | |
d58c55f2 | 32 | @@ -2877,6 +2877,19 @@ F: include/linux/audit.h |
c1595e42 JR |
33 | F: include/uapi/linux/audit.h |
34 | F: kernel/audit* | |
35 | ||
36 | +AUFS (advanced multi layered unification filesystem) FILESYSTEM | |
37 | +M: "J. R. Okajima" <hooanon05g@gmail.com> | |
c1595e42 | 38 | +L: aufs-users@lists.sourceforge.net (members only) |
eca801bf | 39 | +L: linux-unionfs@vger.kernel.org |
c1595e42 | 40 | +W: http://aufs.sourceforge.net |
5527c038 | 41 | +T: git://github.com/sfjro/aufs4-linux.git |
c1595e42 JR |
42 | +S: Supported |
43 | +F: Documentation/filesystems/aufs/ | |
44 | +F: Documentation/ABI/testing/debugfs-aufs | |
45 | +F: Documentation/ABI/testing/sysfs-aufs | |
46 | +F: fs/aufs/ | |
47 | +F: include/uapi/linux/aufs_type.h | |
48 | + | |
49 | AUXILIARY DISPLAY DRIVERS | |
50 | M: Miguel Ojeda Sandonis <miguel.ojeda.sandonis@gmail.com> | |
cd7a4cd9 | 51 | S: Maintained |
392086de | 52 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c |
d58c55f2 | 53 | index 739b372a5112..872e3b3a7693 100644 |
392086de AM |
54 | --- a/drivers/block/loop.c |
55 | +++ b/drivers/block/loop.c | |
d58c55f2 | 56 | @@ -750,6 +750,24 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
cd7a4cd9 | 57 | return error; |
392086de AM |
58 | } |
59 | ||
60 | +/* | |
61 | + * for AUFS | |
62 | + * no get/put for file. | |
63 | + */ | |
64 | +struct file *loop_backing_file(struct super_block *sb) | |
65 | +{ | |
66 | + struct file *ret; | |
67 | + struct loop_device *l; | |
68 | + | |
69 | + ret = NULL; | |
70 | + if (MAJOR(sb->s_dev) == LOOP_MAJOR) { | |
71 | + l = sb->s_bdev->bd_disk->private_data; | |
72 | + ret = l->lo_backing_file; | |
73 | + } | |
74 | + return ret; | |
75 | +} | |
febd17d6 | 76 | +EXPORT_SYMBOL_GPL(loop_backing_file); |
392086de AM |
77 | + |
78 | /* loop sysfs attributes */ | |
79 | ||
80 | static ssize_t loop_attr_show(struct device *dev, char *page, | |
c1595e42 | 81 | diff --git a/fs/dcache.c b/fs/dcache.c |
d58c55f2 | 82 | index b280e07e162b..046000653e4d 100644 |
c1595e42 JR |
83 | --- a/fs/dcache.c |
84 | +++ b/fs/dcache.c | |
d58c55f2 | 85 | @@ -1266,7 +1266,7 @@ enum d_walk_ret { |
c1595e42 | 86 | * |
cd7a4cd9 | 87 | * The @enter() callbacks are called with d_lock held. |
c1595e42 JR |
88 | */ |
89 | -static void d_walk(struct dentry *parent, void *data, | |
90 | +void d_walk(struct dentry *parent, void *data, | |
cd7a4cd9 | 91 | enum d_walk_ret (*enter)(void *, struct dentry *)) |
c1595e42 | 92 | { |
cd7a4cd9 | 93 | struct dentry *this_parent; |
febd17d6 | 94 | diff --git a/fs/fcntl.c b/fs/fcntl.c |
d58c55f2 | 95 | index 9bc167562ee8..b0935c67bd1e 100644 |
febd17d6 JR |
96 | --- a/fs/fcntl.c |
97 | +++ b/fs/fcntl.c | |
2121bcd9 | 98 | @@ -32,7 +32,7 @@ |
febd17d6 JR |
99 | |
100 | #define SETFL_MASK (O_APPEND | O_NONBLOCK | O_NDELAY | O_DIRECT | O_NOATIME) | |
101 | ||
102 | -static int setfl(int fd, struct file * filp, unsigned long arg) | |
43982f53 | 103 | +int setfl(int fd, struct file *filp, unsigned long arg) |
febd17d6 JR |
104 | { |
105 | struct inode * inode = file_inode(filp); | |
106 | int error = 0; | |
2121bcd9 | 107 | @@ -63,6 +63,8 @@ static int setfl(int fd, struct file * filp, unsigned long arg) |
febd17d6 JR |
108 | |
109 | if (filp->f_op->check_flags) | |
110 | error = filp->f_op->check_flags(arg); | |
111 | + if (!error && filp->f_op->setfl) | |
112 | + error = filp->f_op->setfl(filp, arg); | |
113 | if (error) | |
114 | return error; | |
115 | ||
5afbbe0d | 116 | diff --git a/fs/inode.c b/fs/inode.c |
d58c55f2 | 117 | index 96d62d97694e..31796c1040d6 100644 |
5afbbe0d AM |
118 | --- a/fs/inode.c |
119 | +++ b/fs/inode.c | |
d58c55f2 | 120 | @@ -1680,7 +1680,7 @@ EXPORT_SYMBOL(generic_update_time); |
5afbbe0d AM |
121 | * This does the actual work of updating an inodes time or version. Must have |
122 | * had called mnt_want_write() before calling this. | |
123 | */ | |
cd7a4cd9 AM |
124 | -static int update_time(struct inode *inode, struct timespec64 *time, int flags) |
125 | +int update_time(struct inode *inode, struct timespec64 *time, int flags) | |
5afbbe0d | 126 | { |
cd7a4cd9 | 127 | int (*update_time)(struct inode *, struct timespec64 *, int); |
5afbbe0d | 128 | |
8b6a4947 | 129 | diff --git a/fs/namespace.c b/fs/namespace.c |
d58c55f2 | 130 | index 5e1bf611a9eb..c05ac2488abb 100644 |
8b6a4947 AM |
131 | --- a/fs/namespace.c |
132 | +++ b/fs/namespace.c | |
eca34b5c | 133 | @@ -776,6 +776,12 @@ static inline int check_mnt(struct mount *mnt) |
8b6a4947 AM |
134 | return mnt->mnt_ns == current->nsproxy->mnt_ns; |
135 | } | |
136 | ||
137 | +/* for aufs, CONFIG_AUFS_BR_FUSE */ | |
138 | +int is_current_mnt_ns(struct vfsmount *mnt) | |
139 | +{ | |
140 | + return check_mnt(real_mount(mnt)); | |
141 | +} | |
142 | + | |
143 | /* | |
144 | * vfsmount lock must be held for write | |
145 | */ | |
5527c038 | 146 | diff --git a/fs/read_write.c b/fs/read_write.c |
43982f53 | 147 | index 5bbf587f5bc1..fa9b3994b34c 100644 |
5527c038 JR |
148 | --- a/fs/read_write.c |
149 | +++ b/fs/read_write.c | |
fbc438ed | 150 | @@ -498,6 +498,28 @@ static ssize_t __vfs_write(struct file *file, const char __user *p, |
8b6a4947 | 151 | return -EINVAL; |
5527c038 | 152 | } |
5527c038 JR |
153 | |
154 | +vfs_readf_t vfs_readf(struct file *file) | |
155 | +{ | |
156 | + const struct file_operations *fop = file->f_op; | |
157 | + | |
158 | + if (fop->read) | |
159 | + return fop->read; | |
160 | + if (fop->read_iter) | |
161 | + return new_sync_read; | |
43982f53 | 162 | + return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */ |
5527c038 JR |
163 | +} |
164 | + | |
165 | +vfs_writef_t vfs_writef(struct file *file) | |
166 | +{ | |
167 | + const struct file_operations *fop = file->f_op; | |
168 | + | |
169 | + if (fop->write) | |
170 | + return fop->write; | |
171 | + if (fop->write_iter) | |
172 | + return new_sync_write; | |
43982f53 | 173 | + return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */ |
5527c038 JR |
174 | +} |
175 | + | |
8b6a4947 | 176 | ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) |
5527c038 JR |
177 | { |
178 | mm_segment_t old_fs; | |
7f207e10 | 179 | diff --git a/fs/splice.c b/fs/splice.c |
d58c55f2 | 180 | index 3009652a41c8..d9bcc4a71a0a 100644 |
7f207e10 AM |
181 | --- a/fs/splice.c |
182 | +++ b/fs/splice.c | |
d58c55f2 | 183 | @@ -849,8 +849,8 @@ EXPORT_SYMBOL(generic_splice_sendpage); |
7f207e10 AM |
184 | /* |
185 | * Attempt to initiate a splice from pipe to file. | |
186 | */ | |
187 | -static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
188 | - loff_t *ppos, size_t len, unsigned int flags) | |
189 | +long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
190 | + loff_t *ppos, size_t len, unsigned int flags) | |
191 | { | |
192 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, | |
193 | loff_t *, size_t, unsigned int); | |
d58c55f2 | 194 | @@ -866,9 +866,9 @@ static long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
7f207e10 AM |
195 | /* |
196 | * Attempt to initiate a splice from a file to a pipe. | |
197 | */ | |
198 | -static long do_splice_to(struct file *in, loff_t *ppos, | |
199 | - struct pipe_inode_info *pipe, size_t len, | |
200 | - unsigned int flags) | |
201 | +long do_splice_to(struct file *in, loff_t *ppos, | |
202 | + struct pipe_inode_info *pipe, size_t len, | |
203 | + unsigned int flags) | |
204 | { | |
205 | ssize_t (*splice_read)(struct file *, loff_t *, | |
206 | struct pipe_inode_info *, size_t, unsigned int); | |
a2654f78 | 207 | diff --git a/fs/sync.c b/fs/sync.c |
fbc438ed | 208 | index 4d1ff010bc5a..457f4e4a5cc1 100644 |
a2654f78 AM |
209 | --- a/fs/sync.c |
210 | +++ b/fs/sync.c | |
2121bcd9 | 211 | @@ -28,7 +28,7 @@ |
a2654f78 AM |
212 | * wait == 1 case since in that case write_inode() functions do |
213 | * sync_dirty_buffer() and thus effectively write one block at a time. | |
214 | */ | |
215 | -static int __sync_filesystem(struct super_block *sb, int wait) | |
216 | +int __sync_filesystem(struct super_block *sb, int wait) | |
217 | { | |
218 | if (wait) | |
219 | sync_inodes_sb(sb); | |
5527c038 | 220 | diff --git a/include/linux/fs.h b/include/linux/fs.h |
d58c55f2 | 221 | index 98e0349adb52..5fc7807f7c2e 100644 |
5527c038 JR |
222 | --- a/include/linux/fs.h |
223 | +++ b/include/linux/fs.h | |
43982f53 | 224 | @@ -1349,6 +1349,7 @@ extern void fasync_free(struct fasync_struct *); |
febd17d6 JR |
225 | /* can be called from interrupts */ |
226 | extern void kill_fasync(struct fasync_struct **, int, int); | |
227 | ||
43982f53 | 228 | +extern int setfl(int fd, struct file *filp, unsigned long arg); |
febd17d6 | 229 | extern void __f_setown(struct file *filp, struct pid *, enum pid_type, int force); |
3c1bdaff | 230 | extern int f_setown(struct file *filp, unsigned long arg, int force); |
febd17d6 | 231 | extern void f_delown(struct file *filp); |
d58c55f2 | 232 | @@ -1842,6 +1843,7 @@ struct file_operations { |
febd17d6 JR |
233 | ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int); |
234 | unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); | |
235 | int (*check_flags)(int); | |
236 | + int (*setfl)(struct file *, unsigned long); | |
237 | int (*flock) (struct file *, int, struct file_lock *); | |
238 | ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int); | |
239 | ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int); | |
d58c55f2 | 240 | @@ -1912,6 +1914,12 @@ ssize_t rw_copy_check_uvector(int type, const struct iovec __user * uvector, |
5527c038 JR |
241 | struct iovec *fast_pointer, |
242 | struct iovec **ret_pointer); | |
243 | ||
244 | +typedef ssize_t (*vfs_readf_t)(struct file *, char __user *, size_t, loff_t *); | |
245 | +typedef ssize_t (*vfs_writef_t)(struct file *, const char __user *, size_t, | |
246 | + loff_t *); | |
247 | +vfs_readf_t vfs_readf(struct file *file); | |
248 | +vfs_writef_t vfs_writef(struct file *file); | |
249 | + | |
250 | extern ssize_t __vfs_read(struct file *, char __user *, size_t, loff_t *); | |
5527c038 | 251 | extern ssize_t vfs_read(struct file *, char __user *, size_t, loff_t *); |
8b6a4947 | 252 | extern ssize_t vfs_write(struct file *, const char __user *, size_t, loff_t *); |
d58c55f2 | 253 | @@ -2332,6 +2340,7 @@ extern int current_umask(void); |
5afbbe0d AM |
254 | extern void ihold(struct inode * inode); |
255 | extern void iput(struct inode *); | |
cd7a4cd9 AM |
256 | extern int generic_update_time(struct inode *, struct timespec64 *, int); |
257 | +extern int update_time(struct inode *, struct timespec64 *, int); | |
5afbbe0d AM |
258 | |
259 | /* /sys/fs */ | |
260 | extern struct kobject *fs_kobj; | |
d58c55f2 | 261 | @@ -2620,6 +2629,7 @@ static inline bool sb_is_blkdev_sb(struct super_block *sb) |
a2654f78 AM |
262 | return false; |
263 | } | |
264 | #endif | |
265 | +extern int __sync_filesystem(struct super_block *, int); | |
266 | extern int sync_filesystem(struct super_block *); | |
267 | extern const struct file_operations def_blk_fops; | |
268 | extern const struct file_operations def_chr_fops; | |
8b6a4947 | 269 | diff --git a/include/linux/lockdep.h b/include/linux/lockdep.h |
d58c55f2 | 270 | index c50d01ef1414..4f4677020360 100644 |
8b6a4947 AM |
271 | --- a/include/linux/lockdep.h |
272 | +++ b/include/linux/lockdep.h | |
43982f53 | 273 | @@ -331,6 +331,8 @@ static inline int lockdep_match_key(struct lockdep_map *lock, |
8b6a4947 AM |
274 | return lock->key == key; |
275 | } | |
276 | ||
277 | +struct lock_class *lockdep_hlock_class(struct held_lock *hlock); | |
278 | + | |
279 | /* | |
280 | * Acquire a lock. | |
281 | * | |
d58c55f2 | 282 | @@ -472,6 +474,7 @@ struct lockdep_map { }; |
8b6a4947 AM |
283 | |
284 | #define lockdep_depth(tsk) (0) | |
285 | ||
286 | +#define lockdep_is_held(lock) (1) | |
287 | #define lockdep_is_held_type(l, r) (1) | |
288 | ||
289 | #define lockdep_assert_held(l) do { (void)(l); } while (0) | |
290 | diff --git a/include/linux/mnt_namespace.h b/include/linux/mnt_namespace.h | |
ba1aed25 | 291 | index 35942084cd40..24f5fd1a789d 100644 |
8b6a4947 AM |
292 | --- a/include/linux/mnt_namespace.h |
293 | +++ b/include/linux/mnt_namespace.h | |
2121bcd9 | 294 | @@ -6,11 +6,14 @@ |
8b6a4947 AM |
295 | struct mnt_namespace; |
296 | struct fs_struct; | |
297 | struct user_namespace; | |
298 | +struct vfsmount; | |
299 | ||
300 | extern struct mnt_namespace *copy_mnt_ns(unsigned long, struct mnt_namespace *, | |
301 | struct user_namespace *, struct fs_struct *); | |
302 | extern void put_mnt_ns(struct mnt_namespace *ns); | |
303 | ||
304 | +extern int is_current_mnt_ns(struct vfsmount *mnt); | |
305 | + | |
306 | extern const struct file_operations proc_mounts_operations; | |
307 | extern const struct file_operations proc_mountinfo_operations; | |
308 | extern const struct file_operations proc_mountstats_operations; | |
1e00d052 | 309 | diff --git a/include/linux/splice.h b/include/linux/splice.h |
ba1aed25 | 310 | index 74b4911ac16d..19789fbea567 100644 |
1e00d052 AM |
311 | --- a/include/linux/splice.h |
312 | +++ b/include/linux/splice.h | |
2121bcd9 | 313 | @@ -87,4 +87,10 @@ extern void splice_shrink_spd(struct splice_pipe_desc *); |
4b3da204 AM |
314 | |
315 | extern const struct pipe_buf_operations page_cache_pipe_buf_ops; | |
106341ce | 316 | extern const struct pipe_buf_operations default_pipe_buf_ops; |
1e00d052 AM |
317 | + |
318 | +extern long do_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
319 | + loff_t *ppos, size_t len, unsigned int flags); | |
320 | +extern long do_splice_to(struct file *in, loff_t *ppos, | |
321 | + struct pipe_inode_info *pipe, size_t len, | |
322 | + unsigned int flags); | |
323 | #endif | |
8b6a4947 | 324 | diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c |
d58c55f2 | 325 | index 32406ef0d6a2..e52169c2086b 100644 |
8b6a4947 AM |
326 | --- a/kernel/locking/lockdep.c |
327 | +++ b/kernel/locking/lockdep.c | |
eca34b5c | 328 | @@ -153,7 +153,7 @@ static |
9f237c51 | 329 | struct lock_class lock_classes[MAX_LOCKDEP_KEYS]; |
eca34b5c | 330 | static DECLARE_BITMAP(lock_classes_in_use, MAX_LOCKDEP_KEYS); |
8b6a4947 AM |
331 | |
332 | -static inline struct lock_class *hlock_class(struct held_lock *hlock) | |
333 | +inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock) | |
334 | { | |
eca34b5c AM |
335 | unsigned int class_idx = hlock->class_idx; |
336 | ||
337 | @@ -174,6 +174,7 @@ static inline struct lock_class *hlock_class(struct held_lock *hlock) | |
338 | */ | |
339 | return lock_classes + class_idx; | |
8b6a4947 AM |
340 | } |
341 | +#define hlock_class(hlock) lockdep_hlock_class(hlock) | |
342 | ||
343 | #ifdef CONFIG_LOCK_STAT | |
344 | static DEFINE_PER_CPU(struct lock_class_stats[MAX_LOCKDEP_KEYS], cpu_lock_stats); | |
2121bcd9 | 345 | SPDX-License-Identifier: GPL-2.0 |
d58c55f2 | 346 | aufs5.x-rcN mmap patch |
fb47a38f | 347 | |
c1595e42 | 348 | diff --git a/fs/proc/base.c b/fs/proc/base.c |
eca34b5c | 349 | index ebea9501afb8..dc7edc5f7267 100644 |
c1595e42 JR |
350 | --- a/fs/proc/base.c |
351 | +++ b/fs/proc/base.c | |
eca34b5c AM |
352 | @@ -2037,7 +2037,7 @@ static int map_files_get_link(struct dentry *dentry, struct path *path) |
353 | rc = -ENOENT; | |
c1595e42 JR |
354 | vma = find_exact_vma(mm, vm_start, vm_end); |
355 | if (vma && vma->vm_file) { | |
356 | - *path = vma->vm_file->f_path; | |
357 | + *path = vma_pr_or_file(vma)->f_path; | |
358 | path_get(path); | |
359 | rc = 0; | |
360 | } | |
fb47a38f | 361 | diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c |
fbc438ed | 362 | index 14c2badb8fd9..65afe5287e43 100644 |
fb47a38f JR |
363 | --- a/fs/proc/nommu.c |
364 | +++ b/fs/proc/nommu.c | |
fbc438ed | 365 | @@ -41,7 +41,10 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region) |
fb47a38f JR |
366 | file = region->vm_file; |
367 | ||
368 | if (file) { | |
369 | - struct inode *inode = file_inode(region->vm_file); | |
370 | + struct inode *inode; | |
076b876e | 371 | + |
fb47a38f JR |
372 | + file = vmr_pr_or_file(region); |
373 | + inode = file_inode(file); | |
374 | dev = inode->i_sb->s_dev; | |
375 | ino = inode->i_ino; | |
376 | } | |
377 | diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c | |
43982f53 | 378 | index 9442631fd4af..1fa8a5fcdeee 100644 |
fb47a38f JR |
379 | --- a/fs/proc/task_mmu.c |
380 | +++ b/fs/proc/task_mmu.c | |
eca34b5c | 381 | @@ -309,7 +309,10 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma) |
fb47a38f JR |
382 | const char *name = NULL; |
383 | ||
384 | if (file) { | |
385 | - struct inode *inode = file_inode(vma->vm_file); | |
386 | + struct inode *inode; | |
076b876e | 387 | + |
fb47a38f JR |
388 | + file = vma_pr_or_file(vma); |
389 | + inode = file_inode(file); | |
390 | dev = inode->i_sb->s_dev; | |
391 | ino = inode->i_ino; | |
392 | pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; | |
43982f53 | 393 | @@ -1819,7 +1822,7 @@ static int show_numa_map(struct seq_file *m, void *v) |
076b876e AM |
394 | struct proc_maps_private *proc_priv = &numa_priv->proc_maps; |
395 | struct vm_area_struct *vma = v; | |
396 | struct numa_maps *md = &numa_priv->md; | |
397 | - struct file *file = vma->vm_file; | |
398 | + struct file *file = vma_pr_or_file(vma); | |
076b876e | 399 | struct mm_struct *mm = vma->vm_mm; |
43982f53 AM |
400 | struct mempolicy *pol; |
401 | char buffer[64]; | |
fb47a38f | 402 | diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c |
eca34b5c | 403 | index 7907e6419e57..d17209cf52bc 100644 |
fb47a38f JR |
404 | --- a/fs/proc/task_nommu.c |
405 | +++ b/fs/proc/task_nommu.c | |
acd2b654 | 406 | @@ -155,7 +155,10 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma) |
fb47a38f JR |
407 | file = vma->vm_file; |
408 | ||
409 | if (file) { | |
410 | - struct inode *inode = file_inode(vma->vm_file); | |
411 | + struct inode *inode; | |
076b876e | 412 | + |
b912730e | 413 | + file = vma_pr_or_file(vma); |
fb47a38f JR |
414 | + inode = file_inode(file); |
415 | dev = inode->i_sb->s_dev; | |
416 | ino = inode->i_ino; | |
417 | pgoff = (loff_t)vma->vm_pgoff << PAGE_SHIFT; | |
418 | diff --git a/include/linux/mm.h b/include/linux/mm.h | |
d58c55f2 | 419 | index cfaa8feecfe8..b66c4c536ac5 100644 |
fb47a38f JR |
420 | --- a/include/linux/mm.h |
421 | +++ b/include/linux/mm.h | |
d58c55f2 | 422 | @@ -1495,6 +1495,28 @@ static inline void unmap_shared_mapping_range(struct address_space *mapping, |
a3232e84 | 423 | unmap_mapping_range(mapping, holebegin, holelen, 0); |
fb47a38f | 424 | } |
fb47a38f | 425 | |
076b876e AM |
426 | +extern void vma_do_file_update_time(struct vm_area_struct *, const char[], int); |
427 | +extern struct file *vma_do_pr_or_file(struct vm_area_struct *, const char[], | |
f2c43d5f | 428 | + int); |
076b876e AM |
429 | +extern void vma_do_get_file(struct vm_area_struct *, const char[], int); |
430 | +extern void vma_do_fput(struct vm_area_struct *, const char[], int); | |
fb47a38f | 431 | + |
f2c43d5f AM |
432 | +#define vma_file_update_time(vma) vma_do_file_update_time(vma, __func__, \ |
433 | + __LINE__) | |
434 | +#define vma_pr_or_file(vma) vma_do_pr_or_file(vma, __func__, \ | |
435 | + __LINE__) | |
436 | +#define vma_get_file(vma) vma_do_get_file(vma, __func__, __LINE__) | |
437 | +#define vma_fput(vma) vma_do_fput(vma, __func__, __LINE__) | |
b912730e AM |
438 | + |
439 | +#ifndef CONFIG_MMU | |
076b876e AM |
440 | +extern struct file *vmr_do_pr_or_file(struct vm_region *, const char[], int); |
441 | +extern void vmr_do_fput(struct vm_region *, const char[], int); | |
442 | + | |
f2c43d5f AM |
443 | +#define vmr_pr_or_file(region) vmr_do_pr_or_file(region, __func__, \ |
444 | + __LINE__) | |
445 | +#define vmr_fput(region) vmr_do_fput(region, __func__, __LINE__) | |
b912730e | 446 | +#endif /* !CONFIG_MMU */ |
fb47a38f | 447 | + |
a3232e84 JR |
448 | extern int access_process_vm(struct task_struct *tsk, unsigned long addr, |
449 | void *buf, int len, unsigned int gup_flags); | |
fb47a38f | 450 | extern int access_remote_vm(struct mm_struct *mm, unsigned long addr, |
fb47a38f | 451 | diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h |
43982f53 | 452 | index 270aa8fd2800..33848c2165e2 100644 |
fb47a38f JR |
453 | --- a/include/linux/mm_types.h |
454 | +++ b/include/linux/mm_types.h | |
43982f53 | 455 | @@ -267,6 +267,7 @@ struct vm_region { |
fb47a38f JR |
456 | unsigned long vm_top; /* region allocated to here */ |
457 | unsigned long vm_pgoff; /* the offset in vm_file corresponding to vm_start */ | |
458 | struct file *vm_file; /* the backing file or NULL */ | |
459 | + struct file *vm_prfile; /* the virtual backing file or NULL */ | |
460 | ||
461 | int vm_usage; /* region usage count (access under nommu_region_sem) */ | |
462 | bool vm_icache_flushed : 1; /* true if the icache has been flushed for | |
43982f53 | 463 | @@ -341,6 +342,7 @@ struct vm_area_struct { |
fb47a38f | 464 | unsigned long vm_pgoff; /* Offset (within vm_file) in PAGE_SIZE |
5afbbe0d | 465 | units */ |
fb47a38f JR |
466 | struct file * vm_file; /* File we map to (can be NULL). */ |
467 | + struct file *vm_prfile; /* shadow of vm_file */ | |
468 | void * vm_private_data; /* was vm_pte (shared mem) */ | |
469 | ||
eca34b5c | 470 | #ifdef CONFIG_SWAP |
fb47a38f | 471 | diff --git a/kernel/fork.c b/kernel/fork.c |
d58c55f2 | 472 | index 080809560072..968e4dc2279f 100644 |
fb47a38f JR |
473 | --- a/kernel/fork.c |
474 | +++ b/kernel/fork.c | |
d58c55f2 | 475 | @@ -565,7 +565,7 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, |
fb47a38f JR |
476 | struct inode *inode = file_inode(file); |
477 | struct address_space *mapping = file->f_mapping; | |
478 | ||
479 | - get_file(file); | |
480 | + vma_get_file(tmp); | |
481 | if (tmp->vm_flags & VM_DENYWRITE) | |
482 | atomic_dec(&inode->i_writecount); | |
2000de60 | 483 | i_mmap_lock_write(mapping); |
076b876e | 484 | diff --git a/mm/Makefile b/mm/Makefile |
d58c55f2 | 485 | index 1937cc251883..778c1e399903 100644 |
076b876e AM |
486 | --- a/mm/Makefile |
487 | +++ b/mm/Makefile | |
43982f53 | 488 | @@ -42,7 +42,7 @@ obj-y := filemap.o mempool.o oom_kill.o fadvise.o \ |
076b876e | 489 | mm_init.o mmu_context.o percpu.o slab_common.o \ |
b00004a5 | 490 | compaction.o vmacache.o \ |
076b876e | 491 | interval_tree.o list_lru.o workingset.o \ |
eca34b5c AM |
492 | - debug.o gup.o $(mmu-y) |
493 | + prfile.o debug.o gup.o $(mmu-y) | |
076b876e | 494 | |
fbc438ed JR |
495 | # Give 'page_alloc' its own module-parameter namespace |
496 | page-alloc-y := page_alloc.o | |
fb47a38f | 497 | diff --git a/mm/filemap.c b/mm/filemap.c |
d58c55f2 | 498 | index bf6aa30be58d..32ca075c0c8b 100644 |
fb47a38f JR |
499 | --- a/mm/filemap.c |
500 | +++ b/mm/filemap.c | |
d58c55f2 | 501 | @@ -2675,7 +2675,7 @@ vm_fault_t filemap_page_mkwrite(struct vm_fault *vmf) |
cd7a4cd9 | 502 | vm_fault_t ret = VM_FAULT_LOCKED; |
fb47a38f JR |
503 | |
504 | sb_start_pagefault(inode->i_sb); | |
521ced18 JR |
505 | - file_update_time(vmf->vma->vm_file); |
506 | + vma_file_update_time(vmf->vma); | |
fb47a38f JR |
507 | lock_page(page); |
508 | if (page->mapping != inode->i_mapping) { | |
509 | unlock_page(page); | |
fb47a38f | 510 | diff --git a/mm/mmap.c b/mm/mmap.c |
d58c55f2 | 511 | index 71e4ffc83bcd..7256e8b985eb 100644 |
fb47a38f JR |
512 | --- a/mm/mmap.c |
513 | +++ b/mm/mmap.c | |
d58c55f2 | 514 | @@ -176,7 +176,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma) |
fb47a38f JR |
515 | if (vma->vm_ops && vma->vm_ops->close) |
516 | vma->vm_ops->close(vma); | |
517 | if (vma->vm_file) | |
518 | - fput(vma->vm_file); | |
519 | + vma_fput(vma); | |
520 | mpol_put(vma_policy(vma)); | |
cd7a4cd9 | 521 | vm_area_free(vma); |
fb47a38f | 522 | return next; |
d58c55f2 | 523 | @@ -909,7 +909,7 @@ int __vma_adjust(struct vm_area_struct *vma, unsigned long start, |
fb47a38f JR |
524 | if (remove_next) { |
525 | if (file) { | |
526 | uprobe_munmap(next, next->vm_start, next->vm_end); | |
527 | - fput(file); | |
528 | + vma_fput(vma); | |
529 | } | |
530 | if (next->anon_vma) | |
531 | anon_vma_merge(vma, next); | |
d58c55f2 | 532 | @@ -1837,8 +1837,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, |
35939ee7 JR |
533 | return addr; |
534 | ||
fb47a38f | 535 | unmap_and_free_vma: |
fb47a38f JR |
536 | + vma_fput(vma); |
537 | vma->vm_file = NULL; | |
538 | - fput(file); | |
539 | ||
540 | /* Undo any partial mapping done by a device driver. */ | |
541 | unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end); | |
d58c55f2 | 542 | @@ -2667,7 +2667,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
543 | goto out_free_mpol; |
544 | ||
545 | if (new->vm_file) | |
546 | - get_file(new->vm_file); | |
547 | + vma_get_file(new); | |
548 | ||
549 | if (new->vm_ops && new->vm_ops->open) | |
550 | new->vm_ops->open(new); | |
d58c55f2 | 551 | @@ -2686,7 +2686,7 @@ int __split_vma(struct mm_struct *mm, struct vm_area_struct *vma, |
fb47a38f JR |
552 | if (new->vm_ops && new->vm_ops->close) |
553 | new->vm_ops->close(new); | |
554 | if (new->vm_file) | |
555 | - fput(new->vm_file); | |
556 | + vma_fput(new); | |
557 | unlink_anon_vmas(new); | |
558 | out_free_mpol: | |
559 | mpol_put(vma_policy(new)); | |
d58c55f2 | 560 | @@ -2878,7 +2878,7 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
7e9cd9fe AM |
561 | struct vm_area_struct *vma; |
562 | unsigned long populate = 0; | |
563 | unsigned long ret = -EINVAL; | |
564 | - struct file *file; | |
5afbbe0d | 565 | + struct file *file, *prfile; |
7e9cd9fe | 566 | |
cd7a4cd9 | 567 | pr_warn_once("%s (%d) uses deprecated remap_file_pages() syscall. See Documentation/vm/remap_file_pages.rst.\n", |
5afbbe0d | 568 | current->comm, current->pid); |
d58c55f2 | 569 | @@ -2953,10 +2953,27 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size, |
febd17d6 | 570 | } |
7e9cd9fe AM |
571 | } |
572 | ||
573 | - file = get_file(vma->vm_file); | |
574 | + vma_get_file(vma); | |
5afbbe0d AM |
575 | + file = vma->vm_file; |
576 | + prfile = vma->vm_prfile; | |
7e9cd9fe | 577 | ret = do_mmap_pgoff(vma->vm_file, start, size, |
521ced18 | 578 | prot, flags, pgoff, &populate, NULL); |
5afbbe0d AM |
579 | + if (!IS_ERR_VALUE(ret) && file && prfile) { |
580 | + struct vm_area_struct *new_vma; | |
581 | + | |
582 | + new_vma = find_vma(mm, ret); | |
583 | + if (!new_vma->vm_prfile) | |
584 | + new_vma->vm_prfile = prfile; | |
585 | + if (new_vma != vma) | |
586 | + get_file(prfile); | |
587 | + } | |
588 | + /* | |
589 | + * two fput()s instead of vma_fput(vma), | |
590 | + * coz vma may not be available anymore. | |
591 | + */ | |
592 | fput(file); | |
593 | + if (prfile) | |
594 | + fput(prfile); | |
7e9cd9fe AM |
595 | out: |
596 | up_write(&mm->mmap_sem); | |
597 | if (populate) | |
d58c55f2 | 598 | @@ -3247,7 +3264,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, |
79b8bda9 AM |
599 | if (anon_vma_clone(new_vma, vma)) |
600 | goto out_free_mempol; | |
601 | if (new_vma->vm_file) | |
602 | - get_file(new_vma->vm_file); | |
603 | + vma_get_file(new_vma); | |
604 | if (new_vma->vm_ops && new_vma->vm_ops->open) | |
605 | new_vma->vm_ops->open(new_vma); | |
606 | vma_link(mm, new_vma, prev, rb_link, rb_parent); | |
fb47a38f | 607 | diff --git a/mm/nommu.c b/mm/nommu.c |
d58c55f2 | 608 | index bd2b4e5ef144..acdab5253263 100644 |
fb47a38f JR |
609 | --- a/mm/nommu.c |
610 | +++ b/mm/nommu.c | |
d58c55f2 | 611 | @@ -563,7 +563,7 @@ static void __put_nommu_region(struct vm_region *region) |
fb47a38f JR |
612 | up_write(&nommu_region_sem); |
613 | ||
614 | if (region->vm_file) | |
615 | - fput(region->vm_file); | |
616 | + vmr_fput(region); | |
617 | ||
618 | /* IO memory and memory shared directly out of the pagecache | |
619 | * from ramfs/tmpfs mustn't be released here */ | |
d58c55f2 | 620 | @@ -695,7 +695,7 @@ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) |
fb47a38f JR |
621 | if (vma->vm_ops && vma->vm_ops->close) |
622 | vma->vm_ops->close(vma); | |
623 | if (vma->vm_file) | |
624 | - fput(vma->vm_file); | |
625 | + vma_fput(vma); | |
626 | put_nommu_region(vma->vm_region); | |
cd7a4cd9 | 627 | vm_area_free(vma); |
fb47a38f | 628 | } |
d58c55f2 | 629 | @@ -1218,7 +1218,7 @@ unsigned long do_mmap(struct file *file, |
fb47a38f JR |
630 | goto error_just_free; |
631 | } | |
632 | } | |
633 | - fput(region->vm_file); | |
634 | + vmr_fput(region); | |
635 | kmem_cache_free(vm_region_jar, region); | |
636 | region = pregion; | |
637 | result = start; | |
d58c55f2 | 638 | @@ -1295,10 +1295,10 @@ unsigned long do_mmap(struct file *file, |
fb47a38f JR |
639 | up_write(&nommu_region_sem); |
640 | error: | |
641 | if (region->vm_file) | |
642 | - fput(region->vm_file); | |
643 | + vmr_fput(region); | |
644 | kmem_cache_free(vm_region_jar, region); | |
645 | if (vma->vm_file) | |
eca801bf AM |
646 | - fput(vma->vm_file); |
647 | + vma_fput(vma); | |
648 | vm_area_free(vma); | |
649 | return ret; | |
650 | ||
076b876e AM |
651 | diff --git a/mm/prfile.c b/mm/prfile.c |
652 | new file mode 100644 | |
d58c55f2 | 653 | index 000000000000..00d51187c325 |
076b876e AM |
654 | --- /dev/null |
655 | +++ b/mm/prfile.c | |
2121bcd9 | 656 | @@ -0,0 +1,86 @@ |
cd7a4cd9 | 657 | +// SPDX-License-Identifier: GPL-2.0 |
076b876e | 658 | +/* |
1c60b727 AM |
659 | + * Mainly for aufs which mmap(2) different file and wants to print different |
660 | + * path in /proc/PID/maps. | |
076b876e AM |
661 | + * Call these functions via macros defined in linux/mm.h. |
662 | + * | |
663 | + * See Documentation/filesystems/aufs/design/06mmap.txt | |
664 | + * | |
d58c55f2 | 665 | + * Copyright (c) 2014-2020 Junjro R. Okajima |
076b876e AM |
666 | + * Copyright (c) 2014 Ian Campbell |
667 | + */ | |
668 | + | |
669 | +#include <linux/mm.h> | |
670 | +#include <linux/file.h> | |
671 | +#include <linux/fs.h> | |
672 | + | |
673 | +/* #define PRFILE_TRACE */ | |
674 | +static inline void prfile_trace(struct file *f, struct file *pr, | |
675 | + const char func[], int line, const char func2[]) | |
676 | +{ | |
677 | +#ifdef PRFILE_TRACE | |
678 | + if (pr) | |
1c60b727 | 679 | + pr_info("%s:%d: %s, %pD2\n", func, line, func2, f); |
076b876e AM |
680 | +#endif |
681 | +} | |
682 | + | |
076b876e AM |
683 | +void vma_do_file_update_time(struct vm_area_struct *vma, const char func[], |
684 | + int line) | |
685 | +{ | |
686 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
687 | + | |
688 | + prfile_trace(f, pr, func, line, __func__); | |
689 | + file_update_time(f); | |
690 | + if (f && pr) | |
691 | + file_update_time(pr); | |
692 | +} | |
693 | + | |
694 | +struct file *vma_do_pr_or_file(struct vm_area_struct *vma, const char func[], | |
695 | + int line) | |
696 | +{ | |
697 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
698 | + | |
699 | + prfile_trace(f, pr, func, line, __func__); | |
700 | + return (f && pr) ? pr : f; | |
701 | +} | |
702 | + | |
703 | +void vma_do_get_file(struct vm_area_struct *vma, const char func[], int line) | |
704 | +{ | |
705 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
706 | + | |
707 | + prfile_trace(f, pr, func, line, __func__); | |
708 | + get_file(f); | |
709 | + if (f && pr) | |
710 | + get_file(pr); | |
711 | +} | |
712 | + | |
713 | +void vma_do_fput(struct vm_area_struct *vma, const char func[], int line) | |
714 | +{ | |
715 | + struct file *f = vma->vm_file, *pr = vma->vm_prfile; | |
716 | + | |
717 | + prfile_trace(f, pr, func, line, __func__); | |
718 | + fput(f); | |
719 | + if (f && pr) | |
720 | + fput(pr); | |
721 | +} | |
b912730e AM |
722 | + |
723 | +#ifndef CONFIG_MMU | |
076b876e AM |
724 | +struct file *vmr_do_pr_or_file(struct vm_region *region, const char func[], |
725 | + int line) | |
726 | +{ | |
727 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
728 | + | |
729 | + prfile_trace(f, pr, func, line, __func__); | |
730 | + return (f && pr) ? pr : f; | |
731 | +} | |
732 | + | |
733 | +void vmr_do_fput(struct vm_region *region, const char func[], int line) | |
734 | +{ | |
735 | + struct file *f = region->vm_file, *pr = region->vm_prfile; | |
736 | + | |
737 | + prfile_trace(f, pr, func, line, __func__); | |
738 | + fput(f); | |
739 | + if (f && pr) | |
740 | + fput(pr); | |
741 | +} | |
b912730e | 742 | +#endif /* !CONFIG_MMU */ |
2121bcd9 | 743 | SPDX-License-Identifier: GPL-2.0 |
d58c55f2 | 744 | aufs5.x-rcN standalone patch |
7f207e10 | 745 | |
c1595e42 | 746 | diff --git a/fs/dcache.c b/fs/dcache.c |
d58c55f2 | 747 | index 046000653e4d..15aa871d1b45 100644 |
c1595e42 JR |
748 | --- a/fs/dcache.c |
749 | +++ b/fs/dcache.c | |
d58c55f2 | 750 | @@ -1371,6 +1371,7 @@ void d_walk(struct dentry *parent, void *data, |
c1595e42 JR |
751 | seq = 1; |
752 | goto again; | |
753 | } | |
febd17d6 | 754 | +EXPORT_SYMBOL_GPL(d_walk); |
c1595e42 | 755 | |
a2654f78 AM |
756 | struct check_mount { |
757 | struct vfsmount *mnt; | |
d58c55f2 | 758 | @@ -2916,6 +2917,7 @@ void d_exchange(struct dentry *dentry1, struct dentry *dentry2) |
f2c43d5f AM |
759 | |
760 | write_sequnlock(&rename_lock); | |
761 | } | |
762 | +EXPORT_SYMBOL_GPL(d_exchange); | |
763 | ||
764 | /** | |
765 | * d_ancestor - search for an ancestor | |
79b8bda9 | 766 | diff --git a/fs/exec.c b/fs/exec.c |
d58c55f2 | 767 | index 74d88dab98dd..71eb4fcace94 100644 |
79b8bda9 AM |
768 | --- a/fs/exec.c |
769 | +++ b/fs/exec.c | |
d58c55f2 | 770 | @@ -109,6 +109,7 @@ bool path_noexec(const struct path *path) |
79b8bda9 AM |
771 | return (path->mnt->mnt_flags & MNT_NOEXEC) || |
772 | (path->mnt->mnt_sb->s_iflags & SB_I_NOEXEC); | |
773 | } | |
febd17d6 | 774 | +EXPORT_SYMBOL_GPL(path_noexec); |
79b8bda9 AM |
775 | |
776 | #ifdef CONFIG_USELIB | |
777 | /* | |
febd17d6 | 778 | diff --git a/fs/fcntl.c b/fs/fcntl.c |
d58c55f2 | 779 | index b0935c67bd1e..07251ba86c31 100644 |
febd17d6 JR |
780 | --- a/fs/fcntl.c |
781 | +++ b/fs/fcntl.c | |
43982f53 | 782 | @@ -85,6 +85,7 @@ int setfl(int fd, struct file *filp, unsigned long arg) |
febd17d6 JR |
783 | out: |
784 | return error; | |
785 | } | |
786 | +EXPORT_SYMBOL_GPL(setfl); | |
787 | ||
788 | static void f_modown(struct file *filp, struct pid *pid, enum pid_type type, | |
789 | int force) | |
b912730e | 790 | diff --git a/fs/file_table.c b/fs/file_table.c |
43982f53 | 791 | index 30d55c9a1744..34b9bbf4c556 100644 |
b912730e AM |
792 | --- a/fs/file_table.c |
793 | +++ b/fs/file_table.c | |
fbc438ed | 794 | @@ -162,6 +162,7 @@ struct file *alloc_empty_file(int flags, const struct cred *cred) |
b912730e AM |
795 | } |
796 | return ERR_PTR(-ENFILE); | |
797 | } | |
acd2b654 | 798 | +EXPORT_SYMBOL_GPL(alloc_empty_file); |
b912730e | 799 | |
acd2b654 AM |
800 | /* |
801 | * Variant of alloc_empty_file() that doesn't check and modify nr_files. | |
43982f53 | 802 | @@ -375,6 +376,7 @@ void __fput_sync(struct file *file) |
8cdd5066 JR |
803 | } |
804 | ||
805 | EXPORT_SYMBOL(fput); | |
febd17d6 | 806 | +EXPORT_SYMBOL_GPL(__fput_sync); |
8cdd5066 | 807 | |
79b8bda9 | 808 | void __init files_init(void) |
8b6a4947 | 809 | { |
5afbbe0d | 810 | diff --git a/fs/inode.c b/fs/inode.c |
d58c55f2 | 811 | index 31796c1040d6..217169541ac4 100644 |
5afbbe0d AM |
812 | --- a/fs/inode.c |
813 | +++ b/fs/inode.c | |
d58c55f2 | 814 | @@ -1689,6 +1689,7 @@ int update_time(struct inode *inode, struct timespec64 *time, int flags) |
5afbbe0d AM |
815 | |
816 | return update_time(inode, time, flags); | |
817 | } | |
818 | +EXPORT_SYMBOL_GPL(update_time); | |
819 | ||
820 | /** | |
821 | * touch_atime - update the access time | |
7f207e10 | 822 | diff --git a/fs/namespace.c b/fs/namespace.c |
d58c55f2 | 823 | index c05ac2488abb..100b7839c8b0 100644 |
7f207e10 AM |
824 | --- a/fs/namespace.c |
825 | +++ b/fs/namespace.c | |
eca34b5c | 826 | @@ -431,6 +431,7 @@ void __mnt_drop_write(struct vfsmount *mnt) |
c06a8ce3 AM |
827 | mnt_dec_writers(real_mount(mnt)); |
828 | preempt_enable(); | |
829 | } | |
830 | +EXPORT_SYMBOL_GPL(__mnt_drop_write); | |
831 | ||
832 | /** | |
833 | * mnt_drop_write - give up write access to a mount | |
eca34b5c | 834 | @@ -781,6 +782,7 @@ int is_current_mnt_ns(struct vfsmount *mnt) |
8b6a4947 AM |
835 | { |
836 | return check_mnt(real_mount(mnt)); | |
837 | } | |
838 | +EXPORT_SYMBOL_GPL(is_current_mnt_ns); | |
839 | ||
840 | /* | |
841 | * vfsmount lock must be held for write | |
43982f53 | 842 | @@ -1903,6 +1905,7 @@ int iterate_mounts(int (*f)(struct vfsmount *, void *), void *arg, |
7f207e10 AM |
843 | } |
844 | return 0; | |
845 | } | |
febd17d6 | 846 | +EXPORT_SYMBOL_GPL(iterate_mounts); |
7f207e10 | 847 | |
fbc438ed | 848 | static void lock_mnt_tree(struct mount *mnt) |
7f207e10 | 849 | { |
43982f53 AM |
850 | diff --git a/fs/notify/group.c b/fs/notify/group.c |
851 | index 133f723aca07..0b9f7f6d8390 100644 | |
852 | --- a/fs/notify/group.c | |
853 | +++ b/fs/notify/group.c | |
854 | @@ -99,6 +99,7 @@ void fsnotify_get_group(struct fsnotify_group *group) | |
1716fcea | 855 | { |
2121bcd9 | 856 | refcount_inc(&group->refcnt); |
1716fcea | 857 | } |
febd17d6 | 858 | +EXPORT_SYMBOL_GPL(fsnotify_get_group); |
1716fcea AM |
859 | |
860 | /* | |
861 | * Drop a reference to a group. Free it if it's through. | |
7f207e10 | 862 | diff --git a/fs/open.c b/fs/open.c |
43982f53 | 863 | index b62f5c0923a8..89af4b9c7319 100644 |
7f207e10 AM |
864 | --- a/fs/open.c |
865 | +++ b/fs/open.c | |
fbc438ed | 866 | @@ -65,6 +65,7 @@ int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs, |
febd17d6 | 867 | inode_unlock(dentry->d_inode); |
7f207e10 AM |
868 | return ret; |
869 | } | |
febd17d6 | 870 | +EXPORT_SYMBOL_GPL(do_truncate); |
7f207e10 | 871 | |
5afbbe0d | 872 | long vfs_truncate(const struct path *path, loff_t length) |
7f207e10 | 873 | { |
5527c038 | 874 | diff --git a/fs/read_write.c b/fs/read_write.c |
43982f53 | 875 | index fa9b3994b34c..eb0e2c6ebaff 100644 |
5527c038 JR |
876 | --- a/fs/read_write.c |
877 | +++ b/fs/read_write.c | |
fbc438ed | 878 | @@ -468,6 +468,7 @@ ssize_t vfs_read(struct file *file, char __user *buf, size_t count, loff_t *pos) |
8b6a4947 AM |
879 | |
880 | return ret; | |
881 | } | |
882 | +EXPORT_SYMBOL_GPL(vfs_read); | |
883 | ||
884 | static ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos) | |
885 | { | |
fbc438ed | 886 | @@ -508,6 +509,7 @@ vfs_readf_t vfs_readf(struct file *file) |
5527c038 | 887 | return new_sync_read; |
43982f53 | 888 | return ERR_PTR(-ENOSYS); /* doesn't have ->read(|_iter)() op */ |
5527c038 | 889 | } |
febd17d6 | 890 | +EXPORT_SYMBOL_GPL(vfs_readf); |
5527c038 JR |
891 | |
892 | vfs_writef_t vfs_writef(struct file *file) | |
893 | { | |
fbc438ed | 894 | @@ -519,6 +521,7 @@ vfs_writef_t vfs_writef(struct file *file) |
5527c038 | 895 | return new_sync_write; |
43982f53 | 896 | return ERR_PTR(-ENOSYS); /* doesn't have ->write(|_iter)() op */ |
5527c038 | 897 | } |
febd17d6 | 898 | +EXPORT_SYMBOL_GPL(vfs_writef); |
5527c038 | 899 | |
8b6a4947 AM |
900 | ssize_t __kernel_write(struct file *file, const void *buf, size_t count, loff_t *pos) |
901 | { | |
fbc438ed | 902 | @@ -588,6 +591,7 @@ ssize_t vfs_write(struct file *file, const char __user *buf, size_t count, loff_ |
8b6a4947 AM |
903 | |
904 | return ret; | |
905 | } | |
906 | +EXPORT_SYMBOL_GPL(vfs_write); | |
907 | ||
fbc438ed JR |
908 | /* file_ppos returns &file->f_pos or NULL if file is stream */ |
909 | static inline loff_t *file_ppos(struct file *file) | |
7f207e10 | 910 | diff --git a/fs/splice.c b/fs/splice.c |
d58c55f2 | 911 | index d9bcc4a71a0a..bf8725e99070 100644 |
7f207e10 AM |
912 | --- a/fs/splice.c |
913 | +++ b/fs/splice.c | |
d58c55f2 | 914 | @@ -862,6 +862,7 @@ long do_splice_from(struct pipe_inode_info *pipe, struct file *out, |
392086de AM |
915 | |
916 | return splice_write(pipe, out, ppos, len, flags); | |
7f207e10 | 917 | } |
febd17d6 | 918 | +EXPORT_SYMBOL_GPL(do_splice_from); |
7f207e10 AM |
919 | |
920 | /* | |
921 | * Attempt to initiate a splice from a file to a pipe. | |
d58c55f2 | 922 | @@ -891,6 +892,7 @@ long do_splice_to(struct file *in, loff_t *ppos, |
7f207e10 AM |
923 | |
924 | return splice_read(in, ppos, pipe, len, flags); | |
925 | } | |
febd17d6 | 926 | +EXPORT_SYMBOL_GPL(do_splice_to); |
7f207e10 AM |
927 | |
928 | /** | |
929 | * splice_direct_to_actor - splices data directly between two non-pipes | |
a2654f78 | 930 | diff --git a/fs/sync.c b/fs/sync.c |
fbc438ed | 931 | index 457f4e4a5cc1..67c66358f3fe 100644 |
a2654f78 AM |
932 | --- a/fs/sync.c |
933 | +++ b/fs/sync.c | |
2121bcd9 | 934 | @@ -39,6 +39,7 @@ int __sync_filesystem(struct super_block *sb, int wait) |
a2654f78 AM |
935 | sb->s_op->sync_fs(sb, wait); |
936 | return __sync_blockdev(sb->s_bdev, wait); | |
937 | } | |
938 | +EXPORT_SYMBOL_GPL(__sync_filesystem); | |
939 | ||
940 | /* | |
941 | * Write out and wait upon all dirty data associated with this | |
c1595e42 | 942 | diff --git a/fs/xattr.c b/fs/xattr.c |
fbc438ed | 943 | index 90dd78f0eb27..40b01dd1b14a 100644 |
c1595e42 JR |
944 | --- a/fs/xattr.c |
945 | +++ b/fs/xattr.c | |
fbc438ed | 946 | @@ -296,6 +296,7 @@ vfs_getxattr_alloc(struct dentry *dentry, const char *name, char **xattr_value, |
c1595e42 JR |
947 | *xattr_value = value; |
948 | return error; | |
949 | } | |
febd17d6 | 950 | +EXPORT_SYMBOL_GPL(vfs_getxattr_alloc); |
c1595e42 | 951 | |
febd17d6 | 952 | ssize_t |
f2c43d5f | 953 | __vfs_getxattr(struct dentry *dentry, struct inode *inode, const char *name, |
8b6a4947 | 954 | diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c |
d58c55f2 | 955 | index e52169c2086b..d9bc5cbe9078 100644 |
8b6a4947 AM |
956 | --- a/kernel/locking/lockdep.c |
957 | +++ b/kernel/locking/lockdep.c | |
eca34b5c AM |
958 | @@ -174,6 +174,7 @@ inline struct lock_class *lockdep_hlock_class(struct held_lock *hlock) |
959 | */ | |
960 | return lock_classes + class_idx; | |
8b6a4947 AM |
961 | } |
962 | +EXPORT_SYMBOL_GPL(lockdep_hlock_class); | |
963 | #define hlock_class(hlock) lockdep_hlock_class(hlock) | |
964 | ||
965 | #ifdef CONFIG_LOCK_STAT | |
8cdd5066 | 966 | diff --git a/kernel/task_work.c b/kernel/task_work.c |
ba1aed25 | 967 | index 0fef395662a6..83fb1ecfc33d 100644 |
8cdd5066 JR |
968 | --- a/kernel/task_work.c |
969 | +++ b/kernel/task_work.c | |
2121bcd9 | 970 | @@ -116,3 +116,4 @@ void task_work_run(void) |
8cdd5066 JR |
971 | } while (work); |
972 | } | |
973 | } | |
febd17d6 | 974 | +EXPORT_SYMBOL_GPL(task_work_run); |
7f207e10 | 975 | diff --git a/security/security.c b/security/security.c |
d58c55f2 | 976 | index cd2d18d2d279..fbf716450399 100644 |
7f207e10 AM |
977 | --- a/security/security.c |
978 | +++ b/security/security.c | |
43982f53 | 979 | @@ -1036,6 +1036,7 @@ int security_path_rmdir(const struct path *dir, struct dentry *dentry) |
7f207e10 | 980 | return 0; |
c2c0f25c | 981 | return call_int_hook(path_rmdir, 0, dir, dentry); |
7f207e10 | 982 | } |
febd17d6 | 983 | +EXPORT_SYMBOL_GPL(security_path_rmdir); |
7f207e10 | 984 | |
5afbbe0d | 985 | int security_path_unlink(const struct path *dir, struct dentry *dentry) |
7f207e10 | 986 | { |
43982f53 | 987 | @@ -1052,6 +1053,7 @@ int security_path_symlink(const struct path *dir, struct dentry *dentry, |
7f207e10 | 988 | return 0; |
c2c0f25c | 989 | return call_int_hook(path_symlink, 0, dir, dentry, old_name); |
7f207e10 | 990 | } |
febd17d6 | 991 | +EXPORT_SYMBOL_GPL(security_path_symlink); |
7f207e10 | 992 | |
5afbbe0d | 993 | int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
7f207e10 | 994 | struct dentry *new_dentry) |
43982f53 | 995 | @@ -1060,6 +1062,7 @@ int security_path_link(struct dentry *old_dentry, const struct path *new_dir, |
7f207e10 | 996 | return 0; |
c2c0f25c | 997 | return call_int_hook(path_link, 0, old_dentry, new_dir, new_dentry); |
7f207e10 | 998 | } |
febd17d6 | 999 | +EXPORT_SYMBOL_GPL(security_path_link); |
7f207e10 | 1000 | |
5afbbe0d AM |
1001 | int security_path_rename(const struct path *old_dir, struct dentry *old_dentry, |
1002 | const struct path *new_dir, struct dentry *new_dentry, | |
43982f53 | 1003 | @@ -1087,6 +1090,7 @@ int security_path_truncate(const struct path *path) |
7f207e10 | 1004 | return 0; |
c2c0f25c | 1005 | return call_int_hook(path_truncate, 0, path); |
7f207e10 | 1006 | } |
febd17d6 | 1007 | +EXPORT_SYMBOL_GPL(security_path_truncate); |
7f207e10 | 1008 | |
5afbbe0d | 1009 | int security_path_chmod(const struct path *path, umode_t mode) |
7eafdf33 | 1010 | { |
43982f53 | 1011 | @@ -1094,6 +1098,7 @@ int security_path_chmod(const struct path *path, umode_t mode) |
7f207e10 | 1012 | return 0; |
c2c0f25c | 1013 | return call_int_hook(path_chmod, 0, path, mode); |
7f207e10 | 1014 | } |
febd17d6 | 1015 | +EXPORT_SYMBOL_GPL(security_path_chmod); |
7f207e10 | 1016 | |
5afbbe0d | 1017 | int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 1018 | { |
43982f53 | 1019 | @@ -1101,6 +1106,7 @@ int security_path_chown(const struct path *path, kuid_t uid, kgid_t gid) |
7f207e10 | 1020 | return 0; |
c2c0f25c | 1021 | return call_int_hook(path_chown, 0, path, uid, gid); |
7f207e10 | 1022 | } |
febd17d6 | 1023 | +EXPORT_SYMBOL_GPL(security_path_chown); |
7f207e10 | 1024 | |
5afbbe0d | 1025 | int security_path_chroot(const struct path *path) |
7f207e10 | 1026 | { |
43982f53 | 1027 | @@ -1201,6 +1207,7 @@ int security_inode_permission(struct inode *inode, int mask) |
7f207e10 | 1028 | return 0; |
c2c0f25c | 1029 | return call_int_hook(inode_permission, 0, inode, mask); |
7f207e10 | 1030 | } |
febd17d6 | 1031 | +EXPORT_SYMBOL_GPL(security_inode_permission); |
7f207e10 | 1032 | |
1e00d052 | 1033 | int security_inode_setattr(struct dentry *dentry, struct iattr *attr) |
7f207e10 | 1034 | { |
43982f53 | 1035 | @@ -1378,6 +1385,7 @@ int security_file_permission(struct file *file, int mask) |
7f207e10 AM |
1036 | |
1037 | return fsnotify_perm(file, mask); | |
1038 | } | |
febd17d6 | 1039 | +EXPORT_SYMBOL_GPL(security_file_permission); |
7f207e10 AM |
1040 | |
1041 | int security_file_alloc(struct file *file) | |
1042 | { | |
7f207e10 | 1043 | diff -urN /usr/share/empty/Documentation/ABI/testing/debugfs-aufs linux/Documentation/ABI/testing/debugfs-aufs |
eca34b5c AM |
1044 | --- /usr/share/empty/Documentation/ABI/testing/debugfs-aufs 1970-01-01 01:00:00.000000000 +0100 |
1045 | +++ linux/Documentation/ABI/testing/debugfs-aufs 2019-07-11 15:42:14.455570938 +0200 | |
062440b3 | 1046 | @@ -0,0 +1,55 @@ |
7f207e10 AM |
1047 | +What: /debug/aufs/si_<id>/ |
1048 | +Date: March 2009 | |
f6b6e03d | 1049 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1050 | +Description: |
1051 | + Under /debug/aufs, a directory named si_<id> is created | |
1052 | + per aufs mount, where <id> is a unique id generated | |
1053 | + internally. | |
1facf9fc | 1054 | + |
86dc4139 AM |
1055 | +What: /debug/aufs/si_<id>/plink |
1056 | +Date: Apr 2013 | |
f6b6e03d | 1057 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
86dc4139 AM |
1058 | +Description: |
1059 | + It has three lines and shows the information about the | |
1060 | + pseudo-link. The first line is a single number | |
1061 | + representing a number of buckets. The second line is a | |
1062 | + number of pseudo-links per buckets (separated by a | |
1063 | + blank). The last line is a single number representing a | |
1064 | + total number of psedo-links. | |
1065 | + When the aufs mount option 'noplink' is specified, it | |
1066 | + will show "1\n0\n0\n". | |
1067 | + | |
7f207e10 AM |
1068 | +What: /debug/aufs/si_<id>/xib |
1069 | +Date: March 2009 | |
f6b6e03d | 1070 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1071 | +Description: |
1072 | + It shows the consumed blocks by xib (External Inode Number | |
1073 | + Bitmap), its block size and file size. | |
1074 | + When the aufs mount option 'noxino' is specified, it | |
1075 | + will be empty. About XINO files, see the aufs manual. | |
1076 | + | |
062440b3 | 1077 | +What: /debug/aufs/si_<id>/xi0, xi1 ... xiN and xiN-N |
7f207e10 | 1078 | +Date: March 2009 |
f6b6e03d | 1079 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1080 | +Description: |
1081 | + It shows the consumed blocks by xino (External Inode Number | |
1082 | + Translation Table), its link count, block size and file | |
1083 | + size. | |
062440b3 AM |
1084 | + Due to the file size limit, there may exist multiple |
1085 | + xino files per branch. In this case, "-N" is added to | |
1086 | + the filename and it corresponds to the index of the | |
1087 | + internal xino array. "-0" is omitted. | |
1088 | + When the aufs mount option 'noxino' is specified, Those | |
1089 | + entries won't exist. About XINO files, see the aufs | |
1090 | + manual. | |
7f207e10 AM |
1091 | + |
1092 | +What: /debug/aufs/si_<id>/xigen | |
1093 | +Date: March 2009 | |
f6b6e03d | 1094 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1095 | +Description: |
1096 | + It shows the consumed blocks by xigen (External Inode | |
1097 | + Generation Table), its block size and file size. | |
1098 | + If CONFIG_AUFS_EXPORT is disabled, this entry will not | |
1099 | + be created. | |
1100 | + When the aufs mount option 'noxino' is specified, it | |
1101 | + will be empty. About XINO files, see the aufs manual. | |
1102 | diff -urN /usr/share/empty/Documentation/ABI/testing/sysfs-aufs linux/Documentation/ABI/testing/sysfs-aufs | |
eca34b5c AM |
1103 | --- /usr/share/empty/Documentation/ABI/testing/sysfs-aufs 1970-01-01 01:00:00.000000000 +0100 |
1104 | +++ linux/Documentation/ABI/testing/sysfs-aufs 2019-07-11 15:42:14.455570938 +0200 | |
392086de | 1105 | @@ -0,0 +1,31 @@ |
7f207e10 AM |
1106 | +What: /sys/fs/aufs/si_<id>/ |
1107 | +Date: March 2009 | |
f6b6e03d | 1108 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1109 | +Description: |
1110 | + Under /sys/fs/aufs, a directory named si_<id> is created | |
1111 | + per aufs mount, where <id> is a unique id generated | |
1112 | + internally. | |
1113 | + | |
1114 | +What: /sys/fs/aufs/si_<id>/br0, br1 ... brN | |
1115 | +Date: March 2009 | |
f6b6e03d | 1116 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1117 | +Description: |
1118 | + It shows the abolute path of a member directory (which | |
1119 | + is called branch) in aufs, and its permission. | |
1120 | + | |
392086de AM |
1121 | +What: /sys/fs/aufs/si_<id>/brid0, brid1 ... bridN |
1122 | +Date: July 2013 | |
f6b6e03d | 1123 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
392086de AM |
1124 | +Description: |
1125 | + It shows the id of a member directory (which is called | |
1126 | + branch) in aufs. | |
1127 | + | |
7f207e10 AM |
1128 | +What: /sys/fs/aufs/si_<id>/xi_path |
1129 | +Date: March 2009 | |
f6b6e03d | 1130 | +Contact: J. R. Okajima <hooanon05g@gmail.com> |
7f207e10 AM |
1131 | +Description: |
1132 | + It shows the abolute path of XINO (External Inode Number | |
1133 | + Bitmap, Translation Table and Generation Table) file | |
1134 | + even if it is the default path. | |
1135 | + When the aufs mount option 'noxino' is specified, it | |
1136 | + will be empty. About XINO files, see the aufs manual. | |
53392da6 | 1137 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt linux/Documentation/filesystems/aufs/design/01intro.txt |
eca34b5c | 1138 | --- /usr/share/empty/Documentation/filesystems/aufs/design/01intro.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1139 | +++ linux/Documentation/filesystems/aufs/design/01intro.txt 2020-01-27 10:57:18.162204582 +0100 |
1c60b727 | 1140 | @@ -0,0 +1,171 @@ |
53392da6 | 1141 | + |
d58c55f2 | 1142 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
1143 | +# |
1144 | +# This program is free software; you can redistribute it and/or modify | |
1145 | +# it under the terms of the GNU General Public License as published by | |
1146 | +# the Free Software Foundation; either version 2 of the License, or | |
1147 | +# (at your option) any later version. | |
1148 | +# | |
1149 | +# This program is distributed in the hope that it will be useful, | |
1150 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1151 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1152 | +# GNU General Public License for more details. | |
1153 | +# | |
1154 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1155 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1156 | + |
1157 | +Introduction | |
1158 | +---------------------------------------- | |
1159 | + | |
3c1bdaff | 1160 | +aufs [ei ju: ef es] | /ey-yoo-ef-es/ | [a u f s] |
53392da6 AM |
1161 | +1. abbrev. for "advanced multi-layered unification filesystem". |
1162 | +2. abbrev. for "another unionfs". | |
1163 | +3. abbrev. for "auf das" in German which means "on the" in English. | |
1164 | + Ex. "Butter aufs Brot"(G) means "butter onto bread"(E). | |
1165 | + But "Filesystem aufs Filesystem" is hard to understand. | |
1c60b727 | 1166 | +4. abbrev. for "African Urban Fashion Show". |
53392da6 AM |
1167 | + |
1168 | +AUFS is a filesystem with features: | |
1169 | +- multi layered stackable unification filesystem, the member directory | |
1170 | + is called as a branch. | |
1171 | +- branch permission and attribute, 'readonly', 'real-readonly', | |
7e9cd9fe | 1172 | + 'readwrite', 'whiteout-able', 'link-able whiteout', etc. and their |
53392da6 AM |
1173 | + combination. |
1174 | +- internal "file copy-on-write". | |
1175 | +- logical deletion, whiteout. | |
1176 | +- dynamic branch manipulation, adding, deleting and changing permission. | |
1177 | +- allow bypassing aufs, user's direct branch access. | |
1178 | +- external inode number translation table and bitmap which maintains the | |
1179 | + persistent aufs inode number. | |
1180 | +- seekable directory, including NFS readdir. | |
1181 | +- file mapping, mmap and sharing pages. | |
1182 | +- pseudo-link, hardlink over branches. | |
1183 | +- loopback mounted filesystem as a branch. | |
1184 | +- several policies to select one among multiple writable branches. | |
1185 | +- revert a single systemcall when an error occurs in aufs. | |
1186 | +- and more... | |
1187 | + | |
1188 | + | |
1189 | +Multi Layered Stackable Unification Filesystem | |
1190 | +---------------------------------------------------------------------- | |
1191 | +Most people already knows what it is. | |
1192 | +It is a filesystem which unifies several directories and provides a | |
1193 | +merged single directory. When users access a file, the access will be | |
1194 | +passed/re-directed/converted (sorry, I am not sure which English word is | |
1195 | +correct) to the real file on the member filesystem. The member | |
1196 | +filesystem is called 'lower filesystem' or 'branch' and has a mode | |
1197 | +'readonly' and 'readwrite.' And the deletion for a file on the lower | |
1198 | +readonly branch is handled by creating 'whiteout' on the upper writable | |
1199 | +branch. | |
1200 | + | |
1201 | +On LKML, there have been discussions about UnionMount (Jan Blunck, | |
1202 | +Bharata B Rao and Valerie Aurora) and Unionfs (Erez Zadok). They took | |
1203 | +different approaches to implement the merged-view. | |
1204 | +The former tries putting it into VFS, and the latter implements as a | |
1205 | +separate filesystem. | |
1206 | +(If I misunderstand about these implementations, please let me know and | |
1207 | +I shall correct it. Because it is a long time ago when I read their | |
1208 | +source files last time). | |
1209 | + | |
1210 | +UnionMount's approach will be able to small, but may be hard to share | |
1211 | +branches between several UnionMount since the whiteout in it is | |
1212 | +implemented in the inode on branch filesystem and always | |
1213 | +shared. According to Bharata's post, readdir does not seems to be | |
1214 | +finished yet. | |
1215 | +There are several missing features known in this implementations such as | |
1216 | +- for users, the inode number may change silently. eg. copy-up. | |
1217 | +- link(2) may break by copy-up. | |
1218 | +- read(2) may get an obsoleted filedata (fstat(2) too). | |
1219 | +- fcntl(F_SETLK) may be broken by copy-up. | |
1220 | +- unnecessary copy-up may happen, for example mmap(MAP_PRIVATE) after | |
1221 | + open(O_RDWR). | |
1222 | + | |
7e9cd9fe AM |
1223 | +In linux-3.18, "overlay" filesystem (formerly known as "overlayfs") was |
1224 | +merged into mainline. This is another implementation of UnionMount as a | |
1225 | +separated filesystem. All the limitations and known problems which | |
1226 | +UnionMount are equally inherited to "overlay" filesystem. | |
1227 | + | |
1228 | +Unionfs has a longer history. When I started implementing a stackable | |
1229 | +filesystem (Aug 2005), it already existed. It has virtual super_block, | |
1230 | +inode, dentry and file objects and they have an array pointing lower | |
1231 | +same kind objects. After contributing many patches for Unionfs, I | |
1232 | +re-started my project AUFS (Jun 2006). | |
53392da6 AM |
1233 | + |
1234 | +In AUFS, the structure of filesystem resembles to Unionfs, but I | |
1235 | +implemented my own ideas, approaches and enhancements and it became | |
1236 | +totally different one. | |
1237 | + | |
1238 | +Comparing DM snapshot and fs based implementation | |
1239 | +- the number of bytes to be copied between devices is much smaller. | |
1240 | +- the type of filesystem must be one and only. | |
1241 | +- the fs must be writable, no readonly fs, even for the lower original | |
1242 | + device. so the compression fs will not be usable. but if we use | |
1243 | + loopback mount, we may address this issue. | |
1244 | + for instance, | |
1245 | + mount /cdrom/squashfs.img /sq | |
1246 | + losetup /sq/ext2.img | |
1247 | + losetup /somewhere/cow | |
1248 | + dmsetup "snapshot /dev/loop0 /dev/loop1 ..." | |
1249 | +- it will be difficult (or needs more operations) to extract the | |
1250 | + difference between the original device and COW. | |
1251 | +- DM snapshot-merge may help a lot when users try merging. in the | |
1252 | + fs-layer union, users will use rsync(1). | |
1253 | + | |
7e9cd9fe AM |
1254 | +You may want to read my old paper "Filesystems in LiveCD" |
1255 | +(http://aufs.sourceforge.net/aufs2/report/sq/sq.pdf). | |
53392da6 | 1256 | + |
7e9cd9fe AM |
1257 | + |
1258 | +Several characters/aspects/persona of aufs | |
53392da6 AM |
1259 | +---------------------------------------------------------------------- |
1260 | + | |
7e9cd9fe | 1261 | +Aufs has several characters, aspects or persona. |
53392da6 AM |
1262 | +1. a filesystem, callee of VFS helper |
1263 | +2. sub-VFS, caller of VFS helper for branches | |
1264 | +3. a virtual filesystem which maintains persistent inode number | |
1265 | +4. reader/writer of files on branches such like an application | |
1266 | + | |
1267 | +1. Callee of VFS Helper | |
1268 | +As an ordinary linux filesystem, aufs is a callee of VFS. For instance, | |
1269 | +unlink(2) from an application reaches sys_unlink() kernel function and | |
1270 | +then vfs_unlink() is called. vfs_unlink() is one of VFS helper and it | |
1271 | +calls filesystem specific unlink operation. Actually aufs implements the | |
1272 | +unlink operation but it behaves like a redirector. | |
1273 | + | |
1274 | +2. Caller of VFS Helper for Branches | |
1275 | +aufs_unlink() passes the unlink request to the branch filesystem as if | |
1276 | +it were called from VFS. So the called unlink operation of the branch | |
1277 | +filesystem acts as usual. As a caller of VFS helper, aufs should handle | |
1278 | +every necessary pre/post operation for the branch filesystem. | |
1279 | +- acquire the lock for the parent dir on a branch | |
1280 | +- lookup in a branch | |
1281 | +- revalidate dentry on a branch | |
1282 | +- mnt_want_write() for a branch | |
1283 | +- vfs_unlink() for a branch | |
1284 | +- mnt_drop_write() for a branch | |
1285 | +- release the lock on a branch | |
1286 | + | |
1287 | +3. Persistent Inode Number | |
1288 | +One of the most important issue for a filesystem is to maintain inode | |
1289 | +numbers. This is particularly important to support exporting a | |
1290 | +filesystem via NFS. Aufs is a virtual filesystem which doesn't have a | |
1291 | +backend block device for its own. But some storage is necessary to | |
7e9cd9fe AM |
1292 | +keep and maintain the inode numbers. It may be a large space and may not |
1293 | +suit to keep in memory. Aufs rents some space from its first writable | |
1294 | +branch filesystem (by default) and creates file(s) on it. These files | |
1295 | +are created by aufs internally and removed soon (currently) keeping | |
1296 | +opened. | |
53392da6 AM |
1297 | +Note: Because these files are removed, they are totally gone after |
1298 | + unmounting aufs. It means the inode numbers are not persistent | |
1299 | + across unmount or reboot. I have a plan to make them really | |
1300 | + persistent which will be important for aufs on NFS server. | |
1301 | + | |
1302 | +4. Read/Write Files Internally (copy-on-write) | |
1303 | +Because a branch can be readonly, when you write a file on it, aufs will | |
1304 | +"copy-up" it to the upper writable branch internally. And then write the | |
1305 | +originally requested thing to the file. Generally kernel doesn't | |
1306 | +open/read/write file actively. In aufs, even a single write may cause a | |
1307 | +internal "file copy". This behaviour is very similar to cp(1) command. | |
1308 | + | |
1309 | +Some people may think it is better to pass such work to user space | |
1310 | +helper, instead of doing in kernel space. Actually I am still thinking | |
1311 | +about it. But currently I have implemented it in kernel space. | |
1312 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt linux/Documentation/filesystems/aufs/design/02struct.txt | |
eca34b5c | 1313 | --- /usr/share/empty/Documentation/filesystems/aufs/design/02struct.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1314 | +++ linux/Documentation/filesystems/aufs/design/02struct.txt 2020-01-27 10:57:18.162204582 +0100 |
7e9cd9fe | 1315 | @@ -0,0 +1,258 @@ |
53392da6 | 1316 | + |
d58c55f2 | 1317 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
1318 | +# |
1319 | +# This program is free software; you can redistribute it and/or modify | |
1320 | +# it under the terms of the GNU General Public License as published by | |
1321 | +# the Free Software Foundation; either version 2 of the License, or | |
1322 | +# (at your option) any later version. | |
1323 | +# | |
1324 | +# This program is distributed in the hope that it will be useful, | |
1325 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1326 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1327 | +# GNU General Public License for more details. | |
1328 | +# | |
1329 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1330 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1331 | + |
1332 | +Basic Aufs Internal Structure | |
1333 | + | |
1334 | +Superblock/Inode/Dentry/File Objects | |
1335 | +---------------------------------------------------------------------- | |
1336 | +As like an ordinary filesystem, aufs has its own | |
1337 | +superblock/inode/dentry/file objects. All these objects have a | |
1338 | +dynamically allocated array and store the same kind of pointers to the | |
1339 | +lower filesystem, branch. | |
1340 | +For example, when you build a union with one readwrite branch and one | |
1341 | +readonly, mounted /au, /rw and /ro respectively. | |
1342 | +- /au = /rw + /ro | |
1343 | +- /ro/fileA exists but /rw/fileA | |
1344 | + | |
1345 | +Aufs lookup operation finds /ro/fileA and gets dentry for that. These | |
1346 | +pointers are stored in a aufs dentry. The array in aufs dentry will be, | |
7e9cd9fe | 1347 | +- [0] = NULL (because /rw/fileA doesn't exist) |
53392da6 AM |
1348 | +- [1] = /ro/fileA |
1349 | + | |
1350 | +This style of an array is essentially same to the aufs | |
1351 | +superblock/inode/dentry/file objects. | |
1352 | + | |
1353 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1354 | +branches dynamically, these objects has its own generation. When |
1355 | +branches are changed, the generation in aufs superblock is | |
1356 | +incremented. And a generation in other object are compared when it is | |
1357 | +accessed. When a generation in other objects are obsoleted, aufs | |
1358 | +refreshes the internal array. | |
53392da6 AM |
1359 | + |
1360 | + | |
1361 | +Superblock | |
1362 | +---------------------------------------------------------------------- | |
1363 | +Additionally aufs superblock has some data for policies to select one | |
1364 | +among multiple writable branches, XIB files, pseudo-links and kobject. | |
1365 | +See below in detail. | |
7e9cd9fe AM |
1366 | +About the policies which supports copy-down a directory, see |
1367 | +wbr_policy.txt too. | |
53392da6 AM |
1368 | + |
1369 | + | |
1370 | +Branch and XINO(External Inode Number Translation Table) | |
1371 | +---------------------------------------------------------------------- | |
1372 | +Every branch has its own xino (external inode number translation table) | |
1373 | +file. The xino file is created and unlinked by aufs internally. When two | |
1374 | +members of a union exist on the same filesystem, they share the single | |
1375 | +xino file. | |
1376 | +The struct of a xino file is simple, just a sequence of aufs inode | |
1377 | +numbers which is indexed by the lower inode number. | |
1378 | +In the above sample, assume the inode number of /ro/fileA is i111 and | |
1379 | +aufs assigns the inode number i999 for fileA. Then aufs writes 999 as | |
1380 | +4(8) bytes at 111 * 4(8) bytes offset in the xino file. | |
1381 | + | |
1382 | +When the inode numbers are not contiguous, the xino file will be sparse | |
1383 | +which has a hole in it and doesn't consume as much disk space as it | |
1384 | +might appear. If your branch filesystem consumes disk space for such | |
1385 | +holes, then you should specify 'xino=' option at mounting aufs. | |
1386 | + | |
7e9cd9fe AM |
1387 | +Aufs has a mount option to free the disk blocks for such holes in XINO |
1388 | +files on tmpfs or ramdisk. But it is not so effective actually. If you | |
1389 | +meet a problem of disk shortage due to XINO files, then you should try | |
1390 | +"tmpfs-ino.patch" (and "vfs-ino.patch" too) in aufs4-standalone.git. | |
1391 | +The patch localizes the assignment inumbers per tmpfs-mount and avoid | |
1392 | +the holes in XINO files. | |
1393 | + | |
53392da6 | 1394 | +Also a writable branch has three kinds of "whiteout bases". All these |
7e9cd9fe | 1395 | +are existed when the branch is joined to aufs, and their names are |
53392da6 AM |
1396 | +whiteout-ed doubly, so that users will never see their names in aufs |
1397 | +hierarchy. | |
7e9cd9fe | 1398 | +1. a regular file which will be hardlinked to all whiteouts. |
53392da6 | 1399 | +2. a directory to store a pseudo-link. |
7e9cd9fe | 1400 | +3. a directory to store an "orphan"-ed file temporary. |
53392da6 AM |
1401 | + |
1402 | +1. Whiteout Base | |
1403 | + When you remove a file on a readonly branch, aufs handles it as a | |
1404 | + logical deletion and creates a whiteout on the upper writable branch | |
1405 | + as a hardlink of this file in order not to consume inode on the | |
1406 | + writable branch. | |
1407 | +2. Pseudo-link Dir | |
1408 | + See below, Pseudo-link. | |
1409 | +3. Step-Parent Dir | |
1410 | + When "fileC" exists on the lower readonly branch only and it is | |
1411 | + opened and removed with its parent dir, and then user writes | |
1412 | + something into it, then aufs copies-up fileC to this | |
1413 | + directory. Because there is no other dir to store fileC. After | |
1414 | + creating a file under this dir, the file is unlinked. | |
1415 | + | |
1416 | +Because aufs supports manipulating branches, ie. add/delete/change | |
7e9cd9fe AM |
1417 | +dynamically, a branch has its own id. When the branch order changes, |
1418 | +aufs finds the new index by searching the branch id. | |
53392da6 AM |
1419 | + |
1420 | + | |
1421 | +Pseudo-link | |
1422 | +---------------------------------------------------------------------- | |
1423 | +Assume "fileA" exists on the lower readonly branch only and it is | |
1424 | +hardlinked to "fileB" on the branch. When you write something to fileA, | |
1425 | +aufs copies-up it to the upper writable branch. Additionally aufs | |
1426 | +creates a hardlink under the Pseudo-link Directory of the writable | |
1427 | +branch. The inode of a pseudo-link is kept in aufs super_block as a | |
1428 | +simple list. If fileB is read after unlinking fileA, aufs returns | |
1429 | +filedata from the pseudo-link instead of the lower readonly | |
1430 | +branch. Because the pseudo-link is based upon the inode, to keep the | |
7e9cd9fe | 1431 | +inode number by xino (see above) is essentially necessary. |
53392da6 AM |
1432 | + |
1433 | +All the hardlinks under the Pseudo-link Directory of the writable branch | |
1434 | +should be restored in a proper location later. Aufs provides a utility | |
1435 | +to do this. The userspace helpers executed at remounting and unmounting | |
1436 | +aufs by default. | |
1437 | +During this utility is running, it puts aufs into the pseudo-link | |
1438 | +maintenance mode. In this mode, only the process which began the | |
1439 | +maintenance mode (and its child processes) is allowed to operate in | |
1440 | +aufs. Some other processes which are not related to the pseudo-link will | |
1441 | +be allowed to run too, but the rest have to return an error or wait | |
1442 | +until the maintenance mode ends. If a process already acquires an inode | |
1443 | +mutex (in VFS), it has to return an error. | |
1444 | + | |
1445 | + | |
1446 | +XIB(external inode number bitmap) | |
1447 | +---------------------------------------------------------------------- | |
1448 | +Addition to the xino file per a branch, aufs has an external inode number | |
7e9cd9fe AM |
1449 | +bitmap in a superblock object. It is also an internal file such like a |
1450 | +xino file. | |
53392da6 AM |
1451 | +It is a simple bitmap to mark whether the aufs inode number is in-use or |
1452 | +not. | |
1453 | +To reduce the file I/O, aufs prepares a single memory page to cache xib. | |
1454 | + | |
7e9cd9fe | 1455 | +As well as XINO files, aufs has a feature to truncate/refresh XIB to |
53392da6 AM |
1456 | +reduce the number of consumed disk blocks for these files. |
1457 | + | |
1458 | + | |
1459 | +Virtual or Vertical Dir, and Readdir in Userspace | |
1460 | +---------------------------------------------------------------------- | |
1461 | +In order to support multiple layers (branches), aufs readdir operation | |
1462 | +constructs a virtual dir block on memory. For readdir, aufs calls | |
1463 | +vfs_readdir() internally for each dir on branches, merges their entries | |
1464 | +with eliminating the whiteout-ed ones, and sets it to file (dir) | |
1465 | +object. So the file object has its entry list until it is closed. The | |
1466 | +entry list will be updated when the file position is zero and becomes | |
7e9cd9fe | 1467 | +obsoleted. This decision is made in aufs automatically. |
53392da6 AM |
1468 | + |
1469 | +The dynamically allocated memory block for the name of entries has a | |
1470 | +unit of 512 bytes (by default) and stores the names contiguously (no | |
1471 | +padding). Another block for each entry is handled by kmem_cache too. | |
1472 | +During building dir blocks, aufs creates hash list and judging whether | |
1473 | +the entry is whiteouted by its upper branch or already listed. | |
1474 | +The merged result is cached in the corresponding inode object and | |
1475 | +maintained by a customizable life-time option. | |
1476 | + | |
1477 | +Some people may call it can be a security hole or invite DoS attack | |
1478 | +since the opened and once readdir-ed dir (file object) holds its entry | |
1479 | +list and becomes a pressure for system memory. But I'd say it is similar | |
1480 | +to files under /proc or /sys. The virtual files in them also holds a | |
1481 | +memory page (generally) while they are opened. When an idea to reduce | |
1482 | +memory for them is introduced, it will be applied to aufs too. | |
1483 | +For those who really hate this situation, I've developed readdir(3) | |
1484 | +library which operates this merging in userspace. You just need to set | |
1485 | +LD_PRELOAD environment variable, and aufs will not consume no memory in | |
1486 | +kernel space for readdir(3). | |
1487 | + | |
1488 | + | |
1489 | +Workqueue | |
1490 | +---------------------------------------------------------------------- | |
1491 | +Aufs sometimes requires privilege access to a branch. For instance, | |
1492 | +in copy-up/down operation. When a user process is going to make changes | |
1493 | +to a file which exists in the lower readonly branch only, and the mode | |
1494 | +of one of ancestor directories may not be writable by a user | |
1495 | +process. Here aufs copy-up the file with its ancestors and they may | |
1496 | +require privilege to set its owner/group/mode/etc. | |
1497 | +This is a typical case of a application character of aufs (see | |
1498 | +Introduction). | |
1499 | + | |
1500 | +Aufs uses workqueue synchronously for this case. It creates its own | |
1501 | +workqueue. The workqueue is a kernel thread and has privilege. Aufs | |
1502 | +passes the request to call mkdir or write (for example), and wait for | |
1503 | +its completion. This approach solves a problem of a signal handler | |
1504 | +simply. | |
1505 | +If aufs didn't adopt the workqueue and changed the privilege of the | |
7e9cd9fe AM |
1506 | +process, then the process may receive the unexpected SIGXFSZ or other |
1507 | +signals. | |
53392da6 AM |
1508 | + |
1509 | +Also aufs uses the system global workqueue ("events" kernel thread) too | |
1510 | +for asynchronous tasks, such like handling inotify/fsnotify, re-creating a | |
1511 | +whiteout base and etc. This is unrelated to a privilege. | |
1512 | +Most of aufs operation tries acquiring a rw_semaphore for aufs | |
1513 | +superblock at the beginning, at the same time waits for the completion | |
1514 | +of all queued asynchronous tasks. | |
1515 | + | |
1516 | + | |
1517 | +Whiteout | |
1518 | +---------------------------------------------------------------------- | |
1519 | +The whiteout in aufs is very similar to Unionfs's. That is represented | |
1520 | +by its filename. UnionMount takes an approach of a file mode, but I am | |
1521 | +afraid several utilities (find(1) or something) will have to support it. | |
1522 | + | |
1523 | +Basically the whiteout represents "logical deletion" which stops aufs to | |
1524 | +lookup further, but also it represents "dir is opaque" which also stop | |
7e9cd9fe | 1525 | +further lookup. |
53392da6 AM |
1526 | + |
1527 | +In aufs, rmdir(2) and rename(2) for dir uses whiteout alternatively. | |
1528 | +In order to make several functions in a single systemcall to be | |
1529 | +revertible, aufs adopts an approach to rename a directory to a temporary | |
1530 | +unique whiteouted name. | |
1531 | +For example, in rename(2) dir where the target dir already existed, aufs | |
1532 | +renames the target dir to a temporary unique whiteouted name before the | |
7e9cd9fe | 1533 | +actual rename on a branch, and then handles other actions (make it opaque, |
53392da6 AM |
1534 | +update the attributes, etc). If an error happens in these actions, aufs |
1535 | +simply renames the whiteouted name back and returns an error. If all are | |
1536 | +succeeded, aufs registers a function to remove the whiteouted unique | |
1537 | +temporary name completely and asynchronously to the system global | |
1538 | +workqueue. | |
1539 | + | |
1540 | + | |
1541 | +Copy-up | |
1542 | +---------------------------------------------------------------------- | |
1543 | +It is a well-known feature or concept. | |
1544 | +When user modifies a file on a readonly branch, aufs operate "copy-up" | |
1545 | +internally and makes change to the new file on the upper writable branch. | |
1546 | +When the trigger systemcall does not update the timestamps of the parent | |
1547 | +dir, aufs reverts it after copy-up. | |
c2b27bf2 AM |
1548 | + |
1549 | + | |
1550 | +Move-down (aufs3.9 and later) | |
1551 | +---------------------------------------------------------------------- | |
1552 | +"Copy-up" is one of the essential feature in aufs. It copies a file from | |
1553 | +the lower readonly branch to the upper writable branch when a user | |
1554 | +changes something about the file. | |
1555 | +"Move-down" is an opposite action of copy-up. Basically this action is | |
1556 | +ran manually instead of automatically and internally. | |
076b876e AM |
1557 | +For desgin and implementation, aufs has to consider these issues. |
1558 | +- whiteout for the file may exist on the lower branch. | |
1559 | +- ancestor directories may not exist on the lower branch. | |
1560 | +- diropq for the ancestor directories may exist on the upper branch. | |
1561 | +- free space on the lower branch will reduce. | |
1562 | +- another access to the file may happen during moving-down, including | |
7e9cd9fe | 1563 | + UDBA (see "Revalidate Dentry and UDBA"). |
076b876e AM |
1564 | +- the file should not be hard-linked nor pseudo-linked. they should be |
1565 | + handled by auplink utility later. | |
c2b27bf2 AM |
1566 | + |
1567 | +Sometimes users want to move-down a file from the upper writable branch | |
1568 | +to the lower readonly or writable branch. For instance, | |
1569 | +- the free space of the upper writable branch is going to run out. | |
1570 | +- create a new intermediate branch between the upper and lower branch. | |
1571 | +- etc. | |
1572 | + | |
1573 | +For this purpose, use "aumvdown" command in aufs-util.git. | |
b912730e | 1574 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt linux/Documentation/filesystems/aufs/design/03atomic_open.txt |
eca34b5c | 1575 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03atomic_open.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1576 | +++ linux/Documentation/filesystems/aufs/design/03atomic_open.txt 2020-01-27 10:57:18.162204582 +0100 |
b912730e AM |
1577 | @@ -0,0 +1,85 @@ |
1578 | + | |
d58c55f2 | 1579 | +# Copyright (C) 2015-2020 Junjiro R. Okajima |
b912730e AM |
1580 | +# |
1581 | +# This program is free software; you can redistribute it and/or modify | |
1582 | +# it under the terms of the GNU General Public License as published by | |
1583 | +# the Free Software Foundation; either version 2 of the License, or | |
1584 | +# (at your option) any later version. | |
1585 | +# | |
1586 | +# This program is distributed in the hope that it will be useful, | |
1587 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1588 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1589 | +# GNU General Public License for more details. | |
1590 | +# | |
1591 | +# You should have received a copy of the GNU General Public License | |
1592 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1593 | + | |
1594 | +Support for a branch who has its ->atomic_open() | |
1595 | +---------------------------------------------------------------------- | |
1596 | +The filesystems who implement its ->atomic_open() are not majority. For | |
1597 | +example NFSv4 does, and aufs should call NFSv4 ->atomic_open, | |
1598 | +particularly for open(O_CREAT|O_EXCL, 0400) case. Other than | |
1599 | +->atomic_open(), NFSv4 returns an error for this open(2). While I am not | |
1600 | +sure whether all filesystems who have ->atomic_open() behave like this, | |
1601 | +but NFSv4 surely returns the error. | |
1602 | + | |
1603 | +In order to support ->atomic_open() for aufs, there are a few | |
1604 | +approaches. | |
1605 | + | |
1606 | +A. Introduce aufs_atomic_open() | |
1607 | + - calls one of VFS:do_last(), lookup_open() or atomic_open() for | |
1608 | + branch fs. | |
1609 | +B. Introduce aufs_atomic_open() calling create, open and chmod. this is | |
1610 | + an aufs user Pip Cet's approach | |
1611 | + - calls aufs_create(), VFS finish_open() and notify_change(). | |
1612 | + - pass fake-mode to finish_open(), and then correct the mode by | |
1613 | + notify_change(). | |
1614 | +C. Extend aufs_open() to call branch fs's ->atomic_open() | |
1615 | + - no aufs_atomic_open(). | |
1616 | + - aufs_lookup() registers the TID to an aufs internal object. | |
1617 | + - aufs_create() does nothing when the matching TID is registered, but | |
1618 | + registers the mode. | |
1619 | + - aufs_open() calls branch fs's ->atomic_open() when the matching | |
1620 | + TID is registered. | |
1621 | +D. Extend aufs_open() to re-try branch fs's ->open() with superuser's | |
1622 | + credential | |
1623 | + - no aufs_atomic_open(). | |
1624 | + - aufs_create() registers the TID to an internal object. this info | |
1625 | + represents "this process created this file just now." | |
1626 | + - when aufs gets EACCES from branch fs's ->open(), then confirm the | |
1627 | + registered TID and re-try open() with superuser's credential. | |
1628 | + | |
1629 | +Pros and cons for each approach. | |
1630 | + | |
1631 | +A. | |
1632 | + - straightforward but highly depends upon VFS internal. | |
1633 | + - the atomic behavaiour is kept. | |
1634 | + - some of parameters such as nameidata are hard to reproduce for | |
1635 | + branch fs. | |
1636 | + - large overhead. | |
1637 | +B. | |
1638 | + - easy to implement. | |
1639 | + - the atomic behavaiour is lost. | |
1640 | +C. | |
1641 | + - the atomic behavaiour is kept. | |
1642 | + - dirty and tricky. | |
1643 | + - VFS checks whether the file is created correctly after calling | |
1644 | + ->create(), which means this approach doesn't work. | |
1645 | +D. | |
1646 | + - easy to implement. | |
1647 | + - the atomic behavaiour is lost. | |
1648 | + - to open a file with superuser's credential and give it to a user | |
1649 | + process is a bad idea, since the file object keeps the credential | |
1650 | + in it. It may affect LSM or something. This approach doesn't work | |
1651 | + either. | |
1652 | + | |
1653 | +The approach A is ideal, but it hard to implement. So here is a | |
1654 | +variation of A, which is to be implemented. | |
1655 | + | |
1656 | +A-1. Introduce aufs_atomic_open() | |
1657 | + - calls branch fs ->atomic_open() if exists. otherwise calls | |
1658 | + vfs_create() and finish_open(). | |
1659 | + - the demerit is that the several checks after branch fs | |
1660 | + ->atomic_open() are lost. in the ordinary case, the checks are | |
1661 | + done by VFS:do_last(), lookup_open() and atomic_open(). some can | |
1662 | + be implemented in aufs, but not all I am afraid. | |
53392da6 | 1663 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt linux/Documentation/filesystems/aufs/design/03lookup.txt |
eca34b5c | 1664 | --- /usr/share/empty/Documentation/filesystems/aufs/design/03lookup.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1665 | +++ linux/Documentation/filesystems/aufs/design/03lookup.txt 2020-01-27 10:57:18.165538015 +0100 |
7e9cd9fe | 1666 | @@ -0,0 +1,113 @@ |
53392da6 | 1667 | + |
d58c55f2 | 1668 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
1669 | +# |
1670 | +# This program is free software; you can redistribute it and/or modify | |
1671 | +# it under the terms of the GNU General Public License as published by | |
1672 | +# the Free Software Foundation; either version 2 of the License, or | |
1673 | +# (at your option) any later version. | |
1674 | +# | |
1675 | +# This program is distributed in the hope that it will be useful, | |
1676 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1677 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1678 | +# GNU General Public License for more details. | |
1679 | +# | |
1680 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1681 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1682 | + |
1683 | +Lookup in a Branch | |
1684 | +---------------------------------------------------------------------- | |
1685 | +Since aufs has a character of sub-VFS (see Introduction), it operates | |
7e9cd9fe AM |
1686 | +lookup for branches as VFS does. It may be a heavy work. But almost all |
1687 | +lookup operation in aufs is the simplest case, ie. lookup only an entry | |
1688 | +directly connected to its parent. Digging down the directory hierarchy | |
1689 | +is unnecessary. VFS has a function lookup_one_len() for that use, and | |
1690 | +aufs calls it. | |
1691 | + | |
1692 | +When a branch is a remote filesystem, aufs basically relies upon its | |
53392da6 AM |
1693 | +->d_revalidate(), also aufs forces the hardest revalidate tests for |
1694 | +them. | |
1695 | +For d_revalidate, aufs implements three levels of revalidate tests. See | |
1696 | +"Revalidate Dentry and UDBA" in detail. | |
1697 | + | |
1698 | + | |
076b876e AM |
1699 | +Test Only the Highest One for the Directory Permission (dirperm1 option) |
1700 | +---------------------------------------------------------------------- | |
1701 | +Let's try case study. | |
1702 | +- aufs has two branches, upper readwrite and lower readonly. | |
1703 | + /au = /rw + /ro | |
1704 | +- "dirA" exists under /ro, but /rw. and its mode is 0700. | |
1705 | +- user invoked "chmod a+rx /au/dirA" | |
1706 | +- the internal copy-up is activated and "/rw/dirA" is created and its | |
7e9cd9fe | 1707 | + permission bits are set to world readable. |
076b876e AM |
1708 | +- then "/au/dirA" becomes world readable? |
1709 | + | |
1710 | +In this case, /ro/dirA is still 0700 since it exists in readonly branch, | |
1711 | +or it may be a natively readonly filesystem. If aufs respects the lower | |
1712 | +branch, it should not respond readdir request from other users. But user | |
1713 | +allowed it by chmod. Should really aufs rejects showing the entries | |
1714 | +under /ro/dirA? | |
1715 | + | |
7e9cd9fe AM |
1716 | +To be honest, I don't have a good solution for this case. So aufs |
1717 | +implements 'dirperm1' and 'nodirperm1' mount options, and leave it to | |
1718 | +users. | |
076b876e AM |
1719 | +When dirperm1 is specified, aufs checks only the highest one for the |
1720 | +directory permission, and shows the entries. Otherwise, as usual, checks | |
1721 | +every dir existing on all branches and rejects the request. | |
1722 | + | |
1723 | +As a side effect, dirperm1 option improves the performance of aufs | |
1724 | +because the number of permission check is reduced when the number of | |
1725 | +branch is many. | |
1726 | + | |
1727 | + | |
53392da6 AM |
1728 | +Revalidate Dentry and UDBA (User's Direct Branch Access) |
1729 | +---------------------------------------------------------------------- | |
1730 | +Generally VFS helpers re-validate a dentry as a part of lookup. | |
1731 | +0. digging down the directory hierarchy. | |
1732 | +1. lock the parent dir by its i_mutex. | |
1733 | +2. lookup the final (child) entry. | |
1734 | +3. revalidate it. | |
1735 | +4. call the actual operation (create, unlink, etc.) | |
1736 | +5. unlock the parent dir | |
1737 | + | |
1738 | +If the filesystem implements its ->d_revalidate() (step 3), then it is | |
1739 | +called. Actually aufs implements it and checks the dentry on a branch is | |
1740 | +still valid. | |
1741 | +But it is not enough. Because aufs has to release the lock for the | |
1742 | +parent dir on a branch at the end of ->lookup() (step 2) and | |
1743 | +->d_revalidate() (step 3) while the i_mutex of the aufs dir is still | |
1744 | +held by VFS. | |
1745 | +If the file on a branch is changed directly, eg. bypassing aufs, after | |
1746 | +aufs released the lock, then the subsequent operation may cause | |
1747 | +something unpleasant result. | |
1748 | + | |
1749 | +This situation is a result of VFS architecture, ->lookup() and | |
1750 | +->d_revalidate() is separated. But I never say it is wrong. It is a good | |
1751 | +design from VFS's point of view. It is just not suitable for sub-VFS | |
1752 | +character in aufs. | |
1753 | + | |
1754 | +Aufs supports such case by three level of revalidation which is | |
1755 | +selectable by user. | |
1756 | +1. Simple Revalidate | |
1757 | + Addition to the native flow in VFS's, confirm the child-parent | |
1758 | + relationship on the branch just after locking the parent dir on the | |
1759 | + branch in the "actual operation" (step 4). When this validation | |
1760 | + fails, aufs returns EBUSY. ->d_revalidate() (step 3) in aufs still | |
1761 | + checks the validation of the dentry on branches. | |
1762 | +2. Monitor Changes Internally by Inotify/Fsnotify | |
1763 | + Addition to above, in the "actual operation" (step 4) aufs re-lookup | |
1764 | + the dentry on the branch, and returns EBUSY if it finds different | |
1765 | + dentry. | |
1766 | + Additionally, aufs sets the inotify/fsnotify watch for every dir on branches | |
1767 | + during it is in cache. When the event is notified, aufs registers a | |
1768 | + function to kernel 'events' thread by schedule_work(). And the | |
1769 | + function sets some special status to the cached aufs dentry and inode | |
1770 | + private data. If they are not cached, then aufs has nothing to | |
1771 | + do. When the same file is accessed through aufs (step 0-3) later, | |
1772 | + aufs will detect the status and refresh all necessary data. | |
1773 | + In this mode, aufs has to ignore the event which is fired by aufs | |
1774 | + itself. | |
1775 | +3. No Extra Validation | |
1776 | + This is the simplest test and doesn't add any additional revalidation | |
7e9cd9fe | 1777 | + test, and skip the revalidation in step 4. It is useful and improves |
53392da6 AM |
1778 | + aufs performance when system surely hide the aufs branches from user, |
1779 | + by over-mounting something (or another method). | |
1780 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt linux/Documentation/filesystems/aufs/design/04branch.txt | |
eca34b5c | 1781 | --- /usr/share/empty/Documentation/filesystems/aufs/design/04branch.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1782 | +++ linux/Documentation/filesystems/aufs/design/04branch.txt 2020-01-27 10:57:18.165538015 +0100 |
7e9cd9fe | 1783 | @@ -0,0 +1,74 @@ |
53392da6 | 1784 | + |
d58c55f2 | 1785 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
1786 | +# |
1787 | +# This program is free software; you can redistribute it and/or modify | |
1788 | +# it under the terms of the GNU General Public License as published by | |
1789 | +# the Free Software Foundation; either version 2 of the License, or | |
1790 | +# (at your option) any later version. | |
1791 | +# | |
1792 | +# This program is distributed in the hope that it will be useful, | |
1793 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1794 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1795 | +# GNU General Public License for more details. | |
1796 | +# | |
1797 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1798 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1799 | + |
1800 | +Branch Manipulation | |
1801 | + | |
1802 | +Since aufs supports dynamic branch manipulation, ie. add/remove a branch | |
1803 | +and changing its permission/attribute, there are a lot of works to do. | |
1804 | + | |
1805 | + | |
1806 | +Add a Branch | |
1807 | +---------------------------------------------------------------------- | |
1808 | +o Confirm the adding dir exists outside of aufs, including loopback | |
7e9cd9fe | 1809 | + mount, and its various attributes. |
53392da6 AM |
1810 | +o Initialize the xino file and whiteout bases if necessary. |
1811 | + See struct.txt. | |
1812 | + | |
1813 | +o Check the owner/group/mode of the directory | |
1814 | + When the owner/group/mode of the adding directory differs from the | |
1815 | + existing branch, aufs issues a warning because it may impose a | |
1816 | + security risk. | |
1817 | + For example, when a upper writable branch has a world writable empty | |
1818 | + top directory, a malicious user can create any files on the writable | |
1819 | + branch directly, like copy-up and modify manually. If something like | |
1820 | + /etc/{passwd,shadow} exists on the lower readonly branch but the upper | |
1821 | + writable branch, and the writable branch is world-writable, then a | |
1822 | + malicious guy may create /etc/passwd on the writable branch directly | |
1823 | + and the infected file will be valid in aufs. | |
7e9cd9fe | 1824 | + I am afraid it can be a security issue, but aufs can do nothing except |
53392da6 AM |
1825 | + producing a warning. |
1826 | + | |
1827 | + | |
1828 | +Delete a Branch | |
1829 | +---------------------------------------------------------------------- | |
1830 | +o Confirm the deleting branch is not busy | |
1831 | + To be general, there is one merit to adopt "remount" interface to | |
1832 | + manipulate branches. It is to discard caches. At deleting a branch, | |
1833 | + aufs checks the still cached (and connected) dentries and inodes. If | |
1834 | + there are any, then they are all in-use. An inode without its | |
1835 | + corresponding dentry can be alive alone (for example, inotify/fsnotify case). | |
1836 | + | |
1837 | + For the cached one, aufs checks whether the same named entry exists on | |
1838 | + other branches. | |
1839 | + If the cached one is a directory, because aufs provides a merged view | |
1840 | + to users, as long as one dir is left on any branch aufs can show the | |
1841 | + dir to users. In this case, the branch can be removed from aufs. | |
1842 | + Otherwise aufs rejects deleting the branch. | |
1843 | + | |
1844 | + If any file on the deleting branch is opened by aufs, then aufs | |
1845 | + rejects deleting. | |
1846 | + | |
1847 | + | |
1848 | +Modify the Permission of a Branch | |
1849 | +---------------------------------------------------------------------- | |
1850 | +o Re-initialize or remove the xino file and whiteout bases if necessary. | |
1851 | + See struct.txt. | |
1852 | + | |
1853 | +o rw --> ro: Confirm the modifying branch is not busy | |
1854 | + Aufs rejects the request if any of these conditions are true. | |
1855 | + - a file on the branch is mmap-ed. | |
1856 | + - a regular file on the branch is opened for write and there is no | |
1857 | + same named entry on the upper branch. | |
1858 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt linux/Documentation/filesystems/aufs/design/05wbr_policy.txt | |
eca34b5c | 1859 | --- /usr/share/empty/Documentation/filesystems/aufs/design/05wbr_policy.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1860 | +++ linux/Documentation/filesystems/aufs/design/05wbr_policy.txt 2020-01-27 10:57:18.165538015 +0100 |
523b37e3 | 1861 | @@ -0,0 +1,64 @@ |
53392da6 | 1862 | + |
d58c55f2 | 1863 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
1864 | +# |
1865 | +# This program is free software; you can redistribute it and/or modify | |
1866 | +# it under the terms of the GNU General Public License as published by | |
1867 | +# the Free Software Foundation; either version 2 of the License, or | |
1868 | +# (at your option) any later version. | |
1869 | +# | |
1870 | +# This program is distributed in the hope that it will be useful, | |
1871 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1872 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1873 | +# GNU General Public License for more details. | |
1874 | +# | |
1875 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 1876 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
1877 | + |
1878 | +Policies to Select One among Multiple Writable Branches | |
1879 | +---------------------------------------------------------------------- | |
1880 | +When the number of writable branch is more than one, aufs has to decide | |
1881 | +the target branch for file creation or copy-up. By default, the highest | |
1882 | +writable branch which has the parent (or ancestor) dir of the target | |
1883 | +file is chosen (top-down-parent policy). | |
1884 | +By user's request, aufs implements some other policies to select the | |
7e9cd9fe AM |
1885 | +writable branch, for file creation several policies, round-robin, |
1886 | +most-free-space, and other policies. For copy-up, top-down-parent, | |
1887 | +bottom-up-parent, bottom-up and others. | |
53392da6 AM |
1888 | + |
1889 | +As expected, the round-robin policy selects the branch in circular. When | |
1890 | +you have two writable branches and creates 10 new files, 5 files will be | |
1891 | +created for each branch. mkdir(2) systemcall is an exception. When you | |
1892 | +create 10 new directories, all will be created on the same branch. | |
1893 | +And the most-free-space policy selects the one which has most free | |
1894 | +space among the writable branches. The amount of free space will be | |
1895 | +checked by aufs internally, and users can specify its time interval. | |
1896 | + | |
1897 | +The policies for copy-up is more simple, | |
1898 | +top-down-parent is equivalent to the same named on in create policy, | |
1899 | +bottom-up-parent selects the writable branch where the parent dir | |
1900 | +exists and the nearest upper one from the copyup-source, | |
1901 | +bottom-up selects the nearest upper writable branch from the | |
1902 | +copyup-source, regardless the existence of the parent dir. | |
1903 | + | |
1904 | +There are some rules or exceptions to apply these policies. | |
1905 | +- If there is a readonly branch above the policy-selected branch and | |
1906 | + the parent dir is marked as opaque (a variation of whiteout), or the | |
1907 | + target (creating) file is whiteout-ed on the upper readonly branch, | |
1908 | + then the result of the policy is ignored and the target file will be | |
1909 | + created on the nearest upper writable branch than the readonly branch. | |
1910 | +- If there is a writable branch above the policy-selected branch and | |
1911 | + the parent dir is marked as opaque or the target file is whiteouted | |
1912 | + on the branch, then the result of the policy is ignored and the target | |
1913 | + file will be created on the highest one among the upper writable | |
1914 | + branches who has diropq or whiteout. In case of whiteout, aufs removes | |
1915 | + it as usual. | |
1916 | +- link(2) and rename(2) systemcalls are exceptions in every policy. | |
1917 | + They try selecting the branch where the source exists as possible | |
1918 | + since copyup a large file will take long time. If it can't be, | |
1919 | + ie. the branch where the source exists is readonly, then they will | |
1920 | + follow the copyup policy. | |
1921 | +- There is an exception for rename(2) when the target exists. | |
1922 | + If the rename target exists, aufs compares the index of the branches | |
1923 | + where the source and the target exists and selects the higher | |
1924 | + one. If the selected branch is readonly, then aufs follows the | |
1925 | + copyup policy. | |
8b6a4947 | 1926 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot linux/Documentation/filesystems/aufs/design/06dirren.dot |
eca34b5c AM |
1927 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.dot 1970-01-01 01:00:00.000000000 +0100 |
1928 | +++ linux/Documentation/filesystems/aufs/design/06dirren.dot 2019-07-11 15:42:14.458904362 +0200 | |
8b6a4947 AM |
1929 | @@ -0,0 +1,31 @@ |
1930 | + | |
1931 | +// to view this graph, run dot(1) command in GRAPHVIZ. | |
1932 | + | |
1933 | +digraph G { | |
1934 | +node [shape=box]; | |
1935 | +whinfo [label="detailed info file\n(lower_brid_root-hinum, h_inum, namelen, old name)"]; | |
1936 | + | |
1937 | +node [shape=oval]; | |
1938 | + | |
1939 | +aufs_rename -> whinfo [label="store/remove"]; | |
1940 | + | |
1941 | +node [shape=oval]; | |
1942 | +inode_list [label="h_inum list in branch\ncache"]; | |
1943 | + | |
1944 | +node [shape=box]; | |
1945 | +whinode [label="h_inum list file"]; | |
1946 | + | |
1947 | +node [shape=oval]; | |
1948 | +brmgmt [label="br_add/del/mod/umount"]; | |
1949 | + | |
1950 | +brmgmt -> inode_list [label="create/remove"]; | |
1951 | +brmgmt -> whinode [label="load/store"]; | |
1952 | + | |
1953 | +inode_list -> whinode [style=dashed,dir=both]; | |
1954 | + | |
1955 | +aufs_rename -> inode_list [label="add/del"]; | |
1956 | + | |
1957 | +aufs_lookup -> inode_list [label="search"]; | |
1958 | + | |
1959 | +aufs_lookup -> whinfo [label="load/remove"]; | |
1960 | +} | |
1961 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt linux/Documentation/filesystems/aufs/design/06dirren.txt | |
eca34b5c | 1962 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06dirren.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 1963 | +++ linux/Documentation/filesystems/aufs/design/06dirren.txt 2020-01-27 10:57:18.165538015 +0100 |
8b6a4947 AM |
1964 | @@ -0,0 +1,102 @@ |
1965 | + | |
d58c55f2 | 1966 | +# Copyright (C) 2017-2020 Junjiro R. Okajima |
8b6a4947 AM |
1967 | +# |
1968 | +# This program is free software; you can redistribute it and/or modify | |
1969 | +# it under the terms of the GNU General Public License as published by | |
1970 | +# the Free Software Foundation; either version 2 of the License, or | |
1971 | +# (at your option) any later version. | |
1972 | +# | |
1973 | +# This program is distributed in the hope that it will be useful, | |
1974 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1975 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1976 | +# GNU General Public License for more details. | |
1977 | +# | |
1978 | +# You should have received a copy of the GNU General Public License | |
1979 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
1980 | + | |
1981 | +Special handling for renaming a directory (DIRREN) | |
1982 | +---------------------------------------------------------------------- | |
1983 | +First, let's assume we have a simple usecase. | |
1984 | + | |
1985 | +- /u = /rw + /ro | |
1986 | +- /rw/dirA exists | |
1987 | +- /ro/dirA and /ro/dirA/file exist too | |
1988 | +- there is no dirB on both branches | |
1989 | +- a user issues rename("dirA", "dirB") | |
1990 | + | |
1991 | +Now, what should aufs behave against this rename(2)? | |
1992 | +There are a few possible cases. | |
1993 | + | |
1994 | +A. returns EROFS. | |
1995 | + since dirA exists on a readonly branch which cannot be renamed. | |
1996 | +B. returns EXDEV. | |
1997 | + it is possible to copy-up dirA (only the dir itself), but the child | |
1998 | + entries ("file" in this case) should not be. it must be a bad | |
1999 | + approach to copy-up recursively. | |
2000 | +C. returns a success. | |
2001 | + even the branch /ro is readonly, aufs tries renaming it. Obviously it | |
2002 | + is a violation of aufs' policy. | |
2003 | +D. construct an extra information which indicates that /ro/dirA should | |
2004 | + be handled as the name of dirB. | |
2005 | + overlayfs has a similar feature called REDIRECT. | |
2006 | + | |
2007 | +Until now, aufs implements the case B only which returns EXDEV, and | |
2008 | +expects the userspace application behaves like mv(1) which tries | |
2009 | +issueing rename(2) recursively. | |
2010 | + | |
2011 | +A new aufs feature called DIRREN is introduced which implements the case | |
2012 | +D. There are several "extra information" added. | |
2013 | + | |
2014 | +1. detailed info per renamed directory | |
2015 | + path: /rw/dirB/$AUFS_WH_DR_INFO_PFX.<lower branch-id> | |
2016 | +2. the inode-number list of directories on a branch | |
2017 | + path: /rw/dirB/$AUFS_WH_DR_BRHINO | |
2018 | + | |
2019 | +The filename of "detailed info per directory" represents the lower | |
2020 | +branch, and its format is | |
2021 | +- a type of the branch id | |
2022 | + one of these. | |
2023 | + + uuid (not implemented yet) | |
2024 | + + fsid | |
2025 | + + dev | |
2026 | +- the inode-number of the branch root dir | |
2027 | + | |
2028 | +And it contains these info in a single regular file. | |
2029 | +- magic number | |
2030 | +- branch's inode-number of the logically renamed dir | |
2031 | +- the name of the before-renamed dir | |
2032 | + | |
2033 | +The "detailed info per directory" file is created in aufs rename(2), and | |
2034 | +loaded in any lookup. | |
2035 | +The info is considered in lookup for the matching case only. Here | |
2036 | +"matching" means that the root of branch (in the info filename) is same | |
2037 | +to the current looking-up branch. After looking-up the before-renamed | |
2038 | +name, the inode-number is compared. And the matched dentry is used. | |
2039 | + | |
2040 | +The "inode-number list of directories" is a regular file which contains | |
2041 | +simply the inode-numbers on the branch. The file is created or updated | |
2042 | +in removing the branch, and loaded in adding the branch. Its lifetime is | |
2043 | +equal to the branch. | |
2044 | +The list is refered in lookup, and when the current target inode is | |
2045 | +found in the list, the aufs tries loading the "detailed info per | |
2046 | +directory" and get the changed and valid name of the dir. | |
2047 | + | |
2048 | +Theoretically these "extra informaiton" may be able to be put into XATTR | |
2049 | +in the dir inode. But aufs doesn't choose this way because | |
2050 | +1. XATTR may not be supported by the branch (or its configuration) | |
2051 | +2. XATTR may have its size limit. | |
2052 | +3. XATTR may be less easy to convert than a regular file, when the | |
2053 | + format of the info is changed in the future. | |
2054 | +At the same time, I agree that the regular file approach is much slower | |
2055 | +than XATTR approach. So, in the future, aufs may take the XATTR or other | |
2056 | +better approach. | |
2057 | + | |
2058 | +This DIRREN feature is enabled by aufs configuration, and is activated | |
2059 | +by a new mount option. | |
2060 | + | |
2061 | +For the more complicated case, there is a work with UDBA option, which | |
2062 | +is to dected the direct access to the branches (by-passing aufs) and to | |
2063 | +maintain the cashes in aufs. Since a single cached aufs dentry may | |
2064 | +contains two names, before- and after-rename, the name comparision in | |
2065 | +UDBA handler may not work correctly. In this case, the behaviour will be | |
2066 | +equivalen to udba=reval case. | |
076b876e | 2067 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt linux/Documentation/filesystems/aufs/design/06fhsm.txt |
eca34b5c | 2068 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06fhsm.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2069 | +++ linux/Documentation/filesystems/aufs/design/06fhsm.txt 2020-01-27 10:57:18.165538015 +0100 |
076b876e AM |
2070 | @@ -0,0 +1,120 @@ |
2071 | + | |
d58c55f2 | 2072 | +# Copyright (C) 2011-2020 Junjiro R. Okajima |
076b876e AM |
2073 | +# |
2074 | +# This program is free software; you can redistribute it and/or modify | |
2075 | +# it under the terms of the GNU General Public License as published by | |
2076 | +# the Free Software Foundation; either version 2 of the License, or | |
2077 | +# (at your option) any later version. | |
2078 | +# | |
2079 | +# This program is distributed in the hope that it will be useful, | |
2080 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2081 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2082 | +# GNU General Public License for more details. | |
2083 | +# | |
2084 | +# You should have received a copy of the GNU General Public License | |
2085 | +# along with this program; if not, write to the Free Software | |
2086 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2087 | + | |
2088 | + | |
2089 | +File-based Hierarchical Storage Management (FHSM) | |
2090 | +---------------------------------------------------------------------- | |
2091 | +Hierarchical Storage Management (or HSM) is a well-known feature in the | |
2092 | +storage world. Aufs provides this feature as file-based with multiple | |
7e9cd9fe | 2093 | +writable branches, based upon the principle of "Colder, the Lower". |
076b876e | 2094 | +Here the word "colder" means that the less used files, and "lower" means |
7e9cd9fe | 2095 | +that the position in the order of the stacked branches vertically. |
076b876e AM |
2096 | +These multiple writable branches are prioritized, ie. the topmost one |
2097 | +should be the fastest drive and be used heavily. | |
2098 | + | |
2099 | +o Characters in aufs FHSM story | |
2100 | +- aufs itself and a new branch attribute. | |
2101 | +- a new ioctl interface to move-down and to establish a connection with | |
2102 | + the daemon ("move-down" is a converse of "copy-up"). | |
2103 | +- userspace tool and daemon. | |
2104 | + | |
2105 | +The userspace daemon establishes a connection with aufs and waits for | |
2106 | +the notification. The notified information is very similar to struct | |
2107 | +statfs containing the number of consumed blocks and inodes. | |
2108 | +When the consumed blocks/inodes of a branch exceeds the user-specified | |
2109 | +upper watermark, the daemon activates its move-down process until the | |
2110 | +consumed blocks/inodes reaches the user-specified lower watermark. | |
2111 | + | |
2112 | +The actual move-down is done by aufs based upon the request from | |
2113 | +user-space since we need to maintain the inode number and the internal | |
2114 | +pointer arrays in aufs. | |
2115 | + | |
2116 | +Currently aufs FHSM handles the regular files only. Additionally they | |
2117 | +must not be hard-linked nor pseudo-linked. | |
2118 | + | |
2119 | + | |
2120 | +o Cowork of aufs and the user-space daemon | |
2121 | + During the userspace daemon established the connection, aufs sends a | |
2122 | + small notification to it whenever aufs writes something into the | |
2123 | + writable branch. But it may cost high since aufs issues statfs(2) | |
2124 | + internally. So user can specify a new option to cache the | |
2125 | + info. Actually the notification is controlled by these factors. | |
2126 | + + the specified cache time. | |
2127 | + + classified as "force" by aufs internally. | |
2128 | + Until the specified time expires, aufs doesn't send the info | |
2129 | + except the forced cases. When aufs decide forcing, the info is always | |
2130 | + notified to userspace. | |
2131 | + For example, the number of free inodes is generally large enough and | |
2132 | + the shortage of it happens rarely. So aufs doesn't force the | |
2133 | + notification when creating a new file, directory and others. This is | |
2134 | + the typical case which aufs doesn't force. | |
2135 | + When aufs writes the actual filedata and the files consumes any of new | |
2136 | + blocks, the aufs forces notifying. | |
2137 | + | |
2138 | + | |
2139 | +o Interfaces in aufs | |
2140 | +- New branch attribute. | |
2141 | + + fhsm | |
2142 | + Specifies that the branch is managed by FHSM feature. In other word, | |
2143 | + participant in the FHSM. | |
2144 | + When nofhsm is set to the branch, it will not be the source/target | |
2145 | + branch of the move-down operation. This attribute is set | |
2146 | + independently from coo and moo attributes, and if you want full | |
2147 | + FHSM, you should specify them as well. | |
2148 | +- New mount option. | |
2149 | + + fhsm_sec | |
2150 | + Specifies a second to suppress many less important info to be | |
2151 | + notified. | |
2152 | +- New ioctl. | |
2153 | + + AUFS_CTL_FHSM_FD | |
2154 | + create a new file descriptor which userspace can read the notification | |
2155 | + (a subset of struct statfs) from aufs. | |
2156 | +- Module parameter 'brs' | |
2157 | + It has to be set to 1. Otherwise the new mount option 'fhsm' will not | |
2158 | + be set. | |
2159 | +- mount helpers /sbin/mount.aufs and /sbin/umount.aufs | |
2160 | + When there are two or more branches with fhsm attributes, | |
2161 | + /sbin/mount.aufs invokes the user-space daemon and /sbin/umount.aufs | |
2162 | + terminates it. As a result of remounting and branch-manipulation, the | |
2163 | + number of branches with fhsm attribute can be one. In this case, | |
2164 | + /sbin/mount.aufs will terminate the user-space daemon. | |
2165 | + | |
2166 | + | |
2167 | +Finally the operation is done as these steps in kernel-space. | |
2168 | +- make sure that, | |
2169 | + + no one else is using the file. | |
2170 | + + the file is not hard-linked. | |
2171 | + + the file is not pseudo-linked. | |
2172 | + + the file is a regular file. | |
2173 | + + the parent dir is not opaqued. | |
2174 | +- find the target writable branch. | |
2175 | +- make sure the file is not whiteout-ed by the upper (than the target) | |
2176 | + branch. | |
2177 | +- make the parent dir on the target branch. | |
2178 | +- mutex lock the inode on the branch. | |
2179 | +- unlink the whiteout on the target branch (if exists). | |
2180 | +- lookup and create the whiteout-ed temporary name on the target branch. | |
2181 | +- copy the file as the whiteout-ed temporary name on the target branch. | |
2182 | +- rename the whiteout-ed temporary name to the original name. | |
2183 | +- unlink the file on the source branch. | |
2184 | +- maintain the internal pointer array and the external inode number | |
2185 | + table (XINO). | |
2186 | +- maintain the timestamps and other attributes of the parent dir and the | |
2187 | + file. | |
2188 | + | |
2189 | +And of course, in every step, an error may happen. So the operation | |
2190 | +should restore the original file state after an error happens. | |
53392da6 | 2191 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt linux/Documentation/filesystems/aufs/design/06mmap.txt |
eca34b5c | 2192 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06mmap.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2193 | +++ linux/Documentation/filesystems/aufs/design/06mmap.txt 2020-01-27 10:57:18.165538015 +0100 |
b912730e | 2194 | @@ -0,0 +1,72 @@ |
53392da6 | 2195 | + |
d58c55f2 | 2196 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
2197 | +# |
2198 | +# This program is free software; you can redistribute it and/or modify | |
2199 | +# it under the terms of the GNU General Public License as published by | |
2200 | +# the Free Software Foundation; either version 2 of the License, or | |
2201 | +# (at your option) any later version. | |
2202 | +# | |
2203 | +# This program is distributed in the hope that it will be useful, | |
2204 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2205 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2206 | +# GNU General Public License for more details. | |
2207 | +# | |
2208 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2209 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2210 | + |
2211 | +mmap(2) -- File Memory Mapping | |
2212 | +---------------------------------------------------------------------- | |
2213 | +In aufs, the file-mapped pages are handled by a branch fs directly, no | |
2214 | +interaction with aufs. It means aufs_mmap() calls the branch fs's | |
2215 | +->mmap(). | |
2216 | +This approach is simple and good, but there is one problem. | |
7e9cd9fe | 2217 | +Under /proc, several entries show the mmapped files by its path (with |
53392da6 AM |
2218 | +device and inode number), and the printed path will be the path on the |
2219 | +branch fs's instead of virtual aufs's. | |
2220 | +This is not a problem in most cases, but some utilities lsof(1) (and its | |
2221 | +user) may expect the path on aufs. | |
2222 | + | |
2223 | +To address this issue, aufs adds a new member called vm_prfile in struct | |
2224 | +vm_area_struct (and struct vm_region). The original vm_file points to | |
2225 | +the file on the branch fs in order to handle everything correctly as | |
2226 | +usual. The new vm_prfile points to a virtual file in aufs, and the | |
2227 | +show-functions in procfs refers to vm_prfile if it is set. | |
2228 | +Also we need to maintain several other places where touching vm_file | |
2229 | +such like | |
2230 | +- fork()/clone() copies vma and the reference count of vm_file is | |
2231 | + incremented. | |
2232 | +- merging vma maintains the ref count too. | |
2233 | + | |
7e9cd9fe | 2234 | +This is not a good approach. It just fakes the printed path. But it |
53392da6 AM |
2235 | +leaves all behaviour around f_mapping unchanged. This is surely an |
2236 | +advantage. | |
2237 | +Actually aufs had adopted another complicated approach which calls | |
2238 | +generic_file_mmap() and handles struct vm_operations_struct. In this | |
2239 | +approach, aufs met a hard problem and I could not solve it without | |
2240 | +switching the approach. | |
b912730e AM |
2241 | + |
2242 | +There may be one more another approach which is | |
2243 | +- bind-mount the branch-root onto the aufs-root internally | |
2244 | +- grab the new vfsmount (ie. struct mount) | |
2245 | +- lazy-umount the branch-root internally | |
2246 | +- in open(2) the aufs-file, open the branch-file with the hidden | |
2247 | + vfsmount (instead of the original branch's vfsmount) | |
2248 | +- ideally this "bind-mount and lazy-umount" should be done atomically, | |
2249 | + but it may be possible from userspace by the mount helper. | |
2250 | + | |
2251 | +Adding the internal hidden vfsmount and using it in opening a file, the | |
2252 | +file path under /proc will be printed correctly. This approach looks | |
2253 | +smarter, but is not possible I am afraid. | |
2254 | +- aufs-root may be bind-mount later. when it happens, another hidden | |
2255 | + vfsmount will be required. | |
2256 | +- it is hard to get the chance to bind-mount and lazy-umount | |
2257 | + + in kernel-space, FS can have vfsmount in open(2) via | |
2258 | + file->f_path, and aufs can know its vfsmount. But several locks are | |
2259 | + already acquired, and if aufs tries to bind-mount and lazy-umount | |
2260 | + here, then it may cause a deadlock. | |
2261 | + + in user-space, bind-mount doesn't invoke the mount helper. | |
2262 | +- since /proc shows dev and ino, aufs has to give vma these info. it | |
2263 | + means a new member vm_prinode will be necessary. this is essentially | |
2264 | + equivalent to vm_prfile described above. | |
2265 | + | |
2266 | +I have to give up this "looks-smater" approach. | |
c1595e42 | 2267 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt linux/Documentation/filesystems/aufs/design/06xattr.txt |
eca34b5c | 2268 | --- /usr/share/empty/Documentation/filesystems/aufs/design/06xattr.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2269 | +++ linux/Documentation/filesystems/aufs/design/06xattr.txt 2020-01-27 10:57:18.165538015 +0100 |
c1595e42 JR |
2270 | @@ -0,0 +1,96 @@ |
2271 | + | |
d58c55f2 | 2272 | +# Copyright (C) 2014-2020 Junjiro R. Okajima |
c1595e42 JR |
2273 | +# |
2274 | +# This program is free software; you can redistribute it and/or modify | |
2275 | +# it under the terms of the GNU General Public License as published by | |
2276 | +# the Free Software Foundation; either version 2 of the License, or | |
2277 | +# (at your option) any later version. | |
2278 | +# | |
2279 | +# This program is distributed in the hope that it will be useful, | |
2280 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2281 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2282 | +# GNU General Public License for more details. | |
2283 | +# | |
2284 | +# You should have received a copy of the GNU General Public License | |
2285 | +# along with this program; if not, write to the Free Software | |
2286 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
2287 | + | |
2288 | + | |
2289 | +Listing XATTR/EA and getting the value | |
2290 | +---------------------------------------------------------------------- | |
2291 | +For the inode standard attributes (owner, group, timestamps, etc.), aufs | |
2292 | +shows the values from the topmost existing file. This behaviour is good | |
7e9cd9fe | 2293 | +for the non-dir entries since the bahaviour exactly matches the shown |
c1595e42 JR |
2294 | +information. But for the directories, aufs considers all the same named |
2295 | +entries on the lower branches. Which means, if one of the lower entry | |
2296 | +rejects readdir call, then aufs returns an error even if the topmost | |
2297 | +entry allows it. This behaviour is necessary to respect the branch fs's | |
2298 | +security, but can make users confused since the user-visible standard | |
2299 | +attributes don't match the behaviour. | |
2300 | +To address this issue, aufs has a mount option called dirperm1 which | |
2301 | +checks the permission for the topmost entry only, and ignores the lower | |
2302 | +entry's permission. | |
2303 | + | |
2304 | +A similar issue can happen around XATTR. | |
2305 | +getxattr(2) and listxattr(2) families behave as if dirperm1 option is | |
7e9cd9fe AM |
2306 | +always set. Otherwise these very unpleasant situation would happen. |
2307 | +- listxattr(2) may return the duplicated entries. | |
c1595e42 JR |
2308 | +- users may not be able to remove or reset the XATTR forever, |
2309 | + | |
2310 | + | |
2311 | +XATTR/EA support in the internal (copy,move)-(up,down) | |
2312 | +---------------------------------------------------------------------- | |
7e9cd9fe | 2313 | +Generally the extended attributes of inode are categorized as these. |
c1595e42 JR |
2314 | +- "security" for LSM and capability. |
2315 | +- "system" for posix ACL, 'acl' mount option is required for the branch | |
2316 | + fs generally. | |
2317 | +- "trusted" for userspace, CAP_SYS_ADMIN is required. | |
2318 | +- "user" for userspace, 'user_xattr' mount option is required for the | |
2319 | + branch fs generally. | |
2320 | + | |
2321 | +Moreover there are some other categories. Aufs handles these rather | |
2322 | +unpopular categories as the ordinary ones, ie. there is no special | |
2323 | +condition nor exception. | |
2324 | + | |
2325 | +In copy-up, the support for XATTR on the dst branch may differ from the | |
2326 | +src branch. In this case, the copy-up operation will get an error and | |
7e9cd9fe AM |
2327 | +the original user operation which triggered the copy-up will fail. It |
2328 | +can happen that even all copy-up will fail. | |
c1595e42 JR |
2329 | +When both of src and dst branches support XATTR and if an error occurs |
2330 | +during copying XATTR, then the copy-up should fail obviously. That is a | |
2331 | +good reason and aufs should return an error to userspace. But when only | |
7e9cd9fe | 2332 | +the src branch support that XATTR, aufs should not return an error. |
c1595e42 JR |
2333 | +For example, the src branch supports ACL but the dst branch doesn't |
2334 | +because the dst branch may natively un-support it or temporary | |
2335 | +un-support it due to "noacl" mount option. Of course, the dst branch fs | |
2336 | +may NOT return an error even if the XATTR is not supported. It is | |
2337 | +totally up to the branch fs. | |
2338 | + | |
2339 | +Anyway when the aufs internal copy-up gets an error from the dst branch | |
2340 | +fs, then aufs tries removing the just copied entry and returns the error | |
2341 | +to the userspace. The worst case of this situation will be all copy-up | |
2342 | +will fail. | |
2343 | + | |
2344 | +For the copy-up operation, there two basic approaches. | |
2345 | +- copy the specified XATTR only (by category above), and return the | |
7e9cd9fe | 2346 | + error unconditionally if it happens. |
c1595e42 JR |
2347 | +- copy all XATTR, and ignore the error on the specified category only. |
2348 | + | |
2349 | +In order to support XATTR and to implement the correct behaviour, aufs | |
7e9cd9fe AM |
2350 | +chooses the latter approach and introduces some new branch attributes, |
2351 | +"icexsec", "icexsys", "icextr", "icexusr", and "icexoth". | |
c1595e42 | 2352 | +They correspond to the XATTR namespaces (see above). Additionally, to be |
7e9cd9fe AM |
2353 | +convenient, "icex" is also provided which means all "icex*" attributes |
2354 | +are set (here the word "icex" stands for "ignore copy-error on XATTR"). | |
c1595e42 JR |
2355 | + |
2356 | +The meaning of these attributes is to ignore the error from setting | |
2357 | +XATTR on that branch. | |
2358 | +Note that aufs tries copying all XATTR unconditionally, and ignores the | |
2359 | +error from the dst branch according to the specified attributes. | |
2360 | + | |
2361 | +Some XATTR may have its default value. The default value may come from | |
2362 | +the parent dir or the environment. If the default value is set at the | |
2363 | +file creating-time, it will be overwritten by copy-up. | |
2364 | +Some contradiction may happen I am afraid. | |
2365 | +Do we need another attribute to stop copying XATTR? I am unsure. For | |
2366 | +now, aufs implements the branch attributes to ignore the error. | |
53392da6 | 2367 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt linux/Documentation/filesystems/aufs/design/07export.txt |
eca34b5c | 2368 | --- /usr/share/empty/Documentation/filesystems/aufs/design/07export.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2369 | +++ linux/Documentation/filesystems/aufs/design/07export.txt 2020-01-27 10:57:18.165538015 +0100 |
523b37e3 | 2370 | @@ -0,0 +1,58 @@ |
53392da6 | 2371 | + |
d58c55f2 | 2372 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
2373 | +# |
2374 | +# This program is free software; you can redistribute it and/or modify | |
2375 | +# it under the terms of the GNU General Public License as published by | |
2376 | +# the Free Software Foundation; either version 2 of the License, or | |
2377 | +# (at your option) any later version. | |
2378 | +# | |
2379 | +# This program is distributed in the hope that it will be useful, | |
2380 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2381 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2382 | +# GNU General Public License for more details. | |
2383 | +# | |
2384 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2385 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2386 | + |
2387 | +Export Aufs via NFS | |
2388 | +---------------------------------------------------------------------- | |
2389 | +Here is an approach. | |
2390 | +- like xino/xib, add a new file 'xigen' which stores aufs inode | |
2391 | + generation. | |
2392 | +- iget_locked(): initialize aufs inode generation for a new inode, and | |
2393 | + store it in xigen file. | |
2394 | +- destroy_inode(): increment aufs inode generation and store it in xigen | |
2395 | + file. it is necessary even if it is not unlinked, because any data of | |
2396 | + inode may be changed by UDBA. | |
2397 | +- encode_fh(): for a root dir, simply return FILEID_ROOT. otherwise | |
2398 | + build file handle by | |
2399 | + + branch id (4 bytes) | |
2400 | + + superblock generation (4 bytes) | |
2401 | + + inode number (4 or 8 bytes) | |
2402 | + + parent dir inode number (4 or 8 bytes) | |
2403 | + + inode generation (4 bytes)) | |
2404 | + + return value of exportfs_encode_fh() for the parent on a branch (4 | |
2405 | + bytes) | |
2406 | + + file handle for a branch (by exportfs_encode_fh()) | |
2407 | +- fh_to_dentry(): | |
2408 | + + find the index of a branch from its id in handle, and check it is | |
2409 | + still exist in aufs. | |
2410 | + + 1st level: get the inode number from handle and search it in cache. | |
7e9cd9fe AM |
2411 | + + 2nd level: if not found in cache, get the parent inode number from |
2412 | + the handle and search it in cache. and then open the found parent | |
2413 | + dir, find the matching inode number by vfs_readdir() and get its | |
2414 | + name, and call lookup_one_len() for the target dentry. | |
53392da6 AM |
2415 | + + 3rd level: if the parent dir is not cached, call |
2416 | + exportfs_decode_fh() for a branch and get the parent on a branch, | |
2417 | + build a pathname of it, convert it a pathname in aufs, call | |
2418 | + path_lookup(). now aufs gets a parent dir dentry, then handle it as | |
2419 | + the 2nd level. | |
2420 | + + to open the dir, aufs needs struct vfsmount. aufs keeps vfsmount | |
2421 | + for every branch, but not itself. to get this, (currently) aufs | |
2422 | + searches in current->nsproxy->mnt_ns list. it may not be a good | |
2423 | + idea, but I didn't get other approach. | |
2424 | + + test the generation of the gotten inode. | |
2425 | +- every inode operation: they may get EBUSY due to UDBA. in this case, | |
2426 | + convert it into ESTALE for NFSD. | |
2427 | +- readdir(): call lockdep_on/off() because filldir in NFSD calls | |
2428 | + lookup_one_len(), vfs_getattr(), encode_fh() and others. | |
2429 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt linux/Documentation/filesystems/aufs/design/08shwh.txt | |
eca34b5c | 2430 | --- /usr/share/empty/Documentation/filesystems/aufs/design/08shwh.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2431 | +++ linux/Documentation/filesystems/aufs/design/08shwh.txt 2020-01-27 10:57:18.165538015 +0100 |
523b37e3 | 2432 | @@ -0,0 +1,52 @@ |
53392da6 | 2433 | + |
d58c55f2 | 2434 | +# Copyright (C) 2005-2020 Junjiro R. Okajima |
53392da6 AM |
2435 | +# |
2436 | +# This program is free software; you can redistribute it and/or modify | |
2437 | +# it under the terms of the GNU General Public License as published by | |
2438 | +# the Free Software Foundation; either version 2 of the License, or | |
2439 | +# (at your option) any later version. | |
2440 | +# | |
2441 | +# This program is distributed in the hope that it will be useful, | |
2442 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2443 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2444 | +# GNU General Public License for more details. | |
2445 | +# | |
2446 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2447 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2448 | + |
2449 | +Show Whiteout Mode (shwh) | |
2450 | +---------------------------------------------------------------------- | |
2451 | +Generally aufs hides the name of whiteouts. But in some cases, to show | |
2452 | +them is very useful for users. For instance, creating a new middle layer | |
2453 | +(branch) by merging existing layers. | |
2454 | + | |
2455 | +(borrowing aufs1 HOW-TO from a user, Michael Towers) | |
2456 | +When you have three branches, | |
2457 | +- Bottom: 'system', squashfs (underlying base system), read-only | |
2458 | +- Middle: 'mods', squashfs, read-only | |
2459 | +- Top: 'overlay', ram (tmpfs), read-write | |
2460 | + | |
2461 | +The top layer is loaded at boot time and saved at shutdown, to preserve | |
2462 | +the changes made to the system during the session. | |
2463 | +When larger changes have been made, or smaller changes have accumulated, | |
2464 | +the size of the saved top layer data grows. At this point, it would be | |
2465 | +nice to be able to merge the two overlay branches ('mods' and 'overlay') | |
2466 | +and rewrite the 'mods' squashfs, clearing the top layer and thus | |
2467 | +restoring save and load speed. | |
2468 | + | |
2469 | +This merging is simplified by the use of another aufs mount, of just the | |
2470 | +two overlay branches using the 'shwh' option. | |
2471 | +# mount -t aufs -o ro,shwh,br:/livesys/overlay=ro+wh:/livesys/mods=rr+wh \ | |
2472 | + aufs /livesys/merge_union | |
2473 | + | |
2474 | +A merged view of these two branches is then available at | |
2475 | +/livesys/merge_union, and the new feature is that the whiteouts are | |
2476 | +visible! | |
2477 | +Note that in 'shwh' mode the aufs mount must be 'ro', which will disable | |
2478 | +writing to all branches. Also the default mode for all branches is 'ro'. | |
2479 | +It is now possible to save the combined contents of the two overlay | |
2480 | +branches to a new squashfs, e.g.: | |
2481 | +# mksquashfs /livesys/merge_union /path/to/newmods.squash | |
2482 | + | |
2483 | +This new squashfs archive can be stored on the boot device and the | |
2484 | +initramfs will use it to replace the old one at the next boot. | |
2485 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt linux/Documentation/filesystems/aufs/design/10dynop.txt | |
eca34b5c | 2486 | --- /usr/share/empty/Documentation/filesystems/aufs/design/10dynop.txt 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2487 | +++ linux/Documentation/filesystems/aufs/design/10dynop.txt 2020-01-27 10:57:18.165538015 +0100 |
7e9cd9fe | 2488 | @@ -0,0 +1,47 @@ |
53392da6 | 2489 | + |
d58c55f2 | 2490 | +# Copyright (C) 2010-2020 Junjiro R. Okajima |
53392da6 AM |
2491 | +# |
2492 | +# This program is free software; you can redistribute it and/or modify | |
2493 | +# it under the terms of the GNU General Public License as published by | |
2494 | +# the Free Software Foundation; either version 2 of the License, or | |
2495 | +# (at your option) any later version. | |
2496 | +# | |
2497 | +# This program is distributed in the hope that it will be useful, | |
2498 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2499 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2500 | +# GNU General Public License for more details. | |
2501 | +# | |
2502 | +# You should have received a copy of the GNU General Public License | |
523b37e3 | 2503 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
53392da6 AM |
2504 | + |
2505 | +Dynamically customizable FS operations | |
2506 | +---------------------------------------------------------------------- | |
2507 | +Generally FS operations (struct inode_operations, struct | |
2508 | +address_space_operations, struct file_operations, etc.) are defined as | |
2509 | +"static const", but it never means that FS have only one set of | |
2510 | +operation. Some FS have multiple sets of them. For instance, ext2 has | |
2511 | +three sets, one for XIP, for NOBH, and for normal. | |
2512 | +Since aufs overrides and redirects these operations, sometimes aufs has | |
7e9cd9fe | 2513 | +to change its behaviour according to the branch FS type. More importantly |
53392da6 AM |
2514 | +VFS acts differently if a function (member in the struct) is set or |
2515 | +not. It means aufs should have several sets of operations and select one | |
2516 | +among them according to the branch FS definition. | |
2517 | + | |
7e9cd9fe | 2518 | +In order to solve this problem and not to affect the behaviour of VFS, |
53392da6 | 2519 | +aufs defines these operations dynamically. For instance, aufs defines |
7e9cd9fe AM |
2520 | +dummy direct_IO function for struct address_space_operations, but it may |
2521 | +not be set to the address_space_operations actually. When the branch FS | |
2522 | +doesn't have it, aufs doesn't set it to its address_space_operations | |
2523 | +while the function definition itself is still alive. So the behaviour | |
2524 | +itself will not change, and it will return an error when direct_IO is | |
2525 | +not set. | |
53392da6 AM |
2526 | + |
2527 | +The lifetime of these dynamically generated operation object is | |
2528 | +maintained by aufs branch object. When the branch is removed from aufs, | |
2529 | +the reference counter of the object is decremented. When it reaches | |
2530 | +zero, the dynamically generated operation object will be freed. | |
2531 | + | |
7e9cd9fe AM |
2532 | +This approach is designed to support AIO (io_submit), Direct I/O and |
2533 | +XIP (DAX) mainly. | |
2534 | +Currently this approach is applied to address_space_operations for | |
2535 | +regular files only. | |
53392da6 | 2536 | diff -urN /usr/share/empty/Documentation/filesystems/aufs/README linux/Documentation/filesystems/aufs/README |
eca34b5c | 2537 | --- /usr/share/empty/Documentation/filesystems/aufs/README 1970-01-01 01:00:00.000000000 +0100 |
43982f53 AM |
2538 | +++ linux/Documentation/filesystems/aufs/README 2020-01-23 09:59:36.748660743 +0100 |
2539 | @@ -0,0 +1,401 @@ | |
53392da6 | 2540 | + |
fbc438ed | 2541 | +Aufs5 -- advanced multi layered unification filesystem version 5.x |
53392da6 AM |
2542 | +http://aufs.sf.net |
2543 | +Junjiro R. Okajima | |
2544 | + | |
2545 | + | |
2546 | +0. Introduction | |
2547 | +---------------------------------------- | |
2548 | +In the early days, aufs was entirely re-designed and re-implemented | |
7e9cd9fe | 2549 | +Unionfs Version 1.x series. Adding many original ideas, approaches, |
fbc438ed | 2550 | +improvements and implementations, it became totally different from |
53392da6 | 2551 | +Unionfs while keeping the basic features. |
fbc438ed | 2552 | +Later, Unionfs Version 2.x series began taking some of the same |
53392da6 | 2553 | +approaches to aufs1's. |
fbc438ed | 2554 | +Unionfs was being developed by Professor Erez Zadok at Stony Brook |
53392da6 AM |
2555 | +University and his team. |
2556 | + | |
fbc438ed JR |
2557 | +Aufs5 supports linux-v5.0 and later, If you want older kernel version |
2558 | +support, | |
2559 | +- for linux-v4.x series, try aufs4-linux.git or aufs4-standalone.git | |
2560 | +- for linux-v3.x series, try aufs3-linux.git or aufs3-standalone.git | |
2561 | +- for linux-v2.6.16 and later, try aufs2-2.6.git, aufs2-standalone.git | |
2562 | + or aufs1 from CVS on SourceForge. | |
53392da6 AM |
2563 | + |
2564 | +Note: it becomes clear that "Aufs was rejected. Let's give it up." | |
38d290e6 JR |
2565 | + According to Christoph Hellwig, linux rejects all union-type |
2566 | + filesystems but UnionMount. | |
53392da6 AM |
2567 | +<http://marc.info/?l=linux-kernel&m=123938533724484&w=2> |
2568 | + | |
38d290e6 JR |
2569 | +PS. Al Viro seems have a plan to merge aufs as well as overlayfs and |
2570 | + UnionMount, and he pointed out an issue around a directory mutex | |
2571 | + lock and aufs addressed it. But it is still unsure whether aufs will | |
2572 | + be merged (or any other union solution). | |
076b876e | 2573 | +<http://marc.info/?l=linux-kernel&m=136312705029295&w=1> |
38d290e6 | 2574 | + |
53392da6 AM |
2575 | + |
2576 | +1. Features | |
2577 | +---------------------------------------- | |
2578 | +- unite several directories into a single virtual filesystem. The member | |
2579 | + directory is called as a branch. | |
2580 | +- you can specify the permission flags to the branch, which are 'readonly', | |
2581 | + 'readwrite' and 'whiteout-able.' | |
2582 | +- by upper writable branch, internal copyup and whiteout, files/dirs on | |
2583 | + readonly branch are modifiable logically. | |
2584 | +- dynamic branch manipulation, add, del. | |
2585 | +- etc... | |
2586 | + | |
7e9cd9fe AM |
2587 | +Also there are many enhancements in aufs, such as: |
2588 | +- test only the highest one for the directory permission (dirperm1) | |
2589 | +- copyup on open (coo=) | |
2590 | +- 'move' policy for copy-up between two writable branches, after | |
2591 | + checking free space. | |
2592 | +- xattr, acl | |
53392da6 AM |
2593 | +- readdir(3) in userspace. |
2594 | +- keep inode number by external inode number table | |
2595 | +- keep the timestamps of file/dir in internal copyup operation | |
2596 | +- seekable directory, supporting NFS readdir. | |
2597 | +- whiteout is hardlinked in order to reduce the consumption of inodes | |
2598 | + on branch | |
2599 | +- do not copyup, nor create a whiteout when it is unnecessary | |
2600 | +- revert a single systemcall when an error occurs in aufs | |
2601 | +- remount interface instead of ioctl | |
2602 | +- maintain /etc/mtab by an external command, /sbin/mount.aufs. | |
2603 | +- loopback mounted filesystem as a branch | |
2604 | +- kernel thread for removing the dir who has a plenty of whiteouts | |
2605 | +- support copyup sparse file (a file which has a 'hole' in it) | |
2606 | +- default permission flags for branches | |
2607 | +- selectable permission flags for ro branch, whether whiteout can | |
2608 | + exist or not | |
2609 | +- export via NFS. | |
2610 | +- support <sysfs>/fs/aufs and <debugfs>/aufs. | |
2611 | +- support multiple writable branches, some policies to select one | |
2612 | + among multiple writable branches. | |
2613 | +- a new semantics for link(2) and rename(2) to support multiple | |
2614 | + writable branches. | |
2615 | +- no glibc changes are required. | |
2616 | +- pseudo hardlink (hardlink over branches) | |
2617 | +- allow a direct access manually to a file on branch, e.g. bypassing aufs. | |
2618 | + including NFS or remote filesystem branch. | |
2619 | +- userspace wrapper for pathconf(3)/fpathconf(3) with _PC_LINK_MAX. | |
2620 | +- and more... | |
2621 | + | |
fbc438ed | 2622 | +Currently these features are dropped temporary from aufs5. |
53392da6 | 2623 | +See design/08plan.txt in detail. |
53392da6 AM |
2624 | +- nested mount, i.e. aufs as readonly no-whiteout branch of another aufs |
2625 | + (robr) | |
2626 | +- statistics of aufs thread (/sys/fs/aufs/stat) | |
53392da6 AM |
2627 | + |
2628 | +Features or just an idea in the future (see also design/*.txt), | |
2629 | +- reorder the branch index without del/re-add. | |
2630 | +- permanent xino files for NFSD | |
2631 | +- an option for refreshing the opened files after add/del branches | |
53392da6 AM |
2632 | +- light version, without branch manipulation. (unnecessary?) |
2633 | +- copyup in userspace | |
2634 | +- inotify in userspace | |
2635 | +- readv/writev | |
53392da6 AM |
2636 | + |
2637 | + | |
2638 | +2. Download | |
2639 | +---------------------------------------- | |
fbc438ed JR |
2640 | +There are three GIT trees for aufs5, aufs5-linux.git, |
2641 | +aufs5-standalone.git, and aufs-util.git. Note that there is no "5" in | |
1e00d052 | 2642 | +"aufs-util.git." |
fbc438ed JR |
2643 | +While the aufs-util is always necessary, you need either of aufs5-linux |
2644 | +or aufs5-standalone. | |
1e00d052 | 2645 | + |
fbc438ed | 2646 | +The aufs5-linux tree includes the whole linux mainline GIT tree, |
1e00d052 AM |
2647 | +git://git.kernel.org/.../torvalds/linux.git. |
2648 | +And you cannot select CONFIG_AUFS_FS=m for this version, eg. you cannot | |
fbc438ed | 2649 | +build aufs5 as an external kernel module. |
2000de60 | 2650 | +Several extra patches are not included in this tree. Only |
fbc438ed | 2651 | +aufs5-standalone tree contains them. They are described in the later |
2000de60 | 2652 | +section "Configuration and Compilation." |
1e00d052 | 2653 | + |
fbc438ed | 2654 | +On the other hand, the aufs5-standalone tree has only aufs source files |
53392da6 | 2655 | +and necessary patches, and you can select CONFIG_AUFS_FS=m. |
2000de60 | 2656 | +But you need to apply all aufs patches manually. |
53392da6 | 2657 | + |
fbc438ed JR |
2658 | +You will find GIT branches whose name is in form of "aufs5.x" where "x" |
2659 | +represents the linux kernel version, "linux-5.x". For instance, | |
2660 | +"aufs5.0" is for linux-5.0. For latest "linux-5.x-rcN", use | |
2661 | +"aufs5.x-rcN" branch. | |
1e00d052 | 2662 | + |
fbc438ed | 2663 | +o aufs5-linux tree |
1e00d052 | 2664 | +$ git clone --reference /your/linux/git/tree \ |
fbc438ed | 2665 | + git://github.com/sfjro/aufs5-linux.git aufs5-linux.git |
1e00d052 | 2666 | +- if you don't have linux GIT tree, then remove "--reference ..." |
fbc438ed JR |
2667 | +$ cd aufs5-linux.git |
2668 | +$ git checkout origin/aufs5.0 | |
53392da6 | 2669 | + |
2000de60 JR |
2670 | +Or You may want to directly git-pull aufs into your linux GIT tree, and |
2671 | +leave the patch-work to GIT. | |
2672 | +$ cd /your/linux/git/tree | |
fbc438ed JR |
2673 | +$ git remote add aufs5 git://github.com/sfjro/aufs5-linux.git |
2674 | +$ git fetch aufs5 | |
2675 | +$ git checkout -b my5.0 v5.0 | |
5527c038 | 2676 | +$ (add your local change...) |
fbc438ed JR |
2677 | +$ git pull aufs5 aufs5.0 |
2678 | +- now you have v5.0 + your_changes + aufs5.0 in you my5.0 branch. | |
2000de60 | 2679 | +- you may need to solve some conflicts between your_changes and |
fbc438ed JR |
2680 | + aufs5.0. in this case, git-rerere is recommended so that you can |
2681 | + solve the similar conflicts automatically when you upgrade to 5.1 or | |
2000de60 JR |
2682 | + later in the future. |
2683 | + | |
fbc438ed JR |
2684 | +o aufs5-standalone tree |
2685 | +$ git clone git://github.com/sfjro/aufs5-standalone.git aufs5-standalone.git | |
2686 | +$ cd aufs5-standalone.git | |
2687 | +$ git checkout origin/aufs5.0 | |
53392da6 AM |
2688 | + |
2689 | +o aufs-util tree | |
5527c038 JR |
2690 | +$ git clone git://git.code.sf.net/p/aufs/aufs-util aufs-util.git |
2691 | +- note that the public aufs-util.git is on SourceForge instead of | |
2692 | + GitHUB. | |
53392da6 | 2693 | +$ cd aufs-util.git |
fbc438ed | 2694 | +$ git checkout origin/aufs5.0 |
53392da6 | 2695 | + |
fbc438ed JR |
2696 | +Note: The 5.x-rcN branch is to be used with `rc' kernel versions ONLY. |
2697 | +The minor version number, 'x' in '5.x', of aufs may not always | |
9dbd164d AM |
2698 | +follow the minor version number of the kernel. |
2699 | +Because changes in the kernel that cause the use of a new | |
2700 | +minor version number do not always require changes to aufs-util. | |
2701 | + | |
2702 | +Since aufs-util has its own minor version number, you may not be | |
2703 | +able to find a GIT branch in aufs-util for your kernel's | |
2704 | +exact minor version number. | |
2705 | +In this case, you should git-checkout the branch for the | |
53392da6 | 2706 | +nearest lower number. |
9dbd164d AM |
2707 | + |
2708 | +For (an unreleased) example: | |
fbc438ed JR |
2709 | +If you are using "linux-5.10" and the "aufs5.10" branch |
2710 | +does not exist in aufs-util repository, then "aufs5.9", "aufs5.8" | |
9dbd164d AM |
2711 | +or something numerically smaller is the branch for your kernel. |
2712 | + | |
53392da6 AM |
2713 | +Also you can view all branches by |
2714 | + $ git branch -a | |
2715 | + | |
2716 | + | |
2717 | +3. Configuration and Compilation | |
2718 | +---------------------------------------- | |
2719 | +Make sure you have git-checkout'ed the correct branch. | |
2720 | + | |
fbc438ed | 2721 | +For aufs5-linux tree, |
c06a8ce3 | 2722 | +- enable CONFIG_AUFS_FS. |
1e00d052 AM |
2723 | +- set other aufs configurations if necessary. |
2724 | + | |
fbc438ed | 2725 | +For aufs5-standalone tree, |
53392da6 AM |
2726 | +There are several ways to build. |
2727 | + | |
2728 | +1. | |
fbc438ed JR |
2729 | +- apply ./aufs5-kbuild.patch to your kernel source files. |
2730 | +- apply ./aufs5-base.patch too. | |
2731 | +- apply ./aufs5-mmap.patch too. | |
2732 | +- apply ./aufs5-standalone.patch too, if you have a plan to set | |
2733 | + CONFIG_AUFS_FS=m. otherwise you don't need ./aufs5-standalone.patch. | |
537831f9 AM |
2734 | +- copy ./{Documentation,fs,include/uapi/linux/aufs_type.h} files to your |
2735 | + kernel source tree. Never copy $PWD/include/uapi/linux/Kbuild. | |
c06a8ce3 | 2736 | +- enable CONFIG_AUFS_FS, you can select either |
53392da6 AM |
2737 | + =m or =y. |
2738 | +- and build your kernel as usual. | |
2739 | +- install the built kernel. | |
7eafdf33 AM |
2740 | +- install the header files too by "make headers_install" to the |
2741 | + directory where you specify. By default, it is $PWD/usr. | |
b4510431 | 2742 | + "make help" shows a brief note for headers_install. |
53392da6 AM |
2743 | +- and reboot your system. |
2744 | + | |
2745 | +2. | |
2746 | +- module only (CONFIG_AUFS_FS=m). | |
fbc438ed JR |
2747 | +- apply ./aufs5-base.patch to your kernel source files. |
2748 | +- apply ./aufs5-mmap.patch too. | |
2749 | +- apply ./aufs5-standalone.patch too. | |
53392da6 AM |
2750 | +- build your kernel, don't forget "make headers_install", and reboot. |
2751 | +- edit ./config.mk and set other aufs configurations if necessary. | |
b4510431 | 2752 | + Note: You should read $PWD/fs/aufs/Kconfig carefully which describes |
53392da6 AM |
2753 | + every aufs configurations. |
2754 | +- build the module by simple "make". | |
2755 | +- you can specify ${KDIR} make variable which points to your kernel | |
2756 | + source tree. | |
2757 | +- install the files | |
2758 | + + run "make install" to install the aufs module, or copy the built | |
b4510431 AM |
2759 | + $PWD/aufs.ko to /lib/modules/... and run depmod -a (or reboot simply). |
2760 | + + run "make install_headers" (instead of headers_install) to install | |
2761 | + the modified aufs header file (you can specify DESTDIR which is | |
2762 | + available in aufs standalone version's Makefile only), or copy | |
2763 | + $PWD/usr/include/linux/aufs_type.h to /usr/include/linux or wherever | |
2764 | + you like manually. By default, the target directory is $PWD/usr. | |
fbc438ed | 2765 | +- no need to apply aufs5-kbuild.patch, nor copying source files to your |
53392da6 AM |
2766 | + kernel source tree. |
2767 | + | |
b4510431 | 2768 | +Note: The header file aufs_type.h is necessary to build aufs-util |
53392da6 AM |
2769 | + as well as "make headers_install" in the kernel source tree. |
2770 | + headers_install is subject to be forgotten, but it is essentially | |
2771 | + necessary, not only for building aufs-util. | |
2772 | + You may not meet problems without headers_install in some older | |
2773 | + version though. | |
2774 | + | |
2775 | +And then, | |
2776 | +- read README in aufs-util, build and install it | |
9dbd164d AM |
2777 | +- note that your distribution may contain an obsoleted version of |
2778 | + aufs_type.h in /usr/include/linux or something. When you build aufs | |
2779 | + utilities, make sure that your compiler refers the correct aufs header | |
2780 | + file which is built by "make headers_install." | |
53392da6 AM |
2781 | +- if you want to use readdir(3) in userspace or pathconf(3) wrapper, |
2782 | + then run "make install_ulib" too. And refer to the aufs manual in | |
2783 | + detail. | |
2784 | + | |
fbc438ed | 2785 | +There several other patches in aufs5-standalone.git. They are all |
38d290e6 | 2786 | +optional. When you meet some problems, they will help you. |
fbc438ed | 2787 | +- aufs5-loopback.patch |
38d290e6 JR |
2788 | + Supports a nested loopback mount in a branch-fs. This patch is |
2789 | + unnecessary until aufs produces a message like "you may want to try | |
2790 | + another patch for loopback file". | |
83b672a5 AM |
2791 | +- proc_mounts.patch |
2792 | + When there are many mountpoints and many mount(2)/umount(2) are | |
2793 | + running, then /proc/mounts may not show the all mountpoints. This | |
2794 | + patch makes /proc/mounts always show the full mountpoints list. | |
2795 | + If you don't want to apply this patch and meet such problem, then you | |
2796 | + need to increase the value of 'ProcMounts_Times' make-variable in | |
2797 | + aufs-util.git as a second best solution. | |
38d290e6 JR |
2798 | +- vfs-ino.patch |
2799 | + Modifies a system global kernel internal function get_next_ino() in | |
2800 | + order to stop assigning 0 for an inode-number. Not directly related to | |
2801 | + aufs, but recommended generally. | |
2802 | +- tmpfs-idr.patch | |
2803 | + Keeps the tmpfs inode number as the lowest value. Effective to reduce | |
2804 | + the size of aufs XINO files for tmpfs branch. Also it prevents the | |
2805 | + duplication of inode number, which is important for backup tools and | |
2806 | + other utilities. When you find aufs XINO files for tmpfs branch | |
2807 | + growing too much, try this patch. | |
be52b249 AM |
2808 | +- lockdep-debug.patch |
2809 | + Because aufs is not only an ordinary filesystem (callee of VFS), but | |
2810 | + also a caller of VFS functions for branch filesystems, subclassing of | |
2811 | + the internal locks for LOCKDEP is necessary. LOCKDEP is a debugging | |
2812 | + feature of linux kernel. If you enable CONFIG_LOCKDEP, then you will | |
2813 | + need to apply this debug patch to expand several constant values. | |
43982f53 AM |
2814 | + If you don't know what LOCKDEP is, then you don't have apply this |
2815 | + patch. | |
38d290e6 | 2816 | + |
53392da6 AM |
2817 | + |
2818 | +4. Usage | |
2819 | +---------------------------------------- | |
2820 | +At first, make sure aufs-util are installed, and please read the aufs | |
2821 | +manual, aufs.5 in aufs-util.git tree. | |
2822 | +$ man -l aufs.5 | |
2823 | + | |
2824 | +And then, | |
2825 | +$ mkdir /tmp/rw /tmp/aufs | |
2826 | +# mount -t aufs -o br=/tmp/rw:${HOME} none /tmp/aufs | |
2827 | + | |
2828 | +Here is another example. The result is equivalent. | |
2829 | +# mount -t aufs -o br=/tmp/rw=rw:${HOME}=ro none /tmp/aufs | |
2830 | + Or | |
2831 | +# mount -t aufs -o br:/tmp/rw none /tmp/aufs | |
2832 | +# mount -o remount,append:${HOME} /tmp/aufs | |
2833 | + | |
2834 | +Then, you can see whole tree of your home dir through /tmp/aufs. If | |
2835 | +you modify a file under /tmp/aufs, the one on your home directory is | |
2836 | +not affected, instead the same named file will be newly created under | |
2837 | +/tmp/rw. And all of your modification to a file will be applied to | |
2838 | +the one under /tmp/rw. This is called the file based Copy on Write | |
2839 | +(COW) method. | |
2840 | +Aufs mount options are described in aufs.5. | |
2841 | +If you run chroot or something and make your aufs as a root directory, | |
2842 | +then you need to customize the shutdown script. See the aufs manual in | |
2843 | +detail. | |
2844 | + | |
2845 | +Additionally, there are some sample usages of aufs which are a | |
2846 | +diskless system with network booting, and LiveCD over NFS. | |
2847 | +See sample dir in CVS tree on SourceForge. | |
2848 | + | |
2849 | + | |
2850 | +5. Contact | |
2851 | +---------------------------------------- | |
2852 | +When you have any problems or strange behaviour in aufs, please let me | |
2853 | +know with: | |
2854 | +- /proc/mounts (instead of the output of mount(8)) | |
2855 | +- /sys/module/aufs/* | |
2856 | +- /sys/fs/aufs/* (if you have them) | |
2857 | +- /debug/aufs/* (if you have them) | |
2858 | +- linux kernel version | |
2859 | + if your kernel is not plain, for example modified by distributor, | |
2860 | + the url where i can download its source is necessary too. | |
2861 | +- aufs version which was printed at loading the module or booting the | |
2862 | + system, instead of the date you downloaded. | |
2863 | +- configuration (define/undefine CONFIG_AUFS_xxx) | |
2864 | +- kernel configuration or /proc/config.gz (if you have it) | |
43982f53 | 2865 | +- LSM (linux security module, if you are using) |
53392da6 AM |
2866 | +- behaviour which you think to be incorrect |
2867 | +- actual operation, reproducible one is better | |
2868 | +- mailto: aufs-users at lists.sourceforge.net | |
2869 | + | |
2870 | +Usually, I don't watch the Public Areas(Bugs, Support Requests, Patches, | |
2871 | +and Feature Requests) on SourceForge. Please join and write to | |
2872 | +aufs-users ML. | |
2873 | + | |
2874 | + | |
2875 | +6. Acknowledgements | |
2876 | +---------------------------------------- | |
2877 | +Thanks to everyone who have tried and are using aufs, whoever | |
2878 | +have reported a bug or any feedback. | |
2879 | + | |
2880 | +Especially donators: | |
2881 | +Tomas Matejicek(slax.org) made a donation (much more than once). | |
2882 | + Since Apr 2010, Tomas M (the author of Slax and Linux Live | |
2883 | + scripts) is making "doubling" donations. | |
2884 | + Unfortunately I cannot list all of the donators, but I really | |
b4510431 | 2885 | + appreciate. |
53392da6 AM |
2886 | + It ends Aug 2010, but the ordinary donation URL is still available. |
2887 | + <http://sourceforge.net/donate/index.php?group_id=167503> | |
2888 | +Dai Itasaka made a donation (2007/8). | |
2889 | +Chuck Smith made a donation (2008/4, 10 and 12). | |
2890 | +Henk Schoneveld made a donation (2008/9). | |
2891 | +Chih-Wei Huang, ASUS, CTC donated Eee PC 4G (2008/10). | |
2892 | +Francois Dupoux made a donation (2008/11). | |
2893 | +Bruno Cesar Ribas and Luis Carlos Erpen de Bona, C3SL serves public | |
2894 | + aufs2 GIT tree (2009/2). | |
2895 | +William Grant made a donation (2009/3). | |
2896 | +Patrick Lane made a donation (2009/4). | |
2897 | +The Mail Archive (mail-archive.com) made donations (2009/5). | |
2898 | +Nippy Networks (Ed Wildgoose) made a donation (2009/7). | |
2899 | +New Dream Network, LLC (www.dreamhost.com) made a donation (2009/11). | |
2900 | +Pavel Pronskiy made a donation (2011/2). | |
2901 | +Iridium and Inmarsat satellite phone retailer (www.mailasail.com), Nippy | |
2902 | + Networks (Ed Wildgoose) made a donation for hardware (2011/3). | |
537831f9 AM |
2903 | +Max Lekomcev (DOM-TV project) made a donation (2011/7, 12, 2012/3, 6 and |
2904 | +11). | |
1e00d052 | 2905 | +Sam Liddicott made a donation (2011/9). |
86dc4139 AM |
2906 | +Era Scarecrow made a donation (2013/4). |
2907 | +Bor Ratajc made a donation (2013/4). | |
2908 | +Alessandro Gorreta made a donation (2013/4). | |
2909 | +POIRETTE Marc made a donation (2013/4). | |
2910 | +Alessandro Gorreta made a donation (2013/4). | |
2911 | +lauri kasvandik made a donation (2013/5). | |
392086de | 2912 | +"pemasu from Finland" made a donation (2013/7). |
523b37e3 AM |
2913 | +The Parted Magic Project made a donation (2013/9 and 11). |
2914 | +Pavel Barta made a donation (2013/10). | |
38d290e6 | 2915 | +Nikolay Pertsev made a donation (2014/5). |
c2c0f25c | 2916 | +James B made a donation (2014/7 and 2015/7). |
076b876e | 2917 | +Stefano Di Biase made a donation (2014/8). |
2000de60 | 2918 | +Daniel Epellei made a donation (2015/1). |
c4adf169 | 2919 | +OmegaPhil made a donation (2016/1, 2018/4). |
5afbbe0d | 2920 | +Tomasz Szewczyk made a donation (2016/4). |
f2c43d5f | 2921 | +James Burry made a donation (2016/12). |
acd2b654 | 2922 | +Carsten Rose made a donation (2018/9). |
9f237c51 | 2923 | +Porteus Kiosk made a donation (2018/10). |
53392da6 AM |
2924 | + |
2925 | +Thank you very much. | |
2926 | +Donations are always, including future donations, very important and | |
2927 | +helpful for me to keep on developing aufs. | |
2928 | + | |
2929 | + | |
2930 | +7. | |
2931 | +---------------------------------------- | |
2932 | +If you are an experienced user, no explanation is needed. Aufs is | |
2933 | +just a linux filesystem. | |
2934 | + | |
2935 | + | |
2936 | +Enjoy! | |
2937 | + | |
2938 | +# Local variables: ; | |
2939 | +# mode: text; | |
2940 | +# End: ; | |
7f207e10 | 2941 | diff -urN /usr/share/empty/fs/aufs/aufs.h linux/fs/aufs/aufs.h |
eca34b5c | 2942 | --- /usr/share/empty/fs/aufs/aufs.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 2943 | +++ linux/fs/aufs/aufs.h 2020-01-27 10:57:18.165538015 +0100 |
acd2b654 | 2944 | @@ -0,0 +1,62 @@ |
062440b3 | 2945 | +/* SPDX-License-Identifier: GPL-2.0 */ |
7f207e10 | 2946 | +/* |
d58c55f2 | 2947 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
7f207e10 AM |
2948 | + * |
2949 | + * This program, aufs is free software; you can redistribute it and/or modify | |
2950 | + * it under the terms of the GNU General Public License as published by | |
2951 | + * the Free Software Foundation; either version 2 of the License, or | |
2952 | + * (at your option) any later version. | |
2953 | + * | |
2954 | + * This program is distributed in the hope that it will be useful, | |
2955 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
2956 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
2957 | + * GNU General Public License for more details. | |
2958 | + * | |
2959 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 2960 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
2961 | + */ |
2962 | + | |
2963 | +/* | |
2964 | + * all header files | |
2965 | + */ | |
2966 | + | |
2967 | +#ifndef __AUFS_H__ | |
2968 | +#define __AUFS_H__ | |
2969 | + | |
2970 | +#ifdef __KERNEL__ | |
2971 | + | |
2972 | +#define AuStub(type, name, body, ...) \ | |
2973 | + static inline type name(__VA_ARGS__) { body; } | |
2974 | + | |
2975 | +#define AuStubVoid(name, ...) \ | |
2976 | + AuStub(void, name, , __VA_ARGS__) | |
2977 | +#define AuStubInt0(name, ...) \ | |
2978 | + AuStub(int, name, return 0, __VA_ARGS__) | |
2979 | + | |
2980 | +#include "debug.h" | |
2981 | + | |
2982 | +#include "branch.h" | |
2983 | +#include "cpup.h" | |
2984 | +#include "dcsub.h" | |
2985 | +#include "dbgaufs.h" | |
2986 | +#include "dentry.h" | |
2987 | +#include "dir.h" | |
8b6a4947 | 2988 | +#include "dirren.h" |
7f207e10 AM |
2989 | +#include "dynop.h" |
2990 | +#include "file.h" | |
2991 | +#include "fstype.h" | |
8b6a4947 | 2992 | +#include "hbl.h" |
7f207e10 | 2993 | +#include "inode.h" |
acd2b654 | 2994 | +#include "lcnt.h" |
7f207e10 AM |
2995 | +#include "loop.h" |
2996 | +#include "module.h" | |
7f207e10 AM |
2997 | +#include "opts.h" |
2998 | +#include "rwsem.h" | |
7f207e10 AM |
2999 | +#include "super.h" |
3000 | +#include "sysaufs.h" | |
3001 | +#include "vfsub.h" | |
3002 | +#include "whout.h" | |
3003 | +#include "wkq.h" | |
3004 | + | |
3005 | +#endif /* __KERNEL__ */ | |
3006 | +#endif /* __AUFS_H__ */ | |
3007 | diff -urN /usr/share/empty/fs/aufs/branch.c linux/fs/aufs/branch.c | |
eca34b5c | 3008 | --- /usr/share/empty/fs/aufs/branch.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 3009 | +++ linux/fs/aufs/branch.c 2020-01-27 10:57:18.165538015 +0100 |
eca34b5c | 3010 | @@ -0,0 +1,1428 @@ |
cd7a4cd9 | 3011 | +// SPDX-License-Identifier: GPL-2.0 |
7f207e10 | 3012 | +/* |
d58c55f2 | 3013 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
7f207e10 AM |
3014 | + * |
3015 | + * This program, aufs is free software; you can redistribute it and/or modify | |
3016 | + * it under the terms of the GNU General Public License as published by | |
3017 | + * the Free Software Foundation; either version 2 of the License, or | |
3018 | + * (at your option) any later version. | |
3019 | + * | |
3020 | + * This program is distributed in the hope that it will be useful, | |
3021 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
3022 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
3023 | + * GNU General Public License for more details. | |
3024 | + * | |
3025 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 3026 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
3027 | + */ |
3028 | + | |
3029 | +/* | |
3030 | + * branch management | |
3031 | + */ | |
3032 | + | |
027c5e7a | 3033 | +#include <linux/compat.h> |
7f207e10 AM |
3034 | +#include <linux/statfs.h> |
3035 | +#include "aufs.h" | |
3036 | + | |
3037 | +/* | |
3038 | + * free a single branch | |
1facf9fc | 3039 | + */ |
3040 | +static void au_br_do_free(struct au_branch *br) | |
3041 | +{ | |
3042 | + int i; | |
3043 | + struct au_wbr *wbr; | |
4a4d8108 | 3044 | + struct au_dykey **key; |
1facf9fc | 3045 | + |
027c5e7a | 3046 | + au_hnotify_fin_br(br); |
8b6a4947 AM |
3047 | + /* always, regardless the mount option */ |
3048 | + au_dr_hino_free(&br->br_dirren); | |
062440b3 | 3049 | + au_xino_put(br); |
1facf9fc | 3050 | + |
acd2b654 AM |
3051 | + AuLCntZero(au_lcnt_read(&br->br_nfiles, /*do_rev*/0)); |
3052 | + au_lcnt_fin(&br->br_nfiles, /*do_sync*/0); | |
3053 | + AuLCntZero(au_lcnt_read(&br->br_count, /*do_rev*/0)); | |
3054 | + au_lcnt_fin(&br->br_count, /*do_sync*/0); | |
1facf9fc | 3055 | + |
3056 | + wbr = br->br_wbr; | |
3057 | + if (wbr) { | |
3058 | + for (i = 0; i < AuBrWh_Last; i++) | |
3059 | + dput(wbr->wbr_wh[i]); | |
3060 | + AuDebugOn(atomic_read(&wbr->wbr_wh_running)); | |
dece6358 | 3061 | + AuRwDestroy(&wbr->wbr_wh_rwsem); |
1facf9fc | 3062 | + } |
3063 | + | |
076b876e AM |
3064 | + if (br->br_fhsm) { |
3065 | + au_br_fhsm_fin(br->br_fhsm); | |
9f237c51 | 3066 | + au_kfree_try_rcu(br->br_fhsm); |
076b876e AM |
3067 | + } |
3068 | + | |
4a4d8108 AM |
3069 | + key = br->br_dykey; |
3070 | + for (i = 0; i < AuBrDynOp; i++, key++) | |
3071 | + if (*key) | |
3072 | + au_dy_put(*key); | |
3073 | + else | |
3074 | + break; | |
3075 | + | |
537831f9 | 3076 | + /* recursive lock, s_umount of branch's */ |
acd2b654 | 3077 | + /* synchronize_rcu(); */ /* why? */ |
537831f9 | 3078 | + lockdep_off(); |
86dc4139 | 3079 | + path_put(&br->br_path); |
537831f9 | 3080 | + lockdep_on(); |
9f237c51 | 3081 | + au_kfree_rcu(wbr); |
acd2b654 AM |
3082 | + au_lcnt_wait_for_fin(&br->br_nfiles); |
3083 | + au_lcnt_wait_for_fin(&br->br_count); | |
3084 | + /* I don't know why, but percpu_refcount requires this */ | |
3085 | + /* synchronize_rcu(); */ | |
9f237c51 | 3086 | + au_kfree_rcu(br); |
1facf9fc | 3087 | +} |
3088 | + | |
3089 | +/* | |
3090 | + * frees all branches | |
3091 | + */ | |
3092 | +void au_br_free(struct au_sbinfo *sbinfo) | |
3093 | +{ | |
3094 | + aufs_bindex_t bmax; | |
3095 | + struct au_branch **br; | |
3096 | + | |
dece6358 AM |
3097 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3098 | + | |
5afbbe0d | 3099 | + bmax = sbinfo->si_bbot + 1; |
1facf9fc | 3100 | + br = sbinfo->si_branch; |
3101 | + while (bmax--) | |
3102 | + au_br_do_free(*br++); | |
3103 | +} | |
3104 | + | |
3105 | +/* | |
3106 | + * find the index of a branch which is specified by @br_id. | |
3107 | + */ | |
3108 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id) | |
3109 | +{ | |
5afbbe0d | 3110 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 3111 | + |
5afbbe0d AM |
3112 | + bbot = au_sbbot(sb); |
3113 | + for (bindex = 0; bindex <= bbot; bindex++) | |
1facf9fc | 3114 | + if (au_sbr_id(sb, bindex) == br_id) |
3115 | + return bindex; | |
3116 | + return -1; | |
3117 | +} | |
3118 | + | |
3119 | +/* ---------------------------------------------------------------------- */ | |
3120 | + | |
3121 | +/* | |
3122 | + * add a branch | |
3123 | + */ | |
3124 | + | |
b752ccd1 AM |
3125 | +static int test_overlap(struct super_block *sb, struct dentry *h_adding, |
3126 | + struct dentry *h_root) | |
1facf9fc | 3127 | +{ |
b752ccd1 AM |
3128 | + if (unlikely(h_adding == h_root |
3129 | + || au_test_loopback_overlap(sb, h_adding))) | |
1facf9fc | 3130 | + return 1; |
b752ccd1 AM |
3131 | + if (h_adding->d_sb != h_root->d_sb) |
3132 | + return 0; | |
3133 | + return au_test_subdir(h_adding, h_root) | |
3134 | + || au_test_subdir(h_root, h_adding); | |
1facf9fc | 3135 | +} |
3136 | + | |
3137 | +/* | |
3138 | + * returns a newly allocated branch. @new_nbranch is a number of branches | |
3139 | + * after adding a branch. | |
3140 | + */ | |
3141 | +static struct au_branch *au_br_alloc(struct super_block *sb, int new_nbranch, | |
3142 | + int perm) | |
3143 | +{ | |
3144 | + struct au_branch *add_branch; | |
3145 | + struct dentry *root; | |
5527c038 | 3146 | + struct inode *inode; |
4a4d8108 | 3147 | + int err; |
1facf9fc | 3148 | + |
4a4d8108 | 3149 | + err = -ENOMEM; |
be52b249 | 3150 | + add_branch = kzalloc(sizeof(*add_branch), GFP_NOFS); |
1facf9fc | 3151 | + if (unlikely(!add_branch)) |
3152 | + goto out; | |
acd2b654 | 3153 | + add_branch->br_xino = au_xino_alloc(/*nfile*/1); |
062440b3 | 3154 | + if (unlikely(!add_branch->br_xino)) |
521ced18 | 3155 | + goto out_br; |
027c5e7a AM |
3156 | + err = au_hnotify_init_br(add_branch, perm); |
3157 | + if (unlikely(err)) | |
062440b3 | 3158 | + goto out_xino; |
027c5e7a | 3159 | + |
1facf9fc | 3160 | + if (au_br_writable(perm)) { |
3161 | + /* may be freed separately at changing the branch permission */ | |
be52b249 | 3162 | + add_branch->br_wbr = kzalloc(sizeof(*add_branch->br_wbr), |
1facf9fc | 3163 | + GFP_NOFS); |
3164 | + if (unlikely(!add_branch->br_wbr)) | |
027c5e7a | 3165 | + goto out_hnotify; |
1facf9fc | 3166 | + } |
3167 | + | |
076b876e AM |
3168 | + if (au_br_fhsm(perm)) { |
3169 | + err = au_fhsm_br_alloc(add_branch); | |
3170 | + if (unlikely(err)) | |
3171 | + goto out_wbr; | |
3172 | + } | |
3173 | + | |
521ced18 | 3174 | + root = sb->s_root; |
e2f27e51 | 3175 | + err = au_sbr_realloc(au_sbi(sb), new_nbranch, /*may_shrink*/0); |
4a4d8108 | 3176 | + if (!err) |
e2f27e51 | 3177 | + err = au_di_realloc(au_di(root), new_nbranch, /*may_shrink*/0); |
5527c038 JR |
3178 | + if (!err) { |
3179 | + inode = d_inode(root); | |
1c60b727 AM |
3180 | + err = au_hinode_realloc(au_ii(inode), new_nbranch, |
3181 | + /*may_shrink*/0); | |
5527c038 | 3182 | + } |
4a4d8108 AM |
3183 | + if (!err) |
3184 | + return add_branch; /* success */ | |
1facf9fc | 3185 | + |
076b876e | 3186 | +out_wbr: |
9f237c51 | 3187 | + au_kfree_rcu(add_branch->br_wbr); |
027c5e7a AM |
3188 | +out_hnotify: |
3189 | + au_hnotify_fin_br(add_branch); | |
062440b3 AM |
3190 | +out_xino: |
3191 | + au_xino_put(add_branch); | |
4f0767ce | 3192 | +out_br: |
9f237c51 | 3193 | + au_kfree_rcu(add_branch); |
4f0767ce | 3194 | +out: |
4a4d8108 | 3195 | + return ERR_PTR(err); |
1facf9fc | 3196 | +} |
3197 | + | |
3198 | +/* | |
3199 | + * test if the branch permission is legal or not. | |
3200 | + */ | |
3201 | +static int test_br(struct inode *inode, int brperm, char *path) | |
3202 | +{ | |
3203 | + int err; | |
3204 | + | |
4a4d8108 AM |
3205 | + err = (au_br_writable(brperm) && IS_RDONLY(inode)); |
3206 | + if (!err) | |
3207 | + goto out; | |
1facf9fc | 3208 | + |
4a4d8108 AM |
3209 | + err = -EINVAL; |
3210 | + pr_err("write permission for readonly mount or inode, %s\n", path); | |
3211 | + | |
4f0767ce | 3212 | +out: |
1facf9fc | 3213 | + return err; |
3214 | +} | |
3215 | + | |
3216 | +/* | |
3217 | + * returns: | |
3218 | + * 0: success, the caller will add it | |
3219 | + * plus: success, it is already unified, the caller should ignore it | |
3220 | + * minus: error | |
3221 | + */ | |
3222 | +static int test_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3223 | +{ | |
3224 | + int err; | |
5afbbe0d | 3225 | + aufs_bindex_t bbot, bindex; |
5527c038 | 3226 | + struct dentry *root, *h_dentry; |
1facf9fc | 3227 | + struct inode *inode, *h_inode; |
3228 | + | |
3229 | + root = sb->s_root; | |
5afbbe0d AM |
3230 | + bbot = au_sbbot(sb); |
3231 | + if (unlikely(bbot >= 0 | |
1facf9fc | 3232 | + && au_find_dbindex(root, add->path.dentry) >= 0)) { |
3233 | + err = 1; | |
3234 | + if (!remount) { | |
3235 | + err = -EINVAL; | |
4a4d8108 | 3236 | + pr_err("%s duplicated\n", add->pathname); |
1facf9fc | 3237 | + } |
3238 | + goto out; | |
3239 | + } | |
3240 | + | |
3241 | + err = -ENOSPC; /* -E2BIG; */ | |
3242 | + if (unlikely(AUFS_BRANCH_MAX <= add->bindex | |
5afbbe0d | 3243 | + || AUFS_BRANCH_MAX - 1 <= bbot)) { |
4a4d8108 | 3244 | + pr_err("number of branches exceeded %s\n", add->pathname); |
1facf9fc | 3245 | + goto out; |
3246 | + } | |
3247 | + | |
3248 | + err = -EDOM; | |
5afbbe0d | 3249 | + if (unlikely(add->bindex < 0 || bbot + 1 < add->bindex)) { |
4a4d8108 | 3250 | + pr_err("bad index %d\n", add->bindex); |
1facf9fc | 3251 | + goto out; |
3252 | + } | |
3253 | + | |
5527c038 | 3254 | + inode = d_inode(add->path.dentry); |
1facf9fc | 3255 | + err = -ENOENT; |
3256 | + if (unlikely(!inode->i_nlink)) { | |
4a4d8108 | 3257 | + pr_err("no existence %s\n", add->pathname); |
1facf9fc | 3258 | + goto out; |
3259 | + } | |
3260 | + | |
3261 | + err = -EINVAL; | |
3262 | + if (unlikely(inode->i_sb == sb)) { | |
4a4d8108 | 3263 | + pr_err("%s must be outside\n", add->pathname); |
1facf9fc | 3264 | + goto out; |
3265 | + } | |
3266 | + | |
3267 | + if (unlikely(au_test_fs_unsuppoted(inode->i_sb))) { | |
4a4d8108 AM |
3268 | + pr_err("unsupported filesystem, %s (%s)\n", |
3269 | + add->pathname, au_sbtype(inode->i_sb)); | |
1facf9fc | 3270 | + goto out; |
3271 | + } | |
3272 | + | |
c1595e42 JR |
3273 | + if (unlikely(inode->i_sb->s_stack_depth)) { |
3274 | + pr_err("already stacked, %s (%s)\n", | |
3275 | + add->pathname, au_sbtype(inode->i_sb)); | |
3276 | + goto out; | |
3277 | + } | |
3278 | + | |
5527c038 | 3279 | + err = test_br(d_inode(add->path.dentry), add->perm, add->pathname); |
1facf9fc | 3280 | + if (unlikely(err)) |
3281 | + goto out; | |
3282 | + | |
5afbbe0d | 3283 | + if (bbot < 0) |
1facf9fc | 3284 | + return 0; /* success */ |
3285 | + | |
3286 | + err = -EINVAL; | |
5afbbe0d | 3287 | + for (bindex = 0; bindex <= bbot; bindex++) |
1facf9fc | 3288 | + if (unlikely(test_overlap(sb, add->path.dentry, |
3289 | + au_h_dptr(root, bindex)))) { | |
4a4d8108 | 3290 | + pr_err("%s is overlapped\n", add->pathname); |
1facf9fc | 3291 | + goto out; |
3292 | + } | |
3293 | + | |
3294 | + err = 0; | |
3295 | + if (au_opt_test(au_mntflags(sb), WARN_PERM)) { | |
5527c038 JR |
3296 | + h_dentry = au_h_dptr(root, 0); |
3297 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 3298 | + if ((h_inode->i_mode & S_IALLUGO) != (inode->i_mode & S_IALLUGO) |
0c3ec466 AM |
3299 | + || !uid_eq(h_inode->i_uid, inode->i_uid) |
3300 | + || !gid_eq(h_inode->i_gid, inode->i_gid)) | |
3301 | + pr_warn("uid/gid/perm %s %u/%u/0%o, %u/%u/0%o\n", | |
3302 | + add->pathname, | |
3303 | + i_uid_read(inode), i_gid_read(inode), | |
3304 | + (inode->i_mode & S_IALLUGO), | |
3305 | + i_uid_read(h_inode), i_gid_read(h_inode), | |
3306 | + (h_inode->i_mode & S_IALLUGO)); | |
1facf9fc | 3307 | + } |
3308 | + | |
4f0767ce | 3309 | +out: |
1facf9fc | 3310 | + return err; |
3311 | +} | |
3312 | + | |
3313 | +/* | |
3314 | + * initialize or clean the whiteouts for an adding branch | |
3315 | + */ | |
3316 | +static int au_br_init_wh(struct super_block *sb, struct au_branch *br, | |
86dc4139 | 3317 | + int new_perm) |
1facf9fc | 3318 | +{ |
3319 | + int err, old_perm; | |
3320 | + aufs_bindex_t bindex; | |
febd17d6 | 3321 | + struct inode *h_inode; |
1facf9fc | 3322 | + struct au_wbr *wbr; |
3323 | + struct au_hinode *hdir; | |
5527c038 | 3324 | + struct dentry *h_dentry; |
1facf9fc | 3325 | + |
86dc4139 AM |
3326 | + err = vfsub_mnt_want_write(au_br_mnt(br)); |
3327 | + if (unlikely(err)) | |
3328 | + goto out; | |
3329 | + | |
1facf9fc | 3330 | + wbr = br->br_wbr; |
3331 | + old_perm = br->br_perm; | |
3332 | + br->br_perm = new_perm; | |
3333 | + hdir = NULL; | |
febd17d6 | 3334 | + h_inode = NULL; |
1facf9fc | 3335 | + bindex = au_br_index(sb, br->br_id); |
3336 | + if (0 <= bindex) { | |
5527c038 | 3337 | + hdir = au_hi(d_inode(sb->s_root), bindex); |
5afbbe0d | 3338 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 3339 | + } else { |
5527c038 | 3340 | + h_dentry = au_br_dentry(br); |
febd17d6 JR |
3341 | + h_inode = d_inode(h_dentry); |
3342 | + inode_lock_nested(h_inode, AuLsc_I_PARENT); | |
1facf9fc | 3343 | + } |
3344 | + if (!wbr) | |
86dc4139 | 3345 | + err = au_wh_init(br, sb); |
1facf9fc | 3346 | + else { |
3347 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 3348 | + err = au_wh_init(br, sb); |
1facf9fc | 3349 | + wbr_wh_write_unlock(wbr); |
3350 | + } | |
3351 | + if (hdir) | |
5afbbe0d | 3352 | + au_hn_inode_unlock(hdir); |
1facf9fc | 3353 | + else |
febd17d6 | 3354 | + inode_unlock(h_inode); |
86dc4139 | 3355 | + vfsub_mnt_drop_write(au_br_mnt(br)); |
1facf9fc | 3356 | + br->br_perm = old_perm; |
3357 | + | |
3358 | + if (!err && wbr && !au_br_writable(new_perm)) { | |
9f237c51 | 3359 | + au_kfree_rcu(wbr); |
1facf9fc | 3360 | + br->br_wbr = NULL; |
3361 | + } | |
3362 | + | |
86dc4139 | 3363 | +out: |
1facf9fc | 3364 | + return err; |
3365 | +} | |
3366 | + | |
3367 | +static int au_wbr_init(struct au_branch *br, struct super_block *sb, | |
86dc4139 | 3368 | + int perm) |
1facf9fc | 3369 | +{ |
3370 | + int err; | |
4a4d8108 | 3371 | + struct kstatfs kst; |
1facf9fc | 3372 | + struct au_wbr *wbr; |
3373 | + | |
3374 | + wbr = br->br_wbr; | |
dece6358 | 3375 | + au_rw_init(&wbr->wbr_wh_rwsem); |
1facf9fc | 3376 | + atomic_set(&wbr->wbr_wh_running, 0); |
1facf9fc | 3377 | + |
4a4d8108 AM |
3378 | + /* |
3379 | + * a limit for rmdir/rename a dir | |
523b37e3 | 3380 | + * cf. AUFS_MAX_NAMELEN in include/uapi/linux/aufs_type.h |
4a4d8108 | 3381 | + */ |
86dc4139 | 3382 | + err = vfs_statfs(&br->br_path, &kst); |
4a4d8108 AM |
3383 | + if (unlikely(err)) |
3384 | + goto out; | |
3385 | + err = -EINVAL; | |
3386 | + if (kst.f_namelen >= NAME_MAX) | |
86dc4139 | 3387 | + err = au_br_init_wh(sb, br, perm); |
4a4d8108 | 3388 | + else |
523b37e3 AM |
3389 | + pr_err("%pd(%s), unsupported namelen %ld\n", |
3390 | + au_br_dentry(br), | |
86dc4139 | 3391 | + au_sbtype(au_br_dentry(br)->d_sb), kst.f_namelen); |
1facf9fc | 3392 | + |
4f0767ce | 3393 | +out: |
1facf9fc | 3394 | + return err; |
3395 | +} | |
3396 | + | |
c1595e42 | 3397 | +/* initialize a new branch */ |
1facf9fc | 3398 | +static int au_br_init(struct au_branch *br, struct super_block *sb, |
3399 | + struct au_opt_add *add) | |
3400 | +{ | |
3401 | + int err; | |
062440b3 AM |
3402 | + struct au_branch *brbase; |
3403 | + struct file *xf; | |
5527c038 | 3404 | + struct inode *h_inode; |
1facf9fc | 3405 | + |
3406 | + err = 0; | |
1facf9fc | 3407 | + br->br_perm = add->perm; |
86dc4139 | 3408 | + br->br_path = add->path; /* set first, path_get() later */ |
4a4d8108 | 3409 | + spin_lock_init(&br->br_dykey_lock); |
acd2b654 AM |
3410 | + au_lcnt_init(&br->br_nfiles, /*release*/NULL); |
3411 | + au_lcnt_init(&br->br_count, /*release*/NULL); | |
1facf9fc | 3412 | + br->br_id = au_new_br_id(sb); |
7f207e10 | 3413 | + AuDebugOn(br->br_id < 0); |
1facf9fc | 3414 | + |
8b6a4947 AM |
3415 | + /* always, regardless the given option */ |
3416 | + err = au_dr_br_init(sb, br, &add->path); | |
3417 | + if (unlikely(err)) | |
3418 | + goto out_err; | |
3419 | + | |
1facf9fc | 3420 | + if (au_br_writable(add->perm)) { |
86dc4139 | 3421 | + err = au_wbr_init(br, sb, add->perm); |
1facf9fc | 3422 | + if (unlikely(err)) |
b752ccd1 | 3423 | + goto out_err; |
1facf9fc | 3424 | + } |
3425 | + | |
3426 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
062440b3 | 3427 | + brbase = au_sbr(sb, 0); |
acd2b654 | 3428 | + xf = au_xino_file(brbase->br_xino, /*idx*/-1); |
062440b3 | 3429 | + AuDebugOn(!xf); |
5527c038 | 3430 | + h_inode = d_inode(add->path.dentry); |
062440b3 | 3431 | + err = au_xino_init_br(sb, br, h_inode->i_ino, &xf->f_path); |
1facf9fc | 3432 | + if (unlikely(err)) { |
acd2b654 | 3433 | + AuDebugOn(au_xino_file(br->br_xino, /*idx*/-1)); |
b752ccd1 | 3434 | + goto out_err; |
1facf9fc | 3435 | + } |
3436 | + } | |
3437 | + | |
3438 | + sysaufs_br_init(br); | |
86dc4139 | 3439 | + path_get(&br->br_path); |
b752ccd1 | 3440 | + goto out; /* success */ |
1facf9fc | 3441 | + |
4f0767ce | 3442 | +out_err: |
86dc4139 | 3443 | + memset(&br->br_path, 0, sizeof(br->br_path)); |
4f0767ce | 3444 | +out: |
1facf9fc | 3445 | + return err; |
3446 | +} | |
3447 | + | |
3448 | +static void au_br_do_add_brp(struct au_sbinfo *sbinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3449 | + struct au_branch *br, aufs_bindex_t bbot, |
1facf9fc | 3450 | + aufs_bindex_t amount) |
3451 | +{ | |
3452 | + struct au_branch **brp; | |
3453 | + | |
dece6358 AM |
3454 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3455 | + | |
1facf9fc | 3456 | + brp = sbinfo->si_branch + bindex; |
3457 | + memmove(brp + 1, brp, sizeof(*brp) * amount); | |
3458 | + *brp = br; | |
5afbbe0d AM |
3459 | + sbinfo->si_bbot++; |
3460 | + if (unlikely(bbot < 0)) | |
3461 | + sbinfo->si_bbot = 0; | |
1facf9fc | 3462 | +} |
3463 | + | |
3464 | +static void au_br_do_add_hdp(struct au_dinfo *dinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3465 | + aufs_bindex_t bbot, aufs_bindex_t amount) |
1facf9fc | 3466 | +{ |
3467 | + struct au_hdentry *hdp; | |
3468 | + | |
1308ab2a | 3469 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3470 | + | |
5afbbe0d | 3471 | + hdp = au_hdentry(dinfo, bindex); |
1facf9fc | 3472 | + memmove(hdp + 1, hdp, sizeof(*hdp) * amount); |
3473 | + au_h_dentry_init(hdp); | |
5afbbe0d AM |
3474 | + dinfo->di_bbot++; |
3475 | + if (unlikely(bbot < 0)) | |
3476 | + dinfo->di_btop = 0; | |
1facf9fc | 3477 | +} |
3478 | + | |
3479 | +static void au_br_do_add_hip(struct au_iinfo *iinfo, aufs_bindex_t bindex, | |
5afbbe0d | 3480 | + aufs_bindex_t bbot, aufs_bindex_t amount) |
1facf9fc | 3481 | +{ |
3482 | + struct au_hinode *hip; | |
3483 | + | |
1308ab2a | 3484 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3485 | + | |
5afbbe0d | 3486 | + hip = au_hinode(iinfo, bindex); |
1facf9fc | 3487 | + memmove(hip + 1, hip, sizeof(*hip) * amount); |
5afbbe0d AM |
3488 | + au_hinode_init(hip); |
3489 | + iinfo->ii_bbot++; | |
3490 | + if (unlikely(bbot < 0)) | |
3491 | + iinfo->ii_btop = 0; | |
1facf9fc | 3492 | +} |
3493 | + | |
86dc4139 AM |
3494 | +static void au_br_do_add(struct super_block *sb, struct au_branch *br, |
3495 | + aufs_bindex_t bindex) | |
1facf9fc | 3496 | +{ |
86dc4139 | 3497 | + struct dentry *root, *h_dentry; |
5527c038 | 3498 | + struct inode *root_inode, *h_inode; |
5afbbe0d | 3499 | + aufs_bindex_t bbot, amount; |
1facf9fc | 3500 | + |
3501 | + root = sb->s_root; | |
5527c038 | 3502 | + root_inode = d_inode(root); |
5afbbe0d AM |
3503 | + bbot = au_sbbot(sb); |
3504 | + amount = bbot + 1 - bindex; | |
86dc4139 | 3505 | + h_dentry = au_br_dentry(br); |
53392da6 | 3506 | + au_sbilist_lock(); |
5afbbe0d AM |
3507 | + au_br_do_add_brp(au_sbi(sb), bindex, br, bbot, amount); |
3508 | + au_br_do_add_hdp(au_di(root), bindex, bbot, amount); | |
3509 | + au_br_do_add_hip(au_ii(root_inode), bindex, bbot, amount); | |
1facf9fc | 3510 | + au_set_h_dptr(root, bindex, dget(h_dentry)); |
5527c038 JR |
3511 | + h_inode = d_inode(h_dentry); |
3512 | + au_set_h_iptr(root_inode, bindex, au_igrab(h_inode), /*flags*/0); | |
53392da6 | 3513 | + au_sbilist_unlock(); |
1facf9fc | 3514 | +} |
3515 | + | |
3516 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount) | |
3517 | +{ | |
3518 | + int err; | |
5afbbe0d | 3519 | + aufs_bindex_t bbot, add_bindex; |
1facf9fc | 3520 | + struct dentry *root, *h_dentry; |
3521 | + struct inode *root_inode; | |
3522 | + struct au_branch *add_branch; | |
3523 | + | |
3524 | + root = sb->s_root; | |
5527c038 | 3525 | + root_inode = d_inode(root); |
1facf9fc | 3526 | + IMustLock(root_inode); |
5afbbe0d | 3527 | + IiMustWriteLock(root_inode); |
1facf9fc | 3528 | + err = test_add(sb, add, remount); |
3529 | + if (unlikely(err < 0)) | |
3530 | + goto out; | |
3531 | + if (err) { | |
3532 | + err = 0; | |
3533 | + goto out; /* success */ | |
3534 | + } | |
3535 | + | |
5afbbe0d AM |
3536 | + bbot = au_sbbot(sb); |
3537 | + add_branch = au_br_alloc(sb, bbot + 2, add->perm); | |
1facf9fc | 3538 | + err = PTR_ERR(add_branch); |
3539 | + if (IS_ERR(add_branch)) | |
3540 | + goto out; | |
3541 | + | |
3542 | + err = au_br_init(add_branch, sb, add); | |
3543 | + if (unlikely(err)) { | |
3544 | + au_br_do_free(add_branch); | |
3545 | + goto out; | |
3546 | + } | |
3547 | + | |
3548 | + add_bindex = add->bindex; | |
062440b3 AM |
3549 | + sysaufs_brs_del(sb, add_bindex); /* remove successors */ |
3550 | + au_br_do_add(sb, add_branch, add_bindex); | |
3551 | + sysaufs_brs_add(sb, add_bindex); /* append successors */ | |
3552 | + dbgaufs_brs_add(sb, add_bindex, /*topdown*/0); /* rename successors */ | |
1facf9fc | 3553 | + |
86dc4139 | 3554 | + h_dentry = add->path.dentry; |
1308ab2a | 3555 | + if (!add_bindex) { |
1facf9fc | 3556 | + au_cpup_attr_all(root_inode, /*force*/1); |
1308ab2a | 3557 | + sb->s_maxbytes = h_dentry->d_sb->s_maxbytes; |
3558 | + } else | |
5527c038 | 3559 | + au_add_nlink(root_inode, d_inode(h_dentry)); |
1facf9fc | 3560 | + |
4f0767ce | 3561 | +out: |
1facf9fc | 3562 | + return err; |
3563 | +} | |
3564 | + | |
3565 | +/* ---------------------------------------------------------------------- */ | |
3566 | + | |
79b8bda9 | 3567 | +static unsigned long long au_farray_cb(struct super_block *sb, void *a, |
076b876e AM |
3568 | + unsigned long long max __maybe_unused, |
3569 | + void *arg) | |
3570 | +{ | |
3571 | + unsigned long long n; | |
3572 | + struct file **p, *f; | |
8b6a4947 AM |
3573 | + struct hlist_bl_head *files; |
3574 | + struct hlist_bl_node *pos; | |
076b876e | 3575 | + struct au_finfo *finfo; |
076b876e AM |
3576 | + |
3577 | + n = 0; | |
3578 | + p = a; | |
3579 | + files = &au_sbi(sb)->si_files; | |
8b6a4947 AM |
3580 | + hlist_bl_lock(files); |
3581 | + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) { | |
076b876e AM |
3582 | + f = finfo->fi_file; |
3583 | + if (file_count(f) | |
3584 | + && !special_file(file_inode(f)->i_mode)) { | |
3585 | + get_file(f); | |
3586 | + *p++ = f; | |
3587 | + n++; | |
3588 | + AuDebugOn(n > max); | |
3589 | + } | |
3590 | + } | |
8b6a4947 | 3591 | + hlist_bl_unlock(files); |
076b876e AM |
3592 | + |
3593 | + return n; | |
3594 | +} | |
3595 | + | |
3596 | +static struct file **au_farray_alloc(struct super_block *sb, | |
3597 | + unsigned long long *max) | |
3598 | +{ | |
acd2b654 AM |
3599 | + struct au_sbinfo *sbi; |
3600 | + | |
3601 | + sbi = au_sbi(sb); | |
3602 | + *max = au_lcnt_read(&sbi->si_nfiles, /*do_rev*/1); | |
79b8bda9 | 3603 | + return au_array_alloc(max, au_farray_cb, sb, /*arg*/NULL); |
076b876e AM |
3604 | +} |
3605 | + | |
3606 | +static void au_farray_free(struct file **a, unsigned long long max) | |
3607 | +{ | |
3608 | + unsigned long long ull; | |
3609 | + | |
3610 | + for (ull = 0; ull < max; ull++) | |
3611 | + if (a[ull]) | |
3612 | + fput(a[ull]); | |
be52b249 | 3613 | + kvfree(a); |
076b876e AM |
3614 | +} |
3615 | + | |
3616 | +/* ---------------------------------------------------------------------- */ | |
3617 | + | |
1facf9fc | 3618 | +/* |
3619 | + * delete a branch | |
3620 | + */ | |
3621 | + | |
3622 | +/* to show the line number, do not make it inlined function */ | |
4a4d8108 | 3623 | +#define AuVerbose(do_info, fmt, ...) do { \ |
1facf9fc | 3624 | + if (do_info) \ |
4a4d8108 | 3625 | + pr_info(fmt, ##__VA_ARGS__); \ |
1facf9fc | 3626 | +} while (0) |
3627 | + | |
5afbbe0d AM |
3628 | +static int au_test_ibusy(struct inode *inode, aufs_bindex_t btop, |
3629 | + aufs_bindex_t bbot) | |
027c5e7a | 3630 | +{ |
5afbbe0d | 3631 | + return (inode && !S_ISDIR(inode->i_mode)) || btop == bbot; |
027c5e7a AM |
3632 | +} |
3633 | + | |
5afbbe0d AM |
3634 | +static int au_test_dbusy(struct dentry *dentry, aufs_bindex_t btop, |
3635 | + aufs_bindex_t bbot) | |
027c5e7a | 3636 | +{ |
5afbbe0d | 3637 | + return au_test_ibusy(d_inode(dentry), btop, bbot); |
027c5e7a AM |
3638 | +} |
3639 | + | |
1facf9fc | 3640 | +/* |
3641 | + * test if the branch is deletable or not. | |
3642 | + */ | |
3643 | +static int test_dentry_busy(struct dentry *root, aufs_bindex_t bindex, | |
b752ccd1 | 3644 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3645 | +{ |
3646 | + int err, i, j, ndentry; | |
5afbbe0d | 3647 | + aufs_bindex_t btop, bbot; |
1facf9fc | 3648 | + struct au_dcsub_pages dpages; |
3649 | + struct au_dpage *dpage; | |
3650 | + struct dentry *d; | |
1facf9fc | 3651 | + |
3652 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
3653 | + if (unlikely(err)) | |
3654 | + goto out; | |
3655 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); | |
3656 | + if (unlikely(err)) | |
3657 | + goto out_dpages; | |
3658 | + | |
1facf9fc | 3659 | + for (i = 0; !err && i < dpages.ndpage; i++) { |
3660 | + dpage = dpages.dpages + i; | |
3661 | + ndentry = dpage->ndentry; | |
3662 | + for (j = 0; !err && j < ndentry; j++) { | |
3663 | + d = dpage->dentries[j]; | |
c1595e42 | 3664 | + AuDebugOn(au_dcount(d) <= 0); |
027c5e7a | 3665 | + if (!au_digen_test(d, sigen)) { |
1facf9fc | 3666 | + di_read_lock_child(d, AuLock_IR); |
027c5e7a AM |
3667 | + if (unlikely(au_dbrange_test(d))) { |
3668 | + di_read_unlock(d, AuLock_IR); | |
3669 | + continue; | |
3670 | + } | |
3671 | + } else { | |
1facf9fc | 3672 | + di_write_lock_child(d); |
027c5e7a AM |
3673 | + if (unlikely(au_dbrange_test(d))) { |
3674 | + di_write_unlock(d); | |
3675 | + continue; | |
3676 | + } | |
1facf9fc | 3677 | + err = au_reval_dpath(d, sigen); |
3678 | + if (!err) | |
3679 | + di_downgrade_lock(d, AuLock_IR); | |
3680 | + else { | |
3681 | + di_write_unlock(d); | |
3682 | + break; | |
3683 | + } | |
3684 | + } | |
3685 | + | |
027c5e7a | 3686 | + /* AuDbgDentry(d); */ |
5afbbe0d AM |
3687 | + btop = au_dbtop(d); |
3688 | + bbot = au_dbbot(d); | |
3689 | + if (btop <= bindex | |
3690 | + && bindex <= bbot | |
1facf9fc | 3691 | + && au_h_dptr(d, bindex) |
5afbbe0d | 3692 | + && au_test_dbusy(d, btop, bbot)) { |
1facf9fc | 3693 | + err = -EBUSY; |
523b37e3 | 3694 | + AuVerbose(verbose, "busy %pd\n", d); |
027c5e7a | 3695 | + AuDbgDentry(d); |
1facf9fc | 3696 | + } |
3697 | + di_read_unlock(d, AuLock_IR); | |
3698 | + } | |
3699 | + } | |
3700 | + | |
4f0767ce | 3701 | +out_dpages: |
1facf9fc | 3702 | + au_dpages_free(&dpages); |
4f0767ce | 3703 | +out: |
1facf9fc | 3704 | + return err; |
3705 | +} | |
3706 | + | |
3707 | +static int test_inode_busy(struct super_block *sb, aufs_bindex_t bindex, | |
b752ccd1 | 3708 | + unsigned int sigen, const unsigned int verbose) |
1facf9fc | 3709 | +{ |
3710 | + int err; | |
7f207e10 AM |
3711 | + unsigned long long max, ull; |
3712 | + struct inode *i, **array; | |
5afbbe0d | 3713 | + aufs_bindex_t btop, bbot; |
1facf9fc | 3714 | + |
7f207e10 AM |
3715 | + array = au_iarray_alloc(sb, &max); |
3716 | + err = PTR_ERR(array); | |
3717 | + if (IS_ERR(array)) | |
3718 | + goto out; | |
3719 | + | |
1facf9fc | 3720 | + err = 0; |
7f207e10 AM |
3721 | + AuDbg("b%d\n", bindex); |
3722 | + for (ull = 0; !err && ull < max; ull++) { | |
3723 | + i = array[ull]; | |
076b876e AM |
3724 | + if (unlikely(!i)) |
3725 | + break; | |
7f207e10 | 3726 | + if (i->i_ino == AUFS_ROOT_INO) |
1facf9fc | 3727 | + continue; |
3728 | + | |
7f207e10 | 3729 | + /* AuDbgInode(i); */ |
537831f9 | 3730 | + if (au_iigen(i, NULL) == sigen) |
1facf9fc | 3731 | + ii_read_lock_child(i); |
3732 | + else { | |
3733 | + ii_write_lock_child(i); | |
027c5e7a AM |
3734 | + err = au_refresh_hinode_self(i); |
3735 | + au_iigen_dec(i); | |
1facf9fc | 3736 | + if (!err) |
3737 | + ii_downgrade_lock(i); | |
3738 | + else { | |
3739 | + ii_write_unlock(i); | |
3740 | + break; | |
3741 | + } | |
3742 | + } | |
3743 | + | |
5afbbe0d AM |
3744 | + btop = au_ibtop(i); |
3745 | + bbot = au_ibbot(i); | |
3746 | + if (btop <= bindex | |
3747 | + && bindex <= bbot | |
1facf9fc | 3748 | + && au_h_iptr(i, bindex) |
5afbbe0d | 3749 | + && au_test_ibusy(i, btop, bbot)) { |
1facf9fc | 3750 | + err = -EBUSY; |
3751 | + AuVerbose(verbose, "busy i%lu\n", i->i_ino); | |
7f207e10 | 3752 | + AuDbgInode(i); |
1facf9fc | 3753 | + } |
3754 | + ii_read_unlock(i); | |
3755 | + } | |
7f207e10 | 3756 | + au_iarray_free(array, max); |
1facf9fc | 3757 | + |
7f207e10 | 3758 | +out: |
1facf9fc | 3759 | + return err; |
3760 | +} | |
3761 | + | |
b752ccd1 AM |
3762 | +static int test_children_busy(struct dentry *root, aufs_bindex_t bindex, |
3763 | + const unsigned int verbose) | |
1facf9fc | 3764 | +{ |
3765 | + int err; | |
3766 | + unsigned int sigen; | |
3767 | + | |
3768 | + sigen = au_sigen(root->d_sb); | |
3769 | + DiMustNoWaiters(root); | |
5527c038 | 3770 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 3771 | + di_write_unlock(root); |
b752ccd1 | 3772 | + err = test_dentry_busy(root, bindex, sigen, verbose); |
1facf9fc | 3773 | + if (!err) |
b752ccd1 | 3774 | + err = test_inode_busy(root->d_sb, bindex, sigen, verbose); |
1facf9fc | 3775 | + di_write_lock_child(root); /* aufs_write_lock() calls ..._child() */ |
3776 | + | |
3777 | + return err; | |
3778 | +} | |
3779 | + | |
076b876e AM |
3780 | +static int test_dir_busy(struct file *file, aufs_bindex_t br_id, |
3781 | + struct file **to_free, int *idx) | |
3782 | +{ | |
3783 | + int err; | |
c1595e42 | 3784 | + unsigned char matched, root; |
5afbbe0d | 3785 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
3786 | + struct au_fidir *fidir; |
3787 | + struct au_hfile *hfile; | |
3788 | + | |
3789 | + err = 0; | |
2000de60 | 3790 | + root = IS_ROOT(file->f_path.dentry); |
c1595e42 JR |
3791 | + if (root) { |
3792 | + get_file(file); | |
3793 | + to_free[*idx] = file; | |
3794 | + (*idx)++; | |
3795 | + goto out; | |
3796 | + } | |
3797 | + | |
076b876e | 3798 | + matched = 0; |
076b876e AM |
3799 | + fidir = au_fi(file)->fi_hdir; |
3800 | + AuDebugOn(!fidir); | |
5afbbe0d AM |
3801 | + bbot = au_fbbot_dir(file); |
3802 | + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) { | |
076b876e AM |
3803 | + hfile = fidir->fd_hfile + bindex; |
3804 | + if (!hfile->hf_file) | |
3805 | + continue; | |
3806 | + | |
c1595e42 | 3807 | + if (hfile->hf_br->br_id == br_id) { |
076b876e | 3808 | + matched = 1; |
076b876e | 3809 | + break; |
c1595e42 | 3810 | + } |
076b876e | 3811 | + } |
c1595e42 | 3812 | + if (matched) |
076b876e AM |
3813 | + err = -EBUSY; |
3814 | + | |
3815 | +out: | |
3816 | + return err; | |
3817 | +} | |
3818 | + | |
3819 | +static int test_file_busy(struct super_block *sb, aufs_bindex_t br_id, | |
3820 | + struct file **to_free, int opened) | |
3821 | +{ | |
3822 | + int err, idx; | |
3823 | + unsigned long long ull, max; | |
5afbbe0d | 3824 | + aufs_bindex_t btop; |
076b876e | 3825 | + struct file *file, **array; |
076b876e AM |
3826 | + struct dentry *root; |
3827 | + struct au_hfile *hfile; | |
3828 | + | |
3829 | + array = au_farray_alloc(sb, &max); | |
3830 | + err = PTR_ERR(array); | |
3831 | + if (IS_ERR(array)) | |
3832 | + goto out; | |
3833 | + | |
3834 | + err = 0; | |
3835 | + idx = 0; | |
3836 | + root = sb->s_root; | |
3837 | + di_write_unlock(root); | |
3838 | + for (ull = 0; ull < max; ull++) { | |
3839 | + file = array[ull]; | |
3840 | + if (unlikely(!file)) | |
3841 | + break; | |
3842 | + | |
3843 | + /* AuDbg("%pD\n", file); */ | |
3844 | + fi_read_lock(file); | |
5afbbe0d | 3845 | + btop = au_fbtop(file); |
2000de60 | 3846 | + if (!d_is_dir(file->f_path.dentry)) { |
076b876e AM |
3847 | + hfile = &au_fi(file)->fi_htop; |
3848 | + if (hfile->hf_br->br_id == br_id) | |
3849 | + err = -EBUSY; | |
3850 | + } else | |
3851 | + err = test_dir_busy(file, br_id, to_free, &idx); | |
3852 | + fi_read_unlock(file); | |
3853 | + if (unlikely(err)) | |
3854 | + break; | |
3855 | + } | |
3856 | + di_write_lock_child(root); | |
3857 | + au_farray_free(array, max); | |
3858 | + AuDebugOn(idx > opened); | |
3859 | + | |
3860 | +out: | |
3861 | + return err; | |
3862 | +} | |
3863 | + | |
3864 | +static void br_del_file(struct file **to_free, unsigned long long opened, | |
062440b3 | 3865 | + aufs_bindex_t br_id) |
076b876e AM |
3866 | +{ |
3867 | + unsigned long long ull; | |
5afbbe0d | 3868 | + aufs_bindex_t bindex, btop, bbot, bfound; |
076b876e AM |
3869 | + struct file *file; |
3870 | + struct au_fidir *fidir; | |
3871 | + struct au_hfile *hfile; | |
3872 | + | |
3873 | + for (ull = 0; ull < opened; ull++) { | |
3874 | + file = to_free[ull]; | |
3875 | + if (unlikely(!file)) | |
3876 | + break; | |
3877 | + | |
3878 | + /* AuDbg("%pD\n", file); */ | |
2000de60 | 3879 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
076b876e AM |
3880 | + bfound = -1; |
3881 | + fidir = au_fi(file)->fi_hdir; | |
3882 | + AuDebugOn(!fidir); | |
3883 | + fi_write_lock(file); | |
5afbbe0d AM |
3884 | + btop = au_fbtop(file); |
3885 | + bbot = au_fbbot_dir(file); | |
3886 | + for (bindex = btop; bindex <= bbot; bindex++) { | |
076b876e AM |
3887 | + hfile = fidir->fd_hfile + bindex; |
3888 | + if (!hfile->hf_file) | |
3889 | + continue; | |
3890 | + | |
3891 | + if (hfile->hf_br->br_id == br_id) { | |
3892 | + bfound = bindex; | |
3893 | + break; | |
3894 | + } | |
3895 | + } | |
3896 | + AuDebugOn(bfound < 0); | |
3897 | + au_set_h_fptr(file, bfound, NULL); | |
5afbbe0d AM |
3898 | + if (bfound == btop) { |
3899 | + for (btop++; btop <= bbot; btop++) | |
3900 | + if (au_hf_dir(file, btop)) { | |
3901 | + au_set_fbtop(file, btop); | |
076b876e AM |
3902 | + break; |
3903 | + } | |
3904 | + } | |
3905 | + fi_write_unlock(file); | |
3906 | + } | |
3907 | +} | |
3908 | + | |
1facf9fc | 3909 | +static void au_br_do_del_brp(struct au_sbinfo *sbinfo, |
3910 | + const aufs_bindex_t bindex, | |
5afbbe0d | 3911 | + const aufs_bindex_t bbot) |
1facf9fc | 3912 | +{ |
3913 | + struct au_branch **brp, **p; | |
3914 | + | |
dece6358 AM |
3915 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
3916 | + | |
1facf9fc | 3917 | + brp = sbinfo->si_branch + bindex; |
5afbbe0d AM |
3918 | + if (bindex < bbot) |
3919 | + memmove(brp, brp + 1, sizeof(*brp) * (bbot - bindex)); | |
3920 | + sbinfo->si_branch[0 + bbot] = NULL; | |
3921 | + sbinfo->si_bbot--; | |
1facf9fc | 3922 | + |
e2f27e51 AM |
3923 | + p = au_krealloc(sbinfo->si_branch, sizeof(*p) * bbot, AuGFP_SBILIST, |
3924 | + /*may_shrink*/1); | |
1facf9fc | 3925 | + if (p) |
3926 | + sbinfo->si_branch = p; | |
4a4d8108 | 3927 | + /* harmless error */ |
1facf9fc | 3928 | +} |
3929 | + | |
3930 | +static void au_br_do_del_hdp(struct au_dinfo *dinfo, const aufs_bindex_t bindex, | |
5afbbe0d | 3931 | + const aufs_bindex_t bbot) |
1facf9fc | 3932 | +{ |
3933 | + struct au_hdentry *hdp, *p; | |
3934 | + | |
1308ab2a | 3935 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
3936 | + | |
5afbbe0d AM |
3937 | + hdp = au_hdentry(dinfo, bindex); |
3938 | + if (bindex < bbot) | |
3939 | + memmove(hdp, hdp + 1, sizeof(*hdp) * (bbot - bindex)); | |
3940 | + /* au_h_dentry_init(au_hdentry(dinfo, bbot); */ | |
3941 | + dinfo->di_bbot--; | |
1facf9fc | 3942 | + |
e2f27e51 AM |
3943 | + p = au_krealloc(dinfo->di_hdentry, sizeof(*p) * bbot, AuGFP_SBILIST, |
3944 | + /*may_shrink*/1); | |
1facf9fc | 3945 | + if (p) |
3946 | + dinfo->di_hdentry = p; | |
4a4d8108 | 3947 | + /* harmless error */ |
1facf9fc | 3948 | +} |
3949 | + | |
3950 | +static void au_br_do_del_hip(struct au_iinfo *iinfo, const aufs_bindex_t bindex, | |
5afbbe0d | 3951 | + const aufs_bindex_t bbot) |
1facf9fc | 3952 | +{ |
3953 | + struct au_hinode *hip, *p; | |
3954 | + | |
1308ab2a | 3955 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
3956 | + | |
5afbbe0d AM |
3957 | + hip = au_hinode(iinfo, bindex); |
3958 | + if (bindex < bbot) | |
3959 | + memmove(hip, hip + 1, sizeof(*hip) * (bbot - bindex)); | |
3960 | + /* au_hinode_init(au_hinode(iinfo, bbot)); */ | |
3961 | + iinfo->ii_bbot--; | |
1facf9fc | 3962 | + |
e2f27e51 AM |
3963 | + p = au_krealloc(iinfo->ii_hinode, sizeof(*p) * bbot, AuGFP_SBILIST, |
3964 | + /*may_shrink*/1); | |
1facf9fc | 3965 | + if (p) |
3966 | + iinfo->ii_hinode = p; | |
4a4d8108 | 3967 | + /* harmless error */ |
1facf9fc | 3968 | +} |
3969 | + | |
3970 | +static void au_br_do_del(struct super_block *sb, aufs_bindex_t bindex, | |
3971 | + struct au_branch *br) | |
3972 | +{ | |
5afbbe0d | 3973 | + aufs_bindex_t bbot; |
1facf9fc | 3974 | + struct au_sbinfo *sbinfo; |
53392da6 AM |
3975 | + struct dentry *root, *h_root; |
3976 | + struct inode *inode, *h_inode; | |
3977 | + struct au_hinode *hinode; | |
1facf9fc | 3978 | + |
dece6358 AM |
3979 | + SiMustWriteLock(sb); |
3980 | + | |
1facf9fc | 3981 | + root = sb->s_root; |
5527c038 | 3982 | + inode = d_inode(root); |
1facf9fc | 3983 | + sbinfo = au_sbi(sb); |
5afbbe0d | 3984 | + bbot = sbinfo->si_bbot; |
1facf9fc | 3985 | + |
53392da6 AM |
3986 | + h_root = au_h_dptr(root, bindex); |
3987 | + hinode = au_hi(inode, bindex); | |
3988 | + h_inode = au_igrab(hinode->hi_inode); | |
3989 | + au_hiput(hinode); | |
1facf9fc | 3990 | + |
53392da6 | 3991 | + au_sbilist_lock(); |
5afbbe0d AM |
3992 | + au_br_do_del_brp(sbinfo, bindex, bbot); |
3993 | + au_br_do_del_hdp(au_di(root), bindex, bbot); | |
3994 | + au_br_do_del_hip(au_ii(inode), bindex, bbot); | |
53392da6 AM |
3995 | + au_sbilist_unlock(); |
3996 | + | |
8b6a4947 AM |
3997 | + /* ignore an error */ |
3998 | + au_dr_br_fin(sb, br); /* always, regardless the mount option */ | |
3999 | + | |
53392da6 AM |
4000 | + dput(h_root); |
4001 | + iput(h_inode); | |
4002 | + au_br_do_free(br); | |
1facf9fc | 4003 | +} |
4004 | + | |
79b8bda9 AM |
4005 | +static unsigned long long empty_cb(struct super_block *sb, void *array, |
4006 | + unsigned long long max, void *arg) | |
076b876e AM |
4007 | +{ |
4008 | + return max; | |
4009 | +} | |
4010 | + | |
1facf9fc | 4011 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount) |
4012 | +{ | |
4013 | + int err, rerr, i; | |
076b876e | 4014 | + unsigned long long opened; |
1facf9fc | 4015 | + unsigned int mnt_flags; |
5afbbe0d | 4016 | + aufs_bindex_t bindex, bbot, br_id; |
1facf9fc | 4017 | + unsigned char do_wh, verbose; |
4018 | + struct au_branch *br; | |
4019 | + struct au_wbr *wbr; | |
076b876e AM |
4020 | + struct dentry *root; |
4021 | + struct file **to_free; | |
1facf9fc | 4022 | + |
4023 | + err = 0; | |
076b876e AM |
4024 | + opened = 0; |
4025 | + to_free = NULL; | |
4026 | + root = sb->s_root; | |
4027 | + bindex = au_find_dbindex(root, del->h_path.dentry); | |
1facf9fc | 4028 | + if (bindex < 0) { |
4029 | + if (remount) | |
4030 | + goto out; /* success */ | |
4031 | + err = -ENOENT; | |
4a4d8108 | 4032 | + pr_err("%s no such branch\n", del->pathname); |
1facf9fc | 4033 | + goto out; |
4034 | + } | |
4035 | + AuDbg("bindex b%d\n", bindex); | |
4036 | + | |
4037 | + err = -EBUSY; | |
4038 | + mnt_flags = au_mntflags(sb); | |
4039 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
5afbbe0d AM |
4040 | + bbot = au_sbbot(sb); |
4041 | + if (unlikely(!bbot)) { | |
1facf9fc | 4042 | + AuVerbose(verbose, "no more branches left\n"); |
4043 | + goto out; | |
4044 | + } | |
acd2b654 | 4045 | + |
1facf9fc | 4046 | + br = au_sbr(sb, bindex); |
86dc4139 | 4047 | + AuDebugOn(!path_equal(&br->br_path, &del->h_path)); |
acd2b654 AM |
4048 | + if (unlikely(au_lcnt_read(&br->br_count, /*do_rev*/1))) { |
4049 | + AuVerbose(verbose, "br %pd2 is busy now\n", del->h_path.dentry); | |
4050 | + goto out; | |
4051 | + } | |
076b876e AM |
4052 | + |
4053 | + br_id = br->br_id; | |
acd2b654 | 4054 | + opened = au_lcnt_read(&br->br_nfiles, /*do_rev*/1); |
076b876e | 4055 | + if (unlikely(opened)) { |
79b8bda9 | 4056 | + to_free = au_array_alloc(&opened, empty_cb, sb, NULL); |
076b876e AM |
4057 | + err = PTR_ERR(to_free); |
4058 | + if (IS_ERR(to_free)) | |
4059 | + goto out; | |
4060 | + | |
4061 | + err = test_file_busy(sb, br_id, to_free, opened); | |
4062 | + if (unlikely(err)) { | |
4063 | + AuVerbose(verbose, "%llu file(s) opened\n", opened); | |
4064 | + goto out; | |
4065 | + } | |
1facf9fc | 4066 | + } |
4067 | + | |
4068 | + wbr = br->br_wbr; | |
4069 | + do_wh = wbr && (wbr->wbr_whbase || wbr->wbr_plink || wbr->wbr_orph); | |
4070 | + if (do_wh) { | |
1308ab2a | 4071 | + /* instead of WbrWhMustWriteLock(wbr) */ |
4072 | + SiMustWriteLock(sb); | |
1facf9fc | 4073 | + for (i = 0; i < AuBrWh_Last; i++) { |
4074 | + dput(wbr->wbr_wh[i]); | |
4075 | + wbr->wbr_wh[i] = NULL; | |
4076 | + } | |
4077 | + } | |
4078 | + | |
076b876e | 4079 | + err = test_children_busy(root, bindex, verbose); |
1facf9fc | 4080 | + if (unlikely(err)) { |
4081 | + if (do_wh) | |
4082 | + goto out_wh; | |
4083 | + goto out; | |
4084 | + } | |
4085 | + | |
4086 | + err = 0; | |
076b876e AM |
4087 | + if (to_free) { |
4088 | + /* | |
4089 | + * now we confirmed the branch is deletable. | |
4090 | + * let's free the remaining opened dirs on the branch. | |
4091 | + */ | |
4092 | + di_write_unlock(root); | |
4093 | + br_del_file(to_free, opened, br_id); | |
4094 | + di_write_lock_child(root); | |
4095 | + } | |
4096 | + | |
062440b3 AM |
4097 | + sysaufs_brs_del(sb, bindex); /* remove successors */ |
4098 | + dbgaufs_xino_del(br); /* remove one */ | |
4099 | + au_br_do_del(sb, bindex, br); | |
4100 | + sysaufs_brs_add(sb, bindex); /* append successors */ | |
4101 | + dbgaufs_brs_add(sb, bindex, /*topdown*/1); /* rename successors */ | |
1facf9fc | 4102 | + |
1308ab2a | 4103 | + if (!bindex) { |
5527c038 | 4104 | + au_cpup_attr_all(d_inode(root), /*force*/1); |
1308ab2a | 4105 | + sb->s_maxbytes = au_sbr_sb(sb, 0)->s_maxbytes; |
4106 | + } else | |
5527c038 | 4107 | + au_sub_nlink(d_inode(root), d_inode(del->h_path.dentry)); |
1facf9fc | 4108 | + if (au_opt_test(mnt_flags, PLINK)) |
4109 | + au_plink_half_refresh(sb, br_id); | |
4110 | + | |
1facf9fc | 4111 | + goto out; /* success */ |
4112 | + | |
4f0767ce | 4113 | +out_wh: |
1facf9fc | 4114 | + /* revert */ |
86dc4139 | 4115 | + rerr = au_br_init_wh(sb, br, br->br_perm); |
1facf9fc | 4116 | + if (rerr) |
0c3ec466 AM |
4117 | + pr_warn("failed re-creating base whiteout, %s. (%d)\n", |
4118 | + del->pathname, rerr); | |
4f0767ce | 4119 | +out: |
076b876e AM |
4120 | + if (to_free) |
4121 | + au_farray_free(to_free, opened); | |
1facf9fc | 4122 | + return err; |
4123 | +} | |
4124 | + | |
4125 | +/* ---------------------------------------------------------------------- */ | |
4126 | + | |
027c5e7a AM |
4127 | +static int au_ibusy(struct super_block *sb, struct aufs_ibusy __user *arg) |
4128 | +{ | |
4129 | + int err; | |
5afbbe0d | 4130 | + aufs_bindex_t btop, bbot; |
027c5e7a AM |
4131 | + struct aufs_ibusy ibusy; |
4132 | + struct inode *inode, *h_inode; | |
4133 | + | |
4134 | + err = -EPERM; | |
4135 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
4136 | + goto out; | |
4137 | + | |
4138 | + err = copy_from_user(&ibusy, arg, sizeof(ibusy)); | |
4139 | + if (!err) | |
ba1aed25 AM |
4140 | + /* VERIFY_WRITE */ |
4141 | + err = !access_ok(&arg->h_ino, sizeof(arg->h_ino)); | |
027c5e7a AM |
4142 | + if (unlikely(err)) { |
4143 | + err = -EFAULT; | |
4144 | + AuTraceErr(err); | |
4145 | + goto out; | |
4146 | + } | |
4147 | + | |
4148 | + err = -EINVAL; | |
4149 | + si_read_lock(sb, AuLock_FLUSH); | |
5afbbe0d | 4150 | + if (unlikely(ibusy.bindex < 0 || ibusy.bindex > au_sbbot(sb))) |
027c5e7a AM |
4151 | + goto out_unlock; |
4152 | + | |
4153 | + err = 0; | |
4154 | + ibusy.h_ino = 0; /* invalid */ | |
4155 | + inode = ilookup(sb, ibusy.ino); | |
4156 | + if (!inode | |
4157 | + || inode->i_ino == AUFS_ROOT_INO | |
5afbbe0d | 4158 | + || au_is_bad_inode(inode)) |
027c5e7a AM |
4159 | + goto out_unlock; |
4160 | + | |
4161 | + ii_read_lock_child(inode); | |
5afbbe0d AM |
4162 | + btop = au_ibtop(inode); |
4163 | + bbot = au_ibbot(inode); | |
4164 | + if (btop <= ibusy.bindex && ibusy.bindex <= bbot) { | |
027c5e7a | 4165 | + h_inode = au_h_iptr(inode, ibusy.bindex); |
5afbbe0d | 4166 | + if (h_inode && au_test_ibusy(inode, btop, bbot)) |
027c5e7a AM |
4167 | + ibusy.h_ino = h_inode->i_ino; |
4168 | + } | |
4169 | + ii_read_unlock(inode); | |
4170 | + iput(inode); | |
4171 | + | |
4172 | +out_unlock: | |
4173 | + si_read_unlock(sb); | |
4174 | + if (!err) { | |
4175 | + err = __put_user(ibusy.h_ino, &arg->h_ino); | |
4176 | + if (unlikely(err)) { | |
4177 | + err = -EFAULT; | |
4178 | + AuTraceErr(err); | |
4179 | + } | |
4180 | + } | |
4181 | +out: | |
4182 | + return err; | |
4183 | +} | |
4184 | + | |
4185 | +long au_ibusy_ioctl(struct file *file, unsigned long arg) | |
4186 | +{ | |
2000de60 | 4187 | + return au_ibusy(file->f_path.dentry->d_sb, (void __user *)arg); |
027c5e7a AM |
4188 | +} |
4189 | + | |
4190 | +#ifdef CONFIG_COMPAT | |
4191 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg) | |
4192 | +{ | |
2000de60 | 4193 | + return au_ibusy(file->f_path.dentry->d_sb, compat_ptr(arg)); |
027c5e7a AM |
4194 | +} |
4195 | +#endif | |
4196 | + | |
4197 | +/* ---------------------------------------------------------------------- */ | |
4198 | + | |
1facf9fc | 4199 | +/* |
4200 | + * change a branch permission | |
4201 | + */ | |
4202 | + | |
dece6358 AM |
4203 | +static void au_warn_ima(void) |
4204 | +{ | |
4205 | +#ifdef CONFIG_IMA | |
1308ab2a | 4206 | + /* since it doesn't support mark_files_ro() */ |
027c5e7a | 4207 | + AuWarn1("RW -> RO makes IMA to produce wrong message\n"); |
dece6358 AM |
4208 | +#endif |
4209 | +} | |
4210 | + | |
1facf9fc | 4211 | +static int do_need_sigen_inc(int a, int b) |
4212 | +{ | |
4213 | + return au_br_whable(a) && !au_br_whable(b); | |
4214 | +} | |
4215 | + | |
4216 | +static int need_sigen_inc(int old, int new) | |
4217 | +{ | |
4218 | + return do_need_sigen_inc(old, new) | |
4219 | + || do_need_sigen_inc(new, old); | |
4220 | +} | |
4221 | + | |
4222 | +static int au_br_mod_files_ro(struct super_block *sb, aufs_bindex_t bindex) | |
4223 | +{ | |
7f207e10 | 4224 | + int err, do_warn; |
027c5e7a | 4225 | + unsigned int mnt_flags; |
7f207e10 | 4226 | + unsigned long long ull, max; |
e49829fe | 4227 | + aufs_bindex_t br_id; |
38d290e6 | 4228 | + unsigned char verbose, writer; |
7f207e10 | 4229 | + struct file *file, *hf, **array; |
e49829fe | 4230 | + struct au_hfile *hfile; |
eca34b5c | 4231 | + struct inode *h_inode; |
1facf9fc | 4232 | + |
027c5e7a AM |
4233 | + mnt_flags = au_mntflags(sb); |
4234 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
4235 | + | |
7f207e10 AM |
4236 | + array = au_farray_alloc(sb, &max); |
4237 | + err = PTR_ERR(array); | |
4238 | + if (IS_ERR(array)) | |
1facf9fc | 4239 | + goto out; |
4240 | + | |
7f207e10 | 4241 | + do_warn = 0; |
e49829fe | 4242 | + br_id = au_sbr_id(sb, bindex); |
7f207e10 AM |
4243 | + for (ull = 0; ull < max; ull++) { |
4244 | + file = array[ull]; | |
076b876e AM |
4245 | + if (unlikely(!file)) |
4246 | + break; | |
1facf9fc | 4247 | + |
523b37e3 | 4248 | + /* AuDbg("%pD\n", file); */ |
1facf9fc | 4249 | + fi_read_lock(file); |
4250 | + if (unlikely(au_test_mmapped(file))) { | |
4251 | + err = -EBUSY; | |
523b37e3 | 4252 | + AuVerbose(verbose, "mmapped %pD\n", file); |
7f207e10 | 4253 | + AuDbgFile(file); |
1facf9fc | 4254 | + FiMustNoWaiters(file); |
4255 | + fi_read_unlock(file); | |
7f207e10 | 4256 | + goto out_array; |
1facf9fc | 4257 | + } |
4258 | + | |
e49829fe JR |
4259 | + hfile = &au_fi(file)->fi_htop; |
4260 | + hf = hfile->hf_file; | |
7e9cd9fe | 4261 | + if (!d_is_reg(file->f_path.dentry) |
1facf9fc | 4262 | + || !(file->f_mode & FMODE_WRITE) |
e49829fe | 4263 | + || hfile->hf_br->br_id != br_id |
7f207e10 AM |
4264 | + || !(hf->f_mode & FMODE_WRITE)) |
4265 | + array[ull] = NULL; | |
4266 | + else { | |
4267 | + do_warn = 1; | |
4268 | + get_file(file); | |
1facf9fc | 4269 | + } |
4270 | + | |
1facf9fc | 4271 | + FiMustNoWaiters(file); |
4272 | + fi_read_unlock(file); | |
7f207e10 AM |
4273 | + fput(file); |
4274 | + } | |
1facf9fc | 4275 | + |
4276 | + err = 0; | |
7f207e10 | 4277 | + if (do_warn) |
dece6358 | 4278 | + au_warn_ima(); |
7f207e10 AM |
4279 | + |
4280 | + for (ull = 0; ull < max; ull++) { | |
4281 | + file = array[ull]; | |
4282 | + if (!file) | |
4283 | + continue; | |
4284 | + | |
1facf9fc | 4285 | + /* todo: already flushed? */ |
523b37e3 AM |
4286 | + /* |
4287 | + * fs/super.c:mark_files_ro() is gone, but aufs keeps its | |
4288 | + * approach which resets f_mode and calls mnt_drop_write() and | |
4289 | + * file_release_write() for each file, because the branch | |
4290 | + * attribute in aufs world is totally different from the native | |
4291 | + * fs rw/ro mode. | |
4292 | + */ | |
7f207e10 AM |
4293 | + /* fi_read_lock(file); */ |
4294 | + hfile = &au_fi(file)->fi_htop; | |
4295 | + hf = hfile->hf_file; | |
4296 | + /* fi_read_unlock(file); */ | |
027c5e7a | 4297 | + spin_lock(&hf->f_lock); |
38d290e6 JR |
4298 | + writer = !!(hf->f_mode & FMODE_WRITER); |
4299 | + hf->f_mode &= ~(FMODE_WRITE | FMODE_WRITER); | |
027c5e7a | 4300 | + spin_unlock(&hf->f_lock); |
38d290e6 | 4301 | + if (writer) { |
eca34b5c AM |
4302 | + h_inode = file_inode(hf); |
4303 | + put_write_access(h_inode); | |
c06a8ce3 | 4304 | + __mnt_drop_write(hf->f_path.mnt); |
eca34b5c AM |
4305 | + if ((hf->f_mode & (FMODE_READ | FMODE_WRITE)) |
4306 | + == FMODE_READ) | |
4307 | + i_readcount_inc(h_inode); | |
1facf9fc | 4308 | + } |
4309 | + } | |
4310 | + | |
7f207e10 AM |
4311 | +out_array: |
4312 | + au_farray_free(array, max); | |
4f0767ce | 4313 | +out: |
7f207e10 | 4314 | + AuTraceErr(err); |
1facf9fc | 4315 | + return err; |
4316 | +} | |
4317 | + | |
4318 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4319 | + int *do_refresh) |
1facf9fc | 4320 | +{ |
4321 | + int err, rerr; | |
4322 | + aufs_bindex_t bindex; | |
4323 | + struct dentry *root; | |
4324 | + struct au_branch *br; | |
076b876e | 4325 | + struct au_br_fhsm *bf; |
1facf9fc | 4326 | + |
4327 | + root = sb->s_root; | |
1facf9fc | 4328 | + bindex = au_find_dbindex(root, mod->h_root); |
4329 | + if (bindex < 0) { | |
4330 | + if (remount) | |
4331 | + return 0; /* success */ | |
4332 | + err = -ENOENT; | |
4a4d8108 | 4333 | + pr_err("%s no such branch\n", mod->path); |
1facf9fc | 4334 | + goto out; |
4335 | + } | |
4336 | + AuDbg("bindex b%d\n", bindex); | |
4337 | + | |
5527c038 | 4338 | + err = test_br(d_inode(mod->h_root), mod->perm, mod->path); |
1facf9fc | 4339 | + if (unlikely(err)) |
4340 | + goto out; | |
4341 | + | |
4342 | + br = au_sbr(sb, bindex); | |
86dc4139 | 4343 | + AuDebugOn(mod->h_root != au_br_dentry(br)); |
1facf9fc | 4344 | + if (br->br_perm == mod->perm) |
4345 | + return 0; /* success */ | |
4346 | + | |
076b876e AM |
4347 | + /* pre-allocate for non-fhsm --> fhsm */ |
4348 | + bf = NULL; | |
4349 | + if (!au_br_fhsm(br->br_perm) && au_br_fhsm(mod->perm)) { | |
4350 | + err = au_fhsm_br_alloc(br); | |
4351 | + if (unlikely(err)) | |
4352 | + goto out; | |
4353 | + bf = br->br_fhsm; | |
4354 | + br->br_fhsm = NULL; | |
4355 | + } | |
4356 | + | |
1facf9fc | 4357 | + if (au_br_writable(br->br_perm)) { |
4358 | + /* remove whiteout base */ | |
86dc4139 | 4359 | + err = au_br_init_wh(sb, br, mod->perm); |
1facf9fc | 4360 | + if (unlikely(err)) |
076b876e | 4361 | + goto out_bf; |
1facf9fc | 4362 | + |
4363 | + if (!au_br_writable(mod->perm)) { | |
4364 | + /* rw --> ro, file might be mmapped */ | |
4365 | + DiMustNoWaiters(root); | |
5527c038 | 4366 | + IiMustNoWaiters(d_inode(root)); |
1facf9fc | 4367 | + di_write_unlock(root); |
4368 | + err = au_br_mod_files_ro(sb, bindex); | |
4369 | + /* aufs_write_lock() calls ..._child() */ | |
4370 | + di_write_lock_child(root); | |
4371 | + | |
4372 | + if (unlikely(err)) { | |
4373 | + rerr = -ENOMEM; | |
be52b249 | 4374 | + br->br_wbr = kzalloc(sizeof(*br->br_wbr), |
1facf9fc | 4375 | + GFP_NOFS); |
86dc4139 AM |
4376 | + if (br->br_wbr) |
4377 | + rerr = au_wbr_init(br, sb, br->br_perm); | |
1facf9fc | 4378 | + if (unlikely(rerr)) { |
4379 | + AuIOErr("nested error %d (%d)\n", | |
4380 | + rerr, err); | |
4381 | + br->br_perm = mod->perm; | |
4382 | + } | |
4383 | + } | |
4384 | + } | |
4385 | + } else if (au_br_writable(mod->perm)) { | |
4386 | + /* ro --> rw */ | |
4387 | + err = -ENOMEM; | |
be52b249 | 4388 | + br->br_wbr = kzalloc(sizeof(*br->br_wbr), GFP_NOFS); |
1facf9fc | 4389 | + if (br->br_wbr) { |
86dc4139 | 4390 | + err = au_wbr_init(br, sb, mod->perm); |
1facf9fc | 4391 | + if (unlikely(err)) { |
9f237c51 | 4392 | + au_kfree_rcu(br->br_wbr); |
1facf9fc | 4393 | + br->br_wbr = NULL; |
4394 | + } | |
4395 | + } | |
4396 | + } | |
076b876e AM |
4397 | + if (unlikely(err)) |
4398 | + goto out_bf; | |
4399 | + | |
4400 | + if (au_br_fhsm(br->br_perm)) { | |
4401 | + if (!au_br_fhsm(mod->perm)) { | |
4402 | + /* fhsm --> non-fhsm */ | |
4403 | + au_br_fhsm_fin(br->br_fhsm); | |
9f237c51 | 4404 | + au_kfree_rcu(br->br_fhsm); |
076b876e AM |
4405 | + br->br_fhsm = NULL; |
4406 | + } | |
4407 | + } else if (au_br_fhsm(mod->perm)) | |
4408 | + /* non-fhsm --> fhsm */ | |
4409 | + br->br_fhsm = bf; | |
4410 | + | |
076b876e AM |
4411 | + *do_refresh |= need_sigen_inc(br->br_perm, mod->perm); |
4412 | + br->br_perm = mod->perm; | |
4413 | + goto out; /* success */ | |
1facf9fc | 4414 | + |
076b876e | 4415 | +out_bf: |
9f237c51 | 4416 | + au_kfree_try_rcu(bf); |
076b876e AM |
4417 | +out: |
4418 | + AuTraceErr(err); | |
4419 | + return err; | |
4420 | +} | |
4421 | + | |
4422 | +/* ---------------------------------------------------------------------- */ | |
4423 | + | |
4424 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs) | |
4425 | +{ | |
4426 | + int err; | |
4427 | + struct kstatfs kstfs; | |
4428 | + | |
4429 | + err = vfs_statfs(&br->br_path, &kstfs); | |
1facf9fc | 4430 | + if (!err) { |
076b876e AM |
4431 | + stfs->f_blocks = kstfs.f_blocks; |
4432 | + stfs->f_bavail = kstfs.f_bavail; | |
4433 | + stfs->f_files = kstfs.f_files; | |
4434 | + stfs->f_ffree = kstfs.f_ffree; | |
1facf9fc | 4435 | + } |
4436 | + | |
1facf9fc | 4437 | + return err; |
4438 | +} | |
7f207e10 | 4439 | diff -urN /usr/share/empty/fs/aufs/branch.h linux/fs/aufs/branch.h |
eca34b5c | 4440 | --- /usr/share/empty/fs/aufs/branch.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 4441 | +++ linux/fs/aufs/branch.h 2020-01-27 10:57:18.165538015 +0100 |
83b672a5 | 4442 | @@ -0,0 +1,366 @@ |
062440b3 | 4443 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 4444 | +/* |
d58c55f2 | 4445 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 4446 | + * |
4447 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4448 | + * it under the terms of the GNU General Public License as published by | |
4449 | + * the Free Software Foundation; either version 2 of the License, or | |
4450 | + * (at your option) any later version. | |
dece6358 AM |
4451 | + * |
4452 | + * This program is distributed in the hope that it will be useful, | |
4453 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4454 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4455 | + * GNU General Public License for more details. | |
4456 | + * | |
4457 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4458 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4459 | + */ |
4460 | + | |
4461 | +/* | |
4462 | + * branch filesystems and xino for them | |
4463 | + */ | |
4464 | + | |
4465 | +#ifndef __AUFS_BRANCH_H__ | |
4466 | +#define __AUFS_BRANCH_H__ | |
4467 | + | |
4468 | +#ifdef __KERNEL__ | |
4469 | + | |
1facf9fc | 4470 | +#include <linux/mount.h> |
8b6a4947 | 4471 | +#include "dirren.h" |
4a4d8108 | 4472 | +#include "dynop.h" |
acd2b654 | 4473 | +#include "lcnt.h" |
1facf9fc | 4474 | +#include "rwsem.h" |
4475 | +#include "super.h" | |
4476 | + | |
4477 | +/* ---------------------------------------------------------------------- */ | |
4478 | + | |
4479 | +/* a xino file */ | |
062440b3 | 4480 | +struct au_xino { |
acd2b654 AM |
4481 | + struct file **xi_file; |
4482 | + unsigned int xi_nfile; | |
4483 | + | |
521ced18 JR |
4484 | + struct { |
4485 | + spinlock_t spin; | |
4486 | + ino_t *array; | |
4487 | + int total; | |
4488 | + /* reserved for future use */ | |
4489 | + /* unsigned long *bitmap; */ | |
4490 | + wait_queue_head_t wqh; | |
4491 | + } xi_nondir; | |
1facf9fc | 4492 | + |
acd2b654 | 4493 | + struct mutex xi_mtx; /* protects xi_file array */ |
9f237c51 | 4494 | + struct hlist_bl_head xi_writing; |
acd2b654 | 4495 | + |
062440b3 | 4496 | + atomic_t xi_truncating; |
1facf9fc | 4497 | + |
062440b3 | 4498 | + struct kref xi_kref; |
1facf9fc | 4499 | +}; |
4500 | + | |
076b876e AM |
4501 | +/* File-based Hierarchical Storage Management */ |
4502 | +struct au_br_fhsm { | |
4503 | +#ifdef CONFIG_AUFS_FHSM | |
4504 | + struct mutex bf_lock; | |
4505 | + unsigned long bf_jiffy; | |
4506 | + struct aufs_stfs bf_stfs; | |
4507 | + int bf_readable; | |
4508 | +#endif | |
4509 | +}; | |
4510 | + | |
1facf9fc | 4511 | +/* members for writable branch only */ |
4512 | +enum {AuBrWh_BASE, AuBrWh_PLINK, AuBrWh_ORPH, AuBrWh_Last}; | |
4513 | +struct au_wbr { | |
dece6358 | 4514 | + struct au_rwsem wbr_wh_rwsem; |
1facf9fc | 4515 | + struct dentry *wbr_wh[AuBrWh_Last]; |
4a4d8108 | 4516 | + atomic_t wbr_wh_running; |
1facf9fc | 4517 | +#define wbr_whbase wbr_wh[AuBrWh_BASE] /* whiteout base */ |
4518 | +#define wbr_plink wbr_wh[AuBrWh_PLINK] /* pseudo-link dir */ | |
4519 | +#define wbr_orph wbr_wh[AuBrWh_ORPH] /* dir for orphans */ | |
4520 | + | |
4521 | + /* mfs mode */ | |
4522 | + unsigned long long wbr_bytes; | |
4523 | +}; | |
4524 | + | |
4a4d8108 AM |
4525 | +/* ext2 has 3 types of operations at least, ext3 has 4 */ |
4526 | +#define AuBrDynOp (AuDyLast * 4) | |
4527 | + | |
1716fcea AM |
4528 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
4529 | +/* support for asynchronous destruction */ | |
4530 | +struct au_br_hfsnotify { | |
4531 | + struct fsnotify_group *hfsn_group; | |
4532 | +}; | |
4533 | +#endif | |
4534 | + | |
392086de AM |
4535 | +/* sysfs entries */ |
4536 | +struct au_brsysfs { | |
4537 | + char name[16]; | |
4538 | + struct attribute attr; | |
4539 | +}; | |
4540 | + | |
4541 | +enum { | |
4542 | + AuBrSysfs_BR, | |
4543 | + AuBrSysfs_BRID, | |
4544 | + AuBrSysfs_Last | |
4545 | +}; | |
4546 | + | |
1facf9fc | 4547 | +/* protected by superblock rwsem */ |
4548 | +struct au_branch { | |
062440b3 | 4549 | + struct au_xino *br_xino; |
1facf9fc | 4550 | + |
4551 | + aufs_bindex_t br_id; | |
4552 | + | |
4553 | + int br_perm; | |
86dc4139 | 4554 | + struct path br_path; |
4a4d8108 AM |
4555 | + spinlock_t br_dykey_lock; |
4556 | + struct au_dykey *br_dykey[AuBrDynOp]; | |
acd2b654 AM |
4557 | + au_lcnt_t br_nfiles; /* opened files */ |
4558 | + au_lcnt_t br_count; /* in-use for other */ | |
1facf9fc | 4559 | + |
4560 | + struct au_wbr *br_wbr; | |
076b876e | 4561 | + struct au_br_fhsm *br_fhsm; |
1facf9fc | 4562 | + |
027c5e7a | 4563 | +#ifdef CONFIG_AUFS_HFSNOTIFY |
1716fcea | 4564 | + struct au_br_hfsnotify *br_hfsn; |
027c5e7a AM |
4565 | +#endif |
4566 | + | |
1facf9fc | 4567 | +#ifdef CONFIG_SYSFS |
392086de AM |
4568 | + /* entries under sysfs per mount-point */ |
4569 | + struct au_brsysfs br_sysfs[AuBrSysfs_Last]; | |
1facf9fc | 4570 | +#endif |
8b6a4947 | 4571 | + |
062440b3 AM |
4572 | +#ifdef CONFIG_DEBUG_FS |
4573 | + struct dentry *br_dbgaufs; /* xino */ | |
4574 | +#endif | |
4575 | + | |
8b6a4947 | 4576 | + struct au_dr_br br_dirren; |
1facf9fc | 4577 | +}; |
4578 | + | |
4579 | +/* ---------------------------------------------------------------------- */ | |
4580 | + | |
86dc4139 AM |
4581 | +static inline struct vfsmount *au_br_mnt(struct au_branch *br) |
4582 | +{ | |
4583 | + return br->br_path.mnt; | |
4584 | +} | |
4585 | + | |
4586 | +static inline struct dentry *au_br_dentry(struct au_branch *br) | |
4587 | +{ | |
4588 | + return br->br_path.dentry; | |
4589 | +} | |
4590 | + | |
4591 | +static inline struct super_block *au_br_sb(struct au_branch *br) | |
4592 | +{ | |
4593 | + return au_br_mnt(br)->mnt_sb; | |
4594 | +} | |
4595 | + | |
1facf9fc | 4596 | +static inline int au_br_rdonly(struct au_branch *br) |
4597 | +{ | |
8b6a4947 | 4598 | + return (sb_rdonly(au_br_sb(br)) |
1facf9fc | 4599 | + || !au_br_writable(br->br_perm)) |
4600 | + ? -EROFS : 0; | |
4601 | +} | |
4602 | + | |
4a4d8108 | 4603 | +static inline int au_br_hnotifyable(int brperm __maybe_unused) |
1facf9fc | 4604 | +{ |
4a4d8108 | 4605 | +#ifdef CONFIG_AUFS_HNOTIFY |
1e00d052 | 4606 | + return !(brperm & AuBrPerm_RR); |
1facf9fc | 4607 | +#else |
4608 | + return 0; | |
4609 | +#endif | |
4610 | +} | |
4611 | + | |
b912730e AM |
4612 | +static inline int au_br_test_oflag(int oflag, struct au_branch *br) |
4613 | +{ | |
4614 | + int err, exec_flag; | |
4615 | + | |
4616 | + err = 0; | |
4617 | + exec_flag = oflag & __FMODE_EXEC; | |
79b8bda9 | 4618 | + if (unlikely(exec_flag && path_noexec(&br->br_path))) |
b912730e AM |
4619 | + err = -EACCES; |
4620 | + | |
4621 | + return err; | |
4622 | +} | |
4623 | + | |
062440b3 AM |
4624 | +static inline void au_xino_get(struct au_branch *br) |
4625 | +{ | |
4626 | + struct au_xino *xi; | |
4627 | + | |
4628 | + xi = br->br_xino; | |
4629 | + if (xi) | |
4630 | + kref_get(&xi->xi_kref); | |
4631 | +} | |
4632 | + | |
4633 | +static inline int au_xino_count(struct au_branch *br) | |
4634 | +{ | |
4635 | + int v; | |
4636 | + struct au_xino *xi; | |
4637 | + | |
4638 | + v = 0; | |
4639 | + xi = br->br_xino; | |
4640 | + if (xi) | |
4641 | + v = kref_read(&xi->xi_kref); | |
4642 | + | |
4643 | + return v; | |
4644 | +} | |
4645 | + | |
1facf9fc | 4646 | +/* ---------------------------------------------------------------------- */ |
4647 | + | |
4648 | +/* branch.c */ | |
4649 | +struct au_sbinfo; | |
4650 | +void au_br_free(struct au_sbinfo *sinfo); | |
4651 | +int au_br_index(struct super_block *sb, aufs_bindex_t br_id); | |
4652 | +struct au_opt_add; | |
4653 | +int au_br_add(struct super_block *sb, struct au_opt_add *add, int remount); | |
4654 | +struct au_opt_del; | |
4655 | +int au_br_del(struct super_block *sb, struct au_opt_del *del, int remount); | |
027c5e7a AM |
4656 | +long au_ibusy_ioctl(struct file *file, unsigned long arg); |
4657 | +#ifdef CONFIG_COMPAT | |
4658 | +long au_ibusy_compat_ioctl(struct file *file, unsigned long arg); | |
4659 | +#endif | |
1facf9fc | 4660 | +struct au_opt_mod; |
4661 | +int au_br_mod(struct super_block *sb, struct au_opt_mod *mod, int remount, | |
7f207e10 | 4662 | + int *do_refresh); |
076b876e AM |
4663 | +struct aufs_stfs; |
4664 | +int au_br_stfs(struct au_branch *br, struct aufs_stfs *stfs); | |
1facf9fc | 4665 | + |
4666 | +/* xino.c */ | |
4667 | +static const loff_t au_loff_max = LLONG_MAX; | |
4668 | + | |
acd2b654 | 4669 | +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry); |
83b672a5 AM |
4670 | +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent, |
4671 | + int wbrtop); | |
062440b3 AM |
4672 | +struct file *au_xino_create2(struct super_block *sb, struct path *base, |
4673 | + struct file *copy_src); | |
acd2b654 AM |
4674 | +struct au_xi_new { |
4675 | + struct au_xino *xi; /* switch between xino and xigen */ | |
4676 | + int idx; | |
4677 | + struct path *base; | |
4678 | + struct file *copy_src; | |
4679 | +}; | |
4680 | +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew); | |
062440b3 AM |
4681 | + |
4682 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4683 | + ino_t *ino); | |
4684 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4685 | + ino_t ino); | |
5527c038 | 4686 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *buf, size_t size, |
1facf9fc | 4687 | + loff_t *pos); |
5527c038 JR |
4688 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, |
4689 | + size_t size, loff_t *pos); | |
062440b3 AM |
4690 | + |
4691 | +int au_xib_trunc(struct super_block *sb); | |
acd2b654 | 4692 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin); |
1facf9fc | 4693 | + |
acd2b654 | 4694 | +struct au_xino *au_xino_alloc(unsigned int nfile); |
062440b3 | 4695 | +int au_xino_put(struct au_branch *br); |
acd2b654 | 4696 | +struct file *au_xino_file1(struct au_xino *xi); |
062440b3 | 4697 | + |
1facf9fc | 4698 | +struct au_opt_xino; |
1facf9fc | 4699 | +void au_xino_clr(struct super_block *sb); |
062440b3 | 4700 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount); |
1facf9fc | 4701 | +struct file *au_xino_def(struct super_block *sb); |
062440b3 AM |
4702 | +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t hino, |
4703 | + struct path *base); | |
4704 | + | |
4705 | +ino_t au_xino_new_ino(struct super_block *sb); | |
4706 | +void au_xino_delete_inode(struct inode *inode, const int unlinked); | |
1facf9fc | 4707 | + |
521ced18 JR |
4708 | +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex, |
4709 | + ino_t h_ino, int idx); | |
4710 | +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
4711 | + int *idx); | |
4712 | + | |
062440b3 AM |
4713 | +int au_xino_path(struct seq_file *seq, struct file *file); |
4714 | + | |
1facf9fc | 4715 | +/* ---------------------------------------------------------------------- */ |
4716 | + | |
acd2b654 AM |
4717 | +/* @idx is signed to accept -1 meaning the first file */ |
4718 | +static inline struct file *au_xino_file(struct au_xino *xi, int idx) | |
4719 | +{ | |
4720 | + struct file *file; | |
4721 | + | |
4722 | + file = NULL; | |
4723 | + if (!xi) | |
4724 | + goto out; | |
4725 | + | |
4726 | + if (idx >= 0) { | |
4727 | + if (idx < xi->xi_nfile) | |
4728 | + file = xi->xi_file[idx]; | |
4729 | + } else | |
4730 | + file = au_xino_file1(xi); | |
4731 | + | |
4732 | +out: | |
4733 | + return file; | |
4734 | +} | |
4735 | + | |
4736 | +/* ---------------------------------------------------------------------- */ | |
4737 | + | |
1facf9fc | 4738 | +/* Superblock to branch */ |
4739 | +static inline | |
4740 | +aufs_bindex_t au_sbr_id(struct super_block *sb, aufs_bindex_t bindex) | |
4741 | +{ | |
4742 | + return au_sbr(sb, bindex)->br_id; | |
4743 | +} | |
4744 | + | |
4745 | +static inline | |
4746 | +struct vfsmount *au_sbr_mnt(struct super_block *sb, aufs_bindex_t bindex) | |
4747 | +{ | |
86dc4139 | 4748 | + return au_br_mnt(au_sbr(sb, bindex)); |
1facf9fc | 4749 | +} |
4750 | + | |
4751 | +static inline | |
4752 | +struct super_block *au_sbr_sb(struct super_block *sb, aufs_bindex_t bindex) | |
4753 | +{ | |
86dc4139 | 4754 | + return au_br_sb(au_sbr(sb, bindex)); |
1facf9fc | 4755 | +} |
4756 | + | |
1facf9fc | 4757 | +static inline int au_sbr_perm(struct super_block *sb, aufs_bindex_t bindex) |
4758 | +{ | |
4759 | + return au_sbr(sb, bindex)->br_perm; | |
4760 | +} | |
4761 | + | |
4762 | +static inline int au_sbr_whable(struct super_block *sb, aufs_bindex_t bindex) | |
4763 | +{ | |
4764 | + return au_br_whable(au_sbr_perm(sb, bindex)); | |
4765 | +} | |
4766 | + | |
4767 | +/* ---------------------------------------------------------------------- */ | |
4768 | + | |
8b6a4947 AM |
4769 | +#define wbr_wh_read_lock(wbr) au_rw_read_lock(&(wbr)->wbr_wh_rwsem) |
4770 | +#define wbr_wh_write_lock(wbr) au_rw_write_lock(&(wbr)->wbr_wh_rwsem) | |
4771 | +#define wbr_wh_read_trylock(wbr) au_rw_read_trylock(&(wbr)->wbr_wh_rwsem) | |
4772 | +#define wbr_wh_write_trylock(wbr) au_rw_write_trylock(&(wbr)->wbr_wh_rwsem) | |
1facf9fc | 4773 | +/* |
8b6a4947 AM |
4774 | +#define wbr_wh_read_trylock_nested(wbr) \ |
4775 | + au_rw_read_trylock_nested(&(wbr)->wbr_wh_rwsem) | |
4776 | +#define wbr_wh_write_trylock_nested(wbr) \ | |
4777 | + au_rw_write_trylock_nested(&(wbr)->wbr_wh_rwsem) | |
4778 | +*/ | |
1facf9fc | 4779 | + |
8b6a4947 AM |
4780 | +#define wbr_wh_read_unlock(wbr) au_rw_read_unlock(&(wbr)->wbr_wh_rwsem) |
4781 | +#define wbr_wh_write_unlock(wbr) au_rw_write_unlock(&(wbr)->wbr_wh_rwsem) | |
4782 | +#define wbr_wh_downgrade_lock(wbr) au_rw_dgrade_lock(&(wbr)->wbr_wh_rwsem) | |
4783 | + | |
4784 | +#define WbrWhMustNoWaiters(wbr) AuRwMustNoWaiters(&(wbr)->wbr_wh_rwsem) | |
4785 | +#define WbrWhMustAnyLock(wbr) AuRwMustAnyLock(&(wbr)->wbr_wh_rwsem) | |
4786 | +#define WbrWhMustWriteLock(wbr) AuRwMustWriteLock(&(wbr)->wbr_wh_rwsem) | |
dece6358 | 4787 | + |
076b876e AM |
4788 | +/* ---------------------------------------------------------------------- */ |
4789 | + | |
4790 | +#ifdef CONFIG_AUFS_FHSM | |
4791 | +static inline void au_br_fhsm_init(struct au_br_fhsm *brfhsm) | |
4792 | +{ | |
4793 | + mutex_init(&brfhsm->bf_lock); | |
4794 | + brfhsm->bf_jiffy = 0; | |
4795 | + brfhsm->bf_readable = 0; | |
4796 | +} | |
4797 | + | |
4798 | +static inline void au_br_fhsm_fin(struct au_br_fhsm *brfhsm) | |
4799 | +{ | |
4800 | + mutex_destroy(&brfhsm->bf_lock); | |
4801 | +} | |
4802 | +#else | |
4803 | +AuStubVoid(au_br_fhsm_init, struct au_br_fhsm *brfhsm) | |
4804 | +AuStubVoid(au_br_fhsm_fin, struct au_br_fhsm *brfhsm) | |
4805 | +#endif | |
4806 | + | |
1facf9fc | 4807 | +#endif /* __KERNEL__ */ |
4808 | +#endif /* __AUFS_BRANCH_H__ */ | |
7f207e10 | 4809 | diff -urN /usr/share/empty/fs/aufs/conf.mk linux/fs/aufs/conf.mk |
eca34b5c AM |
4810 | --- /usr/share/empty/fs/aufs/conf.mk 1970-01-01 01:00:00.000000000 +0100 |
4811 | +++ linux/fs/aufs/conf.mk 2019-07-11 15:42:14.462237786 +0200 | |
2121bcd9 AM |
4812 | @@ -0,0 +1,40 @@ |
4813 | +# SPDX-License-Identifier: GPL-2.0 | |
4a4d8108 AM |
4814 | + |
4815 | +AuConfStr = CONFIG_AUFS_FS=${CONFIG_AUFS_FS} | |
4816 | + | |
4817 | +define AuConf | |
4818 | +ifdef ${1} | |
4819 | +AuConfStr += ${1}=${${1}} | |
4820 | +endif | |
4821 | +endef | |
4822 | + | |
b752ccd1 | 4823 | +AuConfAll = BRANCH_MAX_127 BRANCH_MAX_511 BRANCH_MAX_1023 BRANCH_MAX_32767 \ |
e49829fe | 4824 | + SBILIST \ |
7f207e10 | 4825 | + HNOTIFY HFSNOTIFY \ |
4a4d8108 | 4826 | + EXPORT INO_T_64 \ |
c1595e42 | 4827 | + XATTR \ |
076b876e | 4828 | + FHSM \ |
4a4d8108 | 4829 | + RDU \ |
8b6a4947 | 4830 | + DIRREN \ |
4a4d8108 AM |
4831 | + SHWH \ |
4832 | + BR_RAMFS \ | |
4833 | + BR_FUSE POLL \ | |
4834 | + BR_HFSPLUS \ | |
4835 | + BDEV_LOOP \ | |
b752ccd1 AM |
4836 | + DEBUG MAGIC_SYSRQ |
4837 | +$(foreach i, ${AuConfAll}, \ | |
4a4d8108 AM |
4838 | + $(eval $(call AuConf,CONFIG_AUFS_${i}))) |
4839 | + | |
4840 | +AuConfName = ${obj}/conf.str | |
4841 | +${AuConfName}.tmp: FORCE | |
4842 | + @echo ${AuConfStr} | tr ' ' '\n' | sed -e 's/^/"/' -e 's/$$/\\n"/' > $@ | |
4843 | +${AuConfName}: ${AuConfName}.tmp | |
4844 | + @diff -q $< $@ > /dev/null 2>&1 || { \ | |
4845 | + echo ' GEN ' $@; \ | |
4846 | + cp -p $< $@; \ | |
4847 | + } | |
4848 | +FORCE: | |
4849 | +clean-files += ${AuConfName} ${AuConfName}.tmp | |
4850 | +${obj}/sysfs.o: ${AuConfName} | |
b752ccd1 AM |
4851 | + |
4852 | +-include ${srctree}/${src}/conf_priv.mk | |
7f207e10 | 4853 | diff -urN /usr/share/empty/fs/aufs/cpup.c linux/fs/aufs/cpup.c |
eca34b5c | 4854 | --- /usr/share/empty/fs/aufs/cpup.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 4855 | +++ linux/fs/aufs/cpup.c 2020-01-27 10:57:18.165538015 +0100 |
9f237c51 | 4856 | @@ -0,0 +1,1458 @@ |
cd7a4cd9 | 4857 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 4858 | +/* |
d58c55f2 | 4859 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 4860 | + * |
4861 | + * This program, aufs is free software; you can redistribute it and/or modify | |
4862 | + * it under the terms of the GNU General Public License as published by | |
4863 | + * the Free Software Foundation; either version 2 of the License, or | |
4864 | + * (at your option) any later version. | |
dece6358 AM |
4865 | + * |
4866 | + * This program is distributed in the hope that it will be useful, | |
4867 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
4868 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
4869 | + * GNU General Public License for more details. | |
4870 | + * | |
4871 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 4872 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 4873 | + */ |
4874 | + | |
4875 | +/* | |
4876 | + * copy-up functions, see wbr_policy.c for copy-down | |
4877 | + */ | |
4878 | + | |
4879 | +#include <linux/fs_stack.h> | |
dece6358 | 4880 | +#include <linux/mm.h> |
8cdd5066 | 4881 | +#include <linux/task_work.h> |
1facf9fc | 4882 | +#include "aufs.h" |
4883 | + | |
86dc4139 | 4884 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags) |
1facf9fc | 4885 | +{ |
4886 | + const unsigned int mask = S_DEAD | S_SWAPFILE | S_PRIVATE | |
367653fa | 4887 | + | S_NOATIME | S_NOCMTIME | S_AUTOMOUNT; |
1facf9fc | 4888 | + |
86dc4139 AM |
4889 | + BUILD_BUG_ON(sizeof(iflags) != sizeof(dst->i_flags)); |
4890 | + | |
4891 | + dst->i_flags |= iflags & ~mask; | |
1facf9fc | 4892 | + if (au_test_fs_notime(dst->i_sb)) |
4893 | + dst->i_flags |= S_NOATIME | S_NOCMTIME; | |
4894 | +} | |
4895 | + | |
4896 | +void au_cpup_attr_timesizes(struct inode *inode) | |
4897 | +{ | |
4898 | + struct inode *h_inode; | |
4899 | + | |
5afbbe0d | 4900 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 4901 | + fsstack_copy_attr_times(inode, h_inode); |
4a4d8108 | 4902 | + fsstack_copy_inode_size(inode, h_inode); |
1facf9fc | 4903 | +} |
4904 | + | |
4905 | +void au_cpup_attr_nlink(struct inode *inode, int force) | |
4906 | +{ | |
4907 | + struct inode *h_inode; | |
4908 | + struct super_block *sb; | |
5afbbe0d | 4909 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 4910 | + |
4911 | + sb = inode->i_sb; | |
5afbbe0d | 4912 | + bindex = au_ibtop(inode); |
1facf9fc | 4913 | + h_inode = au_h_iptr(inode, bindex); |
4914 | + if (!force | |
4915 | + && !S_ISDIR(h_inode->i_mode) | |
4916 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4917 | + && au_plink_test(inode)) | |
4918 | + return; | |
4919 | + | |
7eafdf33 AM |
4920 | + /* |
4921 | + * 0 can happen in revalidating. | |
38d290e6 JR |
4922 | + * h_inode->i_mutex may not be held here, but it is harmless since once |
4923 | + * i_nlink reaches 0, it will never become positive except O_TMPFILE | |
4924 | + * case. | |
4925 | + * todo: O_TMPFILE+linkat(AT_SYMLINK_FOLLOW) bypassing aufs may cause | |
4926 | + * the incorrect link count. | |
7eafdf33 | 4927 | + */ |
92d182d2 | 4928 | + set_nlink(inode, h_inode->i_nlink); |
1facf9fc | 4929 | + |
4930 | + /* | |
4931 | + * fewer nlink makes find(1) noisy, but larger nlink doesn't. | |
4932 | + * it may includes whplink directory. | |
4933 | + */ | |
4934 | + if (S_ISDIR(h_inode->i_mode)) { | |
5afbbe0d AM |
4935 | + bbot = au_ibbot(inode); |
4936 | + for (bindex++; bindex <= bbot; bindex++) { | |
1facf9fc | 4937 | + h_inode = au_h_iptr(inode, bindex); |
4938 | + if (h_inode) | |
4939 | + au_add_nlink(inode, h_inode); | |
4940 | + } | |
4941 | + } | |
4942 | +} | |
4943 | + | |
4944 | +void au_cpup_attr_changeable(struct inode *inode) | |
4945 | +{ | |
4946 | + struct inode *h_inode; | |
4947 | + | |
5afbbe0d | 4948 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 4949 | + inode->i_mode = h_inode->i_mode; |
4950 | + inode->i_uid = h_inode->i_uid; | |
4951 | + inode->i_gid = h_inode->i_gid; | |
4952 | + au_cpup_attr_timesizes(inode); | |
86dc4139 | 4953 | + au_cpup_attr_flags(inode, h_inode->i_flags); |
1facf9fc | 4954 | +} |
4955 | + | |
4956 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode) | |
4957 | +{ | |
4958 | + struct au_iinfo *iinfo = au_ii(inode); | |
4959 | + | |
1308ab2a | 4960 | + IiMustWriteLock(inode); |
4961 | + | |
1facf9fc | 4962 | + iinfo->ii_higen = h_inode->i_generation; |
4963 | + iinfo->ii_hsb1 = h_inode->i_sb; | |
4964 | +} | |
4965 | + | |
4966 | +void au_cpup_attr_all(struct inode *inode, int force) | |
4967 | +{ | |
4968 | + struct inode *h_inode; | |
4969 | + | |
5afbbe0d | 4970 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
1facf9fc | 4971 | + au_cpup_attr_changeable(inode); |
4972 | + if (inode->i_nlink > 0) | |
4973 | + au_cpup_attr_nlink(inode, force); | |
4974 | + inode->i_rdev = h_inode->i_rdev; | |
4975 | + inode->i_blkbits = h_inode->i_blkbits; | |
4976 | + au_cpup_igen(inode, h_inode); | |
4977 | +} | |
4978 | + | |
4979 | +/* ---------------------------------------------------------------------- */ | |
4980 | + | |
4981 | +/* Note: dt_dentry and dt_h_dentry are not dget/dput-ed */ | |
4982 | + | |
4983 | +/* keep the timestamps of the parent dir when cpup */ | |
4984 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
4985 | + struct path *h_path) | |
4986 | +{ | |
4987 | + struct inode *h_inode; | |
4988 | + | |
4989 | + dt->dt_dentry = dentry; | |
4990 | + dt->dt_h_path = *h_path; | |
5527c038 | 4991 | + h_inode = d_inode(h_path->dentry); |
1facf9fc | 4992 | + dt->dt_atime = h_inode->i_atime; |
4993 | + dt->dt_mtime = h_inode->i_mtime; | |
4994 | + /* smp_mb(); */ | |
4995 | +} | |
4996 | + | |
4997 | +void au_dtime_revert(struct au_dtime *dt) | |
4998 | +{ | |
4999 | + struct iattr attr; | |
5000 | + int err; | |
5001 | + | |
5002 | + attr.ia_atime = dt->dt_atime; | |
5003 | + attr.ia_mtime = dt->dt_mtime; | |
5004 | + attr.ia_valid = ATTR_FORCE | ATTR_MTIME | ATTR_MTIME_SET | |
5005 | + | ATTR_ATIME | ATTR_ATIME_SET; | |
5006 | + | |
523b37e3 AM |
5007 | + /* no delegation since this is a directory */ |
5008 | + err = vfsub_notify_change(&dt->dt_h_path, &attr, /*delegated*/NULL); | |
1facf9fc | 5009 | + if (unlikely(err)) |
0c3ec466 | 5010 | + pr_warn("restoring timestamps failed(%d). ignored\n", err); |
1facf9fc | 5011 | +} |
5012 | + | |
5013 | +/* ---------------------------------------------------------------------- */ | |
5014 | + | |
86dc4139 AM |
5015 | +/* internal use only */ |
5016 | +struct au_cpup_reg_attr { | |
5017 | + int valid; | |
5018 | + struct kstat st; | |
5019 | + unsigned int iflags; /* inode->i_flags */ | |
5020 | +}; | |
5021 | + | |
1facf9fc | 5022 | +static noinline_for_stack |
86dc4139 AM |
5023 | +int cpup_iattr(struct dentry *dst, aufs_bindex_t bindex, struct dentry *h_src, |
5024 | + struct au_cpup_reg_attr *h_src_attr) | |
1facf9fc | 5025 | +{ |
c1595e42 | 5026 | + int err, sbits, icex; |
7e9cd9fe AM |
5027 | + unsigned int mnt_flags; |
5028 | + unsigned char verbose; | |
1facf9fc | 5029 | + struct iattr ia; |
5030 | + struct path h_path; | |
1308ab2a | 5031 | + struct inode *h_isrc, *h_idst; |
86dc4139 | 5032 | + struct kstat *h_st; |
c1595e42 | 5033 | + struct au_branch *br; |
1facf9fc | 5034 | + |
5035 | + h_path.dentry = au_h_dptr(dst, bindex); | |
5527c038 | 5036 | + h_idst = d_inode(h_path.dentry); |
c1595e42 JR |
5037 | + br = au_sbr(dst->d_sb, bindex); |
5038 | + h_path.mnt = au_br_mnt(br); | |
5527c038 | 5039 | + h_isrc = d_inode(h_src); |
1308ab2a | 5040 | + ia.ia_valid = ATTR_FORCE | ATTR_UID | ATTR_GID |
1facf9fc | 5041 | + | ATTR_ATIME | ATTR_MTIME |
5042 | + | ATTR_ATIME_SET | ATTR_MTIME_SET; | |
86dc4139 AM |
5043 | + if (h_src_attr && h_src_attr->valid) { |
5044 | + h_st = &h_src_attr->st; | |
5045 | + ia.ia_uid = h_st->uid; | |
5046 | + ia.ia_gid = h_st->gid; | |
5047 | + ia.ia_atime = h_st->atime; | |
5048 | + ia.ia_mtime = h_st->mtime; | |
5049 | + if (h_idst->i_mode != h_st->mode | |
5050 | + && !S_ISLNK(h_idst->i_mode)) { | |
5051 | + ia.ia_valid |= ATTR_MODE; | |
5052 | + ia.ia_mode = h_st->mode; | |
5053 | + } | |
5054 | + sbits = !!(h_st->mode & (S_ISUID | S_ISGID)); | |
5055 | + au_cpup_attr_flags(h_idst, h_src_attr->iflags); | |
5056 | + } else { | |
5057 | + ia.ia_uid = h_isrc->i_uid; | |
5058 | + ia.ia_gid = h_isrc->i_gid; | |
5059 | + ia.ia_atime = h_isrc->i_atime; | |
5060 | + ia.ia_mtime = h_isrc->i_mtime; | |
5061 | + if (h_idst->i_mode != h_isrc->i_mode | |
5062 | + && !S_ISLNK(h_idst->i_mode)) { | |
5063 | + ia.ia_valid |= ATTR_MODE; | |
5064 | + ia.ia_mode = h_isrc->i_mode; | |
5065 | + } | |
5066 | + sbits = !!(h_isrc->i_mode & (S_ISUID | S_ISGID)); | |
5067 | + au_cpup_attr_flags(h_idst, h_isrc->i_flags); | |
1308ab2a | 5068 | + } |
523b37e3 AM |
5069 | + /* no delegation since it is just created */ |
5070 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 5071 | + |
5072 | + /* is this nfs only? */ | |
5073 | + if (!err && sbits && au_test_nfs(h_path.dentry->d_sb)) { | |
5074 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
5075 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 5076 | + err = vfsub_notify_change(&h_path, &ia, /*delegated*/NULL); |
1facf9fc | 5077 | + } |
5078 | + | |
c1595e42 | 5079 | + icex = br->br_perm & AuBrAttr_ICEX; |
7e9cd9fe AM |
5080 | + if (!err) { |
5081 | + mnt_flags = au_mntflags(dst->d_sb); | |
5082 | + verbose = !!au_opt_test(mnt_flags, VERBOSE); | |
5083 | + err = au_cpup_xattr(h_path.dentry, h_src, icex, verbose); | |
5084 | + } | |
c1595e42 | 5085 | + |
1facf9fc | 5086 | + return err; |
5087 | +} | |
5088 | + | |
5089 | +/* ---------------------------------------------------------------------- */ | |
5090 | + | |
5091 | +static int au_do_copy_file(struct file *dst, struct file *src, loff_t len, | |
5092 | + char *buf, unsigned long blksize) | |
5093 | +{ | |
5094 | + int err; | |
5095 | + size_t sz, rbytes, wbytes; | |
5096 | + unsigned char all_zero; | |
5097 | + char *p, *zp; | |
febd17d6 | 5098 | + struct inode *h_inode; |
1facf9fc | 5099 | + /* reduce stack usage */ |
5100 | + struct iattr *ia; | |
5101 | + | |
5102 | + zp = page_address(ZERO_PAGE(0)); | |
5103 | + if (unlikely(!zp)) | |
5104 | + return -ENOMEM; /* possible? */ | |
5105 | + | |
5106 | + err = 0; | |
5107 | + all_zero = 0; | |
5108 | + while (len) { | |
5109 | + AuDbg("len %lld\n", len); | |
5110 | + sz = blksize; | |
5111 | + if (len < blksize) | |
5112 | + sz = len; | |
5113 | + | |
5114 | + rbytes = 0; | |
5115 | + /* todo: signal_pending? */ | |
5116 | + while (!rbytes || err == -EAGAIN || err == -EINTR) { | |
5117 | + rbytes = vfsub_read_k(src, buf, sz, &src->f_pos); | |
5118 | + err = rbytes; | |
5119 | + } | |
5120 | + if (unlikely(err < 0)) | |
5121 | + break; | |
5122 | + | |
5123 | + all_zero = 0; | |
5124 | + if (len >= rbytes && rbytes == blksize) | |
5125 | + all_zero = !memcmp(buf, zp, rbytes); | |
5126 | + if (!all_zero) { | |
5127 | + wbytes = rbytes; | |
5128 | + p = buf; | |
5129 | + while (wbytes) { | |
5130 | + size_t b; | |
5131 | + | |
5132 | + b = vfsub_write_k(dst, p, wbytes, &dst->f_pos); | |
5133 | + err = b; | |
5134 | + /* todo: signal_pending? */ | |
5135 | + if (unlikely(err == -EAGAIN || err == -EINTR)) | |
5136 | + continue; | |
5137 | + if (unlikely(err < 0)) | |
5138 | + break; | |
5139 | + wbytes -= b; | |
5140 | + p += b; | |
5141 | + } | |
392086de AM |
5142 | + if (unlikely(err < 0)) |
5143 | + break; | |
1facf9fc | 5144 | + } else { |
5145 | + loff_t res; | |
5146 | + | |
5147 | + AuLabel(hole); | |
5148 | + res = vfsub_llseek(dst, rbytes, SEEK_CUR); | |
5149 | + err = res; | |
5150 | + if (unlikely(res < 0)) | |
5151 | + break; | |
5152 | + } | |
5153 | + len -= rbytes; | |
5154 | + err = 0; | |
5155 | + } | |
5156 | + | |
5157 | + /* the last block may be a hole */ | |
5158 | + if (!err && all_zero) { | |
5159 | + AuLabel(last hole); | |
5160 | + | |
5161 | + err = 1; | |
2000de60 | 5162 | + if (au_test_nfs(dst->f_path.dentry->d_sb)) { |
1facf9fc | 5163 | + /* nfs requires this step to make last hole */ |
5164 | + /* is this only nfs? */ | |
5165 | + do { | |
5166 | + /* todo: signal_pending? */ | |
5167 | + err = vfsub_write_k(dst, "\0", 1, &dst->f_pos); | |
5168 | + } while (err == -EAGAIN || err == -EINTR); | |
5169 | + if (err == 1) | |
5170 | + dst->f_pos--; | |
5171 | + } | |
5172 | + | |
5173 | + if (err == 1) { | |
5174 | + ia = (void *)buf; | |
5175 | + ia->ia_size = dst->f_pos; | |
5176 | + ia->ia_valid = ATTR_SIZE | ATTR_FILE; | |
5177 | + ia->ia_file = dst; | |
febd17d6 JR |
5178 | + h_inode = file_inode(dst); |
5179 | + inode_lock_nested(h_inode, AuLsc_I_CHILD2); | |
523b37e3 AM |
5180 | + /* no delegation since it is just created */ |
5181 | + err = vfsub_notify_change(&dst->f_path, ia, | |
5182 | + /*delegated*/NULL); | |
febd17d6 | 5183 | + inode_unlock(h_inode); |
1facf9fc | 5184 | + } |
5185 | + } | |
5186 | + | |
5187 | + return err; | |
5188 | +} | |
5189 | + | |
5190 | +int au_copy_file(struct file *dst, struct file *src, loff_t len) | |
5191 | +{ | |
5192 | + int err; | |
5193 | + unsigned long blksize; | |
5194 | + unsigned char do_kfree; | |
5195 | + char *buf; | |
9f237c51 | 5196 | + struct super_block *h_sb; |
1facf9fc | 5197 | + |
5198 | + err = -ENOMEM; | |
9f237c51 AM |
5199 | + h_sb = file_inode(dst)->i_sb; |
5200 | + blksize = h_sb->s_blocksize; | |
1facf9fc | 5201 | + if (!blksize || PAGE_SIZE < blksize) |
5202 | + blksize = PAGE_SIZE; | |
5203 | + AuDbg("blksize %lu\n", blksize); | |
5204 | + do_kfree = (blksize != PAGE_SIZE && blksize >= sizeof(struct iattr *)); | |
5205 | + if (do_kfree) | |
5206 | + buf = kmalloc(blksize, GFP_NOFS); | |
5207 | + else | |
5208 | + buf = (void *)__get_free_page(GFP_NOFS); | |
5209 | + if (unlikely(!buf)) | |
5210 | + goto out; | |
5211 | + | |
5212 | + if (len > (1 << 22)) | |
5213 | + AuDbg("copying a large file %lld\n", (long long)len); | |
5214 | + | |
5215 | + src->f_pos = 0; | |
5216 | + dst->f_pos = 0; | |
5217 | + err = au_do_copy_file(dst, src, len, buf, blksize); | |
9f237c51 AM |
5218 | + if (do_kfree) { |
5219 | + AuDebugOn(!au_kfree_do_sz_test(blksize)); | |
5220 | + au_kfree_do_rcu(buf); | |
5221 | + } else | |
1c60b727 | 5222 | + free_page((unsigned long)buf); |
1facf9fc | 5223 | + |
4f0767ce | 5224 | +out: |
1facf9fc | 5225 | + return err; |
5226 | +} | |
5227 | + | |
1c60b727 AM |
5228 | +static int au_do_copy(struct file *dst, struct file *src, loff_t len) |
5229 | +{ | |
5230 | + int err; | |
5231 | + struct super_block *h_src_sb; | |
5232 | + struct inode *h_src_inode; | |
5233 | + | |
5234 | + h_src_inode = file_inode(src); | |
5235 | + h_src_sb = h_src_inode->i_sb; | |
5236 | + | |
5237 | + /* XFS acquires inode_lock */ | |
5238 | + if (!au_test_xfs(h_src_sb)) | |
5239 | + err = au_copy_file(dst, src, len); | |
5240 | + else { | |
3c1bdaff | 5241 | + inode_unlock_shared(h_src_inode); |
1c60b727 | 5242 | + err = au_copy_file(dst, src, len); |
be118d29 | 5243 | + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
1c60b727 AM |
5244 | + } |
5245 | + | |
5246 | + return err; | |
5247 | +} | |
5248 | + | |
5249 | +static int au_clone_or_copy(struct file *dst, struct file *src, loff_t len) | |
5250 | +{ | |
5251 | + int err; | |
9f237c51 | 5252 | + loff_t lo; |
1c60b727 AM |
5253 | + struct super_block *h_src_sb; |
5254 | + struct inode *h_src_inode; | |
5255 | + | |
5256 | + h_src_inode = file_inode(src); | |
5257 | + h_src_sb = h_src_inode->i_sb; | |
5258 | + if (h_src_sb != file_inode(dst)->i_sb | |
9f237c51 | 5259 | + || !dst->f_op->remap_file_range) { |
1c60b727 AM |
5260 | + err = au_do_copy(dst, src, len); |
5261 | + goto out; | |
5262 | + } | |
5263 | + | |
5264 | + if (!au_test_nfs(h_src_sb)) { | |
3c1bdaff | 5265 | + inode_unlock_shared(h_src_inode); |
9f237c51 | 5266 | + lo = vfsub_clone_file_range(src, dst, len); |
be118d29 | 5267 | + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
1c60b727 | 5268 | + } else |
9f237c51 AM |
5269 | + lo = vfsub_clone_file_range(src, dst, len); |
5270 | + if (lo == len) { | |
5271 | + err = 0; | |
5272 | + goto out; /* success */ | |
5273 | + } else if (lo >= 0) | |
5274 | + /* todo: possible? */ | |
5275 | + /* paritially succeeded */ | |
5276 | + AuDbg("lo %lld, len %lld. Retrying.\n", lo, len); | |
5277 | + else if (lo != -EOPNOTSUPP) { | |
5278 | + /* older XFS has a condition in cloning */ | |
5279 | + err = lo; | |
1c60b727 | 5280 | + goto out; |
9f237c51 | 5281 | + } |
1c60b727 AM |
5282 | + |
5283 | + /* the backend fs on NFS may not support cloning */ | |
5284 | + err = au_do_copy(dst, src, len); | |
5285 | + | |
5286 | +out: | |
5287 | + AuTraceErr(err); | |
5288 | + return err; | |
5289 | +} | |
5290 | + | |
1facf9fc | 5291 | +/* |
5292 | + * to support a sparse file which is opened with O_APPEND, | |
5293 | + * we need to close the file. | |
5294 | + */ | |
c2b27bf2 | 5295 | +static int au_cp_regular(struct au_cp_generic *cpg) |
1facf9fc | 5296 | +{ |
5297 | + int err, i; | |
5298 | + enum { SRC, DST }; | |
5299 | + struct { | |
5300 | + aufs_bindex_t bindex; | |
5301 | + unsigned int flags; | |
5302 | + struct dentry *dentry; | |
392086de | 5303 | + int force_wr; |
1facf9fc | 5304 | + struct file *file; |
1facf9fc | 5305 | + } *f, file[] = { |
5306 | + { | |
c2b27bf2 | 5307 | + .bindex = cpg->bsrc, |
1facf9fc | 5308 | + .flags = O_RDONLY | O_NOATIME | O_LARGEFILE, |
1facf9fc | 5309 | + }, |
5310 | + { | |
c2b27bf2 | 5311 | + .bindex = cpg->bdst, |
1facf9fc | 5312 | + .flags = O_WRONLY | O_NOATIME | O_LARGEFILE, |
392086de | 5313 | + .force_wr = !!au_ftest_cpup(cpg->flags, RWDST), |
1facf9fc | 5314 | + } |
5315 | + }; | |
acd2b654 | 5316 | + struct au_branch *br; |
521ced18 | 5317 | + struct super_block *sb, *h_src_sb; |
e2f27e51 | 5318 | + struct inode *h_src_inode; |
8cdd5066 | 5319 | + struct task_struct *tsk = current; |
1facf9fc | 5320 | + |
5321 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5322 | + sb = cpg->dentry->d_sb; |
1facf9fc | 5323 | + f = file; |
5324 | + for (i = 0; i < 2; i++, f++) { | |
c2b27bf2 AM |
5325 | + f->dentry = au_h_dptr(cpg->dentry, f->bindex); |
5326 | + f->file = au_h_open(cpg->dentry, f->bindex, f->flags, | |
392086de | 5327 | + /*file*/NULL, f->force_wr); |
9f237c51 AM |
5328 | + if (IS_ERR(f->file)) { |
5329 | + err = PTR_ERR(f->file); | |
5330 | + if (i == SRC) | |
5331 | + goto out; | |
5332 | + else | |
5333 | + goto out_src; | |
5334 | + } | |
1facf9fc | 5335 | + } |
5336 | + | |
5337 | + /* try stopping to update while we copyup */ | |
e2f27e51 | 5338 | + h_src_inode = d_inode(file[SRC].dentry); |
521ced18 JR |
5339 | + h_src_sb = h_src_inode->i_sb; |
5340 | + if (!au_test_nfs(h_src_sb)) | |
e2f27e51 | 5341 | + IMustLock(h_src_inode); |
1c60b727 | 5342 | + err = au_clone_or_copy(file[DST].file, file[SRC].file, cpg->len); |
1facf9fc | 5343 | + |
8cdd5066 JR |
5344 | + /* i wonder if we had O_NO_DELAY_FPUT flag */ |
5345 | + if (tsk->flags & PF_KTHREAD) | |
5346 | + __fput_sync(file[DST].file); | |
5347 | + else { | |
062440b3 | 5348 | + /* it happened actually */ |
8cdd5066 JR |
5349 | + fput(file[DST].file); |
5350 | + /* | |
5351 | + * too bad. | |
5352 | + * we have to call both since we don't know which place the file | |
5353 | + * was added to. | |
5354 | + */ | |
5355 | + task_work_run(); | |
5356 | + flush_delayed_fput(); | |
5357 | + } | |
acd2b654 AM |
5358 | + br = au_sbr(sb, file[DST].bindex); |
5359 | + au_lcnt_dec(&br->br_nfiles); | |
523b37e3 | 5360 | + |
4f0767ce | 5361 | +out_src: |
1facf9fc | 5362 | + fput(file[SRC].file); |
acd2b654 AM |
5363 | + br = au_sbr(sb, file[SRC].bindex); |
5364 | + au_lcnt_dec(&br->br_nfiles); | |
4f0767ce | 5365 | +out: |
1facf9fc | 5366 | + return err; |
5367 | +} | |
5368 | + | |
c2b27bf2 | 5369 | +static int au_do_cpup_regular(struct au_cp_generic *cpg, |
86dc4139 | 5370 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5371 | +{ |
5372 | + int err, rerr; | |
5373 | + loff_t l; | |
86dc4139 | 5374 | + struct path h_path; |
38d290e6 | 5375 | + struct inode *h_src_inode, *h_dst_inode; |
1facf9fc | 5376 | + |
5377 | + err = 0; | |
5527c038 | 5378 | + h_src_inode = au_h_iptr(d_inode(cpg->dentry), cpg->bsrc); |
86dc4139 | 5379 | + l = i_size_read(h_src_inode); |
c2b27bf2 AM |
5380 | + if (cpg->len == -1 || l < cpg->len) |
5381 | + cpg->len = l; | |
5382 | + if (cpg->len) { | |
86dc4139 | 5383 | + /* try stopping to update while we are referencing */ |
be118d29 | 5384 | + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
c2b27bf2 | 5385 | + au_pin_hdir_unlock(cpg->pin); |
1facf9fc | 5386 | + |
c2b27bf2 AM |
5387 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5388 | + h_path.mnt = au_sbr_mnt(cpg->dentry->d_sb, cpg->bsrc); | |
86dc4139 | 5389 | + h_src_attr->iflags = h_src_inode->i_flags; |
5527c038 | 5390 | + if (!au_test_nfs(h_src_inode->i_sb)) |
521ced18 | 5391 | + err = vfsub_getattr(&h_path, &h_src_attr->st); |
5527c038 | 5392 | + else { |
3c1bdaff | 5393 | + inode_unlock_shared(h_src_inode); |
521ced18 | 5394 | + err = vfsub_getattr(&h_path, &h_src_attr->st); |
be118d29 | 5395 | + inode_lock_shared_nested(h_src_inode, AuLsc_I_CHILD); |
5527c038 | 5396 | + } |
86dc4139 | 5397 | + if (unlikely(err)) { |
3c1bdaff | 5398 | + inode_unlock_shared(h_src_inode); |
86dc4139 AM |
5399 | + goto out; |
5400 | + } | |
5401 | + h_src_attr->valid = 1; | |
e2f27e51 AM |
5402 | + if (!au_test_nfs(h_src_inode->i_sb)) { |
5403 | + err = au_cp_regular(cpg); | |
3c1bdaff | 5404 | + inode_unlock_shared(h_src_inode); |
e2f27e51 | 5405 | + } else { |
3c1bdaff | 5406 | + inode_unlock_shared(h_src_inode); |
e2f27e51 AM |
5407 | + err = au_cp_regular(cpg); |
5408 | + } | |
c2b27bf2 | 5409 | + rerr = au_pin_hdir_relock(cpg->pin); |
86dc4139 AM |
5410 | + if (!err && rerr) |
5411 | + err = rerr; | |
1facf9fc | 5412 | + } |
38d290e6 JR |
5413 | + if (!err && (h_src_inode->i_state & I_LINKABLE)) { |
5414 | + h_path.dentry = au_h_dptr(cpg->dentry, cpg->bdst); | |
5527c038 | 5415 | + h_dst_inode = d_inode(h_path.dentry); |
38d290e6 JR |
5416 | + spin_lock(&h_dst_inode->i_lock); |
5417 | + h_dst_inode->i_state |= I_LINKABLE; | |
5418 | + spin_unlock(&h_dst_inode->i_lock); | |
5419 | + } | |
1facf9fc | 5420 | + |
4f0767ce | 5421 | +out: |
1facf9fc | 5422 | + return err; |
5423 | +} | |
5424 | + | |
5425 | +static int au_do_cpup_symlink(struct path *h_path, struct dentry *h_src, | |
5426 | + struct inode *h_dir) | |
5427 | +{ | |
5428 | + int err, symlen; | |
5429 | + mm_segment_t old_fs; | |
b752ccd1 AM |
5430 | + union { |
5431 | + char *k; | |
5432 | + char __user *u; | |
5433 | + } sym; | |
1facf9fc | 5434 | + |
5435 | + err = -ENOMEM; | |
537831f9 | 5436 | + sym.k = (void *)__get_free_page(GFP_NOFS); |
b752ccd1 | 5437 | + if (unlikely(!sym.k)) |
1facf9fc | 5438 | + goto out; |
5439 | + | |
9dbd164d | 5440 | + /* unnecessary to support mmap_sem since symlink is not mmap-able */ |
1facf9fc | 5441 | + old_fs = get_fs(); |
5442 | + set_fs(KERNEL_DS); | |
a2654f78 | 5443 | + symlen = vfs_readlink(h_src, sym.u, PATH_MAX); |
1facf9fc | 5444 | + err = symlen; |
5445 | + set_fs(old_fs); | |
5446 | + | |
5447 | + if (symlen > 0) { | |
b752ccd1 AM |
5448 | + sym.k[symlen] = 0; |
5449 | + err = vfsub_symlink(h_dir, h_path, sym.k); | |
1facf9fc | 5450 | + } |
1c60b727 | 5451 | + free_page((unsigned long)sym.k); |
1facf9fc | 5452 | + |
4f0767ce | 5453 | +out: |
1facf9fc | 5454 | + return err; |
5455 | +} | |
5456 | + | |
8cdd5066 JR |
5457 | +/* |
5458 | + * regardless 'acl' option, reset all ACL. | |
5459 | + * All ACL will be copied up later from the original entry on the lower branch. | |
5460 | + */ | |
5461 | +static int au_reset_acl(struct inode *h_dir, struct path *h_path, umode_t mode) | |
5462 | +{ | |
5463 | + int err; | |
5464 | + struct dentry *h_dentry; | |
5465 | + struct inode *h_inode; | |
5466 | + | |
5467 | + h_dentry = h_path->dentry; | |
5468 | + h_inode = d_inode(h_dentry); | |
5469 | + /* forget_all_cached_acls(h_inode)); */ | |
5470 | + err = vfsub_removexattr(h_dentry, XATTR_NAME_POSIX_ACL_ACCESS); | |
5471 | + AuTraceErr(err); | |
5472 | + if (err == -EOPNOTSUPP) | |
5473 | + err = 0; | |
5474 | + if (!err) | |
5475 | + err = vfsub_acl_chmod(h_inode, mode); | |
5476 | + | |
5477 | + AuTraceErr(err); | |
5478 | + return err; | |
5479 | +} | |
5480 | + | |
5481 | +static int au_do_cpup_dir(struct au_cp_generic *cpg, struct dentry *dst_parent, | |
5482 | + struct inode *h_dir, struct path *h_path) | |
5483 | +{ | |
5484 | + int err; | |
5485 | + struct inode *dir, *inode; | |
5486 | + | |
5487 | + err = vfsub_removexattr(h_path->dentry, XATTR_NAME_POSIX_ACL_DEFAULT); | |
5488 | + AuTraceErr(err); | |
5489 | + if (err == -EOPNOTSUPP) | |
5490 | + err = 0; | |
5491 | + if (unlikely(err)) | |
5492 | + goto out; | |
5493 | + | |
5494 | + /* | |
5495 | + * strange behaviour from the users view, | |
acd2b654 | 5496 | + * particularly setattr case |
8cdd5066 JR |
5497 | + */ |
5498 | + dir = d_inode(dst_parent); | |
5afbbe0d | 5499 | + if (au_ibtop(dir) == cpg->bdst) |
8cdd5066 JR |
5500 | + au_cpup_attr_nlink(dir, /*force*/1); |
5501 | + inode = d_inode(cpg->dentry); | |
5502 | + au_cpup_attr_nlink(inode, /*force*/1); | |
5503 | + | |
5504 | +out: | |
5505 | + return err; | |
5506 | +} | |
5507 | + | |
1facf9fc | 5508 | +static noinline_for_stack |
c2b27bf2 | 5509 | +int cpup_entry(struct au_cp_generic *cpg, struct dentry *dst_parent, |
86dc4139 | 5510 | + struct au_cpup_reg_attr *h_src_attr) |
1facf9fc | 5511 | +{ |
5512 | + int err; | |
5513 | + umode_t mode; | |
5514 | + unsigned int mnt_flags; | |
076b876e | 5515 | + unsigned char isdir, isreg, force; |
c2b27bf2 | 5516 | + const unsigned char do_dt = !!au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5517 | + struct au_dtime dt; |
5518 | + struct path h_path; | |
5519 | + struct dentry *h_src, *h_dst, *h_parent; | |
8cdd5066 | 5520 | + struct inode *h_inode, *h_dir; |
1facf9fc | 5521 | + struct super_block *sb; |
5522 | + | |
5523 | + /* bsrc branch can be ro/rw. */ | |
c2b27bf2 | 5524 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 JR |
5525 | + h_inode = d_inode(h_src); |
5526 | + AuDebugOn(h_inode != au_h_iptr(d_inode(cpg->dentry), cpg->bsrc)); | |
1facf9fc | 5527 | + |
5528 | + /* try stopping to be referenced while we are creating */ | |
c2b27bf2 AM |
5529 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); |
5530 | + if (au_ftest_cpup(cpg->flags, RENAME)) | |
86dc4139 AM |
5531 | + AuDebugOn(strncmp(h_dst->d_name.name, AUFS_WH_PFX, |
5532 | + AUFS_WH_PFX_LEN)); | |
1facf9fc | 5533 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5534 | + h_dir = d_inode(h_parent); |
1facf9fc | 5535 | + IMustLock(h_dir); |
5536 | + AuDebugOn(h_parent != h_dst->d_parent); | |
5537 | + | |
c2b27bf2 AM |
5538 | + sb = cpg->dentry->d_sb; |
5539 | + h_path.mnt = au_sbr_mnt(sb, cpg->bdst); | |
1facf9fc | 5540 | + if (do_dt) { |
5541 | + h_path.dentry = h_parent; | |
5542 | + au_dtime_store(&dt, dst_parent, &h_path); | |
5543 | + } | |
5544 | + h_path.dentry = h_dst; | |
5545 | + | |
076b876e | 5546 | + isreg = 0; |
1facf9fc | 5547 | + isdir = 0; |
5548 | + mode = h_inode->i_mode; | |
5549 | + switch (mode & S_IFMT) { | |
5550 | + case S_IFREG: | |
076b876e | 5551 | + isreg = 1; |
cd7a4cd9 | 5552 | + err = vfsub_create(h_dir, &h_path, 0600, /*want_excl*/true); |
1facf9fc | 5553 | + if (!err) |
c2b27bf2 | 5554 | + err = au_do_cpup_regular(cpg, h_src_attr); |
1facf9fc | 5555 | + break; |
5556 | + case S_IFDIR: | |
5557 | + isdir = 1; | |
5558 | + err = vfsub_mkdir(h_dir, &h_path, mode); | |
8cdd5066 JR |
5559 | + if (!err) |
5560 | + err = au_do_cpup_dir(cpg, dst_parent, h_dir, &h_path); | |
1facf9fc | 5561 | + break; |
5562 | + case S_IFLNK: | |
5563 | + err = au_do_cpup_symlink(&h_path, h_src, h_dir); | |
5564 | + break; | |
5565 | + case S_IFCHR: | |
5566 | + case S_IFBLK: | |
5567 | + AuDebugOn(!capable(CAP_MKNOD)); | |
5568 | + /*FALLTHROUGH*/ | |
5569 | + case S_IFIFO: | |
5570 | + case S_IFSOCK: | |
5571 | + err = vfsub_mknod(h_dir, &h_path, mode, h_inode->i_rdev); | |
5572 | + break; | |
5573 | + default: | |
5574 | + AuIOErr("Unknown inode type 0%o\n", mode); | |
5575 | + err = -EIO; | |
5576 | + } | |
8cdd5066 JR |
5577 | + if (!err) |
5578 | + err = au_reset_acl(h_dir, &h_path, mode); | |
1facf9fc | 5579 | + |
5580 | + mnt_flags = au_mntflags(sb); | |
5581 | + if (!au_opt_test(mnt_flags, UDBA_NONE) | |
5582 | + && !isdir | |
5583 | + && au_opt_test(mnt_flags, XINO) | |
38d290e6 JR |
5584 | + && (h_inode->i_nlink == 1 |
5585 | + || (h_inode->i_state & I_LINKABLE)) | |
1facf9fc | 5586 | + /* todo: unnecessary? */ |
5527c038 | 5587 | + /* && d_inode(cpg->dentry)->i_nlink == 1 */ |
c2b27bf2 AM |
5588 | + && cpg->bdst < cpg->bsrc |
5589 | + && !au_ftest_cpup(cpg->flags, KEEPLINO)) | |
5590 | + au_xino_write(sb, cpg->bsrc, h_inode->i_ino, /*ino*/0); | |
1facf9fc | 5591 | + /* ignore this error */ |
5592 | + | |
076b876e AM |
5593 | + if (!err) { |
5594 | + force = 0; | |
5595 | + if (isreg) { | |
5596 | + force = !!cpg->len; | |
5597 | + if (cpg->len == -1) | |
5598 | + force = !!i_size_read(h_inode); | |
5599 | + } | |
5600 | + au_fhsm_wrote(sb, cpg->bdst, force); | |
5601 | + } | |
5602 | + | |
1facf9fc | 5603 | + if (do_dt) |
5604 | + au_dtime_revert(&dt); | |
5605 | + return err; | |
5606 | +} | |
5607 | + | |
392086de | 5608 | +static int au_do_ren_after_cpup(struct au_cp_generic *cpg, struct path *h_path) |
86dc4139 AM |
5609 | +{ |
5610 | + int err; | |
392086de | 5611 | + struct dentry *dentry, *h_dentry, *h_parent, *parent; |
86dc4139 | 5612 | + struct inode *h_dir; |
392086de | 5613 | + aufs_bindex_t bdst; |
86dc4139 | 5614 | + |
392086de AM |
5615 | + dentry = cpg->dentry; |
5616 | + bdst = cpg->bdst; | |
5617 | + h_dentry = au_h_dptr(dentry, bdst); | |
5618 | + if (!au_ftest_cpup(cpg->flags, OVERWRITE)) { | |
5619 | + dget(h_dentry); | |
5620 | + au_set_h_dptr(dentry, bdst, NULL); | |
5621 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); | |
5622 | + if (!err) | |
5623 | + h_path->dentry = dget(au_h_dptr(dentry, bdst)); | |
86dc4139 | 5624 | + au_set_h_dptr(dentry, bdst, h_dentry); |
392086de AM |
5625 | + } else { |
5626 | + err = 0; | |
5627 | + parent = dget_parent(dentry); | |
5628 | + h_parent = au_h_dptr(parent, bdst); | |
5629 | + dput(parent); | |
5630 | + h_path->dentry = vfsub_lkup_one(&dentry->d_name, h_parent); | |
5631 | + if (IS_ERR(h_path->dentry)) | |
5632 | + err = PTR_ERR(h_path->dentry); | |
86dc4139 | 5633 | + } |
392086de AM |
5634 | + if (unlikely(err)) |
5635 | + goto out; | |
86dc4139 | 5636 | + |
86dc4139 | 5637 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ |
5527c038 | 5638 | + h_dir = d_inode(h_parent); |
86dc4139 | 5639 | + IMustLock(h_dir); |
523b37e3 AM |
5640 | + AuDbg("%pd %pd\n", h_dentry, h_path->dentry); |
5641 | + /* no delegation since it is just created */ | |
f2c43d5f AM |
5642 | + err = vfsub_rename(h_dir, h_dentry, h_dir, h_path, /*delegated*/NULL, |
5643 | + /*flags*/0); | |
86dc4139 AM |
5644 | + dput(h_path->dentry); |
5645 | + | |
5646 | +out: | |
5647 | + return err; | |
5648 | +} | |
5649 | + | |
1facf9fc | 5650 | +/* |
5651 | + * copyup the @dentry from @bsrc to @bdst. | |
5652 | + * the caller must set the both of lower dentries. | |
5653 | + * @len is for truncating when it is -1 copyup the entire file. | |
5654 | + * in link/rename cases, @dst_parent may be different from the real one. | |
c2b27bf2 | 5655 | + * basic->bsrc can be larger than basic->bdst. |
f2c43d5f | 5656 | + * aufs doesn't touch the credential so |
acd2b654 | 5657 | + * security_inode_copy_up{,_xattr}() are unnecessary. |
1facf9fc | 5658 | + */ |
c2b27bf2 | 5659 | +static int au_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5660 | +{ |
5661 | + int err, rerr; | |
5afbbe0d | 5662 | + aufs_bindex_t old_ibtop; |
1facf9fc | 5663 | + unsigned char isdir, plink; |
1facf9fc | 5664 | + struct dentry *h_src, *h_dst, *h_parent; |
5527c038 | 5665 | + struct inode *dst_inode, *h_dir, *inode, *delegated, *src_inode; |
1facf9fc | 5666 | + struct super_block *sb; |
86dc4139 | 5667 | + struct au_branch *br; |
acd2b654 | 5668 | + /* to reduce stack size */ |
c2b27bf2 AM |
5669 | + struct { |
5670 | + struct au_dtime dt; | |
5671 | + struct path h_path; | |
5672 | + struct au_cpup_reg_attr h_src_attr; | |
5673 | + } *a; | |
1facf9fc | 5674 | + |
c2b27bf2 AM |
5675 | + err = -ENOMEM; |
5676 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
5677 | + if (unlikely(!a)) | |
5678 | + goto out; | |
5679 | + a->h_src_attr.valid = 0; | |
1facf9fc | 5680 | + |
c2b27bf2 AM |
5681 | + sb = cpg->dentry->d_sb; |
5682 | + br = au_sbr(sb, cpg->bdst); | |
5683 | + a->h_path.mnt = au_br_mnt(br); | |
5684 | + h_dst = au_h_dptr(cpg->dentry, cpg->bdst); | |
1facf9fc | 5685 | + h_parent = h_dst->d_parent; /* dir inode is locked */ |
5527c038 | 5686 | + h_dir = d_inode(h_parent); |
1facf9fc | 5687 | + IMustLock(h_dir); |
5688 | + | |
c2b27bf2 | 5689 | + h_src = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5690 | + inode = d_inode(cpg->dentry); |
1facf9fc | 5691 | + |
5692 | + if (!dst_parent) | |
c2b27bf2 | 5693 | + dst_parent = dget_parent(cpg->dentry); |
1facf9fc | 5694 | + else |
5695 | + dget(dst_parent); | |
5696 | + | |
5697 | + plink = !!au_opt_test(au_mntflags(sb), PLINK); | |
c2b27bf2 | 5698 | + dst_inode = au_h_iptr(inode, cpg->bdst); |
1facf9fc | 5699 | + if (dst_inode) { |
5700 | + if (unlikely(!plink)) { | |
5701 | + err = -EIO; | |
027c5e7a AM |
5702 | + AuIOErr("hi%lu(i%lu) exists on b%d " |
5703 | + "but plink is disabled\n", | |
c2b27bf2 AM |
5704 | + dst_inode->i_ino, inode->i_ino, cpg->bdst); |
5705 | + goto out_parent; | |
1facf9fc | 5706 | + } |
5707 | + | |
5708 | + if (dst_inode->i_nlink) { | |
c2b27bf2 | 5709 | + const int do_dt = au_ftest_cpup(cpg->flags, DTIME); |
1facf9fc | 5710 | + |
c2b27bf2 | 5711 | + h_src = au_plink_lkup(inode, cpg->bdst); |
1facf9fc | 5712 | + err = PTR_ERR(h_src); |
5713 | + if (IS_ERR(h_src)) | |
c2b27bf2 | 5714 | + goto out_parent; |
5527c038 | 5715 | + if (unlikely(d_is_negative(h_src))) { |
1facf9fc | 5716 | + err = -EIO; |
79b8bda9 | 5717 | + AuIOErr("i%lu exists on b%d " |
027c5e7a | 5718 | + "but not pseudo-linked\n", |
79b8bda9 | 5719 | + inode->i_ino, cpg->bdst); |
1facf9fc | 5720 | + dput(h_src); |
c2b27bf2 | 5721 | + goto out_parent; |
1facf9fc | 5722 | + } |
5723 | + | |
5724 | + if (do_dt) { | |
c2b27bf2 AM |
5725 | + a->h_path.dentry = h_parent; |
5726 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
1facf9fc | 5727 | + } |
86dc4139 | 5728 | + |
c2b27bf2 | 5729 | + a->h_path.dentry = h_dst; |
523b37e3 AM |
5730 | + delegated = NULL; |
5731 | + err = vfsub_link(h_src, h_dir, &a->h_path, &delegated); | |
c2b27bf2 | 5732 | + if (!err && au_ftest_cpup(cpg->flags, RENAME)) |
392086de | 5733 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
1facf9fc | 5734 | + if (do_dt) |
c2b27bf2 | 5735 | + au_dtime_revert(&a->dt); |
523b37e3 AM |
5736 | + if (unlikely(err == -EWOULDBLOCK)) { |
5737 | + pr_warn("cannot retry for NFSv4 delegation" | |
5738 | + " for an internal link\n"); | |
5739 | + iput(delegated); | |
5740 | + } | |
1facf9fc | 5741 | + dput(h_src); |
c2b27bf2 | 5742 | + goto out_parent; |
1facf9fc | 5743 | + } else |
5744 | + /* todo: cpup_wh_file? */ | |
5745 | + /* udba work */ | |
4a4d8108 | 5746 | + au_update_ibrange(inode, /*do_put_zero*/1); |
1facf9fc | 5747 | + } |
5748 | + | |
86dc4139 | 5749 | + isdir = S_ISDIR(inode->i_mode); |
5afbbe0d | 5750 | + old_ibtop = au_ibtop(inode); |
c2b27bf2 | 5751 | + err = cpup_entry(cpg, dst_parent, &a->h_src_attr); |
1facf9fc | 5752 | + if (unlikely(err)) |
86dc4139 | 5753 | + goto out_rev; |
5527c038 | 5754 | + dst_inode = d_inode(h_dst); |
febd17d6 | 5755 | + inode_lock_nested(dst_inode, AuLsc_I_CHILD2); |
86dc4139 | 5756 | + /* todo: necessary? */ |
c2b27bf2 | 5757 | + /* au_pin_hdir_unlock(cpg->pin); */ |
1facf9fc | 5758 | + |
c2b27bf2 | 5759 | + err = cpup_iattr(cpg->dentry, cpg->bdst, h_src, &a->h_src_attr); |
86dc4139 AM |
5760 | + if (unlikely(err)) { |
5761 | + /* todo: necessary? */ | |
c2b27bf2 | 5762 | + /* au_pin_hdir_relock(cpg->pin); */ /* ignore an error */ |
febd17d6 | 5763 | + inode_unlock(dst_inode); |
86dc4139 AM |
5764 | + goto out_rev; |
5765 | + } | |
5766 | + | |
5afbbe0d | 5767 | + if (cpg->bdst < old_ibtop) { |
86dc4139 | 5768 | + if (S_ISREG(inode->i_mode)) { |
c2b27bf2 | 5769 | + err = au_dy_iaop(inode, cpg->bdst, dst_inode); |
86dc4139 | 5770 | + if (unlikely(err)) { |
c2b27bf2 AM |
5771 | + /* ignore an error */ |
5772 | + /* au_pin_hdir_relock(cpg->pin); */ | |
febd17d6 | 5773 | + inode_unlock(dst_inode); |
86dc4139 | 5774 | + goto out_rev; |
4a4d8108 | 5775 | + } |
4a4d8108 | 5776 | + } |
5afbbe0d | 5777 | + au_set_ibtop(inode, cpg->bdst); |
c2b27bf2 | 5778 | + } else |
5afbbe0d | 5779 | + au_set_ibbot(inode, cpg->bdst); |
c2b27bf2 | 5780 | + au_set_h_iptr(inode, cpg->bdst, au_igrab(dst_inode), |
86dc4139 AM |
5781 | + au_hi_flags(inode, isdir)); |
5782 | + | |
5783 | + /* todo: necessary? */ | |
c2b27bf2 | 5784 | + /* err = au_pin_hdir_relock(cpg->pin); */ |
febd17d6 | 5785 | + inode_unlock(dst_inode); |
86dc4139 AM |
5786 | + if (unlikely(err)) |
5787 | + goto out_rev; | |
5788 | + | |
5527c038 | 5789 | + src_inode = d_inode(h_src); |
86dc4139 | 5790 | + if (!isdir |
5527c038 JR |
5791 | + && (src_inode->i_nlink > 1 |
5792 | + || src_inode->i_state & I_LINKABLE) | |
86dc4139 | 5793 | + && plink) |
c2b27bf2 | 5794 | + au_plink_append(inode, cpg->bdst, h_dst); |
86dc4139 | 5795 | + |
c2b27bf2 AM |
5796 | + if (au_ftest_cpup(cpg->flags, RENAME)) { |
5797 | + a->h_path.dentry = h_dst; | |
392086de | 5798 | + err = au_do_ren_after_cpup(cpg, &a->h_path); |
86dc4139 AM |
5799 | + } |
5800 | + if (!err) | |
c2b27bf2 | 5801 | + goto out_parent; /* success */ |
1facf9fc | 5802 | + |
5803 | + /* revert */ | |
4a4d8108 | 5804 | +out_rev: |
c2b27bf2 AM |
5805 | + a->h_path.dentry = h_parent; |
5806 | + au_dtime_store(&a->dt, dst_parent, &a->h_path); | |
5807 | + a->h_path.dentry = h_dst; | |
86dc4139 | 5808 | + rerr = 0; |
5527c038 | 5809 | + if (d_is_positive(h_dst)) { |
523b37e3 AM |
5810 | + if (!isdir) { |
5811 | + /* no delegation since it is just created */ | |
5812 | + rerr = vfsub_unlink(h_dir, &a->h_path, | |
5813 | + /*delegated*/NULL, /*force*/0); | |
5814 | + } else | |
c2b27bf2 | 5815 | + rerr = vfsub_rmdir(h_dir, &a->h_path); |
86dc4139 | 5816 | + } |
c2b27bf2 | 5817 | + au_dtime_revert(&a->dt); |
1facf9fc | 5818 | + if (rerr) { |
5819 | + AuIOErr("failed removing broken entry(%d, %d)\n", err, rerr); | |
5820 | + err = -EIO; | |
5821 | + } | |
c2b27bf2 | 5822 | +out_parent: |
1facf9fc | 5823 | + dput(dst_parent); |
9f237c51 | 5824 | + au_kfree_rcu(a); |
c2b27bf2 | 5825 | +out: |
1facf9fc | 5826 | + return err; |
5827 | +} | |
5828 | + | |
7e9cd9fe | 5829 | +#if 0 /* reserved */ |
1facf9fc | 5830 | +struct au_cpup_single_args { |
5831 | + int *errp; | |
c2b27bf2 | 5832 | + struct au_cp_generic *cpg; |
1facf9fc | 5833 | + struct dentry *dst_parent; |
5834 | +}; | |
5835 | + | |
5836 | +static void au_call_cpup_single(void *args) | |
5837 | +{ | |
5838 | + struct au_cpup_single_args *a = args; | |
86dc4139 | 5839 | + |
c2b27bf2 AM |
5840 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5841 | + *a->errp = au_cpup_single(a->cpg, a->dst_parent); | |
5842 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5843 | +} |
c2b27bf2 | 5844 | +#endif |
1facf9fc | 5845 | + |
53392da6 AM |
5846 | +/* |
5847 | + * prevent SIGXFSZ in copy-up. | |
5848 | + * testing CAP_MKNOD is for generic fs, | |
5849 | + * but CAP_FSETID is for xfs only, currently. | |
5850 | + */ | |
86dc4139 | 5851 | +static int au_cpup_sio_test(struct au_pin *pin, umode_t mode) |
53392da6 AM |
5852 | +{ |
5853 | + int do_sio; | |
86dc4139 AM |
5854 | + struct super_block *sb; |
5855 | + struct inode *h_dir; | |
53392da6 AM |
5856 | + |
5857 | + do_sio = 0; | |
86dc4139 | 5858 | + sb = au_pinned_parent(pin)->d_sb; |
53392da6 AM |
5859 | + if (!au_wkq_test() |
5860 | + && (!au_sbi(sb)->si_plink_maint_pid | |
5861 | + || au_plink_maint(sb, AuLock_NOPLM))) { | |
5862 | + switch (mode & S_IFMT) { | |
5863 | + case S_IFREG: | |
5864 | + /* no condition about RLIMIT_FSIZE and the file size */ | |
5865 | + do_sio = 1; | |
5866 | + break; | |
5867 | + case S_IFCHR: | |
5868 | + case S_IFBLK: | |
5869 | + do_sio = !capable(CAP_MKNOD); | |
5870 | + break; | |
5871 | + } | |
5872 | + if (!do_sio) | |
5873 | + do_sio = ((mode & (S_ISUID | S_ISGID)) | |
5874 | + && !capable(CAP_FSETID)); | |
86dc4139 AM |
5875 | + /* this workaround may be removed in the future */ |
5876 | + if (!do_sio) { | |
5877 | + h_dir = au_pinned_h_dir(pin); | |
5878 | + do_sio = h_dir->i_mode & S_ISVTX; | |
5879 | + } | |
53392da6 AM |
5880 | + } |
5881 | + | |
5882 | + return do_sio; | |
5883 | +} | |
5884 | + | |
7e9cd9fe | 5885 | +#if 0 /* reserved */ |
c2b27bf2 | 5886 | +int au_sio_cpup_single(struct au_cp_generic *cpg, struct dentry *dst_parent) |
1facf9fc | 5887 | +{ |
5888 | + int err, wkq_err; | |
1facf9fc | 5889 | + struct dentry *h_dentry; |
5890 | + | |
c2b27bf2 | 5891 | + h_dentry = au_h_dptr(cpg->dentry, cpg->bsrc); |
5527c038 | 5892 | + if (!au_cpup_sio_test(pin, d_inode(h_dentry)->i_mode)) |
c2b27bf2 | 5893 | + err = au_cpup_single(cpg, dst_parent); |
1facf9fc | 5894 | + else { |
5895 | + struct au_cpup_single_args args = { | |
5896 | + .errp = &err, | |
c2b27bf2 AM |
5897 | + .cpg = cpg, |
5898 | + .dst_parent = dst_parent | |
1facf9fc | 5899 | + }; |
5900 | + wkq_err = au_wkq_wait(au_call_cpup_single, &args); | |
5901 | + if (unlikely(wkq_err)) | |
5902 | + err = wkq_err; | |
5903 | + } | |
5904 | + | |
5905 | + return err; | |
5906 | +} | |
c2b27bf2 | 5907 | +#endif |
1facf9fc | 5908 | + |
5909 | +/* | |
5910 | + * copyup the @dentry from the first active lower branch to @bdst, | |
5911 | + * using au_cpup_single(). | |
5912 | + */ | |
c2b27bf2 | 5913 | +static int au_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5914 | +{ |
5915 | + int err; | |
c2b27bf2 AM |
5916 | + unsigned int flags_orig; |
5917 | + struct dentry *dentry; | |
5918 | + | |
5919 | + AuDebugOn(cpg->bsrc < 0); | |
1facf9fc | 5920 | + |
c2b27bf2 | 5921 | + dentry = cpg->dentry; |
86dc4139 | 5922 | + DiMustWriteLock(dentry); |
1facf9fc | 5923 | + |
c2b27bf2 | 5924 | + err = au_lkup_neg(dentry, cpg->bdst, /*wh*/1); |
1facf9fc | 5925 | + if (!err) { |
c2b27bf2 AM |
5926 | + flags_orig = cpg->flags; |
5927 | + au_fset_cpup(cpg->flags, RENAME); | |
5928 | + err = au_cpup_single(cpg, NULL); | |
5929 | + cpg->flags = flags_orig; | |
1facf9fc | 5930 | + if (!err) |
5931 | + return 0; /* success */ | |
5932 | + | |
5933 | + /* revert */ | |
c2b27bf2 | 5934 | + au_set_h_dptr(dentry, cpg->bdst, NULL); |
5afbbe0d | 5935 | + au_set_dbtop(dentry, cpg->bsrc); |
1facf9fc | 5936 | + } |
5937 | + | |
5938 | + return err; | |
5939 | +} | |
5940 | + | |
5941 | +struct au_cpup_simple_args { | |
5942 | + int *errp; | |
c2b27bf2 | 5943 | + struct au_cp_generic *cpg; |
1facf9fc | 5944 | +}; |
5945 | + | |
5946 | +static void au_call_cpup_simple(void *args) | |
5947 | +{ | |
5948 | + struct au_cpup_simple_args *a = args; | |
86dc4139 | 5949 | + |
c2b27bf2 AM |
5950 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
5951 | + *a->errp = au_cpup_simple(a->cpg); | |
5952 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 5953 | +} |
5954 | + | |
c2b27bf2 | 5955 | +static int au_do_sio_cpup_simple(struct au_cp_generic *cpg) |
1facf9fc | 5956 | +{ |
5957 | + int err, wkq_err; | |
c2b27bf2 AM |
5958 | + struct dentry *dentry, *parent; |
5959 | + struct file *h_file; | |
1facf9fc | 5960 | + struct inode *h_dir; |
5961 | + | |
c2b27bf2 AM |
5962 | + dentry = cpg->dentry; |
5963 | + h_file = NULL; | |
5964 | + if (au_ftest_cpup(cpg->flags, HOPEN)) { | |
5965 | + AuDebugOn(cpg->bsrc < 0); | |
392086de | 5966 | + h_file = au_h_open_pre(dentry, cpg->bsrc, /*force_wr*/0); |
c2b27bf2 AM |
5967 | + err = PTR_ERR(h_file); |
5968 | + if (IS_ERR(h_file)) | |
5969 | + goto out; | |
5970 | + } | |
5971 | + | |
1facf9fc | 5972 | + parent = dget_parent(dentry); |
5527c038 | 5973 | + h_dir = au_h_iptr(d_inode(parent), cpg->bdst); |
53392da6 | 5974 | + if (!au_test_h_perm_sio(h_dir, MAY_EXEC | MAY_WRITE) |
5527c038 | 5975 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 5976 | + err = au_cpup_simple(cpg); |
1facf9fc | 5977 | + else { |
5978 | + struct au_cpup_simple_args args = { | |
5979 | + .errp = &err, | |
c2b27bf2 | 5980 | + .cpg = cpg |
1facf9fc | 5981 | + }; |
5982 | + wkq_err = au_wkq_wait(au_call_cpup_simple, &args); | |
5983 | + if (unlikely(wkq_err)) | |
5984 | + err = wkq_err; | |
5985 | + } | |
5986 | + | |
5987 | + dput(parent); | |
c2b27bf2 AM |
5988 | + if (h_file) |
5989 | + au_h_open_post(dentry, cpg->bsrc, h_file); | |
5990 | + | |
5991 | +out: | |
1facf9fc | 5992 | + return err; |
5993 | +} | |
5994 | + | |
c2b27bf2 | 5995 | +int au_sio_cpup_simple(struct au_cp_generic *cpg) |
367653fa | 5996 | +{ |
5afbbe0d | 5997 | + aufs_bindex_t bsrc, bbot; |
c2b27bf2 | 5998 | + struct dentry *dentry, *h_dentry; |
367653fa | 5999 | + |
c2b27bf2 AM |
6000 | + if (cpg->bsrc < 0) { |
6001 | + dentry = cpg->dentry; | |
5afbbe0d AM |
6002 | + bbot = au_dbbot(dentry); |
6003 | + for (bsrc = cpg->bdst + 1; bsrc <= bbot; bsrc++) { | |
c2b27bf2 AM |
6004 | + h_dentry = au_h_dptr(dentry, bsrc); |
6005 | + if (h_dentry) { | |
5527c038 | 6006 | + AuDebugOn(d_is_negative(h_dentry)); |
c2b27bf2 AM |
6007 | + break; |
6008 | + } | |
6009 | + } | |
5afbbe0d | 6010 | + AuDebugOn(bsrc > bbot); |
c2b27bf2 | 6011 | + cpg->bsrc = bsrc; |
367653fa | 6012 | + } |
c2b27bf2 AM |
6013 | + AuDebugOn(cpg->bsrc <= cpg->bdst); |
6014 | + return au_do_sio_cpup_simple(cpg); | |
6015 | +} | |
367653fa | 6016 | + |
c2b27bf2 AM |
6017 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg) |
6018 | +{ | |
6019 | + AuDebugOn(cpg->bdst <= cpg->bsrc); | |
6020 | + return au_do_sio_cpup_simple(cpg); | |
367653fa AM |
6021 | +} |
6022 | + | |
1facf9fc | 6023 | +/* ---------------------------------------------------------------------- */ |
6024 | + | |
6025 | +/* | |
6026 | + * copyup the deleted file for writing. | |
6027 | + */ | |
c2b27bf2 AM |
6028 | +static int au_do_cpup_wh(struct au_cp_generic *cpg, struct dentry *wh_dentry, |
6029 | + struct file *file) | |
1facf9fc | 6030 | +{ |
6031 | + int err; | |
c2b27bf2 AM |
6032 | + unsigned int flags_orig; |
6033 | + aufs_bindex_t bsrc_orig; | |
c2b27bf2 | 6034 | + struct au_dinfo *dinfo; |
5afbbe0d AM |
6035 | + struct { |
6036 | + struct au_hdentry *hd; | |
6037 | + struct dentry *h_dentry; | |
6038 | + } hdst, hsrc; | |
1facf9fc | 6039 | + |
c2b27bf2 | 6040 | + dinfo = au_di(cpg->dentry); |
1308ab2a | 6041 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
6042 | + | |
c2b27bf2 | 6043 | + bsrc_orig = cpg->bsrc; |
5afbbe0d AM |
6044 | + cpg->bsrc = dinfo->di_btop; |
6045 | + hdst.hd = au_hdentry(dinfo, cpg->bdst); | |
6046 | + hdst.h_dentry = hdst.hd->hd_dentry; | |
6047 | + hdst.hd->hd_dentry = wh_dentry; | |
6048 | + dinfo->di_btop = cpg->bdst; | |
6049 | + | |
6050 | + hsrc.h_dentry = NULL; | |
027c5e7a | 6051 | + if (file) { |
5afbbe0d AM |
6052 | + hsrc.hd = au_hdentry(dinfo, cpg->bsrc); |
6053 | + hsrc.h_dentry = hsrc.hd->hd_dentry; | |
6054 | + hsrc.hd->hd_dentry = au_hf_top(file)->f_path.dentry; | |
027c5e7a | 6055 | + } |
c2b27bf2 AM |
6056 | + flags_orig = cpg->flags; |
6057 | + cpg->flags = !AuCpup_DTIME; | |
6058 | + err = au_cpup_single(cpg, /*h_parent*/NULL); | |
6059 | + cpg->flags = flags_orig; | |
027c5e7a AM |
6060 | + if (file) { |
6061 | + if (!err) | |
6062 | + err = au_reopen_nondir(file); | |
5afbbe0d | 6063 | + hsrc.hd->hd_dentry = hsrc.h_dentry; |
1facf9fc | 6064 | + } |
5afbbe0d AM |
6065 | + hdst.hd->hd_dentry = hdst.h_dentry; |
6066 | + dinfo->di_btop = cpg->bsrc; | |
c2b27bf2 | 6067 | + cpg->bsrc = bsrc_orig; |
1facf9fc | 6068 | + |
6069 | + return err; | |
6070 | +} | |
6071 | + | |
c2b27bf2 | 6072 | +static int au_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 6073 | +{ |
6074 | + int err; | |
c2b27bf2 | 6075 | + aufs_bindex_t bdst; |
1facf9fc | 6076 | + struct au_dtime dt; |
c2b27bf2 | 6077 | + struct dentry *dentry, *parent, *h_parent, *wh_dentry; |
1facf9fc | 6078 | + struct au_branch *br; |
6079 | + struct path h_path; | |
6080 | + | |
c2b27bf2 AM |
6081 | + dentry = cpg->dentry; |
6082 | + bdst = cpg->bdst; | |
1facf9fc | 6083 | + br = au_sbr(dentry->d_sb, bdst); |
6084 | + parent = dget_parent(dentry); | |
6085 | + h_parent = au_h_dptr(parent, bdst); | |
6086 | + wh_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
6087 | + err = PTR_ERR(wh_dentry); | |
6088 | + if (IS_ERR(wh_dentry)) | |
6089 | + goto out; | |
6090 | + | |
6091 | + h_path.dentry = h_parent; | |
86dc4139 | 6092 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 6093 | + au_dtime_store(&dt, parent, &h_path); |
c2b27bf2 | 6094 | + err = au_do_cpup_wh(cpg, wh_dentry, file); |
1facf9fc | 6095 | + if (unlikely(err)) |
6096 | + goto out_wh; | |
6097 | + | |
6098 | + dget(wh_dentry); | |
6099 | + h_path.dentry = wh_dentry; | |
2000de60 | 6100 | + if (!d_is_dir(wh_dentry)) { |
523b37e3 | 6101 | + /* no delegation since it is just created */ |
5527c038 | 6102 | + err = vfsub_unlink(d_inode(h_parent), &h_path, |
523b37e3 AM |
6103 | + /*delegated*/NULL, /*force*/0); |
6104 | + } else | |
5527c038 | 6105 | + err = vfsub_rmdir(d_inode(h_parent), &h_path); |
1facf9fc | 6106 | + if (unlikely(err)) { |
523b37e3 AM |
6107 | + AuIOErr("failed remove copied-up tmp file %pd(%d)\n", |
6108 | + wh_dentry, err); | |
1facf9fc | 6109 | + err = -EIO; |
6110 | + } | |
6111 | + au_dtime_revert(&dt); | |
5527c038 | 6112 | + au_set_hi_wh(d_inode(dentry), bdst, wh_dentry); |
1facf9fc | 6113 | + |
4f0767ce | 6114 | +out_wh: |
1facf9fc | 6115 | + dput(wh_dentry); |
4f0767ce | 6116 | +out: |
1facf9fc | 6117 | + dput(parent); |
6118 | + return err; | |
6119 | +} | |
6120 | + | |
6121 | +struct au_cpup_wh_args { | |
6122 | + int *errp; | |
c2b27bf2 | 6123 | + struct au_cp_generic *cpg; |
1facf9fc | 6124 | + struct file *file; |
6125 | +}; | |
6126 | + | |
6127 | +static void au_call_cpup_wh(void *args) | |
6128 | +{ | |
6129 | + struct au_cpup_wh_args *a = args; | |
86dc4139 | 6130 | + |
c2b27bf2 AM |
6131 | + au_pin_hdir_acquire_nest(a->cpg->pin); |
6132 | + *a->errp = au_cpup_wh(a->cpg, a->file); | |
6133 | + au_pin_hdir_release(a->cpg->pin); | |
1facf9fc | 6134 | +} |
6135 | + | |
c2b27bf2 | 6136 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file) |
1facf9fc | 6137 | +{ |
6138 | + int err, wkq_err; | |
c2b27bf2 | 6139 | + aufs_bindex_t bdst; |
c1595e42 | 6140 | + struct dentry *dentry, *parent, *h_orph, *h_parent; |
86dc4139 | 6141 | + struct inode *dir, *h_dir, *h_tmpdir; |
1facf9fc | 6142 | + struct au_wbr *wbr; |
c2b27bf2 | 6143 | + struct au_pin wh_pin, *pin_orig; |
1facf9fc | 6144 | + |
c2b27bf2 AM |
6145 | + dentry = cpg->dentry; |
6146 | + bdst = cpg->bdst; | |
1facf9fc | 6147 | + parent = dget_parent(dentry); |
5527c038 | 6148 | + dir = d_inode(parent); |
1facf9fc | 6149 | + h_orph = NULL; |
6150 | + h_parent = NULL; | |
6151 | + h_dir = au_igrab(au_h_iptr(dir, bdst)); | |
6152 | + h_tmpdir = h_dir; | |
c2b27bf2 | 6153 | + pin_orig = NULL; |
1facf9fc | 6154 | + if (!h_dir->i_nlink) { |
6155 | + wbr = au_sbr(dentry->d_sb, bdst)->br_wbr; | |
6156 | + h_orph = wbr->wbr_orph; | |
6157 | + | |
6158 | + h_parent = dget(au_h_dptr(parent, bdst)); | |
1facf9fc | 6159 | + au_set_h_dptr(parent, bdst, dget(h_orph)); |
5527c038 | 6160 | + h_tmpdir = d_inode(h_orph); |
1facf9fc | 6161 | + au_set_h_iptr(dir, bdst, au_igrab(h_tmpdir), /*flags*/0); |
6162 | + | |
febd17d6 | 6163 | + inode_lock_nested(h_tmpdir, AuLsc_I_PARENT3); |
4a4d8108 | 6164 | + /* todo: au_h_open_pre()? */ |
86dc4139 | 6165 | + |
c2b27bf2 | 6166 | + pin_orig = cpg->pin; |
86dc4139 | 6167 | + au_pin_init(&wh_pin, dentry, bdst, AuLsc_DI_PARENT, |
c2b27bf2 AM |
6168 | + AuLsc_I_PARENT3, cpg->pin->udba, AuPin_DI_LOCKED); |
6169 | + cpg->pin = &wh_pin; | |
1facf9fc | 6170 | + } |
6171 | + | |
53392da6 | 6172 | + if (!au_test_h_perm_sio(h_tmpdir, MAY_EXEC | MAY_WRITE) |
5527c038 | 6173 | + && !au_cpup_sio_test(cpg->pin, d_inode(dentry)->i_mode)) |
c2b27bf2 | 6174 | + err = au_cpup_wh(cpg, file); |
1facf9fc | 6175 | + else { |
6176 | + struct au_cpup_wh_args args = { | |
6177 | + .errp = &err, | |
c2b27bf2 AM |
6178 | + .cpg = cpg, |
6179 | + .file = file | |
1facf9fc | 6180 | + }; |
6181 | + wkq_err = au_wkq_wait(au_call_cpup_wh, &args); | |
6182 | + if (unlikely(wkq_err)) | |
6183 | + err = wkq_err; | |
6184 | + } | |
6185 | + | |
6186 | + if (h_orph) { | |
febd17d6 | 6187 | + inode_unlock(h_tmpdir); |
4a4d8108 | 6188 | + /* todo: au_h_open_post()? */ |
1facf9fc | 6189 | + au_set_h_iptr(dir, bdst, au_igrab(h_dir), /*flags*/0); |
1facf9fc | 6190 | + au_set_h_dptr(parent, bdst, h_parent); |
c2b27bf2 AM |
6191 | + AuDebugOn(!pin_orig); |
6192 | + cpg->pin = pin_orig; | |
1facf9fc | 6193 | + } |
6194 | + iput(h_dir); | |
6195 | + dput(parent); | |
6196 | + | |
6197 | + return err; | |
6198 | +} | |
6199 | + | |
6200 | +/* ---------------------------------------------------------------------- */ | |
6201 | + | |
6202 | +/* | |
6203 | + * generic routine for both of copy-up and copy-down. | |
6204 | + */ | |
6205 | +/* cf. revalidate function in file.c */ | |
6206 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
6207 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6208 | + struct au_pin *pin, |
1facf9fc | 6209 | + struct dentry *h_parent, void *arg), |
6210 | + void *arg) | |
6211 | +{ | |
6212 | + int err; | |
6213 | + struct au_pin pin; | |
5527c038 | 6214 | + struct dentry *d, *parent, *h_parent, *real_parent, *h_dentry; |
1facf9fc | 6215 | + |
6216 | + err = 0; | |
6217 | + parent = dget_parent(dentry); | |
6218 | + if (IS_ROOT(parent)) | |
6219 | + goto out; | |
6220 | + | |
6221 | + au_pin_init(&pin, dentry, bdst, AuLsc_DI_PARENT2, AuLsc_I_PARENT2, | |
6222 | + au_opt_udba(dentry->d_sb), AuPin_MNT_WRITE); | |
6223 | + | |
6224 | + /* do not use au_dpage */ | |
6225 | + real_parent = parent; | |
6226 | + while (1) { | |
6227 | + dput(parent); | |
6228 | + parent = dget_parent(dentry); | |
6229 | + h_parent = au_h_dptr(parent, bdst); | |
6230 | + if (h_parent) | |
6231 | + goto out; /* success */ | |
6232 | + | |
6233 | + /* find top dir which is necessary to cpup */ | |
6234 | + do { | |
6235 | + d = parent; | |
6236 | + dput(parent); | |
6237 | + parent = dget_parent(d); | |
6238 | + di_read_lock_parent3(parent, !AuLock_IR); | |
6239 | + h_parent = au_h_dptr(parent, bdst); | |
6240 | + di_read_unlock(parent, !AuLock_IR); | |
6241 | + } while (!h_parent); | |
6242 | + | |
6243 | + if (d != real_parent) | |
6244 | + di_write_lock_child3(d); | |
6245 | + | |
6246 | + /* somebody else might create while we were sleeping */ | |
5527c038 JR |
6247 | + h_dentry = au_h_dptr(d, bdst); |
6248 | + if (!h_dentry || d_is_negative(h_dentry)) { | |
6249 | + if (h_dentry) | |
5afbbe0d | 6250 | + au_update_dbtop(d); |
1facf9fc | 6251 | + |
6252 | + au_pin_set_dentry(&pin, d); | |
6253 | + err = au_do_pin(&pin); | |
6254 | + if (!err) { | |
86dc4139 | 6255 | + err = cp(d, bdst, &pin, h_parent, arg); |
1facf9fc | 6256 | + au_unpin(&pin); |
6257 | + } | |
6258 | + } | |
6259 | + | |
6260 | + if (d != real_parent) | |
6261 | + di_write_unlock(d); | |
6262 | + if (unlikely(err)) | |
6263 | + break; | |
6264 | + } | |
6265 | + | |
4f0767ce | 6266 | +out: |
1facf9fc | 6267 | + dput(parent); |
6268 | + return err; | |
6269 | +} | |
6270 | + | |
6271 | +static int au_cpup_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6272 | + struct au_pin *pin, |
2000de60 | 6273 | + struct dentry *h_parent __maybe_unused, |
1facf9fc | 6274 | + void *arg __maybe_unused) |
6275 | +{ | |
c2b27bf2 AM |
6276 | + struct au_cp_generic cpg = { |
6277 | + .dentry = dentry, | |
6278 | + .bdst = bdst, | |
6279 | + .bsrc = -1, | |
6280 | + .len = 0, | |
6281 | + .pin = pin, | |
6282 | + .flags = AuCpup_DTIME | |
6283 | + }; | |
6284 | + return au_sio_cpup_simple(&cpg); | |
1facf9fc | 6285 | +} |
6286 | + | |
6287 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
6288 | +{ | |
6289 | + return au_cp_dirs(dentry, bdst, au_cpup_dir, NULL); | |
6290 | +} | |
6291 | + | |
6292 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
6293 | +{ | |
6294 | + int err; | |
6295 | + struct dentry *parent; | |
6296 | + struct inode *dir; | |
6297 | + | |
6298 | + parent = dget_parent(dentry); | |
5527c038 | 6299 | + dir = d_inode(parent); |
1facf9fc | 6300 | + err = 0; |
6301 | + if (au_h_iptr(dir, bdst)) | |
6302 | + goto out; | |
6303 | + | |
6304 | + di_read_unlock(parent, AuLock_IR); | |
6305 | + di_write_lock_parent(parent); | |
6306 | + /* someone else might change our inode while we were sleeping */ | |
6307 | + if (!au_h_iptr(dir, bdst)) | |
6308 | + err = au_cpup_dirs(dentry, bdst); | |
6309 | + di_downgrade_lock(parent, AuLock_IR); | |
6310 | + | |
4f0767ce | 6311 | +out: |
1facf9fc | 6312 | + dput(parent); |
6313 | + return err; | |
6314 | +} | |
7f207e10 | 6315 | diff -urN /usr/share/empty/fs/aufs/cpup.h linux/fs/aufs/cpup.h |
eca34b5c | 6316 | --- /usr/share/empty/fs/aufs/cpup.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 6317 | +++ linux/fs/aufs/cpup.h 2020-01-27 10:57:18.168871450 +0100 |
062440b3 AM |
6318 | @@ -0,0 +1,100 @@ |
6319 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 6320 | +/* |
d58c55f2 | 6321 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 6322 | + * |
6323 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6324 | + * it under the terms of the GNU General Public License as published by | |
6325 | + * the Free Software Foundation; either version 2 of the License, or | |
6326 | + * (at your option) any later version. | |
dece6358 AM |
6327 | + * |
6328 | + * This program is distributed in the hope that it will be useful, | |
6329 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6330 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6331 | + * GNU General Public License for more details. | |
6332 | + * | |
6333 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6334 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6335 | + */ |
6336 | + | |
6337 | +/* | |
6338 | + * copy-up/down functions | |
6339 | + */ | |
6340 | + | |
6341 | +#ifndef __AUFS_CPUP_H__ | |
6342 | +#define __AUFS_CPUP_H__ | |
6343 | + | |
6344 | +#ifdef __KERNEL__ | |
6345 | + | |
dece6358 | 6346 | +#include <linux/path.h> |
1facf9fc | 6347 | + |
dece6358 AM |
6348 | +struct inode; |
6349 | +struct file; | |
86dc4139 | 6350 | +struct au_pin; |
dece6358 | 6351 | + |
86dc4139 | 6352 | +void au_cpup_attr_flags(struct inode *dst, unsigned int iflags); |
1facf9fc | 6353 | +void au_cpup_attr_timesizes(struct inode *inode); |
6354 | +void au_cpup_attr_nlink(struct inode *inode, int force); | |
6355 | +void au_cpup_attr_changeable(struct inode *inode); | |
6356 | +void au_cpup_igen(struct inode *inode, struct inode *h_inode); | |
6357 | +void au_cpup_attr_all(struct inode *inode, int force); | |
6358 | + | |
6359 | +/* ---------------------------------------------------------------------- */ | |
6360 | + | |
c2b27bf2 AM |
6361 | +struct au_cp_generic { |
6362 | + struct dentry *dentry; | |
6363 | + aufs_bindex_t bdst, bsrc; | |
6364 | + loff_t len; | |
6365 | + struct au_pin *pin; | |
6366 | + unsigned int flags; | |
6367 | +}; | |
6368 | + | |
1facf9fc | 6369 | +/* cpup flags */ |
392086de AM |
6370 | +#define AuCpup_DTIME 1 /* do dtime_store/revert */ |
6371 | +#define AuCpup_KEEPLINO (1 << 1) /* do not clear the lower xino, | |
6372 | + for link(2) */ | |
6373 | +#define AuCpup_RENAME (1 << 2) /* rename after cpup */ | |
6374 | +#define AuCpup_HOPEN (1 << 3) /* call h_open_pre/post() in | |
6375 | + cpup */ | |
6376 | +#define AuCpup_OVERWRITE (1 << 4) /* allow overwriting the | |
6377 | + existing entry */ | |
6378 | +#define AuCpup_RWDST (1 << 5) /* force write target even if | |
6379 | + the branch is marked as RO */ | |
c2b27bf2 | 6380 | + |
8b6a4947 AM |
6381 | +#ifndef CONFIG_AUFS_BR_HFSPLUS |
6382 | +#undef AuCpup_HOPEN | |
6383 | +#define AuCpup_HOPEN 0 | |
6384 | +#endif | |
6385 | + | |
1facf9fc | 6386 | +#define au_ftest_cpup(flags, name) ((flags) & AuCpup_##name) |
7f207e10 AM |
6387 | +#define au_fset_cpup(flags, name) \ |
6388 | + do { (flags) |= AuCpup_##name; } while (0) | |
6389 | +#define au_fclr_cpup(flags, name) \ | |
6390 | + do { (flags) &= ~AuCpup_##name; } while (0) | |
1facf9fc | 6391 | + |
6392 | +int au_copy_file(struct file *dst, struct file *src, loff_t len); | |
c2b27bf2 AM |
6393 | +int au_sio_cpup_simple(struct au_cp_generic *cpg); |
6394 | +int au_sio_cpdown_simple(struct au_cp_generic *cpg); | |
6395 | +int au_sio_cpup_wh(struct au_cp_generic *cpg, struct file *file); | |
1facf9fc | 6396 | + |
6397 | +int au_cp_dirs(struct dentry *dentry, aufs_bindex_t bdst, | |
6398 | + int (*cp)(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 6399 | + struct au_pin *pin, |
1facf9fc | 6400 | + struct dentry *h_parent, void *arg), |
6401 | + void *arg); | |
6402 | +int au_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
6403 | +int au_test_and_cpup_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
6404 | + | |
6405 | +/* ---------------------------------------------------------------------- */ | |
6406 | + | |
6407 | +/* keep timestamps when copyup */ | |
6408 | +struct au_dtime { | |
6409 | + struct dentry *dt_dentry; | |
6410 | + struct path dt_h_path; | |
cd7a4cd9 | 6411 | + struct timespec64 dt_atime, dt_mtime; |
1facf9fc | 6412 | +}; |
6413 | +void au_dtime_store(struct au_dtime *dt, struct dentry *dentry, | |
6414 | + struct path *h_path); | |
6415 | +void au_dtime_revert(struct au_dtime *dt); | |
6416 | + | |
6417 | +#endif /* __KERNEL__ */ | |
6418 | +#endif /* __AUFS_CPUP_H__ */ | |
7f207e10 | 6419 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.c linux/fs/aufs/dbgaufs.c |
eca34b5c | 6420 | --- /usr/share/empty/fs/aufs/dbgaufs.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 6421 | +++ linux/fs/aufs/dbgaufs.c 2020-01-27 10:57:18.168871450 +0100 |
9f237c51 | 6422 | @@ -0,0 +1,526 @@ |
cd7a4cd9 | 6423 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 6424 | +/* |
d58c55f2 | 6425 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 6426 | + * |
6427 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6428 | + * it under the terms of the GNU General Public License as published by | |
6429 | + * the Free Software Foundation; either version 2 of the License, or | |
6430 | + * (at your option) any later version. | |
dece6358 AM |
6431 | + * |
6432 | + * This program is distributed in the hope that it will be useful, | |
6433 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6434 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6435 | + * GNU General Public License for more details. | |
6436 | + * | |
6437 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6438 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6439 | + */ |
6440 | + | |
6441 | +/* | |
6442 | + * debugfs interface | |
6443 | + */ | |
6444 | + | |
6445 | +#include <linux/debugfs.h> | |
6446 | +#include "aufs.h" | |
6447 | + | |
6448 | +#ifndef CONFIG_SYSFS | |
6449 | +#error DEBUG_FS depends upon SYSFS | |
6450 | +#endif | |
6451 | + | |
6452 | +static struct dentry *dbgaufs; | |
cd7a4cd9 | 6453 | +static const mode_t dbgaufs_mode = 0444; |
1facf9fc | 6454 | + |
6455 | +/* 20 is max digits length of ulong 64 */ | |
6456 | +struct dbgaufs_arg { | |
6457 | + int n; | |
6458 | + char a[20 * 4]; | |
6459 | +}; | |
6460 | + | |
6461 | +/* | |
6462 | + * common function for all XINO files | |
6463 | + */ | |
6464 | +static int dbgaufs_xi_release(struct inode *inode __maybe_unused, | |
6465 | + struct file *file) | |
6466 | +{ | |
9f237c51 AM |
6467 | + void *p; |
6468 | + | |
6469 | + p = file->private_data; | |
6470 | + if (p) { | |
6471 | + /* this is struct dbgaufs_arg */ | |
6472 | + AuDebugOn(!au_kfree_sz_test(p)); | |
6473 | + au_kfree_do_rcu(p); | |
6474 | + } | |
1facf9fc | 6475 | + return 0; |
6476 | +} | |
6477 | + | |
062440b3 AM |
6478 | +static int dbgaufs_xi_open(struct file *xf, struct file *file, int do_fcnt, |
6479 | + int cnt) | |
1facf9fc | 6480 | +{ |
6481 | + int err; | |
6482 | + struct kstat st; | |
6483 | + struct dbgaufs_arg *p; | |
6484 | + | |
6485 | + err = -ENOMEM; | |
6486 | + p = kmalloc(sizeof(*p), GFP_NOFS); | |
6487 | + if (unlikely(!p)) | |
6488 | + goto out; | |
6489 | + | |
6490 | + err = 0; | |
6491 | + p->n = 0; | |
6492 | + file->private_data = p; | |
6493 | + if (!xf) | |
6494 | + goto out; | |
6495 | + | |
521ced18 | 6496 | + err = vfsub_getattr(&xf->f_path, &st); |
1facf9fc | 6497 | + if (!err) { |
6498 | + if (do_fcnt) | |
6499 | + p->n = snprintf | |
062440b3 AM |
6500 | + (p->a, sizeof(p->a), "%d, %llux%u %lld\n", |
6501 | + cnt, st.blocks, st.blksize, | |
1facf9fc | 6502 | + (long long)st.size); |
6503 | + else | |
521ced18 | 6504 | + p->n = snprintf(p->a, sizeof(p->a), "%llux%u %lld\n", |
1facf9fc | 6505 | + st.blocks, st.blksize, |
6506 | + (long long)st.size); | |
6507 | + AuDebugOn(p->n >= sizeof(p->a)); | |
6508 | + } else { | |
6509 | + p->n = snprintf(p->a, sizeof(p->a), "err %d\n", err); | |
6510 | + err = 0; | |
6511 | + } | |
6512 | + | |
4f0767ce | 6513 | +out: |
1facf9fc | 6514 | + return err; |
1facf9fc | 6515 | +} |
6516 | + | |
6517 | +static ssize_t dbgaufs_xi_read(struct file *file, char __user *buf, | |
6518 | + size_t count, loff_t *ppos) | |
6519 | +{ | |
6520 | + struct dbgaufs_arg *p; | |
6521 | + | |
6522 | + p = file->private_data; | |
6523 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6524 | +} | |
6525 | + | |
6526 | +/* ---------------------------------------------------------------------- */ | |
6527 | + | |
86dc4139 AM |
6528 | +struct dbgaufs_plink_arg { |
6529 | + int n; | |
6530 | + char a[]; | |
6531 | +}; | |
6532 | + | |
6533 | +static int dbgaufs_plink_release(struct inode *inode __maybe_unused, | |
6534 | + struct file *file) | |
6535 | +{ | |
1c60b727 | 6536 | + free_page((unsigned long)file->private_data); |
86dc4139 AM |
6537 | + return 0; |
6538 | +} | |
6539 | + | |
6540 | +static int dbgaufs_plink_open(struct inode *inode, struct file *file) | |
6541 | +{ | |
6542 | + int err, i, limit; | |
6543 | + unsigned long n, sum; | |
6544 | + struct dbgaufs_plink_arg *p; | |
6545 | + struct au_sbinfo *sbinfo; | |
6546 | + struct super_block *sb; | |
8b6a4947 | 6547 | + struct hlist_bl_head *hbl; |
86dc4139 AM |
6548 | + |
6549 | + err = -ENOMEM; | |
6550 | + p = (void *)get_zeroed_page(GFP_NOFS); | |
6551 | + if (unlikely(!p)) | |
6552 | + goto out; | |
6553 | + | |
6554 | + err = -EFBIG; | |
6555 | + sbinfo = inode->i_private; | |
6556 | + sb = sbinfo->si_sb; | |
6557 | + si_noflush_read_lock(sb); | |
6558 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
6559 | + limit = PAGE_SIZE - sizeof(p->n); | |
6560 | + | |
6561 | + /* the number of buckets */ | |
6562 | + n = snprintf(p->a + p->n, limit, "%d\n", AuPlink_NHASH); | |
6563 | + p->n += n; | |
6564 | + limit -= n; | |
6565 | + | |
6566 | + sum = 0; | |
8b6a4947 AM |
6567 | + for (i = 0, hbl = sbinfo->si_plink; i < AuPlink_NHASH; |
6568 | + i++, hbl++) { | |
6569 | + n = au_hbl_count(hbl); | |
86dc4139 AM |
6570 | + sum += n; |
6571 | + | |
6572 | + n = snprintf(p->a + p->n, limit, "%lu ", n); | |
6573 | + p->n += n; | |
6574 | + limit -= n; | |
6575 | + if (unlikely(limit <= 0)) | |
6576 | + goto out_free; | |
6577 | + } | |
6578 | + p->a[p->n - 1] = '\n'; | |
6579 | + | |
6580 | + /* the sum of plinks */ | |
6581 | + n = snprintf(p->a + p->n, limit, "%lu\n", sum); | |
6582 | + p->n += n; | |
6583 | + limit -= n; | |
6584 | + if (unlikely(limit <= 0)) | |
6585 | + goto out_free; | |
6586 | + } else { | |
6587 | +#define str "1\n0\n0\n" | |
6588 | + p->n = sizeof(str) - 1; | |
6589 | + strcpy(p->a, str); | |
6590 | +#undef str | |
6591 | + } | |
6592 | + si_read_unlock(sb); | |
6593 | + | |
6594 | + err = 0; | |
6595 | + file->private_data = p; | |
6596 | + goto out; /* success */ | |
6597 | + | |
6598 | +out_free: | |
1c60b727 | 6599 | + free_page((unsigned long)p); |
86dc4139 AM |
6600 | +out: |
6601 | + return err; | |
6602 | +} | |
6603 | + | |
6604 | +static ssize_t dbgaufs_plink_read(struct file *file, char __user *buf, | |
6605 | + size_t count, loff_t *ppos) | |
6606 | +{ | |
6607 | + struct dbgaufs_plink_arg *p; | |
6608 | + | |
6609 | + p = file->private_data; | |
6610 | + return simple_read_from_buffer(buf, count, ppos, p->a, p->n); | |
6611 | +} | |
6612 | + | |
6613 | +static const struct file_operations dbgaufs_plink_fop = { | |
6614 | + .owner = THIS_MODULE, | |
6615 | + .open = dbgaufs_plink_open, | |
6616 | + .release = dbgaufs_plink_release, | |
6617 | + .read = dbgaufs_plink_read | |
6618 | +}; | |
6619 | + | |
6620 | +/* ---------------------------------------------------------------------- */ | |
6621 | + | |
1facf9fc | 6622 | +static int dbgaufs_xib_open(struct inode *inode, struct file *file) |
6623 | +{ | |
6624 | + int err; | |
6625 | + struct au_sbinfo *sbinfo; | |
6626 | + struct super_block *sb; | |
6627 | + | |
6628 | + sbinfo = inode->i_private; | |
6629 | + sb = sbinfo->si_sb; | |
6630 | + si_noflush_read_lock(sb); | |
062440b3 | 6631 | + err = dbgaufs_xi_open(sbinfo->si_xib, file, /*do_fcnt*/0, /*cnt*/0); |
1facf9fc | 6632 | + si_read_unlock(sb); |
6633 | + return err; | |
6634 | +} | |
6635 | + | |
6636 | +static const struct file_operations dbgaufs_xib_fop = { | |
4a4d8108 | 6637 | + .owner = THIS_MODULE, |
1facf9fc | 6638 | + .open = dbgaufs_xib_open, |
6639 | + .release = dbgaufs_xi_release, | |
6640 | + .read = dbgaufs_xi_read | |
6641 | +}; | |
6642 | + | |
6643 | +/* ---------------------------------------------------------------------- */ | |
6644 | + | |
6645 | +#define DbgaufsXi_PREFIX "xi" | |
6646 | + | |
6647 | +static int dbgaufs_xino_open(struct inode *inode, struct file *file) | |
6648 | +{ | |
acd2b654 | 6649 | + int err, idx; |
1facf9fc | 6650 | + long l; |
acd2b654 AM |
6651 | + aufs_bindex_t bindex; |
6652 | + char *p, a[sizeof(DbgaufsXi_PREFIX) + 8]; | |
1facf9fc | 6653 | + struct au_sbinfo *sbinfo; |
6654 | + struct super_block *sb; | |
acd2b654 | 6655 | + struct au_xino *xi; |
1facf9fc | 6656 | + struct file *xf; |
6657 | + struct qstr *name; | |
062440b3 | 6658 | + struct au_branch *br; |
1facf9fc | 6659 | + |
6660 | + err = -ENOENT; | |
2000de60 | 6661 | + name = &file->f_path.dentry->d_name; |
1facf9fc | 6662 | + if (unlikely(name->len < sizeof(DbgaufsXi_PREFIX) |
6663 | + || memcmp(name->name, DbgaufsXi_PREFIX, | |
6664 | + sizeof(DbgaufsXi_PREFIX) - 1))) | |
6665 | + goto out; | |
acd2b654 AM |
6666 | + |
6667 | + AuDebugOn(name->len >= sizeof(a)); | |
6668 | + memcpy(a, name->name, name->len); | |
6669 | + a[name->len] = '\0'; | |
6670 | + p = strchr(a, '-'); | |
6671 | + if (p) | |
6672 | + *p = '\0'; | |
6673 | + err = kstrtol(a + sizeof(DbgaufsXi_PREFIX) - 1, 10, &l); | |
1facf9fc | 6674 | + if (unlikely(err)) |
6675 | + goto out; | |
acd2b654 AM |
6676 | + bindex = l; |
6677 | + idx = 0; | |
6678 | + if (p) { | |
6679 | + err = kstrtol(p + 1, 10, &l); | |
6680 | + if (unlikely(err)) | |
6681 | + goto out; | |
6682 | + idx = l; | |
6683 | + } | |
1facf9fc | 6684 | + |
acd2b654 | 6685 | + err = -ENOENT; |
1facf9fc | 6686 | + sbinfo = inode->i_private; |
6687 | + sb = sbinfo->si_sb; | |
6688 | + si_noflush_read_lock(sb); | |
acd2b654 AM |
6689 | + if (unlikely(bindex < 0 || bindex > au_sbbot(sb))) |
6690 | + goto out_si; | |
6691 | + br = au_sbr(sb, bindex); | |
6692 | + xi = br->br_xino; | |
6693 | + if (unlikely(idx >= xi->xi_nfile)) | |
6694 | + goto out_si; | |
6695 | + xf = au_xino_file(xi, idx); | |
6696 | + if (xf) | |
062440b3 AM |
6697 | + err = dbgaufs_xi_open(xf, file, /*do_fcnt*/1, |
6698 | + au_xino_count(br)); | |
1facf9fc | 6699 | + |
acd2b654 AM |
6700 | +out_si: |
6701 | + si_read_unlock(sb); | |
4f0767ce | 6702 | +out: |
acd2b654 | 6703 | + AuTraceErr(err); |
1facf9fc | 6704 | + return err; |
6705 | +} | |
6706 | + | |
6707 | +static const struct file_operations dbgaufs_xino_fop = { | |
4a4d8108 | 6708 | + .owner = THIS_MODULE, |
1facf9fc | 6709 | + .open = dbgaufs_xino_open, |
6710 | + .release = dbgaufs_xi_release, | |
6711 | + .read = dbgaufs_xi_read | |
6712 | +}; | |
6713 | + | |
062440b3 AM |
6714 | +void dbgaufs_xino_del(struct au_branch *br) |
6715 | +{ | |
6716 | + struct dentry *dbgaufs; | |
6717 | + | |
6718 | + dbgaufs = br->br_dbgaufs; | |
6719 | + if (!dbgaufs) | |
6720 | + return; | |
6721 | + | |
6722 | + br->br_dbgaufs = NULL; | |
6723 | + /* debugfs acquires the parent i_mutex */ | |
6724 | + lockdep_off(); | |
6725 | + debugfs_remove(dbgaufs); | |
6726 | + lockdep_on(); | |
6727 | +} | |
6728 | + | |
1facf9fc | 6729 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) |
6730 | +{ | |
5afbbe0d | 6731 | + aufs_bindex_t bbot; |
1facf9fc | 6732 | + struct au_branch *br; |
1facf9fc | 6733 | + |
6734 | + if (!au_sbi(sb)->si_dbgaufs) | |
6735 | + return; | |
6736 | + | |
5afbbe0d AM |
6737 | + bbot = au_sbbot(sb); |
6738 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 6739 | + br = au_sbr(sb, bindex); |
062440b3 AM |
6740 | + dbgaufs_xino_del(br); |
6741 | + } | |
6742 | +} | |
6743 | + | |
acd2b654 AM |
6744 | +static void dbgaufs_br_do_add(struct super_block *sb, aufs_bindex_t bindex, |
6745 | + unsigned int idx, struct dentry *parent, | |
6746 | + struct au_sbinfo *sbinfo) | |
062440b3 AM |
6747 | +{ |
6748 | + struct au_branch *br; | |
6749 | + struct dentry *d; | |
acd2b654 AM |
6750 | + /* "xi" bindex(5) "-" idx(2) NULL */ |
6751 | + char name[sizeof(DbgaufsXi_PREFIX) + 8]; | |
062440b3 | 6752 | + |
acd2b654 AM |
6753 | + if (!idx) |
6754 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d", bindex); | |
6755 | + else | |
6756 | + snprintf(name, sizeof(name), DbgaufsXi_PREFIX "%d-%u", | |
6757 | + bindex, idx); | |
062440b3 AM |
6758 | + br = au_sbr(sb, bindex); |
6759 | + if (br->br_dbgaufs) { | |
6760 | + struct qstr qstr = QSTR_INIT(name, strlen(name)); | |
6761 | + | |
6762 | + if (!au_qstreq(&br->br_dbgaufs->d_name, &qstr)) { | |
6763 | + /* debugfs acquires the parent i_mutex */ | |
6764 | + lockdep_off(); | |
6765 | + d = debugfs_rename(parent, br->br_dbgaufs, parent, | |
6766 | + name); | |
6767 | + lockdep_on(); | |
6768 | + if (unlikely(!d)) | |
6769 | + pr_warn("failed renaming %pd/%s, ignored.\n", | |
6770 | + parent, name); | |
6771 | + } | |
6772 | + } else { | |
e2f27e51 | 6773 | + lockdep_off(); |
062440b3 AM |
6774 | + br->br_dbgaufs = debugfs_create_file(name, dbgaufs_mode, parent, |
6775 | + sbinfo, &dbgaufs_xino_fop); | |
e2f27e51 | 6776 | + lockdep_on(); |
062440b3 | 6777 | + if (unlikely(!br->br_dbgaufs)) |
acd2b654 | 6778 | + pr_warn("failed creating %pd/%s, ignored.\n", |
062440b3 | 6779 | + parent, name); |
1facf9fc | 6780 | + } |
6781 | +} | |
6782 | + | |
acd2b654 AM |
6783 | +static void dbgaufs_br_add(struct super_block *sb, aufs_bindex_t bindex, |
6784 | + struct dentry *parent, struct au_sbinfo *sbinfo) | |
6785 | +{ | |
6786 | + struct au_branch *br; | |
6787 | + struct au_xino *xi; | |
6788 | + unsigned int u; | |
6789 | + | |
6790 | + br = au_sbr(sb, bindex); | |
6791 | + xi = br->br_xino; | |
6792 | + for (u = 0; u < xi->xi_nfile; u++) | |
6793 | + dbgaufs_br_do_add(sb, bindex, u, parent, sbinfo); | |
6794 | +} | |
6795 | + | |
062440b3 | 6796 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown) |
1facf9fc | 6797 | +{ |
6798 | + struct au_sbinfo *sbinfo; | |
6799 | + struct dentry *parent; | |
5afbbe0d | 6800 | + aufs_bindex_t bbot; |
062440b3 AM |
6801 | + |
6802 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
6803 | + return; | |
1facf9fc | 6804 | + |
6805 | + sbinfo = au_sbi(sb); | |
6806 | + parent = sbinfo->si_dbgaufs; | |
6807 | + if (!parent) | |
6808 | + return; | |
6809 | + | |
5afbbe0d | 6810 | + bbot = au_sbbot(sb); |
062440b3 AM |
6811 | + if (topdown) |
6812 | + for (; bindex <= bbot; bindex++) | |
6813 | + dbgaufs_br_add(sb, bindex, parent, sbinfo); | |
6814 | + else | |
6815 | + for (; bbot >= bindex; bbot--) | |
6816 | + dbgaufs_br_add(sb, bbot, parent, sbinfo); | |
1facf9fc | 6817 | +} |
6818 | + | |
6819 | +/* ---------------------------------------------------------------------- */ | |
6820 | + | |
6821 | +#ifdef CONFIG_AUFS_EXPORT | |
6822 | +static int dbgaufs_xigen_open(struct inode *inode, struct file *file) | |
6823 | +{ | |
6824 | + int err; | |
6825 | + struct au_sbinfo *sbinfo; | |
6826 | + struct super_block *sb; | |
6827 | + | |
6828 | + sbinfo = inode->i_private; | |
6829 | + sb = sbinfo->si_sb; | |
6830 | + si_noflush_read_lock(sb); | |
062440b3 | 6831 | + err = dbgaufs_xi_open(sbinfo->si_xigen, file, /*do_fcnt*/0, /*cnt*/0); |
1facf9fc | 6832 | + si_read_unlock(sb); |
6833 | + return err; | |
6834 | +} | |
6835 | + | |
6836 | +static const struct file_operations dbgaufs_xigen_fop = { | |
4a4d8108 | 6837 | + .owner = THIS_MODULE, |
1facf9fc | 6838 | + .open = dbgaufs_xigen_open, |
6839 | + .release = dbgaufs_xi_release, | |
6840 | + .read = dbgaufs_xi_read | |
6841 | +}; | |
6842 | + | |
6843 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6844 | +{ | |
6845 | + int err; | |
6846 | + | |
dece6358 | 6847 | + /* |
c1595e42 | 6848 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6849 | + * so the tiny check for si_rwsem is unnecessary. |
6850 | + */ | |
6851 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6852 | + | |
1facf9fc | 6853 | + err = -EIO; |
6854 | + sbinfo->si_dbgaufs_xigen = debugfs_create_file | |
6855 | + ("xigen", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6856 | + &dbgaufs_xigen_fop); | |
6857 | + if (sbinfo->si_dbgaufs_xigen) | |
6858 | + err = 0; | |
6859 | + | |
6860 | + return err; | |
6861 | +} | |
6862 | +#else | |
6863 | +static int dbgaufs_xigen_init(struct au_sbinfo *sbinfo) | |
6864 | +{ | |
6865 | + return 0; | |
6866 | +} | |
6867 | +#endif /* CONFIG_AUFS_EXPORT */ | |
6868 | + | |
6869 | +/* ---------------------------------------------------------------------- */ | |
6870 | + | |
6871 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo) | |
6872 | +{ | |
dece6358 | 6873 | + /* |
7e9cd9fe | 6874 | + * This function is a dynamic '__fin' function actually, |
dece6358 AM |
6875 | + * so the tiny check for si_rwsem is unnecessary. |
6876 | + */ | |
6877 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6878 | + | |
1facf9fc | 6879 | + debugfs_remove_recursive(sbinfo->si_dbgaufs); |
6880 | + sbinfo->si_dbgaufs = NULL; | |
1facf9fc | 6881 | +} |
6882 | + | |
6883 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo) | |
6884 | +{ | |
6885 | + int err; | |
6886 | + char name[SysaufsSiNameLen]; | |
6887 | + | |
dece6358 | 6888 | + /* |
c1595e42 | 6889 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
6890 | + * so the tiny check for si_rwsem is unnecessary. |
6891 | + */ | |
6892 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
6893 | + | |
1facf9fc | 6894 | + err = -ENOENT; |
6895 | + if (!dbgaufs) { | |
6896 | + AuErr1("/debug/aufs is uninitialized\n"); | |
6897 | + goto out; | |
6898 | + } | |
6899 | + | |
6900 | + err = -EIO; | |
6901 | + sysaufs_name(sbinfo, name); | |
6902 | + sbinfo->si_dbgaufs = debugfs_create_dir(name, dbgaufs); | |
6903 | + if (unlikely(!sbinfo->si_dbgaufs)) | |
6904 | + goto out; | |
1facf9fc | 6905 | + |
062440b3 | 6906 | + /* regardless plink/noplink option */ |
86dc4139 AM |
6907 | + sbinfo->si_dbgaufs_plink = debugfs_create_file |
6908 | + ("plink", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6909 | + &dbgaufs_plink_fop); | |
6910 | + if (unlikely(!sbinfo->si_dbgaufs_plink)) | |
6911 | + goto out_dir; | |
6912 | + | |
062440b3 AM |
6913 | + /* regardless xino/noxino option */ |
6914 | + sbinfo->si_dbgaufs_xib = debugfs_create_file | |
6915 | + ("xib", dbgaufs_mode, sbinfo->si_dbgaufs, sbinfo, | |
6916 | + &dbgaufs_xib_fop); | |
6917 | + if (unlikely(!sbinfo->si_dbgaufs_xib)) | |
6918 | + goto out_dir; | |
6919 | + | |
1facf9fc | 6920 | + err = dbgaufs_xigen_init(sbinfo); |
6921 | + if (!err) | |
6922 | + goto out; /* success */ | |
6923 | + | |
4f0767ce | 6924 | +out_dir: |
1facf9fc | 6925 | + dbgaufs_si_fin(sbinfo); |
4f0767ce | 6926 | +out: |
062440b3 AM |
6927 | + if (unlikely(err)) |
6928 | + pr_err("debugfs/aufs failed\n"); | |
1facf9fc | 6929 | + return err; |
6930 | +} | |
6931 | + | |
6932 | +/* ---------------------------------------------------------------------- */ | |
6933 | + | |
6934 | +void dbgaufs_fin(void) | |
6935 | +{ | |
6936 | + debugfs_remove(dbgaufs); | |
6937 | +} | |
6938 | + | |
6939 | +int __init dbgaufs_init(void) | |
6940 | +{ | |
6941 | + int err; | |
6942 | + | |
6943 | + err = -EIO; | |
6944 | + dbgaufs = debugfs_create_dir(AUFS_NAME, NULL); | |
6945 | + if (dbgaufs) | |
6946 | + err = 0; | |
6947 | + return err; | |
6948 | +} | |
7f207e10 | 6949 | diff -urN /usr/share/empty/fs/aufs/dbgaufs.h linux/fs/aufs/dbgaufs.h |
eca34b5c | 6950 | --- /usr/share/empty/fs/aufs/dbgaufs.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 6951 | +++ linux/fs/aufs/dbgaufs.h 2020-01-27 10:57:18.168871450 +0100 |
062440b3 AM |
6952 | @@ -0,0 +1,53 @@ |
6953 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 6954 | +/* |
d58c55f2 | 6955 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 6956 | + * |
6957 | + * This program, aufs is free software; you can redistribute it and/or modify | |
6958 | + * it under the terms of the GNU General Public License as published by | |
6959 | + * the Free Software Foundation; either version 2 of the License, or | |
6960 | + * (at your option) any later version. | |
dece6358 AM |
6961 | + * |
6962 | + * This program is distributed in the hope that it will be useful, | |
6963 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
6964 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
6965 | + * GNU General Public License for more details. | |
6966 | + * | |
6967 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 6968 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 6969 | + */ |
6970 | + | |
6971 | +/* | |
6972 | + * debugfs interface | |
6973 | + */ | |
6974 | + | |
6975 | +#ifndef __DBGAUFS_H__ | |
6976 | +#define __DBGAUFS_H__ | |
6977 | + | |
6978 | +#ifdef __KERNEL__ | |
6979 | + | |
dece6358 | 6980 | +struct super_block; |
1facf9fc | 6981 | +struct au_sbinfo; |
062440b3 | 6982 | +struct au_branch; |
dece6358 | 6983 | + |
1facf9fc | 6984 | +#ifdef CONFIG_DEBUG_FS |
6985 | +/* dbgaufs.c */ | |
062440b3 | 6986 | +void dbgaufs_xino_del(struct au_branch *br); |
1facf9fc | 6987 | +void dbgaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); |
062440b3 | 6988 | +void dbgaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex, int topdown); |
1facf9fc | 6989 | +void dbgaufs_si_fin(struct au_sbinfo *sbinfo); |
6990 | +int dbgaufs_si_init(struct au_sbinfo *sbinfo); | |
6991 | +void dbgaufs_fin(void); | |
6992 | +int __init dbgaufs_init(void); | |
1facf9fc | 6993 | +#else |
062440b3 | 6994 | +AuStubVoid(dbgaufs_xino_del, struct au_branch *br) |
4a4d8108 | 6995 | +AuStubVoid(dbgaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) |
062440b3 AM |
6996 | +AuStubVoid(dbgaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex, |
6997 | + int topdown) | |
4a4d8108 AM |
6998 | +AuStubVoid(dbgaufs_si_fin, struct au_sbinfo *sbinfo) |
6999 | +AuStubInt0(dbgaufs_si_init, struct au_sbinfo *sbinfo) | |
7000 | +AuStubVoid(dbgaufs_fin, void) | |
7001 | +AuStubInt0(__init dbgaufs_init, void) | |
1facf9fc | 7002 | +#endif /* CONFIG_DEBUG_FS */ |
7003 | + | |
7004 | +#endif /* __KERNEL__ */ | |
7005 | +#endif /* __DBGAUFS_H__ */ | |
7f207e10 | 7006 | diff -urN /usr/share/empty/fs/aufs/dcsub.c linux/fs/aufs/dcsub.c |
eca34b5c | 7007 | --- /usr/share/empty/fs/aufs/dcsub.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 7008 | +++ linux/fs/aufs/dcsub.c 2020-01-27 10:57:18.168871450 +0100 |
cd7a4cd9 AM |
7009 | @@ -0,0 +1,225 @@ |
7010 | +// SPDX-License-Identifier: GPL-2.0 | |
1facf9fc | 7011 | +/* |
d58c55f2 | 7012 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 7013 | + * |
7014 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7015 | + * it under the terms of the GNU General Public License as published by | |
7016 | + * the Free Software Foundation; either version 2 of the License, or | |
7017 | + * (at your option) any later version. | |
dece6358 AM |
7018 | + * |
7019 | + * This program is distributed in the hope that it will be useful, | |
7020 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7021 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7022 | + * GNU General Public License for more details. | |
7023 | + * | |
7024 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7025 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7026 | + */ |
7027 | + | |
7028 | +/* | |
7029 | + * sub-routines for dentry cache | |
7030 | + */ | |
7031 | + | |
7032 | +#include "aufs.h" | |
7033 | + | |
7034 | +static void au_dpage_free(struct au_dpage *dpage) | |
7035 | +{ | |
7036 | + int i; | |
7037 | + struct dentry **p; | |
7038 | + | |
7039 | + p = dpage->dentries; | |
7040 | + for (i = 0; i < dpage->ndentry; i++) | |
7041 | + dput(*p++); | |
1c60b727 | 7042 | + free_page((unsigned long)dpage->dentries); |
1facf9fc | 7043 | +} |
7044 | + | |
7045 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp) | |
7046 | +{ | |
7047 | + int err; | |
7048 | + void *p; | |
7049 | + | |
7050 | + err = -ENOMEM; | |
7051 | + dpages->dpages = kmalloc(sizeof(*dpages->dpages), gfp); | |
7052 | + if (unlikely(!dpages->dpages)) | |
7053 | + goto out; | |
7054 | + | |
7055 | + p = (void *)__get_free_page(gfp); | |
7056 | + if (unlikely(!p)) | |
7057 | + goto out_dpages; | |
7058 | + | |
7059 | + dpages->dpages[0].ndentry = 0; | |
7060 | + dpages->dpages[0].dentries = p; | |
7061 | + dpages->ndpage = 1; | |
7062 | + return 0; /* success */ | |
7063 | + | |
4f0767ce | 7064 | +out_dpages: |
9f237c51 | 7065 | + au_kfree_try_rcu(dpages->dpages); |
4f0767ce | 7066 | +out: |
1facf9fc | 7067 | + return err; |
7068 | +} | |
7069 | + | |
7070 | +void au_dpages_free(struct au_dcsub_pages *dpages) | |
7071 | +{ | |
7072 | + int i; | |
7073 | + struct au_dpage *p; | |
7074 | + | |
7075 | + p = dpages->dpages; | |
7076 | + for (i = 0; i < dpages->ndpage; i++) | |
7077 | + au_dpage_free(p++); | |
9f237c51 | 7078 | + au_kfree_try_rcu(dpages->dpages); |
1facf9fc | 7079 | +} |
7080 | + | |
7081 | +static int au_dpages_append(struct au_dcsub_pages *dpages, | |
7082 | + struct dentry *dentry, gfp_t gfp) | |
7083 | +{ | |
7084 | + int err, sz; | |
7085 | + struct au_dpage *dpage; | |
7086 | + void *p; | |
7087 | + | |
7088 | + dpage = dpages->dpages + dpages->ndpage - 1; | |
7089 | + sz = PAGE_SIZE / sizeof(dentry); | |
7090 | + if (unlikely(dpage->ndentry >= sz)) { | |
7091 | + AuLabel(new dpage); | |
7092 | + err = -ENOMEM; | |
7093 | + sz = dpages->ndpage * sizeof(*dpages->dpages); | |
7094 | + p = au_kzrealloc(dpages->dpages, sz, | |
e2f27e51 AM |
7095 | + sz + sizeof(*dpages->dpages), gfp, |
7096 | + /*may_shrink*/0); | |
1facf9fc | 7097 | + if (unlikely(!p)) |
7098 | + goto out; | |
7099 | + | |
7100 | + dpages->dpages = p; | |
7101 | + dpage = dpages->dpages + dpages->ndpage; | |
7102 | + p = (void *)__get_free_page(gfp); | |
7103 | + if (unlikely(!p)) | |
7104 | + goto out; | |
7105 | + | |
7106 | + dpage->ndentry = 0; | |
7107 | + dpage->dentries = p; | |
7108 | + dpages->ndpage++; | |
7109 | + } | |
7110 | + | |
c1595e42 | 7111 | + AuDebugOn(au_dcount(dentry) <= 0); |
027c5e7a | 7112 | + dpage->dentries[dpage->ndentry++] = dget_dlock(dentry); |
1facf9fc | 7113 | + return 0; /* success */ |
7114 | + | |
4f0767ce | 7115 | +out: |
1facf9fc | 7116 | + return err; |
7117 | +} | |
7118 | + | |
c1595e42 JR |
7119 | +/* todo: BAD approach */ |
7120 | +/* copied from linux/fs/dcache.c */ | |
7121 | +enum d_walk_ret { | |
7122 | + D_WALK_CONTINUE, | |
7123 | + D_WALK_QUIT, | |
7124 | + D_WALK_NORETRY, | |
7125 | + D_WALK_SKIP, | |
7126 | +}; | |
7127 | + | |
7128 | +extern void d_walk(struct dentry *parent, void *data, | |
cd7a4cd9 | 7129 | + enum d_walk_ret (*enter)(void *, struct dentry *)); |
c1595e42 JR |
7130 | + |
7131 | +struct ac_dpages_arg { | |
1facf9fc | 7132 | + int err; |
c1595e42 JR |
7133 | + struct au_dcsub_pages *dpages; |
7134 | + struct super_block *sb; | |
7135 | + au_dpages_test test; | |
7136 | + void *arg; | |
7137 | +}; | |
1facf9fc | 7138 | + |
c1595e42 JR |
7139 | +static enum d_walk_ret au_call_dpages_append(void *_arg, struct dentry *dentry) |
7140 | +{ | |
7141 | + enum d_walk_ret ret; | |
7142 | + struct ac_dpages_arg *arg = _arg; | |
1facf9fc | 7143 | + |
c1595e42 JR |
7144 | + ret = D_WALK_CONTINUE; |
7145 | + if (dentry->d_sb == arg->sb | |
7146 | + && !IS_ROOT(dentry) | |
7147 | + && au_dcount(dentry) > 0 | |
7148 | + && au_di(dentry) | |
7149 | + && (!arg->test || arg->test(dentry, arg->arg))) { | |
7150 | + arg->err = au_dpages_append(arg->dpages, dentry, GFP_ATOMIC); | |
7151 | + if (unlikely(arg->err)) | |
7152 | + ret = D_WALK_QUIT; | |
1facf9fc | 7153 | + } |
7154 | + | |
c1595e42 JR |
7155 | + return ret; |
7156 | +} | |
027c5e7a | 7157 | + |
c1595e42 JR |
7158 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, |
7159 | + au_dpages_test test, void *arg) | |
7160 | +{ | |
7161 | + struct ac_dpages_arg args = { | |
7162 | + .err = 0, | |
7163 | + .dpages = dpages, | |
7164 | + .sb = root->d_sb, | |
7165 | + .test = test, | |
7166 | + .arg = arg | |
7167 | + }; | |
027c5e7a | 7168 | + |
cd7a4cd9 | 7169 | + d_walk(root, &args, au_call_dpages_append); |
c1595e42 JR |
7170 | + |
7171 | + return args.err; | |
1facf9fc | 7172 | +} |
7173 | + | |
7174 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
7175 | + int do_include, au_dpages_test test, void *arg) | |
7176 | +{ | |
7177 | + int err; | |
7178 | + | |
7179 | + err = 0; | |
027c5e7a AM |
7180 | + write_seqlock(&rename_lock); |
7181 | + spin_lock(&dentry->d_lock); | |
7182 | + if (do_include | |
c1595e42 | 7183 | + && au_dcount(dentry) > 0 |
027c5e7a | 7184 | + && (!test || test(dentry, arg))) |
1facf9fc | 7185 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
7186 | + spin_unlock(&dentry->d_lock); |
7187 | + if (unlikely(err)) | |
7188 | + goto out; | |
7189 | + | |
7190 | + /* | |
523b37e3 | 7191 | + * RCU for vfsmount is unnecessary since this is a traverse in a single |
027c5e7a AM |
7192 | + * mount |
7193 | + */ | |
1facf9fc | 7194 | + while (!IS_ROOT(dentry)) { |
027c5e7a AM |
7195 | + dentry = dentry->d_parent; /* rename_lock is locked */ |
7196 | + spin_lock(&dentry->d_lock); | |
c1595e42 | 7197 | + if (au_dcount(dentry) > 0 |
027c5e7a | 7198 | + && (!test || test(dentry, arg))) |
1facf9fc | 7199 | + err = au_dpages_append(dpages, dentry, GFP_ATOMIC); |
027c5e7a AM |
7200 | + spin_unlock(&dentry->d_lock); |
7201 | + if (unlikely(err)) | |
7202 | + break; | |
1facf9fc | 7203 | + } |
7204 | + | |
4f0767ce | 7205 | +out: |
027c5e7a | 7206 | + write_sequnlock(&rename_lock); |
1facf9fc | 7207 | + return err; |
7208 | +} | |
7209 | + | |
027c5e7a AM |
7210 | +static inline int au_dcsub_dpages_aufs(struct dentry *dentry, void *arg) |
7211 | +{ | |
7212 | + return au_di(dentry) && dentry->d_sb == arg; | |
7213 | +} | |
7214 | + | |
7215 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, | |
7216 | + struct dentry *dentry, int do_include) | |
7217 | +{ | |
7218 | + return au_dcsub_pages_rev(dpages, dentry, do_include, | |
7219 | + au_dcsub_dpages_aufs, dentry->d_sb); | |
7220 | +} | |
7221 | + | |
4a4d8108 | 7222 | +int au_test_subdir(struct dentry *d1, struct dentry *d2) |
1facf9fc | 7223 | +{ |
4a4d8108 AM |
7224 | + struct path path[2] = { |
7225 | + { | |
7226 | + .dentry = d1 | |
7227 | + }, | |
7228 | + { | |
7229 | + .dentry = d2 | |
7230 | + } | |
7231 | + }; | |
1facf9fc | 7232 | + |
4a4d8108 | 7233 | + return path_is_under(path + 0, path + 1); |
1facf9fc | 7234 | +} |
7f207e10 | 7235 | diff -urN /usr/share/empty/fs/aufs/dcsub.h linux/fs/aufs/dcsub.h |
eca34b5c | 7236 | --- /usr/share/empty/fs/aufs/dcsub.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 7237 | +++ linux/fs/aufs/dcsub.h 2020-01-27 10:57:18.168871450 +0100 |
062440b3 AM |
7238 | @@ -0,0 +1,137 @@ |
7239 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 7240 | +/* |
d58c55f2 | 7241 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 7242 | + * |
7243 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7244 | + * it under the terms of the GNU General Public License as published by | |
7245 | + * the Free Software Foundation; either version 2 of the License, or | |
7246 | + * (at your option) any later version. | |
dece6358 AM |
7247 | + * |
7248 | + * This program is distributed in the hope that it will be useful, | |
7249 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7250 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7251 | + * GNU General Public License for more details. | |
7252 | + * | |
7253 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7254 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7255 | + */ |
7256 | + | |
7257 | +/* | |
7258 | + * sub-routines for dentry cache | |
7259 | + */ | |
7260 | + | |
7261 | +#ifndef __AUFS_DCSUB_H__ | |
7262 | +#define __AUFS_DCSUB_H__ | |
7263 | + | |
7264 | +#ifdef __KERNEL__ | |
7265 | + | |
7f207e10 | 7266 | +#include <linux/dcache.h> |
027c5e7a | 7267 | +#include <linux/fs.h> |
dece6358 | 7268 | + |
1facf9fc | 7269 | +struct au_dpage { |
7270 | + int ndentry; | |
7271 | + struct dentry **dentries; | |
7272 | +}; | |
7273 | + | |
7274 | +struct au_dcsub_pages { | |
7275 | + int ndpage; | |
7276 | + struct au_dpage *dpages; | |
7277 | +}; | |
7278 | + | |
7279 | +/* ---------------------------------------------------------------------- */ | |
7280 | + | |
7f207e10 | 7281 | +/* dcsub.c */ |
1facf9fc | 7282 | +int au_dpages_init(struct au_dcsub_pages *dpages, gfp_t gfp); |
7283 | +void au_dpages_free(struct au_dcsub_pages *dpages); | |
7284 | +typedef int (*au_dpages_test)(struct dentry *dentry, void *arg); | |
7285 | +int au_dcsub_pages(struct au_dcsub_pages *dpages, struct dentry *root, | |
7286 | + au_dpages_test test, void *arg); | |
7287 | +int au_dcsub_pages_rev(struct au_dcsub_pages *dpages, struct dentry *dentry, | |
7288 | + int do_include, au_dpages_test test, void *arg); | |
027c5e7a AM |
7289 | +int au_dcsub_pages_rev_aufs(struct au_dcsub_pages *dpages, |
7290 | + struct dentry *dentry, int do_include); | |
4a4d8108 | 7291 | +int au_test_subdir(struct dentry *d1, struct dentry *d2); |
1facf9fc | 7292 | + |
7f207e10 AM |
7293 | +/* ---------------------------------------------------------------------- */ |
7294 | + | |
523b37e3 AM |
7295 | +/* |
7296 | + * todo: in linux-3.13, several similar (but faster) helpers are added to | |
7297 | + * include/linux/dcache.h. Try them (in the future). | |
7298 | + */ | |
7299 | + | |
027c5e7a AM |
7300 | +static inline int au_d_hashed_positive(struct dentry *d) |
7301 | +{ | |
7302 | + int err; | |
5527c038 | 7303 | + struct inode *inode = d_inode(d); |
076b876e | 7304 | + |
027c5e7a | 7305 | + err = 0; |
5527c038 JR |
7306 | + if (unlikely(d_unhashed(d) |
7307 | + || d_is_negative(d) | |
7308 | + || !inode->i_nlink)) | |
027c5e7a AM |
7309 | + err = -ENOENT; |
7310 | + return err; | |
7311 | +} | |
7312 | + | |
38d290e6 JR |
7313 | +static inline int au_d_linkable(struct dentry *d) |
7314 | +{ | |
7315 | + int err; | |
5527c038 | 7316 | + struct inode *inode = d_inode(d); |
076b876e | 7317 | + |
38d290e6 JR |
7318 | + err = au_d_hashed_positive(d); |
7319 | + if (err | |
5527c038 | 7320 | + && d_is_positive(d) |
38d290e6 JR |
7321 | + && (inode->i_state & I_LINKABLE)) |
7322 | + err = 0; | |
7323 | + return err; | |
7324 | +} | |
7325 | + | |
027c5e7a AM |
7326 | +static inline int au_d_alive(struct dentry *d) |
7327 | +{ | |
7328 | + int err; | |
7329 | + struct inode *inode; | |
076b876e | 7330 | + |
027c5e7a AM |
7331 | + err = 0; |
7332 | + if (!IS_ROOT(d)) | |
7333 | + err = au_d_hashed_positive(d); | |
7334 | + else { | |
5527c038 JR |
7335 | + inode = d_inode(d); |
7336 | + if (unlikely(d_unlinked(d) | |
7337 | + || d_is_negative(d) | |
7338 | + || !inode->i_nlink)) | |
027c5e7a AM |
7339 | + err = -ENOENT; |
7340 | + } | |
7341 | + return err; | |
7342 | +} | |
7343 | + | |
7344 | +static inline int au_alive_dir(struct dentry *d) | |
7f207e10 | 7345 | +{ |
027c5e7a | 7346 | + int err; |
076b876e | 7347 | + |
027c5e7a | 7348 | + err = au_d_alive(d); |
5527c038 | 7349 | + if (unlikely(err || IS_DEADDIR(d_inode(d)))) |
027c5e7a AM |
7350 | + err = -ENOENT; |
7351 | + return err; | |
7f207e10 AM |
7352 | +} |
7353 | + | |
38d290e6 JR |
7354 | +static inline int au_qstreq(struct qstr *a, struct qstr *b) |
7355 | +{ | |
7356 | + return a->len == b->len | |
7357 | + && !memcmp(a->name, b->name, a->len); | |
7358 | +} | |
7359 | + | |
7e9cd9fe AM |
7360 | +/* |
7361 | + * by the commit | |
7362 | + * 360f547 2015-01-25 dcache: let the dentry count go down to zero without | |
7363 | + * taking d_lock | |
7364 | + * the type of d_lockref.count became int, but the inlined function d_count() | |
7365 | + * still returns unsigned int. | |
7366 | + * I don't know why. Maybe it is for every d_count() users? | |
7367 | + * Anyway au_dcount() lives on. | |
7368 | + */ | |
c1595e42 JR |
7369 | +static inline int au_dcount(struct dentry *d) |
7370 | +{ | |
7371 | + return (int)d_count(d); | |
7372 | +} | |
7373 | + | |
1facf9fc | 7374 | +#endif /* __KERNEL__ */ |
7375 | +#endif /* __AUFS_DCSUB_H__ */ | |
7f207e10 | 7376 | diff -urN /usr/share/empty/fs/aufs/debug.c linux/fs/aufs/debug.c |
eca34b5c | 7377 | --- /usr/share/empty/fs/aufs/debug.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 7378 | +++ linux/fs/aufs/debug.c 2020-01-27 10:57:18.168871450 +0100 |
eca801bf | 7379 | @@ -0,0 +1,441 @@ |
cd7a4cd9 | 7380 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 7381 | +/* |
d58c55f2 | 7382 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 7383 | + * |
7384 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7385 | + * it under the terms of the GNU General Public License as published by | |
7386 | + * the Free Software Foundation; either version 2 of the License, or | |
7387 | + * (at your option) any later version. | |
dece6358 AM |
7388 | + * |
7389 | + * This program is distributed in the hope that it will be useful, | |
7390 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7391 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7392 | + * GNU General Public License for more details. | |
7393 | + * | |
7394 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7395 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7396 | + */ |
7397 | + | |
7398 | +/* | |
7399 | + * debug print functions | |
7400 | + */ | |
7401 | + | |
eca801bf | 7402 | +#include <linux/iversion.h> |
1facf9fc | 7403 | +#include "aufs.h" |
7404 | + | |
392086de AM |
7405 | +/* Returns 0, or -errno. arg is in kp->arg. */ |
7406 | +static int param_atomic_t_set(const char *val, const struct kernel_param *kp) | |
7407 | +{ | |
7408 | + int err, n; | |
7409 | + | |
7410 | + err = kstrtoint(val, 0, &n); | |
7411 | + if (!err) { | |
7412 | + if (n > 0) | |
7413 | + au_debug_on(); | |
7414 | + else | |
7415 | + au_debug_off(); | |
7416 | + } | |
7417 | + return err; | |
7418 | +} | |
7419 | + | |
7420 | +/* Returns length written or -errno. Buffer is 4k (ie. be short!) */ | |
7421 | +static int param_atomic_t_get(char *buffer, const struct kernel_param *kp) | |
7422 | +{ | |
7423 | + atomic_t *a; | |
7424 | + | |
7425 | + a = kp->arg; | |
7426 | + return sprintf(buffer, "%d", atomic_read(a)); | |
7427 | +} | |
7428 | + | |
7429 | +static struct kernel_param_ops param_ops_atomic_t = { | |
7430 | + .set = param_atomic_t_set, | |
7431 | + .get = param_atomic_t_get | |
7432 | + /* void (*free)(void *arg) */ | |
7433 | +}; | |
7434 | + | |
7435 | +atomic_t aufs_debug = ATOMIC_INIT(0); | |
1facf9fc | 7436 | +MODULE_PARM_DESC(debug, "debug print"); |
cd7a4cd9 | 7437 | +module_param_named(debug, aufs_debug, atomic_t, 0664); |
1facf9fc | 7438 | + |
c1595e42 | 7439 | +DEFINE_MUTEX(au_dbg_mtx); /* just to serialize the dbg msgs */ |
1facf9fc | 7440 | +char *au_plevel = KERN_DEBUG; |
e49829fe JR |
7441 | +#define dpri(fmt, ...) do { \ |
7442 | + if ((au_plevel \ | |
7443 | + && strcmp(au_plevel, KERN_DEBUG)) \ | |
7444 | + || au_debug_test()) \ | |
7445 | + printk("%s" fmt, au_plevel, ##__VA_ARGS__); \ | |
1facf9fc | 7446 | +} while (0) |
7447 | + | |
7448 | +/* ---------------------------------------------------------------------- */ | |
7449 | + | |
7450 | +void au_dpri_whlist(struct au_nhash *whlist) | |
7451 | +{ | |
7452 | + unsigned long ul, n; | |
7453 | + struct hlist_head *head; | |
c06a8ce3 | 7454 | + struct au_vdir_wh *pos; |
1facf9fc | 7455 | + |
7456 | + n = whlist->nh_num; | |
7457 | + head = whlist->nh_head; | |
7458 | + for (ul = 0; ul < n; ul++) { | |
c06a8ce3 | 7459 | + hlist_for_each_entry(pos, head, wh_hash) |
1facf9fc | 7460 | + dpri("b%d, %.*s, %d\n", |
c06a8ce3 AM |
7461 | + pos->wh_bindex, |
7462 | + pos->wh_str.len, pos->wh_str.name, | |
7463 | + pos->wh_str.len); | |
1facf9fc | 7464 | + head++; |
7465 | + } | |
7466 | +} | |
7467 | + | |
7468 | +void au_dpri_vdir(struct au_vdir *vdir) | |
7469 | +{ | |
7470 | + unsigned long ul; | |
7471 | + union au_vdir_deblk_p p; | |
7472 | + unsigned char *o; | |
7473 | + | |
7474 | + if (!vdir || IS_ERR(vdir)) { | |
7475 | + dpri("err %ld\n", PTR_ERR(vdir)); | |
7476 | + return; | |
7477 | + } | |
7478 | + | |
be118d29 | 7479 | + dpri("deblk %u, nblk %lu, deblk %p, last{%lu, %p}, ver %llu\n", |
1facf9fc | 7480 | + vdir->vd_deblk_sz, vdir->vd_nblk, vdir->vd_deblk, |
7481 | + vdir->vd_last.ul, vdir->vd_last.p.deblk, vdir->vd_version); | |
7482 | + for (ul = 0; ul < vdir->vd_nblk; ul++) { | |
7483 | + p.deblk = vdir->vd_deblk[ul]; | |
7484 | + o = p.deblk; | |
7485 | + dpri("[%lu]: %p\n", ul, o); | |
7486 | + } | |
7487 | +} | |
7488 | + | |
53392da6 | 7489 | +static int do_pri_inode(aufs_bindex_t bindex, struct inode *inode, int hn, |
1facf9fc | 7490 | + struct dentry *wh) |
7491 | +{ | |
7492 | + char *n = NULL; | |
7493 | + int l = 0; | |
7494 | + | |
7495 | + if (!inode || IS_ERR(inode)) { | |
7496 | + dpri("i%d: err %ld\n", bindex, PTR_ERR(inode)); | |
7497 | + return -1; | |
7498 | + } | |
7499 | + | |
c2b27bf2 | 7500 | + /* the type of i_blocks depends upon CONFIG_LBDAF */ |
1facf9fc | 7501 | + BUILD_BUG_ON(sizeof(inode->i_blocks) != sizeof(unsigned long) |
7502 | + && sizeof(inode->i_blocks) != sizeof(u64)); | |
7503 | + if (wh) { | |
7504 | + n = (void *)wh->d_name.name; | |
7505 | + l = wh->d_name.len; | |
7506 | + } | |
7507 | + | |
53392da6 AM |
7508 | + dpri("i%d: %p, i%lu, %s, cnt %d, nl %u, 0%o, sz %llu, blk %llu," |
7509 | + " hn %d, ct %lld, np %lu, st 0x%lx, f 0x%x, v %llu, g %x%s%.*s\n", | |
7510 | + bindex, inode, | |
1facf9fc | 7511 | + inode->i_ino, inode->i_sb ? au_sbtype(inode->i_sb) : "??", |
7512 | + atomic_read(&inode->i_count), inode->i_nlink, inode->i_mode, | |
7513 | + i_size_read(inode), (unsigned long long)inode->i_blocks, | |
cd7a4cd9 | 7514 | + hn, (long long)timespec64_to_ns(&inode->i_ctime) & 0x0ffff, |
1facf9fc | 7515 | + inode->i_mapping ? inode->i_mapping->nrpages : 0, |
be118d29 | 7516 | + inode->i_state, inode->i_flags, inode_peek_iversion(inode), |
b752ccd1 | 7517 | + inode->i_generation, |
1facf9fc | 7518 | + l ? ", wh " : "", l, n); |
7519 | + return 0; | |
7520 | +} | |
7521 | + | |
7522 | +void au_dpri_inode(struct inode *inode) | |
7523 | +{ | |
7524 | + struct au_iinfo *iinfo; | |
5afbbe0d | 7525 | + struct au_hinode *hi; |
1facf9fc | 7526 | + aufs_bindex_t bindex; |
53392da6 | 7527 | + int err, hn; |
1facf9fc | 7528 | + |
53392da6 | 7529 | + err = do_pri_inode(-1, inode, -1, NULL); |
5afbbe0d | 7530 | + if (err || !au_test_aufs(inode->i_sb) || au_is_bad_inode(inode)) |
1facf9fc | 7531 | + return; |
7532 | + | |
7533 | + iinfo = au_ii(inode); | |
5afbbe0d AM |
7534 | + dpri("i-1: btop %d, bbot %d, gen %d\n", |
7535 | + iinfo->ii_btop, iinfo->ii_bbot, au_iigen(inode, NULL)); | |
7536 | + if (iinfo->ii_btop < 0) | |
1facf9fc | 7537 | + return; |
53392da6 | 7538 | + hn = 0; |
5afbbe0d AM |
7539 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; bindex++) { |
7540 | + hi = au_hinode(iinfo, bindex); | |
7541 | + hn = !!au_hn(hi); | |
7542 | + do_pri_inode(bindex, hi->hi_inode, hn, hi->hi_whdentry); | |
53392da6 | 7543 | + } |
1facf9fc | 7544 | +} |
7545 | + | |
2cbb1c4b JR |
7546 | +void au_dpri_dalias(struct inode *inode) |
7547 | +{ | |
7548 | + struct dentry *d; | |
7549 | + | |
7550 | + spin_lock(&inode->i_lock); | |
c1595e42 | 7551 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) |
2cbb1c4b JR |
7552 | + au_dpri_dentry(d); |
7553 | + spin_unlock(&inode->i_lock); | |
7554 | +} | |
7555 | + | |
1facf9fc | 7556 | +static int do_pri_dentry(aufs_bindex_t bindex, struct dentry *dentry) |
7557 | +{ | |
7558 | + struct dentry *wh = NULL; | |
53392da6 | 7559 | + int hn; |
5afbbe0d | 7560 | + struct inode *inode; |
076b876e | 7561 | + struct au_iinfo *iinfo; |
5afbbe0d | 7562 | + struct au_hinode *hi; |
1facf9fc | 7563 | + |
7564 | + if (!dentry || IS_ERR(dentry)) { | |
7565 | + dpri("d%d: err %ld\n", bindex, PTR_ERR(dentry)); | |
7566 | + return -1; | |
7567 | + } | |
7568 | + /* do not call dget_parent() here */ | |
027c5e7a | 7569 | + /* note: access d_xxx without d_lock */ |
523b37e3 AM |
7570 | + dpri("d%d: %p, %pd2?, %s, cnt %d, flags 0x%x, %shashed\n", |
7571 | + bindex, dentry, dentry, | |
1facf9fc | 7572 | + dentry->d_sb ? au_sbtype(dentry->d_sb) : "??", |
c1595e42 | 7573 | + au_dcount(dentry), dentry->d_flags, |
523b37e3 | 7574 | + d_unhashed(dentry) ? "un" : ""); |
53392da6 | 7575 | + hn = -1; |
5afbbe0d AM |
7576 | + inode = NULL; |
7577 | + if (d_is_positive(dentry)) | |
7578 | + inode = d_inode(dentry); | |
7579 | + if (inode | |
7580 | + && au_test_aufs(dentry->d_sb) | |
7581 | + && bindex >= 0 | |
7582 | + && !au_is_bad_inode(inode)) { | |
7583 | + iinfo = au_ii(inode); | |
7584 | + hi = au_hinode(iinfo, bindex); | |
7585 | + hn = !!au_hn(hi); | |
7586 | + wh = hi->hi_whdentry; | |
7587 | + } | |
7588 | + do_pri_inode(bindex, inode, hn, wh); | |
1facf9fc | 7589 | + return 0; |
7590 | +} | |
7591 | + | |
7592 | +void au_dpri_dentry(struct dentry *dentry) | |
7593 | +{ | |
7594 | + struct au_dinfo *dinfo; | |
7595 | + aufs_bindex_t bindex; | |
7596 | + int err; | |
7597 | + | |
7598 | + err = do_pri_dentry(-1, dentry); | |
7599 | + if (err || !au_test_aufs(dentry->d_sb)) | |
7600 | + return; | |
7601 | + | |
7602 | + dinfo = au_di(dentry); | |
7603 | + if (!dinfo) | |
7604 | + return; | |
5afbbe0d AM |
7605 | + dpri("d-1: btop %d, bbot %d, bwh %d, bdiropq %d, gen %d, tmp %d\n", |
7606 | + dinfo->di_btop, dinfo->di_bbot, | |
38d290e6 JR |
7607 | + dinfo->di_bwh, dinfo->di_bdiropq, au_digen(dentry), |
7608 | + dinfo->di_tmpfile); | |
5afbbe0d | 7609 | + if (dinfo->di_btop < 0) |
1facf9fc | 7610 | + return; |
5afbbe0d AM |
7611 | + for (bindex = dinfo->di_btop; bindex <= dinfo->di_bbot; bindex++) |
7612 | + do_pri_dentry(bindex, au_hdentry(dinfo, bindex)->hd_dentry); | |
1facf9fc | 7613 | +} |
7614 | + | |
7615 | +static int do_pri_file(aufs_bindex_t bindex, struct file *file) | |
7616 | +{ | |
7617 | + char a[32]; | |
7618 | + | |
7619 | + if (!file || IS_ERR(file)) { | |
7620 | + dpri("f%d: err %ld\n", bindex, PTR_ERR(file)); | |
7621 | + return -1; | |
7622 | + } | |
7623 | + a[0] = 0; | |
7624 | + if (bindex < 0 | |
b912730e | 7625 | + && !IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7626 | + && au_test_aufs(file->f_path.dentry->d_sb) |
1facf9fc | 7627 | + && au_fi(file)) |
e49829fe | 7628 | + snprintf(a, sizeof(a), ", gen %d, mmapped %d", |
2cbb1c4b | 7629 | + au_figen(file), atomic_read(&au_fi(file)->fi_mmapped)); |
b752ccd1 | 7630 | + dpri("f%d: mode 0x%x, flags 0%o, cnt %ld, v %llu, pos %llu%s\n", |
1facf9fc | 7631 | + bindex, file->f_mode, file->f_flags, (long)file_count(file), |
b752ccd1 | 7632 | + file->f_version, file->f_pos, a); |
b912730e | 7633 | + if (!IS_ERR_OR_NULL(file->f_path.dentry)) |
2000de60 | 7634 | + do_pri_dentry(bindex, file->f_path.dentry); |
1facf9fc | 7635 | + return 0; |
7636 | +} | |
7637 | + | |
7638 | +void au_dpri_file(struct file *file) | |
7639 | +{ | |
7640 | + struct au_finfo *finfo; | |
4a4d8108 AM |
7641 | + struct au_fidir *fidir; |
7642 | + struct au_hfile *hfile; | |
1facf9fc | 7643 | + aufs_bindex_t bindex; |
7644 | + int err; | |
7645 | + | |
7646 | + err = do_pri_file(-1, file); | |
2000de60 | 7647 | + if (err |
b912730e | 7648 | + || IS_ERR_OR_NULL(file->f_path.dentry) |
2000de60 | 7649 | + || !au_test_aufs(file->f_path.dentry->d_sb)) |
1facf9fc | 7650 | + return; |
7651 | + | |
7652 | + finfo = au_fi(file); | |
7653 | + if (!finfo) | |
7654 | + return; | |
4a4d8108 | 7655 | + if (finfo->fi_btop < 0) |
1facf9fc | 7656 | + return; |
4a4d8108 AM |
7657 | + fidir = finfo->fi_hdir; |
7658 | + if (!fidir) | |
7659 | + do_pri_file(finfo->fi_btop, finfo->fi_htop.hf_file); | |
7660 | + else | |
e49829fe JR |
7661 | + for (bindex = finfo->fi_btop; |
7662 | + bindex >= 0 && bindex <= fidir->fd_bbot; | |
4a4d8108 AM |
7663 | + bindex++) { |
7664 | + hfile = fidir->fd_hfile + bindex; | |
7665 | + do_pri_file(bindex, hfile ? hfile->hf_file : NULL); | |
7666 | + } | |
1facf9fc | 7667 | +} |
7668 | + | |
7669 | +static int do_pri_br(aufs_bindex_t bindex, struct au_branch *br) | |
7670 | +{ | |
7671 | + struct vfsmount *mnt; | |
7672 | + struct super_block *sb; | |
7673 | + | |
7674 | + if (!br || IS_ERR(br)) | |
7675 | + goto out; | |
86dc4139 | 7676 | + mnt = au_br_mnt(br); |
1facf9fc | 7677 | + if (!mnt || IS_ERR(mnt)) |
7678 | + goto out; | |
7679 | + sb = mnt->mnt_sb; | |
7680 | + if (!sb || IS_ERR(sb)) | |
7681 | + goto out; | |
7682 | + | |
acd2b654 | 7683 | + dpri("s%d: {perm 0x%x, id %d, wbr %p}, " |
b752ccd1 | 7684 | + "%s, dev 0x%02x%02x, flags 0x%lx, cnt %d, active %d, " |
1facf9fc | 7685 | + "xino %d\n", |
acd2b654 AM |
7686 | + bindex, br->br_perm, br->br_id, br->br_wbr, |
7687 | + au_sbtype(sb), MAJOR(sb->s_dev), MINOR(sb->s_dev), | |
b752ccd1 | 7688 | + sb->s_flags, sb->s_count, |
acd2b654 AM |
7689 | + atomic_read(&sb->s_active), |
7690 | + !!au_xino_file(br->br_xino, /*idx*/-1)); | |
1facf9fc | 7691 | + return 0; |
7692 | + | |
4f0767ce | 7693 | +out: |
1facf9fc | 7694 | + dpri("s%d: err %ld\n", bindex, PTR_ERR(br)); |
7695 | + return -1; | |
7696 | +} | |
7697 | + | |
7698 | +void au_dpri_sb(struct super_block *sb) | |
7699 | +{ | |
7700 | + struct au_sbinfo *sbinfo; | |
7701 | + aufs_bindex_t bindex; | |
7702 | + int err; | |
acd2b654 | 7703 | + /* to reduce stack size */ |
1facf9fc | 7704 | + struct { |
7705 | + struct vfsmount mnt; | |
7706 | + struct au_branch fake; | |
7707 | + } *a; | |
7708 | + | |
7709 | + /* this function can be called from magic sysrq */ | |
7710 | + a = kzalloc(sizeof(*a), GFP_ATOMIC); | |
7711 | + if (unlikely(!a)) { | |
7712 | + dpri("no memory\n"); | |
7713 | + return; | |
7714 | + } | |
7715 | + | |
7716 | + a->mnt.mnt_sb = sb; | |
86dc4139 | 7717 | + a->fake.br_path.mnt = &a->mnt; |
1facf9fc | 7718 | + err = do_pri_br(-1, &a->fake); |
9f237c51 | 7719 | + au_kfree_rcu(a); |
1facf9fc | 7720 | + dpri("dev 0x%x\n", sb->s_dev); |
7721 | + if (err || !au_test_aufs(sb)) | |
7722 | + return; | |
7723 | + | |
7724 | + sbinfo = au_sbi(sb); | |
7725 | + if (!sbinfo) | |
7726 | + return; | |
f0c0a007 AM |
7727 | + dpri("nw %d, gen %u, kobj %d\n", |
7728 | + atomic_read(&sbinfo->si_nowait.nw_len), sbinfo->si_generation, | |
521ced18 | 7729 | + kref_read(&sbinfo->si_kobj.kref)); |
5afbbe0d | 7730 | + for (bindex = 0; bindex <= sbinfo->si_bbot; bindex++) |
1facf9fc | 7731 | + do_pri_br(bindex, sbinfo->si_branch[0 + bindex]); |
7732 | +} | |
7733 | + | |
7734 | +/* ---------------------------------------------------------------------- */ | |
7735 | + | |
027c5e7a AM |
7736 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line) |
7737 | +{ | |
5527c038 | 7738 | + struct inode *h_inode, *inode = d_inode(dentry); |
027c5e7a | 7739 | + struct dentry *h_dentry; |
5afbbe0d | 7740 | + aufs_bindex_t bindex, bbot, bi; |
027c5e7a AM |
7741 | + |
7742 | + if (!inode /* || au_di(dentry)->di_lsc == AuLsc_DI_TMP */) | |
7743 | + return; | |
7744 | + | |
5afbbe0d AM |
7745 | + bbot = au_dbbot(dentry); |
7746 | + bi = au_ibbot(inode); | |
7747 | + if (bi < bbot) | |
7748 | + bbot = bi; | |
7749 | + bindex = au_dbtop(dentry); | |
7750 | + bi = au_ibtop(inode); | |
027c5e7a AM |
7751 | + if (bi > bindex) |
7752 | + bindex = bi; | |
7753 | + | |
5afbbe0d | 7754 | + for (; bindex <= bbot; bindex++) { |
027c5e7a AM |
7755 | + h_dentry = au_h_dptr(dentry, bindex); |
7756 | + if (!h_dentry) | |
7757 | + continue; | |
7758 | + h_inode = au_h_iptr(inode, bindex); | |
5527c038 | 7759 | + if (unlikely(h_inode != d_inode(h_dentry))) { |
392086de | 7760 | + au_debug_on(); |
027c5e7a AM |
7761 | + AuDbg("b%d, %s:%d\n", bindex, func, line); |
7762 | + AuDbgDentry(dentry); | |
7763 | + AuDbgInode(inode); | |
392086de | 7764 | + au_debug_off(); |
027c5e7a AM |
7765 | + BUG(); |
7766 | + } | |
7767 | + } | |
7768 | +} | |
7769 | + | |
1facf9fc | 7770 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen) |
7771 | +{ | |
7772 | + int err, i, j; | |
7773 | + struct au_dcsub_pages dpages; | |
7774 | + struct au_dpage *dpage; | |
7775 | + struct dentry **dentries; | |
7776 | + | |
7777 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
7778 | + AuDebugOn(err); | |
027c5e7a | 7779 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/1); |
1facf9fc | 7780 | + AuDebugOn(err); |
7781 | + for (i = dpages.ndpage - 1; !err && i >= 0; i--) { | |
7782 | + dpage = dpages.dpages + i; | |
7783 | + dentries = dpage->dentries; | |
7784 | + for (j = dpage->ndentry - 1; !err && j >= 0; j--) | |
027c5e7a | 7785 | + AuDebugOn(au_digen_test(dentries[j], sigen)); |
1facf9fc | 7786 | + } |
7787 | + au_dpages_free(&dpages); | |
7788 | +} | |
7789 | + | |
1facf9fc | 7790 | +void au_dbg_verify_kthread(void) |
7791 | +{ | |
53392da6 | 7792 | + if (au_wkq_test()) { |
1facf9fc | 7793 | + au_dbg_blocked(); |
1e00d052 AM |
7794 | + /* |
7795 | + * It may be recursive, but udba=notify between two aufs mounts, | |
7796 | + * where a single ro branch is shared, is not a problem. | |
7797 | + */ | |
7798 | + /* WARN_ON(1); */ | |
1facf9fc | 7799 | + } |
7800 | +} | |
7801 | + | |
7802 | +/* ---------------------------------------------------------------------- */ | |
7803 | + | |
1facf9fc | 7804 | +int __init au_debug_init(void) |
7805 | +{ | |
7806 | + aufs_bindex_t bindex; | |
7807 | + struct au_vdir_destr destr; | |
7808 | + | |
7809 | + bindex = -1; | |
7810 | + AuDebugOn(bindex >= 0); | |
7811 | + | |
7812 | + destr.len = -1; | |
7813 | + AuDebugOn(destr.len < NAME_MAX); | |
7814 | + | |
7815 | +#ifdef CONFIG_4KSTACKS | |
0c3ec466 | 7816 | + pr_warn("CONFIG_4KSTACKS is defined.\n"); |
1facf9fc | 7817 | +#endif |
7818 | + | |
1facf9fc | 7819 | + return 0; |
7820 | +} | |
7f207e10 | 7821 | diff -urN /usr/share/empty/fs/aufs/debug.h linux/fs/aufs/debug.h |
eca34b5c | 7822 | --- /usr/share/empty/fs/aufs/debug.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 7823 | +++ linux/fs/aufs/debug.h 2020-01-27 10:57:18.168871450 +0100 |
062440b3 AM |
7824 | @@ -0,0 +1,226 @@ |
7825 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 7826 | +/* |
d58c55f2 | 7827 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 7828 | + * |
7829 | + * This program, aufs is free software; you can redistribute it and/or modify | |
7830 | + * it under the terms of the GNU General Public License as published by | |
7831 | + * the Free Software Foundation; either version 2 of the License, or | |
7832 | + * (at your option) any later version. | |
dece6358 AM |
7833 | + * |
7834 | + * This program is distributed in the hope that it will be useful, | |
7835 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
7836 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
7837 | + * GNU General Public License for more details. | |
7838 | + * | |
7839 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 7840 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 7841 | + */ |
7842 | + | |
7843 | +/* | |
7844 | + * debug print functions | |
7845 | + */ | |
7846 | + | |
7847 | +#ifndef __AUFS_DEBUG_H__ | |
7848 | +#define __AUFS_DEBUG_H__ | |
7849 | + | |
7850 | +#ifdef __KERNEL__ | |
7851 | + | |
392086de | 7852 | +#include <linux/atomic.h> |
4a4d8108 AM |
7853 | +#include <linux/module.h> |
7854 | +#include <linux/kallsyms.h> | |
1facf9fc | 7855 | +#include <linux/sysrq.h> |
4a4d8108 | 7856 | + |
1facf9fc | 7857 | +#ifdef CONFIG_AUFS_DEBUG |
7858 | +#define AuDebugOn(a) BUG_ON(a) | |
7859 | + | |
7860 | +/* module parameter */ | |
392086de AM |
7861 | +extern atomic_t aufs_debug; |
7862 | +static inline void au_debug_on(void) | |
1facf9fc | 7863 | +{ |
392086de AM |
7864 | + atomic_inc(&aufs_debug); |
7865 | +} | |
7866 | +static inline void au_debug_off(void) | |
7867 | +{ | |
7868 | + atomic_dec_if_positive(&aufs_debug); | |
1facf9fc | 7869 | +} |
7870 | + | |
7871 | +static inline int au_debug_test(void) | |
7872 | +{ | |
392086de | 7873 | + return atomic_read(&aufs_debug) > 0; |
1facf9fc | 7874 | +} |
7875 | +#else | |
7876 | +#define AuDebugOn(a) do {} while (0) | |
392086de AM |
7877 | +AuStubVoid(au_debug_on, void) |
7878 | +AuStubVoid(au_debug_off, void) | |
4a4d8108 | 7879 | +AuStubInt0(au_debug_test, void) |
1facf9fc | 7880 | +#endif /* CONFIG_AUFS_DEBUG */ |
7881 | + | |
392086de AM |
7882 | +#define param_check_atomic_t(name, p) __param_check(name, p, atomic_t) |
7883 | + | |
1facf9fc | 7884 | +/* ---------------------------------------------------------------------- */ |
7885 | + | |
7886 | +/* debug print */ | |
7887 | + | |
4a4d8108 | 7888 | +#define AuDbg(fmt, ...) do { \ |
1facf9fc | 7889 | + if (au_debug_test()) \ |
4a4d8108 | 7890 | + pr_debug("DEBUG: " fmt, ##__VA_ARGS__); \ |
1facf9fc | 7891 | +} while (0) |
4a4d8108 AM |
7892 | +#define AuLabel(l) AuDbg(#l "\n") |
7893 | +#define AuIOErr(fmt, ...) pr_err("I/O Error, " fmt, ##__VA_ARGS__) | |
7894 | +#define AuWarn1(fmt, ...) do { \ | |
1facf9fc | 7895 | + static unsigned char _c; \ |
7896 | + if (!_c++) \ | |
0c3ec466 | 7897 | + pr_warn(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7898 | +} while (0) |
7899 | + | |
4a4d8108 | 7900 | +#define AuErr1(fmt, ...) do { \ |
1facf9fc | 7901 | + static unsigned char _c; \ |
7902 | + if (!_c++) \ | |
4a4d8108 | 7903 | + pr_err(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7904 | +} while (0) |
7905 | + | |
4a4d8108 | 7906 | +#define AuIOErr1(fmt, ...) do { \ |
1facf9fc | 7907 | + static unsigned char _c; \ |
7908 | + if (!_c++) \ | |
4a4d8108 | 7909 | + AuIOErr(fmt, ##__VA_ARGS__); \ |
1facf9fc | 7910 | +} while (0) |
7911 | + | |
7912 | +#define AuUnsupportMsg "This operation is not supported." \ | |
7913 | + " Please report this application to aufs-users ML." | |
4a4d8108 AM |
7914 | +#define AuUnsupport(fmt, ...) do { \ |
7915 | + pr_err(AuUnsupportMsg "\n" fmt, ##__VA_ARGS__); \ | |
1facf9fc | 7916 | + dump_stack(); \ |
7917 | +} while (0) | |
7918 | + | |
7919 | +#define AuTraceErr(e) do { \ | |
7920 | + if (unlikely((e) < 0)) \ | |
7921 | + AuDbg("err %d\n", (int)(e)); \ | |
7922 | +} while (0) | |
7923 | + | |
7924 | +#define AuTraceErrPtr(p) do { \ | |
7925 | + if (IS_ERR(p)) \ | |
7926 | + AuDbg("err %ld\n", PTR_ERR(p)); \ | |
7927 | +} while (0) | |
7928 | + | |
7929 | +/* dirty macros for debug print, use with "%.*s" and caution */ | |
7930 | +#define AuLNPair(qstr) (qstr)->len, (qstr)->name | |
1facf9fc | 7931 | + |
7932 | +/* ---------------------------------------------------------------------- */ | |
7933 | + | |
dece6358 | 7934 | +struct dentry; |
1facf9fc | 7935 | +#ifdef CONFIG_AUFS_DEBUG |
c1595e42 | 7936 | +extern struct mutex au_dbg_mtx; |
1facf9fc | 7937 | +extern char *au_plevel; |
7938 | +struct au_nhash; | |
7939 | +void au_dpri_whlist(struct au_nhash *whlist); | |
7940 | +struct au_vdir; | |
7941 | +void au_dpri_vdir(struct au_vdir *vdir); | |
dece6358 | 7942 | +struct inode; |
1facf9fc | 7943 | +void au_dpri_inode(struct inode *inode); |
2cbb1c4b | 7944 | +void au_dpri_dalias(struct inode *inode); |
1facf9fc | 7945 | +void au_dpri_dentry(struct dentry *dentry); |
dece6358 | 7946 | +struct file; |
1facf9fc | 7947 | +void au_dpri_file(struct file *filp); |
dece6358 | 7948 | +struct super_block; |
1facf9fc | 7949 | +void au_dpri_sb(struct super_block *sb); |
7950 | + | |
027c5e7a AM |
7951 | +#define au_dbg_verify_dinode(d) __au_dbg_verify_dinode(d, __func__, __LINE__) |
7952 | +void __au_dbg_verify_dinode(struct dentry *dentry, const char *func, int line); | |
1facf9fc | 7953 | +void au_dbg_verify_gen(struct dentry *parent, unsigned int sigen); |
1facf9fc | 7954 | +void au_dbg_verify_kthread(void); |
7955 | + | |
7956 | +int __init au_debug_init(void); | |
7e9cd9fe | 7957 | + |
1facf9fc | 7958 | +#define AuDbgWhlist(w) do { \ |
c1595e42 | 7959 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7960 | + AuDbg(#w "\n"); \ |
7961 | + au_dpri_whlist(w); \ | |
c1595e42 | 7962 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7963 | +} while (0) |
7964 | + | |
7965 | +#define AuDbgVdir(v) do { \ | |
c1595e42 | 7966 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7967 | + AuDbg(#v "\n"); \ |
7968 | + au_dpri_vdir(v); \ | |
c1595e42 | 7969 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7970 | +} while (0) |
7971 | + | |
7972 | +#define AuDbgInode(i) do { \ | |
c1595e42 | 7973 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7974 | + AuDbg(#i "\n"); \ |
7975 | + au_dpri_inode(i); \ | |
c1595e42 | 7976 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7977 | +} while (0) |
7978 | + | |
2cbb1c4b | 7979 | +#define AuDbgDAlias(i) do { \ |
c1595e42 | 7980 | + mutex_lock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7981 | + AuDbg(#i "\n"); \ |
7982 | + au_dpri_dalias(i); \ | |
c1595e42 | 7983 | + mutex_unlock(&au_dbg_mtx); \ |
2cbb1c4b JR |
7984 | +} while (0) |
7985 | + | |
1facf9fc | 7986 | +#define AuDbgDentry(d) do { \ |
c1595e42 | 7987 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7988 | + AuDbg(#d "\n"); \ |
7989 | + au_dpri_dentry(d); \ | |
c1595e42 | 7990 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7991 | +} while (0) |
7992 | + | |
7993 | +#define AuDbgFile(f) do { \ | |
c1595e42 | 7994 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 7995 | + AuDbg(#f "\n"); \ |
7996 | + au_dpri_file(f); \ | |
c1595e42 | 7997 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 7998 | +} while (0) |
7999 | + | |
8000 | +#define AuDbgSb(sb) do { \ | |
c1595e42 | 8001 | + mutex_lock(&au_dbg_mtx); \ |
1facf9fc | 8002 | + AuDbg(#sb "\n"); \ |
8003 | + au_dpri_sb(sb); \ | |
c1595e42 | 8004 | + mutex_unlock(&au_dbg_mtx); \ |
1facf9fc | 8005 | +} while (0) |
8006 | + | |
4a4d8108 AM |
8007 | +#define AuDbgSym(addr) do { \ |
8008 | + char sym[KSYM_SYMBOL_LEN]; \ | |
8009 | + sprint_symbol(sym, (unsigned long)addr); \ | |
8010 | + AuDbg("%s\n", sym); \ | |
8011 | +} while (0) | |
1facf9fc | 8012 | +#else |
027c5e7a | 8013 | +AuStubVoid(au_dbg_verify_dinode, struct dentry *dentry) |
4a4d8108 AM |
8014 | +AuStubVoid(au_dbg_verify_gen, struct dentry *parent, unsigned int sigen) |
8015 | +AuStubVoid(au_dbg_verify_kthread, void) | |
8016 | +AuStubInt0(__init au_debug_init, void) | |
1facf9fc | 8017 | + |
1facf9fc | 8018 | +#define AuDbgWhlist(w) do {} while (0) |
8019 | +#define AuDbgVdir(v) do {} while (0) | |
8020 | +#define AuDbgInode(i) do {} while (0) | |
2cbb1c4b | 8021 | +#define AuDbgDAlias(i) do {} while (0) |
1facf9fc | 8022 | +#define AuDbgDentry(d) do {} while (0) |
8023 | +#define AuDbgFile(f) do {} while (0) | |
8024 | +#define AuDbgSb(sb) do {} while (0) | |
4a4d8108 | 8025 | +#define AuDbgSym(addr) do {} while (0) |
1facf9fc | 8026 | +#endif /* CONFIG_AUFS_DEBUG */ |
8027 | + | |
8028 | +/* ---------------------------------------------------------------------- */ | |
8029 | + | |
8030 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
8031 | +int __init au_sysrq_init(void); | |
8032 | +void au_sysrq_fin(void); | |
8033 | + | |
8034 | +#ifdef CONFIG_HW_CONSOLE | |
8035 | +#define au_dbg_blocked() do { \ | |
8036 | + WARN_ON(1); \ | |
0c5527e5 | 8037 | + handle_sysrq('w'); \ |
1facf9fc | 8038 | +} while (0) |
8039 | +#else | |
4a4d8108 | 8040 | +AuStubVoid(au_dbg_blocked, void) |
1facf9fc | 8041 | +#endif |
8042 | + | |
8043 | +#else | |
4a4d8108 AM |
8044 | +AuStubInt0(__init au_sysrq_init, void) |
8045 | +AuStubVoid(au_sysrq_fin, void) | |
8046 | +AuStubVoid(au_dbg_blocked, void) | |
1facf9fc | 8047 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ |
8048 | + | |
8049 | +#endif /* __KERNEL__ */ | |
8050 | +#endif /* __AUFS_DEBUG_H__ */ | |
7f207e10 | 8051 | diff -urN /usr/share/empty/fs/aufs/dentry.c linux/fs/aufs/dentry.c |
eca34b5c | 8052 | --- /usr/share/empty/fs/aufs/dentry.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 8053 | +++ linux/fs/aufs/dentry.c 2020-01-27 10:57:18.168871450 +0100 |
eca801bf | 8054 | @@ -0,0 +1,1154 @@ |
cd7a4cd9 | 8055 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 8056 | +/* |
d58c55f2 | 8057 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 8058 | + * |
8059 | + * This program, aufs is free software; you can redistribute it and/or modify | |
8060 | + * it under the terms of the GNU General Public License as published by | |
8061 | + * the Free Software Foundation; either version 2 of the License, or | |
8062 | + * (at your option) any later version. | |
dece6358 AM |
8063 | + * |
8064 | + * This program is distributed in the hope that it will be useful, | |
8065 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
8066 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
8067 | + * GNU General Public License for more details. | |
8068 | + * | |
8069 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 8070 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 8071 | + */ |
8072 | + | |
8073 | +/* | |
8074 | + * lookup and dentry operations | |
8075 | + */ | |
8076 | + | |
eca801bf | 8077 | +#include <linux/iversion.h> |
dece6358 | 8078 | +#include <linux/namei.h> |
1facf9fc | 8079 | +#include "aufs.h" |
8080 | + | |
1facf9fc | 8081 | +/* |
8082 | + * returns positive/negative dentry, NULL or an error. | |
8083 | + * NULL means whiteout-ed or not-found. | |
8084 | + */ | |
8085 | +static struct dentry* | |
8086 | +au_do_lookup(struct dentry *h_parent, struct dentry *dentry, | |
8b6a4947 | 8087 | + aufs_bindex_t bindex, struct au_do_lookup_args *args) |
1facf9fc | 8088 | +{ |
8089 | + struct dentry *h_dentry; | |
2000de60 | 8090 | + struct inode *h_inode; |
1facf9fc | 8091 | + struct au_branch *br; |
8092 | + int wh_found, opq; | |
8093 | + unsigned char wh_able; | |
8094 | + const unsigned char allow_neg = !!au_ftest_lkup(args->flags, ALLOW_NEG); | |
076b876e AM |
8095 | + const unsigned char ignore_perm = !!au_ftest_lkup(args->flags, |
8096 | + IGNORE_PERM); | |
1facf9fc | 8097 | + |
1facf9fc | 8098 | + wh_found = 0; |
8099 | + br = au_sbr(dentry->d_sb, bindex); | |
8100 | + wh_able = !!au_br_whable(br->br_perm); | |
8101 | + if (wh_able) | |
8b6a4947 | 8102 | + wh_found = au_wh_test(h_parent, &args->whname, ignore_perm); |
1facf9fc | 8103 | + h_dentry = ERR_PTR(wh_found); |
8104 | + if (!wh_found) | |
8105 | + goto real_lookup; | |
8106 | + if (unlikely(wh_found < 0)) | |
8107 | + goto out; | |
8108 | + | |
8109 | + /* We found a whiteout */ | |
5afbbe0d | 8110 | + /* au_set_dbbot(dentry, bindex); */ |
1facf9fc | 8111 | + au_set_dbwh(dentry, bindex); |
8112 | + if (!allow_neg) | |
8113 | + return NULL; /* success */ | |
8114 | + | |
4f0767ce | 8115 | +real_lookup: |
076b876e | 8116 | + if (!ignore_perm) |
8b6a4947 | 8117 | + h_dentry = vfsub_lkup_one(args->name, h_parent); |
076b876e | 8118 | + else |
8b6a4947 | 8119 | + h_dentry = au_sio_lkup_one(args->name, h_parent); |
2000de60 JR |
8120 | + if (IS_ERR(h_dentry)) { |
8121 | + if (PTR_ERR(h_dentry) == -ENAMETOOLONG | |
8122 | + && !allow_neg) | |
8123 | + h_dentry = NULL; | |
1facf9fc | 8124 | + goto out; |
2000de60 | 8125 | + } |
1facf9fc | 8126 | + |
5527c038 JR |
8127 | + h_inode = d_inode(h_dentry); |
8128 | + if (d_is_negative(h_dentry)) { | |
1facf9fc | 8129 | + if (!allow_neg) |
8130 | + goto out_neg; | |
8131 | + } else if (wh_found | |
8132 | + || (args->type && args->type != (h_inode->i_mode & S_IFMT))) | |
8133 | + goto out_neg; | |
8b6a4947 AM |
8134 | + else if (au_ftest_lkup(args->flags, DIRREN) |
8135 | + /* && h_inode */ | |
8136 | + && !au_dr_lkup_h_ino(args, bindex, h_inode->i_ino)) { | |
8137 | + AuDbg("b%d %pd ignored hi%llu\n", bindex, h_dentry, | |
8138 | + (unsigned long long)h_inode->i_ino); | |
8139 | + goto out_neg; | |
8140 | + } | |
1facf9fc | 8141 | + |
5afbbe0d AM |
8142 | + if (au_dbbot(dentry) <= bindex) |
8143 | + au_set_dbbot(dentry, bindex); | |
8144 | + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry)) | |
8145 | + au_set_dbtop(dentry, bindex); | |
1facf9fc | 8146 | + au_set_h_dptr(dentry, bindex, h_dentry); |
8147 | + | |
2000de60 JR |
8148 | + if (!d_is_dir(h_dentry) |
8149 | + || !wh_able | |
5527c038 | 8150 | + || (d_really_is_positive(dentry) && !d_is_dir(dentry))) |
1facf9fc | 8151 | + goto out; /* success */ |
8152 | + | |
be118d29 | 8153 | + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD); |
076b876e | 8154 | + opq = au_diropq_test(h_dentry); |
3c1bdaff | 8155 | + inode_unlock_shared(h_inode); |
1facf9fc | 8156 | + if (opq > 0) |
8157 | + au_set_dbdiropq(dentry, bindex); | |
8158 | + else if (unlikely(opq < 0)) { | |
8159 | + au_set_h_dptr(dentry, bindex, NULL); | |
8160 | + h_dentry = ERR_PTR(opq); | |
8161 | + } | |
8162 | + goto out; | |
8163 | + | |
4f0767ce | 8164 | +out_neg: |
1facf9fc | 8165 | + dput(h_dentry); |
8166 | + h_dentry = NULL; | |
4f0767ce | 8167 | +out: |
1facf9fc | 8168 | + return h_dentry; |
8169 | +} | |
8170 | + | |
dece6358 AM |
8171 | +static int au_test_shwh(struct super_block *sb, const struct qstr *name) |
8172 | +{ | |
8173 | + if (unlikely(!au_opt_test(au_mntflags(sb), SHWH) | |
8174 | + && !strncmp(name->name, AUFS_WH_PFX, AUFS_WH_PFX_LEN))) | |
8175 | + return -EPERM; | |
8176 | + return 0; | |
8177 | +} | |
8178 | + | |
1facf9fc | 8179 | +/* |
8180 | + * returns the number of lower positive dentries, | |
8181 | + * otherwise an error. | |
8182 | + * can be called at unlinking with @type is zero. | |
8183 | + */ | |
5afbbe0d AM |
8184 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop, |
8185 | + unsigned int flags) | |
1facf9fc | 8186 | +{ |
8187 | + int npositive, err; | |
8188 | + aufs_bindex_t bindex, btail, bdiropq; | |
8b6a4947 | 8189 | + unsigned char isdir, dirperm1, dirren; |
1facf9fc | 8190 | + struct au_do_lookup_args args = { |
8b6a4947 AM |
8191 | + .flags = flags, |
8192 | + .name = &dentry->d_name | |
1facf9fc | 8193 | + }; |
1facf9fc | 8194 | + struct dentry *parent; |
076b876e | 8195 | + struct super_block *sb; |
1facf9fc | 8196 | + |
076b876e | 8197 | + sb = dentry->d_sb; |
8b6a4947 | 8198 | + err = au_test_shwh(sb, args.name); |
dece6358 | 8199 | + if (unlikely(err)) |
1facf9fc | 8200 | + goto out; |
8201 | + | |
8b6a4947 | 8202 | + err = au_wh_name_alloc(&args.whname, args.name); |
1facf9fc | 8203 | + if (unlikely(err)) |
8204 | + goto out; | |
8205 | + | |
2000de60 | 8206 | + isdir = !!d_is_dir(dentry); |
076b876e | 8207 | + dirperm1 = !!au_opt_test(au_mntflags(sb), DIRPERM1); |
8b6a4947 AM |
8208 | + dirren = !!au_opt_test(au_mntflags(sb), DIRREN); |
8209 | + if (dirren) | |
8210 | + au_fset_lkup(args.flags, DIRREN); | |
1facf9fc | 8211 | + |
8212 | + npositive = 0; | |
4a4d8108 | 8213 | + parent = dget_parent(dentry); |
1facf9fc | 8214 | + btail = au_dbtaildir(parent); |
5afbbe0d | 8215 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 8216 | + struct dentry *h_parent, *h_dentry; |
8217 | + struct inode *h_inode, *h_dir; | |
8b6a4947 | 8218 | + struct au_branch *br; |
1facf9fc | 8219 | + |
8220 | + h_dentry = au_h_dptr(dentry, bindex); | |
8221 | + if (h_dentry) { | |
5527c038 | 8222 | + if (d_is_positive(h_dentry)) |
1facf9fc | 8223 | + npositive++; |
5afbbe0d | 8224 | + break; |
1facf9fc | 8225 | + } |
8226 | + h_parent = au_h_dptr(parent, bindex); | |
2000de60 | 8227 | + if (!h_parent || !d_is_dir(h_parent)) |
1facf9fc | 8228 | + continue; |
8229 | + | |
8b6a4947 AM |
8230 | + if (dirren) { |
8231 | + /* if the inum matches, then use the prepared name */ | |
8232 | + err = au_dr_lkup_name(&args, bindex); | |
8233 | + if (unlikely(err)) | |
8234 | + goto out_parent; | |
8235 | + } | |
8236 | + | |
5527c038 | 8237 | + h_dir = d_inode(h_parent); |
be118d29 | 8238 | + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT); |
8b6a4947 | 8239 | + h_dentry = au_do_lookup(h_parent, dentry, bindex, &args); |
3c1bdaff | 8240 | + inode_unlock_shared(h_dir); |
1facf9fc | 8241 | + err = PTR_ERR(h_dentry); |
8242 | + if (IS_ERR(h_dentry)) | |
4a4d8108 | 8243 | + goto out_parent; |
2000de60 JR |
8244 | + if (h_dentry) |
8245 | + au_fclr_lkup(args.flags, ALLOW_NEG); | |
076b876e AM |
8246 | + if (dirperm1) |
8247 | + au_fset_lkup(args.flags, IGNORE_PERM); | |
1facf9fc | 8248 | + |
79b8bda9 | 8249 | + if (au_dbwh(dentry) == bindex) |
1facf9fc | 8250 | + break; |
8251 | + if (!h_dentry) | |
8252 | + continue; | |
5527c038 | 8253 | + if (d_is_negative(h_dentry)) |
1facf9fc | 8254 | + continue; |
5527c038 | 8255 | + h_inode = d_inode(h_dentry); |
1facf9fc | 8256 | + npositive++; |
8257 | + if (!args.type) | |
8258 | + args.type = h_inode->i_mode & S_IFMT; | |
8259 | + if (args.type != S_IFDIR) | |
8260 | + break; | |
8261 | + else if (isdir) { | |
8262 | + /* the type of lower may be different */ | |
8263 | + bdiropq = au_dbdiropq(dentry); | |
8264 | + if (bdiropq >= 0 && bdiropq <= bindex) | |
8265 | + break; | |
8266 | + } | |
8b6a4947 AM |
8267 | + br = au_sbr(sb, bindex); |
8268 | + if (dirren | |
8269 | + && au_dr_hino_test_add(&br->br_dirren, h_inode->i_ino, | |
8270 | + /*add_ent*/NULL)) { | |
8271 | + /* prepare next name to lookup */ | |
8272 | + err = au_dr_lkup(&args, dentry, bindex); | |
8273 | + if (unlikely(err)) | |
8274 | + goto out_parent; | |
8275 | + } | |
1facf9fc | 8276 | + } |
8277 | + | |
8278 | + if (npositive) { | |
8279 | + AuLabel(positive); | |
5afbbe0d | 8280 | + au_update_dbtop(dentry); |
1facf9fc | 8281 | + } |
8282 | + err = npositive; | |
076b876e | 8283 | + if (unlikely(!au_opt_test(au_mntflags(sb), UDBA_NONE) |
5afbbe0d | 8284 | + && au_dbtop(dentry) < 0)) { |
1facf9fc | 8285 | + err = -EIO; |
523b37e3 AM |
8286 | + AuIOErr("both of real entry and whiteout found, %pd, err %d\n", |
8287 | + dentry, err); | |
027c5e7a | 8288 | + } |
1facf9fc | 8289 | + |
4f0767ce | 8290 | +out_parent: |
4a4d8108 | 8291 | + dput(parent); |
9f237c51 | 8292 | + au_kfree_try_rcu(args.whname.name); |
8b6a4947 AM |
8293 | + if (dirren) |
8294 | + au_dr_lkup_fin(&args); | |
4f0767ce | 8295 | +out: |
1facf9fc | 8296 | + return err; |
8297 | +} | |
8298 | + | |
076b876e | 8299 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent) |
1facf9fc | 8300 | +{ |
8301 | + struct dentry *dentry; | |
8302 | + int wkq_err; | |
8303 | + | |
5527c038 | 8304 | + if (!au_test_h_perm_sio(d_inode(parent), MAY_EXEC)) |
b4510431 | 8305 | + dentry = vfsub_lkup_one(name, parent); |
1facf9fc | 8306 | + else { |
b4510431 AM |
8307 | + struct vfsub_lkup_one_args args = { |
8308 | + .errp = &dentry, | |
8309 | + .name = name, | |
8310 | + .parent = parent | |
1facf9fc | 8311 | + }; |
8312 | + | |
b4510431 | 8313 | + wkq_err = au_wkq_wait(vfsub_call_lkup_one, &args); |
1facf9fc | 8314 | + if (unlikely(wkq_err)) |
8315 | + dentry = ERR_PTR(wkq_err); | |
8316 | + } | |
8317 | + | |
8318 | + return dentry; | |
8319 | +} | |
8320 | + | |
8321 | +/* | |
8322 | + * lookup @dentry on @bindex which should be negative. | |
8323 | + */ | |
86dc4139 | 8324 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh) |
1facf9fc | 8325 | +{ |
8326 | + int err; | |
8327 | + struct dentry *parent, *h_parent, *h_dentry; | |
86dc4139 | 8328 | + struct au_branch *br; |
1facf9fc | 8329 | + |
1facf9fc | 8330 | + parent = dget_parent(dentry); |
8331 | + h_parent = au_h_dptr(parent, bindex); | |
86dc4139 AM |
8332 | + br = au_sbr(dentry->d_sb, bindex); |
8333 | + if (wh) | |
8334 | + h_dentry = au_whtmp_lkup(h_parent, br, &dentry->d_name); | |
8335 | + else | |
076b876e | 8336 | + h_dentry = au_sio_lkup_one(&dentry->d_name, h_parent); |
1facf9fc | 8337 | + err = PTR_ERR(h_dentry); |
8338 | + if (IS_ERR(h_dentry)) | |
8339 | + goto out; | |
5527c038 | 8340 | + if (unlikely(d_is_positive(h_dentry))) { |
1facf9fc | 8341 | + err = -EIO; |
523b37e3 | 8342 | + AuIOErr("%pd should be negative on b%d.\n", h_dentry, bindex); |
1facf9fc | 8343 | + dput(h_dentry); |
8344 | + goto out; | |
8345 | + } | |
8346 | + | |
4a4d8108 | 8347 | + err = 0; |
5afbbe0d AM |
8348 | + if (bindex < au_dbtop(dentry)) |
8349 | + au_set_dbtop(dentry, bindex); | |
8350 | + if (au_dbbot(dentry) < bindex) | |
8351 | + au_set_dbbot(dentry, bindex); | |
1facf9fc | 8352 | + au_set_h_dptr(dentry, bindex, h_dentry); |
1facf9fc | 8353 | + |
4f0767ce | 8354 | +out: |
1facf9fc | 8355 | + dput(parent); |
8356 | + return err; | |
8357 | +} | |
8358 | + | |
8359 | +/* ---------------------------------------------------------------------- */ | |
8360 | + | |
8361 | +/* subset of struct inode */ | |
8362 | +struct au_iattr { | |
8363 | + unsigned long i_ino; | |
8364 | + /* unsigned int i_nlink; */ | |
0c3ec466 AM |
8365 | + kuid_t i_uid; |
8366 | + kgid_t i_gid; | |
1facf9fc | 8367 | + u64 i_version; |
8368 | +/* | |
8369 | + loff_t i_size; | |
8370 | + blkcnt_t i_blocks; | |
8371 | +*/ | |
8372 | + umode_t i_mode; | |
8373 | +}; | |
8374 | + | |
8375 | +static void au_iattr_save(struct au_iattr *ia, struct inode *h_inode) | |
8376 | +{ | |
8377 | + ia->i_ino = h_inode->i_ino; | |
8378 | + /* ia->i_nlink = h_inode->i_nlink; */ | |
8379 | + ia->i_uid = h_inode->i_uid; | |
8380 | + ia->i_gid = h_inode->i_gid; | |
be118d29 | 8381 | + ia->i_version = inode_query_iversion(h_inode); |
1facf9fc | 8382 | +/* |
8383 | + ia->i_size = h_inode->i_size; | |
8384 | + ia->i_blocks = h_inode->i_blocks; | |
8385 | +*/ | |
8386 | + ia->i_mode = (h_inode->i_mode & S_IFMT); | |
8387 | +} | |
8388 | + | |
8389 | +static int au_iattr_test(struct au_iattr *ia, struct inode *h_inode) | |
8390 | +{ | |
8391 | + return ia->i_ino != h_inode->i_ino | |
8392 | + /* || ia->i_nlink != h_inode->i_nlink */ | |
0c3ec466 | 8393 | + || !uid_eq(ia->i_uid, h_inode->i_uid) |
2dfbb274 | 8394 | + || !gid_eq(ia->i_gid, h_inode->i_gid) |
be118d29 | 8395 | + || !inode_eq_iversion(h_inode, ia->i_version) |
1facf9fc | 8396 | +/* |
8397 | + || ia->i_size != h_inode->i_size | |
8398 | + || ia->i_blocks != h_inode->i_blocks | |
8399 | +*/ | |
8400 | + || ia->i_mode != (h_inode->i_mode & S_IFMT); | |
8401 | +} | |
8402 | + | |
8403 | +static int au_h_verify_dentry(struct dentry *h_dentry, struct dentry *h_parent, | |
8404 | + struct au_branch *br) | |
8405 | +{ | |
8406 | + int err; | |
8407 | + struct au_iattr ia; | |
8408 | + struct inode *h_inode; | |
8409 | + struct dentry *h_d; | |
8410 | + struct super_block *h_sb; | |
8411 | + | |
8412 | + err = 0; | |
8413 | + memset(&ia, -1, sizeof(ia)); | |
8414 | + h_sb = h_dentry->d_sb; | |
5527c038 JR |
8415 | + h_inode = NULL; |
8416 | + if (d_is_positive(h_dentry)) { | |
8417 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8418 | + au_iattr_save(&ia, h_inode); |
5527c038 | 8419 | + } else if (au_test_nfs(h_sb) || au_test_fuse(h_sb)) |
1facf9fc | 8420 | + /* nfs d_revalidate may return 0 for negative dentry */ |
8421 | + /* fuse d_revalidate always return 0 for negative dentry */ | |
8422 | + goto out; | |
8423 | + | |
8424 | + /* main purpose is namei.c:cached_lookup() and d_revalidate */ | |
b4510431 | 8425 | + h_d = vfsub_lkup_one(&h_dentry->d_name, h_parent); |
1facf9fc | 8426 | + err = PTR_ERR(h_d); |
8427 | + if (IS_ERR(h_d)) | |
8428 | + goto out; | |
8429 | + | |
8430 | + err = 0; | |
8431 | + if (unlikely(h_d != h_dentry | |
5527c038 | 8432 | + || d_inode(h_d) != h_inode |
1facf9fc | 8433 | + || (h_inode && au_iattr_test(&ia, h_inode)))) |
8434 | + err = au_busy_or_stale(); | |
8435 | + dput(h_d); | |
8436 | + | |
4f0767ce | 8437 | +out: |
1facf9fc | 8438 | + AuTraceErr(err); |
8439 | + return err; | |
8440 | +} | |
8441 | + | |
8442 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, | |
8443 | + struct dentry *h_parent, struct au_branch *br) | |
8444 | +{ | |
8445 | + int err; | |
8446 | + | |
8447 | + err = 0; | |
027c5e7a AM |
8448 | + if (udba == AuOpt_UDBA_REVAL |
8449 | + && !au_test_fs_remote(h_dentry->d_sb)) { | |
1facf9fc | 8450 | + IMustLock(h_dir); |
5527c038 | 8451 | + err = (d_inode(h_dentry->d_parent) != h_dir); |
027c5e7a | 8452 | + } else if (udba != AuOpt_UDBA_NONE) |
1facf9fc | 8453 | + err = au_h_verify_dentry(h_dentry, h_parent, br); |
8454 | + | |
8455 | + return err; | |
8456 | +} | |
8457 | + | |
8458 | +/* ---------------------------------------------------------------------- */ | |
8459 | + | |
027c5e7a | 8460 | +static int au_do_refresh_hdentry(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 8461 | +{ |
027c5e7a | 8462 | + int err; |
5afbbe0d | 8463 | + aufs_bindex_t new_bindex, bindex, bbot, bwh, bdiropq; |
027c5e7a AM |
8464 | + struct au_hdentry tmp, *p, *q; |
8465 | + struct au_dinfo *dinfo; | |
8466 | + struct super_block *sb; | |
1facf9fc | 8467 | + |
027c5e7a | 8468 | + DiMustWriteLock(dentry); |
1308ab2a | 8469 | + |
027c5e7a AM |
8470 | + sb = dentry->d_sb; |
8471 | + dinfo = au_di(dentry); | |
5afbbe0d | 8472 | + bbot = dinfo->di_bbot; |
1facf9fc | 8473 | + bwh = dinfo->di_bwh; |
8474 | + bdiropq = dinfo->di_bdiropq; | |
5afbbe0d AM |
8475 | + bindex = dinfo->di_btop; |
8476 | + p = au_hdentry(dinfo, bindex); | |
8477 | + for (; bindex <= bbot; bindex++, p++) { | |
027c5e7a | 8478 | + if (!p->hd_dentry) |
1facf9fc | 8479 | + continue; |
8480 | + | |
027c5e7a AM |
8481 | + new_bindex = au_br_index(sb, p->hd_id); |
8482 | + if (new_bindex == bindex) | |
1facf9fc | 8483 | + continue; |
1facf9fc | 8484 | + |
1facf9fc | 8485 | + if (dinfo->di_bwh == bindex) |
8486 | + bwh = new_bindex; | |
8487 | + if (dinfo->di_bdiropq == bindex) | |
8488 | + bdiropq = new_bindex; | |
8489 | + if (new_bindex < 0) { | |
8490 | + au_hdput(p); | |
8491 | + p->hd_dentry = NULL; | |
8492 | + continue; | |
8493 | + } | |
8494 | + | |
8495 | + /* swap two lower dentries, and loop again */ | |
5afbbe0d | 8496 | + q = au_hdentry(dinfo, new_bindex); |
1facf9fc | 8497 | + tmp = *q; |
8498 | + *q = *p; | |
8499 | + *p = tmp; | |
8500 | + if (tmp.hd_dentry) { | |
8501 | + bindex--; | |
8502 | + p--; | |
8503 | + } | |
8504 | + } | |
8505 | + | |
1facf9fc | 8506 | + dinfo->di_bwh = -1; |
5afbbe0d | 8507 | + if (bwh >= 0 && bwh <= au_sbbot(sb) && au_sbr_whable(sb, bwh)) |
1facf9fc | 8508 | + dinfo->di_bwh = bwh; |
8509 | + | |
8510 | + dinfo->di_bdiropq = -1; | |
8511 | + if (bdiropq >= 0 | |
5afbbe0d | 8512 | + && bdiropq <= au_sbbot(sb) |
1facf9fc | 8513 | + && au_sbr_whable(sb, bdiropq)) |
8514 | + dinfo->di_bdiropq = bdiropq; | |
8515 | + | |
027c5e7a | 8516 | + err = -EIO; |
5afbbe0d AM |
8517 | + dinfo->di_btop = -1; |
8518 | + dinfo->di_bbot = -1; | |
8519 | + bbot = au_dbbot(parent); | |
8520 | + bindex = 0; | |
8521 | + p = au_hdentry(dinfo, bindex); | |
8522 | + for (; bindex <= bbot; bindex++, p++) | |
1facf9fc | 8523 | + if (p->hd_dentry) { |
5afbbe0d | 8524 | + dinfo->di_btop = bindex; |
1facf9fc | 8525 | + break; |
8526 | + } | |
8527 | + | |
5afbbe0d AM |
8528 | + if (dinfo->di_btop >= 0) { |
8529 | + bindex = bbot; | |
8530 | + p = au_hdentry(dinfo, bindex); | |
8531 | + for (; bindex >= 0; bindex--, p--) | |
027c5e7a | 8532 | + if (p->hd_dentry) { |
5afbbe0d | 8533 | + dinfo->di_bbot = bindex; |
027c5e7a AM |
8534 | + err = 0; |
8535 | + break; | |
8536 | + } | |
8537 | + } | |
8538 | + | |
8539 | + return err; | |
1facf9fc | 8540 | +} |
8541 | + | |
027c5e7a | 8542 | +static void au_do_hide(struct dentry *dentry) |
1facf9fc | 8543 | +{ |
027c5e7a | 8544 | + struct inode *inode; |
1facf9fc | 8545 | + |
5527c038 JR |
8546 | + if (d_really_is_positive(dentry)) { |
8547 | + inode = d_inode(dentry); | |
8548 | + if (!d_is_dir(dentry)) { | |
027c5e7a AM |
8549 | + if (inode->i_nlink && !d_unhashed(dentry)) |
8550 | + drop_nlink(inode); | |
8551 | + } else { | |
8552 | + clear_nlink(inode); | |
8553 | + /* stop next lookup */ | |
8554 | + inode->i_flags |= S_DEAD; | |
8555 | + } | |
8556 | + smp_mb(); /* necessary? */ | |
8557 | + } | |
8558 | + d_drop(dentry); | |
8559 | +} | |
1308ab2a | 8560 | + |
027c5e7a AM |
8561 | +static int au_hide_children(struct dentry *parent) |
8562 | +{ | |
8563 | + int err, i, j, ndentry; | |
8564 | + struct au_dcsub_pages dpages; | |
8565 | + struct au_dpage *dpage; | |
8566 | + struct dentry *dentry; | |
1facf9fc | 8567 | + |
027c5e7a | 8568 | + err = au_dpages_init(&dpages, GFP_NOFS); |
1facf9fc | 8569 | + if (unlikely(err)) |
8570 | + goto out; | |
027c5e7a AM |
8571 | + err = au_dcsub_pages(&dpages, parent, NULL, NULL); |
8572 | + if (unlikely(err)) | |
8573 | + goto out_dpages; | |
1facf9fc | 8574 | + |
027c5e7a AM |
8575 | + /* in reverse order */ |
8576 | + for (i = dpages.ndpage - 1; i >= 0; i--) { | |
8577 | + dpage = dpages.dpages + i; | |
8578 | + ndentry = dpage->ndentry; | |
8579 | + for (j = ndentry - 1; j >= 0; j--) { | |
8580 | + dentry = dpage->dentries[j]; | |
8581 | + if (dentry != parent) | |
8582 | + au_do_hide(dentry); | |
8583 | + } | |
8584 | + } | |
1facf9fc | 8585 | + |
027c5e7a AM |
8586 | +out_dpages: |
8587 | + au_dpages_free(&dpages); | |
4f0767ce | 8588 | +out: |
027c5e7a | 8589 | + return err; |
1facf9fc | 8590 | +} |
8591 | + | |
027c5e7a | 8592 | +static void au_hide(struct dentry *dentry) |
1facf9fc | 8593 | +{ |
027c5e7a | 8594 | + int err; |
1facf9fc | 8595 | + |
027c5e7a | 8596 | + AuDbgDentry(dentry); |
2000de60 | 8597 | + if (d_is_dir(dentry)) { |
027c5e7a AM |
8598 | + /* shrink_dcache_parent(dentry); */ |
8599 | + err = au_hide_children(dentry); | |
8600 | + if (unlikely(err)) | |
523b37e3 AM |
8601 | + AuIOErr("%pd, failed hiding children, ignored %d\n", |
8602 | + dentry, err); | |
027c5e7a AM |
8603 | + } |
8604 | + au_do_hide(dentry); | |
8605 | +} | |
1facf9fc | 8606 | + |
027c5e7a AM |
8607 | +/* |
8608 | + * By adding a dirty branch, a cached dentry may be affected in various ways. | |
8609 | + * | |
8610 | + * a dirty branch is added | |
8611 | + * - on the top of layers | |
8612 | + * - in the middle of layers | |
8613 | + * - to the bottom of layers | |
8614 | + * | |
8615 | + * on the added branch there exists | |
8616 | + * - a whiteout | |
8617 | + * - a diropq | |
8618 | + * - a same named entry | |
8619 | + * + exist | |
8620 | + * * negative --> positive | |
8621 | + * * positive --> positive | |
8622 | + * - type is unchanged | |
8623 | + * - type is changed | |
8624 | + * + doesn't exist | |
8625 | + * * negative --> negative | |
8626 | + * * positive --> negative (rejected by au_br_del() for non-dir case) | |
8627 | + * - none | |
8628 | + */ | |
8629 | +static int au_refresh_by_dinfo(struct dentry *dentry, struct au_dinfo *dinfo, | |
8630 | + struct au_dinfo *tmp) | |
8631 | +{ | |
8632 | + int err; | |
5afbbe0d | 8633 | + aufs_bindex_t bindex, bbot; |
027c5e7a AM |
8634 | + struct { |
8635 | + struct dentry *dentry; | |
8636 | + struct inode *inode; | |
8637 | + mode_t mode; | |
be52b249 AM |
8638 | + } orig_h, tmp_h = { |
8639 | + .dentry = NULL | |
8640 | + }; | |
027c5e7a AM |
8641 | + struct au_hdentry *hd; |
8642 | + struct inode *inode, *h_inode; | |
8643 | + struct dentry *h_dentry; | |
8644 | + | |
8645 | + err = 0; | |
5afbbe0d | 8646 | + AuDebugOn(dinfo->di_btop < 0); |
027c5e7a | 8647 | + orig_h.mode = 0; |
5afbbe0d | 8648 | + orig_h.dentry = au_hdentry(dinfo, dinfo->di_btop)->hd_dentry; |
5527c038 JR |
8649 | + orig_h.inode = NULL; |
8650 | + if (d_is_positive(orig_h.dentry)) { | |
8651 | + orig_h.inode = d_inode(orig_h.dentry); | |
027c5e7a | 8652 | + orig_h.mode = orig_h.inode->i_mode & S_IFMT; |
5527c038 | 8653 | + } |
5afbbe0d AM |
8654 | + if (tmp->di_btop >= 0) { |
8655 | + tmp_h.dentry = au_hdentry(tmp, tmp->di_btop)->hd_dentry; | |
5527c038 JR |
8656 | + if (d_is_positive(tmp_h.dentry)) { |
8657 | + tmp_h.inode = d_inode(tmp_h.dentry); | |
027c5e7a | 8658 | + tmp_h.mode = tmp_h.inode->i_mode & S_IFMT; |
5527c038 | 8659 | + } |
027c5e7a AM |
8660 | + } |
8661 | + | |
5527c038 JR |
8662 | + inode = NULL; |
8663 | + if (d_really_is_positive(dentry)) | |
8664 | + inode = d_inode(dentry); | |
027c5e7a | 8665 | + if (!orig_h.inode) { |
acd2b654 | 8666 | + AuDbg("negative originally\n"); |
027c5e7a AM |
8667 | + if (inode) { |
8668 | + au_hide(dentry); | |
8669 | + goto out; | |
8670 | + } | |
8671 | + AuDebugOn(inode); | |
5afbbe0d | 8672 | + AuDebugOn(dinfo->di_btop != dinfo->di_bbot); |
027c5e7a AM |
8673 | + AuDebugOn(dinfo->di_bdiropq != -1); |
8674 | + | |
8675 | + if (!tmp_h.inode) { | |
8676 | + AuDbg("negative --> negative\n"); | |
8677 | + /* should have only one negative lower */ | |
5afbbe0d AM |
8678 | + if (tmp->di_btop >= 0 |
8679 | + && tmp->di_btop < dinfo->di_btop) { | |
8680 | + AuDebugOn(tmp->di_btop != tmp->di_bbot); | |
8681 | + AuDebugOn(dinfo->di_btop != dinfo->di_bbot); | |
8682 | + au_set_h_dptr(dentry, dinfo->di_btop, NULL); | |
027c5e7a | 8683 | + au_di_cp(dinfo, tmp); |
5afbbe0d AM |
8684 | + hd = au_hdentry(tmp, tmp->di_btop); |
8685 | + au_set_h_dptr(dentry, tmp->di_btop, | |
027c5e7a AM |
8686 | + dget(hd->hd_dentry)); |
8687 | + } | |
8688 | + au_dbg_verify_dinode(dentry); | |
8689 | + } else { | |
8690 | + AuDbg("negative --> positive\n"); | |
8691 | + /* | |
8692 | + * similar to the behaviour of creating with bypassing | |
8693 | + * aufs. | |
8694 | + * unhash it in order to force an error in the | |
8695 | + * succeeding create operation. | |
8696 | + * we should not set S_DEAD here. | |
8697 | + */ | |
8698 | + d_drop(dentry); | |
8699 | + /* au_di_swap(tmp, dinfo); */ | |
8700 | + au_dbg_verify_dinode(dentry); | |
8701 | + } | |
8702 | + } else { | |
8703 | + AuDbg("positive originally\n"); | |
8704 | + /* inode may be NULL */ | |
8705 | + AuDebugOn(inode && (inode->i_mode & S_IFMT) != orig_h.mode); | |
8706 | + if (!tmp_h.inode) { | |
8707 | + AuDbg("positive --> negative\n"); | |
8708 | + /* or bypassing aufs */ | |
8709 | + au_hide(dentry); | |
5afbbe0d | 8710 | + if (tmp->di_bwh >= 0 && tmp->di_bwh <= dinfo->di_btop) |
027c5e7a AM |
8711 | + dinfo->di_bwh = tmp->di_bwh; |
8712 | + if (inode) | |
8713 | + err = au_refresh_hinode_self(inode); | |
8714 | + au_dbg_verify_dinode(dentry); | |
8715 | + } else if (orig_h.mode == tmp_h.mode) { | |
8716 | + AuDbg("positive --> positive, same type\n"); | |
8717 | + if (!S_ISDIR(orig_h.mode) | |
5afbbe0d | 8718 | + && dinfo->di_btop > tmp->di_btop) { |
027c5e7a AM |
8719 | + /* |
8720 | + * similar to the behaviour of removing and | |
8721 | + * creating. | |
8722 | + */ | |
8723 | + au_hide(dentry); | |
8724 | + if (inode) | |
8725 | + err = au_refresh_hinode_self(inode); | |
8726 | + au_dbg_verify_dinode(dentry); | |
8727 | + } else { | |
8728 | + /* fill empty slots */ | |
5afbbe0d AM |
8729 | + if (dinfo->di_btop > tmp->di_btop) |
8730 | + dinfo->di_btop = tmp->di_btop; | |
8731 | + if (dinfo->di_bbot < tmp->di_bbot) | |
8732 | + dinfo->di_bbot = tmp->di_bbot; | |
027c5e7a AM |
8733 | + dinfo->di_bwh = tmp->di_bwh; |
8734 | + dinfo->di_bdiropq = tmp->di_bdiropq; | |
5afbbe0d AM |
8735 | + bbot = dinfo->di_bbot; |
8736 | + bindex = tmp->di_btop; | |
8737 | + hd = au_hdentry(tmp, bindex); | |
8738 | + for (; bindex <= bbot; bindex++, hd++) { | |
027c5e7a AM |
8739 | + if (au_h_dptr(dentry, bindex)) |
8740 | + continue; | |
5afbbe0d | 8741 | + h_dentry = hd->hd_dentry; |
027c5e7a AM |
8742 | + if (!h_dentry) |
8743 | + continue; | |
5527c038 JR |
8744 | + AuDebugOn(d_is_negative(h_dentry)); |
8745 | + h_inode = d_inode(h_dentry); | |
027c5e7a AM |
8746 | + AuDebugOn(orig_h.mode |
8747 | + != (h_inode->i_mode | |
8748 | + & S_IFMT)); | |
8749 | + au_set_h_dptr(dentry, bindex, | |
8750 | + dget(h_dentry)); | |
8751 | + } | |
5afbbe0d AM |
8752 | + if (inode) |
8753 | + err = au_refresh_hinode(inode, dentry); | |
027c5e7a AM |
8754 | + au_dbg_verify_dinode(dentry); |
8755 | + } | |
8756 | + } else { | |
8757 | + AuDbg("positive --> positive, different type\n"); | |
8758 | + /* similar to the behaviour of removing and creating */ | |
8759 | + au_hide(dentry); | |
8760 | + if (inode) | |
8761 | + err = au_refresh_hinode_self(inode); | |
8762 | + au_dbg_verify_dinode(dentry); | |
8763 | + } | |
8764 | + } | |
8765 | + | |
8766 | +out: | |
8767 | + return err; | |
8768 | +} | |
8769 | + | |
79b8bda9 AM |
8770 | +void au_refresh_dop(struct dentry *dentry, int force_reval) |
8771 | +{ | |
8772 | + const struct dentry_operations *dop | |
8773 | + = force_reval ? &aufs_dop : dentry->d_sb->s_d_op; | |
8774 | + static const unsigned int mask | |
8775 | + = DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE; | |
8776 | + | |
8777 | + BUILD_BUG_ON(sizeof(mask) != sizeof(dentry->d_flags)); | |
8778 | + | |
8779 | + if (dentry->d_op == dop) | |
8780 | + return; | |
8781 | + | |
8782 | + AuDbg("%pd\n", dentry); | |
8783 | + spin_lock(&dentry->d_lock); | |
8784 | + if (dop == &aufs_dop) | |
8785 | + dentry->d_flags |= mask; | |
8786 | + else | |
8787 | + dentry->d_flags &= ~mask; | |
8788 | + dentry->d_op = dop; | |
8789 | + spin_unlock(&dentry->d_lock); | |
8790 | +} | |
8791 | + | |
027c5e7a AM |
8792 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent) |
8793 | +{ | |
e2f27e51 | 8794 | + int err, ebrange, nbr; |
027c5e7a AM |
8795 | + unsigned int sigen; |
8796 | + struct au_dinfo *dinfo, *tmp; | |
8797 | + struct super_block *sb; | |
8798 | + struct inode *inode; | |
8799 | + | |
8800 | + DiMustWriteLock(dentry); | |
8801 | + AuDebugOn(IS_ROOT(dentry)); | |
5527c038 | 8802 | + AuDebugOn(d_really_is_negative(parent)); |
027c5e7a AM |
8803 | + |
8804 | + sb = dentry->d_sb; | |
027c5e7a AM |
8805 | + sigen = au_sigen(sb); |
8806 | + err = au_digen_test(parent, sigen); | |
8807 | + if (unlikely(err)) | |
8808 | + goto out; | |
8809 | + | |
e2f27e51 | 8810 | + nbr = au_sbbot(sb) + 1; |
027c5e7a | 8811 | + dinfo = au_di(dentry); |
e2f27e51 | 8812 | + err = au_di_realloc(dinfo, nbr, /*may_shrink*/0); |
027c5e7a AM |
8813 | + if (unlikely(err)) |
8814 | + goto out; | |
8815 | + ebrange = au_dbrange_test(dentry); | |
8816 | + if (!ebrange) | |
8817 | + ebrange = au_do_refresh_hdentry(dentry, parent); | |
8818 | + | |
38d290e6 | 8819 | + if (d_unhashed(dentry) || ebrange /* || dinfo->di_tmpfile */) { |
5afbbe0d | 8820 | + AuDebugOn(au_dbtop(dentry) < 0 && au_dbbot(dentry) >= 0); |
5527c038 JR |
8821 | + if (d_really_is_positive(dentry)) { |
8822 | + inode = d_inode(dentry); | |
027c5e7a | 8823 | + err = au_refresh_hinode_self(inode); |
5527c038 | 8824 | + } |
027c5e7a AM |
8825 | + au_dbg_verify_dinode(dentry); |
8826 | + if (!err) | |
8827 | + goto out_dgen; /* success */ | |
8828 | + goto out; | |
8829 | + } | |
8830 | + | |
8831 | + /* temporary dinfo */ | |
8832 | + AuDbgDentry(dentry); | |
8833 | + err = -ENOMEM; | |
8834 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
8835 | + if (unlikely(!tmp)) | |
8836 | + goto out; | |
8837 | + au_di_swap(tmp, dinfo); | |
8838 | + /* returns the number of positive dentries */ | |
8839 | + /* | |
8840 | + * if current working dir is removed, it returns an error. | |
8841 | + * but the dentry is legal. | |
8842 | + */ | |
5afbbe0d | 8843 | + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG); |
027c5e7a AM |
8844 | + AuDbgDentry(dentry); |
8845 | + au_di_swap(tmp, dinfo); | |
8846 | + if (err == -ENOENT) | |
8847 | + err = 0; | |
8848 | + if (err >= 0) { | |
8849 | + /* compare/refresh by dinfo */ | |
8850 | + AuDbgDentry(dentry); | |
8851 | + err = au_refresh_by_dinfo(dentry, dinfo, tmp); | |
8852 | + au_dbg_verify_dinode(dentry); | |
8853 | + AuTraceErr(err); | |
8854 | + } | |
e2f27e51 | 8855 | + au_di_realloc(dinfo, nbr, /*may_shrink*/1); /* harmless if err */ |
027c5e7a AM |
8856 | + au_rw_write_unlock(&tmp->di_rwsem); |
8857 | + au_di_free(tmp); | |
8858 | + if (unlikely(err)) | |
8859 | + goto out; | |
8860 | + | |
8861 | +out_dgen: | |
8862 | + au_update_digen(dentry); | |
8863 | +out: | |
8864 | + if (unlikely(err && !(dentry->d_flags & DCACHE_NFSFS_RENAMED))) { | |
523b37e3 | 8865 | + AuIOErr("failed refreshing %pd, %d\n", dentry, err); |
027c5e7a AM |
8866 | + AuDbgDentry(dentry); |
8867 | + } | |
8868 | + AuTraceErr(err); | |
8869 | + return err; | |
8870 | +} | |
8871 | + | |
b4510431 AM |
8872 | +static int au_do_h_d_reval(struct dentry *h_dentry, unsigned int flags, |
8873 | + struct dentry *dentry, aufs_bindex_t bindex) | |
027c5e7a AM |
8874 | +{ |
8875 | + int err, valid; | |
027c5e7a AM |
8876 | + |
8877 | + err = 0; | |
8878 | + if (!(h_dentry->d_flags & DCACHE_OP_REVALIDATE)) | |
8879 | + goto out; | |
027c5e7a AM |
8880 | + |
8881 | + AuDbg("b%d\n", bindex); | |
b4510431 AM |
8882 | + /* |
8883 | + * gave up supporting LOOKUP_CREATE/OPEN for lower fs, | |
8884 | + * due to whiteout and branch permission. | |
8885 | + */ | |
8886 | + flags &= ~(/*LOOKUP_PARENT |*/ LOOKUP_OPEN | LOOKUP_CREATE | |
8887 | + | LOOKUP_FOLLOW | LOOKUP_EXCL); | |
8888 | + /* it may return tri-state */ | |
8889 | + valid = h_dentry->d_op->d_revalidate(h_dentry, flags); | |
1facf9fc | 8890 | + |
8891 | + if (unlikely(valid < 0)) | |
8892 | + err = valid; | |
8893 | + else if (!valid) | |
8894 | + err = -EINVAL; | |
8895 | + | |
4f0767ce | 8896 | +out: |
1facf9fc | 8897 | + AuTraceErr(err); |
8898 | + return err; | |
8899 | +} | |
8900 | + | |
8901 | +/* todo: remove this */ | |
8902 | +static int h_d_revalidate(struct dentry *dentry, struct inode *inode, | |
8b6a4947 | 8903 | + unsigned int flags, int do_udba, int dirren) |
1facf9fc | 8904 | +{ |
8905 | + int err; | |
8906 | + umode_t mode, h_mode; | |
5afbbe0d | 8907 | + aufs_bindex_t bindex, btail, btop, ibs, ibe; |
38d290e6 | 8908 | + unsigned char plus, unhashed, is_root, h_plus, h_nfs, tmpfile; |
4a4d8108 | 8909 | + struct inode *h_inode, *h_cached_inode; |
1facf9fc | 8910 | + struct dentry *h_dentry; |
8911 | + struct qstr *name, *h_name; | |
8912 | + | |
8913 | + err = 0; | |
8914 | + plus = 0; | |
8915 | + mode = 0; | |
1facf9fc | 8916 | + ibs = -1; |
8917 | + ibe = -1; | |
8918 | + unhashed = !!d_unhashed(dentry); | |
8919 | + is_root = !!IS_ROOT(dentry); | |
8920 | + name = &dentry->d_name; | |
38d290e6 | 8921 | + tmpfile = au_di(dentry)->di_tmpfile; |
1facf9fc | 8922 | + |
8923 | + /* | |
7f207e10 AM |
8924 | + * Theoretically, REVAL test should be unnecessary in case of |
8925 | + * {FS,I}NOTIFY. | |
8926 | + * But {fs,i}notify doesn't fire some necessary events, | |
1facf9fc | 8927 | + * IN_ATTRIB for atime/nlink/pageio |
1facf9fc | 8928 | + * Let's do REVAL test too. |
8929 | + */ | |
8930 | + if (do_udba && inode) { | |
8931 | + mode = (inode->i_mode & S_IFMT); | |
8932 | + plus = (inode->i_nlink > 0); | |
5afbbe0d AM |
8933 | + ibs = au_ibtop(inode); |
8934 | + ibe = au_ibbot(inode); | |
1facf9fc | 8935 | + } |
8936 | + | |
5afbbe0d AM |
8937 | + btop = au_dbtop(dentry); |
8938 | + btail = btop; | |
1facf9fc | 8939 | + if (inode && S_ISDIR(inode->i_mode)) |
8940 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 8941 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 8942 | + h_dentry = au_h_dptr(dentry, bindex); |
8943 | + if (!h_dentry) | |
8944 | + continue; | |
8945 | + | |
523b37e3 AM |
8946 | + AuDbg("b%d, %pd\n", bindex, h_dentry); |
8947 | + h_nfs = !!au_test_nfs(h_dentry->d_sb); | |
027c5e7a | 8948 | + spin_lock(&h_dentry->d_lock); |
1facf9fc | 8949 | + h_name = &h_dentry->d_name; |
8950 | + if (unlikely(do_udba | |
8951 | + && !is_root | |
523b37e3 AM |
8952 | + && ((!h_nfs |
8953 | + && (unhashed != !!d_unhashed(h_dentry) | |
8b6a4947 | 8954 | + || (!tmpfile && !dirren |
38d290e6 JR |
8955 | + && !au_qstreq(name, h_name)) |
8956 | + )) | |
523b37e3 AM |
8957 | + || (h_nfs |
8958 | + && !(flags & LOOKUP_OPEN) | |
8959 | + && (h_dentry->d_flags | |
8960 | + & DCACHE_NFSFS_RENAMED))) | |
1facf9fc | 8961 | + )) { |
38d290e6 JR |
8962 | + int h_unhashed; |
8963 | + | |
8964 | + h_unhashed = d_unhashed(h_dentry); | |
027c5e7a | 8965 | + spin_unlock(&h_dentry->d_lock); |
38d290e6 JR |
8966 | + AuDbg("unhash 0x%x 0x%x, %pd %pd\n", |
8967 | + unhashed, h_unhashed, dentry, h_dentry); | |
1facf9fc | 8968 | + goto err; |
8969 | + } | |
027c5e7a | 8970 | + spin_unlock(&h_dentry->d_lock); |
1facf9fc | 8971 | + |
b4510431 | 8972 | + err = au_do_h_d_reval(h_dentry, flags, dentry, bindex); |
1facf9fc | 8973 | + if (unlikely(err)) |
8974 | + /* do not goto err, to keep the errno */ | |
8975 | + break; | |
8976 | + | |
8977 | + /* todo: plink too? */ | |
8978 | + if (!do_udba) | |
8979 | + continue; | |
8980 | + | |
8981 | + /* UDBA tests */ | |
5527c038 | 8982 | + if (unlikely(!!inode != d_is_positive(h_dentry))) |
1facf9fc | 8983 | + goto err; |
8984 | + | |
5527c038 JR |
8985 | + h_inode = NULL; |
8986 | + if (d_is_positive(h_dentry)) | |
8987 | + h_inode = d_inode(h_dentry); | |
1facf9fc | 8988 | + h_plus = plus; |
8989 | + h_mode = mode; | |
8990 | + h_cached_inode = h_inode; | |
8991 | + if (h_inode) { | |
8992 | + h_mode = (h_inode->i_mode & S_IFMT); | |
8993 | + h_plus = (h_inode->i_nlink > 0); | |
8994 | + } | |
8995 | + if (inode && ibs <= bindex && bindex <= ibe) | |
8996 | + h_cached_inode = au_h_iptr(inode, bindex); | |
8997 | + | |
523b37e3 | 8998 | + if (!h_nfs) { |
38d290e6 | 8999 | + if (unlikely(plus != h_plus && !tmpfile)) |
523b37e3 AM |
9000 | + goto err; |
9001 | + } else { | |
9002 | + if (unlikely(!(h_dentry->d_flags & DCACHE_NFSFS_RENAMED) | |
9003 | + && !is_root | |
9004 | + && !IS_ROOT(h_dentry) | |
9005 | + && unhashed != d_unhashed(h_dentry))) | |
9006 | + goto err; | |
9007 | + } | |
9008 | + if (unlikely(mode != h_mode | |
1facf9fc | 9009 | + || h_cached_inode != h_inode)) |
9010 | + goto err; | |
9011 | + continue; | |
9012 | + | |
f6b6e03d | 9013 | +err: |
1facf9fc | 9014 | + err = -EINVAL; |
9015 | + break; | |
9016 | + } | |
9017 | + | |
523b37e3 | 9018 | + AuTraceErr(err); |
1facf9fc | 9019 | + return err; |
9020 | +} | |
9021 | + | |
027c5e7a | 9022 | +/* todo: consolidate with do_refresh() and au_reval_for_attr() */ |
1facf9fc | 9023 | +static int simple_reval_dpath(struct dentry *dentry, unsigned int sigen) |
9024 | +{ | |
9025 | + int err; | |
9026 | + struct dentry *parent; | |
1facf9fc | 9027 | + |
027c5e7a | 9028 | + if (!au_digen_test(dentry, sigen)) |
1facf9fc | 9029 | + return 0; |
9030 | + | |
9031 | + parent = dget_parent(dentry); | |
9032 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 9033 | + AuDebugOn(au_digen_test(parent, sigen)); |
1facf9fc | 9034 | + au_dbg_verify_gen(parent, sigen); |
027c5e7a | 9035 | + err = au_refresh_dentry(dentry, parent); |
1facf9fc | 9036 | + di_read_unlock(parent, AuLock_IR); |
9037 | + dput(parent); | |
027c5e7a | 9038 | + AuTraceErr(err); |
1facf9fc | 9039 | + return err; |
9040 | +} | |
9041 | + | |
9042 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen) | |
9043 | +{ | |
9044 | + int err; | |
9045 | + struct dentry *d, *parent; | |
1facf9fc | 9046 | + |
027c5e7a | 9047 | + if (!au_ftest_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR)) |
1facf9fc | 9048 | + return simple_reval_dpath(dentry, sigen); |
9049 | + | |
9050 | + /* slow loop, keep it simple and stupid */ | |
9051 | + /* cf: au_cpup_dirs() */ | |
9052 | + err = 0; | |
9053 | + parent = NULL; | |
027c5e7a | 9054 | + while (au_digen_test(dentry, sigen)) { |
1facf9fc | 9055 | + d = dentry; |
9056 | + while (1) { | |
9057 | + dput(parent); | |
9058 | + parent = dget_parent(d); | |
027c5e7a | 9059 | + if (!au_digen_test(parent, sigen)) |
1facf9fc | 9060 | + break; |
9061 | + d = parent; | |
9062 | + } | |
9063 | + | |
1facf9fc | 9064 | + if (d != dentry) |
027c5e7a | 9065 | + di_write_lock_child2(d); |
1facf9fc | 9066 | + |
9067 | + /* someone might update our dentry while we were sleeping */ | |
027c5e7a AM |
9068 | + if (au_digen_test(d, sigen)) { |
9069 | + /* | |
9070 | + * todo: consolidate with simple_reval_dpath(), | |
9071 | + * do_refresh() and au_reval_for_attr(). | |
9072 | + */ | |
1facf9fc | 9073 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a | 9074 | + err = au_refresh_dentry(d, parent); |
1facf9fc | 9075 | + di_read_unlock(parent, AuLock_IR); |
9076 | + } | |
9077 | + | |
9078 | + if (d != dentry) | |
9079 | + di_write_unlock(d); | |
9080 | + dput(parent); | |
9081 | + if (unlikely(err)) | |
9082 | + break; | |
9083 | + } | |
9084 | + | |
9085 | + return err; | |
9086 | +} | |
9087 | + | |
9088 | +/* | |
9089 | + * if valid returns 1, otherwise 0. | |
9090 | + */ | |
b4510431 | 9091 | +static int aufs_d_revalidate(struct dentry *dentry, unsigned int flags) |
1facf9fc | 9092 | +{ |
9093 | + int valid, err; | |
9094 | + unsigned int sigen; | |
8b6a4947 | 9095 | + unsigned char do_udba, dirren; |
1facf9fc | 9096 | + struct super_block *sb; |
9097 | + struct inode *inode; | |
9098 | + | |
027c5e7a | 9099 | + /* todo: support rcu-walk? */ |
b4510431 | 9100 | + if (flags & LOOKUP_RCU) |
027c5e7a AM |
9101 | + return -ECHILD; |
9102 | + | |
9103 | + valid = 0; | |
9104 | + if (unlikely(!au_di(dentry))) | |
9105 | + goto out; | |
9106 | + | |
e49829fe | 9107 | + valid = 1; |
1facf9fc | 9108 | + sb = dentry->d_sb; |
e49829fe JR |
9109 | + /* |
9110 | + * todo: very ugly | |
9111 | + * i_mutex of parent dir may be held, | |
9112 | + * but we should not return 'invalid' due to busy. | |
9113 | + */ | |
9114 | + err = aufs_read_lock(dentry, AuLock_FLUSH | AuLock_DW | AuLock_NOPLM); | |
9115 | + if (unlikely(err)) { | |
9116 | + valid = err; | |
027c5e7a | 9117 | + AuTraceErr(err); |
e49829fe JR |
9118 | + goto out; |
9119 | + } | |
5527c038 JR |
9120 | + inode = NULL; |
9121 | + if (d_really_is_positive(dentry)) | |
9122 | + inode = d_inode(dentry); | |
5afbbe0d | 9123 | + if (unlikely(inode && au_is_bad_inode(inode))) { |
c1595e42 JR |
9124 | + err = -EINVAL; |
9125 | + AuTraceErr(err); | |
9126 | + goto out_dgrade; | |
9127 | + } | |
027c5e7a AM |
9128 | + if (unlikely(au_dbrange_test(dentry))) { |
9129 | + err = -EINVAL; | |
9130 | + AuTraceErr(err); | |
9131 | + goto out_dgrade; | |
1facf9fc | 9132 | + } |
027c5e7a AM |
9133 | + |
9134 | + sigen = au_sigen(sb); | |
9135 | + if (au_digen_test(dentry, sigen)) { | |
1facf9fc | 9136 | + AuDebugOn(IS_ROOT(dentry)); |
027c5e7a AM |
9137 | + err = au_reval_dpath(dentry, sigen); |
9138 | + if (unlikely(err)) { | |
9139 | + AuTraceErr(err); | |
1facf9fc | 9140 | + goto out_dgrade; |
027c5e7a | 9141 | + } |
1facf9fc | 9142 | + } |
9143 | + di_downgrade_lock(dentry, AuLock_IR); | |
9144 | + | |
1facf9fc | 9145 | + err = -EINVAL; |
c1595e42 | 9146 | + if (!(flags & (LOOKUP_OPEN | LOOKUP_EMPTY)) |
523b37e3 | 9147 | + && inode |
38d290e6 | 9148 | + && !(inode->i_state && I_LINKABLE) |
79b8bda9 AM |
9149 | + && (IS_DEADDIR(inode) || !inode->i_nlink)) { |
9150 | + AuTraceErr(err); | |
027c5e7a | 9151 | + goto out_inval; |
79b8bda9 | 9152 | + } |
027c5e7a | 9153 | + |
1facf9fc | 9154 | + do_udba = !au_opt_test(au_mntflags(sb), UDBA_NONE); |
9155 | + if (do_udba && inode) { | |
5afbbe0d | 9156 | + aufs_bindex_t btop = au_ibtop(inode); |
027c5e7a | 9157 | + struct inode *h_inode; |
1facf9fc | 9158 | + |
5afbbe0d AM |
9159 | + if (btop >= 0) { |
9160 | + h_inode = au_h_iptr(inode, btop); | |
79b8bda9 AM |
9161 | + if (h_inode && au_test_higen(inode, h_inode)) { |
9162 | + AuTraceErr(err); | |
027c5e7a | 9163 | + goto out_inval; |
79b8bda9 | 9164 | + } |
027c5e7a | 9165 | + } |
1facf9fc | 9166 | + } |
9167 | + | |
8b6a4947 AM |
9168 | + dirren = !!au_opt_test(au_mntflags(sb), DIRREN); |
9169 | + err = h_d_revalidate(dentry, inode, flags, do_udba, dirren); | |
5afbbe0d | 9170 | + if (unlikely(!err && do_udba && au_dbtop(dentry) < 0)) { |
1facf9fc | 9171 | + err = -EIO; |
523b37e3 AM |
9172 | + AuDbg("both of real entry and whiteout found, %p, err %d\n", |
9173 | + dentry, err); | |
027c5e7a | 9174 | + } |
e49829fe | 9175 | + goto out_inval; |
1facf9fc | 9176 | + |
4f0767ce | 9177 | +out_dgrade: |
1facf9fc | 9178 | + di_downgrade_lock(dentry, AuLock_IR); |
e49829fe | 9179 | +out_inval: |
1facf9fc | 9180 | + aufs_read_unlock(dentry, AuLock_IR); |
9181 | + AuTraceErr(err); | |
9182 | + valid = !err; | |
e49829fe | 9183 | +out: |
027c5e7a | 9184 | + if (!valid) { |
523b37e3 | 9185 | + AuDbg("%pd invalid, %d\n", dentry, valid); |
027c5e7a AM |
9186 | + d_drop(dentry); |
9187 | + } | |
1facf9fc | 9188 | + return valid; |
9189 | +} | |
9190 | + | |
9191 | +static void aufs_d_release(struct dentry *dentry) | |
9192 | +{ | |
027c5e7a | 9193 | + if (au_di(dentry)) { |
4a4d8108 AM |
9194 | + au_di_fin(dentry); |
9195 | + au_hn_di_reinit(dentry); | |
1facf9fc | 9196 | + } |
1facf9fc | 9197 | +} |
9198 | + | |
4a4d8108 | 9199 | +const struct dentry_operations aufs_dop = { |
c06a8ce3 AM |
9200 | + .d_revalidate = aufs_d_revalidate, |
9201 | + .d_weak_revalidate = aufs_d_revalidate, | |
9202 | + .d_release = aufs_d_release | |
1facf9fc | 9203 | +}; |
79b8bda9 AM |
9204 | + |
9205 | +/* aufs_dop without d_revalidate */ | |
9206 | +const struct dentry_operations aufs_dop_noreval = { | |
9207 | + .d_release = aufs_d_release | |
9208 | +}; | |
7f207e10 | 9209 | diff -urN /usr/share/empty/fs/aufs/dentry.h linux/fs/aufs/dentry.h |
eca34b5c | 9210 | --- /usr/share/empty/fs/aufs/dentry.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 9211 | +++ linux/fs/aufs/dentry.h 2020-01-27 10:57:18.168871450 +0100 |
9f237c51 | 9212 | @@ -0,0 +1,268 @@ |
062440b3 | 9213 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 9214 | +/* |
d58c55f2 | 9215 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 9216 | + * |
9217 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9218 | + * it under the terms of the GNU General Public License as published by | |
9219 | + * the Free Software Foundation; either version 2 of the License, or | |
9220 | + * (at your option) any later version. | |
dece6358 AM |
9221 | + * |
9222 | + * This program is distributed in the hope that it will be useful, | |
9223 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9224 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9225 | + * GNU General Public License for more details. | |
9226 | + * | |
9227 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9228 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9229 | + */ |
9230 | + | |
9231 | +/* | |
9232 | + * lookup and dentry operations | |
9233 | + */ | |
9234 | + | |
9235 | +#ifndef __AUFS_DENTRY_H__ | |
9236 | +#define __AUFS_DENTRY_H__ | |
9237 | + | |
9238 | +#ifdef __KERNEL__ | |
9239 | + | |
dece6358 | 9240 | +#include <linux/dcache.h> |
8b6a4947 | 9241 | +#include "dirren.h" |
1facf9fc | 9242 | +#include "rwsem.h" |
9243 | + | |
1facf9fc | 9244 | +struct au_hdentry { |
9245 | + struct dentry *hd_dentry; | |
027c5e7a | 9246 | + aufs_bindex_t hd_id; |
1facf9fc | 9247 | +}; |
9248 | + | |
9249 | +struct au_dinfo { | |
9250 | + atomic_t di_generation; | |
9251 | + | |
dece6358 | 9252 | + struct au_rwsem di_rwsem; |
5afbbe0d | 9253 | + aufs_bindex_t di_btop, di_bbot, di_bwh, di_bdiropq; |
38d290e6 | 9254 | + unsigned char di_tmpfile; /* to allow the different name */ |
1c60b727 | 9255 | + struct au_hdentry *di_hdentry; |
9f237c51 | 9256 | + struct rcu_head rcu; |
4a4d8108 | 9257 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 9258 | + |
9259 | +/* ---------------------------------------------------------------------- */ | |
9260 | + | |
5afbbe0d AM |
9261 | +/* flags for au_lkup_dentry() */ |
9262 | +#define AuLkup_ALLOW_NEG 1 | |
9263 | +#define AuLkup_IGNORE_PERM (1 << 1) | |
8b6a4947 | 9264 | +#define AuLkup_DIRREN (1 << 2) |
5afbbe0d AM |
9265 | +#define au_ftest_lkup(flags, name) ((flags) & AuLkup_##name) |
9266 | +#define au_fset_lkup(flags, name) \ | |
9267 | + do { (flags) |= AuLkup_##name; } while (0) | |
9268 | +#define au_fclr_lkup(flags, name) \ | |
9269 | + do { (flags) &= ~AuLkup_##name; } while (0) | |
9270 | + | |
8b6a4947 AM |
9271 | +#ifndef CONFIG_AUFS_DIRREN |
9272 | +#undef AuLkup_DIRREN | |
9273 | +#define AuLkup_DIRREN 0 | |
9274 | +#endif | |
9275 | + | |
9276 | +struct au_do_lookup_args { | |
9277 | + unsigned int flags; | |
9278 | + mode_t type; | |
9279 | + struct qstr whname, *name; | |
9280 | + struct au_dr_lookup dirren; | |
9281 | +}; | |
9282 | + | |
5afbbe0d AM |
9283 | +/* ---------------------------------------------------------------------- */ |
9284 | + | |
1facf9fc | 9285 | +/* dentry.c */ |
79b8bda9 | 9286 | +extern const struct dentry_operations aufs_dop, aufs_dop_noreval; |
1facf9fc | 9287 | +struct au_branch; |
076b876e | 9288 | +struct dentry *au_sio_lkup_one(struct qstr *name, struct dentry *parent); |
1facf9fc | 9289 | +int au_h_verify(struct dentry *h_dentry, unsigned int udba, struct inode *h_dir, |
9290 | + struct dentry *h_parent, struct au_branch *br); | |
9291 | + | |
5afbbe0d AM |
9292 | +int au_lkup_dentry(struct dentry *dentry, aufs_bindex_t btop, |
9293 | + unsigned int flags); | |
86dc4139 | 9294 | +int au_lkup_neg(struct dentry *dentry, aufs_bindex_t bindex, int wh); |
027c5e7a | 9295 | +int au_refresh_dentry(struct dentry *dentry, struct dentry *parent); |
1facf9fc | 9296 | +int au_reval_dpath(struct dentry *dentry, unsigned int sigen); |
79b8bda9 | 9297 | +void au_refresh_dop(struct dentry *dentry, int force_reval); |
1facf9fc | 9298 | + |
9299 | +/* dinfo.c */ | |
4a4d8108 | 9300 | +void au_di_init_once(void *_di); |
027c5e7a AM |
9301 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc); |
9302 | +void au_di_free(struct au_dinfo *dinfo); | |
9303 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b); | |
9304 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src); | |
4a4d8108 AM |
9305 | +int au_di_init(struct dentry *dentry); |
9306 | +void au_di_fin(struct dentry *dentry); | |
e2f27e51 | 9307 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink); |
1facf9fc | 9308 | + |
9309 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc); | |
9310 | +void di_read_unlock(struct dentry *d, int flags); | |
9311 | +void di_downgrade_lock(struct dentry *d, int flags); | |
9312 | +void di_write_lock(struct dentry *d, unsigned int lsc); | |
9313 | +void di_write_unlock(struct dentry *d); | |
9314 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir); | |
9315 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir); | |
9316 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2); | |
9317 | + | |
9318 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex); | |
2cbb1c4b | 9319 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex); |
1facf9fc | 9320 | +aufs_bindex_t au_dbtail(struct dentry *dentry); |
9321 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry); | |
9322 | + | |
9323 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9324 | + struct dentry *h_dentry); | |
027c5e7a AM |
9325 | +int au_digen_test(struct dentry *dentry, unsigned int sigen); |
9326 | +int au_dbrange_test(struct dentry *dentry); | |
1facf9fc | 9327 | +void au_update_digen(struct dentry *dentry); |
9328 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero); | |
5afbbe0d AM |
9329 | +void au_update_dbtop(struct dentry *dentry); |
9330 | +void au_update_dbbot(struct dentry *dentry); | |
1facf9fc | 9331 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry); |
9332 | + | |
9333 | +/* ---------------------------------------------------------------------- */ | |
9334 | + | |
9335 | +static inline struct au_dinfo *au_di(struct dentry *dentry) | |
9336 | +{ | |
9337 | + return dentry->d_fsdata; | |
9338 | +} | |
9339 | + | |
9340 | +/* ---------------------------------------------------------------------- */ | |
9341 | + | |
9342 | +/* lock subclass for dinfo */ | |
9343 | +enum { | |
9344 | + AuLsc_DI_CHILD, /* child first */ | |
4a4d8108 | 9345 | + AuLsc_DI_CHILD2, /* rename(2), link(2), and cpup at hnotify */ |
1facf9fc | 9346 | + AuLsc_DI_CHILD3, /* copyup dirs */ |
9347 | + AuLsc_DI_PARENT, | |
9348 | + AuLsc_DI_PARENT2, | |
027c5e7a AM |
9349 | + AuLsc_DI_PARENT3, |
9350 | + AuLsc_DI_TMP /* temp for replacing dinfo */ | |
1facf9fc | 9351 | +}; |
9352 | + | |
9353 | +/* | |
9354 | + * di_read_lock_child, di_write_lock_child, | |
9355 | + * di_read_lock_child2, di_write_lock_child2, | |
9356 | + * di_read_lock_child3, di_write_lock_child3, | |
9357 | + * di_read_lock_parent, di_write_lock_parent, | |
9358 | + * di_read_lock_parent2, di_write_lock_parent2, | |
9359 | + * di_read_lock_parent3, di_write_lock_parent3, | |
9360 | + */ | |
9361 | +#define AuReadLockFunc(name, lsc) \ | |
9362 | +static inline void di_read_lock_##name(struct dentry *d, int flags) \ | |
9363 | +{ di_read_lock(d, flags, AuLsc_DI_##lsc); } | |
9364 | + | |
9365 | +#define AuWriteLockFunc(name, lsc) \ | |
9366 | +static inline void di_write_lock_##name(struct dentry *d) \ | |
9367 | +{ di_write_lock(d, AuLsc_DI_##lsc); } | |
9368 | + | |
9369 | +#define AuRWLockFuncs(name, lsc) \ | |
9370 | + AuReadLockFunc(name, lsc) \ | |
9371 | + AuWriteLockFunc(name, lsc) | |
9372 | + | |
9373 | +AuRWLockFuncs(child, CHILD); | |
9374 | +AuRWLockFuncs(child2, CHILD2); | |
9375 | +AuRWLockFuncs(child3, CHILD3); | |
9376 | +AuRWLockFuncs(parent, PARENT); | |
9377 | +AuRWLockFuncs(parent2, PARENT2); | |
9378 | +AuRWLockFuncs(parent3, PARENT3); | |
9379 | + | |
9380 | +#undef AuReadLockFunc | |
9381 | +#undef AuWriteLockFunc | |
9382 | +#undef AuRWLockFuncs | |
9383 | + | |
9384 | +#define DiMustNoWaiters(d) AuRwMustNoWaiters(&au_di(d)->di_rwsem) | |
dece6358 AM |
9385 | +#define DiMustAnyLock(d) AuRwMustAnyLock(&au_di(d)->di_rwsem) |
9386 | +#define DiMustWriteLock(d) AuRwMustWriteLock(&au_di(d)->di_rwsem) | |
1facf9fc | 9387 | + |
9388 | +/* ---------------------------------------------------------------------- */ | |
9389 | + | |
9390 | +/* todo: memory barrier? */ | |
9391 | +static inline unsigned int au_digen(struct dentry *d) | |
9392 | +{ | |
9393 | + return atomic_read(&au_di(d)->di_generation); | |
9394 | +} | |
9395 | + | |
9396 | +static inline void au_h_dentry_init(struct au_hdentry *hdentry) | |
9397 | +{ | |
9398 | + hdentry->hd_dentry = NULL; | |
9399 | +} | |
9400 | + | |
5afbbe0d AM |
9401 | +static inline struct au_hdentry *au_hdentry(struct au_dinfo *di, |
9402 | + aufs_bindex_t bindex) | |
9403 | +{ | |
9404 | + return di->di_hdentry + bindex; | |
9405 | +} | |
9406 | + | |
1facf9fc | 9407 | +static inline void au_hdput(struct au_hdentry *hd) |
9408 | +{ | |
4a4d8108 AM |
9409 | + if (hd) |
9410 | + dput(hd->hd_dentry); | |
1facf9fc | 9411 | +} |
9412 | + | |
5afbbe0d | 9413 | +static inline aufs_bindex_t au_dbtop(struct dentry *dentry) |
1facf9fc | 9414 | +{ |
1308ab2a | 9415 | + DiMustAnyLock(dentry); |
5afbbe0d | 9416 | + return au_di(dentry)->di_btop; |
1facf9fc | 9417 | +} |
9418 | + | |
5afbbe0d | 9419 | +static inline aufs_bindex_t au_dbbot(struct dentry *dentry) |
1facf9fc | 9420 | +{ |
1308ab2a | 9421 | + DiMustAnyLock(dentry); |
5afbbe0d | 9422 | + return au_di(dentry)->di_bbot; |
1facf9fc | 9423 | +} |
9424 | + | |
9425 | +static inline aufs_bindex_t au_dbwh(struct dentry *dentry) | |
9426 | +{ | |
1308ab2a | 9427 | + DiMustAnyLock(dentry); |
1facf9fc | 9428 | + return au_di(dentry)->di_bwh; |
9429 | +} | |
9430 | + | |
9431 | +static inline aufs_bindex_t au_dbdiropq(struct dentry *dentry) | |
9432 | +{ | |
1308ab2a | 9433 | + DiMustAnyLock(dentry); |
1facf9fc | 9434 | + return au_di(dentry)->di_bdiropq; |
9435 | +} | |
9436 | + | |
9437 | +/* todo: hard/soft set? */ | |
5afbbe0d | 9438 | +static inline void au_set_dbtop(struct dentry *dentry, aufs_bindex_t bindex) |
1facf9fc | 9439 | +{ |
1308ab2a | 9440 | + DiMustWriteLock(dentry); |
5afbbe0d | 9441 | + au_di(dentry)->di_btop = bindex; |
1facf9fc | 9442 | +} |
9443 | + | |
5afbbe0d | 9444 | +static inline void au_set_dbbot(struct dentry *dentry, aufs_bindex_t bindex) |
1facf9fc | 9445 | +{ |
1308ab2a | 9446 | + DiMustWriteLock(dentry); |
5afbbe0d | 9447 | + au_di(dentry)->di_bbot = bindex; |
1facf9fc | 9448 | +} |
9449 | + | |
9450 | +static inline void au_set_dbwh(struct dentry *dentry, aufs_bindex_t bindex) | |
9451 | +{ | |
1308ab2a | 9452 | + DiMustWriteLock(dentry); |
5afbbe0d | 9453 | + /* dbwh can be outside of btop - bbot range */ |
1facf9fc | 9454 | + au_di(dentry)->di_bwh = bindex; |
9455 | +} | |
9456 | + | |
9457 | +static inline void au_set_dbdiropq(struct dentry *dentry, aufs_bindex_t bindex) | |
9458 | +{ | |
1308ab2a | 9459 | + DiMustWriteLock(dentry); |
1facf9fc | 9460 | + au_di(dentry)->di_bdiropq = bindex; |
9461 | +} | |
9462 | + | |
9463 | +/* ---------------------------------------------------------------------- */ | |
9464 | + | |
4a4d8108 | 9465 | +#ifdef CONFIG_AUFS_HNOTIFY |
1facf9fc | 9466 | +static inline void au_digen_dec(struct dentry *d) |
9467 | +{ | |
e49829fe | 9468 | + atomic_dec(&au_di(d)->di_generation); |
1facf9fc | 9469 | +} |
9470 | + | |
4a4d8108 | 9471 | +static inline void au_hn_di_reinit(struct dentry *dentry) |
1facf9fc | 9472 | +{ |
9473 | + dentry->d_fsdata = NULL; | |
9474 | +} | |
9475 | +#else | |
4a4d8108 AM |
9476 | +AuStubVoid(au_hn_di_reinit, struct dentry *dentry __maybe_unused) |
9477 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
1facf9fc | 9478 | + |
9479 | +#endif /* __KERNEL__ */ | |
9480 | +#endif /* __AUFS_DENTRY_H__ */ | |
7f207e10 | 9481 | diff -urN /usr/share/empty/fs/aufs/dinfo.c linux/fs/aufs/dinfo.c |
eca34b5c | 9482 | --- /usr/share/empty/fs/aufs/dinfo.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 9483 | +++ linux/fs/aufs/dinfo.c 2020-01-27 10:57:18.168871450 +0100 |
062440b3 | 9484 | @@ -0,0 +1,554 @@ |
cd7a4cd9 | 9485 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 9486 | +/* |
d58c55f2 | 9487 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 9488 | + * |
9489 | + * This program, aufs is free software; you can redistribute it and/or modify | |
9490 | + * it under the terms of the GNU General Public License as published by | |
9491 | + * the Free Software Foundation; either version 2 of the License, or | |
9492 | + * (at your option) any later version. | |
dece6358 AM |
9493 | + * |
9494 | + * This program is distributed in the hope that it will be useful, | |
9495 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9496 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
9497 | + * GNU General Public License for more details. | |
9498 | + * | |
9499 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 9500 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 9501 | + */ |
9502 | + | |
9503 | +/* | |
9504 | + * dentry private data | |
9505 | + */ | |
9506 | + | |
9507 | +#include "aufs.h" | |
9508 | + | |
e49829fe | 9509 | +void au_di_init_once(void *_dinfo) |
4a4d8108 | 9510 | +{ |
e49829fe | 9511 | + struct au_dinfo *dinfo = _dinfo; |
4a4d8108 | 9512 | + |
e49829fe | 9513 | + au_rw_init(&dinfo->di_rwsem); |
4a4d8108 AM |
9514 | +} |
9515 | + | |
027c5e7a | 9516 | +struct au_dinfo *au_di_alloc(struct super_block *sb, unsigned int lsc) |
1facf9fc | 9517 | +{ |
9518 | + struct au_dinfo *dinfo; | |
027c5e7a | 9519 | + int nbr, i; |
1facf9fc | 9520 | + |
9521 | + dinfo = au_cache_alloc_dinfo(); | |
9522 | + if (unlikely(!dinfo)) | |
9523 | + goto out; | |
9524 | + | |
5afbbe0d | 9525 | + nbr = au_sbbot(sb) + 1; |
1facf9fc | 9526 | + if (nbr <= 0) |
9527 | + nbr = 1; | |
9528 | + dinfo->di_hdentry = kcalloc(nbr, sizeof(*dinfo->di_hdentry), GFP_NOFS); | |
027c5e7a AM |
9529 | + if (dinfo->di_hdentry) { |
9530 | + au_rw_write_lock_nested(&dinfo->di_rwsem, lsc); | |
5afbbe0d AM |
9531 | + dinfo->di_btop = -1; |
9532 | + dinfo->di_bbot = -1; | |
027c5e7a AM |
9533 | + dinfo->di_bwh = -1; |
9534 | + dinfo->di_bdiropq = -1; | |
38d290e6 | 9535 | + dinfo->di_tmpfile = 0; |
027c5e7a AM |
9536 | + for (i = 0; i < nbr; i++) |
9537 | + dinfo->di_hdentry[i].hd_id = -1; | |
9538 | + goto out; | |
9539 | + } | |
1facf9fc | 9540 | + |
1c60b727 | 9541 | + au_cache_free_dinfo(dinfo); |
027c5e7a AM |
9542 | + dinfo = NULL; |
9543 | + | |
4f0767ce | 9544 | +out: |
027c5e7a | 9545 | + return dinfo; |
1facf9fc | 9546 | +} |
9547 | + | |
027c5e7a | 9548 | +void au_di_free(struct au_dinfo *dinfo) |
4a4d8108 | 9549 | +{ |
4a4d8108 | 9550 | + struct au_hdentry *p; |
5afbbe0d | 9551 | + aufs_bindex_t bbot, bindex; |
4a4d8108 AM |
9552 | + |
9553 | + /* dentry may not be revalidated */ | |
5afbbe0d | 9554 | + bindex = dinfo->di_btop; |
4a4d8108 | 9555 | + if (bindex >= 0) { |
5afbbe0d AM |
9556 | + bbot = dinfo->di_bbot; |
9557 | + p = au_hdentry(dinfo, bindex); | |
9558 | + while (bindex++ <= bbot) | |
4a4d8108 AM |
9559 | + au_hdput(p++); |
9560 | + } | |
9f237c51 | 9561 | + au_kfree_try_rcu(dinfo->di_hdentry); |
1c60b727 | 9562 | + au_cache_free_dinfo(dinfo); |
027c5e7a AM |
9563 | +} |
9564 | + | |
9565 | +void au_di_swap(struct au_dinfo *a, struct au_dinfo *b) | |
9566 | +{ | |
9567 | + struct au_hdentry *p; | |
9568 | + aufs_bindex_t bi; | |
9569 | + | |
9570 | + AuRwMustWriteLock(&a->di_rwsem); | |
9571 | + AuRwMustWriteLock(&b->di_rwsem); | |
9572 | + | |
9573 | +#define DiSwap(v, name) \ | |
9574 | + do { \ | |
9575 | + v = a->di_##name; \ | |
9576 | + a->di_##name = b->di_##name; \ | |
9577 | + b->di_##name = v; \ | |
9578 | + } while (0) | |
9579 | + | |
9580 | + DiSwap(p, hdentry); | |
5afbbe0d AM |
9581 | + DiSwap(bi, btop); |
9582 | + DiSwap(bi, bbot); | |
027c5e7a AM |
9583 | + DiSwap(bi, bwh); |
9584 | + DiSwap(bi, bdiropq); | |
9585 | + /* smp_mb(); */ | |
9586 | + | |
9587 | +#undef DiSwap | |
9588 | +} | |
9589 | + | |
9590 | +void au_di_cp(struct au_dinfo *dst, struct au_dinfo *src) | |
9591 | +{ | |
9592 | + AuRwMustWriteLock(&dst->di_rwsem); | |
9593 | + AuRwMustWriteLock(&src->di_rwsem); | |
9594 | + | |
5afbbe0d AM |
9595 | + dst->di_btop = src->di_btop; |
9596 | + dst->di_bbot = src->di_bbot; | |
027c5e7a AM |
9597 | + dst->di_bwh = src->di_bwh; |
9598 | + dst->di_bdiropq = src->di_bdiropq; | |
9599 | + /* smp_mb(); */ | |
9600 | +} | |
9601 | + | |
9602 | +int au_di_init(struct dentry *dentry) | |
9603 | +{ | |
9604 | + int err; | |
9605 | + struct super_block *sb; | |
9606 | + struct au_dinfo *dinfo; | |
9607 | + | |
9608 | + err = 0; | |
9609 | + sb = dentry->d_sb; | |
9610 | + dinfo = au_di_alloc(sb, AuLsc_DI_CHILD); | |
9611 | + if (dinfo) { | |
9612 | + atomic_set(&dinfo->di_generation, au_sigen(sb)); | |
9613 | + /* smp_mb(); */ /* atomic_set */ | |
9614 | + dentry->d_fsdata = dinfo; | |
9615 | + } else | |
9616 | + err = -ENOMEM; | |
9617 | + | |
9618 | + return err; | |
9619 | +} | |
9620 | + | |
9621 | +void au_di_fin(struct dentry *dentry) | |
9622 | +{ | |
9623 | + struct au_dinfo *dinfo; | |
9624 | + | |
9625 | + dinfo = au_di(dentry); | |
9626 | + AuRwDestroy(&dinfo->di_rwsem); | |
9627 | + au_di_free(dinfo); | |
4a4d8108 AM |
9628 | +} |
9629 | + | |
e2f27e51 | 9630 | +int au_di_realloc(struct au_dinfo *dinfo, int nbr, int may_shrink) |
1facf9fc | 9631 | +{ |
9632 | + int err, sz; | |
9633 | + struct au_hdentry *hdp; | |
9634 | + | |
1308ab2a | 9635 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
9636 | + | |
1facf9fc | 9637 | + err = -ENOMEM; |
5afbbe0d | 9638 | + sz = sizeof(*hdp) * (dinfo->di_bbot + 1); |
1facf9fc | 9639 | + if (!sz) |
9640 | + sz = sizeof(*hdp); | |
e2f27e51 AM |
9641 | + hdp = au_kzrealloc(dinfo->di_hdentry, sz, sizeof(*hdp) * nbr, GFP_NOFS, |
9642 | + may_shrink); | |
1facf9fc | 9643 | + if (hdp) { |
9644 | + dinfo->di_hdentry = hdp; | |
9645 | + err = 0; | |
9646 | + } | |
9647 | + | |
9648 | + return err; | |
9649 | +} | |
9650 | + | |
9651 | +/* ---------------------------------------------------------------------- */ | |
9652 | + | |
9653 | +static void do_ii_write_lock(struct inode *inode, unsigned int lsc) | |
9654 | +{ | |
9655 | + switch (lsc) { | |
9656 | + case AuLsc_DI_CHILD: | |
9657 | + ii_write_lock_child(inode); | |
9658 | + break; | |
9659 | + case AuLsc_DI_CHILD2: | |
9660 | + ii_write_lock_child2(inode); | |
9661 | + break; | |
9662 | + case AuLsc_DI_CHILD3: | |
9663 | + ii_write_lock_child3(inode); | |
9664 | + break; | |
9665 | + case AuLsc_DI_PARENT: | |
9666 | + ii_write_lock_parent(inode); | |
9667 | + break; | |
9668 | + case AuLsc_DI_PARENT2: | |
9669 | + ii_write_lock_parent2(inode); | |
9670 | + break; | |
9671 | + case AuLsc_DI_PARENT3: | |
9672 | + ii_write_lock_parent3(inode); | |
9673 | + break; | |
9674 | + default: | |
9675 | + BUG(); | |
9676 | + } | |
9677 | +} | |
9678 | + | |
9679 | +static void do_ii_read_lock(struct inode *inode, unsigned int lsc) | |
9680 | +{ | |
9681 | + switch (lsc) { | |
9682 | + case AuLsc_DI_CHILD: | |
9683 | + ii_read_lock_child(inode); | |
9684 | + break; | |
9685 | + case AuLsc_DI_CHILD2: | |
9686 | + ii_read_lock_child2(inode); | |
9687 | + break; | |
9688 | + case AuLsc_DI_CHILD3: | |
9689 | + ii_read_lock_child3(inode); | |
9690 | + break; | |
9691 | + case AuLsc_DI_PARENT: | |
9692 | + ii_read_lock_parent(inode); | |
9693 | + break; | |
9694 | + case AuLsc_DI_PARENT2: | |
9695 | + ii_read_lock_parent2(inode); | |
9696 | + break; | |
9697 | + case AuLsc_DI_PARENT3: | |
9698 | + ii_read_lock_parent3(inode); | |
9699 | + break; | |
9700 | + default: | |
9701 | + BUG(); | |
9702 | + } | |
9703 | +} | |
9704 | + | |
9705 | +void di_read_lock(struct dentry *d, int flags, unsigned int lsc) | |
9706 | +{ | |
5527c038 JR |
9707 | + struct inode *inode; |
9708 | + | |
dece6358 | 9709 | + au_rw_read_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9710 | + if (d_really_is_positive(d)) { |
9711 | + inode = d_inode(d); | |
1facf9fc | 9712 | + if (au_ftest_lock(flags, IW)) |
5527c038 | 9713 | + do_ii_write_lock(inode, lsc); |
1facf9fc | 9714 | + else if (au_ftest_lock(flags, IR)) |
5527c038 | 9715 | + do_ii_read_lock(inode, lsc); |
1facf9fc | 9716 | + } |
9717 | +} | |
9718 | + | |
9719 | +void di_read_unlock(struct dentry *d, int flags) | |
9720 | +{ | |
5527c038 JR |
9721 | + struct inode *inode; |
9722 | + | |
9723 | + if (d_really_is_positive(d)) { | |
9724 | + inode = d_inode(d); | |
027c5e7a AM |
9725 | + if (au_ftest_lock(flags, IW)) { |
9726 | + au_dbg_verify_dinode(d); | |
5527c038 | 9727 | + ii_write_unlock(inode); |
027c5e7a AM |
9728 | + } else if (au_ftest_lock(flags, IR)) { |
9729 | + au_dbg_verify_dinode(d); | |
5527c038 | 9730 | + ii_read_unlock(inode); |
027c5e7a | 9731 | + } |
1facf9fc | 9732 | + } |
dece6358 | 9733 | + au_rw_read_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9734 | +} |
9735 | + | |
9736 | +void di_downgrade_lock(struct dentry *d, int flags) | |
9737 | +{ | |
5527c038 JR |
9738 | + if (d_really_is_positive(d) && au_ftest_lock(flags, IR)) |
9739 | + ii_downgrade_lock(d_inode(d)); | |
dece6358 | 9740 | + au_rw_dgrade_lock(&au_di(d)->di_rwsem); |
1facf9fc | 9741 | +} |
9742 | + | |
9743 | +void di_write_lock(struct dentry *d, unsigned int lsc) | |
9744 | +{ | |
dece6358 | 9745 | + au_rw_write_lock_nested(&au_di(d)->di_rwsem, lsc); |
5527c038 JR |
9746 | + if (d_really_is_positive(d)) |
9747 | + do_ii_write_lock(d_inode(d), lsc); | |
1facf9fc | 9748 | +} |
9749 | + | |
9750 | +void di_write_unlock(struct dentry *d) | |
9751 | +{ | |
027c5e7a | 9752 | + au_dbg_verify_dinode(d); |
5527c038 JR |
9753 | + if (d_really_is_positive(d)) |
9754 | + ii_write_unlock(d_inode(d)); | |
dece6358 | 9755 | + au_rw_write_unlock(&au_di(d)->di_rwsem); |
1facf9fc | 9756 | +} |
9757 | + | |
9758 | +void di_write_lock2_child(struct dentry *d1, struct dentry *d2, int isdir) | |
9759 | +{ | |
9760 | + AuDebugOn(d1 == d2 | |
5527c038 | 9761 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9762 | + || d1->d_sb != d2->d_sb); |
9763 | + | |
521ced18 JR |
9764 | + if ((isdir && au_test_subdir(d1, d2)) |
9765 | + || d1 < d2) { | |
1facf9fc | 9766 | + di_write_lock_child(d1); |
9767 | + di_write_lock_child2(d2); | |
9768 | + } else { | |
1facf9fc | 9769 | + di_write_lock_child(d2); |
9770 | + di_write_lock_child2(d1); | |
9771 | + } | |
9772 | +} | |
9773 | + | |
9774 | +void di_write_lock2_parent(struct dentry *d1, struct dentry *d2, int isdir) | |
9775 | +{ | |
9776 | + AuDebugOn(d1 == d2 | |
5527c038 | 9777 | + || d_inode(d1) == d_inode(d2) |
1facf9fc | 9778 | + || d1->d_sb != d2->d_sb); |
9779 | + | |
521ced18 JR |
9780 | + if ((isdir && au_test_subdir(d1, d2)) |
9781 | + || d1 < d2) { | |
1facf9fc | 9782 | + di_write_lock_parent(d1); |
9783 | + di_write_lock_parent2(d2); | |
9784 | + } else { | |
1facf9fc | 9785 | + di_write_lock_parent(d2); |
9786 | + di_write_lock_parent2(d1); | |
9787 | + } | |
9788 | +} | |
9789 | + | |
9790 | +void di_write_unlock2(struct dentry *d1, struct dentry *d2) | |
9791 | +{ | |
9792 | + di_write_unlock(d1); | |
5527c038 | 9793 | + if (d_inode(d1) == d_inode(d2)) |
dece6358 | 9794 | + au_rw_write_unlock(&au_di(d2)->di_rwsem); |
1facf9fc | 9795 | + else |
9796 | + di_write_unlock(d2); | |
9797 | +} | |
9798 | + | |
9799 | +/* ---------------------------------------------------------------------- */ | |
9800 | + | |
9801 | +struct dentry *au_h_dptr(struct dentry *dentry, aufs_bindex_t bindex) | |
9802 | +{ | |
9803 | + struct dentry *d; | |
9804 | + | |
1308ab2a | 9805 | + DiMustAnyLock(dentry); |
9806 | + | |
5afbbe0d | 9807 | + if (au_dbtop(dentry) < 0 || bindex < au_dbtop(dentry)) |
1facf9fc | 9808 | + return NULL; |
9809 | + AuDebugOn(bindex < 0); | |
5afbbe0d | 9810 | + d = au_hdentry(au_di(dentry), bindex)->hd_dentry; |
c1595e42 | 9811 | + AuDebugOn(d && au_dcount(d) <= 0); |
1facf9fc | 9812 | + return d; |
9813 | +} | |
9814 | + | |
2cbb1c4b JR |
9815 | +/* |
9816 | + * extended version of au_h_dptr(). | |
38d290e6 JR |
9817 | + * returns a hashed and positive (or linkable) h_dentry in bindex, NULL, or |
9818 | + * error. | |
2cbb1c4b JR |
9819 | + */ |
9820 | +struct dentry *au_h_d_alias(struct dentry *dentry, aufs_bindex_t bindex) | |
9821 | +{ | |
9822 | + struct dentry *h_dentry; | |
9823 | + struct inode *inode, *h_inode; | |
9824 | + | |
5527c038 | 9825 | + AuDebugOn(d_really_is_negative(dentry)); |
2cbb1c4b JR |
9826 | + |
9827 | + h_dentry = NULL; | |
5afbbe0d AM |
9828 | + if (au_dbtop(dentry) <= bindex |
9829 | + && bindex <= au_dbbot(dentry)) | |
2cbb1c4b | 9830 | + h_dentry = au_h_dptr(dentry, bindex); |
38d290e6 | 9831 | + if (h_dentry && !au_d_linkable(h_dentry)) { |
2cbb1c4b JR |
9832 | + dget(h_dentry); |
9833 | + goto out; /* success */ | |
9834 | + } | |
9835 | + | |
5527c038 | 9836 | + inode = d_inode(dentry); |
5afbbe0d AM |
9837 | + AuDebugOn(bindex < au_ibtop(inode)); |
9838 | + AuDebugOn(au_ibbot(inode) < bindex); | |
2cbb1c4b JR |
9839 | + h_inode = au_h_iptr(inode, bindex); |
9840 | + h_dentry = d_find_alias(h_inode); | |
9841 | + if (h_dentry) { | |
9842 | + if (!IS_ERR(h_dentry)) { | |
38d290e6 | 9843 | + if (!au_d_linkable(h_dentry)) |
2cbb1c4b JR |
9844 | + goto out; /* success */ |
9845 | + dput(h_dentry); | |
9846 | + } else | |
9847 | + goto out; | |
9848 | + } | |
9849 | + | |
9850 | + if (au_opt_test(au_mntflags(dentry->d_sb), PLINK)) { | |
9851 | + h_dentry = au_plink_lkup(inode, bindex); | |
9852 | + AuDebugOn(!h_dentry); | |
9853 | + if (!IS_ERR(h_dentry)) { | |
9854 | + if (!au_d_hashed_positive(h_dentry)) | |
9855 | + goto out; /* success */ | |
9856 | + dput(h_dentry); | |
9857 | + h_dentry = NULL; | |
9858 | + } | |
9859 | + } | |
9860 | + | |
9861 | +out: | |
9862 | + AuDbgDentry(h_dentry); | |
9863 | + return h_dentry; | |
9864 | +} | |
9865 | + | |
1facf9fc | 9866 | +aufs_bindex_t au_dbtail(struct dentry *dentry) |
9867 | +{ | |
5afbbe0d | 9868 | + aufs_bindex_t bbot, bwh; |
1facf9fc | 9869 | + |
5afbbe0d AM |
9870 | + bbot = au_dbbot(dentry); |
9871 | + if (0 <= bbot) { | |
1facf9fc | 9872 | + bwh = au_dbwh(dentry); |
9873 | + if (!bwh) | |
9874 | + return bwh; | |
5afbbe0d | 9875 | + if (0 < bwh && bwh < bbot) |
1facf9fc | 9876 | + return bwh - 1; |
9877 | + } | |
5afbbe0d | 9878 | + return bbot; |
1facf9fc | 9879 | +} |
9880 | + | |
9881 | +aufs_bindex_t au_dbtaildir(struct dentry *dentry) | |
9882 | +{ | |
5afbbe0d | 9883 | + aufs_bindex_t bbot, bopq; |
1facf9fc | 9884 | + |
5afbbe0d AM |
9885 | + bbot = au_dbtail(dentry); |
9886 | + if (0 <= bbot) { | |
1facf9fc | 9887 | + bopq = au_dbdiropq(dentry); |
5afbbe0d AM |
9888 | + if (0 <= bopq && bopq < bbot) |
9889 | + bbot = bopq; | |
1facf9fc | 9890 | + } |
5afbbe0d | 9891 | + return bbot; |
1facf9fc | 9892 | +} |
9893 | + | |
9894 | +/* ---------------------------------------------------------------------- */ | |
9895 | + | |
9896 | +void au_set_h_dptr(struct dentry *dentry, aufs_bindex_t bindex, | |
9897 | + struct dentry *h_dentry) | |
9898 | +{ | |
5afbbe0d AM |
9899 | + struct au_dinfo *dinfo; |
9900 | + struct au_hdentry *hd; | |
027c5e7a | 9901 | + struct au_branch *br; |
1facf9fc | 9902 | + |
1308ab2a | 9903 | + DiMustWriteLock(dentry); |
9904 | + | |
5afbbe0d AM |
9905 | + dinfo = au_di(dentry); |
9906 | + hd = au_hdentry(dinfo, bindex); | |
4a4d8108 | 9907 | + au_hdput(hd); |
1facf9fc | 9908 | + hd->hd_dentry = h_dentry; |
027c5e7a AM |
9909 | + if (h_dentry) { |
9910 | + br = au_sbr(dentry->d_sb, bindex); | |
9911 | + hd->hd_id = br->br_id; | |
9912 | + } | |
9913 | +} | |
9914 | + | |
9915 | +int au_dbrange_test(struct dentry *dentry) | |
9916 | +{ | |
9917 | + int err; | |
5afbbe0d | 9918 | + aufs_bindex_t btop, bbot; |
027c5e7a AM |
9919 | + |
9920 | + err = 0; | |
5afbbe0d AM |
9921 | + btop = au_dbtop(dentry); |
9922 | + bbot = au_dbbot(dentry); | |
9923 | + if (btop >= 0) | |
9924 | + AuDebugOn(bbot < 0 && btop > bbot); | |
027c5e7a AM |
9925 | + else { |
9926 | + err = -EIO; | |
5afbbe0d | 9927 | + AuDebugOn(bbot >= 0); |
027c5e7a AM |
9928 | + } |
9929 | + | |
9930 | + return err; | |
9931 | +} | |
9932 | + | |
9933 | +int au_digen_test(struct dentry *dentry, unsigned int sigen) | |
9934 | +{ | |
9935 | + int err; | |
9936 | + | |
9937 | + err = 0; | |
9938 | + if (unlikely(au_digen(dentry) != sigen | |
5527c038 | 9939 | + || au_iigen_test(d_inode(dentry), sigen))) |
027c5e7a AM |
9940 | + err = -EIO; |
9941 | + | |
9942 | + return err; | |
1facf9fc | 9943 | +} |
9944 | + | |
9945 | +void au_update_digen(struct dentry *dentry) | |
9946 | +{ | |
9947 | + atomic_set(&au_di(dentry)->di_generation, au_sigen(dentry->d_sb)); | |
9948 | + /* smp_mb(); */ /* atomic_set */ | |
9949 | +} | |
9950 | + | |
9951 | +void au_update_dbrange(struct dentry *dentry, int do_put_zero) | |
9952 | +{ | |
9953 | + struct au_dinfo *dinfo; | |
9954 | + struct dentry *h_d; | |
4a4d8108 | 9955 | + struct au_hdentry *hdp; |
5afbbe0d | 9956 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9957 | + |
1308ab2a | 9958 | + DiMustWriteLock(dentry); |
9959 | + | |
1facf9fc | 9960 | + dinfo = au_di(dentry); |
5afbbe0d | 9961 | + if (!dinfo || dinfo->di_btop < 0) |
1facf9fc | 9962 | + return; |
9963 | + | |
9964 | + if (do_put_zero) { | |
5afbbe0d AM |
9965 | + bbot = dinfo->di_bbot; |
9966 | + bindex = dinfo->di_btop; | |
9967 | + hdp = au_hdentry(dinfo, bindex); | |
9968 | + for (; bindex <= bbot; bindex++, hdp++) { | |
9969 | + h_d = hdp->hd_dentry; | |
5527c038 | 9970 | + if (h_d && d_is_negative(h_d)) |
1facf9fc | 9971 | + au_set_h_dptr(dentry, bindex, NULL); |
9972 | + } | |
9973 | + } | |
9974 | + | |
5afbbe0d AM |
9975 | + dinfo->di_btop = 0; |
9976 | + hdp = au_hdentry(dinfo, dinfo->di_btop); | |
9977 | + for (; dinfo->di_btop <= dinfo->di_bbot; dinfo->di_btop++, hdp++) | |
9978 | + if (hdp->hd_dentry) | |
1facf9fc | 9979 | + break; |
5afbbe0d AM |
9980 | + if (dinfo->di_btop > dinfo->di_bbot) { |
9981 | + dinfo->di_btop = -1; | |
9982 | + dinfo->di_bbot = -1; | |
1facf9fc | 9983 | + return; |
9984 | + } | |
9985 | + | |
5afbbe0d AM |
9986 | + hdp = au_hdentry(dinfo, dinfo->di_bbot); |
9987 | + for (; dinfo->di_bbot >= 0; dinfo->di_bbot--, hdp--) | |
9988 | + if (hdp->hd_dentry) | |
1facf9fc | 9989 | + break; |
5afbbe0d | 9990 | + AuDebugOn(dinfo->di_btop > dinfo->di_bbot || dinfo->di_bbot < 0); |
1facf9fc | 9991 | +} |
9992 | + | |
5afbbe0d | 9993 | +void au_update_dbtop(struct dentry *dentry) |
1facf9fc | 9994 | +{ |
5afbbe0d | 9995 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 9996 | + struct dentry *h_dentry; |
9997 | + | |
5afbbe0d AM |
9998 | + bbot = au_dbbot(dentry); |
9999 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) { | |
1facf9fc | 10000 | + h_dentry = au_h_dptr(dentry, bindex); |
10001 | + if (!h_dentry) | |
10002 | + continue; | |
5527c038 | 10003 | + if (d_is_positive(h_dentry)) { |
5afbbe0d | 10004 | + au_set_dbtop(dentry, bindex); |
1facf9fc | 10005 | + return; |
10006 | + } | |
10007 | + au_set_h_dptr(dentry, bindex, NULL); | |
10008 | + } | |
10009 | +} | |
10010 | + | |
5afbbe0d | 10011 | +void au_update_dbbot(struct dentry *dentry) |
1facf9fc | 10012 | +{ |
5afbbe0d | 10013 | + aufs_bindex_t bindex, btop; |
1facf9fc | 10014 | + struct dentry *h_dentry; |
10015 | + | |
5afbbe0d AM |
10016 | + btop = au_dbtop(dentry); |
10017 | + for (bindex = au_dbbot(dentry); bindex >= btop; bindex--) { | |
1facf9fc | 10018 | + h_dentry = au_h_dptr(dentry, bindex); |
10019 | + if (!h_dentry) | |
10020 | + continue; | |
5527c038 | 10021 | + if (d_is_positive(h_dentry)) { |
5afbbe0d | 10022 | + au_set_dbbot(dentry, bindex); |
1facf9fc | 10023 | + return; |
10024 | + } | |
10025 | + au_set_h_dptr(dentry, bindex, NULL); | |
10026 | + } | |
10027 | +} | |
10028 | + | |
10029 | +int au_find_dbindex(struct dentry *dentry, struct dentry *h_dentry) | |
10030 | +{ | |
5afbbe0d | 10031 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 10032 | + |
5afbbe0d AM |
10033 | + bbot = au_dbbot(dentry); |
10034 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) | |
1facf9fc | 10035 | + if (au_h_dptr(dentry, bindex) == h_dentry) |
10036 | + return bindex; | |
10037 | + return -1; | |
10038 | +} | |
7f207e10 | 10039 | diff -urN /usr/share/empty/fs/aufs/dir.c linux/fs/aufs/dir.c |
eca34b5c | 10040 | --- /usr/share/empty/fs/aufs/dir.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 10041 | +++ linux/fs/aufs/dir.c 2020-01-27 10:57:18.168871450 +0100 |
eca801bf | 10042 | @@ -0,0 +1,763 @@ |
cd7a4cd9 | 10043 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 10044 | +/* |
d58c55f2 | 10045 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 10046 | + * |
10047 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10048 | + * it under the terms of the GNU General Public License as published by | |
10049 | + * the Free Software Foundation; either version 2 of the License, or | |
10050 | + * (at your option) any later version. | |
dece6358 AM |
10051 | + * |
10052 | + * This program is distributed in the hope that it will be useful, | |
10053 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10054 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10055 | + * GNU General Public License for more details. | |
10056 | + * | |
10057 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10058 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10059 | + */ |
10060 | + | |
10061 | +/* | |
10062 | + * directory operations | |
10063 | + */ | |
10064 | + | |
10065 | +#include <linux/fs_stack.h> | |
eca801bf | 10066 | +#include <linux/iversion.h> |
1facf9fc | 10067 | +#include "aufs.h" |
10068 | + | |
10069 | +void au_add_nlink(struct inode *dir, struct inode *h_dir) | |
10070 | +{ | |
9dbd164d AM |
10071 | + unsigned int nlink; |
10072 | + | |
1facf9fc | 10073 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
10074 | + | |
9dbd164d AM |
10075 | + nlink = dir->i_nlink; |
10076 | + nlink += h_dir->i_nlink - 2; | |
1facf9fc | 10077 | + if (h_dir->i_nlink < 2) |
9dbd164d | 10078 | + nlink += 2; |
f6b6e03d | 10079 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 10080 | + /* 0 can happen in revaliding */ |
92d182d2 | 10081 | + set_nlink(dir, nlink); |
1facf9fc | 10082 | +} |
10083 | + | |
10084 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir) | |
10085 | +{ | |
9dbd164d AM |
10086 | + unsigned int nlink; |
10087 | + | |
1facf9fc | 10088 | + AuDebugOn(!S_ISDIR(dir->i_mode) || !S_ISDIR(h_dir->i_mode)); |
10089 | + | |
9dbd164d AM |
10090 | + nlink = dir->i_nlink; |
10091 | + nlink -= h_dir->i_nlink - 2; | |
1facf9fc | 10092 | + if (h_dir->i_nlink < 2) |
9dbd164d | 10093 | + nlink -= 2; |
f6b6e03d | 10094 | + smp_mb(); /* for i_nlink */ |
92d182d2 | 10095 | + /* nlink == 0 means the branch-fs is broken */ |
9dbd164d | 10096 | + set_nlink(dir, nlink); |
1facf9fc | 10097 | +} |
10098 | + | |
1308ab2a | 10099 | +loff_t au_dir_size(struct file *file, struct dentry *dentry) |
10100 | +{ | |
10101 | + loff_t sz; | |
5afbbe0d | 10102 | + aufs_bindex_t bindex, bbot; |
1308ab2a | 10103 | + struct file *h_file; |
10104 | + struct dentry *h_dentry; | |
10105 | + | |
10106 | + sz = 0; | |
10107 | + if (file) { | |
2000de60 | 10108 | + AuDebugOn(!d_is_dir(file->f_path.dentry)); |
1308ab2a | 10109 | + |
5afbbe0d AM |
10110 | + bbot = au_fbbot_dir(file); |
10111 | + for (bindex = au_fbtop(file); | |
10112 | + bindex <= bbot && sz < KMALLOC_MAX_SIZE; | |
1308ab2a | 10113 | + bindex++) { |
4a4d8108 | 10114 | + h_file = au_hf_dir(file, bindex); |
c06a8ce3 AM |
10115 | + if (h_file && file_inode(h_file)) |
10116 | + sz += vfsub_f_size_read(h_file); | |
1308ab2a | 10117 | + } |
10118 | + } else { | |
10119 | + AuDebugOn(!dentry); | |
2000de60 | 10120 | + AuDebugOn(!d_is_dir(dentry)); |
1308ab2a | 10121 | + |
5afbbe0d AM |
10122 | + bbot = au_dbtaildir(dentry); |
10123 | + for (bindex = au_dbtop(dentry); | |
10124 | + bindex <= bbot && sz < KMALLOC_MAX_SIZE; | |
1308ab2a | 10125 | + bindex++) { |
10126 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 JR |
10127 | + if (h_dentry && d_is_positive(h_dentry)) |
10128 | + sz += i_size_read(d_inode(h_dentry)); | |
1308ab2a | 10129 | + } |
10130 | + } | |
10131 | + if (sz < KMALLOC_MAX_SIZE) | |
10132 | + sz = roundup_pow_of_two(sz); | |
10133 | + if (sz > KMALLOC_MAX_SIZE) | |
10134 | + sz = KMALLOC_MAX_SIZE; | |
10135 | + else if (sz < NAME_MAX) { | |
10136 | + BUILD_BUG_ON(AUFS_RDBLK_DEF < NAME_MAX); | |
10137 | + sz = AUFS_RDBLK_DEF; | |
10138 | + } | |
10139 | + return sz; | |
10140 | +} | |
10141 | + | |
b912730e AM |
10142 | +struct au_dir_ts_arg { |
10143 | + struct dentry *dentry; | |
10144 | + aufs_bindex_t brid; | |
10145 | +}; | |
10146 | + | |
10147 | +static void au_do_dir_ts(void *arg) | |
10148 | +{ | |
10149 | + struct au_dir_ts_arg *a = arg; | |
10150 | + struct au_dtime dt; | |
10151 | + struct path h_path; | |
10152 | + struct inode *dir, *h_dir; | |
10153 | + struct super_block *sb; | |
10154 | + struct au_branch *br; | |
10155 | + struct au_hinode *hdir; | |
10156 | + int err; | |
5afbbe0d | 10157 | + aufs_bindex_t btop, bindex; |
b912730e AM |
10158 | + |
10159 | + sb = a->dentry->d_sb; | |
5527c038 | 10160 | + if (d_really_is_negative(a->dentry)) |
b912730e | 10161 | + goto out; |
5527c038 | 10162 | + /* no dir->i_mutex lock */ |
b95c5147 AM |
10163 | + aufs_read_lock(a->dentry, AuLock_DW); /* noflush */ |
10164 | + | |
5527c038 | 10165 | + dir = d_inode(a->dentry); |
5afbbe0d | 10166 | + btop = au_ibtop(dir); |
b912730e | 10167 | + bindex = au_br_index(sb, a->brid); |
5afbbe0d | 10168 | + if (bindex < btop) |
b912730e AM |
10169 | + goto out_unlock; |
10170 | + | |
10171 | + br = au_sbr(sb, bindex); | |
10172 | + h_path.dentry = au_h_dptr(a->dentry, bindex); | |
10173 | + if (!h_path.dentry) | |
10174 | + goto out_unlock; | |
10175 | + h_path.mnt = au_br_mnt(br); | |
10176 | + au_dtime_store(&dt, a->dentry, &h_path); | |
10177 | + | |
5afbbe0d | 10178 | + br = au_sbr(sb, btop); |
b912730e AM |
10179 | + if (!au_br_writable(br->br_perm)) |
10180 | + goto out_unlock; | |
5afbbe0d | 10181 | + h_path.dentry = au_h_dptr(a->dentry, btop); |
b912730e AM |
10182 | + h_path.mnt = au_br_mnt(br); |
10183 | + err = vfsub_mnt_want_write(h_path.mnt); | |
10184 | + if (err) | |
10185 | + goto out_unlock; | |
5afbbe0d AM |
10186 | + hdir = au_hi(dir, btop); |
10187 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); | |
10188 | + h_dir = au_h_iptr(dir, btop); | |
b912730e | 10189 | + if (h_dir->i_nlink |
cd7a4cd9 | 10190 | + && timespec64_compare(&h_dir->i_mtime, &dt.dt_mtime) < 0) { |
b912730e AM |
10191 | + dt.dt_h_path = h_path; |
10192 | + au_dtime_revert(&dt); | |
10193 | + } | |
5afbbe0d | 10194 | + au_hn_inode_unlock(hdir); |
b912730e AM |
10195 | + vfsub_mnt_drop_write(h_path.mnt); |
10196 | + au_cpup_attr_timesizes(dir); | |
10197 | + | |
10198 | +out_unlock: | |
10199 | + aufs_read_unlock(a->dentry, AuLock_DW); | |
10200 | +out: | |
10201 | + dput(a->dentry); | |
10202 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
9f237c51 | 10203 | + au_kfree_try_rcu(arg); |
b912730e AM |
10204 | +} |
10205 | + | |
10206 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bindex) | |
10207 | +{ | |
10208 | + int perm, wkq_err; | |
5afbbe0d | 10209 | + aufs_bindex_t btop; |
b912730e AM |
10210 | + struct au_dir_ts_arg *arg; |
10211 | + struct dentry *dentry; | |
10212 | + struct super_block *sb; | |
10213 | + | |
10214 | + IMustLock(dir); | |
10215 | + | |
10216 | + dentry = d_find_any_alias(dir); | |
10217 | + AuDebugOn(!dentry); | |
10218 | + sb = dentry->d_sb; | |
5afbbe0d AM |
10219 | + btop = au_ibtop(dir); |
10220 | + if (btop == bindex) { | |
b912730e AM |
10221 | + au_cpup_attr_timesizes(dir); |
10222 | + goto out; | |
10223 | + } | |
10224 | + | |
5afbbe0d | 10225 | + perm = au_sbr_perm(sb, btop); |
b912730e AM |
10226 | + if (!au_br_writable(perm)) |
10227 | + goto out; | |
10228 | + | |
10229 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
10230 | + if (!arg) | |
10231 | + goto out; | |
10232 | + | |
10233 | + arg->dentry = dget(dentry); /* will be dput-ted by au_do_dir_ts() */ | |
10234 | + arg->brid = au_sbr_id(sb, bindex); | |
10235 | + wkq_err = au_wkq_nowait(au_do_dir_ts, arg, sb, /*flags*/0); | |
10236 | + if (unlikely(wkq_err)) { | |
10237 | + pr_err("wkq %d\n", wkq_err); | |
10238 | + dput(dentry); | |
9f237c51 | 10239 | + au_kfree_try_rcu(arg); |
b912730e AM |
10240 | + } |
10241 | + | |
10242 | +out: | |
10243 | + dput(dentry); | |
10244 | +} | |
10245 | + | |
1facf9fc | 10246 | +/* ---------------------------------------------------------------------- */ |
10247 | + | |
10248 | +static int reopen_dir(struct file *file) | |
10249 | +{ | |
10250 | + int err; | |
10251 | + unsigned int flags; | |
5afbbe0d | 10252 | + aufs_bindex_t bindex, btail, btop; |
1facf9fc | 10253 | + struct dentry *dentry, *h_dentry; |
10254 | + struct file *h_file; | |
10255 | + | |
10256 | + /* open all lower dirs */ | |
2000de60 | 10257 | + dentry = file->f_path.dentry; |
5afbbe0d AM |
10258 | + btop = au_dbtop(dentry); |
10259 | + for (bindex = au_fbtop(file); bindex < btop; bindex++) | |
1facf9fc | 10260 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d | 10261 | + au_set_fbtop(file, btop); |
1facf9fc | 10262 | + |
10263 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 10264 | + for (bindex = au_fbbot_dir(file); btail < bindex; bindex--) |
1facf9fc | 10265 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d | 10266 | + au_set_fbbot_dir(file, btail); |
1facf9fc | 10267 | + |
4a4d8108 | 10268 | + flags = vfsub_file_flags(file); |
5afbbe0d | 10269 | + for (bindex = btop; bindex <= btail; bindex++) { |
1facf9fc | 10270 | + h_dentry = au_h_dptr(dentry, bindex); |
10271 | + if (!h_dentry) | |
10272 | + continue; | |
4a4d8108 | 10273 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 10274 | + if (h_file) |
10275 | + continue; | |
10276 | + | |
392086de | 10277 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 10278 | + err = PTR_ERR(h_file); |
10279 | + if (IS_ERR(h_file)) | |
10280 | + goto out; /* close all? */ | |
10281 | + au_set_h_fptr(file, bindex, h_file); | |
10282 | + } | |
10283 | + au_update_figen(file); | |
10284 | + /* todo: necessary? */ | |
10285 | + /* file->f_ra = h_file->f_ra; */ | |
10286 | + err = 0; | |
10287 | + | |
4f0767ce | 10288 | +out: |
1facf9fc | 10289 | + return err; |
10290 | +} | |
10291 | + | |
b912730e | 10292 | +static int do_open_dir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 10293 | +{ |
10294 | + int err; | |
10295 | + aufs_bindex_t bindex, btail; | |
10296 | + struct dentry *dentry, *h_dentry; | |
8cdd5066 | 10297 | + struct vfsmount *mnt; |
1facf9fc | 10298 | + |
1308ab2a | 10299 | + FiMustWriteLock(file); |
b912730e | 10300 | + AuDebugOn(h_file); |
1308ab2a | 10301 | + |
523b37e3 | 10302 | + err = 0; |
8cdd5066 | 10303 | + mnt = file->f_path.mnt; |
2000de60 | 10304 | + dentry = file->f_path.dentry; |
be118d29 | 10305 | + file->f_version = inode_query_iversion(d_inode(dentry)); |
5afbbe0d AM |
10306 | + bindex = au_dbtop(dentry); |
10307 | + au_set_fbtop(file, bindex); | |
1facf9fc | 10308 | + btail = au_dbtaildir(dentry); |
5afbbe0d | 10309 | + au_set_fbbot_dir(file, btail); |
1facf9fc | 10310 | + for (; !err && bindex <= btail; bindex++) { |
10311 | + h_dentry = au_h_dptr(dentry, bindex); | |
10312 | + if (!h_dentry) | |
10313 | + continue; | |
10314 | + | |
8cdd5066 JR |
10315 | + err = vfsub_test_mntns(mnt, h_dentry->d_sb); |
10316 | + if (unlikely(err)) | |
10317 | + break; | |
392086de | 10318 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
1facf9fc | 10319 | + if (IS_ERR(h_file)) { |
10320 | + err = PTR_ERR(h_file); | |
10321 | + break; | |
10322 | + } | |
10323 | + au_set_h_fptr(file, bindex, h_file); | |
10324 | + } | |
10325 | + au_update_figen(file); | |
10326 | + /* todo: necessary? */ | |
10327 | + /* file->f_ra = h_file->f_ra; */ | |
10328 | + if (!err) | |
10329 | + return 0; /* success */ | |
10330 | + | |
10331 | + /* close all */ | |
5afbbe0d | 10332 | + for (bindex = au_fbtop(file); bindex <= btail; bindex++) |
1facf9fc | 10333 | + au_set_h_fptr(file, bindex, NULL); |
5afbbe0d AM |
10334 | + au_set_fbtop(file, -1); |
10335 | + au_set_fbbot_dir(file, -1); | |
4a4d8108 | 10336 | + |
1facf9fc | 10337 | + return err; |
10338 | +} | |
10339 | + | |
10340 | +static int aufs_open_dir(struct inode *inode __maybe_unused, | |
10341 | + struct file *file) | |
10342 | +{ | |
4a4d8108 AM |
10343 | + int err; |
10344 | + struct super_block *sb; | |
10345 | + struct au_fidir *fidir; | |
10346 | + | |
10347 | + err = -ENOMEM; | |
2000de60 | 10348 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 10349 | + si_read_lock(sb, AuLock_FLUSH); |
e49829fe | 10350 | + fidir = au_fidir_alloc(sb); |
4a4d8108 | 10351 | + if (fidir) { |
b912730e AM |
10352 | + struct au_do_open_args args = { |
10353 | + .open = do_open_dir, | |
10354 | + .fidir = fidir | |
10355 | + }; | |
10356 | + err = au_do_open(file, &args); | |
4a4d8108 | 10357 | + if (unlikely(err)) |
9f237c51 | 10358 | + au_kfree_rcu(fidir); |
4a4d8108 AM |
10359 | + } |
10360 | + si_read_unlock(sb); | |
10361 | + return err; | |
1facf9fc | 10362 | +} |
10363 | + | |
10364 | +static int aufs_release_dir(struct inode *inode __maybe_unused, | |
10365 | + struct file *file) | |
10366 | +{ | |
10367 | + struct au_vdir *vdir_cache; | |
4a4d8108 AM |
10368 | + struct au_finfo *finfo; |
10369 | + struct au_fidir *fidir; | |
f0c0a007 | 10370 | + struct au_hfile *hf; |
5afbbe0d | 10371 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 10372 | + |
4a4d8108 AM |
10373 | + finfo = au_fi(file); |
10374 | + fidir = finfo->fi_hdir; | |
10375 | + if (fidir) { | |
8b6a4947 AM |
10376 | + au_hbl_del(&finfo->fi_hlist, |
10377 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 AM |
10378 | + vdir_cache = fidir->fd_vdir_cache; /* lock-free */ |
10379 | + if (vdir_cache) | |
1c60b727 | 10380 | + au_vdir_free(vdir_cache); |
4a4d8108 AM |
10381 | + |
10382 | + bindex = finfo->fi_btop; | |
10383 | + if (bindex >= 0) { | |
f0c0a007 | 10384 | + hf = fidir->fd_hfile + bindex; |
4a4d8108 AM |
10385 | + /* |
10386 | + * calls fput() instead of filp_close(), | |
10387 | + * since no dnotify or lock for the lower file. | |
10388 | + */ | |
5afbbe0d | 10389 | + bbot = fidir->fd_bbot; |
f0c0a007 AM |
10390 | + for (; bindex <= bbot; bindex++, hf++) |
10391 | + if (hf->hf_file) | |
1c60b727 | 10392 | + au_hfput(hf, /*execed*/0); |
4a4d8108 | 10393 | + } |
9f237c51 | 10394 | + au_kfree_rcu(fidir); |
4a4d8108 | 10395 | + finfo->fi_hdir = NULL; |
1facf9fc | 10396 | + } |
1c60b727 | 10397 | + au_finfo_fin(file); |
1facf9fc | 10398 | + return 0; |
10399 | +} | |
10400 | + | |
10401 | +/* ---------------------------------------------------------------------- */ | |
10402 | + | |
4a4d8108 AM |
10403 | +static int au_do_flush_dir(struct file *file, fl_owner_t id) |
10404 | +{ | |
10405 | + int err; | |
5afbbe0d | 10406 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
10407 | + struct file *h_file; |
10408 | + | |
10409 | + err = 0; | |
5afbbe0d AM |
10410 | + bbot = au_fbbot_dir(file); |
10411 | + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) { | |
4a4d8108 AM |
10412 | + h_file = au_hf_dir(file, bindex); |
10413 | + if (h_file) | |
10414 | + err = vfsub_flush(h_file, id); | |
10415 | + } | |
10416 | + return err; | |
10417 | +} | |
10418 | + | |
10419 | +static int aufs_flush_dir(struct file *file, fl_owner_t id) | |
10420 | +{ | |
10421 | + return au_do_flush(file, id, au_do_flush_dir); | |
10422 | +} | |
10423 | + | |
10424 | +/* ---------------------------------------------------------------------- */ | |
10425 | + | |
1facf9fc | 10426 | +static int au_do_fsync_dir_no_file(struct dentry *dentry, int datasync) |
10427 | +{ | |
10428 | + int err; | |
5afbbe0d | 10429 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 10430 | + struct inode *inode; |
10431 | + struct super_block *sb; | |
10432 | + | |
10433 | + err = 0; | |
10434 | + sb = dentry->d_sb; | |
5527c038 | 10435 | + inode = d_inode(dentry); |
1facf9fc | 10436 | + IMustLock(inode); |
5afbbe0d AM |
10437 | + bbot = au_dbbot(dentry); |
10438 | + for (bindex = au_dbtop(dentry); !err && bindex <= bbot; bindex++) { | |
1facf9fc | 10439 | + struct path h_path; |
1facf9fc | 10440 | + |
10441 | + if (au_test_ro(sb, bindex, inode)) | |
10442 | + continue; | |
10443 | + h_path.dentry = au_h_dptr(dentry, bindex); | |
10444 | + if (!h_path.dentry) | |
10445 | + continue; | |
1facf9fc | 10446 | + |
1facf9fc | 10447 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
53392da6 | 10448 | + err = vfsub_fsync(NULL, &h_path, datasync); |
1facf9fc | 10449 | + } |
10450 | + | |
10451 | + return err; | |
10452 | +} | |
10453 | + | |
10454 | +static int au_do_fsync_dir(struct file *file, int datasync) | |
10455 | +{ | |
10456 | + int err; | |
5afbbe0d | 10457 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 10458 | + struct file *h_file; |
10459 | + struct super_block *sb; | |
10460 | + struct inode *inode; | |
1facf9fc | 10461 | + |
521ced18 | 10462 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0); |
1facf9fc | 10463 | + if (unlikely(err)) |
10464 | + goto out; | |
10465 | + | |
c06a8ce3 | 10466 | + inode = file_inode(file); |
b912730e | 10467 | + sb = inode->i_sb; |
5afbbe0d AM |
10468 | + bbot = au_fbbot_dir(file); |
10469 | + for (bindex = au_fbtop(file); !err && bindex <= bbot; bindex++) { | |
4a4d8108 | 10470 | + h_file = au_hf_dir(file, bindex); |
1facf9fc | 10471 | + if (!h_file || au_test_ro(sb, bindex, inode)) |
10472 | + continue; | |
10473 | + | |
53392da6 | 10474 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
1facf9fc | 10475 | + } |
10476 | + | |
4f0767ce | 10477 | +out: |
1facf9fc | 10478 | + return err; |
10479 | +} | |
10480 | + | |
10481 | +/* | |
10482 | + * @file may be NULL | |
10483 | + */ | |
1e00d052 AM |
10484 | +static int aufs_fsync_dir(struct file *file, loff_t start, loff_t end, |
10485 | + int datasync) | |
1facf9fc | 10486 | +{ |
10487 | + int err; | |
b752ccd1 | 10488 | + struct dentry *dentry; |
5527c038 | 10489 | + struct inode *inode; |
1facf9fc | 10490 | + struct super_block *sb; |
1facf9fc | 10491 | + |
10492 | + err = 0; | |
2000de60 | 10493 | + dentry = file->f_path.dentry; |
5527c038 | 10494 | + inode = d_inode(dentry); |
febd17d6 | 10495 | + inode_lock(inode); |
1facf9fc | 10496 | + sb = dentry->d_sb; |
10497 | + si_noflush_read_lock(sb); | |
10498 | + if (file) | |
10499 | + err = au_do_fsync_dir(file, datasync); | |
10500 | + else { | |
10501 | + di_write_lock_child(dentry); | |
10502 | + err = au_do_fsync_dir_no_file(dentry, datasync); | |
10503 | + } | |
5527c038 | 10504 | + au_cpup_attr_timesizes(inode); |
1facf9fc | 10505 | + di_write_unlock(dentry); |
10506 | + if (file) | |
10507 | + fi_write_unlock(file); | |
10508 | + | |
10509 | + si_read_unlock(sb); | |
febd17d6 | 10510 | + inode_unlock(inode); |
1facf9fc | 10511 | + return err; |
10512 | +} | |
10513 | + | |
10514 | +/* ---------------------------------------------------------------------- */ | |
10515 | + | |
5afbbe0d | 10516 | +static int aufs_iterate_shared(struct file *file, struct dir_context *ctx) |
1facf9fc | 10517 | +{ |
10518 | + int err; | |
10519 | + struct dentry *dentry; | |
9dbd164d | 10520 | + struct inode *inode, *h_inode; |
1facf9fc | 10521 | + struct super_block *sb; |
10522 | + | |
062440b3 | 10523 | + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 10524 | + |
2000de60 | 10525 | + dentry = file->f_path.dentry; |
5527c038 | 10526 | + inode = d_inode(dentry); |
1facf9fc | 10527 | + IMustLock(inode); |
10528 | + | |
10529 | + sb = dentry->d_sb; | |
10530 | + si_read_lock(sb, AuLock_FLUSH); | |
521ced18 | 10531 | + err = au_reval_and_lock_fdi(file, reopen_dir, /*wlock*/1, /*fi_lsc*/0); |
1facf9fc | 10532 | + if (unlikely(err)) |
10533 | + goto out; | |
027c5e7a AM |
10534 | + err = au_alive_dir(dentry); |
10535 | + if (!err) | |
10536 | + err = au_vdir_init(file); | |
1facf9fc | 10537 | + di_downgrade_lock(dentry, AuLock_IR); |
10538 | + if (unlikely(err)) | |
10539 | + goto out_unlock; | |
10540 | + | |
5afbbe0d | 10541 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
b752ccd1 | 10542 | + if (!au_test_nfsd()) { |
392086de | 10543 | + err = au_vdir_fill_de(file, ctx); |
9dbd164d | 10544 | + fsstack_copy_attr_atime(inode, h_inode); |
1facf9fc | 10545 | + } else { |
10546 | + /* | |
10547 | + * nfsd filldir may call lookup_one_len(), vfs_getattr(), | |
10548 | + * encode_fh() and others. | |
10549 | + */ | |
9dbd164d | 10550 | + atomic_inc(&h_inode->i_count); |
1facf9fc | 10551 | + di_read_unlock(dentry, AuLock_IR); |
10552 | + si_read_unlock(sb); | |
392086de | 10553 | + err = au_vdir_fill_de(file, ctx); |
1facf9fc | 10554 | + fsstack_copy_attr_atime(inode, h_inode); |
10555 | + fi_write_unlock(file); | |
9dbd164d | 10556 | + iput(h_inode); |
1facf9fc | 10557 | + |
10558 | + AuTraceErr(err); | |
10559 | + return err; | |
10560 | + } | |
10561 | + | |
4f0767ce | 10562 | +out_unlock: |
1facf9fc | 10563 | + di_read_unlock(dentry, AuLock_IR); |
10564 | + fi_write_unlock(file); | |
4f0767ce | 10565 | +out: |
1facf9fc | 10566 | + si_read_unlock(sb); |
10567 | + return err; | |
10568 | +} | |
10569 | + | |
10570 | +/* ---------------------------------------------------------------------- */ | |
10571 | + | |
10572 | +#define AuTestEmpty_WHONLY 1 | |
dece6358 AM |
10573 | +#define AuTestEmpty_CALLED (1 << 1) |
10574 | +#define AuTestEmpty_SHWH (1 << 2) | |
1facf9fc | 10575 | +#define au_ftest_testempty(flags, name) ((flags) & AuTestEmpty_##name) |
7f207e10 AM |
10576 | +#define au_fset_testempty(flags, name) \ |
10577 | + do { (flags) |= AuTestEmpty_##name; } while (0) | |
10578 | +#define au_fclr_testempty(flags, name) \ | |
10579 | + do { (flags) &= ~AuTestEmpty_##name; } while (0) | |
1facf9fc | 10580 | + |
dece6358 AM |
10581 | +#ifndef CONFIG_AUFS_SHWH |
10582 | +#undef AuTestEmpty_SHWH | |
10583 | +#define AuTestEmpty_SHWH 0 | |
10584 | +#endif | |
10585 | + | |
1facf9fc | 10586 | +struct test_empty_arg { |
392086de | 10587 | + struct dir_context ctx; |
1308ab2a | 10588 | + struct au_nhash *whlist; |
1facf9fc | 10589 | + unsigned int flags; |
10590 | + int err; | |
10591 | + aufs_bindex_t bindex; | |
10592 | +}; | |
10593 | + | |
392086de AM |
10594 | +static int test_empty_cb(struct dir_context *ctx, const char *__name, |
10595 | + int namelen, loff_t offset __maybe_unused, u64 ino, | |
dece6358 | 10596 | + unsigned int d_type) |
1facf9fc | 10597 | +{ |
392086de AM |
10598 | + struct test_empty_arg *arg = container_of(ctx, struct test_empty_arg, |
10599 | + ctx); | |
1facf9fc | 10600 | + char *name = (void *)__name; |
10601 | + | |
10602 | + arg->err = 0; | |
10603 | + au_fset_testempty(arg->flags, CALLED); | |
10604 | + /* smp_mb(); */ | |
10605 | + if (name[0] == '.' | |
10606 | + && (namelen == 1 || (name[1] == '.' && namelen == 2))) | |
10607 | + goto out; /* success */ | |
10608 | + | |
10609 | + if (namelen <= AUFS_WH_PFX_LEN | |
10610 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
10611 | + if (au_ftest_testempty(arg->flags, WHONLY) | |
1308ab2a | 10612 | + && !au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 10613 | + arg->err = -ENOTEMPTY; |
10614 | + goto out; | |
10615 | + } | |
10616 | + | |
10617 | + name += AUFS_WH_PFX_LEN; | |
10618 | + namelen -= AUFS_WH_PFX_LEN; | |
1308ab2a | 10619 | + if (!au_nhash_test_known_wh(arg->whlist, name, namelen)) |
1facf9fc | 10620 | + arg->err = au_nhash_append_wh |
1308ab2a | 10621 | + (arg->whlist, name, namelen, ino, d_type, arg->bindex, |
dece6358 | 10622 | + au_ftest_testempty(arg->flags, SHWH)); |
1facf9fc | 10623 | + |
4f0767ce | 10624 | +out: |
1facf9fc | 10625 | + /* smp_mb(); */ |
10626 | + AuTraceErr(arg->err); | |
10627 | + return arg->err; | |
10628 | +} | |
10629 | + | |
10630 | +static int do_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
10631 | +{ | |
10632 | + int err; | |
10633 | + struct file *h_file; | |
acd2b654 | 10634 | + struct au_branch *br; |
1facf9fc | 10635 | + |
10636 | + h_file = au_h_open(dentry, arg->bindex, | |
10637 | + O_RDONLY | O_NONBLOCK | O_DIRECTORY | O_LARGEFILE, | |
392086de | 10638 | + /*file*/NULL, /*force_wr*/0); |
1facf9fc | 10639 | + err = PTR_ERR(h_file); |
10640 | + if (IS_ERR(h_file)) | |
10641 | + goto out; | |
10642 | + | |
10643 | + err = 0; | |
10644 | + if (!au_opt_test(au_mntflags(dentry->d_sb), UDBA_NONE) | |
c06a8ce3 | 10645 | + && !file_inode(h_file)->i_nlink) |
1facf9fc | 10646 | + goto out_put; |
10647 | + | |
10648 | + do { | |
10649 | + arg->err = 0; | |
10650 | + au_fclr_testempty(arg->flags, CALLED); | |
10651 | + /* smp_mb(); */ | |
392086de | 10652 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1facf9fc | 10653 | + if (err >= 0) |
10654 | + err = arg->err; | |
10655 | + } while (!err && au_ftest_testempty(arg->flags, CALLED)); | |
10656 | + | |
4f0767ce | 10657 | +out_put: |
1facf9fc | 10658 | + fput(h_file); |
acd2b654 AM |
10659 | + br = au_sbr(dentry->d_sb, arg->bindex); |
10660 | + au_lcnt_dec(&br->br_nfiles); | |
4f0767ce | 10661 | +out: |
1facf9fc | 10662 | + return err; |
10663 | +} | |
10664 | + | |
10665 | +struct do_test_empty_args { | |
10666 | + int *errp; | |
10667 | + struct dentry *dentry; | |
10668 | + struct test_empty_arg *arg; | |
10669 | +}; | |
10670 | + | |
10671 | +static void call_do_test_empty(void *args) | |
10672 | +{ | |
10673 | + struct do_test_empty_args *a = args; | |
10674 | + *a->errp = do_test_empty(a->dentry, a->arg); | |
10675 | +} | |
10676 | + | |
10677 | +static int sio_test_empty(struct dentry *dentry, struct test_empty_arg *arg) | |
10678 | +{ | |
10679 | + int err, wkq_err; | |
10680 | + struct dentry *h_dentry; | |
10681 | + struct inode *h_inode; | |
10682 | + | |
10683 | + h_dentry = au_h_dptr(dentry, arg->bindex); | |
5527c038 | 10684 | + h_inode = d_inode(h_dentry); |
53392da6 | 10685 | + /* todo: i_mode changes anytime? */ |
be118d29 | 10686 | + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD); |
1facf9fc | 10687 | + err = au_test_h_perm_sio(h_inode, MAY_EXEC | MAY_READ); |
3c1bdaff | 10688 | + inode_unlock_shared(h_inode); |
1facf9fc | 10689 | + if (!err) |
10690 | + err = do_test_empty(dentry, arg); | |
10691 | + else { | |
10692 | + struct do_test_empty_args args = { | |
10693 | + .errp = &err, | |
10694 | + .dentry = dentry, | |
10695 | + .arg = arg | |
10696 | + }; | |
10697 | + unsigned int flags = arg->flags; | |
10698 | + | |
10699 | + wkq_err = au_wkq_wait(call_do_test_empty, &args); | |
10700 | + if (unlikely(wkq_err)) | |
10701 | + err = wkq_err; | |
10702 | + arg->flags = flags; | |
10703 | + } | |
10704 | + | |
10705 | + return err; | |
10706 | +} | |
10707 | + | |
10708 | +int au_test_empty_lower(struct dentry *dentry) | |
10709 | +{ | |
10710 | + int err; | |
1308ab2a | 10711 | + unsigned int rdhash; |
5afbbe0d | 10712 | + aufs_bindex_t bindex, btop, btail; |
1308ab2a | 10713 | + struct au_nhash whlist; |
392086de AM |
10714 | + struct test_empty_arg arg = { |
10715 | + .ctx = { | |
2000de60 | 10716 | + .actor = test_empty_cb |
392086de AM |
10717 | + } |
10718 | + }; | |
076b876e | 10719 | + int (*test_empty)(struct dentry *dentry, struct test_empty_arg *arg); |
1facf9fc | 10720 | + |
dece6358 AM |
10721 | + SiMustAnyLock(dentry->d_sb); |
10722 | + | |
1308ab2a | 10723 | + rdhash = au_sbi(dentry->d_sb)->si_rdhash; |
10724 | + if (!rdhash) | |
10725 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, dentry)); | |
10726 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
dece6358 | 10727 | + if (unlikely(err)) |
1facf9fc | 10728 | + goto out; |
10729 | + | |
1facf9fc | 10730 | + arg.flags = 0; |
1308ab2a | 10731 | + arg.whlist = &whlist; |
5afbbe0d | 10732 | + btop = au_dbtop(dentry); |
dece6358 AM |
10733 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10734 | + au_fset_testempty(arg.flags, SHWH); | |
076b876e AM |
10735 | + test_empty = do_test_empty; |
10736 | + if (au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1)) | |
10737 | + test_empty = sio_test_empty; | |
5afbbe0d | 10738 | + arg.bindex = btop; |
076b876e | 10739 | + err = test_empty(dentry, &arg); |
1facf9fc | 10740 | + if (unlikely(err)) |
10741 | + goto out_whlist; | |
10742 | + | |
10743 | + au_fset_testempty(arg.flags, WHONLY); | |
10744 | + btail = au_dbtaildir(dentry); | |
5afbbe0d | 10745 | + for (bindex = btop + 1; !err && bindex <= btail; bindex++) { |
1facf9fc | 10746 | + struct dentry *h_dentry; |
10747 | + | |
10748 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10749 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10750 | + arg.bindex = bindex; |
076b876e | 10751 | + err = test_empty(dentry, &arg); |
1facf9fc | 10752 | + } |
10753 | + } | |
10754 | + | |
4f0767ce | 10755 | +out_whlist: |
1308ab2a | 10756 | + au_nhash_wh_free(&whlist); |
4f0767ce | 10757 | +out: |
1facf9fc | 10758 | + return err; |
10759 | +} | |
10760 | + | |
10761 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist) | |
10762 | +{ | |
10763 | + int err; | |
392086de AM |
10764 | + struct test_empty_arg arg = { |
10765 | + .ctx = { | |
2000de60 | 10766 | + .actor = test_empty_cb |
392086de AM |
10767 | + } |
10768 | + }; | |
1facf9fc | 10769 | + aufs_bindex_t bindex, btail; |
10770 | + | |
10771 | + err = 0; | |
1308ab2a | 10772 | + arg.whlist = whlist; |
1facf9fc | 10773 | + arg.flags = AuTestEmpty_WHONLY; |
dece6358 AM |
10774 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH)) |
10775 | + au_fset_testempty(arg.flags, SHWH); | |
1facf9fc | 10776 | + btail = au_dbtaildir(dentry); |
5afbbe0d | 10777 | + for (bindex = au_dbtop(dentry); !err && bindex <= btail; bindex++) { |
1facf9fc | 10778 | + struct dentry *h_dentry; |
10779 | + | |
10780 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 10781 | + if (h_dentry && d_is_positive(h_dentry)) { |
1facf9fc | 10782 | + arg.bindex = bindex; |
10783 | + err = sio_test_empty(dentry, &arg); | |
10784 | + } | |
10785 | + } | |
10786 | + | |
10787 | + return err; | |
10788 | +} | |
10789 | + | |
10790 | +/* ---------------------------------------------------------------------- */ | |
10791 | + | |
10792 | +const struct file_operations aufs_dir_fop = { | |
4a4d8108 | 10793 | + .owner = THIS_MODULE, |
027c5e7a | 10794 | + .llseek = default_llseek, |
1facf9fc | 10795 | + .read = generic_read_dir, |
5afbbe0d | 10796 | + .iterate_shared = aufs_iterate_shared, |
1facf9fc | 10797 | + .unlocked_ioctl = aufs_ioctl_dir, |
b752ccd1 AM |
10798 | +#ifdef CONFIG_COMPAT |
10799 | + .compat_ioctl = aufs_compat_ioctl_dir, | |
10800 | +#endif | |
1facf9fc | 10801 | + .open = aufs_open_dir, |
10802 | + .release = aufs_release_dir, | |
4a4d8108 | 10803 | + .flush = aufs_flush_dir, |
1facf9fc | 10804 | + .fsync = aufs_fsync_dir |
10805 | +}; | |
7f207e10 | 10806 | diff -urN /usr/share/empty/fs/aufs/dir.h linux/fs/aufs/dir.h |
eca34b5c | 10807 | --- /usr/share/empty/fs/aufs/dir.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 10808 | +++ linux/fs/aufs/dir.h 2020-01-27 10:57:18.168871450 +0100 |
9f237c51 | 10809 | @@ -0,0 +1,134 @@ |
062440b3 | 10810 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 10811 | +/* |
d58c55f2 | 10812 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 10813 | + * |
10814 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10815 | + * it under the terms of the GNU General Public License as published by | |
10816 | + * the Free Software Foundation; either version 2 of the License, or | |
10817 | + * (at your option) any later version. | |
dece6358 AM |
10818 | + * |
10819 | + * This program is distributed in the hope that it will be useful, | |
10820 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10821 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10822 | + * GNU General Public License for more details. | |
10823 | + * | |
10824 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 10825 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 10826 | + */ |
10827 | + | |
10828 | +/* | |
10829 | + * directory operations | |
10830 | + */ | |
10831 | + | |
10832 | +#ifndef __AUFS_DIR_H__ | |
10833 | +#define __AUFS_DIR_H__ | |
10834 | + | |
10835 | +#ifdef __KERNEL__ | |
10836 | + | |
10837 | +#include <linux/fs.h> | |
1facf9fc | 10838 | + |
10839 | +/* ---------------------------------------------------------------------- */ | |
10840 | + | |
10841 | +/* need to be faster and smaller */ | |
10842 | + | |
10843 | +struct au_nhash { | |
dece6358 AM |
10844 | + unsigned int nh_num; |
10845 | + struct hlist_head *nh_head; | |
1facf9fc | 10846 | +}; |
10847 | + | |
10848 | +struct au_vdir_destr { | |
10849 | + unsigned char len; | |
10850 | + unsigned char name[0]; | |
10851 | +} __packed; | |
10852 | + | |
10853 | +struct au_vdir_dehstr { | |
10854 | + struct hlist_node hash; | |
1c60b727 | 10855 | + struct au_vdir_destr *str; |
9f237c51 | 10856 | + struct rcu_head rcu; |
4a4d8108 | 10857 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10858 | + |
10859 | +struct au_vdir_de { | |
10860 | + ino_t de_ino; | |
10861 | + unsigned char de_type; | |
10862 | + /* caution: packed */ | |
10863 | + struct au_vdir_destr de_str; | |
10864 | +} __packed; | |
10865 | + | |
10866 | +struct au_vdir_wh { | |
10867 | + struct hlist_node wh_hash; | |
dece6358 AM |
10868 | +#ifdef CONFIG_AUFS_SHWH |
10869 | + ino_t wh_ino; | |
1facf9fc | 10870 | + aufs_bindex_t wh_bindex; |
dece6358 AM |
10871 | + unsigned char wh_type; |
10872 | +#else | |
10873 | + aufs_bindex_t wh_bindex; | |
10874 | +#endif | |
10875 | + /* caution: packed */ | |
1facf9fc | 10876 | + struct au_vdir_destr wh_str; |
10877 | +} __packed; | |
10878 | + | |
10879 | +union au_vdir_deblk_p { | |
10880 | + unsigned char *deblk; | |
10881 | + struct au_vdir_de *de; | |
10882 | +}; | |
10883 | + | |
10884 | +struct au_vdir { | |
10885 | + unsigned char **vd_deblk; | |
10886 | + unsigned long vd_nblk; | |
1facf9fc | 10887 | + struct { |
10888 | + unsigned long ul; | |
10889 | + union au_vdir_deblk_p p; | |
10890 | + } vd_last; | |
10891 | + | |
be118d29 | 10892 | + u64 vd_version; |
dece6358 | 10893 | + unsigned int vd_deblk_sz; |
9f237c51 AM |
10894 | + unsigned long vd_jiffy; |
10895 | + struct rcu_head rcu; | |
4a4d8108 | 10896 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 10897 | + |
10898 | +/* ---------------------------------------------------------------------- */ | |
10899 | + | |
10900 | +/* dir.c */ | |
10901 | +extern const struct file_operations aufs_dir_fop; | |
10902 | +void au_add_nlink(struct inode *dir, struct inode *h_dir); | |
10903 | +void au_sub_nlink(struct inode *dir, struct inode *h_dir); | |
1308ab2a | 10904 | +loff_t au_dir_size(struct file *file, struct dentry *dentry); |
b912730e | 10905 | +void au_dir_ts(struct inode *dir, aufs_bindex_t bsrc); |
1facf9fc | 10906 | +int au_test_empty_lower(struct dentry *dentry); |
10907 | +int au_test_empty(struct dentry *dentry, struct au_nhash *whlist); | |
10908 | + | |
10909 | +/* vdir.c */ | |
1308ab2a | 10910 | +unsigned int au_rdhash_est(loff_t sz); |
dece6358 AM |
10911 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp); |
10912 | +void au_nhash_wh_free(struct au_nhash *whlist); | |
1facf9fc | 10913 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, |
10914 | + int limit); | |
dece6358 AM |
10915 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen); |
10916 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
10917 | + unsigned int d_type, aufs_bindex_t bindex, | |
10918 | + unsigned char shwh); | |
1c60b727 | 10919 | +void au_vdir_free(struct au_vdir *vdir); |
1facf9fc | 10920 | +int au_vdir_init(struct file *file); |
392086de | 10921 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx); |
1facf9fc | 10922 | + |
10923 | +/* ioctl.c */ | |
10924 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg); | |
10925 | + | |
1308ab2a | 10926 | +#ifdef CONFIG_AUFS_RDU |
10927 | +/* rdu.c */ | |
10928 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
10929 | +#ifdef CONFIG_COMPAT |
10930 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, | |
10931 | + unsigned long arg); | |
10932 | +#endif | |
1308ab2a | 10933 | +#else |
c1595e42 JR |
10934 | +AuStub(long, au_rdu_ioctl, return -EINVAL, struct file *file, |
10935 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10936 | +#ifdef CONFIG_COMPAT |
c1595e42 JR |
10937 | +AuStub(long, au_rdu_compat_ioctl, return -EINVAL, struct file *file, |
10938 | + unsigned int cmd, unsigned long arg) | |
b752ccd1 | 10939 | +#endif |
1308ab2a | 10940 | +#endif |
10941 | + | |
1facf9fc | 10942 | +#endif /* __KERNEL__ */ |
10943 | +#endif /* __AUFS_DIR_H__ */ | |
8b6a4947 | 10944 | diff -urN /usr/share/empty/fs/aufs/dirren.c linux/fs/aufs/dirren.c |
eca34b5c | 10945 | --- /usr/share/empty/fs/aufs/dirren.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 10946 | +++ linux/fs/aufs/dirren.c 2020-01-27 10:57:18.168871450 +0100 |
062440b3 | 10947 | @@ -0,0 +1,1316 @@ |
cd7a4cd9 | 10948 | +// SPDX-License-Identifier: GPL-2.0 |
8b6a4947 | 10949 | +/* |
d58c55f2 | 10950 | + * Copyright (C) 2017-2020 Junjiro R. Okajima |
8b6a4947 AM |
10951 | + * |
10952 | + * This program, aufs is free software; you can redistribute it and/or modify | |
10953 | + * it under the terms of the GNU General Public License as published by | |
10954 | + * the Free Software Foundation; either version 2 of the License, or | |
10955 | + * (at your option) any later version. | |
10956 | + * | |
10957 | + * This program is distributed in the hope that it will be useful, | |
10958 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
10959 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
10960 | + * GNU General Public License for more details. | |
10961 | + * | |
10962 | + * You should have received a copy of the GNU General Public License | |
10963 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
10964 | + */ | |
10965 | + | |
10966 | +/* | |
acd2b654 | 10967 | + * special handling in renaming a directory |
8b6a4947 AM |
10968 | + * in order to support looking-up the before-renamed name on the lower readonly |
10969 | + * branches | |
10970 | + */ | |
10971 | + | |
10972 | +#include <linux/byteorder/generic.h> | |
10973 | +#include "aufs.h" | |
10974 | + | |
10975 | +static void au_dr_hino_del(struct au_dr_br *dr, struct au_dr_hino *ent) | |
10976 | +{ | |
10977 | + int idx; | |
10978 | + | |
10979 | + idx = au_dr_ihash(ent->dr_h_ino); | |
10980 | + au_hbl_del(&ent->dr_hnode, dr->dr_h_ino + idx); | |
10981 | +} | |
10982 | + | |
10983 | +static int au_dr_hino_test_empty(struct au_dr_br *dr) | |
10984 | +{ | |
10985 | + int ret, i; | |
10986 | + struct hlist_bl_head *hbl; | |
10987 | + | |
10988 | + ret = 1; | |
10989 | + for (i = 0; ret && i < AuDirren_NHASH; i++) { | |
10990 | + hbl = dr->dr_h_ino + i; | |
10991 | + hlist_bl_lock(hbl); | |
10992 | + ret &= hlist_bl_empty(hbl); | |
10993 | + hlist_bl_unlock(hbl); | |
10994 | + } | |
10995 | + | |
10996 | + return ret; | |
10997 | +} | |
10998 | + | |
10999 | +static struct au_dr_hino *au_dr_hino_find(struct au_dr_br *dr, ino_t ino) | |
11000 | +{ | |
11001 | + struct au_dr_hino *found, *ent; | |
11002 | + struct hlist_bl_head *hbl; | |
11003 | + struct hlist_bl_node *pos; | |
11004 | + int idx; | |
11005 | + | |
11006 | + found = NULL; | |
11007 | + idx = au_dr_ihash(ino); | |
11008 | + hbl = dr->dr_h_ino + idx; | |
11009 | + hlist_bl_lock(hbl); | |
11010 | + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode) | |
11011 | + if (ent->dr_h_ino == ino) { | |
11012 | + found = ent; | |
11013 | + break; | |
11014 | + } | |
11015 | + hlist_bl_unlock(hbl); | |
11016 | + | |
11017 | + return found; | |
11018 | +} | |
11019 | + | |
11020 | +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t ino, | |
11021 | + struct au_dr_hino *add_ent) | |
11022 | +{ | |
11023 | + int found, idx; | |
11024 | + struct hlist_bl_head *hbl; | |
11025 | + struct hlist_bl_node *pos; | |
11026 | + struct au_dr_hino *ent; | |
11027 | + | |
11028 | + found = 0; | |
11029 | + idx = au_dr_ihash(ino); | |
11030 | + hbl = dr->dr_h_ino + idx; | |
43982f53 | 11031 | +#if 0 /* debug print */ |
8b6a4947 AM |
11032 | + { |
11033 | + struct hlist_bl_node *tmp; | |
11034 | + | |
11035 | + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode) | |
11036 | + AuDbg("hi%llu\n", (unsigned long long)ent->dr_h_ino); | |
11037 | + } | |
11038 | +#endif | |
11039 | + hlist_bl_lock(hbl); | |
11040 | + hlist_bl_for_each_entry(ent, pos, hbl, dr_hnode) | |
11041 | + if (ent->dr_h_ino == ino) { | |
11042 | + found = 1; | |
11043 | + break; | |
11044 | + } | |
11045 | + if (!found && add_ent) | |
11046 | + hlist_bl_add_head(&add_ent->dr_hnode, hbl); | |
11047 | + hlist_bl_unlock(hbl); | |
11048 | + | |
11049 | + if (!found && add_ent) | |
11050 | + AuDbg("i%llu added\n", (unsigned long long)add_ent->dr_h_ino); | |
11051 | + | |
11052 | + return found; | |
11053 | +} | |
11054 | + | |
11055 | +void au_dr_hino_free(struct au_dr_br *dr) | |
11056 | +{ | |
11057 | + int i; | |
11058 | + struct hlist_bl_head *hbl; | |
11059 | + struct hlist_bl_node *pos, *tmp; | |
11060 | + struct au_dr_hino *ent; | |
11061 | + | |
11062 | + /* SiMustWriteLock(sb); */ | |
11063 | + | |
11064 | + for (i = 0; i < AuDirren_NHASH; i++) { | |
11065 | + hbl = dr->dr_h_ino + i; | |
11066 | + /* no spinlock since sbinfo must be write-locked */ | |
11067 | + hlist_bl_for_each_entry_safe(ent, pos, tmp, hbl, dr_hnode) | |
9f237c51 | 11068 | + au_kfree_rcu(ent); |
8b6a4947 AM |
11069 | + INIT_HLIST_BL_HEAD(hbl); |
11070 | + } | |
11071 | +} | |
11072 | + | |
11073 | +/* returns the number of inodes or an error */ | |
11074 | +static int au_dr_hino_store(struct super_block *sb, struct au_branch *br, | |
11075 | + struct file *hinofile) | |
11076 | +{ | |
11077 | + int err, i; | |
11078 | + ssize_t ssz; | |
11079 | + loff_t pos, oldsize; | |
11080 | + __be64 u64; | |
11081 | + struct inode *hinoinode; | |
11082 | + struct hlist_bl_head *hbl; | |
11083 | + struct hlist_bl_node *n1, *n2; | |
11084 | + struct au_dr_hino *ent; | |
11085 | + | |
11086 | + SiMustWriteLock(sb); | |
11087 | + AuDebugOn(!au_br_writable(br->br_perm)); | |
11088 | + | |
11089 | + hinoinode = file_inode(hinofile); | |
11090 | + oldsize = i_size_read(hinoinode); | |
11091 | + | |
11092 | + err = 0; | |
11093 | + pos = 0; | |
11094 | + hbl = br->br_dirren.dr_h_ino; | |
11095 | + for (i = 0; !err && i < AuDirren_NHASH; i++, hbl++) { | |
11096 | + /* no bit-lock since sbinfo must be write-locked */ | |
11097 | + hlist_bl_for_each_entry_safe(ent, n1, n2, hbl, dr_hnode) { | |
11098 | + AuDbg("hi%llu, %pD2\n", | |
11099 | + (unsigned long long)ent->dr_h_ino, hinofile); | |
11100 | + u64 = cpu_to_be64(ent->dr_h_ino); | |
11101 | + ssz = vfsub_write_k(hinofile, &u64, sizeof(u64), &pos); | |
11102 | + if (ssz == sizeof(u64)) | |
11103 | + continue; | |
11104 | + | |
11105 | + /* write error */ | |
11106 | + pr_err("ssz %zd, %pD2\n", ssz, hinofile); | |
11107 | + err = -ENOSPC; | |
11108 | + if (ssz < 0) | |
11109 | + err = ssz; | |
11110 | + break; | |
11111 | + } | |
11112 | + } | |
11113 | + /* regardless the error */ | |
11114 | + if (pos < oldsize) { | |
11115 | + err = vfsub_trunc(&hinofile->f_path, pos, /*attr*/0, hinofile); | |
11116 | + AuTraceErr(err); | |
11117 | + } | |
11118 | + | |
11119 | + AuTraceErr(err); | |
11120 | + return err; | |
11121 | +} | |
11122 | + | |
11123 | +static int au_dr_hino_load(struct au_dr_br *dr, struct file *hinofile) | |
11124 | +{ | |
11125 | + int err, hidx; | |
11126 | + ssize_t ssz; | |
11127 | + size_t sz, n; | |
11128 | + loff_t pos; | |
11129 | + uint64_t u64; | |
11130 | + struct au_dr_hino *ent; | |
11131 | + struct inode *hinoinode; | |
11132 | + struct hlist_bl_head *hbl; | |
11133 | + | |
11134 | + err = 0; | |
11135 | + pos = 0; | |
11136 | + hbl = dr->dr_h_ino; | |
11137 | + hinoinode = file_inode(hinofile); | |
11138 | + sz = i_size_read(hinoinode); | |
11139 | + AuDebugOn(sz % sizeof(u64)); | |
11140 | + n = sz / sizeof(u64); | |
11141 | + while (n--) { | |
11142 | + ssz = vfsub_read_k(hinofile, &u64, sizeof(u64), &pos); | |
11143 | + if (unlikely(ssz != sizeof(u64))) { | |
11144 | + pr_err("ssz %zd, %pD2\n", ssz, hinofile); | |
11145 | + err = -EINVAL; | |
11146 | + if (ssz < 0) | |
11147 | + err = ssz; | |
11148 | + goto out_free; | |
11149 | + } | |
11150 | + | |
11151 | + ent = kmalloc(sizeof(*ent), GFP_NOFS); | |
11152 | + if (!ent) { | |
11153 | + err = -ENOMEM; | |
11154 | + AuTraceErr(err); | |
11155 | + goto out_free; | |
11156 | + } | |
11157 | + ent->dr_h_ino = be64_to_cpu((__force __be64)u64); | |
11158 | + AuDbg("hi%llu, %pD2\n", | |
11159 | + (unsigned long long)ent->dr_h_ino, hinofile); | |
11160 | + hidx = au_dr_ihash(ent->dr_h_ino); | |
11161 | + au_hbl_add(&ent->dr_hnode, hbl + hidx); | |
11162 | + } | |
11163 | + goto out; /* success */ | |
11164 | + | |
11165 | +out_free: | |
11166 | + au_dr_hino_free(dr); | |
11167 | +out: | |
11168 | + AuTraceErr(err); | |
11169 | + return err; | |
11170 | +} | |
11171 | + | |
11172 | +/* | |
11173 | + * @bindex/@br is a switch to distinguish whether suspending hnotify or not. | |
11174 | + * @path is a switch to distinguish load and store. | |
11175 | + */ | |
11176 | +static int au_dr_hino(struct super_block *sb, aufs_bindex_t bindex, | |
11177 | + struct au_branch *br, const struct path *path) | |
11178 | +{ | |
11179 | + int err, flags; | |
11180 | + unsigned char load, suspend; | |
11181 | + struct file *hinofile; | |
11182 | + struct au_hinode *hdir; | |
11183 | + struct inode *dir, *delegated; | |
11184 | + struct path hinopath; | |
11185 | + struct qstr hinoname = QSTR_INIT(AUFS_WH_DR_BRHINO, | |
11186 | + sizeof(AUFS_WH_DR_BRHINO) - 1); | |
11187 | + | |
11188 | + AuDebugOn(bindex < 0 && !br); | |
11189 | + AuDebugOn(bindex >= 0 && br); | |
11190 | + | |
11191 | + err = -EINVAL; | |
11192 | + suspend = !br; | |
11193 | + if (suspend) | |
11194 | + br = au_sbr(sb, bindex); | |
11195 | + load = !!path; | |
11196 | + if (!load) { | |
11197 | + path = &br->br_path; | |
11198 | + AuDebugOn(!au_br_writable(br->br_perm)); | |
11199 | + if (unlikely(!au_br_writable(br->br_perm))) | |
11200 | + goto out; | |
11201 | + } | |
11202 | + | |
11203 | + hdir = NULL; | |
11204 | + if (suspend) { | |
11205 | + dir = d_inode(sb->s_root); | |
11206 | + hdir = au_hinode(au_ii(dir), bindex); | |
11207 | + dir = hdir->hi_inode; | |
11208 | + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD); | |
11209 | + } else { | |
11210 | + dir = d_inode(path->dentry); | |
11211 | + inode_lock_nested(dir, AuLsc_I_CHILD); | |
11212 | + } | |
11213 | + hinopath.dentry = vfsub_lkup_one(&hinoname, path->dentry); | |
11214 | + err = PTR_ERR(hinopath.dentry); | |
11215 | + if (IS_ERR(hinopath.dentry)) | |
11216 | + goto out_unlock; | |
11217 | + | |
11218 | + err = 0; | |
11219 | + flags = O_RDONLY; | |
11220 | + if (load) { | |
11221 | + if (d_is_negative(hinopath.dentry)) | |
11222 | + goto out_dput; /* success */ | |
11223 | + } else { | |
11224 | + if (au_dr_hino_test_empty(&br->br_dirren)) { | |
11225 | + if (d_is_positive(hinopath.dentry)) { | |
11226 | + delegated = NULL; | |
11227 | + err = vfsub_unlink(dir, &hinopath, &delegated, | |
11228 | + /*force*/0); | |
11229 | + AuTraceErr(err); | |
11230 | + if (unlikely(err)) | |
11231 | + pr_err("ignored err %d, %pd2\n", | |
11232 | + err, hinopath.dentry); | |
11233 | + if (unlikely(err == -EWOULDBLOCK)) | |
11234 | + iput(delegated); | |
11235 | + err = 0; | |
11236 | + } | |
11237 | + goto out_dput; | |
11238 | + } else if (!d_is_positive(hinopath.dentry)) { | |
11239 | + err = vfsub_create(dir, &hinopath, 0600, | |
11240 | + /*want_excl*/false); | |
11241 | + AuTraceErr(err); | |
11242 | + if (unlikely(err)) | |
11243 | + goto out_dput; | |
11244 | + } | |
11245 | + flags = O_WRONLY; | |
11246 | + } | |
11247 | + hinopath.mnt = path->mnt; | |
11248 | + hinofile = vfsub_dentry_open(&hinopath, flags); | |
11249 | + if (suspend) | |
11250 | + au_hn_inode_unlock(hdir); | |
11251 | + else | |
11252 | + inode_unlock(dir); | |
11253 | + dput(hinopath.dentry); | |
11254 | + AuTraceErrPtr(hinofile); | |
11255 | + if (IS_ERR(hinofile)) { | |
11256 | + err = PTR_ERR(hinofile); | |
11257 | + goto out; | |
11258 | + } | |
11259 | + | |
11260 | + if (load) | |
11261 | + err = au_dr_hino_load(&br->br_dirren, hinofile); | |
11262 | + else | |
11263 | + err = au_dr_hino_store(sb, br, hinofile); | |
11264 | + fput(hinofile); | |
11265 | + goto out; | |
11266 | + | |
11267 | +out_dput: | |
11268 | + dput(hinopath.dentry); | |
11269 | +out_unlock: | |
11270 | + if (suspend) | |
11271 | + au_hn_inode_unlock(hdir); | |
11272 | + else | |
11273 | + inode_unlock(dir); | |
11274 | +out: | |
11275 | + AuTraceErr(err); | |
11276 | + return err; | |
11277 | +} | |
11278 | + | |
11279 | +/* ---------------------------------------------------------------------- */ | |
11280 | + | |
11281 | +static int au_dr_brid_init(struct au_dr_brid *brid, const struct path *path) | |
11282 | +{ | |
11283 | + int err; | |
11284 | + struct kstatfs kstfs; | |
11285 | + dev_t dev; | |
11286 | + struct dentry *dentry; | |
11287 | + struct super_block *sb; | |
11288 | + | |
11289 | + err = vfs_statfs((void *)path, &kstfs); | |
11290 | + AuTraceErr(err); | |
11291 | + if (unlikely(err)) | |
11292 | + goto out; | |
11293 | + | |
11294 | + /* todo: support for UUID */ | |
11295 | + | |
11296 | + if (kstfs.f_fsid.val[0] || kstfs.f_fsid.val[1]) { | |
11297 | + brid->type = AuBrid_FSID; | |
11298 | + brid->fsid = kstfs.f_fsid; | |
11299 | + } else { | |
11300 | + dentry = path->dentry; | |
11301 | + sb = dentry->d_sb; | |
11302 | + dev = sb->s_dev; | |
11303 | + if (dev) { | |
11304 | + brid->type = AuBrid_DEV; | |
11305 | + brid->dev = dev; | |
11306 | + } | |
11307 | + } | |
11308 | + | |
11309 | +out: | |
11310 | + return err; | |
11311 | +} | |
11312 | + | |
11313 | +int au_dr_br_init(struct super_block *sb, struct au_branch *br, | |
11314 | + const struct path *path) | |
11315 | +{ | |
11316 | + int err, i; | |
11317 | + struct au_dr_br *dr; | |
11318 | + struct hlist_bl_head *hbl; | |
11319 | + | |
11320 | + dr = &br->br_dirren; | |
11321 | + hbl = dr->dr_h_ino; | |
11322 | + for (i = 0; i < AuDirren_NHASH; i++, hbl++) | |
11323 | + INIT_HLIST_BL_HEAD(hbl); | |
11324 | + | |
11325 | + err = au_dr_brid_init(&dr->dr_brid, path); | |
11326 | + if (unlikely(err)) | |
11327 | + goto out; | |
11328 | + | |
11329 | + if (au_opt_test(au_mntflags(sb), DIRREN)) | |
11330 | + err = au_dr_hino(sb, /*bindex*/-1, br, path); | |
11331 | + | |
11332 | +out: | |
11333 | + AuTraceErr(err); | |
11334 | + return err; | |
11335 | +} | |
11336 | + | |
11337 | +int au_dr_br_fin(struct super_block *sb, struct au_branch *br) | |
11338 | +{ | |
11339 | + int err; | |
11340 | + | |
11341 | + err = 0; | |
11342 | + if (au_br_writable(br->br_perm)) | |
11343 | + err = au_dr_hino(sb, /*bindex*/-1, br, /*path*/NULL); | |
11344 | + if (!err) | |
11345 | + au_dr_hino_free(&br->br_dirren); | |
11346 | + | |
11347 | + return err; | |
11348 | +} | |
11349 | + | |
11350 | +/* ---------------------------------------------------------------------- */ | |
11351 | + | |
11352 | +static int au_brid_str(struct au_dr_brid *brid, struct inode *h_inode, | |
11353 | + char *buf, size_t sz) | |
11354 | +{ | |
11355 | + int err; | |
11356 | + unsigned int major, minor; | |
11357 | + char *p; | |
11358 | + | |
11359 | + p = buf; | |
11360 | + err = snprintf(p, sz, "%d_", brid->type); | |
11361 | + AuDebugOn(err > sz); | |
11362 | + p += err; | |
11363 | + sz -= err; | |
11364 | + switch (brid->type) { | |
11365 | + case AuBrid_Unset: | |
11366 | + return -EINVAL; | |
11367 | + case AuBrid_UUID: | |
11368 | + err = snprintf(p, sz, "%pU", brid->uuid.b); | |
11369 | + break; | |
11370 | + case AuBrid_FSID: | |
11371 | + err = snprintf(p, sz, "%08x-%08x", | |
11372 | + brid->fsid.val[0], brid->fsid.val[1]); | |
11373 | + break; | |
11374 | + case AuBrid_DEV: | |
11375 | + major = MAJOR(brid->dev); | |
11376 | + minor = MINOR(brid->dev); | |
11377 | + if (major <= 0xff && minor <= 0xff) | |
11378 | + err = snprintf(p, sz, "%02x%02x", major, minor); | |
11379 | + else | |
11380 | + err = snprintf(p, sz, "%03x:%05x", major, minor); | |
11381 | + break; | |
11382 | + } | |
11383 | + AuDebugOn(err > sz); | |
11384 | + p += err; | |
11385 | + sz -= err; | |
11386 | + err = snprintf(p, sz, "_%llu", (unsigned long long)h_inode->i_ino); | |
11387 | + AuDebugOn(err > sz); | |
11388 | + p += err; | |
11389 | + sz -= err; | |
11390 | + | |
11391 | + return p - buf; | |
11392 | +} | |
11393 | + | |
11394 | +static int au_drinfo_name(struct au_branch *br, char *name, int len) | |
11395 | +{ | |
11396 | + int rlen; | |
11397 | + struct dentry *br_dentry; | |
11398 | + struct inode *br_inode; | |
11399 | + | |
11400 | + br_dentry = au_br_dentry(br); | |
11401 | + br_inode = d_inode(br_dentry); | |
11402 | + rlen = au_brid_str(&br->br_dirren.dr_brid, br_inode, name, len); | |
11403 | + AuDebugOn(rlen >= AUFS_DIRREN_ENV_VAL_SZ); | |
11404 | + AuDebugOn(rlen > len); | |
11405 | + | |
11406 | + return rlen; | |
11407 | +} | |
11408 | + | |
11409 | +/* ---------------------------------------------------------------------- */ | |
11410 | + | |
11411 | +/* | |
11412 | + * from the given @h_dentry, construct drinfo at @*fdata. | |
11413 | + * when the size of @*fdata is not enough, reallocate and return new @fdata and | |
11414 | + * @allocated. | |
11415 | + */ | |
11416 | +static int au_drinfo_construct(struct au_drinfo_fdata **fdata, | |
11417 | + struct dentry *h_dentry, | |
11418 | + unsigned char *allocated) | |
11419 | +{ | |
11420 | + int err, v; | |
11421 | + struct au_drinfo_fdata *f, *p; | |
11422 | + struct au_drinfo *drinfo; | |
11423 | + struct inode *h_inode; | |
11424 | + struct qstr *qname; | |
11425 | + | |
11426 | + err = 0; | |
11427 | + f = *fdata; | |
11428 | + h_inode = d_inode(h_dentry); | |
11429 | + qname = &h_dentry->d_name; | |
11430 | + drinfo = &f->drinfo; | |
11431 | + drinfo->ino = (__force uint64_t)cpu_to_be64(h_inode->i_ino); | |
11432 | + drinfo->oldnamelen = qname->len; | |
11433 | + if (*allocated < sizeof(*f) + qname->len) { | |
11434 | + v = roundup_pow_of_two(*allocated + qname->len); | |
11435 | + p = au_krealloc(f, v, GFP_NOFS, /*may_shrink*/0); | |
11436 | + if (unlikely(!p)) { | |
11437 | + err = -ENOMEM; | |
11438 | + AuTraceErr(err); | |
11439 | + goto out; | |
11440 | + } | |
11441 | + f = p; | |
11442 | + *fdata = f; | |
11443 | + *allocated = v; | |
11444 | + drinfo = &f->drinfo; | |
11445 | + } | |
11446 | + memcpy(drinfo->oldname, qname->name, qname->len); | |
11447 | + AuDbg("i%llu, %.*s\n", | |
11448 | + be64_to_cpu((__force __be64)drinfo->ino), drinfo->oldnamelen, | |
11449 | + drinfo->oldname); | |
11450 | + | |
11451 | +out: | |
11452 | + AuTraceErr(err); | |
11453 | + return err; | |
11454 | +} | |
11455 | + | |
11456 | +/* callers have to free the return value */ | |
11457 | +static struct au_drinfo *au_drinfo_read_k(struct file *file, ino_t h_ino) | |
11458 | +{ | |
11459 | + struct au_drinfo *ret, *drinfo; | |
11460 | + struct au_drinfo_fdata fdata; | |
11461 | + int len; | |
11462 | + loff_t pos; | |
11463 | + ssize_t ssz; | |
11464 | + | |
11465 | + ret = ERR_PTR(-EIO); | |
11466 | + pos = 0; | |
11467 | + ssz = vfsub_read_k(file, &fdata, sizeof(fdata), &pos); | |
11468 | + if (unlikely(ssz != sizeof(fdata))) { | |
11469 | + AuIOErr("ssz %zd, %u, %pD2\n", | |
11470 | + ssz, (unsigned int)sizeof(fdata), file); | |
11471 | + goto out; | |
11472 | + } | |
11473 | + | |
11474 | + fdata.magic = ntohl((__force __be32)fdata.magic); | |
11475 | + switch (fdata.magic) { | |
11476 | + case AUFS_DRINFO_MAGIC_V1: | |
11477 | + break; | |
11478 | + default: | |
11479 | + AuIOErr("magic-num 0x%x, 0x%x, %pD2\n", | |
11480 | + fdata.magic, AUFS_DRINFO_MAGIC_V1, file); | |
11481 | + goto out; | |
11482 | + } | |
11483 | + | |
11484 | + drinfo = &fdata.drinfo; | |
11485 | + len = drinfo->oldnamelen; | |
11486 | + if (!len) { | |
11487 | + AuIOErr("broken drinfo %pD2\n", file); | |
11488 | + goto out; | |
11489 | + } | |
11490 | + | |
11491 | + ret = NULL; | |
11492 | + drinfo->ino = be64_to_cpu((__force __be64)drinfo->ino); | |
11493 | + if (unlikely(h_ino && drinfo->ino != h_ino)) { | |
11494 | + AuDbg("ignored i%llu, i%llu, %pD2\n", | |
11495 | + (unsigned long long)drinfo->ino, | |
11496 | + (unsigned long long)h_ino, file); | |
11497 | + goto out; /* success */ | |
11498 | + } | |
11499 | + | |
11500 | + ret = kmalloc(sizeof(*ret) + len, GFP_NOFS); | |
11501 | + if (unlikely(!ret)) { | |
11502 | + ret = ERR_PTR(-ENOMEM); | |
11503 | + AuTraceErrPtr(ret); | |
11504 | + goto out; | |
11505 | + } | |
11506 | + | |
11507 | + *ret = *drinfo; | |
11508 | + ssz = vfsub_read_k(file, (void *)ret->oldname, len, &pos); | |
11509 | + if (unlikely(ssz != len)) { | |
9f237c51 | 11510 | + au_kfree_rcu(ret); |
8b6a4947 AM |
11511 | + ret = ERR_PTR(-EIO); |
11512 | + AuIOErr("ssz %zd, %u, %pD2\n", ssz, len, file); | |
11513 | + goto out; | |
11514 | + } | |
11515 | + | |
11516 | + AuDbg("oldname %.*s\n", ret->oldnamelen, ret->oldname); | |
11517 | + | |
11518 | +out: | |
11519 | + return ret; | |
11520 | +} | |
11521 | + | |
11522 | +/* ---------------------------------------------------------------------- */ | |
11523 | + | |
11524 | +/* in order to be revertible */ | |
11525 | +struct au_drinfo_rev_elm { | |
11526 | + int created; | |
11527 | + struct dentry *info_dentry; | |
11528 | + struct au_drinfo *info_last; | |
11529 | +}; | |
11530 | + | |
11531 | +struct au_drinfo_rev { | |
11532 | + unsigned char already; | |
11533 | + aufs_bindex_t nelm; | |
11534 | + struct au_drinfo_rev_elm elm[0]; | |
11535 | +}; | |
11536 | + | |
11537 | +/* todo: isn't it too large? */ | |
11538 | +struct au_drinfo_store { | |
11539 | + struct path h_ppath; | |
11540 | + struct dentry *h_dentry; | |
11541 | + struct au_drinfo_fdata *fdata; | |
11542 | + char *infoname; /* inside of whname, just after PFX */ | |
11543 | + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ]; | |
11544 | + aufs_bindex_t btgt, btail; | |
11545 | + unsigned char no_sio, | |
11546 | + allocated, /* current size of *fdata */ | |
11547 | + infonamelen, /* room size for p */ | |
acd2b654 | 11548 | + whnamelen, /* length of the generated name */ |
8b6a4947 AM |
11549 | + renameback; /* renamed back */ |
11550 | +}; | |
11551 | + | |
11552 | +/* on rename(2) error, the caller should revert it using @elm */ | |
11553 | +static int au_drinfo_do_store(struct au_drinfo_store *w, | |
11554 | + struct au_drinfo_rev_elm *elm) | |
11555 | +{ | |
11556 | + int err, len; | |
11557 | + ssize_t ssz; | |
11558 | + loff_t pos; | |
11559 | + struct path infopath = { | |
11560 | + .mnt = w->h_ppath.mnt | |
11561 | + }; | |
11562 | + struct inode *h_dir, *h_inode, *delegated; | |
11563 | + struct file *infofile; | |
11564 | + struct qstr *qname; | |
11565 | + | |
11566 | + AuDebugOn(elm | |
11567 | + && memcmp(elm, page_address(ZERO_PAGE(0)), sizeof(*elm))); | |
11568 | + | |
11569 | + infopath.dentry = vfsub_lookup_one_len(w->whname, w->h_ppath.dentry, | |
11570 | + w->whnamelen); | |
11571 | + AuTraceErrPtr(infopath.dentry); | |
11572 | + if (IS_ERR(infopath.dentry)) { | |
11573 | + err = PTR_ERR(infopath.dentry); | |
11574 | + goto out; | |
11575 | + } | |
11576 | + | |
11577 | + err = 0; | |
11578 | + h_dir = d_inode(w->h_ppath.dentry); | |
11579 | + if (elm && d_is_negative(infopath.dentry)) { | |
11580 | + err = vfsub_create(h_dir, &infopath, 0600, /*want_excl*/true); | |
11581 | + AuTraceErr(err); | |
11582 | + if (unlikely(err)) | |
11583 | + goto out_dput; | |
11584 | + elm->created = 1; | |
11585 | + elm->info_dentry = dget(infopath.dentry); | |
11586 | + } | |
11587 | + | |
11588 | + infofile = vfsub_dentry_open(&infopath, O_RDWR); | |
11589 | + AuTraceErrPtr(infofile); | |
11590 | + if (IS_ERR(infofile)) { | |
11591 | + err = PTR_ERR(infofile); | |
11592 | + goto out_dput; | |
11593 | + } | |
11594 | + | |
11595 | + h_inode = d_inode(infopath.dentry); | |
11596 | + if (elm && i_size_read(h_inode)) { | |
11597 | + h_inode = d_inode(w->h_dentry); | |
11598 | + elm->info_last = au_drinfo_read_k(infofile, h_inode->i_ino); | |
11599 | + AuTraceErrPtr(elm->info_last); | |
11600 | + if (IS_ERR(elm->info_last)) { | |
11601 | + err = PTR_ERR(elm->info_last); | |
11602 | + elm->info_last = NULL; | |
11603 | + AuDebugOn(elm->info_dentry); | |
11604 | + goto out_fput; | |
11605 | + } | |
11606 | + } | |
11607 | + | |
11608 | + if (elm && w->renameback) { | |
11609 | + delegated = NULL; | |
11610 | + err = vfsub_unlink(h_dir, &infopath, &delegated, /*force*/0); | |
11611 | + AuTraceErr(err); | |
11612 | + if (unlikely(err == -EWOULDBLOCK)) | |
11613 | + iput(delegated); | |
11614 | + goto out_fput; | |
11615 | + } | |
11616 | + | |
11617 | + pos = 0; | |
11618 | + qname = &w->h_dentry->d_name; | |
11619 | + len = sizeof(*w->fdata) + qname->len; | |
11620 | + if (!elm) | |
11621 | + len = sizeof(*w->fdata) + w->fdata->drinfo.oldnamelen; | |
11622 | + ssz = vfsub_write_k(infofile, w->fdata, len, &pos); | |
11623 | + if (ssz == len) { | |
11624 | + AuDbg("hi%llu, %.*s\n", w->fdata->drinfo.ino, | |
11625 | + w->fdata->drinfo.oldnamelen, w->fdata->drinfo.oldname); | |
11626 | + goto out_fput; /* success */ | |
11627 | + } else { | |
11628 | + err = -EIO; | |
11629 | + if (ssz < 0) | |
11630 | + err = ssz; | |
11631 | + /* the caller should revert it using @elm */ | |
11632 | + } | |
11633 | + | |
11634 | +out_fput: | |
11635 | + fput(infofile); | |
11636 | +out_dput: | |
11637 | + dput(infopath.dentry); | |
11638 | +out: | |
11639 | + AuTraceErr(err); | |
11640 | + return err; | |
11641 | +} | |
11642 | + | |
11643 | +struct au_call_drinfo_do_store_args { | |
11644 | + int *errp; | |
11645 | + struct au_drinfo_store *w; | |
11646 | + struct au_drinfo_rev_elm *elm; | |
11647 | +}; | |
11648 | + | |
11649 | +static void au_call_drinfo_do_store(void *args) | |
11650 | +{ | |
11651 | + struct au_call_drinfo_do_store_args *a = args; | |
11652 | + | |
11653 | + *a->errp = au_drinfo_do_store(a->w, a->elm); | |
11654 | +} | |
11655 | + | |
11656 | +static int au_drinfo_store_sio(struct au_drinfo_store *w, | |
11657 | + struct au_drinfo_rev_elm *elm) | |
11658 | +{ | |
11659 | + int err, wkq_err; | |
11660 | + | |
11661 | + if (w->no_sio) | |
11662 | + err = au_drinfo_do_store(w, elm); | |
11663 | + else { | |
11664 | + struct au_call_drinfo_do_store_args a = { | |
11665 | + .errp = &err, | |
11666 | + .w = w, | |
11667 | + .elm = elm | |
11668 | + }; | |
11669 | + wkq_err = au_wkq_wait(au_call_drinfo_do_store, &a); | |
11670 | + if (unlikely(wkq_err)) | |
11671 | + err = wkq_err; | |
11672 | + } | |
11673 | + AuTraceErr(err); | |
11674 | + | |
11675 | + return err; | |
11676 | +} | |
11677 | + | |
11678 | +static int au_drinfo_store_work_init(struct au_drinfo_store *w, | |
11679 | + aufs_bindex_t btgt) | |
11680 | +{ | |
11681 | + int err; | |
11682 | + | |
11683 | + memset(w, 0, sizeof(*w)); | |
11684 | + w->allocated = roundup_pow_of_two(sizeof(*w->fdata) + 40); | |
11685 | + strcpy(w->whname, AUFS_WH_DR_INFO_PFX); | |
11686 | + w->infoname = w->whname + sizeof(AUFS_WH_DR_INFO_PFX) - 1; | |
11687 | + w->infonamelen = sizeof(w->whname) - sizeof(AUFS_WH_DR_INFO_PFX); | |
11688 | + w->btgt = btgt; | |
11689 | + w->no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID); | |
11690 | + | |
11691 | + err = -ENOMEM; | |
11692 | + w->fdata = kcalloc(1, w->allocated, GFP_NOFS); | |
11693 | + if (unlikely(!w->fdata)) { | |
11694 | + AuTraceErr(err); | |
11695 | + goto out; | |
11696 | + } | |
11697 | + w->fdata->magic = (__force uint32_t)htonl(AUFS_DRINFO_MAGIC_V1); | |
11698 | + err = 0; | |
11699 | + | |
11700 | +out: | |
11701 | + return err; | |
11702 | +} | |
11703 | + | |
11704 | +static void au_drinfo_store_work_fin(struct au_drinfo_store *w) | |
11705 | +{ | |
9f237c51 | 11706 | + au_kfree_rcu(w->fdata); |
8b6a4947 AM |
11707 | +} |
11708 | + | |
11709 | +static void au_drinfo_store_rev(struct au_drinfo_rev *rev, | |
11710 | + struct au_drinfo_store *w) | |
11711 | +{ | |
11712 | + struct au_drinfo_rev_elm *elm; | |
11713 | + struct inode *h_dir, *delegated; | |
11714 | + int err, nelm; | |
11715 | + struct path infopath = { | |
11716 | + .mnt = w->h_ppath.mnt | |
11717 | + }; | |
11718 | + | |
11719 | + h_dir = d_inode(w->h_ppath.dentry); | |
11720 | + IMustLock(h_dir); | |
11721 | + | |
11722 | + err = 0; | |
11723 | + elm = rev->elm; | |
11724 | + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) { | |
11725 | + AuDebugOn(elm->created && elm->info_last); | |
11726 | + if (elm->created) { | |
11727 | + AuDbg("here\n"); | |
11728 | + delegated = NULL; | |
11729 | + infopath.dentry = elm->info_dentry; | |
11730 | + err = vfsub_unlink(h_dir, &infopath, &delegated, | |
11731 | + !w->no_sio); | |
11732 | + AuTraceErr(err); | |
11733 | + if (unlikely(err == -EWOULDBLOCK)) | |
11734 | + iput(delegated); | |
11735 | + dput(elm->info_dentry); | |
11736 | + } else if (elm->info_last) { | |
11737 | + AuDbg("here\n"); | |
11738 | + w->fdata->drinfo = *elm->info_last; | |
11739 | + memcpy(w->fdata->drinfo.oldname, | |
11740 | + elm->info_last->oldname, | |
11741 | + elm->info_last->oldnamelen); | |
11742 | + err = au_drinfo_store_sio(w, /*elm*/NULL); | |
9f237c51 | 11743 | + au_kfree_rcu(elm->info_last); |
8b6a4947 AM |
11744 | + } |
11745 | + if (unlikely(err)) | |
11746 | + AuIOErr("%d, %s\n", err, w->whname); | |
11747 | + /* go on even if err */ | |
11748 | + } | |
11749 | +} | |
11750 | + | |
11751 | +/* caller has to call au_dr_rename_fin() later */ | |
11752 | +static int au_drinfo_store(struct dentry *dentry, aufs_bindex_t btgt, | |
11753 | + struct qstr *dst_name, void *_rev) | |
11754 | +{ | |
11755 | + int err, sz, nelm; | |
11756 | + aufs_bindex_t bindex, btail; | |
11757 | + struct au_drinfo_store work; | |
11758 | + struct au_drinfo_rev *rev, **p; | |
11759 | + struct au_drinfo_rev_elm *elm; | |
11760 | + struct super_block *sb; | |
11761 | + struct au_branch *br; | |
11762 | + struct au_hinode *hdir; | |
11763 | + | |
11764 | + err = au_drinfo_store_work_init(&work, btgt); | |
11765 | + AuTraceErr(err); | |
11766 | + if (unlikely(err)) | |
11767 | + goto out; | |
11768 | + | |
11769 | + err = -ENOMEM; | |
11770 | + btail = au_dbtaildir(dentry); | |
11771 | + nelm = btail - btgt; | |
11772 | + sz = sizeof(*rev) + sizeof(*elm) * nelm; | |
11773 | + rev = kcalloc(1, sz, GFP_NOFS); | |
11774 | + if (unlikely(!rev)) { | |
11775 | + AuTraceErr(err); | |
11776 | + goto out_args; | |
11777 | + } | |
11778 | + rev->nelm = nelm; | |
11779 | + elm = rev->elm; | |
11780 | + p = _rev; | |
11781 | + *p = rev; | |
11782 | + | |
11783 | + err = 0; | |
11784 | + sb = dentry->d_sb; | |
11785 | + work.h_ppath.dentry = au_h_dptr(dentry, btgt); | |
11786 | + work.h_ppath.mnt = au_sbr_mnt(sb, btgt); | |
11787 | + hdir = au_hi(d_inode(dentry), btgt); | |
11788 | + au_hn_inode_lock_nested(hdir, AuLsc_I_CHILD); | |
11789 | + for (bindex = btgt + 1; bindex <= btail; bindex++, elm++) { | |
11790 | + work.h_dentry = au_h_dptr(dentry, bindex); | |
11791 | + if (!work.h_dentry) | |
11792 | + continue; | |
11793 | + | |
11794 | + err = au_drinfo_construct(&work.fdata, work.h_dentry, | |
11795 | + &work.allocated); | |
11796 | + AuTraceErr(err); | |
11797 | + if (unlikely(err)) | |
11798 | + break; | |
11799 | + | |
11800 | + work.renameback = au_qstreq(&work.h_dentry->d_name, dst_name); | |
11801 | + br = au_sbr(sb, bindex); | |
11802 | + work.whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1; | |
11803 | + work.whnamelen += au_drinfo_name(br, work.infoname, | |
11804 | + work.infonamelen); | |
11805 | + AuDbg("whname %.*s, i%llu, %.*s\n", | |
11806 | + work.whnamelen, work.whname, | |
11807 | + be64_to_cpu((__force __be64)work.fdata->drinfo.ino), | |
11808 | + work.fdata->drinfo.oldnamelen, | |
11809 | + work.fdata->drinfo.oldname); | |
11810 | + | |
11811 | + err = au_drinfo_store_sio(&work, elm); | |
11812 | + AuTraceErr(err); | |
11813 | + if (unlikely(err)) | |
11814 | + break; | |
11815 | + } | |
11816 | + if (unlikely(err)) { | |
11817 | + /* revert all drinfo */ | |
11818 | + au_drinfo_store_rev(rev, &work); | |
9f237c51 | 11819 | + au_kfree_try_rcu(rev); |
8b6a4947 AM |
11820 | + *p = NULL; |
11821 | + } | |
11822 | + au_hn_inode_unlock(hdir); | |
11823 | + | |
11824 | +out_args: | |
11825 | + au_drinfo_store_work_fin(&work); | |
11826 | +out: | |
11827 | + return err; | |
11828 | +} | |
11829 | + | |
11830 | +/* ---------------------------------------------------------------------- */ | |
11831 | + | |
11832 | +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex, | |
11833 | + struct qstr *dst_name, void *_rev) | |
11834 | +{ | |
11835 | + int err, already; | |
11836 | + ino_t ino; | |
11837 | + struct super_block *sb; | |
11838 | + struct au_branch *br; | |
11839 | + struct au_dr_br *dr; | |
11840 | + struct dentry *h_dentry; | |
11841 | + struct inode *h_inode; | |
11842 | + struct au_dr_hino *ent; | |
11843 | + struct au_drinfo_rev *rev, **p; | |
11844 | + | |
11845 | + AuDbg("bindex %d\n", bindex); | |
11846 | + | |
11847 | + err = -ENOMEM; | |
11848 | + ent = kmalloc(sizeof(*ent), GFP_NOFS); | |
11849 | + if (unlikely(!ent)) | |
11850 | + goto out; | |
11851 | + | |
11852 | + sb = src->d_sb; | |
11853 | + br = au_sbr(sb, bindex); | |
11854 | + dr = &br->br_dirren; | |
11855 | + h_dentry = au_h_dptr(src, bindex); | |
11856 | + h_inode = d_inode(h_dentry); | |
11857 | + ino = h_inode->i_ino; | |
11858 | + ent->dr_h_ino = ino; | |
11859 | + already = au_dr_hino_test_add(dr, ino, ent); | |
11860 | + AuDbg("b%d, hi%llu, already %d\n", | |
11861 | + bindex, (unsigned long long)ino, already); | |
11862 | + | |
11863 | + err = au_drinfo_store(src, bindex, dst_name, _rev); | |
11864 | + AuTraceErr(err); | |
11865 | + if (!err) { | |
11866 | + p = _rev; | |
11867 | + rev = *p; | |
11868 | + rev->already = already; | |
11869 | + goto out; /* success */ | |
11870 | + } | |
11871 | + | |
11872 | + /* revert */ | |
11873 | + if (!already) | |
11874 | + au_dr_hino_del(dr, ent); | |
9f237c51 | 11875 | + au_kfree_rcu(ent); |
8b6a4947 AM |
11876 | + |
11877 | +out: | |
11878 | + AuTraceErr(err); | |
11879 | + return err; | |
11880 | +} | |
11881 | + | |
11882 | +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *_rev) | |
11883 | +{ | |
11884 | + struct au_drinfo_rev *rev; | |
11885 | + struct au_drinfo_rev_elm *elm; | |
11886 | + int nelm; | |
11887 | + | |
11888 | + rev = _rev; | |
11889 | + elm = rev->elm; | |
11890 | + for (nelm = rev->nelm; nelm > 0; nelm--, elm++) { | |
11891 | + dput(elm->info_dentry); | |
9f237c51 | 11892 | + au_kfree_rcu(elm->info_last); |
8b6a4947 | 11893 | + } |
9f237c51 | 11894 | + au_kfree_try_rcu(rev); |
8b6a4947 AM |
11895 | +} |
11896 | + | |
11897 | +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t btgt, void *_rev) | |
11898 | +{ | |
11899 | + int err; | |
11900 | + struct au_drinfo_store work; | |
11901 | + struct au_drinfo_rev *rev = _rev; | |
11902 | + struct super_block *sb; | |
11903 | + struct au_branch *br; | |
11904 | + struct inode *h_inode; | |
11905 | + struct au_dr_br *dr; | |
11906 | + struct au_dr_hino *ent; | |
11907 | + | |
11908 | + err = au_drinfo_store_work_init(&work, btgt); | |
11909 | + if (unlikely(err)) | |
11910 | + goto out; | |
11911 | + | |
11912 | + sb = src->d_sb; | |
11913 | + br = au_sbr(sb, btgt); | |
11914 | + work.h_ppath.dentry = au_h_dptr(src, btgt); | |
11915 | + work.h_ppath.mnt = au_br_mnt(br); | |
11916 | + au_drinfo_store_rev(rev, &work); | |
11917 | + au_drinfo_store_work_fin(&work); | |
11918 | + if (rev->already) | |
11919 | + goto out; | |
11920 | + | |
11921 | + dr = &br->br_dirren; | |
11922 | + h_inode = d_inode(work.h_ppath.dentry); | |
11923 | + ent = au_dr_hino_find(dr, h_inode->i_ino); | |
11924 | + BUG_ON(!ent); | |
11925 | + au_dr_hino_del(dr, ent); | |
9f237c51 | 11926 | + au_kfree_rcu(ent); |
8b6a4947 AM |
11927 | + |
11928 | +out: | |
9f237c51 | 11929 | + au_kfree_try_rcu(rev); |
8b6a4947 AM |
11930 | + if (unlikely(err)) |
11931 | + pr_err("failed to remove dirren info\n"); | |
11932 | +} | |
11933 | + | |
11934 | +/* ---------------------------------------------------------------------- */ | |
11935 | + | |
11936 | +static struct au_drinfo *au_drinfo_do_load(struct path *h_ppath, | |
11937 | + char *whname, int whnamelen, | |
11938 | + struct dentry **info_dentry) | |
11939 | +{ | |
11940 | + struct au_drinfo *drinfo; | |
11941 | + struct file *f; | |
11942 | + struct inode *h_dir; | |
11943 | + struct path infopath; | |
11944 | + int unlocked; | |
11945 | + | |
11946 | + AuDbg("%pd/%.*s\n", h_ppath->dentry, whnamelen, whname); | |
11947 | + | |
11948 | + *info_dentry = NULL; | |
11949 | + drinfo = NULL; | |
11950 | + unlocked = 0; | |
11951 | + h_dir = d_inode(h_ppath->dentry); | |
be118d29 | 11952 | + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT); |
8b6a4947 AM |
11953 | + infopath.dentry = vfsub_lookup_one_len(whname, h_ppath->dentry, |
11954 | + whnamelen); | |
11955 | + if (IS_ERR(infopath.dentry)) { | |
11956 | + drinfo = (void *)infopath.dentry; | |
11957 | + goto out; | |
11958 | + } | |
11959 | + | |
11960 | + if (d_is_negative(infopath.dentry)) | |
11961 | + goto out_dput; /* success */ | |
11962 | + | |
11963 | + infopath.mnt = h_ppath->mnt; | |
11964 | + f = vfsub_dentry_open(&infopath, O_RDONLY); | |
11965 | + inode_unlock_shared(h_dir); | |
11966 | + unlocked = 1; | |
11967 | + if (IS_ERR(f)) { | |
11968 | + drinfo = (void *)f; | |
11969 | + goto out_dput; | |
11970 | + } | |
11971 | + | |
11972 | + drinfo = au_drinfo_read_k(f, /*h_ino*/0); | |
11973 | + if (IS_ERR_OR_NULL(drinfo)) | |
11974 | + goto out_fput; | |
11975 | + | |
11976 | + AuDbg("oldname %.*s\n", drinfo->oldnamelen, drinfo->oldname); | |
11977 | + *info_dentry = dget(infopath.dentry); /* keep it alive */ | |
11978 | + | |
11979 | +out_fput: | |
11980 | + fput(f); | |
11981 | +out_dput: | |
11982 | + dput(infopath.dentry); | |
11983 | +out: | |
11984 | + if (!unlocked) | |
11985 | + inode_unlock_shared(h_dir); | |
11986 | + AuTraceErrPtr(drinfo); | |
11987 | + return drinfo; | |
11988 | +} | |
11989 | + | |
11990 | +struct au_drinfo_do_load_args { | |
11991 | + struct au_drinfo **drinfop; | |
11992 | + struct path *h_ppath; | |
11993 | + char *whname; | |
11994 | + int whnamelen; | |
11995 | + struct dentry **info_dentry; | |
11996 | +}; | |
11997 | + | |
11998 | +static void au_call_drinfo_do_load(void *args) | |
11999 | +{ | |
12000 | + struct au_drinfo_do_load_args *a = args; | |
12001 | + | |
12002 | + *a->drinfop = au_drinfo_do_load(a->h_ppath, a->whname, a->whnamelen, | |
12003 | + a->info_dentry); | |
12004 | +} | |
12005 | + | |
12006 | +struct au_drinfo_load { | |
12007 | + struct path h_ppath; | |
12008 | + struct qstr *qname; | |
12009 | + unsigned char no_sio; | |
12010 | + | |
12011 | + aufs_bindex_t ninfo; | |
12012 | + struct au_drinfo **drinfo; | |
12013 | +}; | |
12014 | + | |
12015 | +static int au_drinfo_load(struct au_drinfo_load *w, aufs_bindex_t bindex, | |
12016 | + struct au_branch *br) | |
12017 | +{ | |
12018 | + int err, wkq_err, whnamelen, e; | |
12019 | + char whname[sizeof(AUFS_WH_DR_INFO_PFX) + AUFS_DIRREN_ENV_VAL_SZ] | |
12020 | + = AUFS_WH_DR_INFO_PFX; | |
12021 | + struct au_drinfo *drinfo; | |
12022 | + struct qstr oldname; | |
12023 | + struct inode *h_dir, *delegated; | |
12024 | + struct dentry *info_dentry; | |
12025 | + struct path infopath; | |
12026 | + | |
12027 | + whnamelen = sizeof(AUFS_WH_DR_INFO_PFX) - 1; | |
12028 | + whnamelen += au_drinfo_name(br, whname + whnamelen, | |
12029 | + sizeof(whname) - whnamelen); | |
12030 | + if (w->no_sio) | |
12031 | + drinfo = au_drinfo_do_load(&w->h_ppath, whname, whnamelen, | |
12032 | + &info_dentry); | |
12033 | + else { | |
12034 | + struct au_drinfo_do_load_args args = { | |
12035 | + .drinfop = &drinfo, | |
12036 | + .h_ppath = &w->h_ppath, | |
12037 | + .whname = whname, | |
12038 | + .whnamelen = whnamelen, | |
12039 | + .info_dentry = &info_dentry | |
12040 | + }; | |
12041 | + wkq_err = au_wkq_wait(au_call_drinfo_do_load, &args); | |
12042 | + if (unlikely(wkq_err)) | |
12043 | + drinfo = ERR_PTR(wkq_err); | |
12044 | + } | |
12045 | + err = PTR_ERR(drinfo); | |
12046 | + if (IS_ERR_OR_NULL(drinfo)) | |
12047 | + goto out; | |
12048 | + | |
12049 | + err = 0; | |
12050 | + oldname.len = drinfo->oldnamelen; | |
12051 | + oldname.name = drinfo->oldname; | |
12052 | + if (au_qstreq(w->qname, &oldname)) { | |
12053 | + /* the name is renamed back */ | |
9f237c51 | 12054 | + au_kfree_rcu(drinfo); |
8b6a4947 AM |
12055 | + drinfo = NULL; |
12056 | + | |
12057 | + infopath.dentry = info_dentry; | |
12058 | + infopath.mnt = w->h_ppath.mnt; | |
12059 | + h_dir = d_inode(w->h_ppath.dentry); | |
12060 | + delegated = NULL; | |
12061 | + inode_lock_nested(h_dir, AuLsc_I_PARENT); | |
12062 | + e = vfsub_unlink(h_dir, &infopath, &delegated, !w->no_sio); | |
12063 | + inode_unlock(h_dir); | |
12064 | + if (unlikely(e)) | |
12065 | + AuIOErr("ignored %d, %pd2\n", e, &infopath.dentry); | |
12066 | + if (unlikely(e == -EWOULDBLOCK)) | |
12067 | + iput(delegated); | |
12068 | + } | |
9f237c51 | 12069 | + au_kfree_rcu(w->drinfo[bindex]); |
8b6a4947 AM |
12070 | + w->drinfo[bindex] = drinfo; |
12071 | + dput(info_dentry); | |
12072 | + | |
12073 | +out: | |
12074 | + AuTraceErr(err); | |
12075 | + return err; | |
12076 | +} | |
12077 | + | |
12078 | +/* ---------------------------------------------------------------------- */ | |
12079 | + | |
12080 | +static void au_dr_lkup_free(struct au_drinfo **drinfo, int n) | |
12081 | +{ | |
12082 | + struct au_drinfo **p = drinfo; | |
12083 | + | |
12084 | + while (n-- > 0) | |
9f237c51 AM |
12085 | + au_kfree_rcu(*drinfo++); |
12086 | + au_kfree_try_rcu(p); | |
8b6a4947 AM |
12087 | +} |
12088 | + | |
12089 | +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry, | |
12090 | + aufs_bindex_t btgt) | |
12091 | +{ | |
12092 | + int err, ninfo; | |
12093 | + struct au_drinfo_load w; | |
12094 | + aufs_bindex_t bindex, bbot; | |
12095 | + struct au_branch *br; | |
12096 | + struct inode *h_dir; | |
12097 | + struct au_dr_hino *ent; | |
12098 | + struct super_block *sb; | |
12099 | + | |
12100 | + AuDbg("%.*s, name %.*s, whname %.*s, b%d\n", | |
12101 | + AuLNPair(&dentry->d_name), AuLNPair(&lkup->dirren.dr_name), | |
12102 | + AuLNPair(&lkup->whname), btgt); | |
12103 | + | |
12104 | + sb = dentry->d_sb; | |
12105 | + bbot = au_sbbot(sb); | |
12106 | + w.ninfo = bbot + 1; | |
12107 | + if (!lkup->dirren.drinfo) { | |
12108 | + lkup->dirren.drinfo = kcalloc(w.ninfo, | |
12109 | + sizeof(*lkup->dirren.drinfo), | |
12110 | + GFP_NOFS); | |
12111 | + if (unlikely(!lkup->dirren.drinfo)) { | |
12112 | + err = -ENOMEM; | |
12113 | + goto out; | |
12114 | + } | |
12115 | + lkup->dirren.ninfo = w.ninfo; | |
12116 | + } | |
12117 | + w.drinfo = lkup->dirren.drinfo; | |
12118 | + w.no_sio = !!uid_eq(current_fsuid(), GLOBAL_ROOT_UID); | |
12119 | + w.h_ppath.dentry = au_h_dptr(dentry, btgt); | |
12120 | + AuDebugOn(!w.h_ppath.dentry); | |
12121 | + w.h_ppath.mnt = au_sbr_mnt(sb, btgt); | |
12122 | + w.qname = &dentry->d_name; | |
12123 | + | |
12124 | + ninfo = 0; | |
12125 | + for (bindex = btgt + 1; bindex <= bbot; bindex++) { | |
12126 | + br = au_sbr(sb, bindex); | |
12127 | + err = au_drinfo_load(&w, bindex, br); | |
12128 | + if (unlikely(err)) | |
12129 | + goto out_free; | |
12130 | + if (w.drinfo[bindex]) | |
12131 | + ninfo++; | |
12132 | + } | |
12133 | + if (!ninfo) { | |
12134 | + br = au_sbr(sb, btgt); | |
12135 | + h_dir = d_inode(w.h_ppath.dentry); | |
12136 | + ent = au_dr_hino_find(&br->br_dirren, h_dir->i_ino); | |
12137 | + AuDebugOn(!ent); | |
12138 | + au_dr_hino_del(&br->br_dirren, ent); | |
9f237c51 | 12139 | + au_kfree_rcu(ent); |
8b6a4947 AM |
12140 | + } |
12141 | + goto out; /* success */ | |
12142 | + | |
12143 | +out_free: | |
12144 | + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo); | |
12145 | + lkup->dirren.ninfo = 0; | |
12146 | + lkup->dirren.drinfo = NULL; | |
12147 | +out: | |
12148 | + AuTraceErr(err); | |
12149 | + return err; | |
12150 | +} | |
12151 | + | |
12152 | +void au_dr_lkup_fin(struct au_do_lookup_args *lkup) | |
12153 | +{ | |
12154 | + au_dr_lkup_free(lkup->dirren.drinfo, lkup->dirren.ninfo); | |
12155 | +} | |
12156 | + | |
12157 | +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt) | |
12158 | +{ | |
12159 | + int err; | |
12160 | + struct au_drinfo *drinfo; | |
12161 | + | |
12162 | + err = 0; | |
12163 | + if (!lkup->dirren.drinfo) | |
12164 | + goto out; | |
43982f53 AM |
12165 | + AuDebugOn(lkup->dirren.ninfo <= btgt); |
12166 | + drinfo = lkup->dirren.drinfo[btgt]; | |
8b6a4947 AM |
12167 | + if (!drinfo) |
12168 | + goto out; | |
12169 | + | |
9f237c51 | 12170 | + au_kfree_try_rcu(lkup->whname.name); |
8b6a4947 AM |
12171 | + lkup->whname.name = NULL; |
12172 | + lkup->dirren.dr_name.len = drinfo->oldnamelen; | |
12173 | + lkup->dirren.dr_name.name = drinfo->oldname; | |
12174 | + lkup->name = &lkup->dirren.dr_name; | |
12175 | + err = au_wh_name_alloc(&lkup->whname, lkup->name); | |
12176 | + if (!err) | |
12177 | + AuDbg("name %.*s, whname %.*s, b%d\n", | |
12178 | + AuLNPair(lkup->name), AuLNPair(&lkup->whname), | |
12179 | + btgt); | |
12180 | + | |
12181 | +out: | |
12182 | + AuTraceErr(err); | |
12183 | + return err; | |
12184 | +} | |
12185 | + | |
12186 | +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex, | |
12187 | + ino_t h_ino) | |
12188 | +{ | |
12189 | + int match; | |
12190 | + struct au_drinfo *drinfo; | |
12191 | + | |
12192 | + match = 1; | |
12193 | + if (!lkup->dirren.drinfo) | |
12194 | + goto out; | |
43982f53 AM |
12195 | + AuDebugOn(lkup->dirren.ninfo <= bindex); |
12196 | + drinfo = lkup->dirren.drinfo[bindex]; | |
8b6a4947 AM |
12197 | + if (!drinfo) |
12198 | + goto out; | |
12199 | + | |
12200 | + match = (drinfo->ino == h_ino); | |
12201 | + AuDbg("match %d\n", match); | |
12202 | + | |
12203 | +out: | |
12204 | + return match; | |
12205 | +} | |
12206 | + | |
12207 | +/* ---------------------------------------------------------------------- */ | |
12208 | + | |
12209 | +int au_dr_opt_set(struct super_block *sb) | |
12210 | +{ | |
12211 | + int err; | |
12212 | + aufs_bindex_t bindex, bbot; | |
12213 | + struct au_branch *br; | |
12214 | + | |
12215 | + err = 0; | |
12216 | + bbot = au_sbbot(sb); | |
12217 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
12218 | + br = au_sbr(sb, bindex); | |
12219 | + err = au_dr_hino(sb, bindex, /*br*/NULL, &br->br_path); | |
12220 | + } | |
12221 | + | |
12222 | + return err; | |
12223 | +} | |
12224 | + | |
12225 | +int au_dr_opt_flush(struct super_block *sb) | |
12226 | +{ | |
12227 | + int err; | |
12228 | + aufs_bindex_t bindex, bbot; | |
12229 | + struct au_branch *br; | |
12230 | + | |
12231 | + err = 0; | |
12232 | + bbot = au_sbbot(sb); | |
12233 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
12234 | + br = au_sbr(sb, bindex); | |
12235 | + if (au_br_writable(br->br_perm)) | |
12236 | + err = au_dr_hino(sb, bindex, /*br*/NULL, /*path*/NULL); | |
12237 | + } | |
12238 | + | |
12239 | + return err; | |
12240 | +} | |
12241 | + | |
12242 | +int au_dr_opt_clr(struct super_block *sb, int no_flush) | |
12243 | +{ | |
12244 | + int err; | |
12245 | + aufs_bindex_t bindex, bbot; | |
12246 | + struct au_branch *br; | |
12247 | + | |
12248 | + err = 0; | |
12249 | + if (!no_flush) { | |
12250 | + err = au_dr_opt_flush(sb); | |
12251 | + if (unlikely(err)) | |
12252 | + goto out; | |
12253 | + } | |
12254 | + | |
12255 | + bbot = au_sbbot(sb); | |
12256 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
12257 | + br = au_sbr(sb, bindex); | |
12258 | + au_dr_hino_free(&br->br_dirren); | |
12259 | + } | |
12260 | + | |
12261 | +out: | |
12262 | + return err; | |
12263 | +} | |
12264 | diff -urN /usr/share/empty/fs/aufs/dirren.h linux/fs/aufs/dirren.h | |
eca34b5c | 12265 | --- /usr/share/empty/fs/aufs/dirren.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 12266 | +++ linux/fs/aufs/dirren.h 2020-01-27 10:57:18.168871450 +0100 |
062440b3 AM |
12267 | @@ -0,0 +1,140 @@ |
12268 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
8b6a4947 | 12269 | +/* |
d58c55f2 | 12270 | + * Copyright (C) 2017-2020 Junjiro R. Okajima |
8b6a4947 AM |
12271 | + * |
12272 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12273 | + * it under the terms of the GNU General Public License as published by | |
12274 | + * the Free Software Foundation; either version 2 of the License, or | |
12275 | + * (at your option) any later version. | |
12276 | + * | |
12277 | + * This program is distributed in the hope that it will be useful, | |
12278 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12279 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12280 | + * GNU General Public License for more details. | |
12281 | + * | |
12282 | + * You should have received a copy of the GNU General Public License | |
12283 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
12284 | + */ | |
12285 | + | |
12286 | +/* | |
12287 | + * renamed dir info | |
12288 | + */ | |
12289 | + | |
12290 | +#ifndef __AUFS_DIRREN_H__ | |
12291 | +#define __AUFS_DIRREN_H__ | |
12292 | + | |
12293 | +#ifdef __KERNEL__ | |
12294 | + | |
12295 | +#include <linux/dcache.h> | |
12296 | +#include <linux/statfs.h> | |
12297 | +#include <linux/uuid.h> | |
12298 | +#include "hbl.h" | |
12299 | + | |
12300 | +#define AuDirren_NHASH 100 | |
12301 | + | |
12302 | +#ifdef CONFIG_AUFS_DIRREN | |
12303 | +enum au_brid_type { | |
12304 | + AuBrid_Unset, | |
12305 | + AuBrid_UUID, | |
12306 | + AuBrid_FSID, | |
12307 | + AuBrid_DEV | |
12308 | +}; | |
12309 | + | |
12310 | +struct au_dr_brid { | |
12311 | + enum au_brid_type type; | |
12312 | + union { | |
12313 | + uuid_t uuid; /* unimplemented yet */ | |
12314 | + fsid_t fsid; | |
12315 | + dev_t dev; | |
12316 | + }; | |
12317 | +}; | |
12318 | + | |
12319 | +/* 20 is the max digits length of ulong 64 */ | |
12320 | +/* brid-type "_" uuid "_" inum */ | |
12321 | +#define AUFS_DIRREN_FNAME_SZ (1 + 1 + UUID_STRING_LEN + 20) | |
12322 | +#define AUFS_DIRREN_ENV_VAL_SZ (AUFS_DIRREN_FNAME_SZ + 1 + 20) | |
12323 | + | |
12324 | +struct au_dr_hino { | |
12325 | + struct hlist_bl_node dr_hnode; | |
12326 | + ino_t dr_h_ino; | |
12327 | +}; | |
12328 | + | |
12329 | +struct au_dr_br { | |
12330 | + struct hlist_bl_head dr_h_ino[AuDirren_NHASH]; | |
12331 | + struct au_dr_brid dr_brid; | |
12332 | +}; | |
12333 | + | |
12334 | +struct au_dr_lookup { | |
12335 | + /* dr_name is pointed by struct au_do_lookup_args.name */ | |
12336 | + struct qstr dr_name; /* subset of dr_info */ | |
12337 | + aufs_bindex_t ninfo; | |
12338 | + struct au_drinfo **drinfo; | |
12339 | +}; | |
12340 | +#else | |
12341 | +struct au_dr_hino; | |
12342 | +/* empty */ | |
12343 | +struct au_dr_br { }; | |
12344 | +struct au_dr_lookup { }; | |
12345 | +#endif | |
12346 | + | |
12347 | +/* ---------------------------------------------------------------------- */ | |
12348 | + | |
12349 | +struct au_branch; | |
12350 | +struct au_do_lookup_args; | |
12351 | +struct au_hinode; | |
12352 | +#ifdef CONFIG_AUFS_DIRREN | |
12353 | +int au_dr_hino_test_add(struct au_dr_br *dr, ino_t h_ino, | |
12354 | + struct au_dr_hino *add_ent); | |
12355 | +void au_dr_hino_free(struct au_dr_br *dr); | |
12356 | +int au_dr_br_init(struct super_block *sb, struct au_branch *br, | |
12357 | + const struct path *path); | |
12358 | +int au_dr_br_fin(struct super_block *sb, struct au_branch *br); | |
12359 | +int au_dr_rename(struct dentry *src, aufs_bindex_t bindex, | |
12360 | + struct qstr *dst_name, void *_rev); | |
12361 | +void au_dr_rename_fin(struct dentry *src, aufs_bindex_t btgt, void *rev); | |
12362 | +void au_dr_rename_rev(struct dentry *src, aufs_bindex_t bindex, void *rev); | |
12363 | +int au_dr_lkup(struct au_do_lookup_args *lkup, struct dentry *dentry, | |
12364 | + aufs_bindex_t bindex); | |
12365 | +int au_dr_lkup_name(struct au_do_lookup_args *lkup, aufs_bindex_t btgt); | |
12366 | +int au_dr_lkup_h_ino(struct au_do_lookup_args *lkup, aufs_bindex_t bindex, | |
12367 | + ino_t h_ino); | |
12368 | +void au_dr_lkup_fin(struct au_do_lookup_args *lkup); | |
12369 | +int au_dr_opt_set(struct super_block *sb); | |
12370 | +int au_dr_opt_flush(struct super_block *sb); | |
12371 | +int au_dr_opt_clr(struct super_block *sb, int no_flush); | |
12372 | +#else | |
12373 | +AuStubInt0(au_dr_hino_test_add, struct au_dr_br *dr, ino_t h_ino, | |
12374 | + struct au_dr_hino *add_ent); | |
12375 | +AuStubVoid(au_dr_hino_free, struct au_dr_br *dr); | |
12376 | +AuStubInt0(au_dr_br_init, struct super_block *sb, struct au_branch *br, | |
12377 | + const struct path *path); | |
12378 | +AuStubInt0(au_dr_br_fin, struct super_block *sb, struct au_branch *br); | |
12379 | +AuStubInt0(au_dr_rename, struct dentry *src, aufs_bindex_t bindex, | |
12380 | + struct qstr *dst_name, void *_rev); | |
12381 | +AuStubVoid(au_dr_rename_fin, struct dentry *src, aufs_bindex_t btgt, void *rev); | |
12382 | +AuStubVoid(au_dr_rename_rev, struct dentry *src, aufs_bindex_t bindex, | |
12383 | + void *rev); | |
12384 | +AuStubInt0(au_dr_lkup, struct au_do_lookup_args *lkup, struct dentry *dentry, | |
12385 | + aufs_bindex_t bindex); | |
12386 | +AuStubInt0(au_dr_lkup_name, struct au_do_lookup_args *lkup, aufs_bindex_t btgt); | |
12387 | +AuStubInt0(au_dr_lkup_h_ino, struct au_do_lookup_args *lkup, | |
12388 | + aufs_bindex_t bindex, ino_t h_ino); | |
12389 | +AuStubVoid(au_dr_lkup_fin, struct au_do_lookup_args *lkup); | |
12390 | +AuStubInt0(au_dr_opt_set, struct super_block *sb); | |
12391 | +AuStubInt0(au_dr_opt_flush, struct super_block *sb); | |
12392 | +AuStubInt0(au_dr_opt_clr, struct super_block *sb, int no_flush); | |
12393 | +#endif | |
12394 | + | |
12395 | +/* ---------------------------------------------------------------------- */ | |
12396 | + | |
12397 | +#ifdef CONFIG_AUFS_DIRREN | |
12398 | +static inline int au_dr_ihash(ino_t h_ino) | |
12399 | +{ | |
12400 | + return h_ino % AuDirren_NHASH; | |
12401 | +} | |
12402 | +#else | |
12403 | +AuStubInt0(au_dr_ihash, ino_t h_ino); | |
12404 | +#endif | |
12405 | + | |
12406 | +#endif /* __KERNEL__ */ | |
12407 | +#endif /* __AUFS_DIRREN_H__ */ | |
7f207e10 | 12408 | diff -urN /usr/share/empty/fs/aufs/dynop.c linux/fs/aufs/dynop.c |
eca34b5c | 12409 | --- /usr/share/empty/fs/aufs/dynop.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 12410 | +++ linux/fs/aufs/dynop.c 2020-01-27 10:57:18.168871450 +0100 |
fbc438ed | 12411 | @@ -0,0 +1,367 @@ |
cd7a4cd9 | 12412 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 12413 | +/* |
d58c55f2 | 12414 | + * Copyright (C) 2010-2020 Junjiro R. Okajima |
1facf9fc | 12415 | + * |
12416 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12417 | + * it under the terms of the GNU General Public License as published by | |
12418 | + * the Free Software Foundation; either version 2 of the License, or | |
12419 | + * (at your option) any later version. | |
dece6358 AM |
12420 | + * |
12421 | + * This program is distributed in the hope that it will be useful, | |
12422 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12423 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12424 | + * GNU General Public License for more details. | |
12425 | + * | |
12426 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12427 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 12428 | + */ |
12429 | + | |
12430 | +/* | |
4a4d8108 | 12431 | + * dynamically customizable operations for regular files |
1facf9fc | 12432 | + */ |
12433 | + | |
1facf9fc | 12434 | +#include "aufs.h" |
12435 | + | |
4a4d8108 | 12436 | +#define DyPrSym(key) AuDbgSym(key->dk_op.dy_hop) |
1facf9fc | 12437 | + |
4a4d8108 AM |
12438 | +/* |
12439 | + * How large will these lists be? | |
12440 | + * Usually just a few elements, 20-30 at most for each, I guess. | |
12441 | + */ | |
8b6a4947 | 12442 | +static struct hlist_bl_head dynop[AuDyLast]; |
4a4d8108 | 12443 | + |
8b6a4947 AM |
12444 | +static struct au_dykey *dy_gfind_get(struct hlist_bl_head *hbl, |
12445 | + const void *h_op) | |
1facf9fc | 12446 | +{ |
4a4d8108 | 12447 | + struct au_dykey *key, *tmp; |
8b6a4947 | 12448 | + struct hlist_bl_node *pos; |
1facf9fc | 12449 | + |
4a4d8108 | 12450 | + key = NULL; |
8b6a4947 AM |
12451 | + hlist_bl_lock(hbl); |
12452 | + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode) | |
4a4d8108 | 12453 | + if (tmp->dk_op.dy_hop == h_op) { |
83b672a5 AM |
12454 | + if (kref_get_unless_zero(&tmp->dk_kref)) |
12455 | + key = tmp; | |
4a4d8108 AM |
12456 | + break; |
12457 | + } | |
8b6a4947 | 12458 | + hlist_bl_unlock(hbl); |
4a4d8108 AM |
12459 | + |
12460 | + return key; | |
1facf9fc | 12461 | +} |
12462 | + | |
4a4d8108 | 12463 | +static struct au_dykey *dy_bradd(struct au_branch *br, struct au_dykey *key) |
1facf9fc | 12464 | +{ |
4a4d8108 AM |
12465 | + struct au_dykey **k, *found; |
12466 | + const void *h_op = key->dk_op.dy_hop; | |
12467 | + int i; | |
1facf9fc | 12468 | + |
4a4d8108 AM |
12469 | + found = NULL; |
12470 | + k = br->br_dykey; | |
12471 | + for (i = 0; i < AuBrDynOp; i++) | |
12472 | + if (k[i]) { | |
12473 | + if (k[i]->dk_op.dy_hop == h_op) { | |
12474 | + found = k[i]; | |
12475 | + break; | |
12476 | + } | |
12477 | + } else | |
12478 | + break; | |
12479 | + if (!found) { | |
12480 | + spin_lock(&br->br_dykey_lock); | |
12481 | + for (; i < AuBrDynOp; i++) | |
12482 | + if (k[i]) { | |
12483 | + if (k[i]->dk_op.dy_hop == h_op) { | |
12484 | + found = k[i]; | |
12485 | + break; | |
12486 | + } | |
12487 | + } else { | |
12488 | + k[i] = key; | |
12489 | + break; | |
12490 | + } | |
12491 | + spin_unlock(&br->br_dykey_lock); | |
12492 | + BUG_ON(i == AuBrDynOp); /* expand the array */ | |
12493 | + } | |
12494 | + | |
12495 | + return found; | |
1facf9fc | 12496 | +} |
12497 | + | |
4a4d8108 | 12498 | +/* kref_get() if @key is already added */ |
8b6a4947 | 12499 | +static struct au_dykey *dy_gadd(struct hlist_bl_head *hbl, struct au_dykey *key) |
4a4d8108 AM |
12500 | +{ |
12501 | + struct au_dykey *tmp, *found; | |
8b6a4947 | 12502 | + struct hlist_bl_node *pos; |
4a4d8108 | 12503 | + const void *h_op = key->dk_op.dy_hop; |
1facf9fc | 12504 | + |
4a4d8108 | 12505 | + found = NULL; |
8b6a4947 AM |
12506 | + hlist_bl_lock(hbl); |
12507 | + hlist_bl_for_each_entry(tmp, pos, hbl, dk_hnode) | |
4a4d8108 | 12508 | + if (tmp->dk_op.dy_hop == h_op) { |
83b672a5 AM |
12509 | + if (kref_get_unless_zero(&tmp->dk_kref)) |
12510 | + found = tmp; | |
4a4d8108 AM |
12511 | + break; |
12512 | + } | |
12513 | + if (!found) | |
8b6a4947 AM |
12514 | + hlist_bl_add_head(&key->dk_hnode, hbl); |
12515 | + hlist_bl_unlock(hbl); | |
1facf9fc | 12516 | + |
4a4d8108 AM |
12517 | + if (!found) |
12518 | + DyPrSym(key); | |
12519 | + return found; | |
12520 | +} | |
12521 | + | |
12522 | +static void dy_free_rcu(struct rcu_head *rcu) | |
1facf9fc | 12523 | +{ |
4a4d8108 AM |
12524 | + struct au_dykey *key; |
12525 | + | |
12526 | + key = container_of(rcu, struct au_dykey, dk_rcu); | |
12527 | + DyPrSym(key); | |
83b672a5 | 12528 | + kfree(key); |
1facf9fc | 12529 | +} |
12530 | + | |
4a4d8108 AM |
12531 | +static void dy_free(struct kref *kref) |
12532 | +{ | |
12533 | + struct au_dykey *key; | |
8b6a4947 | 12534 | + struct hlist_bl_head *hbl; |
1facf9fc | 12535 | + |
4a4d8108 | 12536 | + key = container_of(kref, struct au_dykey, dk_kref); |
8b6a4947 AM |
12537 | + hbl = dynop + key->dk_op.dy_type; |
12538 | + au_hbl_del(&key->dk_hnode, hbl); | |
4a4d8108 AM |
12539 | + call_rcu(&key->dk_rcu, dy_free_rcu); |
12540 | +} | |
12541 | + | |
12542 | +void au_dy_put(struct au_dykey *key) | |
1facf9fc | 12543 | +{ |
4a4d8108 AM |
12544 | + kref_put(&key->dk_kref, dy_free); |
12545 | +} | |
1facf9fc | 12546 | + |
4a4d8108 AM |
12547 | +/* ---------------------------------------------------------------------- */ |
12548 | + | |
12549 | +#define DyDbgSize(cnt, op) AuDebugOn(cnt != sizeof(op)/sizeof(void *)) | |
12550 | + | |
12551 | +#ifdef CONFIG_AUFS_DEBUG | |
12552 | +#define DyDbgDeclare(cnt) unsigned int cnt = 0 | |
4f0767ce | 12553 | +#define DyDbgInc(cnt) do { cnt++; } while (0) |
4a4d8108 AM |
12554 | +#else |
12555 | +#define DyDbgDeclare(cnt) do {} while (0) | |
12556 | +#define DyDbgInc(cnt) do {} while (0) | |
12557 | +#endif | |
12558 | + | |
12559 | +#define DySet(func, dst, src, h_op, h_sb) do { \ | |
12560 | + DyDbgInc(cnt); \ | |
12561 | + if (h_op->func) { \ | |
12562 | + if (src.func) \ | |
12563 | + dst.func = src.func; \ | |
12564 | + else \ | |
12565 | + AuDbg("%s %s\n", au_sbtype(h_sb), #func); \ | |
12566 | + } \ | |
12567 | +} while (0) | |
12568 | + | |
12569 | +#define DySetForce(func, dst, src) do { \ | |
12570 | + AuDebugOn(!src.func); \ | |
12571 | + DyDbgInc(cnt); \ | |
12572 | + dst.func = src.func; \ | |
12573 | +} while (0) | |
12574 | + | |
12575 | +#define DySetAop(func) \ | |
12576 | + DySet(func, dyaop->da_op, aufs_aop, h_aop, h_sb) | |
12577 | +#define DySetAopForce(func) \ | |
12578 | + DySetForce(func, dyaop->da_op, aufs_aop) | |
12579 | + | |
12580 | +static void dy_aop(struct au_dykey *key, const void *h_op, | |
12581 | + struct super_block *h_sb __maybe_unused) | |
12582 | +{ | |
12583 | + struct au_dyaop *dyaop = (void *)key; | |
12584 | + const struct address_space_operations *h_aop = h_op; | |
12585 | + DyDbgDeclare(cnt); | |
12586 | + | |
12587 | + AuDbg("%s\n", au_sbtype(h_sb)); | |
12588 | + | |
12589 | + DySetAop(writepage); | |
12590 | + DySetAopForce(readpage); /* force */ | |
4a4d8108 AM |
12591 | + DySetAop(writepages); |
12592 | + DySetAop(set_page_dirty); | |
12593 | + DySetAop(readpages); | |
12594 | + DySetAop(write_begin); | |
12595 | + DySetAop(write_end); | |
12596 | + DySetAop(bmap); | |
12597 | + DySetAop(invalidatepage); | |
12598 | + DySetAop(releasepage); | |
027c5e7a | 12599 | + DySetAop(freepage); |
7e9cd9fe | 12600 | + /* this one will be changed according to an aufs mount option */ |
4a4d8108 | 12601 | + DySetAop(direct_IO); |
4a4d8108 | 12602 | + DySetAop(migratepage); |
e2f27e51 AM |
12603 | + DySetAop(isolate_page); |
12604 | + DySetAop(putback_page); | |
4a4d8108 AM |
12605 | + DySetAop(launder_page); |
12606 | + DySetAop(is_partially_uptodate); | |
392086de | 12607 | + DySetAop(is_dirty_writeback); |
4a4d8108 | 12608 | + DySetAop(error_remove_page); |
b4510431 AM |
12609 | + DySetAop(swap_activate); |
12610 | + DySetAop(swap_deactivate); | |
4a4d8108 AM |
12611 | + |
12612 | + DyDbgSize(cnt, *h_aop); | |
4a4d8108 AM |
12613 | +} |
12614 | + | |
4a4d8108 AM |
12615 | +/* ---------------------------------------------------------------------- */ |
12616 | + | |
12617 | +static void dy_bug(struct kref *kref) | |
12618 | +{ | |
12619 | + BUG(); | |
12620 | +} | |
12621 | + | |
12622 | +static struct au_dykey *dy_get(struct au_dynop *op, struct au_branch *br) | |
12623 | +{ | |
12624 | + struct au_dykey *key, *old; | |
8b6a4947 | 12625 | + struct hlist_bl_head *hbl; |
b752ccd1 | 12626 | + struct op { |
4a4d8108 | 12627 | + unsigned int sz; |
b752ccd1 AM |
12628 | + void (*set)(struct au_dykey *key, const void *h_op, |
12629 | + struct super_block *h_sb __maybe_unused); | |
12630 | + }; | |
12631 | + static const struct op a[] = { | |
4a4d8108 AM |
12632 | + [AuDy_AOP] = { |
12633 | + .sz = sizeof(struct au_dyaop), | |
b752ccd1 | 12634 | + .set = dy_aop |
4a4d8108 | 12635 | + } |
b752ccd1 AM |
12636 | + }; |
12637 | + const struct op *p; | |
4a4d8108 | 12638 | + |
8b6a4947 AM |
12639 | + hbl = dynop + op->dy_type; |
12640 | + key = dy_gfind_get(hbl, op->dy_hop); | |
4a4d8108 AM |
12641 | + if (key) |
12642 | + goto out_add; /* success */ | |
12643 | + | |
12644 | + p = a + op->dy_type; | |
12645 | + key = kzalloc(p->sz, GFP_NOFS); | |
12646 | + if (unlikely(!key)) { | |
12647 | + key = ERR_PTR(-ENOMEM); | |
12648 | + goto out; | |
12649 | + } | |
12650 | + | |
12651 | + key->dk_op.dy_hop = op->dy_hop; | |
12652 | + kref_init(&key->dk_kref); | |
86dc4139 | 12653 | + p->set(key, op->dy_hop, au_br_sb(br)); |
8b6a4947 | 12654 | + old = dy_gadd(hbl, key); |
4a4d8108 | 12655 | + if (old) { |
9f237c51 | 12656 | + au_kfree_rcu(key); |
4a4d8108 AM |
12657 | + key = old; |
12658 | + } | |
12659 | + | |
12660 | +out_add: | |
12661 | + old = dy_bradd(br, key); | |
12662 | + if (old) | |
12663 | + /* its ref-count should never be zero here */ | |
12664 | + kref_put(&key->dk_kref, dy_bug); | |
12665 | +out: | |
12666 | + return key; | |
12667 | +} | |
12668 | + | |
12669 | +/* ---------------------------------------------------------------------- */ | |
12670 | +/* | |
acd2b654 | 12671 | + * Aufs prohibits O_DIRECT by default even if the branch supports it. |
c1595e42 | 12672 | + * This behaviour is necessary to return an error from open(O_DIRECT) instead |
4a4d8108 AM |
12673 | + * of the succeeding I/O. The dio mount option enables O_DIRECT and makes |
12674 | + * open(O_DIRECT) always succeed, but the succeeding I/O may return an error. | |
12675 | + * See the aufs manual in detail. | |
4a4d8108 AM |
12676 | + */ |
12677 | +static void dy_adx(struct au_dyaop *dyaop, int do_dx) | |
12678 | +{ | |
7e9cd9fe | 12679 | + if (!do_dx) |
4a4d8108 | 12680 | + dyaop->da_op.direct_IO = NULL; |
7e9cd9fe | 12681 | + else |
4a4d8108 | 12682 | + dyaop->da_op.direct_IO = aufs_aop.direct_IO; |
4a4d8108 AM |
12683 | +} |
12684 | + | |
12685 | +static struct au_dyaop *dy_aget(struct au_branch *br, | |
12686 | + const struct address_space_operations *h_aop, | |
12687 | + int do_dx) | |
12688 | +{ | |
12689 | + struct au_dyaop *dyaop; | |
12690 | + struct au_dynop op; | |
12691 | + | |
12692 | + op.dy_type = AuDy_AOP; | |
12693 | + op.dy_haop = h_aop; | |
12694 | + dyaop = (void *)dy_get(&op, br); | |
12695 | + if (IS_ERR(dyaop)) | |
12696 | + goto out; | |
12697 | + dy_adx(dyaop, do_dx); | |
12698 | + | |
12699 | +out: | |
12700 | + return dyaop; | |
12701 | +} | |
12702 | + | |
12703 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
12704 | + struct inode *h_inode) | |
12705 | +{ | |
12706 | + int err, do_dx; | |
12707 | + struct super_block *sb; | |
12708 | + struct au_branch *br; | |
12709 | + struct au_dyaop *dyaop; | |
12710 | + | |
12711 | + AuDebugOn(!S_ISREG(h_inode->i_mode)); | |
12712 | + IiMustWriteLock(inode); | |
12713 | + | |
12714 | + sb = inode->i_sb; | |
12715 | + br = au_sbr(sb, bindex); | |
12716 | + do_dx = !!au_opt_test(au_mntflags(sb), DIO); | |
12717 | + dyaop = dy_aget(br, h_inode->i_mapping->a_ops, do_dx); | |
12718 | + err = PTR_ERR(dyaop); | |
12719 | + if (IS_ERR(dyaop)) | |
12720 | + /* unnecessary to call dy_fput() */ | |
12721 | + goto out; | |
12722 | + | |
12723 | + err = 0; | |
12724 | + inode->i_mapping->a_ops = &dyaop->da_op; | |
12725 | + | |
12726 | +out: | |
12727 | + return err; | |
12728 | +} | |
12729 | + | |
b752ccd1 AM |
12730 | +/* |
12731 | + * Is it safe to replace a_ops during the inode/file is in operation? | |
12732 | + * Yes, I hope so. | |
12733 | + */ | |
12734 | +int au_dy_irefresh(struct inode *inode) | |
12735 | +{ | |
12736 | + int err; | |
5afbbe0d | 12737 | + aufs_bindex_t btop; |
b752ccd1 AM |
12738 | + struct inode *h_inode; |
12739 | + | |
12740 | + err = 0; | |
12741 | + if (S_ISREG(inode->i_mode)) { | |
5afbbe0d AM |
12742 | + btop = au_ibtop(inode); |
12743 | + h_inode = au_h_iptr(inode, btop); | |
12744 | + err = au_dy_iaop(inode, btop, h_inode); | |
b752ccd1 AM |
12745 | + } |
12746 | + return err; | |
12747 | +} | |
12748 | + | |
4a4d8108 AM |
12749 | +void au_dy_arefresh(int do_dx) |
12750 | +{ | |
8b6a4947 AM |
12751 | + struct hlist_bl_head *hbl; |
12752 | + struct hlist_bl_node *pos; | |
4a4d8108 AM |
12753 | + struct au_dykey *key; |
12754 | + | |
8b6a4947 AM |
12755 | + hbl = dynop + AuDy_AOP; |
12756 | + hlist_bl_lock(hbl); | |
12757 | + hlist_bl_for_each_entry(key, pos, hbl, dk_hnode) | |
4a4d8108 | 12758 | + dy_adx((void *)key, do_dx); |
8b6a4947 | 12759 | + hlist_bl_unlock(hbl); |
4a4d8108 AM |
12760 | +} |
12761 | + | |
4a4d8108 AM |
12762 | +/* ---------------------------------------------------------------------- */ |
12763 | + | |
12764 | +void __init au_dy_init(void) | |
12765 | +{ | |
12766 | + int i; | |
12767 | + | |
4a4d8108 | 12768 | + for (i = 0; i < AuDyLast; i++) |
8b6a4947 | 12769 | + INIT_HLIST_BL_HEAD(dynop + i); |
4a4d8108 AM |
12770 | +} |
12771 | + | |
12772 | +void au_dy_fin(void) | |
12773 | +{ | |
12774 | + int i; | |
12775 | + | |
12776 | + for (i = 0; i < AuDyLast; i++) | |
8b6a4947 | 12777 | + WARN_ON(!hlist_bl_empty(dynop + i)); |
4a4d8108 | 12778 | +} |
7f207e10 | 12779 | diff -urN /usr/share/empty/fs/aufs/dynop.h linux/fs/aufs/dynop.h |
eca34b5c | 12780 | --- /usr/share/empty/fs/aufs/dynop.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 12781 | +++ linux/fs/aufs/dynop.h 2020-01-27 10:57:18.168871450 +0100 |
fbc438ed | 12782 | @@ -0,0 +1,77 @@ |
062440b3 | 12783 | +/* SPDX-License-Identifier: GPL-2.0 */ |
4a4d8108 | 12784 | +/* |
d58c55f2 | 12785 | + * Copyright (C) 2010-2020 Junjiro R. Okajima |
4a4d8108 AM |
12786 | + * |
12787 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12788 | + * it under the terms of the GNU General Public License as published by | |
12789 | + * the Free Software Foundation; either version 2 of the License, or | |
12790 | + * (at your option) any later version. | |
12791 | + * | |
12792 | + * This program is distributed in the hope that it will be useful, | |
12793 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12794 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12795 | + * GNU General Public License for more details. | |
12796 | + * | |
12797 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12798 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
12799 | + */ |
12800 | + | |
12801 | +/* | |
12802 | + * dynamically customizable operations (for regular files only) | |
12803 | + */ | |
12804 | + | |
12805 | +#ifndef __AUFS_DYNOP_H__ | |
12806 | +#define __AUFS_DYNOP_H__ | |
12807 | + | |
12808 | +#ifdef __KERNEL__ | |
12809 | + | |
7e9cd9fe AM |
12810 | +#include <linux/fs.h> |
12811 | +#include <linux/kref.h> | |
4a4d8108 | 12812 | + |
2cbb1c4b | 12813 | +enum {AuDy_AOP, AuDyLast}; |
4a4d8108 AM |
12814 | + |
12815 | +struct au_dynop { | |
12816 | + int dy_type; | |
12817 | + union { | |
12818 | + const void *dy_hop; | |
12819 | + const struct address_space_operations *dy_haop; | |
4a4d8108 AM |
12820 | + }; |
12821 | +}; | |
12822 | + | |
12823 | +struct au_dykey { | |
12824 | + union { | |
8b6a4947 | 12825 | + struct hlist_bl_node dk_hnode; |
4a4d8108 AM |
12826 | + struct rcu_head dk_rcu; |
12827 | + }; | |
12828 | + struct au_dynop dk_op; | |
12829 | + | |
12830 | + /* | |
12831 | + * during I am in the branch local array, kref is gotten. when the | |
12832 | + * branch is removed, kref is put. | |
12833 | + */ | |
12834 | + struct kref dk_kref; | |
12835 | +}; | |
12836 | + | |
12837 | +/* stop unioning since their sizes are very different from each other */ | |
12838 | +struct au_dyaop { | |
12839 | + struct au_dykey da_key; | |
12840 | + struct address_space_operations da_op; /* not const */ | |
4a4d8108 | 12841 | +}; |
fbc438ed JR |
12842 | +/* make sure that 'struct au_dykey *' can be any type */ |
12843 | +static_assert(!offsetof(struct au_dyaop, da_key)); | |
4a4d8108 | 12844 | + |
4a4d8108 AM |
12845 | +/* ---------------------------------------------------------------------- */ |
12846 | + | |
12847 | +/* dynop.c */ | |
12848 | +struct au_branch; | |
12849 | +void au_dy_put(struct au_dykey *key); | |
12850 | +int au_dy_iaop(struct inode *inode, aufs_bindex_t bindex, | |
12851 | + struct inode *h_inode); | |
b752ccd1 | 12852 | +int au_dy_irefresh(struct inode *inode); |
4a4d8108 | 12853 | +void au_dy_arefresh(int do_dio); |
4a4d8108 AM |
12854 | + |
12855 | +void __init au_dy_init(void); | |
12856 | +void au_dy_fin(void); | |
12857 | + | |
4a4d8108 AM |
12858 | +#endif /* __KERNEL__ */ |
12859 | +#endif /* __AUFS_DYNOP_H__ */ | |
7f207e10 | 12860 | diff -urN /usr/share/empty/fs/aufs/export.c linux/fs/aufs/export.c |
eca34b5c | 12861 | --- /usr/share/empty/fs/aufs/export.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 12862 | +++ linux/fs/aufs/export.c 2020-01-27 10:57:18.168871450 +0100 |
062440b3 | 12863 | @@ -0,0 +1,838 @@ |
cd7a4cd9 | 12864 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 12865 | +/* |
d58c55f2 | 12866 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
12867 | + * |
12868 | + * This program, aufs is free software; you can redistribute it and/or modify | |
12869 | + * it under the terms of the GNU General Public License as published by | |
12870 | + * the Free Software Foundation; either version 2 of the License, or | |
12871 | + * (at your option) any later version. | |
12872 | + * | |
12873 | + * This program is distributed in the hope that it will be useful, | |
12874 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12875 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12876 | + * GNU General Public License for more details. | |
12877 | + * | |
12878 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 12879 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
12880 | + */ |
12881 | + | |
12882 | +/* | |
12883 | + * export via nfs | |
12884 | + */ | |
12885 | + | |
12886 | +#include <linux/exportfs.h> | |
7eafdf33 | 12887 | +#include <linux/fs_struct.h> |
4a4d8108 AM |
12888 | +#include <linux/namei.h> |
12889 | +#include <linux/nsproxy.h> | |
12890 | +#include <linux/random.h> | |
12891 | +#include <linux/writeback.h> | |
12892 | +#include "aufs.h" | |
12893 | + | |
12894 | +union conv { | |
12895 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12896 | + __u32 a[2]; | |
12897 | +#else | |
12898 | + __u32 a[1]; | |
12899 | +#endif | |
12900 | + ino_t ino; | |
12901 | +}; | |
12902 | + | |
12903 | +static ino_t decode_ino(__u32 *a) | |
12904 | +{ | |
12905 | + union conv u; | |
12906 | + | |
12907 | + BUILD_BUG_ON(sizeof(u.ino) != sizeof(u.a)); | |
12908 | + u.a[0] = a[0]; | |
12909 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12910 | + u.a[1] = a[1]; | |
12911 | +#endif | |
12912 | + return u.ino; | |
12913 | +} | |
12914 | + | |
12915 | +static void encode_ino(__u32 *a, ino_t ino) | |
12916 | +{ | |
12917 | + union conv u; | |
12918 | + | |
12919 | + u.ino = ino; | |
12920 | + a[0] = u.a[0]; | |
12921 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12922 | + a[1] = u.a[1]; | |
12923 | +#endif | |
12924 | +} | |
12925 | + | |
12926 | +/* NFS file handle */ | |
12927 | +enum { | |
12928 | + Fh_br_id, | |
12929 | + Fh_sigen, | |
12930 | +#ifdef CONFIG_AUFS_INO_T_64 | |
12931 | + /* support 64bit inode number */ | |
12932 | + Fh_ino1, | |
12933 | + Fh_ino2, | |
12934 | + Fh_dir_ino1, | |
12935 | + Fh_dir_ino2, | |
12936 | +#else | |
12937 | + Fh_ino1, | |
12938 | + Fh_dir_ino1, | |
12939 | +#endif | |
12940 | + Fh_igen, | |
12941 | + Fh_h_type, | |
12942 | + Fh_tail, | |
12943 | + | |
12944 | + Fh_ino = Fh_ino1, | |
12945 | + Fh_dir_ino = Fh_dir_ino1 | |
12946 | +}; | |
12947 | + | |
12948 | +static int au_test_anon(struct dentry *dentry) | |
12949 | +{ | |
027c5e7a | 12950 | + /* note: read d_flags without d_lock */ |
4a4d8108 AM |
12951 | + return !!(dentry->d_flags & DCACHE_DISCONNECTED); |
12952 | +} | |
12953 | + | |
a2a7ad62 AM |
12954 | +int au_test_nfsd(void) |
12955 | +{ | |
12956 | + int ret; | |
12957 | + struct task_struct *tsk = current; | |
12958 | + char comm[sizeof(tsk->comm)]; | |
12959 | + | |
12960 | + ret = 0; | |
12961 | + if (tsk->flags & PF_KTHREAD) { | |
12962 | + get_task_comm(comm, tsk); | |
12963 | + ret = !strcmp(comm, "nfsd"); | |
12964 | + } | |
12965 | + | |
12966 | + return ret; | |
12967 | +} | |
12968 | + | |
4a4d8108 AM |
12969 | +/* ---------------------------------------------------------------------- */ |
12970 | +/* inode generation external table */ | |
12971 | + | |
b752ccd1 | 12972 | +void au_xigen_inc(struct inode *inode) |
4a4d8108 | 12973 | +{ |
4a4d8108 AM |
12974 | + loff_t pos; |
12975 | + ssize_t sz; | |
12976 | + __u32 igen; | |
12977 | + struct super_block *sb; | |
12978 | + struct au_sbinfo *sbinfo; | |
12979 | + | |
4a4d8108 | 12980 | + sb = inode->i_sb; |
b752ccd1 | 12981 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); |
1facf9fc | 12982 | + |
b752ccd1 | 12983 | + sbinfo = au_sbi(sb); |
1facf9fc | 12984 | + pos = inode->i_ino; |
12985 | + pos *= sizeof(igen); | |
12986 | + igen = inode->i_generation + 1; | |
1facf9fc | 12987 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xigen, &igen, |
12988 | + sizeof(igen), &pos); | |
12989 | + if (sz == sizeof(igen)) | |
b752ccd1 | 12990 | + return; /* success */ |
1facf9fc | 12991 | + |
b752ccd1 | 12992 | + if (unlikely(sz >= 0)) |
1facf9fc | 12993 | + AuIOErr("xigen error (%zd)\n", sz); |
1facf9fc | 12994 | +} |
12995 | + | |
12996 | +int au_xigen_new(struct inode *inode) | |
12997 | +{ | |
12998 | + int err; | |
12999 | + loff_t pos; | |
13000 | + ssize_t sz; | |
13001 | + struct super_block *sb; | |
13002 | + struct au_sbinfo *sbinfo; | |
13003 | + struct file *file; | |
13004 | + | |
13005 | + err = 0; | |
13006 | + /* todo: dirty, at mount time */ | |
13007 | + if (inode->i_ino == AUFS_ROOT_INO) | |
13008 | + goto out; | |
13009 | + sb = inode->i_sb; | |
dece6358 | 13010 | + SiMustAnyLock(sb); |
1facf9fc | 13011 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) |
13012 | + goto out; | |
13013 | + | |
13014 | + err = -EFBIG; | |
13015 | + pos = inode->i_ino; | |
13016 | + if (unlikely(au_loff_max / sizeof(inode->i_generation) - 1 < pos)) { | |
13017 | + AuIOErr1("too large i%lld\n", pos); | |
13018 | + goto out; | |
13019 | + } | |
13020 | + pos *= sizeof(inode->i_generation); | |
13021 | + | |
13022 | + err = 0; | |
13023 | + sbinfo = au_sbi(sb); | |
13024 | + file = sbinfo->si_xigen; | |
13025 | + BUG_ON(!file); | |
13026 | + | |
c06a8ce3 | 13027 | + if (vfsub_f_size_read(file) |
1facf9fc | 13028 | + < pos + sizeof(inode->i_generation)) { |
13029 | + inode->i_generation = atomic_inc_return(&sbinfo->si_xigen_next); | |
13030 | + sz = xino_fwrite(sbinfo->si_xwrite, file, &inode->i_generation, | |
13031 | + sizeof(inode->i_generation), &pos); | |
13032 | + } else | |
13033 | + sz = xino_fread(sbinfo->si_xread, file, &inode->i_generation, | |
13034 | + sizeof(inode->i_generation), &pos); | |
13035 | + if (sz == sizeof(inode->i_generation)) | |
13036 | + goto out; /* success */ | |
13037 | + | |
13038 | + err = sz; | |
13039 | + if (unlikely(sz >= 0)) { | |
13040 | + err = -EIO; | |
13041 | + AuIOErr("xigen error (%zd)\n", sz); | |
13042 | + } | |
13043 | + | |
4f0767ce | 13044 | +out: |
1facf9fc | 13045 | + return err; |
13046 | +} | |
13047 | + | |
062440b3 | 13048 | +int au_xigen_set(struct super_block *sb, struct path *path) |
1facf9fc | 13049 | +{ |
13050 | + int err; | |
13051 | + struct au_sbinfo *sbinfo; | |
13052 | + struct file *file; | |
13053 | + | |
dece6358 AM |
13054 | + SiMustWriteLock(sb); |
13055 | + | |
1facf9fc | 13056 | + sbinfo = au_sbi(sb); |
062440b3 | 13057 | + file = au_xino_create2(sb, path, sbinfo->si_xigen); |
1facf9fc | 13058 | + err = PTR_ERR(file); |
13059 | + if (IS_ERR(file)) | |
13060 | + goto out; | |
13061 | + err = 0; | |
13062 | + if (sbinfo->si_xigen) | |
13063 | + fput(sbinfo->si_xigen); | |
13064 | + sbinfo->si_xigen = file; | |
13065 | + | |
4f0767ce | 13066 | +out: |
062440b3 | 13067 | + AuTraceErr(err); |
1facf9fc | 13068 | + return err; |
13069 | +} | |
13070 | + | |
13071 | +void au_xigen_clr(struct super_block *sb) | |
13072 | +{ | |
13073 | + struct au_sbinfo *sbinfo; | |
13074 | + | |
dece6358 AM |
13075 | + SiMustWriteLock(sb); |
13076 | + | |
1facf9fc | 13077 | + sbinfo = au_sbi(sb); |
13078 | + if (sbinfo->si_xigen) { | |
13079 | + fput(sbinfo->si_xigen); | |
13080 | + sbinfo->si_xigen = NULL; | |
13081 | + } | |
13082 | +} | |
13083 | + | |
13084 | +/* ---------------------------------------------------------------------- */ | |
13085 | + | |
13086 | +static struct dentry *decode_by_ino(struct super_block *sb, ino_t ino, | |
13087 | + ino_t dir_ino) | |
13088 | +{ | |
13089 | + struct dentry *dentry, *d; | |
13090 | + struct inode *inode; | |
13091 | + unsigned int sigen; | |
13092 | + | |
13093 | + dentry = NULL; | |
13094 | + inode = ilookup(sb, ino); | |
13095 | + if (!inode) | |
13096 | + goto out; | |
13097 | + | |
13098 | + dentry = ERR_PTR(-ESTALE); | |
13099 | + sigen = au_sigen(sb); | |
5afbbe0d | 13100 | + if (unlikely(au_is_bad_inode(inode) |
1facf9fc | 13101 | + || IS_DEADDIR(inode) |
537831f9 | 13102 | + || sigen != au_iigen(inode, NULL))) |
1facf9fc | 13103 | + goto out_iput; |
13104 | + | |
13105 | + dentry = NULL; | |
13106 | + if (!dir_ino || S_ISDIR(inode->i_mode)) | |
13107 | + dentry = d_find_alias(inode); | |
13108 | + else { | |
027c5e7a | 13109 | + spin_lock(&inode->i_lock); |
c1595e42 | 13110 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 13111 | + spin_lock(&d->d_lock); |
1facf9fc | 13112 | + if (!au_test_anon(d) |
5527c038 | 13113 | + && d_inode(d->d_parent)->i_ino == dir_ino) { |
027c5e7a AM |
13114 | + dentry = dget_dlock(d); |
13115 | + spin_unlock(&d->d_lock); | |
1facf9fc | 13116 | + break; |
13117 | + } | |
027c5e7a AM |
13118 | + spin_unlock(&d->d_lock); |
13119 | + } | |
13120 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 13121 | + } |
027c5e7a | 13122 | + if (unlikely(dentry && au_digen_test(dentry, sigen))) { |
2cbb1c4b | 13123 | + /* need to refresh */ |
1facf9fc | 13124 | + dput(dentry); |
2cbb1c4b | 13125 | + dentry = NULL; |
1facf9fc | 13126 | + } |
13127 | + | |
4f0767ce | 13128 | +out_iput: |
1facf9fc | 13129 | + iput(inode); |
4f0767ce | 13130 | +out: |
2cbb1c4b | 13131 | + AuTraceErrPtr(dentry); |
1facf9fc | 13132 | + return dentry; |
13133 | +} | |
13134 | + | |
13135 | +/* ---------------------------------------------------------------------- */ | |
13136 | + | |
13137 | +/* todo: dirty? */ | |
13138 | +/* if exportfs_decode_fh() passed vfsmount*, we could be happy */ | |
4a4d8108 AM |
13139 | + |
13140 | +struct au_compare_mnt_args { | |
13141 | + /* input */ | |
13142 | + struct super_block *sb; | |
13143 | + | |
13144 | + /* output */ | |
13145 | + struct vfsmount *mnt; | |
13146 | +}; | |
13147 | + | |
13148 | +static int au_compare_mnt(struct vfsmount *mnt, void *arg) | |
13149 | +{ | |
13150 | + struct au_compare_mnt_args *a = arg; | |
13151 | + | |
13152 | + if (mnt->mnt_sb != a->sb) | |
13153 | + return 0; | |
13154 | + a->mnt = mntget(mnt); | |
13155 | + return 1; | |
13156 | +} | |
13157 | + | |
1facf9fc | 13158 | +static struct vfsmount *au_mnt_get(struct super_block *sb) |
13159 | +{ | |
4a4d8108 | 13160 | + int err; |
7eafdf33 | 13161 | + struct path root; |
4a4d8108 AM |
13162 | + struct au_compare_mnt_args args = { |
13163 | + .sb = sb | |
13164 | + }; | |
1facf9fc | 13165 | + |
7eafdf33 | 13166 | + get_fs_root(current->fs, &root); |
523b37e3 | 13167 | + rcu_read_lock(); |
7eafdf33 | 13168 | + err = iterate_mounts(au_compare_mnt, &args, root.mnt); |
523b37e3 | 13169 | + rcu_read_unlock(); |
7eafdf33 | 13170 | + path_put(&root); |
4a4d8108 AM |
13171 | + AuDebugOn(!err); |
13172 | + AuDebugOn(!args.mnt); | |
13173 | + return args.mnt; | |
1facf9fc | 13174 | +} |
13175 | + | |
13176 | +struct au_nfsd_si_lock { | |
4a4d8108 | 13177 | + unsigned int sigen; |
027c5e7a | 13178 | + aufs_bindex_t bindex, br_id; |
1facf9fc | 13179 | + unsigned char force_lock; |
13180 | +}; | |
13181 | + | |
027c5e7a AM |
13182 | +static int si_nfsd_read_lock(struct super_block *sb, |
13183 | + struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 13184 | +{ |
027c5e7a | 13185 | + int err; |
1facf9fc | 13186 | + aufs_bindex_t bindex; |
13187 | + | |
13188 | + si_read_lock(sb, AuLock_FLUSH); | |
13189 | + | |
13190 | + /* branch id may be wrapped around */ | |
027c5e7a | 13191 | + err = 0; |
1facf9fc | 13192 | + bindex = au_br_index(sb, nsi_lock->br_id); |
13193 | + if (bindex >= 0 && nsi_lock->sigen + AUFS_BRANCH_MAX > au_sigen(sb)) | |
13194 | + goto out; /* success */ | |
13195 | + | |
027c5e7a AM |
13196 | + err = -ESTALE; |
13197 | + bindex = -1; | |
1facf9fc | 13198 | + if (!nsi_lock->force_lock) |
13199 | + si_read_unlock(sb); | |
1facf9fc | 13200 | + |
4f0767ce | 13201 | +out: |
027c5e7a AM |
13202 | + nsi_lock->bindex = bindex; |
13203 | + return err; | |
1facf9fc | 13204 | +} |
13205 | + | |
13206 | +struct find_name_by_ino { | |
392086de | 13207 | + struct dir_context ctx; |
1facf9fc | 13208 | + int called, found; |
13209 | + ino_t ino; | |
13210 | + char *name; | |
13211 | + int namelen; | |
13212 | +}; | |
13213 | + | |
13214 | +static int | |
392086de AM |
13215 | +find_name_by_ino(struct dir_context *ctx, const char *name, int namelen, |
13216 | + loff_t offset, u64 ino, unsigned int d_type) | |
1facf9fc | 13217 | +{ |
392086de AM |
13218 | + struct find_name_by_ino *a = container_of(ctx, struct find_name_by_ino, |
13219 | + ctx); | |
1facf9fc | 13220 | + |
13221 | + a->called++; | |
13222 | + if (a->ino != ino) | |
13223 | + return 0; | |
13224 | + | |
13225 | + memcpy(a->name, name, namelen); | |
13226 | + a->namelen = namelen; | |
13227 | + a->found = 1; | |
13228 | + return 1; | |
13229 | +} | |
13230 | + | |
13231 | +static struct dentry *au_lkup_by_ino(struct path *path, ino_t ino, | |
13232 | + struct au_nfsd_si_lock *nsi_lock) | |
13233 | +{ | |
13234 | + struct dentry *dentry, *parent; | |
13235 | + struct file *file; | |
13236 | + struct inode *dir; | |
392086de AM |
13237 | + struct find_name_by_ino arg = { |
13238 | + .ctx = { | |
2000de60 | 13239 | + .actor = find_name_by_ino |
392086de AM |
13240 | + } |
13241 | + }; | |
1facf9fc | 13242 | + int err; |
13243 | + | |
13244 | + parent = path->dentry; | |
13245 | + if (nsi_lock) | |
13246 | + si_read_unlock(parent->d_sb); | |
4a4d8108 | 13247 | + file = vfsub_dentry_open(path, au_dir_roflags); |
1facf9fc | 13248 | + dentry = (void *)file; |
13249 | + if (IS_ERR(file)) | |
13250 | + goto out; | |
13251 | + | |
13252 | + dentry = ERR_PTR(-ENOMEM); | |
537831f9 | 13253 | + arg.name = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 13254 | + if (unlikely(!arg.name)) |
13255 | + goto out_file; | |
13256 | + arg.ino = ino; | |
13257 | + arg.found = 0; | |
13258 | + do { | |
13259 | + arg.called = 0; | |
13260 | + /* smp_mb(); */ | |
392086de | 13261 | + err = vfsub_iterate_dir(file, &arg.ctx); |
1facf9fc | 13262 | + } while (!err && !arg.found && arg.called); |
13263 | + dentry = ERR_PTR(err); | |
13264 | + if (unlikely(err)) | |
13265 | + goto out_name; | |
1716fcea AM |
13266 | + /* instead of ENOENT */ |
13267 | + dentry = ERR_PTR(-ESTALE); | |
1facf9fc | 13268 | + if (!arg.found) |
13269 | + goto out_name; | |
13270 | + | |
b4510431 | 13271 | + /* do not call vfsub_lkup_one() */ |
5527c038 | 13272 | + dir = d_inode(parent); |
febd17d6 | 13273 | + dentry = vfsub_lookup_one_len_unlocked(arg.name, parent, arg.namelen); |
1facf9fc | 13274 | + AuTraceErrPtr(dentry); |
13275 | + if (IS_ERR(dentry)) | |
13276 | + goto out_name; | |
13277 | + AuDebugOn(au_test_anon(dentry)); | |
5527c038 | 13278 | + if (unlikely(d_really_is_negative(dentry))) { |
1facf9fc | 13279 | + dput(dentry); |
13280 | + dentry = ERR_PTR(-ENOENT); | |
13281 | + } | |
13282 | + | |
4f0767ce | 13283 | +out_name: |
1c60b727 | 13284 | + free_page((unsigned long)arg.name); |
4f0767ce | 13285 | +out_file: |
1facf9fc | 13286 | + fput(file); |
4f0767ce | 13287 | +out: |
1facf9fc | 13288 | + if (unlikely(nsi_lock |
13289 | + && si_nfsd_read_lock(parent->d_sb, nsi_lock) < 0)) | |
13290 | + if (!IS_ERR(dentry)) { | |
13291 | + dput(dentry); | |
13292 | + dentry = ERR_PTR(-ESTALE); | |
13293 | + } | |
13294 | + AuTraceErrPtr(dentry); | |
13295 | + return dentry; | |
13296 | +} | |
13297 | + | |
13298 | +static struct dentry *decode_by_dir_ino(struct super_block *sb, ino_t ino, | |
13299 | + ino_t dir_ino, | |
13300 | + struct au_nfsd_si_lock *nsi_lock) | |
13301 | +{ | |
13302 | + struct dentry *dentry; | |
13303 | + struct path path; | |
13304 | + | |
13305 | + if (dir_ino != AUFS_ROOT_INO) { | |
13306 | + path.dentry = decode_by_ino(sb, dir_ino, 0); | |
13307 | + dentry = path.dentry; | |
13308 | + if (!path.dentry || IS_ERR(path.dentry)) | |
13309 | + goto out; | |
13310 | + AuDebugOn(au_test_anon(path.dentry)); | |
13311 | + } else | |
13312 | + path.dentry = dget(sb->s_root); | |
13313 | + | |
13314 | + path.mnt = au_mnt_get(sb); | |
13315 | + dentry = au_lkup_by_ino(&path, ino, nsi_lock); | |
13316 | + path_put(&path); | |
13317 | + | |
4f0767ce | 13318 | +out: |
1facf9fc | 13319 | + AuTraceErrPtr(dentry); |
13320 | + return dentry; | |
13321 | +} | |
13322 | + | |
13323 | +/* ---------------------------------------------------------------------- */ | |
13324 | + | |
13325 | +static int h_acceptable(void *expv, struct dentry *dentry) | |
13326 | +{ | |
13327 | + return 1; | |
13328 | +} | |
13329 | + | |
13330 | +static char *au_build_path(struct dentry *h_parent, struct path *h_rootpath, | |
13331 | + char *buf, int len, struct super_block *sb) | |
13332 | +{ | |
13333 | + char *p; | |
13334 | + int n; | |
13335 | + struct path path; | |
13336 | + | |
13337 | + p = d_path(h_rootpath, buf, len); | |
13338 | + if (IS_ERR(p)) | |
13339 | + goto out; | |
13340 | + n = strlen(p); | |
13341 | + | |
13342 | + path.mnt = h_rootpath->mnt; | |
13343 | + path.dentry = h_parent; | |
13344 | + p = d_path(&path, buf, len); | |
13345 | + if (IS_ERR(p)) | |
13346 | + goto out; | |
13347 | + if (n != 1) | |
13348 | + p += n; | |
13349 | + | |
13350 | + path.mnt = au_mnt_get(sb); | |
13351 | + path.dentry = sb->s_root; | |
13352 | + p = d_path(&path, buf, len - strlen(p)); | |
13353 | + mntput(path.mnt); | |
13354 | + if (IS_ERR(p)) | |
13355 | + goto out; | |
13356 | + if (n != 1) | |
13357 | + p[strlen(p)] = '/'; | |
13358 | + | |
4f0767ce | 13359 | +out: |
1facf9fc | 13360 | + AuTraceErrPtr(p); |
13361 | + return p; | |
13362 | +} | |
13363 | + | |
13364 | +static | |
027c5e7a AM |
13365 | +struct dentry *decode_by_path(struct super_block *sb, ino_t ino, __u32 *fh, |
13366 | + int fh_len, struct au_nfsd_si_lock *nsi_lock) | |
1facf9fc | 13367 | +{ |
13368 | + struct dentry *dentry, *h_parent, *root; | |
13369 | + struct super_block *h_sb; | |
13370 | + char *pathname, *p; | |
13371 | + struct vfsmount *h_mnt; | |
13372 | + struct au_branch *br; | |
13373 | + int err; | |
13374 | + struct path path; | |
13375 | + | |
027c5e7a | 13376 | + br = au_sbr(sb, nsi_lock->bindex); |
86dc4139 | 13377 | + h_mnt = au_br_mnt(br); |
1facf9fc | 13378 | + h_sb = h_mnt->mnt_sb; |
13379 | + /* todo: call lower fh_to_dentry()? fh_to_parent()? */ | |
5afbbe0d | 13380 | + lockdep_off(); |
1facf9fc | 13381 | + h_parent = exportfs_decode_fh(h_mnt, (void *)(fh + Fh_tail), |
13382 | + fh_len - Fh_tail, fh[Fh_h_type], | |
13383 | + h_acceptable, /*context*/NULL); | |
5afbbe0d | 13384 | + lockdep_on(); |
1facf9fc | 13385 | + dentry = h_parent; |
13386 | + if (unlikely(!h_parent || IS_ERR(h_parent))) { | |
13387 | + AuWarn1("%s decode_fh failed, %ld\n", | |
13388 | + au_sbtype(h_sb), PTR_ERR(h_parent)); | |
13389 | + goto out; | |
13390 | + } | |
13391 | + dentry = NULL; | |
13392 | + if (unlikely(au_test_anon(h_parent))) { | |
13393 | + AuWarn1("%s decode_fh returned a disconnected dentry\n", | |
13394 | + au_sbtype(h_sb)); | |
13395 | + goto out_h_parent; | |
13396 | + } | |
13397 | + | |
13398 | + dentry = ERR_PTR(-ENOMEM); | |
13399 | + pathname = (void *)__get_free_page(GFP_NOFS); | |
13400 | + if (unlikely(!pathname)) | |
13401 | + goto out_h_parent; | |
13402 | + | |
13403 | + root = sb->s_root; | |
13404 | + path.mnt = h_mnt; | |
13405 | + di_read_lock_parent(root, !AuLock_IR); | |
027c5e7a | 13406 | + path.dentry = au_h_dptr(root, nsi_lock->bindex); |
1facf9fc | 13407 | + di_read_unlock(root, !AuLock_IR); |
13408 | + p = au_build_path(h_parent, &path, pathname, PAGE_SIZE, sb); | |
13409 | + dentry = (void *)p; | |
13410 | + if (IS_ERR(p)) | |
13411 | + goto out_pathname; | |
13412 | + | |
13413 | + si_read_unlock(sb); | |
13414 | + err = vfsub_kern_path(p, LOOKUP_FOLLOW | LOOKUP_DIRECTORY, &path); | |
13415 | + dentry = ERR_PTR(err); | |
13416 | + if (unlikely(err)) | |
13417 | + goto out_relock; | |
13418 | + | |
13419 | + dentry = ERR_PTR(-ENOENT); | |
13420 | + AuDebugOn(au_test_anon(path.dentry)); | |
5527c038 | 13421 | + if (unlikely(d_really_is_negative(path.dentry))) |
1facf9fc | 13422 | + goto out_path; |
13423 | + | |
5527c038 | 13424 | + if (ino != d_inode(path.dentry)->i_ino) |
1facf9fc | 13425 | + dentry = au_lkup_by_ino(&path, ino, /*nsi_lock*/NULL); |
13426 | + else | |
13427 | + dentry = dget(path.dentry); | |
13428 | + | |
4f0767ce | 13429 | +out_path: |
1facf9fc | 13430 | + path_put(&path); |
4f0767ce | 13431 | +out_relock: |
1facf9fc | 13432 | + if (unlikely(si_nfsd_read_lock(sb, nsi_lock) < 0)) |
13433 | + if (!IS_ERR(dentry)) { | |
13434 | + dput(dentry); | |
13435 | + dentry = ERR_PTR(-ESTALE); | |
13436 | + } | |
4f0767ce | 13437 | +out_pathname: |
1c60b727 | 13438 | + free_page((unsigned long)pathname); |
4f0767ce | 13439 | +out_h_parent: |
1facf9fc | 13440 | + dput(h_parent); |
4f0767ce | 13441 | +out: |
1facf9fc | 13442 | + AuTraceErrPtr(dentry); |
13443 | + return dentry; | |
13444 | +} | |
13445 | + | |
13446 | +/* ---------------------------------------------------------------------- */ | |
13447 | + | |
13448 | +static struct dentry * | |
13449 | +aufs_fh_to_dentry(struct super_block *sb, struct fid *fid, int fh_len, | |
13450 | + int fh_type) | |
13451 | +{ | |
13452 | + struct dentry *dentry; | |
13453 | + __u32 *fh = fid->raw; | |
027c5e7a | 13454 | + struct au_branch *br; |
1facf9fc | 13455 | + ino_t ino, dir_ino; |
1facf9fc | 13456 | + struct au_nfsd_si_lock nsi_lock = { |
1facf9fc | 13457 | + .force_lock = 0 |
13458 | + }; | |
13459 | + | |
1facf9fc | 13460 | + dentry = ERR_PTR(-ESTALE); |
4a4d8108 AM |
13461 | + /* it should never happen, but the file handle is unreliable */ |
13462 | + if (unlikely(fh_len < Fh_tail)) | |
13463 | + goto out; | |
13464 | + nsi_lock.sigen = fh[Fh_sigen]; | |
13465 | + nsi_lock.br_id = fh[Fh_br_id]; | |
13466 | + | |
1facf9fc | 13467 | + /* branch id may be wrapped around */ |
027c5e7a AM |
13468 | + br = NULL; |
13469 | + if (unlikely(si_nfsd_read_lock(sb, &nsi_lock))) | |
1facf9fc | 13470 | + goto out; |
13471 | + nsi_lock.force_lock = 1; | |
13472 | + | |
13473 | + /* is this inode still cached? */ | |
13474 | + ino = decode_ino(fh + Fh_ino); | |
4a4d8108 AM |
13475 | + /* it should never happen */ |
13476 | + if (unlikely(ino == AUFS_ROOT_INO)) | |
8cdd5066 | 13477 | + goto out_unlock; |
4a4d8108 | 13478 | + |
1facf9fc | 13479 | + dir_ino = decode_ino(fh + Fh_dir_ino); |
13480 | + dentry = decode_by_ino(sb, ino, dir_ino); | |
13481 | + if (IS_ERR(dentry)) | |
13482 | + goto out_unlock; | |
13483 | + if (dentry) | |
13484 | + goto accept; | |
13485 | + | |
13486 | + /* is the parent dir cached? */ | |
027c5e7a | 13487 | + br = au_sbr(sb, nsi_lock.bindex); |
acd2b654 | 13488 | + au_lcnt_inc(&br->br_nfiles); |
1facf9fc | 13489 | + dentry = decode_by_dir_ino(sb, ino, dir_ino, &nsi_lock); |
13490 | + if (IS_ERR(dentry)) | |
13491 | + goto out_unlock; | |
13492 | + if (dentry) | |
13493 | + goto accept; | |
13494 | + | |
13495 | + /* lookup path */ | |
027c5e7a | 13496 | + dentry = decode_by_path(sb, ino, fh, fh_len, &nsi_lock); |
1facf9fc | 13497 | + if (IS_ERR(dentry)) |
13498 | + goto out_unlock; | |
13499 | + if (unlikely(!dentry)) | |
13500 | + /* todo?: make it ESTALE */ | |
13501 | + goto out_unlock; | |
13502 | + | |
4f0767ce | 13503 | +accept: |
027c5e7a | 13504 | + if (!au_digen_test(dentry, au_sigen(sb)) |
5527c038 | 13505 | + && d_inode(dentry)->i_generation == fh[Fh_igen]) |
1facf9fc | 13506 | + goto out_unlock; /* success */ |
13507 | + | |
13508 | + dput(dentry); | |
13509 | + dentry = ERR_PTR(-ESTALE); | |
4f0767ce | 13510 | +out_unlock: |
027c5e7a | 13511 | + if (br) |
acd2b654 | 13512 | + au_lcnt_dec(&br->br_nfiles); |
1facf9fc | 13513 | + si_read_unlock(sb); |
4f0767ce | 13514 | +out: |
1facf9fc | 13515 | + AuTraceErrPtr(dentry); |
13516 | + return dentry; | |
13517 | +} | |
13518 | + | |
13519 | +#if 0 /* reserved for future use */ | |
13520 | +/* support subtreecheck option */ | |
13521 | +static struct dentry *aufs_fh_to_parent(struct super_block *sb, struct fid *fid, | |
13522 | + int fh_len, int fh_type) | |
13523 | +{ | |
13524 | + struct dentry *parent; | |
13525 | + __u32 *fh = fid->raw; | |
13526 | + ino_t dir_ino; | |
13527 | + | |
13528 | + dir_ino = decode_ino(fh + Fh_dir_ino); | |
13529 | + parent = decode_by_ino(sb, dir_ino, 0); | |
13530 | + if (IS_ERR(parent)) | |
13531 | + goto out; | |
13532 | + if (!parent) | |
13533 | + parent = decode_by_path(sb, au_br_index(sb, fh[Fh_br_id]), | |
13534 | + dir_ino, fh, fh_len); | |
13535 | + | |
4f0767ce | 13536 | +out: |
1facf9fc | 13537 | + AuTraceErrPtr(parent); |
13538 | + return parent; | |
13539 | +} | |
13540 | +#endif | |
13541 | + | |
13542 | +/* ---------------------------------------------------------------------- */ | |
13543 | + | |
0c3ec466 AM |
13544 | +static int aufs_encode_fh(struct inode *inode, __u32 *fh, int *max_len, |
13545 | + struct inode *dir) | |
1facf9fc | 13546 | +{ |
13547 | + int err; | |
0c3ec466 | 13548 | + aufs_bindex_t bindex; |
1facf9fc | 13549 | + struct super_block *sb, *h_sb; |
0c3ec466 AM |
13550 | + struct dentry *dentry, *parent, *h_parent; |
13551 | + struct inode *h_dir; | |
1facf9fc | 13552 | + struct au_branch *br; |
13553 | + | |
1facf9fc | 13554 | + err = -ENOSPC; |
13555 | + if (unlikely(*max_len <= Fh_tail)) { | |
13556 | + AuWarn1("NFSv2 client (max_len %d)?\n", *max_len); | |
13557 | + goto out; | |
13558 | + } | |
13559 | + | |
13560 | + err = FILEID_ROOT; | |
0c3ec466 AM |
13561 | + if (inode->i_ino == AUFS_ROOT_INO) { |
13562 | + AuDebugOn(inode->i_ino != AUFS_ROOT_INO); | |
1facf9fc | 13563 | + goto out; |
13564 | + } | |
13565 | + | |
1facf9fc | 13566 | + h_parent = NULL; |
0c3ec466 AM |
13567 | + sb = inode->i_sb; |
13568 | + err = si_read_lock(sb, AuLock_FLUSH); | |
027c5e7a AM |
13569 | + if (unlikely(err)) |
13570 | + goto out; | |
13571 | + | |
1facf9fc | 13572 | +#ifdef CONFIG_AUFS_DEBUG |
13573 | + if (unlikely(!au_opt_test(au_mntflags(sb), XINO))) | |
13574 | + AuWarn1("NFS-exporting requires xino\n"); | |
13575 | +#endif | |
027c5e7a | 13576 | + err = -EIO; |
0c3ec466 AM |
13577 | + parent = NULL; |
13578 | + ii_read_lock_child(inode); | |
5afbbe0d | 13579 | + bindex = au_ibtop(inode); |
0c3ec466 | 13580 | + if (!dir) { |
c1595e42 | 13581 | + dentry = d_find_any_alias(inode); |
0c3ec466 AM |
13582 | + if (unlikely(!dentry)) |
13583 | + goto out_unlock; | |
13584 | + AuDebugOn(au_test_anon(dentry)); | |
13585 | + parent = dget_parent(dentry); | |
13586 | + dput(dentry); | |
13587 | + if (unlikely(!parent)) | |
13588 | + goto out_unlock; | |
5527c038 JR |
13589 | + if (d_really_is_positive(parent)) |
13590 | + dir = d_inode(parent); | |
1facf9fc | 13591 | + } |
0c3ec466 AM |
13592 | + |
13593 | + ii_read_lock_parent(dir); | |
13594 | + h_dir = au_h_iptr(dir, bindex); | |
13595 | + ii_read_unlock(dir); | |
13596 | + if (unlikely(!h_dir)) | |
13597 | + goto out_parent; | |
c1595e42 | 13598 | + h_parent = d_find_any_alias(h_dir); |
1facf9fc | 13599 | + if (unlikely(!h_parent)) |
0c3ec466 | 13600 | + goto out_hparent; |
1facf9fc | 13601 | + |
13602 | + err = -EPERM; | |
13603 | + br = au_sbr(sb, bindex); | |
86dc4139 | 13604 | + h_sb = au_br_sb(br); |
1facf9fc | 13605 | + if (unlikely(!h_sb->s_export_op)) { |
13606 | + AuErr1("%s branch is not exportable\n", au_sbtype(h_sb)); | |
0c3ec466 | 13607 | + goto out_hparent; |
1facf9fc | 13608 | + } |
13609 | + | |
13610 | + fh[Fh_br_id] = br->br_id; | |
13611 | + fh[Fh_sigen] = au_sigen(sb); | |
13612 | + encode_ino(fh + Fh_ino, inode->i_ino); | |
0c3ec466 | 13613 | + encode_ino(fh + Fh_dir_ino, dir->i_ino); |
1facf9fc | 13614 | + fh[Fh_igen] = inode->i_generation; |
13615 | + | |
13616 | + *max_len -= Fh_tail; | |
13617 | + fh[Fh_h_type] = exportfs_encode_fh(h_parent, (void *)(fh + Fh_tail), | |
13618 | + max_len, | |
13619 | + /*connectable or subtreecheck*/0); | |
13620 | + err = fh[Fh_h_type]; | |
13621 | + *max_len += Fh_tail; | |
13622 | + /* todo: macros? */ | |
1716fcea | 13623 | + if (err != FILEID_INVALID) |
1facf9fc | 13624 | + err = 99; |
13625 | + else | |
13626 | + AuWarn1("%s encode_fh failed\n", au_sbtype(h_sb)); | |
13627 | + | |
0c3ec466 | 13628 | +out_hparent: |
1facf9fc | 13629 | + dput(h_parent); |
0c3ec466 | 13630 | +out_parent: |
1facf9fc | 13631 | + dput(parent); |
0c3ec466 AM |
13632 | +out_unlock: |
13633 | + ii_read_unlock(inode); | |
13634 | + si_read_unlock(sb); | |
4f0767ce | 13635 | +out: |
1facf9fc | 13636 | + if (unlikely(err < 0)) |
1716fcea | 13637 | + err = FILEID_INVALID; |
1facf9fc | 13638 | + return err; |
13639 | +} | |
13640 | + | |
13641 | +/* ---------------------------------------------------------------------- */ | |
13642 | + | |
4a4d8108 AM |
13643 | +static int aufs_commit_metadata(struct inode *inode) |
13644 | +{ | |
13645 | + int err; | |
13646 | + aufs_bindex_t bindex; | |
13647 | + struct super_block *sb; | |
13648 | + struct inode *h_inode; | |
13649 | + int (*f)(struct inode *inode); | |
13650 | + | |
13651 | + sb = inode->i_sb; | |
e49829fe | 13652 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 13653 | + ii_write_lock_child(inode); |
5afbbe0d | 13654 | + bindex = au_ibtop(inode); |
4a4d8108 AM |
13655 | + AuDebugOn(bindex < 0); |
13656 | + h_inode = au_h_iptr(inode, bindex); | |
13657 | + | |
13658 | + f = h_inode->i_sb->s_export_op->commit_metadata; | |
13659 | + if (f) | |
13660 | + err = f(h_inode); | |
13661 | + else { | |
13662 | + struct writeback_control wbc = { | |
13663 | + .sync_mode = WB_SYNC_ALL, | |
13664 | + .nr_to_write = 0 /* metadata only */ | |
13665 | + }; | |
13666 | + | |
13667 | + err = sync_inode(h_inode, &wbc); | |
13668 | + } | |
13669 | + | |
13670 | + au_cpup_attr_timesizes(inode); | |
13671 | + ii_write_unlock(inode); | |
13672 | + si_read_unlock(sb); | |
13673 | + return err; | |
13674 | +} | |
13675 | + | |
13676 | +/* ---------------------------------------------------------------------- */ | |
13677 | + | |
1facf9fc | 13678 | +static struct export_operations aufs_export_op = { |
4a4d8108 | 13679 | + .fh_to_dentry = aufs_fh_to_dentry, |
1facf9fc | 13680 | + /* .fh_to_parent = aufs_fh_to_parent, */ |
4a4d8108 AM |
13681 | + .encode_fh = aufs_encode_fh, |
13682 | + .commit_metadata = aufs_commit_metadata | |
1facf9fc | 13683 | +}; |
13684 | + | |
13685 | +void au_export_init(struct super_block *sb) | |
13686 | +{ | |
13687 | + struct au_sbinfo *sbinfo; | |
13688 | + __u32 u; | |
13689 | + | |
5afbbe0d AM |
13690 | + BUILD_BUG_ON_MSG(IS_BUILTIN(CONFIG_AUFS_FS) |
13691 | + && IS_MODULE(CONFIG_EXPORTFS), | |
13692 | + AUFS_NAME ": unsupported configuration " | |
13693 | + "CONFIG_EXPORTFS=m and CONFIG_AUFS_FS=y"); | |
13694 | + | |
1facf9fc | 13695 | + sb->s_export_op = &aufs_export_op; |
13696 | + sbinfo = au_sbi(sb); | |
13697 | + sbinfo->si_xigen = NULL; | |
13698 | + get_random_bytes(&u, sizeof(u)); | |
13699 | + BUILD_BUG_ON(sizeof(u) != sizeof(int)); | |
13700 | + atomic_set(&sbinfo->si_xigen_next, u); | |
13701 | +} | |
076b876e | 13702 | diff -urN /usr/share/empty/fs/aufs/fhsm.c linux/fs/aufs/fhsm.c |
eca34b5c | 13703 | --- /usr/share/empty/fs/aufs/fhsm.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 13704 | +++ linux/fs/aufs/fhsm.c 2020-01-27 10:57:18.172204883 +0100 |
062440b3 | 13705 | @@ -0,0 +1,427 @@ |
cd7a4cd9 | 13706 | +// SPDX-License-Identifier: GPL-2.0 |
076b876e | 13707 | +/* |
d58c55f2 | 13708 | + * Copyright (C) 2011-2020 Junjiro R. Okajima |
076b876e AM |
13709 | + * |
13710 | + * This program, aufs is free software; you can redistribute it and/or modify | |
13711 | + * it under the terms of the GNU General Public License as published by | |
13712 | + * the Free Software Foundation; either version 2 of the License, or | |
13713 | + * (at your option) any later version. | |
13714 | + * | |
13715 | + * This program is distributed in the hope that it will be useful, | |
13716 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13717 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13718 | + * GNU General Public License for more details. | |
13719 | + * | |
13720 | + * You should have received a copy of the GNU General Public License | |
13721 | + * along with this program; if not, write to the Free Software | |
13722 | + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
13723 | + */ | |
13724 | + | |
13725 | +/* | |
13726 | + * File-based Hierarchy Storage Management | |
13727 | + */ | |
13728 | + | |
13729 | +#include <linux/anon_inodes.h> | |
13730 | +#include <linux/poll.h> | |
13731 | +#include <linux/seq_file.h> | |
13732 | +#include <linux/statfs.h> | |
13733 | +#include "aufs.h" | |
13734 | + | |
c1595e42 JR |
13735 | +static aufs_bindex_t au_fhsm_bottom(struct super_block *sb) |
13736 | +{ | |
13737 | + struct au_sbinfo *sbinfo; | |
13738 | + struct au_fhsm *fhsm; | |
13739 | + | |
13740 | + SiMustAnyLock(sb); | |
13741 | + | |
13742 | + sbinfo = au_sbi(sb); | |
13743 | + fhsm = &sbinfo->si_fhsm; | |
13744 | + AuDebugOn(!fhsm); | |
13745 | + return fhsm->fhsm_bottom; | |
13746 | +} | |
13747 | + | |
13748 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex) | |
13749 | +{ | |
13750 | + struct au_sbinfo *sbinfo; | |
13751 | + struct au_fhsm *fhsm; | |
13752 | + | |
13753 | + SiMustWriteLock(sb); | |
13754 | + | |
13755 | + sbinfo = au_sbi(sb); | |
13756 | + fhsm = &sbinfo->si_fhsm; | |
13757 | + AuDebugOn(!fhsm); | |
13758 | + fhsm->fhsm_bottom = bindex; | |
13759 | +} | |
13760 | + | |
13761 | +/* ---------------------------------------------------------------------- */ | |
13762 | + | |
076b876e AM |
13763 | +static int au_fhsm_test_jiffy(struct au_sbinfo *sbinfo, struct au_branch *br) |
13764 | +{ | |
13765 | + struct au_br_fhsm *bf; | |
13766 | + | |
13767 | + bf = br->br_fhsm; | |
13768 | + MtxMustLock(&bf->bf_lock); | |
13769 | + | |
13770 | + return !bf->bf_readable | |
13771 | + || time_after(jiffies, | |
13772 | + bf->bf_jiffy + sbinfo->si_fhsm.fhsm_expire); | |
13773 | +} | |
13774 | + | |
13775 | +/* ---------------------------------------------------------------------- */ | |
13776 | + | |
13777 | +static void au_fhsm_notify(struct super_block *sb, int val) | |
13778 | +{ | |
13779 | + struct au_sbinfo *sbinfo; | |
13780 | + struct au_fhsm *fhsm; | |
13781 | + | |
13782 | + SiMustAnyLock(sb); | |
13783 | + | |
13784 | + sbinfo = au_sbi(sb); | |
13785 | + fhsm = &sbinfo->si_fhsm; | |
13786 | + if (au_fhsm_pid(fhsm) | |
13787 | + && atomic_read(&fhsm->fhsm_readable) != -1) { | |
13788 | + atomic_set(&fhsm->fhsm_readable, val); | |
13789 | + if (val) | |
13790 | + wake_up(&fhsm->fhsm_wqh); | |
13791 | + } | |
13792 | +} | |
13793 | + | |
13794 | +static int au_fhsm_stfs(struct super_block *sb, aufs_bindex_t bindex, | |
13795 | + struct aufs_stfs *rstfs, int do_lock, int do_notify) | |
13796 | +{ | |
13797 | + int err; | |
13798 | + struct au_branch *br; | |
13799 | + struct au_br_fhsm *bf; | |
13800 | + | |
13801 | + br = au_sbr(sb, bindex); | |
13802 | + AuDebugOn(au_br_rdonly(br)); | |
13803 | + bf = br->br_fhsm; | |
13804 | + AuDebugOn(!bf); | |
13805 | + | |
13806 | + if (do_lock) | |
13807 | + mutex_lock(&bf->bf_lock); | |
13808 | + else | |
13809 | + MtxMustLock(&bf->bf_lock); | |
13810 | + | |
13811 | + /* sb->s_root for NFS is unreliable */ | |
13812 | + err = au_br_stfs(br, &bf->bf_stfs); | |
13813 | + if (unlikely(err)) { | |
13814 | + AuErr1("FHSM failed (%d), b%d, ignored.\n", bindex, err); | |
13815 | + goto out; | |
13816 | + } | |
13817 | + | |
13818 | + bf->bf_jiffy = jiffies; | |
13819 | + bf->bf_readable = 1; | |
13820 | + if (do_notify) | |
13821 | + au_fhsm_notify(sb, /*val*/1); | |
13822 | + if (rstfs) | |
13823 | + *rstfs = bf->bf_stfs; | |
13824 | + | |
13825 | +out: | |
13826 | + if (do_lock) | |
13827 | + mutex_unlock(&bf->bf_lock); | |
13828 | + au_fhsm_notify(sb, /*val*/1); | |
13829 | + | |
13830 | + return err; | |
13831 | +} | |
13832 | + | |
13833 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force) | |
13834 | +{ | |
13835 | + int err; | |
076b876e AM |
13836 | + struct au_sbinfo *sbinfo; |
13837 | + struct au_fhsm *fhsm; | |
13838 | + struct au_branch *br; | |
13839 | + struct au_br_fhsm *bf; | |
13840 | + | |
13841 | + AuDbg("b%d, force %d\n", bindex, force); | |
13842 | + SiMustAnyLock(sb); | |
13843 | + | |
13844 | + sbinfo = au_sbi(sb); | |
13845 | + fhsm = &sbinfo->si_fhsm; | |
c1595e42 JR |
13846 | + if (!au_ftest_si(sbinfo, FHSM) |
13847 | + || fhsm->fhsm_bottom == bindex) | |
076b876e AM |
13848 | + return; |
13849 | + | |
13850 | + br = au_sbr(sb, bindex); | |
13851 | + bf = br->br_fhsm; | |
13852 | + AuDebugOn(!bf); | |
13853 | + mutex_lock(&bf->bf_lock); | |
13854 | + if (force | |
13855 | + || au_fhsm_pid(fhsm) | |
13856 | + || au_fhsm_test_jiffy(sbinfo, br)) | |
13857 | + err = au_fhsm_stfs(sb, bindex, /*rstfs*/NULL, /*do_lock*/0, | |
13858 | + /*do_notify*/1); | |
13859 | + mutex_unlock(&bf->bf_lock); | |
13860 | +} | |
13861 | + | |
13862 | +void au_fhsm_wrote_all(struct super_block *sb, int force) | |
13863 | +{ | |
5afbbe0d | 13864 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
13865 | + struct au_branch *br; |
13866 | + | |
13867 | + /* exclude the bottom */ | |
5afbbe0d AM |
13868 | + bbot = au_fhsm_bottom(sb); |
13869 | + for (bindex = 0; bindex < bbot; bindex++) { | |
076b876e AM |
13870 | + br = au_sbr(sb, bindex); |
13871 | + if (au_br_fhsm(br->br_perm)) | |
13872 | + au_fhsm_wrote(sb, bindex, force); | |
13873 | + } | |
13874 | +} | |
13875 | + | |
13876 | +/* ---------------------------------------------------------------------- */ | |
13877 | + | |
be118d29 | 13878 | +static __poll_t au_fhsm_poll(struct file *file, struct poll_table_struct *wait) |
076b876e | 13879 | +{ |
be118d29 | 13880 | + __poll_t mask; |
076b876e AM |
13881 | + struct au_sbinfo *sbinfo; |
13882 | + struct au_fhsm *fhsm; | |
13883 | + | |
13884 | + mask = 0; | |
13885 | + sbinfo = file->private_data; | |
13886 | + fhsm = &sbinfo->si_fhsm; | |
13887 | + poll_wait(file, &fhsm->fhsm_wqh, wait); | |
13888 | + if (atomic_read(&fhsm->fhsm_readable)) | |
be118d29 | 13889 | + mask = EPOLLIN /* | EPOLLRDNORM */; |
076b876e | 13890 | + |
b00004a5 AM |
13891 | + if (!mask) |
13892 | + AuDbg("mask 0x%x\n", mask); | |
076b876e AM |
13893 | + return mask; |
13894 | +} | |
13895 | + | |
13896 | +static int au_fhsm_do_read_one(struct aufs_stbr __user *stbr, | |
13897 | + struct aufs_stfs *stfs, __s16 brid) | |
13898 | +{ | |
13899 | + int err; | |
13900 | + | |
13901 | + err = copy_to_user(&stbr->stfs, stfs, sizeof(*stfs)); | |
13902 | + if (!err) | |
13903 | + err = __put_user(brid, &stbr->brid); | |
13904 | + if (unlikely(err)) | |
13905 | + err = -EFAULT; | |
13906 | + | |
13907 | + return err; | |
13908 | +} | |
13909 | + | |
13910 | +static ssize_t au_fhsm_do_read(struct super_block *sb, | |
13911 | + struct aufs_stbr __user *stbr, size_t count) | |
13912 | +{ | |
13913 | + ssize_t err; | |
13914 | + int nstbr; | |
5afbbe0d | 13915 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
13916 | + struct au_branch *br; |
13917 | + struct au_br_fhsm *bf; | |
13918 | + | |
13919 | + /* except the bottom branch */ | |
13920 | + err = 0; | |
13921 | + nstbr = 0; | |
5afbbe0d AM |
13922 | + bbot = au_fhsm_bottom(sb); |
13923 | + for (bindex = 0; !err && bindex < bbot; bindex++) { | |
076b876e AM |
13924 | + br = au_sbr(sb, bindex); |
13925 | + if (!au_br_fhsm(br->br_perm)) | |
13926 | + continue; | |
13927 | + | |
13928 | + bf = br->br_fhsm; | |
13929 | + mutex_lock(&bf->bf_lock); | |
13930 | + if (bf->bf_readable) { | |
13931 | + err = -EFAULT; | |
13932 | + if (count >= sizeof(*stbr)) | |
13933 | + err = au_fhsm_do_read_one(stbr++, &bf->bf_stfs, | |
13934 | + br->br_id); | |
13935 | + if (!err) { | |
13936 | + bf->bf_readable = 0; | |
13937 | + count -= sizeof(*stbr); | |
13938 | + nstbr++; | |
13939 | + } | |
13940 | + } | |
13941 | + mutex_unlock(&bf->bf_lock); | |
13942 | + } | |
13943 | + if (!err) | |
13944 | + err = sizeof(*stbr) * nstbr; | |
13945 | + | |
13946 | + return err; | |
13947 | +} | |
13948 | + | |
13949 | +static ssize_t au_fhsm_read(struct file *file, char __user *buf, size_t count, | |
13950 | + loff_t *pos) | |
13951 | +{ | |
13952 | + ssize_t err; | |
13953 | + int readable; | |
5afbbe0d | 13954 | + aufs_bindex_t nfhsm, bindex, bbot; |
076b876e AM |
13955 | + struct au_sbinfo *sbinfo; |
13956 | + struct au_fhsm *fhsm; | |
13957 | + struct au_branch *br; | |
13958 | + struct super_block *sb; | |
13959 | + | |
13960 | + err = 0; | |
13961 | + sbinfo = file->private_data; | |
13962 | + fhsm = &sbinfo->si_fhsm; | |
13963 | +need_data: | |
13964 | + spin_lock_irq(&fhsm->fhsm_wqh.lock); | |
13965 | + if (!atomic_read(&fhsm->fhsm_readable)) { | |
13966 | + if (vfsub_file_flags(file) & O_NONBLOCK) | |
13967 | + err = -EAGAIN; | |
13968 | + else | |
13969 | + err = wait_event_interruptible_locked_irq | |
13970 | + (fhsm->fhsm_wqh, | |
13971 | + atomic_read(&fhsm->fhsm_readable)); | |
13972 | + } | |
13973 | + spin_unlock_irq(&fhsm->fhsm_wqh.lock); | |
13974 | + if (unlikely(err)) | |
13975 | + goto out; | |
13976 | + | |
13977 | + /* sb may already be dead */ | |
13978 | + au_rw_read_lock(&sbinfo->si_rwsem); | |
13979 | + readable = atomic_read(&fhsm->fhsm_readable); | |
13980 | + if (readable > 0) { | |
13981 | + sb = sbinfo->si_sb; | |
13982 | + AuDebugOn(!sb); | |
13983 | + /* exclude the bottom branch */ | |
13984 | + nfhsm = 0; | |
5afbbe0d AM |
13985 | + bbot = au_fhsm_bottom(sb); |
13986 | + for (bindex = 0; bindex < bbot; bindex++) { | |
076b876e AM |
13987 | + br = au_sbr(sb, bindex); |
13988 | + if (au_br_fhsm(br->br_perm)) | |
13989 | + nfhsm++; | |
13990 | + } | |
13991 | + err = -EMSGSIZE; | |
13992 | + if (nfhsm * sizeof(struct aufs_stbr) <= count) { | |
13993 | + atomic_set(&fhsm->fhsm_readable, 0); | |
13994 | + err = au_fhsm_do_read(sbinfo->si_sb, (void __user *)buf, | |
13995 | + count); | |
13996 | + } | |
13997 | + } | |
13998 | + au_rw_read_unlock(&sbinfo->si_rwsem); | |
13999 | + if (!readable) | |
14000 | + goto need_data; | |
14001 | + | |
14002 | +out: | |
14003 | + return err; | |
14004 | +} | |
14005 | + | |
14006 | +static int au_fhsm_release(struct inode *inode, struct file *file) | |
14007 | +{ | |
14008 | + struct au_sbinfo *sbinfo; | |
14009 | + struct au_fhsm *fhsm; | |
14010 | + | |
14011 | + /* sb may already be dead */ | |
14012 | + sbinfo = file->private_data; | |
14013 | + fhsm = &sbinfo->si_fhsm; | |
14014 | + spin_lock(&fhsm->fhsm_spin); | |
14015 | + fhsm->fhsm_pid = 0; | |
14016 | + spin_unlock(&fhsm->fhsm_spin); | |
14017 | + kobject_put(&sbinfo->si_kobj); | |
14018 | + | |
14019 | + return 0; | |
14020 | +} | |
14021 | + | |
14022 | +static const struct file_operations au_fhsm_fops = { | |
14023 | + .owner = THIS_MODULE, | |
14024 | + .llseek = noop_llseek, | |
14025 | + .read = au_fhsm_read, | |
14026 | + .poll = au_fhsm_poll, | |
14027 | + .release = au_fhsm_release | |
14028 | +}; | |
14029 | + | |
14030 | +int au_fhsm_fd(struct super_block *sb, int oflags) | |
14031 | +{ | |
14032 | + int err, fd; | |
14033 | + struct au_sbinfo *sbinfo; | |
14034 | + struct au_fhsm *fhsm; | |
14035 | + | |
14036 | + err = -EPERM; | |
14037 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
14038 | + goto out; | |
14039 | + | |
14040 | + err = -EINVAL; | |
14041 | + if (unlikely(oflags & ~(O_CLOEXEC | O_NONBLOCK))) | |
14042 | + goto out; | |
14043 | + | |
14044 | + err = 0; | |
14045 | + sbinfo = au_sbi(sb); | |
14046 | + fhsm = &sbinfo->si_fhsm; | |
14047 | + spin_lock(&fhsm->fhsm_spin); | |
14048 | + if (!fhsm->fhsm_pid) | |
14049 | + fhsm->fhsm_pid = current->pid; | |
14050 | + else | |
14051 | + err = -EBUSY; | |
14052 | + spin_unlock(&fhsm->fhsm_spin); | |
14053 | + if (unlikely(err)) | |
14054 | + goto out; | |
14055 | + | |
14056 | + oflags |= O_RDONLY; | |
14057 | + /* oflags |= FMODE_NONOTIFY; */ | |
14058 | + fd = anon_inode_getfd("[aufs_fhsm]", &au_fhsm_fops, sbinfo, oflags); | |
14059 | + err = fd; | |
14060 | + if (unlikely(fd < 0)) | |
14061 | + goto out_pid; | |
14062 | + | |
acd2b654 | 14063 | + /* succeed regardless 'fhsm' status */ |
076b876e AM |
14064 | + kobject_get(&sbinfo->si_kobj); |
14065 | + si_noflush_read_lock(sb); | |
14066 | + if (au_ftest_si(sbinfo, FHSM)) | |
14067 | + au_fhsm_wrote_all(sb, /*force*/0); | |
14068 | + si_read_unlock(sb); | |
14069 | + goto out; /* success */ | |
14070 | + | |
14071 | +out_pid: | |
14072 | + spin_lock(&fhsm->fhsm_spin); | |
14073 | + fhsm->fhsm_pid = 0; | |
14074 | + spin_unlock(&fhsm->fhsm_spin); | |
14075 | +out: | |
14076 | + AuTraceErr(err); | |
14077 | + return err; | |
14078 | +} | |
14079 | + | |
14080 | +/* ---------------------------------------------------------------------- */ | |
14081 | + | |
14082 | +int au_fhsm_br_alloc(struct au_branch *br) | |
14083 | +{ | |
14084 | + int err; | |
14085 | + | |
14086 | + err = 0; | |
14087 | + br->br_fhsm = kmalloc(sizeof(*br->br_fhsm), GFP_NOFS); | |
14088 | + if (br->br_fhsm) | |
14089 | + au_br_fhsm_init(br->br_fhsm); | |
14090 | + else | |
14091 | + err = -ENOMEM; | |
14092 | + | |
14093 | + return err; | |
14094 | +} | |
14095 | + | |
14096 | +/* ---------------------------------------------------------------------- */ | |
14097 | + | |
14098 | +void au_fhsm_fin(struct super_block *sb) | |
14099 | +{ | |
14100 | + au_fhsm_notify(sb, /*val*/-1); | |
14101 | +} | |
14102 | + | |
14103 | +void au_fhsm_init(struct au_sbinfo *sbinfo) | |
14104 | +{ | |
14105 | + struct au_fhsm *fhsm; | |
14106 | + | |
14107 | + fhsm = &sbinfo->si_fhsm; | |
14108 | + spin_lock_init(&fhsm->fhsm_spin); | |
14109 | + init_waitqueue_head(&fhsm->fhsm_wqh); | |
14110 | + atomic_set(&fhsm->fhsm_readable, 0); | |
14111 | + fhsm->fhsm_expire | |
14112 | + = msecs_to_jiffies(AUFS_FHSM_CACHE_DEF_SEC * MSEC_PER_SEC); | |
c1595e42 | 14113 | + fhsm->fhsm_bottom = -1; |
076b876e AM |
14114 | +} |
14115 | + | |
14116 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec) | |
14117 | +{ | |
14118 | + sbinfo->si_fhsm.fhsm_expire | |
14119 | + = msecs_to_jiffies(sec * MSEC_PER_SEC); | |
14120 | +} | |
14121 | + | |
14122 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo) | |
14123 | +{ | |
14124 | + unsigned int u; | |
14125 | + | |
14126 | + if (!au_ftest_si(sbinfo, FHSM)) | |
14127 | + return; | |
14128 | + | |
14129 | + u = jiffies_to_msecs(sbinfo->si_fhsm.fhsm_expire) / MSEC_PER_SEC; | |
14130 | + if (u != AUFS_FHSM_CACHE_DEF_SEC) | |
14131 | + seq_printf(seq, ",fhsm_sec=%u", u); | |
14132 | +} | |
7f207e10 | 14133 | diff -urN /usr/share/empty/fs/aufs/file.c linux/fs/aufs/file.c |
eca34b5c | 14134 | --- /usr/share/empty/fs/aufs/file.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 14135 | +++ linux/fs/aufs/file.c 2020-01-27 10:57:18.172204883 +0100 |
acd2b654 | 14136 | @@ -0,0 +1,863 @@ |
cd7a4cd9 | 14137 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 14138 | +/* |
d58c55f2 | 14139 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 14140 | + * |
14141 | + * This program, aufs is free software; you can redistribute it and/or modify | |
14142 | + * it under the terms of the GNU General Public License as published by | |
14143 | + * the Free Software Foundation; either version 2 of the License, or | |
14144 | + * (at your option) any later version. | |
dece6358 AM |
14145 | + * |
14146 | + * This program is distributed in the hope that it will be useful, | |
14147 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14148 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14149 | + * GNU General Public License for more details. | |
14150 | + * | |
14151 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 14152 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 14153 | + */ |
14154 | + | |
14155 | +/* | |
4a4d8108 | 14156 | + * handling file/dir, and address_space operation |
1facf9fc | 14157 | + */ |
14158 | + | |
7eafdf33 AM |
14159 | +#ifdef CONFIG_AUFS_DEBUG |
14160 | +#include <linux/migrate.h> | |
14161 | +#endif | |
4a4d8108 | 14162 | +#include <linux/pagemap.h> |
1facf9fc | 14163 | +#include "aufs.h" |
14164 | + | |
4a4d8108 AM |
14165 | +/* drop flags for writing */ |
14166 | +unsigned int au_file_roflags(unsigned int flags) | |
14167 | +{ | |
14168 | + flags &= ~(O_WRONLY | O_RDWR | O_APPEND | O_CREAT | O_TRUNC); | |
14169 | + flags |= O_RDONLY | O_NOATIME; | |
14170 | + return flags; | |
14171 | +} | |
14172 | + | |
14173 | +/* common functions to regular file and dir */ | |
14174 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 14175 | + struct file *file, int force_wr) |
1facf9fc | 14176 | +{ |
1308ab2a | 14177 | + struct file *h_file; |
4a4d8108 AM |
14178 | + struct dentry *h_dentry; |
14179 | + struct inode *h_inode; | |
14180 | + struct super_block *sb; | |
14181 | + struct au_branch *br; | |
14182 | + struct path h_path; | |
b912730e | 14183 | + int err; |
1facf9fc | 14184 | + |
4a4d8108 AM |
14185 | + /* a race condition can happen between open and unlink/rmdir */ |
14186 | + h_file = ERR_PTR(-ENOENT); | |
14187 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 14188 | + if (au_test_nfsd() && (!h_dentry || d_is_negative(h_dentry))) |
4a4d8108 | 14189 | + goto out; |
5527c038 | 14190 | + h_inode = d_inode(h_dentry); |
027c5e7a AM |
14191 | + spin_lock(&h_dentry->d_lock); |
14192 | + err = (!d_unhashed(dentry) && d_unlinked(h_dentry)) | |
5527c038 | 14193 | + /* || !d_inode(dentry)->i_nlink */ |
027c5e7a AM |
14194 | + ; |
14195 | + spin_unlock(&h_dentry->d_lock); | |
14196 | + if (unlikely(err)) | |
4a4d8108 | 14197 | + goto out; |
1facf9fc | 14198 | + |
4a4d8108 AM |
14199 | + sb = dentry->d_sb; |
14200 | + br = au_sbr(sb, bindex); | |
b912730e AM |
14201 | + err = au_br_test_oflag(flags, br); |
14202 | + h_file = ERR_PTR(err); | |
14203 | + if (unlikely(err)) | |
027c5e7a | 14204 | + goto out; |
1facf9fc | 14205 | + |
4a4d8108 | 14206 | + /* drop flags for writing */ |
5527c038 | 14207 | + if (au_test_ro(sb, bindex, d_inode(dentry))) { |
392086de AM |
14208 | + if (force_wr && !(flags & O_WRONLY)) |
14209 | + force_wr = 0; | |
4a4d8108 | 14210 | + flags = au_file_roflags(flags); |
392086de AM |
14211 | + if (force_wr) { |
14212 | + h_file = ERR_PTR(-EROFS); | |
14213 | + flags = au_file_roflags(flags); | |
14214 | + if (unlikely(vfsub_native_ro(h_inode) | |
14215 | + || IS_APPEND(h_inode))) | |
14216 | + goto out; | |
14217 | + flags &= ~O_ACCMODE; | |
14218 | + flags |= O_WRONLY; | |
14219 | + } | |
14220 | + } | |
4a4d8108 | 14221 | + flags &= ~O_CREAT; |
acd2b654 | 14222 | + au_lcnt_inc(&br->br_nfiles); |
4a4d8108 | 14223 | + h_path.dentry = h_dentry; |
86dc4139 | 14224 | + h_path.mnt = au_br_mnt(br); |
38d290e6 | 14225 | + h_file = vfsub_dentry_open(&h_path, flags); |
4a4d8108 AM |
14226 | + if (IS_ERR(h_file)) |
14227 | + goto out_br; | |
dece6358 | 14228 | + |
b912730e | 14229 | + if (flags & __FMODE_EXEC) { |
4a4d8108 AM |
14230 | + err = deny_write_access(h_file); |
14231 | + if (unlikely(err)) { | |
14232 | + fput(h_file); | |
14233 | + h_file = ERR_PTR(err); | |
14234 | + goto out_br; | |
14235 | + } | |
14236 | + } | |
953406b4 | 14237 | + fsnotify_open(h_file); |
4a4d8108 | 14238 | + goto out; /* success */ |
1facf9fc | 14239 | + |
4f0767ce | 14240 | +out_br: |
acd2b654 | 14241 | + au_lcnt_dec(&br->br_nfiles); |
4f0767ce | 14242 | +out: |
4a4d8108 AM |
14243 | + return h_file; |
14244 | +} | |
1308ab2a | 14245 | + |
076b876e AM |
14246 | +static int au_cmoo(struct dentry *dentry) |
14247 | +{ | |
8b6a4947 | 14248 | + int err, cmoo, matched; |
076b876e AM |
14249 | + unsigned int udba; |
14250 | + struct path h_path; | |
14251 | + struct au_pin pin; | |
14252 | + struct au_cp_generic cpg = { | |
14253 | + .dentry = dentry, | |
14254 | + .bdst = -1, | |
14255 | + .bsrc = -1, | |
14256 | + .len = -1, | |
14257 | + .pin = &pin, | |
14258 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
14259 | + }; | |
7e9cd9fe | 14260 | + struct inode *delegated; |
076b876e AM |
14261 | + struct super_block *sb; |
14262 | + struct au_sbinfo *sbinfo; | |
14263 | + struct au_fhsm *fhsm; | |
14264 | + pid_t pid; | |
14265 | + struct au_branch *br; | |
14266 | + struct dentry *parent; | |
14267 | + struct au_hinode *hdir; | |
14268 | + | |
14269 | + DiMustWriteLock(dentry); | |
5527c038 | 14270 | + IiMustWriteLock(d_inode(dentry)); |
076b876e AM |
14271 | + |
14272 | + err = 0; | |
14273 | + if (IS_ROOT(dentry)) | |
14274 | + goto out; | |
5afbbe0d | 14275 | + cpg.bsrc = au_dbtop(dentry); |
076b876e AM |
14276 | + if (!cpg.bsrc) |
14277 | + goto out; | |
14278 | + | |
14279 | + sb = dentry->d_sb; | |
14280 | + sbinfo = au_sbi(sb); | |
14281 | + fhsm = &sbinfo->si_fhsm; | |
14282 | + pid = au_fhsm_pid(fhsm); | |
8b6a4947 AM |
14283 | + rcu_read_lock(); |
14284 | + matched = (pid | |
14285 | + && (current->pid == pid | |
14286 | + || rcu_dereference(current->real_parent)->pid == pid)); | |
14287 | + rcu_read_unlock(); | |
14288 | + if (matched) | |
076b876e AM |
14289 | + goto out; |
14290 | + | |
14291 | + br = au_sbr(sb, cpg.bsrc); | |
14292 | + cmoo = au_br_cmoo(br->br_perm); | |
14293 | + if (!cmoo) | |
14294 | + goto out; | |
7e9cd9fe | 14295 | + if (!d_is_reg(dentry)) |
076b876e AM |
14296 | + cmoo &= AuBrAttr_COO_ALL; |
14297 | + if (!cmoo) | |
14298 | + goto out; | |
14299 | + | |
14300 | + parent = dget_parent(dentry); | |
14301 | + di_write_lock_parent(parent); | |
14302 | + err = au_wbr_do_copyup_bu(dentry, cpg.bsrc - 1); | |
14303 | + cpg.bdst = err; | |
14304 | + if (unlikely(err < 0)) { | |
14305 | + err = 0; /* there is no upper writable branch */ | |
14306 | + goto out_dgrade; | |
14307 | + } | |
14308 | + AuDbg("bsrc %d, bdst %d\n", cpg.bsrc, cpg.bdst); | |
14309 | + | |
14310 | + /* do not respect the coo attrib for the target branch */ | |
14311 | + err = au_cpup_dirs(dentry, cpg.bdst); | |
14312 | + if (unlikely(err)) | |
14313 | + goto out_dgrade; | |
14314 | + | |
14315 | + di_downgrade_lock(parent, AuLock_IR); | |
14316 | + udba = au_opt_udba(sb); | |
14317 | + err = au_pin(&pin, dentry, cpg.bdst, udba, | |
14318 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
14319 | + if (unlikely(err)) | |
14320 | + goto out_parent; | |
14321 | + | |
14322 | + err = au_sio_cpup_simple(&cpg); | |
14323 | + au_unpin(&pin); | |
14324 | + if (unlikely(err)) | |
14325 | + goto out_parent; | |
14326 | + if (!(cmoo & AuBrWAttr_MOO)) | |
14327 | + goto out_parent; /* success */ | |
14328 | + | |
14329 | + err = au_pin(&pin, dentry, cpg.bsrc, udba, | |
14330 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
14331 | + if (unlikely(err)) | |
14332 | + goto out_parent; | |
14333 | + | |
14334 | + h_path.mnt = au_br_mnt(br); | |
14335 | + h_path.dentry = au_h_dptr(dentry, cpg.bsrc); | |
5527c038 | 14336 | + hdir = au_hi(d_inode(parent), cpg.bsrc); |
076b876e AM |
14337 | + delegated = NULL; |
14338 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, /*force*/1); | |
14339 | + au_unpin(&pin); | |
14340 | + /* todo: keep h_dentry or not? */ | |
14341 | + if (unlikely(err == -EWOULDBLOCK)) { | |
14342 | + pr_warn("cannot retry for NFSv4 delegation" | |
14343 | + " for an internal unlink\n"); | |
14344 | + iput(delegated); | |
14345 | + } | |
14346 | + if (unlikely(err)) { | |
14347 | + pr_err("unlink %pd after coo failed (%d), ignored\n", | |
14348 | + dentry, err); | |
14349 | + err = 0; | |
14350 | + } | |
14351 | + goto out_parent; /* success */ | |
14352 | + | |
14353 | +out_dgrade: | |
14354 | + di_downgrade_lock(parent, AuLock_IR); | |
14355 | +out_parent: | |
14356 | + di_read_unlock(parent, AuLock_IR); | |
14357 | + dput(parent); | |
14358 | +out: | |
14359 | + AuTraceErr(err); | |
14360 | + return err; | |
14361 | +} | |
14362 | + | |
b912730e | 14363 | +int au_do_open(struct file *file, struct au_do_open_args *args) |
1facf9fc | 14364 | +{ |
8b6a4947 | 14365 | + int err, aopen = args->aopen; |
1facf9fc | 14366 | + struct dentry *dentry; |
076b876e | 14367 | + struct au_finfo *finfo; |
1308ab2a | 14368 | + |
8b6a4947 | 14369 | + if (!aopen) |
b912730e AM |
14370 | + err = au_finfo_init(file, args->fidir); |
14371 | + else { | |
14372 | + lockdep_off(); | |
14373 | + err = au_finfo_init(file, args->fidir); | |
14374 | + lockdep_on(); | |
14375 | + } | |
4a4d8108 AM |
14376 | + if (unlikely(err)) |
14377 | + goto out; | |
1facf9fc | 14378 | + |
2000de60 | 14379 | + dentry = file->f_path.dentry; |
b912730e | 14380 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
8b6a4947 AM |
14381 | + di_write_lock_child(dentry); |
14382 | + err = au_cmoo(dentry); | |
14383 | + di_downgrade_lock(dentry, AuLock_IR); | |
14384 | + if (!err) { | |
14385 | + if (!aopen) | |
b912730e | 14386 | + err = args->open(file, vfsub_file_flags(file), NULL); |
8b6a4947 AM |
14387 | + else { |
14388 | + lockdep_off(); | |
acd2b654 AM |
14389 | + err = args->open(file, vfsub_file_flags(file), |
14390 | + args->h_file); | |
8b6a4947 AM |
14391 | + lockdep_on(); |
14392 | + } | |
b912730e | 14393 | + } |
8b6a4947 | 14394 | + di_read_unlock(dentry, AuLock_IR); |
1facf9fc | 14395 | + |
076b876e AM |
14396 | + finfo = au_fi(file); |
14397 | + if (!err) { | |
14398 | + finfo->fi_file = file; | |
8b6a4947 AM |
14399 | + au_hbl_add(&finfo->fi_hlist, |
14400 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
076b876e | 14401 | + } |
8b6a4947 | 14402 | + if (!aopen) |
b912730e AM |
14403 | + fi_write_unlock(file); |
14404 | + else { | |
14405 | + lockdep_off(); | |
14406 | + fi_write_unlock(file); | |
14407 | + lockdep_on(); | |
14408 | + } | |
4a4d8108 | 14409 | + if (unlikely(err)) { |
076b876e | 14410 | + finfo->fi_hdir = NULL; |
1c60b727 | 14411 | + au_finfo_fin(file); |
1308ab2a | 14412 | + } |
4a4d8108 | 14413 | + |
4f0767ce | 14414 | +out: |
8b6a4947 | 14415 | + AuTraceErr(err); |
1308ab2a | 14416 | + return err; |
14417 | +} | |
dece6358 | 14418 | + |
4a4d8108 | 14419 | +int au_reopen_nondir(struct file *file) |
1308ab2a | 14420 | +{ |
4a4d8108 | 14421 | + int err; |
5afbbe0d | 14422 | + aufs_bindex_t btop; |
4a4d8108 | 14423 | + struct dentry *dentry; |
acd2b654 | 14424 | + struct au_branch *br; |
4a4d8108 | 14425 | + struct file *h_file, *h_file_tmp; |
1308ab2a | 14426 | + |
2000de60 | 14427 | + dentry = file->f_path.dentry; |
5afbbe0d | 14428 | + btop = au_dbtop(dentry); |
acd2b654 | 14429 | + br = au_sbr(dentry->d_sb, btop); |
4a4d8108 | 14430 | + h_file_tmp = NULL; |
5afbbe0d | 14431 | + if (au_fbtop(file) == btop) { |
4a4d8108 AM |
14432 | + h_file = au_hf_top(file); |
14433 | + if (file->f_mode == h_file->f_mode) | |
14434 | + return 0; /* success */ | |
14435 | + h_file_tmp = h_file; | |
14436 | + get_file(h_file_tmp); | |
acd2b654 | 14437 | + au_lcnt_inc(&br->br_nfiles); |
5afbbe0d | 14438 | + au_set_h_fptr(file, btop, NULL); |
4a4d8108 AM |
14439 | + } |
14440 | + AuDebugOn(au_fi(file)->fi_hdir); | |
86dc4139 AM |
14441 | + /* |
14442 | + * it can happen | |
14443 | + * file exists on both of rw and ro | |
5afbbe0d | 14444 | + * open --> dbtop and fbtop are both 0 |
86dc4139 AM |
14445 | + * prepend a branch as rw, "rw" become ro |
14446 | + * remove rw/file | |
14447 | + * delete the top branch, "rw" becomes rw again | |
5afbbe0d AM |
14448 | + * --> dbtop is 1, fbtop is still 0 |
14449 | + * write --> fbtop is 0 but dbtop is 1 | |
86dc4139 | 14450 | + */ |
5afbbe0d | 14451 | + /* AuDebugOn(au_fbtop(file) < btop); */ |
1308ab2a | 14452 | + |
5afbbe0d | 14453 | + h_file = au_h_open(dentry, btop, vfsub_file_flags(file) & ~O_TRUNC, |
392086de | 14454 | + file, /*force_wr*/0); |
4a4d8108 | 14455 | + err = PTR_ERR(h_file); |
86dc4139 AM |
14456 | + if (IS_ERR(h_file)) { |
14457 | + if (h_file_tmp) { | |
acd2b654 | 14458 | + /* revert */ |
5afbbe0d | 14459 | + au_set_h_fptr(file, btop, h_file_tmp); |
86dc4139 AM |
14460 | + h_file_tmp = NULL; |
14461 | + } | |
4a4d8108 | 14462 | + goto out; /* todo: close all? */ |
86dc4139 | 14463 | + } |
4a4d8108 AM |
14464 | + |
14465 | + err = 0; | |
5afbbe0d AM |
14466 | + au_set_fbtop(file, btop); |
14467 | + au_set_h_fptr(file, btop, h_file); | |
4a4d8108 AM |
14468 | + au_update_figen(file); |
14469 | + /* todo: necessary? */ | |
14470 | + /* file->f_ra = h_file->f_ra; */ | |
14471 | + | |
4f0767ce | 14472 | +out: |
acd2b654 | 14473 | + if (h_file_tmp) { |
4a4d8108 | 14474 | + fput(h_file_tmp); |
acd2b654 AM |
14475 | + au_lcnt_dec(&br->br_nfiles); |
14476 | + } | |
4a4d8108 | 14477 | + return err; |
1facf9fc | 14478 | +} |
14479 | + | |
1308ab2a | 14480 | +/* ---------------------------------------------------------------------- */ |
14481 | + | |
4a4d8108 AM |
14482 | +static int au_reopen_wh(struct file *file, aufs_bindex_t btgt, |
14483 | + struct dentry *hi_wh) | |
1facf9fc | 14484 | +{ |
4a4d8108 | 14485 | + int err; |
5afbbe0d | 14486 | + aufs_bindex_t btop; |
4a4d8108 AM |
14487 | + struct au_dinfo *dinfo; |
14488 | + struct dentry *h_dentry; | |
14489 | + struct au_hdentry *hdp; | |
1facf9fc | 14490 | + |
2000de60 | 14491 | + dinfo = au_di(file->f_path.dentry); |
4a4d8108 | 14492 | + AuRwMustWriteLock(&dinfo->di_rwsem); |
dece6358 | 14493 | + |
5afbbe0d AM |
14494 | + btop = dinfo->di_btop; |
14495 | + dinfo->di_btop = btgt; | |
14496 | + hdp = au_hdentry(dinfo, btgt); | |
14497 | + h_dentry = hdp->hd_dentry; | |
14498 | + hdp->hd_dentry = hi_wh; | |
4a4d8108 | 14499 | + err = au_reopen_nondir(file); |
5afbbe0d AM |
14500 | + hdp->hd_dentry = h_dentry; |
14501 | + dinfo->di_btop = btop; | |
1facf9fc | 14502 | + |
1facf9fc | 14503 | + return err; |
14504 | +} | |
14505 | + | |
4a4d8108 | 14506 | +static int au_ready_to_write_wh(struct file *file, loff_t len, |
86dc4139 | 14507 | + aufs_bindex_t bcpup, struct au_pin *pin) |
1facf9fc | 14508 | +{ |
4a4d8108 | 14509 | + int err; |
027c5e7a | 14510 | + struct inode *inode, *h_inode; |
c2b27bf2 AM |
14511 | + struct dentry *h_dentry, *hi_wh; |
14512 | + struct au_cp_generic cpg = { | |
2000de60 | 14513 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
14514 | + .bdst = bcpup, |
14515 | + .bsrc = -1, | |
14516 | + .len = len, | |
14517 | + .pin = pin | |
14518 | + }; | |
1facf9fc | 14519 | + |
5afbbe0d | 14520 | + au_update_dbtop(cpg.dentry); |
5527c038 | 14521 | + inode = d_inode(cpg.dentry); |
027c5e7a | 14522 | + h_inode = NULL; |
5afbbe0d AM |
14523 | + if (au_dbtop(cpg.dentry) <= bcpup |
14524 | + && au_dbbot(cpg.dentry) >= bcpup) { | |
c2b27bf2 | 14525 | + h_dentry = au_h_dptr(cpg.dentry, bcpup); |
5527c038 JR |
14526 | + if (h_dentry && d_is_positive(h_dentry)) |
14527 | + h_inode = d_inode(h_dentry); | |
027c5e7a | 14528 | + } |
4a4d8108 | 14529 | + hi_wh = au_hi_wh(inode, bcpup); |
027c5e7a | 14530 | + if (!hi_wh && !h_inode) |
c2b27bf2 | 14531 | + err = au_sio_cpup_wh(&cpg, file); |
4a4d8108 AM |
14532 | + else |
14533 | + /* already copied-up after unlink */ | |
14534 | + err = au_reopen_wh(file, bcpup, hi_wh); | |
1facf9fc | 14535 | + |
4a4d8108 | 14536 | + if (!err |
38d290e6 JR |
14537 | + && (inode->i_nlink > 1 |
14538 | + || (inode->i_state & I_LINKABLE)) | |
c2b27bf2 AM |
14539 | + && au_opt_test(au_mntflags(cpg.dentry->d_sb), PLINK)) |
14540 | + au_plink_append(inode, bcpup, au_h_dptr(cpg.dentry, bcpup)); | |
1308ab2a | 14541 | + |
dece6358 | 14542 | + return err; |
1facf9fc | 14543 | +} |
14544 | + | |
4a4d8108 AM |
14545 | +/* |
14546 | + * prepare the @file for writing. | |
14547 | + */ | |
14548 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin) | |
1facf9fc | 14549 | +{ |
4a4d8108 | 14550 | + int err; |
5afbbe0d | 14551 | + aufs_bindex_t dbtop; |
c1595e42 | 14552 | + struct dentry *parent; |
86dc4139 | 14553 | + struct inode *inode; |
1facf9fc | 14554 | + struct super_block *sb; |
4a4d8108 | 14555 | + struct file *h_file; |
c2b27bf2 | 14556 | + struct au_cp_generic cpg = { |
2000de60 | 14557 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
14558 | + .bdst = -1, |
14559 | + .bsrc = -1, | |
14560 | + .len = len, | |
14561 | + .pin = pin, | |
14562 | + .flags = AuCpup_DTIME | |
14563 | + }; | |
1facf9fc | 14564 | + |
c2b27bf2 | 14565 | + sb = cpg.dentry->d_sb; |
5527c038 | 14566 | + inode = d_inode(cpg.dentry); |
5afbbe0d | 14567 | + cpg.bsrc = au_fbtop(file); |
c2b27bf2 | 14568 | + err = au_test_ro(sb, cpg.bsrc, inode); |
4a4d8108 | 14569 | + if (!err && (au_hf_top(file)->f_mode & FMODE_WRITE)) { |
c2b27bf2 AM |
14570 | + err = au_pin(pin, cpg.dentry, cpg.bsrc, AuOpt_UDBA_NONE, |
14571 | + /*flags*/0); | |
1facf9fc | 14572 | + goto out; |
4a4d8108 | 14573 | + } |
1facf9fc | 14574 | + |
027c5e7a | 14575 | + /* need to cpup or reopen */ |
c2b27bf2 | 14576 | + parent = dget_parent(cpg.dentry); |
4a4d8108 | 14577 | + di_write_lock_parent(parent); |
c2b27bf2 AM |
14578 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
14579 | + cpg.bdst = err; | |
4a4d8108 AM |
14580 | + if (unlikely(err < 0)) |
14581 | + goto out_dgrade; | |
14582 | + err = 0; | |
14583 | + | |
c2b27bf2 AM |
14584 | + if (!d_unhashed(cpg.dentry) && !au_h_dptr(parent, cpg.bdst)) { |
14585 | + err = au_cpup_dirs(cpg.dentry, cpg.bdst); | |
1facf9fc | 14586 | + if (unlikely(err)) |
4a4d8108 AM |
14587 | + goto out_dgrade; |
14588 | + } | |
14589 | + | |
c2b27bf2 | 14590 | + err = au_pin(pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 AM |
14591 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
14592 | + if (unlikely(err)) | |
14593 | + goto out_dgrade; | |
14594 | + | |
5afbbe0d AM |
14595 | + dbtop = au_dbtop(cpg.dentry); |
14596 | + if (dbtop <= cpg.bdst) | |
c2b27bf2 | 14597 | + cpg.bsrc = cpg.bdst; |
027c5e7a | 14598 | + |
5afbbe0d | 14599 | + if (dbtop <= cpg.bdst /* just reopen */ |
c2b27bf2 | 14600 | + || !d_unhashed(cpg.dentry) /* copyup and reopen */ |
027c5e7a | 14601 | + ) { |
392086de | 14602 | + h_file = au_h_open_pre(cpg.dentry, cpg.bsrc, /*force_wr*/0); |
86dc4139 | 14603 | + if (IS_ERR(h_file)) |
027c5e7a | 14604 | + err = PTR_ERR(h_file); |
86dc4139 | 14605 | + else { |
027c5e7a | 14606 | + di_downgrade_lock(parent, AuLock_IR); |
5afbbe0d | 14607 | + if (dbtop > cpg.bdst) |
c2b27bf2 | 14608 | + err = au_sio_cpup_simple(&cpg); |
027c5e7a AM |
14609 | + if (!err) |
14610 | + err = au_reopen_nondir(file); | |
c2b27bf2 | 14611 | + au_h_open_post(cpg.dentry, cpg.bsrc, h_file); |
027c5e7a | 14612 | + } |
027c5e7a AM |
14613 | + } else { /* copyup as wh and reopen */ |
14614 | + /* | |
14615 | + * since writable hfsplus branch is not supported, | |
14616 | + * h_open_pre/post() are unnecessary. | |
14617 | + */ | |
c2b27bf2 | 14618 | + err = au_ready_to_write_wh(file, len, cpg.bdst, pin); |
4a4d8108 | 14619 | + di_downgrade_lock(parent, AuLock_IR); |
4a4d8108 | 14620 | + } |
4a4d8108 AM |
14621 | + |
14622 | + if (!err) { | |
14623 | + au_pin_set_parent_lflag(pin, /*lflag*/0); | |
14624 | + goto out_dput; /* success */ | |
14625 | + } | |
14626 | + au_unpin(pin); | |
14627 | + goto out_unlock; | |
1facf9fc | 14628 | + |
4f0767ce | 14629 | +out_dgrade: |
4a4d8108 | 14630 | + di_downgrade_lock(parent, AuLock_IR); |
4f0767ce | 14631 | +out_unlock: |
4a4d8108 | 14632 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 14633 | +out_dput: |
4a4d8108 | 14634 | + dput(parent); |
4f0767ce | 14635 | +out: |
1facf9fc | 14636 | + return err; |
14637 | +} | |
14638 | + | |
4a4d8108 AM |
14639 | +/* ---------------------------------------------------------------------- */ |
14640 | + | |
14641 | +int au_do_flush(struct file *file, fl_owner_t id, | |
14642 | + int (*flush)(struct file *file, fl_owner_t id)) | |
1facf9fc | 14643 | +{ |
4a4d8108 | 14644 | + int err; |
1facf9fc | 14645 | + struct super_block *sb; |
4a4d8108 | 14646 | + struct inode *inode; |
1facf9fc | 14647 | + |
c06a8ce3 AM |
14648 | + inode = file_inode(file); |
14649 | + sb = inode->i_sb; | |
4a4d8108 AM |
14650 | + si_noflush_read_lock(sb); |
14651 | + fi_read_lock(file); | |
b752ccd1 | 14652 | + ii_read_lock_child(inode); |
1facf9fc | 14653 | + |
4a4d8108 AM |
14654 | + err = flush(file, id); |
14655 | + au_cpup_attr_timesizes(inode); | |
1facf9fc | 14656 | + |
b752ccd1 | 14657 | + ii_read_unlock(inode); |
4a4d8108 | 14658 | + fi_read_unlock(file); |
1308ab2a | 14659 | + si_read_unlock(sb); |
dece6358 | 14660 | + return err; |
1facf9fc | 14661 | +} |
14662 | + | |
4a4d8108 AM |
14663 | +/* ---------------------------------------------------------------------- */ |
14664 | + | |
14665 | +static int au_file_refresh_by_inode(struct file *file, int *need_reopen) | |
1facf9fc | 14666 | +{ |
4a4d8108 | 14667 | + int err; |
4a4d8108 AM |
14668 | + struct au_pin pin; |
14669 | + struct au_finfo *finfo; | |
c2b27bf2 | 14670 | + struct dentry *parent, *hi_wh; |
4a4d8108 | 14671 | + struct inode *inode; |
1facf9fc | 14672 | + struct super_block *sb; |
c2b27bf2 | 14673 | + struct au_cp_generic cpg = { |
2000de60 | 14674 | + .dentry = file->f_path.dentry, |
c2b27bf2 AM |
14675 | + .bdst = -1, |
14676 | + .bsrc = -1, | |
14677 | + .len = -1, | |
14678 | + .pin = &pin, | |
14679 | + .flags = AuCpup_DTIME | |
14680 | + }; | |
1facf9fc | 14681 | + |
4a4d8108 AM |
14682 | + FiMustWriteLock(file); |
14683 | + | |
14684 | + err = 0; | |
14685 | + finfo = au_fi(file); | |
c2b27bf2 | 14686 | + sb = cpg.dentry->d_sb; |
5527c038 | 14687 | + inode = d_inode(cpg.dentry); |
5afbbe0d | 14688 | + cpg.bdst = au_ibtop(inode); |
c2b27bf2 | 14689 | + if (cpg.bdst == finfo->fi_btop || IS_ROOT(cpg.dentry)) |
1308ab2a | 14690 | + goto out; |
dece6358 | 14691 | + |
c2b27bf2 AM |
14692 | + parent = dget_parent(cpg.dentry); |
14693 | + if (au_test_ro(sb, cpg.bdst, inode)) { | |
4a4d8108 | 14694 | + di_read_lock_parent(parent, !AuLock_IR); |
c2b27bf2 AM |
14695 | + err = AuWbrCopyup(au_sbi(sb), cpg.dentry); |
14696 | + cpg.bdst = err; | |
4a4d8108 AM |
14697 | + di_read_unlock(parent, !AuLock_IR); |
14698 | + if (unlikely(err < 0)) | |
14699 | + goto out_parent; | |
14700 | + err = 0; | |
1facf9fc | 14701 | + } |
1facf9fc | 14702 | + |
4a4d8108 | 14703 | + di_read_lock_parent(parent, AuLock_IR); |
c2b27bf2 | 14704 | + hi_wh = au_hi_wh(inode, cpg.bdst); |
7f207e10 AM |
14705 | + if (!S_ISDIR(inode->i_mode) |
14706 | + && au_opt_test(au_mntflags(sb), PLINK) | |
4a4d8108 | 14707 | + && au_plink_test(inode) |
c2b27bf2 | 14708 | + && !d_unhashed(cpg.dentry) |
5afbbe0d | 14709 | + && cpg.bdst < au_dbtop(cpg.dentry)) { |
c2b27bf2 | 14710 | + err = au_test_and_cpup_dirs(cpg.dentry, cpg.bdst); |
4a4d8108 AM |
14711 | + if (unlikely(err)) |
14712 | + goto out_unlock; | |
14713 | + | |
14714 | + /* always superio. */ | |
c2b27bf2 | 14715 | + err = au_pin(&pin, cpg.dentry, cpg.bdst, AuOpt_UDBA_NONE, |
4a4d8108 | 14716 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); |
367653fa | 14717 | + if (!err) { |
c2b27bf2 | 14718 | + err = au_sio_cpup_simple(&cpg); |
367653fa AM |
14719 | + au_unpin(&pin); |
14720 | + } | |
4a4d8108 AM |
14721 | + } else if (hi_wh) { |
14722 | + /* already copied-up after unlink */ | |
c2b27bf2 | 14723 | + err = au_reopen_wh(file, cpg.bdst, hi_wh); |
4a4d8108 AM |
14724 | + *need_reopen = 0; |
14725 | + } | |
1facf9fc | 14726 | + |
4f0767ce | 14727 | +out_unlock: |
4a4d8108 | 14728 | + di_read_unlock(parent, AuLock_IR); |
4f0767ce | 14729 | +out_parent: |
4a4d8108 | 14730 | + dput(parent); |
4f0767ce | 14731 | +out: |
1308ab2a | 14732 | + return err; |
dece6358 | 14733 | +} |
1facf9fc | 14734 | + |
4a4d8108 | 14735 | +static void au_do_refresh_dir(struct file *file) |
dece6358 | 14736 | +{ |
5afbbe0d | 14737 | + aufs_bindex_t bindex, bbot, new_bindex, brid; |
4a4d8108 AM |
14738 | + struct au_hfile *p, tmp, *q; |
14739 | + struct au_finfo *finfo; | |
1308ab2a | 14740 | + struct super_block *sb; |
4a4d8108 | 14741 | + struct au_fidir *fidir; |
1facf9fc | 14742 | + |
4a4d8108 | 14743 | + FiMustWriteLock(file); |
1facf9fc | 14744 | + |
2000de60 | 14745 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 AM |
14746 | + finfo = au_fi(file); |
14747 | + fidir = finfo->fi_hdir; | |
14748 | + AuDebugOn(!fidir); | |
14749 | + p = fidir->fd_hfile + finfo->fi_btop; | |
14750 | + brid = p->hf_br->br_id; | |
5afbbe0d AM |
14751 | + bbot = fidir->fd_bbot; |
14752 | + for (bindex = finfo->fi_btop; bindex <= bbot; bindex++, p++) { | |
4a4d8108 AM |
14753 | + if (!p->hf_file) |
14754 | + continue; | |
1308ab2a | 14755 | + |
4a4d8108 AM |
14756 | + new_bindex = au_br_index(sb, p->hf_br->br_id); |
14757 | + if (new_bindex == bindex) | |
14758 | + continue; | |
14759 | + if (new_bindex < 0) { | |
14760 | + au_set_h_fptr(file, bindex, NULL); | |
14761 | + continue; | |
14762 | + } | |
1308ab2a | 14763 | + |
4a4d8108 AM |
14764 | + /* swap two lower inode, and loop again */ |
14765 | + q = fidir->fd_hfile + new_bindex; | |
14766 | + tmp = *q; | |
14767 | + *q = *p; | |
14768 | + *p = tmp; | |
14769 | + if (tmp.hf_file) { | |
14770 | + bindex--; | |
14771 | + p--; | |
14772 | + } | |
14773 | + } | |
1308ab2a | 14774 | + |
4a4d8108 | 14775 | + p = fidir->fd_hfile; |
2000de60 | 14776 | + if (!au_test_mmapped(file) && !d_unlinked(file->f_path.dentry)) { |
5afbbe0d AM |
14777 | + bbot = au_sbbot(sb); |
14778 | + for (finfo->fi_btop = 0; finfo->fi_btop <= bbot; | |
4a4d8108 AM |
14779 | + finfo->fi_btop++, p++) |
14780 | + if (p->hf_file) { | |
c06a8ce3 | 14781 | + if (file_inode(p->hf_file)) |
4a4d8108 | 14782 | + break; |
1c60b727 | 14783 | + au_hfput(p, /*execed*/0); |
4a4d8108 AM |
14784 | + } |
14785 | + } else { | |
5afbbe0d AM |
14786 | + bbot = au_br_index(sb, brid); |
14787 | + for (finfo->fi_btop = 0; finfo->fi_btop < bbot; | |
4a4d8108 AM |
14788 | + finfo->fi_btop++, p++) |
14789 | + if (p->hf_file) | |
1c60b727 | 14790 | + au_hfput(p, /*execed*/0); |
5afbbe0d | 14791 | + bbot = au_sbbot(sb); |
4a4d8108 | 14792 | + } |
1308ab2a | 14793 | + |
5afbbe0d AM |
14794 | + p = fidir->fd_hfile + bbot; |
14795 | + for (fidir->fd_bbot = bbot; fidir->fd_bbot >= finfo->fi_btop; | |
4a4d8108 AM |
14796 | + fidir->fd_bbot--, p--) |
14797 | + if (p->hf_file) { | |
c06a8ce3 | 14798 | + if (file_inode(p->hf_file)) |
4a4d8108 | 14799 | + break; |
1c60b727 | 14800 | + au_hfput(p, /*execed*/0); |
4a4d8108 AM |
14801 | + } |
14802 | + AuDebugOn(fidir->fd_bbot < finfo->fi_btop); | |
1308ab2a | 14803 | +} |
14804 | + | |
4a4d8108 AM |
14805 | +/* |
14806 | + * after branch manipulating, refresh the file. | |
14807 | + */ | |
14808 | +static int refresh_file(struct file *file, int (*reopen)(struct file *file)) | |
1facf9fc | 14809 | +{ |
e2f27e51 | 14810 | + int err, need_reopen, nbr; |
5afbbe0d | 14811 | + aufs_bindex_t bbot, bindex; |
4a4d8108 | 14812 | + struct dentry *dentry; |
e2f27e51 | 14813 | + struct super_block *sb; |
1308ab2a | 14814 | + struct au_finfo *finfo; |
4a4d8108 | 14815 | + struct au_hfile *hfile; |
1facf9fc | 14816 | + |
2000de60 | 14817 | + dentry = file->f_path.dentry; |
e2f27e51 AM |
14818 | + sb = dentry->d_sb; |
14819 | + nbr = au_sbbot(sb) + 1; | |
1308ab2a | 14820 | + finfo = au_fi(file); |
4a4d8108 AM |
14821 | + if (!finfo->fi_hdir) { |
14822 | + hfile = &finfo->fi_htop; | |
14823 | + AuDebugOn(!hfile->hf_file); | |
e2f27e51 | 14824 | + bindex = au_br_index(sb, hfile->hf_br->br_id); |
4a4d8108 AM |
14825 | + AuDebugOn(bindex < 0); |
14826 | + if (bindex != finfo->fi_btop) | |
5afbbe0d | 14827 | + au_set_fbtop(file, bindex); |
4a4d8108 | 14828 | + } else { |
e2f27e51 | 14829 | + err = au_fidir_realloc(finfo, nbr, /*may_shrink*/0); |
4a4d8108 AM |
14830 | + if (unlikely(err)) |
14831 | + goto out; | |
14832 | + au_do_refresh_dir(file); | |
14833 | + } | |
1facf9fc | 14834 | + |
4a4d8108 AM |
14835 | + err = 0; |
14836 | + need_reopen = 1; | |
14837 | + if (!au_test_mmapped(file)) | |
14838 | + err = au_file_refresh_by_inode(file, &need_reopen); | |
e2f27e51 AM |
14839 | + if (finfo->fi_hdir) |
14840 | + /* harmless if err */ | |
14841 | + au_fidir_realloc(finfo, nbr, /*may_shrink*/1); | |
027c5e7a | 14842 | + if (!err && need_reopen && !d_unlinked(dentry)) |
4a4d8108 AM |
14843 | + err = reopen(file); |
14844 | + if (!err) { | |
14845 | + au_update_figen(file); | |
14846 | + goto out; /* success */ | |
14847 | + } | |
14848 | + | |
14849 | + /* error, close all lower files */ | |
14850 | + if (finfo->fi_hdir) { | |
5afbbe0d AM |
14851 | + bbot = au_fbbot_dir(file); |
14852 | + for (bindex = au_fbtop(file); bindex <= bbot; bindex++) | |
4a4d8108 AM |
14853 | + au_set_h_fptr(file, bindex, NULL); |
14854 | + } | |
1facf9fc | 14855 | + |
4f0767ce | 14856 | +out: |
1facf9fc | 14857 | + return err; |
14858 | +} | |
14859 | + | |
4a4d8108 AM |
14860 | +/* common function to regular file and dir */ |
14861 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
521ced18 | 14862 | + int wlock, unsigned int fi_lsc) |
dece6358 | 14863 | +{ |
1308ab2a | 14864 | + int err; |
4a4d8108 | 14865 | + unsigned int sigen, figen; |
5afbbe0d | 14866 | + aufs_bindex_t btop; |
4a4d8108 AM |
14867 | + unsigned char pseudo_link; |
14868 | + struct dentry *dentry; | |
14869 | + struct inode *inode; | |
1facf9fc | 14870 | + |
4a4d8108 | 14871 | + err = 0; |
2000de60 | 14872 | + dentry = file->f_path.dentry; |
5527c038 | 14873 | + inode = d_inode(dentry); |
4a4d8108 | 14874 | + sigen = au_sigen(dentry->d_sb); |
521ced18 | 14875 | + fi_write_lock_nested(file, fi_lsc); |
4a4d8108 | 14876 | + figen = au_figen(file); |
521ced18 JR |
14877 | + if (!fi_lsc) |
14878 | + di_write_lock_child(dentry); | |
14879 | + else | |
14880 | + di_write_lock_child2(dentry); | |
5afbbe0d AM |
14881 | + btop = au_dbtop(dentry); |
14882 | + pseudo_link = (btop != au_ibtop(inode)); | |
14883 | + if (sigen == figen && !pseudo_link && au_fbtop(file) == btop) { | |
4a4d8108 AM |
14884 | + if (!wlock) { |
14885 | + di_downgrade_lock(dentry, AuLock_IR); | |
14886 | + fi_downgrade_lock(file); | |
14887 | + } | |
14888 | + goto out; /* success */ | |
14889 | + } | |
dece6358 | 14890 | + |
4a4d8108 | 14891 | + AuDbg("sigen %d, figen %d\n", sigen, figen); |
027c5e7a | 14892 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 | 14893 | + err = au_reval_dpath(dentry, sigen); |
027c5e7a | 14894 | + AuDebugOn(!err && au_digen_test(dentry, sigen)); |
4a4d8108 | 14895 | + } |
dece6358 | 14896 | + |
027c5e7a AM |
14897 | + if (!err) |
14898 | + err = refresh_file(file, reopen); | |
4a4d8108 AM |
14899 | + if (!err) { |
14900 | + if (!wlock) { | |
14901 | + di_downgrade_lock(dentry, AuLock_IR); | |
14902 | + fi_downgrade_lock(file); | |
14903 | + } | |
14904 | + } else { | |
14905 | + di_write_unlock(dentry); | |
14906 | + fi_write_unlock(file); | |
14907 | + } | |
1facf9fc | 14908 | + |
4f0767ce | 14909 | +out: |
1308ab2a | 14910 | + return err; |
14911 | +} | |
1facf9fc | 14912 | + |
4a4d8108 AM |
14913 | +/* ---------------------------------------------------------------------- */ |
14914 | + | |
14915 | +/* cf. aufs_nopage() */ | |
14916 | +/* for madvise(2) */ | |
14917 | +static int aufs_readpage(struct file *file __maybe_unused, struct page *page) | |
1308ab2a | 14918 | +{ |
4a4d8108 AM |
14919 | + unlock_page(page); |
14920 | + return 0; | |
14921 | +} | |
1facf9fc | 14922 | + |
4a4d8108 | 14923 | +/* it will never be called, but necessary to support O_DIRECT */ |
5afbbe0d | 14924 | +static ssize_t aufs_direct_IO(struct kiocb *iocb, struct iov_iter *iter) |
4a4d8108 | 14925 | +{ BUG(); return 0; } |
1facf9fc | 14926 | + |
4a4d8108 AM |
14927 | +/* they will never be called. */ |
14928 | +#ifdef CONFIG_AUFS_DEBUG | |
14929 | +static int aufs_write_begin(struct file *file, struct address_space *mapping, | |
14930 | + loff_t pos, unsigned len, unsigned flags, | |
14931 | + struct page **pagep, void **fsdata) | |
14932 | +{ AuUnsupport(); return 0; } | |
14933 | +static int aufs_write_end(struct file *file, struct address_space *mapping, | |
14934 | + loff_t pos, unsigned len, unsigned copied, | |
14935 | + struct page *page, void *fsdata) | |
14936 | +{ AuUnsupport(); return 0; } | |
14937 | +static int aufs_writepage(struct page *page, struct writeback_control *wbc) | |
14938 | +{ AuUnsupport(); return 0; } | |
1308ab2a | 14939 | + |
4a4d8108 AM |
14940 | +static int aufs_set_page_dirty(struct page *page) |
14941 | +{ AuUnsupport(); return 0; } | |
392086de AM |
14942 | +static void aufs_invalidatepage(struct page *page, unsigned int offset, |
14943 | + unsigned int length) | |
4a4d8108 AM |
14944 | +{ AuUnsupport(); } |
14945 | +static int aufs_releasepage(struct page *page, gfp_t gfp) | |
14946 | +{ AuUnsupport(); return 0; } | |
79b8bda9 | 14947 | +#if 0 /* called by memory compaction regardless file */ |
4a4d8108 | 14948 | +static int aufs_migratepage(struct address_space *mapping, struct page *newpage, |
7eafdf33 | 14949 | + struct page *page, enum migrate_mode mode) |
4a4d8108 | 14950 | +{ AuUnsupport(); return 0; } |
79b8bda9 | 14951 | +#endif |
e2f27e51 AM |
14952 | +static bool aufs_isolate_page(struct page *page, isolate_mode_t mode) |
14953 | +{ AuUnsupport(); return true; } | |
14954 | +static void aufs_putback_page(struct page *page) | |
14955 | +{ AuUnsupport(); } | |
4a4d8108 AM |
14956 | +static int aufs_launder_page(struct page *page) |
14957 | +{ AuUnsupport(); return 0; } | |
14958 | +static int aufs_is_partially_uptodate(struct page *page, | |
38d290e6 JR |
14959 | + unsigned long from, |
14960 | + unsigned long count) | |
4a4d8108 | 14961 | +{ AuUnsupport(); return 0; } |
392086de AM |
14962 | +static void aufs_is_dirty_writeback(struct page *page, bool *dirty, |
14963 | + bool *writeback) | |
14964 | +{ AuUnsupport(); } | |
4a4d8108 AM |
14965 | +static int aufs_error_remove_page(struct address_space *mapping, |
14966 | + struct page *page) | |
14967 | +{ AuUnsupport(); return 0; } | |
b4510431 AM |
14968 | +static int aufs_swap_activate(struct swap_info_struct *sis, struct file *file, |
14969 | + sector_t *span) | |
14970 | +{ AuUnsupport(); return 0; } | |
14971 | +static void aufs_swap_deactivate(struct file *file) | |
14972 | +{ AuUnsupport(); } | |
4a4d8108 AM |
14973 | +#endif /* CONFIG_AUFS_DEBUG */ |
14974 | + | |
14975 | +const struct address_space_operations aufs_aop = { | |
14976 | + .readpage = aufs_readpage, | |
14977 | + .direct_IO = aufs_direct_IO, | |
4a4d8108 AM |
14978 | +#ifdef CONFIG_AUFS_DEBUG |
14979 | + .writepage = aufs_writepage, | |
4a4d8108 AM |
14980 | + /* no writepages, because of writepage */ |
14981 | + .set_page_dirty = aufs_set_page_dirty, | |
14982 | + /* no readpages, because of readpage */ | |
14983 | + .write_begin = aufs_write_begin, | |
14984 | + .write_end = aufs_write_end, | |
14985 | + /* no bmap, no block device */ | |
14986 | + .invalidatepage = aufs_invalidatepage, | |
14987 | + .releasepage = aufs_releasepage, | |
79b8bda9 AM |
14988 | + /* is fallback_migrate_page ok? */ |
14989 | + /* .migratepage = aufs_migratepage, */ | |
e2f27e51 AM |
14990 | + .isolate_page = aufs_isolate_page, |
14991 | + .putback_page = aufs_putback_page, | |
4a4d8108 AM |
14992 | + .launder_page = aufs_launder_page, |
14993 | + .is_partially_uptodate = aufs_is_partially_uptodate, | |
392086de | 14994 | + .is_dirty_writeback = aufs_is_dirty_writeback, |
b4510431 AM |
14995 | + .error_remove_page = aufs_error_remove_page, |
14996 | + .swap_activate = aufs_swap_activate, | |
14997 | + .swap_deactivate = aufs_swap_deactivate | |
4a4d8108 | 14998 | +#endif /* CONFIG_AUFS_DEBUG */ |
dece6358 | 14999 | +}; |
7f207e10 | 15000 | diff -urN /usr/share/empty/fs/aufs/file.h linux/fs/aufs/file.h |
eca34b5c | 15001 | --- /usr/share/empty/fs/aufs/file.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 15002 | +++ linux/fs/aufs/file.h 2020-01-27 10:57:18.172204883 +0100 |
9f237c51 | 15003 | @@ -0,0 +1,342 @@ |
062440b3 | 15004 | +/* SPDX-License-Identifier: GPL-2.0 */ |
4a4d8108 | 15005 | +/* |
d58c55f2 | 15006 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
15007 | + * |
15008 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15009 | + * it under the terms of the GNU General Public License as published by | |
15010 | + * the Free Software Foundation; either version 2 of the License, or | |
15011 | + * (at your option) any later version. | |
15012 | + * | |
15013 | + * This program is distributed in the hope that it will be useful, | |
15014 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15015 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15016 | + * GNU General Public License for more details. | |
15017 | + * | |
15018 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15019 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 15020 | + */ |
1facf9fc | 15021 | + |
4a4d8108 AM |
15022 | +/* |
15023 | + * file operations | |
15024 | + */ | |
1facf9fc | 15025 | + |
4a4d8108 AM |
15026 | +#ifndef __AUFS_FILE_H__ |
15027 | +#define __AUFS_FILE_H__ | |
1facf9fc | 15028 | + |
4a4d8108 | 15029 | +#ifdef __KERNEL__ |
1facf9fc | 15030 | + |
2cbb1c4b | 15031 | +#include <linux/file.h> |
4a4d8108 | 15032 | +#include <linux/fs.h> |
3c1bdaff | 15033 | +#include <linux/mm_types.h> |
4a4d8108 | 15034 | +#include <linux/poll.h> |
4a4d8108 | 15035 | +#include "rwsem.h" |
1facf9fc | 15036 | + |
4a4d8108 AM |
15037 | +struct au_branch; |
15038 | +struct au_hfile { | |
15039 | + struct file *hf_file; | |
15040 | + struct au_branch *hf_br; | |
15041 | +}; | |
1facf9fc | 15042 | + |
4a4d8108 AM |
15043 | +struct au_vdir; |
15044 | +struct au_fidir { | |
15045 | + aufs_bindex_t fd_bbot; | |
15046 | + aufs_bindex_t fd_nent; | |
15047 | + struct au_vdir *fd_vdir_cache; | |
15048 | + struct au_hfile fd_hfile[]; | |
15049 | +}; | |
1facf9fc | 15050 | + |
4a4d8108 | 15051 | +static inline int au_fidir_sz(int nent) |
dece6358 | 15052 | +{ |
4f0767ce JR |
15053 | + AuDebugOn(nent < 0); |
15054 | + return sizeof(struct au_fidir) + sizeof(struct au_hfile) * nent; | |
4a4d8108 | 15055 | +} |
1facf9fc | 15056 | + |
4a4d8108 AM |
15057 | +struct au_finfo { |
15058 | + atomic_t fi_generation; | |
dece6358 | 15059 | + |
4a4d8108 AM |
15060 | + struct au_rwsem fi_rwsem; |
15061 | + aufs_bindex_t fi_btop; | |
15062 | + | |
15063 | + /* do not union them */ | |
15064 | + struct { /* for non-dir */ | |
15065 | + struct au_hfile fi_htop; | |
2cbb1c4b | 15066 | + atomic_t fi_mmapped; |
4a4d8108 AM |
15067 | + }; |
15068 | + struct au_fidir *fi_hdir; /* for dir only */ | |
523b37e3 | 15069 | + |
8b6a4947 | 15070 | + struct hlist_bl_node fi_hlist; |
1c60b727 | 15071 | + struct file *fi_file; /* very ugly */ |
9f237c51 | 15072 | + struct rcu_head rcu; |
4a4d8108 | 15073 | +} ____cacheline_aligned_in_smp; |
1facf9fc | 15074 | + |
4a4d8108 | 15075 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15076 | + |
4a4d8108 AM |
15077 | +/* file.c */ |
15078 | +extern const struct address_space_operations aufs_aop; | |
15079 | +unsigned int au_file_roflags(unsigned int flags); | |
15080 | +struct file *au_h_open(struct dentry *dentry, aufs_bindex_t bindex, int flags, | |
392086de | 15081 | + struct file *file, int force_wr); |
b912730e | 15082 | +struct au_do_open_args { |
8b6a4947 | 15083 | + int aopen; |
b912730e AM |
15084 | + int (*open)(struct file *file, int flags, |
15085 | + struct file *h_file); | |
15086 | + struct au_fidir *fidir; | |
15087 | + struct file *h_file; | |
15088 | +}; | |
15089 | +int au_do_open(struct file *file, struct au_do_open_args *args); | |
4a4d8108 AM |
15090 | +int au_reopen_nondir(struct file *file); |
15091 | +struct au_pin; | |
15092 | +int au_ready_to_write(struct file *file, loff_t len, struct au_pin *pin); | |
15093 | +int au_reval_and_lock_fdi(struct file *file, int (*reopen)(struct file *file), | |
521ced18 | 15094 | + int wlock, unsigned int fi_lsc); |
4a4d8108 AM |
15095 | +int au_do_flush(struct file *file, fl_owner_t id, |
15096 | + int (*flush)(struct file *file, fl_owner_t id)); | |
1facf9fc | 15097 | + |
4a4d8108 AM |
15098 | +/* poll.c */ |
15099 | +#ifdef CONFIG_AUFS_POLL | |
cd7a4cd9 | 15100 | +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt); |
4a4d8108 | 15101 | +#endif |
1facf9fc | 15102 | + |
4a4d8108 AM |
15103 | +#ifdef CONFIG_AUFS_BR_HFSPLUS |
15104 | +/* hfsplus.c */ | |
392086de AM |
15105 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
15106 | + int force_wr); | |
4a4d8108 AM |
15107 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
15108 | + struct file *h_file); | |
15109 | +#else | |
c1595e42 JR |
15110 | +AuStub(struct file *, au_h_open_pre, return NULL, struct dentry *dentry, |
15111 | + aufs_bindex_t bindex, int force_wr) | |
4a4d8108 AM |
15112 | +AuStubVoid(au_h_open_post, struct dentry *dentry, aufs_bindex_t bindex, |
15113 | + struct file *h_file); | |
15114 | +#endif | |
1facf9fc | 15115 | + |
4a4d8108 AM |
15116 | +/* f_op.c */ |
15117 | +extern const struct file_operations aufs_file_fop; | |
b912730e | 15118 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file); |
4a4d8108 | 15119 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file); |
521ced18 | 15120 | +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc); |
4a4d8108 | 15121 | + |
4a4d8108 | 15122 | +/* finfo.c */ |
f0c0a007 | 15123 | +void au_hfput(struct au_hfile *hf, int execed); |
4a4d8108 AM |
15124 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, |
15125 | + struct file *h_file); | |
1facf9fc | 15126 | + |
4a4d8108 | 15127 | +void au_update_figen(struct file *file); |
4a4d8108 | 15128 | +struct au_fidir *au_fidir_alloc(struct super_block *sb); |
e2f27e51 | 15129 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink); |
1facf9fc | 15130 | + |
4a4d8108 | 15131 | +void au_fi_init_once(void *_fi); |
1c60b727 | 15132 | +void au_finfo_fin(struct file *file); |
4a4d8108 | 15133 | +int au_finfo_init(struct file *file, struct au_fidir *fidir); |
1facf9fc | 15134 | + |
4a4d8108 AM |
15135 | +/* ioctl.c */ |
15136 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg); | |
b752ccd1 AM |
15137 | +#ifdef CONFIG_COMPAT |
15138 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
15139 | + unsigned long arg); | |
c2b27bf2 AM |
15140 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
15141 | + unsigned long arg); | |
b752ccd1 | 15142 | +#endif |
1facf9fc | 15143 | + |
4a4d8108 | 15144 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15145 | + |
4a4d8108 AM |
15146 | +static inline struct au_finfo *au_fi(struct file *file) |
15147 | +{ | |
38d290e6 | 15148 | + return file->private_data; |
4a4d8108 | 15149 | +} |
1facf9fc | 15150 | + |
4a4d8108 | 15151 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 15152 | + |
8b6a4947 AM |
15153 | +#define fi_read_lock(f) au_rw_read_lock(&au_fi(f)->fi_rwsem) |
15154 | +#define fi_write_lock(f) au_rw_write_lock(&au_fi(f)->fi_rwsem) | |
15155 | +#define fi_read_trylock(f) au_rw_read_trylock(&au_fi(f)->fi_rwsem) | |
15156 | +#define fi_write_trylock(f) au_rw_write_trylock(&au_fi(f)->fi_rwsem) | |
4a4d8108 | 15157 | +/* |
8b6a4947 AM |
15158 | +#define fi_read_trylock_nested(f) \ |
15159 | + au_rw_read_trylock_nested(&au_fi(f)->fi_rwsem) | |
15160 | +#define fi_write_trylock_nested(f) \ | |
15161 | + au_rw_write_trylock_nested(&au_fi(f)->fi_rwsem) | |
15162 | +*/ | |
15163 | + | |
15164 | +#define fi_read_unlock(f) au_rw_read_unlock(&au_fi(f)->fi_rwsem) | |
15165 | +#define fi_write_unlock(f) au_rw_write_unlock(&au_fi(f)->fi_rwsem) | |
15166 | +#define fi_downgrade_lock(f) au_rw_dgrade_lock(&au_fi(f)->fi_rwsem) | |
1308ab2a | 15167 | + |
521ced18 JR |
15168 | +/* lock subclass for finfo */ |
15169 | +enum { | |
15170 | + AuLsc_FI_1, | |
15171 | + AuLsc_FI_2 | |
15172 | +}; | |
15173 | + | |
15174 | +static inline void fi_read_lock_nested(struct file *f, unsigned int lsc) | |
15175 | +{ | |
15176 | + au_rw_read_lock_nested(&au_fi(f)->fi_rwsem, lsc); | |
15177 | +} | |
15178 | + | |
15179 | +static inline void fi_write_lock_nested(struct file *f, unsigned int lsc) | |
15180 | +{ | |
15181 | + au_rw_write_lock_nested(&au_fi(f)->fi_rwsem, lsc); | |
15182 | +} | |
15183 | + | |
15184 | +/* | |
15185 | + * fi_read_lock_1, fi_write_lock_1, | |
15186 | + * fi_read_lock_2, fi_write_lock_2 | |
15187 | + */ | |
15188 | +#define AuReadLockFunc(name) \ | |
15189 | +static inline void fi_read_lock_##name(struct file *f) \ | |
15190 | +{ fi_read_lock_nested(f, AuLsc_FI_##name); } | |
15191 | + | |
15192 | +#define AuWriteLockFunc(name) \ | |
15193 | +static inline void fi_write_lock_##name(struct file *f) \ | |
15194 | +{ fi_write_lock_nested(f, AuLsc_FI_##name); } | |
15195 | + | |
15196 | +#define AuRWLockFuncs(name) \ | |
15197 | + AuReadLockFunc(name) \ | |
15198 | + AuWriteLockFunc(name) | |
15199 | + | |
15200 | +AuRWLockFuncs(1); | |
15201 | +AuRWLockFuncs(2); | |
15202 | + | |
15203 | +#undef AuReadLockFunc | |
15204 | +#undef AuWriteLockFunc | |
15205 | +#undef AuRWLockFuncs | |
15206 | + | |
4a4d8108 AM |
15207 | +#define FiMustNoWaiters(f) AuRwMustNoWaiters(&au_fi(f)->fi_rwsem) |
15208 | +#define FiMustAnyLock(f) AuRwMustAnyLock(&au_fi(f)->fi_rwsem) | |
15209 | +#define FiMustWriteLock(f) AuRwMustWriteLock(&au_fi(f)->fi_rwsem) | |
1facf9fc | 15210 | + |
1308ab2a | 15211 | +/* ---------------------------------------------------------------------- */ |
15212 | + | |
4a4d8108 | 15213 | +/* todo: hard/soft set? */ |
5afbbe0d | 15214 | +static inline aufs_bindex_t au_fbtop(struct file *file) |
dece6358 | 15215 | +{ |
4a4d8108 AM |
15216 | + FiMustAnyLock(file); |
15217 | + return au_fi(file)->fi_btop; | |
15218 | +} | |
dece6358 | 15219 | + |
5afbbe0d | 15220 | +static inline aufs_bindex_t au_fbbot_dir(struct file *file) |
4a4d8108 AM |
15221 | +{ |
15222 | + FiMustAnyLock(file); | |
15223 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15224 | + return au_fi(file)->fi_hdir->fd_bbot; | |
15225 | +} | |
1facf9fc | 15226 | + |
4a4d8108 AM |
15227 | +static inline struct au_vdir *au_fvdir_cache(struct file *file) |
15228 | +{ | |
15229 | + FiMustAnyLock(file); | |
15230 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15231 | + return au_fi(file)->fi_hdir->fd_vdir_cache; | |
15232 | +} | |
1facf9fc | 15233 | + |
5afbbe0d | 15234 | +static inline void au_set_fbtop(struct file *file, aufs_bindex_t bindex) |
4a4d8108 AM |
15235 | +{ |
15236 | + FiMustWriteLock(file); | |
15237 | + au_fi(file)->fi_btop = bindex; | |
15238 | +} | |
1facf9fc | 15239 | + |
5afbbe0d | 15240 | +static inline void au_set_fbbot_dir(struct file *file, aufs_bindex_t bindex) |
4a4d8108 AM |
15241 | +{ |
15242 | + FiMustWriteLock(file); | |
15243 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15244 | + au_fi(file)->fi_hdir->fd_bbot = bindex; | |
15245 | +} | |
1308ab2a | 15246 | + |
4a4d8108 AM |
15247 | +static inline void au_set_fvdir_cache(struct file *file, |
15248 | + struct au_vdir *vdir_cache) | |
15249 | +{ | |
15250 | + FiMustWriteLock(file); | |
15251 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15252 | + au_fi(file)->fi_hdir->fd_vdir_cache = vdir_cache; | |
15253 | +} | |
dece6358 | 15254 | + |
4a4d8108 AM |
15255 | +static inline struct file *au_hf_top(struct file *file) |
15256 | +{ | |
15257 | + FiMustAnyLock(file); | |
15258 | + AuDebugOn(au_fi(file)->fi_hdir); | |
15259 | + return au_fi(file)->fi_htop.hf_file; | |
15260 | +} | |
1facf9fc | 15261 | + |
4a4d8108 AM |
15262 | +static inline struct file *au_hf_dir(struct file *file, aufs_bindex_t bindex) |
15263 | +{ | |
15264 | + FiMustAnyLock(file); | |
15265 | + AuDebugOn(!au_fi(file)->fi_hdir); | |
15266 | + return au_fi(file)->fi_hdir->fd_hfile[0 + bindex].hf_file; | |
dece6358 AM |
15267 | +} |
15268 | + | |
4a4d8108 AM |
15269 | +/* todo: memory barrier? */ |
15270 | +static inline unsigned int au_figen(struct file *f) | |
dece6358 | 15271 | +{ |
4a4d8108 AM |
15272 | + return atomic_read(&au_fi(f)->fi_generation); |
15273 | +} | |
dece6358 | 15274 | + |
2cbb1c4b JR |
15275 | +static inline void au_set_mmapped(struct file *f) |
15276 | +{ | |
15277 | + if (atomic_inc_return(&au_fi(f)->fi_mmapped)) | |
15278 | + return; | |
0c3ec466 | 15279 | + pr_warn("fi_mmapped wrapped around\n"); |
2cbb1c4b JR |
15280 | + while (!atomic_inc_return(&au_fi(f)->fi_mmapped)) |
15281 | + ; | |
15282 | +} | |
15283 | + | |
15284 | +static inline void au_unset_mmapped(struct file *f) | |
15285 | +{ | |
15286 | + atomic_dec(&au_fi(f)->fi_mmapped); | |
15287 | +} | |
15288 | + | |
4a4d8108 AM |
15289 | +static inline int au_test_mmapped(struct file *f) |
15290 | +{ | |
2cbb1c4b JR |
15291 | + return atomic_read(&au_fi(f)->fi_mmapped); |
15292 | +} | |
15293 | + | |
15294 | +/* customize vma->vm_file */ | |
15295 | + | |
15296 | +static inline void au_do_vm_file_reset(struct vm_area_struct *vma, | |
15297 | + struct file *file) | |
15298 | +{ | |
53392da6 AM |
15299 | + struct file *f; |
15300 | + | |
15301 | + f = vma->vm_file; | |
2cbb1c4b JR |
15302 | + get_file(file); |
15303 | + vma->vm_file = file; | |
53392da6 | 15304 | + fput(f); |
2cbb1c4b JR |
15305 | +} |
15306 | + | |
15307 | +#ifdef CONFIG_MMU | |
15308 | +#define AuDbgVmRegion(file, vma) do {} while (0) | |
15309 | + | |
15310 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
15311 | + struct file *file) | |
15312 | +{ | |
15313 | + au_do_vm_file_reset(vma, file); | |
15314 | +} | |
15315 | +#else | |
15316 | +#define AuDbgVmRegion(file, vma) \ | |
15317 | + AuDebugOn((vma)->vm_region && (vma)->vm_region->vm_file != (file)) | |
15318 | + | |
15319 | +static inline void au_vm_file_reset(struct vm_area_struct *vma, | |
15320 | + struct file *file) | |
15321 | +{ | |
53392da6 AM |
15322 | + struct file *f; |
15323 | + | |
2cbb1c4b | 15324 | + au_do_vm_file_reset(vma, file); |
53392da6 | 15325 | + f = vma->vm_region->vm_file; |
2cbb1c4b JR |
15326 | + get_file(file); |
15327 | + vma->vm_region->vm_file = file; | |
53392da6 | 15328 | + fput(f); |
2cbb1c4b JR |
15329 | +} |
15330 | +#endif /* CONFIG_MMU */ | |
15331 | + | |
15332 | +/* handle vma->vm_prfile */ | |
fb47a38f | 15333 | +static inline void au_vm_prfile_set(struct vm_area_struct *vma, |
2cbb1c4b JR |
15334 | + struct file *file) |
15335 | +{ | |
2cbb1c4b JR |
15336 | + get_file(file); |
15337 | + vma->vm_prfile = file; | |
15338 | +#ifndef CONFIG_MMU | |
15339 | + get_file(file); | |
15340 | + vma->vm_region->vm_prfile = file; | |
15341 | +#endif | |
fb47a38f | 15342 | +} |
1308ab2a | 15343 | + |
4a4d8108 AM |
15344 | +#endif /* __KERNEL__ */ |
15345 | +#endif /* __AUFS_FILE_H__ */ | |
7f207e10 | 15346 | diff -urN /usr/share/empty/fs/aufs/finfo.c linux/fs/aufs/finfo.c |
eca34b5c | 15347 | --- /usr/share/empty/fs/aufs/finfo.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 15348 | +++ linux/fs/aufs/finfo.c 2020-01-27 10:57:18.172204883 +0100 |
062440b3 | 15349 | @@ -0,0 +1,149 @@ |
cd7a4cd9 | 15350 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 15351 | +/* |
d58c55f2 | 15352 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
15353 | + * |
15354 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15355 | + * it under the terms of the GNU General Public License as published by | |
15356 | + * the Free Software Foundation; either version 2 of the License, or | |
15357 | + * (at your option) any later version. | |
15358 | + * | |
15359 | + * This program is distributed in the hope that it will be useful, | |
15360 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15361 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15362 | + * GNU General Public License for more details. | |
15363 | + * | |
15364 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15365 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 15366 | + */ |
1308ab2a | 15367 | + |
4a4d8108 AM |
15368 | +/* |
15369 | + * file private data | |
15370 | + */ | |
1facf9fc | 15371 | + |
4a4d8108 | 15372 | +#include "aufs.h" |
1facf9fc | 15373 | + |
f0c0a007 | 15374 | +void au_hfput(struct au_hfile *hf, int execed) |
4a4d8108 | 15375 | +{ |
f0c0a007 | 15376 | + if (execed) |
4a4d8108 AM |
15377 | + allow_write_access(hf->hf_file); |
15378 | + fput(hf->hf_file); | |
15379 | + hf->hf_file = NULL; | |
acd2b654 | 15380 | + au_lcnt_dec(&hf->hf_br->br_nfiles); |
4a4d8108 AM |
15381 | + hf->hf_br = NULL; |
15382 | +} | |
1facf9fc | 15383 | + |
4a4d8108 AM |
15384 | +void au_set_h_fptr(struct file *file, aufs_bindex_t bindex, struct file *val) |
15385 | +{ | |
15386 | + struct au_finfo *finfo = au_fi(file); | |
15387 | + struct au_hfile *hf; | |
15388 | + struct au_fidir *fidir; | |
15389 | + | |
15390 | + fidir = finfo->fi_hdir; | |
15391 | + if (!fidir) { | |
15392 | + AuDebugOn(finfo->fi_btop != bindex); | |
15393 | + hf = &finfo->fi_htop; | |
15394 | + } else | |
15395 | + hf = fidir->fd_hfile + bindex; | |
15396 | + | |
15397 | + if (hf && hf->hf_file) | |
f0c0a007 | 15398 | + au_hfput(hf, vfsub_file_execed(file)); |
4a4d8108 AM |
15399 | + if (val) { |
15400 | + FiMustWriteLock(file); | |
b912730e | 15401 | + AuDebugOn(IS_ERR_OR_NULL(file->f_path.dentry)); |
4a4d8108 | 15402 | + hf->hf_file = val; |
2000de60 | 15403 | + hf->hf_br = au_sbr(file->f_path.dentry->d_sb, bindex); |
1308ab2a | 15404 | + } |
4a4d8108 | 15405 | +} |
1facf9fc | 15406 | + |
4a4d8108 AM |
15407 | +void au_update_figen(struct file *file) |
15408 | +{ | |
2000de60 | 15409 | + atomic_set(&au_fi(file)->fi_generation, au_digen(file->f_path.dentry)); |
4a4d8108 | 15410 | + /* smp_mb(); */ /* atomic_set */ |
1facf9fc | 15411 | +} |
15412 | + | |
4a4d8108 AM |
15413 | +/* ---------------------------------------------------------------------- */ |
15414 | + | |
4a4d8108 AM |
15415 | +struct au_fidir *au_fidir_alloc(struct super_block *sb) |
15416 | +{ | |
15417 | + struct au_fidir *fidir; | |
15418 | + int nbr; | |
15419 | + | |
5afbbe0d | 15420 | + nbr = au_sbbot(sb) + 1; |
4a4d8108 AM |
15421 | + if (nbr < 2) |
15422 | + nbr = 2; /* initial allocate for 2 branches */ | |
15423 | + fidir = kzalloc(au_fidir_sz(nbr), GFP_NOFS); | |
15424 | + if (fidir) { | |
15425 | + fidir->fd_bbot = -1; | |
15426 | + fidir->fd_nent = nbr; | |
4a4d8108 AM |
15427 | + } |
15428 | + | |
15429 | + return fidir; | |
15430 | +} | |
15431 | + | |
e2f27e51 | 15432 | +int au_fidir_realloc(struct au_finfo *finfo, int nbr, int may_shrink) |
4a4d8108 AM |
15433 | +{ |
15434 | + int err; | |
15435 | + struct au_fidir *fidir, *p; | |
15436 | + | |
15437 | + AuRwMustWriteLock(&finfo->fi_rwsem); | |
15438 | + fidir = finfo->fi_hdir; | |
15439 | + AuDebugOn(!fidir); | |
15440 | + | |
15441 | + err = -ENOMEM; | |
15442 | + p = au_kzrealloc(fidir, au_fidir_sz(fidir->fd_nent), au_fidir_sz(nbr), | |
e2f27e51 | 15443 | + GFP_NOFS, may_shrink); |
4a4d8108 AM |
15444 | + if (p) { |
15445 | + p->fd_nent = nbr; | |
15446 | + finfo->fi_hdir = p; | |
15447 | + err = 0; | |
15448 | + } | |
1facf9fc | 15449 | + |
dece6358 | 15450 | + return err; |
1facf9fc | 15451 | +} |
1308ab2a | 15452 | + |
15453 | +/* ---------------------------------------------------------------------- */ | |
15454 | + | |
1c60b727 | 15455 | +void au_finfo_fin(struct file *file) |
1308ab2a | 15456 | +{ |
4a4d8108 AM |
15457 | + struct au_finfo *finfo; |
15458 | + | |
acd2b654 | 15459 | + au_lcnt_dec(&au_sbi(file->f_path.dentry->d_sb)->si_nfiles); |
7f207e10 | 15460 | + |
4a4d8108 AM |
15461 | + finfo = au_fi(file); |
15462 | + AuDebugOn(finfo->fi_hdir); | |
15463 | + AuRwDestroy(&finfo->fi_rwsem); | |
1c60b727 | 15464 | + au_cache_free_finfo(finfo); |
1308ab2a | 15465 | +} |
1308ab2a | 15466 | + |
e49829fe | 15467 | +void au_fi_init_once(void *_finfo) |
4a4d8108 | 15468 | +{ |
e49829fe | 15469 | + struct au_finfo *finfo = _finfo; |
1308ab2a | 15470 | + |
e49829fe | 15471 | + au_rw_init(&finfo->fi_rwsem); |
4a4d8108 | 15472 | +} |
1308ab2a | 15473 | + |
4a4d8108 AM |
15474 | +int au_finfo_init(struct file *file, struct au_fidir *fidir) |
15475 | +{ | |
1716fcea | 15476 | + int err; |
4a4d8108 AM |
15477 | + struct au_finfo *finfo; |
15478 | + struct dentry *dentry; | |
15479 | + | |
15480 | + err = -ENOMEM; | |
2000de60 | 15481 | + dentry = file->f_path.dentry; |
4a4d8108 AM |
15482 | + finfo = au_cache_alloc_finfo(); |
15483 | + if (unlikely(!finfo)) | |
15484 | + goto out; | |
15485 | + | |
15486 | + err = 0; | |
acd2b654 | 15487 | + au_lcnt_inc(&au_sbi(dentry->d_sb)->si_nfiles); |
4a4d8108 AM |
15488 | + au_rw_write_lock(&finfo->fi_rwsem); |
15489 | + finfo->fi_btop = -1; | |
15490 | + finfo->fi_hdir = fidir; | |
15491 | + atomic_set(&finfo->fi_generation, au_digen(dentry)); | |
15492 | + /* smp_mb(); */ /* atomic_set */ | |
15493 | + | |
15494 | + file->private_data = finfo; | |
15495 | + | |
15496 | +out: | |
15497 | + return err; | |
15498 | +} | |
7f207e10 | 15499 | diff -urN /usr/share/empty/fs/aufs/f_op.c linux/fs/aufs/f_op.c |
eca34b5c | 15500 | --- /usr/share/empty/fs/aufs/f_op.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 15501 | +++ linux/fs/aufs/f_op.c 2020-01-27 10:57:18.172204883 +0100 |
acd2b654 | 15502 | @@ -0,0 +1,819 @@ |
cd7a4cd9 | 15503 | +// SPDX-License-Identifier: GPL-2.0 |
dece6358 | 15504 | +/* |
d58c55f2 | 15505 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
dece6358 AM |
15506 | + * |
15507 | + * This program, aufs is free software; you can redistribute it and/or modify | |
15508 | + * it under the terms of the GNU General Public License as published by | |
15509 | + * the Free Software Foundation; either version 2 of the License, or | |
15510 | + * (at your option) any later version. | |
15511 | + * | |
15512 | + * This program is distributed in the hope that it will be useful, | |
15513 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15514 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15515 | + * GNU General Public License for more details. | |
15516 | + * | |
15517 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 15518 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 15519 | + */ |
1facf9fc | 15520 | + |
15521 | +/* | |
4a4d8108 | 15522 | + * file and vm operations |
1facf9fc | 15523 | + */ |
dece6358 | 15524 | + |
86dc4139 | 15525 | +#include <linux/aio.h> |
4a4d8108 AM |
15526 | +#include <linux/fs_stack.h> |
15527 | +#include <linux/mman.h> | |
4a4d8108 | 15528 | +#include <linux/security.h> |
dece6358 AM |
15529 | +#include "aufs.h" |
15530 | + | |
b912730e | 15531 | +int au_do_open_nondir(struct file *file, int flags, struct file *h_file) |
1facf9fc | 15532 | +{ |
4a4d8108 AM |
15533 | + int err; |
15534 | + aufs_bindex_t bindex; | |
8cdd5066 | 15535 | + struct dentry *dentry, *h_dentry; |
4a4d8108 | 15536 | + struct au_finfo *finfo; |
38d290e6 | 15537 | + struct inode *h_inode; |
4a4d8108 AM |
15538 | + |
15539 | + FiMustWriteLock(file); | |
15540 | + | |
523b37e3 | 15541 | + err = 0; |
2000de60 | 15542 | + dentry = file->f_path.dentry; |
b912730e | 15543 | + AuDebugOn(IS_ERR_OR_NULL(dentry)); |
4a4d8108 AM |
15544 | + finfo = au_fi(file); |
15545 | + memset(&finfo->fi_htop, 0, sizeof(finfo->fi_htop)); | |
2cbb1c4b | 15546 | + atomic_set(&finfo->fi_mmapped, 0); |
5afbbe0d | 15547 | + bindex = au_dbtop(dentry); |
8cdd5066 JR |
15548 | + if (!h_file) { |
15549 | + h_dentry = au_h_dptr(dentry, bindex); | |
15550 | + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb); | |
15551 | + if (unlikely(err)) | |
15552 | + goto out; | |
b912730e | 15553 | + h_file = au_h_open(dentry, bindex, flags, file, /*force_wr*/0); |
acd2b654 AM |
15554 | + if (IS_ERR(h_file)) { |
15555 | + err = PTR_ERR(h_file); | |
15556 | + goto out; | |
15557 | + } | |
8cdd5066 JR |
15558 | + } else { |
15559 | + h_dentry = h_file->f_path.dentry; | |
15560 | + err = vfsub_test_mntns(file->f_path.mnt, h_dentry->d_sb); | |
15561 | + if (unlikely(err)) | |
15562 | + goto out; | |
acd2b654 | 15563 | + /* br ref is already inc-ed */ |
8cdd5066 | 15564 | + } |
acd2b654 AM |
15565 | + |
15566 | + if ((flags & __O_TMPFILE) | |
15567 | + && !(flags & O_EXCL)) { | |
15568 | + h_inode = file_inode(h_file); | |
15569 | + spin_lock(&h_inode->i_lock); | |
15570 | + h_inode->i_state |= I_LINKABLE; | |
15571 | + spin_unlock(&h_inode->i_lock); | |
4a4d8108 | 15572 | + } |
acd2b654 AM |
15573 | + au_set_fbtop(file, bindex); |
15574 | + au_set_h_fptr(file, bindex, h_file); | |
15575 | + au_update_figen(file); | |
15576 | + /* todo: necessary? */ | |
15577 | + /* file->f_ra = h_file->f_ra; */ | |
027c5e7a | 15578 | + |
8cdd5066 | 15579 | +out: |
4a4d8108 | 15580 | + return err; |
1facf9fc | 15581 | +} |
15582 | + | |
4a4d8108 AM |
15583 | +static int aufs_open_nondir(struct inode *inode __maybe_unused, |
15584 | + struct file *file) | |
1facf9fc | 15585 | +{ |
4a4d8108 | 15586 | + int err; |
1308ab2a | 15587 | + struct super_block *sb; |
b912730e AM |
15588 | + struct au_do_open_args args = { |
15589 | + .open = au_do_open_nondir | |
15590 | + }; | |
1facf9fc | 15591 | + |
523b37e3 AM |
15592 | + AuDbg("%pD, f_flags 0x%x, f_mode 0x%x\n", |
15593 | + file, vfsub_file_flags(file), file->f_mode); | |
1facf9fc | 15594 | + |
2000de60 | 15595 | + sb = file->f_path.dentry->d_sb; |
4a4d8108 | 15596 | + si_read_lock(sb, AuLock_FLUSH); |
b912730e | 15597 | + err = au_do_open(file, &args); |
4a4d8108 AM |
15598 | + si_read_unlock(sb); |
15599 | + return err; | |
15600 | +} | |
1facf9fc | 15601 | + |
4a4d8108 AM |
15602 | +int aufs_release_nondir(struct inode *inode __maybe_unused, struct file *file) |
15603 | +{ | |
15604 | + struct au_finfo *finfo; | |
15605 | + aufs_bindex_t bindex; | |
1facf9fc | 15606 | + |
4a4d8108 | 15607 | + finfo = au_fi(file); |
8b6a4947 AM |
15608 | + au_hbl_del(&finfo->fi_hlist, |
15609 | + &au_sbi(file->f_path.dentry->d_sb)->si_files); | |
4a4d8108 | 15610 | + bindex = finfo->fi_btop; |
b4510431 | 15611 | + if (bindex >= 0) |
4a4d8108 | 15612 | + au_set_h_fptr(file, bindex, NULL); |
7f207e10 | 15613 | + |
1c60b727 | 15614 | + au_finfo_fin(file); |
4a4d8108 | 15615 | + return 0; |
1facf9fc | 15616 | +} |
15617 | + | |
4a4d8108 AM |
15618 | +/* ---------------------------------------------------------------------- */ |
15619 | + | |
15620 | +static int au_do_flush_nondir(struct file *file, fl_owner_t id) | |
dece6358 | 15621 | +{ |
1308ab2a | 15622 | + int err; |
4a4d8108 AM |
15623 | + struct file *h_file; |
15624 | + | |
15625 | + err = 0; | |
15626 | + h_file = au_hf_top(file); | |
15627 | + if (h_file) | |
15628 | + err = vfsub_flush(h_file, id); | |
15629 | + return err; | |
15630 | +} | |
15631 | + | |
15632 | +static int aufs_flush_nondir(struct file *file, fl_owner_t id) | |
15633 | +{ | |
15634 | + return au_do_flush(file, id, au_do_flush_nondir); | |
15635 | +} | |
15636 | + | |
15637 | +/* ---------------------------------------------------------------------- */ | |
9dbd164d AM |
15638 | +/* |
15639 | + * read and write functions acquire [fdi]_rwsem once, but release before | |
15640 | + * mmap_sem. This is because to stop a race condition between mmap(2). | |
acd2b654 | 15641 | + * Releasing these aufs-rwsem should be safe, no branch-management (by keeping |
9dbd164d AM |
15642 | + * si_rwsem), no harmful copy-up should happen. Actually copy-up may happen in |
15643 | + * read functions after [fdi]_rwsem are released, but it should be harmless. | |
15644 | + */ | |
4a4d8108 | 15645 | + |
b912730e | 15646 | +/* Callers should call au_read_post() or fput() in the end */ |
521ced18 | 15647 | +struct file *au_read_pre(struct file *file, int keep_fi, unsigned int lsc) |
4a4d8108 | 15648 | +{ |
4a4d8108 | 15649 | + struct file *h_file; |
b912730e | 15650 | + int err; |
1facf9fc | 15651 | + |
521ced18 | 15652 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/0, lsc); |
b912730e AM |
15653 | + if (!err) { |
15654 | + di_read_unlock(file->f_path.dentry, AuLock_IR); | |
15655 | + h_file = au_hf_top(file); | |
15656 | + get_file(h_file); | |
15657 | + if (!keep_fi) | |
15658 | + fi_read_unlock(file); | |
15659 | + } else | |
15660 | + h_file = ERR_PTR(err); | |
15661 | + | |
15662 | + return h_file; | |
15663 | +} | |
15664 | + | |
15665 | +static void au_read_post(struct inode *inode, struct file *h_file) | |
15666 | +{ | |
15667 | + /* update without lock, I don't think it a problem */ | |
15668 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
15669 | + fput(h_file); | |
15670 | +} | |
15671 | + | |
15672 | +struct au_write_pre { | |
521ced18 JR |
15673 | + /* input */ |
15674 | + unsigned int lsc; | |
15675 | + | |
15676 | + /* output */ | |
b912730e | 15677 | + blkcnt_t blks; |
5afbbe0d | 15678 | + aufs_bindex_t btop; |
b912730e AM |
15679 | +}; |
15680 | + | |
15681 | +/* | |
15682 | + * return with iinfo is write-locked | |
15683 | + * callers should call au_write_post() or iinfo_write_unlock() + fput() in the | |
15684 | + * end | |
15685 | + */ | |
15686 | +static struct file *au_write_pre(struct file *file, int do_ready, | |
15687 | + struct au_write_pre *wpre) | |
15688 | +{ | |
15689 | + struct file *h_file; | |
15690 | + struct dentry *dentry; | |
15691 | + int err; | |
521ced18 | 15692 | + unsigned int lsc; |
b912730e AM |
15693 | + struct au_pin pin; |
15694 | + | |
521ced18 JR |
15695 | + lsc = 0; |
15696 | + if (wpre) | |
15697 | + lsc = wpre->lsc; | |
15698 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, lsc); | |
b912730e | 15699 | + h_file = ERR_PTR(err); |
dece6358 AM |
15700 | + if (unlikely(err)) |
15701 | + goto out; | |
1facf9fc | 15702 | + |
b912730e AM |
15703 | + dentry = file->f_path.dentry; |
15704 | + if (do_ready) { | |
15705 | + err = au_ready_to_write(file, -1, &pin); | |
15706 | + if (unlikely(err)) { | |
15707 | + h_file = ERR_PTR(err); | |
15708 | + di_write_unlock(dentry); | |
15709 | + goto out_fi; | |
15710 | + } | |
15711 | + } | |
15712 | + | |
15713 | + di_downgrade_lock(dentry, /*flags*/0); | |
15714 | + if (wpre) | |
5afbbe0d | 15715 | + wpre->btop = au_fbtop(file); |
4a4d8108 | 15716 | + h_file = au_hf_top(file); |
9dbd164d | 15717 | + get_file(h_file); |
b912730e AM |
15718 | + if (wpre) |
15719 | + wpre->blks = file_inode(h_file)->i_blocks; | |
15720 | + if (do_ready) | |
15721 | + au_unpin(&pin); | |
15722 | + di_read_unlock(dentry, /*flags*/0); | |
15723 | + | |
15724 | +out_fi: | |
15725 | + fi_write_unlock(file); | |
15726 | +out: | |
15727 | + return h_file; | |
15728 | +} | |
15729 | + | |
15730 | +static void au_write_post(struct inode *inode, struct file *h_file, | |
15731 | + struct au_write_pre *wpre, ssize_t written) | |
15732 | +{ | |
15733 | + struct inode *h_inode; | |
15734 | + | |
15735 | + au_cpup_attr_timesizes(inode); | |
5afbbe0d | 15736 | + AuDebugOn(au_ibtop(inode) != wpre->btop); |
b912730e AM |
15737 | + h_inode = file_inode(h_file); |
15738 | + inode->i_mode = h_inode->i_mode; | |
15739 | + ii_write_unlock(inode); | |
b912730e AM |
15740 | + /* AuDbg("blks %llu, %llu\n", (u64)blks, (u64)h_inode->i_blocks); */ |
15741 | + if (written > 0) | |
5afbbe0d | 15742 | + au_fhsm_wrote(inode->i_sb, wpre->btop, |
b912730e | 15743 | + /*force*/h_inode->i_blocks > wpre->blks); |
1c60b727 | 15744 | + fput(h_file); |
b912730e AM |
15745 | +} |
15746 | + | |
15747 | +static ssize_t aufs_read(struct file *file, char __user *buf, size_t count, | |
15748 | + loff_t *ppos) | |
15749 | +{ | |
15750 | + ssize_t err; | |
15751 | + struct inode *inode; | |
15752 | + struct file *h_file; | |
15753 | + struct super_block *sb; | |
15754 | + | |
15755 | + inode = file_inode(file); | |
15756 | + sb = inode->i_sb; | |
15757 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
15758 | + | |
521ced18 | 15759 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
15760 | + err = PTR_ERR(h_file); |
15761 | + if (IS_ERR(h_file)) | |
15762 | + goto out; | |
9dbd164d AM |
15763 | + |
15764 | + /* filedata may be obsoleted by concurrent copyup, but no problem */ | |
4a4d8108 AM |
15765 | + err = vfsub_read_u(h_file, buf, count, ppos); |
15766 | + /* todo: necessary? */ | |
15767 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 15768 | + au_read_post(inode, h_file); |
1308ab2a | 15769 | + |
4f0767ce | 15770 | +out: |
dece6358 AM |
15771 | + si_read_unlock(sb); |
15772 | + return err; | |
15773 | +} | |
1facf9fc | 15774 | + |
e49829fe JR |
15775 | +/* |
15776 | + * todo: very ugly | |
15777 | + * it locks both of i_mutex and si_rwsem for read in safe. | |
15778 | + * if the plink maintenance mode continues forever (that is the problem), | |
15779 | + * may loop forever. | |
15780 | + */ | |
15781 | +static void au_mtx_and_read_lock(struct inode *inode) | |
15782 | +{ | |
15783 | + int err; | |
15784 | + struct super_block *sb = inode->i_sb; | |
15785 | + | |
15786 | + while (1) { | |
febd17d6 | 15787 | + inode_lock(inode); |
e49829fe JR |
15788 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
15789 | + if (!err) | |
15790 | + break; | |
febd17d6 | 15791 | + inode_unlock(inode); |
e49829fe JR |
15792 | + si_read_lock(sb, AuLock_NOPLMW); |
15793 | + si_read_unlock(sb); | |
15794 | + } | |
15795 | +} | |
15796 | + | |
4a4d8108 AM |
15797 | +static ssize_t aufs_write(struct file *file, const char __user *ubuf, |
15798 | + size_t count, loff_t *ppos) | |
dece6358 | 15799 | +{ |
4a4d8108 | 15800 | + ssize_t err; |
b912730e AM |
15801 | + struct au_write_pre wpre; |
15802 | + struct inode *inode; | |
4a4d8108 AM |
15803 | + struct file *h_file; |
15804 | + char __user *buf = (char __user *)ubuf; | |
1facf9fc | 15805 | + |
b912730e | 15806 | + inode = file_inode(file); |
e49829fe | 15807 | + au_mtx_and_read_lock(inode); |
1facf9fc | 15808 | + |
521ced18 | 15809 | + wpre.lsc = 0; |
b912730e AM |
15810 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15811 | + err = PTR_ERR(h_file); | |
15812 | + if (IS_ERR(h_file)) | |
9dbd164d | 15813 | + goto out; |
9dbd164d | 15814 | + |
4a4d8108 | 15815 | + err = vfsub_write_u(h_file, buf, count, ppos); |
b912730e | 15816 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 15817 | + |
4f0767ce | 15818 | +out: |
b912730e | 15819 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15820 | + inode_unlock(inode); |
dece6358 AM |
15821 | + return err; |
15822 | +} | |
1facf9fc | 15823 | + |
076b876e AM |
15824 | +static ssize_t au_do_iter(struct file *h_file, int rw, struct kiocb *kio, |
15825 | + struct iov_iter *iov_iter) | |
dece6358 | 15826 | +{ |
4a4d8108 AM |
15827 | + ssize_t err; |
15828 | + struct file *file; | |
076b876e | 15829 | + ssize_t (*iter)(struct kiocb *, struct iov_iter *); |
1facf9fc | 15830 | + |
4a4d8108 AM |
15831 | + err = security_file_permission(h_file, rw); |
15832 | + if (unlikely(err)) | |
15833 | + goto out; | |
1facf9fc | 15834 | + |
43982f53 | 15835 | + err = -ENOSYS; /* the branch doesn't have its ->(read|write)_iter() */ |
076b876e | 15836 | + iter = NULL; |
5527c038 | 15837 | + if (rw == MAY_READ) |
076b876e | 15838 | + iter = h_file->f_op->read_iter; |
5527c038 | 15839 | + else if (rw == MAY_WRITE) |
076b876e | 15840 | + iter = h_file->f_op->write_iter; |
076b876e AM |
15841 | + |
15842 | + file = kio->ki_filp; | |
15843 | + kio->ki_filp = h_file; | |
15844 | + if (iter) { | |
2cbb1c4b | 15845 | + lockdep_off(); |
076b876e AM |
15846 | + err = iter(kio, iov_iter); |
15847 | + lockdep_on(); | |
4a4d8108 AM |
15848 | + } else |
15849 | + /* currently there is no such fs */ | |
15850 | + WARN_ON_ONCE(1); | |
076b876e | 15851 | + kio->ki_filp = file; |
1facf9fc | 15852 | + |
4f0767ce | 15853 | +out: |
dece6358 AM |
15854 | + return err; |
15855 | +} | |
1facf9fc | 15856 | + |
076b876e | 15857 | +static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1facf9fc | 15858 | +{ |
4a4d8108 AM |
15859 | + ssize_t err; |
15860 | + struct file *file, *h_file; | |
b912730e | 15861 | + struct inode *inode; |
dece6358 | 15862 | + struct super_block *sb; |
1facf9fc | 15863 | + |
4a4d8108 | 15864 | + file = kio->ki_filp; |
b912730e AM |
15865 | + inode = file_inode(file); |
15866 | + sb = inode->i_sb; | |
e49829fe | 15867 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
4a4d8108 | 15868 | + |
521ced18 | 15869 | + h_file = au_read_pre(file, /*keep_fi*/1, /*lsc*/0); |
b912730e AM |
15870 | + err = PTR_ERR(h_file); |
15871 | + if (IS_ERR(h_file)) | |
15872 | + goto out; | |
9dbd164d | 15873 | + |
5afbbe0d AM |
15874 | + if (au_test_loopback_kthread()) { |
15875 | + au_warn_loopback(h_file->f_path.dentry->d_sb); | |
15876 | + if (file->f_mapping != h_file->f_mapping) { | |
15877 | + file->f_mapping = h_file->f_mapping; | |
15878 | + smp_mb(); /* unnecessary? */ | |
15879 | + } | |
15880 | + } | |
15881 | + fi_read_unlock(file); | |
15882 | + | |
076b876e | 15883 | + err = au_do_iter(h_file, MAY_READ, kio, iov_iter); |
4a4d8108 AM |
15884 | + /* todo: necessary? */ |
15885 | + /* file->f_ra = h_file->f_ra; */ | |
b912730e | 15886 | + au_read_post(inode, h_file); |
1facf9fc | 15887 | + |
4f0767ce | 15888 | +out: |
4a4d8108 | 15889 | + si_read_unlock(sb); |
1308ab2a | 15890 | + return err; |
15891 | +} | |
1facf9fc | 15892 | + |
076b876e | 15893 | +static ssize_t aufs_write_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
1308ab2a | 15894 | +{ |
4a4d8108 | 15895 | + ssize_t err; |
b912730e AM |
15896 | + struct au_write_pre wpre; |
15897 | + struct inode *inode; | |
4a4d8108 | 15898 | + struct file *file, *h_file; |
1308ab2a | 15899 | + |
4a4d8108 | 15900 | + file = kio->ki_filp; |
b912730e | 15901 | + inode = file_inode(file); |
e49829fe JR |
15902 | + au_mtx_and_read_lock(inode); |
15903 | + | |
521ced18 | 15904 | + wpre.lsc = 0; |
b912730e AM |
15905 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15906 | + err = PTR_ERR(h_file); | |
15907 | + if (IS_ERR(h_file)) | |
9dbd164d | 15908 | + goto out; |
9dbd164d | 15909 | + |
076b876e | 15910 | + err = au_do_iter(h_file, MAY_WRITE, kio, iov_iter); |
b912730e | 15911 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 15912 | + |
4f0767ce | 15913 | +out: |
b912730e | 15914 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15915 | + inode_unlock(inode); |
dece6358 | 15916 | + return err; |
1facf9fc | 15917 | +} |
15918 | + | |
4a4d8108 AM |
15919 | +static ssize_t aufs_splice_read(struct file *file, loff_t *ppos, |
15920 | + struct pipe_inode_info *pipe, size_t len, | |
15921 | + unsigned int flags) | |
1facf9fc | 15922 | +{ |
4a4d8108 AM |
15923 | + ssize_t err; |
15924 | + struct file *h_file; | |
b912730e | 15925 | + struct inode *inode; |
dece6358 | 15926 | + struct super_block *sb; |
1facf9fc | 15927 | + |
b912730e AM |
15928 | + inode = file_inode(file); |
15929 | + sb = inode->i_sb; | |
e49829fe | 15930 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 15931 | + |
521ced18 | 15932 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
15933 | + err = PTR_ERR(h_file); |
15934 | + if (IS_ERR(h_file)) | |
dece6358 | 15935 | + goto out; |
1facf9fc | 15936 | + |
4a4d8108 | 15937 | + err = vfsub_splice_to(h_file, ppos, pipe, len, flags); |
acd2b654 | 15938 | + /* todo: necessary? */ |
4a4d8108 | 15939 | + /* file->f_ra = h_file->f_ra; */ |
b912730e | 15940 | + au_read_post(inode, h_file); |
1facf9fc | 15941 | + |
4f0767ce | 15942 | +out: |
4a4d8108 | 15943 | + si_read_unlock(sb); |
dece6358 | 15944 | + return err; |
1facf9fc | 15945 | +} |
15946 | + | |
4a4d8108 AM |
15947 | +static ssize_t |
15948 | +aufs_splice_write(struct pipe_inode_info *pipe, struct file *file, loff_t *ppos, | |
15949 | + size_t len, unsigned int flags) | |
1facf9fc | 15950 | +{ |
4a4d8108 | 15951 | + ssize_t err; |
b912730e AM |
15952 | + struct au_write_pre wpre; |
15953 | + struct inode *inode; | |
076b876e | 15954 | + struct file *h_file; |
1facf9fc | 15955 | + |
b912730e | 15956 | + inode = file_inode(file); |
e49829fe | 15957 | + au_mtx_and_read_lock(inode); |
9dbd164d | 15958 | + |
521ced18 | 15959 | + wpre.lsc = 0; |
b912730e AM |
15960 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15961 | + err = PTR_ERR(h_file); | |
15962 | + if (IS_ERR(h_file)) | |
9dbd164d | 15963 | + goto out; |
9dbd164d | 15964 | + |
4a4d8108 | 15965 | + err = vfsub_splice_from(pipe, h_file, ppos, len, flags); |
b912730e | 15966 | + au_write_post(inode, h_file, &wpre, err); |
1facf9fc | 15967 | + |
4f0767ce | 15968 | +out: |
b912730e | 15969 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15970 | + inode_unlock(inode); |
4a4d8108 AM |
15971 | + return err; |
15972 | +} | |
1facf9fc | 15973 | + |
38d290e6 JR |
15974 | +static long aufs_fallocate(struct file *file, int mode, loff_t offset, |
15975 | + loff_t len) | |
15976 | +{ | |
15977 | + long err; | |
b912730e | 15978 | + struct au_write_pre wpre; |
38d290e6 JR |
15979 | + struct inode *inode; |
15980 | + struct file *h_file; | |
15981 | + | |
b912730e | 15982 | + inode = file_inode(file); |
38d290e6 JR |
15983 | + au_mtx_and_read_lock(inode); |
15984 | + | |
521ced18 | 15985 | + wpre.lsc = 0; |
b912730e AM |
15986 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
15987 | + err = PTR_ERR(h_file); | |
15988 | + if (IS_ERR(h_file)) | |
38d290e6 | 15989 | + goto out; |
38d290e6 JR |
15990 | + |
15991 | + lockdep_off(); | |
03673fb0 | 15992 | + err = vfs_fallocate(h_file, mode, offset, len); |
38d290e6 | 15993 | + lockdep_on(); |
b912730e | 15994 | + au_write_post(inode, h_file, &wpre, /*written*/1); |
38d290e6 JR |
15995 | + |
15996 | +out: | |
b912730e | 15997 | + si_read_unlock(inode->i_sb); |
febd17d6 | 15998 | + inode_unlock(inode); |
38d290e6 JR |
15999 | + return err; |
16000 | +} | |
16001 | + | |
521ced18 JR |
16002 | +static ssize_t aufs_copy_file_range(struct file *src, loff_t src_pos, |
16003 | + struct file *dst, loff_t dst_pos, | |
16004 | + size_t len, unsigned int flags) | |
16005 | +{ | |
16006 | + ssize_t err; | |
16007 | + struct au_write_pre wpre; | |
16008 | + enum { SRC, DST }; | |
16009 | + struct { | |
16010 | + struct inode *inode; | |
16011 | + struct file *h_file; | |
16012 | + struct super_block *h_sb; | |
16013 | + } a[2]; | |
16014 | +#define a_src a[SRC] | |
16015 | +#define a_dst a[DST] | |
16016 | + | |
16017 | + err = -EINVAL; | |
16018 | + a_src.inode = file_inode(src); | |
16019 | + if (unlikely(!S_ISREG(a_src.inode->i_mode))) | |
16020 | + goto out; | |
16021 | + a_dst.inode = file_inode(dst); | |
16022 | + if (unlikely(!S_ISREG(a_dst.inode->i_mode))) | |
16023 | + goto out; | |
16024 | + | |
16025 | + au_mtx_and_read_lock(a_dst.inode); | |
16026 | + /* | |
16027 | + * in order to match the order in di_write_lock2_{child,parent}(), | |
acd2b654 | 16028 | + * use f_path.dentry for this comparison. |
521ced18 JR |
16029 | + */ |
16030 | + if (src->f_path.dentry < dst->f_path.dentry) { | |
16031 | + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_1); | |
16032 | + err = PTR_ERR(a_src.h_file); | |
16033 | + if (IS_ERR(a_src.h_file)) | |
16034 | + goto out_si; | |
16035 | + | |
16036 | + wpre.lsc = AuLsc_FI_2; | |
16037 | + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre); | |
16038 | + err = PTR_ERR(a_dst.h_file); | |
16039 | + if (IS_ERR(a_dst.h_file)) { | |
16040 | + au_read_post(a_src.inode, a_src.h_file); | |
16041 | + goto out_si; | |
16042 | + } | |
16043 | + } else { | |
16044 | + wpre.lsc = AuLsc_FI_1; | |
16045 | + a_dst.h_file = au_write_pre(dst, /*do_ready*/1, &wpre); | |
16046 | + err = PTR_ERR(a_dst.h_file); | |
16047 | + if (IS_ERR(a_dst.h_file)) | |
16048 | + goto out_si; | |
16049 | + | |
16050 | + a_src.h_file = au_read_pre(src, /*keep_fi*/1, AuLsc_FI_2); | |
16051 | + err = PTR_ERR(a_src.h_file); | |
16052 | + if (IS_ERR(a_src.h_file)) { | |
16053 | + au_write_post(a_dst.inode, a_dst.h_file, &wpre, | |
16054 | + /*written*/0); | |
16055 | + goto out_si; | |
16056 | + } | |
16057 | + } | |
16058 | + | |
16059 | + err = -EXDEV; | |
16060 | + a_src.h_sb = file_inode(a_src.h_file)->i_sb; | |
16061 | + a_dst.h_sb = file_inode(a_dst.h_file)->i_sb; | |
16062 | + if (unlikely(a_src.h_sb != a_dst.h_sb)) { | |
16063 | + AuDbgFile(src); | |
16064 | + AuDbgFile(dst); | |
16065 | + goto out_file; | |
16066 | + } | |
16067 | + | |
16068 | + err = vfsub_copy_file_range(a_src.h_file, src_pos, a_dst.h_file, | |
16069 | + dst_pos, len, flags); | |
16070 | + | |
16071 | +out_file: | |
16072 | + au_write_post(a_dst.inode, a_dst.h_file, &wpre, err); | |
16073 | + fi_read_unlock(src); | |
16074 | + au_read_post(a_src.inode, a_src.h_file); | |
16075 | +out_si: | |
16076 | + si_read_unlock(a_dst.inode->i_sb); | |
16077 | + inode_unlock(a_dst.inode); | |
16078 | +out: | |
16079 | + return err; | |
16080 | +#undef a_src | |
16081 | +#undef a_dst | |
16082 | +} | |
16083 | + | |
4a4d8108 AM |
16084 | +/* ---------------------------------------------------------------------- */ |
16085 | + | |
9dbd164d AM |
16086 | +/* |
16087 | + * The locking order around current->mmap_sem. | |
16088 | + * - in most and regular cases | |
16089 | + * file I/O syscall -- aufs_read() or something | |
16090 | + * -- si_rwsem for read -- mmap_sem | |
16091 | + * (Note that [fdi]i_rwsem are released before mmap_sem). | |
16092 | + * - in mmap case | |
16093 | + * mmap(2) -- mmap_sem -- aufs_mmap() -- si_rwsem for read -- [fdi]i_rwsem | |
acd2b654 AM |
16094 | + * This AB-BA order is definitely bad, but is not a problem since "si_rwsem for |
16095 | + * read" allows multiple processes to acquire it and [fdi]i_rwsem are not held | |
16096 | + * in file I/O. Aufs needs to stop lockdep in aufs_mmap() though. | |
9dbd164d AM |
16097 | + * It means that when aufs acquires si_rwsem for write, the process should never |
16098 | + * acquire mmap_sem. | |
16099 | + * | |
392086de | 16100 | + * Actually aufs_iterate() holds [fdi]i_rwsem before mmap_sem, but this is not a |
9dbd164d AM |
16101 | + * problem either since any directory is not able to be mmap-ed. |
16102 | + * The similar scenario is applied to aufs_readlink() too. | |
16103 | + */ | |
16104 | + | |
38d290e6 | 16105 | +#if 0 /* stop calling security_file_mmap() */ |
2dfbb274 AM |
16106 | +/* cf. linux/include/linux/mman.h: calc_vm_prot_bits() */ |
16107 | +#define AuConv_VM_PROT(f, b) _calc_vm_trans(f, VM_##b, PROT_##b) | |
16108 | + | |
16109 | +static unsigned long au_arch_prot_conv(unsigned long flags) | |
16110 | +{ | |
16111 | + /* currently ppc64 only */ | |
16112 | +#ifdef CONFIG_PPC64 | |
16113 | + /* cf. linux/arch/powerpc/include/asm/mman.h */ | |
16114 | + AuDebugOn(arch_calc_vm_prot_bits(-1) != VM_SAO); | |
16115 | + return AuConv_VM_PROT(flags, SAO); | |
16116 | +#else | |
16117 | + AuDebugOn(arch_calc_vm_prot_bits(-1)); | |
16118 | + return 0; | |
16119 | +#endif | |
16120 | +} | |
16121 | + | |
16122 | +static unsigned long au_prot_conv(unsigned long flags) | |
16123 | +{ | |
16124 | + return AuConv_VM_PROT(flags, READ) | |
16125 | + | AuConv_VM_PROT(flags, WRITE) | |
16126 | + | AuConv_VM_PROT(flags, EXEC) | |
16127 | + | au_arch_prot_conv(flags); | |
16128 | +} | |
16129 | + | |
16130 | +/* cf. linux/include/linux/mman.h: calc_vm_flag_bits() */ | |
16131 | +#define AuConv_VM_MAP(f, b) _calc_vm_trans(f, VM_##b, MAP_##b) | |
16132 | + | |
16133 | +static unsigned long au_flag_conv(unsigned long flags) | |
16134 | +{ | |
16135 | + return AuConv_VM_MAP(flags, GROWSDOWN) | |
16136 | + | AuConv_VM_MAP(flags, DENYWRITE) | |
2dfbb274 AM |
16137 | + | AuConv_VM_MAP(flags, LOCKED); |
16138 | +} | |
38d290e6 | 16139 | +#endif |
2dfbb274 | 16140 | + |
9dbd164d | 16141 | +static int aufs_mmap(struct file *file, struct vm_area_struct *vma) |
dece6358 | 16142 | +{ |
4a4d8108 | 16143 | + int err; |
4a4d8108 | 16144 | + const unsigned char wlock |
9dbd164d | 16145 | + = (file->f_mode & FMODE_WRITE) && (vma->vm_flags & VM_SHARED); |
4a4d8108 | 16146 | + struct super_block *sb; |
9dbd164d | 16147 | + struct file *h_file; |
b912730e | 16148 | + struct inode *inode; |
9dbd164d AM |
16149 | + |
16150 | + AuDbgVmRegion(file, vma); | |
1308ab2a | 16151 | + |
b912730e AM |
16152 | + inode = file_inode(file); |
16153 | + sb = inode->i_sb; | |
9dbd164d | 16154 | + lockdep_off(); |
e49829fe | 16155 | + si_read_lock(sb, AuLock_NOPLMW); |
4a4d8108 | 16156 | + |
b912730e | 16157 | + h_file = au_write_pre(file, wlock, /*wpre*/NULL); |
9dbd164d | 16158 | + lockdep_on(); |
b912730e AM |
16159 | + err = PTR_ERR(h_file); |
16160 | + if (IS_ERR(h_file)) | |
16161 | + goto out; | |
1308ab2a | 16162 | + |
b912730e AM |
16163 | + err = 0; |
16164 | + au_set_mmapped(file); | |
9dbd164d | 16165 | + au_vm_file_reset(vma, h_file); |
38d290e6 JR |
16166 | + /* |
16167 | + * we cannot call security_mmap_file() here since it may acquire | |
16168 | + * mmap_sem or i_mutex. | |
16169 | + * | |
16170 | + * err = security_mmap_file(h_file, au_prot_conv(vma->vm_flags), | |
16171 | + * au_flag_conv(vma->vm_flags)); | |
16172 | + */ | |
9dbd164d | 16173 | + if (!err) |
521ced18 | 16174 | + err = call_mmap(h_file, vma); |
b912730e AM |
16175 | + if (!err) { |
16176 | + au_vm_prfile_set(vma, file); | |
16177 | + fsstack_copy_attr_atime(inode, file_inode(h_file)); | |
16178 | + goto out_fput; /* success */ | |
16179 | + } | |
2cbb1c4b JR |
16180 | + au_unset_mmapped(file); |
16181 | + au_vm_file_reset(vma, file); | |
b912730e | 16182 | + |
2cbb1c4b | 16183 | +out_fput: |
9dbd164d | 16184 | + lockdep_off(); |
b912730e AM |
16185 | + ii_write_unlock(inode); |
16186 | + lockdep_on(); | |
16187 | + fput(h_file); | |
4f0767ce | 16188 | +out: |
b912730e | 16189 | + lockdep_off(); |
9dbd164d AM |
16190 | + si_read_unlock(sb); |
16191 | + lockdep_on(); | |
16192 | + AuTraceErr(err); | |
4a4d8108 AM |
16193 | + return err; |
16194 | +} | |
16195 | + | |
16196 | +/* ---------------------------------------------------------------------- */ | |
16197 | + | |
1e00d052 AM |
16198 | +static int aufs_fsync_nondir(struct file *file, loff_t start, loff_t end, |
16199 | + int datasync) | |
4a4d8108 AM |
16200 | +{ |
16201 | + int err; | |
b912730e | 16202 | + struct au_write_pre wpre; |
4a4d8108 AM |
16203 | + struct inode *inode; |
16204 | + struct file *h_file; | |
4a4d8108 AM |
16205 | + |
16206 | + err = 0; /* -EBADF; */ /* posix? */ | |
16207 | + if (unlikely(!(file->f_mode & FMODE_WRITE))) | |
b912730e | 16208 | + goto out; |
4a4d8108 | 16209 | + |
b912730e AM |
16210 | + inode = file_inode(file); |
16211 | + au_mtx_and_read_lock(inode); | |
16212 | + | |
521ced18 | 16213 | + wpre.lsc = 0; |
b912730e AM |
16214 | + h_file = au_write_pre(file, /*do_ready*/1, &wpre); |
16215 | + err = PTR_ERR(h_file); | |
16216 | + if (IS_ERR(h_file)) | |
4a4d8108 | 16217 | + goto out_unlock; |
4a4d8108 | 16218 | + |
53392da6 | 16219 | + err = vfsub_fsync(h_file, &h_file->f_path, datasync); |
b912730e | 16220 | + au_write_post(inode, h_file, &wpre, /*written*/0); |
4a4d8108 | 16221 | + |
4f0767ce | 16222 | +out_unlock: |
b912730e | 16223 | + si_read_unlock(inode->i_sb); |
febd17d6 | 16224 | + inode_unlock(inode); |
b912730e | 16225 | +out: |
4a4d8108 | 16226 | + return err; |
dece6358 AM |
16227 | +} |
16228 | + | |
4a4d8108 | 16229 | +static int aufs_fasync(int fd, struct file *file, int flag) |
dece6358 | 16230 | +{ |
4a4d8108 AM |
16231 | + int err; |
16232 | + struct file *h_file; | |
4a4d8108 | 16233 | + struct super_block *sb; |
1308ab2a | 16234 | + |
b912730e | 16235 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 16236 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 16237 | + |
521ced18 | 16238 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
b912730e AM |
16239 | + err = PTR_ERR(h_file); |
16240 | + if (IS_ERR(h_file)) | |
4a4d8108 AM |
16241 | + goto out; |
16242 | + | |
523b37e3 | 16243 | + if (h_file->f_op->fasync) |
4a4d8108 | 16244 | + err = h_file->f_op->fasync(fd, h_file, flag); |
b912730e | 16245 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 16246 | + |
4f0767ce | 16247 | +out: |
4a4d8108 | 16248 | + si_read_unlock(sb); |
1308ab2a | 16249 | + return err; |
dece6358 | 16250 | +} |
4a4d8108 | 16251 | + |
febd17d6 JR |
16252 | +static int aufs_setfl(struct file *file, unsigned long arg) |
16253 | +{ | |
16254 | + int err; | |
16255 | + struct file *h_file; | |
16256 | + struct super_block *sb; | |
16257 | + | |
16258 | + sb = file->f_path.dentry->d_sb; | |
16259 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); | |
16260 | + | |
521ced18 | 16261 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
febd17d6 JR |
16262 | + err = PTR_ERR(h_file); |
16263 | + if (IS_ERR(h_file)) | |
16264 | + goto out; | |
16265 | + | |
1c60b727 AM |
16266 | + /* stop calling h_file->fasync */ |
16267 | + arg |= vfsub_file_flags(file) & FASYNC; | |
febd17d6 JR |
16268 | + err = setfl(/*unused fd*/-1, h_file, arg); |
16269 | + fput(h_file); /* instead of au_read_post() */ | |
16270 | + | |
16271 | +out: | |
16272 | + si_read_unlock(sb); | |
16273 | + return err; | |
16274 | +} | |
16275 | + | |
4a4d8108 AM |
16276 | +/* ---------------------------------------------------------------------- */ |
16277 | + | |
16278 | +/* no one supports this operation, currently */ | |
43982f53 | 16279 | +#if 0 /* reserved for future use */ |
4a4d8108 | 16280 | +static ssize_t aufs_sendpage(struct file *file, struct page *page, int offset, |
2000de60 | 16281 | + size_t len, loff_t *pos, int more) |
4a4d8108 AM |
16282 | +{ |
16283 | +} | |
16284 | +#endif | |
16285 | + | |
16286 | +/* ---------------------------------------------------------------------- */ | |
16287 | + | |
16288 | +const struct file_operations aufs_file_fop = { | |
16289 | + .owner = THIS_MODULE, | |
2cbb1c4b | 16290 | + |
027c5e7a | 16291 | + .llseek = default_llseek, |
4a4d8108 AM |
16292 | + |
16293 | + .read = aufs_read, | |
16294 | + .write = aufs_write, | |
076b876e AM |
16295 | + .read_iter = aufs_read_iter, |
16296 | + .write_iter = aufs_write_iter, | |
16297 | + | |
4a4d8108 AM |
16298 | +#ifdef CONFIG_AUFS_POLL |
16299 | + .poll = aufs_poll, | |
16300 | +#endif | |
16301 | + .unlocked_ioctl = aufs_ioctl_nondir, | |
b752ccd1 | 16302 | +#ifdef CONFIG_COMPAT |
c2b27bf2 | 16303 | + .compat_ioctl = aufs_compat_ioctl_nondir, |
b752ccd1 | 16304 | +#endif |
4a4d8108 AM |
16305 | + .mmap = aufs_mmap, |
16306 | + .open = aufs_open_nondir, | |
16307 | + .flush = aufs_flush_nondir, | |
16308 | + .release = aufs_release_nondir, | |
16309 | + .fsync = aufs_fsync_nondir, | |
4a4d8108 AM |
16310 | + .fasync = aufs_fasync, |
16311 | + /* .sendpage = aufs_sendpage, */ | |
febd17d6 | 16312 | + .setfl = aufs_setfl, |
4a4d8108 AM |
16313 | + .splice_write = aufs_splice_write, |
16314 | + .splice_read = aufs_splice_read, | |
43982f53 | 16315 | +#if 0 /* reserved for future use */ |
4a4d8108 | 16316 | + .aio_splice_write = aufs_aio_splice_write, |
38d290e6 | 16317 | + .aio_splice_read = aufs_aio_splice_read, |
4a4d8108 | 16318 | +#endif |
521ced18 JR |
16319 | + .fallocate = aufs_fallocate, |
16320 | + .copy_file_range = aufs_copy_file_range | |
4a4d8108 | 16321 | +}; |
7f207e10 | 16322 | diff -urN /usr/share/empty/fs/aufs/fstype.h linux/fs/aufs/fstype.h |
eca34b5c | 16323 | --- /usr/share/empty/fs/aufs/fstype.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 16324 | +++ linux/fs/aufs/fstype.h 2020-01-27 10:57:18.172204883 +0100 |
062440b3 AM |
16325 | @@ -0,0 +1,401 @@ |
16326 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
4a4d8108 | 16327 | +/* |
d58c55f2 | 16328 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
16329 | + * |
16330 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16331 | + * it under the terms of the GNU General Public License as published by | |
16332 | + * the Free Software Foundation; either version 2 of the License, or | |
16333 | + * (at your option) any later version. | |
16334 | + * | |
16335 | + * This program is distributed in the hope that it will be useful, | |
16336 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16337 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16338 | + * GNU General Public License for more details. | |
16339 | + * | |
16340 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16341 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
16342 | + */ |
16343 | + | |
16344 | +/* | |
16345 | + * judging filesystem type | |
16346 | + */ | |
16347 | + | |
16348 | +#ifndef __AUFS_FSTYPE_H__ | |
16349 | +#define __AUFS_FSTYPE_H__ | |
16350 | + | |
16351 | +#ifdef __KERNEL__ | |
16352 | + | |
16353 | +#include <linux/fs.h> | |
16354 | +#include <linux/magic.h> | |
b912730e | 16355 | +#include <linux/nfs_fs.h> |
b95c5147 | 16356 | +#include <linux/romfs_fs.h> |
4a4d8108 AM |
16357 | + |
16358 | +static inline int au_test_aufs(struct super_block *sb) | |
16359 | +{ | |
16360 | + return sb->s_magic == AUFS_SUPER_MAGIC; | |
16361 | +} | |
16362 | + | |
16363 | +static inline const char *au_sbtype(struct super_block *sb) | |
16364 | +{ | |
16365 | + return sb->s_type->name; | |
16366 | +} | |
1308ab2a | 16367 | + |
16368 | +static inline int au_test_iso9660(struct super_block *sb __maybe_unused) | |
16369 | +{ | |
f0c0a007 | 16370 | +#if IS_ENABLED(CONFIG_ISO9660_FS) |
2000de60 | 16371 | + return sb->s_magic == ISOFS_SUPER_MAGIC; |
dece6358 AM |
16372 | +#else |
16373 | + return 0; | |
16374 | +#endif | |
16375 | +} | |
16376 | + | |
1308ab2a | 16377 | +static inline int au_test_romfs(struct super_block *sb __maybe_unused) |
dece6358 | 16378 | +{ |
f0c0a007 | 16379 | +#if IS_ENABLED(CONFIG_ROMFS_FS) |
2000de60 | 16380 | + return sb->s_magic == ROMFS_MAGIC; |
dece6358 AM |
16381 | +#else |
16382 | + return 0; | |
16383 | +#endif | |
16384 | +} | |
16385 | + | |
1308ab2a | 16386 | +static inline int au_test_cramfs(struct super_block *sb __maybe_unused) |
dece6358 | 16387 | +{ |
f0c0a007 | 16388 | +#if IS_ENABLED(CONFIG_CRAMFS) |
1308ab2a | 16389 | + return sb->s_magic == CRAMFS_MAGIC; |
16390 | +#endif | |
16391 | + return 0; | |
16392 | +} | |
16393 | + | |
16394 | +static inline int au_test_nfs(struct super_block *sb __maybe_unused) | |
16395 | +{ | |
f0c0a007 | 16396 | +#if IS_ENABLED(CONFIG_NFS_FS) |
1308ab2a | 16397 | + return sb->s_magic == NFS_SUPER_MAGIC; |
dece6358 AM |
16398 | +#else |
16399 | + return 0; | |
16400 | +#endif | |
16401 | +} | |
16402 | + | |
1308ab2a | 16403 | +static inline int au_test_fuse(struct super_block *sb __maybe_unused) |
dece6358 | 16404 | +{ |
f0c0a007 | 16405 | +#if IS_ENABLED(CONFIG_FUSE_FS) |
1308ab2a | 16406 | + return sb->s_magic == FUSE_SUPER_MAGIC; |
dece6358 AM |
16407 | +#else |
16408 | + return 0; | |
16409 | +#endif | |
16410 | +} | |
16411 | + | |
1308ab2a | 16412 | +static inline int au_test_xfs(struct super_block *sb __maybe_unused) |
dece6358 | 16413 | +{ |
f0c0a007 | 16414 | +#if IS_ENABLED(CONFIG_XFS_FS) |
1308ab2a | 16415 | + return sb->s_magic == XFS_SB_MAGIC; |
dece6358 AM |
16416 | +#else |
16417 | + return 0; | |
16418 | +#endif | |
16419 | +} | |
16420 | + | |
1308ab2a | 16421 | +static inline int au_test_tmpfs(struct super_block *sb __maybe_unused) |
dece6358 | 16422 | +{ |
1308ab2a | 16423 | +#ifdef CONFIG_TMPFS |
16424 | + return sb->s_magic == TMPFS_MAGIC; | |
16425 | +#else | |
16426 | + return 0; | |
dece6358 | 16427 | +#endif |
dece6358 AM |
16428 | +} |
16429 | + | |
1308ab2a | 16430 | +static inline int au_test_ecryptfs(struct super_block *sb __maybe_unused) |
1facf9fc | 16431 | +{ |
f0c0a007 | 16432 | +#if IS_ENABLED(CONFIG_ECRYPT_FS) |
1308ab2a | 16433 | + return !strcmp(au_sbtype(sb), "ecryptfs"); |
16434 | +#else | |
16435 | + return 0; | |
16436 | +#endif | |
1facf9fc | 16437 | +} |
16438 | + | |
1308ab2a | 16439 | +static inline int au_test_ramfs(struct super_block *sb) |
16440 | +{ | |
16441 | + return sb->s_magic == RAMFS_MAGIC; | |
16442 | +} | |
16443 | + | |
16444 | +static inline int au_test_ubifs(struct super_block *sb __maybe_unused) | |
16445 | +{ | |
f0c0a007 | 16446 | +#if IS_ENABLED(CONFIG_UBIFS_FS) |
1308ab2a | 16447 | + return sb->s_magic == UBIFS_SUPER_MAGIC; |
16448 | +#else | |
16449 | + return 0; | |
16450 | +#endif | |
16451 | +} | |
16452 | + | |
16453 | +static inline int au_test_procfs(struct super_block *sb __maybe_unused) | |
16454 | +{ | |
16455 | +#ifdef CONFIG_PROC_FS | |
16456 | + return sb->s_magic == PROC_SUPER_MAGIC; | |
16457 | +#else | |
16458 | + return 0; | |
16459 | +#endif | |
16460 | +} | |
16461 | + | |
16462 | +static inline int au_test_sysfs(struct super_block *sb __maybe_unused) | |
16463 | +{ | |
16464 | +#ifdef CONFIG_SYSFS | |
16465 | + return sb->s_magic == SYSFS_MAGIC; | |
16466 | +#else | |
16467 | + return 0; | |
16468 | +#endif | |
16469 | +} | |
16470 | + | |
16471 | +static inline int au_test_configfs(struct super_block *sb __maybe_unused) | |
16472 | +{ | |
f0c0a007 | 16473 | +#if IS_ENABLED(CONFIG_CONFIGFS_FS) |
1308ab2a | 16474 | + return sb->s_magic == CONFIGFS_MAGIC; |
16475 | +#else | |
16476 | + return 0; | |
16477 | +#endif | |
16478 | +} | |
16479 | + | |
16480 | +static inline int au_test_minix(struct super_block *sb __maybe_unused) | |
16481 | +{ | |
f0c0a007 | 16482 | +#if IS_ENABLED(CONFIG_MINIX_FS) |
1308ab2a | 16483 | + return sb->s_magic == MINIX3_SUPER_MAGIC |
16484 | + || sb->s_magic == MINIX2_SUPER_MAGIC | |
16485 | + || sb->s_magic == MINIX2_SUPER_MAGIC2 | |
16486 | + || sb->s_magic == MINIX_SUPER_MAGIC | |
16487 | + || sb->s_magic == MINIX_SUPER_MAGIC2; | |
16488 | +#else | |
16489 | + return 0; | |
16490 | +#endif | |
16491 | +} | |
16492 | + | |
1308ab2a | 16493 | +static inline int au_test_fat(struct super_block *sb __maybe_unused) |
16494 | +{ | |
f0c0a007 | 16495 | +#if IS_ENABLED(CONFIG_FAT_FS) |
1308ab2a | 16496 | + return sb->s_magic == MSDOS_SUPER_MAGIC; |
16497 | +#else | |
16498 | + return 0; | |
16499 | +#endif | |
16500 | +} | |
16501 | + | |
16502 | +static inline int au_test_msdos(struct super_block *sb) | |
16503 | +{ | |
16504 | + return au_test_fat(sb); | |
16505 | +} | |
16506 | + | |
16507 | +static inline int au_test_vfat(struct super_block *sb) | |
16508 | +{ | |
16509 | + return au_test_fat(sb); | |
16510 | +} | |
16511 | + | |
16512 | +static inline int au_test_securityfs(struct super_block *sb __maybe_unused) | |
16513 | +{ | |
16514 | +#ifdef CONFIG_SECURITYFS | |
16515 | + return sb->s_magic == SECURITYFS_MAGIC; | |
16516 | +#else | |
16517 | + return 0; | |
16518 | +#endif | |
16519 | +} | |
16520 | + | |
16521 | +static inline int au_test_squashfs(struct super_block *sb __maybe_unused) | |
16522 | +{ | |
f0c0a007 | 16523 | +#if IS_ENABLED(CONFIG_SQUASHFS) |
1308ab2a | 16524 | + return sb->s_magic == SQUASHFS_MAGIC; |
16525 | +#else | |
16526 | + return 0; | |
16527 | +#endif | |
16528 | +} | |
16529 | + | |
16530 | +static inline int au_test_btrfs(struct super_block *sb __maybe_unused) | |
16531 | +{ | |
f0c0a007 | 16532 | +#if IS_ENABLED(CONFIG_BTRFS_FS) |
1308ab2a | 16533 | + return sb->s_magic == BTRFS_SUPER_MAGIC; |
16534 | +#else | |
16535 | + return 0; | |
16536 | +#endif | |
16537 | +} | |
16538 | + | |
16539 | +static inline int au_test_xenfs(struct super_block *sb __maybe_unused) | |
16540 | +{ | |
f0c0a007 | 16541 | +#if IS_ENABLED(CONFIG_XENFS) |
1308ab2a | 16542 | + return sb->s_magic == XENFS_SUPER_MAGIC; |
16543 | +#else | |
16544 | + return 0; | |
16545 | +#endif | |
16546 | +} | |
16547 | + | |
16548 | +static inline int au_test_debugfs(struct super_block *sb __maybe_unused) | |
16549 | +{ | |
16550 | +#ifdef CONFIG_DEBUG_FS | |
16551 | + return sb->s_magic == DEBUGFS_MAGIC; | |
16552 | +#else | |
16553 | + return 0; | |
16554 | +#endif | |
16555 | +} | |
16556 | + | |
16557 | +static inline int au_test_nilfs(struct super_block *sb __maybe_unused) | |
16558 | +{ | |
f0c0a007 | 16559 | +#if IS_ENABLED(CONFIG_NILFS) |
1308ab2a | 16560 | + return sb->s_magic == NILFS_SUPER_MAGIC; |
16561 | +#else | |
16562 | + return 0; | |
16563 | +#endif | |
16564 | +} | |
16565 | + | |
4a4d8108 AM |
16566 | +static inline int au_test_hfsplus(struct super_block *sb __maybe_unused) |
16567 | +{ | |
f0c0a007 | 16568 | +#if IS_ENABLED(CONFIG_HFSPLUS_FS) |
4a4d8108 AM |
16569 | + return sb->s_magic == HFSPLUS_SUPER_MAGIC; |
16570 | +#else | |
16571 | + return 0; | |
16572 | +#endif | |
16573 | +} | |
16574 | + | |
1308ab2a | 16575 | +/* ---------------------------------------------------------------------- */ |
16576 | +/* | |
16577 | + * they can't be an aufs branch. | |
16578 | + */ | |
16579 | +static inline int au_test_fs_unsuppoted(struct super_block *sb) | |
16580 | +{ | |
16581 | + return | |
16582 | +#ifndef CONFIG_AUFS_BR_RAMFS | |
16583 | + au_test_ramfs(sb) || | |
16584 | +#endif | |
16585 | + au_test_procfs(sb) | |
16586 | + || au_test_sysfs(sb) | |
16587 | + || au_test_configfs(sb) | |
16588 | + || au_test_debugfs(sb) | |
16589 | + || au_test_securityfs(sb) | |
16590 | + || au_test_xenfs(sb) | |
16591 | + || au_test_ecryptfs(sb) | |
16592 | + /* || !strcmp(au_sbtype(sb), "unionfs") */ | |
16593 | + || au_test_aufs(sb); /* will be supported in next version */ | |
16594 | +} | |
16595 | + | |
1308ab2a | 16596 | +static inline int au_test_fs_remote(struct super_block *sb) |
16597 | +{ | |
16598 | + return !au_test_tmpfs(sb) | |
16599 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
16600 | + && !au_test_ramfs(sb) | |
16601 | +#endif | |
16602 | + && !(sb->s_type->fs_flags & FS_REQUIRES_DEV); | |
16603 | +} | |
16604 | + | |
16605 | +/* ---------------------------------------------------------------------- */ | |
16606 | + | |
16607 | +/* | |
16608 | + * Note: these functions (below) are created after reading ->getattr() in all | |
16609 | + * filesystems under linux/fs. it means we have to do so in every update... | |
16610 | + */ | |
16611 | + | |
16612 | +/* | |
16613 | + * some filesystems require getattr to refresh the inode attributes before | |
16614 | + * referencing. | |
16615 | + * in most cases, we can rely on the inode attribute in NFS (or every remote fs) | |
16616 | + * and leave the work for d_revalidate() | |
16617 | + */ | |
16618 | +static inline int au_test_fs_refresh_iattr(struct super_block *sb) | |
16619 | +{ | |
16620 | + return au_test_nfs(sb) | |
16621 | + || au_test_fuse(sb) | |
1308ab2a | 16622 | + /* || au_test_btrfs(sb) */ /* untested */ |
1308ab2a | 16623 | + ; |
16624 | +} | |
16625 | + | |
16626 | +/* | |
16627 | + * filesystems which don't maintain i_size or i_blocks. | |
16628 | + */ | |
16629 | +static inline int au_test_fs_bad_iattr_size(struct super_block *sb) | |
16630 | +{ | |
16631 | + return au_test_xfs(sb) | |
4a4d8108 AM |
16632 | + || au_test_btrfs(sb) |
16633 | + || au_test_ubifs(sb) | |
16634 | + || au_test_hfsplus(sb) /* maintained, but incorrect */ | |
1308ab2a | 16635 | + /* || au_test_minix(sb) */ /* untested */ |
16636 | + ; | |
16637 | +} | |
16638 | + | |
16639 | +/* | |
16640 | + * filesystems which don't store the correct value in some of their inode | |
16641 | + * attributes. | |
16642 | + */ | |
16643 | +static inline int au_test_fs_bad_iattr(struct super_block *sb) | |
16644 | +{ | |
16645 | + return au_test_fs_bad_iattr_size(sb) | |
1308ab2a | 16646 | + || au_test_fat(sb) |
16647 | + || au_test_msdos(sb) | |
16648 | + || au_test_vfat(sb); | |
1facf9fc | 16649 | +} |
16650 | + | |
16651 | +/* they don't check i_nlink in link(2) */ | |
16652 | +static inline int au_test_fs_no_limit_nlink(struct super_block *sb) | |
16653 | +{ | |
16654 | + return au_test_tmpfs(sb) | |
16655 | +#ifdef CONFIG_AUFS_BR_RAMFS | |
16656 | + || au_test_ramfs(sb) | |
16657 | +#endif | |
4a4d8108 | 16658 | + || au_test_ubifs(sb) |
4a4d8108 | 16659 | + || au_test_hfsplus(sb); |
1facf9fc | 16660 | +} |
16661 | + | |
16662 | +/* | |
16663 | + * filesystems which sets S_NOATIME and S_NOCMTIME. | |
16664 | + */ | |
16665 | +static inline int au_test_fs_notime(struct super_block *sb) | |
16666 | +{ | |
16667 | + return au_test_nfs(sb) | |
16668 | + || au_test_fuse(sb) | |
dece6358 | 16669 | + || au_test_ubifs(sb) |
1facf9fc | 16670 | + ; |
16671 | +} | |
16672 | + | |
1facf9fc | 16673 | +/* temporary support for i#1 in cramfs */ |
16674 | +static inline int au_test_fs_unique_ino(struct inode *inode) | |
16675 | +{ | |
16676 | + if (au_test_cramfs(inode->i_sb)) | |
16677 | + return inode->i_ino != 1; | |
16678 | + return 1; | |
16679 | +} | |
16680 | + | |
16681 | +/* ---------------------------------------------------------------------- */ | |
16682 | + | |
16683 | +/* | |
16684 | + * the filesystem where the xino files placed must support i/o after unlink and | |
16685 | + * maintain i_size and i_blocks. | |
16686 | + */ | |
16687 | +static inline int au_test_fs_bad_xino(struct super_block *sb) | |
16688 | +{ | |
16689 | + return au_test_fs_remote(sb) | |
16690 | + || au_test_fs_bad_iattr_size(sb) | |
1facf9fc | 16691 | + /* don't want unnecessary work for xino */ |
16692 | + || au_test_aufs(sb) | |
1308ab2a | 16693 | + || au_test_ecryptfs(sb) |
16694 | + || au_test_nilfs(sb); | |
1facf9fc | 16695 | +} |
16696 | + | |
16697 | +static inline int au_test_fs_trunc_xino(struct super_block *sb) | |
16698 | +{ | |
16699 | + return au_test_tmpfs(sb) | |
16700 | + || au_test_ramfs(sb); | |
16701 | +} | |
16702 | + | |
16703 | +/* | |
16704 | + * test if the @sb is real-readonly. | |
16705 | + */ | |
16706 | +static inline int au_test_fs_rr(struct super_block *sb) | |
16707 | +{ | |
16708 | + return au_test_squashfs(sb) | |
16709 | + || au_test_iso9660(sb) | |
16710 | + || au_test_cramfs(sb) | |
16711 | + || au_test_romfs(sb); | |
16712 | +} | |
16713 | + | |
b912730e AM |
16714 | +/* |
16715 | + * test if the @inode is nfs with 'noacl' option | |
2121bcd9 | 16716 | + * NFS always sets SB_POSIXACL regardless its mount option 'noacl.' |
b912730e AM |
16717 | + */ |
16718 | +static inline int au_test_nfs_noacl(struct inode *inode) | |
16719 | +{ | |
16720 | + return au_test_nfs(inode->i_sb) | |
16721 | + /* && IS_POSIXACL(inode) */ | |
16722 | + && !nfs_server_capable(inode, NFS_CAP_ACLS); | |
16723 | +} | |
16724 | + | |
1facf9fc | 16725 | +#endif /* __KERNEL__ */ |
16726 | +#endif /* __AUFS_FSTYPE_H__ */ | |
8b6a4947 | 16727 | diff -urN /usr/share/empty/fs/aufs/hbl.h linux/fs/aufs/hbl.h |
eca34b5c | 16728 | --- /usr/share/empty/fs/aufs/hbl.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 16729 | +++ linux/fs/aufs/hbl.h 2020-01-27 10:57:18.172204883 +0100 |
062440b3 AM |
16730 | @@ -0,0 +1,65 @@ |
16731 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
8b6a4947 | 16732 | +/* |
d58c55f2 | 16733 | + * Copyright (C) 2017-2020 Junjiro R. Okajima |
8b6a4947 AM |
16734 | + * |
16735 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16736 | + * it under the terms of the GNU General Public License as published by | |
16737 | + * the Free Software Foundation; either version 2 of the License, or | |
16738 | + * (at your option) any later version. | |
16739 | + * | |
16740 | + * This program is distributed in the hope that it will be useful, | |
16741 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16742 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16743 | + * GNU General Public License for more details. | |
16744 | + * | |
16745 | + * You should have received a copy of the GNU General Public License | |
16746 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
16747 | + */ | |
16748 | + | |
16749 | +/* | |
16750 | + * helpers for hlist_bl.h | |
16751 | + */ | |
16752 | + | |
16753 | +#ifndef __AUFS_HBL_H__ | |
16754 | +#define __AUFS_HBL_H__ | |
16755 | + | |
16756 | +#ifdef __KERNEL__ | |
16757 | + | |
16758 | +#include <linux/list_bl.h> | |
16759 | + | |
16760 | +static inline void au_hbl_add(struct hlist_bl_node *node, | |
16761 | + struct hlist_bl_head *hbl) | |
16762 | +{ | |
16763 | + hlist_bl_lock(hbl); | |
16764 | + hlist_bl_add_head(node, hbl); | |
16765 | + hlist_bl_unlock(hbl); | |
16766 | +} | |
16767 | + | |
16768 | +static inline void au_hbl_del(struct hlist_bl_node *node, | |
16769 | + struct hlist_bl_head *hbl) | |
16770 | +{ | |
16771 | + hlist_bl_lock(hbl); | |
16772 | + hlist_bl_del(node); | |
16773 | + hlist_bl_unlock(hbl); | |
16774 | +} | |
16775 | + | |
16776 | +#define au_hbl_for_each(pos, head) \ | |
16777 | + for (pos = hlist_bl_first(head); \ | |
16778 | + pos; \ | |
16779 | + pos = pos->next) | |
16780 | + | |
16781 | +static inline unsigned long au_hbl_count(struct hlist_bl_head *hbl) | |
16782 | +{ | |
16783 | + unsigned long cnt; | |
16784 | + struct hlist_bl_node *pos; | |
16785 | + | |
16786 | + cnt = 0; | |
16787 | + hlist_bl_lock(hbl); | |
16788 | + au_hbl_for_each(pos, hbl) | |
16789 | + cnt++; | |
16790 | + hlist_bl_unlock(hbl); | |
16791 | + return cnt; | |
16792 | +} | |
16793 | + | |
16794 | +#endif /* __KERNEL__ */ | |
16795 | +#endif /* __AUFS_HBL_H__ */ | |
7f207e10 | 16796 | diff -urN /usr/share/empty/fs/aufs/hfsnotify.c linux/fs/aufs/hfsnotify.c |
eca34b5c | 16797 | --- /usr/share/empty/fs/aufs/hfsnotify.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 16798 | +++ linux/fs/aufs/hfsnotify.c 2020-01-27 10:57:18.172204883 +0100 |
fbc438ed | 16799 | @@ -0,0 +1,288 @@ |
cd7a4cd9 | 16800 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 16801 | +/* |
d58c55f2 | 16802 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 16803 | + * |
16804 | + * This program, aufs is free software; you can redistribute it and/or modify | |
16805 | + * it under the terms of the GNU General Public License as published by | |
16806 | + * the Free Software Foundation; either version 2 of the License, or | |
16807 | + * (at your option) any later version. | |
dece6358 AM |
16808 | + * |
16809 | + * This program is distributed in the hope that it will be useful, | |
16810 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16811 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16812 | + * GNU General Public License for more details. | |
16813 | + * | |
16814 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 16815 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 16816 | + */ |
16817 | + | |
16818 | +/* | |
4a4d8108 | 16819 | + * fsnotify for the lower directories |
1facf9fc | 16820 | + */ |
16821 | + | |
16822 | +#include "aufs.h" | |
16823 | + | |
4a4d8108 AM |
16824 | +/* FS_IN_IGNORED is unnecessary */ |
16825 | +static const __u32 AuHfsnMask = (FS_MOVED_TO | FS_MOVED_FROM | FS_DELETE | |
16826 | + | FS_CREATE | FS_EVENT_ON_CHILD); | |
7f207e10 | 16827 | +static DECLARE_WAIT_QUEUE_HEAD(au_hfsn_wq); |
7eafdf33 | 16828 | +static __cacheline_aligned_in_smp atomic64_t au_hfsn_ifree = ATOMIC64_INIT(0); |
1facf9fc | 16829 | + |
0c5527e5 | 16830 | +static void au_hfsn_free_mark(struct fsnotify_mark *mark) |
1facf9fc | 16831 | +{ |
0c5527e5 AM |
16832 | + struct au_hnotify *hn = container_of(mark, struct au_hnotify, |
16833 | + hn_mark); | |
5afbbe0d | 16834 | + /* AuDbg("here\n"); */ |
1c60b727 | 16835 | + au_cache_free_hnotify(hn); |
8b6a4947 | 16836 | + smp_mb__before_atomic(); /* for atomic64_dec */ |
1716fcea AM |
16837 | + if (atomic64_dec_and_test(&au_hfsn_ifree)) |
16838 | + wake_up(&au_hfsn_wq); | |
4a4d8108 | 16839 | +} |
1facf9fc | 16840 | + |
027c5e7a | 16841 | +static int au_hfsn_alloc(struct au_hinode *hinode) |
4a4d8108 | 16842 | +{ |
1716fcea | 16843 | + int err; |
027c5e7a AM |
16844 | + struct au_hnotify *hn; |
16845 | + struct super_block *sb; | |
16846 | + struct au_branch *br; | |
0c5527e5 | 16847 | + struct fsnotify_mark *mark; |
027c5e7a | 16848 | + aufs_bindex_t bindex; |
1facf9fc | 16849 | + |
027c5e7a AM |
16850 | + hn = hinode->hi_notify; |
16851 | + sb = hn->hn_aufs_inode->i_sb; | |
16852 | + bindex = au_br_index(sb, hinode->hi_id); | |
16853 | + br = au_sbr(sb, bindex); | |
1716fcea AM |
16854 | + AuDebugOn(!br->br_hfsn); |
16855 | + | |
0c5527e5 | 16856 | + mark = &hn->hn_mark; |
ffa93bbd | 16857 | + fsnotify_init_mark(mark, br->br_hfsn->hfsn_group); |
0c5527e5 | 16858 | + mark->mask = AuHfsnMask; |
7f207e10 AM |
16859 | + /* |
16860 | + * by udba rename or rmdir, aufs assign a new inode to the known | |
16861 | + * h_inode, so specify 1 to allow dups. | |
16862 | + */ | |
c1595e42 | 16863 | + lockdep_off(); |
acd2b654 | 16864 | + err = fsnotify_add_inode_mark(mark, hinode->hi_inode, /*allow_dups*/1); |
c1595e42 | 16865 | + lockdep_on(); |
1716fcea AM |
16866 | + |
16867 | + return err; | |
1facf9fc | 16868 | +} |
16869 | + | |
7eafdf33 | 16870 | +static int au_hfsn_free(struct au_hinode *hinode, struct au_hnotify *hn) |
1facf9fc | 16871 | +{ |
0c5527e5 | 16872 | + struct fsnotify_mark *mark; |
7eafdf33 | 16873 | + unsigned long long ull; |
1716fcea | 16874 | + struct fsnotify_group *group; |
7eafdf33 AM |
16875 | + |
16876 | + ull = atomic64_inc_return(&au_hfsn_ifree); | |
16877 | + BUG_ON(!ull); | |
953406b4 | 16878 | + |
0c5527e5 | 16879 | + mark = &hn->hn_mark; |
1716fcea AM |
16880 | + spin_lock(&mark->lock); |
16881 | + group = mark->group; | |
16882 | + fsnotify_get_group(group); | |
16883 | + spin_unlock(&mark->lock); | |
c1595e42 | 16884 | + lockdep_off(); |
1716fcea | 16885 | + fsnotify_destroy_mark(mark, group); |
5afbbe0d | 16886 | + fsnotify_put_mark(mark); |
1716fcea | 16887 | + fsnotify_put_group(group); |
c1595e42 | 16888 | + lockdep_on(); |
7f207e10 | 16889 | + |
7eafdf33 AM |
16890 | + /* free hn by myself */ |
16891 | + return 0; | |
1facf9fc | 16892 | +} |
16893 | + | |
16894 | +/* ---------------------------------------------------------------------- */ | |
16895 | + | |
4a4d8108 | 16896 | +static void au_hfsn_ctl(struct au_hinode *hinode, int do_set) |
1facf9fc | 16897 | +{ |
0c5527e5 | 16898 | + struct fsnotify_mark *mark; |
1facf9fc | 16899 | + |
0c5527e5 AM |
16900 | + mark = &hinode->hi_notify->hn_mark; |
16901 | + spin_lock(&mark->lock); | |
1facf9fc | 16902 | + if (do_set) { |
0c5527e5 AM |
16903 | + AuDebugOn(mark->mask & AuHfsnMask); |
16904 | + mark->mask |= AuHfsnMask; | |
1facf9fc | 16905 | + } else { |
0c5527e5 AM |
16906 | + AuDebugOn(!(mark->mask & AuHfsnMask)); |
16907 | + mark->mask &= ~AuHfsnMask; | |
1facf9fc | 16908 | + } |
0c5527e5 | 16909 | + spin_unlock(&mark->lock); |
4a4d8108 | 16910 | + /* fsnotify_recalc_inode_mask(hinode->hi_inode); */ |
1facf9fc | 16911 | +} |
16912 | + | |
4a4d8108 | 16913 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 16914 | + |
4a4d8108 AM |
16915 | +/* #define AuDbgHnotify */ |
16916 | +#ifdef AuDbgHnotify | |
16917 | +static char *au_hfsn_name(u32 mask) | |
16918 | +{ | |
16919 | +#ifdef CONFIG_AUFS_DEBUG | |
c06a8ce3 AM |
16920 | +#define test_ret(flag) \ |
16921 | + do { \ | |
16922 | + if (mask & flag) \ | |
16923 | + return #flag; \ | |
16924 | + } while (0) | |
4a4d8108 AM |
16925 | + test_ret(FS_ACCESS); |
16926 | + test_ret(FS_MODIFY); | |
16927 | + test_ret(FS_ATTRIB); | |
16928 | + test_ret(FS_CLOSE_WRITE); | |
16929 | + test_ret(FS_CLOSE_NOWRITE); | |
16930 | + test_ret(FS_OPEN); | |
16931 | + test_ret(FS_MOVED_FROM); | |
16932 | + test_ret(FS_MOVED_TO); | |
16933 | + test_ret(FS_CREATE); | |
16934 | + test_ret(FS_DELETE); | |
16935 | + test_ret(FS_DELETE_SELF); | |
16936 | + test_ret(FS_MOVE_SELF); | |
16937 | + test_ret(FS_UNMOUNT); | |
16938 | + test_ret(FS_Q_OVERFLOW); | |
16939 | + test_ret(FS_IN_IGNORED); | |
b912730e | 16940 | + test_ret(FS_ISDIR); |
4a4d8108 AM |
16941 | + test_ret(FS_IN_ONESHOT); |
16942 | + test_ret(FS_EVENT_ON_CHILD); | |
16943 | + return ""; | |
16944 | +#undef test_ret | |
16945 | +#else | |
16946 | + return "??"; | |
16947 | +#endif | |
1facf9fc | 16948 | +} |
4a4d8108 | 16949 | +#endif |
1facf9fc | 16950 | + |
16951 | +/* ---------------------------------------------------------------------- */ | |
16952 | + | |
1716fcea AM |
16953 | +static void au_hfsn_free_group(struct fsnotify_group *group) |
16954 | +{ | |
16955 | + struct au_br_hfsnotify *hfsn = group->private; | |
16956 | + | |
5afbbe0d | 16957 | + /* AuDbg("here\n"); */ |
9f237c51 | 16958 | + au_kfree_try_rcu(hfsn); |
1716fcea AM |
16959 | +} |
16960 | + | |
4a4d8108 | 16961 | +static int au_hfsn_handle_event(struct fsnotify_group *group, |
fb47a38f | 16962 | + struct inode *inode, |
a2654f78 | 16963 | + u32 mask, const void *data, int data_type, |
83b672a5 | 16964 | + const struct qstr *file_name, u32 cookie, |
ffa93bbd | 16965 | + struct fsnotify_iter_info *iter_info) |
1facf9fc | 16966 | +{ |
16967 | + int err; | |
4a4d8108 AM |
16968 | + struct au_hnotify *hnotify; |
16969 | + struct inode *h_dir, *h_inode; | |
cd7a4cd9 | 16970 | + struct fsnotify_mark *inode_mark; |
4a4d8108 | 16971 | + |
fb47a38f | 16972 | + AuDebugOn(data_type != FSNOTIFY_EVENT_INODE); |
1facf9fc | 16973 | + |
16974 | + err = 0; | |
0c5527e5 | 16975 | + /* if FS_UNMOUNT happens, there must be another bug */ |
4a4d8108 | 16976 | + AuDebugOn(mask & FS_UNMOUNT); |
0c5527e5 | 16977 | + if (mask & (FS_IN_IGNORED | FS_UNMOUNT)) |
1facf9fc | 16978 | + goto out; |
1facf9fc | 16979 | + |
fb47a38f JR |
16980 | + h_dir = inode; |
16981 | + h_inode = NULL; | |
4a4d8108 | 16982 | +#ifdef AuDbgHnotify |
392086de | 16983 | + au_debug_on(); |
fbc438ed JR |
16984 | + if (1 || h_child_qstr.len != sizeof(AUFS_XINO_FNAME) - 1 |
16985 | + || strncmp(h_child_qstr.name, AUFS_XINO_FNAME, h_child_qstr.len)) { | |
4a4d8108 AM |
16986 | + AuDbg("i%lu, mask 0x%x %s, hcname %.*s, hi%lu\n", |
16987 | + h_dir->i_ino, mask, au_hfsn_name(mask), | |
fbc438ed | 16988 | + AuLNPair(&h_child_qstr), h_inode ? h_inode->i_ino : 0); |
4a4d8108 | 16989 | + /* WARN_ON(1); */ |
1facf9fc | 16990 | + } |
392086de | 16991 | + au_debug_off(); |
1facf9fc | 16992 | +#endif |
4a4d8108 | 16993 | + |
cd7a4cd9 | 16994 | + inode_mark = fsnotify_iter_inode_mark(iter_info); |
0c5527e5 AM |
16995 | + AuDebugOn(!inode_mark); |
16996 | + hnotify = container_of(inode_mark, struct au_hnotify, hn_mark); | |
b62f1e65 | 16997 | + err = au_hnotify(h_dir, hnotify, mask, file_name, h_inode); |
1facf9fc | 16998 | + |
4a4d8108 AM |
16999 | +out: |
17000 | + return err; | |
17001 | +} | |
1facf9fc | 17002 | + |
4a4d8108 | 17003 | +static struct fsnotify_ops au_hfsn_ops = { |
1716fcea | 17004 | + .handle_event = au_hfsn_handle_event, |
ffa93bbd AM |
17005 | + .free_group_priv = au_hfsn_free_group, |
17006 | + .free_mark = au_hfsn_free_mark | |
4a4d8108 AM |
17007 | +}; |
17008 | + | |
17009 | +/* ---------------------------------------------------------------------- */ | |
17010 | + | |
027c5e7a AM |
17011 | +static void au_hfsn_fin_br(struct au_branch *br) |
17012 | +{ | |
1716fcea | 17013 | + struct au_br_hfsnotify *hfsn; |
027c5e7a | 17014 | + |
1716fcea | 17015 | + hfsn = br->br_hfsn; |
c1595e42 JR |
17016 | + if (hfsn) { |
17017 | + lockdep_off(); | |
1716fcea | 17018 | + fsnotify_put_group(hfsn->hfsn_group); |
c1595e42 JR |
17019 | + lockdep_on(); |
17020 | + } | |
027c5e7a AM |
17021 | +} |
17022 | + | |
1716fcea | 17023 | +static int au_hfsn_init_br(struct au_branch *br, int perm) |
4a4d8108 AM |
17024 | +{ |
17025 | + int err; | |
1716fcea AM |
17026 | + struct fsnotify_group *group; |
17027 | + struct au_br_hfsnotify *hfsn; | |
1facf9fc | 17028 | + |
4a4d8108 | 17029 | + err = 0; |
1716fcea AM |
17030 | + br->br_hfsn = NULL; |
17031 | + if (!au_br_hnotifyable(perm)) | |
027c5e7a | 17032 | + goto out; |
027c5e7a | 17033 | + |
1716fcea AM |
17034 | + err = -ENOMEM; |
17035 | + hfsn = kmalloc(sizeof(*hfsn), GFP_NOFS); | |
17036 | + if (unlikely(!hfsn)) | |
027c5e7a AM |
17037 | + goto out; |
17038 | + | |
1716fcea AM |
17039 | + err = 0; |
17040 | + group = fsnotify_alloc_group(&au_hfsn_ops); | |
17041 | + if (IS_ERR(group)) { | |
17042 | + err = PTR_ERR(group); | |
0c5527e5 | 17043 | + pr_err("fsnotify_alloc_group() failed, %d\n", err); |
1716fcea | 17044 | + goto out_hfsn; |
4a4d8108 | 17045 | + } |
1facf9fc | 17046 | + |
1716fcea AM |
17047 | + group->private = hfsn; |
17048 | + hfsn->hfsn_group = group; | |
17049 | + br->br_hfsn = hfsn; | |
17050 | + goto out; /* success */ | |
17051 | + | |
17052 | +out_hfsn: | |
9f237c51 | 17053 | + au_kfree_try_rcu(hfsn); |
027c5e7a | 17054 | +out: |
1716fcea AM |
17055 | + return err; |
17056 | +} | |
17057 | + | |
17058 | +static int au_hfsn_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
17059 | +{ | |
17060 | + int err; | |
17061 | + | |
17062 | + err = 0; | |
17063 | + if (!br->br_hfsn) | |
17064 | + err = au_hfsn_init_br(br, perm); | |
17065 | + | |
1facf9fc | 17066 | + return err; |
17067 | +} | |
17068 | + | |
7eafdf33 AM |
17069 | +/* ---------------------------------------------------------------------- */ |
17070 | + | |
17071 | +static void au_hfsn_fin(void) | |
17072 | +{ | |
17073 | + AuDbg("au_hfsn_ifree %lld\n", (long long)atomic64_read(&au_hfsn_ifree)); | |
17074 | + wait_event(au_hfsn_wq, !atomic64_read(&au_hfsn_ifree)); | |
17075 | +} | |
17076 | + | |
4a4d8108 AM |
17077 | +const struct au_hnotify_op au_hnotify_op = { |
17078 | + .ctl = au_hfsn_ctl, | |
17079 | + .alloc = au_hfsn_alloc, | |
17080 | + .free = au_hfsn_free, | |
1facf9fc | 17081 | + |
7eafdf33 AM |
17082 | + .fin = au_hfsn_fin, |
17083 | + | |
027c5e7a AM |
17084 | + .reset_br = au_hfsn_reset_br, |
17085 | + .fin_br = au_hfsn_fin_br, | |
17086 | + .init_br = au_hfsn_init_br | |
4a4d8108 | 17087 | +}; |
7f207e10 | 17088 | diff -urN /usr/share/empty/fs/aufs/hfsplus.c linux/fs/aufs/hfsplus.c |
eca34b5c | 17089 | --- /usr/share/empty/fs/aufs/hfsplus.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 17090 | +++ linux/fs/aufs/hfsplus.c 2020-01-27 10:57:18.172204883 +0100 |
acd2b654 | 17091 | @@ -0,0 +1,60 @@ |
cd7a4cd9 | 17092 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 17093 | +/* |
d58c55f2 | 17094 | + * Copyright (C) 2010-2020 Junjiro R. Okajima |
4a4d8108 AM |
17095 | + * |
17096 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17097 | + * it under the terms of the GNU General Public License as published by | |
17098 | + * the Free Software Foundation; either version 2 of the License, or | |
17099 | + * (at your option) any later version. | |
17100 | + * | |
17101 | + * This program is distributed in the hope that it will be useful, | |
17102 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17103 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17104 | + * GNU General Public License for more details. | |
17105 | + * | |
17106 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17107 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 17108 | + */ |
1facf9fc | 17109 | + |
4a4d8108 | 17110 | +/* |
acd2b654 | 17111 | + * special support for filesystems which acquires an inode mutex |
4a4d8108 AM |
17112 | + * at final closing a file, eg, hfsplus. |
17113 | + * | |
17114 | + * This trick is very simple and stupid, just to open the file before really | |
acd2b654 | 17115 | + * necessary open to tell hfsplus that this is not the final closing. |
4a4d8108 AM |
17116 | + * The caller should call au_h_open_pre() after acquiring the inode mutex, |
17117 | + * and au_h_open_post() after releasing it. | |
17118 | + */ | |
1facf9fc | 17119 | + |
4a4d8108 | 17120 | +#include "aufs.h" |
1facf9fc | 17121 | + |
392086de AM |
17122 | +struct file *au_h_open_pre(struct dentry *dentry, aufs_bindex_t bindex, |
17123 | + int force_wr) | |
4a4d8108 AM |
17124 | +{ |
17125 | + struct file *h_file; | |
17126 | + struct dentry *h_dentry; | |
1facf9fc | 17127 | + |
4a4d8108 AM |
17128 | + h_dentry = au_h_dptr(dentry, bindex); |
17129 | + AuDebugOn(!h_dentry); | |
5527c038 | 17130 | + AuDebugOn(d_is_negative(h_dentry)); |
4a4d8108 AM |
17131 | + |
17132 | + h_file = NULL; | |
17133 | + if (au_test_hfsplus(h_dentry->d_sb) | |
7e9cd9fe | 17134 | + && d_is_reg(h_dentry)) |
4a4d8108 AM |
17135 | + h_file = au_h_open(dentry, bindex, |
17136 | + O_RDONLY | O_NOATIME | O_LARGEFILE, | |
392086de | 17137 | + /*file*/NULL, force_wr); |
4a4d8108 | 17138 | + return h_file; |
1facf9fc | 17139 | +} |
17140 | + | |
4a4d8108 AM |
17141 | +void au_h_open_post(struct dentry *dentry, aufs_bindex_t bindex, |
17142 | + struct file *h_file) | |
17143 | +{ | |
acd2b654 AM |
17144 | + struct au_branch *br; |
17145 | + | |
4a4d8108 AM |
17146 | + if (h_file) { |
17147 | + fput(h_file); | |
acd2b654 AM |
17148 | + br = au_sbr(dentry->d_sb, bindex); |
17149 | + au_lcnt_dec(&br->br_nfiles); | |
4a4d8108 AM |
17150 | + } |
17151 | +} | |
7f207e10 | 17152 | diff -urN /usr/share/empty/fs/aufs/hnotify.c linux/fs/aufs/hnotify.c |
eca34b5c | 17153 | --- /usr/share/empty/fs/aufs/hnotify.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 17154 | +++ linux/fs/aufs/hnotify.c 2020-01-27 10:57:18.172204883 +0100 |
43982f53 | 17155 | @@ -0,0 +1,715 @@ |
cd7a4cd9 | 17156 | +// SPDX-License-Identifier: GPL-2.0 |
e49829fe | 17157 | +/* |
d58c55f2 | 17158 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
e49829fe JR |
17159 | + * |
17160 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17161 | + * it under the terms of the GNU General Public License as published by | |
17162 | + * the Free Software Foundation; either version 2 of the License, or | |
17163 | + * (at your option) any later version. | |
17164 | + * | |
17165 | + * This program is distributed in the hope that it will be useful, | |
17166 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17167 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17168 | + * GNU General Public License for more details. | |
17169 | + * | |
17170 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17171 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
17172 | + */ |
17173 | + | |
17174 | +/* | |
7f207e10 | 17175 | + * abstraction to notify the direct changes on lower directories |
e49829fe JR |
17176 | + */ |
17177 | + | |
eca801bf | 17178 | +/* #include <linux/iversion.h> */ |
e49829fe JR |
17179 | +#include "aufs.h" |
17180 | + | |
027c5e7a | 17181 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode) |
e49829fe JR |
17182 | +{ |
17183 | + int err; | |
7f207e10 | 17184 | + struct au_hnotify *hn; |
1facf9fc | 17185 | + |
4a4d8108 AM |
17186 | + err = -ENOMEM; |
17187 | + hn = au_cache_alloc_hnotify(); | |
17188 | + if (hn) { | |
17189 | + hn->hn_aufs_inode = inode; | |
027c5e7a AM |
17190 | + hinode->hi_notify = hn; |
17191 | + err = au_hnotify_op.alloc(hinode); | |
17192 | + AuTraceErr(err); | |
17193 | + if (unlikely(err)) { | |
17194 | + hinode->hi_notify = NULL; | |
1c60b727 | 17195 | + au_cache_free_hnotify(hn); |
4a4d8108 AM |
17196 | + /* |
17197 | + * The upper dir was removed by udba, but the same named | |
acd2b654 | 17198 | + * dir left. In this case, aufs assigns a new inode |
4a4d8108 | 17199 | + * number and set the monitor again. |
acd2b654 | 17200 | + * For the lower dir, the old monitor is still left. |
4a4d8108 AM |
17201 | + */ |
17202 | + if (err == -EEXIST) | |
17203 | + err = 0; | |
17204 | + } | |
1308ab2a | 17205 | + } |
1308ab2a | 17206 | + |
027c5e7a | 17207 | + AuTraceErr(err); |
1308ab2a | 17208 | + return err; |
dece6358 | 17209 | +} |
1facf9fc | 17210 | + |
4a4d8108 | 17211 | +void au_hn_free(struct au_hinode *hinode) |
dece6358 | 17212 | +{ |
4a4d8108 | 17213 | + struct au_hnotify *hn; |
1facf9fc | 17214 | + |
4a4d8108 AM |
17215 | + hn = hinode->hi_notify; |
17216 | + if (hn) { | |
4a4d8108 | 17217 | + hinode->hi_notify = NULL; |
7eafdf33 | 17218 | + if (au_hnotify_op.free(hinode, hn)) |
1c60b727 | 17219 | + au_cache_free_hnotify(hn); |
4a4d8108 AM |
17220 | + } |
17221 | +} | |
dece6358 | 17222 | + |
4a4d8108 | 17223 | +/* ---------------------------------------------------------------------- */ |
dece6358 | 17224 | + |
4a4d8108 AM |
17225 | +void au_hn_ctl(struct au_hinode *hinode, int do_set) |
17226 | +{ | |
17227 | + if (hinode->hi_notify) | |
17228 | + au_hnotify_op.ctl(hinode, do_set); | |
17229 | +} | |
17230 | + | |
17231 | +void au_hn_reset(struct inode *inode, unsigned int flags) | |
17232 | +{ | |
5afbbe0d | 17233 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
17234 | + struct inode *hi; |
17235 | + struct dentry *iwhdentry; | |
1facf9fc | 17236 | + |
5afbbe0d AM |
17237 | + bbot = au_ibbot(inode); |
17238 | + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) { | |
4a4d8108 AM |
17239 | + hi = au_h_iptr(inode, bindex); |
17240 | + if (!hi) | |
17241 | + continue; | |
1308ab2a | 17242 | + |
febd17d6 | 17243 | + /* inode_lock_nested(hi, AuLsc_I_CHILD); */ |
4a4d8108 AM |
17244 | + iwhdentry = au_hi_wh(inode, bindex); |
17245 | + if (iwhdentry) | |
17246 | + dget(iwhdentry); | |
17247 | + au_igrab(hi); | |
17248 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
17249 | + au_set_h_iptr(inode, bindex, au_igrab(hi), | |
17250 | + flags & ~AuHi_XINO); | |
17251 | + iput(hi); | |
17252 | + dput(iwhdentry); | |
febd17d6 | 17253 | + /* inode_unlock(hi); */ |
1facf9fc | 17254 | + } |
1facf9fc | 17255 | +} |
17256 | + | |
1308ab2a | 17257 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17258 | + |
4a4d8108 | 17259 | +static int hn_xino(struct inode *inode, struct inode *h_inode) |
1facf9fc | 17260 | +{ |
4a4d8108 | 17261 | + int err; |
5afbbe0d | 17262 | + aufs_bindex_t bindex, bbot, bfound, btop; |
4a4d8108 | 17263 | + struct inode *h_i; |
1facf9fc | 17264 | + |
4a4d8108 AM |
17265 | + err = 0; |
17266 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 17267 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
17268 | + goto out; |
17269 | + } | |
1facf9fc | 17270 | + |
4a4d8108 | 17271 | + bfound = -1; |
5afbbe0d AM |
17272 | + bbot = au_ibbot(inode); |
17273 | + btop = au_ibtop(inode); | |
4a4d8108 | 17274 | +#if 0 /* reserved for future use */ |
5afbbe0d | 17275 | + if (bindex == bbot) { |
4a4d8108 AM |
17276 | + /* keep this ino in rename case */ |
17277 | + goto out; | |
17278 | + } | |
17279 | +#endif | |
5afbbe0d | 17280 | + for (bindex = btop; bindex <= bbot; bindex++) |
4a4d8108 AM |
17281 | + if (au_h_iptr(inode, bindex) == h_inode) { |
17282 | + bfound = bindex; | |
17283 | + break; | |
17284 | + } | |
17285 | + if (bfound < 0) | |
1308ab2a | 17286 | + goto out; |
1facf9fc | 17287 | + |
5afbbe0d | 17288 | + for (bindex = btop; bindex <= bbot; bindex++) { |
4a4d8108 AM |
17289 | + h_i = au_h_iptr(inode, bindex); |
17290 | + if (!h_i) | |
17291 | + continue; | |
1facf9fc | 17292 | + |
4a4d8108 AM |
17293 | + err = au_xino_write(inode->i_sb, bindex, h_i->i_ino, /*ino*/0); |
17294 | + /* ignore this error */ | |
17295 | + /* bad action? */ | |
1facf9fc | 17296 | + } |
1facf9fc | 17297 | + |
4a4d8108 | 17298 | + /* children inode number will be broken */ |
1facf9fc | 17299 | + |
4f0767ce | 17300 | +out: |
4a4d8108 AM |
17301 | + AuTraceErr(err); |
17302 | + return err; | |
1facf9fc | 17303 | +} |
17304 | + | |
4a4d8108 | 17305 | +static int hn_gen_tree(struct dentry *dentry) |
1facf9fc | 17306 | +{ |
4a4d8108 AM |
17307 | + int err, i, j, ndentry; |
17308 | + struct au_dcsub_pages dpages; | |
17309 | + struct au_dpage *dpage; | |
17310 | + struct dentry **dentries; | |
1facf9fc | 17311 | + |
4a4d8108 AM |
17312 | + err = au_dpages_init(&dpages, GFP_NOFS); |
17313 | + if (unlikely(err)) | |
17314 | + goto out; | |
17315 | + err = au_dcsub_pages(&dpages, dentry, NULL, NULL); | |
17316 | + if (unlikely(err)) | |
17317 | + goto out_dpages; | |
1facf9fc | 17318 | + |
4a4d8108 AM |
17319 | + for (i = 0; i < dpages.ndpage; i++) { |
17320 | + dpage = dpages.dpages + i; | |
17321 | + dentries = dpage->dentries; | |
17322 | + ndentry = dpage->ndentry; | |
17323 | + for (j = 0; j < ndentry; j++) { | |
17324 | + struct dentry *d; | |
17325 | + | |
17326 | + d = dentries[j]; | |
17327 | + if (IS_ROOT(d)) | |
17328 | + continue; | |
17329 | + | |
4a4d8108 | 17330 | + au_digen_dec(d); |
5527c038 | 17331 | + if (d_really_is_positive(d)) |
4a4d8108 AM |
17332 | + /* todo: reset children xino? |
17333 | + cached children only? */ | |
5527c038 | 17334 | + au_iigen_dec(d_inode(d)); |
1308ab2a | 17335 | + } |
dece6358 | 17336 | + } |
1facf9fc | 17337 | + |
4f0767ce | 17338 | +out_dpages: |
4a4d8108 | 17339 | + au_dpages_free(&dpages); |
4f0767ce | 17340 | +out: |
dece6358 AM |
17341 | + return err; |
17342 | +} | |
17343 | + | |
1308ab2a | 17344 | +/* |
4a4d8108 | 17345 | + * return 0 if processed. |
1308ab2a | 17346 | + */ |
4a4d8108 AM |
17347 | +static int hn_gen_by_inode(char *name, unsigned int nlen, struct inode *inode, |
17348 | + const unsigned int isdir) | |
dece6358 | 17349 | +{ |
1308ab2a | 17350 | + int err; |
4a4d8108 AM |
17351 | + struct dentry *d; |
17352 | + struct qstr *dname; | |
1facf9fc | 17353 | + |
4a4d8108 AM |
17354 | + err = 1; |
17355 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 17356 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
17357 | + err = 0; |
17358 | + goto out; | |
17359 | + } | |
dece6358 | 17360 | + |
4a4d8108 AM |
17361 | + if (!isdir) { |
17362 | + AuDebugOn(!name); | |
17363 | + au_iigen_dec(inode); | |
027c5e7a | 17364 | + spin_lock(&inode->i_lock); |
c1595e42 | 17365 | + hlist_for_each_entry(d, &inode->i_dentry, d_u.d_alias) { |
027c5e7a | 17366 | + spin_lock(&d->d_lock); |
4a4d8108 AM |
17367 | + dname = &d->d_name; |
17368 | + if (dname->len != nlen | |
027c5e7a AM |
17369 | + && memcmp(dname->name, name, nlen)) { |
17370 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 17371 | + continue; |
027c5e7a | 17372 | + } |
4a4d8108 | 17373 | + err = 0; |
4a4d8108 AM |
17374 | + au_digen_dec(d); |
17375 | + spin_unlock(&d->d_lock); | |
17376 | + break; | |
1facf9fc | 17377 | + } |
027c5e7a | 17378 | + spin_unlock(&inode->i_lock); |
1308ab2a | 17379 | + } else { |
027c5e7a | 17380 | + au_fset_si(au_sbi(inode->i_sb), FAILED_REFRESH_DIR); |
c1595e42 | 17381 | + d = d_find_any_alias(inode); |
4a4d8108 AM |
17382 | + if (!d) { |
17383 | + au_iigen_dec(inode); | |
17384 | + goto out; | |
17385 | + } | |
1facf9fc | 17386 | + |
027c5e7a | 17387 | + spin_lock(&d->d_lock); |
4a4d8108 | 17388 | + dname = &d->d_name; |
027c5e7a AM |
17389 | + if (dname->len == nlen && !memcmp(dname->name, name, nlen)) { |
17390 | + spin_unlock(&d->d_lock); | |
4a4d8108 | 17391 | + err = hn_gen_tree(d); |
027c5e7a AM |
17392 | + spin_lock(&d->d_lock); |
17393 | + } | |
17394 | + spin_unlock(&d->d_lock); | |
4a4d8108 AM |
17395 | + dput(d); |
17396 | + } | |
1facf9fc | 17397 | + |
4f0767ce | 17398 | +out: |
4a4d8108 | 17399 | + AuTraceErr(err); |
1308ab2a | 17400 | + return err; |
17401 | +} | |
dece6358 | 17402 | + |
4a4d8108 | 17403 | +static int hn_gen_by_name(struct dentry *dentry, const unsigned int isdir) |
1facf9fc | 17404 | +{ |
4a4d8108 | 17405 | + int err; |
1facf9fc | 17406 | + |
5527c038 | 17407 | + if (IS_ROOT(dentry)) { |
0c3ec466 | 17408 | + pr_warn("branch root dir was changed\n"); |
4a4d8108 AM |
17409 | + return 0; |
17410 | + } | |
1308ab2a | 17411 | + |
4a4d8108 AM |
17412 | + err = 0; |
17413 | + if (!isdir) { | |
4a4d8108 | 17414 | + au_digen_dec(dentry); |
5527c038 JR |
17415 | + if (d_really_is_positive(dentry)) |
17416 | + au_iigen_dec(d_inode(dentry)); | |
4a4d8108 | 17417 | + } else { |
027c5e7a | 17418 | + au_fset_si(au_sbi(dentry->d_sb), FAILED_REFRESH_DIR); |
5527c038 | 17419 | + if (d_really_is_positive(dentry)) |
4a4d8108 AM |
17420 | + err = hn_gen_tree(dentry); |
17421 | + } | |
17422 | + | |
17423 | + AuTraceErr(err); | |
17424 | + return err; | |
1facf9fc | 17425 | +} |
17426 | + | |
4a4d8108 | 17427 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17428 | + |
4a4d8108 AM |
17429 | +/* hnotify job flags */ |
17430 | +#define AuHnJob_XINO0 1 | |
17431 | +#define AuHnJob_GEN (1 << 1) | |
17432 | +#define AuHnJob_DIRENT (1 << 2) | |
17433 | +#define AuHnJob_ISDIR (1 << 3) | |
17434 | +#define AuHnJob_TRYXINO0 (1 << 4) | |
17435 | +#define AuHnJob_MNTPNT (1 << 5) | |
17436 | +#define au_ftest_hnjob(flags, name) ((flags) & AuHnJob_##name) | |
7f207e10 AM |
17437 | +#define au_fset_hnjob(flags, name) \ |
17438 | + do { (flags) |= AuHnJob_##name; } while (0) | |
17439 | +#define au_fclr_hnjob(flags, name) \ | |
17440 | + do { (flags) &= ~AuHnJob_##name; } while (0) | |
1facf9fc | 17441 | + |
4a4d8108 AM |
17442 | +enum { |
17443 | + AuHn_CHILD, | |
17444 | + AuHn_PARENT, | |
17445 | + AuHnLast | |
17446 | +}; | |
1facf9fc | 17447 | + |
4a4d8108 AM |
17448 | +struct au_hnotify_args { |
17449 | + struct inode *h_dir, *dir, *h_child_inode; | |
17450 | + u32 mask; | |
17451 | + unsigned int flags[AuHnLast]; | |
17452 | + unsigned int h_child_nlen; | |
17453 | + char h_child_name[]; | |
17454 | +}; | |
1facf9fc | 17455 | + |
4a4d8108 AM |
17456 | +struct hn_job_args { |
17457 | + unsigned int flags; | |
17458 | + struct inode *inode, *h_inode, *dir, *h_dir; | |
17459 | + struct dentry *dentry; | |
17460 | + char *h_name; | |
17461 | + int h_nlen; | |
17462 | +}; | |
1308ab2a | 17463 | + |
4a4d8108 AM |
17464 | +static int hn_job(struct hn_job_args *a) |
17465 | +{ | |
17466 | + const unsigned int isdir = au_ftest_hnjob(a->flags, ISDIR); | |
076b876e | 17467 | + int e; |
1308ab2a | 17468 | + |
4a4d8108 AM |
17469 | + /* reset xino */ |
17470 | + if (au_ftest_hnjob(a->flags, XINO0) && a->inode) | |
17471 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ | |
1308ab2a | 17472 | + |
4a4d8108 AM |
17473 | + if (au_ftest_hnjob(a->flags, TRYXINO0) |
17474 | + && a->inode | |
17475 | + && a->h_inode) { | |
be118d29 | 17476 | + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD); |
38d290e6 JR |
17477 | + if (!a->h_inode->i_nlink |
17478 | + && !(a->h_inode->i_state & I_LINKABLE)) | |
4a4d8108 | 17479 | + hn_xino(a->inode, a->h_inode); /* ignore this error */ |
3c1bdaff | 17480 | + inode_unlock_shared(a->h_inode); |
1308ab2a | 17481 | + } |
1facf9fc | 17482 | + |
4a4d8108 AM |
17483 | + /* make the generation obsolete */ |
17484 | + if (au_ftest_hnjob(a->flags, GEN)) { | |
076b876e | 17485 | + e = -1; |
4a4d8108 | 17486 | + if (a->inode) |
076b876e | 17487 | + e = hn_gen_by_inode(a->h_name, a->h_nlen, a->inode, |
4a4d8108 | 17488 | + isdir); |
076b876e | 17489 | + if (e && a->dentry) |
4a4d8108 AM |
17490 | + hn_gen_by_name(a->dentry, isdir); |
17491 | + /* ignore this error */ | |
1facf9fc | 17492 | + } |
1facf9fc | 17493 | + |
4a4d8108 AM |
17494 | + /* make dir entries obsolete */ |
17495 | + if (au_ftest_hnjob(a->flags, DIRENT) && a->inode) { | |
17496 | + struct au_vdir *vdir; | |
1facf9fc | 17497 | + |
4a4d8108 AM |
17498 | + vdir = au_ivdir(a->inode); |
17499 | + if (vdir) | |
17500 | + vdir->vd_jiffy = 0; | |
17501 | + /* IMustLock(a->inode); */ | |
be118d29 | 17502 | + /* inode_inc_iversion(a->inode); */ |
4a4d8108 | 17503 | + } |
1facf9fc | 17504 | + |
4a4d8108 AM |
17505 | + /* can do nothing but warn */ |
17506 | + if (au_ftest_hnjob(a->flags, MNTPNT) | |
17507 | + && a->dentry | |
17508 | + && d_mountpoint(a->dentry)) | |
523b37e3 | 17509 | + pr_warn("mount-point %pd is removed or renamed\n", a->dentry); |
1facf9fc | 17510 | + |
4a4d8108 | 17511 | + return 0; |
1308ab2a | 17512 | +} |
1facf9fc | 17513 | + |
1308ab2a | 17514 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 17515 | + |
4a4d8108 AM |
17516 | +static struct dentry *lookup_wlock_by_name(char *name, unsigned int nlen, |
17517 | + struct inode *dir) | |
1308ab2a | 17518 | +{ |
4a4d8108 AM |
17519 | + struct dentry *dentry, *d, *parent; |
17520 | + struct qstr *dname; | |
1308ab2a | 17521 | + |
c1595e42 | 17522 | + parent = d_find_any_alias(dir); |
4a4d8108 AM |
17523 | + if (!parent) |
17524 | + return NULL; | |
1308ab2a | 17525 | + |
4a4d8108 | 17526 | + dentry = NULL; |
027c5e7a | 17527 | + spin_lock(&parent->d_lock); |
c1595e42 | 17528 | + list_for_each_entry(d, &parent->d_subdirs, d_child) { |
523b37e3 | 17529 | + /* AuDbg("%pd\n", d); */ |
027c5e7a | 17530 | + spin_lock_nested(&d->d_lock, DENTRY_D_LOCK_NESTED); |
4a4d8108 AM |
17531 | + dname = &d->d_name; |
17532 | + if (dname->len != nlen || memcmp(dname->name, name, nlen)) | |
027c5e7a AM |
17533 | + goto cont_unlock; |
17534 | + if (au_di(d)) | |
17535 | + au_digen_dec(d); | |
17536 | + else | |
17537 | + goto cont_unlock; | |
c1595e42 | 17538 | + if (au_dcount(d) > 0) { |
027c5e7a | 17539 | + dentry = dget_dlock(d); |
4a4d8108 | 17540 | + spin_unlock(&d->d_lock); |
027c5e7a | 17541 | + break; |
dece6358 | 17542 | + } |
1facf9fc | 17543 | + |
f6b6e03d | 17544 | +cont_unlock: |
027c5e7a | 17545 | + spin_unlock(&d->d_lock); |
1308ab2a | 17546 | + } |
027c5e7a | 17547 | + spin_unlock(&parent->d_lock); |
4a4d8108 | 17548 | + dput(parent); |
1facf9fc | 17549 | + |
4a4d8108 AM |
17550 | + if (dentry) |
17551 | + di_write_lock_child(dentry); | |
1308ab2a | 17552 | + |
4a4d8108 AM |
17553 | + return dentry; |
17554 | +} | |
dece6358 | 17555 | + |
4a4d8108 AM |
17556 | +static struct inode *lookup_wlock_by_ino(struct super_block *sb, |
17557 | + aufs_bindex_t bindex, ino_t h_ino) | |
17558 | +{ | |
17559 | + struct inode *inode; | |
17560 | + ino_t ino; | |
17561 | + int err; | |
17562 | + | |
17563 | + inode = NULL; | |
17564 | + err = au_xino_read(sb, bindex, h_ino, &ino); | |
17565 | + if (!err && ino) | |
17566 | + inode = ilookup(sb, ino); | |
17567 | + if (!inode) | |
17568 | + goto out; | |
17569 | + | |
17570 | + if (unlikely(inode->i_ino == AUFS_ROOT_INO)) { | |
0c3ec466 | 17571 | + pr_warn("wrong root branch\n"); |
4a4d8108 AM |
17572 | + iput(inode); |
17573 | + inode = NULL; | |
17574 | + goto out; | |
1308ab2a | 17575 | + } |
17576 | + | |
4a4d8108 | 17577 | + ii_write_lock_child(inode); |
1308ab2a | 17578 | + |
4f0767ce | 17579 | +out: |
4a4d8108 | 17580 | + return inode; |
dece6358 AM |
17581 | +} |
17582 | + | |
4a4d8108 | 17583 | +static void au_hn_bh(void *_args) |
1facf9fc | 17584 | +{ |
4a4d8108 AM |
17585 | + struct au_hnotify_args *a = _args; |
17586 | + struct super_block *sb; | |
5afbbe0d | 17587 | + aufs_bindex_t bindex, bbot, bfound; |
4a4d8108 | 17588 | + unsigned char xino, try_iput; |
1facf9fc | 17589 | + int err; |
1308ab2a | 17590 | + struct inode *inode; |
4a4d8108 AM |
17591 | + ino_t h_ino; |
17592 | + struct hn_job_args args; | |
17593 | + struct dentry *dentry; | |
17594 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 17595 | + |
4a4d8108 AM |
17596 | + AuDebugOn(!_args); |
17597 | + AuDebugOn(!a->h_dir); | |
17598 | + AuDebugOn(!a->dir); | |
17599 | + AuDebugOn(!a->mask); | |
17600 | + AuDbg("mask 0x%x, i%lu, hi%lu, hci%lu\n", | |
17601 | + a->mask, a->dir->i_ino, a->h_dir->i_ino, | |
17602 | + a->h_child_inode ? a->h_child_inode->i_ino : 0); | |
1facf9fc | 17603 | + |
4a4d8108 AM |
17604 | + inode = NULL; |
17605 | + dentry = NULL; | |
17606 | + /* | |
17607 | + * do not lock a->dir->i_mutex here | |
17608 | + * because of d_revalidate() may cause a deadlock. | |
17609 | + */ | |
17610 | + sb = a->dir->i_sb; | |
17611 | + AuDebugOn(!sb); | |
17612 | + sbinfo = au_sbi(sb); | |
17613 | + AuDebugOn(!sbinfo); | |
7f207e10 | 17614 | + si_write_lock(sb, AuLock_NOPLMW); |
1facf9fc | 17615 | + |
8b6a4947 AM |
17616 | + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) |
17617 | + switch (a->mask & FS_EVENTS_POSS_ON_CHILD) { | |
17618 | + case FS_MOVED_FROM: | |
17619 | + case FS_MOVED_TO: | |
17620 | + AuWarn1("DIRREN with UDBA may not work correctly " | |
17621 | + "for the direct rename(2)\n"); | |
17622 | + } | |
17623 | + | |
4a4d8108 AM |
17624 | + ii_read_lock_parent(a->dir); |
17625 | + bfound = -1; | |
5afbbe0d AM |
17626 | + bbot = au_ibbot(a->dir); |
17627 | + for (bindex = au_ibtop(a->dir); bindex <= bbot; bindex++) | |
4a4d8108 AM |
17628 | + if (au_h_iptr(a->dir, bindex) == a->h_dir) { |
17629 | + bfound = bindex; | |
17630 | + break; | |
17631 | + } | |
17632 | + ii_read_unlock(a->dir); | |
17633 | + if (unlikely(bfound < 0)) | |
17634 | + goto out; | |
1facf9fc | 17635 | + |
4a4d8108 AM |
17636 | + xino = !!au_opt_test(au_mntflags(sb), XINO); |
17637 | + h_ino = 0; | |
17638 | + if (a->h_child_inode) | |
17639 | + h_ino = a->h_child_inode->i_ino; | |
1facf9fc | 17640 | + |
4a4d8108 AM |
17641 | + if (a->h_child_nlen |
17642 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], GEN) | |
17643 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], MNTPNT))) | |
17644 | + dentry = lookup_wlock_by_name(a->h_child_name, a->h_child_nlen, | |
17645 | + a->dir); | |
17646 | + try_iput = 0; | |
5527c038 JR |
17647 | + if (dentry && d_really_is_positive(dentry)) |
17648 | + inode = d_inode(dentry); | |
4a4d8108 AM |
17649 | + if (xino && !inode && h_ino |
17650 | + && (au_ftest_hnjob(a->flags[AuHn_CHILD], XINO0) | |
17651 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], TRYXINO0) | |
17652 | + || au_ftest_hnjob(a->flags[AuHn_CHILD], GEN))) { | |
17653 | + inode = lookup_wlock_by_ino(sb, bfound, h_ino); | |
17654 | + try_iput = 1; | |
f0c0a007 | 17655 | + } |
1facf9fc | 17656 | + |
4a4d8108 AM |
17657 | + args.flags = a->flags[AuHn_CHILD]; |
17658 | + args.dentry = dentry; | |
17659 | + args.inode = inode; | |
17660 | + args.h_inode = a->h_child_inode; | |
17661 | + args.dir = a->dir; | |
17662 | + args.h_dir = a->h_dir; | |
17663 | + args.h_name = a->h_child_name; | |
17664 | + args.h_nlen = a->h_child_nlen; | |
17665 | + err = hn_job(&args); | |
17666 | + if (dentry) { | |
027c5e7a | 17667 | + if (au_di(dentry)) |
4a4d8108 AM |
17668 | + di_write_unlock(dentry); |
17669 | + dput(dentry); | |
17670 | + } | |
17671 | + if (inode && try_iput) { | |
17672 | + ii_write_unlock(inode); | |
17673 | + iput(inode); | |
17674 | + } | |
1facf9fc | 17675 | + |
4a4d8108 AM |
17676 | + ii_write_lock_parent(a->dir); |
17677 | + args.flags = a->flags[AuHn_PARENT]; | |
17678 | + args.dentry = NULL; | |
17679 | + args.inode = a->dir; | |
17680 | + args.h_inode = a->h_dir; | |
17681 | + args.dir = NULL; | |
17682 | + args.h_dir = NULL; | |
17683 | + args.h_name = NULL; | |
17684 | + args.h_nlen = 0; | |
17685 | + err = hn_job(&args); | |
17686 | + ii_write_unlock(a->dir); | |
1facf9fc | 17687 | + |
4f0767ce | 17688 | +out: |
4a4d8108 AM |
17689 | + iput(a->h_child_inode); |
17690 | + iput(a->h_dir); | |
17691 | + iput(a->dir); | |
027c5e7a AM |
17692 | + si_write_unlock(sb); |
17693 | + au_nwt_done(&sbinfo->si_nowait); | |
9f237c51 | 17694 | + au_kfree_rcu(a); |
dece6358 | 17695 | +} |
1facf9fc | 17696 | + |
4a4d8108 AM |
17697 | +/* ---------------------------------------------------------------------- */ |
17698 | + | |
17699 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
b62f1e65 | 17700 | + const struct qstr *h_child_qstr, struct inode *h_child_inode) |
dece6358 | 17701 | +{ |
4a4d8108 | 17702 | + int err, len; |
53392da6 | 17703 | + unsigned int flags[AuHnLast], f; |
4a4d8108 AM |
17704 | + unsigned char isdir, isroot, wh; |
17705 | + struct inode *dir; | |
17706 | + struct au_hnotify_args *args; | |
17707 | + char *p, *h_child_name; | |
dece6358 | 17708 | + |
1308ab2a | 17709 | + err = 0; |
4a4d8108 AM |
17710 | + AuDebugOn(!hnotify || !hnotify->hn_aufs_inode); |
17711 | + dir = igrab(hnotify->hn_aufs_inode); | |
17712 | + if (!dir) | |
17713 | + goto out; | |
1facf9fc | 17714 | + |
4a4d8108 AM |
17715 | + isroot = (dir->i_ino == AUFS_ROOT_INO); |
17716 | + wh = 0; | |
17717 | + h_child_name = (void *)h_child_qstr->name; | |
17718 | + len = h_child_qstr->len; | |
17719 | + if (h_child_name) { | |
17720 | + if (len > AUFS_WH_PFX_LEN | |
17721 | + && !memcmp(h_child_name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { | |
17722 | + h_child_name += AUFS_WH_PFX_LEN; | |
17723 | + len -= AUFS_WH_PFX_LEN; | |
17724 | + wh = 1; | |
17725 | + } | |
1facf9fc | 17726 | + } |
dece6358 | 17727 | + |
4a4d8108 AM |
17728 | + isdir = 0; |
17729 | + if (h_child_inode) | |
17730 | + isdir = !!S_ISDIR(h_child_inode->i_mode); | |
17731 | + flags[AuHn_PARENT] = AuHnJob_ISDIR; | |
17732 | + flags[AuHn_CHILD] = 0; | |
17733 | + if (isdir) | |
17734 | + flags[AuHn_CHILD] = AuHnJob_ISDIR; | |
17735 | + au_fset_hnjob(flags[AuHn_PARENT], DIRENT); | |
17736 | + au_fset_hnjob(flags[AuHn_CHILD], GEN); | |
fbc438ed | 17737 | + switch (mask & ALL_FSNOTIFY_DIRENT_EVENTS) { |
4a4d8108 AM |
17738 | + case FS_MOVED_FROM: |
17739 | + case FS_MOVED_TO: | |
17740 | + au_fset_hnjob(flags[AuHn_CHILD], XINO0); | |
17741 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
17742 | + /*FALLTHROUGH*/ | |
17743 | + case FS_CREATE: | |
fb47a38f | 17744 | + AuDebugOn(!h_child_name); |
4a4d8108 | 17745 | + break; |
1facf9fc | 17746 | + |
4a4d8108 AM |
17747 | + case FS_DELETE: |
17748 | + /* | |
17749 | + * aufs never be able to get this child inode. | |
17750 | + * revalidation should be in d_revalidate() | |
17751 | + * by checking i_nlink, i_generation or d_unhashed(). | |
17752 | + */ | |
17753 | + AuDebugOn(!h_child_name); | |
17754 | + au_fset_hnjob(flags[AuHn_CHILD], TRYXINO0); | |
17755 | + au_fset_hnjob(flags[AuHn_CHILD], MNTPNT); | |
17756 | + break; | |
dece6358 | 17757 | + |
4a4d8108 AM |
17758 | + default: |
17759 | + AuDebugOn(1); | |
17760 | + } | |
1308ab2a | 17761 | + |
4a4d8108 AM |
17762 | + if (wh) |
17763 | + h_child_inode = NULL; | |
1308ab2a | 17764 | + |
4a4d8108 AM |
17765 | + err = -ENOMEM; |
17766 | + /* iput() and kfree() will be called in au_hnotify() */ | |
4a4d8108 | 17767 | + args = kmalloc(sizeof(*args) + len + 1, GFP_NOFS); |
4a4d8108 AM |
17768 | + if (unlikely(!args)) { |
17769 | + AuErr1("no memory\n"); | |
17770 | + iput(dir); | |
17771 | + goto out; | |
17772 | + } | |
17773 | + args->flags[AuHn_PARENT] = flags[AuHn_PARENT]; | |
17774 | + args->flags[AuHn_CHILD] = flags[AuHn_CHILD]; | |
17775 | + args->mask = mask; | |
17776 | + args->dir = dir; | |
17777 | + args->h_dir = igrab(h_dir); | |
17778 | + if (h_child_inode) | |
17779 | + h_child_inode = igrab(h_child_inode); /* can be NULL */ | |
17780 | + args->h_child_inode = h_child_inode; | |
17781 | + args->h_child_nlen = len; | |
17782 | + if (len) { | |
17783 | + p = (void *)args; | |
17784 | + p += sizeof(*args); | |
17785 | + memcpy(p, h_child_name, len); | |
17786 | + p[len] = 0; | |
1308ab2a | 17787 | + } |
1308ab2a | 17788 | + |
38d290e6 | 17789 | + /* NFS fires the event for silly-renamed one from kworker */ |
53392da6 | 17790 | + f = 0; |
38d290e6 JR |
17791 | + if (!dir->i_nlink |
17792 | + || (au_test_nfs(h_dir->i_sb) && (mask & FS_DELETE))) | |
53392da6 AM |
17793 | + f = AuWkq_NEST; |
17794 | + err = au_wkq_nowait(au_hn_bh, args, dir->i_sb, f); | |
4a4d8108 AM |
17795 | + if (unlikely(err)) { |
17796 | + pr_err("wkq %d\n", err); | |
17797 | + iput(args->h_child_inode); | |
17798 | + iput(args->h_dir); | |
17799 | + iput(args->dir); | |
9f237c51 | 17800 | + au_kfree_rcu(args); |
1facf9fc | 17801 | + } |
1facf9fc | 17802 | + |
4a4d8108 | 17803 | +out: |
1facf9fc | 17804 | + return err; |
17805 | +} | |
17806 | + | |
027c5e7a AM |
17807 | +/* ---------------------------------------------------------------------- */ |
17808 | + | |
17809 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm) | |
17810 | +{ | |
17811 | + int err; | |
17812 | + | |
17813 | + AuDebugOn(!(udba & AuOptMask_UDBA)); | |
17814 | + | |
17815 | + err = 0; | |
17816 | + if (au_hnotify_op.reset_br) | |
17817 | + err = au_hnotify_op.reset_br(udba, br, perm); | |
17818 | + | |
17819 | + return err; | |
17820 | +} | |
17821 | + | |
17822 | +int au_hnotify_init_br(struct au_branch *br, int perm) | |
17823 | +{ | |
17824 | + int err; | |
17825 | + | |
17826 | + err = 0; | |
17827 | + if (au_hnotify_op.init_br) | |
17828 | + err = au_hnotify_op.init_br(br, perm); | |
17829 | + | |
17830 | + return err; | |
17831 | +} | |
17832 | + | |
17833 | +void au_hnotify_fin_br(struct au_branch *br) | |
17834 | +{ | |
17835 | + if (au_hnotify_op.fin_br) | |
17836 | + au_hnotify_op.fin_br(br); | |
17837 | +} | |
17838 | + | |
4a4d8108 AM |
17839 | +static void au_hn_destroy_cache(void) |
17840 | +{ | |
1c60b727 AM |
17841 | + kmem_cache_destroy(au_cache[AuCache_HNOTIFY]); |
17842 | + au_cache[AuCache_HNOTIFY] = NULL; | |
4a4d8108 | 17843 | +} |
1308ab2a | 17844 | + |
4a4d8108 | 17845 | +int __init au_hnotify_init(void) |
1facf9fc | 17846 | +{ |
1308ab2a | 17847 | + int err; |
1308ab2a | 17848 | + |
4a4d8108 | 17849 | + err = -ENOMEM; |
1c60b727 AM |
17850 | + au_cache[AuCache_HNOTIFY] = AuCache(au_hnotify); |
17851 | + if (au_cache[AuCache_HNOTIFY]) { | |
027c5e7a AM |
17852 | + err = 0; |
17853 | + if (au_hnotify_op.init) | |
17854 | + err = au_hnotify_op.init(); | |
4a4d8108 AM |
17855 | + if (unlikely(err)) |
17856 | + au_hn_destroy_cache(); | |
1308ab2a | 17857 | + } |
1308ab2a | 17858 | + AuTraceErr(err); |
4a4d8108 | 17859 | + return err; |
1308ab2a | 17860 | +} |
17861 | + | |
4a4d8108 | 17862 | +void au_hnotify_fin(void) |
1308ab2a | 17863 | +{ |
027c5e7a AM |
17864 | + if (au_hnotify_op.fin) |
17865 | + au_hnotify_op.fin(); | |
f0c0a007 | 17866 | + |
4a4d8108 | 17867 | + /* cf. au_cache_fin() */ |
1c60b727 | 17868 | + if (au_cache[AuCache_HNOTIFY]) |
4a4d8108 | 17869 | + au_hn_destroy_cache(); |
dece6358 | 17870 | +} |
7f207e10 | 17871 | diff -urN /usr/share/empty/fs/aufs/iinfo.c linux/fs/aufs/iinfo.c |
eca34b5c | 17872 | --- /usr/share/empty/fs/aufs/iinfo.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 17873 | +++ linux/fs/aufs/iinfo.c 2020-01-27 10:57:18.175538316 +0100 |
062440b3 | 17874 | @@ -0,0 +1,286 @@ |
cd7a4cd9 | 17875 | +// SPDX-License-Identifier: GPL-2.0 |
dece6358 | 17876 | +/* |
d58c55f2 | 17877 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
dece6358 AM |
17878 | + * |
17879 | + * This program, aufs is free software; you can redistribute it and/or modify | |
17880 | + * it under the terms of the GNU General Public License as published by | |
17881 | + * the Free Software Foundation; either version 2 of the License, or | |
17882 | + * (at your option) any later version. | |
17883 | + * | |
17884 | + * This program is distributed in the hope that it will be useful, | |
17885 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17886 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17887 | + * GNU General Public License for more details. | |
17888 | + * | |
17889 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 17890 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 | 17891 | + */ |
1facf9fc | 17892 | + |
dece6358 | 17893 | +/* |
4a4d8108 | 17894 | + * inode private data |
dece6358 | 17895 | + */ |
1facf9fc | 17896 | + |
1308ab2a | 17897 | +#include "aufs.h" |
1facf9fc | 17898 | + |
4a4d8108 | 17899 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 17900 | +{ |
4a4d8108 | 17901 | + struct inode *h_inode; |
5afbbe0d | 17902 | + struct au_hinode *hinode; |
1facf9fc | 17903 | + |
4a4d8108 | 17904 | + IiMustAnyLock(inode); |
1facf9fc | 17905 | + |
5afbbe0d AM |
17906 | + hinode = au_hinode(au_ii(inode), bindex); |
17907 | + h_inode = hinode->hi_inode; | |
4a4d8108 AM |
17908 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); |
17909 | + return h_inode; | |
17910 | +} | |
1facf9fc | 17911 | + |
4a4d8108 AM |
17912 | +/* todo: hard/soft set? */ |
17913 | +void au_hiput(struct au_hinode *hinode) | |
17914 | +{ | |
17915 | + au_hn_free(hinode); | |
17916 | + dput(hinode->hi_whdentry); | |
17917 | + iput(hinode->hi_inode); | |
17918 | +} | |
1facf9fc | 17919 | + |
4a4d8108 AM |
17920 | +unsigned int au_hi_flags(struct inode *inode, int isdir) |
17921 | +{ | |
17922 | + unsigned int flags; | |
17923 | + const unsigned int mnt_flags = au_mntflags(inode->i_sb); | |
1facf9fc | 17924 | + |
4a4d8108 AM |
17925 | + flags = 0; |
17926 | + if (au_opt_test(mnt_flags, XINO)) | |
17927 | + au_fset_hi(flags, XINO); | |
17928 | + if (isdir && au_opt_test(mnt_flags, UDBA_HNOTIFY)) | |
17929 | + au_fset_hi(flags, HNOTIFY); | |
17930 | + return flags; | |
1facf9fc | 17931 | +} |
17932 | + | |
4a4d8108 AM |
17933 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
17934 | + struct inode *h_inode, unsigned int flags) | |
1308ab2a | 17935 | +{ |
4a4d8108 AM |
17936 | + struct au_hinode *hinode; |
17937 | + struct inode *hi; | |
17938 | + struct au_iinfo *iinfo = au_ii(inode); | |
1facf9fc | 17939 | + |
4a4d8108 | 17940 | + IiMustWriteLock(inode); |
dece6358 | 17941 | + |
5afbbe0d | 17942 | + hinode = au_hinode(iinfo, bindex); |
4a4d8108 AM |
17943 | + hi = hinode->hi_inode; |
17944 | + AuDebugOn(h_inode && atomic_read(&h_inode->i_count) <= 0); | |
17945 | + | |
17946 | + if (hi) | |
17947 | + au_hiput(hinode); | |
17948 | + hinode->hi_inode = h_inode; | |
17949 | + if (h_inode) { | |
17950 | + int err; | |
17951 | + struct super_block *sb = inode->i_sb; | |
17952 | + struct au_branch *br; | |
17953 | + | |
027c5e7a AM |
17954 | + AuDebugOn(inode->i_mode |
17955 | + && (h_inode->i_mode & S_IFMT) | |
17956 | + != (inode->i_mode & S_IFMT)); | |
5afbbe0d | 17957 | + if (bindex == iinfo->ii_btop) |
4a4d8108 AM |
17958 | + au_cpup_igen(inode, h_inode); |
17959 | + br = au_sbr(sb, bindex); | |
17960 | + hinode->hi_id = br->br_id; | |
17961 | + if (au_ftest_hi(flags, XINO)) { | |
17962 | + err = au_xino_write(sb, bindex, h_inode->i_ino, | |
17963 | + inode->i_ino); | |
17964 | + if (unlikely(err)) | |
17965 | + AuIOErr1("failed au_xino_write() %d\n", err); | |
17966 | + } | |
17967 | + | |
17968 | + if (au_ftest_hi(flags, HNOTIFY) | |
17969 | + && au_br_hnotifyable(br->br_perm)) { | |
027c5e7a | 17970 | + err = au_hn_alloc(hinode, inode); |
4a4d8108 AM |
17971 | + if (unlikely(err)) |
17972 | + AuIOErr1("au_hn_alloc() %d\n", err); | |
1308ab2a | 17973 | + } |
17974 | + } | |
4a4d8108 | 17975 | +} |
dece6358 | 17976 | + |
4a4d8108 AM |
17977 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, |
17978 | + struct dentry *h_wh) | |
17979 | +{ | |
17980 | + struct au_hinode *hinode; | |
dece6358 | 17981 | + |
4a4d8108 AM |
17982 | + IiMustWriteLock(inode); |
17983 | + | |
5afbbe0d | 17984 | + hinode = au_hinode(au_ii(inode), bindex); |
4a4d8108 AM |
17985 | + AuDebugOn(hinode->hi_whdentry); |
17986 | + hinode->hi_whdentry = h_wh; | |
1facf9fc | 17987 | +} |
17988 | + | |
537831f9 | 17989 | +void au_update_iigen(struct inode *inode, int half) |
1308ab2a | 17990 | +{ |
537831f9 AM |
17991 | + struct au_iinfo *iinfo; |
17992 | + struct au_iigen *iigen; | |
17993 | + unsigned int sigen; | |
17994 | + | |
17995 | + sigen = au_sigen(inode->i_sb); | |
17996 | + iinfo = au_ii(inode); | |
17997 | + iigen = &iinfo->ii_generation; | |
be52b249 | 17998 | + spin_lock(&iigen->ig_spin); |
537831f9 AM |
17999 | + iigen->ig_generation = sigen; |
18000 | + if (half) | |
18001 | + au_ig_fset(iigen->ig_flags, HALF_REFRESHED); | |
18002 | + else | |
18003 | + au_ig_fclr(iigen->ig_flags, HALF_REFRESHED); | |
be52b249 | 18004 | + spin_unlock(&iigen->ig_spin); |
4a4d8108 | 18005 | +} |
1facf9fc | 18006 | + |
4a4d8108 AM |
18007 | +/* it may be called at remount time, too */ |
18008 | +void au_update_ibrange(struct inode *inode, int do_put_zero) | |
18009 | +{ | |
18010 | + struct au_iinfo *iinfo; | |
5afbbe0d | 18011 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 18012 | + |
5afbbe0d | 18013 | + AuDebugOn(au_is_bad_inode(inode)); |
4a4d8108 | 18014 | + IiMustWriteLock(inode); |
1facf9fc | 18015 | + |
5afbbe0d AM |
18016 | + iinfo = au_ii(inode); |
18017 | + if (do_put_zero && iinfo->ii_btop >= 0) { | |
18018 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; | |
4a4d8108 AM |
18019 | + bindex++) { |
18020 | + struct inode *h_i; | |
1facf9fc | 18021 | + |
5afbbe0d | 18022 | + h_i = au_hinode(iinfo, bindex)->hi_inode; |
38d290e6 JR |
18023 | + if (h_i |
18024 | + && !h_i->i_nlink | |
18025 | + && !(h_i->i_state & I_LINKABLE)) | |
027c5e7a AM |
18026 | + au_set_h_iptr(inode, bindex, NULL, 0); |
18027 | + } | |
4a4d8108 AM |
18028 | + } |
18029 | + | |
5afbbe0d AM |
18030 | + iinfo->ii_btop = -1; |
18031 | + iinfo->ii_bbot = -1; | |
18032 | + bbot = au_sbbot(inode->i_sb); | |
18033 | + for (bindex = 0; bindex <= bbot; bindex++) | |
18034 | + if (au_hinode(iinfo, bindex)->hi_inode) { | |
18035 | + iinfo->ii_btop = bindex; | |
4a4d8108 | 18036 | + break; |
027c5e7a | 18037 | + } |
5afbbe0d AM |
18038 | + if (iinfo->ii_btop >= 0) |
18039 | + for (bindex = bbot; bindex >= iinfo->ii_btop; bindex--) | |
18040 | + if (au_hinode(iinfo, bindex)->hi_inode) { | |
18041 | + iinfo->ii_bbot = bindex; | |
027c5e7a AM |
18042 | + break; |
18043 | + } | |
5afbbe0d | 18044 | + AuDebugOn(iinfo->ii_btop > iinfo->ii_bbot); |
1308ab2a | 18045 | +} |
1facf9fc | 18046 | + |
dece6358 | 18047 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18048 | + |
4a4d8108 | 18049 | +void au_icntnr_init_once(void *_c) |
dece6358 | 18050 | +{ |
4a4d8108 AM |
18051 | + struct au_icntnr *c = _c; |
18052 | + struct au_iinfo *iinfo = &c->iinfo; | |
1facf9fc | 18053 | + |
be52b249 | 18054 | + spin_lock_init(&iinfo->ii_generation.ig_spin); |
4a4d8108 AM |
18055 | + au_rw_init(&iinfo->ii_rwsem); |
18056 | + inode_init_once(&c->vfs_inode); | |
18057 | +} | |
1facf9fc | 18058 | + |
5afbbe0d AM |
18059 | +void au_hinode_init(struct au_hinode *hinode) |
18060 | +{ | |
18061 | + hinode->hi_inode = NULL; | |
18062 | + hinode->hi_id = -1; | |
18063 | + au_hn_init(hinode); | |
18064 | + hinode->hi_whdentry = NULL; | |
18065 | +} | |
18066 | + | |
4a4d8108 AM |
18067 | +int au_iinfo_init(struct inode *inode) |
18068 | +{ | |
18069 | + struct au_iinfo *iinfo; | |
18070 | + struct super_block *sb; | |
5afbbe0d | 18071 | + struct au_hinode *hi; |
4a4d8108 | 18072 | + int nbr, i; |
1facf9fc | 18073 | + |
4a4d8108 AM |
18074 | + sb = inode->i_sb; |
18075 | + iinfo = &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
5afbbe0d | 18076 | + nbr = au_sbbot(sb) + 1; |
4a4d8108 AM |
18077 | + if (unlikely(nbr <= 0)) |
18078 | + nbr = 1; | |
5afbbe0d AM |
18079 | + hi = kmalloc_array(nbr, sizeof(*iinfo->ii_hinode), GFP_NOFS); |
18080 | + if (hi) { | |
acd2b654 | 18081 | + au_lcnt_inc(&au_sbi(sb)->si_ninodes); |
5afbbe0d AM |
18082 | + |
18083 | + iinfo->ii_hinode = hi; | |
18084 | + for (i = 0; i < nbr; i++, hi++) | |
18085 | + au_hinode_init(hi); | |
1facf9fc | 18086 | + |
537831f9 | 18087 | + iinfo->ii_generation.ig_generation = au_sigen(sb); |
5afbbe0d AM |
18088 | + iinfo->ii_btop = -1; |
18089 | + iinfo->ii_bbot = -1; | |
4a4d8108 AM |
18090 | + iinfo->ii_vdir = NULL; |
18091 | + return 0; | |
1308ab2a | 18092 | + } |
4a4d8108 AM |
18093 | + return -ENOMEM; |
18094 | +} | |
1facf9fc | 18095 | + |
e2f27e51 | 18096 | +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink) |
4a4d8108 | 18097 | +{ |
5afbbe0d | 18098 | + int err, i; |
4a4d8108 | 18099 | + struct au_hinode *hip; |
1facf9fc | 18100 | + |
4a4d8108 AM |
18101 | + AuRwMustWriteLock(&iinfo->ii_rwsem); |
18102 | + | |
18103 | + err = -ENOMEM; | |
e2f27e51 AM |
18104 | + hip = au_krealloc(iinfo->ii_hinode, sizeof(*hip) * nbr, GFP_NOFS, |
18105 | + may_shrink); | |
4a4d8108 AM |
18106 | + if (hip) { |
18107 | + iinfo->ii_hinode = hip; | |
5afbbe0d AM |
18108 | + i = iinfo->ii_bbot + 1; |
18109 | + hip += i; | |
18110 | + for (; i < nbr; i++, hip++) | |
18111 | + au_hinode_init(hip); | |
4a4d8108 | 18112 | + err = 0; |
1308ab2a | 18113 | + } |
4a4d8108 | 18114 | + |
1308ab2a | 18115 | + return err; |
1facf9fc | 18116 | +} |
18117 | + | |
4a4d8108 | 18118 | +void au_iinfo_fin(struct inode *inode) |
1facf9fc | 18119 | +{ |
4a4d8108 AM |
18120 | + struct au_iinfo *iinfo; |
18121 | + struct au_hinode *hi; | |
18122 | + struct super_block *sb; | |
5afbbe0d | 18123 | + aufs_bindex_t bindex, bbot; |
b752ccd1 | 18124 | + const unsigned char unlinked = !inode->i_nlink; |
1308ab2a | 18125 | + |
5afbbe0d | 18126 | + AuDebugOn(au_is_bad_inode(inode)); |
1308ab2a | 18127 | + |
b752ccd1 | 18128 | + sb = inode->i_sb; |
acd2b654 | 18129 | + au_lcnt_dec(&au_sbi(sb)->si_ninodes); |
b752ccd1 AM |
18130 | + if (si_pid_test(sb)) |
18131 | + au_xino_delete_inode(inode, unlinked); | |
18132 | + else { | |
18133 | + /* | |
18134 | + * it is safe to hide the dependency between sbinfo and | |
18135 | + * sb->s_umount. | |
18136 | + */ | |
18137 | + lockdep_off(); | |
18138 | + si_noflush_read_lock(sb); | |
18139 | + au_xino_delete_inode(inode, unlinked); | |
18140 | + si_read_unlock(sb); | |
18141 | + lockdep_on(); | |
18142 | + } | |
18143 | + | |
5afbbe0d | 18144 | + iinfo = au_ii(inode); |
4a4d8108 | 18145 | + if (iinfo->ii_vdir) |
1c60b727 | 18146 | + au_vdir_free(iinfo->ii_vdir); |
1308ab2a | 18147 | + |
5afbbe0d | 18148 | + bindex = iinfo->ii_btop; |
b752ccd1 | 18149 | + if (bindex >= 0) { |
5afbbe0d AM |
18150 | + hi = au_hinode(iinfo, bindex); |
18151 | + bbot = iinfo->ii_bbot; | |
18152 | + while (bindex++ <= bbot) { | |
b752ccd1 | 18153 | + if (hi->hi_inode) |
4a4d8108 | 18154 | + au_hiput(hi); |
4a4d8108 AM |
18155 | + hi++; |
18156 | + } | |
18157 | + } | |
9f237c51 | 18158 | + au_kfree_rcu(iinfo->ii_hinode); |
4a4d8108 | 18159 | + AuRwDestroy(&iinfo->ii_rwsem); |
dece6358 | 18160 | +} |
7f207e10 | 18161 | diff -urN /usr/share/empty/fs/aufs/inode.c linux/fs/aufs/inode.c |
eca34b5c | 18162 | --- /usr/share/empty/fs/aufs/inode.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 18163 | +++ linux/fs/aufs/inode.c 2020-01-27 10:57:18.175538316 +0100 |
eca801bf | 18164 | @@ -0,0 +1,529 @@ |
cd7a4cd9 | 18165 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 18166 | +/* |
d58c55f2 | 18167 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
18168 | + * |
18169 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18170 | + * it under the terms of the GNU General Public License as published by | |
18171 | + * the Free Software Foundation; either version 2 of the License, or | |
18172 | + * (at your option) any later version. | |
18173 | + * | |
18174 | + * This program is distributed in the hope that it will be useful, | |
18175 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18176 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18177 | + * GNU General Public License for more details. | |
18178 | + * | |
18179 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18180 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18181 | + */ |
1facf9fc | 18182 | + |
4a4d8108 AM |
18183 | +/* |
18184 | + * inode functions | |
18185 | + */ | |
1facf9fc | 18186 | + |
eca801bf | 18187 | +#include <linux/iversion.h> |
4a4d8108 | 18188 | +#include "aufs.h" |
1308ab2a | 18189 | + |
4a4d8108 AM |
18190 | +struct inode *au_igrab(struct inode *inode) |
18191 | +{ | |
18192 | + if (inode) { | |
18193 | + AuDebugOn(!atomic_read(&inode->i_count)); | |
027c5e7a | 18194 | + ihold(inode); |
1facf9fc | 18195 | + } |
4a4d8108 AM |
18196 | + return inode; |
18197 | +} | |
1facf9fc | 18198 | + |
4a4d8108 AM |
18199 | +static void au_refresh_hinode_attr(struct inode *inode, int do_version) |
18200 | +{ | |
18201 | + au_cpup_attr_all(inode, /*force*/0); | |
537831f9 | 18202 | + au_update_iigen(inode, /*half*/1); |
4a4d8108 | 18203 | + if (do_version) |
be118d29 | 18204 | + inode_inc_iversion(inode); |
dece6358 | 18205 | +} |
1facf9fc | 18206 | + |
027c5e7a | 18207 | +static int au_ii_refresh(struct inode *inode, int *update) |
dece6358 | 18208 | +{ |
e2f27e51 | 18209 | + int err, e, nbr; |
027c5e7a | 18210 | + umode_t type; |
4a4d8108 | 18211 | + aufs_bindex_t bindex, new_bindex; |
1308ab2a | 18212 | + struct super_block *sb; |
4a4d8108 | 18213 | + struct au_iinfo *iinfo; |
027c5e7a | 18214 | + struct au_hinode *p, *q, tmp; |
1facf9fc | 18215 | + |
5afbbe0d | 18216 | + AuDebugOn(au_is_bad_inode(inode)); |
4a4d8108 | 18217 | + IiMustWriteLock(inode); |
1facf9fc | 18218 | + |
027c5e7a | 18219 | + *update = 0; |
4a4d8108 | 18220 | + sb = inode->i_sb; |
e2f27e51 | 18221 | + nbr = au_sbbot(sb) + 1; |
027c5e7a | 18222 | + type = inode->i_mode & S_IFMT; |
4a4d8108 | 18223 | + iinfo = au_ii(inode); |
e2f27e51 | 18224 | + err = au_hinode_realloc(iinfo, nbr, /*may_shrink*/0); |
4a4d8108 | 18225 | + if (unlikely(err)) |
1308ab2a | 18226 | + goto out; |
1facf9fc | 18227 | + |
5afbbe0d AM |
18228 | + AuDebugOn(iinfo->ii_btop < 0); |
18229 | + p = au_hinode(iinfo, iinfo->ii_btop); | |
18230 | + for (bindex = iinfo->ii_btop; bindex <= iinfo->ii_bbot; | |
4a4d8108 AM |
18231 | + bindex++, p++) { |
18232 | + if (!p->hi_inode) | |
18233 | + continue; | |
1facf9fc | 18234 | + |
027c5e7a | 18235 | + AuDebugOn(type != (p->hi_inode->i_mode & S_IFMT)); |
4a4d8108 AM |
18236 | + new_bindex = au_br_index(sb, p->hi_id); |
18237 | + if (new_bindex == bindex) | |
18238 | + continue; | |
1facf9fc | 18239 | + |
4a4d8108 | 18240 | + if (new_bindex < 0) { |
027c5e7a | 18241 | + *update = 1; |
4a4d8108 AM |
18242 | + au_hiput(p); |
18243 | + p->hi_inode = NULL; | |
18244 | + continue; | |
1308ab2a | 18245 | + } |
4a4d8108 | 18246 | + |
5afbbe0d AM |
18247 | + if (new_bindex < iinfo->ii_btop) |
18248 | + iinfo->ii_btop = new_bindex; | |
18249 | + if (iinfo->ii_bbot < new_bindex) | |
18250 | + iinfo->ii_bbot = new_bindex; | |
4a4d8108 | 18251 | + /* swap two lower inode, and loop again */ |
5afbbe0d | 18252 | + q = au_hinode(iinfo, new_bindex); |
4a4d8108 AM |
18253 | + tmp = *q; |
18254 | + *q = *p; | |
18255 | + *p = tmp; | |
18256 | + if (tmp.hi_inode) { | |
18257 | + bindex--; | |
18258 | + p--; | |
1308ab2a | 18259 | + } |
18260 | + } | |
4a4d8108 | 18261 | + au_update_ibrange(inode, /*do_put_zero*/0); |
e2f27e51 | 18262 | + au_hinode_realloc(iinfo, nbr, /*may_shrink*/1); /* harmless if err */ |
4a4d8108 AM |
18263 | + e = au_dy_irefresh(inode); |
18264 | + if (unlikely(e && !err)) | |
18265 | + err = e; | |
1facf9fc | 18266 | + |
4f0767ce | 18267 | +out: |
027c5e7a AM |
18268 | + AuTraceErr(err); |
18269 | + return err; | |
18270 | +} | |
18271 | + | |
b95c5147 AM |
18272 | +void au_refresh_iop(struct inode *inode, int force_getattr) |
18273 | +{ | |
18274 | + int type; | |
18275 | + struct au_sbinfo *sbi = au_sbi(inode->i_sb); | |
18276 | + const struct inode_operations *iop | |
18277 | + = force_getattr ? aufs_iop : sbi->si_iop_array; | |
18278 | + | |
18279 | + if (inode->i_op == iop) | |
18280 | + return; | |
18281 | + | |
18282 | + switch (inode->i_mode & S_IFMT) { | |
18283 | + case S_IFDIR: | |
18284 | + type = AuIop_DIR; | |
18285 | + break; | |
18286 | + case S_IFLNK: | |
18287 | + type = AuIop_SYMLINK; | |
18288 | + break; | |
18289 | + default: | |
18290 | + type = AuIop_OTHER; | |
18291 | + break; | |
18292 | + } | |
18293 | + | |
18294 | + inode->i_op = iop + type; | |
18295 | + /* unnecessary smp_wmb() */ | |
18296 | +} | |
18297 | + | |
027c5e7a AM |
18298 | +int au_refresh_hinode_self(struct inode *inode) |
18299 | +{ | |
18300 | + int err, update; | |
18301 | + | |
18302 | + err = au_ii_refresh(inode, &update); | |
18303 | + if (!err) | |
18304 | + au_refresh_hinode_attr(inode, update && S_ISDIR(inode->i_mode)); | |
18305 | + | |
18306 | + AuTraceErr(err); | |
4a4d8108 AM |
18307 | + return err; |
18308 | +} | |
1facf9fc | 18309 | + |
4a4d8108 AM |
18310 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry) |
18311 | +{ | |
027c5e7a | 18312 | + int err, e, update; |
4a4d8108 | 18313 | + unsigned int flags; |
027c5e7a | 18314 | + umode_t mode; |
5afbbe0d | 18315 | + aufs_bindex_t bindex, bbot; |
027c5e7a | 18316 | + unsigned char isdir; |
4a4d8108 AM |
18317 | + struct au_hinode *p; |
18318 | + struct au_iinfo *iinfo; | |
1facf9fc | 18319 | + |
027c5e7a | 18320 | + err = au_ii_refresh(inode, &update); |
4a4d8108 AM |
18321 | + if (unlikely(err)) |
18322 | + goto out; | |
18323 | + | |
18324 | + update = 0; | |
18325 | + iinfo = au_ii(inode); | |
5afbbe0d | 18326 | + p = au_hinode(iinfo, iinfo->ii_btop); |
027c5e7a AM |
18327 | + mode = (inode->i_mode & S_IFMT); |
18328 | + isdir = S_ISDIR(mode); | |
4a4d8108 | 18329 | + flags = au_hi_flags(inode, isdir); |
5afbbe0d AM |
18330 | + bbot = au_dbbot(dentry); |
18331 | + for (bindex = au_dbtop(dentry); bindex <= bbot; bindex++) { | |
5527c038 | 18332 | + struct inode *h_i, *h_inode; |
4a4d8108 AM |
18333 | + struct dentry *h_d; |
18334 | + | |
18335 | + h_d = au_h_dptr(dentry, bindex); | |
5527c038 | 18336 | + if (!h_d || d_is_negative(h_d)) |
4a4d8108 AM |
18337 | + continue; |
18338 | + | |
5527c038 JR |
18339 | + h_inode = d_inode(h_d); |
18340 | + AuDebugOn(mode != (h_inode->i_mode & S_IFMT)); | |
5afbbe0d | 18341 | + if (iinfo->ii_btop <= bindex && bindex <= iinfo->ii_bbot) { |
4a4d8108 AM |
18342 | + h_i = au_h_iptr(inode, bindex); |
18343 | + if (h_i) { | |
5527c038 | 18344 | + if (h_i == h_inode) |
4a4d8108 AM |
18345 | + continue; |
18346 | + err = -EIO; | |
18347 | + break; | |
18348 | + } | |
18349 | + } | |
5afbbe0d AM |
18350 | + if (bindex < iinfo->ii_btop) |
18351 | + iinfo->ii_btop = bindex; | |
18352 | + if (iinfo->ii_bbot < bindex) | |
18353 | + iinfo->ii_bbot = bindex; | |
5527c038 | 18354 | + au_set_h_iptr(inode, bindex, au_igrab(h_inode), flags); |
4a4d8108 | 18355 | + update = 1; |
1308ab2a | 18356 | + } |
4a4d8108 AM |
18357 | + au_update_ibrange(inode, /*do_put_zero*/0); |
18358 | + e = au_dy_irefresh(inode); | |
18359 | + if (unlikely(e && !err)) | |
18360 | + err = e; | |
027c5e7a AM |
18361 | + if (!err) |
18362 | + au_refresh_hinode_attr(inode, update && isdir); | |
4a4d8108 | 18363 | + |
4f0767ce | 18364 | +out: |
4a4d8108 | 18365 | + AuTraceErr(err); |
1308ab2a | 18366 | + return err; |
dece6358 AM |
18367 | +} |
18368 | + | |
4a4d8108 | 18369 | +static int set_inode(struct inode *inode, struct dentry *dentry) |
dece6358 | 18370 | +{ |
4a4d8108 AM |
18371 | + int err; |
18372 | + unsigned int flags; | |
18373 | + umode_t mode; | |
5afbbe0d | 18374 | + aufs_bindex_t bindex, btop, btail; |
4a4d8108 AM |
18375 | + unsigned char isdir; |
18376 | + struct dentry *h_dentry; | |
18377 | + struct inode *h_inode; | |
18378 | + struct au_iinfo *iinfo; | |
43982f53 | 18379 | + const struct inode_operations *iop; |
dece6358 | 18380 | + |
4a4d8108 | 18381 | + IiMustWriteLock(inode); |
dece6358 | 18382 | + |
4a4d8108 AM |
18383 | + err = 0; |
18384 | + isdir = 0; | |
b95c5147 | 18385 | + iop = au_sbi(inode->i_sb)->si_iop_array; |
5afbbe0d AM |
18386 | + btop = au_dbtop(dentry); |
18387 | + h_dentry = au_h_dptr(dentry, btop); | |
5527c038 | 18388 | + h_inode = d_inode(h_dentry); |
4a4d8108 AM |
18389 | + mode = h_inode->i_mode; |
18390 | + switch (mode & S_IFMT) { | |
18391 | + case S_IFREG: | |
18392 | + btail = au_dbtail(dentry); | |
b95c5147 | 18393 | + inode->i_op = iop + AuIop_OTHER; |
4a4d8108 | 18394 | + inode->i_fop = &aufs_file_fop; |
5afbbe0d | 18395 | + err = au_dy_iaop(inode, btop, h_inode); |
4a4d8108 AM |
18396 | + if (unlikely(err)) |
18397 | + goto out; | |
18398 | + break; | |
18399 | + case S_IFDIR: | |
18400 | + isdir = 1; | |
18401 | + btail = au_dbtaildir(dentry); | |
b95c5147 | 18402 | + inode->i_op = iop + AuIop_DIR; |
4a4d8108 AM |
18403 | + inode->i_fop = &aufs_dir_fop; |
18404 | + break; | |
18405 | + case S_IFLNK: | |
18406 | + btail = au_dbtail(dentry); | |
b95c5147 | 18407 | + inode->i_op = iop + AuIop_SYMLINK; |
4a4d8108 AM |
18408 | + break; |
18409 | + case S_IFBLK: | |
18410 | + case S_IFCHR: | |
18411 | + case S_IFIFO: | |
18412 | + case S_IFSOCK: | |
18413 | + btail = au_dbtail(dentry); | |
b95c5147 | 18414 | + inode->i_op = iop + AuIop_OTHER; |
38d290e6 | 18415 | + init_special_inode(inode, mode, h_inode->i_rdev); |
4a4d8108 AM |
18416 | + break; |
18417 | + default: | |
18418 | + AuIOErr("Unknown file type 0%o\n", mode); | |
18419 | + err = -EIO; | |
1308ab2a | 18420 | + goto out; |
4a4d8108 | 18421 | + } |
dece6358 | 18422 | + |
4a4d8108 AM |
18423 | + /* do not set hnotify for whiteouted dirs (SHWH mode) */ |
18424 | + flags = au_hi_flags(inode, isdir); | |
18425 | + if (au_opt_test(au_mntflags(dentry->d_sb), SHWH) | |
18426 | + && au_ftest_hi(flags, HNOTIFY) | |
18427 | + && dentry->d_name.len > AUFS_WH_PFX_LEN | |
18428 | + && !memcmp(dentry->d_name.name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) | |
18429 | + au_fclr_hi(flags, HNOTIFY); | |
18430 | + iinfo = au_ii(inode); | |
5afbbe0d AM |
18431 | + iinfo->ii_btop = btop; |
18432 | + iinfo->ii_bbot = btail; | |
18433 | + for (bindex = btop; bindex <= btail; bindex++) { | |
4a4d8108 AM |
18434 | + h_dentry = au_h_dptr(dentry, bindex); |
18435 | + if (h_dentry) | |
18436 | + au_set_h_iptr(inode, bindex, | |
5527c038 | 18437 | + au_igrab(d_inode(h_dentry)), flags); |
4a4d8108 AM |
18438 | + } |
18439 | + au_cpup_attr_all(inode, /*force*/1); | |
c1595e42 JR |
18440 | + /* |
18441 | + * to force calling aufs_get_acl() every time, | |
18442 | + * do not call cache_no_acl() for aufs inode. | |
18443 | + */ | |
dece6358 | 18444 | + |
4f0767ce | 18445 | +out: |
4a4d8108 AM |
18446 | + return err; |
18447 | +} | |
dece6358 | 18448 | + |
027c5e7a AM |
18449 | +/* |
18450 | + * successful returns with iinfo write_locked | |
18451 | + * minus: errno | |
18452 | + * zero: success, matched | |
18453 | + * plus: no error, but unmatched | |
18454 | + */ | |
18455 | +static int reval_inode(struct inode *inode, struct dentry *dentry) | |
4a4d8108 AM |
18456 | +{ |
18457 | + int err; | |
cfc41e69 | 18458 | + unsigned int gen, igflags; |
5afbbe0d | 18459 | + aufs_bindex_t bindex, bbot; |
4a4d8108 | 18460 | + struct inode *h_inode, *h_dinode; |
5527c038 | 18461 | + struct dentry *h_dentry; |
dece6358 | 18462 | + |
4a4d8108 AM |
18463 | + /* |
18464 | + * before this function, if aufs got any iinfo lock, it must be only | |
18465 | + * one, the parent dir. | |
18466 | + * it can happen by UDBA and the obsoleted inode number. | |
18467 | + */ | |
18468 | + err = -EIO; | |
18469 | + if (unlikely(inode->i_ino == parent_ino(dentry))) | |
18470 | + goto out; | |
18471 | + | |
027c5e7a | 18472 | + err = 1; |
4a4d8108 | 18473 | + ii_write_lock_new_child(inode); |
5afbbe0d | 18474 | + h_dentry = au_h_dptr(dentry, au_dbtop(dentry)); |
5527c038 | 18475 | + h_dinode = d_inode(h_dentry); |
5afbbe0d AM |
18476 | + bbot = au_ibbot(inode); |
18477 | + for (bindex = au_ibtop(inode); bindex <= bbot; bindex++) { | |
4a4d8108 | 18478 | + h_inode = au_h_iptr(inode, bindex); |
537831f9 AM |
18479 | + if (!h_inode || h_inode != h_dinode) |
18480 | + continue; | |
18481 | + | |
18482 | + err = 0; | |
cfc41e69 | 18483 | + gen = au_iigen(inode, &igflags); |
537831f9 | 18484 | + if (gen == au_digen(dentry) |
cfc41e69 | 18485 | + && !au_ig_ftest(igflags, HALF_REFRESHED)) |
4a4d8108 | 18486 | + break; |
537831f9 AM |
18487 | + |
18488 | + /* fully refresh inode using dentry */ | |
18489 | + err = au_refresh_hinode(inode, dentry); | |
18490 | + if (!err) | |
18491 | + au_update_iigen(inode, /*half*/0); | |
18492 | + break; | |
1facf9fc | 18493 | + } |
dece6358 | 18494 | + |
4a4d8108 AM |
18495 | + if (unlikely(err)) |
18496 | + ii_write_unlock(inode); | |
4f0767ce | 18497 | +out: |
1facf9fc | 18498 | + return err; |
18499 | +} | |
1facf9fc | 18500 | + |
4a4d8108 AM |
18501 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
18502 | + unsigned int d_type, ino_t *ino) | |
1facf9fc | 18503 | +{ |
521ced18 JR |
18504 | + int err, idx; |
18505 | + const int isnondir = d_type != DT_DIR; | |
1facf9fc | 18506 | + |
b752ccd1 | 18507 | + /* prevent hardlinked inode number from race condition */ |
521ced18 JR |
18508 | + if (isnondir) { |
18509 | + err = au_xinondir_enter(sb, bindex, h_ino, &idx); | |
18510 | + if (unlikely(err)) | |
18511 | + goto out; | |
4a4d8108 | 18512 | + } |
521ced18 | 18513 | + |
4a4d8108 AM |
18514 | + err = au_xino_read(sb, bindex, h_ino, ino); |
18515 | + if (unlikely(err)) | |
521ced18 | 18516 | + goto out_xinondir; |
1308ab2a | 18517 | + |
4a4d8108 AM |
18518 | + if (!*ino) { |
18519 | + err = -EIO; | |
18520 | + *ino = au_xino_new_ino(sb); | |
18521 | + if (unlikely(!*ino)) | |
521ced18 | 18522 | + goto out_xinondir; |
4a4d8108 AM |
18523 | + err = au_xino_write(sb, bindex, h_ino, *ino); |
18524 | + if (unlikely(err)) | |
521ced18 | 18525 | + goto out_xinondir; |
1308ab2a | 18526 | + } |
1facf9fc | 18527 | + |
521ced18 JR |
18528 | +out_xinondir: |
18529 | + if (isnondir && idx >= 0) | |
18530 | + au_xinondir_leave(sb, bindex, h_ino, idx); | |
4f0767ce | 18531 | +out: |
1facf9fc | 18532 | + return err; |
18533 | +} | |
18534 | + | |
4a4d8108 AM |
18535 | +/* successful returns with iinfo write_locked */ |
18536 | +/* todo: return with unlocked? */ | |
18537 | +struct inode *au_new_inode(struct dentry *dentry, int must_new) | |
1facf9fc | 18538 | +{ |
5527c038 | 18539 | + struct inode *inode, *h_inode; |
4a4d8108 AM |
18540 | + struct dentry *h_dentry; |
18541 | + struct super_block *sb; | |
18542 | + ino_t h_ino, ino; | |
521ced18 | 18543 | + int err, idx, hlinked; |
5afbbe0d | 18544 | + aufs_bindex_t btop; |
1facf9fc | 18545 | + |
4a4d8108 | 18546 | + sb = dentry->d_sb; |
5afbbe0d AM |
18547 | + btop = au_dbtop(dentry); |
18548 | + h_dentry = au_h_dptr(dentry, btop); | |
5527c038 JR |
18549 | + h_inode = d_inode(h_dentry); |
18550 | + h_ino = h_inode->i_ino; | |
521ced18 | 18551 | + hlinked = !d_is_dir(h_dentry) && h_inode->i_nlink > 1; |
b752ccd1 | 18552 | + |
521ced18 | 18553 | +new_ino: |
b752ccd1 AM |
18554 | + /* |
18555 | + * stop 'race'-ing between hardlinks under different | |
18556 | + * parents. | |
18557 | + */ | |
521ced18 JR |
18558 | + if (hlinked) { |
18559 | + err = au_xinondir_enter(sb, btop, h_ino, &idx); | |
18560 | + inode = ERR_PTR(err); | |
18561 | + if (unlikely(err)) | |
18562 | + goto out; | |
18563 | + } | |
b752ccd1 | 18564 | + |
5afbbe0d | 18565 | + err = au_xino_read(sb, btop, h_ino, &ino); |
4a4d8108 AM |
18566 | + inode = ERR_PTR(err); |
18567 | + if (unlikely(err)) | |
521ced18 | 18568 | + goto out_xinondir; |
b752ccd1 | 18569 | + |
4a4d8108 AM |
18570 | + if (!ino) { |
18571 | + ino = au_xino_new_ino(sb); | |
18572 | + if (unlikely(!ino)) { | |
18573 | + inode = ERR_PTR(-EIO); | |
521ced18 | 18574 | + goto out_xinondir; |
dece6358 AM |
18575 | + } |
18576 | + } | |
1facf9fc | 18577 | + |
4a4d8108 AM |
18578 | + AuDbg("i%lu\n", (unsigned long)ino); |
18579 | + inode = au_iget_locked(sb, ino); | |
18580 | + err = PTR_ERR(inode); | |
18581 | + if (IS_ERR(inode)) | |
521ced18 | 18582 | + goto out_xinondir; |
1facf9fc | 18583 | + |
4a4d8108 AM |
18584 | + AuDbg("%lx, new %d\n", inode->i_state, !!(inode->i_state & I_NEW)); |
18585 | + if (inode->i_state & I_NEW) { | |
18586 | + ii_write_lock_new_child(inode); | |
18587 | + err = set_inode(inode, dentry); | |
18588 | + if (!err) { | |
18589 | + unlock_new_inode(inode); | |
521ced18 | 18590 | + goto out_xinondir; /* success */ |
4a4d8108 | 18591 | + } |
1308ab2a | 18592 | + |
027c5e7a AM |
18593 | + /* |
18594 | + * iget_failed() calls iput(), but we need to call | |
18595 | + * ii_write_unlock() after iget_failed(). so dirty hack for | |
18596 | + * i_count. | |
18597 | + */ | |
18598 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 18599 | + iget_failed(inode); |
027c5e7a | 18600 | + ii_write_unlock(inode); |
5afbbe0d | 18601 | + au_xino_write(sb, btop, h_ino, /*ino*/0); |
027c5e7a AM |
18602 | + /* ignore this error */ |
18603 | + goto out_iput; | |
18604 | + } else if (!must_new && !IS_DEADDIR(inode) && inode->i_nlink) { | |
b752ccd1 AM |
18605 | + /* |
18606 | + * horrible race condition between lookup, readdir and copyup | |
18607 | + * (or something). | |
18608 | + */ | |
521ced18 JR |
18609 | + if (hlinked && idx >= 0) |
18610 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
027c5e7a AM |
18611 | + err = reval_inode(inode, dentry); |
18612 | + if (unlikely(err < 0)) { | |
521ced18 | 18613 | + hlinked = 0; |
027c5e7a AM |
18614 | + goto out_iput; |
18615 | + } | |
521ced18 | 18616 | + if (!err) |
4a4d8108 | 18617 | + goto out; /* success */ |
521ced18 JR |
18618 | + else if (hlinked && idx >= 0) { |
18619 | + err = au_xinondir_enter(sb, btop, h_ino, &idx); | |
18620 | + if (unlikely(err)) { | |
18621 | + iput(inode); | |
18622 | + inode = ERR_PTR(err); | |
18623 | + goto out; | |
18624 | + } | |
18625 | + } | |
4a4d8108 AM |
18626 | + } |
18627 | + | |
5527c038 | 18628 | + if (unlikely(au_test_fs_unique_ino(h_inode))) |
4a4d8108 | 18629 | + AuWarn1("Warning: Un-notified UDBA or repeatedly renamed dir," |
523b37e3 | 18630 | + " b%d, %s, %pd, hi%lu, i%lu.\n", |
5afbbe0d | 18631 | + btop, au_sbtype(h_dentry->d_sb), dentry, |
4a4d8108 AM |
18632 | + (unsigned long)h_ino, (unsigned long)ino); |
18633 | + ino = 0; | |
5afbbe0d | 18634 | + err = au_xino_write(sb, btop, h_ino, /*ino*/0); |
4a4d8108 AM |
18635 | + if (!err) { |
18636 | + iput(inode); | |
521ced18 JR |
18637 | + if (hlinked && idx >= 0) |
18638 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
4a4d8108 AM |
18639 | + goto new_ino; |
18640 | + } | |
1308ab2a | 18641 | + |
4f0767ce | 18642 | +out_iput: |
4a4d8108 | 18643 | + iput(inode); |
4a4d8108 | 18644 | + inode = ERR_PTR(err); |
521ced18 JR |
18645 | +out_xinondir: |
18646 | + if (hlinked && idx >= 0) | |
18647 | + au_xinondir_leave(sb, btop, h_ino, idx); | |
4f0767ce | 18648 | +out: |
4a4d8108 | 18649 | + return inode; |
1facf9fc | 18650 | +} |
18651 | + | |
4a4d8108 | 18652 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18653 | + |
4a4d8108 AM |
18654 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, |
18655 | + struct inode *inode) | |
18656 | +{ | |
18657 | + int err; | |
076b876e | 18658 | + struct inode *hi; |
1facf9fc | 18659 | + |
4a4d8108 | 18660 | + err = au_br_rdonly(au_sbr(sb, bindex)); |
1facf9fc | 18661 | + |
4a4d8108 AM |
18662 | + /* pseudo-link after flushed may happen out of bounds */ |
18663 | + if (!err | |
18664 | + && inode | |
5afbbe0d AM |
18665 | + && au_ibtop(inode) <= bindex |
18666 | + && bindex <= au_ibbot(inode)) { | |
4a4d8108 AM |
18667 | + /* |
18668 | + * permission check is unnecessary since vfsub routine | |
18669 | + * will be called later | |
18670 | + */ | |
076b876e | 18671 | + hi = au_h_iptr(inode, bindex); |
4a4d8108 AM |
18672 | + if (hi) |
18673 | + err = IS_IMMUTABLE(hi) ? -EROFS : 0; | |
1facf9fc | 18674 | + } |
18675 | + | |
4a4d8108 AM |
18676 | + return err; |
18677 | +} | |
dece6358 | 18678 | + |
4a4d8108 AM |
18679 | +int au_test_h_perm(struct inode *h_inode, int mask) |
18680 | +{ | |
2dfbb274 | 18681 | + if (uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) |
4a4d8108 AM |
18682 | + return 0; |
18683 | + return inode_permission(h_inode, mask); | |
18684 | +} | |
1facf9fc | 18685 | + |
4a4d8108 AM |
18686 | +int au_test_h_perm_sio(struct inode *h_inode, int mask) |
18687 | +{ | |
18688 | + if (au_test_nfs(h_inode->i_sb) | |
18689 | + && (mask & MAY_WRITE) | |
18690 | + && S_ISDIR(h_inode->i_mode)) | |
18691 | + mask |= MAY_READ; /* force permission check */ | |
18692 | + return au_test_h_perm(h_inode, mask); | |
1facf9fc | 18693 | +} |
7f207e10 | 18694 | diff -urN /usr/share/empty/fs/aufs/inode.h linux/fs/aufs/inode.h |
eca34b5c | 18695 | --- /usr/share/empty/fs/aufs/inode.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 18696 | +++ linux/fs/aufs/inode.h 2020-01-27 10:57:18.175538316 +0100 |
9f237c51 | 18697 | @@ -0,0 +1,698 @@ |
062440b3 | 18698 | +/* SPDX-License-Identifier: GPL-2.0 */ |
4a4d8108 | 18699 | +/* |
d58c55f2 | 18700 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
18701 | + * |
18702 | + * This program, aufs is free software; you can redistribute it and/or modify | |
18703 | + * it under the terms of the GNU General Public License as published by | |
18704 | + * the Free Software Foundation; either version 2 of the License, or | |
18705 | + * (at your option) any later version. | |
18706 | + * | |
18707 | + * This program is distributed in the hope that it will be useful, | |
18708 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18709 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18710 | + * GNU General Public License for more details. | |
18711 | + * | |
18712 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 18713 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 18714 | + */ |
1facf9fc | 18715 | + |
1308ab2a | 18716 | +/* |
4a4d8108 | 18717 | + * inode operations |
1308ab2a | 18718 | + */ |
dece6358 | 18719 | + |
4a4d8108 AM |
18720 | +#ifndef __AUFS_INODE_H__ |
18721 | +#define __AUFS_INODE_H__ | |
dece6358 | 18722 | + |
4a4d8108 | 18723 | +#ifdef __KERNEL__ |
1308ab2a | 18724 | + |
4a4d8108 | 18725 | +#include <linux/fsnotify.h> |
4a4d8108 | 18726 | +#include "rwsem.h" |
1308ab2a | 18727 | + |
4a4d8108 | 18728 | +struct vfsmount; |
1facf9fc | 18729 | + |
4a4d8108 AM |
18730 | +struct au_hnotify { |
18731 | +#ifdef CONFIG_AUFS_HNOTIFY | |
18732 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
7f207e10 | 18733 | + /* never use fsnotify_add_vfsmount_mark() */ |
0c5527e5 | 18734 | + struct fsnotify_mark hn_mark; |
4a4d8108 | 18735 | +#endif |
1c60b727 | 18736 | + struct inode *hn_aufs_inode; /* no get/put */ |
9f237c51 | 18737 | + struct rcu_head rcu; |
4a4d8108 AM |
18738 | +#endif |
18739 | +} ____cacheline_aligned_in_smp; | |
1facf9fc | 18740 | + |
4a4d8108 AM |
18741 | +struct au_hinode { |
18742 | + struct inode *hi_inode; | |
18743 | + aufs_bindex_t hi_id; | |
18744 | +#ifdef CONFIG_AUFS_HNOTIFY | |
18745 | + struct au_hnotify *hi_notify; | |
18746 | +#endif | |
dece6358 | 18747 | + |
4a4d8108 AM |
18748 | + /* reference to the copied-up whiteout with get/put */ |
18749 | + struct dentry *hi_whdentry; | |
18750 | +}; | |
dece6358 | 18751 | + |
537831f9 AM |
18752 | +/* ig_flags */ |
18753 | +#define AuIG_HALF_REFRESHED 1 | |
18754 | +#define au_ig_ftest(flags, name) ((flags) & AuIG_##name) | |
18755 | +#define au_ig_fset(flags, name) \ | |
18756 | + do { (flags) |= AuIG_##name; } while (0) | |
18757 | +#define au_ig_fclr(flags, name) \ | |
18758 | + do { (flags) &= ~AuIG_##name; } while (0) | |
18759 | + | |
18760 | +struct au_iigen { | |
be52b249 | 18761 | + spinlock_t ig_spin; |
537831f9 AM |
18762 | + __u32 ig_generation, ig_flags; |
18763 | +}; | |
18764 | + | |
4a4d8108 AM |
18765 | +struct au_vdir; |
18766 | +struct au_iinfo { | |
7a9e40b8 | 18767 | + struct au_iigen ii_generation; |
4a4d8108 | 18768 | + struct super_block *ii_hsb1; /* no get/put */ |
1facf9fc | 18769 | + |
4a4d8108 | 18770 | + struct au_rwsem ii_rwsem; |
5afbbe0d | 18771 | + aufs_bindex_t ii_btop, ii_bbot; |
4a4d8108 AM |
18772 | + __u32 ii_higen; |
18773 | + struct au_hinode *ii_hinode; | |
18774 | + struct au_vdir *ii_vdir; | |
18775 | +}; | |
1facf9fc | 18776 | + |
4a4d8108 | 18777 | +struct au_icntnr { |
9f237c51 AM |
18778 | + struct au_iinfo iinfo; |
18779 | + struct inode vfs_inode; | |
18780 | + struct hlist_bl_node plink; | |
18781 | + struct rcu_head rcu; | |
4a4d8108 | 18782 | +} ____cacheline_aligned_in_smp; |
1308ab2a | 18783 | + |
4a4d8108 AM |
18784 | +/* au_pin flags */ |
18785 | +#define AuPin_DI_LOCKED 1 | |
18786 | +#define AuPin_MNT_WRITE (1 << 1) | |
18787 | +#define au_ftest_pin(flags, name) ((flags) & AuPin_##name) | |
7f207e10 AM |
18788 | +#define au_fset_pin(flags, name) \ |
18789 | + do { (flags) |= AuPin_##name; } while (0) | |
18790 | +#define au_fclr_pin(flags, name) \ | |
18791 | + do { (flags) &= ~AuPin_##name; } while (0) | |
4a4d8108 AM |
18792 | + |
18793 | +struct au_pin { | |
18794 | + /* input */ | |
18795 | + struct dentry *dentry; | |
18796 | + unsigned int udba; | |
18797 | + unsigned char lsc_di, lsc_hi, flags; | |
18798 | + aufs_bindex_t bindex; | |
18799 | + | |
18800 | + /* output */ | |
18801 | + struct dentry *parent; | |
18802 | + struct au_hinode *hdir; | |
18803 | + struct vfsmount *h_mnt; | |
86dc4139 AM |
18804 | + |
18805 | + /* temporary unlock/relock for copyup */ | |
18806 | + struct dentry *h_dentry, *h_parent; | |
18807 | + struct au_branch *br; | |
18808 | + struct task_struct *task; | |
4a4d8108 | 18809 | +}; |
1facf9fc | 18810 | + |
86dc4139 | 18811 | +void au_pin_hdir_unlock(struct au_pin *p); |
c1595e42 | 18812 | +int au_pin_hdir_lock(struct au_pin *p); |
86dc4139 | 18813 | +int au_pin_hdir_relock(struct au_pin *p); |
86dc4139 AM |
18814 | +void au_pin_hdir_acquire_nest(struct au_pin *p); |
18815 | +void au_pin_hdir_release(struct au_pin *p); | |
18816 | + | |
1308ab2a | 18817 | +/* ---------------------------------------------------------------------- */ |
18818 | + | |
4a4d8108 | 18819 | +static inline struct au_iinfo *au_ii(struct inode *inode) |
1facf9fc | 18820 | +{ |
5afbbe0d AM |
18821 | + BUG_ON(is_bad_inode(inode)); |
18822 | + return &(container_of(inode, struct au_icntnr, vfs_inode)->iinfo); | |
4a4d8108 | 18823 | +} |
1facf9fc | 18824 | + |
4a4d8108 | 18825 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 18826 | + |
4a4d8108 AM |
18827 | +/* inode.c */ |
18828 | +struct inode *au_igrab(struct inode *inode); | |
b95c5147 | 18829 | +void au_refresh_iop(struct inode *inode, int force_getattr); |
027c5e7a | 18830 | +int au_refresh_hinode_self(struct inode *inode); |
4a4d8108 AM |
18831 | +int au_refresh_hinode(struct inode *inode, struct dentry *dentry); |
18832 | +int au_ino(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
18833 | + unsigned int d_type, ino_t *ino); | |
18834 | +struct inode *au_new_inode(struct dentry *dentry, int must_new); | |
18835 | +int au_test_ro(struct super_block *sb, aufs_bindex_t bindex, | |
18836 | + struct inode *inode); | |
18837 | +int au_test_h_perm(struct inode *h_inode, int mask); | |
18838 | +int au_test_h_perm_sio(struct inode *h_inode, int mask); | |
1facf9fc | 18839 | + |
4a4d8108 AM |
18840 | +static inline int au_wh_ino(struct super_block *sb, aufs_bindex_t bindex, |
18841 | + ino_t h_ino, unsigned int d_type, ino_t *ino) | |
18842 | +{ | |
18843 | +#ifdef CONFIG_AUFS_SHWH | |
18844 | + return au_ino(sb, bindex, h_ino, d_type, ino); | |
18845 | +#else | |
18846 | + return 0; | |
18847 | +#endif | |
18848 | +} | |
1facf9fc | 18849 | + |
4a4d8108 | 18850 | +/* i_op.c */ |
b95c5147 AM |
18851 | +enum { |
18852 | + AuIop_SYMLINK, | |
18853 | + AuIop_DIR, | |
18854 | + AuIop_OTHER, | |
18855 | + AuIop_Last | |
18856 | +}; | |
43982f53 | 18857 | +extern struct inode_operations aufs_iop[AuIop_Last], /* not const */ |
b95c5147 | 18858 | + aufs_iop_nogetattr[AuIop_Last]; |
1308ab2a | 18859 | + |
4a4d8108 AM |
18860 | +/* au_wr_dir flags */ |
18861 | +#define AuWrDir_ADD_ENTRY 1 | |
7e9cd9fe AM |
18862 | +#define AuWrDir_ISDIR (1 << 1) |
18863 | +#define AuWrDir_TMPFILE (1 << 2) | |
4a4d8108 | 18864 | +#define au_ftest_wrdir(flags, name) ((flags) & AuWrDir_##name) |
7f207e10 AM |
18865 | +#define au_fset_wrdir(flags, name) \ |
18866 | + do { (flags) |= AuWrDir_##name; } while (0) | |
18867 | +#define au_fclr_wrdir(flags, name) \ | |
18868 | + do { (flags) &= ~AuWrDir_##name; } while (0) | |
1facf9fc | 18869 | + |
4a4d8108 AM |
18870 | +struct au_wr_dir_args { |
18871 | + aufs_bindex_t force_btgt; | |
18872 | + unsigned char flags; | |
18873 | +}; | |
18874 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
18875 | + struct au_wr_dir_args *args); | |
dece6358 | 18876 | + |
4a4d8108 AM |
18877 | +struct dentry *au_pinned_h_parent(struct au_pin *pin); |
18878 | +void au_pin_init(struct au_pin *pin, struct dentry *dentry, | |
18879 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
18880 | + unsigned int udba, unsigned char flags); | |
18881 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
18882 | + unsigned int udba, unsigned char flags) __must_check; | |
18883 | +int au_do_pin(struct au_pin *pin) __must_check; | |
18884 | +void au_unpin(struct au_pin *pin); | |
c1595e42 JR |
18885 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen); |
18886 | + | |
18887 | +#define AuIcpup_DID_CPUP 1 | |
18888 | +#define au_ftest_icpup(flags, name) ((flags) & AuIcpup_##name) | |
18889 | +#define au_fset_icpup(flags, name) \ | |
18890 | + do { (flags) |= AuIcpup_##name; } while (0) | |
18891 | +#define au_fclr_icpup(flags, name) \ | |
18892 | + do { (flags) &= ~AuIcpup_##name; } while (0) | |
18893 | + | |
18894 | +struct au_icpup_args { | |
18895 | + unsigned char flags; | |
18896 | + unsigned char pin_flags; | |
18897 | + aufs_bindex_t btgt; | |
18898 | + unsigned int udba; | |
18899 | + struct au_pin pin; | |
18900 | + struct path h_path; | |
18901 | + struct inode *h_inode; | |
18902 | +}; | |
18903 | + | |
18904 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, | |
18905 | + struct au_icpup_args *a); | |
18906 | + | |
a2654f78 AM |
18907 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path, |
18908 | + int locked); | |
1facf9fc | 18909 | + |
4a4d8108 AM |
18910 | +/* i_op_add.c */ |
18911 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
18912 | + struct dentry *h_parent, int isdir); | |
7eafdf33 AM |
18913 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
18914 | + dev_t dev); | |
4a4d8108 | 18915 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname); |
7eafdf33 | 18916 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 18917 | + bool want_excl); |
b912730e AM |
18918 | +struct vfsub_aopen_args; |
18919 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, | |
18920 | + struct vfsub_aopen_args *args); | |
38d290e6 | 18921 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode); |
4a4d8108 AM |
18922 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, |
18923 | + struct dentry *dentry); | |
7eafdf33 | 18924 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode); |
1facf9fc | 18925 | + |
4a4d8108 AM |
18926 | +/* i_op_del.c */ |
18927 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup); | |
18928 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
18929 | + struct dentry *h_parent, int isdir); | |
18930 | +int aufs_unlink(struct inode *dir, struct dentry *dentry); | |
18931 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry); | |
1308ab2a | 18932 | + |
4a4d8108 AM |
18933 | +/* i_op_ren.c */ |
18934 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt); | |
18935 | +int aufs_rename(struct inode *src_dir, struct dentry *src_dentry, | |
f2c43d5f AM |
18936 | + struct inode *dir, struct dentry *dentry, |
18937 | + unsigned int flags); | |
1facf9fc | 18938 | + |
4a4d8108 AM |
18939 | +/* iinfo.c */ |
18940 | +struct inode *au_h_iptr(struct inode *inode, aufs_bindex_t bindex); | |
18941 | +void au_hiput(struct au_hinode *hinode); | |
18942 | +void au_set_hi_wh(struct inode *inode, aufs_bindex_t bindex, | |
18943 | + struct dentry *h_wh); | |
18944 | +unsigned int au_hi_flags(struct inode *inode, int isdir); | |
1308ab2a | 18945 | + |
4a4d8108 AM |
18946 | +/* hinode flags */ |
18947 | +#define AuHi_XINO 1 | |
18948 | +#define AuHi_HNOTIFY (1 << 1) | |
18949 | +#define au_ftest_hi(flags, name) ((flags) & AuHi_##name) | |
7f207e10 AM |
18950 | +#define au_fset_hi(flags, name) \ |
18951 | + do { (flags) |= AuHi_##name; } while (0) | |
18952 | +#define au_fclr_hi(flags, name) \ | |
18953 | + do { (flags) &= ~AuHi_##name; } while (0) | |
1facf9fc | 18954 | + |
4a4d8108 AM |
18955 | +#ifndef CONFIG_AUFS_HNOTIFY |
18956 | +#undef AuHi_HNOTIFY | |
18957 | +#define AuHi_HNOTIFY 0 | |
18958 | +#endif | |
1facf9fc | 18959 | + |
4a4d8108 AM |
18960 | +void au_set_h_iptr(struct inode *inode, aufs_bindex_t bindex, |
18961 | + struct inode *h_inode, unsigned int flags); | |
1facf9fc | 18962 | + |
537831f9 | 18963 | +void au_update_iigen(struct inode *inode, int half); |
4a4d8108 | 18964 | +void au_update_ibrange(struct inode *inode, int do_put_zero); |
1facf9fc | 18965 | + |
4a4d8108 | 18966 | +void au_icntnr_init_once(void *_c); |
5afbbe0d | 18967 | +void au_hinode_init(struct au_hinode *hinode); |
4a4d8108 AM |
18968 | +int au_iinfo_init(struct inode *inode); |
18969 | +void au_iinfo_fin(struct inode *inode); | |
e2f27e51 | 18970 | +int au_hinode_realloc(struct au_iinfo *iinfo, int nbr, int may_shrink); |
1308ab2a | 18971 | + |
e49829fe | 18972 | +#ifdef CONFIG_PROC_FS |
4a4d8108 | 18973 | +/* plink.c */ |
e49829fe | 18974 | +int au_plink_maint(struct super_block *sb, int flags); |
7e9cd9fe | 18975 | +struct au_sbinfo; |
e49829fe JR |
18976 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo); |
18977 | +int au_plink_maint_enter(struct super_block *sb); | |
4a4d8108 AM |
18978 | +#ifdef CONFIG_AUFS_DEBUG |
18979 | +void au_plink_list(struct super_block *sb); | |
18980 | +#else | |
18981 | +AuStubVoid(au_plink_list, struct super_block *sb) | |
18982 | +#endif | |
18983 | +int au_plink_test(struct inode *inode); | |
18984 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex); | |
18985 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
18986 | + struct dentry *h_dentry); | |
e49829fe JR |
18987 | +void au_plink_put(struct super_block *sb, int verbose); |
18988 | +void au_plink_clean(struct super_block *sb, int verbose); | |
4a4d8108 | 18989 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id); |
e49829fe JR |
18990 | +#else |
18991 | +AuStubInt0(au_plink_maint, struct super_block *sb, int flags); | |
18992 | +AuStubVoid(au_plink_maint_leave, struct au_sbinfo *sbinfo); | |
18993 | +AuStubInt0(au_plink_maint_enter, struct super_block *sb); | |
18994 | +AuStubVoid(au_plink_list, struct super_block *sb); | |
18995 | +AuStubInt0(au_plink_test, struct inode *inode); | |
18996 | +AuStub(struct dentry *, au_plink_lkup, return NULL, | |
18997 | + struct inode *inode, aufs_bindex_t bindex); | |
18998 | +AuStubVoid(au_plink_append, struct inode *inode, aufs_bindex_t bindex, | |
18999 | + struct dentry *h_dentry); | |
19000 | +AuStubVoid(au_plink_put, struct super_block *sb, int verbose); | |
19001 | +AuStubVoid(au_plink_clean, struct super_block *sb, int verbose); | |
19002 | +AuStubVoid(au_plink_half_refresh, struct super_block *sb, aufs_bindex_t br_id); | |
19003 | +#endif /* CONFIG_PROC_FS */ | |
1facf9fc | 19004 | + |
c1595e42 JR |
19005 | +#ifdef CONFIG_AUFS_XATTR |
19006 | +/* xattr.c */ | |
7e9cd9fe AM |
19007 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
19008 | + unsigned int verbose); | |
c1595e42 | 19009 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size); |
f2c43d5f | 19010 | +void au_xattr_init(struct super_block *sb); |
c1595e42 JR |
19011 | +#else |
19012 | +AuStubInt0(au_cpup_xattr, struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe | 19013 | + int ignore_flags, unsigned int verbose); |
f2c43d5f | 19014 | +AuStubVoid(au_xattr_init, struct super_block *sb); |
c1595e42 JR |
19015 | +#endif |
19016 | + | |
19017 | +#ifdef CONFIG_FS_POSIX_ACL | |
19018 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type); | |
19019 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type); | |
19020 | +#endif | |
19021 | + | |
19022 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) | |
19023 | +enum { | |
19024 | + AU_XATTR_SET, | |
c1595e42 JR |
19025 | + AU_ACL_SET |
19026 | +}; | |
19027 | + | |
f2c43d5f | 19028 | +struct au_sxattr { |
c1595e42 JR |
19029 | + int type; |
19030 | + union { | |
19031 | + struct { | |
19032 | + const char *name; | |
19033 | + const void *value; | |
19034 | + size_t size; | |
19035 | + int flags; | |
19036 | + } set; | |
19037 | + struct { | |
c1595e42 JR |
19038 | + struct posix_acl *acl; |
19039 | + int type; | |
19040 | + } acl_set; | |
19041 | + } u; | |
19042 | +}; | |
f2c43d5f AM |
19043 | +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode, |
19044 | + struct au_sxattr *arg); | |
c1595e42 JR |
19045 | +#endif |
19046 | + | |
4a4d8108 | 19047 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19048 | + |
4a4d8108 AM |
19049 | +/* lock subclass for iinfo */ |
19050 | +enum { | |
19051 | + AuLsc_II_CHILD, /* child first */ | |
19052 | + AuLsc_II_CHILD2, /* rename(2), link(2), and cpup at hnotify */ | |
19053 | + AuLsc_II_CHILD3, /* copyup dirs */ | |
19054 | + AuLsc_II_PARENT, /* see AuLsc_I_PARENT in vfsub.h */ | |
19055 | + AuLsc_II_PARENT2, | |
19056 | + AuLsc_II_PARENT3, /* copyup dirs */ | |
19057 | + AuLsc_II_NEW_CHILD | |
19058 | +}; | |
1308ab2a | 19059 | + |
1facf9fc | 19060 | +/* |
4a4d8108 AM |
19061 | + * ii_read_lock_child, ii_write_lock_child, |
19062 | + * ii_read_lock_child2, ii_write_lock_child2, | |
19063 | + * ii_read_lock_child3, ii_write_lock_child3, | |
19064 | + * ii_read_lock_parent, ii_write_lock_parent, | |
19065 | + * ii_read_lock_parent2, ii_write_lock_parent2, | |
19066 | + * ii_read_lock_parent3, ii_write_lock_parent3, | |
19067 | + * ii_read_lock_new_child, ii_write_lock_new_child, | |
1facf9fc | 19068 | + */ |
4a4d8108 AM |
19069 | +#define AuReadLockFunc(name, lsc) \ |
19070 | +static inline void ii_read_lock_##name(struct inode *i) \ | |
19071 | +{ \ | |
19072 | + au_rw_read_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
19073 | +} | |
19074 | + | |
19075 | +#define AuWriteLockFunc(name, lsc) \ | |
19076 | +static inline void ii_write_lock_##name(struct inode *i) \ | |
19077 | +{ \ | |
19078 | + au_rw_write_lock_nested(&au_ii(i)->ii_rwsem, AuLsc_II_##lsc); \ | |
19079 | +} | |
19080 | + | |
19081 | +#define AuRWLockFuncs(name, lsc) \ | |
19082 | + AuReadLockFunc(name, lsc) \ | |
19083 | + AuWriteLockFunc(name, lsc) | |
19084 | + | |
19085 | +AuRWLockFuncs(child, CHILD); | |
19086 | +AuRWLockFuncs(child2, CHILD2); | |
19087 | +AuRWLockFuncs(child3, CHILD3); | |
19088 | +AuRWLockFuncs(parent, PARENT); | |
19089 | +AuRWLockFuncs(parent2, PARENT2); | |
19090 | +AuRWLockFuncs(parent3, PARENT3); | |
19091 | +AuRWLockFuncs(new_child, NEW_CHILD); | |
19092 | + | |
19093 | +#undef AuReadLockFunc | |
19094 | +#undef AuWriteLockFunc | |
19095 | +#undef AuRWLockFuncs | |
1facf9fc | 19096 | + |
8b6a4947 AM |
19097 | +#define ii_read_unlock(i) au_rw_read_unlock(&au_ii(i)->ii_rwsem) |
19098 | +#define ii_write_unlock(i) au_rw_write_unlock(&au_ii(i)->ii_rwsem) | |
19099 | +#define ii_downgrade_lock(i) au_rw_dgrade_lock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 19100 | + |
4a4d8108 AM |
19101 | +#define IiMustNoWaiters(i) AuRwMustNoWaiters(&au_ii(i)->ii_rwsem) |
19102 | +#define IiMustAnyLock(i) AuRwMustAnyLock(&au_ii(i)->ii_rwsem) | |
19103 | +#define IiMustWriteLock(i) AuRwMustWriteLock(&au_ii(i)->ii_rwsem) | |
1facf9fc | 19104 | + |
4a4d8108 | 19105 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19106 | + |
027c5e7a AM |
19107 | +static inline void au_icntnr_init(struct au_icntnr *c) |
19108 | +{ | |
19109 | +#ifdef CONFIG_AUFS_DEBUG | |
19110 | + c->vfs_inode.i_mode = 0; | |
19111 | +#endif | |
19112 | +} | |
19113 | + | |
cfc41e69 | 19114 | +static inline unsigned int au_iigen(struct inode *inode, unsigned int *igflags) |
4a4d8108 | 19115 | +{ |
537831f9 AM |
19116 | + unsigned int gen; |
19117 | + struct au_iinfo *iinfo; | |
be52b249 | 19118 | + struct au_iigen *iigen; |
537831f9 AM |
19119 | + |
19120 | + iinfo = au_ii(inode); | |
be52b249 AM |
19121 | + iigen = &iinfo->ii_generation; |
19122 | + spin_lock(&iigen->ig_spin); | |
cfc41e69 AM |
19123 | + if (igflags) |
19124 | + *igflags = iigen->ig_flags; | |
be52b249 AM |
19125 | + gen = iigen->ig_generation; |
19126 | + spin_unlock(&iigen->ig_spin); | |
537831f9 AM |
19127 | + |
19128 | + return gen; | |
4a4d8108 | 19129 | +} |
1308ab2a | 19130 | + |
4a4d8108 AM |
19131 | +/* tiny test for inode number */ |
19132 | +/* tmpfs generation is too rough */ | |
19133 | +static inline int au_test_higen(struct inode *inode, struct inode *h_inode) | |
19134 | +{ | |
19135 | + struct au_iinfo *iinfo; | |
1308ab2a | 19136 | + |
4a4d8108 AM |
19137 | + iinfo = au_ii(inode); |
19138 | + AuRwMustAnyLock(&iinfo->ii_rwsem); | |
19139 | + return !(iinfo->ii_hsb1 == h_inode->i_sb | |
19140 | + && iinfo->ii_higen == h_inode->i_generation); | |
19141 | +} | |
1308ab2a | 19142 | + |
4a4d8108 AM |
19143 | +static inline void au_iigen_dec(struct inode *inode) |
19144 | +{ | |
537831f9 | 19145 | + struct au_iinfo *iinfo; |
be52b249 | 19146 | + struct au_iigen *iigen; |
537831f9 AM |
19147 | + |
19148 | + iinfo = au_ii(inode); | |
be52b249 AM |
19149 | + iigen = &iinfo->ii_generation; |
19150 | + spin_lock(&iigen->ig_spin); | |
19151 | + iigen->ig_generation--; | |
19152 | + spin_unlock(&iigen->ig_spin); | |
027c5e7a AM |
19153 | +} |
19154 | + | |
19155 | +static inline int au_iigen_test(struct inode *inode, unsigned int sigen) | |
19156 | +{ | |
19157 | + int err; | |
19158 | + | |
19159 | + err = 0; | |
537831f9 | 19160 | + if (unlikely(inode && au_iigen(inode, NULL) != sigen)) |
027c5e7a AM |
19161 | + err = -EIO; |
19162 | + | |
19163 | + return err; | |
4a4d8108 | 19164 | +} |
1308ab2a | 19165 | + |
4a4d8108 | 19166 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 19167 | + |
5afbbe0d AM |
19168 | +static inline struct au_hinode *au_hinode(struct au_iinfo *iinfo, |
19169 | + aufs_bindex_t bindex) | |
19170 | +{ | |
19171 | + return iinfo->ii_hinode + bindex; | |
19172 | +} | |
19173 | + | |
19174 | +static inline int au_is_bad_inode(struct inode *inode) | |
19175 | +{ | |
19176 | + return !!(is_bad_inode(inode) || !au_hinode(au_ii(inode), 0)); | |
19177 | +} | |
19178 | + | |
4a4d8108 AM |
19179 | +static inline aufs_bindex_t au_ii_br_id(struct inode *inode, |
19180 | + aufs_bindex_t bindex) | |
19181 | +{ | |
19182 | + IiMustAnyLock(inode); | |
5afbbe0d | 19183 | + return au_hinode(au_ii(inode), bindex)->hi_id; |
4a4d8108 | 19184 | +} |
1308ab2a | 19185 | + |
5afbbe0d | 19186 | +static inline aufs_bindex_t au_ibtop(struct inode *inode) |
4a4d8108 AM |
19187 | +{ |
19188 | + IiMustAnyLock(inode); | |
5afbbe0d | 19189 | + return au_ii(inode)->ii_btop; |
4a4d8108 | 19190 | +} |
1308ab2a | 19191 | + |
5afbbe0d | 19192 | +static inline aufs_bindex_t au_ibbot(struct inode *inode) |
4a4d8108 AM |
19193 | +{ |
19194 | + IiMustAnyLock(inode); | |
5afbbe0d | 19195 | + return au_ii(inode)->ii_bbot; |
4a4d8108 | 19196 | +} |
1308ab2a | 19197 | + |
4a4d8108 AM |
19198 | +static inline struct au_vdir *au_ivdir(struct inode *inode) |
19199 | +{ | |
19200 | + IiMustAnyLock(inode); | |
19201 | + return au_ii(inode)->ii_vdir; | |
19202 | +} | |
1308ab2a | 19203 | + |
4a4d8108 AM |
19204 | +static inline struct dentry *au_hi_wh(struct inode *inode, aufs_bindex_t bindex) |
19205 | +{ | |
19206 | + IiMustAnyLock(inode); | |
5afbbe0d | 19207 | + return au_hinode(au_ii(inode), bindex)->hi_whdentry; |
4a4d8108 | 19208 | +} |
1308ab2a | 19209 | + |
5afbbe0d | 19210 | +static inline void au_set_ibtop(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 19211 | +{ |
4a4d8108 | 19212 | + IiMustWriteLock(inode); |
5afbbe0d | 19213 | + au_ii(inode)->ii_btop = bindex; |
4a4d8108 | 19214 | +} |
1308ab2a | 19215 | + |
5afbbe0d | 19216 | +static inline void au_set_ibbot(struct inode *inode, aufs_bindex_t bindex) |
4a4d8108 AM |
19217 | +{ |
19218 | + IiMustWriteLock(inode); | |
5afbbe0d | 19219 | + au_ii(inode)->ii_bbot = bindex; |
1308ab2a | 19220 | +} |
19221 | + | |
4a4d8108 AM |
19222 | +static inline void au_set_ivdir(struct inode *inode, struct au_vdir *vdir) |
19223 | +{ | |
19224 | + IiMustWriteLock(inode); | |
19225 | + au_ii(inode)->ii_vdir = vdir; | |
19226 | +} | |
1facf9fc | 19227 | + |
4a4d8108 | 19228 | +static inline struct au_hinode *au_hi(struct inode *inode, aufs_bindex_t bindex) |
1308ab2a | 19229 | +{ |
4a4d8108 | 19230 | + IiMustAnyLock(inode); |
5afbbe0d | 19231 | + return au_hinode(au_ii(inode), bindex); |
4a4d8108 | 19232 | +} |
dece6358 | 19233 | + |
4a4d8108 | 19234 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 19235 | + |
4a4d8108 AM |
19236 | +static inline struct dentry *au_pinned_parent(struct au_pin *pin) |
19237 | +{ | |
19238 | + if (pin) | |
19239 | + return pin->parent; | |
19240 | + return NULL; | |
1facf9fc | 19241 | +} |
19242 | + | |
4a4d8108 | 19243 | +static inline struct inode *au_pinned_h_dir(struct au_pin *pin) |
1facf9fc | 19244 | +{ |
4a4d8108 AM |
19245 | + if (pin && pin->hdir) |
19246 | + return pin->hdir->hi_inode; | |
19247 | + return NULL; | |
1308ab2a | 19248 | +} |
1facf9fc | 19249 | + |
4a4d8108 AM |
19250 | +static inline struct au_hinode *au_pinned_hdir(struct au_pin *pin) |
19251 | +{ | |
19252 | + if (pin) | |
19253 | + return pin->hdir; | |
19254 | + return NULL; | |
19255 | +} | |
1facf9fc | 19256 | + |
4a4d8108 | 19257 | +static inline void au_pin_set_dentry(struct au_pin *pin, struct dentry *dentry) |
1308ab2a | 19258 | +{ |
4a4d8108 AM |
19259 | + if (pin) |
19260 | + pin->dentry = dentry; | |
19261 | +} | |
1308ab2a | 19262 | + |
4a4d8108 AM |
19263 | +static inline void au_pin_set_parent_lflag(struct au_pin *pin, |
19264 | + unsigned char lflag) | |
19265 | +{ | |
19266 | + if (pin) { | |
7f207e10 | 19267 | + if (lflag) |
4a4d8108 | 19268 | + au_fset_pin(pin->flags, DI_LOCKED); |
7f207e10 | 19269 | + else |
4a4d8108 | 19270 | + au_fclr_pin(pin->flags, DI_LOCKED); |
1308ab2a | 19271 | + } |
4a4d8108 AM |
19272 | +} |
19273 | + | |
7e9cd9fe | 19274 | +#if 0 /* reserved */ |
4a4d8108 AM |
19275 | +static inline void au_pin_set_parent(struct au_pin *pin, struct dentry *parent) |
19276 | +{ | |
19277 | + if (pin) { | |
19278 | + dput(pin->parent); | |
19279 | + pin->parent = dget(parent); | |
1facf9fc | 19280 | + } |
4a4d8108 | 19281 | +} |
7e9cd9fe | 19282 | +#endif |
1facf9fc | 19283 | + |
4a4d8108 AM |
19284 | +/* ---------------------------------------------------------------------- */ |
19285 | + | |
027c5e7a | 19286 | +struct au_branch; |
4a4d8108 AM |
19287 | +#ifdef CONFIG_AUFS_HNOTIFY |
19288 | +struct au_hnotify_op { | |
19289 | + void (*ctl)(struct au_hinode *hinode, int do_set); | |
027c5e7a | 19290 | + int (*alloc)(struct au_hinode *hinode); |
7eafdf33 AM |
19291 | + |
19292 | + /* | |
19293 | + * if it returns true, the the caller should free hinode->hi_notify, | |
19294 | + * otherwise ->free() frees it. | |
19295 | + */ | |
19296 | + int (*free)(struct au_hinode *hinode, | |
19297 | + struct au_hnotify *hn) __must_check; | |
4a4d8108 AM |
19298 | + |
19299 | + void (*fin)(void); | |
19300 | + int (*init)(void); | |
027c5e7a AM |
19301 | + |
19302 | + int (*reset_br)(unsigned int udba, struct au_branch *br, int perm); | |
19303 | + void (*fin_br)(struct au_branch *br); | |
19304 | + int (*init_br)(struct au_branch *br, int perm); | |
4a4d8108 AM |
19305 | +}; |
19306 | + | |
19307 | +/* hnotify.c */ | |
027c5e7a | 19308 | +int au_hn_alloc(struct au_hinode *hinode, struct inode *inode); |
4a4d8108 AM |
19309 | +void au_hn_free(struct au_hinode *hinode); |
19310 | +void au_hn_ctl(struct au_hinode *hinode, int do_set); | |
19311 | +void au_hn_reset(struct inode *inode, unsigned int flags); | |
19312 | +int au_hnotify(struct inode *h_dir, struct au_hnotify *hnotify, u32 mask, | |
fbc438ed | 19313 | + const struct qstr *h_child_qstr, struct inode *h_child_inode); |
027c5e7a AM |
19314 | +int au_hnotify_reset_br(unsigned int udba, struct au_branch *br, int perm); |
19315 | +int au_hnotify_init_br(struct au_branch *br, int perm); | |
19316 | +void au_hnotify_fin_br(struct au_branch *br); | |
4a4d8108 AM |
19317 | +int __init au_hnotify_init(void); |
19318 | +void au_hnotify_fin(void); | |
19319 | + | |
7f207e10 | 19320 | +/* hfsnotify.c */ |
4a4d8108 AM |
19321 | +extern const struct au_hnotify_op au_hnotify_op; |
19322 | + | |
19323 | +static inline | |
19324 | +void au_hn_init(struct au_hinode *hinode) | |
19325 | +{ | |
19326 | + hinode->hi_notify = NULL; | |
1308ab2a | 19327 | +} |
19328 | + | |
53392da6 AM |
19329 | +static inline struct au_hnotify *au_hn(struct au_hinode *hinode) |
19330 | +{ | |
19331 | + return hinode->hi_notify; | |
19332 | +} | |
19333 | + | |
4a4d8108 | 19334 | +#else |
c1595e42 JR |
19335 | +AuStub(int, au_hn_alloc, return -EOPNOTSUPP, |
19336 | + struct au_hinode *hinode __maybe_unused, | |
19337 | + struct inode *inode __maybe_unused) | |
19338 | +AuStub(struct au_hnotify *, au_hn, return NULL, struct au_hinode *hinode) | |
4a4d8108 AM |
19339 | +AuStubVoid(au_hn_free, struct au_hinode *hinode __maybe_unused) |
19340 | +AuStubVoid(au_hn_ctl, struct au_hinode *hinode __maybe_unused, | |
19341 | + int do_set __maybe_unused) | |
19342 | +AuStubVoid(au_hn_reset, struct inode *inode __maybe_unused, | |
19343 | + unsigned int flags __maybe_unused) | |
027c5e7a AM |
19344 | +AuStubInt0(au_hnotify_reset_br, unsigned int udba __maybe_unused, |
19345 | + struct au_branch *br __maybe_unused, | |
19346 | + int perm __maybe_unused) | |
19347 | +AuStubInt0(au_hnotify_init_br, struct au_branch *br __maybe_unused, | |
19348 | + int perm __maybe_unused) | |
19349 | +AuStubVoid(au_hnotify_fin_br, struct au_branch *br __maybe_unused) | |
4a4d8108 AM |
19350 | +AuStubInt0(__init au_hnotify_init, void) |
19351 | +AuStubVoid(au_hnotify_fin, void) | |
19352 | +AuStubVoid(au_hn_init, struct au_hinode *hinode __maybe_unused) | |
19353 | +#endif /* CONFIG_AUFS_HNOTIFY */ | |
19354 | + | |
19355 | +static inline void au_hn_suspend(struct au_hinode *hdir) | |
19356 | +{ | |
19357 | + au_hn_ctl(hdir, /*do_set*/0); | |
1308ab2a | 19358 | +} |
19359 | + | |
4a4d8108 | 19360 | +static inline void au_hn_resume(struct au_hinode *hdir) |
1308ab2a | 19361 | +{ |
4a4d8108 AM |
19362 | + au_hn_ctl(hdir, /*do_set*/1); |
19363 | +} | |
1308ab2a | 19364 | + |
5afbbe0d | 19365 | +static inline void au_hn_inode_lock(struct au_hinode *hdir) |
4a4d8108 | 19366 | +{ |
febd17d6 | 19367 | + inode_lock(hdir->hi_inode); |
4a4d8108 AM |
19368 | + au_hn_suspend(hdir); |
19369 | +} | |
dece6358 | 19370 | + |
5afbbe0d | 19371 | +static inline void au_hn_inode_lock_nested(struct au_hinode *hdir, |
4a4d8108 AM |
19372 | + unsigned int sc __maybe_unused) |
19373 | +{ | |
febd17d6 | 19374 | + inode_lock_nested(hdir->hi_inode, sc); |
4a4d8108 | 19375 | + au_hn_suspend(hdir); |
1facf9fc | 19376 | +} |
1facf9fc | 19377 | + |
8b6a4947 AM |
19378 | +#if 0 /* unused */ |
19379 | +#include "vfsub.h" | |
3c1bdaff AM |
19380 | +static inline void au_hn_inode_lock_shared_nested(struct au_hinode *hdir, |
19381 | + unsigned int sc) | |
19382 | +{ | |
be118d29 | 19383 | + inode_lock_shared_nested(hdir->hi_inode, sc); |
3c1bdaff AM |
19384 | + au_hn_suspend(hdir); |
19385 | +} | |
8b6a4947 | 19386 | +#endif |
3c1bdaff | 19387 | + |
5afbbe0d | 19388 | +static inline void au_hn_inode_unlock(struct au_hinode *hdir) |
4a4d8108 AM |
19389 | +{ |
19390 | + au_hn_resume(hdir); | |
febd17d6 | 19391 | + inode_unlock(hdir->hi_inode); |
4a4d8108 AM |
19392 | +} |
19393 | + | |
19394 | +#endif /* __KERNEL__ */ | |
19395 | +#endif /* __AUFS_INODE_H__ */ | |
7f207e10 | 19396 | diff -urN /usr/share/empty/fs/aufs/ioctl.c linux/fs/aufs/ioctl.c |
eca34b5c | 19397 | --- /usr/share/empty/fs/aufs/ioctl.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 19398 | +++ linux/fs/aufs/ioctl.c 2020-01-27 10:57:18.175538316 +0100 |
062440b3 | 19399 | @@ -0,0 +1,220 @@ |
cd7a4cd9 | 19400 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 19401 | +/* |
d58c55f2 | 19402 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
19403 | + * |
19404 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19405 | + * it under the terms of the GNU General Public License as published by | |
19406 | + * the Free Software Foundation; either version 2 of the License, or | |
19407 | + * (at your option) any later version. | |
19408 | + * | |
19409 | + * This program is distributed in the hope that it will be useful, | |
19410 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19411 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19412 | + * GNU General Public License for more details. | |
19413 | + * | |
19414 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19415 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
19416 | + */ |
19417 | + | |
19418 | +/* | |
19419 | + * ioctl | |
19420 | + * plink-management and readdir in userspace. | |
19421 | + * assist the pathconf(3) wrapper library. | |
c2b27bf2 | 19422 | + * move-down |
076b876e | 19423 | + * File-based Hierarchical Storage Management. |
4a4d8108 AM |
19424 | + */ |
19425 | + | |
c2b27bf2 AM |
19426 | +#include <linux/compat.h> |
19427 | +#include <linux/file.h> | |
4a4d8108 AM |
19428 | +#include "aufs.h" |
19429 | + | |
1e00d052 | 19430 | +static int au_wbr_fd(struct path *path, struct aufs_wbr_fd __user *arg) |
4a4d8108 AM |
19431 | +{ |
19432 | + int err, fd; | |
5afbbe0d | 19433 | + aufs_bindex_t wbi, bindex, bbot; |
4a4d8108 AM |
19434 | + struct file *h_file; |
19435 | + struct super_block *sb; | |
19436 | + struct dentry *root; | |
1e00d052 AM |
19437 | + struct au_branch *br; |
19438 | + struct aufs_wbr_fd wbrfd = { | |
19439 | + .oflags = au_dir_roflags, | |
19440 | + .brid = -1 | |
19441 | + }; | |
19442 | + const int valid = O_RDONLY | O_NONBLOCK | O_LARGEFILE | O_DIRECTORY | |
19443 | + | O_NOATIME | O_CLOEXEC; | |
4a4d8108 | 19444 | + |
1e00d052 AM |
19445 | + AuDebugOn(wbrfd.oflags & ~valid); |
19446 | + | |
19447 | + if (arg) { | |
19448 | + err = copy_from_user(&wbrfd, arg, sizeof(wbrfd)); | |
19449 | + if (unlikely(err)) { | |
19450 | + err = -EFAULT; | |
19451 | + goto out; | |
19452 | + } | |
19453 | + | |
19454 | + err = -EINVAL; | |
19455 | + AuDbg("wbrfd{0%o, %d}\n", wbrfd.oflags, wbrfd.brid); | |
19456 | + wbrfd.oflags |= au_dir_roflags; | |
19457 | + AuDbg("0%o\n", wbrfd.oflags); | |
19458 | + if (unlikely(wbrfd.oflags & ~valid)) | |
19459 | + goto out; | |
19460 | + } | |
19461 | + | |
2000de60 | 19462 | + fd = get_unused_fd_flags(0); |
1e00d052 AM |
19463 | + err = fd; |
19464 | + if (unlikely(fd < 0)) | |
4a4d8108 | 19465 | + goto out; |
4a4d8108 | 19466 | + |
1e00d052 | 19467 | + h_file = ERR_PTR(-EINVAL); |
4a4d8108 | 19468 | + wbi = 0; |
1e00d052 | 19469 | + br = NULL; |
4a4d8108 AM |
19470 | + sb = path->dentry->d_sb; |
19471 | + root = sb->s_root; | |
19472 | + aufs_read_lock(root, AuLock_IR); | |
5afbbe0d | 19473 | + bbot = au_sbbot(sb); |
1e00d052 AM |
19474 | + if (wbrfd.brid >= 0) { |
19475 | + wbi = au_br_index(sb, wbrfd.brid); | |
5afbbe0d | 19476 | + if (unlikely(wbi < 0 || wbi > bbot)) |
1e00d052 AM |
19477 | + goto out_unlock; |
19478 | + } | |
19479 | + | |
19480 | + h_file = ERR_PTR(-ENOENT); | |
19481 | + br = au_sbr(sb, wbi); | |
19482 | + if (!au_br_writable(br->br_perm)) { | |
19483 | + if (arg) | |
19484 | + goto out_unlock; | |
19485 | + | |
19486 | + bindex = wbi + 1; | |
19487 | + wbi = -1; | |
5afbbe0d | 19488 | + for (; bindex <= bbot; bindex++) { |
1e00d052 AM |
19489 | + br = au_sbr(sb, bindex); |
19490 | + if (au_br_writable(br->br_perm)) { | |
4a4d8108 | 19491 | + wbi = bindex; |
1e00d052 | 19492 | + br = au_sbr(sb, wbi); |
4a4d8108 AM |
19493 | + break; |
19494 | + } | |
19495 | + } | |
4a4d8108 AM |
19496 | + } |
19497 | + AuDbg("wbi %d\n", wbi); | |
1e00d052 | 19498 | + if (wbi >= 0) |
392086de AM |
19499 | + h_file = au_h_open(root, wbi, wbrfd.oflags, NULL, |
19500 | + /*force_wr*/0); | |
1e00d052 AM |
19501 | + |
19502 | +out_unlock: | |
4a4d8108 AM |
19503 | + aufs_read_unlock(root, AuLock_IR); |
19504 | + err = PTR_ERR(h_file); | |
19505 | + if (IS_ERR(h_file)) | |
19506 | + goto out_fd; | |
19507 | + | |
acd2b654 | 19508 | + au_lcnt_dec(&br->br_nfiles); /* cf. au_h_open() */ |
4a4d8108 AM |
19509 | + fd_install(fd, h_file); |
19510 | + err = fd; | |
19511 | + goto out; /* success */ | |
19512 | + | |
4f0767ce | 19513 | +out_fd: |
4a4d8108 | 19514 | + put_unused_fd(fd); |
4f0767ce | 19515 | +out: |
1e00d052 | 19516 | + AuTraceErr(err); |
4a4d8108 AM |
19517 | + return err; |
19518 | +} | |
19519 | + | |
19520 | +/* ---------------------------------------------------------------------- */ | |
19521 | + | |
19522 | +long aufs_ioctl_dir(struct file *file, unsigned int cmd, unsigned long arg) | |
19523 | +{ | |
19524 | + long err; | |
c1595e42 | 19525 | + struct dentry *dentry; |
4a4d8108 AM |
19526 | + |
19527 | + switch (cmd) { | |
4a4d8108 AM |
19528 | + case AUFS_CTL_RDU: |
19529 | + case AUFS_CTL_RDU_INO: | |
19530 | + err = au_rdu_ioctl(file, cmd, arg); | |
19531 | + break; | |
19532 | + | |
19533 | + case AUFS_CTL_WBR_FD: | |
1e00d052 | 19534 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
19535 | + break; |
19536 | + | |
027c5e7a AM |
19537 | + case AUFS_CTL_IBUSY: |
19538 | + err = au_ibusy_ioctl(file, arg); | |
19539 | + break; | |
19540 | + | |
076b876e AM |
19541 | + case AUFS_CTL_BRINFO: |
19542 | + err = au_brinfo_ioctl(file, arg); | |
19543 | + break; | |
19544 | + | |
19545 | + case AUFS_CTL_FHSM_FD: | |
2000de60 | 19546 | + dentry = file->f_path.dentry; |
c1595e42 JR |
19547 | + if (IS_ROOT(dentry)) |
19548 | + err = au_fhsm_fd(dentry->d_sb, arg); | |
19549 | + else | |
19550 | + err = -ENOTTY; | |
076b876e AM |
19551 | + break; |
19552 | + | |
4a4d8108 AM |
19553 | + default: |
19554 | + /* do not call the lower */ | |
19555 | + AuDbg("0x%x\n", cmd); | |
19556 | + err = -ENOTTY; | |
19557 | + } | |
19558 | + | |
19559 | + AuTraceErr(err); | |
19560 | + return err; | |
19561 | +} | |
19562 | + | |
19563 | +long aufs_ioctl_nondir(struct file *file, unsigned int cmd, unsigned long arg) | |
19564 | +{ | |
19565 | + long err; | |
19566 | + | |
19567 | + switch (cmd) { | |
c2b27bf2 | 19568 | + case AUFS_CTL_MVDOWN: |
2000de60 | 19569 | + err = au_mvdown(file->f_path.dentry, (void __user *)arg); |
c2b27bf2 AM |
19570 | + break; |
19571 | + | |
4a4d8108 | 19572 | + case AUFS_CTL_WBR_FD: |
1e00d052 | 19573 | + err = au_wbr_fd(&file->f_path, (void __user *)arg); |
4a4d8108 AM |
19574 | + break; |
19575 | + | |
19576 | + default: | |
19577 | + /* do not call the lower */ | |
19578 | + AuDbg("0x%x\n", cmd); | |
19579 | + err = -ENOTTY; | |
19580 | + } | |
19581 | + | |
19582 | + AuTraceErr(err); | |
19583 | + return err; | |
19584 | +} | |
b752ccd1 AM |
19585 | + |
19586 | +#ifdef CONFIG_COMPAT | |
19587 | +long aufs_compat_ioctl_dir(struct file *file, unsigned int cmd, | |
19588 | + unsigned long arg) | |
19589 | +{ | |
19590 | + long err; | |
19591 | + | |
19592 | + switch (cmd) { | |
19593 | + case AUFS_CTL_RDU: | |
19594 | + case AUFS_CTL_RDU_INO: | |
19595 | + err = au_rdu_compat_ioctl(file, cmd, arg); | |
19596 | + break; | |
19597 | + | |
027c5e7a AM |
19598 | + case AUFS_CTL_IBUSY: |
19599 | + err = au_ibusy_compat_ioctl(file, arg); | |
19600 | + break; | |
19601 | + | |
076b876e AM |
19602 | + case AUFS_CTL_BRINFO: |
19603 | + err = au_brinfo_compat_ioctl(file, arg); | |
19604 | + break; | |
19605 | + | |
b752ccd1 AM |
19606 | + default: |
19607 | + err = aufs_ioctl_dir(file, cmd, arg); | |
19608 | + } | |
19609 | + | |
19610 | + AuTraceErr(err); | |
19611 | + return err; | |
19612 | +} | |
19613 | + | |
b752ccd1 AM |
19614 | +long aufs_compat_ioctl_nondir(struct file *file, unsigned int cmd, |
19615 | + unsigned long arg) | |
19616 | +{ | |
19617 | + return aufs_ioctl_nondir(file, cmd, (unsigned long)compat_ptr(arg)); | |
19618 | +} | |
19619 | +#endif | |
7f207e10 | 19620 | diff -urN /usr/share/empty/fs/aufs/i_op_add.c linux/fs/aufs/i_op_add.c |
eca34b5c | 19621 | --- /usr/share/empty/fs/aufs/i_op_add.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 19622 | +++ linux/fs/aufs/i_op_add.c 2020-01-27 10:57:18.172204883 +0100 |
eca801bf | 19623 | @@ -0,0 +1,936 @@ |
cd7a4cd9 | 19624 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 19625 | +/* |
d58c55f2 | 19626 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
19627 | + * |
19628 | + * This program, aufs is free software; you can redistribute it and/or modify | |
19629 | + * it under the terms of the GNU General Public License as published by | |
19630 | + * the Free Software Foundation; either version 2 of the License, or | |
19631 | + * (at your option) any later version. | |
19632 | + * | |
19633 | + * This program is distributed in the hope that it will be useful, | |
19634 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19635 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19636 | + * GNU General Public License for more details. | |
19637 | + * | |
19638 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 19639 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 AM |
19640 | + */ |
19641 | + | |
19642 | +/* | |
19643 | + * inode operations (add entry) | |
19644 | + */ | |
19645 | + | |
eca801bf | 19646 | +#include <linux/iversion.h> |
4a4d8108 AM |
19647 | +#include "aufs.h" |
19648 | + | |
19649 | +/* | |
19650 | + * final procedure of adding a new entry, except link(2). | |
19651 | + * remove whiteout, instantiate, copyup the parent dir's times and size | |
19652 | + * and update version. | |
19653 | + * if it failed, re-create the removed whiteout. | |
19654 | + */ | |
19655 | +static int epilog(struct inode *dir, aufs_bindex_t bindex, | |
19656 | + struct dentry *wh_dentry, struct dentry *dentry) | |
19657 | +{ | |
19658 | + int err, rerr; | |
19659 | + aufs_bindex_t bwh; | |
19660 | + struct path h_path; | |
076b876e | 19661 | + struct super_block *sb; |
4a4d8108 AM |
19662 | + struct inode *inode, *h_dir; |
19663 | + struct dentry *wh; | |
19664 | + | |
19665 | + bwh = -1; | |
076b876e | 19666 | + sb = dir->i_sb; |
4a4d8108 | 19667 | + if (wh_dentry) { |
5527c038 | 19668 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
4a4d8108 AM |
19669 | + IMustLock(h_dir); |
19670 | + AuDebugOn(au_h_iptr(dir, bindex) != h_dir); | |
19671 | + bwh = au_dbwh(dentry); | |
19672 | + h_path.dentry = wh_dentry; | |
076b876e | 19673 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
4a4d8108 AM |
19674 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, |
19675 | + dentry); | |
19676 | + if (unlikely(err)) | |
19677 | + goto out; | |
19678 | + } | |
19679 | + | |
19680 | + inode = au_new_inode(dentry, /*must_new*/1); | |
19681 | + if (!IS_ERR(inode)) { | |
19682 | + d_instantiate(dentry, inode); | |
5527c038 | 19683 | + dir = d_inode(dentry->d_parent); /* dir inode is locked */ |
4a4d8108 | 19684 | + IMustLock(dir); |
b912730e | 19685 | + au_dir_ts(dir, bindex); |
be118d29 | 19686 | + inode_inc_iversion(dir); |
076b876e | 19687 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
4a4d8108 AM |
19688 | + return 0; /* success */ |
19689 | + } | |
19690 | + | |
19691 | + err = PTR_ERR(inode); | |
19692 | + if (!wh_dentry) | |
19693 | + goto out; | |
19694 | + | |
19695 | + /* revert */ | |
19696 | + /* dir inode is locked */ | |
19697 | + wh = au_wh_create(dentry, bwh, wh_dentry->d_parent); | |
19698 | + rerr = PTR_ERR(wh); | |
19699 | + if (IS_ERR(wh)) { | |
523b37e3 AM |
19700 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", |
19701 | + dentry, err, rerr); | |
4a4d8108 AM |
19702 | + err = -EIO; |
19703 | + } else | |
19704 | + dput(wh); | |
19705 | + | |
4f0767ce | 19706 | +out: |
4a4d8108 AM |
19707 | + return err; |
19708 | +} | |
19709 | + | |
027c5e7a AM |
19710 | +static int au_d_may_add(struct dentry *dentry) |
19711 | +{ | |
19712 | + int err; | |
19713 | + | |
19714 | + err = 0; | |
19715 | + if (unlikely(d_unhashed(dentry))) | |
19716 | + err = -ENOENT; | |
5527c038 | 19717 | + if (unlikely(d_really_is_positive(dentry))) |
027c5e7a AM |
19718 | + err = -EEXIST; |
19719 | + return err; | |
19720 | +} | |
19721 | + | |
4a4d8108 AM |
19722 | +/* |
19723 | + * simple tests for the adding inode operations. | |
19724 | + * following the checks in vfs, plus the parent-child relationship. | |
19725 | + */ | |
19726 | +int au_may_add(struct dentry *dentry, aufs_bindex_t bindex, | |
19727 | + struct dentry *h_parent, int isdir) | |
19728 | +{ | |
19729 | + int err; | |
19730 | + umode_t h_mode; | |
19731 | + struct dentry *h_dentry; | |
19732 | + struct inode *h_inode; | |
19733 | + | |
19734 | + err = -ENAMETOOLONG; | |
19735 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
19736 | + goto out; | |
19737 | + | |
19738 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 19739 | + if (d_really_is_negative(dentry)) { |
4a4d8108 | 19740 | + err = -EEXIST; |
5527c038 | 19741 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
19742 | + goto out; |
19743 | + } else { | |
19744 | + /* rename(2) case */ | |
19745 | + err = -EIO; | |
5527c038 JR |
19746 | + if (unlikely(d_is_negative(h_dentry))) |
19747 | + goto out; | |
19748 | + h_inode = d_inode(h_dentry); | |
19749 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 AM |
19750 | + goto out; |
19751 | + | |
19752 | + h_mode = h_inode->i_mode; | |
19753 | + if (!isdir) { | |
19754 | + err = -EISDIR; | |
19755 | + if (unlikely(S_ISDIR(h_mode))) | |
19756 | + goto out; | |
19757 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
19758 | + err = -ENOTDIR; | |
19759 | + goto out; | |
19760 | + } | |
19761 | + } | |
19762 | + | |
19763 | + err = 0; | |
19764 | + /* expected parent dir is locked */ | |
19765 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
19766 | + err = -EIO; | |
19767 | + | |
4f0767ce | 19768 | +out: |
4a4d8108 AM |
19769 | + AuTraceErr(err); |
19770 | + return err; | |
19771 | +} | |
19772 | + | |
19773 | +/* | |
19774 | + * initial procedure of adding a new entry. | |
19775 | + * prepare writable branch and the parent dir, lock it, | |
19776 | + * and lookup whiteout for the new entry. | |
19777 | + */ | |
19778 | +static struct dentry* | |
19779 | +lock_hdir_lkup_wh(struct dentry *dentry, struct au_dtime *dt, | |
19780 | + struct dentry *src_dentry, struct au_pin *pin, | |
19781 | + struct au_wr_dir_args *wr_dir_args) | |
19782 | +{ | |
19783 | + struct dentry *wh_dentry, *h_parent; | |
19784 | + struct super_block *sb; | |
19785 | + struct au_branch *br; | |
19786 | + int err; | |
19787 | + unsigned int udba; | |
19788 | + aufs_bindex_t bcpup; | |
19789 | + | |
523b37e3 | 19790 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
19791 | + |
19792 | + err = au_wr_dir(dentry, src_dentry, wr_dir_args); | |
19793 | + bcpup = err; | |
19794 | + wh_dentry = ERR_PTR(err); | |
19795 | + if (unlikely(err < 0)) | |
19796 | + goto out; | |
19797 | + | |
19798 | + sb = dentry->d_sb; | |
19799 | + udba = au_opt_udba(sb); | |
19800 | + err = au_pin(pin, dentry, bcpup, udba, | |
19801 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
19802 | + wh_dentry = ERR_PTR(err); | |
19803 | + if (unlikely(err)) | |
19804 | + goto out; | |
19805 | + | |
19806 | + h_parent = au_pinned_h_parent(pin); | |
19807 | + if (udba != AuOpt_UDBA_NONE | |
5afbbe0d | 19808 | + && au_dbtop(dentry) == bcpup) |
4a4d8108 AM |
19809 | + err = au_may_add(dentry, bcpup, h_parent, |
19810 | + au_ftest_wrdir(wr_dir_args->flags, ISDIR)); | |
19811 | + else if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
19812 | + err = -ENAMETOOLONG; | |
19813 | + wh_dentry = ERR_PTR(err); | |
19814 | + if (unlikely(err)) | |
19815 | + goto out_unpin; | |
19816 | + | |
19817 | + br = au_sbr(sb, bcpup); | |
19818 | + if (dt) { | |
19819 | + struct path tmp = { | |
19820 | + .dentry = h_parent, | |
86dc4139 | 19821 | + .mnt = au_br_mnt(br) |
4a4d8108 AM |
19822 | + }; |
19823 | + au_dtime_store(dt, au_pinned_parent(pin), &tmp); | |
19824 | + } | |
19825 | + | |
19826 | + wh_dentry = NULL; | |
19827 | + if (bcpup != au_dbwh(dentry)) | |
19828 | + goto out; /* success */ | |
19829 | + | |
2000de60 JR |
19830 | + /* |
19831 | + * ENAMETOOLONG here means that if we allowed create such name, then it | |
19832 | + * would not be able to removed in the future. So we don't allow such | |
19833 | + * name here and we don't handle ENAMETOOLONG differently here. | |
19834 | + */ | |
4a4d8108 AM |
19835 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, br); |
19836 | + | |
4f0767ce | 19837 | +out_unpin: |
4a4d8108 AM |
19838 | + if (IS_ERR(wh_dentry)) |
19839 | + au_unpin(pin); | |
4f0767ce | 19840 | +out: |
4a4d8108 AM |
19841 | + return wh_dentry; |
19842 | +} | |
19843 | + | |
19844 | +/* ---------------------------------------------------------------------- */ | |
19845 | + | |
19846 | +enum { Mknod, Symlink, Creat }; | |
19847 | +struct simple_arg { | |
19848 | + int type; | |
19849 | + union { | |
19850 | + struct { | |
b912730e AM |
19851 | + umode_t mode; |
19852 | + bool want_excl; | |
19853 | + bool try_aopen; | |
19854 | + struct vfsub_aopen_args *aopen; | |
4a4d8108 AM |
19855 | + } c; |
19856 | + struct { | |
19857 | + const char *symname; | |
19858 | + } s; | |
19859 | + struct { | |
7eafdf33 | 19860 | + umode_t mode; |
4a4d8108 AM |
19861 | + dev_t dev; |
19862 | + } m; | |
19863 | + } u; | |
19864 | +}; | |
19865 | + | |
19866 | +static int add_simple(struct inode *dir, struct dentry *dentry, | |
19867 | + struct simple_arg *arg) | |
19868 | +{ | |
076b876e | 19869 | + int err, rerr; |
5afbbe0d | 19870 | + aufs_bindex_t btop; |
4a4d8108 | 19871 | + unsigned char created; |
b912730e AM |
19872 | + const unsigned char try_aopen |
19873 | + = (arg->type == Creat && arg->u.c.try_aopen); | |
acd2b654 | 19874 | + struct vfsub_aopen_args *aopen = arg->u.c.aopen; |
4a4d8108 AM |
19875 | + struct dentry *wh_dentry, *parent; |
19876 | + struct inode *h_dir; | |
b912730e AM |
19877 | + struct super_block *sb; |
19878 | + struct au_branch *br; | |
acd2b654 | 19879 | + /* to reduce stack size */ |
c2b27bf2 AM |
19880 | + struct { |
19881 | + struct au_dtime dt; | |
19882 | + struct au_pin pin; | |
19883 | + struct path h_path; | |
19884 | + struct au_wr_dir_args wr_dir_args; | |
19885 | + } *a; | |
4a4d8108 | 19886 | + |
523b37e3 | 19887 | + AuDbg("%pd\n", dentry); |
4a4d8108 AM |
19888 | + IMustLock(dir); |
19889 | + | |
c2b27bf2 AM |
19890 | + err = -ENOMEM; |
19891 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
19892 | + if (unlikely(!a)) | |
19893 | + goto out; | |
19894 | + a->wr_dir_args.force_btgt = -1; | |
19895 | + a->wr_dir_args.flags = AuWrDir_ADD_ENTRY; | |
19896 | + | |
4a4d8108 | 19897 | + parent = dentry->d_parent; /* dir inode is locked */ |
b912730e AM |
19898 | + if (!try_aopen) { |
19899 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); | |
19900 | + if (unlikely(err)) | |
19901 | + goto out_free; | |
19902 | + } | |
027c5e7a AM |
19903 | + err = au_d_may_add(dentry); |
19904 | + if (unlikely(err)) | |
19905 | + goto out_unlock; | |
b912730e AM |
19906 | + if (!try_aopen) |
19907 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
19908 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, |
19909 | + &a->pin, &a->wr_dir_args); | |
4a4d8108 AM |
19910 | + err = PTR_ERR(wh_dentry); |
19911 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 19912 | + goto out_parent; |
4a4d8108 | 19913 | + |
5afbbe0d | 19914 | + btop = au_dbtop(dentry); |
b912730e | 19915 | + sb = dentry->d_sb; |
5afbbe0d AM |
19916 | + br = au_sbr(sb, btop); |
19917 | + a->h_path.dentry = au_h_dptr(dentry, btop); | |
b912730e | 19918 | + a->h_path.mnt = au_br_mnt(br); |
c2b27bf2 | 19919 | + h_dir = au_pinned_h_dir(&a->pin); |
4a4d8108 AM |
19920 | + switch (arg->type) { |
19921 | + case Creat: | |
acd2b654 | 19922 | + if (!try_aopen || !h_dir->i_op->atomic_open) { |
b912730e AM |
19923 | + err = vfsub_create(h_dir, &a->h_path, arg->u.c.mode, |
19924 | + arg->u.c.want_excl); | |
acd2b654 AM |
19925 | + created = !err; |
19926 | + if (!err && try_aopen) | |
19927 | + aopen->file->f_mode |= FMODE_CREATED; | |
19928 | + } else { | |
19929 | + aopen->br = br; | |
19930 | + err = vfsub_atomic_open(h_dir, a->h_path.dentry, aopen); | |
19931 | + AuDbg("err %d\n", err); | |
19932 | + AuDbgFile(aopen->file); | |
19933 | + created = err >= 0 | |
19934 | + && !!(aopen->file->f_mode & FMODE_CREATED); | |
19935 | + } | |
4a4d8108 AM |
19936 | + break; |
19937 | + case Symlink: | |
c2b27bf2 | 19938 | + err = vfsub_symlink(h_dir, &a->h_path, arg->u.s.symname); |
acd2b654 | 19939 | + created = !err; |
4a4d8108 AM |
19940 | + break; |
19941 | + case Mknod: | |
c2b27bf2 AM |
19942 | + err = vfsub_mknod(h_dir, &a->h_path, arg->u.m.mode, |
19943 | + arg->u.m.dev); | |
acd2b654 | 19944 | + created = !err; |
4a4d8108 AM |
19945 | + break; |
19946 | + default: | |
19947 | + BUG(); | |
19948 | + } | |
acd2b654 AM |
19949 | + if (unlikely(err < 0)) |
19950 | + goto out_unpin; | |
19951 | + | |
19952 | + err = epilog(dir, btop, wh_dentry, dentry); | |
4a4d8108 | 19953 | + if (!err) |
acd2b654 | 19954 | + goto out_unpin; /* success */ |
4a4d8108 AM |
19955 | + |
19956 | + /* revert */ | |
acd2b654 | 19957 | + if (created /* && d_is_positive(a->h_path.dentry) */) { |
523b37e3 AM |
19958 | + /* no delegation since it is just created */ |
19959 | + rerr = vfsub_unlink(h_dir, &a->h_path, /*delegated*/NULL, | |
19960 | + /*force*/0); | |
4a4d8108 | 19961 | + if (rerr) { |
523b37e3 AM |
19962 | + AuIOErr("%pd revert failure(%d, %d)\n", |
19963 | + dentry, err, rerr); | |
4a4d8108 AM |
19964 | + err = -EIO; |
19965 | + } | |
c2b27bf2 | 19966 | + au_dtime_revert(&a->dt); |
4a4d8108 | 19967 | + } |
acd2b654 AM |
19968 | + if (try_aopen && h_dir->i_op->atomic_open |
19969 | + && (aopen->file->f_mode & FMODE_OPENED)) | |
19970 | + /* aopen->file is still opened */ | |
19971 | + au_lcnt_dec(&aopen->br->br_nfiles); | |
4a4d8108 | 19972 | + |
acd2b654 | 19973 | +out_unpin: |
c2b27bf2 | 19974 | + au_unpin(&a->pin); |
4a4d8108 | 19975 | + dput(wh_dentry); |
027c5e7a | 19976 | +out_parent: |
b912730e AM |
19977 | + if (!try_aopen) |
19978 | + di_write_unlock(parent); | |
027c5e7a | 19979 | +out_unlock: |
4a4d8108 | 19980 | + if (unlikely(err)) { |
5afbbe0d | 19981 | + au_update_dbtop(dentry); |
4a4d8108 AM |
19982 | + d_drop(dentry); |
19983 | + } | |
b912730e AM |
19984 | + if (!try_aopen) |
19985 | + aufs_read_unlock(dentry, AuLock_DW); | |
c2b27bf2 | 19986 | +out_free: |
9f237c51 | 19987 | + au_kfree_rcu(a); |
027c5e7a | 19988 | +out: |
4a4d8108 AM |
19989 | + return err; |
19990 | +} | |
19991 | + | |
7eafdf33 AM |
19992 | +int aufs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, |
19993 | + dev_t dev) | |
4a4d8108 AM |
19994 | +{ |
19995 | + struct simple_arg arg = { | |
19996 | + .type = Mknod, | |
19997 | + .u.m = { | |
19998 | + .mode = mode, | |
19999 | + .dev = dev | |
20000 | + } | |
20001 | + }; | |
20002 | + return add_simple(dir, dentry, &arg); | |
20003 | +} | |
20004 | + | |
20005 | +int aufs_symlink(struct inode *dir, struct dentry *dentry, const char *symname) | |
20006 | +{ | |
20007 | + struct simple_arg arg = { | |
20008 | + .type = Symlink, | |
20009 | + .u.s.symname = symname | |
20010 | + }; | |
20011 | + return add_simple(dir, dentry, &arg); | |
20012 | +} | |
20013 | + | |
7eafdf33 | 20014 | +int aufs_create(struct inode *dir, struct dentry *dentry, umode_t mode, |
b4510431 | 20015 | + bool want_excl) |
4a4d8108 AM |
20016 | +{ |
20017 | + struct simple_arg arg = { | |
20018 | + .type = Creat, | |
20019 | + .u.c = { | |
b4510431 AM |
20020 | + .mode = mode, |
20021 | + .want_excl = want_excl | |
4a4d8108 AM |
20022 | + } |
20023 | + }; | |
20024 | + return add_simple(dir, dentry, &arg); | |
20025 | +} | |
20026 | + | |
b912730e AM |
20027 | +int au_aopen_or_create(struct inode *dir, struct dentry *dentry, |
20028 | + struct vfsub_aopen_args *aopen_args) | |
20029 | +{ | |
20030 | + struct simple_arg arg = { | |
20031 | + .type = Creat, | |
20032 | + .u.c = { | |
20033 | + .mode = aopen_args->create_mode, | |
20034 | + .want_excl = aopen_args->open_flag & O_EXCL, | |
20035 | + .try_aopen = true, | |
20036 | + .aopen = aopen_args | |
20037 | + } | |
20038 | + }; | |
20039 | + return add_simple(dir, dentry, &arg); | |
20040 | +} | |
20041 | + | |
38d290e6 JR |
20042 | +int aufs_tmpfile(struct inode *dir, struct dentry *dentry, umode_t mode) |
20043 | +{ | |
20044 | + int err; | |
20045 | + aufs_bindex_t bindex; | |
20046 | + struct super_block *sb; | |
20047 | + struct dentry *parent, *h_parent, *h_dentry; | |
20048 | + struct inode *h_dir, *inode; | |
20049 | + struct vfsmount *h_mnt; | |
20050 | + struct au_wr_dir_args wr_dir_args = { | |
20051 | + .force_btgt = -1, | |
20052 | + .flags = AuWrDir_TMPFILE | |
20053 | + }; | |
20054 | + | |
20055 | + /* copy-up may happen */ | |
febd17d6 | 20056 | + inode_lock(dir); |
38d290e6 JR |
20057 | + |
20058 | + sb = dir->i_sb; | |
20059 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
20060 | + if (unlikely(err)) | |
20061 | + goto out; | |
20062 | + | |
20063 | + err = au_di_init(dentry); | |
20064 | + if (unlikely(err)) | |
20065 | + goto out_si; | |
20066 | + | |
20067 | + err = -EBUSY; | |
20068 | + parent = d_find_any_alias(dir); | |
20069 | + AuDebugOn(!parent); | |
20070 | + di_write_lock_parent(parent); | |
5527c038 | 20071 | + if (unlikely(d_inode(parent) != dir)) |
38d290e6 JR |
20072 | + goto out_parent; |
20073 | + | |
20074 | + err = au_digen_test(parent, au_sigen(sb)); | |
20075 | + if (unlikely(err)) | |
20076 | + goto out_parent; | |
20077 | + | |
5afbbe0d AM |
20078 | + bindex = au_dbtop(parent); |
20079 | + au_set_dbtop(dentry, bindex); | |
20080 | + au_set_dbbot(dentry, bindex); | |
38d290e6 JR |
20081 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
20082 | + bindex = err; | |
20083 | + if (unlikely(err < 0)) | |
20084 | + goto out_parent; | |
20085 | + | |
20086 | + err = -EOPNOTSUPP; | |
20087 | + h_dir = au_h_iptr(dir, bindex); | |
20088 | + if (unlikely(!h_dir->i_op->tmpfile)) | |
20089 | + goto out_parent; | |
20090 | + | |
20091 | + h_mnt = au_sbr_mnt(sb, bindex); | |
20092 | + err = vfsub_mnt_want_write(h_mnt); | |
20093 | + if (unlikely(err)) | |
20094 | + goto out_parent; | |
20095 | + | |
20096 | + h_parent = au_h_dptr(parent, bindex); | |
521ced18 JR |
20097 | + h_dentry = vfs_tmpfile(h_parent, mode, /*open_flag*/0); |
20098 | + if (IS_ERR(h_dentry)) { | |
20099 | + err = PTR_ERR(h_dentry); | |
38d290e6 | 20100 | + goto out_mnt; |
521ced18 | 20101 | + } |
38d290e6 | 20102 | + |
5afbbe0d AM |
20103 | + au_set_dbtop(dentry, bindex); |
20104 | + au_set_dbbot(dentry, bindex); | |
38d290e6 JR |
20105 | + au_set_h_dptr(dentry, bindex, dget(h_dentry)); |
20106 | + inode = au_new_inode(dentry, /*must_new*/1); | |
20107 | + if (IS_ERR(inode)) { | |
20108 | + err = PTR_ERR(inode); | |
20109 | + au_set_h_dptr(dentry, bindex, NULL); | |
5afbbe0d AM |
20110 | + au_set_dbtop(dentry, -1); |
20111 | + au_set_dbbot(dentry, -1); | |
38d290e6 JR |
20112 | + } else { |
20113 | + if (!inode->i_nlink) | |
20114 | + set_nlink(inode, 1); | |
20115 | + d_tmpfile(dentry, inode); | |
20116 | + au_di(dentry)->di_tmpfile = 1; | |
20117 | + | |
20118 | + /* update without i_mutex */ | |
5afbbe0d | 20119 | + if (au_ibtop(dir) == au_dbtop(dentry)) |
38d290e6 JR |
20120 | + au_cpup_attr_timesizes(dir); |
20121 | + } | |
38d290e6 | 20122 | + dput(h_dentry); |
521ced18 | 20123 | + |
38d290e6 JR |
20124 | +out_mnt: |
20125 | + vfsub_mnt_drop_write(h_mnt); | |
20126 | +out_parent: | |
20127 | + di_write_unlock(parent); | |
20128 | + dput(parent); | |
20129 | + di_write_unlock(dentry); | |
5afbbe0d | 20130 | + if (unlikely(err)) { |
38d290e6 JR |
20131 | + au_di_fin(dentry); |
20132 | + dentry->d_fsdata = NULL; | |
20133 | + } | |
20134 | +out_si: | |
20135 | + si_read_unlock(sb); | |
20136 | +out: | |
febd17d6 | 20137 | + inode_unlock(dir); |
38d290e6 JR |
20138 | + return err; |
20139 | +} | |
20140 | + | |
4a4d8108 AM |
20141 | +/* ---------------------------------------------------------------------- */ |
20142 | + | |
20143 | +struct au_link_args { | |
20144 | + aufs_bindex_t bdst, bsrc; | |
20145 | + struct au_pin pin; | |
20146 | + struct path h_path; | |
20147 | + struct dentry *src_parent, *parent; | |
20148 | +}; | |
20149 | + | |
20150 | +static int au_cpup_before_link(struct dentry *src_dentry, | |
20151 | + struct au_link_args *a) | |
20152 | +{ | |
20153 | + int err; | |
20154 | + struct dentry *h_src_dentry; | |
c2b27bf2 AM |
20155 | + struct au_cp_generic cpg = { |
20156 | + .dentry = src_dentry, | |
20157 | + .bdst = a->bdst, | |
20158 | + .bsrc = a->bsrc, | |
20159 | + .len = -1, | |
20160 | + .pin = &a->pin, | |
20161 | + .flags = AuCpup_DTIME | AuCpup_HOPEN /* | AuCpup_KEEPLINO */ | |
20162 | + }; | |
4a4d8108 AM |
20163 | + |
20164 | + di_read_lock_parent(a->src_parent, AuLock_IR); | |
20165 | + err = au_test_and_cpup_dirs(src_dentry, a->bdst); | |
20166 | + if (unlikely(err)) | |
20167 | + goto out; | |
20168 | + | |
20169 | + h_src_dentry = au_h_dptr(src_dentry, a->bsrc); | |
4a4d8108 AM |
20170 | + err = au_pin(&a->pin, src_dentry, a->bdst, |
20171 | + au_opt_udba(src_dentry->d_sb), | |
20172 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
20173 | + if (unlikely(err)) | |
20174 | + goto out; | |
367653fa | 20175 | + |
c2b27bf2 | 20176 | + err = au_sio_cpup_simple(&cpg); |
4a4d8108 AM |
20177 | + au_unpin(&a->pin); |
20178 | + | |
4f0767ce | 20179 | +out: |
4a4d8108 AM |
20180 | + di_read_unlock(a->src_parent, AuLock_IR); |
20181 | + return err; | |
20182 | +} | |
20183 | + | |
86dc4139 AM |
20184 | +static int au_cpup_or_link(struct dentry *src_dentry, struct dentry *dentry, |
20185 | + struct au_link_args *a) | |
4a4d8108 AM |
20186 | +{ |
20187 | + int err; | |
20188 | + unsigned char plink; | |
5afbbe0d | 20189 | + aufs_bindex_t bbot; |
4a4d8108 | 20190 | + struct dentry *h_src_dentry; |
523b37e3 | 20191 | + struct inode *h_inode, *inode, *delegated; |
4a4d8108 AM |
20192 | + struct super_block *sb; |
20193 | + struct file *h_file; | |
20194 | + | |
20195 | + plink = 0; | |
20196 | + h_inode = NULL; | |
20197 | + sb = src_dentry->d_sb; | |
5527c038 | 20198 | + inode = d_inode(src_dentry); |
5afbbe0d | 20199 | + if (au_ibtop(inode) <= a->bdst) |
4a4d8108 AM |
20200 | + h_inode = au_h_iptr(inode, a->bdst); |
20201 | + if (!h_inode || !h_inode->i_nlink) { | |
20202 | + /* copyup src_dentry as the name of dentry. */ | |
5afbbe0d AM |
20203 | + bbot = au_dbbot(dentry); |
20204 | + if (bbot < a->bsrc) | |
20205 | + au_set_dbbot(dentry, a->bsrc); | |
86dc4139 AM |
20206 | + au_set_h_dptr(dentry, a->bsrc, |
20207 | + dget(au_h_dptr(src_dentry, a->bsrc))); | |
20208 | + dget(a->h_path.dentry); | |
20209 | + au_set_h_dptr(dentry, a->bdst, NULL); | |
c1595e42 JR |
20210 | + AuDbg("temporary d_inode...\n"); |
20211 | + spin_lock(&dentry->d_lock); | |
5527c038 | 20212 | + dentry->d_inode = d_inode(src_dentry); /* tmp */ |
c1595e42 | 20213 | + spin_unlock(&dentry->d_lock); |
392086de | 20214 | + h_file = au_h_open_pre(dentry, a->bsrc, /*force_wr*/0); |
86dc4139 | 20215 | + if (IS_ERR(h_file)) |
4a4d8108 | 20216 | + err = PTR_ERR(h_file); |
86dc4139 | 20217 | + else { |
c2b27bf2 AM |
20218 | + struct au_cp_generic cpg = { |
20219 | + .dentry = dentry, | |
20220 | + .bdst = a->bdst, | |
20221 | + .bsrc = -1, | |
20222 | + .len = -1, | |
20223 | + .pin = &a->pin, | |
20224 | + .flags = AuCpup_KEEPLINO | |
20225 | + }; | |
20226 | + err = au_sio_cpup_simple(&cpg); | |
86dc4139 AM |
20227 | + au_h_open_post(dentry, a->bsrc, h_file); |
20228 | + if (!err) { | |
20229 | + dput(a->h_path.dentry); | |
20230 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); | |
20231 | + } else | |
20232 | + au_set_h_dptr(dentry, a->bdst, | |
20233 | + a->h_path.dentry); | |
20234 | + } | |
c1595e42 | 20235 | + spin_lock(&dentry->d_lock); |
86dc4139 | 20236 | + dentry->d_inode = NULL; /* restore */ |
c1595e42 JR |
20237 | + spin_unlock(&dentry->d_lock); |
20238 | + AuDbg("temporary d_inode...done\n"); | |
86dc4139 | 20239 | + au_set_h_dptr(dentry, a->bsrc, NULL); |
5afbbe0d | 20240 | + au_set_dbbot(dentry, bbot); |
4a4d8108 AM |
20241 | + } else { |
20242 | + /* the inode of src_dentry already exists on a.bdst branch */ | |
20243 | + h_src_dentry = d_find_alias(h_inode); | |
20244 | + if (!h_src_dentry && au_plink_test(inode)) { | |
20245 | + plink = 1; | |
20246 | + h_src_dentry = au_plink_lkup(inode, a->bdst); | |
20247 | + err = PTR_ERR(h_src_dentry); | |
20248 | + if (IS_ERR(h_src_dentry)) | |
20249 | + goto out; | |
20250 | + | |
5527c038 | 20251 | + if (unlikely(d_is_negative(h_src_dentry))) { |
4a4d8108 AM |
20252 | + dput(h_src_dentry); |
20253 | + h_src_dentry = NULL; | |
20254 | + } | |
20255 | + | |
20256 | + } | |
20257 | + if (h_src_dentry) { | |
523b37e3 | 20258 | + delegated = NULL; |
4a4d8108 | 20259 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
20260 | + &a->h_path, &delegated); |
20261 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20262 | + pr_warn("cannot retry for NFSv4 delegation" | |
20263 | + " for an internal link\n"); | |
20264 | + iput(delegated); | |
20265 | + } | |
4a4d8108 AM |
20266 | + dput(h_src_dentry); |
20267 | + } else { | |
20268 | + AuIOErr("no dentry found for hi%lu on b%d\n", | |
20269 | + h_inode->i_ino, a->bdst); | |
20270 | + err = -EIO; | |
20271 | + } | |
20272 | + } | |
20273 | + | |
20274 | + if (!err && !plink) | |
20275 | + au_plink_append(inode, a->bdst, a->h_path.dentry); | |
20276 | + | |
20277 | +out: | |
2cbb1c4b | 20278 | + AuTraceErr(err); |
4a4d8108 AM |
20279 | + return err; |
20280 | +} | |
20281 | + | |
20282 | +int aufs_link(struct dentry *src_dentry, struct inode *dir, | |
20283 | + struct dentry *dentry) | |
20284 | +{ | |
20285 | + int err, rerr; | |
20286 | + struct au_dtime dt; | |
20287 | + struct au_link_args *a; | |
20288 | + struct dentry *wh_dentry, *h_src_dentry; | |
523b37e3 | 20289 | + struct inode *inode, *delegated; |
4a4d8108 AM |
20290 | + struct super_block *sb; |
20291 | + struct au_wr_dir_args wr_dir_args = { | |
20292 | + /* .force_btgt = -1, */ | |
20293 | + .flags = AuWrDir_ADD_ENTRY | |
20294 | + }; | |
20295 | + | |
20296 | + IMustLock(dir); | |
5527c038 | 20297 | + inode = d_inode(src_dentry); |
4a4d8108 AM |
20298 | + IMustLock(inode); |
20299 | + | |
4a4d8108 AM |
20300 | + err = -ENOMEM; |
20301 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
20302 | + if (unlikely(!a)) | |
20303 | + goto out; | |
20304 | + | |
20305 | + a->parent = dentry->d_parent; /* dir inode is locked */ | |
027c5e7a AM |
20306 | + err = aufs_read_and_write_lock2(dentry, src_dentry, |
20307 | + AuLock_NOPLM | AuLock_GEN); | |
e49829fe JR |
20308 | + if (unlikely(err)) |
20309 | + goto out_kfree; | |
38d290e6 | 20310 | + err = au_d_linkable(src_dentry); |
027c5e7a AM |
20311 | + if (unlikely(err)) |
20312 | + goto out_unlock; | |
20313 | + err = au_d_may_add(dentry); | |
20314 | + if (unlikely(err)) | |
20315 | + goto out_unlock; | |
e49829fe | 20316 | + |
4a4d8108 | 20317 | + a->src_parent = dget_parent(src_dentry); |
5afbbe0d | 20318 | + wr_dir_args.force_btgt = au_ibtop(inode); |
4a4d8108 AM |
20319 | + |
20320 | + di_write_lock_parent(a->parent); | |
20321 | + wr_dir_args.force_btgt = au_wbr(dentry, wr_dir_args.force_btgt); | |
20322 | + wh_dentry = lock_hdir_lkup_wh(dentry, &dt, src_dentry, &a->pin, | |
20323 | + &wr_dir_args); | |
20324 | + err = PTR_ERR(wh_dentry); | |
20325 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20326 | + goto out_parent; |
4a4d8108 AM |
20327 | + |
20328 | + err = 0; | |
20329 | + sb = dentry->d_sb; | |
5afbbe0d | 20330 | + a->bdst = au_dbtop(dentry); |
4a4d8108 AM |
20331 | + a->h_path.dentry = au_h_dptr(dentry, a->bdst); |
20332 | + a->h_path.mnt = au_sbr_mnt(sb, a->bdst); | |
5afbbe0d | 20333 | + a->bsrc = au_ibtop(inode); |
2cbb1c4b | 20334 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); |
38d290e6 JR |
20335 | + if (!h_src_dentry && au_di(src_dentry)->di_tmpfile) |
20336 | + h_src_dentry = dget(au_hi_wh(inode, a->bsrc)); | |
2cbb1c4b | 20337 | + if (!h_src_dentry) { |
5afbbe0d | 20338 | + a->bsrc = au_dbtop(src_dentry); |
2cbb1c4b JR |
20339 | + h_src_dentry = au_h_d_alias(src_dentry, a->bsrc); |
20340 | + AuDebugOn(!h_src_dentry); | |
38d290e6 JR |
20341 | + } else if (IS_ERR(h_src_dentry)) { |
20342 | + err = PTR_ERR(h_src_dentry); | |
2cbb1c4b | 20343 | + goto out_parent; |
38d290e6 | 20344 | + } |
2cbb1c4b | 20345 | + |
f2c43d5f AM |
20346 | + /* |
20347 | + * aufs doesn't touch the credential so | |
acd2b654 | 20348 | + * security_dentry_create_files_as() is unnecessary. |
f2c43d5f | 20349 | + */ |
4a4d8108 AM |
20350 | + if (au_opt_test(au_mntflags(sb), PLINK)) { |
20351 | + if (a->bdst < a->bsrc | |
20352 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) | |
86dc4139 | 20353 | + err = au_cpup_or_link(src_dentry, dentry, a); |
523b37e3 AM |
20354 | + else { |
20355 | + delegated = NULL; | |
4a4d8108 | 20356 | + err = vfsub_link(h_src_dentry, au_pinned_h_dir(&a->pin), |
523b37e3 AM |
20357 | + &a->h_path, &delegated); |
20358 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20359 | + pr_warn("cannot retry for NFSv4 delegation" | |
20360 | + " for an internal link\n"); | |
20361 | + iput(delegated); | |
20362 | + } | |
20363 | + } | |
2cbb1c4b | 20364 | + dput(h_src_dentry); |
4a4d8108 AM |
20365 | + } else { |
20366 | + /* | |
20367 | + * copyup src_dentry to the branch we process, | |
20368 | + * and then link(2) to it. | |
20369 | + */ | |
2cbb1c4b | 20370 | + dput(h_src_dentry); |
4a4d8108 AM |
20371 | + if (a->bdst < a->bsrc |
20372 | + /* && h_src_dentry->d_sb != a->h_path.dentry->d_sb */) { | |
20373 | + au_unpin(&a->pin); | |
20374 | + di_write_unlock(a->parent); | |
20375 | + err = au_cpup_before_link(src_dentry, a); | |
20376 | + di_write_lock_parent(a->parent); | |
20377 | + if (!err) | |
20378 | + err = au_pin(&a->pin, dentry, a->bdst, | |
20379 | + au_opt_udba(sb), | |
20380 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
20381 | + if (unlikely(err)) | |
20382 | + goto out_wh; | |
20383 | + } | |
20384 | + if (!err) { | |
20385 | + h_src_dentry = au_h_dptr(src_dentry, a->bdst); | |
20386 | + err = -ENOENT; | |
5527c038 | 20387 | + if (h_src_dentry && d_is_positive(h_src_dentry)) { |
523b37e3 | 20388 | + delegated = NULL; |
4a4d8108 AM |
20389 | + err = vfsub_link(h_src_dentry, |
20390 | + au_pinned_h_dir(&a->pin), | |
523b37e3 AM |
20391 | + &a->h_path, &delegated); |
20392 | + if (unlikely(err == -EWOULDBLOCK)) { | |
20393 | + pr_warn("cannot retry" | |
20394 | + " for NFSv4 delegation" | |
20395 | + " for an internal link\n"); | |
20396 | + iput(delegated); | |
20397 | + } | |
20398 | + } | |
4a4d8108 AM |
20399 | + } |
20400 | + } | |
20401 | + if (unlikely(err)) | |
20402 | + goto out_unpin; | |
20403 | + | |
20404 | + if (wh_dentry) { | |
20405 | + a->h_path.dentry = wh_dentry; | |
20406 | + err = au_wh_unlink_dentry(au_pinned_h_dir(&a->pin), &a->h_path, | |
20407 | + dentry); | |
20408 | + if (unlikely(err)) | |
20409 | + goto out_revert; | |
20410 | + } | |
20411 | + | |
b912730e | 20412 | + au_dir_ts(dir, a->bdst); |
be118d29 | 20413 | + inode_inc_iversion(dir); |
4a4d8108 AM |
20414 | + inc_nlink(inode); |
20415 | + inode->i_ctime = dir->i_ctime; | |
027c5e7a AM |
20416 | + d_instantiate(dentry, au_igrab(inode)); |
20417 | + if (d_unhashed(a->h_path.dentry)) | |
4a4d8108 AM |
20418 | + /* some filesystem calls d_drop() */ |
20419 | + d_drop(dentry); | |
076b876e AM |
20420 | + /* some filesystems consume an inode even hardlink */ |
20421 | + au_fhsm_wrote(sb, a->bdst, /*force*/0); | |
4a4d8108 AM |
20422 | + goto out_unpin; /* success */ |
20423 | + | |
4f0767ce | 20424 | +out_revert: |
523b37e3 AM |
20425 | + /* no delegation since it is just created */ |
20426 | + rerr = vfsub_unlink(au_pinned_h_dir(&a->pin), &a->h_path, | |
20427 | + /*delegated*/NULL, /*force*/0); | |
027c5e7a | 20428 | + if (unlikely(rerr)) { |
523b37e3 | 20429 | + AuIOErr("%pd reverting failed(%d, %d)\n", dentry, err, rerr); |
027c5e7a AM |
20430 | + err = -EIO; |
20431 | + } | |
4a4d8108 | 20432 | + au_dtime_revert(&dt); |
4f0767ce | 20433 | +out_unpin: |
4a4d8108 | 20434 | + au_unpin(&a->pin); |
4f0767ce | 20435 | +out_wh: |
4a4d8108 | 20436 | + dput(wh_dentry); |
027c5e7a AM |
20437 | +out_parent: |
20438 | + di_write_unlock(a->parent); | |
20439 | + dput(a->src_parent); | |
4f0767ce | 20440 | +out_unlock: |
4a4d8108 | 20441 | + if (unlikely(err)) { |
5afbbe0d | 20442 | + au_update_dbtop(dentry); |
4a4d8108 AM |
20443 | + d_drop(dentry); |
20444 | + } | |
4a4d8108 | 20445 | + aufs_read_and_write_unlock2(dentry, src_dentry); |
e49829fe | 20446 | +out_kfree: |
9f237c51 | 20447 | + au_kfree_rcu(a); |
4f0767ce | 20448 | +out: |
86dc4139 | 20449 | + AuTraceErr(err); |
4a4d8108 AM |
20450 | + return err; |
20451 | +} | |
20452 | + | |
7eafdf33 | 20453 | +int aufs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) |
4a4d8108 AM |
20454 | +{ |
20455 | + int err, rerr; | |
20456 | + aufs_bindex_t bindex; | |
20457 | + unsigned char diropq; | |
20458 | + struct path h_path; | |
20459 | + struct dentry *wh_dentry, *parent, *opq_dentry; | |
febd17d6 | 20460 | + struct inode *h_inode; |
4a4d8108 AM |
20461 | + struct super_block *sb; |
20462 | + struct { | |
20463 | + struct au_pin pin; | |
20464 | + struct au_dtime dt; | |
20465 | + } *a; /* reduce the stack usage */ | |
20466 | + struct au_wr_dir_args wr_dir_args = { | |
20467 | + .force_btgt = -1, | |
20468 | + .flags = AuWrDir_ADD_ENTRY | AuWrDir_ISDIR | |
20469 | + }; | |
20470 | + | |
20471 | + IMustLock(dir); | |
20472 | + | |
20473 | + err = -ENOMEM; | |
20474 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
20475 | + if (unlikely(!a)) | |
20476 | + goto out; | |
20477 | + | |
027c5e7a AM |
20478 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
20479 | + if (unlikely(err)) | |
20480 | + goto out_free; | |
20481 | + err = au_d_may_add(dentry); | |
20482 | + if (unlikely(err)) | |
20483 | + goto out_unlock; | |
20484 | + | |
4a4d8108 AM |
20485 | + parent = dentry->d_parent; /* dir inode is locked */ |
20486 | + di_write_lock_parent(parent); | |
20487 | + wh_dentry = lock_hdir_lkup_wh(dentry, &a->dt, /*src_dentry*/NULL, | |
20488 | + &a->pin, &wr_dir_args); | |
20489 | + err = PTR_ERR(wh_dentry); | |
20490 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 20491 | + goto out_parent; |
4a4d8108 AM |
20492 | + |
20493 | + sb = dentry->d_sb; | |
5afbbe0d | 20494 | + bindex = au_dbtop(dentry); |
4a4d8108 AM |
20495 | + h_path.dentry = au_h_dptr(dentry, bindex); |
20496 | + h_path.mnt = au_sbr_mnt(sb, bindex); | |
20497 | + err = vfsub_mkdir(au_pinned_h_dir(&a->pin), &h_path, mode); | |
20498 | + if (unlikely(err)) | |
027c5e7a | 20499 | + goto out_unpin; |
4a4d8108 AM |
20500 | + |
20501 | + /* make the dir opaque */ | |
20502 | + diropq = 0; | |
febd17d6 | 20503 | + h_inode = d_inode(h_path.dentry); |
4a4d8108 AM |
20504 | + if (wh_dentry |
20505 | + || au_opt_test(au_mntflags(sb), ALWAYS_DIROPQ)) { | |
febd17d6 | 20506 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
4a4d8108 | 20507 | + opq_dentry = au_diropq_create(dentry, bindex); |
febd17d6 | 20508 | + inode_unlock(h_inode); |
4a4d8108 AM |
20509 | + err = PTR_ERR(opq_dentry); |
20510 | + if (IS_ERR(opq_dentry)) | |
20511 | + goto out_dir; | |
20512 | + dput(opq_dentry); | |
20513 | + diropq = 1; | |
20514 | + } | |
20515 | + | |
20516 | + err = epilog(dir, bindex, wh_dentry, dentry); | |
20517 | + if (!err) { | |
20518 | + inc_nlink(dir); | |
027c5e7a | 20519 | + goto out_unpin; /* success */ |
4a4d8108 AM |
20520 | + } |
20521 | + | |
20522 | + /* revert */ | |
20523 | + if (diropq) { | |
20524 | + AuLabel(revert opq); | |
febd17d6 | 20525 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
4a4d8108 | 20526 | + rerr = au_diropq_remove(dentry, bindex); |
febd17d6 | 20527 | + inode_unlock(h_inode); |
4a4d8108 | 20528 | + if (rerr) { |
523b37e3 AM |
20529 | + AuIOErr("%pd reverting diropq failed(%d, %d)\n", |
20530 | + dentry, err, rerr); | |
4a4d8108 AM |
20531 | + err = -EIO; |
20532 | + } | |
20533 | + } | |
20534 | + | |
4f0767ce | 20535 | +out_dir: |
4a4d8108 AM |
20536 | + AuLabel(revert dir); |
20537 | + rerr = vfsub_rmdir(au_pinned_h_dir(&a->pin), &h_path); | |
20538 | + if (rerr) { | |
523b37e3 AM |
20539 | + AuIOErr("%pd reverting dir failed(%d, %d)\n", |
20540 | + dentry, err, rerr); | |
4a4d8108 AM |
20541 | + err = -EIO; |
20542 | + } | |
4a4d8108 | 20543 | + au_dtime_revert(&a->dt); |
027c5e7a | 20544 | +out_unpin: |
4a4d8108 AM |
20545 | + au_unpin(&a->pin); |
20546 | + dput(wh_dentry); | |
027c5e7a AM |
20547 | +out_parent: |
20548 | + di_write_unlock(parent); | |
20549 | +out_unlock: | |
4a4d8108 | 20550 | + if (unlikely(err)) { |
5afbbe0d | 20551 | + au_update_dbtop(dentry); |
4a4d8108 AM |
20552 | + d_drop(dentry); |
20553 | + } | |
4a4d8108 | 20554 | + aufs_read_unlock(dentry, AuLock_DW); |
027c5e7a | 20555 | +out_free: |
9f237c51 | 20556 | + au_kfree_rcu(a); |
4f0767ce | 20557 | +out: |
4a4d8108 AM |
20558 | + return err; |
20559 | +} | |
7f207e10 | 20560 | diff -urN /usr/share/empty/fs/aufs/i_op.c linux/fs/aufs/i_op.c |
eca34b5c | 20561 | --- /usr/share/empty/fs/aufs/i_op.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 20562 | +++ linux/fs/aufs/i_op.c 2020-01-27 10:57:18.172204883 +0100 |
43982f53 | 20563 | @@ -0,0 +1,1498 @@ |
cd7a4cd9 | 20564 | +// SPDX-License-Identifier: GPL-2.0 |
4a4d8108 | 20565 | +/* |
d58c55f2 | 20566 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
4a4d8108 AM |
20567 | + * |
20568 | + * This program, aufs is free software; you can redistribute it and/or modify | |
20569 | + * it under the terms of the GNU General Public License as published by | |
20570 | + * the Free Software Foundation; either version 2 of the License, or | |
20571 | + * (at your option) any later version. | |
20572 | + * | |
20573 | + * This program is distributed in the hope that it will be useful, | |
20574 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
20575 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20576 | + * GNU General Public License for more details. | |
20577 | + * | |
20578 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 20579 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
4a4d8108 | 20580 | + */ |
1facf9fc | 20581 | + |
1308ab2a | 20582 | +/* |
4a4d8108 | 20583 | + * inode operations (except add/del/rename) |
1308ab2a | 20584 | + */ |
4a4d8108 AM |
20585 | + |
20586 | +#include <linux/device_cgroup.h> | |
20587 | +#include <linux/fs_stack.h> | |
eca801bf | 20588 | +#include <linux/iversion.h> |
4a4d8108 AM |
20589 | +#include <linux/namei.h> |
20590 | +#include <linux/security.h> | |
4a4d8108 AM |
20591 | +#include "aufs.h" |
20592 | + | |
1e00d052 | 20593 | +static int h_permission(struct inode *h_inode, int mask, |
79b8bda9 | 20594 | + struct path *h_path, int brperm) |
1facf9fc | 20595 | +{ |
1308ab2a | 20596 | + int err; |
4a4d8108 | 20597 | + const unsigned char write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); |
1facf9fc | 20598 | + |
e2f27e51 AM |
20599 | + err = -EPERM; |
20600 | + if (write_mask && IS_IMMUTABLE(h_inode)) | |
20601 | + goto out; | |
20602 | + | |
4a4d8108 | 20603 | + err = -EACCES; |
e2f27e51 AM |
20604 | + if (((mask & MAY_EXEC) |
20605 | + && S_ISREG(h_inode->i_mode) | |
20606 | + && (path_noexec(h_path) | |
cd7a4cd9 | 20607 | + || !(h_inode->i_mode & 0111)))) |
4a4d8108 AM |
20608 | + goto out; |
20609 | + | |
20610 | + /* | |
20611 | + * - skip the lower fs test in the case of write to ro branch. | |
20612 | + * - nfs dir permission write check is optimized, but a policy for | |
20613 | + * link/rename requires a real check. | |
2121bcd9 | 20614 | + * - nfs always sets SB_POSIXACL regardless its mount option 'noacl.' |
b912730e | 20615 | + * in this case, generic_permission() returns -EOPNOTSUPP. |
4a4d8108 AM |
20616 | + */ |
20617 | + if ((write_mask && !au_br_writable(brperm)) | |
20618 | + || (au_test_nfs(h_inode->i_sb) && S_ISDIR(h_inode->i_mode) | |
20619 | + && write_mask && !(mask & MAY_READ)) | |
20620 | + || !h_inode->i_op->permission) { | |
20621 | + /* AuLabel(generic_permission); */ | |
062440b3 | 20622 | + /* AuDbg("get_acl %ps\n", h_inode->i_op->get_acl); */ |
1e00d052 | 20623 | + err = generic_permission(h_inode, mask); |
b912730e AM |
20624 | + if (err == -EOPNOTSUPP && au_test_nfs_noacl(h_inode)) |
20625 | + err = h_inode->i_op->permission(h_inode, mask); | |
20626 | + AuTraceErr(err); | |
1308ab2a | 20627 | + } else { |
4a4d8108 | 20628 | + /* AuLabel(h_inode->permission); */ |
1e00d052 | 20629 | + err = h_inode->i_op->permission(h_inode, mask); |
4a4d8108 AM |
20630 | + AuTraceErr(err); |
20631 | + } | |
1facf9fc | 20632 | + |
4a4d8108 AM |
20633 | + if (!err) |
20634 | + err = devcgroup_inode_permission(h_inode, mask); | |
7f207e10 | 20635 | + if (!err) |
4a4d8108 | 20636 | + err = security_inode_permission(h_inode, mask); |
4a4d8108 | 20637 | + |
4f0767ce | 20638 | +out: |
1308ab2a | 20639 | + return err; |
20640 | +} | |
dece6358 | 20641 | + |
1e00d052 | 20642 | +static int aufs_permission(struct inode *inode, int mask) |
1308ab2a | 20643 | +{ |
20644 | + int err; | |
5afbbe0d | 20645 | + aufs_bindex_t bindex, bbot; |
4a4d8108 AM |
20646 | + const unsigned char isdir = !!S_ISDIR(inode->i_mode), |
20647 | + write_mask = !!(mask & (MAY_WRITE | MAY_APPEND)); | |
20648 | + struct inode *h_inode; | |
20649 | + struct super_block *sb; | |
20650 | + struct au_branch *br; | |
1facf9fc | 20651 | + |
027c5e7a | 20652 | + /* todo: support rcu-walk? */ |
1e00d052 | 20653 | + if (mask & MAY_NOT_BLOCK) |
027c5e7a AM |
20654 | + return -ECHILD; |
20655 | + | |
4a4d8108 AM |
20656 | + sb = inode->i_sb; |
20657 | + si_read_lock(sb, AuLock_FLUSH); | |
20658 | + ii_read_lock_child(inode); | |
43982f53 AM |
20659 | +#if 0 /* reserved for future use */ |
20660 | + /* | |
20661 | + * This test may be rather 'too much' since the test is essentially done | |
20662 | + * in the aufs_lookup(). Theoretically it is possible that the inode | |
20663 | + * generation doesn't match to the superblock's here. But it isn't a | |
20664 | + * big deal I suppose. | |
20665 | + */ | |
027c5e7a AM |
20666 | + err = au_iigen_test(inode, au_sigen(sb)); |
20667 | + if (unlikely(err)) | |
20668 | + goto out; | |
20669 | +#endif | |
dece6358 | 20670 | + |
076b876e AM |
20671 | + if (!isdir |
20672 | + || write_mask | |
20673 | + || au_opt_test(au_mntflags(sb), DIRPERM1)) { | |
4a4d8108 | 20674 | + err = au_busy_or_stale(); |
5afbbe0d | 20675 | + h_inode = au_h_iptr(inode, au_ibtop(inode)); |
4a4d8108 AM |
20676 | + if (unlikely(!h_inode |
20677 | + || (h_inode->i_mode & S_IFMT) | |
20678 | + != (inode->i_mode & S_IFMT))) | |
20679 | + goto out; | |
1facf9fc | 20680 | + |
4a4d8108 | 20681 | + err = 0; |
5afbbe0d | 20682 | + bindex = au_ibtop(inode); |
4a4d8108 | 20683 | + br = au_sbr(sb, bindex); |
79b8bda9 | 20684 | + err = h_permission(h_inode, mask, &br->br_path, br->br_perm); |
4a4d8108 AM |
20685 | + if (write_mask |
20686 | + && !err | |
20687 | + && !special_file(h_inode->i_mode)) { | |
20688 | + /* test whether the upper writable branch exists */ | |
20689 | + err = -EROFS; | |
20690 | + for (; bindex >= 0; bindex--) | |
20691 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
20692 | + err = 0; | |
20693 | + break; | |
20694 | + } | |
20695 | + } | |
20696 | + goto out; | |
20697 | + } | |
dece6358 | 20698 | + |
4a4d8108 | 20699 | + /* non-write to dir */ |
1308ab2a | 20700 | + err = 0; |
5afbbe0d AM |
20701 | + bbot = au_ibbot(inode); |
20702 | + for (bindex = au_ibtop(inode); !err && bindex <= bbot; bindex++) { | |
4a4d8108 AM |
20703 | + h_inode = au_h_iptr(inode, bindex); |
20704 | + if (h_inode) { | |
20705 | + err = au_busy_or_stale(); | |
20706 | + if (unlikely(!S_ISDIR(h_inode->i_mode))) | |
20707 | + break; | |
20708 | + | |
20709 | + br = au_sbr(sb, bindex); | |
79b8bda9 | 20710 | + err = h_permission(h_inode, mask, &br->br_path, |
4a4d8108 AM |
20711 | + br->br_perm); |
20712 | + } | |
20713 | + } | |
1308ab2a | 20714 | + |
4f0767ce | 20715 | +out: |
4a4d8108 AM |
20716 | + ii_read_unlock(inode); |
20717 | + si_read_unlock(sb); | |
1308ab2a | 20718 | + return err; |
20719 | +} | |
20720 | + | |
4a4d8108 | 20721 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20722 | + |
4a4d8108 | 20723 | +static struct dentry *aufs_lookup(struct inode *dir, struct dentry *dentry, |
b4510431 | 20724 | + unsigned int flags) |
4a4d8108 AM |
20725 | +{ |
20726 | + struct dentry *ret, *parent; | |
b752ccd1 | 20727 | + struct inode *inode; |
4a4d8108 | 20728 | + struct super_block *sb; |
1716fcea | 20729 | + int err, npositive; |
dece6358 | 20730 | + |
4a4d8108 | 20731 | + IMustLock(dir); |
1308ab2a | 20732 | + |
537831f9 AM |
20733 | + /* todo: support rcu-walk? */ |
20734 | + ret = ERR_PTR(-ECHILD); | |
20735 | + if (flags & LOOKUP_RCU) | |
20736 | + goto out; | |
20737 | + | |
20738 | + ret = ERR_PTR(-ENAMETOOLONG); | |
20739 | + if (unlikely(dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
20740 | + goto out; | |
20741 | + | |
4a4d8108 | 20742 | + sb = dir->i_sb; |
7f207e10 AM |
20743 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
20744 | + ret = ERR_PTR(err); | |
20745 | + if (unlikely(err)) | |
20746 | + goto out; | |
20747 | + | |
4a4d8108 AM |
20748 | + err = au_di_init(dentry); |
20749 | + ret = ERR_PTR(err); | |
20750 | + if (unlikely(err)) | |
7f207e10 | 20751 | + goto out_si; |
1308ab2a | 20752 | + |
9dbd164d | 20753 | + inode = NULL; |
027c5e7a | 20754 | + npositive = 0; /* suppress a warning */ |
4a4d8108 AM |
20755 | + parent = dentry->d_parent; /* dir inode is locked */ |
20756 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a AM |
20757 | + err = au_alive_dir(parent); |
20758 | + if (!err) | |
20759 | + err = au_digen_test(parent, au_sigen(sb)); | |
20760 | + if (!err) { | |
5afbbe0d AM |
20761 | + /* regardless LOOKUP_CREATE, always ALLOW_NEG */ |
20762 | + npositive = au_lkup_dentry(dentry, au_dbtop(parent), | |
20763 | + AuLkup_ALLOW_NEG); | |
027c5e7a AM |
20764 | + err = npositive; |
20765 | + } | |
4a4d8108 | 20766 | + di_read_unlock(parent, AuLock_IR); |
4a4d8108 AM |
20767 | + ret = ERR_PTR(err); |
20768 | + if (unlikely(err < 0)) | |
20769 | + goto out_unlock; | |
1308ab2a | 20770 | + |
4a4d8108 | 20771 | + if (npositive) { |
b752ccd1 | 20772 | + inode = au_new_inode(dentry, /*must_new*/0); |
c1595e42 JR |
20773 | + if (IS_ERR(inode)) { |
20774 | + ret = (void *)inode; | |
20775 | + inode = NULL; | |
20776 | + goto out_unlock; | |
20777 | + } | |
9dbd164d | 20778 | + } |
4a4d8108 | 20779 | + |
c1595e42 JR |
20780 | + if (inode) |
20781 | + atomic_inc(&inode->i_count); | |
4a4d8108 | 20782 | + ret = d_splice_alias(inode, dentry); |
43982f53 | 20783 | +#if 0 /* reserved for future use */ |
537831f9 AM |
20784 | + if (unlikely(d_need_lookup(dentry))) { |
20785 | + spin_lock(&dentry->d_lock); | |
20786 | + dentry->d_flags &= ~DCACHE_NEED_LOOKUP; | |
20787 | + spin_unlock(&dentry->d_lock); | |
20788 | + } else | |
20789 | +#endif | |
c1595e42 | 20790 | + if (inode) { |
2000de60 | 20791 | + if (!IS_ERR(ret)) { |
c1595e42 | 20792 | + iput(inode); |
2000de60 JR |
20793 | + if (ret && ret != dentry) |
20794 | + ii_write_unlock(inode); | |
20795 | + } else { | |
c1595e42 JR |
20796 | + ii_write_unlock(inode); |
20797 | + iput(inode); | |
20798 | + inode = NULL; | |
20799 | + } | |
7f207e10 | 20800 | + } |
1facf9fc | 20801 | + |
4f0767ce | 20802 | +out_unlock: |
4a4d8108 | 20803 | + di_write_unlock(dentry); |
7f207e10 | 20804 | +out_si: |
4a4d8108 | 20805 | + si_read_unlock(sb); |
7f207e10 | 20806 | +out: |
4a4d8108 AM |
20807 | + return ret; |
20808 | +} | |
1facf9fc | 20809 | + |
4a4d8108 | 20810 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 20811 | + |
acd2b654 AM |
20812 | +/* |
20813 | + * very dirty and complicated aufs ->atomic_open(). | |
20814 | + * aufs_atomic_open() | |
20815 | + * + au_aopen_or_create() | |
20816 | + * + add_simple() | |
20817 | + * + vfsub_atomic_open() | |
20818 | + * + branch fs ->atomic_open() | |
20819 | + * may call the actual 'open' for h_file | |
20820 | + * + inc br_nfiles only if opened | |
20821 | + * + au_aopen_no_open() or au_aopen_do_open() | |
20822 | + * | |
20823 | + * au_aopen_do_open() | |
20824 | + * + finish_open() | |
20825 | + * + au_do_aopen() | |
20826 | + * + au_do_open() the body of all 'open' | |
20827 | + * + au_do_open_nondir() | |
20828 | + * set the passed h_file | |
20829 | + * | |
20830 | + * au_aopen_no_open() | |
20831 | + * + finish_no_open() | |
20832 | + */ | |
20833 | + | |
b912730e | 20834 | +struct aopen_node { |
8b6a4947 | 20835 | + struct hlist_bl_node hblist; |
b912730e AM |
20836 | + struct file *file, *h_file; |
20837 | +}; | |
20838 | + | |
20839 | +static int au_do_aopen(struct inode *inode, struct file *file) | |
20840 | +{ | |
8b6a4947 AM |
20841 | + struct hlist_bl_head *aopen; |
20842 | + struct hlist_bl_node *pos; | |
b912730e AM |
20843 | + struct aopen_node *node; |
20844 | + struct au_do_open_args args = { | |
8b6a4947 AM |
20845 | + .aopen = 1, |
20846 | + .open = au_do_open_nondir | |
b912730e AM |
20847 | + }; |
20848 | + | |
20849 | + aopen = &au_sbi(inode->i_sb)->si_aopen; | |
8b6a4947 AM |
20850 | + hlist_bl_lock(aopen); |
20851 | + hlist_bl_for_each_entry(node, pos, aopen, hblist) | |
b912730e AM |
20852 | + if (node->file == file) { |
20853 | + args.h_file = node->h_file; | |
20854 | + break; | |
20855 | + } | |
8b6a4947 | 20856 | + hlist_bl_unlock(aopen); |
b912730e AM |
20857 | + /* AuDebugOn(!args.h_file); */ |
20858 | + | |
20859 | + return au_do_open(file, &args); | |
20860 | +} | |
20861 | + | |
acd2b654 AM |
20862 | +static int au_aopen_do_open(struct file *file, struct dentry *dentry, |
20863 | + struct aopen_node *aopen_node) | |
20864 | +{ | |
20865 | + int err; | |
20866 | + struct hlist_bl_head *aopen; | |
20867 | + | |
20868 | + AuLabel(here); | |
20869 | + aopen = &au_sbi(dentry->d_sb)->si_aopen; | |
20870 | + au_hbl_add(&aopen_node->hblist, aopen); | |
20871 | + err = finish_open(file, dentry, au_do_aopen); | |
20872 | + au_hbl_del(&aopen_node->hblist, aopen); | |
20873 | + /* AuDbgFile(file); */ | |
20874 | + AuDbg("%pd%s%s\n", dentry, | |
20875 | + (file->f_mode & FMODE_CREATED) ? " created" : "", | |
20876 | + (file->f_mode & FMODE_OPENED) ? " opened" : ""); | |
20877 | + | |
20878 | + AuTraceErr(err); | |
20879 | + return err; | |
20880 | +} | |
20881 | + | |
20882 | +static int au_aopen_no_open(struct file *file, struct dentry *dentry) | |
20883 | +{ | |
20884 | + int err; | |
20885 | + | |
20886 | + AuLabel(here); | |
20887 | + dget(dentry); | |
20888 | + err = finish_no_open(file, dentry); | |
20889 | + | |
20890 | + AuTraceErr(err); | |
20891 | + return err; | |
20892 | +} | |
20893 | + | |
b912730e AM |
20894 | +static int aufs_atomic_open(struct inode *dir, struct dentry *dentry, |
20895 | + struct file *file, unsigned int open_flag, | |
acd2b654 | 20896 | + umode_t create_mode) |
b912730e | 20897 | +{ |
acd2b654 | 20898 | + int err, did_open; |
5afbbe0d | 20899 | + unsigned int lkup_flags; |
acd2b654 AM |
20900 | + aufs_bindex_t bindex; |
20901 | + struct super_block *sb; | |
f0c0a007 | 20902 | + struct dentry *parent, *d; |
b912730e AM |
20903 | + struct vfsub_aopen_args args = { |
20904 | + .open_flag = open_flag, | |
acd2b654 | 20905 | + .create_mode = create_mode |
b912730e AM |
20906 | + }; |
20907 | + struct aopen_node aopen_node = { | |
20908 | + .file = file | |
20909 | + }; | |
20910 | + | |
20911 | + IMustLock(dir); | |
5afbbe0d | 20912 | + AuDbg("open_flag 0%o\n", open_flag); |
b912730e AM |
20913 | + AuDbgDentry(dentry); |
20914 | + | |
20915 | + err = 0; | |
20916 | + if (!au_di(dentry)) { | |
5afbbe0d AM |
20917 | + lkup_flags = LOOKUP_OPEN; |
20918 | + if (open_flag & O_CREAT) | |
20919 | + lkup_flags |= LOOKUP_CREATE; | |
20920 | + d = aufs_lookup(dir, dentry, lkup_flags); | |
b912730e AM |
20921 | + if (IS_ERR(d)) { |
20922 | + err = PTR_ERR(d); | |
5afbbe0d | 20923 | + AuTraceErr(err); |
b912730e AM |
20924 | + goto out; |
20925 | + } else if (d) { | |
20926 | + /* | |
20927 | + * obsoleted dentry found. | |
20928 | + * another error will be returned later. | |
20929 | + */ | |
20930 | + d_drop(d); | |
b912730e | 20931 | + AuDbgDentry(d); |
5afbbe0d | 20932 | + dput(d); |
b912730e AM |
20933 | + } |
20934 | + AuDbgDentry(dentry); | |
20935 | + } | |
20936 | + | |
20937 | + if (d_is_positive(dentry) | |
20938 | + || d_unhashed(dentry) | |
20939 | + || d_unlinked(dentry) | |
acd2b654 AM |
20940 | + || !(open_flag & O_CREAT)) { |
20941 | + err = au_aopen_no_open(file, dentry); | |
20942 | + goto out; /* success */ | |
20943 | + } | |
b912730e AM |
20944 | + |
20945 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); | |
20946 | + if (unlikely(err)) | |
20947 | + goto out; | |
20948 | + | |
acd2b654 | 20949 | + sb = dentry->d_sb; |
b912730e AM |
20950 | + parent = dentry->d_parent; /* dir is locked */ |
20951 | + di_write_lock_parent(parent); | |
5afbbe0d | 20952 | + err = au_lkup_dentry(dentry, /*btop*/0, AuLkup_ALLOW_NEG); |
acd2b654 AM |
20953 | + if (unlikely(err < 0)) |
20954 | + goto out_parent; | |
b912730e AM |
20955 | + |
20956 | + AuDbgDentry(dentry); | |
acd2b654 AM |
20957 | + if (d_is_positive(dentry)) { |
20958 | + err = au_aopen_no_open(file, dentry); | |
20959 | + goto out_parent; /* success */ | |
20960 | + } | |
b912730e | 20961 | + |
acd2b654 | 20962 | + args.file = alloc_empty_file(file->f_flags, current_cred()); |
b912730e AM |
20963 | + err = PTR_ERR(args.file); |
20964 | + if (IS_ERR(args.file)) | |
acd2b654 | 20965 | + goto out_parent; |
b912730e | 20966 | + |
acd2b654 | 20967 | + bindex = au_dbtop(dentry); |
b912730e AM |
20968 | + err = au_aopen_or_create(dir, dentry, &args); |
20969 | + AuTraceErr(err); | |
20970 | + AuDbgFile(args.file); | |
acd2b654 AM |
20971 | + file->f_mode = args.file->f_mode & ~FMODE_OPENED; |
20972 | + did_open = !!(args.file->f_mode & FMODE_OPENED); | |
20973 | + if (!did_open) { | |
20974 | + fput(args.file); | |
20975 | + args.file = NULL; | |
b912730e | 20976 | + } |
8b6a4947 AM |
20977 | + di_write_unlock(parent); |
20978 | + di_write_unlock(dentry); | |
acd2b654 AM |
20979 | + if (unlikely(err < 0)) { |
20980 | + if (args.file) | |
20981 | + fput(args.file); | |
20982 | + goto out_sb; | |
b912730e | 20983 | + } |
b912730e | 20984 | + |
acd2b654 AM |
20985 | + if (!did_open) |
20986 | + err = au_aopen_no_open(file, dentry); | |
8b6a4947 | 20987 | + else { |
acd2b654 AM |
20988 | + aopen_node.h_file = args.file; |
20989 | + err = au_aopen_do_open(file, dentry, &aopen_node); | |
8b6a4947 | 20990 | + } |
acd2b654 AM |
20991 | + if (unlikely(err < 0)) { |
20992 | + if (args.file) | |
20993 | + fput(args.file); | |
20994 | + if (did_open) | |
20995 | + au_lcnt_dec(&args.br->br_nfiles); | |
b912730e | 20996 | + } |
acd2b654 AM |
20997 | + goto out_sb; /* success */ |
20998 | + | |
20999 | +out_parent: | |
21000 | + di_write_unlock(parent); | |
21001 | + di_write_unlock(dentry); | |
21002 | +out_sb: | |
21003 | + si_read_unlock(sb); | |
b912730e | 21004 | +out: |
b912730e | 21005 | + AuTraceErr(err); |
acd2b654 | 21006 | + AuDbgFile(file); |
b912730e AM |
21007 | + return err; |
21008 | +} | |
21009 | + | |
21010 | + | |
21011 | +/* ---------------------------------------------------------------------- */ | |
21012 | + | |
4a4d8108 AM |
21013 | +static int au_wr_dir_cpup(struct dentry *dentry, struct dentry *parent, |
21014 | + const unsigned char add_entry, aufs_bindex_t bcpup, | |
5afbbe0d | 21015 | + aufs_bindex_t btop) |
4a4d8108 AM |
21016 | +{ |
21017 | + int err; | |
21018 | + struct dentry *h_parent; | |
21019 | + struct inode *h_dir; | |
1facf9fc | 21020 | + |
027c5e7a | 21021 | + if (add_entry) |
5527c038 | 21022 | + IMustLock(d_inode(parent)); |
027c5e7a | 21023 | + else |
4a4d8108 AM |
21024 | + di_write_lock_parent(parent); |
21025 | + | |
21026 | + err = 0; | |
21027 | + if (!au_h_dptr(parent, bcpup)) { | |
5afbbe0d | 21028 | + if (btop > bcpup) |
c2b27bf2 | 21029 | + err = au_cpup_dirs(dentry, bcpup); |
5afbbe0d | 21030 | + else if (btop < bcpup) |
4a4d8108 AM |
21031 | + err = au_cpdown_dirs(dentry, bcpup); |
21032 | + else | |
c2b27bf2 | 21033 | + BUG(); |
4a4d8108 | 21034 | + } |
38d290e6 | 21035 | + if (!err && add_entry && !au_ftest_wrdir(add_entry, TMPFILE)) { |
4a4d8108 | 21036 | + h_parent = au_h_dptr(parent, bcpup); |
5527c038 | 21037 | + h_dir = d_inode(h_parent); |
be118d29 | 21038 | + inode_lock_shared_nested(h_dir, AuLsc_I_PARENT); |
7e9cd9fe | 21039 | + err = au_lkup_neg(dentry, bcpup, /*wh*/0); |
4a4d8108 | 21040 | + /* todo: no unlock here */ |
3c1bdaff | 21041 | + inode_unlock_shared(h_dir); |
027c5e7a AM |
21042 | + |
21043 | + AuDbg("bcpup %d\n", bcpup); | |
21044 | + if (!err) { | |
5527c038 | 21045 | + if (d_really_is_negative(dentry)) |
5afbbe0d | 21046 | + au_set_h_dptr(dentry, btop, NULL); |
4a4d8108 AM |
21047 | + au_update_dbrange(dentry, /*do_put_zero*/0); |
21048 | + } | |
1308ab2a | 21049 | + } |
1facf9fc | 21050 | + |
4a4d8108 AM |
21051 | + if (!add_entry) |
21052 | + di_write_unlock(parent); | |
21053 | + if (!err) | |
21054 | + err = bcpup; /* success */ | |
1308ab2a | 21055 | + |
027c5e7a | 21056 | + AuTraceErr(err); |
4a4d8108 AM |
21057 | + return err; |
21058 | +} | |
1facf9fc | 21059 | + |
4a4d8108 AM |
21060 | +/* |
21061 | + * decide the branch and the parent dir where we will create a new entry. | |
21062 | + * returns new bindex or an error. | |
21063 | + * copyup the parent dir if needed. | |
21064 | + */ | |
21065 | +int au_wr_dir(struct dentry *dentry, struct dentry *src_dentry, | |
21066 | + struct au_wr_dir_args *args) | |
21067 | +{ | |
21068 | + int err; | |
392086de | 21069 | + unsigned int flags; |
5afbbe0d | 21070 | + aufs_bindex_t bcpup, btop, src_btop; |
86dc4139 AM |
21071 | + const unsigned char add_entry |
21072 | + = au_ftest_wrdir(args->flags, ADD_ENTRY) | |
38d290e6 | 21073 | + | au_ftest_wrdir(args->flags, TMPFILE); |
4a4d8108 AM |
21074 | + struct super_block *sb; |
21075 | + struct dentry *parent; | |
21076 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 21077 | + |
4a4d8108 AM |
21078 | + sb = dentry->d_sb; |
21079 | + sbinfo = au_sbi(sb); | |
21080 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
21081 | + btop = au_dbtop(dentry); |
21082 | + bcpup = btop; | |
4a4d8108 AM |
21083 | + if (args->force_btgt < 0) { |
21084 | + if (src_dentry) { | |
5afbbe0d AM |
21085 | + src_btop = au_dbtop(src_dentry); |
21086 | + if (src_btop < btop) | |
21087 | + bcpup = src_btop; | |
4a4d8108 | 21088 | + } else if (add_entry) { |
392086de AM |
21089 | + flags = 0; |
21090 | + if (au_ftest_wrdir(args->flags, ISDIR)) | |
21091 | + au_fset_wbr(flags, DIR); | |
21092 | + err = AuWbrCreate(sbinfo, dentry, flags); | |
4a4d8108 AM |
21093 | + bcpup = err; |
21094 | + } | |
1facf9fc | 21095 | + |
5527c038 | 21096 | + if (bcpup < 0 || au_test_ro(sb, bcpup, d_inode(dentry))) { |
4a4d8108 AM |
21097 | + if (add_entry) |
21098 | + err = AuWbrCopyup(sbinfo, dentry); | |
21099 | + else { | |
21100 | + if (!IS_ROOT(dentry)) { | |
21101 | + di_read_lock_parent(parent, !AuLock_IR); | |
21102 | + err = AuWbrCopyup(sbinfo, dentry); | |
21103 | + di_read_unlock(parent, !AuLock_IR); | |
21104 | + } else | |
21105 | + err = AuWbrCopyup(sbinfo, dentry); | |
21106 | + } | |
21107 | + bcpup = err; | |
21108 | + if (unlikely(err < 0)) | |
21109 | + goto out; | |
21110 | + } | |
21111 | + } else { | |
21112 | + bcpup = args->force_btgt; | |
5527c038 | 21113 | + AuDebugOn(au_test_ro(sb, bcpup, d_inode(dentry))); |
1308ab2a | 21114 | + } |
027c5e7a | 21115 | + |
5afbbe0d | 21116 | + AuDbg("btop %d, bcpup %d\n", btop, bcpup); |
4a4d8108 | 21117 | + err = bcpup; |
5afbbe0d | 21118 | + if (bcpup == btop) |
4a4d8108 | 21119 | + goto out; /* success */ |
4a4d8108 AM |
21120 | + |
21121 | + /* copyup the new parent into the branch we process */ | |
5afbbe0d | 21122 | + err = au_wr_dir_cpup(dentry, parent, add_entry, bcpup, btop); |
027c5e7a | 21123 | + if (err >= 0) { |
5527c038 | 21124 | + if (d_really_is_negative(dentry)) { |
5afbbe0d AM |
21125 | + au_set_h_dptr(dentry, btop, NULL); |
21126 | + au_set_dbtop(dentry, bcpup); | |
21127 | + au_set_dbbot(dentry, bcpup); | |
027c5e7a | 21128 | + } |
38d290e6 JR |
21129 | + AuDebugOn(add_entry |
21130 | + && !au_ftest_wrdir(args->flags, TMPFILE) | |
21131 | + && !au_h_dptr(dentry, bcpup)); | |
027c5e7a | 21132 | + } |
86dc4139 AM |
21133 | + |
21134 | +out: | |
21135 | + dput(parent); | |
21136 | + return err; | |
21137 | +} | |
21138 | + | |
21139 | +/* ---------------------------------------------------------------------- */ | |
21140 | + | |
21141 | +void au_pin_hdir_unlock(struct au_pin *p) | |
21142 | +{ | |
21143 | + if (p->hdir) | |
5afbbe0d | 21144 | + au_hn_inode_unlock(p->hdir); |
86dc4139 AM |
21145 | +} |
21146 | + | |
c1595e42 | 21147 | +int au_pin_hdir_lock(struct au_pin *p) |
86dc4139 AM |
21148 | +{ |
21149 | + int err; | |
21150 | + | |
21151 | + err = 0; | |
21152 | + if (!p->hdir) | |
21153 | + goto out; | |
21154 | + | |
21155 | + /* even if an error happens later, keep this lock */ | |
5afbbe0d | 21156 | + au_hn_inode_lock_nested(p->hdir, p->lsc_hi); |
86dc4139 AM |
21157 | + |
21158 | + err = -EBUSY; | |
5527c038 | 21159 | + if (unlikely(p->hdir->hi_inode != d_inode(p->h_parent))) |
86dc4139 AM |
21160 | + goto out; |
21161 | + | |
21162 | + err = 0; | |
21163 | + if (p->h_dentry) | |
21164 | + err = au_h_verify(p->h_dentry, p->udba, p->hdir->hi_inode, | |
21165 | + p->h_parent, p->br); | |
21166 | + | |
21167 | +out: | |
21168 | + return err; | |
21169 | +} | |
21170 | + | |
21171 | +int au_pin_hdir_relock(struct au_pin *p) | |
21172 | +{ | |
21173 | + int err, i; | |
21174 | + struct inode *h_i; | |
21175 | + struct dentry *h_d[] = { | |
21176 | + p->h_dentry, | |
21177 | + p->h_parent | |
21178 | + }; | |
21179 | + | |
21180 | + err = au_pin_hdir_lock(p); | |
21181 | + if (unlikely(err)) | |
21182 | + goto out; | |
21183 | + | |
21184 | + for (i = 0; !err && i < sizeof(h_d)/sizeof(*h_d); i++) { | |
21185 | + if (!h_d[i]) | |
21186 | + continue; | |
5527c038 JR |
21187 | + if (d_is_positive(h_d[i])) { |
21188 | + h_i = d_inode(h_d[i]); | |
86dc4139 | 21189 | + err = !h_i->i_nlink; |
5527c038 | 21190 | + } |
86dc4139 AM |
21191 | + } |
21192 | + | |
21193 | +out: | |
21194 | + return err; | |
21195 | +} | |
21196 | + | |
5afbbe0d | 21197 | +static void au_pin_hdir_set_owner(struct au_pin *p, struct task_struct *task) |
86dc4139 | 21198 | +{ |
eca34b5c | 21199 | + atomic_long_set(&p->hdir->hi_inode->i_rwsem.owner, (long)task); |
86dc4139 AM |
21200 | +} |
21201 | + | |
21202 | +void au_pin_hdir_acquire_nest(struct au_pin *p) | |
21203 | +{ | |
21204 | + if (p->hdir) { | |
5afbbe0d | 21205 | + rwsem_acquire_nest(&p->hdir->hi_inode->i_rwsem.dep_map, |
86dc4139 AM |
21206 | + p->lsc_hi, 0, NULL, _RET_IP_); |
21207 | + au_pin_hdir_set_owner(p, current); | |
21208 | + } | |
dece6358 | 21209 | +} |
1facf9fc | 21210 | + |
86dc4139 AM |
21211 | +void au_pin_hdir_release(struct au_pin *p) |
21212 | +{ | |
21213 | + if (p->hdir) { | |
21214 | + au_pin_hdir_set_owner(p, p->task); | |
d58c55f2 | 21215 | + rwsem_release(&p->hdir->hi_inode->i_rwsem.dep_map, _RET_IP_); |
86dc4139 AM |
21216 | + } |
21217 | +} | |
1308ab2a | 21218 | + |
4a4d8108 | 21219 | +struct dentry *au_pinned_h_parent(struct au_pin *pin) |
1308ab2a | 21220 | +{ |
4a4d8108 AM |
21221 | + if (pin && pin->parent) |
21222 | + return au_h_dptr(pin->parent, pin->bindex); | |
21223 | + return NULL; | |
dece6358 | 21224 | +} |
1facf9fc | 21225 | + |
4a4d8108 | 21226 | +void au_unpin(struct au_pin *p) |
dece6358 | 21227 | +{ |
86dc4139 AM |
21228 | + if (p->hdir) |
21229 | + au_pin_hdir_unlock(p); | |
e49829fe | 21230 | + if (p->h_mnt && au_ftest_pin(p->flags, MNT_WRITE)) |
b4510431 | 21231 | + vfsub_mnt_drop_write(p->h_mnt); |
4a4d8108 AM |
21232 | + if (!p->hdir) |
21233 | + return; | |
1facf9fc | 21234 | + |
4a4d8108 AM |
21235 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
21236 | + di_read_unlock(p->parent, AuLock_IR); | |
21237 | + iput(p->hdir->hi_inode); | |
21238 | + dput(p->parent); | |
21239 | + p->parent = NULL; | |
21240 | + p->hdir = NULL; | |
21241 | + p->h_mnt = NULL; | |
86dc4139 | 21242 | + /* do not clear p->task */ |
4a4d8108 | 21243 | +} |
1308ab2a | 21244 | + |
4a4d8108 AM |
21245 | +int au_do_pin(struct au_pin *p) |
21246 | +{ | |
21247 | + int err; | |
21248 | + struct super_block *sb; | |
4a4d8108 AM |
21249 | + struct inode *h_dir; |
21250 | + | |
21251 | + err = 0; | |
21252 | + sb = p->dentry->d_sb; | |
86dc4139 | 21253 | + p->br = au_sbr(sb, p->bindex); |
4a4d8108 AM |
21254 | + if (IS_ROOT(p->dentry)) { |
21255 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { | |
86dc4139 | 21256 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 21257 | + err = vfsub_mnt_want_write(p->h_mnt); |
4a4d8108 AM |
21258 | + if (unlikely(err)) { |
21259 | + au_fclr_pin(p->flags, MNT_WRITE); | |
21260 | + goto out_err; | |
21261 | + } | |
21262 | + } | |
dece6358 | 21263 | + goto out; |
1facf9fc | 21264 | + } |
21265 | + | |
86dc4139 | 21266 | + p->h_dentry = NULL; |
5afbbe0d | 21267 | + if (p->bindex <= au_dbbot(p->dentry)) |
86dc4139 | 21268 | + p->h_dentry = au_h_dptr(p->dentry, p->bindex); |
dece6358 | 21269 | + |
4a4d8108 AM |
21270 | + p->parent = dget_parent(p->dentry); |
21271 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) | |
21272 | + di_read_lock(p->parent, AuLock_IR, p->lsc_di); | |
dece6358 | 21273 | + |
4a4d8108 | 21274 | + h_dir = NULL; |
86dc4139 | 21275 | + p->h_parent = au_h_dptr(p->parent, p->bindex); |
5527c038 | 21276 | + p->hdir = au_hi(d_inode(p->parent), p->bindex); |
4a4d8108 AM |
21277 | + if (p->hdir) |
21278 | + h_dir = p->hdir->hi_inode; | |
dece6358 | 21279 | + |
b752ccd1 AM |
21280 | + /* |
21281 | + * udba case, or | |
21282 | + * if DI_LOCKED is not set, then p->parent may be different | |
21283 | + * and h_parent can be NULL. | |
21284 | + */ | |
86dc4139 | 21285 | + if (unlikely(!p->hdir || !h_dir || !p->h_parent)) { |
e49829fe | 21286 | + err = -EBUSY; |
4a4d8108 AM |
21287 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
21288 | + di_read_unlock(p->parent, AuLock_IR); | |
21289 | + dput(p->parent); | |
21290 | + p->parent = NULL; | |
21291 | + goto out_err; | |
21292 | + } | |
1308ab2a | 21293 | + |
4a4d8108 | 21294 | + if (au_ftest_pin(p->flags, MNT_WRITE)) { |
86dc4139 | 21295 | + p->h_mnt = au_br_mnt(p->br); |
b4510431 | 21296 | + err = vfsub_mnt_want_write(p->h_mnt); |
dece6358 | 21297 | + if (unlikely(err)) { |
4a4d8108 | 21298 | + au_fclr_pin(p->flags, MNT_WRITE); |
86dc4139 AM |
21299 | + if (!au_ftest_pin(p->flags, DI_LOCKED)) |
21300 | + di_read_unlock(p->parent, AuLock_IR); | |
21301 | + dput(p->parent); | |
21302 | + p->parent = NULL; | |
21303 | + goto out_err; | |
dece6358 AM |
21304 | + } |
21305 | + } | |
4a4d8108 | 21306 | + |
86dc4139 AM |
21307 | + au_igrab(h_dir); |
21308 | + err = au_pin_hdir_lock(p); | |
21309 | + if (!err) | |
21310 | + goto out; /* success */ | |
21311 | + | |
076b876e AM |
21312 | + au_unpin(p); |
21313 | + | |
4f0767ce | 21314 | +out_err: |
4a4d8108 AM |
21315 | + pr_err("err %d\n", err); |
21316 | + err = au_busy_or_stale(); | |
4f0767ce | 21317 | +out: |
1facf9fc | 21318 | + return err; |
21319 | +} | |
21320 | + | |
4a4d8108 AM |
21321 | +void au_pin_init(struct au_pin *p, struct dentry *dentry, |
21322 | + aufs_bindex_t bindex, int lsc_di, int lsc_hi, | |
21323 | + unsigned int udba, unsigned char flags) | |
21324 | +{ | |
21325 | + p->dentry = dentry; | |
21326 | + p->udba = udba; | |
21327 | + p->lsc_di = lsc_di; | |
21328 | + p->lsc_hi = lsc_hi; | |
21329 | + p->flags = flags; | |
21330 | + p->bindex = bindex; | |
21331 | + | |
21332 | + p->parent = NULL; | |
21333 | + p->hdir = NULL; | |
21334 | + p->h_mnt = NULL; | |
86dc4139 AM |
21335 | + |
21336 | + p->h_dentry = NULL; | |
21337 | + p->h_parent = NULL; | |
21338 | + p->br = NULL; | |
21339 | + p->task = current; | |
4a4d8108 AM |
21340 | +} |
21341 | + | |
21342 | +int au_pin(struct au_pin *pin, struct dentry *dentry, aufs_bindex_t bindex, | |
21343 | + unsigned int udba, unsigned char flags) | |
21344 | +{ | |
21345 | + au_pin_init(pin, dentry, bindex, AuLsc_DI_PARENT, AuLsc_I_PARENT2, | |
21346 | + udba, flags); | |
21347 | + return au_do_pin(pin); | |
21348 | +} | |
21349 | + | |
dece6358 AM |
21350 | +/* ---------------------------------------------------------------------- */ |
21351 | + | |
1308ab2a | 21352 | +/* |
4a4d8108 AM |
21353 | + * ->setattr() and ->getattr() are called in various cases. |
21354 | + * chmod, stat: dentry is revalidated. | |
21355 | + * fchmod, fstat: file and dentry are not revalidated, additionally they may be | |
21356 | + * unhashed. | |
21357 | + * for ->setattr(), ia->ia_file is passed from ftruncate only. | |
1308ab2a | 21358 | + */ |
027c5e7a | 21359 | +/* todo: consolidate with do_refresh() and simple_reval_dpath() */ |
c1595e42 | 21360 | +int au_reval_for_attr(struct dentry *dentry, unsigned int sigen) |
1facf9fc | 21361 | +{ |
4a4d8108 | 21362 | + int err; |
4a4d8108 | 21363 | + struct dentry *parent; |
1facf9fc | 21364 | + |
1308ab2a | 21365 | + err = 0; |
027c5e7a | 21366 | + if (au_digen_test(dentry, sigen)) { |
4a4d8108 AM |
21367 | + parent = dget_parent(dentry); |
21368 | + di_read_lock_parent(parent, AuLock_IR); | |
027c5e7a | 21369 | + err = au_refresh_dentry(dentry, parent); |
4a4d8108 AM |
21370 | + di_read_unlock(parent, AuLock_IR); |
21371 | + dput(parent); | |
dece6358 | 21372 | + } |
1facf9fc | 21373 | + |
4a4d8108 | 21374 | + AuTraceErr(err); |
1308ab2a | 21375 | + return err; |
21376 | +} | |
dece6358 | 21377 | + |
c1595e42 JR |
21378 | +int au_pin_and_icpup(struct dentry *dentry, struct iattr *ia, |
21379 | + struct au_icpup_args *a) | |
1308ab2a | 21380 | +{ |
21381 | + int err; | |
4a4d8108 | 21382 | + loff_t sz; |
5afbbe0d | 21383 | + aufs_bindex_t btop, ibtop; |
4a4d8108 AM |
21384 | + struct dentry *hi_wh, *parent; |
21385 | + struct inode *inode; | |
4a4d8108 AM |
21386 | + struct au_wr_dir_args wr_dir_args = { |
21387 | + .force_btgt = -1, | |
21388 | + .flags = 0 | |
21389 | + }; | |
21390 | + | |
2000de60 | 21391 | + if (d_is_dir(dentry)) |
4a4d8108 AM |
21392 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
21393 | + /* plink or hi_wh() case */ | |
5afbbe0d | 21394 | + btop = au_dbtop(dentry); |
5527c038 | 21395 | + inode = d_inode(dentry); |
5afbbe0d AM |
21396 | + ibtop = au_ibtop(inode); |
21397 | + if (btop != ibtop && !au_test_ro(inode->i_sb, ibtop, inode)) | |
21398 | + wr_dir_args.force_btgt = ibtop; | |
4a4d8108 AM |
21399 | + err = au_wr_dir(dentry, /*src_dentry*/NULL, &wr_dir_args); |
21400 | + if (unlikely(err < 0)) | |
21401 | + goto out; | |
21402 | + a->btgt = err; | |
5afbbe0d | 21403 | + if (err != btop) |
4a4d8108 AM |
21404 | + au_fset_icpup(a->flags, DID_CPUP); |
21405 | + | |
21406 | + err = 0; | |
21407 | + a->pin_flags = AuPin_MNT_WRITE; | |
21408 | + parent = NULL; | |
21409 | + if (!IS_ROOT(dentry)) { | |
21410 | + au_fset_pin(a->pin_flags, DI_LOCKED); | |
21411 | + parent = dget_parent(dentry); | |
21412 | + di_write_lock_parent(parent); | |
21413 | + } | |
21414 | + | |
21415 | + err = au_pin(&a->pin, dentry, a->btgt, a->udba, a->pin_flags); | |
21416 | + if (unlikely(err)) | |
21417 | + goto out_parent; | |
21418 | + | |
4a4d8108 | 21419 | + sz = -1; |
5afbbe0d | 21420 | + a->h_path.dentry = au_h_dptr(dentry, btop); |
5527c038 | 21421 | + a->h_inode = d_inode(a->h_path.dentry); |
c1595e42 | 21422 | + if (ia && (ia->ia_valid & ATTR_SIZE)) { |
be118d29 | 21423 | + inode_lock_shared_nested(a->h_inode, AuLsc_I_CHILD); |
c1595e42 JR |
21424 | + if (ia->ia_size < i_size_read(a->h_inode)) |
21425 | + sz = ia->ia_size; | |
3c1bdaff | 21426 | + inode_unlock_shared(a->h_inode); |
c1595e42 | 21427 | + } |
4a4d8108 | 21428 | + |
4a4d8108 | 21429 | + hi_wh = NULL; |
027c5e7a | 21430 | + if (au_ftest_icpup(a->flags, DID_CPUP) && d_unlinked(dentry)) { |
4a4d8108 AM |
21431 | + hi_wh = au_hi_wh(inode, a->btgt); |
21432 | + if (!hi_wh) { | |
c2b27bf2 AM |
21433 | + struct au_cp_generic cpg = { |
21434 | + .dentry = dentry, | |
21435 | + .bdst = a->btgt, | |
21436 | + .bsrc = -1, | |
21437 | + .len = sz, | |
21438 | + .pin = &a->pin | |
21439 | + }; | |
21440 | + err = au_sio_cpup_wh(&cpg, /*file*/NULL); | |
4a4d8108 AM |
21441 | + if (unlikely(err)) |
21442 | + goto out_unlock; | |
21443 | + hi_wh = au_hi_wh(inode, a->btgt); | |
21444 | + /* todo: revalidate hi_wh? */ | |
21445 | + } | |
21446 | + } | |
21447 | + | |
21448 | + if (parent) { | |
21449 | + au_pin_set_parent_lflag(&a->pin, /*lflag*/0); | |
21450 | + di_downgrade_lock(parent, AuLock_IR); | |
21451 | + dput(parent); | |
21452 | + parent = NULL; | |
21453 | + } | |
21454 | + if (!au_ftest_icpup(a->flags, DID_CPUP)) | |
21455 | + goto out; /* success */ | |
21456 | + | |
21457 | + if (!d_unhashed(dentry)) { | |
c2b27bf2 AM |
21458 | + struct au_cp_generic cpg = { |
21459 | + .dentry = dentry, | |
21460 | + .bdst = a->btgt, | |
5afbbe0d | 21461 | + .bsrc = btop, |
c2b27bf2 AM |
21462 | + .len = sz, |
21463 | + .pin = &a->pin, | |
21464 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
21465 | + }; | |
21466 | + err = au_sio_cpup_simple(&cpg); | |
4a4d8108 AM |
21467 | + if (!err) |
21468 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
21469 | + } else if (!hi_wh) | |
21470 | + a->h_path.dentry = au_h_dptr(dentry, a->btgt); | |
21471 | + else | |
21472 | + a->h_path.dentry = hi_wh; /* do not dget here */ | |
1308ab2a | 21473 | + |
4f0767ce | 21474 | +out_unlock: |
5527c038 | 21475 | + a->h_inode = d_inode(a->h_path.dentry); |
86dc4139 | 21476 | + if (!err) |
dece6358 | 21477 | + goto out; /* success */ |
4a4d8108 | 21478 | + au_unpin(&a->pin); |
4f0767ce | 21479 | +out_parent: |
4a4d8108 AM |
21480 | + if (parent) { |
21481 | + di_write_unlock(parent); | |
21482 | + dput(parent); | |
21483 | + } | |
4f0767ce | 21484 | +out: |
86dc4139 | 21485 | + if (!err) |
febd17d6 | 21486 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
1facf9fc | 21487 | + return err; |
21488 | +} | |
21489 | + | |
4a4d8108 | 21490 | +static int aufs_setattr(struct dentry *dentry, struct iattr *ia) |
1facf9fc | 21491 | +{ |
4a4d8108 | 21492 | + int err; |
523b37e3 | 21493 | + struct inode *inode, *delegated; |
4a4d8108 AM |
21494 | + struct super_block *sb; |
21495 | + struct file *file; | |
21496 | + struct au_icpup_args *a; | |
1facf9fc | 21497 | + |
5527c038 | 21498 | + inode = d_inode(dentry); |
4a4d8108 | 21499 | + IMustLock(inode); |
dece6358 | 21500 | + |
f2c43d5f AM |
21501 | + err = setattr_prepare(dentry, ia); |
21502 | + if (unlikely(err)) | |
21503 | + goto out; | |
21504 | + | |
4a4d8108 AM |
21505 | + err = -ENOMEM; |
21506 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
21507 | + if (unlikely(!a)) | |
21508 | + goto out; | |
1facf9fc | 21509 | + |
4a4d8108 AM |
21510 | + if (ia->ia_valid & (ATTR_KILL_SUID | ATTR_KILL_SGID)) |
21511 | + ia->ia_valid &= ~ATTR_MODE; | |
dece6358 | 21512 | + |
4a4d8108 AM |
21513 | + file = NULL; |
21514 | + sb = dentry->d_sb; | |
e49829fe JR |
21515 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
21516 | + if (unlikely(err)) | |
21517 | + goto out_kfree; | |
21518 | + | |
4a4d8108 AM |
21519 | + if (ia->ia_valid & ATTR_FILE) { |
21520 | + /* currently ftruncate(2) only */ | |
7e9cd9fe | 21521 | + AuDebugOn(!d_is_reg(dentry)); |
4a4d8108 | 21522 | + file = ia->ia_file; |
521ced18 JR |
21523 | + err = au_reval_and_lock_fdi(file, au_reopen_nondir, /*wlock*/1, |
21524 | + /*fi_lsc*/0); | |
4a4d8108 AM |
21525 | + if (unlikely(err)) |
21526 | + goto out_si; | |
21527 | + ia->ia_file = au_hf_top(file); | |
21528 | + a->udba = AuOpt_UDBA_NONE; | |
21529 | + } else { | |
21530 | + /* fchmod() doesn't pass ia_file */ | |
21531 | + a->udba = au_opt_udba(sb); | |
027c5e7a AM |
21532 | + di_write_lock_child(dentry); |
21533 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
4a4d8108 AM |
21534 | + if (d_unhashed(dentry)) |
21535 | + a->udba = AuOpt_UDBA_NONE; | |
4a4d8108 AM |
21536 | + if (a->udba != AuOpt_UDBA_NONE) { |
21537 | + AuDebugOn(IS_ROOT(dentry)); | |
21538 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
21539 | + if (unlikely(err)) | |
21540 | + goto out_dentry; | |
21541 | + } | |
dece6358 | 21542 | + } |
dece6358 | 21543 | + |
4a4d8108 AM |
21544 | + err = au_pin_and_icpup(dentry, ia, a); |
21545 | + if (unlikely(err < 0)) | |
21546 | + goto out_dentry; | |
21547 | + if (au_ftest_icpup(a->flags, DID_CPUP)) { | |
21548 | + ia->ia_file = NULL; | |
21549 | + ia->ia_valid &= ~ATTR_FILE; | |
1308ab2a | 21550 | + } |
dece6358 | 21551 | + |
4a4d8108 AM |
21552 | + a->h_path.mnt = au_sbr_mnt(sb, a->btgt); |
21553 | + if ((ia->ia_valid & (ATTR_MODE | ATTR_CTIME)) | |
21554 | + == (ATTR_MODE | ATTR_CTIME)) { | |
7eafdf33 | 21555 | + err = security_path_chmod(&a->h_path, ia->ia_mode); |
4a4d8108 AM |
21556 | + if (unlikely(err)) |
21557 | + goto out_unlock; | |
21558 | + } else if ((ia->ia_valid & (ATTR_UID | ATTR_GID)) | |
21559 | + && (ia->ia_valid & ATTR_CTIME)) { | |
86dc4139 | 21560 | + err = security_path_chown(&a->h_path, ia->ia_uid, ia->ia_gid); |
4a4d8108 AM |
21561 | + if (unlikely(err)) |
21562 | + goto out_unlock; | |
21563 | + } | |
dece6358 | 21564 | + |
4a4d8108 AM |
21565 | + if (ia->ia_valid & ATTR_SIZE) { |
21566 | + struct file *f; | |
1308ab2a | 21567 | + |
953406b4 | 21568 | + if (ia->ia_size < i_size_read(inode)) |
4a4d8108 | 21569 | + /* unmap only */ |
953406b4 | 21570 | + truncate_setsize(inode, ia->ia_size); |
1308ab2a | 21571 | + |
4a4d8108 AM |
21572 | + f = NULL; |
21573 | + if (ia->ia_valid & ATTR_FILE) | |
21574 | + f = ia->ia_file; | |
febd17d6 | 21575 | + inode_unlock(a->h_inode); |
4a4d8108 | 21576 | + err = vfsub_trunc(&a->h_path, ia->ia_size, ia->ia_valid, f); |
febd17d6 | 21577 | + inode_lock_nested(a->h_inode, AuLsc_I_CHILD); |
523b37e3 AM |
21578 | + } else { |
21579 | + delegated = NULL; | |
21580 | + while (1) { | |
21581 | + err = vfsub_notify_change(&a->h_path, ia, &delegated); | |
21582 | + if (delegated) { | |
21583 | + err = break_deleg_wait(&delegated); | |
21584 | + if (!err) | |
21585 | + continue; | |
21586 | + } | |
21587 | + break; | |
21588 | + } | |
21589 | + } | |
8cdd5066 JR |
21590 | + /* |
21591 | + * regardless aufs 'acl' option setting. | |
21592 | + * why don't all acl-aware fs call this func from their ->setattr()? | |
21593 | + */ | |
21594 | + if (!err && (ia->ia_valid & ATTR_MODE)) | |
21595 | + err = vfsub_acl_chmod(a->h_inode, ia->ia_mode); | |
4a4d8108 AM |
21596 | + if (!err) |
21597 | + au_cpup_attr_changeable(inode); | |
1308ab2a | 21598 | + |
4f0767ce | 21599 | +out_unlock: |
febd17d6 | 21600 | + inode_unlock(a->h_inode); |
4a4d8108 | 21601 | + au_unpin(&a->pin); |
027c5e7a | 21602 | + if (unlikely(err)) |
5afbbe0d | 21603 | + au_update_dbtop(dentry); |
4f0767ce | 21604 | +out_dentry: |
4a4d8108 AM |
21605 | + di_write_unlock(dentry); |
21606 | + if (file) { | |
21607 | + fi_write_unlock(file); | |
21608 | + ia->ia_file = file; | |
21609 | + ia->ia_valid |= ATTR_FILE; | |
21610 | + } | |
4f0767ce | 21611 | +out_si: |
4a4d8108 | 21612 | + si_read_unlock(sb); |
e49829fe | 21613 | +out_kfree: |
9f237c51 | 21614 | + au_kfree_rcu(a); |
4f0767ce | 21615 | +out: |
4a4d8108 AM |
21616 | + AuTraceErr(err); |
21617 | + return err; | |
1facf9fc | 21618 | +} |
21619 | + | |
c1595e42 JR |
21620 | +#if IS_ENABLED(CONFIG_AUFS_XATTR) || IS_ENABLED(CONFIG_FS_POSIX_ACL) |
21621 | +static int au_h_path_to_set_attr(struct dentry *dentry, | |
21622 | + struct au_icpup_args *a, struct path *h_path) | |
21623 | +{ | |
21624 | + int err; | |
21625 | + struct super_block *sb; | |
21626 | + | |
21627 | + sb = dentry->d_sb; | |
21628 | + a->udba = au_opt_udba(sb); | |
21629 | + /* no d_unlinked(), to set UDBA_NONE for root */ | |
21630 | + if (d_unhashed(dentry)) | |
21631 | + a->udba = AuOpt_UDBA_NONE; | |
21632 | + if (a->udba != AuOpt_UDBA_NONE) { | |
21633 | + AuDebugOn(IS_ROOT(dentry)); | |
21634 | + err = au_reval_for_attr(dentry, au_sigen(sb)); | |
21635 | + if (unlikely(err)) | |
21636 | + goto out; | |
21637 | + } | |
21638 | + err = au_pin_and_icpup(dentry, /*ia*/NULL, a); | |
21639 | + if (unlikely(err < 0)) | |
21640 | + goto out; | |
21641 | + | |
21642 | + h_path->dentry = a->h_path.dentry; | |
21643 | + h_path->mnt = au_sbr_mnt(sb, a->btgt); | |
21644 | + | |
21645 | +out: | |
21646 | + return err; | |
21647 | +} | |
21648 | + | |
f2c43d5f AM |
21649 | +ssize_t au_sxattr(struct dentry *dentry, struct inode *inode, |
21650 | + struct au_sxattr *arg) | |
c1595e42 JR |
21651 | +{ |
21652 | + int err; | |
21653 | + struct path h_path; | |
21654 | + struct super_block *sb; | |
21655 | + struct au_icpup_args *a; | |
5afbbe0d | 21656 | + struct inode *h_inode; |
c1595e42 | 21657 | + |
c1595e42 JR |
21658 | + IMustLock(inode); |
21659 | + | |
21660 | + err = -ENOMEM; | |
21661 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
21662 | + if (unlikely(!a)) | |
21663 | + goto out; | |
21664 | + | |
21665 | + sb = dentry->d_sb; | |
21666 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
21667 | + if (unlikely(err)) | |
21668 | + goto out_kfree; | |
21669 | + | |
21670 | + h_path.dentry = NULL; /* silence gcc */ | |
21671 | + di_write_lock_child(dentry); | |
21672 | + err = au_h_path_to_set_attr(dentry, a, &h_path); | |
21673 | + if (unlikely(err)) | |
21674 | + goto out_di; | |
21675 | + | |
febd17d6 | 21676 | + inode_unlock(a->h_inode); |
c1595e42 JR |
21677 | + switch (arg->type) { |
21678 | + case AU_XATTR_SET: | |
5afbbe0d | 21679 | + AuDebugOn(d_is_negative(h_path.dentry)); |
c1595e42 JR |
21680 | + err = vfsub_setxattr(h_path.dentry, |
21681 | + arg->u.set.name, arg->u.set.value, | |
21682 | + arg->u.set.size, arg->u.set.flags); | |
21683 | + break; | |
c1595e42 JR |
21684 | + case AU_ACL_SET: |
21685 | + err = -EOPNOTSUPP; | |
5527c038 | 21686 | + h_inode = d_inode(h_path.dentry); |
c1595e42 | 21687 | + if (h_inode->i_op->set_acl) |
f2c43d5f | 21688 | + /* this will call posix_acl_update_mode */ |
c1595e42 JR |
21689 | + err = h_inode->i_op->set_acl(h_inode, |
21690 | + arg->u.acl_set.acl, | |
21691 | + arg->u.acl_set.type); | |
21692 | + break; | |
21693 | + } | |
21694 | + if (!err) | |
21695 | + au_cpup_attr_timesizes(inode); | |
21696 | + | |
21697 | + au_unpin(&a->pin); | |
21698 | + if (unlikely(err)) | |
5afbbe0d | 21699 | + au_update_dbtop(dentry); |
c1595e42 JR |
21700 | + |
21701 | +out_di: | |
21702 | + di_write_unlock(dentry); | |
21703 | + si_read_unlock(sb); | |
21704 | +out_kfree: | |
9f237c51 | 21705 | + au_kfree_rcu(a); |
c1595e42 JR |
21706 | +out: |
21707 | + AuTraceErr(err); | |
21708 | + return err; | |
21709 | +} | |
21710 | +#endif | |
21711 | + | |
4a4d8108 AM |
21712 | +static void au_refresh_iattr(struct inode *inode, struct kstat *st, |
21713 | + unsigned int nlink) | |
1facf9fc | 21714 | +{ |
9dbd164d AM |
21715 | + unsigned int n; |
21716 | + | |
4a4d8108 | 21717 | + inode->i_mode = st->mode; |
86dc4139 AM |
21718 | + /* don't i_[ug]id_write() here */ |
21719 | + inode->i_uid = st->uid; | |
21720 | + inode->i_gid = st->gid; | |
4a4d8108 AM |
21721 | + inode->i_atime = st->atime; |
21722 | + inode->i_mtime = st->mtime; | |
21723 | + inode->i_ctime = st->ctime; | |
1facf9fc | 21724 | + |
4a4d8108 AM |
21725 | + au_cpup_attr_nlink(inode, /*force*/0); |
21726 | + if (S_ISDIR(inode->i_mode)) { | |
9dbd164d AM |
21727 | + n = inode->i_nlink; |
21728 | + n -= nlink; | |
21729 | + n += st->nlink; | |
f6b6e03d | 21730 | + smp_mb(); /* for i_nlink */ |
7eafdf33 | 21731 | + /* 0 can happen */ |
92d182d2 | 21732 | + set_nlink(inode, n); |
4a4d8108 | 21733 | + } |
1facf9fc | 21734 | + |
4a4d8108 AM |
21735 | + spin_lock(&inode->i_lock); |
21736 | + inode->i_blocks = st->blocks; | |
21737 | + i_size_write(inode, st->size); | |
21738 | + spin_unlock(&inode->i_lock); | |
1facf9fc | 21739 | +} |
21740 | + | |
c1595e42 | 21741 | +/* |
f2c43d5f | 21742 | + * common routine for aufs_getattr() and au_getxattr(). |
c1595e42 JR |
21743 | + * returns zero or negative (an error). |
21744 | + * @dentry will be read-locked in success. | |
21745 | + */ | |
a2654f78 AM |
21746 | +int au_h_path_getattr(struct dentry *dentry, int force, struct path *h_path, |
21747 | + int locked) | |
1facf9fc | 21748 | +{ |
4a4d8108 | 21749 | + int err; |
076b876e | 21750 | + unsigned int mnt_flags, sigen; |
c1595e42 | 21751 | + unsigned char udba_none; |
4a4d8108 | 21752 | + aufs_bindex_t bindex; |
4a4d8108 AM |
21753 | + struct super_block *sb, *h_sb; |
21754 | + struct inode *inode; | |
1facf9fc | 21755 | + |
c1595e42 JR |
21756 | + h_path->mnt = NULL; |
21757 | + h_path->dentry = NULL; | |
21758 | + | |
21759 | + err = 0; | |
4a4d8108 | 21760 | + sb = dentry->d_sb; |
4a4d8108 AM |
21761 | + mnt_flags = au_mntflags(sb); |
21762 | + udba_none = !!au_opt_test(mnt_flags, UDBA_NONE); | |
1facf9fc | 21763 | + |
a2654f78 AM |
21764 | + if (unlikely(locked)) |
21765 | + goto body; /* skip locking dinfo */ | |
21766 | + | |
4a4d8108 | 21767 | + /* support fstat(2) */ |
027c5e7a | 21768 | + if (!d_unlinked(dentry) && !udba_none) { |
076b876e | 21769 | + sigen = au_sigen(sb); |
027c5e7a AM |
21770 | + err = au_digen_test(dentry, sigen); |
21771 | + if (!err) { | |
4a4d8108 | 21772 | + di_read_lock_child(dentry, AuLock_IR); |
027c5e7a | 21773 | + err = au_dbrange_test(dentry); |
c1595e42 JR |
21774 | + if (unlikely(err)) { |
21775 | + di_read_unlock(dentry, AuLock_IR); | |
21776 | + goto out; | |
21777 | + } | |
027c5e7a | 21778 | + } else { |
4a4d8108 AM |
21779 | + AuDebugOn(IS_ROOT(dentry)); |
21780 | + di_write_lock_child(dentry); | |
027c5e7a AM |
21781 | + err = au_dbrange_test(dentry); |
21782 | + if (!err) | |
21783 | + err = au_reval_for_attr(dentry, sigen); | |
c1595e42 JR |
21784 | + if (!err) |
21785 | + di_downgrade_lock(dentry, AuLock_IR); | |
21786 | + else { | |
21787 | + di_write_unlock(dentry); | |
21788 | + goto out; | |
21789 | + } | |
4a4d8108 AM |
21790 | + } |
21791 | + } else | |
21792 | + di_read_lock_child(dentry, AuLock_IR); | |
1facf9fc | 21793 | + |
a2654f78 | 21794 | +body: |
5527c038 | 21795 | + inode = d_inode(dentry); |
5afbbe0d | 21796 | + bindex = au_ibtop(inode); |
c1595e42 JR |
21797 | + h_path->mnt = au_sbr_mnt(sb, bindex); |
21798 | + h_sb = h_path->mnt->mnt_sb; | |
21799 | + if (!force | |
21800 | + && !au_test_fs_bad_iattr(h_sb) | |
21801 | + && udba_none) | |
21802 | + goto out; /* success */ | |
1facf9fc | 21803 | + |
5afbbe0d | 21804 | + if (au_dbtop(dentry) == bindex) |
c1595e42 | 21805 | + h_path->dentry = au_h_dptr(dentry, bindex); |
4a4d8108 | 21806 | + else if (au_opt_test(mnt_flags, PLINK) && au_plink_test(inode)) { |
c1595e42 JR |
21807 | + h_path->dentry = au_plink_lkup(inode, bindex); |
21808 | + if (IS_ERR(h_path->dentry)) | |
21809 | + /* pretending success */ | |
21810 | + h_path->dentry = NULL; | |
21811 | + else | |
21812 | + dput(h_path->dentry); | |
4a4d8108 | 21813 | + } |
c1595e42 JR |
21814 | + |
21815 | +out: | |
21816 | + return err; | |
21817 | +} | |
21818 | + | |
521ced18 JR |
21819 | +static int aufs_getattr(const struct path *path, struct kstat *st, |
21820 | + u32 request, unsigned int query) | |
c1595e42 JR |
21821 | +{ |
21822 | + int err; | |
21823 | + unsigned char positive; | |
21824 | + struct path h_path; | |
521ced18 | 21825 | + struct dentry *dentry; |
c1595e42 JR |
21826 | + struct inode *inode; |
21827 | + struct super_block *sb; | |
21828 | + | |
521ced18 | 21829 | + dentry = path->dentry; |
5527c038 | 21830 | + inode = d_inode(dentry); |
c1595e42 JR |
21831 | + sb = dentry->d_sb; |
21832 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
21833 | + if (unlikely(err)) | |
21834 | + goto out; | |
a2654f78 | 21835 | + err = au_h_path_getattr(dentry, /*force*/0, &h_path, /*locked*/0); |
c1595e42 JR |
21836 | + if (unlikely(err)) |
21837 | + goto out_si; | |
c06a8ce3 | 21838 | + if (unlikely(!h_path.dentry)) |
c1595e42 | 21839 | + /* illegally overlapped or something */ |
4a4d8108 AM |
21840 | + goto out_fill; /* pretending success */ |
21841 | + | |
5527c038 | 21842 | + positive = d_is_positive(h_path.dentry); |
4a4d8108 | 21843 | + if (positive) |
521ced18 JR |
21844 | + /* no vfsub version */ |
21845 | + err = vfs_getattr(&h_path, st, request, query); | |
4a4d8108 AM |
21846 | + if (!err) { |
21847 | + if (positive) | |
c06a8ce3 | 21848 | + au_refresh_iattr(inode, st, |
5527c038 | 21849 | + d_inode(h_path.dentry)->i_nlink); |
4a4d8108 | 21850 | + goto out_fill; /* success */ |
1facf9fc | 21851 | + } |
7f207e10 | 21852 | + AuTraceErr(err); |
c1595e42 | 21853 | + goto out_di; |
4a4d8108 | 21854 | + |
4f0767ce | 21855 | +out_fill: |
4a4d8108 | 21856 | + generic_fillattr(inode, st); |
c1595e42 | 21857 | +out_di: |
4a4d8108 | 21858 | + di_read_unlock(dentry, AuLock_IR); |
c1595e42 | 21859 | +out_si: |
4a4d8108 | 21860 | + si_read_unlock(sb); |
7f207e10 AM |
21861 | +out: |
21862 | + AuTraceErr(err); | |
4a4d8108 | 21863 | + return err; |
1facf9fc | 21864 | +} |
21865 | + | |
21866 | +/* ---------------------------------------------------------------------- */ | |
21867 | + | |
febd17d6 JR |
21868 | +static const char *aufs_get_link(struct dentry *dentry, struct inode *inode, |
21869 | + struct delayed_call *done) | |
4a4d8108 | 21870 | +{ |
c2c0f25c | 21871 | + const char *ret; |
c2c0f25c | 21872 | + struct dentry *h_dentry; |
febd17d6 | 21873 | + struct inode *h_inode; |
4a4d8108 | 21874 | + int err; |
c2c0f25c | 21875 | + aufs_bindex_t bindex; |
1facf9fc | 21876 | + |
79b8bda9 | 21877 | + ret = NULL; /* suppress a warning */ |
febd17d6 JR |
21878 | + err = -ECHILD; |
21879 | + if (!dentry) | |
21880 | + goto out; | |
21881 | + | |
027c5e7a AM |
21882 | + err = aufs_read_lock(dentry, AuLock_IR | AuLock_GEN); |
21883 | + if (unlikely(err)) | |
c2c0f25c | 21884 | + goto out; |
027c5e7a AM |
21885 | + |
21886 | + err = au_d_hashed_positive(dentry); | |
c2c0f25c AM |
21887 | + if (unlikely(err)) |
21888 | + goto out_unlock; | |
21889 | + | |
21890 | + err = -EINVAL; | |
21891 | + inode = d_inode(dentry); | |
5afbbe0d | 21892 | + bindex = au_ibtop(inode); |
c2c0f25c | 21893 | + h_inode = au_h_iptr(inode, bindex); |
febd17d6 | 21894 | + if (unlikely(!h_inode->i_op->get_link)) |
c2c0f25c AM |
21895 | + goto out_unlock; |
21896 | + | |
21897 | + err = -EBUSY; | |
21898 | + h_dentry = NULL; | |
5afbbe0d | 21899 | + if (au_dbtop(dentry) <= bindex) { |
c2c0f25c AM |
21900 | + h_dentry = au_h_dptr(dentry, bindex); |
21901 | + if (h_dentry) | |
21902 | + dget(h_dentry); | |
027c5e7a | 21903 | + } |
c2c0f25c AM |
21904 | + if (!h_dentry) { |
21905 | + h_dentry = d_find_any_alias(h_inode); | |
21906 | + if (IS_ERR(h_dentry)) { | |
21907 | + err = PTR_ERR(h_dentry); | |
febd17d6 | 21908 | + goto out_unlock; |
c2c0f25c AM |
21909 | + } |
21910 | + } | |
21911 | + if (unlikely(!h_dentry)) | |
febd17d6 | 21912 | + goto out_unlock; |
1facf9fc | 21913 | + |
c2c0f25c | 21914 | + err = 0; |
062440b3 | 21915 | + AuDbg("%ps\n", h_inode->i_op->get_link); |
c2c0f25c | 21916 | + AuDbgDentry(h_dentry); |
f2c43d5f | 21917 | + ret = vfs_get_link(h_dentry, done); |
c2c0f25c | 21918 | + dput(h_dentry); |
febd17d6 JR |
21919 | + if (IS_ERR(ret)) |
21920 | + err = PTR_ERR(ret); | |
c2c0f25c | 21921 | + |
c2c0f25c AM |
21922 | +out_unlock: |
21923 | + aufs_read_unlock(dentry, AuLock_IR); | |
4f0767ce | 21924 | +out: |
c2c0f25c AM |
21925 | + if (unlikely(err)) |
21926 | + ret = ERR_PTR(err); | |
21927 | + AuTraceErrPtr(ret); | |
21928 | + return ret; | |
4a4d8108 | 21929 | +} |
1facf9fc | 21930 | + |
4a4d8108 | 21931 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 21932 | + |
e2f27e51 AM |
21933 | +static int au_is_special(struct inode *inode) |
21934 | +{ | |
21935 | + return (inode->i_mode & (S_IFBLK | S_IFCHR | S_IFIFO | S_IFSOCK)); | |
21936 | +} | |
21937 | + | |
acd2b654 AM |
21938 | +static int aufs_update_time(struct inode *inode, struct timespec64 *ts, |
21939 | + int flags) | |
4a4d8108 | 21940 | +{ |
0c3ec466 | 21941 | + int err; |
e2f27e51 | 21942 | + aufs_bindex_t bindex; |
0c3ec466 AM |
21943 | + struct super_block *sb; |
21944 | + struct inode *h_inode; | |
e2f27e51 | 21945 | + struct vfsmount *h_mnt; |
0c3ec466 AM |
21946 | + |
21947 | + sb = inode->i_sb; | |
e2f27e51 AM |
21948 | + WARN_ONCE((flags & S_ATIME) && !IS_NOATIME(inode), |
21949 | + "unexpected s_flags 0x%lx", sb->s_flags); | |
21950 | + | |
0c3ec466 AM |
21951 | + /* mmap_sem might be acquired already, cf. aufs_mmap() */ |
21952 | + lockdep_off(); | |
21953 | + si_read_lock(sb, AuLock_FLUSH); | |
21954 | + ii_write_lock_child(inode); | |
e2f27e51 AM |
21955 | + |
21956 | + err = 0; | |
21957 | + bindex = au_ibtop(inode); | |
21958 | + h_inode = au_h_iptr(inode, bindex); | |
21959 | + if (!au_test_ro(sb, bindex, inode)) { | |
21960 | + h_mnt = au_sbr_mnt(sb, bindex); | |
21961 | + err = vfsub_mnt_want_write(h_mnt); | |
21962 | + if (!err) { | |
21963 | + err = vfsub_update_time(h_inode, ts, flags); | |
21964 | + vfsub_mnt_drop_write(h_mnt); | |
21965 | + } | |
21966 | + } else if (au_is_special(h_inode)) { | |
21967 | + /* | |
21968 | + * Never copy-up here. | |
21969 | + * These special files may already be opened and used for | |
21970 | + * communicating. If we copied it up, then the communication | |
21971 | + * would be corrupted. | |
21972 | + */ | |
21973 | + AuWarn1("timestamps for i%lu are ignored " | |
21974 | + "since it is on readonly branch (hi%lu).\n", | |
21975 | + inode->i_ino, h_inode->i_ino); | |
21976 | + } else if (flags & ~S_ATIME) { | |
21977 | + err = -EIO; | |
21978 | + AuIOErr1("unexpected flags 0x%x\n", flags); | |
21979 | + AuDebugOn(1); | |
21980 | + } | |
21981 | + | |
38d290e6 JR |
21982 | + if (!err) |
21983 | + au_cpup_attr_timesizes(inode); | |
0c3ec466 AM |
21984 | + ii_write_unlock(inode); |
21985 | + si_read_unlock(sb); | |
21986 | + lockdep_on(); | |
38d290e6 JR |
21987 | + |
21988 | + if (!err && (flags & S_VERSION)) | |
21989 | + inode_inc_iversion(inode); | |
21990 | + | |
0c3ec466 | 21991 | + return err; |
4a4d8108 | 21992 | +} |
1facf9fc | 21993 | + |
4a4d8108 | 21994 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 21995 | + |
b95c5147 AM |
21996 | +/* no getattr version will be set by module.c:aufs_init() */ |
21997 | +struct inode_operations aufs_iop_nogetattr[AuIop_Last], | |
21998 | + aufs_iop[] = { | |
21999 | + [AuIop_SYMLINK] = { | |
22000 | + .permission = aufs_permission, | |
c1595e42 | 22001 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
22002 | + .get_acl = aufs_get_acl, |
22003 | + .set_acl = aufs_set_acl, /* unsupport for symlink? */ | |
c1595e42 JR |
22004 | +#endif |
22005 | + | |
b95c5147 AM |
22006 | + .setattr = aufs_setattr, |
22007 | + .getattr = aufs_getattr, | |
0c3ec466 | 22008 | + |
c1595e42 | 22009 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 22010 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
22011 | +#endif |
22012 | + | |
febd17d6 | 22013 | + .get_link = aufs_get_link, |
0c3ec466 | 22014 | + |
b95c5147 AM |
22015 | + /* .update_time = aufs_update_time */ |
22016 | + }, | |
22017 | + [AuIop_DIR] = { | |
22018 | + .create = aufs_create, | |
22019 | + .lookup = aufs_lookup, | |
22020 | + .link = aufs_link, | |
22021 | + .unlink = aufs_unlink, | |
22022 | + .symlink = aufs_symlink, | |
22023 | + .mkdir = aufs_mkdir, | |
22024 | + .rmdir = aufs_rmdir, | |
22025 | + .mknod = aufs_mknod, | |
22026 | + .rename = aufs_rename, | |
22027 | + | |
22028 | + .permission = aufs_permission, | |
c1595e42 | 22029 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
22030 | + .get_acl = aufs_get_acl, |
22031 | + .set_acl = aufs_set_acl, | |
c1595e42 JR |
22032 | +#endif |
22033 | + | |
b95c5147 AM |
22034 | + .setattr = aufs_setattr, |
22035 | + .getattr = aufs_getattr, | |
0c3ec466 | 22036 | + |
c1595e42 | 22037 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 22038 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
22039 | +#endif |
22040 | + | |
b95c5147 AM |
22041 | + .update_time = aufs_update_time, |
22042 | + .atomic_open = aufs_atomic_open, | |
22043 | + .tmpfile = aufs_tmpfile | |
22044 | + }, | |
22045 | + [AuIop_OTHER] = { | |
22046 | + .permission = aufs_permission, | |
c1595e42 | 22047 | +#ifdef CONFIG_FS_POSIX_ACL |
b95c5147 AM |
22048 | + .get_acl = aufs_get_acl, |
22049 | + .set_acl = aufs_set_acl, | |
c1595e42 JR |
22050 | +#endif |
22051 | + | |
b95c5147 AM |
22052 | + .setattr = aufs_setattr, |
22053 | + .getattr = aufs_getattr, | |
0c3ec466 | 22054 | + |
c1595e42 | 22055 | +#ifdef CONFIG_AUFS_XATTR |
b95c5147 | 22056 | + .listxattr = aufs_listxattr, |
c1595e42 JR |
22057 | +#endif |
22058 | + | |
b95c5147 AM |
22059 | + .update_time = aufs_update_time |
22060 | + } | |
4a4d8108 | 22061 | +}; |
7f207e10 | 22062 | diff -urN /usr/share/empty/fs/aufs/i_op_del.c linux/fs/aufs/i_op_del.c |
eca34b5c | 22063 | --- /usr/share/empty/fs/aufs/i_op_del.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 22064 | +++ linux/fs/aufs/i_op_del.c 2020-01-27 10:57:18.172204883 +0100 |
eca801bf | 22065 | @@ -0,0 +1,513 @@ |
cd7a4cd9 | 22066 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 22067 | +/* |
d58c55f2 | 22068 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 22069 | + * |
22070 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22071 | + * it under the terms of the GNU General Public License as published by | |
22072 | + * the Free Software Foundation; either version 2 of the License, or | |
22073 | + * (at your option) any later version. | |
dece6358 AM |
22074 | + * |
22075 | + * This program is distributed in the hope that it will be useful, | |
22076 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22077 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22078 | + * GNU General Public License for more details. | |
22079 | + * | |
22080 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22081 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22082 | + */ |
22083 | + | |
22084 | +/* | |
4a4d8108 | 22085 | + * inode operations (del entry) |
1308ab2a | 22086 | + */ |
dece6358 | 22087 | + |
eca801bf | 22088 | +#include <linux/iversion.h> |
1308ab2a | 22089 | +#include "aufs.h" |
dece6358 | 22090 | + |
4a4d8108 AM |
22091 | +/* |
22092 | + * decide if a new whiteout for @dentry is necessary or not. | |
22093 | + * when it is necessary, prepare the parent dir for the upper branch whose | |
22094 | + * branch index is @bcpup for creation. the actual creation of the whiteout will | |
22095 | + * be done by caller. | |
22096 | + * return value: | |
22097 | + * 0: wh is unnecessary | |
22098 | + * plus: wh is necessary | |
22099 | + * minus: error | |
22100 | + */ | |
22101 | +int au_wr_dir_need_wh(struct dentry *dentry, int isdir, aufs_bindex_t *bcpup) | |
1308ab2a | 22102 | +{ |
4a4d8108 | 22103 | + int need_wh, err; |
5afbbe0d | 22104 | + aufs_bindex_t btop; |
4a4d8108 | 22105 | + struct super_block *sb; |
dece6358 | 22106 | + |
4a4d8108 | 22107 | + sb = dentry->d_sb; |
5afbbe0d | 22108 | + btop = au_dbtop(dentry); |
4a4d8108 | 22109 | + if (*bcpup < 0) { |
5afbbe0d AM |
22110 | + *bcpup = btop; |
22111 | + if (au_test_ro(sb, btop, d_inode(dentry))) { | |
4a4d8108 AM |
22112 | + err = AuWbrCopyup(au_sbi(sb), dentry); |
22113 | + *bcpup = err; | |
22114 | + if (unlikely(err < 0)) | |
22115 | + goto out; | |
22116 | + } | |
22117 | + } else | |
5afbbe0d | 22118 | + AuDebugOn(btop < *bcpup |
5527c038 | 22119 | + || au_test_ro(sb, *bcpup, d_inode(dentry))); |
5afbbe0d | 22120 | + AuDbg("bcpup %d, btop %d\n", *bcpup, btop); |
1308ab2a | 22121 | + |
5afbbe0d | 22122 | + if (*bcpup != btop) { |
4a4d8108 AM |
22123 | + err = au_cpup_dirs(dentry, *bcpup); |
22124 | + if (unlikely(err)) | |
22125 | + goto out; | |
22126 | + need_wh = 1; | |
22127 | + } else { | |
027c5e7a | 22128 | + struct au_dinfo *dinfo, *tmp; |
4a4d8108 | 22129 | + |
027c5e7a AM |
22130 | + need_wh = -ENOMEM; |
22131 | + dinfo = au_di(dentry); | |
22132 | + tmp = au_di_alloc(sb, AuLsc_DI_TMP); | |
22133 | + if (tmp) { | |
22134 | + au_di_cp(tmp, dinfo); | |
22135 | + au_di_swap(tmp, dinfo); | |
22136 | + /* returns the number of positive dentries */ | |
5afbbe0d AM |
22137 | + need_wh = au_lkup_dentry(dentry, btop + 1, |
22138 | + /* AuLkup_IGNORE_PERM */ 0); | |
027c5e7a AM |
22139 | + au_di_swap(tmp, dinfo); |
22140 | + au_rw_write_unlock(&tmp->di_rwsem); | |
22141 | + au_di_free(tmp); | |
4a4d8108 AM |
22142 | + } |
22143 | + } | |
22144 | + AuDbg("need_wh %d\n", need_wh); | |
22145 | + err = need_wh; | |
22146 | + | |
4f0767ce | 22147 | +out: |
4a4d8108 | 22148 | + return err; |
1facf9fc | 22149 | +} |
22150 | + | |
4a4d8108 AM |
22151 | +/* |
22152 | + * simple tests for the del-entry operations. | |
22153 | + * following the checks in vfs, plus the parent-child relationship. | |
22154 | + */ | |
22155 | +int au_may_del(struct dentry *dentry, aufs_bindex_t bindex, | |
22156 | + struct dentry *h_parent, int isdir) | |
1facf9fc | 22157 | +{ |
4a4d8108 AM |
22158 | + int err; |
22159 | + umode_t h_mode; | |
22160 | + struct dentry *h_dentry, *h_latest; | |
1308ab2a | 22161 | + struct inode *h_inode; |
1facf9fc | 22162 | + |
4a4d8108 | 22163 | + h_dentry = au_h_dptr(dentry, bindex); |
5527c038 | 22164 | + if (d_really_is_positive(dentry)) { |
4a4d8108 | 22165 | + err = -ENOENT; |
5527c038 JR |
22166 | + if (unlikely(d_is_negative(h_dentry))) |
22167 | + goto out; | |
22168 | + h_inode = d_inode(h_dentry); | |
22169 | + if (unlikely(!h_inode->i_nlink)) | |
4a4d8108 | 22170 | + goto out; |
1facf9fc | 22171 | + |
4a4d8108 AM |
22172 | + h_mode = h_inode->i_mode; |
22173 | + if (!isdir) { | |
22174 | + err = -EISDIR; | |
22175 | + if (unlikely(S_ISDIR(h_mode))) | |
22176 | + goto out; | |
22177 | + } else if (unlikely(!S_ISDIR(h_mode))) { | |
22178 | + err = -ENOTDIR; | |
22179 | + goto out; | |
22180 | + } | |
22181 | + } else { | |
22182 | + /* rename(2) case */ | |
22183 | + err = -EIO; | |
5527c038 | 22184 | + if (unlikely(d_is_positive(h_dentry))) |
4a4d8108 AM |
22185 | + goto out; |
22186 | + } | |
1facf9fc | 22187 | + |
4a4d8108 AM |
22188 | + err = -ENOENT; |
22189 | + /* expected parent dir is locked */ | |
22190 | + if (unlikely(h_parent != h_dentry->d_parent)) | |
22191 | + goto out; | |
22192 | + err = 0; | |
22193 | + | |
22194 | + /* | |
22195 | + * rmdir a dir may break the consistency on some filesystem. | |
22196 | + * let's try heavy test. | |
22197 | + */ | |
22198 | + err = -EACCES; | |
076b876e | 22199 | + if (unlikely(!au_opt_test(au_mntflags(dentry->d_sb), DIRPERM1) |
5527c038 | 22200 | + && au_test_h_perm(d_inode(h_parent), |
076b876e | 22201 | + MAY_EXEC | MAY_WRITE))) |
4a4d8108 AM |
22202 | + goto out; |
22203 | + | |
076b876e | 22204 | + h_latest = au_sio_lkup_one(&dentry->d_name, h_parent); |
4a4d8108 AM |
22205 | + err = -EIO; |
22206 | + if (IS_ERR(h_latest)) | |
22207 | + goto out; | |
22208 | + if (h_latest == h_dentry) | |
22209 | + err = 0; | |
22210 | + dput(h_latest); | |
22211 | + | |
4f0767ce | 22212 | +out: |
4a4d8108 | 22213 | + return err; |
1308ab2a | 22214 | +} |
1facf9fc | 22215 | + |
4a4d8108 AM |
22216 | +/* |
22217 | + * decide the branch where we operate for @dentry. the branch index will be set | |
acd2b654 | 22218 | + * @rbcpup. after deciding it, 'pin' it and store the timestamps of the parent |
4a4d8108 AM |
22219 | + * dir for reverting. |
22220 | + * when a new whiteout is necessary, create it. | |
22221 | + */ | |
22222 | +static struct dentry* | |
22223 | +lock_hdir_create_wh(struct dentry *dentry, int isdir, aufs_bindex_t *rbcpup, | |
22224 | + struct au_dtime *dt, struct au_pin *pin) | |
1308ab2a | 22225 | +{ |
4a4d8108 AM |
22226 | + struct dentry *wh_dentry; |
22227 | + struct super_block *sb; | |
22228 | + struct path h_path; | |
22229 | + int err, need_wh; | |
22230 | + unsigned int udba; | |
22231 | + aufs_bindex_t bcpup; | |
dece6358 | 22232 | + |
4a4d8108 AM |
22233 | + need_wh = au_wr_dir_need_wh(dentry, isdir, rbcpup); |
22234 | + wh_dentry = ERR_PTR(need_wh); | |
22235 | + if (unlikely(need_wh < 0)) | |
22236 | + goto out; | |
22237 | + | |
22238 | + sb = dentry->d_sb; | |
22239 | + udba = au_opt_udba(sb); | |
22240 | + bcpup = *rbcpup; | |
22241 | + err = au_pin(pin, dentry, bcpup, udba, | |
22242 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
22243 | + wh_dentry = ERR_PTR(err); | |
22244 | + if (unlikely(err)) | |
22245 | + goto out; | |
22246 | + | |
22247 | + h_path.dentry = au_pinned_h_parent(pin); | |
22248 | + if (udba != AuOpt_UDBA_NONE | |
5afbbe0d | 22249 | + && au_dbtop(dentry) == bcpup) { |
4a4d8108 AM |
22250 | + err = au_may_del(dentry, bcpup, h_path.dentry, isdir); |
22251 | + wh_dentry = ERR_PTR(err); | |
22252 | + if (unlikely(err)) | |
22253 | + goto out_unpin; | |
22254 | + } | |
22255 | + | |
22256 | + h_path.mnt = au_sbr_mnt(sb, bcpup); | |
22257 | + au_dtime_store(dt, au_pinned_parent(pin), &h_path); | |
22258 | + wh_dentry = NULL; | |
22259 | + if (!need_wh) | |
22260 | + goto out; /* success, no need to create whiteout */ | |
22261 | + | |
22262 | + wh_dentry = au_wh_create(dentry, bcpup, h_path.dentry); | |
22263 | + if (IS_ERR(wh_dentry)) | |
22264 | + goto out_unpin; | |
22265 | + | |
22266 | + /* returns with the parent is locked and wh_dentry is dget-ed */ | |
22267 | + goto out; /* success */ | |
22268 | + | |
4f0767ce | 22269 | +out_unpin: |
4a4d8108 | 22270 | + au_unpin(pin); |
4f0767ce | 22271 | +out: |
4a4d8108 | 22272 | + return wh_dentry; |
1facf9fc | 22273 | +} |
22274 | + | |
4a4d8108 AM |
22275 | +/* |
22276 | + * when removing a dir, rename it to a unique temporary whiteout-ed name first | |
22277 | + * in order to be revertible and save time for removing many child whiteouts | |
22278 | + * under the dir. | |
22279 | + * returns 1 when there are too many child whiteout and caller should remove | |
22280 | + * them asynchronously. returns 0 when the number of children is enough small to | |
22281 | + * remove now or the branch fs is a remote fs. | |
22282 | + * otherwise return an error. | |
22283 | + */ | |
22284 | +static int renwh_and_rmdir(struct dentry *dentry, aufs_bindex_t bindex, | |
22285 | + struct au_nhash *whlist, struct inode *dir) | |
1facf9fc | 22286 | +{ |
4a4d8108 AM |
22287 | + int rmdir_later, err, dirwh; |
22288 | + struct dentry *h_dentry; | |
22289 | + struct super_block *sb; | |
5527c038 | 22290 | + struct inode *inode; |
4a4d8108 AM |
22291 | + |
22292 | + sb = dentry->d_sb; | |
22293 | + SiMustAnyLock(sb); | |
22294 | + h_dentry = au_h_dptr(dentry, bindex); | |
22295 | + err = au_whtmp_ren(h_dentry, au_sbr(sb, bindex)); | |
22296 | + if (unlikely(err)) | |
22297 | + goto out; | |
22298 | + | |
22299 | + /* stop monitoring */ | |
5527c038 JR |
22300 | + inode = d_inode(dentry); |
22301 | + au_hn_free(au_hi(inode, bindex)); | |
4a4d8108 AM |
22302 | + |
22303 | + if (!au_test_fs_remote(h_dentry->d_sb)) { | |
22304 | + dirwh = au_sbi(sb)->si_dirwh; | |
22305 | + rmdir_later = (dirwh <= 1); | |
22306 | + if (!rmdir_later) | |
22307 | + rmdir_later = au_nhash_test_longer_wh(whlist, bindex, | |
22308 | + dirwh); | |
22309 | + if (rmdir_later) | |
22310 | + return rmdir_later; | |
22311 | + } | |
1facf9fc | 22312 | + |
4a4d8108 AM |
22313 | + err = au_whtmp_rmdir(dir, bindex, h_dentry, whlist); |
22314 | + if (unlikely(err)) { | |
523b37e3 AM |
22315 | + AuIOErr("rmdir %pd, b%d failed, %d. ignored\n", |
22316 | + h_dentry, bindex, err); | |
4a4d8108 AM |
22317 | + err = 0; |
22318 | + } | |
dece6358 | 22319 | + |
4f0767ce | 22320 | +out: |
4a4d8108 AM |
22321 | + AuTraceErr(err); |
22322 | + return err; | |
22323 | +} | |
1308ab2a | 22324 | + |
4a4d8108 AM |
22325 | +/* |
22326 | + * final procedure for deleting a entry. | |
22327 | + * maintain dentry and iattr. | |
22328 | + */ | |
22329 | +static void epilog(struct inode *dir, struct dentry *dentry, | |
22330 | + aufs_bindex_t bindex) | |
22331 | +{ | |
22332 | + struct inode *inode; | |
1308ab2a | 22333 | + |
5527c038 | 22334 | + inode = d_inode(dentry); |
4a4d8108 AM |
22335 | + d_drop(dentry); |
22336 | + inode->i_ctime = dir->i_ctime; | |
1308ab2a | 22337 | + |
b912730e | 22338 | + au_dir_ts(dir, bindex); |
be118d29 | 22339 | + inode_inc_iversion(dir); |
1facf9fc | 22340 | +} |
22341 | + | |
4a4d8108 AM |
22342 | +/* |
22343 | + * when an error happened, remove the created whiteout and revert everything. | |
22344 | + */ | |
7f207e10 AM |
22345 | +static int do_revert(int err, struct inode *dir, aufs_bindex_t bindex, |
22346 | + aufs_bindex_t bwh, struct dentry *wh_dentry, | |
22347 | + struct dentry *dentry, struct au_dtime *dt) | |
1facf9fc | 22348 | +{ |
4a4d8108 AM |
22349 | + int rerr; |
22350 | + struct path h_path = { | |
22351 | + .dentry = wh_dentry, | |
7f207e10 | 22352 | + .mnt = au_sbr_mnt(dir->i_sb, bindex) |
4a4d8108 | 22353 | + }; |
dece6358 | 22354 | + |
7f207e10 | 22355 | + rerr = au_wh_unlink_dentry(au_h_iptr(dir, bindex), &h_path, dentry); |
4a4d8108 AM |
22356 | + if (!rerr) { |
22357 | + au_set_dbwh(dentry, bwh); | |
22358 | + au_dtime_revert(dt); | |
22359 | + return 0; | |
22360 | + } | |
dece6358 | 22361 | + |
523b37e3 | 22362 | + AuIOErr("%pd reverting whiteout failed(%d, %d)\n", dentry, err, rerr); |
4a4d8108 | 22363 | + return -EIO; |
1facf9fc | 22364 | +} |
22365 | + | |
4a4d8108 | 22366 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 22367 | + |
4a4d8108 | 22368 | +int aufs_unlink(struct inode *dir, struct dentry *dentry) |
1308ab2a | 22369 | +{ |
4a4d8108 | 22370 | + int err; |
5afbbe0d | 22371 | + aufs_bindex_t bwh, bindex, btop; |
523b37e3 | 22372 | + struct inode *inode, *h_dir, *delegated; |
4a4d8108 | 22373 | + struct dentry *parent, *wh_dentry; |
acd2b654 | 22374 | + /* to reduce stack size */ |
c2b27bf2 AM |
22375 | + struct { |
22376 | + struct au_dtime dt; | |
22377 | + struct au_pin pin; | |
22378 | + struct path h_path; | |
22379 | + } *a; | |
1facf9fc | 22380 | + |
4a4d8108 | 22381 | + IMustLock(dir); |
027c5e7a | 22382 | + |
c2b27bf2 AM |
22383 | + err = -ENOMEM; |
22384 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
22385 | + if (unlikely(!a)) | |
22386 | + goto out; | |
22387 | + | |
027c5e7a AM |
22388 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_GEN); |
22389 | + if (unlikely(err)) | |
c2b27bf2 | 22390 | + goto out_free; |
027c5e7a AM |
22391 | + err = au_d_hashed_positive(dentry); |
22392 | + if (unlikely(err)) | |
22393 | + goto out_unlock; | |
5527c038 | 22394 | + inode = d_inode(dentry); |
4a4d8108 | 22395 | + IMustLock(inode); |
027c5e7a | 22396 | + err = -EISDIR; |
2000de60 | 22397 | + if (unlikely(d_is_dir(dentry))) |
027c5e7a | 22398 | + goto out_unlock; /* possible? */ |
1facf9fc | 22399 | + |
5afbbe0d | 22400 | + btop = au_dbtop(dentry); |
4a4d8108 AM |
22401 | + bwh = au_dbwh(dentry); |
22402 | + bindex = -1; | |
027c5e7a AM |
22403 | + parent = dentry->d_parent; /* dir inode is locked */ |
22404 | + di_write_lock_parent(parent); | |
c2b27bf2 AM |
22405 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/0, &bindex, &a->dt, |
22406 | + &a->pin); | |
4a4d8108 AM |
22407 | + err = PTR_ERR(wh_dentry); |
22408 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 22409 | + goto out_parent; |
1facf9fc | 22410 | + |
5afbbe0d AM |
22411 | + a->h_path.mnt = au_sbr_mnt(dentry->d_sb, btop); |
22412 | + a->h_path.dentry = au_h_dptr(dentry, btop); | |
c2b27bf2 | 22413 | + dget(a->h_path.dentry); |
5afbbe0d | 22414 | + if (bindex == btop) { |
c2b27bf2 | 22415 | + h_dir = au_pinned_h_dir(&a->pin); |
523b37e3 AM |
22416 | + delegated = NULL; |
22417 | + err = vfsub_unlink(h_dir, &a->h_path, &delegated, /*force*/0); | |
22418 | + if (unlikely(err == -EWOULDBLOCK)) { | |
22419 | + pr_warn("cannot retry for NFSv4 delegation" | |
22420 | + " for an internal unlink\n"); | |
22421 | + iput(delegated); | |
22422 | + } | |
4a4d8108 AM |
22423 | + } else { |
22424 | + /* dir inode is locked */ | |
5527c038 | 22425 | + h_dir = d_inode(wh_dentry->d_parent); |
4a4d8108 AM |
22426 | + IMustLock(h_dir); |
22427 | + err = 0; | |
22428 | + } | |
dece6358 | 22429 | + |
4a4d8108 | 22430 | + if (!err) { |
7f207e10 | 22431 | + vfsub_drop_nlink(inode); |
4a4d8108 AM |
22432 | + epilog(dir, dentry, bindex); |
22433 | + | |
22434 | + /* update target timestamps */ | |
5afbbe0d | 22435 | + if (bindex == btop) { |
c2b27bf2 AM |
22436 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); |
22437 | + /*ignore*/ | |
5527c038 | 22438 | + inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
4a4d8108 AM |
22439 | + } else |
22440 | + /* todo: this timestamp may be reverted later */ | |
22441 | + inode->i_ctime = h_dir->i_ctime; | |
027c5e7a | 22442 | + goto out_unpin; /* success */ |
1facf9fc | 22443 | + } |
22444 | + | |
4a4d8108 AM |
22445 | + /* revert */ |
22446 | + if (wh_dentry) { | |
22447 | + int rerr; | |
22448 | + | |
c2b27bf2 AM |
22449 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
22450 | + &a->dt); | |
4a4d8108 AM |
22451 | + if (rerr) |
22452 | + err = rerr; | |
dece6358 | 22453 | + } |
1facf9fc | 22454 | + |
027c5e7a | 22455 | +out_unpin: |
c2b27bf2 | 22456 | + au_unpin(&a->pin); |
4a4d8108 | 22457 | + dput(wh_dentry); |
c2b27bf2 | 22458 | + dput(a->h_path.dentry); |
027c5e7a | 22459 | +out_parent: |
4a4d8108 | 22460 | + di_write_unlock(parent); |
027c5e7a | 22461 | +out_unlock: |
4a4d8108 | 22462 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 | 22463 | +out_free: |
9f237c51 | 22464 | + au_kfree_rcu(a); |
027c5e7a | 22465 | +out: |
4a4d8108 | 22466 | + return err; |
dece6358 AM |
22467 | +} |
22468 | + | |
4a4d8108 | 22469 | +int aufs_rmdir(struct inode *dir, struct dentry *dentry) |
1308ab2a | 22470 | +{ |
4a4d8108 | 22471 | + int err, rmdir_later; |
5afbbe0d | 22472 | + aufs_bindex_t bwh, bindex, btop; |
4a4d8108 AM |
22473 | + struct inode *inode; |
22474 | + struct dentry *parent, *wh_dentry, *h_dentry; | |
22475 | + struct au_whtmp_rmdir *args; | |
acd2b654 | 22476 | + /* to reduce stack size */ |
c2b27bf2 AM |
22477 | + struct { |
22478 | + struct au_dtime dt; | |
22479 | + struct au_pin pin; | |
22480 | + } *a; | |
1facf9fc | 22481 | + |
4a4d8108 | 22482 | + IMustLock(dir); |
027c5e7a | 22483 | + |
c2b27bf2 AM |
22484 | + err = -ENOMEM; |
22485 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
22486 | + if (unlikely(!a)) | |
22487 | + goto out; | |
22488 | + | |
027c5e7a AM |
22489 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_GEN); |
22490 | + if (unlikely(err)) | |
c2b27bf2 | 22491 | + goto out_free; |
53392da6 AM |
22492 | + err = au_alive_dir(dentry); |
22493 | + if (unlikely(err)) | |
027c5e7a | 22494 | + goto out_unlock; |
5527c038 | 22495 | + inode = d_inode(dentry); |
4a4d8108 | 22496 | + IMustLock(inode); |
027c5e7a | 22497 | + err = -ENOTDIR; |
2000de60 | 22498 | + if (unlikely(!d_is_dir(dentry))) |
027c5e7a | 22499 | + goto out_unlock; /* possible? */ |
dece6358 | 22500 | + |
4a4d8108 AM |
22501 | + err = -ENOMEM; |
22502 | + args = au_whtmp_rmdir_alloc(dir->i_sb, GFP_NOFS); | |
22503 | + if (unlikely(!args)) | |
22504 | + goto out_unlock; | |
dece6358 | 22505 | + |
4a4d8108 AM |
22506 | + parent = dentry->d_parent; /* dir inode is locked */ |
22507 | + di_write_lock_parent(parent); | |
22508 | + err = au_test_empty(dentry, &args->whlist); | |
22509 | + if (unlikely(err)) | |
027c5e7a | 22510 | + goto out_parent; |
1facf9fc | 22511 | + |
5afbbe0d | 22512 | + btop = au_dbtop(dentry); |
4a4d8108 AM |
22513 | + bwh = au_dbwh(dentry); |
22514 | + bindex = -1; | |
c2b27bf2 AM |
22515 | + wh_dentry = lock_hdir_create_wh(dentry, /*isdir*/1, &bindex, &a->dt, |
22516 | + &a->pin); | |
4a4d8108 AM |
22517 | + err = PTR_ERR(wh_dentry); |
22518 | + if (IS_ERR(wh_dentry)) | |
027c5e7a | 22519 | + goto out_parent; |
1facf9fc | 22520 | + |
5afbbe0d | 22521 | + h_dentry = au_h_dptr(dentry, btop); |
4a4d8108 AM |
22522 | + dget(h_dentry); |
22523 | + rmdir_later = 0; | |
5afbbe0d AM |
22524 | + if (bindex == btop) { |
22525 | + err = renwh_and_rmdir(dentry, btop, &args->whlist, dir); | |
4a4d8108 AM |
22526 | + if (err > 0) { |
22527 | + rmdir_later = err; | |
22528 | + err = 0; | |
22529 | + } | |
22530 | + } else { | |
22531 | + /* stop monitoring */ | |
5afbbe0d | 22532 | + au_hn_free(au_hi(inode, btop)); |
4a4d8108 AM |
22533 | + |
22534 | + /* dir inode is locked */ | |
5527c038 | 22535 | + IMustLock(d_inode(wh_dentry->d_parent)); |
1facf9fc | 22536 | + err = 0; |
22537 | + } | |
22538 | + | |
4a4d8108 | 22539 | + if (!err) { |
027c5e7a | 22540 | + vfsub_dead_dir(inode); |
4a4d8108 AM |
22541 | + au_set_dbdiropq(dentry, -1); |
22542 | + epilog(dir, dentry, bindex); | |
1308ab2a | 22543 | + |
4a4d8108 | 22544 | + if (rmdir_later) { |
5afbbe0d | 22545 | + au_whtmp_kick_rmdir(dir, btop, h_dentry, args); |
4a4d8108 AM |
22546 | + args = NULL; |
22547 | + } | |
1308ab2a | 22548 | + |
4a4d8108 | 22549 | + goto out_unpin; /* success */ |
1facf9fc | 22550 | + } |
22551 | + | |
4a4d8108 AM |
22552 | + /* revert */ |
22553 | + AuLabel(revert); | |
22554 | + if (wh_dentry) { | |
22555 | + int rerr; | |
1308ab2a | 22556 | + |
c2b27bf2 AM |
22557 | + rerr = do_revert(err, dir, bindex, bwh, wh_dentry, dentry, |
22558 | + &a->dt); | |
4a4d8108 AM |
22559 | + if (rerr) |
22560 | + err = rerr; | |
1facf9fc | 22561 | + } |
22562 | + | |
4f0767ce | 22563 | +out_unpin: |
c2b27bf2 | 22564 | + au_unpin(&a->pin); |
4a4d8108 AM |
22565 | + dput(wh_dentry); |
22566 | + dput(h_dentry); | |
027c5e7a | 22567 | +out_parent: |
4a4d8108 AM |
22568 | + di_write_unlock(parent); |
22569 | + if (args) | |
22570 | + au_whtmp_rmdir_free(args); | |
4f0767ce | 22571 | +out_unlock: |
4a4d8108 | 22572 | + aufs_read_unlock(dentry, AuLock_DW); |
c2b27bf2 | 22573 | +out_free: |
9f237c51 | 22574 | + au_kfree_rcu(a); |
4f0767ce | 22575 | +out: |
4a4d8108 AM |
22576 | + AuTraceErr(err); |
22577 | + return err; | |
dece6358 | 22578 | +} |
7f207e10 | 22579 | diff -urN /usr/share/empty/fs/aufs/i_op_ren.c linux/fs/aufs/i_op_ren.c |
eca34b5c | 22580 | --- /usr/share/empty/fs/aufs/i_op_ren.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 22581 | +++ linux/fs/aufs/i_op_ren.c 2020-01-27 10:57:18.172204883 +0100 |
eca801bf | 22582 | @@ -0,0 +1,1250 @@ |
cd7a4cd9 | 22583 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 22584 | +/* |
d58c55f2 | 22585 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 22586 | + * |
22587 | + * This program, aufs is free software; you can redistribute it and/or modify | |
22588 | + * it under the terms of the GNU General Public License as published by | |
22589 | + * the Free Software Foundation; either version 2 of the License, or | |
22590 | + * (at your option) any later version. | |
dece6358 AM |
22591 | + * |
22592 | + * This program is distributed in the hope that it will be useful, | |
22593 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22594 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
22595 | + * GNU General Public License for more details. | |
22596 | + * | |
22597 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 22598 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 22599 | + */ |
22600 | + | |
22601 | +/* | |
4a4d8108 AM |
22602 | + * inode operation (rename entry) |
22603 | + * todo: this is crazy monster | |
1facf9fc | 22604 | + */ |
22605 | + | |
eca801bf | 22606 | +#include <linux/iversion.h> |
1facf9fc | 22607 | +#include "aufs.h" |
22608 | + | |
4a4d8108 AM |
22609 | +enum { AuSRC, AuDST, AuSrcDst }; |
22610 | +enum { AuPARENT, AuCHILD, AuParentChild }; | |
1facf9fc | 22611 | + |
f2c43d5f AM |
22612 | +#define AuRen_ISDIR_SRC 1 |
22613 | +#define AuRen_ISDIR_DST (1 << 1) | |
22614 | +#define AuRen_ISSAMEDIR (1 << 2) | |
22615 | +#define AuRen_WHSRC (1 << 3) | |
22616 | +#define AuRen_WHDST (1 << 4) | |
22617 | +#define AuRen_MNT_WRITE (1 << 5) | |
22618 | +#define AuRen_DT_DSTDIR (1 << 6) | |
22619 | +#define AuRen_DIROPQ_SRC (1 << 7) | |
22620 | +#define AuRen_DIROPQ_DST (1 << 8) | |
8b6a4947 AM |
22621 | +#define AuRen_DIRREN (1 << 9) |
22622 | +#define AuRen_DROPPED_SRC (1 << 10) | |
22623 | +#define AuRen_DROPPED_DST (1 << 11) | |
4a4d8108 | 22624 | +#define au_ftest_ren(flags, name) ((flags) & AuRen_##name) |
7f207e10 AM |
22625 | +#define au_fset_ren(flags, name) \ |
22626 | + do { (flags) |= AuRen_##name; } while (0) | |
22627 | +#define au_fclr_ren(flags, name) \ | |
22628 | + do { (flags) &= ~AuRen_##name; } while (0) | |
1facf9fc | 22629 | + |
8b6a4947 AM |
22630 | +#ifndef CONFIG_AUFS_DIRREN |
22631 | +#undef AuRen_DIRREN | |
22632 | +#define AuRen_DIRREN 0 | |
22633 | +#endif | |
22634 | + | |
4a4d8108 AM |
22635 | +struct au_ren_args { |
22636 | + struct { | |
22637 | + struct dentry *dentry, *h_dentry, *parent, *h_parent, | |
22638 | + *wh_dentry; | |
22639 | + struct inode *dir, *inode; | |
f2c43d5f | 22640 | + struct au_hinode *hdir, *hinode; |
4a4d8108 | 22641 | + struct au_dtime dt[AuParentChild]; |
f2c43d5f | 22642 | + aufs_bindex_t btop, bdiropq; |
4a4d8108 | 22643 | + } sd[AuSrcDst]; |
1facf9fc | 22644 | + |
4a4d8108 AM |
22645 | +#define src_dentry sd[AuSRC].dentry |
22646 | +#define src_dir sd[AuSRC].dir | |
22647 | +#define src_inode sd[AuSRC].inode | |
22648 | +#define src_h_dentry sd[AuSRC].h_dentry | |
22649 | +#define src_parent sd[AuSRC].parent | |
22650 | +#define src_h_parent sd[AuSRC].h_parent | |
22651 | +#define src_wh_dentry sd[AuSRC].wh_dentry | |
22652 | +#define src_hdir sd[AuSRC].hdir | |
f2c43d5f | 22653 | +#define src_hinode sd[AuSRC].hinode |
4a4d8108 AM |
22654 | +#define src_h_dir sd[AuSRC].hdir->hi_inode |
22655 | +#define src_dt sd[AuSRC].dt | |
5afbbe0d | 22656 | +#define src_btop sd[AuSRC].btop |
f2c43d5f | 22657 | +#define src_bdiropq sd[AuSRC].bdiropq |
1facf9fc | 22658 | + |
4a4d8108 AM |
22659 | +#define dst_dentry sd[AuDST].dentry |
22660 | +#define dst_dir sd[AuDST].dir | |
22661 | +#define dst_inode sd[AuDST].inode | |
22662 | +#define dst_h_dentry sd[AuDST].h_dentry | |
22663 | +#define dst_parent sd[AuDST].parent | |
22664 | +#define dst_h_parent sd[AuDST].h_parent | |
22665 | +#define dst_wh_dentry sd[AuDST].wh_dentry | |
22666 | +#define dst_hdir sd[AuDST].hdir | |
f2c43d5f | 22667 | +#define dst_hinode sd[AuDST].hinode |
4a4d8108 AM |
22668 | +#define dst_h_dir sd[AuDST].hdir->hi_inode |
22669 | +#define dst_dt sd[AuDST].dt | |
5afbbe0d | 22670 | +#define dst_btop sd[AuDST].btop |
f2c43d5f | 22671 | +#define dst_bdiropq sd[AuDST].bdiropq |
4a4d8108 AM |
22672 | + |
22673 | + struct dentry *h_trap; | |
22674 | + struct au_branch *br; | |
4a4d8108 AM |
22675 | + struct path h_path; |
22676 | + struct au_nhash whlist; | |
f2c43d5f | 22677 | + aufs_bindex_t btgt, src_bwh; |
1facf9fc | 22678 | + |
f2c43d5f AM |
22679 | + struct { |
22680 | + unsigned short auren_flags; | |
22681 | + unsigned char flags; /* syscall parameter */ | |
22682 | + unsigned char exchange; | |
22683 | + } __packed; | |
1facf9fc | 22684 | + |
4a4d8108 AM |
22685 | + struct au_whtmp_rmdir *thargs; |
22686 | + struct dentry *h_dst; | |
8b6a4947 | 22687 | + struct au_hinode *h_root; |
4a4d8108 | 22688 | +}; |
1308ab2a | 22689 | + |
4a4d8108 | 22690 | +/* ---------------------------------------------------------------------- */ |
1308ab2a | 22691 | + |
4a4d8108 AM |
22692 | +/* |
22693 | + * functions for reverting. | |
22694 | + * when an error happened in a single rename systemcall, we should revert | |
79b8bda9 | 22695 | + * everything as if nothing happened. |
4a4d8108 AM |
22696 | + * we don't need to revert the copied-up/down the parent dir since they are |
22697 | + * harmless. | |
22698 | + */ | |
1facf9fc | 22699 | + |
4a4d8108 AM |
22700 | +#define RevertFailure(fmt, ...) do { \ |
22701 | + AuIOErr("revert failure: " fmt " (%d, %d)\n", \ | |
22702 | + ##__VA_ARGS__, err, rerr); \ | |
22703 | + err = -EIO; \ | |
22704 | +} while (0) | |
1facf9fc | 22705 | + |
f2c43d5f | 22706 | +static void au_ren_do_rev_diropq(int err, struct au_ren_args *a, int idx) |
1facf9fc | 22707 | +{ |
4a4d8108 | 22708 | + int rerr; |
f2c43d5f AM |
22709 | + struct dentry *d; |
22710 | +#define src_or_dst(member) a->sd[idx].member | |
1facf9fc | 22711 | + |
f2c43d5f AM |
22712 | + d = src_or_dst(dentry); /* {src,dst}_dentry */ |
22713 | + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD); | |
22714 | + rerr = au_diropq_remove(d, a->btgt); | |
22715 | + au_hn_inode_unlock(src_or_dst(hinode)); | |
22716 | + au_set_dbdiropq(d, src_or_dst(bdiropq)); | |
4a4d8108 | 22717 | + if (rerr) |
f2c43d5f AM |
22718 | + RevertFailure("remove diropq %pd", d); |
22719 | + | |
22720 | +#undef src_or_dst_ | |
22721 | +} | |
22722 | + | |
22723 | +static void au_ren_rev_diropq(int err, struct au_ren_args *a) | |
22724 | +{ | |
22725 | + if (au_ftest_ren(a->auren_flags, DIROPQ_SRC)) | |
22726 | + au_ren_do_rev_diropq(err, a, AuSRC); | |
22727 | + if (au_ftest_ren(a->auren_flags, DIROPQ_DST)) | |
22728 | + au_ren_do_rev_diropq(err, a, AuDST); | |
4a4d8108 | 22729 | +} |
1facf9fc | 22730 | + |
4a4d8108 AM |
22731 | +static void au_ren_rev_rename(int err, struct au_ren_args *a) |
22732 | +{ | |
22733 | + int rerr; | |
523b37e3 | 22734 | + struct inode *delegated; |
1facf9fc | 22735 | + |
b4510431 AM |
22736 | + a->h_path.dentry = vfsub_lkup_one(&a->src_dentry->d_name, |
22737 | + a->src_h_parent); | |
4a4d8108 AM |
22738 | + rerr = PTR_ERR(a->h_path.dentry); |
22739 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 22740 | + RevertFailure("lkup one %pd", a->src_dentry); |
4a4d8108 | 22741 | + return; |
1facf9fc | 22742 | + } |
22743 | + | |
523b37e3 | 22744 | + delegated = NULL; |
4a4d8108 AM |
22745 | + rerr = vfsub_rename(a->dst_h_dir, |
22746 | + au_h_dptr(a->src_dentry, a->btgt), | |
f2c43d5f | 22747 | + a->src_h_dir, &a->h_path, &delegated, a->flags); |
523b37e3 AM |
22748 | + if (unlikely(rerr == -EWOULDBLOCK)) { |
22749 | + pr_warn("cannot retry for NFSv4 delegation" | |
22750 | + " for an internal rename\n"); | |
22751 | + iput(delegated); | |
22752 | + } | |
4a4d8108 AM |
22753 | + d_drop(a->h_path.dentry); |
22754 | + dput(a->h_path.dentry); | |
22755 | + /* au_set_h_dptr(a->src_dentry, a->btgt, NULL); */ | |
22756 | + if (rerr) | |
523b37e3 | 22757 | + RevertFailure("rename %pd", a->src_dentry); |
1facf9fc | 22758 | +} |
22759 | + | |
4a4d8108 | 22760 | +static void au_ren_rev_whtmp(int err, struct au_ren_args *a) |
1facf9fc | 22761 | +{ |
4a4d8108 | 22762 | + int rerr; |
523b37e3 | 22763 | + struct inode *delegated; |
dece6358 | 22764 | + |
b4510431 AM |
22765 | + a->h_path.dentry = vfsub_lkup_one(&a->dst_dentry->d_name, |
22766 | + a->dst_h_parent); | |
4a4d8108 AM |
22767 | + rerr = PTR_ERR(a->h_path.dentry); |
22768 | + if (IS_ERR(a->h_path.dentry)) { | |
523b37e3 | 22769 | + RevertFailure("lkup one %pd", a->dst_dentry); |
4a4d8108 AM |
22770 | + return; |
22771 | + } | |
5527c038 | 22772 | + if (d_is_positive(a->h_path.dentry)) { |
4a4d8108 AM |
22773 | + d_drop(a->h_path.dentry); |
22774 | + dput(a->h_path.dentry); | |
22775 | + return; | |
dece6358 AM |
22776 | + } |
22777 | + | |
523b37e3 AM |
22778 | + delegated = NULL; |
22779 | + rerr = vfsub_rename(a->dst_h_dir, a->h_dst, a->dst_h_dir, &a->h_path, | |
f2c43d5f | 22780 | + &delegated, a->flags); |
523b37e3 AM |
22781 | + if (unlikely(rerr == -EWOULDBLOCK)) { |
22782 | + pr_warn("cannot retry for NFSv4 delegation" | |
22783 | + " for an internal rename\n"); | |
22784 | + iput(delegated); | |
22785 | + } | |
4a4d8108 AM |
22786 | + d_drop(a->h_path.dentry); |
22787 | + dput(a->h_path.dentry); | |
22788 | + if (!rerr) | |
22789 | + au_set_h_dptr(a->dst_dentry, a->btgt, dget(a->h_dst)); | |
22790 | + else | |
523b37e3 | 22791 | + RevertFailure("rename %pd", a->h_dst); |
4a4d8108 | 22792 | +} |
1308ab2a | 22793 | + |
4a4d8108 AM |
22794 | +static void au_ren_rev_whsrc(int err, struct au_ren_args *a) |
22795 | +{ | |
22796 | + int rerr; | |
1308ab2a | 22797 | + |
4a4d8108 AM |
22798 | + a->h_path.dentry = a->src_wh_dentry; |
22799 | + rerr = au_wh_unlink_dentry(a->src_h_dir, &a->h_path, a->src_dentry); | |
027c5e7a | 22800 | + au_set_dbwh(a->src_dentry, a->src_bwh); |
4a4d8108 | 22801 | + if (rerr) |
523b37e3 | 22802 | + RevertFailure("unlink %pd", a->src_wh_dentry); |
4a4d8108 | 22803 | +} |
4a4d8108 | 22804 | +#undef RevertFailure |
1facf9fc | 22805 | + |
1308ab2a | 22806 | +/* ---------------------------------------------------------------------- */ |
22807 | + | |
4a4d8108 AM |
22808 | +/* |
22809 | + * when we have to copyup the renaming entry, do it with the rename-target name | |
22810 | + * in order to minimize the cost (the later actual rename is unnecessary). | |
22811 | + * otherwise rename it on the target branch. | |
22812 | + */ | |
22813 | +static int au_ren_or_cpup(struct au_ren_args *a) | |
1facf9fc | 22814 | +{ |
dece6358 | 22815 | + int err; |
4a4d8108 | 22816 | + struct dentry *d; |
523b37e3 | 22817 | + struct inode *delegated; |
1facf9fc | 22818 | + |
4a4d8108 | 22819 | + d = a->src_dentry; |
5afbbe0d | 22820 | + if (au_dbtop(d) == a->btgt) { |
4a4d8108 | 22821 | + a->h_path.dentry = a->dst_h_dentry; |
5afbbe0d | 22822 | + AuDebugOn(au_dbtop(d) != a->btgt); |
523b37e3 | 22823 | + delegated = NULL; |
4a4d8108 | 22824 | + err = vfsub_rename(a->src_h_dir, au_h_dptr(d, a->btgt), |
f2c43d5f AM |
22825 | + a->dst_h_dir, &a->h_path, &delegated, |
22826 | + a->flags); | |
523b37e3 AM |
22827 | + if (unlikely(err == -EWOULDBLOCK)) { |
22828 | + pr_warn("cannot retry for NFSv4 delegation" | |
22829 | + " for an internal rename\n"); | |
22830 | + iput(delegated); | |
22831 | + } | |
c2b27bf2 | 22832 | + } else |
86dc4139 | 22833 | + BUG(); |
1308ab2a | 22834 | + |
027c5e7a AM |
22835 | + if (!err && a->h_dst) |
22836 | + /* it will be set to dinfo later */ | |
22837 | + dget(a->h_dst); | |
1facf9fc | 22838 | + |
dece6358 AM |
22839 | + return err; |
22840 | +} | |
1facf9fc | 22841 | + |
4a4d8108 AM |
22842 | +/* cf. aufs_rmdir() */ |
22843 | +static int au_ren_del_whtmp(struct au_ren_args *a) | |
dece6358 | 22844 | +{ |
4a4d8108 AM |
22845 | + int err; |
22846 | + struct inode *dir; | |
1facf9fc | 22847 | + |
4a4d8108 AM |
22848 | + dir = a->dst_dir; |
22849 | + SiMustAnyLock(dir->i_sb); | |
22850 | + if (!au_nhash_test_longer_wh(&a->whlist, a->btgt, | |
22851 | + au_sbi(dir->i_sb)->si_dirwh) | |
22852 | + || au_test_fs_remote(a->h_dst->d_sb)) { | |
22853 | + err = au_whtmp_rmdir(dir, a->btgt, a->h_dst, &a->whlist); | |
22854 | + if (unlikely(err)) | |
523b37e3 AM |
22855 | + pr_warn("failed removing whtmp dir %pd (%d), " |
22856 | + "ignored.\n", a->h_dst, err); | |
4a4d8108 AM |
22857 | + } else { |
22858 | + au_nhash_wh_free(&a->thargs->whlist); | |
22859 | + a->thargs->whlist = a->whlist; | |
22860 | + a->whlist.nh_num = 0; | |
22861 | + au_whtmp_kick_rmdir(dir, a->btgt, a->h_dst, a->thargs); | |
22862 | + dput(a->h_dst); | |
22863 | + a->thargs = NULL; | |
22864 | + } | |
22865 | + | |
22866 | + return 0; | |
1308ab2a | 22867 | +} |
1facf9fc | 22868 | + |
4a4d8108 | 22869 | +/* make it 'opaque' dir. */ |
f2c43d5f | 22870 | +static int au_ren_do_diropq(struct au_ren_args *a, int idx) |
4a4d8108 AM |
22871 | +{ |
22872 | + int err; | |
f2c43d5f AM |
22873 | + struct dentry *d, *diropq; |
22874 | +#define src_or_dst(member) a->sd[idx].member | |
1facf9fc | 22875 | + |
4a4d8108 | 22876 | + err = 0; |
f2c43d5f AM |
22877 | + d = src_or_dst(dentry); /* {src,dst}_dentry */ |
22878 | + src_or_dst(bdiropq) = au_dbdiropq(d); | |
22879 | + src_or_dst(hinode) = au_hi(src_or_dst(inode), a->btgt); | |
22880 | + au_hn_inode_lock_nested(src_or_dst(hinode), AuLsc_I_CHILD); | |
22881 | + diropq = au_diropq_create(d, a->btgt); | |
22882 | + au_hn_inode_unlock(src_or_dst(hinode)); | |
4a4d8108 AM |
22883 | + if (IS_ERR(diropq)) |
22884 | + err = PTR_ERR(diropq); | |
076b876e AM |
22885 | + else |
22886 | + dput(diropq); | |
1facf9fc | 22887 | + |
f2c43d5f | 22888 | +#undef src_or_dst_ |
4a4d8108 AM |
22889 | + return err; |
22890 | +} | |
1facf9fc | 22891 | + |
f2c43d5f | 22892 | +static int au_ren_diropq(struct au_ren_args *a) |
4a4d8108 AM |
22893 | +{ |
22894 | + int err; | |
f2c43d5f AM |
22895 | + unsigned char always; |
22896 | + struct dentry *d; | |
1facf9fc | 22897 | + |
f2c43d5f AM |
22898 | + err = 0; |
22899 | + d = a->dst_dentry; /* already renamed on the branch */ | |
22900 | + always = !!au_opt_test(au_mntflags(d->d_sb), ALWAYS_DIROPQ); | |
22901 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) | |
8b6a4947 | 22902 | + && !au_ftest_ren(a->auren_flags, DIRREN) |
f2c43d5f AM |
22903 | + && a->btgt != au_dbdiropq(a->src_dentry) |
22904 | + && (a->dst_wh_dentry | |
22905 | + || a->btgt <= au_dbdiropq(d) | |
22906 | + /* hide the lower to keep xino */ | |
22907 | + /* the lowers may not be a dir, but we hide them anyway */ | |
22908 | + || a->btgt < au_dbbot(d) | |
22909 | + || always)) { | |
22910 | + AuDbg("here\n"); | |
22911 | + err = au_ren_do_diropq(a, AuSRC); | |
22912 | + if (unlikely(err)) | |
4a4d8108 | 22913 | + goto out; |
f2c43d5f | 22914 | + au_fset_ren(a->auren_flags, DIROPQ_SRC); |
4a4d8108 | 22915 | + } |
f2c43d5f AM |
22916 | + if (!a->exchange) |
22917 | + goto out; /* success */ | |
1facf9fc | 22918 | + |
f2c43d5f AM |
22919 | + d = a->src_dentry; /* already renamed on the branch */ |
22920 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) | |
22921 | + && a->btgt != au_dbdiropq(a->dst_dentry) | |
22922 | + && (a->btgt < au_dbdiropq(d) | |
22923 | + || a->btgt < au_dbbot(d) | |
22924 | + || always)) { | |
22925 | + AuDbgDentry(a->src_dentry); | |
22926 | + AuDbgDentry(a->dst_dentry); | |
22927 | + err = au_ren_do_diropq(a, AuDST); | |
4a4d8108 | 22928 | + if (unlikely(err)) |
f2c43d5f AM |
22929 | + goto out_rev_src; |
22930 | + au_fset_ren(a->auren_flags, DIROPQ_DST); | |
22931 | + } | |
22932 | + goto out; /* success */ | |
dece6358 | 22933 | + |
f2c43d5f AM |
22934 | +out_rev_src: |
22935 | + AuDbg("err %d, reverting src\n", err); | |
22936 | + au_ren_rev_diropq(err, a); | |
22937 | +out: | |
22938 | + return err; | |
22939 | +} | |
22940 | + | |
22941 | +static int do_rename(struct au_ren_args *a) | |
22942 | +{ | |
22943 | + int err; | |
22944 | + struct dentry *d, *h_d; | |
22945 | + | |
22946 | + if (!a->exchange) { | |
22947 | + /* prepare workqueue args for asynchronous rmdir */ | |
22948 | + h_d = a->dst_h_dentry; | |
22949 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) | |
8b6a4947 | 22950 | + /* && !au_ftest_ren(a->auren_flags, DIRREN) */ |
f2c43d5f AM |
22951 | + && d_is_positive(h_d)) { |
22952 | + err = -ENOMEM; | |
22953 | + a->thargs = au_whtmp_rmdir_alloc(a->src_dentry->d_sb, | |
22954 | + GFP_NOFS); | |
22955 | + if (unlikely(!a->thargs)) | |
22956 | + goto out; | |
22957 | + a->h_dst = dget(h_d); | |
22958 | + } | |
22959 | + | |
22960 | + /* create whiteout for src_dentry */ | |
22961 | + if (au_ftest_ren(a->auren_flags, WHSRC)) { | |
22962 | + a->src_bwh = au_dbwh(a->src_dentry); | |
22963 | + AuDebugOn(a->src_bwh >= 0); | |
22964 | + a->src_wh_dentry = au_wh_create(a->src_dentry, a->btgt, | |
22965 | + a->src_h_parent); | |
22966 | + err = PTR_ERR(a->src_wh_dentry); | |
22967 | + if (IS_ERR(a->src_wh_dentry)) | |
22968 | + goto out_thargs; | |
22969 | + } | |
22970 | + | |
22971 | + /* lookup whiteout for dentry */ | |
22972 | + if (au_ftest_ren(a->auren_flags, WHDST)) { | |
22973 | + h_d = au_wh_lkup(a->dst_h_parent, | |
22974 | + &a->dst_dentry->d_name, a->br); | |
22975 | + err = PTR_ERR(h_d); | |
22976 | + if (IS_ERR(h_d)) | |
22977 | + goto out_whsrc; | |
22978 | + if (d_is_negative(h_d)) | |
22979 | + dput(h_d); | |
22980 | + else | |
22981 | + a->dst_wh_dentry = h_d; | |
22982 | + } | |
22983 | + | |
22984 | + /* rename dentry to tmpwh */ | |
22985 | + if (a->thargs) { | |
22986 | + err = au_whtmp_ren(a->dst_h_dentry, a->br); | |
22987 | + if (unlikely(err)) | |
22988 | + goto out_whdst; | |
22989 | + | |
22990 | + d = a->dst_dentry; | |
22991 | + au_set_h_dptr(d, a->btgt, NULL); | |
22992 | + err = au_lkup_neg(d, a->btgt, /*wh*/0); | |
22993 | + if (unlikely(err)) | |
22994 | + goto out_whtmp; | |
22995 | + a->dst_h_dentry = au_h_dptr(d, a->btgt); | |
22996 | + } | |
4a4d8108 | 22997 | + } |
1facf9fc | 22998 | + |
5afbbe0d | 22999 | + BUG_ON(d_is_positive(a->dst_h_dentry) && a->src_btop != a->btgt); |
43982f53 | 23000 | +#if 0 /* debugging */ |
8b6a4947 AM |
23001 | + BUG_ON(!au_ftest_ren(a->auren_flags, DIRREN) |
23002 | + && d_is_positive(a->dst_h_dentry) | |
23003 | + && a->src_btop != a->btgt); | |
23004 | +#endif | |
1facf9fc | 23005 | + |
4a4d8108 | 23006 | + /* rename by vfs_rename or cpup */ |
4a4d8108 AM |
23007 | + err = au_ren_or_cpup(a); |
23008 | + if (unlikely(err)) | |
23009 | + /* leave the copied-up one */ | |
23010 | + goto out_whtmp; | |
1308ab2a | 23011 | + |
4a4d8108 | 23012 | + /* make dir opaque */ |
f2c43d5f AM |
23013 | + err = au_ren_diropq(a); |
23014 | + if (unlikely(err)) | |
23015 | + goto out_rename; | |
1308ab2a | 23016 | + |
4a4d8108 | 23017 | + /* update target timestamps */ |
f2c43d5f AM |
23018 | + if (a->exchange) { |
23019 | + AuDebugOn(au_dbtop(a->dst_dentry) != a->btgt); | |
23020 | + a->h_path.dentry = au_h_dptr(a->dst_dentry, a->btgt); | |
23021 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
23022 | + a->dst_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; | |
23023 | + } | |
5afbbe0d | 23024 | + AuDebugOn(au_dbtop(a->src_dentry) != a->btgt); |
4a4d8108 AM |
23025 | + a->h_path.dentry = au_h_dptr(a->src_dentry, a->btgt); |
23026 | + vfsub_update_h_iattr(&a->h_path, /*did*/NULL); /*ignore*/ | |
5527c038 | 23027 | + a->src_inode->i_ctime = d_inode(a->h_path.dentry)->i_ctime; |
1facf9fc | 23028 | + |
f2c43d5f AM |
23029 | + if (!a->exchange) { |
23030 | + /* remove whiteout for dentry */ | |
23031 | + if (a->dst_wh_dentry) { | |
23032 | + a->h_path.dentry = a->dst_wh_dentry; | |
23033 | + err = au_wh_unlink_dentry(a->dst_h_dir, &a->h_path, | |
23034 | + a->dst_dentry); | |
23035 | + if (unlikely(err)) | |
23036 | + goto out_diropq; | |
23037 | + } | |
1facf9fc | 23038 | + |
f2c43d5f AM |
23039 | + /* remove whtmp */ |
23040 | + if (a->thargs) | |
23041 | + au_ren_del_whtmp(a); /* ignore this error */ | |
1308ab2a | 23042 | + |
f2c43d5f AM |
23043 | + au_fhsm_wrote(a->src_dentry->d_sb, a->btgt, /*force*/0); |
23044 | + } | |
4a4d8108 AM |
23045 | + err = 0; |
23046 | + goto out_success; | |
23047 | + | |
4f0767ce | 23048 | +out_diropq: |
f2c43d5f | 23049 | + au_ren_rev_diropq(err, a); |
4f0767ce | 23050 | +out_rename: |
7e9cd9fe | 23051 | + au_ren_rev_rename(err, a); |
027c5e7a | 23052 | + dput(a->h_dst); |
4f0767ce | 23053 | +out_whtmp: |
4a4d8108 AM |
23054 | + if (a->thargs) |
23055 | + au_ren_rev_whtmp(err, a); | |
4f0767ce | 23056 | +out_whdst: |
4a4d8108 AM |
23057 | + dput(a->dst_wh_dentry); |
23058 | + a->dst_wh_dentry = NULL; | |
4f0767ce | 23059 | +out_whsrc: |
4a4d8108 AM |
23060 | + if (a->src_wh_dentry) |
23061 | + au_ren_rev_whsrc(err, a); | |
4f0767ce | 23062 | +out_success: |
4a4d8108 AM |
23063 | + dput(a->src_wh_dentry); |
23064 | + dput(a->dst_wh_dentry); | |
4f0767ce | 23065 | +out_thargs: |
4a4d8108 AM |
23066 | + if (a->thargs) { |
23067 | + dput(a->h_dst); | |
23068 | + au_whtmp_rmdir_free(a->thargs); | |
23069 | + a->thargs = NULL; | |
23070 | + } | |
4f0767ce | 23071 | +out: |
4a4d8108 | 23072 | + return err; |
dece6358 | 23073 | +} |
1facf9fc | 23074 | + |
1308ab2a | 23075 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 23076 | + |
4a4d8108 AM |
23077 | +/* |
23078 | + * test if @dentry dir can be rename destination or not. | |
23079 | + * success means, it is a logically empty dir. | |
23080 | + */ | |
23081 | +static int may_rename_dstdir(struct dentry *dentry, struct au_nhash *whlist) | |
1308ab2a | 23082 | +{ |
4a4d8108 | 23083 | + return au_test_empty(dentry, whlist); |
1308ab2a | 23084 | +} |
1facf9fc | 23085 | + |
4a4d8108 | 23086 | +/* |
8b6a4947 AM |
23087 | + * test if @a->src_dentry dir can be rename source or not. |
23088 | + * if it can, return 0. | |
4a4d8108 AM |
23089 | + * success means, |
23090 | + * - it is a logically empty dir. | |
23091 | + * - or, it exists on writable branch and has no children including whiteouts | |
8b6a4947 | 23092 | + * on the lower branch unless DIRREN is on. |
4a4d8108 | 23093 | + */ |
8b6a4947 | 23094 | +static int may_rename_srcdir(struct au_ren_args *a) |
4a4d8108 AM |
23095 | +{ |
23096 | + int err; | |
23097 | + unsigned int rdhash; | |
8b6a4947 AM |
23098 | + aufs_bindex_t btop, btgt; |
23099 | + struct dentry *dentry; | |
23100 | + struct super_block *sb; | |
23101 | + struct au_sbinfo *sbinfo; | |
1facf9fc | 23102 | + |
8b6a4947 AM |
23103 | + dentry = a->src_dentry; |
23104 | + sb = dentry->d_sb; | |
23105 | + sbinfo = au_sbi(sb); | |
23106 | + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) | |
23107 | + au_fset_ren(a->auren_flags, DIRREN); | |
23108 | + | |
23109 | + btgt = a->btgt; | |
5afbbe0d AM |
23110 | + btop = au_dbtop(dentry); |
23111 | + if (btop != btgt) { | |
4a4d8108 | 23112 | + struct au_nhash whlist; |
dece6358 | 23113 | + |
8b6a4947 AM |
23114 | + SiMustAnyLock(sb); |
23115 | + rdhash = sbinfo->si_rdhash; | |
4a4d8108 AM |
23116 | + if (!rdhash) |
23117 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, | |
23118 | + dentry)); | |
23119 | + err = au_nhash_alloc(&whlist, rdhash, GFP_NOFS); | |
23120 | + if (unlikely(err)) | |
23121 | + goto out; | |
23122 | + err = au_test_empty(dentry, &whlist); | |
23123 | + au_nhash_wh_free(&whlist); | |
23124 | + goto out; | |
23125 | + } | |
dece6358 | 23126 | + |
5afbbe0d | 23127 | + if (btop == au_dbtaildir(dentry)) |
4a4d8108 | 23128 | + return 0; /* success */ |
dece6358 | 23129 | + |
4a4d8108 | 23130 | + err = au_test_empty_lower(dentry); |
1facf9fc | 23131 | + |
4f0767ce | 23132 | +out: |
4a4d8108 | 23133 | + if (err == -ENOTEMPTY) { |
8b6a4947 AM |
23134 | + if (au_ftest_ren(a->auren_flags, DIRREN)) { |
23135 | + err = 0; | |
23136 | + } else { | |
23137 | + AuWarn1("renaming dir who has child(ren) on multiple " | |
23138 | + "branches, is not supported\n"); | |
23139 | + err = -EXDEV; | |
23140 | + } | |
4a4d8108 AM |
23141 | + } |
23142 | + return err; | |
23143 | +} | |
1308ab2a | 23144 | + |
4a4d8108 AM |
23145 | +/* side effect: sets whlist and h_dentry */ |
23146 | +static int au_ren_may_dir(struct au_ren_args *a) | |
1308ab2a | 23147 | +{ |
4a4d8108 AM |
23148 | + int err; |
23149 | + unsigned int rdhash; | |
23150 | + struct dentry *d; | |
1facf9fc | 23151 | + |
4a4d8108 AM |
23152 | + d = a->dst_dentry; |
23153 | + SiMustAnyLock(d->d_sb); | |
1facf9fc | 23154 | + |
4a4d8108 | 23155 | + err = 0; |
f2c43d5f | 23156 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST) && a->dst_inode) { |
4a4d8108 AM |
23157 | + rdhash = au_sbi(d->d_sb)->si_rdhash; |
23158 | + if (!rdhash) | |
23159 | + rdhash = au_rdhash_est(au_dir_size(/*file*/NULL, d)); | |
23160 | + err = au_nhash_alloc(&a->whlist, rdhash, GFP_NOFS); | |
23161 | + if (unlikely(err)) | |
23162 | + goto out; | |
1308ab2a | 23163 | + |
f2c43d5f AM |
23164 | + if (!a->exchange) { |
23165 | + au_set_dbtop(d, a->dst_btop); | |
23166 | + err = may_rename_dstdir(d, &a->whlist); | |
23167 | + au_set_dbtop(d, a->btgt); | |
23168 | + } else | |
8b6a4947 | 23169 | + err = may_rename_srcdir(a); |
4a4d8108 | 23170 | + } |
5afbbe0d | 23171 | + a->dst_h_dentry = au_h_dptr(d, au_dbtop(d)); |
4a4d8108 AM |
23172 | + if (unlikely(err)) |
23173 | + goto out; | |
23174 | + | |
23175 | + d = a->src_dentry; | |
5afbbe0d | 23176 | + a->src_h_dentry = au_h_dptr(d, au_dbtop(d)); |
f2c43d5f | 23177 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { |
8b6a4947 | 23178 | + err = may_rename_srcdir(a); |
4a4d8108 AM |
23179 | + if (unlikely(err)) { |
23180 | + au_nhash_wh_free(&a->whlist); | |
23181 | + a->whlist.nh_num = 0; | |
23182 | + } | |
23183 | + } | |
4f0767ce | 23184 | +out: |
4a4d8108 | 23185 | + return err; |
1facf9fc | 23186 | +} |
23187 | + | |
4a4d8108 | 23188 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 23189 | + |
4a4d8108 AM |
23190 | +/* |
23191 | + * simple tests for rename. | |
23192 | + * following the checks in vfs, plus the parent-child relationship. | |
23193 | + */ | |
23194 | +static int au_may_ren(struct au_ren_args *a) | |
23195 | +{ | |
23196 | + int err, isdir; | |
23197 | + struct inode *h_inode; | |
1facf9fc | 23198 | + |
5afbbe0d | 23199 | + if (a->src_btop == a->btgt) { |
4a4d8108 | 23200 | + err = au_may_del(a->src_dentry, a->btgt, a->src_h_parent, |
f2c43d5f | 23201 | + au_ftest_ren(a->auren_flags, ISDIR_SRC)); |
4a4d8108 AM |
23202 | + if (unlikely(err)) |
23203 | + goto out; | |
23204 | + err = -EINVAL; | |
23205 | + if (unlikely(a->src_h_dentry == a->h_trap)) | |
23206 | + goto out; | |
23207 | + } | |
1facf9fc | 23208 | + |
4a4d8108 | 23209 | + err = 0; |
5afbbe0d | 23210 | + if (a->dst_btop != a->btgt) |
4a4d8108 | 23211 | + goto out; |
1facf9fc | 23212 | + |
027c5e7a AM |
23213 | + err = -ENOTEMPTY; |
23214 | + if (unlikely(a->dst_h_dentry == a->h_trap)) | |
23215 | + goto out; | |
23216 | + | |
4a4d8108 | 23217 | + err = -EIO; |
f2c43d5f | 23218 | + isdir = !!au_ftest_ren(a->auren_flags, ISDIR_DST); |
5527c038 JR |
23219 | + if (d_really_is_negative(a->dst_dentry)) { |
23220 | + if (d_is_negative(a->dst_h_dentry)) | |
23221 | + err = au_may_add(a->dst_dentry, a->btgt, | |
23222 | + a->dst_h_parent, isdir); | |
4a4d8108 | 23223 | + } else { |
5527c038 | 23224 | + if (unlikely(d_is_negative(a->dst_h_dentry))) |
4a4d8108 | 23225 | + goto out; |
5527c038 JR |
23226 | + h_inode = d_inode(a->dst_h_dentry); |
23227 | + if (h_inode->i_nlink) | |
23228 | + err = au_may_del(a->dst_dentry, a->btgt, | |
23229 | + a->dst_h_parent, isdir); | |
4a4d8108 | 23230 | + } |
1facf9fc | 23231 | + |
4f0767ce | 23232 | +out: |
4a4d8108 AM |
23233 | + if (unlikely(err == -ENOENT || err == -EEXIST)) |
23234 | + err = -EIO; | |
23235 | + AuTraceErr(err); | |
23236 | + return err; | |
23237 | +} | |
1facf9fc | 23238 | + |
1308ab2a | 23239 | +/* ---------------------------------------------------------------------- */ |
1facf9fc | 23240 | + |
4a4d8108 AM |
23241 | +/* |
23242 | + * locking order | |
23243 | + * (VFS) | |
23244 | + * - src_dir and dir by lock_rename() | |
acd2b654 | 23245 | + * - inode if exists |
4a4d8108 AM |
23246 | + * (aufs) |
23247 | + * - lock all | |
23248 | + * + src_dentry and dentry by aufs_read_and_write_lock2() which calls, | |
23249 | + * + si_read_lock | |
23250 | + * + di_write_lock2_child() | |
23251 | + * + di_write_lock_child() | |
23252 | + * + ii_write_lock_child() | |
23253 | + * + di_write_lock_child2() | |
23254 | + * + ii_write_lock_child2() | |
23255 | + * + src_parent and parent | |
23256 | + * + di_write_lock_parent() | |
23257 | + * + ii_write_lock_parent() | |
23258 | + * + di_write_lock_parent2() | |
23259 | + * + ii_write_lock_parent2() | |
23260 | + * + lower src_dir and dir by vfsub_lock_rename() | |
23261 | + * + verify the every relationships between child and parent. if any | |
23262 | + * of them failed, unlock all and return -EBUSY. | |
23263 | + */ | |
23264 | +static void au_ren_unlock(struct au_ren_args *a) | |
1308ab2a | 23265 | +{ |
4a4d8108 AM |
23266 | + vfsub_unlock_rename(a->src_h_parent, a->src_hdir, |
23267 | + a->dst_h_parent, a->dst_hdir); | |
8b6a4947 AM |
23268 | + if (au_ftest_ren(a->auren_flags, DIRREN) |
23269 | + && a->h_root) | |
23270 | + au_hn_inode_unlock(a->h_root); | |
f2c43d5f | 23271 | + if (au_ftest_ren(a->auren_flags, MNT_WRITE)) |
86dc4139 | 23272 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
1308ab2a | 23273 | +} |
23274 | + | |
4a4d8108 | 23275 | +static int au_ren_lock(struct au_ren_args *a) |
1308ab2a | 23276 | +{ |
4a4d8108 AM |
23277 | + int err; |
23278 | + unsigned int udba; | |
1308ab2a | 23279 | + |
4a4d8108 AM |
23280 | + err = 0; |
23281 | + a->src_h_parent = au_h_dptr(a->src_parent, a->btgt); | |
23282 | + a->src_hdir = au_hi(a->src_dir, a->btgt); | |
23283 | + a->dst_h_parent = au_h_dptr(a->dst_parent, a->btgt); | |
23284 | + a->dst_hdir = au_hi(a->dst_dir, a->btgt); | |
86dc4139 AM |
23285 | + |
23286 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); | |
23287 | + if (unlikely(err)) | |
23288 | + goto out; | |
f2c43d5f | 23289 | + au_fset_ren(a->auren_flags, MNT_WRITE); |
8b6a4947 AM |
23290 | + if (au_ftest_ren(a->auren_flags, DIRREN)) { |
23291 | + struct dentry *root; | |
23292 | + struct inode *dir; | |
23293 | + | |
23294 | + /* | |
23295 | + * sbinfo is already locked, so this ii_read_lock is | |
23296 | + * unnecessary. but our debugging feature checks it. | |
23297 | + */ | |
23298 | + root = a->src_inode->i_sb->s_root; | |
23299 | + if (root != a->src_parent && root != a->dst_parent) { | |
23300 | + dir = d_inode(root); | |
23301 | + ii_read_lock_parent3(dir); | |
23302 | + a->h_root = au_hi(dir, a->btgt); | |
23303 | + ii_read_unlock(dir); | |
23304 | + au_hn_inode_lock_nested(a->h_root, AuLsc_I_PARENT3); | |
23305 | + } | |
23306 | + } | |
4a4d8108 AM |
23307 | + a->h_trap = vfsub_lock_rename(a->src_h_parent, a->src_hdir, |
23308 | + a->dst_h_parent, a->dst_hdir); | |
23309 | + udba = au_opt_udba(a->src_dentry->d_sb); | |
5527c038 JR |
23310 | + if (unlikely(a->src_hdir->hi_inode != d_inode(a->src_h_parent) |
23311 | + || a->dst_hdir->hi_inode != d_inode(a->dst_h_parent))) | |
4a4d8108 | 23312 | + err = au_busy_or_stale(); |
5afbbe0d | 23313 | + if (!err && au_dbtop(a->src_dentry) == a->btgt) |
4a4d8108 | 23314 | + err = au_h_verify(a->src_h_dentry, udba, |
5527c038 | 23315 | + d_inode(a->src_h_parent), a->src_h_parent, |
4a4d8108 | 23316 | + a->br); |
5afbbe0d | 23317 | + if (!err && au_dbtop(a->dst_dentry) == a->btgt) |
4a4d8108 | 23318 | + err = au_h_verify(a->dst_h_dentry, udba, |
5527c038 | 23319 | + d_inode(a->dst_h_parent), a->dst_h_parent, |
4a4d8108 | 23320 | + a->br); |
86dc4139 | 23321 | + if (!err) |
4a4d8108 | 23322 | + goto out; /* success */ |
4a4d8108 AM |
23323 | + |
23324 | + err = au_busy_or_stale(); | |
4a4d8108 | 23325 | + au_ren_unlock(a); |
86dc4139 | 23326 | + |
4f0767ce | 23327 | +out: |
4a4d8108 | 23328 | + return err; |
1facf9fc | 23329 | +} |
23330 | + | |
23331 | +/* ---------------------------------------------------------------------- */ | |
23332 | + | |
4a4d8108 | 23333 | +static void au_ren_refresh_dir(struct au_ren_args *a) |
1facf9fc | 23334 | +{ |
4a4d8108 | 23335 | + struct inode *dir; |
dece6358 | 23336 | + |
4a4d8108 | 23337 | + dir = a->dst_dir; |
be118d29 | 23338 | + inode_inc_iversion(dir); |
f2c43d5f | 23339 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) { |
4a4d8108 AM |
23340 | + /* is this updating defined in POSIX? */ |
23341 | + au_cpup_attr_timesizes(a->src_inode); | |
23342 | + au_cpup_attr_nlink(dir, /*force*/1); | |
4a4d8108 | 23343 | + } |
b912730e | 23344 | + au_dir_ts(dir, a->btgt); |
dece6358 | 23345 | + |
f2c43d5f AM |
23346 | + if (a->exchange) { |
23347 | + dir = a->src_dir; | |
be118d29 | 23348 | + inode_inc_iversion(dir); |
f2c43d5f AM |
23349 | + if (au_ftest_ren(a->auren_flags, ISDIR_DST)) { |
23350 | + /* is this updating defined in POSIX? */ | |
23351 | + au_cpup_attr_timesizes(a->dst_inode); | |
23352 | + au_cpup_attr_nlink(dir, /*force*/1); | |
23353 | + } | |
23354 | + au_dir_ts(dir, a->btgt); | |
23355 | + } | |
23356 | + | |
23357 | + if (au_ftest_ren(a->auren_flags, ISSAMEDIR)) | |
4a4d8108 | 23358 | + return; |
dece6358 | 23359 | + |
4a4d8108 | 23360 | + dir = a->src_dir; |
be118d29 | 23361 | + inode_inc_iversion(dir); |
f2c43d5f | 23362 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC)) |
4a4d8108 | 23363 | + au_cpup_attr_nlink(dir, /*force*/1); |
b912730e | 23364 | + au_dir_ts(dir, a->btgt); |
1facf9fc | 23365 | +} |
23366 | + | |
4a4d8108 | 23367 | +static void au_ren_refresh(struct au_ren_args *a) |
1facf9fc | 23368 | +{ |
5afbbe0d | 23369 | + aufs_bindex_t bbot, bindex; |
4a4d8108 AM |
23370 | + struct dentry *d, *h_d; |
23371 | + struct inode *i, *h_i; | |
23372 | + struct super_block *sb; | |
dece6358 | 23373 | + |
027c5e7a AM |
23374 | + d = a->dst_dentry; |
23375 | + d_drop(d); | |
23376 | + if (a->h_dst) | |
23377 | + /* already dget-ed by au_ren_or_cpup() */ | |
23378 | + au_set_h_dptr(d, a->btgt, a->h_dst); | |
23379 | + | |
23380 | + i = a->dst_inode; | |
23381 | + if (i) { | |
f2c43d5f AM |
23382 | + if (!a->exchange) { |
23383 | + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) | |
23384 | + vfsub_drop_nlink(i); | |
23385 | + else { | |
23386 | + vfsub_dead_dir(i); | |
23387 | + au_cpup_attr_timesizes(i); | |
23388 | + } | |
23389 | + au_update_dbrange(d, /*do_put_zero*/1); | |
23390 | + } else | |
23391 | + au_cpup_attr_nlink(i, /*force*/1); | |
027c5e7a | 23392 | + } else { |
5afbbe0d AM |
23393 | + bbot = a->btgt; |
23394 | + for (bindex = au_dbtop(d); bindex < bbot; bindex++) | |
027c5e7a | 23395 | + au_set_h_dptr(d, bindex, NULL); |
5afbbe0d AM |
23396 | + bbot = au_dbbot(d); |
23397 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) | |
027c5e7a AM |
23398 | + au_set_h_dptr(d, bindex, NULL); |
23399 | + au_update_dbrange(d, /*do_put_zero*/0); | |
23400 | + } | |
23401 | + | |
8b6a4947 AM |
23402 | + if (a->exchange |
23403 | + || au_ftest_ren(a->auren_flags, DIRREN)) { | |
23404 | + d_drop(a->src_dentry); | |
23405 | + if (au_ftest_ren(a->auren_flags, DIRREN)) | |
23406 | + au_set_dbwh(a->src_dentry, -1); | |
23407 | + return; | |
23408 | + } | |
23409 | + | |
4a4d8108 | 23410 | + d = a->src_dentry; |
8b6a4947 AM |
23411 | + au_set_dbwh(d, -1); |
23412 | + bbot = au_dbbot(d); | |
23413 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { | |
23414 | + h_d = au_h_dptr(d, bindex); | |
23415 | + if (h_d) | |
23416 | + au_set_h_dptr(d, bindex, NULL); | |
23417 | + } | |
23418 | + au_set_dbbot(d, a->btgt); | |
4a4d8108 | 23419 | + |
8b6a4947 AM |
23420 | + sb = d->d_sb; |
23421 | + i = a->src_inode; | |
23422 | + if (au_opt_test(au_mntflags(sb), PLINK) && au_plink_test(i)) | |
23423 | + return; /* success */ | |
4a4d8108 | 23424 | + |
8b6a4947 AM |
23425 | + bbot = au_ibbot(i); |
23426 | + for (bindex = a->btgt + 1; bindex <= bbot; bindex++) { | |
23427 | + h_i = au_h_iptr(i, bindex); | |
23428 | + if (h_i) { | |
23429 | + au_xino_write(sb, bindex, h_i->i_ino, /*ino*/0); | |
23430 | + /* ignore this error */ | |
23431 | + au_set_h_iptr(i, bindex, NULL, 0); | |
4a4d8108 AM |
23432 | + } |
23433 | + } | |
8b6a4947 | 23434 | + au_set_ibbot(i, a->btgt); |
1308ab2a | 23435 | +} |
dece6358 | 23436 | + |
4a4d8108 AM |
23437 | +/* ---------------------------------------------------------------------- */ |
23438 | + | |
23439 | +/* mainly for link(2) and rename(2) */ | |
23440 | +int au_wbr(struct dentry *dentry, aufs_bindex_t btgt) | |
1308ab2a | 23441 | +{ |
4a4d8108 AM |
23442 | + aufs_bindex_t bdiropq, bwh; |
23443 | + struct dentry *parent; | |
23444 | + struct au_branch *br; | |
23445 | + | |
23446 | + parent = dentry->d_parent; | |
5527c038 | 23447 | + IMustLock(d_inode(parent)); /* dir is locked */ |
4a4d8108 AM |
23448 | + |
23449 | + bdiropq = au_dbdiropq(parent); | |
23450 | + bwh = au_dbwh(dentry); | |
23451 | + br = au_sbr(dentry->d_sb, btgt); | |
23452 | + if (au_br_rdonly(br) | |
23453 | + || (0 <= bdiropq && bdiropq < btgt) | |
23454 | + || (0 <= bwh && bwh < btgt)) | |
23455 | + btgt = -1; | |
23456 | + | |
23457 | + AuDbg("btgt %d\n", btgt); | |
23458 | + return btgt; | |
1facf9fc | 23459 | +} |
23460 | + | |
5afbbe0d | 23461 | +/* sets src_btop, dst_btop and btgt */ |
4a4d8108 | 23462 | +static int au_ren_wbr(struct au_ren_args *a) |
1facf9fc | 23463 | +{ |
4a4d8108 AM |
23464 | + int err; |
23465 | + struct au_wr_dir_args wr_dir_args = { | |
23466 | + /* .force_btgt = -1, */ | |
23467 | + .flags = AuWrDir_ADD_ENTRY | |
23468 | + }; | |
dece6358 | 23469 | + |
5afbbe0d AM |
23470 | + a->src_btop = au_dbtop(a->src_dentry); |
23471 | + a->dst_btop = au_dbtop(a->dst_dentry); | |
f2c43d5f AM |
23472 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) |
23473 | + || au_ftest_ren(a->auren_flags, ISDIR_DST)) | |
4a4d8108 | 23474 | + au_fset_wrdir(wr_dir_args.flags, ISDIR); |
5afbbe0d AM |
23475 | + wr_dir_args.force_btgt = a->src_btop; |
23476 | + if (a->dst_inode && a->dst_btop < a->src_btop) | |
23477 | + wr_dir_args.force_btgt = a->dst_btop; | |
4a4d8108 AM |
23478 | + wr_dir_args.force_btgt = au_wbr(a->dst_dentry, wr_dir_args.force_btgt); |
23479 | + err = au_wr_dir(a->dst_dentry, a->src_dentry, &wr_dir_args); | |
23480 | + a->btgt = err; | |
f2c43d5f AM |
23481 | + if (a->exchange) |
23482 | + au_update_dbtop(a->dst_dentry); | |
dece6358 | 23483 | + |
4a4d8108 | 23484 | + return err; |
1facf9fc | 23485 | +} |
23486 | + | |
4a4d8108 | 23487 | +static void au_ren_dt(struct au_ren_args *a) |
1facf9fc | 23488 | +{ |
4a4d8108 AM |
23489 | + a->h_path.dentry = a->src_h_parent; |
23490 | + au_dtime_store(a->src_dt + AuPARENT, a->src_parent, &a->h_path); | |
f2c43d5f | 23491 | + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) { |
4a4d8108 AM |
23492 | + a->h_path.dentry = a->dst_h_parent; |
23493 | + au_dtime_store(a->dst_dt + AuPARENT, a->dst_parent, &a->h_path); | |
23494 | + } | |
1facf9fc | 23495 | + |
f2c43d5f AM |
23496 | + au_fclr_ren(a->auren_flags, DT_DSTDIR); |
23497 | + if (!au_ftest_ren(a->auren_flags, ISDIR_SRC) | |
23498 | + && !a->exchange) | |
4a4d8108 | 23499 | + return; |
dece6358 | 23500 | + |
4a4d8108 AM |
23501 | + a->h_path.dentry = a->src_h_dentry; |
23502 | + au_dtime_store(a->src_dt + AuCHILD, a->src_dentry, &a->h_path); | |
5527c038 | 23503 | + if (d_is_positive(a->dst_h_dentry)) { |
f2c43d5f | 23504 | + au_fset_ren(a->auren_flags, DT_DSTDIR); |
4a4d8108 AM |
23505 | + a->h_path.dentry = a->dst_h_dentry; |
23506 | + au_dtime_store(a->dst_dt + AuCHILD, a->dst_dentry, &a->h_path); | |
23507 | + } | |
1308ab2a | 23508 | +} |
dece6358 | 23509 | + |
4a4d8108 | 23510 | +static void au_ren_rev_dt(int err, struct au_ren_args *a) |
1308ab2a | 23511 | +{ |
4a4d8108 | 23512 | + struct dentry *h_d; |
febd17d6 | 23513 | + struct inode *h_inode; |
4a4d8108 AM |
23514 | + |
23515 | + au_dtime_revert(a->src_dt + AuPARENT); | |
f2c43d5f | 23516 | + if (!au_ftest_ren(a->auren_flags, ISSAMEDIR)) |
4a4d8108 AM |
23517 | + au_dtime_revert(a->dst_dt + AuPARENT); |
23518 | + | |
f2c43d5f | 23519 | + if (au_ftest_ren(a->auren_flags, ISDIR_SRC) && err != -EIO) { |
4a4d8108 | 23520 | + h_d = a->src_dt[AuCHILD].dt_h_path.dentry; |
febd17d6 JR |
23521 | + h_inode = d_inode(h_d); |
23522 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); | |
4a4d8108 | 23523 | + au_dtime_revert(a->src_dt + AuCHILD); |
febd17d6 | 23524 | + inode_unlock(h_inode); |
4a4d8108 | 23525 | + |
f2c43d5f | 23526 | + if (au_ftest_ren(a->auren_flags, DT_DSTDIR)) { |
4a4d8108 | 23527 | + h_d = a->dst_dt[AuCHILD].dt_h_path.dentry; |
febd17d6 JR |
23528 | + h_inode = d_inode(h_d); |
23529 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); | |
4a4d8108 | 23530 | + au_dtime_revert(a->dst_dt + AuCHILD); |
febd17d6 | 23531 | + inode_unlock(h_inode); |
1facf9fc | 23532 | + } |
23533 | + } | |
23534 | +} | |
23535 | + | |
4a4d8108 AM |
23536 | +/* ---------------------------------------------------------------------- */ |
23537 | + | |
23538 | +int aufs_rename(struct inode *_src_dir, struct dentry *_src_dentry, | |
f2c43d5f AM |
23539 | + struct inode *_dst_dir, struct dentry *_dst_dentry, |
23540 | + unsigned int _flags) | |
1facf9fc | 23541 | +{ |
f2c43d5f | 23542 | + int err, lock_flags; |
8b6a4947 | 23543 | + void *rev; |
4a4d8108 AM |
23544 | + /* reduce stack space */ |
23545 | + struct au_ren_args *a; | |
f2c43d5f | 23546 | + struct au_pin pin; |
4a4d8108 | 23547 | + |
f2c43d5f | 23548 | + AuDbg("%pd, %pd, 0x%x\n", _src_dentry, _dst_dentry, _flags); |
4a4d8108 AM |
23549 | + IMustLock(_src_dir); |
23550 | + IMustLock(_dst_dir); | |
23551 | + | |
f2c43d5f AM |
23552 | + err = -EINVAL; |
23553 | + if (unlikely(_flags & RENAME_WHITEOUT)) | |
23554 | + goto out; | |
23555 | + | |
4a4d8108 AM |
23556 | + err = -ENOMEM; |
23557 | + BUILD_BUG_ON(sizeof(*a) > PAGE_SIZE); | |
23558 | + a = kzalloc(sizeof(*a), GFP_NOFS); | |
23559 | + if (unlikely(!a)) | |
23560 | + goto out; | |
23561 | + | |
f2c43d5f | 23562 | + a->flags = _flags; |
acd2b654 AM |
23563 | + BUILD_BUG_ON(sizeof(a->exchange) == sizeof(u8) |
23564 | + && RENAME_EXCHANGE > U8_MAX); | |
f2c43d5f | 23565 | + a->exchange = _flags & RENAME_EXCHANGE; |
4a4d8108 AM |
23566 | + a->src_dir = _src_dir; |
23567 | + a->src_dentry = _src_dentry; | |
5527c038 JR |
23568 | + a->src_inode = NULL; |
23569 | + if (d_really_is_positive(a->src_dentry)) | |
23570 | + a->src_inode = d_inode(a->src_dentry); | |
4a4d8108 AM |
23571 | + a->src_parent = a->src_dentry->d_parent; /* dir inode is locked */ |
23572 | + a->dst_dir = _dst_dir; | |
23573 | + a->dst_dentry = _dst_dentry; | |
5527c038 JR |
23574 | + a->dst_inode = NULL; |
23575 | + if (d_really_is_positive(a->dst_dentry)) | |
23576 | + a->dst_inode = d_inode(a->dst_dentry); | |
4a4d8108 AM |
23577 | + a->dst_parent = a->dst_dentry->d_parent; /* dir inode is locked */ |
23578 | + if (a->dst_inode) { | |
f2c43d5f AM |
23579 | + /* |
23580 | + * if EXCHANGE && src is non-dir && dst is dir, | |
23581 | + * dst is not locked. | |
23582 | + */ | |
23583 | + /* IMustLock(a->dst_inode); */ | |
4a4d8108 | 23584 | + au_igrab(a->dst_inode); |
1facf9fc | 23585 | + } |
1facf9fc | 23586 | + |
4a4d8108 | 23587 | + err = -ENOTDIR; |
f2c43d5f | 23588 | + lock_flags = AuLock_FLUSH | AuLock_NOPLM | AuLock_GEN; |
2000de60 | 23589 | + if (d_is_dir(a->src_dentry)) { |
f2c43d5f AM |
23590 | + au_fset_ren(a->auren_flags, ISDIR_SRC); |
23591 | + if (unlikely(!a->exchange | |
23592 | + && d_really_is_positive(a->dst_dentry) | |
2000de60 | 23593 | + && !d_is_dir(a->dst_dentry))) |
4a4d8108 | 23594 | + goto out_free; |
f2c43d5f AM |
23595 | + lock_flags |= AuLock_DIRS; |
23596 | + } | |
23597 | + if (a->dst_inode && d_is_dir(a->dst_dentry)) { | |
23598 | + au_fset_ren(a->auren_flags, ISDIR_DST); | |
23599 | + if (unlikely(!a->exchange | |
23600 | + && d_really_is_positive(a->src_dentry) | |
23601 | + && !d_is_dir(a->src_dentry))) | |
23602 | + goto out_free; | |
23603 | + lock_flags |= AuLock_DIRS; | |
b95c5147 | 23604 | + } |
8b6a4947 AM |
23605 | + err = aufs_read_and_write_lock2(a->dst_dentry, a->src_dentry, |
23606 | + lock_flags); | |
e49829fe JR |
23607 | + if (unlikely(err)) |
23608 | + goto out_free; | |
1facf9fc | 23609 | + |
027c5e7a AM |
23610 | + err = au_d_hashed_positive(a->src_dentry); |
23611 | + if (unlikely(err)) | |
23612 | + goto out_unlock; | |
23613 | + err = -ENOENT; | |
23614 | + if (a->dst_inode) { | |
23615 | + /* | |
f2c43d5f | 23616 | + * If it is a dir, VFS unhash it before this |
027c5e7a AM |
23617 | + * function. It means we cannot rely upon d_unhashed(). |
23618 | + */ | |
23619 | + if (unlikely(!a->dst_inode->i_nlink)) | |
23620 | + goto out_unlock; | |
f2c43d5f | 23621 | + if (!au_ftest_ren(a->auren_flags, ISDIR_DST)) { |
027c5e7a | 23622 | + err = au_d_hashed_positive(a->dst_dentry); |
f2c43d5f | 23623 | + if (unlikely(err && !a->exchange)) |
027c5e7a AM |
23624 | + goto out_unlock; |
23625 | + } else if (unlikely(IS_DEADDIR(a->dst_inode))) | |
23626 | + goto out_unlock; | |
23627 | + } else if (unlikely(d_unhashed(a->dst_dentry))) | |
23628 | + goto out_unlock; | |
23629 | + | |
7eafdf33 AM |
23630 | + /* |
23631 | + * is it possible? | |
79b8bda9 | 23632 | + * yes, it happened (in linux-3.3-rcN) but I don't know why. |
7eafdf33 AM |
23633 | + * there may exist a problem somewhere else. |
23634 | + */ | |
23635 | + err = -EINVAL; | |
5527c038 | 23636 | + if (unlikely(d_inode(a->dst_parent) == d_inode(a->src_dentry))) |
7eafdf33 AM |
23637 | + goto out_unlock; |
23638 | + | |
f2c43d5f | 23639 | + au_fset_ren(a->auren_flags, ISSAMEDIR); /* temporary */ |
4a4d8108 | 23640 | + di_write_lock_parent(a->dst_parent); |
1facf9fc | 23641 | + |
4a4d8108 AM |
23642 | + /* which branch we process */ |
23643 | + err = au_ren_wbr(a); | |
23644 | + if (unlikely(err < 0)) | |
027c5e7a | 23645 | + goto out_parent; |
4a4d8108 | 23646 | + a->br = au_sbr(a->dst_dentry->d_sb, a->btgt); |
86dc4139 | 23647 | + a->h_path.mnt = au_br_mnt(a->br); |
1facf9fc | 23648 | + |
4a4d8108 AM |
23649 | + /* are they available to be renamed */ |
23650 | + err = au_ren_may_dir(a); | |
23651 | + if (unlikely(err)) | |
23652 | + goto out_children; | |
1facf9fc | 23653 | + |
4a4d8108 | 23654 | + /* prepare the writable parent dir on the same branch */ |
5afbbe0d | 23655 | + if (a->dst_btop == a->btgt) { |
f2c43d5f | 23656 | + au_fset_ren(a->auren_flags, WHDST); |
4a4d8108 AM |
23657 | + } else { |
23658 | + err = au_cpup_dirs(a->dst_dentry, a->btgt); | |
23659 | + if (unlikely(err)) | |
23660 | + goto out_children; | |
23661 | + } | |
1facf9fc | 23662 | + |
f2c43d5f AM |
23663 | + err = 0; |
23664 | + if (!a->exchange) { | |
23665 | + if (a->src_dir != a->dst_dir) { | |
23666 | + /* | |
23667 | + * this temporary unlock is safe, | |
23668 | + * because both dir->i_mutex are locked. | |
23669 | + */ | |
23670 | + di_write_unlock(a->dst_parent); | |
23671 | + di_write_lock_parent(a->src_parent); | |
23672 | + err = au_wr_dir_need_wh(a->src_dentry, | |
23673 | + au_ftest_ren(a->auren_flags, | |
23674 | + ISDIR_SRC), | |
23675 | + &a->btgt); | |
23676 | + di_write_unlock(a->src_parent); | |
23677 | + di_write_lock2_parent(a->src_parent, a->dst_parent, | |
23678 | + /*isdir*/1); | |
23679 | + au_fclr_ren(a->auren_flags, ISSAMEDIR); | |
23680 | + } else | |
23681 | + err = au_wr_dir_need_wh(a->src_dentry, | |
23682 | + au_ftest_ren(a->auren_flags, | |
23683 | + ISDIR_SRC), | |
23684 | + &a->btgt); | |
23685 | + } | |
4a4d8108 AM |
23686 | + if (unlikely(err < 0)) |
23687 | + goto out_children; | |
23688 | + if (err) | |
f2c43d5f | 23689 | + au_fset_ren(a->auren_flags, WHSRC); |
1facf9fc | 23690 | + |
86dc4139 | 23691 | + /* cpup src */ |
5afbbe0d | 23692 | + if (a->src_btop != a->btgt) { |
86dc4139 AM |
23693 | + err = au_pin(&pin, a->src_dentry, a->btgt, |
23694 | + au_opt_udba(a->src_dentry->d_sb), | |
23695 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
367653fa | 23696 | + if (!err) { |
c2b27bf2 AM |
23697 | + struct au_cp_generic cpg = { |
23698 | + .dentry = a->src_dentry, | |
23699 | + .bdst = a->btgt, | |
5afbbe0d | 23700 | + .bsrc = a->src_btop, |
c2b27bf2 AM |
23701 | + .len = -1, |
23702 | + .pin = &pin, | |
23703 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
23704 | + }; | |
5afbbe0d | 23705 | + AuDebugOn(au_dbtop(a->src_dentry) != a->src_btop); |
c2b27bf2 | 23706 | + err = au_sio_cpup_simple(&cpg); |
367653fa | 23707 | + au_unpin(&pin); |
86dc4139 | 23708 | + } |
86dc4139 AM |
23709 | + if (unlikely(err)) |
23710 | + goto out_children; | |
5afbbe0d | 23711 | + a->src_btop = a->btgt; |
86dc4139 | 23712 | + a->src_h_dentry = au_h_dptr(a->src_dentry, a->btgt); |
f2c43d5f AM |
23713 | + if (!a->exchange) |
23714 | + au_fset_ren(a->auren_flags, WHSRC); | |
23715 | + } | |
23716 | + | |
23717 | + /* cpup dst */ | |
23718 | + if (a->exchange && a->dst_inode | |
23719 | + && a->dst_btop != a->btgt) { | |
23720 | + err = au_pin(&pin, a->dst_dentry, a->btgt, | |
23721 | + au_opt_udba(a->dst_dentry->d_sb), | |
23722 | + AuPin_DI_LOCKED | AuPin_MNT_WRITE); | |
23723 | + if (!err) { | |
23724 | + struct au_cp_generic cpg = { | |
23725 | + .dentry = a->dst_dentry, | |
23726 | + .bdst = a->btgt, | |
23727 | + .bsrc = a->dst_btop, | |
23728 | + .len = -1, | |
23729 | + .pin = &pin, | |
23730 | + .flags = AuCpup_DTIME | AuCpup_HOPEN | |
23731 | + }; | |
23732 | + err = au_sio_cpup_simple(&cpg); | |
23733 | + au_unpin(&pin); | |
23734 | + } | |
23735 | + if (unlikely(err)) | |
23736 | + goto out_children; | |
23737 | + a->dst_btop = a->btgt; | |
23738 | + a->dst_h_dentry = au_h_dptr(a->dst_dentry, a->btgt); | |
86dc4139 AM |
23739 | + } |
23740 | + | |
4a4d8108 AM |
23741 | + /* lock them all */ |
23742 | + err = au_ren_lock(a); | |
23743 | + if (unlikely(err)) | |
86dc4139 | 23744 | + /* leave the copied-up one */ |
4a4d8108 | 23745 | + goto out_children; |
1facf9fc | 23746 | + |
f2c43d5f AM |
23747 | + if (!a->exchange) { |
23748 | + if (!au_opt_test(au_mntflags(a->dst_dir->i_sb), UDBA_NONE)) | |
23749 | + err = au_may_ren(a); | |
23750 | + else if (unlikely(a->dst_dentry->d_name.len > AUFS_MAX_NAMELEN)) | |
23751 | + err = -ENAMETOOLONG; | |
23752 | + if (unlikely(err)) | |
23753 | + goto out_hdir; | |
23754 | + } | |
1facf9fc | 23755 | + |
4a4d8108 AM |
23756 | + /* store timestamps to be revertible */ |
23757 | + au_ren_dt(a); | |
1facf9fc | 23758 | + |
8b6a4947 AM |
23759 | + /* store dirren info */ |
23760 | + if (au_ftest_ren(a->auren_flags, DIRREN)) { | |
23761 | + err = au_dr_rename(a->src_dentry, a->btgt, | |
23762 | + &a->dst_dentry->d_name, &rev); | |
23763 | + AuTraceErr(err); | |
23764 | + if (unlikely(err)) | |
23765 | + goto out_dt; | |
23766 | + } | |
23767 | + | |
4a4d8108 AM |
23768 | + /* here we go */ |
23769 | + err = do_rename(a); | |
23770 | + if (unlikely(err)) | |
8b6a4947 AM |
23771 | + goto out_dirren; |
23772 | + | |
23773 | + if (au_ftest_ren(a->auren_flags, DIRREN)) | |
23774 | + au_dr_rename_fin(a->src_dentry, a->btgt, rev); | |
4a4d8108 AM |
23775 | + |
23776 | + /* update dir attributes */ | |
23777 | + au_ren_refresh_dir(a); | |
23778 | + | |
23779 | + /* dput/iput all lower dentries */ | |
23780 | + au_ren_refresh(a); | |
23781 | + | |
23782 | + goto out_hdir; /* success */ | |
23783 | + | |
8b6a4947 AM |
23784 | +out_dirren: |
23785 | + if (au_ftest_ren(a->auren_flags, DIRREN)) | |
23786 | + au_dr_rename_rev(a->src_dentry, a->btgt, rev); | |
4f0767ce | 23787 | +out_dt: |
4a4d8108 | 23788 | + au_ren_rev_dt(err, a); |
4f0767ce | 23789 | +out_hdir: |
4a4d8108 | 23790 | + au_ren_unlock(a); |
4f0767ce | 23791 | +out_children: |
4a4d8108 | 23792 | + au_nhash_wh_free(&a->whlist); |
5afbbe0d AM |
23793 | + if (err && a->dst_inode && a->dst_btop != a->btgt) { |
23794 | + AuDbg("btop %d, btgt %d\n", a->dst_btop, a->btgt); | |
027c5e7a | 23795 | + au_set_h_dptr(a->dst_dentry, a->btgt, NULL); |
5afbbe0d | 23796 | + au_set_dbtop(a->dst_dentry, a->dst_btop); |
4a4d8108 | 23797 | + } |
027c5e7a | 23798 | +out_parent: |
f2c43d5f | 23799 | + if (!err) { |
8b6a4947 AM |
23800 | + if (d_unhashed(a->src_dentry)) |
23801 | + au_fset_ren(a->auren_flags, DROPPED_SRC); | |
23802 | + if (d_unhashed(a->dst_dentry)) | |
23803 | + au_fset_ren(a->auren_flags, DROPPED_DST); | |
f2c43d5f AM |
23804 | + if (!a->exchange) |
23805 | + d_move(a->src_dentry, a->dst_dentry); | |
8b6a4947 | 23806 | + else { |
f2c43d5f | 23807 | + d_exchange(a->src_dentry, a->dst_dentry); |
8b6a4947 AM |
23808 | + if (au_ftest_ren(a->auren_flags, DROPPED_DST)) |
23809 | + d_drop(a->dst_dentry); | |
23810 | + } | |
23811 | + if (au_ftest_ren(a->auren_flags, DROPPED_SRC)) | |
23812 | + d_drop(a->src_dentry); | |
f2c43d5f | 23813 | + } else { |
5afbbe0d | 23814 | + au_update_dbtop(a->dst_dentry); |
027c5e7a AM |
23815 | + if (!a->dst_inode) |
23816 | + d_drop(a->dst_dentry); | |
23817 | + } | |
f2c43d5f | 23818 | + if (au_ftest_ren(a->auren_flags, ISSAMEDIR)) |
4a4d8108 AM |
23819 | + di_write_unlock(a->dst_parent); |
23820 | + else | |
23821 | + di_write_unlock2(a->src_parent, a->dst_parent); | |
027c5e7a | 23822 | +out_unlock: |
4a4d8108 | 23823 | + aufs_read_and_write_unlock2(a->dst_dentry, a->src_dentry); |
4f0767ce | 23824 | +out_free: |
4a4d8108 AM |
23825 | + iput(a->dst_inode); |
23826 | + if (a->thargs) | |
23827 | + au_whtmp_rmdir_free(a->thargs); | |
9f237c51 | 23828 | + au_kfree_rcu(a); |
4f0767ce | 23829 | +out: |
4a4d8108 AM |
23830 | + AuTraceErr(err); |
23831 | + return err; | |
1308ab2a | 23832 | +} |
7f207e10 | 23833 | diff -urN /usr/share/empty/fs/aufs/Kconfig linux/fs/aufs/Kconfig |
eca34b5c AM |
23834 | --- /usr/share/empty/fs/aufs/Kconfig 1970-01-01 01:00:00.000000000 +0100 |
23835 | +++ linux/fs/aufs/Kconfig 2019-07-11 15:42:14.458904362 +0200 | |
2121bcd9 AM |
23836 | @@ -0,0 +1,199 @@ |
23837 | +# SPDX-License-Identifier: GPL-2.0 | |
4a4d8108 AM |
23838 | +config AUFS_FS |
23839 | + tristate "Aufs (Advanced multi layered unification filesystem) support" | |
4a4d8108 AM |
23840 | + help |
23841 | + Aufs is a stackable unification filesystem such as Unionfs, | |
23842 | + which unifies several directories and provides a merged single | |
23843 | + directory. | |
23844 | + In the early days, aufs was entirely re-designed and | |
23845 | + re-implemented Unionfs Version 1.x series. Introducing many | |
23846 | + original ideas, approaches and improvements, it becomes totally | |
23847 | + different from Unionfs while keeping the basic features. | |
1facf9fc | 23848 | + |
4a4d8108 AM |
23849 | +if AUFS_FS |
23850 | +choice | |
23851 | + prompt "Maximum number of branches" | |
23852 | + default AUFS_BRANCH_MAX_127 | |
23853 | + help | |
23854 | + Specifies the maximum number of branches (or member directories) | |
23855 | + in a single aufs. The larger value consumes more system | |
23856 | + resources and has a minor impact to performance. | |
23857 | +config AUFS_BRANCH_MAX_127 | |
23858 | + bool "127" | |
23859 | + help | |
23860 | + Specifies the maximum number of branches (or member directories) | |
23861 | + in a single aufs. The larger value consumes more system | |
23862 | + resources and has a minor impact to performance. | |
23863 | +config AUFS_BRANCH_MAX_511 | |
23864 | + bool "511" | |
23865 | + help | |
23866 | + Specifies the maximum number of branches (or member directories) | |
23867 | + in a single aufs. The larger value consumes more system | |
23868 | + resources and has a minor impact to performance. | |
23869 | +config AUFS_BRANCH_MAX_1023 | |
23870 | + bool "1023" | |
23871 | + help | |
23872 | + Specifies the maximum number of branches (or member directories) | |
23873 | + in a single aufs. The larger value consumes more system | |
23874 | + resources and has a minor impact to performance. | |
23875 | +config AUFS_BRANCH_MAX_32767 | |
23876 | + bool "32767" | |
23877 | + help | |
23878 | + Specifies the maximum number of branches (or member directories) | |
23879 | + in a single aufs. The larger value consumes more system | |
23880 | + resources and has a minor impact to performance. | |
23881 | +endchoice | |
1facf9fc | 23882 | + |
e49829fe JR |
23883 | +config AUFS_SBILIST |
23884 | + bool | |
23885 | + depends on AUFS_MAGIC_SYSRQ || PROC_FS | |
23886 | + default y | |
23887 | + help | |
23888 | + Automatic configuration for internal use. | |
23889 | + When aufs supports Magic SysRq or /proc, enabled automatically. | |
23890 | + | |
4a4d8108 AM |
23891 | +config AUFS_HNOTIFY |
23892 | + bool "Detect direct branch access (bypassing aufs)" | |
23893 | + help | |
23894 | + If you want to modify files on branches directly, eg. bypassing aufs, | |
23895 | + and want aufs to detect the changes of them fully, then enable this | |
23896 | + option and use 'udba=notify' mount option. | |
7f207e10 | 23897 | + Currently there is only one available configuration, "fsnotify". |
4a4d8108 AM |
23898 | + It will have a negative impact to the performance. |
23899 | + See detail in aufs.5. | |
dece6358 | 23900 | + |
4a4d8108 AM |
23901 | +choice |
23902 | + prompt "method" if AUFS_HNOTIFY | |
23903 | + default AUFS_HFSNOTIFY | |
23904 | +config AUFS_HFSNOTIFY | |
23905 | + bool "fsnotify" | |
23906 | + select FSNOTIFY | |
4a4d8108 | 23907 | +endchoice |
1facf9fc | 23908 | + |
4a4d8108 AM |
23909 | +config AUFS_EXPORT |
23910 | + bool "NFS-exportable aufs" | |
2cbb1c4b | 23911 | + depends on EXPORTFS |
4a4d8108 AM |
23912 | + help |
23913 | + If you want to export your mounted aufs via NFS, then enable this | |
23914 | + option. There are several requirements for this configuration. | |
23915 | + See detail in aufs.5. | |
1facf9fc | 23916 | + |
4a4d8108 AM |
23917 | +config AUFS_INO_T_64 |
23918 | + bool | |
23919 | + depends on AUFS_EXPORT | |
23920 | + depends on 64BIT && !(ALPHA || S390) | |
23921 | + default y | |
23922 | + help | |
23923 | + Automatic configuration for internal use. | |
23924 | + /* typedef unsigned long/int __kernel_ino_t */ | |
23925 | + /* alpha and s390x are int */ | |
1facf9fc | 23926 | + |
c1595e42 JR |
23927 | +config AUFS_XATTR |
23928 | + bool "support for XATTR/EA (including Security Labels)" | |
23929 | + help | |
23930 | + If your branch fs supports XATTR/EA and you want to make them | |
23931 | + available in aufs too, then enable this opsion and specify the | |
23932 | + branch attributes for EA. | |
23933 | + See detail in aufs.5. | |
23934 | + | |
076b876e AM |
23935 | +config AUFS_FHSM |
23936 | + bool "File-based Hierarchical Storage Management" | |
23937 | + help | |
23938 | + Hierarchical Storage Management (or HSM) is a well-known feature | |
23939 | + in the storage world. Aufs provides this feature as file-based. | |
23940 | + with multiple branches. | |
23941 | + These multiple branches are prioritized, ie. the topmost one | |
23942 | + should be the fastest drive and be used heavily. | |
23943 | + | |
4a4d8108 AM |
23944 | +config AUFS_RDU |
23945 | + bool "Readdir in userspace" | |
23946 | + help | |
23947 | + Aufs has two methods to provide a merged view for a directory, | |
23948 | + by a user-space library and by kernel-space natively. The latter | |
23949 | + is always enabled but sometimes large and slow. | |
23950 | + If you enable this option, install the library in aufs2-util | |
23951 | + package, and set some environment variables for your readdir(3), | |
23952 | + then the work will be handled in user-space which generally | |
23953 | + shows better performance in most cases. | |
23954 | + See detail in aufs.5. | |
1facf9fc | 23955 | + |
8b6a4947 AM |
23956 | +config AUFS_DIRREN |
23957 | + bool "Workaround for rename(2)-ing a directory" | |
23958 | + help | |
23959 | + By default, aufs returns EXDEV error in renameing a dir who has | |
23960 | + his child on the lower branch, since it is a bad idea to issue | |
23961 | + rename(2) internally for every lower branch. But user may not | |
23962 | + accept this behaviour. So here is a workaround to allow such | |
23963 | + rename(2) and store some extra infromation on the writable | |
23964 | + branch. Obviously this costs high (and I don't like it). | |
23965 | + To use this feature, you need to enable this configuration AND | |
23966 | + to specify the mount option `dirren.' | |
23967 | + See details in aufs.5 and the design documents. | |
23968 | + | |
4a4d8108 AM |
23969 | +config AUFS_SHWH |
23970 | + bool "Show whiteouts" | |
23971 | + help | |
23972 | + If you want to make the whiteouts in aufs visible, then enable | |
23973 | + this option and specify 'shwh' mount option. Although it may | |
23974 | + sounds like philosophy or something, but in technically it | |
23975 | + simply shows the name of whiteout with keeping its behaviour. | |
1facf9fc | 23976 | + |
4a4d8108 AM |
23977 | +config AUFS_BR_RAMFS |
23978 | + bool "Ramfs (initramfs/rootfs) as an aufs branch" | |
23979 | + help | |
23980 | + If you want to use ramfs as an aufs branch fs, then enable this | |
23981 | + option. Generally tmpfs is recommended. | |
23982 | + Aufs prohibited them to be a branch fs by default, because | |
23983 | + initramfs becomes unusable after switch_root or something | |
23984 | + generally. If you sets initramfs as an aufs branch and boot your | |
23985 | + system by switch_root, you will meet a problem easily since the | |
23986 | + files in initramfs may be inaccessible. | |
23987 | + Unless you are going to use ramfs as an aufs branch fs without | |
23988 | + switch_root or something, leave it N. | |
1facf9fc | 23989 | + |
4a4d8108 AM |
23990 | +config AUFS_BR_FUSE |
23991 | + bool "Fuse fs as an aufs branch" | |
23992 | + depends on FUSE_FS | |
23993 | + select AUFS_POLL | |
23994 | + help | |
23995 | + If you want to use fuse-based userspace filesystem as an aufs | |
23996 | + branch fs, then enable this option. | |
23997 | + It implements the internal poll(2) operation which is | |
23998 | + implemented by fuse only (curretnly). | |
1facf9fc | 23999 | + |
4a4d8108 AM |
24000 | +config AUFS_POLL |
24001 | + bool | |
24002 | + help | |
24003 | + Automatic configuration for internal use. | |
1facf9fc | 24004 | + |
4a4d8108 AM |
24005 | +config AUFS_BR_HFSPLUS |
24006 | + bool "Hfsplus as an aufs branch" | |
24007 | + depends on HFSPLUS_FS | |
24008 | + default y | |
24009 | + help | |
24010 | + If you want to use hfsplus fs as an aufs branch fs, then enable | |
24011 | + this option. This option introduces a small overhead at | |
24012 | + copying-up a file on hfsplus. | |
1facf9fc | 24013 | + |
4a4d8108 AM |
24014 | +config AUFS_BDEV_LOOP |
24015 | + bool | |
24016 | + depends on BLK_DEV_LOOP | |
24017 | + default y | |
24018 | + help | |
24019 | + Automatic configuration for internal use. | |
24020 | + Convert =[ym] into =y. | |
1308ab2a | 24021 | + |
4a4d8108 AM |
24022 | +config AUFS_DEBUG |
24023 | + bool "Debug aufs" | |
24024 | + help | |
24025 | + Enable this to compile aufs internal debug code. | |
24026 | + It will have a negative impact to the performance. | |
24027 | + | |
24028 | +config AUFS_MAGIC_SYSRQ | |
24029 | + bool | |
24030 | + depends on AUFS_DEBUG && MAGIC_SYSRQ | |
24031 | + default y | |
24032 | + help | |
24033 | + Automatic configuration for internal use. | |
24034 | + When aufs supports Magic SysRq, enabled automatically. | |
24035 | +endif | |
acd2b654 | 24036 | diff -urN /usr/share/empty/fs/aufs/lcnt.h linux/fs/aufs/lcnt.h |
eca34b5c | 24037 | --- /usr/share/empty/fs/aufs/lcnt.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 24038 | +++ linux/fs/aufs/lcnt.h 2020-01-27 10:57:18.175538316 +0100 |
acd2b654 AM |
24039 | @@ -0,0 +1,186 @@ |
24040 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
24041 | +/* | |
d58c55f2 | 24042 | + * Copyright (C) 2018-2020 Junjiro R. Okajima |
acd2b654 AM |
24043 | + * |
24044 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24045 | + * it under the terms of the GNU General Public License as published by | |
24046 | + * the Free Software Foundation; either version 2 of the License, or | |
24047 | + * (at your option) any later version. | |
24048 | + * | |
24049 | + * This program is distributed in the hope that it will be useful, | |
24050 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24051 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24052 | + * GNU General Public License for more details. | |
24053 | + * | |
24054 | + * You should have received a copy of the GNU General Public License | |
24055 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
24056 | + */ | |
24057 | + | |
24058 | +/* | |
24059 | + * simple long counter wrapper | |
24060 | + */ | |
24061 | + | |
24062 | +#ifndef __AUFS_LCNT_H__ | |
24063 | +#define __AUFS_LCNT_H__ | |
24064 | + | |
24065 | +#ifdef __KERNEL__ | |
24066 | + | |
24067 | +#include "debug.h" | |
24068 | + | |
24069 | +#define AuLCntATOMIC 1 | |
24070 | +#define AuLCntPCPUCNT 2 | |
24071 | +/* | |
24072 | + * why does percpu_refcount require extra synchronize_rcu()s in | |
24073 | + * au_br_do_free() | |
24074 | + */ | |
24075 | +#define AuLCntPCPUREF 3 | |
24076 | + | |
24077 | +/* #define AuLCntChosen AuLCntATOMIC */ | |
24078 | +#define AuLCntChosen AuLCntPCPUCNT | |
24079 | +/* #define AuLCntChosen AuLCntPCPUREF */ | |
24080 | + | |
24081 | +#if AuLCntChosen == AuLCntATOMIC | |
24082 | +#include <linux/atomic.h> | |
24083 | + | |
24084 | +typedef atomic_long_t au_lcnt_t; | |
24085 | + | |
24086 | +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused) | |
24087 | +{ | |
24088 | + atomic_long_set(cnt, 0); | |
24089 | + return 0; | |
24090 | +} | |
24091 | + | |
24092 | +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused) | |
24093 | +{ | |
24094 | + /* empty */ | |
24095 | +} | |
24096 | + | |
24097 | +static inline void au_lcnt_fin(au_lcnt_t *cnt __maybe_unused, | |
24098 | + int do_sync __maybe_unused) | |
24099 | +{ | |
24100 | + /* empty */ | |
24101 | +} | |
24102 | + | |
24103 | +static inline void au_lcnt_inc(au_lcnt_t *cnt) | |
24104 | +{ | |
24105 | + atomic_long_inc(cnt); | |
24106 | +} | |
24107 | + | |
24108 | +static inline void au_lcnt_dec(au_lcnt_t *cnt) | |
24109 | +{ | |
24110 | + atomic_long_dec(cnt); | |
24111 | +} | |
24112 | + | |
24113 | +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused) | |
24114 | +{ | |
24115 | + return atomic_long_read(cnt); | |
24116 | +} | |
24117 | +#endif | |
24118 | + | |
24119 | +#if AuLCntChosen == AuLCntPCPUCNT | |
24120 | +#include <linux/percpu_counter.h> | |
24121 | + | |
24122 | +typedef struct percpu_counter au_lcnt_t; | |
24123 | + | |
24124 | +static inline int au_lcnt_init(au_lcnt_t *cnt, void *release __maybe_unused) | |
24125 | +{ | |
24126 | + return percpu_counter_init(cnt, 0, GFP_NOFS); | |
24127 | +} | |
24128 | + | |
24129 | +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused) | |
24130 | +{ | |
24131 | + /* empty */ | |
24132 | +} | |
24133 | + | |
24134 | +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync __maybe_unused) | |
24135 | +{ | |
24136 | + percpu_counter_destroy(cnt); | |
24137 | +} | |
24138 | + | |
24139 | +static inline void au_lcnt_inc(au_lcnt_t *cnt) | |
24140 | +{ | |
24141 | + percpu_counter_inc(cnt); | |
24142 | +} | |
24143 | + | |
24144 | +static inline void au_lcnt_dec(au_lcnt_t *cnt) | |
24145 | +{ | |
24146 | + percpu_counter_dec(cnt); | |
24147 | +} | |
24148 | + | |
24149 | +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev __maybe_unused) | |
24150 | +{ | |
24151 | + s64 n; | |
24152 | + | |
24153 | + n = percpu_counter_sum(cnt); | |
24154 | + BUG_ON(n < 0); | |
24155 | + if (LONG_MAX != LLONG_MAX | |
24156 | + && n > LONG_MAX) | |
24157 | + AuWarn1("%s\n", "wrap-around"); | |
24158 | + | |
24159 | + return n; | |
24160 | +} | |
24161 | +#endif | |
24162 | + | |
24163 | +#if AuLCntChosen == AuLCntPCPUREF | |
24164 | +#include <linux/percpu-refcount.h> | |
24165 | + | |
24166 | +typedef struct percpu_ref au_lcnt_t; | |
24167 | + | |
24168 | +static inline int au_lcnt_init(au_lcnt_t *cnt, percpu_ref_func_t *release) | |
24169 | +{ | |
24170 | + if (!release) | |
24171 | + release = percpu_ref_exit; | |
24172 | + return percpu_ref_init(cnt, release, /*percpu mode*/0, GFP_NOFS); | |
24173 | +} | |
24174 | + | |
24175 | +static inline void au_lcnt_wait_for_fin(au_lcnt_t *cnt __maybe_unused) | |
24176 | +{ | |
24177 | + synchronize_rcu(); | |
24178 | +} | |
24179 | + | |
24180 | +static inline void au_lcnt_fin(au_lcnt_t *cnt, int do_sync) | |
24181 | +{ | |
24182 | + percpu_ref_kill(cnt); | |
24183 | + if (do_sync) | |
24184 | + au_lcnt_wait_for_fin(cnt); | |
24185 | +} | |
24186 | + | |
24187 | +static inline void au_lcnt_inc(au_lcnt_t *cnt) | |
24188 | +{ | |
24189 | + percpu_ref_get(cnt); | |
24190 | +} | |
24191 | + | |
24192 | +static inline void au_lcnt_dec(au_lcnt_t *cnt) | |
24193 | +{ | |
24194 | + percpu_ref_put(cnt); | |
24195 | +} | |
24196 | + | |
24197 | +/* | |
24198 | + * avoid calling this func as possible. | |
24199 | + */ | |
24200 | +static inline long au_lcnt_read(au_lcnt_t *cnt, int do_rev) | |
24201 | +{ | |
24202 | + long l; | |
24203 | + | |
24204 | + percpu_ref_switch_to_atomic_sync(cnt); | |
24205 | + l = atomic_long_read(&cnt->count); | |
24206 | + if (do_rev) | |
24207 | + percpu_ref_switch_to_percpu(cnt); | |
24208 | + | |
24209 | + /* percpu_ref is initialized by 1 instead of 0 */ | |
24210 | + return l - 1; | |
24211 | +} | |
24212 | +#endif | |
24213 | + | |
24214 | +#ifdef CONFIG_AUFS_DEBUG | |
24215 | +#define AuLCntZero(val) do { \ | |
24216 | + long l = val; \ | |
24217 | + if (l) \ | |
24218 | + AuDbg("%s = %ld\n", #val, l); \ | |
24219 | +} while (0) | |
24220 | +#else | |
24221 | +#define AuLCntZero(val) do {} while (0) | |
24222 | +#endif | |
24223 | + | |
24224 | +#endif /* __KERNEL__ */ | |
24225 | +#endif /* __AUFS_LCNT_H__ */ | |
7f207e10 | 24226 | diff -urN /usr/share/empty/fs/aufs/loop.c linux/fs/aufs/loop.c |
eca34b5c | 24227 | --- /usr/share/empty/fs/aufs/loop.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 24228 | +++ linux/fs/aufs/loop.c 2020-01-27 10:57:18.175538316 +0100 |
062440b3 | 24229 | @@ -0,0 +1,148 @@ |
cd7a4cd9 | 24230 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 24231 | +/* |
d58c55f2 | 24232 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 24233 | + * |
24234 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24235 | + * it under the terms of the GNU General Public License as published by | |
24236 | + * the Free Software Foundation; either version 2 of the License, or | |
24237 | + * (at your option) any later version. | |
dece6358 AM |
24238 | + * |
24239 | + * This program is distributed in the hope that it will be useful, | |
24240 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24241 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24242 | + * GNU General Public License for more details. | |
24243 | + * | |
24244 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24245 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24246 | + */ |
24247 | + | |
24248 | +/* | |
24249 | + * support for loopback block device as a branch | |
24250 | + */ | |
24251 | + | |
1facf9fc | 24252 | +#include "aufs.h" |
24253 | + | |
392086de AM |
24254 | +/* added into drivers/block/loop.c */ |
24255 | +static struct file *(*backing_file_func)(struct super_block *sb); | |
24256 | + | |
1facf9fc | 24257 | +/* |
24258 | + * test if two lower dentries have overlapping branches. | |
24259 | + */ | |
b752ccd1 | 24260 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding) |
1facf9fc | 24261 | +{ |
b752ccd1 | 24262 | + struct super_block *h_sb; |
392086de AM |
24263 | + struct file *backing_file; |
24264 | + | |
24265 | + if (unlikely(!backing_file_func)) { | |
24266 | + /* don't load "loop" module here */ | |
24267 | + backing_file_func = symbol_get(loop_backing_file); | |
24268 | + if (unlikely(!backing_file_func)) | |
24269 | + /* "loop" module is not loaded */ | |
24270 | + return 0; | |
24271 | + } | |
1facf9fc | 24272 | + |
b752ccd1 | 24273 | + h_sb = h_adding->d_sb; |
392086de AM |
24274 | + backing_file = backing_file_func(h_sb); |
24275 | + if (!backing_file) | |
1facf9fc | 24276 | + return 0; |
24277 | + | |
2000de60 | 24278 | + h_adding = backing_file->f_path.dentry; |
b752ccd1 AM |
24279 | + /* |
24280 | + * h_adding can be local NFS. | |
24281 | + * in this case aufs cannot detect the loop. | |
24282 | + */ | |
24283 | + if (unlikely(h_adding->d_sb == sb)) | |
1facf9fc | 24284 | + return 1; |
b752ccd1 | 24285 | + return !!au_test_subdir(h_adding, sb->s_root); |
1facf9fc | 24286 | +} |
24287 | + | |
24288 | +/* true if a kernel thread named 'loop[0-9].*' accesses a file */ | |
24289 | +int au_test_loopback_kthread(void) | |
24290 | +{ | |
b752ccd1 AM |
24291 | + int ret; |
24292 | + struct task_struct *tsk = current; | |
a2a7ad62 | 24293 | + char c, comm[sizeof(tsk->comm)]; |
b752ccd1 AM |
24294 | + |
24295 | + ret = 0; | |
24296 | + if (tsk->flags & PF_KTHREAD) { | |
a2a7ad62 AM |
24297 | + get_task_comm(comm, tsk); |
24298 | + c = comm[4]; | |
b752ccd1 | 24299 | + ret = ('0' <= c && c <= '9' |
a2a7ad62 | 24300 | + && !strncmp(comm, "loop", 4)); |
b752ccd1 | 24301 | + } |
1facf9fc | 24302 | + |
b752ccd1 | 24303 | + return ret; |
1facf9fc | 24304 | +} |
87a755f4 AM |
24305 | + |
24306 | +/* ---------------------------------------------------------------------- */ | |
24307 | + | |
24308 | +#define au_warn_loopback_step 16 | |
24309 | +static int au_warn_loopback_nelem = au_warn_loopback_step; | |
24310 | +static unsigned long *au_warn_loopback_array; | |
24311 | + | |
24312 | +void au_warn_loopback(struct super_block *h_sb) | |
24313 | +{ | |
24314 | + int i, new_nelem; | |
24315 | + unsigned long *a, magic; | |
24316 | + static DEFINE_SPINLOCK(spin); | |
24317 | + | |
24318 | + magic = h_sb->s_magic; | |
24319 | + spin_lock(&spin); | |
24320 | + a = au_warn_loopback_array; | |
24321 | + for (i = 0; i < au_warn_loopback_nelem && *a; i++) | |
24322 | + if (a[i] == magic) { | |
24323 | + spin_unlock(&spin); | |
24324 | + return; | |
24325 | + } | |
24326 | + | |
24327 | + /* h_sb is new to us, print it */ | |
24328 | + if (i < au_warn_loopback_nelem) { | |
24329 | + a[i] = magic; | |
24330 | + goto pr; | |
24331 | + } | |
24332 | + | |
24333 | + /* expand the array */ | |
24334 | + new_nelem = au_warn_loopback_nelem + au_warn_loopback_step; | |
24335 | + a = au_kzrealloc(au_warn_loopback_array, | |
24336 | + au_warn_loopback_nelem * sizeof(unsigned long), | |
e2f27e51 AM |
24337 | + new_nelem * sizeof(unsigned long), GFP_ATOMIC, |
24338 | + /*may_shrink*/0); | |
87a755f4 AM |
24339 | + if (a) { |
24340 | + au_warn_loopback_nelem = new_nelem; | |
24341 | + au_warn_loopback_array = a; | |
24342 | + a[i] = magic; | |
24343 | + goto pr; | |
24344 | + } | |
24345 | + | |
24346 | + spin_unlock(&spin); | |
24347 | + AuWarn1("realloc failed, ignored\n"); | |
24348 | + return; | |
24349 | + | |
24350 | +pr: | |
24351 | + spin_unlock(&spin); | |
0c3ec466 AM |
24352 | + pr_warn("you may want to try another patch for loopback file " |
24353 | + "on %s(0x%lx) branch\n", au_sbtype(h_sb), magic); | |
87a755f4 AM |
24354 | +} |
24355 | + | |
24356 | +int au_loopback_init(void) | |
24357 | +{ | |
24358 | + int err; | |
24359 | + struct super_block *sb __maybe_unused; | |
24360 | + | |
fbc438ed | 24361 | + BUILD_BUG_ON(sizeof(sb->s_magic) != sizeof(*au_warn_loopback_array)); |
87a755f4 AM |
24362 | + |
24363 | + err = 0; | |
24364 | + au_warn_loopback_array = kcalloc(au_warn_loopback_step, | |
24365 | + sizeof(unsigned long), GFP_NOFS); | |
24366 | + if (unlikely(!au_warn_loopback_array)) | |
24367 | + err = -ENOMEM; | |
24368 | + | |
24369 | + return err; | |
24370 | +} | |
24371 | + | |
24372 | +void au_loopback_fin(void) | |
24373 | +{ | |
79b8bda9 AM |
24374 | + if (backing_file_func) |
24375 | + symbol_put(loop_backing_file); | |
9f237c51 | 24376 | + au_kfree_try_rcu(au_warn_loopback_array); |
87a755f4 | 24377 | +} |
7f207e10 | 24378 | diff -urN /usr/share/empty/fs/aufs/loop.h linux/fs/aufs/loop.h |
eca34b5c | 24379 | --- /usr/share/empty/fs/aufs/loop.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 24380 | +++ linux/fs/aufs/loop.h 2020-01-27 10:57:18.175538316 +0100 |
eca801bf | 24381 | @@ -0,0 +1,55 @@ |
062440b3 | 24382 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 24383 | +/* |
d58c55f2 | 24384 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 24385 | + * |
24386 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24387 | + * it under the terms of the GNU General Public License as published by | |
24388 | + * the Free Software Foundation; either version 2 of the License, or | |
24389 | + * (at your option) any later version. | |
dece6358 AM |
24390 | + * |
24391 | + * This program is distributed in the hope that it will be useful, | |
24392 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24393 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24394 | + * GNU General Public License for more details. | |
24395 | + * | |
24396 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24397 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24398 | + */ |
24399 | + | |
24400 | +/* | |
24401 | + * support for loopback mount as a branch | |
24402 | + */ | |
24403 | + | |
24404 | +#ifndef __AUFS_LOOP_H__ | |
24405 | +#define __AUFS_LOOP_H__ | |
24406 | + | |
24407 | +#ifdef __KERNEL__ | |
24408 | + | |
dece6358 AM |
24409 | +struct dentry; |
24410 | +struct super_block; | |
1facf9fc | 24411 | + |
24412 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
392086de AM |
24413 | +/* drivers/block/loop.c */ |
24414 | +struct file *loop_backing_file(struct super_block *sb); | |
24415 | + | |
1facf9fc | 24416 | +/* loop.c */ |
b752ccd1 | 24417 | +int au_test_loopback_overlap(struct super_block *sb, struct dentry *h_adding); |
1facf9fc | 24418 | +int au_test_loopback_kthread(void); |
87a755f4 AM |
24419 | +void au_warn_loopback(struct super_block *h_sb); |
24420 | + | |
24421 | +int au_loopback_init(void); | |
24422 | +void au_loopback_fin(void); | |
1facf9fc | 24423 | +#else |
83b672a5 | 24424 | +AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb) |
eca801bf | 24425 | + |
4a4d8108 | 24426 | +AuStubInt0(au_test_loopback_overlap, struct super_block *sb, |
b752ccd1 | 24427 | + struct dentry *h_adding) |
4a4d8108 | 24428 | +AuStubInt0(au_test_loopback_kthread, void) |
87a755f4 AM |
24429 | +AuStubVoid(au_warn_loopback, struct super_block *h_sb) |
24430 | + | |
24431 | +AuStubInt0(au_loopback_init, void) | |
24432 | +AuStubVoid(au_loopback_fin, void) | |
1facf9fc | 24433 | +#endif /* BLK_DEV_LOOP */ |
24434 | + | |
24435 | +#endif /* __KERNEL__ */ | |
24436 | +#endif /* __AUFS_LOOP_H__ */ | |
7f207e10 | 24437 | diff -urN /usr/share/empty/fs/aufs/magic.mk linux/fs/aufs/magic.mk |
eca34b5c AM |
24438 | --- /usr/share/empty/fs/aufs/magic.mk 1970-01-01 01:00:00.000000000 +0100 |
24439 | +++ linux/fs/aufs/magic.mk 2019-07-11 15:42:14.468904634 +0200 | |
2121bcd9 AM |
24440 | @@ -0,0 +1,31 @@ |
24441 | +# SPDX-License-Identifier: GPL-2.0 | |
1facf9fc | 24442 | + |
24443 | +# defined in ${srctree}/fs/fuse/inode.c | |
24444 | +# tristate | |
24445 | +ifdef CONFIG_FUSE_FS | |
24446 | +ccflags-y += -DFUSE_SUPER_MAGIC=0x65735546 | |
24447 | +endif | |
24448 | + | |
1facf9fc | 24449 | +# defined in ${srctree}/fs/xfs/xfs_sb.h |
24450 | +# tristate | |
24451 | +ifdef CONFIG_XFS_FS | |
24452 | +ccflags-y += -DXFS_SB_MAGIC=0x58465342 | |
24453 | +endif | |
24454 | + | |
24455 | +# defined in ${srctree}/fs/configfs/mount.c | |
24456 | +# tristate | |
24457 | +ifdef CONFIG_CONFIGFS_FS | |
24458 | +ccflags-y += -DCONFIGFS_MAGIC=0x62656570 | |
24459 | +endif | |
24460 | + | |
1facf9fc | 24461 | +# defined in ${srctree}/fs/ubifs/ubifs.h |
24462 | +# tristate | |
24463 | +ifdef CONFIG_UBIFS_FS | |
24464 | +ccflags-y += -DUBIFS_SUPER_MAGIC=0x24051905 | |
24465 | +endif | |
4a4d8108 AM |
24466 | + |
24467 | +# defined in ${srctree}/fs/hfsplus/hfsplus_raw.h | |
24468 | +# tristate | |
24469 | +ifdef CONFIG_HFSPLUS_FS | |
24470 | +ccflags-y += -DHFSPLUS_SUPER_MAGIC=0x482b | |
24471 | +endif | |
7f207e10 | 24472 | diff -urN /usr/share/empty/fs/aufs/Makefile linux/fs/aufs/Makefile |
eca34b5c AM |
24473 | --- /usr/share/empty/fs/aufs/Makefile 1970-01-01 01:00:00.000000000 +0100 |
24474 | +++ linux/fs/aufs/Makefile 2019-07-11 15:42:14.462237786 +0200 | |
2121bcd9 AM |
24475 | @@ -0,0 +1,46 @@ |
24476 | +# SPDX-License-Identifier: GPL-2.0 | |
4a4d8108 AM |
24477 | + |
24478 | +include ${src}/magic.mk | |
24479 | +ifeq (${CONFIG_AUFS_FS},m) | |
24480 | +include ${src}/conf.mk | |
24481 | +endif | |
24482 | +-include ${src}/priv_def.mk | |
24483 | + | |
24484 | +# cf. include/linux/kernel.h | |
24485 | +# enable pr_debug | |
24486 | +ccflags-y += -DDEBUG | |
f6c5ef8b AM |
24487 | +# sparse requires the full pathname |
24488 | +ifdef M | |
523b37e3 | 24489 | +ccflags-y += -include ${M}/../../include/uapi/linux/aufs_type.h |
f6c5ef8b | 24490 | +else |
523b37e3 | 24491 | +ccflags-y += -include ${srctree}/include/uapi/linux/aufs_type.h |
f6c5ef8b | 24492 | +endif |
4a4d8108 AM |
24493 | + |
24494 | +obj-$(CONFIG_AUFS_FS) += aufs.o | |
24495 | +aufs-y := module.o sbinfo.o super.o branch.o xino.o sysaufs.o opts.o \ | |
24496 | + wkq.o vfsub.o dcsub.o \ | |
e49829fe | 24497 | + cpup.o whout.o wbr_policy.o \ |
4a4d8108 AM |
24498 | + dinfo.o dentry.o \ |
24499 | + dynop.o \ | |
24500 | + finfo.o file.o f_op.o \ | |
24501 | + dir.o vdir.o \ | |
24502 | + iinfo.o inode.o i_op.o i_op_add.o i_op_del.o i_op_ren.o \ | |
c2b27bf2 | 24503 | + mvdown.o ioctl.o |
4a4d8108 AM |
24504 | + |
24505 | +# all are boolean | |
e49829fe | 24506 | +aufs-$(CONFIG_PROC_FS) += procfs.o plink.o |
4a4d8108 AM |
24507 | +aufs-$(CONFIG_SYSFS) += sysfs.o |
24508 | +aufs-$(CONFIG_DEBUG_FS) += dbgaufs.o | |
24509 | +aufs-$(CONFIG_AUFS_BDEV_LOOP) += loop.o | |
24510 | +aufs-$(CONFIG_AUFS_HNOTIFY) += hnotify.o | |
24511 | +aufs-$(CONFIG_AUFS_HFSNOTIFY) += hfsnotify.o | |
4a4d8108 | 24512 | +aufs-$(CONFIG_AUFS_EXPORT) += export.o |
c1595e42 JR |
24513 | +aufs-$(CONFIG_AUFS_XATTR) += xattr.o |
24514 | +aufs-$(CONFIG_FS_POSIX_ACL) += posix_acl.o | |
8b6a4947 | 24515 | +aufs-$(CONFIG_AUFS_DIRREN) += dirren.o |
076b876e | 24516 | +aufs-$(CONFIG_AUFS_FHSM) += fhsm.o |
4a4d8108 AM |
24517 | +aufs-$(CONFIG_AUFS_POLL) += poll.o |
24518 | +aufs-$(CONFIG_AUFS_RDU) += rdu.o | |
4a4d8108 AM |
24519 | +aufs-$(CONFIG_AUFS_BR_HFSPLUS) += hfsplus.o |
24520 | +aufs-$(CONFIG_AUFS_DEBUG) += debug.o | |
24521 | +aufs-$(CONFIG_AUFS_MAGIC_SYSRQ) += sysrq.o | |
7f207e10 | 24522 | diff -urN /usr/share/empty/fs/aufs/module.c linux/fs/aufs/module.c |
eca34b5c | 24523 | --- /usr/share/empty/fs/aufs/module.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 24524 | +++ linux/fs/aufs/module.c 2020-01-27 10:57:18.175538316 +0100 |
062440b3 | 24525 | @@ -0,0 +1,273 @@ |
cd7a4cd9 | 24526 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 24527 | +/* |
d58c55f2 | 24528 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 24529 | + * |
24530 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24531 | + * it under the terms of the GNU General Public License as published by | |
24532 | + * the Free Software Foundation; either version 2 of the License, or | |
24533 | + * (at your option) any later version. | |
dece6358 AM |
24534 | + * |
24535 | + * This program is distributed in the hope that it will be useful, | |
24536 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24537 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24538 | + * GNU General Public License for more details. | |
24539 | + * | |
24540 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24541 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24542 | + */ |
24543 | + | |
24544 | +/* | |
24545 | + * module global variables and operations | |
24546 | + */ | |
24547 | + | |
24548 | +#include <linux/module.h> | |
24549 | +#include <linux/seq_file.h> | |
24550 | +#include "aufs.h" | |
24551 | + | |
e2f27e51 AM |
24552 | +/* shrinkable realloc */ |
24553 | +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink) | |
1facf9fc | 24554 | +{ |
e2f27e51 AM |
24555 | + size_t sz; |
24556 | + int diff; | |
1facf9fc | 24557 | + |
e2f27e51 AM |
24558 | + sz = 0; |
24559 | + diff = -1; | |
24560 | + if (p) { | |
24561 | +#if 0 /* unused */ | |
24562 | + if (!new_sz) { | |
9f237c51 | 24563 | + au_kfree_rcu(p); |
e2f27e51 AM |
24564 | + p = NULL; |
24565 | + goto out; | |
24566 | + } | |
24567 | +#else | |
24568 | + AuDebugOn(!new_sz); | |
24569 | +#endif | |
24570 | + sz = ksize(p); | |
24571 | + diff = au_kmidx_sub(sz, new_sz); | |
24572 | + } | |
24573 | + if (sz && !diff) | |
24574 | + goto out; | |
24575 | + | |
24576 | + if (sz < new_sz) | |
24577 | + /* expand or SLOB */ | |
24578 | + p = krealloc(p, new_sz, gfp); | |
24579 | + else if (new_sz < sz && may_shrink) { | |
24580 | + /* shrink */ | |
24581 | + void *q; | |
24582 | + | |
24583 | + q = kmalloc(new_sz, gfp); | |
24584 | + if (q) { | |
24585 | + if (p) { | |
24586 | + memcpy(q, p, new_sz); | |
9f237c51 | 24587 | + au_kfree_try_rcu(p); |
e2f27e51 AM |
24588 | + } |
24589 | + p = q; | |
24590 | + } else | |
24591 | + p = NULL; | |
24592 | + } | |
24593 | + | |
24594 | +out: | |
24595 | + return p; | |
24596 | +} | |
24597 | + | |
24598 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp, | |
24599 | + int may_shrink) | |
24600 | +{ | |
24601 | + p = au_krealloc(p, new_sz, gfp, may_shrink); | |
24602 | + if (p && new_sz > nused) | |
1facf9fc | 24603 | + memset(p + nused, 0, new_sz - nused); |
24604 | + return p; | |
24605 | +} | |
24606 | + | |
24607 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 24608 | +/* |
24609 | + * aufs caches | |
24610 | + */ | |
1c60b727 | 24611 | +struct kmem_cache *au_cache[AuCache_Last]; |
5afbbe0d AM |
24612 | + |
24613 | +static void au_cache_fin(void) | |
24614 | +{ | |
24615 | + int i; | |
24616 | + | |
24617 | + /* | |
24618 | + * Make sure all delayed rcu free inodes are flushed before we | |
24619 | + * destroy cache. | |
24620 | + */ | |
24621 | + rcu_barrier(); | |
24622 | + | |
24623 | + /* excluding AuCache_HNOTIFY */ | |
24624 | + BUILD_BUG_ON(AuCache_HNOTIFY + 1 != AuCache_Last); | |
24625 | + for (i = 0; i < AuCache_HNOTIFY; i++) { | |
1c60b727 AM |
24626 | + kmem_cache_destroy(au_cache[i]); |
24627 | + au_cache[i] = NULL; | |
5afbbe0d AM |
24628 | + } |
24629 | +} | |
24630 | + | |
1facf9fc | 24631 | +static int __init au_cache_init(void) |
24632 | +{ | |
1c60b727 AM |
24633 | + au_cache[AuCache_DINFO] = AuCacheCtor(au_dinfo, au_di_init_once); |
24634 | + if (au_cache[AuCache_DINFO]) | |
027c5e7a | 24635 | + /* SLAB_DESTROY_BY_RCU */ |
1c60b727 | 24636 | + au_cache[AuCache_ICNTNR] = AuCacheCtor(au_icntnr, |
f0c0a007 | 24637 | + au_icntnr_init_once); |
1c60b727 AM |
24638 | + if (au_cache[AuCache_ICNTNR]) |
24639 | + au_cache[AuCache_FINFO] = AuCacheCtor(au_finfo, | |
f0c0a007 | 24640 | + au_fi_init_once); |
1c60b727 AM |
24641 | + if (au_cache[AuCache_FINFO]) |
24642 | + au_cache[AuCache_VDIR] = AuCache(au_vdir); | |
24643 | + if (au_cache[AuCache_VDIR]) | |
24644 | + au_cache[AuCache_DEHSTR] = AuCache(au_vdir_dehstr); | |
24645 | + if (au_cache[AuCache_DEHSTR]) | |
1facf9fc | 24646 | + return 0; |
24647 | + | |
5afbbe0d | 24648 | + au_cache_fin(); |
1facf9fc | 24649 | + return -ENOMEM; |
24650 | +} | |
24651 | + | |
1facf9fc | 24652 | +/* ---------------------------------------------------------------------- */ |
24653 | + | |
24654 | +int au_dir_roflags; | |
24655 | + | |
e49829fe | 24656 | +#ifdef CONFIG_AUFS_SBILIST |
1e00d052 AM |
24657 | +/* |
24658 | + * iterate_supers_type() doesn't protect us from | |
24659 | + * remounting (branch management) | |
24660 | + */ | |
8b6a4947 | 24661 | +struct hlist_bl_head au_sbilist; |
e49829fe JR |
24662 | +#endif |
24663 | + | |
1facf9fc | 24664 | +/* |
24665 | + * functions for module interface. | |
24666 | + */ | |
24667 | +MODULE_LICENSE("GPL"); | |
24668 | +/* MODULE_LICENSE("GPL v2"); */ | |
dece6358 | 24669 | +MODULE_AUTHOR("Junjiro R. Okajima <aufs-users@lists.sourceforge.net>"); |
1facf9fc | 24670 | +MODULE_DESCRIPTION(AUFS_NAME |
24671 | + " -- Advanced multi layered unification filesystem"); | |
24672 | +MODULE_VERSION(AUFS_VERSION); | |
c06a8ce3 | 24673 | +MODULE_ALIAS_FS(AUFS_NAME); |
1facf9fc | 24674 | + |
1facf9fc | 24675 | +/* this module parameter has no meaning when SYSFS is disabled */ |
24676 | +int sysaufs_brs = 1; | |
24677 | +MODULE_PARM_DESC(brs, "use <sysfs>/fs/aufs/si_*/brN"); | |
cd7a4cd9 | 24678 | +module_param_named(brs, sysaufs_brs, int, 0444); |
1facf9fc | 24679 | + |
076b876e | 24680 | +/* this module parameter has no meaning when USER_NS is disabled */ |
8cdd5066 | 24681 | +bool au_userns; |
076b876e | 24682 | +MODULE_PARM_DESC(allow_userns, "allow unprivileged to mount under userns"); |
cd7a4cd9 | 24683 | +module_param_named(allow_userns, au_userns, bool, 0444); |
076b876e | 24684 | + |
1facf9fc | 24685 | +/* ---------------------------------------------------------------------- */ |
24686 | + | |
24687 | +static char au_esc_chars[0x20 + 3]; /* 0x01-0x20, backslash, del, and NULL */ | |
24688 | + | |
24689 | +int au_seq_path(struct seq_file *seq, struct path *path) | |
24690 | +{ | |
79b8bda9 AM |
24691 | + int err; |
24692 | + | |
24693 | + err = seq_path(seq, path, au_esc_chars); | |
1c60b727 | 24694 | + if (err >= 0) |
79b8bda9 | 24695 | + err = 0; |
1c60b727 | 24696 | + else |
79b8bda9 AM |
24697 | + err = -ENOMEM; |
24698 | + | |
24699 | + return err; | |
1facf9fc | 24700 | +} |
24701 | + | |
24702 | +/* ---------------------------------------------------------------------- */ | |
24703 | + | |
24704 | +static int __init aufs_init(void) | |
24705 | +{ | |
24706 | + int err, i; | |
24707 | + char *p; | |
24708 | + | |
24709 | + p = au_esc_chars; | |
24710 | + for (i = 1; i <= ' '; i++) | |
24711 | + *p++ = i; | |
24712 | + *p++ = '\\'; | |
24713 | + *p++ = '\x7f'; | |
24714 | + *p = 0; | |
24715 | + | |
24716 | + au_dir_roflags = au_file_roflags(O_DIRECTORY | O_LARGEFILE); | |
24717 | + | |
b95c5147 AM |
24718 | + memcpy(aufs_iop_nogetattr, aufs_iop, sizeof(aufs_iop)); |
24719 | + for (i = 0; i < AuIop_Last; i++) | |
24720 | + aufs_iop_nogetattr[i].getattr = NULL; | |
24721 | + | |
1c60b727 | 24722 | + memset(au_cache, 0, sizeof(au_cache)); /* including hnotify */ |
f0c0a007 | 24723 | + |
e49829fe | 24724 | + au_sbilist_init(); |
1facf9fc | 24725 | + sysaufs_brs_init(); |
24726 | + au_debug_init(); | |
4a4d8108 | 24727 | + au_dy_init(); |
1facf9fc | 24728 | + err = sysaufs_init(); |
24729 | + if (unlikely(err)) | |
24730 | + goto out; | |
062440b3 | 24731 | + err = dbgaufs_init(); |
4f0767ce | 24732 | + if (unlikely(err)) |
953406b4 | 24733 | + goto out_sysaufs; |
062440b3 AM |
24734 | + err = au_procfs_init(); |
24735 | + if (unlikely(err)) | |
24736 | + goto out_dbgaufs; | |
e49829fe JR |
24737 | + err = au_wkq_init(); |
24738 | + if (unlikely(err)) | |
24739 | + goto out_procfs; | |
87a755f4 | 24740 | + err = au_loopback_init(); |
1facf9fc | 24741 | + if (unlikely(err)) |
24742 | + goto out_wkq; | |
87a755f4 AM |
24743 | + err = au_hnotify_init(); |
24744 | + if (unlikely(err)) | |
24745 | + goto out_loopback; | |
1facf9fc | 24746 | + err = au_sysrq_init(); |
24747 | + if (unlikely(err)) | |
24748 | + goto out_hin; | |
24749 | + err = au_cache_init(); | |
24750 | + if (unlikely(err)) | |
24751 | + goto out_sysrq; | |
076b876e AM |
24752 | + |
24753 | + aufs_fs_type.fs_flags |= au_userns ? FS_USERNS_MOUNT : 0; | |
1facf9fc | 24754 | + err = register_filesystem(&aufs_fs_type); |
24755 | + if (unlikely(err)) | |
24756 | + goto out_cache; | |
076b876e | 24757 | + |
4a4d8108 AM |
24758 | + /* since we define pr_fmt, call printk directly */ |
24759 | + printk(KERN_INFO AUFS_NAME " " AUFS_VERSION "\n"); | |
1facf9fc | 24760 | + goto out; /* success */ |
24761 | + | |
4f0767ce | 24762 | +out_cache: |
1facf9fc | 24763 | + au_cache_fin(); |
4f0767ce | 24764 | +out_sysrq: |
1facf9fc | 24765 | + au_sysrq_fin(); |
4f0767ce | 24766 | +out_hin: |
4a4d8108 | 24767 | + au_hnotify_fin(); |
87a755f4 AM |
24768 | +out_loopback: |
24769 | + au_loopback_fin(); | |
4f0767ce | 24770 | +out_wkq: |
1facf9fc | 24771 | + au_wkq_fin(); |
e49829fe JR |
24772 | +out_procfs: |
24773 | + au_procfs_fin(); | |
062440b3 AM |
24774 | +out_dbgaufs: |
24775 | + dbgaufs_fin(); | |
4f0767ce | 24776 | +out_sysaufs: |
1facf9fc | 24777 | + sysaufs_fin(); |
4a4d8108 | 24778 | + au_dy_fin(); |
4f0767ce | 24779 | +out: |
1facf9fc | 24780 | + return err; |
24781 | +} | |
24782 | + | |
24783 | +static void __exit aufs_exit(void) | |
24784 | +{ | |
24785 | + unregister_filesystem(&aufs_fs_type); | |
24786 | + au_cache_fin(); | |
24787 | + au_sysrq_fin(); | |
4a4d8108 | 24788 | + au_hnotify_fin(); |
87a755f4 | 24789 | + au_loopback_fin(); |
1facf9fc | 24790 | + au_wkq_fin(); |
e49829fe | 24791 | + au_procfs_fin(); |
062440b3 | 24792 | + dbgaufs_fin(); |
1facf9fc | 24793 | + sysaufs_fin(); |
4a4d8108 | 24794 | + au_dy_fin(); |
1facf9fc | 24795 | +} |
24796 | + | |
24797 | +module_init(aufs_init); | |
24798 | +module_exit(aufs_exit); | |
7f207e10 | 24799 | diff -urN /usr/share/empty/fs/aufs/module.h linux/fs/aufs/module.h |
eca34b5c | 24800 | --- /usr/share/empty/fs/aufs/module.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 24801 | +++ linux/fs/aufs/module.h 2020-01-27 10:57:18.175538316 +0100 |
9f237c51 | 24802 | @@ -0,0 +1,166 @@ |
062440b3 | 24803 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 24804 | +/* |
d58c55f2 | 24805 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 24806 | + * |
24807 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24808 | + * it under the terms of the GNU General Public License as published by | |
24809 | + * the Free Software Foundation; either version 2 of the License, or | |
24810 | + * (at your option) any later version. | |
dece6358 AM |
24811 | + * |
24812 | + * This program is distributed in the hope that it will be useful, | |
24813 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24814 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24815 | + * GNU General Public License for more details. | |
24816 | + * | |
24817 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 24818 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 24819 | + */ |
24820 | + | |
24821 | +/* | |
24822 | + * module initialization and module-global | |
24823 | + */ | |
24824 | + | |
24825 | +#ifndef __AUFS_MODULE_H__ | |
24826 | +#define __AUFS_MODULE_H__ | |
24827 | + | |
24828 | +#ifdef __KERNEL__ | |
24829 | + | |
24830 | +#include <linux/slab.h> | |
9f237c51 AM |
24831 | +#include "debug.h" |
24832 | +#include "dentry.h" | |
24833 | +#include "dir.h" | |
24834 | +#include "file.h" | |
24835 | +#include "inode.h" | |
1facf9fc | 24836 | + |
dece6358 AM |
24837 | +struct path; |
24838 | +struct seq_file; | |
24839 | + | |
1facf9fc | 24840 | +/* module parameters */ |
1facf9fc | 24841 | +extern int sysaufs_brs; |
8cdd5066 | 24842 | +extern bool au_userns; |
1facf9fc | 24843 | + |
24844 | +/* ---------------------------------------------------------------------- */ | |
24845 | + | |
24846 | +extern int au_dir_roflags; | |
24847 | + | |
e2f27e51 AM |
24848 | +void *au_krealloc(void *p, unsigned int new_sz, gfp_t gfp, int may_shrink); |
24849 | +void *au_kzrealloc(void *p, unsigned int nused, unsigned int new_sz, gfp_t gfp, | |
24850 | + int may_shrink); | |
24851 | + | |
9f237c51 AM |
24852 | +/* |
24853 | + * Comparing the size of the object with sizeof(struct rcu_head) | |
24854 | + * case 1: object is always larger | |
24855 | + * --> au_kfree_rcu() or au_kfree_do_rcu() | |
24856 | + * case 2: object is always smaller | |
24857 | + * --> au_kfree_small() | |
24858 | + * case 3: object can be any size | |
24859 | + * --> au_kfree_try_rcu() | |
24860 | + */ | |
24861 | + | |
24862 | +static inline void au_kfree_do_rcu(const void *p) | |
24863 | +{ | |
24864 | + struct { | |
24865 | + struct rcu_head rcu; | |
24866 | + } *a = (void *)p; | |
24867 | + | |
24868 | + kfree_rcu(a, rcu); | |
24869 | +} | |
24870 | + | |
24871 | +#define au_kfree_rcu(_p) do { \ | |
24872 | + typeof(_p) p = (_p); \ | |
24873 | + BUILD_BUG_ON(sizeof(*p) < sizeof(struct rcu_head)); \ | |
24874 | + if (p) \ | |
24875 | + au_kfree_do_rcu(p); \ | |
24876 | + } while (0) | |
24877 | + | |
24878 | +#define au_kfree_do_sz_test(sz) (sz >= sizeof(struct rcu_head)) | |
24879 | +#define au_kfree_sz_test(p) (p && au_kfree_do_sz_test(ksize(p))) | |
24880 | + | |
24881 | +static inline void au_kfree_try_rcu(const void *p) | |
24882 | +{ | |
24883 | + if (!p) | |
24884 | + return; | |
24885 | + if (au_kfree_sz_test(p)) | |
24886 | + au_kfree_do_rcu(p); | |
24887 | + else | |
24888 | + kfree(p); | |
24889 | +} | |
24890 | + | |
24891 | +static inline void au_kfree_small(const void *p) | |
24892 | +{ | |
24893 | + if (!p) | |
24894 | + return; | |
24895 | + AuDebugOn(au_kfree_sz_test(p)); | |
24896 | + kfree(p); | |
24897 | +} | |
24898 | + | |
e2f27e51 AM |
24899 | +static inline int au_kmidx_sub(size_t sz, size_t new_sz) |
24900 | +{ | |
24901 | +#ifndef CONFIG_SLOB | |
24902 | + return kmalloc_index(sz) - kmalloc_index(new_sz); | |
24903 | +#else | |
24904 | + return -1; /* SLOB is untested */ | |
24905 | +#endif | |
24906 | +} | |
24907 | + | |
1facf9fc | 24908 | +int au_seq_path(struct seq_file *seq, struct path *path); |
24909 | + | |
e49829fe JR |
24910 | +#ifdef CONFIG_PROC_FS |
24911 | +/* procfs.c */ | |
24912 | +int __init au_procfs_init(void); | |
24913 | +void au_procfs_fin(void); | |
24914 | +#else | |
24915 | +AuStubInt0(au_procfs_init, void); | |
24916 | +AuStubVoid(au_procfs_fin, void); | |
24917 | +#endif | |
24918 | + | |
4f0767ce JR |
24919 | +/* ---------------------------------------------------------------------- */ |
24920 | + | |
1c60b727 | 24921 | +/* kmem cache */ |
1facf9fc | 24922 | +enum { |
24923 | + AuCache_DINFO, | |
24924 | + AuCache_ICNTNR, | |
24925 | + AuCache_FINFO, | |
24926 | + AuCache_VDIR, | |
24927 | + AuCache_DEHSTR, | |
7eafdf33 | 24928 | + AuCache_HNOTIFY, /* must be last */ |
1facf9fc | 24929 | + AuCache_Last |
24930 | +}; | |
24931 | + | |
1c60b727 | 24932 | +extern struct kmem_cache *au_cache[AuCache_Last]; |
f0c0a007 | 24933 | + |
4a4d8108 AM |
24934 | +#define AuCacheFlags (SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD) |
24935 | +#define AuCache(type) KMEM_CACHE(type, AuCacheFlags) | |
24936 | +#define AuCacheCtor(type, ctor) \ | |
24937 | + kmem_cache_create(#type, sizeof(struct type), \ | |
24938 | + __alignof__(struct type), AuCacheFlags, ctor) | |
1facf9fc | 24939 | + |
9f237c51 AM |
24940 | +#define AuCacheFuncs(name, index) \ |
24941 | + static inline struct au_##name *au_cache_alloc_##name(void) \ | |
24942 | + { return kmem_cache_alloc(au_cache[AuCache_##index], GFP_NOFS); } \ | |
24943 | + static inline void au_cache_free_##name##_norcu(struct au_##name *p) \ | |
24944 | + { kmem_cache_free(au_cache[AuCache_##index], p); } \ | |
24945 | + \ | |
24946 | + static inline void au_cache_free_##name##_rcu_cb(struct rcu_head *rcu) \ | |
24947 | + { void *p = rcu; \ | |
24948 | + p -= offsetof(struct au_##name, rcu); \ | |
24949 | + kmem_cache_free(au_cache[AuCache_##index], p); } \ | |
24950 | + static inline void au_cache_free_##name##_rcu(struct au_##name *p) \ | |
24951 | + { BUILD_BUG_ON(sizeof(struct au_##name) < sizeof(struct rcu_head)); \ | |
24952 | + call_rcu(&p->rcu, au_cache_free_##name##_rcu_cb); } \ | |
24953 | + \ | |
24954 | + static inline void au_cache_free_##name(struct au_##name *p) \ | |
24955 | + { /* au_cache_free_##name##_norcu(p); */ \ | |
24956 | + au_cache_free_##name##_rcu(p); } | |
1facf9fc | 24957 | + |
24958 | +AuCacheFuncs(dinfo, DINFO); | |
24959 | +AuCacheFuncs(icntnr, ICNTNR); | |
24960 | +AuCacheFuncs(finfo, FINFO); | |
24961 | +AuCacheFuncs(vdir, VDIR); | |
4a4d8108 AM |
24962 | +AuCacheFuncs(vdir_dehstr, DEHSTR); |
24963 | +#ifdef CONFIG_AUFS_HNOTIFY | |
24964 | +AuCacheFuncs(hnotify, HNOTIFY); | |
24965 | +#endif | |
1facf9fc | 24966 | + |
4a4d8108 AM |
24967 | +#endif /* __KERNEL__ */ |
24968 | +#endif /* __AUFS_MODULE_H__ */ | |
c2b27bf2 | 24969 | diff -urN /usr/share/empty/fs/aufs/mvdown.c linux/fs/aufs/mvdown.c |
eca34b5c | 24970 | --- /usr/share/empty/fs/aufs/mvdown.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 24971 | +++ linux/fs/aufs/mvdown.c 2020-01-27 10:57:18.175538316 +0100 |
ba1aed25 | 24972 | @@ -0,0 +1,706 @@ |
cd7a4cd9 | 24973 | +// SPDX-License-Identifier: GPL-2.0 |
c2b27bf2 | 24974 | +/* |
d58c55f2 | 24975 | + * Copyright (C) 2011-2020 Junjiro R. Okajima |
c2b27bf2 AM |
24976 | + * |
24977 | + * This program, aufs is free software; you can redistribute it and/or modify | |
24978 | + * it under the terms of the GNU General Public License as published by | |
24979 | + * the Free Software Foundation; either version 2 of the License, or | |
24980 | + * (at your option) any later version. | |
24981 | + * | |
24982 | + * This program is distributed in the hope that it will be useful, | |
24983 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24984 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24985 | + * GNU General Public License for more details. | |
24986 | + * | |
24987 | + * You should have received a copy of the GNU General Public License | |
523b37e3 AM |
24988 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
24989 | + */ | |
24990 | + | |
24991 | +/* | |
24992 | + * move-down, opposite of copy-up | |
c2b27bf2 AM |
24993 | + */ |
24994 | + | |
24995 | +#include "aufs.h" | |
24996 | + | |
c2b27bf2 AM |
24997 | +struct au_mvd_args { |
24998 | + struct { | |
c2b27bf2 AM |
24999 | + struct super_block *h_sb; |
25000 | + struct dentry *h_parent; | |
25001 | + struct au_hinode *hdir; | |
392086de | 25002 | + struct inode *h_dir, *h_inode; |
c1595e42 | 25003 | + struct au_pin pin; |
c2b27bf2 AM |
25004 | + } info[AUFS_MVDOWN_NARRAY]; |
25005 | + | |
25006 | + struct aufs_mvdown mvdown; | |
25007 | + struct dentry *dentry, *parent; | |
25008 | + struct inode *inode, *dir; | |
25009 | + struct super_block *sb; | |
25010 | + aufs_bindex_t bopq, bwh, bfound; | |
25011 | + unsigned char rename_lock; | |
c2b27bf2 AM |
25012 | +}; |
25013 | + | |
392086de | 25014 | +#define mvd_errno mvdown.au_errno |
076b876e AM |
25015 | +#define mvd_bsrc mvdown.stbr[AUFS_MVDOWN_UPPER].bindex |
25016 | +#define mvd_src_brid mvdown.stbr[AUFS_MVDOWN_UPPER].brid | |
25017 | +#define mvd_bdst mvdown.stbr[AUFS_MVDOWN_LOWER].bindex | |
25018 | +#define mvd_dst_brid mvdown.stbr[AUFS_MVDOWN_LOWER].brid | |
c2b27bf2 | 25019 | + |
392086de AM |
25020 | +#define mvd_h_src_sb info[AUFS_MVDOWN_UPPER].h_sb |
25021 | +#define mvd_h_src_parent info[AUFS_MVDOWN_UPPER].h_parent | |
25022 | +#define mvd_hdir_src info[AUFS_MVDOWN_UPPER].hdir | |
25023 | +#define mvd_h_src_dir info[AUFS_MVDOWN_UPPER].h_dir | |
25024 | +#define mvd_h_src_inode info[AUFS_MVDOWN_UPPER].h_inode | |
c1595e42 | 25025 | +#define mvd_pin_src info[AUFS_MVDOWN_UPPER].pin |
392086de AM |
25026 | + |
25027 | +#define mvd_h_dst_sb info[AUFS_MVDOWN_LOWER].h_sb | |
25028 | +#define mvd_h_dst_parent info[AUFS_MVDOWN_LOWER].h_parent | |
25029 | +#define mvd_hdir_dst info[AUFS_MVDOWN_LOWER].hdir | |
25030 | +#define mvd_h_dst_dir info[AUFS_MVDOWN_LOWER].h_dir | |
25031 | +#define mvd_h_dst_inode info[AUFS_MVDOWN_LOWER].h_inode | |
c1595e42 | 25032 | +#define mvd_pin_dst info[AUFS_MVDOWN_LOWER].pin |
c2b27bf2 AM |
25033 | + |
25034 | +#define AU_MVD_PR(flag, ...) do { \ | |
25035 | + if (flag) \ | |
25036 | + pr_err(__VA_ARGS__); \ | |
25037 | + } while (0) | |
25038 | + | |
076b876e AM |
25039 | +static int find_lower_writable(struct au_mvd_args *a) |
25040 | +{ | |
25041 | + struct super_block *sb; | |
5afbbe0d | 25042 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
25043 | + struct au_branch *br; |
25044 | + | |
25045 | + sb = a->sb; | |
25046 | + bindex = a->mvd_bsrc; | |
5afbbe0d | 25047 | + bbot = au_sbbot(sb); |
076b876e | 25048 | + if (a->mvdown.flags & AUFS_MVDOWN_FHSM_LOWER) |
5afbbe0d | 25049 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
25050 | + br = au_sbr(sb, bindex); |
25051 | + if (au_br_fhsm(br->br_perm) | |
8b6a4947 | 25052 | + && !sb_rdonly(au_br_sb(br))) |
076b876e AM |
25053 | + return bindex; |
25054 | + } | |
25055 | + else if (!(a->mvdown.flags & AUFS_MVDOWN_ROLOWER)) | |
5afbbe0d | 25056 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e AM |
25057 | + br = au_sbr(sb, bindex); |
25058 | + if (!au_br_rdonly(br)) | |
25059 | + return bindex; | |
25060 | + } | |
25061 | + else | |
5afbbe0d | 25062 | + for (bindex++; bindex <= bbot; bindex++) { |
076b876e | 25063 | + br = au_sbr(sb, bindex); |
8b6a4947 | 25064 | + if (!sb_rdonly(au_br_sb(br))) { |
076b876e AM |
25065 | + if (au_br_rdonly(br)) |
25066 | + a->mvdown.flags | |
25067 | + |= AUFS_MVDOWN_ROLOWER_R; | |
25068 | + return bindex; | |
25069 | + } | |
25070 | + } | |
25071 | + | |
25072 | + return -1; | |
25073 | +} | |
25074 | + | |
c2b27bf2 | 25075 | +/* make the parent dir on bdst */ |
392086de | 25076 | +static int au_do_mkdir(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25077 | +{ |
25078 | + int err; | |
25079 | + | |
25080 | + err = 0; | |
25081 | + a->mvd_hdir_src = au_hi(a->dir, a->mvd_bsrc); | |
25082 | + a->mvd_hdir_dst = au_hi(a->dir, a->mvd_bdst); | |
25083 | + a->mvd_h_src_parent = au_h_dptr(a->parent, a->mvd_bsrc); | |
25084 | + a->mvd_h_dst_parent = NULL; | |
5afbbe0d | 25085 | + if (au_dbbot(a->parent) >= a->mvd_bdst) |
c2b27bf2 AM |
25086 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); |
25087 | + if (!a->mvd_h_dst_parent) { | |
25088 | + err = au_cpdown_dirs(a->dentry, a->mvd_bdst); | |
25089 | + if (unlikely(err)) { | |
392086de | 25090 | + AU_MVD_PR(dmsg, "cpdown_dirs failed\n"); |
c2b27bf2 AM |
25091 | + goto out; |
25092 | + } | |
25093 | + a->mvd_h_dst_parent = au_h_dptr(a->parent, a->mvd_bdst); | |
25094 | + } | |
25095 | + | |
25096 | +out: | |
25097 | + AuTraceErr(err); | |
25098 | + return err; | |
25099 | +} | |
25100 | + | |
25101 | +/* lock them all */ | |
392086de | 25102 | +static int au_do_lock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25103 | +{ |
25104 | + int err; | |
25105 | + struct dentry *h_trap; | |
25106 | + | |
25107 | + a->mvd_h_src_sb = au_sbr_sb(a->sb, a->mvd_bsrc); | |
25108 | + a->mvd_h_dst_sb = au_sbr_sb(a->sb, a->mvd_bdst); | |
c1595e42 JR |
25109 | + err = au_pin(&a->mvd_pin_dst, a->dentry, a->mvd_bdst, |
25110 | + au_opt_udba(a->sb), | |
25111 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
25112 | + AuTraceErr(err); | |
25113 | + if (unlikely(err)) { | |
25114 | + AU_MVD_PR(dmsg, "pin_dst failed\n"); | |
25115 | + goto out; | |
25116 | + } | |
25117 | + | |
c2b27bf2 AM |
25118 | + if (a->mvd_h_src_sb != a->mvd_h_dst_sb) { |
25119 | + a->rename_lock = 0; | |
c1595e42 JR |
25120 | + au_pin_init(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, |
25121 | + AuLsc_DI_PARENT, AuLsc_I_PARENT3, | |
25122 | + au_opt_udba(a->sb), | |
25123 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
25124 | + err = au_do_pin(&a->mvd_pin_src); | |
25125 | + AuTraceErr(err); | |
5527c038 | 25126 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
25127 | + if (unlikely(err)) { |
25128 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
25129 | + goto out_dst; | |
25130 | + } | |
25131 | + goto out; /* success */ | |
c2b27bf2 AM |
25132 | + } |
25133 | + | |
c2b27bf2 | 25134 | + a->rename_lock = 1; |
c1595e42 JR |
25135 | + au_pin_hdir_unlock(&a->mvd_pin_dst); |
25136 | + err = au_pin(&a->mvd_pin_src, a->dentry, a->mvd_bsrc, | |
25137 | + au_opt_udba(a->sb), | |
25138 | + AuPin_MNT_WRITE | AuPin_DI_LOCKED); | |
25139 | + AuTraceErr(err); | |
5527c038 | 25140 | + a->mvd_h_src_dir = d_inode(a->mvd_h_src_parent); |
c1595e42 JR |
25141 | + if (unlikely(err)) { |
25142 | + AU_MVD_PR(dmsg, "pin_src failed\n"); | |
25143 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
25144 | + goto out_dst; | |
25145 | + } | |
25146 | + au_pin_hdir_unlock(&a->mvd_pin_src); | |
c2b27bf2 AM |
25147 | + h_trap = vfsub_lock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
25148 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
25149 | + if (h_trap) { | |
25150 | + err = (h_trap != a->mvd_h_src_parent); | |
25151 | + if (err) | |
25152 | + err = (h_trap != a->mvd_h_dst_parent); | |
25153 | + } | |
25154 | + BUG_ON(err); /* it should never happen */ | |
c1595e42 JR |
25155 | + if (unlikely(a->mvd_h_src_dir != au_pinned_h_dir(&a->mvd_pin_src))) { |
25156 | + err = -EBUSY; | |
25157 | + AuTraceErr(err); | |
25158 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, | |
25159 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
25160 | + au_pin_hdir_lock(&a->mvd_pin_src); | |
25161 | + au_unpin(&a->mvd_pin_src); | |
25162 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
25163 | + goto out_dst; | |
25164 | + } | |
25165 | + goto out; /* success */ | |
c2b27bf2 | 25166 | + |
c1595e42 JR |
25167 | +out_dst: |
25168 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
25169 | +out: |
25170 | + AuTraceErr(err); | |
25171 | + return err; | |
25172 | +} | |
25173 | + | |
392086de | 25174 | +static void au_do_unlock(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 | 25175 | +{ |
c1595e42 JR |
25176 | + if (!a->rename_lock) |
25177 | + au_unpin(&a->mvd_pin_src); | |
25178 | + else { | |
c2b27bf2 AM |
25179 | + vfsub_unlock_rename(a->mvd_h_src_parent, a->mvd_hdir_src, |
25180 | + a->mvd_h_dst_parent, a->mvd_hdir_dst); | |
c1595e42 JR |
25181 | + au_pin_hdir_lock(&a->mvd_pin_src); |
25182 | + au_unpin(&a->mvd_pin_src); | |
25183 | + au_pin_hdir_lock(&a->mvd_pin_dst); | |
25184 | + } | |
25185 | + au_unpin(&a->mvd_pin_dst); | |
c2b27bf2 AM |
25186 | +} |
25187 | + | |
25188 | +/* copy-down the file */ | |
392086de | 25189 | +static int au_do_cpdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25190 | +{ |
25191 | + int err; | |
25192 | + struct au_cp_generic cpg = { | |
25193 | + .dentry = a->dentry, | |
25194 | + .bdst = a->mvd_bdst, | |
25195 | + .bsrc = a->mvd_bsrc, | |
25196 | + .len = -1, | |
c1595e42 | 25197 | + .pin = &a->mvd_pin_dst, |
c2b27bf2 AM |
25198 | + .flags = AuCpup_DTIME | AuCpup_HOPEN |
25199 | + }; | |
25200 | + | |
25201 | + AuDbg("b%d, b%d\n", cpg.bsrc, cpg.bdst); | |
392086de AM |
25202 | + if (a->mvdown.flags & AUFS_MVDOWN_OWLOWER) |
25203 | + au_fset_cpup(cpg.flags, OVERWRITE); | |
25204 | + if (a->mvdown.flags & AUFS_MVDOWN_ROLOWER) | |
25205 | + au_fset_cpup(cpg.flags, RWDST); | |
c2b27bf2 AM |
25206 | + err = au_sio_cpdown_simple(&cpg); |
25207 | + if (unlikely(err)) | |
392086de | 25208 | + AU_MVD_PR(dmsg, "cpdown failed\n"); |
c2b27bf2 AM |
25209 | + |
25210 | + AuTraceErr(err); | |
25211 | + return err; | |
25212 | +} | |
25213 | + | |
25214 | +/* | |
25215 | + * unlink the whiteout on bdst if exist which may be created by UDBA while we | |
25216 | + * were sleeping | |
25217 | + */ | |
392086de | 25218 | +static int au_do_unlink_wh(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25219 | +{ |
25220 | + int err; | |
25221 | + struct path h_path; | |
25222 | + struct au_branch *br; | |
523b37e3 | 25223 | + struct inode *delegated; |
c2b27bf2 AM |
25224 | + |
25225 | + br = au_sbr(a->sb, a->mvd_bdst); | |
25226 | + h_path.dentry = au_wh_lkup(a->mvd_h_dst_parent, &a->dentry->d_name, br); | |
25227 | + err = PTR_ERR(h_path.dentry); | |
25228 | + if (IS_ERR(h_path.dentry)) { | |
392086de | 25229 | + AU_MVD_PR(dmsg, "wh_lkup failed\n"); |
c2b27bf2 AM |
25230 | + goto out; |
25231 | + } | |
25232 | + | |
25233 | + err = 0; | |
5527c038 | 25234 | + if (d_is_positive(h_path.dentry)) { |
c2b27bf2 | 25235 | + h_path.mnt = au_br_mnt(br); |
523b37e3 | 25236 | + delegated = NULL; |
5527c038 | 25237 | + err = vfsub_unlink(d_inode(a->mvd_h_dst_parent), &h_path, |
523b37e3 AM |
25238 | + &delegated, /*force*/0); |
25239 | + if (unlikely(err == -EWOULDBLOCK)) { | |
25240 | + pr_warn("cannot retry for NFSv4 delegation" | |
25241 | + " for an internal unlink\n"); | |
25242 | + iput(delegated); | |
25243 | + } | |
c2b27bf2 | 25244 | + if (unlikely(err)) |
392086de | 25245 | + AU_MVD_PR(dmsg, "wh_unlink failed\n"); |
c2b27bf2 AM |
25246 | + } |
25247 | + dput(h_path.dentry); | |
25248 | + | |
25249 | +out: | |
25250 | + AuTraceErr(err); | |
25251 | + return err; | |
25252 | +} | |
25253 | + | |
25254 | +/* | |
25255 | + * unlink the topmost h_dentry | |
c2b27bf2 | 25256 | + */ |
392086de | 25257 | +static int au_do_unlink(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25258 | +{ |
25259 | + int err; | |
25260 | + struct path h_path; | |
523b37e3 | 25261 | + struct inode *delegated; |
c2b27bf2 AM |
25262 | + |
25263 | + h_path.mnt = au_sbr_mnt(a->sb, a->mvd_bsrc); | |
25264 | + h_path.dentry = au_h_dptr(a->dentry, a->mvd_bsrc); | |
523b37e3 AM |
25265 | + delegated = NULL; |
25266 | + err = vfsub_unlink(a->mvd_h_src_dir, &h_path, &delegated, /*force*/0); | |
25267 | + if (unlikely(err == -EWOULDBLOCK)) { | |
25268 | + pr_warn("cannot retry for NFSv4 delegation" | |
25269 | + " for an internal unlink\n"); | |
25270 | + iput(delegated); | |
25271 | + } | |
c2b27bf2 | 25272 | + if (unlikely(err)) |
392086de | 25273 | + AU_MVD_PR(dmsg, "unlink failed\n"); |
c2b27bf2 AM |
25274 | + |
25275 | + AuTraceErr(err); | |
25276 | + return err; | |
25277 | +} | |
25278 | + | |
076b876e AM |
25279 | +/* Since mvdown succeeded, we ignore an error of this function */ |
25280 | +static void au_do_stfs(const unsigned char dmsg, struct au_mvd_args *a) | |
25281 | +{ | |
25282 | + int err; | |
25283 | + struct au_branch *br; | |
25284 | + | |
25285 | + a->mvdown.flags |= AUFS_MVDOWN_STFS_FAILED; | |
25286 | + br = au_sbr(a->sb, a->mvd_bsrc); | |
25287 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_UPPER].stfs); | |
25288 | + if (!err) { | |
25289 | + br = au_sbr(a->sb, a->mvd_bdst); | |
25290 | + a->mvdown.stbr[AUFS_MVDOWN_LOWER].brid = br->br_id; | |
25291 | + err = au_br_stfs(br, &a->mvdown.stbr[AUFS_MVDOWN_LOWER].stfs); | |
25292 | + } | |
25293 | + if (!err) | |
25294 | + a->mvdown.flags &= ~AUFS_MVDOWN_STFS_FAILED; | |
25295 | + else | |
25296 | + AU_MVD_PR(dmsg, "statfs failed (%d), ignored\n", err); | |
25297 | +} | |
25298 | + | |
c2b27bf2 AM |
25299 | +/* |
25300 | + * copy-down the file and unlink the bsrc file. | |
25301 | + * - unlink the bdst whout if exist | |
25302 | + * - copy-down the file (with whtmp name and rename) | |
25303 | + * - unlink the bsrc file | |
25304 | + */ | |
392086de | 25305 | +static int au_do_mvdown(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25306 | +{ |
25307 | + int err; | |
25308 | + | |
392086de | 25309 | + err = au_do_mkdir(dmsg, a); |
c2b27bf2 | 25310 | + if (!err) |
392086de | 25311 | + err = au_do_lock(dmsg, a); |
c2b27bf2 AM |
25312 | + if (unlikely(err)) |
25313 | + goto out; | |
25314 | + | |
25315 | + /* | |
25316 | + * do not revert the activities we made on bdst since they should be | |
25317 | + * harmless in aufs. | |
25318 | + */ | |
25319 | + | |
392086de | 25320 | + err = au_do_cpdown(dmsg, a); |
c2b27bf2 | 25321 | + if (!err) |
392086de AM |
25322 | + err = au_do_unlink_wh(dmsg, a); |
25323 | + if (!err && !(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
25324 | + err = au_do_unlink(dmsg, a); | |
c2b27bf2 AM |
25325 | + if (unlikely(err)) |
25326 | + goto out_unlock; | |
25327 | + | |
c1595e42 JR |
25328 | + AuDbg("%pd2, 0x%x, %d --> %d\n", |
25329 | + a->dentry, a->mvdown.flags, a->mvd_bsrc, a->mvd_bdst); | |
076b876e AM |
25330 | + if (find_lower_writable(a) < 0) |
25331 | + a->mvdown.flags |= AUFS_MVDOWN_BOTTOM; | |
25332 | + | |
25333 | + if (a->mvdown.flags & AUFS_MVDOWN_STFS) | |
25334 | + au_do_stfs(dmsg, a); | |
25335 | + | |
c2b27bf2 | 25336 | + /* maintain internal array */ |
392086de AM |
25337 | + if (!(a->mvdown.flags & AUFS_MVDOWN_KUPPER)) { |
25338 | + au_set_h_dptr(a->dentry, a->mvd_bsrc, NULL); | |
5afbbe0d | 25339 | + au_set_dbtop(a->dentry, a->mvd_bdst); |
392086de | 25340 | + au_set_h_iptr(a->inode, a->mvd_bsrc, NULL, /*flags*/0); |
5afbbe0d | 25341 | + au_set_ibtop(a->inode, a->mvd_bdst); |
79b8bda9 AM |
25342 | + } else { |
25343 | + /* hide the lower */ | |
25344 | + au_set_h_dptr(a->dentry, a->mvd_bdst, NULL); | |
5afbbe0d | 25345 | + au_set_dbbot(a->dentry, a->mvd_bsrc); |
79b8bda9 | 25346 | + au_set_h_iptr(a->inode, a->mvd_bdst, NULL, /*flags*/0); |
5afbbe0d | 25347 | + au_set_ibbot(a->inode, a->mvd_bsrc); |
392086de | 25348 | + } |
5afbbe0d AM |
25349 | + if (au_dbbot(a->dentry) < a->mvd_bdst) |
25350 | + au_set_dbbot(a->dentry, a->mvd_bdst); | |
25351 | + if (au_ibbot(a->inode) < a->mvd_bdst) | |
25352 | + au_set_ibbot(a->inode, a->mvd_bdst); | |
c2b27bf2 AM |
25353 | + |
25354 | +out_unlock: | |
392086de | 25355 | + au_do_unlock(dmsg, a); |
c2b27bf2 AM |
25356 | +out: |
25357 | + AuTraceErr(err); | |
25358 | + return err; | |
25359 | +} | |
25360 | + | |
25361 | +/* ---------------------------------------------------------------------- */ | |
25362 | + | |
c2b27bf2 | 25363 | +/* make sure the file is idle */ |
392086de | 25364 | +static int au_mvd_args_busy(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25365 | +{ |
25366 | + int err, plinked; | |
c2b27bf2 AM |
25367 | + |
25368 | + err = 0; | |
c2b27bf2 | 25369 | + plinked = !!au_opt_test(au_mntflags(a->sb), PLINK); |
5afbbe0d | 25370 | + if (au_dbtop(a->dentry) == a->mvd_bsrc |
c1595e42 | 25371 | + && au_dcount(a->dentry) == 1 |
c2b27bf2 | 25372 | + && atomic_read(&a->inode->i_count) == 1 |
392086de | 25373 | + /* && a->mvd_h_src_inode->i_nlink == 1 */ |
c2b27bf2 AM |
25374 | + && (!plinked || !au_plink_test(a->inode)) |
25375 | + && a->inode->i_nlink == 1) | |
25376 | + goto out; | |
25377 | + | |
25378 | + err = -EBUSY; | |
392086de | 25379 | + AU_MVD_PR(dmsg, |
c1595e42 | 25380 | + "b%d, d{b%d, c%d?}, i{c%d?, l%u}, hi{l%u}, p{%d, %d}\n", |
5afbbe0d | 25381 | + a->mvd_bsrc, au_dbtop(a->dentry), au_dcount(a->dentry), |
c2b27bf2 | 25382 | + atomic_read(&a->inode->i_count), a->inode->i_nlink, |
392086de | 25383 | + a->mvd_h_src_inode->i_nlink, |
c2b27bf2 AM |
25384 | + plinked, plinked ? au_plink_test(a->inode) : 0); |
25385 | + | |
25386 | +out: | |
25387 | + AuTraceErr(err); | |
25388 | + return err; | |
25389 | +} | |
25390 | + | |
25391 | +/* make sure the parent dir is fine */ | |
392086de | 25392 | +static int au_mvd_args_parent(const unsigned char dmsg, |
c2b27bf2 AM |
25393 | + struct au_mvd_args *a) |
25394 | +{ | |
25395 | + int err; | |
25396 | + aufs_bindex_t bindex; | |
25397 | + | |
25398 | + err = 0; | |
25399 | + if (unlikely(au_alive_dir(a->parent))) { | |
25400 | + err = -ENOENT; | |
392086de | 25401 | + AU_MVD_PR(dmsg, "parent dir is dead\n"); |
c2b27bf2 AM |
25402 | + goto out; |
25403 | + } | |
25404 | + | |
25405 | + a->bopq = au_dbdiropq(a->parent); | |
25406 | + bindex = au_wbr_nonopq(a->dentry, a->mvd_bdst); | |
25407 | + AuDbg("b%d\n", bindex); | |
25408 | + if (unlikely((bindex >= 0 && bindex < a->mvd_bdst) | |
25409 | + || (a->bopq != -1 && a->bopq < a->mvd_bdst))) { | |
25410 | + err = -EINVAL; | |
392086de AM |
25411 | + a->mvd_errno = EAU_MVDOWN_OPAQUE; |
25412 | + AU_MVD_PR(dmsg, "ancestor is opaque b%d, b%d\n", | |
c2b27bf2 AM |
25413 | + a->bopq, a->mvd_bdst); |
25414 | + } | |
25415 | + | |
25416 | +out: | |
25417 | + AuTraceErr(err); | |
25418 | + return err; | |
25419 | +} | |
25420 | + | |
392086de | 25421 | +static int au_mvd_args_intermediate(const unsigned char dmsg, |
c2b27bf2 AM |
25422 | + struct au_mvd_args *a) |
25423 | +{ | |
25424 | + int err; | |
25425 | + struct au_dinfo *dinfo, *tmp; | |
25426 | + | |
25427 | + /* lookup the next lower positive entry */ | |
25428 | + err = -ENOMEM; | |
25429 | + tmp = au_di_alloc(a->sb, AuLsc_DI_TMP); | |
25430 | + if (unlikely(!tmp)) | |
25431 | + goto out; | |
25432 | + | |
25433 | + a->bfound = -1; | |
25434 | + a->bwh = -1; | |
25435 | + dinfo = au_di(a->dentry); | |
25436 | + au_di_cp(tmp, dinfo); | |
25437 | + au_di_swap(tmp, dinfo); | |
25438 | + | |
25439 | + /* returns the number of positive dentries */ | |
5afbbe0d AM |
25440 | + err = au_lkup_dentry(a->dentry, a->mvd_bsrc + 1, |
25441 | + /* AuLkup_IGNORE_PERM */ 0); | |
c2b27bf2 AM |
25442 | + if (!err) |
25443 | + a->bwh = au_dbwh(a->dentry); | |
25444 | + else if (err > 0) | |
5afbbe0d | 25445 | + a->bfound = au_dbtop(a->dentry); |
c2b27bf2 AM |
25446 | + |
25447 | + au_di_swap(tmp, dinfo); | |
25448 | + au_rw_write_unlock(&tmp->di_rwsem); | |
25449 | + au_di_free(tmp); | |
25450 | + if (unlikely(err < 0)) | |
392086de | 25451 | + AU_MVD_PR(dmsg, "failed look-up lower\n"); |
c2b27bf2 AM |
25452 | + |
25453 | + /* | |
25454 | + * here, we have these cases. | |
25455 | + * bfound == -1 | |
25456 | + * no positive dentry under bsrc. there are more sub-cases. | |
25457 | + * bwh < 0 | |
25458 | + * there no whiteout, we can safely move-down. | |
25459 | + * bwh <= bsrc | |
25460 | + * impossible | |
25461 | + * bsrc < bwh && bwh < bdst | |
25462 | + * there is a whiteout on RO branch. cannot proceed. | |
25463 | + * bwh == bdst | |
25464 | + * there is a whiteout on the RW target branch. it should | |
25465 | + * be removed. | |
25466 | + * bdst < bwh | |
25467 | + * there is a whiteout somewhere unrelated branch. | |
25468 | + * -1 < bfound && bfound <= bsrc | |
25469 | + * impossible. | |
25470 | + * bfound < bdst | |
25471 | + * found, but it is on RO branch between bsrc and bdst. cannot | |
25472 | + * proceed. | |
25473 | + * bfound == bdst | |
25474 | + * found, replace it if AUFS_MVDOWN_FORCE is set. otherwise return | |
25475 | + * error. | |
25476 | + * bdst < bfound | |
25477 | + * found, after we create the file on bdst, it will be hidden. | |
25478 | + */ | |
25479 | + | |
25480 | + AuDebugOn(a->bfound == -1 | |
25481 | + && a->bwh != -1 | |
25482 | + && a->bwh <= a->mvd_bsrc); | |
25483 | + AuDebugOn(-1 < a->bfound | |
25484 | + && a->bfound <= a->mvd_bsrc); | |
25485 | + | |
25486 | + err = -EINVAL; | |
25487 | + if (a->bfound == -1 | |
25488 | + && a->mvd_bsrc < a->bwh | |
25489 | + && a->bwh != -1 | |
25490 | + && a->bwh < a->mvd_bdst) { | |
392086de AM |
25491 | + a->mvd_errno = EAU_MVDOWN_WHITEOUT; |
25492 | + AU_MVD_PR(dmsg, "bsrc %d, bdst %d, bfound %d, bwh %d\n", | |
c2b27bf2 AM |
25493 | + a->mvd_bsrc, a->mvd_bdst, a->bfound, a->bwh); |
25494 | + goto out; | |
25495 | + } else if (a->bfound != -1 && a->bfound < a->mvd_bdst) { | |
392086de AM |
25496 | + a->mvd_errno = EAU_MVDOWN_UPPER; |
25497 | + AU_MVD_PR(dmsg, "bdst %d, bfound %d\n", | |
c2b27bf2 AM |
25498 | + a->mvd_bdst, a->bfound); |
25499 | + goto out; | |
25500 | + } | |
25501 | + | |
25502 | + err = 0; /* success */ | |
25503 | + | |
25504 | +out: | |
25505 | + AuTraceErr(err); | |
25506 | + return err; | |
25507 | +} | |
25508 | + | |
392086de | 25509 | +static int au_mvd_args_exist(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25510 | +{ |
25511 | + int err; | |
25512 | + | |
392086de AM |
25513 | + err = 0; |
25514 | + if (!(a->mvdown.flags & AUFS_MVDOWN_OWLOWER) | |
25515 | + && a->bfound == a->mvd_bdst) | |
25516 | + err = -EEXIST; | |
c2b27bf2 AM |
25517 | + AuTraceErr(err); |
25518 | + return err; | |
25519 | +} | |
25520 | + | |
392086de | 25521 | +static int au_mvd_args(const unsigned char dmsg, struct au_mvd_args *a) |
c2b27bf2 AM |
25522 | +{ |
25523 | + int err; | |
25524 | + struct au_branch *br; | |
25525 | + | |
25526 | + err = -EISDIR; | |
25527 | + if (unlikely(S_ISDIR(a->inode->i_mode))) | |
25528 | + goto out; | |
25529 | + | |
25530 | + err = -EINVAL; | |
392086de | 25531 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_UPPER)) |
5afbbe0d | 25532 | + a->mvd_bsrc = au_ibtop(a->inode); |
392086de AM |
25533 | + else { |
25534 | + a->mvd_bsrc = au_br_index(a->sb, a->mvd_src_brid); | |
25535 | + if (unlikely(a->mvd_bsrc < 0 | |
5afbbe0d AM |
25536 | + || (a->mvd_bsrc < au_dbtop(a->dentry) |
25537 | + || au_dbbot(a->dentry) < a->mvd_bsrc | |
392086de | 25538 | + || !au_h_dptr(a->dentry, a->mvd_bsrc)) |
5afbbe0d AM |
25539 | + || (a->mvd_bsrc < au_ibtop(a->inode) |
25540 | + || au_ibbot(a->inode) < a->mvd_bsrc | |
392086de AM |
25541 | + || !au_h_iptr(a->inode, a->mvd_bsrc)))) { |
25542 | + a->mvd_errno = EAU_MVDOWN_NOUPPER; | |
25543 | + AU_MVD_PR(dmsg, "no upper\n"); | |
25544 | + goto out; | |
25545 | + } | |
25546 | + } | |
5afbbe0d | 25547 | + if (unlikely(a->mvd_bsrc == au_sbbot(a->sb))) { |
392086de AM |
25548 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; |
25549 | + AU_MVD_PR(dmsg, "on the bottom\n"); | |
c2b27bf2 AM |
25550 | + goto out; |
25551 | + } | |
392086de | 25552 | + a->mvd_h_src_inode = au_h_iptr(a->inode, a->mvd_bsrc); |
c2b27bf2 AM |
25553 | + br = au_sbr(a->sb, a->mvd_bsrc); |
25554 | + err = au_br_rdonly(br); | |
392086de AM |
25555 | + if (!(a->mvdown.flags & AUFS_MVDOWN_ROUPPER)) { |
25556 | + if (unlikely(err)) | |
25557 | + goto out; | |
25558 | + } else if (!(vfsub_native_ro(a->mvd_h_src_inode) | |
25559 | + || IS_APPEND(a->mvd_h_src_inode))) { | |
25560 | + if (err) | |
25561 | + a->mvdown.flags |= AUFS_MVDOWN_ROUPPER_R; | |
25562 | + /* go on */ | |
25563 | + } else | |
c2b27bf2 AM |
25564 | + goto out; |
25565 | + | |
25566 | + err = -EINVAL; | |
392086de AM |
25567 | + if (!(a->mvdown.flags & AUFS_MVDOWN_BRID_LOWER)) { |
25568 | + a->mvd_bdst = find_lower_writable(a); | |
25569 | + if (unlikely(a->mvd_bdst < 0)) { | |
25570 | + a->mvd_errno = EAU_MVDOWN_BOTTOM; | |
25571 | + AU_MVD_PR(dmsg, "no writable lower branch\n"); | |
25572 | + goto out; | |
25573 | + } | |
25574 | + } else { | |
25575 | + a->mvd_bdst = au_br_index(a->sb, a->mvd_dst_brid); | |
25576 | + if (unlikely(a->mvd_bdst < 0 | |
5afbbe0d | 25577 | + || au_sbbot(a->sb) < a->mvd_bdst)) { |
392086de AM |
25578 | + a->mvd_errno = EAU_MVDOWN_NOLOWERBR; |
25579 | + AU_MVD_PR(dmsg, "no lower brid\n"); | |
25580 | + goto out; | |
25581 | + } | |
c2b27bf2 AM |
25582 | + } |
25583 | + | |
392086de | 25584 | + err = au_mvd_args_busy(dmsg, a); |
c2b27bf2 | 25585 | + if (!err) |
392086de | 25586 | + err = au_mvd_args_parent(dmsg, a); |
c2b27bf2 | 25587 | + if (!err) |
392086de | 25588 | + err = au_mvd_args_intermediate(dmsg, a); |
c2b27bf2 | 25589 | + if (!err) |
392086de | 25590 | + err = au_mvd_args_exist(dmsg, a); |
c2b27bf2 AM |
25591 | + if (!err) |
25592 | + AuDbg("b%d, b%d\n", a->mvd_bsrc, a->mvd_bdst); | |
25593 | + | |
25594 | +out: | |
25595 | + AuTraceErr(err); | |
25596 | + return err; | |
25597 | +} | |
25598 | + | |
25599 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *uarg) | |
25600 | +{ | |
392086de AM |
25601 | + int err, e; |
25602 | + unsigned char dmsg; | |
25603 | + struct au_mvd_args *args; | |
79b8bda9 | 25604 | + struct inode *inode; |
c2b27bf2 | 25605 | + |
79b8bda9 | 25606 | + inode = d_inode(dentry); |
c2b27bf2 AM |
25607 | + err = -EPERM; |
25608 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
25609 | + goto out; | |
25610 | + | |
392086de AM |
25611 | + err = -ENOMEM; |
25612 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
25613 | + if (unlikely(!args)) | |
25614 | + goto out; | |
25615 | + | |
25616 | + err = copy_from_user(&args->mvdown, uarg, sizeof(args->mvdown)); | |
25617 | + if (!err) | |
ba1aed25 AM |
25618 | + /* VERIFY_WRITE */ |
25619 | + err = !access_ok(uarg, sizeof(*uarg)); | |
c2b27bf2 AM |
25620 | + if (unlikely(err)) { |
25621 | + err = -EFAULT; | |
392086de AM |
25622 | + AuTraceErr(err); |
25623 | + goto out_free; | |
c2b27bf2 | 25624 | + } |
392086de AM |
25625 | + AuDbg("flags 0x%x\n", args->mvdown.flags); |
25626 | + args->mvdown.flags &= ~(AUFS_MVDOWN_ROLOWER_R | AUFS_MVDOWN_ROUPPER_R); | |
25627 | + args->mvdown.au_errno = 0; | |
25628 | + args->dentry = dentry; | |
79b8bda9 | 25629 | + args->inode = inode; |
392086de | 25630 | + args->sb = dentry->d_sb; |
c2b27bf2 | 25631 | + |
392086de AM |
25632 | + err = -ENOENT; |
25633 | + dmsg = !!(args->mvdown.flags & AUFS_MVDOWN_DMSG); | |
25634 | + args->parent = dget_parent(dentry); | |
5527c038 | 25635 | + args->dir = d_inode(args->parent); |
febd17d6 | 25636 | + inode_lock_nested(args->dir, I_MUTEX_PARENT); |
392086de AM |
25637 | + dput(args->parent); |
25638 | + if (unlikely(args->parent != dentry->d_parent)) { | |
25639 | + AU_MVD_PR(dmsg, "parent dir is moved\n"); | |
c2b27bf2 AM |
25640 | + goto out_dir; |
25641 | + } | |
25642 | + | |
febd17d6 | 25643 | + inode_lock_nested(inode, I_MUTEX_CHILD); |
b95c5147 | 25644 | + err = aufs_read_lock(dentry, AuLock_DW | AuLock_FLUSH | AuLock_NOPLMW); |
c2b27bf2 AM |
25645 | + if (unlikely(err)) |
25646 | + goto out_inode; | |
25647 | + | |
392086de AM |
25648 | + di_write_lock_parent(args->parent); |
25649 | + err = au_mvd_args(dmsg, args); | |
c2b27bf2 AM |
25650 | + if (unlikely(err)) |
25651 | + goto out_parent; | |
25652 | + | |
392086de | 25653 | + err = au_do_mvdown(dmsg, args); |
c2b27bf2 AM |
25654 | + if (unlikely(err)) |
25655 | + goto out_parent; | |
c2b27bf2 | 25656 | + |
392086de | 25657 | + au_cpup_attr_timesizes(args->dir); |
79b8bda9 AM |
25658 | + au_cpup_attr_timesizes(inode); |
25659 | + if (!(args->mvdown.flags & AUFS_MVDOWN_KUPPER)) | |
25660 | + au_cpup_igen(inode, au_h_iptr(inode, args->mvd_bdst)); | |
c2b27bf2 AM |
25661 | + /* au_digen_dec(dentry); */ |
25662 | + | |
25663 | +out_parent: | |
392086de | 25664 | + di_write_unlock(args->parent); |
c2b27bf2 AM |
25665 | + aufs_read_unlock(dentry, AuLock_DW); |
25666 | +out_inode: | |
febd17d6 | 25667 | + inode_unlock(inode); |
c2b27bf2 | 25668 | +out_dir: |
febd17d6 | 25669 | + inode_unlock(args->dir); |
392086de AM |
25670 | +out_free: |
25671 | + e = copy_to_user(uarg, &args->mvdown, sizeof(args->mvdown)); | |
25672 | + if (unlikely(e)) | |
25673 | + err = -EFAULT; | |
9f237c51 | 25674 | + au_kfree_rcu(args); |
c2b27bf2 AM |
25675 | +out: |
25676 | + AuTraceErr(err); | |
25677 | + return err; | |
25678 | +} | |
25679 | diff -urN /usr/share/empty/fs/aufs/opts.c linux/fs/aufs/opts.c | |
eca34b5c | 25680 | --- /usr/share/empty/fs/aufs/opts.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 25681 | +++ linux/fs/aufs/opts.c 2020-01-27 10:57:18.175538316 +0100 |
eca34b5c | 25682 | @@ -0,0 +1,1880 @@ |
cd7a4cd9 | 25683 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 25684 | +/* |
d58c55f2 | 25685 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 25686 | + * |
25687 | + * This program, aufs is free software; you can redistribute it and/or modify | |
25688 | + * it under the terms of the GNU General Public License as published by | |
25689 | + * the Free Software Foundation; either version 2 of the License, or | |
25690 | + * (at your option) any later version. | |
dece6358 AM |
25691 | + * |
25692 | + * This program is distributed in the hope that it will be useful, | |
25693 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
25694 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25695 | + * GNU General Public License for more details. | |
25696 | + * | |
25697 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 25698 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 25699 | + */ |
25700 | + | |
25701 | +/* | |
25702 | + * mount options/flags | |
25703 | + */ | |
25704 | + | |
dece6358 | 25705 | +#include <linux/namei.h> |
1facf9fc | 25706 | +#include <linux/types.h> /* a distribution requires */ |
25707 | +#include <linux/parser.h> | |
25708 | +#include "aufs.h" | |
25709 | + | |
25710 | +/* ---------------------------------------------------------------------- */ | |
25711 | + | |
25712 | +enum { | |
25713 | + Opt_br, | |
7e9cd9fe AM |
25714 | + Opt_add, Opt_del, Opt_mod, Opt_append, Opt_prepend, |
25715 | + Opt_idel, Opt_imod, | |
25716 | + Opt_dirwh, Opt_rdcache, Opt_rdblk, Opt_rdhash, | |
dece6358 | 25717 | + Opt_rdblk_def, Opt_rdhash_def, |
7e9cd9fe | 25718 | + Opt_xino, Opt_noxino, |
1facf9fc | 25719 | + Opt_trunc_xino, Opt_trunc_xino_v, Opt_notrunc_xino, |
25720 | + Opt_trunc_xino_path, Opt_itrunc_xino, | |
25721 | + Opt_trunc_xib, Opt_notrunc_xib, | |
dece6358 | 25722 | + Opt_shwh, Opt_noshwh, |
1facf9fc | 25723 | + Opt_plink, Opt_noplink, Opt_list_plink, |
25724 | + Opt_udba, | |
4a4d8108 | 25725 | + Opt_dio, Opt_nodio, |
1facf9fc | 25726 | + Opt_diropq_a, Opt_diropq_w, |
25727 | + Opt_warn_perm, Opt_nowarn_perm, | |
25728 | + Opt_wbr_copyup, Opt_wbr_create, | |
076b876e | 25729 | + Opt_fhsm_sec, |
1facf9fc | 25730 | + Opt_verbose, Opt_noverbose, |
25731 | + Opt_sum, Opt_nosum, Opt_wsum, | |
076b876e | 25732 | + Opt_dirperm1, Opt_nodirperm1, |
8b6a4947 | 25733 | + Opt_dirren, Opt_nodirren, |
c1595e42 | 25734 | + Opt_acl, Opt_noacl, |
1facf9fc | 25735 | + Opt_tail, Opt_ignore, Opt_ignore_silent, Opt_err |
25736 | +}; | |
25737 | + | |
25738 | +static match_table_t options = { | |
25739 | + {Opt_br, "br=%s"}, | |
25740 | + {Opt_br, "br:%s"}, | |
25741 | + | |
25742 | + {Opt_add, "add=%d:%s"}, | |
25743 | + {Opt_add, "add:%d:%s"}, | |
25744 | + {Opt_add, "ins=%d:%s"}, | |
25745 | + {Opt_add, "ins:%d:%s"}, | |
25746 | + {Opt_append, "append=%s"}, | |
25747 | + {Opt_append, "append:%s"}, | |
25748 | + {Opt_prepend, "prepend=%s"}, | |
25749 | + {Opt_prepend, "prepend:%s"}, | |
25750 | + | |
25751 | + {Opt_del, "del=%s"}, | |
25752 | + {Opt_del, "del:%s"}, | |
25753 | + /* {Opt_idel, "idel:%d"}, */ | |
25754 | + {Opt_mod, "mod=%s"}, | |
25755 | + {Opt_mod, "mod:%s"}, | |
25756 | + /* {Opt_imod, "imod:%d:%s"}, */ | |
25757 | + | |
25758 | + {Opt_dirwh, "dirwh=%d"}, | |
25759 | + | |
25760 | + {Opt_xino, "xino=%s"}, | |
25761 | + {Opt_noxino, "noxino"}, | |
25762 | + {Opt_trunc_xino, "trunc_xino"}, | |
25763 | + {Opt_trunc_xino_v, "trunc_xino_v=%d:%d"}, | |
25764 | + {Opt_notrunc_xino, "notrunc_xino"}, | |
25765 | + {Opt_trunc_xino_path, "trunc_xino=%s"}, | |
25766 | + {Opt_itrunc_xino, "itrunc_xino=%d"}, | |
25767 | + /* {Opt_zxino, "zxino=%s"}, */ | |
25768 | + {Opt_trunc_xib, "trunc_xib"}, | |
25769 | + {Opt_notrunc_xib, "notrunc_xib"}, | |
25770 | + | |
e49829fe | 25771 | +#ifdef CONFIG_PROC_FS |
1facf9fc | 25772 | + {Opt_plink, "plink"}, |
e49829fe JR |
25773 | +#else |
25774 | + {Opt_ignore_silent, "plink"}, | |
25775 | +#endif | |
25776 | + | |
1facf9fc | 25777 | + {Opt_noplink, "noplink"}, |
e49829fe | 25778 | + |
1facf9fc | 25779 | +#ifdef CONFIG_AUFS_DEBUG |
25780 | + {Opt_list_plink, "list_plink"}, | |
25781 | +#endif | |
25782 | + | |
25783 | + {Opt_udba, "udba=%s"}, | |
25784 | + | |
4a4d8108 AM |
25785 | + {Opt_dio, "dio"}, |
25786 | + {Opt_nodio, "nodio"}, | |
25787 | + | |
8b6a4947 AM |
25788 | +#ifdef CONFIG_AUFS_DIRREN |
25789 | + {Opt_dirren, "dirren"}, | |
25790 | + {Opt_nodirren, "nodirren"}, | |
25791 | +#else | |
25792 | + {Opt_ignore, "dirren"}, | |
25793 | + {Opt_ignore_silent, "nodirren"}, | |
25794 | +#endif | |
25795 | + | |
076b876e AM |
25796 | +#ifdef CONFIG_AUFS_FHSM |
25797 | + {Opt_fhsm_sec, "fhsm_sec=%d"}, | |
25798 | +#else | |
8b6a4947 | 25799 | + {Opt_ignore, "fhsm_sec=%d"}, |
076b876e AM |
25800 | +#endif |
25801 | + | |
1facf9fc | 25802 | + {Opt_diropq_a, "diropq=always"}, |
25803 | + {Opt_diropq_a, "diropq=a"}, | |
25804 | + {Opt_diropq_w, "diropq=whiteouted"}, | |
25805 | + {Opt_diropq_w, "diropq=w"}, | |
25806 | + | |
25807 | + {Opt_warn_perm, "warn_perm"}, | |
25808 | + {Opt_nowarn_perm, "nowarn_perm"}, | |
25809 | + | |
25810 | + /* keep them temporary */ | |
1facf9fc | 25811 | + {Opt_ignore_silent, "nodlgt"}, |
8b6a4947 | 25812 | + {Opt_ignore, "clean_plink"}, |
1facf9fc | 25813 | + |
dece6358 AM |
25814 | +#ifdef CONFIG_AUFS_SHWH |
25815 | + {Opt_shwh, "shwh"}, | |
25816 | +#endif | |
25817 | + {Opt_noshwh, "noshwh"}, | |
25818 | + | |
076b876e AM |
25819 | + {Opt_dirperm1, "dirperm1"}, |
25820 | + {Opt_nodirperm1, "nodirperm1"}, | |
25821 | + | |
1facf9fc | 25822 | + {Opt_verbose, "verbose"}, |
25823 | + {Opt_verbose, "v"}, | |
25824 | + {Opt_noverbose, "noverbose"}, | |
25825 | + {Opt_noverbose, "quiet"}, | |
25826 | + {Opt_noverbose, "q"}, | |
25827 | + {Opt_noverbose, "silent"}, | |
25828 | + | |
25829 | + {Opt_sum, "sum"}, | |
25830 | + {Opt_nosum, "nosum"}, | |
25831 | + {Opt_wsum, "wsum"}, | |
25832 | + | |
25833 | + {Opt_rdcache, "rdcache=%d"}, | |
25834 | + {Opt_rdblk, "rdblk=%d"}, | |
dece6358 | 25835 | + {Opt_rdblk_def, "rdblk=def"}, |
1facf9fc | 25836 | + {Opt_rdhash, "rdhash=%d"}, |
dece6358 | 25837 | + {Opt_rdhash_def, "rdhash=def"}, |
1facf9fc | 25838 | + |
25839 | + {Opt_wbr_create, "create=%s"}, | |
25840 | + {Opt_wbr_create, "create_policy=%s"}, | |
25841 | + {Opt_wbr_copyup, "cpup=%s"}, | |
25842 | + {Opt_wbr_copyup, "copyup=%s"}, | |
25843 | + {Opt_wbr_copyup, "copyup_policy=%s"}, | |
25844 | + | |
c1595e42 JR |
25845 | + /* generic VFS flag */ |
25846 | +#ifdef CONFIG_FS_POSIX_ACL | |
25847 | + {Opt_acl, "acl"}, | |
25848 | + {Opt_noacl, "noacl"}, | |
25849 | +#else | |
8b6a4947 | 25850 | + {Opt_ignore, "acl"}, |
c1595e42 JR |
25851 | + {Opt_ignore_silent, "noacl"}, |
25852 | +#endif | |
25853 | + | |
1facf9fc | 25854 | + /* internal use for the scripts */ |
25855 | + {Opt_ignore_silent, "si=%s"}, | |
25856 | + | |
25857 | + {Opt_br, "dirs=%s"}, | |
25858 | + {Opt_ignore, "debug=%d"}, | |
25859 | + {Opt_ignore, "delete=whiteout"}, | |
25860 | + {Opt_ignore, "delete=all"}, | |
25861 | + {Opt_ignore, "imap=%s"}, | |
25862 | + | |
1308ab2a | 25863 | + /* temporary workaround, due to old mount(8)? */ |
25864 | + {Opt_ignore_silent, "relatime"}, | |
25865 | + | |
1facf9fc | 25866 | + {Opt_err, NULL} |
25867 | +}; | |
25868 | + | |
25869 | +/* ---------------------------------------------------------------------- */ | |
25870 | + | |
076b876e | 25871 | +static const char *au_parser_pattern(int val, match_table_t tbl) |
1facf9fc | 25872 | +{ |
076b876e AM |
25873 | + struct match_token *p; |
25874 | + | |
25875 | + p = tbl; | |
25876 | + while (p->pattern) { | |
25877 | + if (p->token == val) | |
25878 | + return p->pattern; | |
25879 | + p++; | |
1facf9fc | 25880 | + } |
25881 | + BUG(); | |
25882 | + return "??"; | |
25883 | +} | |
25884 | + | |
076b876e AM |
25885 | +static const char *au_optstr(int *val, match_table_t tbl) |
25886 | +{ | |
25887 | + struct match_token *p; | |
25888 | + int v; | |
25889 | + | |
25890 | + v = *val; | |
2000de60 JR |
25891 | + if (!v) |
25892 | + goto out; | |
076b876e | 25893 | + p = tbl; |
2000de60 JR |
25894 | + while (p->pattern) { |
25895 | + if (p->token | |
25896 | + && (v & p->token) == p->token) { | |
076b876e AM |
25897 | + *val &= ~p->token; |
25898 | + return p->pattern; | |
25899 | + } | |
25900 | + p++; | |
25901 | + } | |
2000de60 JR |
25902 | + |
25903 | +out: | |
076b876e AM |
25904 | + return NULL; |
25905 | +} | |
25906 | + | |
1facf9fc | 25907 | +/* ---------------------------------------------------------------------- */ |
25908 | + | |
1e00d052 | 25909 | +static match_table_t brperm = { |
1facf9fc | 25910 | + {AuBrPerm_RO, AUFS_BRPERM_RO}, |
25911 | + {AuBrPerm_RR, AUFS_BRPERM_RR}, | |
25912 | + {AuBrPerm_RW, AUFS_BRPERM_RW}, | |
1e00d052 AM |
25913 | + {0, NULL} |
25914 | +}; | |
1facf9fc | 25915 | + |
86dc4139 | 25916 | +static match_table_t brattr = { |
076b876e AM |
25917 | + /* general */ |
25918 | + {AuBrAttr_COO_REG, AUFS_BRATTR_COO_REG}, | |
25919 | + {AuBrAttr_COO_ALL, AUFS_BRATTR_COO_ALL}, | |
c1595e42 | 25920 | + /* 'unpin' attrib is meaningless since linux-3.18-rc1 */ |
86dc4139 | 25921 | + {AuBrAttr_UNPIN, AUFS_BRATTR_UNPIN}, |
2000de60 | 25922 | +#ifdef CONFIG_AUFS_FHSM |
076b876e | 25923 | + {AuBrAttr_FHSM, AUFS_BRATTR_FHSM}, |
2000de60 JR |
25924 | +#endif |
25925 | +#ifdef CONFIG_AUFS_XATTR | |
c1595e42 JR |
25926 | + {AuBrAttr_ICEX, AUFS_BRATTR_ICEX}, |
25927 | + {AuBrAttr_ICEX_SEC, AUFS_BRATTR_ICEX_SEC}, | |
25928 | + {AuBrAttr_ICEX_SYS, AUFS_BRATTR_ICEX_SYS}, | |
25929 | + {AuBrAttr_ICEX_TR, AUFS_BRATTR_ICEX_TR}, | |
25930 | + {AuBrAttr_ICEX_USR, AUFS_BRATTR_ICEX_USR}, | |
25931 | + {AuBrAttr_ICEX_OTH, AUFS_BRATTR_ICEX_OTH}, | |
2000de60 | 25932 | +#endif |
076b876e AM |
25933 | + |
25934 | + /* ro/rr branch */ | |
1e00d052 | 25935 | + {AuBrRAttr_WH, AUFS_BRRATTR_WH}, |
076b876e AM |
25936 | + |
25937 | + /* rw branch */ | |
25938 | + {AuBrWAttr_MOO, AUFS_BRWATTR_MOO}, | |
1e00d052 | 25939 | + {AuBrWAttr_NoLinkWH, AUFS_BRWATTR_NLWH}, |
076b876e | 25940 | + |
1e00d052 | 25941 | + {0, NULL} |
1facf9fc | 25942 | +}; |
25943 | + | |
1e00d052 AM |
25944 | +static int br_attr_val(char *str, match_table_t table, substring_t args[]) |
25945 | +{ | |
25946 | + int attr, v; | |
25947 | + char *p; | |
25948 | + | |
25949 | + attr = 0; | |
25950 | + do { | |
25951 | + p = strchr(str, '+'); | |
25952 | + if (p) | |
25953 | + *p = 0; | |
25954 | + v = match_token(str, table, args); | |
076b876e AM |
25955 | + if (v) { |
25956 | + if (v & AuBrAttr_CMOO_Mask) | |
25957 | + attr &= ~AuBrAttr_CMOO_Mask; | |
1e00d052 | 25958 | + attr |= v; |
076b876e | 25959 | + } else { |
1e00d052 AM |
25960 | + if (p) |
25961 | + *p = '+'; | |
0c3ec466 | 25962 | + pr_warn("ignored branch attribute %s\n", str); |
1e00d052 AM |
25963 | + break; |
25964 | + } | |
25965 | + if (p) | |
25966 | + str = p + 1; | |
25967 | + } while (p); | |
25968 | + | |
25969 | + return attr; | |
25970 | +} | |
25971 | + | |
076b876e AM |
25972 | +static int au_do_optstr_br_attr(au_br_perm_str_t *str, int perm) |
25973 | +{ | |
25974 | + int sz; | |
25975 | + const char *p; | |
25976 | + char *q; | |
25977 | + | |
076b876e AM |
25978 | + q = str->a; |
25979 | + *q = 0; | |
25980 | + p = au_optstr(&perm, brattr); | |
25981 | + if (p) { | |
25982 | + sz = strlen(p); | |
25983 | + memcpy(q, p, sz + 1); | |
25984 | + q += sz; | |
25985 | + } else | |
25986 | + goto out; | |
25987 | + | |
25988 | + do { | |
25989 | + p = au_optstr(&perm, brattr); | |
25990 | + if (p) { | |
25991 | + *q++ = '+'; | |
25992 | + sz = strlen(p); | |
25993 | + memcpy(q, p, sz + 1); | |
25994 | + q += sz; | |
25995 | + } | |
25996 | + } while (p); | |
25997 | + | |
25998 | +out: | |
c1595e42 | 25999 | + return q - str->a; |
076b876e AM |
26000 | +} |
26001 | + | |
4a4d8108 | 26002 | +static int noinline_for_stack br_perm_val(char *perm) |
1facf9fc | 26003 | +{ |
076b876e AM |
26004 | + int val, bad, sz; |
26005 | + char *p; | |
1facf9fc | 26006 | + substring_t args[MAX_OPT_ARGS]; |
076b876e | 26007 | + au_br_perm_str_t attr; |
1facf9fc | 26008 | + |
1e00d052 AM |
26009 | + p = strchr(perm, '+'); |
26010 | + if (p) | |
26011 | + *p = 0; | |
26012 | + val = match_token(perm, brperm, args); | |
26013 | + if (!val) { | |
26014 | + if (p) | |
26015 | + *p = '+'; | |
0c3ec466 | 26016 | + pr_warn("ignored branch permission %s\n", perm); |
1e00d052 AM |
26017 | + val = AuBrPerm_RO; |
26018 | + goto out; | |
26019 | + } | |
26020 | + if (!p) | |
26021 | + goto out; | |
26022 | + | |
076b876e AM |
26023 | + val |= br_attr_val(p + 1, brattr, args); |
26024 | + | |
26025 | + bad = 0; | |
86dc4139 | 26026 | + switch (val & AuBrPerm_Mask) { |
1e00d052 AM |
26027 | + case AuBrPerm_RO: |
26028 | + case AuBrPerm_RR: | |
076b876e AM |
26029 | + bad = val & AuBrWAttr_Mask; |
26030 | + val &= ~AuBrWAttr_Mask; | |
1e00d052 AM |
26031 | + break; |
26032 | + case AuBrPerm_RW: | |
076b876e AM |
26033 | + bad = val & AuBrRAttr_Mask; |
26034 | + val &= ~AuBrRAttr_Mask; | |
1e00d052 AM |
26035 | + break; |
26036 | + } | |
c1595e42 JR |
26037 | + |
26038 | + /* | |
26039 | + * 'unpin' attrib becomes meaningless since linux-3.18-rc1, but aufs | |
26040 | + * does not treat it as an error, just warning. | |
26041 | + * this is a tiny guard for the user operation. | |
26042 | + */ | |
26043 | + if (val & AuBrAttr_UNPIN) { | |
26044 | + bad |= AuBrAttr_UNPIN; | |
26045 | + val &= ~AuBrAttr_UNPIN; | |
26046 | + } | |
26047 | + | |
076b876e AM |
26048 | + if (unlikely(bad)) { |
26049 | + sz = au_do_optstr_br_attr(&attr, bad); | |
26050 | + AuDebugOn(!sz); | |
26051 | + pr_warn("ignored branch attribute %s\n", attr.a); | |
26052 | + } | |
1e00d052 AM |
26053 | + |
26054 | +out: | |
1facf9fc | 26055 | + return val; |
26056 | +} | |
26057 | + | |
076b876e | 26058 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm) |
1facf9fc | 26059 | +{ |
076b876e AM |
26060 | + au_br_perm_str_t attr; |
26061 | + const char *p; | |
26062 | + char *q; | |
1e00d052 AM |
26063 | + int sz; |
26064 | + | |
076b876e AM |
26065 | + q = str->a; |
26066 | + p = au_optstr(&perm, brperm); | |
26067 | + AuDebugOn(!p || !*p); | |
26068 | + sz = strlen(p); | |
26069 | + memcpy(q, p, sz + 1); | |
26070 | + q += sz; | |
1e00d052 | 26071 | + |
076b876e AM |
26072 | + sz = au_do_optstr_br_attr(&attr, perm); |
26073 | + if (sz) { | |
26074 | + *q++ = '+'; | |
26075 | + memcpy(q, attr.a, sz + 1); | |
1e00d052 AM |
26076 | + } |
26077 | + | |
076b876e | 26078 | + AuDebugOn(strlen(str->a) >= sizeof(str->a)); |
1facf9fc | 26079 | +} |
26080 | + | |
26081 | +/* ---------------------------------------------------------------------- */ | |
26082 | + | |
26083 | +static match_table_t udbalevel = { | |
26084 | + {AuOpt_UDBA_REVAL, "reval"}, | |
26085 | + {AuOpt_UDBA_NONE, "none"}, | |
4a4d8108 AM |
26086 | +#ifdef CONFIG_AUFS_HNOTIFY |
26087 | + {AuOpt_UDBA_HNOTIFY, "notify"}, /* abstraction */ | |
26088 | +#ifdef CONFIG_AUFS_HFSNOTIFY | |
26089 | + {AuOpt_UDBA_HNOTIFY, "fsnotify"}, | |
4a4d8108 | 26090 | +#endif |
1facf9fc | 26091 | +#endif |
26092 | + {-1, NULL} | |
26093 | +}; | |
26094 | + | |
4a4d8108 | 26095 | +static int noinline_for_stack udba_val(char *str) |
1facf9fc | 26096 | +{ |
26097 | + substring_t args[MAX_OPT_ARGS]; | |
26098 | + | |
7f207e10 | 26099 | + return match_token(str, udbalevel, args); |
1facf9fc | 26100 | +} |
26101 | + | |
26102 | +const char *au_optstr_udba(int udba) | |
26103 | +{ | |
076b876e | 26104 | + return au_parser_pattern(udba, udbalevel); |
1facf9fc | 26105 | +} |
26106 | + | |
26107 | +/* ---------------------------------------------------------------------- */ | |
26108 | + | |
26109 | +static match_table_t au_wbr_create_policy = { | |
26110 | + {AuWbrCreate_TDP, "tdp"}, | |
26111 | + {AuWbrCreate_TDP, "top-down-parent"}, | |
26112 | + {AuWbrCreate_RR, "rr"}, | |
26113 | + {AuWbrCreate_RR, "round-robin"}, | |
26114 | + {AuWbrCreate_MFS, "mfs"}, | |
26115 | + {AuWbrCreate_MFS, "most-free-space"}, | |
26116 | + {AuWbrCreate_MFSV, "mfs:%d"}, | |
26117 | + {AuWbrCreate_MFSV, "most-free-space:%d"}, | |
26118 | + | |
f2c43d5f AM |
26119 | + /* top-down regardless the parent, and then mfs */ |
26120 | + {AuWbrCreate_TDMFS, "tdmfs:%d"}, | |
26121 | + {AuWbrCreate_TDMFSV, "tdmfs:%d:%d"}, | |
26122 | + | |
1facf9fc | 26123 | + {AuWbrCreate_MFSRR, "mfsrr:%d"}, |
26124 | + {AuWbrCreate_MFSRRV, "mfsrr:%d:%d"}, | |
26125 | + {AuWbrCreate_PMFS, "pmfs"}, | |
26126 | + {AuWbrCreate_PMFSV, "pmfs:%d"}, | |
392086de AM |
26127 | + {AuWbrCreate_PMFSRR, "pmfsrr:%d"}, |
26128 | + {AuWbrCreate_PMFSRRV, "pmfsrr:%d:%d"}, | |
1facf9fc | 26129 | + |
26130 | + {-1, NULL} | |
26131 | +}; | |
26132 | + | |
1facf9fc | 26133 | +static int au_wbr_mfs_wmark(substring_t *arg, char *str, |
26134 | + struct au_opt_wbr_create *create) | |
26135 | +{ | |
26136 | + int err; | |
26137 | + unsigned long long ull; | |
26138 | + | |
26139 | + err = 0; | |
a2654f78 | 26140 | + if (!match_u64(arg, &ull)) |
1facf9fc | 26141 | + create->mfsrr_watermark = ull; |
26142 | + else { | |
4a4d8108 | 26143 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 26144 | + err = -EINVAL; |
26145 | + } | |
26146 | + | |
26147 | + return err; | |
26148 | +} | |
26149 | + | |
26150 | +static int au_wbr_mfs_sec(substring_t *arg, char *str, | |
26151 | + struct au_opt_wbr_create *create) | |
26152 | +{ | |
26153 | + int n, err; | |
26154 | + | |
26155 | + err = 0; | |
027c5e7a | 26156 | + if (!match_int(arg, &n) && 0 <= n && n <= AUFS_MFS_MAX_SEC) |
1facf9fc | 26157 | + create->mfs_second = n; |
26158 | + else { | |
4a4d8108 | 26159 | + pr_err("bad integer in %s\n", str); |
1facf9fc | 26160 | + err = -EINVAL; |
26161 | + } | |
26162 | + | |
26163 | + return err; | |
26164 | +} | |
26165 | + | |
4a4d8108 AM |
26166 | +static int noinline_for_stack |
26167 | +au_wbr_create_val(char *str, struct au_opt_wbr_create *create) | |
1facf9fc | 26168 | +{ |
26169 | + int err, e; | |
26170 | + substring_t args[MAX_OPT_ARGS]; | |
26171 | + | |
26172 | + err = match_token(str, au_wbr_create_policy, args); | |
26173 | + create->wbr_create = err; | |
26174 | + switch (err) { | |
26175 | + case AuWbrCreate_MFSRRV: | |
f2c43d5f | 26176 | + case AuWbrCreate_TDMFSV: |
392086de | 26177 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 26178 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
26179 | + if (!e) | |
26180 | + e = au_wbr_mfs_sec(&args[1], str, create); | |
26181 | + if (unlikely(e)) | |
26182 | + err = e; | |
26183 | + break; | |
26184 | + case AuWbrCreate_MFSRR: | |
f2c43d5f | 26185 | + case AuWbrCreate_TDMFS: |
392086de | 26186 | + case AuWbrCreate_PMFSRR: |
1facf9fc | 26187 | + e = au_wbr_mfs_wmark(&args[0], str, create); |
26188 | + if (unlikely(e)) { | |
26189 | + err = e; | |
26190 | + break; | |
26191 | + } | |
26192 | + /*FALLTHROUGH*/ | |
26193 | + case AuWbrCreate_MFS: | |
26194 | + case AuWbrCreate_PMFS: | |
027c5e7a | 26195 | + create->mfs_second = AUFS_MFS_DEF_SEC; |
1facf9fc | 26196 | + break; |
26197 | + case AuWbrCreate_MFSV: | |
26198 | + case AuWbrCreate_PMFSV: | |
26199 | + e = au_wbr_mfs_sec(&args[0], str, create); | |
26200 | + if (unlikely(e)) | |
26201 | + err = e; | |
26202 | + break; | |
26203 | + } | |
26204 | + | |
26205 | + return err; | |
26206 | +} | |
26207 | + | |
26208 | +const char *au_optstr_wbr_create(int wbr_create) | |
26209 | +{ | |
076b876e | 26210 | + return au_parser_pattern(wbr_create, au_wbr_create_policy); |
1facf9fc | 26211 | +} |
26212 | + | |
26213 | +static match_table_t au_wbr_copyup_policy = { | |
26214 | + {AuWbrCopyup_TDP, "tdp"}, | |
26215 | + {AuWbrCopyup_TDP, "top-down-parent"}, | |
26216 | + {AuWbrCopyup_BUP, "bup"}, | |
26217 | + {AuWbrCopyup_BUP, "bottom-up-parent"}, | |
26218 | + {AuWbrCopyup_BU, "bu"}, | |
26219 | + {AuWbrCopyup_BU, "bottom-up"}, | |
26220 | + {-1, NULL} | |
26221 | +}; | |
26222 | + | |
4a4d8108 | 26223 | +static int noinline_for_stack au_wbr_copyup_val(char *str) |
1facf9fc | 26224 | +{ |
26225 | + substring_t args[MAX_OPT_ARGS]; | |
26226 | + | |
26227 | + return match_token(str, au_wbr_copyup_policy, args); | |
26228 | +} | |
26229 | + | |
26230 | +const char *au_optstr_wbr_copyup(int wbr_copyup) | |
26231 | +{ | |
076b876e | 26232 | + return au_parser_pattern(wbr_copyup, au_wbr_copyup_policy); |
1facf9fc | 26233 | +} |
26234 | + | |
26235 | +/* ---------------------------------------------------------------------- */ | |
26236 | + | |
26237 | +static const int lkup_dirflags = LOOKUP_FOLLOW | LOOKUP_DIRECTORY; | |
26238 | + | |
26239 | +static void dump_opts(struct au_opts *opts) | |
26240 | +{ | |
26241 | +#ifdef CONFIG_AUFS_DEBUG | |
26242 | + /* reduce stack space */ | |
26243 | + union { | |
26244 | + struct au_opt_add *add; | |
26245 | + struct au_opt_del *del; | |
26246 | + struct au_opt_mod *mod; | |
26247 | + struct au_opt_xino *xino; | |
26248 | + struct au_opt_xino_itrunc *xino_itrunc; | |
26249 | + struct au_opt_wbr_create *create; | |
26250 | + } u; | |
26251 | + struct au_opt *opt; | |
26252 | + | |
26253 | + opt = opts->opt; | |
26254 | + while (opt->type != Opt_tail) { | |
26255 | + switch (opt->type) { | |
26256 | + case Opt_add: | |
26257 | + u.add = &opt->add; | |
26258 | + AuDbg("add {b%d, %s, 0x%x, %p}\n", | |
26259 | + u.add->bindex, u.add->pathname, u.add->perm, | |
26260 | + u.add->path.dentry); | |
26261 | + break; | |
26262 | + case Opt_del: | |
26263 | + case Opt_idel: | |
26264 | + u.del = &opt->del; | |
26265 | + AuDbg("del {%s, %p}\n", | |
26266 | + u.del->pathname, u.del->h_path.dentry); | |
26267 | + break; | |
26268 | + case Opt_mod: | |
26269 | + case Opt_imod: | |
26270 | + u.mod = &opt->mod; | |
26271 | + AuDbg("mod {%s, 0x%x, %p}\n", | |
26272 | + u.mod->path, u.mod->perm, u.mod->h_root); | |
26273 | + break; | |
26274 | + case Opt_append: | |
26275 | + u.add = &opt->add; | |
26276 | + AuDbg("append {b%d, %s, 0x%x, %p}\n", | |
26277 | + u.add->bindex, u.add->pathname, u.add->perm, | |
26278 | + u.add->path.dentry); | |
26279 | + break; | |
26280 | + case Opt_prepend: | |
26281 | + u.add = &opt->add; | |
26282 | + AuDbg("prepend {b%d, %s, 0x%x, %p}\n", | |
26283 | + u.add->bindex, u.add->pathname, u.add->perm, | |
26284 | + u.add->path.dentry); | |
26285 | + break; | |
26286 | + case Opt_dirwh: | |
26287 | + AuDbg("dirwh %d\n", opt->dirwh); | |
26288 | + break; | |
26289 | + case Opt_rdcache: | |
26290 | + AuDbg("rdcache %d\n", opt->rdcache); | |
26291 | + break; | |
26292 | + case Opt_rdblk: | |
26293 | + AuDbg("rdblk %u\n", opt->rdblk); | |
26294 | + break; | |
dece6358 AM |
26295 | + case Opt_rdblk_def: |
26296 | + AuDbg("rdblk_def\n"); | |
26297 | + break; | |
1facf9fc | 26298 | + case Opt_rdhash: |
26299 | + AuDbg("rdhash %u\n", opt->rdhash); | |
26300 | + break; | |
dece6358 AM |
26301 | + case Opt_rdhash_def: |
26302 | + AuDbg("rdhash_def\n"); | |
26303 | + break; | |
1facf9fc | 26304 | + case Opt_xino: |
26305 | + u.xino = &opt->xino; | |
523b37e3 | 26306 | + AuDbg("xino {%s %pD}\n", u.xino->path, u.xino->file); |
1facf9fc | 26307 | + break; |
26308 | + case Opt_trunc_xino: | |
26309 | + AuLabel(trunc_xino); | |
26310 | + break; | |
26311 | + case Opt_notrunc_xino: | |
26312 | + AuLabel(notrunc_xino); | |
26313 | + break; | |
26314 | + case Opt_trunc_xino_path: | |
26315 | + case Opt_itrunc_xino: | |
26316 | + u.xino_itrunc = &opt->xino_itrunc; | |
26317 | + AuDbg("trunc_xino %d\n", u.xino_itrunc->bindex); | |
26318 | + break; | |
1facf9fc | 26319 | + case Opt_noxino: |
26320 | + AuLabel(noxino); | |
26321 | + break; | |
26322 | + case Opt_trunc_xib: | |
26323 | + AuLabel(trunc_xib); | |
26324 | + break; | |
26325 | + case Opt_notrunc_xib: | |
26326 | + AuLabel(notrunc_xib); | |
26327 | + break; | |
dece6358 AM |
26328 | + case Opt_shwh: |
26329 | + AuLabel(shwh); | |
26330 | + break; | |
26331 | + case Opt_noshwh: | |
26332 | + AuLabel(noshwh); | |
26333 | + break; | |
076b876e AM |
26334 | + case Opt_dirperm1: |
26335 | + AuLabel(dirperm1); | |
26336 | + break; | |
26337 | + case Opt_nodirperm1: | |
26338 | + AuLabel(nodirperm1); | |
26339 | + break; | |
1facf9fc | 26340 | + case Opt_plink: |
26341 | + AuLabel(plink); | |
26342 | + break; | |
26343 | + case Opt_noplink: | |
26344 | + AuLabel(noplink); | |
26345 | + break; | |
26346 | + case Opt_list_plink: | |
26347 | + AuLabel(list_plink); | |
26348 | + break; | |
26349 | + case Opt_udba: | |
26350 | + AuDbg("udba %d, %s\n", | |
26351 | + opt->udba, au_optstr_udba(opt->udba)); | |
26352 | + break; | |
4a4d8108 AM |
26353 | + case Opt_dio: |
26354 | + AuLabel(dio); | |
26355 | + break; | |
26356 | + case Opt_nodio: | |
26357 | + AuLabel(nodio); | |
26358 | + break; | |
1facf9fc | 26359 | + case Opt_diropq_a: |
26360 | + AuLabel(diropq_a); | |
26361 | + break; | |
26362 | + case Opt_diropq_w: | |
26363 | + AuLabel(diropq_w); | |
26364 | + break; | |
26365 | + case Opt_warn_perm: | |
26366 | + AuLabel(warn_perm); | |
26367 | + break; | |
26368 | + case Opt_nowarn_perm: | |
26369 | + AuLabel(nowarn_perm); | |
26370 | + break; | |
1facf9fc | 26371 | + case Opt_verbose: |
26372 | + AuLabel(verbose); | |
26373 | + break; | |
26374 | + case Opt_noverbose: | |
26375 | + AuLabel(noverbose); | |
26376 | + break; | |
26377 | + case Opt_sum: | |
26378 | + AuLabel(sum); | |
26379 | + break; | |
26380 | + case Opt_nosum: | |
26381 | + AuLabel(nosum); | |
26382 | + break; | |
26383 | + case Opt_wsum: | |
26384 | + AuLabel(wsum); | |
26385 | + break; | |
26386 | + case Opt_wbr_create: | |
26387 | + u.create = &opt->wbr_create; | |
26388 | + AuDbg("create %d, %s\n", u.create->wbr_create, | |
26389 | + au_optstr_wbr_create(u.create->wbr_create)); | |
26390 | + switch (u.create->wbr_create) { | |
26391 | + case AuWbrCreate_MFSV: | |
26392 | + case AuWbrCreate_PMFSV: | |
26393 | + AuDbg("%d sec\n", u.create->mfs_second); | |
26394 | + break; | |
26395 | + case AuWbrCreate_MFSRR: | |
f2c43d5f | 26396 | + case AuWbrCreate_TDMFS: |
1facf9fc | 26397 | + AuDbg("%llu watermark\n", |
26398 | + u.create->mfsrr_watermark); | |
26399 | + break; | |
26400 | + case AuWbrCreate_MFSRRV: | |
f2c43d5f | 26401 | + case AuWbrCreate_TDMFSV: |
392086de | 26402 | + case AuWbrCreate_PMFSRRV: |
1facf9fc | 26403 | + AuDbg("%llu watermark, %d sec\n", |
26404 | + u.create->mfsrr_watermark, | |
26405 | + u.create->mfs_second); | |
26406 | + break; | |
26407 | + } | |
26408 | + break; | |
26409 | + case Opt_wbr_copyup: | |
26410 | + AuDbg("copyup %d, %s\n", opt->wbr_copyup, | |
26411 | + au_optstr_wbr_copyup(opt->wbr_copyup)); | |
26412 | + break; | |
076b876e AM |
26413 | + case Opt_fhsm_sec: |
26414 | + AuDbg("fhsm_sec %u\n", opt->fhsm_second); | |
26415 | + break; | |
8b6a4947 AM |
26416 | + case Opt_dirren: |
26417 | + AuLabel(dirren); | |
26418 | + break; | |
26419 | + case Opt_nodirren: | |
26420 | + AuLabel(nodirren); | |
26421 | + break; | |
c1595e42 JR |
26422 | + case Opt_acl: |
26423 | + AuLabel(acl); | |
26424 | + break; | |
26425 | + case Opt_noacl: | |
26426 | + AuLabel(noacl); | |
26427 | + break; | |
1facf9fc | 26428 | + default: |
26429 | + BUG(); | |
26430 | + } | |
26431 | + opt++; | |
26432 | + } | |
26433 | +#endif | |
26434 | +} | |
26435 | + | |
26436 | +void au_opts_free(struct au_opts *opts) | |
26437 | +{ | |
26438 | + struct au_opt *opt; | |
26439 | + | |
26440 | + opt = opts->opt; | |
26441 | + while (opt->type != Opt_tail) { | |
26442 | + switch (opt->type) { | |
26443 | + case Opt_add: | |
26444 | + case Opt_append: | |
26445 | + case Opt_prepend: | |
26446 | + path_put(&opt->add.path); | |
26447 | + break; | |
26448 | + case Opt_del: | |
26449 | + case Opt_idel: | |
26450 | + path_put(&opt->del.h_path); | |
26451 | + break; | |
26452 | + case Opt_mod: | |
26453 | + case Opt_imod: | |
26454 | + dput(opt->mod.h_root); | |
26455 | + break; | |
26456 | + case Opt_xino: | |
26457 | + fput(opt->xino.file); | |
26458 | + break; | |
26459 | + } | |
26460 | + opt++; | |
26461 | + } | |
26462 | +} | |
26463 | + | |
26464 | +static int opt_add(struct au_opt *opt, char *opt_str, unsigned long sb_flags, | |
26465 | + aufs_bindex_t bindex) | |
26466 | +{ | |
26467 | + int err; | |
26468 | + struct au_opt_add *add = &opt->add; | |
26469 | + char *p; | |
26470 | + | |
26471 | + add->bindex = bindex; | |
1e00d052 | 26472 | + add->perm = AuBrPerm_RO; |
1facf9fc | 26473 | + add->pathname = opt_str; |
26474 | + p = strchr(opt_str, '='); | |
26475 | + if (p) { | |
26476 | + *p++ = 0; | |
26477 | + if (*p) | |
26478 | + add->perm = br_perm_val(p); | |
26479 | + } | |
26480 | + | |
26481 | + err = vfsub_kern_path(add->pathname, lkup_dirflags, &add->path); | |
26482 | + if (!err) { | |
26483 | + if (!p) { | |
26484 | + add->perm = AuBrPerm_RO; | |
26485 | + if (au_test_fs_rr(add->path.dentry->d_sb)) | |
26486 | + add->perm = AuBrPerm_RR; | |
2121bcd9 | 26487 | + else if (!bindex && !(sb_flags & SB_RDONLY)) |
1facf9fc | 26488 | + add->perm = AuBrPerm_RW; |
26489 | + } | |
26490 | + opt->type = Opt_add; | |
26491 | + goto out; | |
26492 | + } | |
4a4d8108 | 26493 | + pr_err("lookup failed %s (%d)\n", add->pathname, err); |
1facf9fc | 26494 | + err = -EINVAL; |
26495 | + | |
4f0767ce | 26496 | +out: |
1facf9fc | 26497 | + return err; |
26498 | +} | |
26499 | + | |
26500 | +static int au_opts_parse_del(struct au_opt_del *del, substring_t args[]) | |
26501 | +{ | |
26502 | + int err; | |
26503 | + | |
26504 | + del->pathname = args[0].from; | |
26505 | + AuDbg("del path %s\n", del->pathname); | |
26506 | + | |
26507 | + err = vfsub_kern_path(del->pathname, lkup_dirflags, &del->h_path); | |
26508 | + if (unlikely(err)) | |
4a4d8108 | 26509 | + pr_err("lookup failed %s (%d)\n", del->pathname, err); |
1facf9fc | 26510 | + |
26511 | + return err; | |
26512 | +} | |
26513 | + | |
26514 | +#if 0 /* reserved for future use */ | |
26515 | +static int au_opts_parse_idel(struct super_block *sb, aufs_bindex_t bindex, | |
26516 | + struct au_opt_del *del, substring_t args[]) | |
26517 | +{ | |
26518 | + int err; | |
26519 | + struct dentry *root; | |
26520 | + | |
26521 | + err = -EINVAL; | |
26522 | + root = sb->s_root; | |
26523 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 26524 | + if (bindex < 0 || au_sbbot(sb) < bindex) { |
4a4d8108 | 26525 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 26526 | + goto out; |
26527 | + } | |
26528 | + | |
26529 | + err = 0; | |
26530 | + del->h_path.dentry = dget(au_h_dptr(root, bindex)); | |
26531 | + del->h_path.mnt = mntget(au_sbr_mnt(sb, bindex)); | |
26532 | + | |
4f0767ce | 26533 | +out: |
1facf9fc | 26534 | + aufs_read_unlock(root, !AuLock_IR); |
26535 | + return err; | |
26536 | +} | |
26537 | +#endif | |
26538 | + | |
4a4d8108 AM |
26539 | +static int noinline_for_stack |
26540 | +au_opts_parse_mod(struct au_opt_mod *mod, substring_t args[]) | |
1facf9fc | 26541 | +{ |
26542 | + int err; | |
26543 | + struct path path; | |
26544 | + char *p; | |
26545 | + | |
26546 | + err = -EINVAL; | |
26547 | + mod->path = args[0].from; | |
26548 | + p = strchr(mod->path, '='); | |
26549 | + if (unlikely(!p)) { | |
acd2b654 | 26550 | + pr_err("no permission %s\n", args[0].from); |
1facf9fc | 26551 | + goto out; |
26552 | + } | |
26553 | + | |
26554 | + *p++ = 0; | |
26555 | + err = vfsub_kern_path(mod->path, lkup_dirflags, &path); | |
26556 | + if (unlikely(err)) { | |
4a4d8108 | 26557 | + pr_err("lookup failed %s (%d)\n", mod->path, err); |
1facf9fc | 26558 | + goto out; |
26559 | + } | |
26560 | + | |
26561 | + mod->perm = br_perm_val(p); | |
26562 | + AuDbg("mod path %s, perm 0x%x, %s\n", mod->path, mod->perm, p); | |
26563 | + mod->h_root = dget(path.dentry); | |
26564 | + path_put(&path); | |
26565 | + | |
4f0767ce | 26566 | +out: |
1facf9fc | 26567 | + return err; |
26568 | +} | |
26569 | + | |
26570 | +#if 0 /* reserved for future use */ | |
26571 | +static int au_opts_parse_imod(struct super_block *sb, aufs_bindex_t bindex, | |
26572 | + struct au_opt_mod *mod, substring_t args[]) | |
26573 | +{ | |
26574 | + int err; | |
26575 | + struct dentry *root; | |
26576 | + | |
26577 | + err = -EINVAL; | |
26578 | + root = sb->s_root; | |
26579 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 26580 | + if (bindex < 0 || au_sbbot(sb) < bindex) { |
4a4d8108 | 26581 | + pr_err("out of bounds, %d\n", bindex); |
1facf9fc | 26582 | + goto out; |
26583 | + } | |
26584 | + | |
26585 | + err = 0; | |
26586 | + mod->perm = br_perm_val(args[1].from); | |
26587 | + AuDbg("mod path %s, perm 0x%x, %s\n", | |
26588 | + mod->path, mod->perm, args[1].from); | |
26589 | + mod->h_root = dget(au_h_dptr(root, bindex)); | |
26590 | + | |
4f0767ce | 26591 | +out: |
1facf9fc | 26592 | + aufs_read_unlock(root, !AuLock_IR); |
26593 | + return err; | |
26594 | +} | |
26595 | +#endif | |
26596 | + | |
26597 | +static int au_opts_parse_xino(struct super_block *sb, struct au_opt_xino *xino, | |
26598 | + substring_t args[]) | |
26599 | +{ | |
26600 | + int err; | |
26601 | + struct file *file; | |
26602 | + | |
83b672a5 | 26603 | + file = au_xino_create(sb, args[0].from, /*silent*/0, /*wbrtop*/0); |
1facf9fc | 26604 | + err = PTR_ERR(file); |
26605 | + if (IS_ERR(file)) | |
26606 | + goto out; | |
26607 | + | |
26608 | + err = -EINVAL; | |
2000de60 | 26609 | + if (unlikely(file->f_path.dentry->d_sb == sb)) { |
1facf9fc | 26610 | + fput(file); |
4a4d8108 | 26611 | + pr_err("%s must be outside\n", args[0].from); |
1facf9fc | 26612 | + goto out; |
26613 | + } | |
26614 | + | |
26615 | + err = 0; | |
26616 | + xino->file = file; | |
26617 | + xino->path = args[0].from; | |
26618 | + | |
4f0767ce | 26619 | +out: |
1facf9fc | 26620 | + return err; |
26621 | +} | |
26622 | + | |
4a4d8108 AM |
26623 | +static int noinline_for_stack |
26624 | +au_opts_parse_xino_itrunc_path(struct super_block *sb, | |
26625 | + struct au_opt_xino_itrunc *xino_itrunc, | |
26626 | + substring_t args[]) | |
1facf9fc | 26627 | +{ |
26628 | + int err; | |
5afbbe0d | 26629 | + aufs_bindex_t bbot, bindex; |
1facf9fc | 26630 | + struct path path; |
26631 | + struct dentry *root; | |
26632 | + | |
26633 | + err = vfsub_kern_path(args[0].from, lkup_dirflags, &path); | |
26634 | + if (unlikely(err)) { | |
4a4d8108 | 26635 | + pr_err("lookup failed %s (%d)\n", args[0].from, err); |
1facf9fc | 26636 | + goto out; |
26637 | + } | |
26638 | + | |
26639 | + xino_itrunc->bindex = -1; | |
26640 | + root = sb->s_root; | |
26641 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d AM |
26642 | + bbot = au_sbbot(sb); |
26643 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
1facf9fc | 26644 | + if (au_h_dptr(root, bindex) == path.dentry) { |
26645 | + xino_itrunc->bindex = bindex; | |
26646 | + break; | |
26647 | + } | |
26648 | + } | |
26649 | + aufs_read_unlock(root, !AuLock_IR); | |
26650 | + path_put(&path); | |
26651 | + | |
26652 | + if (unlikely(xino_itrunc->bindex < 0)) { | |
4a4d8108 | 26653 | + pr_err("no such branch %s\n", args[0].from); |
1facf9fc | 26654 | + err = -EINVAL; |
26655 | + } | |
26656 | + | |
4f0767ce | 26657 | +out: |
1facf9fc | 26658 | + return err; |
26659 | +} | |
26660 | + | |
26661 | +/* called without aufs lock */ | |
26662 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts) | |
26663 | +{ | |
26664 | + int err, n, token; | |
26665 | + aufs_bindex_t bindex; | |
26666 | + unsigned char skipped; | |
26667 | + struct dentry *root; | |
26668 | + struct au_opt *opt, *opt_tail; | |
26669 | + char *opt_str; | |
26670 | + /* reduce the stack space */ | |
26671 | + union { | |
26672 | + struct au_opt_xino_itrunc *xino_itrunc; | |
26673 | + struct au_opt_wbr_create *create; | |
26674 | + } u; | |
26675 | + struct { | |
26676 | + substring_t args[MAX_OPT_ARGS]; | |
26677 | + } *a; | |
26678 | + | |
26679 | + err = -ENOMEM; | |
26680 | + a = kmalloc(sizeof(*a), GFP_NOFS); | |
26681 | + if (unlikely(!a)) | |
26682 | + goto out; | |
26683 | + | |
26684 | + root = sb->s_root; | |
26685 | + err = 0; | |
26686 | + bindex = 0; | |
26687 | + opt = opts->opt; | |
26688 | + opt_tail = opt + opts->max_opt - 1; | |
26689 | + opt->type = Opt_tail; | |
26690 | + while (!err && (opt_str = strsep(&str, ",")) && *opt_str) { | |
26691 | + err = -EINVAL; | |
26692 | + skipped = 0; | |
26693 | + token = match_token(opt_str, options, a->args); | |
26694 | + switch (token) { | |
26695 | + case Opt_br: | |
26696 | + err = 0; | |
26697 | + while (!err && (opt_str = strsep(&a->args[0].from, ":")) | |
26698 | + && *opt_str) { | |
26699 | + err = opt_add(opt, opt_str, opts->sb_flags, | |
26700 | + bindex++); | |
26701 | + if (unlikely(!err && ++opt > opt_tail)) { | |
26702 | + err = -E2BIG; | |
26703 | + break; | |
26704 | + } | |
26705 | + opt->type = Opt_tail; | |
26706 | + skipped = 1; | |
26707 | + } | |
26708 | + break; | |
26709 | + case Opt_add: | |
26710 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 26711 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26712 | + break; |
26713 | + } | |
26714 | + bindex = n; | |
26715 | + err = opt_add(opt, a->args[1].from, opts->sb_flags, | |
26716 | + bindex); | |
26717 | + if (!err) | |
26718 | + opt->type = token; | |
26719 | + break; | |
26720 | + case Opt_append: | |
26721 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
26722 | + /*dummy bindex*/1); | |
26723 | + if (!err) | |
26724 | + opt->type = token; | |
26725 | + break; | |
26726 | + case Opt_prepend: | |
26727 | + err = opt_add(opt, a->args[0].from, opts->sb_flags, | |
26728 | + /*bindex*/0); | |
26729 | + if (!err) | |
26730 | + opt->type = token; | |
26731 | + break; | |
26732 | + case Opt_del: | |
26733 | + err = au_opts_parse_del(&opt->del, a->args); | |
26734 | + if (!err) | |
26735 | + opt->type = token; | |
26736 | + break; | |
26737 | +#if 0 /* reserved for future use */ | |
26738 | + case Opt_idel: | |
26739 | + del->pathname = "(indexed)"; | |
26740 | + if (unlikely(match_int(&args[0], &n))) { | |
4a4d8108 | 26741 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26742 | + break; |
26743 | + } | |
26744 | + err = au_opts_parse_idel(sb, n, &opt->del, a->args); | |
26745 | + if (!err) | |
26746 | + opt->type = token; | |
26747 | + break; | |
26748 | +#endif | |
26749 | + case Opt_mod: | |
26750 | + err = au_opts_parse_mod(&opt->mod, a->args); | |
26751 | + if (!err) | |
26752 | + opt->type = token; | |
26753 | + break; | |
26754 | +#ifdef IMOD /* reserved for future use */ | |
26755 | + case Opt_imod: | |
26756 | + u.mod->path = "(indexed)"; | |
26757 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 26758 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26759 | + break; |
26760 | + } | |
26761 | + err = au_opts_parse_imod(sb, n, &opt->mod, a->args); | |
26762 | + if (!err) | |
26763 | + opt->type = token; | |
26764 | + break; | |
26765 | +#endif | |
26766 | + case Opt_xino: | |
26767 | + err = au_opts_parse_xino(sb, &opt->xino, a->args); | |
26768 | + if (!err) | |
26769 | + opt->type = token; | |
26770 | + break; | |
26771 | + | |
26772 | + case Opt_trunc_xino_path: | |
26773 | + err = au_opts_parse_xino_itrunc_path | |
26774 | + (sb, &opt->xino_itrunc, a->args); | |
26775 | + if (!err) | |
26776 | + opt->type = token; | |
26777 | + break; | |
26778 | + | |
26779 | + case Opt_itrunc_xino: | |
26780 | + u.xino_itrunc = &opt->xino_itrunc; | |
26781 | + if (unlikely(match_int(&a->args[0], &n))) { | |
4a4d8108 | 26782 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26783 | + break; |
26784 | + } | |
26785 | + u.xino_itrunc->bindex = n; | |
26786 | + aufs_read_lock(root, AuLock_FLUSH); | |
5afbbe0d | 26787 | + if (n < 0 || au_sbbot(sb) < n) { |
4a4d8108 | 26788 | + pr_err("out of bounds, %d\n", n); |
1facf9fc | 26789 | + aufs_read_unlock(root, !AuLock_IR); |
26790 | + break; | |
26791 | + } | |
26792 | + aufs_read_unlock(root, !AuLock_IR); | |
26793 | + err = 0; | |
26794 | + opt->type = token; | |
26795 | + break; | |
26796 | + | |
26797 | + case Opt_dirwh: | |
26798 | + if (unlikely(match_int(&a->args[0], &opt->dirwh))) | |
26799 | + break; | |
26800 | + err = 0; | |
26801 | + opt->type = token; | |
26802 | + break; | |
26803 | + | |
26804 | + case Opt_rdcache: | |
027c5e7a AM |
26805 | + if (unlikely(match_int(&a->args[0], &n))) { |
26806 | + pr_err("bad integer in %s\n", opt_str); | |
1facf9fc | 26807 | + break; |
027c5e7a AM |
26808 | + } |
26809 | + if (unlikely(n > AUFS_RDCACHE_MAX)) { | |
26810 | + pr_err("rdcache must be smaller than %d\n", | |
26811 | + AUFS_RDCACHE_MAX); | |
26812 | + break; | |
26813 | + } | |
26814 | + opt->rdcache = n; | |
1facf9fc | 26815 | + err = 0; |
26816 | + opt->type = token; | |
26817 | + break; | |
26818 | + case Opt_rdblk: | |
26819 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 26820 | + || n < 0 |
1facf9fc | 26821 | + || n > KMALLOC_MAX_SIZE)) { |
4a4d8108 | 26822 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26823 | + break; |
26824 | + } | |
1308ab2a | 26825 | + if (unlikely(n && n < NAME_MAX)) { |
4a4d8108 AM |
26826 | + pr_err("rdblk must be larger than %d\n", |
26827 | + NAME_MAX); | |
1facf9fc | 26828 | + break; |
26829 | + } | |
26830 | + opt->rdblk = n; | |
26831 | + err = 0; | |
26832 | + opt->type = token; | |
26833 | + break; | |
26834 | + case Opt_rdhash: | |
26835 | + if (unlikely(match_int(&a->args[0], &n) | |
1308ab2a | 26836 | + || n < 0 |
1facf9fc | 26837 | + || n * sizeof(struct hlist_head) |
26838 | + > KMALLOC_MAX_SIZE)) { | |
4a4d8108 | 26839 | + pr_err("bad integer in %s\n", opt_str); |
1facf9fc | 26840 | + break; |
26841 | + } | |
26842 | + opt->rdhash = n; | |
26843 | + err = 0; | |
26844 | + opt->type = token; | |
26845 | + break; | |
26846 | + | |
26847 | + case Opt_trunc_xino: | |
26848 | + case Opt_notrunc_xino: | |
26849 | + case Opt_noxino: | |
26850 | + case Opt_trunc_xib: | |
26851 | + case Opt_notrunc_xib: | |
dece6358 AM |
26852 | + case Opt_shwh: |
26853 | + case Opt_noshwh: | |
076b876e AM |
26854 | + case Opt_dirperm1: |
26855 | + case Opt_nodirperm1: | |
1facf9fc | 26856 | + case Opt_plink: |
26857 | + case Opt_noplink: | |
26858 | + case Opt_list_plink: | |
4a4d8108 AM |
26859 | + case Opt_dio: |
26860 | + case Opt_nodio: | |
1facf9fc | 26861 | + case Opt_diropq_a: |
26862 | + case Opt_diropq_w: | |
26863 | + case Opt_warn_perm: | |
26864 | + case Opt_nowarn_perm: | |
1facf9fc | 26865 | + case Opt_verbose: |
26866 | + case Opt_noverbose: | |
26867 | + case Opt_sum: | |
26868 | + case Opt_nosum: | |
26869 | + case Opt_wsum: | |
dece6358 AM |
26870 | + case Opt_rdblk_def: |
26871 | + case Opt_rdhash_def: | |
8b6a4947 AM |
26872 | + case Opt_dirren: |
26873 | + case Opt_nodirren: | |
c1595e42 JR |
26874 | + case Opt_acl: |
26875 | + case Opt_noacl: | |
1facf9fc | 26876 | + err = 0; |
26877 | + opt->type = token; | |
26878 | + break; | |
26879 | + | |
26880 | + case Opt_udba: | |
26881 | + opt->udba = udba_val(a->args[0].from); | |
26882 | + if (opt->udba >= 0) { | |
26883 | + err = 0; | |
26884 | + opt->type = token; | |
26885 | + } else | |
4a4d8108 | 26886 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 26887 | + break; |
26888 | + | |
26889 | + case Opt_wbr_create: | |
26890 | + u.create = &opt->wbr_create; | |
26891 | + u.create->wbr_create | |
26892 | + = au_wbr_create_val(a->args[0].from, u.create); | |
26893 | + if (u.create->wbr_create >= 0) { | |
26894 | + err = 0; | |
26895 | + opt->type = token; | |
26896 | + } else | |
4a4d8108 | 26897 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 26898 | + break; |
26899 | + case Opt_wbr_copyup: | |
26900 | + opt->wbr_copyup = au_wbr_copyup_val(a->args[0].from); | |
26901 | + if (opt->wbr_copyup >= 0) { | |
26902 | + err = 0; | |
26903 | + opt->type = token; | |
26904 | + } else | |
4a4d8108 | 26905 | + pr_err("wrong value, %s\n", opt_str); |
1facf9fc | 26906 | + break; |
26907 | + | |
076b876e AM |
26908 | + case Opt_fhsm_sec: |
26909 | + if (unlikely(match_int(&a->args[0], &n) | |
26910 | + || n < 0)) { | |
26911 | + pr_err("bad integer in %s\n", opt_str); | |
26912 | + break; | |
26913 | + } | |
26914 | + if (sysaufs_brs) { | |
26915 | + opt->fhsm_second = n; | |
26916 | + opt->type = token; | |
26917 | + } else | |
26918 | + pr_warn("ignored %s\n", opt_str); | |
26919 | + err = 0; | |
26920 | + break; | |
26921 | + | |
1facf9fc | 26922 | + case Opt_ignore: |
0c3ec466 | 26923 | + pr_warn("ignored %s\n", opt_str); |
1facf9fc | 26924 | + /*FALLTHROUGH*/ |
26925 | + case Opt_ignore_silent: | |
26926 | + skipped = 1; | |
26927 | + err = 0; | |
26928 | + break; | |
26929 | + case Opt_err: | |
4a4d8108 | 26930 | + pr_err("unknown option %s\n", opt_str); |
1facf9fc | 26931 | + break; |
26932 | + } | |
26933 | + | |
26934 | + if (!err && !skipped) { | |
26935 | + if (unlikely(++opt > opt_tail)) { | |
26936 | + err = -E2BIG; | |
26937 | + opt--; | |
26938 | + opt->type = Opt_tail; | |
26939 | + break; | |
26940 | + } | |
26941 | + opt->type = Opt_tail; | |
26942 | + } | |
26943 | + } | |
26944 | + | |
9f237c51 | 26945 | + au_kfree_rcu(a); |
1facf9fc | 26946 | + dump_opts(opts); |
26947 | + if (unlikely(err)) | |
26948 | + au_opts_free(opts); | |
26949 | + | |
4f0767ce | 26950 | +out: |
1facf9fc | 26951 | + return err; |
26952 | +} | |
26953 | + | |
26954 | +static int au_opt_wbr_create(struct super_block *sb, | |
26955 | + struct au_opt_wbr_create *create) | |
26956 | +{ | |
26957 | + int err; | |
26958 | + struct au_sbinfo *sbinfo; | |
26959 | + | |
dece6358 AM |
26960 | + SiMustWriteLock(sb); |
26961 | + | |
1facf9fc | 26962 | + err = 1; /* handled */ |
26963 | + sbinfo = au_sbi(sb); | |
26964 | + if (sbinfo->si_wbr_create_ops->fin) { | |
26965 | + err = sbinfo->si_wbr_create_ops->fin(sb); | |
26966 | + if (!err) | |
26967 | + err = 1; | |
26968 | + } | |
26969 | + | |
26970 | + sbinfo->si_wbr_create = create->wbr_create; | |
26971 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + create->wbr_create; | |
26972 | + switch (create->wbr_create) { | |
26973 | + case AuWbrCreate_MFSRRV: | |
26974 | + case AuWbrCreate_MFSRR: | |
f2c43d5f AM |
26975 | + case AuWbrCreate_TDMFS: |
26976 | + case AuWbrCreate_TDMFSV: | |
392086de AM |
26977 | + case AuWbrCreate_PMFSRR: |
26978 | + case AuWbrCreate_PMFSRRV: | |
1facf9fc | 26979 | + sbinfo->si_wbr_mfs.mfsrr_watermark = create->mfsrr_watermark; |
26980 | + /*FALLTHROUGH*/ | |
26981 | + case AuWbrCreate_MFS: | |
26982 | + case AuWbrCreate_MFSV: | |
26983 | + case AuWbrCreate_PMFS: | |
26984 | + case AuWbrCreate_PMFSV: | |
e49829fe JR |
26985 | + sbinfo->si_wbr_mfs.mfs_expire |
26986 | + = msecs_to_jiffies(create->mfs_second * MSEC_PER_SEC); | |
1facf9fc | 26987 | + break; |
26988 | + } | |
26989 | + | |
26990 | + if (sbinfo->si_wbr_create_ops->init) | |
26991 | + sbinfo->si_wbr_create_ops->init(sb); /* ignore */ | |
26992 | + | |
26993 | + return err; | |
26994 | +} | |
26995 | + | |
26996 | +/* | |
26997 | + * returns, | |
26998 | + * plus: processed without an error | |
26999 | + * zero: unprocessed | |
27000 | + */ | |
27001 | +static int au_opt_simple(struct super_block *sb, struct au_opt *opt, | |
27002 | + struct au_opts *opts) | |
27003 | +{ | |
27004 | + int err; | |
27005 | + struct au_sbinfo *sbinfo; | |
27006 | + | |
dece6358 AM |
27007 | + SiMustWriteLock(sb); |
27008 | + | |
1facf9fc | 27009 | + err = 1; /* handled */ |
27010 | + sbinfo = au_sbi(sb); | |
27011 | + switch (opt->type) { | |
27012 | + case Opt_udba: | |
27013 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; | |
27014 | + sbinfo->si_mntflags |= opt->udba; | |
27015 | + opts->given_udba |= opt->udba; | |
27016 | + break; | |
27017 | + | |
27018 | + case Opt_plink: | |
27019 | + au_opt_set(sbinfo->si_mntflags, PLINK); | |
27020 | + break; | |
27021 | + case Opt_noplink: | |
27022 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
e49829fe | 27023 | + au_plink_put(sb, /*verbose*/1); |
1facf9fc | 27024 | + au_opt_clr(sbinfo->si_mntflags, PLINK); |
27025 | + break; | |
27026 | + case Opt_list_plink: | |
27027 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
27028 | + au_plink_list(sb); | |
27029 | + break; | |
27030 | + | |
4a4d8108 AM |
27031 | + case Opt_dio: |
27032 | + au_opt_set(sbinfo->si_mntflags, DIO); | |
27033 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
27034 | + break; | |
27035 | + case Opt_nodio: | |
27036 | + au_opt_clr(sbinfo->si_mntflags, DIO); | |
27037 | + au_fset_opts(opts->flags, REFRESH_DYAOP); | |
27038 | + break; | |
27039 | + | |
076b876e AM |
27040 | + case Opt_fhsm_sec: |
27041 | + au_fhsm_set(sbinfo, opt->fhsm_second); | |
27042 | + break; | |
27043 | + | |
1facf9fc | 27044 | + case Opt_diropq_a: |
27045 | + au_opt_set(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
27046 | + break; | |
27047 | + case Opt_diropq_w: | |
27048 | + au_opt_clr(sbinfo->si_mntflags, ALWAYS_DIROPQ); | |
27049 | + break; | |
27050 | + | |
27051 | + case Opt_warn_perm: | |
27052 | + au_opt_set(sbinfo->si_mntflags, WARN_PERM); | |
27053 | + break; | |
27054 | + case Opt_nowarn_perm: | |
27055 | + au_opt_clr(sbinfo->si_mntflags, WARN_PERM); | |
27056 | + break; | |
27057 | + | |
1facf9fc | 27058 | + case Opt_verbose: |
27059 | + au_opt_set(sbinfo->si_mntflags, VERBOSE); | |
27060 | + break; | |
27061 | + case Opt_noverbose: | |
27062 | + au_opt_clr(sbinfo->si_mntflags, VERBOSE); | |
27063 | + break; | |
27064 | + | |
27065 | + case Opt_sum: | |
27066 | + au_opt_set(sbinfo->si_mntflags, SUM); | |
27067 | + break; | |
27068 | + case Opt_wsum: | |
27069 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
27070 | + au_opt_set(sbinfo->si_mntflags, SUM_W); | |
eca34b5c | 27071 | + break; |
1facf9fc | 27072 | + case Opt_nosum: |
27073 | + au_opt_clr(sbinfo->si_mntflags, SUM); | |
27074 | + au_opt_clr(sbinfo->si_mntflags, SUM_W); | |
27075 | + break; | |
27076 | + | |
27077 | + case Opt_wbr_create: | |
27078 | + err = au_opt_wbr_create(sb, &opt->wbr_create); | |
27079 | + break; | |
27080 | + case Opt_wbr_copyup: | |
27081 | + sbinfo->si_wbr_copyup = opt->wbr_copyup; | |
27082 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + opt->wbr_copyup; | |
27083 | + break; | |
27084 | + | |
27085 | + case Opt_dirwh: | |
27086 | + sbinfo->si_dirwh = opt->dirwh; | |
27087 | + break; | |
27088 | + | |
27089 | + case Opt_rdcache: | |
e49829fe JR |
27090 | + sbinfo->si_rdcache |
27091 | + = msecs_to_jiffies(opt->rdcache * MSEC_PER_SEC); | |
1facf9fc | 27092 | + break; |
27093 | + case Opt_rdblk: | |
27094 | + sbinfo->si_rdblk = opt->rdblk; | |
27095 | + break; | |
dece6358 AM |
27096 | + case Opt_rdblk_def: |
27097 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; | |
27098 | + break; | |
1facf9fc | 27099 | + case Opt_rdhash: |
27100 | + sbinfo->si_rdhash = opt->rdhash; | |
27101 | + break; | |
dece6358 AM |
27102 | + case Opt_rdhash_def: |
27103 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
27104 | + break; | |
27105 | + | |
27106 | + case Opt_shwh: | |
27107 | + au_opt_set(sbinfo->si_mntflags, SHWH); | |
27108 | + break; | |
27109 | + case Opt_noshwh: | |
27110 | + au_opt_clr(sbinfo->si_mntflags, SHWH); | |
27111 | + break; | |
1facf9fc | 27112 | + |
076b876e AM |
27113 | + case Opt_dirperm1: |
27114 | + au_opt_set(sbinfo->si_mntflags, DIRPERM1); | |
27115 | + break; | |
27116 | + case Opt_nodirperm1: | |
27117 | + au_opt_clr(sbinfo->si_mntflags, DIRPERM1); | |
27118 | + break; | |
27119 | + | |
1facf9fc | 27120 | + case Opt_trunc_xino: |
27121 | + au_opt_set(sbinfo->si_mntflags, TRUNC_XINO); | |
27122 | + break; | |
27123 | + case Opt_notrunc_xino: | |
27124 | + au_opt_clr(sbinfo->si_mntflags, TRUNC_XINO); | |
27125 | + break; | |
27126 | + | |
27127 | + case Opt_trunc_xino_path: | |
27128 | + case Opt_itrunc_xino: | |
acd2b654 AM |
27129 | + err = au_xino_trunc(sb, opt->xino_itrunc.bindex, |
27130 | + /*idx_begin*/0); | |
1facf9fc | 27131 | + if (!err) |
27132 | + err = 1; | |
27133 | + break; | |
27134 | + | |
27135 | + case Opt_trunc_xib: | |
27136 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
27137 | + break; | |
27138 | + case Opt_notrunc_xib: | |
27139 | + au_fclr_opts(opts->flags, TRUNC_XIB); | |
27140 | + break; | |
27141 | + | |
8b6a4947 AM |
27142 | + case Opt_dirren: |
27143 | + err = 1; | |
27144 | + if (!au_opt_test(sbinfo->si_mntflags, DIRREN)) { | |
27145 | + err = au_dr_opt_set(sb); | |
27146 | + if (!err) | |
27147 | + err = 1; | |
27148 | + } | |
27149 | + if (err == 1) | |
27150 | + au_opt_set(sbinfo->si_mntflags, DIRREN); | |
27151 | + break; | |
27152 | + case Opt_nodirren: | |
27153 | + err = 1; | |
27154 | + if (au_opt_test(sbinfo->si_mntflags, DIRREN)) { | |
27155 | + err = au_dr_opt_clr(sb, au_ftest_opts(opts->flags, | |
27156 | + DR_FLUSHED)); | |
27157 | + if (!err) | |
27158 | + err = 1; | |
27159 | + } | |
27160 | + if (err == 1) | |
27161 | + au_opt_clr(sbinfo->si_mntflags, DIRREN); | |
27162 | + break; | |
27163 | + | |
c1595e42 | 27164 | + case Opt_acl: |
2121bcd9 | 27165 | + sb->s_flags |= SB_POSIXACL; |
c1595e42 JR |
27166 | + break; |
27167 | + case Opt_noacl: | |
2121bcd9 | 27168 | + sb->s_flags &= ~SB_POSIXACL; |
c1595e42 JR |
27169 | + break; |
27170 | + | |
1facf9fc | 27171 | + default: |
27172 | + err = 0; | |
27173 | + break; | |
27174 | + } | |
27175 | + | |
27176 | + return err; | |
27177 | +} | |
27178 | + | |
27179 | +/* | |
27180 | + * returns tri-state. | |
27181 | + * plus: processed without an error | |
27182 | + * zero: unprocessed | |
27183 | + * minus: error | |
27184 | + */ | |
27185 | +static int au_opt_br(struct super_block *sb, struct au_opt *opt, | |
27186 | + struct au_opts *opts) | |
27187 | +{ | |
27188 | + int err, do_refresh; | |
27189 | + | |
27190 | + err = 0; | |
27191 | + switch (opt->type) { | |
27192 | + case Opt_append: | |
5afbbe0d | 27193 | + opt->add.bindex = au_sbbot(sb) + 1; |
1facf9fc | 27194 | + if (opt->add.bindex < 0) |
27195 | + opt->add.bindex = 0; | |
27196 | + goto add; | |
eca34b5c | 27197 | + /* Always goto add, not fallthrough */ |
1facf9fc | 27198 | + case Opt_prepend: |
27199 | + opt->add.bindex = 0; | |
eca34b5c | 27200 | + /* fallthrough */ |
f6b6e03d | 27201 | + add: /* indented label */ |
1facf9fc | 27202 | + case Opt_add: |
27203 | + err = au_br_add(sb, &opt->add, | |
27204 | + au_ftest_opts(opts->flags, REMOUNT)); | |
27205 | + if (!err) { | |
27206 | + err = 1; | |
027c5e7a | 27207 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 27208 | + } |
27209 | + break; | |
27210 | + | |
27211 | + case Opt_del: | |
27212 | + case Opt_idel: | |
27213 | + err = au_br_del(sb, &opt->del, | |
27214 | + au_ftest_opts(opts->flags, REMOUNT)); | |
27215 | + if (!err) { | |
27216 | + err = 1; | |
27217 | + au_fset_opts(opts->flags, TRUNC_XIB); | |
027c5e7a | 27218 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 27219 | + } |
27220 | + break; | |
27221 | + | |
27222 | + case Opt_mod: | |
27223 | + case Opt_imod: | |
27224 | + err = au_br_mod(sb, &opt->mod, | |
27225 | + au_ftest_opts(opts->flags, REMOUNT), | |
27226 | + &do_refresh); | |
27227 | + if (!err) { | |
27228 | + err = 1; | |
027c5e7a AM |
27229 | + if (do_refresh) |
27230 | + au_fset_opts(opts->flags, REFRESH); | |
1facf9fc | 27231 | + } |
27232 | + break; | |
27233 | + } | |
1facf9fc | 27234 | + return err; |
27235 | +} | |
27236 | + | |
27237 | +static int au_opt_xino(struct super_block *sb, struct au_opt *opt, | |
27238 | + struct au_opt_xino **opt_xino, | |
27239 | + struct au_opts *opts) | |
27240 | +{ | |
27241 | + int err; | |
1facf9fc | 27242 | + |
27243 | + err = 0; | |
27244 | + switch (opt->type) { | |
27245 | + case Opt_xino: | |
062440b3 AM |
27246 | + err = au_xino_set(sb, &opt->xino, |
27247 | + !!au_ftest_opts(opts->flags, REMOUNT)); | |
27248 | + if (unlikely(err)) | |
27249 | + break; | |
27250 | + | |
27251 | + *opt_xino = &opt->xino; | |
1facf9fc | 27252 | + break; |
27253 | + | |
27254 | + case Opt_noxino: | |
27255 | + au_xino_clr(sb); | |
1facf9fc | 27256 | + *opt_xino = (void *)-1; |
27257 | + break; | |
27258 | + } | |
27259 | + | |
27260 | + return err; | |
27261 | +} | |
27262 | + | |
27263 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
27264 | + unsigned int pending) | |
27265 | +{ | |
076b876e | 27266 | + int err, fhsm; |
5afbbe0d | 27267 | + aufs_bindex_t bindex, bbot; |
79b8bda9 | 27268 | + unsigned char do_plink, skip, do_free, can_no_dreval; |
1facf9fc | 27269 | + struct au_branch *br; |
27270 | + struct au_wbr *wbr; | |
79b8bda9 | 27271 | + struct dentry *root, *dentry; |
1facf9fc | 27272 | + struct inode *dir, *h_dir; |
27273 | + struct au_sbinfo *sbinfo; | |
27274 | + struct au_hinode *hdir; | |
27275 | + | |
dece6358 AM |
27276 | + SiMustAnyLock(sb); |
27277 | + | |
1facf9fc | 27278 | + sbinfo = au_sbi(sb); |
27279 | + AuDebugOn(!(sbinfo->si_mntflags & AuOptMask_UDBA)); | |
27280 | + | |
2121bcd9 | 27281 | + if (!(sb_flags & SB_RDONLY)) { |
dece6358 | 27282 | + if (unlikely(!au_br_writable(au_sbr_perm(sb, 0)))) |
0c3ec466 | 27283 | + pr_warn("first branch should be rw\n"); |
dece6358 | 27284 | + if (unlikely(au_opt_test(sbinfo->si_mntflags, SHWH))) |
febd17d6 | 27285 | + pr_warn_once("shwh should be used with ro\n"); |
dece6358 | 27286 | + } |
1facf9fc | 27287 | + |
4a4d8108 | 27288 | + if (au_opt_test((sbinfo->si_mntflags | pending), UDBA_HNOTIFY) |
1facf9fc | 27289 | + && !au_opt_test(sbinfo->si_mntflags, XINO)) |
febd17d6 | 27290 | + pr_warn_once("udba=*notify requires xino\n"); |
1facf9fc | 27291 | + |
076b876e | 27292 | + if (au_opt_test(sbinfo->si_mntflags, DIRPERM1)) |
febd17d6 JR |
27293 | + pr_warn_once("dirperm1 breaks the protection" |
27294 | + " by the permission bits on the lower branch\n"); | |
076b876e | 27295 | + |
1facf9fc | 27296 | + err = 0; |
076b876e | 27297 | + fhsm = 0; |
1facf9fc | 27298 | + root = sb->s_root; |
5527c038 | 27299 | + dir = d_inode(root); |
1facf9fc | 27300 | + do_plink = !!au_opt_test(sbinfo->si_mntflags, PLINK); |
79b8bda9 AM |
27301 | + can_no_dreval = !!au_opt_test((sbinfo->si_mntflags | pending), |
27302 | + UDBA_NONE); | |
5afbbe0d AM |
27303 | + bbot = au_sbbot(sb); |
27304 | + for (bindex = 0; !err && bindex <= bbot; bindex++) { | |
1facf9fc | 27305 | + skip = 0; |
27306 | + h_dir = au_h_iptr(dir, bindex); | |
27307 | + br = au_sbr(sb, bindex); | |
1facf9fc | 27308 | + |
c1595e42 JR |
27309 | + if ((br->br_perm & AuBrAttr_ICEX) |
27310 | + && !h_dir->i_op->listxattr) | |
27311 | + br->br_perm &= ~AuBrAttr_ICEX; | |
43982f53 | 27312 | +#if 0 /* untested */ |
c1595e42 | 27313 | + if ((br->br_perm & AuBrAttr_ICEX_SEC) |
2121bcd9 | 27314 | + && (au_br_sb(br)->s_flags & SB_NOSEC)) |
c1595e42 JR |
27315 | + br->br_perm &= ~AuBrAttr_ICEX_SEC; |
27316 | +#endif | |
27317 | + | |
27318 | + do_free = 0; | |
1facf9fc | 27319 | + wbr = br->br_wbr; |
27320 | + if (wbr) | |
27321 | + wbr_wh_read_lock(wbr); | |
27322 | + | |
1e00d052 | 27323 | + if (!au_br_writable(br->br_perm)) { |
1facf9fc | 27324 | + do_free = !!wbr; |
27325 | + skip = (!wbr | |
27326 | + || (!wbr->wbr_whbase | |
27327 | + && !wbr->wbr_plink | |
27328 | + && !wbr->wbr_orph)); | |
1e00d052 | 27329 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 27330 | + /* skip = (!br->br_whbase && !br->br_orph); */ |
27331 | + skip = (!wbr || !wbr->wbr_whbase); | |
27332 | + if (skip && wbr) { | |
27333 | + if (do_plink) | |
27334 | + skip = !!wbr->wbr_plink; | |
27335 | + else | |
27336 | + skip = !wbr->wbr_plink; | |
27337 | + } | |
1e00d052 | 27338 | + } else { |
1facf9fc | 27339 | + /* skip = (br->br_whbase && br->br_ohph); */ |
27340 | + skip = (wbr && wbr->wbr_whbase); | |
27341 | + if (skip) { | |
27342 | + if (do_plink) | |
27343 | + skip = !!wbr->wbr_plink; | |
27344 | + else | |
27345 | + skip = !wbr->wbr_plink; | |
27346 | + } | |
1facf9fc | 27347 | + } |
27348 | + if (wbr) | |
27349 | + wbr_wh_read_unlock(wbr); | |
27350 | + | |
79b8bda9 AM |
27351 | + if (can_no_dreval) { |
27352 | + dentry = br->br_path.dentry; | |
27353 | + spin_lock(&dentry->d_lock); | |
27354 | + if (dentry->d_flags & | |
27355 | + (DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE)) | |
27356 | + can_no_dreval = 0; | |
27357 | + spin_unlock(&dentry->d_lock); | |
27358 | + } | |
27359 | + | |
076b876e AM |
27360 | + if (au_br_fhsm(br->br_perm)) { |
27361 | + fhsm++; | |
27362 | + AuDebugOn(!br->br_fhsm); | |
27363 | + } | |
27364 | + | |
1facf9fc | 27365 | + if (skip) |
27366 | + continue; | |
27367 | + | |
27368 | + hdir = au_hi(dir, bindex); | |
5afbbe0d | 27369 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 27370 | + if (wbr) |
27371 | + wbr_wh_write_lock(wbr); | |
86dc4139 | 27372 | + err = au_wh_init(br, sb); |
1facf9fc | 27373 | + if (wbr) |
27374 | + wbr_wh_write_unlock(wbr); | |
5afbbe0d | 27375 | + au_hn_inode_unlock(hdir); |
1facf9fc | 27376 | + |
27377 | + if (!err && do_free) { | |
9f237c51 | 27378 | + au_kfree_rcu(wbr); |
1facf9fc | 27379 | + br->br_wbr = NULL; |
27380 | + } | |
27381 | + } | |
27382 | + | |
79b8bda9 AM |
27383 | + if (can_no_dreval) |
27384 | + au_fset_si(sbinfo, NO_DREVAL); | |
27385 | + else | |
27386 | + au_fclr_si(sbinfo, NO_DREVAL); | |
27387 | + | |
c1595e42 | 27388 | + if (fhsm >= 2) { |
076b876e | 27389 | + au_fset_si(sbinfo, FHSM); |
5afbbe0d | 27390 | + for (bindex = bbot; bindex >= 0; bindex--) { |
c1595e42 JR |
27391 | + br = au_sbr(sb, bindex); |
27392 | + if (au_br_fhsm(br->br_perm)) { | |
27393 | + au_fhsm_set_bottom(sb, bindex); | |
27394 | + break; | |
27395 | + } | |
27396 | + } | |
27397 | + } else { | |
076b876e | 27398 | + au_fclr_si(sbinfo, FHSM); |
c1595e42 JR |
27399 | + au_fhsm_set_bottom(sb, -1); |
27400 | + } | |
076b876e | 27401 | + |
1facf9fc | 27402 | + return err; |
27403 | +} | |
27404 | + | |
27405 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts) | |
27406 | +{ | |
27407 | + int err; | |
27408 | + unsigned int tmp; | |
5afbbe0d | 27409 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 27410 | + struct au_opt *opt; |
27411 | + struct au_opt_xino *opt_xino, xino; | |
27412 | + struct au_sbinfo *sbinfo; | |
027c5e7a | 27413 | + struct au_branch *br; |
076b876e | 27414 | + struct inode *dir; |
1facf9fc | 27415 | + |
dece6358 AM |
27416 | + SiMustWriteLock(sb); |
27417 | + | |
1facf9fc | 27418 | + err = 0; |
27419 | + opt_xino = NULL; | |
27420 | + opt = opts->opt; | |
27421 | + while (err >= 0 && opt->type != Opt_tail) | |
27422 | + err = au_opt_simple(sb, opt++, opts); | |
27423 | + if (err > 0) | |
27424 | + err = 0; | |
27425 | + else if (unlikely(err < 0)) | |
27426 | + goto out; | |
27427 | + | |
27428 | + /* disable xino and udba temporary */ | |
27429 | + sbinfo = au_sbi(sb); | |
27430 | + tmp = sbinfo->si_mntflags; | |
27431 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
27432 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_REVAL); | |
27433 | + | |
27434 | + opt = opts->opt; | |
27435 | + while (err >= 0 && opt->type != Opt_tail) | |
27436 | + err = au_opt_br(sb, opt++, opts); | |
27437 | + if (err > 0) | |
27438 | + err = 0; | |
27439 | + else if (unlikely(err < 0)) | |
27440 | + goto out; | |
27441 | + | |
5afbbe0d AM |
27442 | + bbot = au_sbbot(sb); |
27443 | + if (unlikely(bbot < 0)) { | |
1facf9fc | 27444 | + err = -EINVAL; |
4a4d8108 | 27445 | + pr_err("no branches\n"); |
1facf9fc | 27446 | + goto out; |
27447 | + } | |
27448 | + | |
27449 | + if (au_opt_test(tmp, XINO)) | |
27450 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
27451 | + opt = opts->opt; | |
27452 | + while (!err && opt->type != Opt_tail) | |
27453 | + err = au_opt_xino(sb, opt++, &opt_xino, opts); | |
27454 | + if (unlikely(err)) | |
27455 | + goto out; | |
27456 | + | |
27457 | + err = au_opts_verify(sb, sb->s_flags, tmp); | |
27458 | + if (unlikely(err)) | |
27459 | + goto out; | |
27460 | + | |
27461 | + /* restore xino */ | |
27462 | + if (au_opt_test(tmp, XINO) && !opt_xino) { | |
27463 | + xino.file = au_xino_def(sb); | |
27464 | + err = PTR_ERR(xino.file); | |
27465 | + if (IS_ERR(xino.file)) | |
27466 | + goto out; | |
27467 | + | |
27468 | + err = au_xino_set(sb, &xino, /*remount*/0); | |
27469 | + fput(xino.file); | |
27470 | + if (unlikely(err)) | |
27471 | + goto out; | |
27472 | + } | |
27473 | + | |
27474 | + /* restore udba */ | |
027c5e7a | 27475 | + tmp &= AuOptMask_UDBA; |
1facf9fc | 27476 | + sbinfo->si_mntflags &= ~AuOptMask_UDBA; |
027c5e7a | 27477 | + sbinfo->si_mntflags |= tmp; |
5afbbe0d AM |
27478 | + bbot = au_sbbot(sb); |
27479 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
027c5e7a AM |
27480 | + br = au_sbr(sb, bindex); |
27481 | + err = au_hnotify_reset_br(tmp, br, br->br_perm); | |
27482 | + if (unlikely(err)) | |
27483 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", | |
27484 | + bindex, err); | |
27485 | + /* go on even if err */ | |
27486 | + } | |
4a4d8108 | 27487 | + if (au_opt_test(tmp, UDBA_HNOTIFY)) { |
5527c038 | 27488 | + dir = d_inode(sb->s_root); |
4a4d8108 | 27489 | + au_hn_reset(dir, au_hi_flags(dir, /*isdir*/1) & ~AuHi_XINO); |
1facf9fc | 27490 | + } |
27491 | + | |
4f0767ce | 27492 | +out: |
1facf9fc | 27493 | + return err; |
27494 | +} | |
27495 | + | |
27496 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts) | |
27497 | +{ | |
27498 | + int err, rerr; | |
79b8bda9 | 27499 | + unsigned char no_dreval; |
1facf9fc | 27500 | + struct inode *dir; |
27501 | + struct au_opt_xino *opt_xino; | |
27502 | + struct au_opt *opt; | |
27503 | + struct au_sbinfo *sbinfo; | |
27504 | + | |
dece6358 AM |
27505 | + SiMustWriteLock(sb); |
27506 | + | |
8b6a4947 AM |
27507 | + err = au_dr_opt_flush(sb); |
27508 | + if (unlikely(err)) | |
27509 | + goto out; | |
27510 | + au_fset_opts(opts->flags, DR_FLUSHED); | |
27511 | + | |
5527c038 | 27512 | + dir = d_inode(sb->s_root); |
1facf9fc | 27513 | + sbinfo = au_sbi(sb); |
1facf9fc | 27514 | + opt_xino = NULL; |
27515 | + opt = opts->opt; | |
27516 | + while (err >= 0 && opt->type != Opt_tail) { | |
27517 | + err = au_opt_simple(sb, opt, opts); | |
27518 | + if (!err) | |
27519 | + err = au_opt_br(sb, opt, opts); | |
27520 | + if (!err) | |
27521 | + err = au_opt_xino(sb, opt, &opt_xino, opts); | |
27522 | + opt++; | |
27523 | + } | |
27524 | + if (err > 0) | |
27525 | + err = 0; | |
27526 | + AuTraceErr(err); | |
27527 | + /* go on even err */ | |
27528 | + | |
79b8bda9 | 27529 | + no_dreval = !!au_ftest_si(sbinfo, NO_DREVAL); |
1facf9fc | 27530 | + rerr = au_opts_verify(sb, opts->sb_flags, /*pending*/0); |
27531 | + if (unlikely(rerr && !err)) | |
27532 | + err = rerr; | |
27533 | + | |
79b8bda9 | 27534 | + if (no_dreval != !!au_ftest_si(sbinfo, NO_DREVAL)) |
b95c5147 | 27535 | + au_fset_opts(opts->flags, REFRESH_IDOP); |
79b8bda9 | 27536 | + |
1facf9fc | 27537 | + if (au_ftest_opts(opts->flags, TRUNC_XIB)) { |
27538 | + rerr = au_xib_trunc(sb); | |
27539 | + if (unlikely(rerr && !err)) | |
27540 | + err = rerr; | |
27541 | + } | |
27542 | + | |
27543 | + /* will be handled by the caller */ | |
027c5e7a | 27544 | + if (!au_ftest_opts(opts->flags, REFRESH) |
79b8bda9 AM |
27545 | + && (opts->given_udba |
27546 | + || au_opt_test(sbinfo->si_mntflags, XINO) | |
b95c5147 | 27547 | + || au_ftest_opts(opts->flags, REFRESH_IDOP) |
79b8bda9 | 27548 | + )) |
027c5e7a | 27549 | + au_fset_opts(opts->flags, REFRESH); |
1facf9fc | 27550 | + |
27551 | + AuDbg("status 0x%x\n", opts->flags); | |
8b6a4947 AM |
27552 | + |
27553 | +out: | |
1facf9fc | 27554 | + return err; |
27555 | +} | |
27556 | + | |
27557 | +/* ---------------------------------------------------------------------- */ | |
27558 | + | |
27559 | +unsigned int au_opt_udba(struct super_block *sb) | |
27560 | +{ | |
27561 | + return au_mntflags(sb) & AuOptMask_UDBA; | |
27562 | +} | |
7f207e10 | 27563 | diff -urN /usr/share/empty/fs/aufs/opts.h linux/fs/aufs/opts.h |
eca34b5c | 27564 | --- /usr/share/empty/fs/aufs/opts.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 27565 | +++ linux/fs/aufs/opts.h 2020-01-27 10:57:18.175538316 +0100 |
062440b3 AM |
27566 | @@ -0,0 +1,225 @@ |
27567 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 27568 | +/* |
d58c55f2 | 27569 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 27570 | + * |
27571 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27572 | + * it under the terms of the GNU General Public License as published by | |
27573 | + * the Free Software Foundation; either version 2 of the License, or | |
27574 | + * (at your option) any later version. | |
dece6358 AM |
27575 | + * |
27576 | + * This program is distributed in the hope that it will be useful, | |
27577 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27578 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27579 | + * GNU General Public License for more details. | |
27580 | + * | |
27581 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27582 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27583 | + */ |
27584 | + | |
27585 | +/* | |
27586 | + * mount options/flags | |
27587 | + */ | |
27588 | + | |
27589 | +#ifndef __AUFS_OPTS_H__ | |
27590 | +#define __AUFS_OPTS_H__ | |
27591 | + | |
27592 | +#ifdef __KERNEL__ | |
27593 | + | |
dece6358 | 27594 | +#include <linux/path.h> |
1facf9fc | 27595 | + |
dece6358 | 27596 | +struct file; |
dece6358 | 27597 | + |
1facf9fc | 27598 | +/* ---------------------------------------------------------------------- */ |
27599 | + | |
27600 | +/* mount flags */ | |
27601 | +#define AuOpt_XINO 1 /* external inode number bitmap | |
27602 | + and translation table */ | |
27603 | +#define AuOpt_TRUNC_XINO (1 << 1) /* truncate xino files */ | |
27604 | +#define AuOpt_UDBA_NONE (1 << 2) /* users direct branch access */ | |
27605 | +#define AuOpt_UDBA_REVAL (1 << 3) | |
4a4d8108 | 27606 | +#define AuOpt_UDBA_HNOTIFY (1 << 4) |
dece6358 AM |
27607 | +#define AuOpt_SHWH (1 << 5) /* show whiteout */ |
27608 | +#define AuOpt_PLINK (1 << 6) /* pseudo-link */ | |
076b876e AM |
27609 | +#define AuOpt_DIRPERM1 (1 << 7) /* ignore the lower dir's perm |
27610 | + bits */ | |
dece6358 AM |
27611 | +#define AuOpt_ALWAYS_DIROPQ (1 << 9) /* policy to creating diropq */ |
27612 | +#define AuOpt_SUM (1 << 10) /* summation for statfs(2) */ | |
27613 | +#define AuOpt_SUM_W (1 << 11) /* unimplemented */ | |
27614 | +#define AuOpt_WARN_PERM (1 << 12) /* warn when add-branch */ | |
eca801bf | 27615 | +#define AuOpt_VERBOSE (1 << 13) /* print the cause of error */ |
4a4d8108 | 27616 | +#define AuOpt_DIO (1 << 14) /* direct io */ |
8b6a4947 | 27617 | +#define AuOpt_DIRREN (1 << 15) /* directory rename */ |
1facf9fc | 27618 | + |
4a4d8108 AM |
27619 | +#ifndef CONFIG_AUFS_HNOTIFY |
27620 | +#undef AuOpt_UDBA_HNOTIFY | |
27621 | +#define AuOpt_UDBA_HNOTIFY 0 | |
1facf9fc | 27622 | +#endif |
8b6a4947 AM |
27623 | +#ifndef CONFIG_AUFS_DIRREN |
27624 | +#undef AuOpt_DIRREN | |
27625 | +#define AuOpt_DIRREN 0 | |
27626 | +#endif | |
dece6358 AM |
27627 | +#ifndef CONFIG_AUFS_SHWH |
27628 | +#undef AuOpt_SHWH | |
27629 | +#define AuOpt_SHWH 0 | |
27630 | +#endif | |
1facf9fc | 27631 | + |
27632 | +#define AuOpt_Def (AuOpt_XINO \ | |
27633 | + | AuOpt_UDBA_REVAL \ | |
27634 | + | AuOpt_PLINK \ | |
27635 | + /* | AuOpt_DIRPERM1 */ \ | |
27636 | + | AuOpt_WARN_PERM) | |
27637 | +#define AuOptMask_UDBA (AuOpt_UDBA_NONE \ | |
27638 | + | AuOpt_UDBA_REVAL \ | |
4a4d8108 | 27639 | + | AuOpt_UDBA_HNOTIFY) |
1facf9fc | 27640 | + |
27641 | +#define au_opt_test(flags, name) (flags & AuOpt_##name) | |
27642 | +#define au_opt_set(flags, name) do { \ | |
27643 | + BUILD_BUG_ON(AuOpt_##name & AuOptMask_UDBA); \ | |
27644 | + ((flags) |= AuOpt_##name); \ | |
27645 | +} while (0) | |
27646 | +#define au_opt_set_udba(flags, name) do { \ | |
27647 | + (flags) &= ~AuOptMask_UDBA; \ | |
27648 | + ((flags) |= AuOpt_##name); \ | |
27649 | +} while (0) | |
7f207e10 AM |
27650 | +#define au_opt_clr(flags, name) do { \ |
27651 | + ((flags) &= ~AuOpt_##name); \ | |
27652 | +} while (0) | |
1facf9fc | 27653 | + |
e49829fe JR |
27654 | +static inline unsigned int au_opts_plink(unsigned int mntflags) |
27655 | +{ | |
27656 | +#ifdef CONFIG_PROC_FS | |
27657 | + return mntflags; | |
27658 | +#else | |
27659 | + return mntflags & ~AuOpt_PLINK; | |
27660 | +#endif | |
27661 | +} | |
27662 | + | |
1facf9fc | 27663 | +/* ---------------------------------------------------------------------- */ |
27664 | + | |
27665 | +/* policies to select one among multiple writable branches */ | |
27666 | +enum { | |
27667 | + AuWbrCreate_TDP, /* top down parent */ | |
27668 | + AuWbrCreate_RR, /* round robin */ | |
27669 | + AuWbrCreate_MFS, /* most free space */ | |
27670 | + AuWbrCreate_MFSV, /* mfs with seconds */ | |
27671 | + AuWbrCreate_MFSRR, /* mfs then rr */ | |
27672 | + AuWbrCreate_MFSRRV, /* mfs then rr with seconds */ | |
f2c43d5f AM |
27673 | + AuWbrCreate_TDMFS, /* top down regardless parent and mfs */ |
27674 | + AuWbrCreate_TDMFSV, /* top down regardless parent and mfs */ | |
1facf9fc | 27675 | + AuWbrCreate_PMFS, /* parent and mfs */ |
27676 | + AuWbrCreate_PMFSV, /* parent and mfs with seconds */ | |
392086de AM |
27677 | + AuWbrCreate_PMFSRR, /* parent, mfs and round-robin */ |
27678 | + AuWbrCreate_PMFSRRV, /* plus seconds */ | |
1facf9fc | 27679 | + |
27680 | + AuWbrCreate_Def = AuWbrCreate_TDP | |
27681 | +}; | |
27682 | + | |
27683 | +enum { | |
27684 | + AuWbrCopyup_TDP, /* top down parent */ | |
27685 | + AuWbrCopyup_BUP, /* bottom up parent */ | |
27686 | + AuWbrCopyup_BU, /* bottom up */ | |
27687 | + | |
27688 | + AuWbrCopyup_Def = AuWbrCopyup_TDP | |
27689 | +}; | |
27690 | + | |
27691 | +/* ---------------------------------------------------------------------- */ | |
27692 | + | |
27693 | +struct au_opt_add { | |
27694 | + aufs_bindex_t bindex; | |
27695 | + char *pathname; | |
27696 | + int perm; | |
27697 | + struct path path; | |
27698 | +}; | |
27699 | + | |
27700 | +struct au_opt_del { | |
27701 | + char *pathname; | |
27702 | + struct path h_path; | |
27703 | +}; | |
27704 | + | |
27705 | +struct au_opt_mod { | |
27706 | + char *path; | |
27707 | + int perm; | |
27708 | + struct dentry *h_root; | |
27709 | +}; | |
27710 | + | |
27711 | +struct au_opt_xino { | |
27712 | + char *path; | |
27713 | + struct file *file; | |
27714 | +}; | |
27715 | + | |
27716 | +struct au_opt_xino_itrunc { | |
27717 | + aufs_bindex_t bindex; | |
27718 | +}; | |
27719 | + | |
27720 | +struct au_opt_wbr_create { | |
27721 | + int wbr_create; | |
27722 | + int mfs_second; | |
27723 | + unsigned long long mfsrr_watermark; | |
27724 | +}; | |
27725 | + | |
27726 | +struct au_opt { | |
27727 | + int type; | |
27728 | + union { | |
27729 | + struct au_opt_xino xino; | |
27730 | + struct au_opt_xino_itrunc xino_itrunc; | |
27731 | + struct au_opt_add add; | |
27732 | + struct au_opt_del del; | |
27733 | + struct au_opt_mod mod; | |
27734 | + int dirwh; | |
27735 | + int rdcache; | |
27736 | + unsigned int rdblk; | |
27737 | + unsigned int rdhash; | |
27738 | + int udba; | |
27739 | + struct au_opt_wbr_create wbr_create; | |
27740 | + int wbr_copyup; | |
076b876e | 27741 | + unsigned int fhsm_second; |
1facf9fc | 27742 | + }; |
27743 | +}; | |
27744 | + | |
27745 | +/* opts flags */ | |
27746 | +#define AuOpts_REMOUNT 1 | |
027c5e7a AM |
27747 | +#define AuOpts_REFRESH (1 << 1) |
27748 | +#define AuOpts_TRUNC_XIB (1 << 2) | |
27749 | +#define AuOpts_REFRESH_DYAOP (1 << 3) | |
b95c5147 | 27750 | +#define AuOpts_REFRESH_IDOP (1 << 4) |
8b6a4947 | 27751 | +#define AuOpts_DR_FLUSHED (1 << 5) |
1facf9fc | 27752 | +#define au_ftest_opts(flags, name) ((flags) & AuOpts_##name) |
7f207e10 AM |
27753 | +#define au_fset_opts(flags, name) \ |
27754 | + do { (flags) |= AuOpts_##name; } while (0) | |
27755 | +#define au_fclr_opts(flags, name) \ | |
27756 | + do { (flags) &= ~AuOpts_##name; } while (0) | |
1facf9fc | 27757 | + |
8b6a4947 AM |
27758 | +#ifndef CONFIG_AUFS_DIRREN |
27759 | +#undef AuOpts_DR_FLUSHED | |
27760 | +#define AuOpts_DR_FLUSHED 0 | |
27761 | +#endif | |
27762 | + | |
1facf9fc | 27763 | +struct au_opts { |
27764 | + struct au_opt *opt; | |
27765 | + int max_opt; | |
27766 | + | |
27767 | + unsigned int given_udba; | |
27768 | + unsigned int flags; | |
27769 | + unsigned long sb_flags; | |
27770 | +}; | |
27771 | + | |
27772 | +/* ---------------------------------------------------------------------- */ | |
27773 | + | |
7e9cd9fe | 27774 | +/* opts.c */ |
076b876e | 27775 | +void au_optstr_br_perm(au_br_perm_str_t *str, int perm); |
1facf9fc | 27776 | +const char *au_optstr_udba(int udba); |
27777 | +const char *au_optstr_wbr_copyup(int wbr_copyup); | |
27778 | +const char *au_optstr_wbr_create(int wbr_create); | |
27779 | + | |
27780 | +void au_opts_free(struct au_opts *opts); | |
3c1bdaff | 27781 | +struct super_block; |
1facf9fc | 27782 | +int au_opts_parse(struct super_block *sb, char *str, struct au_opts *opts); |
27783 | +int au_opts_verify(struct super_block *sb, unsigned long sb_flags, | |
27784 | + unsigned int pending); | |
27785 | +int au_opts_mount(struct super_block *sb, struct au_opts *opts); | |
27786 | +int au_opts_remount(struct super_block *sb, struct au_opts *opts); | |
27787 | + | |
27788 | +unsigned int au_opt_udba(struct super_block *sb); | |
27789 | + | |
1facf9fc | 27790 | +#endif /* __KERNEL__ */ |
27791 | +#endif /* __AUFS_OPTS_H__ */ | |
7f207e10 | 27792 | diff -urN /usr/share/empty/fs/aufs/plink.c linux/fs/aufs/plink.c |
eca34b5c | 27793 | --- /usr/share/empty/fs/aufs/plink.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 27794 | +++ linux/fs/aufs/plink.c 2020-01-27 10:57:18.175538316 +0100 |
062440b3 | 27795 | @@ -0,0 +1,516 @@ |
cd7a4cd9 | 27796 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 27797 | +/* |
d58c55f2 | 27798 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 27799 | + * |
27800 | + * This program, aufs is free software; you can redistribute it and/or modify | |
27801 | + * it under the terms of the GNU General Public License as published by | |
27802 | + * the Free Software Foundation; either version 2 of the License, or | |
27803 | + * (at your option) any later version. | |
dece6358 AM |
27804 | + * |
27805 | + * This program is distributed in the hope that it will be useful, | |
27806 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
27807 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
27808 | + * GNU General Public License for more details. | |
27809 | + * | |
27810 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 27811 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 27812 | + */ |
27813 | + | |
27814 | +/* | |
27815 | + * pseudo-link | |
27816 | + */ | |
27817 | + | |
27818 | +#include "aufs.h" | |
27819 | + | |
27820 | +/* | |
e49829fe | 27821 | + * the pseudo-link maintenance mode. |
1facf9fc | 27822 | + * during a user process maintains the pseudo-links, |
27823 | + * prohibit adding a new plink and branch manipulation. | |
e49829fe JR |
27824 | + * |
27825 | + * Flags | |
27826 | + * NOPLM: | |
27827 | + * For entry functions which will handle plink, and i_mutex is already held | |
27828 | + * in VFS. | |
27829 | + * They cannot wait and should return an error at once. | |
27830 | + * Callers has to check the error. | |
27831 | + * NOPLMW: | |
27832 | + * For entry functions which will handle plink, but i_mutex is not held | |
27833 | + * in VFS. | |
27834 | + * They can wait the plink maintenance mode to finish. | |
27835 | + * | |
27836 | + * They behave like F_SETLK and F_SETLKW. | |
27837 | + * If the caller never handle plink, then both flags are unnecessary. | |
1facf9fc | 27838 | + */ |
e49829fe JR |
27839 | + |
27840 | +int au_plink_maint(struct super_block *sb, int flags) | |
1facf9fc | 27841 | +{ |
e49829fe JR |
27842 | + int err; |
27843 | + pid_t pid, ppid; | |
f0c0a007 | 27844 | + struct task_struct *parent, *prev; |
e49829fe | 27845 | + struct au_sbinfo *sbi; |
dece6358 AM |
27846 | + |
27847 | + SiMustAnyLock(sb); | |
27848 | + | |
e49829fe JR |
27849 | + err = 0; |
27850 | + if (!au_opt_test(au_mntflags(sb), PLINK)) | |
27851 | + goto out; | |
27852 | + | |
27853 | + sbi = au_sbi(sb); | |
27854 | + pid = sbi->si_plink_maint_pid; | |
27855 | + if (!pid || pid == current->pid) | |
27856 | + goto out; | |
27857 | + | |
27858 | + /* todo: it highly depends upon /sbin/mount.aufs */ | |
f0c0a007 AM |
27859 | + prev = NULL; |
27860 | + parent = current; | |
27861 | + ppid = 0; | |
e49829fe | 27862 | + rcu_read_lock(); |
f0c0a007 AM |
27863 | + while (1) { |
27864 | + parent = rcu_dereference(parent->real_parent); | |
27865 | + if (parent == prev) | |
27866 | + break; | |
27867 | + ppid = task_pid_vnr(parent); | |
27868 | + if (pid == ppid) { | |
27869 | + rcu_read_unlock(); | |
27870 | + goto out; | |
27871 | + } | |
27872 | + prev = parent; | |
27873 | + } | |
e49829fe | 27874 | + rcu_read_unlock(); |
e49829fe JR |
27875 | + |
27876 | + if (au_ftest_lock(flags, NOPLMW)) { | |
027c5e7a AM |
27877 | + /* if there is no i_mutex lock in VFS, we don't need to wait */ |
27878 | + /* AuDebugOn(!lockdep_depth(current)); */ | |
e49829fe JR |
27879 | + while (sbi->si_plink_maint_pid) { |
27880 | + si_read_unlock(sb); | |
27881 | + /* gave up wake_up_bit() */ | |
27882 | + wait_event(sbi->si_plink_wq, !sbi->si_plink_maint_pid); | |
27883 | + | |
27884 | + if (au_ftest_lock(flags, FLUSH)) | |
27885 | + au_nwt_flush(&sbi->si_nowait); | |
27886 | + si_noflush_read_lock(sb); | |
27887 | + } | |
27888 | + } else if (au_ftest_lock(flags, NOPLM)) { | |
27889 | + AuDbg("ppid %d, pid %d\n", ppid, pid); | |
27890 | + err = -EAGAIN; | |
27891 | + } | |
27892 | + | |
27893 | +out: | |
27894 | + return err; | |
4a4d8108 AM |
27895 | +} |
27896 | + | |
e49829fe | 27897 | +void au_plink_maint_leave(struct au_sbinfo *sbinfo) |
4a4d8108 | 27898 | +{ |
4a4d8108 | 27899 | + spin_lock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 27900 | + sbinfo->si_plink_maint_pid = 0; |
4a4d8108 | 27901 | + spin_unlock(&sbinfo->si_plink_maint_lock); |
027c5e7a | 27902 | + wake_up_all(&sbinfo->si_plink_wq); |
4a4d8108 AM |
27903 | +} |
27904 | + | |
e49829fe | 27905 | +int au_plink_maint_enter(struct super_block *sb) |
4a4d8108 AM |
27906 | +{ |
27907 | + int err; | |
4a4d8108 AM |
27908 | + struct au_sbinfo *sbinfo; |
27909 | + | |
27910 | + err = 0; | |
4a4d8108 AM |
27911 | + sbinfo = au_sbi(sb); |
27912 | + /* make sure i am the only one in this fs */ | |
e49829fe JR |
27913 | + si_write_lock(sb, AuLock_FLUSH); |
27914 | + if (au_opt_test(au_mntflags(sb), PLINK)) { | |
27915 | + spin_lock(&sbinfo->si_plink_maint_lock); | |
27916 | + if (!sbinfo->si_plink_maint_pid) | |
27917 | + sbinfo->si_plink_maint_pid = current->pid; | |
27918 | + else | |
27919 | + err = -EBUSY; | |
27920 | + spin_unlock(&sbinfo->si_plink_maint_lock); | |
27921 | + } | |
4a4d8108 AM |
27922 | + si_write_unlock(sb); |
27923 | + | |
27924 | + return err; | |
1facf9fc | 27925 | +} |
27926 | + | |
27927 | +/* ---------------------------------------------------------------------- */ | |
27928 | + | |
1facf9fc | 27929 | +#ifdef CONFIG_AUFS_DEBUG |
27930 | +void au_plink_list(struct super_block *sb) | |
27931 | +{ | |
86dc4139 | 27932 | + int i; |
1facf9fc | 27933 | + struct au_sbinfo *sbinfo; |
8b6a4947 AM |
27934 | + struct hlist_bl_head *hbl; |
27935 | + struct hlist_bl_node *pos; | |
5afbbe0d | 27936 | + struct au_icntnr *icntnr; |
1facf9fc | 27937 | + |
dece6358 AM |
27938 | + SiMustAnyLock(sb); |
27939 | + | |
1facf9fc | 27940 | + sbinfo = au_sbi(sb); |
27941 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 27942 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 27943 | + |
86dc4139 | 27944 | + for (i = 0; i < AuPlink_NHASH; i++) { |
8b6a4947 AM |
27945 | + hbl = sbinfo->si_plink + i; |
27946 | + hlist_bl_lock(hbl); | |
27947 | + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) | |
5afbbe0d | 27948 | + AuDbg("%lu\n", icntnr->vfs_inode.i_ino); |
8b6a4947 | 27949 | + hlist_bl_unlock(hbl); |
86dc4139 | 27950 | + } |
1facf9fc | 27951 | +} |
27952 | +#endif | |
27953 | + | |
27954 | +/* is the inode pseudo-linked? */ | |
27955 | +int au_plink_test(struct inode *inode) | |
27956 | +{ | |
86dc4139 | 27957 | + int found, i; |
1facf9fc | 27958 | + struct au_sbinfo *sbinfo; |
8b6a4947 AM |
27959 | + struct hlist_bl_head *hbl; |
27960 | + struct hlist_bl_node *pos; | |
5afbbe0d | 27961 | + struct au_icntnr *icntnr; |
1facf9fc | 27962 | + |
27963 | + sbinfo = au_sbi(inode->i_sb); | |
dece6358 | 27964 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
1facf9fc | 27965 | + AuDebugOn(!au_opt_test(au_mntflags(inode->i_sb), PLINK)); |
e49829fe | 27966 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
1facf9fc | 27967 | + |
27968 | + found = 0; | |
86dc4139 | 27969 | + i = au_plink_hash(inode->i_ino); |
8b6a4947 AM |
27970 | + hbl = sbinfo->si_plink + i; |
27971 | + hlist_bl_lock(hbl); | |
27972 | + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) | |
5afbbe0d | 27973 | + if (&icntnr->vfs_inode == inode) { |
1facf9fc | 27974 | + found = 1; |
27975 | + break; | |
27976 | + } | |
8b6a4947 | 27977 | + hlist_bl_unlock(hbl); |
1facf9fc | 27978 | + return found; |
27979 | +} | |
27980 | + | |
27981 | +/* ---------------------------------------------------------------------- */ | |
27982 | + | |
27983 | +/* | |
27984 | + * generate a name for plink. | |
27985 | + * the file will be stored under AUFS_WH_PLINKDIR. | |
27986 | + */ | |
27987 | +/* 20 is max digits length of ulong 64 */ | |
27988 | +#define PLINK_NAME_LEN ((20 + 1) * 2) | |
27989 | + | |
27990 | +static int plink_name(char *name, int len, struct inode *inode, | |
27991 | + aufs_bindex_t bindex) | |
27992 | +{ | |
27993 | + int rlen; | |
27994 | + struct inode *h_inode; | |
27995 | + | |
27996 | + h_inode = au_h_iptr(inode, bindex); | |
27997 | + rlen = snprintf(name, len, "%lu.%lu", inode->i_ino, h_inode->i_ino); | |
27998 | + return rlen; | |
27999 | +} | |
28000 | + | |
7f207e10 AM |
28001 | +struct au_do_plink_lkup_args { |
28002 | + struct dentry **errp; | |
28003 | + struct qstr *tgtname; | |
28004 | + struct dentry *h_parent; | |
28005 | + struct au_branch *br; | |
28006 | +}; | |
28007 | + | |
28008 | +static struct dentry *au_do_plink_lkup(struct qstr *tgtname, | |
28009 | + struct dentry *h_parent, | |
28010 | + struct au_branch *br) | |
28011 | +{ | |
28012 | + struct dentry *h_dentry; | |
febd17d6 | 28013 | + struct inode *h_inode; |
7f207e10 | 28014 | + |
febd17d6 | 28015 | + h_inode = d_inode(h_parent); |
be118d29 | 28016 | + inode_lock_shared_nested(h_inode, AuLsc_I_CHILD2); |
b4510431 | 28017 | + h_dentry = vfsub_lkup_one(tgtname, h_parent); |
3c1bdaff | 28018 | + inode_unlock_shared(h_inode); |
7f207e10 AM |
28019 | + return h_dentry; |
28020 | +} | |
28021 | + | |
28022 | +static void au_call_do_plink_lkup(void *args) | |
28023 | +{ | |
28024 | + struct au_do_plink_lkup_args *a = args; | |
28025 | + *a->errp = au_do_plink_lkup(a->tgtname, a->h_parent, a->br); | |
28026 | +} | |
28027 | + | |
1facf9fc | 28028 | +/* lookup the plink-ed @inode under the branch at @bindex */ |
28029 | +struct dentry *au_plink_lkup(struct inode *inode, aufs_bindex_t bindex) | |
28030 | +{ | |
28031 | + struct dentry *h_dentry, *h_parent; | |
28032 | + struct au_branch *br; | |
7f207e10 | 28033 | + int wkq_err; |
1facf9fc | 28034 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 28035 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 28036 | + |
e49829fe JR |
28037 | + AuDebugOn(au_plink_maint(inode->i_sb, AuLock_NOPLM)); |
28038 | + | |
1facf9fc | 28039 | + br = au_sbr(inode->i_sb, bindex); |
28040 | + h_parent = br->br_wbr->wbr_plink; | |
1facf9fc | 28041 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
28042 | + | |
2dfbb274 | 28043 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
7f207e10 AM |
28044 | + struct au_do_plink_lkup_args args = { |
28045 | + .errp = &h_dentry, | |
28046 | + .tgtname = &tgtname, | |
28047 | + .h_parent = h_parent, | |
28048 | + .br = br | |
28049 | + }; | |
28050 | + | |
28051 | + wkq_err = au_wkq_wait(au_call_do_plink_lkup, &args); | |
28052 | + if (unlikely(wkq_err)) | |
28053 | + h_dentry = ERR_PTR(wkq_err); | |
28054 | + } else | |
28055 | + h_dentry = au_do_plink_lkup(&tgtname, h_parent, br); | |
28056 | + | |
1facf9fc | 28057 | + return h_dentry; |
28058 | +} | |
28059 | + | |
28060 | +/* create a pseudo-link */ | |
28061 | +static int do_whplink(struct qstr *tgt, struct dentry *h_parent, | |
28062 | + struct dentry *h_dentry, struct au_branch *br) | |
28063 | +{ | |
28064 | + int err; | |
28065 | + struct path h_path = { | |
86dc4139 | 28066 | + .mnt = au_br_mnt(br) |
1facf9fc | 28067 | + }; |
523b37e3 | 28068 | + struct inode *h_dir, *delegated; |
1facf9fc | 28069 | + |
5527c038 | 28070 | + h_dir = d_inode(h_parent); |
febd17d6 | 28071 | + inode_lock_nested(h_dir, AuLsc_I_CHILD2); |
4f0767ce | 28072 | +again: |
b4510431 | 28073 | + h_path.dentry = vfsub_lkup_one(tgt, h_parent); |
1facf9fc | 28074 | + err = PTR_ERR(h_path.dentry); |
28075 | + if (IS_ERR(h_path.dentry)) | |
28076 | + goto out; | |
28077 | + | |
28078 | + err = 0; | |
28079 | + /* wh.plink dir is not monitored */ | |
7f207e10 | 28080 | + /* todo: is it really safe? */ |
5527c038 JR |
28081 | + if (d_is_positive(h_path.dentry) |
28082 | + && d_inode(h_path.dentry) != d_inode(h_dentry)) { | |
523b37e3 AM |
28083 | + delegated = NULL; |
28084 | + err = vfsub_unlink(h_dir, &h_path, &delegated, /*force*/0); | |
28085 | + if (unlikely(err == -EWOULDBLOCK)) { | |
28086 | + pr_warn("cannot retry for NFSv4 delegation" | |
28087 | + " for an internal unlink\n"); | |
28088 | + iput(delegated); | |
28089 | + } | |
1facf9fc | 28090 | + dput(h_path.dentry); |
28091 | + h_path.dentry = NULL; | |
28092 | + if (!err) | |
28093 | + goto again; | |
28094 | + } | |
5527c038 | 28095 | + if (!err && d_is_negative(h_path.dentry)) { |
523b37e3 AM |
28096 | + delegated = NULL; |
28097 | + err = vfsub_link(h_dentry, h_dir, &h_path, &delegated); | |
28098 | + if (unlikely(err == -EWOULDBLOCK)) { | |
28099 | + pr_warn("cannot retry for NFSv4 delegation" | |
28100 | + " for an internal link\n"); | |
28101 | + iput(delegated); | |
28102 | + } | |
28103 | + } | |
1facf9fc | 28104 | + dput(h_path.dentry); |
28105 | + | |
4f0767ce | 28106 | +out: |
febd17d6 | 28107 | + inode_unlock(h_dir); |
1facf9fc | 28108 | + return err; |
28109 | +} | |
28110 | + | |
28111 | +struct do_whplink_args { | |
28112 | + int *errp; | |
28113 | + struct qstr *tgt; | |
28114 | + struct dentry *h_parent; | |
28115 | + struct dentry *h_dentry; | |
28116 | + struct au_branch *br; | |
28117 | +}; | |
28118 | + | |
28119 | +static void call_do_whplink(void *args) | |
28120 | +{ | |
28121 | + struct do_whplink_args *a = args; | |
28122 | + *a->errp = do_whplink(a->tgt, a->h_parent, a->h_dentry, a->br); | |
28123 | +} | |
28124 | + | |
28125 | +static int whplink(struct dentry *h_dentry, struct inode *inode, | |
28126 | + aufs_bindex_t bindex, struct au_branch *br) | |
28127 | +{ | |
28128 | + int err, wkq_err; | |
28129 | + struct au_wbr *wbr; | |
28130 | + struct dentry *h_parent; | |
1facf9fc | 28131 | + char a[PLINK_NAME_LEN]; |
0c3ec466 | 28132 | + struct qstr tgtname = QSTR_INIT(a, 0); |
1facf9fc | 28133 | + |
28134 | + wbr = au_sbr(inode->i_sb, bindex)->br_wbr; | |
28135 | + h_parent = wbr->wbr_plink; | |
1facf9fc | 28136 | + tgtname.len = plink_name(a, sizeof(a), inode, bindex); |
28137 | + | |
28138 | + /* always superio. */ | |
2dfbb274 | 28139 | + if (!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)) { |
1facf9fc | 28140 | + struct do_whplink_args args = { |
28141 | + .errp = &err, | |
28142 | + .tgt = &tgtname, | |
28143 | + .h_parent = h_parent, | |
28144 | + .h_dentry = h_dentry, | |
28145 | + .br = br | |
28146 | + }; | |
28147 | + wkq_err = au_wkq_wait(call_do_whplink, &args); | |
28148 | + if (unlikely(wkq_err)) | |
28149 | + err = wkq_err; | |
28150 | + } else | |
28151 | + err = do_whplink(&tgtname, h_parent, h_dentry, br); | |
1facf9fc | 28152 | + |
28153 | + return err; | |
28154 | +} | |
28155 | + | |
1facf9fc | 28156 | +/* |
28157 | + * create a new pseudo-link for @h_dentry on @bindex. | |
28158 | + * the linked inode is held in aufs @inode. | |
28159 | + */ | |
28160 | +void au_plink_append(struct inode *inode, aufs_bindex_t bindex, | |
28161 | + struct dentry *h_dentry) | |
28162 | +{ | |
28163 | + struct super_block *sb; | |
28164 | + struct au_sbinfo *sbinfo; | |
8b6a4947 AM |
28165 | + struct hlist_bl_head *hbl; |
28166 | + struct hlist_bl_node *pos; | |
5afbbe0d | 28167 | + struct au_icntnr *icntnr; |
86dc4139 | 28168 | + int found, err, cnt, i; |
1facf9fc | 28169 | + |
28170 | + sb = inode->i_sb; | |
28171 | + sbinfo = au_sbi(sb); | |
28172 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 28173 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 28174 | + |
86dc4139 | 28175 | + found = au_plink_test(inode); |
4a4d8108 | 28176 | + if (found) |
1facf9fc | 28177 | + return; |
4a4d8108 | 28178 | + |
86dc4139 | 28179 | + i = au_plink_hash(inode->i_ino); |
8b6a4947 | 28180 | + hbl = sbinfo->si_plink + i; |
5afbbe0d | 28181 | + au_igrab(inode); |
1facf9fc | 28182 | + |
8b6a4947 AM |
28183 | + hlist_bl_lock(hbl); |
28184 | + hlist_bl_for_each_entry(icntnr, pos, hbl, plink) { | |
5afbbe0d | 28185 | + if (&icntnr->vfs_inode == inode) { |
4a4d8108 AM |
28186 | + found = 1; |
28187 | + break; | |
28188 | + } | |
1facf9fc | 28189 | + } |
5afbbe0d AM |
28190 | + if (!found) { |
28191 | + icntnr = container_of(inode, struct au_icntnr, vfs_inode); | |
8b6a4947 | 28192 | + hlist_bl_add_head(&icntnr->plink, hbl); |
5afbbe0d | 28193 | + } |
8b6a4947 | 28194 | + hlist_bl_unlock(hbl); |
4a4d8108 | 28195 | + if (!found) { |
8b6a4947 | 28196 | + cnt = au_hbl_count(hbl); |
acd2b654 | 28197 | +#define msg "unexpectedly unbalanced or too many pseudo-links" |
86dc4139 AM |
28198 | + if (cnt > AUFS_PLINK_WARN) |
28199 | + AuWarn1(msg ", %d\n", cnt); | |
28200 | +#undef msg | |
1facf9fc | 28201 | + err = whplink(h_dentry, inode, bindex, au_sbr(sb, bindex)); |
5afbbe0d AM |
28202 | + if (unlikely(err)) { |
28203 | + pr_warn("err %d, damaged pseudo link.\n", err); | |
8b6a4947 | 28204 | + au_hbl_del(&icntnr->plink, hbl); |
5afbbe0d | 28205 | + iput(&icntnr->vfs_inode); |
4a4d8108 | 28206 | + } |
5afbbe0d AM |
28207 | + } else |
28208 | + iput(&icntnr->vfs_inode); | |
1facf9fc | 28209 | +} |
28210 | + | |
28211 | +/* free all plinks */ | |
e49829fe | 28212 | +void au_plink_put(struct super_block *sb, int verbose) |
1facf9fc | 28213 | +{ |
86dc4139 | 28214 | + int i, warned; |
1facf9fc | 28215 | + struct au_sbinfo *sbinfo; |
8b6a4947 AM |
28216 | + struct hlist_bl_head *hbl; |
28217 | + struct hlist_bl_node *pos, *tmp; | |
5afbbe0d | 28218 | + struct au_icntnr *icntnr; |
1facf9fc | 28219 | + |
dece6358 AM |
28220 | + SiMustWriteLock(sb); |
28221 | + | |
1facf9fc | 28222 | + sbinfo = au_sbi(sb); |
28223 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 28224 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 28225 | + |
1facf9fc | 28226 | + /* no spin_lock since sbinfo is write-locked */ |
86dc4139 AM |
28227 | + warned = 0; |
28228 | + for (i = 0; i < AuPlink_NHASH; i++) { | |
8b6a4947 AM |
28229 | + hbl = sbinfo->si_plink + i; |
28230 | + if (!warned && verbose && !hlist_bl_empty(hbl)) { | |
86dc4139 AM |
28231 | + pr_warn("pseudo-link is not flushed"); |
28232 | + warned = 1; | |
28233 | + } | |
8b6a4947 | 28234 | + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) |
5afbbe0d | 28235 | + iput(&icntnr->vfs_inode); |
8b6a4947 | 28236 | + INIT_HLIST_BL_HEAD(hbl); |
86dc4139 | 28237 | + } |
1facf9fc | 28238 | +} |
28239 | + | |
e49829fe JR |
28240 | +void au_plink_clean(struct super_block *sb, int verbose) |
28241 | +{ | |
28242 | + struct dentry *root; | |
28243 | + | |
28244 | + root = sb->s_root; | |
28245 | + aufs_write_lock(root); | |
28246 | + if (au_opt_test(au_mntflags(sb), PLINK)) | |
28247 | + au_plink_put(sb, verbose); | |
28248 | + aufs_write_unlock(root); | |
28249 | +} | |
28250 | + | |
86dc4139 AM |
28251 | +static int au_plink_do_half_refresh(struct inode *inode, aufs_bindex_t br_id) |
28252 | +{ | |
28253 | + int do_put; | |
5afbbe0d | 28254 | + aufs_bindex_t btop, bbot, bindex; |
86dc4139 AM |
28255 | + |
28256 | + do_put = 0; | |
5afbbe0d AM |
28257 | + btop = au_ibtop(inode); |
28258 | + bbot = au_ibbot(inode); | |
28259 | + if (btop >= 0) { | |
28260 | + for (bindex = btop; bindex <= bbot; bindex++) { | |
86dc4139 AM |
28261 | + if (!au_h_iptr(inode, bindex) |
28262 | + || au_ii_br_id(inode, bindex) != br_id) | |
28263 | + continue; | |
28264 | + au_set_h_iptr(inode, bindex, NULL, 0); | |
28265 | + do_put = 1; | |
28266 | + break; | |
28267 | + } | |
28268 | + if (do_put) | |
5afbbe0d | 28269 | + for (bindex = btop; bindex <= bbot; bindex++) |
86dc4139 AM |
28270 | + if (au_h_iptr(inode, bindex)) { |
28271 | + do_put = 0; | |
28272 | + break; | |
28273 | + } | |
28274 | + } else | |
28275 | + do_put = 1; | |
28276 | + | |
28277 | + return do_put; | |
28278 | +} | |
28279 | + | |
1facf9fc | 28280 | +/* free the plinks on a branch specified by @br_id */ |
28281 | +void au_plink_half_refresh(struct super_block *sb, aufs_bindex_t br_id) | |
28282 | +{ | |
28283 | + struct au_sbinfo *sbinfo; | |
8b6a4947 AM |
28284 | + struct hlist_bl_head *hbl; |
28285 | + struct hlist_bl_node *pos, *tmp; | |
5afbbe0d | 28286 | + struct au_icntnr *icntnr; |
1facf9fc | 28287 | + struct inode *inode; |
86dc4139 | 28288 | + int i, do_put; |
1facf9fc | 28289 | + |
dece6358 AM |
28290 | + SiMustWriteLock(sb); |
28291 | + | |
1facf9fc | 28292 | + sbinfo = au_sbi(sb); |
28293 | + AuDebugOn(!au_opt_test(au_mntflags(sb), PLINK)); | |
e49829fe | 28294 | + AuDebugOn(au_plink_maint(sb, AuLock_NOPLM)); |
1facf9fc | 28295 | + |
8b6a4947 | 28296 | + /* no bit_lock since sbinfo is write-locked */ |
86dc4139 | 28297 | + for (i = 0; i < AuPlink_NHASH; i++) { |
8b6a4947 AM |
28298 | + hbl = sbinfo->si_plink + i; |
28299 | + hlist_bl_for_each_entry_safe(icntnr, pos, tmp, hbl, plink) { | |
5afbbe0d | 28300 | + inode = au_igrab(&icntnr->vfs_inode); |
86dc4139 AM |
28301 | + ii_write_lock_child(inode); |
28302 | + do_put = au_plink_do_half_refresh(inode, br_id); | |
5afbbe0d | 28303 | + if (do_put) { |
8b6a4947 | 28304 | + hlist_bl_del(&icntnr->plink); |
5afbbe0d AM |
28305 | + iput(inode); |
28306 | + } | |
86dc4139 AM |
28307 | + ii_write_unlock(inode); |
28308 | + iput(inode); | |
dece6358 | 28309 | + } |
dece6358 AM |
28310 | + } |
28311 | +} | |
7f207e10 | 28312 | diff -urN /usr/share/empty/fs/aufs/poll.c linux/fs/aufs/poll.c |
eca34b5c | 28313 | --- /usr/share/empty/fs/aufs/poll.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 28314 | +++ linux/fs/aufs/poll.c 2020-01-27 10:57:18.175538316 +0100 |
cd7a4cd9 AM |
28315 | @@ -0,0 +1,51 @@ |
28316 | +// SPDX-License-Identifier: GPL-2.0 | |
dece6358 | 28317 | +/* |
d58c55f2 | 28318 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
dece6358 AM |
28319 | + * |
28320 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28321 | + * it under the terms of the GNU General Public License as published by | |
28322 | + * the Free Software Foundation; either version 2 of the License, or | |
28323 | + * (at your option) any later version. | |
28324 | + * | |
28325 | + * This program is distributed in the hope that it will be useful, | |
28326 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28327 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28328 | + * GNU General Public License for more details. | |
28329 | + * | |
28330 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28331 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
dece6358 AM |
28332 | + */ |
28333 | + | |
1308ab2a | 28334 | +/* |
28335 | + * poll operation | |
28336 | + * There is only one filesystem which implements ->poll operation, currently. | |
28337 | + */ | |
28338 | + | |
28339 | +#include "aufs.h" | |
28340 | + | |
cd7a4cd9 | 28341 | +__poll_t aufs_poll(struct file *file, struct poll_table_struct *pt) |
1308ab2a | 28342 | +{ |
be118d29 | 28343 | + __poll_t mask; |
1308ab2a | 28344 | + struct file *h_file; |
1308ab2a | 28345 | + struct super_block *sb; |
28346 | + | |
28347 | + /* We should pretend an error happened. */ | |
be118d29 | 28348 | + mask = EPOLLERR /* | EPOLLIN | EPOLLOUT */; |
b912730e | 28349 | + sb = file->f_path.dentry->d_sb; |
e49829fe | 28350 | + si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLMW); |
b912730e | 28351 | + |
521ced18 | 28352 | + h_file = au_read_pre(file, /*keep_fi*/0, /*lsc*/0); |
062440b3 AM |
28353 | + if (IS_ERR(h_file)) { |
28354 | + AuDbg("h_file %ld\n", PTR_ERR(h_file)); | |
1308ab2a | 28355 | + goto out; |
062440b3 | 28356 | + } |
1308ab2a | 28357 | + |
cd7a4cd9 | 28358 | + mask = vfs_poll(h_file, pt); |
b912730e | 28359 | + fput(h_file); /* instead of au_read_post() */ |
1308ab2a | 28360 | + |
4f0767ce | 28361 | +out: |
1308ab2a | 28362 | + si_read_unlock(sb); |
062440b3 | 28363 | + if (mask & EPOLLERR) |
b00004a5 | 28364 | + AuDbg("mask 0x%x\n", mask); |
1308ab2a | 28365 | + return mask; |
28366 | +} | |
c1595e42 | 28367 | diff -urN /usr/share/empty/fs/aufs/posix_acl.c linux/fs/aufs/posix_acl.c |
eca34b5c | 28368 | --- /usr/share/empty/fs/aufs/posix_acl.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 28369 | +++ linux/fs/aufs/posix_acl.c 2020-01-27 10:57:18.175538316 +0100 |
9f00928d | 28370 | @@ -0,0 +1,105 @@ |
cd7a4cd9 | 28371 | +// SPDX-License-Identifier: GPL-2.0 |
c1595e42 | 28372 | +/* |
d58c55f2 | 28373 | + * Copyright (C) 2014-2020 Junjiro R. Okajima |
c1595e42 JR |
28374 | + * |
28375 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28376 | + * it under the terms of the GNU General Public License as published by | |
28377 | + * the Free Software Foundation; either version 2 of the License, or | |
28378 | + * (at your option) any later version. | |
28379 | + * | |
28380 | + * This program is distributed in the hope that it will be useful, | |
28381 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28382 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28383 | + * GNU General Public License for more details. | |
28384 | + * | |
28385 | + * You should have received a copy of the GNU General Public License | |
28386 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
28387 | + */ | |
28388 | + | |
28389 | +/* | |
28390 | + * posix acl operations | |
28391 | + */ | |
28392 | + | |
28393 | +#include <linux/fs.h> | |
c1595e42 JR |
28394 | +#include "aufs.h" |
28395 | + | |
28396 | +struct posix_acl *aufs_get_acl(struct inode *inode, int type) | |
28397 | +{ | |
28398 | + struct posix_acl *acl; | |
28399 | + int err; | |
28400 | + aufs_bindex_t bindex; | |
28401 | + struct inode *h_inode; | |
28402 | + struct super_block *sb; | |
28403 | + | |
28404 | + acl = NULL; | |
28405 | + sb = inode->i_sb; | |
28406 | + si_read_lock(sb, AuLock_FLUSH); | |
28407 | + ii_read_lock_child(inode); | |
2121bcd9 | 28408 | + if (!(sb->s_flags & SB_POSIXACL)) |
c1595e42 JR |
28409 | + goto out; |
28410 | + | |
5afbbe0d | 28411 | + bindex = au_ibtop(inode); |
c1595e42 JR |
28412 | + h_inode = au_h_iptr(inode, bindex); |
28413 | + if (unlikely(!h_inode | |
28414 | + || ((h_inode->i_mode & S_IFMT) | |
28415 | + != (inode->i_mode & S_IFMT)))) { | |
28416 | + err = au_busy_or_stale(); | |
28417 | + acl = ERR_PTR(err); | |
28418 | + goto out; | |
28419 | + } | |
28420 | + | |
28421 | + /* always topmost only */ | |
28422 | + acl = get_acl(h_inode, type); | |
9f00928d AM |
28423 | + if (IS_ERR(acl)) |
28424 | + forget_cached_acl(inode, type); | |
28425 | + else | |
a2654f78 | 28426 | + set_cached_acl(inode, type, acl); |
c1595e42 JR |
28427 | + |
28428 | +out: | |
28429 | + ii_read_unlock(inode); | |
28430 | + si_read_unlock(sb); | |
28431 | + | |
28432 | + AuTraceErrPtr(acl); | |
28433 | + return acl; | |
28434 | +} | |
28435 | + | |
28436 | +int aufs_set_acl(struct inode *inode, struct posix_acl *acl, int type) | |
28437 | +{ | |
28438 | + int err; | |
28439 | + ssize_t ssz; | |
28440 | + struct dentry *dentry; | |
f2c43d5f | 28441 | + struct au_sxattr arg = { |
c1595e42 JR |
28442 | + .type = AU_ACL_SET, |
28443 | + .u.acl_set = { | |
28444 | + .acl = acl, | |
28445 | + .type = type | |
28446 | + }, | |
28447 | + }; | |
28448 | + | |
5afbbe0d AM |
28449 | + IMustLock(inode); |
28450 | + | |
c1595e42 JR |
28451 | + if (inode->i_ino == AUFS_ROOT_INO) |
28452 | + dentry = dget(inode->i_sb->s_root); | |
28453 | + else { | |
28454 | + dentry = d_find_alias(inode); | |
28455 | + if (!dentry) | |
28456 | + dentry = d_find_any_alias(inode); | |
28457 | + if (!dentry) { | |
28458 | + pr_warn("cannot handle this inode, " | |
28459 | + "please report to aufs-users ML\n"); | |
28460 | + err = -ENOENT; | |
28461 | + goto out; | |
28462 | + } | |
28463 | + } | |
28464 | + | |
f2c43d5f | 28465 | + ssz = au_sxattr(dentry, inode, &arg); |
9f00928d AM |
28466 | + /* forget even it if succeeds since the branch might set differently */ |
28467 | + forget_cached_acl(inode, type); | |
c1595e42 JR |
28468 | + dput(dentry); |
28469 | + err = ssz; | |
9f00928d | 28470 | + if (ssz >= 0) |
c1595e42 JR |
28471 | + err = 0; |
28472 | + | |
28473 | +out: | |
c1595e42 JR |
28474 | + return err; |
28475 | +} | |
7f207e10 | 28476 | diff -urN /usr/share/empty/fs/aufs/procfs.c linux/fs/aufs/procfs.c |
eca34b5c | 28477 | --- /usr/share/empty/fs/aufs/procfs.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 28478 | +++ linux/fs/aufs/procfs.c 2020-01-27 10:57:18.175538316 +0100 |
062440b3 | 28479 | @@ -0,0 +1,171 @@ |
cd7a4cd9 | 28480 | +// SPDX-License-Identifier: GPL-2.0 |
e49829fe | 28481 | +/* |
d58c55f2 | 28482 | + * Copyright (C) 2010-2020 Junjiro R. Okajima |
e49829fe JR |
28483 | + * |
28484 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28485 | + * it under the terms of the GNU General Public License as published by | |
28486 | + * the Free Software Foundation; either version 2 of the License, or | |
28487 | + * (at your option) any later version. | |
28488 | + * | |
28489 | + * This program is distributed in the hope that it will be useful, | |
28490 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28491 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28492 | + * GNU General Public License for more details. | |
28493 | + * | |
28494 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28495 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
e49829fe JR |
28496 | + */ |
28497 | + | |
28498 | +/* | |
28499 | + * procfs interfaces | |
28500 | + */ | |
28501 | + | |
28502 | +#include <linux/proc_fs.h> | |
28503 | +#include "aufs.h" | |
28504 | + | |
28505 | +static int au_procfs_plm_release(struct inode *inode, struct file *file) | |
28506 | +{ | |
28507 | + struct au_sbinfo *sbinfo; | |
28508 | + | |
28509 | + sbinfo = file->private_data; | |
28510 | + if (sbinfo) { | |
28511 | + au_plink_maint_leave(sbinfo); | |
28512 | + kobject_put(&sbinfo->si_kobj); | |
28513 | + } | |
28514 | + | |
28515 | + return 0; | |
28516 | +} | |
28517 | + | |
28518 | +static void au_procfs_plm_write_clean(struct file *file) | |
28519 | +{ | |
28520 | + struct au_sbinfo *sbinfo; | |
28521 | + | |
28522 | + sbinfo = file->private_data; | |
28523 | + if (sbinfo) | |
28524 | + au_plink_clean(sbinfo->si_sb, /*verbose*/0); | |
28525 | +} | |
28526 | + | |
28527 | +static int au_procfs_plm_write_si(struct file *file, unsigned long id) | |
28528 | +{ | |
28529 | + int err; | |
28530 | + struct super_block *sb; | |
28531 | + struct au_sbinfo *sbinfo; | |
8b6a4947 | 28532 | + struct hlist_bl_node *pos; |
e49829fe JR |
28533 | + |
28534 | + err = -EBUSY; | |
28535 | + if (unlikely(file->private_data)) | |
28536 | + goto out; | |
28537 | + | |
28538 | + sb = NULL; | |
53392da6 | 28539 | + /* don't use au_sbilist_lock() here */ |
8b6a4947 AM |
28540 | + hlist_bl_lock(&au_sbilist); |
28541 | + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list) | |
e49829fe | 28542 | + if (id == sysaufs_si_id(sbinfo)) { |
83b672a5 AM |
28543 | + if (kobject_get_unless_zero(&sbinfo->si_kobj)) |
28544 | + sb = sbinfo->si_sb; | |
e49829fe JR |
28545 | + break; |
28546 | + } | |
8b6a4947 | 28547 | + hlist_bl_unlock(&au_sbilist); |
e49829fe JR |
28548 | + |
28549 | + err = -EINVAL; | |
28550 | + if (unlikely(!sb)) | |
28551 | + goto out; | |
28552 | + | |
28553 | + err = au_plink_maint_enter(sb); | |
28554 | + if (!err) | |
28555 | + /* keep kobject_get() */ | |
28556 | + file->private_data = sbinfo; | |
28557 | + else | |
28558 | + kobject_put(&sbinfo->si_kobj); | |
28559 | +out: | |
28560 | + return err; | |
28561 | +} | |
28562 | + | |
28563 | +/* | |
28564 | + * Accept a valid "si=xxxx" only. | |
28565 | + * Once it is accepted successfully, accept "clean" too. | |
28566 | + */ | |
28567 | +static ssize_t au_procfs_plm_write(struct file *file, const char __user *ubuf, | |
28568 | + size_t count, loff_t *ppos) | |
28569 | +{ | |
28570 | + ssize_t err; | |
28571 | + unsigned long id; | |
28572 | + /* last newline is allowed */ | |
28573 | + char buf[3 + sizeof(unsigned long) * 2 + 1]; | |
28574 | + | |
28575 | + err = -EACCES; | |
28576 | + if (unlikely(!capable(CAP_SYS_ADMIN))) | |
28577 | + goto out; | |
28578 | + | |
28579 | + err = -EINVAL; | |
28580 | + if (unlikely(count > sizeof(buf))) | |
28581 | + goto out; | |
28582 | + | |
28583 | + err = copy_from_user(buf, ubuf, count); | |
28584 | + if (unlikely(err)) { | |
28585 | + err = -EFAULT; | |
28586 | + goto out; | |
28587 | + } | |
28588 | + buf[count] = 0; | |
28589 | + | |
28590 | + err = -EINVAL; | |
28591 | + if (!strcmp("clean", buf)) { | |
28592 | + au_procfs_plm_write_clean(file); | |
28593 | + goto out_success; | |
28594 | + } else if (unlikely(strncmp("si=", buf, 3))) | |
28595 | + goto out; | |
28596 | + | |
9dbd164d | 28597 | + err = kstrtoul(buf + 3, 16, &id); |
e49829fe JR |
28598 | + if (unlikely(err)) |
28599 | + goto out; | |
28600 | + | |
28601 | + err = au_procfs_plm_write_si(file, id); | |
28602 | + if (unlikely(err)) | |
28603 | + goto out; | |
28604 | + | |
28605 | +out_success: | |
28606 | + err = count; /* success */ | |
28607 | +out: | |
28608 | + return err; | |
28609 | +} | |
28610 | + | |
28611 | +static const struct file_operations au_procfs_plm_fop = { | |
28612 | + .write = au_procfs_plm_write, | |
28613 | + .release = au_procfs_plm_release, | |
28614 | + .owner = THIS_MODULE | |
28615 | +}; | |
28616 | + | |
28617 | +/* ---------------------------------------------------------------------- */ | |
28618 | + | |
28619 | +static struct proc_dir_entry *au_procfs_dir; | |
28620 | + | |
28621 | +void au_procfs_fin(void) | |
28622 | +{ | |
28623 | + remove_proc_entry(AUFS_PLINK_MAINT_NAME, au_procfs_dir); | |
28624 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
28625 | +} | |
28626 | + | |
28627 | +int __init au_procfs_init(void) | |
28628 | +{ | |
28629 | + int err; | |
28630 | + struct proc_dir_entry *entry; | |
28631 | + | |
28632 | + err = -ENOMEM; | |
28633 | + au_procfs_dir = proc_mkdir(AUFS_PLINK_MAINT_DIR, NULL); | |
28634 | + if (unlikely(!au_procfs_dir)) | |
28635 | + goto out; | |
28636 | + | |
cd7a4cd9 | 28637 | + entry = proc_create(AUFS_PLINK_MAINT_NAME, S_IFREG | 0200, |
e49829fe JR |
28638 | + au_procfs_dir, &au_procfs_plm_fop); |
28639 | + if (unlikely(!entry)) | |
28640 | + goto out_dir; | |
28641 | + | |
28642 | + err = 0; | |
28643 | + goto out; /* success */ | |
28644 | + | |
28645 | + | |
28646 | +out_dir: | |
28647 | + remove_proc_entry(AUFS_PLINK_MAINT_DIR, NULL); | |
28648 | +out: | |
28649 | + return err; | |
28650 | +} | |
7f207e10 | 28651 | diff -urN /usr/share/empty/fs/aufs/rdu.c linux/fs/aufs/rdu.c |
eca34b5c | 28652 | --- /usr/share/empty/fs/aufs/rdu.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 28653 | +++ linux/fs/aufs/rdu.c 2020-01-27 10:57:18.178871751 +0100 |
ba1aed25 | 28654 | @@ -0,0 +1,384 @@ |
cd7a4cd9 | 28655 | +// SPDX-License-Identifier: GPL-2.0 |
1308ab2a | 28656 | +/* |
d58c55f2 | 28657 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1308ab2a | 28658 | + * |
28659 | + * This program, aufs is free software; you can redistribute it and/or modify | |
28660 | + * it under the terms of the GNU General Public License as published by | |
28661 | + * the Free Software Foundation; either version 2 of the License, or | |
28662 | + * (at your option) any later version. | |
28663 | + * | |
28664 | + * This program is distributed in the hope that it will be useful, | |
28665 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
28666 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
28667 | + * GNU General Public License for more details. | |
28668 | + * | |
28669 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 28670 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1308ab2a | 28671 | + */ |
28672 | + | |
28673 | +/* | |
28674 | + * readdir in userspace. | |
28675 | + */ | |
28676 | + | |
b752ccd1 | 28677 | +#include <linux/compat.h> |
4a4d8108 | 28678 | +#include <linux/fs_stack.h> |
1308ab2a | 28679 | +#include <linux/security.h> |
1308ab2a | 28680 | +#include "aufs.h" |
28681 | + | |
28682 | +/* bits for struct aufs_rdu.flags */ | |
28683 | +#define AuRdu_CALLED 1 | |
28684 | +#define AuRdu_CONT (1 << 1) | |
28685 | +#define AuRdu_FULL (1 << 2) | |
28686 | +#define au_ftest_rdu(flags, name) ((flags) & AuRdu_##name) | |
7f207e10 AM |
28687 | +#define au_fset_rdu(flags, name) \ |
28688 | + do { (flags) |= AuRdu_##name; } while (0) | |
28689 | +#define au_fclr_rdu(flags, name) \ | |
28690 | + do { (flags) &= ~AuRdu_##name; } while (0) | |
1308ab2a | 28691 | + |
28692 | +struct au_rdu_arg { | |
392086de | 28693 | + struct dir_context ctx; |
1308ab2a | 28694 | + struct aufs_rdu *rdu; |
28695 | + union au_rdu_ent_ul ent; | |
28696 | + unsigned long end; | |
28697 | + | |
28698 | + struct super_block *sb; | |
28699 | + int err; | |
28700 | +}; | |
28701 | + | |
392086de | 28702 | +static int au_rdu_fill(struct dir_context *ctx, const char *name, int nlen, |
1308ab2a | 28703 | + loff_t offset, u64 h_ino, unsigned int d_type) |
28704 | +{ | |
28705 | + int err, len; | |
392086de | 28706 | + struct au_rdu_arg *arg = container_of(ctx, struct au_rdu_arg, ctx); |
1308ab2a | 28707 | + struct aufs_rdu *rdu = arg->rdu; |
28708 | + struct au_rdu_ent ent; | |
28709 | + | |
28710 | + err = 0; | |
28711 | + arg->err = 0; | |
28712 | + au_fset_rdu(rdu->cookie.flags, CALLED); | |
28713 | + len = au_rdu_len(nlen); | |
28714 | + if (arg->ent.ul + len < arg->end) { | |
28715 | + ent.ino = h_ino; | |
28716 | + ent.bindex = rdu->cookie.bindex; | |
28717 | + ent.type = d_type; | |
28718 | + ent.nlen = nlen; | |
4a4d8108 AM |
28719 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) |
28720 | + ent.type = DT_UNKNOWN; | |
1308ab2a | 28721 | + |
9dbd164d | 28722 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 28723 | + err = -EFAULT; |
28724 | + if (copy_to_user(arg->ent.e, &ent, sizeof(ent))) | |
28725 | + goto out; | |
28726 | + if (copy_to_user(arg->ent.e->name, name, nlen)) | |
28727 | + goto out; | |
28728 | + /* the terminating NULL */ | |
28729 | + if (__put_user(0, arg->ent.e->name + nlen)) | |
28730 | + goto out; | |
28731 | + err = 0; | |
28732 | + /* AuDbg("%p, %.*s\n", arg->ent.p, nlen, name); */ | |
28733 | + arg->ent.ul += len; | |
28734 | + rdu->rent++; | |
28735 | + } else { | |
28736 | + err = -EFAULT; | |
28737 | + au_fset_rdu(rdu->cookie.flags, FULL); | |
28738 | + rdu->full = 1; | |
28739 | + rdu->tail = arg->ent; | |
28740 | + } | |
28741 | + | |
4f0767ce | 28742 | +out: |
1308ab2a | 28743 | + /* AuTraceErr(err); */ |
28744 | + return err; | |
28745 | +} | |
28746 | + | |
28747 | +static int au_rdu_do(struct file *h_file, struct au_rdu_arg *arg) | |
28748 | +{ | |
28749 | + int err; | |
28750 | + loff_t offset; | |
28751 | + struct au_rdu_cookie *cookie = &arg->rdu->cookie; | |
28752 | + | |
92d182d2 | 28753 | + /* we don't have to care (FMODE_32BITHASH | FMODE_64BITHASH) for ext4 */ |
1308ab2a | 28754 | + offset = vfsub_llseek(h_file, cookie->h_pos, SEEK_SET); |
28755 | + err = offset; | |
28756 | + if (unlikely(offset != cookie->h_pos)) | |
28757 | + goto out; | |
28758 | + | |
28759 | + err = 0; | |
28760 | + do { | |
28761 | + arg->err = 0; | |
28762 | + au_fclr_rdu(cookie->flags, CALLED); | |
28763 | + /* smp_mb(); */ | |
392086de | 28764 | + err = vfsub_iterate_dir(h_file, &arg->ctx); |
1308ab2a | 28765 | + if (err >= 0) |
28766 | + err = arg->err; | |
28767 | + } while (!err | |
28768 | + && au_ftest_rdu(cookie->flags, CALLED) | |
28769 | + && !au_ftest_rdu(cookie->flags, FULL)); | |
28770 | + cookie->h_pos = h_file->f_pos; | |
28771 | + | |
4f0767ce | 28772 | +out: |
1308ab2a | 28773 | + AuTraceErr(err); |
28774 | + return err; | |
28775 | +} | |
28776 | + | |
28777 | +static int au_rdu(struct file *file, struct aufs_rdu *rdu) | |
28778 | +{ | |
28779 | + int err; | |
5afbbe0d | 28780 | + aufs_bindex_t bbot; |
392086de AM |
28781 | + struct au_rdu_arg arg = { |
28782 | + .ctx = { | |
2000de60 | 28783 | + .actor = au_rdu_fill |
392086de AM |
28784 | + } |
28785 | + }; | |
1308ab2a | 28786 | + struct dentry *dentry; |
28787 | + struct inode *inode; | |
28788 | + struct file *h_file; | |
28789 | + struct au_rdu_cookie *cookie = &rdu->cookie; | |
28790 | + | |
ba1aed25 AM |
28791 | + /* VERIFY_WRITE */ |
28792 | + err = !access_ok(rdu->ent.e, rdu->sz); | |
1308ab2a | 28793 | + if (unlikely(err)) { |
28794 | + err = -EFAULT; | |
28795 | + AuTraceErr(err); | |
28796 | + goto out; | |
28797 | + } | |
28798 | + rdu->rent = 0; | |
28799 | + rdu->tail = rdu->ent; | |
28800 | + rdu->full = 0; | |
28801 | + arg.rdu = rdu; | |
28802 | + arg.ent = rdu->ent; | |
28803 | + arg.end = arg.ent.ul; | |
28804 | + arg.end += rdu->sz; | |
28805 | + | |
28806 | + err = -ENOTDIR; | |
5afbbe0d | 28807 | + if (unlikely(!file->f_op->iterate && !file->f_op->iterate_shared)) |
1308ab2a | 28808 | + goto out; |
28809 | + | |
28810 | + err = security_file_permission(file, MAY_READ); | |
28811 | + AuTraceErr(err); | |
28812 | + if (unlikely(err)) | |
28813 | + goto out; | |
28814 | + | |
2000de60 | 28815 | + dentry = file->f_path.dentry; |
5527c038 | 28816 | + inode = d_inode(dentry); |
5afbbe0d | 28817 | + inode_lock_shared(inode); |
1308ab2a | 28818 | + |
28819 | + arg.sb = inode->i_sb; | |
e49829fe JR |
28820 | + err = si_read_lock(arg.sb, AuLock_FLUSH | AuLock_NOPLM); |
28821 | + if (unlikely(err)) | |
28822 | + goto out_mtx; | |
027c5e7a AM |
28823 | + err = au_alive_dir(dentry); |
28824 | + if (unlikely(err)) | |
28825 | + goto out_si; | |
e49829fe | 28826 | + /* todo: reval? */ |
1308ab2a | 28827 | + fi_read_lock(file); |
28828 | + | |
28829 | + err = -EAGAIN; | |
28830 | + if (unlikely(au_ftest_rdu(cookie->flags, CONT) | |
28831 | + && cookie->generation != au_figen(file))) | |
28832 | + goto out_unlock; | |
28833 | + | |
28834 | + err = 0; | |
28835 | + if (!rdu->blk) { | |
28836 | + rdu->blk = au_sbi(arg.sb)->si_rdblk; | |
28837 | + if (!rdu->blk) | |
28838 | + rdu->blk = au_dir_size(file, /*dentry*/NULL); | |
28839 | + } | |
5afbbe0d AM |
28840 | + bbot = au_fbtop(file); |
28841 | + if (cookie->bindex < bbot) | |
28842 | + cookie->bindex = bbot; | |
28843 | + bbot = au_fbbot_dir(file); | |
28844 | + /* AuDbg("b%d, b%d\n", cookie->bindex, bbot); */ | |
28845 | + for (; !err && cookie->bindex <= bbot; | |
1308ab2a | 28846 | + cookie->bindex++, cookie->h_pos = 0) { |
4a4d8108 | 28847 | + h_file = au_hf_dir(file, cookie->bindex); |
1308ab2a | 28848 | + if (!h_file) |
28849 | + continue; | |
28850 | + | |
28851 | + au_fclr_rdu(cookie->flags, FULL); | |
28852 | + err = au_rdu_do(h_file, &arg); | |
28853 | + AuTraceErr(err); | |
28854 | + if (unlikely(au_ftest_rdu(cookie->flags, FULL) || err)) | |
28855 | + break; | |
28856 | + } | |
28857 | + AuDbg("rent %llu\n", rdu->rent); | |
28858 | + | |
28859 | + if (!err && !au_ftest_rdu(cookie->flags, CONT)) { | |
28860 | + rdu->shwh = !!au_opt_test(au_sbi(arg.sb)->si_mntflags, SHWH); | |
28861 | + au_fset_rdu(cookie->flags, CONT); | |
28862 | + cookie->generation = au_figen(file); | |
28863 | + } | |
28864 | + | |
28865 | + ii_read_lock_child(inode); | |
5afbbe0d | 28866 | + fsstack_copy_attr_atime(inode, au_h_iptr(inode, au_ibtop(inode))); |
1308ab2a | 28867 | + ii_read_unlock(inode); |
28868 | + | |
4f0767ce | 28869 | +out_unlock: |
1308ab2a | 28870 | + fi_read_unlock(file); |
027c5e7a | 28871 | +out_si: |
1308ab2a | 28872 | + si_read_unlock(arg.sb); |
4f0767ce | 28873 | +out_mtx: |
5afbbe0d | 28874 | + inode_unlock_shared(inode); |
4f0767ce | 28875 | +out: |
1308ab2a | 28876 | + AuTraceErr(err); |
28877 | + return err; | |
28878 | +} | |
28879 | + | |
28880 | +static int au_rdu_ino(struct file *file, struct aufs_rdu *rdu) | |
28881 | +{ | |
28882 | + int err; | |
28883 | + ino_t ino; | |
28884 | + unsigned long long nent; | |
28885 | + union au_rdu_ent_ul *u; | |
28886 | + struct au_rdu_ent ent; | |
28887 | + struct super_block *sb; | |
28888 | + | |
28889 | + err = 0; | |
28890 | + nent = rdu->nent; | |
28891 | + u = &rdu->ent; | |
2000de60 | 28892 | + sb = file->f_path.dentry->d_sb; |
1308ab2a | 28893 | + si_read_lock(sb, AuLock_FLUSH); |
28894 | + while (nent-- > 0) { | |
9dbd164d | 28895 | + /* unnecessary to support mmap_sem since this is a dir */ |
1308ab2a | 28896 | + err = copy_from_user(&ent, u->e, sizeof(ent)); |
4a4d8108 | 28897 | + if (!err) |
ba1aed25 AM |
28898 | + /* VERIFY_WRITE */ |
28899 | + err = !access_ok(&u->e->ino, sizeof(ino)); | |
1308ab2a | 28900 | + if (unlikely(err)) { |
28901 | + err = -EFAULT; | |
28902 | + AuTraceErr(err); | |
28903 | + break; | |
28904 | + } | |
28905 | + | |
28906 | + /* AuDbg("b%d, i%llu\n", ent.bindex, ent.ino); */ | |
28907 | + if (!ent.wh) | |
28908 | + err = au_ino(sb, ent.bindex, ent.ino, ent.type, &ino); | |
28909 | + else | |
28910 | + err = au_wh_ino(sb, ent.bindex, ent.ino, ent.type, | |
28911 | + &ino); | |
28912 | + if (unlikely(err)) { | |
28913 | + AuTraceErr(err); | |
28914 | + break; | |
28915 | + } | |
28916 | + | |
28917 | + err = __put_user(ino, &u->e->ino); | |
28918 | + if (unlikely(err)) { | |
28919 | + err = -EFAULT; | |
28920 | + AuTraceErr(err); | |
28921 | + break; | |
28922 | + } | |
28923 | + u->ul += au_rdu_len(ent.nlen); | |
28924 | + } | |
28925 | + si_read_unlock(sb); | |
28926 | + | |
28927 | + return err; | |
28928 | +} | |
28929 | + | |
28930 | +/* ---------------------------------------------------------------------- */ | |
28931 | + | |
28932 | +static int au_rdu_verify(struct aufs_rdu *rdu) | |
28933 | +{ | |
b752ccd1 | 28934 | + AuDbg("rdu{%llu, %p, %u | %u | %llu, %u, %u | " |
1308ab2a | 28935 | + "%llu, b%d, 0x%x, g%u}\n", |
b752ccd1 | 28936 | + rdu->sz, rdu->ent.e, rdu->verify[AufsCtlRduV_SZ], |
1308ab2a | 28937 | + rdu->blk, |
28938 | + rdu->rent, rdu->shwh, rdu->full, | |
28939 | + rdu->cookie.h_pos, rdu->cookie.bindex, rdu->cookie.flags, | |
28940 | + rdu->cookie.generation); | |
dece6358 | 28941 | + |
b752ccd1 | 28942 | + if (rdu->verify[AufsCtlRduV_SZ] == sizeof(*rdu)) |
1308ab2a | 28943 | + return 0; |
dece6358 | 28944 | + |
b752ccd1 AM |
28945 | + AuDbg("%u:%u\n", |
28946 | + rdu->verify[AufsCtlRduV_SZ], (unsigned int)sizeof(*rdu)); | |
1308ab2a | 28947 | + return -EINVAL; |
28948 | +} | |
28949 | + | |
28950 | +long au_rdu_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
dece6358 | 28951 | +{ |
1308ab2a | 28952 | + long err, e; |
28953 | + struct aufs_rdu rdu; | |
28954 | + void __user *p = (void __user *)arg; | |
dece6358 | 28955 | + |
1308ab2a | 28956 | + err = copy_from_user(&rdu, p, sizeof(rdu)); |
28957 | + if (unlikely(err)) { | |
28958 | + err = -EFAULT; | |
28959 | + AuTraceErr(err); | |
28960 | + goto out; | |
28961 | + } | |
28962 | + err = au_rdu_verify(&rdu); | |
dece6358 AM |
28963 | + if (unlikely(err)) |
28964 | + goto out; | |
28965 | + | |
1308ab2a | 28966 | + switch (cmd) { |
28967 | + case AUFS_CTL_RDU: | |
28968 | + err = au_rdu(file, &rdu); | |
28969 | + if (unlikely(err)) | |
28970 | + break; | |
dece6358 | 28971 | + |
1308ab2a | 28972 | + e = copy_to_user(p, &rdu, sizeof(rdu)); |
28973 | + if (unlikely(e)) { | |
28974 | + err = -EFAULT; | |
28975 | + AuTraceErr(err); | |
28976 | + } | |
28977 | + break; | |
28978 | + case AUFS_CTL_RDU_INO: | |
28979 | + err = au_rdu_ino(file, &rdu); | |
28980 | + break; | |
28981 | + | |
28982 | + default: | |
4a4d8108 | 28983 | + /* err = -ENOTTY; */ |
1308ab2a | 28984 | + err = -EINVAL; |
28985 | + } | |
dece6358 | 28986 | + |
4f0767ce | 28987 | +out: |
1308ab2a | 28988 | + AuTraceErr(err); |
28989 | + return err; | |
1facf9fc | 28990 | +} |
b752ccd1 AM |
28991 | + |
28992 | +#ifdef CONFIG_COMPAT | |
28993 | +long au_rdu_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) | |
28994 | +{ | |
28995 | + long err, e; | |
28996 | + struct aufs_rdu rdu; | |
28997 | + void __user *p = compat_ptr(arg); | |
28998 | + | |
28999 | + /* todo: get_user()? */ | |
29000 | + err = copy_from_user(&rdu, p, sizeof(rdu)); | |
29001 | + if (unlikely(err)) { | |
29002 | + err = -EFAULT; | |
29003 | + AuTraceErr(err); | |
29004 | + goto out; | |
29005 | + } | |
29006 | + rdu.ent.e = compat_ptr(rdu.ent.ul); | |
29007 | + err = au_rdu_verify(&rdu); | |
29008 | + if (unlikely(err)) | |
29009 | + goto out; | |
29010 | + | |
29011 | + switch (cmd) { | |
29012 | + case AUFS_CTL_RDU: | |
29013 | + err = au_rdu(file, &rdu); | |
29014 | + if (unlikely(err)) | |
29015 | + break; | |
29016 | + | |
29017 | + rdu.ent.ul = ptr_to_compat(rdu.ent.e); | |
29018 | + rdu.tail.ul = ptr_to_compat(rdu.tail.e); | |
29019 | + e = copy_to_user(p, &rdu, sizeof(rdu)); | |
29020 | + if (unlikely(e)) { | |
29021 | + err = -EFAULT; | |
29022 | + AuTraceErr(err); | |
29023 | + } | |
29024 | + break; | |
29025 | + case AUFS_CTL_RDU_INO: | |
29026 | + err = au_rdu_ino(file, &rdu); | |
29027 | + break; | |
29028 | + | |
29029 | + default: | |
29030 | + /* err = -ENOTTY; */ | |
29031 | + err = -EINVAL; | |
29032 | + } | |
29033 | + | |
4f0767ce | 29034 | +out: |
b752ccd1 AM |
29035 | + AuTraceErr(err); |
29036 | + return err; | |
29037 | +} | |
29038 | +#endif | |
7f207e10 | 29039 | diff -urN /usr/share/empty/fs/aufs/rwsem.h linux/fs/aufs/rwsem.h |
eca34b5c | 29040 | --- /usr/share/empty/fs/aufs/rwsem.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 29041 | +++ linux/fs/aufs/rwsem.h 2020-01-27 10:57:18.178871751 +0100 |
062440b3 AM |
29042 | @@ -0,0 +1,73 @@ |
29043 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 29044 | +/* |
d58c55f2 | 29045 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 29046 | + * |
29047 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29048 | + * it under the terms of the GNU General Public License as published by | |
29049 | + * the Free Software Foundation; either version 2 of the License, or | |
29050 | + * (at your option) any later version. | |
dece6358 AM |
29051 | + * |
29052 | + * This program is distributed in the hope that it will be useful, | |
29053 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29054 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29055 | + * GNU General Public License for more details. | |
29056 | + * | |
29057 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29058 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29059 | + */ |
29060 | + | |
29061 | +/* | |
29062 | + * simple read-write semaphore wrappers | |
29063 | + */ | |
29064 | + | |
29065 | +#ifndef __AUFS_RWSEM_H__ | |
29066 | +#define __AUFS_RWSEM_H__ | |
29067 | + | |
29068 | +#ifdef __KERNEL__ | |
29069 | + | |
4a4d8108 | 29070 | +#include "debug.h" |
dece6358 | 29071 | + |
acd2b654 | 29072 | +/* in the future, the name 'au_rwsem' will be totally gone */ |
8b6a4947 | 29073 | +#define au_rwsem rw_semaphore |
dece6358 AM |
29074 | + |
29075 | +/* to debug easier, do not make them inlined functions */ | |
8b6a4947 | 29076 | +#define AuRwMustNoWaiters(rw) AuDebugOn(rwsem_is_contended(rw)) |
dece6358 | 29077 | +/* rwsem_is_locked() is unusable */ |
8b6a4947 AM |
29078 | +#define AuRwMustReadLock(rw) AuDebugOn(!lockdep_recursing(current) \ |
29079 | + && debug_locks \ | |
29080 | + && !lockdep_is_held_type(rw, 1)) | |
29081 | +#define AuRwMustWriteLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
29082 | + && debug_locks \ | |
29083 | + && !lockdep_is_held_type(rw, 0)) | |
29084 | +#define AuRwMustAnyLock(rw) AuDebugOn(!lockdep_recursing(current) \ | |
29085 | + && debug_locks \ | |
29086 | + && !lockdep_is_held(rw)) | |
29087 | +#define AuRwDestroy(rw) AuDebugOn(!lockdep_recursing(current) \ | |
29088 | + && debug_locks \ | |
29089 | + && lockdep_is_held(rw)) | |
29090 | + | |
29091 | +#define au_rw_init(rw) init_rwsem(rw) | |
dece6358 | 29092 | + |
5afbbe0d AM |
29093 | +#define au_rw_init_wlock(rw) do { \ |
29094 | + au_rw_init(rw); \ | |
8b6a4947 | 29095 | + down_write(rw); \ |
5afbbe0d | 29096 | + } while (0) |
dece6358 | 29097 | + |
8b6a4947 AM |
29098 | +#define au_rw_init_wlock_nested(rw, lsc) do { \ |
29099 | + au_rw_init(rw); \ | |
29100 | + down_write_nested(rw, lsc); \ | |
5afbbe0d | 29101 | + } while (0) |
dece6358 | 29102 | + |
8b6a4947 AM |
29103 | +#define au_rw_read_lock(rw) down_read(rw) |
29104 | +#define au_rw_read_lock_nested(rw, lsc) down_read_nested(rw, lsc) | |
29105 | +#define au_rw_read_unlock(rw) up_read(rw) | |
29106 | +#define au_rw_dgrade_lock(rw) downgrade_write(rw) | |
29107 | +#define au_rw_write_lock(rw) down_write(rw) | |
29108 | +#define au_rw_write_lock_nested(rw, lsc) down_write_nested(rw, lsc) | |
29109 | +#define au_rw_write_unlock(rw) up_write(rw) | |
29110 | +/* why is not _nested version defined? */ | |
29111 | +#define au_rw_read_trylock(rw) down_read_trylock(rw) | |
29112 | +#define au_rw_write_trylock(rw) down_write_trylock(rw) | |
1facf9fc | 29113 | + |
29114 | +#endif /* __KERNEL__ */ | |
29115 | +#endif /* __AUFS_RWSEM_H__ */ | |
7f207e10 | 29116 | diff -urN /usr/share/empty/fs/aufs/sbinfo.c linux/fs/aufs/sbinfo.c |
eca34b5c | 29117 | --- /usr/share/empty/fs/aufs/sbinfo.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 29118 | +++ linux/fs/aufs/sbinfo.c 2020-01-27 10:57:18.178871751 +0100 |
eca801bf | 29119 | @@ -0,0 +1,314 @@ |
cd7a4cd9 | 29120 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 29121 | +/* |
d58c55f2 | 29122 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 29123 | + * |
29124 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29125 | + * it under the terms of the GNU General Public License as published by | |
29126 | + * the Free Software Foundation; either version 2 of the License, or | |
29127 | + * (at your option) any later version. | |
dece6358 AM |
29128 | + * |
29129 | + * This program is distributed in the hope that it will be useful, | |
29130 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29131 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29132 | + * GNU General Public License for more details. | |
29133 | + * | |
29134 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29135 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29136 | + */ |
29137 | + | |
29138 | +/* | |
29139 | + * superblock private data | |
29140 | + */ | |
29141 | + | |
eca801bf | 29142 | +#include <linux/iversion.h> |
1facf9fc | 29143 | +#include "aufs.h" |
29144 | + | |
29145 | +/* | |
29146 | + * they are necessary regardless sysfs is disabled. | |
29147 | + */ | |
29148 | +void au_si_free(struct kobject *kobj) | |
29149 | +{ | |
86dc4139 | 29150 | + int i; |
1facf9fc | 29151 | + struct au_sbinfo *sbinfo; |
b752ccd1 | 29152 | + char *locked __maybe_unused; /* debug only */ |
1facf9fc | 29153 | + |
29154 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
86dc4139 | 29155 | + for (i = 0; i < AuPlink_NHASH; i++) |
8b6a4947 | 29156 | + AuDebugOn(!hlist_bl_empty(sbinfo->si_plink + i)); |
f0c0a007 | 29157 | + AuDebugOn(atomic_read(&sbinfo->si_nowait.nw_len)); |
5afbbe0d | 29158 | + |
acd2b654 AM |
29159 | + AuLCntZero(au_lcnt_read(&sbinfo->si_ninodes, /*do_rev*/0)); |
29160 | + au_lcnt_fin(&sbinfo->si_ninodes, /*do_sync*/0); | |
29161 | + AuLCntZero(au_lcnt_read(&sbinfo->si_nfiles, /*do_rev*/0)); | |
29162 | + au_lcnt_fin(&sbinfo->si_nfiles, /*do_sync*/0); | |
1facf9fc | 29163 | + |
062440b3 | 29164 | + dbgaufs_si_fin(sbinfo); |
e49829fe | 29165 | + au_rw_write_lock(&sbinfo->si_rwsem); |
1facf9fc | 29166 | + au_br_free(sbinfo); |
e49829fe | 29167 | + au_rw_write_unlock(&sbinfo->si_rwsem); |
b752ccd1 | 29168 | + |
9f237c51 | 29169 | + au_kfree_try_rcu(sbinfo->si_branch); |
1facf9fc | 29170 | + mutex_destroy(&sbinfo->si_xib_mtx); |
dece6358 | 29171 | + AuRwDestroy(&sbinfo->si_rwsem); |
1facf9fc | 29172 | + |
acd2b654 AM |
29173 | + au_lcnt_wait_for_fin(&sbinfo->si_ninodes); |
29174 | + /* si_nfiles is waited too */ | |
9f237c51 | 29175 | + au_kfree_rcu(sbinfo); |
1facf9fc | 29176 | +} |
29177 | + | |
29178 | +int au_si_alloc(struct super_block *sb) | |
29179 | +{ | |
86dc4139 | 29180 | + int err, i; |
1facf9fc | 29181 | + struct au_sbinfo *sbinfo; |
29182 | + | |
29183 | + err = -ENOMEM; | |
4a4d8108 | 29184 | + sbinfo = kzalloc(sizeof(*sbinfo), GFP_NOFS); |
1facf9fc | 29185 | + if (unlikely(!sbinfo)) |
29186 | + goto out; | |
29187 | + | |
29188 | + /* will be reallocated separately */ | |
29189 | + sbinfo->si_branch = kzalloc(sizeof(*sbinfo->si_branch), GFP_NOFS); | |
29190 | + if (unlikely(!sbinfo->si_branch)) | |
febd17d6 | 29191 | + goto out_sbinfo; |
1facf9fc | 29192 | + |
1facf9fc | 29193 | + err = sysaufs_si_init(sbinfo); |
062440b3 AM |
29194 | + if (!err) { |
29195 | + dbgaufs_si_null(sbinfo); | |
29196 | + err = dbgaufs_si_init(sbinfo); | |
29197 | + if (unlikely(err)) | |
29198 | + kobject_put(&sbinfo->si_kobj); | |
29199 | + } | |
1facf9fc | 29200 | + if (unlikely(err)) |
29201 | + goto out_br; | |
29202 | + | |
29203 | + au_nwt_init(&sbinfo->si_nowait); | |
dece6358 | 29204 | + au_rw_init_wlock(&sbinfo->si_rwsem); |
b752ccd1 | 29205 | + |
acd2b654 AM |
29206 | + au_lcnt_init(&sbinfo->si_ninodes, /*release*/NULL); |
29207 | + au_lcnt_init(&sbinfo->si_nfiles, /*release*/NULL); | |
7f207e10 | 29208 | + |
5afbbe0d | 29209 | + sbinfo->si_bbot = -1; |
392086de | 29210 | + sbinfo->si_last_br_id = AUFS_BRANCH_MAX / 2; |
1facf9fc | 29211 | + |
29212 | + sbinfo->si_wbr_copyup = AuWbrCopyup_Def; | |
29213 | + sbinfo->si_wbr_create = AuWbrCreate_Def; | |
4a4d8108 AM |
29214 | + sbinfo->si_wbr_copyup_ops = au_wbr_copyup_ops + sbinfo->si_wbr_copyup; |
29215 | + sbinfo->si_wbr_create_ops = au_wbr_create_ops + sbinfo->si_wbr_create; | |
1facf9fc | 29216 | + |
076b876e AM |
29217 | + au_fhsm_init(sbinfo); |
29218 | + | |
e49829fe | 29219 | + sbinfo->si_mntflags = au_opts_plink(AuOpt_Def); |
1facf9fc | 29220 | + |
392086de AM |
29221 | + sbinfo->si_xino_jiffy = jiffies; |
29222 | + sbinfo->si_xino_expire | |
29223 | + = msecs_to_jiffies(AUFS_XINO_DEF_SEC * MSEC_PER_SEC); | |
1facf9fc | 29224 | + mutex_init(&sbinfo->si_xib_mtx); |
1facf9fc | 29225 | + /* leave si_xib_last_pindex and si_xib_next_bit */ |
29226 | + | |
8b6a4947 | 29227 | + INIT_HLIST_BL_HEAD(&sbinfo->si_aopen); |
b912730e | 29228 | + |
e49829fe | 29229 | + sbinfo->si_rdcache = msecs_to_jiffies(AUFS_RDCACHE_DEF * MSEC_PER_SEC); |
1facf9fc | 29230 | + sbinfo->si_rdblk = AUFS_RDBLK_DEF; |
29231 | + sbinfo->si_rdhash = AUFS_RDHASH_DEF; | |
29232 | + sbinfo->si_dirwh = AUFS_DIRWH_DEF; | |
29233 | + | |
86dc4139 | 29234 | + for (i = 0; i < AuPlink_NHASH; i++) |
8b6a4947 | 29235 | + INIT_HLIST_BL_HEAD(sbinfo->si_plink + i); |
1facf9fc | 29236 | + init_waitqueue_head(&sbinfo->si_plink_wq); |
4a4d8108 | 29237 | + spin_lock_init(&sbinfo->si_plink_maint_lock); |
1facf9fc | 29238 | + |
8b6a4947 | 29239 | + INIT_HLIST_BL_HEAD(&sbinfo->si_files); |
523b37e3 | 29240 | + |
b95c5147 AM |
29241 | + /* with getattr by default */ |
29242 | + sbinfo->si_iop_array = aufs_iop; | |
29243 | + | |
1facf9fc | 29244 | + /* leave other members for sysaufs and si_mnt. */ |
29245 | + sbinfo->si_sb = sb; | |
29246 | + sb->s_fs_info = sbinfo; | |
b752ccd1 | 29247 | + si_pid_set(sb); |
1facf9fc | 29248 | + return 0; /* success */ |
29249 | + | |
4f0767ce | 29250 | +out_br: |
9f237c51 | 29251 | + au_kfree_try_rcu(sbinfo->si_branch); |
4f0767ce | 29252 | +out_sbinfo: |
9f237c51 | 29253 | + au_kfree_rcu(sbinfo); |
4f0767ce | 29254 | +out: |
1facf9fc | 29255 | + return err; |
29256 | +} | |
29257 | + | |
e2f27e51 | 29258 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink) |
1facf9fc | 29259 | +{ |
29260 | + int err, sz; | |
29261 | + struct au_branch **brp; | |
29262 | + | |
dece6358 AM |
29263 | + AuRwMustWriteLock(&sbinfo->si_rwsem); |
29264 | + | |
1facf9fc | 29265 | + err = -ENOMEM; |
5afbbe0d | 29266 | + sz = sizeof(*brp) * (sbinfo->si_bbot + 1); |
1facf9fc | 29267 | + if (unlikely(!sz)) |
29268 | + sz = sizeof(*brp); | |
e2f27e51 AM |
29269 | + brp = au_kzrealloc(sbinfo->si_branch, sz, sizeof(*brp) * nbr, GFP_NOFS, |
29270 | + may_shrink); | |
1facf9fc | 29271 | + if (brp) { |
29272 | + sbinfo->si_branch = brp; | |
29273 | + err = 0; | |
29274 | + } | |
29275 | + | |
29276 | + return err; | |
29277 | +} | |
29278 | + | |
29279 | +/* ---------------------------------------------------------------------- */ | |
29280 | + | |
29281 | +unsigned int au_sigen_inc(struct super_block *sb) | |
29282 | +{ | |
29283 | + unsigned int gen; | |
5527c038 | 29284 | + struct inode *inode; |
1facf9fc | 29285 | + |
dece6358 AM |
29286 | + SiMustWriteLock(sb); |
29287 | + | |
1facf9fc | 29288 | + gen = ++au_sbi(sb)->si_generation; |
29289 | + au_update_digen(sb->s_root); | |
5527c038 JR |
29290 | + inode = d_inode(sb->s_root); |
29291 | + au_update_iigen(inode, /*half*/0); | |
be118d29 | 29292 | + inode_inc_iversion(inode); |
1facf9fc | 29293 | + return gen; |
29294 | +} | |
29295 | + | |
29296 | +aufs_bindex_t au_new_br_id(struct super_block *sb) | |
29297 | +{ | |
29298 | + aufs_bindex_t br_id; | |
29299 | + int i; | |
29300 | + struct au_sbinfo *sbinfo; | |
29301 | + | |
dece6358 AM |
29302 | + SiMustWriteLock(sb); |
29303 | + | |
1facf9fc | 29304 | + sbinfo = au_sbi(sb); |
29305 | + for (i = 0; i <= AUFS_BRANCH_MAX; i++) { | |
29306 | + br_id = ++sbinfo->si_last_br_id; | |
7f207e10 | 29307 | + AuDebugOn(br_id < 0); |
1facf9fc | 29308 | + if (br_id && au_br_index(sb, br_id) < 0) |
29309 | + return br_id; | |
29310 | + } | |
29311 | + | |
29312 | + return -1; | |
29313 | +} | |
29314 | + | |
29315 | +/* ---------------------------------------------------------------------- */ | |
29316 | + | |
e49829fe JR |
29317 | +/* it is ok that new 'nwt' tasks are appended while we are sleeping */ |
29318 | +int si_read_lock(struct super_block *sb, int flags) | |
29319 | +{ | |
29320 | + int err; | |
29321 | + | |
29322 | + err = 0; | |
29323 | + if (au_ftest_lock(flags, FLUSH)) | |
29324 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
29325 | + | |
29326 | + si_noflush_read_lock(sb); | |
29327 | + err = au_plink_maint(sb, flags); | |
29328 | + if (unlikely(err)) | |
29329 | + si_read_unlock(sb); | |
29330 | + | |
29331 | + return err; | |
29332 | +} | |
29333 | + | |
29334 | +int si_write_lock(struct super_block *sb, int flags) | |
29335 | +{ | |
29336 | + int err; | |
29337 | + | |
29338 | + if (au_ftest_lock(flags, FLUSH)) | |
29339 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
29340 | + | |
29341 | + si_noflush_write_lock(sb); | |
29342 | + err = au_plink_maint(sb, flags); | |
29343 | + if (unlikely(err)) | |
29344 | + si_write_unlock(sb); | |
29345 | + | |
29346 | + return err; | |
29347 | +} | |
29348 | + | |
1facf9fc | 29349 | +/* dentry and super_block lock. call at entry point */ |
e49829fe | 29350 | +int aufs_read_lock(struct dentry *dentry, int flags) |
1facf9fc | 29351 | +{ |
e49829fe | 29352 | + int err; |
027c5e7a | 29353 | + struct super_block *sb; |
e49829fe | 29354 | + |
027c5e7a AM |
29355 | + sb = dentry->d_sb; |
29356 | + err = si_read_lock(sb, flags); | |
29357 | + if (unlikely(err)) | |
29358 | + goto out; | |
29359 | + | |
29360 | + if (au_ftest_lock(flags, DW)) | |
29361 | + di_write_lock_child(dentry); | |
29362 | + else | |
29363 | + di_read_lock_child(dentry, flags); | |
29364 | + | |
29365 | + if (au_ftest_lock(flags, GEN)) { | |
29366 | + err = au_digen_test(dentry, au_sigen(sb)); | |
79b8bda9 AM |
29367 | + if (!au_opt_test(au_mntflags(sb), UDBA_NONE)) |
29368 | + AuDebugOn(!err && au_dbrange_test(dentry)); | |
29369 | + else if (!err) | |
29370 | + err = au_dbrange_test(dentry); | |
027c5e7a AM |
29371 | + if (unlikely(err)) |
29372 | + aufs_read_unlock(dentry, flags); | |
e49829fe JR |
29373 | + } |
29374 | + | |
027c5e7a | 29375 | +out: |
e49829fe | 29376 | + return err; |
1facf9fc | 29377 | +} |
29378 | + | |
29379 | +void aufs_read_unlock(struct dentry *dentry, int flags) | |
29380 | +{ | |
29381 | + if (au_ftest_lock(flags, DW)) | |
29382 | + di_write_unlock(dentry); | |
29383 | + else | |
29384 | + di_read_unlock(dentry, flags); | |
29385 | + si_read_unlock(dentry->d_sb); | |
29386 | +} | |
29387 | + | |
29388 | +void aufs_write_lock(struct dentry *dentry) | |
29389 | +{ | |
e49829fe | 29390 | + si_write_lock(dentry->d_sb, AuLock_FLUSH | AuLock_NOPLMW); |
1facf9fc | 29391 | + di_write_lock_child(dentry); |
29392 | +} | |
29393 | + | |
29394 | +void aufs_write_unlock(struct dentry *dentry) | |
29395 | +{ | |
29396 | + di_write_unlock(dentry); | |
29397 | + si_write_unlock(dentry->d_sb); | |
29398 | +} | |
29399 | + | |
e49829fe | 29400 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags) |
1facf9fc | 29401 | +{ |
e49829fe | 29402 | + int err; |
027c5e7a AM |
29403 | + unsigned int sigen; |
29404 | + struct super_block *sb; | |
e49829fe | 29405 | + |
027c5e7a AM |
29406 | + sb = d1->d_sb; |
29407 | + err = si_read_lock(sb, flags); | |
29408 | + if (unlikely(err)) | |
29409 | + goto out; | |
29410 | + | |
b95c5147 | 29411 | + di_write_lock2_child(d1, d2, au_ftest_lock(flags, DIRS)); |
027c5e7a AM |
29412 | + |
29413 | + if (au_ftest_lock(flags, GEN)) { | |
29414 | + sigen = au_sigen(sb); | |
29415 | + err = au_digen_test(d1, sigen); | |
29416 | + AuDebugOn(!err && au_dbrange_test(d1)); | |
29417 | + if (!err) { | |
29418 | + err = au_digen_test(d2, sigen); | |
29419 | + AuDebugOn(!err && au_dbrange_test(d2)); | |
29420 | + } | |
29421 | + if (unlikely(err)) | |
29422 | + aufs_read_and_write_unlock2(d1, d2); | |
29423 | + } | |
29424 | + | |
29425 | +out: | |
e49829fe | 29426 | + return err; |
1facf9fc | 29427 | +} |
29428 | + | |
29429 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2) | |
29430 | +{ | |
29431 | + di_write_unlock2(d1, d2); | |
29432 | + si_read_unlock(d1->d_sb); | |
29433 | +} | |
7f207e10 | 29434 | diff -urN /usr/share/empty/fs/aufs/super.c linux/fs/aufs/super.c |
eca34b5c | 29435 | --- /usr/share/empty/fs/aufs/super.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 29436 | +++ linux/fs/aufs/super.c 2020-01-27 10:57:18.178871751 +0100 |
fbc438ed | 29437 | @@ -0,0 +1,1047 @@ |
cd7a4cd9 | 29438 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 29439 | +/* |
d58c55f2 | 29440 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 29441 | + * |
29442 | + * This program, aufs is free software; you can redistribute it and/or modify | |
29443 | + * it under the terms of the GNU General Public License as published by | |
29444 | + * the Free Software Foundation; either version 2 of the License, or | |
29445 | + * (at your option) any later version. | |
dece6358 AM |
29446 | + * |
29447 | + * This program is distributed in the hope that it will be useful, | |
29448 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
29449 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
29450 | + * GNU General Public License for more details. | |
29451 | + * | |
29452 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 29453 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 29454 | + */ |
29455 | + | |
29456 | +/* | |
29457 | + * mount and super_block operations | |
29458 | + */ | |
29459 | + | |
eca801bf | 29460 | +#include <linux/iversion.h> |
f6c5ef8b | 29461 | +#include <linux/mm.h> |
1facf9fc | 29462 | +#include <linux/seq_file.h> |
29463 | +#include <linux/statfs.h> | |
7f207e10 | 29464 | +#include <linux/vmalloc.h> |
1facf9fc | 29465 | +#include "aufs.h" |
29466 | + | |
29467 | +/* | |
29468 | + * super_operations | |
29469 | + */ | |
29470 | +static struct inode *aufs_alloc_inode(struct super_block *sb __maybe_unused) | |
29471 | +{ | |
29472 | + struct au_icntnr *c; | |
29473 | + | |
29474 | + c = au_cache_alloc_icntnr(); | |
29475 | + if (c) { | |
027c5e7a | 29476 | + au_icntnr_init(c); |
be118d29 | 29477 | + inode_set_iversion(&c->vfs_inode, 1); /* sigen(sb); */ |
1facf9fc | 29478 | + c->iinfo.ii_hinode = NULL; |
29479 | + return &c->vfs_inode; | |
29480 | + } | |
29481 | + return NULL; | |
29482 | +} | |
29483 | + | |
29484 | +static void aufs_destroy_inode(struct inode *inode) | |
29485 | +{ | |
5afbbe0d AM |
29486 | + if (!au_is_bad_inode(inode)) |
29487 | + au_iinfo_fin(inode); | |
fbc438ed JR |
29488 | +} |
29489 | + | |
29490 | +static void aufs_free_inode(struct inode *inode) | |
29491 | +{ | |
29492 | + au_cache_free_icntnr(container_of(inode, struct au_icntnr, vfs_inode)); | |
1facf9fc | 29493 | +} |
29494 | + | |
29495 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino) | |
29496 | +{ | |
29497 | + struct inode *inode; | |
29498 | + int err; | |
29499 | + | |
29500 | + inode = iget_locked(sb, ino); | |
29501 | + if (unlikely(!inode)) { | |
29502 | + inode = ERR_PTR(-ENOMEM); | |
29503 | + goto out; | |
29504 | + } | |
29505 | + if (!(inode->i_state & I_NEW)) | |
29506 | + goto out; | |
29507 | + | |
29508 | + err = au_xigen_new(inode); | |
29509 | + if (!err) | |
29510 | + err = au_iinfo_init(inode); | |
29511 | + if (!err) | |
be118d29 | 29512 | + inode_inc_iversion(inode); |
1facf9fc | 29513 | + else { |
29514 | + iget_failed(inode); | |
29515 | + inode = ERR_PTR(err); | |
29516 | + } | |
29517 | + | |
4f0767ce | 29518 | +out: |
1facf9fc | 29519 | + /* never return NULL */ |
29520 | + AuDebugOn(!inode); | |
29521 | + AuTraceErrPtr(inode); | |
29522 | + return inode; | |
29523 | +} | |
29524 | + | |
29525 | +/* lock free root dinfo */ | |
29526 | +static int au_show_brs(struct seq_file *seq, struct super_block *sb) | |
29527 | +{ | |
29528 | + int err; | |
5afbbe0d | 29529 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 29530 | + struct path path; |
4a4d8108 | 29531 | + struct au_hdentry *hdp; |
1facf9fc | 29532 | + struct au_branch *br; |
076b876e | 29533 | + au_br_perm_str_t perm; |
1facf9fc | 29534 | + |
29535 | + err = 0; | |
5afbbe0d AM |
29536 | + bbot = au_sbbot(sb); |
29537 | + bindex = 0; | |
29538 | + hdp = au_hdentry(au_di(sb->s_root), bindex); | |
29539 | + for (; !err && bindex <= bbot; bindex++, hdp++) { | |
1facf9fc | 29540 | + br = au_sbr(sb, bindex); |
86dc4139 | 29541 | + path.mnt = au_br_mnt(br); |
5afbbe0d | 29542 | + path.dentry = hdp->hd_dentry; |
1facf9fc | 29543 | + err = au_seq_path(seq, &path); |
79b8bda9 | 29544 | + if (!err) { |
076b876e | 29545 | + au_optstr_br_perm(&perm, br->br_perm); |
79b8bda9 | 29546 | + seq_printf(seq, "=%s", perm.a); |
5afbbe0d | 29547 | + if (bindex != bbot) |
79b8bda9 | 29548 | + seq_putc(seq, ':'); |
1e00d052 | 29549 | + } |
1facf9fc | 29550 | + } |
79b8bda9 AM |
29551 | + if (unlikely(err || seq_has_overflowed(seq))) |
29552 | + err = -E2BIG; | |
1facf9fc | 29553 | + |
29554 | + return err; | |
29555 | +} | |
29556 | + | |
f2c43d5f AM |
29557 | +static void au_gen_fmt(char *fmt, int len __maybe_unused, const char *pat, |
29558 | + const char *append) | |
29559 | +{ | |
29560 | + char *p; | |
29561 | + | |
29562 | + p = fmt; | |
29563 | + while (*pat != ':') | |
29564 | + *p++ = *pat++; | |
29565 | + *p++ = *pat++; | |
29566 | + strcpy(p, append); | |
29567 | + AuDebugOn(strlen(fmt) >= len); | |
29568 | +} | |
29569 | + | |
1facf9fc | 29570 | +static void au_show_wbr_create(struct seq_file *m, int v, |
29571 | + struct au_sbinfo *sbinfo) | |
29572 | +{ | |
29573 | + const char *pat; | |
f2c43d5f AM |
29574 | + char fmt[32]; |
29575 | + struct au_wbr_mfs *mfs; | |
1facf9fc | 29576 | + |
dece6358 AM |
29577 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
29578 | + | |
c2b27bf2 | 29579 | + seq_puts(m, ",create="); |
1facf9fc | 29580 | + pat = au_optstr_wbr_create(v); |
f2c43d5f | 29581 | + mfs = &sbinfo->si_wbr_mfs; |
1facf9fc | 29582 | + switch (v) { |
29583 | + case AuWbrCreate_TDP: | |
29584 | + case AuWbrCreate_RR: | |
29585 | + case AuWbrCreate_MFS: | |
29586 | + case AuWbrCreate_PMFS: | |
c2b27bf2 | 29587 | + seq_puts(m, pat); |
1facf9fc | 29588 | + break; |
f2c43d5f AM |
29589 | + case AuWbrCreate_MFSRR: |
29590 | + case AuWbrCreate_TDMFS: | |
29591 | + case AuWbrCreate_PMFSRR: | |
29592 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu"); | |
29593 | + seq_printf(m, fmt, mfs->mfsrr_watermark); | |
1facf9fc | 29594 | + break; |
f2c43d5f | 29595 | + case AuWbrCreate_MFSV: |
1facf9fc | 29596 | + case AuWbrCreate_PMFSV: |
f2c43d5f AM |
29597 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%lu"); |
29598 | + seq_printf(m, fmt, | |
29599 | + jiffies_to_msecs(mfs->mfs_expire) | |
e49829fe | 29600 | + / MSEC_PER_SEC); |
1facf9fc | 29601 | + break; |
1facf9fc | 29602 | + case AuWbrCreate_MFSRRV: |
f2c43d5f | 29603 | + case AuWbrCreate_TDMFSV: |
392086de | 29604 | + case AuWbrCreate_PMFSRRV: |
f2c43d5f AM |
29605 | + au_gen_fmt(fmt, sizeof(fmt), pat, "%llu:%lu"); |
29606 | + seq_printf(m, fmt, mfs->mfsrr_watermark, | |
29607 | + jiffies_to_msecs(mfs->mfs_expire) / MSEC_PER_SEC); | |
392086de | 29608 | + break; |
f2c43d5f AM |
29609 | + default: |
29610 | + BUG(); | |
1facf9fc | 29611 | + } |
29612 | +} | |
29613 | + | |
7eafdf33 | 29614 | +static int au_show_xino(struct seq_file *seq, struct super_block *sb) |
1facf9fc | 29615 | +{ |
29616 | +#ifdef CONFIG_SYSFS | |
29617 | + return 0; | |
29618 | +#else | |
29619 | + int err; | |
29620 | + const int len = sizeof(AUFS_XINO_FNAME) - 1; | |
29621 | + aufs_bindex_t bindex, brid; | |
1facf9fc | 29622 | + struct qstr *name; |
29623 | + struct file *f; | |
29624 | + struct dentry *d, *h_root; | |
acd2b654 | 29625 | + struct au_branch *br; |
1facf9fc | 29626 | + |
dece6358 AM |
29627 | + AuRwMustAnyLock(&sbinfo->si_rwsem); |
29628 | + | |
1facf9fc | 29629 | + err = 0; |
1facf9fc | 29630 | + f = au_sbi(sb)->si_xib; |
29631 | + if (!f) | |
29632 | + goto out; | |
29633 | + | |
29634 | + /* stop printing the default xino path on the first writable branch */ | |
29635 | + h_root = NULL; | |
acd2b654 AM |
29636 | + bindex = au_xi_root(sb, f->f_path.dentry); |
29637 | + if (bindex >= 0) { | |
29638 | + br = au_sbr_sb(sb, bindex); | |
29639 | + h_root = au_br_dentry(br); | |
1facf9fc | 29640 | + } |
acd2b654 | 29641 | + |
2000de60 | 29642 | + d = f->f_path.dentry; |
1facf9fc | 29643 | + name = &d->d_name; |
29644 | + /* safe ->d_parent because the file is unlinked */ | |
29645 | + if (d->d_parent == h_root | |
29646 | + && name->len == len | |
29647 | + && !memcmp(name->name, AUFS_XINO_FNAME, len)) | |
29648 | + goto out; | |
29649 | + | |
29650 | + seq_puts(seq, ",xino="); | |
29651 | + err = au_xino_path(seq, f); | |
29652 | + | |
4f0767ce | 29653 | +out: |
1facf9fc | 29654 | + return err; |
29655 | +#endif | |
29656 | +} | |
29657 | + | |
29658 | +/* seq_file will re-call me in case of too long string */ | |
7eafdf33 | 29659 | +static int aufs_show_options(struct seq_file *m, struct dentry *dentry) |
1facf9fc | 29660 | +{ |
027c5e7a | 29661 | + int err; |
1facf9fc | 29662 | + unsigned int mnt_flags, v; |
29663 | + struct super_block *sb; | |
29664 | + struct au_sbinfo *sbinfo; | |
29665 | + | |
29666 | +#define AuBool(name, str) do { \ | |
29667 | + v = au_opt_test(mnt_flags, name); \ | |
29668 | + if (v != au_opt_test(AuOpt_Def, name)) \ | |
29669 | + seq_printf(m, ",%s" #str, v ? "" : "no"); \ | |
29670 | +} while (0) | |
29671 | + | |
29672 | +#define AuStr(name, str) do { \ | |
29673 | + v = mnt_flags & AuOptMask_##name; \ | |
29674 | + if (v != (AuOpt_Def & AuOptMask_##name)) \ | |
29675 | + seq_printf(m, "," #str "=%s", au_optstr_##str(v)); \ | |
29676 | +} while (0) | |
29677 | + | |
29678 | +#define AuUInt(name, str, val) do { \ | |
29679 | + if (val != AUFS_##name##_DEF) \ | |
29680 | + seq_printf(m, "," #str "=%u", val); \ | |
29681 | +} while (0) | |
29682 | + | |
7eafdf33 | 29683 | + sb = dentry->d_sb; |
2121bcd9 | 29684 | + if (sb->s_flags & SB_POSIXACL) |
c1595e42 | 29685 | + seq_puts(m, ",acl"); |
43982f53 | 29686 | +#if 0 /* reserved for future use */ |
be118d29 JR |
29687 | + if (sb->s_flags & SB_I_VERSION) |
29688 | + seq_puts(m, ",i_version"); | |
29689 | +#endif | |
c1595e42 JR |
29690 | + |
29691 | + /* lock free root dinfo */ | |
1facf9fc | 29692 | + si_noflush_read_lock(sb); |
29693 | + sbinfo = au_sbi(sb); | |
29694 | + seq_printf(m, ",si=%lx", sysaufs_si_id(sbinfo)); | |
29695 | + | |
29696 | + mnt_flags = au_mntflags(sb); | |
29697 | + if (au_opt_test(mnt_flags, XINO)) { | |
7eafdf33 | 29698 | + err = au_show_xino(m, sb); |
1facf9fc | 29699 | + if (unlikely(err)) |
29700 | + goto out; | |
29701 | + } else | |
29702 | + seq_puts(m, ",noxino"); | |
29703 | + | |
29704 | + AuBool(TRUNC_XINO, trunc_xino); | |
29705 | + AuStr(UDBA, udba); | |
dece6358 | 29706 | + AuBool(SHWH, shwh); |
1facf9fc | 29707 | + AuBool(PLINK, plink); |
4a4d8108 | 29708 | + AuBool(DIO, dio); |
076b876e | 29709 | + AuBool(DIRPERM1, dirperm1); |
1facf9fc | 29710 | + |
29711 | + v = sbinfo->si_wbr_create; | |
29712 | + if (v != AuWbrCreate_Def) | |
29713 | + au_show_wbr_create(m, v, sbinfo); | |
29714 | + | |
29715 | + v = sbinfo->si_wbr_copyup; | |
29716 | + if (v != AuWbrCopyup_Def) | |
29717 | + seq_printf(m, ",cpup=%s", au_optstr_wbr_copyup(v)); | |
29718 | + | |
29719 | + v = au_opt_test(mnt_flags, ALWAYS_DIROPQ); | |
29720 | + if (v != au_opt_test(AuOpt_Def, ALWAYS_DIROPQ)) | |
29721 | + seq_printf(m, ",diropq=%c", v ? 'a' : 'w'); | |
29722 | + | |
29723 | + AuUInt(DIRWH, dirwh, sbinfo->si_dirwh); | |
29724 | + | |
027c5e7a AM |
29725 | + v = jiffies_to_msecs(sbinfo->si_rdcache) / MSEC_PER_SEC; |
29726 | + AuUInt(RDCACHE, rdcache, v); | |
1facf9fc | 29727 | + |
29728 | + AuUInt(RDBLK, rdblk, sbinfo->si_rdblk); | |
29729 | + AuUInt(RDHASH, rdhash, sbinfo->si_rdhash); | |
29730 | + | |
076b876e AM |
29731 | + au_fhsm_show(m, sbinfo); |
29732 | + | |
8b6a4947 | 29733 | + AuBool(DIRREN, dirren); |
1facf9fc | 29734 | + AuBool(SUM, sum); |
29735 | + /* AuBool(SUM_W, wsum); */ | |
29736 | + AuBool(WARN_PERM, warn_perm); | |
29737 | + AuBool(VERBOSE, verbose); | |
29738 | + | |
4f0767ce | 29739 | +out: |
1facf9fc | 29740 | + /* be sure to print "br:" last */ |
29741 | + if (!sysaufs_brs) { | |
29742 | + seq_puts(m, ",br:"); | |
29743 | + au_show_brs(m, sb); | |
29744 | + } | |
29745 | + si_read_unlock(sb); | |
29746 | + return 0; | |
29747 | + | |
1facf9fc | 29748 | +#undef AuBool |
29749 | +#undef AuStr | |
4a4d8108 | 29750 | +#undef AuUInt |
1facf9fc | 29751 | +} |
29752 | + | |
29753 | +/* ---------------------------------------------------------------------- */ | |
29754 | + | |
29755 | +/* sum mode which returns the summation for statfs(2) */ | |
29756 | + | |
29757 | +static u64 au_add_till_max(u64 a, u64 b) | |
29758 | +{ | |
29759 | + u64 old; | |
29760 | + | |
29761 | + old = a; | |
29762 | + a += b; | |
92d182d2 AM |
29763 | + if (old <= a) |
29764 | + return a; | |
29765 | + return ULLONG_MAX; | |
29766 | +} | |
29767 | + | |
29768 | +static u64 au_mul_till_max(u64 a, long mul) | |
29769 | +{ | |
29770 | + u64 old; | |
29771 | + | |
29772 | + old = a; | |
29773 | + a *= mul; | |
29774 | + if (old <= a) | |
1facf9fc | 29775 | + return a; |
29776 | + return ULLONG_MAX; | |
29777 | +} | |
29778 | + | |
29779 | +static int au_statfs_sum(struct super_block *sb, struct kstatfs *buf) | |
29780 | +{ | |
29781 | + int err; | |
92d182d2 | 29782 | + long bsize, factor; |
1facf9fc | 29783 | + u64 blocks, bfree, bavail, files, ffree; |
5afbbe0d | 29784 | + aufs_bindex_t bbot, bindex, i; |
1facf9fc | 29785 | + unsigned char shared; |
7f207e10 | 29786 | + struct path h_path; |
1facf9fc | 29787 | + struct super_block *h_sb; |
29788 | + | |
92d182d2 AM |
29789 | + err = 0; |
29790 | + bsize = LONG_MAX; | |
29791 | + files = 0; | |
29792 | + ffree = 0; | |
1facf9fc | 29793 | + blocks = 0; |
29794 | + bfree = 0; | |
29795 | + bavail = 0; | |
5afbbe0d AM |
29796 | + bbot = au_sbbot(sb); |
29797 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
7f207e10 AM |
29798 | + h_path.mnt = au_sbr_mnt(sb, bindex); |
29799 | + h_sb = h_path.mnt->mnt_sb; | |
1facf9fc | 29800 | + shared = 0; |
92d182d2 | 29801 | + for (i = 0; !shared && i < bindex; i++) |
1facf9fc | 29802 | + shared = (au_sbr_sb(sb, i) == h_sb); |
29803 | + if (shared) | |
29804 | + continue; | |
29805 | + | |
29806 | + /* sb->s_root for NFS is unreliable */ | |
7f207e10 AM |
29807 | + h_path.dentry = h_path.mnt->mnt_root; |
29808 | + err = vfs_statfs(&h_path, buf); | |
1facf9fc | 29809 | + if (unlikely(err)) |
29810 | + goto out; | |
29811 | + | |
92d182d2 AM |
29812 | + if (bsize > buf->f_bsize) { |
29813 | + /* | |
29814 | + * we will reduce bsize, so we have to expand blocks | |
29815 | + * etc. to match them again | |
29816 | + */ | |
29817 | + factor = (bsize / buf->f_bsize); | |
29818 | + blocks = au_mul_till_max(blocks, factor); | |
29819 | + bfree = au_mul_till_max(bfree, factor); | |
29820 | + bavail = au_mul_till_max(bavail, factor); | |
29821 | + bsize = buf->f_bsize; | |
29822 | + } | |
29823 | + | |
29824 | + factor = (buf->f_bsize / bsize); | |
29825 | + blocks = au_add_till_max(blocks, | |
29826 | + au_mul_till_max(buf->f_blocks, factor)); | |
29827 | + bfree = au_add_till_max(bfree, | |
29828 | + au_mul_till_max(buf->f_bfree, factor)); | |
29829 | + bavail = au_add_till_max(bavail, | |
29830 | + au_mul_till_max(buf->f_bavail, factor)); | |
1facf9fc | 29831 | + files = au_add_till_max(files, buf->f_files); |
29832 | + ffree = au_add_till_max(ffree, buf->f_ffree); | |
29833 | + } | |
29834 | + | |
92d182d2 | 29835 | + buf->f_bsize = bsize; |
1facf9fc | 29836 | + buf->f_blocks = blocks; |
29837 | + buf->f_bfree = bfree; | |
29838 | + buf->f_bavail = bavail; | |
29839 | + buf->f_files = files; | |
29840 | + buf->f_ffree = ffree; | |
92d182d2 | 29841 | + buf->f_frsize = 0; |
1facf9fc | 29842 | + |
4f0767ce | 29843 | +out: |
1facf9fc | 29844 | + return err; |
29845 | +} | |
29846 | + | |
29847 | +static int aufs_statfs(struct dentry *dentry, struct kstatfs *buf) | |
29848 | +{ | |
29849 | + int err; | |
7f207e10 | 29850 | + struct path h_path; |
1facf9fc | 29851 | + struct super_block *sb; |
29852 | + | |
29853 | + /* lock free root dinfo */ | |
29854 | + sb = dentry->d_sb; | |
29855 | + si_noflush_read_lock(sb); | |
7f207e10 | 29856 | + if (!au_opt_test(au_mntflags(sb), SUM)) { |
1facf9fc | 29857 | + /* sb->s_root for NFS is unreliable */ |
7f207e10 AM |
29858 | + h_path.mnt = au_sbr_mnt(sb, 0); |
29859 | + h_path.dentry = h_path.mnt->mnt_root; | |
29860 | + err = vfs_statfs(&h_path, buf); | |
29861 | + } else | |
1facf9fc | 29862 | + err = au_statfs_sum(sb, buf); |
29863 | + si_read_unlock(sb); | |
29864 | + | |
29865 | + if (!err) { | |
29866 | + buf->f_type = AUFS_SUPER_MAGIC; | |
4a4d8108 | 29867 | + buf->f_namelen = AUFS_MAX_NAMELEN; |
1facf9fc | 29868 | + memset(&buf->f_fsid, 0, sizeof(buf->f_fsid)); |
29869 | + } | |
29870 | + /* buf->f_bsize = buf->f_blocks = buf->f_bfree = buf->f_bavail = -1; */ | |
29871 | + | |
29872 | + return err; | |
29873 | +} | |
29874 | + | |
29875 | +/* ---------------------------------------------------------------------- */ | |
29876 | + | |
537831f9 AM |
29877 | +static int aufs_sync_fs(struct super_block *sb, int wait) |
29878 | +{ | |
29879 | + int err, e; | |
5afbbe0d | 29880 | + aufs_bindex_t bbot, bindex; |
537831f9 AM |
29881 | + struct au_branch *br; |
29882 | + struct super_block *h_sb; | |
29883 | + | |
29884 | + err = 0; | |
29885 | + si_noflush_read_lock(sb); | |
5afbbe0d AM |
29886 | + bbot = au_sbbot(sb); |
29887 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
537831f9 AM |
29888 | + br = au_sbr(sb, bindex); |
29889 | + if (!au_br_writable(br->br_perm)) | |
29890 | + continue; | |
29891 | + | |
29892 | + h_sb = au_sbr_sb(sb, bindex); | |
a2654f78 AM |
29893 | + e = vfsub_sync_filesystem(h_sb, wait); |
29894 | + if (unlikely(e && !err)) | |
29895 | + err = e; | |
29896 | + /* go on even if an error happens */ | |
537831f9 AM |
29897 | + } |
29898 | + si_read_unlock(sb); | |
29899 | + | |
29900 | + return err; | |
29901 | +} | |
29902 | + | |
29903 | +/* ---------------------------------------------------------------------- */ | |
29904 | + | |
1facf9fc | 29905 | +/* final actions when unmounting a file system */ |
29906 | +static void aufs_put_super(struct super_block *sb) | |
29907 | +{ | |
29908 | + struct au_sbinfo *sbinfo; | |
29909 | + | |
29910 | + sbinfo = au_sbi(sb); | |
062440b3 AM |
29911 | + if (sbinfo) |
29912 | + kobject_put(&sbinfo->si_kobj); | |
1facf9fc | 29913 | +} |
29914 | + | |
29915 | +/* ---------------------------------------------------------------------- */ | |
29916 | + | |
79b8bda9 AM |
29917 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, |
29918 | + struct super_block *sb, void *arg) | |
7f207e10 AM |
29919 | +{ |
29920 | + void *array; | |
076b876e | 29921 | + unsigned long long n, sz; |
7f207e10 AM |
29922 | + |
29923 | + array = NULL; | |
29924 | + n = 0; | |
29925 | + if (!*hint) | |
29926 | + goto out; | |
29927 | + | |
29928 | + if (*hint > ULLONG_MAX / sizeof(array)) { | |
29929 | + array = ERR_PTR(-EMFILE); | |
29930 | + pr_err("hint %llu\n", *hint); | |
29931 | + goto out; | |
29932 | + } | |
29933 | + | |
076b876e AM |
29934 | + sz = sizeof(array) * *hint; |
29935 | + array = kzalloc(sz, GFP_NOFS); | |
7f207e10 | 29936 | + if (unlikely(!array)) |
076b876e | 29937 | + array = vzalloc(sz); |
7f207e10 AM |
29938 | + if (unlikely(!array)) { |
29939 | + array = ERR_PTR(-ENOMEM); | |
29940 | + goto out; | |
29941 | + } | |
29942 | + | |
79b8bda9 | 29943 | + n = cb(sb, array, *hint, arg); |
7f207e10 AM |
29944 | + AuDebugOn(n > *hint); |
29945 | + | |
29946 | +out: | |
29947 | + *hint = n; | |
29948 | + return array; | |
29949 | +} | |
29950 | + | |
79b8bda9 | 29951 | +static unsigned long long au_iarray_cb(struct super_block *sb, void *a, |
7f207e10 AM |
29952 | + unsigned long long max __maybe_unused, |
29953 | + void *arg) | |
29954 | +{ | |
29955 | + unsigned long long n; | |
29956 | + struct inode **p, *inode; | |
29957 | + struct list_head *head; | |
29958 | + | |
29959 | + n = 0; | |
29960 | + p = a; | |
29961 | + head = arg; | |
79b8bda9 | 29962 | + spin_lock(&sb->s_inode_list_lock); |
7f207e10 | 29963 | + list_for_each_entry(inode, head, i_sb_list) { |
5afbbe0d AM |
29964 | + if (!au_is_bad_inode(inode) |
29965 | + && au_ii(inode)->ii_btop >= 0) { | |
2cbb1c4b JR |
29966 | + spin_lock(&inode->i_lock); |
29967 | + if (atomic_read(&inode->i_count)) { | |
29968 | + au_igrab(inode); | |
29969 | + *p++ = inode; | |
29970 | + n++; | |
29971 | + AuDebugOn(n > max); | |
29972 | + } | |
29973 | + spin_unlock(&inode->i_lock); | |
7f207e10 AM |
29974 | + } |
29975 | + } | |
79b8bda9 | 29976 | + spin_unlock(&sb->s_inode_list_lock); |
7f207e10 AM |
29977 | + |
29978 | + return n; | |
29979 | +} | |
29980 | + | |
29981 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max) | |
29982 | +{ | |
acd2b654 AM |
29983 | + struct au_sbinfo *sbi; |
29984 | + | |
29985 | + sbi = au_sbi(sb); | |
29986 | + *max = au_lcnt_read(&sbi->si_ninodes, /*do_rev*/1); | |
79b8bda9 | 29987 | + return au_array_alloc(max, au_iarray_cb, sb, &sb->s_inodes); |
7f207e10 AM |
29988 | +} |
29989 | + | |
29990 | +void au_iarray_free(struct inode **a, unsigned long long max) | |
29991 | +{ | |
29992 | + unsigned long long ull; | |
29993 | + | |
29994 | + for (ull = 0; ull < max; ull++) | |
29995 | + iput(a[ull]); | |
be52b249 | 29996 | + kvfree(a); |
7f207e10 AM |
29997 | +} |
29998 | + | |
29999 | +/* ---------------------------------------------------------------------- */ | |
30000 | + | |
1facf9fc | 30001 | +/* |
30002 | + * refresh dentry and inode at remount time. | |
30003 | + */ | |
027c5e7a AM |
30004 | +/* todo: consolidate with simple_reval_dpath() and au_reval_for_attr() */ |
30005 | +static int au_do_refresh(struct dentry *dentry, unsigned int dir_flags, | |
30006 | + struct dentry *parent) | |
1facf9fc | 30007 | +{ |
30008 | + int err; | |
1facf9fc | 30009 | + |
30010 | + di_write_lock_child(dentry); | |
1facf9fc | 30011 | + di_read_lock_parent(parent, AuLock_IR); |
027c5e7a AM |
30012 | + err = au_refresh_dentry(dentry, parent); |
30013 | + if (!err && dir_flags) | |
5527c038 | 30014 | + au_hn_reset(d_inode(dentry), dir_flags); |
1facf9fc | 30015 | + di_read_unlock(parent, AuLock_IR); |
1facf9fc | 30016 | + di_write_unlock(dentry); |
30017 | + | |
30018 | + return err; | |
30019 | +} | |
30020 | + | |
027c5e7a AM |
30021 | +static int au_do_refresh_d(struct dentry *dentry, unsigned int sigen, |
30022 | + struct au_sbinfo *sbinfo, | |
b95c5147 | 30023 | + const unsigned int dir_flags, unsigned int do_idop) |
1facf9fc | 30024 | +{ |
027c5e7a AM |
30025 | + int err; |
30026 | + struct dentry *parent; | |
027c5e7a AM |
30027 | + |
30028 | + err = 0; | |
30029 | + parent = dget_parent(dentry); | |
30030 | + if (!au_digen_test(parent, sigen) && au_digen_test(dentry, sigen)) { | |
5527c038 JR |
30031 | + if (d_really_is_positive(dentry)) { |
30032 | + if (!d_is_dir(dentry)) | |
027c5e7a AM |
30033 | + err = au_do_refresh(dentry, /*dir_flags*/0, |
30034 | + parent); | |
30035 | + else { | |
30036 | + err = au_do_refresh(dentry, dir_flags, parent); | |
30037 | + if (unlikely(err)) | |
30038 | + au_fset_si(sbinfo, FAILED_REFRESH_DIR); | |
30039 | + } | |
30040 | + } else | |
30041 | + err = au_do_refresh(dentry, /*dir_flags*/0, parent); | |
30042 | + AuDbgDentry(dentry); | |
30043 | + } | |
30044 | + dput(parent); | |
30045 | + | |
79b8bda9 | 30046 | + if (!err) { |
b95c5147 | 30047 | + if (do_idop) |
79b8bda9 AM |
30048 | + au_refresh_dop(dentry, /*force_reval*/0); |
30049 | + } else | |
30050 | + au_refresh_dop(dentry, /*force_reval*/1); | |
30051 | + | |
027c5e7a AM |
30052 | + AuTraceErr(err); |
30053 | + return err; | |
1facf9fc | 30054 | +} |
30055 | + | |
b95c5147 | 30056 | +static int au_refresh_d(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 30057 | +{ |
30058 | + int err, i, j, ndentry, e; | |
027c5e7a | 30059 | + unsigned int sigen; |
1facf9fc | 30060 | + struct au_dcsub_pages dpages; |
30061 | + struct au_dpage *dpage; | |
027c5e7a AM |
30062 | + struct dentry **dentries, *d; |
30063 | + struct au_sbinfo *sbinfo; | |
30064 | + struct dentry *root = sb->s_root; | |
5527c038 | 30065 | + const unsigned int dir_flags = au_hi_flags(d_inode(root), /*isdir*/1); |
1facf9fc | 30066 | + |
b95c5147 | 30067 | + if (do_idop) |
79b8bda9 AM |
30068 | + au_refresh_dop(root, /*force_reval*/0); |
30069 | + | |
027c5e7a AM |
30070 | + err = au_dpages_init(&dpages, GFP_NOFS); |
30071 | + if (unlikely(err)) | |
1facf9fc | 30072 | + goto out; |
027c5e7a AM |
30073 | + err = au_dcsub_pages(&dpages, root, NULL, NULL); |
30074 | + if (unlikely(err)) | |
1facf9fc | 30075 | + goto out_dpages; |
1facf9fc | 30076 | + |
027c5e7a AM |
30077 | + sigen = au_sigen(sb); |
30078 | + sbinfo = au_sbi(sb); | |
30079 | + for (i = 0; i < dpages.ndpage; i++) { | |
1facf9fc | 30080 | + dpage = dpages.dpages + i; |
30081 | + dentries = dpage->dentries; | |
30082 | + ndentry = dpage->ndentry; | |
027c5e7a | 30083 | + for (j = 0; j < ndentry; j++) { |
1facf9fc | 30084 | + d = dentries[j]; |
79b8bda9 | 30085 | + e = au_do_refresh_d(d, sigen, sbinfo, dir_flags, |
b95c5147 | 30086 | + do_idop); |
027c5e7a AM |
30087 | + if (unlikely(e && !err)) |
30088 | + err = e; | |
30089 | + /* go on even err */ | |
1facf9fc | 30090 | + } |
30091 | + } | |
30092 | + | |
4f0767ce | 30093 | +out_dpages: |
1facf9fc | 30094 | + au_dpages_free(&dpages); |
4f0767ce | 30095 | +out: |
1facf9fc | 30096 | + return err; |
30097 | +} | |
30098 | + | |
b95c5147 | 30099 | +static int au_refresh_i(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 30100 | +{ |
027c5e7a AM |
30101 | + int err, e; |
30102 | + unsigned int sigen; | |
30103 | + unsigned long long max, ull; | |
30104 | + struct inode *inode, **array; | |
1facf9fc | 30105 | + |
027c5e7a AM |
30106 | + array = au_iarray_alloc(sb, &max); |
30107 | + err = PTR_ERR(array); | |
30108 | + if (IS_ERR(array)) | |
30109 | + goto out; | |
1facf9fc | 30110 | + |
30111 | + err = 0; | |
027c5e7a AM |
30112 | + sigen = au_sigen(sb); |
30113 | + for (ull = 0; ull < max; ull++) { | |
30114 | + inode = array[ull]; | |
076b876e AM |
30115 | + if (unlikely(!inode)) |
30116 | + break; | |
b95c5147 AM |
30117 | + |
30118 | + e = 0; | |
30119 | + ii_write_lock_child(inode); | |
537831f9 | 30120 | + if (au_iigen(inode, NULL) != sigen) { |
027c5e7a | 30121 | + e = au_refresh_hinode_self(inode); |
1facf9fc | 30122 | + if (unlikely(e)) { |
b95c5147 | 30123 | + au_refresh_iop(inode, /*force_getattr*/1); |
027c5e7a | 30124 | + pr_err("error %d, i%lu\n", e, inode->i_ino); |
1facf9fc | 30125 | + if (!err) |
30126 | + err = e; | |
30127 | + /* go on even if err */ | |
30128 | + } | |
30129 | + } | |
b95c5147 AM |
30130 | + if (!e && do_idop) |
30131 | + au_refresh_iop(inode, /*force_getattr*/0); | |
30132 | + ii_write_unlock(inode); | |
1facf9fc | 30133 | + } |
30134 | + | |
027c5e7a | 30135 | + au_iarray_free(array, max); |
1facf9fc | 30136 | + |
4f0767ce | 30137 | +out: |
1facf9fc | 30138 | + return err; |
30139 | +} | |
30140 | + | |
b95c5147 | 30141 | +static void au_remount_refresh(struct super_block *sb, unsigned int do_idop) |
1facf9fc | 30142 | +{ |
027c5e7a AM |
30143 | + int err, e; |
30144 | + unsigned int udba; | |
5afbbe0d | 30145 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 30146 | + struct dentry *root; |
30147 | + struct inode *inode; | |
027c5e7a | 30148 | + struct au_branch *br; |
79b8bda9 | 30149 | + struct au_sbinfo *sbi; |
1facf9fc | 30150 | + |
30151 | + au_sigen_inc(sb); | |
79b8bda9 AM |
30152 | + sbi = au_sbi(sb); |
30153 | + au_fclr_si(sbi, FAILED_REFRESH_DIR); | |
1facf9fc | 30154 | + |
30155 | + root = sb->s_root; | |
30156 | + DiMustNoWaiters(root); | |
5527c038 | 30157 | + inode = d_inode(root); |
1facf9fc | 30158 | + IiMustNoWaiters(inode); |
1facf9fc | 30159 | + |
027c5e7a | 30160 | + udba = au_opt_udba(sb); |
5afbbe0d AM |
30161 | + bbot = au_sbbot(sb); |
30162 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
027c5e7a AM |
30163 | + br = au_sbr(sb, bindex); |
30164 | + err = au_hnotify_reset_br(udba, br, br->br_perm); | |
1facf9fc | 30165 | + if (unlikely(err)) |
027c5e7a AM |
30166 | + AuIOErr("hnotify failed on br %d, %d, ignored\n", |
30167 | + bindex, err); | |
30168 | + /* go on even if err */ | |
1facf9fc | 30169 | + } |
027c5e7a | 30170 | + au_hn_reset(inode, au_hi_flags(inode, /*isdir*/1)); |
1facf9fc | 30171 | + |
b95c5147 | 30172 | + if (do_idop) { |
79b8bda9 AM |
30173 | + if (au_ftest_si(sbi, NO_DREVAL)) { |
30174 | + AuDebugOn(sb->s_d_op == &aufs_dop_noreval); | |
30175 | + sb->s_d_op = &aufs_dop_noreval; | |
b95c5147 AM |
30176 | + AuDebugOn(sbi->si_iop_array == aufs_iop_nogetattr); |
30177 | + sbi->si_iop_array = aufs_iop_nogetattr; | |
79b8bda9 AM |
30178 | + } else { |
30179 | + AuDebugOn(sb->s_d_op == &aufs_dop); | |
30180 | + sb->s_d_op = &aufs_dop; | |
b95c5147 AM |
30181 | + AuDebugOn(sbi->si_iop_array == aufs_iop); |
30182 | + sbi->si_iop_array = aufs_iop; | |
79b8bda9 | 30183 | + } |
062440b3 | 30184 | + pr_info("reset to %ps and %ps\n", |
b95c5147 | 30185 | + sb->s_d_op, sbi->si_iop_array); |
79b8bda9 AM |
30186 | + } |
30187 | + | |
027c5e7a | 30188 | + di_write_unlock(root); |
b95c5147 AM |
30189 | + err = au_refresh_d(sb, do_idop); |
30190 | + e = au_refresh_i(sb, do_idop); | |
027c5e7a AM |
30191 | + if (unlikely(e && !err)) |
30192 | + err = e; | |
1facf9fc | 30193 | + /* aufs_write_lock() calls ..._child() */ |
30194 | + di_write_lock_child(root); | |
027c5e7a AM |
30195 | + |
30196 | + au_cpup_attr_all(inode, /*force*/1); | |
30197 | + | |
30198 | + if (unlikely(err)) | |
30199 | + AuIOErr("refresh failed, ignored, %d\n", err); | |
1facf9fc | 30200 | +} |
30201 | + | |
30202 | +/* stop extra interpretation of errno in mount(8), and strange error messages */ | |
30203 | +static int cvt_err(int err) | |
30204 | +{ | |
30205 | + AuTraceErr(err); | |
30206 | + | |
30207 | + switch (err) { | |
30208 | + case -ENOENT: | |
30209 | + case -ENOTDIR: | |
30210 | + case -EEXIST: | |
30211 | + case -EIO: | |
30212 | + err = -EINVAL; | |
30213 | + } | |
30214 | + return err; | |
30215 | +} | |
30216 | + | |
30217 | +static int aufs_remount_fs(struct super_block *sb, int *flags, char *data) | |
30218 | +{ | |
4a4d8108 AM |
30219 | + int err, do_dx; |
30220 | + unsigned int mntflags; | |
be52b249 AM |
30221 | + struct au_opts opts = { |
30222 | + .opt = NULL | |
30223 | + }; | |
1facf9fc | 30224 | + struct dentry *root; |
30225 | + struct inode *inode; | |
30226 | + struct au_sbinfo *sbinfo; | |
30227 | + | |
30228 | + err = 0; | |
30229 | + root = sb->s_root; | |
30230 | + if (!data || !*data) { | |
e49829fe JR |
30231 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
30232 | + if (!err) { | |
30233 | + di_write_lock_child(root); | |
30234 | + err = au_opts_verify(sb, *flags, /*pending*/0); | |
30235 | + aufs_write_unlock(root); | |
30236 | + } | |
1facf9fc | 30237 | + goto out; |
30238 | + } | |
30239 | + | |
30240 | + err = -ENOMEM; | |
1facf9fc | 30241 | + opts.opt = (void *)__get_free_page(GFP_NOFS); |
30242 | + if (unlikely(!opts.opt)) | |
30243 | + goto out; | |
30244 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
30245 | + opts.flags = AuOpts_REMOUNT; | |
30246 | + opts.sb_flags = *flags; | |
30247 | + | |
30248 | + /* parse it before aufs lock */ | |
30249 | + err = au_opts_parse(sb, data, &opts); | |
30250 | + if (unlikely(err)) | |
30251 | + goto out_opts; | |
30252 | + | |
30253 | + sbinfo = au_sbi(sb); | |
5527c038 | 30254 | + inode = d_inode(root); |
febd17d6 | 30255 | + inode_lock(inode); |
e49829fe JR |
30256 | + err = si_write_lock(sb, AuLock_FLUSH | AuLock_NOPLM); |
30257 | + if (unlikely(err)) | |
30258 | + goto out_mtx; | |
30259 | + di_write_lock_child(root); | |
1facf9fc | 30260 | + |
30261 | + /* au_opts_remount() may return an error */ | |
30262 | + err = au_opts_remount(sb, &opts); | |
30263 | + au_opts_free(&opts); | |
30264 | + | |
027c5e7a | 30265 | + if (au_ftest_opts(opts.flags, REFRESH)) |
b95c5147 | 30266 | + au_remount_refresh(sb, au_ftest_opts(opts.flags, REFRESH_IDOP)); |
1facf9fc | 30267 | + |
4a4d8108 AM |
30268 | + if (au_ftest_opts(opts.flags, REFRESH_DYAOP)) { |
30269 | + mntflags = au_mntflags(sb); | |
30270 | + do_dx = !!au_opt_test(mntflags, DIO); | |
30271 | + au_dy_arefresh(do_dx); | |
30272 | + } | |
30273 | + | |
076b876e | 30274 | + au_fhsm_wrote_all(sb, /*force*/1); /* ?? */ |
1facf9fc | 30275 | + aufs_write_unlock(root); |
953406b4 | 30276 | + |
e49829fe | 30277 | +out_mtx: |
febd17d6 | 30278 | + inode_unlock(inode); |
4f0767ce | 30279 | +out_opts: |
1c60b727 | 30280 | + free_page((unsigned long)opts.opt); |
4f0767ce | 30281 | +out: |
1facf9fc | 30282 | + err = cvt_err(err); |
30283 | + AuTraceErr(err); | |
30284 | + return err; | |
30285 | +} | |
30286 | + | |
4a4d8108 | 30287 | +static const struct super_operations aufs_sop = { |
1facf9fc | 30288 | + .alloc_inode = aufs_alloc_inode, |
30289 | + .destroy_inode = aufs_destroy_inode, | |
fbc438ed | 30290 | + .free_inode = aufs_free_inode, |
b752ccd1 | 30291 | + /* always deleting, no clearing */ |
1facf9fc | 30292 | + .drop_inode = generic_delete_inode, |
30293 | + .show_options = aufs_show_options, | |
30294 | + .statfs = aufs_statfs, | |
30295 | + .put_super = aufs_put_super, | |
537831f9 | 30296 | + .sync_fs = aufs_sync_fs, |
1facf9fc | 30297 | + .remount_fs = aufs_remount_fs |
30298 | +}; | |
30299 | + | |
30300 | +/* ---------------------------------------------------------------------- */ | |
30301 | + | |
30302 | +static int alloc_root(struct super_block *sb) | |
30303 | +{ | |
30304 | + int err; | |
30305 | + struct inode *inode; | |
30306 | + struct dentry *root; | |
30307 | + | |
30308 | + err = -ENOMEM; | |
30309 | + inode = au_iget_locked(sb, AUFS_ROOT_INO); | |
30310 | + err = PTR_ERR(inode); | |
30311 | + if (IS_ERR(inode)) | |
30312 | + goto out; | |
30313 | + | |
b95c5147 | 30314 | + inode->i_op = aufs_iop + AuIop_DIR; /* with getattr by default */ |
1facf9fc | 30315 | + inode->i_fop = &aufs_dir_fop; |
30316 | + inode->i_mode = S_IFDIR; | |
9dbd164d | 30317 | + set_nlink(inode, 2); |
1facf9fc | 30318 | + unlock_new_inode(inode); |
30319 | + | |
92d182d2 | 30320 | + root = d_make_root(inode); |
1facf9fc | 30321 | + if (unlikely(!root)) |
92d182d2 | 30322 | + goto out; |
1facf9fc | 30323 | + err = PTR_ERR(root); |
30324 | + if (IS_ERR(root)) | |
92d182d2 | 30325 | + goto out; |
1facf9fc | 30326 | + |
4a4d8108 | 30327 | + err = au_di_init(root); |
1facf9fc | 30328 | + if (!err) { |
30329 | + sb->s_root = root; | |
30330 | + return 0; /* success */ | |
30331 | + } | |
30332 | + dput(root); | |
1facf9fc | 30333 | + |
4f0767ce | 30334 | +out: |
1facf9fc | 30335 | + return err; |
1facf9fc | 30336 | +} |
30337 | + | |
30338 | +static int aufs_fill_super(struct super_block *sb, void *raw_data, | |
30339 | + int silent __maybe_unused) | |
30340 | +{ | |
30341 | + int err; | |
be52b249 AM |
30342 | + struct au_opts opts = { |
30343 | + .opt = NULL | |
30344 | + }; | |
79b8bda9 | 30345 | + struct au_sbinfo *sbinfo; |
1facf9fc | 30346 | + struct dentry *root; |
30347 | + struct inode *inode; | |
30348 | + char *arg = raw_data; | |
30349 | + | |
30350 | + if (unlikely(!arg || !*arg)) { | |
30351 | + err = -EINVAL; | |
4a4d8108 | 30352 | + pr_err("no arg\n"); |
1facf9fc | 30353 | + goto out; |
30354 | + } | |
30355 | + | |
30356 | + err = -ENOMEM; | |
1facf9fc | 30357 | + opts.opt = (void *)__get_free_page(GFP_NOFS); |
30358 | + if (unlikely(!opts.opt)) | |
30359 | + goto out; | |
30360 | + opts.max_opt = PAGE_SIZE / sizeof(*opts.opt); | |
30361 | + opts.sb_flags = sb->s_flags; | |
30362 | + | |
30363 | + err = au_si_alloc(sb); | |
30364 | + if (unlikely(err)) | |
30365 | + goto out_opts; | |
79b8bda9 | 30366 | + sbinfo = au_sbi(sb); |
1facf9fc | 30367 | + |
30368 | + /* all timestamps always follow the ones on the branch */ | |
2121bcd9 | 30369 | + sb->s_flags |= SB_NOATIME | SB_NODIRATIME; |
be118d29 | 30370 | + sb->s_flags |= SB_I_VERSION; /* do we really need this? */ |
1facf9fc | 30371 | + sb->s_op = &aufs_sop; |
027c5e7a | 30372 | + sb->s_d_op = &aufs_dop; |
1facf9fc | 30373 | + sb->s_magic = AUFS_SUPER_MAGIC; |
30374 | + sb->s_maxbytes = 0; | |
c1595e42 | 30375 | + sb->s_stack_depth = 1; |
1facf9fc | 30376 | + au_export_init(sb); |
f2c43d5f | 30377 | + au_xattr_init(sb); |
1facf9fc | 30378 | + |
30379 | + err = alloc_root(sb); | |
30380 | + if (unlikely(err)) { | |
30381 | + si_write_unlock(sb); | |
30382 | + goto out_info; | |
30383 | + } | |
30384 | + root = sb->s_root; | |
5527c038 | 30385 | + inode = d_inode(root); |
1facf9fc | 30386 | + |
30387 | + /* | |
30388 | + * actually we can parse options regardless aufs lock here. | |
30389 | + * but at remount time, parsing must be done before aufs lock. | |
30390 | + * so we follow the same rule. | |
30391 | + */ | |
30392 | + ii_write_lock_parent(inode); | |
30393 | + aufs_write_unlock(root); | |
30394 | + err = au_opts_parse(sb, arg, &opts); | |
30395 | + if (unlikely(err)) | |
30396 | + goto out_root; | |
30397 | + | |
30398 | + /* lock vfs_inode first, then aufs. */ | |
febd17d6 | 30399 | + inode_lock(inode); |
1facf9fc | 30400 | + aufs_write_lock(root); |
30401 | + err = au_opts_mount(sb, &opts); | |
30402 | + au_opts_free(&opts); | |
79b8bda9 AM |
30403 | + if (!err && au_ftest_si(sbinfo, NO_DREVAL)) { |
30404 | + sb->s_d_op = &aufs_dop_noreval; | |
062440b3 | 30405 | + pr_info("%ps\n", sb->s_d_op); |
79b8bda9 | 30406 | + au_refresh_dop(root, /*force_reval*/0); |
b95c5147 AM |
30407 | + sbinfo->si_iop_array = aufs_iop_nogetattr; |
30408 | + au_refresh_iop(inode, /*force_getattr*/0); | |
79b8bda9 | 30409 | + } |
1facf9fc | 30410 | + aufs_write_unlock(root); |
febd17d6 | 30411 | + inode_unlock(inode); |
4a4d8108 AM |
30412 | + if (!err) |
30413 | + goto out_opts; /* success */ | |
1facf9fc | 30414 | + |
4f0767ce | 30415 | +out_root: |
1facf9fc | 30416 | + dput(root); |
30417 | + sb->s_root = NULL; | |
4f0767ce | 30418 | +out_info: |
79b8bda9 | 30419 | + kobject_put(&sbinfo->si_kobj); |
1facf9fc | 30420 | + sb->s_fs_info = NULL; |
4f0767ce | 30421 | +out_opts: |
1c60b727 | 30422 | + free_page((unsigned long)opts.opt); |
4f0767ce | 30423 | +out: |
1facf9fc | 30424 | + AuTraceErr(err); |
30425 | + err = cvt_err(err); | |
30426 | + AuTraceErr(err); | |
30427 | + return err; | |
30428 | +} | |
30429 | + | |
30430 | +/* ---------------------------------------------------------------------- */ | |
30431 | + | |
027c5e7a AM |
30432 | +static struct dentry *aufs_mount(struct file_system_type *fs_type, int flags, |
30433 | + const char *dev_name __maybe_unused, | |
30434 | + void *raw_data) | |
1facf9fc | 30435 | +{ |
027c5e7a | 30436 | + struct dentry *root; |
1facf9fc | 30437 | + |
30438 | + /* all timestamps always follow the ones on the branch */ | |
30439 | + /* mnt->mnt_flags |= MNT_NOATIME | MNT_NODIRATIME; */ | |
027c5e7a AM |
30440 | + root = mount_nodev(fs_type, flags, raw_data, aufs_fill_super); |
30441 | + if (IS_ERR(root)) | |
30442 | + goto out; | |
30443 | + | |
062440b3 | 30444 | + au_sbilist_add(root->d_sb); |
027c5e7a AM |
30445 | + |
30446 | +out: | |
30447 | + return root; | |
1facf9fc | 30448 | +} |
30449 | + | |
e49829fe JR |
30450 | +static void aufs_kill_sb(struct super_block *sb) |
30451 | +{ | |
30452 | + struct au_sbinfo *sbinfo; | |
30453 | + | |
30454 | + sbinfo = au_sbi(sb); | |
30455 | + if (sbinfo) { | |
30456 | + au_sbilist_del(sb); | |
30457 | + aufs_write_lock(sb->s_root); | |
076b876e | 30458 | + au_fhsm_fin(sb); |
e49829fe JR |
30459 | + if (sbinfo->si_wbr_create_ops->fin) |
30460 | + sbinfo->si_wbr_create_ops->fin(sb); | |
30461 | + if (au_opt_test(sbinfo->si_mntflags, UDBA_HNOTIFY)) { | |
30462 | + au_opt_set_udba(sbinfo->si_mntflags, UDBA_NONE); | |
b95c5147 | 30463 | + au_remount_refresh(sb, /*do_idop*/0); |
e49829fe JR |
30464 | + } |
30465 | + if (au_opt_test(sbinfo->si_mntflags, PLINK)) | |
30466 | + au_plink_put(sb, /*verbose*/1); | |
30467 | + au_xino_clr(sb); | |
8b6a4947 | 30468 | + au_dr_opt_flush(sb); |
1e00d052 | 30469 | + sbinfo->si_sb = NULL; |
e49829fe | 30470 | + aufs_write_unlock(sb->s_root); |
e49829fe JR |
30471 | + au_nwt_flush(&sbinfo->si_nowait); |
30472 | + } | |
98d9a5b1 | 30473 | + kill_anon_super(sb); |
e49829fe JR |
30474 | +} |
30475 | + | |
1facf9fc | 30476 | +struct file_system_type aufs_fs_type = { |
30477 | + .name = AUFS_FSTYPE, | |
c06a8ce3 AM |
30478 | + /* a race between rename and others */ |
30479 | + .fs_flags = FS_RENAME_DOES_D_MOVE, | |
027c5e7a | 30480 | + .mount = aufs_mount, |
e49829fe | 30481 | + .kill_sb = aufs_kill_sb, |
1facf9fc | 30482 | + /* no need to __module_get() and module_put(). */ |
30483 | + .owner = THIS_MODULE, | |
30484 | +}; | |
7f207e10 | 30485 | diff -urN /usr/share/empty/fs/aufs/super.h linux/fs/aufs/super.h |
eca34b5c | 30486 | --- /usr/share/empty/fs/aufs/super.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 30487 | +++ linux/fs/aufs/super.h 2020-01-27 10:57:18.178871751 +0100 |
acd2b654 | 30488 | @@ -0,0 +1,589 @@ |
062440b3 | 30489 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 30490 | +/* |
d58c55f2 | 30491 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 30492 | + * |
30493 | + * This program, aufs is free software; you can redistribute it and/or modify | |
30494 | + * it under the terms of the GNU General Public License as published by | |
30495 | + * the Free Software Foundation; either version 2 of the License, or | |
30496 | + * (at your option) any later version. | |
dece6358 AM |
30497 | + * |
30498 | + * This program is distributed in the hope that it will be useful, | |
30499 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
30500 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
30501 | + * GNU General Public License for more details. | |
30502 | + * | |
30503 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 30504 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 30505 | + */ |
30506 | + | |
30507 | +/* | |
30508 | + * super_block operations | |
30509 | + */ | |
30510 | + | |
30511 | +#ifndef __AUFS_SUPER_H__ | |
30512 | +#define __AUFS_SUPER_H__ | |
30513 | + | |
30514 | +#ifdef __KERNEL__ | |
30515 | + | |
30516 | +#include <linux/fs.h> | |
5527c038 | 30517 | +#include <linux/kobject.h> |
8b6a4947 | 30518 | +#include "hbl.h" |
acd2b654 | 30519 | +#include "lcnt.h" |
1facf9fc | 30520 | +#include "rwsem.h" |
1facf9fc | 30521 | +#include "wkq.h" |
30522 | + | |
1facf9fc | 30523 | +/* policies to select one among multiple writable branches */ |
30524 | +struct au_wbr_copyup_operations { | |
30525 | + int (*copyup)(struct dentry *dentry); | |
30526 | +}; | |
30527 | + | |
392086de AM |
30528 | +#define AuWbr_DIR 1 /* target is a dir */ |
30529 | +#define AuWbr_PARENT (1 << 1) /* always require a parent */ | |
30530 | + | |
30531 | +#define au_ftest_wbr(flags, name) ((flags) & AuWbr_##name) | |
30532 | +#define au_fset_wbr(flags, name) { (flags) |= AuWbr_##name; } | |
30533 | +#define au_fclr_wbr(flags, name) { (flags) &= ~AuWbr_##name; } | |
30534 | + | |
1facf9fc | 30535 | +struct au_wbr_create_operations { |
392086de | 30536 | + int (*create)(struct dentry *dentry, unsigned int flags); |
1facf9fc | 30537 | + int (*init)(struct super_block *sb); |
30538 | + int (*fin)(struct super_block *sb); | |
30539 | +}; | |
30540 | + | |
30541 | +struct au_wbr_mfs { | |
30542 | + struct mutex mfs_lock; /* protect this structure */ | |
30543 | + unsigned long mfs_jiffy; | |
30544 | + unsigned long mfs_expire; | |
30545 | + aufs_bindex_t mfs_bindex; | |
30546 | + | |
30547 | + unsigned long long mfsrr_bytes; | |
30548 | + unsigned long long mfsrr_watermark; | |
30549 | +}; | |
30550 | + | |
86dc4139 AM |
30551 | +#define AuPlink_NHASH 100 |
30552 | +static inline int au_plink_hash(ino_t ino) | |
30553 | +{ | |
30554 | + return ino % AuPlink_NHASH; | |
30555 | +} | |
30556 | + | |
076b876e AM |
30557 | +/* File-based Hierarchical Storage Management */ |
30558 | +struct au_fhsm { | |
30559 | +#ifdef CONFIG_AUFS_FHSM | |
30560 | + /* allow only one process who can receive the notification */ | |
30561 | + spinlock_t fhsm_spin; | |
30562 | + pid_t fhsm_pid; | |
30563 | + wait_queue_head_t fhsm_wqh; | |
30564 | + atomic_t fhsm_readable; | |
30565 | + | |
c1595e42 | 30566 | + /* these are protected by si_rwsem */ |
076b876e | 30567 | + unsigned long fhsm_expire; |
c1595e42 | 30568 | + aufs_bindex_t fhsm_bottom; |
076b876e AM |
30569 | +#endif |
30570 | +}; | |
30571 | + | |
1facf9fc | 30572 | +struct au_branch; |
30573 | +struct au_sbinfo { | |
30574 | + /* nowait tasks in the system-wide workqueue */ | |
30575 | + struct au_nowait_tasks si_nowait; | |
30576 | + | |
b752ccd1 | 30577 | + /* |
acd2b654 | 30578 | + * tried sb->s_umount, but failed due to the dependency between i_mutex. |
b752ccd1 AM |
30579 | + * rwsem for au_sbinfo is necessary. |
30580 | + */ | |
dece6358 | 30581 | + struct au_rwsem si_rwsem; |
1facf9fc | 30582 | + |
7f207e10 | 30583 | + /* |
523b37e3 AM |
30584 | + * dirty approach to protect sb->sb_inodes and ->s_files (gone) from |
30585 | + * remount. | |
7f207e10 | 30586 | + */ |
acd2b654 | 30587 | + au_lcnt_t si_ninodes, si_nfiles; |
7f207e10 | 30588 | + |
1facf9fc | 30589 | + /* branch management */ |
30590 | + unsigned int si_generation; | |
30591 | + | |
2000de60 | 30592 | + /* see AuSi_ flags */ |
1facf9fc | 30593 | + unsigned char au_si_status; |
30594 | + | |
5afbbe0d | 30595 | + aufs_bindex_t si_bbot; |
7f207e10 AM |
30596 | + |
30597 | + /* dirty trick to keep br_id plus */ | |
30598 | + unsigned int si_last_br_id : | |
30599 | + sizeof(aufs_bindex_t) * BITS_PER_BYTE - 1; | |
1facf9fc | 30600 | + struct au_branch **si_branch; |
30601 | + | |
30602 | + /* policy to select a writable branch */ | |
30603 | + unsigned char si_wbr_copyup; | |
30604 | + unsigned char si_wbr_create; | |
30605 | + struct au_wbr_copyup_operations *si_wbr_copyup_ops; | |
30606 | + struct au_wbr_create_operations *si_wbr_create_ops; | |
30607 | + | |
30608 | + /* round robin */ | |
30609 | + atomic_t si_wbr_rr_next; | |
30610 | + | |
30611 | + /* most free space */ | |
30612 | + struct au_wbr_mfs si_wbr_mfs; | |
30613 | + | |
076b876e AM |
30614 | + /* File-based Hierarchical Storage Management */ |
30615 | + struct au_fhsm si_fhsm; | |
30616 | + | |
1facf9fc | 30617 | + /* mount flags */ |
30618 | + /* include/asm-ia64/siginfo.h defines a macro named si_flags */ | |
30619 | + unsigned int si_mntflags; | |
30620 | + | |
30621 | + /* external inode number (bitmap and translation table) */ | |
5527c038 JR |
30622 | + vfs_readf_t si_xread; |
30623 | + vfs_writef_t si_xwrite; | |
acd2b654 AM |
30624 | + loff_t si_ximaxent; /* max entries in a xino */ |
30625 | + | |
1facf9fc | 30626 | + struct file *si_xib; |
30627 | + struct mutex si_xib_mtx; /* protect xib members */ | |
30628 | + unsigned long *si_xib_buf; | |
30629 | + unsigned long si_xib_last_pindex; | |
30630 | + int si_xib_next_bit; | |
acd2b654 | 30631 | + |
392086de AM |
30632 | + unsigned long si_xino_jiffy; |
30633 | + unsigned long si_xino_expire; | |
1facf9fc | 30634 | + /* reserved for future use */ |
30635 | + /* unsigned long long si_xib_limit; */ /* Max xib file size */ | |
30636 | + | |
30637 | +#ifdef CONFIG_AUFS_EXPORT | |
30638 | + /* i_generation */ | |
acd2b654 | 30639 | + /* todo: make xigen file an array to support many inode numbers */ |
1facf9fc | 30640 | + struct file *si_xigen; |
30641 | + atomic_t si_xigen_next; | |
30642 | +#endif | |
30643 | + | |
acd2b654 | 30644 | + /* dirty trick to support atomic_open */ |
8b6a4947 | 30645 | + struct hlist_bl_head si_aopen; |
b912730e | 30646 | + |
1facf9fc | 30647 | + /* vdir parameters */ |
e49829fe | 30648 | + unsigned long si_rdcache; /* max cache time in jiffies */ |
1facf9fc | 30649 | + unsigned int si_rdblk; /* deblk size */ |
30650 | + unsigned int si_rdhash; /* hash size */ | |
30651 | + | |
30652 | + /* | |
30653 | + * If the number of whiteouts are larger than si_dirwh, leave all of | |
30654 | + * them after au_whtmp_ren to reduce the cost of rmdir(2). | |
30655 | + * future fsck.aufs or kernel thread will remove them later. | |
30656 | + * Otherwise, remove all whiteouts and the dir in rmdir(2). | |
30657 | + */ | |
30658 | + unsigned int si_dirwh; | |
30659 | + | |
1facf9fc | 30660 | + /* pseudo_link list */ |
8b6a4947 | 30661 | + struct hlist_bl_head si_plink[AuPlink_NHASH]; |
1facf9fc | 30662 | + wait_queue_head_t si_plink_wq; |
4a4d8108 | 30663 | + spinlock_t si_plink_maint_lock; |
e49829fe | 30664 | + pid_t si_plink_maint_pid; |
1facf9fc | 30665 | + |
523b37e3 | 30666 | + /* file list */ |
8b6a4947 | 30667 | + struct hlist_bl_head si_files; |
523b37e3 | 30668 | + |
b95c5147 | 30669 | + /* with/without getattr, brother of sb->s_d_op */ |
43982f53 | 30670 | + const struct inode_operations *si_iop_array; |
b95c5147 | 30671 | + |
1facf9fc | 30672 | + /* |
30673 | + * sysfs and lifetime management. | |
30674 | + * this is not a small structure and it may be a waste of memory in case | |
acd2b654 | 30675 | + * of sysfs is disabled, particularly when many aufs-es are mounted. |
1facf9fc | 30676 | + * but using sysfs is majority. |
30677 | + */ | |
30678 | + struct kobject si_kobj; | |
30679 | +#ifdef CONFIG_DEBUG_FS | |
86dc4139 AM |
30680 | + struct dentry *si_dbgaufs; |
30681 | + struct dentry *si_dbgaufs_plink; | |
30682 | + struct dentry *si_dbgaufs_xib; | |
1facf9fc | 30683 | +#ifdef CONFIG_AUFS_EXPORT |
30684 | + struct dentry *si_dbgaufs_xigen; | |
30685 | +#endif | |
30686 | +#endif | |
30687 | + | |
e49829fe | 30688 | +#ifdef CONFIG_AUFS_SBILIST |
8b6a4947 | 30689 | + struct hlist_bl_node si_list; |
e49829fe JR |
30690 | +#endif |
30691 | + | |
1facf9fc | 30692 | + /* dirty, necessary for unmounting, sysfs and sysrq */ |
30693 | + struct super_block *si_sb; | |
30694 | +}; | |
30695 | + | |
dece6358 AM |
30696 | +/* sbinfo status flags */ |
30697 | +/* | |
30698 | + * set true when refresh_dirs() failed at remount time. | |
30699 | + * then try refreshing dirs at access time again. | |
062440b3 | 30700 | + * if it is false, refreshing dirs at access time is unnecessary |
dece6358 | 30701 | + */ |
027c5e7a | 30702 | +#define AuSi_FAILED_REFRESH_DIR 1 |
076b876e | 30703 | +#define AuSi_FHSM (1 << 1) /* fhsm is active now */ |
79b8bda9 | 30704 | +#define AuSi_NO_DREVAL (1 << 2) /* disable all d_revalidate */ |
076b876e AM |
30705 | + |
30706 | +#ifndef CONFIG_AUFS_FHSM | |
30707 | +#undef AuSi_FHSM | |
30708 | +#define AuSi_FHSM 0 | |
30709 | +#endif | |
30710 | + | |
dece6358 AM |
30711 | +static inline unsigned char au_do_ftest_si(struct au_sbinfo *sbi, |
30712 | + unsigned int flag) | |
30713 | +{ | |
30714 | + AuRwMustAnyLock(&sbi->si_rwsem); | |
30715 | + return sbi->au_si_status & flag; | |
30716 | +} | |
30717 | +#define au_ftest_si(sbinfo, name) au_do_ftest_si(sbinfo, AuSi_##name) | |
30718 | +#define au_fset_si(sbinfo, name) do { \ | |
30719 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
30720 | + (sbinfo)->au_si_status |= AuSi_##name; \ | |
30721 | +} while (0) | |
30722 | +#define au_fclr_si(sbinfo, name) do { \ | |
30723 | + AuRwMustWriteLock(&(sbinfo)->si_rwsem); \ | |
30724 | + (sbinfo)->au_si_status &= ~AuSi_##name; \ | |
30725 | +} while (0) | |
30726 | + | |
1facf9fc | 30727 | +/* ---------------------------------------------------------------------- */ |
30728 | + | |
30729 | +/* policy to select one among writable branches */ | |
4a4d8108 AM |
30730 | +#define AuWbrCopyup(sbinfo, ...) \ |
30731 | + ((sbinfo)->si_wbr_copyup_ops->copyup(__VA_ARGS__)) | |
30732 | +#define AuWbrCreate(sbinfo, ...) \ | |
30733 | + ((sbinfo)->si_wbr_create_ops->create(__VA_ARGS__)) | |
1facf9fc | 30734 | + |
30735 | +/* flags for si_read_lock()/aufs_read_lock()/di_read_lock() */ | |
30736 | +#define AuLock_DW 1 /* write-lock dentry */ | |
30737 | +#define AuLock_IR (1 << 1) /* read-lock inode */ | |
30738 | +#define AuLock_IW (1 << 2) /* write-lock inode */ | |
30739 | +#define AuLock_FLUSH (1 << 3) /* wait for 'nowait' tasks */ | |
b95c5147 | 30740 | +#define AuLock_DIRS (1 << 4) /* target is a pair of dirs */ |
f2c43d5f | 30741 | + /* except RENAME_EXCHANGE */ |
e49829fe JR |
30742 | +#define AuLock_NOPLM (1 << 5) /* return err in plm mode */ |
30743 | +#define AuLock_NOPLMW (1 << 6) /* wait for plm mode ends */ | |
027c5e7a | 30744 | +#define AuLock_GEN (1 << 7) /* test digen/iigen */ |
1facf9fc | 30745 | +#define au_ftest_lock(flags, name) ((flags) & AuLock_##name) |
7f207e10 AM |
30746 | +#define au_fset_lock(flags, name) \ |
30747 | + do { (flags) |= AuLock_##name; } while (0) | |
30748 | +#define au_fclr_lock(flags, name) \ | |
30749 | + do { (flags) &= ~AuLock_##name; } while (0) | |
1facf9fc | 30750 | + |
30751 | +/* ---------------------------------------------------------------------- */ | |
30752 | + | |
30753 | +/* super.c */ | |
30754 | +extern struct file_system_type aufs_fs_type; | |
30755 | +struct inode *au_iget_locked(struct super_block *sb, ino_t ino); | |
79b8bda9 AM |
30756 | +typedef unsigned long long (*au_arraycb_t)(struct super_block *sb, void *array, |
30757 | + unsigned long long max, void *arg); | |
79b8bda9 AM |
30758 | +void *au_array_alloc(unsigned long long *hint, au_arraycb_t cb, |
30759 | + struct super_block *sb, void *arg); | |
7f207e10 AM |
30760 | +struct inode **au_iarray_alloc(struct super_block *sb, unsigned long long *max); |
30761 | +void au_iarray_free(struct inode **a, unsigned long long max); | |
1facf9fc | 30762 | + |
30763 | +/* sbinfo.c */ | |
30764 | +void au_si_free(struct kobject *kobj); | |
30765 | +int au_si_alloc(struct super_block *sb); | |
e2f27e51 | 30766 | +int au_sbr_realloc(struct au_sbinfo *sbinfo, int nbr, int may_shrink); |
1facf9fc | 30767 | + |
30768 | +unsigned int au_sigen_inc(struct super_block *sb); | |
30769 | +aufs_bindex_t au_new_br_id(struct super_block *sb); | |
30770 | + | |
e49829fe JR |
30771 | +int si_read_lock(struct super_block *sb, int flags); |
30772 | +int si_write_lock(struct super_block *sb, int flags); | |
30773 | +int aufs_read_lock(struct dentry *dentry, int flags); | |
1facf9fc | 30774 | +void aufs_read_unlock(struct dentry *dentry, int flags); |
30775 | +void aufs_write_lock(struct dentry *dentry); | |
30776 | +void aufs_write_unlock(struct dentry *dentry); | |
e49829fe | 30777 | +int aufs_read_and_write_lock2(struct dentry *d1, struct dentry *d2, int flags); |
1facf9fc | 30778 | +void aufs_read_and_write_unlock2(struct dentry *d1, struct dentry *d2); |
30779 | + | |
30780 | +/* wbr_policy.c */ | |
30781 | +extern struct au_wbr_copyup_operations au_wbr_copyup_ops[]; | |
30782 | +extern struct au_wbr_create_operations au_wbr_create_ops[]; | |
30783 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst); | |
c2b27bf2 | 30784 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex); |
5afbbe0d | 30785 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop); |
c2b27bf2 AM |
30786 | + |
30787 | +/* mvdown.c */ | |
30788 | +int au_mvdown(struct dentry *dentry, struct aufs_mvdown __user *arg); | |
1facf9fc | 30789 | + |
076b876e AM |
30790 | +#ifdef CONFIG_AUFS_FHSM |
30791 | +/* fhsm.c */ | |
30792 | + | |
30793 | +static inline pid_t au_fhsm_pid(struct au_fhsm *fhsm) | |
30794 | +{ | |
30795 | + pid_t pid; | |
30796 | + | |
30797 | + spin_lock(&fhsm->fhsm_spin); | |
30798 | + pid = fhsm->fhsm_pid; | |
30799 | + spin_unlock(&fhsm->fhsm_spin); | |
30800 | + | |
30801 | + return pid; | |
30802 | +} | |
30803 | + | |
30804 | +void au_fhsm_wrote(struct super_block *sb, aufs_bindex_t bindex, int force); | |
30805 | +void au_fhsm_wrote_all(struct super_block *sb, int force); | |
30806 | +int au_fhsm_fd(struct super_block *sb, int oflags); | |
30807 | +int au_fhsm_br_alloc(struct au_branch *br); | |
c1595e42 | 30808 | +void au_fhsm_set_bottom(struct super_block *sb, aufs_bindex_t bindex); |
076b876e AM |
30809 | +void au_fhsm_fin(struct super_block *sb); |
30810 | +void au_fhsm_init(struct au_sbinfo *sbinfo); | |
30811 | +void au_fhsm_set(struct au_sbinfo *sbinfo, unsigned int sec); | |
30812 | +void au_fhsm_show(struct seq_file *seq, struct au_sbinfo *sbinfo); | |
30813 | +#else | |
30814 | +AuStubVoid(au_fhsm_wrote, struct super_block *sb, aufs_bindex_t bindex, | |
30815 | + int force) | |
30816 | +AuStubVoid(au_fhsm_wrote_all, struct super_block *sb, int force) | |
30817 | +AuStub(int, au_fhsm_fd, return -EOPNOTSUPP, struct super_block *sb, int oflags) | |
c1595e42 JR |
30818 | +AuStub(pid_t, au_fhsm_pid, return 0, struct au_fhsm *fhsm) |
30819 | +AuStubInt0(au_fhsm_br_alloc, struct au_branch *br) | |
30820 | +AuStubVoid(au_fhsm_set_bottom, struct super_block *sb, aufs_bindex_t bindex) | |
076b876e AM |
30821 | +AuStubVoid(au_fhsm_fin, struct super_block *sb) |
30822 | +AuStubVoid(au_fhsm_init, struct au_sbinfo *sbinfo) | |
30823 | +AuStubVoid(au_fhsm_set, struct au_sbinfo *sbinfo, unsigned int sec) | |
30824 | +AuStubVoid(au_fhsm_show, struct seq_file *seq, struct au_sbinfo *sbinfo) | |
30825 | +#endif | |
30826 | + | |
1facf9fc | 30827 | +/* ---------------------------------------------------------------------- */ |
30828 | + | |
30829 | +static inline struct au_sbinfo *au_sbi(struct super_block *sb) | |
30830 | +{ | |
30831 | + return sb->s_fs_info; | |
30832 | +} | |
30833 | + | |
30834 | +/* ---------------------------------------------------------------------- */ | |
30835 | + | |
30836 | +#ifdef CONFIG_AUFS_EXPORT | |
a2a7ad62 | 30837 | +int au_test_nfsd(void); |
1facf9fc | 30838 | +void au_export_init(struct super_block *sb); |
b752ccd1 | 30839 | +void au_xigen_inc(struct inode *inode); |
1facf9fc | 30840 | +int au_xigen_new(struct inode *inode); |
062440b3 | 30841 | +int au_xigen_set(struct super_block *sb, struct path *path); |
1facf9fc | 30842 | +void au_xigen_clr(struct super_block *sb); |
30843 | + | |
30844 | +static inline int au_busy_or_stale(void) | |
30845 | +{ | |
b752ccd1 | 30846 | + if (!au_test_nfsd()) |
1facf9fc | 30847 | + return -EBUSY; |
30848 | + return -ESTALE; | |
30849 | +} | |
30850 | +#else | |
b752ccd1 | 30851 | +AuStubInt0(au_test_nfsd, void) |
a2a7ad62 | 30852 | +AuStubVoid(au_export_init, struct super_block *sb) |
b752ccd1 | 30853 | +AuStubVoid(au_xigen_inc, struct inode *inode) |
4a4d8108 | 30854 | +AuStubInt0(au_xigen_new, struct inode *inode) |
062440b3 | 30855 | +AuStubInt0(au_xigen_set, struct super_block *sb, struct path *path) |
4a4d8108 | 30856 | +AuStubVoid(au_xigen_clr, struct super_block *sb) |
c1595e42 | 30857 | +AuStub(int, au_busy_or_stale, return -EBUSY, void) |
1facf9fc | 30858 | +#endif /* CONFIG_AUFS_EXPORT */ |
30859 | + | |
30860 | +/* ---------------------------------------------------------------------- */ | |
30861 | + | |
e49829fe JR |
30862 | +#ifdef CONFIG_AUFS_SBILIST |
30863 | +/* module.c */ | |
8b6a4947 | 30864 | +extern struct hlist_bl_head au_sbilist; |
e49829fe JR |
30865 | + |
30866 | +static inline void au_sbilist_init(void) | |
30867 | +{ | |
8b6a4947 | 30868 | + INIT_HLIST_BL_HEAD(&au_sbilist); |
e49829fe JR |
30869 | +} |
30870 | + | |
30871 | +static inline void au_sbilist_add(struct super_block *sb) | |
30872 | +{ | |
8b6a4947 | 30873 | + au_hbl_add(&au_sbi(sb)->si_list, &au_sbilist); |
e49829fe JR |
30874 | +} |
30875 | + | |
30876 | +static inline void au_sbilist_del(struct super_block *sb) | |
30877 | +{ | |
8b6a4947 | 30878 | + au_hbl_del(&au_sbi(sb)->si_list, &au_sbilist); |
e49829fe | 30879 | +} |
53392da6 AM |
30880 | + |
30881 | +#ifdef CONFIG_AUFS_MAGIC_SYSRQ | |
30882 | +static inline void au_sbilist_lock(void) | |
30883 | +{ | |
8b6a4947 | 30884 | + hlist_bl_lock(&au_sbilist); |
53392da6 AM |
30885 | +} |
30886 | + | |
30887 | +static inline void au_sbilist_unlock(void) | |
30888 | +{ | |
8b6a4947 | 30889 | + hlist_bl_unlock(&au_sbilist); |
53392da6 AM |
30890 | +} |
30891 | +#define AuGFP_SBILIST GFP_ATOMIC | |
30892 | +#else | |
30893 | +AuStubVoid(au_sbilist_lock, void) | |
30894 | +AuStubVoid(au_sbilist_unlock, void) | |
30895 | +#define AuGFP_SBILIST GFP_NOFS | |
30896 | +#endif /* CONFIG_AUFS_MAGIC_SYSRQ */ | |
e49829fe JR |
30897 | +#else |
30898 | +AuStubVoid(au_sbilist_init, void) | |
c1595e42 JR |
30899 | +AuStubVoid(au_sbilist_add, struct super_block *sb) |
30900 | +AuStubVoid(au_sbilist_del, struct super_block *sb) | |
53392da6 AM |
30901 | +AuStubVoid(au_sbilist_lock, void) |
30902 | +AuStubVoid(au_sbilist_unlock, void) | |
30903 | +#define AuGFP_SBILIST GFP_NOFS | |
e49829fe JR |
30904 | +#endif |
30905 | + | |
30906 | +/* ---------------------------------------------------------------------- */ | |
30907 | + | |
1facf9fc | 30908 | +static inline void dbgaufs_si_null(struct au_sbinfo *sbinfo) |
30909 | +{ | |
dece6358 | 30910 | + /* |
c1595e42 | 30911 | + * This function is a dynamic '__init' function actually, |
dece6358 AM |
30912 | + * so the tiny check for si_rwsem is unnecessary. |
30913 | + */ | |
30914 | + /* AuRwMustWriteLock(&sbinfo->si_rwsem); */ | |
1facf9fc | 30915 | +#ifdef CONFIG_DEBUG_FS |
30916 | + sbinfo->si_dbgaufs = NULL; | |
86dc4139 | 30917 | + sbinfo->si_dbgaufs_plink = NULL; |
1facf9fc | 30918 | + sbinfo->si_dbgaufs_xib = NULL; |
30919 | +#ifdef CONFIG_AUFS_EXPORT | |
30920 | + sbinfo->si_dbgaufs_xigen = NULL; | |
30921 | +#endif | |
30922 | +#endif | |
30923 | +} | |
30924 | + | |
30925 | +/* ---------------------------------------------------------------------- */ | |
30926 | + | |
a2654f78 AM |
30927 | +/* current->atomic_flags */ |
30928 | +/* this value should never corrupt the ones defined in linux/sched.h */ | |
fbc438ed | 30929 | +#define PFA_AUFS 0x10 |
a2654f78 AM |
30930 | + |
30931 | +TASK_PFA_TEST(AUFS, test_aufs) /* task_test_aufs */ | |
30932 | +TASK_PFA_SET(AUFS, aufs) /* task_set_aufs */ | |
30933 | +TASK_PFA_CLEAR(AUFS, aufs) /* task_clear_aufs */ | |
b752ccd1 AM |
30934 | + |
30935 | +static inline int si_pid_test(struct super_block *sb) | |
30936 | +{ | |
a2654f78 | 30937 | + return !!task_test_aufs(current); |
b752ccd1 AM |
30938 | +} |
30939 | + | |
30940 | +static inline void si_pid_clr(struct super_block *sb) | |
30941 | +{ | |
a2654f78 AM |
30942 | + AuDebugOn(!task_test_aufs(current)); |
30943 | + task_clear_aufs(current); | |
b752ccd1 AM |
30944 | +} |
30945 | + | |
a2654f78 AM |
30946 | +static inline void si_pid_set(struct super_block *sb) |
30947 | +{ | |
30948 | + AuDebugOn(task_test_aufs(current)); | |
30949 | + task_set_aufs(current); | |
30950 | +} | |
febd17d6 | 30951 | + |
b752ccd1 AM |
30952 | +/* ---------------------------------------------------------------------- */ |
30953 | + | |
1facf9fc | 30954 | +/* lock superblock. mainly for entry point functions */ |
8b6a4947 AM |
30955 | +#define __si_read_lock(sb) au_rw_read_lock(&au_sbi(sb)->si_rwsem) |
30956 | +#define __si_write_lock(sb) au_rw_write_lock(&au_sbi(sb)->si_rwsem) | |
30957 | +#define __si_read_trylock(sb) au_rw_read_trylock(&au_sbi(sb)->si_rwsem) | |
30958 | +#define __si_write_trylock(sb) au_rw_write_trylock(&au_sbi(sb)->si_rwsem) | |
30959 | +/* | |
30960 | +#define __si_read_trylock_nested(sb) \ | |
30961 | + au_rw_read_trylock_nested(&au_sbi(sb)->si_rwsem) | |
30962 | +#define __si_write_trylock_nested(sb) \ | |
30963 | + au_rw_write_trylock_nested(&au_sbi(sb)->si_rwsem) | |
30964 | +*/ | |
30965 | + | |
30966 | +#define __si_read_unlock(sb) au_rw_read_unlock(&au_sbi(sb)->si_rwsem) | |
30967 | +#define __si_write_unlock(sb) au_rw_write_unlock(&au_sbi(sb)->si_rwsem) | |
30968 | +#define __si_downgrade_lock(sb) au_rw_dgrade_lock(&au_sbi(sb)->si_rwsem) | |
1facf9fc | 30969 | + |
dece6358 AM |
30970 | +#define SiMustNoWaiters(sb) AuRwMustNoWaiters(&au_sbi(sb)->si_rwsem) |
30971 | +#define SiMustAnyLock(sb) AuRwMustAnyLock(&au_sbi(sb)->si_rwsem) | |
30972 | +#define SiMustWriteLock(sb) AuRwMustWriteLock(&au_sbi(sb)->si_rwsem) | |
30973 | + | |
b752ccd1 AM |
30974 | +static inline void si_noflush_read_lock(struct super_block *sb) |
30975 | +{ | |
30976 | + __si_read_lock(sb); | |
30977 | + si_pid_set(sb); | |
30978 | +} | |
30979 | + | |
30980 | +static inline int si_noflush_read_trylock(struct super_block *sb) | |
30981 | +{ | |
076b876e AM |
30982 | + int locked; |
30983 | + | |
30984 | + locked = __si_read_trylock(sb); | |
b752ccd1 AM |
30985 | + if (locked) |
30986 | + si_pid_set(sb); | |
30987 | + return locked; | |
30988 | +} | |
30989 | + | |
30990 | +static inline void si_noflush_write_lock(struct super_block *sb) | |
30991 | +{ | |
30992 | + __si_write_lock(sb); | |
30993 | + si_pid_set(sb); | |
30994 | +} | |
30995 | + | |
30996 | +static inline int si_noflush_write_trylock(struct super_block *sb) | |
30997 | +{ | |
076b876e AM |
30998 | + int locked; |
30999 | + | |
31000 | + locked = __si_write_trylock(sb); | |
b752ccd1 AM |
31001 | + if (locked) |
31002 | + si_pid_set(sb); | |
31003 | + return locked; | |
31004 | +} | |
31005 | + | |
7e9cd9fe | 31006 | +#if 0 /* reserved */ |
1facf9fc | 31007 | +static inline int si_read_trylock(struct super_block *sb, int flags) |
31008 | +{ | |
31009 | + if (au_ftest_lock(flags, FLUSH)) | |
31010 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
31011 | + return si_noflush_read_trylock(sb); | |
31012 | +} | |
e49829fe | 31013 | +#endif |
1facf9fc | 31014 | + |
b752ccd1 AM |
31015 | +static inline void si_read_unlock(struct super_block *sb) |
31016 | +{ | |
31017 | + si_pid_clr(sb); | |
31018 | + __si_read_unlock(sb); | |
31019 | +} | |
31020 | + | |
7e9cd9fe | 31021 | +#if 0 /* reserved */ |
1facf9fc | 31022 | +static inline int si_write_trylock(struct super_block *sb, int flags) |
31023 | +{ | |
31024 | + if (au_ftest_lock(flags, FLUSH)) | |
31025 | + au_nwt_flush(&au_sbi(sb)->si_nowait); | |
31026 | + return si_noflush_write_trylock(sb); | |
31027 | +} | |
b752ccd1 AM |
31028 | +#endif |
31029 | + | |
31030 | +static inline void si_write_unlock(struct super_block *sb) | |
31031 | +{ | |
31032 | + si_pid_clr(sb); | |
31033 | + __si_write_unlock(sb); | |
31034 | +} | |
31035 | + | |
7e9cd9fe | 31036 | +#if 0 /* reserved */ |
b752ccd1 AM |
31037 | +static inline void si_downgrade_lock(struct super_block *sb) |
31038 | +{ | |
31039 | + __si_downgrade_lock(sb); | |
31040 | +} | |
31041 | +#endif | |
1facf9fc | 31042 | + |
31043 | +/* ---------------------------------------------------------------------- */ | |
31044 | + | |
5afbbe0d | 31045 | +static inline aufs_bindex_t au_sbbot(struct super_block *sb) |
1facf9fc | 31046 | +{ |
dece6358 | 31047 | + SiMustAnyLock(sb); |
5afbbe0d | 31048 | + return au_sbi(sb)->si_bbot; |
1facf9fc | 31049 | +} |
31050 | + | |
31051 | +static inline unsigned int au_mntflags(struct super_block *sb) | |
31052 | +{ | |
dece6358 | 31053 | + SiMustAnyLock(sb); |
1facf9fc | 31054 | + return au_sbi(sb)->si_mntflags; |
31055 | +} | |
31056 | + | |
31057 | +static inline unsigned int au_sigen(struct super_block *sb) | |
31058 | +{ | |
dece6358 | 31059 | + SiMustAnyLock(sb); |
1facf9fc | 31060 | + return au_sbi(sb)->si_generation; |
31061 | +} | |
31062 | + | |
31063 | +static inline struct au_branch *au_sbr(struct super_block *sb, | |
31064 | + aufs_bindex_t bindex) | |
31065 | +{ | |
dece6358 | 31066 | + SiMustAnyLock(sb); |
1facf9fc | 31067 | + return au_sbi(sb)->si_branch[0 + bindex]; |
31068 | +} | |
31069 | + | |
acd2b654 | 31070 | +static inline loff_t au_xi_maxent(struct super_block *sb) |
1facf9fc | 31071 | +{ |
dece6358 | 31072 | + SiMustAnyLock(sb); |
acd2b654 | 31073 | + return au_sbi(sb)->si_ximaxent; |
1facf9fc | 31074 | +} |
31075 | + | |
31076 | +#endif /* __KERNEL__ */ | |
31077 | +#endif /* __AUFS_SUPER_H__ */ | |
7f207e10 | 31078 | diff -urN /usr/share/empty/fs/aufs/sysaufs.c linux/fs/aufs/sysaufs.c |
eca34b5c | 31079 | --- /usr/share/empty/fs/aufs/sysaufs.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 31080 | +++ linux/fs/aufs/sysaufs.c 2020-01-27 10:57:18.178871751 +0100 |
062440b3 | 31081 | @@ -0,0 +1,93 @@ |
cd7a4cd9 | 31082 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 31083 | +/* |
d58c55f2 | 31084 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 31085 | + * |
31086 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31087 | + * it under the terms of the GNU General Public License as published by | |
31088 | + * the Free Software Foundation; either version 2 of the License, or | |
31089 | + * (at your option) any later version. | |
dece6358 AM |
31090 | + * |
31091 | + * This program is distributed in the hope that it will be useful, | |
31092 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31093 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31094 | + * GNU General Public License for more details. | |
31095 | + * | |
31096 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31097 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31098 | + */ |
31099 | + | |
31100 | +/* | |
31101 | + * sysfs interface and lifetime management | |
31102 | + * they are necessary regardless sysfs is disabled. | |
31103 | + */ | |
31104 | + | |
1facf9fc | 31105 | +#include <linux/random.h> |
1facf9fc | 31106 | +#include "aufs.h" |
31107 | + | |
31108 | +unsigned long sysaufs_si_mask; | |
e49829fe | 31109 | +struct kset *sysaufs_kset; |
1facf9fc | 31110 | + |
31111 | +#define AuSiAttr(_name) { \ | |
31112 | + .attr = { .name = __stringify(_name), .mode = 0444 }, \ | |
31113 | + .show = sysaufs_si_##_name, \ | |
31114 | +} | |
31115 | + | |
31116 | +static struct sysaufs_si_attr sysaufs_si_attr_xi_path = AuSiAttr(xi_path); | |
31117 | +struct attribute *sysaufs_si_attrs[] = { | |
31118 | + &sysaufs_si_attr_xi_path.attr, | |
31119 | + NULL, | |
31120 | +}; | |
31121 | + | |
4a4d8108 | 31122 | +static const struct sysfs_ops au_sbi_ops = { |
1facf9fc | 31123 | + .show = sysaufs_si_show |
31124 | +}; | |
31125 | + | |
31126 | +static struct kobj_type au_sbi_ktype = { | |
31127 | + .release = au_si_free, | |
31128 | + .sysfs_ops = &au_sbi_ops, | |
31129 | + .default_attrs = sysaufs_si_attrs | |
31130 | +}; | |
31131 | + | |
31132 | +/* ---------------------------------------------------------------------- */ | |
31133 | + | |
31134 | +int sysaufs_si_init(struct au_sbinfo *sbinfo) | |
31135 | +{ | |
31136 | + int err; | |
31137 | + | |
e49829fe | 31138 | + sbinfo->si_kobj.kset = sysaufs_kset; |
1facf9fc | 31139 | + /* cf. sysaufs_name() */ |
31140 | + err = kobject_init_and_add | |
e49829fe | 31141 | + (&sbinfo->si_kobj, &au_sbi_ktype, /*&sysaufs_kset->kobj*/NULL, |
1facf9fc | 31142 | + SysaufsSiNamePrefix "%lx", sysaufs_si_id(sbinfo)); |
31143 | + | |
1facf9fc | 31144 | + return err; |
31145 | +} | |
31146 | + | |
31147 | +void sysaufs_fin(void) | |
31148 | +{ | |
e49829fe JR |
31149 | + sysfs_remove_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
31150 | + kset_unregister(sysaufs_kset); | |
1facf9fc | 31151 | +} |
31152 | + | |
31153 | +int __init sysaufs_init(void) | |
31154 | +{ | |
31155 | + int err; | |
31156 | + | |
31157 | + do { | |
31158 | + get_random_bytes(&sysaufs_si_mask, sizeof(sysaufs_si_mask)); | |
31159 | + } while (!sysaufs_si_mask); | |
31160 | + | |
4a4d8108 | 31161 | + err = -EINVAL; |
e49829fe JR |
31162 | + sysaufs_kset = kset_create_and_add(AUFS_NAME, NULL, fs_kobj); |
31163 | + if (unlikely(!sysaufs_kset)) | |
4a4d8108 | 31164 | + goto out; |
e49829fe JR |
31165 | + err = PTR_ERR(sysaufs_kset); |
31166 | + if (IS_ERR(sysaufs_kset)) | |
1facf9fc | 31167 | + goto out; |
e49829fe | 31168 | + err = sysfs_create_group(&sysaufs_kset->kobj, sysaufs_attr_group); |
062440b3 | 31169 | + if (unlikely(err)) |
e49829fe | 31170 | + kset_unregister(sysaufs_kset); |
1facf9fc | 31171 | + |
4f0767ce | 31172 | +out: |
1facf9fc | 31173 | + return err; |
31174 | +} | |
7f207e10 | 31175 | diff -urN /usr/share/empty/fs/aufs/sysaufs.h linux/fs/aufs/sysaufs.h |
eca34b5c | 31176 | --- /usr/share/empty/fs/aufs/sysaufs.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 31177 | +++ linux/fs/aufs/sysaufs.h 2020-01-27 10:57:18.178871751 +0100 |
062440b3 AM |
31178 | @@ -0,0 +1,102 @@ |
31179 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 31180 | +/* |
d58c55f2 | 31181 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 31182 | + * |
31183 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31184 | + * it under the terms of the GNU General Public License as published by | |
31185 | + * the Free Software Foundation; either version 2 of the License, or | |
31186 | + * (at your option) any later version. | |
dece6358 AM |
31187 | + * |
31188 | + * This program is distributed in the hope that it will be useful, | |
31189 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31190 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31191 | + * GNU General Public License for more details. | |
31192 | + * | |
31193 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31194 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31195 | + */ |
31196 | + | |
31197 | +/* | |
31198 | + * sysfs interface and mount lifetime management | |
31199 | + */ | |
31200 | + | |
31201 | +#ifndef __SYSAUFS_H__ | |
31202 | +#define __SYSAUFS_H__ | |
31203 | + | |
31204 | +#ifdef __KERNEL__ | |
31205 | + | |
1facf9fc | 31206 | +#include <linux/sysfs.h> |
1facf9fc | 31207 | +#include "module.h" |
31208 | + | |
dece6358 AM |
31209 | +struct super_block; |
31210 | +struct au_sbinfo; | |
31211 | + | |
1facf9fc | 31212 | +struct sysaufs_si_attr { |
31213 | + struct attribute attr; | |
31214 | + int (*show)(struct seq_file *seq, struct super_block *sb); | |
31215 | +}; | |
31216 | + | |
31217 | +/* ---------------------------------------------------------------------- */ | |
31218 | + | |
31219 | +/* sysaufs.c */ | |
31220 | +extern unsigned long sysaufs_si_mask; | |
e49829fe | 31221 | +extern struct kset *sysaufs_kset; |
1facf9fc | 31222 | +extern struct attribute *sysaufs_si_attrs[]; |
31223 | +int sysaufs_si_init(struct au_sbinfo *sbinfo); | |
31224 | +int __init sysaufs_init(void); | |
31225 | +void sysaufs_fin(void); | |
31226 | + | |
31227 | +/* ---------------------------------------------------------------------- */ | |
31228 | + | |
31229 | +/* some people doesn't like to show a pointer in kernel */ | |
31230 | +static inline unsigned long sysaufs_si_id(struct au_sbinfo *sbinfo) | |
31231 | +{ | |
31232 | + return sysaufs_si_mask ^ (unsigned long)sbinfo; | |
31233 | +} | |
31234 | + | |
31235 | +#define SysaufsSiNamePrefix "si_" | |
31236 | +#define SysaufsSiNameLen (sizeof(SysaufsSiNamePrefix) + 16) | |
31237 | +static inline void sysaufs_name(struct au_sbinfo *sbinfo, char *name) | |
31238 | +{ | |
31239 | + snprintf(name, SysaufsSiNameLen, SysaufsSiNamePrefix "%lx", | |
31240 | + sysaufs_si_id(sbinfo)); | |
31241 | +} | |
31242 | + | |
31243 | +struct au_branch; | |
31244 | +#ifdef CONFIG_SYSFS | |
31245 | +/* sysfs.c */ | |
31246 | +extern struct attribute_group *sysaufs_attr_group; | |
31247 | + | |
31248 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb); | |
31249 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
31250 | + char *buf); | |
076b876e AM |
31251 | +long au_brinfo_ioctl(struct file *file, unsigned long arg); |
31252 | +#ifdef CONFIG_COMPAT | |
31253 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg); | |
31254 | +#endif | |
1facf9fc | 31255 | + |
31256 | +void sysaufs_br_init(struct au_branch *br); | |
31257 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex); | |
31258 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex); | |
31259 | + | |
31260 | +#define sysaufs_brs_init() do {} while (0) | |
31261 | + | |
31262 | +#else | |
31263 | +#define sysaufs_attr_group NULL | |
31264 | + | |
4a4d8108 | 31265 | +AuStubInt0(sysaufs_si_xi_path, struct seq_file *seq, struct super_block *sb) |
c1595e42 JR |
31266 | +AuStub(ssize_t, sysaufs_si_show, return 0, struct kobject *kobj, |
31267 | + struct attribute *attr, char *buf) | |
4a4d8108 AM |
31268 | +AuStubVoid(sysaufs_br_init, struct au_branch *br) |
31269 | +AuStubVoid(sysaufs_brs_add, struct super_block *sb, aufs_bindex_t bindex) | |
31270 | +AuStubVoid(sysaufs_brs_del, struct super_block *sb, aufs_bindex_t bindex) | |
1facf9fc | 31271 | + |
31272 | +static inline void sysaufs_brs_init(void) | |
31273 | +{ | |
31274 | + sysaufs_brs = 0; | |
31275 | +} | |
31276 | + | |
31277 | +#endif /* CONFIG_SYSFS */ | |
31278 | + | |
31279 | +#endif /* __KERNEL__ */ | |
31280 | +#endif /* __SYSAUFS_H__ */ | |
7f207e10 | 31281 | diff -urN /usr/share/empty/fs/aufs/sysfs.c linux/fs/aufs/sysfs.c |
eca34b5c | 31282 | --- /usr/share/empty/fs/aufs/sysfs.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 31283 | +++ linux/fs/aufs/sysfs.c 2020-01-27 10:57:18.178871751 +0100 |
ba1aed25 | 31284 | @@ -0,0 +1,374 @@ |
cd7a4cd9 | 31285 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 31286 | +/* |
d58c55f2 | 31287 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 31288 | + * |
31289 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31290 | + * it under the terms of the GNU General Public License as published by | |
31291 | + * the Free Software Foundation; either version 2 of the License, or | |
31292 | + * (at your option) any later version. | |
dece6358 AM |
31293 | + * |
31294 | + * This program is distributed in the hope that it will be useful, | |
31295 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31296 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31297 | + * GNU General Public License for more details. | |
31298 | + * | |
31299 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31300 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31301 | + */ |
31302 | + | |
31303 | +/* | |
31304 | + * sysfs interface | |
31305 | + */ | |
31306 | + | |
076b876e | 31307 | +#include <linux/compat.h> |
1facf9fc | 31308 | +#include <linux/seq_file.h> |
1facf9fc | 31309 | +#include "aufs.h" |
31310 | + | |
4a4d8108 AM |
31311 | +#ifdef CONFIG_AUFS_FS_MODULE |
31312 | +/* this entry violates the "one line per file" policy of sysfs */ | |
31313 | +static ssize_t config_show(struct kobject *kobj, struct kobj_attribute *attr, | |
31314 | + char *buf) | |
31315 | +{ | |
31316 | + ssize_t err; | |
31317 | + static char *conf = | |
31318 | +/* this file is generated at compiling */ | |
31319 | +#include "conf.str" | |
31320 | + ; | |
31321 | + | |
31322 | + err = snprintf(buf, PAGE_SIZE, conf); | |
31323 | + if (unlikely(err >= PAGE_SIZE)) | |
31324 | + err = -EFBIG; | |
31325 | + return err; | |
31326 | +} | |
31327 | + | |
31328 | +static struct kobj_attribute au_config_attr = __ATTR_RO(config); | |
31329 | +#endif | |
31330 | + | |
1facf9fc | 31331 | +static struct attribute *au_attr[] = { |
4a4d8108 AM |
31332 | +#ifdef CONFIG_AUFS_FS_MODULE |
31333 | + &au_config_attr.attr, | |
31334 | +#endif | |
1facf9fc | 31335 | + NULL, /* need to NULL terminate the list of attributes */ |
31336 | +}; | |
31337 | + | |
31338 | +static struct attribute_group sysaufs_attr_group_body = { | |
31339 | + .attrs = au_attr | |
31340 | +}; | |
31341 | + | |
31342 | +struct attribute_group *sysaufs_attr_group = &sysaufs_attr_group_body; | |
31343 | + | |
31344 | +/* ---------------------------------------------------------------------- */ | |
31345 | + | |
31346 | +int sysaufs_si_xi_path(struct seq_file *seq, struct super_block *sb) | |
31347 | +{ | |
31348 | + int err; | |
31349 | + | |
dece6358 AM |
31350 | + SiMustAnyLock(sb); |
31351 | + | |
1facf9fc | 31352 | + err = 0; |
31353 | + if (au_opt_test(au_mntflags(sb), XINO)) { | |
31354 | + err = au_xino_path(seq, au_sbi(sb)->si_xib); | |
31355 | + seq_putc(seq, '\n'); | |
31356 | + } | |
31357 | + return err; | |
31358 | +} | |
31359 | + | |
31360 | +/* | |
31361 | + * the lifetime of branch is independent from the entry under sysfs. | |
31362 | + * sysfs handles the lifetime of the entry, and never call ->show() after it is | |
31363 | + * unlinked. | |
31364 | + */ | |
31365 | +static int sysaufs_si_br(struct seq_file *seq, struct super_block *sb, | |
392086de | 31366 | + aufs_bindex_t bindex, int idx) |
1facf9fc | 31367 | +{ |
1e00d052 | 31368 | + int err; |
1facf9fc | 31369 | + struct path path; |
31370 | + struct dentry *root; | |
31371 | + struct au_branch *br; | |
076b876e | 31372 | + au_br_perm_str_t perm; |
1facf9fc | 31373 | + |
31374 | + AuDbg("b%d\n", bindex); | |
31375 | + | |
1e00d052 | 31376 | + err = 0; |
1facf9fc | 31377 | + root = sb->s_root; |
31378 | + di_read_lock_parent(root, !AuLock_IR); | |
31379 | + br = au_sbr(sb, bindex); | |
392086de AM |
31380 | + |
31381 | + switch (idx) { | |
31382 | + case AuBrSysfs_BR: | |
31383 | + path.mnt = au_br_mnt(br); | |
31384 | + path.dentry = au_h_dptr(root, bindex); | |
79b8bda9 AM |
31385 | + err = au_seq_path(seq, &path); |
31386 | + if (!err) { | |
31387 | + au_optstr_br_perm(&perm, br->br_perm); | |
31388 | + seq_printf(seq, "=%s\n", perm.a); | |
31389 | + } | |
392086de AM |
31390 | + break; |
31391 | + case AuBrSysfs_BRID: | |
79b8bda9 | 31392 | + seq_printf(seq, "%d\n", br->br_id); |
392086de AM |
31393 | + break; |
31394 | + } | |
076b876e | 31395 | + di_read_unlock(root, !AuLock_IR); |
79b8bda9 | 31396 | + if (unlikely(err || seq_has_overflowed(seq))) |
076b876e | 31397 | + err = -E2BIG; |
392086de | 31398 | + |
1e00d052 | 31399 | + return err; |
1facf9fc | 31400 | +} |
31401 | + | |
31402 | +/* ---------------------------------------------------------------------- */ | |
31403 | + | |
31404 | +static struct seq_file *au_seq(char *p, ssize_t len) | |
31405 | +{ | |
31406 | + struct seq_file *seq; | |
31407 | + | |
31408 | + seq = kzalloc(sizeof(*seq), GFP_NOFS); | |
31409 | + if (seq) { | |
31410 | + /* mutex_init(&seq.lock); */ | |
31411 | + seq->buf = p; | |
31412 | + seq->size = len; | |
31413 | + return seq; /* success */ | |
31414 | + } | |
31415 | + | |
31416 | + seq = ERR_PTR(-ENOMEM); | |
31417 | + return seq; | |
31418 | +} | |
31419 | + | |
392086de AM |
31420 | +#define SysaufsBr_PREFIX "br" |
31421 | +#define SysaufsBrid_PREFIX "brid" | |
1facf9fc | 31422 | + |
31423 | +/* todo: file size may exceed PAGE_SIZE */ | |
31424 | +ssize_t sysaufs_si_show(struct kobject *kobj, struct attribute *attr, | |
1308ab2a | 31425 | + char *buf) |
1facf9fc | 31426 | +{ |
31427 | + ssize_t err; | |
392086de | 31428 | + int idx; |
1facf9fc | 31429 | + long l; |
5afbbe0d | 31430 | + aufs_bindex_t bbot; |
1facf9fc | 31431 | + struct au_sbinfo *sbinfo; |
31432 | + struct super_block *sb; | |
31433 | + struct seq_file *seq; | |
31434 | + char *name; | |
31435 | + struct attribute **cattr; | |
31436 | + | |
31437 | + sbinfo = container_of(kobj, struct au_sbinfo, si_kobj); | |
31438 | + sb = sbinfo->si_sb; | |
1308ab2a | 31439 | + |
31440 | + /* | |
31441 | + * prevent a race condition between sysfs and aufs. | |
31442 | + * for instance, sysfs_file_read() calls sysfs_get_active_two() which | |
31443 | + * prohibits maintaining the sysfs entries. | |
31444 | + * hew we acquire read lock after sysfs_get_active_two(). | |
31445 | + * on the other hand, the remount process may maintain the sysfs/aufs | |
31446 | + * entries after acquiring write lock. | |
31447 | + * it can cause a deadlock. | |
31448 | + * simply we gave up processing read here. | |
31449 | + */ | |
31450 | + err = -EBUSY; | |
31451 | + if (unlikely(!si_noflush_read_trylock(sb))) | |
31452 | + goto out; | |
1facf9fc | 31453 | + |
31454 | + seq = au_seq(buf, PAGE_SIZE); | |
31455 | + err = PTR_ERR(seq); | |
31456 | + if (IS_ERR(seq)) | |
1308ab2a | 31457 | + goto out_unlock; |
1facf9fc | 31458 | + |
31459 | + name = (void *)attr->name; | |
31460 | + cattr = sysaufs_si_attrs; | |
31461 | + while (*cattr) { | |
31462 | + if (!strcmp(name, (*cattr)->name)) { | |
31463 | + err = container_of(*cattr, struct sysaufs_si_attr, attr) | |
31464 | + ->show(seq, sb); | |
31465 | + goto out_seq; | |
31466 | + } | |
31467 | + cattr++; | |
31468 | + } | |
31469 | + | |
392086de AM |
31470 | + if (!strncmp(name, SysaufsBrid_PREFIX, |
31471 | + sizeof(SysaufsBrid_PREFIX) - 1)) { | |
31472 | + idx = AuBrSysfs_BRID; | |
31473 | + name += sizeof(SysaufsBrid_PREFIX) - 1; | |
31474 | + } else if (!strncmp(name, SysaufsBr_PREFIX, | |
31475 | + sizeof(SysaufsBr_PREFIX) - 1)) { | |
31476 | + idx = AuBrSysfs_BR; | |
1facf9fc | 31477 | + name += sizeof(SysaufsBr_PREFIX) - 1; |
392086de AM |
31478 | + } else |
31479 | + BUG(); | |
31480 | + | |
31481 | + err = kstrtol(name, 10, &l); | |
31482 | + if (!err) { | |
5afbbe0d AM |
31483 | + bbot = au_sbbot(sb); |
31484 | + if (l <= bbot) | |
392086de AM |
31485 | + err = sysaufs_si_br(seq, sb, (aufs_bindex_t)l, idx); |
31486 | + else | |
31487 | + err = -ENOENT; | |
1facf9fc | 31488 | + } |
1facf9fc | 31489 | + |
4f0767ce | 31490 | +out_seq: |
1facf9fc | 31491 | + if (!err) { |
31492 | + err = seq->count; | |
31493 | + /* sysfs limit */ | |
31494 | + if (unlikely(err == PAGE_SIZE)) | |
31495 | + err = -EFBIG; | |
31496 | + } | |
9f237c51 | 31497 | + au_kfree_rcu(seq); |
4f0767ce | 31498 | +out_unlock: |
1facf9fc | 31499 | + si_read_unlock(sb); |
4f0767ce | 31500 | +out: |
1facf9fc | 31501 | + return err; |
31502 | +} | |
31503 | + | |
31504 | +/* ---------------------------------------------------------------------- */ | |
31505 | + | |
076b876e AM |
31506 | +static int au_brinfo(struct super_block *sb, union aufs_brinfo __user *arg) |
31507 | +{ | |
31508 | + int err; | |
31509 | + int16_t brid; | |
5afbbe0d | 31510 | + aufs_bindex_t bindex, bbot; |
076b876e AM |
31511 | + size_t sz; |
31512 | + char *buf; | |
31513 | + struct seq_file *seq; | |
31514 | + struct au_branch *br; | |
31515 | + | |
31516 | + si_read_lock(sb, AuLock_FLUSH); | |
5afbbe0d AM |
31517 | + bbot = au_sbbot(sb); |
31518 | + err = bbot + 1; | |
076b876e AM |
31519 | + if (!arg) |
31520 | + goto out; | |
31521 | + | |
31522 | + err = -ENOMEM; | |
31523 | + buf = (void *)__get_free_page(GFP_NOFS); | |
31524 | + if (unlikely(!buf)) | |
31525 | + goto out; | |
31526 | + | |
31527 | + seq = au_seq(buf, PAGE_SIZE); | |
31528 | + err = PTR_ERR(seq); | |
31529 | + if (IS_ERR(seq)) | |
31530 | + goto out_buf; | |
31531 | + | |
31532 | + sz = sizeof(*arg) - offsetof(union aufs_brinfo, path); | |
5afbbe0d | 31533 | + for (bindex = 0; bindex <= bbot; bindex++, arg++) { |
ba1aed25 AM |
31534 | + /* VERIFY_WRITE */ |
31535 | + err = !access_ok(arg, sizeof(*arg)); | |
076b876e AM |
31536 | + if (unlikely(err)) |
31537 | + break; | |
31538 | + | |
31539 | + br = au_sbr(sb, bindex); | |
31540 | + brid = br->br_id; | |
31541 | + BUILD_BUG_ON(sizeof(brid) != sizeof(arg->id)); | |
31542 | + err = __put_user(brid, &arg->id); | |
31543 | + if (unlikely(err)) | |
31544 | + break; | |
31545 | + | |
31546 | + BUILD_BUG_ON(sizeof(br->br_perm) != sizeof(arg->perm)); | |
31547 | + err = __put_user(br->br_perm, &arg->perm); | |
31548 | + if (unlikely(err)) | |
31549 | + break; | |
31550 | + | |
79b8bda9 AM |
31551 | + err = au_seq_path(seq, &br->br_path); |
31552 | + if (unlikely(err)) | |
31553 | + break; | |
31554 | + seq_putc(seq, '\0'); | |
31555 | + if (!seq_has_overflowed(seq)) { | |
076b876e AM |
31556 | + err = copy_to_user(arg->path, seq->buf, seq->count); |
31557 | + seq->count = 0; | |
31558 | + if (unlikely(err)) | |
31559 | + break; | |
31560 | + } else { | |
31561 | + err = -E2BIG; | |
31562 | + goto out_seq; | |
31563 | + } | |
31564 | + } | |
31565 | + if (unlikely(err)) | |
31566 | + err = -EFAULT; | |
31567 | + | |
31568 | +out_seq: | |
9f237c51 | 31569 | + au_kfree_rcu(seq); |
076b876e | 31570 | +out_buf: |
1c60b727 | 31571 | + free_page((unsigned long)buf); |
076b876e AM |
31572 | +out: |
31573 | + si_read_unlock(sb); | |
31574 | + return err; | |
31575 | +} | |
31576 | + | |
31577 | +long au_brinfo_ioctl(struct file *file, unsigned long arg) | |
31578 | +{ | |
2000de60 | 31579 | + return au_brinfo(file->f_path.dentry->d_sb, (void __user *)arg); |
076b876e AM |
31580 | +} |
31581 | + | |
31582 | +#ifdef CONFIG_COMPAT | |
31583 | +long au_brinfo_compat_ioctl(struct file *file, unsigned long arg) | |
31584 | +{ | |
2000de60 | 31585 | + return au_brinfo(file->f_path.dentry->d_sb, compat_ptr(arg)); |
076b876e AM |
31586 | +} |
31587 | +#endif | |
31588 | + | |
31589 | +/* ---------------------------------------------------------------------- */ | |
31590 | + | |
1facf9fc | 31591 | +void sysaufs_br_init(struct au_branch *br) |
31592 | +{ | |
392086de AM |
31593 | + int i; |
31594 | + struct au_brsysfs *br_sysfs; | |
31595 | + struct attribute *attr; | |
4a4d8108 | 31596 | + |
392086de AM |
31597 | + br_sysfs = br->br_sysfs; |
31598 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
31599 | + attr = &br_sysfs->attr; | |
31600 | + sysfs_attr_init(attr); | |
31601 | + attr->name = br_sysfs->name; | |
cd7a4cd9 | 31602 | + attr->mode = 0444; |
392086de AM |
31603 | + br_sysfs++; |
31604 | + } | |
1facf9fc | 31605 | +} |
31606 | + | |
31607 | +void sysaufs_brs_del(struct super_block *sb, aufs_bindex_t bindex) | |
31608 | +{ | |
31609 | + struct au_branch *br; | |
31610 | + struct kobject *kobj; | |
392086de AM |
31611 | + struct au_brsysfs *br_sysfs; |
31612 | + int i; | |
5afbbe0d | 31613 | + aufs_bindex_t bbot; |
1facf9fc | 31614 | + |
1facf9fc | 31615 | + if (!sysaufs_brs) |
31616 | + return; | |
31617 | + | |
31618 | + kobj = &au_sbi(sb)->si_kobj; | |
5afbbe0d AM |
31619 | + bbot = au_sbbot(sb); |
31620 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 31621 | + br = au_sbr(sb, bindex); |
392086de AM |
31622 | + br_sysfs = br->br_sysfs; |
31623 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
31624 | + sysfs_remove_file(kobj, &br_sysfs->attr); | |
31625 | + br_sysfs++; | |
31626 | + } | |
1facf9fc | 31627 | + } |
31628 | +} | |
31629 | + | |
31630 | +void sysaufs_brs_add(struct super_block *sb, aufs_bindex_t bindex) | |
31631 | +{ | |
392086de | 31632 | + int err, i; |
5afbbe0d | 31633 | + aufs_bindex_t bbot; |
1facf9fc | 31634 | + struct kobject *kobj; |
31635 | + struct au_branch *br; | |
392086de | 31636 | + struct au_brsysfs *br_sysfs; |
1facf9fc | 31637 | + |
1facf9fc | 31638 | + if (!sysaufs_brs) |
31639 | + return; | |
31640 | + | |
31641 | + kobj = &au_sbi(sb)->si_kobj; | |
5afbbe0d AM |
31642 | + bbot = au_sbbot(sb); |
31643 | + for (; bindex <= bbot; bindex++) { | |
1facf9fc | 31644 | + br = au_sbr(sb, bindex); |
392086de AM |
31645 | + br_sysfs = br->br_sysfs; |
31646 | + snprintf(br_sysfs[AuBrSysfs_BR].name, sizeof(br_sysfs->name), | |
31647 | + SysaufsBr_PREFIX "%d", bindex); | |
31648 | + snprintf(br_sysfs[AuBrSysfs_BRID].name, sizeof(br_sysfs->name), | |
31649 | + SysaufsBrid_PREFIX "%d", bindex); | |
31650 | + for (i = 0; i < ARRAY_SIZE(br->br_sysfs); i++) { | |
31651 | + err = sysfs_create_file(kobj, &br_sysfs->attr); | |
31652 | + if (unlikely(err)) | |
31653 | + pr_warn("failed %s under sysfs(%d)\n", | |
31654 | + br_sysfs->name, err); | |
31655 | + br_sysfs++; | |
31656 | + } | |
1facf9fc | 31657 | + } |
31658 | +} | |
7f207e10 | 31659 | diff -urN /usr/share/empty/fs/aufs/sysrq.c linux/fs/aufs/sysrq.c |
eca34b5c | 31660 | --- /usr/share/empty/fs/aufs/sysrq.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 31661 | +++ linux/fs/aufs/sysrq.c 2020-01-27 10:57:18.178871751 +0100 |
43982f53 | 31662 | @@ -0,0 +1,149 @@ |
cd7a4cd9 | 31663 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 31664 | +/* |
d58c55f2 | 31665 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 31666 | + * |
31667 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31668 | + * it under the terms of the GNU General Public License as published by | |
31669 | + * the Free Software Foundation; either version 2 of the License, or | |
31670 | + * (at your option) any later version. | |
dece6358 AM |
31671 | + * |
31672 | + * This program is distributed in the hope that it will be useful, | |
31673 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31674 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31675 | + * GNU General Public License for more details. | |
31676 | + * | |
31677 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31678 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31679 | + */ |
31680 | + | |
31681 | +/* | |
acd2b654 | 31682 | + * magic sysrq handler |
1facf9fc | 31683 | + */ |
31684 | + | |
1facf9fc | 31685 | +/* #include <linux/sysrq.h> */ |
027c5e7a | 31686 | +#include <linux/writeback.h> |
1facf9fc | 31687 | +#include "aufs.h" |
31688 | + | |
31689 | +/* ---------------------------------------------------------------------- */ | |
31690 | + | |
31691 | +static void sysrq_sb(struct super_block *sb) | |
31692 | +{ | |
31693 | + char *plevel; | |
31694 | + struct au_sbinfo *sbinfo; | |
31695 | + struct file *file; | |
8b6a4947 AM |
31696 | + struct hlist_bl_head *files; |
31697 | + struct hlist_bl_node *pos; | |
523b37e3 | 31698 | + struct au_finfo *finfo; |
43982f53 | 31699 | + struct inode *i; |
1facf9fc | 31700 | + |
31701 | + plevel = au_plevel; | |
31702 | + au_plevel = KERN_WARNING; | |
1facf9fc | 31703 | + |
4a4d8108 | 31704 | + /* since we define pr_fmt, call printk directly */ |
c06a8ce3 AM |
31705 | +#define pr(str) printk(KERN_WARNING AUFS_NAME ": " str) |
31706 | + | |
31707 | + sbinfo = au_sbi(sb); | |
4a4d8108 | 31708 | + printk(KERN_WARNING "si=%lx\n", sysaufs_si_id(sbinfo)); |
c06a8ce3 | 31709 | + pr("superblock\n"); |
1facf9fc | 31710 | + au_dpri_sb(sb); |
027c5e7a | 31711 | + |
43982f53 | 31712 | +#if 0 /* reserved */ |
027c5e7a AM |
31713 | + do { |
31714 | + int err, i, j, ndentry; | |
31715 | + struct au_dcsub_pages dpages; | |
31716 | + struct au_dpage *dpage; | |
31717 | + | |
31718 | + err = au_dpages_init(&dpages, GFP_ATOMIC); | |
31719 | + if (unlikely(err)) | |
31720 | + break; | |
31721 | + err = au_dcsub_pages(&dpages, sb->s_root, NULL, NULL); | |
31722 | + if (!err) | |
31723 | + for (i = 0; i < dpages.ndpage; i++) { | |
31724 | + dpage = dpages.dpages + i; | |
31725 | + ndentry = dpage->ndentry; | |
31726 | + for (j = 0; j < ndentry; j++) | |
31727 | + au_dpri_dentry(dpage->dentries[j]); | |
31728 | + } | |
31729 | + au_dpages_free(&dpages); | |
31730 | + } while (0); | |
31731 | +#endif | |
31732 | + | |
43982f53 AM |
31733 | + pr("isolated inode\n"); |
31734 | + spin_lock(&sb->s_inode_list_lock); | |
31735 | + list_for_each_entry(i, &sb->s_inodes, i_sb_list) { | |
31736 | + spin_lock(&i->i_lock); | |
31737 | + if (hlist_empty(&i->i_dentry)) | |
31738 | + au_dpri_inode(i); | |
31739 | + spin_unlock(&i->i_lock); | |
027c5e7a | 31740 | + } |
43982f53 AM |
31741 | + spin_unlock(&sb->s_inode_list_lock); |
31742 | + | |
c06a8ce3 | 31743 | + pr("files\n"); |
523b37e3 | 31744 | + files = &au_sbi(sb)->si_files; |
8b6a4947 AM |
31745 | + hlist_bl_lock(files); |
31746 | + hlist_bl_for_each_entry(finfo, pos, files, fi_hlist) { | |
4a4d8108 | 31747 | + umode_t mode; |
076b876e | 31748 | + |
523b37e3 | 31749 | + file = finfo->fi_file; |
c06a8ce3 | 31750 | + mode = file_inode(file)->i_mode; |
38d290e6 | 31751 | + if (!special_file(mode)) |
1facf9fc | 31752 | + au_dpri_file(file); |
523b37e3 | 31753 | + } |
8b6a4947 | 31754 | + hlist_bl_unlock(files); |
c06a8ce3 | 31755 | + pr("done\n"); |
1facf9fc | 31756 | + |
c06a8ce3 | 31757 | +#undef pr |
1facf9fc | 31758 | + au_plevel = plevel; |
1facf9fc | 31759 | +} |
31760 | + | |
31761 | +/* ---------------------------------------------------------------------- */ | |
31762 | + | |
31763 | +/* module parameter */ | |
31764 | +static char *aufs_sysrq_key = "a"; | |
cd7a4cd9 | 31765 | +module_param_named(sysrq, aufs_sysrq_key, charp, 0444); |
1facf9fc | 31766 | +MODULE_PARM_DESC(sysrq, "MagicSysRq key for " AUFS_NAME); |
31767 | + | |
0c5527e5 | 31768 | +static void au_sysrq(int key __maybe_unused) |
1facf9fc | 31769 | +{ |
1facf9fc | 31770 | + struct au_sbinfo *sbinfo; |
8b6a4947 | 31771 | + struct hlist_bl_node *pos; |
1facf9fc | 31772 | + |
027c5e7a | 31773 | + lockdep_off(); |
53392da6 | 31774 | + au_sbilist_lock(); |
8b6a4947 | 31775 | + hlist_bl_for_each_entry(sbinfo, pos, &au_sbilist, si_list) |
1facf9fc | 31776 | + sysrq_sb(sbinfo->si_sb); |
53392da6 | 31777 | + au_sbilist_unlock(); |
027c5e7a | 31778 | + lockdep_on(); |
1facf9fc | 31779 | +} |
31780 | + | |
31781 | +static struct sysrq_key_op au_sysrq_op = { | |
31782 | + .handler = au_sysrq, | |
31783 | + .help_msg = "Aufs", | |
31784 | + .action_msg = "Aufs", | |
31785 | + .enable_mask = SYSRQ_ENABLE_DUMP | |
31786 | +}; | |
31787 | + | |
31788 | +/* ---------------------------------------------------------------------- */ | |
31789 | + | |
31790 | +int __init au_sysrq_init(void) | |
31791 | +{ | |
31792 | + int err; | |
31793 | + char key; | |
31794 | + | |
31795 | + err = -1; | |
31796 | + key = *aufs_sysrq_key; | |
31797 | + if ('a' <= key && key <= 'z') | |
31798 | + err = register_sysrq_key(key, &au_sysrq_op); | |
31799 | + if (unlikely(err)) | |
4a4d8108 | 31800 | + pr_err("err %d, sysrq=%c\n", err, key); |
1facf9fc | 31801 | + return err; |
31802 | +} | |
31803 | + | |
31804 | +void au_sysrq_fin(void) | |
31805 | +{ | |
31806 | + int err; | |
076b876e | 31807 | + |
1facf9fc | 31808 | + err = unregister_sysrq_key(*aufs_sysrq_key, &au_sysrq_op); |
31809 | + if (unlikely(err)) | |
4a4d8108 | 31810 | + pr_err("err %d (ignored)\n", err); |
1facf9fc | 31811 | +} |
7f207e10 | 31812 | diff -urN /usr/share/empty/fs/aufs/vdir.c linux/fs/aufs/vdir.c |
eca34b5c | 31813 | --- /usr/share/empty/fs/aufs/vdir.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 31814 | +++ linux/fs/aufs/vdir.c 2020-01-27 10:57:18.178871751 +0100 |
eca801bf | 31815 | @@ -0,0 +1,896 @@ |
cd7a4cd9 | 31816 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 31817 | +/* |
d58c55f2 | 31818 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 31819 | + * |
31820 | + * This program, aufs is free software; you can redistribute it and/or modify | |
31821 | + * it under the terms of the GNU General Public License as published by | |
31822 | + * the Free Software Foundation; either version 2 of the License, or | |
31823 | + * (at your option) any later version. | |
dece6358 AM |
31824 | + * |
31825 | + * This program is distributed in the hope that it will be useful, | |
31826 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31827 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
31828 | + * GNU General Public License for more details. | |
31829 | + * | |
31830 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 31831 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 31832 | + */ |
31833 | + | |
31834 | +/* | |
31835 | + * virtual or vertical directory | |
31836 | + */ | |
31837 | + | |
eca801bf | 31838 | +#include <linux/iversion.h> |
1facf9fc | 31839 | +#include "aufs.h" |
31840 | + | |
dece6358 | 31841 | +static unsigned int calc_size(int nlen) |
1facf9fc | 31842 | +{ |
dece6358 | 31843 | + return ALIGN(sizeof(struct au_vdir_de) + nlen, sizeof(ino_t)); |
1facf9fc | 31844 | +} |
31845 | + | |
31846 | +static int set_deblk_end(union au_vdir_deblk_p *p, | |
31847 | + union au_vdir_deblk_p *deblk_end) | |
31848 | +{ | |
31849 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) { | |
31850 | + p->de->de_str.len = 0; | |
31851 | + /* smp_mb(); */ | |
31852 | + return 0; | |
31853 | + } | |
31854 | + return -1; /* error */ | |
31855 | +} | |
31856 | + | |
31857 | +/* returns true or false */ | |
31858 | +static int is_deblk_end(union au_vdir_deblk_p *p, | |
31859 | + union au_vdir_deblk_p *deblk_end) | |
31860 | +{ | |
31861 | + if (calc_size(0) <= deblk_end->deblk - p->deblk) | |
31862 | + return !p->de->de_str.len; | |
31863 | + return 1; | |
31864 | +} | |
31865 | + | |
31866 | +static unsigned char *last_deblk(struct au_vdir *vdir) | |
31867 | +{ | |
31868 | + return vdir->vd_deblk[vdir->vd_nblk - 1]; | |
31869 | +} | |
31870 | + | |
31871 | +/* ---------------------------------------------------------------------- */ | |
31872 | + | |
79b8bda9 | 31873 | +/* estimate the appropriate size for name hash table */ |
1308ab2a | 31874 | +unsigned int au_rdhash_est(loff_t sz) |
31875 | +{ | |
31876 | + unsigned int n; | |
31877 | + | |
31878 | + n = UINT_MAX; | |
31879 | + sz >>= 10; | |
31880 | + if (sz < n) | |
31881 | + n = sz; | |
31882 | + if (sz < AUFS_RDHASH_DEF) | |
31883 | + n = AUFS_RDHASH_DEF; | |
4a4d8108 | 31884 | + /* pr_info("n %u\n", n); */ |
1308ab2a | 31885 | + return n; |
31886 | +} | |
31887 | + | |
1facf9fc | 31888 | +/* |
31889 | + * the allocated memory has to be freed by | |
dece6358 | 31890 | + * au_nhash_wh_free() or au_nhash_de_free(). |
1facf9fc | 31891 | + */ |
dece6358 | 31892 | +int au_nhash_alloc(struct au_nhash *nhash, unsigned int num_hash, gfp_t gfp) |
1facf9fc | 31893 | +{ |
1facf9fc | 31894 | + struct hlist_head *head; |
dece6358 | 31895 | + unsigned int u; |
076b876e | 31896 | + size_t sz; |
1facf9fc | 31897 | + |
076b876e AM |
31898 | + sz = sizeof(*nhash->nh_head) * num_hash; |
31899 | + head = kmalloc(sz, gfp); | |
dece6358 AM |
31900 | + if (head) { |
31901 | + nhash->nh_num = num_hash; | |
31902 | + nhash->nh_head = head; | |
31903 | + for (u = 0; u < num_hash; u++) | |
1facf9fc | 31904 | + INIT_HLIST_HEAD(head++); |
dece6358 | 31905 | + return 0; /* success */ |
1facf9fc | 31906 | + } |
1facf9fc | 31907 | + |
dece6358 | 31908 | + return -ENOMEM; |
1facf9fc | 31909 | +} |
31910 | + | |
dece6358 AM |
31911 | +static void nhash_count(struct hlist_head *head) |
31912 | +{ | |
43982f53 | 31913 | +#if 0 /* debugging */ |
dece6358 AM |
31914 | + unsigned long n; |
31915 | + struct hlist_node *pos; | |
31916 | + | |
31917 | + n = 0; | |
31918 | + hlist_for_each(pos, head) | |
31919 | + n++; | |
4a4d8108 | 31920 | + pr_info("%lu\n", n); |
dece6358 AM |
31921 | +#endif |
31922 | +} | |
31923 | + | |
31924 | +static void au_nhash_wh_do_free(struct hlist_head *head) | |
1facf9fc | 31925 | +{ |
c06a8ce3 AM |
31926 | + struct au_vdir_wh *pos; |
31927 | + struct hlist_node *node; | |
1facf9fc | 31928 | + |
c06a8ce3 | 31929 | + hlist_for_each_entry_safe(pos, node, head, wh_hash) |
9f237c51 | 31930 | + au_kfree_rcu(pos); |
1facf9fc | 31931 | +} |
31932 | + | |
dece6358 | 31933 | +static void au_nhash_de_do_free(struct hlist_head *head) |
1facf9fc | 31934 | +{ |
c06a8ce3 AM |
31935 | + struct au_vdir_dehstr *pos; |
31936 | + struct hlist_node *node; | |
1facf9fc | 31937 | + |
c06a8ce3 | 31938 | + hlist_for_each_entry_safe(pos, node, head, hash) |
1c60b727 | 31939 | + au_cache_free_vdir_dehstr(pos); |
1facf9fc | 31940 | +} |
31941 | + | |
dece6358 AM |
31942 | +static void au_nhash_do_free(struct au_nhash *nhash, |
31943 | + void (*free)(struct hlist_head *head)) | |
1facf9fc | 31944 | +{ |
1308ab2a | 31945 | + unsigned int n; |
1facf9fc | 31946 | + struct hlist_head *head; |
1facf9fc | 31947 | + |
dece6358 | 31948 | + n = nhash->nh_num; |
1308ab2a | 31949 | + if (!n) |
31950 | + return; | |
31951 | + | |
dece6358 | 31952 | + head = nhash->nh_head; |
1308ab2a | 31953 | + while (n-- > 0) { |
dece6358 AM |
31954 | + nhash_count(head); |
31955 | + free(head++); | |
1facf9fc | 31956 | + } |
9f237c51 | 31957 | + au_kfree_try_rcu(nhash->nh_head); |
1facf9fc | 31958 | +} |
31959 | + | |
dece6358 | 31960 | +void au_nhash_wh_free(struct au_nhash *whlist) |
1facf9fc | 31961 | +{ |
dece6358 AM |
31962 | + au_nhash_do_free(whlist, au_nhash_wh_do_free); |
31963 | +} | |
1facf9fc | 31964 | + |
dece6358 AM |
31965 | +static void au_nhash_de_free(struct au_nhash *delist) |
31966 | +{ | |
31967 | + au_nhash_do_free(delist, au_nhash_de_do_free); | |
1facf9fc | 31968 | +} |
31969 | + | |
31970 | +/* ---------------------------------------------------------------------- */ | |
31971 | + | |
31972 | +int au_nhash_test_longer_wh(struct au_nhash *whlist, aufs_bindex_t btgt, | |
31973 | + int limit) | |
31974 | +{ | |
31975 | + int num; | |
31976 | + unsigned int u, n; | |
31977 | + struct hlist_head *head; | |
c06a8ce3 | 31978 | + struct au_vdir_wh *pos; |
1facf9fc | 31979 | + |
31980 | + num = 0; | |
31981 | + n = whlist->nh_num; | |
31982 | + head = whlist->nh_head; | |
1308ab2a | 31983 | + for (u = 0; u < n; u++, head++) |
c06a8ce3 AM |
31984 | + hlist_for_each_entry(pos, head, wh_hash) |
31985 | + if (pos->wh_bindex == btgt && ++num > limit) | |
1facf9fc | 31986 | + return 1; |
1facf9fc | 31987 | + return 0; |
31988 | +} | |
31989 | + | |
31990 | +static struct hlist_head *au_name_hash(struct au_nhash *nhash, | |
dece6358 | 31991 | + unsigned char *name, |
1facf9fc | 31992 | + unsigned int len) |
31993 | +{ | |
dece6358 AM |
31994 | + unsigned int v; |
31995 | + /* const unsigned int magic_bit = 12; */ | |
31996 | + | |
1308ab2a | 31997 | + AuDebugOn(!nhash->nh_num || !nhash->nh_head); |
31998 | + | |
dece6358 | 31999 | + v = 0; |
f0c0a007 AM |
32000 | + if (len > 8) |
32001 | + len = 8; | |
dece6358 AM |
32002 | + while (len--) |
32003 | + v += *name++; | |
32004 | + /* v = hash_long(v, magic_bit); */ | |
32005 | + v %= nhash->nh_num; | |
32006 | + return nhash->nh_head + v; | |
32007 | +} | |
32008 | + | |
32009 | +static int au_nhash_test_name(struct au_vdir_destr *str, const char *name, | |
32010 | + int nlen) | |
32011 | +{ | |
32012 | + return str->len == nlen && !memcmp(str->name, name, nlen); | |
1facf9fc | 32013 | +} |
32014 | + | |
32015 | +/* returns found or not */ | |
dece6358 | 32016 | +int au_nhash_test_known_wh(struct au_nhash *whlist, char *name, int nlen) |
1facf9fc | 32017 | +{ |
32018 | + struct hlist_head *head; | |
c06a8ce3 | 32019 | + struct au_vdir_wh *pos; |
1facf9fc | 32020 | + struct au_vdir_destr *str; |
32021 | + | |
dece6358 | 32022 | + head = au_name_hash(whlist, name, nlen); |
c06a8ce3 AM |
32023 | + hlist_for_each_entry(pos, head, wh_hash) { |
32024 | + str = &pos->wh_str; | |
1facf9fc | 32025 | + AuDbg("%.*s\n", str->len, str->name); |
dece6358 AM |
32026 | + if (au_nhash_test_name(str, name, nlen)) |
32027 | + return 1; | |
32028 | + } | |
32029 | + return 0; | |
32030 | +} | |
32031 | + | |
32032 | +/* returns found(true) or not */ | |
32033 | +static int test_known(struct au_nhash *delist, char *name, int nlen) | |
32034 | +{ | |
32035 | + struct hlist_head *head; | |
c06a8ce3 | 32036 | + struct au_vdir_dehstr *pos; |
dece6358 AM |
32037 | + struct au_vdir_destr *str; |
32038 | + | |
32039 | + head = au_name_hash(delist, name, nlen); | |
c06a8ce3 AM |
32040 | + hlist_for_each_entry(pos, head, hash) { |
32041 | + str = pos->str; | |
dece6358 AM |
32042 | + AuDbg("%.*s\n", str->len, str->name); |
32043 | + if (au_nhash_test_name(str, name, nlen)) | |
1facf9fc | 32044 | + return 1; |
32045 | + } | |
32046 | + return 0; | |
32047 | +} | |
32048 | + | |
dece6358 AM |
32049 | +static void au_shwh_init_wh(struct au_vdir_wh *wh, ino_t ino, |
32050 | + unsigned char d_type) | |
32051 | +{ | |
32052 | +#ifdef CONFIG_AUFS_SHWH | |
32053 | + wh->wh_ino = ino; | |
32054 | + wh->wh_type = d_type; | |
32055 | +#endif | |
32056 | +} | |
32057 | + | |
32058 | +/* ---------------------------------------------------------------------- */ | |
32059 | + | |
32060 | +int au_nhash_append_wh(struct au_nhash *whlist, char *name, int nlen, ino_t ino, | |
32061 | + unsigned int d_type, aufs_bindex_t bindex, | |
32062 | + unsigned char shwh) | |
1facf9fc | 32063 | +{ |
32064 | + int err; | |
32065 | + struct au_vdir_destr *str; | |
32066 | + struct au_vdir_wh *wh; | |
32067 | + | |
dece6358 | 32068 | + AuDbg("%.*s\n", nlen, name); |
1308ab2a | 32069 | + AuDebugOn(!whlist->nh_num || !whlist->nh_head); |
32070 | + | |
1facf9fc | 32071 | + err = -ENOMEM; |
dece6358 | 32072 | + wh = kmalloc(sizeof(*wh) + nlen, GFP_NOFS); |
1facf9fc | 32073 | + if (unlikely(!wh)) |
32074 | + goto out; | |
32075 | + | |
32076 | + err = 0; | |
32077 | + wh->wh_bindex = bindex; | |
dece6358 AM |
32078 | + if (shwh) |
32079 | + au_shwh_init_wh(wh, ino, d_type); | |
1facf9fc | 32080 | + str = &wh->wh_str; |
dece6358 AM |
32081 | + str->len = nlen; |
32082 | + memcpy(str->name, name, nlen); | |
32083 | + hlist_add_head(&wh->wh_hash, au_name_hash(whlist, name, nlen)); | |
1facf9fc | 32084 | + /* smp_mb(); */ |
32085 | + | |
4f0767ce | 32086 | +out: |
1facf9fc | 32087 | + return err; |
32088 | +} | |
32089 | + | |
1facf9fc | 32090 | +static int append_deblk(struct au_vdir *vdir) |
32091 | +{ | |
32092 | + int err; | |
dece6358 | 32093 | + unsigned long ul; |
1facf9fc | 32094 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; |
32095 | + union au_vdir_deblk_p p, deblk_end; | |
32096 | + unsigned char **o; | |
32097 | + | |
32098 | + err = -ENOMEM; | |
e2f27e51 AM |
32099 | + o = au_krealloc(vdir->vd_deblk, sizeof(*o) * (vdir->vd_nblk + 1), |
32100 | + GFP_NOFS, /*may_shrink*/0); | |
1facf9fc | 32101 | + if (unlikely(!o)) |
32102 | + goto out; | |
32103 | + | |
32104 | + vdir->vd_deblk = o; | |
32105 | + p.deblk = kmalloc(deblk_sz, GFP_NOFS); | |
32106 | + if (p.deblk) { | |
32107 | + ul = vdir->vd_nblk++; | |
32108 | + vdir->vd_deblk[ul] = p.deblk; | |
32109 | + vdir->vd_last.ul = ul; | |
32110 | + vdir->vd_last.p.deblk = p.deblk; | |
32111 | + deblk_end.deblk = p.deblk + deblk_sz; | |
32112 | + err = set_deblk_end(&p, &deblk_end); | |
32113 | + } | |
32114 | + | |
4f0767ce | 32115 | +out: |
1facf9fc | 32116 | + return err; |
32117 | +} | |
32118 | + | |
dece6358 AM |
32119 | +static int append_de(struct au_vdir *vdir, char *name, int nlen, ino_t ino, |
32120 | + unsigned int d_type, struct au_nhash *delist) | |
32121 | +{ | |
32122 | + int err; | |
32123 | + unsigned int sz; | |
32124 | + const unsigned int deblk_sz = vdir->vd_deblk_sz; | |
32125 | + union au_vdir_deblk_p p, *room, deblk_end; | |
32126 | + struct au_vdir_dehstr *dehstr; | |
32127 | + | |
32128 | + p.deblk = last_deblk(vdir); | |
32129 | + deblk_end.deblk = p.deblk + deblk_sz; | |
32130 | + room = &vdir->vd_last.p; | |
32131 | + AuDebugOn(room->deblk < p.deblk || deblk_end.deblk <= room->deblk | |
32132 | + || !is_deblk_end(room, &deblk_end)); | |
32133 | + | |
32134 | + sz = calc_size(nlen); | |
32135 | + if (unlikely(sz > deblk_end.deblk - room->deblk)) { | |
32136 | + err = append_deblk(vdir); | |
32137 | + if (unlikely(err)) | |
32138 | + goto out; | |
32139 | + | |
32140 | + p.deblk = last_deblk(vdir); | |
32141 | + deblk_end.deblk = p.deblk + deblk_sz; | |
32142 | + /* smp_mb(); */ | |
32143 | + AuDebugOn(room->deblk != p.deblk); | |
32144 | + } | |
32145 | + | |
32146 | + err = -ENOMEM; | |
4a4d8108 | 32147 | + dehstr = au_cache_alloc_vdir_dehstr(); |
dece6358 AM |
32148 | + if (unlikely(!dehstr)) |
32149 | + goto out; | |
32150 | + | |
32151 | + dehstr->str = &room->de->de_str; | |
32152 | + hlist_add_head(&dehstr->hash, au_name_hash(delist, name, nlen)); | |
32153 | + room->de->de_ino = ino; | |
32154 | + room->de->de_type = d_type; | |
32155 | + room->de->de_str.len = nlen; | |
32156 | + memcpy(room->de->de_str.name, name, nlen); | |
32157 | + | |
32158 | + err = 0; | |
32159 | + room->deblk += sz; | |
32160 | + if (unlikely(set_deblk_end(room, &deblk_end))) | |
32161 | + err = append_deblk(vdir); | |
32162 | + /* smp_mb(); */ | |
32163 | + | |
4f0767ce | 32164 | +out: |
dece6358 AM |
32165 | + return err; |
32166 | +} | |
32167 | + | |
32168 | +/* ---------------------------------------------------------------------- */ | |
32169 | + | |
1c60b727 | 32170 | +void au_vdir_free(struct au_vdir *vdir) |
dece6358 AM |
32171 | +{ |
32172 | + unsigned char **deblk; | |
32173 | + | |
32174 | + deblk = vdir->vd_deblk; | |
1c60b727 | 32175 | + while (vdir->vd_nblk--) |
9f237c51 AM |
32176 | + au_kfree_try_rcu(*deblk++); |
32177 | + au_kfree_try_rcu(vdir->vd_deblk); | |
1c60b727 | 32178 | + au_cache_free_vdir(vdir); |
dece6358 AM |
32179 | +} |
32180 | + | |
1308ab2a | 32181 | +static struct au_vdir *alloc_vdir(struct file *file) |
1facf9fc | 32182 | +{ |
32183 | + struct au_vdir *vdir; | |
1308ab2a | 32184 | + struct super_block *sb; |
1facf9fc | 32185 | + int err; |
32186 | + | |
2000de60 | 32187 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
32188 | + SiMustAnyLock(sb); |
32189 | + | |
1facf9fc | 32190 | + err = -ENOMEM; |
32191 | + vdir = au_cache_alloc_vdir(); | |
32192 | + if (unlikely(!vdir)) | |
32193 | + goto out; | |
32194 | + | |
32195 | + vdir->vd_deblk = kzalloc(sizeof(*vdir->vd_deblk), GFP_NOFS); | |
32196 | + if (unlikely(!vdir->vd_deblk)) | |
32197 | + goto out_free; | |
32198 | + | |
32199 | + vdir->vd_deblk_sz = au_sbi(sb)->si_rdblk; | |
1308ab2a | 32200 | + if (!vdir->vd_deblk_sz) { |
79b8bda9 | 32201 | + /* estimate the appropriate size for deblk */ |
1308ab2a | 32202 | + vdir->vd_deblk_sz = au_dir_size(file, /*dentry*/NULL); |
4a4d8108 | 32203 | + /* pr_info("vd_deblk_sz %u\n", vdir->vd_deblk_sz); */ |
1308ab2a | 32204 | + } |
1facf9fc | 32205 | + vdir->vd_nblk = 0; |
32206 | + vdir->vd_version = 0; | |
32207 | + vdir->vd_jiffy = 0; | |
32208 | + err = append_deblk(vdir); | |
32209 | + if (!err) | |
32210 | + return vdir; /* success */ | |
32211 | + | |
9f237c51 | 32212 | + au_kfree_try_rcu(vdir->vd_deblk); |
1facf9fc | 32213 | + |
4f0767ce | 32214 | +out_free: |
1c60b727 | 32215 | + au_cache_free_vdir(vdir); |
4f0767ce | 32216 | +out: |
1facf9fc | 32217 | + vdir = ERR_PTR(err); |
32218 | + return vdir; | |
32219 | +} | |
32220 | + | |
32221 | +static int reinit_vdir(struct au_vdir *vdir) | |
32222 | +{ | |
32223 | + int err; | |
32224 | + union au_vdir_deblk_p p, deblk_end; | |
32225 | + | |
32226 | + while (vdir->vd_nblk > 1) { | |
9f237c51 | 32227 | + au_kfree_try_rcu(vdir->vd_deblk[vdir->vd_nblk - 1]); |
1facf9fc | 32228 | + /* vdir->vd_deblk[vdir->vd_nblk - 1] = NULL; */ |
32229 | + vdir->vd_nblk--; | |
32230 | + } | |
32231 | + p.deblk = vdir->vd_deblk[0]; | |
32232 | + deblk_end.deblk = p.deblk + vdir->vd_deblk_sz; | |
32233 | + err = set_deblk_end(&p, &deblk_end); | |
32234 | + /* keep vd_dblk_sz */ | |
32235 | + vdir->vd_last.ul = 0; | |
32236 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
32237 | + vdir->vd_version = 0; | |
32238 | + vdir->vd_jiffy = 0; | |
32239 | + /* smp_mb(); */ | |
32240 | + return err; | |
32241 | +} | |
32242 | + | |
32243 | +/* ---------------------------------------------------------------------- */ | |
32244 | + | |
1facf9fc | 32245 | +#define AuFillVdir_CALLED 1 |
32246 | +#define AuFillVdir_WHABLE (1 << 1) | |
dece6358 | 32247 | +#define AuFillVdir_SHWH (1 << 2) |
1facf9fc | 32248 | +#define au_ftest_fillvdir(flags, name) ((flags) & AuFillVdir_##name) |
7f207e10 AM |
32249 | +#define au_fset_fillvdir(flags, name) \ |
32250 | + do { (flags) |= AuFillVdir_##name; } while (0) | |
32251 | +#define au_fclr_fillvdir(flags, name) \ | |
32252 | + do { (flags) &= ~AuFillVdir_##name; } while (0) | |
1facf9fc | 32253 | + |
dece6358 AM |
32254 | +#ifndef CONFIG_AUFS_SHWH |
32255 | +#undef AuFillVdir_SHWH | |
32256 | +#define AuFillVdir_SHWH 0 | |
32257 | +#endif | |
32258 | + | |
1facf9fc | 32259 | +struct fillvdir_arg { |
392086de | 32260 | + struct dir_context ctx; |
1facf9fc | 32261 | + struct file *file; |
32262 | + struct au_vdir *vdir; | |
dece6358 AM |
32263 | + struct au_nhash delist; |
32264 | + struct au_nhash whlist; | |
1facf9fc | 32265 | + aufs_bindex_t bindex; |
32266 | + unsigned int flags; | |
32267 | + int err; | |
32268 | +}; | |
32269 | + | |
392086de | 32270 | +static int fillvdir(struct dir_context *ctx, const char *__name, int nlen, |
1facf9fc | 32271 | + loff_t offset __maybe_unused, u64 h_ino, |
32272 | + unsigned int d_type) | |
32273 | +{ | |
392086de | 32274 | + struct fillvdir_arg *arg = container_of(ctx, struct fillvdir_arg, ctx); |
1facf9fc | 32275 | + char *name = (void *)__name; |
32276 | + struct super_block *sb; | |
1facf9fc | 32277 | + ino_t ino; |
dece6358 | 32278 | + const unsigned char shwh = !!au_ftest_fillvdir(arg->flags, SHWH); |
1facf9fc | 32279 | + |
1facf9fc | 32280 | + arg->err = 0; |
2000de60 | 32281 | + sb = arg->file->f_path.dentry->d_sb; |
1facf9fc | 32282 | + au_fset_fillvdir(arg->flags, CALLED); |
32283 | + /* smp_mb(); */ | |
dece6358 | 32284 | + if (nlen <= AUFS_WH_PFX_LEN |
1facf9fc | 32285 | + || memcmp(name, AUFS_WH_PFX, AUFS_WH_PFX_LEN)) { |
dece6358 AM |
32286 | + if (test_known(&arg->delist, name, nlen) |
32287 | + || au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
32288 | + goto out; /* already exists or whiteouted */ | |
1facf9fc | 32289 | + |
dece6358 | 32290 | + arg->err = au_ino(sb, arg->bindex, h_ino, d_type, &ino); |
4a4d8108 AM |
32291 | + if (!arg->err) { |
32292 | + if (unlikely(nlen > AUFS_MAX_NAMELEN)) | |
32293 | + d_type = DT_UNKNOWN; | |
dece6358 AM |
32294 | + arg->err = append_de(arg->vdir, name, nlen, ino, |
32295 | + d_type, &arg->delist); | |
4a4d8108 | 32296 | + } |
1facf9fc | 32297 | + } else if (au_ftest_fillvdir(arg->flags, WHABLE)) { |
32298 | + name += AUFS_WH_PFX_LEN; | |
dece6358 AM |
32299 | + nlen -= AUFS_WH_PFX_LEN; |
32300 | + if (au_nhash_test_known_wh(&arg->whlist, name, nlen)) | |
32301 | + goto out; /* already whiteouted */ | |
1facf9fc | 32302 | + |
acd2b654 | 32303 | + ino = 0; /* just to suppress a warning */ |
dece6358 AM |
32304 | + if (shwh) |
32305 | + arg->err = au_wh_ino(sb, arg->bindex, h_ino, d_type, | |
32306 | + &ino); | |
4a4d8108 AM |
32307 | + if (!arg->err) { |
32308 | + if (nlen <= AUFS_MAX_NAMELEN + AUFS_WH_PFX_LEN) | |
32309 | + d_type = DT_UNKNOWN; | |
1facf9fc | 32310 | + arg->err = au_nhash_append_wh |
dece6358 AM |
32311 | + (&arg->whlist, name, nlen, ino, d_type, |
32312 | + arg->bindex, shwh); | |
4a4d8108 | 32313 | + } |
1facf9fc | 32314 | + } |
32315 | + | |
4f0767ce | 32316 | +out: |
1facf9fc | 32317 | + if (!arg->err) |
32318 | + arg->vdir->vd_jiffy = jiffies; | |
32319 | + /* smp_mb(); */ | |
32320 | + AuTraceErr(arg->err); | |
32321 | + return arg->err; | |
32322 | +} | |
32323 | + | |
dece6358 AM |
32324 | +static int au_handle_shwh(struct super_block *sb, struct au_vdir *vdir, |
32325 | + struct au_nhash *whlist, struct au_nhash *delist) | |
32326 | +{ | |
32327 | +#ifdef CONFIG_AUFS_SHWH | |
32328 | + int err; | |
32329 | + unsigned int nh, u; | |
32330 | + struct hlist_head *head; | |
c06a8ce3 AM |
32331 | + struct au_vdir_wh *pos; |
32332 | + struct hlist_node *n; | |
dece6358 AM |
32333 | + char *p, *o; |
32334 | + struct au_vdir_destr *destr; | |
32335 | + | |
32336 | + AuDebugOn(!au_opt_test(au_mntflags(sb), SHWH)); | |
32337 | + | |
32338 | + err = -ENOMEM; | |
537831f9 | 32339 | + o = p = (void *)__get_free_page(GFP_NOFS); |
dece6358 AM |
32340 | + if (unlikely(!p)) |
32341 | + goto out; | |
32342 | + | |
32343 | + err = 0; | |
32344 | + nh = whlist->nh_num; | |
32345 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
32346 | + p += AUFS_WH_PFX_LEN; | |
32347 | + for (u = 0; u < nh; u++) { | |
32348 | + head = whlist->nh_head + u; | |
c06a8ce3 AM |
32349 | + hlist_for_each_entry_safe(pos, n, head, wh_hash) { |
32350 | + destr = &pos->wh_str; | |
dece6358 AM |
32351 | + memcpy(p, destr->name, destr->len); |
32352 | + err = append_de(vdir, o, destr->len + AUFS_WH_PFX_LEN, | |
c06a8ce3 | 32353 | + pos->wh_ino, pos->wh_type, delist); |
dece6358 AM |
32354 | + if (unlikely(err)) |
32355 | + break; | |
32356 | + } | |
32357 | + } | |
32358 | + | |
1c60b727 | 32359 | + free_page((unsigned long)o); |
dece6358 | 32360 | + |
4f0767ce | 32361 | +out: |
dece6358 AM |
32362 | + AuTraceErr(err); |
32363 | + return err; | |
32364 | +#else | |
32365 | + return 0; | |
32366 | +#endif | |
32367 | +} | |
32368 | + | |
1facf9fc | 32369 | +static int au_do_read_vdir(struct fillvdir_arg *arg) |
32370 | +{ | |
32371 | + int err; | |
dece6358 | 32372 | + unsigned int rdhash; |
1facf9fc | 32373 | + loff_t offset; |
5afbbe0d | 32374 | + aufs_bindex_t bbot, bindex, btop; |
dece6358 | 32375 | + unsigned char shwh; |
1facf9fc | 32376 | + struct file *hf, *file; |
32377 | + struct super_block *sb; | |
32378 | + | |
1facf9fc | 32379 | + file = arg->file; |
2000de60 | 32380 | + sb = file->f_path.dentry->d_sb; |
dece6358 AM |
32381 | + SiMustAnyLock(sb); |
32382 | + | |
32383 | + rdhash = au_sbi(sb)->si_rdhash; | |
1308ab2a | 32384 | + if (!rdhash) |
32385 | + rdhash = au_rdhash_est(au_dir_size(file, /*dentry*/NULL)); | |
dece6358 AM |
32386 | + err = au_nhash_alloc(&arg->delist, rdhash, GFP_NOFS); |
32387 | + if (unlikely(err)) | |
1facf9fc | 32388 | + goto out; |
dece6358 AM |
32389 | + err = au_nhash_alloc(&arg->whlist, rdhash, GFP_NOFS); |
32390 | + if (unlikely(err)) | |
1facf9fc | 32391 | + goto out_delist; |
32392 | + | |
32393 | + err = 0; | |
32394 | + arg->flags = 0; | |
dece6358 AM |
32395 | + shwh = 0; |
32396 | + if (au_opt_test(au_mntflags(sb), SHWH)) { | |
32397 | + shwh = 1; | |
32398 | + au_fset_fillvdir(arg->flags, SHWH); | |
32399 | + } | |
5afbbe0d AM |
32400 | + btop = au_fbtop(file); |
32401 | + bbot = au_fbbot_dir(file); | |
32402 | + for (bindex = btop; !err && bindex <= bbot; bindex++) { | |
4a4d8108 | 32403 | + hf = au_hf_dir(file, bindex); |
1facf9fc | 32404 | + if (!hf) |
32405 | + continue; | |
32406 | + | |
32407 | + offset = vfsub_llseek(hf, 0, SEEK_SET); | |
32408 | + err = offset; | |
32409 | + if (unlikely(offset)) | |
32410 | + break; | |
32411 | + | |
32412 | + arg->bindex = bindex; | |
32413 | + au_fclr_fillvdir(arg->flags, WHABLE); | |
dece6358 | 32414 | + if (shwh |
5afbbe0d | 32415 | + || (bindex != bbot |
dece6358 | 32416 | + && au_br_whable(au_sbr_perm(sb, bindex)))) |
1facf9fc | 32417 | + au_fset_fillvdir(arg->flags, WHABLE); |
32418 | + do { | |
32419 | + arg->err = 0; | |
32420 | + au_fclr_fillvdir(arg->flags, CALLED); | |
32421 | + /* smp_mb(); */ | |
392086de | 32422 | + err = vfsub_iterate_dir(hf, &arg->ctx); |
1facf9fc | 32423 | + if (err >= 0) |
32424 | + err = arg->err; | |
32425 | + } while (!err && au_ftest_fillvdir(arg->flags, CALLED)); | |
392086de AM |
32426 | + |
32427 | + /* | |
32428 | + * dir_relax() may be good for concurrency, but aufs should not | |
32429 | + * use it since it will cause a lockdep problem. | |
32430 | + */ | |
1facf9fc | 32431 | + } |
dece6358 AM |
32432 | + |
32433 | + if (!err && shwh) | |
32434 | + err = au_handle_shwh(sb, arg->vdir, &arg->whlist, &arg->delist); | |
32435 | + | |
32436 | + au_nhash_wh_free(&arg->whlist); | |
1facf9fc | 32437 | + |
4f0767ce | 32438 | +out_delist: |
dece6358 | 32439 | + au_nhash_de_free(&arg->delist); |
4f0767ce | 32440 | +out: |
1facf9fc | 32441 | + return err; |
32442 | +} | |
32443 | + | |
32444 | +static int read_vdir(struct file *file, int may_read) | |
32445 | +{ | |
32446 | + int err; | |
32447 | + unsigned long expire; | |
32448 | + unsigned char do_read; | |
392086de AM |
32449 | + struct fillvdir_arg arg = { |
32450 | + .ctx = { | |
2000de60 | 32451 | + .actor = fillvdir |
392086de AM |
32452 | + } |
32453 | + }; | |
1facf9fc | 32454 | + struct inode *inode; |
32455 | + struct au_vdir *vdir, *allocated; | |
32456 | + | |
32457 | + err = 0; | |
c06a8ce3 | 32458 | + inode = file_inode(file); |
1facf9fc | 32459 | + IMustLock(inode); |
5afbbe0d | 32460 | + IiMustWriteLock(inode); |
dece6358 AM |
32461 | + SiMustAnyLock(inode->i_sb); |
32462 | + | |
1facf9fc | 32463 | + allocated = NULL; |
32464 | + do_read = 0; | |
32465 | + expire = au_sbi(inode->i_sb)->si_rdcache; | |
32466 | + vdir = au_ivdir(inode); | |
32467 | + if (!vdir) { | |
32468 | + do_read = 1; | |
1308ab2a | 32469 | + vdir = alloc_vdir(file); |
1facf9fc | 32470 | + err = PTR_ERR(vdir); |
32471 | + if (IS_ERR(vdir)) | |
32472 | + goto out; | |
32473 | + err = 0; | |
32474 | + allocated = vdir; | |
32475 | + } else if (may_read | |
be118d29 | 32476 | + && (!inode_eq_iversion(inode, vdir->vd_version) |
1facf9fc | 32477 | + || time_after(jiffies, vdir->vd_jiffy + expire))) { |
32478 | + do_read = 1; | |
32479 | + err = reinit_vdir(vdir); | |
32480 | + if (unlikely(err)) | |
32481 | + goto out; | |
32482 | + } | |
32483 | + | |
32484 | + if (!do_read) | |
32485 | + return 0; /* success */ | |
32486 | + | |
32487 | + arg.file = file; | |
32488 | + arg.vdir = vdir; | |
32489 | + err = au_do_read_vdir(&arg); | |
32490 | + if (!err) { | |
392086de | 32491 | + /* file->f_pos = 0; */ /* todo: ctx->pos? */ |
be118d29 | 32492 | + vdir->vd_version = inode_query_iversion(inode); |
1facf9fc | 32493 | + vdir->vd_last.ul = 0; |
32494 | + vdir->vd_last.p.deblk = vdir->vd_deblk[0]; | |
32495 | + if (allocated) | |
32496 | + au_set_ivdir(inode, allocated); | |
32497 | + } else if (allocated) | |
1c60b727 | 32498 | + au_vdir_free(allocated); |
1facf9fc | 32499 | + |
4f0767ce | 32500 | +out: |
1facf9fc | 32501 | + return err; |
32502 | +} | |
32503 | + | |
32504 | +static int copy_vdir(struct au_vdir *tgt, struct au_vdir *src) | |
32505 | +{ | |
32506 | + int err, rerr; | |
32507 | + unsigned long ul, n; | |
32508 | + const unsigned int deblk_sz = src->vd_deblk_sz; | |
32509 | + | |
32510 | + AuDebugOn(tgt->vd_nblk != 1); | |
32511 | + | |
32512 | + err = -ENOMEM; | |
32513 | + if (tgt->vd_nblk < src->vd_nblk) { | |
32514 | + unsigned char **p; | |
32515 | + | |
e2f27e51 AM |
32516 | + p = au_krealloc(tgt->vd_deblk, sizeof(*p) * src->vd_nblk, |
32517 | + GFP_NOFS, /*may_shrink*/0); | |
1facf9fc | 32518 | + if (unlikely(!p)) |
32519 | + goto out; | |
32520 | + tgt->vd_deblk = p; | |
32521 | + } | |
32522 | + | |
1308ab2a | 32523 | + if (tgt->vd_deblk_sz != deblk_sz) { |
32524 | + unsigned char *p; | |
32525 | + | |
32526 | + tgt->vd_deblk_sz = deblk_sz; | |
e2f27e51 AM |
32527 | + p = au_krealloc(tgt->vd_deblk[0], deblk_sz, GFP_NOFS, |
32528 | + /*may_shrink*/1); | |
1308ab2a | 32529 | + if (unlikely(!p)) |
32530 | + goto out; | |
32531 | + tgt->vd_deblk[0] = p; | |
32532 | + } | |
1facf9fc | 32533 | + memcpy(tgt->vd_deblk[0], src->vd_deblk[0], deblk_sz); |
1facf9fc | 32534 | + tgt->vd_version = src->vd_version; |
32535 | + tgt->vd_jiffy = src->vd_jiffy; | |
32536 | + | |
32537 | + n = src->vd_nblk; | |
32538 | + for (ul = 1; ul < n; ul++) { | |
dece6358 AM |
32539 | + tgt->vd_deblk[ul] = kmemdup(src->vd_deblk[ul], deblk_sz, |
32540 | + GFP_NOFS); | |
32541 | + if (unlikely(!tgt->vd_deblk[ul])) | |
1facf9fc | 32542 | + goto out; |
1308ab2a | 32543 | + tgt->vd_nblk++; |
1facf9fc | 32544 | + } |
1308ab2a | 32545 | + tgt->vd_nblk = n; |
32546 | + tgt->vd_last.ul = tgt->vd_last.ul; | |
32547 | + tgt->vd_last.p.deblk = tgt->vd_deblk[tgt->vd_last.ul]; | |
32548 | + tgt->vd_last.p.deblk += src->vd_last.p.deblk | |
32549 | + - src->vd_deblk[src->vd_last.ul]; | |
1facf9fc | 32550 | + /* smp_mb(); */ |
32551 | + return 0; /* success */ | |
32552 | + | |
4f0767ce | 32553 | +out: |
1facf9fc | 32554 | + rerr = reinit_vdir(tgt); |
32555 | + BUG_ON(rerr); | |
32556 | + return err; | |
32557 | +} | |
32558 | + | |
32559 | +int au_vdir_init(struct file *file) | |
32560 | +{ | |
32561 | + int err; | |
32562 | + struct inode *inode; | |
32563 | + struct au_vdir *vdir_cache, *allocated; | |
32564 | + | |
392086de | 32565 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 32566 | + err = read_vdir(file, !file->f_pos); |
32567 | + if (unlikely(err)) | |
32568 | + goto out; | |
32569 | + | |
32570 | + allocated = NULL; | |
32571 | + vdir_cache = au_fvdir_cache(file); | |
32572 | + if (!vdir_cache) { | |
1308ab2a | 32573 | + vdir_cache = alloc_vdir(file); |
1facf9fc | 32574 | + err = PTR_ERR(vdir_cache); |
32575 | + if (IS_ERR(vdir_cache)) | |
32576 | + goto out; | |
32577 | + allocated = vdir_cache; | |
32578 | + } else if (!file->f_pos && vdir_cache->vd_version != file->f_version) { | |
392086de | 32579 | + /* test file->f_pos here instead of ctx->pos */ |
1facf9fc | 32580 | + err = reinit_vdir(vdir_cache); |
32581 | + if (unlikely(err)) | |
32582 | + goto out; | |
32583 | + } else | |
32584 | + return 0; /* success */ | |
32585 | + | |
c06a8ce3 | 32586 | + inode = file_inode(file); |
1facf9fc | 32587 | + err = copy_vdir(vdir_cache, au_ivdir(inode)); |
32588 | + if (!err) { | |
be118d29 | 32589 | + file->f_version = inode_query_iversion(inode); |
1facf9fc | 32590 | + if (allocated) |
32591 | + au_set_fvdir_cache(file, allocated); | |
32592 | + } else if (allocated) | |
1c60b727 | 32593 | + au_vdir_free(allocated); |
1facf9fc | 32594 | + |
4f0767ce | 32595 | +out: |
1facf9fc | 32596 | + return err; |
32597 | +} | |
32598 | + | |
32599 | +static loff_t calc_offset(struct au_vdir *vdir) | |
32600 | +{ | |
32601 | + loff_t offset; | |
32602 | + union au_vdir_deblk_p p; | |
32603 | + | |
32604 | + p.deblk = vdir->vd_deblk[vdir->vd_last.ul]; | |
32605 | + offset = vdir->vd_last.p.deblk - p.deblk; | |
32606 | + offset += vdir->vd_deblk_sz * vdir->vd_last.ul; | |
32607 | + return offset; | |
32608 | +} | |
32609 | + | |
32610 | +/* returns true or false */ | |
392086de | 32611 | +static int seek_vdir(struct file *file, struct dir_context *ctx) |
1facf9fc | 32612 | +{ |
32613 | + int valid; | |
32614 | + unsigned int deblk_sz; | |
32615 | + unsigned long ul, n; | |
32616 | + loff_t offset; | |
32617 | + union au_vdir_deblk_p p, deblk_end; | |
32618 | + struct au_vdir *vdir_cache; | |
32619 | + | |
32620 | + valid = 1; | |
32621 | + vdir_cache = au_fvdir_cache(file); | |
32622 | + offset = calc_offset(vdir_cache); | |
32623 | + AuDbg("offset %lld\n", offset); | |
392086de | 32624 | + if (ctx->pos == offset) |
1facf9fc | 32625 | + goto out; |
32626 | + | |
32627 | + vdir_cache->vd_last.ul = 0; | |
32628 | + vdir_cache->vd_last.p.deblk = vdir_cache->vd_deblk[0]; | |
392086de | 32629 | + if (!ctx->pos) |
1facf9fc | 32630 | + goto out; |
32631 | + | |
32632 | + valid = 0; | |
32633 | + deblk_sz = vdir_cache->vd_deblk_sz; | |
392086de | 32634 | + ul = div64_u64(ctx->pos, deblk_sz); |
1facf9fc | 32635 | + AuDbg("ul %lu\n", ul); |
32636 | + if (ul >= vdir_cache->vd_nblk) | |
32637 | + goto out; | |
32638 | + | |
32639 | + n = vdir_cache->vd_nblk; | |
32640 | + for (; ul < n; ul++) { | |
32641 | + p.deblk = vdir_cache->vd_deblk[ul]; | |
32642 | + deblk_end.deblk = p.deblk + deblk_sz; | |
32643 | + offset = ul; | |
32644 | + offset *= deblk_sz; | |
392086de | 32645 | + while (!is_deblk_end(&p, &deblk_end) && offset < ctx->pos) { |
1facf9fc | 32646 | + unsigned int l; |
32647 | + | |
32648 | + l = calc_size(p.de->de_str.len); | |
32649 | + offset += l; | |
32650 | + p.deblk += l; | |
32651 | + } | |
32652 | + if (!is_deblk_end(&p, &deblk_end)) { | |
32653 | + valid = 1; | |
32654 | + vdir_cache->vd_last.ul = ul; | |
32655 | + vdir_cache->vd_last.p = p; | |
32656 | + break; | |
32657 | + } | |
32658 | + } | |
32659 | + | |
4f0767ce | 32660 | +out: |
1facf9fc | 32661 | + /* smp_mb(); */ |
b00004a5 AM |
32662 | + if (!valid) |
32663 | + AuDbg("valid %d\n", !valid); | |
1facf9fc | 32664 | + return valid; |
32665 | +} | |
32666 | + | |
392086de | 32667 | +int au_vdir_fill_de(struct file *file, struct dir_context *ctx) |
1facf9fc | 32668 | +{ |
1facf9fc | 32669 | + unsigned int l, deblk_sz; |
32670 | + union au_vdir_deblk_p deblk_end; | |
32671 | + struct au_vdir *vdir_cache; | |
32672 | + struct au_vdir_de *de; | |
32673 | + | |
392086de | 32674 | + if (!seek_vdir(file, ctx)) |
1facf9fc | 32675 | + return 0; |
32676 | + | |
acd2b654 | 32677 | + vdir_cache = au_fvdir_cache(file); |
1facf9fc | 32678 | + deblk_sz = vdir_cache->vd_deblk_sz; |
32679 | + while (1) { | |
32680 | + deblk_end.deblk = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
32681 | + deblk_end.deblk += deblk_sz; | |
32682 | + while (!is_deblk_end(&vdir_cache->vd_last.p, &deblk_end)) { | |
32683 | + de = vdir_cache->vd_last.p.de; | |
32684 | + AuDbg("%.*s, off%lld, i%lu, dt%d\n", | |
392086de | 32685 | + de->de_str.len, de->de_str.name, ctx->pos, |
1facf9fc | 32686 | + (unsigned long)de->de_ino, de->de_type); |
392086de AM |
32687 | + if (unlikely(!dir_emit(ctx, de->de_str.name, |
32688 | + de->de_str.len, de->de_ino, | |
32689 | + de->de_type))) { | |
1facf9fc | 32690 | + /* todo: ignore the error caused by udba? */ |
32691 | + /* return err; */ | |
32692 | + return 0; | |
32693 | + } | |
32694 | + | |
32695 | + l = calc_size(de->de_str.len); | |
32696 | + vdir_cache->vd_last.p.deblk += l; | |
392086de | 32697 | + ctx->pos += l; |
1facf9fc | 32698 | + } |
32699 | + if (vdir_cache->vd_last.ul < vdir_cache->vd_nblk - 1) { | |
32700 | + vdir_cache->vd_last.ul++; | |
32701 | + vdir_cache->vd_last.p.deblk | |
32702 | + = vdir_cache->vd_deblk[vdir_cache->vd_last.ul]; | |
392086de | 32703 | + ctx->pos = deblk_sz * vdir_cache->vd_last.ul; |
1facf9fc | 32704 | + continue; |
32705 | + } | |
32706 | + break; | |
32707 | + } | |
32708 | + | |
32709 | + /* smp_mb(); */ | |
32710 | + return 0; | |
32711 | +} | |
7f207e10 | 32712 | diff -urN /usr/share/empty/fs/aufs/vfsub.c linux/fs/aufs/vfsub.c |
eca34b5c | 32713 | --- /usr/share/empty/fs/aufs/vfsub.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 32714 | +++ linux/fs/aufs/vfsub.c 2020-01-27 10:57:18.178871751 +0100 |
acd2b654 | 32715 | @@ -0,0 +1,902 @@ |
cd7a4cd9 | 32716 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 32717 | +/* |
d58c55f2 | 32718 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 32719 | + * |
32720 | + * This program, aufs is free software; you can redistribute it and/or modify | |
32721 | + * it under the terms of the GNU General Public License as published by | |
32722 | + * the Free Software Foundation; either version 2 of the License, or | |
32723 | + * (at your option) any later version. | |
dece6358 AM |
32724 | + * |
32725 | + * This program is distributed in the hope that it will be useful, | |
32726 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
32727 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32728 | + * GNU General Public License for more details. | |
32729 | + * | |
32730 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 32731 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 32732 | + */ |
32733 | + | |
32734 | +/* | |
32735 | + * sub-routines for VFS | |
32736 | + */ | |
32737 | + | |
8b6a4947 | 32738 | +#include <linux/mnt_namespace.h> |
dece6358 | 32739 | +#include <linux/namei.h> |
8cdd5066 | 32740 | +#include <linux/nsproxy.h> |
dece6358 AM |
32741 | +#include <linux/security.h> |
32742 | +#include <linux/splice.h> | |
1facf9fc | 32743 | +#include "aufs.h" |
32744 | + | |
8cdd5066 JR |
32745 | +#ifdef CONFIG_AUFS_BR_FUSE |
32746 | +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb) | |
32747 | +{ | |
8cdd5066 JR |
32748 | + if (!au_test_fuse(h_sb) || !au_userns) |
32749 | + return 0; | |
32750 | + | |
8b6a4947 | 32751 | + return is_current_mnt_ns(mnt) ? 0 : -EACCES; |
8cdd5066 JR |
32752 | +} |
32753 | +#endif | |
32754 | + | |
a2654f78 AM |
32755 | +int vfsub_sync_filesystem(struct super_block *h_sb, int wait) |
32756 | +{ | |
32757 | + int err; | |
32758 | + | |
32759 | + lockdep_off(); | |
32760 | + down_read(&h_sb->s_umount); | |
32761 | + err = __sync_filesystem(h_sb, wait); | |
32762 | + up_read(&h_sb->s_umount); | |
32763 | + lockdep_on(); | |
32764 | + | |
32765 | + return err; | |
32766 | +} | |
32767 | + | |
8cdd5066 JR |
32768 | +/* ---------------------------------------------------------------------- */ |
32769 | + | |
1facf9fc | 32770 | +int vfsub_update_h_iattr(struct path *h_path, int *did) |
32771 | +{ | |
32772 | + int err; | |
32773 | + struct kstat st; | |
32774 | + struct super_block *h_sb; | |
32775 | + | |
32776 | + /* for remote fs, leave work for its getattr or d_revalidate */ | |
32777 | + /* for bad i_attr fs, handle them in aufs_getattr() */ | |
32778 | + /* still some fs may acquire i_mutex. we need to skip them */ | |
32779 | + err = 0; | |
32780 | + if (!did) | |
32781 | + did = &err; | |
32782 | + h_sb = h_path->dentry->d_sb; | |
32783 | + *did = (!au_test_fs_remote(h_sb) && au_test_fs_refresh_iattr(h_sb)); | |
32784 | + if (*did) | |
521ced18 | 32785 | + err = vfsub_getattr(h_path, &st); |
1facf9fc | 32786 | + |
32787 | + return err; | |
32788 | +} | |
32789 | + | |
32790 | +/* ---------------------------------------------------------------------- */ | |
32791 | + | |
4a4d8108 | 32792 | +struct file *vfsub_dentry_open(struct path *path, int flags) |
1308ab2a | 32793 | +{ |
32794 | + struct file *file; | |
32795 | + | |
b4510431 | 32796 | + file = dentry_open(path, flags /* | __FMODE_NONOTIFY */, |
7f207e10 | 32797 | + current_cred()); |
2cbb1c4b JR |
32798 | + if (!IS_ERR_OR_NULL(file) |
32799 | + && (file->f_mode & (FMODE_READ | FMODE_WRITE)) == FMODE_READ) | |
5527c038 | 32800 | + i_readcount_inc(d_inode(path->dentry)); |
4a4d8108 | 32801 | + |
1308ab2a | 32802 | + return file; |
32803 | +} | |
32804 | + | |
1facf9fc | 32805 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode) |
32806 | +{ | |
32807 | + struct file *file; | |
32808 | + | |
2cbb1c4b | 32809 | + lockdep_off(); |
7f207e10 | 32810 | + file = filp_open(path, |
2cbb1c4b | 32811 | + oflags /* | __FMODE_NONOTIFY */, |
7f207e10 | 32812 | + mode); |
2cbb1c4b | 32813 | + lockdep_on(); |
1facf9fc | 32814 | + if (IS_ERR(file)) |
32815 | + goto out; | |
32816 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
32817 | + | |
4f0767ce | 32818 | +out: |
1facf9fc | 32819 | + return file; |
32820 | +} | |
32821 | + | |
b912730e AM |
32822 | +/* |
32823 | + * Ideally this function should call VFS:do_last() in order to keep all its | |
32824 | + * checkings. But it is very hard for aufs to regenerate several VFS internal | |
32825 | + * structure such as nameidata. This is a second (or third) best approach. | |
32826 | + * cf. linux/fs/namei.c:do_last(), lookup_open() and atomic_open(). | |
32827 | + */ | |
32828 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, | |
acd2b654 | 32829 | + struct vfsub_aopen_args *args) |
b912730e AM |
32830 | +{ |
32831 | + int err; | |
acd2b654 | 32832 | + struct au_branch *br = args->br; |
b912730e AM |
32833 | + struct file *file = args->file; |
32834 | + /* copied from linux/fs/namei.c:atomic_open() */ | |
32835 | + struct dentry *const DENTRY_NOT_SET = (void *)-1UL; | |
32836 | + | |
32837 | + IMustLock(dir); | |
32838 | + AuDebugOn(!dir->i_op->atomic_open); | |
32839 | + | |
32840 | + err = au_br_test_oflag(args->open_flag, br); | |
32841 | + if (unlikely(err)) | |
32842 | + goto out; | |
32843 | + | |
acd2b654 AM |
32844 | + au_lcnt_inc(&br->br_nfiles); |
32845 | + file->f_path.dentry = DENTRY_NOT_SET; | |
32846 | + file->f_path.mnt = au_br_mnt(br); | |
32847 | + AuDbg("%ps\n", dir->i_op->atomic_open); | |
b912730e | 32848 | + err = dir->i_op->atomic_open(dir, dentry, file, args->open_flag, |
acd2b654 AM |
32849 | + args->create_mode); |
32850 | + if (unlikely(err < 0)) { | |
32851 | + au_lcnt_dec(&br->br_nfiles); | |
b912730e | 32852 | + goto out; |
acd2b654 | 32853 | + } |
b912730e | 32854 | + |
acd2b654 AM |
32855 | + /* temporary workaround for nfsv4 branch */ |
32856 | + if (au_test_nfs(dir->i_sb)) | |
32857 | + nfs_mark_for_revalidate(dir); | |
b912730e | 32858 | + |
acd2b654 AM |
32859 | + if (file->f_mode & FMODE_CREATED) |
32860 | + fsnotify_create(dir, dentry); | |
32861 | + if (!(file->f_mode & FMODE_OPENED)) { | |
32862 | + au_lcnt_dec(&br->br_nfiles); | |
32863 | + goto out; | |
b912730e AM |
32864 | + } |
32865 | + | |
acd2b654 AM |
32866 | + /* todo: call VFS:may_open() here */ |
32867 | + /* todo: ima_file_check() too? */ | |
32868 | + if (!err && (args->open_flag & __FMODE_EXEC)) | |
32869 | + err = deny_write_access(file); | |
32870 | + if (!err) | |
32871 | + fsnotify_open(file); | |
32872 | + else | |
32873 | + au_lcnt_dec(&br->br_nfiles); | |
32874 | + /* note that the file is created and still opened */ | |
b912730e AM |
32875 | + |
32876 | +out: | |
32877 | + return err; | |
32878 | +} | |
32879 | + | |
1facf9fc | 32880 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path) |
32881 | +{ | |
32882 | + int err; | |
32883 | + | |
1facf9fc | 32884 | + err = kern_path(name, flags, path); |
5527c038 | 32885 | + if (!err && d_is_positive(path->dentry)) |
1facf9fc | 32886 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ |
32887 | + return err; | |
32888 | +} | |
32889 | + | |
febd17d6 JR |
32890 | +struct dentry *vfsub_lookup_one_len_unlocked(const char *name, |
32891 | + struct dentry *parent, int len) | |
32892 | +{ | |
32893 | + struct path path = { | |
32894 | + .mnt = NULL | |
32895 | + }; | |
32896 | + | |
32897 | + path.dentry = lookup_one_len_unlocked(name, parent, len); | |
32898 | + if (IS_ERR(path.dentry)) | |
32899 | + goto out; | |
32900 | + if (d_is_positive(path.dentry)) | |
32901 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ | |
32902 | + | |
32903 | +out: | |
32904 | + AuTraceErrPtr(path.dentry); | |
32905 | + return path.dentry; | |
32906 | +} | |
32907 | + | |
1facf9fc | 32908 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
32909 | + int len) | |
32910 | +{ | |
32911 | + struct path path = { | |
32912 | + .mnt = NULL | |
32913 | + }; | |
32914 | + | |
1308ab2a | 32915 | + /* VFS checks it too, but by WARN_ON_ONCE() */ |
5527c038 | 32916 | + IMustLock(d_inode(parent)); |
1facf9fc | 32917 | + |
32918 | + path.dentry = lookup_one_len(name, parent, len); | |
32919 | + if (IS_ERR(path.dentry)) | |
32920 | + goto out; | |
5527c038 | 32921 | + if (d_is_positive(path.dentry)) |
1facf9fc | 32922 | + vfsub_update_h_iattr(&path, /*did*/NULL); /*ignore*/ |
32923 | + | |
4f0767ce | 32924 | +out: |
4a4d8108 | 32925 | + AuTraceErrPtr(path.dentry); |
1facf9fc | 32926 | + return path.dentry; |
32927 | +} | |
32928 | + | |
b4510431 | 32929 | +void vfsub_call_lkup_one(void *args) |
2cbb1c4b | 32930 | +{ |
b4510431 AM |
32931 | + struct vfsub_lkup_one_args *a = args; |
32932 | + *a->errp = vfsub_lkup_one(a->name, a->parent); | |
2cbb1c4b JR |
32933 | +} |
32934 | + | |
1facf9fc | 32935 | +/* ---------------------------------------------------------------------- */ |
32936 | + | |
32937 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
32938 | + struct dentry *d2, struct au_hinode *hdir2) | |
32939 | +{ | |
32940 | + struct dentry *d; | |
32941 | + | |
2cbb1c4b | 32942 | + lockdep_off(); |
1facf9fc | 32943 | + d = lock_rename(d1, d2); |
2cbb1c4b | 32944 | + lockdep_on(); |
4a4d8108 | 32945 | + au_hn_suspend(hdir1); |
1facf9fc | 32946 | + if (hdir1 != hdir2) |
4a4d8108 | 32947 | + au_hn_suspend(hdir2); |
1facf9fc | 32948 | + |
32949 | + return d; | |
32950 | +} | |
32951 | + | |
32952 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
32953 | + struct dentry *d2, struct au_hinode *hdir2) | |
32954 | +{ | |
4a4d8108 | 32955 | + au_hn_resume(hdir1); |
1facf9fc | 32956 | + if (hdir1 != hdir2) |
4a4d8108 | 32957 | + au_hn_resume(hdir2); |
2cbb1c4b | 32958 | + lockdep_off(); |
1facf9fc | 32959 | + unlock_rename(d1, d2); |
2cbb1c4b | 32960 | + lockdep_on(); |
1facf9fc | 32961 | +} |
32962 | + | |
32963 | +/* ---------------------------------------------------------------------- */ | |
32964 | + | |
b4510431 | 32965 | +int vfsub_create(struct inode *dir, struct path *path, int mode, bool want_excl) |
1facf9fc | 32966 | +{ |
32967 | + int err; | |
32968 | + struct dentry *d; | |
32969 | + | |
32970 | + IMustLock(dir); | |
32971 | + | |
32972 | + d = path->dentry; | |
32973 | + path->dentry = d->d_parent; | |
b752ccd1 | 32974 | + err = security_path_mknod(path, d, mode, 0); |
1facf9fc | 32975 | + path->dentry = d; |
32976 | + if (unlikely(err)) | |
32977 | + goto out; | |
32978 | + | |
c1595e42 | 32979 | + lockdep_off(); |
b4510431 | 32980 | + err = vfs_create(dir, path->dentry, mode, want_excl); |
c1595e42 | 32981 | + lockdep_on(); |
1facf9fc | 32982 | + if (!err) { |
32983 | + struct path tmp = *path; | |
32984 | + int did; | |
32985 | + | |
32986 | + vfsub_update_h_iattr(&tmp, &did); | |
32987 | + if (did) { | |
32988 | + tmp.dentry = path->dentry->d_parent; | |
32989 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
32990 | + } | |
32991 | + /*ignore*/ | |
32992 | + } | |
32993 | + | |
4f0767ce | 32994 | +out: |
1facf9fc | 32995 | + return err; |
32996 | +} | |
32997 | + | |
32998 | +int vfsub_symlink(struct inode *dir, struct path *path, const char *symname) | |
32999 | +{ | |
33000 | + int err; | |
33001 | + struct dentry *d; | |
33002 | + | |
33003 | + IMustLock(dir); | |
33004 | + | |
33005 | + d = path->dentry; | |
33006 | + path->dentry = d->d_parent; | |
b752ccd1 | 33007 | + err = security_path_symlink(path, d, symname); |
1facf9fc | 33008 | + path->dentry = d; |
33009 | + if (unlikely(err)) | |
33010 | + goto out; | |
33011 | + | |
c1595e42 | 33012 | + lockdep_off(); |
1facf9fc | 33013 | + err = vfs_symlink(dir, path->dentry, symname); |
c1595e42 | 33014 | + lockdep_on(); |
1facf9fc | 33015 | + if (!err) { |
33016 | + struct path tmp = *path; | |
33017 | + int did; | |
33018 | + | |
33019 | + vfsub_update_h_iattr(&tmp, &did); | |
33020 | + if (did) { | |
33021 | + tmp.dentry = path->dentry->d_parent; | |
33022 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33023 | + } | |
33024 | + /*ignore*/ | |
33025 | + } | |
33026 | + | |
4f0767ce | 33027 | +out: |
1facf9fc | 33028 | + return err; |
33029 | +} | |
33030 | + | |
33031 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev) | |
33032 | +{ | |
33033 | + int err; | |
33034 | + struct dentry *d; | |
33035 | + | |
33036 | + IMustLock(dir); | |
33037 | + | |
33038 | + d = path->dentry; | |
33039 | + path->dentry = d->d_parent; | |
027c5e7a | 33040 | + err = security_path_mknod(path, d, mode, new_encode_dev(dev)); |
1facf9fc | 33041 | + path->dentry = d; |
33042 | + if (unlikely(err)) | |
33043 | + goto out; | |
33044 | + | |
c1595e42 | 33045 | + lockdep_off(); |
1facf9fc | 33046 | + err = vfs_mknod(dir, path->dentry, mode, dev); |
c1595e42 | 33047 | + lockdep_on(); |
1facf9fc | 33048 | + if (!err) { |
33049 | + struct path tmp = *path; | |
33050 | + int did; | |
33051 | + | |
33052 | + vfsub_update_h_iattr(&tmp, &did); | |
33053 | + if (did) { | |
33054 | + tmp.dentry = path->dentry->d_parent; | |
33055 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33056 | + } | |
33057 | + /*ignore*/ | |
33058 | + } | |
33059 | + | |
4f0767ce | 33060 | +out: |
1facf9fc | 33061 | + return err; |
33062 | +} | |
33063 | + | |
33064 | +static int au_test_nlink(struct inode *inode) | |
33065 | +{ | |
33066 | + const unsigned int link_max = UINT_MAX >> 1; /* rough margin */ | |
33067 | + | |
33068 | + if (!au_test_fs_no_limit_nlink(inode->i_sb) | |
33069 | + || inode->i_nlink < link_max) | |
33070 | + return 0; | |
33071 | + return -EMLINK; | |
33072 | +} | |
33073 | + | |
523b37e3 AM |
33074 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, struct path *path, |
33075 | + struct inode **delegated_inode) | |
1facf9fc | 33076 | +{ |
33077 | + int err; | |
33078 | + struct dentry *d; | |
33079 | + | |
33080 | + IMustLock(dir); | |
33081 | + | |
5527c038 | 33082 | + err = au_test_nlink(d_inode(src_dentry)); |
1facf9fc | 33083 | + if (unlikely(err)) |
33084 | + return err; | |
33085 | + | |
b4510431 | 33086 | + /* we don't call may_linkat() */ |
1facf9fc | 33087 | + d = path->dentry; |
33088 | + path->dentry = d->d_parent; | |
b752ccd1 | 33089 | + err = security_path_link(src_dentry, path, d); |
1facf9fc | 33090 | + path->dentry = d; |
33091 | + if (unlikely(err)) | |
33092 | + goto out; | |
33093 | + | |
2cbb1c4b | 33094 | + lockdep_off(); |
523b37e3 | 33095 | + err = vfs_link(src_dentry, dir, path->dentry, delegated_inode); |
2cbb1c4b | 33096 | + lockdep_on(); |
1facf9fc | 33097 | + if (!err) { |
33098 | + struct path tmp = *path; | |
33099 | + int did; | |
33100 | + | |
33101 | + /* fuse has different memory inode for the same inumber */ | |
33102 | + vfsub_update_h_iattr(&tmp, &did); | |
33103 | + if (did) { | |
33104 | + tmp.dentry = path->dentry->d_parent; | |
33105 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33106 | + tmp.dentry = src_dentry; | |
33107 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33108 | + } | |
33109 | + /*ignore*/ | |
33110 | + } | |
33111 | + | |
4f0767ce | 33112 | +out: |
1facf9fc | 33113 | + return err; |
33114 | +} | |
33115 | + | |
33116 | +int vfsub_rename(struct inode *src_dir, struct dentry *src_dentry, | |
523b37e3 | 33117 | + struct inode *dir, struct path *path, |
f2c43d5f | 33118 | + struct inode **delegated_inode, unsigned int flags) |
1facf9fc | 33119 | +{ |
33120 | + int err; | |
33121 | + struct path tmp = { | |
33122 | + .mnt = path->mnt | |
33123 | + }; | |
33124 | + struct dentry *d; | |
33125 | + | |
33126 | + IMustLock(dir); | |
33127 | + IMustLock(src_dir); | |
33128 | + | |
33129 | + d = path->dentry; | |
33130 | + path->dentry = d->d_parent; | |
33131 | + tmp.dentry = src_dentry->d_parent; | |
38d290e6 | 33132 | + err = security_path_rename(&tmp, src_dentry, path, d, /*flags*/0); |
1facf9fc | 33133 | + path->dentry = d; |
33134 | + if (unlikely(err)) | |
33135 | + goto out; | |
33136 | + | |
2cbb1c4b | 33137 | + lockdep_off(); |
523b37e3 | 33138 | + err = vfs_rename(src_dir, src_dentry, dir, path->dentry, |
f2c43d5f | 33139 | + delegated_inode, flags); |
2cbb1c4b | 33140 | + lockdep_on(); |
1facf9fc | 33141 | + if (!err) { |
33142 | + int did; | |
33143 | + | |
33144 | + tmp.dentry = d->d_parent; | |
33145 | + vfsub_update_h_iattr(&tmp, &did); | |
33146 | + if (did) { | |
33147 | + tmp.dentry = src_dentry; | |
33148 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33149 | + tmp.dentry = src_dentry->d_parent; | |
33150 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33151 | + } | |
33152 | + /*ignore*/ | |
33153 | + } | |
33154 | + | |
4f0767ce | 33155 | +out: |
1facf9fc | 33156 | + return err; |
33157 | +} | |
33158 | + | |
33159 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode) | |
33160 | +{ | |
33161 | + int err; | |
33162 | + struct dentry *d; | |
33163 | + | |
33164 | + IMustLock(dir); | |
33165 | + | |
33166 | + d = path->dentry; | |
33167 | + path->dentry = d->d_parent; | |
b752ccd1 | 33168 | + err = security_path_mkdir(path, d, mode); |
1facf9fc | 33169 | + path->dentry = d; |
33170 | + if (unlikely(err)) | |
33171 | + goto out; | |
33172 | + | |
c1595e42 | 33173 | + lockdep_off(); |
1facf9fc | 33174 | + err = vfs_mkdir(dir, path->dentry, mode); |
c1595e42 | 33175 | + lockdep_on(); |
1facf9fc | 33176 | + if (!err) { |
33177 | + struct path tmp = *path; | |
33178 | + int did; | |
33179 | + | |
33180 | + vfsub_update_h_iattr(&tmp, &did); | |
33181 | + if (did) { | |
33182 | + tmp.dentry = path->dentry->d_parent; | |
33183 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); | |
33184 | + } | |
33185 | + /*ignore*/ | |
33186 | + } | |
33187 | + | |
4f0767ce | 33188 | +out: |
1facf9fc | 33189 | + return err; |
33190 | +} | |
33191 | + | |
33192 | +int vfsub_rmdir(struct inode *dir, struct path *path) | |
33193 | +{ | |
33194 | + int err; | |
33195 | + struct dentry *d; | |
33196 | + | |
33197 | + IMustLock(dir); | |
33198 | + | |
33199 | + d = path->dentry; | |
33200 | + path->dentry = d->d_parent; | |
b752ccd1 | 33201 | + err = security_path_rmdir(path, d); |
1facf9fc | 33202 | + path->dentry = d; |
33203 | + if (unlikely(err)) | |
33204 | + goto out; | |
33205 | + | |
2cbb1c4b | 33206 | + lockdep_off(); |
1facf9fc | 33207 | + err = vfs_rmdir(dir, path->dentry); |
2cbb1c4b | 33208 | + lockdep_on(); |
1facf9fc | 33209 | + if (!err) { |
33210 | + struct path tmp = { | |
33211 | + .dentry = path->dentry->d_parent, | |
33212 | + .mnt = path->mnt | |
33213 | + }; | |
33214 | + | |
33215 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
33216 | + } | |
33217 | + | |
4f0767ce | 33218 | +out: |
1facf9fc | 33219 | + return err; |
33220 | +} | |
33221 | + | |
33222 | +/* ---------------------------------------------------------------------- */ | |
33223 | + | |
9dbd164d | 33224 | +/* todo: support mmap_sem? */ |
1facf9fc | 33225 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, |
33226 | + loff_t *ppos) | |
33227 | +{ | |
33228 | + ssize_t err; | |
33229 | + | |
2cbb1c4b | 33230 | + lockdep_off(); |
1facf9fc | 33231 | + err = vfs_read(file, ubuf, count, ppos); |
2cbb1c4b | 33232 | + lockdep_on(); |
1facf9fc | 33233 | + if (err >= 0) |
33234 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
33235 | + return err; | |
33236 | +} | |
33237 | + | |
33238 | +/* todo: kernel_read()? */ | |
33239 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
33240 | + loff_t *ppos) | |
33241 | +{ | |
33242 | + ssize_t err; | |
33243 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33244 | + union { |
33245 | + void *k; | |
33246 | + char __user *u; | |
33247 | + } buf; | |
1facf9fc | 33248 | + |
b752ccd1 | 33249 | + buf.k = kbuf; |
1facf9fc | 33250 | + oldfs = get_fs(); |
33251 | + set_fs(KERNEL_DS); | |
b752ccd1 | 33252 | + err = vfsub_read_u(file, buf.u, count, ppos); |
1facf9fc | 33253 | + set_fs(oldfs); |
33254 | + return err; | |
33255 | +} | |
33256 | + | |
33257 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
33258 | + loff_t *ppos) | |
33259 | +{ | |
33260 | + ssize_t err; | |
33261 | + | |
2cbb1c4b | 33262 | + lockdep_off(); |
1facf9fc | 33263 | + err = vfs_write(file, ubuf, count, ppos); |
2cbb1c4b | 33264 | + lockdep_on(); |
1facf9fc | 33265 | + if (err >= 0) |
33266 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
33267 | + return err; | |
33268 | +} | |
33269 | + | |
33270 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, loff_t *ppos) | |
33271 | +{ | |
33272 | + ssize_t err; | |
33273 | + mm_segment_t oldfs; | |
b752ccd1 AM |
33274 | + union { |
33275 | + void *k; | |
33276 | + const char __user *u; | |
33277 | + } buf; | |
1facf9fc | 33278 | + |
b752ccd1 | 33279 | + buf.k = kbuf; |
1facf9fc | 33280 | + oldfs = get_fs(); |
33281 | + set_fs(KERNEL_DS); | |
b752ccd1 | 33282 | + err = vfsub_write_u(file, buf.u, count, ppos); |
1facf9fc | 33283 | + set_fs(oldfs); |
33284 | + return err; | |
33285 | +} | |
33286 | + | |
4a4d8108 AM |
33287 | +int vfsub_flush(struct file *file, fl_owner_t id) |
33288 | +{ | |
33289 | + int err; | |
33290 | + | |
33291 | + err = 0; | |
523b37e3 | 33292 | + if (file->f_op->flush) { |
2000de60 | 33293 | + if (!au_test_nfs(file->f_path.dentry->d_sb)) |
2cbb1c4b JR |
33294 | + err = file->f_op->flush(file, id); |
33295 | + else { | |
33296 | + lockdep_off(); | |
33297 | + err = file->f_op->flush(file, id); | |
33298 | + lockdep_on(); | |
33299 | + } | |
4a4d8108 AM |
33300 | + if (!err) |
33301 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); | |
33302 | + /*ignore*/ | |
33303 | + } | |
33304 | + return err; | |
33305 | +} | |
33306 | + | |
392086de | 33307 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx) |
1facf9fc | 33308 | +{ |
33309 | + int err; | |
33310 | + | |
062440b3 | 33311 | + AuDbg("%pD, ctx{%ps, %llu}\n", file, ctx->actor, ctx->pos); |
392086de | 33312 | + |
2cbb1c4b | 33313 | + lockdep_off(); |
392086de | 33314 | + err = iterate_dir(file, ctx); |
2cbb1c4b | 33315 | + lockdep_on(); |
1facf9fc | 33316 | + if (err >= 0) |
33317 | + vfsub_update_h_iattr(&file->f_path, /*did*/NULL); /*ignore*/ | |
1c60b727 | 33318 | + |
1facf9fc | 33319 | + return err; |
33320 | +} | |
33321 | + | |
33322 | +long vfsub_splice_to(struct file *in, loff_t *ppos, | |
33323 | + struct pipe_inode_info *pipe, size_t len, | |
33324 | + unsigned int flags) | |
33325 | +{ | |
33326 | + long err; | |
33327 | + | |
2cbb1c4b | 33328 | + lockdep_off(); |
0fc653ad | 33329 | + err = do_splice_to(in, ppos, pipe, len, flags); |
2cbb1c4b | 33330 | + lockdep_on(); |
4a4d8108 | 33331 | + file_accessed(in); |
1facf9fc | 33332 | + if (err >= 0) |
33333 | + vfsub_update_h_iattr(&in->f_path, /*did*/NULL); /*ignore*/ | |
33334 | + return err; | |
33335 | +} | |
33336 | + | |
33337 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
33338 | + loff_t *ppos, size_t len, unsigned int flags) | |
33339 | +{ | |
33340 | + long err; | |
33341 | + | |
2cbb1c4b | 33342 | + lockdep_off(); |
0fc653ad | 33343 | + err = do_splice_from(pipe, out, ppos, len, flags); |
2cbb1c4b | 33344 | + lockdep_on(); |
1facf9fc | 33345 | + if (err >= 0) |
33346 | + vfsub_update_h_iattr(&out->f_path, /*did*/NULL); /*ignore*/ | |
33347 | + return err; | |
33348 | +} | |
33349 | + | |
53392da6 AM |
33350 | +int vfsub_fsync(struct file *file, struct path *path, int datasync) |
33351 | +{ | |
33352 | + int err; | |
33353 | + | |
33354 | + /* file can be NULL */ | |
33355 | + lockdep_off(); | |
33356 | + err = vfs_fsync(file, datasync); | |
33357 | + lockdep_on(); | |
33358 | + if (!err) { | |
33359 | + if (!path) { | |
33360 | + AuDebugOn(!file); | |
33361 | + path = &file->f_path; | |
33362 | + } | |
33363 | + vfsub_update_h_iattr(path, /*did*/NULL); /*ignore*/ | |
33364 | + } | |
33365 | + return err; | |
33366 | +} | |
33367 | + | |
1facf9fc | 33368 | +/* cf. open.c:do_sys_truncate() and do_sys_ftruncate() */ |
33369 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, | |
33370 | + struct file *h_file) | |
33371 | +{ | |
33372 | + int err; | |
33373 | + struct inode *h_inode; | |
c06a8ce3 | 33374 | + struct super_block *h_sb; |
1facf9fc | 33375 | + |
1facf9fc | 33376 | + if (!h_file) { |
c06a8ce3 AM |
33377 | + err = vfsub_truncate(h_path, length); |
33378 | + goto out; | |
1facf9fc | 33379 | + } |
33380 | + | |
5527c038 | 33381 | + h_inode = d_inode(h_path->dentry); |
c06a8ce3 AM |
33382 | + h_sb = h_inode->i_sb; |
33383 | + lockdep_off(); | |
33384 | + sb_start_write(h_sb); | |
33385 | + lockdep_on(); | |
1facf9fc | 33386 | + err = locks_verify_truncate(h_inode, h_file, length); |
33387 | + if (!err) | |
953406b4 | 33388 | + err = security_path_truncate(h_path); |
2cbb1c4b JR |
33389 | + if (!err) { |
33390 | + lockdep_off(); | |
1facf9fc | 33391 | + err = do_truncate(h_path->dentry, length, attr, h_file); |
2cbb1c4b JR |
33392 | + lockdep_on(); |
33393 | + } | |
c06a8ce3 AM |
33394 | + lockdep_off(); |
33395 | + sb_end_write(h_sb); | |
33396 | + lockdep_on(); | |
1facf9fc | 33397 | + |
4f0767ce | 33398 | +out: |
1facf9fc | 33399 | + return err; |
33400 | +} | |
33401 | + | |
33402 | +/* ---------------------------------------------------------------------- */ | |
33403 | + | |
33404 | +struct au_vfsub_mkdir_args { | |
33405 | + int *errp; | |
33406 | + struct inode *dir; | |
33407 | + struct path *path; | |
33408 | + int mode; | |
33409 | +}; | |
33410 | + | |
33411 | +static void au_call_vfsub_mkdir(void *args) | |
33412 | +{ | |
33413 | + struct au_vfsub_mkdir_args *a = args; | |
33414 | + *a->errp = vfsub_mkdir(a->dir, a->path, a->mode); | |
33415 | +} | |
33416 | + | |
33417 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode) | |
33418 | +{ | |
33419 | + int err, do_sio, wkq_err; | |
33420 | + | |
33421 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
33422 | + if (!do_sio) { |
33423 | + lockdep_off(); | |
1facf9fc | 33424 | + err = vfsub_mkdir(dir, path, mode); |
c1595e42 JR |
33425 | + lockdep_on(); |
33426 | + } else { | |
1facf9fc | 33427 | + struct au_vfsub_mkdir_args args = { |
33428 | + .errp = &err, | |
33429 | + .dir = dir, | |
33430 | + .path = path, | |
33431 | + .mode = mode | |
33432 | + }; | |
33433 | + wkq_err = au_wkq_wait(au_call_vfsub_mkdir, &args); | |
33434 | + if (unlikely(wkq_err)) | |
33435 | + err = wkq_err; | |
33436 | + } | |
33437 | + | |
33438 | + return err; | |
33439 | +} | |
33440 | + | |
33441 | +struct au_vfsub_rmdir_args { | |
33442 | + int *errp; | |
33443 | + struct inode *dir; | |
33444 | + struct path *path; | |
33445 | +}; | |
33446 | + | |
33447 | +static void au_call_vfsub_rmdir(void *args) | |
33448 | +{ | |
33449 | + struct au_vfsub_rmdir_args *a = args; | |
33450 | + *a->errp = vfsub_rmdir(a->dir, a->path); | |
33451 | +} | |
33452 | + | |
33453 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path) | |
33454 | +{ | |
33455 | + int err, do_sio, wkq_err; | |
33456 | + | |
33457 | + do_sio = au_test_h_perm_sio(dir, MAY_EXEC | MAY_WRITE); | |
c1595e42 JR |
33458 | + if (!do_sio) { |
33459 | + lockdep_off(); | |
1facf9fc | 33460 | + err = vfsub_rmdir(dir, path); |
c1595e42 JR |
33461 | + lockdep_on(); |
33462 | + } else { | |
1facf9fc | 33463 | + struct au_vfsub_rmdir_args args = { |
33464 | + .errp = &err, | |
33465 | + .dir = dir, | |
33466 | + .path = path | |
33467 | + }; | |
33468 | + wkq_err = au_wkq_wait(au_call_vfsub_rmdir, &args); | |
33469 | + if (unlikely(wkq_err)) | |
33470 | + err = wkq_err; | |
33471 | + } | |
33472 | + | |
33473 | + return err; | |
33474 | +} | |
33475 | + | |
33476 | +/* ---------------------------------------------------------------------- */ | |
33477 | + | |
33478 | +struct notify_change_args { | |
33479 | + int *errp; | |
33480 | + struct path *path; | |
33481 | + struct iattr *ia; | |
523b37e3 | 33482 | + struct inode **delegated_inode; |
1facf9fc | 33483 | +}; |
33484 | + | |
33485 | +static void call_notify_change(void *args) | |
33486 | +{ | |
33487 | + struct notify_change_args *a = args; | |
33488 | + struct inode *h_inode; | |
33489 | + | |
5527c038 | 33490 | + h_inode = d_inode(a->path->dentry); |
1facf9fc | 33491 | + IMustLock(h_inode); |
33492 | + | |
33493 | + *a->errp = -EPERM; | |
33494 | + if (!IS_IMMUTABLE(h_inode) && !IS_APPEND(h_inode)) { | |
c1595e42 | 33495 | + lockdep_off(); |
523b37e3 AM |
33496 | + *a->errp = notify_change(a->path->dentry, a->ia, |
33497 | + a->delegated_inode); | |
c1595e42 | 33498 | + lockdep_on(); |
1facf9fc | 33499 | + if (!*a->errp) |
33500 | + vfsub_update_h_iattr(a->path, /*did*/NULL); /*ignore*/ | |
33501 | + } | |
33502 | + AuTraceErr(*a->errp); | |
33503 | +} | |
33504 | + | |
523b37e3 AM |
33505 | +int vfsub_notify_change(struct path *path, struct iattr *ia, |
33506 | + struct inode **delegated_inode) | |
1facf9fc | 33507 | +{ |
33508 | + int err; | |
33509 | + struct notify_change_args args = { | |
523b37e3 AM |
33510 | + .errp = &err, |
33511 | + .path = path, | |
33512 | + .ia = ia, | |
33513 | + .delegated_inode = delegated_inode | |
1facf9fc | 33514 | + }; |
33515 | + | |
33516 | + call_notify_change(&args); | |
33517 | + | |
33518 | + return err; | |
33519 | +} | |
33520 | + | |
523b37e3 AM |
33521 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
33522 | + struct inode **delegated_inode) | |
1facf9fc | 33523 | +{ |
33524 | + int err, wkq_err; | |
33525 | + struct notify_change_args args = { | |
523b37e3 AM |
33526 | + .errp = &err, |
33527 | + .path = path, | |
33528 | + .ia = ia, | |
33529 | + .delegated_inode = delegated_inode | |
1facf9fc | 33530 | + }; |
33531 | + | |
33532 | + wkq_err = au_wkq_wait(call_notify_change, &args); | |
33533 | + if (unlikely(wkq_err)) | |
33534 | + err = wkq_err; | |
33535 | + | |
33536 | + return err; | |
33537 | +} | |
33538 | + | |
33539 | +/* ---------------------------------------------------------------------- */ | |
33540 | + | |
33541 | +struct unlink_args { | |
33542 | + int *errp; | |
33543 | + struct inode *dir; | |
33544 | + struct path *path; | |
523b37e3 | 33545 | + struct inode **delegated_inode; |
1facf9fc | 33546 | +}; |
33547 | + | |
33548 | +static void call_unlink(void *args) | |
33549 | +{ | |
33550 | + struct unlink_args *a = args; | |
33551 | + struct dentry *d = a->path->dentry; | |
33552 | + struct inode *h_inode; | |
33553 | + const int stop_sillyrename = (au_test_nfs(d->d_sb) | |
c1595e42 | 33554 | + && au_dcount(d) == 1); |
1facf9fc | 33555 | + |
33556 | + IMustLock(a->dir); | |
33557 | + | |
33558 | + a->path->dentry = d->d_parent; | |
33559 | + *a->errp = security_path_unlink(a->path, d); | |
33560 | + a->path->dentry = d; | |
33561 | + if (unlikely(*a->errp)) | |
33562 | + return; | |
33563 | + | |
33564 | + if (!stop_sillyrename) | |
33565 | + dget(d); | |
5527c038 JR |
33566 | + h_inode = NULL; |
33567 | + if (d_is_positive(d)) { | |
33568 | + h_inode = d_inode(d); | |
027c5e7a | 33569 | + ihold(h_inode); |
5527c038 | 33570 | + } |
1facf9fc | 33571 | + |
2cbb1c4b | 33572 | + lockdep_off(); |
523b37e3 | 33573 | + *a->errp = vfs_unlink(a->dir, d, a->delegated_inode); |
2cbb1c4b | 33574 | + lockdep_on(); |
1facf9fc | 33575 | + if (!*a->errp) { |
33576 | + struct path tmp = { | |
33577 | + .dentry = d->d_parent, | |
33578 | + .mnt = a->path->mnt | |
33579 | + }; | |
33580 | + vfsub_update_h_iattr(&tmp, /*did*/NULL); /*ignore*/ | |
33581 | + } | |
33582 | + | |
33583 | + if (!stop_sillyrename) | |
33584 | + dput(d); | |
33585 | + if (h_inode) | |
33586 | + iput(h_inode); | |
33587 | + | |
33588 | + AuTraceErr(*a->errp); | |
33589 | +} | |
33590 | + | |
33591 | +/* | |
33592 | + * @dir: must be locked. | |
33593 | + * @dentry: target dentry. | |
33594 | + */ | |
523b37e3 AM |
33595 | +int vfsub_unlink(struct inode *dir, struct path *path, |
33596 | + struct inode **delegated_inode, int force) | |
1facf9fc | 33597 | +{ |
33598 | + int err; | |
33599 | + struct unlink_args args = { | |
523b37e3 AM |
33600 | + .errp = &err, |
33601 | + .dir = dir, | |
33602 | + .path = path, | |
33603 | + .delegated_inode = delegated_inode | |
1facf9fc | 33604 | + }; |
33605 | + | |
33606 | + if (!force) | |
33607 | + call_unlink(&args); | |
33608 | + else { | |
33609 | + int wkq_err; | |
33610 | + | |
33611 | + wkq_err = au_wkq_wait(call_unlink, &args); | |
33612 | + if (unlikely(wkq_err)) | |
33613 | + err = wkq_err; | |
33614 | + } | |
33615 | + | |
33616 | + return err; | |
33617 | +} | |
7f207e10 | 33618 | diff -urN /usr/share/empty/fs/aufs/vfsub.h linux/fs/aufs/vfsub.h |
eca34b5c | 33619 | --- /usr/share/empty/fs/aufs/vfsub.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 33620 | +++ linux/fs/aufs/vfsub.h 2020-01-27 10:57:18.178871751 +0100 |
eca801bf | 33621 | @@ -0,0 +1,354 @@ |
062440b3 | 33622 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 33623 | +/* |
d58c55f2 | 33624 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 33625 | + * |
33626 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33627 | + * it under the terms of the GNU General Public License as published by | |
33628 | + * the Free Software Foundation; either version 2 of the License, or | |
33629 | + * (at your option) any later version. | |
dece6358 AM |
33630 | + * |
33631 | + * This program is distributed in the hope that it will be useful, | |
33632 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33633 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33634 | + * GNU General Public License for more details. | |
33635 | + * | |
33636 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33637 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33638 | + */ |
33639 | + | |
33640 | +/* | |
33641 | + * sub-routines for VFS | |
33642 | + */ | |
33643 | + | |
33644 | +#ifndef __AUFS_VFSUB_H__ | |
33645 | +#define __AUFS_VFSUB_H__ | |
33646 | + | |
33647 | +#ifdef __KERNEL__ | |
33648 | + | |
33649 | +#include <linux/fs.h> | |
b4510431 | 33650 | +#include <linux/mount.h> |
8cdd5066 | 33651 | +#include <linux/posix_acl.h> |
c1595e42 | 33652 | +#include <linux/xattr.h> |
7f207e10 | 33653 | +#include "debug.h" |
1facf9fc | 33654 | + |
7f207e10 | 33655 | +/* copied from linux/fs/internal.h */ |
2cbb1c4b | 33656 | +/* todo: BAD approach!! */ |
c06a8ce3 | 33657 | +extern void __mnt_drop_write(struct vfsmount *); |
acd2b654 | 33658 | +extern struct file *alloc_empty_file(int, const struct cred *); |
7f207e10 AM |
33659 | + |
33660 | +/* ---------------------------------------------------------------------- */ | |
1facf9fc | 33661 | + |
33662 | +/* lock subclass for lower inode */ | |
33663 | +/* default MAX_LOCKDEP_SUBCLASSES(8) is not enough */ | |
33664 | +/* reduce? gave up. */ | |
33665 | +enum { | |
c1595e42 | 33666 | + AuLsc_I_Begin = I_MUTEX_PARENT2, /* 5 */ |
1facf9fc | 33667 | + AuLsc_I_PARENT, /* lower inode, parent first */ |
33668 | + AuLsc_I_PARENT2, /* copyup dirs */ | |
dece6358 | 33669 | + AuLsc_I_PARENT3, /* copyup wh */ |
1facf9fc | 33670 | + AuLsc_I_CHILD, |
33671 | + AuLsc_I_CHILD2, | |
33672 | + AuLsc_I_End | |
33673 | +}; | |
33674 | + | |
33675 | +/* to debug easier, do not make them inlined functions */ | |
33676 | +#define MtxMustLock(mtx) AuDebugOn(!mutex_is_locked(mtx)) | |
febd17d6 | 33677 | +#define IMustLock(i) AuDebugOn(!inode_is_locked(i)) |
1facf9fc | 33678 | + |
33679 | +/* ---------------------------------------------------------------------- */ | |
33680 | + | |
7f207e10 AM |
33681 | +static inline void vfsub_drop_nlink(struct inode *inode) |
33682 | +{ | |
33683 | + AuDebugOn(!inode->i_nlink); | |
33684 | + drop_nlink(inode); | |
33685 | +} | |
33686 | + | |
027c5e7a AM |
33687 | +static inline void vfsub_dead_dir(struct inode *inode) |
33688 | +{ | |
33689 | + AuDebugOn(!S_ISDIR(inode->i_mode)); | |
33690 | + inode->i_flags |= S_DEAD; | |
33691 | + clear_nlink(inode); | |
33692 | +} | |
33693 | + | |
392086de AM |
33694 | +static inline int vfsub_native_ro(struct inode *inode) |
33695 | +{ | |
8b6a4947 | 33696 | + return sb_rdonly(inode->i_sb) |
392086de AM |
33697 | + || IS_RDONLY(inode) |
33698 | + /* || IS_APPEND(inode) */ | |
33699 | + || IS_IMMUTABLE(inode); | |
33700 | +} | |
33701 | + | |
8cdd5066 JR |
33702 | +#ifdef CONFIG_AUFS_BR_FUSE |
33703 | +int vfsub_test_mntns(struct vfsmount *mnt, struct super_block *h_sb); | |
33704 | +#else | |
33705 | +AuStubInt0(vfsub_test_mntns, struct vfsmount *mnt, struct super_block *h_sb); | |
33706 | +#endif | |
33707 | + | |
a2654f78 AM |
33708 | +int vfsub_sync_filesystem(struct super_block *h_sb, int wait); |
33709 | + | |
7f207e10 AM |
33710 | +/* ---------------------------------------------------------------------- */ |
33711 | + | |
33712 | +int vfsub_update_h_iattr(struct path *h_path, int *did); | |
33713 | +struct file *vfsub_dentry_open(struct path *path, int flags); | |
33714 | +struct file *vfsub_filp_open(const char *path, int oflags, int mode); | |
acd2b654 | 33715 | +struct au_branch; |
b912730e | 33716 | +struct vfsub_aopen_args { |
acd2b654 AM |
33717 | + struct file *file; |
33718 | + unsigned int open_flag; | |
33719 | + umode_t create_mode; | |
33720 | + struct au_branch *br; | |
b912730e | 33721 | +}; |
b912730e | 33722 | +int vfsub_atomic_open(struct inode *dir, struct dentry *dentry, |
acd2b654 | 33723 | + struct vfsub_aopen_args *args); |
1facf9fc | 33724 | +int vfsub_kern_path(const char *name, unsigned int flags, struct path *path); |
b4510431 | 33725 | + |
febd17d6 JR |
33726 | +struct dentry *vfsub_lookup_one_len_unlocked(const char *name, |
33727 | + struct dentry *parent, int len); | |
1facf9fc | 33728 | +struct dentry *vfsub_lookup_one_len(const char *name, struct dentry *parent, |
33729 | + int len); | |
b4510431 AM |
33730 | + |
33731 | +struct vfsub_lkup_one_args { | |
33732 | + struct dentry **errp; | |
33733 | + struct qstr *name; | |
33734 | + struct dentry *parent; | |
33735 | +}; | |
33736 | + | |
33737 | +static inline struct dentry *vfsub_lkup_one(struct qstr *name, | |
33738 | + struct dentry *parent) | |
33739 | +{ | |
33740 | + return vfsub_lookup_one_len(name->name, parent, name->len); | |
33741 | +} | |
33742 | + | |
33743 | +void vfsub_call_lkup_one(void *args); | |
33744 | + | |
33745 | +/* ---------------------------------------------------------------------- */ | |
33746 | + | |
33747 | +static inline int vfsub_mnt_want_write(struct vfsmount *mnt) | |
33748 | +{ | |
33749 | + int err; | |
076b876e | 33750 | + |
b4510431 AM |
33751 | + lockdep_off(); |
33752 | + err = mnt_want_write(mnt); | |
33753 | + lockdep_on(); | |
33754 | + return err; | |
33755 | +} | |
33756 | + | |
33757 | +static inline void vfsub_mnt_drop_write(struct vfsmount *mnt) | |
33758 | +{ | |
33759 | + lockdep_off(); | |
33760 | + mnt_drop_write(mnt); | |
33761 | + lockdep_on(); | |
33762 | +} | |
1facf9fc | 33763 | + |
7e9cd9fe | 33764 | +#if 0 /* reserved */ |
c06a8ce3 AM |
33765 | +static inline void vfsub_mnt_drop_write_file(struct file *file) |
33766 | +{ | |
33767 | + lockdep_off(); | |
33768 | + mnt_drop_write_file(file); | |
33769 | + lockdep_on(); | |
33770 | +} | |
7e9cd9fe | 33771 | +#endif |
c06a8ce3 | 33772 | + |
1facf9fc | 33773 | +/* ---------------------------------------------------------------------- */ |
33774 | + | |
33775 | +struct au_hinode; | |
33776 | +struct dentry *vfsub_lock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
33777 | + struct dentry *d2, struct au_hinode *hdir2); | |
33778 | +void vfsub_unlock_rename(struct dentry *d1, struct au_hinode *hdir1, | |
33779 | + struct dentry *d2, struct au_hinode *hdir2); | |
33780 | + | |
537831f9 AM |
33781 | +int vfsub_create(struct inode *dir, struct path *path, int mode, |
33782 | + bool want_excl); | |
1facf9fc | 33783 | +int vfsub_symlink(struct inode *dir, struct path *path, |
33784 | + const char *symname); | |
33785 | +int vfsub_mknod(struct inode *dir, struct path *path, int mode, dev_t dev); | |
33786 | +int vfsub_link(struct dentry *src_dentry, struct inode *dir, | |
523b37e3 | 33787 | + struct path *path, struct inode **delegated_inode); |
1facf9fc | 33788 | +int vfsub_rename(struct inode *src_hdir, struct dentry *src_dentry, |
523b37e3 | 33789 | + struct inode *hdir, struct path *path, |
f2c43d5f | 33790 | + struct inode **delegated_inode, unsigned int flags); |
1facf9fc | 33791 | +int vfsub_mkdir(struct inode *dir, struct path *path, int mode); |
33792 | +int vfsub_rmdir(struct inode *dir, struct path *path); | |
33793 | + | |
33794 | +/* ---------------------------------------------------------------------- */ | |
33795 | + | |
33796 | +ssize_t vfsub_read_u(struct file *file, char __user *ubuf, size_t count, | |
33797 | + loff_t *ppos); | |
33798 | +ssize_t vfsub_read_k(struct file *file, void *kbuf, size_t count, | |
33799 | + loff_t *ppos); | |
33800 | +ssize_t vfsub_write_u(struct file *file, const char __user *ubuf, size_t count, | |
33801 | + loff_t *ppos); | |
33802 | +ssize_t vfsub_write_k(struct file *file, void *kbuf, size_t count, | |
33803 | + loff_t *ppos); | |
4a4d8108 | 33804 | +int vfsub_flush(struct file *file, fl_owner_t id); |
392086de AM |
33805 | +int vfsub_iterate_dir(struct file *file, struct dir_context *ctx); |
33806 | + | |
c06a8ce3 AM |
33807 | +static inline loff_t vfsub_f_size_read(struct file *file) |
33808 | +{ | |
33809 | + return i_size_read(file_inode(file)); | |
33810 | +} | |
33811 | + | |
4a4d8108 AM |
33812 | +static inline unsigned int vfsub_file_flags(struct file *file) |
33813 | +{ | |
33814 | + unsigned int flags; | |
33815 | + | |
33816 | + spin_lock(&file->f_lock); | |
33817 | + flags = file->f_flags; | |
33818 | + spin_unlock(&file->f_lock); | |
33819 | + | |
33820 | + return flags; | |
33821 | +} | |
1308ab2a | 33822 | + |
f0c0a007 AM |
33823 | +static inline int vfsub_file_execed(struct file *file) |
33824 | +{ | |
33825 | + /* todo: direct access f_flags */ | |
33826 | + return !!(vfsub_file_flags(file) & __FMODE_EXEC); | |
33827 | +} | |
33828 | + | |
7e9cd9fe | 33829 | +#if 0 /* reserved */ |
1facf9fc | 33830 | +static inline void vfsub_file_accessed(struct file *h_file) |
33831 | +{ | |
33832 | + file_accessed(h_file); | |
33833 | + vfsub_update_h_iattr(&h_file->f_path, /*did*/NULL); /*ignore*/ | |
33834 | +} | |
7e9cd9fe | 33835 | +#endif |
1facf9fc | 33836 | + |
79b8bda9 | 33837 | +#if 0 /* reserved */ |
1facf9fc | 33838 | +static inline void vfsub_touch_atime(struct vfsmount *h_mnt, |
33839 | + struct dentry *h_dentry) | |
33840 | +{ | |
33841 | + struct path h_path = { | |
33842 | + .dentry = h_dentry, | |
33843 | + .mnt = h_mnt | |
33844 | + }; | |
92d182d2 | 33845 | + touch_atime(&h_path); |
1facf9fc | 33846 | + vfsub_update_h_iattr(&h_path, /*did*/NULL); /*ignore*/ |
33847 | +} | |
79b8bda9 | 33848 | +#endif |
1facf9fc | 33849 | + |
cd7a4cd9 AM |
33850 | +static inline int vfsub_update_time(struct inode *h_inode, |
33851 | + struct timespec64 *ts, int flags) | |
0c3ec466 | 33852 | +{ |
5afbbe0d | 33853 | + return update_time(h_inode, ts, flags); |
0c3ec466 AM |
33854 | + /* no vfsub_update_h_iattr() since we don't have struct path */ |
33855 | +} | |
33856 | + | |
8cdd5066 JR |
33857 | +#ifdef CONFIG_FS_POSIX_ACL |
33858 | +static inline int vfsub_acl_chmod(struct inode *h_inode, umode_t h_mode) | |
33859 | +{ | |
33860 | + int err; | |
33861 | + | |
33862 | + err = posix_acl_chmod(h_inode, h_mode); | |
33863 | + if (err == -EOPNOTSUPP) | |
33864 | + err = 0; | |
33865 | + return err; | |
33866 | +} | |
33867 | +#else | |
33868 | +AuStubInt0(vfsub_acl_chmod, struct inode *h_inode, umode_t h_mode); | |
33869 | +#endif | |
33870 | + | |
4a4d8108 AM |
33871 | +long vfsub_splice_to(struct file *in, loff_t *ppos, |
33872 | + struct pipe_inode_info *pipe, size_t len, | |
33873 | + unsigned int flags); | |
33874 | +long vfsub_splice_from(struct pipe_inode_info *pipe, struct file *out, | |
33875 | + loff_t *ppos, size_t len, unsigned int flags); | |
c06a8ce3 AM |
33876 | + |
33877 | +static inline long vfsub_truncate(struct path *path, loff_t length) | |
33878 | +{ | |
33879 | + long err; | |
076b876e | 33880 | + |
c06a8ce3 AM |
33881 | + lockdep_off(); |
33882 | + err = vfs_truncate(path, length); | |
33883 | + lockdep_on(); | |
33884 | + return err; | |
33885 | +} | |
33886 | + | |
4a4d8108 AM |
33887 | +int vfsub_trunc(struct path *h_path, loff_t length, unsigned int attr, |
33888 | + struct file *h_file); | |
53392da6 | 33889 | +int vfsub_fsync(struct file *file, struct path *path, int datasync); |
4a4d8108 | 33890 | + |
521ced18 JR |
33891 | +/* |
33892 | + * re-use branch fs's ioctl(FICLONE) while aufs itself doesn't support such | |
33893 | + * ioctl. | |
33894 | + */ | |
9f237c51 AM |
33895 | +static inline loff_t vfsub_clone_file_range(struct file *src, struct file *dst, |
33896 | + loff_t len) | |
521ced18 | 33897 | +{ |
9f237c51 | 33898 | + loff_t err; |
521ced18 JR |
33899 | + |
33900 | + lockdep_off(); | |
9f237c51 | 33901 | + err = vfs_clone_file_range(src, 0, dst, 0, len, /*remap_flags*/0); |
521ced18 JR |
33902 | + lockdep_on(); |
33903 | + | |
33904 | + return err; | |
33905 | +} | |
33906 | + | |
33907 | +/* copy_file_range(2) is a systemcall */ | |
33908 | +static inline ssize_t vfsub_copy_file_range(struct file *src, loff_t src_pos, | |
33909 | + struct file *dst, loff_t dst_pos, | |
33910 | + size_t len, unsigned int flags) | |
33911 | +{ | |
33912 | + ssize_t ssz; | |
33913 | + | |
33914 | + lockdep_off(); | |
33915 | + ssz = vfs_copy_file_range(src, src_pos, dst, dst_pos, len, flags); | |
33916 | + lockdep_on(); | |
33917 | + | |
33918 | + return ssz; | |
33919 | +} | |
33920 | + | |
1facf9fc | 33921 | +/* ---------------------------------------------------------------------- */ |
33922 | + | |
33923 | +static inline loff_t vfsub_llseek(struct file *file, loff_t offset, int origin) | |
33924 | +{ | |
33925 | + loff_t err; | |
33926 | + | |
2cbb1c4b | 33927 | + lockdep_off(); |
1facf9fc | 33928 | + err = vfs_llseek(file, offset, origin); |
2cbb1c4b | 33929 | + lockdep_on(); |
1facf9fc | 33930 | + return err; |
33931 | +} | |
33932 | + | |
33933 | +/* ---------------------------------------------------------------------- */ | |
33934 | + | |
4a4d8108 AM |
33935 | +int vfsub_sio_mkdir(struct inode *dir, struct path *path, int mode); |
33936 | +int vfsub_sio_rmdir(struct inode *dir, struct path *path); | |
523b37e3 AM |
33937 | +int vfsub_sio_notify_change(struct path *path, struct iattr *ia, |
33938 | + struct inode **delegated_inode); | |
33939 | +int vfsub_notify_change(struct path *path, struct iattr *ia, | |
33940 | + struct inode **delegated_inode); | |
33941 | +int vfsub_unlink(struct inode *dir, struct path *path, | |
33942 | + struct inode **delegated_inode, int force); | |
4a4d8108 | 33943 | + |
521ced18 JR |
33944 | +static inline int vfsub_getattr(const struct path *path, struct kstat *st) |
33945 | +{ | |
33946 | + return vfs_getattr(path, st, STATX_BASIC_STATS, AT_STATX_SYNC_AS_STAT); | |
33947 | +} | |
33948 | + | |
c1595e42 JR |
33949 | +/* ---------------------------------------------------------------------- */ |
33950 | + | |
33951 | +static inline int vfsub_setxattr(struct dentry *dentry, const char *name, | |
33952 | + const void *value, size_t size, int flags) | |
33953 | +{ | |
33954 | + int err; | |
33955 | + | |
33956 | + lockdep_off(); | |
33957 | + err = vfs_setxattr(dentry, name, value, size, flags); | |
33958 | + lockdep_on(); | |
33959 | + | |
33960 | + return err; | |
33961 | +} | |
33962 | + | |
33963 | +static inline int vfsub_removexattr(struct dentry *dentry, const char *name) | |
33964 | +{ | |
33965 | + int err; | |
33966 | + | |
33967 | + lockdep_off(); | |
33968 | + err = vfs_removexattr(dentry, name); | |
33969 | + lockdep_on(); | |
33970 | + | |
33971 | + return err; | |
33972 | +} | |
33973 | + | |
1facf9fc | 33974 | +#endif /* __KERNEL__ */ |
33975 | +#endif /* __AUFS_VFSUB_H__ */ | |
7f207e10 | 33976 | diff -urN /usr/share/empty/fs/aufs/wbr_policy.c linux/fs/aufs/wbr_policy.c |
eca34b5c | 33977 | --- /usr/share/empty/fs/aufs/wbr_policy.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 33978 | +++ linux/fs/aufs/wbr_policy.c 2020-01-27 10:57:18.178871751 +0100 |
cd7a4cd9 AM |
33979 | @@ -0,0 +1,830 @@ |
33980 | +// SPDX-License-Identifier: GPL-2.0 | |
1facf9fc | 33981 | +/* |
d58c55f2 | 33982 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 33983 | + * |
33984 | + * This program, aufs is free software; you can redistribute it and/or modify | |
33985 | + * it under the terms of the GNU General Public License as published by | |
33986 | + * the Free Software Foundation; either version 2 of the License, or | |
33987 | + * (at your option) any later version. | |
dece6358 AM |
33988 | + * |
33989 | + * This program is distributed in the hope that it will be useful, | |
33990 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33991 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
33992 | + * GNU General Public License for more details. | |
33993 | + * | |
33994 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 33995 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 33996 | + */ |
33997 | + | |
33998 | +/* | |
33999 | + * policies for selecting one among multiple writable branches | |
34000 | + */ | |
34001 | + | |
34002 | +#include <linux/statfs.h> | |
34003 | +#include "aufs.h" | |
34004 | + | |
34005 | +/* subset of cpup_attr() */ | |
34006 | +static noinline_for_stack | |
34007 | +int au_cpdown_attr(struct path *h_path, struct dentry *h_src) | |
34008 | +{ | |
34009 | + int err, sbits; | |
34010 | + struct iattr ia; | |
34011 | + struct inode *h_isrc; | |
34012 | + | |
5527c038 | 34013 | + h_isrc = d_inode(h_src); |
1facf9fc | 34014 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE | ATTR_UID | ATTR_GID; |
34015 | + ia.ia_mode = h_isrc->i_mode; | |
34016 | + ia.ia_uid = h_isrc->i_uid; | |
34017 | + ia.ia_gid = h_isrc->i_gid; | |
34018 | + sbits = !!(ia.ia_mode & (S_ISUID | S_ISGID)); | |
5527c038 | 34019 | + au_cpup_attr_flags(d_inode(h_path->dentry), h_isrc->i_flags); |
523b37e3 AM |
34020 | + /* no delegation since it is just created */ |
34021 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); | |
1facf9fc | 34022 | + |
34023 | + /* is this nfs only? */ | |
34024 | + if (!err && sbits && au_test_nfs(h_path->dentry->d_sb)) { | |
34025 | + ia.ia_valid = ATTR_FORCE | ATTR_MODE; | |
34026 | + ia.ia_mode = h_isrc->i_mode; | |
523b37e3 | 34027 | + err = vfsub_sio_notify_change(h_path, &ia, /*delegated*/NULL); |
1facf9fc | 34028 | + } |
34029 | + | |
34030 | + return err; | |
34031 | +} | |
34032 | + | |
34033 | +#define AuCpdown_PARENT_OPQ 1 | |
34034 | +#define AuCpdown_WHED (1 << 1) | |
34035 | +#define AuCpdown_MADE_DIR (1 << 2) | |
34036 | +#define AuCpdown_DIROPQ (1 << 3) | |
34037 | +#define au_ftest_cpdown(flags, name) ((flags) & AuCpdown_##name) | |
7f207e10 AM |
34038 | +#define au_fset_cpdown(flags, name) \ |
34039 | + do { (flags) |= AuCpdown_##name; } while (0) | |
34040 | +#define au_fclr_cpdown(flags, name) \ | |
34041 | + do { (flags) &= ~AuCpdown_##name; } while (0) | |
1facf9fc | 34042 | + |
1facf9fc | 34043 | +static int au_cpdown_dir_opq(struct dentry *dentry, aufs_bindex_t bdst, |
c2b27bf2 | 34044 | + unsigned int *flags) |
1facf9fc | 34045 | +{ |
34046 | + int err; | |
34047 | + struct dentry *opq_dentry; | |
34048 | + | |
34049 | + opq_dentry = au_diropq_create(dentry, bdst); | |
34050 | + err = PTR_ERR(opq_dentry); | |
34051 | + if (IS_ERR(opq_dentry)) | |
34052 | + goto out; | |
34053 | + dput(opq_dentry); | |
c2b27bf2 | 34054 | + au_fset_cpdown(*flags, DIROPQ); |
1facf9fc | 34055 | + |
4f0767ce | 34056 | +out: |
1facf9fc | 34057 | + return err; |
34058 | +} | |
34059 | + | |
34060 | +static int au_cpdown_dir_wh(struct dentry *dentry, struct dentry *h_parent, | |
34061 | + struct inode *dir, aufs_bindex_t bdst) | |
34062 | +{ | |
34063 | + int err; | |
34064 | + struct path h_path; | |
34065 | + struct au_branch *br; | |
34066 | + | |
34067 | + br = au_sbr(dentry->d_sb, bdst); | |
34068 | + h_path.dentry = au_wh_lkup(h_parent, &dentry->d_name, br); | |
34069 | + err = PTR_ERR(h_path.dentry); | |
34070 | + if (IS_ERR(h_path.dentry)) | |
34071 | + goto out; | |
34072 | + | |
34073 | + err = 0; | |
5527c038 | 34074 | + if (d_is_positive(h_path.dentry)) { |
86dc4139 | 34075 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 34076 | + err = au_wh_unlink_dentry(au_h_iptr(dir, bdst), &h_path, |
34077 | + dentry); | |
34078 | + } | |
34079 | + dput(h_path.dentry); | |
34080 | + | |
4f0767ce | 34081 | +out: |
1facf9fc | 34082 | + return err; |
34083 | +} | |
34084 | + | |
34085 | +static int au_cpdown_dir(struct dentry *dentry, aufs_bindex_t bdst, | |
86dc4139 | 34086 | + struct au_pin *pin, |
1facf9fc | 34087 | + struct dentry *h_parent, void *arg) |
34088 | +{ | |
34089 | + int err, rerr; | |
5afbbe0d | 34090 | + aufs_bindex_t bopq, btop; |
1facf9fc | 34091 | + struct path h_path; |
34092 | + struct dentry *parent; | |
34093 | + struct inode *h_dir, *h_inode, *inode, *dir; | |
c2b27bf2 | 34094 | + unsigned int *flags = arg; |
1facf9fc | 34095 | + |
5afbbe0d | 34096 | + btop = au_dbtop(dentry); |
1facf9fc | 34097 | + /* dentry is di-locked */ |
34098 | + parent = dget_parent(dentry); | |
5527c038 JR |
34099 | + dir = d_inode(parent); |
34100 | + h_dir = d_inode(h_parent); | |
1facf9fc | 34101 | + AuDebugOn(h_dir != au_h_iptr(dir, bdst)); |
34102 | + IMustLock(h_dir); | |
34103 | + | |
86dc4139 | 34104 | + err = au_lkup_neg(dentry, bdst, /*wh*/0); |
1facf9fc | 34105 | + if (unlikely(err < 0)) |
34106 | + goto out; | |
34107 | + h_path.dentry = au_h_dptr(dentry, bdst); | |
34108 | + h_path.mnt = au_sbr_mnt(dentry->d_sb, bdst); | |
cd7a4cd9 | 34109 | + err = vfsub_sio_mkdir(au_h_iptr(dir, bdst), &h_path, 0755); |
1facf9fc | 34110 | + if (unlikely(err)) |
34111 | + goto out_put; | |
c2b27bf2 | 34112 | + au_fset_cpdown(*flags, MADE_DIR); |
1facf9fc | 34113 | + |
1facf9fc | 34114 | + bopq = au_dbdiropq(dentry); |
c2b27bf2 AM |
34115 | + au_fclr_cpdown(*flags, WHED); |
34116 | + au_fclr_cpdown(*flags, DIROPQ); | |
1facf9fc | 34117 | + if (au_dbwh(dentry) == bdst) |
c2b27bf2 AM |
34118 | + au_fset_cpdown(*flags, WHED); |
34119 | + if (!au_ftest_cpdown(*flags, PARENT_OPQ) && bopq <= bdst) | |
34120 | + au_fset_cpdown(*flags, PARENT_OPQ); | |
5527c038 | 34121 | + h_inode = d_inode(h_path.dentry); |
febd17d6 | 34122 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
c2b27bf2 AM |
34123 | + if (au_ftest_cpdown(*flags, WHED)) { |
34124 | + err = au_cpdown_dir_opq(dentry, bdst, flags); | |
1facf9fc | 34125 | + if (unlikely(err)) { |
febd17d6 | 34126 | + inode_unlock(h_inode); |
1facf9fc | 34127 | + goto out_dir; |
34128 | + } | |
34129 | + } | |
34130 | + | |
5afbbe0d | 34131 | + err = au_cpdown_attr(&h_path, au_h_dptr(dentry, btop)); |
febd17d6 | 34132 | + inode_unlock(h_inode); |
1facf9fc | 34133 | + if (unlikely(err)) |
34134 | + goto out_opq; | |
34135 | + | |
c2b27bf2 | 34136 | + if (au_ftest_cpdown(*flags, WHED)) { |
1facf9fc | 34137 | + err = au_cpdown_dir_wh(dentry, h_parent, dir, bdst); |
34138 | + if (unlikely(err)) | |
34139 | + goto out_opq; | |
34140 | + } | |
34141 | + | |
5527c038 | 34142 | + inode = d_inode(dentry); |
5afbbe0d AM |
34143 | + if (au_ibbot(inode) < bdst) |
34144 | + au_set_ibbot(inode, bdst); | |
1facf9fc | 34145 | + au_set_h_iptr(inode, bdst, au_igrab(h_inode), |
34146 | + au_hi_flags(inode, /*isdir*/1)); | |
076b876e | 34147 | + au_fhsm_wrote(dentry->d_sb, bdst, /*force*/0); |
1facf9fc | 34148 | + goto out; /* success */ |
34149 | + | |
34150 | + /* revert */ | |
4f0767ce | 34151 | +out_opq: |
c2b27bf2 | 34152 | + if (au_ftest_cpdown(*flags, DIROPQ)) { |
febd17d6 | 34153 | + inode_lock_nested(h_inode, AuLsc_I_CHILD); |
1facf9fc | 34154 | + rerr = au_diropq_remove(dentry, bdst); |
febd17d6 | 34155 | + inode_unlock(h_inode); |
1facf9fc | 34156 | + if (unlikely(rerr)) { |
523b37e3 AM |
34157 | + AuIOErr("failed removing diropq for %pd b%d (%d)\n", |
34158 | + dentry, bdst, rerr); | |
1facf9fc | 34159 | + err = -EIO; |
34160 | + goto out; | |
34161 | + } | |
34162 | + } | |
4f0767ce | 34163 | +out_dir: |
c2b27bf2 | 34164 | + if (au_ftest_cpdown(*flags, MADE_DIR)) { |
1facf9fc | 34165 | + rerr = vfsub_sio_rmdir(au_h_iptr(dir, bdst), &h_path); |
34166 | + if (unlikely(rerr)) { | |
523b37e3 AM |
34167 | + AuIOErr("failed removing %pd b%d (%d)\n", |
34168 | + dentry, bdst, rerr); | |
1facf9fc | 34169 | + err = -EIO; |
34170 | + } | |
34171 | + } | |
4f0767ce | 34172 | +out_put: |
1facf9fc | 34173 | + au_set_h_dptr(dentry, bdst, NULL); |
5afbbe0d AM |
34174 | + if (au_dbbot(dentry) == bdst) |
34175 | + au_update_dbbot(dentry); | |
4f0767ce | 34176 | +out: |
1facf9fc | 34177 | + dput(parent); |
34178 | + return err; | |
34179 | +} | |
34180 | + | |
34181 | +int au_cpdown_dirs(struct dentry *dentry, aufs_bindex_t bdst) | |
34182 | +{ | |
34183 | + int err; | |
c2b27bf2 | 34184 | + unsigned int flags; |
1facf9fc | 34185 | + |
c2b27bf2 AM |
34186 | + flags = 0; |
34187 | + err = au_cp_dirs(dentry, bdst, au_cpdown_dir, &flags); | |
1facf9fc | 34188 | + |
34189 | + return err; | |
34190 | +} | |
34191 | + | |
34192 | +/* ---------------------------------------------------------------------- */ | |
34193 | + | |
34194 | +/* policies for create */ | |
34195 | + | |
c2b27bf2 | 34196 | +int au_wbr_nonopq(struct dentry *dentry, aufs_bindex_t bindex) |
4a4d8108 AM |
34197 | +{ |
34198 | + int err, i, j, ndentry; | |
34199 | + aufs_bindex_t bopq; | |
34200 | + struct au_dcsub_pages dpages; | |
34201 | + struct au_dpage *dpage; | |
34202 | + struct dentry **dentries, *parent, *d; | |
34203 | + | |
34204 | + err = au_dpages_init(&dpages, GFP_NOFS); | |
34205 | + if (unlikely(err)) | |
34206 | + goto out; | |
34207 | + parent = dget_parent(dentry); | |
027c5e7a | 34208 | + err = au_dcsub_pages_rev_aufs(&dpages, parent, /*do_include*/0); |
4a4d8108 AM |
34209 | + if (unlikely(err)) |
34210 | + goto out_free; | |
34211 | + | |
34212 | + err = bindex; | |
34213 | + for (i = 0; i < dpages.ndpage; i++) { | |
34214 | + dpage = dpages.dpages + i; | |
34215 | + dentries = dpage->dentries; | |
34216 | + ndentry = dpage->ndentry; | |
34217 | + for (j = 0; j < ndentry; j++) { | |
34218 | + d = dentries[j]; | |
34219 | + di_read_lock_parent2(d, !AuLock_IR); | |
34220 | + bopq = au_dbdiropq(d); | |
34221 | + di_read_unlock(d, !AuLock_IR); | |
34222 | + if (bopq >= 0 && bopq < err) | |
34223 | + err = bopq; | |
34224 | + } | |
34225 | + } | |
34226 | + | |
34227 | +out_free: | |
34228 | + dput(parent); | |
34229 | + au_dpages_free(&dpages); | |
34230 | +out: | |
34231 | + return err; | |
34232 | +} | |
34233 | + | |
1facf9fc | 34234 | +static int au_wbr_bu(struct super_block *sb, aufs_bindex_t bindex) |
34235 | +{ | |
34236 | + for (; bindex >= 0; bindex--) | |
34237 | + if (!au_br_rdonly(au_sbr(sb, bindex))) | |
34238 | + return bindex; | |
34239 | + return -EROFS; | |
34240 | +} | |
34241 | + | |
34242 | +/* top down parent */ | |
392086de AM |
34243 | +static int au_wbr_create_tdp(struct dentry *dentry, |
34244 | + unsigned int flags __maybe_unused) | |
1facf9fc | 34245 | +{ |
34246 | + int err; | |
5afbbe0d | 34247 | + aufs_bindex_t btop, bindex; |
1facf9fc | 34248 | + struct super_block *sb; |
34249 | + struct dentry *parent, *h_parent; | |
34250 | + | |
34251 | + sb = dentry->d_sb; | |
5afbbe0d AM |
34252 | + btop = au_dbtop(dentry); |
34253 | + err = btop; | |
34254 | + if (!au_br_rdonly(au_sbr(sb, btop))) | |
1facf9fc | 34255 | + goto out; |
34256 | + | |
34257 | + err = -EROFS; | |
34258 | + parent = dget_parent(dentry); | |
5afbbe0d | 34259 | + for (bindex = au_dbtop(parent); bindex < btop; bindex++) { |
1facf9fc | 34260 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 34261 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 34262 | + continue; |
34263 | + | |
34264 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
34265 | + err = bindex; | |
34266 | + break; | |
34267 | + } | |
34268 | + } | |
34269 | + dput(parent); | |
34270 | + | |
34271 | + /* bottom up here */ | |
4a4d8108 | 34272 | + if (unlikely(err < 0)) { |
5afbbe0d | 34273 | + err = au_wbr_bu(sb, btop - 1); |
4a4d8108 AM |
34274 | + if (err >= 0) |
34275 | + err = au_wbr_nonopq(dentry, err); | |
34276 | + } | |
1facf9fc | 34277 | + |
4f0767ce | 34278 | +out: |
1facf9fc | 34279 | + AuDbg("b%d\n", err); |
34280 | + return err; | |
34281 | +} | |
34282 | + | |
34283 | +/* ---------------------------------------------------------------------- */ | |
34284 | + | |
34285 | +/* an exception for the policy other than tdp */ | |
34286 | +static int au_wbr_create_exp(struct dentry *dentry) | |
34287 | +{ | |
34288 | + int err; | |
34289 | + aufs_bindex_t bwh, bdiropq; | |
34290 | + struct dentry *parent; | |
34291 | + | |
34292 | + err = -1; | |
34293 | + bwh = au_dbwh(dentry); | |
34294 | + parent = dget_parent(dentry); | |
34295 | + bdiropq = au_dbdiropq(parent); | |
34296 | + if (bwh >= 0) { | |
34297 | + if (bdiropq >= 0) | |
34298 | + err = min(bdiropq, bwh); | |
34299 | + else | |
34300 | + err = bwh; | |
34301 | + AuDbg("%d\n", err); | |
34302 | + } else if (bdiropq >= 0) { | |
34303 | + err = bdiropq; | |
34304 | + AuDbg("%d\n", err); | |
34305 | + } | |
34306 | + dput(parent); | |
34307 | + | |
4a4d8108 AM |
34308 | + if (err >= 0) |
34309 | + err = au_wbr_nonopq(dentry, err); | |
34310 | + | |
1facf9fc | 34311 | + if (err >= 0 && au_br_rdonly(au_sbr(dentry->d_sb, err))) |
34312 | + err = -1; | |
34313 | + | |
34314 | + AuDbg("%d\n", err); | |
34315 | + return err; | |
34316 | +} | |
34317 | + | |
34318 | +/* ---------------------------------------------------------------------- */ | |
34319 | + | |
34320 | +/* round robin */ | |
34321 | +static int au_wbr_create_init_rr(struct super_block *sb) | |
34322 | +{ | |
34323 | + int err; | |
34324 | + | |
5afbbe0d | 34325 | + err = au_wbr_bu(sb, au_sbbot(sb)); |
1facf9fc | 34326 | + atomic_set(&au_sbi(sb)->si_wbr_rr_next, -err); /* less important */ |
dece6358 | 34327 | + /* smp_mb(); */ |
1facf9fc | 34328 | + |
34329 | + AuDbg("b%d\n", err); | |
34330 | + return err; | |
34331 | +} | |
34332 | + | |
392086de | 34333 | +static int au_wbr_create_rr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34334 | +{ |
34335 | + int err, nbr; | |
34336 | + unsigned int u; | |
5afbbe0d | 34337 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 34338 | + struct super_block *sb; |
34339 | + atomic_t *next; | |
34340 | + | |
34341 | + err = au_wbr_create_exp(dentry); | |
34342 | + if (err >= 0) | |
34343 | + goto out; | |
34344 | + | |
34345 | + sb = dentry->d_sb; | |
34346 | + next = &au_sbi(sb)->si_wbr_rr_next; | |
5afbbe0d AM |
34347 | + bbot = au_sbbot(sb); |
34348 | + nbr = bbot + 1; | |
34349 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
392086de | 34350 | + if (!au_ftest_wbr(flags, DIR)) { |
1facf9fc | 34351 | + err = atomic_dec_return(next) + 1; |
34352 | + /* modulo for 0 is meaningless */ | |
34353 | + if (unlikely(!err)) | |
34354 | + err = atomic_dec_return(next) + 1; | |
34355 | + } else | |
34356 | + err = atomic_read(next); | |
34357 | + AuDbg("%d\n", err); | |
34358 | + u = err; | |
34359 | + err = u % nbr; | |
34360 | + AuDbg("%d\n", err); | |
34361 | + if (!au_br_rdonly(au_sbr(sb, err))) | |
34362 | + break; | |
34363 | + err = -EROFS; | |
34364 | + } | |
34365 | + | |
4a4d8108 AM |
34366 | + if (err >= 0) |
34367 | + err = au_wbr_nonopq(dentry, err); | |
34368 | + | |
4f0767ce | 34369 | +out: |
1facf9fc | 34370 | + AuDbg("%d\n", err); |
34371 | + return err; | |
34372 | +} | |
34373 | + | |
34374 | +/* ---------------------------------------------------------------------- */ | |
34375 | + | |
34376 | +/* most free space */ | |
392086de | 34377 | +static void au_mfs(struct dentry *dentry, struct dentry *parent) |
1facf9fc | 34378 | +{ |
34379 | + struct super_block *sb; | |
34380 | + struct au_branch *br; | |
34381 | + struct au_wbr_mfs *mfs; | |
392086de | 34382 | + struct dentry *h_parent; |
5afbbe0d | 34383 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 34384 | + int err; |
34385 | + unsigned long long b, bavail; | |
7f207e10 | 34386 | + struct path h_path; |
1facf9fc | 34387 | + /* reduce the stack usage */ |
34388 | + struct kstatfs *st; | |
34389 | + | |
34390 | + st = kmalloc(sizeof(*st), GFP_NOFS); | |
34391 | + if (unlikely(!st)) { | |
34392 | + AuWarn1("failed updating mfs(%d), ignored\n", -ENOMEM); | |
34393 | + return; | |
34394 | + } | |
34395 | + | |
34396 | + bavail = 0; | |
34397 | + sb = dentry->d_sb; | |
34398 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
dece6358 | 34399 | + MtxMustLock(&mfs->mfs_lock); |
1facf9fc | 34400 | + mfs->mfs_bindex = -EROFS; |
34401 | + mfs->mfsrr_bytes = 0; | |
392086de AM |
34402 | + if (!parent) { |
34403 | + bindex = 0; | |
5afbbe0d | 34404 | + bbot = au_sbbot(sb); |
392086de | 34405 | + } else { |
5afbbe0d AM |
34406 | + bindex = au_dbtop(parent); |
34407 | + bbot = au_dbtaildir(parent); | |
392086de AM |
34408 | + } |
34409 | + | |
5afbbe0d | 34410 | + for (; bindex <= bbot; bindex++) { |
392086de AM |
34411 | + if (parent) { |
34412 | + h_parent = au_h_dptr(parent, bindex); | |
5527c038 | 34413 | + if (!h_parent || d_is_negative(h_parent)) |
392086de AM |
34414 | + continue; |
34415 | + } | |
1facf9fc | 34416 | + br = au_sbr(sb, bindex); |
34417 | + if (au_br_rdonly(br)) | |
34418 | + continue; | |
34419 | + | |
34420 | + /* sb->s_root for NFS is unreliable */ | |
86dc4139 | 34421 | + h_path.mnt = au_br_mnt(br); |
7f207e10 AM |
34422 | + h_path.dentry = h_path.mnt->mnt_root; |
34423 | + err = vfs_statfs(&h_path, st); | |
1facf9fc | 34424 | + if (unlikely(err)) { |
34425 | + AuWarn1("failed statfs, b%d, %d\n", bindex, err); | |
34426 | + continue; | |
34427 | + } | |
34428 | + | |
34429 | + /* when the available size is equal, select the lower one */ | |
34430 | + BUILD_BUG_ON(sizeof(b) < sizeof(st->f_bavail) | |
34431 | + || sizeof(b) < sizeof(st->f_bsize)); | |
34432 | + b = st->f_bavail * st->f_bsize; | |
34433 | + br->br_wbr->wbr_bytes = b; | |
34434 | + if (b >= bavail) { | |
34435 | + bavail = b; | |
34436 | + mfs->mfs_bindex = bindex; | |
34437 | + mfs->mfs_jiffy = jiffies; | |
34438 | + } | |
34439 | + } | |
34440 | + | |
34441 | + mfs->mfsrr_bytes = bavail; | |
34442 | + AuDbg("b%d\n", mfs->mfs_bindex); | |
9f237c51 | 34443 | + au_kfree_rcu(st); |
1facf9fc | 34444 | +} |
34445 | + | |
392086de | 34446 | +static int au_wbr_create_mfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34447 | +{ |
34448 | + int err; | |
392086de | 34449 | + struct dentry *parent; |
1facf9fc | 34450 | + struct super_block *sb; |
34451 | + struct au_wbr_mfs *mfs; | |
34452 | + | |
34453 | + err = au_wbr_create_exp(dentry); | |
34454 | + if (err >= 0) | |
34455 | + goto out; | |
34456 | + | |
34457 | + sb = dentry->d_sb; | |
392086de AM |
34458 | + parent = NULL; |
34459 | + if (au_ftest_wbr(flags, PARENT)) | |
34460 | + parent = dget_parent(dentry); | |
1facf9fc | 34461 | + mfs = &au_sbi(sb)->si_wbr_mfs; |
34462 | + mutex_lock(&mfs->mfs_lock); | |
34463 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
34464 | + || mfs->mfs_bindex < 0 | |
34465 | + || au_br_rdonly(au_sbr(sb, mfs->mfs_bindex))) | |
392086de | 34466 | + au_mfs(dentry, parent); |
1facf9fc | 34467 | + mutex_unlock(&mfs->mfs_lock); |
34468 | + err = mfs->mfs_bindex; | |
392086de | 34469 | + dput(parent); |
1facf9fc | 34470 | + |
4a4d8108 AM |
34471 | + if (err >= 0) |
34472 | + err = au_wbr_nonopq(dentry, err); | |
34473 | + | |
4f0767ce | 34474 | +out: |
1facf9fc | 34475 | + AuDbg("b%d\n", err); |
34476 | + return err; | |
34477 | +} | |
34478 | + | |
34479 | +static int au_wbr_create_init_mfs(struct super_block *sb) | |
34480 | +{ | |
34481 | + struct au_wbr_mfs *mfs; | |
34482 | + | |
34483 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
34484 | + mutex_init(&mfs->mfs_lock); | |
34485 | + mfs->mfs_jiffy = 0; | |
34486 | + mfs->mfs_bindex = -EROFS; | |
34487 | + | |
34488 | + return 0; | |
34489 | +} | |
34490 | + | |
34491 | +static int au_wbr_create_fin_mfs(struct super_block *sb __maybe_unused) | |
34492 | +{ | |
34493 | + mutex_destroy(&au_sbi(sb)->si_wbr_mfs.mfs_lock); | |
34494 | + return 0; | |
34495 | +} | |
34496 | + | |
34497 | +/* ---------------------------------------------------------------------- */ | |
34498 | + | |
f2c43d5f AM |
34499 | +/* top down regardless parent, and then mfs */ |
34500 | +static int au_wbr_create_tdmfs(struct dentry *dentry, | |
34501 | + unsigned int flags __maybe_unused) | |
34502 | +{ | |
34503 | + int err; | |
34504 | + aufs_bindex_t bwh, btail, bindex, bfound, bmfs; | |
34505 | + unsigned long long watermark; | |
34506 | + struct super_block *sb; | |
34507 | + struct au_wbr_mfs *mfs; | |
34508 | + struct au_branch *br; | |
34509 | + struct dentry *parent; | |
34510 | + | |
34511 | + sb = dentry->d_sb; | |
34512 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
34513 | + mutex_lock(&mfs->mfs_lock); | |
34514 | + if (time_after(jiffies, mfs->mfs_jiffy + mfs->mfs_expire) | |
34515 | + || mfs->mfs_bindex < 0) | |
34516 | + au_mfs(dentry, /*parent*/NULL); | |
34517 | + watermark = mfs->mfsrr_watermark; | |
34518 | + bmfs = mfs->mfs_bindex; | |
34519 | + mutex_unlock(&mfs->mfs_lock); | |
34520 | + | |
34521 | + /* another style of au_wbr_create_exp() */ | |
34522 | + bwh = au_dbwh(dentry); | |
34523 | + parent = dget_parent(dentry); | |
34524 | + btail = au_dbtaildir(parent); | |
34525 | + if (bwh >= 0 && bwh < btail) | |
34526 | + btail = bwh; | |
34527 | + | |
34528 | + err = au_wbr_nonopq(dentry, btail); | |
34529 | + if (unlikely(err < 0)) | |
34530 | + goto out; | |
34531 | + btail = err; | |
34532 | + bfound = -1; | |
34533 | + for (bindex = 0; bindex <= btail; bindex++) { | |
34534 | + br = au_sbr(sb, bindex); | |
34535 | + if (au_br_rdonly(br)) | |
34536 | + continue; | |
34537 | + if (br->br_wbr->wbr_bytes > watermark) { | |
34538 | + bfound = bindex; | |
34539 | + break; | |
34540 | + } | |
34541 | + } | |
34542 | + err = bfound; | |
34543 | + if (err < 0) | |
34544 | + err = bmfs; | |
34545 | + | |
34546 | +out: | |
34547 | + dput(parent); | |
34548 | + AuDbg("b%d\n", err); | |
34549 | + return err; | |
34550 | +} | |
34551 | + | |
34552 | +/* ---------------------------------------------------------------------- */ | |
34553 | + | |
1facf9fc | 34554 | +/* most free space and then round robin */ |
392086de | 34555 | +static int au_wbr_create_mfsrr(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34556 | +{ |
34557 | + int err; | |
34558 | + struct au_wbr_mfs *mfs; | |
34559 | + | |
392086de | 34560 | + err = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 34561 | + if (err >= 0) { |
34562 | + mfs = &au_sbi(dentry->d_sb)->si_wbr_mfs; | |
dece6358 | 34563 | + mutex_lock(&mfs->mfs_lock); |
1facf9fc | 34564 | + if (mfs->mfsrr_bytes < mfs->mfsrr_watermark) |
392086de | 34565 | + err = au_wbr_create_rr(dentry, flags); |
dece6358 | 34566 | + mutex_unlock(&mfs->mfs_lock); |
1facf9fc | 34567 | + } |
34568 | + | |
34569 | + AuDbg("b%d\n", err); | |
34570 | + return err; | |
34571 | +} | |
34572 | + | |
34573 | +static int au_wbr_create_init_mfsrr(struct super_block *sb) | |
34574 | +{ | |
34575 | + int err; | |
34576 | + | |
34577 | + au_wbr_create_init_mfs(sb); /* ignore */ | |
34578 | + err = au_wbr_create_init_rr(sb); | |
34579 | + | |
34580 | + return err; | |
34581 | +} | |
34582 | + | |
34583 | +/* ---------------------------------------------------------------------- */ | |
34584 | + | |
34585 | +/* top down parent and most free space */ | |
392086de | 34586 | +static int au_wbr_create_pmfs(struct dentry *dentry, unsigned int flags) |
1facf9fc | 34587 | +{ |
34588 | + int err, e2; | |
34589 | + unsigned long long b; | |
5afbbe0d | 34590 | + aufs_bindex_t bindex, btop, bbot; |
1facf9fc | 34591 | + struct super_block *sb; |
34592 | + struct dentry *parent, *h_parent; | |
34593 | + struct au_branch *br; | |
34594 | + | |
392086de | 34595 | + err = au_wbr_create_tdp(dentry, flags); |
1facf9fc | 34596 | + if (unlikely(err < 0)) |
34597 | + goto out; | |
34598 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
34599 | + btop = au_dbtop(parent); |
34600 | + bbot = au_dbtaildir(parent); | |
34601 | + if (btop == bbot) | |
1facf9fc | 34602 | + goto out_parent; /* success */ |
34603 | + | |
392086de | 34604 | + e2 = au_wbr_create_mfs(dentry, flags); |
1facf9fc | 34605 | + if (e2 < 0) |
34606 | + goto out_parent; /* success */ | |
34607 | + | |
34608 | + /* when the available size is equal, select upper one */ | |
34609 | + sb = dentry->d_sb; | |
34610 | + br = au_sbr(sb, err); | |
34611 | + b = br->br_wbr->wbr_bytes; | |
34612 | + AuDbg("b%d, %llu\n", err, b); | |
34613 | + | |
5afbbe0d | 34614 | + for (bindex = btop; bindex <= bbot; bindex++) { |
1facf9fc | 34615 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 34616 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 34617 | + continue; |
34618 | + | |
34619 | + br = au_sbr(sb, bindex); | |
34620 | + if (!au_br_rdonly(br) && br->br_wbr->wbr_bytes > b) { | |
34621 | + b = br->br_wbr->wbr_bytes; | |
34622 | + err = bindex; | |
34623 | + AuDbg("b%d, %llu\n", err, b); | |
34624 | + } | |
34625 | + } | |
34626 | + | |
4a4d8108 AM |
34627 | + if (err >= 0) |
34628 | + err = au_wbr_nonopq(dentry, err); | |
34629 | + | |
4f0767ce | 34630 | +out_parent: |
1facf9fc | 34631 | + dput(parent); |
4f0767ce | 34632 | +out: |
1facf9fc | 34633 | + AuDbg("b%d\n", err); |
34634 | + return err; | |
34635 | +} | |
34636 | + | |
34637 | +/* ---------------------------------------------------------------------- */ | |
34638 | + | |
392086de AM |
34639 | +/* |
34640 | + * - top down parent | |
34641 | + * - most free space with parent | |
34642 | + * - most free space round-robin regardless parent | |
34643 | + */ | |
34644 | +static int au_wbr_create_pmfsrr(struct dentry *dentry, unsigned int flags) | |
34645 | +{ | |
34646 | + int err; | |
34647 | + unsigned long long watermark; | |
34648 | + struct super_block *sb; | |
34649 | + struct au_branch *br; | |
34650 | + struct au_wbr_mfs *mfs; | |
34651 | + | |
34652 | + err = au_wbr_create_pmfs(dentry, flags | AuWbr_PARENT); | |
34653 | + if (unlikely(err < 0)) | |
34654 | + goto out; | |
34655 | + | |
34656 | + sb = dentry->d_sb; | |
34657 | + br = au_sbr(sb, err); | |
34658 | + mfs = &au_sbi(sb)->si_wbr_mfs; | |
34659 | + mutex_lock(&mfs->mfs_lock); | |
34660 | + watermark = mfs->mfsrr_watermark; | |
34661 | + mutex_unlock(&mfs->mfs_lock); | |
34662 | + if (br->br_wbr->wbr_bytes < watermark) | |
34663 | + /* regardless the parent dir */ | |
34664 | + err = au_wbr_create_mfsrr(dentry, flags); | |
34665 | + | |
34666 | +out: | |
34667 | + AuDbg("b%d\n", err); | |
34668 | + return err; | |
34669 | +} | |
34670 | + | |
34671 | +/* ---------------------------------------------------------------------- */ | |
34672 | + | |
1facf9fc | 34673 | +/* policies for copyup */ |
34674 | + | |
34675 | +/* top down parent */ | |
34676 | +static int au_wbr_copyup_tdp(struct dentry *dentry) | |
34677 | +{ | |
392086de | 34678 | + return au_wbr_create_tdp(dentry, /*flags, anything is ok*/0); |
1facf9fc | 34679 | +} |
34680 | + | |
34681 | +/* bottom up parent */ | |
34682 | +static int au_wbr_copyup_bup(struct dentry *dentry) | |
34683 | +{ | |
34684 | + int err; | |
5afbbe0d | 34685 | + aufs_bindex_t bindex, btop; |
1facf9fc | 34686 | + struct dentry *parent, *h_parent; |
34687 | + struct super_block *sb; | |
34688 | + | |
34689 | + err = -EROFS; | |
34690 | + sb = dentry->d_sb; | |
34691 | + parent = dget_parent(dentry); | |
5afbbe0d AM |
34692 | + btop = au_dbtop(parent); |
34693 | + for (bindex = au_dbtop(dentry); bindex >= btop; bindex--) { | |
1facf9fc | 34694 | + h_parent = au_h_dptr(parent, bindex); |
5527c038 | 34695 | + if (!h_parent || d_is_negative(h_parent)) |
1facf9fc | 34696 | + continue; |
34697 | + | |
34698 | + if (!au_br_rdonly(au_sbr(sb, bindex))) { | |
34699 | + err = bindex; | |
34700 | + break; | |
34701 | + } | |
34702 | + } | |
34703 | + dput(parent); | |
34704 | + | |
34705 | + /* bottom up here */ | |
34706 | + if (unlikely(err < 0)) | |
5afbbe0d | 34707 | + err = au_wbr_bu(sb, btop - 1); |
1facf9fc | 34708 | + |
34709 | + AuDbg("b%d\n", err); | |
34710 | + return err; | |
34711 | +} | |
34712 | + | |
34713 | +/* bottom up */ | |
5afbbe0d | 34714 | +int au_wbr_do_copyup_bu(struct dentry *dentry, aufs_bindex_t btop) |
1facf9fc | 34715 | +{ |
34716 | + int err; | |
34717 | + | |
5afbbe0d | 34718 | + err = au_wbr_bu(dentry->d_sb, btop); |
4a4d8108 | 34719 | + AuDbg("b%d\n", err); |
5afbbe0d | 34720 | + if (err > btop) |
4a4d8108 | 34721 | + err = au_wbr_nonopq(dentry, err); |
1facf9fc | 34722 | + |
34723 | + AuDbg("b%d\n", err); | |
34724 | + return err; | |
34725 | +} | |
34726 | + | |
076b876e AM |
34727 | +static int au_wbr_copyup_bu(struct dentry *dentry) |
34728 | +{ | |
34729 | + int err; | |
5afbbe0d | 34730 | + aufs_bindex_t btop; |
076b876e | 34731 | + |
5afbbe0d AM |
34732 | + btop = au_dbtop(dentry); |
34733 | + err = au_wbr_do_copyup_bu(dentry, btop); | |
076b876e AM |
34734 | + return err; |
34735 | +} | |
34736 | + | |
1facf9fc | 34737 | +/* ---------------------------------------------------------------------- */ |
34738 | + | |
34739 | +struct au_wbr_copyup_operations au_wbr_copyup_ops[] = { | |
34740 | + [AuWbrCopyup_TDP] = { | |
34741 | + .copyup = au_wbr_copyup_tdp | |
34742 | + }, | |
34743 | + [AuWbrCopyup_BUP] = { | |
34744 | + .copyup = au_wbr_copyup_bup | |
34745 | + }, | |
34746 | + [AuWbrCopyup_BU] = { | |
34747 | + .copyup = au_wbr_copyup_bu | |
34748 | + } | |
34749 | +}; | |
34750 | + | |
34751 | +struct au_wbr_create_operations au_wbr_create_ops[] = { | |
34752 | + [AuWbrCreate_TDP] = { | |
34753 | + .create = au_wbr_create_tdp | |
34754 | + }, | |
34755 | + [AuWbrCreate_RR] = { | |
34756 | + .create = au_wbr_create_rr, | |
34757 | + .init = au_wbr_create_init_rr | |
34758 | + }, | |
34759 | + [AuWbrCreate_MFS] = { | |
34760 | + .create = au_wbr_create_mfs, | |
34761 | + .init = au_wbr_create_init_mfs, | |
34762 | + .fin = au_wbr_create_fin_mfs | |
34763 | + }, | |
34764 | + [AuWbrCreate_MFSV] = { | |
34765 | + .create = au_wbr_create_mfs, | |
34766 | + .init = au_wbr_create_init_mfs, | |
34767 | + .fin = au_wbr_create_fin_mfs | |
34768 | + }, | |
34769 | + [AuWbrCreate_MFSRR] = { | |
34770 | + .create = au_wbr_create_mfsrr, | |
34771 | + .init = au_wbr_create_init_mfsrr, | |
34772 | + .fin = au_wbr_create_fin_mfs | |
34773 | + }, | |
34774 | + [AuWbrCreate_MFSRRV] = { | |
34775 | + .create = au_wbr_create_mfsrr, | |
34776 | + .init = au_wbr_create_init_mfsrr, | |
34777 | + .fin = au_wbr_create_fin_mfs | |
34778 | + }, | |
f2c43d5f AM |
34779 | + [AuWbrCreate_TDMFS] = { |
34780 | + .create = au_wbr_create_tdmfs, | |
34781 | + .init = au_wbr_create_init_mfs, | |
34782 | + .fin = au_wbr_create_fin_mfs | |
34783 | + }, | |
34784 | + [AuWbrCreate_TDMFSV] = { | |
34785 | + .create = au_wbr_create_tdmfs, | |
34786 | + .init = au_wbr_create_init_mfs, | |
34787 | + .fin = au_wbr_create_fin_mfs | |
34788 | + }, | |
1facf9fc | 34789 | + [AuWbrCreate_PMFS] = { |
34790 | + .create = au_wbr_create_pmfs, | |
34791 | + .init = au_wbr_create_init_mfs, | |
34792 | + .fin = au_wbr_create_fin_mfs | |
34793 | + }, | |
34794 | + [AuWbrCreate_PMFSV] = { | |
34795 | + .create = au_wbr_create_pmfs, | |
34796 | + .init = au_wbr_create_init_mfs, | |
34797 | + .fin = au_wbr_create_fin_mfs | |
392086de AM |
34798 | + }, |
34799 | + [AuWbrCreate_PMFSRR] = { | |
34800 | + .create = au_wbr_create_pmfsrr, | |
34801 | + .init = au_wbr_create_init_mfsrr, | |
34802 | + .fin = au_wbr_create_fin_mfs | |
34803 | + }, | |
34804 | + [AuWbrCreate_PMFSRRV] = { | |
34805 | + .create = au_wbr_create_pmfsrr, | |
34806 | + .init = au_wbr_create_init_mfsrr, | |
34807 | + .fin = au_wbr_create_fin_mfs | |
1facf9fc | 34808 | + } |
34809 | +}; | |
7f207e10 | 34810 | diff -urN /usr/share/empty/fs/aufs/whout.c linux/fs/aufs/whout.c |
eca34b5c | 34811 | --- /usr/share/empty/fs/aufs/whout.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 34812 | +++ linux/fs/aufs/whout.c 2020-01-27 10:57:18.178871751 +0100 |
062440b3 | 34813 | @@ -0,0 +1,1062 @@ |
cd7a4cd9 | 34814 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 34815 | +/* |
d58c55f2 | 34816 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 34817 | + * |
34818 | + * This program, aufs is free software; you can redistribute it and/or modify | |
34819 | + * it under the terms of the GNU General Public License as published by | |
34820 | + * the Free Software Foundation; either version 2 of the License, or | |
34821 | + * (at your option) any later version. | |
dece6358 AM |
34822 | + * |
34823 | + * This program is distributed in the hope that it will be useful, | |
34824 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
34825 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34826 | + * GNU General Public License for more details. | |
34827 | + * | |
34828 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 34829 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 34830 | + */ |
34831 | + | |
34832 | +/* | |
34833 | + * whiteout for logical deletion and opaque directory | |
34834 | + */ | |
34835 | + | |
1facf9fc | 34836 | +#include "aufs.h" |
34837 | + | |
cd7a4cd9 | 34838 | +#define WH_MASK 0444 |
1facf9fc | 34839 | + |
34840 | +/* | |
34841 | + * If a directory contains this file, then it is opaque. We start with the | |
34842 | + * .wh. flag so that it is blocked by lookup. | |
34843 | + */ | |
0c3ec466 AM |
34844 | +static struct qstr diropq_name = QSTR_INIT(AUFS_WH_DIROPQ, |
34845 | + sizeof(AUFS_WH_DIROPQ) - 1); | |
1facf9fc | 34846 | + |
34847 | +/* | |
34848 | + * generate whiteout name, which is NOT terminated by NULL. | |
34849 | + * @name: original d_name.name | |
34850 | + * @len: original d_name.len | |
34851 | + * @wh: whiteout qstr | |
34852 | + * returns zero when succeeds, otherwise error. | |
34853 | + * succeeded value as wh->name should be freed by kfree(). | |
34854 | + */ | |
34855 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name) | |
34856 | +{ | |
34857 | + char *p; | |
34858 | + | |
34859 | + if (unlikely(name->len > PATH_MAX - AUFS_WH_PFX_LEN)) | |
34860 | + return -ENAMETOOLONG; | |
34861 | + | |
34862 | + wh->len = name->len + AUFS_WH_PFX_LEN; | |
34863 | + p = kmalloc(wh->len, GFP_NOFS); | |
34864 | + wh->name = p; | |
34865 | + if (p) { | |
34866 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
34867 | + memcpy(p + AUFS_WH_PFX_LEN, name->name, name->len); | |
34868 | + /* smp_mb(); */ | |
34869 | + return 0; | |
34870 | + } | |
34871 | + return -ENOMEM; | |
34872 | +} | |
34873 | + | |
34874 | +/* ---------------------------------------------------------------------- */ | |
34875 | + | |
34876 | +/* | |
34877 | + * test if the @wh_name exists under @h_parent. | |
34878 | + * @try_sio specifies the necessary of super-io. | |
34879 | + */ | |
076b876e | 34880 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio) |
1facf9fc | 34881 | +{ |
34882 | + int err; | |
34883 | + struct dentry *wh_dentry; | |
1facf9fc | 34884 | + |
1facf9fc | 34885 | + if (!try_sio) |
b4510431 | 34886 | + wh_dentry = vfsub_lkup_one(wh_name, h_parent); |
1facf9fc | 34887 | + else |
076b876e | 34888 | + wh_dentry = au_sio_lkup_one(wh_name, h_parent); |
1facf9fc | 34889 | + err = PTR_ERR(wh_dentry); |
2000de60 JR |
34890 | + if (IS_ERR(wh_dentry)) { |
34891 | + if (err == -ENAMETOOLONG) | |
34892 | + err = 0; | |
1facf9fc | 34893 | + goto out; |
2000de60 | 34894 | + } |
1facf9fc | 34895 | + |
34896 | + err = 0; | |
5527c038 | 34897 | + if (d_is_negative(wh_dentry)) |
1facf9fc | 34898 | + goto out_wh; /* success */ |
34899 | + | |
34900 | + err = 1; | |
7e9cd9fe | 34901 | + if (d_is_reg(wh_dentry)) |
1facf9fc | 34902 | + goto out_wh; /* success */ |
34903 | + | |
34904 | + err = -EIO; | |
523b37e3 | 34905 | + AuIOErr("%pd Invalid whiteout entry type 0%o.\n", |
5527c038 | 34906 | + wh_dentry, d_inode(wh_dentry)->i_mode); |
1facf9fc | 34907 | + |
4f0767ce | 34908 | +out_wh: |
1facf9fc | 34909 | + dput(wh_dentry); |
4f0767ce | 34910 | +out: |
1facf9fc | 34911 | + return err; |
34912 | +} | |
34913 | + | |
34914 | +/* | |
34915 | + * test if the @h_dentry sets opaque or not. | |
34916 | + */ | |
076b876e | 34917 | +int au_diropq_test(struct dentry *h_dentry) |
1facf9fc | 34918 | +{ |
34919 | + int err; | |
34920 | + struct inode *h_dir; | |
34921 | + | |
5527c038 | 34922 | + h_dir = d_inode(h_dentry); |
076b876e | 34923 | + err = au_wh_test(h_dentry, &diropq_name, |
1facf9fc | 34924 | + au_test_h_perm_sio(h_dir, MAY_EXEC)); |
34925 | + return err; | |
34926 | +} | |
34927 | + | |
34928 | +/* | |
34929 | + * returns a negative dentry whose name is unique and temporary. | |
34930 | + */ | |
34931 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, | |
34932 | + struct qstr *prefix) | |
34933 | +{ | |
1facf9fc | 34934 | + struct dentry *dentry; |
34935 | + int i; | |
027c5e7a | 34936 | + char defname[NAME_MAX - AUFS_MAX_NAMELEN + DNAME_INLINE_LEN + 1], |
4a4d8108 | 34937 | + *name, *p; |
027c5e7a | 34938 | + /* strict atomic_t is unnecessary here */ |
1facf9fc | 34939 | + static unsigned short cnt; |
34940 | + struct qstr qs; | |
34941 | + | |
4a4d8108 AM |
34942 | + BUILD_BUG_ON(sizeof(cnt) * 2 > AUFS_WH_TMP_LEN); |
34943 | + | |
1facf9fc | 34944 | + name = defname; |
027c5e7a AM |
34945 | + qs.len = sizeof(defname) - DNAME_INLINE_LEN + prefix->len - 1; |
34946 | + if (unlikely(prefix->len > DNAME_INLINE_LEN)) { | |
1facf9fc | 34947 | + dentry = ERR_PTR(-ENAMETOOLONG); |
4a4d8108 | 34948 | + if (unlikely(qs.len > NAME_MAX)) |
1facf9fc | 34949 | + goto out; |
34950 | + dentry = ERR_PTR(-ENOMEM); | |
34951 | + name = kmalloc(qs.len + 1, GFP_NOFS); | |
34952 | + if (unlikely(!name)) | |
34953 | + goto out; | |
34954 | + } | |
34955 | + | |
34956 | + /* doubly whiteout-ed */ | |
34957 | + memcpy(name, AUFS_WH_PFX AUFS_WH_PFX, AUFS_WH_PFX_LEN * 2); | |
34958 | + p = name + AUFS_WH_PFX_LEN * 2; | |
34959 | + memcpy(p, prefix->name, prefix->len); | |
34960 | + p += prefix->len; | |
34961 | + *p++ = '.'; | |
4a4d8108 | 34962 | + AuDebugOn(name + qs.len + 1 - p <= AUFS_WH_TMP_LEN); |
1facf9fc | 34963 | + |
34964 | + qs.name = name; | |
34965 | + for (i = 0; i < 3; i++) { | |
b752ccd1 | 34966 | + sprintf(p, "%.*x", AUFS_WH_TMP_LEN, cnt++); |
076b876e | 34967 | + dentry = au_sio_lkup_one(&qs, h_parent); |
5527c038 | 34968 | + if (IS_ERR(dentry) || d_is_negative(dentry)) |
1facf9fc | 34969 | + goto out_name; |
34970 | + dput(dentry); | |
34971 | + } | |
0c3ec466 | 34972 | + /* pr_warn("could not get random name\n"); */ |
1facf9fc | 34973 | + dentry = ERR_PTR(-EEXIST); |
34974 | + AuDbg("%.*s\n", AuLNPair(&qs)); | |
34975 | + BUG(); | |
34976 | + | |
4f0767ce | 34977 | +out_name: |
1facf9fc | 34978 | + if (name != defname) |
9f237c51 | 34979 | + au_kfree_try_rcu(name); |
4f0767ce | 34980 | +out: |
4a4d8108 | 34981 | + AuTraceErrPtr(dentry); |
1facf9fc | 34982 | + return dentry; |
1facf9fc | 34983 | +} |
34984 | + | |
34985 | +/* | |
34986 | + * rename the @h_dentry on @br to the whiteouted temporary name. | |
34987 | + */ | |
34988 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br) | |
34989 | +{ | |
34990 | + int err; | |
34991 | + struct path h_path = { | |
86dc4139 | 34992 | + .mnt = au_br_mnt(br) |
1facf9fc | 34993 | + }; |
523b37e3 | 34994 | + struct inode *h_dir, *delegated; |
1facf9fc | 34995 | + struct dentry *h_parent; |
34996 | + | |
34997 | + h_parent = h_dentry->d_parent; /* dir inode is locked */ | |
5527c038 | 34998 | + h_dir = d_inode(h_parent); |
1facf9fc | 34999 | + IMustLock(h_dir); |
35000 | + | |
35001 | + h_path.dentry = au_whtmp_lkup(h_parent, br, &h_dentry->d_name); | |
35002 | + err = PTR_ERR(h_path.dentry); | |
35003 | + if (IS_ERR(h_path.dentry)) | |
35004 | + goto out; | |
35005 | + | |
35006 | + /* under the same dir, no need to lock_rename() */ | |
523b37e3 | 35007 | + delegated = NULL; |
f2c43d5f AM |
35008 | + err = vfsub_rename(h_dir, h_dentry, h_dir, &h_path, &delegated, |
35009 | + /*flags*/0); | |
1facf9fc | 35010 | + AuTraceErr(err); |
523b37e3 AM |
35011 | + if (unlikely(err == -EWOULDBLOCK)) { |
35012 | + pr_warn("cannot retry for NFSv4 delegation" | |
35013 | + " for an internal rename\n"); | |
35014 | + iput(delegated); | |
35015 | + } | |
1facf9fc | 35016 | + dput(h_path.dentry); |
35017 | + | |
4f0767ce | 35018 | +out: |
4a4d8108 | 35019 | + AuTraceErr(err); |
1facf9fc | 35020 | + return err; |
35021 | +} | |
35022 | + | |
35023 | +/* ---------------------------------------------------------------------- */ | |
35024 | +/* | |
35025 | + * functions for removing a whiteout | |
35026 | + */ | |
35027 | + | |
35028 | +static int do_unlink_wh(struct inode *h_dir, struct path *h_path) | |
35029 | +{ | |
523b37e3 AM |
35030 | + int err, force; |
35031 | + struct inode *delegated; | |
1facf9fc | 35032 | + |
35033 | + /* | |
35034 | + * forces superio when the dir has a sticky bit. | |
35035 | + * this may be a violation of unix fs semantics. | |
35036 | + */ | |
35037 | + force = (h_dir->i_mode & S_ISVTX) | |
5527c038 | 35038 | + && !uid_eq(current_fsuid(), d_inode(h_path->dentry)->i_uid); |
523b37e3 AM |
35039 | + delegated = NULL; |
35040 | + err = vfsub_unlink(h_dir, h_path, &delegated, force); | |
35041 | + if (unlikely(err == -EWOULDBLOCK)) { | |
35042 | + pr_warn("cannot retry for NFSv4 delegation" | |
35043 | + " for an internal unlink\n"); | |
35044 | + iput(delegated); | |
35045 | + } | |
35046 | + return err; | |
1facf9fc | 35047 | +} |
35048 | + | |
35049 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
35050 | + struct dentry *dentry) | |
35051 | +{ | |
35052 | + int err; | |
35053 | + | |
35054 | + err = do_unlink_wh(h_dir, h_path); | |
35055 | + if (!err && dentry) | |
35056 | + au_set_dbwh(dentry, -1); | |
35057 | + | |
35058 | + return err; | |
35059 | +} | |
35060 | + | |
35061 | +static int unlink_wh_name(struct dentry *h_parent, struct qstr *wh, | |
35062 | + struct au_branch *br) | |
35063 | +{ | |
35064 | + int err; | |
35065 | + struct path h_path = { | |
86dc4139 | 35066 | + .mnt = au_br_mnt(br) |
1facf9fc | 35067 | + }; |
35068 | + | |
35069 | + err = 0; | |
b4510431 | 35070 | + h_path.dentry = vfsub_lkup_one(wh, h_parent); |
1facf9fc | 35071 | + if (IS_ERR(h_path.dentry)) |
35072 | + err = PTR_ERR(h_path.dentry); | |
35073 | + else { | |
5527c038 JR |
35074 | + if (d_is_reg(h_path.dentry)) |
35075 | + err = do_unlink_wh(d_inode(h_parent), &h_path); | |
1facf9fc | 35076 | + dput(h_path.dentry); |
35077 | + } | |
35078 | + | |
35079 | + return err; | |
35080 | +} | |
35081 | + | |
35082 | +/* ---------------------------------------------------------------------- */ | |
35083 | +/* | |
35084 | + * initialize/clean whiteout for a branch | |
35085 | + */ | |
35086 | + | |
35087 | +static void au_wh_clean(struct inode *h_dir, struct path *whpath, | |
35088 | + const int isdir) | |
35089 | +{ | |
35090 | + int err; | |
523b37e3 | 35091 | + struct inode *delegated; |
1facf9fc | 35092 | + |
5527c038 | 35093 | + if (d_is_negative(whpath->dentry)) |
1facf9fc | 35094 | + return; |
35095 | + | |
86dc4139 AM |
35096 | + if (isdir) |
35097 | + err = vfsub_rmdir(h_dir, whpath); | |
523b37e3 AM |
35098 | + else { |
35099 | + delegated = NULL; | |
35100 | + err = vfsub_unlink(h_dir, whpath, &delegated, /*force*/0); | |
35101 | + if (unlikely(err == -EWOULDBLOCK)) { | |
35102 | + pr_warn("cannot retry for NFSv4 delegation" | |
35103 | + " for an internal unlink\n"); | |
35104 | + iput(delegated); | |
35105 | + } | |
35106 | + } | |
1facf9fc | 35107 | + if (unlikely(err)) |
523b37e3 AM |
35108 | + pr_warn("failed removing %pd (%d), ignored.\n", |
35109 | + whpath->dentry, err); | |
1facf9fc | 35110 | +} |
35111 | + | |
35112 | +static int test_linkable(struct dentry *h_root) | |
35113 | +{ | |
5527c038 | 35114 | + struct inode *h_dir = d_inode(h_root); |
1facf9fc | 35115 | + |
35116 | + if (h_dir->i_op->link) | |
35117 | + return 0; | |
35118 | + | |
523b37e3 AM |
35119 | + pr_err("%pd (%s) doesn't support link(2), use noplink and rw+nolwh\n", |
35120 | + h_root, au_sbtype(h_root->d_sb)); | |
43982f53 | 35121 | + return -ENOSYS; /* the branch doesn't have its ->link() */ |
1facf9fc | 35122 | +} |
35123 | + | |
35124 | +/* todo: should this mkdir be done in /sbin/mount.aufs helper? */ | |
35125 | +static int au_whdir(struct inode *h_dir, struct path *path) | |
35126 | +{ | |
35127 | + int err; | |
35128 | + | |
35129 | + err = -EEXIST; | |
5527c038 | 35130 | + if (d_is_negative(path->dentry)) { |
cd7a4cd9 | 35131 | + int mode = 0700; |
1facf9fc | 35132 | + |
35133 | + if (au_test_nfs(path->dentry->d_sb)) | |
cd7a4cd9 | 35134 | + mode |= 0111; |
86dc4139 | 35135 | + err = vfsub_mkdir(h_dir, path, mode); |
2000de60 | 35136 | + } else if (d_is_dir(path->dentry)) |
1facf9fc | 35137 | + err = 0; |
35138 | + else | |
523b37e3 | 35139 | + pr_err("unknown %pd exists\n", path->dentry); |
1facf9fc | 35140 | + |
35141 | + return err; | |
35142 | +} | |
35143 | + | |
35144 | +struct au_wh_base { | |
35145 | + const struct qstr *name; | |
35146 | + struct dentry *dentry; | |
35147 | +}; | |
35148 | + | |
35149 | +static void au_wh_init_ro(struct inode *h_dir, struct au_wh_base base[], | |
35150 | + struct path *h_path) | |
35151 | +{ | |
35152 | + h_path->dentry = base[AuBrWh_BASE].dentry; | |
35153 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
35154 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
35155 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
35156 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
35157 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
35158 | +} | |
35159 | + | |
35160 | +/* | |
35161 | + * returns tri-state, | |
c1595e42 | 35162 | + * minus: error, caller should print the message |
acd2b654 | 35163 | + * zero: success |
c1595e42 | 35164 | + * plus: error, caller should NOT print the message |
1facf9fc | 35165 | + */ |
35166 | +static int au_wh_init_rw_nolink(struct dentry *h_root, struct au_wbr *wbr, | |
35167 | + int do_plink, struct au_wh_base base[], | |
35168 | + struct path *h_path) | |
35169 | +{ | |
35170 | + int err; | |
35171 | + struct inode *h_dir; | |
35172 | + | |
5527c038 | 35173 | + h_dir = d_inode(h_root); |
1facf9fc | 35174 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
35175 | + au_wh_clean(h_dir, h_path, /*isdir*/0); | |
35176 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
35177 | + if (do_plink) { | |
35178 | + err = test_linkable(h_root); | |
35179 | + if (unlikely(err)) { | |
35180 | + err = 1; | |
35181 | + goto out; | |
35182 | + } | |
35183 | + | |
35184 | + err = au_whdir(h_dir, h_path); | |
35185 | + if (unlikely(err)) | |
35186 | + goto out; | |
35187 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
35188 | + } else | |
35189 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
35190 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
35191 | + err = au_whdir(h_dir, h_path); | |
35192 | + if (unlikely(err)) | |
35193 | + goto out; | |
35194 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
35195 | + | |
4f0767ce | 35196 | +out: |
1facf9fc | 35197 | + return err; |
35198 | +} | |
35199 | + | |
35200 | +/* | |
35201 | + * for the moment, aufs supports the branch filesystem which does not support | |
35202 | + * link(2). testing on FAT which does not support i_op->setattr() fully either, | |
35203 | + * copyup failed. finally, such filesystem will not be used as the writable | |
35204 | + * branch. | |
35205 | + * | |
35206 | + * returns tri-state, see above. | |
35207 | + */ | |
35208 | +static int au_wh_init_rw(struct dentry *h_root, struct au_wbr *wbr, | |
35209 | + int do_plink, struct au_wh_base base[], | |
35210 | + struct path *h_path) | |
35211 | +{ | |
35212 | + int err; | |
35213 | + struct inode *h_dir; | |
35214 | + | |
1308ab2a | 35215 | + WbrWhMustWriteLock(wbr); |
35216 | + | |
1facf9fc | 35217 | + err = test_linkable(h_root); |
35218 | + if (unlikely(err)) { | |
35219 | + err = 1; | |
35220 | + goto out; | |
35221 | + } | |
35222 | + | |
35223 | + /* | |
35224 | + * todo: should this create be done in /sbin/mount.aufs helper? | |
35225 | + */ | |
35226 | + err = -EEXIST; | |
5527c038 JR |
35227 | + h_dir = d_inode(h_root); |
35228 | + if (d_is_negative(base[AuBrWh_BASE].dentry)) { | |
86dc4139 AM |
35229 | + h_path->dentry = base[AuBrWh_BASE].dentry; |
35230 | + err = vfsub_create(h_dir, h_path, WH_MASK, /*want_excl*/true); | |
7e9cd9fe | 35231 | + } else if (d_is_reg(base[AuBrWh_BASE].dentry)) |
1facf9fc | 35232 | + err = 0; |
35233 | + else | |
523b37e3 | 35234 | + pr_err("unknown %pd2 exists\n", base[AuBrWh_BASE].dentry); |
1facf9fc | 35235 | + if (unlikely(err)) |
35236 | + goto out; | |
35237 | + | |
35238 | + h_path->dentry = base[AuBrWh_PLINK].dentry; | |
35239 | + if (do_plink) { | |
35240 | + err = au_whdir(h_dir, h_path); | |
35241 | + if (unlikely(err)) | |
35242 | + goto out; | |
35243 | + wbr->wbr_plink = dget(base[AuBrWh_PLINK].dentry); | |
35244 | + } else | |
35245 | + au_wh_clean(h_dir, h_path, /*isdir*/1); | |
35246 | + wbr->wbr_whbase = dget(base[AuBrWh_BASE].dentry); | |
35247 | + | |
35248 | + h_path->dentry = base[AuBrWh_ORPH].dentry; | |
35249 | + err = au_whdir(h_dir, h_path); | |
35250 | + if (unlikely(err)) | |
35251 | + goto out; | |
35252 | + wbr->wbr_orph = dget(base[AuBrWh_ORPH].dentry); | |
35253 | + | |
4f0767ce | 35254 | +out: |
1facf9fc | 35255 | + return err; |
35256 | +} | |
35257 | + | |
35258 | +/* | |
35259 | + * initialize the whiteout base file/dir for @br. | |
35260 | + */ | |
86dc4139 | 35261 | +int au_wh_init(struct au_branch *br, struct super_block *sb) |
1facf9fc | 35262 | +{ |
35263 | + int err, i; | |
35264 | + const unsigned char do_plink | |
35265 | + = !!au_opt_test(au_mntflags(sb), PLINK); | |
1facf9fc | 35266 | + struct inode *h_dir; |
86dc4139 AM |
35267 | + struct path path = br->br_path; |
35268 | + struct dentry *h_root = path.dentry; | |
1facf9fc | 35269 | + struct au_wbr *wbr = br->br_wbr; |
35270 | + static const struct qstr base_name[] = { | |
0c3ec466 AM |
35271 | + [AuBrWh_BASE] = QSTR_INIT(AUFS_BASE_NAME, |
35272 | + sizeof(AUFS_BASE_NAME) - 1), | |
35273 | + [AuBrWh_PLINK] = QSTR_INIT(AUFS_PLINKDIR_NAME, | |
35274 | + sizeof(AUFS_PLINKDIR_NAME) - 1), | |
35275 | + [AuBrWh_ORPH] = QSTR_INIT(AUFS_ORPHDIR_NAME, | |
35276 | + sizeof(AUFS_ORPHDIR_NAME) - 1) | |
1facf9fc | 35277 | + }; |
35278 | + struct au_wh_base base[] = { | |
35279 | + [AuBrWh_BASE] = { | |
35280 | + .name = base_name + AuBrWh_BASE, | |
35281 | + .dentry = NULL | |
35282 | + }, | |
35283 | + [AuBrWh_PLINK] = { | |
35284 | + .name = base_name + AuBrWh_PLINK, | |
35285 | + .dentry = NULL | |
35286 | + }, | |
35287 | + [AuBrWh_ORPH] = { | |
35288 | + .name = base_name + AuBrWh_ORPH, | |
35289 | + .dentry = NULL | |
35290 | + } | |
35291 | + }; | |
35292 | + | |
1308ab2a | 35293 | + if (wbr) |
35294 | + WbrWhMustWriteLock(wbr); | |
1facf9fc | 35295 | + |
1facf9fc | 35296 | + for (i = 0; i < AuBrWh_Last; i++) { |
35297 | + /* doubly whiteouted */ | |
35298 | + struct dentry *d; | |
35299 | + | |
35300 | + d = au_wh_lkup(h_root, (void *)base[i].name, br); | |
35301 | + err = PTR_ERR(d); | |
35302 | + if (IS_ERR(d)) | |
35303 | + goto out; | |
35304 | + | |
35305 | + base[i].dentry = d; | |
35306 | + AuDebugOn(wbr | |
35307 | + && wbr->wbr_wh[i] | |
35308 | + && wbr->wbr_wh[i] != base[i].dentry); | |
35309 | + } | |
35310 | + | |
35311 | + if (wbr) | |
35312 | + for (i = 0; i < AuBrWh_Last; i++) { | |
35313 | + dput(wbr->wbr_wh[i]); | |
35314 | + wbr->wbr_wh[i] = NULL; | |
35315 | + } | |
35316 | + | |
35317 | + err = 0; | |
1e00d052 | 35318 | + if (!au_br_writable(br->br_perm)) { |
5527c038 | 35319 | + h_dir = d_inode(h_root); |
1facf9fc | 35320 | + au_wh_init_ro(h_dir, base, &path); |
1e00d052 | 35321 | + } else if (!au_br_wh_linkable(br->br_perm)) { |
1facf9fc | 35322 | + err = au_wh_init_rw_nolink(h_root, wbr, do_plink, base, &path); |
35323 | + if (err > 0) | |
35324 | + goto out; | |
35325 | + else if (err) | |
35326 | + goto out_err; | |
1e00d052 | 35327 | + } else { |
1facf9fc | 35328 | + err = au_wh_init_rw(h_root, wbr, do_plink, base, &path); |
35329 | + if (err > 0) | |
35330 | + goto out; | |
35331 | + else if (err) | |
35332 | + goto out_err; | |
1facf9fc | 35333 | + } |
35334 | + goto out; /* success */ | |
35335 | + | |
4f0767ce | 35336 | +out_err: |
523b37e3 AM |
35337 | + pr_err("an error(%d) on the writable branch %pd(%s)\n", |
35338 | + err, h_root, au_sbtype(h_root->d_sb)); | |
4f0767ce | 35339 | +out: |
1facf9fc | 35340 | + for (i = 0; i < AuBrWh_Last; i++) |
35341 | + dput(base[i].dentry); | |
35342 | + return err; | |
35343 | +} | |
35344 | + | |
35345 | +/* ---------------------------------------------------------------------- */ | |
35346 | +/* | |
35347 | + * whiteouts are all hard-linked usually. | |
35348 | + * when its link count reaches a ceiling, we create a new whiteout base | |
35349 | + * asynchronously. | |
35350 | + */ | |
35351 | + | |
35352 | +struct reinit_br_wh { | |
35353 | + struct super_block *sb; | |
35354 | + struct au_branch *br; | |
35355 | +}; | |
35356 | + | |
35357 | +static void reinit_br_wh(void *arg) | |
35358 | +{ | |
35359 | + int err; | |
35360 | + aufs_bindex_t bindex; | |
35361 | + struct path h_path; | |
35362 | + struct reinit_br_wh *a = arg; | |
35363 | + struct au_wbr *wbr; | |
523b37e3 | 35364 | + struct inode *dir, *delegated; |
1facf9fc | 35365 | + struct dentry *h_root; |
35366 | + struct au_hinode *hdir; | |
35367 | + | |
35368 | + err = 0; | |
35369 | + wbr = a->br->br_wbr; | |
35370 | + /* big aufs lock */ | |
35371 | + si_noflush_write_lock(a->sb); | |
35372 | + if (!au_br_writable(a->br->br_perm)) | |
35373 | + goto out; | |
35374 | + bindex = au_br_index(a->sb, a->br->br_id); | |
35375 | + if (unlikely(bindex < 0)) | |
35376 | + goto out; | |
35377 | + | |
1308ab2a | 35378 | + di_read_lock_parent(a->sb->s_root, AuLock_IR); |
5527c038 | 35379 | + dir = d_inode(a->sb->s_root); |
1facf9fc | 35380 | + hdir = au_hi(dir, bindex); |
35381 | + h_root = au_h_dptr(a->sb->s_root, bindex); | |
86dc4139 | 35382 | + AuDebugOn(h_root != au_br_dentry(a->br)); |
1facf9fc | 35383 | + |
5afbbe0d | 35384 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
1facf9fc | 35385 | + wbr_wh_write_lock(wbr); |
35386 | + err = au_h_verify(wbr->wbr_whbase, au_opt_udba(a->sb), hdir->hi_inode, | |
35387 | + h_root, a->br); | |
35388 | + if (!err) { | |
86dc4139 AM |
35389 | + h_path.dentry = wbr->wbr_whbase; |
35390 | + h_path.mnt = au_br_mnt(a->br); | |
523b37e3 AM |
35391 | + delegated = NULL; |
35392 | + err = vfsub_unlink(hdir->hi_inode, &h_path, &delegated, | |
35393 | + /*force*/0); | |
35394 | + if (unlikely(err == -EWOULDBLOCK)) { | |
35395 | + pr_warn("cannot retry for NFSv4 delegation" | |
35396 | + " for an internal unlink\n"); | |
35397 | + iput(delegated); | |
35398 | + } | |
1facf9fc | 35399 | + } else { |
523b37e3 | 35400 | + pr_warn("%pd is moved, ignored\n", wbr->wbr_whbase); |
1facf9fc | 35401 | + err = 0; |
35402 | + } | |
35403 | + dput(wbr->wbr_whbase); | |
35404 | + wbr->wbr_whbase = NULL; | |
35405 | + if (!err) | |
86dc4139 | 35406 | + err = au_wh_init(a->br, a->sb); |
1facf9fc | 35407 | + wbr_wh_write_unlock(wbr); |
5afbbe0d | 35408 | + au_hn_inode_unlock(hdir); |
1308ab2a | 35409 | + di_read_unlock(a->sb->s_root, AuLock_IR); |
076b876e AM |
35410 | + if (!err) |
35411 | + au_fhsm_wrote(a->sb, bindex, /*force*/0); | |
1facf9fc | 35412 | + |
4f0767ce | 35413 | +out: |
1facf9fc | 35414 | + if (wbr) |
35415 | + atomic_dec(&wbr->wbr_wh_running); | |
acd2b654 | 35416 | + au_lcnt_dec(&a->br->br_count); |
1facf9fc | 35417 | + si_write_unlock(a->sb); |
027c5e7a | 35418 | + au_nwt_done(&au_sbi(a->sb)->si_nowait); |
9f237c51 | 35419 | + au_kfree_rcu(a); |
1facf9fc | 35420 | + if (unlikely(err)) |
35421 | + AuIOErr("err %d\n", err); | |
35422 | +} | |
35423 | + | |
35424 | +static void kick_reinit_br_wh(struct super_block *sb, struct au_branch *br) | |
35425 | +{ | |
35426 | + int do_dec, wkq_err; | |
35427 | + struct reinit_br_wh *arg; | |
35428 | + | |
35429 | + do_dec = 1; | |
35430 | + if (atomic_inc_return(&br->br_wbr->wbr_wh_running) != 1) | |
35431 | + goto out; | |
35432 | + | |
35433 | + /* ignore ENOMEM */ | |
35434 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
35435 | + if (arg) { | |
35436 | + /* | |
35437 | + * dec(wh_running), kfree(arg) and dec(br_count) | |
35438 | + * in reinit function | |
35439 | + */ | |
35440 | + arg->sb = sb; | |
35441 | + arg->br = br; | |
acd2b654 | 35442 | + au_lcnt_inc(&br->br_count); |
53392da6 | 35443 | + wkq_err = au_wkq_nowait(reinit_br_wh, arg, sb, /*flags*/0); |
1facf9fc | 35444 | + if (unlikely(wkq_err)) { |
35445 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
acd2b654 | 35446 | + au_lcnt_dec(&br->br_count); |
9f237c51 | 35447 | + au_kfree_rcu(arg); |
1facf9fc | 35448 | + } |
35449 | + do_dec = 0; | |
35450 | + } | |
35451 | + | |
4f0767ce | 35452 | +out: |
1facf9fc | 35453 | + if (do_dec) |
35454 | + atomic_dec(&br->br_wbr->wbr_wh_running); | |
35455 | +} | |
35456 | + | |
35457 | +/* ---------------------------------------------------------------------- */ | |
35458 | + | |
35459 | +/* | |
35460 | + * create the whiteout @wh. | |
35461 | + */ | |
35462 | +static int link_or_create_wh(struct super_block *sb, aufs_bindex_t bindex, | |
35463 | + struct dentry *wh) | |
35464 | +{ | |
35465 | + int err; | |
35466 | + struct path h_path = { | |
35467 | + .dentry = wh | |
35468 | + }; | |
35469 | + struct au_branch *br; | |
35470 | + struct au_wbr *wbr; | |
35471 | + struct dentry *h_parent; | |
523b37e3 | 35472 | + struct inode *h_dir, *delegated; |
1facf9fc | 35473 | + |
35474 | + h_parent = wh->d_parent; /* dir inode is locked */ | |
5527c038 | 35475 | + h_dir = d_inode(h_parent); |
1facf9fc | 35476 | + IMustLock(h_dir); |
35477 | + | |
35478 | + br = au_sbr(sb, bindex); | |
86dc4139 | 35479 | + h_path.mnt = au_br_mnt(br); |
1facf9fc | 35480 | + wbr = br->br_wbr; |
35481 | + wbr_wh_read_lock(wbr); | |
35482 | + if (wbr->wbr_whbase) { | |
523b37e3 AM |
35483 | + delegated = NULL; |
35484 | + err = vfsub_link(wbr->wbr_whbase, h_dir, &h_path, &delegated); | |
35485 | + if (unlikely(err == -EWOULDBLOCK)) { | |
35486 | + pr_warn("cannot retry for NFSv4 delegation" | |
35487 | + " for an internal link\n"); | |
35488 | + iput(delegated); | |
35489 | + } | |
1facf9fc | 35490 | + if (!err || err != -EMLINK) |
35491 | + goto out; | |
35492 | + | |
35493 | + /* link count full. re-initialize br_whbase. */ | |
35494 | + kick_reinit_br_wh(sb, br); | |
35495 | + } | |
35496 | + | |
35497 | + /* return this error in this context */ | |
b4510431 | 35498 | + err = vfsub_create(h_dir, &h_path, WH_MASK, /*want_excl*/true); |
076b876e AM |
35499 | + if (!err) |
35500 | + au_fhsm_wrote(sb, bindex, /*force*/0); | |
1facf9fc | 35501 | + |
4f0767ce | 35502 | +out: |
1facf9fc | 35503 | + wbr_wh_read_unlock(wbr); |
35504 | + return err; | |
35505 | +} | |
35506 | + | |
35507 | +/* ---------------------------------------------------------------------- */ | |
35508 | + | |
35509 | +/* | |
35510 | + * create or remove the diropq. | |
35511 | + */ | |
35512 | +static struct dentry *do_diropq(struct dentry *dentry, aufs_bindex_t bindex, | |
35513 | + unsigned int flags) | |
35514 | +{ | |
35515 | + struct dentry *opq_dentry, *h_dentry; | |
35516 | + struct super_block *sb; | |
35517 | + struct au_branch *br; | |
35518 | + int err; | |
35519 | + | |
35520 | + sb = dentry->d_sb; | |
35521 | + br = au_sbr(sb, bindex); | |
35522 | + h_dentry = au_h_dptr(dentry, bindex); | |
b4510431 | 35523 | + opq_dentry = vfsub_lkup_one(&diropq_name, h_dentry); |
1facf9fc | 35524 | + if (IS_ERR(opq_dentry)) |
35525 | + goto out; | |
35526 | + | |
35527 | + if (au_ftest_diropq(flags, CREATE)) { | |
35528 | + err = link_or_create_wh(sb, bindex, opq_dentry); | |
35529 | + if (!err) { | |
35530 | + au_set_dbdiropq(dentry, bindex); | |
35531 | + goto out; /* success */ | |
35532 | + } | |
35533 | + } else { | |
35534 | + struct path tmp = { | |
35535 | + .dentry = opq_dentry, | |
86dc4139 | 35536 | + .mnt = au_br_mnt(br) |
1facf9fc | 35537 | + }; |
5527c038 | 35538 | + err = do_unlink_wh(au_h_iptr(d_inode(dentry), bindex), &tmp); |
1facf9fc | 35539 | + if (!err) |
35540 | + au_set_dbdiropq(dentry, -1); | |
35541 | + } | |
35542 | + dput(opq_dentry); | |
35543 | + opq_dentry = ERR_PTR(err); | |
35544 | + | |
4f0767ce | 35545 | +out: |
1facf9fc | 35546 | + return opq_dentry; |
35547 | +} | |
35548 | + | |
35549 | +struct do_diropq_args { | |
35550 | + struct dentry **errp; | |
35551 | + struct dentry *dentry; | |
35552 | + aufs_bindex_t bindex; | |
35553 | + unsigned int flags; | |
35554 | +}; | |
35555 | + | |
35556 | +static void call_do_diropq(void *args) | |
35557 | +{ | |
35558 | + struct do_diropq_args *a = args; | |
35559 | + *a->errp = do_diropq(a->dentry, a->bindex, a->flags); | |
35560 | +} | |
35561 | + | |
35562 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
35563 | + unsigned int flags) | |
35564 | +{ | |
35565 | + struct dentry *diropq, *h_dentry; | |
35566 | + | |
35567 | + h_dentry = au_h_dptr(dentry, bindex); | |
5527c038 | 35568 | + if (!au_test_h_perm_sio(d_inode(h_dentry), MAY_EXEC | MAY_WRITE)) |
1facf9fc | 35569 | + diropq = do_diropq(dentry, bindex, flags); |
35570 | + else { | |
35571 | + int wkq_err; | |
35572 | + struct do_diropq_args args = { | |
35573 | + .errp = &diropq, | |
35574 | + .dentry = dentry, | |
35575 | + .bindex = bindex, | |
35576 | + .flags = flags | |
35577 | + }; | |
35578 | + | |
35579 | + wkq_err = au_wkq_wait(call_do_diropq, &args); | |
35580 | + if (unlikely(wkq_err)) | |
35581 | + diropq = ERR_PTR(wkq_err); | |
35582 | + } | |
35583 | + | |
35584 | + return diropq; | |
35585 | +} | |
35586 | + | |
35587 | +/* ---------------------------------------------------------------------- */ | |
35588 | + | |
35589 | +/* | |
35590 | + * lookup whiteout dentry. | |
35591 | + * @h_parent: lower parent dentry which must exist and be locked | |
35592 | + * @base_name: name of dentry which will be whiteouted | |
35593 | + * returns dentry for whiteout. | |
35594 | + */ | |
35595 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
35596 | + struct au_branch *br) | |
35597 | +{ | |
35598 | + int err; | |
35599 | + struct qstr wh_name; | |
35600 | + struct dentry *wh_dentry; | |
35601 | + | |
35602 | + err = au_wh_name_alloc(&wh_name, base_name); | |
35603 | + wh_dentry = ERR_PTR(err); | |
35604 | + if (!err) { | |
b4510431 | 35605 | + wh_dentry = vfsub_lkup_one(&wh_name, h_parent); |
9f237c51 | 35606 | + au_kfree_try_rcu(wh_name.name); |
1facf9fc | 35607 | + } |
35608 | + return wh_dentry; | |
35609 | +} | |
35610 | + | |
35611 | +/* | |
35612 | + * link/create a whiteout for @dentry on @bindex. | |
35613 | + */ | |
35614 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
35615 | + struct dentry *h_parent) | |
35616 | +{ | |
35617 | + struct dentry *wh_dentry; | |
35618 | + struct super_block *sb; | |
35619 | + int err; | |
35620 | + | |
35621 | + sb = dentry->d_sb; | |
35622 | + wh_dentry = au_wh_lkup(h_parent, &dentry->d_name, au_sbr(sb, bindex)); | |
5527c038 | 35623 | + if (!IS_ERR(wh_dentry) && d_is_negative(wh_dentry)) { |
1facf9fc | 35624 | + err = link_or_create_wh(sb, bindex, wh_dentry); |
076b876e | 35625 | + if (!err) { |
1facf9fc | 35626 | + au_set_dbwh(dentry, bindex); |
076b876e AM |
35627 | + au_fhsm_wrote(sb, bindex, /*force*/0); |
35628 | + } else { | |
1facf9fc | 35629 | + dput(wh_dentry); |
35630 | + wh_dentry = ERR_PTR(err); | |
35631 | + } | |
35632 | + } | |
35633 | + | |
35634 | + return wh_dentry; | |
35635 | +} | |
35636 | + | |
35637 | +/* ---------------------------------------------------------------------- */ | |
35638 | + | |
35639 | +/* Delete all whiteouts in this directory on branch bindex. */ | |
35640 | +static int del_wh_children(struct dentry *h_dentry, struct au_nhash *whlist, | |
35641 | + aufs_bindex_t bindex, struct au_branch *br) | |
35642 | +{ | |
35643 | + int err; | |
35644 | + unsigned long ul, n; | |
35645 | + struct qstr wh_name; | |
35646 | + char *p; | |
35647 | + struct hlist_head *head; | |
c06a8ce3 | 35648 | + struct au_vdir_wh *pos; |
1facf9fc | 35649 | + struct au_vdir_destr *str; |
35650 | + | |
35651 | + err = -ENOMEM; | |
537831f9 | 35652 | + p = (void *)__get_free_page(GFP_NOFS); |
1facf9fc | 35653 | + wh_name.name = p; |
35654 | + if (unlikely(!wh_name.name)) | |
35655 | + goto out; | |
35656 | + | |
35657 | + err = 0; | |
35658 | + memcpy(p, AUFS_WH_PFX, AUFS_WH_PFX_LEN); | |
35659 | + p += AUFS_WH_PFX_LEN; | |
35660 | + n = whlist->nh_num; | |
35661 | + head = whlist->nh_head; | |
35662 | + for (ul = 0; !err && ul < n; ul++, head++) { | |
c06a8ce3 AM |
35663 | + hlist_for_each_entry(pos, head, wh_hash) { |
35664 | + if (pos->wh_bindex != bindex) | |
1facf9fc | 35665 | + continue; |
35666 | + | |
c06a8ce3 | 35667 | + str = &pos->wh_str; |
1facf9fc | 35668 | + if (str->len + AUFS_WH_PFX_LEN <= PATH_MAX) { |
35669 | + memcpy(p, str->name, str->len); | |
35670 | + wh_name.len = AUFS_WH_PFX_LEN + str->len; | |
35671 | + err = unlink_wh_name(h_dentry, &wh_name, br); | |
35672 | + if (!err) | |
35673 | + continue; | |
35674 | + break; | |
35675 | + } | |
35676 | + AuIOErr("whiteout name too long %.*s\n", | |
35677 | + str->len, str->name); | |
35678 | + err = -EIO; | |
35679 | + break; | |
35680 | + } | |
35681 | + } | |
1c60b727 | 35682 | + free_page((unsigned long)wh_name.name); |
1facf9fc | 35683 | + |
4f0767ce | 35684 | +out: |
1facf9fc | 35685 | + return err; |
35686 | +} | |
35687 | + | |
35688 | +struct del_wh_children_args { | |
35689 | + int *errp; | |
35690 | + struct dentry *h_dentry; | |
1308ab2a | 35691 | + struct au_nhash *whlist; |
1facf9fc | 35692 | + aufs_bindex_t bindex; |
35693 | + struct au_branch *br; | |
35694 | +}; | |
35695 | + | |
35696 | +static void call_del_wh_children(void *args) | |
35697 | +{ | |
35698 | + struct del_wh_children_args *a = args; | |
1308ab2a | 35699 | + *a->errp = del_wh_children(a->h_dentry, a->whlist, a->bindex, a->br); |
1facf9fc | 35700 | +} |
35701 | + | |
35702 | +/* ---------------------------------------------------------------------- */ | |
35703 | + | |
35704 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp) | |
35705 | +{ | |
35706 | + struct au_whtmp_rmdir *whtmp; | |
dece6358 | 35707 | + int err; |
1308ab2a | 35708 | + unsigned int rdhash; |
dece6358 AM |
35709 | + |
35710 | + SiMustAnyLock(sb); | |
1facf9fc | 35711 | + |
be52b249 | 35712 | + whtmp = kzalloc(sizeof(*whtmp), gfp); |
dece6358 AM |
35713 | + if (unlikely(!whtmp)) { |
35714 | + whtmp = ERR_PTR(-ENOMEM); | |
1facf9fc | 35715 | + goto out; |
dece6358 | 35716 | + } |
1facf9fc | 35717 | + |
1308ab2a | 35718 | + /* no estimation for dir size */ |
35719 | + rdhash = au_sbi(sb)->si_rdhash; | |
35720 | + if (!rdhash) | |
35721 | + rdhash = AUFS_RDHASH_DEF; | |
35722 | + err = au_nhash_alloc(&whtmp->whlist, rdhash, gfp); | |
35723 | + if (unlikely(err)) { | |
9f237c51 | 35724 | + au_kfree_rcu(whtmp); |
1308ab2a | 35725 | + whtmp = ERR_PTR(err); |
35726 | + } | |
dece6358 | 35727 | + |
4f0767ce | 35728 | +out: |
dece6358 | 35729 | + return whtmp; |
1facf9fc | 35730 | +} |
35731 | + | |
35732 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp) | |
35733 | +{ | |
027c5e7a | 35734 | + if (whtmp->br) |
acd2b654 | 35735 | + au_lcnt_dec(&whtmp->br->br_count); |
1facf9fc | 35736 | + dput(whtmp->wh_dentry); |
35737 | + iput(whtmp->dir); | |
dece6358 | 35738 | + au_nhash_wh_free(&whtmp->whlist); |
9f237c51 | 35739 | + au_kfree_rcu(whtmp); |
1facf9fc | 35740 | +} |
35741 | + | |
35742 | +/* | |
35743 | + * rmdir the whiteouted temporary named dir @h_dentry. | |
35744 | + * @whlist: whiteouted children. | |
35745 | + */ | |
35746 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35747 | + struct dentry *wh_dentry, struct au_nhash *whlist) | |
35748 | +{ | |
35749 | + int err; | |
2000de60 | 35750 | + unsigned int h_nlink; |
1facf9fc | 35751 | + struct path h_tmp; |
35752 | + struct inode *wh_inode, *h_dir; | |
35753 | + struct au_branch *br; | |
35754 | + | |
5527c038 | 35755 | + h_dir = d_inode(wh_dentry->d_parent); /* dir inode is locked */ |
1facf9fc | 35756 | + IMustLock(h_dir); |
35757 | + | |
35758 | + br = au_sbr(dir->i_sb, bindex); | |
5527c038 | 35759 | + wh_inode = d_inode(wh_dentry); |
febd17d6 | 35760 | + inode_lock_nested(wh_inode, AuLsc_I_CHILD); |
1facf9fc | 35761 | + |
35762 | + /* | |
35763 | + * someone else might change some whiteouts while we were sleeping. | |
35764 | + * it means this whlist may have an obsoleted entry. | |
35765 | + */ | |
35766 | + if (!au_test_h_perm_sio(wh_inode, MAY_EXEC | MAY_WRITE)) | |
35767 | + err = del_wh_children(wh_dentry, whlist, bindex, br); | |
35768 | + else { | |
35769 | + int wkq_err; | |
35770 | + struct del_wh_children_args args = { | |
35771 | + .errp = &err, | |
35772 | + .h_dentry = wh_dentry, | |
1308ab2a | 35773 | + .whlist = whlist, |
1facf9fc | 35774 | + .bindex = bindex, |
35775 | + .br = br | |
35776 | + }; | |
35777 | + | |
35778 | + wkq_err = au_wkq_wait(call_del_wh_children, &args); | |
35779 | + if (unlikely(wkq_err)) | |
35780 | + err = wkq_err; | |
35781 | + } | |
febd17d6 | 35782 | + inode_unlock(wh_inode); |
1facf9fc | 35783 | + |
35784 | + if (!err) { | |
35785 | + h_tmp.dentry = wh_dentry; | |
86dc4139 | 35786 | + h_tmp.mnt = au_br_mnt(br); |
2000de60 | 35787 | + h_nlink = h_dir->i_nlink; |
1facf9fc | 35788 | + err = vfsub_rmdir(h_dir, &h_tmp); |
2000de60 JR |
35789 | + /* some fs doesn't change the parent nlink in some cases */ |
35790 | + h_nlink -= h_dir->i_nlink; | |
1facf9fc | 35791 | + } |
35792 | + | |
35793 | + if (!err) { | |
5afbbe0d | 35794 | + if (au_ibtop(dir) == bindex) { |
7f207e10 | 35795 | + /* todo: dir->i_mutex is necessary */ |
1facf9fc | 35796 | + au_cpup_attr_timesizes(dir); |
2000de60 JR |
35797 | + if (h_nlink) |
35798 | + vfsub_drop_nlink(dir); | |
1facf9fc | 35799 | + } |
35800 | + return 0; /* success */ | |
35801 | + } | |
35802 | + | |
523b37e3 | 35803 | + pr_warn("failed removing %pd(%d), ignored\n", wh_dentry, err); |
1facf9fc | 35804 | + return err; |
35805 | +} | |
35806 | + | |
35807 | +static void call_rmdir_whtmp(void *args) | |
35808 | +{ | |
35809 | + int err; | |
e49829fe | 35810 | + aufs_bindex_t bindex; |
1facf9fc | 35811 | + struct au_whtmp_rmdir *a = args; |
35812 | + struct super_block *sb; | |
35813 | + struct dentry *h_parent; | |
35814 | + struct inode *h_dir; | |
1facf9fc | 35815 | + struct au_hinode *hdir; |
35816 | + | |
35817 | + /* rmdir by nfsd may cause deadlock with this i_mutex */ | |
febd17d6 | 35818 | + /* inode_lock(a->dir); */ |
e49829fe | 35819 | + err = -EROFS; |
1facf9fc | 35820 | + sb = a->dir->i_sb; |
e49829fe JR |
35821 | + si_read_lock(sb, !AuLock_FLUSH); |
35822 | + if (!au_br_writable(a->br->br_perm)) | |
35823 | + goto out; | |
35824 | + bindex = au_br_index(sb, a->br->br_id); | |
35825 | + if (unlikely(bindex < 0)) | |
1facf9fc | 35826 | + goto out; |
35827 | + | |
35828 | + err = -EIO; | |
1facf9fc | 35829 | + ii_write_lock_parent(a->dir); |
35830 | + h_parent = dget_parent(a->wh_dentry); | |
5527c038 | 35831 | + h_dir = d_inode(h_parent); |
e49829fe | 35832 | + hdir = au_hi(a->dir, bindex); |
86dc4139 AM |
35833 | + err = vfsub_mnt_want_write(au_br_mnt(a->br)); |
35834 | + if (unlikely(err)) | |
35835 | + goto out_mnt; | |
5afbbe0d | 35836 | + au_hn_inode_lock_nested(hdir, AuLsc_I_PARENT); |
e49829fe JR |
35837 | + err = au_h_verify(a->wh_dentry, au_opt_udba(sb), h_dir, h_parent, |
35838 | + a->br); | |
86dc4139 AM |
35839 | + if (!err) |
35840 | + err = au_whtmp_rmdir(a->dir, bindex, a->wh_dentry, &a->whlist); | |
5afbbe0d | 35841 | + au_hn_inode_unlock(hdir); |
86dc4139 AM |
35842 | + vfsub_mnt_drop_write(au_br_mnt(a->br)); |
35843 | + | |
35844 | +out_mnt: | |
1facf9fc | 35845 | + dput(h_parent); |
35846 | + ii_write_unlock(a->dir); | |
4f0767ce | 35847 | +out: |
febd17d6 | 35848 | + /* inode_unlock(a->dir); */ |
1facf9fc | 35849 | + au_whtmp_rmdir_free(a); |
027c5e7a AM |
35850 | + si_read_unlock(sb); |
35851 | + au_nwt_done(&au_sbi(sb)->si_nowait); | |
1facf9fc | 35852 | + if (unlikely(err)) |
35853 | + AuIOErr("err %d\n", err); | |
35854 | +} | |
35855 | + | |
35856 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35857 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args) | |
35858 | +{ | |
35859 | + int wkq_err; | |
e49829fe | 35860 | + struct super_block *sb; |
1facf9fc | 35861 | + |
35862 | + IMustLock(dir); | |
35863 | + | |
35864 | + /* all post-process will be done in do_rmdir_whtmp(). */ | |
e49829fe | 35865 | + sb = dir->i_sb; |
1facf9fc | 35866 | + args->dir = au_igrab(dir); |
e49829fe | 35867 | + args->br = au_sbr(sb, bindex); |
acd2b654 | 35868 | + au_lcnt_inc(&args->br->br_count); |
1facf9fc | 35869 | + args->wh_dentry = dget(wh_dentry); |
53392da6 | 35870 | + wkq_err = au_wkq_nowait(call_rmdir_whtmp, args, sb, /*flags*/0); |
1facf9fc | 35871 | + if (unlikely(wkq_err)) { |
523b37e3 | 35872 | + pr_warn("rmdir error %pd (%d), ignored\n", wh_dentry, wkq_err); |
1facf9fc | 35873 | + au_whtmp_rmdir_free(args); |
35874 | + } | |
35875 | +} | |
7f207e10 | 35876 | diff -urN /usr/share/empty/fs/aufs/whout.h linux/fs/aufs/whout.h |
eca34b5c | 35877 | --- /usr/share/empty/fs/aufs/whout.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 35878 | +++ linux/fs/aufs/whout.h 2020-01-27 10:57:18.178871751 +0100 |
062440b3 AM |
35879 | @@ -0,0 +1,86 @@ |
35880 | +/* SPDX-License-Identifier: GPL-2.0 */ | |
1facf9fc | 35881 | +/* |
d58c55f2 | 35882 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 35883 | + * |
35884 | + * This program, aufs is free software; you can redistribute it and/or modify | |
35885 | + * it under the terms of the GNU General Public License as published by | |
35886 | + * the Free Software Foundation; either version 2 of the License, or | |
35887 | + * (at your option) any later version. | |
dece6358 AM |
35888 | + * |
35889 | + * This program is distributed in the hope that it will be useful, | |
35890 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
35891 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35892 | + * GNU General Public License for more details. | |
35893 | + * | |
35894 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 35895 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 35896 | + */ |
35897 | + | |
35898 | +/* | |
35899 | + * whiteout for logical deletion and opaque directory | |
35900 | + */ | |
35901 | + | |
35902 | +#ifndef __AUFS_WHOUT_H__ | |
35903 | +#define __AUFS_WHOUT_H__ | |
35904 | + | |
35905 | +#ifdef __KERNEL__ | |
35906 | + | |
1facf9fc | 35907 | +#include "dir.h" |
35908 | + | |
35909 | +/* whout.c */ | |
35910 | +int au_wh_name_alloc(struct qstr *wh, const struct qstr *name); | |
076b876e AM |
35911 | +int au_wh_test(struct dentry *h_parent, struct qstr *wh_name, int try_sio); |
35912 | +int au_diropq_test(struct dentry *h_dentry); | |
3c1bdaff | 35913 | +struct au_branch; |
1facf9fc | 35914 | +struct dentry *au_whtmp_lkup(struct dentry *h_parent, struct au_branch *br, |
35915 | + struct qstr *prefix); | |
35916 | +int au_whtmp_ren(struct dentry *h_dentry, struct au_branch *br); | |
35917 | +int au_wh_unlink_dentry(struct inode *h_dir, struct path *h_path, | |
35918 | + struct dentry *dentry); | |
86dc4139 | 35919 | +int au_wh_init(struct au_branch *br, struct super_block *sb); |
1facf9fc | 35920 | + |
35921 | +/* diropq flags */ | |
35922 | +#define AuDiropq_CREATE 1 | |
35923 | +#define au_ftest_diropq(flags, name) ((flags) & AuDiropq_##name) | |
7f207e10 AM |
35924 | +#define au_fset_diropq(flags, name) \ |
35925 | + do { (flags) |= AuDiropq_##name; } while (0) | |
35926 | +#define au_fclr_diropq(flags, name) \ | |
35927 | + do { (flags) &= ~AuDiropq_##name; } while (0) | |
1facf9fc | 35928 | + |
35929 | +struct dentry *au_diropq_sio(struct dentry *dentry, aufs_bindex_t bindex, | |
35930 | + unsigned int flags); | |
35931 | +struct dentry *au_wh_lkup(struct dentry *h_parent, struct qstr *base_name, | |
35932 | + struct au_branch *br); | |
35933 | +struct dentry *au_wh_create(struct dentry *dentry, aufs_bindex_t bindex, | |
35934 | + struct dentry *h_parent); | |
35935 | + | |
35936 | +/* real rmdir for the whiteout-ed dir */ | |
35937 | +struct au_whtmp_rmdir { | |
35938 | + struct inode *dir; | |
e49829fe | 35939 | + struct au_branch *br; |
1facf9fc | 35940 | + struct dentry *wh_dentry; |
dece6358 | 35941 | + struct au_nhash whlist; |
1facf9fc | 35942 | +}; |
35943 | + | |
35944 | +struct au_whtmp_rmdir *au_whtmp_rmdir_alloc(struct super_block *sb, gfp_t gfp); | |
35945 | +void au_whtmp_rmdir_free(struct au_whtmp_rmdir *whtmp); | |
35946 | +int au_whtmp_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35947 | + struct dentry *wh_dentry, struct au_nhash *whlist); | |
35948 | +void au_whtmp_kick_rmdir(struct inode *dir, aufs_bindex_t bindex, | |
35949 | + struct dentry *wh_dentry, struct au_whtmp_rmdir *args); | |
35950 | + | |
35951 | +/* ---------------------------------------------------------------------- */ | |
35952 | + | |
35953 | +static inline struct dentry *au_diropq_create(struct dentry *dentry, | |
35954 | + aufs_bindex_t bindex) | |
35955 | +{ | |
35956 | + return au_diropq_sio(dentry, bindex, AuDiropq_CREATE); | |
35957 | +} | |
35958 | + | |
35959 | +static inline int au_diropq_remove(struct dentry *dentry, aufs_bindex_t bindex) | |
35960 | +{ | |
35961 | + return PTR_ERR(au_diropq_sio(dentry, bindex, !AuDiropq_CREATE)); | |
35962 | +} | |
35963 | + | |
35964 | +#endif /* __KERNEL__ */ | |
35965 | +#endif /* __AUFS_WHOUT_H__ */ | |
7f207e10 | 35966 | diff -urN /usr/share/empty/fs/aufs/wkq.c linux/fs/aufs/wkq.c |
eca34b5c | 35967 | --- /usr/share/empty/fs/aufs/wkq.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 35968 | +++ linux/fs/aufs/wkq.c 2020-01-27 10:57:18.178871751 +0100 |
43982f53 | 35969 | @@ -0,0 +1,372 @@ |
cd7a4cd9 | 35970 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 35971 | +/* |
d58c55f2 | 35972 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 35973 | + * |
35974 | + * This program, aufs is free software; you can redistribute it and/or modify | |
35975 | + * it under the terms of the GNU General Public License as published by | |
35976 | + * the Free Software Foundation; either version 2 of the License, or | |
35977 | + * (at your option) any later version. | |
dece6358 AM |
35978 | + * |
35979 | + * This program is distributed in the hope that it will be useful, | |
35980 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
35981 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
35982 | + * GNU General Public License for more details. | |
35983 | + * | |
35984 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 35985 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 35986 | + */ |
35987 | + | |
35988 | +/* | |
35989 | + * workqueue for asynchronous/super-io operations | |
acd2b654 | 35990 | + * todo: try new credential scheme |
1facf9fc | 35991 | + */ |
35992 | + | |
dece6358 | 35993 | +#include <linux/module.h> |
1facf9fc | 35994 | +#include "aufs.h" |
35995 | + | |
9dbd164d | 35996 | +/* internal workqueue named AUFS_WKQ_NAME */ |
b752ccd1 | 35997 | + |
9dbd164d | 35998 | +static struct workqueue_struct *au_wkq; |
1facf9fc | 35999 | + |
36000 | +struct au_wkinfo { | |
36001 | + struct work_struct wk; | |
7f207e10 | 36002 | + struct kobject *kobj; |
1facf9fc | 36003 | + |
36004 | + unsigned int flags; /* see wkq.h */ | |
36005 | + | |
36006 | + au_wkq_func_t func; | |
36007 | + void *args; | |
36008 | + | |
8b6a4947 AM |
36009 | +#ifdef CONFIG_LOCKDEP |
36010 | + int dont_check; | |
36011 | + struct held_lock **hlock; | |
36012 | +#endif | |
36013 | + | |
1facf9fc | 36014 | + struct completion *comp; |
36015 | +}; | |
36016 | + | |
36017 | +/* ---------------------------------------------------------------------- */ | |
8b6a4947 AM |
36018 | +/* |
36019 | + * Aufs passes some operations to the workqueue such as the internal copyup. | |
36020 | + * This scheme looks rather unnatural for LOCKDEP debugging feature, since the | |
36021 | + * job run by workqueue depends upon the locks acquired in the other task. | |
36022 | + * Delegating a small operation to the workqueue, aufs passes its lockdep | |
36023 | + * information too. And the job in the workqueue restores the info in order to | |
36024 | + * pretend as if it acquired those locks. This is just to make LOCKDEP work | |
36025 | + * correctly and expectedly. | |
36026 | + */ | |
36027 | + | |
36028 | +#ifndef CONFIG_LOCKDEP | |
36029 | +AuStubInt0(au_wkq_lockdep_alloc, struct au_wkinfo *wkinfo); | |
36030 | +AuStubVoid(au_wkq_lockdep_free, struct au_wkinfo *wkinfo); | |
36031 | +AuStubVoid(au_wkq_lockdep_pre, struct au_wkinfo *wkinfo); | |
36032 | +AuStubVoid(au_wkq_lockdep_post, struct au_wkinfo *wkinfo); | |
36033 | +AuStubVoid(au_wkq_lockdep_init, struct au_wkinfo *wkinfo); | |
36034 | +#else | |
36035 | +static void au_wkq_lockdep_init(struct au_wkinfo *wkinfo) | |
36036 | +{ | |
36037 | + wkinfo->hlock = NULL; | |
36038 | + wkinfo->dont_check = 0; | |
36039 | +} | |
36040 | + | |
36041 | +/* | |
36042 | + * 1: matched | |
36043 | + * 0: unmatched | |
36044 | + */ | |
36045 | +static int au_wkq_lockdep_test(struct lock_class_key *key, const char *name) | |
36046 | +{ | |
36047 | + static DEFINE_SPINLOCK(spin); | |
36048 | + static struct { | |
36049 | + char *name; | |
36050 | + struct lock_class_key *key; | |
36051 | + } a[] = { | |
36052 | + { .name = "&sbinfo->si_rwsem" }, | |
36053 | + { .name = "&finfo->fi_rwsem" }, | |
36054 | + { .name = "&dinfo->di_rwsem" }, | |
36055 | + { .name = "&iinfo->ii_rwsem" } | |
36056 | + }; | |
36057 | + static int set; | |
36058 | + int i; | |
36059 | + | |
36060 | + /* lockless read from 'set.' see below */ | |
36061 | + if (set == ARRAY_SIZE(a)) { | |
36062 | + for (i = 0; i < ARRAY_SIZE(a); i++) | |
36063 | + if (a[i].key == key) | |
36064 | + goto match; | |
36065 | + goto unmatch; | |
36066 | + } | |
36067 | + | |
36068 | + spin_lock(&spin); | |
36069 | + if (set) | |
36070 | + for (i = 0; i < ARRAY_SIZE(a); i++) | |
36071 | + if (a[i].key == key) { | |
36072 | + spin_unlock(&spin); | |
36073 | + goto match; | |
36074 | + } | |
36075 | + for (i = 0; i < ARRAY_SIZE(a); i++) { | |
36076 | + if (a[i].key) { | |
36077 | + if (unlikely(a[i].key == key)) { /* rare but possible */ | |
36078 | + spin_unlock(&spin); | |
36079 | + goto match; | |
36080 | + } else | |
36081 | + continue; | |
36082 | + } | |
36083 | + if (strstr(a[i].name, name)) { | |
36084 | + /* | |
36085 | + * the order of these three lines is important for the | |
36086 | + * lockless read above. | |
36087 | + */ | |
36088 | + a[i].key = key; | |
36089 | + spin_unlock(&spin); | |
36090 | + set++; | |
36091 | + /* AuDbg("%d, %s\n", set, name); */ | |
36092 | + goto match; | |
36093 | + } | |
36094 | + } | |
36095 | + spin_unlock(&spin); | |
36096 | + goto unmatch; | |
36097 | + | |
36098 | +match: | |
36099 | + return 1; | |
36100 | +unmatch: | |
36101 | + return 0; | |
36102 | +} | |
36103 | + | |
36104 | +static int au_wkq_lockdep_alloc(struct au_wkinfo *wkinfo) | |
36105 | +{ | |
36106 | + int err, n; | |
36107 | + struct task_struct *curr; | |
36108 | + struct held_lock **hl, *held_locks, *p; | |
36109 | + | |
36110 | + err = 0; | |
36111 | + curr = current; | |
36112 | + wkinfo->dont_check = lockdep_recursing(curr); | |
36113 | + if (wkinfo->dont_check) | |
36114 | + goto out; | |
36115 | + n = curr->lockdep_depth; | |
36116 | + if (!n) | |
36117 | + goto out; | |
36118 | + | |
36119 | + err = -ENOMEM; | |
36120 | + wkinfo->hlock = kmalloc_array(n + 1, sizeof(*wkinfo->hlock), GFP_NOFS); | |
36121 | + if (unlikely(!wkinfo->hlock)) | |
36122 | + goto out; | |
36123 | + | |
36124 | + err = 0; | |
43982f53 AM |
36125 | +#if 0 /* left for debugging */ |
36126 | + if (0 && au_debug_test()) | |
8b6a4947 AM |
36127 | + lockdep_print_held_locks(curr); |
36128 | +#endif | |
36129 | + held_locks = curr->held_locks; | |
36130 | + hl = wkinfo->hlock; | |
36131 | + while (n--) { | |
36132 | + p = held_locks++; | |
36133 | + if (au_wkq_lockdep_test(p->instance->key, p->instance->name)) | |
36134 | + *hl++ = p; | |
36135 | + } | |
36136 | + *hl = NULL; | |
36137 | + | |
36138 | +out: | |
36139 | + return err; | |
36140 | +} | |
36141 | + | |
36142 | +static void au_wkq_lockdep_free(struct au_wkinfo *wkinfo) | |
36143 | +{ | |
9f237c51 | 36144 | + au_kfree_try_rcu(wkinfo->hlock); |
8b6a4947 AM |
36145 | +} |
36146 | + | |
36147 | +static void au_wkq_lockdep_pre(struct au_wkinfo *wkinfo) | |
36148 | +{ | |
36149 | + struct held_lock *p, **hl = wkinfo->hlock; | |
36150 | + int subclass; | |
36151 | + | |
36152 | + if (wkinfo->dont_check) | |
36153 | + lockdep_off(); | |
36154 | + if (!hl) | |
36155 | + return; | |
36156 | + while ((p = *hl++)) { /* assignment */ | |
36157 | + subclass = lockdep_hlock_class(p)->subclass; | |
36158 | + /* AuDbg("%s, %d\n", p->instance->name, subclass); */ | |
36159 | + if (p->read) | |
36160 | + rwsem_acquire_read(p->instance, subclass, 0, | |
36161 | + /*p->acquire_ip*/_RET_IP_); | |
36162 | + else | |
36163 | + rwsem_acquire(p->instance, subclass, 0, | |
36164 | + /*p->acquire_ip*/_RET_IP_); | |
36165 | + } | |
36166 | +} | |
36167 | + | |
36168 | +static void au_wkq_lockdep_post(struct au_wkinfo *wkinfo) | |
36169 | +{ | |
36170 | + struct held_lock *p, **hl = wkinfo->hlock; | |
36171 | + | |
36172 | + if (wkinfo->dont_check) | |
36173 | + lockdep_on(); | |
36174 | + if (!hl) | |
36175 | + return; | |
36176 | + while ((p = *hl++)) /* assignment */ | |
d58c55f2 | 36177 | + rwsem_release(p->instance, /*p->acquire_ip*/_RET_IP_); |
8b6a4947 AM |
36178 | +} |
36179 | +#endif | |
1facf9fc | 36180 | + |
1facf9fc | 36181 | +static void wkq_func(struct work_struct *wk) |
36182 | +{ | |
36183 | + struct au_wkinfo *wkinfo = container_of(wk, struct au_wkinfo, wk); | |
36184 | + | |
2dfbb274 | 36185 | + AuDebugOn(!uid_eq(current_fsuid(), GLOBAL_ROOT_UID)); |
7f207e10 AM |
36186 | + AuDebugOn(rlimit(RLIMIT_FSIZE) != RLIM_INFINITY); |
36187 | + | |
8b6a4947 | 36188 | + au_wkq_lockdep_pre(wkinfo); |
1facf9fc | 36189 | + wkinfo->func(wkinfo->args); |
8b6a4947 | 36190 | + au_wkq_lockdep_post(wkinfo); |
1facf9fc | 36191 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) |
36192 | + complete(wkinfo->comp); | |
36193 | + else { | |
7f207e10 | 36194 | + kobject_put(wkinfo->kobj); |
9dbd164d | 36195 | + module_put(THIS_MODULE); /* todo: ?? */ |
9f237c51 | 36196 | + au_kfree_rcu(wkinfo); |
1facf9fc | 36197 | + } |
36198 | +} | |
36199 | + | |
36200 | +/* | |
36201 | + * Since struct completion is large, try allocating it dynamically. | |
36202 | + */ | |
1facf9fc | 36203 | +#define AuWkqCompDeclare(name) struct completion *comp = NULL |
36204 | + | |
36205 | +static int au_wkq_comp_alloc(struct au_wkinfo *wkinfo, struct completion **comp) | |
36206 | +{ | |
36207 | + *comp = kmalloc(sizeof(**comp), GFP_NOFS); | |
36208 | + if (*comp) { | |
36209 | + init_completion(*comp); | |
36210 | + wkinfo->comp = *comp; | |
36211 | + return 0; | |
36212 | + } | |
36213 | + return -ENOMEM; | |
36214 | +} | |
36215 | + | |
36216 | +static void au_wkq_comp_free(struct completion *comp) | |
36217 | +{ | |
9f237c51 | 36218 | + au_kfree_rcu(comp); |
1facf9fc | 36219 | +} |
36220 | + | |
53392da6 | 36221 | +static void au_wkq_run(struct au_wkinfo *wkinfo) |
1facf9fc | 36222 | +{ |
53392da6 AM |
36223 | + if (au_ftest_wkq(wkinfo->flags, NEST)) { |
36224 | + if (au_wkq_test()) { | |
38d290e6 | 36225 | + AuWarn1("wkq from wkq, unless silly-rename on NFS," |
acd2b654 AM |
36226 | + " due to a dead dir by UDBA," |
36227 | + " or async xino write?\n"); | |
53392da6 AM |
36228 | + AuDebugOn(au_ftest_wkq(wkinfo->flags, WAIT)); |
36229 | + } | |
36230 | + } else | |
36231 | + au_dbg_verify_kthread(); | |
36232 | + | |
36233 | + if (au_ftest_wkq(wkinfo->flags, WAIT)) { | |
a1f66529 | 36234 | + INIT_WORK_ONSTACK(&wkinfo->wk, wkq_func); |
9dbd164d | 36235 | + queue_work(au_wkq, &wkinfo->wk); |
4a4d8108 AM |
36236 | + } else { |
36237 | + INIT_WORK(&wkinfo->wk, wkq_func); | |
36238 | + schedule_work(&wkinfo->wk); | |
36239 | + } | |
1facf9fc | 36240 | +} |
36241 | + | |
7f207e10 AM |
36242 | +/* |
36243 | + * Be careful. It is easy to make deadlock happen. | |
36244 | + * processA: lock, wkq and wait | |
36245 | + * processB: wkq and wait, lock in wkq | |
36246 | + * --> deadlock | |
36247 | + */ | |
b752ccd1 | 36248 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args) |
1facf9fc | 36249 | +{ |
36250 | + int err; | |
36251 | + AuWkqCompDeclare(comp); | |
36252 | + struct au_wkinfo wkinfo = { | |
b752ccd1 | 36253 | + .flags = flags, |
1facf9fc | 36254 | + .func = func, |
36255 | + .args = args | |
36256 | + }; | |
36257 | + | |
36258 | + err = au_wkq_comp_alloc(&wkinfo, &comp); | |
8b6a4947 AM |
36259 | + if (unlikely(err)) |
36260 | + goto out; | |
36261 | + err = au_wkq_lockdep_alloc(&wkinfo); | |
36262 | + if (unlikely(err)) | |
36263 | + goto out_comp; | |
1facf9fc | 36264 | + if (!err) { |
53392da6 | 36265 | + au_wkq_run(&wkinfo); |
1facf9fc | 36266 | + /* no timeout, no interrupt */ |
36267 | + wait_for_completion(wkinfo.comp); | |
1facf9fc | 36268 | + } |
8b6a4947 | 36269 | + au_wkq_lockdep_free(&wkinfo); |
1facf9fc | 36270 | + |
8b6a4947 AM |
36271 | +out_comp: |
36272 | + au_wkq_comp_free(comp); | |
36273 | +out: | |
36274 | + destroy_work_on_stack(&wkinfo.wk); | |
1facf9fc | 36275 | + return err; |
1facf9fc | 36276 | +} |
36277 | + | |
027c5e7a AM |
36278 | +/* |
36279 | + * Note: dget/dput() in func for aufs dentries are not supported. It will be a | |
36280 | + * problem in a concurrent umounting. | |
36281 | + */ | |
53392da6 AM |
36282 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
36283 | + unsigned int flags) | |
1facf9fc | 36284 | +{ |
36285 | + int err; | |
36286 | + struct au_wkinfo *wkinfo; | |
36287 | + | |
f0c0a007 | 36288 | + atomic_inc(&au_sbi(sb)->si_nowait.nw_len); |
1facf9fc | 36289 | + |
36290 | + /* | |
36291 | + * wkq_func() must free this wkinfo. | |
36292 | + * it highly depends upon the implementation of workqueue. | |
36293 | + */ | |
36294 | + err = 0; | |
36295 | + wkinfo = kmalloc(sizeof(*wkinfo), GFP_NOFS); | |
36296 | + if (wkinfo) { | |
7f207e10 | 36297 | + wkinfo->kobj = &au_sbi(sb)->si_kobj; |
53392da6 | 36298 | + wkinfo->flags = flags & ~AuWkq_WAIT; |
1facf9fc | 36299 | + wkinfo->func = func; |
36300 | + wkinfo->args = args; | |
36301 | + wkinfo->comp = NULL; | |
8b6a4947 | 36302 | + au_wkq_lockdep_init(wkinfo); |
7f207e10 | 36303 | + kobject_get(wkinfo->kobj); |
9dbd164d | 36304 | + __module_get(THIS_MODULE); /* todo: ?? */ |
1facf9fc | 36305 | + |
53392da6 | 36306 | + au_wkq_run(wkinfo); |
1facf9fc | 36307 | + } else { |
36308 | + err = -ENOMEM; | |
e49829fe | 36309 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
1facf9fc | 36310 | + } |
36311 | + | |
36312 | + return err; | |
36313 | +} | |
36314 | + | |
36315 | +/* ---------------------------------------------------------------------- */ | |
36316 | + | |
36317 | +void au_nwt_init(struct au_nowait_tasks *nwt) | |
36318 | +{ | |
f0c0a007 AM |
36319 | + atomic_set(&nwt->nw_len, 0); |
36320 | + /* smp_mb(); */ /* atomic_set */ | |
1facf9fc | 36321 | + init_waitqueue_head(&nwt->nw_wq); |
36322 | +} | |
36323 | + | |
36324 | +void au_wkq_fin(void) | |
36325 | +{ | |
9dbd164d | 36326 | + destroy_workqueue(au_wkq); |
1facf9fc | 36327 | +} |
36328 | + | |
36329 | +int __init au_wkq_init(void) | |
36330 | +{ | |
9dbd164d | 36331 | + int err; |
b752ccd1 AM |
36332 | + |
36333 | + err = 0; | |
86dc4139 | 36334 | + au_wkq = alloc_workqueue(AUFS_WKQ_NAME, 0, WQ_DFL_ACTIVE); |
9dbd164d AM |
36335 | + if (IS_ERR(au_wkq)) |
36336 | + err = PTR_ERR(au_wkq); | |
36337 | + else if (!au_wkq) | |
36338 | + err = -ENOMEM; | |
b752ccd1 AM |
36339 | + |
36340 | + return err; | |
1facf9fc | 36341 | +} |
7f207e10 | 36342 | diff -urN /usr/share/empty/fs/aufs/wkq.h linux/fs/aufs/wkq.h |
eca34b5c | 36343 | --- /usr/share/empty/fs/aufs/wkq.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 36344 | +++ linux/fs/aufs/wkq.h 2020-01-27 10:57:18.182205184 +0100 |
acd2b654 | 36345 | @@ -0,0 +1,89 @@ |
062440b3 | 36346 | +/* SPDX-License-Identifier: GPL-2.0 */ |
1facf9fc | 36347 | +/* |
d58c55f2 | 36348 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 36349 | + * |
36350 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36351 | + * it under the terms of the GNU General Public License as published by | |
36352 | + * the Free Software Foundation; either version 2 of the License, or | |
36353 | + * (at your option) any later version. | |
dece6358 AM |
36354 | + * |
36355 | + * This program is distributed in the hope that it will be useful, | |
36356 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36357 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36358 | + * GNU General Public License for more details. | |
36359 | + * | |
36360 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 36361 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 36362 | + */ |
36363 | + | |
36364 | +/* | |
36365 | + * workqueue for asynchronous/super-io operations | |
36366 | + * todo: try new credentials management scheme | |
36367 | + */ | |
36368 | + | |
36369 | +#ifndef __AUFS_WKQ_H__ | |
36370 | +#define __AUFS_WKQ_H__ | |
36371 | + | |
36372 | +#ifdef __KERNEL__ | |
36373 | + | |
8b6a4947 | 36374 | +#include <linux/wait.h> |
5afbbe0d | 36375 | + |
dece6358 AM |
36376 | +struct super_block; |
36377 | + | |
1facf9fc | 36378 | +/* ---------------------------------------------------------------------- */ |
36379 | + | |
36380 | +/* | |
36381 | + * in the next operation, wait for the 'nowait' tasks in system-wide workqueue | |
36382 | + */ | |
36383 | +struct au_nowait_tasks { | |
f0c0a007 | 36384 | + atomic_t nw_len; |
1facf9fc | 36385 | + wait_queue_head_t nw_wq; |
36386 | +}; | |
36387 | + | |
36388 | +/* ---------------------------------------------------------------------- */ | |
36389 | + | |
36390 | +typedef void (*au_wkq_func_t)(void *args); | |
36391 | + | |
36392 | +/* wkq flags */ | |
36393 | +#define AuWkq_WAIT 1 | |
9dbd164d | 36394 | +#define AuWkq_NEST (1 << 1) |
1facf9fc | 36395 | +#define au_ftest_wkq(flags, name) ((flags) & AuWkq_##name) |
7f207e10 AM |
36396 | +#define au_fset_wkq(flags, name) \ |
36397 | + do { (flags) |= AuWkq_##name; } while (0) | |
36398 | +#define au_fclr_wkq(flags, name) \ | |
36399 | + do { (flags) &= ~AuWkq_##name; } while (0) | |
1facf9fc | 36400 | + |
36401 | +/* wkq.c */ | |
b752ccd1 | 36402 | +int au_wkq_do_wait(unsigned int flags, au_wkq_func_t func, void *args); |
53392da6 AM |
36403 | +int au_wkq_nowait(au_wkq_func_t func, void *args, struct super_block *sb, |
36404 | + unsigned int flags); | |
1facf9fc | 36405 | +void au_nwt_init(struct au_nowait_tasks *nwt); |
36406 | +int __init au_wkq_init(void); | |
36407 | +void au_wkq_fin(void); | |
36408 | + | |
36409 | +/* ---------------------------------------------------------------------- */ | |
36410 | + | |
53392da6 AM |
36411 | +static inline int au_wkq_test(void) |
36412 | +{ | |
36413 | + return current->flags & PF_WQ_WORKER; | |
36414 | +} | |
36415 | + | |
b752ccd1 | 36416 | +static inline int au_wkq_wait(au_wkq_func_t func, void *args) |
1facf9fc | 36417 | +{ |
b752ccd1 | 36418 | + return au_wkq_do_wait(AuWkq_WAIT, func, args); |
1facf9fc | 36419 | +} |
36420 | + | |
36421 | +static inline void au_nwt_done(struct au_nowait_tasks *nwt) | |
36422 | +{ | |
f0c0a007 | 36423 | + if (atomic_dec_and_test(&nwt->nw_len)) |
1facf9fc | 36424 | + wake_up_all(&nwt->nw_wq); |
36425 | +} | |
36426 | + | |
36427 | +static inline int au_nwt_flush(struct au_nowait_tasks *nwt) | |
36428 | +{ | |
f0c0a007 | 36429 | + wait_event(nwt->nw_wq, !atomic_read(&nwt->nw_len)); |
1facf9fc | 36430 | + return 0; |
36431 | +} | |
36432 | + | |
36433 | +#endif /* __KERNEL__ */ | |
36434 | +#endif /* __AUFS_WKQ_H__ */ | |
c1595e42 | 36435 | diff -urN /usr/share/empty/fs/aufs/xattr.c linux/fs/aufs/xattr.c |
eca34b5c | 36436 | --- /usr/share/empty/fs/aufs/xattr.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 36437 | +++ linux/fs/aufs/xattr.c 2020-01-27 10:57:18.182205184 +0100 |
062440b3 | 36438 | @@ -0,0 +1,356 @@ |
cd7a4cd9 | 36439 | +// SPDX-License-Identifier: GPL-2.0 |
c1595e42 | 36440 | +/* |
d58c55f2 | 36441 | + * Copyright (C) 2014-2020 Junjiro R. Okajima |
c1595e42 JR |
36442 | + * |
36443 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36444 | + * it under the terms of the GNU General Public License as published by | |
36445 | + * the Free Software Foundation; either version 2 of the License, or | |
36446 | + * (at your option) any later version. | |
36447 | + * | |
36448 | + * This program is distributed in the hope that it will be useful, | |
36449 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36450 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36451 | + * GNU General Public License for more details. | |
36452 | + * | |
36453 | + * You should have received a copy of the GNU General Public License | |
36454 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
36455 | + */ | |
36456 | + | |
36457 | +/* | |
36458 | + * handling xattr functions | |
36459 | + */ | |
36460 | + | |
a2654f78 AM |
36461 | +#include <linux/fs.h> |
36462 | +#include <linux/posix_acl_xattr.h> | |
c1595e42 JR |
36463 | +#include <linux/xattr.h> |
36464 | +#include "aufs.h" | |
36465 | + | |
36466 | +static int au_xattr_ignore(int err, char *name, unsigned int ignore_flags) | |
36467 | +{ | |
36468 | + if (!ignore_flags) | |
36469 | + goto out; | |
36470 | + switch (err) { | |
36471 | + case -ENOMEM: | |
36472 | + case -EDQUOT: | |
36473 | + goto out; | |
36474 | + } | |
36475 | + | |
36476 | + if ((ignore_flags & AuBrAttr_ICEX) == AuBrAttr_ICEX) { | |
36477 | + err = 0; | |
36478 | + goto out; | |
36479 | + } | |
36480 | + | |
36481 | +#define cmp(brattr, prefix) do { \ | |
36482 | + if (!strncmp(name, XATTR_##prefix##_PREFIX, \ | |
36483 | + XATTR_##prefix##_PREFIX_LEN)) { \ | |
36484 | + if (ignore_flags & AuBrAttr_ICEX_##brattr) \ | |
36485 | + err = 0; \ | |
36486 | + goto out; \ | |
36487 | + } \ | |
36488 | + } while (0) | |
36489 | + | |
36490 | + cmp(SEC, SECURITY); | |
36491 | + cmp(SYS, SYSTEM); | |
36492 | + cmp(TR, TRUSTED); | |
36493 | + cmp(USR, USER); | |
36494 | +#undef cmp | |
36495 | + | |
36496 | + if (ignore_flags & AuBrAttr_ICEX_OTH) | |
36497 | + err = 0; | |
36498 | + | |
36499 | +out: | |
36500 | + return err; | |
36501 | +} | |
36502 | + | |
36503 | +static const int au_xattr_out_of_list = AuBrAttr_ICEX_OTH << 1; | |
36504 | + | |
36505 | +static int au_do_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, | |
7e9cd9fe AM |
36506 | + char *name, char **buf, unsigned int ignore_flags, |
36507 | + unsigned int verbose) | |
c1595e42 JR |
36508 | +{ |
36509 | + int err; | |
36510 | + ssize_t ssz; | |
36511 | + struct inode *h_idst; | |
36512 | + | |
36513 | + ssz = vfs_getxattr_alloc(h_src, name, buf, 0, GFP_NOFS); | |
36514 | + err = ssz; | |
36515 | + if (unlikely(err <= 0)) { | |
c1595e42 JR |
36516 | + if (err == -ENODATA |
36517 | + || (err == -EOPNOTSUPP | |
b912730e | 36518 | + && ((ignore_flags & au_xattr_out_of_list) |
5527c038 | 36519 | + || (au_test_nfs_noacl(d_inode(h_src)) |
b912730e AM |
36520 | + && (!strcmp(name, XATTR_NAME_POSIX_ACL_ACCESS) |
36521 | + || !strcmp(name, | |
36522 | + XATTR_NAME_POSIX_ACL_DEFAULT)))) | |
36523 | + )) | |
c1595e42 | 36524 | + err = 0; |
b912730e AM |
36525 | + if (err && (verbose || au_debug_test())) |
36526 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
36527 | + goto out; |
36528 | + } | |
36529 | + | |
36530 | + /* unlock it temporary */ | |
5527c038 | 36531 | + h_idst = d_inode(h_dst); |
febd17d6 | 36532 | + inode_unlock(h_idst); |
c1595e42 | 36533 | + err = vfsub_setxattr(h_dst, name, *buf, ssz, /*flags*/0); |
febd17d6 | 36534 | + inode_lock_nested(h_idst, AuLsc_I_CHILD2); |
c1595e42 | 36535 | + if (unlikely(err)) { |
7e9cd9fe AM |
36536 | + if (verbose || au_debug_test()) |
36537 | + pr_err("%s, err %d\n", name, err); | |
c1595e42 JR |
36538 | + err = au_xattr_ignore(err, name, ignore_flags); |
36539 | + } | |
36540 | + | |
36541 | +out: | |
36542 | + return err; | |
36543 | +} | |
36544 | + | |
7e9cd9fe AM |
36545 | +int au_cpup_xattr(struct dentry *h_dst, struct dentry *h_src, int ignore_flags, |
36546 | + unsigned int verbose) | |
c1595e42 JR |
36547 | +{ |
36548 | + int err, unlocked, acl_access, acl_default; | |
36549 | + ssize_t ssz; | |
36550 | + struct inode *h_isrc, *h_idst; | |
36551 | + char *value, *p, *o, *e; | |
36552 | + | |
36553 | + /* try stopping to update the source inode while we are referencing */ | |
7e9cd9fe | 36554 | + /* there should not be the parent-child relationship between them */ |
5527c038 JR |
36555 | + h_isrc = d_inode(h_src); |
36556 | + h_idst = d_inode(h_dst); | |
febd17d6 | 36557 | + inode_unlock(h_idst); |
be118d29 | 36558 | + inode_lock_shared_nested(h_isrc, AuLsc_I_CHILD); |
febd17d6 | 36559 | + inode_lock_nested(h_idst, AuLsc_I_CHILD2); |
c1595e42 JR |
36560 | + unlocked = 0; |
36561 | + | |
36562 | + /* some filesystems don't list POSIX ACL, for example tmpfs */ | |
36563 | + ssz = vfs_listxattr(h_src, NULL, 0); | |
36564 | + err = ssz; | |
36565 | + if (unlikely(err < 0)) { | |
36566 | + AuTraceErr(err); | |
36567 | + if (err == -ENODATA | |
36568 | + || err == -EOPNOTSUPP) | |
36569 | + err = 0; /* ignore */ | |
36570 | + goto out; | |
36571 | + } | |
36572 | + | |
36573 | + err = 0; | |
36574 | + p = NULL; | |
36575 | + o = NULL; | |
36576 | + if (ssz) { | |
36577 | + err = -ENOMEM; | |
36578 | + p = kmalloc(ssz, GFP_NOFS); | |
36579 | + o = p; | |
36580 | + if (unlikely(!p)) | |
36581 | + goto out; | |
36582 | + err = vfs_listxattr(h_src, p, ssz); | |
36583 | + } | |
3c1bdaff | 36584 | + inode_unlock_shared(h_isrc); |
c1595e42 JR |
36585 | + unlocked = 1; |
36586 | + AuDbg("err %d, ssz %zd\n", err, ssz); | |
36587 | + if (unlikely(err < 0)) | |
36588 | + goto out_free; | |
36589 | + | |
36590 | + err = 0; | |
36591 | + e = p + ssz; | |
36592 | + value = NULL; | |
36593 | + acl_access = 0; | |
36594 | + acl_default = 0; | |
36595 | + while (!err && p < e) { | |
36596 | + acl_access |= !strncmp(p, XATTR_NAME_POSIX_ACL_ACCESS, | |
36597 | + sizeof(XATTR_NAME_POSIX_ACL_ACCESS) - 1); | |
36598 | + acl_default |= !strncmp(p, XATTR_NAME_POSIX_ACL_DEFAULT, | |
36599 | + sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) | |
36600 | + - 1); | |
7e9cd9fe AM |
36601 | + err = au_do_cpup_xattr(h_dst, h_src, p, &value, ignore_flags, |
36602 | + verbose); | |
c1595e42 JR |
36603 | + p += strlen(p) + 1; |
36604 | + } | |
36605 | + AuTraceErr(err); | |
36606 | + ignore_flags |= au_xattr_out_of_list; | |
36607 | + if (!err && !acl_access) { | |
36608 | + err = au_do_cpup_xattr(h_dst, h_src, | |
36609 | + XATTR_NAME_POSIX_ACL_ACCESS, &value, | |
7e9cd9fe | 36610 | + ignore_flags, verbose); |
c1595e42 JR |
36611 | + AuTraceErr(err); |
36612 | + } | |
36613 | + if (!err && !acl_default) { | |
36614 | + err = au_do_cpup_xattr(h_dst, h_src, | |
36615 | + XATTR_NAME_POSIX_ACL_DEFAULT, &value, | |
7e9cd9fe | 36616 | + ignore_flags, verbose); |
c1595e42 JR |
36617 | + AuTraceErr(err); |
36618 | + } | |
36619 | + | |
9f237c51 | 36620 | + au_kfree_try_rcu(value); |
c1595e42 JR |
36621 | + |
36622 | +out_free: | |
9f237c51 | 36623 | + au_kfree_try_rcu(o); |
c1595e42 JR |
36624 | +out: |
36625 | + if (!unlocked) | |
3c1bdaff | 36626 | + inode_unlock_shared(h_isrc); |
c1595e42 JR |
36627 | + AuTraceErr(err); |
36628 | + return err; | |
36629 | +} | |
36630 | + | |
36631 | +/* ---------------------------------------------------------------------- */ | |
36632 | + | |
a2654f78 AM |
36633 | +static int au_smack_reentering(struct super_block *sb) |
36634 | +{ | |
36635 | +#if IS_ENABLED(CONFIG_SECURITY_SMACK) | |
36636 | + /* | |
36637 | + * as a part of lookup, smack_d_instantiate() is called, and it calls | |
36638 | + * i_op->getxattr(). ouch. | |
36639 | + */ | |
36640 | + return si_pid_test(sb); | |
36641 | +#else | |
36642 | + return 0; | |
36643 | +#endif | |
36644 | +} | |
36645 | + | |
c1595e42 JR |
36646 | +enum { |
36647 | + AU_XATTR_LIST, | |
36648 | + AU_XATTR_GET | |
36649 | +}; | |
36650 | + | |
36651 | +struct au_lgxattr { | |
36652 | + int type; | |
36653 | + union { | |
36654 | + struct { | |
36655 | + char *list; | |
36656 | + size_t size; | |
36657 | + } list; | |
36658 | + struct { | |
36659 | + const char *name; | |
36660 | + void *value; | |
36661 | + size_t size; | |
36662 | + } get; | |
36663 | + } u; | |
36664 | +}; | |
36665 | + | |
36666 | +static ssize_t au_lgxattr(struct dentry *dentry, struct au_lgxattr *arg) | |
36667 | +{ | |
36668 | + ssize_t err; | |
a2654f78 | 36669 | + int reenter; |
c1595e42 JR |
36670 | + struct path h_path; |
36671 | + struct super_block *sb; | |
36672 | + | |
36673 | + sb = dentry->d_sb; | |
a2654f78 AM |
36674 | + reenter = au_smack_reentering(sb); |
36675 | + if (!reenter) { | |
36676 | + err = si_read_lock(sb, AuLock_FLUSH | AuLock_NOPLM); | |
36677 | + if (unlikely(err)) | |
36678 | + goto out; | |
36679 | + } | |
36680 | + err = au_h_path_getattr(dentry, /*force*/1, &h_path, reenter); | |
c1595e42 JR |
36681 | + if (unlikely(err)) |
36682 | + goto out_si; | |
36683 | + if (unlikely(!h_path.dentry)) | |
36684 | + /* illegally overlapped or something */ | |
36685 | + goto out_di; /* pretending success */ | |
36686 | + | |
36687 | + /* always topmost entry only */ | |
36688 | + switch (arg->type) { | |
36689 | + case AU_XATTR_LIST: | |
36690 | + err = vfs_listxattr(h_path.dentry, | |
36691 | + arg->u.list.list, arg->u.list.size); | |
36692 | + break; | |
36693 | + case AU_XATTR_GET: | |
5afbbe0d | 36694 | + AuDebugOn(d_is_negative(h_path.dentry)); |
c1595e42 JR |
36695 | + err = vfs_getxattr(h_path.dentry, |
36696 | + arg->u.get.name, arg->u.get.value, | |
36697 | + arg->u.get.size); | |
36698 | + break; | |
36699 | + } | |
36700 | + | |
36701 | +out_di: | |
a2654f78 AM |
36702 | + if (!reenter) |
36703 | + di_read_unlock(dentry, AuLock_IR); | |
c1595e42 | 36704 | +out_si: |
a2654f78 AM |
36705 | + if (!reenter) |
36706 | + si_read_unlock(sb); | |
c1595e42 JR |
36707 | +out: |
36708 | + AuTraceErr(err); | |
36709 | + return err; | |
36710 | +} | |
36711 | + | |
36712 | +ssize_t aufs_listxattr(struct dentry *dentry, char *list, size_t size) | |
36713 | +{ | |
36714 | + struct au_lgxattr arg = { | |
36715 | + .type = AU_XATTR_LIST, | |
36716 | + .u.list = { | |
36717 | + .list = list, | |
36718 | + .size = size | |
36719 | + }, | |
36720 | + }; | |
36721 | + | |
36722 | + return au_lgxattr(dentry, &arg); | |
36723 | +} | |
36724 | + | |
f2c43d5f AM |
36725 | +static ssize_t au_getxattr(struct dentry *dentry, |
36726 | + struct inode *inode __maybe_unused, | |
36727 | + const char *name, void *value, size_t size) | |
c1595e42 JR |
36728 | +{ |
36729 | + struct au_lgxattr arg = { | |
36730 | + .type = AU_XATTR_GET, | |
36731 | + .u.get = { | |
36732 | + .name = name, | |
36733 | + .value = value, | |
36734 | + .size = size | |
36735 | + }, | |
36736 | + }; | |
36737 | + | |
36738 | + return au_lgxattr(dentry, &arg); | |
36739 | +} | |
36740 | + | |
f2c43d5f AM |
36741 | +static int au_setxattr(struct dentry *dentry, struct inode *inode, |
36742 | + const char *name, const void *value, size_t size, | |
36743 | + int flags) | |
c1595e42 | 36744 | +{ |
f2c43d5f | 36745 | + struct au_sxattr arg = { |
c1595e42 JR |
36746 | + .type = AU_XATTR_SET, |
36747 | + .u.set = { | |
36748 | + .name = name, | |
36749 | + .value = value, | |
36750 | + .size = size, | |
36751 | + .flags = flags | |
36752 | + }, | |
36753 | + }; | |
36754 | + | |
f2c43d5f | 36755 | + return au_sxattr(dentry, inode, &arg); |
c1595e42 JR |
36756 | +} |
36757 | + | |
36758 | +/* ---------------------------------------------------------------------- */ | |
36759 | + | |
f2c43d5f AM |
36760 | +static int au_xattr_get(const struct xattr_handler *handler, |
36761 | + struct dentry *dentry, struct inode *inode, | |
36762 | + const char *name, void *buffer, size_t size) | |
c1595e42 | 36763 | +{ |
f2c43d5f | 36764 | + return au_getxattr(dentry, inode, name, buffer, size); |
c1595e42 JR |
36765 | +} |
36766 | + | |
f2c43d5f AM |
36767 | +static int au_xattr_set(const struct xattr_handler *handler, |
36768 | + struct dentry *dentry, struct inode *inode, | |
36769 | + const char *name, const void *value, size_t size, | |
36770 | + int flags) | |
c1595e42 | 36771 | +{ |
f2c43d5f | 36772 | + return au_setxattr(dentry, inode, name, value, size, flags); |
c1595e42 JR |
36773 | +} |
36774 | + | |
36775 | +static const struct xattr_handler au_xattr_handler = { | |
f2c43d5f AM |
36776 | + .name = "", |
36777 | + .prefix = "", | |
c1595e42 JR |
36778 | + .get = au_xattr_get, |
36779 | + .set = au_xattr_set | |
c1595e42 JR |
36780 | +}; |
36781 | + | |
36782 | +static const struct xattr_handler *au_xattr_handlers[] = { | |
a2654f78 AM |
36783 | +#ifdef CONFIG_FS_POSIX_ACL |
36784 | + &posix_acl_access_xattr_handler, | |
36785 | + &posix_acl_default_xattr_handler, | |
36786 | +#endif | |
36787 | + &au_xattr_handler, /* must be last */ | |
f2c43d5f | 36788 | + NULL |
c1595e42 JR |
36789 | +}; |
36790 | + | |
36791 | +void au_xattr_init(struct super_block *sb) | |
36792 | +{ | |
f2c43d5f | 36793 | + sb->s_xattr = au_xattr_handlers; |
c1595e42 | 36794 | +} |
7f207e10 | 36795 | diff -urN /usr/share/empty/fs/aufs/xino.c linux/fs/aufs/xino.c |
eca34b5c | 36796 | --- /usr/share/empty/fs/aufs/xino.c 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 36797 | +++ linux/fs/aufs/xino.c 2020-01-27 10:57:18.182205184 +0100 |
83b672a5 | 36798 | @@ -0,0 +1,1965 @@ |
cd7a4cd9 | 36799 | +// SPDX-License-Identifier: GPL-2.0 |
1facf9fc | 36800 | +/* |
d58c55f2 | 36801 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
1facf9fc | 36802 | + * |
36803 | + * This program, aufs is free software; you can redistribute it and/or modify | |
36804 | + * it under the terms of the GNU General Public License as published by | |
36805 | + * the Free Software Foundation; either version 2 of the License, or | |
36806 | + * (at your option) any later version. | |
dece6358 AM |
36807 | + * |
36808 | + * This program is distributed in the hope that it will be useful, | |
36809 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
36810 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
36811 | + * GNU General Public License for more details. | |
36812 | + * | |
36813 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 36814 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1facf9fc | 36815 | + */ |
36816 | + | |
36817 | +/* | |
36818 | + * external inode number translation table and bitmap | |
062440b3 AM |
36819 | + * |
36820 | + * things to consider | |
36821 | + * - the lifetime | |
36822 | + * + au_xino object | |
36823 | + * + XINO files (xino, xib, xigen) | |
36824 | + * + dynamic debugfs entries (xiN) | |
36825 | + * + static debugfs entries (xib, xigen) | |
36826 | + * + static sysfs entry (xi_path) | |
36827 | + * - several entry points to handle them. | |
36828 | + * + mount(2) without xino option (default) | |
36829 | + * + mount(2) with xino option | |
36830 | + * + mount(2) with noxino option | |
36831 | + * + umount(2) | |
36832 | + * + remount with add/del branches | |
36833 | + * + remount with xino/noxino options | |
1facf9fc | 36834 | + */ |
36835 | + | |
36836 | +#include <linux/seq_file.h> | |
392086de | 36837 | +#include <linux/statfs.h> |
1facf9fc | 36838 | +#include "aufs.h" |
36839 | + | |
062440b3 AM |
36840 | +static aufs_bindex_t sbr_find_shared(struct super_block *sb, aufs_bindex_t btop, |
36841 | + aufs_bindex_t bbot, | |
36842 | + struct super_block *h_sb) | |
1facf9fc | 36843 | +{ |
062440b3 AM |
36844 | + /* todo: try binary-search if the branches are many */ |
36845 | + for (; btop <= bbot; btop++) | |
36846 | + if (h_sb == au_sbr_sb(sb, btop)) | |
36847 | + return btop; | |
36848 | + return -1; | |
be52b249 AM |
36849 | +} |
36850 | + | |
062440b3 AM |
36851 | +/* |
36852 | + * find another branch who is on the same filesystem of the specified | |
36853 | + * branch{@btgt}. search until @bbot. | |
36854 | + */ | |
36855 | +static aufs_bindex_t is_sb_shared(struct super_block *sb, aufs_bindex_t btgt, | |
36856 | + aufs_bindex_t bbot) | |
1facf9fc | 36857 | +{ |
062440b3 AM |
36858 | + aufs_bindex_t bindex; |
36859 | + struct super_block *tgt_sb; | |
1facf9fc | 36860 | + |
062440b3 AM |
36861 | + tgt_sb = au_sbr_sb(sb, btgt); |
36862 | + bindex = sbr_find_shared(sb, /*btop*/0, btgt - 1, tgt_sb); | |
36863 | + if (bindex < 0) | |
36864 | + bindex = sbr_find_shared(sb, btgt + 1, bbot, tgt_sb); | |
1facf9fc | 36865 | + |
062440b3 | 36866 | + return bindex; |
1facf9fc | 36867 | +} |
36868 | + | |
36869 | +/* ---------------------------------------------------------------------- */ | |
36870 | + | |
36871 | +/* | |
062440b3 | 36872 | + * stop unnecessary notify events at creating xino files |
1facf9fc | 36873 | + */ |
acd2b654 AM |
36874 | + |
36875 | +aufs_bindex_t au_xi_root(struct super_block *sb, struct dentry *dentry) | |
36876 | +{ | |
36877 | + aufs_bindex_t bfound, bindex, bbot; | |
36878 | + struct dentry *parent; | |
36879 | + struct au_branch *br; | |
36880 | + | |
36881 | + bfound = -1; | |
36882 | + parent = dentry->d_parent; /* safe d_parent access */ | |
36883 | + bbot = au_sbbot(sb); | |
36884 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
36885 | + br = au_sbr(sb, bindex); | |
36886 | + if (au_br_dentry(br) == parent) { | |
36887 | + bfound = bindex; | |
36888 | + break; | |
36889 | + } | |
36890 | + } | |
36891 | + | |
36892 | + AuDbg("bfound b%d\n", bfound); | |
36893 | + return bfound; | |
36894 | +} | |
36895 | + | |
062440b3 AM |
36896 | +struct au_xino_lock_dir { |
36897 | + struct au_hinode *hdir; | |
36898 | + struct dentry *parent; | |
36899 | + struct inode *dir; | |
36900 | +}; | |
36901 | + | |
36902 | +static struct dentry *au_dget_parent_lock(struct dentry *dentry, | |
36903 | + unsigned int lsc) | |
1facf9fc | 36904 | +{ |
062440b3 AM |
36905 | + struct dentry *parent; |
36906 | + struct inode *dir; | |
1facf9fc | 36907 | + |
062440b3 | 36908 | + parent = dget_parent(dentry); |
5527c038 | 36909 | + dir = d_inode(parent); |
062440b3 AM |
36910 | + inode_lock_nested(dir, lsc); |
36911 | +#if 0 /* it should not happen */ | |
36912 | + spin_lock(&dentry->d_lock); | |
36913 | + if (unlikely(dentry->d_parent != parent)) { | |
36914 | + spin_unlock(&dentry->d_lock); | |
36915 | + inode_unlock(dir); | |
36916 | + dput(parent); | |
36917 | + parent = NULL; | |
1facf9fc | 36918 | + goto out; |
36919 | + } | |
062440b3 | 36920 | + spin_unlock(&dentry->d_lock); |
1facf9fc | 36921 | + |
4f0767ce | 36922 | +out: |
062440b3 AM |
36923 | +#endif |
36924 | + return parent; | |
1facf9fc | 36925 | +} |
36926 | + | |
062440b3 | 36927 | +static void au_xino_lock_dir(struct super_block *sb, struct path *xipath, |
1facf9fc | 36928 | + struct au_xino_lock_dir *ldir) |
36929 | +{ | |
acd2b654 | 36930 | + aufs_bindex_t bindex; |
1facf9fc | 36931 | + |
36932 | + ldir->hdir = NULL; | |
acd2b654 | 36933 | + bindex = au_xi_root(sb, xipath->dentry); |
1facf9fc | 36934 | + if (bindex >= 0) { |
062440b3 | 36935 | + /* rw branch root */ |
5527c038 | 36936 | + ldir->hdir = au_hi(d_inode(sb->s_root), bindex); |
5afbbe0d | 36937 | + au_hn_inode_lock_nested(ldir->hdir, AuLsc_I_PARENT); |
1facf9fc | 36938 | + } else { |
062440b3 AM |
36939 | + /* other */ |
36940 | + ldir->parent = au_dget_parent_lock(xipath->dentry, | |
36941 | + AuLsc_I_PARENT); | |
febd17d6 | 36942 | + ldir->dir = d_inode(ldir->parent); |
1facf9fc | 36943 | + } |
36944 | +} | |
36945 | + | |
36946 | +static void au_xino_unlock_dir(struct au_xino_lock_dir *ldir) | |
36947 | +{ | |
36948 | + if (ldir->hdir) | |
5afbbe0d | 36949 | + au_hn_inode_unlock(ldir->hdir); |
1facf9fc | 36950 | + else { |
febd17d6 | 36951 | + inode_unlock(ldir->dir); |
1facf9fc | 36952 | + dput(ldir->parent); |
36953 | + } | |
36954 | +} | |
36955 | + | |
36956 | +/* ---------------------------------------------------------------------- */ | |
36957 | + | |
062440b3 AM |
36958 | +/* |
36959 | + * create and set a new xino file | |
36960 | + */ | |
83b672a5 AM |
36961 | +struct file *au_xino_create(struct super_block *sb, char *fpath, int silent, |
36962 | + int wbrtop) | |
062440b3 AM |
36963 | +{ |
36964 | + struct file *file; | |
36965 | + struct dentry *h_parent, *d; | |
36966 | + struct inode *h_dir, *inode; | |
36967 | + int err; | |
83b672a5 | 36968 | + static DEFINE_MUTEX(mtx); |
062440b3 AM |
36969 | + |
36970 | + /* | |
36971 | + * at mount-time, and the xino file is the default path, | |
36972 | + * hnotify is disabled so we have no notify events to ignore. | |
36973 | + * when a user specified the xino, we cannot get au_hdir to be ignored. | |
36974 | + */ | |
83b672a5 AM |
36975 | + if (!wbrtop) |
36976 | + mutex_lock(&mtx); | |
062440b3 AM |
36977 | + file = vfsub_filp_open(fpath, O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE |
36978 | + /* | __FMODE_NONOTIFY */, | |
cd7a4cd9 | 36979 | + 0666); |
062440b3 | 36980 | + if (IS_ERR(file)) { |
83b672a5 AM |
36981 | + if (!wbrtop) |
36982 | + mutex_unlock(&mtx); | |
062440b3 AM |
36983 | + if (!silent) |
36984 | + pr_err("open %s(%ld)\n", fpath, PTR_ERR(file)); | |
36985 | + return file; | |
36986 | + } | |
36987 | + | |
36988 | + /* keep file count */ | |
36989 | + err = 0; | |
36990 | + d = file->f_path.dentry; | |
36991 | + h_parent = au_dget_parent_lock(d, AuLsc_I_PARENT); | |
83b672a5 AM |
36992 | + if (!wbrtop) |
36993 | + mutex_unlock(&mtx); | |
062440b3 AM |
36994 | + /* mnt_want_write() is unnecessary here */ |
36995 | + h_dir = d_inode(h_parent); | |
36996 | + inode = file_inode(file); | |
36997 | + /* no delegation since it is just created */ | |
36998 | + if (inode->i_nlink) | |
36999 | + err = vfsub_unlink(h_dir, &file->f_path, /*delegated*/NULL, | |
37000 | + /*force*/0); | |
37001 | + inode_unlock(h_dir); | |
37002 | + dput(h_parent); | |
37003 | + if (unlikely(err)) { | |
37004 | + if (!silent) | |
37005 | + pr_err("unlink %s(%d)\n", fpath, err); | |
37006 | + goto out; | |
37007 | + } | |
37008 | + | |
37009 | + err = -EINVAL; | |
37010 | + if (unlikely(sb == d->d_sb)) { | |
37011 | + if (!silent) | |
37012 | + pr_err("%s must be outside\n", fpath); | |
37013 | + goto out; | |
37014 | + } | |
37015 | + if (unlikely(au_test_fs_bad_xino(d->d_sb))) { | |
37016 | + if (!silent) | |
37017 | + pr_err("xino doesn't support %s(%s)\n", | |
37018 | + fpath, au_sbtype(d->d_sb)); | |
37019 | + goto out; | |
37020 | + } | |
37021 | + return file; /* success */ | |
37022 | + | |
37023 | +out: | |
37024 | + fput(file); | |
37025 | + file = ERR_PTR(err); | |
37026 | + return file; | |
37027 | +} | |
37028 | + | |
37029 | +/* | |
37030 | + * create a new xinofile at the same place/path as @base. | |
37031 | + */ | |
37032 | +struct file *au_xino_create2(struct super_block *sb, struct path *base, | |
37033 | + struct file *copy_src) | |
37034 | +{ | |
37035 | + struct file *file; | |
37036 | + struct dentry *dentry, *parent; | |
37037 | + struct inode *dir, *delegated; | |
37038 | + struct qstr *name; | |
37039 | + struct path path; | |
37040 | + int err, do_unlock; | |
37041 | + struct au_xino_lock_dir ldir; | |
37042 | + | |
37043 | + do_unlock = 1; | |
37044 | + au_xino_lock_dir(sb, base, &ldir); | |
37045 | + dentry = base->dentry; | |
37046 | + parent = dentry->d_parent; /* dir inode is locked */ | |
37047 | + dir = d_inode(parent); | |
37048 | + IMustLock(dir); | |
37049 | + | |
37050 | + name = &dentry->d_name; | |
37051 | + path.dentry = vfsub_lookup_one_len(name->name, parent, name->len); | |
37052 | + if (IS_ERR(path.dentry)) { | |
37053 | + file = (void *)path.dentry; | |
37054 | + pr_err("%pd lookup err %ld\n", dentry, PTR_ERR(path.dentry)); | |
37055 | + goto out; | |
37056 | + } | |
37057 | + | |
37058 | + /* no need to mnt_want_write() since we call dentry_open() later */ | |
cd7a4cd9 | 37059 | + err = vfs_create(dir, path.dentry, 0666, NULL); |
062440b3 AM |
37060 | + if (unlikely(err)) { |
37061 | + file = ERR_PTR(err); | |
37062 | + pr_err("%pd create err %d\n", dentry, err); | |
37063 | + goto out_dput; | |
37064 | + } | |
37065 | + | |
37066 | + path.mnt = base->mnt; | |
37067 | + file = vfsub_dentry_open(&path, | |
37068 | + O_RDWR | O_CREAT | O_EXCL | O_LARGEFILE | |
37069 | + /* | __FMODE_NONOTIFY */); | |
37070 | + if (IS_ERR(file)) { | |
37071 | + pr_err("%pd open err %ld\n", dentry, PTR_ERR(file)); | |
37072 | + goto out_dput; | |
37073 | + } | |
37074 | + | |
37075 | + delegated = NULL; | |
37076 | + err = vfsub_unlink(dir, &file->f_path, &delegated, /*force*/0); | |
37077 | + au_xino_unlock_dir(&ldir); | |
37078 | + do_unlock = 0; | |
37079 | + if (unlikely(err == -EWOULDBLOCK)) { | |
37080 | + pr_warn("cannot retry for NFSv4 delegation" | |
37081 | + " for an internal unlink\n"); | |
37082 | + iput(delegated); | |
37083 | + } | |
37084 | + if (unlikely(err)) { | |
37085 | + pr_err("%pd unlink err %d\n", dentry, err); | |
37086 | + goto out_fput; | |
37087 | + } | |
37088 | + | |
37089 | + if (copy_src) { | |
37090 | + /* no one can touch copy_src xino */ | |
37091 | + err = au_copy_file(file, copy_src, vfsub_f_size_read(copy_src)); | |
37092 | + if (unlikely(err)) { | |
37093 | + pr_err("%pd copy err %d\n", dentry, err); | |
37094 | + goto out_fput; | |
37095 | + } | |
37096 | + } | |
37097 | + goto out_dput; /* success */ | |
1facf9fc | 37098 | + |
062440b3 AM |
37099 | +out_fput: |
37100 | + fput(file); | |
37101 | + file = ERR_PTR(err); | |
37102 | +out_dput: | |
37103 | + dput(path.dentry); | |
37104 | +out: | |
37105 | + if (do_unlock) | |
37106 | + au_xino_unlock_dir(&ldir); | |
37107 | + return file; | |
37108 | +} | |
37109 | + | |
acd2b654 AM |
37110 | +struct file *au_xino_file1(struct au_xino *xi) |
37111 | +{ | |
37112 | + struct file *file; | |
37113 | + unsigned int u, nfile; | |
37114 | + | |
37115 | + file = NULL; | |
37116 | + nfile = xi->xi_nfile; | |
37117 | + for (u = 0; u < nfile; u++) { | |
37118 | + file = xi->xi_file[u]; | |
37119 | + if (file) | |
37120 | + break; | |
37121 | + } | |
37122 | + | |
37123 | + return file; | |
37124 | +} | |
37125 | + | |
37126 | +static int au_xino_file_set(struct au_xino *xi, int idx, struct file *file) | |
37127 | +{ | |
37128 | + int err; | |
37129 | + struct file *f; | |
37130 | + void *p; | |
37131 | + | |
37132 | + if (file) | |
37133 | + get_file(file); | |
37134 | + | |
37135 | + err = 0; | |
37136 | + f = NULL; | |
37137 | + if (idx < xi->xi_nfile) { | |
37138 | + f = xi->xi_file[idx]; | |
37139 | + if (f) | |
37140 | + fput(f); | |
37141 | + } else { | |
37142 | + p = au_kzrealloc(xi->xi_file, | |
37143 | + sizeof(*xi->xi_file) * xi->xi_nfile, | |
37144 | + sizeof(*xi->xi_file) * (idx + 1), | |
37145 | + GFP_NOFS, /*may_shrink*/0); | |
37146 | + if (p) { | |
37147 | + MtxMustLock(&xi->xi_mtx); | |
37148 | + xi->xi_file = p; | |
37149 | + xi->xi_nfile = idx + 1; | |
37150 | + } else { | |
37151 | + err = -ENOMEM; | |
37152 | + if (file) | |
37153 | + fput(file); | |
37154 | + goto out; | |
37155 | + } | |
37156 | + } | |
37157 | + xi->xi_file[idx] = file; | |
37158 | + | |
37159 | +out: | |
37160 | + return err; | |
37161 | +} | |
37162 | + | |
37163 | +/* | |
37164 | + * if @xinew->xi is not set, then create new xigen file. | |
37165 | + */ | |
37166 | +struct file *au_xi_new(struct super_block *sb, struct au_xi_new *xinew) | |
37167 | +{ | |
37168 | + struct file *file; | |
37169 | + int err; | |
37170 | + | |
37171 | + SiMustAnyLock(sb); | |
37172 | + | |
37173 | + file = au_xino_create2(sb, xinew->base, xinew->copy_src); | |
37174 | + if (IS_ERR(file)) { | |
37175 | + err = PTR_ERR(file); | |
37176 | + pr_err("%s[%d], err %d\n", | |
37177 | + xinew->xi ? "xino" : "xigen", | |
37178 | + xinew->idx, err); | |
37179 | + goto out; | |
37180 | + } | |
37181 | + | |
37182 | + if (xinew->xi) | |
37183 | + err = au_xino_file_set(xinew->xi, xinew->idx, file); | |
37184 | + else { | |
37185 | + BUG(); | |
37186 | + /* todo: make xigen file an array */ | |
37187 | + /* err = au_xigen_file_set(sb, xinew->idx, file); */ | |
37188 | + } | |
37189 | + fput(file); | |
37190 | + if (unlikely(err)) | |
37191 | + file = ERR_PTR(err); | |
37192 | + | |
37193 | +out: | |
37194 | + return file; | |
37195 | +} | |
37196 | + | |
062440b3 AM |
37197 | +/* ---------------------------------------------------------------------- */ |
37198 | + | |
37199 | +/* | |
37200 | + * truncate xino files | |
37201 | + */ | |
acd2b654 AM |
37202 | +static int au_xino_do_trunc(struct super_block *sb, aufs_bindex_t bindex, |
37203 | + int idx, struct kstatfs *st) | |
1facf9fc | 37204 | +{ |
37205 | + int err; | |
392086de | 37206 | + blkcnt_t blocks; |
acd2b654 AM |
37207 | + struct file *file, *new_xino; |
37208 | + struct au_xi_new xinew = { | |
37209 | + .idx = idx | |
37210 | + }; | |
37211 | + | |
37212 | + err = 0; | |
37213 | + xinew.xi = au_sbr(sb, bindex)->br_xino; | |
37214 | + file = au_xino_file(xinew.xi, idx); | |
37215 | + if (!file) | |
37216 | + goto out; | |
37217 | + | |
37218 | + xinew.base = &file->f_path; | |
37219 | + err = vfs_statfs(xinew.base, st); | |
37220 | + if (unlikely(err)) { | |
37221 | + AuErr1("statfs err %d, ignored\n", err); | |
37222 | + err = 0; | |
37223 | + goto out; | |
37224 | + } | |
37225 | + | |
37226 | + blocks = file_inode(file)->i_blocks; | |
37227 | + pr_info("begin truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n", | |
37228 | + bindex, idx, (u64)blocks, st->f_bfree, st->f_blocks); | |
37229 | + | |
37230 | + xinew.copy_src = file; | |
37231 | + new_xino = au_xi_new(sb, &xinew); | |
37232 | + if (IS_ERR(new_xino)) { | |
37233 | + err = PTR_ERR(new_xino); | |
37234 | + pr_err("xino(b%d-%d), err %d, ignored\n", bindex, idx, err); | |
37235 | + goto out; | |
37236 | + } | |
37237 | + | |
37238 | + err = vfs_statfs(&new_xino->f_path, st); | |
37239 | + if (!err) | |
37240 | + pr_info("end truncating xino(b%d-%d), ib%llu, %llu/%llu free blks\n", | |
37241 | + bindex, idx, (u64)file_inode(new_xino)->i_blocks, | |
37242 | + st->f_bfree, st->f_blocks); | |
37243 | + else { | |
37244 | + AuErr1("statfs err %d, ignored\n", err); | |
37245 | + err = 0; | |
37246 | + } | |
37247 | + | |
37248 | +out: | |
37249 | + return err; | |
37250 | +} | |
37251 | + | |
37252 | +int au_xino_trunc(struct super_block *sb, aufs_bindex_t bindex, int idx_begin) | |
37253 | +{ | |
37254 | + int err, i; | |
37255 | + unsigned long jiffy; | |
062440b3 | 37256 | + aufs_bindex_t bbot; |
392086de | 37257 | + struct kstatfs *st; |
1facf9fc | 37258 | + struct au_branch *br; |
acd2b654 | 37259 | + struct au_xino *xi; |
1facf9fc | 37260 | + |
392086de | 37261 | + err = -ENOMEM; |
be52b249 | 37262 | + st = kmalloc(sizeof(*st), GFP_NOFS); |
392086de AM |
37263 | + if (unlikely(!st)) |
37264 | + goto out; | |
37265 | + | |
1facf9fc | 37266 | + err = -EINVAL; |
5afbbe0d AM |
37267 | + bbot = au_sbbot(sb); |
37268 | + if (unlikely(bindex < 0 || bbot < bindex)) | |
392086de | 37269 | + goto out_st; |
392086de | 37270 | + |
1facf9fc | 37271 | + err = 0; |
acd2b654 AM |
37272 | + jiffy = jiffies; |
37273 | + br = au_sbr(sb, bindex); | |
37274 | + xi = br->br_xino; | |
37275 | + for (i = idx_begin; !err && i < xi->xi_nfile; i++) | |
37276 | + err = au_xino_do_trunc(sb, bindex, i, st); | |
37277 | + if (!err) | |
37278 | + au_sbi(sb)->si_xino_jiffy = jiffy; | |
392086de AM |
37279 | + |
37280 | +out_st: | |
9f237c51 | 37281 | + au_kfree_rcu(st); |
4f0767ce | 37282 | +out: |
1facf9fc | 37283 | + return err; |
37284 | +} | |
37285 | + | |
37286 | +struct xino_do_trunc_args { | |
37287 | + struct super_block *sb; | |
37288 | + struct au_branch *br; | |
acd2b654 | 37289 | + int idx; |
1facf9fc | 37290 | +}; |
37291 | + | |
37292 | +static void xino_do_trunc(void *_args) | |
37293 | +{ | |
37294 | + struct xino_do_trunc_args *args = _args; | |
37295 | + struct super_block *sb; | |
37296 | + struct au_branch *br; | |
37297 | + struct inode *dir; | |
acd2b654 | 37298 | + int err, idx; |
1facf9fc | 37299 | + aufs_bindex_t bindex; |
37300 | + | |
37301 | + err = 0; | |
37302 | + sb = args->sb; | |
5527c038 | 37303 | + dir = d_inode(sb->s_root); |
1facf9fc | 37304 | + br = args->br; |
acd2b654 | 37305 | + idx = args->idx; |
1facf9fc | 37306 | + |
37307 | + si_noflush_write_lock(sb); | |
37308 | + ii_read_lock_parent(dir); | |
37309 | + bindex = au_br_index(sb, br->br_id); | |
acd2b654 | 37310 | + err = au_xino_trunc(sb, bindex, idx); |
1facf9fc | 37311 | + ii_read_unlock(dir); |
37312 | + if (unlikely(err)) | |
392086de | 37313 | + pr_warn("err b%d, (%d)\n", bindex, err); |
062440b3 | 37314 | + atomic_dec(&br->br_xino->xi_truncating); |
acd2b654 | 37315 | + au_lcnt_dec(&br->br_count); |
1facf9fc | 37316 | + si_write_unlock(sb); |
027c5e7a | 37317 | + au_nwt_done(&au_sbi(sb)->si_nowait); |
9f237c51 | 37318 | + au_kfree_rcu(args); |
1facf9fc | 37319 | +} |
37320 | + | |
acd2b654 AM |
37321 | +/* |
37322 | + * returns the index in the xi_file array whose corresponding file is necessary | |
37323 | + * to truncate, or -1 which means no need to truncate. | |
37324 | + */ | |
392086de AM |
37325 | +static int xino_trunc_test(struct super_block *sb, struct au_branch *br) |
37326 | +{ | |
37327 | + int err; | |
acd2b654 | 37328 | + unsigned int u; |
392086de AM |
37329 | + struct kstatfs st; |
37330 | + struct au_sbinfo *sbinfo; | |
acd2b654 | 37331 | + struct au_xino *xi; |
062440b3 | 37332 | + struct file *file; |
392086de AM |
37333 | + |
37334 | + /* todo: si_xino_expire and the ratio should be customizable */ | |
37335 | + sbinfo = au_sbi(sb); | |
37336 | + if (time_before(jiffies, | |
37337 | + sbinfo->si_xino_jiffy + sbinfo->si_xino_expire)) | |
acd2b654 | 37338 | + return -1; |
392086de AM |
37339 | + |
37340 | + /* truncation border */ | |
acd2b654 AM |
37341 | + xi = br->br_xino; |
37342 | + for (u = 0; u < xi->xi_nfile; u++) { | |
37343 | + file = au_xino_file(xi, u); | |
37344 | + if (!file) | |
37345 | + continue; | |
37346 | + | |
37347 | + err = vfs_statfs(&file->f_path, &st); | |
37348 | + if (unlikely(err)) { | |
37349 | + AuErr1("statfs err %d, ignored\n", err); | |
37350 | + return -1; | |
37351 | + } | |
37352 | + if (div64_u64(st.f_bfree * 100, st.f_blocks) | |
37353 | + >= AUFS_XINO_DEF_TRUNC) | |
37354 | + return u; | |
392086de | 37355 | + } |
392086de | 37356 | + |
acd2b654 | 37357 | + return -1; |
392086de AM |
37358 | +} |
37359 | + | |
1facf9fc | 37360 | +static void xino_try_trunc(struct super_block *sb, struct au_branch *br) |
37361 | +{ | |
acd2b654 | 37362 | + int idx; |
1facf9fc | 37363 | + struct xino_do_trunc_args *args; |
37364 | + int wkq_err; | |
37365 | + | |
acd2b654 AM |
37366 | + idx = xino_trunc_test(sb, br); |
37367 | + if (idx < 0) | |
1facf9fc | 37368 | + return; |
37369 | + | |
062440b3 | 37370 | + if (atomic_inc_return(&br->br_xino->xi_truncating) > 1) |
1facf9fc | 37371 | + goto out; |
37372 | + | |
37373 | + /* lock and kfree() will be called in trunc_xino() */ | |
37374 | + args = kmalloc(sizeof(*args), GFP_NOFS); | |
37375 | + if (unlikely(!args)) { | |
37376 | + AuErr1("no memory\n"); | |
f0c0a007 | 37377 | + goto out; |
1facf9fc | 37378 | + } |
37379 | + | |
acd2b654 | 37380 | + au_lcnt_inc(&br->br_count); |
1facf9fc | 37381 | + args->sb = sb; |
37382 | + args->br = br; | |
acd2b654 | 37383 | + args->idx = idx; |
53392da6 | 37384 | + wkq_err = au_wkq_nowait(xino_do_trunc, args, sb, /*flags*/0); |
1facf9fc | 37385 | + if (!wkq_err) |
37386 | + return; /* success */ | |
37387 | + | |
4a4d8108 | 37388 | + pr_err("wkq %d\n", wkq_err); |
acd2b654 | 37389 | + au_lcnt_dec(&br->br_count); |
9f237c51 | 37390 | + au_kfree_rcu(args); |
1facf9fc | 37391 | + |
4f0767ce | 37392 | +out: |
062440b3 | 37393 | + atomic_dec(&br->br_xino->xi_truncating); |
1facf9fc | 37394 | +} |
37395 | + | |
37396 | +/* ---------------------------------------------------------------------- */ | |
37397 | + | |
acd2b654 AM |
37398 | +struct au_xi_calc { |
37399 | + int idx; | |
37400 | + loff_t pos; | |
37401 | +}; | |
37402 | + | |
37403 | +static void au_xi_calc(struct super_block *sb, ino_t h_ino, | |
37404 | + struct au_xi_calc *calc) | |
37405 | +{ | |
37406 | + loff_t maxent; | |
37407 | + | |
37408 | + maxent = au_xi_maxent(sb); | |
37409 | + calc->idx = div64_u64_rem(h_ino, maxent, &calc->pos); | |
37410 | + calc->pos *= sizeof(ino_t); | |
37411 | +} | |
37412 | + | |
37413 | +static int au_xino_do_new_async(struct super_block *sb, struct au_branch *br, | |
37414 | + struct au_xi_calc *calc) | |
37415 | +{ | |
37416 | + int err; | |
37417 | + struct file *file; | |
37418 | + struct au_xino *xi = br->br_xino; | |
37419 | + struct au_xi_new xinew = { | |
37420 | + .xi = xi | |
37421 | + }; | |
37422 | + | |
37423 | + SiMustAnyLock(sb); | |
37424 | + | |
37425 | + err = 0; | |
37426 | + if (!xi) | |
37427 | + goto out; | |
37428 | + | |
37429 | + mutex_lock(&xi->xi_mtx); | |
37430 | + file = au_xino_file(xi, calc->idx); | |
37431 | + if (file) | |
37432 | + goto out_mtx; | |
37433 | + | |
37434 | + file = au_xino_file(xi, /*idx*/-1); | |
37435 | + AuDebugOn(!file); | |
37436 | + xinew.idx = calc->idx; | |
37437 | + xinew.base = &file->f_path; | |
37438 | + /* xinew.copy_src = NULL; */ | |
37439 | + file = au_xi_new(sb, &xinew); | |
37440 | + if (IS_ERR(file)) | |
37441 | + err = PTR_ERR(file); | |
37442 | + | |
37443 | +out_mtx: | |
37444 | + mutex_unlock(&xi->xi_mtx); | |
37445 | +out: | |
37446 | + return err; | |
37447 | +} | |
37448 | + | |
37449 | +struct au_xino_do_new_async_args { | |
37450 | + struct super_block *sb; | |
37451 | + struct au_branch *br; | |
37452 | + struct au_xi_calc calc; | |
37453 | + ino_t ino; | |
37454 | +}; | |
37455 | + | |
9f237c51 AM |
37456 | +struct au_xi_writing { |
37457 | + struct hlist_bl_node node; | |
37458 | + ino_t h_ino, ino; | |
37459 | +}; | |
37460 | + | |
acd2b654 AM |
37461 | +static int au_xino_do_write(vfs_writef_t write, struct file *file, |
37462 | + struct au_xi_calc *calc, ino_t ino); | |
37463 | + | |
37464 | +static void au_xino_call_do_new_async(void *args) | |
37465 | +{ | |
37466 | + struct au_xino_do_new_async_args *a = args; | |
37467 | + struct au_branch *br; | |
37468 | + struct super_block *sb; | |
37469 | + struct au_sbinfo *sbi; | |
37470 | + struct inode *root; | |
37471 | + struct file *file; | |
9f237c51 AM |
37472 | + struct au_xi_writing *del, *p; |
37473 | + struct hlist_bl_head *hbl; | |
37474 | + struct hlist_bl_node *pos; | |
acd2b654 AM |
37475 | + int err; |
37476 | + | |
37477 | + br = a->br; | |
37478 | + sb = a->sb; | |
37479 | + sbi = au_sbi(sb); | |
37480 | + si_noflush_read_lock(sb); | |
37481 | + root = d_inode(sb->s_root); | |
37482 | + ii_read_lock_child(root); | |
37483 | + err = au_xino_do_new_async(sb, br, &a->calc); | |
9f237c51 AM |
37484 | + if (unlikely(err)) { |
37485 | + AuIOErr("err %d\n", err); | |
37486 | + goto out; | |
37487 | + } | |
37488 | + | |
37489 | + file = au_xino_file(br->br_xino, a->calc.idx); | |
37490 | + AuDebugOn(!file); | |
37491 | + err = au_xino_do_write(sbi->si_xwrite, file, &a->calc, a->ino); | |
37492 | + if (unlikely(err)) { | |
acd2b654 | 37493 | + AuIOErr("err %d\n", err); |
9f237c51 AM |
37494 | + goto out; |
37495 | + } | |
37496 | + | |
37497 | + del = NULL; | |
37498 | + hbl = &br->br_xino->xi_writing; | |
37499 | + hlist_bl_lock(hbl); | |
37500 | + au_hbl_for_each(pos, hbl) { | |
37501 | + p = container_of(pos, struct au_xi_writing, node); | |
37502 | + if (p->ino == a->ino) { | |
37503 | + del = p; | |
37504 | + hlist_bl_del(&p->node); | |
37505 | + break; | |
37506 | + } | |
37507 | + } | |
37508 | + hlist_bl_unlock(hbl); | |
37509 | + au_kfree_rcu(del); | |
37510 | + | |
37511 | +out: | |
acd2b654 AM |
37512 | + au_lcnt_dec(&br->br_count); |
37513 | + ii_read_unlock(root); | |
37514 | + si_read_unlock(sb); | |
37515 | + au_nwt_done(&sbi->si_nowait); | |
9f237c51 | 37516 | + au_kfree_rcu(a); |
acd2b654 AM |
37517 | +} |
37518 | + | |
37519 | +/* | |
37520 | + * create a new xino file asynchronously | |
37521 | + */ | |
37522 | +static int au_xino_new_async(struct super_block *sb, struct au_branch *br, | |
37523 | + struct au_xi_calc *calc, ino_t ino) | |
37524 | +{ | |
37525 | + int err; | |
37526 | + struct au_xino_do_new_async_args *arg; | |
37527 | + | |
37528 | + err = -ENOMEM; | |
37529 | + arg = kmalloc(sizeof(*arg), GFP_NOFS); | |
37530 | + if (unlikely(!arg)) | |
37531 | + goto out; | |
37532 | + | |
37533 | + arg->sb = sb; | |
37534 | + arg->br = br; | |
37535 | + arg->calc = *calc; | |
37536 | + arg->ino = ino; | |
37537 | + au_lcnt_inc(&br->br_count); | |
37538 | + err = au_wkq_nowait(au_xino_call_do_new_async, arg, sb, AuWkq_NEST); | |
37539 | + if (unlikely(err)) { | |
37540 | + pr_err("wkq %d\n", err); | |
37541 | + au_lcnt_dec(&br->br_count); | |
9f237c51 | 37542 | + au_kfree_rcu(arg); |
acd2b654 AM |
37543 | + } |
37544 | + | |
37545 | +out: | |
37546 | + return err; | |
37547 | +} | |
37548 | + | |
062440b3 AM |
37549 | +/* |
37550 | + * read @ino from xinofile for the specified branch{@sb, @bindex} | |
37551 | + * at the position of @h_ino. | |
37552 | + */ | |
37553 | +int au_xino_read(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
37554 | + ino_t *ino) | |
37555 | +{ | |
37556 | + int err; | |
37557 | + ssize_t sz; | |
acd2b654 | 37558 | + struct au_xi_calc calc; |
062440b3 | 37559 | + struct au_sbinfo *sbinfo; |
acd2b654 | 37560 | + struct file *file; |
9f237c51 AM |
37561 | + struct au_xino *xi; |
37562 | + struct hlist_bl_head *hbl; | |
37563 | + struct hlist_bl_node *pos; | |
37564 | + struct au_xi_writing *p; | |
062440b3 AM |
37565 | + |
37566 | + *ino = 0; | |
37567 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
37568 | + return 0; /* no xino */ | |
37569 | + | |
37570 | + err = 0; | |
acd2b654 | 37571 | + au_xi_calc(sb, h_ino, &calc); |
9f237c51 AM |
37572 | + xi = au_sbr(sb, bindex)->br_xino; |
37573 | + file = au_xino_file(xi, calc.idx); | |
37574 | + if (!file) { | |
37575 | + hbl = &xi->xi_writing; | |
37576 | + hlist_bl_lock(hbl); | |
37577 | + au_hbl_for_each(pos, hbl) { | |
37578 | + p = container_of(pos, struct au_xi_writing, node); | |
37579 | + if (p->h_ino == h_ino) { | |
37580 | + AuDbg("hi%llu, i%llu, found\n", | |
37581 | + (u64)p->h_ino, (u64)p->ino); | |
37582 | + *ino = p->ino; | |
37583 | + break; | |
37584 | + } | |
37585 | + } | |
37586 | + hlist_bl_unlock(hbl); | |
37587 | + return 0; | |
37588 | + } else if (vfsub_f_size_read(file) < calc.pos + sizeof(*ino)) | |
37589 | + return 0; /* no xino */ | |
062440b3 | 37590 | + |
acd2b654 AM |
37591 | + sbinfo = au_sbi(sb); |
37592 | + sz = xino_fread(sbinfo->si_xread, file, ino, sizeof(*ino), &calc.pos); | |
062440b3 AM |
37593 | + if (sz == sizeof(*ino)) |
37594 | + return 0; /* success */ | |
37595 | + | |
37596 | + err = sz; | |
37597 | + if (unlikely(sz >= 0)) { | |
37598 | + err = -EIO; | |
37599 | + AuIOErr("xino read error (%zd)\n", sz); | |
37600 | + } | |
062440b3 AM |
37601 | + return err; |
37602 | +} | |
37603 | + | |
5527c038 | 37604 | +static int au_xino_do_write(vfs_writef_t write, struct file *file, |
acd2b654 | 37605 | + struct au_xi_calc *calc, ino_t ino) |
1facf9fc | 37606 | +{ |
1facf9fc | 37607 | + ssize_t sz; |
37608 | + | |
acd2b654 | 37609 | + sz = xino_fwrite(write, file, &ino, sizeof(ino), &calc->pos); |
1facf9fc | 37610 | + if (sz == sizeof(ino)) |
37611 | + return 0; /* success */ | |
37612 | + | |
37613 | + AuIOErr("write failed (%zd)\n", sz); | |
37614 | + return -EIO; | |
37615 | +} | |
37616 | + | |
37617 | +/* | |
37618 | + * write @ino to the xinofile for the specified branch{@sb, @bindex} | |
37619 | + * at the position of @h_ino. | |
37620 | + * even if @ino is zero, it is written to the xinofile and means no entry. | |
37621 | + * if the size of the xino file on a specific filesystem exceeds the watermark, | |
37622 | + * try truncating it. | |
37623 | + */ | |
37624 | +int au_xino_write(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, | |
37625 | + ino_t ino) | |
37626 | +{ | |
37627 | + int err; | |
37628 | + unsigned int mnt_flags; | |
acd2b654 AM |
37629 | + struct au_xi_calc calc; |
37630 | + struct file *file; | |
1facf9fc | 37631 | + struct au_branch *br; |
acd2b654 | 37632 | + struct au_xino *xi; |
9f237c51 | 37633 | + struct au_xi_writing *p; |
1facf9fc | 37634 | + |
dece6358 | 37635 | + SiMustAnyLock(sb); |
1facf9fc | 37636 | + |
37637 | + mnt_flags = au_mntflags(sb); | |
37638 | + if (!au_opt_test(mnt_flags, XINO)) | |
37639 | + return 0; | |
37640 | + | |
acd2b654 | 37641 | + au_xi_calc(sb, h_ino, &calc); |
1facf9fc | 37642 | + br = au_sbr(sb, bindex); |
acd2b654 AM |
37643 | + xi = br->br_xino; |
37644 | + file = au_xino_file(xi, calc.idx); | |
37645 | + if (!file) { | |
9f237c51 AM |
37646 | + /* store the inum pair into the list */ |
37647 | + p = kmalloc(sizeof(*p), GFP_NOFS | __GFP_NOFAIL); | |
37648 | + p->h_ino = h_ino; | |
37649 | + p->ino = ino; | |
37650 | + au_hbl_add(&p->node, &xi->xi_writing); | |
37651 | + | |
acd2b654 AM |
37652 | + /* create and write a new xino file asynchronously */ |
37653 | + err = au_xino_new_async(sb, br, &calc, ino); | |
37654 | + if (!err) | |
37655 | + return 0; /* success */ | |
37656 | + goto out; | |
37657 | + } | |
37658 | + | |
37659 | + err = au_xino_do_write(au_sbi(sb)->si_xwrite, file, &calc, ino); | |
1facf9fc | 37660 | + if (!err) { |
acd2b654 | 37661 | + br = au_sbr(sb, bindex); |
1facf9fc | 37662 | + if (au_opt_test(mnt_flags, TRUNC_XINO) |
86dc4139 | 37663 | + && au_test_fs_trunc_xino(au_br_sb(br))) |
1facf9fc | 37664 | + xino_try_trunc(sb, br); |
37665 | + return 0; /* success */ | |
37666 | + } | |
37667 | + | |
acd2b654 | 37668 | +out: |
1facf9fc | 37669 | + AuIOErr("write failed (%d)\n", err); |
37670 | + return -EIO; | |
37671 | +} | |
37672 | + | |
062440b3 AM |
37673 | +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf, |
37674 | + size_t size, loff_t *pos); | |
1facf9fc | 37675 | + |
062440b3 AM |
37676 | +/* todo: unnecessary to support mmap_sem since kernel-space? */ |
37677 | +ssize_t xino_fread(vfs_readf_t func, struct file *file, void *kbuf, size_t size, | |
37678 | + loff_t *pos) | |
37679 | +{ | |
37680 | + ssize_t err; | |
37681 | + mm_segment_t oldfs; | |
37682 | + union { | |
37683 | + void *k; | |
37684 | + char __user *u; | |
37685 | + } buf; | |
37686 | + int i; | |
37687 | + const int prevent_endless = 10; | |
1facf9fc | 37688 | + |
062440b3 AM |
37689 | + i = 0; |
37690 | + buf.k = kbuf; | |
37691 | + oldfs = get_fs(); | |
37692 | + set_fs(KERNEL_DS); | |
37693 | + do { | |
37694 | + err = func(file, buf.u, size, pos); | |
37695 | + if (err == -EINTR | |
37696 | + && !au_wkq_test() | |
37697 | + && fatal_signal_pending(current)) { | |
37698 | + set_fs(oldfs); | |
37699 | + err = xino_fread_wkq(func, file, kbuf, size, pos); | |
37700 | + BUG_ON(err == -EINTR); | |
37701 | + oldfs = get_fs(); | |
37702 | + set_fs(KERNEL_DS); | |
37703 | + } | |
37704 | + } while (i++ < prevent_endless | |
37705 | + && (err == -EAGAIN || err == -EINTR)); | |
37706 | + set_fs(oldfs); | |
37707 | + | |
37708 | +#if 0 /* reserved for future use */ | |
37709 | + if (err > 0) | |
37710 | + fsnotify_access(file->f_path.dentry); | |
37711 | +#endif | |
37712 | + | |
37713 | + return err; | |
37714 | +} | |
37715 | + | |
37716 | +struct xino_fread_args { | |
37717 | + ssize_t *errp; | |
37718 | + vfs_readf_t func; | |
37719 | + struct file *file; | |
37720 | + void *buf; | |
37721 | + size_t size; | |
37722 | + loff_t *pos; | |
37723 | +}; | |
37724 | + | |
37725 | +static void call_xino_fread(void *args) | |
37726 | +{ | |
37727 | + struct xino_fread_args *a = args; | |
37728 | + *a->errp = xino_fread(a->func, a->file, a->buf, a->size, a->pos); | |
37729 | +} | |
37730 | + | |
37731 | +static ssize_t xino_fread_wkq(vfs_readf_t func, struct file *file, void *buf, | |
37732 | + size_t size, loff_t *pos) | |
37733 | +{ | |
37734 | + ssize_t err; | |
37735 | + int wkq_err; | |
37736 | + struct xino_fread_args args = { | |
37737 | + .errp = &err, | |
37738 | + .func = func, | |
37739 | + .file = file, | |
37740 | + .buf = buf, | |
37741 | + .size = size, | |
37742 | + .pos = pos | |
37743 | + }; | |
37744 | + | |
37745 | + wkq_err = au_wkq_wait(call_xino_fread, &args); | |
37746 | + if (unlikely(wkq_err)) | |
37747 | + err = wkq_err; | |
37748 | + | |
37749 | + return err; | |
37750 | +} | |
37751 | + | |
37752 | +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf, | |
37753 | + size_t size, loff_t *pos); | |
37754 | + | |
37755 | +static ssize_t do_xino_fwrite(vfs_writef_t func, struct file *file, void *kbuf, | |
37756 | + size_t size, loff_t *pos) | |
37757 | +{ | |
37758 | + ssize_t err; | |
37759 | + mm_segment_t oldfs; | |
37760 | + union { | |
37761 | + void *k; | |
37762 | + const char __user *u; | |
37763 | + } buf; | |
37764 | + int i; | |
37765 | + const int prevent_endless = 10; | |
37766 | + | |
37767 | + i = 0; | |
37768 | + buf.k = kbuf; | |
37769 | + oldfs = get_fs(); | |
37770 | + set_fs(KERNEL_DS); | |
37771 | + do { | |
37772 | + err = func(file, buf.u, size, pos); | |
37773 | + if (err == -EINTR | |
37774 | + && !au_wkq_test() | |
37775 | + && fatal_signal_pending(current)) { | |
37776 | + set_fs(oldfs); | |
37777 | + err = xino_fwrite_wkq(func, file, kbuf, size, pos); | |
37778 | + BUG_ON(err == -EINTR); | |
37779 | + oldfs = get_fs(); | |
37780 | + set_fs(KERNEL_DS); | |
37781 | + } | |
37782 | + } while (i++ < prevent_endless | |
37783 | + && (err == -EAGAIN || err == -EINTR)); | |
37784 | + set_fs(oldfs); | |
37785 | + | |
37786 | +#if 0 /* reserved for future use */ | |
37787 | + if (err > 0) | |
37788 | + fsnotify_modify(file->f_path.dentry); | |
37789 | +#endif | |
37790 | + | |
37791 | + return err; | |
37792 | +} | |
37793 | + | |
37794 | +struct do_xino_fwrite_args { | |
37795 | + ssize_t *errp; | |
37796 | + vfs_writef_t func; | |
37797 | + struct file *file; | |
37798 | + void *buf; | |
37799 | + size_t size; | |
37800 | + loff_t *pos; | |
37801 | +}; | |
37802 | + | |
37803 | +static void call_do_xino_fwrite(void *args) | |
37804 | +{ | |
37805 | + struct do_xino_fwrite_args *a = args; | |
37806 | + *a->errp = do_xino_fwrite(a->func, a->file, a->buf, a->size, a->pos); | |
37807 | +} | |
37808 | + | |
37809 | +static ssize_t xino_fwrite_wkq(vfs_writef_t func, struct file *file, void *buf, | |
37810 | + size_t size, loff_t *pos) | |
37811 | +{ | |
37812 | + ssize_t err; | |
37813 | + int wkq_err; | |
37814 | + struct do_xino_fwrite_args args = { | |
37815 | + .errp = &err, | |
37816 | + .func = func, | |
37817 | + .file = file, | |
37818 | + .buf = buf, | |
37819 | + .size = size, | |
37820 | + .pos = pos | |
37821 | + }; | |
37822 | + | |
37823 | + /* | |
37824 | + * it breaks RLIMIT_FSIZE and normal user's limit, | |
37825 | + * users should care about quota and real 'filesystem full.' | |
37826 | + */ | |
37827 | + wkq_err = au_wkq_wait(call_do_xino_fwrite, &args); | |
37828 | + if (unlikely(wkq_err)) | |
37829 | + err = wkq_err; | |
37830 | + | |
37831 | + return err; | |
37832 | +} | |
37833 | + | |
37834 | +ssize_t xino_fwrite(vfs_writef_t func, struct file *file, void *buf, | |
37835 | + size_t size, loff_t *pos) | |
37836 | +{ | |
37837 | + ssize_t err; | |
37838 | + | |
37839 | + if (rlimit(RLIMIT_FSIZE) == RLIM_INFINITY) { | |
37840 | + lockdep_off(); | |
37841 | + err = do_xino_fwrite(func, file, buf, size, pos); | |
37842 | + lockdep_on(); | |
37843 | + } else { | |
37844 | + lockdep_off(); | |
37845 | + err = xino_fwrite_wkq(func, file, buf, size, pos); | |
37846 | + lockdep_on(); | |
37847 | + } | |
37848 | + | |
37849 | + return err; | |
37850 | +} | |
37851 | + | |
37852 | +/* ---------------------------------------------------------------------- */ | |
37853 | + | |
37854 | +/* | |
37855 | + * inode number bitmap | |
37856 | + */ | |
1facf9fc | 37857 | +static const int page_bits = (int)PAGE_SIZE * BITS_PER_BYTE; |
37858 | +static ino_t xib_calc_ino(unsigned long pindex, int bit) | |
37859 | +{ | |
37860 | + ino_t ino; | |
37861 | + | |
37862 | + AuDebugOn(bit < 0 || page_bits <= bit); | |
37863 | + ino = AUFS_FIRST_INO + pindex * page_bits + bit; | |
37864 | + return ino; | |
37865 | +} | |
37866 | + | |
37867 | +static void xib_calc_bit(ino_t ino, unsigned long *pindex, int *bit) | |
37868 | +{ | |
37869 | + AuDebugOn(ino < AUFS_FIRST_INO); | |
37870 | + ino -= AUFS_FIRST_INO; | |
37871 | + *pindex = ino / page_bits; | |
37872 | + *bit = ino % page_bits; | |
37873 | +} | |
37874 | + | |
37875 | +static int xib_pindex(struct super_block *sb, unsigned long pindex) | |
37876 | +{ | |
37877 | + int err; | |
37878 | + loff_t pos; | |
37879 | + ssize_t sz; | |
37880 | + struct au_sbinfo *sbinfo; | |
37881 | + struct file *xib; | |
37882 | + unsigned long *p; | |
37883 | + | |
37884 | + sbinfo = au_sbi(sb); | |
37885 | + MtxMustLock(&sbinfo->si_xib_mtx); | |
37886 | + AuDebugOn(pindex > ULONG_MAX / PAGE_SIZE | |
37887 | + || !au_opt_test(sbinfo->si_mntflags, XINO)); | |
37888 | + | |
37889 | + if (pindex == sbinfo->si_xib_last_pindex) | |
37890 | + return 0; | |
37891 | + | |
37892 | + xib = sbinfo->si_xib; | |
37893 | + p = sbinfo->si_xib_buf; | |
37894 | + pos = sbinfo->si_xib_last_pindex; | |
37895 | + pos *= PAGE_SIZE; | |
37896 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
37897 | + if (unlikely(sz != PAGE_SIZE)) | |
37898 | + goto out; | |
37899 | + | |
37900 | + pos = pindex; | |
37901 | + pos *= PAGE_SIZE; | |
c06a8ce3 | 37902 | + if (vfsub_f_size_read(xib) >= pos + PAGE_SIZE) |
1facf9fc | 37903 | + sz = xino_fread(sbinfo->si_xread, xib, p, PAGE_SIZE, &pos); |
37904 | + else { | |
37905 | + memset(p, 0, PAGE_SIZE); | |
37906 | + sz = xino_fwrite(sbinfo->si_xwrite, xib, p, PAGE_SIZE, &pos); | |
37907 | + } | |
37908 | + if (sz == PAGE_SIZE) { | |
37909 | + sbinfo->si_xib_last_pindex = pindex; | |
37910 | + return 0; /* success */ | |
37911 | + } | |
37912 | + | |
4f0767ce | 37913 | +out: |
b752ccd1 AM |
37914 | + AuIOErr1("write failed (%zd)\n", sz); |
37915 | + err = sz; | |
37916 | + if (sz >= 0) | |
37917 | + err = -EIO; | |
37918 | + return err; | |
37919 | +} | |
37920 | + | |
b752ccd1 AM |
37921 | +static void au_xib_clear_bit(struct inode *inode) |
37922 | +{ | |
37923 | + int err, bit; | |
37924 | + unsigned long pindex; | |
37925 | + struct super_block *sb; | |
37926 | + struct au_sbinfo *sbinfo; | |
37927 | + | |
37928 | + AuDebugOn(inode->i_nlink); | |
37929 | + | |
37930 | + sb = inode->i_sb; | |
37931 | + xib_calc_bit(inode->i_ino, &pindex, &bit); | |
37932 | + AuDebugOn(page_bits <= bit); | |
37933 | + sbinfo = au_sbi(sb); | |
37934 | + mutex_lock(&sbinfo->si_xib_mtx); | |
37935 | + err = xib_pindex(sb, pindex); | |
37936 | + if (!err) { | |
37937 | + clear_bit(bit, sbinfo->si_xib_buf); | |
37938 | + sbinfo->si_xib_next_bit = bit; | |
37939 | + } | |
37940 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
37941 | +} | |
37942 | + | |
1facf9fc | 37943 | +/* ---------------------------------------------------------------------- */ |
37944 | + | |
1facf9fc | 37945 | +/* |
062440b3 | 37946 | + * truncate a xino bitmap file |
1facf9fc | 37947 | + */ |
1facf9fc | 37948 | + |
37949 | +/* todo: slow */ | |
37950 | +static int do_xib_restore(struct super_block *sb, struct file *file, void *page) | |
37951 | +{ | |
37952 | + int err, bit; | |
37953 | + ssize_t sz; | |
37954 | + unsigned long pindex; | |
37955 | + loff_t pos, pend; | |
37956 | + struct au_sbinfo *sbinfo; | |
5527c038 | 37957 | + vfs_readf_t func; |
1facf9fc | 37958 | + ino_t *ino; |
37959 | + unsigned long *p; | |
37960 | + | |
37961 | + err = 0; | |
37962 | + sbinfo = au_sbi(sb); | |
dece6358 | 37963 | + MtxMustLock(&sbinfo->si_xib_mtx); |
1facf9fc | 37964 | + p = sbinfo->si_xib_buf; |
37965 | + func = sbinfo->si_xread; | |
c06a8ce3 | 37966 | + pend = vfsub_f_size_read(file); |
1facf9fc | 37967 | + pos = 0; |
37968 | + while (pos < pend) { | |
37969 | + sz = xino_fread(func, file, page, PAGE_SIZE, &pos); | |
37970 | + err = sz; | |
37971 | + if (unlikely(sz <= 0)) | |
37972 | + goto out; | |
37973 | + | |
37974 | + err = 0; | |
37975 | + for (ino = page; sz > 0; ino++, sz -= sizeof(ino)) { | |
37976 | + if (unlikely(*ino < AUFS_FIRST_INO)) | |
37977 | + continue; | |
37978 | + | |
37979 | + xib_calc_bit(*ino, &pindex, &bit); | |
37980 | + AuDebugOn(page_bits <= bit); | |
37981 | + err = xib_pindex(sb, pindex); | |
37982 | + if (!err) | |
37983 | + set_bit(bit, p); | |
37984 | + else | |
37985 | + goto out; | |
37986 | + } | |
37987 | + } | |
37988 | + | |
4f0767ce | 37989 | +out: |
1facf9fc | 37990 | + return err; |
37991 | +} | |
37992 | + | |
37993 | +static int xib_restore(struct super_block *sb) | |
37994 | +{ | |
acd2b654 AM |
37995 | + int err, i; |
37996 | + unsigned int nfile; | |
5afbbe0d | 37997 | + aufs_bindex_t bindex, bbot; |
1facf9fc | 37998 | + void *page; |
062440b3 | 37999 | + struct au_branch *br; |
acd2b654 AM |
38000 | + struct au_xino *xi; |
38001 | + struct file *file; | |
1facf9fc | 38002 | + |
38003 | + err = -ENOMEM; | |
38004 | + page = (void *)__get_free_page(GFP_NOFS); | |
38005 | + if (unlikely(!page)) | |
38006 | + goto out; | |
38007 | + | |
38008 | + err = 0; | |
5afbbe0d AM |
38009 | + bbot = au_sbbot(sb); |
38010 | + for (bindex = 0; !err && bindex <= bbot; bindex++) | |
062440b3 AM |
38011 | + if (!bindex || is_sb_shared(sb, bindex, bindex - 1) < 0) { |
38012 | + br = au_sbr(sb, bindex); | |
acd2b654 AM |
38013 | + xi = br->br_xino; |
38014 | + nfile = xi->xi_nfile; | |
38015 | + for (i = 0; i < nfile; i++) { | |
38016 | + file = au_xino_file(xi, i); | |
38017 | + if (file) | |
38018 | + err = do_xib_restore(sb, file, page); | |
38019 | + } | |
062440b3 AM |
38020 | + } else |
38021 | + AuDbg("skip shared b%d\n", bindex); | |
1c60b727 | 38022 | + free_page((unsigned long)page); |
1facf9fc | 38023 | + |
4f0767ce | 38024 | +out: |
1facf9fc | 38025 | + return err; |
38026 | +} | |
38027 | + | |
38028 | +int au_xib_trunc(struct super_block *sb) | |
38029 | +{ | |
38030 | + int err; | |
38031 | + ssize_t sz; | |
38032 | + loff_t pos; | |
1facf9fc | 38033 | + struct au_sbinfo *sbinfo; |
38034 | + unsigned long *p; | |
38035 | + struct file *file; | |
38036 | + | |
dece6358 AM |
38037 | + SiMustWriteLock(sb); |
38038 | + | |
1facf9fc | 38039 | + err = 0; |
38040 | + sbinfo = au_sbi(sb); | |
38041 | + if (!au_opt_test(sbinfo->si_mntflags, XINO)) | |
38042 | + goto out; | |
38043 | + | |
38044 | + file = sbinfo->si_xib; | |
c06a8ce3 | 38045 | + if (vfsub_f_size_read(file) <= PAGE_SIZE) |
1facf9fc | 38046 | + goto out; |
38047 | + | |
062440b3 | 38048 | + file = au_xino_create2(sb, &sbinfo->si_xib->f_path, NULL); |
1facf9fc | 38049 | + err = PTR_ERR(file); |
38050 | + if (IS_ERR(file)) | |
38051 | + goto out; | |
38052 | + fput(sbinfo->si_xib); | |
38053 | + sbinfo->si_xib = file; | |
38054 | + | |
38055 | + p = sbinfo->si_xib_buf; | |
38056 | + memset(p, 0, PAGE_SIZE); | |
38057 | + pos = 0; | |
38058 | + sz = xino_fwrite(sbinfo->si_xwrite, sbinfo->si_xib, p, PAGE_SIZE, &pos); | |
38059 | + if (unlikely(sz != PAGE_SIZE)) { | |
38060 | + err = sz; | |
38061 | + AuIOErr("err %d\n", err); | |
38062 | + if (sz >= 0) | |
38063 | + err = -EIO; | |
38064 | + goto out; | |
38065 | + } | |
38066 | + | |
38067 | + mutex_lock(&sbinfo->si_xib_mtx); | |
38068 | + /* mnt_want_write() is unnecessary here */ | |
38069 | + err = xib_restore(sb); | |
38070 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
38071 | + | |
38072 | +out: | |
38073 | + return err; | |
38074 | +} | |
38075 | + | |
38076 | +/* ---------------------------------------------------------------------- */ | |
38077 | + | |
acd2b654 | 38078 | +struct au_xino *au_xino_alloc(unsigned int nfile) |
062440b3 AM |
38079 | +{ |
38080 | + struct au_xino *xi; | |
38081 | + | |
38082 | + xi = kzalloc(sizeof(*xi), GFP_NOFS); | |
38083 | + if (unlikely(!xi)) | |
38084 | + goto out; | |
acd2b654 AM |
38085 | + xi->xi_nfile = nfile; |
38086 | + xi->xi_file = kcalloc(nfile, sizeof(*xi->xi_file), GFP_NOFS); | |
38087 | + if (unlikely(!xi->xi_file)) | |
38088 | + goto out_free; | |
062440b3 AM |
38089 | + |
38090 | + xi->xi_nondir.total = 8; /* initial size */ | |
38091 | + xi->xi_nondir.array = kcalloc(xi->xi_nondir.total, sizeof(ino_t), | |
38092 | + GFP_NOFS); | |
38093 | + if (unlikely(!xi->xi_nondir.array)) | |
acd2b654 | 38094 | + goto out_file; |
062440b3 AM |
38095 | + |
38096 | + spin_lock_init(&xi->xi_nondir.spin); | |
38097 | + init_waitqueue_head(&xi->xi_nondir.wqh); | |
acd2b654 | 38098 | + mutex_init(&xi->xi_mtx); |
9f237c51 | 38099 | + INIT_HLIST_BL_HEAD(&xi->xi_writing); |
062440b3 AM |
38100 | + atomic_set(&xi->xi_truncating, 0); |
38101 | + kref_init(&xi->xi_kref); | |
38102 | + goto out; /* success */ | |
38103 | + | |
acd2b654 | 38104 | +out_file: |
9f237c51 | 38105 | + au_kfree_try_rcu(xi->xi_file); |
062440b3 | 38106 | +out_free: |
9f237c51 | 38107 | + au_kfree_rcu(xi); |
062440b3 AM |
38108 | + xi = NULL; |
38109 | +out: | |
38110 | + return xi; | |
38111 | +} | |
38112 | + | |
acd2b654 | 38113 | +static int au_xino_init(struct au_branch *br, int idx, struct file *file) |
062440b3 AM |
38114 | +{ |
38115 | + int err; | |
38116 | + struct au_xino *xi; | |
38117 | + | |
38118 | + err = 0; | |
acd2b654 | 38119 | + xi = au_xino_alloc(idx + 1); |
062440b3 AM |
38120 | + if (unlikely(!xi)) { |
38121 | + err = -ENOMEM; | |
38122 | + goto out; | |
38123 | + } | |
38124 | + | |
acd2b654 AM |
38125 | + if (file) |
38126 | + get_file(file); | |
38127 | + xi->xi_file[idx] = file; | |
062440b3 AM |
38128 | + AuDebugOn(br->br_xino); |
38129 | + br->br_xino = xi; | |
38130 | + | |
38131 | +out: | |
38132 | + return err; | |
38133 | +} | |
38134 | + | |
38135 | +static void au_xino_release(struct kref *kref) | |
38136 | +{ | |
38137 | + struct au_xino *xi; | |
38138 | + int i; | |
9f237c51 AM |
38139 | + unsigned long ul; |
38140 | + struct hlist_bl_head *hbl; | |
38141 | + struct hlist_bl_node *pos, *n; | |
38142 | + struct au_xi_writing *p; | |
062440b3 AM |
38143 | + |
38144 | + xi = container_of(kref, struct au_xino, xi_kref); | |
acd2b654 AM |
38145 | + for (i = 0; i < xi->xi_nfile; i++) |
38146 | + if (xi->xi_file[i]) | |
38147 | + fput(xi->xi_file[i]); | |
062440b3 AM |
38148 | + for (i = xi->xi_nondir.total - 1; i >= 0; i--) |
38149 | + AuDebugOn(xi->xi_nondir.array[i]); | |
acd2b654 | 38150 | + mutex_destroy(&xi->xi_mtx); |
9f237c51 AM |
38151 | + hbl = &xi->xi_writing; |
38152 | + ul = au_hbl_count(hbl); | |
38153 | + if (unlikely(ul)) { | |
38154 | + pr_warn("xi_writing %lu\n", ul); | |
38155 | + hlist_bl_lock(hbl); | |
43982f53 | 38156 | + hlist_bl_for_each_entry_safe(p, pos, n, hbl, node) { |
9f237c51 AM |
38157 | + hlist_bl_del(&p->node); |
38158 | + au_kfree_rcu(p); | |
38159 | + } | |
38160 | + hlist_bl_unlock(hbl); | |
38161 | + } | |
38162 | + au_kfree_try_rcu(xi->xi_file); | |
38163 | + au_kfree_try_rcu(xi->xi_nondir.array); | |
38164 | + au_kfree_rcu(xi); | |
062440b3 AM |
38165 | +} |
38166 | + | |
38167 | +int au_xino_put(struct au_branch *br) | |
38168 | +{ | |
38169 | + int ret; | |
38170 | + struct au_xino *xi; | |
38171 | + | |
38172 | + ret = 0; | |
38173 | + xi = br->br_xino; | |
38174 | + if (xi) { | |
38175 | + br->br_xino = NULL; | |
38176 | + ret = kref_put(&xi->xi_kref, au_xino_release); | |
38177 | + } | |
38178 | + | |
38179 | + return ret; | |
38180 | +} | |
38181 | + | |
062440b3 AM |
38182 | +/* ---------------------------------------------------------------------- */ |
38183 | + | |
1facf9fc | 38184 | +/* |
38185 | + * xino mount option handlers | |
38186 | + */ | |
1facf9fc | 38187 | + |
38188 | +/* xino bitmap */ | |
38189 | +static void xino_clear_xib(struct super_block *sb) | |
38190 | +{ | |
38191 | + struct au_sbinfo *sbinfo; | |
38192 | + | |
dece6358 AM |
38193 | + SiMustWriteLock(sb); |
38194 | + | |
1facf9fc | 38195 | + sbinfo = au_sbi(sb); |
062440b3 | 38196 | + /* unnecessary to clear sbinfo->si_xread and ->si_xwrite */ |
1facf9fc | 38197 | + if (sbinfo->si_xib) |
38198 | + fput(sbinfo->si_xib); | |
38199 | + sbinfo->si_xib = NULL; | |
f0c0a007 | 38200 | + if (sbinfo->si_xib_buf) |
1c60b727 | 38201 | + free_page((unsigned long)sbinfo->si_xib_buf); |
1facf9fc | 38202 | + sbinfo->si_xib_buf = NULL; |
38203 | +} | |
38204 | + | |
062440b3 | 38205 | +static int au_xino_set_xib(struct super_block *sb, struct path *path) |
1facf9fc | 38206 | +{ |
38207 | + int err; | |
38208 | + loff_t pos; | |
38209 | + struct au_sbinfo *sbinfo; | |
38210 | + struct file *file; | |
acd2b654 | 38211 | + struct super_block *xi_sb; |
1facf9fc | 38212 | + |
dece6358 AM |
38213 | + SiMustWriteLock(sb); |
38214 | + | |
1facf9fc | 38215 | + sbinfo = au_sbi(sb); |
062440b3 | 38216 | + file = au_xino_create2(sb, path, sbinfo->si_xib); |
1facf9fc | 38217 | + err = PTR_ERR(file); |
38218 | + if (IS_ERR(file)) | |
38219 | + goto out; | |
38220 | + if (sbinfo->si_xib) | |
38221 | + fput(sbinfo->si_xib); | |
38222 | + sbinfo->si_xib = file; | |
5527c038 JR |
38223 | + sbinfo->si_xread = vfs_readf(file); |
38224 | + sbinfo->si_xwrite = vfs_writef(file); | |
acd2b654 AM |
38225 | + xi_sb = file_inode(file)->i_sb; |
38226 | + sbinfo->si_ximaxent = xi_sb->s_maxbytes; | |
38227 | + if (unlikely(sbinfo->si_ximaxent < PAGE_SIZE)) { | |
38228 | + err = -EIO; | |
38229 | + pr_err("s_maxbytes(%llu) on %s is too small\n", | |
38230 | + (u64)sbinfo->si_ximaxent, au_sbtype(xi_sb)); | |
38231 | + goto out_unset; | |
38232 | + } | |
38233 | + sbinfo->si_ximaxent /= sizeof(ino_t); | |
1facf9fc | 38234 | + |
38235 | + err = -ENOMEM; | |
38236 | + if (!sbinfo->si_xib_buf) | |
38237 | + sbinfo->si_xib_buf = (void *)get_zeroed_page(GFP_NOFS); | |
38238 | + if (unlikely(!sbinfo->si_xib_buf)) | |
38239 | + goto out_unset; | |
38240 | + | |
38241 | + sbinfo->si_xib_last_pindex = 0; | |
38242 | + sbinfo->si_xib_next_bit = 0; | |
c06a8ce3 | 38243 | + if (vfsub_f_size_read(file) < PAGE_SIZE) { |
1facf9fc | 38244 | + pos = 0; |
38245 | + err = xino_fwrite(sbinfo->si_xwrite, file, sbinfo->si_xib_buf, | |
38246 | + PAGE_SIZE, &pos); | |
38247 | + if (unlikely(err != PAGE_SIZE)) | |
38248 | + goto out_free; | |
38249 | + } | |
38250 | + err = 0; | |
38251 | + goto out; /* success */ | |
38252 | + | |
4f0767ce | 38253 | +out_free: |
f0c0a007 | 38254 | + if (sbinfo->si_xib_buf) |
1c60b727 | 38255 | + free_page((unsigned long)sbinfo->si_xib_buf); |
b752ccd1 AM |
38256 | + sbinfo->si_xib_buf = NULL; |
38257 | + if (err >= 0) | |
38258 | + err = -EIO; | |
4f0767ce | 38259 | +out_unset: |
b752ccd1 AM |
38260 | + fput(sbinfo->si_xib); |
38261 | + sbinfo->si_xib = NULL; | |
4f0767ce | 38262 | +out: |
062440b3 | 38263 | + AuTraceErr(err); |
b752ccd1 | 38264 | + return err; |
1facf9fc | 38265 | +} |
38266 | + | |
b752ccd1 AM |
38267 | +/* xino for each branch */ |
38268 | +static void xino_clear_br(struct super_block *sb) | |
38269 | +{ | |
5afbbe0d | 38270 | + aufs_bindex_t bindex, bbot; |
b752ccd1 | 38271 | + struct au_branch *br; |
1facf9fc | 38272 | + |
5afbbe0d AM |
38273 | + bbot = au_sbbot(sb); |
38274 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
b752ccd1 | 38275 | + br = au_sbr(sb, bindex); |
062440b3 AM |
38276 | + AuDebugOn(!br); |
38277 | + au_xino_put(br); | |
38278 | + } | |
38279 | +} | |
38280 | + | |
38281 | +static void au_xino_set_br_shared(struct super_block *sb, struct au_branch *br, | |
38282 | + aufs_bindex_t bshared) | |
38283 | +{ | |
38284 | + struct au_branch *brshared; | |
b752ccd1 | 38285 | + |
062440b3 AM |
38286 | + brshared = au_sbr(sb, bshared); |
38287 | + AuDebugOn(!brshared->br_xino); | |
38288 | + AuDebugOn(!brshared->br_xino->xi_file); | |
38289 | + if (br->br_xino != brshared->br_xino) { | |
38290 | + au_xino_get(brshared); | |
38291 | + au_xino_put(br); | |
38292 | + br->br_xino = brshared->br_xino; | |
b752ccd1 AM |
38293 | + } |
38294 | +} | |
38295 | + | |
062440b3 AM |
38296 | +struct au_xino_do_set_br { |
38297 | + vfs_writef_t writef; | |
38298 | + struct au_branch *br; | |
38299 | + ino_t h_ino; | |
38300 | + aufs_bindex_t bshared; | |
38301 | +}; | |
38302 | + | |
38303 | +static int au_xino_do_set_br(struct super_block *sb, struct path *path, | |
38304 | + struct au_xino_do_set_br *args) | |
1facf9fc | 38305 | +{ |
38306 | + int err; | |
acd2b654 | 38307 | + struct au_xi_calc calc; |
062440b3 | 38308 | + struct file *file; |
acd2b654 AM |
38309 | + struct au_branch *br; |
38310 | + struct au_xi_new xinew = { | |
38311 | + .base = path | |
38312 | + }; | |
062440b3 | 38313 | + |
acd2b654 AM |
38314 | + br = args->br; |
38315 | + xinew.xi = br->br_xino; | |
38316 | + au_xi_calc(sb, args->h_ino, &calc); | |
38317 | + xinew.copy_src = au_xino_file(xinew.xi, calc.idx); | |
38318 | + if (args->bshared >= 0) | |
062440b3 | 38319 | + /* shared xino */ |
acd2b654 AM |
38320 | + au_xino_set_br_shared(sb, br, args->bshared); |
38321 | + else if (!xinew.xi) { | |
38322 | + /* new xino */ | |
38323 | + err = au_xino_init(br, calc.idx, xinew.copy_src); | |
38324 | + if (unlikely(err)) | |
38325 | + goto out; | |
062440b3 AM |
38326 | + } |
38327 | + | |
acd2b654 AM |
38328 | + /* force re-creating */ |
38329 | + xinew.xi = br->br_xino; | |
38330 | + xinew.idx = calc.idx; | |
38331 | + mutex_lock(&xinew.xi->xi_mtx); | |
38332 | + file = au_xi_new(sb, &xinew); | |
38333 | + mutex_unlock(&xinew.xi->xi_mtx); | |
062440b3 AM |
38334 | + err = PTR_ERR(file); |
38335 | + if (IS_ERR(file)) | |
38336 | + goto out; | |
acd2b654 AM |
38337 | + AuDebugOn(!file); |
38338 | + | |
38339 | + err = au_xino_do_write(args->writef, file, &calc, AUFS_ROOT_INO); | |
38340 | + if (unlikely(err)) | |
38341 | + au_xino_put(br); | |
062440b3 | 38342 | + |
062440b3 AM |
38343 | +out: |
38344 | + AuTraceErr(err); | |
38345 | + return err; | |
38346 | +} | |
38347 | + | |
38348 | +static int au_xino_set_br(struct super_block *sb, struct path *path) | |
38349 | +{ | |
38350 | + int err; | |
38351 | + aufs_bindex_t bindex, bbot; | |
38352 | + struct au_xino_do_set_br args; | |
b752ccd1 | 38353 | + struct inode *inode; |
1facf9fc | 38354 | + |
b752ccd1 AM |
38355 | + SiMustWriteLock(sb); |
38356 | + | |
5afbbe0d | 38357 | + bbot = au_sbbot(sb); |
5527c038 | 38358 | + inode = d_inode(sb->s_root); |
062440b3 AM |
38359 | + args.writef = au_sbi(sb)->si_xwrite; |
38360 | + for (bindex = 0; bindex <= bbot; bindex++) { | |
38361 | + args.h_ino = au_h_iptr(inode, bindex)->i_ino; | |
38362 | + args.br = au_sbr(sb, bindex); | |
38363 | + args.bshared = is_sb_shared(sb, bindex, bindex - 1); | |
38364 | + err = au_xino_do_set_br(sb, path, &args); | |
b752ccd1 | 38365 | + if (unlikely(err)) |
062440b3 | 38366 | + break; |
b752ccd1 | 38367 | + } |
1facf9fc | 38368 | + |
062440b3 | 38369 | + AuTraceErr(err); |
1facf9fc | 38370 | + return err; |
38371 | +} | |
b752ccd1 AM |
38372 | + |
38373 | +void au_xino_clr(struct super_block *sb) | |
38374 | +{ | |
38375 | + struct au_sbinfo *sbinfo; | |
38376 | + | |
38377 | + au_xigen_clr(sb); | |
38378 | + xino_clear_xib(sb); | |
38379 | + xino_clear_br(sb); | |
062440b3 | 38380 | + dbgaufs_brs_del(sb, 0); |
b752ccd1 AM |
38381 | + sbinfo = au_sbi(sb); |
38382 | + /* lvalue, do not call au_mntflags() */ | |
38383 | + au_opt_clr(sbinfo->si_mntflags, XINO); | |
38384 | +} | |
38385 | + | |
062440b3 | 38386 | +int au_xino_set(struct super_block *sb, struct au_opt_xino *xiopt, int remount) |
b752ccd1 AM |
38387 | +{ |
38388 | + int err, skip; | |
062440b3 | 38389 | + struct dentry *dentry, *parent, *cur_dentry, *cur_parent; |
b752ccd1 AM |
38390 | + struct qstr *dname, *cur_name; |
38391 | + struct file *cur_xino; | |
b752ccd1 | 38392 | + struct au_sbinfo *sbinfo; |
062440b3 | 38393 | + struct path *path, *cur_path; |
b752ccd1 AM |
38394 | + |
38395 | + SiMustWriteLock(sb); | |
38396 | + | |
38397 | + err = 0; | |
38398 | + sbinfo = au_sbi(sb); | |
062440b3 AM |
38399 | + path = &xiopt->file->f_path; |
38400 | + dentry = path->dentry; | |
38401 | + parent = dget_parent(dentry); | |
b752ccd1 AM |
38402 | + if (remount) { |
38403 | + skip = 0; | |
b752ccd1 AM |
38404 | + cur_xino = sbinfo->si_xib; |
38405 | + if (cur_xino) { | |
062440b3 AM |
38406 | + cur_path = &cur_xino->f_path; |
38407 | + cur_dentry = cur_path->dentry; | |
38408 | + cur_parent = dget_parent(cur_dentry); | |
38409 | + cur_name = &cur_dentry->d_name; | |
38410 | + dname = &dentry->d_name; | |
b752ccd1 | 38411 | + skip = (cur_parent == parent |
38d290e6 | 38412 | + && au_qstreq(dname, cur_name)); |
b752ccd1 AM |
38413 | + dput(cur_parent); |
38414 | + } | |
38415 | + if (skip) | |
38416 | + goto out; | |
38417 | + } | |
38418 | + | |
38419 | + au_opt_set(sbinfo->si_mntflags, XINO); | |
062440b3 AM |
38420 | + err = au_xino_set_xib(sb, path); |
38421 | + /* si_x{read,write} are set */ | |
b752ccd1 | 38422 | + if (!err) |
062440b3 | 38423 | + err = au_xigen_set(sb, path); |
b752ccd1 | 38424 | + if (!err) |
062440b3 AM |
38425 | + err = au_xino_set_br(sb, path); |
38426 | + if (!err) { | |
38427 | + dbgaufs_brs_add(sb, 0, /*topdown*/1); | |
b752ccd1 | 38428 | + goto out; /* success */ |
062440b3 | 38429 | + } |
b752ccd1 AM |
38430 | + |
38431 | + /* reset all */ | |
062440b3 AM |
38432 | + AuIOErr("failed setting xino(%d).\n", err); |
38433 | + au_xino_clr(sb); | |
b752ccd1 | 38434 | + |
4f0767ce | 38435 | +out: |
b752ccd1 AM |
38436 | + dput(parent); |
38437 | + return err; | |
38438 | +} | |
38439 | + | |
b752ccd1 AM |
38440 | +/* |
38441 | + * create a xinofile at the default place/path. | |
38442 | + */ | |
38443 | +struct file *au_xino_def(struct super_block *sb) | |
38444 | +{ | |
38445 | + struct file *file; | |
38446 | + char *page, *p; | |
38447 | + struct au_branch *br; | |
38448 | + struct super_block *h_sb; | |
38449 | + struct path path; | |
5afbbe0d | 38450 | + aufs_bindex_t bbot, bindex, bwr; |
b752ccd1 AM |
38451 | + |
38452 | + br = NULL; | |
5afbbe0d | 38453 | + bbot = au_sbbot(sb); |
b752ccd1 | 38454 | + bwr = -1; |
5afbbe0d | 38455 | + for (bindex = 0; bindex <= bbot; bindex++) { |
b752ccd1 AM |
38456 | + br = au_sbr(sb, bindex); |
38457 | + if (au_br_writable(br->br_perm) | |
86dc4139 | 38458 | + && !au_test_fs_bad_xino(au_br_sb(br))) { |
b752ccd1 AM |
38459 | + bwr = bindex; |
38460 | + break; | |
38461 | + } | |
38462 | + } | |
38463 | + | |
7f207e10 AM |
38464 | + if (bwr >= 0) { |
38465 | + file = ERR_PTR(-ENOMEM); | |
537831f9 | 38466 | + page = (void *)__get_free_page(GFP_NOFS); |
7f207e10 AM |
38467 | + if (unlikely(!page)) |
38468 | + goto out; | |
86dc4139 | 38469 | + path.mnt = au_br_mnt(br); |
7f207e10 AM |
38470 | + path.dentry = au_h_dptr(sb->s_root, bwr); |
38471 | + p = d_path(&path, page, PATH_MAX - sizeof(AUFS_XINO_FNAME)); | |
38472 | + file = (void *)p; | |
38473 | + if (!IS_ERR(p)) { | |
38474 | + strcat(p, "/" AUFS_XINO_FNAME); | |
38475 | + AuDbg("%s\n", p); | |
83b672a5 | 38476 | + file = au_xino_create(sb, p, /*silent*/0, /*wbrtop*/1); |
7f207e10 | 38477 | + } |
1c60b727 | 38478 | + free_page((unsigned long)page); |
7f207e10 | 38479 | + } else { |
83b672a5 AM |
38480 | + file = au_xino_create(sb, AUFS_XINO_DEFPATH, /*silent*/0, |
38481 | + /*wbrtop*/0); | |
7f207e10 AM |
38482 | + if (IS_ERR(file)) |
38483 | + goto out; | |
2000de60 | 38484 | + h_sb = file->f_path.dentry->d_sb; |
7f207e10 AM |
38485 | + if (unlikely(au_test_fs_bad_xino(h_sb))) { |
38486 | + pr_err("xino doesn't support %s(%s)\n", | |
38487 | + AUFS_XINO_DEFPATH, au_sbtype(h_sb)); | |
38488 | + fput(file); | |
38489 | + file = ERR_PTR(-EINVAL); | |
38490 | + } | |
7f207e10 | 38491 | + } |
0c5527e5 | 38492 | + |
7f207e10 AM |
38493 | +out: |
38494 | + return file; | |
38495 | +} | |
38496 | + | |
38497 | +/* ---------------------------------------------------------------------- */ | |
38498 | + | |
062440b3 AM |
38499 | +/* |
38500 | + * initialize the xinofile for the specified branch @br | |
38501 | + * at the place/path where @base_file indicates. | |
38502 | + * test whether another branch is on the same filesystem or not, | |
38503 | + * if found then share the xinofile with another branch. | |
38504 | + */ | |
38505 | +int au_xino_init_br(struct super_block *sb, struct au_branch *br, ino_t h_ino, | |
38506 | + struct path *base) | |
7f207e10 AM |
38507 | +{ |
38508 | + int err; | |
062440b3 AM |
38509 | + struct au_xino_do_set_br args = { |
38510 | + .h_ino = h_ino, | |
38511 | + .br = br | |
38512 | + }; | |
7f207e10 | 38513 | + |
062440b3 AM |
38514 | + args.writef = au_sbi(sb)->si_xwrite; |
38515 | + args.bshared = sbr_find_shared(sb, /*btop*/0, au_sbbot(sb), | |
38516 | + au_br_sb(br)); | |
38517 | + err = au_xino_do_set_br(sb, base, &args); | |
79b8bda9 | 38518 | + if (unlikely(err)) |
062440b3 | 38519 | + au_xino_put(br); |
7f207e10 | 38520 | + |
7f207e10 AM |
38521 | + return err; |
38522 | +} | |
521ced18 JR |
38523 | + |
38524 | +/* ---------------------------------------------------------------------- */ | |
38525 | + | |
062440b3 AM |
38526 | +/* |
38527 | + * get an unused inode number from bitmap | |
38528 | + */ | |
38529 | +ino_t au_xino_new_ino(struct super_block *sb) | |
38530 | +{ | |
38531 | + ino_t ino; | |
38532 | + unsigned long *p, pindex, ul, pend; | |
38533 | + struct au_sbinfo *sbinfo; | |
38534 | + struct file *file; | |
38535 | + int free_bit, err; | |
38536 | + | |
38537 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
38538 | + return iunique(sb, AUFS_FIRST_INO); | |
38539 | + | |
38540 | + sbinfo = au_sbi(sb); | |
38541 | + mutex_lock(&sbinfo->si_xib_mtx); | |
38542 | + p = sbinfo->si_xib_buf; | |
38543 | + free_bit = sbinfo->si_xib_next_bit; | |
38544 | + if (free_bit < page_bits && !test_bit(free_bit, p)) | |
38545 | + goto out; /* success */ | |
38546 | + free_bit = find_first_zero_bit(p, page_bits); | |
38547 | + if (free_bit < page_bits) | |
38548 | + goto out; /* success */ | |
38549 | + | |
38550 | + pindex = sbinfo->si_xib_last_pindex; | |
38551 | + for (ul = pindex - 1; ul < ULONG_MAX; ul--) { | |
38552 | + err = xib_pindex(sb, ul); | |
38553 | + if (unlikely(err)) | |
38554 | + goto out_err; | |
38555 | + free_bit = find_first_zero_bit(p, page_bits); | |
38556 | + if (free_bit < page_bits) | |
38557 | + goto out; /* success */ | |
38558 | + } | |
38559 | + | |
38560 | + file = sbinfo->si_xib; | |
38561 | + pend = vfsub_f_size_read(file) / PAGE_SIZE; | |
38562 | + for (ul = pindex + 1; ul <= pend; ul++) { | |
38563 | + err = xib_pindex(sb, ul); | |
38564 | + if (unlikely(err)) | |
38565 | + goto out_err; | |
38566 | + free_bit = find_first_zero_bit(p, page_bits); | |
38567 | + if (free_bit < page_bits) | |
38568 | + goto out; /* success */ | |
38569 | + } | |
38570 | + BUG(); | |
38571 | + | |
38572 | +out: | |
38573 | + set_bit(free_bit, p); | |
38574 | + sbinfo->si_xib_next_bit = free_bit + 1; | |
38575 | + pindex = sbinfo->si_xib_last_pindex; | |
38576 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
38577 | + ino = xib_calc_ino(pindex, free_bit); | |
38578 | + AuDbg("i%lu\n", (unsigned long)ino); | |
38579 | + return ino; | |
38580 | +out_err: | |
38581 | + mutex_unlock(&sbinfo->si_xib_mtx); | |
38582 | + AuDbg("i0\n"); | |
38583 | + return 0; | |
38584 | +} | |
38585 | + | |
38586 | +/* for s_op->delete_inode() */ | |
38587 | +void au_xino_delete_inode(struct inode *inode, const int unlinked) | |
521ced18 | 38588 | +{ |
062440b3 AM |
38589 | + int err; |
38590 | + unsigned int mnt_flags; | |
38591 | + aufs_bindex_t bindex, bbot, bi; | |
38592 | + unsigned char try_trunc; | |
38593 | + struct au_iinfo *iinfo; | |
38594 | + struct super_block *sb; | |
38595 | + struct au_hinode *hi; | |
38596 | + struct inode *h_inode; | |
38597 | + struct au_branch *br; | |
38598 | + vfs_writef_t xwrite; | |
acd2b654 AM |
38599 | + struct au_xi_calc calc; |
38600 | + struct file *file; | |
521ced18 | 38601 | + |
062440b3 | 38602 | + AuDebugOn(au_is_bad_inode(inode)); |
521ced18 | 38603 | + |
062440b3 AM |
38604 | + sb = inode->i_sb; |
38605 | + mnt_flags = au_mntflags(sb); | |
38606 | + if (!au_opt_test(mnt_flags, XINO) | |
38607 | + || inode->i_ino == AUFS_ROOT_INO) | |
38608 | + return; | |
38609 | + | |
38610 | + if (unlinked) { | |
38611 | + au_xigen_inc(inode); | |
38612 | + au_xib_clear_bit(inode); | |
38613 | + } | |
38614 | + | |
38615 | + iinfo = au_ii(inode); | |
38616 | + bindex = iinfo->ii_btop; | |
38617 | + if (bindex < 0) | |
38618 | + return; | |
38619 | + | |
38620 | + xwrite = au_sbi(sb)->si_xwrite; | |
38621 | + try_trunc = !!au_opt_test(mnt_flags, TRUNC_XINO); | |
38622 | + hi = au_hinode(iinfo, bindex); | |
38623 | + bbot = iinfo->ii_bbot; | |
38624 | + for (; bindex <= bbot; bindex++, hi++) { | |
38625 | + h_inode = hi->hi_inode; | |
38626 | + if (!h_inode | |
38627 | + || (!unlinked && h_inode->i_nlink)) | |
38628 | + continue; | |
38629 | + | |
38630 | + /* inode may not be revalidated */ | |
38631 | + bi = au_br_index(sb, hi->hi_id); | |
38632 | + if (bi < 0) | |
38633 | + continue; | |
38634 | + | |
38635 | + br = au_sbr(sb, bi); | |
acd2b654 AM |
38636 | + au_xi_calc(sb, h_inode->i_ino, &calc); |
38637 | + file = au_xino_file(br->br_xino, calc.idx); | |
38638 | + if (IS_ERR_OR_NULL(file)) | |
38639 | + continue; | |
38640 | + | |
38641 | + err = au_xino_do_write(xwrite, file, &calc, /*ino*/0); | |
062440b3 AM |
38642 | + if (!err && try_trunc |
38643 | + && au_test_fs_trunc_xino(au_br_sb(br))) | |
38644 | + xino_try_trunc(sb, br); | |
38645 | + } | |
521ced18 JR |
38646 | +} |
38647 | + | |
062440b3 AM |
38648 | +/* ---------------------------------------------------------------------- */ |
38649 | + | |
38650 | +static int au_xinondir_find(struct au_xino *xi, ino_t h_ino) | |
521ced18 JR |
38651 | +{ |
38652 | + int found, total, i; | |
38653 | + | |
38654 | + found = -1; | |
062440b3 | 38655 | + total = xi->xi_nondir.total; |
521ced18 | 38656 | + for (i = 0; i < total; i++) { |
062440b3 | 38657 | + if (xi->xi_nondir.array[i] != h_ino) |
521ced18 JR |
38658 | + continue; |
38659 | + found = i; | |
38660 | + break; | |
38661 | + } | |
38662 | + | |
38663 | + return found; | |
38664 | +} | |
38665 | + | |
062440b3 | 38666 | +static int au_xinondir_expand(struct au_xino *xi) |
521ced18 JR |
38667 | +{ |
38668 | + int err, sz; | |
38669 | + ino_t *p; | |
38670 | + | |
38671 | + BUILD_BUG_ON(KMALLOC_MAX_SIZE > INT_MAX); | |
38672 | + | |
38673 | + err = -ENOMEM; | |
062440b3 | 38674 | + sz = xi->xi_nondir.total * sizeof(ino_t); |
521ced18 JR |
38675 | + if (unlikely(sz > KMALLOC_MAX_SIZE / 2)) |
38676 | + goto out; | |
062440b3 | 38677 | + p = au_kzrealloc(xi->xi_nondir.array, sz, sz << 1, GFP_ATOMIC, |
521ced18 JR |
38678 | + /*may_shrink*/0); |
38679 | + if (p) { | |
062440b3 AM |
38680 | + xi->xi_nondir.array = p; |
38681 | + xi->xi_nondir.total <<= 1; | |
38682 | + AuDbg("xi_nondir.total %d\n", xi->xi_nondir.total); | |
521ced18 JR |
38683 | + err = 0; |
38684 | + } | |
38685 | + | |
38686 | +out: | |
38687 | + return err; | |
38688 | +} | |
38689 | + | |
062440b3 AM |
38690 | +void au_xinondir_leave(struct super_block *sb, aufs_bindex_t bindex, |
38691 | + ino_t h_ino, int idx) | |
38692 | +{ | |
38693 | + struct au_xino *xi; | |
38694 | + | |
38695 | + AuDebugOn(!au_opt_test(au_mntflags(sb), XINO)); | |
38696 | + xi = au_sbr(sb, bindex)->br_xino; | |
38697 | + AuDebugOn(idx < 0 || xi->xi_nondir.total <= idx); | |
38698 | + | |
38699 | + spin_lock(&xi->xi_nondir.spin); | |
38700 | + AuDebugOn(xi->xi_nondir.array[idx] != h_ino); | |
38701 | + xi->xi_nondir.array[idx] = 0; | |
38702 | + spin_unlock(&xi->xi_nondir.spin); | |
38703 | + wake_up_all(&xi->xi_nondir.wqh); | |
38704 | +} | |
38705 | + | |
521ced18 JR |
38706 | +int au_xinondir_enter(struct super_block *sb, aufs_bindex_t bindex, ino_t h_ino, |
38707 | + int *idx) | |
38708 | +{ | |
38709 | + int err, found, empty; | |
062440b3 | 38710 | + struct au_xino *xi; |
521ced18 JR |
38711 | + |
38712 | + err = 0; | |
38713 | + *idx = -1; | |
38714 | + if (!au_opt_test(au_mntflags(sb), XINO)) | |
38715 | + goto out; /* no xino */ | |
38716 | + | |
062440b3 | 38717 | + xi = au_sbr(sb, bindex)->br_xino; |
521ced18 JR |
38718 | + |
38719 | +again: | |
062440b3 AM |
38720 | + spin_lock(&xi->xi_nondir.spin); |
38721 | + found = au_xinondir_find(xi, h_ino); | |
521ced18 | 38722 | + if (found == -1) { |
062440b3 | 38723 | + empty = au_xinondir_find(xi, /*h_ino*/0); |
521ced18 | 38724 | + if (empty == -1) { |
062440b3 AM |
38725 | + empty = xi->xi_nondir.total; |
38726 | + err = au_xinondir_expand(xi); | |
521ced18 JR |
38727 | + if (unlikely(err)) |
38728 | + goto out_unlock; | |
38729 | + } | |
062440b3 | 38730 | + xi->xi_nondir.array[empty] = h_ino; |
521ced18 JR |
38731 | + *idx = empty; |
38732 | + } else { | |
062440b3 AM |
38733 | + spin_unlock(&xi->xi_nondir.spin); |
38734 | + wait_event(xi->xi_nondir.wqh, | |
38735 | + xi->xi_nondir.array[found] != h_ino); | |
521ced18 JR |
38736 | + goto again; |
38737 | + } | |
38738 | + | |
38739 | +out_unlock: | |
062440b3 AM |
38740 | + spin_unlock(&xi->xi_nondir.spin); |
38741 | +out: | |
38742 | + return err; | |
38743 | +} | |
38744 | + | |
38745 | +/* ---------------------------------------------------------------------- */ | |
38746 | + | |
38747 | +int au_xino_path(struct seq_file *seq, struct file *file) | |
38748 | +{ | |
38749 | + int err; | |
38750 | + | |
38751 | + err = au_seq_path(seq, &file->f_path); | |
38752 | + if (unlikely(err)) | |
38753 | + goto out; | |
38754 | + | |
38755 | +#define Deleted "\\040(deleted)" | |
38756 | + seq->count -= sizeof(Deleted) - 1; | |
38757 | + AuDebugOn(memcmp(seq->buf + seq->count, Deleted, | |
38758 | + sizeof(Deleted) - 1)); | |
38759 | +#undef Deleted | |
38760 | + | |
521ced18 JR |
38761 | +out: |
38762 | + return err; | |
38763 | +} | |
537831f9 | 38764 | diff -urN /usr/share/empty/include/uapi/linux/aufs_type.h linux/include/uapi/linux/aufs_type.h |
eca34b5c | 38765 | --- /usr/share/empty/include/uapi/linux/aufs_type.h 1970-01-01 01:00:00.000000000 +0100 |
d58c55f2 | 38766 | +++ linux/include/uapi/linux/aufs_type.h 2020-01-27 10:57:18.182205184 +0100 |
eca34b5c AM |
38767 | @@ -0,0 +1,452 @@ |
38768 | +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ | |
7f207e10 | 38769 | +/* |
d58c55f2 | 38770 | + * Copyright (C) 2005-2020 Junjiro R. Okajima |
7f207e10 AM |
38771 | + * |
38772 | + * This program, aufs is free software; you can redistribute it and/or modify | |
38773 | + * it under the terms of the GNU General Public License as published by | |
38774 | + * the Free Software Foundation; either version 2 of the License, or | |
38775 | + * (at your option) any later version. | |
38776 | + * | |
38777 | + * This program is distributed in the hope that it will be useful, | |
38778 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
38779 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
38780 | + * GNU General Public License for more details. | |
38781 | + * | |
38782 | + * You should have received a copy of the GNU General Public License | |
523b37e3 | 38783 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
7f207e10 AM |
38784 | + */ |
38785 | + | |
38786 | +#ifndef __AUFS_TYPE_H__ | |
38787 | +#define __AUFS_TYPE_H__ | |
38788 | + | |
f6c5ef8b AM |
38789 | +#define AUFS_NAME "aufs" |
38790 | + | |
9dbd164d | 38791 | +#ifdef __KERNEL__ |
f6c5ef8b AM |
38792 | +/* |
38793 | + * define it before including all other headers. | |
38794 | + * sched.h may use pr_* macros before defining "current", so define the | |
38795 | + * no-current version first, and re-define later. | |
38796 | + */ | |
38797 | +#define pr_fmt(fmt) AUFS_NAME " %s:%d: " fmt, __func__, __LINE__ | |
38798 | +#include <linux/sched.h> | |
38799 | +#undef pr_fmt | |
a2a7ad62 AM |
38800 | +#define pr_fmt(fmt) \ |
38801 | + AUFS_NAME " %s:%d:%.*s[%d]: " fmt, __func__, __LINE__, \ | |
38802 | + (int)sizeof(current->comm), current->comm, current->pid | |
43982f53 | 38803 | +#include <linux/limits.h> |
9dbd164d AM |
38804 | +#else |
38805 | +#include <stdint.h> | |
38806 | +#include <sys/types.h> | |
43982f53 | 38807 | +#include <limits.h> |
f6c5ef8b | 38808 | +#endif /* __KERNEL__ */ |
7f207e10 | 38809 | + |
d58c55f2 | 38810 | +#define AUFS_VERSION "5.x-rcN-20200127" |
7f207e10 AM |
38811 | + |
38812 | +/* todo? move this to linux-2.6.19/include/magic.h */ | |
38813 | +#define AUFS_SUPER_MAGIC ('a' << 24 | 'u' << 16 | 'f' << 8 | 's') | |
38814 | + | |
38815 | +/* ---------------------------------------------------------------------- */ | |
38816 | + | |
43982f53 | 38817 | +#ifdef __KERNEL__ |
7f207e10 | 38818 | +#ifdef CONFIG_AUFS_BRANCH_MAX_127 |
9dbd164d | 38819 | +typedef int8_t aufs_bindex_t; |
7f207e10 AM |
38820 | +#define AUFS_BRANCH_MAX 127 |
38821 | +#else | |
9dbd164d | 38822 | +typedef int16_t aufs_bindex_t; |
7f207e10 AM |
38823 | +#ifdef CONFIG_AUFS_BRANCH_MAX_511 |
38824 | +#define AUFS_BRANCH_MAX 511 | |
38825 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_1023) | |
38826 | +#define AUFS_BRANCH_MAX 1023 | |
38827 | +#elif defined(CONFIG_AUFS_BRANCH_MAX_32767) | |
38828 | +#define AUFS_BRANCH_MAX 32767 | |
38829 | +#endif | |
38830 | +#endif | |
38831 | + | |
7f207e10 AM |
38832 | +#ifndef AUFS_BRANCH_MAX |
38833 | +#error unknown CONFIG_AUFS_BRANCH_MAX value | |
38834 | +#endif | |
38835 | +#endif /* __KERNEL__ */ | |
38836 | + | |
38837 | +/* ---------------------------------------------------------------------- */ | |
38838 | + | |
7f207e10 AM |
38839 | +#define AUFS_FSTYPE AUFS_NAME |
38840 | + | |
38841 | +#define AUFS_ROOT_INO 2 | |
38842 | +#define AUFS_FIRST_INO 11 | |
38843 | + | |
38844 | +#define AUFS_WH_PFX ".wh." | |
38845 | +#define AUFS_WH_PFX_LEN ((int)sizeof(AUFS_WH_PFX) - 1) | |
38846 | +#define AUFS_WH_TMP_LEN 4 | |
86dc4139 | 38847 | +/* a limit for rmdir/rename a dir and copyup */ |
7f207e10 AM |
38848 | +#define AUFS_MAX_NAMELEN (NAME_MAX \ |
38849 | + - AUFS_WH_PFX_LEN * 2 /* doubly whiteouted */\ | |
38850 | + - 1 /* dot */\ | |
38851 | + - AUFS_WH_TMP_LEN) /* hex */ | |
38852 | +#define AUFS_XINO_FNAME "." AUFS_NAME ".xino" | |
38853 | +#define AUFS_XINO_DEFPATH "/tmp/" AUFS_XINO_FNAME | |
392086de AM |
38854 | +#define AUFS_XINO_DEF_SEC 30 /* seconds */ |
38855 | +#define AUFS_XINO_DEF_TRUNC 45 /* percentage */ | |
7f207e10 AM |
38856 | +#define AUFS_DIRWH_DEF 3 |
38857 | +#define AUFS_RDCACHE_DEF 10 /* seconds */ | |
027c5e7a | 38858 | +#define AUFS_RDCACHE_MAX 3600 /* seconds */ |
7f207e10 AM |
38859 | +#define AUFS_RDBLK_DEF 512 /* bytes */ |
38860 | +#define AUFS_RDHASH_DEF 32 | |
38861 | +#define AUFS_WKQ_NAME AUFS_NAME "d" | |
027c5e7a AM |
38862 | +#define AUFS_MFS_DEF_SEC 30 /* seconds */ |
38863 | +#define AUFS_MFS_MAX_SEC 3600 /* seconds */ | |
076b876e | 38864 | +#define AUFS_FHSM_CACHE_DEF_SEC 30 /* seconds */ |
86dc4139 | 38865 | +#define AUFS_PLINK_WARN 50 /* number of plinks in a single bucket */ |
7f207e10 AM |
38866 | + |
38867 | +/* pseudo-link maintenace under /proc */ | |
38868 | +#define AUFS_PLINK_MAINT_NAME "plink_maint" | |
38869 | +#define AUFS_PLINK_MAINT_DIR "fs/" AUFS_NAME | |
38870 | +#define AUFS_PLINK_MAINT_PATH AUFS_PLINK_MAINT_DIR "/" AUFS_PLINK_MAINT_NAME | |
38871 | + | |
8b6a4947 AM |
38872 | +/* dirren, renamed dir */ |
38873 | +#define AUFS_DR_INFO_PFX AUFS_WH_PFX ".dr." | |
38874 | +#define AUFS_DR_BRHINO_NAME AUFS_WH_PFX "hino" | |
38875 | +/* whiteouted doubly */ | |
38876 | +#define AUFS_WH_DR_INFO_PFX AUFS_WH_PFX AUFS_DR_INFO_PFX | |
38877 | +#define AUFS_WH_DR_BRHINO AUFS_WH_PFX AUFS_DR_BRHINO_NAME | |
38878 | + | |
7f207e10 AM |
38879 | +#define AUFS_DIROPQ_NAME AUFS_WH_PFX ".opq" /* whiteouted doubly */ |
38880 | +#define AUFS_WH_DIROPQ AUFS_WH_PFX AUFS_DIROPQ_NAME | |
38881 | + | |
38882 | +#define AUFS_BASE_NAME AUFS_WH_PFX AUFS_NAME | |
38883 | +#define AUFS_PLINKDIR_NAME AUFS_WH_PFX "plnk" | |
38884 | +#define AUFS_ORPHDIR_NAME AUFS_WH_PFX "orph" | |
38885 | + | |
38886 | +/* doubly whiteouted */ | |
38887 | +#define AUFS_WH_BASE AUFS_WH_PFX AUFS_BASE_NAME | |
38888 | +#define AUFS_WH_PLINKDIR AUFS_WH_PFX AUFS_PLINKDIR_NAME | |
38889 | +#define AUFS_WH_ORPHDIR AUFS_WH_PFX AUFS_ORPHDIR_NAME | |
38890 | + | |
1e00d052 | 38891 | +/* branch permissions and attributes */ |
7f207e10 AM |
38892 | +#define AUFS_BRPERM_RW "rw" |
38893 | +#define AUFS_BRPERM_RO "ro" | |
38894 | +#define AUFS_BRPERM_RR "rr" | |
076b876e AM |
38895 | +#define AUFS_BRATTR_COO_REG "coo_reg" |
38896 | +#define AUFS_BRATTR_COO_ALL "coo_all" | |
38897 | +#define AUFS_BRATTR_FHSM "fhsm" | |
38898 | +#define AUFS_BRATTR_UNPIN "unpin" | |
c1595e42 JR |
38899 | +#define AUFS_BRATTR_ICEX "icex" |
38900 | +#define AUFS_BRATTR_ICEX_SEC "icexsec" | |
38901 | +#define AUFS_BRATTR_ICEX_SYS "icexsys" | |
38902 | +#define AUFS_BRATTR_ICEX_TR "icextr" | |
38903 | +#define AUFS_BRATTR_ICEX_USR "icexusr" | |
38904 | +#define AUFS_BRATTR_ICEX_OTH "icexoth" | |
1e00d052 AM |
38905 | +#define AUFS_BRRATTR_WH "wh" |
38906 | +#define AUFS_BRWATTR_NLWH "nolwh" | |
076b876e AM |
38907 | +#define AUFS_BRWATTR_MOO "moo" |
38908 | + | |
38909 | +#define AuBrPerm_RW 1 /* writable, hardlinkable wh */ | |
38910 | +#define AuBrPerm_RO (1 << 1) /* readonly */ | |
38911 | +#define AuBrPerm_RR (1 << 2) /* natively readonly */ | |
38912 | +#define AuBrPerm_Mask (AuBrPerm_RW | AuBrPerm_RO | AuBrPerm_RR) | |
38913 | + | |
38914 | +#define AuBrAttr_COO_REG (1 << 3) /* copy-up on open */ | |
38915 | +#define AuBrAttr_COO_ALL (1 << 4) | |
38916 | +#define AuBrAttr_COO_Mask (AuBrAttr_COO_REG | AuBrAttr_COO_ALL) | |
38917 | + | |
38918 | +#define AuBrAttr_FHSM (1 << 5) /* file-based hsm */ | |
38919 | +#define AuBrAttr_UNPIN (1 << 6) /* rename-able top dir of | |
c1595e42 JR |
38920 | + branch. meaningless since |
38921 | + linux-3.18-rc1 */ | |
38922 | + | |
38923 | +/* ignore error in copying XATTR */ | |
38924 | +#define AuBrAttr_ICEX_SEC (1 << 7) | |
38925 | +#define AuBrAttr_ICEX_SYS (1 << 8) | |
38926 | +#define AuBrAttr_ICEX_TR (1 << 9) | |
38927 | +#define AuBrAttr_ICEX_USR (1 << 10) | |
38928 | +#define AuBrAttr_ICEX_OTH (1 << 11) | |
38929 | +#define AuBrAttr_ICEX (AuBrAttr_ICEX_SEC \ | |
38930 | + | AuBrAttr_ICEX_SYS \ | |
38931 | + | AuBrAttr_ICEX_TR \ | |
38932 | + | AuBrAttr_ICEX_USR \ | |
38933 | + | AuBrAttr_ICEX_OTH) | |
38934 | + | |
38935 | +#define AuBrRAttr_WH (1 << 12) /* whiteout-able */ | |
076b876e AM |
38936 | +#define AuBrRAttr_Mask AuBrRAttr_WH |
38937 | + | |
c1595e42 JR |
38938 | +#define AuBrWAttr_NoLinkWH (1 << 13) /* un-hardlinkable whiteouts */ |
38939 | +#define AuBrWAttr_MOO (1 << 14) /* move-up on open */ | |
076b876e AM |
38940 | +#define AuBrWAttr_Mask (AuBrWAttr_NoLinkWH | AuBrWAttr_MOO) |
38941 | + | |
38942 | +#define AuBrAttr_CMOO_Mask (AuBrAttr_COO_Mask | AuBrWAttr_MOO) | |
38943 | + | |
c1595e42 | 38944 | +/* #warning test userspace */ |
076b876e AM |
38945 | +#ifdef __KERNEL__ |
38946 | +#ifndef CONFIG_AUFS_FHSM | |
38947 | +#undef AuBrAttr_FHSM | |
38948 | +#define AuBrAttr_FHSM 0 | |
38949 | +#endif | |
c1595e42 JR |
38950 | +#ifndef CONFIG_AUFS_XATTR |
38951 | +#undef AuBrAttr_ICEX | |
38952 | +#define AuBrAttr_ICEX 0 | |
38953 | +#undef AuBrAttr_ICEX_SEC | |
38954 | +#define AuBrAttr_ICEX_SEC 0 | |
38955 | +#undef AuBrAttr_ICEX_SYS | |
38956 | +#define AuBrAttr_ICEX_SYS 0 | |
38957 | +#undef AuBrAttr_ICEX_TR | |
38958 | +#define AuBrAttr_ICEX_TR 0 | |
38959 | +#undef AuBrAttr_ICEX_USR | |
38960 | +#define AuBrAttr_ICEX_USR 0 | |
38961 | +#undef AuBrAttr_ICEX_OTH | |
38962 | +#define AuBrAttr_ICEX_OTH 0 | |
38963 | +#endif | |
076b876e AM |
38964 | +#endif |
38965 | + | |
38966 | +/* the longest combination */ | |
c1595e42 JR |
38967 | +/* AUFS_BRATTR_ICEX and AUFS_BRATTR_ICEX_TR don't affect here */ |
38968 | +#define AuBrPermStrSz sizeof(AUFS_BRPERM_RW \ | |
38969 | + "+" AUFS_BRATTR_COO_REG \ | |
38970 | + "+" AUFS_BRATTR_FHSM \ | |
38971 | + "+" AUFS_BRATTR_UNPIN \ | |
7e9cd9fe AM |
38972 | + "+" AUFS_BRATTR_ICEX_SEC \ |
38973 | + "+" AUFS_BRATTR_ICEX_SYS \ | |
38974 | + "+" AUFS_BRATTR_ICEX_USR \ | |
38975 | + "+" AUFS_BRATTR_ICEX_OTH \ | |
076b876e AM |
38976 | + "+" AUFS_BRWATTR_NLWH) |
38977 | + | |
38978 | +typedef struct { | |
38979 | + char a[AuBrPermStrSz]; | |
38980 | +} au_br_perm_str_t; | |
38981 | + | |
38982 | +static inline int au_br_writable(int brperm) | |
38983 | +{ | |
38984 | + return brperm & AuBrPerm_RW; | |
38985 | +} | |
38986 | + | |
38987 | +static inline int au_br_whable(int brperm) | |
38988 | +{ | |
38989 | + return brperm & (AuBrPerm_RW | AuBrRAttr_WH); | |
38990 | +} | |
38991 | + | |
38992 | +static inline int au_br_wh_linkable(int brperm) | |
38993 | +{ | |
38994 | + return !(brperm & AuBrWAttr_NoLinkWH); | |
38995 | +} | |
38996 | + | |
38997 | +static inline int au_br_cmoo(int brperm) | |
38998 | +{ | |
38999 | + return brperm & AuBrAttr_CMOO_Mask; | |
39000 | +} | |
39001 | + | |
39002 | +static inline int au_br_fhsm(int brperm) | |
39003 | +{ | |
39004 | + return brperm & AuBrAttr_FHSM; | |
39005 | +} | |
7f207e10 AM |
39006 | + |
39007 | +/* ---------------------------------------------------------------------- */ | |
39008 | + | |
39009 | +/* ioctl */ | |
39010 | +enum { | |
39011 | + /* readdir in userspace */ | |
39012 | + AuCtl_RDU, | |
39013 | + AuCtl_RDU_INO, | |
39014 | + | |
076b876e AM |
39015 | + AuCtl_WBR_FD, /* pathconf wrapper */ |
39016 | + AuCtl_IBUSY, /* busy inode */ | |
39017 | + AuCtl_MVDOWN, /* move-down */ | |
39018 | + AuCtl_BR, /* info about branches */ | |
39019 | + AuCtl_FHSM_FD /* connection for fhsm */ | |
7f207e10 AM |
39020 | +}; |
39021 | + | |
39022 | +/* borrowed from linux/include/linux/kernel.h */ | |
39023 | +#ifndef ALIGN | |
eca34b5c | 39024 | +#ifdef _GNU_SOURCE |
7f207e10 | 39025 | +#define ALIGN(x, a) __ALIGN_MASK(x, (typeof(x))(a)-1) |
eca34b5c AM |
39026 | +#else |
39027 | +#define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1)) | |
39028 | +#endif | |
7f207e10 AM |
39029 | +#define __ALIGN_MASK(x, mask) (((x)+(mask))&~(mask)) |
39030 | +#endif | |
39031 | + | |
39032 | +/* borrowed from linux/include/linux/compiler-gcc3.h */ | |
39033 | +#ifndef __aligned | |
39034 | +#define __aligned(x) __attribute__((aligned(x))) | |
53392da6 AM |
39035 | +#endif |
39036 | + | |
39037 | +#ifdef __KERNEL__ | |
39038 | +#ifndef __packed | |
7f207e10 AM |
39039 | +#define __packed __attribute__((packed)) |
39040 | +#endif | |
53392da6 | 39041 | +#endif |
7f207e10 AM |
39042 | + |
39043 | +struct au_rdu_cookie { | |
9dbd164d AM |
39044 | + uint64_t h_pos; |
39045 | + int16_t bindex; | |
39046 | + uint8_t flags; | |
39047 | + uint8_t pad; | |
39048 | + uint32_t generation; | |
7f207e10 AM |
39049 | +} __aligned(8); |
39050 | + | |
39051 | +struct au_rdu_ent { | |
9dbd164d AM |
39052 | + uint64_t ino; |
39053 | + int16_t bindex; | |
39054 | + uint8_t type; | |
39055 | + uint8_t nlen; | |
39056 | + uint8_t wh; | |
7f207e10 AM |
39057 | + char name[0]; |
39058 | +} __aligned(8); | |
39059 | + | |
39060 | +static inline int au_rdu_len(int nlen) | |
39061 | +{ | |
39062 | + /* include the terminating NULL */ | |
39063 | + return ALIGN(sizeof(struct au_rdu_ent) + nlen + 1, | |
9dbd164d | 39064 | + sizeof(uint64_t)); |
7f207e10 AM |
39065 | +} |
39066 | + | |
39067 | +union au_rdu_ent_ul { | |
39068 | + struct au_rdu_ent __user *e; | |
9dbd164d | 39069 | + uint64_t ul; |
7f207e10 AM |
39070 | +}; |
39071 | + | |
39072 | +enum { | |
39073 | + AufsCtlRduV_SZ, | |
39074 | + AufsCtlRduV_End | |
39075 | +}; | |
39076 | + | |
39077 | +struct aufs_rdu { | |
39078 | + /* input */ | |
39079 | + union { | |
9dbd164d AM |
39080 | + uint64_t sz; /* AuCtl_RDU */ |
39081 | + uint64_t nent; /* AuCtl_RDU_INO */ | |
7f207e10 AM |
39082 | + }; |
39083 | + union au_rdu_ent_ul ent; | |
9dbd164d | 39084 | + uint16_t verify[AufsCtlRduV_End]; |
7f207e10 AM |
39085 | + |
39086 | + /* input/output */ | |
9dbd164d | 39087 | + uint32_t blk; |
7f207e10 AM |
39088 | + |
39089 | + /* output */ | |
39090 | + union au_rdu_ent_ul tail; | |
39091 | + /* number of entries which were added in a single call */ | |
9dbd164d AM |
39092 | + uint64_t rent; |
39093 | + uint8_t full; | |
39094 | + uint8_t shwh; | |
7f207e10 AM |
39095 | + |
39096 | + struct au_rdu_cookie cookie; | |
39097 | +} __aligned(8); | |
39098 | + | |
1e00d052 AM |
39099 | +/* ---------------------------------------------------------------------- */ |
39100 | + | |
8b6a4947 AM |
39101 | +/* dirren. the branch is identified by the filename who contains this */ |
39102 | +struct au_drinfo { | |
39103 | + uint64_t ino; | |
39104 | + union { | |
39105 | + uint8_t oldnamelen; | |
39106 | + uint64_t _padding; | |
39107 | + }; | |
39108 | + uint8_t oldname[0]; | |
39109 | +} __aligned(8); | |
39110 | + | |
39111 | +struct au_drinfo_fdata { | |
39112 | + uint32_t magic; | |
39113 | + struct au_drinfo drinfo; | |
39114 | +} __aligned(8); | |
39115 | + | |
39116 | +#define AUFS_DRINFO_MAGIC_V1 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x01) | |
39117 | +/* future */ | |
39118 | +#define AUFS_DRINFO_MAGIC_V2 ('a' << 24 | 'd' << 16 | 'r' << 8 | 0x02) | |
39119 | + | |
39120 | +/* ---------------------------------------------------------------------- */ | |
39121 | + | |
1e00d052 | 39122 | +struct aufs_wbr_fd { |
9dbd164d AM |
39123 | + uint32_t oflags; |
39124 | + int16_t brid; | |
1e00d052 AM |
39125 | +} __aligned(8); |
39126 | + | |
39127 | +/* ---------------------------------------------------------------------- */ | |
39128 | + | |
027c5e7a | 39129 | +struct aufs_ibusy { |
9dbd164d AM |
39130 | + uint64_t ino, h_ino; |
39131 | + int16_t bindex; | |
027c5e7a AM |
39132 | +} __aligned(8); |
39133 | + | |
1e00d052 AM |
39134 | +/* ---------------------------------------------------------------------- */ |
39135 | + | |
392086de AM |
39136 | +/* error code for move-down */ |
39137 | +/* the actual message strings are implemented in aufs-util.git */ | |
39138 | +enum { | |
39139 | + EAU_MVDOWN_OPAQUE = 1, | |
39140 | + EAU_MVDOWN_WHITEOUT, | |
39141 | + EAU_MVDOWN_UPPER, | |
39142 | + EAU_MVDOWN_BOTTOM, | |
39143 | + EAU_MVDOWN_NOUPPER, | |
39144 | + EAU_MVDOWN_NOLOWERBR, | |
39145 | + EAU_Last | |
39146 | +}; | |
39147 | + | |
c2b27bf2 | 39148 | +/* flags for move-down */ |
392086de AM |
39149 | +#define AUFS_MVDOWN_DMSG 1 |
39150 | +#define AUFS_MVDOWN_OWLOWER (1 << 1) /* overwrite lower */ | |
39151 | +#define AUFS_MVDOWN_KUPPER (1 << 2) /* keep upper */ | |
39152 | +#define AUFS_MVDOWN_ROLOWER (1 << 3) /* do even if lower is RO */ | |
39153 | +#define AUFS_MVDOWN_ROLOWER_R (1 << 4) /* did on lower RO */ | |
39154 | +#define AUFS_MVDOWN_ROUPPER (1 << 5) /* do even if upper is RO */ | |
39155 | +#define AUFS_MVDOWN_ROUPPER_R (1 << 6) /* did on upper RO */ | |
39156 | +#define AUFS_MVDOWN_BRID_UPPER (1 << 7) /* upper brid */ | |
39157 | +#define AUFS_MVDOWN_BRID_LOWER (1 << 8) /* lower brid */ | |
076b876e AM |
39158 | +#define AUFS_MVDOWN_FHSM_LOWER (1 << 9) /* find fhsm attr for lower */ |
39159 | +#define AUFS_MVDOWN_STFS (1 << 10) /* req. stfs */ | |
39160 | +#define AUFS_MVDOWN_STFS_FAILED (1 << 11) /* output: stfs is unusable */ | |
39161 | +#define AUFS_MVDOWN_BOTTOM (1 << 12) /* output: no more lowers */ | |
c2b27bf2 | 39162 | + |
076b876e | 39163 | +/* index for move-down */ |
392086de AM |
39164 | +enum { |
39165 | + AUFS_MVDOWN_UPPER, | |
39166 | + AUFS_MVDOWN_LOWER, | |
39167 | + AUFS_MVDOWN_NARRAY | |
39168 | +}; | |
39169 | + | |
076b876e AM |
39170 | +/* |
39171 | + * additional info of move-down | |
39172 | + * number of free blocks and inodes. | |
39173 | + * subset of struct kstatfs, but smaller and always 64bit. | |
39174 | + */ | |
39175 | +struct aufs_stfs { | |
39176 | + uint64_t f_blocks; | |
39177 | + uint64_t f_bavail; | |
39178 | + uint64_t f_files; | |
39179 | + uint64_t f_ffree; | |
39180 | +}; | |
39181 | + | |
39182 | +struct aufs_stbr { | |
39183 | + int16_t brid; /* optional input */ | |
39184 | + int16_t bindex; /* output */ | |
39185 | + struct aufs_stfs stfs; /* output when AUFS_MVDOWN_STFS set */ | |
39186 | +} __aligned(8); | |
39187 | + | |
c2b27bf2 | 39188 | +struct aufs_mvdown { |
076b876e AM |
39189 | + uint32_t flags; /* input/output */ |
39190 | + struct aufs_stbr stbr[AUFS_MVDOWN_NARRAY]; /* input/output */ | |
39191 | + int8_t au_errno; /* output */ | |
39192 | +} __aligned(8); | |
39193 | + | |
39194 | +/* ---------------------------------------------------------------------- */ | |
39195 | + | |
39196 | +union aufs_brinfo { | |
39197 | + /* PATH_MAX may differ between kernel-space and user-space */ | |
39198 | + char _spacer[4096]; | |
392086de | 39199 | + struct { |
076b876e AM |
39200 | + int16_t id; |
39201 | + int perm; | |
39202 | + char path[0]; | |
39203 | + }; | |
c2b27bf2 AM |
39204 | +} __aligned(8); |
39205 | + | |
39206 | +/* ---------------------------------------------------------------------- */ | |
39207 | + | |
7f207e10 AM |
39208 | +#define AuCtlType 'A' |
39209 | +#define AUFS_CTL_RDU _IOWR(AuCtlType, AuCtl_RDU, struct aufs_rdu) | |
39210 | +#define AUFS_CTL_RDU_INO _IOWR(AuCtlType, AuCtl_RDU_INO, struct aufs_rdu) | |
1e00d052 AM |
39211 | +#define AUFS_CTL_WBR_FD _IOW(AuCtlType, AuCtl_WBR_FD, \ |
39212 | + struct aufs_wbr_fd) | |
027c5e7a | 39213 | +#define AUFS_CTL_IBUSY _IOWR(AuCtlType, AuCtl_IBUSY, struct aufs_ibusy) |
392086de AM |
39214 | +#define AUFS_CTL_MVDOWN _IOWR(AuCtlType, AuCtl_MVDOWN, \ |
39215 | + struct aufs_mvdown) | |
076b876e AM |
39216 | +#define AUFS_CTL_BRINFO _IOW(AuCtlType, AuCtl_BR, union aufs_brinfo) |
39217 | +#define AUFS_CTL_FHSM_FD _IOW(AuCtlType, AuCtl_FHSM_FD, int) | |
7f207e10 AM |
39218 | + |
39219 | +#endif /* __AUFS_TYPE_H__ */ | |
2121bcd9 | 39220 | SPDX-License-Identifier: GPL-2.0 |
d58c55f2 | 39221 | aufs5.x-rcN loopback patch |
5527c038 JR |
39222 | |
39223 | diff --git a/drivers/block/loop.c b/drivers/block/loop.c | |
d58c55f2 | 39224 | index 872e3b3a7693..768100025129 100644 |
5527c038 JR |
39225 | --- a/drivers/block/loop.c |
39226 | +++ b/drivers/block/loop.c | |
d58c55f2 | 39227 | @@ -635,6 +635,15 @@ static inline void loop_update_dio(struct loop_device *lo) |
8b6a4947 | 39228 | lo->use_dio); |
5527c038 JR |
39229 | } |
39230 | ||
5527c038 JR |
39231 | +static struct file *loop_real_file(struct file *file) |
39232 | +{ | |
39233 | + struct file *f = NULL; | |
39234 | + | |
39235 | + if (file->f_path.dentry->d_sb->s_op->real_loop) | |
39236 | + f = file->f_path.dentry->d_sb->s_op->real_loop(file); | |
39237 | + return f; | |
8b6a4947 AM |
39238 | +} |
39239 | + | |
c2c0f25c | 39240 | static void loop_reread_partitions(struct loop_device *lo, |
8b6a4947 AM |
39241 | struct block_device *bdev) |
39242 | { | |
d58c55f2 | 39243 | @@ -690,6 +699,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
5527c038 JR |
39244 | unsigned int arg) |
39245 | { | |
e1106418 | 39246 | struct file *file = NULL, *old_file; |
5527c038 | 39247 | + struct file *f, *virt_file = NULL, *old_virt_file; |
5527c038 | 39248 | int error; |
ba1aed25 | 39249 | bool partscan; |
5527c038 | 39250 | |
d58c55f2 | 39251 | @@ -709,12 +719,19 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
cd7a4cd9 AM |
39252 | file = fget(arg); |
39253 | if (!file) | |
e1106418 | 39254 | goto out_err; |
5527c038 JR |
39255 | + f = loop_real_file(file); |
39256 | + if (f) { | |
39257 | + virt_file = file; | |
39258 | + file = f; | |
39259 | + get_file(file); | |
39260 | + } | |
39261 | ||
cd7a4cd9 AM |
39262 | error = loop_validate_file(file, bdev); |
39263 | if (error) | |
e1106418 | 39264 | goto out_err; |
cd7a4cd9 | 39265 | |
5527c038 JR |
39266 | old_file = lo->lo_backing_file; |
39267 | + old_virt_file = lo->lo_backing_virt_file; | |
39268 | ||
39269 | error = -EINVAL; | |
39270 | ||
d58c55f2 | 39271 | @@ -726,6 +743,7 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
8b6a4947 AM |
39272 | blk_mq_freeze_queue(lo->lo_queue); |
39273 | mapping_set_gfp_mask(old_file->f_mapping, lo->old_gfp_mask); | |
39274 | lo->lo_backing_file = file; | |
39275 | + lo->lo_backing_virt_file = virt_file; | |
39276 | lo->old_gfp_mask = mapping_gfp_mask(file->f_mapping); | |
39277 | mapping_set_gfp_mask(file->f_mapping, | |
39278 | lo->old_gfp_mask & ~(__GFP_IO|__GFP_FS)); | |
d58c55f2 | 39279 | @@ -739,6 +757,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
e1106418 JR |
39280 | * dependency. |
39281 | */ | |
5527c038 JR |
39282 | fput(old_file); |
39283 | + if (old_virt_file) | |
39284 | + fput(old_virt_file); | |
e1106418 | 39285 | if (partscan) |
c2c0f25c | 39286 | loop_reread_partitions(lo, bdev); |
5527c038 | 39287 | return 0; |
d58c55f2 | 39288 | @@ -747,6 +767,8 @@ static int loop_change_fd(struct loop_device *lo, struct block_device *bdev, |
e1106418 JR |
39289 | mutex_unlock(&loop_ctl_mutex); |
39290 | if (file) | |
39291 | fput(file); | |
5527c038 JR |
39292 | + if (virt_file) |
39293 | + fput(virt_file); | |
5527c038 JR |
39294 | return error; |
39295 | } | |
e1106418 | 39296 | |
d58c55f2 | 39297 | @@ -951,7 +973,7 @@ static void loop_update_rotational(struct loop_device *lo) |
5527c038 JR |
39298 | static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
39299 | struct block_device *bdev, unsigned int arg) | |
39300 | { | |
062440b3 | 39301 | - struct file *file; |
5527c038 JR |
39302 | + struct file *file, *f, *virt_file = NULL; |
39303 | struct inode *inode; | |
39304 | struct address_space *mapping; | |
eca34b5c | 39305 | struct block_device *claimed_bdev = NULL; |
d58c55f2 | 39306 | @@ -967,6 +989,12 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
39307 | file = fget(arg); |
39308 | if (!file) | |
39309 | goto out; | |
39310 | + f = loop_real_file(file); | |
39311 | + if (f) { | |
39312 | + virt_file = file; | |
39313 | + file = f; | |
39314 | + get_file(file); | |
39315 | + } | |
39316 | ||
fbc438ed JR |
39317 | /* |
39318 | * If we don't hold exclusive handle for the device, upgrade to it | |
d58c55f2 | 39319 | @@ -1015,6 +1043,7 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
5527c038 JR |
39320 | lo->lo_device = bdev; |
39321 | lo->lo_flags = lo_flags; | |
39322 | lo->lo_backing_file = file; | |
39323 | + lo->lo_backing_virt_file = virt_file; | |
39324 | lo->transfer = NULL; | |
39325 | lo->ioctl = NULL; | |
39326 | lo->lo_sizelimit = 0; | |
d58c55f2 | 39327 | @@ -1068,6 +1097,8 @@ static int loop_set_fd(struct loop_device *lo, fmode_t mode, |
eca34b5c | 39328 | bd_abort_claiming(bdev, claimed_bdev, loop_set_fd); |
e1106418 | 39329 | out_putf: |
5527c038 JR |
39330 | fput(file); |
39331 | + if (virt_file) | |
39332 | + fput(virt_file); | |
e1106418 | 39333 | out: |
5527c038 JR |
39334 | /* This is safe: open() is still holding a reference. */ |
39335 | module_put(THIS_MODULE); | |
d58c55f2 | 39336 | @@ -1114,6 +1145,7 @@ loop_init_xfer(struct loop_device *lo, struct loop_func_table *xfer, |
ba1aed25 | 39337 | static int __loop_clr_fd(struct loop_device *lo, bool release) |
5527c038 | 39338 | { |
e1106418 | 39339 | struct file *filp = NULL; |
5527c038 JR |
39340 | + struct file *virt_filp = lo->lo_backing_virt_file; |
39341 | gfp_t gfp = lo->old_gfp_mask; | |
39342 | struct block_device *bdev = lo->lo_device; | |
ba1aed25 | 39343 | int err = 0; |
d58c55f2 | 39344 | @@ -1137,6 +1169,7 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) |
5527c038 | 39345 | |
5527c038 | 39346 | spin_lock_irq(&lo->lo_lock); |
5527c038 JR |
39347 | lo->lo_backing_file = NULL; |
39348 | + lo->lo_backing_virt_file = NULL; | |
39349 | spin_unlock_irq(&lo->lo_lock); | |
39350 | ||
39351 | loop_release_xfer(lo); | |
d58c55f2 | 39352 | @@ -1220,6 +1253,8 @@ static int __loop_clr_fd(struct loop_device *lo, bool release) |
5527c038 | 39353 | */ |
e1106418 JR |
39354 | if (filp) |
39355 | fput(filp); | |
5527c038 JR |
39356 | + if (virt_filp) |
39357 | + fput(virt_filp); | |
e1106418 | 39358 | return err; |
5527c038 JR |
39359 | } |
39360 | ||
39361 | diff --git a/drivers/block/loop.h b/drivers/block/loop.h | |
43982f53 | 39362 | index af75a5ee4094..1d847cb194ff 100644 |
5527c038 JR |
39363 | --- a/drivers/block/loop.h |
39364 | +++ b/drivers/block/loop.h | |
39365 | @@ -46,7 +46,7 @@ struct loop_device { | |
39366 | int (*ioctl)(struct loop_device *, int cmd, | |
39367 | unsigned long arg); | |
39368 | ||
39369 | - struct file * lo_backing_file; | |
43982f53 | 39370 | + struct file *lo_backing_file, *lo_backing_virt_file; |
5527c038 | 39371 | struct block_device *lo_device; |
5527c038 | 39372 | void *key_data; |
8b6a4947 | 39373 | |
5527c038 | 39374 | diff --git a/fs/aufs/f_op.c b/fs/aufs/f_op.c |
d58c55f2 | 39375 | index 6fb4a4ed8cc7..ba9a959f2db2 100644 |
5527c038 JR |
39376 | --- a/fs/aufs/f_op.c |
39377 | +++ b/fs/aufs/f_op.c | |
acd2b654 | 39378 | @@ -359,7 +359,7 @@ static ssize_t aufs_read_iter(struct kiocb *kio, struct iov_iter *iov_iter) |
5527c038 JR |
39379 | if (IS_ERR(h_file)) |
39380 | goto out; | |
39381 | ||
39382 | - if (au_test_loopback_kthread()) { | |
39383 | + if (0 && au_test_loopback_kthread()) { | |
39384 | au_warn_loopback(h_file->f_path.dentry->d_sb); | |
39385 | if (file->f_mapping != h_file->f_mapping) { | |
39386 | file->f_mapping = h_file->f_mapping; | |
39387 | diff --git a/fs/aufs/loop.c b/fs/aufs/loop.c | |
d58c55f2 | 39388 | index a8b63acc6204..9d97c3af5686 100644 |
5527c038 JR |
39389 | --- a/fs/aufs/loop.c |
39390 | +++ b/fs/aufs/loop.c | |
2121bcd9 | 39391 | @@ -133,3 +133,19 @@ void au_loopback_fin(void) |
79b8bda9 | 39392 | symbol_put(loop_backing_file); |
9f237c51 | 39393 | au_kfree_try_rcu(au_warn_loopback_array); |
5527c038 JR |
39394 | } |
39395 | + | |
39396 | +/* ---------------------------------------------------------------------- */ | |
39397 | + | |
39398 | +/* support the loopback block device insude aufs */ | |
39399 | + | |
39400 | +struct file *aufs_real_loop(struct file *file) | |
39401 | +{ | |
39402 | + struct file *f; | |
39403 | + | |
39404 | + BUG_ON(!au_test_aufs(file->f_path.dentry->d_sb)); | |
39405 | + fi_read_lock(file); | |
39406 | + f = au_hf_top(file); | |
39407 | + fi_read_unlock(file); | |
39408 | + AuDebugOn(!f); | |
39409 | + return f; | |
39410 | +} | |
39411 | diff --git a/fs/aufs/loop.h b/fs/aufs/loop.h | |
d58c55f2 | 39412 | index 94f4f80ae33b..ca1194354aff 100644 |
5527c038 JR |
39413 | --- a/fs/aufs/loop.h |
39414 | +++ b/fs/aufs/loop.h | |
eca801bf | 39415 | @@ -26,6 +26,8 @@ void au_warn_loopback(struct super_block *h_sb); |
5527c038 JR |
39416 | |
39417 | int au_loopback_init(void); | |
39418 | void au_loopback_fin(void); | |
39419 | + | |
39420 | +struct file *aufs_real_loop(struct file *file); | |
39421 | #else | |
83b672a5 | 39422 | AuStub(struct file *, loop_backing_file, return NULL, struct super_block *sb) |
eca801bf AM |
39423 | |
39424 | @@ -36,6 +38,8 @@ AuStubVoid(au_warn_loopback, struct super_block *h_sb) | |
5527c038 JR |
39425 | |
39426 | AuStubInt0(au_loopback_init, void) | |
39427 | AuStubVoid(au_loopback_fin, void) | |
39428 | + | |
39429 | +AuStub(struct file *, aufs_real_loop, return NULL, struct file *file) | |
39430 | #endif /* BLK_DEV_LOOP */ | |
39431 | ||
39432 | #endif /* __KERNEL__ */ | |
39433 | diff --git a/fs/aufs/super.c b/fs/aufs/super.c | |
d58c55f2 | 39434 | index 589dd0122020..801e0a7faec5 100644 |
5527c038 JR |
39435 | --- a/fs/aufs/super.c |
39436 | +++ b/fs/aufs/super.c | |
fbc438ed | 39437 | @@ -844,7 +844,10 @@ static const struct super_operations aufs_sop = { |
5527c038 JR |
39438 | .statfs = aufs_statfs, |
39439 | .put_super = aufs_put_super, | |
39440 | .sync_fs = aufs_sync_fs, | |
39441 | - .remount_fs = aufs_remount_fs | |
39442 | + .remount_fs = aufs_remount_fs, | |
39443 | +#ifdef CONFIG_AUFS_BDEV_LOOP | |
39444 | + .real_loop = aufs_real_loop | |
39445 | +#endif | |
39446 | }; | |
39447 | ||
39448 | /* ---------------------------------------------------------------------- */ | |
39449 | diff --git a/include/linux/fs.h b/include/linux/fs.h | |
d58c55f2 | 39450 | index 5fc7807f7c2e..07e24e72706e 100644 |
5527c038 JR |
39451 | --- a/include/linux/fs.h |
39452 | +++ b/include/linux/fs.h | |
d58c55f2 | 39453 | @@ -1980,6 +1980,10 @@ struct super_operations { |
5527c038 JR |
39454 | struct shrink_control *); |
39455 | long (*free_cached_objects)(struct super_block *, | |
39456 | struct shrink_control *); | |
43982f53 | 39457 | +#if IS_ENABLED(CONFIG_BLK_DEV_LOOP) || IS_ENABLED(CONFIG_BLK_DEV_LOOP_MODULE) |
5527c038 JR |
39458 | + /* and aufs */ |
39459 | + struct file *(*real_loop)(struct file *); | |
39460 | +#endif | |
39461 | }; | |
39462 | ||
39463 | /* |